blob_id stringlengths 40 40 | directory_id stringlengths 40 40 | path stringlengths 7 139 | content_id stringlengths 40 40 | detected_licenses listlengths 0 16 | license_type stringclasses 2 values | repo_name stringlengths 7 55 | snapshot_id stringlengths 40 40 | revision_id stringlengths 40 40 | branch_name stringclasses 6 values | visit_date int64 1,471B 1,694B | revision_date int64 1,378B 1,694B | committer_date int64 1,378B 1,694B | github_id float64 1.33M 604M ⌀ | star_events_count int64 0 43.5k | fork_events_count int64 0 1.5k | gha_license_id stringclasses 6 values | gha_event_created_at int64 1,402B 1,695B ⌀ | gha_created_at int64 1,359B 1,637B ⌀ | gha_language stringclasses 19 values | src_encoding stringclasses 2 values | language stringclasses 1 value | is_vendor bool 1 class | is_generated bool 1 class | length_bytes int64 3 6.4M | extension stringclasses 4 values | content stringlengths 3 6.12M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ad5024a80fa9545cf2ff0f765d36e691dbb4b168 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/topology/uniform_space/completion.lean | 4979d8ce94ef26ea4a7d4e4f3f7b2fb06cdc8dc9 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 23,772 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
-/
import topology.uniform_space.abstract_completion
/-!
# Hausdorff completions of uniform spaces
The goal is to construct a left-adjoint to the inclusion of complete Hausdorff uniform spaces
into all uniform spaces. Any uniform space `α` gets a completion `completion α` and a morphism
(ie. uniformly continuous map) `coe : α → completion α` which solves the universal
mapping problem of factorizing morphisms from `α` to any complete Hausdorff uniform space `β`.
It means any uniformly continuous `f : α → β` gives rise to a unique morphism
`completion.extension f : completion α → β` such that `f = completion.extension f ∘ coe`.
Actually `completion.extension f` is defined for all maps from `α` to `β` but it has the desired
properties only if `f` is uniformly continuous.
Beware that `coe` is not injective if `α` is not Hausdorff. But its image is always
dense. The adjoint functor acting on morphisms is then constructed by the usual abstract nonsense.
For every uniform spaces `α` and `β`, it turns `f : α → β` into a morphism
`completion.map f : completion α → completion β`
such that
`coe ∘ f = (completion.map f) ∘ coe`
provided `f` is uniformly continuous. This construction is compatible with composition.
In this file we introduce the following concepts:
* `Cauchy α` the uniform completion of the uniform space `α` (using Cauchy filters). These are not
minimal filters.
* `completion α := quotient (separation_setoid (Cauchy α))` the Hausdorff completion.
## References
This formalization is mostly based on
N. Bourbaki: General Topology
I. M. James: Topologies and Uniformities
From a slightly different perspective in order to reuse material in topology.uniform_space.basic.
-/
noncomputable theory
open filter set
universes u v w x
open_locale uniformity classical topological_space filter
/-- Space of Cauchy filters
This is essentially the completion of a uniform space. The embeddings are the neighbourhood filters.
This space is not minimal, the separated uniform space (i.e. quotiented on the intersection of all
entourages) is necessary for this.
-/
def Cauchy (α : Type u) [uniform_space α] : Type u := { f : filter α // cauchy f }
namespace Cauchy
section
parameters {α : Type u} [uniform_space α]
variables {β : Type v} {γ : Type w}
variables [uniform_space β] [uniform_space γ]
def gen (s : set (α × α)) : set (Cauchy α × Cauchy α) :=
{p | s ∈ p.1.val ×ᶠ p.2.val }
lemma monotone_gen : monotone gen :=
monotone_set_of $ assume p, @monotone_mem (α×α) (p.1.val ×ᶠ p.2.val)
private lemma symm_gen : map prod.swap ((𝓤 α).lift' gen) ≤ (𝓤 α).lift' gen :=
calc map prod.swap ((𝓤 α).lift' gen) =
(𝓤 α).lift' (λs:set (α×α), {p | s ∈ p.2.val ×ᶠ p.1.val }) :
begin
delta gen,
simp [map_lift'_eq, monotone_set_of, monotone_mem,
function.comp, image_swap_eq_preimage_swap, -subtype.val_eq_coe]
end
... ≤ (𝓤 α).lift' gen :
uniformity_lift_le_swap
(monotone_principal.comp (monotone_set_of $ assume p,
@monotone_mem (α×α) (p.2.val ×ᶠ p.1.val)))
begin
have h := λ(p:Cauchy α×Cauchy α), @filter.prod_comm _ _ (p.2.val) (p.1.val),
simp [function.comp, h, -subtype.val_eq_coe, mem_map'],
exact le_rfl,
end
private lemma comp_rel_gen_gen_subset_gen_comp_rel {s t : set (α×α)} : comp_rel (gen s) (gen t) ⊆
(gen (comp_rel s t) : set (Cauchy α × Cauchy α)) :=
assume ⟨f, g⟩ ⟨h, h₁, h₂⟩,
let ⟨t₁, (ht₁ : t₁ ∈ f.val), t₂, (ht₂ : t₂ ∈ h.val), (h₁ : t₁ ×ˢ t₂ ⊆ s)⟩ :=
mem_prod_iff.mp h₁ in
let ⟨t₃, (ht₃ : t₃ ∈ h.val), t₄, (ht₄ : t₄ ∈ g.val), (h₂ : t₃ ×ˢ t₄ ⊆ t)⟩ :=
mem_prod_iff.mp h₂ in
have t₂ ∩ t₃ ∈ h.val,
from inter_mem ht₂ ht₃,
let ⟨x, xt₂, xt₃⟩ :=
h.property.left.nonempty_of_mem this in
(f.val ×ᶠ g.val).sets_of_superset
(prod_mem_prod ht₁ ht₄)
(assume ⟨a, b⟩ ⟨(ha : a ∈ t₁), (hb : b ∈ t₄)⟩,
⟨x,
h₁ (show (a, x) ∈ t₁ ×ˢ t₂, from ⟨ha, xt₂⟩),
h₂ (show (x, b) ∈ t₃ ×ˢ t₄, from ⟨xt₃, hb⟩)⟩)
private lemma comp_gen :
((𝓤 α).lift' gen).lift' (λs, comp_rel s s) ≤ (𝓤 α).lift' gen :=
calc ((𝓤 α).lift' gen).lift' (λs, comp_rel s s) =
(𝓤 α).lift' (λs, comp_rel (gen s) (gen s)) :
begin
rw [lift'_lift'_assoc],
exact monotone_gen,
exact (monotone_comp_rel monotone_id monotone_id)
end
... ≤ (𝓤 α).lift' (λs, gen $ comp_rel s s) :
lift'_mono' $ assume s hs, comp_rel_gen_gen_subset_gen_comp_rel
... = ((𝓤 α).lift' $ λs:set(α×α), comp_rel s s).lift' gen :
begin
rw [lift'_lift'_assoc],
exact (monotone_comp_rel monotone_id monotone_id),
exact monotone_gen
end
... ≤ (𝓤 α).lift' gen : lift'_mono comp_le_uniformity le_rfl
instance : uniform_space (Cauchy α) :=
uniform_space.of_core
{ uniformity := (𝓤 α).lift' gen,
refl := principal_le_lift' $ assume s hs ⟨a, b⟩ (a_eq_b : a = b),
a_eq_b ▸ a.property.right hs,
symm := symm_gen,
comp := comp_gen }
theorem mem_uniformity {s : set (Cauchy α × Cauchy α)} :
s ∈ 𝓤 (Cauchy α) ↔ ∃ t ∈ 𝓤 α, gen t ⊆ s :=
mem_lift'_sets monotone_gen
theorem mem_uniformity' {s : set (Cauchy α × Cauchy α)} :
s ∈ 𝓤 (Cauchy α) ↔ ∃ t ∈ 𝓤 α, ∀ f g : Cauchy α, t ∈ f.1 ×ᶠ g.1 → (f, g) ∈ s :=
mem_uniformity.trans $ bex_congr $ λ t h, prod.forall
/-- Embedding of `α` into its completion `Cauchy α` -/
def pure_cauchy (a : α) : Cauchy α :=
⟨pure a, cauchy_pure⟩
lemma uniform_inducing_pure_cauchy : uniform_inducing (pure_cauchy : α → Cauchy α) :=
⟨have (preimage (λ (x : α × α), (pure_cauchy (x.fst), pure_cauchy (x.snd))) ∘ gen) = id,
from funext $ assume s, set.ext $ assume ⟨a₁, a₂⟩,
by simp [preimage, gen, pure_cauchy, prod_principal_principal],
calc comap (λ (x : α × α), (pure_cauchy (x.fst), pure_cauchy (x.snd))) ((𝓤 α).lift' gen)
= (𝓤 α).lift'
(preimage (λ (x : α × α), (pure_cauchy (x.fst), pure_cauchy (x.snd))) ∘ gen) :
comap_lift'_eq monotone_gen
... = 𝓤 α : by simp [this]⟩
lemma uniform_embedding_pure_cauchy : uniform_embedding (pure_cauchy : α → Cauchy α) :=
{ inj := assume a₁ a₂ h, pure_injective $ subtype.ext_iff_val.1 h,
..uniform_inducing_pure_cauchy }
lemma dense_range_pure_cauchy : dense_range pure_cauchy :=
assume f,
have h_ex : ∀ s ∈ 𝓤 (Cauchy α), ∃y:α, (f, pure_cauchy y) ∈ s, from
assume s hs,
let ⟨t'', ht''₁, (ht''₂ : gen t'' ⊆ s)⟩ := (mem_lift'_sets monotone_gen).mp hs in
let ⟨t', ht'₁, ht'₂⟩ := comp_mem_uniformity_sets ht''₁ in
have t' ∈ f.val ×ᶠ f.val,
from f.property.right ht'₁,
let ⟨t, ht, (h : t ×ˢ t ⊆ t')⟩ := mem_prod_same_iff.mp this in
let ⟨x, (hx : x ∈ t)⟩ := f.property.left.nonempty_of_mem ht in
have t'' ∈ f.val ×ᶠ pure x,
from mem_prod_iff.mpr ⟨t, ht, {y:α | (x, y) ∈ t'},
h $ mk_mem_prod hx hx,
assume ⟨a, b⟩ ⟨(h₁ : a ∈ t), (h₂ : (x, b) ∈ t')⟩,
ht'₂ $ prod_mk_mem_comp_rel (@h (a, x) ⟨h₁, hx⟩) h₂⟩,
⟨x, ht''₂ $ by dsimp [gen]; exact this⟩,
begin
simp only [closure_eq_cluster_pts, cluster_pt, nhds_eq_uniformity, lift'_inf_principal_eq,
set.inter_comm _ (range pure_cauchy), mem_set_of_eq],
exact (lift'_ne_bot_iff $ monotone_const.inter monotone_preimage).mpr
(assume s hs,
let ⟨y, hy⟩ := h_ex s hs in
have pure_cauchy y ∈ range pure_cauchy ∩ {y : Cauchy α | (f, y) ∈ s},
from ⟨mem_range_self y, hy⟩,
⟨_, this⟩)
end
lemma dense_inducing_pure_cauchy : dense_inducing pure_cauchy :=
uniform_inducing_pure_cauchy.dense_inducing dense_range_pure_cauchy
lemma dense_embedding_pure_cauchy : dense_embedding pure_cauchy :=
uniform_embedding_pure_cauchy.dense_embedding dense_range_pure_cauchy
lemma nonempty_Cauchy_iff : nonempty (Cauchy α) ↔ nonempty α :=
begin
split ; rintro ⟨c⟩,
{ have := eq_univ_iff_forall.1 dense_embedding_pure_cauchy.to_dense_inducing.closure_range c,
obtain ⟨_, ⟨_, a, _⟩⟩ := mem_closure_iff.1 this _ is_open_univ trivial,
exact ⟨a⟩ },
{ exact ⟨pure_cauchy c⟩ }
end
section
set_option eqn_compiler.zeta true
instance : complete_space (Cauchy α) :=
complete_space_extension
uniform_inducing_pure_cauchy
dense_range_pure_cauchy $
assume f hf,
let f' : Cauchy α := ⟨f, hf⟩ in
have map pure_cauchy f ≤ (𝓤 $ Cauchy α).lift' (preimage (prod.mk f')),
from le_lift' $ assume s hs,
let ⟨t, ht₁, (ht₂ : gen t ⊆ s)⟩ := (mem_lift'_sets monotone_gen).mp hs in
let ⟨t', ht', (h : t' ×ˢ t' ⊆ t)⟩ := mem_prod_same_iff.mp (hf.right ht₁) in
have t' ⊆ { y : α | (f', pure_cauchy y) ∈ gen t },
from assume x hx, (f ×ᶠ pure x).sets_of_superset (prod_mem_prod ht' hx) h,
f.sets_of_superset ht' $ subset.trans this (preimage_mono ht₂),
⟨f', by simp [nhds_eq_uniformity]; assumption⟩
end
instance [inhabited α] : inhabited (Cauchy α) :=
⟨pure_cauchy default⟩
instance [h : nonempty α] : nonempty (Cauchy α) :=
h.rec_on $ assume a, nonempty.intro $ Cauchy.pure_cauchy a
section extend
def extend (f : α → β) : (Cauchy α → β) :=
if uniform_continuous f then
dense_inducing_pure_cauchy.extend f
else
λ x, f (classical.inhabited_of_nonempty $ nonempty_Cauchy_iff.1 ⟨x⟩).default
section separated_space
variables [separated_space β]
lemma extend_pure_cauchy {f : α → β} (hf : uniform_continuous f) (a : α) :
extend f (pure_cauchy a) = f a :=
begin
rw [extend, if_pos hf],
exact uniformly_extend_of_ind uniform_inducing_pure_cauchy dense_range_pure_cauchy hf _
end
end separated_space
variables [_root_.complete_space β]
lemma uniform_continuous_extend {f : α → β} : uniform_continuous (extend f) :=
begin
by_cases hf : uniform_continuous f,
{ rw [extend, if_pos hf],
exact uniform_continuous_uniformly_extend uniform_inducing_pure_cauchy
dense_range_pure_cauchy hf },
{ rw [extend, if_neg hf],
exact uniform_continuous_of_const (assume a b, by congr) }
end
end extend
end
theorem Cauchy_eq {α : Type*} [inhabited α] [uniform_space α] [complete_space α]
[separated_space α] {f g : Cauchy α} :
Lim f.1 = Lim g.1 ↔ (f, g) ∈ separation_rel (Cauchy α) :=
begin
split,
{ intros e s hs,
rcases Cauchy.mem_uniformity'.1 hs with ⟨t, tu, ts⟩,
apply ts,
rcases comp_mem_uniformity_sets tu with ⟨d, du, dt⟩,
refine mem_prod_iff.2
⟨_, f.2.le_nhds_Lim (mem_nhds_right (Lim f.1) du),
_, g.2.le_nhds_Lim (mem_nhds_left (Lim g.1) du), λ x h, _⟩,
cases x with a b, cases h with h₁ h₂,
rw ← e at h₂,
exact dt ⟨_, h₁, h₂⟩ },
{ intros H,
refine separated_def.1 (by apply_instance) _ _ (λ t tu, _),
rcases mem_uniformity_is_closed tu with ⟨d, du, dc, dt⟩,
refine H {p | (Lim p.1.1, Lim p.2.1) ∈ t}
(Cauchy.mem_uniformity'.2 ⟨d, du, λ f g h, _⟩),
rcases mem_prod_iff.1 h with ⟨x, xf, y, yg, h⟩,
have limc : ∀ (f : Cauchy α) (x ∈ f.1), Lim f.1 ∈ closure x,
{ intros f x xf,
rw closure_eq_cluster_pts,
exact f.2.1.mono
(le_inf f.2.le_nhds_Lim (le_principal_iff.2 xf)) },
have := dc.closure_subset_iff.2 h,
rw closure_prod_eq at this,
refine dt (this ⟨_, _⟩); dsimp; apply limc; assumption }
end
section
local attribute [instance] uniform_space.separation_setoid
lemma separated_pure_cauchy_injective {α : Type*} [uniform_space α] [s : separated_space α] :
function.injective (λa:α, ⟦pure_cauchy a⟧) | a b h :=
separated_def.1 s _ _ $ assume s hs,
let ⟨t, ht, hts⟩ :=
by rw [← (@uniform_embedding_pure_cauchy α _).comap_uniformity, filter.mem_comap] at hs;
exact hs in
have (pure_cauchy a, pure_cauchy b) ∈ t, from quotient.exact h t ht,
@hts (a, b) this
end
end Cauchy
local attribute [instance] uniform_space.separation_setoid
open Cauchy set
namespace uniform_space
variables (α : Type*) [uniform_space α]
variables {β : Type*} [uniform_space β]
variables {γ : Type*} [uniform_space γ]
instance complete_space_separation [h : complete_space α] :
complete_space (quotient (separation_setoid α)) :=
⟨assume f, assume hf : cauchy f,
have cauchy (f.comap (λx, ⟦x⟧)), from
hf.comap' comap_quotient_le_uniformity $ hf.left.comap_of_surj (surjective_quotient_mk _),
let ⟨x, (hx : f.comap (λx, ⟦x⟧) ≤ 𝓝 x)⟩ := complete_space.complete this in
⟨⟦x⟧, (comap_le_comap_iff $ by simp).1
(hx.trans $ map_le_iff_le_comap.1 continuous_quotient_mk.continuous_at)⟩⟩
/-- Hausdorff completion of `α` -/
def completion := quotient (separation_setoid $ Cauchy α)
namespace completion
instance [inhabited α] : inhabited (completion α) :=
quotient.inhabited (separation_setoid (Cauchy α))
@[priority 50]
instance : uniform_space (completion α) := separation_setoid.uniform_space
instance : complete_space (completion α) := uniform_space.complete_space_separation (Cauchy α)
instance : separated_space (completion α) := uniform_space.separated_separation
instance : regular_space (completion α) := separated_regular
/-- Automatic coercion from `α` to its completion. Not always injective. -/
instance : has_coe_t α (completion α) := ⟨quotient.mk ∘ pure_cauchy⟩ -- note [use has_coe_t]
protected lemma coe_eq : (coe : α → completion α) = quotient.mk ∘ pure_cauchy := rfl
lemma comap_coe_eq_uniformity :
(𝓤 _).comap (λ(p:α×α), ((p.1 : completion α), (p.2 : completion α))) = 𝓤 α :=
begin
have : (λx:α×α, ((x.1 : completion α), (x.2 : completion α))) =
(λx:(Cauchy α)×(Cauchy α), (⟦x.1⟧, ⟦x.2⟧)) ∘ (λx:α×α, (pure_cauchy x.1, pure_cauchy x.2)),
{ ext ⟨a, b⟩; simp; refl },
rw [this, ← filter.comap_comap],
change filter.comap _ (filter.comap _ (𝓤 $ quotient $ separation_setoid $ Cauchy α)) = 𝓤 α,
rw [comap_quotient_eq_uniformity, uniform_embedding_pure_cauchy.comap_uniformity]
end
lemma uniform_inducing_coe : uniform_inducing (coe : α → completion α) :=
⟨comap_coe_eq_uniformity α⟩
variables {α}
lemma dense_range_coe : dense_range (coe : α → completion α) :=
dense_range_pure_cauchy.quotient
variables (α)
def cpkg {α : Type*} [uniform_space α] : abstract_completion α :=
{ space := completion α,
coe := coe,
uniform_struct := by apply_instance,
complete := by apply_instance,
separation := by apply_instance,
uniform_inducing := completion.uniform_inducing_coe α,
dense := completion.dense_range_coe }
instance abstract_completion.inhabited : inhabited (abstract_completion α) :=
⟨cpkg⟩
local attribute [instance]
abstract_completion.uniform_struct abstract_completion.complete abstract_completion.separation
lemma nonempty_completion_iff : nonempty (completion α) ↔ nonempty α :=
cpkg.dense.nonempty_iff.symm
lemma uniform_continuous_coe : uniform_continuous (coe : α → completion α) :=
cpkg.uniform_continuous_coe
lemma continuous_coe : continuous (coe : α → completion α) :=
cpkg.continuous_coe
lemma uniform_embedding_coe [separated_space α] : uniform_embedding (coe : α → completion α) :=
{ comap_uniformity := comap_coe_eq_uniformity α,
inj := separated_pure_cauchy_injective }
lemma coe_injective [separated_space α] : function.injective (coe : α → completion α) :=
uniform_embedding.inj (uniform_embedding_coe _)
variable {α}
lemma dense_inducing_coe : dense_inducing (coe : α → completion α) :=
{ dense := dense_range_coe,
..(uniform_inducing_coe α).inducing }
open topological_space
instance separable_space_completion [separable_space α] : separable_space (completion α) :=
completion.dense_inducing_coe.separable_space
lemma dense_embedding_coe [separated_space α]: dense_embedding (coe : α → completion α) :=
{ inj := separated_pure_cauchy_injective,
..dense_inducing_coe }
lemma dense_range_coe₂ :
dense_range (λx:α × β, ((x.1 : completion α), (x.2 : completion β))) :=
dense_range_coe.prod_map dense_range_coe
lemma dense_range_coe₃ :
dense_range (λx:α × (β × γ),
((x.1 : completion α), ((x.2.1 : completion β), (x.2.2 : completion γ)))) :=
dense_range_coe.prod_map dense_range_coe₂
@[elab_as_eliminator]
lemma induction_on {p : completion α → Prop}
(a : completion α) (hp : is_closed {a | p a}) (ih : ∀a:α, p a) : p a :=
is_closed_property dense_range_coe hp ih a
@[elab_as_eliminator]
lemma induction_on₂ {p : completion α → completion β → Prop}
(a : completion α) (b : completion β)
(hp : is_closed {x : completion α × completion β | p x.1 x.2})
(ih : ∀(a:α) (b:β), p a b) : p a b :=
have ∀x : completion α × completion β, p x.1 x.2, from
is_closed_property dense_range_coe₂ hp $ assume ⟨a, b⟩, ih a b,
this (a, b)
@[elab_as_eliminator]
lemma induction_on₃ {p : completion α → completion β → completion γ → Prop}
(a : completion α) (b : completion β) (c : completion γ)
(hp : is_closed {x : completion α × completion β × completion γ | p x.1 x.2.1 x.2.2})
(ih : ∀(a:α) (b:β) (c:γ), p a b c) : p a b c :=
have ∀x : completion α × completion β × completion γ, p x.1 x.2.1 x.2.2, from
is_closed_property dense_range_coe₃ hp $ assume ⟨a, b, c⟩, ih a b c,
this (a, b, c)
lemma ext {Y : Type*} [topological_space Y] [t2_space Y] {f g : completion α → Y}
(hf : continuous f) (hg : continuous g) (h : ∀a:α, f a = g a) : f = g :=
cpkg.funext hf hg h
lemma ext' {Y : Type*} [topological_space Y] [t2_space Y] {f g : completion α → Y}
(hf : continuous f) (hg : continuous g) (h : ∀a:α, f a = g a) (a : completion α) :
f a = g a :=
congr_fun (ext hf hg h) a
section extension
variables {f : α → β}
/-- "Extension" to the completion. It is defined for any map `f` but
returns an arbitrary constant value if `f` is not uniformly continuous -/
protected def extension (f : α → β) : completion α → β :=
cpkg.extend f
section complete_space
variables [complete_space β]
lemma uniform_continuous_extension : uniform_continuous (completion.extension f) :=
cpkg.uniform_continuous_extend
lemma continuous_extension : continuous (completion.extension f) :=
cpkg.continuous_extend
end complete_space
@[simp] lemma extension_coe [separated_space β] (hf : uniform_continuous f) (a : α) :
(completion.extension f) a = f a :=
cpkg.extend_coe hf a
variables [separated_space β] [complete_space β]
lemma extension_unique (hf : uniform_continuous f) {g : completion α → β}
(hg : uniform_continuous g) (h : ∀ a : α, f a = g (a : completion α)) :
completion.extension f = g :=
cpkg.extend_unique hf hg h
@[simp] lemma extension_comp_coe {f : completion α → β} (hf : uniform_continuous f) :
completion.extension (f ∘ coe) = f :=
cpkg.extend_comp_coe hf
end extension
section map
variables {f : α → β}
/-- Completion functor acting on morphisms -/
protected def map (f : α → β) : completion α → completion β :=
cpkg.map cpkg f
lemma uniform_continuous_map : uniform_continuous (completion.map f) :=
cpkg.uniform_continuous_map cpkg f
lemma continuous_map : continuous (completion.map f) :=
cpkg.continuous_map cpkg f
@[simp] lemma map_coe (hf : uniform_continuous f) (a : α) : (completion.map f) a = f a :=
cpkg.map_coe cpkg hf a
lemma map_unique {f : α → β} {g : completion α → completion β}
(hg : uniform_continuous g) (h : ∀a:α, ↑(f a) = g a) : completion.map f = g :=
cpkg.map_unique cpkg hg h
@[simp] lemma map_id : completion.map (@id α) = id :=
cpkg.map_id
lemma extension_map [complete_space γ] [separated_space γ] {f : β → γ} {g : α → β}
(hf : uniform_continuous f) (hg : uniform_continuous g) :
completion.extension f ∘ completion.map g = completion.extension (f ∘ g) :=
completion.ext (continuous_extension.comp continuous_map) continuous_extension $
by intro a; simp only [hg, hf, hf.comp hg, (∘), map_coe, extension_coe]
lemma map_comp {g : β → γ} {f : α → β} (hg : uniform_continuous g) (hf : uniform_continuous f) :
completion.map g ∘ completion.map f = completion.map (g ∘ f) :=
extension_map ((uniform_continuous_coe _).comp hg) hf
end map
/- In this section we construct isomorphisms between the completion of a uniform space and the
completion of its separation quotient -/
section separation_quotient_completion
def completion_separation_quotient_equiv (α : Type u) [uniform_space α] :
completion (separation_quotient α) ≃ completion α :=
begin
refine ⟨completion.extension (separation_quotient.lift (coe : α → completion α)),
completion.map quotient.mk, _, _⟩,
{ assume a,
refine induction_on a (is_closed_eq (continuous_map.comp continuous_extension) continuous_id) _,
rintros ⟨a⟩,
show completion.map quotient.mk
(completion.extension (separation_quotient.lift coe) ↑⟦a⟧) = ↑⟦a⟧,
rw [extension_coe (separation_quotient.uniform_continuous_lift _),
separation_quotient.lift_mk (uniform_continuous_coe α),
completion.map_coe uniform_continuous_quotient_mk] ; apply_instance },
{ assume a,
refine completion.induction_on a
(is_closed_eq (continuous_extension.comp continuous_map) continuous_id) (λ a, _),
rw [map_coe uniform_continuous_quotient_mk,
extension_coe (separation_quotient.uniform_continuous_lift _),
separation_quotient.lift_mk (uniform_continuous_coe α) _] ; apply_instance }
end
lemma uniform_continuous_completion_separation_quotient_equiv :
uniform_continuous ⇑(completion_separation_quotient_equiv α) :=
uniform_continuous_extension
lemma uniform_continuous_completion_separation_quotient_equiv_symm :
uniform_continuous ⇑(completion_separation_quotient_equiv α).symm :=
uniform_continuous_map
end separation_quotient_completion
section extension₂
variables (f : α → β → γ)
open function
protected def extension₂ (f : α → β → γ) : completion α → completion β → γ :=
cpkg.extend₂ cpkg f
section separated_space
variables [separated_space γ] {f}
@[simp] lemma extension₂_coe_coe (hf : uniform_continuous₂ f) (a : α) (b : β) :
completion.extension₂ f a b = f a b :=
cpkg.extension₂_coe_coe cpkg hf a b
end separated_space
variables [complete_space γ] (f)
lemma uniform_continuous_extension₂ : uniform_continuous₂ (completion.extension₂ f) :=
cpkg.uniform_continuous_extension₂ cpkg f
end extension₂
section map₂
open function
protected def map₂ (f : α → β → γ) : completion α → completion β → completion γ :=
cpkg.map₂ cpkg cpkg f
lemma uniform_continuous_map₂ (f : α → β → γ) : uniform_continuous₂ (completion.map₂ f) :=
cpkg.uniform_continuous_map₂ cpkg cpkg f
lemma continuous_map₂ {δ} [topological_space δ] {f : α → β → γ}
{a : δ → completion α} {b : δ → completion β} (ha : continuous a) (hb : continuous b) :
continuous (λd:δ, completion.map₂ f (a d) (b d)) :=
cpkg.continuous_map₂ cpkg cpkg ha hb
lemma map₂_coe_coe (a : α) (b : β) (f : α → β → γ) (hf : uniform_continuous₂ f) :
completion.map₂ f (a : completion α) (b : completion β) = f a b :=
cpkg.map₂_coe_coe cpkg cpkg a b f hf
end map₂
end completion
end uniform_space
|
ceea9217a189a5fc621d6ff9d9bef91a324a3efa | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/1200.lean | e04343c048500b3186b738ad3a6682f4e538362d | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | leanprover/lean4 | 4bdf9790294964627eb9be79f5e8f6157780b4cc | f1f9dc0f2f531af3312398999d8b8303fa5f096b | refs/heads/master | 1,693,360,665,786 | 1,693,350,868,000 | 1,693,350,868,000 | 129,571,436 | 2,827 | 311 | Apache-2.0 | 1,694,716,156,000 | 1,523,760,560,000 | Lean | UTF-8 | Lean | false | false | 111 | lean | example
(h: match none (α:=α) with
| some _ => True
| _ => True):
True := by
split at h <;> trivial
|
5e4afacd41c3e883b55a57ae60e72772aeda2e34 | 618003631150032a5676f229d13a079ac875ff77 | /src/ring_theory/adjoin.lean | ba9188e1f1ecd6d0d3b93d5758bb71f2efc3c765 | [
"Apache-2.0"
] | permissive | awainverse/mathlib | 939b68c8486df66cfda64d327ad3d9165248c777 | ea76bd8f3ca0a8bf0a166a06a475b10663dec44a | refs/heads/master | 1,659,592,962,036 | 1,590,987,592,000 | 1,590,987,592,000 | 268,436,019 | 1 | 0 | Apache-2.0 | 1,590,990,500,000 | 1,590,990,500,000 | null | UTF-8 | Lean | false | false | 7,955 | lean | /-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
Adjoining elements to form subalgebras.
-/
import ring_theory.polynomial
import ring_theory.principal_ideal_domain
universes u v w
open submodule ring
namespace algebra
variables {R : Type u} {A : Type v}
variables [comm_ring R] [comm_ring A]
variables [algebra R A] {s t : set A}
theorem subset_adjoin : s ⊆ adjoin R s :=
set.subset.trans (set.subset_union_right _ _) subset_closure
theorem adjoin_le {S : subalgebra R A} (H : s ⊆ S) : adjoin R s ≤ S :=
closure_subset $ set.union_subset S.3 H
theorem adjoin_le_iff {S : subalgebra R A} : adjoin R s ≤ S ↔ s ⊆ S:=
⟨set.subset.trans subset_adjoin, adjoin_le⟩
theorem adjoin_mono (H : s ⊆ t) : adjoin R s ≤ adjoin R t :=
closure_subset (set.subset.trans (set.union_subset_union_right _ H) subset_closure)
variables (R A)
@[simp] theorem adjoin_empty : adjoin R (∅ : set A) = ⊥ :=
eq_bot_iff.2 $ adjoin_le $ set.empty_subset _
variables {A}
variables (s t)
theorem adjoin_union : adjoin R (s ∪ t) = (adjoin R s).under (adjoin (adjoin R s) t) :=
le_antisymm
(closure_mono $ set.union_subset
(set.range_subset_iff.2 $ λ r, or.inl ⟨algebra_map R (adjoin R s) r, rfl⟩)
(set.union_subset_union_left _ $ λ x hxs, ⟨⟨_, subset_adjoin hxs⟩, rfl⟩))
(closure_subset $ set.union_subset
(set.range_subset_iff.2 $ λ x, adjoin_mono (set.subset_union_left _ _) x.2)
(set.subset.trans (set.subset_union_right _ _) subset_adjoin))
theorem adjoin_eq_span : (adjoin R s : submodule R A) = span R (monoid.closure s) :=
begin
apply le_antisymm,
{ intros r hr, rcases ring.exists_list_of_mem_closure hr with ⟨L, HL, rfl⟩, clear hr,
induction L with hd tl ih, { exact zero_mem _ },
rw list.forall_mem_cons at HL,
rw [list.map_cons, list.sum_cons],
refine submodule.add_mem _ _ (ih HL.2),
replace HL := HL.1, clear ih tl,
suffices : ∃ z r (hr : r ∈ monoid.closure s), has_scalar.smul.{u v} z r = list.prod hd,
{ rcases this with ⟨z, r, hr, hzr⟩, rw ← hzr,
exact smul_mem _ _ (subset_span hr) },
induction hd with hd tl ih, { exact ⟨1, 1, is_submonoid.one_mem, one_smul _ _⟩ },
rw list.forall_mem_cons at HL,
rcases (ih HL.2) with ⟨z, r, hr, hzr⟩, rw [list.prod_cons, ← hzr],
rcases HL.1 with ⟨⟨hd, rfl⟩ | hs⟩ | rfl,
{ refine ⟨hd * z, r, hr, _⟩,
rw [smul_def, smul_def, (algebra_map _ _).map_mul, _root_.mul_assoc] },
{ refine ⟨z, hd * r, is_submonoid.mul_mem (monoid.subset_closure hs) hr, _⟩,
rw [smul_def, smul_def, mul_left_comm] },
{ refine ⟨-z, r, hr, _⟩, rw [neg_smul, neg_one_mul] } },
exact span_le.2 (show monoid.closure s ⊆ adjoin R s, from monoid.closure_subset subset_adjoin)
end
theorem adjoin_eq_range :
adjoin R s = (mv_polynomial.aeval R A (coe : s → A)).range :=
le_antisymm
(adjoin_le $ λ x hx, ⟨mv_polynomial.X ⟨x, hx⟩, mv_polynomial.eval₂_X _ _ _⟩)
(λ x ⟨p, hp⟩, hp ▸ mv_polynomial.induction_on p
(λ r, by rw [mv_polynomial.aeval_def, mv_polynomial.eval₂_C]; exact (adjoin R s).3 ⟨r, rfl⟩)
(λ p q hp hq, by rw alg_hom.map_add; exact is_add_submonoid.add_mem hp hq)
(λ p ⟨n, hn⟩ hp, by rw [alg_hom.map_mul, mv_polynomial.aeval_def _ _ _ (mv_polynomial.X _),
mv_polynomial.eval₂_X]; exact is_submonoid.mul_mem hp (subset_adjoin hn)))
theorem adjoin_singleton_eq_range (x : A) :
adjoin R {x} = (polynomial.aeval R A x).range :=
le_antisymm
(adjoin_le $ set.singleton_subset_iff.2 ⟨polynomial.X, polynomial.eval₂_X _ _⟩)
(λ y ⟨p, hp⟩, hp ▸ polynomial.induction_on p
(λ r, by rw [polynomial.aeval_def, polynomial.eval₂_C]; exact (adjoin R _).3 ⟨r, rfl⟩)
(λ p q hp hq, by rw alg_hom.map_add; exact is_add_submonoid.add_mem hp hq)
(λ n r ih, by { rw [pow_succ', ← ring.mul_assoc, alg_hom.map_mul,
polynomial.aeval_def _ polynomial.X, polynomial.eval₂_X],
exact is_submonoid.mul_mem ih (subset_adjoin rfl) }))
theorem adjoin_union_coe_submodule : (adjoin R (s ∪ t) : submodule R A) =
(adjoin R s) * (adjoin R t) :=
begin
rw [adjoin_eq_span, adjoin_eq_span, adjoin_eq_span, span_mul_span],
congr' 1,
ext z,
rw monoid.mem_closure_union_iff,
split;
{ rintro ⟨y, hys, z, hzt, rfl⟩, exact ⟨_, hys, _, hzt, rfl⟩ }
end
variables {R s t}
theorem adjoin_int (s : set R) : adjoin ℤ s = subalgebra_of_subring (ring.closure s) :=
le_antisymm (adjoin_le subset_closure) (closure_subset subset_adjoin)
local attribute [instance] set.pointwise_mul_semiring
theorem fg_trans (h1 : (adjoin R s : submodule R A).fg)
(h2 : (adjoin (adjoin R s) t : submodule (adjoin R s) A).fg) :
(adjoin R (s ∪ t) : submodule R A).fg :=
begin
rcases fg_def.1 h1 with ⟨p, hp, hp'⟩,
rcases fg_def.1 h2 with ⟨q, hq, hq'⟩,
refine fg_def.2 ⟨p * q, set.pointwise_mul_finite hp hq, le_antisymm _ _⟩,
{ rw [span_le],
rintros _ ⟨x, hx, y, hy, rfl⟩,
change x * y ∈ _,
refine is_submonoid.mul_mem _ _,
{ have : x ∈ (adjoin R s : submodule R A),
{ rw ← hp', exact subset_span hx },
exact adjoin_mono (set.subset_union_left _ _) this },
have : y ∈ (adjoin (adjoin R s) t : submodule (adjoin R s) A),
{ rw ← hq', exact subset_span hy },
change y ∈ adjoin R (s ∪ t), rwa adjoin_union },
{ intros r hr,
change r ∈ adjoin R (s ∪ t) at hr,
rw adjoin_union at hr,
change r ∈ (adjoin (adjoin R s) t : submodule (adjoin R s) A) at hr,
haveI := classical.dec_eq A,
haveI := classical.dec_eq R,
rw [← hq', ← set.image_id q, finsupp.mem_span_iff_total (adjoin R s)] at hr,
rcases hr with ⟨l, hlq, rfl⟩,
have := @finsupp.total_apply A A (adjoin R s),
rw [this, finsupp.sum],
refine sum_mem _ _,
intros z hz, change (l z).1 * _ ∈ _,
have : (l z).1 ∈ (adjoin R s : submodule R A) := (l z).2,
rw [← hp', ← set.image_id p, finsupp.mem_span_iff_total R] at this,
rcases this with ⟨l2, hlp, hl⟩,
have := @finsupp.total_apply A A R,
rw this at hl,
rw [←hl, finsupp.sum_mul],
refine sum_mem _ _,
intros t ht, change _ * _ ∈ _, rw smul_mul_assoc, refine smul_mem _ _ _,
exact subset_span ⟨t, hlp ht, z, hlq hz, rfl⟩ }
end
end algebra
namespace subalgebra
variables {R : Type u} {A : Type v}
variables [comm_ring R] [comm_ring A] [algebra R A]
/-- A subalgebra `S` is finitely generated if there exists `t : finset A` such that
`algebra.adjoin R t = S`. -/
def fg (S : subalgebra R A) : Prop :=
∃ t : finset A, algebra.adjoin R ↑t = S
theorem fg_def {S : subalgebra R A} : S.fg ↔ ∃ t : set A, set.finite t ∧ algebra.adjoin R t = S :=
⟨λ ⟨t, ht⟩, ⟨↑t, set.finite_mem_finset t, ht⟩,
λ ⟨t, ht1, ht2⟩, ⟨ht1.to_finset, by rwa set.finite.coe_to_finset⟩⟩
theorem fg_bot : (⊥ : subalgebra R A).fg :=
⟨∅, algebra.adjoin_empty R A⟩
end subalgebra
variables {R : Type u} {A : Type v} {B : Type w}
variables [comm_ring R] [comm_ring A] [comm_ring B] [algebra R A] [algebra R B]
instance alg_hom.is_noetherian_ring_range (f : A →ₐ[R] B) [is_noetherian_ring A] :
is_noetherian_ring f.range :=
is_noetherian_ring_range f.to_ring_hom
theorem is_noetherian_ring_of_fg {S : subalgebra R A} (HS : S.fg)
[is_noetherian_ring R] : is_noetherian_ring S :=
let ⟨t, ht⟩ := HS in ht ▸ (algebra.adjoin_eq_range R (↑t : set A)).symm ▸
by haveI : is_noetherian_ring (mv_polynomial (↑t : set A) R) :=
mv_polynomial.is_noetherian_ring;
convert alg_hom.is_noetherian_ring_range _; apply_instance
theorem is_noetherian_ring_closure (s : set R) (hs : s.finite) :
is_noetherian_ring (ring.closure s) :=
show is_noetherian_ring (subalgebra_of_subring (ring.closure s)), from
algebra.adjoin_int s ▸ is_noetherian_ring_of_fg (subalgebra.fg_def.2 ⟨s, hs, rfl⟩)
|
131fef7f0e7c4a6cdc280ac984a7ed49a4333ed3 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/measure_theory/function/strongly_measurable.lean | e24a038c63a6aab71348f79b9e1e40efc3c218fb | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 88,190 | lean | /-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Sébastien Gouëzel
-/
import measure_theory.function.ess_sup
import measure_theory.integral.mean_inequalities
import topology.continuous_function.compact
import topology.metric_space.metrizable
import measure_theory.function.simple_func_dense
/-!
# Strongly measurable and finitely strongly measurable functions
A function `f` is said to be strongly measurable if `f` is the sequential limit of simple functions.
It is said to be finitely strongly measurable with respect to a measure `μ` if the supports
of those simple functions have finite measure. We also provide almost everywhere versions of
these notions.
Almost everywhere strongly measurable functions form the largest class of functions that can be
integrated using the Bochner integral.
If the target space has a second countable topology, strongly measurable and measurable are
equivalent.
If the measure is sigma-finite, strongly measurable and finitely strongly measurable are equivalent.
The main property of finitely strongly measurable functions is
`fin_strongly_measurable.exists_set_sigma_finite`: there exists a measurable set `t` such that the
function is supported on `t` and `μ.restrict t` is sigma-finite. As a consequence, we can prove some
results for those functions as if the measure was sigma-finite.
## Main definitions
* `strongly_measurable f`: `f : α → β` is the limit of a sequence `fs : ℕ → simple_func α β`.
* `fin_strongly_measurable f μ`: `f : α → β` is the limit of a sequence `fs : ℕ → simple_func α β`
such that for all `n ∈ ℕ`, the measure of the support of `fs n` is finite.
* `ae_strongly_measurable f μ`: `f` is almost everywhere equal to a `strongly_measurable` function.
* `ae_fin_strongly_measurable f μ`: `f` is almost everywhere equal to a `fin_strongly_measurable`
function.
* `ae_fin_strongly_measurable.sigma_finite_set`: a measurable set `t` such that
`f =ᵐ[μ.restrict tᶜ] 0` and `μ.restrict t` is sigma-finite.
## Main statements
* `ae_fin_strongly_measurable.exists_set_sigma_finite`: there exists a measurable set `t` such that
`f =ᵐ[μ.restrict tᶜ] 0` and `μ.restrict t` is sigma-finite.
We provide a solid API for strongly measurable functions, and for almost everywhere strongly
measurable functions, as a basis for the Bochner integral.
## References
* Hytönen, Tuomas, Jan Van Neerven, Mark Veraar, and Lutz Weis. Analysis in Banach spaces.
Springer, 2016.
-/
open measure_theory filter topological_space function set measure_theory.measure
open_locale ennreal topological_space measure_theory nnreal big_operators
/-- The typeclass `second_countable_topology_either α β` registers the fact that at least one of
the two spaces has second countable topology. This is the right assumption to ensure that continuous
maps from `α` to `β` are strongly measurable. -/
class second_countable_topology_either
(α β : Type*) [topological_space α] [topological_space β] : Prop :=
(out : second_countable_topology α ∨ second_countable_topology β)
@[priority 100] instance second_countable_topology_either_of_left
(α β : Type*) [topological_space α] [topological_space β] [second_countable_topology α] :
second_countable_topology_either α β :=
{ out := or.inl (by apply_instance) }
@[priority 100] instance second_countable_topology_either_of_right
(α β : Type*) [topological_space α] [topological_space β] [second_countable_topology β] :
second_countable_topology_either α β :=
{ out := or.inr (by apply_instance) }
variables {α β γ ι : Type*} [countable ι]
namespace measure_theory
local infixr ` →ₛ `:25 := simple_func
section definitions
variable [topological_space β]
/-- A function is `strongly_measurable` if it is the limit of simple functions. -/
def strongly_measurable [measurable_space α] (f : α → β) : Prop :=
∃ fs : ℕ → α →ₛ β, ∀ x, tendsto (λ n, fs n x) at_top (𝓝 (f x))
localized "notation (name := strongly_measurable_of)
`strongly_measurable[` m `]` := @measure_theory.strongly_measurable _ _ _ m" in measure_theory
/-- A function is `fin_strongly_measurable` with respect to a measure if it is the limit of simple
functions with support with finite measure. -/
def fin_strongly_measurable [has_zero β] {m0 : measurable_space α} (f : α → β) (μ : measure α) :
Prop :=
∃ fs : ℕ → α →ₛ β, (∀ n, μ (support (fs n)) < ∞) ∧ (∀ x, tendsto (λ n, fs n x) at_top (𝓝 (f x)))
/-- A function is `ae_strongly_measurable` with respect to a measure `μ` if it is almost everywhere
equal to the limit of a sequence of simple functions. -/
def ae_strongly_measurable {m0 : measurable_space α} (f : α → β) (μ : measure α) : Prop :=
∃ g, strongly_measurable g ∧ f =ᵐ[μ] g
/-- A function is `ae_fin_strongly_measurable` with respect to a measure if it is almost everywhere
equal to the limit of a sequence of simple functions with support with finite measure. -/
def ae_fin_strongly_measurable [has_zero β] {m0 : measurable_space α} (f : α → β) (μ : measure α) :
Prop :=
∃ g, fin_strongly_measurable g μ ∧ f =ᵐ[μ] g
end definitions
open_locale measure_theory
/-! ## Strongly measurable functions -/
lemma strongly_measurable.ae_strongly_measurable {α β} {m0 : measurable_space α}
[topological_space β] {f : α → β} {μ : measure α} (hf : strongly_measurable f) :
ae_strongly_measurable f μ :=
⟨f, hf, eventually_eq.refl _ _⟩
@[simp] lemma subsingleton.strongly_measurable {α β} [measurable_space α] [topological_space β]
[subsingleton β] (f : α → β) :
strongly_measurable f :=
begin
let f_sf : α →ₛ β := ⟨f, λ x, _, set.subsingleton.finite set.subsingleton_of_subsingleton⟩,
{ exact ⟨λ n, f_sf, λ x, tendsto_const_nhds⟩, },
{ have h_univ : f ⁻¹' {x} = set.univ, by { ext1 y, simp, },
rw h_univ,
exact measurable_set.univ, },
end
lemma simple_func.strongly_measurable {α β} {m : measurable_space α} [topological_space β]
(f : α →ₛ β) :
strongly_measurable f :=
⟨λ _, f, λ x, tendsto_const_nhds⟩
lemma strongly_measurable_of_is_empty [is_empty α] {m : measurable_space α} [topological_space β]
(f : α → β) : strongly_measurable f :=
⟨λ n, simple_func.of_is_empty, is_empty_elim⟩
lemma strongly_measurable_const {α β} {m : measurable_space α} [topological_space β] {b : β} :
strongly_measurable (λ a : α, b) :=
⟨λ n, simple_func.const α b, λ a, tendsto_const_nhds⟩
@[to_additive]
lemma strongly_measurable_one {α β} {m : measurable_space α} [topological_space β] [has_one β] :
strongly_measurable (1 : α → β) :=
@strongly_measurable_const _ _ _ _ 1
/-- A version of `strongly_measurable_const` that assumes `f x = f y` for all `x, y`.
This version works for functions between empty types. -/
lemma strongly_measurable_const' {α β} {m : measurable_space α} [topological_space β] {f : α → β}
(hf : ∀ x y, f x = f y) : strongly_measurable f :=
begin
casesI is_empty_or_nonempty α,
{ exact strongly_measurable_of_is_empty f },
{ convert strongly_measurable_const, exact funext (λ x, hf x h.some) }
end
@[simp] lemma subsingleton.strongly_measurable' {α β} [measurable_space α] [topological_space β]
[subsingleton α] (f : α → β) :
strongly_measurable f :=
strongly_measurable_const' (λ x y, by rw subsingleton.elim x y)
namespace strongly_measurable
variables {f g : α → β}
section basic_properties_in_any_topological_space
variables [topological_space β]
/-- A sequence of simple functions such that `∀ x, tendsto (λ n, hf.approx n x) at_top (𝓝 (f x))`.
That property is given by `strongly_measurable.tendsto_approx`. -/
protected noncomputable
def approx {m : measurable_space α} (hf : strongly_measurable f) : ℕ → α →ₛ β :=
hf.some
protected lemma tendsto_approx {m : measurable_space α} (hf : strongly_measurable f) :
∀ x, tendsto (λ n, hf.approx n x) at_top (𝓝 (f x)) :=
hf.some_spec
/-- Similar to `strongly_measurable.approx`, but enforces that the norm of every function in the
sequence is less than `c` everywhere. If `∥f x∥ ≤ c` this sequence of simple functions verifies
`tendsto (λ n, hf.approx_bounded n x) at_top (𝓝 (f x))`. -/
noncomputable
def approx_bounded {m : measurable_space α}
[has_norm β] [has_smul ℝ β] (hf : strongly_measurable f) (c : ℝ) :
ℕ → simple_func α β :=
λ n, (hf.approx n).map (λ x, (min 1 (c / ∥x∥)) • x)
lemma tendsto_approx_bounded_of_norm_le {β} {f : α → β} [normed_add_comm_group β] [normed_space ℝ β]
{m : measurable_space α} (hf : strongly_measurable[m] f) {c : ℝ} {x : α} (hfx : ∥f x∥ ≤ c) :
tendsto (λ n, hf.approx_bounded c n x) at_top (𝓝 (f x)) :=
begin
have h_tendsto := hf.tendsto_approx x,
simp only [strongly_measurable.approx_bounded, simple_func.coe_map, function.comp_app],
by_cases hfx0 : ∥f x∥ = 0,
{ rw norm_eq_zero at hfx0,
rw hfx0 at h_tendsto ⊢,
have h_tendsto_norm : tendsto (λ n, ∥hf.approx n x∥) at_top (𝓝 0),
{ convert h_tendsto.norm,
rw norm_zero, },
refine squeeze_zero_norm (λ n, _) h_tendsto_norm,
calc ∥min 1 (c / ∥hf.approx n x∥) • hf.approx n x∥
= ∥min 1 (c / ∥hf.approx n x∥)∥ * ∥hf.approx n x∥ : norm_smul _ _
... ≤ ∥(1 : ℝ)∥ * ∥hf.approx n x∥ :
begin
refine mul_le_mul_of_nonneg_right _ (norm_nonneg _),
rw [norm_one, real.norm_of_nonneg],
{ exact min_le_left _ _, },
{ exact le_min zero_le_one
(div_nonneg ((norm_nonneg _).trans hfx) (norm_nonneg _)), },
end
... = ∥hf.approx n x∥ : by rw [norm_one, one_mul], },
rw ← one_smul ℝ (f x),
refine tendsto.smul _ h_tendsto,
have : min 1 (c / ∥f x∥) = 1,
{ rw [min_eq_left_iff, one_le_div (lt_of_le_of_ne (norm_nonneg _) (ne.symm hfx0))],
exact hfx, },
nth_rewrite 0 this.symm,
refine tendsto.min tendsto_const_nhds _,
refine tendsto.div tendsto_const_nhds h_tendsto.norm hfx0,
end
lemma tendsto_approx_bounded_ae {β} {f : α → β} [normed_add_comm_group β] [normed_space ℝ β]
{m m0 : measurable_space α} {μ : measure α}
(hf : strongly_measurable[m] f) {c : ℝ}
(hf_bound : ∀ᵐ x ∂μ, ∥f x∥ ≤ c) :
∀ᵐ x ∂μ, tendsto (λ n, hf.approx_bounded c n x) at_top (𝓝 (f x)) :=
by filter_upwards [hf_bound] with x hfx using tendsto_approx_bounded_of_norm_le hf hfx
lemma norm_approx_bounded_le {β} {f : α → β} [seminormed_add_comm_group β] [normed_space ℝ β]
{m : measurable_space α} {c : ℝ} (hf : strongly_measurable[m] f) (hc : 0 ≤ c) (n : ℕ) (x : α) :
∥hf.approx_bounded c n x∥ ≤ c :=
begin
simp only [strongly_measurable.approx_bounded, simple_func.coe_map, function.comp_app],
refine (norm_smul _ _).le.trans _,
by_cases h0 : ∥hf.approx n x∥ = 0,
{ simp only [h0, div_zero, min_eq_right, zero_le_one, norm_zero, mul_zero],
exact hc, },
cases le_total (∥hf.approx n x∥) c,
{ rw min_eq_left _,
{ simpa only [norm_one, one_mul] using h, },
{ rwa one_le_div (lt_of_le_of_ne (norm_nonneg _) (ne.symm h0)), }, },
{ rw min_eq_right _,
{ rw [norm_div, norm_norm, mul_comm, mul_div, div_eq_mul_inv, mul_comm, ← mul_assoc,
inv_mul_cancel h0, one_mul, real.norm_of_nonneg hc], },
{ rwa div_le_one (lt_of_le_of_ne (norm_nonneg _) (ne.symm h0)), }, },
end
lemma _root_.strongly_measurable_bot_iff [nonempty β] [t2_space β] :
strongly_measurable[⊥] f ↔ ∃ c, f = λ _, c :=
begin
casesI is_empty_or_nonempty α with hα hα,
{ simp only [subsingleton.strongly_measurable', eq_iff_true_of_subsingleton, exists_const], },
refine ⟨λ hf, _, λ hf_eq, _⟩,
{ refine ⟨f hα.some, _⟩,
let fs := hf.approx,
have h_fs_tendsto : ∀ x, tendsto (λ n, fs n x) at_top (𝓝 (f x)) := hf.tendsto_approx,
have : ∀ n, ∃ c, ∀ x, fs n x = c := λ n, simple_func.simple_func_bot (fs n),
let cs := λ n, (this n).some,
have h_cs_eq : ∀ n, ⇑(fs n) = (λ x, cs n) := λ n, funext (this n).some_spec,
simp_rw h_cs_eq at h_fs_tendsto,
have h_tendsto : tendsto cs at_top (𝓝 (f hα.some)) := h_fs_tendsto hα.some,
ext1 x,
exact tendsto_nhds_unique (h_fs_tendsto x) h_tendsto, },
{ obtain ⟨c, rfl⟩ := hf_eq,
exact strongly_measurable_const, },
end
end basic_properties_in_any_topological_space
lemma fin_strongly_measurable_of_set_sigma_finite [topological_space β] [has_zero β]
{m : measurable_space α} {μ : measure α} (hf_meas : strongly_measurable f) {t : set α}
(ht : measurable_set t) (hft_zero : ∀ x ∈ tᶜ, f x = 0) (htμ : sigma_finite (μ.restrict t)) :
fin_strongly_measurable f μ :=
begin
haveI : sigma_finite (μ.restrict t) := htμ,
let S := spanning_sets (μ.restrict t),
have hS_meas : ∀ n, measurable_set (S n), from measurable_spanning_sets (μ.restrict t),
let f_approx := hf_meas.approx,
let fs := λ n, simple_func.restrict (f_approx n) (S n ∩ t),
have h_fs_t_compl : ∀ n, ∀ x ∉ t, fs n x = 0,
{ intros n x hxt,
rw simple_func.restrict_apply _ ((hS_meas n).inter ht),
refine set.indicator_of_not_mem _ _,
simp [hxt], },
refine ⟨fs, _, λ x, _⟩,
{ simp_rw simple_func.support_eq,
refine λ n, (measure_bUnion_finset_le _ _).trans_lt _,
refine ennreal.sum_lt_top_iff.mpr (λ y hy, _),
rw simple_func.restrict_preimage_singleton _ ((hS_meas n).inter ht),
swap, { rw finset.mem_filter at hy, exact hy.2, },
refine (measure_mono (set.inter_subset_left _ _)).trans_lt _,
have h_lt_top := measure_spanning_sets_lt_top (μ.restrict t) n,
rwa measure.restrict_apply' ht at h_lt_top, },
{ by_cases hxt : x ∈ t,
swap, { rw [funext (λ n, h_fs_t_compl n x hxt), hft_zero x hxt], exact tendsto_const_nhds, },
have h : tendsto (λ n, (f_approx n) x) at_top (𝓝 (f x)), from hf_meas.tendsto_approx x,
obtain ⟨n₁, hn₁⟩ : ∃ n, ∀ m, n ≤ m → fs m x = f_approx m x,
{ obtain ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → x ∈ S m ∩ t,
{ rsuffices ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → x ∈ S m,
{ exact ⟨n, λ m hnm, set.mem_inter (hn m hnm) hxt⟩, },
rsuffices ⟨n, hn⟩ : ∃ n, x ∈ S n,
{ exact ⟨n, λ m hnm, monotone_spanning_sets (μ.restrict t) hnm hn⟩, },
rw [← set.mem_Union, Union_spanning_sets (μ.restrict t)],
trivial, },
refine ⟨n, λ m hnm, _⟩,
simp_rw [fs, simple_func.restrict_apply _ ((hS_meas m).inter ht),
set.indicator_of_mem (hn m hnm)], },
rw tendsto_at_top' at h ⊢,
intros s hs,
obtain ⟨n₂, hn₂⟩ := h s hs,
refine ⟨max n₁ n₂, λ m hm, _⟩,
rw hn₁ m ((le_max_left _ _).trans hm.le),
exact hn₂ m ((le_max_right _ _).trans hm.le), },
end
/-- If the measure is sigma-finite, all strongly measurable functions are
`fin_strongly_measurable`. -/
protected lemma fin_strongly_measurable [topological_space β] [has_zero β] {m0 : measurable_space α}
(hf : strongly_measurable f) (μ : measure α) [sigma_finite μ] :
fin_strongly_measurable f μ :=
hf.fin_strongly_measurable_of_set_sigma_finite measurable_set.univ (by simp)
(by rwa measure.restrict_univ)
/-- A strongly measurable function is measurable. -/
protected lemma measurable {m : measurable_space α} [topological_space β]
[pseudo_metrizable_space β] [measurable_space β] [borel_space β] (hf : strongly_measurable f) :
measurable f :=
measurable_of_tendsto_metrizable (λ n, (hf.approx n).measurable)
(tendsto_pi_nhds.mpr hf.tendsto_approx)
/-- A strongly measurable function is almost everywhere measurable. -/
protected lemma ae_measurable {m : measurable_space α} [topological_space β]
[pseudo_metrizable_space β] [measurable_space β] [borel_space β] {μ : measure α}
(hf : strongly_measurable f) :
ae_measurable f μ :=
hf.measurable.ae_measurable
lemma _root_.continuous.comp_strongly_measurable
{m : measurable_space α} [topological_space β] [topological_space γ] {g : β → γ} {f : α → β}
(hg : continuous g) (hf : strongly_measurable f) : strongly_measurable (λ x, g (f x)) :=
⟨λ n, simple_func.map g (hf.approx n), λ x, (hg.tendsto _).comp (hf.tendsto_approx x)⟩
@[to_additive]
lemma measurable_set_mul_support {m : measurable_space α}
[has_one β] [topological_space β] [metrizable_space β] (hf : strongly_measurable f) :
measurable_set (mul_support f) :=
by { borelize β, exact measurable_set_mul_support hf.measurable }
protected lemma mono {m m' : measurable_space α} [topological_space β]
(hf : strongly_measurable[m'] f) (h_mono : m' ≤ m) :
strongly_measurable[m] f :=
begin
let f_approx : ℕ → @simple_func α m β := λ n,
{ to_fun := hf.approx n,
measurable_set_fiber' := λ x, h_mono _ (simple_func.measurable_set_fiber' _ x),
finite_range' := simple_func.finite_range (hf.approx n) },
exact ⟨f_approx, hf.tendsto_approx⟩,
end
protected lemma prod_mk {m : measurable_space α} [topological_space β] [topological_space γ]
{f : α → β} {g : α → γ} (hf : strongly_measurable f) (hg : strongly_measurable g) :
strongly_measurable (λ x, (f x, g x)) :=
begin
refine ⟨λ n, simple_func.pair (hf.approx n) (hg.approx n), λ x, _⟩,
rw nhds_prod_eq,
exact tendsto.prod_mk (hf.tendsto_approx x) (hg.tendsto_approx x),
end
lemma comp_measurable [topological_space β] {m : measurable_space α} {m' : measurable_space γ}
{f : α → β} {g : γ → α} (hf : strongly_measurable f) (hg : measurable g) :
strongly_measurable (f ∘ g) :=
⟨λ n, simple_func.comp (hf.approx n) g hg, λ x, hf.tendsto_approx (g x)⟩
lemma of_uncurry_left [topological_space β] {mα : measurable_space α} {mγ : measurable_space γ}
{f : α → γ → β} (hf : strongly_measurable (uncurry f)) {x : α} :
strongly_measurable (f x) :=
hf.comp_measurable measurable_prod_mk_left
lemma of_uncurry_right [topological_space β] {mα : measurable_space α} {mγ : measurable_space γ}
{f : α → γ → β} (hf : strongly_measurable (uncurry f)) {y : γ} :
strongly_measurable (λ x, f x y) :=
hf.comp_measurable measurable_prod_mk_right
section arithmetic
variables {mα : measurable_space α} [topological_space β]
include mα
@[to_additive]
protected lemma mul [has_mul β] [has_continuous_mul β]
(hf : strongly_measurable f) (hg : strongly_measurable g) :
strongly_measurable (f * g) :=
⟨λ n, hf.approx n * hg.approx n, λ x, (hf.tendsto_approx x).mul (hg.tendsto_approx x)⟩
@[to_additive]
lemma mul_const [has_mul β] [has_continuous_mul β] (hf : strongly_measurable f) (c : β) :
strongly_measurable (λ x, f x * c) :=
hf.mul strongly_measurable_const
@[to_additive]
lemma const_mul [has_mul β] [has_continuous_mul β] (hf : strongly_measurable f) (c : β) :
strongly_measurable (λ x, c * f x) :=
strongly_measurable_const.mul hf
@[to_additive]
protected lemma inv [group β] [topological_group β] (hf : strongly_measurable f) :
strongly_measurable f⁻¹ :=
⟨λ n, (hf.approx n)⁻¹, λ x, (hf.tendsto_approx x).inv⟩
@[to_additive]
protected lemma div [has_div β] [has_continuous_div β]
(hf : strongly_measurable f) (hg : strongly_measurable g) :
strongly_measurable (f / g) :=
⟨λ n, hf.approx n / hg.approx n, λ x, (hf.tendsto_approx x).div' (hg.tendsto_approx x)⟩
@[to_additive]
protected lemma smul {𝕜} [topological_space 𝕜] [has_smul 𝕜 β] [has_continuous_smul 𝕜 β]
{f : α → 𝕜} {g : α → β} (hf : strongly_measurable f) (hg : strongly_measurable g) :
strongly_measurable (λ x, f x • g x) :=
continuous_smul.comp_strongly_measurable (hf.prod_mk hg)
protected lemma const_smul {𝕜} [has_smul 𝕜 β] [has_continuous_const_smul 𝕜 β]
(hf : strongly_measurable f) (c : 𝕜) :
strongly_measurable (c • f) :=
⟨λ n, c • (hf.approx n), λ x, (hf.tendsto_approx x).const_smul c⟩
protected lemma const_smul' {𝕜} [has_smul 𝕜 β] [has_continuous_const_smul 𝕜 β]
(hf : strongly_measurable f) (c : 𝕜) :
strongly_measurable (λ x, c • (f x)) :=
hf.const_smul c
@[to_additive]
protected lemma smul_const {𝕜} [topological_space 𝕜] [has_smul 𝕜 β] [has_continuous_smul 𝕜 β]
{f : α → 𝕜} (hf : strongly_measurable f) (c : β) :
strongly_measurable (λ x, f x • c) :=
continuous_smul.comp_strongly_measurable (hf.prod_mk strongly_measurable_const)
end arithmetic
section mul_action
variables [topological_space β] {G : Type*} [group G] [mul_action G β]
[has_continuous_const_smul G β]
lemma _root_.strongly_measurable_const_smul_iff {m : measurable_space α} (c : G) :
strongly_measurable (λ x, c • f x) ↔ strongly_measurable f :=
⟨λ h, by simpa only [inv_smul_smul] using h.const_smul' c⁻¹, λ h, h.const_smul c⟩
variables {G₀ : Type*} [group_with_zero G₀] [mul_action G₀ β]
[has_continuous_const_smul G₀ β]
lemma _root_.strongly_measurable_const_smul_iff₀ {m : measurable_space α} {c : G₀} (hc : c ≠ 0) :
strongly_measurable (λ x, c • f x) ↔ strongly_measurable f :=
begin
refine ⟨λ h, _, λ h, h.const_smul c⟩,
convert h.const_smul' c⁻¹,
simp [smul_smul, inv_mul_cancel hc]
end
end mul_action
section order
variables [measurable_space α] [topological_space β]
open filter
open_locale filter
protected lemma sup [has_sup β] [has_continuous_sup β] (hf : strongly_measurable f)
(hg : strongly_measurable g) :
strongly_measurable (f ⊔ g) :=
⟨λ n, hf.approx n ⊔ hg.approx n, λ x, (hf.tendsto_approx x).sup_right_nhds (hg.tendsto_approx x)⟩
protected lemma inf [has_inf β] [has_continuous_inf β] (hf : strongly_measurable f)
(hg : strongly_measurable g) :
strongly_measurable (f ⊓ g) :=
⟨λ n, hf.approx n ⊓ hg.approx n, λ x, (hf.tendsto_approx x).inf_right_nhds (hg.tendsto_approx x)⟩
end order
/-!
### Big operators: `∏` and `∑`
-/
section monoid
variables {M : Type*} [monoid M] [topological_space M] [has_continuous_mul M]
{m : measurable_space α}
include m
@[to_additive]
lemma _root_.list.strongly_measurable_prod'
(l : list (α → M)) (hl : ∀ f ∈ l, strongly_measurable f) :
strongly_measurable l.prod :=
begin
induction l with f l ihl, { exact strongly_measurable_one },
rw [list.forall_mem_cons] at hl,
rw [list.prod_cons],
exact hl.1.mul (ihl hl.2)
end
@[to_additive]
lemma _root_.list.strongly_measurable_prod
(l : list (α → M)) (hl : ∀ f ∈ l, strongly_measurable f) :
strongly_measurable (λ x, (l.map (λ f : α → M, f x)).prod) :=
by simpa only [← pi.list_prod_apply] using l.strongly_measurable_prod' hl
end monoid
section comm_monoid
variables {M : Type*} [comm_monoid M] [topological_space M] [has_continuous_mul M]
{m : measurable_space α}
include m
@[to_additive]
lemma _root_.multiset.strongly_measurable_prod'
(l : multiset (α → M)) (hl : ∀ f ∈ l, strongly_measurable f) :
strongly_measurable l.prod :=
by { rcases l with ⟨l⟩, simpa using l.strongly_measurable_prod' (by simpa using hl) }
@[to_additive]
lemma _root_.multiset.strongly_measurable_prod
(s : multiset (α → M)) (hs : ∀ f ∈ s, strongly_measurable f) :
strongly_measurable (λ x, (s.map (λ f : α → M, f x)).prod) :=
by simpa only [← pi.multiset_prod_apply] using s.strongly_measurable_prod' hs
@[to_additive]
lemma _root_.finset.strongly_measurable_prod'
{ι : Type*} {f : ι → α → M} (s : finset ι) (hf : ∀i ∈ s, strongly_measurable (f i)) :
strongly_measurable (∏ i in s, f i) :=
finset.prod_induction _ _ (λ a b ha hb, ha.mul hb) (@strongly_measurable_one α M _ _ _) hf
@[to_additive]
lemma _root_.finset.strongly_measurable_prod
{ι : Type*} {f : ι → α → M} (s : finset ι) (hf : ∀i ∈ s, strongly_measurable (f i)) :
strongly_measurable (λ a, ∏ i in s, f i a) :=
by simpa only [← finset.prod_apply] using s.strongly_measurable_prod' hf
end comm_monoid
/-- The range of a strongly measurable function is separable. -/
lemma is_separable_range {m : measurable_space α} [topological_space β]
(hf : strongly_measurable f) :
topological_space.is_separable (range f) :=
begin
have : is_separable (closure (⋃ n, range (hf.approx n))) :=
(is_separable_Union (λ n, (simple_func.finite_range (hf.approx n)).is_separable)).closure,
apply this.mono,
rintros _ ⟨x, rfl⟩,
apply mem_closure_of_tendsto (hf.tendsto_approx x),
apply eventually_of_forall (λ n, _),
apply mem_Union_of_mem n,
exact mem_range_self _
end
lemma separable_space_range_union_singleton {m : measurable_space α} [topological_space β]
[pseudo_metrizable_space β] (hf : strongly_measurable f) {b : β} :
separable_space (range f ∪ {b} : set β) :=
begin
letI := pseudo_metrizable_space_pseudo_metric β,
exact (hf.is_separable_range.union (finite_singleton _).is_separable).separable_space
end
section second_countable_strongly_measurable
variables {mα : measurable_space α} [measurable_space β]
include mα
/-- In a space with second countable topology, measurable implies strongly measurable. -/
lemma _root_.measurable.strongly_measurable [topological_space β] [pseudo_metrizable_space β]
[second_countable_topology β] [opens_measurable_space β] (hf : measurable f) :
strongly_measurable f :=
begin
letI := pseudo_metrizable_space_pseudo_metric β,
rcases is_empty_or_nonempty β; resetI,
{ exact subsingleton.strongly_measurable f, },
{ inhabit β,
exact ⟨simple_func.approx_on f hf set.univ default (set.mem_univ _),
λ x, simple_func.tendsto_approx_on hf (set.mem_univ _) (by simp)⟩, },
end
/-- In a space with second countable topology, strongly measurable and measurable are equivalent. -/
lemma _root_.strongly_measurable_iff_measurable
[topological_space β] [metrizable_space β] [borel_space β] [second_countable_topology β] :
strongly_measurable f ↔ measurable f :=
⟨λ h, h.measurable, λ h, measurable.strongly_measurable h⟩
lemma _root_.strongly_measurable_id [topological_space α] [pseudo_metrizable_space α]
[opens_measurable_space α] [second_countable_topology α] :
strongly_measurable (id : α → α) :=
measurable_id.strongly_measurable
end second_countable_strongly_measurable
/-- A function is strongly measurable if and only if it is measurable and has separable
range. -/
theorem _root_.strongly_measurable_iff_measurable_separable {m : measurable_space α}
[topological_space β] [pseudo_metrizable_space β] [measurable_space β] [borel_space β] :
strongly_measurable f ↔ (measurable f ∧ is_separable (range f)) :=
begin
refine ⟨λ H, ⟨H.measurable, H.is_separable_range⟩, _⟩,
rintros ⟨H, H'⟩,
letI := pseudo_metrizable_space_pseudo_metric β,
let g := cod_restrict f (closure (range f)) (λ x, subset_closure (mem_range_self x)),
have fg : f = (coe : closure (range f) → β) ∘ g, by { ext x, refl },
have T : measurable_embedding (coe : closure (range f) → β),
{ apply closed_embedding.measurable_embedding,
exact closed_embedding_subtype_coe is_closed_closure },
have g_meas : measurable g,
{ rw fg at H, exact T.measurable_comp_iff.1 H },
haveI : second_countable_topology (closure (range f)),
{ suffices : separable_space (closure (range f)),
by exactI uniform_space.second_countable_of_separable _,
exact (is_separable.closure H').separable_space },
have g_smeas : strongly_measurable g := measurable.strongly_measurable g_meas,
rw fg,
exact continuous_subtype_coe.comp_strongly_measurable g_smeas,
end
/-- A continuous function is strongly measurable when either the source space or the target space
is second-countable. -/
lemma _root_.continuous.strongly_measurable [measurable_space α]
[topological_space α] [opens_measurable_space α]
{β : Type*} [topological_space β] [pseudo_metrizable_space β]
[h : second_countable_topology_either α β]
{f : α → β} (hf : continuous f) :
strongly_measurable f :=
begin
borelize β,
casesI h.out,
{ rw strongly_measurable_iff_measurable_separable,
refine ⟨hf.measurable, _⟩,
rw ← image_univ,
exact (is_separable_of_separable_space univ).image hf },
{ exact hf.measurable.strongly_measurable }
end
/-- If `g` is a topological embedding, then `f` is strongly measurable iff `g ∘ f` is. -/
lemma _root_.embedding.comp_strongly_measurable_iff {m : measurable_space α}
[topological_space β] [pseudo_metrizable_space β] [topological_space γ]
[pseudo_metrizable_space γ]
{g : β → γ} {f : α → β} (hg : embedding g) :
strongly_measurable (λ x, g (f x)) ↔ strongly_measurable f :=
begin
letI := pseudo_metrizable_space_pseudo_metric γ,
borelize [β, γ],
refine ⟨λ H, strongly_measurable_iff_measurable_separable.2 ⟨_, _⟩,
λ H, hg.continuous.comp_strongly_measurable H⟩,
{ let G : β → range g := cod_restrict g (range g) mem_range_self,
have hG : closed_embedding G :=
{ closed_range :=
begin
convert is_closed_univ,
apply eq_univ_of_forall,
rintros ⟨-, ⟨x, rfl⟩⟩,
exact mem_range_self x
end,
.. hg.cod_restrict _ _ },
have : measurable (G ∘ f) := measurable.subtype_mk H.measurable,
exact hG.measurable_embedding.measurable_comp_iff.1 this },
{ have : is_separable (g ⁻¹' (range (g ∘ f))) := hg.is_separable_preimage H.is_separable_range,
convert this,
ext x,
simp [hg.inj.eq_iff] }
end
/-- A sequential limit of strongly measurable functions is strongly measurable. -/
lemma _root_.strongly_measurable_of_tendsto {ι : Type*} {m : measurable_space α}
[topological_space β] [pseudo_metrizable_space β] (u : filter ι) [ne_bot u]
[is_countably_generated u] {f : ι → α → β} {g : α → β} (hf : ∀ i, strongly_measurable (f i))
(lim : tendsto f u (𝓝 g)) :
strongly_measurable g :=
begin
borelize β,
refine strongly_measurable_iff_measurable_separable.2 ⟨_, _⟩,
{ exact measurable_of_tendsto_metrizable' u (λ i, (hf i).measurable) lim },
{ rcases u.exists_seq_tendsto with ⟨v, hv⟩,
have : is_separable (closure (⋃ i, range (f (v i)))) :=
(is_separable_Union (λ i, (hf (v i)).is_separable_range)).closure,
apply this.mono,
rintros _ ⟨x, rfl⟩,
rw [tendsto_pi_nhds] at lim,
apply mem_closure_of_tendsto ((lim x).comp hv),
apply eventually_of_forall (λ n, _),
apply mem_Union_of_mem n,
exact mem_range_self _ }
end
protected lemma piecewise {m : measurable_space α} [topological_space β]
{s : set α} {_ : decidable_pred (∈ s)} (hs : measurable_set s)
(hf : strongly_measurable f) (hg : strongly_measurable g) :
strongly_measurable (set.piecewise s f g) :=
begin
refine ⟨λ n, simple_func.piecewise s hs (hf.approx n) (hg.approx n), λ x, _⟩,
by_cases hx : x ∈ s,
{ simpa [hx] using hf.tendsto_approx x },
{ simpa [hx] using hg.tendsto_approx x },
end
/-- this is slightly different from `strongly_measurable.piecewise`. It can be used to show
`strongly_measurable (ite (x=0) 0 1)` by
`exact strongly_measurable.ite (measurable_set_singleton 0) strongly_measurable_const
strongly_measurable_const`, but replacing `strongly_measurable.ite` by
`strongly_measurable.piecewise` in that example proof does not work. -/
protected lemma ite {m : measurable_space α} [topological_space β]
{p : α → Prop} {_ : decidable_pred p}
(hp : measurable_set {a : α | p a}) (hf : strongly_measurable f) (hg : strongly_measurable g) :
strongly_measurable (λ x, ite (p x) (f x) (g x)) :=
strongly_measurable.piecewise hp hf hg
lemma _root_.strongly_measurable_of_strongly_measurable_union_cover
{m : measurable_space α} [topological_space β]
{f : α → β} (s t : set α) (hs : measurable_set s) (ht : measurable_set t) (h : univ ⊆ s ∪ t)
(hc : strongly_measurable (λ a : s, f a)) (hd : strongly_measurable (λ a : t, f a)) :
strongly_measurable f :=
begin
classical,
let f : ℕ → α →ₛ β := λ n,
{ to_fun := λ x, if hx : x ∈ s then hc.approx n ⟨x, hx⟩
else hd.approx n ⟨x, by simpa [hx] using h (mem_univ x)⟩,
measurable_set_fiber' :=
begin
assume x,
convert (hs.subtype_image
((hc.approx n).measurable_set_fiber x)).union
((ht.subtype_image
((hd.approx n).measurable_set_fiber x)).diff hs),
ext1 y,
simp only [mem_union_eq, mem_preimage, mem_singleton_iff, mem_image, set_coe.exists,
subtype.coe_mk, exists_and_distrib_right, exists_eq_right, mem_diff],
by_cases hy : y ∈ s,
{ rw dif_pos hy,
simp only [hy, exists_true_left, not_true, and_false, or_false]},
{ rw dif_neg hy,
have A : y ∈ t, by simpa [hy] using h (mem_univ y),
simp only [A, hy, false_or, is_empty.exists_iff, not_false_iff, and_true,
exists_true_left] }
end,
finite_range' :=
begin
apply ((hc.approx n).finite_range.union (hd.approx n).finite_range).subset,
rintros - ⟨y, rfl⟩,
dsimp,
by_cases hy : y ∈ s,
{ left,
rw dif_pos hy,
exact mem_range_self _ },
{ right,
rw dif_neg hy,
exact mem_range_self _ }
end },
refine ⟨f, λ y, _⟩,
by_cases hy : y ∈ s,
{ convert hc.tendsto_approx ⟨y, hy⟩ using 1,
ext1 n,
simp only [dif_pos hy, simple_func.apply_mk] },
{ have A : y ∈ t, by simpa [hy] using h (mem_univ y),
convert hd.tendsto_approx ⟨y, A⟩ using 1,
ext1 n,
simp only [dif_neg hy, simple_func.apply_mk] }
end
lemma _root_.strongly_measurable_of_restrict_of_restrict_compl
{m : measurable_space α} [topological_space β] {f : α → β} {s : set α} (hs : measurable_set s)
(h₁ : strongly_measurable (s.restrict f)) (h₂ : strongly_measurable (sᶜ.restrict f)) :
strongly_measurable f :=
strongly_measurable_of_strongly_measurable_union_cover s sᶜ hs hs.compl
(union_compl_self s).ge h₁ h₂
protected lemma indicator {m : measurable_space α} [topological_space β] [has_zero β]
(hf : strongly_measurable f) {s : set α} (hs : measurable_set s) :
strongly_measurable (s.indicator f) :=
hf.piecewise hs strongly_measurable_const
protected lemma dist {m : measurable_space α} {β : Type*} [pseudo_metric_space β] {f g : α → β}
(hf : strongly_measurable f) (hg : strongly_measurable g) :
strongly_measurable (λ x, dist (f x) (g x)) :=
continuous_dist.comp_strongly_measurable (hf.prod_mk hg)
protected lemma norm {m : measurable_space α} {β : Type*} [seminormed_add_comm_group β]
{f : α → β} (hf : strongly_measurable f) :
strongly_measurable (λ x, ∥f x∥) :=
continuous_norm.comp_strongly_measurable hf
protected lemma nnnorm {m : measurable_space α} {β : Type*} [seminormed_add_comm_group β]
{f : α → β} (hf : strongly_measurable f) :
strongly_measurable (λ x, ∥f x∥₊) :=
continuous_nnnorm.comp_strongly_measurable hf
protected lemma ennnorm {m : measurable_space α} {β : Type*} [seminormed_add_comm_group β]
{f : α → β} (hf : strongly_measurable f) :
measurable (λ a, (∥f a∥₊ : ℝ≥0∞)) :=
(ennreal.continuous_coe.comp_strongly_measurable hf.nnnorm).measurable
protected lemma real_to_nnreal {m : measurable_space α} {f : α → ℝ}
(hf : strongly_measurable f) :
strongly_measurable (λ x, (f x).to_nnreal) :=
continuous_real_to_nnreal.comp_strongly_measurable hf
lemma _root_.measurable_embedding.strongly_measurable_extend {f : α → β} {g : α → γ} {g' : γ → β}
{mα : measurable_space α} {mγ : measurable_space γ} [topological_space β]
(hg : measurable_embedding g)
(hf : strongly_measurable f) (hg' : strongly_measurable g') :
strongly_measurable (function.extend g f g') :=
begin
refine ⟨λ n, simple_func.extend (hf.approx n) g hg (hg'.approx n), _⟩,
assume x,
by_cases hx : ∃ y, g y = x,
{ rcases hx with ⟨y, rfl⟩,
simpa only [simple_func.extend_apply, hg.injective, extend_apply] using hf.tendsto_approx y },
{ simpa only [hx, simple_func.extend_apply', not_false_iff, extend_apply']
using hg'.tendsto_approx x }
end
lemma _root_.measurable_embedding.exists_strongly_measurable_extend
{f : α → β} {g : α → γ}
{mα : measurable_space α} {mγ : measurable_space γ} [topological_space β]
(hg : measurable_embedding g) (hf : strongly_measurable f) (hne : γ → nonempty β) :
∃ f' : γ → β, strongly_measurable f' ∧ f' ∘ g = f :=
⟨function.extend g f (λ x, classical.choice (hne x)),
hg.strongly_measurable_extend hf (strongly_measurable_const' $ λ _ _, rfl),
funext $ λ x, extend_apply hg.injective _ _ _⟩
protected lemma inner {𝕜 : Type*} {E : Type*} [is_R_or_C 𝕜] [inner_product_space 𝕜 E]
{m : measurable_space α} {f g : α → E} (hf : strongly_measurable f) (hg : strongly_measurable g) :
strongly_measurable (λ t, @inner 𝕜 _ _(f t) (g t)) :=
continuous.comp_strongly_measurable continuous_inner (hf.prod_mk hg)
lemma measurable_set_eq_fun {m : measurable_space α} {E} [topological_space E] [metrizable_space E]
{f g : α → E} (hf : strongly_measurable f) (hg : strongly_measurable g) :
measurable_set {x | f x = g x} :=
begin
borelize E × E,
exact (hf.prod_mk hg).measurable is_closed_diagonal.measurable_set
end
lemma measurable_set_lt {m : measurable_space α} [topological_space β]
[linear_order β] [order_closed_topology β] [pseudo_metrizable_space β]
{f g : α → β} (hf : strongly_measurable f) (hg : strongly_measurable g) :
measurable_set {a | f a < g a} :=
begin
borelize β × β,
exact (hf.prod_mk hg).measurable is_open_lt_prod.measurable_set
end
lemma measurable_set_le {m : measurable_space α} [topological_space β]
[preorder β] [order_closed_topology β] [pseudo_metrizable_space β]
{f g : α → β} (hf : strongly_measurable f) (hg : strongly_measurable g) :
measurable_set {a | f a ≤ g a} :=
begin
borelize β × β,
exact (hf.prod_mk hg).measurable is_closed_le_prod.measurable_set
end
lemma strongly_measurable_in_set {m : measurable_space α} [topological_space β] [has_zero β]
{s : set α} {f : α → β}
(hs : measurable_set s) (hf : strongly_measurable f) (hf_zero : ∀ x ∉ s, f x = 0) :
∃ fs : ℕ → α →ₛ β, (∀ x, tendsto (λ n, fs n x) at_top (𝓝 (f x))) ∧ (∀ (x ∉ s) n, fs n x = 0) :=
begin
let g_seq_s : ℕ → @simple_func α m β := λ n, (hf.approx n).restrict s,
have hg_eq : ∀ x ∈ s, ∀ n, g_seq_s n x = hf.approx n x,
{ intros x hx n,
rw [simple_func.coe_restrict _ hs, set.indicator_of_mem hx], },
have hg_zero : ∀ x ∉ s, ∀ n, g_seq_s n x = 0,
{ intros x hx n,
rw [simple_func.coe_restrict _ hs, set.indicator_of_not_mem hx], },
refine ⟨g_seq_s, λ x, _, hg_zero⟩,
by_cases hx : x ∈ s,
{ simp_rw hg_eq x hx,
exact hf.tendsto_approx x, },
{ simp_rw [hg_zero x hx, hf_zero x hx],
exact tendsto_const_nhds, },
end
/-- If the restriction to a set `s` of a σ-algebra `m` is included in the restriction to `s` of
another σ-algebra `m₂` (hypothesis `hs`), the set `s` is `m` measurable and a function `f` supported
on `s` is `m`-strongly-measurable, then `f` is also `m₂`-strongly-measurable. -/
lemma strongly_measurable_of_measurable_space_le_on {α E} {m m₂ : measurable_space α}
[topological_space E] [has_zero E] {s : set α} {f : α → E}
(hs_m : measurable_set[m] s) (hs : ∀ t, measurable_set[m] (s ∩ t) → measurable_set[m₂] (s ∩ t))
(hf : strongly_measurable[m] f) (hf_zero : ∀ x ∉ s, f x = 0) :
strongly_measurable[m₂] f :=
begin
have hs_m₂ : measurable_set[m₂] s,
{ rw ← set.inter_univ s,
refine hs set.univ _,
rwa [set.inter_univ], },
obtain ⟨g_seq_s, hg_seq_tendsto, hg_seq_zero⟩ := strongly_measurable_in_set hs_m hf hf_zero,
let g_seq_s₂ : ℕ → @simple_func α m₂ E := λ n,
{ to_fun := g_seq_s n,
measurable_set_fiber' := λ x, begin
rw [← set.inter_univ ((g_seq_s n) ⁻¹' {x}), ← set.union_compl_self s,
set.inter_union_distrib_left, set.inter_comm ((g_seq_s n) ⁻¹' {x})],
refine measurable_set.union (hs _ (hs_m.inter _)) _,
{ exact @simple_func.measurable_set_fiber _ _ m _ _, },
by_cases hx : x = 0,
{ suffices : (g_seq_s n) ⁻¹' {x} ∩ sᶜ = sᶜ, by { rw this, exact hs_m₂.compl, },
ext1 y,
rw [hx, set.mem_inter_iff, set.mem_preimage, set.mem_singleton_iff],
exact ⟨λ h, h.2, λ h, ⟨hg_seq_zero y h n, h⟩⟩, },
{ suffices : (g_seq_s n) ⁻¹' {x} ∩ sᶜ = ∅, by { rw this, exact measurable_set.empty, },
ext1 y,
simp only [mem_inter_eq, mem_preimage, mem_singleton_iff, mem_compl_eq, mem_empty_eq,
iff_false, not_and, not_not_mem],
refine imp_of_not_imp_not _ _ (λ hys, _),
rw hg_seq_zero y hys n,
exact ne.symm hx, },
end,
finite_range' := @simple_func.finite_range _ _ m (g_seq_s n), },
have hg_eq : ∀ x n, g_seq_s₂ n x = g_seq_s n x := λ x n, rfl,
refine ⟨g_seq_s₂, λ x, _⟩,
simp_rw hg_eq,
exact hg_seq_tendsto x,
end
/-- If a function `f` is strongly measurable w.r.t. a sub-σ-algebra `m` and the measure is σ-finite
on `m`, then there exists spanning measurable sets with finite measure on which `f` has bounded
norm. In particular, `f` is integrable on each of those sets. -/
lemma exists_spanning_measurable_set_norm_le [seminormed_add_comm_group β]
{m m0 : measurable_space α} (hm : m ≤ m0) (hf : strongly_measurable[m] f) (μ : measure α)
[sigma_finite (μ.trim hm)] :
∃ s : ℕ → set α, (∀ n, measurable_set[m] (s n) ∧ μ (s n) < ∞ ∧ ∀ x ∈ s n, ∥f x∥ ≤ n)
∧ (⋃ i, s i) = set.univ :=
begin
let sigma_finite_sets := spanning_sets (μ.trim hm),
let norm_sets := λ (n : ℕ), {x | ∥f x∥ ≤ n},
have norm_sets_spanning : (⋃ n, norm_sets n) = set.univ,
{ ext1 x, simp only [set.mem_Union, set.mem_set_of_eq, set.mem_univ, iff_true],
exact ⟨⌈∥f x∥⌉₊, nat.le_ceil (∥f x∥)⟩, },
let sets := λ n, sigma_finite_sets n ∩ norm_sets n,
have h_meas : ∀ n, measurable_set[m] (sets n),
{ refine λ n, measurable_set.inter _ _,
{ exact measurable_spanning_sets (μ.trim hm) n, },
{ exact hf.norm.measurable_set_le strongly_measurable_const, }, },
have h_finite : ∀ n, μ (sets n) < ∞,
{ refine λ n, (measure_mono (set.inter_subset_left _ _)).trans_lt _,
exact (le_trim hm).trans_lt (measure_spanning_sets_lt_top (μ.trim hm) n), },
refine ⟨sets, λ n, ⟨h_meas n, h_finite n, _⟩, _⟩,
{ exact λ x hx, hx.2, },
{ have : (⋃ i, sigma_finite_sets i ∩ norm_sets i)
= (⋃ i, sigma_finite_sets i) ∩ (⋃ i, norm_sets i),
{ refine set.Union_inter_of_monotone (monotone_spanning_sets (μ.trim hm)) (λ i j hij x, _),
simp only [norm_sets, set.mem_set_of_eq],
refine λ hif, hif.trans _,
exact_mod_cast hij, },
rw [this, norm_sets_spanning, Union_spanning_sets (μ.trim hm), set.inter_univ], },
end
end strongly_measurable
/-! ## Finitely strongly measurable functions -/
lemma fin_strongly_measurable_zero {α β} {m : measurable_space α} {μ : measure α} [has_zero β]
[topological_space β] :
fin_strongly_measurable (0 : α → β) μ :=
⟨0, by simp only [pi.zero_apply, simple_func.coe_zero, support_zero', measure_empty,
with_top.zero_lt_top, forall_const],
λ n, tendsto_const_nhds⟩
namespace fin_strongly_measurable
variables {m0 : measurable_space α} {μ : measure α} {f g : α → β}
lemma ae_fin_strongly_measurable [has_zero β] [topological_space β]
(hf : fin_strongly_measurable f μ) :
ae_fin_strongly_measurable f μ :=
⟨f, hf, ae_eq_refl f⟩
section sequence
variables [has_zero β] [topological_space β] (hf : fin_strongly_measurable f μ)
/-- A sequence of simple functions such that `∀ x, tendsto (λ n, hf.approx n x) at_top (𝓝 (f x))`
and `∀ n, μ (support (hf.approx n)) < ∞`. These properties are given by
`fin_strongly_measurable.tendsto_approx` and `fin_strongly_measurable.fin_support_approx`. -/
protected noncomputable def approx : ℕ → α →ₛ β := hf.some
protected lemma fin_support_approx : ∀ n, μ (support (hf.approx n)) < ∞ := hf.some_spec.1
protected lemma tendsto_approx : ∀ x, tendsto (λ n, hf.approx n x) at_top (𝓝 (f x)) :=
hf.some_spec.2
end sequence
protected lemma strongly_measurable [has_zero β] [topological_space β]
(hf : fin_strongly_measurable f μ) :
strongly_measurable f :=
⟨hf.approx, hf.tendsto_approx⟩
lemma exists_set_sigma_finite [has_zero β] [topological_space β] [t2_space β]
(hf : fin_strongly_measurable f μ) :
∃ t, measurable_set t ∧ (∀ x ∈ tᶜ, f x = 0) ∧ sigma_finite (μ.restrict t) :=
begin
rcases hf with ⟨fs, hT_lt_top, h_approx⟩,
let T := λ n, support (fs n),
have hT_meas : ∀ n, measurable_set (T n), from λ n, simple_func.measurable_set_support (fs n),
let t := ⋃ n, T n,
refine ⟨t, measurable_set.Union hT_meas, _, _⟩,
{ have h_fs_zero : ∀ n, ∀ x ∈ tᶜ, fs n x = 0,
{ intros n x hxt,
rw [set.mem_compl_iff, set.mem_Union, not_exists] at hxt,
simpa using (hxt n), },
refine λ x hxt, tendsto_nhds_unique (h_approx x) _,
rw funext (λ n, h_fs_zero n x hxt),
exact tendsto_const_nhds, },
{ refine ⟨⟨⟨λ n, tᶜ ∪ T n, λ n, trivial, λ n, _, _⟩⟩⟩,
{ rw [measure.restrict_apply' (measurable_set.Union hT_meas), set.union_inter_distrib_right,
set.compl_inter_self t, set.empty_union],
exact (measure_mono (set.inter_subset_left _ _)).trans_lt (hT_lt_top n), },
{ rw ← set.union_Union tᶜ T,
exact set.compl_union_self _ } }
end
/-- A finitely strongly measurable function is measurable. -/
protected lemma measurable [has_zero β] [topological_space β] [pseudo_metrizable_space β]
[measurable_space β] [borel_space β] (hf : fin_strongly_measurable f μ) :
measurable f :=
hf.strongly_measurable.measurable
section arithmetic
variables [topological_space β]
protected lemma mul [monoid_with_zero β] [has_continuous_mul β]
(hf : fin_strongly_measurable f μ) (hg : fin_strongly_measurable g μ) :
fin_strongly_measurable (f * g) μ :=
begin
refine ⟨λ n, hf.approx n * hg.approx n, _, λ x, (hf.tendsto_approx x).mul (hg.tendsto_approx x)⟩,
intro n,
exact (measure_mono (support_mul_subset_left _ _)).trans_lt (hf.fin_support_approx n),
end
protected lemma add [add_monoid β] [has_continuous_add β]
(hf : fin_strongly_measurable f μ) (hg : fin_strongly_measurable g μ) :
fin_strongly_measurable (f + g) μ :=
⟨λ n, hf.approx n + hg.approx n,
λ n, (measure_mono (function.support_add _ _)).trans_lt ((measure_union_le _ _).trans_lt
(ennreal.add_lt_top.mpr ⟨hf.fin_support_approx n, hg.fin_support_approx n⟩)),
λ x, (hf.tendsto_approx x).add (hg.tendsto_approx x)⟩
protected lemma neg [add_group β] [topological_add_group β] (hf : fin_strongly_measurable f μ) :
fin_strongly_measurable (-f) μ :=
begin
refine ⟨λ n, -hf.approx n, λ n, _, λ x, (hf.tendsto_approx x).neg⟩,
suffices : μ (function.support (λ x, - (hf.approx n) x)) < ∞, by convert this,
rw function.support_neg (hf.approx n),
exact hf.fin_support_approx n,
end
protected lemma sub [add_group β] [has_continuous_sub β]
(hf : fin_strongly_measurable f μ) (hg : fin_strongly_measurable g μ) :
fin_strongly_measurable (f - g) μ :=
⟨λ n, hf.approx n - hg.approx n,
λ n, (measure_mono (function.support_sub _ _)).trans_lt ((measure_union_le _ _).trans_lt
(ennreal.add_lt_top.mpr ⟨hf.fin_support_approx n, hg.fin_support_approx n⟩)),
λ x, (hf.tendsto_approx x).sub (hg.tendsto_approx x)⟩
protected lemma const_smul {𝕜} [topological_space 𝕜] [add_monoid β] [monoid 𝕜]
[distrib_mul_action 𝕜 β] [has_continuous_smul 𝕜 β]
(hf : fin_strongly_measurable f μ) (c : 𝕜) :
fin_strongly_measurable (c • f) μ :=
begin
refine ⟨λ n, c • (hf.approx n), λ n, _, λ x, (hf.tendsto_approx x).const_smul c⟩,
rw simple_func.coe_smul,
refine (measure_mono (support_smul_subset_right c _)).trans_lt (hf.fin_support_approx n),
end
end arithmetic
section order
variables [topological_space β] [has_zero β]
protected lemma sup [semilattice_sup β] [has_continuous_sup β]
(hf : fin_strongly_measurable f μ) (hg : fin_strongly_measurable g μ) :
fin_strongly_measurable (f ⊔ g) μ :=
begin
refine ⟨λ n, hf.approx n ⊔ hg.approx n, λ n, _,
λ x, (hf.tendsto_approx x).sup_right_nhds (hg.tendsto_approx x)⟩,
refine (measure_mono (support_sup _ _)).trans_lt _,
exact measure_union_lt_top_iff.mpr ⟨hf.fin_support_approx n, hg.fin_support_approx n⟩,
end
protected lemma inf [semilattice_inf β] [has_continuous_inf β]
(hf : fin_strongly_measurable f μ) (hg : fin_strongly_measurable g μ) :
fin_strongly_measurable (f ⊓ g) μ :=
begin
refine ⟨λ n, hf.approx n ⊓ hg.approx n, λ n, _,
λ x, (hf.tendsto_approx x).inf_right_nhds (hg.tendsto_approx x)⟩,
refine (measure_mono (support_inf _ _)).trans_lt _,
exact measure_union_lt_top_iff.mpr ⟨hf.fin_support_approx n, hg.fin_support_approx n⟩,
end
end order
end fin_strongly_measurable
lemma fin_strongly_measurable_iff_strongly_measurable_and_exists_set_sigma_finite {α β} {f : α → β}
[topological_space β] [t2_space β] [has_zero β] {m : measurable_space α} {μ : measure α} :
fin_strongly_measurable f μ ↔ (strongly_measurable f
∧ (∃ t, measurable_set t ∧ (∀ x ∈ tᶜ, f x = 0) ∧ sigma_finite (μ.restrict t))) :=
⟨λ hf, ⟨hf.strongly_measurable, hf.exists_set_sigma_finite⟩,
λ hf, hf.1.fin_strongly_measurable_of_set_sigma_finite hf.2.some_spec.1 hf.2.some_spec.2.1
hf.2.some_spec.2.2⟩
lemma ae_fin_strongly_measurable_zero {α β} {m : measurable_space α} (μ : measure α) [has_zero β]
[topological_space β] :
ae_fin_strongly_measurable (0 : α → β) μ :=
⟨0, fin_strongly_measurable_zero, eventually_eq.rfl⟩
/-! ## Almost everywhere strongly measurable functions -/
lemma ae_strongly_measurable_const {α β} {m : measurable_space α} {μ : measure α}
[topological_space β] {b : β} :
ae_strongly_measurable (λ a : α, b) μ :=
strongly_measurable_const.ae_strongly_measurable
@[to_additive] lemma ae_strongly_measurable_one {α β} {m : measurable_space α} {μ : measure α}
[topological_space β] [has_one β] :
ae_strongly_measurable (1 : α → β) μ :=
strongly_measurable_one.ae_strongly_measurable
@[simp] lemma subsingleton.ae_strongly_measurable {m : measurable_space α} [topological_space β]
[subsingleton β] {μ : measure α} (f : α → β) :
ae_strongly_measurable f μ :=
(subsingleton.strongly_measurable f).ae_strongly_measurable
@[simp] lemma subsingleton.ae_strongly_measurable' {m : measurable_space α} [topological_space β]
[subsingleton α] {μ : measure α} (f : α → β) :
ae_strongly_measurable f μ :=
(subsingleton.strongly_measurable' f).ae_strongly_measurable
@[simp] lemma ae_strongly_measurable_zero_measure [measurable_space α] [topological_space β]
(f : α → β) :
ae_strongly_measurable f (0 : measure α) :=
begin
nontriviality α,
inhabit α,
exact ⟨λ x, f default, strongly_measurable_const, rfl⟩
end
lemma simple_func.ae_strongly_measurable {m : measurable_space α} {μ : measure α}
[topological_space β] (f : α →ₛ β) :
ae_strongly_measurable f μ :=
f.strongly_measurable.ae_strongly_measurable
namespace ae_strongly_measurable
variables {m : measurable_space α} {μ : measure α} [topological_space β] [topological_space γ]
{f g : α → β}
section mk
/-- A `strongly_measurable` function such that `f =ᵐ[μ] hf.mk f`. See lemmas
`strongly_measurable_mk` and `ae_eq_mk`. -/
protected noncomputable def mk (f : α → β) (hf : ae_strongly_measurable f μ) : α → β := hf.some
lemma strongly_measurable_mk (hf : ae_strongly_measurable f μ) :
strongly_measurable (hf.mk f) :=
hf.some_spec.1
lemma measurable_mk [pseudo_metrizable_space β] [measurable_space β] [borel_space β]
(hf : ae_strongly_measurable f μ) :
measurable (hf.mk f) :=
hf.strongly_measurable_mk.measurable
lemma ae_eq_mk (hf : ae_strongly_measurable f μ) : f =ᵐ[μ] hf.mk f :=
hf.some_spec.2
protected lemma ae_measurable {β} [measurable_space β] [topological_space β]
[pseudo_metrizable_space β] [borel_space β] {f : α → β} (hf : ae_strongly_measurable f μ) :
ae_measurable f μ :=
⟨hf.mk f, hf.strongly_measurable_mk.measurable, hf.ae_eq_mk⟩
end mk
lemma congr (hf : ae_strongly_measurable f μ) (h : f =ᵐ[μ] g) : ae_strongly_measurable g μ :=
⟨hf.mk f, hf.strongly_measurable_mk, h.symm.trans hf.ae_eq_mk⟩
lemma _root_.ae_strongly_measurable_congr (h : f =ᵐ[μ] g) :
ae_strongly_measurable f μ ↔ ae_strongly_measurable g μ :=
⟨λ hf, hf.congr h, λ hg, hg.congr h.symm⟩
lemma mono_measure {ν : measure α} (hf : ae_strongly_measurable f μ) (h : ν ≤ μ) :
ae_strongly_measurable f ν :=
⟨hf.mk f, hf.strongly_measurable_mk, eventually.filter_mono (ae_mono h) hf.ae_eq_mk⟩
protected lemma mono' {ν : measure α} (h : ae_strongly_measurable f μ) (h' : ν ≪ μ) :
ae_strongly_measurable f ν :=
⟨h.mk f, h.strongly_measurable_mk, h' h.ae_eq_mk⟩
lemma mono_set {s t} (h : s ⊆ t) (ht : ae_strongly_measurable f (μ.restrict t)) :
ae_strongly_measurable f (μ.restrict s) :=
ht.mono_measure (restrict_mono h le_rfl)
protected lemma restrict (hfm : ae_strongly_measurable f μ) {s} :
ae_strongly_measurable f (μ.restrict s) :=
hfm.mono_measure measure.restrict_le_self
lemma ae_mem_imp_eq_mk {s} (h : ae_strongly_measurable f (μ.restrict s)) :
∀ᵐ x ∂μ, x ∈ s → f x = h.mk f x :=
ae_imp_of_ae_restrict h.ae_eq_mk
/-- The composition of a continuous function and an ae strongly measurable function is ae strongly
measurable. -/
lemma _root_.continuous.comp_ae_strongly_measurable {g : β → γ} {f : α → β}
(hg : continuous g) (hf : ae_strongly_measurable f μ) :
ae_strongly_measurable (λ x, g (f x)) μ :=
⟨_, hg.comp_strongly_measurable hf.strongly_measurable_mk, eventually_eq.fun_comp hf.ae_eq_mk g⟩
/-- A continuous function from `α` to `β` is ae strongly measurable when one of the two spaces is
second countable. -/
lemma _root_.continuous.ae_strongly_measurable [topological_space α] [opens_measurable_space α]
[pseudo_metrizable_space β] [second_countable_topology_either α β] (hf : continuous f) :
ae_strongly_measurable f μ :=
hf.strongly_measurable.ae_strongly_measurable
protected lemma prod_mk {f : α → β} {g : α → γ}
(hf : ae_strongly_measurable f μ) (hg : ae_strongly_measurable g μ) :
ae_strongly_measurable (λ x, (f x, g x)) μ :=
⟨λ x, (hf.mk f x, hg.mk g x), hf.strongly_measurable_mk.prod_mk hg.strongly_measurable_mk,
hf.ae_eq_mk.prod_mk hg.ae_eq_mk⟩
/-- In a space with second countable topology, measurable implies ae strongly measurable. -/
lemma _root_.measurable.ae_strongly_measurable {m : measurable_space α}
{μ : measure α} [measurable_space β] [pseudo_metrizable_space β]
[second_countable_topology β] [opens_measurable_space β] (hf : measurable f) :
ae_strongly_measurable f μ :=
hf.strongly_measurable.ae_strongly_measurable
section arithmetic
@[to_additive]
protected lemma mul [has_mul β] [has_continuous_mul β]
(hf : ae_strongly_measurable f μ) (hg : ae_strongly_measurable g μ) :
ae_strongly_measurable (f * g) μ :=
⟨hf.mk f * hg.mk g, hf.strongly_measurable_mk.mul hg.strongly_measurable_mk,
hf.ae_eq_mk.mul hg.ae_eq_mk⟩
@[to_additive]
protected lemma mul_const [has_mul β] [has_continuous_mul β]
(hf : ae_strongly_measurable f μ) (c : β) :
ae_strongly_measurable (λ x, f x * c) μ :=
hf.mul ae_strongly_measurable_const
@[to_additive]
protected lemma const_mul [has_mul β] [has_continuous_mul β]
(hf : ae_strongly_measurable f μ) (c : β) :
ae_strongly_measurable (λ x, c * f x) μ :=
ae_strongly_measurable_const.mul hf
@[to_additive]
protected lemma inv [group β] [topological_group β] (hf : ae_strongly_measurable f μ) :
ae_strongly_measurable (f⁻¹) μ :=
⟨(hf.mk f)⁻¹, hf.strongly_measurable_mk.inv, hf.ae_eq_mk.inv⟩
@[to_additive]
protected lemma div [group β] [topological_group β]
(hf : ae_strongly_measurable f μ) (hg : ae_strongly_measurable g μ) :
ae_strongly_measurable (f / g) μ :=
⟨hf.mk f / hg.mk g, hf.strongly_measurable_mk.div hg.strongly_measurable_mk,
hf.ae_eq_mk.div hg.ae_eq_mk⟩
@[to_additive]
protected lemma smul {𝕜} [topological_space 𝕜] [has_smul 𝕜 β] [has_continuous_smul 𝕜 β]
{f : α → 𝕜} {g : α → β} (hf : ae_strongly_measurable f μ) (hg : ae_strongly_measurable g μ) :
ae_strongly_measurable (λ x, f x • g x) μ :=
continuous_smul.comp_ae_strongly_measurable (hf.prod_mk hg)
protected lemma const_smul {𝕜} [has_smul 𝕜 β] [has_continuous_const_smul 𝕜 β]
(hf : ae_strongly_measurable f μ) (c : 𝕜) :
ae_strongly_measurable (c • f) μ :=
⟨c • hf.mk f, hf.strongly_measurable_mk.const_smul c, hf.ae_eq_mk.const_smul c⟩
protected lemma const_smul' {𝕜} [has_smul 𝕜 β] [has_continuous_const_smul 𝕜 β]
(hf : ae_strongly_measurable f μ) (c : 𝕜) :
ae_strongly_measurable (λ x, c • (f x)) μ :=
hf.const_smul c
@[to_additive]
protected lemma smul_const {𝕜} [topological_space 𝕜] [has_smul 𝕜 β] [has_continuous_smul 𝕜 β]
{f : α → 𝕜} (hf : ae_strongly_measurable f μ) (c : β) :
ae_strongly_measurable (λ x, f x • c) μ :=
continuous_smul.comp_ae_strongly_measurable (hf.prod_mk ae_strongly_measurable_const)
end arithmetic
section order
protected lemma sup [semilattice_sup β] [has_continuous_sup β]
(hf : ae_strongly_measurable f μ) (hg : ae_strongly_measurable g μ) :
ae_strongly_measurable (f ⊔ g) μ :=
⟨hf.mk f ⊔ hg.mk g, hf.strongly_measurable_mk.sup hg.strongly_measurable_mk,
hf.ae_eq_mk.sup hg.ae_eq_mk⟩
protected lemma inf [semilattice_inf β] [has_continuous_inf β]
(hf : ae_strongly_measurable f μ) (hg : ae_strongly_measurable g μ) :
ae_strongly_measurable (f ⊓ g) μ :=
⟨hf.mk f ⊓ hg.mk g, hf.strongly_measurable_mk.inf hg.strongly_measurable_mk,
hf.ae_eq_mk.inf hg.ae_eq_mk⟩
end order
/-!
### Big operators: `∏` and `∑`
-/
section monoid
variables {M : Type*} [monoid M] [topological_space M] [has_continuous_mul M]
@[to_additive]
lemma _root_.list.ae_strongly_measurable_prod' (l : list (α → M))
(hl : ∀ f ∈ l, ae_strongly_measurable f μ) : ae_strongly_measurable l.prod μ :=
begin
induction l with f l ihl, { exact ae_strongly_measurable_one },
rw [list.forall_mem_cons] at hl,
rw [list.prod_cons],
exact hl.1.mul (ihl hl.2)
end
@[to_additive]
lemma _root_.list.ae_strongly_measurable_prod
(l : list (α → M)) (hl : ∀ f ∈ l, ae_strongly_measurable f μ) :
ae_strongly_measurable (λ x, (l.map (λ f : α → M, f x)).prod) μ :=
by simpa only [← pi.list_prod_apply] using l.ae_strongly_measurable_prod' hl
end monoid
section comm_monoid
variables {M : Type*} [comm_monoid M] [topological_space M] [has_continuous_mul M]
@[to_additive]
lemma _root_.multiset.ae_strongly_measurable_prod' (l : multiset (α → M))
(hl : ∀ f ∈ l, ae_strongly_measurable f μ) : ae_strongly_measurable l.prod μ :=
by { rcases l with ⟨l⟩, simpa using l.ae_strongly_measurable_prod' (by simpa using hl) }
@[to_additive]
lemma _root_.multiset.ae_strongly_measurable_prod (s : multiset (α → M))
(hs : ∀ f ∈ s, ae_strongly_measurable f μ) :
ae_strongly_measurable (λ x, (s.map (λ f : α → M, f x)).prod) μ :=
by simpa only [← pi.multiset_prod_apply] using s.ae_strongly_measurable_prod' hs
@[to_additive]
lemma _root_.finset.ae_strongly_measurable_prod' {ι : Type*} {f : ι → α → M}
(s : finset ι) (hf : ∀i ∈ s, ae_strongly_measurable (f i) μ) :
ae_strongly_measurable (∏ i in s, f i) μ :=
multiset.ae_strongly_measurable_prod' _ $
λ g hg, let ⟨i, hi, hg⟩ := multiset.mem_map.1 hg in (hg ▸ hf _ hi)
@[to_additive]
lemma _root_.finset.ae_strongly_measurable_prod {ι : Type*} {f : ι → α → M}
(s : finset ι) (hf : ∀i ∈ s, ae_strongly_measurable (f i) μ) :
ae_strongly_measurable (λ a, ∏ i in s, f i a) μ :=
by simpa only [← finset.prod_apply] using s.ae_strongly_measurable_prod' hf
end comm_monoid
section second_countable_ae_strongly_measurable
variables [measurable_space β]
/-- In a space with second countable topology, measurable implies strongly measurable. -/
lemma _root_.ae_measurable.ae_strongly_measurable [pseudo_metrizable_space β]
[opens_measurable_space β] [second_countable_topology β] (hf : ae_measurable f μ) :
ae_strongly_measurable f μ :=
⟨hf.mk f, hf.measurable_mk.strongly_measurable, hf.ae_eq_mk⟩
lemma _root_.ae_strongly_measurable_id {α : Type*} [topological_space α] [pseudo_metrizable_space α]
{m : measurable_space α} [opens_measurable_space α] [second_countable_topology α]
{μ : measure α} :
ae_strongly_measurable (id : α → α) μ :=
ae_measurable_id.ae_strongly_measurable
/-- In a space with second countable topology, strongly measurable and measurable are equivalent. -/
lemma _root_.ae_strongly_measurable_iff_ae_measurable [pseudo_metrizable_space β] [borel_space β]
[second_countable_topology β] :
ae_strongly_measurable f μ ↔ ae_measurable f μ :=
⟨λ h, h.ae_measurable, λ h, h.ae_strongly_measurable⟩
end second_countable_ae_strongly_measurable
protected lemma dist {β : Type*} [pseudo_metric_space β] {f g : α → β}
(hf : ae_strongly_measurable f μ) (hg : ae_strongly_measurable g μ) :
ae_strongly_measurable (λ x, dist (f x) (g x)) μ :=
continuous_dist.comp_ae_strongly_measurable (hf.prod_mk hg)
protected lemma norm {β : Type*} [seminormed_add_comm_group β] {f : α → β}
(hf : ae_strongly_measurable f μ) :
ae_strongly_measurable (λ x, ∥f x∥) μ :=
continuous_norm.comp_ae_strongly_measurable hf
protected lemma nnnorm {β : Type*} [seminormed_add_comm_group β] {f : α → β}
(hf : ae_strongly_measurable f μ) :
ae_strongly_measurable (λ x, ∥f x∥₊) μ :=
continuous_nnnorm.comp_ae_strongly_measurable hf
protected lemma ennnorm {β : Type*} [seminormed_add_comm_group β] {f : α → β}
(hf : ae_strongly_measurable f μ) :
ae_measurable (λ a, (∥f a∥₊ : ℝ≥0∞)) μ :=
(ennreal.continuous_coe.comp_ae_strongly_measurable hf.nnnorm).ae_measurable
protected lemma edist {β : Type*} [seminormed_add_comm_group β] {f g : α → β}
(hf : ae_strongly_measurable f μ) (hg : ae_strongly_measurable g μ) :
ae_measurable (λ a, edist (f a) (g a)) μ :=
(continuous_edist.comp_ae_strongly_measurable (hf.prod_mk hg)).ae_measurable
protected lemma real_to_nnreal {f : α → ℝ}
(hf : ae_strongly_measurable f μ) :
ae_strongly_measurable (λ x, (f x).to_nnreal) μ :=
continuous_real_to_nnreal.comp_ae_strongly_measurable hf
section
variables {𝕜 : Type*} {E : Type*} [is_R_or_C 𝕜] [inner_product_space 𝕜 E]
local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y
protected lemma re {f : α → 𝕜} (hf : ae_strongly_measurable f μ) :
ae_strongly_measurable (λ x, is_R_or_C.re (f x)) μ :=
is_R_or_C.continuous_re.comp_ae_strongly_measurable hf
protected lemma im {f : α → 𝕜} (hf : ae_strongly_measurable f μ) :
ae_strongly_measurable (λ x, is_R_or_C.im (f x)) μ :=
is_R_or_C.continuous_im.comp_ae_strongly_measurable hf
protected lemma inner {m : measurable_space α} {μ : measure α} {f g : α → E}
(hf : ae_strongly_measurable f μ) (hg : ae_strongly_measurable g μ) :
ae_strongly_measurable (λ x, ⟪f x, g x⟫) μ :=
continuous_inner.comp_ae_strongly_measurable (hf.prod_mk hg)
end
lemma _root_.ae_strongly_measurable_indicator_iff [has_zero β] {s : set α} (hs : measurable_set s) :
ae_strongly_measurable (indicator s f) μ ↔ ae_strongly_measurable f (μ.restrict s) :=
begin
split,
{ intro h,
exact (h.mono_measure measure.restrict_le_self).congr (indicator_ae_eq_restrict hs) },
{ intro h,
refine ⟨indicator s (h.mk f), h.strongly_measurable_mk.indicator hs, _⟩,
have A : s.indicator f =ᵐ[μ.restrict s] s.indicator (h.mk f) :=
(indicator_ae_eq_restrict hs).trans (h.ae_eq_mk.trans $ (indicator_ae_eq_restrict hs).symm),
have B : s.indicator f =ᵐ[μ.restrict sᶜ] s.indicator (h.mk f) :=
(indicator_ae_eq_restrict_compl hs).trans (indicator_ae_eq_restrict_compl hs).symm,
exact ae_of_ae_restrict_of_ae_restrict_compl _ A B },
end
protected lemma indicator [has_zero β]
(hfm : ae_strongly_measurable f μ) {s : set α} (hs : measurable_set s) :
ae_strongly_measurable (s.indicator f) μ :=
(ae_strongly_measurable_indicator_iff hs).mpr hfm.restrict
lemma _root_.ae_strongly_measurable_of_ae_strongly_measurable_trim {α} {m m0 : measurable_space α}
{μ : measure α} (hm : m ≤ m0) {f : α → β} (hf : ae_strongly_measurable f (μ.trim hm)) :
ae_strongly_measurable f μ :=
⟨hf.mk f, strongly_measurable.mono hf.strongly_measurable_mk hm, ae_eq_of_ae_eq_trim hf.ae_eq_mk⟩
lemma comp_ae_measurable {γ : Type*} {mγ : measurable_space γ} {mα : measurable_space α} {f : γ → α}
{μ : measure γ} (hg : ae_strongly_measurable g (measure.map f μ)) (hf : ae_measurable f μ) :
ae_strongly_measurable (g ∘ f) μ :=
⟨(hg.mk g) ∘ hf.mk f, hg.strongly_measurable_mk.comp_measurable hf.measurable_mk,
(ae_eq_comp hf hg.ae_eq_mk).trans ((hf.ae_eq_mk).fun_comp (hg.mk g))⟩
lemma comp_measurable {γ : Type*} {mγ : measurable_space γ} {mα : measurable_space α} {f : γ → α}
{μ : measure γ} (hg : ae_strongly_measurable g (measure.map f μ)) (hf : measurable f) :
ae_strongly_measurable (g ∘ f) μ :=
hg.comp_ae_measurable hf.ae_measurable
lemma comp_measurable' {γ : Type*} {mγ : measurable_space γ} {mα : measurable_space α} {f : γ → α}
{μ : measure γ} {ν : measure α} (hg : ae_strongly_measurable g ν) (hf : measurable f)
(h : μ.map f ≪ ν) : ae_strongly_measurable (g ∘ f) μ :=
(hg.mono' h).comp_measurable hf
lemma is_separable_ae_range (hf : ae_strongly_measurable f μ) :
∃ (t : set β), is_separable t ∧ ∀ᵐ x ∂μ, f x ∈ t :=
begin
refine ⟨range (hf.mk f), hf.strongly_measurable_mk.is_separable_range, _⟩,
filter_upwards [hf.ae_eq_mk] with x hx,
simp [hx]
end
/-- A function is almost everywhere strongly measurable if and only if it is almost everywhere
measurable, and up to a zero measure set its range is contained in a separable set. -/
theorem _root_.ae_strongly_measurable_iff_ae_measurable_separable
[pseudo_metrizable_space β] [measurable_space β] [borel_space β] :
ae_strongly_measurable f μ ↔
(ae_measurable f μ ∧ ∃ (t : set β), is_separable t ∧ ∀ᵐ x ∂μ, f x ∈ t) :=
begin
refine ⟨λ H, ⟨H.ae_measurable, H.is_separable_ae_range⟩, _⟩,
rintros ⟨H, ⟨t, t_sep, ht⟩⟩,
rcases eq_empty_or_nonempty t with rfl|h₀,
{ simp only [mem_empty_eq, eventually_false_iff_eq_bot, ae_eq_bot] at ht,
rw ht,
exact ae_strongly_measurable_zero_measure f },
{ obtain ⟨g, g_meas, gt, fg⟩ : ∃ (g : α → β), measurable g ∧ range g ⊆ t ∧ f =ᵐ[μ] g :=
H.exists_ae_eq_range_subset ht h₀,
refine ⟨g, _, fg⟩,
exact strongly_measurable_iff_measurable_separable.2 ⟨g_meas, t_sep.mono gt⟩ }
end
lemma _root_.measurable_embedding.ae_strongly_measurable_map_iff
{γ : Type*} {mγ : measurable_space γ} {mα : measurable_space α}
{f : γ → α} {μ : measure γ} (hf : measurable_embedding f) {g : α → β} :
ae_strongly_measurable g (measure.map f μ) ↔ ae_strongly_measurable (g ∘ f) μ :=
begin
refine ⟨λ H, H.comp_measurable hf.measurable, _⟩,
rintro ⟨g₁, hgm₁, heq⟩,
rcases hf.exists_strongly_measurable_extend hgm₁ (λ x, ⟨g x⟩) with ⟨g₂, hgm₂, rfl⟩,
exact ⟨g₂, hgm₂, hf.ae_map_iff.2 heq⟩
end
lemma _root_.embedding.ae_strongly_measurable_comp_iff
[pseudo_metrizable_space β] [pseudo_metrizable_space γ]
{g : β → γ} {f : α → β} (hg : embedding g) :
ae_strongly_measurable (λ x, g (f x)) μ ↔ ae_strongly_measurable f μ :=
begin
letI := pseudo_metrizable_space_pseudo_metric γ,
borelize [β, γ],
refine ⟨λ H, ae_strongly_measurable_iff_ae_measurable_separable.2 ⟨_, _⟩,
λ H, hg.continuous.comp_ae_strongly_measurable H⟩,
{ let G : β → range g := cod_restrict g (range g) mem_range_self,
have hG : closed_embedding G :=
{ closed_range :=
begin
convert is_closed_univ,
apply eq_univ_of_forall,
rintros ⟨-, ⟨x, rfl⟩⟩,
exact mem_range_self x
end,
.. hg.cod_restrict _ _ },
have : ae_measurable (G ∘ f) μ := ae_measurable.subtype_mk H.ae_measurable,
exact hG.measurable_embedding.ae_measurable_comp_iff.1 this },
{ rcases (ae_strongly_measurable_iff_ae_measurable_separable.1 H).2 with ⟨t, ht, h't⟩,
exact ⟨g⁻¹' t, hg.is_separable_preimage ht, h't⟩ }
end
lemma _root_.measure_theory.measure_preserving.ae_strongly_measurable_comp_iff {β : Type*}
{f : α → β} {mα : measurable_space α} {μa : measure α} {mβ : measurable_space β} {μb : measure β}
(hf : measure_preserving f μa μb) (h₂ : measurable_embedding f) {g : β → γ} :
ae_strongly_measurable (g ∘ f) μa ↔ ae_strongly_measurable g μb :=
by rw [← hf.map_eq, h₂.ae_strongly_measurable_map_iff]
/-- An almost everywhere sequential limit of almost everywhere strongly measurable functions is
almost everywhere strongly measurable. -/
lemma _root_.ae_strongly_measurable_of_tendsto_ae {ι : Type*}
[pseudo_metrizable_space β] (u : filter ι) [ne_bot u] [is_countably_generated u]
{f : ι → α → β} {g : α → β} (hf : ∀ i, ae_strongly_measurable (f i) μ)
(lim : ∀ᵐ x ∂μ, tendsto (λ n, f n x) u (𝓝 (g x))) :
ae_strongly_measurable g μ :=
begin
borelize β,
refine ae_strongly_measurable_iff_ae_measurable_separable.2 ⟨_, _⟩,
{ exact ae_measurable_of_tendsto_metrizable_ae _ (λ n, (hf n).ae_measurable) lim },
{ rcases u.exists_seq_tendsto with ⟨v, hv⟩,
have : ∀ (n : ℕ), ∃ (t : set β), is_separable t ∧ f (v n) ⁻¹' t ∈ μ.ae :=
λ n, (ae_strongly_measurable_iff_ae_measurable_separable.1 (hf (v n))).2,
choose t t_sep ht using this,
refine ⟨closure (⋃ i, (t i)), (is_separable_Union (λ i, (t_sep i))).closure, _⟩,
filter_upwards [ae_all_iff.2 ht, lim] with x hx h'x,
apply mem_closure_of_tendsto ((h'x).comp hv),
apply eventually_of_forall (λ n, _),
apply mem_Union_of_mem n,
exact hx n }
end
/-- If a sequence of almost everywhere strongly measurable functions converges almost everywhere,
one can select a strongly measurable function as the almost everywhere limit. -/
lemma _root_.exists_strongly_measurable_limit_of_tendsto_ae [pseudo_metrizable_space β]
{f : ℕ → α → β} (hf : ∀ n, ae_strongly_measurable (f n) μ)
(h_ae_tendsto : ∀ᵐ x ∂μ, ∃ l : β, tendsto (λ n, f n x) at_top (𝓝 l)) :
∃ (f_lim : α → β) (hf_lim_meas : strongly_measurable f_lim),
∀ᵐ x ∂μ, tendsto (λ n, f n x) at_top (𝓝 (f_lim x)) :=
begin
borelize β,
obtain ⟨g, g_meas, hg⟩ : ∃ (g : α → β) (g_meas : measurable g),
∀ᵐ x ∂μ, tendsto (λ n, f n x) at_top (𝓝 (g x)) :=
measurable_limit_of_tendsto_metrizable_ae (λ n, (hf n).ae_measurable) h_ae_tendsto,
have Hg : ae_strongly_measurable g μ := ae_strongly_measurable_of_tendsto_ae _ hf hg,
refine ⟨Hg.mk g, Hg.strongly_measurable_mk, _⟩,
filter_upwards [hg, Hg.ae_eq_mk] with x hx h'x,
rwa h'x at hx,
end
lemma sum_measure [pseudo_metrizable_space β]
{m : measurable_space α} {μ : ι → measure α} (h : ∀ i, ae_strongly_measurable f (μ i)) :
ae_strongly_measurable f (measure.sum μ) :=
begin
borelize β,
refine ae_strongly_measurable_iff_ae_measurable_separable.2
⟨ae_measurable.sum_measure (λ i, (h i).ae_measurable), _⟩,
have A : ∀ (i : ι), ∃ (t : set β), is_separable t ∧ f ⁻¹' t ∈ (μ i).ae :=
λ i, (ae_strongly_measurable_iff_ae_measurable_separable.1 (h i)).2,
choose t t_sep ht using A,
refine ⟨(⋃ i, t i), is_separable_Union t_sep, _⟩,
simp only [measure.ae_sum_eq, mem_Union, eventually_supr],
assume i,
filter_upwards [ht i] with x hx,
exact ⟨i, hx⟩
end
@[simp] lemma _root_.ae_strongly_measurable_sum_measure_iff
[pseudo_metrizable_space β] {m : measurable_space α} {μ : ι → measure α} :
ae_strongly_measurable f (sum μ) ↔ ∀ i, ae_strongly_measurable f (μ i) :=
⟨λ h i, h.mono_measure (measure.le_sum _ _), sum_measure⟩
@[simp] lemma _root_.ae_strongly_measurable_add_measure_iff [pseudo_metrizable_space β]
{ν : measure α} :
ae_strongly_measurable f (μ + ν) ↔ ae_strongly_measurable f μ ∧ ae_strongly_measurable f ν :=
by { rw [← sum_cond, ae_strongly_measurable_sum_measure_iff, bool.forall_bool, and.comm], refl }
lemma add_measure [pseudo_metrizable_space β] {ν : measure α} {f : α → β}
(hμ : ae_strongly_measurable f μ) (hν : ae_strongly_measurable f ν) :
ae_strongly_measurable f (μ + ν) :=
ae_strongly_measurable_add_measure_iff.2 ⟨hμ, hν⟩
protected lemma Union [pseudo_metrizable_space β] {s : ι → set α}
(h : ∀ i, ae_strongly_measurable f (μ.restrict (s i))) :
ae_strongly_measurable f (μ.restrict (⋃ i, s i)) :=
(sum_measure h).mono_measure $ restrict_Union_le
@[simp] lemma _root_.ae_strongly_measurable_Union_iff [pseudo_metrizable_space β] {s : ι → set α} :
ae_strongly_measurable f (μ.restrict (⋃ i, s i)) ↔
∀ i, ae_strongly_measurable f (μ.restrict (s i)) :=
⟨λ h i, h.mono_measure $ restrict_mono (subset_Union _ _) le_rfl, ae_strongly_measurable.Union⟩
@[simp] lemma _root_.ae_strongly_measurable_union_iff [pseudo_metrizable_space β] {s t : set α} :
ae_strongly_measurable f (μ.restrict (s ∪ t)) ↔
ae_strongly_measurable f (μ.restrict s) ∧ ae_strongly_measurable f (μ.restrict t) :=
by simp only [union_eq_Union, ae_strongly_measurable_Union_iff, bool.forall_bool, cond, and.comm]
lemma smul_measure {R : Type*} [monoid R] [distrib_mul_action R ℝ≥0∞]
[is_scalar_tower R ℝ≥0∞ ℝ≥0∞] (h : ae_strongly_measurable f μ) (c : R) :
ae_strongly_measurable f (c • μ) :=
⟨h.mk f, h.strongly_measurable_mk, ae_smul_measure h.ae_eq_mk c⟩
section normed_space
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜] [complete_space 𝕜]
variables {E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
lemma _root_.ae_strongly_measurable_smul_const_iff {f : α → 𝕜} {c : E} (hc : c ≠ 0) :
ae_strongly_measurable (λ x, f x • c) μ ↔ ae_strongly_measurable f μ :=
(closed_embedding_smul_left hc).to_embedding.ae_strongly_measurable_comp_iff
end normed_space
section mul_action
variables {G : Type*} [group G] [mul_action G β]
[has_continuous_const_smul G β]
lemma _root_.ae_strongly_measurable_const_smul_iff (c : G) :
ae_strongly_measurable (λ x, c • f x) μ ↔ ae_strongly_measurable f μ :=
⟨λ h, by simpa only [inv_smul_smul] using h.const_smul' c⁻¹, λ h, h.const_smul c⟩
variables {G₀ : Type*} [group_with_zero G₀] [mul_action G₀ β]
[has_continuous_const_smul G₀ β]
lemma _root_.ae_strongly_measurable_const_smul_iff₀ {c : G₀} (hc : c ≠ 0) :
ae_strongly_measurable (λ x, c • f x) μ ↔ ae_strongly_measurable f μ :=
begin
refine ⟨λ h, _, λ h, h.const_smul c⟩,
convert h.const_smul' c⁻¹,
simp [smul_smul, inv_mul_cancel hc]
end
end mul_action
section continuous_linear_map_nontrivially_normed_field
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜]
variables {E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
variables {F : Type*} [normed_add_comm_group F] [normed_space 𝕜 F]
variables {G : Type*} [normed_add_comm_group G] [normed_space 𝕜 G]
lemma _root_.strongly_measurable.apply_continuous_linear_map
{m : measurable_space α} {φ : α → F →L[𝕜] E} (hφ : strongly_measurable φ) (v : F) :
strongly_measurable (λ a, φ a v) :=
(continuous_linear_map.apply 𝕜 E v).continuous.comp_strongly_measurable hφ
lemma apply_continuous_linear_map {φ : α → F →L[𝕜] E}
(hφ : ae_strongly_measurable φ μ) (v : F) :
ae_strongly_measurable (λ a, φ a v) μ :=
(continuous_linear_map.apply 𝕜 E v).continuous.comp_ae_strongly_measurable hφ
lemma _root_.continuous_linear_map.ae_strongly_measurable_comp₂ (L : E →L[𝕜] F →L[𝕜] G)
{f : α → E} {g : α → F}
(hf : ae_strongly_measurable f μ) (hg : ae_strongly_measurable g μ) :
ae_strongly_measurable (λ x, L (f x) (g x)) μ :=
L.continuous₂.comp_ae_strongly_measurable $ hf.prod_mk hg
end continuous_linear_map_nontrivially_normed_field
lemma _root_.ae_strongly_measurable_with_density_iff {E : Type*} [normed_add_comm_group E]
[normed_space ℝ E] {f : α → ℝ≥0} (hf : measurable f) {g : α → E} :
ae_strongly_measurable g (μ.with_density (λ x, (f x : ℝ≥0∞))) ↔
ae_strongly_measurable (λ x, (f x : ℝ) • g x) μ :=
begin
split,
{ rintros ⟨g', g'meas, hg'⟩,
have A : measurable_set {x : α | f x ≠ 0} := (hf (measurable_set_singleton 0)).compl,
refine ⟨λ x, (f x : ℝ) • g' x, hf.coe_nnreal_real.strongly_measurable.smul g'meas, _⟩,
apply @ae_of_ae_restrict_of_ae_restrict_compl _ _ _ {x | f x ≠ 0},
{ rw [eventually_eq, ae_with_density_iff hf.coe_nnreal_ennreal] at hg',
rw ae_restrict_iff' A,
filter_upwards [hg'] with a ha h'a,
have : (f a : ℝ≥0∞) ≠ 0, by simpa only [ne.def, ennreal.coe_eq_zero] using h'a,
rw ha this },
{ filter_upwards [ae_restrict_mem A.compl] with x hx,
simp only [not_not, mem_set_of_eq, mem_compl_eq] at hx,
simp [hx] } },
{ rintros ⟨g', g'meas, hg'⟩,
refine ⟨λ x, (f x : ℝ)⁻¹ • g' x, hf.coe_nnreal_real.inv.strongly_measurable.smul g'meas, _⟩,
rw [eventually_eq, ae_with_density_iff hf.coe_nnreal_ennreal],
filter_upwards [hg'] with x hx h'x,
rw [← hx, smul_smul, _root_.inv_mul_cancel, one_smul],
simp only [ne.def, ennreal.coe_eq_zero] at h'x,
simpa only [nnreal.coe_eq_zero, ne.def] using h'x }
end
end ae_strongly_measurable
/-! ## Almost everywhere finitely strongly measurable functions -/
namespace ae_fin_strongly_measurable
variables {m : measurable_space α} {μ : measure α} [topological_space β]
{f g : α → β}
section mk
variables [has_zero β]
/-- A `fin_strongly_measurable` function such that `f =ᵐ[μ] hf.mk f`. See lemmas
`fin_strongly_measurable_mk` and `ae_eq_mk`. -/
protected noncomputable def mk (f : α → β) (hf : ae_fin_strongly_measurable f μ) : α → β := hf.some
lemma fin_strongly_measurable_mk (hf : ae_fin_strongly_measurable f μ) :
fin_strongly_measurable (hf.mk f) μ :=
hf.some_spec.1
lemma ae_eq_mk (hf : ae_fin_strongly_measurable f μ) : f =ᵐ[μ] hf.mk f :=
hf.some_spec.2
protected lemma ae_measurable {β} [has_zero β] [measurable_space β] [topological_space β]
[pseudo_metrizable_space β] [borel_space β]
{f : α → β} (hf : ae_fin_strongly_measurable f μ) :
ae_measurable f μ :=
⟨hf.mk f, hf.fin_strongly_measurable_mk.measurable, hf.ae_eq_mk⟩
end mk
section arithmetic
protected lemma mul [monoid_with_zero β] [has_continuous_mul β]
(hf : ae_fin_strongly_measurable f μ) (hg : ae_fin_strongly_measurable g μ) :
ae_fin_strongly_measurable (f * g) μ :=
⟨hf.mk f * hg.mk g, hf.fin_strongly_measurable_mk.mul hg.fin_strongly_measurable_mk,
hf.ae_eq_mk.mul hg.ae_eq_mk⟩
protected lemma add [add_monoid β] [has_continuous_add β]
(hf : ae_fin_strongly_measurable f μ) (hg : ae_fin_strongly_measurable g μ) :
ae_fin_strongly_measurable (f + g) μ :=
⟨hf.mk f + hg.mk g, hf.fin_strongly_measurable_mk.add hg.fin_strongly_measurable_mk,
hf.ae_eq_mk.add hg.ae_eq_mk⟩
protected lemma neg [add_group β] [topological_add_group β] (hf : ae_fin_strongly_measurable f μ) :
ae_fin_strongly_measurable (-f) μ :=
⟨-hf.mk f, hf.fin_strongly_measurable_mk.neg, hf.ae_eq_mk.neg⟩
protected lemma sub [add_group β] [has_continuous_sub β]
(hf : ae_fin_strongly_measurable f μ) (hg : ae_fin_strongly_measurable g μ) :
ae_fin_strongly_measurable (f - g) μ :=
⟨hf.mk f - hg.mk g, hf.fin_strongly_measurable_mk.sub hg.fin_strongly_measurable_mk,
hf.ae_eq_mk.sub hg.ae_eq_mk⟩
protected lemma const_smul {𝕜} [topological_space 𝕜] [add_monoid β] [monoid 𝕜]
[distrib_mul_action 𝕜 β] [has_continuous_smul 𝕜 β]
(hf : ae_fin_strongly_measurable f μ) (c : 𝕜) :
ae_fin_strongly_measurable (c • f) μ :=
⟨c • hf.mk f, hf.fin_strongly_measurable_mk.const_smul c, hf.ae_eq_mk.const_smul c⟩
end arithmetic
section order
variables [has_zero β]
protected lemma sup [semilattice_sup β] [has_continuous_sup β]
(hf : ae_fin_strongly_measurable f μ) (hg : ae_fin_strongly_measurable g μ) :
ae_fin_strongly_measurable (f ⊔ g) μ :=
⟨hf.mk f ⊔ hg.mk g, hf.fin_strongly_measurable_mk.sup hg.fin_strongly_measurable_mk,
hf.ae_eq_mk.sup hg.ae_eq_mk⟩
protected lemma inf [semilattice_inf β] [has_continuous_inf β]
(hf : ae_fin_strongly_measurable f μ) (hg : ae_fin_strongly_measurable g μ) :
ae_fin_strongly_measurable (f ⊓ g) μ :=
⟨hf.mk f ⊓ hg.mk g, hf.fin_strongly_measurable_mk.inf hg.fin_strongly_measurable_mk,
hf.ae_eq_mk.inf hg.ae_eq_mk⟩
end order
variables [has_zero β] [t2_space β]
lemma exists_set_sigma_finite (hf : ae_fin_strongly_measurable f μ) :
∃ t, measurable_set t ∧ f =ᵐ[μ.restrict tᶜ] 0 ∧ sigma_finite (μ.restrict t) :=
begin
rcases hf with ⟨g, hg, hfg⟩,
obtain ⟨t, ht, hgt_zero, htμ⟩ := hg.exists_set_sigma_finite,
refine ⟨t, ht, _, htμ⟩,
refine eventually_eq.trans (ae_restrict_of_ae hfg) _,
rw [eventually_eq, ae_restrict_iff' ht.compl],
exact eventually_of_forall hgt_zero,
end
/-- A measurable set `t` such that `f =ᵐ[μ.restrict tᶜ] 0` and `sigma_finite (μ.restrict t)`. -/
def sigma_finite_set (hf : ae_fin_strongly_measurable f μ) : set α :=
hf.exists_set_sigma_finite.some
protected lemma measurable_set (hf : ae_fin_strongly_measurable f μ) :
measurable_set hf.sigma_finite_set :=
hf.exists_set_sigma_finite.some_spec.1
lemma ae_eq_zero_compl (hf : ae_fin_strongly_measurable f μ) :
f =ᵐ[μ.restrict hf.sigma_finite_setᶜ] 0 :=
hf.exists_set_sigma_finite.some_spec.2.1
instance sigma_finite_restrict (hf : ae_fin_strongly_measurable f μ) :
sigma_finite (μ.restrict hf.sigma_finite_set) :=
hf.exists_set_sigma_finite.some_spec.2.2
end ae_fin_strongly_measurable
section second_countable_topology
variables {G : Type*} {p : ℝ≥0∞} {m m0 : measurable_space α} {μ : measure α}
[seminormed_add_comm_group G] [measurable_space G] [borel_space G] [second_countable_topology G]
{f : α → G}
/-- In a space with second countable topology and a sigma-finite measure, `fin_strongly_measurable`
and `measurable` are equivalent. -/
lemma fin_strongly_measurable_iff_measurable {m0 : measurable_space α} (μ : measure α)
[sigma_finite μ] :
fin_strongly_measurable f μ ↔ measurable f :=
⟨λ h, h.measurable, λ h, (measurable.strongly_measurable h).fin_strongly_measurable μ⟩
/-- In a space with second countable topology and a sigma-finite measure,
`ae_fin_strongly_measurable` and `ae_measurable` are equivalent. -/
lemma ae_fin_strongly_measurable_iff_ae_measurable {m0 : measurable_space α} (μ : measure α)
[sigma_finite μ] :
ae_fin_strongly_measurable f μ ↔ ae_measurable f μ :=
by simp_rw [ae_fin_strongly_measurable, ae_measurable, fin_strongly_measurable_iff_measurable]
end second_countable_topology
lemma measurable_uncurry_of_continuous_of_measurable {α β ι : Type*} [topological_space ι]
[metrizable_space ι] [measurable_space ι] [second_countable_topology ι] [opens_measurable_space ι]
{mβ : measurable_space β} [topological_space β] [pseudo_metrizable_space β] [borel_space β]
{m : measurable_space α} {u : ι → α → β}
(hu_cont : ∀ x, continuous (λ i, u i x)) (h : ∀ i, measurable (u i)) :
measurable (function.uncurry u) :=
begin
obtain ⟨t_sf, ht_sf⟩ : ∃ t : ℕ → simple_func ι ι, ∀ j x,
tendsto (λ n, u (t n j) x) at_top (𝓝 $ u j x),
{ have h_str_meas : strongly_measurable (id : ι → ι), from strongly_measurable_id,
refine ⟨h_str_meas.approx, λ j x, _⟩,
exact ((hu_cont x).tendsto j).comp (h_str_meas.tendsto_approx j), },
let U := λ (n : ℕ) (p : ι × α), u (t_sf n p.fst) p.snd,
have h_tendsto : tendsto U at_top (𝓝 (λ p, u p.fst p.snd)),
{ rw tendsto_pi_nhds,
exact λ p, ht_sf p.fst p.snd, },
refine measurable_of_tendsto_metrizable (λ n, _) h_tendsto,
have h_meas : measurable (λ (p : (t_sf n).range × α), u ↑p.fst p.snd),
{ have : (λ (p : ↥((t_sf n).range) × α), u ↑(p.fst) p.snd)
= (λ (p : α × ((t_sf n).range)), u ↑(p.snd) p.fst) ∘ prod.swap := rfl,
rw [this, @measurable_swap_iff α ↥((t_sf n).range) β m],
exact measurable_from_prod_countable (λ j, h j), },
have : (λ p : ι × α, u (t_sf n p.fst) p.snd)
= (λ p : ↥(t_sf n).range × α, u p.fst p.snd)
∘ (λ p : ι × α, (⟨t_sf n p.fst, simple_func.mem_range_self _ _⟩, p.snd)) := rfl,
simp_rw [U, this],
refine h_meas.comp (measurable.prod_mk _ measurable_snd),
exact ((t_sf n).measurable.comp measurable_fst).subtype_mk,
end
lemma strongly_measurable_uncurry_of_continuous_of_strongly_measurable {α β ι : Type*}
[topological_space ι] [metrizable_space ι] [measurable_space ι] [second_countable_topology ι]
[opens_measurable_space ι] [topological_space β] [pseudo_metrizable_space β]
[measurable_space α] {u : ι → α → β}
(hu_cont : ∀ x, continuous (λ i, u i x)) (h : ∀ i, strongly_measurable (u i)) :
strongly_measurable (function.uncurry u) :=
begin
borelize β,
obtain ⟨t_sf, ht_sf⟩ : ∃ t : ℕ → simple_func ι ι, ∀ j x,
tendsto (λ n, u (t n j) x) at_top (𝓝 $ u j x),
{ have h_str_meas : strongly_measurable (id : ι → ι), from strongly_measurable_id,
refine ⟨h_str_meas.approx, λ j x, _⟩,
exact ((hu_cont x).tendsto j).comp (h_str_meas.tendsto_approx j), },
let U := λ (n : ℕ) (p : ι × α), u (t_sf n p.fst) p.snd,
have h_tendsto : tendsto U at_top (𝓝 (λ p, u p.fst p.snd)),
{ rw tendsto_pi_nhds,
exact λ p, ht_sf p.fst p.snd, },
refine strongly_measurable_of_tendsto _ (λ n, _) h_tendsto,
have h_str_meas : strongly_measurable (λ (p : (t_sf n).range × α), u ↑p.fst p.snd),
{ refine strongly_measurable_iff_measurable_separable.2 ⟨_, _⟩,
{ have : (λ (p : ↥((t_sf n).range) × α), u ↑(p.fst) p.snd)
= (λ (p : α × ((t_sf n).range)), u ↑(p.snd) p.fst) ∘ prod.swap := rfl,
rw [this, measurable_swap_iff],
exact measurable_from_prod_countable (λ j, (h j).measurable), },
{ have : is_separable (⋃ (i : (t_sf n).range), range (u i)) :=
is_separable_Union (λ i, (h i).is_separable_range),
apply this.mono,
rintros _ ⟨⟨i, x⟩, rfl⟩,
simp only [mem_Union, mem_range],
exact ⟨i, x, rfl⟩ } },
have : (λ p : ι × α, u (t_sf n p.fst) p.snd)
= (λ p : ↥(t_sf n).range × α, u p.fst p.snd)
∘ (λ p : ι × α, (⟨t_sf n p.fst, simple_func.mem_range_self _ _⟩, p.snd)) := rfl,
simp_rw [U, this],
refine h_str_meas.comp_measurable (measurable.prod_mk _ measurable_snd),
exact ((t_sf n).measurable.comp measurable_fst).subtype_mk,
end
end measure_theory
|
8fbf1810fb4bbecdc06a60291abc3aced7fde32d | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/category_theory/Fintype.lean | 5603b7ff304a09cfb030a49a8459bc1817045ed6 | [
"Apache-2.0"
] | permissive | Lix0120/mathlib | 0020745240315ed0e517cbf32e738d8f9811dd80 | e14c37827456fc6707f31b4d1d16f1f3a3205e91 | refs/heads/master | 1,673,102,855,024 | 1,604,151,044,000 | 1,604,151,044,000 | 308,930,245 | 0 | 0 | Apache-2.0 | 1,604,164,710,000 | 1,604,163,547,000 | null | UTF-8 | Lean | false | false | 3,691 | lean | /-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Adam Topaz
-/
import data.fintype.basic
import data.fin
import category_theory.concrete_category.bundled
import category_theory.concrete_category
import category_theory.full_subcategory
import category_theory.skeletal
/-!
# The category of finite types.
We define the category of finite types, denoted `Fintype` as
(bundled) types with a `fintype` instance.
We also define `Fintype.skeleton`, the standard skeleton of `Fintype` whose objects are `fin n`
for `n : ℕ`. We prove that the obvious inclusion functor `Fintype.skeleton ⥤ Fintype` is an
equivalence of categories in `Fintype.skeleton.equivalence`.
We prove that `Fintype.skeleton` is a skeleton of `Fintype` in `Fintype.is_skeleton`.
-/
open_locale classical
open category_theory
/-- The category of finite types. -/
@[derive has_coe_to_sort]
def Fintype := bundled fintype
namespace Fintype
/-- Construct a bundled `Fintype` from the underlying type and typeclass. -/
def of (X : Type*) [fintype X] : Fintype := bundled.of X
instance : inhabited Fintype := ⟨⟨pempty⟩⟩
instance {X : Fintype} : fintype X := X.2
instance : category Fintype := induced_category.category bundled.α
/-- The fully faithful embedding of `Fintype` into the category of types. -/
@[derive [full, faithful], simps {rhs_md:=semireducible}]
def incl : Fintype ⥤ Type* := induced_functor _
instance : concrete_category Fintype := ⟨incl⟩
/--
The "standard" skeleton for `Fintype`. This is the full subcategory of `Fintype` spanned by objects
of the form `fin n` for `n : ℕ`. We parameterize the objects of `Fintype.skeleton` directly as `ℕ`,
as the type `fin m ≃ fin n` is nonempty if and only if `n = m`.
-/
def skeleton := ℕ
namespace skeleton
/-- Given any natural number `n`, this creates the associated object of `Fintype.skeleton`. -/
def mk : ℕ → skeleton := id
instance : inhabited skeleton := ⟨mk 0⟩
/-- Given any object of `Fintype.skeleton`, this returns the associated natural number. -/
def to_nat : skeleton → ℕ := id
instance : category skeleton :=
{ hom := λ X Y, fin X → fin Y,
id := λ _, id,
comp := λ _ _ _ f g, g ∘ f }
lemma is_skeletal : skeletal skeleton := λ X Y ⟨h⟩, fin.equiv_iff_eq.mp $ nonempty.intro $
{ to_fun := h.1,
inv_fun := h.2,
left_inv := λ _, by {change (h.hom ≫ h.inv) _ = _, simpa},
right_inv := λ _, by {change (h.inv ≫ h.hom) _ = _, simpa} }
/-- The canonical fully faithful embedding of `Fintype.skeleton` into `Fintype`. -/
def incl : skeleton ⥤ Fintype :=
{ obj := λ X, Fintype.of (fin X),
map := λ _ _ f, f }
instance : full incl := { preimage := λ _ _ f, f }
instance : faithful incl := {}
noncomputable instance : ess_surj incl :=
{ obj_preimage := λ X, fintype.card X,
iso' := λ X,
let F := trunc.out (fintype.equiv_fin X) in
{ hom := F.symm,
inv := F,
hom_inv_id' := by { change F.to_fun ∘ F.inv_fun = _, simpa },
inv_hom_id' := by { change F.inv_fun ∘ F.to_fun = _, simpa } } }
noncomputable instance : is_equivalence incl :=
equivalence.equivalence_of_fully_faithfully_ess_surj _
/-- The equivalence between `Fintype.skeleton` and `Fintype`. -/
noncomputable def equivalence : skeleton ≌ Fintype := incl.as_equivalence
@[simp] lemma incl_mk_nat_card (n : ℕ) : fintype.card (incl.obj (mk n)) = n := finset.card_fin n
end skeleton
/-- `Fintype.skeleton` is a skeleton of `Fintype`. -/
noncomputable def is_skeleton : is_skeleton_of Fintype skeleton skeleton.incl :=
{ skel := skeleton.is_skeletal,
eqv := by apply_instance }
end Fintype
|
66493119ea74d47e538fd689cd1c357e14693c65 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/measure_theory/integral/mean_inequalities.lean | 9c8942b2eba3607e67119430e2280db5f84e19af | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 20,703 | lean | /-
Copyright (c) 2020 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import measure_theory.integral.lebesgue
import analysis.mean_inequalities
import analysis.mean_inequalities_pow
import measure_theory.function.special_functions.basic
/-!
# Mean value inequalities for integrals
In this file we prove several inequalities on integrals, notably the Hölder inequality and
the Minkowski inequality. The versions for finite sums are in `analysis.mean_inequalities`.
## Main results
Hölder's inequality for the Lebesgue integral of `ℝ≥0∞` and `ℝ≥0` functions: we prove
`∫ (f * g) ∂μ ≤ (∫ f^p ∂μ) ^ (1/p) * (∫ g^q ∂μ) ^ (1/q)` for `p`, `q` conjugate real exponents
and `α→(e)nnreal` functions in two cases,
* `ennreal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0∞ functions,
* `nnreal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0 functions.
Minkowski's inequality for the Lebesgue integral of measurable functions with `ℝ≥0∞` values:
we prove `(∫ (f + g)^p ∂μ) ^ (1/p) ≤ (∫ f^p ∂μ) ^ (1/p) + (∫ g^p ∂μ) ^ (1/p)` for `1 ≤ p`.
-/
section lintegral
/-!
### Hölder's inequality for the Lebesgue integral of ℝ≥0∞ and nnreal functions
We prove `∫ (f * g) ∂μ ≤ (∫ f^p ∂μ) ^ (1/p) * (∫ g^q ∂μ) ^ (1/q)` for `p`, `q`
conjugate real exponents and `α→(e)nnreal` functions in several cases, the first two being useful
only to prove the more general results:
* `ennreal.lintegral_mul_le_one_of_lintegral_rpow_eq_one` : ℝ≥0∞ functions for which the
integrals on the right are equal to 1,
* `ennreal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top` : ℝ≥0∞ functions for which the
integrals on the right are neither ⊤ nor 0,
* `ennreal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0∞ functions,
* `nnreal.lintegral_mul_le_Lp_mul_Lq` : nnreal functions.
-/
noncomputable theory
open_locale classical big_operators nnreal ennreal
open measure_theory
variables {α : Type*} [measurable_space α] {μ : measure α}
namespace ennreal
lemma lintegral_mul_le_one_of_lintegral_rpow_eq_one {p q : ℝ} (hpq : p.is_conjugate_exponent q)
{f g : α → ℝ≥0∞} (hf : ae_measurable f μ) (hf_norm : ∫⁻ a, (f a)^p ∂μ = 1)
(hg_norm : ∫⁻ a, (g a)^q ∂μ = 1) :
∫⁻ a, (f * g) a ∂μ ≤ 1 :=
begin
calc ∫⁻ (a : α), ((f * g) a) ∂μ
≤ ∫⁻ (a : α), ((f a)^p / ennreal.of_real p + (g a)^q / ennreal.of_real q) ∂μ :
lintegral_mono (λ a, young_inequality (f a) (g a) hpq)
... = 1 :
begin
simp only [div_eq_mul_inv],
rw lintegral_add_left',
{ rw [lintegral_mul_const'' _ (hf.pow_const p), lintegral_mul_const', hf_norm, hg_norm,
← div_eq_mul_inv, ← div_eq_mul_inv, hpq.inv_add_inv_conj_ennreal],
simp [hpq.symm.pos], },
{ exact (hf.pow_const _).mul_const _, },
end
end
/-- Function multiplied by the inverse of its p-seminorm `(∫⁻ f^p ∂μ) ^ 1/p`-/
def fun_mul_inv_snorm (f : α → ℝ≥0∞) (p : ℝ) (μ : measure α) : α → ℝ≥0∞ :=
λ a, (f a) * ((∫⁻ c, (f c) ^ p ∂μ) ^ (1 / p))⁻¹
lemma fun_eq_fun_mul_inv_snorm_mul_snorm {p : ℝ} (f : α → ℝ≥0∞)
(hf_nonzero : ∫⁻ a, (f a) ^ p ∂μ ≠ 0) (hf_top : ∫⁻ a, (f a) ^ p ∂μ ≠ ⊤) {a : α} :
f a = (fun_mul_inv_snorm f p μ a) * (∫⁻ c, (f c)^p ∂μ)^(1/p) :=
by simp [fun_mul_inv_snorm, mul_assoc, ennreal.inv_mul_cancel, hf_nonzero, hf_top]
lemma fun_mul_inv_snorm_rpow {p : ℝ} (hp0 : 0 < p) {f : α → ℝ≥0∞} {a : α} :
(fun_mul_inv_snorm f p μ a) ^ p = (f a)^p * (∫⁻ c, (f c) ^ p ∂μ)⁻¹ :=
begin
rw [fun_mul_inv_snorm, mul_rpow_of_nonneg _ _ (le_of_lt hp0)],
suffices h_inv_rpow : ((∫⁻ (c : α), f c ^ p ∂μ) ^ (1 / p))⁻¹ ^ p = (∫⁻ (c : α), f c ^ p ∂μ)⁻¹,
by rw h_inv_rpow,
rw [inv_rpow, ← rpow_mul, one_div_mul_cancel hp0.ne', rpow_one]
end
lemma lintegral_rpow_fun_mul_inv_snorm_eq_one {p : ℝ} (hp0_lt : 0 < p) {f : α → ℝ≥0∞}
(hf_nonzero : ∫⁻ a, (f a)^p ∂μ ≠ 0) (hf_top : ∫⁻ a, (f a)^p ∂μ ≠ ⊤) :
∫⁻ c, (fun_mul_inv_snorm f p μ c)^p ∂μ = 1 :=
begin
simp_rw fun_mul_inv_snorm_rpow hp0_lt,
rw [lintegral_mul_const', ennreal.mul_inv_cancel hf_nonzero hf_top],
rwa inv_ne_top
end
/-- Hölder's inequality in case of finite non-zero integrals -/
lemma lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top {p q : ℝ} (hpq : p.is_conjugate_exponent q)
{f g : α → ℝ≥0∞} (hf : ae_measurable f μ)
(hf_nontop : ∫⁻ a, (f a)^p ∂μ ≠ ⊤) (hg_nontop : ∫⁻ a, (g a)^q ∂μ ≠ ⊤)
(hf_nonzero : ∫⁻ a, (f a)^p ∂μ ≠ 0) (hg_nonzero : ∫⁻ a, (g a)^q ∂μ ≠ 0) :
∫⁻ a, (f * g) a ∂μ ≤ (∫⁻ a, (f a)^p ∂μ)^(1/p) * (∫⁻ a, (g a)^q ∂μ)^(1/q) :=
begin
let npf := (∫⁻ (c : α), (f c) ^ p ∂μ) ^ (1/p),
let nqg := (∫⁻ (c : α), (g c) ^ q ∂μ) ^ (1/q),
calc ∫⁻ (a : α), (f * g) a ∂μ
= ∫⁻ (a : α), ((fun_mul_inv_snorm f p μ * fun_mul_inv_snorm g q μ) a)
* (npf * nqg) ∂μ :
begin
refine lintegral_congr (λ a, _),
rw [pi.mul_apply, fun_eq_fun_mul_inv_snorm_mul_snorm f hf_nonzero hf_nontop,
fun_eq_fun_mul_inv_snorm_mul_snorm g hg_nonzero hg_nontop, pi.mul_apply],
ring,
end
... ≤ npf * nqg :
begin
rw lintegral_mul_const' (npf * nqg) _
(by simp [hf_nontop, hg_nontop, hf_nonzero, hg_nonzero, ennreal.mul_eq_top]),
refine mul_le_of_le_one_left' _,
have hf1 := lintegral_rpow_fun_mul_inv_snorm_eq_one hpq.pos hf_nonzero hf_nontop,
have hg1 := lintegral_rpow_fun_mul_inv_snorm_eq_one hpq.symm.pos hg_nonzero hg_nontop,
exact lintegral_mul_le_one_of_lintegral_rpow_eq_one hpq (hf.mul_const _) hf1 hg1,
end
end
lemma ae_eq_zero_of_lintegral_rpow_eq_zero {p : ℝ} (hp0 : 0 ≤ p) {f : α → ℝ≥0∞}
(hf : ae_measurable f μ) (hf_zero : ∫⁻ a, (f a)^p ∂μ = 0) :
f =ᵐ[μ] 0 :=
begin
rw lintegral_eq_zero_iff' (hf.pow_const p) at hf_zero,
refine filter.eventually.mp hf_zero (filter.eventually_of_forall (λ x, _)),
dsimp only,
rw [pi.zero_apply, ← not_imp_not],
exact λ hx, (rpow_pos_of_nonneg (pos_iff_ne_zero.2 hx) hp0).ne'
end
lemma lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero {p : ℝ} (hp0 : 0 ≤ p)
{f g : α → ℝ≥0∞} (hf : ae_measurable f μ) (hf_zero : ∫⁻ a, (f a)^p ∂μ = 0) :
∫⁻ a, (f * g) a ∂μ = 0 :=
begin
rw ←@lintegral_zero_fun α _ μ,
refine lintegral_congr_ae _,
suffices h_mul_zero : f * g =ᵐ[μ] 0 * g , by rwa zero_mul at h_mul_zero,
have hf_eq_zero : f =ᵐ[μ] 0, from ae_eq_zero_of_lintegral_rpow_eq_zero hp0 hf hf_zero,
exact hf_eq_zero.mul (ae_eq_refl g),
end
lemma lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top {p q : ℝ} (hp0_lt : 0 < p) (hq0 : 0 ≤ q)
{f g : α → ℝ≥0∞} (hf_top : ∫⁻ a, (f a)^p ∂μ = ⊤) (hg_nonzero : ∫⁻ a, (g a)^q ∂μ ≠ 0) :
∫⁻ a, (f * g) a ∂μ ≤ (∫⁻ a, (f a)^p ∂μ) ^ (1/p) * (∫⁻ a, (g a)^q ∂μ) ^ (1/q) :=
begin
refine le_trans le_top (le_of_eq _),
have hp0_inv_lt : 0 < 1/p, by simp [hp0_lt],
rw [hf_top, ennreal.top_rpow_of_pos hp0_inv_lt],
simp [hq0, hg_nonzero],
end
/-- Hölder's inequality for functions `α → ℝ≥0∞`. The integral of the product of two functions
is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are conjugate
exponents. -/
theorem lintegral_mul_le_Lp_mul_Lq (μ : measure α) {p q : ℝ} (hpq : p.is_conjugate_exponent q)
{f g : α → ℝ≥0∞} (hf : ae_measurable f μ) (hg : ae_measurable g μ) :
∫⁻ a, (f * g) a ∂μ ≤ (∫⁻ a, (f a)^p ∂μ) ^ (1/p) * (∫⁻ a, (g a)^q ∂μ) ^ (1/q) :=
begin
by_cases hf_zero : ∫⁻ a, (f a) ^ p ∂μ = 0,
{ refine eq.trans_le _ (zero_le _),
exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.nonneg hf hf_zero, },
by_cases hg_zero : ∫⁻ a, (g a) ^ q ∂μ = 0,
{ refine eq.trans_le _ (zero_le _),
rw mul_comm,
exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.symm.nonneg hg hg_zero, },
by_cases hf_top : ∫⁻ a, (f a) ^ p ∂μ = ⊤,
{ exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.pos hpq.symm.nonneg hf_top hg_zero, },
by_cases hg_top : ∫⁻ a, (g a) ^ q ∂μ = ⊤,
{ rw [mul_comm, mul_comm ((∫⁻ (a : α), (f a) ^ p ∂μ) ^ (1 / p))],
exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.symm.pos hpq.nonneg hg_top hf_zero, },
-- non-⊤ non-zero case
exact ennreal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top hpq hf hf_top hg_top hf_zero hg_zero
end
lemma lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top {p : ℝ}
{f g : α → ℝ≥0∞} (hf : ae_measurable f μ) (hf_top : ∫⁻ a, (f a) ^ p ∂μ < ⊤)
(hg_top : ∫⁻ a, (g a) ^ p ∂μ < ⊤) (hp1 : 1 ≤ p) :
∫⁻ a, ((f + g) a) ^ p ∂μ < ⊤ :=
begin
have hp0_lt : 0 < p, from lt_of_lt_of_le zero_lt_one hp1,
have hp0 : 0 ≤ p, from le_of_lt hp0_lt,
calc ∫⁻ (a : α), (f a + g a) ^ p ∂μ
≤ ∫⁻ a, ((2:ℝ≥0∞)^(p-1) * (f a) ^ p + (2:ℝ≥0∞)^(p-1) * (g a) ^ p) ∂ μ :
begin
refine lintegral_mono (λ a, _),
dsimp only,
have h_zero_lt_half_rpow : (0 : ℝ≥0∞) < (1 / 2) ^ p,
{ rw [←ennreal.zero_rpow_of_pos hp0_lt],
exact ennreal.rpow_lt_rpow (by simp [zero_lt_one]) hp0_lt, },
have h_rw : (1 / 2) ^ p * (2:ℝ≥0∞) ^ (p - 1) = 1 / 2,
{ rw [sub_eq_add_neg, ennreal.rpow_add _ _ two_ne_zero ennreal.coe_ne_top,
←mul_assoc, ←ennreal.mul_rpow_of_nonneg _ _ hp0, one_div,
ennreal.inv_mul_cancel two_ne_zero ennreal.coe_ne_top, ennreal.one_rpow,
one_mul, ennreal.rpow_neg_one], },
rw ←ennreal.mul_le_mul_left (ne_of_lt h_zero_lt_half_rpow).symm _,
{ rw [mul_add, ← mul_assoc, ← mul_assoc, h_rw, ←ennreal.mul_rpow_of_nonneg _ _ hp0, mul_add],
refine ennreal.rpow_arith_mean_le_arith_mean2_rpow (1/2 : ℝ≥0∞) (1/2 : ℝ≥0∞)
(f a) (g a) _ hp1,
rw [ennreal.div_add_div_same, one_add_one_eq_two,
ennreal.div_self two_ne_zero ennreal.coe_ne_top], },
{ rw ← lt_top_iff_ne_top,
refine ennreal.rpow_lt_top_of_nonneg hp0 _,
rw [one_div, ennreal.inv_ne_top],
exact two_ne_zero, },
end
... < ⊤ :
begin
have h_two : (2 : ℝ≥0∞) ^ (p - 1) ≠ ⊤,
from ennreal.rpow_ne_top_of_nonneg (by simp [hp1]) ennreal.coe_ne_top,
rw [lintegral_add_left', lintegral_const_mul'' _ (hf.pow_const p),
lintegral_const_mul' _ _ h_two, ennreal.add_lt_top],
{ exact ⟨ennreal.mul_lt_top h_two hf_top.ne, ennreal.mul_lt_top h_two hg_top.ne⟩ },
{ exact (hf.pow_const p).const_mul _ }
end
end
lemma lintegral_Lp_mul_le_Lq_mul_Lr {α} [measurable_space α] {p q r : ℝ} (hp0_lt : 0 < p)
(hpq : p < q) (hpqr : 1/p = 1/q + 1/r) (μ : measure α) {f g : α → ℝ≥0∞}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) :
(∫⁻ a, ((f * g) a)^p ∂μ) ^ (1/p) ≤ (∫⁻ a, (f a)^q ∂μ) ^ (1/q) * (∫⁻ a, (g a)^r ∂μ) ^ (1/r) :=
begin
have hp0_ne : p ≠ 0, from (ne_of_lt hp0_lt).symm,
have hp0 : 0 ≤ p, from le_of_lt hp0_lt,
have hq0_lt : 0 < q, from lt_of_le_of_lt hp0 hpq,
have hq0_ne : q ≠ 0, from (ne_of_lt hq0_lt).symm,
have h_one_div_r : 1/r = 1/p - 1/q, by simp [hpqr],
have hr0_ne : r ≠ 0,
{ have hr_inv_pos : 0 < 1/r,
by rwa [h_one_div_r, sub_pos, one_div_lt_one_div hq0_lt hp0_lt],
rw [one_div, _root_.inv_pos] at hr_inv_pos,
exact (ne_of_lt hr_inv_pos).symm, },
let p2 := q/p,
let q2 := p2.conjugate_exponent,
have hp2q2 : p2.is_conjugate_exponent q2,
from real.is_conjugate_exponent_conjugate_exponent (by simp [lt_div_iff, hpq, hp0_lt]),
calc (∫⁻ (a : α), ((f * g) a) ^ p ∂μ) ^ (1 / p)
= (∫⁻ (a : α), (f a)^p * (g a)^p ∂μ) ^ (1 / p) :
by simp_rw [pi.mul_apply, ennreal.mul_rpow_of_nonneg _ _ hp0]
... ≤ ((∫⁻ a, (f a)^(p * p2) ∂ μ)^(1/p2) * (∫⁻ a, (g a)^(p * q2) ∂ μ)^(1/q2)) ^ (1/p) :
begin
refine ennreal.rpow_le_rpow _ (by simp [hp0]),
simp_rw ennreal.rpow_mul,
exact ennreal.lintegral_mul_le_Lp_mul_Lq μ hp2q2 (hf.pow_const _) (hg.pow_const _)
end
... = (∫⁻ (a : α), (f a) ^ q ∂μ) ^ (1 / q) * (∫⁻ (a : α), (g a) ^ r ∂μ) ^ (1 / r) :
begin
rw [@ennreal.mul_rpow_of_nonneg _ _ (1/p) (by simp [hp0]), ←ennreal.rpow_mul,
←ennreal.rpow_mul],
have hpp2 : p * p2 = q,
{ symmetry, rw [mul_comm, ←div_eq_iff hp0_ne], },
have hpq2 : p * q2 = r,
{ rw [← inv_inv r, ← one_div, ← one_div, h_one_div_r],
field_simp [q2, real.conjugate_exponent, p2, hp0_ne, hq0_ne] },
simp_rw [div_mul_div_comm, mul_one, mul_comm p2, mul_comm q2, hpp2, hpq2],
end
end
lemma lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow {p q : ℝ}
(hpq : p.is_conjugate_exponent q) {f g : α → ℝ≥0∞}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) (hf_top : ∫⁻ a, (f a) ^ p ∂μ ≠ ⊤) :
∫⁻ a, (f a) * (g a) ^ (p - 1) ∂μ ≤ (∫⁻ a, (f a)^p ∂μ) ^ (1/p) * (∫⁻ a, (g a)^p ∂μ) ^ (1/q) :=
begin
refine le_trans (ennreal.lintegral_mul_le_Lp_mul_Lq μ hpq hf (hg.pow_const _)) _,
by_cases hf_zero_rpow : (∫⁻ (a : α), (f a) ^ p ∂μ) ^ (1 / p) = 0,
{ rw [hf_zero_rpow, zero_mul],
exact zero_le _, },
have hf_top_rpow : (∫⁻ (a : α), (f a) ^ p ∂μ) ^ (1 / p) ≠ ⊤,
{ by_contra h,
refine hf_top _,
have hp_not_neg : ¬ p < 0, by simp [hpq.nonneg],
simpa [hpq.pos, hp_not_neg] using h, },
refine (ennreal.mul_le_mul_left hf_zero_rpow hf_top_rpow).mpr (le_of_eq _),
congr,
ext1 a,
rw [←ennreal.rpow_mul, hpq.sub_one_mul_conj],
end
lemma lintegral_rpow_add_le_add_snorm_mul_lintegral_rpow_add {p q : ℝ}
(hpq : p.is_conjugate_exponent q) {f g : α → ℝ≥0∞} (hf : ae_measurable f μ)
(hf_top : ∫⁻ a, (f a) ^ p ∂μ ≠ ⊤) (hg : ae_measurable g μ) (hg_top : ∫⁻ a, (g a) ^ p ∂μ ≠ ⊤) :
∫⁻ a, ((f + g) a)^p ∂ μ
≤ ((∫⁻ a, (f a)^p ∂μ) ^ (1/p) + (∫⁻ a, (g a)^p ∂μ) ^ (1/p))
* (∫⁻ a, (f a + g a)^p ∂μ) ^ (1/q) :=
begin
calc ∫⁻ a, ((f+g) a) ^ p ∂μ ≤ ∫⁻ a, ((f + g) a) * ((f + g) a) ^ (p - 1) ∂μ :
begin
refine lintegral_mono (λ a, _),
dsimp only,
by_cases h_zero : (f + g) a = 0,
{ rw [h_zero, ennreal.zero_rpow_of_pos hpq.pos],
exact zero_le _, },
by_cases h_top : (f + g) a = ⊤,
{ rw [h_top, ennreal.top_rpow_of_pos hpq.sub_one_pos, ennreal.top_mul_top],
exact le_top, },
refine le_of_eq _,
nth_rewrite 1 ←ennreal.rpow_one ((f + g) a),
rw [←ennreal.rpow_add _ _ h_zero h_top, add_sub_cancel'_right],
end
... = ∫⁻ (a : α), f a * (f + g) a ^ (p - 1) ∂μ + ∫⁻ (a : α), g a * (f + g) a ^ (p - 1) ∂μ :
begin
have h_add_m : ae_measurable (λ (a : α), ((f + g) a) ^ (p-1)) μ,
from (hf.add hg).pow_const _,
have h_add_apply : ∫⁻ (a : α), (f + g) a * (f + g) a ^ (p - 1) ∂μ
= ∫⁻ (a : α), (f a + g a) * (f + g) a ^ (p - 1) ∂μ,
from rfl,
simp_rw [h_add_apply, add_mul],
rw lintegral_add_left' (hf.mul h_add_m),
end
... ≤ ((∫⁻ a, (f a)^p ∂μ) ^ (1/p) + (∫⁻ a, (g a)^p ∂μ) ^ (1/p))
* (∫⁻ a, (f a + g a)^p ∂μ) ^ (1/q) :
begin
rw add_mul,
exact add_le_add
(lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow hpq hf (hf.add hg) hf_top)
(lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow hpq hg (hf.add hg) hg_top),
end
end
private lemma lintegral_Lp_add_le_aux {p q : ℝ}
(hpq : p.is_conjugate_exponent q) {f g : α → ℝ≥0∞} (hf : ae_measurable f μ)
(hf_top : ∫⁻ a, (f a) ^ p ∂μ ≠ ⊤) (hg : ae_measurable g μ) (hg_top : ∫⁻ a, (g a) ^ p ∂μ ≠ ⊤)
(h_add_zero : ∫⁻ a, ((f+g) a) ^ p ∂ μ ≠ 0) (h_add_top : ∫⁻ a, ((f+g) a) ^ p ∂ μ ≠ ⊤) :
(∫⁻ a, ((f + g) a)^p ∂ μ) ^ (1/p) ≤ (∫⁻ a, (f a)^p ∂μ) ^ (1/p) + (∫⁻ a, (g a)^p ∂μ) ^ (1/p) :=
begin
have hp_not_nonpos : ¬ p ≤ 0, by simp [hpq.pos],
have htop_rpow : (∫⁻ a, ((f+g) a) ^ p ∂μ)^(1/p) ≠ ⊤,
{ by_contra h,
exact h_add_top (@ennreal.rpow_eq_top_of_nonneg _ (1/p) (by simp [hpq.nonneg]) h), },
have h0_rpow : (∫⁻ a, ((f+g) a) ^ p ∂ μ) ^ (1/p) ≠ 0,
by simp [h_add_zero, h_add_top, hpq.nonneg, hp_not_nonpos, -pi.add_apply],
suffices h : 1 ≤ (∫⁻ (a : α), ((f+g) a)^p ∂μ) ^ -(1/p)
* ((∫⁻ (a : α), (f a)^p ∂μ) ^ (1/p) + (∫⁻ (a : α), (g a)^p ∂μ) ^ (1/p)),
by rwa [←mul_le_mul_left h0_rpow htop_rpow, ←mul_assoc, ←rpow_add _ _ h_add_zero h_add_top,
←sub_eq_add_neg, _root_.sub_self, rpow_zero, one_mul, mul_one] at h,
have h : ∫⁻ (a : α), ((f+g) a)^p ∂μ
≤ ((∫⁻ (a : α), (f a)^p ∂μ) ^ (1/p) + (∫⁻ (a : α), (g a)^p ∂μ) ^ (1/p))
* (∫⁻ (a : α), ((f+g) a)^p ∂μ) ^ (1/q),
from lintegral_rpow_add_le_add_snorm_mul_lintegral_rpow_add hpq hf hf_top hg hg_top,
have h_one_div_q : 1/q = 1 - 1/p, by { nth_rewrite 1 ←hpq.inv_add_inv_conj, ring, },
simp_rw [h_one_div_q, sub_eq_add_neg 1 (1/p), ennreal.rpow_add _ _ h_add_zero h_add_top,
rpow_one] at h,
nth_rewrite 1 mul_comm at h,
nth_rewrite 0 ←one_mul (∫⁻ (a : α), ((f+g) a) ^ p ∂μ) at h,
rwa [←mul_assoc, ennreal.mul_le_mul_right h_add_zero h_add_top, mul_comm] at h,
end
/-- Minkowski's inequality for functions `α → ℝ≥0∞`: the `ℒp` seminorm of the sum of two
functions is bounded by the sum of their `ℒp` seminorms. -/
theorem lintegral_Lp_add_le {p : ℝ} {f g : α → ℝ≥0∞}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) (hp1 : 1 ≤ p) :
(∫⁻ a, ((f + g) a)^p ∂ μ) ^ (1/p) ≤ (∫⁻ a, (f a)^p ∂μ) ^ (1/p) + (∫⁻ a, (g a)^p ∂μ) ^ (1/p) :=
begin
have hp_pos : 0 < p, from lt_of_lt_of_le zero_lt_one hp1,
by_cases hf_top : ∫⁻ a, (f a) ^ p ∂μ = ⊤,
{ simp [hf_top, hp_pos], },
by_cases hg_top : ∫⁻ a, (g a) ^ p ∂μ = ⊤,
{ simp [hg_top, hp_pos], },
by_cases h1 : p = 1,
{ refine le_of_eq _,
simp_rw [h1, one_div_one, ennreal.rpow_one],
exact lintegral_add_left' hf _, },
have hp1_lt : 1 < p, by { refine lt_of_le_of_ne hp1 _, symmetry, exact h1, },
have hpq := real.is_conjugate_exponent_conjugate_exponent hp1_lt,
by_cases h0 : ∫⁻ a, ((f+g) a) ^ p ∂ μ = 0,
{ rw [h0, @ennreal.zero_rpow_of_pos (1/p) (by simp [lt_of_lt_of_le zero_lt_one hp1])],
exact zero_le _, },
have htop : ∫⁻ a, ((f+g) a) ^ p ∂ μ ≠ ⊤,
{ rw ← ne.def at hf_top hg_top,
rw ← lt_top_iff_ne_top at hf_top hg_top ⊢,
exact lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top hf hf_top hg_top hp1, },
exact lintegral_Lp_add_le_aux hpq hf hf_top hg hg_top h0 htop,
end
/-- Variant of Minkowski's inequality for functions `α → ℝ≥0∞` in `ℒp` with `p ≤ 1`: the `ℒp`
seminorm of the sum of two functions is bounded by a constant multiple of the sum
of their `ℒp` seminorms. -/
theorem lintegral_Lp_add_le_of_le_one {p : ℝ} {f g : α → ℝ≥0∞}
(hf : ae_measurable f μ) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) :
(∫⁻ a, ((f + g) a)^p ∂ μ) ^ (1/p) ≤
2^(1/p-1) * ((∫⁻ a, (f a)^p ∂μ) ^ (1/p) + (∫⁻ a, (g a)^p ∂μ) ^ (1/p)) :=
begin
rcases eq_or_lt_of_le hp0 with rfl|hp,
{ simp only [pi.add_apply, rpow_zero, lintegral_one, _root_.div_zero, zero_sub],
norm_num,
rw [rpow_neg, rpow_one, ennreal.inv_mul_cancel two_ne_zero two_ne_top],
exact le_rfl },
calc (∫⁻ a, (f + g) a ^ p ∂μ) ^ (1 / p) ≤ (∫⁻ a, (f a)^p ∂ μ + ∫⁻ a, (g a)^p ∂ μ) ^ (1/p) :
begin
apply rpow_le_rpow _ (div_nonneg zero_le_one hp0),
rw ← lintegral_add_left' (hf.pow_const p),
exact lintegral_mono (λ a, rpow_add_le_add_rpow _ _ hp0 hp1)
end
... ≤ 2 ^ (1/p-1) * ((∫⁻ a, f a ^ p ∂μ) ^ (1/p) + (∫⁻ a, g a ^ p ∂μ) ^ (1/p)) :
rpow_add_le_mul_rpow_add_rpow _ _ ((one_le_div hp).2 hp1)
end
end ennreal
/-- Hölder's inequality for functions `α → ℝ≥0`. The integral of the product of two functions
is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are conjugate
exponents. -/
theorem nnreal.lintegral_mul_le_Lp_mul_Lq {p q : ℝ} (hpq : p.is_conjugate_exponent q)
{f g : α → ℝ≥0} (hf : ae_measurable f μ) (hg : ae_measurable g μ) :
∫⁻ a, (f * g) a ∂μ ≤ (∫⁻ a, (f a)^p ∂μ)^(1/p) * (∫⁻ a, (g a)^q ∂μ)^(1/q) :=
begin
simp_rw [pi.mul_apply, ennreal.coe_mul],
exact ennreal.lintegral_mul_le_Lp_mul_Lq μ hpq hf.coe_nnreal_ennreal hg.coe_nnreal_ennreal,
end
end lintegral
|
cee2a5b8830227414d79e6b89160732d4157439b | b7f22e51856f4989b970961f794f1c435f9b8f78 | /library/data/sigma.lean | 78d064be8da7a5a0e5c5f8a8c04d1884258d5b21 | [
"Apache-2.0"
] | permissive | soonhokong/lean | cb8aa01055ffe2af0fb99a16b4cda8463b882cd1 | 38607e3eb57f57f77c0ac114ad169e9e4262e24f | refs/heads/master | 1,611,187,284,081 | 1,450,766,737,000 | 1,476,122,547,000 | 11,513,992 | 2 | 0 | null | 1,401,763,102,000 | 1,374,182,235,000 | C++ | UTF-8 | Lean | false | false | 3,164 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura, Jeremy Avigad, Floris van Doorn
Sigma types, aka dependent sum.
-/
import logic.cast
open inhabited sigma.ops
override eq.ops
namespace sigma
universe variables u v
variables {A A' : Type.{u}} {B : A → Type.{v}} {B' : A' → Type.{v}}
definition unpack {C : (Σa, B a) → Type} {u : Σa, B a} (H : C ⟨u.1 , u.2⟩) : C u :=
destruct u (λx y H, H) H
theorem imp_sigma {C : A → Type} (H : ∀a, (B a → C a)) (p : Σa, B a) : Σa, C a :=
destruct p (λa Hp, mk a (H a Hp))
theorem dpair_heq {a : A} {a' : A'} {b : B a} {b' : B' a'}
(HB : B == B') (Ha : a == a') (Hb : b == b') : ⟨a, b⟩ == ⟨a', b'⟩ :=
hcongr_arg4 @mk (type_eq_of_heq Ha) HB Ha Hb
protected theorem heq {p : Σa : A, B a} {p' : Σa' : A', B' a'} (HB : B == B') :
∀(H₁ : p.1 == p'.1) (H₂ : p.2 == p'.2), p == p' :=
destruct p (take a₁ b₁, destruct p' (take a₂ b₂ H₁ H₂, dpair_heq HB H₁ H₂))
protected definition is_inhabited [instance] [H₁ : inhabited A] [H₂ : inhabited (B (default A))] :
inhabited (sigma B) :=
inhabited.destruct H₁ (λa, inhabited.destruct H₂ (λb, inhabited.mk ⟨default A, b⟩))
theorem eq_rec_dpair_commute {C : Πa, B a → Type} {a a' : A} (H : a = a') (b : B a) (c : C a b) :
eq.rec_on H ⟨b, c⟩ = ⟨eq.rec_on H b, eq.rec_on (dcongr_arg2 C H rfl) c⟩ :=
eq.drec_on H (dpair_eq rfl (!eq.rec_on_id⁻¹))
variables {C : Πa, B a → Type} {D : Πa b, C a b → Type}
definition dtrip (a : A) (b : B a) (c : C a b) := ⟨a, b, c⟩
definition dquad (a : A) (b : B a) (c : C a b) (d : D a b c) := ⟨a, b, c, d⟩
definition pr1' [reducible] (x : Σ a, B a) := x.1
definition pr2' [reducible] (x : Σ a b, C a b) := x.2.1
definition pr3 [reducible] (x : Σ a b, C a b) := x.2.2
definition pr3' [reducible] (x : Σ a b c, D a b c) := x.2.2.1
definition pr4 [reducible] (x : Σ a b c, D a b c) := x.2.2.2
theorem dtrip_eq {a₁ a₂ : A} {b₁ : B a₁} {b₂ : B a₂} {c₁ : C a₁ b₁} {c₂ : C a₂ b₂}
(H₁ : a₁ = a₂) (H₂ : eq.rec_on H₁ b₁ = b₂) (H₃ : cast (dcongr_arg2 C H₁ H₂) c₁ = c₂) :
⟨a₁, b₁, c₁⟩ = ⟨a₂, b₂, c₂⟩ :=
dcongr_arg3 dtrip H₁ H₂ H₃
theorem ndtrip_eq {A B : Type} {C : A → B → Type} {a₁ a₂ : A} {b₁ b₂ : B}
{c₁ : C a₁ b₁} {c₂ : C a₂ b₂} (H₁ : a₁ = a₂) (H₂ : b₁ = b₂)
(H₃ : cast (congr_arg2 C H₁ H₂) c₁ = c₂) : ⟨a₁, b₁, c₁⟩ = ⟨a₂, b₂, c₂⟩ :=
hdcongr_arg3 dtrip H₁ (heq_of_eq H₂) H₃
theorem ndtrip_equal {A B : Type} {C : A → B → Type} {p₁ p₂ : Σa b, C a b} :
∀(H₁ : pr1 p₁ = pr1 p₂) (H₂ : pr2' p₁ = pr2' p₂)
(H₃ : eq.rec_on (congr_arg2 C H₁ H₂) (pr3 p₁) = pr3 p₂), p₁ = p₂ :=
destruct p₁ (take a₁ q₁, destruct q₁ (take b₁ c₁, destruct p₂ (take a₂ q₂, destruct q₂
(take b₂ c₂ H₁ H₂ H₃, ndtrip_eq H₁ H₂ H₃))))
end sigma
|
ea6bdacc665382a3bd41657b4eef8287ca1652df | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/set_theory/ordinal/fixed_point.lean | 819ed03bcdacea7cf7aa41cc36feb65f0b25cb6c | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 24,611 | lean | /-
Copyright (c) 2018 Violeta Hernández Palacios, Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios, Mario Carneiro
-/
import set_theory.ordinal.arithmetic
import set_theory.ordinal.exponential
/-!
# Fixed points of normal functions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We prove various statements about the fixed points of normal ordinal functions. We state them in
three forms: as statements about type-indexed families of normal functions, as statements about
ordinal-indexed families of normal functions, and as statements about a single normal function. For
the most part, the first case encompasses the others.
Moreover, we prove some lemmas about the fixed points of specific normal functions.
## Main definitions and results
* `nfp_family`, `nfp_bfamily`, `nfp`: the next fixed point of a (family of) normal function(s).
* `fp_family_unbounded`, `fp_bfamily_unbounded`, `fp_unbounded`: the (common) fixed points of a
(family of) normal function(s) are unbounded in the ordinals.
* `deriv_add_eq_mul_omega_add`: a characterization of the derivative of addition.
* `deriv_mul_eq_opow_omega_mul`: a characterization of the derivative of multiplication.
-/
noncomputable theory
universes u v
open function order
namespace ordinal
/-! ### Fixed points of type-indexed families of ordinals -/
section
variables {ι : Type u} {f : ι → ordinal.{max u v} → ordinal.{max u v}}
/-- The next common fixed point, at least `a`, for a family of normal functions.
This is defined for any family of functions, as the supremum of all values reachable by applying
finitely many functions in the family to `a`.
`ordinal.nfp_family_fp` shows this is a fixed point, `ordinal.le_nfp_family` shows it's at
least `a`, and `ordinal.nfp_family_le_fp` shows this is the least ordinal with these properties. -/
def nfp_family (f : ι → ordinal → ordinal) (a) : ordinal :=
sup (list.foldr f a)
theorem nfp_family_eq_sup (f : ι → ordinal → ordinal) (a) :
nfp_family f a = sup (list.foldr f a) :=
rfl
theorem foldr_le_nfp_family (f : ι → ordinal → ordinal) (a l) :
list.foldr f a l ≤ nfp_family f a :=
le_sup _ _
theorem le_nfp_family (f : ι → ordinal → ordinal) (a) : a ≤ nfp_family f a :=
le_sup _ []
theorem lt_nfp_family {a b} : a < nfp_family f b ↔ ∃ l, a < list.foldr f b l :=
lt_sup
theorem nfp_family_le_iff {a b} : nfp_family f a ≤ b ↔ ∀ l, list.foldr f a l ≤ b :=
sup_le_iff
theorem nfp_family_le {a b} : (∀ l, list.foldr f a l ≤ b) → nfp_family f a ≤ b :=
sup_le
theorem nfp_family_monotone (hf : ∀ i, monotone (f i)) : monotone (nfp_family f) :=
λ a b h, sup_le $ λ l, (list.foldr_monotone hf l h).trans (le_sup _ l)
theorem apply_lt_nfp_family (H : ∀ i, is_normal (f i)) {a b} (hb : b < nfp_family f a) (i) :
f i b < nfp_family f a :=
let ⟨l, hl⟩ := lt_nfp_family.1 hb in lt_sup.2 ⟨i :: l, (H i).strict_mono hl⟩
theorem apply_lt_nfp_family_iff [nonempty ι] (H : ∀ i, is_normal (f i)) {a b} :
(∀ i, f i b < nfp_family f a) ↔ b < nfp_family f a :=
⟨λ h, lt_nfp_family.2 $ let ⟨l, hl⟩ := lt_sup.1 $ h $ classical.arbitrary ι in
⟨l, ((H _).self_le b).trans_lt hl⟩, apply_lt_nfp_family H⟩
theorem nfp_family_le_apply [nonempty ι] (H : ∀ i, is_normal (f i)) {a b} :
(∃ i, nfp_family f a ≤ f i b) ↔ nfp_family f a ≤ b :=
by { rw ←not_iff_not, push_neg, exact apply_lt_nfp_family_iff H }
theorem nfp_family_le_fp (H : ∀ i, monotone (f i)) {a b} (ab : a ≤ b) (h : ∀ i, f i b ≤ b) :
nfp_family f a ≤ b :=
sup_le $ λ l, begin
by_cases hι : is_empty ι,
{ resetI, rwa unique.eq_default l },
{ haveI := not_is_empty_iff.1 hι,
induction l with i l IH generalizing a, {exact ab},
exact (H i (IH ab)).trans (h i) }
end
theorem nfp_family_fp {i} (H : is_normal (f i)) (a) : f i (nfp_family f a) = nfp_family f a :=
begin
unfold nfp_family,
rw @is_normal.sup _ H _ _ ⟨[]⟩,
apply le_antisymm;
refine ordinal.sup_le (λ l, _),
{ exact le_sup _ (i :: l) },
{ exact (H.self_le _).trans (le_sup _ _) }
end
theorem apply_le_nfp_family [hι : nonempty ι] {f : ι → ordinal → ordinal} (H : ∀ i, is_normal (f i))
{a b} : (∀ i, f i b ≤ nfp_family f a) ↔ b ≤ nfp_family f a :=
begin
refine ⟨λ h, _, λ h i, _⟩,
{ unfreezingI { cases hι with i },
exact ((H i).self_le b).trans (h i) },
rw ←nfp_family_fp (H i),
exact (H i).monotone h
end
theorem nfp_family_eq_self {f : ι → ordinal → ordinal} {a} (h : ∀ i, f i a = a) :
nfp_family f a = a :=
le_antisymm (sup_le $ λ l, by rw list.foldr_fixed' h l) $ le_nfp_family f a
/-- A generalization of the fixed point lemma for normal functions: any family of normal functions
has an unbounded set of common fixed points. -/
-- Todo: This is actually a special case of the fact the intersection of club sets is a club set.
theorem fp_family_unbounded (H : ∀ i, is_normal (f i)) :
(⋂ i, function.fixed_points (f i)).unbounded (<) :=
λ a, ⟨_, λ s ⟨i, hi⟩, begin
rw ←hi,
exact nfp_family_fp (H i) a
end, (le_nfp_family f a).not_lt⟩
/-- The derivative of a family of normal functions is the sequence of their common fixed points.
This is defined for all functions such that `ordinal.deriv_family_zero`,
`ordinal.deriv_family_succ`, and `ordinal.deriv_family_limit` are satisfied. -/
def deriv_family (f : ι → ordinal → ordinal) (o : ordinal) : ordinal :=
limit_rec_on o (nfp_family f 0)
(λ a IH, nfp_family f (succ IH))
(λ a l, bsup.{(max u v) u} a)
@[simp] theorem deriv_family_zero (f : ι → ordinal → ordinal) :
deriv_family f 0 = nfp_family f 0 :=
limit_rec_on_zero _ _ _
@[simp] theorem deriv_family_succ (f : ι → ordinal → ordinal) (o) :
deriv_family f (succ o) = nfp_family f (succ (deriv_family f o)) :=
limit_rec_on_succ _ _ _ _
theorem deriv_family_limit (f : ι → ordinal → ordinal) {o} : is_limit o →
deriv_family f o = bsup.{(max u v) u} o (λ a _, deriv_family f a) :=
limit_rec_on_limit _ _ _ _
theorem deriv_family_is_normal (f : ι → ordinal → ordinal) : is_normal (deriv_family f) :=
⟨λ o, by rw [deriv_family_succ, ← succ_le_iff]; apply le_nfp_family,
λ o l a, by rw [deriv_family_limit _ l, bsup_le_iff]⟩
theorem deriv_family_fp {i} (H : is_normal (f i)) (o : ordinal.{max u v}) :
f i (deriv_family f o) = deriv_family f o :=
begin
refine limit_rec_on o _ (λ o IH, _) _,
{ rw [deriv_family_zero], exact nfp_family_fp H 0 },
{ rw [deriv_family_succ], exact nfp_family_fp H _ },
{ intros o l IH,
rw [deriv_family_limit _ l,
is_normal.bsup.{(max u v) u (max u v)} H (λ a _, deriv_family f a) l.1],
refine eq_of_forall_ge_iff (λ c, _),
simp only [bsup_le_iff, IH] {contextual:=tt} }
end
theorem le_iff_deriv_family (H : ∀ i, is_normal (f i)) {a} :
(∀ i, f i a ≤ a) ↔ ∃ o, deriv_family f o = a :=
⟨λ ha, begin
suffices : ∀ o (_ : a ≤ deriv_family f o), ∃ o, deriv_family f o = a,
from this a ((deriv_family_is_normal _).self_le _),
refine λ o, limit_rec_on o (λ h₁, ⟨0, le_antisymm _ h₁⟩) (λ o IH h₁, _) (λ o l IH h₁, _),
{ rw deriv_family_zero,
exact nfp_family_le_fp (λ i, (H i).monotone) (ordinal.zero_le _) ha },
{ cases le_or_lt a (deriv_family f o), {exact IH h},
refine ⟨succ o, le_antisymm _ h₁⟩,
rw deriv_family_succ,
exact nfp_family_le_fp (λ i, (H i).monotone) (succ_le_of_lt h) ha },
{ cases eq_or_lt_of_le h₁, {exact ⟨_, h.symm⟩},
rw [deriv_family_limit _ l, ← not_le, bsup_le_iff, not_ball] at h,
exact let ⟨o', h, hl⟩ := h in IH o' h (le_of_not_le hl) }
end, λ ⟨o, e⟩ i, e ▸ (deriv_family_fp (H i) _).le⟩
theorem fp_iff_deriv_family (H : ∀ i, is_normal (f i)) {a} :
(∀ i, f i a = a) ↔ ∃ o, deriv_family f o = a :=
iff.trans ⟨λ h i, le_of_eq (h i), λ h i, (H i).le_iff_eq.1 (h i)⟩ (le_iff_deriv_family H)
/-- For a family of normal functions, `ordinal.deriv_family` enumerates the common fixed points. -/
theorem deriv_family_eq_enum_ord (H : ∀ i, is_normal (f i)) :
deriv_family f = enum_ord (⋂ i, function.fixed_points (f i)) :=
begin
rw ←eq_enum_ord _ (fp_family_unbounded H),
use (deriv_family_is_normal f).strict_mono,
rw set.range_eq_iff,
refine ⟨_, λ a ha, _⟩,
{ rintros a S ⟨i, hi⟩,
rw ←hi,
exact deriv_family_fp (H i) a },
rw set.mem_Inter at ha,
rwa ←fp_iff_deriv_family H
end
end
/-! ### Fixed points of ordinal-indexed families of ordinals -/
section
variables {o : ordinal.{u}} {f : Π b < o, ordinal.{max u v} → ordinal.{max u v}}
/-- The next common fixed point, at least `a`, for a family of normal functions indexed by ordinals.
This is defined as `ordinal.nfp_family` of the type-indexed family associated to `f`.
-/
def nfp_bfamily (o : ordinal) (f : Π b < o, ordinal → ordinal) : ordinal → ordinal :=
nfp_family (family_of_bfamily o f)
theorem nfp_bfamily_eq_nfp_family {o : ordinal} (f : Π b < o, ordinal → ordinal) :
nfp_bfamily o f = nfp_family (family_of_bfamily o f) :=
rfl
theorem foldr_le_nfp_bfamily {o : ordinal} (f : Π b < o, ordinal → ordinal) (a l) :
list.foldr (family_of_bfamily o f) a l ≤ nfp_bfamily o f a :=
le_sup _ _
theorem le_nfp_bfamily {o : ordinal} (f : Π b < o, ordinal → ordinal) (a) :
a ≤ nfp_bfamily o f a :=
le_sup _ []
theorem lt_nfp_bfamily {a b} :
a < nfp_bfamily o f b ↔ ∃ l, a < list.foldr (family_of_bfamily o f) b l :=
lt_sup
theorem nfp_bfamily_le_iff {o : ordinal} {f : Π b < o, ordinal → ordinal} {a b} :
nfp_bfamily o f a ≤ b ↔ ∀ l, list.foldr (family_of_bfamily o f) a l ≤ b :=
sup_le_iff
theorem nfp_bfamily_le {o : ordinal} {f : Π b < o, ordinal → ordinal} {a b} :
(∀ l, list.foldr (family_of_bfamily o f) a l ≤ b) → nfp_bfamily o f a ≤ b :=
sup_le
theorem nfp_bfamily_monotone (hf : ∀ i hi, monotone (f i hi)) : monotone (nfp_bfamily o f) :=
nfp_family_monotone (λ i, hf _ _)
theorem apply_lt_nfp_bfamily (H : ∀ i hi, is_normal (f i hi)) {a b} (hb : b < nfp_bfamily o f a)
(i hi) : f i hi b < nfp_bfamily o f a :=
begin
rw ←family_of_bfamily_enum o f,
apply apply_lt_nfp_family _ hb,
exact λ _, H _ _
end
theorem apply_lt_nfp_bfamily_iff (ho : o ≠ 0) (H : ∀ i hi, is_normal (f i hi)) {a b} :
(∀ i hi, f i hi b < nfp_bfamily o f a) ↔ b < nfp_bfamily o f a :=
⟨λ h, begin
haveI := out_nonempty_iff_ne_zero.2 ho,
refine (apply_lt_nfp_family_iff _).1 (λ _, h _ _),
exact λ _, H _ _,
end, apply_lt_nfp_bfamily H⟩
theorem nfp_bfamily_le_apply (ho : o ≠ 0) (H : ∀ i hi, is_normal (f i hi)) {a b} :
(∃ i hi, nfp_bfamily o f a ≤ f i hi b) ↔ nfp_bfamily o f a ≤ b :=
by { rw ←not_iff_not, push_neg, convert apply_lt_nfp_bfamily_iff ho H, simp only [not_le] }
theorem nfp_bfamily_le_fp (H : ∀ i hi, monotone (f i hi)) {a b} (ab : a ≤ b)
(h : ∀ i hi, f i hi b ≤ b) : nfp_bfamily o f a ≤ b :=
nfp_family_le_fp (λ _, H _ _) ab (λ i, h _ _)
theorem nfp_bfamily_fp {i hi} (H : is_normal (f i hi)) (a) :
f i hi (nfp_bfamily o f a) = nfp_bfamily o f a :=
by { rw ←family_of_bfamily_enum o f, apply nfp_family_fp, rw family_of_bfamily_enum, exact H }
theorem apply_le_nfp_bfamily (ho : o ≠ 0) (H : ∀ i hi, is_normal (f i hi)) {a b} :
(∀ i hi, f i hi b ≤ nfp_bfamily o f a) ↔ b ≤ nfp_bfamily o f a :=
begin
refine ⟨λ h, _, λ h i hi, _⟩,
{ have ho' : 0 < o := ordinal.pos_iff_ne_zero.2 ho,
exact ((H 0 ho').self_le b).trans (h 0 ho') },
{ rw ←nfp_bfamily_fp (H i hi),
exact (H i hi).monotone h }
end
theorem nfp_bfamily_eq_self {a} (h : ∀ i hi, f i hi a = a) : nfp_bfamily o f a = a :=
nfp_family_eq_self (λ _, h _ _)
/-- A generalization of the fixed point lemma for normal functions: any family of normal functions
has an unbounded set of common fixed points. -/
theorem fp_bfamily_unbounded (H : ∀ i hi, is_normal (f i hi)) :
(⋂ i hi, function.fixed_points (f i hi)).unbounded (<) :=
λ a, ⟨_, by { rw set.mem_Inter₂, exact λ i hi, nfp_bfamily_fp (H i hi) _ },
(le_nfp_bfamily f a).not_lt⟩
/-- The derivative of a family of normal functions is the sequence of their common fixed points.
This is defined as `ordinal.deriv_family` of the type-indexed family associated to `f`. -/
def deriv_bfamily (o : ordinal) (f : Π b < o, ordinal → ordinal) : ordinal → ordinal :=
deriv_family (family_of_bfamily o f)
theorem deriv_bfamily_eq_deriv_family {o : ordinal} (f : Π b < o, ordinal → ordinal) :
deriv_bfamily o f = deriv_family (family_of_bfamily o f) :=
rfl
theorem deriv_bfamily_is_normal {o : ordinal} (f : Π b < o, ordinal → ordinal) :
is_normal (deriv_bfamily o f) :=
deriv_family_is_normal _
theorem deriv_bfamily_fp {i hi} (H : is_normal (f i hi)) (a : ordinal) :
f i hi (deriv_bfamily o f a) = deriv_bfamily o f a :=
by { rw ←family_of_bfamily_enum o f, apply deriv_family_fp, rw family_of_bfamily_enum, exact H }
theorem le_iff_deriv_bfamily (H : ∀ i hi, is_normal (f i hi)) {a} :
(∀ i hi, f i hi a ≤ a) ↔ ∃ b, deriv_bfamily o f b = a :=
begin
unfold deriv_bfamily,
rw ←le_iff_deriv_family,
{ refine ⟨λ h i, h _ _, λ h i hi, _⟩,
rw ←family_of_bfamily_enum o f,
apply h },
{ exact λ _, H _ _ }
end
theorem fp_iff_deriv_bfamily (H : ∀ i hi, is_normal (f i hi)) {a} :
(∀ i hi, f i hi a = a) ↔ ∃ b, deriv_bfamily o f b = a :=
begin
rw ←le_iff_deriv_bfamily H,
refine ⟨λ h i hi, le_of_eq (h i hi), λ h i hi, _⟩,
rw ←(H i hi).le_iff_eq,
exact h i hi
end
/-- For a family of normal functions, `ordinal.deriv_bfamily` enumerates the common fixed points. -/
theorem deriv_bfamily_eq_enum_ord (H : ∀ i hi, is_normal (f i hi)) :
deriv_bfamily o f = enum_ord (⋂ i hi, function.fixed_points (f i hi)) :=
begin
rw ←eq_enum_ord _ (fp_bfamily_unbounded H),
use (deriv_bfamily_is_normal f).strict_mono,
rw set.range_eq_iff,
refine ⟨λ a, set.mem_Inter₂.2 (λ i hi, deriv_bfamily_fp (H i hi) a), λ a ha, _⟩,
rw set.mem_Inter₂ at ha,
rwa ←fp_iff_deriv_bfamily H
end
end
/-! ### Fixed points of a single function -/
section
variable {f : ordinal.{u} → ordinal.{u}}
/-- The next fixed point function, the least fixed point of the normal function `f`, at least `a`.
This is defined as `ordinal.nfp_family` applied to a family consisting only of `f`. -/
def nfp (f : ordinal → ordinal) : ordinal → ordinal :=
nfp_family (λ _ : unit, f)
theorem nfp_eq_nfp_family (f : ordinal → ordinal) : nfp f = nfp_family (λ _ : unit, f) :=
rfl
@[simp] theorem sup_iterate_eq_nfp (f : ordinal.{u} → ordinal.{u}) :
(λ a, sup (λ n : ℕ, f^[n] a)) = nfp f :=
begin
refine funext (λ a, le_antisymm _ (sup_le (λ l, _))),
{ rw sup_le_iff,
intro n,
rw [←list.length_replicate n unit.star, ←list.foldr_const f a],
apply le_sup },
{ rw list.foldr_const f a l,
exact le_sup _ _ },
end
theorem iterate_le_nfp (f a n) : f^[n] a ≤ nfp f a :=
by { rw ←sup_iterate_eq_nfp, exact le_sup _ n }
theorem le_nfp (f a) : a ≤ nfp f a :=
iterate_le_nfp f a 0
theorem lt_nfp {a b} : a < nfp f b ↔ ∃ n, a < (f^[n]) b :=
by { rw ←sup_iterate_eq_nfp, exact lt_sup }
theorem nfp_le_iff {a b} : nfp f a ≤ b ↔ ∀ n, (f^[n]) a ≤ b :=
by { rw ←sup_iterate_eq_nfp, exact sup_le_iff }
theorem nfp_le {a b} : (∀ n, (f^[n]) a ≤ b) → nfp f a ≤ b := nfp_le_iff.2
@[simp] theorem nfp_id : nfp id = id :=
funext (λ a, begin
simp_rw [←sup_iterate_eq_nfp, iterate_id],
exact sup_const a
end)
theorem nfp_monotone (hf : monotone f) : monotone (nfp f) :=
nfp_family_monotone (λ i, hf)
theorem is_normal.apply_lt_nfp {f} (H : is_normal f) {a b} :
f b < nfp f a ↔ b < nfp f a :=
begin
unfold nfp,
rw ←@apply_lt_nfp_family_iff unit (λ _, f) _ (λ _, H) a b,
exact ⟨λ h _, h, λ h, h unit.star⟩
end
theorem is_normal.nfp_le_apply {f} (H : is_normal f) {a b} : nfp f a ≤ f b ↔ nfp f a ≤ b :=
le_iff_le_iff_lt_iff_lt.2 H.apply_lt_nfp
theorem nfp_le_fp {f} (H : monotone f) {a b} (ab : a ≤ b) (h : f b ≤ b) : nfp f a ≤ b :=
nfp_family_le_fp (λ _, H) ab (λ _, h)
theorem is_normal.nfp_fp {f} (H : is_normal f) : ∀ a, f (nfp f a) = nfp f a :=
@nfp_family_fp unit (λ _, f) unit.star H
theorem is_normal.apply_le_nfp {f} (H : is_normal f) {a b} :
f b ≤ nfp f a ↔ b ≤ nfp f a :=
⟨le_trans (H.self_le _), λ h, by simpa only [H.nfp_fp] using H.le_iff.2 h⟩
theorem nfp_eq_self {f : ordinal → ordinal} {a} (h : f a = a) : nfp f a = a :=
nfp_family_eq_self (λ _, h)
/-- The fixed point lemma for normal functions: any normal function has an unbounded set of
fixed points. -/
theorem fp_unbounded (H : is_normal f) : (function.fixed_points f).unbounded (<) :=
by { convert fp_family_unbounded (λ _ : unit, H), exact (set.Inter_const _).symm }
/-- The derivative of a normal function `f` is the sequence of fixed points of `f`.
This is defined as `ordinal.deriv_family` applied to a trivial family consisting only of `f`. -/
def deriv (f : ordinal → ordinal) : ordinal → ordinal :=
deriv_family (λ _ : unit, f)
theorem deriv_eq_deriv_family (f : ordinal → ordinal) : deriv f = deriv_family (λ _ : unit, f) :=
rfl
@[simp] theorem deriv_zero (f) : deriv f 0 = nfp f 0 :=
deriv_family_zero _
@[simp] theorem deriv_succ (f o) : deriv f (succ o) = nfp f (succ (deriv f o)) :=
deriv_family_succ _ _
theorem deriv_limit (f) {o} : is_limit o → deriv f o = bsup.{u 0} o (λ a _, deriv f a) :=
deriv_family_limit _
theorem deriv_is_normal (f) : is_normal (deriv f) :=
deriv_family_is_normal _
theorem deriv_id_of_nfp_id {f : ordinal → ordinal} (h : nfp f = id) : deriv f = id :=
((deriv_is_normal _).eq_iff_zero_and_succ is_normal.refl).2 (by simp [h])
theorem is_normal.deriv_fp {f} (H : is_normal f) : ∀ o, f (deriv f o) = deriv f o :=
@deriv_family_fp unit (λ _, f) unit.star H
theorem is_normal.le_iff_deriv {f} (H : is_normal f) {a} : f a ≤ a ↔ ∃ o, deriv f o = a :=
begin
unfold deriv,
rw ←le_iff_deriv_family (λ _ : unit, H),
exact ⟨λ h _, h, λ h, h unit.star⟩
end
theorem is_normal.fp_iff_deriv {f} (H : is_normal f) {a} : f a = a ↔ ∃ o, deriv f o = a :=
by rw [←H.le_iff_eq, H.le_iff_deriv]
/-- `ordinal.deriv` enumerates the fixed points of a normal function. -/
theorem deriv_eq_enum_ord (H : is_normal f) : deriv f = enum_ord (function.fixed_points f) :=
by { convert deriv_family_eq_enum_ord (λ _ : unit, H), exact (set.Inter_const _).symm }
theorem deriv_eq_id_of_nfp_eq_id {f : ordinal → ordinal} (h : nfp f = id) : deriv f = id :=
(is_normal.eq_iff_zero_and_succ (deriv_is_normal _) is_normal.refl).2 $ by simp [h]
end
/-! ### Fixed points of addition -/
@[simp] theorem nfp_add_zero (a) : nfp ((+) a) 0 = a * omega :=
begin
simp_rw [←sup_iterate_eq_nfp, ←sup_mul_nat],
congr, funext,
induction n with n hn,
{ rw [nat.cast_zero, mul_zero, iterate_zero_apply] },
{ nth_rewrite 1 nat.succ_eq_one_add,
rw [nat.cast_add, nat.cast_one, mul_one_add, iterate_succ_apply', hn] }
end
theorem nfp_add_eq_mul_omega {a b} (hba : b ≤ a * omega) :
nfp ((+) a) b = a * omega :=
begin
apply le_antisymm (nfp_le_fp (add_is_normal a).monotone hba _),
{ rw ←nfp_add_zero,
exact nfp_monotone (add_is_normal a).monotone (ordinal.zero_le b) },
{ rw [←mul_one_add, one_add_omega] }
end
theorem add_eq_right_iff_mul_omega_le {a b : ordinal} : a + b = b ↔ a * omega ≤ b :=
begin
refine ⟨λ h, _, λ h, _⟩,
{ rw [←nfp_add_zero a, ←deriv_zero],
cases (add_is_normal a).fp_iff_deriv.1 h with c hc,
rw ←hc,
exact (deriv_is_normal _).monotone (ordinal.zero_le _) },
{ have := ordinal.add_sub_cancel_of_le h,
nth_rewrite 0 ←this,
rwa [←add_assoc, ←mul_one_add, one_add_omega] }
end
theorem add_le_right_iff_mul_omega_le {a b : ordinal} : a + b ≤ b ↔ a * omega ≤ b :=
by { rw ←add_eq_right_iff_mul_omega_le, exact (add_is_normal a).le_iff_eq }
theorem deriv_add_eq_mul_omega_add (a b : ordinal.{u}) : deriv ((+) a) b = a * omega + b :=
begin
revert b,
rw [←funext_iff, is_normal.eq_iff_zero_and_succ (deriv_is_normal _) (add_is_normal _)],
refine ⟨_, λ a h, _⟩,
{ rw [deriv_zero, add_zero],
exact nfp_add_zero a },
{ rw [deriv_succ, h, add_succ],
exact nfp_eq_self (add_eq_right_iff_mul_omega_le.2 ((le_add_right _ _).trans (le_succ _))) }
end
/-! ### Fixed points of multiplication -/
local infixr (name := ordinal.pow) ^ := @pow ordinal ordinal ordinal.has_pow
@[simp] theorem nfp_mul_one {a : ordinal} (ha : 0 < a) : nfp ((*) a) 1 = a ^ omega :=
begin
rw [←sup_iterate_eq_nfp, ←sup_opow_nat],
{ dsimp, congr, funext,
induction n with n hn,
{ rw [nat.cast_zero, opow_zero, iterate_zero_apply] },
nth_rewrite 1 nat.succ_eq_one_add,
rw [nat.cast_add, nat.cast_one, opow_add, opow_one, iterate_succ_apply', hn] },
{ exact ha }
end
@[simp] theorem nfp_mul_zero (a : ordinal) : nfp ((*) a) 0 = 0 :=
begin
rw [←ordinal.le_zero, nfp_le_iff],
intro n,
induction n with n hn, { refl },
rwa [iterate_succ_apply, mul_zero]
end
@[simp] theorem nfp_zero_mul : nfp ((*) 0) = id :=
begin
rw ←sup_iterate_eq_nfp,
refine funext (λ a, (sup_le (λ n, _)).antisymm (le_sup (λ n, ((*) 0)^[n] a) 0)),
induction n with n hn, { refl },
rw function.iterate_succ',
change 0 * _ ≤ a,
rw zero_mul,
exact ordinal.zero_le a
end
@[simp] theorem deriv_mul_zero : deriv ((*) 0) = id :=
deriv_eq_id_of_nfp_eq_id nfp_zero_mul
theorem nfp_mul_eq_opow_omega {a b : ordinal} (hb : 0 < b) (hba : b ≤ a ^ omega) :
nfp ((*) a) b = a ^ omega.{u} :=
begin
cases eq_zero_or_pos a with ha ha,
{ rw [ha, zero_opow omega_ne_zero] at *,
rw [ordinal.le_zero.1 hba, nfp_zero_mul],
refl },
apply le_antisymm,
{ apply nfp_le_fp (mul_is_normal ha).monotone hba,
rw [←opow_one_add, one_add_omega] },
rw ←nfp_mul_one ha,
exact nfp_monotone (mul_is_normal ha).monotone (one_le_iff_pos.2 hb)
end
theorem eq_zero_or_opow_omega_le_of_mul_eq_right {a b : ordinal} (hab : a * b = b) :
b = 0 ∨ a ^ omega.{u} ≤ b :=
begin
cases eq_zero_or_pos a with ha ha,
{ rw [ha, zero_opow omega_ne_zero],
exact or.inr (ordinal.zero_le b) },
rw or_iff_not_imp_left,
intro hb,
change b ≠ 0 at hb,
rw ←nfp_mul_one ha,
rw ←one_le_iff_ne_zero at hb,
exact nfp_le_fp (mul_is_normal ha).monotone hb (le_of_eq hab)
end
theorem mul_eq_right_iff_opow_omega_dvd {a b : ordinal} : a * b = b ↔ a ^ omega ∣ b :=
begin
cases eq_zero_or_pos a with ha ha,
{ rw [ha, zero_mul, zero_opow omega_ne_zero, zero_dvd_iff],
exact eq_comm },
refine ⟨λ hab, _, λ h, _⟩,
{ rw dvd_iff_mod_eq_zero,
rw [←div_add_mod b (a ^ omega), mul_add, ←mul_assoc, ←opow_one_add, one_add_omega,
add_left_cancel] at hab,
cases eq_zero_or_opow_omega_le_of_mul_eq_right hab with hab hab,
{ exact hab },
refine (not_lt_of_le hab (mod_lt b (opow_ne_zero omega _))).elim,
rwa ←ordinal.pos_iff_ne_zero },
cases h with c hc,
rw [hc, ←mul_assoc, ←opow_one_add, one_add_omega]
end
theorem mul_le_right_iff_opow_omega_dvd {a b : ordinal} (ha : 0 < a) : a * b ≤ b ↔ a ^ omega ∣ b :=
by { rw ←mul_eq_right_iff_opow_omega_dvd, exact (mul_is_normal ha).le_iff_eq }
theorem nfp_mul_opow_omega_add {a c : ordinal} (b) (ha : 0 < a) (hc : 0 < c) (hca : c ≤ a ^ omega) :
nfp ((*) a) (a ^ omega * b + c) = a ^ omega.{u} * (succ b) :=
begin
apply le_antisymm,
{ apply nfp_le_fp (mul_is_normal ha).monotone,
{ rw mul_succ,
apply add_le_add_left hca },
{ rw [←mul_assoc, ←opow_one_add, one_add_omega] } },
{ cases mul_eq_right_iff_opow_omega_dvd.1 ((mul_is_normal ha).nfp_fp (a ^ omega * b + c))
with d hd,
rw hd,
apply mul_le_mul_left',
have := le_nfp (has_mul.mul a) (a ^ omega * b + c),
rw hd at this,
have := (add_lt_add_left hc (a ^ omega * b)).trans_le this,
rw [add_zero, mul_lt_mul_iff_left (opow_pos omega ha)] at this,
rwa succ_le_iff }
end
theorem deriv_mul_eq_opow_omega_mul {a : ordinal.{u}} (ha : 0 < a) (b) :
deriv ((*) a) b = a ^ omega * b :=
begin
revert b,
rw [←funext_iff,
is_normal.eq_iff_zero_and_succ (deriv_is_normal _) (mul_is_normal (opow_pos omega ha))],
refine ⟨_, λ c h, _⟩,
{ rw [deriv_zero, nfp_mul_zero, mul_zero] },
{ rw [deriv_succ, h],
exact nfp_mul_opow_omega_add c ha zero_lt_one (one_le_iff_pos.2 (opow_pos _ ha)) },
end
end ordinal
|
e8fbda035382e9d118488473e8472d0038812efe | b561a44b48979a98df50ade0789a21c79ee31288 | /stage0/src/Lean/Elab/BuiltinTerm.lean | 823568acde62ce1062d870b7ba585c08e5ad987e | [
"Apache-2.0"
] | permissive | 3401ijk/lean4 | 97659c475ebd33a034fed515cb83a85f75ccfb06 | a5b1b8de4f4b038ff752b9e607b721f15a9a4351 | refs/heads/master | 1,693,933,007,651 | 1,636,424,845,000 | 1,636,424,845,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,403 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Elab.Term
namespace Lean.Elab.Term
open Meta
@[builtinTermElab «prop»] def elabProp : TermElab := fun _ _ =>
return mkSort levelZero
private def elabOptLevel (stx : Syntax) : TermElabM Level :=
if stx.isNone then
pure levelZero
else
elabLevel stx[0]
@[builtinTermElab «sort»] def elabSort : TermElab := fun stx _ =>
return mkSort (← elabOptLevel stx[1])
@[builtinTermElab «type»] def elabTypeStx : TermElab := fun stx _ =>
return mkSort (mkLevelSucc (← elabOptLevel stx[1]))
/-
the method `resolveName` adds a completion point for it using the given
expected type. Thus, we propagate the expected type if `stx[0]` is an identifier.
It doesn't "hurt" if the identifier can be resolved because the expected type is not used in this case.
Recall that if the name resolution fails a synthetic sorry is returned.-/
@[builtinTermElab «pipeCompletion»] def elabPipeCompletion : TermElab := fun stx expectedType? => do
let e ← elabTerm stx[0] none
unless e.isSorry do
addDotCompletionInfo stx e expectedType?
throwErrorAt stx[1] "invalid field notation, identifier or numeral expected"
@[builtinTermElab «completion»] def elabCompletion : TermElab := fun stx expectedType? => do
/- `ident.` is ambiguous in Lean, we may try to be completing a declaration name or access a "field". -/
if stx[0].isIdent then
/- If we can elaborate the identifier successfully, we assume it is a dot-completion. Otherwise, we treat it as
identifier completion with a dangling `.`.
Recall that the server falls back to identifier completion when dot-completion fails. -/
let s ← saveState
try
let e ← elabTerm stx[0] none
addDotCompletionInfo stx e expectedType?
catch _ =>
s.restore
addCompletionInfo <| CompletionInfo.id stx stx[0].getId (danglingDot := true) (← getLCtx) expectedType?
throwErrorAt stx[1] "invalid field notation, identifier or numeral expected"
else
elabPipeCompletion stx expectedType?
@[builtinTermElab «hole»] def elabHole : TermElab := fun stx expectedType? => do
let mvar ← mkFreshExprMVar expectedType?
registerMVarErrorHoleInfo mvar.mvarId! stx
pure mvar
@[builtinTermElab «syntheticHole»] def elabSyntheticHole : TermElab := fun stx expectedType? => do
let arg := stx[1]
let userName := if arg.isIdent then arg.getId else Name.anonymous
let mkNewHole : Unit → TermElabM Expr := fun _ => do
let mvar ← mkFreshExprMVar expectedType? MetavarKind.syntheticOpaque userName
registerMVarErrorHoleInfo mvar.mvarId! stx
pure mvar
if userName.isAnonymous then
mkNewHole ()
else
let mctx ← getMCtx
match mctx.findUserName? userName with
| none => mkNewHole ()
| some mvarId =>
let mvar := mkMVar mvarId
let mvarDecl ← getMVarDecl mvarId
let lctx ← getLCtx
if mvarDecl.lctx.isSubPrefixOf lctx then
pure mvar
else match mctx.getExprAssignment? mvarId with
| some val =>
let val ← instantiateMVars val
if mctx.isWellFormed lctx val then
pure val
else
withLCtx mvarDecl.lctx mvarDecl.localInstances do
throwError "synthetic hole has already been defined and assigned to value incompatible with the current context{indentExpr val}"
| none =>
if mctx.isDelayedAssigned mvarId then
-- We can try to improve this case if needed.
throwError "synthetic hole has already beend defined and delayed assigned with an incompatible local context"
else if lctx.isSubPrefixOf mvarDecl.lctx then
let mvarNew ← mkNewHole ()
modifyMCtx fun mctx => mctx.assignExpr mvarId mvarNew
pure mvarNew
else
throwError "synthetic hole has already been defined with an incompatible local context"
@[builtinTermElab «letMVar»] def elabLetMVar : TermElab := fun stx expectedType? => do
match stx with
| `(let_mvar% ? $n := $e; $b) =>
match (← getMCtx).findUserName? n.getId with
| some _ => throwError "invalid 'let_mvar%', metavariable '?{n.getId}' has already been used"
| none =>
let e ← elabTerm e none
let mvar ← mkFreshExprMVar (← inferType e) MetavarKind.syntheticOpaque n.getId
assignExprMVar mvar.mvarId! e
-- We use `mkSaveInfoAnnotation` to make sure the info trees for `e` are saved even if `b` is a metavariable.
return mkSaveInfoAnnotation (← elabTerm b expectedType?)
| _ => throwUnsupportedSyntax
private def getMVarFromUserName (ident : Syntax) : MetaM Expr := do
match (← getMCtx).findUserName? ident.getId with
| none => throwError "unknown metavariable '?{ident.getId}'"
| some mvarId => instantiateMVars (mkMVar mvarId)
@[builtinTermElab «waitIfTypeMVar»] def elabWaitIfTypeMVar : TermElab := fun stx expectedType? => do
match stx with
| `(wait_if_type_mvar% ? $n; $b) =>
tryPostponeIfMVar (← inferType (← getMVarFromUserName n))
elabTerm b expectedType?
| _ => throwUnsupportedSyntax
@[builtinTermElab «waitIfTypeContainsMVar»] def elabWaitIfTypeContainsMVar : TermElab := fun stx expectedType? => do
match stx with
| `(wait_if_type_contains_mvar% ? $n; $b) =>
if (← instantiateMVars (← inferType (← getMVarFromUserName n))).hasExprMVar then
tryPostpone
elabTerm b expectedType?
| _ => throwUnsupportedSyntax
@[builtinTermElab «waitIfContainsMVar»] def elabWaitIfContainsMVar : TermElab := fun stx expectedType? => do
match stx with
| `(wait_if_contains_mvar% ? $n; $b) =>
if (← getMVarFromUserName n).hasExprMVar then
tryPostpone
elabTerm b expectedType?
| _ => throwUnsupportedSyntax
private def mkTacticMVar (type : Expr) (tacticCode : Syntax) : TermElabM Expr := do
let mvar ← mkFreshExprMVar type MetavarKind.syntheticOpaque
let mvarId := mvar.mvarId!
let ref ← getRef
let declName? ← getDeclName?
registerSyntheticMVar ref mvarId <| SyntheticMVarKind.tactic tacticCode (← saveContext)
return mvar
@[builtinTermElab byTactic] def elabByTactic : TermElab := fun stx expectedType? =>
match expectedType? with
| some expectedType => mkTacticMVar expectedType stx
| none => throwError ("invalid 'by' tactic, expected type has not been provided")
@[builtinTermElab noImplicitLambda] def elabNoImplicitLambda : TermElab := fun stx expectedType? =>
elabTerm stx[1] (mkNoImplicitLambdaAnnotation <$> expectedType?)
@[builtinTermElab cdot] def elabBadCDot : TermElab := fun stx _ =>
throwError "invalid occurrence of `·` notation, it must be surrounded by parentheses (e.g. `(· + 1)`)"
@[builtinTermElab strLit] def elabStrLit : TermElab := fun stx _ => do
match stx.isStrLit? with
| some val => pure $ mkStrLit val
| none => throwIllFormedSyntax
private def mkFreshTypeMVarFor (expectedType? : Option Expr) : TermElabM Expr := do
let typeMVar ← mkFreshTypeMVar MetavarKind.synthetic
match expectedType? with
| some expectedType => discard <| isDefEq expectedType typeMVar
| _ => pure ()
return typeMVar
@[builtinTermElab numLit] def elabNumLit : TermElab := fun stx expectedType? => do
let val ← match stx.isNatLit? with
| some val => pure val
| none => throwIllFormedSyntax
let typeMVar ← mkFreshTypeMVarFor expectedType?
let u ← getDecLevel typeMVar
let mvar ← mkInstMVar (mkApp2 (Lean.mkConst ``OfNat [u]) typeMVar (mkRawNatLit val))
let r := mkApp3 (Lean.mkConst ``OfNat.ofNat [u]) typeMVar (mkRawNatLit val) mvar
registerMVarErrorImplicitArgInfo mvar.mvarId! stx r
return r
@[builtinTermElab rawNatLit] def elabRawNatLit : TermElab := fun stx expectedType? => do
match stx[1].isNatLit? with
| some val => return mkRawNatLit val
| none => throwIllFormedSyntax
@[builtinTermElab scientificLit]
def elabScientificLit : TermElab := fun stx expectedType? => do
match stx.isScientificLit? with
| none => throwIllFormedSyntax
| some (m, sign, e) =>
let typeMVar ← mkFreshTypeMVarFor expectedType?
let u ← getDecLevel typeMVar
let mvar ← mkInstMVar (mkApp (Lean.mkConst ``OfScientific [u]) typeMVar)
let r := mkApp5 (Lean.mkConst ``OfScientific.ofScientific [u]) typeMVar mvar (mkRawNatLit m) (toExpr sign) (mkRawNatLit e)
registerMVarErrorImplicitArgInfo mvar.mvarId! stx r
return r
@[builtinTermElab charLit] def elabCharLit : TermElab := fun stx _ => do
match stx.isCharLit? with
| some val => return mkApp (Lean.mkConst ``Char.ofNat) (mkRawNatLit val.toNat)
| none => throwIllFormedSyntax
@[builtinTermElab quotedName] def elabQuotedName : TermElab := fun stx _ =>
match stx[0].isNameLit? with
| some val => pure $ toExpr val
| none => throwIllFormedSyntax
@[builtinTermElab doubleQuotedName] def elabDoubleQuotedName : TermElab := fun stx _ => do
toExpr (← resolveGlobalConstNoOverloadWithInfo stx[2])
@[builtinTermElab typeOf] def elabTypeOf : TermElab := fun stx _ => do
inferType (← elabTerm stx[1] none)
@[builtinTermElab ensureTypeOf] def elabEnsureTypeOf : TermElab := fun stx expectedType? =>
match stx[2].isStrLit? with
| none => throwIllFormedSyntax
| some msg => do
let refTerm ← elabTerm stx[1] none
let refTermType ← inferType refTerm
elabTermEnsuringType stx[3] refTermType (errorMsgHeader? := msg)
@[builtinTermElab ensureExpectedType] def elabEnsureExpectedType : TermElab := fun stx expectedType? =>
match stx[1].isStrLit? with
| none => throwIllFormedSyntax
| some msg => elabTermEnsuringType stx[2] expectedType? (errorMsgHeader? := msg)
@[builtinTermElab «open»] def elabOpen : TermElab := fun stx expectedType? => do
try
pushScope
let openDecls ← elabOpenDecl stx[1]
withTheReader Core.Context (fun ctx => { ctx with openDecls := openDecls }) do
elabTerm stx[3] expectedType?
finally
popScope
@[builtinTermElab «set_option»] def elabSetOption : TermElab := fun stx expectedType? => do
let options ← Elab.elabSetOption stx[1] stx[2]
withTheReader Core.Context (fun ctx => { ctx with maxRecDepth := maxRecDepth.get options, options := options }) do
elabTerm stx[4] expectedType?
end Lean.Elab.Term
|
115bfe096b8edcc4b174b572e0aa5d9324a67793 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/topology/algebra/group_completion.lean | afe26321bb8f40c9ce1824f77cb85bcfac544623 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 10,480 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
-/
import algebra.hom.group_instances
import topology.algebra.uniform_group
import topology.algebra.uniform_mul_action
import topology.uniform_space.completion
/-!
# Completion of topological groups:
This files endows the completion of a topological abelian group with a group structure.
More precisely the instance `uniform_space.completion.add_group` builds an abelian group structure
on the completion of an abelian group endowed with a compatible uniform structure.
Then the instance `uniform_space.completion.uniform_add_group` proves this group structure is
compatible with the completed uniform structure. The compatibility condition is `uniform_add_group`.
## Main declarations:
Beyond the instances explained above (that don't have to be explicitly invoked),
the main constructions deal with continuous group morphisms.
* `add_monoid_hom.extension`: extends a continuous group morphism from `G`
to a complete separated group `H` to `completion G`.
* `add_monoid_hom.completion`: promotes a continuous group morphism
from `G` to `H` into a continuous group morphism
from `completion G` to `completion H`.
-/
noncomputable theory
variables {M R α β : Type*}
section group
open uniform_space Cauchy filter set
variables [uniform_space α]
instance [has_zero α] : has_zero (completion α) := ⟨(0 : α)⟩
instance [has_neg α] : has_neg (completion α) := ⟨completion.map (λa, -a : α → α)⟩
instance [has_add α] : has_add (completion α) := ⟨completion.map₂ (+)⟩
instance [has_sub α] : has_sub (completion α) := ⟨completion.map₂ has_sub.sub⟩
@[norm_cast]
lemma uniform_space.completion.coe_zero [has_zero α] : ((0 : α) : completion α) = 0 := rfl
end group
namespace uniform_space.completion
open uniform_space
section has_zero
instance [uniform_space α] [monoid_with_zero M] [has_zero α] [mul_action_with_zero M α]
[has_uniform_continuous_const_smul M α] :
mul_action_with_zero M (completion α) :=
{ smul := (•),
smul_zero := λ r, by rw [← coe_zero, ← coe_smul, mul_action_with_zero.smul_zero r],
zero_smul := ext' (continuous_const_smul _) continuous_const $ λ a,
by rw [← coe_smul, zero_smul, coe_zero],
.. completion.mul_action M α }
end has_zero
section uniform_add_group
variables [uniform_space α] [add_group α] [uniform_add_group α]
@[norm_cast]
lemma coe_neg (a : α) : ((- a : α) : completion α) = - a :=
(map_coe uniform_continuous_neg a).symm
@[norm_cast]
lemma coe_sub (a b : α) : ((a - b : α) : completion α) = a - b :=
(map₂_coe_coe a b has_sub.sub uniform_continuous_sub).symm
@[norm_cast]
lemma coe_add (a b : α) : ((a + b : α) : completion α) = a + b :=
(map₂_coe_coe a b (+) uniform_continuous_add).symm
instance : add_monoid (completion α) :=
{ zero_add := assume a, completion.induction_on a
(is_closed_eq (continuous_map₂ continuous_const continuous_id) continuous_id)
(assume a, show 0 + (a : completion α) = a, by rw_mod_cast zero_add),
add_zero := assume a, completion.induction_on a
(is_closed_eq (continuous_map₂ continuous_id continuous_const) continuous_id)
(assume a, show (a : completion α) + 0 = a, by rw_mod_cast add_zero),
add_assoc := assume a b c, completion.induction_on₃ a b c
(is_closed_eq
(continuous_map₂
(continuous_map₂ continuous_fst (continuous_fst.comp continuous_snd))
(continuous_snd.comp continuous_snd))
(continuous_map₂ continuous_fst
(continuous_map₂
(continuous_fst.comp continuous_snd)
(continuous_snd.comp continuous_snd))))
(assume a b c, show (a : completion α) + b + c = a + (b + c),
by repeat { rw_mod_cast add_assoc }),
nsmul := (•),
nsmul_zero' := λ a, completion.induction_on a (is_closed_eq continuous_map continuous_const)
(λ a, by rw [←coe_smul, ←coe_zero, zero_smul]),
nsmul_succ' := λ n a, completion.induction_on a
(is_closed_eq continuous_map $ continuous_map₂ continuous_id continuous_map)
(λ a, by rw_mod_cast succ_nsmul ),
.. completion.has_zero, ..completion.has_add, }
instance : sub_neg_monoid (completion α) :=
{ sub_eq_add_neg := λ a b, completion.induction_on₂ a b
(is_closed_eq (continuous_map₂ continuous_fst continuous_snd)
(continuous_map₂ continuous_fst (completion.continuous_map.comp continuous_snd)))
(λ a b, by exact_mod_cast congr_arg coe (sub_eq_add_neg a b)),
zsmul := (•),
zsmul_zero' := λ a, completion.induction_on a (is_closed_eq continuous_map continuous_const)
(λ a, by { rw_mod_cast zero_smul, refl} ),
zsmul_succ' := λ n a, completion.induction_on a
(is_closed_eq continuous_map $ continuous_map₂ continuous_id continuous_map)
(λ a, by rw_mod_cast (show int.of_nat n.succ • a = a + int.of_nat n • a,
from sub_neg_monoid.zsmul_succ' n a) ),
zsmul_neg' := λ n a, completion.induction_on a
(is_closed_eq continuous_map $ completion.continuous_map.comp continuous_map)
(λ a, by rw [←coe_smul, ←coe_smul, ←coe_neg, show -[1+ n] • a = -((n.succ : ℤ) • a),
from sub_neg_monoid.zsmul_neg' n a]),
.. completion.add_monoid, .. completion.has_neg, .. completion.has_sub }
instance : add_group (completion α) :=
{ add_left_neg := assume a, completion.induction_on a
(is_closed_eq (continuous_map₂ completion.continuous_map continuous_id) continuous_const)
(assume a, show - (a : completion α) + a = 0, by { rw_mod_cast add_left_neg, refl }),
.. completion.sub_neg_monoid }
instance : uniform_add_group (completion α) :=
⟨uniform_continuous_map₂ has_sub.sub⟩
instance {M} [monoid M] [distrib_mul_action M α] [has_uniform_continuous_const_smul M α] :
distrib_mul_action M (completion α) :=
{ smul := (•),
smul_add := λ r x y, induction_on₂ x y
(is_closed_eq ((continuous_fst.add continuous_snd).const_smul _)
((continuous_fst.const_smul _).add (continuous_snd.const_smul _)))
(λ a b, by simp only [← coe_add, ← coe_smul, smul_add]),
smul_zero := λ r, by rw [← coe_zero, ← coe_smul, smul_zero r],
.. completion.mul_action M α }
/-- The map from a group to its completion as a group hom. -/
@[simps] def to_compl : α →+ completion α :=
{ to_fun := coe,
map_add' := coe_add,
map_zero' := coe_zero }
lemma continuous_to_compl : continuous (to_compl : α → completion α) :=
continuous_coe α
variable (α)
lemma dense_inducing_to_compl : dense_inducing (to_compl : α → completion α) :=
dense_inducing_coe
variable {α}
end uniform_add_group
section uniform_add_comm_group
variables [uniform_space α] [add_comm_group α] [uniform_add_group α]
instance : add_comm_group (completion α) :=
{ add_comm := assume a b, completion.induction_on₂ a b
(is_closed_eq (continuous_map₂ continuous_fst continuous_snd)
(continuous_map₂ continuous_snd continuous_fst))
(assume x y, by { change ↑x + ↑y = ↑y + ↑x, rw [← coe_add, ← coe_add, add_comm]}),
.. completion.add_group }
instance [semiring R] [module R α] [has_uniform_continuous_const_smul R α] :
module R (completion α) :=
{ smul := (•),
add_smul := λ a b, ext' (continuous_const_smul _)
((continuous_const_smul _).add (continuous_const_smul _)) $ λ x, by { norm_cast, rw add_smul },
.. completion.distrib_mul_action, .. completion.mul_action_with_zero }
end uniform_add_comm_group
end uniform_space.completion
section add_monoid_hom
variables [uniform_space α] [add_group α] [uniform_add_group α]
[uniform_space β] [add_group β] [uniform_add_group β]
open uniform_space uniform_space.completion
/-- Extension to the completion of a continuous group hom. -/
def add_monoid_hom.extension [complete_space β] [separated_space β] (f : α →+ β)
(hf : continuous f) : completion α →+ β :=
have hf : uniform_continuous f, from uniform_continuous_add_monoid_hom_of_continuous hf,
{ to_fun := completion.extension f,
map_zero' := by rw [← coe_zero, extension_coe hf, f.map_zero],
map_add' := assume a b, completion.induction_on₂ a b
(is_closed_eq
(continuous_extension.comp continuous_add)
((continuous_extension.comp continuous_fst).add (continuous_extension.comp continuous_snd)))
(λ a b, by rw_mod_cast [extension_coe hf, extension_coe hf, extension_coe hf,
f.map_add]) }
lemma add_monoid_hom.extension_coe [complete_space β] [separated_space β] (f : α →+ β)
(hf : continuous f) (a : α) : f.extension hf a = f a :=
extension_coe (uniform_continuous_add_monoid_hom_of_continuous hf) a
@[continuity]
lemma add_monoid_hom.continuous_extension [complete_space β] [separated_space β] (f : α →+ β)
(hf : continuous f) : continuous (f.extension hf) :=
continuous_extension
/-- Completion of a continuous group hom, as a group hom. -/
def add_monoid_hom.completion (f : α →+ β) (hf : continuous f) : completion α →+ completion β :=
(to_compl.comp f).extension (continuous_to_compl.comp hf)
@[continuity]
lemma add_monoid_hom.continuous_completion (f : α →+ β)
(hf : continuous f) : continuous (f.completion hf : completion α → completion β) :=
continuous_map
lemma add_monoid_hom.completion_coe (f : α →+ β)
(hf : continuous f) (a : α) : f.completion hf a = f a :=
map_coe (uniform_continuous_add_monoid_hom_of_continuous hf) a
lemma add_monoid_hom.completion_zero : (0 : α →+ β).completion continuous_const = 0 :=
begin
ext x,
apply completion.induction_on x,
{ apply is_closed_eq ((0 : α →+ β).continuous_completion continuous_const),
simp [continuous_const] },
{ intro a,
simp [(0 : α →+ β).completion_coe continuous_const, coe_zero] }
end
lemma add_monoid_hom.completion_add {γ : Type*} [add_comm_group γ] [uniform_space γ]
[uniform_add_group γ] (f g : α →+ γ) (hf : continuous f) (hg : continuous g) :
(f + g).completion (hf.add hg) = f.completion hf + g.completion hg :=
begin
have hfg := hf.add hg,
ext x,
apply completion.induction_on x,
{ exact is_closed_eq ((f+g).continuous_completion hfg)
((f.continuous_completion hf).add (g.continuous_completion hg)) },
{ intro a,
simp [(f+g).completion_coe hfg, coe_add, f.completion_coe hf, g.completion_coe hg] }
end
end add_monoid_hom
|
261d04955f20256249e980ec2305db4be529005a | 4fa161becb8ce7378a709f5992a594764699e268 | /src/tactic/linarith.lean | c4731013b099bb0c80507480a9b0c6fe35a23622 | [
"Apache-2.0"
] | permissive | laughinggas/mathlib | e4aa4565ae34e46e834434284cb26bd9d67bc373 | 86dcd5cda7a5017c8b3c8876c89a510a19d49aad | refs/heads/master | 1,669,496,232,688 | 1,592,831,995,000 | 1,592,831,995,000 | 274,155,979 | 0 | 0 | Apache-2.0 | 1,592,835,190,000 | 1,592,835,189,000 | null | UTF-8 | Lean | false | false | 50,929 | lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Robert Y. Lewis
-/
import tactic.ring
import data.tree
/-!
# `linarith`
A tactic for discharging linear arithmetic goals using Fourier-Motzkin elimination.
`linarith` is (in principle) complete for ℚ and ℝ. It is not complete for non-dense orders, i.e. ℤ.
- @TODO: investigate storing comparisons in a list instead of a set, for possible efficiency gains
- @TODO: delay proofs of denominator normalization and nat casting until after contradiction is
found
-/
meta def nat.to_pexpr : ℕ → pexpr
| 0 := ``(0)
| 1 := ``(1)
| n := if n % 2 = 0 then ``(bit0 %%(nat.to_pexpr (n/2))) else ``(bit1 %%(nat.to_pexpr (n/2)))
open native
namespace linarith
section lemmas
lemma int.coe_nat_bit0 (n : ℕ) : (↑(bit0 n : ℕ) : ℤ) = bit0 (↑n : ℤ) := by simp [bit0]
lemma int.coe_nat_bit1 (n : ℕ) : (↑(bit1 n : ℕ) : ℤ) = bit1 (↑n : ℤ) := by simp [bit1, bit0]
lemma int.coe_nat_bit0_mul (n : ℕ) (x : ℕ) : (↑(bit0 n * x) : ℤ) = (↑(bit0 n) : ℤ) * (↑x : ℤ) := by simp
lemma int.coe_nat_bit1_mul (n : ℕ) (x : ℕ) : (↑(bit1 n * x) : ℤ) = (↑(bit1 n) : ℤ) * (↑x : ℤ) := by simp
lemma int.coe_nat_one_mul (x : ℕ) : (↑(1 * x) : ℤ) = 1 * (↑x : ℤ) := by simp
lemma int.coe_nat_zero_mul (x : ℕ) : (↑(0 * x) : ℤ) = 0 * (↑x : ℤ) := by simp
lemma int.coe_nat_mul_bit0 (n : ℕ) (x : ℕ) : (↑(x * bit0 n) : ℤ) = (↑x : ℤ) * (↑(bit0 n) : ℤ) := by simp
lemma int.coe_nat_mul_bit1 (n : ℕ) (x : ℕ) : (↑(x * bit1 n) : ℤ) = (↑x : ℤ) * (↑(bit1 n) : ℤ) := by simp
lemma int.coe_nat_mul_one (x : ℕ) : (↑(x * 1) : ℤ) = (↑x : ℤ) * 1 := by simp
lemma int.coe_nat_mul_zero (x : ℕ) : (↑(x * 0) : ℤ) = (↑x : ℤ) * 0 := by simp
lemma nat_eq_subst {n1 n2 : ℕ} {z1 z2 : ℤ} (hn : n1 = n2) (h1 : ↑n1 = z1) (h2 : ↑n2 = z2) : z1 = z2 :=
by simpa [eq.symm h1, eq.symm h2, int.coe_nat_eq_coe_nat_iff]
lemma nat_le_subst {n1 n2 : ℕ} {z1 z2 : ℤ} (hn : n1 ≤ n2) (h1 : ↑n1 = z1) (h2 : ↑n2 = z2) : z1 ≤ z2 :=
by simpa [eq.symm h1, eq.symm h2, int.coe_nat_le]
lemma nat_lt_subst {n1 n2 : ℕ} {z1 z2 : ℤ} (hn : n1 < n2) (h1 : ↑n1 = z1) (h2 : ↑n2 = z2) : z1 < z2 :=
by simpa [eq.symm h1, eq.symm h2, int.coe_nat_lt]
lemma eq_of_eq_of_eq {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b = 0) : a + b = 0 :=
by simp *
lemma le_of_eq_of_le {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b ≤ 0) : a + b ≤ 0 :=
by simp *
lemma lt_of_eq_of_lt {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b < 0) : a + b < 0 :=
by simp *
lemma le_of_le_of_eq {α} [ordered_semiring α] {a b : α} (ha : a ≤ 0) (hb : b = 0) : a + b ≤ 0 :=
by simp *
lemma lt_of_lt_of_eq {α} [ordered_semiring α] {a b : α} (ha : a < 0) (hb : b = 0) : a + b < 0 :=
by simp *
lemma mul_neg {α} [ordered_ring α] {a b : α} (ha : a < 0) (hb : b > 0) : b * a < 0 :=
have (-b)*a > 0, from mul_pos_of_neg_of_neg (neg_neg_of_pos hb) ha,
neg_of_neg_pos (by simpa)
lemma mul_nonpos {α} [ordered_ring α] {a b : α} (ha : a ≤ 0) (hb : b > 0) : b * a ≤ 0 :=
have (-b)*a ≥ 0, from mul_nonneg_of_nonpos_of_nonpos (le_of_lt (neg_neg_of_pos hb)) ha,
(by simpa)
lemma mul_eq {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b > 0) : b * a = 0 :=
by simp *
lemma eq_of_not_lt_of_not_gt {α} [linear_order α] (a b : α) (h1 : ¬ a < b) (h2 : ¬ b < a) : a = b :=
le_antisymm (le_of_not_gt h2) (le_of_not_gt h1)
lemma add_subst {α} [ring α] {n e1 e2 t1 t2 : α} (h1 : n * e1 = t1) (h2 : n * e2 = t2) :
n * (e1 + e2) = t1 + t2 := by simp [left_distrib, *]
lemma sub_subst {α} [ring α] {n e1 e2 t1 t2 : α} (h1 : n * e1 = t1) (h2 : n * e2 = t2) :
n * (e1 - e2) = t1 - t2 := by simp [left_distrib, *, sub_eq_add_neg]
lemma neg_subst {α} [ring α] {n e t : α} (h1 : n * e = t) : n * (-e) = -t := by simp *
private meta def apnn : tactic unit := `[norm_num]
lemma mul_subst {α} [comm_ring α] {n1 n2 k e1 e2 t1 t2 : α} (h1 : n1 * e1 = t1) (h2 : n2 * e2 = t2)
(h3 : n1*n2 = k . apnn) : k * (e1 * e2) = t1 * t2 :=
have h3 : n1 * n2 = k, from h3,
by rw [←h3, mul_comm n1, mul_assoc n2, ←mul_assoc n1, h1, ←mul_assoc n2, mul_comm n2, mul_assoc, h2] -- OUCH
lemma div_subst {α} [field α] {n1 n2 k e1 e2 t1 : α} (h1 : n1 * e1 = t1) (h2 : n2 / e2 = 1) (h3 : n1*n2 = k) :
k * (e1 / e2) = t1 :=
by rw [←h3, mul_assoc, mul_div_comm, h2, ←mul_assoc, h1, mul_comm, one_mul]
end lemmas
/--
A linear expression is a list of pairs of variable indices and coefficients.
Some functions on `linexp` assume that `n : ℕ` occurs at most once as the first element of a pair,
and that the list is sorted in decreasing order of the first argument.
This is not enforced by the type but the operations here preserve it.
-/
@[reducible]
def linexp : Type := list (ℕ × ℤ)
end linarith
/--
A map `ℕ → ℤ` is converted to `list (ℕ × ℤ)` in the obvious way.
This list is sorted in decreasing order of the first argument.
-/
meta def native.rb_map.to_linexp (m : rb_map ℕ ℤ) : linarith.linexp :=
m.to_list
namespace linarith
namespace linexp
/--
Add two `linexp`s together componentwise.
Preserves sorting and uniqueness of the first argument.
-/
meta def add : linexp → linexp → linexp
| [] a := a
| a [] := a
| (a@(n1,z1)::t1) (b@(n2,z2)::t2) :=
if n1 < n2 then b::add (a::t1) t2
else if n2 < n1 then a::add t1 (b::t2)
else let sum := z1 + z2 in if sum = 0 then add t1 t2 else (n1, sum)::add t1 t2
/-- `l.scale c` scales the values in `l` by `c` without modifying the order or keys. -/
def scale (c : ℤ) (l : linexp) : linexp :=
if c = 0 then []
else if c = 1 then l
else l.map $ λ ⟨n, z⟩, (n, z*c)
/--
`l.get n` returns the value in `l` associated with key `n`, if it exists, and `none` otherwise.
This function assumes that `l` is sorted in decreasing order of the first argument,
that is, it will return `none` as soon as it finds a key smaller than `n`.
-/
def get (n : ℕ) : linexp → option ℤ
| [] := none
| ((a, b)::t) :=
if a < n then none
else if a = n then some b
else get t
/--
`l.contains n` is true iff `n` is the first element of a pair in `l`.
-/
def contains (n : ℕ) : linexp → bool := option.is_some ∘ get n
/--
`l.zfind n` returns the value associated with key `n` if there is one, and 0 otherwise.
-/
def zfind (n : ℕ) (l : linexp) : ℤ :=
match l.get n with
| none := 0
| some v := v
end
/--
Defines a lex ordering on `linexp`. This function is performance critical.
-/
def cmp : linexp → linexp → ordering
| [] [] := ordering.eq
| [] _ := ordering.lt
| _ [] := ordering.gt
| ((n1,z1)::t1) ((n2,z2)::t2) :=
if n1 < n2 then ordering.lt
else if n2 < n1 then ordering.gt
else if z1 < z2 then ordering.lt
else if z2 < z1 then ordering.gt
else cmp t1 t2
/-- `l.vars` returns the list of variables that occur in `l`. -/
def vars (l : linexp) : list ℕ :=
l.map prod.fst
end linexp
section datatypes
@[derive decidable_eq, derive inhabited]
inductive ineq
| eq | le | lt
open ineq
def ineq.max : ineq → ineq → ineq
| eq a := a
| le a := a
| lt a := lt
/-- `ineq` is ordered `eq < le < lt`. -/
def ineq.cmp : ineq → ineq → ordering
| eq eq := ordering.eq
| eq _ := ordering.lt
| le le := ordering.eq
| le lt := ordering.lt
| lt lt := ordering.eq
| _ _ := ordering.gt
def ineq.to_string : ineq → string
| eq := "="
| le := "≤"
| lt := "<"
instance : has_to_string ineq := ⟨ineq.to_string⟩
/--
The main datatype for FM elimination.
Variables are represented by natural numbers, each of which has an integer coefficient.
Index 0 is reserved for constants, i.e. `coeffs.find 0` is the coefficient of 1.
The represented term is `coeffs.sum (λ ⟨k, v⟩, v * Var[k])`.
str determines the direction of the comparison -- is it < 0, ≤ 0, or = 0?
-/
@[derive inhabited]
structure comp : Type :=
(str : ineq)
(coeffs : linexp)
/-- `c.vars` returns the list of variables that appear in the linear expression contained in `c`. -/
def comp.vars : comp → list ℕ :=
linexp.vars ∘ comp.coeffs
@[derive inhabited]
inductive comp_source : Type
| assump : ℕ → comp_source
| add : comp_source → comp_source → comp_source
| scale : ℕ → comp_source → comp_source
meta def comp_source.flatten : comp_source → rb_map ℕ ℕ
| (comp_source.assump n) := mk_rb_map.insert n 1
| (comp_source.add c1 c2) := (comp_source.flatten c1).add (comp_source.flatten c2)
| (comp_source.scale n c) := (comp_source.flatten c).map (λ v, v * n)
def comp_source.to_string : comp_source → string
| (comp_source.assump e) := to_string e
| (comp_source.add c1 c2) := comp_source.to_string c1 ++ " + " ++ comp_source.to_string c2
| (comp_source.scale n c) := to_string n ++ " * " ++ comp_source.to_string c
meta instance comp_source.has_to_format : has_to_format comp_source :=
⟨λ a, comp_source.to_string a⟩
/--
A `pcomp` stores a linear comparison `Σ cᵢ*xᵢ R 0`,
along with information about how this comparison was derived.
The original expressions fed into `linarith` are each assigned a unique natural number label.
The *historical set* `pcomp.history` stores the labels of expressions
that were used in deriving the current `pcomp`.
Variables are also indexed by natural numbers. The sets `pcomp.effective`, `pcomp.implicit`,
and `pcomp.vars` contain variable indices.
* `pcomp.vars` contains the variables that appear in `pcomp.c`. We store them in `pcomp` to
avoid recomputing the set, which requires folding over a list. (TODO: is this really needed?)
* `pcomp.effective` contains the variables that have been effectively eliminated from `pcomp`.
A variable `n` is said to be *effectively eliminated* in `pcomp` if the elimination of `n`
produced at least one of the ancestors of `pcomp`.
* `pcomp.implicit` contains the variables that have been implicitly eliminated from `pcomp`.
A variable `n` is said to be *implicitly eliminated* in `pcomp` if it satisfies the following
properties:
- There is some `ancestor` of `pcomp` such that `n` appears in `ancestor.vars`.
- `n` does not appear in `pcomp.vars`.
- `n` was not effectively eliminated.
We track these sets in order to compute whether the history of a `pcomp` is *minimal*.
Checking this directly is expensive, but effective approximations can be defined in terms of these
sets. During the variable elimination process, a `pcomp` with non-minimal history can be discarded.
-/
meta structure pcomp : Type :=
(c : comp)
(src : comp_source)
(history : rb_set ℕ)
(effective : rb_set ℕ)
(implicit : rb_set ℕ)
(vars : rb_set ℕ)
/--
Any comparison whose history is not minimal is redundant,
and need not be included in the new set of comparisons.
`elimed_ge : ℕ` is a natural number such that all variables with index ≥ `elimed_ge` have been
removed from the system.
This test is an overapproximation to minimality. It gives necessary but not sufficient conditions.
If the history of `c` is minimal, then `c.maybe_minimal` is true,
but `c.maybe_minimal` may also be true for some `c` with minimal history.
Thus, if `c.maybe_minimal` is false, `c` is known not to be minimal and must be redundant.
See http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.51.493&rep=rep1&type=pdf p.13
(Theorem 7).
The condition described there considers only implicitly eliminated variables that have been
officially eliminated from the system. This is not the case for every implicitly eliminated variable.
Consider eliminating `z` from `{x + y + z < 0, x - y - z < 0}`. The result is the set
`{2*x < 0}`; `y` is implicitly but not officially eliminated.
This implementation of Fourier-Motzkin elimination processes variables in decreasing order of
indices. Immediately after a step that eliminates variable `k`, variable `k'` has been eliminated
iff `k' ≥ k`. Thus we can compute the intersection of officially and implicitly eliminated variables
by taking the set of implicitly eliminated variables with indices ≥ `elimed_ge`.
-/
meta def pcomp.maybe_minimal (c : pcomp) (elimed_ge : ℕ) : bool :=
c.history.size ≤ 1 + ((c.implicit.filter (≥ elimed_ge)).union c.effective).size
/-- `comp` has a lex order. First the `ineq`s are compared, then the `coeff`s. -/
meta def comp.cmp : comp → comp → ordering
| ⟨str1, coeffs1⟩ ⟨str2, coeffs2⟩ :=
match str1.cmp str2 with
| ordering.lt := ordering.lt
| ordering.gt := ordering.gt
| ordering.eq := coeffs1.cmp coeffs2
end
/--
The `comp_source` field is ignored when comparing `pcomp`s. Two `pcomp`s proving the same
comparison, with different sources, are considered equivalent.
-/
meta def pcomp.cmp (p1 p2 : pcomp) : ordering :=
p1.c.cmp p2.c
meta def comp.coeff_of (c : comp) (a : ℕ) : ℤ :=
c.coeffs.zfind a
meta def comp.scale (c : comp) (n : ℕ) : comp :=
{ c with coeffs := c.coeffs.scale n }
meta def comp.add (c1 c2 : comp) : comp :=
⟨c1.str.max c2.str, c1.coeffs.add c2.coeffs⟩
meta def pcomp.scale (c : pcomp) (n : ℕ) : pcomp :=
{c with c := c.c.scale n, src := c.src.scale n}
/--
`pcomp.add c1 c2 elim_var` creates the result of summing the linear comparisons `c1` and `c2`,
during the process of eliminating the variable `elim_var`.
The computation assumes, but does not enforce, that `elim_var` appears in both `c1` and `c2`
and does not appear in the sum.
Computing the sum of the two comparisons is easy; the complicated details lie in tracking the
additional fields of `pcomp`.
* The historical set `pcomp.history` of `c1 + c2` is the union of the two historical sets.
* We recompute the variables that appear in `c1 + c2` from the newly created `linexp`,
since some may have been implicitly eliminated.
* The effectively eliminated variables of `c1 + c2` are the union of the two effective sets,
with `elim_var` inserted.
* The implicitly eliminated variables of `c1 + c2` are those that appear in at least one of
`c1.vars` and `c2.vars` but not in `(c1 + c2).vars`, excluding `elim_var`.
-/
meta def pcomp.add (c1 c2 : pcomp) (elim_var : ℕ) : pcomp :=
let c := c1.c.add c2.c,
src := c1.src.add c2.src,
history := c1.history.union c2.history,
vars := native.rb_set.of_list c.vars,
effective := (c1.effective.union c2.effective).insert elim_var,
implicit := ((c1.vars.union c2.vars).sdiff vars).erase elim_var in
⟨c, src, history, effective, implicit, vars⟩
/--
`pcomp.assump c n` creates a `pcomp` whose comparison is `c` and whose source is
`comp_source.assump n`, that is, `c` is derived from the `n`th hypothesis.
The history is the singleton set `{n}`.
No variables have been eliminated (effectively or implicitly).
-/
meta def pcomp.assump (c : comp) (n : ℕ) : pcomp :=
{ c := c,
src := comp_source.assump n,
history := mk_rb_set.insert n,
effective := mk_rb_set,
implicit := mk_rb_set,
vars := rb_set.of_list c.vars }
meta instance pcomp.to_format : has_to_format pcomp :=
⟨λ p, to_fmt p.c.coeffs ++ to_string p.c.str ++ "0"⟩
meta instance comp.to_format : has_to_format comp :=
⟨λ p, to_fmt p.coeffs ++ to_string p.str ++ "0"⟩
/-- Creates an empty set of `pcomp`s, sorted using `pcomp.cmp`. -/
meta def mk_pcomp_set : rb_set pcomp :=
rb_map.mk_core unit pcomp.cmp
end datatypes
section fm_elim
/-- If `c1` and `c2` both contain variable `a` with opposite coefficients,
produces `v1`, `v2` such that `a` has been cancelled in `v1*c1 + v2*c2`. -/
meta def elim_var (c1 c2 : comp) (a : ℕ) : option (ℕ × ℕ) :=
let v1 := c1.coeff_of a,
v2 := c2.coeff_of a in
if v1 * v2 < 0 then
let vlcm := nat.lcm v1.nat_abs v2.nat_abs,
v1' := vlcm / v1.nat_abs,
v2' := vlcm / v2.nat_abs in
some ⟨v1', v2'⟩
else none
meta def pelim_var (p1 p2 : pcomp) (a : ℕ) : option pcomp :=
do (n1, n2) ← elim_var p1.c p2.c a,
return $ (p1.scale n1).add (p2.scale n2) a
meta def comp.is_contr (c : comp) : bool := c.coeffs.empty ∧ c.str = ineq.lt
meta def pcomp.is_contr (p : pcomp) : bool := p.c.is_contr
meta def elim_with_set (a : ℕ) (p : pcomp) (comps : rb_set pcomp) : rb_set pcomp :=
comps.fold mk_pcomp_set $ λ pc s,
match pelim_var p pc a with
| some pc := if pc.maybe_minimal a then s.insert pc else s
| none := s
end
/--
The state for the elimination monad.
* `vars`: the set of variables present in `comps`
* `comps`: a set of comparisons
-/
meta structure linarith_structure :=
(vars : rb_set ℕ)
(comps : rb_set pcomp)
@[reducible, derive [monad, monad_except pcomp]] meta def linarith_monad :=
state_t linarith_structure (except_t pcomp id)
meta def get_vars : linarith_monad (rb_set ℕ) :=
linarith_structure.vars <$> get
meta def get_var_list : linarith_monad (list ℕ) :=
rb_set.to_list <$> get_vars
meta def get_comps : linarith_monad (rb_set pcomp) :=
linarith_structure.comps <$> get
meta def validate : linarith_monad unit :=
do ⟨_, comps⟩ ← get,
match comps.to_list.find (λ p : pcomp, p.is_contr) with
| none := return ()
| some c := throw c
end
meta def update (vars : rb_set ℕ) (comps : rb_set pcomp) : linarith_monad unit :=
state_t.put ⟨vars, comps⟩ >> validate
/--
`split_set_by_var_sign a comps` partitions the set `comps` into three parts.
* `pos` contains the elements of `comps` in which `a` has a positive coefficient.
* `neg` contains the elements of `comps` in which `a` has a negative coefficient.
* `not_present` contains the elements of `comps` in which `a` has coefficient 0.
Returns `(pos, neg, not_present)`.
-/
meta def split_set_by_var_sign (a : ℕ) (comps : rb_set pcomp) :
rb_set pcomp × rb_set pcomp × rb_set pcomp :=
comps.fold ⟨mk_pcomp_set, mk_pcomp_set, mk_pcomp_set⟩ $ λ pc ⟨pos, neg, not_present⟩,
let n := pc.c.coeff_of a in
if n > 0 then ⟨pos.insert pc, neg, not_present⟩
else if n < 0 then ⟨pos, neg.insert pc, not_present⟩
else ⟨pos, neg, not_present.insert pc⟩
/--
`monad.elim_var a` performs one round of Fourier-Motzkin elimination, eliminating the variable `a`
from the `linarith` state.
-/
meta def monad.elim_var (a : ℕ) : linarith_monad unit :=
do vs ← get_vars,
when (vs.contains a) $
do ⟨pos, neg, not_present⟩ ← split_set_by_var_sign a <$> get_comps,
let cs' := pos.fold not_present (λ p s, s.union (elim_with_set a p neg)),
update (vs.erase a) cs'
meta def elim_all_vars : linarith_monad unit :=
get_var_list >>= list.mmap' monad.elim_var
end fm_elim
/-!
`linarith` computes the linear form of its input expressions,
assuming (without justification) that the type of these expressions
is a commutative semiring.
It identifies atoms up to ring-equivalence: that is, `(y*3)*x` will be identified `3*(x*y)`,
where the monomial `x*y` is the linear atom.
* Variables are represented by natural numbers.
* Monomials are represented by `monom := rb_map ℕ ℕ`. The monomial `1` is represented by the empty map.
* Linear combinations of monomials are represented by `sum := rb_map monom ℤ`.
All input expressions are converted to `sum`s, preserving the map from expressions to variables.
We then discard the monomial information, mapping each distinct monomial to a natural number.
The resulting `rb_map ℕ ℤ` represents the ring-normalized linear form of the expression.
-/
/-- Variables (represented by natural numbers) map to their power. -/
@[reducible] meta def monom : Type := rb_map ℕ ℕ
/-- Compare monomials by first comparing their keys and then their powers. -/
@[reducible] meta def monom.lt : monom → monom → Prop :=
λ a b, (a.keys < b.keys) || ((a.keys = b.keys) && (a.values < b.values))
/-- The `has_lt` instance for `monom` is only needed locally. -/
local attribute [instance]
meta def monom_has_lt : has_lt monom := ⟨monom.lt⟩
/-- Linear combinations of monomials are represented by mapping monomials to coefficients. -/
@[reducible] meta def sum : Type := rb_map monom ℤ
/-- `sum.scale_by_monom s m` multiplies every monomial in `s` by `m`. -/
meta def sum.scale_by_monom (s : sum) (m : monom) : sum :=
s.fold mk_rb_map $ λ m' coeff sm, sm.insert (m.add m') coeff
/-- `sum.mul s1 s2` distributes the multiplication of two sums.` -/
meta def sum.mul (s1 s2 : sum) : sum :=
s1.fold mk_rb_map $ λ mn coeff sm, sm.add $ (s2.scale_by_monom mn).scale coeff
/-- `sum_of_monom m` lifts `m` to a sum with coefficient `1`. -/
meta def sum_of_monom (m : monom) : sum :=
mk_rb_map.insert m 1
/-- The unit monomial `one` is represented by the empty rb map. -/
meta def one : monom := mk_rb_map
/-- A scalar `z` is represented by a `sum` with coefficient `z` and monomial `one` -/
meta def scalar (z : ℤ) : sum :=
mk_rb_map.insert one z
/-- A single variable `n` is represented by a sum with coefficient `1` and monomial `n`. -/
meta def var (n : ℕ) : sum :=
mk_rb_map.insert (mk_rb_map.insert n 1) 1
section parse
open ineq tactic
meta def map_of_expr_mul_aux (c1 c2 : rb_map ℕ ℤ) : option (rb_map ℕ ℤ) :=
match c1.keys, c2.keys with
| [0], _ := some $ c2.scale (c1.zfind 0)
| _, [0] := some $ c1.scale (c2.zfind 0)
| [], _ := some mk_rb_map
| _, [] := some mk_rb_map
| _, _ := none
end
meta def list.mfind {α} (tac : α → tactic unit) : list α → tactic α
| [] := failed
| (h::t) := tac h >> return h <|> list.mfind t
meta def rb_map.find_defeq (red : transparency) {v} (m : expr_map v) (e : expr) : tactic v :=
prod.snd <$> list.mfind (λ p, is_def_eq e p.1 red) m.to_list
/--
`map_of_expr red map e` computes the linear form of `e`.
`map` is a lookup map from atomic expressions to variable numbers.
If a new atomic expression is encountered, it is added to the map with a new number.
-/
meta def map_of_expr (red : transparency) : expr_map ℕ → expr → tactic (expr_map ℕ × sum)
| m e@`(%%e1 * %%e2) :=
do (m', comp1) ← map_of_expr m e1,
(m', comp2) ← map_of_expr m' e2,
return (m', comp1.mul comp2)
| m `(%%e1 + %%e2) :=
do (m', comp1) ← map_of_expr m e1,
(m', comp2) ← map_of_expr m' e2,
return (m', comp1.add comp2)
| m `(%%e1 - %%e2) :=
do (m', comp1) ← map_of_expr m e1,
(m', comp2) ← map_of_expr m' e2,
return (m', comp1.add (comp2.scale (-1)))
| m `(-%%e) := do (m', comp) ← map_of_expr m e, return (m', comp.scale (-1))
| m e :=
match e.to_int with
| some 0 := return ⟨m, mk_rb_map⟩
| some z := return ⟨m, scalar z⟩
| none :=
(do k ← rb_map.find_defeq red m e, return (m, var k)) <|>
(let n := m.size + 1 in return (m.insert e n, var n))
end
/--
`sum_to_lf s map` eliminates the monomial level of the `sum` `s`.
`map` is a lookup map from monomials to variable numbers.
The output `rb_map ℕ ℤ` has the same structure as `sum`,
but each monomial key is replaced with its index according to `map`.
If any new monomials are encountered, they are assigned variable numbers and `map` is updated.
-/
meta def sum_to_lf (s : sum) (m : rb_map monom ℕ) : rb_map monom ℕ × rb_map ℕ ℤ :=
s.fold (m, mk_rb_map) $ λ mn coeff ⟨map, out⟩,
match map.find mn with
| some n := ⟨map, out.insert n coeff⟩
| none := let n := map.size in ⟨map.insert mn n, out.insert n coeff⟩
end
meta def parse_into_comp_and_expr : expr → option (ineq × expr)
| `(%%e < 0) := (ineq.lt, e)
| `(%%e ≤ 0) := (ineq.le, e)
| `(%%e = 0) := (ineq.eq, e)
| _ := none
meta def to_comp (red : transparency) (e : expr) (m : expr_map ℕ) (mm : rb_map monom ℕ) :
tactic (comp × expr_map ℕ × rb_map monom ℕ) :=
do (iq, e) ← parse_into_comp_and_expr e,
(m', comp') ← map_of_expr red m e,
let ⟨nm, mm'⟩ := sum_to_lf comp' mm,
return ⟨⟨iq, mm'.to_linexp⟩,m',nm⟩
meta def to_comp_fold (red : transparency) : expr_map ℕ → list expr → rb_map monom ℕ →
tactic (list (option comp) × expr_map ℕ × rb_map monom ℕ )
| m [] mm := return ([], m, mm)
| m (h::t) mm :=
(do (c, m', mm') ← to_comp red h m mm,
(l, mp, mm') ← to_comp_fold m' t mm',
return (c::l, mp, mm')) <|>
(do (l, mp, mm') ← to_comp_fold m t mm,
return (none::l, mp, mm'))
/--
Takes a list of proofs of props of the form `t {<, ≤, =} 0`, and creates a
`linarith_structure`.
-/
meta def mk_linarith_structure (red : transparency) (l : list expr) :
tactic (linarith_structure × rb_map ℕ (expr × expr)) :=
do pftps ← l.mmap infer_type,
(l', _, map) ← to_comp_fold red mk_rb_map pftps mk_rb_map,
let lz := list.enum $ ((l.zip pftps).zip l').filter_map (λ ⟨a, b⟩, prod.mk a <$> b),
let prmap := rb_map.of_list $ lz.map (λ ⟨n, x⟩, (n, x.1)),
let vars : rb_set ℕ := rb_map.set_of_list $ list.range map.size,
let pc : rb_set pcomp :=
rb_set.of_list_core mk_pcomp_set $ lz.map (λ ⟨n, x⟩, pcomp.assump x.2 n),
return ({vars := vars, comps := pc}, prmap)
meta def linarith_monad.run (red : transparency) {α} (tac : linarith_monad α) (l : list expr) :
tactic ((pcomp ⊕ α) × rb_map ℕ (expr × expr)) :=
do (struct, inputs) ← mk_linarith_structure red l,
match (state_t.run (validate >> tac) struct).run with
| (except.ok (a, _)) := return (sum.inr a, inputs)
| (except.error contr) := return (sum.inl contr, inputs)
end
end parse
section prove
open ineq tactic
meta def get_rel_sides : expr → tactic (expr × expr)
| `(%%a < %%b) := return (a, b)
| `(%%a ≤ %%b) := return (a, b)
| `(%%a = %%b) := return (a, b)
| `(%%a ≥ %%b) := return (a, b)
| `(%%a > %%b) := return (a, b)
| _ := failed
meta def mul_expr (n : ℕ) (e : expr) : pexpr :=
if n = 1 then ``(%%e) else
``(%%(nat.to_pexpr n) * %%e)
meta def add_exprs_aux : pexpr → list pexpr → pexpr
| p [] := p
| p [a] := ``(%%p + %%a)
| p (h::t) := add_exprs_aux ``(%%p + %%h) t
meta def add_exprs : list pexpr → pexpr
| [] := ``(0)
| (h::t) := add_exprs_aux h t
meta def find_contr (m : rb_set pcomp) : option pcomp :=
m.keys.find (λ p, p.c.is_contr)
meta def ineq_const_mul_nm : ineq → name
| lt := ``mul_neg
| le := ``mul_nonpos
| eq := ``mul_eq
meta def ineq_const_nm : ineq → ineq → (name × ineq)
| eq eq := (``eq_of_eq_of_eq, eq)
| eq le := (``le_of_eq_of_le, le)
| eq lt := (``lt_of_eq_of_lt, lt)
| le eq := (``le_of_le_of_eq, le)
| le le := (`add_nonpos, le)
| le lt := (`add_neg_of_nonpos_of_neg, lt)
| lt eq := (``lt_of_lt_of_eq, lt)
| lt le := (`add_neg_of_neg_of_nonpos, lt)
| lt lt := (`add_neg, lt)
meta def mk_single_comp_zero_pf (c : ℕ) (h : expr) : tactic (ineq × expr) :=
do tp ← infer_type h,
some (iq, e) ← return $ parse_into_comp_and_expr tp,
if c = 0 then
do e' ← mk_app ``zero_mul [e], return (eq, e')
else if c = 1 then return (iq, h)
else
do nm ← resolve_name (ineq_const_mul_nm iq),
tp ← (prod.snd <$> (infer_type h >>= get_rel_sides)) >>= infer_type,
cpos ← to_expr ``((%%c.to_pexpr : %%tp) > 0),
(_, ex) ← solve_aux cpos `[norm_num, done],
-- e' ← mk_app (ineq_const_mul_nm iq) [h, ex], -- this takes many seconds longer in some examples! why?
e' ← to_expr ``(%%nm %%h %%ex) ff,
return (iq, e')
meta def mk_lt_zero_pf_aux (c : ineq) (pf npf : expr) (coeff : ℕ) : tactic (ineq × expr) :=
do (iq, h') ← mk_single_comp_zero_pf coeff npf,
let (nm, niq) := ineq_const_nm c iq,
n ← resolve_name nm,
e' ← to_expr ``(%%n %%pf %%h'),
return (niq, e')
/--
Takes a list of coefficients `[c]` and list of expressions, of equal length.
Each expression is a proof of a prop of the form `t {<, ≤, =} 0`.
Produces a proof that the sum of `(c*t) {<, ≤, =} 0`,
where the `comp` is as strong as possible.
-/
meta def mk_lt_zero_pf : list ℕ → list expr → tactic expr
| _ [] := fail "no linear hypotheses found"
| [c] [h] := prod.snd <$> mk_single_comp_zero_pf c h
| (c::ct) (h::t) :=
do (iq, h') ← mk_single_comp_zero_pf c h,
prod.snd <$> (ct.zip t).mfoldl (λ pr ce, mk_lt_zero_pf_aux pr.1 pr.2 ce.2 ce.1) (iq, h')
| _ _ := fail "not enough args to mk_lt_zero_pf"
meta def term_of_ineq_prf (prf : expr) : tactic expr :=
do (lhs, _) ← infer_type prf >>= get_rel_sides,
return lhs
meta structure linarith_config :=
(discharger : tactic unit := `[ring])
(restrict_type : option Type := none)
(restrict_type_reflect : reflected restrict_type . apply_instance)
(exfalso : bool := tt)
(transparency : transparency := reducible)
(split_hypotheses : bool := tt)
meta def ineq_pf_tp (pf : expr) : tactic expr :=
do (_, z) ← infer_type pf >>= get_rel_sides,
infer_type z
meta def mk_neg_one_lt_zero_pf (tp : expr) : tactic expr :=
to_expr ``((neg_neg_of_pos zero_lt_one : -1 < (0 : %%tp)))
/--
Assumes `e` is a proof that `t = 0`. Creates a proof that `-t = 0`.
-/
meta def mk_neg_eq_zero_pf (e : expr) : tactic expr :=
to_expr ``(neg_eq_zero.mpr %%e)
meta def add_neg_eq_pfs : list expr → tactic (list expr)
| [] := return []
| (h::t) :=
do some (iq, tp) ← parse_into_comp_and_expr <$> infer_type h,
match iq with
| ineq.eq := do nep ← mk_neg_eq_zero_pf h, tl ← add_neg_eq_pfs t, return $ h::nep::tl
| _ := list.cons h <$> add_neg_eq_pfs t
end
/--
Takes a list of proofs of propositions of the form `t {<, ≤, =} 0`,
and tries to prove the goal `false`.
-/
meta def prove_false_by_linarith1 (cfg : linarith_config) : list expr → tactic unit
| [] := fail "no args to linarith"
| l@(h::t) :=
do l' ← add_neg_eq_pfs l,
hz ← ineq_pf_tp h >>= mk_neg_one_lt_zero_pf,
(sum.inl contr, inputs) ← elim_all_vars.run cfg.transparency (hz::l')
| fail "linarith failed to find a contradiction",
let coeffs := inputs.keys.map (λ k, (contr.src.flatten.ifind k)),
let pfs : list expr := inputs.keys.map (λ k, (inputs.ifind k).1),
let zip := (coeffs.zip pfs).filter (λ pr, pr.1 ≠ 0),
let (coeffs, pfs) := zip.unzip,
mls ← zip.mmap (λ pr, do e ← term_of_ineq_prf pr.2, return (mul_expr pr.1 e)),
sm ← to_expr $ add_exprs mls,
tgt ← to_expr ``(%%sm = 0),
(a, b) ← solve_aux tgt (cfg.discharger >> done),
pf ← mk_lt_zero_pf coeffs pfs,
pftp ← infer_type pf,
(_, nep, _) ← rewrite_core b pftp,
pf' ← mk_eq_mp nep pf,
mk_app `lt_irrefl [pf'] >>= exact
end prove
section normalize
open tactic
set_option eqn_compiler.max_steps 50000
meta def rem_neg (prf : expr) : expr → tactic expr
| `(_ ≤ _) := to_expr ``(lt_of_not_ge %%prf)
| `(_ < _) := to_expr ``(le_of_not_gt %%prf)
| `(_ > _) := to_expr ``(le_of_not_gt %%prf)
| `(_ ≥ _) := to_expr ``(lt_of_not_ge %%prf)
| e := failed
meta def rearr_comp : expr → expr → tactic expr
| prf `(%%a ≤ 0) := return prf
| prf `(%%a < 0) := return prf
| prf `(%%a = 0) := return prf
| prf `(%%a ≥ 0) := to_expr ``(neg_nonpos.mpr %%prf)
| prf `(%%a > 0) := to_expr ``(neg_neg_of_pos %%prf)
| prf `(0 ≥ %%a) := to_expr ``(show %%a ≤ 0, from %%prf)
| prf `(0 > %%a) := to_expr ``(show %%a < 0, from %%prf)
| prf `(0 = %%a) := to_expr ``(eq.symm %%prf)
| prf `(0 ≤ %%a) := to_expr ``(neg_nonpos.mpr %%prf)
| prf `(0 < %%a) := to_expr ``(neg_neg_of_pos %%prf)
| prf `(%%a ≤ %%b) := to_expr ``(sub_nonpos.mpr %%prf)
| prf `(%%a < %%b) := to_expr ``(sub_neg_of_lt %%prf)
| prf `(%%a = %%b) := to_expr ``(sub_eq_zero.mpr %%prf)
| prf `(%%a > %%b) := to_expr ``(sub_neg_of_lt %%prf)
| prf `(%%a ≥ %%b) := to_expr ``(sub_nonpos.mpr %%prf)
| prf `(¬ %%t) := do nprf ← rem_neg prf t, tp ← infer_type nprf, rearr_comp nprf tp
| prf _ := fail "couldn't rearrange comp"
meta def is_numeric : expr → option ℚ
| `(%%e1 + %%e2) := (+) <$> is_numeric e1 <*> is_numeric e2
| `(%%e1 - %%e2) := has_sub.sub <$> is_numeric e1 <*> is_numeric e2
| `(%%e1 * %%e2) := (*) <$> is_numeric e1 <*> is_numeric e2
| `(%%e1 / %%e2) := (/) <$> is_numeric e1 <*> is_numeric e2
| `(-%%e) := rat.neg <$> is_numeric e
| e := e.to_rat
meta def find_cancel_factor : expr → ℕ × tree ℕ
| `(%%e1 + %%e2) :=
let (v1, t1) := find_cancel_factor e1, (v2, t2) := find_cancel_factor e2, lcm := v1.lcm v2 in
(lcm, tree.node lcm t1 t2)
| `(%%e1 - %%e2) :=
let (v1, t1) := find_cancel_factor e1, (v2, t2) := find_cancel_factor e2, lcm := v1.lcm v2 in
(lcm, tree.node lcm t1 t2)
| `(%%e1 * %%e2) :=
let (v1, t1) := find_cancel_factor e1, (v2, t2) := find_cancel_factor e2, pd := v1*v2 in
(pd, tree.node pd t1 t2)
| `(%%e1 / %%e2) :=
match is_numeric e2 with
| some q := let (v1, t1) := find_cancel_factor e1, n := v1.lcm q.num.nat_abs in
(n, tree.node n t1 (tree.node q.num.nat_abs tree.nil tree.nil))
| none := (1, tree.node 1 tree.nil tree.nil)
end
| `(-%%e) := find_cancel_factor e
| _ := (1, tree.node 1 tree.nil tree.nil)
open tree
meta def mk_prod_prf : ℕ → tree ℕ → expr → tactic expr
| v (node _ lhs rhs) `(%%e1 + %%e2) :=
do v1 ← mk_prod_prf v lhs e1, v2 ← mk_prod_prf v rhs e2, mk_app ``add_subst [v1, v2]
| v (node _ lhs rhs) `(%%e1 - %%e2) :=
do v1 ← mk_prod_prf v lhs e1, v2 ← mk_prod_prf v rhs e2, mk_app ``sub_subst [v1, v2]
| v (node n lhs@(node ln _ _) rhs) `(%%e1 * %%e2) :=
do tp ← infer_type e1, v1 ← mk_prod_prf ln lhs e1, v2 ← mk_prod_prf (v/ln) rhs e2,
ln' ← tp.of_nat ln, vln' ← tp.of_nat (v/ln), v' ← tp.of_nat v,
ntp ← to_expr ``(%%ln' * %%vln' = %%v'),
(_, npf) ← solve_aux ntp `[norm_num, done],
mk_app ``mul_subst [v1, v2, npf]
| v (node n lhs rhs@(node rn _ _)) `(%%e1 / %%e2) :=
do tp ← infer_type e1, v1 ← mk_prod_prf (v/rn) lhs e1,
rn' ← tp.of_nat rn, vrn' ← tp.of_nat (v/rn), n' ← tp.of_nat n, v' ← tp.of_nat v,
ntp ← to_expr ``(%%rn' / %%e2 = 1),
(_, npf) ← solve_aux ntp `[norm_num, done],
ntp2 ← to_expr ``(%%vrn' * %%n' = %%v'),
(_, npf2) ← solve_aux ntp2 `[norm_num, done],
mk_app ``div_subst [v1, npf, npf2]
| v t `(-%%e) := do v' ← mk_prod_prf v t e, mk_app ``neg_subst [v']
| v _ e :=
do tp ← infer_type e,
v' ← tp.of_nat v,
e' ← to_expr ``(%%v' * %%e),
mk_app `eq.refl [e']
/--
Given `e`, a term with rational division, produces a natural number `n` and a proof of `n*e = e'`,
where `e'` has no division.
-/
meta def kill_factors (e : expr) : tactic (ℕ × expr) :=
let (n, t) := find_cancel_factor e in
do e' ← mk_prod_prf n t e, return (n, e')
open expr
meta def expr_contains (n : name) : expr → bool
| (const nm _) := nm = n
| (lam _ _ _ bd) := expr_contains bd
| (pi _ _ _ bd) := expr_contains bd
| (app e1 e2) := expr_contains e1 || expr_contains e2
| _ := ff
lemma sub_into_lt {α} [ordered_semiring α] {a b : α} (he : a = b) (hl : a ≤ 0) : b ≤ 0 :=
by rwa he at hl
meta def norm_hyp_aux (h' lhs : expr) : tactic expr :=
do (v, lhs') ← kill_factors lhs,
if v = 1 then return h' else do
(ih, h'') ← mk_single_comp_zero_pf v h',
(_, nep, _) ← infer_type h'' >>= rewrite_core lhs',
mk_eq_mp nep h''
meta def norm_hyp (h : expr) : tactic expr :=
do htp ← infer_type h,
h' ← rearr_comp h htp,
some (c, lhs) ← parse_into_comp_and_expr <$> infer_type h',
if expr_contains `has_div.div lhs then
norm_hyp_aux h' lhs
else return h'
meta def get_contr_lemma_name : expr → option name
| `(%%a < %%b) := return `lt_of_not_ge
| `(%%a ≤ %%b) := return `le_of_not_gt
| `(%%a = %%b) := return ``eq_of_not_lt_of_not_gt
| `(%%a ≠ %%b) := return `not.intro
| `(%%a ≥ %%b) := return `le_of_not_gt
| `(%%a > %%b) := return `lt_of_not_ge
| `(¬ %%a < %%b) := return `not.intro
| `(¬ %%a ≤ %%b) := return `not.intro
| `(¬ %%a = %%b) := return `not.intro
| `(¬ %%a ≥ %%b) := return `not.intro
| `(¬ %%a > %%b) := return `not.intro
| _ := none
/-- Assumes the input `t` is of type `ℕ`. Produces `t'` of type `ℤ` such that `↑t = t'` and
a proof of equality. -/
meta def cast_expr (e : expr) : tactic (expr × expr) :=
do s ← [`int.coe_nat_add, `int.coe_nat_zero, `int.coe_nat_one,
``int.coe_nat_bit0_mul, ``int.coe_nat_bit1_mul, ``int.coe_nat_zero_mul, ``int.coe_nat_one_mul,
``int.coe_nat_mul_bit0, ``int.coe_nat_mul_bit1, ``int.coe_nat_mul_zero, ``int.coe_nat_mul_one,
``int.coe_nat_bit0, ``int.coe_nat_bit1].mfoldl simp_lemmas.add_simp simp_lemmas.mk,
ce ← to_expr ``(↑%%e : ℤ),
simplify s [] ce {fail_if_unchanged := ff}
meta def is_nat_int_coe : expr → option expr
| `((↑(%%n : ℕ) : ℤ)) := some n
| _ := none
meta def mk_coe_nat_nonneg_prf (e : expr) : tactic expr :=
mk_app `int.coe_nat_nonneg [e]
meta def get_nat_comps : expr → list expr
| `(%%a + %%b) := (get_nat_comps a).append (get_nat_comps b)
| `(%%a * %%b) := (get_nat_comps a).append (get_nat_comps b)
| e := match is_nat_int_coe e with
| some e' := [e']
| none := []
end
meta def mk_coe_nat_nonneg_prfs (e : expr) : tactic (list expr) :=
(get_nat_comps e).mmap mk_coe_nat_nonneg_prf
meta def mk_cast_eq_and_nonneg_prfs (pf a b : expr) (ln : name) : tactic (list expr) :=
do (a', prfa) ← cast_expr a,
(b', prfb) ← cast_expr b,
la ← mk_coe_nat_nonneg_prfs a',
lb ← mk_coe_nat_nonneg_prfs b',
pf' ← mk_app ln [pf, prfa, prfb],
return $ pf'::(la.append lb)
meta def mk_int_pfs_of_nat_pf (pf : expr) : tactic (list expr) :=
do tp ← infer_type pf,
match tp with
| `(%%a = %%b) := mk_cast_eq_and_nonneg_prfs pf a b ``nat_eq_subst
| `(%%a ≤ %%b) := mk_cast_eq_and_nonneg_prfs pf a b ``nat_le_subst
| `(%%a < %%b) := mk_cast_eq_and_nonneg_prfs pf a b ``nat_lt_subst
| `(%%a ≥ %%b) := mk_cast_eq_and_nonneg_prfs pf b a ``nat_le_subst
| `(%%a > %%b) := mk_cast_eq_and_nonneg_prfs pf b a ``nat_lt_subst
| `(¬ %%a ≤ %%b) := do pf' ← mk_app ``lt_of_not_ge [pf], mk_cast_eq_and_nonneg_prfs pf' b a ``nat_lt_subst
| `(¬ %%a < %%b) := do pf' ← mk_app ``le_of_not_gt [pf], mk_cast_eq_and_nonneg_prfs pf' b a ``nat_le_subst
| `(¬ %%a ≥ %%b) := do pf' ← mk_app ``lt_of_not_ge [pf], mk_cast_eq_and_nonneg_prfs pf' a b ``nat_lt_subst
| `(¬ %%a > %%b) := do pf' ← mk_app ``le_of_not_gt [pf], mk_cast_eq_and_nonneg_prfs pf' a b ``nat_le_subst
| _ := fail "mk_int_pfs_of_nat_pf failed: proof is not an inequality"
end
meta def mk_non_strict_int_pf_of_strict_int_pf (pf : expr) : tactic expr :=
do tp ← infer_type pf,
match tp with
| `(%%a < %%b) := to_expr ``(@cast (%%a < %%b) (%%a + 1 ≤ %%b) (by refl) %%pf)
| `(%%a > %%b) := to_expr ``(@cast (%%a > %%b) (%%a ≥ %%b + 1) (by refl) %%pf)
| `(¬ %%a ≤ %%b) := to_expr ``(@cast (%%a > %%b) (%%a ≥ %%b + 1) (by refl) (lt_of_not_ge %%pf))
| `(¬ %%a ≥ %%b) := to_expr ``(@cast (%%a < %%b) (%%a + 1 ≤ %%b) (by refl) (lt_of_not_ge %%pf))
| _ := fail "mk_non_strict_int_pf_of_strict_int_pf failed: proof is not an inequality"
end
meta def guard_is_nat_prop : expr → tactic unit
| `(%%a = _) := infer_type a >>= unify `(ℕ)
| `(%%a ≤ _) := infer_type a >>= unify `(ℕ)
| `(%%a < _) := infer_type a >>= unify `(ℕ)
| `(%%a ≥ _) := infer_type a >>= unify `(ℕ)
| `(%%a > _) := infer_type a >>= unify `(ℕ)
| `(¬ %%p) := guard_is_nat_prop p
| _ := failed
meta def guard_is_strict_int_prop : expr → tactic unit
| `(%%a < _) := infer_type a >>= unify `(ℤ)
| `(%%a > _) := infer_type a >>= unify `(ℤ)
| `(¬ %%a ≤ _) := infer_type a >>= unify `(ℤ)
| `(¬ %%a ≥ _) := infer_type a >>= unify `(ℤ)
| _ := failed
meta def replace_nat_pfs : list expr → tactic (list expr)
| [] := return []
| (h::t) :=
(do infer_type h >>= guard_is_nat_prop,
ls ← mk_int_pfs_of_nat_pf h,
list.append ls <$> replace_nat_pfs t) <|> list.cons h <$> replace_nat_pfs t
meta def replace_strict_int_pfs : list expr → tactic (list expr)
| [] := return []
| (h::t) :=
(do infer_type h >>= guard_is_strict_int_prop,
l ← mk_non_strict_int_pf_of_strict_int_pf h,
list.cons l <$> replace_strict_int_pfs t) <|> list.cons h <$> replace_strict_int_pfs t
meta def partition_by_type_aux : rb_lmap expr expr → list expr → tactic (rb_lmap expr expr)
| m [] := return m
| m (h::t) := do tp ← ineq_pf_tp h, partition_by_type_aux (m.insert tp h) t
meta def partition_by_type (l : list expr) : tactic (rb_lmap expr expr) :=
partition_by_type_aux mk_rb_map l
private meta def try_linarith_on_lists (cfg : linarith_config) (ls : list (list expr)) : tactic unit :=
(first $ ls.map $ prove_false_by_linarith1 cfg) <|> fail "linarith failed"
/--
Takes a list of proofs of propositions.
Filters out the proofs of linear (in)equalities,
and tries to use them to prove `false`.
If `pref_type` is given, starts by working over this type.
-/
meta def prove_false_by_linarith (cfg : linarith_config) (pref_type : option expr) (l : list expr) : tactic unit :=
do l' ← replace_nat_pfs l,
l'' ← replace_strict_int_pfs l',
ls ← list.reduce_option <$> l''.mmap (λ h, (do s ← norm_hyp h, return (some s)) <|> return none)
>>= partition_by_type,
pref_type ← (unify pref_type.iget `(ℕ) >> return (some `(ℤ) : option expr)) <|> return pref_type,
match cfg.restrict_type, rb_map.values ls, pref_type with
| some rtp, _, _ :=
do m ← mk_mvar, unify `(some %%m : option Type) cfg.restrict_type_reflect, m ← instantiate_mvars m,
prove_false_by_linarith1 cfg (ls.ifind m)
| none, [ls'], _ := prove_false_by_linarith1 cfg ls'
| none, ls', none := try_linarith_on_lists cfg ls'
| none, _, (some t) := prove_false_by_linarith1 cfg (ls.ifind t) <|>
try_linarith_on_lists cfg (rb_map.values (ls.erase t))
end
end normalize
/--
`find_squares m e` collects all terms of the form `a ^ 2` and `a * a` that appear in `e`
and adds them to the set `m`.
A pair `(a, tt)` is added to `m` when `a^2` appears in `e`, and `(a, ff)` is added to `m`
when `a*a` appears in `e`. -/
meta def find_squares : rb_set (expr × bool) → expr → tactic (rb_set (expr × bool))
| s `(%%a ^ 2) := do s ← find_squares s a, return (s.insert (a, tt))
| s e@`(%%e1 * %%e2) := if e1 = e2 then do s ← find_squares s e1, return (s.insert (e1, ff)) else e.mfoldl find_squares s
| s e := e.mfoldl find_squares s
-- used in the `nlinarith` normalization steps. The `_` argument is for uniformity.
@[nolint unused_arguments]
lemma mul_zero_eq {α} {R : α → α → Prop} [semiring α] {a b : α} (_ : R a 0) (h : b = 0) : a * b = 0 :=
by simp [h]
-- used in the `nlinarith` normalization steps. The `_` argument is for uniformity.
@[nolint unused_arguments]
lemma zero_mul_eq {α} {R : α → α → Prop} [semiring α] {a b : α} (h : a = 0) (_ : R b 0) : a * b = 0 :=
by simp [h]
end linarith
section
open tactic linarith
open lean lean.parser interactive tactic interactive.types
local postfix `?`:9001 := optional
local postfix *:9001 := many
meta def linarith.elab_arg_list : option (list pexpr) → tactic (list expr)
| none := return []
| (some l) := l.mmap i_to_expr
meta def linarith.preferred_type_of_goal : option expr → tactic (option expr)
| none := return none
| (some e) := some <$> ineq_pf_tp e
/--
`linarith.interactive_aux cfg o_goal restrict_hyps args`:
* `cfg` is a `linarith_config` object
* `o_goal : option expr` is the local constant corresponding to the former goal, if there was one
* `restrict_hyps : bool` is `tt` if `linarith only [...]` was used
* `args : option (list pexpr)` is the optional list of arguments in `linarith [...]`
-/
meta def linarith.interactive_aux (cfg : linarith_config) :
option expr → bool → option (list pexpr) → tactic unit
| none tt none := fail "linarith only called with no arguments"
| none tt (some l) := l.mmap i_to_expr >>= prove_false_by_linarith cfg none
| (some e) tt l :=
do tp ← ineq_pf_tp e,
list.cons e <$> linarith.elab_arg_list l >>= prove_false_by_linarith cfg (some tp)
| oe ff l :=
do otp ← linarith.preferred_type_of_goal oe,
list.append <$> local_context <*>
(list.filter (λ a, bnot $ expr.is_local_constant a) <$> linarith.elab_arg_list l) >>=
prove_false_by_linarith cfg otp
/--
Tries to prove a goal of `false` by linear arithmetic on hypotheses.
If the goal is a linear (in)equality, tries to prove it by contradiction.
If the goal is not `false` or an inequality, applies `exfalso` and tries linarith on the
hypotheses.
* `linarith` will use all relevant hypotheses in the local context.
* `linarith [t1, t2, t3]` will add proof terms t1, t2, t3 to the local context.
* `linarith only [h1, h2, h3, t1, t2, t3]` will use only the goal (if relevant), local hypotheses
`h1`, `h2`, `h3`, and proofs `t1`, `t2`, `t3`. It will ignore the rest of the local context.
* `linarith!` will use a stronger reducibility setting to identify atoms.
Config options:
* `linarith {exfalso := ff}` will fail on a goal that is neither an inequality nor `false`
* `linarith {restrict_type := T}` will run only on hypotheses that are inequalities over `T`
* `linarith {discharger := tac}` will use `tac` instead of `ring` for normalization.
Options: `ring2`, `ring SOP`, `simp`
-/
meta def tactic.interactive.linarith (red : parse ((tk "!")?))
(restr : parse ((tk "only")?)) (hyps : parse pexpr_list?)
(cfg : linarith_config := {}) : tactic unit :=
let cfg :=
if red.is_some then {cfg with transparency := semireducible, discharger := `[ring!]}
else cfg in
do t ← target,
when cfg.split_hypotheses (try auto.split_hyps),
match get_contr_lemma_name t with
| some nm := seq' (applyc nm) $
do t ← intro1, linarith.interactive_aux cfg (some t) restr.is_some hyps
| none := if cfg.exfalso then exfalso >> linarith.interactive_aux cfg none restr.is_some hyps
else fail "linarith failed: target type is not an inequality."
end
add_hint_tactic "linarith"
/--
`linarith` attempts to find a contradiction between hypotheses that are linear (in)equalities.
Equivalently, it can prove a linear inequality by assuming its negation and proving `false`.
In theory, `linarith` should prove any goal that is true in the theory of linear arithmetic over
the rationals. While there is some special handling for non-dense orders like `nat` and `int`,
this tactic is not complete for these theories and will not prove every true goal.
An example:
```lean
example (x y z : ℚ) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0)
(h3 : 12*y - 4* z < 0) : false :=
by linarith
```
`linarith` will use all appropriate hypotheses and the negation of the goal, if applicable.
`linarith [t1, t2, t3]` will additionally use proof terms `t1, t2, t3`.
`linarith only [h1, h2, h3, t1, t2, t3]` will use only the goal (if relevant), local hypotheses
`h1`, `h2`, `h3`, and proofs `t1`, `t2`, `t3`. It will ignore the rest of the local context.
`linarith!` will use a stronger reducibility setting to try to identify atoms. For example,
```lean
example (x : ℚ) : id x ≥ x :=
by linarith
```
will fail, because `linarith` will not identify `x` and `id x`. `linarith!` will.
This can sometimes be expensive.
`linarith {discharger := tac, restrict_type := tp, exfalso := ff}` takes a config object with five
optional arguments:
* `discharger` specifies a tactic to be used for reducing an algebraic equation in the
proof stage. The default is `ring`. Other options currently include `ring SOP` or `simp` for basic
problems.
* `restrict_type` will only use hypotheses that are inequalities over `tp`. This is useful
if you have e.g. both integer and rational valued inequalities in the local context, which can
sometimes confuse the tactic.
* `transparency` controls how hard `linarith` will try to match atoms to each other. By default
it will only unfold `reducible` definitions.
* If `split_hypotheses` is true, `linarith` will split conjunctions in the context into separate
hypotheses.
* If `exfalso` is false, `linarith` will fail when the goal is neither an inequality nor `false`.
(True by default.)
A variant, `nlinarith`, does some basic preprocessing to handle some nonlinear goals.
-/
add_tactic_doc
{ name := "linarith",
category := doc_category.tactic,
decl_names := [`tactic.interactive.linarith],
tags := ["arithmetic", "decision procedure", "finishing"] }
/--
An extension of `linarith` with some preprocessing to allow it to solve some nonlinear arithmetic
problems. (Based on Coq's `nra` tactic.) See `linarith` for the available syntax of options,
which are inherited by `nlinarith`; that is, `nlinarith!` and `nlinarith only [h1, h2]` all work as
in `linarith`. The preprocessing is as follows:
* For every subterm `a ^ 2` or `a * a` in a hypothesis or the goal,
the assumption `0 ≤ a ^ 2` or `0 ≤ a * a` is added to the context.
* For every pair of hypotheses `a1 R1 b1`, `a2 R2 b2` in the context, `R1, R2 ∈ {<, ≤, =}`,
the assumption `0 R' (b1 - a1) * (b2 - a2)` is added to the context (non-recursively),
where `R ∈ {<, ≤, =}` is the appropriate comparison derived from `R1, R2`.
-/
meta def tactic.interactive.nlinarith (red : parse ((tk "!")?))
(restr : parse ((tk "only")?)) (hyps : parse pexpr_list?)
(cfg : linarith_config := {}) : tactic unit := do
ls ← match hyps with
| none := if restr.is_some then return [] else local_context
| some hyps := do
ls ← hyps.mmap i_to_expr,
if restr.is_some then return ls else (++ ls) <$> local_context
end,
(s, ge0) ← (list.mfoldr (λ h ⟨s, l⟩, do
h ← infer_type h >>= rearr_comp h <|> return h,
t ← infer_type h,
s ← find_squares s t,
return (s, match t with
| `(%%a ≤ 0) := (ineq.le, h) :: l
| `(%%a < 0) := (ineq.lt, h) :: l
| `(%%a = 0) := (ineq.eq, h) :: l
| _ := l end))
(mk_rb_set, []) ls : tactic (rb_set (expr × bool) × list (ineq × expr))),
s ← target >>= find_squares s,
(hyps, ge0) ← s.fold (return (hyps, ge0)) (λ ⟨e, is_sq⟩ tac, do
(hyps, ge0) ← tac,
(do
t ← infer_type e,
when cfg.restrict_type.is_some
(is_def_eq `(some %%t : option Type) cfg.restrict_type_reflect),
p ← mk_app (if is_sq then ``pow_two_nonneg else ``mul_self_nonneg) [e],
p ← infer_type p >>= rearr_comp p <|> return p,
t ← infer_type p,
h ← assertv `h t p,
return (hyps.map (λ l, pexpr.of_expr h :: l), (ineq.le, h) :: ge0)) <|>
return (hyps, ge0)),
ge0.mmap'_diag (λ ⟨posa, a⟩ ⟨posb, b⟩, try $ do
p ← match posa, posb with
| ineq.eq, _ := mk_app ``zero_mul_eq [a, b]
| _, ineq.eq := mk_app ``mul_zero_eq [a, b]
| ineq.lt, ineq.lt := mk_app ``mul_pos_of_neg_of_neg [a, b]
| ineq.lt, ineq.le := do a ← mk_app ``le_of_lt [a], mk_app ``mul_nonneg_of_nonpos_of_nonpos [a, b]
| ineq.le, ineq.lt := do b ← mk_app ``le_of_lt [b], mk_app ``mul_nonneg_of_nonpos_of_nonpos [a, b]
| ineq.le, ineq.le := mk_app ``mul_nonneg_of_nonpos_of_nonpos [a, b]
end,
t ← infer_type p,
assertv `h t p, skip),
tactic.interactive.linarith red restr hyps cfg
add_hint_tactic "nlinarith"
add_tactic_doc
{ name := "nlinarith",
category := doc_category.tactic,
decl_names := [`tactic.interactive.nlinarith],
tags := ["arithmetic", "decision procedure", "finishing"] }
end
|
fea9d8ca4c841a80e4979f97731881950881e728 | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /tests/lean/run/bigmul.lean | 7b708f861a7b7ed98f74b573483687c18da3eb0c | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 228 | lean | @[noinline] def f (x : Nat) :=
1000000000000000000000000000000
@[noinline] def tst1 (n : Nat) : IO Unit := do
IO.println (n * f n)
@[noinline] def tst2 (n : Nat) : IO Unit := do
IO.println (f n * n)
#eval tst1 0
#eval tst2 0
|
ba72e20e1f20181151b37edaded96d2d5304119a | f313d4982feee650661f61ed73f0cb6635326350 | /Mathlib/Algebra/Ring/Basic.lean | ec890e49d27dfcc63f248c2d616bce4249e0b764 | [
"Apache-2.0"
] | permissive | shingtaklam1324/mathlib4 | 38c6e172eec1385944db5a70a3b5545c924980ee | 50610c343b7065e8eec056d641f859ceed608e69 | refs/heads/master | 1,683,032,333,313 | 1,621,942,699,000 | 1,621,942,699,000 | 371,130,608 | 0 | 0 | Apache-2.0 | 1,622,053,166,000 | 1,622,053,166,000 | null | UTF-8 | Lean | false | false | 1,328 | lean | import Mathlib.Algebra.GroupWithZero.Defs
import Mathlib.Algebra.Group.Basic
/-
# Semirings and rings
-/
class Semiring (R : Type u) extends Monoid R, AddCommMonoid R where
zero_mul (a : R) : 0 * a = 0
mul_zero (a : R) : a * 0 = 0
mul_add (a b c : R) : a * (b + c) = a * b + a * c
add_mul (a b c : R) : (a + b) * c = a * c + b * c
instance (R : Type u) [h : Semiring R] : MonoidWithZero R :=
{ h with }
class CommSemiring (R : Type u) extends Semiring R where
mul_comm (a b : R) : a * b = b * a
instance (R : Type u) [h : CommSemiring R] : CommMonoid R :=
{ h with }
class Ring (R : Type u) extends Monoid R, AddCommGroup R where
mul_add (a b c : R) : a * (b + c) = a * b + a * c
add_mul (a b c : R) : (a + b) * c = a * c + b * c
-- I need to name this instance and I don't know the default name
instance Ring.toSemiring (R : Type u) [h : Ring R] : Semiring R :=
{ h with
toAddCommMonoid := AddCommGroup.toAddCommMonoid R
zero_mul := λ a => by rw [← add_right_eq_self (a := 0 * a), ← Ring.add_mul, zero_add]
mul_zero := λ a => by rw [← add_right_eq_self (a := a * 0), ← Ring.mul_add, add_zero]
}
class CommRing (R : Type u) extends Ring R where
mul_comm (a b : R) : a * b = b * a
instance (R : Type u) [h : CommRing R] : CommSemiring R :=
{ h with
toSemiring := Ring.toSemiring R
}
|
e75d958fdd5ee8f5e4aa83eba48d7b97e8be3dfb | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/combinatorics/additive/behrend.lean | a98ea5c4dde4c7fb6d7badb5b017c6d17a9e2448 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 22,401 | lean | /-
Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import analysis.inner_product_space.pi_L2
import combinatorics.additive.salem_spencer
import combinatorics.pigeonhole
import data.complex.exponential_bounds
/-!
# Behrend's bound on Roth numbers
This file proves Behrend's lower bound on Roth numbers. This says that we can find a subset of
`{1, ..., n}` of size `n / exp (O (sqrt (log n)))` which does not contain arithmetic progressions of
length `3`.
The idea is that the sphere (in the `n` dimensional Euclidean space) doesn't contain arithmetic
progressions (literally) because the corresponding ball is strictly convex. Thus we can take
integer points on that sphere and map them onto `ℕ` in a way that preserves arithmetic progressions
(`behrend.map`).
## Main declarations
* `behrend.sphere`: The intersection of the Euclidean sphere with the positive integer quadrant.
This is the set that we will map on `ℕ`.
* `behrend.map`: Given a natural number `d`, `behrend.map d : ℕⁿ → ℕ` reads off the coordinates as
digits in base `d`.
* `behrend.card_sphere_le_roth_number_nat`: Implicit lower bound on Roth numbers in terms of
`behrend.sphere`.
* `behrend.roth_lower_bound`: Behrend's explicit lower bound on Roth numbers.
## References
* [Bryan Gillespie, *Behrend’s Construction*]
(http://www.epsilonsmall.com/resources/behrends-construction/behrend.pdf)
* Behrend, F. A., "On sets of integers which contain no three terms in arithmetical progression"
* [Wikipedia, *Salem-Spencer set*](https://en.wikipedia.org/wiki/Salem–Spencer_set)
## Tags
Salem-Spencer, Behrend construction, arithmetic progression, sphere, strictly convex
-/
open finset nat real
open_locale big_operators pointwise
namespace behrend
variables {α β : Type*} {n d k N : ℕ} {x : fin n → ℕ}
/-!
### Turning the sphere into a Salem-Spencer set
We define `behrend.sphere`, the intersection of the $$L^2$$ sphere with the positive quadrant of
integer points. Because the $$L^2$$ closed ball is strictly convex, the $$L^2$$ sphere and
`behrend.sphere` are Salem-Spencer (`add_salem_spencer_sphere`). Then we can turn this set in
`fin n → ℕ` into a set in `ℕ` using `behrend.map`, which preserves `add_salem_spencer` because it is
an additive monoid homomorphism.
-/
/-- The box `{0, ..., d - 1}^n` as a finset. -/
def box (n d : ℕ) : finset (fin n → ℕ) := fintype.pi_finset $ λ _, range d
lemma mem_box : x ∈ box n d ↔ ∀ i, x i < d := by simp only [box, fintype.mem_pi_finset, mem_range]
@[simp] lemma card_box : (box n d).card = d ^ n := by simp [box]
@[simp] lemma box_zero : box (n + 1) 0 = ∅ := by simp [box]
/-- The intersection of the sphere of radius `sqrt k` with the integer points in the positive
quadrant. -/
def sphere (n d k : ℕ) : finset (fin n → ℕ) := (box n d).filter $ λ x, ∑ i, x i^2 = k
lemma sphere_zero_subset : sphere n d 0 ⊆ 0 :=
λ x, by simp [sphere, function.funext_iff] {contextual := tt}
@[simp] lemma sphere_zero_right (n k : ℕ) : sphere (n + 1) 0 k = ∅ := by simp [sphere]
lemma sphere_subset_box : sphere n d k ⊆ box n d := filter_subset _ _
lemma norm_of_mem_sphere {x : fin n → ℕ} (hx : x ∈ sphere n d k) :
∥(pi_Lp.equiv 2 _).symm (coe ∘ x : fin n → ℝ)∥ = sqrt k :=
begin
rw euclidean_space.norm_eq,
dsimp,
simp_rw [abs_cast, ←cast_pow, ←cast_sum, (mem_filter.1 hx).2],
end
lemma sphere_subset_preimage_metric_sphere :
(sphere n d k : set (fin n → ℕ)) ⊆
(λ x : fin n → ℕ, (pi_Lp.equiv 2 _).symm (coe ∘ x : fin n → ℝ)) ⁻¹'
metric.sphere (0 : pi_Lp 2 (λ _ : fin n, ℝ)) (sqrt k) :=
λ x hx, by rw [set.mem_preimage, mem_sphere_zero_iff_norm, norm_of_mem_sphere hx]
/-- The map that appears in Behrend's bound on Roth numbers. -/
@[simps] def map (d : ℕ) : (fin n → ℕ) →+ ℕ :=
{ to_fun := λ a, ∑ i, a i * d ^ (i : ℕ),
map_zero' := by simp_rw [pi.zero_apply, zero_mul, sum_const_zero],
map_add' := λ a b, by simp_rw [pi.add_apply, add_mul, sum_add_distrib] }
@[simp] lemma map_zero (d : ℕ) (a : fin 0 → ℕ) : map d a = 0 := by simp [map]
lemma map_succ (a : fin (n + 1) → ℕ) : map d a = a 0 + (∑ x : fin n, a x.succ * d ^ (x : ℕ)) * d :=
by simp [map, fin.sum_univ_succ, pow_succ', ←mul_assoc, ←sum_mul]
lemma map_succ' (a : fin (n + 1) → ℕ) : map d a = a 0 + map d (a ∘ fin.succ) * d := map_succ _
lemma map_monotone (d : ℕ) : monotone (map d : (fin n → ℕ) → ℕ) :=
λ x y h, by { dsimp, exact sum_le_sum (λ i _, nat.mul_le_mul_right _ $ h i) }
lemma map_mod (a : fin n.succ → ℕ) : map d a % d = a 0 % d :=
by rw [map_succ, nat.add_mul_mod_self_right]
lemma map_eq_iff {x₁ x₂ : fin n.succ → ℕ} (hx₁ : ∀ i, x₁ i < d) (hx₂ : ∀ i, x₂ i < d) :
map d x₁ = map d x₂ ↔ x₁ 0 = x₂ 0 ∧ map d (x₁ ∘ fin.succ) = map d (x₂ ∘ fin.succ) :=
begin
refine ⟨λ h, _, λ h, by rw [map_succ', map_succ', h.1, h.2]⟩,
have : x₁ 0 = x₂ 0,
{ rw [←mod_eq_of_lt (hx₁ _), ←map_mod, ←mod_eq_of_lt (hx₂ _), ←map_mod, h] },
rw [map_succ, map_succ, this, add_right_inj, mul_eq_mul_right_iff] at h,
exact ⟨this, h.resolve_right (pos_of_gt (hx₁ 0)).ne'⟩,
end
lemma map_inj_on : {x : fin n → ℕ | ∀ i, x i < d}.inj_on (map d) :=
begin
intros x₁ hx₁ x₂ hx₂ h,
induction n with n ih,
{ simp },
ext i,
have x := (map_eq_iff hx₁ hx₂).1 h,
refine fin.cases x.1 (congr_fun $ ih (λ _, _) (λ _, _) x.2) i,
{ exact hx₁ _ },
{ exact hx₂ _ }
end
lemma map_le_of_mem_box (hx : x ∈ box n d) :
map (2 * d - 1) x ≤ ∑ i : fin n, (d - 1) * (2 * d - 1) ^ (i : ℕ) :=
map_monotone (2 * d - 1) $ λ _, nat.le_pred_of_lt $ mem_box.1 hx _
lemma add_salem_spencer_sphere : add_salem_spencer (sphere n d k : set (fin n → ℕ)) :=
begin
set f : (fin n → ℕ) →+ euclidean_space ℝ (fin n) :=
{ to_fun := λ f, (coe : ℕ → ℝ) ∘ f,
map_zero' := funext $ λ _, cast_zero,
map_add' := λ _ _, funext $ λ _, cast_add _ _ },
refine add_salem_spencer.of_image (f.to_add_freiman_hom (sphere n d k) 2) _ _,
{ exact cast_injective.comp_left.inj_on _ },
refine (add_salem_spencer_sphere 0 $ sqrt k).mono (set.image_subset_iff.2 $ λ x, _),
rw [set.mem_preimage, mem_sphere_zero_iff_norm],
exact norm_of_mem_sphere,
end
lemma add_salem_spencer_image_sphere :
add_salem_spencer ((sphere n d k).image (map (2 * d - 1)) : set ℕ) :=
begin
rw coe_image,
refine @add_salem_spencer.image _ (fin n → ℕ) ℕ _ _ (sphere n d k) _ (map (2 * d - 1))
(map_inj_on.mono _) add_salem_spencer_sphere,
rw set.add_subset_iff,
rintro a ha b hb i,
have hai := mem_box.1 (sphere_subset_box ha) i,
have hbi := mem_box.1 (sphere_subset_box hb) i,
rw [lt_tsub_iff_right, ←succ_le_iff, two_mul],
exact (add_add_add_comm _ _ 1 1).trans_le (add_le_add hai hbi),
end
lemma sum_sq_le_of_mem_box (hx : x ∈ box n d) : ∑ i : fin n, (x i)^2 ≤ n * (d - 1)^2 :=
begin
rw mem_box at hx,
have : ∀ i, x i ^ 2 ≤ (d - 1) ^ 2 := λ i, nat.pow_le_pow_of_le_left (nat.le_pred_of_lt (hx i)) _,
exact (sum_le_card_nsmul univ _ _ $ λ i _, this i).trans (by rw [card_fin, smul_eq_mul]),
end
lemma sum_eq : ∑ i : fin n, d * (2 * d + 1) ^ (i : ℕ) = ((2 * d + 1) ^ n - 1) / 2 :=
begin
refine (nat.div_eq_of_eq_mul_left zero_lt_two _).symm,
rw [←sum_range (λ i, d * (2 * d + 1) ^ (i : ℕ)), ←mul_sum, mul_right_comm, mul_comm d,
←geom_sum_mul_add, add_tsub_cancel_right, mul_comm],
end
lemma sum_lt : ∑ i : fin n, d * (2 * d + 1) ^ (i : ℕ) < (2 * d + 1) ^ n :=
sum_eq.trans_lt $ (nat.div_le_self _ 2).trans_lt $ pred_lt (pow_pos (succ_pos _) _).ne'
lemma card_sphere_le_roth_number_nat (n d k : ℕ) :
(sphere n d k).card ≤ roth_number_nat ((2 * d - 1) ^ n) :=
begin
cases n,
{ refine (card_le_univ _).trans_eq _,
rw pow_zero,
exact fintype.card_unique },
cases d,
{ simp },
refine add_salem_spencer_image_sphere.le_roth_number_nat _ _ (card_image_of_inj_on _),
{ simp only [subset_iff, mem_image, and_imp, forall_exists_index, mem_range,
forall_apply_eq_imp_iff₂, sphere, mem_filter],
rintro _ x hx _ rfl,
exact (map_le_of_mem_box hx).trans_lt sum_lt },
refine map_inj_on.mono (λ x, _),
simp only [mem_coe, sphere, mem_filter, mem_box, and_imp, two_mul],
exact λ h _ i, (h i).trans_le le_self_add,
end
/-!
### Optimization
Now that we know how to turn the integer points of any sphere into a Salem-Spencer set, we find a
sphere containing many integer points by the pigeonhole principle. This gives us an implicit bound
that we then optimize by tweaking the parameters. The (almost) optimal parameters are
`behrend.n_value` and `behrend.d_value`.
-/
lemma exists_large_sphere_aux (n d : ℕ) :
∃ k ∈ range (n * (d - 1)^2 + 1), (↑(d ^ n) / (↑(n * (d - 1)^2) + 1) : ℝ) ≤ (sphere n d k).card :=
begin
refine exists_le_card_fiber_of_nsmul_le_card_of_maps_to (λ x hx, _) nonempty_range_succ _,
{ rw [mem_range, lt_succ_iff],
exact sum_sq_le_of_mem_box hx },
{ rw [card_range, _root_.nsmul_eq_mul, mul_div_assoc', cast_add_one, mul_div_cancel_left,
card_box],
exact (cast_add_one_pos _).ne' }
end
lemma exists_large_sphere (n d : ℕ) : ∃ k, (d ^ n / ↑(n * d^2) : ℝ) ≤ (sphere n d k).card :=
begin
obtain ⟨k, -, hk⟩ := exists_large_sphere_aux n d,
refine ⟨k, _⟩,
obtain rfl | hn := n.eq_zero_or_pos,
{ simp },
obtain rfl | hd := d.eq_zero_or_pos,
{ simp },
rw ←cast_pow,
refine (div_le_div_of_le_left _ _ _).trans hk,
{ exact cast_nonneg _ },
{ exact cast_add_one_pos _ },
simp only [←le_sub_iff_add_le', cast_mul, ←mul_sub, cast_pow, cast_sub hd, sub_sq,
one_pow, cast_one, mul_one, sub_add, sub_sub_self],
apply one_le_mul_of_one_le_of_one_le,
{ rwa one_le_cast },
rw le_sub_iff_add_le,
norm_num,
exact one_le_cast.2 hd,
end
lemma bound_aux' (n d : ℕ) : (d ^ n / ↑(n * d^2) : ℝ) ≤ roth_number_nat ((2 * d - 1)^n) :=
let ⟨k, h⟩ := exists_large_sphere n d in h.trans $ cast_le.2 $ card_sphere_le_roth_number_nat _ _ _
lemma bound_aux (hd : d ≠ 0) (hn : 2 ≤ n) :
(d ^ (n - 2) / n : ℝ) ≤ roth_number_nat ((2 * d - 1)^n) :=
begin
convert bound_aux' n d using 1,
rw [cast_mul, cast_pow, mul_comm, ←div_div, pow_sub₀ _ _ hn, ←div_eq_mul_inv],
rwa cast_ne_zero,
end
open_locale filter topological_space
open real
section numerical_bounds
lemma log_two_mul_two_le_sqrt_log_eight : log 2 * 2 ≤ sqrt (log 8) :=
begin
rw [show (8 : ℝ) = 2 ^ ((3 : ℕ) : ℝ), by norm_num1, log_rpow zero_lt_two (3:ℕ)],
apply le_sqrt_of_sq_le,
rw [mul_pow, sq (log 2), mul_assoc, mul_comm],
refine mul_le_mul_of_nonneg_right _ (log_nonneg one_le_two),
rw ←le_div_iff,
apply log_two_lt_d9.le.trans,
all_goals { norm_num1 }
end
lemma two_div_one_sub_two_div_e_le_eight : 2 / (1 - 2 / exp 1) ≤ 8 :=
begin
rw [div_le_iff, mul_sub, mul_one, mul_div_assoc', le_sub, div_le_iff (exp_pos _)],
{ linarith [exp_one_gt_d9] },
rw [sub_pos, div_lt_one];
exact exp_one_gt_d9.trans' (by norm_num),
end
lemma le_sqrt_log (hN : 4096 ≤ N) : log (2 / (1 - 2 / exp 1)) * (69 / 50) ≤ sqrt (log ↑N) :=
begin
have : ((12 : ℕ) : ℝ) * log 2 ≤ log N,
{ rw [←log_rpow zero_lt_two, log_le_log, rpow_nat_cast],
{ norm_num1,
exact_mod_cast hN },
{ exact rpow_pos_of_pos zero_lt_two _ },
rw cast_pos,
exact hN.trans_lt' (by norm_num1) },
refine (mul_le_mul_of_nonneg_right ((log_le_log _ $ by norm_num1).2
two_div_one_sub_two_div_e_le_eight) $ by norm_num1).trans (_),
{ refine div_pos zero_lt_two _,
rw [sub_pos, div_lt_one (exp_pos _)],
exact exp_one_gt_d9.trans_le' (by norm_num1) },
have l8 : log 8 = (3 : ℕ) * log 2,
{ rw [←log_rpow zero_lt_two, rpow_nat_cast],
norm_num },
rw [l8, cast_bit1, cast_one],
apply le_sqrt_of_sq_le (le_trans _ this),
simp only [cast_bit0, cast_bit1, cast_one],
rw [mul_right_comm, mul_pow, sq (log 2), ←mul_assoc],
apply mul_le_mul_of_nonneg_right _ (log_nonneg one_le_two),
rw ←le_div_iff' ,
{ exact log_two_lt_d9.le.trans (by norm_num1) },
exact sq_pos_of_ne_zero _ (by norm_num1),
end
lemma exp_neg_two_mul_le {x : ℝ} (hx : 0 < x) : exp (-2 * x) < exp (2 - ⌈x⌉₊) / ⌈x⌉₊ :=
begin
have h₁ := ceil_lt_add_one hx.le,
have h₂ : 1 - x ≤ 2 - ⌈x⌉₊,
{ rw le_sub_iff_add_le,
apply (add_le_add_left h₁.le _).trans_eq,
rw [←add_assoc, sub_add_cancel],
refl },
have h₃ : exp (-(x+1)) ≤ 1 / (x + 1),
{ rw [exp_neg, inv_eq_one_div],
refine one_div_le_one_div_of_le (add_pos hx zero_lt_one) _,
apply le_trans _ (add_one_le_exp_of_nonneg $ add_nonneg hx.le zero_le_one),
exact le_add_of_nonneg_right zero_le_one },
refine lt_of_le_of_lt _ (div_lt_div_of_lt_left (exp_pos _) (cast_pos.2 $ ceil_pos.2 hx) h₁),
refine le_trans _ (div_le_div_of_le_of_nonneg (exp_le_exp.2 h₂) $ add_nonneg hx.le zero_le_one),
rw [le_div_iff (add_pos hx zero_lt_one), ←le_div_iff' (exp_pos _), ←exp_sub, neg_mul,
sub_neg_eq_add, two_mul, sub_add_add_cancel, add_comm _ x],
refine le_trans _ (add_one_le_exp_of_nonneg $ add_nonneg hx.le zero_le_one),
exact le_add_of_nonneg_right zero_le_one,
end
lemma div_lt_floor {x : ℝ} (hx : 2 / (1 - 2 / exp 1) ≤ x) : x / exp 1 < (⌊x/2⌋₊ : ℝ) :=
begin
apply lt_of_le_of_lt _ (sub_one_lt_floor _),
have : 0 < 1 - 2 / exp 1,
{ rw [sub_pos, div_lt_one (exp_pos _)],
exact lt_of_le_of_lt (by norm_num) exp_one_gt_d9 },
rwa [le_sub, div_eq_mul_one_div x, div_eq_mul_one_div x, ←mul_sub, div_sub', ←div_eq_mul_one_div,
mul_div_assoc', one_le_div, ←div_le_iff this],
{ exact zero_lt_two },
{ exact two_ne_zero }
end
lemma ceil_lt_mul {x : ℝ} (hx : 50/19 ≤ x) : (⌈x⌉₊ : ℝ) < 1.38 * x :=
begin
refine (ceil_lt_add_one $ hx.trans' $ by norm_num).trans_le _,
rwa [←le_sub_iff_add_le', ←sub_one_mul, show (69/50 - 1 : ℝ) = (50/19)⁻¹, by norm_num1,
←div_eq_inv_mul, one_le_div],
norm_num1,
end
end numerical_bounds
/-- The (almost) optimal value of `n` in `behrend.bound_aux`. -/
noncomputable def n_value (N : ℕ) : ℕ := ⌈sqrt (log N)⌉₊
/-- The (almost) optimal value of `d` in `behrend.bound_aux`. -/
noncomputable def d_value (N : ℕ) : ℕ := ⌊(N : ℝ)^(1 / n_value N : ℝ)/2⌋₊
lemma n_value_pos (hN : 2 ≤ N) : 0 < n_value N :=
ceil_pos.2 $ real.sqrt_pos.2 $ log_pos $ one_lt_cast.2 $ hN
lemma two_le_n_value (hN : 3 ≤ N) : 2 ≤ n_value N :=
begin
refine succ_le_of_lt (lt_ceil.2 $ lt_sqrt_of_sq_lt _),
rw [cast_one, one_pow, lt_log_iff_exp_lt],
refine lt_of_lt_of_le _ (cast_le.2 hN),
{ exact exp_one_lt_d9.trans_le (by norm_num) },
rw cast_pos,
exact (zero_lt_succ _).trans_le hN,
end
lemma three_le_n_value (hN : 64 ≤ N) : 3 ≤ n_value N :=
begin
rw [n_value, ←lt_iff_add_one_le, lt_ceil, cast_two],
apply lt_sqrt_of_sq_lt,
have : (2 : ℝ)^((6 : ℕ) : ℝ) ≤ N,
{ rw rpow_nat_cast,
exact (cast_le.2 hN).trans' (by norm_num1) },
apply lt_of_lt_of_le _ ((log_le_log (rpow_pos_of_pos zero_lt_two _) _).2 this),
rw [log_rpow zero_lt_two, cast_bit0, cast_bit1, cast_one, ←div_lt_iff'],
{ exact log_two_gt_d9.trans_le' (by norm_num1) },
{ norm_num1 },
rw cast_pos,
exact hN.trans_lt' (by norm_num1),
end
lemma d_value_pos (hN₃ : 8 ≤ N) : 0 < d_value N :=
begin
have hN₀ : 0 < (N : ℝ) := cast_pos.2 (succ_pos'.trans_le hN₃),
rw [d_value, floor_pos, ←log_le_log zero_lt_one, log_one, log_div _ two_ne_zero, log_rpow hN₀,
div_mul_eq_mul_div, one_mul, sub_nonneg, le_div_iff],
{ have : (n_value N : ℝ) ≤ 2 * sqrt (log N),
{ apply (ceil_lt_add_one $ sqrt_nonneg _).le.trans,
rw [two_mul, add_le_add_iff_left],
apply le_sqrt_of_sq_le,
rw [one_pow, le_log_iff_exp_le hN₀],
exact (exp_one_lt_d9.le.trans $ by norm_num).trans (cast_le.2 hN₃) },
apply (mul_le_mul_of_nonneg_left this $ log_nonneg one_le_two).trans _,
rw [←mul_assoc, ←le_div_iff (real.sqrt_pos.2 $ log_pos $ one_lt_cast.2 _), div_sqrt],
{ apply log_two_mul_two_le_sqrt_log_eight.trans,
apply real.sqrt_le_sqrt,
rw log_le_log _ hN₀,
{ exact_mod_cast hN₃ },
{ norm_num } },
exact hN₃.trans_lt' (by norm_num) },
{ exact cast_pos.2 (n_value_pos $ hN₃.trans' $ by norm_num) },
{ exact (rpow_pos_of_pos hN₀ _).ne' },
{ exact div_pos (rpow_pos_of_pos hN₀ _) zero_lt_two },
end
lemma le_N (hN : 2 ≤ N) : (2 * (d_value N) - 1)^(n_value N) ≤ N :=
begin
have : (2 * d_value N - 1)^(n_value N) ≤ (2 * d_value N)^(n_value N) :=
nat.pow_le_pow_of_le_left (nat.sub_le _ _) _,
apply this.trans,
suffices : ((2 * d_value N)^n_value N : ℝ) ≤ N, by exact_mod_cast this,
rw ←rpow_nat_cast,
suffices i : (2 * d_value N : ℝ) ≤ (N : ℝ)^(1/n_value N : ℝ),
{ apply (rpow_le_rpow (mul_nonneg zero_le_two (cast_nonneg _)) i (cast_nonneg _)).trans,
rw [←rpow_mul (cast_nonneg _), one_div_mul_cancel, rpow_one],
rw cast_ne_zero,
apply (n_value_pos hN).ne', },
rw ←le_div_iff',
{ exact floor_le (div_nonneg (rpow_nonneg_of_nonneg (cast_nonneg _) _) zero_le_two) },
apply zero_lt_two
end
lemma bound (hN : 4096 ≤ N) : (N : ℝ)^(1/n_value N : ℝ) / exp 1 < d_value N :=
begin
apply div_lt_floor _,
rw [←log_le_log, log_rpow, mul_comm, ←div_eq_mul_one_div],
{ apply le_trans _ (div_le_div_of_le_left _ _ (ceil_lt_mul _).le),
rw [mul_comm, ←div_div, div_sqrt, le_div_iff],
{ exact le_sqrt_log hN },
{ norm_num1 },
{ apply log_nonneg,
rw one_le_cast,
exact hN.trans' (by norm_num1) },
{ rw [cast_pos, lt_ceil, cast_zero, real.sqrt_pos],
apply log_pos,
rw one_lt_cast,
exact hN.trans_lt' (by norm_num1) },
apply le_sqrt_of_sq_le,
have : ((12 : ℕ) : ℝ) * log 2 ≤ log N,
{ rw [←log_rpow zero_lt_two, log_le_log, rpow_nat_cast],
{ norm_num1,
exact_mod_cast hN },
{ exact rpow_pos_of_pos zero_lt_two _ },
rw cast_pos,
exact hN.trans_lt' (by norm_num1) },
refine le_trans _ this,
simp only [cast_bit0, cast_bit1, cast_one],
rw ←div_le_iff',
{ exact log_two_gt_d9.le.trans' (by norm_num1) },
{ norm_num1 } },
{ rw cast_pos,
exact hN.trans_lt' (by norm_num1) },
{ refine div_pos zero_lt_two _,
rw [sub_pos, div_lt_one (exp_pos _)],
exact lt_of_le_of_lt (by norm_num1) exp_one_gt_d9 },
apply rpow_pos_of_pos,
rw cast_pos,
exact hN.trans_lt' (by norm_num1),
end
lemma roth_lower_bound_explicit (hN : 4096 ≤ N) :
(N : ℝ) * exp (-4 * sqrt (log N)) < roth_number_nat N :=
begin
let n := n_value N,
have hn : 0 < (n : ℝ) := cast_pos.2 (n_value_pos $ hN.trans' $ by norm_num1),
have hd : 0 < d_value N := d_value_pos (hN.trans' $ by norm_num1),
have hN₀ : 0 < (N : ℝ) := cast_pos.2 (hN.trans' $ by norm_num1),
have hn₂ : 2 ≤ n := two_le_n_value (hN.trans' $ by norm_num1),
have : (2 * d_value N - 1)^n ≤ N := le_N (hN.trans' $ by norm_num1),
refine ((bound_aux hd.ne' hn₂).trans $ cast_le.2 $ roth_number_nat.mono this).trans_lt' _,
refine (div_lt_div_of_lt hn $ pow_lt_pow_of_lt_left (bound hN) _ _).trans_le' _,
{ exact div_nonneg (rpow_nonneg_of_nonneg (cast_nonneg _) _) (exp_pos _).le },
{ exact tsub_pos_of_lt (three_le_n_value $ hN.trans' $ by norm_num1) },
rw [←rpow_nat_cast, div_rpow (rpow_nonneg_of_nonneg hN₀.le _) (exp_pos _).le, ←rpow_mul hN₀.le,
mul_comm (_ / _), mul_one_div, cast_sub hn₂, cast_two, same_sub_div hn.ne', exp_one_rpow,
div_div, rpow_sub hN₀, rpow_one, div_div, div_eq_mul_inv],
refine mul_le_mul_of_nonneg_left _ (cast_nonneg _),
rw [mul_inv, mul_inv, ←exp_neg, ←rpow_neg (cast_nonneg _), neg_sub, ←div_eq_mul_inv],
have : exp ((-4) * sqrt (log N)) = exp (-2 * sqrt (log N)) * exp (-2 * sqrt (log N)),
{ rw [←exp_add, ←add_mul],
norm_num },
rw this,
refine (mul_le_mul _ (exp_neg_two_mul_le $ real.sqrt_pos.2 $ log_pos _).le (exp_pos _).le $
rpow_nonneg_of_nonneg (cast_nonneg _) _),
{ rw [←le_log_iff_exp_le (rpow_pos_of_pos hN₀ _), log_rpow hN₀, ←le_div_iff, mul_div_assoc,
div_sqrt, neg_mul, neg_le_neg_iff, div_mul_eq_mul_div, div_le_iff hn],
{ exact mul_le_mul_of_nonneg_left (le_ceil _) zero_le_two },
refine real.sqrt_pos.2 (log_pos _),
rw one_lt_cast,
exact hN.trans_lt' (by norm_num1) },
{ rw one_lt_cast,
exact hN.trans_lt' (by norm_num1) }
end
lemma exp_four_lt : exp 4 < 64 :=
begin
rw [show (64 : ℝ) = 2 ^ ((6 : ℕ) : ℝ), by norm_num1,
←lt_log_iff_exp_lt (rpow_pos_of_pos zero_lt_two _), log_rpow zero_lt_two, ←div_lt_iff'],
exact log_two_gt_d9.trans_le' (by norm_num1),
norm_num
end
lemma four_zero_nine_six_lt_exp_sixteen : 4096 < exp 16 :=
begin
rw [←log_lt_iff_lt_exp (show (0 : ℝ) < 4096, by norm_num), show (4096 : ℝ) = 2 ^ 12, by norm_num,
←rpow_nat_cast, log_rpow zero_lt_two, cast_bit0, cast_bit0, cast_bit1, cast_one],
linarith [log_two_lt_d9],
end
lemma lower_bound_le_one' (hN : 2 ≤ N) (hN' : N ≤ 4096) : (N : ℝ) * exp (-4 * sqrt (log N)) ≤ 1 :=
begin
rw [←log_le_log (mul_pos (cast_pos.2 (zero_lt_two.trans_le hN)) (exp_pos _)) zero_lt_one,
log_one, log_mul (cast_pos.2 (zero_lt_two.trans_le hN)).ne' (exp_pos _).ne', log_exp,
neg_mul, ←sub_eq_add_neg, sub_nonpos, ←div_le_iff (real.sqrt_pos.2 $ log_pos $
one_lt_cast.2 $ one_lt_two.trans_le hN), div_sqrt, sqrt_le_left
(zero_le_bit0.2 zero_le_two), log_le_iff_le_exp (cast_pos.2 (zero_lt_two.trans_le hN))],
norm_num1,
apply le_trans _ four_zero_nine_six_lt_exp_sixteen.le,
exact_mod_cast hN',
end
lemma lower_bound_le_one (hN : 1 ≤ N) (hN' : N ≤ 4096) : (N : ℝ) * exp (-4 * sqrt (log N)) ≤ 1 :=
begin
obtain rfl | hN := hN.eq_or_lt,
{ norm_num },
{ exact lower_bound_le_one' hN hN' }
end
lemma roth_lower_bound : (N : ℝ) * exp (-4 * sqrt (log N)) ≤ roth_number_nat N :=
begin
obtain rfl | hN := nat.eq_zero_or_pos N,
{ norm_num },
obtain h₁ | h₁ := le_or_lt 4096 N,
{ exact (roth_lower_bound_explicit h₁).le },
{ apply (lower_bound_le_one hN h₁.le).trans,
simpa using roth_number_nat.monotone hN }
end
end behrend
|
8eaf49f926efc687b32629e6d96dc04124507559 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /tests/lean/string_imp2.lean | 5ce398b9385f1eb2b6259b14182a7f50b2c37a6e | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | EdAyers/lean4 | 57ac632d6b0789cb91fab2170e8c9e40441221bd | 37ba0df5841bde51dbc2329da81ac23d4f6a4de4 | refs/heads/master | 1,676,463,245,298 | 1,660,619,433,000 | 1,660,619,433,000 | 183,433,437 | 1 | 0 | Apache-2.0 | 1,657,612,672,000 | 1,556,196,574,000 | Lean | UTF-8 | Lean | false | false | 2,075 | lean | def f (s : String) : String :=
s ++ " " ++ s
def g (s : String) : String :=
s.push ' ' ++ s.push '-'
def h (s : String) : String :=
let it₁ := s.mkIterator;
let it₂ := it₁.next;
it₁.remainingToString ++ "-" ++ it₂.remainingToString
#eval "hello" ++ "hello"
#eval f "hello"
#eval (f "αβ").length
#eval "hello".toList
#eval "αβ".toList
#eval "".toList
#eval "αβγ".toList
#eval "αβγ".mkIterator.1
#eval "αβγ".mkIterator.next.1
#eval "αβγ".mkIterator.next.next.1
#eval "αβγ".mkIterator.next.2
#eval "αβ".1
#eval "αβ".push 'a'
#eval g "α"
#eval "".mkIterator.curr
#eval ("αβγ".mkIterator.setCurr 'a').toString
#eval (("αβγ".mkIterator.setCurr 'a').next.setCurr 'b').toString
#eval ((("αβγ".mkIterator.setCurr 'a').next.setCurr 'b').next.setCurr 'c').toString
#eval ((("αβγ".mkIterator.setCurr 'a').next.setCurr 'b').prev.setCurr 'c').toString
#eval ("abc".mkIterator.setCurr '0').toString
#eval (("abc".mkIterator.setCurr '0').next.setCurr '1').toString
#eval ((("abc".mkIterator.setCurr '0').next.setCurr '1').next.setCurr '2').toString
#eval ((("abc".mkIterator.setCurr '0').next.setCurr '1').prev.setCurr '2').toString
#eval ("abc".mkIterator.setCurr (Char.ofNat 955)).toString
#eval h "abc"
#eval "abc".mkIterator.remainingToString
#eval ("a".push (Char.ofNat 0)) ++ "bb"
#eval (("a".push (Char.ofNat 0)) ++ "αb").length
#eval "".mkIterator.hasNext
#eval "a".mkIterator.hasNext
#eval "a".mkIterator.next.hasNext
#eval "".mkIterator.hasPrev
#eval "a".mkIterator.next.hasPrev
#eval "αβ".mkIterator.next.hasPrev
#eval "αβ".mkIterator.next.prev.hasPrev
#eval "abc" == "abc"
#eval "abc" == "abd"
#eval "αβγ".drop 1
#eval "αβγ".takeRight 1
def ss : Substring := "0123abcdαβγδ".toSubstring
#eval ss.drop 4 |>.takeRight 4
#eval ss.drop 4 |>.take 4
#eval ss.dropRight 4 |>.takeRight 4
def ssDots : Substring := "____abc.αβγ.123.____".toSubstring.extract ⟨4⟩ ⟨19⟩
#eval ssDots.splitOn "."
def ssHyphs : Substring := "____abc--αβγ--123--____".toSubstring.extract ⟨4⟩ ⟨22⟩
#eval ssHyphs.splitOn "--"
|
d9ed2479880fde029daa6dc492492235e74fd47f | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/ring_theory/unique_factorization_domain.lean | fd642829377160e2268dbcfeeddc9afeaf5c4f0a | [
"Apache-2.0"
] | permissive | hikari0108/mathlib | b7ea2b7350497ab1a0b87a09d093ecc025a50dfa | a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901 | refs/heads/master | 1,690,483,608,260 | 1,631,541,580,000 | 1,631,541,580,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 52,162 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jens Wagemaker, Aaron Anderson
-/
import algebra.gcd_monoid.basic
import ring_theory.integral_domain
import ring_theory.noetherian
/-!
# Unique factorization
## Main Definitions
* `wf_dvd_monoid` holds for `monoid`s for which a strict divisibility relation is
well-founded.
* `unique_factorization_monoid` holds for `wf_dvd_monoid`s where
`irreducible` is equivalent to `prime`
## To do
* set up the complete lattice structure on `factor_set`.
-/
variables {α : Type*}
local infix ` ~ᵤ ` : 50 := associated
/-- Well-foundedness of the strict version of |, which is equivalent to the descending chain
condition on divisibility and to the ascending chain condition on
principal ideals in an integral domain.
-/
class wf_dvd_monoid (α : Type*) [comm_monoid_with_zero α] : Prop :=
(well_founded_dvd_not_unit : well_founded (@dvd_not_unit α _))
export wf_dvd_monoid (well_founded_dvd_not_unit)
@[priority 100] -- see Note [lower instance priority]
instance is_noetherian_ring.wf_dvd_monoid [integral_domain α] [is_noetherian_ring α] :
wf_dvd_monoid α :=
⟨by { convert inv_image.wf (λ a, ideal.span ({a} : set α)) (well_founded_submodule_gt _ _),
ext,
exact ideal.span_singleton_lt_span_singleton.symm }⟩
namespace wf_dvd_monoid
variables [comm_monoid_with_zero α]
open associates nat
theorem of_wf_dvd_monoid_associates (h : wf_dvd_monoid (associates α)): wf_dvd_monoid α :=
⟨begin
haveI := h,
refine (surjective.well_founded_iff mk_surjective _).2 wf_dvd_monoid.well_founded_dvd_not_unit,
intros, rw mk_dvd_not_unit_mk_iff
end⟩
variables [wf_dvd_monoid α]
instance wf_dvd_monoid_associates : wf_dvd_monoid (associates α) :=
⟨begin
refine (surjective.well_founded_iff mk_surjective _).1 wf_dvd_monoid.well_founded_dvd_not_unit,
intros, rw mk_dvd_not_unit_mk_iff
end⟩
theorem well_founded_associates : well_founded ((<) : associates α → associates α → Prop) :=
subrelation.wf (λ x y, dvd_not_unit_of_lt) wf_dvd_monoid.well_founded_dvd_not_unit
local attribute [elab_as_eliminator] well_founded.fix
lemma exists_irreducible_factor {a : α} (ha : ¬ is_unit a) (ha0 : a ≠ 0) :
∃ i, irreducible i ∧ i ∣ a :=
(irreducible_or_factor a ha).elim (λ hai, ⟨a, hai, dvd_rfl⟩)
(well_founded.fix
wf_dvd_monoid.well_founded_dvd_not_unit
(λ a ih ha ha0 ⟨x, y, hx, hy, hxy⟩,
have hx0 : x ≠ 0, from λ hx0, ha0 (by rw [← hxy, hx0, zero_mul]),
(irreducible_or_factor x hx).elim
(λ hxi, ⟨x, hxi, hxy ▸ by simp⟩)
(λ hxf, let ⟨i, hi⟩ := ih x ⟨hx0, y, hy, hxy.symm⟩ hx hx0 hxf in
⟨i, hi.1, hi.2.trans (hxy ▸ by simp)⟩)) a ha ha0)
@[elab_as_eliminator] lemma induction_on_irreducible {P : α → Prop} (a : α)
(h0 : P 0) (hu : ∀ u : α, is_unit u → P u)
(hi : ∀ a i : α, a ≠ 0 → irreducible i → P a → P (i * a)) :
P a :=
by haveI := classical.dec; exact
well_founded.fix wf_dvd_monoid.well_founded_dvd_not_unit
(λ a ih, if ha0 : a = 0 then ha0.symm ▸ h0
else if hau : is_unit a then hu a hau
else let ⟨i, hii, ⟨b, hb⟩⟩ := exists_irreducible_factor hau ha0 in
have hb0 : b ≠ 0, from λ hb0, by simp * at *,
hb.symm ▸ hi _ _ hb0 hii (ih _ ⟨hb0, i,
hii.1, by rw [hb, mul_comm]⟩))
a
lemma exists_factors (a : α) : a ≠ 0 →
∃f : multiset α, (∀b ∈ f, irreducible b) ∧ associated f.prod a :=
wf_dvd_monoid.induction_on_irreducible a
(λ h, (h rfl).elim)
(λ u hu _, ⟨0, ⟨by simp [hu], associated.symm (by simp [hu, associated_one_iff_is_unit])⟩⟩)
(λ a i ha0 hii ih hia0,
let ⟨s, hs⟩ := ih ha0 in
⟨i ::ₘ s, ⟨by clear _let_match; finish,
by { rw multiset.prod_cons,
exact hs.2.mul_left _ }⟩⟩)
end wf_dvd_monoid
theorem wf_dvd_monoid.of_well_founded_associates [comm_cancel_monoid_with_zero α]
(h : well_founded ((<) : associates α → associates α → Prop)) : wf_dvd_monoid α :=
wf_dvd_monoid.of_wf_dvd_monoid_associates
⟨by { convert h, ext, exact associates.dvd_not_unit_iff_lt }⟩
theorem wf_dvd_monoid.iff_well_founded_associates [comm_cancel_monoid_with_zero α] :
wf_dvd_monoid α ↔ well_founded ((<) : associates α → associates α → Prop) :=
⟨by apply wf_dvd_monoid.well_founded_associates, wf_dvd_monoid.of_well_founded_associates⟩
section prio
set_option default_priority 100 -- see Note [default priority]
/-- unique factorization monoids.
These are defined as `comm_cancel_monoid_with_zero`s with well-founded strict divisibility
relations, but this is equivalent to more familiar definitions:
Each element (except zero) is uniquely represented as a multiset of irreducible factors.
Uniqueness is only up to associated elements.
Each element (except zero) is non-uniquely represented as a multiset
of prime factors.
To define a UFD using the definition in terms of multisets
of irreducible factors, use the definition `of_exists_unique_irreducible_factors`
To define a UFD using the definition in terms of multisets
of prime factors, use the definition `of_exists_prime_factors`
-/
class unique_factorization_monoid (α : Type*) [comm_cancel_monoid_with_zero α]
extends wf_dvd_monoid α : Prop :=
(irreducible_iff_prime : ∀ {a : α}, irreducible a ↔ prime a)
instance ufm_of_gcd_of_wf_dvd_monoid [nontrivial α] [comm_cancel_monoid_with_zero α]
[wf_dvd_monoid α] [gcd_monoid α] : unique_factorization_monoid α :=
{ irreducible_iff_prime := λ _, gcd_monoid.irreducible_iff_prime
.. ‹wf_dvd_monoid α› }
instance associates.ufm [comm_cancel_monoid_with_zero α]
[unique_factorization_monoid α] : unique_factorization_monoid (associates α) :=
{ irreducible_iff_prime := by { rw ← associates.irreducible_iff_prime_iff,
apply unique_factorization_monoid.irreducible_iff_prime, }
.. (wf_dvd_monoid.wf_dvd_monoid_associates : wf_dvd_monoid (associates α)) }
end prio
namespace unique_factorization_monoid
variables [comm_cancel_monoid_with_zero α] [unique_factorization_monoid α]
theorem exists_prime_factors (a : α) : a ≠ 0 →
∃ f : multiset α, (∀b ∈ f, prime b) ∧ f.prod ~ᵤ a :=
by { simp_rw ← unique_factorization_monoid.irreducible_iff_prime,
apply wf_dvd_monoid.exists_factors a }
@[elab_as_eliminator] lemma induction_on_prime {P : α → Prop}
(a : α) (h₁ : P 0) (h₂ : ∀ x : α, is_unit x → P x)
(h₃ : ∀ a p : α, a ≠ 0 → prime p → P a → P (p * a)) : P a :=
begin
simp_rw ← unique_factorization_monoid.irreducible_iff_prime at h₃,
exact wf_dvd_monoid.induction_on_irreducible a h₁ h₂ h₃,
end
lemma factors_unique : ∀{f g : multiset α},
(∀x∈f, irreducible x) → (∀x∈g, irreducible x) → f.prod ~ᵤ g.prod →
multiset.rel associated f g :=
by haveI := classical.dec_eq α; exact
λ f, multiset.induction_on f
(λ g _ hg h,
multiset.rel_zero_left.2 $
multiset.eq_zero_of_forall_not_mem (λ x hx,
have is_unit g.prod, by simpa [associated_one_iff_is_unit] using h.symm,
(hg x hx).not_unit (is_unit_iff_dvd_one.2 ((multiset.dvd_prod hx).trans
(is_unit_iff_dvd_one.1 this)))))
(λ p f ih g hf hg hfg,
let ⟨b, hbg, hb⟩ := exists_associated_mem_of_dvd_prod
(irreducible_iff_prime.1 (hf p (by simp)))
(λ q hq, irreducible_iff_prime.1 (hg _ hq)) $
hfg.dvd_iff_dvd_right.1
(show p ∣ (p ::ₘ f).prod, by simp) in
begin
rw ← multiset.cons_erase hbg,
exact multiset.rel.cons hb (ih (λ q hq, hf _ (by simp [hq]))
(λ q (hq : q ∈ g.erase b), hg q (multiset.mem_of_mem_erase hq))
(associated.of_mul_left
(by rwa [← multiset.prod_cons, ← multiset.prod_cons, multiset.cons_erase hbg]) hb
(hf p (by simp)).ne_zero))
end)
end unique_factorization_monoid
lemma prime_factors_unique [comm_cancel_monoid_with_zero α] : ∀ {f g : multiset α},
(∀ x ∈ f, prime x) → (∀ x ∈ g, prime x) → f.prod ~ᵤ g.prod →
multiset.rel associated f g :=
by haveI := classical.dec_eq α; exact
λ f, multiset.induction_on f
(λ g _ hg h,
multiset.rel_zero_left.2 $
multiset.eq_zero_of_forall_not_mem $ λ x hx,
have is_unit g.prod, by simpa [associated_one_iff_is_unit] using h.symm,
(hg x hx).not_unit $ is_unit_iff_dvd_one.2 $
(multiset.dvd_prod hx).trans (is_unit_iff_dvd_one.1 this))
(λ p f ih g hf hg hfg,
let ⟨b, hbg, hb⟩ := exists_associated_mem_of_dvd_prod
(hf p (by simp)) (λ q hq, hg _ hq) $
hfg.dvd_iff_dvd_right.1
(show p ∣ (p ::ₘ f).prod, by simp) in
begin
rw ← multiset.cons_erase hbg,
exact multiset.rel.cons hb (ih (λ q hq, hf _ (by simp [hq]))
(λ q (hq : q ∈ g.erase b), hg q (multiset.mem_of_mem_erase hq))
(associated.of_mul_left
(by rwa [← multiset.prod_cons, ← multiset.prod_cons, multiset.cons_erase hbg]) hb
(hf p (by simp)).ne_zero)),
end)
/-- If an irreducible has a prime factorization,
then it is an associate of one of its prime factors. -/
lemma prime_factors_irreducible [comm_cancel_monoid_with_zero α] {a : α} {f : multiset α}
(ha : irreducible a) (pfa : (∀b ∈ f, prime b) ∧ f.prod ~ᵤ a) :
∃ p, a ~ᵤ p ∧ f = {p} :=
begin
haveI := classical.dec_eq α,
refine multiset.induction_on f (λ h, (ha.not_unit
(associated_one_iff_is_unit.1 (associated.symm h))).elim) _ pfa.2 pfa.1,
rintros p s _ ⟨u, hu⟩ hs,
use p,
have hs0 : s = 0,
{ by_contra hs0,
obtain ⟨q, hq⟩ := multiset.exists_mem_of_ne_zero hs0,
apply (hs q (by simp [hq])).2.1,
refine (ha.is_unit_or_is_unit (_ : _ = ((p * ↑u) * (s.erase q).prod) * _)).resolve_left _,
{ rw [mul_right_comm _ _ q, mul_assoc, ← multiset.prod_cons, multiset.cons_erase hq, ← hu,
mul_comm, mul_comm p _, mul_assoc],
simp, },
apply mt is_unit_of_mul_is_unit_left (mt is_unit_of_mul_is_unit_left _),
apply (hs p (multiset.mem_cons_self _ _)).2.1 },
simp only [mul_one, multiset.prod_cons, multiset.prod_zero, hs0] at *,
exact ⟨associated.symm ⟨u, hu⟩, rfl⟩,
end
section exists_prime_factors
variables [comm_cancel_monoid_with_zero α]
variables (pf : ∀ (a : α), a ≠ 0 → ∃ f : multiset α, (∀b ∈ f, prime b) ∧ f.prod ~ᵤ a)
include pf
lemma wf_dvd_monoid.of_exists_prime_factors : wf_dvd_monoid α :=
⟨begin
classical,
apply rel_hom.well_founded (rel_hom.mk _ _) (with_top.well_founded_lt nat.lt_wf),
{ intro a,
by_cases h : a = 0, { exact ⊤ },
exact (classical.some (pf a h)).card },
rintros a b ⟨ane0, ⟨c, hc, b_eq⟩⟩,
rw dif_neg ane0,
by_cases h : b = 0, { simp [h, lt_top_iff_ne_top] },
rw [dif_neg h, with_top.coe_lt_coe],
have cne0 : c ≠ 0, { refine mt (λ con, _) h, rw [b_eq, con, mul_zero] },
calc multiset.card (classical.some (pf a ane0))
< _ + multiset.card (classical.some (pf c cne0)) :
lt_add_of_pos_right _ (multiset.card_pos.mpr (λ con, hc (associated_one_iff_is_unit.mp _)))
... = multiset.card (classical.some (pf a ane0) + classical.some (pf c cne0)) :
(multiset.card_add _ _).symm
... = multiset.card (classical.some (pf b h)) :
multiset.card_eq_card_of_rel (prime_factors_unique _ (classical.some_spec (pf _ h)).1 _),
{ convert (classical.some_spec (pf c cne0)).2.symm,
rw [con, multiset.prod_zero] },
{ intros x hadd,
rw multiset.mem_add at hadd,
cases hadd; apply (classical.some_spec (pf _ _)).1 _ hadd },
{ rw multiset.prod_add,
transitivity a * c,
{ apply associated.mul_mul; apply (classical.some_spec (pf _ _)).2 },
{ rw ← b_eq,
apply (classical.some_spec (pf _ _)).2.symm, } }
end⟩
lemma irreducible_iff_prime_of_exists_prime_factors {p : α} : irreducible p ↔ prime p :=
begin
by_cases hp0 : p = 0,
{ simp [hp0] },
refine ⟨λ h, _, prime.irreducible⟩,
obtain ⟨f, hf⟩ := pf p hp0,
obtain ⟨q, hq, rfl⟩ := prime_factors_irreducible h hf,
rw hq.prime_iff,
exact hf.1 q (multiset.mem_singleton_self _)
end
theorem unique_factorization_monoid.of_exists_prime_factors :
unique_factorization_monoid α :=
{ irreducible_iff_prime := λ _, irreducible_iff_prime_of_exists_prime_factors pf,
.. wf_dvd_monoid.of_exists_prime_factors pf }
end exists_prime_factors
theorem unique_factorization_monoid.iff_exists_prime_factors [comm_cancel_monoid_with_zero α] :
unique_factorization_monoid α ↔
(∀ (a : α), a ≠ 0 → ∃ f : multiset α, (∀b ∈ f, prime b) ∧ f.prod ~ᵤ a) :=
⟨λ h, @unique_factorization_monoid.exists_prime_factors _ _ h,
unique_factorization_monoid.of_exists_prime_factors⟩
theorem irreducible_iff_prime_of_exists_unique_irreducible_factors [comm_cancel_monoid_with_zero α]
(eif : ∀ (a : α), a ≠ 0 → ∃ f : multiset α, (∀b ∈ f, irreducible b) ∧ f.prod ~ᵤ a)
(uif : ∀ (f g : multiset α),
(∀ x ∈ f, irreducible x) → (∀ x ∈ g, irreducible x) → f.prod ~ᵤ g.prod →
multiset.rel associated f g)
(p : α) : irreducible p ↔ prime p :=
⟨by letI := classical.dec_eq α; exact λ hpi,
⟨hpi.ne_zero, hpi.1,
λ a b ⟨x, hx⟩,
if hab0 : a * b = 0
then (eq_zero_or_eq_zero_of_mul_eq_zero hab0).elim
(λ ha0, by simp [ha0])
(λ hb0, by simp [hb0])
else
have hx0 : x ≠ 0, from λ hx0, by simp * at *,
have ha0 : a ≠ 0, from left_ne_zero_of_mul hab0,
have hb0 : b ≠ 0, from right_ne_zero_of_mul hab0,
begin
cases eif x hx0 with fx hfx,
cases eif a ha0 with fa hfa,
cases eif b hb0 with fb hfb,
have h : multiset.rel associated (p ::ₘ fx) (fa + fb),
{ apply uif,
{ exact λ i hi, (multiset.mem_cons.1 hi).elim (λ hip, hip.symm ▸ hpi) (hfx.1 _), },
{ exact λ i hi, (multiset.mem_add.1 hi).elim (hfa.1 _) (hfb.1 _), },
calc multiset.prod (p ::ₘ fx)
~ᵤ a * b : by rw [hx, multiset.prod_cons];
exact hfx.2.mul_left _
... ~ᵤ (fa).prod * (fb).prod :
hfa.2.symm.mul_mul hfb.2.symm
... = _ : by rw multiset.prod_add, },
exact let ⟨q, hqf, hq⟩ := multiset.exists_mem_of_rel_of_mem h
(multiset.mem_cons_self p _) in
(multiset.mem_add.1 hqf).elim
(λ hqa, or.inl $ hq.dvd_iff_dvd_left.2 $
hfa.2.dvd_iff_dvd_right.1
(multiset.dvd_prod hqa))
(λ hqb, or.inr $ hq.dvd_iff_dvd_left.2 $
hfb.2.dvd_iff_dvd_right.1
(multiset.dvd_prod hqb))
end⟩, prime.irreducible⟩
theorem unique_factorization_monoid.of_exists_unique_irreducible_factors
[comm_cancel_monoid_with_zero α]
(eif : ∀ (a : α), a ≠ 0 → ∃ f : multiset α, (∀b ∈ f, irreducible b) ∧ f.prod ~ᵤ a)
(uif : ∀ (f g : multiset α),
(∀ x ∈ f, irreducible x) → (∀ x ∈ g, irreducible x) → f.prod ~ᵤ g.prod →
multiset.rel associated f g) :
unique_factorization_monoid α :=
unique_factorization_monoid.of_exists_prime_factors (by
{ convert eif,
simp_rw irreducible_iff_prime_of_exists_unique_irreducible_factors eif uif })
namespace unique_factorization_monoid
variables [comm_cancel_monoid_with_zero α] [decidable_eq α] [nontrivial α] [normalization_monoid α]
variables [unique_factorization_monoid α]
/-- Noncomputably determines the multiset of prime factors. -/
noncomputable def factors (a : α) : multiset α := if h : a = 0 then 0 else
multiset.map normalize $ classical.some (unique_factorization_monoid.exists_prime_factors a h)
theorem factors_prod {a : α} (ane0 : a ≠ 0) : associated (factors a).prod a :=
begin
rw [factors, dif_neg ane0],
refine associated.trans _ (classical.some_spec (exists_prime_factors a ane0)).2,
rw [← associates.mk_eq_mk_iff_associated, ← associates.prod_mk, ← associates.prod_mk,
multiset.map_map],
congr' 2,
ext,
rw [function.comp_apply, associates.mk_normalize],
end
theorem prime_of_factor {a : α} : ∀ (x : α), x ∈ factors a → prime x :=
begin
rw [factors],
split_ifs with ane0, { simp },
intros x hx, rcases multiset.mem_map.1 hx with ⟨y, ⟨hy, rfl⟩⟩,
rw (normalize_associated _).prime_iff,
exact (classical.some_spec (unique_factorization_monoid.exists_prime_factors a ane0)).1 y hy,
end
theorem irreducible_of_factor {a : α} : ∀ (x : α), x ∈ factors a → irreducible x :=
λ x h, (prime_of_factor x h).irreducible
theorem normalize_factor {a : α} : ∀ (x : α), x ∈ factors a → normalize x = x :=
begin
rw factors,
split_ifs with h, { simp },
intros x hx,
obtain ⟨y, hy, rfl⟩ := multiset.mem_map.1 hx,
apply normalize_idem
end
lemma factors_irreducible {a : α} (ha : irreducible a) :
factors a = {normalize a} :=
begin
obtain ⟨p, a_assoc, hp⟩ := prime_factors_irreducible ha
⟨prime_of_factor, factors_prod ha.ne_zero⟩,
have p_mem : p ∈ factors a,
{ rw hp, exact multiset.mem_singleton_self _ },
convert hp,
rwa [← normalize_factor p p_mem, normalize_eq_normalize_iff, dvd_dvd_iff_associated]
end
lemma exists_mem_factors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : irreducible p) : p ∣ a →
∃ q ∈ factors a, p ~ᵤ q :=
λ ⟨b, hb⟩,
have hb0 : b ≠ 0, from λ hb0, by simp * at *,
have multiset.rel associated (p ::ₘ factors b) (factors a),
from factors_unique
(λ x hx, (multiset.mem_cons.1 hx).elim (λ h, h.symm ▸ hp)
(irreducible_of_factor _))
irreducible_of_factor
(associated.symm $ calc multiset.prod (factors a) ~ᵤ a : factors_prod ha0
... = p * b : hb
... ~ᵤ multiset.prod (p ::ₘ factors b) :
by rw multiset.prod_cons; exact (factors_prod hb0).symm.mul_left _),
multiset.exists_mem_of_rel_of_mem this (by simp)
@[simp] lemma factors_zero : factors (0 : α) = 0 := dif_pos rfl
@[simp] lemma factors_one : factors (1 : α) = 0 :=
begin
rw ← multiset.rel_zero_right,
apply factors_unique irreducible_of_factor,
{ intros x hx,
exfalso,
apply multiset.not_mem_zero x hx },
{ simp [factors_prod (@one_ne_zero α _ _)] },
apply_instance
end
@[simp] lemma factors_mul {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) :
factors (x * y) = factors x + factors y :=
begin
have h : (normalize : α → α) = associates.out ∘ associates.mk,
{ ext, rw [function.comp_apply, associates.out_mk], },
rw [← multiset.map_id' (factors (x * y)), ← multiset.map_id' (factors x),
← multiset.map_id' (factors y), ← multiset.map_congr normalize_factor,
← multiset.map_congr normalize_factor, ← multiset.map_congr normalize_factor,
← multiset.map_add, h, ← multiset.map_map associates.out, eq_comm,
← multiset.map_map associates.out],
refine congr rfl _,
apply multiset.map_mk_eq_map_mk_of_rel,
apply factors_unique,
{ intros x hx,
rcases multiset.mem_add.1 hx with hx | hx;
exact irreducible_of_factor x hx },
{ exact irreducible_of_factor },
{ rw multiset.prod_add,
exact ((factors_prod hx).mul_mul (factors_prod hy)).trans
(factors_prod (mul_ne_zero hx hy)).symm }
end
@[simp] lemma factors_pow {x : α} (n : ℕ) :
factors (x ^ n) = n • factors x :=
begin
induction n with n ih,
{ simp },
by_cases h0 : x = 0,
{ simp [h0, zero_pow n.succ_pos, smul_zero] },
rw [pow_succ, succ_nsmul, factors_mul h0 (pow_ne_zero _ h0), ih],
end
lemma dvd_iff_factors_le_factors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) :
x ∣ y ↔ factors x ≤ factors y :=
begin
split,
{ rintro ⟨c, rfl⟩,
simp [hx, right_ne_zero_of_mul hy] },
{ rw [← (factors_prod hx).dvd_iff_dvd_left, ← (factors_prod hy).dvd_iff_dvd_right],
apply multiset.prod_dvd_prod }
end
lemma zero_not_mem_factors (x : α) : (0 : α) ∉ factors x :=
λ h, prime.ne_zero (prime_of_factor _ h) rfl
lemma dvd_of_mem_factors {a p : α} (H : p ∈ factors a) : p ∣ a :=
begin
by_cases hcases : a = 0,
{ rw hcases,
exact dvd_zero p },
{ exact dvd_trans (multiset.dvd_prod H) (associated.dvd (factors_prod hcases)) },
end
end unique_factorization_monoid
namespace unique_factorization_monoid
open_locale classical
open multiset associates
noncomputable theory
variables [comm_cancel_monoid_with_zero α] [nontrivial α] [unique_factorization_monoid α]
/-- Noncomputably defines a `normalization_monoid` structure on a `unique_factorization_monoid`. -/
protected def normalization_monoid : normalization_monoid α :=
normalization_monoid_of_monoid_hom_right_inverse {
to_fun := λ a : associates α, if a = 0 then 0 else ((factors a).map
(classical.some mk_surjective.has_right_inverse : associates α → α)).prod,
map_one' := by simp,
map_mul' := λ x y, by {
by_cases hx : x = 0, { simp [hx] },
by_cases hy : y = 0, { simp [hy] },
simp [hx, hy] } } begin
intro x,
dsimp,
by_cases hx : x = 0, { simp [hx] },
have h : associates.mk_monoid_hom ∘ (classical.some mk_surjective.has_right_inverse) =
(id : associates α → associates α),
{ ext x,
rw [function.comp_apply, mk_monoid_hom_apply,
classical.some_spec mk_surjective.has_right_inverse x],
refl },
rw [if_neg hx, ← mk_monoid_hom_apply, monoid_hom.map_multiset_prod, map_map, h, map_id,
← associated_iff_eq],
apply factors_prod hx
end
instance : inhabited (normalization_monoid α) := ⟨unique_factorization_monoid.normalization_monoid⟩
end unique_factorization_monoid
namespace unique_factorization_monoid
variables {R : Type*} [comm_cancel_monoid_with_zero R] [unique_factorization_monoid R]
lemma no_factors_of_no_prime_factors {a b : R} (ha : a ≠ 0)
(h : (∀ {d}, d ∣ a → d ∣ b → ¬ prime d)) : ∀ {d}, d ∣ a → d ∣ b → is_unit d :=
λ d, induction_on_prime d
(by { simp only [zero_dvd_iff], intros, contradiction })
(λ x hx _ _, hx)
(λ d q hp hq ih dvd_a dvd_b,
absurd hq (h (dvd_of_mul_right_dvd dvd_a) (dvd_of_mul_right_dvd dvd_b)))
/-- Euclid's lemma: if `a ∣ b * c` and `a` and `c` have no common prime factors, `a ∣ b`.
Compare `is_coprime.dvd_of_dvd_mul_left`. -/
lemma dvd_of_dvd_mul_left_of_no_prime_factors {a b c : R} (ha : a ≠ 0) :
(∀ {d}, d ∣ a → d ∣ c → ¬ prime d) → a ∣ b * c → a ∣ b :=
begin
refine induction_on_prime c _ _ _,
{ intro no_factors,
simp only [dvd_zero, mul_zero, forall_prop_of_true],
haveI := classical.prop_decidable,
exact is_unit_iff_forall_dvd.mp
(no_factors_of_no_prime_factors ha @no_factors (dvd_refl a) (dvd_zero a)) _ },
{ rintros _ ⟨x, rfl⟩ _ a_dvd_bx,
apply units.dvd_mul_right.mp a_dvd_bx },
{ intros c p hc hp ih no_factors a_dvd_bpc,
apply ih (λ q dvd_a dvd_c hq, no_factors dvd_a (dvd_c.mul_left _) hq),
rw mul_left_comm at a_dvd_bpc,
refine or.resolve_left (hp.left_dvd_or_dvd_right_of_dvd_mul a_dvd_bpc) (λ h, _),
exact no_factors h (dvd_mul_right p c) hp }
end
/-- Euclid's lemma: if `a ∣ b * c` and `a` and `b` have no common prime factors, `a ∣ c`.
Compare `is_coprime.dvd_of_dvd_mul_right`. -/
lemma dvd_of_dvd_mul_right_of_no_prime_factors {a b c : R} (ha : a ≠ 0)
(no_factors : ∀ {d}, d ∣ a → d ∣ b → ¬ prime d) : a ∣ b * c → a ∣ c :=
by simpa [mul_comm b c] using dvd_of_dvd_mul_left_of_no_prime_factors ha @no_factors
/-- If `a ≠ 0, b` are elements of a unique factorization domain, then dividing
out their common factor `c'` gives `a'` and `b'` with no factors in common. -/
lemma exists_reduced_factors : ∀ (a ≠ (0 : R)) b,
∃ a' b' c', (∀ {d}, d ∣ a' → d ∣ b' → is_unit d) ∧ c' * a' = a ∧ c' * b' = b :=
begin
haveI := classical.prop_decidable,
intros a,
refine induction_on_prime a _ _ _,
{ intros, contradiction },
{ intros a a_unit a_ne_zero b,
use [a, b, 1],
split,
{ intros p p_dvd_a _,
exact is_unit_of_dvd_unit p_dvd_a a_unit },
{ simp } },
{ intros a p a_ne_zero p_prime ih_a pa_ne_zero b,
by_cases p ∣ b,
{ rcases h with ⟨b, rfl⟩,
obtain ⟨a', b', c', no_factor, ha', hb'⟩ := ih_a a_ne_zero b,
refine ⟨a', b', p * c', @no_factor, _, _⟩,
{ rw [mul_assoc, ha'] },
{ rw [mul_assoc, hb'] } },
{ obtain ⟨a', b', c', coprime, rfl, rfl⟩ := ih_a a_ne_zero b,
refine ⟨p * a', b', c', _, mul_left_comm _ _ _, rfl⟩,
intros q q_dvd_pa' q_dvd_b',
cases p_prime.left_dvd_or_dvd_right_of_dvd_mul q_dvd_pa' with p_dvd_q q_dvd_a',
{ have : p ∣ c' * b' := dvd_mul_of_dvd_right (p_dvd_q.trans q_dvd_b') _,
contradiction },
exact coprime q_dvd_a' q_dvd_b' } }
end
lemma exists_reduced_factors' (a b : R) (hb : b ≠ 0) :
∃ a' b' c', (∀ {d}, d ∣ a' → d ∣ b' → is_unit d) ∧ c' * a' = a ∧ c' * b' = b :=
let ⟨b', a', c', no_factor, hb, ha⟩ := exists_reduced_factors b hb a
in ⟨a', b', c', λ _ hpb hpa, no_factor hpa hpb, ha, hb⟩
section multiplicity
variables [nontrivial R] [normalization_monoid R] [decidable_eq R]
variables [decidable_rel (has_dvd.dvd : R → R → Prop)]
open multiplicity multiset
lemma le_multiplicity_iff_repeat_le_factors {a b : R} {n : ℕ} (ha : irreducible a) (hb : b ≠ 0) :
↑n ≤ multiplicity a b ↔ repeat (normalize a) n ≤ factors b :=
begin
rw ← pow_dvd_iff_le_multiplicity,
revert b,
induction n with n ih, { simp },
intros b hb,
split,
{ rintro ⟨c, rfl⟩,
rw [ne.def, pow_succ, mul_assoc, mul_eq_zero, decidable.not_or_iff_and_not] at hb,
rw [pow_succ, mul_assoc, factors_mul hb.1 hb.2, repeat_succ, factors_irreducible ha,
singleton_add, cons_le_cons_iff, ← ih hb.2],
apply dvd.intro _ rfl },
{ rw [multiset.le_iff_exists_add],
rintro ⟨u, hu⟩,
rw [← (factors_prod hb).dvd_iff_dvd_right, hu, prod_add, prod_repeat],
exact (associated.pow_pow $ associated_normalize a).dvd.trans (dvd.intro u.prod rfl) }
end
lemma multiplicity_eq_count_factors {a b : R} (ha : irreducible a) (hb : b ≠ 0) :
multiplicity a b = (factors b).count (normalize a) :=
begin
apply le_antisymm,
{ apply enat.le_of_lt_add_one,
rw [← nat.cast_one, ← nat.cast_add, lt_iff_not_ge, ge_iff_le,
le_multiplicity_iff_repeat_le_factors ha hb, ← le_count_iff_repeat_le],
simp },
rw [le_multiplicity_iff_repeat_le_factors ha hb, ← le_count_iff_repeat_le],
end
end multiplicity
end unique_factorization_monoid
namespace associates
open unique_factorization_monoid associated multiset
variables [comm_cancel_monoid_with_zero α]
/-- `factor_set α` representation elements of unique factorization domain as multisets.
`multiset α` produced by `factors` are only unique up to associated elements, while the multisets in
`factor_set α` are unqiue by equality and restricted to irreducible elements. This gives us a
representation of each element as a unique multisets (or the added ⊤ for 0), which has a complete
lattice struture. Infimum is the greatest common divisor and supremum is the least common multiple.
-/
@[reducible] def {u} factor_set (α : Type u) [comm_cancel_monoid_with_zero α] :
Type u :=
with_top (multiset { a : associates α // irreducible a })
local attribute [instance] associated.setoid
theorem factor_set.coe_add {a b : multiset { a : associates α // irreducible a }} :
(↑(a + b) : factor_set α) = a + b :=
by norm_cast
lemma factor_set.sup_add_inf_eq_add [decidable_eq (associates α)] :
∀(a b : factor_set α), a ⊔ b + a ⊓ b = a + b
| none b := show ⊤ ⊔ b + ⊤ ⊓ b = ⊤ + b, by simp
| a none := show a ⊔ ⊤ + a ⊓ ⊤ = a + ⊤, by simp
| (some a) (some b) := show (a : factor_set α) ⊔ b + a ⊓ b = a + b, from
begin
rw [← with_top.coe_sup, ← with_top.coe_inf, ← with_top.coe_add, ← with_top.coe_add,
with_top.coe_eq_coe],
exact multiset.union_add_inter _ _
end
/-- Evaluates the product of a `factor_set` to be the product of the corresponding multiset,
or `0` if there is none. -/
def factor_set.prod : factor_set α → associates α
| none := 0
| (some s) := (s.map coe).prod
@[simp] theorem prod_top : (⊤ : factor_set α).prod = 0 := rfl
@[simp] theorem prod_coe {s : multiset { a : associates α // irreducible a }} :
(s : factor_set α).prod = (s.map coe).prod :=
rfl
@[simp] theorem prod_add : ∀(a b : factor_set α), (a + b).prod = a.prod * b.prod
| none b := show (⊤ + b).prod = (⊤:factor_set α).prod * b.prod, by simp
| a none := show (a + ⊤).prod = a.prod * (⊤:factor_set α).prod, by simp
| (some a) (some b) :=
show (↑a + ↑b:factor_set α).prod = (↑a:factor_set α).prod * (↑b:factor_set α).prod,
by rw [← factor_set.coe_add, prod_coe, prod_coe, prod_coe, multiset.map_add, multiset.prod_add]
theorem prod_mono : ∀{a b : factor_set α}, a ≤ b → a.prod ≤ b.prod
| none b h := have b = ⊤, from top_unique h, by rw [this, prod_top]; exact le_refl _
| a none h := show a.prod ≤ (⊤ : factor_set α).prod, by simp; exact le_top
| (some a) (some b) h := prod_le_prod $ multiset.map_le_map $ with_top.coe_le_coe.1 $ h
/-- `bcount p s` is the multiplicity of `p` in the factor_set `s` (with bundled `p`)-/
def bcount [decidable_eq (associates α)] (p : {a : associates α // irreducible a}) :
factor_set α → ℕ
| none := 0
| (some s) := s.count p
variables [dec_irr : Π (p : associates α), decidable (irreducible p)]
include dec_irr
/-- `count p s` is the multiplicity of the irreducible `p` in the factor_set `s`.
If `p` is not irreducible, `count p s` is defined to be `0`. -/
def count [decidable_eq (associates α)] (p : associates α) :
factor_set α → ℕ :=
if hp : irreducible p then bcount ⟨p, hp⟩ else 0
@[simp] lemma count_some [decidable_eq (associates α)] {p : associates α} (hp : irreducible p)
(s : multiset _) : count p (some s) = s.count ⟨p, hp⟩:=
by { dunfold count, split_ifs, refl }
@[simp] lemma count_zero [decidable_eq (associates α)] {p : associates α} (hp : irreducible p) :
count p (0 : factor_set α) = 0 :=
by { dunfold count, split_ifs, refl }
lemma count_reducible [decidable_eq (associates α)] {p : associates α} (hp : ¬ irreducible p) :
count p = 0 := dif_neg hp
omit dec_irr
/-- membership in a factor_set (bundled version) -/
def bfactor_set_mem : {a : associates α // irreducible a} → (factor_set α) → Prop
| _ ⊤ := true
| p (some l) := p ∈ l
include dec_irr
/-- `factor_set_mem p s` is the predicate that the irreducible `p` is a member of
`s : factor_set α`.
If `p` is not irreducible, `p` is not a member of any `factor_set`. -/
def factor_set_mem (p : associates α) (s : factor_set α) : Prop :=
if hp : irreducible p then bfactor_set_mem ⟨p, hp⟩ s else false
instance : has_mem (associates α) (factor_set α) := ⟨factor_set_mem⟩
@[simp] lemma factor_set_mem_eq_mem (p : associates α) (s : factor_set α) :
factor_set_mem p s = (p ∈ s) := rfl
lemma mem_factor_set_top {p : associates α} {hp : irreducible p} :
p ∈ (⊤ : factor_set α) :=
begin
dunfold has_mem.mem, dunfold factor_set_mem, split_ifs, exact trivial
end
lemma mem_factor_set_some {p : associates α} {hp : irreducible p}
{l : multiset {a : associates α // irreducible a }} :
p ∈ (l : factor_set α) ↔ subtype.mk p hp ∈ l :=
begin
dunfold has_mem.mem, dunfold factor_set_mem, split_ifs, refl
end
lemma reducible_not_mem_factor_set {p : associates α} (hp : ¬ irreducible p)
(s : factor_set α) : ¬ p ∈ s :=
λ (h : if hp : irreducible p then bfactor_set_mem ⟨p, hp⟩ s else false),
by rwa [dif_neg hp] at h
omit dec_irr
variable [unique_factorization_monoid α]
theorem unique' {p q : multiset (associates α)} :
(∀a∈p, irreducible a) → (∀a∈q, irreducible a) → p.prod = q.prod → p = q :=
begin
apply multiset.induction_on_multiset_quot p,
apply multiset.induction_on_multiset_quot q,
assume s t hs ht eq,
refine multiset.map_mk_eq_map_mk_of_rel (unique_factorization_monoid.factors_unique _ _ _),
{ exact assume a ha, ((irreducible_mk _).1 $ hs _ $ multiset.mem_map_of_mem _ ha) },
{ exact assume a ha, ((irreducible_mk _).1 $ ht _ $ multiset.mem_map_of_mem _ ha) },
simpa [quot_mk_eq_mk, prod_mk, mk_eq_mk_iff_associated] using eq
end
variables [nontrivial α] [normalization_monoid α]
private theorem forall_map_mk_factors_irreducible [decidable_eq α] (x : α) (hx : x ≠ 0) :
∀(a : associates α), a ∈ multiset.map associates.mk (factors x) → irreducible a :=
begin
assume a ha,
rcases multiset.mem_map.1 ha with ⟨c, hc, rfl⟩,
exact (irreducible_mk c).2 (irreducible_of_factor _ hc)
end
theorem prod_le_prod_iff_le {p q : multiset (associates α)}
(hp : ∀a∈p, irreducible a) (hq : ∀a∈q, irreducible a) :
p.prod ≤ q.prod ↔ p ≤ q :=
iff.intro
begin
classical,
rintros ⟨⟨c⟩, eqc⟩,
have : c ≠ 0, from (mt mk_eq_zero.2 $
assume (hc : quot.mk setoid.r c = 0),
have (0 : associates α) ∈ q, from prod_eq_zero_iff.1 $ eqc.symm ▸ hc.symm ▸ mul_zero _,
not_irreducible_zero ((irreducible_mk 0).1 $ hq _ this)),
have : associates.mk (factors c).prod = quot.mk setoid.r c,
from mk_eq_mk_iff_associated.2 (factors_prod this),
refine multiset.le_iff_exists_add.2 ⟨(factors c).map associates.mk, unique' hq _ _⟩,
{ assume x hx,
rcases multiset.mem_add.1 hx with h | h,
exact hp x h,
exact forall_map_mk_factors_irreducible c ‹c ≠ 0› _ h },
{ simp [multiset.prod_add, prod_mk, *] at * }
end
prod_le_prod
variables [dec : decidable_eq α] [dec' : decidable_eq (associates α)]
include dec
/-- This returns the multiset of irreducible factors as a `factor_set`,
a multiset of irreducible associates `with_top`. -/
noncomputable def factors' (a : α) :
multiset { a : associates α // irreducible a } :=
(factors a).pmap (λa ha, ⟨associates.mk a, (irreducible_mk _).2 ha⟩)
(irreducible_of_factor)
@[simp] theorem map_subtype_coe_factors' {a : α} :
(factors' a).map coe = (factors a).map associates.mk :=
by simp [factors', multiset.map_pmap, multiset.pmap_eq_map]
theorem factors'_cong {a b : α} (ha : a ≠ 0) (hb : b ≠ 0) (h : a ~ᵤ b) :
factors' a = factors' b :=
have multiset.rel associated (factors a) (factors b), from
factors_unique irreducible_of_factor irreducible_of_factor
((factors_prod ha).trans $ h.trans $ (factors_prod hb).symm),
by simpa [(multiset.map_eq_map subtype.coe_injective).symm, rel_associated_iff_map_eq_map.symm]
include dec'
/-- This returns the multiset of irreducible factors of an associate as a `factor_set`,
a multiset of irreducible associates `with_top`. -/
noncomputable def factors (a : associates α) :
factor_set α :=
begin
refine (if h : a = 0 then ⊤ else
quotient.hrec_on a (λx h, some $ factors' x) _ h),
assume a b hab,
apply function.hfunext,
{ have : a ~ᵤ 0 ↔ b ~ᵤ 0, from
iff.intro (assume ha0, hab.symm.trans ha0) (assume hb0, hab.trans hb0),
simp only [associated_zero_iff_eq_zero] at this,
simp only [quotient_mk_eq_mk, this, mk_eq_zero] },
exact (assume ha hb eq, heq_of_eq $ congr_arg some $ factors'_cong
(λ c, ha (mk_eq_zero.2 c)) (λ c, hb (mk_eq_zero.2 c)) hab)
end
@[simp] theorem factors_0 : (0 : associates α).factors = ⊤ :=
dif_pos rfl
@[simp] theorem factors_mk (a : α) (h : a ≠ 0) :
(associates.mk a).factors = factors' a :=
by { classical, apply dif_neg, apply (mt mk_eq_zero.1 h) }
theorem prod_factors : ∀(s : factor_set α), s.prod.factors = s
| none := by simp [factor_set.prod]; refl
| (some s) :=
begin
unfold factor_set.prod,
generalize eq_a : (s.map coe).prod = a,
rcases a with ⟨a⟩,
rw quot_mk_eq_mk at *,
have : (s.map (coe : _ → associates α)).prod ≠ 0, from assume ha,
let ⟨⟨a, ha⟩, h, eq⟩ := multiset.mem_map.1 (prod_eq_zero_iff.1 ha) in
have irreducible (0 : associates α), from eq ▸ ha,
not_irreducible_zero ((irreducible_mk _).1 this),
have ha : a ≠ 0, by simp [*] at *,
suffices : (unique_factorization_monoid.factors a).map associates.mk = s.map coe,
{ rw [factors_mk a ha],
apply congr_arg some _,
simpa [(multiset.map_eq_map subtype.coe_injective).symm] },
refine unique'
(forall_map_mk_factors_irreducible _ ha)
(assume a ha, let ⟨⟨x, hx⟩, ha, eq⟩ := multiset.mem_map.1 ha in eq ▸ hx)
_,
rw [prod_mk, eq_a, mk_eq_mk_iff_associated],
exact factors_prod ha
end
@[simp]
theorem factors_prod (a : associates α) : a.factors.prod = a :=
quotient.induction_on a $ assume a, decidable.by_cases
(assume : associates.mk a = 0, by simp [quotient_mk_eq_mk, this])
(assume : associates.mk a ≠ 0,
have a ≠ 0, by simp * at *,
by simp [this, quotient_mk_eq_mk, prod_mk, mk_eq_mk_iff_associated.2 (factors_prod this)])
theorem eq_of_factors_eq_factors {a b : associates α} (h : a.factors = b.factors) : a = b :=
have a.factors.prod = b.factors.prod, by rw h,
by rwa [factors_prod, factors_prod] at this
omit dec dec'
theorem eq_of_prod_eq_prod {a b : factor_set α} (h : a.prod = b.prod) : a = b :=
begin
classical,
have : a.prod.factors = b.prod.factors, by rw h,
rwa [prod_factors, prod_factors] at this
end
include dec dec'
@[simp] theorem factors_mul (a b : associates α) : (a * b).factors = a.factors + b.factors :=
eq_of_prod_eq_prod $ eq_of_factors_eq_factors $
by rw [prod_add, factors_prod, factors_prod, factors_prod]
theorem factors_mono : ∀{a b : associates α}, a ≤ b → a.factors ≤ b.factors
| s t ⟨d, rfl⟩ := by rw [factors_mul] ; exact le_add_of_nonneg_right bot_le
theorem factors_le {a b : associates α} : a.factors ≤ b.factors ↔ a ≤ b :=
iff.intro
(assume h, have a.factors.prod ≤ b.factors.prod, from prod_mono h,
by rwa [factors_prod, factors_prod] at this)
factors_mono
omit dec dec'
theorem prod_le {a b : factor_set α} : a.prod ≤ b.prod ↔ a ≤ b :=
begin
classical,
exact iff.intro
(assume h, have a.prod.factors ≤ b.prod.factors, from factors_mono h,
by rwa [prod_factors, prod_factors] at this)
prod_mono
end
include dec dec'
noncomputable instance : has_sup (associates α) := ⟨λa b, (a.factors ⊔ b.factors).prod⟩
noncomputable instance : has_inf (associates α) := ⟨λa b, (a.factors ⊓ b.factors).prod⟩
noncomputable instance : bounded_lattice (associates α) :=
{ sup := (⊔),
inf := (⊓),
sup_le :=
assume a b c hac hbc, factors_prod c ▸ prod_mono (sup_le (factors_mono hac) (factors_mono hbc)),
le_sup_left := assume a b,
le_trans (le_of_eq (factors_prod a).symm) $ prod_mono $ le_sup_left,
le_sup_right := assume a b,
le_trans (le_of_eq (factors_prod b).symm) $ prod_mono $ le_sup_right,
le_inf :=
assume a b c hac hbc, factors_prod a ▸ prod_mono (le_inf (factors_mono hac) (factors_mono hbc)),
inf_le_left := assume a b,
le_trans (prod_mono inf_le_left) (le_of_eq (factors_prod a)),
inf_le_right := assume a b,
le_trans (prod_mono inf_le_right) (le_of_eq (factors_prod b)),
.. associates.partial_order,
.. associates.order_top,
.. associates.order_bot }
lemma sup_mul_inf (a b : associates α) : (a ⊔ b) * (a ⊓ b) = a * b :=
show (a.factors ⊔ b.factors).prod * (a.factors ⊓ b.factors).prod = a * b,
begin
refine eq_of_factors_eq_factors _,
rw [← prod_add, prod_factors, factors_mul, factor_set.sup_add_inf_eq_add]
end
include dec_irr
lemma dvd_of_mem_factors {a p : associates α} {hp : irreducible p}
(hm : p ∈ factors a) : p ∣ a :=
begin
by_cases ha0 : a = 0, { rw ha0, exact dvd_zero p },
obtain ⟨a0, nza, ha'⟩ := exists_non_zero_rep ha0,
rw [← associates.factors_prod a],
rw [← ha', factors_mk a0 nza] at hm ⊢,
erw prod_coe,
apply multiset.dvd_prod, apply multiset.mem_map.mpr,
exact ⟨⟨p, hp⟩, mem_factor_set_some.mp hm, rfl⟩
end
omit dec'
lemma dvd_of_mem_factors' {a : α} {p : associates α} {hp : irreducible p} {hz : a ≠ 0}
(h_mem : subtype.mk p hp ∈ factors' a) : p ∣ associates.mk a :=
by { haveI := classical.dec_eq (associates α),
apply @dvd_of_mem_factors _ _ _ _ _ _ _ _ _ _ hp,
rw factors_mk _ hz,
apply mem_factor_set_some.2 h_mem }
omit dec_irr
lemma mem_factors'_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : irreducible p) (hd : p ∣ a) :
subtype.mk (associates.mk p) ((irreducible_mk _).2 hp) ∈ factors' a :=
begin
obtain ⟨q, hq, hpq⟩ := exists_mem_factors_of_dvd ha0 hp hd,
apply multiset.mem_pmap.mpr, use q, use hq,
exact subtype.eq (eq.symm (mk_eq_mk_iff_associated.mpr hpq))
end
include dec_irr
lemma mem_factors'_iff_dvd {a p : α} (ha0 : a ≠ 0) (hp : irreducible p) :
subtype.mk (associates.mk p) ((irreducible_mk _).2 hp) ∈ factors' a ↔ p ∣ a :=
begin
split,
{ rw ← mk_dvd_mk, apply dvd_of_mem_factors', apply ha0 },
{ apply mem_factors'_of_dvd ha0 }
end
include dec'
lemma mem_factors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : irreducible p) (hd : p ∣ a) :
(associates.mk p) ∈ factors (associates.mk a) :=
begin
rw factors_mk _ ha0, exact mem_factor_set_some.mpr (mem_factors'_of_dvd ha0 hp hd)
end
lemma mem_factors_iff_dvd {a p : α} (ha0 : a ≠ 0) (hp : irreducible p) :
(associates.mk p) ∈ factors (associates.mk a) ↔ p ∣ a :=
begin
split,
{ rw ← mk_dvd_mk, apply dvd_of_mem_factors, exact (irreducible_mk p).mpr hp },
{ apply mem_factors_of_dvd ha0 hp }
end
lemma exists_prime_dvd_of_not_inf_one {a b : α}
(ha : a ≠ 0) (hb : b ≠ 0) (h : (associates.mk a) ⊓ (associates.mk b) ≠ 1) :
∃ (p : α), prime p ∧ p ∣ a ∧ p ∣ b :=
begin
have hz : (factors (associates.mk a)) ⊓ (factors (associates.mk b)) ≠ 0,
{ contrapose! h with hf,
change ((factors (associates.mk a)) ⊓ (factors (associates.mk b))).prod = 1,
rw hf,
exact multiset.prod_zero },
rw [factors_mk a ha, factors_mk b hb, ← with_top.coe_inf] at hz,
obtain ⟨⟨p0, p0_irr⟩, p0_mem⟩ := multiset.exists_mem_of_ne_zero ((mt with_top.coe_eq_coe.mpr) hz),
rw multiset.inf_eq_inter at p0_mem,
obtain ⟨p, rfl⟩ : ∃ p, associates.mk p = p0 := quot.exists_rep p0,
refine ⟨p, _, _, _⟩,
{ rw [← irreducible_iff_prime, ← irreducible_mk],
exact p0_irr },
{ apply dvd_of_mk_le_mk,
apply dvd_of_mem_factors' (multiset.mem_inter.mp p0_mem).left,
apply ha, },
{ apply dvd_of_mk_le_mk,
apply dvd_of_mem_factors' (multiset.mem_inter.mp p0_mem).right,
apply hb }
end
theorem coprime_iff_inf_one {a b : α} (ha0 : a ≠ 0) (hb0 : b ≠ 0) :
(associates.mk a) ⊓ (associates.mk b) = 1 ↔ ∀ {d : α}, d ∣ a → d ∣ b → ¬ prime d :=
begin
split,
{ intros hg p ha hb hp,
refine ((associates.prime_mk _).mpr hp).not_unit (is_unit_of_dvd_one _ _),
rw ← hg,
exact le_inf (mk_le_mk_of_dvd ha) (mk_le_mk_of_dvd hb) },
{ contrapose,
intros hg hc,
obtain ⟨p, hp, hpa, hpb⟩ := exists_prime_dvd_of_not_inf_one ha0 hb0 hg,
exact hc hpa hpb hp }
end
omit dec_irr
theorem factors_prime_pow {p : associates α} (hp : irreducible p)
(k : ℕ) : factors (p ^ k) = some (multiset.repeat ⟨p, hp⟩ k) :=
eq_of_prod_eq_prod (by rw [associates.factors_prod, factor_set.prod, multiset.map_repeat,
multiset.prod_repeat, subtype.coe_mk])
include dec_irr
theorem prime_pow_dvd_iff_le {m p : associates α} (h₁ : m ≠ 0)
(h₂ : irreducible p) {k : ℕ} : p ^ k ≤ m ↔ k ≤ count p m.factors :=
begin
obtain ⟨a, nz, rfl⟩ := associates.exists_non_zero_rep h₁,
rw [factors_mk _ nz, ← with_top.some_eq_coe, count_some, multiset.le_count_iff_repeat_le,
← factors_le, factors_prime_pow h₂, factors_mk _ nz],
exact with_top.coe_le_coe
end
theorem le_of_count_ne_zero {m p : associates α} (h0 : m ≠ 0)
(hp : irreducible p) : count p m.factors ≠ 0 → p ≤ m :=
begin
rw [← pos_iff_ne_zero],
intro h,
rw [← pow_one p],
apply (prime_pow_dvd_iff_le h0 hp).2,
simpa only
end
theorem count_mul {a : associates α} (ha : a ≠ 0) {b : associates α} (hb : b ≠ 0)
{p : associates α} (hp : irreducible p) :
count p (factors (a * b)) = count p a.factors + count p b.factors :=
begin
obtain ⟨a0, nza, ha'⟩ := exists_non_zero_rep ha,
obtain ⟨b0, nzb, hb'⟩ := exists_non_zero_rep hb,
rw [factors_mul, ← ha', ← hb', factors_mk a0 nza, factors_mk b0 nzb, ← factor_set.coe_add,
← with_top.some_eq_coe, ← with_top.some_eq_coe, ← with_top.some_eq_coe, count_some hp,
multiset.count_add, count_some hp, count_some hp]
end
theorem count_of_coprime {a : associates α} (ha : a ≠ 0) {b : associates α} (hb : b ≠ 0)
(hab : ∀ d, d ∣ a → d ∣ b → ¬ prime d) {p : associates α} (hp : irreducible p) :
count p a.factors = 0 ∨ count p b.factors = 0 :=
begin
rw [or_iff_not_imp_left, ← ne.def],
intro hca,
contrapose! hab with hcb,
exact ⟨p, le_of_count_ne_zero ha hp hca, le_of_count_ne_zero hb hp hcb,
(irreducible_iff_prime.mp hp)⟩,
end
theorem count_mul_of_coprime {a : associates α} (ha : a ≠ 0) {b : associates α} (hb : b ≠ 0)
{p : associates α} (hp : irreducible p) (hab : ∀ d, d ∣ a → d ∣ b → ¬ prime d) :
count p a.factors = 0 ∨ count p a.factors = count p (a * b).factors :=
begin
cases count_of_coprime ha hb hab hp with hz hb0, { tauto },
apply or.intro_right,
rw [count_mul ha hb hp, hb0, add_zero]
end
theorem count_mul_of_coprime' {a : associates α} (ha : a ≠ 0) {b : associates α} (hb : b ≠ 0)
{p : associates α} (hp : irreducible p) (hab : ∀ d, d ∣ a → d ∣ b → ¬ prime d) :
count p (a * b).factors = count p a.factors
∨ count p (a * b).factors = count p b.factors :=
begin
rw [count_mul ha hb hp],
cases count_of_coprime ha hb hab hp with ha0 hb0,
{ apply or.intro_right, rw [ha0, zero_add] },
{ apply or.intro_left, rw [hb0, add_zero] }
end
theorem dvd_count_of_dvd_count_mul {a b : associates α} (ha : a ≠ 0) (hb : b ≠ 0)
{p : associates α} (hp : irreducible p) (hab : ∀ d, d ∣ a → d ∣ b → ¬ prime d)
{k : ℕ} (habk : k ∣ count p (a * b).factors) : k ∣ count p a.factors :=
begin
cases count_of_coprime ha hb hab hp with hz h,
{ rw hz, exact dvd_zero k },
{ rw [count_mul ha hb hp, h] at habk, exact habk }
end
omit dec_irr
@[simp] lemma factors_one : factors (1 : associates α) = 0 :=
begin
apply eq_of_prod_eq_prod,
rw associates.factors_prod,
exact multiset.prod_zero,
end
@[simp] theorem pow_factors {a : associates α} {k : ℕ} : (a ^ k).factors = k • a.factors :=
begin
induction k with n h,
{ rw [zero_nsmul, pow_zero], exact factors_one },
{ rw [pow_succ, succ_nsmul, factors_mul, h] }
end
include dec_irr
lemma count_pow {a : associates α} (ha : a ≠ 0) {p : associates α} (hp : irreducible p)
(k : ℕ) : count p (a ^ k).factors = k * count p a.factors :=
begin
induction k with n h,
{ rw [pow_zero, factors_one, zero_mul, count_zero hp] },
{ rw [pow_succ, count_mul ha (pow_ne_zero _ ha) hp, h, nat.succ_eq_add_one], ring }
end
theorem dvd_count_pow {a : associates α} (ha : a ≠ 0) {p : associates α} (hp : irreducible p)
(k : ℕ) : k ∣ count p (a ^ k).factors := by { rw count_pow ha hp, apply dvd_mul_right }
theorem is_pow_of_dvd_count {a : associates α} (ha : a ≠ 0) {k : ℕ}
(hk : ∀ (p : associates α) (hp : irreducible p), k ∣ count p a.factors) :
∃ (b : associates α), a = b ^ k :=
begin
obtain ⟨a0, hz, rfl⟩ := exists_non_zero_rep ha,
rw [factors_mk a0 hz] at hk,
have hk' : ∀ p, p ∈ (factors' a0) → k ∣ (factors' a0).count p,
{ rintros p -,
have pp : p = ⟨p.val, p.2⟩, { simp only [subtype.coe_eta, subtype.val_eq_coe] },
rw [pp, ← count_some p.2], exact hk p.val p.2 },
obtain ⟨u, hu⟩ := multiset.exists_smul_of_dvd_count _ hk',
use (u : factor_set α).prod,
apply eq_of_factors_eq_factors,
rw [pow_factors, prod_factors, factors_mk a0 hz, ← with_top.some_eq_coe, hu],
exact with_bot.coe_nsmul u k
end
omit dec
omit dec_irr
omit dec'
theorem eq_pow_of_mul_eq_pow {a b c : associates α} (ha : a ≠ 0) (hb : b ≠ 0)
(hab : ∀ d, d ∣ a → d ∣ b → ¬ prime d) {k : ℕ} (h : a * b = c ^ k) :
∃ (d : associates α), a = d ^ k :=
begin
classical,
by_cases hk0 : k = 0,
{ use 1,
rw [hk0, pow_zero] at h ⊢,
apply (mul_eq_one_iff.1 h).1 },
{ refine is_pow_of_dvd_count ha _,
intros p hp,
apply dvd_count_of_dvd_count_mul ha hb hp hab,
rw h,
apply dvd_count_pow _ hp,
rintros rfl,
rw zero_pow' _ hk0 at h,
cases mul_eq_zero.mp h; contradiction }
end
end associates
section
open associates unique_factorization_monoid
/-- `to_gcd_monoid` constructs a GCD monoid out of a normalization on a
unique factorization domain. -/
noncomputable def unique_factorization_monoid.to_gcd_monoid
(α : Type*) [comm_cancel_monoid_with_zero α] [nontrivial α] [unique_factorization_monoid α]
[normalization_monoid α] [decidable_eq (associates α)] [decidable_eq α] : gcd_monoid α :=
{ gcd := λa b, (associates.mk a ⊓ associates.mk b).out,
lcm := λa b, (associates.mk a ⊔ associates.mk b).out,
gcd_dvd_left := assume a b, (out_dvd_iff a (associates.mk a ⊓ associates.mk b)).2 $ inf_le_left,
gcd_dvd_right := assume a b, (out_dvd_iff b (associates.mk a ⊓ associates.mk b)).2 $ inf_le_right,
dvd_gcd := assume a b c hac hab, show a ∣ (associates.mk c ⊓ associates.mk b).out,
by rw [dvd_out_iff, le_inf_iff, mk_le_mk_iff_dvd_iff, mk_le_mk_iff_dvd_iff]; exact ⟨hac, hab⟩,
lcm_zero_left := assume a, show (⊤ ⊔ associates.mk a).out = 0, by simp,
lcm_zero_right := assume a, show (associates.mk a ⊔ ⊤).out = 0, by simp,
gcd_mul_lcm := assume a b,
show (associates.mk a ⊓ associates.mk b).out * (associates.mk a ⊔ associates.mk b).out =
normalize (a * b),
by rw [← out_mk, ← out_mul, mul_comm, sup_mul_inf]; refl,
normalize_gcd := assume a b, by convert normalize_out _,
.. ‹normalization_monoid α› }
end
namespace unique_factorization_monoid
/-- If `y` is a nonzero element of a unique factorization monoid with finitely
many units (e.g. `ℤ`, `ideal (ring_of_integers K)`), it has finitely many divisors. -/
noncomputable def fintype_subtype_dvd {M : Type*} [comm_cancel_monoid_with_zero M]
[unique_factorization_monoid M] [fintype (units M)]
(y : M) (hy : y ≠ 0) :
fintype {x // x ∣ y} :=
begin
haveI : nontrivial M := ⟨⟨y, 0, hy⟩⟩,
haveI : normalization_monoid M := unique_factorization_monoid.normalization_monoid,
haveI := classical.dec_eq M,
haveI := classical.dec_eq (associates M),
-- We'll show `λ (u : units M) (f ⊆ factors y) → u * Π f` is injective
-- and has image exactly the divisors of `y`.
refine fintype.of_finset
(((factors y).powerset.to_finset.product (finset.univ : finset (units M))).image
(λ s, (s.snd : M) * s.fst.prod))
(λ x, _),
simp only [exists_prop, finset.mem_image, finset.mem_product, finset.mem_univ, and_true,
multiset.mem_to_finset, multiset.mem_powerset, exists_eq_right, multiset.mem_map],
split,
{ rintros ⟨s, hs, rfl⟩,
have prod_s_ne : s.fst.prod ≠ 0,
{ intro hz,
apply hy (eq_zero_of_zero_dvd _),
have hz := (@multiset.prod_eq_zero_iff M _ _ _ s.fst).mp hz,
rw ← (factors_prod hy).dvd_iff_dvd_right,
exact multiset.dvd_prod (multiset.mem_of_le hs hz) },
show (s.snd : M) * s.fst.prod ∣ y,
rw [(unit_associated_one.mul_right s.fst.prod).dvd_iff_dvd_left, one_mul,
← (factors_prod hy).dvd_iff_dvd_right],
exact multiset.prod_dvd_prod hs },
{ rintro (h : x ∣ y),
have hx : x ≠ 0, { refine mt (λ hx, _) hy, rwa [hx, zero_dvd_iff] at h },
obtain ⟨u, hu⟩ := factors_prod hx,
refine ⟨⟨factors x, u⟩, _, (mul_comm _ _).trans hu⟩,
exact (dvd_iff_factors_le_factors hx hy).mp h }
end
end unique_factorization_monoid
|
11b03b8fb91cb0809d6715bf43fd37e709ecf755 | 900ff83b8a995f83b07c2fa0715d52fa265c4b9e | /library/init/data/nat/bitwise.lean | 84055d70f26e840a59220b4e09227eb36f2ea752 | [
"Apache-2.0"
] | permissive | moritzbuhl/lean | b2ee98197f1c47255c647228c07c830b229ba766 | 89e98b56713c027afdf97ad96abd2d54b35a43d5 | refs/heads/master | 1,688,295,006,616 | 1,627,741,115,000 | 1,627,741,115,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,074 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
prelude
import init.data.nat.lemmas init.meta.well_founded_tactics
universe u
namespace nat
def bodd_div2 : ℕ → bool × ℕ
| 0 := (ff, 0)
| (succ n) :=
match bodd_div2 n with
| (ff, m) := (tt, m)
| (tt, m) := (ff, succ m)
end
def div2 (n : ℕ) : ℕ := (bodd_div2 n).2
def bodd (n : ℕ) : bool := (bodd_div2 n).1
@[simp] lemma bodd_zero : bodd 0 = ff := rfl
lemma bodd_one : bodd 1 = tt := rfl
lemma bodd_two : bodd 2 = ff := rfl
@[simp] lemma bodd_succ (n : ℕ) : bodd (succ n) = bnot (bodd n) :=
by unfold bodd bodd_div2; cases bodd_div2 n; cases fst; refl
@[simp] lemma bodd_add (m n : ℕ) : bodd (m + n) = bxor (bodd m) (bodd n) :=
begin
induction n with n IH,
{ simp, cases bodd m; refl },
{ simp [IH], cases bodd m; cases bodd n; refl }
end
@[simp] lemma bodd_mul (m n : ℕ) : bodd (m * n) = bodd m && bodd n :=
begin
induction n with n IH,
{ simp, cases bodd m; refl },
{ simp [mul_succ, IH], cases bodd m; cases bodd n; refl }
end
lemma mod_two_of_bodd (n : ℕ) : n % 2 = cond (bodd n) 1 0 :=
begin
have := congr_arg bodd (mod_add_div n 2),
simp [bnot] at this,
rw [show ∀ b, ff && b = ff, by intros; cases b; refl,
show ∀ b, bxor b ff = b, by intros; cases b; refl] at this,
rw [← this],
cases mod_two_eq_zero_or_one n with h h; rw h; refl
end
@[simp] lemma div2_zero : div2 0 = 0 := rfl
lemma div2_one : div2 1 = 0 := rfl
lemma div2_two : div2 2 = 1 := rfl
@[simp] lemma div2_succ (n : ℕ) : div2 (succ n) = cond (bodd n) (succ (div2 n)) (div2 n) :=
by unfold bodd div2 bodd_div2; cases bodd_div2 n; cases fst; refl
local attribute [simp] nat.add_comm nat.add_assoc nat.add_left_comm nat.mul_comm nat.mul_assoc
theorem bodd_add_div2 : ∀ n, cond (bodd n) 1 0 + 2 * div2 n = n
| 0 := rfl
| (succ n) := begin
simp,
refine eq.trans _ (congr_arg succ (bodd_add_div2 n)),
cases bodd n; simp [cond, bnot],
{ rw [nat.add_comm, nat.zero_add], },
{ rw [succ_mul, nat.add_comm 1, nat.zero_add] }
end
theorem div2_val (n) : div2 n = n / 2 :=
begin
refine nat.eq_of_mul_eq_mul_left dec_trivial
(nat.add_left_cancel (eq.trans _ (nat.mod_add_div n 2).symm)),
rw [mod_two_of_bodd, bodd_add_div2]
end
def bit (b : bool) : ℕ → ℕ := cond b bit1 bit0
lemma bit0_val (n : nat) : bit0 n = 2 * n :=
calc n + n = 0 + n + n : by rw nat.zero_add
... = n * 2 : rfl
... = 2 * n : nat.mul_comm _ _
lemma bit1_val (n : nat) : bit1 n = 2 * n + 1 := congr_arg succ (bit0_val _)
lemma bit_val (b n) : bit b n = 2 * n + cond b 1 0 :=
by { cases b, apply bit0_val, apply bit1_val }
lemma bit_decomp (n : nat) : bit (bodd n) (div2 n) = n :=
(bit_val _ _).trans $ (nat.add_comm _ _).trans $ bodd_add_div2 _
def bit_cases_on {C : nat → Sort u} (n) (h : ∀ b n, C (bit b n)) : C n :=
by rw [← bit_decomp n]; apply h
lemma bit_zero : bit ff 0 = 0 := rfl
def shiftl' (b : bool) (m : ℕ) : ℕ → ℕ
| 0 := m
| (n+1) := bit b (shiftl' n)
def shiftl : ℕ → ℕ → ℕ := shiftl' ff
@[simp] theorem shiftl_zero (m) : shiftl m 0 = m := rfl
@[simp] theorem shiftl_succ (m n) : shiftl m (n + 1) = bit0 (shiftl m n) := rfl
def shiftr : ℕ → ℕ → ℕ
| m 0 := m
| m (n+1) := div2 (shiftr m n)
def test_bit (m n : ℕ) : bool := bodd (shiftr m n)
def binary_rec {C : nat → Sort u} (z : C 0) (f : ∀ b n, C n → C (bit b n)) : Π n, C n
| n := if n0 : n = 0 then by rw n0; exact z else let n' := div2 n in
have n' < n, begin
change div2 n < n, rw div2_val,
apply (div_lt_iff_lt_mul _ _ (succ_pos 1)).2,
have := nat.mul_lt_mul_of_pos_left (lt_succ_self 1)
(lt_of_le_of_ne n.zero_le (ne.symm n0)),
rwa nat.mul_one at this
end,
by rw [← show bit (bodd n) n' = n, from bit_decomp n]; exact
f (bodd n) n' (binary_rec n')
def size : ℕ → ℕ := binary_rec 0 (λ_ _, succ)
def bits : ℕ → list bool := binary_rec [] (λb _ IH, b :: IH)
def bitwise (f : bool → bool → bool) : ℕ → ℕ → ℕ :=
binary_rec
(λn, cond (f ff tt) n 0)
(λa m Ia, binary_rec
(cond (f tt ff) (bit a m) 0)
(λb n _, bit (f a b) (Ia n)))
def lor : ℕ → ℕ → ℕ := bitwise bor
def land : ℕ → ℕ → ℕ := bitwise band
def ldiff : ℕ → ℕ → ℕ := bitwise (λ a b, a && bnot b)
def lxor : ℕ → ℕ → ℕ := bitwise bxor
@[simp] lemma binary_rec_zero {C : nat → Sort u} (z : C 0) (f : ∀ b n, C n → C (bit b n)) :
binary_rec z f 0 = z :=
by {rw [binary_rec], refl}
/- bitwise ops -/
lemma bodd_bit (b n) : bodd (bit b n) = b :=
by rw bit_val; simp; cases b; cases bodd n; refl
lemma div2_bit (b n) : div2 (bit b n) = n :=
by rw [bit_val, div2_val, nat.add_comm, add_mul_div_left, div_eq_of_lt, nat.zero_add];
cases b; exact dec_trivial
lemma shiftl'_add (b m n) : ∀ k, shiftl' b m (n + k) = shiftl' b (shiftl' b m n) k
| 0 := rfl
| (k+1) := congr_arg (bit b) (shiftl'_add k)
lemma shiftl_add : ∀ m n k, shiftl m (n + k) = shiftl (shiftl m n) k := shiftl'_add _
lemma shiftr_add (m n) : ∀ k, shiftr m (n + k) = shiftr (shiftr m n) k
| 0 := rfl
| (k+1) := congr_arg div2 (shiftr_add k)
lemma shiftl'_sub (b m) : ∀ {n k}, k ≤ n → shiftl' b m (n - k) = shiftr (shiftl' b m n) k
| n 0 h := rfl
| (n+1) (k+1) h := begin
simp [shiftl'], rw [nat.add_comm, shiftr_add],
simp [shiftr, div2_bit],
apply shiftl'_sub (nat.le_of_succ_le_succ h)
end
lemma shiftl_sub : ∀ m {n k}, k ≤ n → shiftl m (n - k) = shiftr (shiftl m n) k := shiftl'_sub _
@[simp] lemma test_bit_zero (b n) : test_bit (bit b n) 0 = b := bodd_bit _ _
lemma test_bit_succ (m b n) : test_bit (bit b n) (succ m) = test_bit n m :=
have bodd (shiftr (shiftr (bit b n) 1) m) = bodd (shiftr n m),
by dsimp [shiftr]; rw div2_bit,
by rw [← shiftr_add, nat.add_comm] at this; exact this
lemma binary_rec_eq {C : nat → Sort u} {z : C 0} {f : ∀ b n, C n → C (bit b n)}
(h : f ff 0 z = z) (b n) :
binary_rec z f (bit b n) = f b n (binary_rec z f n) :=
begin
rw [binary_rec],
with_cases { by_cases bit b n = 0 },
case pos : h' {
simp [dif_pos h'],
generalize : binary_rec._main._pack._proof_1 (bit b n) h' = e,
revert e,
have bf := bodd_bit b n,
have n0 := div2_bit b n,
rw h' at bf n0,
simp at bf n0,
rw [← bf, ← n0, binary_rec_zero],
intros, exact h.symm },
case neg : h' {
simp [dif_neg h'],
generalize : binary_rec._main._pack._proof_2 (bit b n) = e,
revert e,
rw [bodd_bit, div2_bit],
intros, refl}
end
lemma bitwise_bit_aux {f : bool → bool → bool} (h : f ff ff = ff) :
@binary_rec (λ_, ℕ)
(cond (f tt ff) (bit ff 0) 0)
(λ b n _, bit (f ff b) (cond (f ff tt) n 0)) =
λ (n : ℕ), cond (f ff tt) n 0 :=
begin
funext n,
apply bit_cases_on n, intros b n, rw [binary_rec_eq],
{ cases b; try {rw h}; induction fft : f ff tt; simp [cond]; refl },
{ rw [h, show cond (f ff tt) 0 0 = 0, by cases f ff tt; refl,
show cond (f tt ff) (bit ff 0) 0 = 0, by cases f tt ff; refl]; refl }
end
@[simp] lemma bitwise_zero_left (f : bool → bool → bool) (n) :
bitwise f 0 n = cond (f ff tt) n 0 :=
by unfold bitwise; rw [binary_rec_zero]
@[simp] lemma bitwise_zero_right (f : bool → bool → bool) (h : f ff ff = ff) (m) :
bitwise f m 0 = cond (f tt ff) m 0 :=
by unfold bitwise; apply bit_cases_on m; intros;
rw [binary_rec_eq, binary_rec_zero]; exact bitwise_bit_aux h
@[simp] lemma bitwise_zero (f : bool → bool → bool) :
bitwise f 0 0 = 0 :=
by rw bitwise_zero_left; cases f ff tt; refl
@[simp] lemma bitwise_bit {f : bool → bool → bool} (h : f ff ff = ff) (a m b n) :
bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) :=
begin
unfold bitwise,
rw [binary_rec_eq, binary_rec_eq],
{ induction ftf : f tt ff; dsimp [cond],
rw [show f a ff = ff, by cases a; assumption],
apply @congr_arg _ _ _ 0 (bit ff), tactic.swap,
rw [show f a ff = a, by cases a; assumption],
apply congr_arg (bit a),
all_goals {
apply bit_cases_on m, intros a m,
rw [binary_rec_eq, binary_rec_zero],
rw [← bitwise_bit_aux h, ftf], refl } },
{ exact bitwise_bit_aux h }
end
theorem bitwise_swap {f : bool → bool → bool} (h : f ff ff = ff) :
bitwise (function.swap f) = function.swap (bitwise f) :=
begin
funext m n, revert n,
dsimp [function.swap],
apply binary_rec _ (λ a m' IH, _) m; intro n,
{ rw [bitwise_zero_left, bitwise_zero_right], exact h },
apply bit_cases_on n; intros b n',
rw [bitwise_bit, bitwise_bit, IH]; exact h
end
@[simp] lemma lor_bit : ∀ (a m b n),
lor (bit a m) (bit b n) = bit (a || b) (lor m n) := bitwise_bit rfl
@[simp] lemma land_bit : ∀ (a m b n),
land (bit a m) (bit b n) = bit (a && b) (land m n) := bitwise_bit rfl
@[simp] lemma ldiff_bit : ∀ (a m b n),
ldiff (bit a m) (bit b n) = bit (a && bnot b) (ldiff m n) := bitwise_bit rfl
@[simp] lemma lxor_bit : ∀ (a m b n),
lxor (bit a m) (bit b n) = bit (bxor a b) (lxor m n) := bitwise_bit rfl
@[simp] lemma test_bit_bitwise {f : bool → bool → bool} (h : f ff ff = ff) (m n k) :
test_bit (bitwise f m n) k = f (test_bit m k) (test_bit n k) :=
begin
revert m n; induction k with k IH; intros m n;
apply bit_cases_on m; intros a m';
apply bit_cases_on n; intros b n';
rw bitwise_bit h,
{ simp [test_bit_zero] },
{ simp [test_bit_succ, IH] }
end
@[simp] lemma test_bit_lor : ∀ (m n k),
test_bit (lor m n) k = test_bit m k || test_bit n k := test_bit_bitwise rfl
@[simp] lemma test_bit_land : ∀ (m n k),
test_bit (land m n) k = test_bit m k && test_bit n k := test_bit_bitwise rfl
@[simp] lemma test_bit_ldiff : ∀ (m n k),
test_bit (ldiff m n) k = test_bit m k && bnot (test_bit n k) := test_bit_bitwise rfl
@[simp] lemma test_bit_lxor : ∀ (m n k),
test_bit (lxor m n) k = bxor (test_bit m k) (test_bit n k) := test_bit_bitwise rfl
end nat
|
c3143c9cc18832fc813a2612c1e09d8f0d15382b | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/data/subtype.lean | a20a8f3643371ffbc09f0d134b3ef6b413688277 | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 7,514 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import logic.function.basic
import tactic.ext
import tactic.lint
import tactic.simps
/-!
# Subtypes
This file provides basic API for subtypes, which are defined in core.
A subtype is a type made from restricting another type, say `α`, to its elements that satisfy some
predicate, say `p : α → Prop`. Specifically, it is the type of pairs `⟨val, property⟩` where
`val : α` and `property : p val`. It is denoted `subtype p` and notation `{val : α // p val}` is
available.
A subtype has a natural coercion to the parent type, by coercing `⟨val, property⟩` to `val`. As
such, subtypes can be thought of as bundled sets, the difference being that elements of a set are
still of type `α` while elements of a subtype aren't.
-/
open function
namespace subtype
variables {α β γ : Sort*} {p q : α → Prop}
/-- See Note [custom simps projection] -/
def simps.coe (x : subtype p) : α := x
initialize_simps_projections subtype (val → coe)
/-- A version of `x.property` or `x.2` where `p` is syntactically applied to the coercion of `x`
instead of `x.1`. A similar result is `subtype.mem` in `data.set.basic`. -/
lemma prop (x : subtype p) : p x := x.2
@[simp] lemma val_eq_coe {x : subtype p} : x.1 = ↑x := rfl
@[simp] protected theorem «forall» {q : {a // p a} → Prop} :
(∀ x, q x) ↔ (∀ a b, q ⟨a, b⟩) :=
⟨assume h a b, h ⟨a, b⟩, assume h ⟨a, b⟩, h a b⟩
/-- An alternative version of `subtype.forall`. This one is useful if Lean cannot figure out `q`
when using `subtype.forall` from right to left. -/
protected theorem forall' {q : ∀ x, p x → Prop} :
(∀ x h, q x h) ↔ (∀ x : {a // p a}, q x x.2) :=
(@subtype.forall _ _ (λ x, q x.1 x.2)).symm
@[simp] protected theorem «exists» {q : {a // p a} → Prop} :
(∃ x, q x) ↔ (∃ a b, q ⟨a, b⟩) :=
⟨assume ⟨⟨a, b⟩, h⟩, ⟨a, b, h⟩, assume ⟨a, b, h⟩, ⟨⟨a, b⟩, h⟩⟩
/-- An alternative version of `subtype.exists`. This one is useful if Lean cannot figure out `q`
when using `subtype.exists` from right to left. -/
protected theorem exists' {q : ∀x, p x → Prop} :
(∃ x h, q x h) ↔ (∃ x : {a // p a}, q x x.2) :=
(@subtype.exists _ _ (λ x, q x.1 x.2)).symm
@[ext] protected lemma ext : ∀ {a1 a2 : {x // p x}}, (a1 : α) = (a2 : α) → a1 = a2
| ⟨x, h1⟩ ⟨.(x), h2⟩ rfl := rfl
lemma ext_iff {a1 a2 : {x // p x}} : a1 = a2 ↔ (a1 : α) = (a2 : α) :=
⟨congr_arg _, subtype.ext⟩
lemma heq_iff_coe_eq (h : ∀ x, p x ↔ q x) {a1 : {x // p x}} {a2 : {x // q x}} :
a1 == a2 ↔ (a1 : α) = (a2 : α) :=
eq.rec (λ a2', heq_iff_eq.trans ext_iff) (funext $ λ x, propext (h x)) a2
lemma heq_iff_coe_heq {α β : Sort*} {p : α → Prop} {q : β → Prop} {a : {x // p x}}
{b : {y // q y}} (h : α = β) (h' : p == q) :
a == b ↔ (a : α) == (b : β) :=
by { subst h, subst h', rw [heq_iff_eq, heq_iff_eq, ext_iff] }
lemma ext_val {a1 a2 : {x // p x}} : a1.1 = a2.1 → a1 = a2 :=
subtype.ext
lemma ext_iff_val {a1 a2 : {x // p x}} : a1 = a2 ↔ a1.1 = a2.1 :=
ext_iff
@[simp] theorem coe_eta (a : {a // p a}) (h : p a) : mk ↑a h = a := subtype.ext rfl
@[simp] theorem coe_mk (a h) : (@mk α p a h : α) = a := rfl
@[simp, nolint simp_nf] -- built-in reduction doesn't always work
theorem mk_eq_mk {a h a' h'} : @mk α p a h = @mk α p a' h' ↔ a = a' :=
ext_iff
theorem coe_eq_iff {a : {a // p a}} {b : α} : ↑a = b ↔ ∃ h, a = ⟨b, h⟩ :=
⟨λ h, h ▸ ⟨a.2, (coe_eta _ _).symm⟩, λ ⟨hb, ha⟩, ha.symm ▸ rfl⟩
theorem coe_injective : injective (coe : subtype p → α) :=
λ a b, subtype.ext
theorem val_injective : injective (@val _ p) :=
coe_injective
/-- Restrict a (dependent) function to a subtype -/
def restrict {α} {β : α → Type*} (f : Π x, β x) (p : α → Prop) (x : subtype p) : β x.1 :=
f x
lemma restrict_apply {α} {β : α → Type*} (f : Π x, β x) (p : α → Prop) (x : subtype p) :
restrict f p x = f x.1 :=
by refl
lemma restrict_def {α β} (f : α → β) (p : α → Prop) : restrict f p = f ∘ coe :=
by refl
lemma restrict_injective {α β} {f : α → β} (p : α → Prop) (h : injective f) :
injective (restrict f p) :=
h.comp coe_injective
lemma surjective_restrict {α} {β : α → Type*} [ne : Π a, nonempty (β a)] (p : α → Prop) :
surjective (λ f : Π x, β x, restrict f p) :=
begin
letI := classical.dec_pred p,
refine λ f, ⟨λ x, if h : p x then f ⟨x, h⟩ else nonempty.some (ne x), funext $ _⟩,
rintro ⟨x, hx⟩,
exact dif_pos hx
end
/-- Defining a map into a subtype, this can be seen as an "coinduction principle" of `subtype`-/
@[simps] def coind {α β} (f : α → β) {p : β → Prop} (h : ∀ a, p (f a)) : α → subtype p :=
λ a, ⟨f a, h a⟩
theorem coind_injective {α β} {f : α → β} {p : β → Prop} (h : ∀ a, p (f a))
(hf : injective f) : injective (coind f h) :=
λ x y hxy, hf $ by apply congr_arg subtype.val hxy
theorem coind_surjective {α β} {f : α → β} {p : β → Prop} (h : ∀ a, p (f a))
(hf : surjective f) : surjective (coind f h) :=
λ x, let ⟨a, ha⟩ := hf x in ⟨a, coe_injective ha⟩
theorem coind_bijective {α β} {f : α → β} {p : β → Prop} (h : ∀ a, p (f a))
(hf : bijective f) : bijective (coind f h) :=
⟨coind_injective h hf.1, coind_surjective h hf.2⟩
/-- Restriction of a function to a function on subtypes. -/
@[simps] def map {p : α → Prop} {q : β → Prop} (f : α → β) (h : ∀ a, p a → q (f a)) :
subtype p → subtype q :=
λ x, ⟨f x, h x x.prop⟩
theorem map_comp {p : α → Prop} {q : β → Prop} {r : γ → Prop} {x : subtype p}
(f : α → β) (h : ∀ a, p a → q (f a)) (g : β → γ) (l : ∀ a, q a → r (g a)) :
map g l (map f h x) = map (g ∘ f) (assume a ha, l (f a) $ h a ha) x :=
rfl
theorem map_id {p : α → Prop} {h : ∀ a, p a → p (id a)} : map (@id α) h = id :=
funext $ assume ⟨v, h⟩, rfl
lemma map_injective {p : α → Prop} {q : β → Prop} {f : α → β} (h : ∀ a, p a → q (f a))
(hf : injective f) : injective (map f h) :=
coind_injective _ $ hf.comp coe_injective
lemma map_involutive {p : α → Prop} {f : α → α} (h : ∀ a, p a → p (f a))
(hf : involutive f) : involutive (map f h) :=
λ x, subtype.ext (hf x)
instance [has_equiv α] (p : α → Prop) : has_equiv (subtype p) :=
⟨λ s t, (s : α) ≈ (t : α)⟩
theorem equiv_iff [has_equiv α] {p : α → Prop} {s t : subtype p} :
s ≈ t ↔ (s : α) ≈ (t : α) :=
iff.rfl
variables [setoid α]
protected theorem refl (s : subtype p) : s ≈ s :=
setoid.refl ↑s
protected theorem symm {s t : subtype p} (h : s ≈ t) : t ≈ s :=
setoid.symm h
protected theorem trans {s t u : subtype p} (h₁ : s ≈ t) (h₂ : t ≈ u) : s ≈ u :=
setoid.trans h₁ h₂
theorem equivalence (p : α → Prop) : equivalence (@has_equiv.equiv (subtype p) _) :=
mk_equivalence _ subtype.refl (@subtype.symm _ p _) (@subtype.trans _ p _)
instance (p : α → Prop) : setoid (subtype p) :=
setoid.mk (≈) (equivalence p)
end subtype
namespace subtype
/-! Some facts about sets, which require that `α` is a type. -/
variables {α β γ : Type*} {p : α → Prop}
@[simp] lemma coe_prop {S : set α} (a : {a // a ∈ S}) : ↑a ∈ S := a.prop
lemma val_prop {S : set α} (a : {a // a ∈ S}) : a.val ∈ S := a.property
end subtype
|
9194edf7069c4691e985290a356deb8f9c95ae85 | d642a6b1261b2cbe691e53561ac777b924751b63 | /src/topology/algebra/group.lean | 41291affd76d59b7ede311e8c8855200ac04543c | [
"Apache-2.0"
] | permissive | cipher1024/mathlib | fee56b9954e969721715e45fea8bcb95f9dc03fe | d077887141000fefa5a264e30fa57520e9f03522 | refs/heads/master | 1,651,806,490,504 | 1,573,508,694,000 | 1,573,508,694,000 | 107,216,176 | 0 | 0 | Apache-2.0 | 1,647,363,136,000 | 1,508,213,014,000 | Lean | UTF-8 | Lean | false | false | 16,497 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
Theory of topological groups.
-/
import data.equiv.algebra
import algebra.pointwise order.filter.pointwise
import group_theory.quotient_group
import topology.algebra.monoid topology.homeomorph
open classical set lattice filter topological_space
open_locale classical
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
section topological_group
/-- A topological (additive) group is a group in which the addition and negation operations are
continuous. -/
class topological_add_group (α : Type u) [topological_space α] [add_group α]
extends topological_add_monoid α : Prop :=
(continuous_neg : continuous (λa:α, -a))
/-- A topological group is a group in which the multiplication and inversion operations are
continuous. -/
@[to_additive topological_add_group]
class topological_group (α : Type*) [topological_space α] [group α]
extends topological_monoid α : Prop :=
(continuous_inv : continuous (λa:α, a⁻¹))
variables [topological_space α] [group α]
@[to_additive]
lemma continuous_inv' [topological_group α] : continuous (λx:α, x⁻¹) :=
topological_group.continuous_inv α
@[to_additive]
lemma continuous_inv [topological_group α] [topological_space β] {f : β → α}
(hf : continuous f) : continuous (λx, (f x)⁻¹) :=
continuous_inv'.comp hf
@[to_additive]
lemma continuous_on.inv [topological_group α] [topological_space β] {f : β → α} {s : set β}
(hf : continuous_on f s) : continuous_on (λx, (f x)⁻¹) s :=
continuous_inv'.comp_continuous_on hf
@[to_additive]
lemma tendsto_inv [topological_group α] {f : β → α} {x : filter β} {a : α}
(hf : tendsto f x (nhds a)) : tendsto (λx, (f x)⁻¹) x (nhds a⁻¹) :=
tendsto.comp (continuous_iff_continuous_at.mp (topological_group.continuous_inv α) a) hf
@[to_additive topological_add_group]
instance [topological_group α] [topological_space β] [group β] [topological_group β] :
topological_group (α × β) :=
{ continuous_inv := continuous.prod_mk (continuous_inv continuous_fst) (continuous_inv continuous_snd) }
attribute [instance] prod.topological_add_group
@[to_additive]
protected def homeomorph.mul_left [topological_group α] (a : α) : α ≃ₜ α :=
{ continuous_to_fun := continuous_mul continuous_const continuous_id,
continuous_inv_fun := continuous_mul continuous_const continuous_id,
.. equiv.mul_left a }
@[to_additive]
lemma is_open_map_mul_left [topological_group α] (a : α) : is_open_map (λ x, a * x) :=
(homeomorph.mul_left a).is_open_map
@[to_additive]
lemma is_closed_map_mul_left [topological_group α] (a : α) : is_closed_map (λ x, a * x) :=
(homeomorph.mul_left a).is_closed_map
@[to_additive]
protected def homeomorph.mul_right
{α : Type*} [topological_space α] [group α] [topological_group α] (a : α) :
α ≃ₜ α :=
{ continuous_to_fun := continuous_mul continuous_id continuous_const,
continuous_inv_fun := continuous_mul continuous_id continuous_const,
.. equiv.mul_right a }
@[to_additive]
lemma is_open_map_mul_right [topological_group α] (a : α) : is_open_map (λ x, x * a) :=
(homeomorph.mul_right a).is_open_map
@[to_additive]
lemma is_closed_map_mul_right [topological_group α] (a : α) : is_closed_map (λ x, x * a) :=
(homeomorph.mul_right a).is_closed_map
@[to_additive]
protected def homeomorph.inv (α : Type*) [topological_space α] [group α] [topological_group α] :
α ≃ₜ α :=
{ continuous_to_fun := continuous_inv',
continuous_inv_fun := continuous_inv',
.. equiv.inv α }
@[to_additive exists_nhds_half]
lemma exists_nhds_split [topological_group α] {s : set α} (hs : s ∈ nhds (1 : α)) :
∃ V ∈ nhds (1 : α), ∀ v w ∈ V, v * w ∈ s :=
begin
have : ((λa:α×α, a.1 * a.2) ⁻¹' s) ∈ nhds ((1, 1) : α × α) :=
tendsto_mul' (by simpa using hs),
rw nhds_prod_eq at this,
rcases mem_prod_iff.1 this with ⟨V₁, H₁, V₂, H₂, H⟩,
exact ⟨V₁ ∩ V₂, inter_mem_sets H₁ H₂, assume v w ⟨hv, _⟩ ⟨_, hw⟩, @H (v, w) ⟨hv, hw⟩⟩
end
@[to_additive exists_nhds_half_neg]
lemma exists_nhds_split_inv [topological_group α] {s : set α} (hs : s ∈ nhds (1 : α)) :
∃ V ∈ nhds (1 : α), ∀ v w ∈ V, v * w⁻¹ ∈ s :=
begin
have : tendsto (λa:α×α, a.1 * (a.2)⁻¹) ((nhds (1:α)).prod (nhds (1:α))) (nhds 1),
{ simpa using tendsto_mul (@tendsto_fst α α (nhds 1) (nhds 1)) (tendsto_inv tendsto_snd) },
have : ((λa:α×α, a.1 * (a.2)⁻¹) ⁻¹' s) ∈ (nhds (1:α)).prod (nhds (1:α)) :=
this (by simpa using hs),
rcases mem_prod_iff.1 this with ⟨V₁, H₁, V₂, H₂, H⟩,
exact ⟨V₁ ∩ V₂, inter_mem_sets H₁ H₂, assume v w ⟨hv, _⟩ ⟨_, hw⟩, @H (v, w) ⟨hv, hw⟩⟩
end
@[to_additive exists_nhds_quarter]
lemma exists_nhds_split4 [topological_group α] {u : set α} (hu : u ∈ nhds (1 : α)) :
∃ V ∈ nhds (1 : α), ∀ {v w s t}, v ∈ V → w ∈ V → s ∈ V → t ∈ V → v * w * s * t ∈ u :=
begin
rcases exists_nhds_split hu with ⟨W, W_nhd, h⟩,
rcases exists_nhds_split W_nhd with ⟨V, V_nhd, h'⟩,
existsi [V, V_nhd],
intros v w s t v_in w_in s_in t_in,
simpa [mul_assoc] using h _ _ (h' v w v_in w_in) (h' s t s_in t_in)
end
section
variable (α)
@[to_additive]
lemma nhds_one_symm [topological_group α] : comap (λr:α, r⁻¹) (nhds (1 : α)) = nhds (1 : α) :=
begin
have lim : tendsto (λr:α, r⁻¹) (nhds 1) (nhds 1),
{ simpa using tendsto_inv (@tendsto_id α (nhds 1)) },
refine comap_eq_of_inverse _ _ lim lim,
{ funext x, simp },
end
end
@[to_additive]
lemma nhds_translation_mul_inv [topological_group α] (x : α) :
comap (λy:α, y * x⁻¹) (nhds 1) = nhds x :=
begin
refine comap_eq_of_inverse (λy:α, y * x) _ _ _,
{ funext x; simp },
{ suffices : tendsto (λy:α, y * x⁻¹) (nhds x) (nhds (x * x⁻¹)), { simpa },
exact tendsto_mul tendsto_id tendsto_const_nhds },
{ suffices : tendsto (λy:α, y * x) (nhds 1) (nhds (1 * x)), { simpa },
exact tendsto_mul tendsto_id tendsto_const_nhds }
end
@[to_additive]
lemma topological_group.ext {G : Type*} [group G] {t t' : topological_space G}
(tg : @topological_group G t _) (tg' : @topological_group G t' _)
(h : @nhds G t 1 = @nhds G t' 1) : t = t' :=
eq_of_nhds_eq_nhds $ λ x, by
rw [← @nhds_translation_mul_inv G t _ _ x , ← @nhds_translation_mul_inv G t' _ _ x , ← h]
end topological_group
section quotient_topological_group
variables [topological_space α] [group α] [topological_group α] (N : set α) [normal_subgroup N]
@[to_additive]
instance {α : Type u} [group α] [topological_space α] (N : set α) [normal_subgroup N] :
topological_space (quotient_group.quotient N) :=
by dunfold quotient_group.quotient; apply_instance
open quotient_group
@[to_additive quotient_add_group_saturate]
lemma quotient_group_saturate {α : Type u} [group α] (N : set α) [normal_subgroup N] (s : set α) :
(coe : α → quotient N) ⁻¹' ((coe : α → quotient N) '' s) = (⋃ x : N, (λ y, y*x.1) '' s) :=
begin
ext x,
simp only [mem_preimage, mem_image, mem_Union, quotient_group.eq],
split,
{ exact assume ⟨a, a_in, h⟩, ⟨⟨_, h⟩, a, a_in, mul_inv_cancel_left _ _⟩ },
{ exact assume ⟨⟨i, hi⟩, a, ha, eq⟩,
⟨a, ha, by simp only [eq.symm, (mul_assoc _ _ _).symm, inv_mul_cancel_left, hi]⟩ }
end
@[to_additive]
lemma quotient_group.open_coe : is_open_map (coe : α → quotient N) :=
begin
intros s s_op,
change is_open ((coe : α → quotient N) ⁻¹' (coe '' s)),
rw quotient_group_saturate N s,
apply is_open_Union,
rintro ⟨n, _⟩,
exact is_open_map_mul_right n s s_op
end
@[to_additive topological_add_group_quotient]
instance topological_group_quotient : topological_group (quotient N) :=
{ continuous_mul := begin
have cont : continuous ((coe : α → quotient N) ∘ (λ (p : α × α), p.fst * p.snd)) :=
continuous_quot_mk.comp continuous_mul',
have quot : quotient_map (λ p : α × α, ((p.1:quotient N), (p.2:quotient N))),
{ apply is_open_map.to_quotient_map,
{ exact is_open_map.prod (quotient_group.open_coe N) (quotient_group.open_coe N) },
{ apply continuous.prod_mk,
{ exact continuous_quot_mk.comp continuous_fst },
{ exact continuous_quot_mk.comp continuous_snd } },
{ rintro ⟨⟨x⟩, ⟨y⟩⟩,
exact ⟨(x, y), rfl⟩ } },
exact (quotient_map.continuous_iff quot).2 cont,
end,
continuous_inv := begin
apply continuous_quotient_lift,
change continuous ((coe : α → quotient N) ∘ (λ (a : α), a⁻¹)),
exact continuous_quot_mk.comp continuous_inv'
end }
attribute [instance] topological_add_group_quotient
end quotient_topological_group
section topological_add_group
variables [topological_space α] [add_group α]
lemma continuous_sub [topological_add_group α] [topological_space β] {f : β → α} {g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λx, f x - g x) :=
by simp; exact continuous_add hf (continuous_neg hg)
lemma continuous_sub' [topological_add_group α] : continuous (λp:α×α, p.1 - p.2) :=
continuous_sub continuous_fst continuous_snd
lemma continuous_on.sub [topological_add_group α] [topological_space β] {f : β → α} {g : β → α} {s : set β}
(hf : continuous_on f s) (hg : continuous_on g s) : continuous_on (λx, f x - g x) s :=
continuous_sub'.comp_continuous_on (hf.prod hg)
lemma tendsto_sub [topological_add_group α] {f : β → α} {g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (nhds a)) (hg : tendsto g x (nhds b)) : tendsto (λx, f x - g x) x (nhds (a - b)) :=
by simp; exact tendsto_add hf (tendsto_neg hg)
lemma nhds_translation [topological_add_group α] (x : α) : comap (λy:α, y - x) (nhds 0) = nhds x :=
nhds_translation_add_neg x
end topological_add_group
/-- additive group with a neighbourhood around 0.
Only used to construct a topology and uniform space.
This is currently only available for commutative groups, but it can be extended to
non-commutative groups too.
-/
class add_group_with_zero_nhd (α : Type u) extends add_comm_group α :=
(Z : filter α)
(zero_Z {} : pure 0 ≤ Z)
(sub_Z {} : tendsto (λp:α×α, p.1 - p.2) (Z.prod Z) Z)
namespace add_group_with_zero_nhd
variables (α) [add_group_with_zero_nhd α]
local notation `Z` := add_group_with_zero_nhd.Z
instance : topological_space α :=
topological_space.mk_of_nhds $ λa, map (λx, x + a) (Z α)
variables {α}
lemma neg_Z : tendsto (λa:α, - a) (Z α) (Z α) :=
have tendsto (λa, (0:α)) (Z α) (Z α),
by refine le_trans (assume h, _) zero_Z; simp [univ_mem_sets'] {contextual := tt},
have tendsto (λa:α, 0 - a) (Z α) (Z α), from
sub_Z.comp (tendsto.prod_mk this tendsto_id),
by simpa
lemma add_Z : tendsto (λp:α×α, p.1 + p.2) ((Z α).prod (Z α)) (Z α) :=
suffices tendsto (λp:α×α, p.1 - -p.2) ((Z α).prod (Z α)) (Z α),
by simpa,
sub_Z.comp (tendsto.prod_mk tendsto_fst (neg_Z.comp tendsto_snd))
lemma exists_Z_half {s : set α} (hs : s ∈ Z α) : ∃ V ∈ Z α, ∀ v w ∈ V, v + w ∈ s :=
begin
have : ((λa:α×α, a.1 + a.2) ⁻¹' s) ∈ (Z α).prod (Z α) := add_Z (by simpa using hs),
rcases mem_prod_iff.1 this with ⟨V₁, H₁, V₂, H₂, H⟩,
exact ⟨V₁ ∩ V₂, inter_mem_sets H₁ H₂, assume v w ⟨hv, _⟩ ⟨_, hw⟩, @H (v, w) ⟨hv, hw⟩⟩
end
lemma nhds_eq (a : α) : nhds a = map (λx, x + a) (Z α) :=
topological_space.nhds_mk_of_nhds _ _
(assume a, calc pure a = map (λx, x + a) (pure 0) : by simp
... ≤ _ : map_mono zero_Z)
(assume b s hs,
let ⟨t, ht, eqt⟩ := exists_Z_half hs in
have t0 : (0:α) ∈ t, by simpa using zero_Z ht,
begin
refine ⟨(λx:α, x + b) '' t, image_mem_map ht, _, _⟩,
{ refine set.image_subset_iff.2 (assume b hbt, _),
simpa using eqt 0 b t0 hbt },
{ rintros _ ⟨c, hb, rfl⟩,
refine (Z α).sets_of_superset ht (assume x hxt, _),
simpa using eqt _ _ hxt hb }
end)
lemma nhds_zero_eq_Z : nhds 0 = Z α := by simp [nhds_eq]; exact filter.map_id
instance : topological_add_monoid α :=
⟨ continuous_iff_continuous_at.2 $ assume ⟨a, b⟩,
begin
rw [continuous_at, nhds_prod_eq, nhds_eq, nhds_eq, nhds_eq, filter.prod_map_map_eq,
tendsto_map'_iff],
suffices : tendsto ((λx:α, (a + b) + x) ∘ (λp:α×α,p.1 + p.2)) (filter.prod (Z α) (Z α))
(map (λx:α, (a + b) + x) (Z α)),
{ simpa [(∘)] },
exact tendsto_map.comp add_Z
end⟩
instance : topological_add_group α :=
⟨continuous_iff_continuous_at.2 $ assume a,
begin
rw [continuous_at, nhds_eq, nhds_eq, tendsto_map'_iff],
suffices : tendsto ((λx:α, x - a) ∘ (λx:α, -x)) (Z α) (map (λx:α, x - a) (Z α)),
{ simpa [(∘)] },
exact tendsto_map.comp neg_Z
end⟩
end add_group_with_zero_nhd
section filter_mul
local attribute [instance]
set.pointwise_one set.pointwise_mul set.pointwise_add filter.pointwise_mul filter.pointwise_add
filter.pointwise_one
section
variables [topological_space α] [group α] [topological_group α]
@[to_additive]
lemma is_open_pointwise_mul_left {s t : set α} : is_open t → is_open (s * t) := λ ht,
begin
have : ∀a, is_open ((λ (x : α), a * x) '' t),
assume a, apply is_open_map_mul_left, exact ht,
rw pointwise_mul_eq_Union_mul_left,
exact is_open_Union (λa, is_open_Union $ λha, this _),
end
@[to_additive]
lemma is_open_pointwise_mul_right {s t : set α} : is_open s → is_open (s * t) := λ hs,
begin
have : ∀a, is_open ((λ (x : α), x * a) '' s),
assume a, apply is_open_map_mul_right, exact hs,
rw pointwise_mul_eq_Union_mul_right,
exact is_open_Union (λa, is_open_Union $ λha, this _),
end
variables (α)
lemma topological_group.t1_space (h : @is_closed α _ {1}) : t1_space α :=
⟨assume x, by { convert is_closed_map_mul_right x _ h, simp }⟩
lemma topological_group.regular_space [t1_space α] : regular_space α :=
⟨assume s a hs ha,
let f := λ p : α × α, p.1 * (p.2)⁻¹ in
have hf : continuous f :=
continuous.comp continuous_mul'
(continuous.prod_mk (continuous_fst) (continuous.comp continuous_inv' continuous_snd)),
-- a ∈ -s implies f (a, 1) ∈ -s, and so (a, 1) ∈ f⁻¹' (-s);
-- and so can find t₁ t₂ open such that a ∈ t₁ × t₂ ⊆ f⁻¹' (-s)
let ⟨t₁, t₂, ht₁, ht₂, a_mem_t₁, one_mem_t₂, t_subset⟩ :=
is_open_prod_iff.1 (hf _ (is_open_compl_iff.2 hs)) a (1:α) (by simpa [f]) in
begin
use s * t₂,
use is_open_pointwise_mul_left ht₂,
use λ x hx, ⟨x, hx, 1, one_mem_t₂, (mul_one _).symm⟩,
apply inf_principal_eq_bot,
rw mem_nhds_sets_iff,
refine ⟨t₁, _, ht₁, a_mem_t₁⟩,
rintros x hx ⟨y, hy, z, hz, yz⟩,
have : x * z⁻¹ ∈ -s := (prod_subset_iff.1 t_subset) x hx z hz,
have : x * z⁻¹ ∈ s, rw yz, simpa,
contradiction
end⟩
local attribute [instance] topological_group.regular_space
lemma topological_group.t2_space [t1_space α] : t2_space α := regular_space.t2_space α
end
section
variables [topological_space α] [comm_group α] [topological_group α]
@[to_additive]
lemma nhds_pointwise_mul (x y : α) : nhds (x * y) = nhds x * nhds y :=
filter_eq $ set.ext $ assume s,
begin
rw [← nhds_translation_mul_inv x, ← nhds_translation_mul_inv y, ← nhds_translation_mul_inv (x*y)],
split,
{ rintros ⟨t, ht, ts⟩,
rcases exists_nhds_split ht with ⟨V, V_mem, h⟩,
refine ⟨(λa, a * x⁻¹) ⁻¹' V, ⟨V, V_mem, subset.refl _⟩,
(λa, a * y⁻¹) ⁻¹' V, ⟨V, V_mem, subset.refl _⟩, _⟩,
rintros a ⟨v, v_mem, w, w_mem, rfl⟩,
apply ts,
simpa [mul_comm, mul_assoc, mul_left_comm] using h (v * x⁻¹) (w * y⁻¹) v_mem w_mem },
{ rintros ⟨a, ⟨b, hb, ba⟩, c, ⟨d, hd, dc⟩, ac⟩,
refine ⟨b ∩ d, inter_mem_sets hb hd, assume v, _⟩,
simp only [preimage_subset_iff, mul_inv_rev, mem_preimage] at *,
rintros ⟨vb, vd⟩,
refine ac ⟨v * y⁻¹, _, y, _, _⟩,
{ rw ← mul_assoc _ _ _ at vb, exact ba _ vb },
{ apply dc y, rw mul_right_inv, exact mem_of_nhds hd },
{ simp only [inv_mul_cancel_right] } }
end
@[to_additive]
lemma nhds_is_mul_hom : is_mul_hom (λx:α, nhds x) := ⟨λ_ _, nhds_pointwise_mul _ _⟩
end
end filter_mul
|
1f643a73f0ec2503b03e2f643a896f0385489cc0 | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/ring_theory/integral_domain.lean | c183acafc69996f31b2bb581f520e5af5aa768fb | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 6,909 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Chris Hughes
-/
import data.fintype.card
import data.polynomial.ring_division
import group_theory.order_of_element
import algebra.geom_sum
/-!
# Integral domains
Assorted theorems about integral domains.
## Main theorems
* `is_cyclic_of_subgroup_integral_domain` : A finite subgroup of the units of an integral domain
is cyclic.
* `field_of_integral_domain` : A finite integral domain is a field.
## Tags
integral domain, finite integral domain, finite field
-/
section
open finset polynomial function
open_locale big_operators nat
variables {R : Type*} {G : Type*} [integral_domain R] [group G] [fintype G]
lemma card_nth_roots_subgroup_units (f : G →* R) (hf : injective f) {n : ℕ} (hn : 0 < n) (g₀ : G) :
({g ∈ univ | g ^ n = g₀} : finset G).card ≤ (nth_roots n (f g₀)).card :=
begin
haveI : decidable_eq R := classical.dec_eq _,
refine le_trans _ (nth_roots n (f g₀)).to_finset_card_le,
apply card_le_card_of_inj_on f,
{ intros g hg,
rw [sep_def, mem_filter] at hg,
rw [multiset.mem_to_finset, mem_nth_roots hn, ← f.map_pow, hg.2] },
{ intros, apply hf, assumption }
end
/-- A finite subgroup of the unit group of an integral domain is cyclic. -/
lemma is_cyclic_of_subgroup_integral_domain (f : G →* R) (hf : injective f) : is_cyclic G :=
begin
haveI := classical.dec_eq G,
apply is_cyclic_of_card_pow_eq_one_le,
intros n hn,
convert (le_trans (card_nth_roots_subgroup_units f hf hn 1) (card_nth_roots n (f 1)))
end
/-- The unit group of a finite integral domain is cyclic. -/
instance [fintype R] : is_cyclic (units R) :=
is_cyclic_of_subgroup_integral_domain (units.coe_hom R) $ units.ext
/-- Every finite integral domain is a field. -/
def field_of_integral_domain [decidable_eq R] [fintype R] : field R :=
{ inv := λ a, if h : a = 0 then 0
else fintype.bij_inv (show function.bijective (* a),
from fintype.injective_iff_bijective.1 $ λ _ _, mul_right_cancel' h) 1,
mul_inv_cancel := λ a ha, show a * dite _ _ _ = _, by rw [dif_neg ha, mul_comm];
exact fintype.right_inverse_bij_inv (show function.bijective (* a), from _) 1,
inv_zero := dif_pos rfl,
..show integral_domain R, by apply_instance }
section
variables (S : set (units R)) [is_subgroup S] [fintype S]
/-- A finite subgroup of the units of an integral domain is cyclic. -/
instance subgroup_units_cyclic : is_cyclic S :=
begin
refine is_cyclic_of_subgroup_integral_domain ⟨(coe : S → R), _, _⟩
(units.ext.comp subtype.val_injective),
{ simp only [is_submonoid.coe_one, units.coe_one, coe_coe] },
{ intros, simp only [is_submonoid.coe_mul, units.coe_mul, coe_coe] },
end
end
lemma card_fiber_eq_of_mem_range {H : Type*} [group H] [decidable_eq H]
(f : G →* H) {x y : H} (hx : x ∈ set.range f) (hy : y ∈ set.range f) :
(univ.filter $ λ g, f g = x).card = (univ.filter $ λ g, f g = y).card :=
begin
rcases hx with ⟨x, rfl⟩,
rcases hy with ⟨y, rfl⟩,
refine card_congr (λ g _, g * x⁻¹ * y) _ _ (λ g hg, ⟨g * y⁻¹ * x, _⟩),
{ simp only [mem_filter, one_mul, monoid_hom.map_mul, mem_univ, mul_right_inv,
eq_self_iff_true, monoid_hom.map_mul_inv, and_self, forall_true_iff] {contextual := tt} },
{ simp only [mul_left_inj, imp_self, forall_2_true_iff], },
{ simp only [true_and, mem_filter, mem_univ] at hg,
simp only [hg, mem_filter, one_mul, monoid_hom.map_mul, mem_univ, mul_right_inv,
eq_self_iff_true, exists_prop_of_true, monoid_hom.map_mul_inv, and_self,
mul_inv_cancel_right, inv_mul_cancel_right], }
end
/-- In an integral domain, a sum indexed by a nontrivial homomorphism from a finite group is zero. -/
lemma sum_hom_units_eq_zero (f : G →* R) (hf : f ≠ 1) : ∑ g : G, f g = 0 :=
begin
classical,
obtain ⟨x, hx⟩ : ∃ x : set.range f.to_hom_units, ∀ y : set.range f.to_hom_units, y ∈ powers x,
from is_cyclic.exists_monoid_generator (set.range (f.to_hom_units)),
have hx1 : x ≠ 1,
{ rintro rfl,
apply hf,
ext g,
rw [monoid_hom.one_apply],
cases hx ⟨f.to_hom_units g, g, rfl⟩ with n hn,
rwa [subtype.ext_iff, units.ext_iff, subtype.coe_mk, monoid_hom.coe_to_hom_units,
is_submonoid.coe_pow, units.coe_pow, is_submonoid.coe_one, units.coe_one,
one_pow, eq_comm] at hn, },
replace hx1 : (x : R) - 1 ≠ 0,
from λ h, hx1 (subtype.eq (units.ext (sub_eq_zero.1 h))),
let c := (univ.filter (λ g, f.to_hom_units g = 1)).card,
calc ∑ g : G, f g
= ∑ g : G, f.to_hom_units g : rfl
... = ∑ u : units R in univ.image f.to_hom_units, (univ.filter (λ g, f.to_hom_units g = u)).card • u :
sum_comp (coe : units R → R) f.to_hom_units
... = ∑ u : units R in univ.image f.to_hom_units, c • u :
sum_congr rfl (λ u hu, congr_arg2 _ _ rfl) -- remaining goal 1, proven below
... = ∑ b : set.range f.to_hom_units, c • ↑b : finset.sum_subtype
(by simp only [mem_image, set.mem_range, forall_const, iff_self, mem_univ, exists_prop_of_true]) _
... = c • ∑ b : set.range f.to_hom_units, (b : R) : smul_sum.symm
... = c • 0 : congr_arg2 _ rfl _ -- remaining goal 2, proven below
... = 0 : smul_zero _,
{ -- remaining goal 1
show (univ.filter (λ (g : G), f.to_hom_units g = u)).card = c,
apply card_fiber_eq_of_mem_range f.to_hom_units,
{ simpa only [mem_image, mem_univ, exists_prop_of_true, set.mem_range] using hu, },
{ exact ⟨1, f.to_hom_units.map_one⟩ } },
-- remaining goal 2
show ∑ b : set.range f.to_hom_units, (b : R) = 0,
calc ∑ b : set.range f.to_hom_units, (b : R)
= ∑ n in range (order_of x), x ^ n :
eq.symm $ sum_bij (λ n _, x ^ n)
(by simp only [mem_univ, forall_true_iff])
(by simp only [is_submonoid.coe_pow, eq_self_iff_true, units.coe_pow, coe_coe, forall_true_iff])
(λ m n hm hn, pow_injective_of_lt_order_of _
(by simpa only [mem_range] using hm)
(by simpa only [mem_range] using hn))
(λ b hb, let ⟨n, hn⟩ := hx b in ⟨n % order_of x, mem_range.2 (nat.mod_lt _ (order_of_pos _)),
by rw [← pow_eq_mod_order_of, hn]⟩)
... = 0 : _,
rw [← mul_left_inj' hx1, zero_mul, ← geom_series, geom_sum_mul, coe_coe],
norm_cast,
rw [pow_order_of_eq_one, is_submonoid.coe_one, units.coe_one, sub_self],
end
/-- In an integral domain, a sum indexed by a homomorphism from a finite group is zero,
unless the homomorphism is trivial, in which case the sum is equal to the cardinality of the group. -/
lemma sum_hom_units (f : G →* R) [decidable (f = 1)] :
∑ g : G, f g = if f = 1 then fintype.card G else 0 :=
begin
split_ifs with h h,
{ simp [h, card_univ] },
{ exact sum_hom_units_eq_zero f h }
end
end
|
466e2f2e14fa6d64ca50242370df06320b8d3d2d | 36c7a18fd72e5b57229bd8ba36493daf536a19ce | /library/algebra/ordered_ring.lean | 431b8bc0b7c1fe2fff84e469b3dc078ab9735581 | [
"Apache-2.0"
] | permissive | YHVHvx/lean | 732bf0fb7a298cd7fe0f15d82f8e248c11db49e9 | 038369533e0136dd395dc252084d3c1853accbf2 | refs/heads/master | 1,610,701,080,210 | 1,449,128,595,000 | 1,449,128,595,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 26,630 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
Here an "ordered_ring" is partially ordered ring, which is ordered with respect to both a weak
order and an associated strict order. Our numeric structures (int, rat, and real) will be instances
of "linear_ordered_comm_ring". This development is modeled after Isabelle's library.
-/
import algebra.ordered_group algebra.ring
open eq eq.ops
namespace algebra
variable {A : Type}
private definition absurd_a_lt_a {B : Type} {a : A} [s : strict_order A] (H : a < a) : B :=
absurd H (lt.irrefl a)
/- semiring structures -/
structure ordered_semiring [class] (A : Type)
extends semiring A, ordered_cancel_comm_monoid A :=
(mul_le_mul_of_nonneg_left: ∀a b c, le a b → le zero c → le (mul c a) (mul c b))
(mul_le_mul_of_nonneg_right: ∀a b c, le a b → le zero c → le (mul a c) (mul b c))
(mul_lt_mul_of_pos_left: ∀a b c, lt a b → lt zero c → lt (mul c a) (mul c b))
(mul_lt_mul_of_pos_right: ∀a b c, lt a b → lt zero c → lt (mul a c) (mul b c))
section
variable [s : ordered_semiring A]
variables (a b c d e : A)
include s
theorem mul_le_mul_of_nonneg_left {a b c : A} (Hab : a ≤ b) (Hc : 0 ≤ c) :
c * a ≤ c * b := !ordered_semiring.mul_le_mul_of_nonneg_left Hab Hc
theorem mul_le_mul_of_nonneg_right {a b c : A} (Hab : a ≤ b) (Hc : 0 ≤ c) :
a * c ≤ b * c := !ordered_semiring.mul_le_mul_of_nonneg_right Hab Hc
-- TODO: there are four variations, depending on which variables we assume to be nonneg
theorem mul_le_mul {a b c d : A} (Hac : a ≤ c) (Hbd : b ≤ d) (nn_b : 0 ≤ b) (nn_c : 0 ≤ c) :
a * b ≤ c * d :=
calc
a * b ≤ c * b : mul_le_mul_of_nonneg_right Hac nn_b
... ≤ c * d : mul_le_mul_of_nonneg_left Hbd nn_c
theorem mul_nonneg {a b : A} (Ha : a ≥ 0) (Hb : b ≥ 0) : a * b ≥ 0 :=
begin
have H : 0 * b ≤ a * b, from mul_le_mul_of_nonneg_right Ha Hb,
rewrite zero_mul at H,
exact H
end
theorem mul_nonpos_of_nonneg_of_nonpos {a b : A} (Ha : a ≥ 0) (Hb : b ≤ 0) : a * b ≤ 0 :=
begin
have H : a * b ≤ a * 0, from mul_le_mul_of_nonneg_left Hb Ha,
rewrite mul_zero at H,
exact H
end
theorem mul_nonpos_of_nonpos_of_nonneg {a b : A} (Ha : a ≤ 0) (Hb : b ≥ 0) : a * b ≤ 0 :=
begin
have H : a * b ≤ 0 * b, from mul_le_mul_of_nonneg_right Ha Hb,
rewrite zero_mul at H,
exact H
end
theorem mul_lt_mul_of_pos_left {a b c : A} (Hab : a < b) (Hc : 0 < c) :
c * a < c * b := !ordered_semiring.mul_lt_mul_of_pos_left Hab Hc
theorem mul_lt_mul_of_pos_right {a b c : A} (Hab : a < b) (Hc : 0 < c) :
a * c < b * c := !ordered_semiring.mul_lt_mul_of_pos_right Hab Hc
-- TODO: once again, there are variations
theorem mul_lt_mul {a b c d : A} (Hac : a < c) (Hbd : b ≤ d) (pos_b : 0 < b) (nn_c : 0 ≤ c) :
a * b < c * d :=
calc
a * b < c * b : mul_lt_mul_of_pos_right Hac pos_b
... ≤ c * d : mul_le_mul_of_nonneg_left Hbd nn_c
theorem mul_pos {a b : A} (Ha : a > 0) (Hb : b > 0) : a * b > 0 :=
begin
have H : 0 * b < a * b, from mul_lt_mul_of_pos_right Ha Hb,
rewrite zero_mul at H,
exact H
end
theorem mul_neg_of_pos_of_neg {a b : A} (Ha : a > 0) (Hb : b < 0) : a * b < 0 :=
begin
have H : a * b < a * 0, from mul_lt_mul_of_pos_left Hb Ha,
rewrite mul_zero at H,
exact H
end
theorem mul_neg_of_neg_of_pos {a b : A} (Ha : a < 0) (Hb : b > 0) : a * b < 0 :=
begin
have H : a * b < 0 * b, from mul_lt_mul_of_pos_right Ha Hb,
rewrite zero_mul at H,
exact H
end
end
structure linear_ordered_semiring [class] (A : Type)
extends ordered_semiring A, linear_strong_order_pair A :=
(zero_lt_one : lt zero one)
section
variable [s : linear_ordered_semiring A]
variables {a b c : A}
include s
theorem zero_lt_one : 0 < (1:A) := linear_ordered_semiring.zero_lt_one A
theorem lt_of_mul_lt_mul_left (H : c * a < c * b) (Hc : c ≥ 0) : a < b :=
lt_of_not_ge
(assume H1 : b ≤ a,
have H2 : c * b ≤ c * a, from mul_le_mul_of_nonneg_left H1 Hc,
not_lt_of_ge H2 H)
theorem lt_of_mul_lt_mul_right (H : a * c < b * c) (Hc : c ≥ 0) : a < b :=
lt_of_not_ge
(assume H1 : b ≤ a,
have H2 : b * c ≤ a * c, from mul_le_mul_of_nonneg_right H1 Hc,
not_lt_of_ge H2 H)
theorem le_of_mul_le_mul_left (H : c * a ≤ c * b) (Hc : c > 0) : a ≤ b :=
le_of_not_gt
(assume H1 : b < a,
have H2 : c * b < c * a, from mul_lt_mul_of_pos_left H1 Hc,
not_le_of_gt H2 H)
theorem le_of_mul_le_mul_right (H : a * c ≤ b * c) (Hc : c > 0) : a ≤ b :=
le_of_not_gt
(assume H1 : b < a,
have H2 : b * c < a * c, from mul_lt_mul_of_pos_right H1 Hc,
not_le_of_gt H2 H)
theorem le_iff_mul_le_mul_left (a b : A) {c : A} (H : c > 0) : a ≤ b ↔ c * a ≤ c * b :=
iff.intro
(assume H', mul_le_mul_of_nonneg_left H' (le_of_lt H))
(assume H', le_of_mul_le_mul_left H' H)
theorem le_iff_mul_le_mul_right (a b : A) {c : A} (H : c > 0) : a ≤ b ↔ a * c ≤ b * c :=
iff.intro
(assume H', mul_le_mul_of_nonneg_right H' (le_of_lt H))
(assume H', le_of_mul_le_mul_right H' H)
theorem pos_of_mul_pos_left (H : 0 < a * b) (H1 : 0 ≤ a) : 0 < b :=
lt_of_not_ge
(assume H2 : b ≤ 0,
have H3 : a * b ≤ 0, from mul_nonpos_of_nonneg_of_nonpos H1 H2,
not_lt_of_ge H3 H)
theorem pos_of_mul_pos_right (H : 0 < a * b) (H1 : 0 ≤ b) : 0 < a :=
lt_of_not_ge
(assume H2 : a ≤ 0,
have H3 : a * b ≤ 0, from mul_nonpos_of_nonpos_of_nonneg H2 H1,
not_lt_of_ge H3 H)
theorem nonneg_of_mul_nonneg_left (H : 0 ≤ a * b) (H1 : 0 < a) : 0 ≤ b :=
le_of_not_gt
(assume H2 : b < 0,
not_le_of_gt (mul_neg_of_pos_of_neg H1 H2) H)
theorem nonneg_of_mul_nonneg_right (H : 0 ≤ a * b) (H1 : 0 < b) : 0 ≤ a :=
le_of_not_gt
(assume H2 : a < 0,
not_le_of_gt (mul_neg_of_neg_of_pos H2 H1) H)
theorem neg_of_mul_neg_left (H : a * b < 0) (H1 : 0 ≤ a) : b < 0 :=
lt_of_not_ge
(assume H2 : b ≥ 0,
not_lt_of_ge (mul_nonneg H1 H2) H)
theorem neg_of_mul_neg_right (H : a * b < 0) (H1 : 0 ≤ b) : a < 0 :=
lt_of_not_ge
(assume H2 : a ≥ 0,
not_lt_of_ge (mul_nonneg H2 H1) H)
theorem nonpos_of_mul_nonpos_left (H : a * b ≤ 0) (H1 : 0 < a) : b ≤ 0 :=
le_of_not_gt
(assume H2 : b > 0,
not_le_of_gt (mul_pos H1 H2) H)
theorem nonpos_of_mul_nonpos_right (H : a * b ≤ 0) (H1 : 0 < b) : a ≤ 0 :=
le_of_not_gt
(assume H2 : a > 0,
not_le_of_gt (mul_pos H2 H1) H)
end
structure decidable_linear_ordered_semiring [class] (A : Type)
extends linear_ordered_semiring A, decidable_linear_order A
/- ring structures -/
structure ordered_ring [class] (A : Type)
extends ring A, ordered_comm_group A, zero_ne_one_class A :=
(mul_nonneg : ∀a b, le zero a → le zero b → le zero (mul a b))
(mul_pos : ∀a b, lt zero a → lt zero b → lt zero (mul a b))
theorem ordered_ring.mul_le_mul_of_nonneg_left [s : ordered_ring A] {a b c : A}
(Hab : a ≤ b) (Hc : 0 ≤ c) : c * a ≤ c * b :=
have H1 : 0 ≤ b - a, from iff.elim_right !sub_nonneg_iff_le Hab,
assert H2 : 0 ≤ c * (b - a), from ordered_ring.mul_nonneg _ _ Hc H1,
begin
rewrite mul_sub_left_distrib at H2,
exact (iff.mp !sub_nonneg_iff_le H2)
end
theorem ordered_ring.mul_le_mul_of_nonneg_right [s : ordered_ring A] {a b c : A}
(Hab : a ≤ b) (Hc : 0 ≤ c) : a * c ≤ b * c :=
have H1 : 0 ≤ b - a, from iff.elim_right !sub_nonneg_iff_le Hab,
assert H2 : 0 ≤ (b - a) * c, from ordered_ring.mul_nonneg _ _ H1 Hc,
begin
rewrite mul_sub_right_distrib at H2,
exact (iff.mp !sub_nonneg_iff_le H2)
end
theorem ordered_ring.mul_lt_mul_of_pos_left [s : ordered_ring A] {a b c : A}
(Hab : a < b) (Hc : 0 < c) : c * a < c * b :=
have H1 : 0 < b - a, from iff.elim_right !sub_pos_iff_lt Hab,
assert H2 : 0 < c * (b - a), from ordered_ring.mul_pos _ _ Hc H1,
begin
rewrite mul_sub_left_distrib at H2,
exact (iff.mp !sub_pos_iff_lt H2)
end
theorem ordered_ring.mul_lt_mul_of_pos_right [s : ordered_ring A] {a b c : A}
(Hab : a < b) (Hc : 0 < c) : a * c < b * c :=
have H1 : 0 < b - a, from iff.elim_right !sub_pos_iff_lt Hab,
assert H2 : 0 < (b - a) * c, from ordered_ring.mul_pos _ _ H1 Hc,
begin
rewrite mul_sub_right_distrib at H2,
exact (iff.mp !sub_pos_iff_lt H2)
end
definition ordered_ring.to_ordered_semiring [trans_instance] [reducible]
[s : ordered_ring A] :
ordered_semiring A :=
⦃ ordered_semiring, s,
mul_zero := mul_zero,
zero_mul := zero_mul,
add_left_cancel := @add.left_cancel A _,
add_right_cancel := @add.right_cancel A _,
le_of_add_le_add_left := @le_of_add_le_add_left A _,
mul_le_mul_of_nonneg_left := @ordered_ring.mul_le_mul_of_nonneg_left A _,
mul_le_mul_of_nonneg_right := @ordered_ring.mul_le_mul_of_nonneg_right A _,
mul_lt_mul_of_pos_left := @ordered_ring.mul_lt_mul_of_pos_left A _,
mul_lt_mul_of_pos_right := @ordered_ring.mul_lt_mul_of_pos_right A _,
lt_of_add_lt_add_left := @lt_of_add_lt_add_left A _⦄
section
variable [s : ordered_ring A]
variables {a b c : A}
include s
theorem mul_le_mul_of_nonpos_left (H : b ≤ a) (Hc : c ≤ 0) : c * a ≤ c * b :=
have Hc' : -c ≥ 0, from iff.mpr !neg_nonneg_iff_nonpos Hc,
assert H1 : -c * b ≤ -c * a, from mul_le_mul_of_nonneg_left H Hc',
have H2 : -(c * b) ≤ -(c * a),
begin
rewrite [-*neg_mul_eq_neg_mul at H1],
exact H1
end,
iff.mp !neg_le_neg_iff_le H2
theorem mul_le_mul_of_nonpos_right (H : b ≤ a) (Hc : c ≤ 0) : a * c ≤ b * c :=
have Hc' : -c ≥ 0, from iff.mpr !neg_nonneg_iff_nonpos Hc,
assert H1 : b * -c ≤ a * -c, from mul_le_mul_of_nonneg_right H Hc',
have H2 : -(b * c) ≤ -(a * c),
begin
rewrite [-*neg_mul_eq_mul_neg at H1],
exact H1
end,
iff.mp !neg_le_neg_iff_le H2
theorem mul_nonneg_of_nonpos_of_nonpos (Ha : a ≤ 0) (Hb : b ≤ 0) : 0 ≤ a * b :=
begin
have H : 0 * b ≤ a * b, from mul_le_mul_of_nonpos_right Ha Hb,
rewrite zero_mul at H,
exact H
end
theorem mul_lt_mul_of_neg_left (H : b < a) (Hc : c < 0) : c * a < c * b :=
have Hc' : -c > 0, from iff.mpr !neg_pos_iff_neg Hc,
assert H1 : -c * b < -c * a, from mul_lt_mul_of_pos_left H Hc',
have H2 : -(c * b) < -(c * a),
begin
rewrite [-*neg_mul_eq_neg_mul at H1],
exact H1
end,
iff.mp !neg_lt_neg_iff_lt H2
theorem mul_lt_mul_of_neg_right (H : b < a) (Hc : c < 0) : a * c < b * c :=
have Hc' : -c > 0, from iff.mpr !neg_pos_iff_neg Hc,
assert H1 : b * -c < a * -c, from mul_lt_mul_of_pos_right H Hc',
have H2 : -(b * c) < -(a * c),
begin
rewrite [-*neg_mul_eq_mul_neg at H1],
exact H1
end,
iff.mp !neg_lt_neg_iff_lt H2
theorem mul_pos_of_neg_of_neg (Ha : a < 0) (Hb : b < 0) : 0 < a * b :=
begin
have H : 0 * b < a * b, from mul_lt_mul_of_neg_right Ha Hb,
rewrite zero_mul at H,
exact H
end
end
-- TODO: we can eliminate mul_pos_of_pos, but now it is not worth the effort to redeclare the
-- class instance
structure linear_ordered_ring [class] (A : Type)
extends ordered_ring A, linear_strong_order_pair A :=
(zero_lt_one : lt zero one)
definition linear_ordered_ring.to_linear_ordered_semiring [trans_instance] [reducible]
[s : linear_ordered_ring A] :
linear_ordered_semiring A :=
⦃ linear_ordered_semiring, s,
mul_zero := mul_zero,
zero_mul := zero_mul,
add_left_cancel := @add.left_cancel A _,
add_right_cancel := @add.right_cancel A _,
le_of_add_le_add_left := @le_of_add_le_add_left A _,
mul_le_mul_of_nonneg_left := @mul_le_mul_of_nonneg_left A _,
mul_le_mul_of_nonneg_right := @mul_le_mul_of_nonneg_right A _,
mul_lt_mul_of_pos_left := @mul_lt_mul_of_pos_left A _,
mul_lt_mul_of_pos_right := @mul_lt_mul_of_pos_right A _,
le_total := linear_ordered_ring.le_total,
lt_of_add_lt_add_left := @lt_of_add_lt_add_left A _ ⦄
structure linear_ordered_comm_ring [class] (A : Type) extends linear_ordered_ring A, comm_monoid A
theorem linear_ordered_comm_ring.eq_zero_or_eq_zero_of_mul_eq_zero [s : linear_ordered_comm_ring A]
{a b : A} (H : a * b = 0) : a = 0 ∨ b = 0 :=
lt.by_cases
(assume Ha : 0 < a,
lt.by_cases
(assume Hb : 0 < b,
begin
have H1 : 0 < a * b, from mul_pos Ha Hb,
rewrite H at H1,
apply absurd_a_lt_a H1
end)
(assume Hb : 0 = b, or.inr (Hb⁻¹))
(assume Hb : 0 > b,
begin
have H1 : 0 > a * b, from mul_neg_of_pos_of_neg Ha Hb,
rewrite H at H1,
apply absurd_a_lt_a H1
end))
(assume Ha : 0 = a, or.inl (Ha⁻¹))
(assume Ha : 0 > a,
lt.by_cases
(assume Hb : 0 < b,
begin
have H1 : 0 > a * b, from mul_neg_of_neg_of_pos Ha Hb,
rewrite H at H1,
apply absurd_a_lt_a H1
end)
(assume Hb : 0 = b, or.inr (Hb⁻¹))
(assume Hb : 0 > b,
begin
have H1 : 0 < a * b, from mul_pos_of_neg_of_neg Ha Hb,
rewrite H at H1,
apply absurd_a_lt_a H1
end))
-- Linearity implies no zero divisors. Doesn't need commutativity.
definition linear_ordered_comm_ring.to_integral_domain [trans_instance] [reducible]
[s: linear_ordered_comm_ring A] : integral_domain A :=
⦃ integral_domain, s,
eq_zero_or_eq_zero_of_mul_eq_zero :=
@linear_ordered_comm_ring.eq_zero_or_eq_zero_of_mul_eq_zero A s ⦄
section
variable [s : linear_ordered_ring A]
variables (a b c : A)
include s
theorem mul_self_nonneg : a * a ≥ 0 :=
or.elim (le.total 0 a)
(assume H : a ≥ 0, mul_nonneg H H)
(assume H : a ≤ 0, mul_nonneg_of_nonpos_of_nonpos H H)
theorem zero_le_one : 0 ≤ (1:A) := one_mul 1 ▸ mul_self_nonneg 1
theorem pos_and_pos_or_neg_and_neg_of_mul_pos {a b : A} (Hab : a * b > 0) :
(a > 0 ∧ b > 0) ∨ (a < 0 ∧ b < 0) :=
lt.by_cases
(assume Ha : 0 < a,
lt.by_cases
(assume Hb : 0 < b, or.inl (and.intro Ha Hb))
(assume Hb : 0 = b,
begin
rewrite [-Hb at Hab, mul_zero at Hab],
apply absurd_a_lt_a Hab
end)
(assume Hb : b < 0,
absurd Hab (lt.asymm (mul_neg_of_pos_of_neg Ha Hb))))
(assume Ha : 0 = a,
begin
rewrite [-Ha at Hab, zero_mul at Hab],
apply absurd_a_lt_a Hab
end)
(assume Ha : a < 0,
lt.by_cases
(assume Hb : 0 < b,
absurd Hab (lt.asymm (mul_neg_of_neg_of_pos Ha Hb)))
(assume Hb : 0 = b,
begin
rewrite [-Hb at Hab, mul_zero at Hab],
apply absurd_a_lt_a Hab
end)
(assume Hb : b < 0, or.inr (and.intro Ha Hb)))
theorem gt_of_mul_lt_mul_neg_left {a b c : A} (H : c * a < c * b) (Hc : c ≤ 0) : a > b :=
have nhc : -c ≥ 0, from neg_nonneg_of_nonpos Hc,
have H2 : -(c * b) < -(c * a), from iff.mpr (neg_lt_neg_iff_lt _ _) H,
have H3 : (-c) * b < (-c) * a, from calc
(-c) * b = - (c * b) : neg_mul_eq_neg_mul
... < -(c * a) : H2
... = (-c) * a : neg_mul_eq_neg_mul,
lt_of_mul_lt_mul_left H3 nhc
theorem zero_gt_neg_one : -1 < (0:A) :=
neg_zero ▸ (neg_lt_neg zero_lt_one)
theorem le_of_mul_le_of_ge_one {a b c : A} (H : a * c ≤ b) (Hb : b ≥ 0) (Hc : c ≥ 1) : a ≤ b :=
have H' : a * c ≤ b * c, from calc
a * c ≤ b : H
... = b * 1 : mul_one
... ≤ b * c : mul_le_mul_of_nonneg_left Hc Hb,
le_of_mul_le_mul_right H' (lt_of_lt_of_le zero_lt_one Hc)
theorem nonneg_le_nonneg_of_squares_le {a b : A} (Ha : a ≥ 0) (Hb : b ≥ 0) (H : a * a ≤ b * b) :
a ≤ b :=
begin
apply le_of_not_gt,
intro Hab,
let Hposa := lt_of_le_of_lt Hb Hab,
let H' := calc
b * b ≤ a * b : mul_le_mul_of_nonneg_right (le_of_lt Hab) Hb
... < a * a : mul_lt_mul_of_pos_left Hab Hposa,
apply (not_le_of_gt H') H
end
end
/- TODO: Isabelle's library has all kinds of cancelation rules for the simplifier.
Search on mult_le_cancel_right1 in Rings.thy. -/
structure decidable_linear_ordered_comm_ring [class] (A : Type) extends linear_ordered_comm_ring A,
decidable_linear_ordered_comm_group A
section
variable [s : decidable_linear_ordered_comm_ring A]
variables {a b c : A}
include s
definition sign (a : A) : A := lt.cases a 0 (-1) 0 1
theorem sign_of_neg (H : a < 0) : sign a = -1 := lt.cases_of_lt H
theorem sign_zero : sign 0 = (0:A) := lt.cases_of_eq rfl
theorem sign_of_pos (H : a > 0) : sign a = 1 := lt.cases_of_gt H
theorem sign_one : sign 1 = (1:A) := sign_of_pos zero_lt_one
theorem sign_neg_one : sign (-1) = -(1:A) := sign_of_neg (neg_neg_of_pos zero_lt_one)
theorem sign_sign (a : A) : sign (sign a) = sign a :=
lt.by_cases
(assume H : a > 0,
calc
sign (sign a) = sign 1 : by rewrite (sign_of_pos H)
... = 1 : by rewrite sign_one
... = sign a : by rewrite (sign_of_pos H))
(assume H : 0 = a,
calc
sign (sign a) = sign (sign 0) : by rewrite H
... = sign 0 : by rewrite sign_zero at {1}
... = sign a : by rewrite -H)
(assume H : a < 0,
calc
sign (sign a) = sign (-1) : by rewrite (sign_of_neg H)
... = -1 : by rewrite sign_neg_one
... = sign a : by rewrite (sign_of_neg H))
theorem pos_of_sign_eq_one (H : sign a = 1) : a > 0 :=
lt.by_cases
(assume H1 : 0 < a, H1)
(assume H1 : 0 = a,
begin
rewrite [-H1 at H, sign_zero at H],
apply absurd H zero_ne_one
end)
(assume H1 : 0 > a,
have H2 : -1 = 1, from (sign_of_neg H1)⁻¹ ⬝ H,
absurd ((eq_zero_of_neg_eq H2)⁻¹) zero_ne_one)
theorem eq_zero_of_sign_eq_zero (H : sign a = 0) : a = 0 :=
lt.by_cases
(assume H1 : 0 < a,
absurd (H⁻¹ ⬝ sign_of_pos H1) zero_ne_one)
(assume H1 : 0 = a, H1⁻¹)
(assume H1 : 0 > a,
have H2 : 0 = -1, from H⁻¹ ⬝ sign_of_neg H1,
have H3 : 1 = 0, from eq_neg_of_eq_neg H2 ⬝ neg_zero,
absurd (H3⁻¹) zero_ne_one)
theorem neg_of_sign_eq_neg_one (H : sign a = -1) : a < 0 :=
lt.by_cases
(assume H1 : 0 < a,
have H2 : -1 = 1, from H⁻¹ ⬝ (sign_of_pos H1),
absurd ((eq_zero_of_neg_eq H2)⁻¹) zero_ne_one)
(assume H1 : 0 = a,
have H2 : (0:A) = -1,
begin
rewrite [-H1 at H, sign_zero at H],
exact H
end,
have H3 : 1 = 0, from eq_neg_of_eq_neg H2 ⬝ neg_zero,
absurd (H3⁻¹) zero_ne_one)
(assume H1 : 0 > a, H1)
theorem sign_neg (a : A) : sign (-a) = -(sign a) :=
lt.by_cases
(assume H1 : 0 < a,
calc
sign (-a) = -1 : sign_of_neg (neg_neg_of_pos H1)
... = -(sign a) : by rewrite (sign_of_pos H1))
(assume H1 : 0 = a,
calc
sign (-a) = sign (-0) : by rewrite H1
... = sign 0 : by rewrite neg_zero
... = 0 : by rewrite sign_zero
... = -0 : by rewrite neg_zero
... = -(sign 0) : by rewrite sign_zero
... = -(sign a) : by rewrite -H1)
(assume H1 : 0 > a,
calc
sign (-a) = 1 : sign_of_pos (neg_pos_of_neg H1)
... = -(-1) : by rewrite neg_neg
... = -(sign a) : sign_of_neg H1)
theorem sign_mul (a b : A) : sign (a * b) = sign a * sign b :=
lt.by_cases
(assume z_lt_a : 0 < a,
lt.by_cases
(assume z_lt_b : 0 < b,
by rewrite [sign_of_pos z_lt_a, sign_of_pos z_lt_b,
sign_of_pos (mul_pos z_lt_a z_lt_b), one_mul])
(assume z_eq_b : 0 = b, by rewrite [-z_eq_b, mul_zero, *sign_zero, mul_zero])
(assume z_gt_b : 0 > b,
by rewrite [sign_of_pos z_lt_a, sign_of_neg z_gt_b,
sign_of_neg (mul_neg_of_pos_of_neg z_lt_a z_gt_b), one_mul]))
(assume z_eq_a : 0 = a, by rewrite [-z_eq_a, zero_mul, *sign_zero, zero_mul])
(assume z_gt_a : 0 > a,
lt.by_cases
(assume z_lt_b : 0 < b,
by rewrite [sign_of_neg z_gt_a, sign_of_pos z_lt_b,
sign_of_neg (mul_neg_of_neg_of_pos z_gt_a z_lt_b), mul_one])
(assume z_eq_b : 0 = b, by rewrite [-z_eq_b, mul_zero, *sign_zero, mul_zero])
(assume z_gt_b : 0 > b,
by rewrite [sign_of_neg z_gt_a, sign_of_neg z_gt_b,
sign_of_pos (mul_pos_of_neg_of_neg z_gt_a z_gt_b),
neg_mul_neg, one_mul]))
theorem abs_eq_sign_mul (a : A) : abs a = sign a * a :=
lt.by_cases
(assume H1 : 0 < a,
calc
abs a = a : abs_of_pos H1
... = 1 * a : by rewrite one_mul
... = sign a * a : by rewrite (sign_of_pos H1))
(assume H1 : 0 = a,
calc
abs a = abs 0 : by rewrite H1
... = 0 : by rewrite abs_zero
... = 0 * a : by rewrite zero_mul
... = sign 0 * a : by rewrite sign_zero
... = sign a * a : by rewrite H1)
(assume H1 : a < 0,
calc
abs a = -a : abs_of_neg H1
... = -1 * a : by rewrite neg_eq_neg_one_mul
... = sign a * a : by rewrite (sign_of_neg H1))
theorem eq_sign_mul_abs (a : A) : a = sign a * abs a :=
lt.by_cases
(assume H1 : 0 < a,
calc
a = abs a : abs_of_pos H1
... = 1 * abs a : by rewrite one_mul
... = sign a * abs a : by rewrite (sign_of_pos H1))
(assume H1 : 0 = a,
calc
a = 0 : H1⁻¹
... = 0 * abs a : by rewrite zero_mul
... = sign 0 * abs a : by rewrite sign_zero
... = sign a * abs a : by rewrite H1)
(assume H1 : a < 0,
calc
a = -(-a) : by rewrite neg_neg
... = -abs a : by rewrite (abs_of_neg H1)
... = -1 * abs a : by rewrite neg_eq_neg_one_mul
... = sign a * abs a : by rewrite (sign_of_neg H1))
theorem abs_dvd_iff (a b : A) : abs a ∣ b ↔ a ∣ b :=
abs.by_cases !iff.refl !neg_dvd_iff_dvd
theorem abs_dvd_of_dvd {a b : A} : a ∣ b → abs a ∣ b :=
iff.mpr !abs_dvd_iff
theorem dvd_abs_iff (a b : A) : a ∣ abs b ↔ a ∣ b :=
abs.by_cases !iff.refl !dvd_neg_iff_dvd
theorem dvd_abs_of_dvd {a b : A} : a ∣ b → a ∣ abs b :=
iff.mpr !dvd_abs_iff
theorem abs_mul (a b : A) : abs (a * b) = abs a * abs b :=
or.elim (le.total 0 a)
(assume H1 : 0 ≤ a,
or.elim (le.total 0 b)
(assume H2 : 0 ≤ b,
calc
abs (a * b) = a * b : abs_of_nonneg (mul_nonneg H1 H2)
... = abs a * b : by rewrite (abs_of_nonneg H1)
... = abs a * abs b : by rewrite (abs_of_nonneg H2))
(assume H2 : b ≤ 0,
calc
abs (a * b) = -(a * b) : abs_of_nonpos (mul_nonpos_of_nonneg_of_nonpos H1 H2)
... = a * -b : by rewrite neg_mul_eq_mul_neg
... = abs a * -b : by rewrite (abs_of_nonneg H1)
... = abs a * abs b : by rewrite (abs_of_nonpos H2)))
(assume H1 : a ≤ 0,
or.elim (le.total 0 b)
(assume H2 : 0 ≤ b,
calc
abs (a * b) = -(a * b) : abs_of_nonpos (mul_nonpos_of_nonpos_of_nonneg H1 H2)
... = -a * b : by rewrite neg_mul_eq_neg_mul
... = abs a * b : by rewrite (abs_of_nonpos H1)
... = abs a * abs b : by rewrite (abs_of_nonneg H2))
(assume H2 : b ≤ 0,
calc
abs (a * b) = a * b : abs_of_nonneg (mul_nonneg_of_nonpos_of_nonpos H1 H2)
... = -a * -b : by rewrite neg_mul_neg
... = abs a * -b : by rewrite (abs_of_nonpos H1)
... = abs a * abs b : by rewrite (abs_of_nonpos H2)))
theorem abs_mul_abs_self (a : A) : abs a * abs a = a * a :=
abs.by_cases rfl !neg_mul_neg
theorem abs_mul_self (a : A) : abs (a * a) = a * a :=
by rewrite [abs_mul, abs_mul_abs_self]
theorem sub_le_of_abs_sub_le_left (H : abs (a - b) ≤ c) : b - c ≤ a :=
if Hz : 0 ≤ a - b then
(calc
a ≥ b : (iff.mp !sub_nonneg_iff_le) Hz
... ≥ b - c : sub_le_of_nonneg _ (le.trans !abs_nonneg H))
else
(have Habs : b - a ≤ c, by rewrite [abs_of_neg (lt_of_not_ge Hz) at H, neg_sub at H]; apply H,
have Habs' : b ≤ c + a, from (iff.mpr !le_add_iff_sub_right_le) Habs,
(iff.mp !le_add_iff_sub_left_le) Habs')
theorem sub_le_of_abs_sub_le_right (H : abs (a - b) ≤ c) : a - c ≤ b :=
sub_le_of_abs_sub_le_left (!abs_sub ▸ H)
theorem sub_lt_of_abs_sub_lt_left (H : abs (a - b) < c) : b - c < a :=
if Hz : 0 ≤ a - b then
(calc
a ≥ b : (iff.mp !sub_nonneg_iff_le) Hz
... > b - c : sub_lt_of_pos _ (lt_of_le_of_lt !abs_nonneg H))
else
(have Habs : b - a < c, by rewrite [abs_of_neg (lt_of_not_ge Hz) at H, neg_sub at H]; apply H,
have Habs' : b < c + a, from lt_add_of_sub_lt_right Habs,
sub_lt_left_of_lt_add Habs')
theorem sub_lt_of_abs_sub_lt_right (H : abs (a - b) < c) : a - c < b :=
sub_lt_of_abs_sub_lt_left (!abs_sub ▸ H)
theorem abs_sub_square (a b : A) : abs (a - b) * abs (a - b) = a * a + b * b - (1 + 1) * a * b :=
begin
rewrite [abs_mul_abs_self, *mul_sub_left_distrib, *mul_sub_right_distrib,
sub_eq_add_neg (a*b), sub_add_eq_sub_sub, sub_neg_eq_add, *right_distrib, sub_add_eq_sub_sub, *one_mul,
*add.assoc, {_ + b * b}add.comm, *sub_eq_add_neg],
rewrite [{a*a + b*b}add.comm],
rewrite [mul.comm b a, *add.assoc]
end
theorem abs_abs_sub_abs_le_abs_sub (a b : A) : abs (abs a - abs b) ≤ abs (a - b) :=
begin
apply nonneg_le_nonneg_of_squares_le,
repeat apply abs_nonneg,
rewrite [*abs_sub_square, *abs_abs, *abs_mul_abs_self],
apply sub_le_sub_left,
rewrite *mul.assoc,
apply mul_le_mul_of_nonneg_left,
rewrite -abs_mul,
apply le_abs_self,
apply le_of_lt,
apply add_pos,
apply zero_lt_one,
apply zero_lt_one
end
end
/- TODO: Multiplication and one, starting with mult_right_le_one_le. -/
end algebra
|
f49d259cf461bcf8132097e5129a41bd26dd5483 | 367134ba5a65885e863bdc4507601606690974c1 | /src/analysis/normed_space/hahn_banach.lean | e13fbce7a47f0fcf9c45976d3399d90e092e77f2 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 6,989 | lean | /-
Copyright (c) 2020 Yury Kudryashov All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Heather Macbeth
-/
import analysis.normed_space.operator_norm
import analysis.normed_space.extend
import analysis.convex.cone
import data.complex.is_R_or_C
/-!
# Hahn-Banach theorem
In this file we prove a version of Hahn-Banach theorem for continuous linear
functions on normed spaces over `ℝ` and `ℂ`.
In order to state and prove its corollaries uniformly, we prove the statements for a field `𝕜`
satisfying `is_R_or_C 𝕜`.
In this setting, `exists_dual_vector` states that, for any nonzero `x`, there exists a continuous
linear form `g` of norm `1` with `g x = ∥x∥` (where the norm has to be interpreted as an element
of `𝕜`).
-/
universes u v
/--
The norm of `x` as an element of `𝕜` (a normed algebra over `ℝ`). This is needed in particular to
state equalities of the form `g x = norm' 𝕜 x` when `g` is a linear function.
For the concrete cases of `ℝ` and `ℂ`, this is just `∥x∥` and `↑∥x∥`, respectively.
-/
noncomputable def norm' (𝕜 : Type*) [nondiscrete_normed_field 𝕜] [normed_algebra ℝ 𝕜]
{E : Type*} [normed_group E] (x : E) : 𝕜 :=
algebra_map ℝ 𝕜 ∥x∥
lemma norm'_def (𝕜 : Type*) [nondiscrete_normed_field 𝕜] [normed_algebra ℝ 𝕜]
{E : Type*} [normed_group E] (x : E) :
norm' 𝕜 x = (algebra_map ℝ 𝕜 ∥x∥) := rfl
lemma norm_norm'
(𝕜 : Type*) [nondiscrete_normed_field 𝕜] [normed_algebra ℝ 𝕜]
(A : Type*) [normed_group A]
(x : A) : ∥norm' 𝕜 x∥ = ∥x∥ :=
by rw [norm'_def, norm_algebra_map_eq, norm_norm]
namespace real
variables {E : Type*} [normed_group E] [normed_space ℝ E]
/-- Hahn-Banach theorem for continuous linear functions over `ℝ`. -/
theorem exists_extension_norm_eq (p : subspace ℝ E) (f : p →L[ℝ] ℝ) :
∃ g : E →L[ℝ] ℝ, (∀ x : p, g x = f x) ∧ ∥g∥ = ∥f∥ :=
begin
rcases exists_extension_of_le_sublinear ⟨p, f⟩ (λ x, ∥f∥ * ∥x∥)
(λ c hc x, by simp only [norm_smul c x, real.norm_eq_abs, abs_of_pos hc, mul_left_comm])
(λ x y, _) (λ x, le_trans (le_abs_self _) (f.le_op_norm _))
with ⟨g, g_eq, g_le⟩,
set g' := g.mk_continuous (∥f∥)
(λ x, abs_le.2 ⟨neg_le.1 $ g.map_neg x ▸ norm_neg x ▸ g_le (-x), g_le x⟩),
{ refine ⟨g', g_eq, _⟩,
{ apply le_antisymm (g.mk_continuous_norm_le (norm_nonneg f) _),
refine f.op_norm_le_bound (norm_nonneg _) (λ x, _),
dsimp at g_eq,
rw ← g_eq,
apply g'.le_op_norm } },
{ simp only [← mul_add],
exact mul_le_mul_of_nonneg_left (norm_add_le x y) (norm_nonneg f) }
end
end real
section is_R_or_C
open is_R_or_C
variables {𝕜 : Type*} [is_R_or_C 𝕜] {F : Type*} [normed_group F] [normed_space 𝕜 F]
/-- Hahn-Banach theorem for continuous linear functions over `𝕜` satisyfing `is_R_or_C 𝕜`. -/
theorem exists_extension_norm_eq (p : subspace 𝕜 F) (f : p →L[𝕜] 𝕜) :
∃ g : F →L[𝕜] 𝕜, (∀ x : p, g x = f x) ∧ ∥g∥ = ∥f∥ :=
begin
letI : module ℝ F := restrict_scalars.semimodule ℝ 𝕜 F,
letI : is_scalar_tower ℝ 𝕜 F := restrict_scalars.is_scalar_tower _ _ _,
letI : normed_space ℝ F := normed_space.restrict_scalars _ 𝕜 _,
letI : normed_space ℝ p := (by apply_instance : normed_space ℝ (submodule.restrict_scalars ℝ p)),
-- Let `fr: p →L[ℝ] ℝ` be the real part of `f`.
let fr := re_clm.comp (f.restrict_scalars ℝ),
have fr_apply : ∀ x, fr x = re (f x) := λ x, rfl,
-- Use the real version to get a norm-preserving extension of `fr`, which
-- we'll call `g : F →L[ℝ] ℝ`.
rcases real.exists_extension_norm_eq (p.restrict_scalars ℝ) fr with ⟨g, ⟨hextends, hnormeq⟩⟩,
-- Now `g` can be extended to the `F →L[𝕜] 𝕜` we need.
use g.extend_to_𝕜,
-- It is an extension of `f`.
have h : ∀ x : p, g.extend_to_𝕜 x = f x,
{ assume x,
change (g (x : F) : 𝕜) - (I : 𝕜) * g ((((I : 𝕜) • x) : p) : F) = f x,
rw [hextends, hextends],
change (re (f x) : 𝕜) - (I : 𝕜) * (re (f ((I : 𝕜) • x))) = f x,
apply ext,
{ simp only [add_zero, algebra.id.smul_eq_mul, I_re, of_real_im, add_monoid_hom.map_add,
zero_sub, I_im', zero_mul, of_real_re, eq_self_iff_true, sub_zero, mul_neg_eq_neg_mul_symm,
of_real_neg, mul_re, mul_zero, sub_neg_eq_add, continuous_linear_map.map_smul] },
{ simp only [algebra.id.smul_eq_mul, I_re, of_real_im, add_monoid_hom.map_add, zero_sub, I_im',
zero_mul, of_real_re, mul_neg_eq_neg_mul_symm, mul_im, zero_add, of_real_neg, mul_re,
sub_neg_eq_add, continuous_linear_map.map_smul] } },
refine ⟨h, _⟩,
-- And we derive the equality of the norms by bounding on both sides.
refine le_antisymm _ _,
{ calc ∥g.extend_to_𝕜∥
≤ ∥g∥ : g.extend_to_𝕜.op_norm_le_bound g.op_norm_nonneg (norm_bound _)
... = ∥fr∥ : hnormeq
... ≤ ∥re_clm∥ * ∥f∥ : continuous_linear_map.op_norm_comp_le _ _
... = ∥f∥ : by rw [re_clm_norm, one_mul] },
{ exact f.op_norm_le_bound g.extend_to_𝕜.op_norm_nonneg (λ x, h x ▸ g.extend_to_𝕜.le_op_norm x) },
end
end is_R_or_C
section dual_vector
variables {𝕜 : Type v} [is_R_or_C 𝕜]
variables {E : Type u} [normed_group E] [normed_space 𝕜 E]
open continuous_linear_equiv submodule
open_locale classical
lemma coord_norm' (x : E) (h : x ≠ 0) : ∥norm' 𝕜 x • coord 𝕜 x h∥ = 1 :=
by rw [norm_smul, norm_norm', coord_norm, mul_inv_cancel (mt norm_eq_zero.mp h)]
/-- Corollary of Hahn-Banach. Given a nonzero element `x` of a normed space, there exists an
element of the dual space, of norm `1`, whose value on `x` is `∥x∥`. -/
theorem exists_dual_vector (x : E) (h : x ≠ 0) : ∃ g : E →L[𝕜] 𝕜, ∥g∥ = 1 ∧ g x = norm' 𝕜 x :=
begin
let p : submodule 𝕜 E := 𝕜 ∙ x,
let f := norm' 𝕜 x • coord 𝕜 x h,
obtain ⟨g, hg⟩ := exists_extension_norm_eq p f,
use g, split,
{ rw [hg.2, coord_norm'] },
{ calc g x = g (⟨x, mem_span_singleton_self x⟩ : 𝕜 ∙ x) : by rw coe_mk
... = (norm' 𝕜 x • coord 𝕜 x h) (⟨x, mem_span_singleton_self x⟩ : 𝕜 ∙ x) : by rw ← hg.1
... = norm' 𝕜 x : by simp }
end
/-- Variant of Hahn-Banach, eliminating the hypothesis that `x` be nonzero, and choosing
the dual element arbitrarily when `x = 0`. -/
theorem exists_dual_vector' [nontrivial E] (x : E) :
∃ g : E →L[𝕜] 𝕜, ∥g∥ = 1 ∧ g x = norm' 𝕜 x :=
begin
by_cases hx : x = 0,
{ obtain ⟨y, hy⟩ := exists_ne (0 : E),
obtain ⟨g, hg⟩ : ∃ g : E →L[𝕜] 𝕜, ∥g∥ = 1 ∧ g y = norm' 𝕜 y := exists_dual_vector y hy,
refine ⟨g, hg.left, _⟩,
rw [norm'_def, hx, norm_zero, ring_hom.map_zero, continuous_linear_map.map_zero] },
{ exact exists_dual_vector x hx }
end
end dual_vector
|
d004e13b78f3a57e4597ec1195f3512b8e9aac8a | d1a52c3f208fa42c41df8278c3d280f075eb020c | /src/Lean/Meta/AppBuilder.lean | 09f1bc978aa11ef461e839a6baf2be47c4fed8ea | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | cipher1024/lean4 | 6e1f98bb58e7a92b28f5364eb38a14c8d0aae393 | 69114d3b50806264ef35b57394391c3e738a9822 | refs/heads/master | 1,642,227,983,603 | 1,642,011,696,000 | 1,642,011,696,000 | 228,607,691 | 0 | 0 | Apache-2.0 | 1,576,584,269,000 | 1,576,584,268,000 | null | UTF-8 | Lean | false | false | 20,848 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Structure
import Lean.Util.Recognizers
import Lean.Meta.SynthInstance
import Lean.Meta.Check
import Lean.Meta.DecLevel
namespace Lean.Meta
/-- Return `id e` -/
def mkId (e : Expr) : MetaM Expr := do
let type ← inferType e
let u ← getLevel type
return mkApp2 (mkConst ``id [u]) type e
/--
Given `e` s.t. `inferType e` is definitionally equal to `expectedType`, return
term `@id expectedType e`. -/
def mkExpectedTypeHint (e : Expr) (expectedType : Expr) : MetaM Expr := do
let u ← getLevel expectedType
return mkApp2 (mkConst ``id [u]) expectedType e
def mkEq (a b : Expr) : MetaM Expr := do
let aType ← inferType a
let u ← getLevel aType
return mkApp3 (mkConst ``Eq [u]) aType a b
def mkHEq (a b : Expr) : MetaM Expr := do
let aType ← inferType a
let bType ← inferType b
let u ← getLevel aType
return mkApp4 (mkConst ``HEq [u]) aType a bType b
def mkEqRefl (a : Expr) : MetaM Expr := do
let aType ← inferType a
let u ← getLevel aType
return mkApp2 (mkConst ``Eq.refl [u]) aType a
def mkHEqRefl (a : Expr) : MetaM Expr := do
let aType ← inferType a
let u ← getLevel aType
return mkApp2 (mkConst ``HEq.refl [u]) aType a
def mkAbsurd (e : Expr) (hp hnp : Expr) : MetaM Expr := do
let p ← inferType hp
let u ← getLevel e
return mkApp4 (mkConst ``absurd [u]) p e hp hnp
def mkFalseElim (e : Expr) (h : Expr) : MetaM Expr := do
let u ← getLevel e
return mkApp2 (mkConst ``False.elim [u]) e h
private def infer (h : Expr) : MetaM Expr := do
let hType ← inferType h
whnfD hType
private def hasTypeMsg (e type : Expr) : MessageData :=
m!"{indentExpr e}\nhas type{indentExpr type}"
private def throwAppBuilderException {α} (op : Name) (msg : MessageData) : MetaM α :=
throwError "AppBuilder for '{op}', {msg}"
def mkEqSymm (h : Expr) : MetaM Expr := do
if h.isAppOf ``Eq.refl then
return h
else
let hType ← infer h
match hType.eq? with
| some (α, a, b) =>
let u ← getLevel α
return mkApp4 (mkConst ``Eq.symm [u]) α a b h
| none => throwAppBuilderException ``Eq.symm ("equality proof expected" ++ hasTypeMsg h hType)
def mkEqTrans (h₁ h₂ : Expr) : MetaM Expr := do
if h₁.isAppOf ``Eq.refl then
return h₂
else if h₂.isAppOf ``Eq.refl then
return h₁
else
let hType₁ ← infer h₁
let hType₂ ← infer h₂
match hType₁.eq?, hType₂.eq? with
| some (α, a, b), some (_, _, c) =>
let u ← getLevel α
return mkApp6 (mkConst ``Eq.trans [u]) α a b c h₁ h₂
| none, _ => throwAppBuilderException ``Eq.trans ("equality proof expected" ++ hasTypeMsg h₁ hType₁)
| _, none => throwAppBuilderException ``Eq.trans ("equality proof expected" ++ hasTypeMsg h₂ hType₂)
def mkHEqSymm (h : Expr) : MetaM Expr := do
if h.isAppOf ``HEq.refl then
return h
else
let hType ← infer h
match hType.heq? with
| some (α, a, β, b) =>
let u ← getLevel α
return mkApp5 (mkConst ``HEq.symm [u]) α β a b h
| none =>
throwAppBuilderException ``HEq.symm ("heterogeneous equality proof expected" ++ hasTypeMsg h hType)
def mkHEqTrans (h₁ h₂ : Expr) : MetaM Expr := do
if h₁.isAppOf ``HEq.refl then
return h₂
else if h₂.isAppOf ``HEq.refl then
return h₁
else
let hType₁ ← infer h₁
let hType₂ ← infer h₂
match hType₁.heq?, hType₂.heq? with
| some (α, a, β, b), some (_, _, γ, c) =>
let u ← getLevel α
return mkApp8 (mkConst ``HEq.trans [u]) α β γ a b c h₁ h₂
| none, _ => throwAppBuilderException ``HEq.trans ("heterogeneous equality proof expected" ++ hasTypeMsg h₁ hType₁)
| _, none => throwAppBuilderException ``HEq.trans ("heterogeneous equality proof expected" ++ hasTypeMsg h₂ hType₂)
def mkEqOfHEq (h : Expr) : MetaM Expr := do
let hType ← infer h
match hType.heq? with
| some (α, a, β, b) =>
unless (← isDefEq α β) do
throwAppBuilderException ``eq_of_heq m!"heterogeneous equality types are not definitionally equal{indentExpr α}\nis not definitionally equal to{indentExpr β}"
let u ← getLevel α
return mkApp4 (mkConst ``eq_of_heq [u]) α a b h
| _ =>
throwAppBuilderException ``HEq.trans m!"heterogeneous equality proof expected{indentExpr h}"
def mkCongrArg (f h : Expr) : MetaM Expr := do
if h.isAppOf ``Eq.refl then
mkEqRefl (mkApp f h.appArg!)
else
let hType ← infer h
let fType ← infer f
match fType.arrow?, hType.eq? with
| some (α, β), some (_, a, b) =>
let u ← getLevel α
let v ← getLevel β
return mkApp6 (mkConst ``congrArg [u, v]) α β a b f h
| none, _ => throwAppBuilderException ``congrArg ("non-dependent function expected" ++ hasTypeMsg f fType)
| _, none => throwAppBuilderException ``congrArg ("equality proof expected" ++ hasTypeMsg h hType)
def mkCongrFun (h a : Expr) : MetaM Expr := do
if h.isAppOf ``Eq.refl then
mkEqRefl (mkApp h.appArg! a)
else
let hType ← infer h
match hType.eq? with
| some (ρ, f, g) => do
let ρ ← whnfD ρ
match ρ with
| Expr.forallE n α β _ =>
let β' := Lean.mkLambda n BinderInfo.default α β
let u ← getLevel α
let v ← getLevel (mkApp β' a)
return mkApp6 (mkConst ``congrFun [u, v]) α β' f g h a
| _ => throwAppBuilderException ``congrFun ("equality proof between functions expected" ++ hasTypeMsg h hType)
| _ => throwAppBuilderException ``congrFun ("equality proof expected" ++ hasTypeMsg h hType)
def mkCongr (h₁ h₂ : Expr) : MetaM Expr := do
if h₁.isAppOf ``Eq.refl then
mkCongrArg h₁.appArg! h₂
else if h₂.isAppOf ``Eq.refl then
mkCongrFun h₁ h₂.appArg!
else
let hType₁ ← infer h₁
let hType₂ ← infer h₂
match hType₁.eq?, hType₂.eq? with
| some (ρ, f, g), some (α, a, b) =>
let ρ ← whnfD ρ
match ρ.arrow? with
| some (_, β) => do
let u ← getLevel α
let v ← getLevel β
return mkApp8 (mkConst ``congr [u, v]) α β f g a b h₁ h₂
| _ => throwAppBuilderException ``congr ("non-dependent function expected" ++ hasTypeMsg h₁ hType₁)
| none, _ => throwAppBuilderException ``congr ("equality proof expected" ++ hasTypeMsg h₁ hType₁)
| _, none => throwAppBuilderException ``congr ("equality proof expected" ++ hasTypeMsg h₂ hType₂)
private def mkAppMFinal (methodName : Name) (f : Expr) (args : Array Expr) (instMVars : Array MVarId) : MetaM Expr := do
instMVars.forM fun mvarId => do
let mvarDecl ← getMVarDecl mvarId
let mvarVal ← synthInstance mvarDecl.type
assignExprMVar mvarId mvarVal
let result ← instantiateMVars (mkAppN f args)
if (← hasAssignableMVar result) then throwAppBuilderException methodName ("result contains metavariables" ++ indentExpr result)
return result
private partial def mkAppMArgs (f : Expr) (fType : Expr) (xs : Array Expr) : MetaM Expr :=
let rec loop (type : Expr) (i : Nat) (j : Nat) (args : Array Expr) (instMVars : Array MVarId) : MetaM Expr := do
if i >= xs.size then
mkAppMFinal `mkAppM f args instMVars
else match type with
| Expr.forallE n d b c =>
let d := d.instantiateRevRange j args.size args
match c.binderInfo with
| BinderInfo.implicit =>
let mvar ← mkFreshExprMVar d MetavarKind.natural n
loop b i j (args.push mvar) instMVars
| BinderInfo.strictImplicit =>
let mvar ← mkFreshExprMVar d MetavarKind.natural n
loop b i j (args.push mvar) instMVars
| BinderInfo.instImplicit =>
let mvar ← mkFreshExprMVar d MetavarKind.synthetic n
loop b i j (args.push mvar) (instMVars.push mvar.mvarId!)
| _ =>
let x := xs[i]
let xType ← inferType x
if (← isDefEq d xType) then
loop b (i+1) j (args.push x) instMVars
else
throwAppTypeMismatch (mkAppN f args) x
| type =>
let type := type.instantiateRevRange j args.size args
let type ← whnfD type
if type.isForall then
loop type i args.size args instMVars
else
throwAppBuilderException `mkAppM m!"too many explicit arguments provided to{indentExpr f}\narguments{indentD xs}"
loop fType 0 0 #[] #[]
private def mkFun (constName : Name) : MetaM (Expr × Expr) := do
let cinfo ← getConstInfo constName
let us ← cinfo.levelParams.mapM fun _ => mkFreshLevelMVar
let f := mkConst constName us
let fType := cinfo.instantiateTypeLevelParams us
return (f, fType)
/--
Return the application `constName xs`.
It tries to fill the implicit arguments before the last element in `xs`.
Remark:
``mkAppM `arbitrary #[α]`` returns `@arbitrary.{u} α` without synthesizing
the implicit argument occurring after `α`.
Given a `x : (([Decidable p] → Bool) × Nat`, ``mkAppM `Prod.fst #[x]`` returns `@Prod.fst ([Decidable p] → Bool) Nat x`
-/
def mkAppM (constName : Name) (xs : Array Expr) : MetaM Expr := do
traceCtx `Meta.appBuilder <| withNewMCtxDepth do
let (f, fType) ← mkFun constName
let r ← mkAppMArgs f fType xs
trace[Meta.appBuilder] "constName: {constName}, xs: {xs}, result: {r}"
return r
/-- Similar to `mkAppM`, but takes an `Expr` instead of a constant name. -/
def mkAppM' (f : Expr) (xs : Array Expr) : MetaM Expr := do
let fType ← inferType f
traceCtx `Meta.appBuilder <| withNewMCtxDepth do
let r ← mkAppMArgs f fType xs
trace[Meta.appBuilder] "f: {f}, xs: {xs}, result: {r}"
return r
private partial def mkAppOptMAux (f : Expr) (xs : Array (Option Expr)) : Nat → Array Expr → Nat → Array MVarId → Expr → MetaM Expr
| i, args, j, instMVars, Expr.forallE n d b c => do
let d := d.instantiateRevRange j args.size args
if h : i < xs.size then
match xs.get ⟨i, h⟩ with
| none =>
match c.binderInfo with
| BinderInfo.instImplicit => do
let mvar ← mkFreshExprMVar d MetavarKind.synthetic n
mkAppOptMAux f xs (i+1) (args.push mvar) j (instMVars.push mvar.mvarId!) b
| _ => do
let mvar ← mkFreshExprMVar d MetavarKind.natural n
mkAppOptMAux f xs (i+1) (args.push mvar) j instMVars b
| some x =>
let xType ← inferType x
if (← isDefEq d xType) then
mkAppOptMAux f xs (i+1) (args.push x) j instMVars b
else
throwAppTypeMismatch (mkAppN f args) x
else
mkAppMFinal `mkAppOptM f args instMVars
| i, args, j, instMVars, type => do
let type := type.instantiateRevRange j args.size args
let type ← whnfD type
if type.isForall then
mkAppOptMAux f xs i args args.size instMVars type
else if i == xs.size then
mkAppMFinal `mkAppOptM f args instMVars
else do
let xs : Array Expr := xs.foldl (fun r x? => match x? with | none => r | some x => r.push x) #[]
throwAppBuilderException `mkAppOptM ("too many arguments provided to" ++ indentExpr f ++ Format.line ++ "arguments" ++ xs)
/--
Similar to `mkAppM`, but it allows us to specify which arguments are provided explicitly using `Option` type.
Example:
Given `Pure.pure {m : Type u → Type v} [Pure m] {α : Type u} (a : α) : m α`,
```
mkAppOptM `Pure.pure #[m, none, none, a]
```
returns a `Pure.pure` application if the instance `Pure m` can be synthesized, and the universe match.
Note that,
```
mkAppM `Pure.pure #[a]
```
fails because the only explicit argument `(a : α)` is not sufficient for inferring the remaining arguments,
we would need the expected type. -/
def mkAppOptM (constName : Name) (xs : Array (Option Expr)) : MetaM Expr := do
traceCtx `Meta.appBuilder <| withNewMCtxDepth do
let (f, fType) ← mkFun constName
mkAppOptMAux f xs 0 #[] 0 #[] fType
/-- Similar to `mkAppOptM`, but takes an `Expr` instead of a constant name -/
def mkAppOptM' (f : Expr) (xs : Array (Option Expr)) : MetaM Expr := do
let fType ← inferType f
traceCtx `Meta.appBuilder <| withNewMCtxDepth do
mkAppOptMAux f xs 0 #[] 0 #[] fType
def mkEqNDRec (motive h1 h2 : Expr) : MetaM Expr := do
if h2.isAppOf ``Eq.refl then
return h1
else
let h2Type ← infer h2
match h2Type.eq? with
| none => throwAppBuilderException ``Eq.ndrec ("equality proof expected" ++ hasTypeMsg h2 h2Type)
| some (α, a, b) =>
let u2 ← getLevel α
let motiveType ← infer motive
match motiveType with
| Expr.forallE _ _ (Expr.sort u1 _) _ =>
return mkAppN (mkConst ``Eq.ndrec [u1, u2]) #[α, a, motive, h1, b, h2]
| _ => throwAppBuilderException ``Eq.ndrec ("invalid motive" ++ indentExpr motive)
def mkEqRec (motive h1 h2 : Expr) : MetaM Expr := do
if h2.isAppOf ``Eq.refl then
return h1
else
let h2Type ← infer h2
match h2Type.eq? with
| none => throwAppBuilderException ``Eq.rec ("equality proof expected" ++ indentExpr h2)
| some (α, a, b) =>
let u2 ← getLevel α
let motiveType ← infer motive
match motiveType with
| Expr.forallE _ _ (Expr.forallE _ _ (Expr.sort u1 _) _) _ =>
return mkAppN (mkConst ``Eq.rec [u1, u2]) #[α, a, motive, h1, b, h2]
| _ =>
throwAppBuilderException ``Eq.rec ("invalid motive" ++ indentExpr motive)
def mkEqMP (eqProof pr : Expr) : MetaM Expr :=
mkAppM ``Eq.mp #[eqProof, pr]
def mkEqMPR (eqProof pr : Expr) : MetaM Expr :=
mkAppM ``Eq.mpr #[eqProof, pr]
def mkNoConfusion (target : Expr) (h : Expr) : MetaM Expr := do
let type ← inferType h
let type ← whnf type
match type.eq? with
| none => throwAppBuilderException `noConfusion ("equality expected" ++ hasTypeMsg h type)
| some (α, a, b) =>
let α ← whnf α
matchConstInduct α.getAppFn (fun _ => throwAppBuilderException `noConfusion ("inductive type expected" ++ indentExpr α)) fun v us => do
let u ← getLevel target
return mkAppN (mkConst (Name.mkStr v.name "noConfusion") (u :: us)) (α.getAppArgs ++ #[target, a, b, h])
def mkPure (monad : Expr) (e : Expr) : MetaM Expr :=
mkAppOptM ``Pure.pure #[monad, none, none, e]
/--
`mkProjection s fieldName` return an expression for accessing field `fieldName` of the structure `s`.
Remark: `fieldName` may be a subfield of `s`. -/
partial def mkProjection : Expr → Name → MetaM Expr
| s, fieldName => do
let type ← inferType s
let type ← whnf type
match type.getAppFn with
| Expr.const structName us _ =>
let env ← getEnv
unless isStructure env structName do
throwAppBuilderException `mkProjection ("structure expected" ++ hasTypeMsg s type)
match getProjFnForField? env structName fieldName with
| some projFn =>
let params := type.getAppArgs
return mkApp (mkAppN (mkConst projFn us) params) s
| none =>
let fields := getStructureFields env structName
let r? ← fields.findSomeM? fun fieldName' => do
match isSubobjectField? env structName fieldName' with
| none => pure none
| some _ =>
let parent ← mkProjection s fieldName'
(do let r ← mkProjection parent fieldName; return some r)
<|>
pure none
match r? with
| some r => pure r
| none => throwAppBuilderException `mkProjectionn ("invalid field name '" ++ toString fieldName ++ "' for" ++ hasTypeMsg s type)
| _ => throwAppBuilderException `mkProjectionn ("structure expected" ++ hasTypeMsg s type)
private def mkListLitAux (nil : Expr) (cons : Expr) : List Expr → Expr
| [] => nil
| x::xs => mkApp (mkApp cons x) (mkListLitAux nil cons xs)
def mkListLit (type : Expr) (xs : List Expr) : MetaM Expr := do
let u ← getDecLevel type
let nil := mkApp (mkConst ``List.nil [u]) type
match xs with
| [] => return nil
| _ =>
let cons := mkApp (mkConst ``List.cons [u]) type
return mkListLitAux nil cons xs
def mkArrayLit (type : Expr) (xs : List Expr) : MetaM Expr := do
let u ← getDecLevel type
let listLit ← mkListLit type xs
return mkApp (mkApp (mkConst ``List.toArray [u]) type) listLit
def mkSorry (type : Expr) (synthetic : Bool) : MetaM Expr := do
let u ← getLevel type
return mkApp2 (mkConst ``sorryAx [u]) type (toExpr synthetic)
/-- Return `Decidable.decide p` -/
def mkDecide (p : Expr) : MetaM Expr :=
mkAppOptM ``Decidable.decide #[p, none]
/-- Return a proof for `p : Prop` using `decide p` -/
def mkDecideProof (p : Expr) : MetaM Expr := do
let decP ← mkDecide p
let decEqTrue ← mkEq decP (mkConst ``Bool.true)
let h ← mkEqRefl (mkConst ``Bool.true)
let h ← mkExpectedTypeHint h decEqTrue
mkAppM ``of_decide_eq_true #[h]
/-- Return `a < b` -/
def mkLt (a b : Expr) : MetaM Expr :=
mkAppM ``LT.lt #[a, b]
/-- Return `a <= b` -/
def mkLe (a b : Expr) : MetaM Expr :=
mkAppM ``LE.le #[a, b]
/-- Return `arbitrary α` -/
def mkArbitrary (α : Expr) : MetaM Expr :=
mkAppOptM ``arbitrary #[α, none]
/-- Return `sorryAx type` -/
def mkSyntheticSorry (type : Expr) : MetaM Expr :=
return mkApp2 (mkConst ``sorryAx [← getLevel type]) type (mkConst ``Bool.true)
/-- Return `funext h` -/
def mkFunExt (h : Expr) : MetaM Expr :=
mkAppM ``funext #[h]
/-- Return `propext h` -/
def mkPropExt (h : Expr) : MetaM Expr :=
mkAppM ``propext #[h]
/-- Return `let_congr h₁ h₂` -/
def mkLetCongr (h₁ h₂ : Expr) : MetaM Expr :=
mkAppM ``let_congr #[h₁, h₂]
/-- Return `let_val_congr b h` -/
def mkLetValCongr (b h : Expr) : MetaM Expr :=
mkAppM ``let_val_congr #[b, h]
/-- Return `let_body_congr a h` -/
def mkLetBodyCongr (a h : Expr) : MetaM Expr :=
mkAppM ``let_body_congr #[a, h]
/-- Return `of_eq_true h` -/
def mkOfEqTrue (h : Expr) : MetaM Expr :=
mkAppM ``of_eq_true #[h]
/-- Return `eq_true h` -/
def mkEqTrue (h : Expr) : MetaM Expr :=
mkAppM ``eq_true #[h]
/--
Return `eq_false h`
`h` must have type definitionally equal to `¬ p` in the current
reducibility setting. -/
def mkEqFalse (h : Expr) : MetaM Expr :=
mkAppM ``eq_false #[h]
/--
Return `eq_false' h`
`h` must have type definitionally equal to `p → False` in the current
reducibility setting. -/
def mkEqFalse' (h : Expr) : MetaM Expr :=
mkAppM ``eq_false' #[h]
def mkImpCongr (h₁ h₂ : Expr) : MetaM Expr :=
mkAppM ``implies_congr #[h₁, h₂]
def mkImpCongrCtx (h₁ h₂ : Expr) : MetaM Expr :=
mkAppM ``implies_congr_ctx #[h₁, h₂]
def mkForallCongr (h : Expr) : MetaM Expr :=
mkAppM ``forall_congr #[h]
/-- Return instance for `[Monad m]` if there is one -/
def isMonad? (m : Expr) : MetaM (Option Expr) :=
try
let monadType ← mkAppM `Monad #[m]
let result ← trySynthInstance monadType
match result with
| LOption.some inst => pure inst
| _ => pure none
catch _ =>
pure none
/-- Return `(n : type)`, a numeric literal of type `type`. The method fails if we don't have an instance `OfNat type n` -/
def mkNumeral (type : Expr) (n : Nat) : MetaM Expr := do
let u ← getDecLevel type
let inst ← synthInstance (mkApp2 (mkConst ``OfNat [u]) type (mkRawNatLit n))
return mkApp3 (mkConst ``OfNat.ofNat [u]) type (mkRawNatLit n) inst
/--
Return `a op b`, where `op` has name `opName` and is implemented using the typeclass `className`.
This method assumes `a` and `b` have the same type, and typeclass `className` is heterogeneous.
Examples of supported clases: `HAdd`, `HSub`, `HMul`.
We use heterogeneous operators to ensure we have a uniform representation.
-/
private def mkBinaryOp (className : Name) (opName : Name) (a b : Expr) : MetaM Expr := do
let aType ← inferType a
let u ← getDecLevel aType
let inst ← synthInstance (mkApp3 (mkConst className [u, u, u]) aType aType aType)
return mkApp6 (mkConst opName [u, u, u]) aType aType aType inst a b
/-- Return `a + b` using a heterogeneous `+`. This method assumes `a` and `b` have the same type. -/
def mkAdd (a b : Expr) : MetaM Expr := mkBinaryOp ``HAdd ``HAdd.hAdd a b
/-- Return `a - b` using a heterogeneous `-`. This method assumes `a` and `b` have the same type. -/
def mkSub (a b : Expr) : MetaM Expr := mkBinaryOp ``HSub ``HSub.hSub a b
/-- Return `a * b` using a heterogeneous `*`. This method assumes `a` and `b` have the same type. -/
def mkMul (a b : Expr) : MetaM Expr := mkBinaryOp ``HMul ``HMul.hMul a b
builtin_initialize registerTraceClass `Meta.appBuilder
end Lean.Meta
|
89e2aa3fe51d6822a9f23584b630d31cd1a8b3ac | 4727251e0cd73359b15b664c3170e5d754078599 | /src/order/grade.lean | 9a8f467c7cb7f3928e75f5b14d85087a7a829d6d | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 12,714 | lean | /-
Copyright (c) 2022 Yaël Dillies, Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Violeta Hernández Palacios, Grayson Burton, Vladimir Ivanov
-/
import data.nat.interval
import data.int.succ_pred
import order.atoms
/-!
# Graded orders
This file defines graded orders, also known as ranked orders.
A `𝕆`-graded order is an order `α` equipped with a distinguished "grade" function `α → 𝕆` which
should be understood as giving the "height" of the elements. Usual graded orders are `ℕ`-graded,
cograded orders are `ℕᵒᵈ`-graded, but we can also grade by `ℤ`, and polytopes are naturally
`fin n`-graded.
Visually, `grade ℕ a` is the height of `a` in the Hasse diagram of `α`.
## Main declarations
* `grade_order`: Graded order.
* `grade_min_order`: Graded order where minimal elements have minimal grades.
* `grade_max_order`: Graded order where maximal elements have maximal grades.
* `grade_bounded_order`: Graded order where minimal elements have minimal grades and maximal
elements have maximal grades.
* `grade`: The grade of an element. Because an order can admit several gradings, the first argument
is the order we grade by.
* `grade_max_order`: Graded orders with maximal elements. All maximal elements have the same grade.
* `max_grade`: The maximum grade in a `grade_max_order`.
* `order_embedding.grade`: The grade of an element in a linear order as an order embedding.
## How to grade your order
Here are the translations between common references and our `grade_order`:
* [Stanley][stanley2012] defines a graded order of rank `n` as an order where all maximal chains
have "length" `n` (so the number of elements of a chain is `n + 1`). This corresponds to
`grade_bounded_order (fin (n + 1)) α`.
* [Engel][engel1997]'s ranked orders are somewhere between `grade_order ℕ α` and
`grade_min_order ℕ α`, in that he requires `∃ a, is_min a ∧ grade ℕ a + 0` rather than
`∀ a, is_min a → grade ℕ a = 0`. He defines a graded order as an order where all minimal elements
have grade `0` and all maximal elements have the same grade. This is roughly a less bundled
version of `grade_bounded_order (fin n) α`, assuming we discard orders with infinite chains.
## Implementation notes
One possible definition of graded orders is as the bounded orders whose flags (maximal chains)
all have the same finite length (see Stanley p. 99). However, this means that all graded orders must
have minimal and maximal elements and that the grade is not data.
Instead, we define graded orders by their grade function, without talking about flags yet.
## References
* [Konrad Engel, *Sperner Theory*][engel1997]
* [Richard Stanley, *Enumerative Combinatorics*][stanley2012]
-/
set_option old_structure_cmd true
open finset nat order_dual
variables {𝕆 ℙ α β : Type*}
/-- An `𝕆`-graded order is an order `α` equipped with a strictly monotone function `grade 𝕆 : α → 𝕆`
which preserves order covering (`covby`). -/
class grade_order (𝕆 α : Type*) [preorder 𝕆] [preorder α] :=
(grade : α → 𝕆)
(grade_strict_mono : strict_mono grade)
(covby_grade ⦃a b : α⦄ : a ⋖ b → grade a ⋖ grade b)
/-- A `𝕆`-graded order where minimal elements have minimal grades. -/
class grade_min_order (𝕆 α : Type*) [preorder 𝕆] [preorder α] extends grade_order 𝕆 α :=
(is_min_grade ⦃a : α⦄ : is_min a → is_min (grade a))
/-- A `𝕆`-graded order where maximal elements have maximal grades. -/
class grade_max_order (𝕆 α : Type*) [preorder 𝕆] [preorder α] extends grade_order 𝕆 α :=
(is_max_grade ⦃a : α⦄ : is_max a → is_max (grade a))
/-- A `𝕆`-graded order where minimal elements have minimal grades and maximal elements have maximal
grades. -/
class grade_bounded_order (𝕆 α : Type*) [preorder 𝕆] [preorder α]
extends grade_min_order 𝕆 α, grade_max_order 𝕆 α
section preorder -- grading
variables [preorder 𝕆]
section preorder -- graded order
variables [preorder α]
section grade_order
variables (𝕆) [grade_order 𝕆 α] {a b : α}
/-- The grade of an element in a graded order. Morally, this is the number of elements you need to
go down by to get to `⊥`. -/
def grade : α → 𝕆 := grade_order.grade
protected lemma covby.grade (h : a ⋖ b) : grade 𝕆 a ⋖ grade 𝕆 b := grade_order.covby_grade h
variables {𝕆}
lemma grade_strict_mono : strict_mono (grade 𝕆 : α → 𝕆) := grade_order.grade_strict_mono
lemma covby_iff_lt_covby_grade : a ⋖ b ↔ a < b ∧ grade 𝕆 a ⋖ grade 𝕆 b :=
⟨λ h, ⟨h.1, h.grade _⟩, and.imp_right $ λ h c ha hb,
h.2 (grade_strict_mono ha) $ grade_strict_mono hb⟩
end grade_order
section grade_min_order
variables (𝕆) [grade_min_order 𝕆 α] {a : α}
protected lemma is_min.grade (h : is_min a) : is_min (grade 𝕆 a) := grade_min_order.is_min_grade h
variables {𝕆}
@[simp] lemma is_min_grade_iff : is_min (grade 𝕆 a) ↔ is_min a :=
⟨grade_strict_mono.is_min_of_apply, is_min.grade _⟩
end grade_min_order
section grade_max_order
variables (𝕆) [grade_max_order 𝕆 α] {a : α}
protected lemma is_max.grade (h : is_max a) : is_max (grade 𝕆 a) := grade_max_order.is_max_grade h
variables {𝕆}
@[simp] lemma is_max_grade_iff : is_max (grade 𝕆 a) ↔ is_max a :=
⟨grade_strict_mono.is_max_of_apply, is_max.grade _⟩
end grade_max_order
end preorder -- graded order
lemma grade_mono [partial_order α] [grade_order 𝕆 α] : monotone (grade 𝕆 : α → 𝕆) :=
grade_strict_mono.monotone
section linear_order -- graded order
variables [linear_order α] [grade_order 𝕆 α] {a b : α}
lemma grade_injective : function.injective (grade 𝕆 : α → 𝕆) := grade_strict_mono.injective
@[simp] lemma grade_le_grade_iff : grade 𝕆 a ≤ grade 𝕆 b ↔ a ≤ b := grade_strict_mono.le_iff_le
@[simp] lemma grade_lt_grade_iff : grade 𝕆 a < grade 𝕆 b ↔ a < b := grade_strict_mono.lt_iff_lt
@[simp] lemma grade_eq_grade_iff : grade 𝕆 a = grade 𝕆 b ↔ a = b := grade_injective.eq_iff
lemma grade_ne_grade_iff : grade 𝕆 a ≠ grade 𝕆 b ↔ a ≠ b := grade_injective.ne_iff
lemma grade_covby_grade_iff : grade 𝕆 a ⋖ grade 𝕆 b ↔ a ⋖ b :=
(covby_iff_lt_covby_grade.trans $ and_iff_right_of_imp $ λ h, grade_lt_grade_iff.1 h.1).symm
end linear_order -- graded order
end preorder -- grading
section partial_order
variables [partial_order 𝕆] [preorder α]
@[simp] lemma grade_bot [order_bot 𝕆] [order_bot α] [grade_min_order 𝕆 α] : grade 𝕆 (⊥ : α) = ⊥ :=
(is_min_bot.grade _).eq_bot
@[simp] lemma grade_top [order_top 𝕆] [order_top α] [grade_max_order 𝕆 α] : grade 𝕆 (⊤ : α) = ⊤ :=
(is_max_top.grade _).eq_top
end partial_order
/-! ### Instances -/
variables [preorder 𝕆] [preorder ℙ] [preorder α] [preorder β]
instance preorder.to_grade_bounded_order : grade_bounded_order α α :=
{ grade := id,
is_min_grade := λ _, id,
is_max_grade := λ _, id,
grade_strict_mono := strict_mono_id,
covby_grade := λ a b, id }
@[simp] lemma grade_self (a : α) : grade α a = a := rfl
/-! #### Dual -/
instance [grade_order 𝕆 α] : grade_order 𝕆ᵒᵈ αᵒᵈ :=
{ grade := to_dual ∘ grade 𝕆 ∘ of_dual,
grade_strict_mono := grade_strict_mono.dual,
covby_grade := λ a b h, (h.of_dual.grade _).to_dual }
instance [grade_max_order 𝕆 α] : grade_min_order 𝕆ᵒᵈ αᵒᵈ :=
{ is_min_grade := λ _, is_max.grade _,
..order_dual.grade_order }
instance [grade_min_order 𝕆 α] : grade_max_order 𝕆ᵒᵈ αᵒᵈ :=
{ is_max_grade := λ _, is_min.grade _,
..order_dual.grade_order }
instance [grade_bounded_order 𝕆 α] : grade_bounded_order 𝕆ᵒᵈ αᵒᵈ :=
{ ..order_dual.grade_min_order, ..order_dual.grade_max_order }
@[simp] lemma grade_to_dual [grade_order 𝕆 α] (a : α) :
grade 𝕆ᵒᵈ (to_dual a) = to_dual (grade 𝕆 a) := rfl
@[simp] lemma grade_of_dual [grade_order 𝕆 α] (a : αᵒᵈ) :
grade 𝕆 (of_dual a) = of_dual (grade 𝕆ᵒᵈ a) := rfl
/-! #### Lifting a graded order -/
/-- Lifts a graded order along a strictly monotone function. -/
@[reducible] -- See note [reducible non-instances]
def grade_order.lift_left [grade_order 𝕆 α] (f : 𝕆 → ℙ) (hf : strict_mono f)
(hcovby : ∀ a b, a ⋖ b → f a ⋖ f b) : grade_order ℙ α :=
{ grade := f ∘ grade 𝕆,
grade_strict_mono := hf.comp grade_strict_mono,
covby_grade := λ a b h, hcovby _ _ $ h.grade _ }
/-- Lifts a graded order along a strictly monotone function. -/
@[reducible] -- See note [reducible non-instances]
def grade_min_order.lift_left [grade_min_order 𝕆 α] (f : 𝕆 → ℙ) (hf : strict_mono f)
(hcovby : ∀ a b, a ⋖ b → f a ⋖ f b) (hmin : ∀ a, is_min a → is_min (f a)) :
grade_min_order ℙ α :=
{ is_min_grade := λ a ha, hmin _ $ ha.grade _,
..grade_order.lift_left f hf hcovby }
/-- Lifts a graded order along a strictly monotone function. -/
@[reducible] -- See note [reducible non-instances]
def grade_max_order.lift_left [grade_max_order 𝕆 α] (f : 𝕆 → ℙ) (hf : strict_mono f)
(hcovby : ∀ a b, a ⋖ b → f a ⋖ f b) (hmax : ∀ a, is_max a → is_max (f a)) :
grade_max_order ℙ α :=
{ is_max_grade := λ a ha, hmax _ $ ha.grade _,
..grade_order.lift_left f hf hcovby }
/-- Lifts a graded order along a strictly monotone function. -/
@[reducible] -- See note [reducible non-instances]
def grade_bounded_order.lift_left [grade_bounded_order 𝕆 α] (f : 𝕆 → ℙ) (hf : strict_mono f)
(hcovby : ∀ a b, a ⋖ b → f a ⋖ f b) (hmin : ∀ a, is_min a → is_min (f a))
(hmax : ∀ a, is_max a → is_max (f a)) :
grade_bounded_order ℙ α :=
{ ..grade_min_order.lift_left f hf hcovby hmin, ..grade_max_order.lift_left f hf hcovby hmax }
/-- Lifts a graded order along a strictly monotone function. -/
@[reducible] -- See note [reducible non-instances]
def grade_order.lift_right [grade_order 𝕆 β] (f : α → β) (hf : strict_mono f)
(hcovby : ∀ a b, a ⋖ b → f a ⋖ f b) : grade_order 𝕆 α :=
{ grade := grade 𝕆 ∘ f,
grade_strict_mono := grade_strict_mono.comp hf,
covby_grade := λ a b h, (hcovby _ _ h).grade _ }
/-- Lifts a graded order along a strictly monotone function. -/
@[reducible] -- See note [reducible non-instances]
def grade_min_order.lift_right [grade_min_order 𝕆 β] (f : α → β) (hf : strict_mono f)
(hcovby : ∀ a b, a ⋖ b → f a ⋖ f b) (hmin : ∀ a, is_min a → is_min (f a)) :
grade_min_order 𝕆 α :=
{ is_min_grade := λ a ha, (hmin _ ha).grade _,
..grade_order.lift_right f hf hcovby }
/-- Lifts a graded order along a strictly monotone function. -/
@[reducible] -- See note [reducible non-instances]
def grade_max_order.lift_right [grade_max_order 𝕆 β] (f : α → β) (hf : strict_mono f)
(hcovby : ∀ a b, a ⋖ b → f a ⋖ f b) (hmax : ∀ a, is_max a → is_max (f a)) :
grade_max_order 𝕆 α :=
{ is_max_grade := λ a ha, (hmax _ ha).grade _,
..grade_order.lift_right f hf hcovby }
/-- Lifts a graded order along a strictly monotone function. -/
@[reducible] -- See note [reducible non-instances]
def grade_bounded_order.lift_right [grade_bounded_order 𝕆 β] (f : α → β) (hf : strict_mono f)
(hcovby : ∀ a b, a ⋖ b → f a ⋖ f b) (hmin : ∀ a, is_min a → is_min (f a))
(hmax : ∀ a, is_max a → is_max (f a)) : grade_bounded_order 𝕆 α :=
{ ..grade_min_order.lift_right f hf hcovby hmin, ..grade_max_order.lift_right f hf hcovby hmax }
/-! #### `fin n`-graded to `ℕ`-graded to `ℤ`-graded -/
/-- A `fin n`-graded order is also `ℕ`-graded. We do not mark this an instance because `n` is not
inferrable. -/
@[reducible] -- See note [reducible non-instances]
def grade_order.fin_to_nat (n : ℕ) [grade_order (fin n) α] : grade_order ℕ α :=
grade_order.lift_left (_ : fin n → ℕ) fin.coe_strict_mono $ λ _ _, covby.coe_fin
/-- A `fin n`-graded order is also `ℕ`-graded. We do not mark this an instance because `n` is not
inferrable. -/
@[reducible] -- See note [reducible non-instances]
def grade_min_order.fin_to_nat (n : ℕ) [grade_min_order (fin n) α] : grade_min_order ℕ α :=
grade_min_order.lift_left (_ : fin n → ℕ) fin.coe_strict_mono (λ _ _, covby.coe_fin) $ λ a h, begin
unfreezingI { cases n },
{ exact (@fin.elim0 (λ _, false) $ grade (fin 0) a).elim },
rw [h.eq_bot, fin.bot_eq_zero],
exact is_min_bot,
end
instance grade_order.nat_to_int [grade_order ℕ α] : grade_order ℤ α :=
grade_order.lift_left _ int.coe_nat_strict_mono $ λ _ _, covby.cast_int
|
ff939d982b2656b6e9213dd8bf75af997b1f2310 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/measure_theory/prod.lean | aa0dc6f64bf234739479f0a6ba25aceb299e7aef | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 46,988 | lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import measure_theory.giry_monad
import measure_theory.set_integral
/-!
# The product measure
In this file we define and prove properties about the binary product measure. If `α` and `β` have
σ-finite measures `μ` resp. `ν` then `α × β` can be equipped with a σ-finite measure `μ.prod ν` that
satisfies `(μ.prod ν) s = ∫⁻ x, ν {y | (x, y) ∈ s} ∂μ`.
We also have `(μ.prod ν) (s.prod t) = μ s * ν t`, i.e. the measure of a rectangle is the product of
the measures of the sides.
We also prove Tonelli's theorem and Fubini's theorem.
## Main definition
* `measure_theory.measure.prod`: The product of two measures.
## Main results
* `measure_theory.measure.prod_apply` states `μ.prod ν s = ∫⁻ x, ν {y | (x, y) ∈ s} ∂μ`
for measurable `s`. `measure_theory.measure.prod_apply_symm` is the reversed version.
* `measure_theory.measure.prod_prod` states `μ.prod ν (s.prod t) = μ s * ν t` for measurable sets
`s` and `t`.
* `measure_theory.lintegral_prod`: Tonelli's theorem. It states that for a measurable function
`α × β → ℝ≥0∞` we have `∫⁻ z, f z ∂(μ.prod ν) = ∫⁻ x, ∫⁻ y, f (x, y) ∂ν ∂μ`. The version
for functions `α → β → ℝ≥0∞` is reversed, and called `lintegral_lintegral`. Both versions have
a variant with `_symm` appended, where the order of integration is reversed.
The lemma `measurable.lintegral_prod_right'` states that the inner integral of the right-hand side
is measurable.
* `measure_theory.integrable_prod_iff` states that a binary function is integrable iff both
* `y ↦ f (x, y)` is integrable for almost every `x`, and
* the function `x ↦ ∫ ∥f (x, y)∥ dy` is integrable.
* `measure_theory.integral_prod`: Fubini's theorem. It states that for a integrable function
`α × β → E` (where `E` is a second countable Banach space) we have
`∫ z, f z ∂(μ.prod ν) = ∫ x, ∫ y, f (x, y) ∂ν ∂μ`. This theorem has the same variants as
Tonelli's theorem. The lemma `measure_theory.integrable.integral_prod_right` states that the
inner integral of the right-hand side is integrable.
## Implementation Notes
Many results are proven twice, once for functions in curried form (`α → β → γ`) and one for
functions in uncurried form (`α × β → γ`). The former often has an assumption
`measurable (uncurry f)`, which could be inconvenient to discharge, but for the latter it is more
common that the function has to be given explicitly, since Lean cannot synthesize the function by
itself. We name the lemmas about the uncurried form with a prime.
Tonelli's theorem and Fubini's theorem have a different naming scheme, since the version for the
uncurried version is reversed.
## Tags
product measure, Fubini's theorem, Tonelli's theorem, Fubini-Tonelli theorem
-/
noncomputable theory
open_locale classical topological_space ennreal measure_theory
open set function real ennreal
open measure_theory measurable_space measure_theory.measure
open topological_space (hiding generate_from)
open filter (hiding prod_eq map)
variables {α α' β β' γ E : Type*}
/-- Rectangles formed by π-systems form a π-system. -/
lemma is_pi_system.prod {C : set (set α)} {D : set (set β)} (hC : is_pi_system C)
(hD : is_pi_system D) : is_pi_system (image2 set.prod C D) :=
begin
rintro _ _ ⟨s₁, t₁, hs₁, ht₁, rfl⟩ ⟨s₂, t₂, hs₂, ht₂, rfl⟩ hst,
rw [prod_inter_prod] at hst ⊢, rw [prod_nonempty_iff] at hst,
exact mem_image2_of_mem (hC _ _ hs₁ hs₂ hst.1) (hD _ _ ht₁ ht₂ hst.2)
end
/-- Rectangles of countably spanning sets are countably spanning. -/
lemma is_countably_spanning.prod {C : set (set α)} {D : set (set β)}
(hC : is_countably_spanning C) (hD : is_countably_spanning D) :
is_countably_spanning (image2 set.prod C D) :=
begin
rcases ⟨hC, hD⟩ with ⟨⟨s, h1s, h2s⟩, t, h1t, h2t⟩,
refine ⟨λ n, (s n.unpair.1).prod (t n.unpair.2), λ n, mem_image2_of_mem (h1s _) (h1t _), _⟩,
rw [Union_unpair_prod, h2s, h2t, univ_prod_univ]
end
variables [measurable_space α] [measurable_space α'] [measurable_space β] [measurable_space β']
variables [measurable_space γ]
variables {μ : measure α} {ν : measure β} {τ : measure γ}
variables [normed_group E] [measurable_space E]
/-! ### Measurability
Before we define the product measure, we can talk about the measurability of operations on binary
functions. We show that if `f` is a binary measurable function, then the function that integrates
along one of the variables (using either the Lebesgue or Bochner integral) is measurable.
-/
/-- The product of generated σ-algebras is the one generated by rectangles, if both generating sets
are countably spanning. -/
lemma generate_from_prod_eq {α β} {C : set (set α)} {D : set (set β)}
(hC : is_countably_spanning C) (hD : is_countably_spanning D) :
@prod.measurable_space _ _ (generate_from C) (generate_from D) =
generate_from (image2 set.prod C D) :=
begin
apply le_antisymm,
{ refine sup_le _ _; rw [comap_generate_from];
apply generate_from_le; rintro _ ⟨s, hs, rfl⟩,
{ rcases hD with ⟨t, h1t, h2t⟩,
rw [← prod_univ, ← h2t, prod_Union],
apply measurable_set.Union,
intro n, apply measurable_set_generate_from,
exact ⟨s, t n, hs, h1t n, rfl⟩ },
{ rcases hC with ⟨t, h1t, h2t⟩,
rw [← univ_prod, ← h2t, Union_prod_const],
apply measurable_set.Union,
rintro n, apply measurable_set_generate_from,
exact mem_image2_of_mem (h1t n) hs } },
{ apply generate_from_le, rintro _ ⟨s, t, hs, ht, rfl⟩, rw [prod_eq],
apply (measurable_fst _).inter (measurable_snd _),
{ exact measurable_set_generate_from hs },
{ exact measurable_set_generate_from ht } }
end
/-- If `C` and `D` generate the σ-algebras on `α` resp. `β`, then rectangles formed by `C` and `D`
generate the σ-algebra on `α × β`. -/
lemma generate_from_eq_prod {C : set (set α)} {D : set (set β)} (hC : generate_from C = ‹_›)
(hD : generate_from D = ‹_›) (h2C : is_countably_spanning C) (h2D : is_countably_spanning D) :
generate_from (image2 set.prod C D) = prod.measurable_space :=
by rw [← hC, ← hD, generate_from_prod_eq h2C h2D]
/-- The product σ-algebra is generated from boxes, i.e. `s.prod t` for sets `s : set α` and
`t : set β`. -/
lemma generate_from_prod :
generate_from (image2 set.prod {s : set α | measurable_set s} {t : set β | measurable_set t}) =
prod.measurable_space :=
generate_from_eq_prod generate_from_measurable_set generate_from_measurable_set
is_countably_spanning_measurable_set is_countably_spanning_measurable_set
/-- Rectangles form a π-system. -/
lemma is_pi_system_prod :
is_pi_system (image2 set.prod {s : set α | measurable_set s} {t : set β | measurable_set t}) :=
is_pi_system_measurable_set.prod is_pi_system_measurable_set
/-- If `ν` is a finite measure, and `s ⊆ α × β` is measurable, then `x ↦ ν { y | (x, y) ∈ s }` is
a measurable function. `measurable_measure_prod_mk_left` is strictly more general. -/
lemma measurable_measure_prod_mk_left_finite [finite_measure ν] {s : set (α × β)}
(hs : measurable_set s) : measurable (λ x, ν (prod.mk x ⁻¹' s)) :=
begin
refine induction_on_inter generate_from_prod.symm is_pi_system_prod _ _ _ _ hs,
{ simp [measurable_zero, const_def] },
{ rintro _ ⟨s, t, hs, ht, rfl⟩, simp only [mk_preimage_prod_right_eq_if, measure_if],
exact measurable_const.indicator hs },
{ intros t ht h2t,
simp_rw [preimage_compl, measure_compl (measurable_prod_mk_left ht) (measure_lt_top ν _)],
exact h2t.const_sub _ },
{ intros f h1f h2f h3f, simp_rw [preimage_Union],
have : ∀ b, ν (⋃ i, prod.mk b ⁻¹' f i) = ∑' i, ν (prod.mk b ⁻¹' f i) :=
λ b, measure_Union (λ i j hij, disjoint.preimage _ (h1f i j hij))
(λ i, measurable_prod_mk_left (h2f i)),
simp_rw [this], apply measurable.ennreal_tsum h3f },
end
/-- If `ν` is a σ-finite measure, and `s ⊆ α × β` is measurable, then `x ↦ ν { y | (x, y) ∈ s }` is
a measurable function. -/
lemma measurable_measure_prod_mk_left [sigma_finite ν] {s : set (α × β)}
(hs : measurable_set s) : measurable (λ x, ν (prod.mk x ⁻¹' s)) :=
begin
have : ∀ x, measurable_set (prod.mk x ⁻¹' s) := λ x, measurable_prod_mk_left hs,
simp only [← @supr_restrict_spanning_sets _ _ ν, this],
apply measurable_supr, intro i,
haveI := fact.mk (measure_spanning_sets_lt_top ν i),
exact measurable_measure_prod_mk_left_finite hs
end
/-- If `μ` is a σ-finite measure, and `s ⊆ α × β` is measurable, then `y ↦ μ { x | (x, y) ∈ s }` is
a measurable function. -/
lemma measurable_measure_prod_mk_right {μ : measure α} [sigma_finite μ] {s : set (α × β)}
(hs : measurable_set s) : measurable (λ y, μ ((λ x, (x, y)) ⁻¹' s)) :=
measurable_measure_prod_mk_left (measurable_set_swap_iff.mpr hs)
lemma measurable.map_prod_mk_left [sigma_finite ν] : measurable (λ x : α, map (prod.mk x) ν) :=
begin
apply measurable_of_measurable_coe, intros s hs,
simp_rw [map_apply measurable_prod_mk_left hs],
exact measurable_measure_prod_mk_left hs
end
lemma measurable.map_prod_mk_right {μ : measure α} [sigma_finite μ] :
measurable (λ y : β, map (λ x : α, (x, y)) μ) :=
begin
apply measurable_of_measurable_coe, intros s hs,
simp_rw [map_apply measurable_prod_mk_right hs],
exact measurable_measure_prod_mk_right hs
end
/-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of)
Tonelli's theorem is measurable. -/
lemma measurable.lintegral_prod_right' [sigma_finite ν] :
∀ {f : α × β → ℝ≥0∞} (hf : measurable f), measurable (λ x, ∫⁻ y, f (x, y) ∂ν) :=
begin
have m := @measurable_prod_mk_left,
refine measurable.ennreal_induction _ _ _,
{ intros c s hs, simp only [← indicator_comp_right],
suffices : measurable (λ x, c * ν (prod.mk x ⁻¹' s)),
{ simpa [lintegral_indicator _ (m hs)] },
exact (measurable_measure_prod_mk_left hs).const_mul _ },
{ rintro f g - hf hg h2f h2g, simp_rw [pi.add_apply, lintegral_add (hf.comp m) (hg.comp m)],
exact h2f.add h2g },
{ intros f hf h2f h3f,
have := measurable_supr h3f,
have : ∀ x, monotone (λ n y, f n (x, y)) := λ x i j hij y, h2f hij (x, y),
simpa [lintegral_supr (λ n, (hf n).comp m), this] }
end
/-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of)
Tonelli's theorem is measurable.
This version has the argument `f` in curried form. -/
lemma measurable.lintegral_prod_right [sigma_finite ν] {f : α → β → ℝ≥0∞}
(hf : measurable (uncurry f)) : measurable (λ x, ∫⁻ y, f x y ∂ν) :=
hf.lintegral_prod_right'
/-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Tonelli's theorem is measurable. -/
lemma measurable.lintegral_prod_left' [sigma_finite μ] {f : α × β → ℝ≥0∞}
(hf : measurable f) : measurable (λ y, ∫⁻ x, f (x, y) ∂μ) :=
(measurable_swap_iff.mpr hf).lintegral_prod_right'
/-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Tonelli's theorem is measurable.
This version has the argument `f` in curried form. -/
lemma measurable.lintegral_prod_left [sigma_finite μ] {f : α → β → ℝ≥0∞}
(hf : measurable (uncurry f)) : measurable (λ y, ∫⁻ x, f x y ∂μ) :=
hf.lintegral_prod_left'
lemma measurable_set_integrable [sigma_finite ν] [opens_measurable_space E] ⦃f : α → β → E⦄
(hf : measurable (uncurry f)) : measurable_set { x | integrable (f x) ν } :=
begin
simp_rw [integrable, hf.of_uncurry_left.ae_measurable, true_and],
exact measurable_set_lt (measurable.lintegral_prod_right hf.ennnorm) measurable_const
end
section
variables [second_countable_topology E] [normed_space ℝ E]
[complete_space E] [borel_space E]
/-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of)
Fubini's theorem is measurable.
This version has `f` in curried form. -/
lemma measurable.integral_prod_right [sigma_finite ν] ⦃f : α → β → E⦄
(hf : measurable (uncurry f)) : measurable (λ x, ∫ y, f x y ∂ν) :=
begin
let s : ℕ → simple_func (α × β) E := simple_func.approx_on _ hf univ _ (mem_univ 0),
let s' : ℕ → α → simple_func β E := λ n x, (s n).comp (prod.mk x) measurable_prod_mk_left,
let f' : ℕ → α → E := λ n, {x | integrable (f x) ν}.indicator
(λ x, (s' n x).integral ν),
have hf' : ∀ n, measurable (f' n),
{ intro n, refine measurable.indicator _ (measurable_set_integrable hf),
have : ∀ x, (s' n x).range.filter (λ x, x ≠ 0) ⊆ (s n).range,
{ intros x, refine finset.subset.trans (finset.filter_subset _ _) _, intro y,
simp_rw [simple_func.mem_range], rintro ⟨z, rfl⟩, exact ⟨(x, z), rfl⟩ },
simp only [simple_func.integral_eq_sum_of_subset (this _)],
refine finset.measurable_sum _ (λ x _, _),
refine (measurable.ennreal_to_real _).smul_const _,
simp only [simple_func.coe_comp, preimage_comp] {single_pass := tt},
apply measurable_measure_prod_mk_left,
exact (s n).measurable_set_fiber x },
have h2f' : tendsto f' at_top (𝓝 (λ (x : α), ∫ (y : β), f x y ∂ν)),
{ rw [tendsto_pi], intro x,
by_cases hfx : integrable (f x) ν,
{ have : ∀ n, integrable (s' n x) ν,
{ intro n, apply (hfx.norm.add hfx.norm).mono' (s' n x).measurable.ae_measurable,
apply eventually_of_forall, intro y,
simp_rw [s', simple_func.coe_comp], exact simple_func.norm_approx_on_zero_le _ _ (x, y) n },
simp only [f', hfx, simple_func.integral_eq_integral _ (this _), indicator_of_mem,
mem_set_of_eq],
refine tendsto_integral_of_dominated_convergence (λ y, ∥f x y∥ + ∥f x y∥)
(λ n, (s' n x).ae_measurable) hf.of_uncurry_left.ae_measurable (hfx.norm.add hfx.norm) _ _,
{ exact λ n, eventually_of_forall (λ y, simple_func.norm_approx_on_zero_le _ _ (x, y) n) },
{ exact eventually_of_forall (λ y, simple_func.tendsto_approx_on _ _ (by simp)) } },
{ simpa [f', hfx, integral_undef] using @tendsto_const_nhds _ _ _ (0 : E) _, } },
exact measurable_of_tendsto_metric hf' h2f'
end
/-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of)
Fubini's theorem is measurable. -/
lemma measurable.integral_prod_right' [sigma_finite ν] ⦃f : α × β → E⦄
(hf : measurable f) : measurable (λ x, ∫ y, f (x, y) ∂ν) :=
by { rw [← uncurry_curry f] at hf, exact hf.integral_prod_right }
/-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Fubini's theorem is measurable.
This version has `f` in curried form. -/
lemma measurable.integral_prod_left [sigma_finite μ] ⦃f : α → β → E⦄
(hf : measurable (uncurry f)) : measurable (λ y, ∫ x, f x y ∂μ) :=
(hf.comp measurable_swap).integral_prod_right'
/-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Fubini's theorem is measurable. -/
lemma measurable.integral_prod_left' [sigma_finite μ] ⦃f : α × β → E⦄
(hf : measurable f) : measurable (λ y, ∫ x, f (x, y) ∂μ) :=
(hf.comp measurable_swap).integral_prod_right'
end
/-! ### The product measure -/
namespace measure_theory
namespace measure
/-- The binary product of measures. They are defined for arbitrary measures, but we basically
prove all properties under the assumption that at least one of them is σ-finite. -/
@[irreducible] protected def prod (μ : measure α) (ν : measure β) : measure (α × β) :=
bind μ $ λ x : α, map (prod.mk x) ν
instance prod.measure_space {α β} [measure_space α] [measure_space β] : measure_space (α × β) :=
{ volume := volume.prod volume }
variables {μ ν} [sigma_finite ν]
lemma prod_apply {s : set (α × β)} (hs : measurable_set s) :
μ.prod ν s = ∫⁻ x, ν (prod.mk x ⁻¹' s) ∂μ :=
by simp_rw [measure.prod, bind_apply hs measurable.map_prod_mk_left,
map_apply measurable_prod_mk_left hs]
@[simp] lemma prod_prod {s : set α} {t : set β}
(hs : measurable_set s) (ht : measurable_set t) : μ.prod ν (s.prod t) = μ s * ν t :=
by simp_rw [prod_apply (hs.prod ht), mk_preimage_prod_right_eq_if, measure_if,
lintegral_indicator _ hs, lintegral_const, restrict_apply measurable_set.univ,
univ_inter, mul_comm]
local attribute [instance] nonempty_measurable_superset
/-- If we don't assume measurability of `s` and `t`, we can bound the measure of their product. -/
lemma prod_prod_le (s : set α) (t : set β) : μ.prod ν (s.prod t) ≤ μ s * ν t :=
begin
by_cases hs0 : μ s = 0,
{ rcases (exists_measurable_superset_of_null hs0) with ⟨s', hs', h2s', h3s'⟩,
convert measure_mono (prod_mono hs' (subset_univ _)),
simp_rw [hs0, prod_prod h2s' measurable_set.univ, h3s', zero_mul] },
by_cases hti : ν t = ∞,
{ convert le_top, simp_rw [hti, ennreal.mul_top, hs0, if_false] },
rw [measure_eq_infi' μ],
simp_rw [ennreal.infi_mul hti],
refine le_infi _,
rintro ⟨s', h1s', h2s'⟩,
rw [subtype.coe_mk],
by_cases ht0 : ν t = 0,
{ rcases (exists_measurable_superset_of_null ht0) with ⟨t', ht', h2t', h3t'⟩,
convert measure_mono (prod_mono (subset_univ _) ht'),
simp_rw [ht0, prod_prod measurable_set.univ h2t', h3t', mul_zero] },
by_cases hsi : μ s' = ∞,
{ convert le_top, simp_rw [hsi, ennreal.top_mul, ht0, if_false] },
rw [measure_eq_infi' ν],
simp_rw [ennreal.mul_infi hsi],
refine le_infi _,
rintro ⟨t', h1t', h2t'⟩,
convert measure_mono (prod_mono h1s' h1t'),
simp [prod_prod h2s' h2t'],
end
lemma ae_measure_lt_top {s : set (α × β)} (hs : measurable_set s)
(h2s : (μ.prod ν) s < ∞) : ∀ᵐ x ∂μ, ν (prod.mk x ⁻¹' s) < ∞ :=
by { simp_rw [prod_apply hs] at h2s, refine ae_lt_top (measurable_measure_prod_mk_left hs) h2s }
lemma integrable_measure_prod_mk_left {s : set (α × β)}
(hs : measurable_set s) (h2s : (μ.prod ν) s < ∞) :
integrable (λ x, (ν (prod.mk x ⁻¹' s)).to_real) μ :=
begin
refine ⟨(measurable_measure_prod_mk_left hs).ennreal_to_real.ae_measurable, _⟩,
simp_rw [has_finite_integral, ennnorm_eq_of_real to_real_nonneg],
convert h2s using 1, simp_rw [prod_apply hs], apply lintegral_congr_ae,
refine (ae_measure_lt_top hs h2s).mp _, apply eventually_of_forall, intros x hx,
rw [lt_top_iff_ne_top] at hx, simp [of_real_to_real, hx],
end
/-- Note: the assumption `hs` cannot be dropped. For a counterexample, see
Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. -/
lemma measure_prod_null {s : set (α × β)}
(hs : measurable_set s) : μ.prod ν s = 0 ↔ (λ x, ν (prod.mk x ⁻¹' s)) =ᵐ[μ] 0 :=
by simp_rw [prod_apply hs, lintegral_eq_zero_iff (measurable_measure_prod_mk_left hs)]
/-- Note: the converse is not true without assuming that `s` is measurable. For a counterexample,
see Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. -/
lemma measure_ae_null_of_prod_null {s : set (α × β)}
(h : μ.prod ν s = 0) : (λ x, ν (prod.mk x ⁻¹' s)) =ᵐ[μ] 0 :=
begin
obtain ⟨t, hst, mt, ht⟩ := exists_measurable_superset_of_null h,
simp_rw [measure_prod_null mt] at ht,
rw [eventually_le_antisymm_iff],
exact ⟨eventually_le.trans_eq
(eventually_of_forall $ λ x, (measure_mono (preimage_mono hst) : _)) ht,
eventually_of_forall $ λ x, zero_le _⟩
end
/-- Note: the converse is not true. For a counterexample, see
Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. -/
lemma ae_ae_of_ae_prod {p : α × β → Prop} (h : ∀ᵐ z ∂μ.prod ν, p z) :
∀ᵐ x ∂ μ, ∀ᵐ y ∂ ν, p (x, y) :=
measure_ae_null_of_prod_null h
/-- `μ.prod ν` has finite spanning sets in rectangles of finite spanning sets. -/
def finite_spanning_sets_in.prod {ν : measure β} {C : set (set α)} {D : set (set β)}
(hμ : μ.finite_spanning_sets_in C) (hν : ν.finite_spanning_sets_in D)
(hC : ∀ s ∈ C, measurable_set s) (hD : ∀ t ∈ D, measurable_set t) :
(μ.prod ν).finite_spanning_sets_in (image2 set.prod C D) :=
begin
haveI := hν.sigma_finite hD,
refine ⟨λ n, (hμ.set n.unpair.1).prod (hν.set n.unpair.2),
λ n, mem_image2_of_mem (hμ.set_mem _) (hν.set_mem _), λ n, _, _⟩,
{ simp_rw [prod_prod (hC _ (hμ.set_mem _)) (hD _ (hν.set_mem _))],
exact mul_lt_top (hμ.finite _) (hν.finite _) },
{ simp_rw [Union_unpair_prod, hμ.spanning, hν.spanning, univ_prod_univ] }
end
lemma prod_fst_absolutely_continuous : map prod.fst (μ.prod ν) ≪ μ :=
begin
refine absolutely_continuous.mk (λ s hs h2s, _),
simp_rw [map_apply measurable_fst hs, ← prod_univ, prod_prod hs measurable_set.univ],
rw [h2s, zero_mul] -- for some reason `simp_rw [h2s]` doesn't work
end
lemma prod_snd_absolutely_continuous : map prod.snd (μ.prod ν) ≪ ν :=
begin
refine absolutely_continuous.mk (λ s hs h2s, _),
simp_rw [map_apply measurable_snd hs, ← univ_prod, prod_prod measurable_set.univ hs],
rw [h2s, mul_zero] -- for some reason `simp_rw [h2s]` doesn't work
end
variables [sigma_finite μ]
instance prod.sigma_finite : sigma_finite (μ.prod ν) :=
⟨⟨(μ.to_finite_spanning_sets_in.prod ν.to_finite_spanning_sets_in (λ _, id) (λ _, id)).mono $
by { rintro _ ⟨s, t, hs, ht, rfl⟩, exact hs.prod ht }⟩⟩
/-- A measure on a product space equals the product measure if they are equal on rectangles
with as sides sets that generate the corresponding σ-algebras. -/
lemma prod_eq_generate_from {μ : measure α} {ν : measure β} {C : set (set α)}
{D : set (set β)} (hC : generate_from C = ‹_›)
(hD : generate_from D = ‹_›) (h2C : is_pi_system C) (h2D : is_pi_system D)
(h3C : μ.finite_spanning_sets_in C) (h3D : ν.finite_spanning_sets_in D)
{μν : measure (α × β)}
(h₁ : ∀ (s ∈ C) (t ∈ D), μν (set.prod s t) = μ s * ν t) : μ.prod ν = μν :=
begin
have h4C : ∀ (s : set α), s ∈ C → measurable_set s,
{ intros s hs, rw [← hC], exact measurable_set_generate_from hs },
have h4D : ∀ (t : set β), t ∈ D → measurable_set t,
{ intros t ht, rw [← hD], exact measurable_set_generate_from ht },
refine (h3C.prod h3D h4C h4D).ext
(generate_from_eq_prod hC hD h3C.is_countably_spanning h3D.is_countably_spanning).symm
(h2C.prod h2D) _,
{ rintro _ ⟨s, t, hs, ht, rfl⟩, haveI := h3D.sigma_finite h4D,
simp_rw [h₁ s hs t ht, prod_prod (h4C s hs) (h4D t ht)] }
end
/-- A measure on a product space equals the product measure if they are equal on rectangles. -/
lemma prod_eq {μν : measure (α × β)}
(h : ∀ s t, measurable_set s → measurable_set t → μν (s.prod t) = μ s * ν t) : μ.prod ν = μν :=
prod_eq_generate_from generate_from_measurable_set generate_from_measurable_set
is_pi_system_measurable_set is_pi_system_measurable_set
μ.to_finite_spanning_sets_in ν.to_finite_spanning_sets_in (λ s hs t ht, h s t hs ht)
lemma prod_swap : map prod.swap (μ.prod ν) = ν.prod μ :=
begin
refine (prod_eq _).symm,
intros s t hs ht,
simp_rw [map_apply measurable_swap (hs.prod ht), preimage_swap_prod, prod_prod ht hs, mul_comm]
end
lemma prod_apply_symm {s : set (α × β)} (hs : measurable_set s) :
μ.prod ν s = ∫⁻ y, μ ((λ x, (x, y)) ⁻¹' s) ∂ν :=
by { rw [← prod_swap, map_apply measurable_swap hs],
simp only [prod_apply (measurable_swap hs)], refl }
lemma prod_assoc_prod [sigma_finite τ] :
map measurable_equiv.prod_assoc ((μ.prod ν).prod τ) = μ.prod (ν.prod τ) :=
begin
refine (prod_eq_generate_from generate_from_measurable_set generate_from_prod
is_pi_system_measurable_set is_pi_system_prod μ.to_finite_spanning_sets_in
(ν.to_finite_spanning_sets_in.prod τ.to_finite_spanning_sets_in (λ _, id) (λ _, id)) _).symm,
rintro s hs _ ⟨t, u, ht, hu, rfl⟩, rw [mem_set_of_eq] at hs ht hu,
simp_rw [map_apply (measurable_equiv.measurable _) (hs.prod (ht.prod hu)), prod_prod ht hu,
measurable_equiv.prod_assoc, measurable_equiv.coe_eq, equiv.prod_assoc_preimage,
prod_prod (hs.prod ht) hu, prod_prod hs ht, mul_assoc]
end
/-! ### The product of specific measures -/
lemma prod_restrict {s : set α} {t : set β} (hs : measurable_set s) (ht : measurable_set t) :
(μ.restrict s).prod (ν.restrict t) = (μ.prod ν).restrict (s.prod t) :=
begin
refine prod_eq (λ s' t' hs' ht', _),
simp_rw [restrict_apply (hs'.prod ht'), prod_inter_prod, prod_prod (hs'.inter hs) (ht'.inter ht),
restrict_apply hs', restrict_apply ht']
end
lemma restrict_prod_eq_prod_univ {s : set α} (hs : measurable_set s) :
(μ.restrict s).prod ν = (μ.prod ν).restrict (s.prod univ) :=
begin
have : ν = ν.restrict set.univ := measure.restrict_univ.symm,
rwa [this, measure.prod_restrict, ← this],
exact measurable_set.univ,
end
lemma prod_dirac (y : β) : μ.prod (dirac y) = map (λ x, (x, y)) μ :=
begin
refine prod_eq (λ s t hs ht, _),
simp_rw [map_apply measurable_prod_mk_right (hs.prod ht), mk_preimage_prod_left_eq_if, measure_if,
dirac_apply' _ ht, ← indicator_mul_right _ (λ x, μ s), pi.one_apply, mul_one]
end
lemma dirac_prod (x : α) : (dirac x).prod ν = map (prod.mk x) ν :=
begin
refine prod_eq (λ s t hs ht, _),
simp_rw [map_apply measurable_prod_mk_left (hs.prod ht), mk_preimage_prod_right_eq_if, measure_if,
dirac_apply' _ hs, ← indicator_mul_left _ _ (λ x, ν t), pi.one_apply, one_mul]
end
lemma dirac_prod_dirac {x : α} {y : β} : (dirac x).prod (dirac y) = dirac (x, y) :=
by rw [prod_dirac, map_dirac measurable_prod_mk_right]
lemma prod_sum {ι : Type*} [fintype ι] (ν : ι → measure β) [∀ i, sigma_finite (ν i)] :
μ.prod (sum ν) = sum (λ i, μ.prod (ν i)) :=
begin
refine prod_eq (λ s t hs ht, _),
simp_rw [sum_apply _ (hs.prod ht), sum_apply _ ht, prod_prod hs ht, tsum_fintype, finset.mul_sum]
end
lemma sum_prod {ι : Type*} [fintype ι] (μ : ι → measure α) [∀ i, sigma_finite (μ i)] :
(sum μ).prod ν = sum (λ i, (μ i).prod ν) :=
begin
refine prod_eq (λ s t hs ht, _),
simp_rw [sum_apply _ (hs.prod ht), sum_apply _ hs, prod_prod hs ht, tsum_fintype, finset.sum_mul]
end
lemma prod_add (ν' : measure β) [sigma_finite ν'] : μ.prod (ν + ν') = μ.prod ν + μ.prod ν' :=
by { refine prod_eq (λ s t hs ht, _), simp_rw [add_apply, prod_prod hs ht, left_distrib] }
lemma add_prod (μ' : measure α) [sigma_finite μ'] : (μ + μ').prod ν = μ.prod ν + μ'.prod ν :=
by { refine prod_eq (λ s t hs ht, _), simp_rw [add_apply, prod_prod hs ht, right_distrib] }
@[simp] lemma zero_prod (ν : measure β) : (0 : measure α).prod ν = 0 :=
by { rw measure.prod, exact bind_zero_left _ }
@[simp] lemma prod_zero (μ : measure α) : μ.prod (0 : measure β) = 0 :=
by simp [measure.prod]
lemma map_prod_map {δ} [measurable_space δ] {f : α → β} {g : γ → δ}
{μa : measure α} {μc : measure γ} (hfa : sigma_finite (map f μa))
(hgc : sigma_finite (map g μc)) (hf : measurable f) (hg : measurable g) :
(map f μa).prod (map g μc) = map (prod.map f g) (μa.prod μc) :=
begin
haveI := hgc.of_map μc hg,
refine prod_eq (λ s t hs ht, _),
rw [map_apply (hf.prod_map hg) (hs.prod ht), map_apply hf hs, map_apply hg ht],
exact prod_prod (hf hs) (hg ht)
end
end measure
end measure_theory
open measure_theory.measure
section
lemma ae_measurable.prod_swap [sigma_finite μ] [sigma_finite ν] {f : β × α → γ}
(hf : ae_measurable f (ν.prod μ)) : ae_measurable (λ (z : α × β), f z.swap) (μ.prod ν) :=
by { rw ← prod_swap at hf, exact hf.comp_measurable measurable_swap }
lemma ae_measurable.fst [sigma_finite ν] {f : α → γ}
(hf : ae_measurable f μ) : ae_measurable (λ (z : α × β), f z.1) (μ.prod ν) :=
hf.comp_measurable' measurable_fst prod_fst_absolutely_continuous
lemma ae_measurable.snd [sigma_finite ν] {f : β → γ}
(hf : ae_measurable f ν) : ae_measurable (λ (z : α × β), f z.2) (μ.prod ν) :=
hf.comp_measurable' measurable_snd prod_snd_absolutely_continuous
/-- The Bochner integral is a.e.-measurable.
This shows that the integrand of (the right-hand-side of) Fubini's theorem is a.e.-measurable. -/
lemma ae_measurable.integral_prod_right' [sigma_finite ν]
[second_countable_topology E] [normed_space ℝ E] [borel_space E] [complete_space E]
⦃f : α × β → E⦄ (hf : ae_measurable f (μ.prod ν)) : ae_measurable (λ x, ∫ y, f (x, y) ∂ν) μ :=
⟨λ x, ∫ y, hf.mk f (x, y) ∂ν, hf.measurable_mk.integral_prod_right', begin
filter_upwards [ae_ae_of_ae_prod hf.ae_eq_mk],
assume x hx,
exact integral_congr_ae hx
end⟩
lemma ae_measurable.prod_mk_left [sigma_finite ν] {f : α × β → γ}
(hf : ae_measurable f (μ.prod ν)) : ∀ᵐ x ∂μ, ae_measurable (λ y, f (x, y)) ν :=
begin
filter_upwards [ae_ae_of_ae_prod hf.ae_eq_mk],
intros x hx,
exact ⟨λ y, hf.mk f (x, y), hf.measurable_mk.comp measurable_prod_mk_left, hx⟩
end
end
namespace measure_theory
/-! ### The Lebesgue integral on a product -/
variables [sigma_finite ν]
lemma lintegral_prod_swap [sigma_finite μ] (f : α × β → ℝ≥0∞)
(hf : ae_measurable f (μ.prod ν)) : ∫⁻ z, f z.swap ∂(ν.prod μ) = ∫⁻ z, f z ∂(μ.prod ν) :=
by { rw ← prod_swap at hf, rw [← lintegral_map' hf measurable_swap, prod_swap] }
/-- Tonelli's Theorem: For `ℝ≥0∞`-valued measurable functions on `α × β`,
the integral of `f` is equal to the iterated integral. -/
lemma lintegral_prod_of_measurable :
∀ (f : α × β → ℝ≥0∞) (hf : measurable f), ∫⁻ z, f z ∂(μ.prod ν) = ∫⁻ x, ∫⁻ y, f (x, y) ∂ν ∂μ :=
begin
have m := @measurable_prod_mk_left,
refine measurable.ennreal_induction _ _ _,
{ intros c s hs, simp only [← indicator_comp_right],
simp [lintegral_indicator, m hs, hs, lintegral_const_mul, measurable_measure_prod_mk_left hs,
prod_apply] },
{ rintro f g - hf hg h2f h2g,
simp [lintegral_add, measurable.lintegral_prod_right', hf.comp m, hg.comp m,
hf, hg, h2f, h2g] },
{ intros f hf h2f h3f,
have kf : ∀ x n, measurable (λ y, f n (x, y)) := λ x n, (hf n).comp m,
have k2f : ∀ x, monotone (λ n y, f n (x, y)) := λ x i j hij y, h2f hij (x, y),
have lf : ∀ n, measurable (λ x, ∫⁻ y, f n (x, y) ∂ν) := λ n, (hf n).lintegral_prod_right',
have l2f : monotone (λ n x, ∫⁻ y, f n (x, y) ∂ν) := λ i j hij x, lintegral_mono (k2f x hij),
simp only [lintegral_supr hf h2f, lintegral_supr (kf _), k2f, lintegral_supr lf l2f, h3f] },
end
/-- Tonelli's Theorem: For `ℝ≥0∞`-valued almost everywhere measurable functions on `α × β`,
the integral of `f` is equal to the iterated integral. -/
lemma lintegral_prod (f : α × β → ℝ≥0∞) (hf : ae_measurable f (μ.prod ν)) :
∫⁻ z, f z ∂(μ.prod ν) = ∫⁻ x, ∫⁻ y, f (x, y) ∂ν ∂μ :=
begin
have A : ∫⁻ z, f z ∂(μ.prod ν) = ∫⁻ z, hf.mk f z ∂(μ.prod ν) :=
lintegral_congr_ae hf.ae_eq_mk,
have B : ∫⁻ x, ∫⁻ y, f (x, y) ∂ν ∂μ = ∫⁻ x, ∫⁻ y, hf.mk f (x, y) ∂ν ∂μ,
{ apply lintegral_congr_ae,
filter_upwards [ae_ae_of_ae_prod hf.ae_eq_mk],
assume a ha,
exact lintegral_congr_ae ha },
rw [A, B, lintegral_prod_of_measurable _ hf.measurable_mk],
apply_instance
end
/-- The symmetric verion of Tonelli's Theorem: For `ℝ≥0∞`-valued almost everywhere measurable
functions on `α × β`, the integral of `f` is equal to the iterated integral, in reverse order. -/
lemma lintegral_prod_symm' [sigma_finite μ] (f : α × β → ℝ≥0∞)
(hf : ae_measurable f (μ.prod ν)) : ∫⁻ z, f z ∂(μ.prod ν) = ∫⁻ y, ∫⁻ x, f (x, y) ∂μ ∂ν :=
by { simp_rw [← lintegral_prod_swap f hf], exact lintegral_prod _ hf.prod_swap }
/-- The symmetric verion of Tonelli's Theorem: For `ℝ≥0∞`-valued measurable
functions on `α × β`, the integral of `f` is equal to the iterated integral, in reverse order. -/
lemma lintegral_prod_symm [sigma_finite μ] (f : α × β → ℝ≥0∞)
(hf : ae_measurable f (μ.prod ν)) : ∫⁻ z, f z ∂(μ.prod ν) = ∫⁻ y, ∫⁻ x, f (x, y) ∂μ ∂ν :=
lintegral_prod_symm' f hf
/-- The reversed version of Tonelli's Theorem. In this version `f` is in curried form, which makes
it easier for the elaborator to figure out `f` automatically. -/
lemma lintegral_lintegral ⦃f : α → β → ℝ≥0∞⦄
(hf : ae_measurable (uncurry f) (μ.prod ν)) :
∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ = ∫⁻ z, f z.1 z.2 ∂(μ.prod ν) :=
(lintegral_prod _ hf).symm
/-- The reversed version of Tonelli's Theorem (symmetric version). In this version `f` is in curried
form, which makes it easier for the elaborator to figure out `f` automatically. -/
lemma lintegral_lintegral_symm [sigma_finite μ] ⦃f : α → β → ℝ≥0∞⦄
(hf : ae_measurable (uncurry f) (μ.prod ν)) :
∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ = ∫⁻ z, f z.2 z.1 ∂(ν.prod μ) :=
(lintegral_prod_symm _ hf.prod_swap).symm
/-- Change the order of Lebesgue integration. -/
lemma lintegral_lintegral_swap [sigma_finite μ] ⦃f : α → β → ℝ≥0∞⦄
(hf : ae_measurable (uncurry f) (μ.prod ν)) :
∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ = ∫⁻ y, ∫⁻ x, f x y ∂μ ∂ν :=
(lintegral_lintegral hf).trans (lintegral_prod_symm _ hf)
lemma lintegral_prod_mul {f : α → ℝ≥0∞} {g : β → ℝ≥0∞}
(hf : ae_measurable f μ) (hg : ae_measurable g ν) :
∫⁻ z, f z.1 * g z.2 ∂(μ.prod ν) = ∫⁻ x, f x ∂μ * ∫⁻ y, g y ∂ν :=
by simp [lintegral_prod _ (hf.fst.mul hg.snd), lintegral_lintegral_mul hf hg]
/-! ### Integrability on a product -/
section
variables [opens_measurable_space E]
lemma integrable.swap [sigma_finite μ] ⦃f : α × β → E⦄
(hf : integrable f (μ.prod ν)) : integrable (f ∘ prod.swap) (ν.prod μ) :=
⟨hf.ae_measurable.prod_swap,
(lintegral_prod_swap _ hf.ae_measurable.ennnorm : _).le.trans_lt hf.has_finite_integral⟩
lemma integrable_swap_iff [sigma_finite μ] ⦃f : α × β → E⦄ :
integrable (f ∘ prod.swap) (ν.prod μ) ↔ integrable f (μ.prod ν) :=
⟨λ hf, by { convert hf.swap, ext ⟨x, y⟩, refl }, λ hf, hf.swap⟩
lemma has_finite_integral_prod_iff ⦃f : α × β → E⦄ (h1f : measurable f) :
has_finite_integral f (μ.prod ν) ↔ (∀ᵐ x ∂ μ, has_finite_integral (λ y, f (x, y)) ν) ∧
has_finite_integral (λ x, ∫ y, ∥f (x, y)∥ ∂ν) μ :=
begin
simp only [has_finite_integral, lintegral_prod_of_measurable _ h1f.ennnorm],
have : ∀ x, ∀ᵐ y ∂ν, 0 ≤ ∥f (x, y)∥ := λ x, eventually_of_forall (λ y, norm_nonneg _),
simp_rw [integral_eq_lintegral_of_nonneg_ae (this _)
(h1f.norm.comp measurable_prod_mk_left).ae_measurable,
ennnorm_eq_of_real to_real_nonneg, of_real_norm_eq_coe_nnnorm],
-- this fact is probably too specialized to be its own lemma
have : ∀ {p q r : Prop} (h1 : r → p), (r ↔ p ∧ q) ↔ (p → (r ↔ q)) :=
λ p q r h1, by rw [← and.congr_right_iff, and_iff_right_of_imp h1],
rw [this],
{ intro h2f, rw lintegral_congr_ae,
refine h2f.mp _, apply eventually_of_forall, intros x hx, dsimp only,
rw [of_real_to_real], rw [← lt_top_iff_ne_top], exact hx },
{ intro h2f, refine ae_lt_top _ h2f, exact h1f.ennnorm.lintegral_prod_right' },
end
lemma has_finite_integral_prod_iff' ⦃f : α × β → E⦄ (h1f : ae_measurable f (μ.prod ν)) :
has_finite_integral f (μ.prod ν) ↔ (∀ᵐ x ∂ μ, has_finite_integral (λ y, f (x, y)) ν) ∧
has_finite_integral (λ x, ∫ y, ∥f (x, y)∥ ∂ν) μ :=
begin
rw [has_finite_integral_congr h1f.ae_eq_mk, has_finite_integral_prod_iff h1f.measurable_mk],
apply and_congr,
{ apply eventually_congr,
filter_upwards [ae_ae_of_ae_prod h1f.ae_eq_mk.symm],
assume x hx,
exact has_finite_integral_congr hx },
{ apply has_finite_integral_congr,
filter_upwards [ae_ae_of_ae_prod h1f.ae_eq_mk.symm],
assume x hx,
exact integral_congr_ae (eventually_eq.fun_comp hx _) },
{ apply_instance }
end
/-- A binary function is integrable if the function `y ↦ f (x, y)` is integrable for almost every
`x` and the function `x ↦ ∫ ∥f (x, y)∥ dy` is integrable. -/
lemma integrable_prod_iff ⦃f : α × β → E⦄ (h1f : ae_measurable f (μ.prod ν)) :
integrable f (μ.prod ν) ↔
(∀ᵐ x ∂ μ, integrable (λ y, f (x, y)) ν) ∧ integrable (λ x, ∫ y, ∥f (x, y)∥ ∂ν) μ :=
by simp [integrable, h1f, has_finite_integral_prod_iff', h1f.norm.integral_prod_right',
h1f.prod_mk_left]
/-- A binary function is integrable if the function `x ↦ f (x, y)` is integrable for almost every
`y` and the function `y ↦ ∫ ∥f (x, y)∥ dx` is integrable. -/
lemma integrable_prod_iff' [sigma_finite μ] ⦃f : α × β → E⦄ (h1f : ae_measurable f (μ.prod ν)) :
integrable f (μ.prod ν) ↔
(∀ᵐ y ∂ ν, integrable (λ x, f (x, y)) μ) ∧ integrable (λ y, ∫ x, ∥f (x, y)∥ ∂μ) ν :=
by { convert integrable_prod_iff (h1f.prod_swap) using 1, rw [integrable_swap_iff] }
lemma integrable.prod_left_ae [sigma_finite μ] ⦃f : α × β → E⦄
(hf : integrable f (μ.prod ν)) : ∀ᵐ y ∂ ν, integrable (λ x, f (x, y)) μ :=
((integrable_prod_iff' hf.ae_measurable).mp hf).1
lemma integrable.prod_right_ae [sigma_finite μ] ⦃f : α × β → E⦄
(hf : integrable f (μ.prod ν)) : ∀ᵐ x ∂ μ, integrable (λ y, f (x, y)) ν :=
hf.swap.prod_left_ae
lemma integrable.integral_norm_prod_left ⦃f : α × β → E⦄
(hf : integrable f (μ.prod ν)) : integrable (λ x, ∫ y, ∥f (x, y)∥ ∂ν) μ :=
((integrable_prod_iff hf.ae_measurable).mp hf).2
lemma integrable.integral_norm_prod_right [sigma_finite μ] ⦃f : α × β → E⦄
(hf : integrable f (μ.prod ν)) : integrable (λ y, ∫ x, ∥f (x, y)∥ ∂μ) ν :=
hf.swap.integral_norm_prod_left
end
variables [second_countable_topology E] [normed_space ℝ E]
[complete_space E] [borel_space E]
lemma integrable.integral_prod_left ⦃f : α × β → E⦄
(hf : integrable f (μ.prod ν)) : integrable (λ x, ∫ y, f (x, y) ∂ν) μ :=
integrable.mono hf.integral_norm_prod_left hf.ae_measurable.integral_prod_right' $
eventually_of_forall $ λ x, (norm_integral_le_integral_norm _).trans_eq $
(norm_of_nonneg $ integral_nonneg_of_ae $ eventually_of_forall $
λ y, (norm_nonneg (f (x, y)) : _)).symm
lemma integrable.integral_prod_right [sigma_finite μ] ⦃f : α × β → E⦄
(hf : integrable f (μ.prod ν)) : integrable (λ y, ∫ x, f (x, y) ∂μ) ν :=
hf.swap.integral_prod_left
/-! ### The Bochner integral on a product -/
variables [sigma_finite μ]
lemma integral_prod_swap (f : α × β → E)
(hf : ae_measurable f (μ.prod ν)) : ∫ z, f z.swap ∂(ν.prod μ) = ∫ z, f z ∂(μ.prod ν) :=
begin
rw ← prod_swap at hf,
rw [← integral_map measurable_swap hf, prod_swap]
end
variables {E' : Type*} [measurable_space E'] [normed_group E'] [borel_space E'] [complete_space E']
[normed_space ℝ E'] [second_countable_topology E']
/-! Some rules about the sum/difference of double integrals. They follow from `integral_add`, but
we separate them out as separate lemmas, because they involve quite some steps. -/
/-- Integrals commute with addition inside another integral. `F` can be any function. -/
lemma integral_fn_integral_add ⦃f g : α × β → E⦄ (F : E → E')
(hf : integrable f (μ.prod ν)) (hg : integrable g (μ.prod ν)) :
∫ x, F (∫ y, f (x, y) + g (x, y) ∂ν) ∂μ = ∫ x, F (∫ y, f (x, y) ∂ν + ∫ y, g (x, y) ∂ν) ∂μ :=
begin
refine integral_congr_ae _,
filter_upwards [hf.prod_right_ae, hg.prod_right_ae],
intros x h2f h2g, simp [integral_add h2f h2g],
end
/-- Integrals commute with subtraction inside another integral.
`F` can be any measurable function. -/
lemma integral_fn_integral_sub ⦃f g : α × β → E⦄ (F : E → E')
(hf : integrable f (μ.prod ν)) (hg : integrable g (μ.prod ν)) :
∫ x, F (∫ y, f (x, y) - g (x, y) ∂ν) ∂μ = ∫ x, F (∫ y, f (x, y) ∂ν - ∫ y, g (x, y) ∂ν) ∂μ :=
begin
refine integral_congr_ae _,
filter_upwards [hf.prod_right_ae, hg.prod_right_ae],
intros x h2f h2g, simp [integral_sub h2f h2g]
end
/-- Integrals commute with subtraction inside a lower Lebesgue integral.
`F` can be any function. -/
lemma lintegral_fn_integral_sub ⦃f g : α × β → E⦄
(F : E → ℝ≥0∞) (hf : integrable f (μ.prod ν)) (hg : integrable g (μ.prod ν)) :
∫⁻ x, F (∫ y, f (x, y) - g (x, y) ∂ν) ∂μ = ∫⁻ x, F (∫ y, f (x, y) ∂ν - ∫ y, g (x, y) ∂ν) ∂μ :=
begin
refine lintegral_congr_ae _,
filter_upwards [hf.prod_right_ae, hg.prod_right_ae],
intros x h2f h2g, simp [integral_sub h2f h2g]
end
/-- Double integrals commute with addition. -/
lemma integral_integral_add ⦃f g : α × β → E⦄
(hf : integrable f (μ.prod ν)) (hg : integrable g (μ.prod ν)) :
∫ x, ∫ y, f (x, y) + g (x, y) ∂ν ∂μ = ∫ x, ∫ y, f (x, y) ∂ν ∂μ + ∫ x, ∫ y, g (x, y) ∂ν ∂μ :=
(integral_fn_integral_add id hf hg).trans $
integral_add hf.integral_prod_left hg.integral_prod_left
/-- Double integrals commute with addition. This is the version with `(f + g) (x, y)`
(instead of `f (x, y) + g (x, y)`) in the LHS. -/
lemma integral_integral_add' ⦃f g : α × β → E⦄
(hf : integrable f (μ.prod ν)) (hg : integrable g (μ.prod ν)) :
∫ x, ∫ y, (f + g) (x, y) ∂ν ∂μ = ∫ x, ∫ y, f (x, y) ∂ν ∂μ + ∫ x, ∫ y, g (x, y) ∂ν ∂μ :=
integral_integral_add hf hg
/-- Double integrals commute with subtraction. -/
lemma integral_integral_sub ⦃f g : α × β → E⦄
(hf : integrable f (μ.prod ν)) (hg : integrable g (μ.prod ν)) :
∫ x, ∫ y, f (x, y) - g (x, y) ∂ν ∂μ = ∫ x, ∫ y, f (x, y) ∂ν ∂μ - ∫ x, ∫ y, g (x, y) ∂ν ∂μ :=
(integral_fn_integral_sub id hf hg).trans $
integral_sub hf.integral_prod_left hg.integral_prod_left
/-- Double integrals commute with subtraction. This is the version with `(f - g) (x, y)`
(instead of `f (x, y) - g (x, y)`) in the LHS. -/
lemma integral_integral_sub' ⦃f g : α × β → E⦄
(hf : integrable f (μ.prod ν)) (hg : integrable g (μ.prod ν)) :
∫ x, ∫ y, (f - g) (x, y) ∂ν ∂μ = ∫ x, ∫ y, f (x, y) ∂ν ∂μ - ∫ x, ∫ y, g (x, y) ∂ν ∂μ :=
integral_integral_sub hf hg
/-- The map that sends an L¹-function `f : α × β → E` to `∫∫f` is continuous. -/
lemma continuous_integral_integral :
continuous (λ (f : α × β →₁[μ.prod ν] E), ∫ x, ∫ y, f (x, y) ∂ν ∂μ) :=
begin
rw [continuous_iff_continuous_at], intro g,
refine tendsto_integral_of_L1 _ (L1.integrable_coe_fn g).integral_prod_left
(eventually_of_forall $ λ h, (L1.integrable_coe_fn h).integral_prod_left) _,
simp_rw [edist_eq_coe_nnnorm_sub,
← lintegral_fn_integral_sub (λ x, (nnnorm x : ℝ≥0∞)) (L1.integrable_coe_fn _)
(L1.integrable_coe_fn g)],
refine tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds _ (λ i, zero_le _) _,
{ exact λ i, ∫⁻ x, ∫⁻ y, nnnorm (i (x, y) - g (x, y)) ∂ν ∂μ },
swap, { exact λ i, lintegral_mono (λ x, ennnorm_integral_le_lintegral_ennnorm _) },
show tendsto (λ (i : α × β →₁[μ.prod ν] E),
∫⁻ x, ∫⁻ (y : β), nnnorm (i (x, y) - g (x, y)) ∂ν ∂μ) (𝓝 g) (𝓝 0),
have : ∀ (i : α × β →₁[μ.prod ν] E), measurable (λ z, (nnnorm (i z - g z) : ℝ≥0∞)) :=
λ i, ((Lp.measurable i).sub (Lp.measurable g)).ennnorm,
simp_rw [← lintegral_prod_of_measurable _ (this _), ← L1.of_real_norm_sub_eq_lintegral,
← of_real_zero],
refine (continuous_of_real.tendsto 0).comp _,
rw [← tendsto_iff_norm_tendsto_zero], exact tendsto_id
end
/-- Fubini's Theorem: For integrable functions on `α × β`,
the Bochner integral of `f` is equal to the iterated Bochner integral.
`integrable_prod_iff` can be useful to show that the function in question in integrable.
`measure_theory.integrable.integral_prod_right` is useful to show that the inner integral
of the right-hand side is integrable. -/
lemma integral_prod : ∀ (f : α × β → E) (hf : integrable f (μ.prod ν)),
∫ z, f z ∂(μ.prod ν) = ∫ x, ∫ y, f (x, y) ∂ν ∂μ :=
begin
apply integrable.induction,
{ intros c s hs h2s,
simp_rw [integral_indicator hs, ← indicator_comp_right,
function.comp, integral_indicator (measurable_prod_mk_left hs),
set_integral_const, integral_smul_const,
integral_to_real (measurable_measure_prod_mk_left hs).ae_measurable
(ae_measure_lt_top hs h2s), prod_apply hs] },
{ intros f g hfg i_f i_g hf hg,
simp_rw [integral_add' i_f i_g, integral_integral_add' i_f i_g, hf, hg] },
{ exact is_closed_eq continuous_integral continuous_integral_integral },
{ intros f g hfg i_f hf, convert hf using 1,
{ exact integral_congr_ae hfg.symm },
{ refine integral_congr_ae _,
refine (ae_ae_of_ae_prod hfg).mp _,
apply eventually_of_forall, intros x hfgx,
exact integral_congr_ae (ae_eq_symm hfgx) } }
end
/-- Symmetric version of Fubini's Theorem: For integrable functions on `α × β`,
the Bochner integral of `f` is equal to the iterated Bochner integral.
This version has the integrals on the right-hand side in the other order. -/
lemma integral_prod_symm (f : α × β → E) (hf : integrable f (μ.prod ν)) :
∫ z, f z ∂(μ.prod ν) = ∫ y, ∫ x, f (x, y) ∂μ ∂ν :=
by { simp_rw [← integral_prod_swap f hf.ae_measurable], exact integral_prod _ hf.swap }
/-- Reversed version of Fubini's Theorem. -/
lemma integral_integral {f : α → β → E} (hf : integrable (uncurry f) (μ.prod ν)) :
∫ x, ∫ y, f x y ∂ν ∂μ = ∫ z, f z.1 z.2 ∂(μ.prod ν) :=
(integral_prod _ hf).symm
/-- Reversed version of Fubini's Theorem (symmetric version). -/
lemma integral_integral_symm {f : α → β → E} (hf : integrable (uncurry f) (μ.prod ν)) :
∫ x, ∫ y, f x y ∂ν ∂μ = ∫ z, f z.2 z.1 ∂(ν.prod μ) :=
(integral_prod_symm _ hf.swap).symm
/-- Change the order of Bochner integration. -/
lemma integral_integral_swap ⦃f : α → β → E⦄ (hf : integrable (uncurry f) (μ.prod ν)) :
∫ x, ∫ y, f x y ∂ν ∂μ = ∫ y, ∫ x, f x y ∂μ ∂ν :=
(integral_integral hf).trans (integral_prod_symm _ hf)
end measure_theory
|
5aaf212bd36fbd0f1615397445a297a519097d21 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/field_theory/perfect_closure.lean | 4cd7e40e568458f1abaf24768003bea3686c4729 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 17,390 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Yury Kudryashov
-/
import algebra.char_p.basic
import data.equiv.ring
import algebra.group_with_zero.power
import algebra.iterate_hom
/-!
# The perfect closure of a field
-/
universes u v
open function
section defs
variables (R : Type u) [comm_semiring R] (p : ℕ) [fact p.prime] [char_p R p]
/-- A perfect ring is a ring of characteristic p that has p-th root. -/
class perfect_ring : Type u :=
(pth_root' : R → R)
(frobenius_pth_root' : ∀ x, frobenius R p (pth_root' x) = x)
(pth_root_frobenius' : ∀ x, pth_root' (frobenius R p x) = x)
/-- Frobenius automorphism of a perfect ring. -/
def frobenius_equiv [perfect_ring R p] : R ≃+* R :=
{ inv_fun := perfect_ring.pth_root' p,
left_inv := perfect_ring.pth_root_frobenius',
right_inv := perfect_ring.frobenius_pth_root',
.. frobenius R p }
/-- `p`-th root of an element in a `perfect_ring` as a `ring_hom`. -/
def pth_root [perfect_ring R p] : R →+* R :=
(frobenius_equiv R p).symm
end defs
section
variables {R : Type u} [comm_semiring R] {S : Type v} [comm_semiring S] (f : R →* S) (g : R →+* S)
{p : ℕ} [fact p.prime] [char_p R p] [perfect_ring R p] [char_p S p] [perfect_ring S p]
@[simp] lemma coe_frobenius_equiv : ⇑(frobenius_equiv R p) = frobenius R p := rfl
@[simp] lemma coe_frobenius_equiv_symm : ⇑(frobenius_equiv R p).symm = pth_root R p := rfl
@[simp] theorem frobenius_pth_root (x : R) : frobenius R p (pth_root R p x) = x :=
(frobenius_equiv R p).apply_symm_apply x
@[simp] theorem pth_root_pow_p (x : R) : pth_root R p x ^ p = x :=
frobenius_pth_root x
@[simp] theorem pth_root_frobenius (x : R) : pth_root R p (frobenius R p x) = x :=
(frobenius_equiv R p).symm_apply_apply x
@[simp] theorem pth_root_pow_p' (x : R) : pth_root R p (x ^ p) = x :=
pth_root_frobenius x
theorem left_inverse_pth_root_frobenius : left_inverse (pth_root R p) (frobenius R p) :=
pth_root_frobenius
theorem right_inverse_pth_root_frobenius : function.right_inverse (pth_root R p) (frobenius R p) :=
frobenius_pth_root
theorem commute_frobenius_pth_root : function.commute (frobenius R p) (pth_root R p) :=
λ x, (frobenius_pth_root x).trans (pth_root_frobenius x).symm
theorem eq_pth_root_iff {x y : R} : x = pth_root R p y ↔ frobenius R p x = y :=
(frobenius_equiv R p).to_equiv.eq_symm_apply
theorem pth_root_eq_iff {x y : R} : pth_root R p x = y ↔ x = frobenius R p y :=
(frobenius_equiv R p).to_equiv.symm_apply_eq
theorem monoid_hom.map_pth_root (x : R) : f (pth_root R p x) = pth_root S p (f x) :=
eq_pth_root_iff.2 $ by rw [← f.map_frobenius, frobenius_pth_root]
theorem monoid_hom.map_iterate_pth_root (x : R) (n : ℕ) :
f (pth_root R p^[n] x) = (pth_root S p^[n] (f x)) :=
semiconj.iterate_right f.map_pth_root n x
theorem ring_hom.map_pth_root (x : R) :
g (pth_root R p x) = pth_root S p (g x) :=
g.to_monoid_hom.map_pth_root x
theorem ring_hom.map_iterate_pth_root (x : R) (n : ℕ) :
g (pth_root R p^[n] x) = (pth_root S p^[n] (g x)) :=
g.to_monoid_hom.map_iterate_pth_root x n
variables (p)
lemma injective_pow_p {x y : R} (hxy : x ^ p = y ^ p) : x = y :=
left_inverse_pth_root_frobenius.injective hxy
end
section
variables (K : Type u) [comm_ring K] (p : ℕ) [fact p.prime] [char_p K p]
/-- `perfect_closure K p` is the quotient by this relation. -/
@[mk_iff] inductive perfect_closure.r : (ℕ × K) → (ℕ × K) → Prop
| intro : ∀ n x, perfect_closure.r (n, x) (n+1, frobenius K p x)
/-- The perfect closure is the smallest extension that makes frobenius surjective. -/
def perfect_closure : Type u := quot (perfect_closure.r K p)
end
namespace perfect_closure
variables (K : Type u)
section ring
variables [comm_ring K] (p : ℕ) [fact p.prime] [char_p K p]
/-- Constructor for `perfect_closure`. -/
def mk (x : ℕ × K) : perfect_closure K p := quot.mk (r K p) x
@[simp] lemma quot_mk_eq_mk (x : ℕ × K) :
(quot.mk (r K p) x : perfect_closure K p) = mk K p x := rfl
variables {K p}
/-- Lift a function `ℕ × K → L` to a function on `perfect_closure K p`. -/
@[elab_as_eliminator]
def lift_on {L : Type*} (x : perfect_closure K p) (f : ℕ × K → L)
(hf : ∀ x y, r K p x y → f x = f y) : L :=
quot.lift_on x f hf
@[simp] lemma lift_on_mk {L : Sort*} (f : ℕ × K → L)
(hf : ∀ x y, r K p x y → f x = f y) (x : ℕ × K) :
(mk K p x).lift_on f hf = f x :=
rfl
@[elab_as_eliminator]
lemma induction_on (x : perfect_closure K p) {q : perfect_closure K p → Prop}
(h : ∀ x, q (mk K p x)) : q x :=
quot.induction_on x h
variables (K p)
private lemma mul_aux_left (x1 x2 y : ℕ × K) (H : r K p x1 x2) :
mk K p (x1.1 + y.1, ((frobenius K p)^[y.1] x1.2) * ((frobenius K p)^[x1.1] y.2)) =
mk K p (x2.1 + y.1, ((frobenius K p)^[y.1] x2.2) * ((frobenius K p)^[x2.1] y.2)) :=
match x1, x2, H with
| _, _, r.intro n x := quot.sound $ by rw [← iterate_succ_apply, iterate_succ',
iterate_succ', ← frobenius_mul, nat.succ_add]; apply r.intro
end
private lemma mul_aux_right (x y1 y2 : ℕ × K) (H : r K p y1 y2) :
mk K p (x.1 + y1.1, ((frobenius K p)^[y1.1] x.2) * ((frobenius K p)^[x.1] y1.2)) =
mk K p (x.1 + y2.1, ((frobenius K p)^[y2.1] x.2) * ((frobenius K p)^[x.1] y2.2)) :=
match y1, y2, H with
| _, _, r.intro n y := quot.sound $ by rw [← iterate_succ_apply, iterate_succ',
iterate_succ', ← frobenius_mul]; apply r.intro
end
instance : has_mul (perfect_closure K p) :=
⟨quot.lift (λ x:ℕ×K, quot.lift (λ y:ℕ×K, mk K p
(x.1 + y.1, ((frobenius K p)^[y.1] x.2) * ((frobenius K p)^[x.1] y.2))) (mul_aux_right K p x))
(λ x1 x2 (H : r K p x1 x2), funext $ λ e, quot.induction_on e $ λ y,
mul_aux_left K p x1 x2 y H)⟩
@[simp] lemma mk_mul_mk (x y : ℕ × K) :
mk K p x * mk K p y = mk K p
(x.1 + y.1, ((frobenius K p)^[y.1] x.2) * ((frobenius K p)^[x.1] y.2)) :=
rfl
instance : comm_monoid (perfect_closure K p) :=
{ mul_assoc := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, congr_arg (quot.mk _) $
by simp only [add_assoc, mul_assoc, ring_hom.iterate_map_mul,
← iterate_add_apply, add_comm, add_left_comm],
one := mk K p (0, 1),
one_mul := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_one, iterate_zero_apply, one_mul, zero_add]),
mul_one := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_one, iterate_zero_apply, mul_one, add_zero]),
mul_comm := λ e f, quot.induction_on e (λ ⟨m, x⟩, quot.induction_on f (λ ⟨n, y⟩,
congr_arg (quot.mk _) $ by simp only [add_comm, mul_comm])),
.. (infer_instance : has_mul (perfect_closure K p)) }
lemma one_def : (1 : perfect_closure K p) = mk K p (0, 1) := rfl
instance : inhabited (perfect_closure K p) := ⟨1⟩
private lemma add_aux_left (x1 x2 y : ℕ × K) (H : r K p x1 x2) :
mk K p (x1.1 + y.1, ((frobenius K p)^[y.1] x1.2) + ((frobenius K p)^[x1.1] y.2)) =
mk K p (x2.1 + y.1, ((frobenius K p)^[y.1] x2.2) + ((frobenius K p)^[x2.1] y.2)) :=
match x1, x2, H with
| _, _, r.intro n x := quot.sound $ by rw [← iterate_succ_apply, iterate_succ',
iterate_succ', ← frobenius_add, nat.succ_add]; apply r.intro
end
private lemma add_aux_right (x y1 y2 : ℕ × K) (H : r K p y1 y2) :
mk K p (x.1 + y1.1, ((frobenius K p)^[y1.1] x.2) + ((frobenius K p)^[x.1] y1.2)) =
mk K p (x.1 + y2.1, ((frobenius K p)^[y2.1] x.2) + ((frobenius K p)^[x.1] y2.2)) :=
match y1, y2, H with
| _, _, r.intro n y := quot.sound $ by rw [← iterate_succ_apply, iterate_succ',
iterate_succ', ← frobenius_add]; apply r.intro
end
instance : has_add (perfect_closure K p) :=
⟨quot.lift (λ x:ℕ×K, quot.lift (λ y:ℕ×K, mk K p
(x.1 + y.1, ((frobenius K p)^[y.1] x.2) + ((frobenius K p)^[x.1] y.2))) (add_aux_right K p x))
(λ x1 x2 (H : r K p x1 x2), funext $ λ e, quot.induction_on e $ λ y,
add_aux_left K p x1 x2 y H)⟩
@[simp] lemma mk_add_mk (x y : ℕ × K) :
mk K p x + mk K p y =
mk K p (x.1 + y.1, ((frobenius K p)^[y.1] x.2) + ((frobenius K p)^[x.1] y.2)) := rfl
instance : has_neg (perfect_closure K p) :=
⟨quot.lift (λ x:ℕ×K, mk K p (x.1, -x.2)) (λ x y (H : r K p x y), match x, y, H with
| _, _, r.intro n x := quot.sound $ by rw ← frobenius_neg; apply r.intro
end)⟩
@[simp] lemma neg_mk (x : ℕ × K) : - mk K p x = mk K p (x.1, -x.2) := rfl
instance : has_zero (perfect_closure K p) := ⟨mk K p (0, 0)⟩
lemma zero_def : (0 : perfect_closure K p) = mk K p (0, 0) := rfl
theorem mk_zero (n : ℕ) : mk K p (n, 0) = 0 :=
by induction n with n ih; [refl, rw ← ih]; symmetry; apply quot.sound;
have := r.intro n (0:K); rwa [frobenius_zero K p] at this
theorem r.sound (m n : ℕ) (x y : K) (H : frobenius K p^[m] x = y) :
mk K p (n, x) = mk K p (m + n, y) :=
by subst H; induction m with m ih; [simp only [zero_add, iterate_zero_apply],
rw [ih, nat.succ_add, iterate_succ']]; apply quot.sound; apply r.intro
instance : comm_ring (perfect_closure K p) :=
{ add_assoc := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_add, ← iterate_add_apply, add_assoc, add_comm s _],
zero := 0,
zero_add := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_zero, iterate_zero_apply, zero_add]),
add_zero := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_zero, iterate_zero_apply, add_zero]),
sub_eq_add_neg := λ a b, rfl,
add_left_neg := λ e, by exact quot.induction_on e (λ ⟨n, x⟩,
by simp only [quot_mk_eq_mk, neg_mk, mk_add_mk,
ring_hom.iterate_map_neg, add_left_neg, mk_zero]),
add_comm := λ e f, quot.induction_on e (λ ⟨m, x⟩, quot.induction_on f (λ ⟨n, y⟩,
congr_arg (quot.mk _) $ by simp only [add_comm])),
left_distrib := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, show quot.mk _ _ = quot.mk _ _,
by simp only [add_assoc, add_comm, add_left_comm]; apply r.sound;
simp only [ring_hom.iterate_map_mul, ring_hom.iterate_map_add,
← iterate_add_apply, mul_add, add_comm, add_left_comm],
right_distrib := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, show quot.mk _ _ = quot.mk _ _,
by simp only [add_assoc, add_comm _ s, add_left_comm _ s]; apply r.sound;
simp only [ring_hom.iterate_map_mul, ring_hom.iterate_map_add,
← iterate_add_apply, add_mul, add_comm, add_left_comm],
.. (infer_instance : has_add (perfect_closure K p)),
.. (infer_instance : has_neg (perfect_closure K p)),
.. (infer_instance : comm_monoid (perfect_closure K p)) }
theorem eq_iff' (x y : ℕ × K) : mk K p x = mk K p y ↔
∃ z, (frobenius K p^[y.1 + z] x.2) = (frobenius K p^[x.1 + z] y.2) :=
begin
split,
{ intro H,
replace H := quot.exact _ H,
induction H,
case eqv_gen.rel : x y H
{ cases H with n x, exact ⟨0, rfl⟩ },
case eqv_gen.refl : H
{ exact ⟨0, rfl⟩ },
case eqv_gen.symm : x y H ih
{ cases ih with w ih, exact ⟨w, ih.symm⟩ },
case eqv_gen.trans : x y z H1 H2 ih1 ih2
{ cases ih1 with z1 ih1,
cases ih2 with z2 ih2,
existsi z2+(y.1+z1),
rw [← add_assoc, iterate_add_apply, ih1],
rw [← iterate_add_apply, add_comm, iterate_add_apply, ih2],
rw [← iterate_add_apply],
simp only [add_comm, add_left_comm] } },
intro H,
cases x with m x,
cases y with n y,
cases H with z H, dsimp only at H,
rw [r.sound K p (n+z) m x _ rfl, r.sound K p (m+z) n y _ rfl, H],
rw [add_assoc, add_comm, add_comm z]
end
theorem nat_cast (n x : ℕ) : (x : perfect_closure K p) = mk K p (n, x) :=
begin
induction n with n ih,
{ induction x with x ih, {refl},
rw [nat.cast_succ, nat.cast_succ, ih], refl },
rw ih, apply quot.sound,
conv {congr, skip, skip, rw ← frobenius_nat_cast K p x},
apply r.intro
end
theorem int_cast (x : ℤ) : (x : perfect_closure K p) = mk K p (0, x) :=
by induction x; simp only [int.cast_of_nat, int.cast_neg_succ_of_nat, nat_cast K p 0]; refl
theorem nat_cast_eq_iff (x y : ℕ) : (x : perfect_closure K p) = y ↔ (x : K) = y :=
begin
split; intro H,
{ rw [nat_cast K p 0, nat_cast K p 0, eq_iff'] at H,
cases H with z H,
simpa only [zero_add, iterate_fixed (frobenius_nat_cast K p _)] using H },
rw [nat_cast K p 0, nat_cast K p 0, H]
end
instance : char_p (perfect_closure K p) p :=
begin
constructor, intro x, rw ← char_p.cast_eq_zero_iff K,
rw [← nat.cast_zero, nat_cast_eq_iff, nat.cast_zero]
end
theorem frobenius_mk (x : ℕ × K) :
(frobenius (perfect_closure K p) p : perfect_closure K p → perfect_closure K p)
(mk K p x) = mk _ _ (x.1, x.2^p) :=
begin
simp only [frobenius_def], cases x with n x, dsimp only,
suffices : ∀ p':ℕ, mk K p (n, x) ^ p' = mk K p (n, x ^ p'),
{ apply this },
intro p, induction p with p ih,
case nat.zero { apply r.sound, rw [(frobenius _ _).iterate_map_one, pow_zero] },
case nat.succ {
rw [pow_succ, ih],
symmetry,
apply r.sound,
simp only [pow_succ, (frobenius _ _).iterate_map_mul] }
end
/-- Embedding of `K` into `perfect_closure K p` -/
def of : K →+* perfect_closure K p :=
{ to_fun := λ x, mk _ _ (0, x),
map_one' := rfl,
map_mul' := λ x y, rfl,
map_zero' := rfl,
map_add' := λ x y, rfl }
lemma of_apply (x : K) : of K p x = mk _ _ (0, x) := rfl
end ring
theorem eq_iff [comm_ring K] [is_domain K] (p : ℕ) [fact p.prime] [char_p K p]
(x y : ℕ × K) : quot.mk (r K p) x = quot.mk (r K p) y ↔
(frobenius K p^[y.1] x.2) = (frobenius K p^[x.1] y.2) :=
(eq_iff' K p x y).trans ⟨λ ⟨z, H⟩, (frobenius_inj K p).iterate z $
by simpa only [add_comm, iterate_add] using H,
λ H, ⟨0, H⟩⟩
section field
variables [field K] (p : ℕ) [fact p.prime] [char_p K p]
instance : has_inv (perfect_closure K p) :=
⟨quot.lift (λ x:ℕ×K, quot.mk (r K p) (x.1, x.2⁻¹)) (λ x y (H : r K p x y), match x, y, H with
| _, _, r.intro n x := quot.sound $ by { simp only [frobenius_def], rw ← inv_pow₀, apply r.intro }
end)⟩
instance : field (perfect_closure K p) :=
{ exists_pair_ne := ⟨0, 1, λ H, zero_ne_one ((eq_iff _ _ _ _).1 H)⟩,
mul_inv_cancel := λ e, induction_on e $ λ ⟨m, x⟩ H,
have _ := mt (eq_iff _ _ _ _).2 H, (eq_iff _ _ _ _).2
(by simp only [(frobenius _ _).iterate_map_one, (frobenius K p).iterate_map_zero,
iterate_zero_apply, ← (frobenius _ p).iterate_map_mul] at this ⊢;
rw [mul_inv_cancel this, (frobenius _ _).iterate_map_one]),
inv_zero := congr_arg (quot.mk (r K p)) (by rw [inv_zero]),
.. (infer_instance : has_inv (perfect_closure K p)),
.. (infer_instance : comm_ring (perfect_closure K p)) }
instance : perfect_ring (perfect_closure K p) p :=
{ pth_root' := λ e, lift_on e (λ x, mk K p (x.1 + 1, x.2)) (λ x y H,
match x, y, H with
| _, _, r.intro n x := quot.sound (r.intro _ _)
end),
frobenius_pth_root' := λ e, induction_on e (λ ⟨n, x⟩,
by { simp only [lift_on_mk, frobenius_mk], exact (quot.sound $ r.intro _ _).symm }),
pth_root_frobenius' := λ e, induction_on e (λ ⟨n, x⟩,
by { simp only [lift_on_mk, frobenius_mk], exact (quot.sound $ r.intro _ _).symm }) }
theorem eq_pth_root (x : ℕ × K) :
mk K p x = (pth_root (perfect_closure K p) p^[x.1] (of K p x.2)) :=
begin
rcases x with ⟨m, x⟩,
induction m with m ih, {refl},
rw [iterate_succ_apply', ← ih]; refl
end
/-- Given a field `K` of characteristic `p` and a perfect ring `L` of the same characteristic,
any homomorphism `K →+* L` can be lifted to `perfect_closure K p`. -/
def lift (L : Type v) [comm_semiring L] [char_p L p] [perfect_ring L p] :
(K →+* L) ≃ (perfect_closure K p →+* L) :=
begin
have := left_inverse_pth_root_frobenius.iterate,
refine_struct { .. },
field to_fun { intro f,
refine_struct { .. },
field to_fun { refine λ e, lift_on e (λ x, pth_root L p^[x.1] (f x.2)) _,
rintro a b ⟨n⟩,
simp only [f.map_frobenius, iterate_succ_apply, pth_root_frobenius] },
field map_one' { exact f.map_one },
field map_zero' { exact f.map_zero },
field map_mul' { rintro ⟨x⟩ ⟨y⟩,
simp only [quot_mk_eq_mk, lift_on_mk, mk_mul_mk, ring_hom.map_iterate_frobenius,
ring_hom.iterate_map_mul, ring_hom.map_mul],
rw [iterate_add_apply, this _ _, add_comm, iterate_add_apply, this _ _] },
field map_add' { rintro ⟨x⟩ ⟨y⟩,
simp only [quot_mk_eq_mk, lift_on_mk, mk_add_mk, ring_hom.map_iterate_frobenius,
ring_hom.iterate_map_add, ring_hom.map_add],
rw [iterate_add_apply, this _ _, add_comm x.1, iterate_add_apply, this _ _] } },
field inv_fun { exact λ f, f.comp (of K p) },
field left_inv { intro f, ext x, refl },
field right_inv { intro f, ext ⟨x⟩,
simp only [ring_hom.coe_mk, quot_mk_eq_mk, ring_hom.comp_apply, lift_on_mk],
rw [eq_pth_root, ring_hom.map_iterate_pth_root] }
end
end field
end perfect_closure
|
a753c6caaf6e4dba3f5a6ffe8134f4e65adad739 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/topology/list.lean | 9c9c61c317aa038b09808bda086b382e5204d0bd | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 8,828 | lean | /-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import topology.constructions
import topology.algebra.monoid
/-!
# Topology on lists and vectors
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
-/
open topological_space set filter
open_locale topology filter
variables {α : Type*} {β : Type*} [topological_space α] [topological_space β]
instance : topological_space (list α) :=
topological_space.mk_of_nhds (traverse nhds)
lemma nhds_list (as : list α) : 𝓝 as = traverse 𝓝 as :=
begin
refine nhds_mk_of_nhds _ _ _ _,
{ assume l, induction l,
case list.nil { exact le_rfl },
case list.cons : a l ih
{ suffices : list.cons <$> pure a <*> pure l ≤ list.cons <$> 𝓝 a <*> traverse 𝓝 l,
{ simpa only [] with functor_norm using this },
exact filter.seq_mono (filter.map_mono $ pure_le_nhds a) ih } },
{ assume l s hs,
rcases (mem_traverse_iff _ _).1 hs with ⟨u, hu, hus⟩, clear as hs,
have : ∃v:list (set α), l.forall₂ (λa s, is_open s ∧ a ∈ s) v ∧ sequence v ⊆ s,
{ induction hu generalizing s,
case list.forall₂.nil : hs this
{ existsi [], simpa only [list.forall₂_nil_left_iff, exists_eq_left] },
case list.forall₂.cons : a s as ss ht h ih t hts
{ rcases mem_nhds_iff.1 ht with ⟨u, hut, hu⟩,
rcases ih _ subset.rfl with ⟨v, hv, hvss⟩,
exact ⟨u::v, list.forall₂.cons hu hv,
subset.trans (set.seq_mono (set.image_subset _ hut) hvss) hts⟩ } },
rcases this with ⟨v, hv, hvs⟩,
refine ⟨sequence v, mem_traverse _ _ _, hvs, _⟩,
{ exact hv.imp (assume a s ⟨hs, ha⟩, is_open.mem_nhds hs ha) },
{ assume u hu,
have hu := (list.mem_traverse _ _).1 hu,
have : list.forall₂ (λa s, is_open s ∧ a ∈ s) u v,
{ refine list.forall₂.flip _,
replace hv := hv.flip,
simp only [list.forall₂_and_left, flip] at ⊢ hv,
exact ⟨hv.1, hu.flip⟩ },
refine mem_of_superset _ hvs,
exact mem_traverse _ _ (this.imp $ assume a s ⟨hs, ha⟩, is_open.mem_nhds hs ha) } }
end
@[simp] lemma nhds_nil : 𝓝 ([] : list α) = pure [] :=
by rw [nhds_list, list.traverse_nil _]; apply_instance
lemma nhds_cons (a : α) (l : list α) :
𝓝 (a :: l) = list.cons <$> 𝓝 a <*> 𝓝 l :=
by rw [nhds_list, list.traverse_cons _, ← nhds_list]; apply_instance
lemma list.tendsto_cons {a : α} {l : list α} :
tendsto (λp:α×list α, list.cons p.1 p.2) (𝓝 a ×ᶠ 𝓝 l) (𝓝 (a :: l)) :=
by rw [nhds_cons, tendsto, filter.map_prod]; exact le_rfl
lemma filter.tendsto.cons {α : Type*} {f : α → β} {g : α → list β}
{a : _root_.filter α} {b : β} {l : list β} (hf : tendsto f a (𝓝 b)) (hg : tendsto g a (𝓝 l)) :
tendsto (λa, list.cons (f a) (g a)) a (𝓝 (b :: l)) :=
list.tendsto_cons.comp (tendsto.prod_mk hf hg)
namespace list
lemma tendsto_cons_iff {β : Type*} {f : list α → β} {b : _root_.filter β} {a : α} {l : list α} :
tendsto f (𝓝 (a :: l)) b ↔ tendsto (λp:α×list α, f (p.1 :: p.2)) (𝓝 a ×ᶠ 𝓝 l) b :=
have 𝓝 (a :: l) = (𝓝 a ×ᶠ 𝓝 l).map (λp:α×list α, (p.1 :: p.2)),
begin
simp only
[nhds_cons, filter.prod_eq, (filter.map_def _ _).symm, (filter.seq_eq_filter_seq _ _).symm],
simp [-filter.seq_eq_filter_seq, -filter.map_def, (∘)] with functor_norm,
end,
by rw [this, filter.tendsto_map'_iff]
lemma continuous_cons : continuous (λ x : α × list α, (x.1 :: x.2 : list α)) :=
continuous_iff_continuous_at.mpr $ λ ⟨x, y⟩, continuous_at_fst.cons continuous_at_snd
lemma tendsto_nhds {β : Type*} {f : list α → β} {r : list α → _root_.filter β}
(h_nil : tendsto f (pure []) (r []))
(h_cons : ∀l a, tendsto f (𝓝 l) (r l) →
tendsto (λp:α×list α, f (p.1 :: p.2)) (𝓝 a ×ᶠ 𝓝 l) (r (a::l))) :
∀l, tendsto f (𝓝 l) (r l)
| [] := by rwa [nhds_nil]
| (a::l) := by rw [tendsto_cons_iff]; exact h_cons l a (tendsto_nhds l)
lemma continuous_at_length :
∀(l : list α), continuous_at list.length l :=
begin
simp only [continuous_at, nhds_discrete],
refine tendsto_nhds _ _,
{ exact tendsto_pure_pure _ _ },
{ assume l a ih,
dsimp only [list.length],
refine tendsto.comp (tendsto_pure_pure (λx, x + 1) _) _,
refine tendsto.comp ih tendsto_snd }
end
lemma tendsto_insert_nth' {a : α} : ∀{n : ℕ} {l : list α},
tendsto (λp:α×list α, insert_nth n p.1 p.2) (𝓝 a ×ᶠ 𝓝 l) (𝓝 (insert_nth n a l))
| 0 l := tendsto_cons
| (n+1) [] := by simp
| (n+1) (a'::l) :=
have 𝓝 a ×ᶠ 𝓝 (a' :: l) =
(𝓝 a ×ᶠ (𝓝 a' ×ᶠ 𝓝 l)).map (λp:α×α×list α, (p.1, p.2.1 :: p.2.2)),
begin
simp only [nhds_cons, filter.prod_eq, ← filter.map_def, ← filter.seq_eq_filter_seq],
simp [-filter.seq_eq_filter_seq, -filter.map_def, (∘)] with functor_norm
end,
begin
rw [this, tendsto_map'_iff],
exact (tendsto_fst.comp tendsto_snd).cons
((@tendsto_insert_nth' n l).comp $ tendsto_fst.prod_mk $ tendsto_snd.comp tendsto_snd)
end
lemma tendsto_insert_nth {β} {n : ℕ} {a : α} {l : list α} {f : β → α} {g : β → list α}
{b : _root_.filter β} (hf : tendsto f b (𝓝 a)) (hg : tendsto g b (𝓝 l)) :
tendsto (λb:β, insert_nth n (f b) (g b)) b (𝓝 (insert_nth n a l)) :=
tendsto_insert_nth'.comp (tendsto.prod_mk hf hg)
lemma continuous_insert_nth {n : ℕ} : continuous (λp:α×list α, insert_nth n p.1 p.2) :=
continuous_iff_continuous_at.mpr $
assume ⟨a, l⟩, by rw [continuous_at, nhds_prod_eq]; exact tendsto_insert_nth'
lemma tendsto_remove_nth : ∀{n : ℕ} {l : list α},
tendsto (λl, remove_nth l n) (𝓝 l) (𝓝 (remove_nth l n))
| _ [] := by rw [nhds_nil]; exact tendsto_pure_nhds _ _
| 0 (a::l) := by rw [tendsto_cons_iff]; exact tendsto_snd
| (n+1) (a::l) :=
begin
rw [tendsto_cons_iff],
dsimp [remove_nth],
exact tendsto_fst.cons ((@tendsto_remove_nth n l).comp tendsto_snd)
end
lemma continuous_remove_nth {n : ℕ} : continuous (λl : list α, remove_nth l n) :=
continuous_iff_continuous_at.mpr $ assume a, tendsto_remove_nth
@[to_additive]
lemma tendsto_prod [monoid α] [has_continuous_mul α] {l : list α} :
tendsto list.prod (𝓝 l) (𝓝 l.prod) :=
begin
induction l with x l ih,
{ simp [nhds_nil, mem_of_mem_nhds, tendsto_pure_left] {contextual := tt} },
simp_rw [tendsto_cons_iff, prod_cons],
have := continuous_iff_continuous_at.mp continuous_mul (x, l.prod),
rw [continuous_at, nhds_prod_eq] at this,
exact this.comp (tendsto_id.prod_map ih)
end
@[to_additive]
lemma continuous_prod [monoid α] [has_continuous_mul α] : continuous (prod : list α → α) :=
continuous_iff_continuous_at.mpr $ λ l, tendsto_prod
end list
namespace vector
open list
instance (n : ℕ) : topological_space (vector α n) :=
by unfold vector; apply_instance
lemma tendsto_cons {n : ℕ} {a : α} {l : vector α n}:
tendsto (λp:α×vector α n, p.1 ::ᵥ p.2) (𝓝 a ×ᶠ 𝓝 l) (𝓝 (a ::ᵥ l)) :=
by { simp [tendsto_subtype_rng, ←subtype.val_eq_coe, cons_val],
exact tendsto_fst.cons (tendsto.comp continuous_at_subtype_coe tendsto_snd) }
lemma tendsto_insert_nth
{n : ℕ} {i : fin (n+1)} {a:α} :
∀{l:vector α n}, tendsto (λp:α×vector α n, insert_nth p.1 i p.2)
(𝓝 a ×ᶠ 𝓝 l) (𝓝 (insert_nth a i l))
| ⟨l, hl⟩ :=
begin
rw [insert_nth, tendsto_subtype_rng],
simp [insert_nth_val],
exact list.tendsto_insert_nth tendsto_fst (tendsto.comp continuous_at_subtype_coe tendsto_snd : _)
end
lemma continuous_insert_nth' {n : ℕ} {i : fin (n+1)} :
continuous (λp:α×vector α n, insert_nth p.1 i p.2) :=
continuous_iff_continuous_at.mpr $ assume ⟨a, l⟩,
by rw [continuous_at, nhds_prod_eq]; exact tendsto_insert_nth
lemma continuous_insert_nth {n : ℕ} {i : fin (n+1)}
{f : β → α} {g : β → vector α n} (hf : continuous f) (hg : continuous g) :
continuous (λb, insert_nth (f b) i (g b)) :=
continuous_insert_nth'.comp (hf.prod_mk hg : _)
lemma continuous_at_remove_nth {n : ℕ} {i : fin (n+1)} :
∀{l:vector α (n+1)}, continuous_at (remove_nth i) l
| ⟨l, hl⟩ :=
-- ∀{l:vector α (n+1)}, tendsto (remove_nth i) (𝓝 l) (𝓝 (remove_nth i l))
--| ⟨l, hl⟩ :=
begin
rw [continuous_at, remove_nth, tendsto_subtype_rng],
simp only [← subtype.val_eq_coe, vector.remove_nth_val],
exact tendsto.comp list.tendsto_remove_nth continuous_at_subtype_coe,
end
lemma continuous_remove_nth {n : ℕ} {i : fin (n+1)} :
continuous (remove_nth i : vector α (n+1) → vector α n) :=
continuous_iff_continuous_at.mpr $ assume ⟨a, l⟩, continuous_at_remove_nth
end vector
|
4adcfe880c4d4a0ef7464fe3a86fbac0edf9f9bc | a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7 | /src/topology/metric_space/hausdorff_distance.lean | 5f776426e8b0957af35343184907014754032d43 | [
"Apache-2.0"
] | permissive | kmill/mathlib | ea5a007b67ae4e9e18dd50d31d8aa60f650425ee | 1a419a9fea7b959317eddd556e1bb9639f4dcc05 | refs/heads/master | 1,668,578,197,719 | 1,593,629,163,000 | 1,593,629,163,000 | 276,482,939 | 0 | 0 | null | 1,593,637,960,000 | 1,593,637,959,000 | null | UTF-8 | Lean | false | false | 32,342 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Sébastien Gouëzel
-/
import topology.metric_space.isometry
import topology.instances.ennreal
/-!
# Hausdorff distance
The Hausdorff distance on subsets of a metric (or emetric) space.
Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d`
such that any point `s` is within `d` of a point in `t`, and conversely. This quantity
is often infinite (think of `s` bounded and `t` unbounded), and therefore better
expressed in the setting of emetric spaces.
## Main definitions
This files introduces:
* `inf_edist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space
* `Hausdorff_edist s t`, the Hausdorff edistance of two sets in an emetric space
* Versions of these notions on metric spaces, called respectively `inf_dist` and
`Hausdorff_dist`.
-/
noncomputable theory
open_locale classical
universes u v w
open classical set function topological_space filter
namespace emetric
section inf_edist
open_locale ennreal
variables {α : Type u} {β : Type v} [emetric_space α] [emetric_space β] {x y : α} {s t : set α} {Φ : α → β}
/-- The minimal edistance of a point to a set -/
def inf_edist (x : α) (s : set α) : ennreal := Inf ((edist x) '' s)
@[simp] lemma inf_edist_empty : inf_edist x ∅ = ∞ :=
by unfold inf_edist; simp
/-- The edist to a union is the minimum of the edists -/
@[simp] lemma inf_edist_union : inf_edist x (s ∪ t) = inf_edist x s ⊓ inf_edist x t :=
by simp [inf_edist, image_union, Inf_union]
/-- The edist to a singleton is the edistance to the single point of this singleton -/
@[simp] lemma inf_edist_singleton : inf_edist x {y} = edist x y :=
by simp [inf_edist]
/-- The edist to a set is bounded above by the edist to any of its points -/
lemma inf_edist_le_edist_of_mem (h : y ∈ s) : inf_edist x s ≤ edist x y :=
Inf_le ((mem_image _ _ _).2 ⟨y, h, by refl⟩)
/-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/
lemma inf_edist_zero_of_mem (h : x ∈ s) : inf_edist x s = 0 :=
le_zero_iff_eq.1 $ @edist_self _ _ x ▸ inf_edist_le_edist_of_mem h
/-- The edist is monotonous with respect to inclusion -/
lemma inf_edist_le_inf_edist_of_subset (h : s ⊆ t) : inf_edist x t ≤ inf_edist x s :=
Inf_le_Inf (image_subset _ h)
/-- If the edist to a set is `< r`, there exists a point in the set at edistance `< r` -/
lemma exists_edist_lt_of_inf_edist_lt {r : ennreal} (h : inf_edist x s < r) :
∃y∈s, edist x y < r :=
let ⟨t, ⟨ht, tr⟩⟩ := Inf_lt_iff.1 h in
let ⟨y, ⟨ys, hy⟩⟩ := (mem_image _ _ _).1 ht in
⟨y, ys, by rwa ← hy at tr⟩
/-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and
the edist from `x` to `y` -/
lemma inf_edist_le_inf_edist_add_edist : inf_edist x s ≤ inf_edist y s + edist x y :=
begin
have : ∀z ∈ s, Inf (edist x '' s) ≤ edist y z + edist x y := λz hz, calc
Inf (edist x '' s) ≤ edist x z :
Inf_le ((mem_image _ _ _).2 ⟨z, hz, by refl⟩)
... ≤ edist x y + edist y z : edist_triangle _ _ _
... = edist y z + edist x y : add_comm _ _,
have : (λz, z + edist x y) (Inf (edist y '' s)) = Inf ((λz, z + edist x y) '' (edist y '' s)),
{ refine map_Inf_of_continuous_at_of_monotone _ _ (by simp),
{ exact continuous_at_id.add continuous_at_const },
{ assume a b h, simp, apply add_le_add_right' h }},
simp only [inf_edist] at this,
rw [inf_edist, inf_edist, this, ← image_comp],
simpa only [and_imp, function.comp_app, le_Inf_iff, exists_imp_distrib, ball_image_iff]
end
/-- The edist to a set depends continuously on the point -/
lemma continuous_inf_edist : continuous (λx, inf_edist x s) :=
continuous_of_le_add_edist 1 (by simp) $
by simp only [one_mul, inf_edist_le_inf_edist_add_edist, forall_2_true_iff]
/-- The edist to a set and to its closure coincide -/
lemma inf_edist_closure : inf_edist x (closure s) = inf_edist x s :=
begin
refine le_antisymm (inf_edist_le_inf_edist_of_subset subset_closure) _,
refine ennreal.le_of_forall_epsilon_le (λε εpos h, _),
have εpos' : (0 : ennreal) < ε := by simpa,
have : inf_edist x (closure s) < inf_edist x (closure s) + ε/2 :=
ennreal.lt_add_right h (ennreal.half_pos εpos'),
rcases exists_edist_lt_of_inf_edist_lt this with ⟨y, ycs, hy⟩,
-- y : α, ycs : y ∈ closure s, hy : edist x y < inf_edist x (closure s) + ↑ε / 2
rcases emetric.mem_closure_iff.1 ycs (ε/2) (ennreal.half_pos εpos') with ⟨z, zs, dyz⟩,
-- z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2
calc inf_edist x s ≤ edist x z : inf_edist_le_edist_of_mem zs
... ≤ edist x y + edist y z : edist_triangle _ _ _
... ≤ (inf_edist x (closure s) + ε / 2) + (ε/2) : add_le_add (le_of_lt hy) (le_of_lt dyz)
... = inf_edist x (closure s) + ↑ε : by rw [add_assoc, ennreal.add_halves]
end
/-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/
lemma mem_closure_iff_inf_edist_zero : x ∈ closure s ↔ inf_edist x s = 0 :=
⟨λh, by rw ← inf_edist_closure; exact inf_edist_zero_of_mem h,
λh, emetric.mem_closure_iff.2 $ λε εpos, exists_edist_lt_of_inf_edist_lt (by rwa h)⟩
/-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/
lemma mem_iff_ind_edist_zero_of_closed (h : is_closed s) : x ∈ s ↔ inf_edist x s = 0 :=
begin
convert ← mem_closure_iff_inf_edist_zero,
exact h.closure_eq
end
/-- The infimum edistance is invariant under isometries -/
lemma inf_edist_image (hΦ : isometry Φ) :
inf_edist (Φ x) (Φ '' t) = inf_edist x t :=
begin
simp only [inf_edist],
apply congr_arg,
ext b, split,
{ assume hb,
rcases (mem_image _ _ _).1 hb with ⟨y, ⟨hy, hy'⟩⟩,
rcases (mem_image _ _ _).1 hy with ⟨z, ⟨hz, hz'⟩⟩,
rw [← hy', ← hz', hΦ x z],
exact mem_image_of_mem _ hz },
{ assume hb,
rcases (mem_image _ _ _).1 hb with ⟨y, ⟨hy, hy'⟩⟩,
rw [← hy', ← hΦ x y],
exact mem_image_of_mem _ (mem_image_of_mem _ hy) }
end
end inf_edist --section
/-- The Hausdorff edistance between two sets is the smallest `r` such that each set
is contained in the `r`-neighborhood of the other one -/
def Hausdorff_edist {α : Type u} [emetric_space α] (s t : set α) : ennreal :=
Sup ((λx, inf_edist x t) '' s) ⊔ Sup ((λx, inf_edist x s) '' t)
lemma Hausdorff_edist_def {α : Type u} [emetric_space α] (s t : set α) :
Hausdorff_edist s t = Sup ((λx, inf_edist x t) '' s) ⊔ Sup ((λx, inf_edist x s) '' t) := rfl
attribute [irreducible] Hausdorff_edist
section Hausdorff_edist
open_locale ennreal
variables {α : Type u} {β : Type v} [emetric_space α] [emetric_space β]
{x y : α} {s t u : set α} {Φ : α → β}
/-- The Hausdorff edistance of a set to itself vanishes -/
@[simp] lemma Hausdorff_edist_self : Hausdorff_edist s s = 0 :=
begin
erw [Hausdorff_edist_def, sup_idem, ← le_bot_iff],
apply Sup_le _,
simp [le_bot_iff, inf_edist_zero_of_mem, le_refl] {contextual := tt},
end
/-- The Haudorff edistances of `s` to `t` and of `t` to `s` coincide -/
lemma Hausdorff_edist_comm : Hausdorff_edist s t = Hausdorff_edist t s :=
by unfold Hausdorff_edist; apply sup_comm
/-- Bounding the Hausdorff edistance by bounding the edistance of any point
in each set to the other set -/
lemma Hausdorff_edist_le_of_inf_edist {r : ennreal}
(H1 : ∀x ∈ s, inf_edist x t ≤ r) (H2 : ∀x ∈ t, inf_edist x s ≤ r) :
Hausdorff_edist s t ≤ r :=
begin
simp only [Hausdorff_edist, -mem_image, set.ball_image_iff, Sup_le_iff, sup_le_iff],
exact ⟨H1, H2⟩
end
/-- Bounding the Hausdorff edistance by exhibiting, for any point in each set,
another point in the other set at controlled distance -/
lemma Hausdorff_edist_le_of_mem_edist {r : ennreal}
(H1 : ∀x ∈ s, ∃y ∈ t, edist x y ≤ r) (H2 : ∀x ∈ t, ∃y ∈ s, edist x y ≤ r) :
Hausdorff_edist s t ≤ r :=
begin
refine Hausdorff_edist_le_of_inf_edist _ _,
{ assume x xs,
rcases H1 x xs with ⟨y, yt, hy⟩,
exact le_trans (inf_edist_le_edist_of_mem yt) hy },
{ assume x xt,
rcases H2 x xt with ⟨y, ys, hy⟩,
exact le_trans (inf_edist_le_edist_of_mem ys) hy }
end
/-- The distance to a set is controlled by the Hausdorff distance -/
lemma inf_edist_le_Hausdorff_edist_of_mem (h : x ∈ s) : inf_edist x t ≤ Hausdorff_edist s t :=
begin
rw Hausdorff_edist_def,
refine le_trans (le_Sup _) le_sup_left,
exact mem_image_of_mem _ h
end
/-- If the Hausdorff distance is `<r`, then any point in one of the sets has
a corresponding point at distance `<r` in the other set -/
lemma exists_edist_lt_of_Hausdorff_edist_lt {r : ennreal} (h : x ∈ s) (H : Hausdorff_edist s t < r) :
∃y∈t, edist x y < r :=
exists_edist_lt_of_inf_edist_lt $ calc
inf_edist x t ≤ Sup ((λx, inf_edist x t) '' s) : le_Sup (mem_image_of_mem _ h)
... ≤ Sup ((λx, inf_edist x t) '' s) ⊔ Sup ((λx, inf_edist x s) '' t) : le_sup_left
... < r : by rwa Hausdorff_edist_def at H
/-- The distance from `x` to `s`or `t` is controlled in terms of the Hausdorff distance
between `s` and `t` -/
lemma inf_edist_le_inf_edist_add_Hausdorff_edist :
inf_edist x t ≤ inf_edist x s + Hausdorff_edist s t :=
ennreal.le_of_forall_epsilon_le $ λε εpos h, begin
have εpos' : (0 : ennreal) < ε := by simpa,
have : inf_edist x s < inf_edist x s + ε/2 :=
ennreal.lt_add_right (ennreal.add_lt_top.1 h).1 (ennreal.half_pos εpos'),
rcases exists_edist_lt_of_inf_edist_lt this with ⟨y, ys, dxy⟩,
-- y : α, ys : y ∈ s, dxy : edist x y < inf_edist x s + ↑ε / 2
have : Hausdorff_edist s t < Hausdorff_edist s t + ε/2 :=
ennreal.lt_add_right (ennreal.add_lt_top.1 h).2 (ennreal.half_pos εpos'),
rcases exists_edist_lt_of_Hausdorff_edist_lt ys this with ⟨z, zt, dyz⟩,
-- z : α, zt : z ∈ t, dyz : edist y z < Hausdorff_edist s t + ↑ε / 2
calc inf_edist x t ≤ edist x z : inf_edist_le_edist_of_mem zt
... ≤ edist x y + edist y z : edist_triangle _ _ _
... ≤ (inf_edist x s + ε/2) + (Hausdorff_edist s t + ε/2) : add_le_add (le_of_lt dxy) (le_of_lt dyz)
... = inf_edist x s + Hausdorff_edist s t + ε : by simp [ennreal.add_halves, add_comm, add_left_comm]
end
/-- The Hausdorff edistance is invariant under eisometries -/
lemma Hausdorff_edist_image (h : isometry Φ) :
Hausdorff_edist (Φ '' s) (Φ '' t) = Hausdorff_edist s t :=
begin
unfold Hausdorff_edist,
congr,
{ ext b,
split,
{ assume hb,
rcases (mem_image _ _ _ ).1 hb with ⟨y, ⟨hy, hy'⟩⟩,
rcases (mem_image _ _ _ ).1 hy with ⟨z, ⟨hz, hz'⟩⟩,
rw [← hy', ← hz', inf_edist_image h],
exact mem_image_of_mem _ hz },
{ assume hb,
rcases (mem_image _ _ _ ).1 hb with ⟨y, ⟨hy, hy'⟩⟩,
rw [← hy', ← inf_edist_image h],
exact mem_image_of_mem _ (mem_image_of_mem _ hy) }},
{ ext b,
split,
{ assume hb,
rcases (mem_image _ _ _ ).1 hb with ⟨y, ⟨hy, hy'⟩⟩,
rcases (mem_image _ _ _ ).1 hy with ⟨z, ⟨hz, hz'⟩⟩,
rw [← hy', ← hz', inf_edist_image h],
exact mem_image_of_mem _ hz },
{ assume hb,
rcases (mem_image _ _ _ ).1 hb with ⟨y, ⟨hy, hy'⟩⟩,
rw [← hy', ← inf_edist_image h],
exact mem_image_of_mem _ (mem_image_of_mem _ hy) }}
end
/-- The Hausdorff distance is controlled by the diameter of the union -/
lemma Hausdorff_edist_le_ediam (hs : s.nonempty) (ht : t.nonempty) : Hausdorff_edist s t ≤ diam (s ∪ t) :=
begin
rcases hs with ⟨x, xs⟩,
rcases ht with ⟨y, yt⟩,
refine Hausdorff_edist_le_of_mem_edist _ _,
{ exact λz hz, ⟨y, yt, edist_le_diam_of_mem (subset_union_left _ _ hz) (subset_union_right _ _ yt)⟩ },
{ exact λz hz, ⟨x, xs, edist_le_diam_of_mem (subset_union_right _ _ hz) (subset_union_left _ _ xs)⟩ }
end
/-- The Hausdorff distance satisfies the triangular inequality -/
lemma Hausdorff_edist_triangle : Hausdorff_edist s u ≤ Hausdorff_edist s t + Hausdorff_edist t u :=
begin
rw Hausdorff_edist_def,
simp only [and_imp, set.mem_image, Sup_le_iff, exists_imp_distrib,
sup_le_iff, -mem_image, set.ball_image_iff],
split,
show ∀x ∈ s, inf_edist x u ≤ Hausdorff_edist s t + Hausdorff_edist t u, from λx xs, calc
inf_edist x u ≤ inf_edist x t + Hausdorff_edist t u : inf_edist_le_inf_edist_add_Hausdorff_edist
... ≤ Hausdorff_edist s t + Hausdorff_edist t u :
add_le_add_right' (inf_edist_le_Hausdorff_edist_of_mem xs),
show ∀x ∈ u, inf_edist x s ≤ Hausdorff_edist s t + Hausdorff_edist t u, from λx xu, calc
inf_edist x s ≤ inf_edist x t + Hausdorff_edist t s : inf_edist_le_inf_edist_add_Hausdorff_edist
... ≤ Hausdorff_edist u t + Hausdorff_edist t s :
add_le_add_right' (inf_edist_le_Hausdorff_edist_of_mem xu)
... = Hausdorff_edist s t + Hausdorff_edist t u : by simp [Hausdorff_edist_comm, add_comm]
end
/-- The Hausdorff edistance between a set and its closure vanishes -/
@[simp, priority 1100]
lemma Hausdorff_edist_self_closure : Hausdorff_edist s (closure s) = 0 :=
begin
erw ← le_bot_iff,
simp only [Hausdorff_edist, inf_edist_closure, -le_zero_iff_eq, and_imp,
set.mem_image, Sup_le_iff, exists_imp_distrib, sup_le_iff,
set.ball_image_iff, ennreal.bot_eq_zero, -mem_image],
simp only [inf_edist_zero_of_mem, mem_closure_iff_inf_edist_zero, le_refl, and_self,
forall_true_iff] {contextual := tt}
end
/-- Replacing a set by its closure does not change the Hausdorff edistance. -/
@[simp] lemma Hausdorff_edist_closure₁ : Hausdorff_edist (closure s) t = Hausdorff_edist s t :=
begin
refine le_antisymm _ _,
{ calc _ ≤ Hausdorff_edist (closure s) s + Hausdorff_edist s t : Hausdorff_edist_triangle
... = Hausdorff_edist s t : by simp [Hausdorff_edist_comm] },
{ calc _ ≤ Hausdorff_edist s (closure s) + Hausdorff_edist (closure s) t : Hausdorff_edist_triangle
... = Hausdorff_edist (closure s) t : by simp }
end
/-- Replacing a set by its closure does not change the Hausdorff edistance. -/
@[simp] lemma Hausdorff_edist_closure₂ : Hausdorff_edist s (closure t) = Hausdorff_edist s t :=
by simp [@Hausdorff_edist_comm _ _ s _]
/-- The Hausdorff edistance between sets or their closures is the same -/
@[simp] lemma Hausdorff_edist_closure : Hausdorff_edist (closure s) (closure t) = Hausdorff_edist s t :=
by simp
/-- Two sets are at zero Hausdorff edistance if and only if they have the same closure -/
lemma Hausdorff_edist_zero_iff_closure_eq_closure : Hausdorff_edist s t = 0 ↔ closure s = closure t :=
⟨begin
assume h,
refine subset.antisymm _ _,
{ have : s ⊆ closure t := λx xs, mem_closure_iff_inf_edist_zero.2 $ begin
erw ← le_bot_iff,
have := @inf_edist_le_Hausdorff_edist_of_mem _ _ _ _ t xs,
rwa h at this,
end,
by rw ← @closure_closure _ _ t; exact closure_mono this },
{ have : t ⊆ closure s := λx xt, mem_closure_iff_inf_edist_zero.2 $ begin
erw ← le_bot_iff,
have := @inf_edist_le_Hausdorff_edist_of_mem _ _ _ _ s xt,
rw Hausdorff_edist_comm at h,
rwa h at this,
end,
by rw ← @closure_closure _ _ s; exact closure_mono this }
end,
λh, by rw [← Hausdorff_edist_closure, h, Hausdorff_edist_self]⟩
/-- Two closed sets are at zero Hausdorff edistance if and only if they coincide -/
lemma Hausdorff_edist_zero_iff_eq_of_closed (hs : is_closed s) (ht : is_closed t) :
Hausdorff_edist s t = 0 ↔ s = t :=
by rw [Hausdorff_edist_zero_iff_closure_eq_closure, hs.closure_eq,
ht.closure_eq]
/-- The Haudorff edistance to the empty set is infinite -/
lemma Hausdorff_edist_empty (ne : s.nonempty) : Hausdorff_edist s ∅ = ∞ :=
begin
rcases ne with ⟨x, xs⟩,
have : inf_edist x ∅ ≤ Hausdorff_edist s ∅ := inf_edist_le_Hausdorff_edist_of_mem xs,
simpa using this,
end
/-- If a set is at finite Hausdorff edistance of a nonempty set, it is nonempty -/
lemma nonempty_of_Hausdorff_edist_ne_top (hs : s.nonempty) (fin : Hausdorff_edist s t ≠ ⊤) :
t.nonempty :=
t.eq_empty_or_nonempty.elim (λ ht, (fin $ ht.symm ▸ Hausdorff_edist_empty hs).elim) id
lemma empty_or_nonempty_of_Hausdorff_edist_ne_top (fin : Hausdorff_edist s t ≠ ⊤) :
s = ∅ ∧ t = ∅ ∨ s.nonempty ∧ t.nonempty :=
begin
cases s.eq_empty_or_nonempty with hs hs,
{ cases t.eq_empty_or_nonempty with ht ht,
{ exact or.inl ⟨hs, ht⟩ },
{ rw Hausdorff_edist_comm at fin,
exact or.inr ⟨nonempty_of_Hausdorff_edist_ne_top ht fin, ht⟩ } },
{ exact or.inr ⟨hs, nonempty_of_Hausdorff_edist_ne_top hs fin⟩ }
end
end Hausdorff_edist -- section
end emetric --namespace
/-Now, we turn to the same notions in metric spaces. To avoid the difficulties related to
Inf and Sup on ℝ (which is only conditionnally complete), we use the notions in ennreal formulated
in terms of the edistance, and coerce them to ℝ. Then their properties follow readily from the
corresponding properties in ennreal, modulo some tedious rewriting of inequalities from one to the
other -/
namespace metric
section
variables {α : Type u} {β : Type v} [metric_space α] [metric_space β] {s t u : set α} {x y : α} {Φ : α → β}
open emetric
/-- The minimal distance of a point to a set -/
def inf_dist (x : α) (s : set α) : ℝ := ennreal.to_real (inf_edist x s)
/-- the minimal distance is always nonnegative -/
lemma inf_dist_nonneg : 0 ≤ inf_dist x s := by simp [inf_dist]
/-- the minimal distance to the empty set is 0 (if you want to have the more reasonable
value ∞ instead, use `inf_edist`, which takes values in ennreal) -/
@[simp] lemma inf_dist_empty : inf_dist x ∅ = 0 :=
by simp [inf_dist]
/-- In a metric space, the minimal edistance to a nonempty set is finite -/
lemma inf_edist_ne_top (h : s.nonempty) : inf_edist x s ≠ ⊤ :=
begin
rcases h with ⟨y, hy⟩,
apply lt_top_iff_ne_top.1,
calc inf_edist x s ≤ edist x y : inf_edist_le_edist_of_mem hy
... < ⊤ : lt_top_iff_ne_top.2 (edist_ne_top _ _)
end
/-- The minimal distance of a point to a set containing it vanishes -/
lemma inf_dist_zero_of_mem (h : x ∈ s) : inf_dist x s = 0 :=
by simp [inf_edist_zero_of_mem h, inf_dist]
/-- The minimal distance to a singleton is the distance to the unique point in this singleton -/
@[simp] lemma inf_dist_singleton : inf_dist x {y} = dist x y :=
by simp [inf_dist, inf_edist, dist_edist]
/-- The minimal distance to a set is bounded by the distance to any point in this set -/
lemma inf_dist_le_dist_of_mem (h : y ∈ s) : inf_dist x s ≤ dist x y :=
begin
rw [dist_edist, inf_dist, ennreal.to_real_le_to_real (inf_edist_ne_top ⟨_, h⟩) (edist_ne_top _ _)],
exact inf_edist_le_edist_of_mem h
end
/-- The minimal distance is monotonous with respect to inclusion -/
lemma inf_dist_le_inf_dist_of_subset (h : s ⊆ t) (hs : s.nonempty) :
inf_dist x t ≤ inf_dist x s :=
begin
have ht : t.nonempty := hs.mono h,
rw [inf_dist, inf_dist, ennreal.to_real_le_to_real (inf_edist_ne_top ht) (inf_edist_ne_top hs)],
exact inf_edist_le_inf_edist_of_subset h
end
/-- If the minimal distance to a set is `<r`, there exists a point in this set at distance `<r` -/
lemma exists_dist_lt_of_inf_dist_lt {r : real} (h : inf_dist x s < r) (hs : s.nonempty) :
∃y∈s, dist x y < r :=
begin
have rpos : 0 < r := lt_of_le_of_lt inf_dist_nonneg h,
have : inf_edist x s < ennreal.of_real r,
{ rwa [inf_dist, ← ennreal.to_real_of_real (le_of_lt rpos), ennreal.to_real_lt_to_real (inf_edist_ne_top hs)] at h,
simp },
rcases exists_edist_lt_of_inf_edist_lt this with ⟨y, ys, hy⟩,
rw [edist_dist, ennreal.of_real_lt_of_real_iff rpos] at hy,
exact ⟨y, ys, hy⟩,
end
/-- The minimal distance from `x` to `s` is bounded by the distance from `y` to `s`, modulo
the distance between `x` and `y` -/
lemma inf_dist_le_inf_dist_add_dist : inf_dist x s ≤ inf_dist y s + dist x y :=
begin
cases s.eq_empty_or_nonempty with hs hs,
{ by simp [hs, dist_nonneg] },
{ rw [inf_dist, inf_dist, dist_edist, ← ennreal.to_real_add (inf_edist_ne_top hs) (edist_ne_top _ _),
ennreal.to_real_le_to_real (inf_edist_ne_top hs)],
{ apply inf_edist_le_inf_edist_add_edist },
{ simp [ennreal.add_eq_top, inf_edist_ne_top hs, edist_ne_top] }}
end
variable (s)
/-- The minimal distance to a set is Lipschitz in point with constant 1 -/
lemma lipschitz_inf_dist_pt : lipschitz_with 1 (λx, inf_dist x s) :=
lipschitz_with.of_le_add $ λ x y, inf_dist_le_inf_dist_add_dist
/-- The minimal distance to a set is uniformly continuous in point -/
lemma uniform_continuous_inf_dist_pt :
uniform_continuous (λx, inf_dist x s) :=
(lipschitz_inf_dist_pt s).uniform_continuous
/-- The minimal distance to a set is continuous in point -/
lemma continuous_inf_dist_pt : continuous (λx, inf_dist x s) :=
(uniform_continuous_inf_dist_pt s).continuous
variable {s}
/-- The minimal distance to a set and its closure coincide -/
lemma inf_dist_eq_closure : inf_dist x (closure s) = inf_dist x s :=
by simp [inf_dist, inf_edist_closure]
/-- A point belongs to the closure of `s` iff its infimum distance to this set vanishes -/
lemma mem_closure_iff_inf_dist_zero (h : s.nonempty) : x ∈ closure s ↔ inf_dist x s = 0 :=
by simp [mem_closure_iff_inf_edist_zero, inf_dist, ennreal.to_real_eq_zero_iff, inf_edist_ne_top h]
/-- Given a closed set `s`, a point belongs to `s` iff its infimum distance to this set vanishes -/
lemma mem_iff_inf_dist_zero_of_closed (h : is_closed s) (hs : s.nonempty) :
x ∈ s ↔ inf_dist x s = 0 :=
begin
have := @mem_closure_iff_inf_dist_zero _ _ s x hs,
rwa h.closure_eq at this
end
/-- The infimum distance is invariant under isometries -/
lemma inf_dist_image (hΦ : isometry Φ) :
inf_dist (Φ x) (Φ '' t) = inf_dist x t :=
by simp [inf_dist, inf_edist_image hΦ]
/-- The Hausdorff distance between two sets is the smallest nonnegative `r` such that each set is
included in the `r`-neighborhood of the other. If there is no such `r`, it is defined to
be `0`, arbitrarily -/
def Hausdorff_dist (s t : set α) : ℝ := ennreal.to_real (Hausdorff_edist s t)
/-- The Hausdorff distance is nonnegative -/
lemma Hausdorff_dist_nonneg : 0 ≤ Hausdorff_dist s t :=
by simp [Hausdorff_dist]
/-- If two sets are nonempty and bounded in a metric space, they are at finite Hausdorff edistance -/
lemma Hausdorff_edist_ne_top_of_nonempty_of_bounded (hs : s.nonempty) (ht : t.nonempty)
(bs : bounded s) (bt : bounded t) : Hausdorff_edist s t ≠ ⊤ :=
begin
rcases hs with ⟨cs, hcs⟩,
rcases ht with ⟨ct, hct⟩,
rcases (bounded_iff_subset_ball ct).1 bs with ⟨rs, hrs⟩,
rcases (bounded_iff_subset_ball cs).1 bt with ⟨rt, hrt⟩,
have : Hausdorff_edist s t ≤ ennreal.of_real (max rs rt),
{ apply Hausdorff_edist_le_of_mem_edist,
{ assume x xs,
existsi [ct, hct],
have : dist x ct ≤ max rs rt := le_trans (hrs xs) (le_max_left _ _),
rwa [edist_dist, ennreal.of_real_le_of_real_iff],
exact le_trans dist_nonneg this },
{ assume x xt,
existsi [cs, hcs],
have : dist x cs ≤ max rs rt := le_trans (hrt xt) (le_max_right _ _),
rwa [edist_dist, ennreal.of_real_le_of_real_iff],
exact le_trans dist_nonneg this }},
exact ennreal.lt_top_iff_ne_top.1 (lt_of_le_of_lt this (by simp [lt_top_iff_ne_top]))
end
/-- The Hausdorff distance between a set and itself is zero -/
@[simp] lemma Hausdorff_dist_self_zero : Hausdorff_dist s s = 0 :=
by simp [Hausdorff_dist]
/-- The Hausdorff distance from `s` to `t` and from `t` to `s` coincide -/
lemma Hausdorff_dist_comm : Hausdorff_dist s t = Hausdorff_dist t s :=
by simp [Hausdorff_dist, Hausdorff_edist_comm]
/-- The Hausdorff distance to the empty set vanishes (if you want to have the more reasonable
value ∞ instead, use `Hausdorff_edist`, which takes values in ennreal) -/
@[simp] lemma Hausdorff_dist_empty : Hausdorff_dist s ∅ = 0 :=
begin
cases s.eq_empty_or_nonempty with h h,
{ simp [h] },
{ simp [Hausdorff_dist, Hausdorff_edist_empty h] }
end
/-- The Hausdorff distance to the empty set vanishes (if you want to have the more reasonable
value ∞ instead, use `Hausdorff_edist`, which takes values in ennreal) -/
@[simp] lemma Hausdorff_dist_empty' : Hausdorff_dist ∅ s = 0 :=
by simp [Hausdorff_dist_comm]
/-- Bounding the Hausdorff distance by bounding the distance of any point
in each set to the other set -/
lemma Hausdorff_dist_le_of_inf_dist {r : ℝ} (hr : r ≥ 0)
(H1 : ∀x ∈ s, inf_dist x t ≤ r) (H2 : ∀x ∈ t, inf_dist x s ≤ r) :
Hausdorff_dist s t ≤ r :=
begin
by_cases h1 : Hausdorff_edist s t = ⊤,
by rwa [Hausdorff_dist, h1, ennreal.top_to_real],
cases s.eq_empty_or_nonempty with hs hs,
by rwa [hs, Hausdorff_dist_empty'],
cases t.eq_empty_or_nonempty with ht ht,
by rwa [ht, Hausdorff_dist_empty],
have : Hausdorff_edist s t ≤ ennreal.of_real r,
{ apply Hausdorff_edist_le_of_inf_edist _ _,
{ assume x hx,
have I := H1 x hx,
rwa [inf_dist, ← ennreal.to_real_of_real hr,
ennreal.to_real_le_to_real (inf_edist_ne_top ht) ennreal.of_real_ne_top] at I },
{ assume x hx,
have I := H2 x hx,
rwa [inf_dist, ← ennreal.to_real_of_real hr,
ennreal.to_real_le_to_real (inf_edist_ne_top hs) ennreal.of_real_ne_top] at I }},
rwa [Hausdorff_dist, ← ennreal.to_real_of_real hr,
ennreal.to_real_le_to_real h1 ennreal.of_real_ne_top]
end
/-- Bounding the Hausdorff distance by exhibiting, for any point in each set,
another point in the other set at controlled distance -/
lemma Hausdorff_dist_le_of_mem_dist {r : ℝ} (hr : 0 ≤ r)
(H1 : ∀x ∈ s, ∃y ∈ t, dist x y ≤ r) (H2 : ∀x ∈ t, ∃y ∈ s, dist x y ≤ r) :
Hausdorff_dist s t ≤ r :=
begin
apply Hausdorff_dist_le_of_inf_dist hr,
{ assume x xs,
rcases H1 x xs with ⟨y, yt, hy⟩,
exact le_trans (inf_dist_le_dist_of_mem yt) hy },
{ assume x xt,
rcases H2 x xt with ⟨y, ys, hy⟩,
exact le_trans (inf_dist_le_dist_of_mem ys) hy }
end
/-- The Hausdorff distance is controlled by the diameter of the union -/
lemma Hausdorff_dist_le_diam (hs : s.nonempty) (bs : bounded s) (ht : t.nonempty) (bt : bounded t) :
Hausdorff_dist s t ≤ diam (s ∪ t) :=
begin
rcases hs with ⟨x, xs⟩,
rcases ht with ⟨y, yt⟩,
refine Hausdorff_dist_le_of_mem_dist diam_nonneg _ _,
{ exact λz hz, ⟨y, yt, dist_le_diam_of_mem (bounded_union.2 ⟨bs, bt⟩)
(subset_union_left _ _ hz) (subset_union_right _ _ yt)⟩ },
{ exact λz hz, ⟨x, xs, dist_le_diam_of_mem (bounded_union.2 ⟨bs, bt⟩)
(subset_union_right _ _ hz) (subset_union_left _ _ xs)⟩ }
end
/-- The distance to a set is controlled by the Hausdorff distance -/
lemma inf_dist_le_Hausdorff_dist_of_mem (hx : x ∈ s) (fin : Hausdorff_edist s t ≠ ⊤) :
inf_dist x t ≤ Hausdorff_dist s t :=
begin
have ht : t.nonempty := nonempty_of_Hausdorff_edist_ne_top ⟨x, hx⟩ fin,
rw [Hausdorff_dist, inf_dist, ennreal.to_real_le_to_real (inf_edist_ne_top ht) fin],
exact inf_edist_le_Hausdorff_edist_of_mem hx
end
/-- If the Hausdorff distance is `<r`, then any point in one of the sets is at distance
`<r` of a point in the other set -/
lemma exists_dist_lt_of_Hausdorff_dist_lt {r : ℝ} (h : x ∈ s) (H : Hausdorff_dist s t < r)
(fin : Hausdorff_edist s t ≠ ⊤) : ∃y∈t, dist x y < r :=
begin
have r0 : 0 < r := lt_of_le_of_lt (Hausdorff_dist_nonneg) H,
have : Hausdorff_edist s t < ennreal.of_real r,
by rwa [Hausdorff_dist, ← ennreal.to_real_of_real (le_of_lt r0),
ennreal.to_real_lt_to_real fin (ennreal.of_real_ne_top)] at H,
rcases exists_edist_lt_of_Hausdorff_edist_lt h this with ⟨y, hy, yr⟩,
rw [edist_dist, ennreal.of_real_lt_of_real_iff r0] at yr,
exact ⟨y, hy, yr⟩
end
/-- If the Hausdorff distance is `<r`, then any point in one of the sets is at distance
`<r` of a point in the other set -/
lemma exists_dist_lt_of_Hausdorff_dist_lt' {r : ℝ} (h : y ∈ t) (H : Hausdorff_dist s t < r)
(fin : Hausdorff_edist s t ≠ ⊤) : ∃x∈s, dist x y < r :=
begin
rw Hausdorff_dist_comm at H,
rw Hausdorff_edist_comm at fin,
simpa [dist_comm] using exists_dist_lt_of_Hausdorff_dist_lt h H fin
end
/-- The infimum distance to `s` and `t` are the same, up to the Hausdorff distance
between `s` and `t` -/
lemma inf_dist_le_inf_dist_add_Hausdorff_dist (fin : Hausdorff_edist s t ≠ ⊤) :
inf_dist x t ≤ inf_dist x s + Hausdorff_dist s t :=
begin
rcases empty_or_nonempty_of_Hausdorff_edist_ne_top fin with ⟨hs,ht⟩|⟨hs,ht⟩,
{ simp only [hs, ht, Hausdorff_dist_empty, inf_dist_empty, zero_add] },
rw [inf_dist, inf_dist, Hausdorff_dist, ← ennreal.to_real_add (inf_edist_ne_top hs) fin,
ennreal.to_real_le_to_real (inf_edist_ne_top ht)],
{ exact inf_edist_le_inf_edist_add_Hausdorff_edist },
{ exact ennreal.add_ne_top.2 ⟨inf_edist_ne_top hs, fin⟩ }
end
/-- The Hausdorff distance is invariant under isometries -/
lemma Hausdorff_dist_image (h : isometry Φ) :
Hausdorff_dist (Φ '' s) (Φ '' t) = Hausdorff_dist s t :=
by simp [Hausdorff_dist, Hausdorff_edist_image h]
/-- The Hausdorff distance satisfies the triangular inequality -/
lemma Hausdorff_dist_triangle (fin : Hausdorff_edist s t ≠ ⊤) :
Hausdorff_dist s u ≤ Hausdorff_dist s t + Hausdorff_dist t u :=
begin
by_cases Hausdorff_edist s u = ⊤,
{ calc Hausdorff_dist s u = 0 + 0 : by simp [Hausdorff_dist, h]
... ≤ Hausdorff_dist s t + Hausdorff_dist t u :
add_le_add (Hausdorff_dist_nonneg) (Hausdorff_dist_nonneg) },
{ have Dtu : Hausdorff_edist t u < ⊤ := calc
Hausdorff_edist t u ≤ Hausdorff_edist t s + Hausdorff_edist s u : Hausdorff_edist_triangle
... = Hausdorff_edist s t + Hausdorff_edist s u : by simp [Hausdorff_edist_comm]
... < ⊤ : by simp [ennreal.add_lt_top]; simp [ennreal.lt_top_iff_ne_top, h, fin],
rw [Hausdorff_dist, Hausdorff_dist, Hausdorff_dist,
← ennreal.to_real_add fin (lt_top_iff_ne_top.1 Dtu), ennreal.to_real_le_to_real h],
{ exact Hausdorff_edist_triangle },
{ simp [ennreal.add_eq_top, lt_top_iff_ne_top.1 Dtu, fin] }}
end
/-- The Hausdorff distance satisfies the triangular inequality -/
lemma Hausdorff_dist_triangle' (fin : Hausdorff_edist t u ≠ ⊤) :
Hausdorff_dist s u ≤ Hausdorff_dist s t + Hausdorff_dist t u :=
begin
rw Hausdorff_edist_comm at fin,
have I : Hausdorff_dist u s ≤ Hausdorff_dist u t + Hausdorff_dist t s := Hausdorff_dist_triangle fin,
simpa [add_comm, Hausdorff_dist_comm] using I
end
/-- The Hausdorff distance between a set and its closure vanish -/
@[simp, priority 1100]
lemma Hausdorff_dist_self_closure : Hausdorff_dist s (closure s) = 0 :=
by simp [Hausdorff_dist]
/-- Replacing a set by its closure does not change the Hausdorff distance. -/
@[simp] lemma Hausdorff_dist_closure₁ : Hausdorff_dist (closure s) t = Hausdorff_dist s t :=
by simp [Hausdorff_dist]
/-- Replacing a set by its closure does not change the Hausdorff distance. -/
@[simp] lemma Hausdorff_dist_closure₂ : Hausdorff_dist s (closure t) = Hausdorff_dist s t :=
by simp [Hausdorff_dist]
/-- The Hausdorff distance between two sets and their closures coincide -/
@[simp] lemma Hausdorff_dist_closure : Hausdorff_dist (closure s) (closure t) = Hausdorff_dist s t :=
by simp [Hausdorff_dist]
/-- Two sets are at zero Hausdorff distance if and only if they have the same closures -/
lemma Hausdorff_dist_zero_iff_closure_eq_closure (fin : Hausdorff_edist s t ≠ ⊤) :
Hausdorff_dist s t = 0 ↔ closure s = closure t :=
by simp [Hausdorff_edist_zero_iff_closure_eq_closure.symm, Hausdorff_dist,
ennreal.to_real_eq_zero_iff, fin]
/-- Two closed sets are at zero Hausdorff distance if and only if they coincide -/
lemma Hausdorff_dist_zero_iff_eq_of_closed (hs : is_closed s) (ht : is_closed t)
(fin : Hausdorff_edist s t ≠ ⊤) : Hausdorff_dist s t = 0 ↔ s = t :=
by simp [(Hausdorff_edist_zero_iff_eq_of_closed hs ht).symm, Hausdorff_dist,
ennreal.to_real_eq_zero_iff, fin]
end --section
end metric --namespace
|
e7a6d4b296178537ac8acbd0bb79fd3b6e70ac02 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/data/prod.lean | e9ea601783978d93c389b1f46e7ac8a25cadd76a | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 6,125 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import tactic.basic
/-!
# Extra facts about `prod`
This file defines `prod.swap : α × β → β × α` and proves various simple lemmas about `prod`.
-/
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
@[simp] lemma prod_map (f : α → γ) (g : β → δ) (p : α × β) : prod.map f g p = (f p.1, g p.2) := rfl
namespace prod
@[simp] theorem «forall» {p : α × β → Prop} : (∀ x, p x) ↔ (∀ a b, p (a, b)) :=
⟨assume h a b, h (a, b), assume h ⟨a, b⟩, h a b⟩
@[simp] theorem «exists» {p : α × β → Prop} : (∃ x, p x) ↔ (∃ a b, p (a, b)) :=
⟨assume ⟨⟨a, b⟩, h⟩, ⟨a, b, h⟩, assume ⟨a, b, h⟩, ⟨⟨a, b⟩, h⟩⟩
theorem forall' {p : α → β → Prop} : (∀ x : α × β, p x.1 x.2) ↔ ∀ a b, p a b :=
prod.forall
theorem exists' {p : α → β → Prop} : (∃ x : α × β, p x.1 x.2) ↔ ∃ a b, p a b :=
prod.exists
@[simp] lemma map_mk (f : α → γ) (g : β → δ) (a : α) (b : β) : map f g (a, b) = (f a, g b) := rfl
lemma map_fst (f : α → γ) (g : β → δ) (p : α × β) : (map f g p).1 = f (p.1) := rfl
lemma map_snd (f : α → γ) (g : β → δ) (p : α × β) : (map f g p).2 = g (p.2) := rfl
lemma map_fst' (f : α → γ) (g : β → δ) : (prod.fst ∘ map f g) = f ∘ prod.fst :=
funext $ map_fst f g
lemma map_snd' (f : α → γ) (g : β → δ) : (prod.snd ∘ map f g) = g ∘ prod.snd :=
funext $ map_snd f g
/--
Composing a `prod.map` with another `prod.map` is equal to
a single `prod.map` of composed functions.
-/
lemma map_comp_map {ε ζ : Type*}
(f : α → β) (f' : γ → δ) (g : β → ε) (g' : δ → ζ) :
prod.map g g' ∘ prod.map f f' = prod.map (g ∘ f) (g' ∘ f') :=
rfl
/--
Composing a `prod.map` with another `prod.map` is equal to
a single `prod.map` of composed functions, fully applied.
-/
lemma map_map {ε ζ : Type*}
(f : α → β) (f' : γ → δ) (g : β → ε) (g' : δ → ζ) (x : α × γ) :
prod.map g g' (prod.map f f' x) = prod.map (g ∘ f) (g' ∘ f') x :=
rfl
@[simp] theorem mk.inj_iff {a₁ a₂ : α} {b₁ b₂ : β} : (a₁, b₁) = (a₂, b₂) ↔ (a₁ = a₂ ∧ b₁ = b₂) :=
⟨prod.mk.inj, by cc⟩
lemma mk.inj_left {α β : Type*} (a : α) :
function.injective (prod.mk a : β → α × β) :=
by { intros b₁ b₂ h, simpa only [true_and, prod.mk.inj_iff, eq_self_iff_true] using h }
lemma mk.inj_right {α β : Type*} (b : β) :
function.injective (λ a, prod.mk a b : α → α × β) :=
by { intros b₁ b₂ h, by simpa only [and_true, eq_self_iff_true, mk.inj_iff] using h }
lemma ext_iff {p q : α × β} : p = q ↔ p.1 = q.1 ∧ p.2 = q.2 :=
by rw [← @mk.eta _ _ p, ← @mk.eta _ _ q, mk.inj_iff]
@[ext]
lemma ext {α β} {p q : α × β} (h₁ : p.1 = q.1) (h₂ : p.2 = q.2) : p = q :=
ext_iff.2 ⟨h₁, h₂⟩
lemma map_def {f : α → γ} {g : β → δ} : prod.map f g = λ (p : α × β), (f p.1, g p.2) :=
funext (λ p, ext (map_fst f g p) (map_snd f g p))
lemma id_prod : (λ (p : α × α), (p.1, p.2)) = id :=
funext $ λ ⟨a, b⟩, rfl
lemma fst_surjective [h : nonempty β] : function.surjective (@fst α β) :=
λ x, h.elim $ λ y, ⟨⟨x, y⟩, rfl⟩
lemma snd_surjective [h : nonempty α] : function.surjective (@snd α β) :=
λ y, h.elim $ λ x, ⟨⟨x, y⟩, rfl⟩
lemma fst_injective [subsingleton β] : function.injective (@fst α β) :=
λ x y h, ext h (subsingleton.elim _ _)
lemma snd_injective [subsingleton α] : function.injective (@snd α β) :=
λ x y h, ext (subsingleton.elim _ _) h
/-- Swap the factors of a product. `swap (a, b) = (b, a)` -/
def swap : α × β → β × α := λp, (p.2, p.1)
@[simp] lemma swap_swap : ∀ x : α × β, swap (swap x) = x
| ⟨a, b⟩ := rfl
@[simp] lemma fst_swap {p : α × β} : (swap p).1 = p.2 := rfl
@[simp] lemma snd_swap {p : α × β} : (swap p).2 = p.1 := rfl
@[simp] lemma swap_prod_mk {a : α} {b : β} : swap (a, b) = (b, a) := rfl
@[simp] lemma swap_swap_eq : swap ∘ swap = @id (α × β) :=
funext swap_swap
@[simp] lemma swap_left_inverse : function.left_inverse (@swap α β) swap :=
swap_swap
@[simp] lemma swap_right_inverse : function.right_inverse (@swap α β) swap :=
swap_swap
lemma swap_injective : function.injective (@swap α β) :=
swap_left_inverse.injective
lemma swap_surjective : function.surjective (@swap α β) :=
swap_left_inverse.surjective
lemma swap_bijective : function.bijective (@swap α β) :=
⟨swap_injective, swap_surjective⟩
@[simp] lemma swap_inj {p q : α × β} : swap p = swap q ↔ p = q := swap_injective.eq_iff
lemma eq_iff_fst_eq_snd_eq : ∀{p q : α × β}, p = q ↔ (p.1 = q.1 ∧ p.2 = q.2)
| ⟨p₁, p₂⟩ ⟨q₁, q₂⟩ := by simp
lemma fst_eq_iff : ∀ {p : α × β} {x : α}, p.1 = x ↔ p = (x, p.2)
| ⟨a, b⟩ x := by simp
lemma snd_eq_iff : ∀ {p : α × β} {x : β}, p.2 = x ↔ p = (p.1, x)
| ⟨a, b⟩ x := by simp
theorem lex_def (r : α → α → Prop) (s : β → β → Prop)
{p q : α × β} : prod.lex r s p q ↔ r p.1 q.1 ∨ p.1 = q.1 ∧ s p.2 q.2 :=
⟨λ h, by cases h; simp *,
λ h, match p, q, h with
| (a, b), (c, d), or.inl h := lex.left _ _ h
| (a, b), (c, d), or.inr ⟨e, h⟩ :=
by change a = c at e; subst e; exact lex.right _ h
end⟩
instance lex.decidable [decidable_eq α]
(r : α → α → Prop) (s : β → β → Prop) [decidable_rel r] [decidable_rel s] :
decidable_rel (prod.lex r s) :=
λ p q, decidable_of_decidable_of_iff (by apply_instance) (lex_def r s).symm
end prod
open function
lemma function.injective.prod_map {f : α → γ} {g : β → δ} (hf : injective f) (hg : injective g) :
injective (prod.map f g) :=
λ x y h, prod.ext (hf (prod.ext_iff.1 h).1) (hg $ (prod.ext_iff.1 h).2)
lemma function.surjective.prod_map {f : α → γ} {g : β → δ} (hf : surjective f) (hg : surjective g) :
surjective (prod.map f g) :=
λ p, let ⟨x, hx⟩ := hf p.1 in let ⟨y, hy⟩ := hg p.2 in ⟨(x, y), prod.ext hx hy⟩
|
a57909ebc3366949ce9abd1c884b05e96e53987f | 36c7a18fd72e5b57229bd8ba36493daf536a19ce | /tests/lean/run/blast_cc10.lean | a11b6267082a4ce5b1e6c8ae696ca84c6d5bfe7e | [
"Apache-2.0"
] | permissive | YHVHvx/lean | 732bf0fb7a298cd7fe0f15d82f8e248c11db49e9 | 038369533e0136dd395dc252084d3c1853accbf2 | refs/heads/master | 1,610,701,080,210 | 1,449,128,595,000 | 1,449,128,595,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 127 | lean | set_option blast.subst false
set_option blast.simp false
definition t1 (a b : nat) : (a = b ↔ a = b) :=
by blast
print t1
|
5ac9e426b2df39128d812176b53d0a42b1056955 | ce89339993655da64b6ccb555c837ce6c10f9ef4 | /bluejam/chap7/exercise7.2.lean | a7ff749f5462d279472d6dbf98e0c08f8f3e2740 | [] | no_license | zeptometer/LearnLean | ef32dc36a22119f18d843f548d0bb42f907bff5d | bb84d5dbe521127ba134d4dbf9559b294a80b9f7 | refs/heads/master | 1,625,710,824,322 | 1,601,382,570,000 | 1,601,382,570,000 | 195,228,870 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,320 | lean | namespace hidden
universes u v
inductive list (α : Type u)
| nil {} : list
| cons : α → list → list
namespace list
variable {α : Type}
notation h :: t := cons h t
def append (s t : list α) : list α :=
list.rec t (λ x l u, x::u) s
notation s ++ t := append s t
theorem nil_append (t : list α) : nil ++ t = t := rfl
theorem cons_append (x : α) (s t : list α) :
x :: s ++ t = x :: (s ++ t) := rfl
notation `[` l:(foldr `,` (h t, cons h t) nil) `]` := l
section
open nat
#check [1, 2, 3, 4, 5]
#check ([1,2,3,4,5] : list int)
end
-- exercise
theorem append_nil (t : list α) : t ++ nil = t :=
list.rec_on t
(show (@nil α) ++ nil = nil, from rfl)
(
assume h,
assume l,
assume ih: l ++ nil = l,
calc (h :: l) ++ nil = h :: (l ++ nil) : cons_append h l nil
... = h :: l : by rw ih
)
theorem append_assoc (r s t : list α) : (r ++ s) ++ t = r ++ (s ++ t) :=
list.rec_on r
(
calc (nil ++ s) ++ t = s ++ t : by rw nil_append
... = nil ++ (s ++ t) : by rw nil_append
)
(
assume h,
assume l,
assume ih: (l ++ s) ++ t = l ++ (s ++ t),
calc (h :: l) ++ s ++ t = h :: (l ++ s) ++ t : by rw cons_append
... = h :: (l ++ s ++ t) : by rw cons_append
... = h :: (l ++ (s ++ t)) : by rw ih
... = (h :: l) ++ (s ++ t) : by rw cons_append
)
def length : Π {α : Type u}, list α → ℕ :=
λ t l, list.rec_on l 0 (λ h x n, n + 1)
theorem append_length (s t : list α) : length (s ++ t) = length s + length t :=
list.rec_on s
(
show length (nil ++ t) = length nil + length t, from
calc length (nil ++ t) = length t : by rw nil_append
... = 0 + length t : by rw zero_add
... = length nil + length t : rfl
)
(
assume h,
assume l,
assume ih: length (l ++ t) = length l + length t,
show length (h :: l ++ t) = length (h :: l) + length t, from
calc length ((h :: l) ++ t) = length (h :: (l ++ t)) : by rw cons_append
... = length (l ++ t) + 1 : rfl
... = length l + length t + 1 : by rw ih
... = length l + 1 + length t : by simp
... = length (h :: l) + length t : by rw length
)
def reverse (s : list α) : list α :=
list.rec_on s nil (λ h l t, t ++ [h])
example (h : α) (s : list α) : reverse (h :: s) = (reverse s) ++ [h] :=
rfl
example (t: list α) : length (reverse t) = length t :=
list.rec_on t
(show length (reverse nil) = length nil, from rfl)
(
assume h,
assume l : list α,
assume ih : length (reverse l) = length l,
show length (reverse (h :: l)) = length (h :: l), from
calc length (reverse (h :: l))
= length (reverse l ++ [h]) : rfl
... = length (reverse l) + length [h] : by rw append_length
... = length l + length [h] : by rw ih
)
theorem reverse_append (s t : list α) : reverse (s ++ t) = reverse t ++ reverse s :=
list.rec_on s
(
show reverse (nil ++ t) = reverse t ++ reverse nil, from
calc reverse (nil ++ t) = reverse t : by rw nil_append
... = reverse t ++ nil : by rw append_nil
... = reverse t ++ reverse nil : rfl
)
(
assume h,
assume l,
assume ih : reverse (l ++ t) = reverse t ++ reverse l,
show reverse ((h :: l) ++ t) = reverse t ++ reverse (h :: l), from
calc reverse ((h :: l) ++ t)
= reverse (h :: (l ++ t)) : by rw cons_append
... = reverse (l ++ t) ++ [h] : rfl
... = reverse t ++ reverse l ++ [h] : by rw ih
... = reverse t ++ (reverse l ++ [h]) : by rw append_assoc
... = reverse t ++ reverse (h :: l) : rfl
)
example (t : list α) : reverse (reverse t) = t :=
list.rec_on t
(show reverse (reverse nil) = nil, from rfl)
(
assume h,
assume l : list α,
assume ih : reverse (reverse l) = l,
show reverse (reverse (h :: l)) = h :: l, from
calc reverse (reverse (h :: l))
= reverse (reverse l ++ [h]) : rfl
... = reverse [h] ++ reverse (reverse l) : by rw reverse_append
... = [h] ++ reverse (reverse l) : rfl
... = [h] ++ l : by rw ih
... = h :: l : by rw [append]
)
end list
end hidden
|
5508f2cc704c747479a123df6ba3529238622c52 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/algebraic_geometry/prime_spectrum/basic.lean | 5e0b3631d604e361b174854234a1dd0e2af416ce | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 33,239 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import algebra.punit_instances
import linear_algebra.finsupp
import ring_theory.nilpotent
import ring_theory.localization.away
import ring_theory.ideal.prod
import ring_theory.ideal.over
import topology.sets.opens
import topology.sober
/-!
# Prime spectrum of a commutative ring
The prime spectrum of a commutative ring is the type of all prime ideals.
It is naturally endowed with a topology: the Zariski topology.
(It is also naturally endowed with a sheaf of rings,
which is constructed in `algebraic_geometry.structure_sheaf`.)
## Main definitions
* `prime_spectrum R`: The prime spectrum of a commutative ring `R`,
i.e., the set of all prime ideals of `R`.
* `zero_locus s`: The zero locus of a subset `s` of `R`
is the subset of `prime_spectrum R` consisting of all prime ideals that contain `s`.
* `vanishing_ideal t`: The vanishing ideal of a subset `t` of `prime_spectrum R`
is the intersection of points in `t` (viewed as prime ideals).
## Conventions
We denote subsets of rings with `s`, `s'`, etc...
whereas we denote subsets of prime spectra with `t`, `t'`, etc...
## Inspiration/contributors
The contents of this file draw inspiration from
<https://github.com/ramonfmir/lean-scheme>
which has contributions from Ramon Fernandez Mir, Kevin Buzzard, Kenny Lau,
and Chris Hughes (on an earlier repository).
-/
noncomputable theory
open_locale classical
universes u v
variables (R : Type u) [comm_ring R]
/-- The prime spectrum of a commutative ring `R`
is the type of all prime ideals of `R`.
It is naturally endowed with a topology (the Zariski topology),
and a sheaf of commutative rings (see `algebraic_geometry.structure_sheaf`).
It is a fundamental building block in algebraic geometry. -/
@[nolint has_nonempty_instance]
def prime_spectrum := {I : ideal R // I.is_prime}
variable {R}
namespace prime_spectrum
/-- A method to view a point in the prime spectrum of a commutative ring
as an ideal of that ring. -/
abbreviation as_ideal (x : prime_spectrum R) : ideal R := x.val
instance is_prime (x : prime_spectrum R) :
x.as_ideal.is_prime := x.2
/--
The prime spectrum of the zero ring is empty.
-/
lemma punit (x : prime_spectrum punit) : false :=
x.1.ne_top_iff_one.1 x.2.1 $ subsingleton.elim (0 : punit) 1 ▸ x.1.zero_mem
section
variables (R) (S : Type v) [comm_ring S]
/-- The prime spectrum of `R × S` is in bijection with the disjoint unions of the prime spectrum of
`R` and the prime spectrum of `S`. -/
noncomputable def prime_spectrum_prod :
prime_spectrum (R × S) ≃ prime_spectrum R ⊕ prime_spectrum S :=
ideal.prime_ideals_equiv R S
variables {R S}
@[simp] lemma prime_spectrum_prod_symm_inl_as_ideal (x : prime_spectrum R) :
((prime_spectrum_prod R S).symm (sum.inl x)).as_ideal = ideal.prod x.as_ideal ⊤ :=
by { cases x, refl }
@[simp] lemma prime_spectrum_prod_symm_inr_as_ideal (x : prime_spectrum S) :
((prime_spectrum_prod R S).symm (sum.inr x)).as_ideal = ideal.prod ⊤ x.as_ideal :=
by { cases x, refl }
end
@[ext] lemma ext {x y : prime_spectrum R} :
x = y ↔ x.as_ideal = y.as_ideal :=
subtype.ext_iff_val
/-- The zero locus of a set `s` of elements of a commutative ring `R`
is the set of all prime ideals of the ring that contain the set `s`.
An element `f` of `R` can be thought of as a dependent function
on the prime spectrum of `R`.
At a point `x` (a prime ideal)
the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`.
In this manner, `zero_locus s` is exactly the subset of `prime_spectrum R`
where all "functions" in `s` vanish simultaneously.
-/
def zero_locus (s : set R) : set (prime_spectrum R) :=
{x | s ⊆ x.as_ideal}
@[simp] lemma mem_zero_locus (x : prime_spectrum R) (s : set R) :
x ∈ zero_locus s ↔ s ⊆ x.as_ideal := iff.rfl
@[simp] lemma zero_locus_span (s : set R) :
zero_locus (ideal.span s : set R) = zero_locus s :=
by { ext x, exact (submodule.gi R R).gc s x.as_ideal }
/-- The vanishing ideal of a set `t` of points
of the prime spectrum of a commutative ring `R`
is the intersection of all the prime ideals in the set `t`.
An element `f` of `R` can be thought of as a dependent function
on the prime spectrum of `R`.
At a point `x` (a prime ideal)
the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`.
In this manner, `vanishing_ideal t` is exactly the ideal of `R`
consisting of all "functions" that vanish on all of `t`.
-/
def vanishing_ideal (t : set (prime_spectrum R)) : ideal R :=
⨅ (x : prime_spectrum R) (h : x ∈ t), x.as_ideal
lemma coe_vanishing_ideal (t : set (prime_spectrum R)) :
(vanishing_ideal t : set R) = {f : R | ∀ x : prime_spectrum R, x ∈ t → f ∈ x.as_ideal} :=
begin
ext f,
rw [vanishing_ideal, set_like.mem_coe, submodule.mem_infi],
apply forall_congr, intro x,
rw [submodule.mem_infi],
end
lemma mem_vanishing_ideal (t : set (prime_spectrum R)) (f : R) :
f ∈ vanishing_ideal t ↔ ∀ x : prime_spectrum R, x ∈ t → f ∈ x.as_ideal :=
by rw [← set_like.mem_coe, coe_vanishing_ideal, set.mem_set_of_eq]
@[simp] lemma vanishing_ideal_singleton (x : prime_spectrum R) :
vanishing_ideal ({x} : set (prime_spectrum R)) = x.as_ideal :=
by simp [vanishing_ideal]
lemma subset_zero_locus_iff_le_vanishing_ideal (t : set (prime_spectrum R)) (I : ideal R) :
t ⊆ zero_locus I ↔ I ≤ vanishing_ideal t :=
⟨λ h f k, (mem_vanishing_ideal _ _).mpr (λ x j, (mem_zero_locus _ _).mpr (h j) k), λ h,
λ x j, (mem_zero_locus _ _).mpr (le_trans h (λ f h, ((mem_vanishing_ideal _ _).mp h) x j))⟩
section gc
variable (R)
/-- `zero_locus` and `vanishing_ideal` form a galois connection. -/
lemma gc : @galois_connection (ideal R) (set (prime_spectrum R))ᵒᵈ _ _
(λ I, zero_locus I) (λ t, vanishing_ideal t) :=
λ I t, subset_zero_locus_iff_le_vanishing_ideal t I
/-- `zero_locus` and `vanishing_ideal` form a galois connection. -/
lemma gc_set : @galois_connection (set R) (set (prime_spectrum R))ᵒᵈ _ _
(λ s, zero_locus s) (λ t, vanishing_ideal t) :=
have ideal_gc : galois_connection (ideal.span) coe := (submodule.gi R R).gc,
by simpa [zero_locus_span, function.comp] using ideal_gc.compose (gc R)
lemma subset_zero_locus_iff_subset_vanishing_ideal (t : set (prime_spectrum R)) (s : set R) :
t ⊆ zero_locus s ↔ s ⊆ vanishing_ideal t :=
(gc_set R) s t
end gc
lemma subset_vanishing_ideal_zero_locus (s : set R) :
s ⊆ vanishing_ideal (zero_locus s) :=
(gc_set R).le_u_l s
lemma le_vanishing_ideal_zero_locus (I : ideal R) :
I ≤ vanishing_ideal (zero_locus I) :=
(gc R).le_u_l I
@[simp] lemma vanishing_ideal_zero_locus_eq_radical (I : ideal R) :
vanishing_ideal (zero_locus (I : set R)) = I.radical := ideal.ext $ λ f,
begin
rw [mem_vanishing_ideal, ideal.radical_eq_Inf, submodule.mem_Inf],
exact ⟨(λ h x hx, h ⟨x, hx.2⟩ hx.1), (λ h x hx, h x.1 ⟨hx, x.2⟩)⟩
end
@[simp] lemma zero_locus_radical (I : ideal R) : zero_locus (I.radical : set R) = zero_locus I :=
vanishing_ideal_zero_locus_eq_radical I ▸ (gc R).l_u_l_eq_l I
lemma subset_zero_locus_vanishing_ideal (t : set (prime_spectrum R)) :
t ⊆ zero_locus (vanishing_ideal t) :=
(gc R).l_u_le t
lemma zero_locus_anti_mono {s t : set R} (h : s ⊆ t) : zero_locus t ⊆ zero_locus s :=
(gc_set R).monotone_l h
lemma zero_locus_anti_mono_ideal {s t : ideal R} (h : s ≤ t) :
zero_locus (t : set R) ⊆ zero_locus (s : set R) :=
(gc R).monotone_l h
lemma vanishing_ideal_anti_mono {s t : set (prime_spectrum R)} (h : s ⊆ t) :
vanishing_ideal t ≤ vanishing_ideal s :=
(gc R).monotone_u h
lemma zero_locus_subset_zero_locus_iff (I J : ideal R) :
zero_locus (I : set R) ⊆ zero_locus (J : set R) ↔ J ≤ I.radical :=
⟨λ h, ideal.radical_le_radical_iff.mp (vanishing_ideal_zero_locus_eq_radical I ▸
vanishing_ideal_zero_locus_eq_radical J ▸ vanishing_ideal_anti_mono h),
λ h, zero_locus_radical I ▸ zero_locus_anti_mono_ideal h⟩
lemma zero_locus_subset_zero_locus_singleton_iff (f g : R) :
zero_locus ({f} : set R) ⊆ zero_locus {g} ↔ g ∈ (ideal.span ({f} : set R)).radical :=
by rw [← zero_locus_span {f}, ← zero_locus_span {g}, zero_locus_subset_zero_locus_iff,
ideal.span_le, set.singleton_subset_iff, set_like.mem_coe]
lemma zero_locus_bot :
zero_locus ((⊥ : ideal R) : set R) = set.univ :=
(gc R).l_bot
@[simp] lemma zero_locus_singleton_zero :
zero_locus ({0} : set R) = set.univ :=
zero_locus_bot
@[simp] lemma zero_locus_empty :
zero_locus (∅ : set R) = set.univ :=
(gc_set R).l_bot
@[simp] lemma vanishing_ideal_univ :
vanishing_ideal (∅ : set (prime_spectrum R)) = ⊤ :=
by simpa using (gc R).u_top
lemma zero_locus_empty_of_one_mem {s : set R} (h : (1:R) ∈ s) :
zero_locus s = ∅ :=
begin
rw set.eq_empty_iff_forall_not_mem,
intros x hx,
rw mem_zero_locus at hx,
have x_prime : x.as_ideal.is_prime := by apply_instance,
have eq_top : x.as_ideal = ⊤, { rw ideal.eq_top_iff_one, exact hx h },
apply x_prime.ne_top eq_top,
end
@[simp] lemma zero_locus_singleton_one :
zero_locus ({1} : set R) = ∅ :=
zero_locus_empty_of_one_mem (set.mem_singleton (1 : R))
lemma zero_locus_empty_iff_eq_top {I : ideal R} :
zero_locus (I : set R) = ∅ ↔ I = ⊤ :=
begin
split,
{ contrapose!,
intro h,
apply set.ne_empty_iff_nonempty.mpr,
rcases ideal.exists_le_maximal I h with ⟨M, hM, hIM⟩,
exact ⟨⟨M, hM.is_prime⟩, hIM⟩ },
{ rintro rfl, apply zero_locus_empty_of_one_mem, trivial }
end
@[simp] lemma zero_locus_univ :
zero_locus (set.univ : set R) = ∅ :=
zero_locus_empty_of_one_mem (set.mem_univ 1)
lemma zero_locus_sup (I J : ideal R) :
zero_locus ((I ⊔ J : ideal R) : set R) = zero_locus I ∩ zero_locus J :=
(gc R).l_sup
lemma zero_locus_union (s s' : set R) :
zero_locus (s ∪ s') = zero_locus s ∩ zero_locus s' :=
(gc_set R).l_sup
lemma vanishing_ideal_union (t t' : set (prime_spectrum R)) :
vanishing_ideal (t ∪ t') = vanishing_ideal t ⊓ vanishing_ideal t' :=
(gc R).u_inf
lemma zero_locus_supr {ι : Sort*} (I : ι → ideal R) :
zero_locus ((⨆ i, I i : ideal R) : set R) = (⋂ i, zero_locus (I i)) :=
(gc R).l_supr
lemma zero_locus_Union {ι : Sort*} (s : ι → set R) :
zero_locus (⋃ i, s i) = (⋂ i, zero_locus (s i)) :=
(gc_set R).l_supr
lemma zero_locus_bUnion (s : set (set R)) :
zero_locus (⋃ s' ∈ s, s' : set R) = ⋂ s' ∈ s, zero_locus s' :=
by simp only [zero_locus_Union]
lemma vanishing_ideal_Union {ι : Sort*} (t : ι → set (prime_spectrum R)) :
vanishing_ideal (⋃ i, t i) = (⨅ i, vanishing_ideal (t i)) :=
(gc R).u_infi
lemma zero_locus_inf (I J : ideal R) :
zero_locus ((I ⊓ J : ideal R) : set R) = zero_locus I ∪ zero_locus J :=
set.ext $ λ x, x.2.inf_le
lemma union_zero_locus (s s' : set R) :
zero_locus s ∪ zero_locus s' = zero_locus ((ideal.span s) ⊓ (ideal.span s') : ideal R) :=
by { rw zero_locus_inf, simp }
lemma zero_locus_mul (I J : ideal R) :
zero_locus ((I * J : ideal R) : set R) = zero_locus I ∪ zero_locus J :=
set.ext $ λ x, x.2.mul_le
lemma zero_locus_singleton_mul (f g : R) :
zero_locus ({f * g} : set R) = zero_locus {f} ∪ zero_locus {g} :=
set.ext $ λ x, by simpa using x.2.mul_mem_iff_mem_or_mem
@[simp] lemma zero_locus_pow (I : ideal R) {n : ℕ} (hn : 0 < n) :
zero_locus ((I ^ n : ideal R) : set R) = zero_locus I :=
zero_locus_radical (I ^ n) ▸ (I.radical_pow n hn).symm ▸ zero_locus_radical I
@[simp] lemma zero_locus_singleton_pow (f : R) (n : ℕ) (hn : 0 < n) :
zero_locus ({f ^ n} : set R) = zero_locus {f} :=
set.ext $ λ x, by simpa using x.2.pow_mem_iff_mem n hn
lemma sup_vanishing_ideal_le (t t' : set (prime_spectrum R)) :
vanishing_ideal t ⊔ vanishing_ideal t' ≤ vanishing_ideal (t ∩ t') :=
begin
intros r,
rw [submodule.mem_sup, mem_vanishing_ideal],
rintro ⟨f, hf, g, hg, rfl⟩ x ⟨hxt, hxt'⟩,
rw mem_vanishing_ideal at hf hg,
apply submodule.add_mem; solve_by_elim
end
lemma mem_compl_zero_locus_iff_not_mem {f : R} {I : prime_spectrum R} :
I ∈ (zero_locus {f} : set (prime_spectrum R))ᶜ ↔ f ∉ I.as_ideal :=
by rw [set.mem_compl_eq, mem_zero_locus, set.singleton_subset_iff]; refl
/-- The Zariski topology on the prime spectrum of a commutative ring
is defined via the closed sets of the topology:
they are exactly those sets that are the zero locus of a subset of the ring. -/
instance zariski_topology : topological_space (prime_spectrum R) :=
topological_space.of_closed (set.range prime_spectrum.zero_locus)
(⟨set.univ, by simp⟩)
begin
intros Zs h,
rw set.sInter_eq_Inter,
let f : Zs → set R := λ i, classical.some (h i.2),
have hf : ∀ i : Zs, ↑i = zero_locus (f i) := λ i, (classical.some_spec (h i.2)).symm,
simp only [hf],
exact ⟨_, zero_locus_Union _⟩
end
(by { rintro _ ⟨s, rfl⟩ _ ⟨t, rfl⟩, exact ⟨_, (union_zero_locus s t).symm⟩ })
lemma is_open_iff (U : set (prime_spectrum R)) :
is_open U ↔ ∃ s, Uᶜ = zero_locus s :=
by simp only [@eq_comm _ Uᶜ]; refl
lemma is_closed_iff_zero_locus (Z : set (prime_spectrum R)) :
is_closed Z ↔ ∃ s, Z = zero_locus s :=
by rw [← is_open_compl_iff, is_open_iff, compl_compl]
lemma is_closed_iff_zero_locus_ideal (Z : set (prime_spectrum R)) :
is_closed Z ↔ ∃ (s : ideal R), Z = zero_locus s :=
(is_closed_iff_zero_locus _).trans
⟨λ x, ⟨_, x.some_spec.trans (zero_locus_span _).symm⟩, λ x, ⟨_, x.some_spec⟩⟩
lemma is_closed_iff_zero_locus_radical_ideal (Z : set (prime_spectrum R)) :
is_closed Z ↔ ∃ (s : ideal R), s.radical = s ∧ Z = zero_locus s :=
(is_closed_iff_zero_locus_ideal _).trans
⟨λ x, ⟨_, ideal.radical_idem _, x.some_spec.trans (zero_locus_radical _).symm⟩,
λ x, ⟨_, x.some_spec.2⟩⟩
lemma is_closed_zero_locus (s : set R) :
is_closed (zero_locus s) :=
by { rw [is_closed_iff_zero_locus], exact ⟨s, rfl⟩ }
lemma is_closed_singleton_iff_is_maximal (x : prime_spectrum R) :
is_closed ({x} : set (prime_spectrum R)) ↔ x.as_ideal.is_maximal :=
begin
refine (is_closed_iff_zero_locus _).trans ⟨λ h, _, λ h, _⟩,
{ obtain ⟨s, hs⟩ := h,
rw [eq_comm, set.eq_singleton_iff_unique_mem] at hs,
refine ⟨⟨x.2.1, λ I hI, not_not.1 (mt (ideal.exists_le_maximal I) $
not_exists.2 (λ J, not_and.2 $ λ hJ hIJ,_))⟩⟩,
exact ne_of_lt (lt_of_lt_of_le hI hIJ) (symm $ congr_arg prime_spectrum.as_ideal
(hs.2 ⟨J, hJ.is_prime⟩ (λ r hr, hIJ (le_of_lt hI $ hs.1 hr)))) },
{ refine ⟨x.as_ideal.1, _⟩,
rw [eq_comm, set.eq_singleton_iff_unique_mem],
refine ⟨λ _ h, h, λ y hy, prime_spectrum.ext.2 (h.eq_of_le y.2.ne_top hy).symm⟩ }
end
lemma zero_locus_vanishing_ideal_eq_closure (t : set (prime_spectrum R)) :
zero_locus (vanishing_ideal t : set R) = closure t :=
begin
apply set.subset.antisymm,
{ rintro x hx t' ⟨ht', ht⟩,
obtain ⟨fs, rfl⟩ : ∃ s, t' = zero_locus s,
by rwa [is_closed_iff_zero_locus] at ht',
rw [subset_zero_locus_iff_subset_vanishing_ideal] at ht,
exact set.subset.trans ht hx },
{ rw (is_closed_zero_locus _).closure_subset_iff,
exact subset_zero_locus_vanishing_ideal t }
end
lemma vanishing_ideal_closure (t : set (prime_spectrum R)) :
vanishing_ideal (closure t) = vanishing_ideal t :=
zero_locus_vanishing_ideal_eq_closure t ▸ (gc R).u_l_u_eq_u t
lemma t1_space_iff_is_field [is_domain R] :
t1_space (prime_spectrum R) ↔ is_field R :=
begin
refine ⟨_, λ h, _⟩,
{ introI h,
have hbot : ideal.is_prime (⊥ : ideal R) := ideal.bot_prime,
exact not_not.1 (mt (ring.ne_bot_of_is_maximal_of_not_is_field $
(is_closed_singleton_iff_is_maximal _).1 (t1_space.t1 ⟨⊥, hbot⟩)) (not_not.2 rfl)) },
{ refine ⟨λ x, (is_closed_singleton_iff_is_maximal x).2 _⟩,
by_cases hx : x.as_ideal = ⊥,
{ exact hx.symm ▸ @ideal.bot_is_maximal R (@field.to_division_ring _ h.to_field) },
{ exact absurd h (ring.not_is_field_iff_exists_prime.2 ⟨x.as_ideal, ⟨hx, x.2⟩⟩) } }
end
local notation `Z(` a `)` := zero_locus (a : set R)
lemma is_irreducible_zero_locus_iff_of_radical (I : ideal R) (hI : I.radical = I) :
is_irreducible (zero_locus (I : set R)) ↔ I.is_prime :=
begin
rw [ideal.is_prime_iff, is_irreducible],
apply and_congr,
{ rw [← set.ne_empty_iff_nonempty, ne.def, zero_locus_empty_iff_eq_top] },
{ transitivity ∀ (x y : ideal R), Z(I) ⊆ Z(x) ∪ Z(y) → Z(I) ⊆ Z(x) ∨ Z(I) ⊆ Z(y),
{ simp_rw [is_preirreducible_iff_closed_union_closed, is_closed_iff_zero_locus_ideal],
split,
{ rintros h x y, exact h _ _ ⟨x, rfl⟩ ⟨y, rfl⟩ },
{ rintros h _ _ ⟨x, rfl⟩ ⟨y, rfl⟩, exact h x y } },
{ simp_rw [← zero_locus_inf, subset_zero_locus_iff_le_vanishing_ideal,
vanishing_ideal_zero_locus_eq_radical, hI],
split,
{ intros h x y h',
simp_rw [← set_like.mem_coe, ← set.singleton_subset_iff, ← ideal.span_le],
apply h,
rw [← hI, ← ideal.radical_le_radical_iff, ideal.radical_inf, ← ideal.radical_mul,
ideal.radical_le_radical_iff, hI, ideal.span_mul_span],
simpa [ideal.span_le] using h' },
{ simp_rw [or_iff_not_imp_left, set_like.not_le_iff_exists],
rintros h s t h' ⟨x, hx, hx'⟩ y hy,
exact h (h' ⟨ideal.mul_mem_right _ _ hx, ideal.mul_mem_left _ _ hy⟩) hx' } } }
end
lemma is_irreducible_zero_locus_iff (I : ideal R) :
is_irreducible (zero_locus (I : set R)) ↔ I.radical.is_prime :=
(zero_locus_radical I) ▸ is_irreducible_zero_locus_iff_of_radical _ I.radical_idem
instance [is_domain R] : irreducible_space (prime_spectrum R) :=
begin
rw [irreducible_space_def, set.top_eq_univ, ← zero_locus_bot, is_irreducible_zero_locus_iff],
simpa using ideal.bot_prime
end
instance : quasi_sober (prime_spectrum R) :=
begin
constructor,
intros S h₁ h₂,
rw [← h₂.closure_eq, ← zero_locus_vanishing_ideal_eq_closure,
is_irreducible_zero_locus_iff] at h₁,
use ⟨_, h₁⟩,
obtain ⟨s, hs, rfl⟩ := (is_closed_iff_zero_locus_radical_ideal _).mp h₂,
rw is_generic_point_iff_forall_closed h₂,
intros Z hZ hxZ,
obtain ⟨t, rfl⟩ := (is_closed_iff_zero_locus_ideal _).mp hZ,
exact zero_locus_anti_mono (by simpa [hs] using hxZ),
simp [hs]
end
section comap
variables {S : Type v} [comm_ring S] {S' : Type*} [comm_ring S']
lemma preimage_comap_zero_locus_aux (f : R →+* S) (s : set R) :
(λ y, ⟨ideal.comap f y.as_ideal, infer_instance⟩ :
prime_spectrum S → prime_spectrum R) ⁻¹' (zero_locus s) = zero_locus (f '' s) :=
begin
ext x,
simp only [mem_zero_locus, set.image_subset_iff],
refl
end
/-- The function between prime spectra of commutative rings induced by a ring homomorphism.
This function is continuous. -/
def comap (f : R →+* S) : C(prime_spectrum S, prime_spectrum R) :=
{ to_fun := λ y, ⟨ideal.comap f y.as_ideal, infer_instance⟩,
continuous_to_fun :=
begin
simp only [continuous_iff_is_closed, is_closed_iff_zero_locus],
rintro _ ⟨s, rfl⟩,
exact ⟨_, preimage_comap_zero_locus_aux f s⟩
end }
variables (f : R →+* S)
@[simp] lemma comap_as_ideal (y : prime_spectrum S) :
(comap f y).as_ideal = ideal.comap f y.as_ideal :=
rfl
@[simp] lemma comap_id : comap (ring_hom.id R) = continuous_map.id _ := by { ext, refl }
@[simp] lemma comap_comp (f : R →+* S) (g : S →+* S') :
comap (g.comp f) = (comap f).comp (comap g) :=
rfl
lemma comap_comp_apply (f : R →+* S) (g : S →+* S') (x : prime_spectrum S') :
prime_spectrum.comap (g.comp f) x = (prime_spectrum.comap f) (prime_spectrum.comap g x) :=
rfl
@[simp] lemma preimage_comap_zero_locus (s : set R) :
(comap f) ⁻¹' (zero_locus s) = zero_locus (f '' s) :=
preimage_comap_zero_locus_aux f s
lemma comap_injective_of_surjective (f : R →+* S) (hf : function.surjective f) :
function.injective (comap f) :=
λ x y h, prime_spectrum.ext.2 (ideal.comap_injective_of_surjective f hf
(congr_arg prime_spectrum.as_ideal h : (comap f x).as_ideal = (comap f y).as_ideal))
lemma comap_singleton_is_closed_of_surjective (f : R →+* S) (hf : function.surjective f)
(x : prime_spectrum S) (hx : is_closed ({x} : set (prime_spectrum S))) :
is_closed ({comap f x} : set (prime_spectrum R)) :=
begin
haveI : x.as_ideal.is_maximal := (is_closed_singleton_iff_is_maximal x).1 hx,
exact (is_closed_singleton_iff_is_maximal _).2 (ideal.comap_is_maximal_of_surjective f hf)
end
lemma comap_singleton_is_closed_of_is_integral (f : R →+* S) (hf : f.is_integral)
(x : prime_spectrum S) (hx : is_closed ({x} : set (prime_spectrum S))) :
is_closed ({comap f x} : set (prime_spectrum R)) :=
(is_closed_singleton_iff_is_maximal _).2 (ideal.is_maximal_comap_of_is_integral_of_is_maximal'
f hf x.as_ideal $ (is_closed_singleton_iff_is_maximal x).1 hx)
variable S
lemma localization_comap_inducing [algebra R S] (M : submonoid R)
[is_localization M S] : inducing (comap (algebra_map R S)) :=
begin
constructor,
rw topological_space_eq_iff,
intro U,
simp_rw ← is_closed_compl_iff,
generalize : Uᶜ = Z,
simp_rw [is_closed_induced_iff, is_closed_iff_zero_locus],
split,
{ rintro ⟨s, rfl⟩,
refine ⟨_,⟨(algebra_map R S) ⁻¹' (ideal.span s),rfl⟩,_⟩,
rw [preimage_comap_zero_locus, ← zero_locus_span, ← zero_locus_span s],
congr' 1,
exact congr_arg submodule.carrier (is_localization.map_comap M S (ideal.span s)) },
{ rintro ⟨_, ⟨t, rfl⟩, rfl⟩, simp }
end
lemma localization_comap_injective [algebra R S] (M : submonoid R)
[is_localization M S] : function.injective (comap (algebra_map R S)) :=
begin
intros p q h,
replace h := congr_arg (λ (x : prime_spectrum R), ideal.map (algebra_map R S) x.as_ideal) h,
dsimp only at h,
erw [is_localization.map_comap M S, is_localization.map_comap M S] at h,
ext1,
exact h
end
lemma localization_comap_embedding [algebra R S] (M : submonoid R)
[is_localization M S] : embedding (comap (algebra_map R S)) :=
⟨localization_comap_inducing S M, localization_comap_injective S M⟩
lemma localization_comap_range [algebra R S] (M : submonoid R)
[is_localization M S] :
set.range (comap (algebra_map R S)) = { p | disjoint (M : set R) p.as_ideal } :=
begin
ext x,
split,
{ rintro ⟨p, rfl⟩ x ⟨hx₁, hx₂⟩,
exact (p.2.1 : ¬ _)
(p.as_ideal.eq_top_of_is_unit_mem hx₂ (is_localization.map_units S ⟨x, hx₁⟩)) },
{ intro h,
use ⟨x.as_ideal.map (algebra_map R S),
is_localization.is_prime_of_is_prime_disjoint M S _ x.2 h⟩,
ext1,
exact is_localization.comap_map_of_is_prime_disjoint M S _ x.2 h }
end
section spec_of_surjective
/-! The comap of a surjective ring homomorphism is a closed embedding between the prime spectra. -/
open function ring_hom
lemma comap_inducing_of_surjective (hf : surjective f) : inducing (comap f) :=
{ induced := begin
simp_rw [topological_space_eq_iff, ←is_closed_compl_iff, is_closed_induced_iff,
is_closed_iff_zero_locus],
refine λ s, ⟨λ ⟨F, hF⟩, ⟨zero_locus (f ⁻¹' F), ⟨f ⁻¹' F, rfl⟩,
by rw [preimage_comap_zero_locus, surjective.image_preimage hf, hF]⟩, _⟩,
rintros ⟨-, ⟨F, rfl⟩, hF⟩,
exact ⟨f '' F, hF.symm.trans (preimage_comap_zero_locus f F)⟩,
end }
lemma image_comap_zero_locus_eq_zero_locus_comap (hf : surjective f) (I : ideal S) :
comap f '' zero_locus I = zero_locus (I.comap f) :=
begin
simp only [set.ext_iff, set.mem_image, mem_zero_locus, set_like.coe_subset_coe],
refine λ p, ⟨_, λ h_I_p, _⟩,
{ rintro ⟨p, hp, rfl⟩ a ha,
exact hp ha },
{ have hp : ker f ≤ p.as_ideal := (ideal.comap_mono bot_le).trans h_I_p,
refine ⟨⟨p.as_ideal.map f, ideal.map_is_prime_of_surjective hf hp⟩, λ x hx, _, _⟩,
{ obtain ⟨x', rfl⟩ := hf x,
exact ideal.mem_map_of_mem f (h_I_p hx) },
{ ext x,
change f x ∈ p.as_ideal.map f ↔ _,
rw ideal.mem_map_iff_of_surjective f hf,
refine ⟨_, λ hx, ⟨x, hx, rfl⟩⟩,
rintros ⟨x', hx', heq⟩,
rw ← sub_sub_cancel x' x,
refine p.as_ideal.sub_mem hx' (hp _),
rwa [mem_ker, map_sub, sub_eq_zero] } },
end
lemma range_comap_of_surjective (hf : surjective f) :
set.range (comap f) = zero_locus (ker f) :=
begin
rw ← set.image_univ,
convert image_comap_zero_locus_eq_zero_locus_comap _ _ hf _,
rw zero_locus_bot,
end
lemma is_closed_range_comap_of_surjective (hf : surjective f) : is_closed (set.range (comap f)) :=
begin
rw range_comap_of_surjective _ f hf,
exact is_closed_zero_locus ↑(ker f),
end
lemma closed_embedding_comap_of_surjective (hf : surjective f) : closed_embedding (comap f) :=
{ induced := (comap_inducing_of_surjective S f hf).induced,
inj := comap_injective_of_surjective f hf,
closed_range := is_closed_range_comap_of_surjective S f hf }
end spec_of_surjective
end comap
section basic_open
/-- `basic_open r` is the open subset containing all prime ideals not containing `r`. -/
def basic_open (r : R) : topological_space.opens (prime_spectrum R) :=
{ val := { x | r ∉ x.as_ideal },
property := ⟨{r}, set.ext $ λ x, set.singleton_subset_iff.trans $ not_not.symm⟩ }
@[simp] lemma mem_basic_open (f : R) (x : prime_spectrum R) :
x ∈ basic_open f ↔ f ∉ x.as_ideal := iff.rfl
lemma is_open_basic_open {a : R} : is_open ((basic_open a) : set (prime_spectrum R)) :=
(basic_open a).property
@[simp] lemma basic_open_eq_zero_locus_compl (r : R) :
(basic_open r : set (prime_spectrum R)) = (zero_locus {r})ᶜ :=
set.ext $ λ x, by simpa only [set.mem_compl_eq, mem_zero_locus, set.singleton_subset_iff]
@[simp] lemma basic_open_one : basic_open (1 : R) = ⊤ :=
topological_space.opens.ext $ by simp
@[simp] lemma basic_open_zero : basic_open (0 : R) = ⊥ :=
topological_space.opens.ext $ by simp
lemma basic_open_le_basic_open_iff (f g : R) :
basic_open f ≤ basic_open g ↔ f ∈ (ideal.span ({g} : set R)).radical :=
by rw [topological_space.opens.le_def, basic_open_eq_zero_locus_compl,
basic_open_eq_zero_locus_compl, set.le_eq_subset, set.compl_subset_compl,
zero_locus_subset_zero_locus_singleton_iff]
lemma basic_open_mul (f g : R) : basic_open (f * g) = basic_open f ⊓ basic_open g :=
topological_space.opens.ext $ by {simp [zero_locus_singleton_mul]}
lemma basic_open_mul_le_left (f g : R) : basic_open (f * g) ≤ basic_open f :=
by { rw basic_open_mul f g, exact inf_le_left }
lemma basic_open_mul_le_right (f g : R) : basic_open (f * g) ≤ basic_open g :=
by { rw basic_open_mul f g, exact inf_le_right }
@[simp] lemma basic_open_pow (f : R) (n : ℕ) (hn : 0 < n) : basic_open (f ^ n) = basic_open f :=
topological_space.opens.ext $ by simpa using zero_locus_singleton_pow f n hn
lemma is_topological_basis_basic_opens : topological_space.is_topological_basis
(set.range (λ (r : R), (basic_open r : set (prime_spectrum R)))) :=
begin
apply topological_space.is_topological_basis_of_open_of_nhds,
{ rintros _ ⟨r, rfl⟩,
exact is_open_basic_open },
{ rintros p U hp ⟨s, hs⟩,
rw [← compl_compl U, set.mem_compl_eq, ← hs, mem_zero_locus, set.not_subset] at hp,
obtain ⟨f, hfs, hfp⟩ := hp,
refine ⟨basic_open f, ⟨f, rfl⟩, hfp, _⟩,
rw [← set.compl_subset_compl, ← hs, basic_open_eq_zero_locus_compl, compl_compl],
exact zero_locus_anti_mono (set.singleton_subset_iff.mpr hfs) }
end
lemma is_basis_basic_opens :
topological_space.opens.is_basis (set.range (@basic_open R _)) :=
begin
unfold topological_space.opens.is_basis,
convert is_topological_basis_basic_opens,
rw ← set.range_comp,
end
lemma is_compact_basic_open (f : R) : is_compact (basic_open f : set (prime_spectrum R)) :=
is_compact_of_finite_subfamily_closed $ λ ι Z hZc hZ,
begin
let I : ι → ideal R := λ i, vanishing_ideal (Z i),
have hI : ∀ i, Z i = zero_locus (I i) := λ i,
by simpa only [zero_locus_vanishing_ideal_eq_closure] using (hZc i).closure_eq.symm,
rw [basic_open_eq_zero_locus_compl f, set.inter_comm, ← set.diff_eq,
set.diff_eq_empty, funext hI, ← zero_locus_supr] at hZ,
obtain ⟨n, hn⟩ : f ∈ (⨆ (i : ι), I i).radical,
{ rw ← vanishing_ideal_zero_locus_eq_radical,
apply vanishing_ideal_anti_mono hZ,
exact (subset_vanishing_ideal_zero_locus {f} (set.mem_singleton f)) },
rcases submodule.exists_finset_of_mem_supr I hn with ⟨s, hs⟩,
use s,
-- Using simp_rw here, because `hI` and `zero_locus_supr` need to be applied underneath binders
simp_rw [basic_open_eq_zero_locus_compl f, set.inter_comm (zero_locus {f})ᶜ, ← set.diff_eq,
set.diff_eq_empty, hI, ← zero_locus_supr],
rw ← zero_locus_radical, -- this one can't be in `simp_rw` because it would loop
apply zero_locus_anti_mono,
rw set.singleton_subset_iff,
exact ⟨n, hs⟩
end
@[simp]
lemma basic_open_eq_bot_iff (f : R) :
basic_open f = ⊥ ↔ is_nilpotent f :=
begin
rw [← subtype.coe_injective.eq_iff, basic_open_eq_zero_locus_compl],
simp only [set.eq_univ_iff_forall, topological_space.opens.empty_eq, set.singleton_subset_iff,
topological_space.opens.coe_bot, nilpotent_iff_mem_prime, set.compl_empty_iff, mem_zero_locus,
set_like.mem_coe],
exact subtype.forall,
end
lemma localization_away_comap_range (S : Type v) [comm_ring S] [algebra R S] (r : R)
[is_localization.away r S] : set.range (comap (algebra_map R S)) = basic_open r :=
begin
rw localization_comap_range S (submonoid.powers r),
ext,
simp only [mem_zero_locus, basic_open_eq_zero_locus_compl, set_like.mem_coe, set.mem_set_of_eq,
set.singleton_subset_iff, set.mem_compl_eq],
split,
{ intros h₁ h₂,
exact h₁ ⟨submonoid.mem_powers r, h₂⟩ },
{ rintros h₁ _ ⟨⟨n, rfl⟩, h₃⟩,
exact h₁ (x.2.mem_of_pow_mem _ h₃) },
end
lemma localization_away_open_embedding (S : Type v) [comm_ring S] [algebra R S] (r : R)
[is_localization.away r S] : open_embedding (comap (algebra_map R S)) :=
{ to_embedding := localization_comap_embedding S (submonoid.powers r),
open_range := by { rw localization_away_comap_range S r, exact is_open_basic_open } }
end basic_open
/-- The prime spectrum of a commutative ring is a compact topological space. -/
instance : compact_space (prime_spectrum R) :=
{ compact_univ := by { convert is_compact_basic_open (1 : R), rw basic_open_one, refl } }
section order
/-!
## The specialization order
We endow `prime_spectrum R` with a partial order,
where `x ≤ y` if and only if `y ∈ closure {x}`.
-/
instance : partial_order (prime_spectrum R) :=
subtype.partial_order _
@[simp] lemma as_ideal_le_as_ideal (x y : prime_spectrum R) :
x.as_ideal ≤ y.as_ideal ↔ x ≤ y :=
subtype.coe_le_coe
@[simp] lemma as_ideal_lt_as_ideal (x y : prime_spectrum R) :
x.as_ideal < y.as_ideal ↔ x < y :=
subtype.coe_lt_coe
lemma le_iff_mem_closure (x y : prime_spectrum R) :
x ≤ y ↔ y ∈ closure ({x} : set (prime_spectrum R)) :=
by rw [← as_ideal_le_as_ideal, ← zero_locus_vanishing_ideal_eq_closure,
mem_zero_locus, vanishing_ideal_singleton, set_like.coe_subset_coe]
lemma le_iff_specializes (x y : prime_spectrum R) :
x ≤ y ↔ x ⤳ y :=
(le_iff_mem_closure x y).trans specializes_iff_mem_closure.symm
/-- `nhds` as an order embedding. -/
@[simps { fully_applied := tt }]
def nhds_order_embedding : prime_spectrum R ↪o filter (prime_spectrum R) :=
order_embedding.of_map_le_iff nhds $ λ a b, (le_iff_specializes a b).symm
instance : t0_space (prime_spectrum R) := ⟨nhds_order_embedding.injective⟩
end order
/-- If `x` specializes to `y`, then there is a natural map from the localization of `y` to
the localization of `x`. -/
def localization_map_of_specializes {x y : prime_spectrum R} (h : x ⤳ y) :
localization.at_prime y.as_ideal →+* localization.at_prime x.as_ideal :=
@is_localization.lift _ _ _ _ _ _ _ _
localization.is_localization (algebra_map R (localization.at_prime x.as_ideal))
begin
rintro ⟨a, ha⟩,
rw [← prime_spectrum.le_iff_specializes, ← as_ideal_le_as_ideal, ← set_like.coe_subset_coe,
← set.compl_subset_compl] at h,
exact (is_localization.map_units _ ⟨a, (show a ∈ x.as_ideal.prime_compl, from h ha)⟩ : _)
end
end prime_spectrum
namespace local_ring
variables (R) [local_ring R]
/--
The closed point in the prime spectrum of a local ring.
-/
def closed_point : prime_spectrum R :=
⟨maximal_ideal R, (maximal_ideal.is_maximal R).is_prime⟩
variable {R}
lemma is_local_ring_hom_iff_comap_closed_point {S : Type v} [comm_ring S] [local_ring S]
(f : R →+* S) : is_local_ring_hom f ↔ prime_spectrum.comap f (closed_point S) = closed_point R :=
by { rw [(local_hom_tfae f).out 0 4, subtype.ext_iff], refl }
@[simp] lemma comap_closed_point {S : Type v} [comm_ring S] [local_ring S] (f : R →+* S)
[is_local_ring_hom f] : prime_spectrum.comap f (closed_point S) = closed_point R :=
(is_local_ring_hom_iff_comap_closed_point f).mp infer_instance
end local_ring
|
cbf23fcc3e88995f62f720c3b9b1faa54bcb9d61 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/probability/independence.lean | 889236043b328bd3f28df4abcdc72bf9bc7a9666 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 36,549 | lean | /-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import algebra.big_operators.intervals
import measure_theory.constructions.pi
/-!
# Independence of sets of sets and measure spaces (σ-algebras)
* A family of sets of sets `π : ι → set (set Ω)` is independent with respect to a measure `μ` if for
any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`,
`μ (⋂ i in s, f i) = ∏ i in s, μ (f i) `. It will be used for families of π-systems.
* A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a
measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they
define is independent. I.e., `m : ι → measurable_space Ω` is independent with respect to a
measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i in s, μ (f i)`.
* Independence of sets (or events in probabilistic parlance) is defined as independence of the
measurable space structures they generate: a set `s` generates the measurable space structure with
measurable sets `∅, s, sᶜ, univ`.
* Independence of functions (or random variables) is also defined as independence of the measurable
space structures they generate: a function `f` for which we have a measurable space `m` on the
codomain generates `measurable_space.comap f m`.
## Main statements
* `Indep_sets.Indep`: if π-systems are independent as sets of sets, then the
measurable space structures they generate are independent.
* `indep_sets.indep`: variant with two π-systems.
## Implementation notes
We provide one main definition of independence:
* `Indep_sets`: independence of a family of sets of sets `pi : ι → set (set Ω)`.
Three other independence notions are defined using `Indep_sets`:
* `Indep`: independence of a family of measurable space structures `m : ι → measurable_space Ω`,
* `Indep_set`: independence of a family of sets `s : ι → set Ω`,
* `Indep_fun`: independence of a family of functions. For measurable spaces
`m : Π (i : ι), measurable_space (β i)`, we consider functions `f : Π (i : ι), Ω → β i`.
Additionally, we provide four corresponding statements for two measurable space structures (resp.
sets of sets, sets, functions) instead of a family. These properties are denoted by the same names
as for a family, but without a capital letter, for example `indep_fun` is the version of `Indep_fun`
for two functions.
The definition of independence for `Indep_sets` uses finite sets (`finset`). An alternative and
equivalent way of defining independence would have been to use countable sets.
TODO: prove that equivalence.
Most of the definitions and lemma in this file list all variables instead of using the `variables`
keyword at the beginning of a section, for example
`lemma indep.symm {Ω} {m₁ m₂ : measurable_space Ω} [measurable_space Ω] {μ : measure Ω} ...` .
This is intentional, to be able to control the order of the `measurable_space` variables. Indeed
when defining `μ` in the example above, the measurable space used is the last one defined, here
`[measurable_space Ω]`, and not `m₁` or `m₂`.
## References
* Williams, David. Probability with martingales. Cambridge university press, 1991.
Part A, Chapter 4.
-/
open measure_theory measurable_space
open_locale big_operators classical measure_theory
namespace probability_theory
variables {Ω ι : Type*}
section definitions
/-- A family of sets of sets `π : ι → set (set Ω)` is independent with respect to a measure `μ` if
for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `μ (⋂ i in s, f i) = ∏ i in s, μ (f i) `.
It will be used for families of pi_systems. -/
def Indep_sets [measurable_space Ω] (π : ι → set (set Ω)) (μ : measure Ω . volume_tac) :
Prop :=
∀ (s : finset ι) {f : ι → set Ω} (H : ∀ i, i ∈ s → f i ∈ π i), μ (⋂ i ∈ s, f i) = ∏ i in s, μ (f i)
/-- Two sets of sets `s₁, s₂` are independent with respect to a measure `μ` if for any sets
`t₁ ∈ p₁, t₂ ∈ s₂`, then `μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/
def indep_sets [measurable_space Ω] (s1 s2 : set (set Ω)) (μ : measure Ω . volume_tac) : Prop :=
∀ t1 t2 : set Ω, t1 ∈ s1 → t2 ∈ s2 → μ (t1 ∩ t2) = μ t1 * μ t2
/-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a
measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they
define is independent. `m : ι → measurable_space Ω` is independent with respect to measure `μ` if
for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i in s, μ (f i) `. -/
def Indep (m : ι → measurable_space Ω) [measurable_space Ω] (μ : measure Ω . volume_tac) :
Prop :=
Indep_sets (λ x, {s | measurable_set[m x] s}) μ
/-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a
measure `μ` (defined on a third σ-algebra) if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`,
`μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/
def indep (m₁ m₂ : measurable_space Ω) [measurable_space Ω] (μ : measure Ω . volume_tac) :
Prop :=
indep_sets {s | measurable_set[m₁] s} {s | measurable_set[m₂] s} μ
/-- A family of sets is independent if the family of measurable space structures they generate is
independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/
def Indep_set [measurable_space Ω] (s : ι → set Ω) (μ : measure Ω . volume_tac) : Prop :=
Indep (λ i, generate_from {s i}) μ
/-- Two sets are independent if the two measurable space structures they generate are independent.
For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/
def indep_set [measurable_space Ω] (s t : set Ω) (μ : measure Ω . volume_tac) : Prop :=
indep (generate_from {s}) (generate_from {t}) μ
/-- A family of functions defined on the same space `Ω` and taking values in possibly different
spaces, each with a measurable space structure, is independent if the family of measurable space
structures they generate on `Ω` is independent. For a function `g` with codomain having measurable
space structure `m`, the generated measurable space structure is `measurable_space.comap g m`. -/
def Indep_fun [measurable_space Ω] {β : ι → Type*} (m : Π (x : ι), measurable_space (β x))
(f : Π (x : ι), Ω → β x) (μ : measure Ω . volume_tac) : Prop :=
Indep (λ x, measurable_space.comap (f x) (m x)) μ
/-- Two functions are independent if the two measurable space structures they generate are
independent. For a function `f` with codomain having measurable space structure `m`, the generated
measurable space structure is `measurable_space.comap f m`. -/
def indep_fun {β γ} [measurable_space Ω] [mβ : measurable_space β] [mγ : measurable_space γ]
(f : Ω → β) (g : Ω → γ) (μ : measure Ω . volume_tac) : Prop :=
indep (measurable_space.comap f mβ) (measurable_space.comap g mγ) μ
end definitions
section indep
lemma indep_sets.symm {s₁ s₂ : set (set Ω)} [measurable_space Ω] {μ : measure Ω}
(h : indep_sets s₁ s₂ μ) :
indep_sets s₂ s₁ μ :=
by { intros t1 t2 ht1 ht2, rw [set.inter_comm, mul_comm], exact h t2 t1 ht2 ht1, }
lemma indep.symm {m₁ m₂ : measurable_space Ω} [measurable_space Ω] {μ : measure Ω}
(h : indep m₁ m₂ μ) :
indep m₂ m₁ μ :=
indep_sets.symm h
lemma indep_bot_right (m' : measurable_space Ω) {m : measurable_space Ω}
{μ : measure Ω} [is_probability_measure μ] :
indep m' ⊥ μ :=
begin
intros s t hs ht,
rw [set.mem_set_of_eq, measurable_space.measurable_set_bot_iff] at ht,
cases ht,
{ rw [ht, set.inter_empty, measure_empty, mul_zero], },
{ rw [ht, set.inter_univ, measure_univ, mul_one], },
end
lemma indep_bot_left (m' : measurable_space Ω) {m : measurable_space Ω}
{μ : measure Ω} [is_probability_measure μ] :
indep ⊥ m' μ :=
(indep_bot_right m').symm
lemma indep_sets_of_indep_sets_of_le_left {s₁ s₂ s₃: set (set Ω)} [measurable_space Ω]
{μ : measure Ω} (h_indep : indep_sets s₁ s₂ μ) (h31 : s₃ ⊆ s₁) :
indep_sets s₃ s₂ μ :=
λ t1 t2 ht1 ht2, h_indep t1 t2 (set.mem_of_subset_of_mem h31 ht1) ht2
lemma indep_sets_of_indep_sets_of_le_right {s₁ s₂ s₃: set (set Ω)} [measurable_space Ω]
{μ : measure Ω} (h_indep : indep_sets s₁ s₂ μ) (h32 : s₃ ⊆ s₂) :
indep_sets s₁ s₃ μ :=
λ t1 t2 ht1 ht2, h_indep t1 t2 ht1 (set.mem_of_subset_of_mem h32 ht2)
lemma indep_of_indep_of_le_left {m₁ m₂ m₃: measurable_space Ω} [measurable_space Ω]
{μ : measure Ω} (h_indep : indep m₁ m₂ μ) (h31 : m₃ ≤ m₁) :
indep m₃ m₂ μ :=
λ t1 t2 ht1 ht2, h_indep t1 t2 (h31 _ ht1) ht2
lemma indep_of_indep_of_le_right {m₁ m₂ m₃: measurable_space Ω} [measurable_space Ω]
{μ : measure Ω} (h_indep : indep m₁ m₂ μ) (h32 : m₃ ≤ m₂) :
indep m₁ m₃ μ :=
λ t1 t2 ht1 ht2, h_indep t1 t2 ht1 (h32 _ ht2)
lemma indep_sets.union [measurable_space Ω] {s₁ s₂ s' : set (set Ω)} {μ : measure Ω}
(h₁ : indep_sets s₁ s' μ) (h₂ : indep_sets s₂ s' μ) :
indep_sets (s₁ ∪ s₂) s' μ :=
begin
intros t1 t2 ht1 ht2,
cases (set.mem_union _ _ _).mp ht1 with ht1₁ ht1₂,
{ exact h₁ t1 t2 ht1₁ ht2, },
{ exact h₂ t1 t2 ht1₂ ht2, },
end
@[simp] lemma indep_sets.union_iff [measurable_space Ω] {s₁ s₂ s' : set (set Ω)}
{μ : measure Ω} :
indep_sets (s₁ ∪ s₂) s' μ ↔ indep_sets s₁ s' μ ∧ indep_sets s₂ s' μ :=
⟨λ h, ⟨indep_sets_of_indep_sets_of_le_left h (set.subset_union_left s₁ s₂),
indep_sets_of_indep_sets_of_le_left h (set.subset_union_right s₁ s₂)⟩,
λ h, indep_sets.union h.left h.right⟩
lemma indep_sets.Union [measurable_space Ω] {s : ι → set (set Ω)} {s' : set (set Ω)}
{μ : measure Ω} (hyp : ∀ n, indep_sets (s n) s' μ) :
indep_sets (⋃ n, s n) s' μ :=
begin
intros t1 t2 ht1 ht2,
rw set.mem_Union at ht1,
cases ht1 with n ht1,
exact hyp n t1 t2 ht1 ht2,
end
lemma indep_sets.inter [measurable_space Ω] {s₁ s' : set (set Ω)} (s₂ : set (set Ω))
{μ : measure Ω} (h₁ : indep_sets s₁ s' μ) :
indep_sets (s₁ ∩ s₂) s' μ :=
λ t1 t2 ht1 ht2, h₁ t1 t2 ((set.mem_inter_iff _ _ _).mp ht1).left ht2
lemma indep_sets.Inter [measurable_space Ω] {s : ι → set (set Ω)} {s' : set (set Ω)}
{μ : measure Ω} (h : ∃ n, indep_sets (s n) s' μ) :
indep_sets (⋂ n, s n) s' μ :=
by {intros t1 t2 ht1 ht2, cases h with n h, exact h t1 t2 (set.mem_Inter.mp ht1 n) ht2 }
lemma indep_sets_singleton_iff [measurable_space Ω] {s t : set Ω} {μ : measure Ω} :
indep_sets {s} {t} μ ↔ μ (s ∩ t) = μ s * μ t :=
⟨λ h, h s t rfl rfl,
λ h s1 t1 hs1 ht1, by rwa [set.mem_singleton_iff.mp hs1, set.mem_singleton_iff.mp ht1]⟩
end indep
/-! ### Deducing `indep` from `Indep` -/
section from_Indep_to_indep
lemma Indep_sets.indep_sets {s : ι → set (set Ω)} [measurable_space Ω] {μ : measure Ω}
(h_indep : Indep_sets s μ) {i j : ι} (hij : i ≠ j) :
indep_sets (s i) (s j) μ :=
begin
intros t₁ t₂ ht₁ ht₂,
have hf_m : ∀ (x : ι), x ∈ {i, j} → (ite (x=i) t₁ t₂) ∈ s x,
{ intros x hx,
cases finset.mem_insert.mp hx with hx hx,
{ simp [hx, ht₁], },
{ simp [finset.mem_singleton.mp hx, hij.symm, ht₂], }, },
have h1 : t₁ = ite (i = i) t₁ t₂, by simp only [if_true, eq_self_iff_true],
have h2 : t₂ = ite (j = i) t₁ t₂, by simp only [hij.symm, if_false],
have h_inter : (⋂ (t : ι) (H : t ∈ ({i, j} : finset ι)), ite (t = i) t₁ t₂)
= (ite (i = i) t₁ t₂) ∩ (ite (j = i) t₁ t₂),
by simp only [finset.set_bInter_singleton, finset.set_bInter_insert],
have h_prod : (∏ (t : ι) in ({i, j} : finset ι), μ (ite (t = i) t₁ t₂))
= μ (ite (i = i) t₁ t₂) * μ (ite (j = i) t₁ t₂),
by simp only [hij, finset.prod_singleton, finset.prod_insert, not_false_iff,
finset.mem_singleton],
rw h1,
nth_rewrite 1 h2,
nth_rewrite 3 h2,
rw [←h_inter, ←h_prod, h_indep {i, j} hf_m],
end
lemma Indep.indep {m : ι → measurable_space Ω} [measurable_space Ω] {μ : measure Ω}
(h_indep : Indep m μ) {i j : ι} (hij : i ≠ j) :
indep (m i) (m j) μ :=
begin
change indep_sets ((λ x, measurable_set[m x]) i) ((λ x, measurable_set[m x]) j) μ,
exact Indep_sets.indep_sets h_indep hij,
end
lemma Indep_fun.indep_fun {m₀ : measurable_space Ω} {μ : measure Ω} {β : ι → Type*}
{m : Π x, measurable_space (β x)} {f : Π i, Ω → β i} (hf_Indep : Indep_fun m f μ)
{i j : ι} (hij : i ≠ j) :
indep_fun (f i) (f j) μ :=
hf_Indep.indep hij
end from_Indep_to_indep
/-!
## π-system lemma
Independence of measurable spaces is equivalent to independence of generating π-systems.
-/
section from_measurable_spaces_to_sets_of_sets
/-! ### Independence of measurable space structures implies independence of generating π-systems -/
lemma Indep.Indep_sets [measurable_space Ω] {μ : measure Ω} {m : ι → measurable_space Ω}
{s : ι → set (set Ω)} (hms : ∀ n, m n = generate_from (s n))
(h_indep : Indep m μ) :
Indep_sets s μ :=
λ S f hfs, h_indep S $ λ x hxS,
((hms x).symm ▸ measurable_set_generate_from (hfs x hxS) : measurable_set[m x] (f x))
lemma indep.indep_sets [measurable_space Ω] {μ : measure Ω} {s1 s2 : set (set Ω)}
(h_indep : indep (generate_from s1) (generate_from s2) μ) :
indep_sets s1 s2 μ :=
λ t1 t2 ht1 ht2, h_indep t1 t2 (measurable_set_generate_from ht1) (measurable_set_generate_from ht2)
end from_measurable_spaces_to_sets_of_sets
section from_pi_systems_to_measurable_spaces
/-! ### Independence of generating π-systems implies independence of measurable space structures -/
private lemma indep_sets.indep_aux {m2 : measurable_space Ω}
{m : measurable_space Ω} {μ : measure Ω} [is_probability_measure μ] {p1 p2 : set (set Ω)}
(h2 : m2 ≤ m) (hp2 : is_pi_system p2) (hpm2 : m2 = generate_from p2)
(hyp : indep_sets p1 p2 μ) {t1 t2 : set Ω} (ht1 : t1 ∈ p1) (ht2m : measurable_set[m2] t2) :
μ (t1 ∩ t2) = μ t1 * μ t2 :=
begin
let μ_inter := μ.restrict t1,
let ν := (μ t1) • μ,
have h_univ : μ_inter set.univ = ν set.univ,
by rw [measure.restrict_apply_univ, measure.smul_apply, smul_eq_mul, measure_univ, mul_one],
haveI : is_finite_measure μ_inter := @restrict.is_finite_measure Ω _ t1 μ ⟨measure_lt_top μ t1⟩,
rw [set.inter_comm, ←@measure.restrict_apply Ω _ μ t1 t2 (h2 t2 ht2m)],
refine ext_on_measurable_space_of_generate_finite m p2 (λ t ht, _) h2 hpm2 hp2 h_univ ht2m,
have ht2 : measurable_set[m] t,
{ refine h2 _ _,
rw hpm2,
exact measurable_set_generate_from ht, },
rw [measure.restrict_apply ht2, measure.smul_apply, set.inter_comm],
exact hyp t1 t ht1 ht,
end
lemma indep_sets.indep {m1 m2 : measurable_space Ω} {m : measurable_space Ω}
{μ : measure Ω} [is_probability_measure μ] {p1 p2 : set (set Ω)} (h1 : m1 ≤ m) (h2 : m2 ≤ m)
(hp1 : is_pi_system p1) (hp2 : is_pi_system p2) (hpm1 : m1 = generate_from p1)
(hpm2 : m2 = generate_from p2) (hyp : indep_sets p1 p2 μ) :
indep m1 m2 μ :=
begin
intros t1 t2 ht1 ht2,
let μ_inter := μ.restrict t2,
let ν := (μ t2) • μ,
have h_univ : μ_inter set.univ = ν set.univ,
by rw [measure.restrict_apply_univ, measure.smul_apply, smul_eq_mul, measure_univ, mul_one],
haveI : is_finite_measure μ_inter := @restrict.is_finite_measure Ω _ t2 μ ⟨measure_lt_top μ t2⟩,
rw [mul_comm, ←@measure.restrict_apply Ω _ μ t2 t1 (h1 t1 ht1)],
refine ext_on_measurable_space_of_generate_finite m p1 (λ t ht, _) h1 hpm1 hp1 h_univ ht1,
have ht1 : measurable_set[m] t,
{ refine h1 _ _,
rw hpm1,
exact measurable_set_generate_from ht, },
rw [measure.restrict_apply ht1, measure.smul_apply, smul_eq_mul, mul_comm],
exact indep_sets.indep_aux h2 hp2 hpm2 hyp ht ht2,
end
variables {m0 : measurable_space Ω} {μ : measure Ω}
lemma Indep_sets.pi_Union_Inter_singleton {π : ι → set (set Ω)} {a : ι} {S : finset ι}
(hp_ind : Indep_sets π μ) (haS : a ∉ S) :
indep_sets (pi_Union_Inter π {S}) (π a) μ :=
begin
rintros t1 t2 ⟨s, hs_mem, ft1, hft1_mem, ht1_eq⟩ ht2_mem_pia,
rw set.mem_singleton_iff at hs_mem,
subst hs_mem,
let f := λ n, ite (n = a) t2 (ite (n ∈ s) (ft1 n) set.univ),
have h_f_mem : ∀ n ∈ insert a s, f n ∈ π n,
{ intros n hn_mem_insert,
simp_rw f,
cases (finset.mem_insert.mp hn_mem_insert) with hn_mem hn_mem,
{ simp [hn_mem, ht2_mem_pia], },
{ have hn_ne_a : n ≠ a, by { rintro rfl, exact haS hn_mem, },
simp [hn_ne_a, hn_mem, hft1_mem n hn_mem], }, },
have h_f_mem_pi : ∀ n ∈ s, f n ∈ π n, from λ x hxS, h_f_mem x (by simp [hxS]),
have h_t1 : t1 = ⋂ n ∈ s, f n,
{ suffices h_forall : ∀ n ∈ s, f n = ft1 n,
{ rw ht1_eq,
congr' with n x,
congr' with hns y,
simp only [(h_forall n hns).symm], },
intros n hnS,
have hn_ne_a : n ≠ a, by { rintro rfl, exact haS hnS, },
simp_rw [f, if_pos hnS, if_neg hn_ne_a], },
have h_μ_t1 : μ t1 = ∏ n in s, μ (f n), by rw [h_t1, ←hp_ind s h_f_mem_pi],
have h_t2 : t2 = f a, by { simp_rw [f], simp, },
have h_μ_inter : μ (t1 ∩ t2) = ∏ n in insert a s, μ (f n),
{ have h_t1_inter_t2 : t1 ∩ t2 = ⋂ n ∈ insert a s, f n,
by rw [h_t1, h_t2, finset.set_bInter_insert, set.inter_comm],
rw [h_t1_inter_t2, ←hp_ind (insert a s) h_f_mem], },
rw [h_μ_inter, finset.prod_insert haS, h_t2, mul_comm, h_μ_t1],
end
/-- Auxiliary lemma for `Indep_sets.Indep`. -/
theorem Indep_sets.Indep_aux [is_probability_measure μ] (m : ι → measurable_space Ω)
(h_le : ∀ i, m i ≤ m0) (π : ι → set (set Ω)) (h_pi : ∀ n, is_pi_system (π n))
(hp_univ : ∀ i, set.univ ∈ π i) (h_generate : ∀ i, m i = generate_from (π i))
(h_ind : Indep_sets π μ) :
Indep m μ :=
begin
refine finset.induction (by simp [measure_univ]) _,
intros a S ha_notin_S h_rec f hf_m,
have hf_m_S : ∀ x ∈ S, measurable_set[m x] (f x) := λ x hx, hf_m x (by simp [hx]),
rw [finset.set_bInter_insert, finset.prod_insert ha_notin_S, ←h_rec hf_m_S],
let p := pi_Union_Inter π {S},
set m_p := generate_from p with hS_eq_generate,
have h_indep : indep m_p (m a) μ,
{ have hp : is_pi_system p := is_pi_system_pi_Union_Inter π h_pi {S} (sup_closed_singleton S),
have h_le' : ∀ i, generate_from (π i) ≤ m0 := λ i, (h_generate i).symm.trans_le (h_le i),
have hm_p : m_p ≤ m0 := generate_from_pi_Union_Inter_le π h_le' {S},
exact indep_sets.indep hm_p (h_le a) hp (h_pi a) hS_eq_generate (h_generate a)
(h_ind.pi_Union_Inter_singleton ha_notin_S), },
refine h_indep.symm (f a) (⋂ n ∈ S, f n) (hf_m a (finset.mem_insert_self a S)) _,
have h_le_p : ∀ i ∈ S, m i ≤ m_p,
{ intros n hn,
rw [hS_eq_generate, h_generate n],
exact le_generate_from_pi_Union_Inter {S} hp_univ (set.mem_singleton _) hn, },
have h_S_f : ∀ i ∈ S, measurable_set[m_p] (f i) := λ i hi, (h_le_p i hi) (f i) (hf_m_S i hi),
exact S.measurable_set_bInter h_S_f,
end
/-- The measurable space structures generated by independent pi-systems are independent. -/
theorem Indep_sets.Indep [is_probability_measure μ] (m : ι → measurable_space Ω)
(h_le : ∀ i, m i ≤ m0) (π : ι → set (set Ω)) (h_pi : ∀ n, is_pi_system (π n))
(h_generate : ∀ i, m i = generate_from (π i)) (h_ind : Indep_sets π μ) :
Indep m μ :=
begin
-- We want to apply `Indep_sets.Indep_aux`, but `π i` does not contain `univ`, hence we replace
-- `π` with a new augmented pi-system `π'`, and prove all hypotheses for that pi-system.
let π' := λ i, insert set.univ (π i),
have h_subset : ∀ i, π i ⊆ π' i := λ i, set.subset_insert _ _,
have h_pi' : ∀ n, is_pi_system (π' n) := λ n, (h_pi n).insert_univ,
have h_univ' : ∀ i, set.univ ∈ π' i, from λ i, set.mem_insert _ _,
have h_gen' : ∀ i, m i = generate_from (π' i),
{ intros i,
rw [h_generate i, generate_from_insert_univ (π i)], },
have h_ind' : Indep_sets π' μ,
{ intros S f hfπ',
let S' := finset.filter (λ i, f i ≠ set.univ) S,
have h_mem : ∀ i ∈ S', f i ∈ π i,
{ intros i hi,
simp_rw [S', finset.mem_filter] at hi,
cases hfπ' i hi.1,
{ exact absurd h hi.2, },
{ exact h, }, },
have h_left : (⋂ i ∈ S, f i) = ⋂ i ∈ S', f i,
{ ext1 x,
simp only [set.mem_Inter, finset.mem_filter, ne.def, and_imp],
split,
{ exact λ h i hiS hif, h i hiS, },
{ intros h i hiS,
by_cases hfi_univ : f i = set.univ,
{ rw hfi_univ, exact set.mem_univ _, },
{ exact h i hiS hfi_univ, }, }, },
have h_right : ∏ i in S, μ (f i) = ∏ i in S', μ (f i),
{ rw ← finset.prod_filter_mul_prod_filter_not S (λ i, f i ≠ set.univ),
simp only [ne.def, finset.filter_congr_decidable, not_not],
suffices : ∏ x in finset.filter (λ x, f x = set.univ) S, μ (f x) = 1,
{ rw [this, mul_one], },
calc ∏ x in finset.filter (λ x, f x = set.univ) S, μ (f x)
= ∏ x in finset.filter (λ x, f x = set.univ) S, μ set.univ :
finset.prod_congr rfl (λ x hx, by { rw finset.mem_filter at hx, rw hx.2, })
... = ∏ x in finset.filter (λ x, f x = set.univ) S, 1 :
finset.prod_congr rfl (λ _ _, measure_univ)
... = 1 : finset.prod_const_one, },
rw [h_left, h_right],
exact h_ind S' h_mem, },
exact Indep_sets.Indep_aux m h_le π' h_pi' h_univ' h_gen' h_ind',
end
end from_pi_systems_to_measurable_spaces
section indep_set
/-! ### Independence of measurable sets
We prove the following equivalences on `indep_set`, for measurable sets `s, t`.
* `indep_set s t μ ↔ μ (s ∩ t) = μ s * μ t`,
* `indep_set s t μ ↔ indep_sets {s} {t} μ`.
-/
variables [measurable_space Ω] {s t : set Ω} (S T : set (set Ω))
lemma indep_set_iff_indep_sets_singleton (hs_meas : measurable_set s) (ht_meas : measurable_set t)
(μ : measure Ω . volume_tac) [is_probability_measure μ] :
indep_set s t μ ↔ indep_sets {s} {t} μ :=
⟨indep.indep_sets, λ h, indep_sets.indep
(generate_from_le (λ u hu, by rwa set.mem_singleton_iff.mp hu))
(generate_from_le (λ u hu, by rwa set.mem_singleton_iff.mp hu)) (is_pi_system.singleton s)
(is_pi_system.singleton t) rfl rfl h⟩
lemma indep_set_iff_measure_inter_eq_mul (hs_meas : measurable_set s) (ht_meas : measurable_set t)
(μ : measure Ω . volume_tac) [is_probability_measure μ] :
indep_set s t μ ↔ μ (s ∩ t) = μ s * μ t :=
(indep_set_iff_indep_sets_singleton hs_meas ht_meas μ).trans indep_sets_singleton_iff
lemma indep_sets.indep_set_of_mem (hs : s ∈ S) (ht : t ∈ T) (hs_meas : measurable_set s)
(ht_meas : measurable_set t) (μ : measure Ω . volume_tac) [is_probability_measure μ]
(h_indep : indep_sets S T μ) :
indep_set s t μ :=
(indep_set_iff_measure_inter_eq_mul hs_meas ht_meas μ).mpr (h_indep s t hs ht)
end indep_set
section indep_fun
/-! ### Independence of random variables
-/
variables {β β' γ γ' : Type*} {mΩ : measurable_space Ω} {μ : measure Ω} {f : Ω → β} {g : Ω → β'}
lemma indep_fun_iff_measure_inter_preimage_eq_mul
{mβ : measurable_space β} {mβ' : measurable_space β'} :
indep_fun f g μ
↔ ∀ s t, measurable_set s → measurable_set t
→ μ (f ⁻¹' s ∩ g ⁻¹' t) = μ (f ⁻¹' s) * μ (g ⁻¹' t) :=
begin
split; intro h,
{ refine λ s t hs ht, h (f ⁻¹' s) (g ⁻¹' t) ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩, },
{ rintros _ _ ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩, exact h s t hs ht, },
end
lemma Indep_fun_iff_measure_inter_preimage_eq_mul {ι : Type*} {β : ι → Type*}
(m : Π x, measurable_space (β x)) (f : Π i, Ω → β i) :
Indep_fun m f μ
↔ ∀ (S : finset ι) {sets : Π i : ι, set (β i)} (H : ∀ i, i ∈ S → measurable_set[m i] (sets i)),
μ (⋂ i ∈ S, (f i) ⁻¹' (sets i)) = ∏ i in S, μ ((f i) ⁻¹' (sets i)) :=
begin
refine ⟨λ h S sets h_meas, h _ (λ i hi_mem, ⟨sets i, h_meas i hi_mem, rfl⟩), _⟩,
intros h S setsΩ h_meas,
let setsβ : (Π i : ι, set (β i)) := λ i,
dite (i ∈ S) (λ hi_mem, (h_meas i hi_mem).some) (λ _, set.univ),
have h_measβ : ∀ i ∈ S, measurable_set[m i] (setsβ i),
{ intros i hi_mem,
simp_rw [setsβ, dif_pos hi_mem],
exact (h_meas i hi_mem).some_spec.1, },
have h_preim : ∀ i ∈ S, setsΩ i = (f i) ⁻¹' (setsβ i),
{ intros i hi_mem,
simp_rw [setsβ, dif_pos hi_mem],
exact (h_meas i hi_mem).some_spec.2.symm, },
have h_left_eq : μ (⋂ i ∈ S, setsΩ i) = μ (⋂ i ∈ S, (f i) ⁻¹' (setsβ i)),
{ congr' with i x,
simp only [set.mem_Inter],
split; intros h hi_mem; specialize h hi_mem,
{ rwa h_preim i hi_mem at h, },
{ rwa h_preim i hi_mem, }, },
have h_right_eq : (∏ i in S, μ (setsΩ i)) = ∏ i in S, μ ((f i) ⁻¹' (setsβ i)),
{ refine finset.prod_congr rfl (λ i hi_mem, _),
rw h_preim i hi_mem, },
rw [h_left_eq, h_right_eq],
exact h S h_measβ,
end
lemma indep_fun_iff_indep_set_preimage {mβ : measurable_space β} {mβ' : measurable_space β'}
[is_probability_measure μ] (hf : measurable f) (hg : measurable g) :
indep_fun f g μ ↔ ∀ s t, measurable_set s → measurable_set t → indep_set (f ⁻¹' s) (g ⁻¹' t) μ :=
begin
refine indep_fun_iff_measure_inter_preimage_eq_mul.trans _,
split; intros h s t hs ht; specialize h s t hs ht,
{ rwa indep_set_iff_measure_inter_eq_mul (hf hs) (hg ht) μ, },
{ rwa ← indep_set_iff_measure_inter_eq_mul (hf hs) (hg ht) μ, },
end
lemma indep_fun.symm {mβ : measurable_space β} {f g : Ω → β} (hfg : indep_fun f g μ) :
indep_fun g f μ :=
hfg.symm
lemma indep_fun.ae_eq {mβ : measurable_space β} {f g f' g' : Ω → β}
(hfg : indep_fun f g μ) (hf : f =ᵐ[μ] f') (hg : g =ᵐ[μ] g') :
indep_fun f' g' μ :=
begin
rintro _ _ ⟨A, hA, rfl⟩ ⟨B, hB, rfl⟩,
have h1 : f ⁻¹' A =ᵐ[μ] f' ⁻¹' A := hf.fun_comp A,
have h2 : g ⁻¹' B =ᵐ[μ] g' ⁻¹' B := hg.fun_comp B,
rw [←measure_congr h1, ←measure_congr h2, ←measure_congr (h1.inter h2)],
exact hfg _ _ ⟨_, hA, rfl⟩ ⟨_, hB, rfl⟩
end
lemma indep_fun.comp {mβ : measurable_space β} {mβ' : measurable_space β'}
{mγ : measurable_space γ} {mγ' : measurable_space γ'} {φ : β → γ} {ψ : β' → γ'}
(hfg : indep_fun f g μ) (hφ : measurable φ) (hψ : measurable ψ) :
indep_fun (φ ∘ f) (ψ ∘ g) μ :=
begin
rintro _ _ ⟨A, hA, rfl⟩ ⟨B, hB, rfl⟩,
apply hfg,
{ exact ⟨φ ⁻¹' A, hφ hA, set.preimage_comp.symm⟩ },
{ exact ⟨ψ ⁻¹' B, hψ hB, set.preimage_comp.symm⟩ }
end
/-- If `f` is a family of mutually independent random variables (`Indep_fun m f μ`) and `S, T` are
two disjoint finite index sets, then the tuple formed by `f i` for `i ∈ S` is independent of the
tuple `(f i)_i` for `i ∈ T`. -/
lemma Indep_fun.indep_fun_finset [is_probability_measure μ]
{ι : Type*} {β : ι → Type*} {m : Π i, measurable_space (β i)}
{f : Π i, Ω → β i} (S T : finset ι) (hST : disjoint S T) (hf_Indep : Indep_fun m f μ)
(hf_meas : ∀ i, measurable (f i)) :
indep_fun (λ a (i : S), f i a) (λ a (i : T), f i a) μ :=
begin
-- We introduce π-systems, build from the π-system of boxes which generates `measurable_space.pi`.
let πSβ := (set.pi (set.univ : set S) ''
(set.pi (set.univ : set S) (λ i, {s : set (β i) | measurable_set[m i] s}))),
let πS := {s : set Ω | ∃ t ∈ πSβ, (λ a (i : S), f i a) ⁻¹' t = s},
have hπS_pi : is_pi_system πS := is_pi_system_pi.comap (λ a i, f i a),
have hπS_gen : measurable_space.pi.comap (λ a (i : S), f i a) = generate_from πS,
{ rw [generate_from_pi.symm, comap_generate_from],
{ congr' with s,
simp only [set.mem_image, set.mem_set_of_eq, exists_prop], },
{ apply_instance } },
let πTβ := (set.pi (set.univ : set T) ''
(set.pi (set.univ : set T) (λ i, {s : set (β i) | measurable_set[m i] s}))),
let πT := {s : set Ω | ∃ t ∈ πTβ, (λ a (i : T), f i a) ⁻¹' t = s},
have hπT_pi : is_pi_system πT := is_pi_system_pi.comap (λ a i, f i a),
have hπT_gen : measurable_space.pi.comap (λ a (i : T), f i a) = generate_from πT,
{ rw [generate_from_pi.symm, comap_generate_from],
{ congr' with s,
simp only [set.mem_image, set.mem_set_of_eq, exists_prop], },
{ apply_instance } },
-- To prove independence, we prove independence of the generating π-systems.
refine indep_sets.indep (measurable.comap_le (measurable_pi_iff.mpr (λ i, hf_meas i)))
(measurable.comap_le (measurable_pi_iff.mpr (λ i, hf_meas i))) hπS_pi hπT_pi hπS_gen hπT_gen _,
rintros _ _ ⟨s, ⟨sets_s, hs1, hs2⟩, rfl⟩ ⟨t, ⟨sets_t, ht1, ht2⟩, rfl⟩,
simp only [set.mem_univ_pi, set.mem_set_of_eq] at hs1 ht1,
rw [← hs2, ← ht2],
let sets_s' : (Π i : ι, set (β i)) := λ i, dite (i ∈ S) (λ hi, sets_s ⟨i, hi⟩) (λ _, set.univ),
have h_sets_s'_eq : ∀ {i} (hi : i ∈ S), sets_s' i = sets_s ⟨i, hi⟩,
{ intros i hi, simp_rw [sets_s', dif_pos hi], },
have h_sets_s'_univ : ∀ {i} (hi : i ∈ T), sets_s' i = set.univ,
{ intros i hi, simp_rw [sets_s', dif_neg (finset.disjoint_right.mp hST hi)], },
let sets_t' : (Π i : ι, set (β i)) := λ i, dite (i ∈ T) (λ hi, sets_t ⟨i, hi⟩) (λ _, set.univ),
have h_sets_t'_univ : ∀ {i} (hi : i ∈ S), sets_t' i = set.univ,
{ intros i hi, simp_rw [sets_t', dif_neg (finset.disjoint_left.mp hST hi)], },
have h_meas_s' : ∀ i ∈ S, measurable_set (sets_s' i),
{ intros i hi, rw h_sets_s'_eq hi, exact hs1 _, },
have h_meas_t' : ∀ i ∈ T, measurable_set (sets_t' i),
{ intros i hi, simp_rw [sets_t', dif_pos hi], exact ht1 _, },
have h_eq_inter_S : (λ (ω : Ω) (i : ↥S), f ↑i ω) ⁻¹' set.pi set.univ sets_s
= ⋂ i ∈ S, (f i) ⁻¹' (sets_s' i),
{ ext1 x,
simp only [set.mem_preimage, set.mem_univ_pi, set.mem_Inter],
split; intro h,
{ intros i hi, rw [h_sets_s'_eq hi], exact h ⟨i, hi⟩, },
{ rintros ⟨i, hi⟩, specialize h i hi, rw [h_sets_s'_eq hi] at h, exact h, }, },
have h_eq_inter_T : (λ (ω : Ω) (i : ↥T), f ↑i ω) ⁻¹' set.pi set.univ sets_t
= ⋂ i ∈ T, (f i) ⁻¹' (sets_t' i),
{ ext1 x,
simp only [set.mem_preimage, set.mem_univ_pi, set.mem_Inter],
split; intro h,
{ intros i hi, simp_rw [sets_t', dif_pos hi], exact h ⟨i, hi⟩, },
{ rintros ⟨i, hi⟩, specialize h i hi, simp_rw [sets_t', dif_pos hi] at h, exact h, }, },
rw Indep_fun_iff_measure_inter_preimage_eq_mul at hf_Indep,
rw [h_eq_inter_S, h_eq_inter_T, hf_Indep S h_meas_s', hf_Indep T h_meas_t'],
have h_Inter_inter : (⋂ i ∈ S, (f i) ⁻¹' (sets_s' i)) ∩ (⋂ i ∈ T, (f i) ⁻¹' (sets_t' i))
= ⋂ i ∈ (S ∪ T), (f i) ⁻¹' (sets_s' i ∩ sets_t' i),
{ ext1 x,
simp only [set.mem_inter_eq, set.mem_Inter, set.mem_preimage, finset.mem_union],
split; intro h,
{ intros i hi,
cases hi,
{ rw h_sets_t'_univ hi, exact ⟨h.1 i hi, set.mem_univ _⟩, },
{ rw h_sets_s'_univ hi, exact ⟨set.mem_univ _, h.2 i hi⟩, }, },
{ exact ⟨λ i hi, (h i (or.inl hi)).1, λ i hi, (h i (or.inr hi)).2⟩, }, },
rw [h_Inter_inter, hf_Indep (S ∪ T)],
swap, { intros i hi_mem,
rw finset.mem_union at hi_mem,
cases hi_mem,
{ rw [h_sets_t'_univ hi_mem, set.inter_univ], exact h_meas_s' i hi_mem, },
{ rw [h_sets_s'_univ hi_mem, set.univ_inter], exact h_meas_t' i hi_mem, }, },
rw finset.prod_union hST,
congr' 1,
{ refine finset.prod_congr rfl (λ i hi, _),
rw [h_sets_t'_univ hi, set.inter_univ], },
{ refine finset.prod_congr rfl (λ i hi, _),
rw [h_sets_s'_univ hi, set.univ_inter], },
end
lemma Indep_fun.indep_fun_prod [is_probability_measure μ]
{ι : Type*} {β : ι → Type*} {m : Π i, measurable_space (β i)}
{f : Π i, Ω → β i} (hf_Indep : Indep_fun m f μ) (hf_meas : ∀ i, measurable (f i))
(i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
indep_fun (λ a, (f i a, f j a)) (f k) μ :=
begin
classical,
have h_right : f k = (λ p : (Π j : ({k} : finset ι), β j), p ⟨k, finset.mem_singleton_self k⟩)
∘ (λ a (j : ({k} : finset ι)), f j a) := rfl,
have h_meas_right : measurable
(λ p : (Π j : ({k} : finset ι), β j), p ⟨k, finset.mem_singleton_self k⟩),
from measurable_pi_apply ⟨k, finset.mem_singleton_self k⟩,
let s : finset ι := {i, j},
have h_left : (λ ω, (f i ω, f j ω))
= (λ p : (Π l : s, β l), (p ⟨i, finset.mem_insert_self i _⟩,
p ⟨j, finset.mem_insert_of_mem (finset.mem_singleton_self _)⟩))
∘ (λ a (j : s), f j a),
{ ext1 a,
simp only [prod.mk.inj_iff],
split; refl, },
have h_meas_left : measurable (λ p : (Π l : s, β l), (p ⟨i, finset.mem_insert_self i _⟩,
p ⟨j, finset.mem_insert_of_mem (finset.mem_singleton_self _)⟩)),
from measurable.prod (measurable_pi_apply ⟨i, finset.mem_insert_self i {j}⟩)
(measurable_pi_apply ⟨j, finset.mem_insert_of_mem (finset.mem_singleton_self j)⟩),
rw [h_left, h_right],
refine (hf_Indep.indep_fun_finset s {k} _ hf_meas).comp h_meas_left h_meas_right,
intros x hx,
simp only [finset.inf_eq_inter, finset.mem_inter, finset.mem_insert, finset.mem_singleton] at hx,
simp only [finset.bot_eq_empty, finset.not_mem_empty],
cases hx.1 with hx_eq hx_eq; rw hx_eq at hx,
{ exact hik hx.2, },
{ exact hjk hx.2, },
end
@[to_additive]
lemma Indep_fun.mul [is_probability_measure μ]
{ι : Type*} {β : Type*} {m : measurable_space β} [has_mul β] [has_measurable_mul₂ β]
{f : ι → Ω → β} (hf_Indep : Indep_fun (λ _, m) f μ) (hf_meas : ∀ i, measurable (f i))
(i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
indep_fun (f i * f j) (f k) μ :=
begin
have : indep_fun (λ ω, (f i ω, f j ω)) (f k) μ := hf_Indep.indep_fun_prod hf_meas i j k hik hjk,
change indep_fun ((λ p : β × β, p.fst * p.snd) ∘ (λ ω, (f i ω, f j ω))) (id ∘ (f k)) μ,
exact indep_fun.comp this (measurable_fst.mul measurable_snd) measurable_id,
end
@[to_additive]
lemma Indep_fun.indep_fun_finset_prod_of_not_mem [is_probability_measure μ]
{ι : Type*} {β : Type*} {m : measurable_space β} [comm_monoid β] [has_measurable_mul₂ β]
{f : ι → Ω → β} (hf_Indep : Indep_fun (λ _, m) f μ) (hf_meas : ∀ i, measurable (f i))
{s : finset ι} {i : ι} (hi : i ∉ s) :
indep_fun (∏ j in s, f j) (f i) μ :=
begin
classical,
have h_right : f i = (λ p : (Π j : ({i} : finset ι), β), p ⟨i, finset.mem_singleton_self i⟩)
∘ (λ a (j : ({i} : finset ι)), f j a) := rfl,
have h_meas_right : measurable
(λ p : (Π j : ({i} : finset ι), β), p ⟨i, finset.mem_singleton_self i⟩),
from measurable_pi_apply ⟨i, finset.mem_singleton_self i⟩,
have h_left : (∏ j in s, f j) = (λ p : (Π j : s, β), ∏ j, p j) ∘ (λ a (j : s), f j a),
{ ext1 a,
simp only [function.comp_app],
have : (∏ (j : ↥s), f ↑j a) = (∏ (j : ↥s), f ↑j) a, by rw finset.prod_apply,
rw [this, finset.prod_coe_sort], },
have h_meas_left : measurable (λ p : (Π j : s, β), ∏ j, p j),
from finset.univ.measurable_prod (λ (j : ↥s) (H : j ∈ finset.univ), measurable_pi_apply j),
rw [h_left, h_right],
exact (hf_Indep.indep_fun_finset s {i} (finset.disjoint_singleton_left.mpr hi).symm hf_meas).comp
h_meas_left h_meas_right,
end
@[to_additive]
lemma Indep_fun.indep_fun_prod_range_succ [is_probability_measure μ]
{β : Type*} {m : measurable_space β} [comm_monoid β] [has_measurable_mul₂ β]
{f : ℕ → Ω → β} (hf_Indep : Indep_fun (λ _, m) f μ) (hf_meas : ∀ i, measurable (f i))
(n : ℕ) :
indep_fun (∏ j in finset.range n, f j) (f n) μ :=
hf_Indep.indep_fun_finset_prod_of_not_mem hf_meas finset.not_mem_range_self
end indep_fun
end probability_theory
|
058e8ea58fae10265eaede6a54506bf9d3630dca | cf39355caa609c0f33405126beee2739aa3cb77e | /library/init/data/nat/gcd.lean | 54d8d1cbf92666eb6b897b99be34ac9650f8977c | [
"Apache-2.0"
] | permissive | leanprover-community/lean | 12b87f69d92e614daea8bcc9d4de9a9ace089d0e | cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0 | refs/heads/master | 1,687,508,156,644 | 1,684,951,104,000 | 1,684,951,104,000 | 169,960,991 | 457 | 107 | Apache-2.0 | 1,686,744,372,000 | 1,549,790,268,000 | C++ | UTF-8 | Lean | false | false | 1,649 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro
-/
prelude
import init.data.nat.lemmas init.meta.well_founded_tactics
/-!
# Definitions and properties of gcd, lcm, and coprime
-/
open well_founded
namespace nat
/-! gcd -/
def gcd : nat → nat → nat
| 0 y := y
| (succ x) y := have y % succ x < succ x, from mod_lt _ $ succ_pos _,
gcd (y % succ x) (succ x)
@[simp] theorem gcd_zero_left (x : nat) : gcd 0 x = x := by simp [gcd]
@[simp] theorem gcd_succ (x y : nat) : gcd (succ x) y = gcd (y % succ x) (succ x) :=
by simp [gcd]
@[simp] theorem gcd_one_left (n : ℕ) : gcd 1 n = 1 := by simp [gcd]
theorem gcd_def (x y : ℕ) : gcd x y = if x = 0 then y else gcd (y % x) x :=
by cases x; simp [gcd, succ_ne_zero]
@[simp] theorem gcd_self (n : ℕ) : gcd n n = n :=
by cases n; simp [gcd, mod_self]
@[simp] theorem gcd_zero_right (n : ℕ) : gcd n 0 = n :=
by cases n; simp [gcd]
theorem gcd_rec (m n : ℕ) : gcd m n = gcd (n % m) m :=
by cases m; simp [gcd]
@[elab_as_eliminator]
theorem gcd.induction {P : ℕ → ℕ → Prop}
(m n : ℕ)
(H0 : ∀n, P 0 n)
(H1 : ∀m n, 0 < m → P (n % m) m → P m n) :
P m n :=
@induction _ _ lt_wf (λm, ∀n, P m n) m (λk IH,
by {induction k with k ih, exact H0,
exact λn, H1 _ _ (succ_pos _) (IH _ (mod_lt _ (succ_pos _)) _)}) n
def lcm (m n : ℕ) : ℕ := m * n / (gcd m n)
@[reducible] def coprime (m n : ℕ) : Prop := gcd m n = 1
end nat
|
5c00062169c6a69d045802cf3adf65891e30d681 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/analysis/inner_product_space/gram_schmidt_ortho.lean | 1b546aeab8cec08d42952a9cc31c5fa377a28e99 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 17,601 | lean | /-
Copyright (c) 2022 Jiale Miao. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jiale Miao, Kevin Buzzard, Alexander Bentkamp
-/
import analysis.inner_product_space.pi_L2
import linear_algebra.matrix.block
/-!
# Gram-Schmidt Orthogonalization and Orthonormalization
In this file we introduce Gram-Schmidt Orthogonalization and Orthonormalization.
The Gram-Schmidt process takes a set of vectors as input
and outputs a set of orthogonal vectors which have the same span.
## Main results
- `gram_schmidt` : the Gram-Schmidt process
- `gram_schmidt_orthogonal` :
`gram_schmidt` produces an orthogonal system of vectors.
- `span_gram_schmidt` :
`gram_schmidt` preserves span of vectors.
- `gram_schmidt_ne_zero` :
If the input vectors of `gram_schmidt` are linearly independent,
then the output vectors are non-zero.
- `gram_schmidt_basis` :
The basis produced by the Gram-Schmidt process when given a basis as input.
- `gram_schmidt_normed` :
the normalized `gram_schmidt` (i.e each vector in `gram_schmidt_normed` has unit length.)
- `gram_schmidt_orthornormal` :
`gram_schmidt_normed` produces an orthornormal system of vectors.
- `gram_schmidt_orthonormal_basis`: orthonormal basis constructed by the Gram-Schmidt process from
an indexed set of vectors of the right size
-/
open_locale big_operators
open finset submodule finite_dimensional
variables (𝕜 : Type*) {E : Type*} [is_R_or_C 𝕜] [inner_product_space 𝕜 E]
variables {ι : Type*} [linear_order ι] [locally_finite_order_bot ι] [is_well_order ι (<)]
local attribute [instance] is_well_order.to_has_well_founded
local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y
/-- The Gram-Schmidt process takes a set of vectors as input
and outputs a set of orthogonal vectors which have the same span. -/
noncomputable def gram_schmidt (f : ι → E) : ι → E
| n := f n - ∑ i : Iio n, orthogonal_projection (𝕜 ∙ gram_schmidt i) (f n)
using_well_founded { dec_tac := `[exact mem_Iio.1 i.2] }
/-- This lemma uses `∑ i in` instead of `∑ i :`.-/
lemma gram_schmidt_def (f : ι → E) (n : ι):
gram_schmidt 𝕜 f n = f n - ∑ i in Iio n,
orthogonal_projection (𝕜 ∙ gram_schmidt 𝕜 f i) (f n) :=
by { rw [←sum_attach, attach_eq_univ, gram_schmidt], refl }
lemma gram_schmidt_def' (f : ι → E) (n : ι):
f n = gram_schmidt 𝕜 f n + ∑ i in Iio n,
orthogonal_projection (𝕜 ∙ gram_schmidt 𝕜 f i) (f n) :=
by rw [gram_schmidt_def, sub_add_cancel]
lemma gram_schmidt_def'' (f : ι → E) (n : ι):
f n = gram_schmidt 𝕜 f n
+ ∑ i in Iio n, (⟪gram_schmidt 𝕜 f i, f n⟫ / ‖gram_schmidt 𝕜 f i‖ ^ 2) • gram_schmidt 𝕜 f i :=
begin
convert gram_schmidt_def' 𝕜 f n,
ext i,
rw orthogonal_projection_singleton,
end
@[simp] lemma gram_schmidt_zero {ι : Type*} [linear_order ι] [locally_finite_order ι]
[order_bot ι] [is_well_order ι (<)] (f : ι → E) : gram_schmidt 𝕜 f ⊥ = f ⊥ :=
by rw [gram_schmidt_def, Iio_eq_Ico, finset.Ico_self, finset.sum_empty, sub_zero]
/-- **Gram-Schmidt Orthogonalisation**:
`gram_schmidt` produces an orthogonal system of vectors. -/
theorem gram_schmidt_orthogonal (f : ι → E) {a b : ι} (h₀ : a ≠ b) :
⟪gram_schmidt 𝕜 f a, gram_schmidt 𝕜 f b⟫ = 0 :=
begin
suffices : ∀ a b : ι, a < b → ⟪gram_schmidt 𝕜 f a, gram_schmidt 𝕜 f b⟫ = 0,
{ cases h₀.lt_or_lt with ha hb,
{ exact this _ _ ha, },
{ rw inner_eq_zero_sym,
exact this _ _ hb, }, },
clear h₀ a b,
intros a b h₀,
revert a,
apply well_founded.induction (@is_well_founded.wf ι (<) _) b,
intros b ih a h₀,
simp only [gram_schmidt_def 𝕜 f b, inner_sub_right, inner_sum,
orthogonal_projection_singleton, inner_smul_right],
rw finset.sum_eq_single_of_mem a (finset.mem_Iio.mpr h₀),
{ by_cases h : gram_schmidt 𝕜 f a = 0,
{ simp only [h, inner_zero_left, zero_div, zero_mul, sub_zero], },
{ rw [← inner_self_eq_norm_sq_to_K, div_mul_cancel, sub_self],
rwa [ne.def, inner_self_eq_zero], }, },
simp_intros i hi hia only [finset.mem_range],
simp only [mul_eq_zero, div_eq_zero_iff, inner_self_eq_zero],
right,
cases hia.lt_or_lt with hia₁ hia₂,
{ rw inner_eq_zero_sym,
exact ih a h₀ i hia₁ },
{ exact ih i (mem_Iio.1 hi) a hia₂ }
end
/-- This is another version of `gram_schmidt_orthogonal` using `pairwise` instead. -/
theorem gram_schmidt_pairwise_orthogonal (f : ι → E) :
pairwise (λ a b, ⟪gram_schmidt 𝕜 f a, gram_schmidt 𝕜 f b⟫ = 0) :=
λ a b, gram_schmidt_orthogonal 𝕜 f
lemma gram_schmidt_inv_triangular (v : ι → E) {i j : ι} (hij : i < j) :
⟪gram_schmidt 𝕜 v j, v i⟫ = 0 :=
begin
rw gram_schmidt_def'' 𝕜 v,
simp only [inner_add_right, inner_sum, inner_smul_right],
set b : ι → E := gram_schmidt 𝕜 v,
convert zero_add (0:𝕜),
{ exact gram_schmidt_orthogonal 𝕜 v hij.ne' },
apply finset.sum_eq_zero,
rintros k hki',
have hki : k < i := by simpa using hki',
have : ⟪b j, b k⟫ = 0 := gram_schmidt_orthogonal 𝕜 v (hki.trans hij).ne',
simp [this],
end
open submodule set order
lemma mem_span_gram_schmidt (f : ι → E) {i j : ι} (hij : i ≤ j) :
f i ∈ span 𝕜 (gram_schmidt 𝕜 f '' Iic j) :=
begin
rw [gram_schmidt_def' 𝕜 f i],
simp_rw orthogonal_projection_singleton,
exact submodule.add_mem _ (subset_span $ mem_image_of_mem _ hij)
(submodule.sum_mem _ $ λ k hk, smul_mem (span 𝕜 (gram_schmidt 𝕜 f '' Iic j)) _ $
subset_span $ mem_image_of_mem (gram_schmidt 𝕜 f) $ (finset.mem_Iio.1 hk).le.trans hij),
end
lemma gram_schmidt_mem_span (f : ι → E) :
∀ {j i}, i ≤ j → gram_schmidt 𝕜 f i ∈ span 𝕜 (f '' Iic j)
| j := λ i hij,
begin
rw [gram_schmidt_def 𝕜 f i],
simp_rw orthogonal_projection_singleton,
refine submodule.sub_mem _ (subset_span (mem_image_of_mem _ hij))
(submodule.sum_mem _ $ λ k hk, _),
let hkj : k < j := (finset.mem_Iio.1 hk).trans_le hij,
exact smul_mem _ _ (span_mono (image_subset f $ Iic_subset_Iic.2 hkj.le) $
gram_schmidt_mem_span le_rfl),
end
using_well_founded { dec_tac := `[assumption] }
lemma span_gram_schmidt_Iic (f : ι → E) (c : ι) :
span 𝕜 (gram_schmidt 𝕜 f '' Iic c) = span 𝕜 (f '' Iic c) :=
span_eq_span (set.image_subset_iff.2 $ λ i, gram_schmidt_mem_span _ _) $
set.image_subset_iff.2 $ λ i, mem_span_gram_schmidt _ _
lemma span_gram_schmidt_Iio (f : ι → E) (c : ι) :
span 𝕜 (gram_schmidt 𝕜 f '' Iio c) = span 𝕜 (f '' Iio c) :=
span_eq_span
(set.image_subset_iff.2 $ λ i hi, span_mono (image_subset _ $ Iic_subset_Iio.2 hi) $
gram_schmidt_mem_span _ _ le_rfl) $
set.image_subset_iff.2 $ λ i hi, span_mono (image_subset _ $ Iic_subset_Iio.2 hi) $
mem_span_gram_schmidt _ _ le_rfl
/-- `gram_schmidt` preserves span of vectors. -/
lemma span_gram_schmidt (f : ι → E) : span 𝕜 (range (gram_schmidt 𝕜 f)) = span 𝕜 (range f) :=
span_eq_span (range_subset_iff.2 $ λ i, span_mono (image_subset_range _ _) $
gram_schmidt_mem_span _ _ le_rfl) $
range_subset_iff.2 $ λ i, span_mono (image_subset_range _ _) $ mem_span_gram_schmidt _ _ le_rfl
lemma gram_schmidt_of_orthogonal {f : ι → E} (hf : pairwise (λ i j, ⟪f i, f j⟫ = 0)) :
gram_schmidt 𝕜 f = f :=
begin
ext i,
rw gram_schmidt_def,
transitivity f i - 0,
{ congr,
apply finset.sum_eq_zero,
intros j hj,
rw coe_eq_zero,
suffices : span 𝕜 (f '' set.Iic j) ≤ (𝕜 ∙ f i)ᗮ,
{ apply orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero,
apply mem_orthogonal_singleton_of_inner_left,
apply inner_right_of_mem_orthogonal_singleton,
exact this (gram_schmidt_mem_span 𝕜 f (le_refl j)) },
rw span_le,
rintros - ⟨k, hk, rfl⟩,
apply mem_orthogonal_singleton_of_inner_left,
apply hf,
refine (lt_of_le_of_lt hk _).ne,
simpa using hj },
{ simp },
end
variables {𝕜}
lemma gram_schmidt_ne_zero_coe
{f : ι → E} (n : ι) (h₀ : linear_independent 𝕜 (f ∘ (coe : set.Iic n → ι))) :
gram_schmidt 𝕜 f n ≠ 0 :=
begin
by_contra h,
have h₁ : f n ∈ span 𝕜 (f '' Iio n),
{ rw [← span_gram_schmidt_Iio 𝕜 f n, gram_schmidt_def' _ f, h, zero_add],
apply submodule.sum_mem _ _,
simp_intros a ha only [finset.mem_Ico],
simp only [set.mem_image, set.mem_Iio, orthogonal_projection_singleton],
apply submodule.smul_mem _ _ _,
rw finset.mem_Iio at ha,
refine subset_span ⟨a, ha, by refl⟩ },
have h₂ : (f ∘ (coe : set.Iic n → ι)) ⟨n, le_refl n⟩
∈ span 𝕜 (f ∘ (coe : set.Iic n → ι) '' Iio ⟨n, le_refl n⟩),
{ rw [image_comp],
convert h₁ using 3,
ext i,
simpa using @le_of_lt _ _ i n },
apply linear_independent.not_mem_span_image h₀ _ h₂,
simp only [set.mem_Iio, lt_self_iff_false, not_false_iff]
end
/-- If the input vectors of `gram_schmidt` are linearly independent,
then the output vectors are non-zero. -/
lemma gram_schmidt_ne_zero {f : ι → E} (n : ι) (h₀ : linear_independent 𝕜 f) :
gram_schmidt 𝕜 f n ≠ 0 :=
gram_schmidt_ne_zero_coe _ (linear_independent.comp h₀ _ subtype.coe_injective)
/-- `gram_schmidt` produces a triangular matrix of vectors when given a basis. -/
lemma gram_schmidt_triangular {i j : ι} (hij : i < j) (b : basis ι 𝕜 E) :
b.repr (gram_schmidt 𝕜 b i) j = 0 :=
begin
have : gram_schmidt 𝕜 b i ∈ span 𝕜 (gram_schmidt 𝕜 b '' set.Iio j),
from subset_span ((set.mem_image _ _ _).2 ⟨i, hij, rfl⟩),
have : gram_schmidt 𝕜 b i ∈ span 𝕜 (b '' set.Iio j),
by rwa [← span_gram_schmidt_Iio 𝕜 b j],
have : ↑(((b.repr) (gram_schmidt 𝕜 b i)).support) ⊆ set.Iio j,
from basis.repr_support_subset_of_mem_span b (set.Iio j) this,
exact (finsupp.mem_supported' _ _).1
((finsupp.mem_supported 𝕜 _).2 this) j set.not_mem_Iio_self,
end
/-- `gram_schmidt` produces linearly independent vectors when given linearly independent vectors. -/
lemma gram_schmidt_linear_independent {f : ι → E} (h₀ : linear_independent 𝕜 f) :
linear_independent 𝕜 (gram_schmidt 𝕜 f) :=
linear_independent_of_ne_zero_of_inner_eq_zero
(λ i, gram_schmidt_ne_zero _ h₀) (λ i j, gram_schmidt_orthogonal 𝕜 f)
/-- When given a basis, `gram_schmidt` produces a basis. -/
noncomputable def gram_schmidt_basis (b : basis ι 𝕜 E) : basis ι 𝕜 E :=
basis.mk
(gram_schmidt_linear_independent b.linear_independent)
((span_gram_schmidt 𝕜 b).trans b.span_eq).ge
lemma coe_gram_schmidt_basis (b : basis ι 𝕜 E) :
(gram_schmidt_basis b : ι → E) = gram_schmidt 𝕜 b := basis.coe_mk _ _
variables (𝕜)
/-- the normalized `gram_schmidt`
(i.e each vector in `gram_schmidt_normed` has unit length.) -/
noncomputable def gram_schmidt_normed (f : ι → E) (n : ι) : E :=
(‖gram_schmidt 𝕜 f n‖ : 𝕜)⁻¹ • (gram_schmidt 𝕜 f n)
variables {𝕜}
lemma gram_schmidt_normed_unit_length_coe
{f : ι → E} (n : ι) (h₀ : linear_independent 𝕜 (f ∘ (coe : set.Iic n → ι))) :
‖gram_schmidt_normed 𝕜 f n‖ = 1 :=
by simp only [gram_schmidt_ne_zero_coe n h₀,
gram_schmidt_normed, norm_smul_inv_norm, ne.def, not_false_iff]
lemma gram_schmidt_normed_unit_length {f : ι → E} (n : ι) (h₀ : linear_independent 𝕜 f) :
‖gram_schmidt_normed 𝕜 f n‖ = 1 :=
gram_schmidt_normed_unit_length_coe _ (linear_independent.comp h₀ _ subtype.coe_injective)
lemma gram_schmidt_normed_unit_length' {f : ι → E} {n : ι} (hn : gram_schmidt_normed 𝕜 f n ≠ 0) :
‖gram_schmidt_normed 𝕜 f n‖ = 1 :=
begin
rw gram_schmidt_normed at *,
rw [norm_smul_inv_norm],
simpa using hn,
end
/-- **Gram-Schmidt Orthonormalization**:
`gram_schmidt_normed` applied to a linearly independent set of vectors produces an orthornormal
system of vectors. -/
theorem gram_schmidt_orthonormal {f : ι → E} (h₀ : linear_independent 𝕜 f) :
orthonormal 𝕜 (gram_schmidt_normed 𝕜 f) :=
begin
unfold orthonormal,
split,
{ simp only [gram_schmidt_normed_unit_length, h₀, eq_self_iff_true, implies_true_iff], },
{ intros i j hij,
simp only [gram_schmidt_normed, inner_smul_left, inner_smul_right, is_R_or_C.conj_inv,
is_R_or_C.conj_of_real, mul_eq_zero, inv_eq_zero, is_R_or_C.of_real_eq_zero, norm_eq_zero],
repeat { right },
exact gram_schmidt_orthogonal 𝕜 f hij }
end
/-- **Gram-Schmidt Orthonormalization**:
`gram_schmidt_normed` produces an orthornormal system of vectors after removing the vectors which
become zero in the process. -/
lemma gram_schmidt_orthonormal' (f : ι → E) :
orthonormal 𝕜 (λ i : {i | gram_schmidt_normed 𝕜 f i ≠ 0}, gram_schmidt_normed 𝕜 f i) :=
begin
refine ⟨λ i, gram_schmidt_normed_unit_length' i.prop, _⟩,
rintros i j (hij : ¬ _),
rw subtype.ext_iff at hij,
simp [gram_schmidt_normed, inner_smul_left, inner_smul_right, gram_schmidt_orthogonal 𝕜 f hij],
end
lemma span_gram_schmidt_normed (f : ι → E) (s : set ι) :
span 𝕜 (gram_schmidt_normed 𝕜 f '' s) = span 𝕜 (gram_schmidt 𝕜 f '' s) :=
begin
refine span_eq_span (set.image_subset_iff.2 $ λ i hi, smul_mem _ _ $ subset_span $
mem_image_of_mem _ hi)
(set.image_subset_iff.2 $ λ i hi, span_mono (image_subset _ $ singleton_subset_set_iff.2 hi) _),
simp only [coe_singleton, set.image_singleton],
by_cases h : gram_schmidt 𝕜 f i = 0,
{ simp [h] },
{ refine mem_span_singleton.2 ⟨‖gram_schmidt 𝕜 f i‖, smul_inv_smul₀ _ _⟩,
exact_mod_cast (norm_ne_zero_iff.2 h) }
end
lemma span_gram_schmidt_normed_range (f : ι → E) :
span 𝕜 (range (gram_schmidt_normed 𝕜 f)) = span 𝕜 (range (gram_schmidt 𝕜 f)) :=
by simpa only [image_univ.symm] using span_gram_schmidt_normed f univ
section orthonormal_basis
variables [fintype ι] [finite_dimensional 𝕜 E] (h : finrank 𝕜 E = fintype.card ι) (f : ι → E)
include h
/-- Given an indexed family `f : ι → E` of vectors in an inner product space `E`, for which the
size of the index set is the dimension of `E`, produce an orthonormal basis for `E` which agrees
with the orthonormal set produced by the Gram-Schmidt orthonormalization process on the elements of
`ι` for which this process gives a nonzero number. -/
noncomputable def gram_schmidt_orthonormal_basis : orthonormal_basis ι 𝕜 E :=
((gram_schmidt_orthonormal' f).exists_orthonormal_basis_extension_of_card_eq h).some
lemma gram_schmidt_orthonormal_basis_apply {f : ι → E} {i : ι}
(hi : gram_schmidt_normed 𝕜 f i ≠ 0) :
gram_schmidt_orthonormal_basis h f i = gram_schmidt_normed 𝕜 f i :=
((gram_schmidt_orthonormal' f).exists_orthonormal_basis_extension_of_card_eq h).some_spec i hi
lemma gram_schmidt_orthonormal_basis_apply_of_orthogonal {f : ι → E}
(hf : pairwise (λ i j, ⟪f i, f j⟫ = 0)) {i : ι} (hi : f i ≠ 0) :
gram_schmidt_orthonormal_basis h f i = (‖f i‖⁻¹ : 𝕜) • f i :=
begin
have H : gram_schmidt_normed 𝕜 f i = (‖f i‖⁻¹ : 𝕜) • f i,
{ rw [gram_schmidt_normed, gram_schmidt_of_orthogonal 𝕜 hf] },
rw [gram_schmidt_orthonormal_basis_apply h, H],
simpa [H] using hi,
end
lemma inner_gram_schmidt_orthonormal_basis_eq_zero {f : ι → E} {i : ι}
(hi : gram_schmidt_normed 𝕜 f i = 0) (j : ι) :
⟪gram_schmidt_orthonormal_basis h f i, f j⟫ = 0 :=
begin
apply inner_right_of_mem_orthogonal_singleton,
suffices : span 𝕜 (gram_schmidt_normed 𝕜 f '' Iic j)
≤ (𝕜 ∙ gram_schmidt_orthonormal_basis h f i)ᗮ,
{ apply this,
rw span_gram_schmidt_normed,
simpa using mem_span_gram_schmidt 𝕜 f (le_refl j) },
rw span_le,
rintros - ⟨k, -, rfl⟩,
apply mem_orthogonal_singleton_of_inner_left,
by_cases hk : gram_schmidt_normed 𝕜 f k = 0,
{ simp [hk] },
rw ← gram_schmidt_orthonormal_basis_apply h hk,
have : k ≠ i,
{ rintros rfl,
exact hk hi },
exact (gram_schmidt_orthonormal_basis h f).orthonormal.2 this,
end
lemma gram_schmidt_orthonormal_basis_inv_triangular {i j : ι} (hij : i < j) :
⟪gram_schmidt_orthonormal_basis h f j, f i⟫ = 0 :=
begin
by_cases hi : gram_schmidt_normed 𝕜 f j = 0,
{ rw inner_gram_schmidt_orthonormal_basis_eq_zero h hi },
{ simp [gram_schmidt_orthonormal_basis_apply h hi, gram_schmidt_normed, inner_smul_left,
gram_schmidt_inv_triangular 𝕜 f hij] }
end
lemma gram_schmidt_orthonormal_basis_inv_triangular' {i j : ι} (hij : i < j) :
(gram_schmidt_orthonormal_basis h f).repr (f i) j = 0 :=
by simpa [orthonormal_basis.repr_apply_apply]
using gram_schmidt_orthonormal_basis_inv_triangular h f hij
/-- Given an indexed family `f : ι → E` of vectors in an inner product space `E`, for which the
size of the index set is the dimension of `E`, the matrix of coefficients of `f` with respect to the
orthonormal basis `gram_schmidt_orthonormal_basis` constructed from `f` is upper-triangular. -/
lemma gram_schmidt_orthonormal_basis_inv_block_triangular :
((gram_schmidt_orthonormal_basis h f).to_basis.to_matrix f).block_triangular id :=
λ i j, gram_schmidt_orthonormal_basis_inv_triangular' h f
lemma gram_schmidt_orthonormal_basis_det :
(gram_schmidt_orthonormal_basis h f).to_basis.det f =
∏ i, ⟪gram_schmidt_orthonormal_basis h f i, f i⟫ :=
begin
convert matrix.det_of_upper_triangular (gram_schmidt_orthonormal_basis_inv_block_triangular h f),
ext i,
exact ((gram_schmidt_orthonormal_basis h f).repr_apply_apply (f i) i).symm,
end
end orthonormal_basis
|
4dfcc0f3897b204a23b75f06150e0ed281f72e4a | c777c32c8e484e195053731103c5e52af26a25d1 | /archive/imo/imo2008_q2.lean | a20f897827eefb39937176a4046fb18e8a3c13ed | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 5,148 | lean | /-
Copyright (c) 2021 Manuel Candales. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Manuel Candales
-/
import data.real.basic
import data.set.finite
/-!
# IMO 2008 Q2
(a) Prove that
```
x^2 / (x-1)^2 + y^2 / (y-1)^2 + z^2 / (z-1)^2 ≥ 1
```
for all real numbers `x`,`y`, `z`, each different from 1, and satisfying `xyz = 1`.
(b) Prove that equality holds above for infinitely many triples of rational numbers `x`, `y`, `z`,
each different from 1, and satisfying `xyz = 1`.
# Solution
(a) Since `xyz = 1`, we can apply the substitution `x = a/b`, `y = b/c`, `z = c/a`.
Then we define `m = c-b`, `n = b-a` and rewrite the inequality as `LHS - 1 ≥ 0`
using `c`, `m` and `n`. We factor `LHS - 1` as a square, which finishes the proof.
(b) We present a set `W` of rational triples. We prove that `W` is a subset of the
set of rational solutions to the equation, and that `W` is infinite.
-/
lemma subst_abc {x y z : ℝ} (h : x*y*z = 1) :
∃ a b c : ℝ, a ≠ 0 ∧ b ≠ 0 ∧ c ≠ 0 ∧ x = a/b ∧ y = b/c ∧ z = c /a :=
begin
use [x, 1, 1/y],
obtain ⟨⟨hx, hy⟩, hz⟩ : (x ≠ 0 ∧ y ≠ 0) ∧ z ≠ 0,
by simpa [not_or_distrib] using trans_rel_right (≠) h one_ne_zero,
have : z * (y * x) = 1, by { rw ← h, ac_refl },
field_simp *
end
theorem imo2008_q2a (x y z : ℝ) (h : x*y*z = 1) (hx : x ≠ 1) (hy : y ≠ 1) (hz : z ≠ 1) :
x^2 / (x-1)^2 + y^2 / (y-1)^2 + z^2 / (z-1)^2 ≥ 1 :=
begin
obtain ⟨a, b, c, ha, hb, hc, rfl, rfl, rfl⟩ := subst_abc h,
obtain ⟨m, n, rfl, rfl⟩ : ∃ m n, b = c - m ∧ a = c - m - n,
{ use [c - b, b - a], simp },
have hm_ne_zero : m ≠ 0,
{ contrapose! hy, field_simp, assumption },
have hn_ne_zero : n ≠ 0,
{ contrapose! hx, field_simp, assumption },
have hmn_ne_zero : m + n ≠ 0,
{ contrapose! hz, field_simp, linarith },
have hc_sub_sub : c - (c - m - n) = m + n, by abel,
rw [ge_iff_le, ← sub_nonneg],
convert sq_nonneg ((c*(m^2+n^2+m*n) - m*(m+n)^2) / (m*n*(m+n)) ),
field_simp *, ring
end
def rational_solutions := { s : ℚ×ℚ×ℚ | ∃ (x y z : ℚ), s = (x, y, z) ∧
x ≠ 1 ∧ y ≠ 1 ∧ z ≠ 1 ∧ x*y*z = 1 ∧ x^2/(x-1)^2 + y^2/(y-1)^2 + z^2/(z-1)^2 = 1 }
theorem imo2008_q2b : set.infinite rational_solutions :=
begin
let W := { s : ℚ×ℚ×ℚ | ∃ (x y z : ℚ), s = (x, y, z) ∧
∃ t : ℚ, t > 0 ∧ x = -(t+1)/t^2 ∧ y = t/(t+1)^2 ∧ z = -t*(t+1)},
have hW_sub_S : W ⊆ rational_solutions,
{ intros s hs_in_W,
rw rational_solutions,
simp only [set.mem_set_of_eq] at hs_in_W ⊢,
rcases hs_in_W with ⟨x, y, z, h₁, t, ht_gt_zero, hx_t, hy_t, hz_t⟩,
use [x, y, z],
have ht_ne_zero : t ≠ 0, exact ne_of_gt ht_gt_zero,
have ht1_ne_zero : t+1 ≠ 0, linarith[ht_gt_zero],
have key_gt_zero : t^2 + t + 1 > 0, linarith[pow_pos ht_gt_zero 2, ht_gt_zero],
have key_ne_zero : t^2 + t + 1 ≠ 0, exact ne_of_gt key_gt_zero,
have h₂ : x ≠ 1, { rw hx_t, field_simp, linarith[key_gt_zero] },
have h₃ : y ≠ 1, { rw hy_t, field_simp, linarith[key_gt_zero] },
have h₄ : z ≠ 1, { rw hz_t, linarith[key_gt_zero] },
have h₅ : x*y*z = 1, { rw [hx_t, hy_t, hz_t], field_simp, ring },
have h₆ : x^2/(x-1)^2 + y^2/(y-1)^2 + z^2/(z-1)^2 = 1,
{ have hx1 : (x - 1)^2 = (t^2 + t + 1)^2/t^4, { field_simp, rw hx_t, field_simp, ring },
have hy1 : (y - 1)^2 = (t^2 + t + 1)^2/(t+1)^4, { field_simp, rw hy_t, field_simp, ring },
have hz1 : (z - 1)^2 = (t^2 + t + 1)^2, { rw hz_t, ring },
calc x^2/(x-1)^2 + y^2/(y-1)^2 + z^2/(z-1)^2
= (x^2*t^4 + y^2*(t+1)^4 + z^2)/(t^2 + t + 1)^2 :
by { rw [hx1, hy1, hz1], field_simp }
... = 1 :
by { rw [hx_t, hy_t, hz_t], field_simp, ring } },
exact ⟨h₁, h₂, h₃, h₄, h₅, h₆⟩ },
have hW_inf : set.infinite W,
{ let g : ℚ×ℚ×ℚ → ℚ := (λs, -s.2.2),
let K := g '' W,
have hK_not_bdd : ¬bdd_above K,
{ rw not_bdd_above_iff,
intro q,
let t : ℚ := max (q+1) 1,
use t*(t+1),
have h₁ : t * (t + 1) ∈ K,
{ let x : ℚ := -(t + 1)/t^2,
let y : ℚ := t/(t+1)^2,
set z : ℚ := -t*(t+1) with hz_def,
simp only [set.mem_image, prod.exists],
use [x, y, z], split,
simp only [set.mem_set_of_eq],
{ use [x, y, z], split,
refl,
{ use t, split,
{ simp only [gt_iff_lt, lt_max_iff], right, exact zero_lt_one },
exact ⟨rfl, rfl, rfl⟩ } },
{ have hg : g(x, y, z) = -z := rfl,
rw [hg, hz_def], ring } },
have h₂ : q < t * (t + 1),
{ calc q < q + 1 : by linarith
... ≤ t : le_max_left (q + 1) 1
... ≤ t+t^2 : by linarith [sq_nonneg t]
... = t*(t+1) : by ring },
exact ⟨h₁, h₂⟩ },
have hK_inf : set.infinite K,
{ intro h, apply hK_not_bdd, exact set.finite.bdd_above h },
exact hK_inf.of_image g },
exact hW_inf.mono hW_sub_S,
end
|
ab26be3784cf98714d0d5e3af614811fe78127a4 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/ind0.lean | 2caef9b45c4efd9903147de460b17940ecfc7c28 | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 92 | lean | prelude
inductive nat : Type
| zero : nat
| succ : nat → nat
check nat
check nat.rec.{1}
|
c8d881dc61fda2fe77af76e162af7dd18a79c81d | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/delabUnexpand.lean | 8d83b2944c12dc79a24e121a1f3b4c9b7916dee8 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | leanprover/lean4 | 4bdf9790294964627eb9be79f5e8f6157780b4cc | f1f9dc0f2f531af3312398999d8b8303fa5f096b | refs/heads/master | 1,693,360,665,786 | 1,693,350,868,000 | 1,693,350,868,000 | 129,571,436 | 2,827 | 311 | Apache-2.0 | 1,694,716,156,000 | 1,523,760,560,000 | Lean | UTF-8 | Lean | false | false | 758 | lean | structure Foo where
x : Nat
y : Nat
macro a:term " ♬ " b:term : term => `(Foo.mk $a $b)
@[app_unexpander Foo.mk] def unexpandFooFailure1 : Lean.PrettyPrinter.Unexpander
| _ => throw ()
@[app_unexpander Foo.mk] def unexpandFoo : Lean.PrettyPrinter.Unexpander
| `(Foo.mk $a $b) => `($a ♬ $b)
| _ => throw ()
@[app_unexpander Foo.mk] def unexpandFooFailure2 : Lean.PrettyPrinter.Unexpander
| _ => throw ()
#check 3 ♬ 4
def foo (k : Nat → Nat) (n : Nat) : Nat := k (n+1)
@[app_unexpander foo] def unexpandFooApp : Lean.PrettyPrinter.Unexpander
| `(foo $k $a) => `(My.foo $k $a)
| _ => throw ()
#check foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ foo $ id
|
6f3f12bab72c5bdb276ade322ca2e24fd3361c44 | a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7 | /src/data/finset/sort.lean | 81b4dfcdc9887bf0cd55772b3b79dd23ee8e5258 | [
"Apache-2.0"
] | permissive | kmill/mathlib | ea5a007b67ae4e9e18dd50d31d8aa60f650425ee | 1a419a9fea7b959317eddd556e1bb9639f4dcc05 | refs/heads/master | 1,668,578,197,719 | 1,593,629,163,000 | 1,593,629,163,000 | 276,482,939 | 0 | 0 | null | 1,593,637,960,000 | 1,593,637,959,000 | null | UTF-8 | Lean | false | false | 8,302 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import data.finset.lattice
import data.multiset.sort
/-!
# Construct a sorted list from a finset.
-/
namespace finset
open multiset nat
variables {α β : Type*}
/-! ### sort -/
section sort
variables (r : α → α → Prop) [decidable_rel r]
[is_trans α r] [is_antisymm α r] [is_total α r]
/-- `sort s` constructs a sorted list from the unordered set `s`.
(Uses merge sort algorithm.) -/
def sort (s : finset α) : list α := sort r s.1
@[simp] theorem sort_sorted (s : finset α) : list.sorted r (sort r s) :=
sort_sorted _ _
@[simp] theorem sort_eq (s : finset α) : ↑(sort r s) = s.1 :=
sort_eq _ _
@[simp] theorem sort_nodup (s : finset α) : (sort r s).nodup :=
(by rw sort_eq; exact s.2 : @multiset.nodup α (sort r s))
@[simp] theorem sort_to_finset [decidable_eq α] (s : finset α) : (sort r s).to_finset = s :=
list.to_finset_eq (sort_nodup r s) ▸ eq_of_veq (sort_eq r s)
@[simp] theorem mem_sort {s : finset α} {a : α} : a ∈ sort r s ↔ a ∈ s :=
multiset.mem_sort _
@[simp] theorem length_sort {s : finset α} : (sort r s).length = s.card :=
multiset.length_sort _
end sort
section sort_linear_order
variables [decidable_linear_order α]
theorem sort_sorted_lt (s : finset α) :
list.sorted (<) (sort (≤) s) :=
(sort_sorted _ _).imp₂ (@lt_of_le_of_ne _ _) (sort_nodup _ _)
lemma sorted_zero_eq_min' (s : finset α) (h : 0 < (s.sort (≤)).length) (H : s.nonempty) :
(s.sort (≤)).nth_le 0 h = s.min' H :=
begin
let l := s.sort (≤),
apply le_antisymm,
{ have : s.min' H ∈ l := (finset.mem_sort (≤)).mpr (s.min'_mem H),
obtain ⟨i, i_lt, hi⟩ : ∃ i (hi : i < l.length), l.nth_le i hi = s.min' H :=
list.mem_iff_nth_le.1 this,
rw ← hi,
exact list.nth_le_of_sorted_of_le (s.sort_sorted (≤)) (nat.zero_le i) },
{ have : l.nth_le 0 h ∈ s := (finset.mem_sort (≤)).1 (list.nth_le_mem l 0 h),
exact s.min'_le H _ this }
end
lemma sorted_last_eq_max' (s : finset α) (h : (s.sort (≤)).length - 1 < (s.sort (≤)).length)
(H : s.nonempty) : (s.sort (≤)).nth_le ((s.sort (≤)).length - 1) h = s.max' H :=
begin
let l := s.sort (≤),
apply le_antisymm,
{ have : l.nth_le ((s.sort (≤)).length - 1) h ∈ s :=
(finset.mem_sort (≤)).1 (list.nth_le_mem l _ h),
exact s.le_max' H _ this },
{ have : s.max' H ∈ l := (finset.mem_sort (≤)).mpr (s.max'_mem H),
obtain ⟨i, i_lt, hi⟩ : ∃ i (hi : i < l.length), l.nth_le i hi = s.max' H :=
list.mem_iff_nth_le.1 this,
rw ← hi,
have : i ≤ l.length - 1 := nat.le_pred_of_lt i_lt,
exact list.nth_le_of_sorted_of_le (s.sort_sorted (≤)) (nat.le_pred_of_lt i_lt) },
end
/-- Given a finset `s` of cardinal `k` in a linear order `α`, the map `mono_of_fin s h`
is the increasing bijection between `fin k` and `s` as an `α`-valued map. Here, `h` is a proof that
the cardinality of `s` is `k`. We use this instead of a map `fin s.card → α` to avoid
casting issues in further uses of this function. -/
def mono_of_fin (s : finset α) {k : ℕ} (h : s.card = k) (i : fin k) : α :=
have A : (i : ℕ) < (s.sort (≤)).length, by simpa [h] using i.2,
(s.sort (≤)).nth_le i A
lemma mono_of_fin_strict_mono (s : finset α) {k : ℕ} (h : s.card = k) :
strict_mono (s.mono_of_fin h) :=
begin
assume i j hij,
exact list.pairwise_iff_nth_le.1 s.sort_sorted_lt _ _ _ hij
end
lemma mono_of_fin_bij_on (s : finset α) {k : ℕ} (h : s.card = k) :
set.bij_on (s.mono_of_fin h) set.univ ↑s :=
begin
have A : ∀ j, j ∈ s ↔ j ∈ (s.sort (≤)) := λ j, by simp,
apply set.bij_on.mk,
{ assume i hi,
simp only [mono_of_fin, set.mem_preimage, mem_coe, list.nth_le, A],
exact list.nth_le_mem _ _ _ },
{ exact ((mono_of_fin_strict_mono s h).injective).inj_on _ },
{ assume x hx,
simp only [mem_coe, A] at hx,
obtain ⟨i, il, hi⟩ : ∃ (i : ℕ) (h : i < (s.sort (≤)).length), (s.sort (≤)).nth_le i h = x :=
list.nth_le_of_mem hx,
simp [h] at il,
exact ⟨⟨i, il⟩, set.mem_univ _, hi⟩ }
end
lemma mono_of_fin_injective (s : finset α) {k : ℕ} (h : s.card = k) :
function.injective (s.mono_of_fin h) :=
set.injective_iff_inj_on_univ.mpr (s.mono_of_fin_bij_on h).inj_on
/-- The bijection `mono_of_fin s h` sends `0` to the minimum of `s`. -/
lemma mono_of_fin_zero {s : finset α} {k : ℕ} (h : s.card = k) (hs : s.nonempty) (hz : 0 < k) :
mono_of_fin s h ⟨0, hz⟩ = s.min' hs :=
begin
apply le_antisymm,
{ have : min' s hs ∈ s := min'_mem s hs,
rcases (mono_of_fin_bij_on s h).surj_on this with ⟨a, _, ha⟩,
rw ← ha,
apply (mono_of_fin_strict_mono s h).monotone,
exact zero_le a.val },
{ have : mono_of_fin s h ⟨0, hz⟩ ∈ s := (mono_of_fin_bij_on s h).maps_to (set.mem_univ _),
exact min'_le s hs _ this }
end
/-- The bijection `mono_of_fin s h` sends `k-1` to the maximum of `s`. -/
lemma mono_of_fin_last {s : finset α} {k : ℕ} (h : s.card = k) (hs : s.nonempty) (hz : 0 < k) :
mono_of_fin s h ⟨k-1, buffer.lt_aux_2 hz⟩ = s.max' hs :=
begin
have h'' : k - 1 < k := buffer.lt_aux_2 hz,
apply le_antisymm,
{ have : mono_of_fin s h ⟨k-1, h''⟩ ∈ s := (mono_of_fin_bij_on s h).maps_to (set.mem_univ _),
exact le_max' s hs _ this },
{ have : max' s hs ∈ s := max'_mem s hs,
rcases (mono_of_fin_bij_on s h).surj_on this with ⟨a, _, ha⟩,
rw ← ha,
apply (mono_of_fin_strict_mono s h).monotone,
exact le_pred_of_lt a.2},
end
/-- Any increasing bijection between `fin k` and a finset of cardinality `k` has to coincide with
the increasing bijection `mono_of_fin s h`. For a statement assuming only that `f` maps `univ` to
`s`, see `mono_of_fin_unique'`.-/
lemma mono_of_fin_unique {s : finset α} {k : ℕ} (h : s.card = k) {f : fin k → α}
(hbij : set.bij_on f set.univ ↑s) (hmono : strict_mono f) : f = s.mono_of_fin h :=
begin
ext ⟨i, hi⟩,
induction i using nat.strong_induction_on with i IH,
rcases lt_trichotomy (f ⟨i, hi⟩) (mono_of_fin s h ⟨i, hi⟩) with H|H|H,
{ have A : f ⟨i, hi⟩ ∈ ↑s := hbij.maps_to (set.mem_univ _),
rcases (mono_of_fin_bij_on s h).surj_on A with ⟨j, _, hj⟩,
rw ← hj at H,
have ji : j < ⟨i, hi⟩ := (mono_of_fin_strict_mono s h).lt_iff_lt.1 H,
have : f j = mono_of_fin s h j,
by { convert IH j.1 ji (lt_trans ji hi), rw fin.ext_iff },
rw ← this at hj,
exact (ne_of_lt (hmono ji) hj).elim },
{ exact H },
{ have A : mono_of_fin s h ⟨i, hi⟩ ∈ ↑s := (mono_of_fin_bij_on s h).maps_to (set.mem_univ _),
rcases hbij.surj_on A with ⟨j, _, hj⟩,
rw ← hj at H,
have ji : j < ⟨i, hi⟩ := hmono.lt_iff_lt.1 H,
have : f j = mono_of_fin s h j,
by { convert IH j.1 ji (lt_trans ji hi), rw fin.ext_iff },
rw this at hj,
exact (ne_of_lt (mono_of_fin_strict_mono s h ji) hj).elim }
end
/-- Two parametrizations `mono_of_fin` of the same set take the same value on `i` and `j` if and
only if `i = j`. Since they can be defined on a priori not defeq types `fin k` and `fin l` (although
necessarily `k = l`), the conclusion is rather written `i.val = j.val`. -/
@[simp] lemma mono_of_fin_eq_mono_of_fin_iff
{k l : ℕ} {s : finset α} {i : fin k} {j : fin l} {h : s.card = k} {h' : s.card = l} :
s.mono_of_fin h i = s.mono_of_fin h' j ↔ i.val = j.val :=
begin
have A : k = l, by rw [← h', ← h],
have : s.mono_of_fin h = (s.mono_of_fin h') ∘ (λ j : (fin k), ⟨j.1, A ▸ j.2⟩) := rfl,
rw [this, function.comp_app, (s.mono_of_fin_injective h').eq_iff, fin.ext_iff]
end
/-- Given a finset `s` of cardinal `k` in a linear order `α`, the equiv `mono_equiv_of_fin s h`
is the increasing bijection between `fin k` and `s` as an `s`-valued map. Here, `h` is a proof that
the cardinality of `s` is `k`. We use this instead of a map `fin s.card → α` to avoid
casting issues in further uses of this function. -/
noncomputable def mono_equiv_of_fin (s : finset α) {k : ℕ} (h : s.card = k) :
fin k ≃ {x // x ∈ s} :=
(s.mono_of_fin_bij_on h).equiv _
end sort_linear_order
instance [has_repr α] : has_repr (finset α) := ⟨λ s, repr s.1⟩
end finset
|
09707557ca5996f0f6c4a7f8692573f4927f1457 | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/linear_algebra/determinant.lean | c077e3ef480cae20c77a18b92fa03799be985a7b | [
"Apache-2.0"
] | permissive | hikari0108/mathlib | b7ea2b7350497ab1a0b87a09d093ecc025a50dfa | a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901 | refs/heads/master | 1,690,483,608,260 | 1,631,541,580,000 | 1,631,541,580,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 12,573 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import linear_algebra.free_module_pid
import linear_algebra.matrix.basis
import linear_algebra.matrix.diagonal
import linear_algebra.matrix.to_linear_equiv
import linear_algebra.matrix.reindex
import linear_algebra.multilinear
import linear_algebra.dual
import ring_theory.algebra_tower
/-!
# Determinant of families of vectors
This file defines the determinant of an endomorphism, and of a family of vectors
with respect to some basis. For the determinant of a matrix, see the file
`linear_algebra.matrix.determinant`.
## Main definitions
In the list below, and in all this file, `R` is a commutative ring (semiring
is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite
types used for indexing.
* `basis.det`: the determinant of a family of vectors with respect to a basis,
as a multilinear map
* `linear_map.det`: the determinant of an endomorphism `f : End R M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
## Tags
basis, det, determinant
-/
noncomputable theory
open_locale big_operators
open_locale matrix
open linear_map
open submodule
universes u v w
open linear_map matrix
variables {R : Type*} [comm_ring R]
variables {M : Type*} [add_comm_group M] [module R M]
variables {M' : Type*} [add_comm_group M'] [module R M']
variables {ι : Type*} [decidable_eq ι] [fintype ι]
variables (e : basis ι R M)
section conjugate
variables {A : Type*} [integral_domain A]
variables {m n : Type*} [fintype m] [fintype n]
/-- If `R^m` and `R^n` are linearly equivalent, then `m` and `n` are also equivalent. -/
def equiv_of_pi_lequiv_pi {R : Type*} [integral_domain R]
(e : (m → R) ≃ₗ[R] (n → R)) : m ≃ n :=
basis.index_equiv (basis.of_equiv_fun e.symm) (pi.basis_fun _ _)
namespace matrix
/-- If `M` and `M'` are each other's inverse matrices, they are square matrices up to
equivalence of types. -/
def index_equiv_of_inv [decidable_eq m] [decidable_eq n]
{M : matrix m n A} {M' : matrix n m A}
(hMM' : M ⬝ M' = 1) (hM'M : M' ⬝ M = 1) :
m ≃ n :=
equiv_of_pi_lequiv_pi (to_lin'_of_inv hMM' hM'M)
lemma det_comm [decidable_eq n] (M N : matrix n n A) : det (M ⬝ N) = det (N ⬝ M) :=
by rw [det_mul, det_mul, mul_comm]
/-- If there exists a two-sided inverse `M'` for `M` (indexed differently),
then `det (N ⬝ M) = det (M ⬝ N)`. -/
lemma det_comm' [decidable_eq m] [decidable_eq n]
{M : matrix n m A} {N : matrix m n A} {M' : matrix m n A}
(hMM' : M ⬝ M' = 1) (hM'M : M' ⬝ M = 1) :
det (M ⬝ N) = det (N ⬝ M) :=
-- Although `m` and `n` are different a priori, we will show they have the same cardinality.
-- This turns the problem into one for square matrices, which is easy.
let e := index_equiv_of_inv hMM' hM'M in
by rw [← det_minor_equiv_self e, minor_mul_equiv _ _ _ (equiv.refl n) _, det_comm,
← minor_mul_equiv, equiv.coe_refl, minor_id_id]
/-- If `M'` is a two-sided inverse for `M` (indexed differently), `det (M ⬝ N ⬝ M') = det N`. -/
lemma det_conj [decidable_eq m] [decidable_eq n]
{M : matrix m n A} {M' : matrix n m A} {N : matrix n n A}
(hMM' : M ⬝ M' = 1) (hM'M : M' ⬝ M = 1) :
det (M ⬝ N ⬝ M') = det N :=
by rw [← det_comm' hM'M hMM', ← matrix.mul_assoc, hM'M, matrix.one_mul]
end matrix
end conjugate
namespace linear_map
/-! ### Determinant of a linear map -/
variables {A : Type*} [integral_domain A] [module A M]
variables {κ : Type*} [fintype κ]
/-- The determinant of `linear_map.to_matrix` does not depend on the choice of basis. -/
lemma det_to_matrix_eq_det_to_matrix [decidable_eq κ]
(b : basis ι A M) (c : basis κ A M) (f : M →ₗ[A] M) :
det (linear_map.to_matrix b b f) = det (linear_map.to_matrix c c f) :=
by rw [← linear_map_to_matrix_mul_basis_to_matrix c b c,
← basis_to_matrix_mul_linear_map_to_matrix b c b,
matrix.det_conj]; rw [basis.to_matrix_mul_to_matrix, basis.to_matrix_self]
/-- The determinant of an endomorphism given a basis.
See `linear_map.det` for a version that populates the basis non-computably.
Although the `trunc (basis ι A M)` parameter makes it slightly more convenient to switch bases,
there is no good way to generalize over universe parameters, so we can't fully state in `det_aux`'s
type that it does not depend on the choice of basis. Instead you can use the `det_aux_def'` lemma,
or avoid mentioning a basis at all using `linear_map.det`.
-/
def det_aux : trunc (basis ι A M) → (M →ₗ[A] M) →* A :=
trunc.lift
(λ b : basis ι A M,
(det_monoid_hom).comp (to_matrix_alg_equiv b : (M →ₗ[A] M) →* matrix ι ι A))
(λ b c, monoid_hom.ext $ det_to_matrix_eq_det_to_matrix b c)
/-- Unfold lemma for `det_aux`.
See also `det_aux_def'` which allows you to vary the basis.
-/
lemma det_aux_def (b : basis ι A M) (f : M →ₗ[A] M) :
linear_map.det_aux (trunc.mk b) f = matrix.det (linear_map.to_matrix b b f) :=
rfl
-- Discourage the elaborator from unfolding `det_aux` and producing a huge term.
attribute [irreducible] linear_map.det_aux
lemma det_aux_def' {ι' : Type*} [fintype ι'] [decidable_eq ι']
(tb : trunc $ basis ι A M) (b' : basis ι' A M) (f : M →ₗ[A] M) :
linear_map.det_aux tb f = matrix.det (linear_map.to_matrix b' b' f) :=
by { apply trunc.induction_on tb, intro b, rw [det_aux_def, det_to_matrix_eq_det_to_matrix b b'] }
@[simp]
lemma det_aux_id (b : trunc $ basis ι A M) : linear_map.det_aux b (linear_map.id) = 1 :=
(linear_map.det_aux b).map_one
@[simp]
lemma det_aux_comp (b : trunc $ basis ι A M) (f g : M →ₗ[A] M) :
linear_map.det_aux b (f.comp g) = linear_map.det_aux b f * linear_map.det_aux b g :=
(linear_map.det_aux b).map_mul f g
section
open_locale classical
/-- The determinant of an endomorphism independent of basis.
If there is no finite basis on `M`, the result is `1` instead.
-/
protected def det : (M →ₗ[A] M) →* A :=
if H : ∃ (s : finset M), nonempty (basis s A M)
then linear_map.det_aux (trunc.mk H.some_spec.some)
else 1
lemma coe_det [decidable_eq M] : ⇑(linear_map.det : (M →ₗ[A] M) →* A) =
if H : ∃ (s : finset M), nonempty (basis s A M)
then linear_map.det_aux (trunc.mk H.some_spec.some)
else 1 :=
by { ext, unfold linear_map.det,
split_ifs,
{ congr }, -- use the correct `decidable_eq` instance
refl }
end
-- Discourage the elaborator from unfolding `det` and producing a huge term.
attribute [irreducible] linear_map.det
-- Auxiliary lemma, the `simp` normal form goes in the other direction
-- (using `linear_map.det_to_matrix`)
lemma det_eq_det_to_matrix_of_finset [decidable_eq M]
{s : finset M} (b : basis s A M) (f : M →ₗ[A] M) :
f.det = matrix.det (linear_map.to_matrix b b f) :=
have ∃ (s : finset M), nonempty (basis s A M),
from ⟨s, ⟨b⟩⟩,
by rw [linear_map.coe_det, dif_pos, det_aux_def' _ b]; assumption
@[simp] lemma det_to_matrix
(b : basis ι A M) (f : M →ₗ[A] M) :
matrix.det (to_matrix b b f) = f.det :=
by { haveI := classical.dec_eq M,
rw [det_eq_det_to_matrix_of_finset b.reindex_finset_range, det_to_matrix_eq_det_to_matrix b] }
/-- To show `P f.det` it suffices to consider `P (to_matrix _ _ f).det` and `P 1`. -/
@[elab_as_eliminator]
lemma det_cases [decidable_eq M] {P : A → Prop} (f : M →ₗ[A] M)
(hb : ∀ (s : finset M) (b : basis s A M), P (to_matrix b b f).det) (h1 : P 1) :
P f.det :=
begin
unfold linear_map.det,
split_ifs with h,
{ convert hb _ h.some_spec.some,
apply det_aux_def' },
{ exact h1 }
end
@[simp]
lemma det_comp (f g : M →ₗ[A] M) : (f.comp g).det = f.det * g.det :=
linear_map.det.map_mul f g
@[simp]
lemma det_id : (linear_map.id : M →ₗ[A] M).det = 1 :=
linear_map.det.map_one
lemma det_zero {ι : Type*} [fintype ι] [nonempty ι] (b : basis ι A M) :
linear_map.det (0 : M →ₗ[A] M) = 0 :=
by { haveI := classical.dec_eq ι,
rw [← det_to_matrix b, linear_equiv.map_zero, det_zero],
assumption }
end linear_map
-- Cannot be stated using `linear_map.det` because `f` is not an endomorphism.
lemma linear_equiv.is_unit_det (f : M ≃ₗ[R] M') (v : basis ι R M) (v' : basis ι R M') :
is_unit (linear_map.to_matrix v v' f).det :=
begin
apply is_unit_det_of_left_inverse,
simpa using (linear_map.to_matrix_comp v v' v f.symm f).symm
end
/-- Specialization of `linear_equiv.is_unit_det` -/
lemma linear_equiv.is_unit_det' {A : Type*} [integral_domain A] [module A M]
(f : M ≃ₗ[A] M) : is_unit (linear_map.det (f : M →ₗ[A] M)) :=
by haveI := classical.dec_eq M; exact
(f : M →ₗ[A] M).det_cases (λ s b, f.is_unit_det _ _) is_unit_one
/-- Builds a linear equivalence from a linear map whose determinant in some bases is a unit. -/
@[simps]
def linear_equiv.of_is_unit_det {f : M →ₗ[R] M'} {v : basis ι R M} {v' : basis ι R M'}
(h : is_unit (linear_map.to_matrix v v' f).det) : M ≃ₗ[R] M' :=
{ to_fun := f,
map_add' := f.map_add,
map_smul' := f.map_smul,
inv_fun := to_lin v' v (to_matrix v v' f)⁻¹,
left_inv := λ x,
calc to_lin v' v (to_matrix v v' f)⁻¹ (f x)
= to_lin v v ((to_matrix v v' f)⁻¹ ⬝ to_matrix v v' f) x :
by { rw [to_lin_mul v v' v, to_lin_to_matrix, linear_map.comp_apply] }
... = x : by simp [h],
right_inv := λ x,
calc f (to_lin v' v (to_matrix v v' f)⁻¹ x)
= to_lin v' v' (to_matrix v v' f ⬝ (to_matrix v v' f)⁻¹) x :
by { rw [to_lin_mul v' v v', linear_map.comp_apply, to_lin_to_matrix v v'] }
... = x : by simp [h] }
/-- The determinant of a family of vectors with respect to some basis, as an alternating
multilinear map. -/
def basis.det : alternating_map R M R ι :=
{ to_fun := λ v, det (e.to_matrix v),
map_add' := begin
intros v i x y,
simp only [e.to_matrix_update, linear_equiv.map_add],
apply det_update_column_add
end,
map_smul' := begin
intros u i c x,
simp only [e.to_matrix_update, algebra.id.smul_eq_mul, linear_equiv.map_smul],
apply det_update_column_smul
end,
map_eq_zero_of_eq' := begin
intros v i j h hij,
rw [←function.update_eq_self i v, h, ←det_transpose, e.to_matrix_update,
←update_row_transpose, ←e.to_matrix_transpose_apply],
apply det_zero_of_row_eq hij,
rw [update_row_ne hij.symm, update_row_self],
end }
lemma basis.det_apply (v : ι → M) : e.det v = det (e.to_matrix v) := rfl
lemma basis.det_self : e.det e = 1 :=
by simp [e.det_apply]
lemma is_basis_iff_det {v : ι → M} :
linear_independent R v ∧ span R (set.range v) = ⊤ ↔ is_unit (e.det v) :=
begin
split,
{ rintro ⟨hli, hspan⟩,
set v' := basis.mk hli hspan with v'_eq,
rw e.det_apply,
convert linear_equiv.is_unit_det (linear_equiv.refl _ _) v' e using 2,
ext i j,
simp },
{ intro h,
rw [basis.det_apply, basis.to_matrix_eq_to_matrix_constr] at h,
set v' := basis.map e (linear_equiv.of_is_unit_det h) with v'_def,
have : ⇑ v' = v,
{ ext i, rw [v'_def, basis.map_apply, linear_equiv.of_is_unit_det_apply, e.constr_basis] },
rw ← this,
exact ⟨v'.linear_independent, v'.span_eq⟩ },
end
lemma basis.is_unit_det (e' : basis ι R M) : is_unit (e.det e') :=
(is_basis_iff_det e).mp ⟨e'.linear_independent, e'.span_eq⟩
variables {A : Type*} [integral_domain A] [module A M]
@[simp] lemma basis.det_comp (e : basis ι A M) (f : M →ₗ[A] M) (v : ι → M) :
e.det (f ∘ v) = f.det * e.det v :=
by { rw [basis.det_apply, basis.det_apply, ← f.det_to_matrix e, ← matrix.det_mul,
e.to_matrix_eq_to_matrix_constr (f ∘ v), e.to_matrix_eq_to_matrix_constr v,
← to_matrix_comp, e.constr_comp] }
lemma basis.det_reindex {ι' : Type*} [fintype ι'] [decidable_eq ι']
(b : basis ι R M) (v : ι' → M) (e : ι ≃ ι') :
(b.reindex e).det v = b.det (v ∘ e) :=
by rw [basis.det_apply, basis.to_matrix_reindex', det_reindex_alg_equiv, basis.det_apply]
lemma basis.det_reindex_symm {ι' : Type*} [fintype ι'] [decidable_eq ι']
(b : basis ι R M) (v : ι → M) (e : ι' ≃ ι) :
(b.reindex e.symm).det (v ∘ e) = b.det v :=
by rw [basis.det_reindex, function.comp.assoc, e.self_comp_symm, function.comp.right_id]
@[simp]
lemma basis.det_map (b : basis ι R M) (f : M ≃ₗ[R] M') (v : ι → M') :
(b.map f).det v = b.det (f.symm ∘ v) :=
by { rw [basis.det_apply, basis.to_matrix_map, basis.det_apply] }
|
8692160f7455333d32019e5379736069facbba0f | 1437b3495ef9020d5413178aa33c0a625f15f15f | /analysis/measure_theory/outer_measure.lean | d6f1c3f9be59a24d059f9c69ae5104a028833089 | [
"Apache-2.0"
] | permissive | jean002/mathlib | c66bbb2d9fdc9c03ae07f869acac7ddbfce67a30 | dc6c38a765799c99c4d9c8d5207d9e6c9e0e2cfd | refs/heads/master | 1,587,027,806,375 | 1,547,306,358,000 | 1,547,306,358,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 18,151 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
Outer measures -- overapproximations of measures
-/
import order.galois_connection algebra.big_operators algebra.module
analysis.ennreal analysis.limits
analysis.measure_theory.measurable_space
noncomputable theory
open set lattice finset function filter encodable
local attribute [instance] classical.prop_decidable
namespace measure_theory
structure outer_measure (α : Type*) :=
(measure_of : set α → ennreal)
(empty : measure_of ∅ = 0)
(mono : ∀{s₁ s₂}, s₁ ⊆ s₂ → measure_of s₁ ≤ measure_of s₂)
(Union_nat : ∀(s:ℕ → set α), measure_of (⋃i, s i) ≤ (∑i, measure_of (s i)))
namespace outer_measure
instance {α} : has_coe_to_fun (outer_measure α) := ⟨_, λ m, m.measure_of⟩
section basic
variables {α : Type*} {ms : set (outer_measure α)} {m : outer_measure α}
@[simp] theorem empty' (m : outer_measure α) : m ∅ = 0 := m.empty
theorem mono' (m : outer_measure α) {s₁ s₂}
(h : s₁ ⊆ s₂) : m s₁ ≤ m s₂ := m.mono h
theorem Union_aux (m : set α → ennreal) (m0 : m ∅ = 0)
{β} [encodable β] (s : β → set α) :
(∑ b, m (s b)) = ∑ i, m (⋃ b ∈ decode2 β i, s b) :=
begin
have H : ∀ n, m (⋃ b ∈ decode2 β n, s b) ≠ 0 → (decode2 β n).is_some,
{ intros n h,
cases decode2 β n with b,
{ exact (h (by simp [m0])).elim },
{ exact rfl } },
refine tsum_eq_tsum_of_ne_zero_bij (λ n h, option.get (H n h)) _ _ _,
{ intros m n hm hn e,
have := mem_decode2.1 (option.get_mem (H n hn)),
rwa [← e, mem_decode2.1 (option.get_mem (H m hm))] at this },
{ intros b h,
refine ⟨encode b, _, _⟩,
{ convert h, simp [ext_iff, encodek2] },
{ exact option.get_of_mem _ (encodek2 _) } },
{ intros n h,
transitivity, swap,
rw [show decode2 β n = _, from option.get_mem (H n h)],
congr, simp [ext_iff] }
end
protected theorem Union (m : outer_measure α)
{β} [encodable β] (s : β → set α) :
m (⋃i, s i) ≤ (∑i, m (s i)) :=
by rw [Union_decode2, Union_aux _ m.empty' s]; exact m.Union_nat _
lemma Union_null (m : outer_measure α)
{β} [encodable β] {s : β → set α} (h : ∀ i, m (s i) = 0) : m (⋃i, s i) = 0 :=
by simpa [h] using m.Union s
protected lemma union (m : outer_measure α) (s₁ s₂ : set α) :
m (s₁ ∪ s₂) ≤ m s₁ + m s₂ :=
begin
convert m.Union (λ b, cond b s₁ s₂),
{ simp [union_eq_Union] },
{ rw tsum_fintype, change _ = _ + _, simp }
end
lemma union_null (m : outer_measure α) {s₁ s₂ : set α}
(h₁ : m s₁ = 0) (h₂ : m s₂ = 0) : m (s₁ ∪ s₂) = 0 :=
by simpa [h₁, h₂] using m.union s₁ s₂
@[extensionality] lemma ext : ∀{μ₁ μ₂ : outer_measure α},
(∀s, μ₁ s = μ₂ s) → μ₁ = μ₂
| ⟨m₁, e₁, _, u₁⟩ ⟨m₂, e₂, _, u₂⟩ h := by congr; exact funext h
instance : has_zero (outer_measure α) :=
⟨{ measure_of := λ_, 0,
empty := rfl,
mono := assume _ _ _, le_refl 0,
Union_nat := assume s, zero_le _ }⟩
@[simp] theorem zero_apply (s : set α) : (0 : outer_measure α) s = 0 := rfl
instance : inhabited (outer_measure α) := ⟨0⟩
instance : has_add (outer_measure α) :=
⟨λm₁ m₂,
{ measure_of := λs, m₁ s + m₂ s,
empty := show m₁ ∅ + m₂ ∅ = 0, by simp [outer_measure.empty],
mono := assume s₁ s₂ h, add_le_add' (m₁.mono h) (m₂.mono h),
Union_nat := assume s,
calc m₁ (⋃i, s i) + m₂ (⋃i, s i) ≤
(∑i, m₁ (s i)) + (∑i, m₂ (s i)) :
add_le_add' (m₁.Union_nat s) (m₂.Union_nat s)
... = _ : ennreal.tsum_add.symm}⟩
@[simp] theorem add_apply (m₁ m₂ : outer_measure α) (s : set α) :
(m₁ + m₂) s = m₁ s + m₂ s := rfl
instance : add_comm_monoid (outer_measure α) :=
{ zero := 0,
add := (+),
add_comm := assume a b, ext $ assume s, add_comm _ _,
add_assoc := assume a b c, ext $ assume s, add_assoc _ _ _,
add_zero := assume a, ext $ assume s, add_zero _,
zero_add := assume a, ext $ assume s, zero_add _ }
instance : has_bot (outer_measure α) := ⟨0⟩
instance outer_measure.order_bot : order_bot (outer_measure α) :=
{ le := λm₁ m₂, ∀s, m₁ s ≤ m₂ s,
bot := 0,
le_refl := assume a s, le_refl _,
le_trans := assume a b c hab hbc s, le_trans (hab s) (hbc s),
le_antisymm := assume a b hab hba, ext $ assume s, le_antisymm (hab s) (hba s),
bot_le := assume a s, zero_le _ }
section supremum
instance : has_Sup (outer_measure α) :=
⟨λms, {
measure_of := λs, ⨆m:ms, m.val s,
empty := le_zero_iff_eq.1 $ supr_le $ λ ⟨m, h⟩, le_of_eq m.empty,
mono := assume s₁ s₂ hs, supr_le_supr $ assume ⟨m, hm⟩, m.mono hs,
Union_nat := assume f, supr_le $ assume m,
calc m.val (⋃i, f i) ≤ (∑ (i : ℕ), m.val (f i)) : m.val.Union_nat _
... ≤ (∑i, ⨆m:ms, m.val (f i)) :
ennreal.tsum_le_tsum $ assume i, le_supr (λm:ms, m.val (f i)) m }⟩
private lemma le_Sup (hm : m ∈ ms) : m ≤ Sup ms :=
λ s, le_supr (λm:ms, m.val s) ⟨m, hm⟩
private lemma Sup_le (hm : ∀m' ∈ ms, m' ≤ m) : Sup ms ≤ m :=
λ s, (supr_le $ assume ⟨m', h'⟩, (hm m' h') s)
instance : has_Inf (outer_measure α) := ⟨λs, Sup {m | ∀m'∈s, m ≤ m'}⟩
private lemma Inf_le (hm : m ∈ ms) : Inf ms ≤ m := Sup_le $ assume m' h', h' _ hm
private lemma le_Inf (hm : ∀m' ∈ ms, m ≤ m') : m ≤ Inf ms := le_Sup hm
instance : complete_lattice (outer_measure α) :=
{ top := Sup univ,
le_top := assume a, le_Sup (mem_univ a),
Sup := Sup,
Sup_le := assume s m, Sup_le,
le_Sup := assume s m, le_Sup,
Inf := Inf,
Inf_le := assume s m, Inf_le,
le_Inf := assume s m, le_Inf,
sup := λa b, Sup {a, b},
le_sup_left := assume a b, le_Sup $ by simp,
le_sup_right := assume a b, le_Sup $ by simp,
sup_le := assume a b c ha hb, Sup_le $ by simp [or_imp_distrib, ha, hb] {contextual:=tt},
inf := λa b, Inf {a, b},
inf_le_left := assume a b, Inf_le $ by simp,
inf_le_right := assume a b, Inf_le $ by simp,
le_inf := assume a b c ha hb, le_Inf $ by simp [or_imp_distrib, ha, hb] {contextual:=tt},
.. outer_measure.order_bot }
@[simp] theorem Sup_apply (ms : set (outer_measure α)) (s : set α) :
(Sup ms) s = ⨆ m : ms, m s := rfl
@[simp] theorem supr_apply {ι} (f : ι → outer_measure α) (s : set α) :
(⨆ i : ι, f i) s = ⨆ i, f i s :=
le_antisymm
(supr_le $ λ ⟨_, i, rfl⟩, le_supr _ i)
(supr_le $ λ i, le_supr
(λ (m : {a : outer_measure α // ∃ i, f i = a}), m.1 s)
⟨f i, i, rfl⟩)
@[simp] theorem sup_apply (m₁ m₂ : outer_measure α) (s : set α) :
(m₁ ⊔ m₂) s = m₁ s ⊔ m₂ s :=
by have := supr_apply (λ b, cond b m₁ m₂) s;
rwa [supr_bool_eq, supr_bool_eq] at this
end supremum
def map {β} (f : α → β) (m : outer_measure α) : outer_measure β :=
{ measure_of := λs, m (f ⁻¹' s),
empty := m.empty,
mono := λ s t h, m.mono (preimage_mono h),
Union_nat := λ s, by rw [preimage_Union]; exact
m.Union_nat (λ i, f ⁻¹' s i) }
@[simp] theorem map_apply {β} (f : α → β)
(m : outer_measure α) (s : set β) : map f m s = m (f ⁻¹' s) := rfl
@[simp] theorem map_id (m : outer_measure α) : map id m = m :=
ext $ λ s, rfl
@[simp] theorem map_map {β γ} (f : α → β) (g : β → γ)
(m : outer_measure α) : map g (map f m) = map (g ∘ f) m :=
ext $ λ s, rfl
instance : functor outer_measure := {map := λ α β, map}
instance : is_lawful_functor outer_measure :=
{ id_map := λ α, map_id,
comp_map := λ α β γ f g m, (map_map f g m).symm }
/-- The dirac outer measure. -/
def dirac (a : α) : outer_measure α :=
{ measure_of := λs, ⨆ h : a ∈ s, 1,
empty := by simp,
mono := λ s t h, supr_le_supr2 (λ h', ⟨h h', le_refl _⟩),
Union_nat := λ s, supr_le $ λ h,
let ⟨i, h⟩ := mem_Union.1 h in
le_trans (by exact le_supr _ h) (ennreal.le_tsum i) }
@[simp] theorem dirac_apply (a : α) (s : set α) :
dirac a s = ⨆ h : a ∈ s, 1 := rfl
def sum {ι} (f : ι → outer_measure α) : outer_measure α :=
{ measure_of := λs, ∑ i, f i s,
empty := by simp,
mono := λ s t h, ennreal.tsum_le_tsum (λ i, (f i).mono' h),
Union_nat := λ s, by rw ennreal.tsum_comm; exact
ennreal.tsum_le_tsum (λ i, (f i).Union_nat _) }
@[simp] theorem sum_apply {ι} (f : ι → outer_measure α) (s : set α) :
sum f s = ∑ i, f i s := rfl
instance : has_scalar ennreal (outer_measure α) :=
⟨λ a m, {
measure_of := λs, a * m s,
empty := by simp,
mono := λ s t h, canonically_ordered_semiring.mul_le_mul (le_refl _) (m.mono' h),
Union_nat := λ s, by rw ennreal.mul_tsum; exact
canonically_ordered_semiring.mul_le_mul (le_refl _) (m.Union_nat _) }⟩
@[simp] theorem smul_apply (a : ennreal) (m : outer_measure α) (s : set α) :
(a • m) s = a * m s := rfl
instance : semimodule ennreal (outer_measure α) :=
{ smul_add := λ a m₁ m₂, ext $ λ s, mul_add _ _ _,
add_smul := λ a b m, ext $ λ s, add_mul _ _ _,
mul_smul := λ a b m, ext $ λ s, mul_assoc _ _ _,
one_smul := λ m, ext $ λ s, one_mul _,
zero_smul := λ m, ext $ λ s, zero_mul _,
smul_zero := λ a, ext $ λ s, mul_zero _,
..outer_measure.has_scalar }
theorem smul_dirac_apply (a : ennreal) (b : α) (s : set α) :
(a • dirac b) s = ⨆ h : b ∈ s, a :=
by by_cases b ∈ s; simp [h]
theorem top_apply {s : set α} (h : s ≠ ∅) : (⊤ : outer_measure α) s = ⊤ :=
let ⟨a, as⟩ := set.exists_mem_of_ne_empty h in
top_unique $ le_supr_of_le ⟨⊤ • dirac a, trivial⟩ $
by simp [smul_dirac_apply, as]
end basic
section of_function
set_option eqn_compiler.zeta true
/-- Given any function `m` assigning measures to sets satisying `m ∅ = 0`, there is
a unique maximal outer measure `μ` satisfying `μ s ≤ m s` for all `s : set α`. -/
protected def of_function {α : Type*} (m : set α → ennreal) (m_empty : m ∅ = 0) :
outer_measure α :=
let μ := λs, ⨅{f : ℕ → set α} (h : s ⊆ ⋃i, f i), ∑i, m (f i) in
{ measure_of := μ,
empty := le_antisymm
(infi_le_of_le (λ_, ∅) $ infi_le_of_le (empty_subset _) $ by simp [m_empty])
(zero_le _),
mono := assume s₁ s₂ hs, infi_le_infi $ assume f,
infi_le_infi2 $ assume hb, ⟨subset.trans hs hb, le_refl _⟩,
Union_nat := assume s, ennreal.le_of_forall_epsilon_le $ begin
assume ε hε (hb : (∑i, μ (s i)) < ⊤),
rcases ennreal.exists_pos_sum_of_encodable (ennreal.coe_lt_coe.2 hε) ℕ with ⟨ε', hε', hl⟩,
refine le_trans _ (add_le_add_left' (le_of_lt hl)),
rw ← ennreal.tsum_add,
choose f hf using show
∀i, ∃f:ℕ → set α, s i ⊆ (⋃i, f i) ∧ (∑i, m (f i)) < μ (s i) + ε' i,
{ intro,
have : μ (s i) < μ (s i) + ε' i :=
ennreal.lt_add_right
(lt_of_le_of_lt (by apply ennreal.le_tsum) hb)
(by simpa using hε' i),
simpa [μ, infi_lt_iff] },
refine le_trans _ (ennreal.tsum_le_tsum $ λ i, le_of_lt (hf i).2),
rw [← ennreal.tsum_prod, ← tsum_equiv equiv.nat_prod_nat_equiv_nat.symm],
swap, {apply_instance},
refine infi_le_of_le _ (infi_le _ _),
exact Union_subset (λ i, subset.trans (hf i).1 $
Union_subset $ λ j, subset.trans (by simp) $
subset_Union _ $ equiv.nat_prod_nat_equiv_nat (i, j)),
end }
theorem of_function_le {α : Type*} (m : set α → ennreal) (m_empty s) :
outer_measure.of_function m m_empty s ≤ m s :=
let f : ℕ → set α := λi, nat.rec_on i s (λn s, ∅) in
infi_le_of_le f $ infi_le_of_le (subset_Union f 0) $ le_of_eq $
calc (∑i, m (f i)) = ({0} : finset ℕ).sum (λi, m (f i)) :
tsum_eq_sum $ by intro i; cases i; simp [m_empty]
... = m s : by simp; refl
theorem le_of_function {α : Type*} {m m_empty} {μ : outer_measure α} :
μ ≤ outer_measure.of_function m m_empty ↔ ∀ s, μ s ≤ m s :=
⟨λ H s, le_trans (H _) (of_function_le _ _ _),
λ H s, le_infi $ λ f, le_infi $ λ hs,
le_trans (μ.mono hs) $ le_trans (μ.Union f) $
ennreal.tsum_le_tsum $ λ i, H _⟩
end of_function
section caratheodory_measurable
universe u
parameters {α : Type u} (m : outer_measure α)
include m
local attribute [simp] set.inter_comm set.inter_left_comm set.inter_assoc
variables {s s₁ s₂ : set α}
private def C (s : set α) := ∀t, m t = m (t ∩ s) + m (t \ s)
private lemma C_iff_le {s : set α} : C s ↔ ∀t, m (t ∩ s) + m (t \ s) ≤ m t :=
forall_congr $ λ t, le_antisymm_iff.trans $ and_iff_right $
by convert m.union _ _; rw inter_union_diff t s
@[simp] private lemma C_empty : C ∅ := by simp [C, m.empty, diff_empty]
private lemma C_compl : C s₁ → C (- s₁) := by simp [C, diff_eq]
@[simp] private lemma C_compl_iff : C (- s) ↔ C s :=
⟨λ h, by simpa using C_compl m h, C_compl⟩
private lemma C_union (h₁ : C s₁) (h₂ : C s₂) : C (s₁ ∪ s₂) :=
λ t, begin
rw [h₁ t, h₂ (t ∩ s₁), h₂ (t \ s₁), h₁ (t ∩ (s₁ ∪ s₂)),
inter_diff_assoc _ _ s₁, set.inter_assoc _ _ s₁,
inter_eq_self_of_subset_right (set.subset_union_left _ _),
union_diff_left, h₂ (t ∩ s₁)],
simp [diff_eq]
end
private lemma measure_inter_union (h : s₁ ∩ s₂ ⊆ ∅) (h₁ : C s₁) {t : set α} :
m (t ∩ (s₁ ∪ s₂)) = m (t ∩ s₁) + m (t ∩ s₂) :=
by rw [h₁, set.inter_assoc, union_inter_cancel_left,
inter_diff_assoc, union_diff_cancel_left h]
private lemma C_Union_lt {s : ℕ → set α} : ∀{n:ℕ}, (∀i<n, C (s i)) → C (⋃i<n, s i)
| 0 h := by simp [nat.not_lt_zero]
| (n + 1) h := by rw Union_lt_succ; exact C_union m
(h n (le_refl (n + 1)))
(C_Union_lt $ assume i hi, h i $ lt_of_lt_of_le hi $ nat.le_succ _)
private lemma C_inter (h₁ : C s₁) (h₂ : C s₂) : C (s₁ ∩ s₂) :=
by rw [← C_compl_iff, compl_inter]; from C_union _ (C_compl _ h₁) (C_compl _ h₂)
private lemma C_sum {s : ℕ → set α} (h : ∀i, C (s i)) (hd : pairwise (disjoint on s)) {t : set α} :
∀ {n}, (finset.range n).sum (λi, m (t ∩ s i)) = m (t ∩ ⋃i<n, s i)
| 0 := by simp [nat.not_lt_zero, m.empty]
| (nat.succ n) := begin
simp [Union_lt_succ, range_succ],
rw [measure_inter_union m _ (h n), C_sum],
intro a, simpa [range_succ] using λ h₁ i hi h₂, hd _ _ (ne_of_gt hi) ⟨h₁, h₂⟩
end
private lemma C_Union_nat {s : ℕ → set α} (h : ∀i, C (s i))
(hd : pairwise (disjoint on s)) : C (⋃i, s i) :=
C_iff_le.2 $ λ t, begin
have hp : m (t ∩ ⋃i, s i) ≤ (⨆n, m (t ∩ ⋃i<n, s i)),
{ convert m.Union (λ i, t ∩ s i),
{ rw inter_Union_left },
{ simp [ennreal.tsum_eq_supr_nat, C_sum m h hd] } },
refine le_trans (add_le_add_right' hp) _,
rw ennreal.supr_add,
refine supr_le (λ n, le_trans (add_le_add_left' _)
(ge_of_eq (C_Union_lt m (λ i _, h i) _))),
refine m.mono (diff_subset_diff_right _),
exact bUnion_subset (λ i _, subset_Union _ i),
end
private lemma f_Union {s : ℕ → set α} (h : ∀i, C (s i))
(hd : pairwise (disjoint on s)) : m (⋃i, s i) = ∑i, m (s i) :=
begin
refine le_antisymm (m.Union_nat s) _,
rw ennreal.tsum_eq_supr_nat,
refine supr_le (λ n, _),
have := @C_sum _ m _ h hd univ n,
simp at this, simp [this],
exact m.mono (bUnion_subset (λ i _, subset_Union _ i)),
end
private def caratheodory_dynkin : measurable_space.dynkin_system α :=
{ has := C,
has_empty := C_empty,
has_compl := assume s, C_compl,
has_Union_nat := assume f hf hn, C_Union_nat hn hf }
/-- Given an outer measure `μ`, the Caratheodory measurable space is
defined such that `s` is measurable if `∀t, μ t = μ (t ∩ s) + μ (t \ s)`. -/
protected def caratheodory : measurable_space α :=
caratheodory_dynkin.to_measurable_space $ assume s₁ s₂, C_inter
lemma is_caratheodory {s : set α} :
caratheodory.is_measurable s ↔ ∀t, m t = m (t ∩ s) + m (t \ s) :=
iff.rfl
lemma is_caratheodory_le {s : set α} :
caratheodory.is_measurable s ↔ ∀t, m (t ∩ s) + m (t \ s) ≤ m t :=
C_iff_le
protected lemma Union_eq_of_caratheodory {s : ℕ → set α}
(h : ∀i, caratheodory.is_measurable (s i)) (hd : pairwise (disjoint on s)) :
m (⋃i, s i) = ∑i, m (s i) :=
f_Union h hd
end caratheodory_measurable
variables {α : Type*}
lemma caratheodory_is_measurable {m : set α → ennreal} {s : set α}
{h₀ : m ∅ = 0} (hs : ∀t, m (t ∩ s) + m (t \ s) ≤ m t) :
(outer_measure.of_function m h₀).caratheodory.is_measurable s :=
let o := (outer_measure.of_function m h₀) in
(is_caratheodory_le o).2 $ λ t,
le_infi $ λ f, le_infi $ λ hf, begin
refine le_trans (add_le_add'
(infi_le_of_le (λi, f i ∩ s) $ infi_le _ _)
(infi_le_of_le (λi, f i \ s) $ infi_le _ _)) _,
{ rw ← inter_Union_right,
exact inter_subset_inter_left _ hf },
{ rw ← diff_Union_right,
exact diff_subset_diff_left hf },
{ rw ← ennreal.tsum_add,
exact ennreal.tsum_le_tsum (λ i, hs _) }
end
@[simp] theorem zero_caratheodory : (0 : outer_measure α).caratheodory = ⊤ :=
top_unique $ λ s _ t, (add_zero _).symm
theorem le_add_caratheodory (m₁ m₂ : outer_measure α) :
m₁.caratheodory ⊓ m₂.caratheodory ≤ (m₁ + m₂ : outer_measure α).caratheodory :=
λ s ⟨hs₁, hs₂⟩ t, by simp [hs₁ t, hs₂ t]
theorem le_sum_caratheodory {ι} (m : ι → outer_measure α) :
(⨅ i, (m i).caratheodory) ≤ (sum m).caratheodory :=
λ s h t, by simp [λ i,
measurable_space.is_measurable_infi.1 h i t, ennreal.tsum_add]
theorem le_smul_caratheodory (a : ennreal) (m : outer_measure α) :
m.caratheodory ≤ (a • m).caratheodory :=
λ s h t, by simp [h t, mul_add]
@[simp] theorem dirac_caratheodory (a : α) : (dirac a).caratheodory = ⊤ :=
top_unique $ λ s _ t, begin
by_cases a ∈ t; simp [h],
by_cases a ∈ s; simp [h]
end
end outer_measure
end measure_theory
|
e6fc0b84835df2c0553f2a7d291fad84c5e9a2dc | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/measure_theory/function/conditional_expectation/indicator.lean | 75267db6ea2d76c6d08a4560f1d333a4680f3dc7 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 9,961 | lean | /-
Copyright (c) 2022 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import measure_theory.function.conditional_expectation.basic
/-!
# Conditional expectation of indicator functions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file proves some results about the conditional expectation of an indicator function and
as a corollary, also proves several results about the behaviour of the conditional expectation on
a restricted measure.
## Main result
* `measure_theory.condexp_indicator`: If `s` is a `m`-measurable set, then the conditional
expectation of the indicator function of `s` is almost everywhere equal to the indicator
of `s` of the conditional expectation. Namely, `𝔼[s.indicator f | m] = s.indicator 𝔼[f | m]` a.e.
-/
noncomputable theory
open topological_space measure_theory.Lp filter continuous_linear_map
open_locale nnreal ennreal topology big_operators measure_theory
namespace measure_theory
variables {α 𝕜 E : Type*} {m m0 : measurable_space α}
[normed_add_comm_group E] [normed_space ℝ E] [complete_space E]
{μ : measure α} {f : α → E} {s : set α}
lemma condexp_ae_eq_restrict_zero (hs : measurable_set[m] s) (hf : f =ᵐ[μ.restrict s] 0) :
μ[f | m] =ᵐ[μ.restrict s] 0 :=
begin
by_cases hm : m ≤ m0,
swap, { simp_rw condexp_of_not_le hm, },
by_cases hμm : sigma_finite (μ.trim hm),
swap, { simp_rw condexp_of_not_sigma_finite hm hμm, },
haveI : sigma_finite (μ.trim hm) := hμm,
haveI : sigma_finite ((μ.restrict s).trim hm),
{ rw ← restrict_trim hm _ hs,
exact restrict.sigma_finite _ s, },
by_cases hf_int : integrable f μ,
swap, { rw condexp_undef hf_int, },
refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' hm _ _ _ _ _,
{ exact λ t ht hμt, integrable_condexp.integrable_on.integrable_on, },
{ exact λ t ht hμt, (integrable_zero _ _ _).integrable_on, },
{ intros t ht hμt,
rw [measure.restrict_restrict (hm _ ht), set_integral_condexp hm hf_int (ht.inter hs),
← measure.restrict_restrict (hm _ ht)],
refine set_integral_congr_ae (hm _ ht) _,
filter_upwards [hf] with x hx h using hx, },
{ exact strongly_measurable_condexp.ae_strongly_measurable', },
{ exact strongly_measurable_zero.ae_strongly_measurable', },
end
/-- Auxiliary lemma for `condexp_indicator`. -/
lemma condexp_indicator_aux (hs : measurable_set[m] s) (hf : f =ᵐ[μ.restrict sᶜ] 0) :
μ[s.indicator f | m] =ᵐ[μ] s.indicator (μ[f | m]) :=
begin
by_cases hm : m ≤ m0,
swap, { simp_rw [condexp_of_not_le hm, set.indicator_zero'], },
have hsf_zero : ∀ g : α → E, g =ᵐ[μ.restrict sᶜ] 0 → s.indicator g =ᵐ[μ] g,
from λ g, indicator_ae_eq_of_restrict_compl_ae_eq_zero (hm _ hs),
refine ((hsf_zero (μ[f | m]) (condexp_ae_eq_restrict_zero hs.compl hf)).trans _).symm,
exact condexp_congr_ae (hsf_zero f hf).symm,
end
/-- The conditional expectation of the indicator of a function over an `m`-measurable set with
respect to the σ-algebra `m` is a.e. equal to the indicator of the conditional expectation. -/
lemma condexp_indicator (hf_int : integrable f μ) (hs : measurable_set[m] s) :
μ[s.indicator f | m] =ᵐ[μ] s.indicator (μ[f | m]) :=
begin
by_cases hm : m ≤ m0,
swap, { simp_rw [condexp_of_not_le hm, set.indicator_zero'], },
by_cases hμm : sigma_finite (μ.trim hm),
swap, { simp_rw [condexp_of_not_sigma_finite hm hμm, set.indicator_zero'], },
haveI : sigma_finite (μ.trim hm) := hμm,
-- use `have` to perform what should be the first calc step because of an error I don't
-- understand
have : s.indicator (μ[f|m]) =ᵐ[μ] s.indicator (μ[s.indicator f + sᶜ.indicator f|m]),
by rw set.indicator_self_add_compl s f,
refine (this.trans _).symm,
calc s.indicator (μ[s.indicator f + sᶜ.indicator f|m])
=ᵐ[μ] s.indicator (μ[s.indicator f|m] + μ[sᶜ.indicator f|m]) :
begin
have : μ[s.indicator f + sᶜ.indicator f|m] =ᵐ[μ] μ[s.indicator f|m] + μ[sᶜ.indicator f|m],
from condexp_add (hf_int.indicator (hm _ hs)) (hf_int.indicator (hm _ hs.compl)),
filter_upwards [this] with x hx,
classical,
rw [set.indicator_apply, set.indicator_apply, hx],
end
... = s.indicator (μ[s.indicator f|m]) + s.indicator (μ[sᶜ.indicator f|m]) :
s.indicator_add' _ _
... =ᵐ[μ] s.indicator (μ[s.indicator f|m]) + s.indicator (sᶜ.indicator (μ[sᶜ.indicator f|m])) :
begin
refine filter.eventually_eq.rfl.add _,
have : sᶜ.indicator (μ[sᶜ.indicator f|m]) =ᵐ[μ] μ[sᶜ.indicator f|m],
{ refine (condexp_indicator_aux hs.compl _).symm.trans _,
{ exact indicator_ae_eq_restrict_compl (hm _ hs.compl), },
{ rw [set.indicator_indicator, set.inter_self], }, },
filter_upwards [this] with x hx,
by_cases hxs : x ∈ s,
{ simp only [hx, hxs, set.indicator_of_mem], },
{ simp only [hxs, set.indicator_of_not_mem, not_false_iff], },
end
... =ᵐ[μ] s.indicator (μ[s.indicator f|m]) :
by rw [set.indicator_indicator, set.inter_compl_self, set.indicator_empty', add_zero]
... =ᵐ[μ] μ[s.indicator f|m] :
begin
refine (condexp_indicator_aux hs _).symm.trans _,
{ exact indicator_ae_eq_restrict_compl (hm _ hs), },
{ rw [set.indicator_indicator, set.inter_self], },
end
end
lemma condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [sigma_finite (μ.trim hm)]
(hs_m : measurable_set[m] s) (hf_int : integrable f μ) :
(μ.restrict s)[f | m] =ᵐ[μ.restrict s] μ[f | m] :=
begin
haveI : sigma_finite ((μ.restrict s).trim hm),
{ rw ← restrict_trim hm _ hs_m, apply_instance, },
rw ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m),
swap, { apply_instance, },
refine eventually_eq.trans _ (condexp_indicator hf_int hs_m),
refine ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _,
{ intros t ht hμt,
rw [← integrable_indicator_iff (hm _ ht), set.indicator_indicator, set.inter_comm,
← set.indicator_indicator],
suffices h_int_restrict : integrable (t.indicator ((μ.restrict s)[f|m])) (μ.restrict s),
{ rw [integrable_indicator_iff (hm _ hs_m), integrable_on],
rw [integrable_indicator_iff (hm _ ht), integrable_on] at h_int_restrict ⊢,
exact h_int_restrict, },
exact integrable_condexp.indicator (hm _ ht), },
{ intros t ht hμt,
calc ∫ x in t, s.indicator ((μ.restrict s)[f|m]) x ∂μ
= ∫ x in t, ((μ.restrict s)[f|m]) x ∂(μ.restrict s) :
by rw [integral_indicator (hm _ hs_m), measure.restrict_restrict (hm _ hs_m),
measure.restrict_restrict (hm _ ht), set.inter_comm]
... = ∫ x in t, f x ∂(μ.restrict s) : set_integral_condexp hm hf_int.integrable_on ht
... = ∫ x in t, s.indicator f x ∂μ :
by rw [integral_indicator (hm _ hs_m), measure.restrict_restrict (hm _ hs_m),
measure.restrict_restrict (hm _ ht), set.inter_comm], },
{ exact (strongly_measurable_condexp.indicator hs_m).ae_strongly_measurable', },
end
/-- If the restriction to a `m`-measurable set `s` of a σ-algebra `m` is equal to the restriction
to `s` of another σ-algebra `m₂` (hypothesis `hs`), then `μ[f | m] =ᵐ[μ.restrict s] μ[f | m₂]`. -/
lemma condexp_ae_eq_restrict_of_measurable_space_eq_on {m m₂ m0 : measurable_space α}
{μ : measure α} (hm : m ≤ m0) (hm₂ : m₂ ≤ m0)
[sigma_finite (μ.trim hm)] [sigma_finite (μ.trim hm₂)]
(hs_m : measurable_set[m] s) (hs : ∀ t, measurable_set[m] (s ∩ t) ↔ measurable_set[m₂] (s ∩ t)) :
μ[f | m] =ᵐ[μ.restrict s] μ[f | m₂] :=
begin
rw ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m),
have hs_m₂ : measurable_set[m₂] s,
{ rwa [← set.inter_univ s, ← hs set.univ, set.inter_univ], },
by_cases hf_int : integrable f μ,
swap, { simp_rw condexp_undef hf_int, },
refine ((condexp_indicator hf_int hs_m).symm.trans _).trans (condexp_indicator hf_int hs_m₂),
refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' hm₂
(λ s hs hμs, integrable_condexp.integrable_on)
(λ s hs hμs, integrable_condexp.integrable_on) _ _
strongly_measurable_condexp.ae_strongly_measurable',
swap,
{ have : strongly_measurable[m] (μ[s.indicator f | m]) := strongly_measurable_condexp,
refine this.ae_strongly_measurable'.ae_strongly_measurable'_of_measurable_space_le_on
hm hs_m (λ t, (hs t).mp) _,
exact condexp_ae_eq_restrict_zero hs_m.compl (indicator_ae_eq_restrict_compl (hm _ hs_m)), },
intros t ht hμt,
have : ∫ x in t, μ[s.indicator f|m] x ∂μ = ∫ x in s ∩ t, μ[s.indicator f|m] x ∂μ,
{ rw ← integral_add_compl (hm _ hs_m) integrable_condexp.integrable_on,
suffices : ∫ x in sᶜ, μ[s.indicator f|m] x ∂μ.restrict t = 0,
by rw [this, add_zero, measure.restrict_restrict (hm _ hs_m)],
rw measure.restrict_restrict (measurable_set.compl (hm _ hs_m)),
suffices : μ[s.indicator f|m] =ᵐ[μ.restrict sᶜ] 0,
{ rw [set.inter_comm, ← measure.restrict_restrict (hm₂ _ ht)],
calc ∫ (x : α) in t, μ[s.indicator f|m] x ∂μ.restrict sᶜ
= ∫ (x : α) in t, 0 ∂μ.restrict sᶜ : begin
refine set_integral_congr_ae (hm₂ _ ht) _,
filter_upwards [this] with x hx h using hx,
end
... = 0 : integral_zero _ _, },
refine condexp_ae_eq_restrict_zero hs_m.compl _,
exact indicator_ae_eq_restrict_compl (hm _ hs_m), },
have hst_m : measurable_set[m] (s ∩ t) := (hs _).mpr (hs_m₂.inter ht),
simp_rw [this, set_integral_condexp hm₂ (hf_int.indicator (hm _ hs_m)) ht,
set_integral_condexp hm (hf_int.indicator (hm _ hs_m)) hst_m,
integral_indicator (hm _ hs_m), measure.restrict_restrict (hm _ hs_m),
← set.inter_assoc, set.inter_self],
end
end measure_theory
|
e3363a50f6760b3a08abeacfd9b8bc0bdeb3a350 | 7d5ad87afb17e514aee234fcf0a24412eed6384f | /src/normal.lean | 0e5203aa6a78dce9e6e6ea10c872377629449994 | [] | no_license | digama0/flypitch | 764f849eaef59c045dfbeca142a0f827973e70c1 | 2ec14b8da6a3964f09521d17e51f363d255b030f | refs/heads/master | 1,586,980,069,651 | 1,547,078,141,000 | 1,547,078,283,000 | 164,965,135 | 1 | 0 | null | 1,547,082,858,000 | 1,547,082,857,000 | null | UTF-8 | Lean | false | false | 2,376 | lean | import .fol tactic.tidy
open fol
local notation h :: t := dvector.cons h t
local notation `[]` := dvector.nil
local notation `[` l:(foldr `, ` (h t, dvector.cons h t) dvector.nil `]`) := l
namespace nnf
section
/- Recurse through a formula, rewriting f ⟹ ⊥ to (∼f) when possible -/
def not_rewrite {L} : ∀{l}, preformula L l → preformula L l
| l falsum := falsum
| l (t₁ ≃ t₂) := t₁ ≃ t₂
| l (rel R) := rel R
| l (apprel f t) := apprel f t
| l (f ⟹ falsum) := (∼f)
| l (f ⟹ g) := (not_rewrite f) ⟹ (not_rewrite g)
| l (∀' f) := ∀' not_rewrite f
/- Recurse through a formula, rewriting ∼(f ⟹ ∼g) to f ⊓ g -/
def and_rewrite {L} : ∀{l}, preformula L l → preformula L l
| l falsum := falsum
| l (t₁ ≃ t₂) := t₁ ≃ t₂
| l (rel R) := rel R
| l (apprel f t) := apprel f t
--| l ∼(f ⟹ (∼ g)) := f ⊓ g -- this pattern makes the equation compiler complain
| l ((f ⟹ (g ⟹ falsum)) ⟹ falsum) := f ⊓ g
| l (f ⟹ g) := (and_rewrite f) ⟹ (and_rewrite g)
| l (∀' f) := ∀' and_rewrite f
def or_rewrite {L} : ∀{l}, preformula L l → preformula L l
| l falsum := falsum
| l (t₁ ≃ t₂) := t₁ ≃ t₂
| l (rel R) := rel R
| l (apprel f t) := apprel f t
| l ((f ⟹ falsum) ⟹ g) := f ⊔ g
| l (f ⟹ g) := (or_rewrite f) ⟹ (or_rewrite g)
| l (∀' f) := ∀' or_rewrite f
def imp_rewrite {L} : ∀{l}, preformula L l → preformula L l
| l falsum := falsum
| l (t₁ ≃ t₂) := t₁ ≃ t₂
| l (rel R) := rel R
| l (apprel f t) := apprel f t
| l (f ⟹ g) := ∼(imp_rewrite f) ⊔ (imp_rewrite g)
| l (∀' f) := ∀' imp_rewrite f
lemma neg_rewrite_sanity_check {L} {f : formula L} : not_rewrite (f ⟹ ⊥) = (∼f) :=
by {conv {to_lhs, rw[not_rewrite]}}
lemma and_rewrite_sanity_check {L} {f g : formula L} : and_rewrite ∼(f ⟹ (∼g)) = f ⊓ g :=
by {conv {to_lhs, simp[fol.not], rw[and_rewrite]}}
--the simp[fol.not] is unfortunate, but the equation compiler doesn't let me use `∼` in and_rewrite
/- To put formulas into normal form,
1. replace implication with material implication, and
2. simplify with de-morgan's laws
maybe hijack the simplifier?
-/
end
end nnf
|
a4acafba06fa3ce6758b3d4b915d2ce4338074da | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/bad_inaccessible.lean | b3705fba618e111e0e55674fa0e879a8b864bd76 | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 484 | lean | universe variables u
definition f : nat → nat → nat
| a .a := a
definition f : ∀ (a b c : nat), a = c → c = a
| a b .b rfl := rfl
inductive vec (A : Type u) : nat → Type (max 1 u)
| nil {} : vec 0
| cons : Π {n}, A → vec n → vec (n+1)
definition foo (A : Type u) (f : A → A → A) : Π {n}, vec A n → vec A n → vec A n
| ._ vec.nil vec.nil := vec.nil
| ._ (vec.cons a₁ l₁) (vec.cons a₂ l₂) := vec.cons (f a₁ a₂) (foo l₁ l₂)
|
246e9ab773abc04614281b9ebc31d18835e9bffc | 38ee9024fb5974f555fb578fcf5a5a7b71e669b5 | /Mathlib/Data/Int/Basic.lean | 4fec5e2b28254d4fc806cfa959791628e73e2b86 | [
"Apache-2.0"
] | permissive | denayd/mathlib4 | 750e0dcd106554640a1ac701e51517501a574715 | 7f40a5c514066801ab3c6d431e9f405baa9b9c58 | refs/heads/master | 1,693,743,991,894 | 1,636,618,048,000 | 1,636,618,048,000 | 373,926,241 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 18,251 | lean | /-
Ported by Deniz Aydin from the lean3 prelude's data/int/basic.lean. Should be in a "prelude"
https://github.com/leanprover-community/lean/blob/master/library/init/data/int/basic.lean
Original file license:
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Data.Nat.Basic
import Mathlib.Tactic.Coe
open Nat
/- ## Additional notation -/
notation "ℤ" => Int
notation "-[1+ " n "]" => Int.negSucc n
namespace Int
lemma ofNat_zero : ofNat (0 : ℕ) = (0 : ℤ) := rfl
lemma ofNat_one : ofNat (1 : ℕ) = (1 : ℤ) := rfl
/- ## Definitions of basic functions -/
lemma subNatNat_of_sub_eq_zero {m n : ℕ} (h : n - m = 0) : subNatNat m n = ofNat (m - n) := by
show (match (n - m) with -- No `unfold` so I do this
| 0 => ofNat (m-n)
| succ k => -[1+ k]
) = ofNat (m - n)
rw [h]
lemma subNatNat_of_sub_eq_succ {m n k : ℕ} (h : n - m = succ k) : subNatNat m n = -[1+ k] := by
show (match n - m with
| 0 => ofNat (m - n)
| succ k => -[1+ k]) =
-[1+ k]
rw [h]
protected lemma neg_zero : -(0:ℤ) = 0 := rfl
lemma ofNat_add (n m : ℕ) : ofNat (n + m) = ofNat n + ofNat m := rfl
lemma ofNat_mul (n m : ℕ) : ofNat (n * m) = ofNat n * ofNat m := rfl
lemma ofNat_succ (n : ℕ) : ofNat (succ n) = ofNat n + 1 := rfl
lemma neg_ofNat_zero : -(ofNat 0) = 0 := rfl
lemma neg_ofNat_of_succ (n : ℕ) : -(ofNat (succ n)) = -[1+ n] := rfl
lemma neg_neg_ofNat_succ (n : ℕ) : -(-[1+ n]) = ofNat (succ n) := rfl
lemma negSucc_ofNat_coe (n : ℕ) : -[1+ n] = -↑(n + 1) := rfl
/- ## These are only for internal use -/
lemma ofNat_add_ofNat (m n : ℕ) :
ofNat m + ofNat n = ofNat (m + n) := rfl
lemma ofNat_add_negSucc_ofNat (m n : ℕ) :
ofNat m + -[1+ n] = subNatNat m (succ n) := rfl
lemma negSucc_ofNat_add_ofNat (m n : ℕ) :
-[1+ m] + ofNat n = subNatNat n (succ m) := rfl
lemma negSucc_ofNat_add_negSucc_ofNat (m n : ℕ) :
-[1+ m] + -[1+ n] = -[1+ succ (m + n)] := rfl
lemma ofNat_mul_ofNat (m n : ℕ) :
ofNat m * ofNat n = ofNat (m * n) := rfl
lemma ofNat_mul_negSucc_ofNat (m n : ℕ) :
ofNat m * -[1+ n] = negOfNat (m * succ n) := rfl
lemma negSucc_ofNat_ofNat (m n : ℕ) :
-[1+ m] * ofNat n = negOfNat (succ m * n) := rfl
lemma mul_negSucc_ofNat_negSucc_ofNat (m n : ℕ) :
-[1+ m] * -[1+ n] = ofNat (succ m * succ n) := rfl
attribute [local simp] ofNat_add_ofNat ofNat_mul_ofNat neg_ofNat_zero neg_ofNat_of_succ
neg_neg_ofNat_succ ofNat_add_negSucc_ofNat negSucc_ofNat_add_ofNat
negSucc_ofNat_add_negSucc_ofNat ofNat_mul_negSucc_ofNat negSucc_ofNat_ofNat
mul_negSucc_ofNat_negSucc_ofNat
/- ## some basic functions and properties -/
protected lemma coe_nat_inj {m n : ℕ} (h : (↑m : ℤ) = ↑n) : m = n :=
Int.ofNat.inj h
lemma ofNat_eq_ofNat_iff (m n : ℕ) : ofNat m = ofNat n ↔ m = n :=
Iff.intro Int.ofNat.inj (congr_arg _)
lemma negSucc_ofNat_inj_iff {m n : ℕ} : negSucc m = negSucc n ↔ m = n :=
⟨Int.negSucc.inj, λ H => by simp [H]⟩
lemma negSucc_ofNat_eq (n : ℕ) : -[1+ n] = -((↑n) + 1) := rfl
/- ## neg -/
protected lemma neg_neg : ∀ a : ℤ, -(-a) = a
| ofNat 0 => rfl
| ofNat (n+1) => rfl
| -[1+ n] => rfl
protected lemma neg_inj {a b : ℤ} (h : -a = -b) : a = b :=
by rw [← Int.neg_neg a, ← Int.neg_neg b, h]
protected lemma sub_eq_add_neg {a b : ℤ} : a - b = a + -b := rfl
/- ## basic properties of subNatNat -/
lemma subNatNat_elim (m n : ℕ) (P : ℕ → ℕ → ℤ → Prop)
(hp : ∀i n, P (n + i) n (ofNat i))
(hn : ∀i m, P m (m + i + 1) (-[1+ i])) :
P m n (subNatNat m n) :=
by
have H : ∀ k , n - m = k → P m n (match n - m with | 0 => ofNat (m - n) | succ k => -[1+ k] : ℤ) := by
intros k h
cases k with
| zero =>
have ⟨k, h⟩ := (Nat.le.dest (Nat.le_of_sub_eq_zero h))
rw [h.symm, Nat.add_sub_cancel_left, Nat.sub_self_add]
apply hp
| succ k =>
simp
have hle : m ≤ n := Nat.le_of_lt (Nat.lt_of_sub_eq_succ h)
rw [Nat.sub_eq_iff_eq_add hle] at h
rw [h, Nat.add_comm, Nat.add_sub_cancel_left]
apply hn
exact H _ rfl
lemma subNatNat_add_left {m n : ℕ} :
subNatNat (m + n) m = ofNat n :=
by
change (match m - (m + n) with
| 0 => ofNat (m + n - m)
| succ k => -[1+ k]) = ofNat n
rw [Nat.sub_eq_zero_of_le (Nat.le_add_right _ _)]
rw [Nat.add_sub_cancel_left]
lemma subNatNat_add_right {m n : ℕ} : subNatNat m (m + n + 1) = negSucc n := by
change (match m + n + 1 - m with
| 0 => ofNat (m - (m + n + 1))
| succ k => -[1+ k]) = negSucc n
simp
rw [Nat.add_assoc, Nat.add_one, Nat.add_sub_cancel_left]
lemma subNatNat_add_add (m n k : ℕ) : subNatNat (m + k) (n + k) = subNatNat m n :=
subNatNat_elim m n (λm n i => subNatNat (m + k) (n + k) = i)
(by
intros i j
rw [Nat.add_assoc, Nat.add_comm i k, ← Nat.add_assoc]
exact subNatNat_add_left
)
(by
intros i j
rw [Nat.add_assoc j i 1, Nat.add_comm j (i+1), Nat.add_assoc, Nat.add_comm (i+1) (j+k)]
exact subNatNat_add_right
)
lemma subNatNat_of_le {m n : ℕ} (h : n ≤ m) : subNatNat m n = ofNat (m - n) :=
subNatNat_of_sub_eq_zero (Nat.sub_eq_zero_of_le h)
lemma subNatNat_of_lt {m n : ℕ} (h : m < n) : subNatNat m n = -[1+ pred (n - m)] := by
rw [subNatNat_of_sub_eq_succ]
rw [Nat.succ_pred_eq_of_pos (Nat.sub_pos_of_lt h)]
/- ## natAbs -/
lemma natAbs_ofNat (n : ℕ) : natAbs ↑n = n := rfl
lemma eq_zero_ofNatAbs_eq_zero : ∀ {a : ℤ}, natAbs a = 0 → a = 0
| (ofNat _), H => congr_arg ofNat H
| -[1+ _], H => absurd H (succ_ne_zero _)
lemma natAbs_pos_of_ne_zero {a : ℤ} (h : a ≠ 0) : 0 < natAbs a :=
(eq_zero_or_pos _).resolve_left $ mt eq_zero_ofNatAbs_eq_zero h
lemma natAbs_zero : natAbs (0 : ℤ) = (0 : ℕ) := rfl
lemma natAbs_one : natAbs (1 : ℤ) = (1 : ℕ) := rfl
lemma natAbs_mul_self : ∀ {a : ℤ}, ↑(natAbs a * natAbs a) = a * a
| (ofNat _) => rfl
| -[1+ _] => rfl
@[simp] lemma natAbs_neg (a : ℤ) : natAbs (-a) = natAbs a := match a with
| (ofNat zero) => rfl
| (ofNat (succ _)) => rfl
| (negSucc _) => rfl
lemma natAbs_eq : ∀ (a : ℤ), a = natAbs a ∨ a = -↑(natAbs a)
| (ofNat _) => Or.inl rfl
| -[1+ _] => Or.inr rfl
lemma eq_x_or_neg (a : ℤ) : ∃n : ℕ, a = n ∨ a = -↑n := ⟨_, natAbs_eq a⟩
/- ## sign -/
def sign : ℤ → ℤ
| (n+1:ℕ) => 1
| 0 => 0
| -[1+ n] => -1
@[simp] theorem sign_zero : sign 0 = 0 := rfl
@[simp] theorem sign_one : sign 1 = 1 := rfl
@[simp] theorem sign_neg_one : sign (-1) = -1 := rfl
/- ## Quotient and remainder
There are three main conventions for integer division,
referred here as the E, F, T rounding conventions.
All three pairs satisfy the identity x % y + (x / y) * y = x
unconditionally. -/
-- E-rounding (`div` and `mod` defined in core) satisfy 0 ≤ mod x y < natAbs y for y ≠ 0
-- F-rounding: This pair satisfies fdiv x y = floor (x / y)
def fdiv : ℤ → ℤ → ℤ
| 0, _ => 0
| (m : ℕ), (n : ℕ) => ofNat (m / n)
| (m+1:ℕ), -[1+ n] => -[1+ m / succ n]
| -[1+ m], 0 => 0
| -[1+ m], (n+1:ℕ) => -[1+ m / succ n]
| -[1+ m], -[1+ n] => ofNat (succ m / succ n)
def fmod : ℤ → ℤ → ℤ
| 0, _ => 0
| (m : ℕ), (n : ℕ) => ofNat (m % n)
| (m+1:ℕ), -[1+ n] => subNatNat (m % succ n) n
| -[1+ m], (n : ℕ) => subNatNat n (succ (m % n))
| -[1+ m], -[1+ n] => -ofNat (succ m % succ n)
-- T-rounding: This pair satisfies quot x y = round_to_zero (x / y)
def quot : ℤ → ℤ → ℤ
| (m : ℕ), (n : ℕ) => ofNat (m / n)
| (m : ℕ), -[1+ n] => -ofNat (m / succ n)
| -[1+ m], (n : ℕ) => -ofNat (succ m / n)
| -[1+ m], -[1+ n] => ofNat (succ m / succ n)
def rem : ℤ → ℤ → ℤ
| (m : ℕ), (n : ℕ) => ofNat (m % n)
| (m : ℕ), -[1+ n] => ofNat (m % succ n)
| -[1+ m], (n : ℕ) => -ofNat (succ m % n)
| -[1+ m], -[1+ n] => -ofNat (succ m % succ n)
/- ## gcd -/
def gcd (m n : ℤ) : ℕ := Nat.gcd (natAbs m) (natAbs n)
/- # ring properties -/
/- addition -/
protected lemma add_comm : ∀ a b : ℤ, a + b = b + a
| (n : ℕ), (m : ℕ) => by simp [Nat.add_comm]
| (_ : ℕ), -[1+ _] => rfl
| -[1+ _], (_ : ℕ) => rfl
| -[1+ _], -[1+ _] => by simp [Nat.add_comm]
protected lemma add_zero : ∀ a : ℤ, a + 0 = a
| (ofNat n) => rfl
| -[1+ n] => rfl
protected lemma zero_add (a : ℤ) : 0 + a = a := Int.add_comm a 0 ▸ Int.add_zero a
lemma subNatNat_sub {m n : ℕ} (h : n ≤ m) (k : ℕ) :
subNatNat (m - n) k = subNatNat m (k + n) := by
rwa [← subNatNat_add_add _ _ n, Nat.sub_add_cancel]
lemma subNatNat_add (m n k : ℕ) : subNatNat (m + n) k = ofNat m + subNatNat n k :=
by
have h := Nat.lt_or_ge n k
cases h with
| inl h' =>
rw [subNatNat_of_lt h']
simp
rw [succ_pred_eq_of_pos (Nat.sub_pos_of_lt h')]
apply Eq.trans
rw [← Nat.sub_add_cancel (Nat.le_of_lt h')]
apply subNatNat_add_add
| inr h' =>
rw [subNatNat_of_le (h')]
have h₂ : k ≤ m + n := Nat.le_trans h' (le_add_left _ _)
rw [subNatNat_of_le h₂]
simp
rw [Nat.add_sub_assoc h']
lemma subNatNat_add_negSucc_ofNat (m n k : ℕ) :
subNatNat m n + -[1+ k] = subNatNat m (n + succ k) :=
by
have h := Nat.lt_or_ge m n
cases h with
| inr h' =>
rw [subNatNat_of_le h']
simp
rw [subNatNat_sub h', Nat.add_comm]
| inl h' =>
have h₂ : m < n + succ k := Nat.lt_of_lt_of_le h' (le_add_right _ _)
have h₃ : m ≤ n + k := le_of_succ_le_succ h₂
rw [subNatNat_of_lt h', subNatNat_of_lt h₂]
simp [Nat.add_comm]
rw [← add_succ, succ_pred_eq_of_pos (Nat.sub_pos_of_lt h'), add_succ, succ_sub h₃, pred_succ]
rw [Nat.add_comm n, Nat.add_sub_assoc (Nat.le_of_lt h')]
lemma add_assoc_aux1 (m n : ℕ) :
∀ c : ℤ, ofNat m + ofNat n + c = ofNat m + (ofNat n + c)
| (ofNat k) => by simp [Nat.add_assoc]
| -[1+ k] => by simp [subNatNat_add]
lemma add_assoc_aux2 (m n k : ℕ) :
-[1+ m] + -[1+ n] + ofNat k = -[1+ m] + (-[1+ n] + ofNat k) :=
by
simp [add_succ]
rw [Int.add_comm, subNatNat_add_negSucc_ofNat]
simp [add_succ, succ_add, Nat.add_comm]
protected lemma add_assoc : ∀ a b c : ℤ, a + b + c = a + (b + c)
| (ofNat m), (ofNat n), c => add_assoc_aux1 _ _ _
| (ofNat m), b, (ofNat k) => by
rw [Int.add_comm, ← add_assoc_aux1, Int.add_comm k, add_assoc_aux1, Int.add_comm b]
| a, (ofNat n), (ofNat k) => by
rw [Int.add_comm, Int.add_comm a, ← add_assoc_aux1, Int.add_comm a, Int.add_comm (ofNat k)]
| -[1+ m], -[1+ n], (ofNat k) => add_assoc_aux2 _ _ _
| -[1+ m], (ofNat n), -[1+ k] => by
rw [Int.add_comm, ← add_assoc_aux2, Int.add_comm n, ← add_assoc_aux2, Int.add_comm -[1+ m]]
| (ofNat m), -[1+ n], -[1+ k] => by
rw [Int.add_comm, Int.add_comm (ofNat m), Int.add_comm m, ← add_assoc_aux2, Int.add_comm -[1+ k]]
| -[1+ m], -[1+ n], -[1+ k] => by
simp [add_succ, Nat.add_comm, Nat.add_left_comm, neg_ofNat_of_succ]
/- ## negation -/
lemma sub_nat_self : ∀ n, subNatNat n n = 0
| 0 => rfl
| (succ m) => by
rw [subNatNat_of_sub_eq_zero, Nat.sub_self, ofNat_zero]
rw [Nat.sub_self]
attribute [local simp] sub_nat_self
protected lemma add_left_neg : ∀ a : ℤ, -a + a = 0
| (ofNat 0) => rfl
| (ofNat (succ m)) => by simp
| -[1+ m] => by simp
protected lemma add_right_neg (a : ℤ) : a + -a = 0 :=
by rw [Int.add_comm, Int.add_left_neg]
/- ## multiplication -/
protected lemma mul_comm : ∀ a b : ℤ, a * b = b * a
| a, b => by cases a <;> cases b <;> simp [Nat.mul_comm]
lemma ofNat_mul_negOfNat (m : ℕ) : ∀ n, ofNat m * negOfNat n = negOfNat (m * n)
| 0 => rfl
| (succ n) => rfl
lemma negOfNat_mul_ofNat (m n : ℕ) : negOfNat m * ofNat n = negOfNat (m * n) := by
rw [Int.mul_comm]
simp [ofNat_mul_negOfNat, Nat.mul_comm]
lemma negSucc_ofNat_mul_negOfNat (m : ℕ) :
∀ n, -[1+ m] * negOfNat n = ofNat (succ m * n)
| 0 => rfl
| (succ n) => rfl
lemma negOfNat_mul_negSucc_ofNat (m n : ℕ) :
negOfNat n * -[1+ m] = ofNat (n * succ m) := by
rw [Int.mul_comm, negSucc_ofNat_mul_negOfNat, Nat.mul_comm]
attribute [local simp] ofNat_mul_negOfNat negOfNat_mul_ofNat
negSucc_ofNat_mul_negOfNat negOfNat_mul_negSucc_ofNat
protected lemma mul_assoc : ∀ a b c : ℤ, a * b * c = a * (b * c)
| a, b, c => by cases a <;> cases b <;> cases c <;> simp [Nat.mul_assoc]
protected lemma mul_zero : ∀ (a : ℤ), a * 0 = 0
| (ofNat m) => rfl
| -[1+ m] => rfl
protected lemma zero_mul (a : ℤ) : 0 * a = 0 :=
Int.mul_comm a 0 ▸ Int.mul_zero a
lemma negOfNat_eq_subNatNat_zero : ∀ n, negOfNat n = subNatNat 0 n
| 0 => rfl
| (succ n) => rfl
lemma ofNat_mul_subNatNat (m n k : ℕ) :
ofNat m * subNatNat n k = subNatNat (m * n) (m * k) :=
by
cases m with
| zero =>
simp [ofNat_zero, Int.zero_mul, Nat.zero_mul]
| succ m =>
have h := Nat.lt_or_ge n k
cases h with
| inl h =>
have h' : (succ m) * n < (succ m) * k := Nat.mul_lt_mul_of_pos_left h (Nat.succ_pos m)
rw [subNatNat_of_lt h, subNatNat_of_lt h']
simp
rw [succ_pred_eq_of_pos (Nat.sub_pos_of_lt h)]
rw [← neg_ofNat_of_succ, Nat.mul_sub_left_distrib]
rw [← succ_pred_eq_of_pos (Nat.sub_pos_of_lt h')]
rfl
| inr h =>
have h' : (succ m) * k ≤ (succ m) * n := Nat.mul_le_mul_left _ h
rw [subNatNat_of_le h, subNatNat_of_le h']
simp
rw [Nat.mul_sub_left_distrib]
lemma negOfNat_add : ∀ m n : ℕ, negOfNat m + negOfNat n = negOfNat (m + n)
| zero, zero => by simp
| zero, succ n => by simp [Nat.zero_add]; rfl
| succ m, zero => by simp; rfl
| succ m, succ n => by simp [Nat.succ_add]; rfl
lemma negSucc_ofNat_mul_subNatNat (m n k : ℕ) :
-[1+ m] * subNatNat n k = subNatNat (succ m * k) (succ m * n) :=
by
have h := Nat.lt_or_ge n k
cases h with
| inl h =>
have h' : succ m * n < succ m * k := Nat.mul_lt_mul_of_pos_left h (Nat.succ_pos m)
rw [subNatNat_of_lt h, subNatNat_of_le (Nat.le_of_lt h')]
simp [succ_pred_eq_of_pos (Nat.sub_pos_of_lt h), Nat.mul_sub_left_distrib]
| inr h =>
cases Nat.lt_or_ge k n with
| inl h' =>
have h₁ : succ m * n > succ m * k := Nat.mul_lt_mul_of_pos_left h' (Nat.succ_pos m)
rw [subNatNat_of_le h, subNatNat_of_lt h₁]
simp [Nat.mul_sub_left_distrib, Nat.mul_comm]
rw [Nat.mul_comm k, Nat.mul_comm n, ← succ_pred_eq_of_pos (Nat.sub_pos_of_lt h₁),
← neg_ofNat_of_succ]
rfl
| inr h' =>
rw [Nat.le_antisymm h h']
simp
rfl
attribute [local simp] ofNat_mul_subNatNat negOfNat_add negSucc_ofNat_mul_subNatNat
protected lemma distrib_left : ∀ a b c : ℤ, a * (b + c) = a * b + a * c
| (ofNat m), (ofNat n), (ofNat k) => by simp [Nat.left_distrib]
| (ofNat m), (ofNat n), -[1+ k] => by simp [negOfNat_eq_subNatNat_zero] rw [← subNatNat_add] rfl
| (ofNat m), -[1+ n], (ofNat k) => by simp [negOfNat_eq_subNatNat_zero] rw [Int.add_comm, ← subNatNat_add] rfl
| (ofNat m), -[1+ n], -[1+ k] => by simp rw [← Nat.left_distrib, succ_add] rfl
| -[1+ m], (ofNat n), (ofNat k) => by simp [Nat.mul_comm] rw [← Nat.right_distrib, Nat.mul_comm]
| -[1+ m], (ofNat n), -[1+ k] => by simp [negOfNat_eq_subNatNat_zero] rw [Int.add_comm, ← subNatNat_add] rfl
| -[1+ m], -[1+ n], (ofNat k) => by simp [negOfNat_eq_subNatNat_zero] rw [← subNatNat_add] rfl
| -[1+ m], -[1+ n], -[1+ k] => by simp rw [← Nat.left_distrib, succ_add] rfl
protected lemma distrib_right (a b c : ℤ) : (a + b) * c = a * c + b * c :=
by simp [Int.mul_comm, Int.distrib_left]
protected lemma zero_ne_one : (0 : ℤ) ≠ 1 := λ h => Int.noConfusion h fun.
lemma ofNat_sub {n m : ℕ} (h : m ≤ n) : ofNat (n - m) = ofNat n - ofNat m := by
show ofNat (n - m) = ofNat n + negOfNat m
match m, h with
| 0, h =>
rfl
| succ m, h =>
show ofNat (n - succ m) = subNatNat n (succ m)
simp [subNatNat, subNatNat] -- TODO: How to avoid having to simp through rename definitions to unfold them?
rw [Nat.sub_eq_zero_of_le h]
protected lemma add_left_comm (a b c : ℤ) : a + (b + c) = b + (a + c) :=
by rw [← Int.add_assoc, Int.add_comm a, Int.add_assoc]
protected lemma add_left_cancel {a b c : ℤ} (h : a + b = a + c) : b = c := by
have h₁ : -a + (a + b) = -a + (a + c) := by rw [h]
rwa [← Int.add_assoc, ← Int.add_assoc, Int.add_left_neg, Int.zero_add, Int.zero_add] at h₁
protected lemma neg_add {a b : ℤ} : - (a + b) = -a + -b := by
have h₁ : - (a + b) = -(a + b) + (a + b) + -a + -b := by
rw [Int.add_assoc, Int.add_comm (-a), Int.add_assoc, Int.add_assoc, ← Int.add_assoc b]
rw [Int.add_right_neg, Int.zero_add, Int.add_right_neg, Int.add_zero]
rwa [Int.add_left_neg, Int.zero_add] at h₁
lemma negSucc_ofNat_coe' (n : ℕ) : -[1+ n] = -↑n - 1 :=
by rw [Int.sub_eq_add_neg, ← Int.neg_add]; rfl
protected lemma coe_nat_sub {n m : ℕ} : n ≤ m → (↑(m - n) : ℤ) = ↑m - ↑n := ofNat_sub
protected lemma subNatNat_eq_coe {m n : ℕ} : subNatNat m n = ↑m - ↑n := by
refine subNatNat_elim m n (fun m n i => i = ↑m - ↑n) ?p ?n
case p =>
intros i n
simp only [Int.ofNat_add, Int.add_left_comm, Int.add_assoc, Int.add_right_neg, Int.sub_eq_add_neg]
rfl
case n =>
intros i n
simp only [negSucc_ofNat_coe, ofNat_add, Int.sub_eq_add_neg, Int.neg_add, ← Int.add_assoc]
rw [← @Int.sub_eq_add_neg n, ← ofNat_sub, Nat.sub_self, ofNat_zero, Int.zero_add]
apply Nat.le_refl
theorem toNat_sub (m n : ℕ) : toNat (m - n : ℕ) = m - n := rfl
protected lemma one_mul : ∀ (a : ℤ), (1 : ℤ) * a = a
| (ofNat n) => show ofNat (1 * n) = ofNat n by rw [Nat.one_mul]
| -[1+ n] => show -[1+ (1 * n)] = -[1+ n] by rw [Nat.one_mul]
protected lemma mul_one (a : ℤ) : a * 1 = a :=
by rw [Int.mul_comm, Int.one_mul]
protected lemma neg_eq_neg_one_mul : ∀ a : ℤ, -a = -1 * a
| (ofNat 0) => rfl
| (ofNat (n+1)) => show _ = -[1+ (1*n)+0] by rw [Nat.one_mul] rfl
| -[1+ n] => show _ = ofNat _ by rw [Nat.one_mul] rfl
theorem sign_mul_natAbs : ∀ (a : ℤ), sign a * natAbs a = a
| (n+1:ℕ) => Int.one_mul _
| 0 => rfl
| -[1+ n] => (Int.neg_eq_neg_one_mul _).symm
end Int
|
6ea8b0c650879894d8b888ec9c55b9d47148a10e | bb31430994044506fa42fd667e2d556327e18dfe | /src/analysis/normed_space/add_torsor_bases.lean | 87ed4056ec2a80aae9ad167c0fe8029999ca0559 | [
"Apache-2.0"
] | permissive | sgouezel/mathlib | 0cb4e5335a2ba189fa7af96d83a377f83270e503 | 00638177efd1b2534fc5269363ebf42a7871df9a | refs/heads/master | 1,674,527,483,042 | 1,673,665,568,000 | 1,673,665,568,000 | 119,598,202 | 0 | 0 | null | 1,517,348,647,000 | 1,517,348,646,000 | null | UTF-8 | Lean | false | false | 7,120 | lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import analysis.normed_space.finite_dimension
import analysis.calculus.affine_map
import analysis.convex.combination
import linear_algebra.affine_space.finite_dimensional
/-!
# Bases in normed affine spaces.
This file contains results about bases in normed affine spaces.
## Main definitions:
* `continuous_barycentric_coord`
* `is_open_map_barycentric_coord`
* `affine_basis.interior_convex_hull`
* `exists_subset_affine_independent_span_eq_top_of_open`
* `interior_convex_hull_nonempty_iff_affine_span_eq_top`
-/
section barycentric
variables {ι 𝕜 E P : Type*} [nontrivially_normed_field 𝕜] [complete_space 𝕜]
variables [normed_add_comm_group E] [normed_space 𝕜 E]
variables [metric_space P] [normed_add_torsor E P]
include E
lemma is_open_map_barycentric_coord [nontrivial ι] (b : affine_basis ι 𝕜 P) (i : ι) :
is_open_map (b.coord i) :=
affine_map.is_open_map_linear_iff.mp $ (b.coord i).linear.is_open_map_of_finite_dimensional $
(b.coord i).linear_surjective_iff.mpr (b.surjective_coord i)
variables [finite_dimensional 𝕜 E] (b : affine_basis ι 𝕜 P)
@[continuity]
lemma continuous_barycentric_coord (i : ι) : continuous (b.coord i) :=
(b.coord i).continuous_of_finite_dimensional
lemma smooth_barycentric_coord (b : affine_basis ι 𝕜 E) (i : ι) : cont_diff 𝕜 ⊤ (b.coord i) :=
(⟨b.coord i, continuous_barycentric_coord b i⟩ : E →A[𝕜] 𝕜).cont_diff
end barycentric
open set
/-- Given a finite-dimensional normed real vector space, the interior of the convex hull of an
affine basis is the set of points whose barycentric coordinates are strictly positive with respect
to this basis.
TODO Restate this result for affine spaces (instead of vector spaces) once the definition of
convexity is generalised to this setting. -/
lemma affine_basis.interior_convex_hull {ι E : Type*} [finite ι] [normed_add_comm_group E]
[normed_space ℝ E] (b : affine_basis ι ℝ E) :
interior (convex_hull ℝ (range b.points)) = {x | ∀ i, 0 < b.coord i x} :=
begin
casesI subsingleton_or_nontrivial ι,
{ -- The zero-dimensional case.
have : range (b.points) = univ,
from affine_subspace.eq_univ_of_subsingleton_span_eq_top (subsingleton_range _) b.tot,
simp [this] },
{ -- The positive-dimensional case.
haveI : finite_dimensional ℝ E := b.finite_dimensional,
have : convex_hull ℝ (range b.points) = ⋂ i, (b.coord i)⁻¹' Ici 0,
{ rw [convex_hull_affine_basis_eq_nonneg_barycentric b, set_of_forall], refl },
ext,
simp only [this, interior_Inter, ← is_open_map.preimage_interior_eq_interior_preimage
(is_open_map_barycentric_coord b _) (continuous_barycentric_coord b _),
interior_Ici, mem_Inter, mem_set_of_eq, mem_Ioi, mem_preimage], },
end
variables {V P : Type*} [normed_add_comm_group V] [normed_space ℝ V] [metric_space P]
[normed_add_torsor V P]
include V
open affine_map
/-- Given a set `s` of affine-independent points belonging to an open set `u`, we may extend `s` to
an affine basis, all of whose elements belong to `u`. -/
lemma is_open.exists_between_affine_independent_span_eq_top {s u : set P} (hu : is_open u)
(hsu : s ⊆ u) (hne : s.nonempty) (h : affine_independent ℝ (coe : s → P)) :
∃ t : set P, s ⊆ t ∧ t ⊆ u ∧ affine_independent ℝ (coe : t → P) ∧ affine_span ℝ t = ⊤ :=
begin
obtain ⟨q, hq⟩ := hne,
obtain ⟨ε, ε0, hεu⟩ := metric.nhds_basis_closed_ball.mem_iff.1 (hu.mem_nhds $ hsu hq),
obtain ⟨t, ht₁, ht₂, ht₃⟩ := exists_subset_affine_independent_affine_span_eq_top h,
let f : P → P := λ y, line_map q y (ε / dist y q),
have hf : ∀ y, f y ∈ u,
{ refine λ y, hεu _,
simp only [f],
rw [metric.mem_closed_ball, line_map_apply, dist_vadd_left, norm_smul, real.norm_eq_abs,
dist_eq_norm_vsub V y q, abs_div, abs_of_pos ε0, abs_of_nonneg (norm_nonneg _), div_mul_comm],
exact mul_le_of_le_one_left ε0.le (div_self_le_one _) },
have hεyq : ∀ y ∉ s, ε / dist y q ≠ 0,
from λ y hy, div_ne_zero ε0.ne' (dist_ne_zero.2 (ne_of_mem_of_not_mem hq hy).symm),
classical,
let w : t → ℝˣ := λ p, if hp : (p : P) ∈ s then 1 else units.mk0 _ (hεyq ↑p hp),
refine ⟨set.range (λ (p : t), line_map q p (w p : ℝ)), _, _, _, _⟩,
{ intros p hp, use ⟨p, ht₁ hp⟩, simp [w, hp], },
{ rintros y ⟨⟨p, hp⟩, rfl⟩,
by_cases hps : p ∈ s; simp only [w, hps, line_map_apply_one, units.coe_mk0, dif_neg, dif_pos,
not_false_iff, units.coe_one, subtype.coe_mk];
[exact hsu hps, exact hf p], },
{ exact (ht₂.units_line_map ⟨q, ht₁ hq⟩ w).range, },
{ rw [affine_span_eq_affine_span_line_map_units (ht₁ hq) w, ht₃], },
end
lemma is_open.exists_subset_affine_independent_span_eq_top {u : set P} (hu : is_open u)
(hne : u.nonempty) :
∃ s ⊆ u, affine_independent ℝ (coe : s → P) ∧ affine_span ℝ s = ⊤ :=
begin
rcases hne with ⟨x, hx⟩,
rcases hu.exists_between_affine_independent_span_eq_top (singleton_subset_iff.mpr hx)
(singleton_nonempty _) (affine_independent_of_subsingleton _ _) with ⟨s, -, hsu, hs⟩,
exact ⟨s, hsu, hs⟩
end
/-- The affine span of a nonempty open set is `⊤`. -/
lemma is_open.affine_span_eq_top {u : set P} (hu : is_open u) (hne : u.nonempty) :
affine_span ℝ u = ⊤ :=
let ⟨s, hsu, hs, hs'⟩ := hu.exists_subset_affine_independent_span_eq_top hne
in top_unique $ hs' ▸ affine_span_mono _ hsu
lemma affine_span_eq_top_of_nonempty_interior {s : set V}
(hs : (interior $ convex_hull ℝ s).nonempty) :
affine_span ℝ s = ⊤ :=
top_unique $ is_open_interior.affine_span_eq_top hs ▸
(affine_span_mono _ interior_subset).trans_eq (affine_span_convex_hull _)
lemma affine_basis.centroid_mem_interior_convex_hull {ι} [fintype ι] (b : affine_basis ι ℝ V) :
finset.univ.centroid ℝ b.points ∈ interior (convex_hull ℝ (range b.points)) :=
begin
haveI := b.nonempty,
simp only [b.interior_convex_hull, mem_set_of_eq, b.coord_apply_centroid (finset.mem_univ _),
inv_pos, nat.cast_pos, finset.card_pos, finset.univ_nonempty, forall_true_iff]
end
lemma interior_convex_hull_nonempty_iff_affine_span_eq_top [finite_dimensional ℝ V] {s : set V} :
(interior (convex_hull ℝ s)).nonempty ↔ affine_span ℝ s = ⊤ :=
begin
refine ⟨affine_span_eq_top_of_nonempty_interior, λ h, _⟩,
obtain ⟨t, hts, b, hb⟩ := affine_basis.exists_affine_subbasis h,
suffices : (interior (convex_hull ℝ (range b.points))).nonempty,
{ rw [hb, subtype.range_coe_subtype, set_of_mem_eq] at this,
refine this.mono _,
mono* },
lift t to finset V using b.finite_set,
exact ⟨_, b.centroid_mem_interior_convex_hull⟩
end
lemma convex.interior_nonempty_iff_affine_span_eq_top [finite_dimensional ℝ V] {s : set V}
(hs : convex ℝ s) : (interior s).nonempty ↔ affine_span ℝ s = ⊤ :=
by rw [← interior_convex_hull_nonempty_iff_affine_span_eq_top, hs.convex_hull_eq]
|
37b38ff57cedaed3b7a94bc1b6dcd8ec3b3f1ac4 | 82e44445c70db0f03e30d7be725775f122d72f3e | /archive/sensitivity.lean | b561c7143d443a1f5cf491a33aa3f3340ab2bfce | [
"Apache-2.0"
] | permissive | stjordanis/mathlib | 51e286d19140e3788ef2c470bc7b953e4991f0c9 | 2568d41bca08f5d6bf39d915434c8447e21f42ee | refs/heads/master | 1,631,748,053,501 | 1,627,938,886,000 | 1,627,938,886,000 | 228,728,358 | 0 | 0 | Apache-2.0 | 1,576,630,588,000 | 1,576,630,587,000 | null | UTF-8 | Lean | false | false | 15,672 | lean | /-
Copyright (c) 2019 Reid Barton, Johan Commelin, Jesse Han, Chris Hughes, Robert Y. Lewis,
Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Johan Commelin, Jesse Han, Chris Hughes, Robert Y. Lewis, Patrick Massot
-/
import tactic.fin_cases
import tactic.apply_fun
import linear_algebra.finite_dimensional
import linear_algebra.dual
import analysis.normed_space.basic
import data.real.sqrt
/-!
# Huang's sensitivity theorem
A formalization of Hao Huang's sensitivity theorem: in the hypercube of
dimension n ≥ 1, if one colors more than half the vertices then at least one
vertex has at least √n colored neighbors.
A fun summer collaboration by
Reid Barton, Johan Commelin, Jesse Han, Chris Hughes, Robert Y. Lewis, and Patrick Massot,
based on Don Knuth's account of the story
(https://www.cs.stanford.edu/~knuth/papers/huang.pdf),
using the Lean theorem prover (https://leanprover.github.io/),
by Leonardo de Moura at Microsoft Research, and his collaborators
(https://leanprover.github.io/people/),
and using Lean's user maintained mathematics library
(https://github.com/leanprover-community/mathlib).
The project was developed at https://github.com/leanprover-community/lean-sensitivity and is now
archived at https://github.com/leanprover-community/mathlib/blob/master/archive/sensitivity.lean
-/
/-! The next two lines assert we do not want to give a constructive proof,
but rather use classical logic. -/
noncomputable theory
open_locale classical
/-! We also want to use the notation `∑` for sums. -/
open_locale big_operators
notation `|`x`|` := abs x
notation `√` := real.sqrt
open function bool linear_map fintype finite_dimensional dual_pair
/-!
### The hypercube
Notations:
- `ℕ` denotes natural numbers (including zero).
- `fin n` = {0, ⋯ , n - 1}.
- `bool` = {`tt`, `ff`}.
-/
/-- The hypercube in dimension `n`. -/
@[derive [inhabited, fintype]] def Q (n : ℕ) := fin n → bool
/-- The projection from `Q (n + 1)` to `Q n` forgetting the first value
(ie. the image of zero). -/
def π {n : ℕ} : Q (n + 1) → Q n := λ p, p ∘ fin.succ
namespace Q
/-! `n` will always denote a natural number. -/
variable (n : ℕ)
/-- `Q 0` has a unique element. -/
instance : unique (Q 0) :=
⟨⟨λ _, tt⟩, by { intro, ext x, fin_cases x }⟩
/-- `Q n` has 2^n elements. -/
lemma card : card (Q n) = 2^n :=
by simp [Q]
/-! Until the end of this namespace, `n` will be an implicit argument (still
a natural number). -/
variable {n}
lemma succ_n_eq (p q : Q (n+1)) : p = q ↔ (p 0 = q 0 ∧ π p = π q) :=
begin
split,
{ rintro rfl, exact ⟨rfl, rfl⟩, },
{ rintros ⟨h₀, h⟩,
ext x,
by_cases hx : x = 0,
{ rwa hx },
{ rw ← fin.succ_pred x hx,
convert congr_fun h (fin.pred x hx) } }
end
/-- The adjacency relation defining the graph structure on `Q n`:
`p.adjacent q` if there is an edge from `p` to `q` in `Q n`. -/
def adjacent {n : ℕ} (p : Q n) : set (Q n) := λ q, ∃! i, p i ≠ q i
/-- In `Q 0`, no two vertices are adjacent. -/
lemma not_adjacent_zero (p q : Q 0) : ¬ p.adjacent q :=
by rintros ⟨v, _⟩; apply fin_zero_elim v
/-- If `p` and `q` in `Q (n+1)` have different values at zero then they are adjacent
iff their projections to `Q n` are equal. -/
lemma adj_iff_proj_eq {p q : Q (n+1)} (h₀ : p 0 ≠ q 0) :
p.adjacent q ↔ π p = π q :=
begin
split,
{ rintros ⟨i, h_eq, h_uni⟩,
ext x, by_contradiction hx,
apply fin.succ_ne_zero x,
rw [h_uni _ hx, h_uni _ h₀] },
{ intro heq,
use [0, h₀],
intros y hy,
contrapose! hy,
rw ←fin.succ_pred _ hy,
apply congr_fun heq }
end
/-- If `p` and `q` in `Q (n+1)` have the same value at zero then they are adjacent
iff their projections to `Q n` are adjacent. -/
lemma adj_iff_proj_adj {p q : Q (n+1)} (h₀ : p 0 = q 0) :
p.adjacent q ↔ (π p).adjacent (π q) :=
begin
split,
{ rintros ⟨i, h_eq, h_uni⟩,
have h_i : i ≠ 0, from λ h_i, absurd h₀ (by rwa h_i at h_eq),
use [i.pred h_i,
show p (fin.succ (fin.pred i _)) ≠ q (fin.succ (fin.pred i _)),
by rwa fin.succ_pred],
intros y hy,
simp [eq.symm (h_uni _ hy)] },
{ rintros ⟨i, h_eq, h_uni⟩,
use [i.succ, h_eq],
intros y hy,
rw [←fin.pred_inj, fin.pred_succ],
{ apply h_uni,
change p (fin.pred _ _).succ ≠ q (fin.pred _ _).succ,
simp [hy] },
{ contrapose! hy,
rw [hy, h₀] },
{ apply fin.succ_ne_zero } }
end
@[symm] lemma adjacent.symm {p q : Q n} : p.adjacent q ↔ q.adjacent p :=
by simp only [adjacent, ne_comm]
end Q
/-! ### The vector space -/
/-- The free vector space on vertices of a hypercube, defined inductively. -/
def V : ℕ → Type
| 0 := ℝ
| (n+1) := V n × V n
namespace V
variables (n : ℕ)
/-! `V n` is a real vector space whose equality relation is computable. -/
instance : decidable_eq (V n) :=
by { induction n ; { dunfold V, resetI, apply_instance } }
instance : add_comm_group (V n) :=
by { induction n ; { dunfold V, resetI, apply_instance } }
instance : module ℝ (V n) :=
by { induction n ; { dunfold V, resetI, apply_instance } }
end V
/-- The basis of `V` indexed by the hypercube, defined inductively. -/
noncomputable def e : Π {n}, Q n → V n
| 0 := λ _, (1:ℝ)
| (n+1) := λ x, cond (x 0) (e (π x), 0) (0, e (π x))
@[simp] lemma e_zero_apply (x : Q 0) : e x = (1 : ℝ) := rfl
/-- The dual basis to `e`, defined inductively. -/
noncomputable def ε : Π {n : ℕ} (p : Q n), V n →ₗ[ℝ] ℝ
| 0 _ := linear_map.id
| (n+1) p := cond (p 0) ((ε $ π p).comp $ linear_map.fst _ _ _)
((ε $ π p).comp $ linear_map.snd _ _ _)
variable {n : ℕ}
lemma duality (p q : Q n) : ε p (e q) = if p = q then 1 else 0 :=
begin
induction n with n IH,
{ rw (show p = q, from subsingleton.elim p q),
dsimp [ε, e],
simp },
{ dsimp [ε, e],
cases hp : p 0 ; cases hq : q 0,
all_goals {
repeat {rw cond_tt},
repeat {rw cond_ff},
simp only [linear_map.fst_apply, linear_map.snd_apply, linear_map.comp_apply, IH],
try { congr' 1, rw Q.succ_n_eq, finish },
try {
erw (ε _).map_zero,
have : p ≠ q, { intro h, rw p.succ_n_eq q at h, finish },
simp [this] } } }
end
/-- Any vector in `V n` annihilated by all `ε p`'s is zero. -/
lemma epsilon_total {v : V n} (h : ∀ p : Q n, (ε p) v = 0) : v = 0 :=
begin
induction n with n ih,
{ dsimp [ε] at h, exact h (λ _, tt) },
{ cases v with v₁ v₂,
ext ; change _ = (0 : V n) ; simp only ; apply ih ; intro p ;
[ let q : Q (n+1) := λ i, if h : i = 0 then tt else p (i.pred h),
let q : Q (n+1) := λ i, if h : i = 0 then ff else p (i.pred h)],
all_goals {
specialize h q,
rw [ε, show q 0 = tt, from rfl, cond_tt] at h <|>
rw [ε, show q 0 = ff, from rfl, cond_ff] at h,
rwa show p = π q, by { ext, simp [q, fin.succ_ne_zero, π] } } }
end
/-- `e` and `ε` are dual families of vectors. It implies that `e` is indeed a basis
and `ε` computes coefficients of decompositions of vectors on that basis. -/
def dual_pair_e_ε (n : ℕ) : dual_pair (@e n) (@ε n) :=
{ eval := duality,
total := @epsilon_total _ }
/-! We will now derive the dimension of `V`, first as a cardinal in `dim_V` and,
since this cardinal is finite, as a natural number in `finrank_V` -/
lemma dim_V : module.rank ℝ (V n) = 2^n :=
have module.rank ℝ (V n) = (2^n : ℕ),
by { rw [dim_eq_card_basis (dual_pair_e_ε _).basis, Q.card]; apply_instance },
by assumption_mod_cast
instance : finite_dimensional ℝ (V n) :=
finite_dimensional.of_fintype_basis (dual_pair_e_ε _).basis
lemma finrank_V : finrank ℝ (V n) = 2^n :=
have _ := @dim_V n,
by rw ←finrank_eq_dim at this; assumption_mod_cast
/-! ### The linear map -/
/-- The linear operator $f_n$ corresponding to Huang's matrix $A_n$,
defined inductively as a ℝ-linear map from `V n` to `V n`. -/
noncomputable def f : Π n, V n →ₗ[ℝ] V n
| 0 := 0
| (n+1) := linear_map.prod
(linear_map.coprod (f n) linear_map.id)
(linear_map.coprod linear_map.id (-f n))
/-! The preceding definition uses linear map constructions to automatically
get that `f` is linear, but its values are somewhat buried as a side-effect.
The next two lemmas unbury them. -/
@[simp] lemma f_zero : f 0 = 0 := rfl
lemma f_succ_apply (v : V (n+1)) :
f (n+1) v = (f n v.1 + v.2, v.1 - f n v.2) :=
begin
cases v,
rw f,
simp only [linear_map.id_apply, linear_map.prod_apply, prod.mk.inj_iff,
linear_map.neg_apply, sub_eq_add_neg, linear_map.coprod_apply],
exact ⟨rfl, rfl⟩
end
/-! In the next statement, the explicit conversion `(n : ℝ)` of `n` to a real number
is necessary since otherwise `n • v` refers to the multiplication defined
using only the addition of `V`. -/
lemma f_squared : ∀ v : V n, (f n) (f n v) = (n : ℝ) • v :=
begin
induction n with n IH; intro,
{ simpa only [nat.cast_zero, zero_smul] },
{ cases v, simp [f_succ_apply, IH, add_smul, add_assoc], abel }
end
/-! We now compute the matrix of `f` in the `e` basis (`p` is the line index,
`q` the column index). -/
lemma f_matrix :
∀ p q : Q n, |ε q (f n (e p))| = if q.adjacent p then 1 else 0 :=
begin
induction n with n IH,
{ intros p q,
dsimp [f],
simp [Q.not_adjacent_zero] },
{ intros p q,
have ite_nonneg : ite (π q = π p) (1 : ℝ) 0 ≥ 0,
{ split_ifs ; norm_num },
have f_map_zero := (show linear_map ℝ (V (n+0)) (V n), from f n).map_zero,
dsimp [e, ε, f], cases hp : p 0 ; cases hq : q 0,
all_goals
{ repeat {rw cond_tt}, repeat {rw cond_ff},
simp [f_map_zero, hp, hq, IH, duality, abs_of_nonneg ite_nonneg, Q.adj_iff_proj_eq,
Q.adj_iff_proj_adj] } }
end
/-- The linear operator $g_m$ corresponding to Knuth's matrix $B_m$. -/
noncomputable def g (m : ℕ) : V m →ₗ[ℝ] V (m+1) :=
linear_map.prod (f m + √(m+1) • linear_map.id) linear_map.id
/-! In the following lemmas, `m` will denote a natural number. -/
variables {m : ℕ}
/-! Again we unpack what are the values of `g`. -/
lemma g_apply : ∀ v, g m v = (f m v + √(m+1) • v, v) :=
by delta g; simp
lemma g_injective : injective (g m) :=
begin
rw g,
intros x₁ x₂ h,
simp only [linear_map.prod_apply, linear_map.id_apply, prod.mk.inj_iff] at h,
exact h.right
end
lemma f_image_g (w : V (m + 1)) (hv : ∃ v, g m v = w) :
f (m + 1) w = √(m + 1) • w :=
begin
rcases hv with ⟨v, rfl⟩,
have : √(m+1) * √(m+1) = m+1 :=
real.mul_self_sqrt (by exact_mod_cast zero_le _),
simp [this, f_succ_apply, g_apply, f_squared, smul_add, add_smul, smul_smul],
abel
end
/-!
### The main proof
In this section, in order to enforce that `n` is positive, we write it as
`m + 1` for some natural number `m`. -/
/-! `dim X` will denote the dimension of a subspace `X` as a cardinal. -/
notation `dim` X:70 := module.rank ℝ ↥X
/-! `fdim X` will denote the (finite) dimension of a subspace `X` as a natural number. -/
notation `fdim` := finrank ℝ
/-! `Span S` will denote the ℝ-subspace spanned by `S`. -/
notation `Span` := submodule.span ℝ
/-! `Card X` will denote the cardinal of a subset of a finite type, as a
natural number. -/
notation `Card` X:70 := X.to_finset.card
/-! In the following, `⊓` and `⊔` will denote intersection and sums of ℝ-subspaces,
equipped with their subspace structures. The notations come from the general
theory of lattices, with inf and sup (also known as meet and join). -/
/-- If a subset `H` of `Q (m+1)` has cardinal at least `2^m + 1` then the
subspace of `V (m+1)` spanned by the corresponding basis vectors non-trivially
intersects the range of `g m`. -/
lemma exists_eigenvalue (H : set (Q (m + 1))) (hH : Card H ≥ 2^m + 1) :
∃ y ∈ Span (e '' H) ⊓ (g m).range, y ≠ (0 : _) :=
begin
let W := Span (e '' H),
let img := (g m).range,
suffices : 0 < dim (W ⊓ img),
{ simp only [exists_prop],
exact_mod_cast exists_mem_ne_zero_of_dim_pos this },
have dim_le : dim (W ⊔ img) ≤ 2^(m + 1),
{ convert ← dim_submodule_le (W ⊔ img),
apply dim_V },
have dim_add : dim (W ⊔ img) + dim (W ⊓ img) = dim W + 2^m,
{ convert ← dim_sup_add_dim_inf_eq W img,
rw ← dim_eq_of_injective (g m) g_injective,
apply dim_V },
have dimW : dim W = card H,
{ have li : linear_independent ℝ (set.restrict e H),
{ convert (dual_pair_e_ε _).basis.linear_independent.comp _ subtype.val_injective,
rw (dual_pair_e_ε _).coe_basis },
have hdW := dim_span li,
rw set.range_restrict at hdW,
convert hdW,
rw [← (dual_pair_e_ε _).coe_basis, cardinal.mk_image_eq (dual_pair_e_ε _).basis.injective,
cardinal.fintype_card] },
rw ← finrank_eq_dim ℝ at ⊢ dim_le dim_add dimW,
rw [← finrank_eq_dim ℝ, ← finrank_eq_dim ℝ] at dim_add,
norm_cast at ⊢ dim_le dim_add dimW,
rw pow_succ' at dim_le,
rw set.to_finset_card at hH,
linarith
end
/-- **Huang sensitivity theorem** also known as the **Huang degree theorem** -/
theorem huang_degree_theorem (H : set (Q (m + 1))) (hH : Card H ≥ 2^m + 1) :
∃ q, q ∈ H ∧ √(m + 1) ≤ Card (H ∩ q.adjacent) :=
begin
rcases exists_eigenvalue H hH with ⟨y, ⟨⟨y_mem_H, y_mem_g⟩, y_ne⟩⟩,
have coeffs_support : ((dual_pair_e_ε (m+1)).coeffs y).support ⊆ H.to_finset,
{ intros p p_in,
rw finsupp.mem_support_iff at p_in,
rw set.mem_to_finset,
exact (dual_pair_e_ε _).mem_of_mem_span y_mem_H p p_in },
obtain ⟨q, H_max⟩ : ∃ q : Q (m+1), ∀ q' : Q (m+1), |(ε q' : _) y| ≤ |ε q y|,
from fintype.exists_max _,
have H_q_pos : 0 < |ε q y|,
{ contrapose! y_ne,
exact epsilon_total (λ p, abs_nonpos_iff.mp (le_trans (H_max p) y_ne)) },
refine ⟨q, (dual_pair_e_ε _).mem_of_mem_span y_mem_H q (abs_pos.mp H_q_pos), _⟩,
let s := √(m+1),
suffices : s * |ε q y| ≤ ↑(_) * |ε q y|,
from (mul_le_mul_right H_q_pos).mp ‹_›,
let coeffs := (dual_pair_e_ε (m+1)).coeffs,
calc
s * |ε q y|
= |ε q (s • y)| :
by rw [map_smul, smul_eq_mul, abs_mul, abs_of_nonneg (real.sqrt_nonneg _)]
... = |ε q (f (m+1) y)| : by rw [← f_image_g y (by simpa using y_mem_g)]
... = |ε q (f (m+1) (lc _ (coeffs y)))| : by rw (dual_pair_e_ε _).lc_coeffs y
... = |(coeffs y).sum (λ (i : Q (m + 1)) (a : ℝ), a • ((ε q) ∘ (f (m + 1)) ∘
λ (i : Q (m + 1)), e i) i)| :
by erw [(f $ m + 1).map_finsupp_total, (ε q).map_finsupp_total, finsupp.total_apply]
... ≤ ∑ p in (coeffs y).support, |(coeffs y p) * (ε q $ f (m+1) $ e p)| :
norm_sum_le _ $ λ p, coeffs y p * _
... = ∑ p in (coeffs y).support, |coeffs y p| * ite (q.adjacent p) 1 0 :
by simp only [abs_mul, f_matrix]
... = ∑ p in (coeffs y).support.filter (Q.adjacent q), |coeffs y p| :
by simp [finset.sum_filter]
... ≤ ∑ p in (coeffs y).support.filter (Q.adjacent q), |coeffs y q| :
finset.sum_le_sum (λ p _, H_max p)
... = (((coeffs y).support.filter (Q.adjacent q)).card : ℝ) * |coeffs y q| :
by rw [finset.sum_const, nsmul_eq_mul]
... = (((coeffs y).support ∩ (Q.adjacent q).to_finset).card : ℝ) * |coeffs y q| :
by { congr' with x, simp, refl }
... ≤ (finset.card ((H ∩ Q.adjacent q).to_finset )) * |ε q y| :
begin
refine (mul_le_mul_right H_q_pos).2 _,
norm_cast,
apply finset.card_le_of_subset,
rw set.to_finset_inter,
convert finset.inter_subset_inter_right coeffs_support
end
end
|
e28a21225dc17933b67b096c24bc6977a3ce07d6 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/topology/algebra/order/floor.lean | 837b14a8f142308cca7b601633749054fc6bd614 | [
"Apache-2.0"
] | permissive | urkud/mathlib | eab80095e1b9f1513bfb7f25b4fa82fa4fd02989 | 6379d39e6b5b279df9715f8011369a301b634e41 | refs/heads/master | 1,658,425,342,662 | 1,658,078,703,000 | 1,658,078,703,000 | 186,910,338 | 0 | 0 | Apache-2.0 | 1,568,512,083,000 | 1,557,958,709,000 | Lean | UTF-8 | Lean | false | false | 9,570 | lean | /-
Copyright (c) 2020 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import algebra.order.floor
import topology.algebra.order.basic
/-!
# Topological facts about `int.floor`, `int.ceil` and `int.fract`
This file proves statements about limits and continuity of functions involving `floor`, `ceil` and
`fract`.
## Main declarations
* `tendsto_floor_at_top`, `tendsto_floor_at_bot`, `tendsto_ceil_at_top`, `tendsto_ceil_at_bot`:
`int.floor` and `int.ceil` tend to +-∞ in +-∞.
* `continuous_on_floor`: `int.floor` is continuous on `Ico n (n + 1)`, because constant.
* `continuous_on_ceil`: `int.ceil` is continuous on `Ioc n (n + 1)`, because constant.
* `continuous_on_fract`: `int.fract` is continuous on `Ico n (n + 1)`.
* `continuous_on.comp_fract`: Precomposing a continuous function satisfying `f 0 = f 1` with
`int.fract` yields another continuous function.
-/
open filter function int set
open_locale topological_space
variables {α β γ : Type*} [linear_ordered_ring α] [floor_ring α]
lemma tendsto_floor_at_top : tendsto (floor : α → ℤ) at_top at_top :=
floor_mono.tendsto_at_top_at_top $ λ b, ⟨(b + 1 : ℤ), by { rw floor_coe, exact (lt_add_one _).le }⟩
lemma tendsto_floor_at_bot : tendsto (floor : α → ℤ) at_bot at_bot :=
floor_mono.tendsto_at_bot_at_bot $ λ b, ⟨b, (floor_coe _).le⟩
lemma tendsto_ceil_at_top : tendsto (ceil : α → ℤ) at_top at_top :=
ceil_mono.tendsto_at_top_at_top $ λ b, ⟨b, (ceil_coe _).ge⟩
lemma tendsto_ceil_at_bot : tendsto (ceil : α → ℤ) at_bot at_bot :=
ceil_mono.tendsto_at_bot_at_bot $ λ b, ⟨(b - 1 : ℤ), by { rw ceil_coe, exact (sub_one_lt _).le }⟩
variables [topological_space α]
lemma continuous_on_floor (n : ℤ) : continuous_on (λ x, floor x : α → α) (Ico n (n+1) : set α) :=
(continuous_on_congr $ floor_eq_on_Ico' n).mpr continuous_on_const
lemma continuous_on_ceil (n : ℤ) : continuous_on (λ x, ceil x : α → α) (Ioc (n-1) n : set α) :=
(continuous_on_congr $ ceil_eq_on_Ioc' n).mpr continuous_on_const
lemma tendsto_floor_right' [order_closed_topology α] (n : ℤ) :
tendsto (λ x, floor x : α → α) (𝓝[≥] n) (𝓝 n) :=
begin
rw ← nhds_within_Ico_eq_nhds_within_Ici (lt_add_one (n : α)),
simpa only [floor_coe] using
(continuous_on_floor n _ (left_mem_Ico.mpr $ lt_add_one (_ : α))).tendsto
end
lemma tendsto_ceil_left' [order_closed_topology α] (n : ℤ) :
tendsto (λ x, ceil x : α → α) (𝓝[≤] n) (𝓝 n) :=
begin
rw ← nhds_within_Ioc_eq_nhds_within_Iic (sub_one_lt (n : α)),
simpa only [ceil_coe] using
(continuous_on_ceil _ _ (right_mem_Ioc.mpr $ sub_one_lt (_ : α))).tendsto
end
lemma tendsto_floor_right [order_closed_topology α] (n : ℤ) :
tendsto (λ x, floor x : α → α) (𝓝[≥] n) (𝓝[≥] n) :=
tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ (tendsto_floor_right' _)
begin
refine (eventually_nhds_within_of_forall $ λ x (hx : (n : α) ≤ x), _),
change _ ≤ _,
norm_cast,
convert ← floor_mono hx,
rw floor_eq_iff,
exact ⟨le_rfl, lt_add_one _⟩
end
lemma tendsto_ceil_left [order_closed_topology α] (n : ℤ) :
tendsto (λ x, ceil x : α → α) (𝓝[≤] n) (𝓝[≤] n) :=
tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ (tendsto_ceil_left' _)
begin
refine (eventually_nhds_within_of_forall $ λ x (hx : x ≤ (n : α)), _),
change _ ≤ _,
norm_cast,
convert ← ceil_mono hx,
rw ceil_eq_iff,
exact ⟨sub_one_lt _, le_rfl⟩
end
lemma tendsto_floor_left [order_closed_topology α] (n : ℤ) :
tendsto (λ x, floor x : α → α) (𝓝[<] n) (𝓝[≤] (n-1)) :=
begin
rw ← nhds_within_Ico_eq_nhds_within_Iio (sub_one_lt (n : α)),
convert (tendsto_nhds_within_congr $ (λ x hx, (floor_eq_on_Ico' (n-1) x hx).symm))
(tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ tendsto_const_nhds
(eventually_of_forall (λ _, mem_Iic.mpr $ le_rfl)));
norm_cast <|> apply_instance,
ring
end
lemma tendsto_ceil_right [order_closed_topology α] (n : ℤ) :
tendsto (λ x, ceil x : α → α) (𝓝[>] n) (𝓝[≥] (n+1)) :=
begin
rw ← nhds_within_Ioc_eq_nhds_within_Ioi (lt_add_one (n : α)),
convert (tendsto_nhds_within_congr $ (λ x hx, (ceil_eq_on_Ioc' (n+1) x hx).symm))
(tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ tendsto_const_nhds
(eventually_of_forall (λ _, mem_Ici.mpr $ le_rfl)));
norm_cast <|> apply_instance,
ring
end
lemma tendsto_floor_left' [order_closed_topology α] (n : ℤ) :
tendsto (λ x, floor x : α → α) (𝓝[<] n) (𝓝 (n-1)) :=
begin
rw ← nhds_within_univ,
exact tendsto_nhds_within_mono_right (subset_univ _) (tendsto_floor_left n),
end
lemma tendsto_ceil_right' [order_closed_topology α] (n : ℤ) :
tendsto (λ x, ceil x : α → α) (𝓝[>] n) (𝓝 (n+1)) :=
begin
rw ← nhds_within_univ,
exact tendsto_nhds_within_mono_right (subset_univ _) (tendsto_ceil_right n),
end
lemma continuous_on_fract [topological_add_group α] (n : ℤ) :
continuous_on (fract : α → α) (Ico n (n+1) : set α) :=
continuous_on_id.sub (continuous_on_floor n)
lemma tendsto_fract_left' [order_closed_topology α] [topological_add_group α]
(n : ℤ) : tendsto (fract : α → α) (𝓝[<] n) (𝓝 1) :=
begin
convert (tendsto_nhds_within_of_tendsto_nhds tendsto_id).sub (tendsto_floor_left' n);
[{norm_cast, ring}, apply_instance, apply_instance]
end
lemma tendsto_fract_left [order_closed_topology α] [topological_add_group α]
(n : ℤ) : tendsto (fract : α → α) (𝓝[<] n) (𝓝[<] 1) :=
tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _
(tendsto_fract_left' _) (eventually_of_forall fract_lt_one)
lemma tendsto_fract_right' [order_closed_topology α] [topological_add_group α]
(n : ℤ) : tendsto (fract : α → α) (𝓝[≥] n) (𝓝 0) :=
begin
convert (tendsto_nhds_within_of_tendsto_nhds tendsto_id).sub (tendsto_floor_right' n);
[exact (sub_self _).symm, apply_instance, apply_instance]
end
lemma tendsto_fract_right [order_closed_topology α] [topological_add_group α]
(n : ℤ) : tendsto (fract : α → α) (𝓝[≥] n) (𝓝[≥] 0) :=
tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _
(tendsto_fract_right' _) (eventually_of_forall fract_nonneg)
local notation `I` := (Icc 0 1 : set α)
variables [order_topology α] [topological_add_group α] [topological_space β] [topological_space γ]
/-- Do not use this, use `continuous_on.comp_fract` instead. -/
lemma continuous_on.comp_fract' {f : β → α → γ}
(h : continuous_on (uncurry f) $ (univ : set β) ×ˢ I) (hf : ∀ s, f s 0 = f s 1) :
continuous (λ st : β × α, f st.1 $ fract st.2) :=
begin
change continuous ((uncurry f) ∘ (prod.map id (fract))),
rw continuous_iff_continuous_at,
rintro ⟨s, t⟩,
by_cases ht : t = floor t,
{ rw ht,
rw ← continuous_within_at_univ,
have : (univ : set (β × α)) ⊆ ((univ : set β) ×ˢ Iio ↑⌊t⌋) ∪ ((univ : set β) ×ˢ Ici ↑⌊t⌋),
{ rintros p -,
rw ← prod_union,
exact ⟨trivial, lt_or_le p.2 _⟩ },
refine continuous_within_at.mono _ this,
refine continuous_within_at.union _ _,
{ simp only [continuous_within_at, fract_coe, nhds_within_prod_eq,
nhds_within_univ, id.def, comp_app, prod.map_mk],
have : (uncurry f) (s, 0) = (uncurry f) (s, (1 : α)),
by simp [uncurry, hf],
rw this,
refine (h _ ⟨⟨⟩, by exact_mod_cast right_mem_Icc.2 (zero_le_one' α)⟩).tendsto.comp _,
rw [nhds_within_prod_eq, nhds_within_univ],
rw nhds_within_Icc_eq_nhds_within_Iic (@zero_lt_one α _ _),
exact tendsto_id.prod_map
(tendsto_nhds_within_mono_right Iio_subset_Iic_self $ tendsto_fract_left _) },
{ simp only [continuous_within_at, fract_coe, nhds_within_prod_eq,
nhds_within_univ, id.def, comp_app, prod.map_mk],
refine (h _ ⟨⟨⟩, by exact_mod_cast left_mem_Icc.2 (zero_le_one' α)⟩).tendsto.comp _,
rw [nhds_within_prod_eq, nhds_within_univ,
nhds_within_Icc_eq_nhds_within_Ici (@zero_lt_one α _ _)],
exact tendsto_id.prod_map (tendsto_fract_right _) } },
{ have : t ∈ Ioo (floor t : α) ((floor t : α) + 1),
from ⟨lt_of_le_of_ne (floor_le t) (ne.symm ht), lt_floor_add_one _⟩,
apply (h ((prod.map _ fract) _) ⟨trivial, ⟨fract_nonneg _, (fract_lt_one _).le⟩⟩).tendsto.comp,
simp only [nhds_prod_eq, nhds_within_prod_eq, nhds_within_univ, id.def, prod.map_mk],
exact continuous_at_id.tendsto.prod_map
(tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _
(((continuous_on_fract _ _ (Ioo_subset_Ico_self this)).mono
Ioo_subset_Ico_self).continuous_at (Ioo_mem_nhds this.1 this.2))
(eventually_of_forall (λ x, ⟨fract_nonneg _, (fract_lt_one _).le⟩)) ) }
end
lemma continuous_on.comp_fract
{s : β → α}
{f : β → α → γ}
(h : continuous_on (uncurry f) $ (univ : set β) ×ˢ (Icc 0 1 : set α))
(hs : continuous s)
(hf : ∀ s, f s 0 = f s 1) :
continuous (λ x : β, f x $ int.fract (s x)) :=
(h.comp_fract' hf).comp (continuous_id.prod_mk hs)
/-- A special case of `continuous_on.comp_fract`. -/
lemma continuous_on.comp_fract'' {f : α → β} (h : continuous_on f I) (hf : f 0 = f 1) :
continuous (f ∘ fract) :=
continuous_on.comp_fract (h.comp continuous_on_snd $ λ x hx, (mem_prod.mp hx).2)
continuous_id (λ _, hf)
|
dcab54dff6efdd97cb764804a85a9f520237b7ab | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/number_theory/dioph.lean | a08aa848b1497a77d6ac483eb04ff0aa35b83d0a | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 26,425 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.fin.fin2
import data.pfun
import data.vector3
import number_theory.pell
/-!
# Diophantine functions and Matiyasevic's theorem
Hilbert's tenth problem asked whether there exists an algorithm which for a given integer polynomial
determines whether this polynomial has integer solutions. It was answered in the negative in 1970,
the final step being completed by Matiyasevic who showed that the power function is Diophantine.
Here a function is called Diophantine if its graph is Diophantine as a set. A subset `S ⊆ ℕ ^ α` in
turn is called Diophantine if there exists an integer polynomial on `α ⊕ β` such that `v ∈ S` iff
there exists `t : ℕ^β` with `p (v, t) = 0`.
## Main definitions
* `is_poly`: a predicate stating that a function is a multivariate integer polynomial.
* `poly`: the type of multivariate integer polynomial functions.
* `dioph`: a predicate stating that a set is Diophantine, i.e. a set `S ⊆ ℕ^α` is
Diophantine if there exists a polynomial on `α ⊕ β` such that `v ∈ S` iff there
exists `t : ℕ^β` with `p (v, t) = 0`.
* `dioph_fn`: a predicate on a function stating that it is Diophantine in the sense that its graph
is Diophantine as a set.
## Main statements
* `pell_dioph` states that solutions to Pell's equation form a Diophantine set.
* `pow_dioph` states that the power function is Diophantine, a version of Matiyasevic's theorem.
## References
* [M. Carneiro, _A Lean formalization of Matiyasevic's theorem_][carneiro2018matiyasevic]
* [M. Davis, _Hilbert's tenth problem is unsolvable_][MR317916]
## Tags
Matiyasevic's theorem, Hilbert's tenth problem
## TODO
* Finish the solution of Hilbert's tenth problem.
* Connect `poly` to `mv_polynomial`
-/
open fin2 function nat sum
local infixr ` ::ₒ `:67 := option.elim
local infixr ` ⊗ `:65 := sum.elim
universe u
/-!
### Multivariate integer polynomials
Note that this duplicates `mv_polynomial`.
-/
section polynomials
variables {α β γ : Type*}
/-- A predicate asserting that a function is a multivariate integer polynomial.
(We are being a bit lazy here by allowing many representations for multiplication,
rather than only allowing monomials and addition, but the definition is equivalent
and this is easier to use.) -/
inductive is_poly : ((α → ℕ) → ℤ) → Prop
| proj : ∀ i, is_poly (λ x : α → ℕ, x i)
| const : Π (n : ℤ), is_poly (λ x : α → ℕ, n)
| sub : Π {f g : (α → ℕ) → ℤ}, is_poly f → is_poly g → is_poly (λ x, f x - g x)
| mul : Π {f g : (α → ℕ) → ℤ}, is_poly f → is_poly g → is_poly (λ x, f x * g x)
lemma is_poly.neg {f : (α → ℕ) → ℤ} : is_poly f → is_poly (-f) :=
by { rw ←zero_sub, exact (is_poly.const 0).sub }
lemma is_poly.add {f g : (α → ℕ) → ℤ} (hf : is_poly f) (hg : is_poly g) : is_poly (f + g) :=
by { rw ←sub_neg_eq_add, exact hf.sub hg.neg }
/-- The type of multivariate integer polynomials -/
def poly (α : Type u) := {f : (α → ℕ) → ℤ // is_poly f}
namespace poly
section
instance fun_like : fun_like (poly α) (α → ℕ) (λ _, ℤ) := ⟨subtype.val, subtype.val_injective⟩
/-- Helper instance for when there are too many metavariables to apply `fun_like.has_coe_to_fun`
directly. -/
instance : has_coe_to_fun (poly α) (λ _, (α → ℕ) → ℤ) := fun_like.has_coe_to_fun
/-- The underlying function of a `poly` is a polynomial -/
protected lemma is_poly (f : poly α) : is_poly f := f.2
/-- Extensionality for `poly α` -/
@[ext] lemma ext {f g : poly α} : (∀ x, f x = g x) → f = g := fun_like.ext _ _
/-- The `i`th projection function, `x_i`. -/
def proj (i) : poly α := ⟨_, is_poly.proj i⟩
@[simp] lemma proj_apply (i : α) (x) : proj i x = x i := rfl
/-- The constant function with value `n : ℤ`. -/
def const (n) : poly α := ⟨_, is_poly.const n⟩
@[simp] lemma const_apply (n) (x : α → ℕ) : const n x = n := rfl
instance : has_zero (poly α) := ⟨const 0⟩
instance : has_one (poly α) := ⟨const 1⟩
instance : has_neg (poly α) := ⟨λ f, ⟨-f, f.2.neg⟩⟩
instance : has_add (poly α) := ⟨λ f g, ⟨f + g, f.2.add g.2⟩⟩
instance : has_sub (poly α) := ⟨λ f g, ⟨f - g, f.2.sub g.2⟩⟩
instance : has_mul (poly α) := ⟨λ f g, ⟨f * g, f.2.mul g.2⟩⟩
@[simp] lemma coe_zero : ⇑(0 : poly α) = const 0 := rfl
@[simp] lemma coe_one : ⇑(1 : poly α) = const 1 := rfl
@[simp] lemma coe_neg (f : poly α) : ⇑(-f) = -f := rfl
@[simp] lemma coe_add (f g : poly α) : ⇑(f + g) = f + g := rfl
@[simp] lemma coe_sub (f g : poly α) : ⇑(f - g) = f - g := rfl
@[simp] lemma coe_mul (f g : poly α) : ⇑(f * g) = f * g := rfl
@[simp] lemma zero_apply (x) : (0 : poly α) x = 0 := rfl
@[simp] lemma one_apply (x) : (1 : poly α) x = 1 := rfl
@[simp] lemma neg_apply (f : poly α) (x) : (-f) x = -f x := rfl
@[simp] lemma add_apply (f g : poly α) (x : α → ℕ) : (f + g) x = f x + g x := rfl
@[simp] lemma sub_apply (f g : poly α) (x : α → ℕ) : (f - g) x = f x - g x := rfl
@[simp] lemma mul_apply (f g : poly α) (x : α → ℕ) : (f * g) x = f x * g x := rfl
instance (α : Type*) : inhabited (poly α) := ⟨0⟩
instance : add_comm_group (poly α) := by refine_struct
{ add := ((+) : poly α → poly α → poly α),
neg := (has_neg.neg : poly α → poly α),
sub := (has_sub.sub),
zero := 0,
zsmul := @zsmul_rec _ ⟨(0 : poly α)⟩ ⟨(+)⟩ ⟨has_neg.neg⟩,
nsmul := @nsmul_rec _ ⟨(0 : poly α)⟩ ⟨(+)⟩ };
intros; try { refl }; refine ext (λ _, _);
simp [sub_eq_add_neg, add_comm, add_assoc]
instance : add_group_with_one (poly α) :=
{ one := 1,
nat_cast := λ n, poly.const n,
int_cast := poly.const,
.. poly.add_comm_group }
instance : comm_ring (poly α) := by refine_struct
{ add := ((+) : poly α → poly α → poly α),
zero := 0,
mul := (*),
one := 1,
npow := @npow_rec _ ⟨(1 : poly α)⟩ ⟨(*)⟩,
.. poly.add_group_with_one, .. poly.add_comm_group };
intros; try { refl }; refine ext (λ _, _);
simp [sub_eq_add_neg, mul_add, mul_left_comm, mul_comm, add_comm, add_assoc]
lemma induction {C : poly α → Prop}
(H1 : ∀i, C (proj i)) (H2 : ∀n, C (const n))
(H3 : ∀f g, C f → C g → C (f - g))
(H4 : ∀f g, C f → C g → C (f * g)) (f : poly α) : C f :=
begin
cases f with f pf,
induction pf with i n f g pf pg ihf ihg f g pf pg ihf ihg,
apply H1, apply H2, apply H3 _ _ ihf ihg, apply H4 _ _ ihf ihg
end
/-- The sum of squares of a list of polynomials. This is relevant for
Diophantine equations, because it means that a list of equations
can be encoded as a single equation: `x = 0 ∧ y = 0 ∧ z = 0` is
equivalent to `x^2 + y^2 + z^2 = 0`. -/
def sumsq : list (poly α) → poly α
| [] := 0
| (p::ps) := p*p + sumsq ps
lemma sumsq_nonneg (x : α → ℕ) : ∀ l, 0 ≤ sumsq l x
| [] := le_refl 0
| (p::ps) := by rw sumsq; simp [-add_comm];
exact add_nonneg (mul_self_nonneg _) (sumsq_nonneg ps)
lemma sumsq_eq_zero (x) : ∀ l, sumsq l x = 0 ↔ l.all₂ (λ a : poly α, a x = 0)
| [] := eq_self_iff_true _
| (p::ps) := by rw [list.all₂_cons, ← sumsq_eq_zero ps]; rw sumsq; simp [-add_comm]; exact
⟨λ (h : p x * p x + sumsq ps x = 0),
have p x = 0, from eq_zero_of_mul_self_eq_zero $ le_antisymm
(by rw ← h; have t := add_le_add_left (sumsq_nonneg x ps) (p x * p x); rwa [add_zero] at t)
(mul_self_nonneg _),
⟨this, by simp [this] at h; exact h⟩,
λ ⟨h1, h2⟩, by rw [h1, h2]; refl⟩
end
/-- Map the index set of variables, replacing `x_i` with `x_(f i)`. -/
def map {α β} (f : α → β) (g : poly α) : poly β :=
⟨λ v, g $ v ∘ f, g.induction
(λ i, by simp; apply is_poly.proj)
(λ n, by simp; apply is_poly.const)
(λ f g pf pg, by simp; apply is_poly.sub pf pg)
(λ f g pf pg, by simp; apply is_poly.mul pf pg)⟩
@[simp] lemma map_apply {α β} (f : α → β) (g : poly α) (v) : map f g v = g (v ∘ f) := rfl
end poly
end polynomials
/-! ### Diophantine sets -/
/-- A set `S ⊆ ℕ^α` is Diophantine if there exists a polynomial on
`α ⊕ β` such that `v ∈ S` iff there exists `t : ℕ^β` with `p (v, t) = 0`. -/
def dioph {α : Type u} (S : set (α → ℕ)) : Prop :=
∃ {β : Type u} (p : poly (α ⊕ β)), ∀ v, S v ↔ ∃ t, p (v ⊗ t) = 0
namespace dioph
section
variables {α β γ : Type u} {S S' : set (α → ℕ)}
lemma ext (d : dioph S) (H : ∀ v, v ∈ S ↔ v ∈ S') : dioph S' := by rwa ←set.ext H
lemma of_no_dummies (S : set (α → ℕ)) (p : poly α) (h : ∀ v, S v ↔ p v = 0) : dioph S :=
⟨pempty, p.map inl, λ v, (h v).trans ⟨λ h, ⟨pempty.rec _, h⟩, λ ⟨t, ht⟩, ht⟩⟩
lemma inject_dummies_lem (f : β → γ) (g : γ → option β) (inv : ∀ x, g (f x) = some x)
(p : poly (α ⊕ β)) (v : α → ℕ) :
(∃ t, p (v ⊗ t) = 0) ↔ ∃ t, p.map (inl ⊗ inr ∘ f) (v ⊗ t) = 0 :=
begin
dsimp, refine ⟨λ t, _, λ t, _⟩; cases t with t ht,
{ have : (v ⊗ (0 ::ₒ t) ∘ g) ∘ (inl ⊗ inr ∘ f) = v ⊗ t :=
funext (λ s, by cases s with a b; dsimp [(∘)]; try {rw inv}; refl),
exact ⟨(0 ::ₒ t) ∘ g, by rwa this⟩ },
{ have : v ⊗ t ∘ f = (v ⊗ t) ∘ (inl ⊗ inr ∘ f) :=
funext (λ s, by cases s with a b; refl),
exact ⟨t ∘ f, by rwa this⟩ }
end
lemma inject_dummies (f : β → γ) (g : γ → option β) (inv : ∀ x, g (f x) = some x) (p : poly (α ⊕ β))
(h : ∀ v, S v ↔ ∃ t, p (v ⊗ t) = 0) :
∃ q : poly (α ⊕ γ), ∀ v, S v ↔ ∃ t, q (v ⊗ t) = 0 :=
⟨p.map (inl ⊗ (inr ∘ f)), λ v, (h v).trans $ inject_dummies_lem f g inv _ _⟩
variables (β)
lemma reindex_dioph (f : α → β) : Π (d : dioph S), dioph {v | v ∘ f ∈ S}
| ⟨γ, p, pe⟩ := ⟨γ, p.map ((inl ∘ f) ⊗ inr), λ v, (pe _).trans $ exists_congr $ λ t,
suffices v ∘ f ⊗ t = (v ⊗ t) ∘ (inl ∘ f ⊗ inr), by simp [this],
funext $ λ s, by cases s with a b; refl⟩
variables {β}
lemma dioph_list.all₂ (l : list (set $ α → ℕ)) (d : l.all₂ dioph) :
dioph {v | l.all₂ (λ S : set (α → ℕ), v ∈ S)} :=
suffices ∃ β (pl : list (poly (α ⊕ β))), ∀ v,
list.all₂ (λ S : set _, S v) l ↔ ∃ t, list.all₂ (λ p : poly (α ⊕ β), p (v ⊗ t) = 0) pl,
from let ⟨β, pl, h⟩ := this
in ⟨β, poly.sumsq pl, λ v, (h v).trans $ exists_congr $ λ t, (poly.sumsq_eq_zero _ _).symm⟩,
begin
induction l with S l IH,
exact ⟨ulift empty, [], λ v, by simp; exact ⟨λ ⟨t⟩, empty.rec _ t, trivial⟩⟩,
simp at d,
exact let ⟨⟨β, p, pe⟩, dl⟩ := d, ⟨γ, pl, ple⟩ := IH dl in
⟨β ⊕ γ, p.map (inl ⊗ inr ∘ inl) :: pl.map (λ q, q.map (inl ⊗ (inr ∘ inr))), λ v,
by simp; exact iff.trans (and_congr (pe v) (ple v))
⟨λ ⟨⟨m, hm⟩, ⟨n, hn⟩⟩,
⟨m ⊗ n, by rw [
show (v ⊗ m ⊗ n) ∘ (inl ⊗ inr ∘ inl) = v ⊗ m,
from funext $ λ s, by cases s with a b; refl]; exact hm,
by { refine list.all₂.imp (λ q hq, _) hn, dsimp [(∘)],
rw [show (λ (x : α ⊕ γ), (v ⊗ m ⊗ n) ((inl ⊗ λ (x : γ), inr (inr x)) x)) = v ⊗ n,
from funext $ λ s, by cases s with a b; refl]; exact hq }⟩,
λ ⟨t, hl, hr⟩,
⟨⟨t ∘ inl, by rwa [
show (v ⊗ t) ∘ (inl ⊗ inr ∘ inl) = v ⊗ t ∘ inl,
from funext $ λ s, by cases s with a b; refl] at hl⟩,
⟨t ∘ inr, by
{ refine list.all₂.imp (λ q hq, _) hr, dsimp [(∘)] at hq,
rwa [show (λ (x : α ⊕ γ), (v ⊗ t) ((inl ⊗ λ (x : γ), inr (inr x)) x)) = v ⊗ t ∘ inr,
from funext $ λ s, by cases s with a b; refl] at hq }⟩⟩⟩⟩
end
lemma inter (d : dioph S) (d' : dioph S') : dioph (S ∩ S') := dioph_list.all₂ [S, S'] ⟨d, d'⟩
lemma union : ∀ (d : dioph S) (d' : dioph S'), dioph (S ∪ S')
| ⟨β, p, pe⟩ ⟨γ, q, qe⟩ := ⟨β ⊕ γ, p.map (inl ⊗ inr ∘ inl) * q.map (inl ⊗ inr ∘ inr), λ v,
begin
refine iff.trans (or_congr ((pe v).trans _) ((qe v).trans _))
(exists_or_distrib.symm.trans (exists_congr $ λ t,
(@mul_eq_zero _ _ _ (p ((v ⊗ t) ∘ (inl ⊗ inr ∘ inl)))
(q ((v ⊗ t) ∘ (inl ⊗ inr ∘ inr)))).symm)),
exact inject_dummies_lem _ (some ⊗ (λ _, none)) (λ x, rfl) _ _,
exact inject_dummies_lem _ ((λ _, none) ⊗ some) (λ x, rfl) _ _,
end⟩
/-- A partial function is Diophantine if its graph is Diophantine. -/
def dioph_pfun (f : (α → ℕ) →. ℕ) : Prop := dioph {v : option α → ℕ | f.graph (v ∘ some, v none)}
/-- A function is Diophantine if its graph is Diophantine. -/
def dioph_fn (f : (α → ℕ) → ℕ) : Prop := dioph {v : option α → ℕ | f (v ∘ some) = v none}
lemma reindex_dioph_fn {f : (α → ℕ) → ℕ} (g : α → β) (d : dioph_fn f) : dioph_fn (λ v, f (v ∘ g)) :=
by convert reindex_dioph (option β) (option.map g) d
lemma ex_dioph {S : set (α ⊕ β → ℕ)} : dioph S → dioph {v | ∃ x, v ⊗ x ∈ S}
| ⟨γ, p, pe⟩ := ⟨β ⊕ γ, p.map ((inl ⊗ inr ∘ inl) ⊗ inr ∘ inr), λ v,
⟨λ ⟨x, hx⟩, let ⟨t, ht⟩ := (pe _).1 hx in ⟨x ⊗ t, by simp; rw [
show (v ⊗ x ⊗ t) ∘ ((inl ⊗ inr ∘ inl) ⊗ inr ∘ inr) = (v ⊗ x) ⊗ t,
from funext $ λ s, by cases s with a b; try {cases a}; refl]; exact ht⟩,
λ ⟨t, ht⟩, ⟨t ∘ inl, (pe _).2 ⟨t ∘ inr, by simp at ht; rwa [
show (v ⊗ t) ∘ ((inl ⊗ inr ∘ inl) ⊗ inr ∘ inr) = (v ⊗ t ∘ inl) ⊗ t ∘ inr,
from funext $ λ s, by cases s with a b; try {cases a}; refl] at ht⟩⟩⟩⟩
lemma ex1_dioph {S : set (option α → ℕ)} : dioph S → dioph {v | ∃ x, x ::ₒ v ∈ S}
| ⟨β, p, pe⟩ := ⟨option β, p.map (inr none ::ₒ inl ⊗ inr ∘ some), λ v,
⟨λ ⟨x, hx⟩, let ⟨t, ht⟩ := (pe _).1 hx in ⟨x ::ₒ t, by simp; rw [
show (v ⊗ x ::ₒ t) ∘ (inr none ::ₒ inl ⊗ inr ∘ some) = x ::ₒ v ⊗ t,
from funext $ λ s, by cases s with a b; try {cases a}; refl]; exact ht⟩,
λ ⟨t, ht⟩, ⟨t none, (pe _).2 ⟨t ∘ some, by simp at ht; rwa [
show (v ⊗ t) ∘ (inr none ::ₒ inl ⊗ inr ∘ some) = t none ::ₒ v ⊗ t ∘ some,
from funext $ λ s, by cases s with a b; try {cases a}; refl] at ht⟩⟩⟩⟩
theorem dom_dioph {f : (α → ℕ) →. ℕ} (d : dioph_pfun f) : dioph f.dom :=
cast (congr_arg dioph $ set.ext $ λ v, (pfun.dom_iff_graph _ _).symm) (ex1_dioph d)
theorem dioph_fn_iff_pfun (f : (α → ℕ) → ℕ) : dioph_fn f = @dioph_pfun α f :=
by refine congr_arg dioph (set.ext $ λ v, _); exact pfun.lift_graph.symm
lemma abs_poly_dioph (p : poly α) : dioph_fn (λ v, (p v).nat_abs) :=
of_no_dummies _ ((p.map some - poly.proj none) * (p.map some + poly.proj none)) $ λ v,
by { dsimp, exact int.eq_nat_abs_iff_mul_eq_zero }
theorem proj_dioph (i : α) : dioph_fn (λ v, v i) :=
abs_poly_dioph (poly.proj i)
theorem dioph_pfun_comp1 {S : set (option α → ℕ)} (d : dioph S) {f} (df : dioph_pfun f) :
dioph {v : α → ℕ | ∃ h : f.dom v, f.fn v h ::ₒ v ∈ S} :=
ext (ex1_dioph (d.inter df)) $ λ v,
⟨λ ⟨x, hS, (h: Exists _)⟩, by
rw [show (x ::ₒ v) ∘ some = v, from funext $ λ s, rfl] at h;
cases h with hf h; refine ⟨hf, _⟩; rw [pfun.fn, h]; exact hS,
λ ⟨x, hS⟩, ⟨f.fn v x, hS, show Exists _,
by rw [show (f.fn v x ::ₒ v) ∘ some = v, from funext $ λ s, rfl]; exact ⟨x, rfl⟩⟩⟩
theorem dioph_fn_comp1 {S : set (option α → ℕ)} (d : dioph S) {f : (α → ℕ) → ℕ} (df : dioph_fn f) :
dioph {v | f v ::ₒ v ∈ S} :=
ext (dioph_pfun_comp1 d $ cast (dioph_fn_iff_pfun f) df) $ λ v,
⟨λ ⟨_, h⟩, h, λ h, ⟨trivial, h⟩⟩
end
section
variables {α β : Type} {n : ℕ}
open vector3
open_locale vector3
local attribute [reducible] vector3
lemma dioph_fn_vec_comp1 {S : set (vector3 ℕ (succ n))} (d : dioph S) {f : vector3 ℕ n → ℕ}
(df : dioph_fn f) :
dioph {v : vector3 ℕ n | f v :: v ∈ S} :=
ext (dioph_fn_comp1 (reindex_dioph _ (none :: some) d) df) $ λ v,
by { dsimp, congr', ext x, cases x; refl }
theorem vec_ex1_dioph (n) {S : set (vector3 ℕ (succ n))} (d : dioph S) :
dioph {v : fin2 n → ℕ | ∃ x, x :: v ∈ S} :=
ext (ex1_dioph $ reindex_dioph _ (none :: some) d) $ λ v, exists_congr $ λ x, by { dsimp,
rw [show option.elim x v ∘ cons none some = x :: v,
from funext $ λ s, by cases s with a b; refl] }
lemma dioph_fn_vec (f : vector3 ℕ n → ℕ) : dioph_fn f ↔ dioph {v | f (v ∘ fs) = v fz} :=
⟨reindex_dioph _ (fz ::ₒ fs), reindex_dioph _ (none :: some)⟩
lemma dioph_pfun_vec (f : vector3 ℕ n →. ℕ) : dioph_pfun f ↔ dioph {v | f.graph (v ∘ fs, v fz)} :=
⟨reindex_dioph _ (fz ::ₒ fs), reindex_dioph _ (none :: some)⟩
lemma dioph_fn_compn : ∀ {n} {S : set (α ⊕ fin2 n → ℕ)} (d : dioph S)
{f : vector3 ((α → ℕ) → ℕ) n} (df : vector_allp dioph_fn f),
dioph {v : α → ℕ | v ⊗ (λ i, f i v) ∈ S}
| 0 S d f := λ df, ext (reindex_dioph _ (id ⊗ fin2.elim0) d) $ λ v,
by { dsimp, congr', ext x, obtain (_ | _ | _) := x, refl }
| (succ n) S d f := f.cons_elim $ λ f fl, by simp; exact λ df dfl,
have dioph {v |v ∘ inl ⊗ f (v ∘ inl) :: v ∘ inr ∈ S},
from ext (dioph_fn_comp1 (reindex_dioph _ (some ∘ inl ⊗ none :: some ∘ inr) d) $
reindex_dioph_fn inl df) $ λ v,
by { dsimp, congr', ext x, obtain (_ | _ | _) := x; refl },
have dioph {v | v ⊗ f v :: (λ (i : fin2 n), fl i v) ∈ S},
from @dioph_fn_compn n (λ v, S (v ∘ inl ⊗ f (v ∘ inl) :: v ∘ inr)) this _ dfl,
ext this $ λ v, by { dsimp, congr', ext x, obtain (_ | _ | _) := x; refl }
lemma dioph_comp {S : set (vector3 ℕ n)} (d : dioph S) (f : vector3 ((α → ℕ) → ℕ) n)
(df : vector_allp dioph_fn f) : dioph {v | (λ i, f i v) ∈ S} :=
dioph_fn_compn (reindex_dioph _ inr d) df
lemma dioph_fn_comp {f : vector3 ℕ n → ℕ} (df : dioph_fn f) (g : vector3 ((α → ℕ) → ℕ) n)
(dg : vector_allp dioph_fn g) : dioph_fn (λ v, f (λ i, g i v)) :=
dioph_comp ((dioph_fn_vec _).1 df) ((λ v, v none) :: λ i v, g i (v ∘ some)) $
by simp; exact ⟨proj_dioph none, (vector_allp_iff_forall _ _).2 $ λ i,
reindex_dioph_fn _ $ (vector_allp_iff_forall _ _).1 dg _⟩
localized "notation (name := dioph.inter) x ` D∧ `:35 y := dioph.inter x y" in dioph
localized "notation (name := dioph.union) x ` D∨ `:35 y := dioph.union x y" in dioph
localized "notation (name := dioph.vec_ex1_dioph) `D∃`:30 := dioph.vec_ex1_dioph" in dioph
localized "prefix (name := fin2.of_nat') `&`:max := fin2.of_nat'" in dioph
theorem proj_dioph_of_nat {n : ℕ} (m : ℕ) [is_lt m n] : dioph_fn (λ v : vector3 ℕ n, v &m) :=
proj_dioph &m
localized "prefix (name := proj_dioph_of_nat) `D&`:100 := dioph.proj_dioph_of_nat" in dioph
theorem const_dioph (n : ℕ) : dioph_fn (const (α → ℕ) n) :=
abs_poly_dioph (poly.const n)
localized "prefix (name := const_dioph) `D.`:100 := dioph.const_dioph" in dioph
variables {f g : (α → ℕ) → ℕ} (df : dioph_fn f) (dg : dioph_fn g)
include df dg
lemma dioph_comp2 {S : ℕ → ℕ → Prop} (d : dioph (λ v:vector3 ℕ 2, S (v &0) (v &1))) :
dioph (λ v, S (f v) (g v)) :=
dioph_comp d [f, g] (by exact ⟨df, dg⟩)
lemma dioph_fn_comp2 {h : ℕ → ℕ → ℕ} (d : dioph_fn (λ v:vector3 ℕ 2, h (v &0) (v &1))) :
dioph_fn (λ v, h (f v) (g v)) :=
dioph_fn_comp d [f, g] (by exact ⟨df, dg⟩)
lemma eq_dioph : dioph (λ v, f v = g v) :=
dioph_comp2 df dg $ of_no_dummies _ (poly.proj &0 - poly.proj &1)
(λ v, (int.coe_nat_eq_coe_nat_iff _ _).symm.trans
⟨@sub_eq_zero_of_eq ℤ _ (v &0) (v &1), eq_of_sub_eq_zero⟩)
localized "infix (name := eq_dioph) ` D= `:50 := dioph.eq_dioph" in dioph
lemma add_dioph : dioph_fn (λ v, f v + g v) :=
dioph_fn_comp2 df dg $ abs_poly_dioph (poly.proj &0 + poly.proj &1)
localized "infix (name := add_dioph) ` D+ `:80 := dioph.add_dioph" in dioph
lemma mul_dioph : dioph_fn (λ v, f v * g v) :=
dioph_fn_comp2 df dg $ abs_poly_dioph (poly.proj &0 * poly.proj &1)
localized "infix (name := mul_dioph) ` D* `:90 := dioph.mul_dioph" in dioph
lemma le_dioph : dioph {v | f v ≤ g v} :=
dioph_comp2 df dg $ ext (D∃2 $ D&1 D+ D&0 D= D&2) (λ v, ⟨λ ⟨x, hx⟩, le.intro hx, le.dest⟩)
localized "infix (name := le_dioph) ` D≤ `:50 := dioph.le_dioph" in dioph
lemma lt_dioph : dioph {v | f v < g v} := df D+ (D. 1) D≤ dg
localized "infix (name := lt_dioph) ` D< `:50 := dioph.lt_dioph" in dioph
lemma ne_dioph : dioph {v | f v ≠ g v} :=
ext (df D< dg D∨ dg D< df) $ λ v, by { dsimp, exact lt_or_lt_iff_ne }
localized "infix (name := ne_dioph) ` D≠ `:50 := dioph.ne_dioph" in dioph
lemma sub_dioph : dioph_fn (λ v, f v - g v) :=
dioph_fn_comp2 df dg $ (dioph_fn_vec _).2 $
ext (D&1 D= D&0 D+ D&2 D∨ D&1 D≤ D&2 D∧ D&0 D= D.0) $ (vector_all_iff_forall _).1 $ λ x y z,
show (y = x + z ∨ y ≤ z ∧ x = 0) ↔ y - z = x, from
⟨λ o, begin
rcases o with ae | ⟨yz, x0⟩,
{ rw [ae, add_tsub_cancel_right] },
{ rw [x0, tsub_eq_zero_iff_le.mpr yz] }
end, begin
rintro rfl,
cases le_total y z with yz zy,
{ exact or.inr ⟨yz, tsub_eq_zero_iff_le.mpr yz⟩ },
{ exact or.inl (tsub_add_cancel_of_le zy).symm },
end⟩
localized "infix (name := sub_dioph) ` D- `:80 := dioph.sub_dioph" in dioph
lemma dvd_dioph : dioph (λ v, f v ∣ g v) :=
dioph_comp (D∃2 $ D&2 D= D&1 D* D&0) [f, g] (by exact ⟨df, dg⟩)
localized "infix (name := dvd_dioph) ` D∣ `:50 := dioph.dvd_dioph" in dioph
lemma mod_dioph : dioph_fn (λ v, f v % g v) :=
have dioph (λ v : vector3 ℕ 3, (v &2 = 0 ∨ v &0 < v &2) ∧ ∃ (x : ℕ), v &0 + v &2 * x = v &1),
from (D&2 D= D.0 D∨ D&0 D< D&2) D∧ (D∃3 $ D&1 D+ D&3 D* D&0 D= D&2),
dioph_fn_comp2 df dg $ (dioph_fn_vec _).2 $ ext this $ (vector_all_iff_forall _).1 $ λ z x y,
show ((y = 0 ∨ z < y) ∧ ∃ c, z + y * c = x) ↔ x % y = z, from
⟨λ ⟨h, c, hc⟩, begin rw ← hc; simp; cases h with x0 hl, rw [x0, mod_zero],
exact mod_eq_of_lt hl end,
λ e, by rw ← e; exact ⟨or_iff_not_imp_left.2 $ λ h, mod_lt _ (nat.pos_of_ne_zero h), x / y,
mod_add_div _ _⟩⟩
localized "infix (name := mod_dioph) ` D% `:80 := dioph.mod_dioph" in dioph
lemma modeq_dioph {h : (α → ℕ) → ℕ} (dh : dioph_fn h) : dioph (λ v, f v ≡ g v [MOD h v]) :=
df D% dh D= dg D% dh
localized "notation (name := modeq_dioph) ` D≡ ` := dioph.modeq_dioph" in dioph
lemma div_dioph : dioph_fn (λ v, f v / g v) :=
have dioph (λ v : vector3 ℕ 3, v &2 = 0 ∧ v &0 = 0 ∨ v &0 * v &2 ≤ v &1 ∧ v &1 < (v &0 + 1) * v &2),
from (D&2 D= D.0 D∧ D&0 D= D.0) D∨ D&0 D* D&2 D≤ D&1 D∧ D&1 D< (D&0 D+ D.1) D* D&2,
dioph_fn_comp2 df dg $ (dioph_fn_vec _).2 $ ext this $ (vector_all_iff_forall _).1 $ λ z x y,
show y = 0 ∧ z = 0 ∨ z * y ≤ x ∧ x < (z + 1) * y ↔ x / y = z,
by refine iff.trans _ eq_comm; exact y.eq_zero_or_pos.elim
(λ y0, by rw [y0, nat.div_zero]; exact
⟨λ o, (o.resolve_right $ λ ⟨_, h2⟩, nat.not_lt_zero _ h2).right, λ z0, or.inl ⟨rfl, z0⟩⟩)
(λ ypos, iff.trans ⟨λ o, o.resolve_left $ λ ⟨h1, _⟩, ne_of_gt ypos h1, or.inr⟩
(le_antisymm_iff.trans $ and_congr (nat.le_div_iff_mul_le ypos) $
iff.trans ⟨lt_succ_of_le, le_of_lt_succ⟩ (div_lt_iff_lt_mul ypos)).symm)
localized "infix (name := div_dioph) ` D/ `:80 := dioph.div_dioph" in dioph
omit df dg
open pell
lemma pell_dioph : dioph (λ v:vector3 ℕ 4, ∃ h : 1 < v &0,
xn h (v &1) = v &2 ∧ yn h (v &1) = v &3) :=
have dioph {v : vector3 ℕ 4 |
1 < v &0 ∧ v &1 ≤ v &3 ∧
(v &2 = 1 ∧ v &3 = 0 ∨
∃ (u w s t b : ℕ),
v &2 * v &2 - (v &0 * v &0 - 1) * v &3 * v &3 = 1 ∧
u * u - (v &0 * v &0 - 1) * w * w = 1 ∧
s * s - (b * b - 1) * t * t = 1 ∧
1 < b ∧ (b ≡ 1 [MOD 4 * v &3]) ∧ (b ≡ v &0 [MOD u]) ∧
0 < w ∧ v &3 * v &3 ∣ w ∧
(s ≡ v &2 [MOD u]) ∧
(t ≡ v &1 [MOD 4 * v &3]))}, from
D.1 D< D&0 D∧ D&1 D≤ D&3 D∧
((D&2 D= D.1 D∧ D&3 D= D.0) D∨
(D∃4 $ D∃5 $ D∃6 $ D∃7 $ D∃8 $
D&7 D* D&7 D- (D&5 D* D&5 D- D.1) D* D&8 D* D&8 D= D.1 D∧
D&4 D* D&4 D- (D&5 D* D&5 D- D.1) D* D&3 D* D&3 D= D.1 D∧
D&2 D* D&2 D- (D&0 D* D&0 D- D.1) D* D&1 D* D&1 D= D.1 D∧
D.1 D< D&0 D∧ (D≡ (D&0) (D.1) (D.4 D* D&8)) D∧ (D≡ (D&0) (D&5) D&4) D∧
D.0 D< D&3 D∧ D&8 D* D&8 D∣ D&3 D∧
(D≡ (D&2) (D&7) D&4) D∧
(D≡ (D&1) (D&6) (D.4 D* D&8)))),
dioph.ext this $ λ v, matiyasevic.symm
lemma xn_dioph : dioph_pfun (λ v:vector3 ℕ 2, ⟨1 < v &0, λ h, xn h (v &1)⟩) :=
have dioph (λ v:vector3 ℕ 3, ∃ y, ∃ h : 1 < v &1, xn h (v &2) = v &0 ∧ yn h (v &2) = y), from
let D_pell := pell_dioph.reindex_dioph (fin2 4) [&2, &3, &1, &0] in D∃3 D_pell,
(dioph_pfun_vec _).2 $ dioph.ext this $ λ v, ⟨λ ⟨y, h, xe, ye⟩, ⟨h, xe⟩, λ ⟨h, xe⟩, ⟨_, h, xe, rfl⟩⟩
include df dg
/-- A version of **Matiyasevic's theorem** -/
theorem pow_dioph : dioph_fn (λ v, f v ^ g v) :=
have dioph {v : vector3 ℕ 3 |
v &2 = 0 ∧ v &0 = 1 ∨ 0 < v &2 ∧
(v &1 = 0 ∧ v &0 = 0 ∨ 0 < v &1 ∧
∃ (w a t z x y : ℕ),
(∃ (a1 : 1 < a), xn a1 (v &2) = x ∧ yn a1 (v &2) = y) ∧
(x ≡ y * (a - v &1) + v &0 [MOD t]) ∧
2 * a * v &1 = t + (v &1 * v &1 + 1) ∧
v &0 < t ∧ v &1 ≤ w ∧ v &2 ≤ w ∧
a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1)}, from
let D_pell := pell_dioph.reindex_dioph (fin2 9) [&4, &8, &1, &0] in
(D&2 D= D.0 D∧ D&0 D= D.1) D∨ (D.0 D< D&2 D∧
((D&1 D= D.0 D∧ D&0 D= D.0) D∨ (D.0 D< D&1 D∧
(D∃3 $ D∃4 $ D∃5 $ D∃6 $ D∃7 $ D∃8 $ D_pell D∧
(D≡ (D&1) (D&0 D* (D&4 D- D&7) D+ D&6) (D&3)) D∧
D.2 D* D&4 D* D&7 D= D&3 D+ (D&7 D* D&7 D+ D.1) D∧
D&6 D< D&3 D∧ D&7 D≤ D&5 D∧ D&8 D≤ D&5 D∧
D&4 D* D&4 D- ((D&5 D+ D.1) D* (D&5 D+ D.1) D- D.1) D* (D&5 D* D&2) D* (D&5 D* D&2) D= D.1)))),
dioph_fn_comp2 df dg $ (dioph_fn_vec _).2 $ dioph.ext this $ λ v, iff.symm $
eq_pow_of_pell.trans $ or_congr iff.rfl $ and_congr iff.rfl $ or_congr iff.rfl $ and_congr iff.rfl $
⟨λ ⟨w, a, t, z, a1, h⟩, ⟨w, a, t, z, _, _, ⟨a1, rfl, rfl⟩, h⟩,
λ ⟨w, a, t, z, ._, ._, ⟨a1, rfl, rfl⟩, h⟩, ⟨w, a, t, z, a1, h⟩⟩
end
end dioph
|
763f5145615a0b9de8cd5aab98dac8a5589dd6c9 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/number_theory/lucas_primality.lean | f2b85d805b3778bb2c4bf79803600580d4c59c80 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 2,809 | lean | /-
Copyright (c) 2020 Bolton Bailey. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bolton Bailey
-/
import data.fintype.basic
import group_theory.order_of_element
import tactic.zify
import data.nat.totient
/-!
# The Lucas test for primes.
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file implements the Lucas test for primes (not to be confused with the Lucas-Lehmer test for
Mersenne primes). A number `a` witnesses that `n` is prime if `a` has order `n-1` in the
multiplicative group of integers mod `n`. This is checked by verifying that `a^(n-1) = 1 (mod n)`
and `a^d ≠ 1 (mod n)` for any divisor `d | n - 1`. This test is the basis of the Pratt primality
certificate.
## TODO
- Bonus: Show the reverse implication i.e. if a number is prime then it has a Lucas witness.
Use `units.is_cyclic` from `ring_theory/integral_domain` to show the group is cyclic.
- Write a tactic that uses this theorem to generate Pratt primality certificates
- Integrate Pratt primality certificates into the norm_num primality verifier
## Implementation notes
Note that the proof for `lucas_primality` relies on analyzing the multiplicative group
modulo `p`. Despite this, the theorem still holds vacuously for `p = 0` and `p = 1`: In these
cases, we can take `q` to be any prime and see that `hd` does not hold, since `a^((p-1)/q)` reduces
to `1`.
-/
/--
If `a^(p-1) = 1 mod p`, but `a^((p-1)/q) ≠ 1 mod p` for all prime factors `q` of `p-1`, then `p`
is prime. This is true because `a` has order `p-1` in the multiplicative group mod `p`, so this
group must itself have order `p-1`, which only happens when `p` is prime.
-/
theorem lucas_primality (p : ℕ) (a : zmod p) (ha : a^(p-1) = 1)
(hd : ∀ q : ℕ, q.prime → q ∣ (p-1) → a^((p-1)/q) ≠ 1) : p.prime :=
begin
have h0 : p ≠ 0, { rintro ⟨⟩, exact hd 2 nat.prime_two (dvd_zero _) (pow_zero _) },
have h1 : p ≠ 1, { rintro ⟨⟩, exact hd 2 nat.prime_two (dvd_zero _) (pow_zero _) },
have hp1 : 1 < p := lt_of_le_of_ne h0.bot_lt h1.symm,
have order_of_a : order_of a = p-1,
{ apply order_of_eq_of_pow_and_pow_div_prime _ ha hd,
exact tsub_pos_of_lt hp1, },
haveI : ne_zero p := ⟨h0⟩,
rw nat.prime_iff_card_units,
-- Prove cardinality of `units` of `zmod p` is both `≤ p-1` and `≥ p-1`
refine le_antisymm (nat.card_units_zmod_lt_sub_one hp1) _,
have hp' : p - 2 + 1 = p - 1 := tsub_add_eq_add_tsub hp1,
let a' : (zmod p)ˣ := units.mk_of_mul_eq_one a (a ^ (p-2)) (by rw [←pow_succ, hp', ha]),
calc p - 1 = order_of a : order_of_a.symm
... = order_of a' : order_of_injective (units.coe_hom (zmod p)) units.ext a'
... ≤ fintype.card (zmod p)ˣ : order_of_le_card_univ,
end
|
ada88cac65246cbd4c88a935c61b05d944c9d40a | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/linear_algebra/affine_space/basis.lean | 307c61c787c4a30a3d1708ff46f30a3b4ed5e940 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 17,629 | lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import linear_algebra.affine_space.independent
import linear_algebra.affine_space.finite_dimensional
import linear_algebra.determinant
/-!
# Affine bases and barycentric coordinates
Suppose `P` is an affine space modelled on the module `V` over the ring `k`, and `p : ι → P` is an
affine-independent family of points spanning `P`. Given this data, each point `q : P` may be written
uniquely as an affine combination: `q = w₀ p₀ + w₁ p₁ + ⋯` for some (finitely-supported) weights
`wᵢ`. For each `i : ι`, we thus have an affine map `P →ᵃ[k] k`, namely `q ↦ wᵢ`. This family of
maps is known as the family of barycentric coordinates. It is defined in this file.
## The construction
Fixing `i : ι`, and allowing `j : ι` to range over the values `j ≠ i`, we obtain a basis `bᵢ` of `V`
defined by `bᵢ j = p j -ᵥ p i`. Let `fᵢ j : V →ₗ[k] k` be the corresponding dual basis and let
`fᵢ = ∑ j, fᵢ j : V →ₗ[k] k` be the corresponding "sum of all coordinates" form. Then the `i`th
barycentric coordinate of `q : P` is `1 - fᵢ (q -ᵥ p i)`.
## Main definitions
* `affine_basis`: a structure representing an affine basis of an affine space.
* `affine_basis.coord`: the map `P →ᵃ[k] k` corresponding to `i : ι`.
* `affine_basis.coord_apply_eq`: the behaviour of `affine_basis.coord i` on `p i`.
* `affine_basis.coord_apply_neq`: the behaviour of `affine_basis.coord i` on `p j` when `j ≠ i`.
* `affine_basis.coord_apply`: the behaviour of `affine_basis.coord i` on `p j` for general `j`.
* `affine_basis.coord_apply_combination`: the characterisation of `affine_basis.coord i` in terms
of affine combinations, i.e., `affine_basis.coord i (w₀ p₀ + w₁ p₁ + ⋯) = wᵢ`.
## TODO
* Construct the affine equivalence between `P` and `{ f : ι →₀ k | f.sum = 1 }`.
-/
open_locale affine big_operators matrix
open set
universes u₁ u₂ u₃ u₄
/-- An affine basis is a family of affine-independent points whose span is the top subspace. -/
structure affine_basis (ι : Type u₁) (k : Type u₂) {V : Type u₃} (P : Type u₄)
[add_comm_group V] [affine_space V P] [ring k] [module k V] :=
(points : ι → P)
(ind : affine_independent k points)
(tot : affine_span k (range points) = ⊤)
variables {ι : Type u₁} {k : Type u₂} {V : Type u₃} {P : Type u₄}
variables [add_comm_group V] [affine_space V P]
namespace affine_basis
section ring
variables [ring k] [module k V] (b : affine_basis ι k P)
/-- The unique point in a single-point space is the simplest example of an affine basis. -/
instance : inhabited (affine_basis punit k punit) :=
⟨{ points := id,
ind := affine_independent_of_subsingleton k id,
tot := by simp }⟩
include b
protected lemma nonempty : nonempty ι :=
not_is_empty_iff.mp $ λ hι,
by simpa only [@range_eq_empty _ _ hι, affine_subspace.span_empty, bot_ne_top] using b.tot
/-- Composition of an affine basis and an equivalence of index types. -/
def comp_equiv {ι'} (e : ι' ≃ ι) : affine_basis ι' k P :=
⟨b.points ∘ e, b.ind.comp_embedding e.to_embedding, by { rw [e.surjective.range_comp], exact b.3 }⟩
/-- Given an affine basis for an affine space `P`, if we single out one member of the family, we
obtain a linear basis for the model space `V`.
The linear basis correpsonding to the singled-out member `i : ι` is indexed by `{j : ι // j ≠ i}`
and its `j`th element is `points j -ᵥ points i`. (See `basis_of_apply`.) -/
noncomputable def basis_of (i : ι) : basis {j : ι // j ≠ i} k V :=
basis.mk ((affine_independent_iff_linear_independent_vsub k b.points i).mp b.ind)
begin
suffices : submodule.span k (range (λ (j : {x // x ≠ i}), b.points ↑j -ᵥ b.points i)) =
vector_span k (range b.points),
{ rw [this, ← direction_affine_span, b.tot, affine_subspace.direction_top], exact le_rfl },
conv_rhs { rw ← image_univ, },
rw vector_span_image_eq_span_vsub_set_right_ne k b.points (mem_univ i),
congr,
ext v,
simp,
end
@[simp] lemma basis_of_apply (i : ι) (j : {j : ι // j ≠ i}) :
b.basis_of i j = b.points ↑j -ᵥ b.points i :=
by simp [basis_of]
/-- The `i`th barycentric coordinate of a point. -/
noncomputable def coord (i : ι) : P →ᵃ[k] k :=
{ to_fun := λ q, 1 - (b.basis_of i).sum_coords (q -ᵥ b.points i),
linear := -(b.basis_of i).sum_coords,
map_vadd' := λ q v, by rw [vadd_vsub_assoc, linear_map.map_add, vadd_eq_add, linear_map.neg_apply,
sub_add_eq_sub_sub_swap, add_comm, sub_eq_add_neg], }
@[simp] lemma linear_eq_sum_coords (i : ι) :
(b.coord i).linear = -(b.basis_of i).sum_coords :=
rfl
@[simp] lemma coord_apply_eq (i : ι) :
b.coord i (b.points i) = 1 :=
by simp only [coord, basis.coe_sum_coords, linear_equiv.map_zero, linear_equiv.coe_coe,
sub_zero, affine_map.coe_mk, finsupp.sum_zero_index, vsub_self]
@[simp] lemma coord_apply_neq (i j : ι) (h : j ≠ i) :
b.coord i (b.points j) = 0 :=
by rw [coord, affine_map.coe_mk, ← subtype.coe_mk j h, ← b.basis_of_apply i ⟨j, h⟩,
basis.sum_coords_self_apply, sub_self]
lemma coord_apply [decidable_eq ι] (i j : ι) :
b.coord i (b.points j) = if i = j then 1 else 0 :=
by { cases eq_or_ne i j; simp [h.symm], simp [h], }
@[simp] lemma coord_apply_combination_of_mem
{s : finset ι} {i : ι} (hi : i ∈ s) {w : ι → k} (hw : s.sum w = 1) :
b.coord i (s.affine_combination b.points w) = w i :=
begin
classical,
simp only [coord_apply, hi, finset.affine_combination_eq_linear_combination, if_true, mul_boole,
hw, function.comp_app, smul_eq_mul, s.sum_ite_eq, s.map_affine_combination b.points w hw],
end
@[simp] lemma coord_apply_combination_of_not_mem
{s : finset ι} {i : ι} (hi : i ∉ s) {w : ι → k} (hw : s.sum w = 1) :
b.coord i (s.affine_combination b.points w) = 0 :=
begin
classical,
simp only [coord_apply, hi, finset.affine_combination_eq_linear_combination, if_false, mul_boole,
hw, function.comp_app, smul_eq_mul, s.sum_ite_eq, s.map_affine_combination b.points w hw],
end
@[simp] lemma sum_coord_apply_eq_one [fintype ι] (q : P) :
∑ i, b.coord i q = 1 :=
begin
have hq : q ∈ affine_span k (range b.points), { rw b.tot, exact affine_subspace.mem_top k V q, },
obtain ⟨w, hw, rfl⟩ := eq_affine_combination_of_mem_affine_span_of_fintype hq,
convert hw,
ext i,
exact b.coord_apply_combination_of_mem (finset.mem_univ i) hw,
end
@[simp] lemma affine_combination_coord_eq_self [fintype ι] (q : P) :
finset.univ.affine_combination b.points (λ i, b.coord i q) = q :=
begin
have hq : q ∈ affine_span k (range b.points), { rw b.tot, exact affine_subspace.mem_top k V q, },
obtain ⟨w, hw, rfl⟩ := eq_affine_combination_of_mem_affine_span_of_fintype hq,
congr,
ext i,
exact b.coord_apply_combination_of_mem (finset.mem_univ i) hw,
end
/-- A variant of `affine_basis.affine_combination_coord_eq_self` for the special case when the
affine space is a module so we can talk about linear combinations. -/
@[simp] lemma linear_combination_coord_eq_self [fintype ι] (b : affine_basis ι k V) (v : V) :
∑ i, (b.coord i v) • (b.points i) = v :=
begin
have hb := b.affine_combination_coord_eq_self v,
rwa finset.univ.affine_combination_eq_linear_combination _ _ (b.sum_coord_apply_eq_one v) at hb,
end
lemma ext_elem [fintype ι] {q₁ q₂ : P} (h : ∀ i, b.coord i q₁ = b.coord i q₂) : q₁ = q₂ :=
begin
rw [← b.affine_combination_coord_eq_self q₁, ← b.affine_combination_coord_eq_self q₂],
simp only [h],
end
@[simp] lemma coe_coord_of_subsingleton_eq_one [subsingleton ι] (i : ι) :
(b.coord i : P → k) = 1 :=
begin
ext q,
have hp : (range b.points).subsingleton,
{ rw ← image_univ,
apply subsingleton.image,
apply subsingleton_of_subsingleton, },
haveI := affine_subspace.subsingleton_of_subsingleton_span_eq_top hp b.tot,
let s : finset ι := {i},
have hi : i ∈ s, { simp, },
have hw : s.sum (function.const ι (1 : k)) = 1, { simp, },
have hq : q = s.affine_combination b.points (function.const ι (1 : k)), { simp, },
rw [pi.one_apply, hq, b.coord_apply_combination_of_mem hi hw],
end
lemma surjective_coord [nontrivial ι] (i : ι) :
function.surjective $ b.coord i :=
begin
classical,
intros x,
obtain ⟨j, hij⟩ := exists_ne i,
let s : finset ι := {i, j},
have hi : i ∈ s, { simp, },
have hj : j ∈ s, { simp, },
let w : ι → k := λ j', if j' = i then x else 1-x,
have hw : s.sum w = 1, { simp [hij, finset.sum_ite, finset.filter_insert, finset.filter_eq'], },
use s.affine_combination b.points w,
simp [b.coord_apply_combination_of_mem hi hw],
end
/-- Barycentric coordinates as an affine map. -/
noncomputable def coords : P →ᵃ[k] ι → k :=
{ to_fun := λ q i, b.coord i q,
linear :=
{ to_fun := λ v i, -(b.basis_of i).sum_coords v,
map_add' := λ v w, by { ext i, simp only [linear_map.map_add, pi.add_apply, neg_add], },
map_smul' := λ t v, by { ext i, simpa only [linear_map.map_smul, pi.smul_apply, smul_neg] } },
map_vadd' := λ p v, by
{ ext i,
simp only [linear_eq_sum_coords, linear_map.coe_mk, linear_map.neg_apply, pi.vadd_apply',
affine_map.map_vadd], }, }
@[simp] lemma coords_apply (q : P) (i : ι) :
b.coords q i = b.coord i q :=
rfl
/-- Given an affine basis `p`, and a family of points `q : ι' → P`, this is the matrix whose
rows are the barycentric coordinates of `q` with respect to `p`.
It is an affine equivalent of `basis.to_matrix`. -/
noncomputable def to_matrix {ι' : Type*} (q : ι' → P) : matrix ι' ι k :=
λ i j, b.coord j (q i)
@[simp] lemma to_matrix_apply {ι' : Type*} (q : ι' → P) (i : ι') (j : ι) :
b.to_matrix q i j = b.coord j (q i) :=
rfl
@[simp] lemma to_matrix_self [decidable_eq ι] :
b.to_matrix b.points = (1 : matrix ι ι k) :=
begin
ext i j,
rw [to_matrix_apply, coord_apply, matrix.one_eq_pi_single, pi.single_apply],
end
variables {ι' : Type*} [fintype ι'] [fintype ι] (b₂ : affine_basis ι k P)
lemma to_matrix_row_sum_one {ι' : Type*} (q : ι' → P) (i : ι') :
∑ j, b.to_matrix q i j = 1 :=
by simp
/-- Given a family of points `p : ι' → P` and an affine basis `b`, if the matrix whose rows are the
coordinates of `p` with respect `b` has a right inverse, then `p` is affine independent. -/
lemma affine_independent_of_to_matrix_right_inv [decidable_eq ι']
(p : ι' → P) {A : matrix ι ι' k} (hA : (b.to_matrix p) ⬝ A = 1) : affine_independent k p :=
begin
rw affine_independent_iff_eq_of_fintype_affine_combination_eq,
intros w₁ w₂ hw₁ hw₂ hweq,
have hweq' : (b.to_matrix p).vec_mul w₁ = (b.to_matrix p).vec_mul w₂,
{ ext j,
change ∑ i, (w₁ i) • (b.coord j (p i)) = ∑ i, (w₂ i) • (b.coord j (p i)),
rw [← finset.univ.affine_combination_eq_linear_combination _ _ hw₁,
← finset.univ.affine_combination_eq_linear_combination _ _ hw₂,
← finset.univ.map_affine_combination p w₁ hw₁,
← finset.univ.map_affine_combination p w₂ hw₂, hweq], },
replace hweq' := congr_arg (λ w, A.vec_mul w) hweq',
simpa only [matrix.vec_mul_vec_mul, ← matrix.mul_eq_mul, hA, matrix.vec_mul_one] using hweq',
end
/-- Given a family of points `p : ι' → P` and an affine basis `b`, if the matrix whose rows are the
coordinates of `p` with respect `b` has a left inverse, then `p` spans the entire space. -/
lemma affine_span_eq_top_of_to_matrix_left_inv [decidable_eq ι] [nontrivial k]
(p : ι' → P) {A : matrix ι ι' k} (hA : A ⬝ b.to_matrix p = 1) : affine_span k (range p) = ⊤ :=
begin
suffices : ∀ i, b.points i ∈ affine_span k (range p),
{ rw [eq_top_iff, ← b.tot, affine_span_le],
rintros q ⟨i, rfl⟩,
exact this i, },
intros i,
have hAi : ∑ j, A i j = 1,
{ calc ∑ j, A i j = ∑ j, (A i j) * ∑ l, b.to_matrix p j l : by simp
... = ∑ j, ∑ l, (A i j) * b.to_matrix p j l : by simp_rw finset.mul_sum
... = ∑ l, ∑ j, (A i j) * b.to_matrix p j l : by rw finset.sum_comm
... = ∑ l, (A ⬝ b.to_matrix p) i l : rfl
... = 1 : by simp [hA, matrix.one_apply, finset.filter_eq], },
have hbi : b.points i = finset.univ.affine_combination p (A i),
{ apply b.ext_elem,
intros j,
rw [b.coord_apply, finset.univ.map_affine_combination _ _ hAi,
finset.univ.affine_combination_eq_linear_combination _ _ hAi],
change _ = (A ⬝ b.to_matrix p) i j,
simp_rw [hA, matrix.one_apply, @eq_comm _ i j] },
rw hbi,
exact affine_combination_mem_affine_span hAi p,
end
/-- A change of basis formula for barycentric coordinates.
See also `affine_basis.to_matrix_inv_mul_affine_basis_to_matrix`. -/
@[simp] lemma to_matrix_vec_mul_coords (x : P) :
(b.to_matrix b₂.points).vec_mul (b₂.coords x) = b.coords x :=
begin
ext j,
change _ = b.coord j x,
conv_rhs { rw ← b₂.affine_combination_coord_eq_self x, },
rw finset.map_affine_combination _ _ _ (b₂.sum_coord_apply_eq_one x),
simp [matrix.vec_mul, matrix.dot_product, to_matrix_apply, coords],
end
variables [decidable_eq ι]
lemma to_matrix_mul_to_matrix :
(b.to_matrix b₂.points) ⬝ (b₂.to_matrix b.points) = 1 :=
begin
ext l m,
change (b₂.to_matrix b.points).vec_mul (b.coords (b₂.points l)) m = _,
rw [to_matrix_vec_mul_coords, coords_apply, ← to_matrix_apply, to_matrix_self],
end
lemma is_unit_to_matrix :
is_unit (b.to_matrix b₂.points) :=
⟨{ val := b.to_matrix b₂.points,
inv := b₂.to_matrix b.points,
val_inv := b.to_matrix_mul_to_matrix b₂,
inv_val := b₂.to_matrix_mul_to_matrix b, }, rfl⟩
lemma is_unit_to_matrix_iff [nontrivial k] (p : ι → P) :
is_unit (b.to_matrix p) ↔ affine_independent k p ∧ affine_span k (range p) = ⊤ :=
begin
split,
{ rintros ⟨⟨B, A, hA, hA'⟩, (rfl : B = b.to_matrix p)⟩,
rw matrix.mul_eq_mul at hA hA',
exact ⟨b.affine_independent_of_to_matrix_right_inv p hA,
b.affine_span_eq_top_of_to_matrix_left_inv p hA'⟩, },
{ rintros ⟨h_tot, h_ind⟩,
let b' : affine_basis ι k P := ⟨p, h_tot, h_ind⟩,
change is_unit (b.to_matrix b'.points),
exact b.is_unit_to_matrix b', },
end
end ring
section comm_ring
variables [comm_ring k] [module k V] [decidable_eq ι] [fintype ι]
variables (b b₂ : affine_basis ι k P)
/-- A change of basis formula for barycentric coordinates.
See also `affine_basis.to_matrix_vec_mul_coords`. -/
@[simp] lemma to_matrix_inv_vec_mul_to_matrix (x : P) :
(b.to_matrix b₂.points)⁻¹.vec_mul (b.coords x) = b₂.coords x :=
begin
have hu := b.is_unit_to_matrix b₂,
rw matrix.is_unit_iff_is_unit_det at hu,
rw [← b.to_matrix_vec_mul_coords b₂, matrix.vec_mul_vec_mul, matrix.mul_nonsing_inv _ hu,
matrix.vec_mul_one],
end
/-- If we fix a background affine basis `b`, then for any other basis `b₂`, we can characterise
the barycentric coordinates provided by `b₂` in terms of determinants relative to `b`. -/
lemma det_smul_coords_eq_cramer_coords (x : P) :
(b.to_matrix b₂.points).det • b₂.coords x = (b.to_matrix b₂.points)ᵀ.cramer (b.coords x) :=
begin
have hu := b.is_unit_to_matrix b₂,
rw matrix.is_unit_iff_is_unit_det at hu,
rw [← b.to_matrix_inv_vec_mul_to_matrix, matrix.det_smul_inv_vec_mul_eq_cramer_transpose _ _ hu],
end
end comm_ring
section division_ring
variables [division_ring k] [module k V]
include V
protected lemma finite_dimensional [finite ι] (b : affine_basis ι k P) : finite_dimensional k V :=
let ⟨i⟩ := b.nonempty in finite_dimensional.of_fintype_basis (b.basis_of i)
protected lemma finite [finite_dimensional k V] (b : affine_basis ι k P) : finite ι :=
finite_of_fin_dim_affine_independent k b.ind
protected lemma finite_set [finite_dimensional k V] {s : set ι} (b : affine_basis s k P) :
s.finite :=
finite_set_of_fin_dim_affine_independent k b.ind
@[simp] lemma coord_apply_centroid [char_zero k] (b : affine_basis ι k P) {s : finset ι} {i : ι}
(hi : i ∈ s) :
b.coord i (s.centroid k b.points) = (s.card : k) ⁻¹ :=
by rw [finset.centroid, b.coord_apply_combination_of_mem hi
(s.sum_centroid_weights_eq_one_of_nonempty _ ⟨i, hi⟩), finset.centroid_weights]
lemma card_eq_finrank_add_one [fintype ι] (b : affine_basis ι k P) :
fintype.card ι = finite_dimensional.finrank k V + 1 :=
begin
haveI := b.finite_dimensional,
exact b.ind.affine_span_eq_top_iff_card_eq_finrank_add_one.mp b.tot
end
lemma exists_affine_subbasis {t : set P} (ht : affine_span k t = ⊤) :
∃ (s ⊆ t) (b : affine_basis ↥s k P), b.points = coe :=
begin
obtain ⟨s, hst, h_tot, h_ind⟩ := exists_affine_independent k V t,
refine ⟨s, hst, ⟨coe, h_ind, _⟩, rfl⟩,
rw [subtype.range_coe, h_tot, ht]
end
variables (k V P)
lemma exists_affine_basis : ∃ (s : set P) (b : affine_basis ↥s k P), b.points = coe :=
let ⟨s, _, hs⟩ := exists_affine_subbasis (affine_subspace.span_univ k V P) in ⟨s, hs⟩
variables {k V P}
lemma exists_affine_basis_of_finite_dimensional [fintype ι] [finite_dimensional k V]
(h : fintype.card ι = finite_dimensional.finrank k V + 1) :
nonempty (affine_basis ι k P) :=
begin
obtain ⟨s, b, hb⟩ := affine_basis.exists_affine_basis k V P,
lift s to finset P using b.finite_set,
refine ⟨b.comp_equiv $ fintype.equiv_of_card_eq _⟩,
rw [h, ← b.card_eq_finrank_add_one]
end
end division_ring
end affine_basis
|
1bf7953d4ef5ec166cddbfeb9680896dd78fa986 | a623837965543f72645ad3de4797a693f5c64274 | /src/tidy/backwards_reasoning.lean | 039bea8c8eabfb6b3b54d806fcb6b8d78258320e | [] | no_license | khoek/lean-tidy | 9e1c8ffebc6a3e4739128e6cf7b7e84cba3a0625 | 995fbf6efa56f6c01cdb3754fc4a84b648a6dd91 | refs/heads/master | 1,619,535,208,982 | 1,549,094,268,000 | 1,549,094,268,000 | 122,460,123 | 0 | 0 | null | 1,534,214,616,000 | 1,519,293,337,000 | Lean | UTF-8 | Lean | false | false | 2,495 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Scott Morrison
import tactic.basic
import tactic.ext
import .recover
open tactic
meta def back_attribute : user_attribute := {
name := `back,
descr := "A lemma that should be applied to a goal whenever possible; use `backwards_reasoning` to automatically `apply` all lemmas tagged `[back]`."
}
run_cmd attribute.register ``back_attribute
/-- Try to apply the given lemma, solving new terminal goals by solve_by_elim if possible. -/
meta def apply_using_solve_by_elim (c : name) : tactic unit :=
focus1 $ do
t ← mk_const c,
r ← apply t,
try (any_goals (terminal_goal >> solve_by_elim))
meta def elim_attribute : user_attribute := {
name := `elim,
descr := "A lemma that should be applied to a goal whenever possible, as long as all arguments to the lemma by be fulfilled from existing hypotheses; use `backwards_reasoning` to automatically apply all lemmas tagged `[elim]`."
}
run_cmd attribute.register ``elim_attribute
/-- Try to apply the given lemma, fulfilling all new goals using existing hypotheses. -/
meta def apply_no_new_goals (c : name) : tactic unit :=
focus1 $ do
t ← mk_const c,
r ← apply t,
all_goals solve_by_elim,
a ← r.mmap (λ p, do e ← instantiate_mvars p.2, return e.list_meta_vars.length),
guard (a.all (λ n, n = 0))
/-- Try to apply one of the given lemmas; it succeeds as soon as one of them succeeds. -/
meta def any_apply_with (f : name → tactic unit) : list name → tactic name
| [] := failed
| (c::cs) := (f c >> pure c) <|> any_apply_with cs
/-- Try to apply any lemma marked with the attributes `@[back]` or `@[elim]`. -/
meta def backwards_reasoning : tactic string :=
(attribute.get_instances `elim >>= any_apply_with apply_no_new_goals >>=
λ n, return ("apply " ++ n.to_string ++ " ; solve_by_elim")) <|>
(attribute.get_instances `back >>= any_apply_with apply_using_solve_by_elim >>=
λ n, return ("apply " ++ n.to_string)) <|>
fail "no @[back] or @[back'] lemmas could be applied"
attribute [extensionality] subtype.eq
-- TODO should `apply_instance` be in tidy? If so, these shouldn't be needed.
@[back] definition decidable_true : decidable true := is_true dec_trivial
@[back] definition decidable_false : decidable false := is_false dec_trivial
attribute [back] quotient.mk quotient.sound
attribute [back] eqv_gen.rel
attribute [elim] Exists.intro
|
9aebf21e4c0c0f1afd5f5aea8258e3ca024c9273 | 618003631150032a5676f229d13a079ac875ff77 | /src/analysis/calculus/implicit.lean | 1ddb389ea91a8d044a0f709dca7759d18d5cd2da | [
"Apache-2.0"
] | permissive | awainverse/mathlib | 939b68c8486df66cfda64d327ad3d9165248c777 | ea76bd8f3ca0a8bf0a166a06a475b10663dec44a | refs/heads/master | 1,659,592,962,036 | 1,590,987,592,000 | 1,590,987,592,000 | 268,436,019 | 1 | 0 | Apache-2.0 | 1,590,990,500,000 | 1,590,990,500,000 | null | UTF-8 | Lean | false | false | 18,602 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov.
-/
import analysis.calculus.inverse
import analysis.normed_space.complemented
/-!
# Implicit function theorem
We prove three versions of the implicit function theorem. First we define a structure
`implicit_function_data` that holds arguments for the most general version of the implicit function
theorem, see `implicit_function_data.implicit_function`
and `implicit_function_data.to_implicit_function`. This version allows a user to choose
a specific implicit function but provides only a little convenience over the inverse function
theorem.
Then we define `implicit_function_of_complemented`: implicit function defined by `f (g z y) = z`,
where `f : E → F` is a function strictly differentiable at `a` such that its derivative `f'`
is surjective and has a `complemented` kernel.
Finally, if the codomain of `f` is a finite dimensional space, then we can automatically prove
that the kernel of `f'` is complemented, hence the only assumptions are `has_strict_fderiv_at`
and `f'.range = ⊤`. This version is named `implicit_function`.
## TODO
* Add a version for a function `f : E × F → G` such that $$\frac{\partial f}{\partial y}$$ is
invertible.
* Add a version for `f : 𝕜 × 𝕜 → 𝕜` proving `has_strict_deriv_at` and `deriv φ = ...`.
* Prove that in a real vector space the implicit function has the same smoothness as the original
one.
* If the original function is differentiable in a neighborhood, then the implicit function is
differentiable in a neighborhood as well. Current setup only proves differentiability at one
point for the implicit function constructed in this file (as opposed to an unspecified implicit
function). One of the ways to overcome this difficulty is to use uniqueness of the implicit
function in the general version of the theorem. Another way is to prove that *any* implicit
function satisfying some predicate is strictly differentiable.
## Tags
implicit function, inverse function
-/
noncomputable theory
open_locale topological_space
open filter
open continuous_linear_map (fst snd subtype_val smul_right ker_prod)
open continuous_linear_equiv (of_bijective)
/-!
### General version
Consider two functions `f : E → F` and `g : E → G` and a point `a` such that
* both functions are strictly differentiable at `a`;
* the derivatives are surjective;
* the kernels of the derivatives are complementary subspaces of `E`.
Note that the map `x ↦ (f x, g x)` has a bijective derivative, hence it is a local homeomorphism
between `E` and `F × G`. We use this fact to define a function `φ : F → G → E`
(see `implicit_function_data.implicit_function`) such that for `(y, z)` close enough to `(f a, g a)`
we have `f (φ y z) = y` and `g (φ y z) = z`.
We also prove a formula for $$\frac{\partial\varphi}{\partial z}.$$
Though this statement is almost symmetric with respect to `F`, `G`, we interpret it in the following
way. Consider a family of surfaces `{x | f x = y}`, `y ∈ 𝓝 (f a)`. Each of these surfaces is
parametrized by `φ y`.
There are many ways to choose a (differentiable) function `φ` such that `f (φ y z) = y` but the
extra condition `g (φ y z) = z` allows a user to select one of these functions. If we imagine
that the level surfaces `f = const` form a local horizontal foliation, then the choice of
`g` fixes a transverse foliation `g = const`, and `φ` is the inverse function of the projection
of `{x | f x = y}` along this transverse foliation.
This version of the theorem is used to prove the other versions and can be used if a user
needs to have a complete control over the choice of the implicit function.
-/
/-- Data for the general version of the implicit function theorem. It holds two functions
`f : E → F` and `g : E → G` (named `left_fun` and `right_fun`) and a point `a` (named `pt`)
such that
* both functions are strictly differentiable at `a`;
* the derivatives are surjective;
* the kernels of the derivatives are complementary subspaces of `E`. -/
@[nolint has_inhabited_instance]
structure implicit_function_data (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
(E : Type*) [normed_group E] [normed_space 𝕜 E] [complete_space E]
(F : Type*) [normed_group F] [normed_space 𝕜 F] [complete_space F]
(G : Type*) [normed_group G] [normed_space 𝕜 G] [complete_space G] :=
(left_fun : E → F)
(left_deriv : E →L[𝕜] F)
(right_fun : E → G)
(right_deriv : E →L[𝕜] G)
(pt : E)
(left_has_deriv : has_strict_fderiv_at left_fun left_deriv pt)
(right_has_deriv : has_strict_fderiv_at right_fun right_deriv pt)
(left_range : left_deriv.range = ⊤)
(right_range : right_deriv.range = ⊤)
(is_compl_ker : is_compl left_deriv.ker right_deriv.ker)
namespace implicit_function_data
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] [complete_space E]
{F : Type*} [normed_group F] [normed_space 𝕜 F] [complete_space F]
{G : Type*} [normed_group G] [normed_space 𝕜 G] [complete_space G]
(φ : implicit_function_data 𝕜 E F G)
/-- The function given by `x ↦ (left_fun x, right_fun x)`. -/
def prod_fun (x : E) : F × G := (φ.left_fun x, φ.right_fun x)
@[simp] lemma prod_fun_apply (x : E) : φ.prod_fun x = (φ.left_fun x, φ.right_fun x) := rfl
protected lemma has_strict_fderiv_at :
has_strict_fderiv_at φ.prod_fun
(φ.left_deriv.equiv_prod_of_surjective_of_is_compl φ.right_deriv φ.left_range φ.right_range
φ.is_compl_ker : E →L[𝕜] F × G) φ.pt :=
φ.left_has_deriv.prod φ.right_has_deriv
/-- Implicit function theorem. If `f : E → F` and `g : E → G` are two maps strictly differentiable
at `a`, their derivatives `f'`, `g'` are surjective, and the kernels of these derivatives are
complementary subspaces of `E`, then `x ↦ (f x, g x)` defines a local homeomorphism between
`E` and `F × G`. In particular, `{x | f x = f a}` is locally homeomorphic to `G`. -/
def to_local_homeomorph : local_homeomorph E (F × G) :=
φ.has_strict_fderiv_at.to_local_homeomorph _
/-- Implicit function theorem. If `f : E → F` and `g : E → G` are two maps strictly differentiable
at `a`, their derivatives `f'`, `g'` are surjective, and the kernels of these derivatives are
complementary subspaces of `E`, then `implicit_function_of_is_compl_ker` is the unique (germ of a)
map `φ : F → G → E` such that `f (φ y z) = y` and `g (φ y z) = z`. -/
def implicit_function : F → G → E := function.curry $ φ.to_local_homeomorph.symm
@[simp] lemma to_local_homeomorph_coe : ⇑(φ.to_local_homeomorph) = φ.prod_fun := rfl
lemma to_local_homeomorph_apply (x : E) :
φ.to_local_homeomorph x = (φ.left_fun x, φ.right_fun x) :=
rfl
lemma pt_mem_to_local_homeomorph_source :
φ.pt ∈ φ.to_local_homeomorph.source :=
φ.has_strict_fderiv_at.mem_to_local_homeomorph_source
lemma map_pt_mem_to_local_homeomorph_target :
(φ.left_fun φ.pt, φ.right_fun φ.pt) ∈ φ.to_local_homeomorph.target :=
φ.to_local_homeomorph.map_source $ φ.pt_mem_to_local_homeomorph_source
lemma prod_map_implicit_function :
∀ᶠ (p : F × G) in 𝓝 (φ.prod_fun φ.pt), φ.prod_fun (φ.implicit_function p.1 p.2) = p :=
φ.has_strict_fderiv_at.eventually_right_inverse.mono $ λ ⟨z, y⟩ h, h
lemma left_map_implicit_function :
∀ᶠ (p : F × G) in 𝓝 (φ.prod_fun φ.pt), φ.left_fun (φ.implicit_function p.1 p.2) = p.1 :=
φ.prod_map_implicit_function.mono $ λ z, congr_arg prod.fst
lemma right_map_implicit_function :
∀ᶠ (p : F × G) in 𝓝 (φ.prod_fun φ.pt), φ.right_fun (φ.implicit_function p.1 p.2) = p.2 :=
φ.prod_map_implicit_function.mono $ λ z, congr_arg prod.snd
lemma implicit_function_apply_image :
∀ᶠ x in 𝓝 φ.pt, φ.implicit_function (φ.left_fun x) (φ.right_fun x) = x :=
φ.has_strict_fderiv_at.eventually_left_inverse
lemma implicit_function_has_strict_fderiv_at
(g'inv : G →L[𝕜] E) (hg'inv : φ.right_deriv.comp g'inv = continuous_linear_map.id 𝕜 G)
(hg'invf : φ.left_deriv.comp g'inv = 0) :
has_strict_fderiv_at (φ.implicit_function (φ.left_fun φ.pt)) g'inv (φ.right_fun φ.pt) :=
begin
have := φ.has_strict_fderiv_at.to_local_inverse,
simp only [prod_fun] at this,
convert this.comp (φ.right_fun φ.pt)
((has_strict_fderiv_at_const _ _).prod (has_strict_fderiv_at_id _)),
simp only [continuous_linear_map.ext_iff, continuous_linear_map.coe_comp', function.comp_app]
at hg'inv hg'invf ⊢,
simp [continuous_linear_equiv.eq_symm_apply, *]
end
end implicit_function_data
namespace has_strict_fderiv_at
section complemented
/-!
### Case of a complemented kernel
In this section we prove the following version of the implicit function theorem. Consider a map
`f : E → F` and a point `a : E` such that `f` is strictly differentiable at `a`, its derivative `f'`
is surjective and the kernel of `f'` is a complemented subspace of `E` (i.e., it has a closed
complementary subspace). Then there exists a function `φ : F → ker f' → E` such that for `(y, z)`
close to `(f a, 0)` we have `f (φ y z) = y` and the derivative of `φ (f a)` at zero is the
embedding `ker f' → E`.
Note that a map with these properties is not unique. E.g., different choices of a subspace
complementary to `ker f'` lead to different maps `φ`.
-/
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] [complete_space E]
{F : Type*} [normed_group F] [normed_space 𝕜 F] [complete_space F]
{f : E → F} {f' : E →L[𝕜] F} {a : E}
section defs
variables (f f')
/-- Data used to apply the generic implicit function theorem to the case of a strictly
differentiable map such that its derivative is surjective and has a complemented kernel. -/
@[simp] def implicit_function_data_of_complemented (hf : has_strict_fderiv_at f f' a)
(hf' : f'.range = ⊤) (hker : f'.ker.closed_complemented) :
implicit_function_data 𝕜 E F f'.ker :=
{ left_fun := f,
left_deriv := f',
right_fun := λ x, classical.some hker (x - a),
right_deriv := classical.some hker,
pt := a,
left_has_deriv := hf,
right_has_deriv := (classical.some hker).has_strict_fderiv_at.comp a
((has_strict_fderiv_at_id a).sub_const a),
left_range := hf',
right_range := linear_map.range_eq_of_proj (classical.some_spec hker),
is_compl_ker := linear_map.is_compl_of_proj (classical.some_spec hker) }
/-- A local homeomorphism between `E` and `F × f'.ker` sending level surfaces of `f`
to vertical subspaces. -/
def implicit_to_local_homeomorph_of_complemented (hf : has_strict_fderiv_at f f' a)
(hf' : f'.range = ⊤) (hker : f'.ker.closed_complemented) :
local_homeomorph E (F × f'.ker) :=
(implicit_function_data_of_complemented f f' hf hf' hker).to_local_homeomorph
/-- Implicit function `g` defined by `f (g z y) = z`. -/
def implicit_function_of_complemented (hf : has_strict_fderiv_at f f' a)
(hf' : f'.range = ⊤) (hker : f'.ker.closed_complemented) :
F → f'.ker → E :=
(implicit_function_data_of_complemented f f' hf hf' hker).implicit_function
end defs
@[simp] lemma implicit_to_local_homeomorph_of_complemented_fst (hf : has_strict_fderiv_at f f' a)
(hf' : f'.range = ⊤) (hker : f'.ker.closed_complemented) (x : E) :
(hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker x).fst = f x :=
rfl
lemma implicit_to_local_homeomorph_of_complemented_apply
(hf : has_strict_fderiv_at f f' a) (hf' : f'.range = ⊤)
(hker : f'.ker.closed_complemented) (y : E) :
hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker y =
(f y, classical.some hker (y - a)) :=
rfl
@[simp] lemma implicit_to_local_homeomorph_of_complemented_apply_ker
(hf : has_strict_fderiv_at f f' a) (hf' : f'.range = ⊤)
(hker : f'.ker.closed_complemented) (y : f'.ker) :
hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker (y + a) = (f (y + a), y) :=
by simp only [implicit_to_local_homeomorph_of_complemented_apply, add_sub_cancel,
classical.some_spec hker]
@[simp] lemma implicit_to_local_homeomorph_of_complemented_self
(hf : has_strict_fderiv_at f f' a) (hf' : f'.range = ⊤) (hker : f'.ker.closed_complemented) :
hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker a = (f a, 0) :=
by simp [hf.implicit_to_local_homeomorph_of_complemented_apply]
lemma mem_implicit_to_local_homeomorph_of_complemented_source (hf : has_strict_fderiv_at f f' a)
(hf' : f'.range = ⊤) (hker : f'.ker.closed_complemented) :
a ∈ (hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker).source :=
mem_to_local_homeomorph_source _
lemma mem_implicit_to_local_homeomorph_of_complemented_target (hf : has_strict_fderiv_at f f' a)
(hf' : f'.range = ⊤) (hker : f'.ker.closed_complemented) :
(f a, (0 : f'.ker)) ∈ (hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker).target :=
by simpa only [implicit_to_local_homeomorph_of_complemented_self] using
((hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker).map_source $
(hf.mem_implicit_to_local_homeomorph_of_complemented_source hf' hker))
/-- `implicit_function_of_complemented` sends `(z, y)` to a point in `f ⁻¹' z`. -/
lemma map_implicit_function_of_complemented_eq (hf : has_strict_fderiv_at f f' a)
(hf' : f'.range = ⊤) (hker : f'.ker.closed_complemented) :
∀ᶠ (p : F × f'.ker) in 𝓝 (f a, 0),
f (hf.implicit_function_of_complemented f f' hf' hker p.1 p.2) = p.1 :=
((hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker).eventually_right_inverse $
hf.mem_implicit_to_local_homeomorph_of_complemented_target hf' hker).mono $ λ ⟨z, y⟩ h,
congr_arg prod.fst h
/-- Any point in some neighborhood of `a` can be represented as `implicit_function`
of some point. -/
lemma eq_implicit_function_of_complemented (hf : has_strict_fderiv_at f f' a)
(hf' : f'.range = ⊤) (hker : f'.ker.closed_complemented) :
∀ᶠ x in 𝓝 a, hf.implicit_function_of_complemented f f' hf' hker (f x)
(hf.implicit_to_local_homeomorph_of_complemented f f' hf' hker x).snd = x :=
(implicit_function_data_of_complemented f f' hf hf' hker).implicit_function_apply_image
lemma to_implicit_function_of_complemented (hf : has_strict_fderiv_at f f' a)
(hf' : f'.range = ⊤) (hker : f'.ker.closed_complemented) :
has_strict_fderiv_at (hf.implicit_function_of_complemented f f' hf' hker (f a))
(subtype_val f'.ker) 0 :=
by convert (implicit_function_data_of_complemented f f' hf hf'
hker).implicit_function_has_strict_fderiv_at (subtype_val f'.ker) _ _;
[skip, ext, ext]; simp [classical.some_spec hker]
end complemented
/-!
### Finite dimensional case
In this section we prove the following version of the implicit function theorem. Consider a map
`f : E → F` from a Banach normed space to a finite dimensional space.
Take a point `a : E` such that `f` is strictly differentiable at `a` and its derivative `f'`
is surjective. Then there exists a function `φ : F → ker f' → E` such that for `(y, z)`
close to `(f a, 0)` we have `f (φ y z) = y` and the derivative of `φ (f a)` at zero is the
embedding `ker f' → E`.
This version deduces that `ker f'` is a complemented subspace from the fact that `F` is a finite
dimensional space, then applies the previous version.
Note that a map with these properties is not unique. E.g., different choices of a subspace
complementary to `ker f'` lead to different maps `φ`.
-/
section finite_dimensional
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] [complete_space 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] [complete_space E]
{F : Type*} [normed_group F] [normed_space 𝕜 F] [finite_dimensional 𝕜 F]
(f : E → F) (f' : E →L[𝕜] F) {a : E}
/-- Given a map `f : E → F` to a finite dimensional space with a surjective derivative `f'`,
returns a local homeomorphism between `E` and `F × ker f'`. -/
def implicit_to_local_homeomorph (hf : has_strict_fderiv_at f f' a) (hf' : f'.range = ⊤) :
local_homeomorph E (F × f'.ker) :=
by haveI := finite_dimensional.complete 𝕜 F; exact
hf.implicit_to_local_homeomorph_of_complemented f f' hf'
f'.ker_closed_complemented_of_finite_dimensional_range
/-- Implicit function `g` defined by `f (g z y) = z`. -/
def implicit_function (hf : has_strict_fderiv_at f f' a) (hf' : f'.range = ⊤) :
F → f'.ker → E :=
function.curry $ (hf.implicit_to_local_homeomorph f f' hf').symm
variables {f f'}
@[simp] lemma implicit_to_local_homeomorph_fst (hf : has_strict_fderiv_at f f' a)
(hf' : f'.range = ⊤) (x : E) :
(hf.implicit_to_local_homeomorph f f' hf' x).fst = f x :=
rfl
@[simp] lemma implicit_to_local_homeomorph_apply_ker
(hf : has_strict_fderiv_at f f' a) (hf' : f'.range = ⊤) (y : f'.ker) :
hf.implicit_to_local_homeomorph f f' hf' (y + a) = (f (y + a), y) :=
by apply implicit_to_local_homeomorph_of_complemented_apply_ker
@[simp] lemma implicit_to_local_homeomorph_self
(hf : has_strict_fderiv_at f f' a) (hf' : f'.range = ⊤) :
hf.implicit_to_local_homeomorph f f' hf' a = (f a, 0) :=
by apply implicit_to_local_homeomorph_of_complemented_self
lemma mem_implicit_to_local_homeomorph_source (hf : has_strict_fderiv_at f f' a)
(hf' : f'.range = ⊤) :
a ∈ (hf.implicit_to_local_homeomorph f f' hf').source :=
mem_to_local_homeomorph_source _
lemma mem_implicit_to_local_homeomorph_target (hf : has_strict_fderiv_at f f' a)
(hf' : f'.range = ⊤) :
(f a, (0 : f'.ker)) ∈ (hf.implicit_to_local_homeomorph f f' hf').target :=
by apply mem_implicit_to_local_homeomorph_of_complemented_target
/-- `implicit_function` sends `(z, y)` to a point in `f ⁻¹' z`. -/
lemma map_implicit_function_eq (hf : has_strict_fderiv_at f f' a) (hf' : f'.range = ⊤) :
∀ᶠ (p : F × f'.ker) in 𝓝 (f a, 0), f (hf.implicit_function f f' hf' p.1 p.2) = p.1 :=
by apply map_implicit_function_of_complemented_eq
/-- Any point in some neighborhood of `a` can be represented as `implicit_function`
of some point. -/
lemma eq_implicit_function (hf : has_strict_fderiv_at f f' a) (hf' : f'.range = ⊤) :
∀ᶠ x in 𝓝 a, hf.implicit_function f f' hf' (f x)
(hf.implicit_to_local_homeomorph f f' hf' x).snd = x :=
by apply eq_implicit_function_of_complemented
lemma to_implicit_function (hf : has_strict_fderiv_at f f' a) (hf' : f'.range = ⊤) :
has_strict_fderiv_at (hf.implicit_function f f' hf' (f a))
(subtype_val f'.ker) 0 :=
by apply to_implicit_function_of_complemented
end finite_dimensional
end has_strict_fderiv_at
|
f68989f7a8aed09a611b119b5b2ab74ca946f568 | 5749d8999a76f3a8fddceca1f6941981e33aaa96 | /src/geometry/manifold/basic_smooth_bundle.lean | 1ac2d8eeed4c24cd9fc27c2f48c0f45452522b8b | [
"Apache-2.0"
] | permissive | jdsalchow/mathlib | 13ab43ef0d0515a17e550b16d09bd14b76125276 | 497e692b946d93906900bb33a51fd243e7649406 | refs/heads/master | 1,585,819,143,348 | 1,580,072,892,000 | 1,580,072,892,000 | 154,287,128 | 0 | 0 | Apache-2.0 | 1,540,281,610,000 | 1,540,281,609,000 | null | UTF-8 | Lean | false | false | 33,245 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import topology.topological_fiber_bundle geometry.manifold.smooth_manifold_with_corners
/-!
# Basic smooth bundles
In general, a smooth bundle is a bundle over a smooth manifold, whose fiber is a manifold, and
for which the coordinate changes are smooth. In this definition, there are charts involved at
several places: in the manifold structure of the base, in the manifold structure of the fibers, and
in the local trivializations. This makes it a complicated object in general. There is however a
specific situation where things are much simpler: when the fiber is a vector space (no need for
charts for the fibers), and when the local trivializations of the bundle and the charts of the base
coincide. Then everything is expressed in terms of the charts of the base, making for a much
simpler overall structure, which is easier to manipulate formally.
Most vector bundles that naturally occur in differential geometry are of this form:
the tangent bundle, the cotangent bundle, differential forms (used to define de Rham cohomology)
and the bundle of Riemannian metrics. Therefore, it is worth defining a specific constructor for
this kind of bundle, that we call basic smooth bundles.
A basic smooth bundle is thus a smooth bundle over a smooth manifold whose fiber is a vector space,
and which is trivial in the coordinate charts of the base. (We recall that in our notion of manifold
there is a distinguished atlas, which does not need to be maximal: we require the triviality above
this specific atlas). It can be constructed from a basic smooth bundled core, defined below,
specifying the changes in the fiber when one goes from one coordinate chart to another one. We do
not require that this changes in fiber are linear, but only diffeomorphisms.
## Main definitions
* `basic_smooth_bundle_core I M F`: assuming that `M` is a smooth manifold over the model with
corners `I` on `(𝕜, E, H)`, and `F` is a normed vector space over `𝕜`, this structure registers,
for each pair of charts of `M`, a smooth change of coordinates on `F`. This is the core structure
from which one will build a smooth bundle with fiber `F` over `M`.
Let `Z` be a basic smooth bundle core over `M` with fiber `F`. We define
`Z.to_topological_fiber_bundle_core`, the (topological) fiber bundle core associated to `Z`. From it,
we get a space `Z.to_topological_fiber_bundle_core.total_space` (which as a Type is just `M × F`),
with the fiber bundle topology. It inherits a manifold structure (where the charts are in bijection
with the charts of the basis). We show that this manifold is smooth.
Then we use this machinery to construct the tangent bundle of a smooth manifold.
* `tangent_bundle_core I M`: the basic smooth bundle core associated to a smooth manifold `M` over a
model with corners `I`.
* `tangent_bundle I M` : the total space of `tangent_bundle_core I M`. It is itself a
smooth manifold over the model with corners `I.tangent`, the product of `I` and the trivial model
with corners on `E`.
* `tangent_space I x` : the tangent space to `M` at `x`
* `tangent_bundle.proj I M`: the projection from the tangent bundle to the base manifold
## Implementation notes
In the definition of a basic smooth bundle core, we do not require that the coordinate changes of
the fibers are linear map, only that they are diffeomorphisms. Therefore, the fibers of the
resulting fiber bundle do not inherit a vector space structure (as an algebraic object) in general.
As the fiber, as a type, is just `F`, one can still always register the vector space structure, but
it does not make sense to do so (i.e., it will not lead to any useful theorem) unless this structure
is canonical, i.e., the coordinate changes are linear maps.
For instance, we register the vector space structure on the fibers of the tangent bundle. However,
we do not register the normed space structure coming from that of `F` (as it is not canonical, and
we also want to keep the possibility to add a Riemannian structure on the manifold later on without
having two competing normed space instances on the tangent spaces).
We require `F` to be a normed space, and not just a topological vector space, as we want to talk
about smooth functions on `F`. The notion of derivative requires a norm to be defined.
## TODO
construct the cotangent bundle, and the bundles of differential forms. They should follow
functorially from the description of the tangent bundle as a basic smooth bundle.
## Tags
Smooth fiber bundle, vector bundle, tangent space, tangent bundle
-/
noncomputable theory
universe u
open topological_space set
/-- Core structure used to create a smooth bundle above `M` (a manifold over the model with
corner `I`) with fiber the normed vector space `F` over `𝕜`, which is trivial in the chart domains
of `M`. This structure registers the changes in the fibers when one changes coordinate charts in the
base. We do not require the change of coordinates of the fibers to be linear, only smooth.
Therefore, the fibers of the resulting bundle will not inherit a canonical vector space structure
in general. -/
structure basic_smooth_bundle_core {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type u} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [manifold H M] [smooth_manifold_with_corners I M]
(F : Type u) [normed_group F] [normed_space 𝕜 F] :=
(coord_change : atlas H M → atlas H M → H → F → F)
(coord_change_self :
∀ i : atlas H M, ∀ x ∈ i.1.target, ∀ v, coord_change i i x v = v)
(coord_change_comp : ∀ i j k : atlas H M,
∀ x ∈ ((i.1.symm.trans j.1).trans (j.1.symm.trans k.1)).source, ∀ v,
(coord_change j k ((i.1.symm.trans j.1).to_fun x)) (coord_change i j x v) = coord_change i k x v)
(coord_change_smooth : ∀ i j : atlas H M,
times_cont_diff_on 𝕜 ⊤ (λp : E × F, coord_change i j (I.inv_fun p.1) p.2)
((I.to_fun '' (i.1.symm.trans j.1).source).prod (univ : set F)))
namespace basic_smooth_bundle_core
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type u} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] {I : model_with_corners 𝕜 E H}
{M : Type*} [topological_space M] [manifold H M] [smooth_manifold_with_corners I M]
{F : Type u} [normed_group F] [normed_space 𝕜 F]
(Z : basic_smooth_bundle_core I M F)
/-- Fiber bundle core associated to a basic smooth bundle core -/
def to_topological_fiber_bundle_core : topological_fiber_bundle_core (atlas H M) M F :=
{ base_set := λi, i.1.source,
is_open_base_set := λi, i.1.open_source,
index_at := λx, ⟨chart_at H x, chart_mem_atlas H x⟩,
mem_base_set_at := λx, mem_chart_source H x,
coord_change := λi j x v, Z.coord_change i j (i.1.to_fun x) v,
coord_change_self := λi x hx v, Z.coord_change_self i (i.1.to_fun x) (i.1.map_source hx) v,
coord_change_comp := λi j k x ⟨⟨hx1, hx2⟩, hx3⟩ v, begin
have := Z.coord_change_comp i j k (i.1.to_fun x) _ v,
convert this using 2,
{ simp [hx1] },
{ simp [local_equiv.trans_source, hx1, hx2, hx3, i.1.map_source, j.1.map_source] }
end,
coord_change_continuous := λi j, begin
have A : continuous_on (λp : E × F, Z.coord_change i j (I.inv_fun p.1) p.2)
((I.to_fun '' (i.1.symm.trans j.1).source).prod (univ : set F)) :=
(Z.coord_change_smooth i j).continuous_on,
have B : continuous_on (λx : M, I.to_fun (i.1.to_fun x)) i.1.source :=
I.continuous_to_fun.comp_continuous_on i.1.continuous_to_fun,
have C : continuous_on (λp : M × F, (⟨I.to_fun (i.1.to_fun p.1), p.2⟩ : E × F))
(i.1.source.prod univ),
{ apply continuous_on.prod _ continuous_snd.continuous_on,
exact B.comp continuous_fst.continuous_on (prod_subset_preimage_fst _ _) },
have C' : continuous_on (λp : M × F, (⟨I.to_fun (i.1.to_fun p.1), p.2⟩ : E × F))
((i.1.source ∩ j.1.source).prod univ) :=
continuous_on.mono C (prod_mono (inter_subset_left _ _) (subset.refl _)),
have D : (i.1.source ∩ j.1.source).prod univ ⊆ (λ (p : M × F),
(I.to_fun (i.1.to_fun p.1), p.2)) ⁻¹' ((I.to_fun '' (i.1.symm.trans j.1).source).prod univ),
{ rintros ⟨x, v⟩ hx,
simp at hx,
simp [mem_image_of_mem, local_equiv.trans_source, hx] },
convert continuous_on.comp A C' D,
ext p,
simp
end }
@[simp] lemma base_set (i : atlas H M) :
Z.to_topological_fiber_bundle_core.base_set i = i.1.source := rfl
/-- Local chart for the total space of a basic smooth bundle -/
def chart {e : local_homeomorph M H} (he : e ∈ atlas H M) :
local_homeomorph (Z.to_topological_fiber_bundle_core.total_space) (H × F) :=
(Z.to_topological_fiber_bundle_core.local_triv ⟨e, he⟩).trans
(local_homeomorph.prod e (local_homeomorph.refl F))
@[simp] lemma chart_source (e : local_homeomorph M H) (he : e ∈ atlas H M) :
(Z.chart he).source = Z.to_topological_fiber_bundle_core.proj ⁻¹' e.source :=
by { ext p, simp [chart, local_equiv.trans_source] }
@[simp] lemma chart_target (e : local_homeomorph M H) (he : e ∈ atlas H M) :
(Z.chart he).target = e.target.prod univ :=
begin
simp only [chart, local_equiv.trans_target, local_homeomorph.prod_to_local_equiv, id.def,
local_equiv.refl_inv_fun, local_homeomorph.trans_to_local_equiv, local_equiv.refl_target,
local_homeomorph.refl_local_equiv, local_equiv.prod_target, local_homeomorph.prod_inv_fun],
ext p,
split;
simp [e.map_target] {contextual := tt}
end
/-- The total space of a basic smooth bundle is endowed with a manifold structure, where the charts
are in bijection with the charts of the basis. -/
instance to_manifold : manifold (H × F) Z.to_topological_fiber_bundle_core.total_space :=
{ atlas := ⋃(e : local_homeomorph M H) (he : e ∈ atlas H M), {Z.chart he},
chart_at := λp, Z.chart (chart_mem_atlas H p.1),
mem_chart_source := λp, by simp [mem_chart_source],
chart_mem_atlas := λp, begin
simp only [mem_Union, mem_singleton_iff, chart_mem_atlas],
exact ⟨chart_at H p.1, chart_mem_atlas H p.1, rfl⟩
end }
lemma mem_atlas_iff (f : local_homeomorph Z.to_topological_fiber_bundle_core.total_space (H × F)) :
f ∈ atlas (H × F) Z.to_topological_fiber_bundle_core.total_space ↔
∃(e : local_homeomorph M H) (he : e ∈ atlas H M), f = Z.chart he :=
by simp [atlas, manifold.atlas]
@[simp] lemma mem_chart_source_iff (p q : Z.to_topological_fiber_bundle_core.total_space) :
p ∈ (chart_at (H × F) q).source ↔ p.1 ∈ (chart_at H q.1).source :=
by simp [chart_at, manifold.chart_at]
@[simp] lemma mem_chart_target_iff (p : H × F) (q : Z.to_topological_fiber_bundle_core.total_space) :
p ∈ (chart_at (H × F) q).target ↔ p.1 ∈ (chart_at H q.1).target :=
by simp [chart_at, manifold.chart_at]
@[simp] lemma chart_at_to_fun_fst (p q : Z.to_topological_fiber_bundle_core.total_space) :
((chart_at (H × F) q).to_fun p).1 = (chart_at H q.1).to_fun p.1 := rfl
@[simp] lemma chart_at_inv_fun_fst (p : H × F) (q : Z.to_topological_fiber_bundle_core.total_space) :
((chart_at (H × F) q).inv_fun p).1 = (chart_at H q.1).inv_fun p.1 := rfl
/-- Smooth manifold structure on the total space of a basic smooth bundle -/
instance to_smooth_manifold :
smooth_manifold_with_corners (I.prod (model_with_corners_self 𝕜 F))
Z.to_topological_fiber_bundle_core.total_space :=
begin
/- We have to check that the charts belong to the smooth groupoid, i.e., they are smooth on their
source, and their inverses are smooth on the target. Since both objects are of the same type, it
suffices to prove the first statement in A below, and then glue back the pieces at the end. -/
let J := model_with_corners.to_local_equiv (I.prod (model_with_corners_self 𝕜 F)),
have A : ∀ (e e' : local_homeomorph M H) (he : e ∈ atlas H M) (he' : e' ∈ atlas H M),
times_cont_diff_on 𝕜 ⊤
(J.to_fun ∘ ((Z.chart he).symm.trans (Z.chart he')).to_fun ∘ J.inv_fun)
(J.inv_fun ⁻¹' ((Z.chart he).symm.trans (Z.chart he')).source ∩ range J.to_fun),
{ assume e e' he he',
have U : unique_diff_on 𝕜
((I.inv_fun ⁻¹' (e.symm.trans e').source ∩ range I.to_fun).prod (univ : set F)),
{ apply unique_diff_on.prod _ unique_diff_on_univ,
rw inter_comm,
exact I.unique_diff.inter (I.continuous_inv_fun _ (local_homeomorph.open_source _)) },
have : J.inv_fun ⁻¹' ((chart Z he).symm.trans (chart Z he')).source ∩ range J.to_fun =
(I.inv_fun ⁻¹' (e.symm.trans e').source ∩ range I.to_fun).prod univ,
{ have : range (λ (p : H × F), (I.to_fun (p.fst), id p.snd)) =
(range I.to_fun).prod (range (id : F → F)) := prod_range_range_eq.symm,
simp at this,
ext p,
simp [-mem_range, J, local_equiv.trans_source, chart, model_with_corners.prod,
local_equiv.trans_target, this],
split,
{ tauto },
{ exact λ⟨⟨hx1, hx2⟩, hx3⟩, ⟨⟨⟨hx1, e.map_target hx1⟩, hx2⟩, hx3⟩ } },
rw this,
-- check separately that the two components of the coordinate change are smooth
apply times_cont_diff_on.prod _ _ U,
show times_cont_diff_on 𝕜 ⊤ (λ (p : E × F), (I.to_fun ∘ e'.to_fun ∘ e.inv_fun ∘ I.inv_fun) p.1)
((I.inv_fun ⁻¹' (e.symm.trans e').source ∩ range I.to_fun).prod (univ : set F)),
{ -- the coordinate change on the base is just a coordinate change for `M`, smooth since
-- `M` is smooth
have A : times_cont_diff_on 𝕜 ⊤
(I.to_fun ∘ (e.symm.trans e').to_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (e.symm.trans e').source ∩ range I.to_fun) :=
(has_groupoid.compatible (times_cont_diff_groupoid ⊤ I) he he').1,
have B : times_cont_diff_on 𝕜 ⊤ (λp : E × F, p.1)
((I.inv_fun ⁻¹' (e.symm.trans e').source ∩ range I.to_fun).prod univ) :=
times_cont_diff_fst.times_cont_diff_on U,
exact times_cont_diff_on.comp A B U (prod_subset_preimage_fst _ _) },
show times_cont_diff_on 𝕜 ⊤ (λ (p : E × F),
Z.coord_change ⟨chart_at H (e.inv_fun (I.inv_fun p.1)), _⟩ ⟨e', he'⟩
((chart_at H (e.inv_fun (I.inv_fun p.1))).to_fun (e.inv_fun (I.inv_fun p.1)))
(Z.coord_change ⟨e, he⟩ ⟨chart_at H (e.inv_fun (I.inv_fun p.1)), _⟩
(e.to_fun (e.inv_fun (I.inv_fun p.1))) p.2))
((I.inv_fun ⁻¹' (e.symm.trans e').source ∩ range I.to_fun).prod (univ : set F)),
{ /- The coordinate change in the fiber is more complicated as its definition involves the
reference chart chosen at each point. However, it appears with its inverse, so using the
cocycle property one can get rid of it, and then conclude using the smoothness of the
cocycle as given in the definition of basic smooth bundles. -/
have := Z.coord_change_smooth ⟨e, he⟩ ⟨e', he'⟩,
rw model_with_corners.image at this,
apply times_cont_diff_on.congr this U,
rintros ⟨x, v⟩ hx,
simp [local_equiv.trans_source] at hx,
let f := chart_at H (e.inv_fun (I.inv_fun x)),
have A : I.inv_fun x ∈ ((e.symm.trans f).trans (f.symm.trans e')).source,
by simp [local_equiv.trans_source, hx.1.1, hx.1.2, mem_chart_source, f.map_source],
rw e.right_inv hx.1.1,
have := Z.coord_change_comp ⟨e, he⟩ ⟨f, chart_mem_atlas _ _⟩ ⟨e', he'⟩ (I.inv_fun x) A v,
simpa using this } },
haveI : has_groupoid Z.to_topological_fiber_bundle_core.total_space
(times_cont_diff_groupoid ⊤ (I.prod (model_with_corners_self 𝕜 F))) :=
begin
split,
assume e₀ e₀' he₀ he₀',
rcases (Z.mem_atlas_iff _).1 he₀ with ⟨e, he, rfl⟩,
rcases (Z.mem_atlas_iff _).1 he₀' with ⟨e', he', rfl⟩,
rw [times_cont_diff_groupoid, mem_groupoid_of_pregroupoid],
exact ⟨A e e' he he', A e' e he' he⟩
end,
constructor
end
end basic_smooth_bundle_core
section tangent_bundle
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type u} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [manifold H M] [smooth_manifold_with_corners I M]
set_option class.instance_max_depth 50
/-- Basic smooth bundle core version of the tangent bundle of a smooth manifold `M` modelled over a
model with corners `I` on `(E, H)`. The fibers are equal to `E`, and the coordinate change in the
fiber corresponds to the derivative of the coordinate change in `M`. -/
def tangent_bundle_core : basic_smooth_bundle_core I M E :=
{ coord_change := λi j x v, (fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(range I.to_fun) (I.to_fun x) : E → E) v,
coord_change_smooth := λi j, begin
/- To check that the coordinate change of the bundle is smooth, one should just use the
smoothness of the charts, and thus the smoothness of their derivatives. -/
rw model_with_corners.image,
have A : times_cont_diff_on 𝕜 ⊤
(I.to_fun ∘ (i.1.symm.trans j.1).to_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun) :=
(has_groupoid.compatible (times_cont_diff_groupoid ⊤ I) i.2 j.2).1,
have B : unique_diff_on 𝕜 (I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun),
{ rw inter_comm,
apply I.unique_diff.inter (I.continuous_inv_fun _ (local_homeomorph.open_source _)) },
have C : times_cont_diff_on 𝕜 ⊤
(λ (p : E × E), (fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun) p.1 : E → E) p.2)
((I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun).prod univ) :=
times_cont_diff_on_fderiv_within_apply A B lattice.le_top,
have D : ∀ x ∈ (I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun),
fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(range I.to_fun) x =
fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun) x,
{ assume x hx,
have N : I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∈ nhds x :=
I.continuous_inv_fun.continuous_at.preimage_mem_nhds
(mem_nhds_sets (local_homeomorph.open_source _) hx.1),
symmetry,
rw inter_comm,
exact fderiv_within_inter N (I.unique_diff _ hx.2) },
apply times_cont_diff_on.congr C (unique_diff_on.prod B unique_diff_on_univ),
rintros ⟨x, v⟩ hx,
have E : x ∈ I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun,
by simpa using hx,
have : I.to_fun (I.inv_fun x) = x, by simp [E.2],
dsimp,
rw [this, D x E],
refl
end,
coord_change_self := λi x hx v, begin
/- Locally, a self-change of coordinate is just the identity, thus its derivative is the
identity. One just needs to write this carefully, paying attention to the sets where the
functions are defined. -/
have A : I.inv_fun ⁻¹' (i.1.symm.trans i.1).source ∩ range I.to_fun ∈
nhds_within (I.to_fun x) (range I.to_fun),
{ rw inter_comm,
apply inter_mem_nhds_within,
apply I.continuous_inv_fun.continuous_at.preimage_mem_nhds
(mem_nhds_sets (local_homeomorph.open_source _) _),
simp [hx, local_equiv.trans_source, i.1.map_target] },
have B : {y : E | (I.to_fun ∘ i.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) y = (id : E → E) y} ∈
nhds_within (I.to_fun x) (range I.to_fun),
{ apply filter.mem_sets_of_superset A,
assume y hy,
rw ← model_with_corners.image at hy,
rcases hy with ⟨z, hz⟩,
simp [local_equiv.trans_source] at hz,
simp [hz.2.symm, hz.1] },
have C : fderiv_within 𝕜 (I.to_fun ∘ i.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(range I.to_fun) (I.to_fun x) =
fderiv_within 𝕜 (id : E → E) (range I.to_fun) (I.to_fun x) :=
fderiv_within_congr_of_mem_nhds_within (I.unique_diff _ (mem_range_self _)) B (by simp [hx]),
rw fderiv_within_id (I.unique_diff _ (mem_range_self _)) at C,
rw C,
refl
end,
coord_change_comp := λi j u x hx, begin
/- The cocycle property is just the fact that the derivative of a composition is the product of
the derivatives. One needs however to check that all the functions one considers are smooth, and
to pay attention to the domains where these functions are defined, making this proof a little
bit cumbersome although there is nothing complicated here. -/
have M : I.to_fun x ∈
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun) :=
⟨by simpa using hx, mem_range_self _⟩,
have U : unique_diff_within_at 𝕜
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x),
{ have : unique_diff_on 𝕜
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun),
{ rw inter_comm,
exact I.unique_diff.inter (I.continuous_inv_fun _ (local_homeomorph.open_source _)) },
exact this _ M },
have A : fderiv_within 𝕜 ((I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
∘ (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun))
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x)
= (fderiv_within 𝕜 (I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (j.1.symm.trans u.1).source ∩ range I.to_fun)
((I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) (I.to_fun x))).comp
(fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x)),
{ apply fderiv_within.comp _ _ _ _ U,
show differentiable_within_at 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x),
{ have A : times_cont_diff_on 𝕜 ⊤
(I.to_fun ∘ (i.1.symm.trans j.1).to_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun) :=
(has_groupoid.compatible (times_cont_diff_groupoid ⊤ I) i.2 j.2).1,
have B : differentiable_on 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun),
{ apply (A.differentiable_on (lattice.le_top)).mono,
have : ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ⊆ (i.1.symm.trans j.1).source :=
inter_subset_left _ _,
exact inter_subset_inter (preimage_mono this) (subset.refl (range I.to_fun)) },
apply B,
simpa [mem_inter_iff, -mem_image, -mem_range, mem_range_self] using hx },
show differentiable_within_at 𝕜 (I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (j.1.symm.trans u.1).source ∩ range I.to_fun)
((I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) (I.to_fun x)),
{ have A : times_cont_diff_on 𝕜 ⊤
(I.to_fun ∘ (j.1.symm.trans u.1).to_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (j.1.symm.trans u.1).source ∩ range I.to_fun) :=
(has_groupoid.compatible (times_cont_diff_groupoid ⊤ I) j.2 u.2).1,
apply A.differentiable_on (lattice.le_top),
rw [local_homeomorph.trans_source] at hx,
simp [mem_inter_iff, -mem_image, -mem_range, mem_range_self],
exact hx.2 },
show (I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
⊆ (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) ⁻¹'
(I.inv_fun ⁻¹' (j.1.symm.trans u.1).source ∩ range I.to_fun),
{ assume y hy,
simp [-mem_range, local_equiv.trans_source] at hy,
rw [local_equiv.left_inv] at hy,
{ simp [-mem_range, mem_range_self, hy, local_equiv.trans_source] },
{ exact hy.1.1.2 } } },
have B : fderiv_within 𝕜 ((I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
∘ (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun))
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x)
= fderiv_within 𝕜 (I.to_fun ∘ u.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x),
{ have E : ∀ y ∈ (I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun),
((I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
∘ (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)) y =
(I.to_fun ∘ u.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) y,
{ assume y hy,
simp only [function.comp_app, model_with_corners_left_inv],
rw [j.1.left_inv],
exact hy.1.1.2 },
exact fderiv_within_congr U E (E _ M) },
have C : fderiv_within 𝕜 (I.to_fun ∘ u.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x) =
fderiv_within 𝕜 (I.to_fun ∘ u.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(range I.to_fun) (I.to_fun x),
{ rw inter_comm,
apply fderiv_within_inter _ (I.unique_diff _ (mem_range_self _)),
apply I.continuous_inv_fun.continuous_at.preimage_mem_nhds
(mem_nhds_sets (local_homeomorph.open_source _) _),
simpa using hx },
have D : fderiv_within 𝕜 (I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (j.1.symm.trans u.1).source ∩ range I.to_fun)
((I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) (I.to_fun x)) =
fderiv_within 𝕜 (I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
(range I.to_fun)
((I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) (I.to_fun x)),
{ rw inter_comm,
apply fderiv_within_inter _ (I.unique_diff _ (mem_range_self _)),
apply I.continuous_inv_fun.continuous_at.preimage_mem_nhds
(mem_nhds_sets (local_homeomorph.open_source _) _),
rw [local_homeomorph.trans_source] at hx,
simp [mem_inter_iff, -mem_image, -mem_range, mem_range_self],
exact hx.2 },
have E : fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x) =
(fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(range I.to_fun)
(I.to_fun x)),
{ rw inter_comm,
apply fderiv_within_inter _ (I.unique_diff _ (mem_range_self _)),
apply I.continuous_inv_fun.continuous_at.preimage_mem_nhds
(mem_nhds_sets (local_homeomorph.open_source _) _),
simpa using hx },
rw [B, C, D, E] at A,
rw A,
assume v,
simp,
unfold_coes,
simp
end }
/-- The tangent bundle to a smooth manifold, as a plain type. -/
def tangent_bundle := (tangent_bundle_core I M).to_topological_fiber_bundle_core.total_space
/-- The projection from the tangent bundle of a smooth manifold to the manifold. As the tangent
bundle is represented internally as a product type, the notation `p.1` also works for the projection
of the point `p`. -/
def tangent_bundle.proj : tangent_bundle I M → M :=
(tangent_bundle_core I M).to_topological_fiber_bundle_core.proj
variable {M}
/-- The tangent space at a point of the manifold `M`. It is just `E`. -/
def tangent_space (x : M) : Type* :=
(tangent_bundle_core I M).to_topological_fiber_bundle_core.fiber x
section tangent_bundle_instances
/- In general, the definition of tangent_bundle and tangent_space are not reducible, so that type
class inference does not pick wrong instances. In this section, we record the right instances for
them, noting in particular that the tangent bundle is a smooth manifold. -/
variable (M)
local attribute [reducible] tangent_bundle
instance : topological_space (tangent_bundle I M) := by apply_instance
instance : manifold (H × E) (tangent_bundle I M) := by apply_instance
instance : smooth_manifold_with_corners I.tangent (tangent_bundle I M) := by apply_instance
local attribute [reducible] tangent_space topological_fiber_bundle_core.fiber
/- When `topological_fiber_bundle_core.fiber` is reducible, then
`topological_fiber_bundle_core.topological_space_fiber` can be applied to prove that any space is
a topological space, with several unknown metavariables. This is a bad instance, that we disable.-/
local attribute [instance, priority 0] topological_fiber_bundle_core.topological_space_fiber
variables {M} (x : M)
instance : topological_module 𝕜 (tangent_space I x) := by apply_instance
instance : topological_space (tangent_space I x) := by apply_instance
instance : add_comm_group (tangent_space I x) := by apply_instance
instance : topological_add_group (tangent_space I x) := by apply_instance
instance : vector_space 𝕜 (tangent_space I x) := by apply_instance
end tangent_bundle_instances
variable (M)
/-- The tangent bundle projection on the basis is a continuous map. -/
lemma tangent_bundle_proj_continuous : continuous (tangent_bundle.proj I M) :=
topological_fiber_bundle_core.continuous_proj _
/-- The tangent bundle projection on the basis is an open map. -/
lemma tangent_bundle_proj_open : is_open_map (tangent_bundle.proj I M) :=
topological_fiber_bundle_core.is_open_map_proj _
/-- In the tangent bundle to the model space, the charts are just the identity-/
@[simp] lemma tangent_bundle_model_space_chart_at (p : tangent_bundle I H) :
(chart_at (H × E) p).to_local_equiv = local_equiv.refl (H × E) :=
begin
have A : ∀ x_fst, fderiv_within 𝕜 (I.to_fun ∘ I.inv_fun) (range I.to_fun) (I.to_fun x_fst)
= continuous_linear_map.id,
{ assume x_fst,
have : fderiv_within 𝕜 (I.to_fun ∘ I.inv_fun) (range I.to_fun) (I.to_fun x_fst)
= fderiv_within 𝕜 id (range I.to_fun) (I.to_fun x_fst),
{ refine fderiv_within_congr (I.unique_diff _ (mem_range_self _)) (λy hy, _) (by simp),
exact model_with_corners_right_inv _ hy },
rwa fderiv_within_id (I.unique_diff _ (mem_range_self _)) at this },
ext x : 1,
show (chart_at (H × E) p).to_fun x = (local_equiv.refl (H × E)).to_fun x,
{ cases x,
simp [chart_at, manifold.chart_at, basic_smooth_bundle_core.chart,
topological_fiber_bundle_core.local_triv, topological_fiber_bundle_core.local_triv',
basic_smooth_bundle_core.to_topological_fiber_bundle_core, tangent_bundle_core],
erw [local_equiv.refl_to_fun, local_equiv.refl_inv_fun, A],
refl },
show ∀ x, ((chart_at (H × E) p).to_local_equiv).inv_fun x = (local_equiv.refl (H × E)).inv_fun x,
{ rintros ⟨x_fst, x_snd⟩,
simp [chart_at, manifold.chart_at, basic_smooth_bundle_core.chart,
topological_fiber_bundle_core.local_triv, topological_fiber_bundle_core.local_triv',
basic_smooth_bundle_core.to_topological_fiber_bundle_core, tangent_bundle_core],
erw [local_equiv.refl_to_fun, local_equiv.refl_inv_fun, A],
refl },
show ((chart_at (H × E) p).to_local_equiv).source = (local_equiv.refl (H × E)).source,
by simp [chart_at, manifold.chart_at, basic_smooth_bundle_core.chart,
topological_fiber_bundle_core.local_triv, topological_fiber_bundle_core.local_triv',
basic_smooth_bundle_core.to_topological_fiber_bundle_core, tangent_bundle_core,
local_equiv.trans_source]
end
variable (H)
/-- In the tangent bundle to the model space, the topology is the product topology, i.e., the bundle
is trivial -/
lemma tangent_bundle_model_space_topology_eq_prod :
tangent_bundle.topological_space I H = prod.topological_space :=
begin
ext o,
let x : tangent_bundle I H := (I.inv_fun (0 : E), (0 : E)),
let e := chart_at (H × E) x,
have e_source : e.source = univ, by { simp [e], refl },
have e_target : e.target = univ, by { simp [e], refl },
let e' := e.to_homeomorph_of_source_eq_univ_target_eq_univ e_source e_target,
split,
{ assume ho,
have := e'.continuous_inv_fun o ho,
simpa [e', tangent_bundle_model_space_chart_at] },
{ assume ho,
have := e'.continuous_to_fun o ho,
simpa [e', tangent_bundle_model_space_chart_at] }
end
end tangent_bundle
|
b817e2654d4053f1e72c46fa2962fa12de6e1392 | b2fe74b11b57d362c13326bc5651244f111fa6f4 | /src/algebra/continued_fractions/convergents_equiv.lean | 48cc3a4a1126b2c222b287ab911879578de07a50 | [
"Apache-2.0"
] | permissive | midfield/mathlib | c4db5fa898b5ac8f2f80ae0d00c95eb6f745f4c7 | 775edc615ecec631d65b6180dbcc7bc26c3abc26 | refs/heads/master | 1,675,330,551,921 | 1,608,304,514,000 | 1,608,304,514,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 20,531 | lean | /-
Copyright (c) 2020 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import algebra.continued_fractions.continuants_recurrence
import algebra.continued_fractions.terminated_stable
import tactic.linarith
/-!
# Equivalence of Recursive and Direct Computations of `gcf` Convergents
## Summary
We show the equivalence of two computations of convergents (recurrence relation (`convergents`) vs.
direct evaluation (`convergents'`)) for `gcf`s on linear ordered fields. We follow the proof from
[hardy2008introduction], Chapter 10. Here's a sketch:
Let `c` be a continued fraction `[h; (a₀, b₀), (a₁, b₁), (a₂, b₂),...]`, visually:
a₀
h + ---------------------------
a₁
b₀ + --------------------
a₂
b₁ + --------------
a₃
b₂ + --------
b₃ + ...
One can compute the convergents of `c` in two ways:
1. Directly evaluating the fraction described by `c` up to a given `n` (`convergents'`)
2. Using the recurrence (`convergents`):
- `A₋₁ = 1, A₀ = h, Aₙ = bₙ₋₁ * Aₙ₋₁ + aₙ₋₁ * Aₙ₋₂`, and
- `B₋₁ = 0, B₀ = 1, Bₙ = bₙ₋₁ * Bₙ₋₁ + aₙ₋₁ * Bₙ₋₂`.
To show the equivalence of the computations in the main theorem of this file
`convergents_eq_convergents'`, we proceed by induction. The case `n = 0` is trivial.
For `n + 1`, we first "squash" the `n + 1`th position of `c` into the `n`th position to obtain
another continued fraction
`c' := [h; (a₀, b₀),..., (aₙ-₁, bₙ-₁), (aₙ, bₙ + aₙ₊₁ / bₙ₊₁), (aₙ₊₁, bₙ₊₁),...]`.
This squashing process is formalised in section `squash`. Note that directly evaluating `c` up to
position `n + 1` is equal to evaluating `c'` up to `n`. This is shown in lemma
`succ_nth_convergent'_eq_squash_gcf_nth_convergent'`.
By the inductive hypothesis, the two computations for the `n`th convergent of `c` coincide.
So all that is left to show is that the recurrence relation for `c` at `n + 1` and and `c'` at
`n` coincide. This can be shown by another induction.
The corresponding lemma in this file is `succ_nth_convergent_eq_squash_gcf_nth_convergent`.
## Main Theorems
- `generalized_continued_fraction.convergents_eq_convergents'` shows the equivalence under a strict
positivity restriction on the sequence.
- `continued_fractions.convergents_eq_convergents'` shows the equivalence for (regular) continued
fractions.
## References
- https://en.wikipedia.org/wiki/Generalized_continued_fraction
- [*Hardy, GH and Wright, EM and Heath-Brown, Roger and Silverman, Joseph*][hardy2008introduction]
## Tags
fractions, recurrence, equivalence
-/
variables {K : Type*} {n : ℕ}
namespace generalized_continued_fraction
open generalized_continued_fraction as gcf
variables {g : gcf K} {s : seq $ gcf.pair K}
section squash
/-!
We will show the equivalence of the computations by induction. To make the induction work, we need
to be able to *squash* the nth and (n + 1)th value of a sequence. This squashing itself and the
lemmas about it are not very interesting. As a reader, you hence might want to skip this section.
-/
section with_division_ring
variable [division_ring K]
/--
Given a sequence of gcf.pairs `s = [(a₀, bₒ), (a₁, b₁), ...]`, `squash_seq s n`
combines `⟨aₙ, bₙ⟩` and `⟨aₙ₊₁, bₙ₊₁⟩` at position `n` to `⟨aₙ, bₙ + aₙ₊₁ / bₙ₊₁⟩`. For example,
`squash_seq s 0 = [(a₀, bₒ + a₁ / b₁), (a₁, b₁),...]`.
If `s.terminated_at (n + 1)`, then `squash_seq s n = s`.
-/
def squash_seq (s : seq $ gcf.pair K) (n : ℕ) : seq (gcf.pair K) :=
match prod.mk (s.nth n) (s.nth (n + 1)) with
| ⟨some gp_n, some gp_succ_n⟩ := seq.nats.zip_with
-- return the squashed value at position `n`; otherwise, do nothing.
(λ n' gp, if n' = n then ⟨gp_n.a, gp_n.b + gp_succ_n.a / gp_succ_n.b⟩ else gp) s
| _ := s
end
/-! We now prove some simple lemmas about the squashed sequence -/
/-- If the sequence already terminated at position `n + 1`, nothing gets squashed. -/
lemma squash_seq_eq_self_of_terminated (terminated_at_succ_n : s.terminated_at (n + 1)) :
squash_seq s n = s :=
begin
change s.nth (n + 1) = none at terminated_at_succ_n,
cases s_nth_eq : (s.nth n);
simp only [*, squash_seq]
end
/-- If the sequence has not terminated before position `n + 1`, the value at `n + 1` gets
squashed into position `n`. -/
lemma squash_seq_nth_of_not_terminated {gp_n gp_succ_n : gcf.pair K}
(s_nth_eq : s.nth n = some gp_n) (s_succ_nth_eq : s.nth (n + 1) = some gp_succ_n) :
(squash_seq s n).nth n = some ⟨gp_n.a, gp_n.b + gp_succ_n.a / gp_succ_n.b⟩ :=
by simp [*, squash_seq, (seq.zip_with_nth_some (seq.nats_nth n) s_nth_eq _)]
/-- The values before the squashed position stay the same. -/
lemma squash_seq_nth_of_lt {m : ℕ} (m_lt_n : m < n) : (squash_seq s n).nth m = s.nth m :=
begin
cases s_succ_nth_eq : s.nth (n + 1),
case option.none { rw (squash_seq_eq_self_of_terminated s_succ_nth_eq) },
case option.some
{ obtain ⟨gp_n, s_nth_eq⟩ : ∃ gp_n, s.nth n = some gp_n, from
s.ge_stable n.le_succ s_succ_nth_eq,
obtain ⟨gp_m, s_mth_eq⟩ : ∃ gp_m, s.nth m = some gp_m, from
s.ge_stable (le_of_lt m_lt_n) s_nth_eq,
simp [*, squash_seq, (seq.zip_with_nth_some (seq.nats_nth m) s_mth_eq _),
(ne_of_lt m_lt_n)] }
end
/-- Squashing at position `n + 1` and taking the tail is the same as squashing the tail of the
sequence at position `n`. -/
lemma squash_seq_succ_n_tail_eq_squash_seq_tail_n :
(squash_seq s (n + 1)).tail = squash_seq s.tail n :=
begin
cases s_succ_succ_nth_eq : s.nth (n + 2) with gp_succ_succ_n,
case option.none
{ have : squash_seq s (n + 1) = s, from squash_seq_eq_self_of_terminated s_succ_succ_nth_eq,
cases s_succ_nth_eq : (s.nth (n + 1));
simp only [squash_seq, seq.nth_tail, s_succ_nth_eq, s_succ_succ_nth_eq] },
case option.some
{ obtain ⟨gp_succ_n, s_succ_nth_eq⟩ : ∃ gp_succ_n, s.nth (n + 1) = some gp_succ_n, from
s.ge_stable (n + 1).le_succ s_succ_succ_nth_eq,
-- apply extensionality with `m` and continue by cases `m = n`.
ext m,
cases decidable.em (m = n) with m_eq_n m_ne_n,
{ have : s.tail.nth n = some gp_succ_n, from (s.nth_tail n).trans s_succ_nth_eq,
simp [*, squash_seq, seq.nth_tail, (seq.zip_with_nth_some (seq.nats_nth n) this),
(seq.zip_with_nth_some (seq.nats_nth (n + 1)) s_succ_nth_eq)] },
{ have : s.tail.nth m = s.nth (m + 1), from s.nth_tail m,
cases s_succ_mth_eq : s.nth (m + 1),
all_goals { have s_tail_mth_eq, from this.trans s_succ_mth_eq },
{ simp only [*, squash_seq, seq.nth_tail, (seq.zip_with_nth_none' s_succ_mth_eq),
(seq.zip_with_nth_none' s_tail_mth_eq)] },
{ simp [*, squash_seq, seq.nth_tail,
(seq.zip_with_nth_some (seq.nats_nth (m + 1)) s_succ_mth_eq),
(seq.zip_with_nth_some (seq.nats_nth m) s_tail_mth_eq)] } } }
end
/-- The auxiliary function `convergents'_aux` returns the same value for a sequence and the
corresponding squashed sequence at the squashed position. -/
lemma succ_succ_nth_convergent'_aux_eq_succ_nth_convergent'_aux_squash_seq :
convergents'_aux s (n + 2) = convergents'_aux (squash_seq s n) (n + 1) :=
begin
cases s_succ_nth_eq : (s.nth $ n + 1) with gp_succ_n,
case option.none
{ rw [(squash_seq_eq_self_of_terminated s_succ_nth_eq),
(convergents'_aux_stable_step_of_terminated s_succ_nth_eq)] },
case option.some
{ induction n with m IH generalizing s gp_succ_n,
case nat.zero
{ obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head, from
s.ge_stable zero_le_one s_succ_nth_eq,
have : (squash_seq s 0).head = some ⟨gp_head.a, gp_head.b + gp_succ_n.a / gp_succ_n.b⟩,
from squash_seq_nth_of_not_terminated s_head_eq s_succ_nth_eq,
simp [*, convergents'_aux, seq.head, seq.nth_tail] },
case nat.succ
{ obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head, from
s.ge_stable (m + 2).zero_le s_succ_nth_eq,
suffices : gp_head.a / (gp_head.b + convergents'_aux s.tail (m + 2))
= convergents'_aux (squash_seq s (m + 1)) (m + 2), by
simpa only [convergents'_aux, s_head_eq],
have : convergents'_aux s.tail (m + 2) = convergents'_aux (squash_seq s.tail m) (m + 1), by
{ have : s.tail.nth (m + 1) = some gp_succ_n, by simpa [seq.nth_tail] using s_succ_nth_eq,
exact (IH _ this) },
have : (squash_seq s (m + 1)).head = some gp_head, from
(squash_seq_nth_of_lt m.succ_pos).trans s_head_eq,
simp only [*, convergents'_aux, squash_seq_succ_n_tail_eq_squash_seq_tail_n] } }
end
/-! Let us now lift the squashing operation to gcfs. -/
/--
Given a gcf `g = [h; (a₀, bₒ), (a₁, b₁), ...]`, we have
- `squash_nth.gcf g 0 = [h + a₀ / b₀); (a₀, bₒ), ...]`,
- `squash_nth.gcf g (n + 1) = ⟨g.h, squash_seq g.s n⟩`
-/
def squash_gcf (g : gcf K) : ℕ → gcf K
| 0 := match g.s.nth 0 with
| none := g
| some gp := ⟨g.h + gp.a / gp.b, g.s⟩
end
| (n + 1) := ⟨g.h, squash_seq g.s n⟩
/-! Again, we derive some simple lemmas that are not really of interest. This time for the
squashed gcf. -/
/-- If the gcf already terminated at position `n`, nothing gets squashed. -/
lemma squash_gcf_eq_self_of_terminated (terminated_at_n : terminated_at g n) :
squash_gcf g n = g :=
begin
cases n,
case nat.zero
{ change g.s.nth 0 = none at terminated_at_n,
simp only [convergents', squash_gcf, convergents'_aux, terminated_at_n] },
case nat.succ
{ cases g, simp [(squash_seq_eq_self_of_terminated terminated_at_n), squash_gcf] }
end
/-- The values before the squashed position stay the same. -/
lemma squash_gcf_nth_of_lt {m : ℕ} (m_lt_n : m < n) :
(squash_gcf g (n + 1)).s.nth m = g.s.nth m :=
by simp only [squash_gcf, (squash_seq_nth_of_lt m_lt_n)]
/-- `convergents'` returns the same value for a gcf and the corresponding squashed gcf at the
squashed position. -/
lemma succ_nth_convergent'_eq_squash_gcf_nth_convergent' :
g.convergents' (n + 1) = (squash_gcf g n).convergents' n :=
begin
cases n,
case nat.zero
{ cases g_s_head_eq : (g.s.nth 0);
simp [g_s_head_eq, squash_gcf, convergents', convergents'_aux, seq.head] },
case nat.succ
{ simp only [succ_succ_nth_convergent'_aux_eq_succ_nth_convergent'_aux_squash_seq,
convergents', squash_gcf] }
end
/-- The auxiliary continuants before the squashed position stay the same. -/
lemma continuants_aux_eq_continuants_aux_squash_gcf_of_le {m : ℕ} :
m ≤ n → continuants_aux g m = (squash_gcf g n).continuants_aux m :=
nat.strong_induction_on m
(begin
clear m,
assume m IH m_le_n,
cases m with m',
{ refl },
{ cases n with n',
{ have : false, from m'.not_succ_le_zero m_le_n, contradiction }, -- 1 ≰ 0
{ cases m' with m'',
{ refl },
{ -- get some inequalities to instantiate the IH for m'' and m'' + 1
have m'_lt_n : m'' + 1 < n' + 1, from m_le_n,
have : m'' + 1 < m'' + 2, by linarith,
have succ_m''th_conts_aux_eq := IH (m'' + 1) this (le_of_lt m'_lt_n),
have : m'' < m'' + 2, by linarith,
have m''th_conts_aux_eq := IH m'' this (le_of_lt $ lt_of_lt_of_le (by linarith) n'.le_succ),
have : (squash_gcf g (n' + 1)).s.nth m'' = g.s.nth m'', from
squash_gcf_nth_of_lt (by linarith),
simp [continuants_aux, succ_m''th_conts_aux_eq, m''th_conts_aux_eq, this] } } }
end)
end with_division_ring
/-- The convergents coincide in the expected way at the squashed position if the partial denominator
at the squashed position is not zero. -/
lemma succ_nth_convergent_eq_squash_gcf_nth_convergent [field K]
(nth_part_denom_ne_zero : ∀ {b : K}, g.partial_denominators.nth n = some b → b ≠ 0) :
g.convergents (n + 1) = (squash_gcf g n).convergents n :=
begin
cases decidable.em (g.terminated_at n) with terminated_at_n not_terminated_at_n,
{ have : squash_gcf g n = g, from squash_gcf_eq_self_of_terminated terminated_at_n,
simp only [this, (convergents_stable_of_terminated n.le_succ terminated_at_n)] },
{ obtain ⟨⟨a, b⟩, s_nth_eq⟩ : ∃ gp_n, g.s.nth n = some gp_n, from
option.ne_none_iff_exists'.mp not_terminated_at_n,
have b_ne_zero : b ≠ 0, from nth_part_denom_ne_zero (part_denom_eq_s_b s_nth_eq),
cases n with n',
case nat.zero
{ suffices : (b * g.h + a) / b = g.h + a / b, by
simpa [squash_gcf, s_nth_eq, convergent_eq_conts_a_div_conts_b,
(continuants_recurrence_aux s_nth_eq zeroth_continuant_aux_eq_one_zero
first_continuant_aux_eq_h_one)],
calc
(b * g.h + a) / b = b * g.h / b + a / b : by ring -- requires `field` rather than `division_ring`
... = g.h + a / b : by rw (mul_div_cancel_left _ b_ne_zero) },
case nat.succ
{ obtain ⟨⟨pa, pb⟩, s_n'th_eq⟩ : ∃ gp_n', g.s.nth n' = some gp_n' :=
g.s.ge_stable n'.le_succ s_nth_eq,
-- Notations
let g' := squash_gcf g (n' + 1),
set pred_conts := g.continuants_aux (n' + 1) with succ_n'th_conts_aux_eq,
set ppred_conts := g.continuants_aux n' with n'th_conts_aux_eq,
let pA := pred_conts.a, let pB := pred_conts.b,
let ppA := ppred_conts.a, let ppB := ppred_conts.b,
set pred_conts' := g'.continuants_aux (n' + 1) with succ_n'th_conts_aux_eq',
set ppred_conts' := g'.continuants_aux n' with n'th_conts_aux_eq',
let pA' := pred_conts'.a, let pB' := pred_conts'.b, let ppA' := ppred_conts'.a,
let ppB' := ppred_conts'.b,
-- first compute the convergent of the squashed gcf
have : g'.convergents (n' + 1)
= ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB'),
{ have : g'.s.nth n' = some ⟨pa, pb + a / b⟩ :=
squash_seq_nth_of_not_terminated s_n'th_eq s_nth_eq,
rw [convergent_eq_conts_a_div_conts_b,
continuants_recurrence_aux this n'th_conts_aux_eq'.symm succ_n'th_conts_aux_eq'.symm], },
rw this,
-- then compute the convergent of the original gcf by recursively unfolding the continuants
-- computation twice
have : g.convergents (n' + 2)
= (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB),
{ -- use the recurrence once
have : g.continuants_aux (n' + 2) = ⟨pb * pA + pa * ppA, pb * pB + pa * ppB⟩ :=
continuants_aux_recurrence s_n'th_eq n'th_conts_aux_eq.symm succ_n'th_conts_aux_eq.symm,
-- and a second time
rw [convergent_eq_conts_a_div_conts_b,
continuants_recurrence_aux s_nth_eq succ_n'th_conts_aux_eq.symm this] },
rw this,
suffices : ((pb + a / b) * pA + pa * ppA) / ((pb + a / b) * pB + pa * ppB)
= (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB),
{ obtain ⟨eq1, eq2, eq3, eq4⟩ : pA' = pA ∧ pB' = pB ∧ ppA' = ppA ∧ ppB' = ppB,
{ simp [*, (continuants_aux_eq_continuants_aux_squash_gcf_of_le $ le_refl $ n' + 1).symm,
(continuants_aux_eq_continuants_aux_squash_gcf_of_le n'.le_succ).symm] },
symmetry,
simpa only [eq1, eq2, eq3, eq4, mul_div_cancel _ b_ne_zero] },
field_simp [b_ne_zero],
congr' 1; ring } }
end
end squash
/-- Shows that the recurrence relation (`convergents`) and direct evaluation (`convergents'`) of the
gcf coincide at position `n` if the sequence of fractions contains strictly positive values only.
Requiring positivity of all values is just one possible condition to obtain this result.
For example, the dual - sequences with strictly negative values only - would also work.
In practice, one most commonly deals with (regular) continued fractions, which satisfy the
positivity criterion required here. The analogous result for them
(see `continued_fractions.convergents_eq_convergents`) hence follows directly from this theorem.
-/
theorem convergents_eq_convergents' [linear_ordered_field K]
(s_pos : ∀ {gp : gcf.pair K} {m : ℕ}, m < n → g.s.nth m = some gp → 0 < gp.a ∧ 0 < gp.b) :
g.convergents n = g.convergents' n :=
begin
induction n with n IH generalizing g,
case nat.zero { simp },
case nat.succ
{ let g' := squash_gcf g n, -- first replace the rhs with the squashed computation
suffices : g.convergents (n + 1) = g'.convergents' n, by
rwa [succ_nth_convergent'_eq_squash_gcf_nth_convergent'],
cases decidable.em (terminated_at g n) with terminated_at_n not_terminated_at_n,
{ have g'_eq_g : g' = g, from squash_gcf_eq_self_of_terminated terminated_at_n,
have : ∀ ⦃gp m⦄, m < n → g.s.nth m = some gp → 0 < gp.a ∧ 0 < gp.b, by
{ assume _ _ m_lt_n s_mth_eq, exact (s_pos (nat.lt.step m_lt_n) s_mth_eq) },
rw [(convergents_stable_of_terminated n.le_succ terminated_at_n), g'_eq_g, (IH this)] },
{ suffices : g.convergents (n + 1) = g'.convergents n, by -- invoke the IH for the squashed gcf
{ have : ∀ ⦃gp' m⦄, m < n → g'.s.nth m = some gp' → 0 < gp'.a ∧ 0 < gp'.b, by
{ assume gp' m m_lt_n s_mth_eq',
-- case distinction on m + 1 = n or m + 1 < n
cases m_lt_n with n succ_m_lt_n,
{ -- the difficult case at the squashed position: we first obtain the values from
-- the sequence
obtain ⟨gp_succ_m, s_succ_mth_eq⟩ : ∃ gp_succ_m, g.s.nth (m + 1) = some gp_succ_m, from
option.ne_none_iff_exists'.mp not_terminated_at_n,
obtain ⟨gp_m, mth_s_eq⟩ : ∃ gp_m, g.s.nth m = some gp_m, from
g.s.ge_stable m.le_succ s_succ_mth_eq,
-- we then plug them into the recurrence
suffices : 0 < gp_m.a ∧ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b, by {
have : g'.s.nth m = some ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩, from
squash_seq_nth_of_not_terminated mth_s_eq s_succ_mth_eq,
have : gp' = ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩, by cc,
rwa this },
split,
{ exact (s_pos (nat.lt.step m_lt_n) mth_s_eq).left },
{ have : 0 < gp_m.b, from (s_pos (nat.lt.step m_lt_n) mth_s_eq).right,
have : 0 < gp_succ_m.a / gp_succ_m.b, by
{ have : 0 < gp_succ_m.a ∧ 0 < gp_succ_m.b, from
s_pos (lt_add_one $ m + 1) s_succ_mth_eq,
exact (div_pos this.left this.right) },
linarith } },
{ -- the easy case: before the squashed position, nothing changes
have : g.s.nth m = some gp', by {
have : g'.s.nth m = g.s.nth m, from squash_gcf_nth_of_lt succ_m_lt_n,
rwa this at s_mth_eq' },
exact s_pos (nat.lt.step $ nat.lt.step succ_m_lt_n) this } },
rwa [(IH this).symm] },
-- now the result follows from the fact that the convergents coincide at the squashed position
-- as established in `succ_nth_convergent_eq_squash_gcf_nth_convergent`.
have : ∀ ⦃b⦄, g.partial_denominators.nth n = some b → b ≠ 0, by
{ assume b nth_part_denom_eq,
obtain ⟨gp, s_nth_eq, ⟨refl⟩⟩ : ∃ gp, g.s.nth n = some gp ∧ gp.b = b, from
exists_s_b_of_part_denom nth_part_denom_eq,
exact (ne_of_lt (s_pos (lt_add_one n) s_nth_eq).right).symm },
exact succ_nth_convergent_eq_squash_gcf_nth_convergent this } }
end
end generalized_continued_fraction
namespace continued_fraction
open generalized_continued_fraction as gcf
open simple_continued_fraction as scf
open continued_fraction as cf
/-- Shows that the recurrence relation (`convergents`) and direct evaluation (`convergents'`) of a
(regular) continued fraction coincide. -/
theorem convergents_eq_convergents' [linear_ordered_field K] {c : cf K} :
(↑c : gcf K).convergents = (↑c : gcf K).convergents' :=
begin
ext n,
apply gcf.convergents_eq_convergents',
assume gp m m_lt_n s_nth_eq,
split,
{ have : gp.a = 1, from (c : scf K).property m gp.a (gcf.part_num_eq_s_a s_nth_eq),
simp only [zero_lt_one, this] },
{ exact (c.property m gp.b $ gcf.part_denom_eq_s_b s_nth_eq) }
end
end continued_fraction
|
02f052c43f8b89374b2724825c891433513ef219 | 2bafba05c98c1107866b39609d15e849a4ca2bb8 | /src/week_7/Part_B_universal_property.lean | cd6f68ddf493d85ebcbdedb6b02c865bb8777998 | [
"Apache-2.0"
] | permissive | ImperialCollegeLondon/formalising-mathematics | b54c83c94b5c315024ff09997fcd6b303892a749 | 7cf1d51c27e2038d2804561d63c74711924044a1 | refs/heads/master | 1,651,267,046,302 | 1,638,888,459,000 | 1,638,888,459,000 | 331,592,375 | 284 | 24 | Apache-2.0 | 1,669,593,705,000 | 1,611,224,849,000 | Lean | UTF-8 | Lean | false | false | 5,213 | lean | import tactic
/-
# Further analysis of the universal property of quotients.
Let `X` be a type with an equivalence relation on it.
We say that a pair `Q` and `p : X → Q` is _universal_
if `p` is constant on equivalence classes, and furthermore
that `p` is "initial" for this property, which means that
for all types `T` and for all functions `f : X → T` which
are constant on equivalence classes, there's a unique `g : Q → T`
such that `f = g ∘ p`. Let's formalise this universal property in Lean.
-/
def is_universal {X : Type} [setoid X] (Q : Type) (p : X → Q) :=
(∀ x y, x ≈ y → p x = p y) ∧
∀ (T : Type) (f : X → T) (h : ∀ x y : X, x ≈ y → f x = f y),
∃ (g : Q → T), f = g ∘ p ∧ ∀ k : Q → T, f = k ∘ p → k = g
variables {X : Type} [setoid X] {Q : Type} {p : X → Q}
/-
`is_universal` is a definition, so we need to make a little API for it.
Let's start by giving us a way to get to that function `g` whose
existence is claimed by `is_universal`.
If `hu` is a proof that `(Q, p)` is universal, then given
`f : X → T` and a proof `h` that `f` is constant on equivalence classes,
let's define `g_univ hu h` to be the function `g : Q → T` which makes
the diagram commute. To define this we have to go from an "exists `g`"
statement in `is_universal` to an actual function `g`. We do this with
the `classical.some : (∃ (a : X), p a) → X` function. Note that this function
is noncomputable, but this doesn't matter because we are proving theorems.
-/
noncomputable def g_univ (hu : is_universal Q p)
{T : Type} {f : X → T} (h : ∀ x y : X, x ≈ y → f x = f y) : Q → T :=
classical.some (hu.2 T f h)
/-
Now `g_univ` is also a definition, so we need to make an API for this too!
The proof that `g := g_univ hu h : Q → T` satisfies `f = g ∘ p` needs
a convenient name -- let's call it called `g_univ_spec hu h`
-/
lemma g_univ_spec (hu : is_universal Q p)
{T : Type} {f : X → T} (h : ∀ x y : X, x ≈ y → f x = f y) :
f = (g_univ hu h) ∘ p :=
(classical.some_spec (hu.2 T f h)).1
/-
And here's a variant which says that the functions take the same
values everywhere. This is sometimes more convenient. I prove it
by applying `congr_fun` to the previous proof.
-/
lemma g_univ_spec' (hu : is_universal Q p)
{T : Type} {f : X → T} (h : ∀ x y : X, x ≈ y → f x = f y) (x : X) :
f x = (g_univ hu h) (p x) :=
congr_fun (g_univ_spec hu h) x
/-
The proof of uniqueness of `g`, or more precisely that if `k : Q → T`
satisfies `f = k ∘ p` then `k = g`, also needs a convenient name --
let's call it `g_univ_unique hu h`.
-/
lemma g_univ_unique (hu : is_universal Q p)
{T : Type} {f : X → T} (h : ∀ x y : X, x ≈ y → f x = f y) :
∀ (k : Q → T), f = k ∘ p → k = g_univ hu h :=
(classical.some_spec (hu.2 T f h)).2
/-
Let's make a variant where the conclusion is that `k q = g q` for all `q`,
other than just saying `k = g`. Again we just apply `congr_fun` to the
previous proof.
-/
lemma g_univ_unique' (hu : is_universal Q p)
{T : Type} {f : X → T} (h : ∀ x y : X, x ≈ y → f x = f y) (k : Q → T)
(hk : f = k ∘ p) (q : Q) : k q = g_univ hu h q :=
congr_fun (g_univ_unique hu h k hk) q
/-
Note that if `h : is_universal Q p` then `h` has type `P ∧ Q`
so `h.1` is a proof of `∀ x y, x ≈ y → p x = p y`.
Example: if `(Q, p)` is universal, then `p` is constant on equivalence classes.
-/
example (X : Type) [s : setoid X] (Q : Type) (p : X → Q) (h : is_universal Q p)
(x y : X) (hxy : x ≈ y) : p x = p y :=
h.1 x y hxy
/-
Now let's go through the standard proof that universal objects
are unique up to isomorphism.
-/
-- Here's how to use `g_univ` to define functions between universal objects.
noncomputable example {X : Type} [s : setoid X] {Q1 Q2 : Type}
{p1 : X → Q1} {p2 : X → Q2}
(h1 : is_universal Q1 p1) (h2 : is_universal Q2 p2) :
Q1 → Q2 :=
g_univ h1 h2.1
-- Applying the universal property to `p : X → Q` gives us the
-- identity function `id : Q → Q`
lemma useful {X : Type} [s : setoid X] {Q : Type}
{p : X → Q} (h1 : is_universal Q p) :
g_univ h1 h1.1 = id :=
begin
sorry
end
-- A variant of the previous lemma where we say `g q = q` rather than `g = id`
lemma useful2 {X : Type} [s : setoid X] {Q : Type}
{p : X → Q} (h1 : is_universal Q p) (q : Q) :
g_univ h1 h1.1 q = q :=
begin
rw useful,
refl
end
-- This is tricky. Ask if you need help.
noncomputable def univ_equiv {X : Type} [s : setoid X] {Q1 Q2 : Type}
{p1 : X → Q1} {p2 : X → Q2}
(h1 : is_universal Q1 p1) (h2 : is_universal Q2 p2) :
Q1 ≃ Q2 :=
{ to_fun := g_univ h1 h2.1,
inv_fun := g_univ h2 h1.1,
left_inv := begin
sorry
end,
right_inv := begin
-- same proof, mutatis mutandis
sorry
end }
-- Lean's builtin quotients are universal
theorem quotient_is_universal {X : Type} [s : setoid X] :
is_universal (quotient s) quotient.mk :=
begin
sorry
end
-- so any universal object is isomorphic to the quotient object.
noncomputable def universal_equiv_quotient (X : Type) [s : setoid X]
(Q : Type) (p : X → Q) (hu : is_universal Q p) :
Q ≃ (quotient s) :=
univ_equiv hu quotient_is_universal
|
cbd1745593fb6af2e6542f9d9a1701fc5b46ff91 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/tactic/converter/old_conv.lean | 314da820a72b2f1ced51d847052505343af99d12 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,287 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
Converter monad for building simplifiers.
-/
import control.basic
open tactic
meta structure old_conv_result (α : Type) :=
(val : α) (rhs : expr) (proof : option expr)
meta def old_conv (α : Type) : Type :=
name → expr → tactic (old_conv_result α)
namespace old_conv
meta def lhs : old_conv expr :=
λ r e, return ⟨e, e, none⟩
meta def change (new_p : pexpr) : old_conv unit :=
λ r e, do
e_type ← infer_type e,
new_e ← to_expr ``(%%new_p : %%e_type),
unify e new_e,
return ⟨(), new_e, none⟩
protected meta def pure {α : Type} : α → old_conv α :=
λ a r e, return ⟨a, e, none⟩
private meta def join_proofs (r : name) (o₁ o₂ : option expr) : tactic (option expr) :=
match o₁, o₂ with
| none, _ := return o₂
| _, none := return o₁
| some p₁, some p₂ := do
env ← get_env,
match env.trans_for r with
| some trans := do pr ← mk_app trans [p₁, p₂], return $ some pr
| none := fail format!"converter failed, relation '{r}' is not transitive"
end
end
protected meta def seq {α β : Type} (c₁ : old_conv (α → β)) (c₂ : old_conv α) : old_conv β :=
λ r e, do
⟨fn, e₁, pr₁⟩ ← c₁ r e,
⟨a, e₂, pr₂⟩ ← c₂ r e₁,
pr ← join_proofs r pr₁ pr₂,
return ⟨fn a, e₂, pr⟩
protected meta def fail {α β : Type} [has_to_format β] (msg : β) : old_conv α :=
λ r e, tactic.fail msg
protected meta def failed {α : Type} : old_conv α :=
λ r e, tactic.failed
protected meta def orelse {α : Type} (c₁ : old_conv α) (c₂ : old_conv α) : old_conv α :=
λ r e, c₁ r e <|> c₂ r e
protected meta def map {α β : Type} (f : α → β) (c : old_conv α) : old_conv β :=
λ r e, do
⟨a, e₁, pr⟩ ← c r e,
return ⟨f a, e₁, pr⟩
protected meta def bind {α β : Type} (c₁ : old_conv α) (c₂ : α → old_conv β) : old_conv β :=
λ r e,
has_bind.bind (c₁ r e) (λ⟨a, e₁, pr₁⟩,
has_bind.bind (c₂ a r e₁) (λ⟨b, e₂, pr₂⟩,
has_bind.bind (join_proofs r pr₁ pr₂) (λpr, return ⟨b, e₂, pr⟩)))
/- do -- wrong bind instance something with `name`?
⟨a, e₁, pr₁⟩ ← c₁ r e,
⟨b, e₂, pr₂⟩ ← c₂ a r e₁,
pr ← join_proofs r pr₁ pr₂,
return ⟨b, e₂, pr⟩
-/
meta instance : monad old_conv :=
{ map := @old_conv.map,
pure := @old_conv.pure,
bind := @old_conv.bind }
meta instance : alternative old_conv :=
{ failure := @old_conv.failed,
orelse := @old_conv.orelse,
..old_conv.monad }
meta def whnf (md : transparency := reducible) : old_conv unit :=
λ r e, do n ← tactic.whnf e md, return ⟨(), n, none⟩
meta def dsimp : old_conv unit :=
λ r e, do s ← simp_lemmas.mk_default, n ← s.dsimplify [] e, return ⟨(), n, none⟩
meta def trace {α : Type} [has_to_tactic_format α] (a : α) : old_conv unit :=
λ r e, tactic.trace a >> return ⟨(), e, none⟩
meta def trace_lhs : old_conv unit :=
lhs >>= trace
meta def apply_lemmas_core (s : simp_lemmas) (prove : tactic unit) : old_conv unit :=
λ r e, do
(new_e, pr) ← s.rewrite e prove r,
return ⟨(), new_e, some pr⟩
meta def apply_lemmas (s : simp_lemmas) : old_conv unit :=
apply_lemmas_core s failed
/- adapter for using iff-lemmas as eq-lemmas -/
meta def apply_propext_lemmas_core (s : simp_lemmas) (prove : tactic unit) : old_conv unit :=
λ r e, do
guard (r = `eq),
(new_e, pr) ← s.rewrite e prove `iff,
new_pr ← mk_app `propext [pr],
return ⟨(), new_e, some new_pr⟩
meta def apply_propext_lemmas (s : simp_lemmas) : old_conv unit :=
apply_propext_lemmas_core s failed
private meta def mk_refl_proof (r : name) (e : expr) : tactic expr :=
do env ← get_env,
match (environment.refl_for env r) with
| (some refl) := do pr ← mk_app refl [e], return pr
| none := fail format!"converter failed, relation '{r}' is not reflexive"
end
meta def to_tactic (c : old_conv unit) : name → expr → tactic (expr × expr) :=
λ r e, do
⟨u, e₁, o⟩ ← c r e,
match o with
| none := do p ← mk_refl_proof r e, return (e₁, p)
| some p := return (e₁, p)
end
meta def lift_tactic {α : Type} (t : tactic α) : old_conv α :=
λ r e, do a ← t, return ⟨a, e, none⟩
meta def apply_simp_set (attr_name : name) : old_conv unit :=
lift_tactic (get_user_simp_lemmas attr_name) >>= apply_lemmas
meta def apply_propext_simp_set (attr_name : name) : old_conv unit :=
lift_tactic (get_user_simp_lemmas attr_name) >>= apply_propext_lemmas
meta def skip : old_conv unit :=
return ()
meta def repeat : old_conv unit → old_conv unit
| c r lhs :=
(do
⟨_, rhs₁, pr₁⟩ ← c r lhs,
guard (¬ lhs =ₐ rhs₁),
⟨_, rhs₂, pr₂⟩ ← repeat c r rhs₁,
pr ← join_proofs r pr₁ pr₂,
return ⟨(), rhs₂, pr⟩)
<|> return ⟨(), lhs, none⟩
meta def first {α : Type} : list (old_conv α) → old_conv α
| [] := old_conv.failed
| (c::cs) := c <|> first cs
meta def match_pattern (p : pattern) : old_conv unit :=
λ r e, tactic.match_pattern p e >> return ⟨(), e, none⟩
meta def mk_match_expr (p : pexpr) : tactic (old_conv unit) :=
do new_p ← pexpr_to_pattern p,
return (λ r e, tactic.match_pattern new_p e >> return ⟨(), e, none⟩)
meta def match_expr (p : pexpr) : old_conv unit :=
λ r e, do
new_p ← pexpr_to_pattern p,
tactic.match_pattern new_p e >> return ⟨(), e, none⟩
meta def funext (c : old_conv unit) : old_conv unit :=
λ r lhs, do
guard (r = `eq),
(expr.lam n bi d b) ← return lhs,
let aux_type := expr.pi n bi d (expr.const `true []),
(result, _) ← solve_aux aux_type $ do {
x ← intro1,
c_result ← c r (b.instantiate_var x),
let rhs := expr.lam n bi d (c_result.rhs.abstract x),
match c_result.proof : _ → tactic (old_conv_result unit) with
| some pr := do
let aux_pr := expr.lam n bi d (pr.abstract x),
new_pr ← mk_app `funext [lhs, rhs, aux_pr],
return ⟨(), rhs, some new_pr⟩
| none := return ⟨(), rhs, none⟩
end },
return result
meta def congr_core (c_f c_a : old_conv unit) : old_conv unit :=
λ r lhs, do
guard (r = `eq),
(expr.app f a) ← return lhs,
f_type ← infer_type f >>= tactic.whnf,
guard (f_type.is_arrow),
⟨(), new_f, of⟩ ← mtry c_f r f,
⟨(), new_a, oa⟩ ← mtry c_a r a,
rhs ← return $ new_f new_a,
match of, oa with
| none, none :=
return ⟨(), rhs, none⟩
| none, some pr_a := do
pr ← mk_app `congr_arg [a, new_a, f, pr_a],
return ⟨(), new_f new_a, some pr⟩
| some pr_f, none := do
pr ← mk_app `congr_fun [f, new_f, pr_f, a],
return ⟨(), rhs, some pr⟩
| some pr_f, some pr_a := do
pr ← mk_app `congr [f, new_f, a, new_a, pr_f, pr_a],
return ⟨(), rhs, some pr⟩
end
meta def congr (c : old_conv unit) : old_conv unit :=
congr_core c c
meta def bottom_up (c : old_conv unit) : old_conv unit :=
λ r e, do
s ← simp_lemmas.mk_default,
(a, new_e, pr) ←
ext_simplify_core () {} s
(λ u, return u)
(λ a s r p e, failed)
(λ a s r p e, do ⟨u, new_e, pr⟩ ← c r e, return ((), new_e, pr, tt))
r e,
return ⟨(), new_e, some pr⟩
meta def top_down (c : old_conv unit) : old_conv unit :=
λ r e, do
s ← simp_lemmas.mk_default,
(a, new_e, pr) ←
ext_simplify_core () {} s
(λ u, return u)
(λ a s r p e, do ⟨u, new_e, pr⟩ ← c r e, return ((), new_e, pr, tt))
(λ a s r p e, failed)
r e,
return ⟨(), new_e, some pr⟩
meta def find (c : old_conv unit) : old_conv unit :=
λ r e, do
s ← simp_lemmas.mk_default,
(a, new_e, pr) ←
ext_simplify_core () {} s
(λ u, return u)
(λ a s r p e,
(do ⟨u, new_e, pr⟩ ← c r e, return ((), new_e, pr, ff))
<|>
return ((), e, none, tt))
(λ a s r p e, failed)
r e,
return ⟨(), new_e, some pr⟩
meta def find_pattern (pat : pattern) (c : old_conv unit) : old_conv unit :=
λ r e, do
s ← simp_lemmas.mk_default,
(a, new_e, pr) ←
ext_simplify_core () {} s
(λ u, return u)
(λ a s r p e, do
matched ← (tactic.match_pattern pat e >> return tt) <|> return ff,
if matched
then do ⟨u, new_e, pr⟩ ← c r e, return ((), new_e, pr, ff)
else return ((), e, none, tt))
(λ a s r p e, failed)
r e,
return ⟨(), new_e, some pr⟩
meta def findp : pexpr → old_conv unit → old_conv unit :=
λ p c r e, do
pat ← pexpr_to_pattern p,
find_pattern pat c r e
meta def conversion (c : old_conv unit) : tactic unit :=
do (r, lhs, rhs) ←
(target_lhs_rhs <|> fail "conversion failed, target is not of the form 'lhs R rhs'"),
(new_lhs, pr) ← to_tactic c r lhs,
(unify new_lhs rhs <|>
do new_lhs_fmt ← pp new_lhs,
rhs_fmt ← pp rhs,
fail (to_fmt "conversion failed, expected" ++
rhs_fmt.indent 4 ++ format.line ++ "provided" ++
new_lhs_fmt.indent 4)),
exact pr
end old_conv
|
cd21cd47ef873616a68dc37b9232a248becf51e9 | 1890046a4987fbd27f3f50dbac83f3ce095556d5 | /01_Equality/02_type_judgments.lean | a4de941a57455789889e5580ca14c31eb741ff5d | [] | no_license | kbhuynh/cs-dm | 9f335727d1779f7c3d9e8221a52b4c9c106659ba | 4041bd73618a49ef6870a1a80764e8947e60e768 | refs/heads/master | 1,585,353,017,958 | 1,536,055,215,000 | 1,536,055,215,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,662 | lean | /- * Type judgments * -/
/-
Recall the inference rule for Leibniz equality.
T: Type, t : T
-------------- (eq_refl)
pf: t = t
Above the line in this inference rule, we meet a
new kind of judgment here: a type judgment. If X
is some type (such as string, bool, or nat), and
x is a value of that type, X, we can denote this
fact by writing x : X. We read this as "x is of
type X."
The Lean tool that you're using here is based on a
foundational theory called type theory. In type
theory, every object (value) and every expression
has a type. Every parameter, such as an argument
to a function, has a type, as does the value that
a function returns. Every well formed expression
has a unique type.
In Lean you can check the type of an expression
by using the #check command.
-/
#check 0
#check "Hi!"
#check tt
/-
Note that ℕ is math shorthand for the type of
natural numbers, i.e., non-negative integers
(thus zero on up). Hover your mouse over the
#check commands to see what are the types of 0,
"Hi!", and tt in Lean.
-/
/-
Now here's an amazing idea. In Lean, types are
values, too! It thus follows that a type must
have a type. So what is the type of a type? Well,
let's check a few!
-/
#check nat
#check bool
#check string
/-
Partial answer: The type of any ordinary data
type is simply "Type".
Now the curious and insightful student will ask,
"Well, then, what about Type, itself? Is it a value?
What is its type?"
-/
#check Type
#check Type 1
#check Type 2
-- etc!
/-
So, if T is some data type, then we'd write the
type judgment, "T : Type". And if T is a type,
and t a value of type, T, then we'd write t : T.
-/
/-
With all that out of the way, we can once again
write and now more fully understand the inference
rule for equality that we really want.
T: Type, t : T
-------------- (eq-refl)
pf: t = t
Those are now type judgments above the line. You can
understand this inference rule as saying this: "if you
give me a T that is a type (e.g., bool, nat, string),
and if you also give me a value, t, of type, T, (e.g.,
0 or true), then I will give you back a proof that
t = t. This single inference rule thus defines a very
sensible notion of equality for all values of all types
that exist or might ever be defined.
So now, rather than a separate axiom for 0 = 0,
another one for 1 = 1, another for true = true, and
yet another for Fido = Fido, so forth, we now have
a single inference rule that gives them all as
special cases.
You can think of the "inputs" above the line as parameters. That is how we generalize from a single
case to an infinity of cases.
Indeed, you can now start to think of eq_refl in
two different ways: as a logical inference rule,
and as a kind of program! This program takes two
arguments. The first is a type and the second is
a value of the type given as the first argument.
The program then returns a proof that the second
argument is equal to itself.
We are given this inference rule as something
akin to an axiom, in the sense that it does not
require proofs of other propositions as arguments.
The only "proofs" it requires as inputs are proofs
that T is a type and t is a value of that type.
That is, its inputs are not proofs of proposition,
but rather are type judgments.
EXERCISE: Take the view that eq_refl is a program
that takes two parameters as discussed here, and
write an expression that reduces to ("returns") a
proof of the proposition that the natural number,
0, is equal to itself.
EXERCISE: Give comparable expressions that return
proofs of equality-with-self for the Boolean value,
tt, and for the string value, "Hello Lean".
-/
|
a956b7ee71886f6fd4f951eda020d6ec01cdd8a4 | 592ee40978ac7604005a4e0d35bbc4b467389241 | /Library/generated/mathscheme-lean/RightCancellativeSemigroup.lean | b4632c96467d3d47fba67b7532e87313cfab57a5 | [] | no_license | ysharoda/Deriving-Definitions | 3e149e6641fae440badd35ac110a0bd705a49ad2 | dfecb27572022de3d4aa702cae8db19957523a59 | refs/heads/master | 1,679,127,857,700 | 1,615,939,007,000 | 1,615,939,007,000 | 229,785,731 | 4 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,023 | lean | import init.data.nat.basic
import init.data.fin.basic
import data.vector
import .Prelude
open Staged
open nat
open fin
open vector
section RightCancellativeSemigroup
structure RightCancellativeSemigroup (A : Type) : Type :=
(op : (A → (A → A)))
(associative_op : (∀ {x y z : A} , (op (op x y) z) = (op x (op y z))))
(rightCancellative : (∀ {x y z : A} , ((op x z) = (op y z) → x = y)))
open RightCancellativeSemigroup
structure Sig (AS : Type) : Type :=
(opS : (AS → (AS → AS)))
structure Product (A : Type) : Type :=
(opP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(associative_opP : (∀ {xP yP zP : (Prod A A)} , (opP (opP xP yP) zP) = (opP xP (opP yP zP))))
(rightCancellativeP : (∀ {xP yP zP : (Prod A A)} , ((opP xP zP) = (opP yP zP) → xP = yP)))
structure Hom {A1 : Type} {A2 : Type} (Ri1 : (RightCancellativeSemigroup A1)) (Ri2 : (RightCancellativeSemigroup A2)) : Type :=
(hom : (A1 → A2))
(pres_op : (∀ {x1 x2 : A1} , (hom ((op Ri1) x1 x2)) = ((op Ri2) (hom x1) (hom x2))))
structure RelInterp {A1 : Type} {A2 : Type} (Ri1 : (RightCancellativeSemigroup A1)) (Ri2 : (RightCancellativeSemigroup A2)) : Type 1 :=
(interp : (A1 → (A2 → Type)))
(interp_op : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((op Ri1) x1 x2) ((op Ri2) y1 y2))))))
inductive RightCancellativeSemigroupTerm : Type
| opL : (RightCancellativeSemigroupTerm → (RightCancellativeSemigroupTerm → RightCancellativeSemigroupTerm))
open RightCancellativeSemigroupTerm
inductive ClRightCancellativeSemigroupTerm (A : Type) : Type
| sing : (A → ClRightCancellativeSemigroupTerm)
| opCl : (ClRightCancellativeSemigroupTerm → (ClRightCancellativeSemigroupTerm → ClRightCancellativeSemigroupTerm))
open ClRightCancellativeSemigroupTerm
inductive OpRightCancellativeSemigroupTerm (n : ℕ) : Type
| v : ((fin n) → OpRightCancellativeSemigroupTerm)
| opOL : (OpRightCancellativeSemigroupTerm → (OpRightCancellativeSemigroupTerm → OpRightCancellativeSemigroupTerm))
open OpRightCancellativeSemigroupTerm
inductive OpRightCancellativeSemigroupTerm2 (n : ℕ) (A : Type) : Type
| v2 : ((fin n) → OpRightCancellativeSemigroupTerm2)
| sing2 : (A → OpRightCancellativeSemigroupTerm2)
| opOL2 : (OpRightCancellativeSemigroupTerm2 → (OpRightCancellativeSemigroupTerm2 → OpRightCancellativeSemigroupTerm2))
open OpRightCancellativeSemigroupTerm2
def simplifyCl {A : Type} : ((ClRightCancellativeSemigroupTerm A) → (ClRightCancellativeSemigroupTerm A))
| (opCl x1 x2) := (opCl (simplifyCl x1) (simplifyCl x2))
| (sing x1) := (sing x1)
def simplifyOpB {n : ℕ} : ((OpRightCancellativeSemigroupTerm n) → (OpRightCancellativeSemigroupTerm n))
| (opOL x1 x2) := (opOL (simplifyOpB x1) (simplifyOpB x2))
| (v x1) := (v x1)
def simplifyOp {n : ℕ} {A : Type} : ((OpRightCancellativeSemigroupTerm2 n A) → (OpRightCancellativeSemigroupTerm2 n A))
| (opOL2 x1 x2) := (opOL2 (simplifyOp x1) (simplifyOp x2))
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((RightCancellativeSemigroup A) → (RightCancellativeSemigroupTerm → A))
| Ri (opL x1 x2) := ((op Ri) (evalB Ri x1) (evalB Ri x2))
def evalCl {A : Type} : ((RightCancellativeSemigroup A) → ((ClRightCancellativeSemigroupTerm A) → A))
| Ri (sing x1) := x1
| Ri (opCl x1 x2) := ((op Ri) (evalCl Ri x1) (evalCl Ri x2))
def evalOpB {A : Type} {n : ℕ} : ((RightCancellativeSemigroup A) → ((vector A n) → ((OpRightCancellativeSemigroupTerm n) → A)))
| Ri vars (v x1) := (nth vars x1)
| Ri vars (opOL x1 x2) := ((op Ri) (evalOpB Ri vars x1) (evalOpB Ri vars x2))
def evalOp {A : Type} {n : ℕ} : ((RightCancellativeSemigroup A) → ((vector A n) → ((OpRightCancellativeSemigroupTerm2 n A) → A)))
| Ri vars (v2 x1) := (nth vars x1)
| Ri vars (sing2 x1) := x1
| Ri vars (opOL2 x1 x2) := ((op Ri) (evalOp Ri vars x1) (evalOp Ri vars x2))
def inductionB {P : (RightCancellativeSemigroupTerm → Type)} : ((∀ (x1 x2 : RightCancellativeSemigroupTerm) , ((P x1) → ((P x2) → (P (opL x1 x2))))) → (∀ (x : RightCancellativeSemigroupTerm) , (P x)))
| popl (opL x1 x2) := (popl _ _ (inductionB popl x1) (inductionB popl x2))
def inductionCl {A : Type} {P : ((ClRightCancellativeSemigroupTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 x2 : (ClRightCancellativeSemigroupTerm A)) , ((P x1) → ((P x2) → (P (opCl x1 x2))))) → (∀ (x : (ClRightCancellativeSemigroupTerm A)) , (P x))))
| psing popcl (sing x1) := (psing x1)
| psing popcl (opCl x1 x2) := (popcl _ _ (inductionCl psing popcl x1) (inductionCl psing popcl x2))
def inductionOpB {n : ℕ} {P : ((OpRightCancellativeSemigroupTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 x2 : (OpRightCancellativeSemigroupTerm n)) , ((P x1) → ((P x2) → (P (opOL x1 x2))))) → (∀ (x : (OpRightCancellativeSemigroupTerm n)) , (P x))))
| pv popol (v x1) := (pv x1)
| pv popol (opOL x1 x2) := (popol _ _ (inductionOpB pv popol x1) (inductionOpB pv popol x2))
def inductionOp {n : ℕ} {A : Type} {P : ((OpRightCancellativeSemigroupTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 x2 : (OpRightCancellativeSemigroupTerm2 n A)) , ((P x1) → ((P x2) → (P (opOL2 x1 x2))))) → (∀ (x : (OpRightCancellativeSemigroupTerm2 n A)) , (P x)))))
| pv2 psing2 popol2 (v2 x1) := (pv2 x1)
| pv2 psing2 popol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 popol2 (opOL2 x1 x2) := (popol2 _ _ (inductionOp pv2 psing2 popol2 x1) (inductionOp pv2 psing2 popol2 x2))
def stageB : (RightCancellativeSemigroupTerm → (Staged RightCancellativeSemigroupTerm))
| (opL x1 x2) := (stage2 opL (codeLift2 opL) (stageB x1) (stageB x2))
def stageCl {A : Type} : ((ClRightCancellativeSemigroupTerm A) → (Staged (ClRightCancellativeSemigroupTerm A)))
| (sing x1) := (Now (sing x1))
| (opCl x1 x2) := (stage2 opCl (codeLift2 opCl) (stageCl x1) (stageCl x2))
def stageOpB {n : ℕ} : ((OpRightCancellativeSemigroupTerm n) → (Staged (OpRightCancellativeSemigroupTerm n)))
| (v x1) := (const (code (v x1)))
| (opOL x1 x2) := (stage2 opOL (codeLift2 opOL) (stageOpB x1) (stageOpB x2))
def stageOp {n : ℕ} {A : Type} : ((OpRightCancellativeSemigroupTerm2 n A) → (Staged (OpRightCancellativeSemigroupTerm2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (opOL2 x1 x2) := (stage2 opOL2 (codeLift2 opOL2) (stageOp x1) (stageOp x2))
structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type :=
(opT : ((Repr A) → ((Repr A) → (Repr A))))
end RightCancellativeSemigroup |
ecf5629f752f1ac51e8e5bafe15defb1ebabb16c | 2a70b774d16dbdf5a533432ee0ebab6838df0948 | /_target/deps/mathlib/src/linear_algebra/dimension.lean | 85078612474d65525f37aaa11fa88a64e6c6b0f0 | [
"Apache-2.0"
] | permissive | hjvromen/lewis | 40b035973df7c77ebf927afab7878c76d05ff758 | 105b675f73630f028ad5d890897a51b3c1146fb0 | refs/heads/master | 1,677,944,636,343 | 1,676,555,301,000 | 1,676,555,301,000 | 327,553,599 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 25,378 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro, Johannes Hölzl, Sander Dahmen
-/
import linear_algebra.basis
import set_theory.cardinal_ordinal
/-!
# Dimension of modules and vector spaces
## Main definitions
* The dimension of a vector space is defined as `vector_space.dim : cardinal`.
## Main statements
* `mk_eq_mk_of_basis`: the dimension theorem, any two bases of the same vector space have the same
cardinality.
* `dim_quotient_add_dim`: if V₁ is a submodule of V, then dim (V/V₁) + dim V₁ = dim V.
* `dim_range_add_dim_ker`: the rank-nullity theorem.
## Implementation notes
Many theorems in this file are not universe-generic when they relate dimensions
in different universes. They should be as general as they can be without
inserting `lift`s. The types `V`, `V'`, ... all live in different universes,
and `V₁`, `V₂`, ... all live in the same universe.
-/
noncomputable theory
universes u v v' v'' u₁' w w'
variables {K : Type u} {V V₁ V₂ V₃ : Type v} {V' V'₁ : Type v'} {V'' : Type v''}
variables {ι : Type w} {ι' : Type w'} {η : Type u₁'} {φ : η → Type*}
open_locale classical big_operators
section vector_space
variables [field K] [add_comm_group V] [vector_space K V] [add_comm_group V₁] [vector_space K V₁]
include K
open submodule function set
variables (K V)
/-- the dimension of a vector space, defined as a term of type `cardinal` -/
def vector_space.dim : cardinal :=
cardinal.min
(nonempty_subtype.2 (@exists_is_basis K V _ _ _))
(λ b, cardinal.mk b.1)
variables {K V}
open vector_space
section
theorem is_basis.le_span {v : ι → V} {J : set V} (hv : is_basis K v)
(hJ : span K J = ⊤) : cardinal.mk (range v) ≤ cardinal.mk J :=
begin
cases le_or_lt cardinal.omega (cardinal.mk J) with oJ oJ,
{ have := cardinal.mk_range_eq_of_injective (linear_independent.injective hv.1),
let S : J → set ι := λ j, ↑(is_basis.repr hv j).support,
let S' : J → set V := λ j, v '' S j,
have hs : range v ⊆ ⋃ j, S' j,
{ intros b hb,
rcases mem_range.1 hb with ⟨i, hi⟩,
have : span K J ≤ comap hv.repr (finsupp.supported K K (⋃ j, S j)) :=
span_le.2 (λ j hj x hx, ⟨_, ⟨⟨j, hj⟩, rfl⟩, hx⟩),
rw hJ at this,
replace : hv.repr (v i) ∈ (finsupp.supported K K (⋃ j, S j)) := this trivial,
rw [hv.repr_eq_single, finsupp.mem_supported,
finsupp.support_single_ne_zero one_ne_zero] at this,
{ subst b,
rcases mem_Union.1 (this (finset.mem_singleton_self _)) with ⟨j, hj⟩,
exact mem_Union.2 ⟨j, (mem_image _ _ _).2 ⟨i, hj, rfl⟩⟩ },
{ apply_instance } },
refine le_of_not_lt (λ IJ, _),
suffices : cardinal.mk (⋃ j, S' j) < cardinal.mk (range v),
{ exact not_le_of_lt this ⟨set.embedding_of_subset _ _ hs⟩ },
refine lt_of_le_of_lt (le_trans cardinal.mk_Union_le_sum_mk
(cardinal.sum_le_sum _ (λ _, cardinal.omega) _)) _,
{ exact λ j, le_of_lt (cardinal.lt_omega_iff_finite.2 $ (finset.finite_to_set _).image _) },
{ rwa [cardinal.sum_const, cardinal.mul_eq_max oJ (le_refl _), max_eq_left oJ] } },
{ rcases exists_finite_card_le_of_finite_of_linear_independent_of_span
(cardinal.lt_omega_iff_finite.1 oJ) hv.1.to_subtype_range _ with ⟨fI, hi⟩,
{ rwa [← cardinal.nat_cast_le, cardinal.finset_card, set.finite.coe_to_finset,
cardinal.finset_card, set.finite.coe_to_finset] at hi, },
{ rw hJ, apply set.subset_univ } },
end
end
/-- dimension theorem -/
theorem mk_eq_mk_of_basis {v : ι → V} {v' : ι' → V}
(hv : is_basis K v) (hv' : is_basis K v') :
cardinal.lift.{w w'} (cardinal.mk ι) = cardinal.lift.{w' w} (cardinal.mk ι') :=
begin
rw ←cardinal.lift_inj.{(max w w') v},
rw [cardinal.lift_lift, cardinal.lift_lift],
apply le_antisymm,
{ convert cardinal.lift_le.{v (max w w')}.2 (hv.le_span hv'.2),
{ rw cardinal.lift_max.{w v w'},
apply (cardinal.mk_range_eq_of_injective hv.injective).symm, },
{ rw cardinal.lift_max.{w' v w},
apply (cardinal.mk_range_eq_of_injective hv'.injective).symm, }, },
{ convert cardinal.lift_le.{v (max w w')}.2 (hv'.le_span hv.2),
{ rw cardinal.lift_max.{w' v w},
apply (cardinal.mk_range_eq_of_injective hv'.injective).symm, },
{ rw cardinal.lift_max.{w v w'},
apply (cardinal.mk_range_eq_of_injective hv.injective).symm, }, }
end
theorem mk_eq_mk_of_basis' {ι' : Type w} {v : ι → V} {v' : ι' → V} (hv : is_basis K v)
(hv' : is_basis K v') :
cardinal.mk ι = cardinal.mk ι' :=
cardinal.lift_inj.1 $ mk_eq_mk_of_basis hv hv'
theorem is_basis.mk_eq_dim'' {ι : Type v} {v : ι → V} (h : is_basis K v) :
cardinal.mk ι = dim K V :=
begin
obtain ⟨v', e : dim K V = _⟩ := cardinal.min_eq _ _,
rw e,
rw ← cardinal.mk_range_eq _ h.injective,
exact mk_eq_mk_of_basis' h.range v'.2
end
theorem is_basis.mk_range_eq_dim {v : ι → V} (h : is_basis K v) :
cardinal.mk (range v) = dim K V :=
h.range.mk_eq_dim''
theorem is_basis.mk_eq_dim {v : ι → V} (h : is_basis K v) :
cardinal.lift.{w v} (cardinal.mk ι) = cardinal.lift.{v w} (dim K V) :=
by rw [←h.mk_range_eq_dim, cardinal.mk_range_eq_of_injective h.injective]
theorem {m} is_basis.mk_eq_dim' {v : ι → V} (h : is_basis K v) :
cardinal.lift.{w (max v m)} (cardinal.mk ι) = cardinal.lift.{v (max w m)} (dim K V) :=
by simpa using h.mk_eq_dim
theorem dim_le {n : ℕ}
(H : ∀ s : finset V, linear_independent K (λ i : (↑s : set V), (i : V)) → s.card ≤ n) :
dim K V ≤ n :=
let ⟨b, hb⟩ := exists_is_basis K V in
hb.mk_eq_dim'' ▸ cardinal.card_le_of (λ s, @finset.card_map _ _ ⟨_, subtype.val_injective⟩ s ▸ H _
(by { refine hb.1.mono (λ y h, _),
rw [finset.mem_coe, finset.mem_map] at h, rcases h with ⟨x, hx, rfl⟩, exact x.2 } ))
variables [add_comm_group V'] [vector_space K V']
/-- Two linearly equivalent vector spaces have the same dimension, a version with different
universes. -/
theorem linear_equiv.lift_dim_eq (f : V ≃ₗ[K] V') :
cardinal.lift.{v v'} (dim K V) = cardinal.lift.{v' v} (dim K V') :=
let ⟨b, hb⟩ := exists_is_basis K V in
calc cardinal.lift.{v v'} (dim K V) = cardinal.lift.{v v'} (cardinal.mk b) :
congr_arg _ hb.mk_eq_dim''.symm
... = cardinal.lift.{v' v} (dim K V') : (f.is_basis hb).mk_eq_dim
/-- Two linearly equivalent vector spaces have the same dimension. -/
theorem linear_equiv.dim_eq (f : V ≃ₗ[K] V₁) :
dim K V = dim K V₁ :=
cardinal.lift_inj.1 f.lift_dim_eq
/-- Two vector spaces are isomorphic if they have the same dimension. -/
theorem nonempty_linear_equiv_of_lift_dim_eq
(cond : cardinal.lift.{v v'} (dim K V) = cardinal.lift.{v' v} (dim K V')) :
nonempty (V ≃ₗ[K] V') :=
begin
obtain ⟨B, h⟩ := exists_is_basis K V,
obtain ⟨B', h'⟩ := exists_is_basis K V',
have : cardinal.lift.{v v'} (cardinal.mk B) = cardinal.lift.{v' v} (cardinal.mk B'),
by rw [h.mk_eq_dim'', cond, h'.mk_eq_dim''],
exact (cardinal.lift_mk_eq.{v v' 0}.1 this).map (linear_equiv_of_is_basis h h')
end
/-- Two vector spaces are isomorphic if they have the same dimension. -/
theorem nonempty_linear_equiv_of_dim_eq (cond : dim K V = dim K V₁) :
nonempty (V ≃ₗ[K] V₁) :=
nonempty_linear_equiv_of_lift_dim_eq $ congr_arg _ cond
section
variables (V V' V₁)
/-- Two vector spaces are isomorphic if they have the same dimension. -/
def linear_equiv.of_lift_dim_eq
(cond : cardinal.lift.{v v'} (dim K V) = cardinal.lift.{v' v} (dim K V')) :
V ≃ₗ[K] V' :=
classical.choice (nonempty_linear_equiv_of_lift_dim_eq cond)
/-- Two vector spaces are isomorphic if they have the same dimension. -/
def linear_equiv.of_dim_eq (cond : dim K V = dim K V₁) : V ≃ₗ[K] V₁ :=
classical.choice (nonempty_linear_equiv_of_dim_eq cond)
end
/-- Two vector spaces are isomorphic if and only if they have the same dimension. -/
theorem linear_equiv.nonempty_equiv_iff_lift_dim_eq :
nonempty (V ≃ₗ[K] V') ↔ cardinal.lift.{v v'} (dim K V) = cardinal.lift.{v' v} (dim K V') :=
⟨λ ⟨h⟩, linear_equiv.lift_dim_eq h, λ h, nonempty_linear_equiv_of_lift_dim_eq h⟩
/-- Two vector spaces are isomorphic if and only if they have the same dimension. -/
theorem linear_equiv.nonempty_equiv_iff_dim_eq : nonempty (V ≃ₗ[K] V₁) ↔ dim K V = dim K V₁ :=
⟨λ ⟨h⟩, linear_equiv.dim_eq h, λ h, nonempty_linear_equiv_of_dim_eq h⟩
@[simp] lemma dim_bot : dim K (⊥ : submodule K V) = 0 :=
by letI := classical.dec_eq V;
rw [← cardinal.lift_inj, ← (@is_basis_empty_bot pempty K V _ _ _ not_nonempty_pempty).mk_eq_dim,
cardinal.mk_pempty]
@[simp] lemma dim_top : dim K (⊤ : submodule K V) = dim K V :=
linear_equiv.dim_eq (linear_equiv.of_top _ rfl)
lemma dim_of_field (K : Type*) [field K] : dim K K = 1 :=
by rw [←cardinal.lift_inj, ← (@is_basis_singleton_one punit K _ _).mk_eq_dim, cardinal.mk_punit]
lemma dim_span {v : ι → V} (hv : linear_independent K v) :
dim K ↥(span K (range v)) = cardinal.mk (range v) :=
by rw [←cardinal.lift_inj, ← (is_basis_span hv).mk_eq_dim,
cardinal.mk_range_eq_of_injective (@linear_independent.injective ι K V v _ _ _ _ hv)]
lemma dim_span_set {s : set V} (hs : linear_independent K (λ x, x : s → V)) :
dim K ↥(span K s) = cardinal.mk s :=
by { rw [← @set_of_mem_eq _ s, ← subtype.range_coe_subtype], exact dim_span hs }
lemma {m} cardinal_lift_le_dim_of_linear_independent
{ι : Type w} {v : ι → V} (hv : linear_independent K v) :
cardinal.lift.{w (max v m)} (cardinal.mk ι) ≤ cardinal.lift.{v (max w m)} (dim K V) :=
begin
obtain ⟨ι', v', is⟩ := exists_sum_is_basis hv,
rw [← cardinal.lift_umax, ← cardinal.lift_umax.{v}],
simpa using le_trans
(cardinal.lift_mk_le.{w _ (max v m)}.2 ⟨@function.embedding.inl ι ι'⟩)
(le_of_eq $ is_basis.mk_eq_dim'.{_ _ _ (max w m)} is),
end
lemma cardinal_le_dim_of_linear_independent
{ι : Type v} {v : ι → V} (hv : linear_independent K v) :
(cardinal.mk ι) ≤ (dim.{u v} K V) :=
by simpa using cardinal_lift_le_dim_of_linear_independent hv
lemma cardinal_le_dim_of_linear_independent'
{s : set V} (hs : linear_independent K (λ x, x : s → V)) :
cardinal.mk s ≤ dim K V :=
begin
-- extend s to a basis
obtain ⟨b, ss, h⟩ := exists_subset_is_basis hs,
rw [←h.mk_range_eq_dim, subtype.range_coe],
apply cardinal.mk_le_of_injective (inclusion_injective ss),
end
lemma dim_span_le (s : set V) : dim K (span K s) ≤ cardinal.mk s :=
begin
classical,
rcases
exists_linear_independent (linear_independent_empty K V) (set.empty_subset s)
with ⟨b, hb, _, hsb, hlib⟩,
have hsab : span K s = span K b,
from span_eq_of_le _ hsb (span_le.2 (λ x hx, subset_span (hb hx))),
convert cardinal.mk_le_mk_of_subset hb,
rw [hsab, dim_span_set hlib]
end
lemma dim_span_of_finset (s : finset V) :
dim K (span K (↑s : set V)) < cardinal.omega :=
calc dim K (span K (↑s : set V)) ≤ cardinal.mk (↑s : set V) : dim_span_le ↑s
... = s.card : by rw ←cardinal.finset_card
... < cardinal.omega : cardinal.nat_lt_omega _
theorem dim_prod : dim K (V × V₁) = dim K V + dim K V₁ :=
begin
letI := classical.dec_eq V,
letI := classical.dec_eq V₁,
rcases exists_is_basis K V with ⟨b, hb⟩,
rcases exists_is_basis K V₁ with ⟨c, hc⟩,
rw [← cardinal.lift_inj,
← @is_basis.mk_eq_dim K (V × V₁) _ _ _ _ _ (is_basis_inl_union_inr hb hc),
cardinal.lift_add, cardinal.lift_mk,
← hb.mk_eq_dim, ← hc.mk_eq_dim,
cardinal.lift_mk, cardinal.lift_mk,
cardinal.add_def (ulift b) (ulift c)],
exact cardinal.lift_inj.1 (cardinal.lift_mk_eq.2
⟨equiv.ulift.trans (equiv.sum_congr (@equiv.ulift b) (@equiv.ulift c)).symm ⟩),
end
theorem dim_quotient_add_dim (p : submodule K V) :
dim K p.quotient + dim K p = dim K V :=
by classical; exact let ⟨f⟩ := quotient_prod_linear_equiv p in dim_prod.symm.trans f.dim_eq
theorem dim_quotient_le (p : submodule K V) :
dim K p.quotient ≤ dim K V :=
by { rw ← dim_quotient_add_dim p, exact self_le_add_right _ _ }
/-- rank-nullity theorem -/
theorem dim_range_add_dim_ker (f : V →ₗ[K] V₁) : dim K f.range + dim K f.ker = dim K V :=
begin
haveI := λ (p : submodule K V), classical.dec_eq p.quotient,
rw [← f.quot_ker_equiv_range.dim_eq, dim_quotient_add_dim]
end
lemma dim_range_le (f : V →ₗ[K] V₁) : dim K f.range ≤ dim K V :=
by { rw ← dim_range_add_dim_ker f, exact self_le_add_right _ _ }
lemma dim_map_le (f : V →ₗ V₁) (p : submodule K V) : dim K (p.map f) ≤ dim K p :=
begin
have h := dim_range_le (f.comp (submodule.subtype p)),
rwa [linear_map.range_comp, range_subtype] at h,
end
lemma dim_range_of_surjective (f : V →ₗ[K] V') (h : surjective f) : dim K f.range = dim K V' :=
begin
refine linear_equiv.dim_eq (linear_equiv.of_bijective (submodule.subtype _) _ _),
exact linear_map.ker_eq_bot.2 subtype.val_injective,
rwa [range_subtype, linear_map.range_eq_top]
end
lemma dim_eq_of_surjective (f : V →ₗ[K] V₁) (h : surjective f) : dim K V = dim K V₁ + dim K f.ker :=
by rw [← dim_range_add_dim_ker f, ← dim_range_of_surjective f h]
lemma dim_le_of_surjective (f : V →ₗ[K] V₁) (h : surjective f) : dim K V₁ ≤ dim K V :=
by { rw [dim_eq_of_surjective f h], refine self_le_add_right _ _ }
lemma dim_eq_of_injective (f : V →ₗ[K] V₁) (h : injective f) : dim K V = dim K f.range :=
by rw [← dim_range_add_dim_ker f, linear_map.ker_eq_bot.2 h]; simp [dim_bot]
lemma dim_submodule_le (s : submodule K V) : dim K s ≤ dim K V :=
by { rw ← dim_quotient_add_dim s, exact self_le_add_left _ _ }
lemma dim_le_of_injective (f : V →ₗ[K] V₁) (h : injective f) :
dim K V ≤ dim K V₁ :=
by { rw [dim_eq_of_injective f h], exact dim_submodule_le _ }
lemma dim_le_of_submodule (s t : submodule K V) (h : s ≤ t) : dim K s ≤ dim K t :=
dim_le_of_injective (of_le h) $ assume ⟨x, hx⟩ ⟨y, hy⟩ eq,
subtype.eq $ show x = y, from subtype.ext_iff_val.1 eq
lemma linear_independent_le_dim
{v : ι → V} (hv : linear_independent K v) :
cardinal.lift.{w v} (cardinal.mk ι) ≤ cardinal.lift.{v w} (dim K V) :=
calc
cardinal.lift.{w v} (cardinal.mk ι) = cardinal.lift.{v w} (cardinal.mk (set.range v)) :
(cardinal.mk_range_eq_of_injective (linear_independent.injective hv)).symm
... = cardinal.lift.{v w} (dim K (submodule.span K (set.range v))) : by rw (dim_span hv).symm
... ≤ cardinal.lift.{v w} (dim K V) : cardinal.lift_le.2 (dim_submodule_le (submodule.span K _))
theorem {u₁} linear_independent_le_dim' {v : ι → V} (hs : linear_independent K v) :
((cardinal.mk ι).lift : cardinal.{(max w v u₁)}) ≤
((vector_space.dim K V).lift : cardinal.{(max v w u₁)}) :=
cardinal.mk_range_eq_lift hs.injective ▸ dim_span hs ▸ cardinal.lift_le.2 (dim_submodule_le _)
section
variables [add_comm_group V₂] [vector_space K V₂]
variables [add_comm_group V₃] [vector_space K V₃]
open linear_map
/-- This is mostly an auxiliary lemma for `dim_sup_add_dim_inf_eq`. -/
lemma dim_add_dim_split
(db : V₂ →ₗ[K] V) (eb : V₃ →ₗ[K] V) (cd : V₁ →ₗ[K] V₂) (ce : V₁ →ₗ[K] V₃)
(hde : ⊤ ≤ db.range ⊔ eb.range)
(hgd : ker cd = ⊥)
(eq : db.comp cd = eb.comp ce)
(eq₂ : ∀d e, db d = eb e → (∃c, cd c = d ∧ ce c = e)) :
dim K V + dim K V₁ = dim K V₂ + dim K V₃ :=
have hf : surjective (coprod db eb),
begin
refine (range_eq_top.1 $ top_unique $ _),
rwa [← map_top, ← prod_top, map_coprod_prod]
end,
begin
conv {to_rhs, rw [← dim_prod, dim_eq_of_surjective _ hf] },
congr' 1,
apply linear_equiv.dim_eq,
refine linear_equiv.of_bijective _ _ _,
{ refine cod_restrict _ (prod cd (- ce)) _,
{ assume c,
simp only [add_eq_zero_iff_eq_neg, prod_apply, mem_ker,
coprod_apply, neg_neg, map_neg, neg_apply],
exact linear_map.ext_iff.1 eq c } },
{ rw [ker_cod_restrict, ker_prod, hgd, bot_inf_eq] },
{ rw [eq_top_iff, range_cod_restrict, ← map_le_iff_le_comap, map_top, range_subtype],
rintros ⟨d, e⟩,
have h := eq₂ d (-e),
simp only [add_eq_zero_iff_eq_neg, prod_apply, mem_ker, mem_coe, prod.mk.inj_iff,
coprod_apply, map_neg, neg_apply, linear_map.mem_range] at ⊢ h,
assume hde,
rcases h hde with ⟨c, h₁, h₂⟩,
refine ⟨c, h₁, _⟩,
rw [h₂, _root_.neg_neg] }
end
lemma dim_sup_add_dim_inf_eq (s t : submodule K V) :
dim K (s ⊔ t : submodule K V) + dim K (s ⊓ t : submodule K V) = dim K s + dim K t :=
dim_add_dim_split (of_le le_sup_left) (of_le le_sup_right) (of_le inf_le_left) (of_le inf_le_right)
begin
rw [← map_le_map_iff' (ker_subtype $ s ⊔ t), map_sup, map_top,
← linear_map.range_comp, ← linear_map.range_comp, subtype_comp_of_le, subtype_comp_of_le,
range_subtype, range_subtype, range_subtype],
exact le_refl _
end
(ker_of_le _ _ _)
begin ext ⟨x, hx⟩, refl end
begin
rintros ⟨b₁, hb₁⟩ ⟨b₂, hb₂⟩ eq,
have : b₁ = b₂ := congr_arg subtype.val eq,
subst this,
exact ⟨⟨b₁, hb₁, hb₂⟩, rfl, rfl⟩
end
lemma dim_add_le_dim_add_dim (s t : submodule K V) :
dim K (s ⊔ t : submodule K V) ≤ dim K s + dim K t :=
by { rw [← dim_sup_add_dim_inf_eq], exact self_le_add_right _ _ }
end
section fintype
variable [fintype η]
variables [∀i, add_comm_group (φ i)] [∀i, vector_space K (φ i)]
open linear_map
lemma dim_pi : vector_space.dim K (Πi, φ i) = cardinal.sum (λi, vector_space.dim K (φ i)) :=
begin
choose b hb using assume i, exists_is_basis K (φ i),
have : is_basis K (λ (ji : Σ j, b j), std_basis K (λ j, φ j) ji.fst ji.snd.val),
by apply pi.is_basis_std_basis _ hb,
rw [←cardinal.lift_inj, ← this.mk_eq_dim],
simp [λ i, (hb i).mk_range_eq_dim.symm, cardinal.sum_mk]
end
lemma dim_fun {V η : Type u} [fintype η] [add_comm_group V] [vector_space K V] :
vector_space.dim K (η → V) = fintype.card η * vector_space.dim K V :=
by rw [dim_pi, cardinal.sum_const, cardinal.fintype_card]
lemma dim_fun_eq_lift_mul :
vector_space.dim K (η → V) = (fintype.card η : cardinal.{max u₁' v}) *
cardinal.lift.{v u₁'} (vector_space.dim K V) :=
by rw [dim_pi, cardinal.sum_const_eq_lift_mul, cardinal.fintype_card, cardinal.lift_nat_cast]
lemma dim_fun' : vector_space.dim K (η → K) = fintype.card η :=
by rw [dim_fun_eq_lift_mul, dim_of_field K, cardinal.lift_one, mul_one, cardinal.nat_cast_inj]
lemma dim_fin_fun (n : ℕ) : dim K (fin n → K) = n :=
by simp [dim_fun']
end fintype
lemma exists_mem_ne_zero_of_ne_bot {s : submodule K V} (h : s ≠ ⊥) : ∃ b : V, b ∈ s ∧ b ≠ 0 :=
begin
classical,
by_contradiction hex,
have : ∀x∈s, (x:V) = 0, { simpa only [not_exists, not_and, not_not, ne.def] using hex },
exact (h $ bot_unique $ assume s hs, (submodule.mem_bot K).2 $ this s hs)
end
lemma exists_mem_ne_zero_of_dim_pos {s : submodule K V} (h : 0 < vector_space.dim K s) :
∃ b : V, b ∈ s ∧ b ≠ 0 :=
exists_mem_ne_zero_of_ne_bot $ assume eq, by rw [eq, dim_bot] at h; exact lt_irrefl _ h
lemma exists_is_basis_fintype (h : dim K V < cardinal.omega) :
∃ s : (set V), (is_basis K (subtype.val : s → V)) ∧ nonempty (fintype s) :=
begin
cases exists_is_basis K V with s hs,
rw [←cardinal.lift_lt, ← is_basis.mk_eq_dim hs, cardinal.lift_lt,
cardinal.lt_omega_iff_fintype] at h,
exact ⟨s, hs, h⟩
end
section rank
/-- `rank f` is the rank of a `linear_map f`, defined as the dimension of `f.range`. -/
def rank (f : V →ₗ[K] V') : cardinal := dim K f.range
lemma rank_le_domain (f : V →ₗ[K] V₁) : rank f ≤ dim K V :=
by { rw [← dim_range_add_dim_ker f], exact self_le_add_right _ _ }
lemma rank_le_range (f : V →ₗ[K] V₁) : rank f ≤ dim K V₁ :=
dim_submodule_le _
lemma rank_add_le (f g : V →ₗ[K] V') : rank (f + g) ≤ rank f + rank g :=
calc rank (f + g) ≤ dim K (f.range ⊔ g.range : submodule K V') :
begin
refine dim_le_of_submodule _ _ _,
exact (linear_map.range_le_iff_comap.2 $ eq_top_iff'.2 $
assume x, show f x + g x ∈ (f.range ⊔ g.range : submodule K V'), from
mem_sup.2 ⟨_, mem_image_of_mem _ (mem_univ _), _, mem_image_of_mem _ (mem_univ _), rfl⟩)
end
... ≤ rank f + rank g : dim_add_le_dim_add_dim _ _
@[simp] lemma rank_zero : rank (0 : V →ₗ[K] V') = 0 :=
by rw [rank, linear_map.range_zero, dim_bot]
lemma rank_finset_sum_le {η} (s : finset η) (f : η → V →ₗ[K] V') :
rank (∑ d in s, f d) ≤ ∑ d in s, rank (f d) :=
@finset.sum_hom_rel _ _ _ _ _ (λa b, rank a ≤ b) f (λ d, rank (f d)) s (le_of_eq rank_zero)
(λ i g c h, le_trans (rank_add_le _ _) (add_le_add_left h _))
variables [add_comm_group V''] [vector_space K V'']
lemma rank_comp_le1 (g : V →ₗ[K] V') (f : V' →ₗ[K] V'') : rank (f.comp g) ≤ rank f :=
begin
refine dim_le_of_submodule _ _ _,
rw [linear_map.range_comp],
exact image_subset _ (subset_univ _)
end
variables [add_comm_group V'₁] [vector_space K V'₁]
lemma rank_comp_le2 (g : V →ₗ[K] V') (f : V' →ₗ V'₁) : rank (f.comp g) ≤ rank g :=
by rw [rank, rank, linear_map.range_comp]; exact dim_map_le _ _
end rank
lemma dim_zero_iff_forall_zero : vector_space.dim K V = 0 ↔ ∀ x : V, x = 0 :=
begin
split,
{ intros h x,
cases exists_is_basis K V with w hw,
have card_mk_range := hw.mk_range_eq_dim,
rw [h, cardinal.mk_emptyc_iff, subtype.range_coe] at card_mk_range,
simpa [card_mk_range] using hw.mem_span x },
{ intro h,
have : (⊤ : submodule K V) = ⊥,
{ ext x, simp [h x] },
rw [←dim_top, this, dim_bot] }
end
lemma dim_pos_iff_exists_ne_zero : 0 < vector_space.dim K V ↔ ∃ x : V, x ≠ 0 :=
begin
rw ←not_iff_not,
simpa using dim_zero_iff_forall_zero
end
lemma dim_pos_iff_nontrivial : 0 < vector_space.dim K V ↔ nontrivial V :=
begin
rw dim_pos_iff_exists_ne_zero,
split,
{ rintros ⟨x, h⟩, exact ⟨⟨x, 0, h⟩⟩ },
{ introsI, exact exists_ne 0 }
end
lemma dim_pos [h : nontrivial V] : 0 < vector_space.dim K V :=
dim_pos_iff_nontrivial.2 h
/-- A vector space has dimension at most `1` if and only if there is a
single vector of which all vectors are multiples. -/
lemma dim_le_one_iff : dim K V ≤ 1 ↔ ∃ v₀ : V, ∀ v, ∃ r : K, r • v₀ = v :=
begin
obtain ⟨b, h⟩ := exists_is_basis K V,
split,
{ intro hd,
rw [←is_basis.mk_eq_dim'' h, cardinal.le_one_iff_subsingleton, subsingleton_coe] at hd,
rcases eq_empty_or_nonempty b with rfl | ⟨⟨v₀, hv₀⟩⟩,
{ use 0,
have h' : ∀ v : V, v = 0, { simpa [submodule.eq_bot_iff] using h.2.symm },
intro v,
simp [h' v] },
{ use v₀,
have h' : (K ∙ v₀) = ⊤, { simpa [hd.eq_singleton_of_mem hv₀] using h.2 },
intro v,
have hv : v ∈ (⊤ : submodule K V) := mem_top,
rwa [←h', mem_span_singleton] at hv } },
{ rintros ⟨v₀, hv₀⟩,
have h : (K ∙ v₀) = ⊤,
{ ext, simp [mem_span_singleton, hv₀] },
rw [←dim_top, ←h],
convert dim_span_le _,
simp }
end
/-- A submodule has dimension at most `1` if and only if there is a
single vector in the submodule such that the submodule is contained in
its span. -/
lemma dim_submodule_le_one_iff (s : submodule K V) : dim K s ≤ 1 ↔ ∃ v₀ ∈ s, s ≤ K ∙ v₀ :=
begin
simp_rw [dim_le_one_iff, le_span_singleton_iff],
split,
{ rintro ⟨⟨v₀, hv₀⟩, h⟩,
use [v₀, hv₀],
intros v hv,
obtain ⟨r, hr⟩ := h ⟨v, hv⟩,
use r,
simp_rw [subtype.ext_iff, coe_smul, coe_mk] at hr,
exact hr },
{ rintro ⟨v₀, hv₀, h⟩,
use ⟨v₀, hv₀⟩,
rintro ⟨v, hv⟩,
obtain ⟨r, hr⟩ := h v hv,
use r,
simp_rw [subtype.ext_iff, coe_smul, coe_mk],
exact hr }
end
/-- A submodule has dimension at most `1` if and only if there is a
single vector, not necessarily in the submodule, such that the
submodule is contained in its span. -/
lemma dim_submodule_le_one_iff' (s : submodule K V) : dim K s ≤ 1 ↔ ∃ v₀, s ≤ K ∙ v₀ :=
begin
rw dim_submodule_le_one_iff,
split,
{ rintros ⟨v₀, hv₀, h⟩,
exact ⟨v₀, h⟩ },
{ rintros ⟨v₀, h⟩,
by_cases hw : ∃ w : V, w ∈ s ∧ w ≠ 0,
{ rcases hw with ⟨w, hw, hw0⟩,
use [w, hw],
rcases mem_span_singleton.1 (h hw) with ⟨r', rfl⟩,
have h0 : r' ≠ 0,
{ rintro rfl,
simpa using hw0 },
rwa span_singleton_smul_eq _ h0 },
{ push_neg at hw,
rw ←submodule.eq_bot_iff at hw,
simp [hw] } }
end
end vector_space
section unconstrained_universes
variables {E : Type v'}
variables [field K] [add_comm_group V] [vector_space K V]
[add_comm_group E] [vector_space K E]
open vector_space
/-- Version of linear_equiv.dim_eq without universe constraints. -/
theorem linear_equiv.dim_eq_lift (f : V ≃ₗ[K] E) :
cardinal.lift.{v v'} (dim K V) = cardinal.lift.{v' v} (dim K E) :=
begin
cases exists_is_basis K V with b hb,
rw [← cardinal.lift_inj.1 hb.mk_eq_dim, ← (f.is_basis hb).mk_eq_dim, cardinal.lift_mk],
end
end unconstrained_universes
|
a0a9c8a6df2800eded79dee19dd3b6a0fe38df1e | fbef61907e2e2afef7e1e91395505ed27448a945 | /LeanProtocPlugin/Google/Protobuf/Compiler/Plugin.lean | a9d19330231175c6641e141d7a6538997da9d485 | [
"MIT"
] | permissive | yatima-inc/Protoc.lean | 7edecca1f5b33909e6dfef1bcebcbbf9a322ca8c | 3ad7839ec911906e19984e5b60958ee9c866b7ec | refs/heads/master | 1,682,196,995,576 | 1,620,507,180,000 | 1,620,507,180,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 16,195 | lean | -- Generated by the Lean protobuf compiler. Do not edit manually.
-- source: google/protobuf/compiler/plugin.proto
import LeanProto
import Std.Data.AssocList
import LeanProtocPlugin.Google.Protobuf.Descriptor
set_option maxHeartbeats 10000000
set_option maxRecDepth 2048
set_option synthInstance.maxHeartbeats 10000000
set_option genSizeOfSpec false
open Std (AssocList)
namespace LeanProtocPlugin.Google.Protobuf.Compiler
inductive CodeGeneratorResponse_Feature where
| FEATURE_NONE : CodeGeneratorResponse_Feature
| FEATURE_PROTO3_OPTIONAL : CodeGeneratorResponse_Feature
deriving Repr, Inhabited, BEq
instance : LeanProto.ProtoEnum CodeGeneratorResponse_Feature where
toInt
| CodeGeneratorResponse_Feature.FEATURE_NONE => 0
| CodeGeneratorResponse_Feature.FEATURE_PROTO3_OPTIONAL => 1
ofInt
| 0 => some CodeGeneratorResponse_Feature.FEATURE_NONE
| 1 => some CodeGeneratorResponse_Feature.FEATURE_PROTO3_OPTIONAL
| _ => none
mutual
-- Starting
-- Starting Version
inductive Version where
| mk
(major : (Int))
(minor : (Int))
(patch : (Int))
(suffix : (String))
: Version
-- Starting CodeGeneratorRequest
inductive CodeGeneratorRequest where
| mk
(fileToGenerate : (Array (String)))
(parameter : (String))
(protoFile : (Array (LeanProtocPlugin.Google.Protobuf.FileDescriptorProto)))
(compilerVersion : (Option (Version)))
: CodeGeneratorRequest
-- Starting CodeGeneratorResponse
inductive CodeGeneratorResponse where
| mk
(error : (String))
(supportedFeatures : (Nat))
(file : (Array (CodeGeneratorResponse_File)))
: CodeGeneratorResponse
-- Starting CodeGeneratorResponse_File
inductive CodeGeneratorResponse_File where
| mk
(name : (String))
(insertionPoint : (String))
(content : (String))
(generatedCodeInfo : (Option (LeanProtocPlugin.Google.Protobuf.GeneratedCodeInfo)))
: CodeGeneratorResponse_File
end
def Version.mkDefault : Version :=
Version.mk arbitrary arbitrary arbitrary arbitrary
instance : Inhabited Version where
default := Version.mkDefault
def Version.major : Version → (Int)
| mk v0 v1 v2 v3 => v0
def Version.set_major (orig: Version) (val: (Int))
: Version := match orig with
| mk v0 v1 v2 v3 => Version.mk val v1 v2 v3
def Version.minor : Version → (Int)
| mk v0 v1 v2 v3 => v1
def Version.set_minor (orig: Version) (val: (Int))
: Version := match orig with
| mk v0 v1 v2 v3 => Version.mk v0 val v2 v3
def Version.patch : Version → (Int)
| mk v0 v1 v2 v3 => v2
def Version.set_patch (orig: Version) (val: (Int))
: Version := match orig with
| mk v0 v1 v2 v3 => Version.mk v0 v1 val v3
def Version.suffix : Version → (String)
| mk v0 v1 v2 v3 => v3
def Version.set_suffix (orig: Version) (val: (String))
: Version := match orig with
| mk v0 v1 v2 v3 => Version.mk v0 v1 v2 val
def CodeGeneratorRequest.mkDefault : CodeGeneratorRequest :=
CodeGeneratorRequest.mk arbitrary arbitrary arbitrary none
instance : Inhabited CodeGeneratorRequest where
default := CodeGeneratorRequest.mkDefault
def CodeGeneratorRequest.fileToGenerate : CodeGeneratorRequest → (Array (String))
| mk v0 v1 v2 v3 => v0
def CodeGeneratorRequest.set_fileToGenerate (orig: CodeGeneratorRequest) (val: (Array (String)))
: CodeGeneratorRequest := match orig with
| mk v0 v1 v2 v3 => CodeGeneratorRequest.mk val v1 v2 v3
def CodeGeneratorRequest.parameter : CodeGeneratorRequest → (String)
| mk v0 v1 v2 v3 => v1
def CodeGeneratorRequest.set_parameter (orig: CodeGeneratorRequest) (val: (String))
: CodeGeneratorRequest := match orig with
| mk v0 v1 v2 v3 => CodeGeneratorRequest.mk v0 val v2 v3
def CodeGeneratorRequest.protoFile : CodeGeneratorRequest → (Array (LeanProtocPlugin.Google.Protobuf.FileDescriptorProto))
| mk v0 v1 v2 v3 => v2
def CodeGeneratorRequest.set_protoFile (orig: CodeGeneratorRequest) (val: (Array (LeanProtocPlugin.Google.Protobuf.FileDescriptorProto)))
: CodeGeneratorRequest := match orig with
| mk v0 v1 v2 v3 => CodeGeneratorRequest.mk v0 v1 val v3
def CodeGeneratorRequest.compilerVersion : CodeGeneratorRequest → (Option (Version))
| mk v0 v1 v2 v3 => v3
def CodeGeneratorRequest.set_compilerVersion (orig: CodeGeneratorRequest) (val: (Option (Version)))
: CodeGeneratorRequest := match orig with
| mk v0 v1 v2 v3 => CodeGeneratorRequest.mk v0 v1 v2 val
def CodeGeneratorResponse.mkDefault : CodeGeneratorResponse :=
CodeGeneratorResponse.mk arbitrary arbitrary arbitrary
instance : Inhabited CodeGeneratorResponse where
default := CodeGeneratorResponse.mkDefault
def CodeGeneratorResponse.error : CodeGeneratorResponse → (String)
| mk v0 v1 v2 => v0
def CodeGeneratorResponse.set_error (orig: CodeGeneratorResponse) (val: (String))
: CodeGeneratorResponse := match orig with
| mk v0 v1 v2 => CodeGeneratorResponse.mk val v1 v2
def CodeGeneratorResponse.supportedFeatures : CodeGeneratorResponse → (Nat)
| mk v0 v1 v2 => v1
def CodeGeneratorResponse.set_supportedFeatures (orig: CodeGeneratorResponse) (val: (Nat))
: CodeGeneratorResponse := match orig with
| mk v0 v1 v2 => CodeGeneratorResponse.mk v0 val v2
def CodeGeneratorResponse.file : CodeGeneratorResponse → (Array (CodeGeneratorResponse_File))
| mk v0 v1 v2 => v2
def CodeGeneratorResponse.set_file (orig: CodeGeneratorResponse) (val: (Array (CodeGeneratorResponse_File)))
: CodeGeneratorResponse := match orig with
| mk v0 v1 v2 => CodeGeneratorResponse.mk v0 v1 val
def CodeGeneratorResponse_File.mkDefault : CodeGeneratorResponse_File :=
CodeGeneratorResponse_File.mk arbitrary arbitrary arbitrary none
instance : Inhabited CodeGeneratorResponse_File where
default := CodeGeneratorResponse_File.mkDefault
def CodeGeneratorResponse_File.name : CodeGeneratorResponse_File → (String)
| mk v0 v1 v2 v3 => v0
def CodeGeneratorResponse_File.set_name (orig: CodeGeneratorResponse_File) (val: (String))
: CodeGeneratorResponse_File := match orig with
| mk v0 v1 v2 v3 => CodeGeneratorResponse_File.mk val v1 v2 v3
def CodeGeneratorResponse_File.insertionPoint : CodeGeneratorResponse_File → (String)
| mk v0 v1 v2 v3 => v1
def CodeGeneratorResponse_File.set_insertionPoint (orig: CodeGeneratorResponse_File) (val: (String))
: CodeGeneratorResponse_File := match orig with
| mk v0 v1 v2 v3 => CodeGeneratorResponse_File.mk v0 val v2 v3
def CodeGeneratorResponse_File.content : CodeGeneratorResponse_File → (String)
| mk v0 v1 v2 v3 => v2
def CodeGeneratorResponse_File.set_content (orig: CodeGeneratorResponse_File) (val: (String))
: CodeGeneratorResponse_File := match orig with
| mk v0 v1 v2 v3 => CodeGeneratorResponse_File.mk v0 v1 val v3
def CodeGeneratorResponse_File.generatedCodeInfo : CodeGeneratorResponse_File → (Option (LeanProtocPlugin.Google.Protobuf.GeneratedCodeInfo))
| mk v0 v1 v2 v3 => v3
def CodeGeneratorResponse_File.set_generatedCodeInfo (orig: CodeGeneratorResponse_File) (val: (Option (LeanProtocPlugin.Google.Protobuf.GeneratedCodeInfo)))
: CodeGeneratorResponse_File := match orig with
| mk v0 v1 v2 v3 => CodeGeneratorResponse_File.mk v0 v1 v2 val
deriving instance BEq for CodeGeneratorResponse_File, CodeGeneratorResponse, CodeGeneratorRequest, Version
mutual
partial def Version_deserializeAux (x: Version) : LeanProto.EncDec.ProtoParseM Version := do
if (← LeanProto.EncDec.done) then return x
let (_type, key) ← LeanProto.EncDec.parseKey
match key with
| 1 => do Version_deserializeAux (x.set_major (← (LeanProto.EncDec.withIgnoredState LeanProto.EncDec.parseInt32AsInt) (x.major)))
| 2 => do Version_deserializeAux (x.set_minor (← (LeanProto.EncDec.withIgnoredState LeanProto.EncDec.parseInt32AsInt) (x.minor)))
| 3 => do Version_deserializeAux (x.set_patch (← (LeanProto.EncDec.withIgnoredState LeanProto.EncDec.parseInt32AsInt) (x.patch)))
| 4 => do Version_deserializeAux (x.set_suffix (← (LeanProto.EncDec.withIgnoredState LeanProto.EncDec.parseString) (x.suffix)))
| 0 => do throw $ IO.userError "Decoding message with field number 0"
| _ => do let _ ← LeanProto.EncDec.parseUnknown _type; Version_deserializeAux x
partial def CodeGeneratorRequest_deserializeAux (x: CodeGeneratorRequest) : LeanProto.EncDec.ProtoParseM CodeGeneratorRequest := do
if (← LeanProto.EncDec.done) then return x
let (_type, key) ← LeanProto.EncDec.parseKey
match key with
| 1 => do CodeGeneratorRequest_deserializeAux (x.set_fileToGenerate (← (LeanProto.EncDec.parseKeyAndNonPackedArray ((LeanProto.EncDec.withIgnoredState LeanProto.EncDec.parseString) arbitrary) _type) (x.fileToGenerate)))
| 2 => do CodeGeneratorRequest_deserializeAux (x.set_parameter (← (LeanProto.EncDec.withIgnoredState LeanProto.EncDec.parseString) (x.parameter)))
| 15 => do CodeGeneratorRequest_deserializeAux (x.set_protoFile (← (LeanProto.EncDec.parseKeyAndNonPackedArray ((fun v => LeanProto.EncDec.parseMessage (LeanProtocPlugin.Google.Protobuf.FileDescriptorProto_deserializeAux v)) arbitrary) _type) (x.protoFile)))
| 3 => do CodeGeneratorRequest_deserializeAux (x.set_compilerVersion (← (fun v => LeanProto.EncDec.parseMessage (Version_deserializeAux v)) (x.compilerVersion.getD arbitrary)))
| 0 => do throw $ IO.userError "Decoding message with field number 0"
| _ => do let _ ← LeanProto.EncDec.parseUnknown _type; CodeGeneratorRequest_deserializeAux x
partial def CodeGeneratorResponse_deserializeAux (x: CodeGeneratorResponse) : LeanProto.EncDec.ProtoParseM CodeGeneratorResponse := do
if (← LeanProto.EncDec.done) then return x
let (_type, key) ← LeanProto.EncDec.parseKey
match key with
| 1 => do CodeGeneratorResponse_deserializeAux (x.set_error (← (LeanProto.EncDec.withIgnoredState LeanProto.EncDec.parseString) (x.error)))
| 2 => do CodeGeneratorResponse_deserializeAux (x.set_supportedFeatures (← (LeanProto.EncDec.withIgnoredState LeanProto.EncDec.parseUInt64AsNat) (x.supportedFeatures)))
| 15 => do CodeGeneratorResponse_deserializeAux (x.set_file (← (LeanProto.EncDec.parseKeyAndNonPackedArray ((fun v => LeanProto.EncDec.parseMessage (CodeGeneratorResponse_File_deserializeAux v)) arbitrary) _type) (x.file)))
| 0 => do throw $ IO.userError "Decoding message with field number 0"
| _ => do let _ ← LeanProto.EncDec.parseUnknown _type; CodeGeneratorResponse_deserializeAux x
partial def CodeGeneratorResponse_File_deserializeAux (x: CodeGeneratorResponse_File) : LeanProto.EncDec.ProtoParseM CodeGeneratorResponse_File := do
if (← LeanProto.EncDec.done) then return x
let (_type, key) ← LeanProto.EncDec.parseKey
match key with
| 1 => do CodeGeneratorResponse_File_deserializeAux (x.set_name (← (LeanProto.EncDec.withIgnoredState LeanProto.EncDec.parseString) (x.name)))
| 2 => do CodeGeneratorResponse_File_deserializeAux (x.set_insertionPoint (← (LeanProto.EncDec.withIgnoredState LeanProto.EncDec.parseString) (x.insertionPoint)))
| 15 => do CodeGeneratorResponse_File_deserializeAux (x.set_content (← (LeanProto.EncDec.withIgnoredState LeanProto.EncDec.parseString) (x.content)))
| 16 => do CodeGeneratorResponse_File_deserializeAux (x.set_generatedCodeInfo (← (fun v => LeanProto.EncDec.parseMessage (LeanProtocPlugin.Google.Protobuf.GeneratedCodeInfo_deserializeAux v)) (x.generatedCodeInfo.getD arbitrary)))
| 0 => do throw $ IO.userError "Decoding message with field number 0"
| _ => do let _ ← LeanProto.EncDec.parseUnknown _type; CodeGeneratorResponse_File_deserializeAux x
end
mutual
partial def Version_serializeAux : Version -> LeanProto.EncDec.ProtoSerAction
| Version.mk v0 v1 v2 v3 => do
LeanProto.EncDec.serializeSkipDefault (LeanProto.EncDec.serializeWithTag (LeanProto.EncDec.serializeIntAsInt32) (LeanProto.EncDec.WireType.ofLit 0 rfl) 1) v0
LeanProto.EncDec.serializeSkipDefault (LeanProto.EncDec.serializeWithTag (LeanProto.EncDec.serializeIntAsInt32) (LeanProto.EncDec.WireType.ofLit 0 rfl) 2) v1
LeanProto.EncDec.serializeSkipDefault (LeanProto.EncDec.serializeWithTag (LeanProto.EncDec.serializeIntAsInt32) (LeanProto.EncDec.WireType.ofLit 0 rfl) 3) v2
LeanProto.EncDec.serializeSkipDefault (LeanProto.EncDec.serializeWithTag (LeanProto.EncDec.serializeString) (LeanProto.EncDec.WireType.ofLit 2 rfl) 4) v3
partial def CodeGeneratorRequest_serializeAux : CodeGeneratorRequest -> LeanProto.EncDec.ProtoSerAction
| CodeGeneratorRequest.mk v0 v1 v2 v3 => do
(LeanProto.EncDec.serializeUnpackedArrayWithTag (LeanProto.EncDec.serializeString) (LeanProto.EncDec.WireType.ofLit 2 rfl) 1) v0
LeanProto.EncDec.serializeSkipDefault (LeanProto.EncDec.serializeWithTag (LeanProto.EncDec.serializeString) (LeanProto.EncDec.WireType.ofLit 2 rfl) 2) v1
(LeanProto.EncDec.serializeUnpackedArrayWithTag ((LeanProto.EncDec.serializeMessage (LeanProtocPlugin.Google.Protobuf.FileDescriptorProto_serializeAux))) (LeanProto.EncDec.WireType.ofLit 2 rfl) 15) v2
LeanProto.EncDec.serializeOpt (LeanProto.EncDec.serializeWithTag ((LeanProto.EncDec.serializeMessage (Version_serializeAux))) (LeanProto.EncDec.WireType.ofLit 2 rfl) 3) v3
partial def CodeGeneratorResponse_serializeAux : CodeGeneratorResponse -> LeanProto.EncDec.ProtoSerAction
| CodeGeneratorResponse.mk v0 v1 v2 => do
LeanProto.EncDec.serializeSkipDefault (LeanProto.EncDec.serializeWithTag (LeanProto.EncDec.serializeString) (LeanProto.EncDec.WireType.ofLit 2 rfl) 1) v0
LeanProto.EncDec.serializeSkipDefault (LeanProto.EncDec.serializeWithTag (LeanProto.EncDec.serializeNatAsUInt64) (LeanProto.EncDec.WireType.ofLit 0 rfl) 2) v1
(LeanProto.EncDec.serializeUnpackedArrayWithTag ((LeanProto.EncDec.serializeMessage (CodeGeneratorResponse_File_serializeAux))) (LeanProto.EncDec.WireType.ofLit 2 rfl) 15) v2
partial def CodeGeneratorResponse_File_serializeAux : CodeGeneratorResponse_File -> LeanProto.EncDec.ProtoSerAction
| CodeGeneratorResponse_File.mk v0 v1 v2 v3 => do
LeanProto.EncDec.serializeSkipDefault (LeanProto.EncDec.serializeWithTag (LeanProto.EncDec.serializeString) (LeanProto.EncDec.WireType.ofLit 2 rfl) 1) v0
LeanProto.EncDec.serializeSkipDefault (LeanProto.EncDec.serializeWithTag (LeanProto.EncDec.serializeString) (LeanProto.EncDec.WireType.ofLit 2 rfl) 2) v1
LeanProto.EncDec.serializeSkipDefault (LeanProto.EncDec.serializeWithTag (LeanProto.EncDec.serializeString) (LeanProto.EncDec.WireType.ofLit 2 rfl) 15) v2
LeanProto.EncDec.serializeOpt (LeanProto.EncDec.serializeWithTag ((LeanProto.EncDec.serializeMessage (LeanProtocPlugin.Google.Protobuf.GeneratedCodeInfo_serializeAux))) (LeanProto.EncDec.WireType.ofLit 2 rfl) 16) v3
end
instance : LeanProto.ProtoSerialize Version where
serialize x := do
let res := LeanProto.EncDec.serialize (Version_serializeAux x)
LeanProto.EncDec.resultStateToExcept res
instance : LeanProto.ProtoDeserialize Version where
deserialize b :=
let res := LeanProto.EncDec.parse b (Version_deserializeAux (Version.mkDefault))
LeanProto.EncDec.resultToExcept res
instance : LeanProto.ProtoSerialize CodeGeneratorRequest where
serialize x := do
let res := LeanProto.EncDec.serialize (CodeGeneratorRequest_serializeAux x)
LeanProto.EncDec.resultStateToExcept res
instance : LeanProto.ProtoDeserialize CodeGeneratorRequest where
deserialize b :=
let res := LeanProto.EncDec.parse b (CodeGeneratorRequest_deserializeAux (CodeGeneratorRequest.mkDefault))
LeanProto.EncDec.resultToExcept res
instance : LeanProto.ProtoSerialize CodeGeneratorResponse where
serialize x := do
let res := LeanProto.EncDec.serialize (CodeGeneratorResponse_serializeAux x)
LeanProto.EncDec.resultStateToExcept res
instance : LeanProto.ProtoDeserialize CodeGeneratorResponse where
deserialize b :=
let res := LeanProto.EncDec.parse b (CodeGeneratorResponse_deserializeAux (CodeGeneratorResponse.mkDefault))
LeanProto.EncDec.resultToExcept res
instance : LeanProto.ProtoSerialize CodeGeneratorResponse_File where
serialize x := do
let res := LeanProto.EncDec.serialize (CodeGeneratorResponse_File_serializeAux x)
LeanProto.EncDec.resultStateToExcept res
instance : LeanProto.ProtoDeserialize CodeGeneratorResponse_File where
deserialize b :=
let res := LeanProto.EncDec.parse b (CodeGeneratorResponse_File_deserializeAux (CodeGeneratorResponse_File.mkDefault))
LeanProto.EncDec.resultToExcept res
end LeanProtocPlugin.Google.Protobuf.Compiler |
391ba087d8c5768ff713ed06471fa1184c2e2234 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/ring_theory/dedekind_domain/dvr.lean | 094322743245444fa14c6e68d42ff21abc17a1bc | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 1,895 | lean | /-
Copyright (c) 2020 Kenji Nakagawa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenji Nakagawa, Anne Baanen, Filippo A. E. Nuccio
-/
import ring_theory.localization.at_prime
import ring_theory.discrete_valuation_ring
/-!
# Dedekind domains
This file defines an equivalent notion of a Dedekind domain (or Dedekind ring),
namely a Noetherian integral domain where the localization at all nonzero prime ideals is a DVR
(TODO: and shows that it is equivalent to the main definition).
## Main definitions
- `is_dedekind_domain_dvr` alternatively defines a Dedekind domain as an integral domain that
is Noetherian, and the localization at every nonzero prime ideal is a DVR.
## Implementation notes
The definitions that involve a field of fractions choose a canonical field of fractions,
but are independent of that choice. The `..._iff` lemmas express this independence.
Often, definitions assume that Dedekind domains are not fields. We found it more practical
to add a `(h : ¬ is_field A)` assumption whenever this is explicitly needed.
## References
* [D. Marcus, *Number Fields*][marcus1977number]
* [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic]
* [J. Neukirch, *Algebraic Number Theory*][Neukirch1992]
## Tags
dedekind domain, dedekind ring
-/
variables (R A K : Type*) [comm_ring R] [comm_ring A] [is_domain A] [field K]
open_locale non_zero_divisors polynomial
/--
A Dedekind domain is an integral domain that is Noetherian, and the
localization at every nonzero prime is a discrete valuation ring.
This is equivalent to `is_dedekind_domain`.
TODO: prove the equivalence.
-/
structure is_dedekind_domain_dvr : Prop :=
(is_noetherian_ring : is_noetherian_ring A)
(is_dvr_at_nonzero_prime : ∀ P ≠ (⊥ : ideal A), P.is_prime →
discrete_valuation_ring (localization.at_prime P))
|
fa9827789c3320c99969f80bb9b4b10600b3deb2 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/field_theory/chevalley_warning.lean | cad0f2899a95b6b161cac0b4b42347de25d959c5 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 8,469 | lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import field_theory.finite.basic
/-!
# The Chevalley–Warning theorem
This file contains a proof of the Chevalley–Warning theorem.
Throughout most of this file, `K` denotes a finite field
and `q` is notation for the cardinality of `K`.
## Main results
1. Let `f` be a multivariate polynomial in finitely many variables (`X s`, `s : σ`)
such that the total degree of `f` is less than `(q-1)` times the cardinality of `σ`.
Then the evaluation of `f` on all points of `σ → K` (aka `K^σ`) sums to `0`.
(`sum_mv_polynomial_eq_zero`)
2. The Chevalley–Warning theorem (`char_dvd_card_solutions`).
Let `f i` be a finite family of multivariate polynomials
in finitely many variables (`X s`, `s : σ`) such that
the sum of the total degrees of the `f i` is less than the cardinality of `σ`.
Then the number of common solutions of the `f i`
is divisible by the characteristic of `K`.
## Notation
- `K` is a finite field
- `q` is notation for the cardinality of `K`
- `σ` is the indexing type for the variables of a multivariate polynomial ring over `K`
-/
universes u v
open_locale big_operators
section finite_field
open mv_polynomial function (hiding eval) finset finite_field
variables {K : Type*} {σ : Type*} [fintype K] [field K] [fintype σ]
local notation `q` := fintype.card K
lemma mv_polynomial.sum_mv_polynomial_eq_zero [decidable_eq σ] (f : mv_polynomial σ K)
(h : f.total_degree < (q - 1) * fintype.card σ) :
(∑ x, eval x f) = 0 :=
begin
haveI : decidable_eq K := classical.dec_eq K,
calc (∑ x, eval x f)
= ∑ x : σ → K, ∑ d in f.support, f.coeff d * ∏ i, x i ^ d i : by simp only [eval_eq']
... = ∑ d in f.support, ∑ x : σ → K, f.coeff d * ∏ i, x i ^ d i : sum_comm
... = 0 : sum_eq_zero _,
intros d hd,
obtain ⟨i, hi⟩ : ∃ i, d i < q - 1, from f.exists_degree_lt (q - 1) h hd,
calc (∑ x : σ → K, f.coeff d * ∏ i, x i ^ d i)
= f.coeff d * (∑ x : σ → K, ∏ i, x i ^ d i) : mul_sum.symm
... = 0 : (mul_eq_zero.mpr ∘ or.inr) _,
calc (∑ x : σ → K, ∏ i, x i ^ d i)
= ∑ (x₀ : {j // j ≠ i} → K) (x : {x : σ → K // x ∘ coe = x₀}), ∏ j, (x : σ → K) j ^ d j :
(fintype.sum_fiberwise _ _).symm
... = 0 : fintype.sum_eq_zero _ _,
intros x₀,
let e : K ≃ {x // x ∘ coe = x₀} := (equiv.subtype_equiv_codomain _).symm,
calc (∑ x : {x : σ → K // x ∘ coe = x₀}, ∏ j, (x : σ → K) j ^ d j)
= ∑ a : K, ∏ j : σ, (e a : σ → K) j ^ d j : (e.sum_comp _).symm
... = ∑ a : K, (∏ j, x₀ j ^ d j) * a ^ d i : fintype.sum_congr _ _ _
... = (∏ j, x₀ j ^ d j) * ∑ a : K, a ^ d i : by rw mul_sum
... = 0 : by rw [sum_pow_lt_card_sub_one _ hi, mul_zero],
intros a,
let e' : {j // j = i} ⊕ {j // j ≠ i} ≃ σ := equiv.sum_compl _,
letI : unique {j // j = i} :=
{ default := ⟨i, rfl⟩, uniq := λ ⟨j, h⟩, subtype.val_injective h },
calc (∏ j : σ, (e a : σ → K) j ^ d j)
= (e a : σ → K) i ^ d i * (∏ (j : {j // j ≠ i}), (e a : σ → K) j ^ d j) :
by { rw [← e'.prod_comp, fintype.prod_sum_type, univ_unique, prod_singleton], refl }
... = a ^ d i * (∏ (j : {j // j ≠ i}), (e a : σ → K) j ^ d j) :
by rw equiv.subtype_equiv_codomain_symm_apply_eq
... = a ^ d i * (∏ j, x₀ j ^ d j) : congr_arg _ (fintype.prod_congr _ _ _) -- see below
... = (∏ j, x₀ j ^ d j) * a ^ d i : mul_comm _ _,
{ -- the remaining step of the calculation above
rintros ⟨j, hj⟩,
show (e a : σ → K) j ^ d j = x₀ ⟨j, hj⟩ ^ d j,
rw equiv.subtype_equiv_codomain_symm_apply_ne, }
end
variables [decidable_eq K] [decidable_eq σ]
/-- The Chevalley–Warning theorem.
Let `(f i)` be a finite family of multivariate polynomials
in finitely many variables (`X s`, `s : σ`) over a finite field of characteristic `p`.
Assume that the sum of the total degrees of the `f i` is less than the cardinality of `σ`.
Then the number of common solutions of the `f i` is divisible by `p`. -/
theorem char_dvd_card_solutions_family (p : ℕ) [char_p K p]
{ι : Type*} {s : finset ι} {f : ι → mv_polynomial σ K}
(h : (∑ i in s, (f i).total_degree) < fintype.card σ) :
p ∣ fintype.card {x : σ → K // ∀ i ∈ s, eval x (f i) = 0} :=
begin
have hq : 0 < q - 1, { rw [← fintype.card_units, fintype.card_pos_iff], exact ⟨1⟩ },
let S : finset (σ → K) := { x ∈ univ | ∀ i ∈ s, eval x (f i) = 0 },
have hS : ∀ (x : σ → K), x ∈ S ↔ ∀ (i : ι), i ∈ s → eval x (f i) = 0,
{ intros x, simp only [S, true_and, sep_def, mem_filter, mem_univ], },
/- The polynomial `F = ∏ i in s, (1 - (f i)^(q - 1))` has the nice property
that it takes the value `1` on elements of `{x : σ → K // ∀ i ∈ s, (f i).eval x = 0}`
while it is `0` outside that locus.
Hence the sum of its values is equal to the cardinality of
`{x : σ → K // ∀ i ∈ s, (f i).eval x = 0}` modulo `p`. -/
let F : mv_polynomial σ K := ∏ i in s, (1 - (f i)^(q - 1)),
have hF : ∀ x, eval x F = if x ∈ S then 1 else 0,
{ intro x,
calc eval x F = ∏ i in s, eval x (1 - f i ^ (q - 1)) : eval_prod s _ x
... = if x ∈ S then 1 else 0 : _,
simp only [(eval x).map_sub, (eval x).map_pow, (eval x).map_one],
split_ifs with hx hx,
{ apply finset.prod_eq_one,
intros i hi,
rw hS at hx,
rw [hx i hi, zero_pow hq, sub_zero], },
{ obtain ⟨i, hi, hx⟩ : ∃ (i : ι), i ∈ s ∧ eval x (f i) ≠ 0,
{ simpa only [hS, not_forall, not_imp] using hx },
apply finset.prod_eq_zero hi,
rw [pow_card_sub_one_eq_one (eval x (f i)) hx, sub_self], } },
-- In particular, we can now show:
have key : ∑ x, eval x F = fintype.card {x : σ → K // ∀ i ∈ s, eval x (f i) = 0},
rw [fintype.card_of_subtype S hS, card_eq_sum_ones, nat.cast_sum, nat.cast_one,
← fintype.sum_extend_by_zero S, sum_congr rfl (λ x hx, hF x)],
-- With these preparations under our belt, we will approach the main goal.
show p ∣ fintype.card {x // ∀ (i : ι), i ∈ s → eval x (f i) = 0},
rw [← char_p.cast_eq_zero_iff K, ← key],
show ∑ x, eval x F = 0,
-- We are now ready to apply the main machine, proven before.
apply F.sum_mv_polynomial_eq_zero,
-- It remains to verify the crucial assumption of this machine
show F.total_degree < (q - 1) * fintype.card σ,
calc F.total_degree ≤ ∑ i in s, (1 - (f i)^(q - 1)).total_degree : total_degree_finset_prod s _
... ≤ ∑ i in s, (q - 1) * (f i).total_degree : sum_le_sum $ λ i hi, _ -- see ↓
... = (q - 1) * (∑ i in s, (f i).total_degree) : mul_sum.symm
... < (q - 1) * (fintype.card σ) : by rwa mul_lt_mul_left hq,
-- Now we prove the remaining step from the preceding calculation
show (1 - f i ^ (q - 1)).total_degree ≤ (q - 1) * (f i).total_degree,
calc (1 - f i ^ (q - 1)).total_degree
≤ max (1 : mv_polynomial σ K).total_degree (f i ^ (q - 1)).total_degree :
total_degree_sub _ _
... ≤ (f i ^ (q - 1)).total_degree : by simp only [max_eq_right, nat.zero_le, total_degree_one]
... ≤ (q - 1) * (f i).total_degree : total_degree_pow _ _
end
/-- The Chevalley–Warning theorem.
Let `f` be a multivariate polynomial in finitely many variables (`X s`, `s : σ`)
over a finite field of characteristic `p`.
Assume that the total degree of `f` is less than the cardinality of `σ`.
Then the number of solutions of `f` is divisible by `p`.
See `char_dvd_card_solutions_family` for a version that takes a family of polynomials `f i`. -/
theorem char_dvd_card_solutions (p : ℕ) [char_p K p]
{f : mv_polynomial σ K} (h : f.total_degree < fintype.card σ) :
p ∣ fintype.card {x : σ → K // eval x f = 0} :=
begin
let F : unit → mv_polynomial σ K := λ _, f,
have : ∑ i : unit, (F i).total_degree < fintype.card σ,
{ simpa only [fintype.univ_punit, sum_singleton] using h, },
have key := char_dvd_card_solutions_family p this,
simp only [F, fintype.univ_punit, forall_eq, mem_singleton] at key,
convert key,
end
end finite_field
|
540f8ca9de059ead27e60e5a22d98858f6fc9f03 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /src/Lean/Data/Options.lean | 21a94a1ff30ef2497d6040c15a7e255c65d17f87 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | EdAyers/lean4 | 57ac632d6b0789cb91fab2170e8c9e40441221bd | 37ba0df5841bde51dbc2329da81ac23d4f6a4de4 | refs/heads/master | 1,676,463,245,298 | 1,660,619,433,000 | 1,660,619,433,000 | 183,433,437 | 1 | 0 | Apache-2.0 | 1,657,612,672,000 | 1,556,196,574,000 | Lean | UTF-8 | Lean | false | false | 5,888 | lean | /-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich and Leonardo de Moura
-/
import Lean.ImportingFlag
import Lean.Data.KVMap
namespace Lean
def Options := KVMap
def Options.empty : Options := {}
instance : Inhabited Options where
default := {}
instance : ToString Options := inferInstanceAs (ToString KVMap)
instance : ForIn m Options (Name × DataValue) := inferInstanceAs (ForIn _ KVMap _)
structure OptionDecl where
defValue : DataValue
group : String := ""
descr : String := ""
deriving Inhabited
def OptionDecls := NameMap OptionDecl
instance : Inhabited OptionDecls := ⟨({} : NameMap OptionDecl)⟩
private builtin_initialize optionDeclsRef : IO.Ref OptionDecls ← IO.mkRef (mkNameMap OptionDecl)
@[export lean_register_option]
def registerOption (name : Name) (decl : OptionDecl) : IO Unit := do
unless (← initializing) do
throw (IO.userError "failed to register option, options can only be registered during initialization")
let decls ← optionDeclsRef.get
if decls.contains name then
throw $ IO.userError s!"invalid option declaration '{name}', option already exists"
optionDeclsRef.set $ decls.insert name decl
def getOptionDecls : IO OptionDecls := optionDeclsRef.get
@[export lean_get_option_decls_array]
def getOptionDeclsArray : IO (Array (Name × OptionDecl)) := do
let decls ← getOptionDecls
pure $ decls.fold
(fun (r : Array (Name × OptionDecl)) k v => r.push (k, v))
#[]
def getOptionDecl (name : Name) : IO OptionDecl := do
let decls ← getOptionDecls
let (some decl) ← pure (decls.find? name) | throw $ IO.userError s!"unknown option '{name}'"
pure decl
def getOptionDefaulValue (name : Name) : IO DataValue := do
let decl ← getOptionDecl name
pure decl.defValue
def getOptionDescr (name : Name) : IO String := do
let decl ← getOptionDecl name
pure decl.descr
def setOptionFromString (opts : Options) (entry : String) : IO Options := do
let ps := (entry.splitOn "=").map String.trim
let [key, val] ← pure ps | throw $ IO.userError "invalid configuration option entry, it must be of the form '<key> = <value>'"
let key := Name.mkSimple key
let defValue ← getOptionDefaulValue key
match defValue with
| DataValue.ofString _ => pure $ opts.setString key val
| DataValue.ofBool _ =>
if key == `true then pure $ opts.setBool key true
else if key == `false then pure $ opts.setBool key false
else throw $ IO.userError s!"invalid Bool option value '{val}'"
| DataValue.ofName _ => pure $ opts.setName key val.toName
| DataValue.ofNat _ =>
match val.toNat? with
| none => throw (IO.userError s!"invalid Nat option value '{val}'")
| some v => pure $ opts.setNat key v
| DataValue.ofInt _ =>
match val.toInt? with
| none => throw (IO.userError s!"invalid Int option value '{val}'")
| some v => pure $ opts.setInt key v
| DataValue.ofSyntax _ => throw (IO.userError s!"invalid Syntax option value")
class MonadOptions (m : Type → Type) where
getOptions : m Options
export MonadOptions (getOptions)
instance [MonadLift m n] [MonadOptions m] : MonadOptions n where
getOptions := liftM (getOptions : m _)
variable [Monad m] [MonadOptions m]
def getBoolOption (k : Name) (defValue := false) : m Bool := do
let opts ← getOptions
return opts.getBool k defValue
def getNatOption (k : Name) (defValue := 0) : m Nat := do
let opts ← getOptions
return opts.getNat k defValue
class MonadWithOptions (m : Type → Type) where
withOptions (f : Options → Options) (x : m α) : m α
export MonadWithOptions (withOptions)
instance [MonadFunctor m n] [MonadWithOptions m] : MonadWithOptions n where
withOptions f x := monadMap (m := m) (withOptions f) x
/-! Remark: `_inPattern` is an internal option for communicating to the delaborator that
the term being delaborated should be treated as a pattern. -/
def withInPattern [MonadWithOptions m] (x : m α) : m α :=
withOptions (fun o => o.setBool `_inPattern true) x
def Options.getInPattern (o : Options) : Bool :=
o.getBool `_inPattern
/-- A strongly-typed reference to an option. -/
protected structure Option (α : Type) where
name : Name
defValue : α
deriving Inhabited
namespace Option
protected structure Decl (α : Type) where
defValue : α
group : String := ""
descr : String := ""
protected def get? [KVMap.Value α] (opts : Options) (opt : Lean.Option α) : Option α :=
opts.get? opt.name
protected def get [KVMap.Value α] (opts : Options) (opt : Lean.Option α) : α :=
opts.get opt.name opt.defValue
protected def set [KVMap.Value α] (opts : Options) (opt : Lean.Option α) (val : α) : Options :=
opts.set opt.name val
/-- Similar to `set`, but update `opts` only if it doesn't already contains an setting for `opt.name` -/
protected def setIfNotSet [KVMap.Value α] (opts : Options) (opt : Lean.Option α) (val : α) : Options :=
if opts.contains opt.name then opts else opt.set opts val
protected def register [KVMap.Value α] (name : Name) (decl : Lean.Option.Decl α) : IO (Lean.Option α) := do
registerOption name { defValue := KVMap.Value.toDataValue decl.defValue, group := decl.group, descr := decl.descr }
return { name := name, defValue := decl.defValue }
macro (name := registerBuiltinOption) doc?:(docComment)? "register_builtin_option" name:ident " : " type:term " := " decl:term : command =>
`($[$doc?]? builtin_initialize $name : Lean.Option $type ← Lean.Option.register $(quote name.getId) $decl)
macro (name := registerOption) doc?:(docComment)? "register_option" name:ident " : " type:term " := " decl:term : command =>
`($[$doc?]? initialize $name : Lean.Option $type ← Lean.Option.register $(quote name.getId) $decl)
end Option
end Lean
|
3be787fe4e2fb3f9aad81ae74edb968704767a3e | 78269ad0b3c342b20786f60690708b6e328132b0 | /src/library_dev/data/set/finite.lean | 1659b104b34b135c9b46585cd958cbe240c6ba10 | [] | no_license | dselsam/library_dev | e74f46010fee9c7b66eaa704654cad0fcd2eefca | 1b4e34e7fb067ea5211714d6d3ecef5132fc8218 | refs/heads/master | 1,610,372,841,675 | 1,497,014,421,000 | 1,497,014,421,000 | 86,526,137 | 0 | 0 | null | 1,490,752,133,000 | 1,490,752,132,000 | null | UTF-8 | Lean | false | false | 2,199 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
Finite sets -- assuming a classical logic.
-/
import .basic
noncomputable theory
universes u v w
variables {α : Type u} {β : Type v} {ι : Sort w}
open set lattice
namespace set
/-
local attribute [instance] classical.decidable_inhabited
local attribute [instance] classical.prop_decidable
-/
inductive finite : set α → Prop
| empty : finite ∅
| insert : ∀a s, a ∉ s → finite s → finite (insert a s)
attribute [simp] finite.empty
@[simp]
lemma finite_insert {a : α} {s : set α} (h : finite s) : finite (insert a s) :=
classical.by_cases
(suppose a ∈ s, by simph)
(suppose a ∉ s, finite.insert a s this h)
@[simp]
lemma finite_singleton {a : α} : finite ({a} : set α) :=
finite_insert finite.empty
lemma finite_union {s t : set α} (hs : finite s) (ht : finite t) : finite (s ∪ t) :=
finite.drec_on ht (by simp [hs]) $ take a t _ _, by simp; exact finite_insert
lemma finite_subset {s : set α} (hs : finite s) : ∀{t}, t ⊆ s → finite t :=
begin
induction hs with a t' ha ht' ih,
{ intros t ht, simp [(subset_empty_iff t)^.mp ht, finite.empty] },
{ intros t ht,
note tm : finite (t \ {a}) :=
(ih $ show t \ {a} ⊆ t',
from take x ⟨hxt, hna⟩, or.resolve_left (ht hxt) (by simp at hna; assumption)),
cases (classical.em $ a ∈ t) with ha hna,
{ have finite (insert a (t \ {a})), from finite_insert tm,
show finite t,
by simp [ha] at this; assumption },
{ simp [sdiff_singleton_eq_same, hna] at tm, exact tm } }
end
lemma finite_image {s : set α} {f : α → β} (h : finite s) : finite (f '' s) :=
begin
induction h with a s' hns' hs' hi,
simp [image_empty, finite.empty],
simp [image_insert_eq, finite_insert, hi]
end
lemma finite_sUnion {s : set (set α)} (h : finite s) : (∀t∈s, finite t) → finite (⋃₀ s) :=
begin
induction h with a s' hns' hs' hi,
{ simp [finite.empty] },
{ intro h,
simp,
apply finite_union,
{ apply h, simp },
{ exact (hi $ take t ht, h _ $ mem_insert_of_mem _ ht) } }
end
end set
|
3aabe77a86a28616c533cc610fd9fd0d5799f073 | 5ae26df177f810c5006841e9c73dc56e01b978d7 | /test/mllist.lean | 038b86d646d3ee53fb045a5fed37b96da80d4c2e | [
"Apache-2.0"
] | permissive | ChrisHughes24/mathlib | 98322577c460bc6b1fe5c21f42ce33ad1c3e5558 | a2a867e827c2a6702beb9efc2b9282bd801d5f9a | refs/heads/master | 1,583,848,251,477 | 1,565,164,247,000 | 1,565,164,247,000 | 129,409,993 | 0 | 1 | Apache-2.0 | 1,565,164,817,000 | 1,523,628,059,000 | Lean | UTF-8 | Lean | false | false | 1,047 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import data.mllist
@[reducible] def S (α : Type) := state_t (list nat) option α
def append (x : nat) : S unit :=
{ run := λ s, some ((), x :: s) }
def F : nat → S nat
| 0 := failure
| (n+1) := append (n+1) >> pure n
open tactic
run_cmd
(do let x := ((mllist.fix F 10).force).run [],
guard $ x = (some ([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])))
run_cmd
(do let x := (((mllist.fix F 10).map(λ n, n*n)).take 2).run [],
guard $ x = (some ([100, 81], [9, 10])))
run_cmd
(do let x := (((mllist.fix F 10).mmap(λ n, pure $ n*n)).take 3).run [],
guard $ x = (some ([100, 81, 64], [8, 9, 10])))
meta def l1 : mllist S nat := mllist.of_list [0,1,2]
meta def l2 : mllist S nat := mllist.of_list [3,4,5]
meta def ll : mllist S nat := (mllist.of_list [l1, l2]).join
run_cmd
(do let x := ll.force.run [],
guard $ x = (some ([0, 1, 2, 3, 4, 5], [])))
|
966ef02b110d12a948c20efd3cbb89b0114b7520 | 957a80ea22c5abb4f4670b250d55534d9db99108 | /tests/lean/run/1782.lean | b633a00d1299e3b1d22b6c6afe261bdd20498f25 | [
"Apache-2.0"
] | permissive | GaloisInc/lean | aa1e64d604051e602fcf4610061314b9a37ab8cd | f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0 | refs/heads/master | 1,592,202,909,807 | 1,504,624,387,000 | 1,504,624,387,000 | 75,319,626 | 2 | 1 | Apache-2.0 | 1,539,290,164,000 | 1,480,616,104,000 | C++ | UTF-8 | Lean | false | false | 632 | lean | mutual inductive a, b, c
with a : Type
| foo : a
with b : Type
| bar : b
with c : Type
| baz : c
mutual def f, g, h
with f : a → nat
| a.foo := 0
with g : b → nat
| b.bar := 1
with h : c → nat
| c.baz := 2
example : f a.foo = 0 := rfl
example : g b.bar = 1 := rfl
example : h c.baz = 2 := rfl
mutual def f_1, f_2, f_3, f_4
with f_1 : a → nat
| a.foo := 0
with f_2 : b → nat
| b.bar := 1
with f_3 : c → nat
| c.baz := 2
with f_4 : nat → nat
| 0 := 3
| _ := 4
example : f_1 a.foo = 0 := rfl
example : f_2 b.bar = 1 := rfl
example : f_3 c.baz = 2 := rfl
example : f_4 0 = 3 := rfl
example : f_4 1 = 4 := rfl
|
766f2cb83f1694325d60e79113b2f7a7d6d1eedb | 0c1546a496eccfb56620165cad015f88d56190c5 | /library/init/meta/mk_inhabited_instance.lean | 0390e8c3af3d23a78c73722b45b7464262091214 | [
"Apache-2.0"
] | permissive | Solertis/lean | 491e0939957486f664498fbfb02546e042699958 | 84188c5aa1673fdf37a082b2de8562dddf53df3f | refs/heads/master | 1,610,174,257,606 | 1,486,263,620,000 | 1,486,263,620,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,705 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
Helper tactic for showing that a type has decidable equality.
-/
prelude
import init.meta.contradiction_tactic init.meta.constructor_tactic
import init.meta.injection_tactic init.meta.relation_tactics
namespace tactic
open expr environment list
/- Retrieve the name of the type we are building an inhabitant instance for. -/
private meta def get_inhabited_type_name : tactic name :=
do {
(app (const n ls) t) ← target >>= whnf | failed,
when (n ≠ `inhabited) failed,
(const I ls) ← return (get_app_fn t) | failed,
return I }
<|>
fail "mk_inhabited_instance tactic failed, target type is expected to be of the form (inhabited ...)"
/- Try to synthesize constructor argument using type class resolution -/
private meta def mk_inhabited_arg : tactic unit :=
do tgt ← target,
inh ← mk_app `inhabited [tgt],
inst ← mk_instance inh,
mk_app `inhabited.default [inst] >>= exact
private meta def try_constructors : nat → nat → tactic unit
| 0 n := failed
| (i+1) n :=
do {constructor_idx (n - i), all_goals mk_inhabited_arg, now}
<|>
try_constructors i n
meta def mk_inhabited_instance : tactic unit :=
do
I ← get_inhabited_type_name,
env ← get_env,
n : nat ← return $ length (constructors_of env I),
when (n = 0) (fail $ "mk_inhabited_instance failed, type '" ++ to_string I ++ "' does not have constructors"),
constructor,
(try_constructors n n)
<|>
(fail $ "mk_inhabited_instance failed, failed to build instance using all constructors of '" ++ to_string I ++ "'")
end tactic
|
b7bb774ee746341736ebd091826e748930664cf5 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/data/set/lattice.lean | 6c38cce8a7b6eb70ad966c5e8afd4029d52447cd | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 74,053 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Johannes Hölzl, Mario Carneiro
-/
import data.nat.basic
import order.complete_boolean_algebra
import order.directed
import order.galois_connection
/-!
# The set lattice
This file provides usual set notation for unions and intersections, a `complete_lattice` instance
for `set α`, and some more set constructions.
## Main declarations
* `set.Union`: Union of an indexed family of sets.
* `set.Inter`: Intersection of an indexed family of sets.
* `set.sInter`: **s**et **Inter**. Intersection of sets belonging to a set of sets.
* `set.sUnion`: **s**et **Union**. Union of sets belonging to a set of sets. This is actually
defined in core Lean.
* `set.sInter_eq_bInter`, `set.sUnion_eq_bInter`: Shows that `⋂₀ s = ⋂ x ∈ s, x` and
`⋃₀ s = ⋃ x ∈ s, x`.
* `set.complete_boolean_algebra`: `set α` is a `complete_boolean_algebra` with `≤ = ⊆`, `< = ⊂`,
`⊓ = ∩`, `⊔ = ∪`, `⨅ = ⋂`, `⨆ = ⋃` and `\` as the set difference. See `set.boolean_algebra`.
* `set.kern_image`: For a function `f : α → β`, `s.kern_image f` is the set of `y` such that
`f ⁻¹ y ⊆ s`.
* `set.seq`: Union of the image of a set under a **seq**uence of functions. `seq s t` is the union
of `f '' t` over all `f ∈ s`, where `t : set α` and `s : set (α → β)`.
* `set.Union_eq_sigma_of_disjoint`: Equivalence between `⋃ i, t i` and `Σ i, t i`, where `t` is an
indexed family of disjoint sets.
## Naming convention
In lemma names,
* `⋃ i, s i` is called `Union`
* `⋂ i, s i` is called `Inter`
* `⋃ i j, s i j` is called `Union₂`. This is a `Union` inside a `Union`.
* `⋂ i j, s i j` is called `Inter₂`. This is an `Inter` inside an `Inter`.
* `⋃ i ∈ s, t i` is called `bUnion` for "bounded `Union`". This is the special case of `Union₂`
where `j : i ∈ s`.
* `⋂ i ∈ s, t i` is called `bInter` for "bounded `Inter`". This is the special case of `Inter₂`
where `j : i ∈ s`.
## Notation
* `⋃`: `set.Union`
* `⋂`: `set.Inter`
* `⋃₀`: `set.sUnion`
* `⋂₀`: `set.sInter`
-/
open function tactic set
universes u
variables {α β γ : Type*} {ι ι' ι₂ : Sort*} {κ κ₁ κ₂ : ι → Sort*} {κ' : ι' → Sort*}
namespace set
/-! ### Complete lattice and complete Boolean algebra instances -/
instance : has_Inf (set α) := ⟨λ s, {a | ∀ t ∈ s, a ∈ t}⟩
instance : has_Sup (set α) := ⟨λ s, {a | ∃ t ∈ s, a ∈ t}⟩
/-- Intersection of a set of sets. -/
def sInter (S : set (set α)) : set α := Inf S
/-- Union of a set of sets. -/
def sUnion (S : set (set α)) : set α := Sup S
prefix `⋂₀ `:110 := sInter
prefix `⋃₀ `:110 := sUnion
@[simp] theorem mem_sInter {x : α} {S : set (set α)} : x ∈ ⋂₀ S ↔ ∀ t ∈ S, x ∈ t := iff.rfl
@[simp] theorem mem_sUnion {x : α} {S : set (set α)} : x ∈ ⋃₀ S ↔ ∃ t ∈ S, x ∈ t := iff.rfl
/-- Indexed union of a family of sets -/
def Union (s : ι → set β) : set β := supr s
/-- Indexed intersection of a family of sets -/
def Inter (s : ι → set β) : set β := infi s
notation `⋃` binders `, ` r:(scoped f, Union f) := r
notation `⋂` binders `, ` r:(scoped f, Inter f) := r
@[simp] lemma Sup_eq_sUnion (S : set (set α)) : Sup S = ⋃₀ S := rfl
@[simp] lemma Inf_eq_sInter (S : set (set α)) : Inf S = ⋂₀ S := rfl
@[simp] lemma supr_eq_Union (s : ι → set α) : supr s = Union s := rfl
@[simp] lemma infi_eq_Inter (s : ι → set α) : infi s = Inter s := rfl
@[simp] lemma mem_Union {x : α} {s : ι → set α} : x ∈ (⋃ i, s i) ↔ ∃ i, x ∈ s i :=
⟨λ ⟨t, ⟨⟨a, (t_eq : s a = t)⟩, (h : x ∈ t)⟩⟩, ⟨a, t_eq.symm ▸ h⟩,
λ ⟨a, h⟩, ⟨s a, ⟨⟨a, rfl⟩, h⟩⟩⟩
@[simp] lemma mem_Inter {x : α} {s : ι → set α} : x ∈ (⋂ i, s i) ↔ ∀ i, x ∈ s i :=
⟨λ (h : ∀ a ∈ {a : set α | ∃ i, s i = a}, x ∈ a) a, h (s a) ⟨a, rfl⟩,
λ h t ⟨a, (eq : s a = t)⟩, eq ▸ h a⟩
lemma mem_Union₂ {x : γ} {s : Π i, κ i → set γ} : x ∈ (⋃ i j, s i j) ↔ ∃ i j, x ∈ s i j :=
by simp_rw mem_Union
lemma mem_Inter₂ {x : γ} {s : Π i, κ i → set γ} : x ∈ (⋂ i j, s i j) ↔ ∀ i j, x ∈ s i j :=
by simp_rw mem_Inter
lemma mem_Union_of_mem {s : ι → set α} {a : α} (i : ι) (ha : a ∈ s i) : a ∈ ⋃ i, s i :=
mem_Union.2 ⟨i, ha⟩
lemma mem_Union₂_of_mem {s : Π i, κ i → set α} {a : α} {i : ι} (j : κ i) (ha : a ∈ s i j) :
a ∈ ⋃ i j, s i j :=
mem_Union₂.2 ⟨i, j, ha⟩
lemma mem_Inter_of_mem {s : ι → set α} {a : α} (h : ∀ i, a ∈ s i) : a ∈ ⋂ i, s i := mem_Inter.2 h
lemma mem_Inter₂_of_mem {s : Π i, κ i → set α} {a : α} (h : ∀ i j, a ∈ s i j) : a ∈ ⋂ i j, s i j :=
mem_Inter₂.2 h
instance : complete_boolean_algebra (set α) :=
{ Sup := Sup,
Inf := Inf,
le_Sup := λ s t t_in a a_in, ⟨t, ⟨t_in, a_in⟩⟩,
Sup_le := λ s t h a ⟨t', ⟨t'_in, a_in⟩⟩, h t' t'_in a_in,
le_Inf := λ s t h a a_in t' t'_in, h t' t'_in a_in,
Inf_le := λ s t t_in a h, h _ t_in,
infi_sup_le_sup_Inf := λ s S x, iff.mp $ by simp [forall_or_distrib_left],
inf_Sup_le_supr_inf := λ s S x, iff.mp $ by simp [exists_and_distrib_left],
.. set.boolean_algebra }
/-- `set.image` is monotone. See `set.image_image` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : monotone (image f) :=
λ s t, image_subset _
theorem _root_.monotone.inter [preorder β] {f g : β → set α}
(hf : monotone f) (hg : monotone g) : monotone (λ x, f x ∩ g x) :=
hf.inf hg
theorem _root_.monotone_on.inter [preorder β] {f g : β → set α} {s : set β}
(hf : monotone_on f s) (hg : monotone_on g s) : monotone_on (λ x, f x ∩ g x) s :=
hf.inf hg
theorem _root_.antitone.inter [preorder β] {f g : β → set α}
(hf : antitone f) (hg : antitone g) : antitone (λ x, f x ∩ g x) :=
hf.inf hg
theorem _root_.antitone_on.inter [preorder β] {f g : β → set α} {s : set β}
(hf : antitone_on f s) (hg : antitone_on g s) : antitone_on (λ x, f x ∩ g x) s :=
hf.inf hg
theorem _root_.monotone.union [preorder β] {f g : β → set α}
(hf : monotone f) (hg : monotone g) : monotone (λ x, f x ∪ g x) :=
hf.sup hg
theorem _root_.monotone_on.union [preorder β] {f g : β → set α} {s : set β}
(hf : monotone_on f s) (hg : monotone_on g s) : monotone_on (λ x, f x ∪ g x) s :=
hf.sup hg
theorem _root_.antitone.union [preorder β] {f g : β → set α}
(hf : antitone f) (hg : antitone g) : antitone (λ x, f x ∪ g x) :=
hf.sup hg
theorem _root_.antitone_on.union [preorder β] {f g : β → set α} {s : set β}
(hf : antitone_on f s) (hg : antitone_on g s) : antitone_on (λ x, f x ∪ g x) s :=
hf.sup hg
theorem monotone_set_of [preorder α] {p : α → β → Prop}
(hp : ∀ b, monotone (λ a, p a b)) : monotone (λ a, {b | p a b}) :=
λ a a' h b, hp b h
theorem antitone_set_of [preorder α] {p : α → β → Prop}
(hp : ∀ b, antitone (λ a, p a b)) : antitone (λ a, {b | p a b}) :=
λ a a' h b, hp b h
/-- Quantifying over a set is antitone in the set -/
lemma antitone_bforall {P : α → Prop} : antitone (λ s : set α, ∀ x ∈ s, P x) :=
λ s t hst h x hx, h x $ hst hx
section galois_connection
variables {f : α → β}
protected lemma image_preimage : galois_connection (image f) (preimage f) :=
λ a b, image_subset_iff
/-- `kern_image f s` is the set of `y` such that `f ⁻¹ y ⊆ s`. -/
def kern_image (f : α → β) (s : set α) : set β := {y | ∀ ⦃x⦄, f x = y → x ∈ s}
protected lemma preimage_kern_image : galois_connection (preimage f) (kern_image f) :=
λ a b,
⟨ λ h x hx y hy, have f y ∈ a, from hy.symm ▸ hx, h this,
λ h x (hx : f x ∈ a), h hx rfl⟩
end galois_connection
/-! ### Union and intersection over an indexed family of sets -/
instance : order_top (set α) :=
{ top := univ,
le_top := by simp }
@[congr] theorem Union_congr_Prop {p q : Prop} {f₁ : p → set α} {f₂ : q → set α}
(pq : p ↔ q) (f : ∀x, f₁ (pq.mpr x) = f₂ x) : Union f₁ = Union f₂ :=
supr_congr_Prop pq f
@[congr] theorem Inter_congr_Prop {p q : Prop} {f₁ : p → set α} {f₂ : q → set α}
(pq : p ↔ q) (f : ∀x, f₁ (pq.mpr x) = f₂ x) : Inter f₁ = Inter f₂ :=
infi_congr_Prop pq f
lemma Union_plift_up (f : plift ι → set α) : (⋃ i, f (plift.up i)) = ⋃ i, f i := supr_plift_up _
lemma Union_plift_down (f : ι → set α) : (⋃ i, f (plift.down i)) = ⋃ i, f i := supr_plift_down _
lemma Inter_plift_up (f : plift ι → set α) : (⋂ i, f (plift.up i)) = ⋂ i, f i := infi_plift_up _
lemma Inter_plift_down (f : ι → set α) : (⋂ i, f (plift.down i)) = ⋂ i, f i := infi_plift_down _
lemma Union_eq_if {p : Prop} [decidable p] (s : set α) :
(⋃ h : p, s) = if p then s else ∅ :=
supr_eq_if _
lemma Union_eq_dif {p : Prop} [decidable p] (s : p → set α) :
(⋃ (h : p), s h) = if h : p then s h else ∅ :=
supr_eq_dif _
lemma Inter_eq_if {p : Prop} [decidable p] (s : set α) :
(⋂ h : p, s) = if p then s else univ :=
infi_eq_if _
lemma Infi_eq_dif {p : Prop} [decidable p] (s : p → set α) :
(⋂ (h : p), s h) = if h : p then s h else univ :=
infi_eq_dif _
lemma exists_set_mem_of_union_eq_top {ι : Type*} (t : set ι) (s : ι → set β)
(w : (⋃ i ∈ t, s i) = ⊤) (x : β) :
∃ (i ∈ t), x ∈ s i :=
begin
have p : x ∈ ⊤ := set.mem_univ x,
simpa only [←w, set.mem_Union] using p,
end
lemma nonempty_of_union_eq_top_of_nonempty
{ι : Type*} (t : set ι) (s : ι → set α) (H : nonempty α) (w : (⋃ i ∈ t, s i) = ⊤) :
t.nonempty :=
begin
obtain ⟨x, m, -⟩ := exists_set_mem_of_union_eq_top t s w H.some,
exact ⟨x, m⟩,
end
theorem set_of_exists (p : ι → β → Prop) : {x | ∃ i, p i x} = ⋃ i, {x | p i x} :=
ext $ λ i, mem_Union.symm
theorem set_of_forall (p : ι → β → Prop) : {x | ∀ i, p i x} = ⋂ i, {x | p i x} :=
ext $ λ i, mem_Inter.symm
lemma Union_subset {s : ι → set α} {t : set α} (h : ∀ i, s i ⊆ t) : (⋃ i, s i) ⊆ t :=
@supr_le (set α) _ _ _ _ h
lemma Union₂_subset {s : Π i, κ i → set α} {t : set α} (h : ∀ i j, s i j ⊆ t) :
(⋃ i j, s i j) ⊆ t :=
Union_subset $ λ x, Union_subset (h x)
theorem subset_Inter {t : set β} {s : ι → set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i :=
@le_infi (set β) _ _ _ _ h
lemma subset_Inter₂ {s : set α} {t : Π i, κ i → set α} (h : ∀ i j, s ⊆ t i j) : s ⊆ ⋂ i j, t i j :=
subset_Inter $ λ x, subset_Inter $ h x
@[simp] lemma Union_subset_iff {s : ι → set α} {t : set α} : (⋃ i, s i) ⊆ t ↔ ∀ i, s i ⊆ t :=
⟨λ h i, subset.trans (le_supr s _) h, Union_subset⟩
lemma Union₂_subset_iff {s : Π i, κ i → set α} {t : set α} :
(⋃ i j, s i j) ⊆ t ↔ ∀ i j, s i j ⊆ t :=
by simp_rw Union_subset_iff
@[simp] lemma subset_Inter_iff {s : set α} {t : ι → set α} : s ⊆ (⋂ i, t i) ↔ ∀ i, s ⊆ t i :=
@le_infi_iff (set α) _ _ _ _
@[simp] lemma subset_Inter₂_iff {s : set α} {t : Π i, κ i → set α} :
s ⊆ (⋂ i j, t i j) ↔ ∀ i j, s ⊆ t i j :=
by simp_rw subset_Inter_iff
lemma subset_Union : ∀ (s : ι → set β) (i : ι), s i ⊆ ⋃ i, s i := le_supr
lemma Inter_subset : ∀ (s : ι → set β) (i : ι), (⋂ i, s i) ⊆ s i := infi_le
lemma subset_Union₂ {s : Π i, κ i → set α} (i : ι) (j : κ i) : s i j ⊆ ⋃ i j, s i j :=
@le_supr₂ (set α) _ _ _ _ i j
lemma Inter₂_subset {s : Π i, κ i → set α} (i : ι) (j : κ i) : (⋂ i j, s i j) ⊆ s i j :=
@infi₂_le (set α) _ _ _ _ i j
/-- This rather trivial consequence of `subset_Union`is convenient with `apply`, and has `i`
explicit for this purpose. -/
lemma subset_Union_of_subset {s : set α} {t : ι → set α} (i : ι) (h : s ⊆ t i) : s ⊆ ⋃ i, t i :=
@le_supr_of_le (set α) _ _ _ _ i h
/-- This rather trivial consequence of `Inter_subset`is convenient with `apply`, and has `i`
explicit for this purpose. -/
lemma Inter_subset_of_subset {s : ι → set α} {t : set α} (i : ι) (h : s i ⊆ t) : (⋂ i, s i) ⊆ t :=
@infi_le_of_le (set α) _ _ _ _ i h
/-- This rather trivial consequence of `subset_Union₂` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
lemma subset_Union₂_of_subset {s : set α} {t : Π i, κ i → set α} (i : ι) (j : κ i) (h : s ⊆ t i j) :
s ⊆ ⋃ i j, t i j :=
@le_supr₂_of_le (set α) _ _ _ _ _ i j h
/-- This rather trivial consequence of `Inter₂_subset` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
lemma Inter₂_subset_of_subset {s : Π i, κ i → set α} {t : set α} (i : ι) (j : κ i) (h : s i j ⊆ t) :
(⋂ i j, s i j) ⊆ t :=
@infi₂_le_of_le (set α) _ _ _ _ _ i j h
lemma Union_mono {s t : ι → set α} (h : ∀ i, s i ⊆ t i) : (⋃ i, s i) ⊆ ⋃ i, t i :=
@supr_mono (set α) _ _ s t h
lemma Union₂_mono {s t : Π i, κ i → set α} (h : ∀ i j, s i j ⊆ t i j) :
(⋃ i j, s i j) ⊆ ⋃ i j, t i j :=
@supr₂_mono (set α) _ _ _ s t h
lemma Inter_mono {s t : ι → set α} (h : ∀ i, s i ⊆ t i) : (⋂ i, s i) ⊆ ⋂ i, t i :=
@infi_mono (set α) _ _ s t h
lemma Inter₂_mono {s t : Π i, κ i → set α} (h : ∀ i j, s i j ⊆ t i j) :
(⋂ i j, s i j) ⊆ ⋂ i j, t i j :=
@infi₂_mono (set α) _ _ _ s t h
lemma Union_mono' {s : ι → set α} {t : ι₂ → set α} (h : ∀ i, ∃ j, s i ⊆ t j) :
(⋃ i, s i) ⊆ ⋃ i, t i :=
@supr_mono' (set α) _ _ _ s t h
lemma Union₂_mono' {s : Π i, κ i → set α} {t : Π i', κ' i' → set α}
(h : ∀ i j, ∃ i' j', s i j ⊆ t i' j') :
(⋃ i j, s i j) ⊆ ⋃ i' j', t i' j' :=
@supr₂_mono' (set α) _ _ _ _ _ s t h
lemma Inter_mono' {s : ι → set α} {t : ι' → set α} (h : ∀ j, ∃ i, s i ⊆ t j) :
(⋂ i, s i) ⊆ (⋂ j, t j) :=
set.subset_Inter $ λ j, let ⟨i, hi⟩ := h j in Inter_subset_of_subset i hi
lemma Inter₂_mono' {s : Π i, κ i → set α} {t : Π i', κ' i' → set α}
(h : ∀ i' j', ∃ i j, s i j ⊆ t i' j') :
(⋂ i j, s i j) ⊆ ⋂ i' j', t i' j' :=
subset_Inter₂_iff.2 $ λ i' j', let ⟨i, j, hst⟩ := h i' j' in (Inter₂_subset _ _).trans hst
lemma Union₂_subset_Union (κ : ι → Sort*) (s : ι → set α) : (⋃ i (j : κ i), s i) ⊆ ⋃ i, s i :=
Union_mono $ λ i, Union_subset $ λ h, subset.rfl
lemma Inter_subset_Inter₂ (κ : ι → Sort*) (s : ι → set α) : (⋂ i, s i) ⊆ ⋂ i (j : κ i), s i :=
Inter_mono $ λ i, subset_Inter $ λ h, subset.rfl
lemma Union_set_of (P : ι → α → Prop) : (⋃ i, {x : α | P i x}) = {x : α | ∃ i, P i x} :=
by { ext, exact mem_Union }
lemma Inter_set_of (P : ι → α → Prop) : (⋂ i, {x : α | P i x}) = {x : α | ∀ i, P i x} :=
by { ext, exact mem_Inter }
lemma Union_congr_of_surjective {f : ι → set α} {g : ι₂ → set α} (h : ι → ι₂)
(h1 : surjective h) (h2 : ∀ x, g (h x) = f x) : (⋃ x, f x) = ⋃ y, g y :=
h1.supr_congr h h2
lemma Inter_congr_of_surjective {f : ι → set α} {g : ι₂ → set α} (h : ι → ι₂)
(h1 : surjective h) (h2 : ∀ x, g (h x) = f x) : (⋂ x, f x) = ⋂ y, g y :=
h1.infi_congr h h2
theorem Union_const [nonempty ι] (s : set β) : (⋃ i : ι, s) = s := supr_const
theorem Inter_const [nonempty ι] (s : set β) : (⋂ i : ι, s) = s := infi_const
@[simp] theorem compl_Union (s : ι → set β) : (⋃ i, s i)ᶜ = (⋂ i, (s i)ᶜ) :=
compl_supr
lemma compl_Union₂ (s : Π i, κ i → set α) : (⋃ i j, s i j)ᶜ = ⋂ i j, (s i j)ᶜ :=
by simp_rw compl_Union
@[simp] theorem compl_Inter (s : ι → set β) : (⋂ i, s i)ᶜ = (⋃ i, (s i)ᶜ) :=
compl_infi
lemma compl_Inter₂ (s : Π i, κ i → set α) : (⋂ i j, s i j)ᶜ = ⋃ i j, (s i j)ᶜ :=
by simp_rw compl_Inter
-- classical -- complete_boolean_algebra
theorem Union_eq_compl_Inter_compl (s : ι → set β) : (⋃ i, s i) = (⋂ i, (s i)ᶜ)ᶜ :=
by simp only [compl_Inter, compl_compl]
-- classical -- complete_boolean_algebra
theorem Inter_eq_compl_Union_compl (s : ι → set β) : (⋂ i, s i) = (⋃ i, (s i)ᶜ)ᶜ :=
by simp only [compl_Union, compl_compl]
theorem inter_Union (s : set β) (t : ι → set β) :
s ∩ (⋃ i, t i) = ⋃ i, s ∩ t i :=
inf_supr_eq _ _
theorem Union_inter (s : set β) (t : ι → set β) :
(⋃ i, t i) ∩ s = ⋃ i, t i ∩ s :=
supr_inf_eq _ _
theorem Union_union_distrib (s : ι → set β) (t : ι → set β) :
(⋃ i, s i ∪ t i) = (⋃ i, s i) ∪ (⋃ i, t i) :=
supr_sup_eq
theorem Inter_inter_distrib (s : ι → set β) (t : ι → set β) :
(⋂ i, s i ∩ t i) = (⋂ i, s i) ∩ (⋂ i, t i) :=
infi_inf_eq
theorem union_Union [nonempty ι] (s : set β) (t : ι → set β) :
s ∪ (⋃ i, t i) = ⋃ i, s ∪ t i :=
sup_supr
theorem Union_union [nonempty ι] (s : set β) (t : ι → set β) :
(⋃ i, t i) ∪ s = ⋃ i, t i ∪ s :=
supr_sup
theorem inter_Inter [nonempty ι] (s : set β) (t : ι → set β) :
s ∩ (⋂ i, t i) = ⋂ i, s ∩ t i :=
inf_infi
theorem Inter_inter [nonempty ι] (s : set β) (t : ι → set β) :
(⋂ i, t i) ∩ s = ⋂ i, t i ∩ s :=
infi_inf
-- classical
theorem union_Inter (s : set β) (t : ι → set β) :
s ∪ (⋂ i, t i) = ⋂ i, s ∪ t i :=
sup_infi_eq _ _
theorem Inter_union (s : ι → set β) (t : set β) :
(⋂ i, s i) ∪ t = ⋂ i, s i ∪ t :=
infi_sup_eq _ _
theorem Union_diff (s : set β) (t : ι → set β) :
(⋃ i, t i) \ s = ⋃ i, t i \ s :=
Union_inter _ _
theorem diff_Union [nonempty ι] (s : set β) (t : ι → set β) :
s \ (⋃ i, t i) = ⋂ i, s \ t i :=
by rw [diff_eq, compl_Union, inter_Inter]; refl
theorem diff_Inter (s : set β) (t : ι → set β) :
s \ (⋂ i, t i) = ⋃ i, s \ t i :=
by rw [diff_eq, compl_Inter, inter_Union]; refl
lemma directed_on_Union {r} {f : ι → set α} (hd : directed (⊆) f)
(h : ∀ x, directed_on r (f x)) : directed_on r (⋃ x, f x) :=
by simp only [directed_on, exists_prop, mem_Union, exists_imp_distrib]; exact
λ a₁ b₁ fb₁ a₂ b₂ fb₂,
let ⟨z, zb₁, zb₂⟩ := hd b₁ b₂,
⟨x, xf, xa₁, xa₂⟩ := h z a₁ (zb₁ fb₁) a₂ (zb₂ fb₂) in
⟨x, ⟨z, xf⟩, xa₁, xa₂⟩
lemma Union_inter_subset {ι α} {s t : ι → set α} : (⋃ i, s i ∩ t i) ⊆ (⋃ i, s i) ∩ (⋃ i, t i) :=
le_supr_inf_supr s t
lemma Union_inter_of_monotone {ι α} [preorder ι] [is_directed ι (≤)] {s t : ι → set α}
(hs : monotone s) (ht : monotone t) : (⋃ i, s i ∩ t i) = (⋃ i, s i) ∩ (⋃ i, t i) :=
supr_inf_of_monotone hs ht
lemma Union_inter_of_antitone {ι α} [preorder ι] [is_directed ι (swap (≤))] {s t : ι → set α}
(hs : antitone s) (ht : antitone t) : (⋃ i, s i ∩ t i) = (⋃ i, s i) ∩ (⋃ i, t i) :=
supr_inf_of_antitone hs ht
lemma Inter_union_of_monotone {ι α} [preorder ι] [is_directed ι (swap (≤))] {s t : ι → set α}
(hs : monotone s) (ht : monotone t) : (⋂ i, s i ∪ t i) = (⋂ i, s i) ∪ (⋂ i, t i) :=
infi_sup_of_monotone hs ht
lemma Inter_union_of_antitone {ι α} [preorder ι] [is_directed ι (≤)] {s t : ι → set α}
(hs : antitone s) (ht : antitone t) : (⋂ i, s i ∪ t i) = (⋂ i, s i) ∪ (⋂ i, t i) :=
infi_sup_of_antitone hs ht
/-- An equality version of this lemma is `Union_Inter_of_monotone` in `data.set.finite`. -/
lemma Union_Inter_subset {s : ι → ι' → set α} : (⋃ j, ⋂ i, s i j) ⊆ ⋂ i, ⋃ j, s i j :=
supr_infi_le_infi_supr (flip s)
lemma Union_option {ι} (s : option ι → set α) : (⋃ o, s o) = s none ∪ ⋃ i, s (some i) :=
supr_option s
lemma Inter_option {ι} (s : option ι → set α) : (⋂ o, s o) = s none ∩ ⋂ i, s (some i) :=
infi_option s
section
variables (p : ι → Prop) [decidable_pred p]
lemma Union_dite (f : Π i, p i → set α) (g : Π i, ¬p i → set α) :
(⋃ i, if h : p i then f i h else g i h) = (⋃ i (h : p i), f i h) ∪ (⋃ i (h : ¬ p i), g i h) :=
supr_dite _ _ _
lemma Union_ite (f g : ι → set α) :
(⋃ i, if p i then f i else g i) = (⋃ i (h : p i), f i) ∪ (⋃ i (h : ¬ p i), g i) :=
Union_dite _ _ _
lemma Inter_dite (f : Π i, p i → set α) (g : Π i, ¬p i → set α) :
(⋂ i, if h : p i then f i h else g i h) = (⋂ i (h : p i), f i h) ∩ (⋂ i (h : ¬ p i), g i h) :=
infi_dite _ _ _
lemma Inter_ite (f g : ι → set α) :
(⋂ i, if p i then f i else g i) = (⋂ i (h : p i), f i) ∩ (⋂ i (h : ¬ p i), g i) :=
Inter_dite _ _ _
end
lemma image_projection_prod {ι : Type*} {α : ι → Type*} {v : Π (i : ι), set (α i)}
(hv : (pi univ v).nonempty) (i : ι) :
(λ (x : Π (i : ι), α i), x i) '' (⋂ k, (λ (x : Π (j : ι), α j), x k) ⁻¹' v k) = v i:=
begin
classical,
apply subset.antisymm,
{ simp [Inter_subset] },
{ intros y y_in,
simp only [mem_image, mem_Inter, mem_preimage],
rcases hv with ⟨z, hz⟩,
refine ⟨function.update z i y, _, update_same i y z⟩,
rw @forall_update_iff ι α _ z i y (λ i t, t ∈ v i),
exact ⟨y_in, λ j hj, by simpa using hz j⟩ },
end
/-! ### Unions and intersections indexed by `Prop` -/
@[simp] theorem Inter_false {s : false → set α} : Inter s = univ := infi_false
@[simp] theorem Union_false {s : false → set α} : Union s = ∅ := supr_false
@[simp] theorem Inter_true {s : true → set α} : Inter s = s trivial := infi_true
@[simp] theorem Union_true {s : true → set α} : Union s = s trivial := supr_true
@[simp] theorem Inter_exists {p : ι → Prop} {f : Exists p → set α} :
(⋂ x, f x) = (⋂ i (h : p i), f ⟨i, h⟩) :=
infi_exists
@[simp] theorem Union_exists {p : ι → Prop} {f : Exists p → set α} :
(⋃ x, f x) = (⋃ i (h : p i), f ⟨i, h⟩) :=
supr_exists
@[simp] lemma Union_empty : (⋃ i : ι, ∅ : set α) = ∅ := supr_bot
@[simp] lemma Inter_univ : (⋂ i : ι, univ : set α) = univ := infi_top
section
variables {s : ι → set α}
@[simp] lemma Union_eq_empty : (⋃ i, s i) = ∅ ↔ ∀ i, s i = ∅ := supr_eq_bot
@[simp] lemma Inter_eq_univ : (⋂ i, s i) = univ ↔ ∀ i, s i = univ := infi_eq_top
@[simp] lemma nonempty_Union : (⋃ i, s i).nonempty ↔ ∃ i, (s i).nonempty :=
by simp [← ne_empty_iff_nonempty]
@[simp] lemma nonempty_bUnion {t : set α} {s : α → set β} :
(⋃ i ∈ t, s i).nonempty ↔ ∃ i ∈ t, (s i).nonempty :=
by simp [← ne_empty_iff_nonempty]
lemma Union_nonempty_index (s : set α) (t : s.nonempty → set β) :
(⋃ h, t h) = ⋃ x ∈ s, t ⟨x, ‹_›⟩ :=
supr_exists
end
@[simp] theorem Inter_Inter_eq_left {b : β} {s : Π x : β, x = b → set α} :
(⋂ x (h : x = b), s x h) = s b rfl :=
infi_infi_eq_left
@[simp] theorem Inter_Inter_eq_right {b : β} {s : Π x : β, b = x → set α} :
(⋂ x (h : b = x), s x h) = s b rfl :=
infi_infi_eq_right
@[simp] theorem Union_Union_eq_left {b : β} {s : Π x : β, x = b → set α} :
(⋃ x (h : x = b), s x h) = s b rfl :=
supr_supr_eq_left
@[simp] theorem Union_Union_eq_right {b : β} {s : Π x : β, b = x → set α} :
(⋃ x (h : b = x), s x h) = s b rfl :=
supr_supr_eq_right
theorem Inter_or {p q : Prop} (s : p ∨ q → set α) :
(⋂ h, s h) = (⋂ h : p, s (or.inl h)) ∩ (⋂ h : q, s (or.inr h)) :=
infi_or
theorem Union_or {p q : Prop} (s : p ∨ q → set α) :
(⋃ h, s h) = (⋃ i, s (or.inl i)) ∪ (⋃ j, s (or.inr j)) :=
supr_or
theorem Union_and {p q : Prop} (s : p ∧ q → set α) :
(⋃ h, s h) = ⋃ hp hq, s ⟨hp, hq⟩ :=
supr_and
theorem Inter_and {p q : Prop} (s : p ∧ q → set α) :
(⋂ h, s h) = ⋂ hp hq, s ⟨hp, hq⟩ :=
infi_and
lemma Union_comm (s : ι → ι' → set α) : (⋃ i i', s i i') = ⋃ i' i, s i i' := supr_comm
lemma Inter_comm (s : ι → ι' → set α) : (⋂ i i', s i i') = ⋂ i' i, s i i' := infi_comm
lemma Union₂_comm (s : Π i₁, κ₁ i₁ → Π i₂, κ₂ i₂ → set α) :
(⋃ i₁ j₁ i₂ j₂, s i₁ j₁ i₂ j₂) = ⋃ i₂ j₂ i₁ j₁, s i₁ j₁ i₂ j₂ :=
supr₂_comm _
lemma Inter₂_comm (s : Π i₁, κ₁ i₁ → Π i₂, κ₂ i₂ → set α) :
(⋂ i₁ j₁ i₂ j₂, s i₁ j₁ i₂ j₂) = ⋂ i₂ j₂ i₁ j₁, s i₁ j₁ i₂ j₂ :=
infi₂_comm _
@[simp] theorem bUnion_and (p : ι → Prop) (q : ι → ι' → Prop) (s : Π x y, p x ∧ q x y → set α) :
(⋃ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h) =
⋃ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ :=
by simp only [Union_and, @Union_comm _ ι']
@[simp] theorem bUnion_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : Π x y, p y ∧ q x y → set α) :
(⋃ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h) =
⋃ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ :=
by simp only [Union_and, @Union_comm _ ι]
@[simp] theorem bInter_and (p : ι → Prop) (q : ι → ι' → Prop) (s : Π x y, p x ∧ q x y → set α) :
(⋂ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h) =
⋂ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ :=
by simp only [Inter_and, @Inter_comm _ ι']
@[simp] theorem bInter_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : Π x y, p y ∧ q x y → set α) :
(⋂ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h) =
⋂ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ :=
by simp only [Inter_and, @Inter_comm _ ι]
@[simp] theorem Union_Union_eq_or_left {b : β} {p : β → Prop} {s : Π x : β, (x = b ∨ p x) → set α} :
(⋃ x h, s x h) = s b (or.inl rfl) ∪ ⋃ x (h : p x), s x (or.inr h) :=
by simp only [Union_or, Union_union_distrib, Union_Union_eq_left]
@[simp] theorem Inter_Inter_eq_or_left {b : β} {p : β → Prop} {s : Π x : β, (x = b ∨ p x) → set α} :
(⋂ x h, s x h) = s b (or.inl rfl) ∩ ⋂ x (h : p x), s x (or.inr h) :=
by simp only [Inter_or, Inter_inter_distrib, Inter_Inter_eq_left]
/-! ### Bounded unions and intersections -/
/-- A specialization of `mem_Union₂`. -/
theorem mem_bUnion {s : set α} {t : α → set β} {x : α} {y : β} (xs : x ∈ s) (ytx : y ∈ t x) :
y ∈ ⋃ x ∈ s, t x :=
mem_Union₂_of_mem xs ytx
/-- A specialization of `mem_Inter₂`. -/
theorem mem_bInter {s : set α} {t : α → set β} {y : β} (h : ∀ x ∈ s, y ∈ t x) :
y ∈ ⋂ x ∈ s, t x :=
mem_Inter₂_of_mem h
/-- A specialization of `subset_Union₂`. -/
theorem subset_bUnion_of_mem {s : set α} {u : α → set β} {x : α} (xs : x ∈ s) :
u x ⊆ (⋃ x ∈ s, u x) :=
subset_Union₂ x xs
/-- A specialization of `Inter₂_subset`. -/
theorem bInter_subset_of_mem {s : set α} {t : α → set β} {x : α} (xs : x ∈ s) :
(⋂ x ∈ s, t x) ⊆ t x :=
Inter₂_subset x xs
theorem bUnion_subset_bUnion_left {s s' : set α} {t : α → set β}
(h : s ⊆ s') : (⋃ x ∈ s, t x) ⊆ (⋃ x ∈ s', t x) :=
Union₂_subset $ λ x hx, subset_bUnion_of_mem $ h hx
theorem bInter_subset_bInter_left {s s' : set α} {t : α → set β}
(h : s' ⊆ s) : (⋂ x ∈ s, t x) ⊆ (⋂ x ∈ s', t x) :=
subset_Inter₂ $ λ x hx, bInter_subset_of_mem $ h hx
lemma bUnion_mono {s s' : set α} {t t' : α → set β} (hs : s' ⊆ s) (h : ∀ x ∈ s, t x ⊆ t' x) :
(⋃ x ∈ s', t x) ⊆ ⋃ x ∈ s, t' x :=
(bUnion_subset_bUnion_left hs).trans $ Union₂_mono h
lemma bInter_mono {s s' : set α} {t t' : α → set β} (hs : s ⊆ s') (h : ∀ x ∈ s, t x ⊆ t' x) :
(⋂ x ∈ s', t x) ⊆ (⋂ x ∈ s, t' x) :=
(bInter_subset_bInter_left hs).trans $ Inter₂_mono h
lemma Union_congr {s t : ι → set α} (h : ∀ i, s i = t i) : (⋃ i, s i) = ⋃ i, t i := supr_congr h
lemma Inter_congr {s t : ι → set α} (h : ∀ i, s i = t i) : (⋂ i, s i) = ⋂ i, t i := infi_congr h
lemma Union₂_congr {s t : Π i, κ i → set α} (h : ∀ i j, s i j = t i j) :
(⋃ i j, s i j) = ⋃ i j, t i j :=
Union_congr $ λ i, Union_congr $ h i
lemma Inter₂_congr {s t : Π i, κ i → set α} (h : ∀ i j, s i j = t i j) :
(⋂ i j, s i j) = ⋂ i j, t i j :=
Inter_congr $ λ i, Inter_congr $ h i
theorem bUnion_eq_Union (s : set α) (t : Π x ∈ s, set β) :
(⋃ x ∈ s, t x ‹_›) = (⋃ x : s, t x x.2) :=
supr_subtype'
theorem bInter_eq_Inter (s : set α) (t : Π x ∈ s, set β) :
(⋂ x ∈ s, t x ‹_›) = (⋂ x : s, t x x.2) :=
infi_subtype'
theorem Union_subtype (p : α → Prop) (s : {x // p x} → set β) :
(⋃ x : {x // p x}, s x) = ⋃ x (hx : p x), s ⟨x, hx⟩ :=
supr_subtype
theorem Inter_subtype (p : α → Prop) (s : {x // p x} → set β) :
(⋂ x : {x // p x}, s x) = ⋂ x (hx : p x), s ⟨x, hx⟩ :=
infi_subtype
theorem bInter_empty (u : α → set β) : (⋂ x ∈ (∅ : set α), u x) = univ :=
infi_emptyset
theorem bInter_univ (u : α → set β) : (⋂ x ∈ @univ α, u x) = ⋂ x, u x :=
infi_univ
@[simp] lemma bUnion_self (s : set α) : (⋃ x ∈ s, s) = s :=
subset.antisymm (Union₂_subset $ λ x hx, subset.refl s) (λ x hx, mem_bUnion hx hx)
@[simp] lemma Union_nonempty_self (s : set α) : (⋃ h : s.nonempty, s) = s :=
by rw [Union_nonempty_index, bUnion_self]
-- TODO(Jeremy): here is an artifact of the encoding of bounded intersection:
-- without dsimp, the next theorem fails to type check, because there is a lambda
-- in a type that needs to be contracted. Using simp [eq_of_mem_singleton xa] also works.
theorem bInter_singleton (a : α) (s : α → set β) : (⋂ x ∈ ({a} : set α), s x) = s a :=
infi_singleton
theorem bInter_union (s t : set α) (u : α → set β) :
(⋂ x ∈ s ∪ t, u x) = (⋂ x ∈ s, u x) ∩ (⋂ x ∈ t, u x) :=
infi_union
theorem bInter_insert (a : α) (s : set α) (t : α → set β) :
(⋂ x ∈ insert a s, t x) = t a ∩ (⋂ x ∈ s, t x) :=
by simp
-- TODO(Jeremy): another example of where an annotation is needed
theorem bInter_pair (a b : α) (s : α → set β) :
(⋂ x ∈ ({a, b} : set α), s x) = s a ∩ s b :=
by rw [bInter_insert, bInter_singleton]
lemma bInter_inter {ι α : Type*} {s : set ι} (hs : s.nonempty) (f : ι → set α) (t : set α) :
(⋂ i ∈ s, f i ∩ t) = (⋂ i ∈ s, f i) ∩ t :=
begin
haveI : nonempty s := hs.to_subtype,
simp [bInter_eq_Inter, ← Inter_inter]
end
lemma inter_bInter {ι α : Type*} {s : set ι} (hs : s.nonempty) (f : ι → set α) (t : set α) :
(⋂ i ∈ s, t ∩ f i) = t ∩ ⋂ i ∈ s, f i :=
begin
rw [inter_comm, ← bInter_inter hs],
simp [inter_comm]
end
theorem bUnion_empty (s : α → set β) : (⋃ x ∈ (∅ : set α), s x) = ∅ :=
supr_emptyset
theorem bUnion_univ (s : α → set β) : (⋃ x ∈ @univ α, s x) = ⋃ x, s x :=
supr_univ
theorem bUnion_singleton (a : α) (s : α → set β) : (⋃ x ∈ ({a} : set α), s x) = s a :=
supr_singleton
@[simp] theorem bUnion_of_singleton (s : set α) : (⋃ x ∈ s, {x}) = s :=
ext $ by simp
theorem bUnion_union (s t : set α) (u : α → set β) :
(⋃ x ∈ s ∪ t, u x) = (⋃ x ∈ s, u x) ∪ (⋃ x ∈ t, u x) :=
supr_union
@[simp] lemma Union_coe_set {α β : Type*} (s : set α) (f : s → set β) :
(⋃ i, f i) = ⋃ i ∈ s, f ⟨i, ‹i ∈ s›⟩ :=
Union_subtype _ _
@[simp] lemma Inter_coe_set {α β : Type*} (s : set α) (f : s → set β) :
(⋂ i, f i) = ⋂ i ∈ s, f ⟨i, ‹i ∈ s›⟩ :=
Inter_subtype _ _
theorem bUnion_insert (a : α) (s : set α) (t : α → set β) :
(⋃ x ∈ insert a s, t x) = t a ∪ (⋃ x ∈ s, t x) :=
by simp
theorem bUnion_pair (a b : α) (s : α → set β) :
(⋃ x ∈ ({a, b} : set α), s x) = s a ∪ s b :=
by simp
lemma inter_Union₂ (s : set α) (t : Π i, κ i → set α) : s ∩ (⋃ i j, t i j) = ⋃ i j, s ∩ t i j :=
by simp only [inter_Union]
lemma Union₂_inter (s : Π i, κ i → set α) (t : set α) : (⋃ i j, s i j) ∩ t = ⋃ i j, s i j ∩ t :=
by simp_rw Union_inter
lemma union_Inter₂ (s : set α) (t : Π i, κ i → set α) : s ∪ (⋂ i j, t i j) = ⋂ i j, s ∪ t i j :=
by simp_rw union_Inter
lemma Inter₂_union (s : Π i, κ i → set α) (t : set α) : (⋂ i j, s i j) ∪ t = ⋂ i j, s i j ∪ t :=
by simp_rw Inter_union
theorem mem_sUnion_of_mem {x : α} {t : set α} {S : set (set α)} (hx : x ∈ t) (ht : t ∈ S) :
x ∈ ⋃₀ S :=
⟨t, ht, hx⟩
-- is this theorem really necessary?
theorem not_mem_of_not_mem_sUnion {x : α} {t : set α} {S : set (set α)}
(hx : x ∉ ⋃₀ S) (ht : t ∈ S) : x ∉ t :=
λ h, hx ⟨t, ht, h⟩
theorem sInter_subset_of_mem {S : set (set α)} {t : set α} (tS : t ∈ S) : ⋂₀ S ⊆ t :=
Inf_le tS
theorem subset_sUnion_of_mem {S : set (set α)} {t : set α} (tS : t ∈ S) : t ⊆ ⋃₀ S :=
le_Sup tS
lemma subset_sUnion_of_subset {s : set α} (t : set (set α)) (u : set α) (h₁ : s ⊆ u)
(h₂ : u ∈ t) : s ⊆ ⋃₀ t :=
subset.trans h₁ (subset_sUnion_of_mem h₂)
theorem sUnion_subset {S : set (set α)} {t : set α} (h : ∀ t' ∈ S, t' ⊆ t) : (⋃₀ S) ⊆ t :=
Sup_le h
@[simp] theorem sUnion_subset_iff {s : set (set α)} {t : set α} : ⋃₀ s ⊆ t ↔ ∀ t' ∈ s, t' ⊆ t :=
@Sup_le_iff (set α) _ _ _
theorem subset_sInter {S : set (set α)} {t : set α} (h : ∀ t' ∈ S, t ⊆ t') : t ⊆ (⋂₀ S) :=
le_Inf h
@[simp] theorem subset_sInter_iff {S : set (set α)} {t : set α} : t ⊆ (⋂₀ S) ↔ ∀ t' ∈ S, t ⊆ t' :=
@le_Inf_iff (set α) _ _ _
theorem sUnion_subset_sUnion {S T : set (set α)} (h : S ⊆ T) : ⋃₀ S ⊆ ⋃₀ T :=
sUnion_subset $ λ s hs, subset_sUnion_of_mem (h hs)
theorem sInter_subset_sInter {S T : set (set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S :=
subset_sInter $ λ s hs, sInter_subset_of_mem (h hs)
@[simp] theorem sUnion_empty : ⋃₀ ∅ = (∅ : set α) := Sup_empty
@[simp] theorem sInter_empty : ⋂₀ ∅ = (univ : set α) := Inf_empty
@[simp] theorem sUnion_singleton (s : set α) : ⋃₀ {s} = s := Sup_singleton
@[simp] theorem sInter_singleton (s : set α) : ⋂₀ {s} = s := Inf_singleton
@[simp] theorem sUnion_eq_empty {S : set (set α)} : (⋃₀ S) = ∅ ↔ ∀ s ∈ S, s = ∅ := Sup_eq_bot
@[simp] theorem sInter_eq_univ {S : set (set α)} : (⋂₀ S) = univ ↔ ∀ s ∈ S, s = univ := Inf_eq_top
@[simp] theorem nonempty_sUnion {S : set (set α)} : (⋃₀ S).nonempty ↔ ∃ s ∈ S, set.nonempty s :=
by simp [← ne_empty_iff_nonempty]
lemma nonempty.of_sUnion {s : set (set α)} (h : (⋃₀ s).nonempty) : s.nonempty :=
let ⟨s, hs, _⟩ := nonempty_sUnion.1 h in ⟨s, hs⟩
lemma nonempty.of_sUnion_eq_univ [nonempty α] {s : set (set α)} (h : ⋃₀ s = univ) : s.nonempty :=
nonempty.of_sUnion $ h.symm ▸ univ_nonempty
theorem sUnion_union (S T : set (set α)) : ⋃₀ (S ∪ T) = ⋃₀ S ∪ ⋃₀ T := Sup_union
theorem sInter_union (S T : set (set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T := Inf_union
@[simp] theorem sUnion_insert (s : set α) (T : set (set α)) : ⋃₀ (insert s T) = s ∪ ⋃₀ T :=
Sup_insert
@[simp] theorem sInter_insert (s : set α) (T : set (set α)) : ⋂₀ (insert s T) = s ∩ ⋂₀ T :=
Inf_insert
@[simp] lemma sUnion_diff_singleton_empty (s : set (set α)) : ⋃₀ (s \ {∅}) = ⋃₀ s :=
Sup_diff_singleton_bot s
@[simp] lemma sInter_diff_singleton_univ (s : set (set α)) : ⋂₀ (s \ {univ}) = ⋂₀ s :=
Inf_diff_singleton_top s
theorem sUnion_pair (s t : set α) : ⋃₀ {s, t} = s ∪ t :=
Sup_pair
theorem sInter_pair (s t : set α) : ⋂₀ {s, t} = s ∩ t :=
Inf_pair
@[simp] theorem sUnion_image (f : α → set β) (s : set α) : ⋃₀ (f '' s) = ⋃ x ∈ s, f x := Sup_image
@[simp] theorem sInter_image (f : α → set β) (s : set α) : ⋂₀ (f '' s) = ⋂ x ∈ s, f x := Inf_image
@[simp] theorem sUnion_range (f : ι → set β) : ⋃₀ (range f) = ⋃ x, f x := rfl
@[simp] theorem sInter_range (f : ι → set β) : ⋂₀ (range f) = ⋂ x, f x := rfl
lemma Union_eq_univ_iff {f : ι → set α} : (⋃ i, f i) = univ ↔ ∀ x, ∃ i, x ∈ f i :=
by simp only [eq_univ_iff_forall, mem_Union]
lemma Union₂_eq_univ_iff {s : Π i, κ i → set α} : (⋃ i j, s i j) = univ ↔ ∀ a, ∃ i j, a ∈ s i j :=
by simp only [Union_eq_univ_iff, mem_Union]
lemma sUnion_eq_univ_iff {c : set (set α)} :
⋃₀ c = univ ↔ ∀ a, ∃ b ∈ c, a ∈ b :=
by simp only [eq_univ_iff_forall, mem_sUnion]
-- classical
lemma Inter_eq_empty_iff {f : ι → set α} : (⋂ i, f i) = ∅ ↔ ∀ x, ∃ i, x ∉ f i :=
by simp [set.eq_empty_iff_forall_not_mem]
-- classical
lemma Inter₂_eq_empty_iff {s : Π i, κ i → set α} : (⋂ i j, s i j) = ∅ ↔ ∀ a, ∃ i j, a ∉ s i j :=
by simp only [eq_empty_iff_forall_not_mem, mem_Inter, not_forall]
-- classical
lemma sInter_eq_empty_iff {c : set (set α)} :
⋂₀ c = ∅ ↔ ∀ a, ∃ b ∈ c, a ∉ b :=
by simp [set.eq_empty_iff_forall_not_mem]
-- classical
@[simp] theorem nonempty_Inter {f : ι → set α} : (⋂ i, f i).nonempty ↔ ∃ x, ∀ i, x ∈ f i :=
by simp [← ne_empty_iff_nonempty, Inter_eq_empty_iff]
-- classical
@[simp] lemma nonempty_Inter₂ {s : Π i, κ i → set α} :
(⋂ i j, s i j).nonempty ↔ ∃ a, ∀ i j, a ∈ s i j :=
by simp [← ne_empty_iff_nonempty, Inter_eq_empty_iff]
-- classical
@[simp] theorem nonempty_sInter {c : set (set α)}:
(⋂₀ c).nonempty ↔ ∃ a, ∀ b ∈ c, a ∈ b :=
by simp [← ne_empty_iff_nonempty, sInter_eq_empty_iff]
-- classical
theorem compl_sUnion (S : set (set α)) :
(⋃₀ S)ᶜ = ⋂₀ (compl '' S) :=
ext $ λ x, by simp
-- classical
theorem sUnion_eq_compl_sInter_compl (S : set (set α)) :
⋃₀ S = (⋂₀ (compl '' S))ᶜ :=
by rw [←compl_compl (⋃₀ S), compl_sUnion]
-- classical
theorem compl_sInter (S : set (set α)) :
(⋂₀ S)ᶜ = ⋃₀ (compl '' S) :=
by rw [sUnion_eq_compl_sInter_compl, compl_compl_image]
-- classical
theorem sInter_eq_compl_sUnion_compl (S : set (set α)) :
⋂₀ S = (⋃₀ (compl '' S))ᶜ :=
by rw [←compl_compl (⋂₀ S), compl_sInter]
theorem inter_empty_of_inter_sUnion_empty {s t : set α} {S : set (set α)} (hs : t ∈ S)
(h : s ∩ ⋃₀ S = ∅) :
s ∩ t = ∅ :=
eq_empty_of_subset_empty $ by rw ← h; exact
inter_subset_inter_right _ (subset_sUnion_of_mem hs)
theorem range_sigma_eq_Union_range {γ : α → Type*} (f : sigma γ → β) :
range f = ⋃ a, range (λ b, f ⟨a, b⟩) :=
set.ext $ by simp
theorem Union_eq_range_sigma (s : α → set β) : (⋃ i, s i) = range (λ a : Σ i, s i, a.2) :=
by simp [set.ext_iff]
theorem Union_eq_range_psigma (s : ι → set β) : (⋃ i, s i) = range (λ a : Σ' i, s i, a.2) :=
by simp [set.ext_iff]
theorem Union_image_preimage_sigma_mk_eq_self {ι : Type*} {σ : ι → Type*} (s : set (sigma σ)) :
(⋃ i, sigma.mk i '' (sigma.mk i ⁻¹' s)) = s :=
begin
ext x,
simp only [mem_Union, mem_image, mem_preimage],
split,
{ rintro ⟨i, a, h, rfl⟩, exact h },
{ intro h, cases x with i a, exact ⟨i, a, h, rfl⟩ }
end
lemma sigma.univ (X : α → Type*) : (set.univ : set (Σ a, X a)) = ⋃ a, range (sigma.mk a) :=
set.ext $ λ x, iff_of_true trivial ⟨range (sigma.mk x.1), set.mem_range_self _, x.2, sigma.eta x⟩
lemma sUnion_mono {s t : set (set α)} (h : s ⊆ t) : (⋃₀ s) ⊆ (⋃₀ t) :=
sUnion_subset $ λ t' ht', subset_sUnion_of_mem $ h ht'
lemma Union_subset_Union_const {s : set α} (h : ι → ι₂) : (⋃ i : ι, s) ⊆ (⋃ j : ι₂, s) :=
@supr_const_mono (set α) ι ι₂ _ s h
@[simp] lemma Union_singleton_eq_range {α β : Type*} (f : α → β) :
(⋃ (x : α), {f x}) = range f :=
by { ext x, simp [@eq_comm _ x] }
lemma Union_of_singleton (α : Type*) : (⋃ x, {x} : set α) = univ :=
by simp
lemma Union_of_singleton_coe (s : set α) :
(⋃ (i : s), {i} : set α) = s :=
by simp
lemma sUnion_eq_bUnion {s : set (set α)} : (⋃₀ s) = (⋃ (i : set α) (h : i ∈ s), i) :=
by rw [← sUnion_image, image_id']
lemma sInter_eq_bInter {s : set (set α)} : (⋂₀ s) = (⋂ (i : set α) (h : i ∈ s), i) :=
by rw [← sInter_image, image_id']
lemma sUnion_eq_Union {s : set (set α)} : (⋃₀ s) = (⋃ (i : s), i) :=
by simp only [←sUnion_range, subtype.range_coe]
lemma sInter_eq_Inter {s : set (set α)} : (⋂₀ s) = (⋂ (i : s), i) :=
by simp only [←sInter_range, subtype.range_coe]
lemma union_eq_Union {s₁ s₂ : set α} : s₁ ∪ s₂ = ⋃ b : bool, cond b s₁ s₂ :=
sup_eq_supr s₁ s₂
lemma inter_eq_Inter {s₁ s₂ : set α} : s₁ ∩ s₂ = ⋂ b : bool, cond b s₁ s₂ :=
inf_eq_infi s₁ s₂
lemma sInter_union_sInter {S T : set (set α)} :
(⋂₀ S) ∪ (⋂₀ T) = (⋂ p ∈ S ×ˢ T, (p : (set α) × (set α)).1 ∪ p.2) :=
Inf_sup_Inf
lemma sUnion_inter_sUnion {s t : set (set α)} :
(⋃₀ s) ∩ (⋃₀ t) = (⋃ p ∈ s ×ˢ t, (p : (set α) × (set α )).1 ∩ p.2) :=
Sup_inf_Sup
lemma bUnion_Union (s : ι → set α) (t : α → set β) :
(⋃ x ∈ ⋃ i, s i, t x) = ⋃ i (x ∈ s i), t x :=
by simp [@Union_comm _ ι]
lemma bInter_Union (s : ι → set α) (t : α → set β) :
(⋂ x ∈ ⋃ i, s i, t x) = ⋂ i (x ∈ s i), t x :=
by simp [@Inter_comm _ ι]
lemma sUnion_Union (s : ι → set (set α)) : ⋃₀ (⋃ i, s i) = ⋃ i, ⋃₀ (s i) :=
by simp only [sUnion_eq_bUnion, bUnion_Union]
theorem sInter_Union (s : ι → set (set α)) : ⋂₀ (⋃ i, s i) = ⋂ i, ⋂₀ s i :=
by simp only [sInter_eq_bInter, bInter_Union]
lemma Union_range_eq_sUnion {α β : Type*} (C : set (set α))
{f : ∀ (s : C), β → s} (hf : ∀ (s : C), surjective (f s)) :
(⋃ (y : β), range (λ (s : C), (f s y).val)) = ⋃₀ C :=
begin
ext x, split,
{ rintro ⟨s, ⟨y, rfl⟩, ⟨s, hs⟩, rfl⟩, refine ⟨_, hs, _⟩, exact (f ⟨s, hs⟩ y).2 },
{ rintro ⟨s, hs, hx⟩, cases hf ⟨s, hs⟩ ⟨x, hx⟩ with y hy, refine ⟨_, ⟨y, rfl⟩, ⟨s, hs⟩, _⟩,
exact congr_arg subtype.val hy }
end
lemma Union_range_eq_Union (C : ι → set α) {f : ∀ (x : ι), β → C x}
(hf : ∀ (x : ι), surjective (f x)) :
(⋃ (y : β), range (λ (x : ι), (f x y).val)) = ⋃ x, C x :=
begin
ext x, rw [mem_Union, mem_Union], split,
{ rintro ⟨y, i, rfl⟩, exact ⟨i, (f i y).2⟩ },
{ rintro ⟨i, hx⟩, cases hf i ⟨x, hx⟩ with y hy,
exact ⟨y, i, congr_arg subtype.val hy⟩ }
end
lemma union_distrib_Inter_left (s : ι → set α) (t : set α) : t ∪ (⋂ i, s i) = (⋂ i, t ∪ s i) :=
sup_infi_eq _ _
lemma union_distrib_Inter₂_left (s : set α) (t : Π i, κ i → set α) :
s ∪ (⋂ i j, t i j) = ⋂ i j, s ∪ t i j :=
by simp_rw union_distrib_Inter_left
lemma union_distrib_Inter_right (s : ι → set α) (t : set α) : (⋂ i, s i) ∪ t = (⋂ i, s i ∪ t) :=
infi_sup_eq _ _
lemma union_distrib_Inter₂_right (s : Π i, κ i → set α) (t : set α) :
(⋂ i j, s i j) ∪ t = ⋂ i j, s i j ∪ t :=
by simp_rw union_distrib_Inter_right
section function
/-! ### `maps_to` -/
lemma maps_to_sUnion {S : set (set α)} {t : set β} {f : α → β} (H : ∀ s ∈ S, maps_to f s t) :
maps_to f (⋃₀ S) t :=
λ x ⟨s, hs, hx⟩, H s hs hx
lemma maps_to_Union {s : ι → set α} {t : set β} {f : α → β} (H : ∀ i, maps_to f (s i) t) :
maps_to f (⋃ i, s i) t :=
maps_to_sUnion $ forall_range_iff.2 H
lemma maps_to_Union₂ {s : Π i, κ i → set α} {t : set β} {f : α → β}
(H : ∀ i j, maps_to f (s i j) t) :
maps_to f (⋃ i j, s i j) t :=
maps_to_Union $ λ i, maps_to_Union (H i)
lemma maps_to_Union_Union {s : ι → set α} {t : ι → set β} {f : α → β}
(H : ∀ i, maps_to f (s i) (t i)) :
maps_to f (⋃ i, s i) (⋃ i, t i) :=
maps_to_Union $ λ i, (H i).mono (subset.refl _) (subset_Union t i)
lemma maps_to_Union₂_Union₂ {s : Π i, κ i → set α} {t : Π i, κ i → set β} {f : α → β}
(H : ∀ i j, maps_to f (s i j) (t i j)) :
maps_to f (⋃ i j, s i j) (⋃ i j, t i j) :=
maps_to_Union_Union $ λ i, maps_to_Union_Union (H i)
lemma maps_to_sInter {s : set α} {T : set (set β)} {f : α → β} (H : ∀ t ∈ T, maps_to f s t) :
maps_to f s (⋂₀ T) :=
λ x hx t ht, H t ht hx
lemma maps_to_Inter {s : set α} {t : ι → set β} {f : α → β} (H : ∀ i, maps_to f s (t i)) :
maps_to f s (⋂ i, t i) :=
λ x hx, mem_Inter.2 $ λ i, H i hx
lemma maps_to_Inter₂ {s : set α} {t : Π i, κ i → set β} {f : α → β}
(H : ∀ i j, maps_to f s (t i j)) :
maps_to f s (⋂ i j, t i j) :=
maps_to_Inter $ λ i, maps_to_Inter (H i)
lemma maps_to_Inter_Inter {s : ι → set α} {t : ι → set β} {f : α → β}
(H : ∀ i, maps_to f (s i) (t i)) :
maps_to f (⋂ i, s i) (⋂ i, t i) :=
maps_to_Inter $ λ i, (H i).mono (Inter_subset s i) (subset.refl _)
lemma maps_to_Inter₂_Inter₂ {s : Π i, κ i → set α} {t : Π i, κ i → set β} {f : α → β}
(H : ∀ i j, maps_to f (s i j) (t i j)) :
maps_to f (⋂ i j, s i j) (⋂ i j, t i j) :=
maps_to_Inter_Inter $ λ i, maps_to_Inter_Inter (H i)
lemma image_Inter_subset (s : ι → set α) (f : α → β) :
f '' (⋂ i, s i) ⊆ ⋂ i, f '' (s i) :=
(maps_to_Inter_Inter $ λ i, maps_to_image f (s i)).image_subset
lemma image_Inter₂_subset (s : Π i, κ i → set α) (f : α → β) :
f '' (⋂ i j, s i j) ⊆ ⋂ i j, f '' s i j :=
(maps_to_Inter₂_Inter₂ $ λ i hi, maps_to_image f (s i hi)).image_subset
lemma image_sInter_subset (S : set (set α)) (f : α → β) :
f '' (⋂₀ S) ⊆ ⋂ s ∈ S, f '' s :=
by { rw sInter_eq_bInter, apply image_Inter₂_subset }
/-! ### `restrict_preimage` -/
section
open function
variables (s : set β) {f : α → β} {U : ι → set β} (hU : Union U = univ)
lemma restrict_preimage_injective (hf : injective f) : injective (s.restrict_preimage f) :=
λ x y e, subtype.mk.inj_arrow e (λ e, subtype.coe_injective (hf e))
lemma restrict_preimage_surjective (hf : surjective f) : surjective (s.restrict_preimage f) :=
λ x, ⟨⟨_, (show f (hf x).some ∈ s, from (hf x).some_spec.symm ▸ x.2)⟩, subtype.ext (hf x).some_spec⟩
lemma restrict_preimage_bijective (hf : bijective f) : bijective (s.restrict_preimage f) :=
⟨s.restrict_preimage_injective hf.1, s.restrict_preimage_surjective hf.2⟩
alias set.restrict_preimage_injective ← _root_.function.injective.restrict_preimage
alias set.restrict_preimage_surjective ← _root_.function.surjective.restrict_preimage
alias set.restrict_preimage_bijective ← _root_.function.bijective.restrict_preimage
include hU
lemma injective_iff_injective_of_Union_eq_univ :
injective f ↔ ∀ i, injective ((U i).restrict_preimage f) :=
begin
refine ⟨λ H i, (U i).restrict_preimage_injective H, λ H x y e, _⟩,
obtain ⟨i, hi⟩ := set.mem_Union.mp (show f x ∈ set.Union U, by { rw hU, triv }),
injection @H i ⟨x, hi⟩ ⟨y, show f y ∈ U i, from e ▸ hi⟩ (subtype.ext e)
end
lemma surjective_iff_surjective_of_Union_eq_univ :
surjective f ↔ ∀ i, surjective ((U i).restrict_preimage f) :=
begin
refine ⟨λ H i, (U i).restrict_preimage_surjective H, λ H x, _⟩,
obtain ⟨i, hi⟩ := set.mem_Union.mp (show x ∈ set.Union U, by { rw hU, triv }),
exact ⟨_, congr_arg subtype.val (H i ⟨x, hi⟩).some_spec⟩
end
lemma bijective_iff_bijective_of_Union_eq_univ :
bijective f ↔ ∀ i, bijective ((U i).restrict_preimage f) :=
by simp_rw [bijective, forall_and_distrib, injective_iff_injective_of_Union_eq_univ hU,
surjective_iff_surjective_of_Union_eq_univ hU]
end
/-! ### `inj_on` -/
lemma inj_on.image_inter {f : α → β} {s t u : set α} (hf : inj_on f u) (hs : s ⊆ u) (ht : t ⊆ u) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
begin
apply subset.antisymm (image_inter_subset _ _ _),
rintros x ⟨⟨y, ys, hy⟩, ⟨z, zt, hz⟩⟩,
have : y = z,
{ apply hf (hs ys) (ht zt),
rwa ← hz at hy },
rw ← this at zt,
exact ⟨y, ⟨ys, zt⟩, hy⟩,
end
lemma inj_on.image_Inter_eq [nonempty ι] {s : ι → set α} {f : α → β} (h : inj_on f (⋃ i, s i)) :
f '' (⋂ i, s i) = ⋂ i, f '' (s i) :=
begin
inhabit ι,
refine subset.antisymm (image_Inter_subset s f) (λ y hy, _),
simp only [mem_Inter, mem_image_iff_bex] at hy,
choose x hx hy using hy,
refine ⟨x default, mem_Inter.2 $ λ i, _, hy _⟩,
suffices : x default = x i,
{ rw this, apply hx },
replace hx : ∀ i, x i ∈ ⋃ j, s j := λ i, (subset_Union _ _) (hx i),
apply h (hx _) (hx _),
simp only [hy]
end
lemma inj_on.image_bInter_eq {p : ι → Prop} {s : Π i (hi : p i), set α} (hp : ∃ i, p i) {f : α → β}
(h : inj_on f (⋃ i hi, s i hi)) :
f '' (⋂ i hi, s i hi) = ⋂ i hi, f '' (s i hi) :=
begin
simp only [Inter, infi_subtype'],
haveI : nonempty {i // p i} := nonempty_subtype.2 hp,
apply inj_on.image_Inter_eq,
simpa only [Union, supr_subtype'] using h
end
lemma inj_on_Union_of_directed {s : ι → set α} (hs : directed (⊆) s)
{f : α → β} (hf : ∀ i, inj_on f (s i)) :
inj_on f (⋃ i, s i) :=
begin
intros x hx y hy hxy,
rcases mem_Union.1 hx with ⟨i, hx⟩,
rcases mem_Union.1 hy with ⟨j, hy⟩,
rcases hs i j with ⟨k, hi, hj⟩,
exact hf k (hi hx) (hj hy) hxy
end
/-! ### `surj_on` -/
lemma surj_on_sUnion {s : set α} {T : set (set β)} {f : α → β} (H : ∀ t ∈ T, surj_on f s t) :
surj_on f s (⋃₀ T) :=
λ x ⟨t, ht, hx⟩, H t ht hx
lemma surj_on_Union {s : set α} {t : ι → set β} {f : α → β} (H : ∀ i, surj_on f s (t i)) :
surj_on f s (⋃ i, t i) :=
surj_on_sUnion $ forall_range_iff.2 H
lemma surj_on_Union_Union {s : ι → set α} {t : ι → set β} {f : α → β}
(H : ∀ i, surj_on f (s i) (t i)) :
surj_on f (⋃ i, s i) (⋃ i, t i) :=
surj_on_Union $ λ i, (H i).mono (subset_Union _ _) (subset.refl _)
lemma surj_on_Union₂ {s : set α} {t : Π i, κ i → set β} {f : α → β}
(H : ∀ i j, surj_on f s (t i j)) :
surj_on f s (⋃ i j, t i j) :=
surj_on_Union $ λ i, surj_on_Union (H i)
lemma surj_on_Union₂_Union₂ {s : Π i, κ i → set α} {t : Π i, κ i → set β} {f : α → β}
(H : ∀ i j, surj_on f (s i j) (t i j)) :
surj_on f (⋃ i j, s i j) (⋃ i j, t i j) :=
surj_on_Union_Union $ λ i, surj_on_Union_Union (H i)
lemma surj_on_Inter [hi : nonempty ι] {s : ι → set α} {t : set β} {f : α → β}
(H : ∀ i, surj_on f (s i) t) (Hinj : inj_on f (⋃ i, s i)) :
surj_on f (⋂ i, s i) t :=
begin
intros y hy,
rw [Hinj.image_Inter_eq, mem_Inter],
exact λ i, H i hy
end
lemma surj_on_Inter_Inter [hi : nonempty ι] {s : ι → set α} {t : ι → set β} {f : α → β}
(H : ∀ i, surj_on f (s i) (t i)) (Hinj : inj_on f (⋃ i, s i)) :
surj_on f (⋂ i, s i) (⋂ i, t i) :=
surj_on_Inter (λ i, (H i).mono (subset.refl _) (Inter_subset _ _)) Hinj
/-! ### `bij_on` -/
lemma bij_on_Union {s : ι → set α} {t : ι → set β} {f : α → β} (H : ∀ i, bij_on f (s i) (t i))
(Hinj : inj_on f (⋃ i, s i)) :
bij_on f (⋃ i, s i) (⋃ i, t i) :=
⟨maps_to_Union_Union $ λ i, (H i).maps_to, Hinj, surj_on_Union_Union $ λ i, (H i).surj_on⟩
lemma bij_on_Inter [hi :nonempty ι] {s : ι → set α} {t : ι → set β} {f : α → β}
(H : ∀ i, bij_on f (s i) (t i)) (Hinj : inj_on f (⋃ i, s i)) :
bij_on f (⋂ i, s i) (⋂ i, t i) :=
⟨maps_to_Inter_Inter $ λ i, (H i).maps_to, hi.elim $ λ i, (H i).inj_on.mono (Inter_subset _ _),
surj_on_Inter_Inter (λ i, (H i).surj_on) Hinj⟩
lemma bij_on_Union_of_directed {s : ι → set α} (hs : directed (⊆) s) {t : ι → set β} {f : α → β}
(H : ∀ i, bij_on f (s i) (t i)) :
bij_on f (⋃ i, s i) (⋃ i, t i) :=
bij_on_Union H $ inj_on_Union_of_directed hs (λ i, (H i).inj_on)
lemma bij_on_Inter_of_directed [nonempty ι] {s : ι → set α} (hs : directed (⊆) s) {t : ι → set β}
{f : α → β} (H : ∀ i, bij_on f (s i) (t i)) :
bij_on f (⋂ i, s i) (⋂ i, t i) :=
bij_on_Inter H $ inj_on_Union_of_directed hs (λ i, (H i).inj_on)
end function
/-! ### `image`, `preimage` -/
section image
lemma image_Union {f : α → β} {s : ι → set α} : f '' (⋃ i, s i) = (⋃ i, f '' s i) :=
begin
ext1 x,
simp [image, ← exists_and_distrib_right, @exists_swap α]
end
lemma image_Union₂ (f : α → β) (s : Π i, κ i → set α) : f '' (⋃ i j, s i j) = ⋃ i j, f '' s i j :=
by simp_rw image_Union
lemma univ_subtype {p : α → Prop} : (univ : set (subtype p)) = (⋃ x (h : p x), {⟨x, h⟩}) :=
set.ext $ λ ⟨x, h⟩, by simp [h]
lemma range_eq_Union {ι} (f : ι → α) : range f = (⋃ i, {f i}) :=
set.ext $ λ a, by simp [@eq_comm α a]
lemma image_eq_Union (f : α → β) (s : set α) : f '' s = (⋃ i ∈ s, {f i}) :=
set.ext $ λ b, by simp [@eq_comm β b]
lemma bUnion_range {f : ι → α} {g : α → set β} : (⋃ x ∈ range f, g x) = (⋃ y, g (f y)) :=
supr_range
@[simp] lemma Union_Union_eq' {f : ι → α} {g : α → set β} :
(⋃ x y (h : f y = x), g x) = ⋃ y, g (f y) :=
by simpa using bUnion_range
lemma bInter_range {f : ι → α} {g : α → set β} : (⋂ x ∈ range f, g x) = (⋂ y, g (f y)) :=
infi_range
@[simp] lemma Inter_Inter_eq' {f : ι → α} {g : α → set β} :
(⋂ x y (h : f y = x), g x) = ⋂ y, g (f y) :=
by simpa using bInter_range
variables {s : set γ} {f : γ → α} {g : α → set β}
lemma bUnion_image : (⋃ x ∈ f '' s, g x) = (⋃ y ∈ s, g (f y)) :=
supr_image
lemma bInter_image : (⋂ x ∈ f '' s, g x) = (⋂ y ∈ s, g (f y)) :=
infi_image
end image
section preimage
theorem monotone_preimage {f : α → β} : monotone (preimage f) := λ a b h, preimage_mono h
@[simp] lemma preimage_Union {f : α → β} {s : ι → set β} : f ⁻¹' (⋃ i, s i) = (⋃ i, f ⁻¹' s i) :=
set.ext $ by simp [preimage]
lemma preimage_Union₂ {f : α → β} {s : Π i, κ i → set β} :
f ⁻¹' (⋃ i j, s i j) = ⋃ i j, f ⁻¹' s i j :=
by simp_rw preimage_Union
@[simp] theorem preimage_sUnion {f : α → β} {s : set (set β)} :
f ⁻¹' (⋃₀ s) = (⋃ t ∈ s, f ⁻¹' t) :=
by rw [sUnion_eq_bUnion, preimage_Union₂]
lemma preimage_Inter {f : α → β} {s : ι → set β} : f ⁻¹' (⋂ i, s i) = (⋂ i, f ⁻¹' s i) :=
by ext; simp
lemma preimage_Inter₂ {f : α → β} {s : Π i, κ i → set β} :
f ⁻¹' (⋂ i j, s i j) = ⋂ i j, f ⁻¹' s i j :=
by simp_rw preimage_Inter
@[simp] lemma preimage_sInter {f : α → β} {s : set (set β)} : f ⁻¹' (⋂₀ s) = ⋂ t ∈ s, f ⁻¹' t :=
by rw [sInter_eq_bInter, preimage_Inter₂]
@[simp] lemma bUnion_preimage_singleton (f : α → β) (s : set β) : (⋃ y ∈ s, f ⁻¹' {y}) = f ⁻¹' s :=
by rw [← preimage_Union₂, bUnion_of_singleton]
lemma bUnion_range_preimage_singleton (f : α → β) : (⋃ y ∈ range f, f ⁻¹' {y}) = univ :=
by rw [bUnion_preimage_singleton, preimage_range]
end preimage
section prod
lemma prod_Union {s : set α} {t : ι → set β} : s ×ˢ (⋃ i, t i) = ⋃ i, s ×ˢ (t i) := by { ext, simp }
lemma prod_Union₂ {s : set α} {t : Π i, κ i → set β} : s ×ˢ (⋃ i j, t i j) = ⋃ i j, s ×ˢ t i j :=
by simp_rw [prod_Union]
lemma prod_sUnion {s : set α} {C : set (set β)} : s ×ˢ (⋃₀ C) = ⋃₀ ((λ t, s ×ˢ t) '' C) :=
by simp_rw [sUnion_eq_bUnion, bUnion_image, prod_Union₂]
lemma Union_prod_const {s : ι → set α} {t : set β} : (⋃ i, s i) ×ˢ t = ⋃ i, s i ×ˢ t :=
by { ext, simp }
lemma Union₂_prod_const {s : Π i, κ i → set α} {t : set β} :
(⋃ i j, s i j) ×ˢ t = ⋃ i j, s i j ×ˢ t :=
by simp_rw [Union_prod_const]
lemma sUnion_prod_const {C : set (set α)} {t : set β} :
(⋃₀ C) ×ˢ t = ⋃₀ ((λ s : set α, s ×ˢ t) '' C) :=
by simp only [sUnion_eq_bUnion, Union₂_prod_const, bUnion_image]
lemma Union_prod {ι ι' α β} (s : ι → set α) (t : ι' → set β) :
(⋃ (x : ι × ι'), s x.1 ×ˢ t x.2) = (⋃ (i : ι), s i) ×ˢ (⋃ (i : ι'), t i) :=
by { ext, simp }
lemma Union_prod_of_monotone [semilattice_sup α] {s : α → set β} {t : α → set γ}
(hs : monotone s) (ht : monotone t) : (⋃ x, s x ×ˢ t x) = (⋃ x, s x) ×ˢ (⋃ x, t x) :=
begin
ext ⟨z, w⟩, simp only [mem_prod, mem_Union, exists_imp_distrib, and_imp, iff_def], split,
{ intros x hz hw, exact ⟨⟨x, hz⟩, x, hw⟩ },
{ intros x hz x' hw, exact ⟨x ⊔ x', hs le_sup_left hz, ht le_sup_right hw⟩ }
end
end prod
section image2
variables (f : α → β → γ) {s : set α} {t : set β}
lemma Union_image_left : (⋃ a ∈ s, f a '' t) = image2 f s t :=
by { ext y, split; simp only [mem_Union]; rintro ⟨a, ha, x, hx, ax⟩; exact ⟨a, x, ha, hx, ax⟩ }
lemma Union_image_right : (⋃ b ∈ t, (λ a, f a b) '' s) = image2 f s t :=
by { ext y, split; simp only [mem_Union]; rintro ⟨a, b, c, d, e⟩, exact ⟨c, a, d, b, e⟩,
exact ⟨b, d, a, c, e⟩ }
lemma image2_Union_left (s : ι → set α) (t : set β) :
image2 f (⋃ i, s i) t = ⋃ i, image2 f (s i) t :=
by simp only [← image_prod, Union_prod_const, image_Union]
lemma image2_Union_right (s : set α) (t : ι → set β) :
image2 f s (⋃ i, t i) = ⋃ i, image2 f s (t i) :=
by simp only [← image_prod, prod_Union, image_Union]
lemma image2_Union₂_left (s : Π i, κ i → set α) (t : set β) :
image2 f (⋃ i j, s i j) t = ⋃ i j, image2 f (s i j) t :=
by simp_rw image2_Union_left
lemma image2_Union₂_right (s : set α) (t : Π i, κ i → set β) :
image2 f s (⋃ i j, t i j) = ⋃ i j, image2 f s (t i j) :=
by simp_rw image2_Union_right
lemma image2_Inter_subset_left (s : ι → set α) (t : set β) :
image2 f (⋂ i, s i) t ⊆ ⋂ i, image2 f (s i) t :=
by { simp_rw [image2_subset_iff, mem_Inter], exact λ x hx y hy i, mem_image2_of_mem (hx _) hy }
lemma image2_Inter_subset_right (s : set α) (t : ι → set β) :
image2 f s (⋂ i, t i) ⊆ ⋂ i, image2 f s (t i) :=
by { simp_rw [image2_subset_iff, mem_Inter], exact λ x hx y hy i, mem_image2_of_mem hx (hy _) }
lemma image2_Inter₂_subset_left (s : Π i, κ i → set α) (t : set β) :
image2 f (⋂ i j, s i j) t ⊆ ⋂ i j, image2 f (s i j) t :=
by { simp_rw [image2_subset_iff, mem_Inter], exact λ x hx y hy i j, mem_image2_of_mem (hx _ _) hy }
lemma image2_Inter₂_subset_right (s : set α) (t : Π i, κ i → set β) :
image2 f s (⋂ i j, t i j) ⊆ ⋂ i j, image2 f s (t i j) :=
by { simp_rw [image2_subset_iff, mem_Inter], exact λ x hx y hy i j, mem_image2_of_mem hx (hy _ _) }
/-- The `set.image2` version of `set.image_eq_Union` -/
lemma image2_eq_Union (s : set α) (t : set β) : image2 f s t = ⋃ (i ∈ s) (j ∈ t), {f i j} :=
by simp_rw [←image_eq_Union, Union_image_left]
lemma prod_eq_bUnion_left : s ×ˢ t = ⋃ a ∈ s, (λ b, (a, b)) '' t :=
by rw [Union_image_left, image2_mk_eq_prod]
lemma prod_eq_bUnion_right : s ×ˢ t = ⋃ b ∈ t, (λ a, (a, b)) '' s :=
by rw [Union_image_right, image2_mk_eq_prod]
end image2
section seq
/-- Given a set `s` of functions `α → β` and `t : set α`, `seq s t` is the union of `f '' t` over
all `f ∈ s`. -/
def seq (s : set (α → β)) (t : set α) : set β := {b | ∃ f ∈ s, ∃ a ∈ t, (f : α → β) a = b}
lemma seq_def {s : set (α → β)} {t : set α} : seq s t = ⋃ f ∈ s, f '' t :=
set.ext $ by simp [seq]
@[simp] lemma mem_seq_iff {s : set (α → β)} {t : set α} {b : β} :
b ∈ seq s t ↔ ∃ (f ∈ s) (a ∈ t), (f : α → β) a = b :=
iff.rfl
lemma seq_subset {s : set (α → β)} {t : set α} {u : set β} :
seq s t ⊆ u ↔ (∀ f ∈ s, ∀ a ∈ t, (f : α → β) a ∈ u) :=
iff.intro
(λ h f hf a ha, h ⟨f, hf, a, ha, rfl⟩)
(λ h b ⟨f, hf, a, ha, eq⟩, eq ▸ h f hf a ha)
lemma seq_mono {s₀ s₁ : set (α → β)} {t₀ t₁ : set α} (hs : s₀ ⊆ s₁) (ht : t₀ ⊆ t₁) :
seq s₀ t₀ ⊆ seq s₁ t₁ :=
λ b ⟨f, hf, a, ha, eq⟩, ⟨f, hs hf, a, ht ha, eq⟩
lemma singleton_seq {f : α → β} {t : set α} : set.seq {f} t = f '' t :=
set.ext $ by simp
lemma seq_singleton {s : set (α → β)} {a : α} : set.seq s {a} = (λ f : α → β, f a) '' s :=
set.ext $ by simp
lemma seq_seq {s : set (β → γ)} {t : set (α → β)} {u : set α} :
seq s (seq t u) = seq (seq ((∘) '' s) t) u :=
begin
refine set.ext (λ c, iff.intro _ _),
{ rintro ⟨f, hfs, b, ⟨g, hg, a, hau, rfl⟩, rfl⟩,
exact ⟨f ∘ g, ⟨(∘) f, mem_image_of_mem _ hfs, g, hg, rfl⟩, a, hau, rfl⟩ },
{ rintro ⟨fg, ⟨fc, ⟨f, hfs, rfl⟩, g, hgt, rfl⟩, a, ha, rfl⟩,
exact ⟨f, hfs, g a, ⟨g, hgt, a, ha, rfl⟩, rfl⟩ }
end
lemma image_seq {f : β → γ} {s : set (α → β)} {t : set α} :
f '' seq s t = seq ((∘) f '' s) t :=
by rw [← singleton_seq, ← singleton_seq, seq_seq, image_singleton]
lemma prod_eq_seq {s : set α} {t : set β} : s ×ˢ t = (prod.mk '' s).seq t :=
begin
ext ⟨a, b⟩,
split,
{ rintro ⟨ha, hb⟩, exact ⟨prod.mk a, ⟨a, ha, rfl⟩, b, hb, rfl⟩ },
{ rintro ⟨f, ⟨x, hx, rfl⟩, y, hy, eq⟩, rw ← eq, exact ⟨hx, hy⟩ }
end
lemma prod_image_seq_comm (s : set α) (t : set β) :
(prod.mk '' s).seq t = seq ((λ b a, (a, b)) '' t) s :=
by rw [← prod_eq_seq, ← image_swap_prod, prod_eq_seq, image_seq, ← image_comp, prod.swap]
lemma image2_eq_seq (f : α → β → γ) (s : set α) (t : set β) : image2 f s t = seq (f '' s) t :=
by { ext, simp }
end seq
section pi
variables {π : α → Type*}
lemma pi_def (i : set α) (s : Π a, set (π a)) :
pi i s = (⋂ a ∈ i, eval a ⁻¹' s a) :=
by { ext, simp }
lemma univ_pi_eq_Inter (t : Π i, set (π i)) : pi univ t = ⋂ i, eval i ⁻¹' t i :=
by simp only [pi_def, Inter_true, mem_univ]
lemma pi_diff_pi_subset (i : set α) (s t : Π a, set (π a)) :
pi i s \ pi i t ⊆ ⋃ a ∈ i, (eval a ⁻¹' (s a \ t a)) :=
begin
refine diff_subset_comm.2 (λ x hx a ha, _),
simp only [mem_diff, mem_pi, mem_Union, not_exists, mem_preimage, not_and, not_not, eval_apply]
at hx,
exact hx.2 _ ha (hx.1 _ ha)
end
lemma Union_univ_pi (t : Π i, ι → set (π i)) :
(⋃ (x : α → ι), pi univ (λ i, t i (x i))) = pi univ (λ i, ⋃ (j : ι), t i j) :=
by { ext, simp [classical.skolem] }
end pi
end set
namespace function
namespace surjective
lemma Union_comp {f : ι → ι₂} (hf : surjective f) (g : ι₂ → set α) :
(⋃ x, g (f x)) = ⋃ y, g y :=
hf.supr_comp g
lemma Inter_comp {f : ι → ι₂} (hf : surjective f) (g : ι₂ → set α) :
(⋂ x, g (f x)) = ⋂ y, g y :=
hf.infi_comp g
end surjective
end function
/-!
### Disjoint sets
We define some lemmas in the `disjoint` namespace to be able to use projection notation.
-/
section disjoint
variables {s t u : set α} {f : α → β}
namespace disjoint
theorem union_left (hs : disjoint s u) (ht : disjoint t u) : disjoint (s ∪ t) u :=
hs.sup_left ht
theorem union_right (ht : disjoint s t) (hu : disjoint s u) : disjoint s (t ∪ u) :=
ht.sup_right hu
lemma inter_left (u : set α) (h : disjoint s t) : disjoint (s ∩ u) t :=
inf_left _ h
lemma inter_left' (u : set α) (h : disjoint s t) : disjoint (u ∩ s) t :=
inf_left' _ h
lemma inter_right (u : set α) (h : disjoint s t) : disjoint s (t ∩ u) :=
inf_right _ h
lemma inter_right' (u : set α) (h : disjoint s t) : disjoint s (u ∩ t) :=
inf_right' _ h
lemma subset_left_of_subset_union (h : s ⊆ t ∪ u) (hac : disjoint s u) : s ⊆ t :=
hac.left_le_of_le_sup_right h
lemma subset_right_of_subset_union (h : s ⊆ t ∪ u) (hab : disjoint s t) : s ⊆ u :=
hab.left_le_of_le_sup_left h
lemma preimage {α β} (f : α → β) {s t : set β} (h : disjoint s t) : disjoint (f ⁻¹' s) (f ⁻¹' t) :=
λ x hx, h hx
end disjoint
namespace set
protected theorem disjoint_iff : disjoint s t ↔ s ∩ t ⊆ ∅ := iff.rfl
theorem disjoint_iff_inter_eq_empty : disjoint s t ↔ s ∩ t = ∅ :=
disjoint_iff
lemma not_disjoint_iff : ¬disjoint s t ↔ ∃ x, x ∈ s ∧ x ∈ t :=
not_forall.trans $ exists_congr $ λ x, not_not
lemma not_disjoint_iff_nonempty_inter : ¬disjoint s t ↔ (s ∩ t).nonempty :=
not_disjoint_iff
alias not_disjoint_iff_nonempty_inter ↔ _ nonempty.not_disjoint
lemma disjoint_or_nonempty_inter (s t : set α) : disjoint s t ∨ (s ∩ t).nonempty :=
(em _).imp_right not_disjoint_iff_nonempty_inter.mp
lemma disjoint_iff_forall_ne : disjoint s t ↔ ∀ (x ∈ s) (y ∈ t), x ≠ y :=
by simp only [ne.def, disjoint_left, @imp_not_comm _ (_ = _), forall_eq']
lemma _root_.disjoint.ne_of_mem (h : disjoint s t) {x y} (hx : x ∈ s) (hy : y ∈ t) : x ≠ y :=
disjoint_iff_forall_ne.mp h x hx y hy
theorem disjoint_of_subset_left (h : s ⊆ u) (d : disjoint u t) : disjoint s t :=
d.mono_left h
theorem disjoint_of_subset_right (h : t ⊆ u) (d : disjoint s u) : disjoint s t :=
d.mono_right h
theorem disjoint_of_subset {s t u v : set α} (h1 : s ⊆ u) (h2 : t ⊆ v) (d : disjoint u v) :
disjoint s t :=
d.mono h1 h2
@[simp] theorem disjoint_union_left :
disjoint (s ∪ t) u ↔ disjoint s u ∧ disjoint t u :=
disjoint_sup_left
@[simp] theorem disjoint_union_right :
disjoint s (t ∪ u) ↔ disjoint s t ∧ disjoint s u :=
disjoint_sup_right
@[simp] theorem disjoint_Union_left {ι : Sort*} {s : ι → set α} :
disjoint (⋃ i, s i) t ↔ ∀ i, disjoint (s i) t :=
supr_disjoint_iff
@[simp] theorem disjoint_Union_right {ι : Sort*} {s : ι → set α} :
disjoint t (⋃ i, s i) ↔ ∀ i, disjoint t (s i) :=
disjoint_supr_iff
@[simp] lemma disjoint_Union₂_left {s : Π i, κ i → set α} {t : set α} :
disjoint (⋃ i j, s i j) t ↔ ∀ i j, disjoint (s i j) t :=
supr₂_disjoint_iff
@[simp] lemma disjoint_Union₂_right {s : set α} {t : Π i, κ i → set α} :
disjoint s (⋃ i j, t i j) ↔ ∀ i j, disjoint s (t i j) :=
disjoint_supr₂_iff
@[simp] lemma disjoint_sUnion_left {S : set (set α)} {t : set α} :
disjoint (⋃₀ S) t ↔ ∀ s ∈ S, disjoint s t :=
Sup_disjoint_iff
@[simp] lemma disjoint_sUnion_right {s : set α} {S : set (set α)} :
disjoint s (⋃₀ S) ↔ ∀ t ∈ S, disjoint s t :=
disjoint_Sup_iff
theorem disjoint_diff {a b : set α} : disjoint a (b \ a) :=
disjoint_iff.2 (inter_diff_self _ _)
@[simp] theorem disjoint_empty (s : set α) : disjoint s ∅ := disjoint_bot_right
@[simp] theorem empty_disjoint (s : set α) : disjoint ∅ s := disjoint_bot_left
@[simp] lemma univ_disjoint {s : set α} : disjoint univ s ↔ s = ∅ :=
top_disjoint
@[simp] lemma disjoint_univ {s : set α} : disjoint s univ ↔ s = ∅ :=
disjoint_top
@[simp] theorem disjoint_singleton_left {a : α} {s : set α} : disjoint {a} s ↔ a ∉ s :=
by simp [set.disjoint_iff, subset_def]; exact iff.rfl
@[simp] theorem disjoint_singleton_right {a : α} {s : set α} : disjoint s {a} ↔ a ∉ s :=
by rw [disjoint.comm]; exact disjoint_singleton_left
@[simp] lemma disjoint_singleton {a b : α} : disjoint ({a} : set α) {b} ↔ a ≠ b :=
by rw [disjoint_singleton_left, mem_singleton_iff]
theorem disjoint_image_image {f : β → α} {g : γ → α} {s : set β} {t : set γ}
(h : ∀ b ∈ s, ∀ c ∈ t, f b ≠ g c) : disjoint (f '' s) (g '' t) :=
by rintro a ⟨⟨b, hb, eq⟩, c, hc, rfl⟩; exact h b hb c hc eq
lemma disjoint_image_of_injective {f : α → β} (hf : injective f) {s t : set α}
(hd : disjoint s t) : disjoint (f '' s) (f '' t) :=
disjoint_image_image $ λ x hx y hy, hf.ne $ λ H, set.disjoint_iff.1 hd ⟨hx, H.symm ▸ hy⟩
lemma _root_.disjoint.of_image (h : disjoint (f '' s) (f '' t)) : disjoint s t :=
λ x hx, disjoint_left.1 h (mem_image_of_mem _ hx.1) (mem_image_of_mem _ hx.2)
lemma disjoint_image_iff (hf : injective f) : disjoint (f '' s) (f '' t) ↔ disjoint s t :=
⟨disjoint.of_image, disjoint_image_of_injective hf⟩
lemma _root_.disjoint.of_preimage (hf : surjective f) {s t : set β}
(h : disjoint (f ⁻¹' s) (f ⁻¹' t)) :
disjoint s t :=
by rw [disjoint_iff_inter_eq_empty, ←image_preimage_eq (_ ∩ _) hf, preimage_inter, h.inter_eq,
image_empty]
lemma disjoint_preimage_iff (hf : surjective f) {s t : set β} :
disjoint (f ⁻¹' s) (f ⁻¹' t) ↔ disjoint s t :=
⟨disjoint.of_preimage hf, disjoint.preimage _⟩
lemma preimage_eq_empty {f : α → β} {s : set β} (h : disjoint s (range f)) :
f ⁻¹' s = ∅ :=
by simpa using h.preimage f
lemma preimage_eq_empty_iff {s : set β} : f ⁻¹' s = ∅ ↔ disjoint s (range f) :=
⟨λ h, begin
simp only [eq_empty_iff_forall_not_mem, disjoint_iff_inter_eq_empty, not_exists,
mem_inter_eq, not_and, mem_range, mem_preimage] at h ⊢,
assume y hy x hx,
rw ← hx at hy,
exact h x hy,
end, preimage_eq_empty⟩
lemma _root_.disjoint.image {s t u : set α} {f : α → β} (h : disjoint s t) (hf : inj_on f u)
(hs : s ⊆ u) (ht : t ⊆ u) : disjoint (f '' s) (f '' t) :=
begin
rw disjoint_iff_inter_eq_empty at h ⊢,
rw [← hf.image_inter hs ht, h, image_empty],
end
end set
end disjoint
/-! ### Intervals -/
namespace set
variables [complete_lattice α]
lemma Ici_supr (f : ι → α) : Ici (⨆ i, f i) = ⋂ i, Ici (f i) :=
ext $ λ _, by simp only [mem_Ici, supr_le_iff, mem_Inter]
lemma Iic_infi (f : ι → α) : Iic (⨅ i, f i) = ⋂ i, Iic (f i) :=
ext $ λ _, by simp only [mem_Iic, le_infi_iff, mem_Inter]
lemma Ici_supr₂ (f : Π i, κ i → α) : Ici (⨆ i j, f i j) = ⋂ i j, Ici (f i j) := by simp_rw Ici_supr
lemma Iic_infi₂ (f : Π i, κ i → α) : Iic (⨅ i j, f i j) = ⋂ i j, Iic (f i j) := by simp_rw Iic_infi
lemma Ici_Sup (s : set α) : Ici (Sup s) = ⋂ a ∈ s, Ici a := by rw [Sup_eq_supr, Ici_supr₂]
lemma Iic_Inf (s : set α) : Iic (Inf s) = ⋂ a ∈ s, Iic a := by rw [Inf_eq_infi, Iic_infi₂]
end set
namespace set
variables (t : α → set β)
lemma subset_diff {s t u : set α} : s ⊆ t \ u ↔ s ⊆ t ∧ disjoint s u :=
⟨λ h, ⟨λ x hxs, (h hxs).1, λ x ⟨hxs, hxu⟩, (h hxs).2 hxu⟩,
λ ⟨h1, h2⟩ x hxs, ⟨h1 hxs, λ hxu, h2 ⟨hxs, hxu⟩⟩⟩
lemma bUnion_diff_bUnion_subset (s₁ s₂ : set α) :
(⋃ x ∈ s₁, t x) \ (⋃ x ∈ s₂, t x) ⊆ (⋃ x ∈ s₁ \ s₂, t x) :=
begin
simp only [diff_subset_iff, ← bUnion_union],
apply bUnion_subset_bUnion_left,
rw union_diff_self,
apply subset_union_right
end
/-- If `t` is an indexed family of sets, then there is a natural map from `Σ i, t i` to `⋃ i, t i`
sending `⟨i, x⟩` to `x`. -/
def sigma_to_Union (x : Σ i, t i) : (⋃ i, t i) := ⟨x.2, mem_Union.2 ⟨x.1, x.2.2⟩⟩
lemma sigma_to_Union_surjective : surjective (sigma_to_Union t)
| ⟨b, hb⟩ := have ∃ a, b ∈ t a, by simpa using hb, let ⟨a, hb⟩ := this in ⟨⟨a, b, hb⟩, rfl⟩
lemma sigma_to_Union_injective (h : ∀ i j, i ≠ j → disjoint (t i) (t j)) :
injective (sigma_to_Union t)
| ⟨a₁, b₁, h₁⟩ ⟨a₂, b₂, h₂⟩ eq :=
have b_eq : b₁ = b₂, from congr_arg subtype.val eq,
have a_eq : a₁ = a₂, from classical.by_contradiction $ λ ne,
have b₁ ∈ t a₁ ∩ t a₂, from ⟨h₁, b_eq.symm ▸ h₂⟩,
h _ _ ne this,
sigma.eq a_eq $ subtype.eq $ by subst b_eq; subst a_eq
lemma sigma_to_Union_bijective (h : ∀ i j, i ≠ j → disjoint (t i) (t j)) :
bijective (sigma_to_Union t) :=
⟨sigma_to_Union_injective t h, sigma_to_Union_surjective t⟩
/-- Equivalence between a disjoint union and a dependent sum. -/
noncomputable def Union_eq_sigma_of_disjoint {t : α → set β}
(h : ∀ i j, i ≠ j → disjoint (t i) (t j)) : (⋃ i, t i) ≃ (Σ i, t i) :=
(equiv.of_bijective _ $ sigma_to_Union_bijective t h).symm
lemma Union_ge_eq_Union_nat_add (u : ℕ → set α) (n : ℕ) : (⋃ i ≥ n, u i) = ⋃ i, u (i + n) :=
supr_ge_eq_supr_nat_add u n
lemma Inter_ge_eq_Inter_nat_add (u : ℕ → set α) (n : ℕ) : (⋂ i ≥ n, u i) = ⋂ i, u (i + n) :=
infi_ge_eq_infi_nat_add u n
lemma _root_.monotone.Union_nat_add {f : ℕ → set α} (hf : monotone f) (k : ℕ) :
(⋃ n, f (n + k)) = ⋃ n, f n :=
hf.supr_nat_add k
lemma _root_.antitone.Inter_nat_add {f : ℕ → set α} (hf : antitone f) (k : ℕ) :
(⋂ n, f (n + k)) = ⋂ n, f n :=
hf.infi_nat_add k
@[simp] lemma Union_Inter_ge_nat_add (f : ℕ → set α) (k : ℕ) :
(⋃ n, ⋂ i ≥ n, f (i + k)) = ⋃ n, ⋂ i ≥ n, f i :=
supr_infi_ge_nat_add f k
lemma union_Union_nat_succ (u : ℕ → set α) : u 0 ∪ (⋃ i, u (i + 1)) = ⋃ i, u i :=
sup_supr_nat_succ u
lemma inter_Inter_nat_succ (u : ℕ → set α) : u 0 ∩ (⋂ i, u (i + 1)) = ⋂ i, u i :=
inf_infi_nat_succ u
end set
section sup_closed
/-- A set `s` is sup-closed if for all `x₁, x₂ ∈ s`, `x₁ ⊔ x₂ ∈ s`. -/
def sup_closed [has_sup α] (s : set α) : Prop := ∀ x1 x2, x1 ∈ s → x2 ∈ s → x1 ⊔ x2 ∈ s
lemma sup_closed_singleton [semilattice_sup α] (x : α) : sup_closed ({x} : set α) :=
λ _ _ y1_mem y2_mem, by { rw set.mem_singleton_iff at *, rw [y1_mem, y2_mem, sup_idem], }
lemma sup_closed.inter [semilattice_sup α] {s t : set α} (hs : sup_closed s)
(ht : sup_closed t) :
sup_closed (s ∩ t) :=
begin
intros x y hx hy,
rw set.mem_inter_iff at hx hy ⊢,
exact ⟨hs x y hx.left hy.left, ht x y hx.right hy.right⟩,
end
lemma sup_closed_of_totally_ordered [semilattice_sup α] (s : set α)
(hs : ∀ x y : α, x ∈ s → y ∈ s → y ≤ x ∨ x ≤ y) :
sup_closed s :=
begin
intros x y hxs hys,
cases hs x y hxs hys,
{ rwa (sup_eq_left.mpr h), },
{ rwa (sup_eq_right.mpr h), },
end
lemma sup_closed_of_linear_order [linear_order α] (s : set α) : sup_closed s :=
sup_closed_of_totally_ordered s (λ x y hxs hys, le_total y x)
end sup_closed
open set
variables [complete_lattice β]
lemma supr_Union (s : ι → set α) (f : α → β) : (⨆ a ∈ (⋃ i, s i), f a) = ⨆ i (a ∈ s i), f a :=
by { rw supr_comm, simp_rw [mem_Union, supr_exists] }
lemma infi_Union (s : ι → set α) (f : α → β) : (⨅ a ∈ (⋃ i, s i), f a) = ⨅ i (a ∈ s i), f a :=
@supr_Union α βᵒᵈ _ _ s f
lemma Sup_sUnion (s : set (set β)) : Sup (⋃₀ s) = ⨆ t ∈ s, Sup t :=
by simp only [sUnion_eq_bUnion, Sup_eq_supr, supr_Union]
lemma Inf_sUnion (s : set (set β)) : Inf (⋃₀ s) = ⨅ t ∈ s, Inf t := @Sup_sUnion βᵒᵈ _ _
|
4c522fa1d066ea46e832abeccc14bd3ba1ef9688 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/linear_algebra/affine_space/basic.lean | dc2f712962af671e93a61315d0ec839bd29e5845 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 1,589 | lean | /-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import algebra.add_torsor
/-!
# Affine space
In this file we introduce the following notation:
* `affine_space V P` is an alternative notation for `add_torsor V P` introduced at the end of this
file.
We tried to use an `abbreviation` instead of a `notation` but this led to hard-to-debug elaboration
errors. So, we introduce a localized notation instead. When this notation is enabled with
`open_locale affine`, Lean will use `affine_space` instead of `add_torsor` both in input and in the
proof state.
Here is an incomplete list of notions related to affine spaces, all of them are defined in other
files:
* `affine_map`: a map between affine spaces that preserves the affine structure;
* `affine_equiv`: an equivalence between affine spaces that preserves the affine structure;
* `affine_subspace`: a subset of an affine space closed w.r.t. affine combinations of points;
* `affine_combination`: an affine combination of points;
* `affine_independent`: affine independent set of points;
* `affine_basis.coord`: the barycentric coordinate of a point.
## TODO
Some key definitions are not yet present.
* Affine frames. An affine frame might perhaps be represented as an `affine_equiv` to a `finsupp`
(in the general case) or function type (in the finite-dimensional case) that gives the
coordinates, with appropriate proofs of existence when `k` is a field.
-/
localized "notation `affine_space` := add_torsor" in affine
|
b5c0f6ab907c268596ab959d12eff29c37853440 | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /tests/lean/run/inliner_loop.lean | 0feb7c37cb369719a1884f835f249fc59335811a | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 138 | lean | unsafe inductive t
| mk : (t → t) → t
unsafe def loop' : t → t
| t.mk f => f (t.mk f)
unsafe def loop : t :=
loop' (t.mk loop')
|
5cdafd8417defbecfb2c406bba349c851da368ea | ce6917c5bacabee346655160b74a307b4a5ab620 | /src/ch5/ex0706.lean | b02e3e93f6bf456508c96cc5ccce09d0e8022013 | [] | no_license | Ailrun/Theorem_Proving_in_Lean | ae6a23f3c54d62d401314d6a771e8ff8b4132db2 | 2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68 | refs/heads/master | 1,609,838,270,467 | 1,586,846,743,000 | 1,586,846,743,000 | 240,967,761 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 516 | lean | variables {α : Type} [comm_ring α]
local attribute [simp] mul_comm mul_assoc mul_left_comm
example (x y z : α) : (x - x) * y + z = z :=
begin
simp [sub_eq_add_neg]
end
-- lean 3.6 removes simp attributes from sub_eq_add_neg
-- i.e., now it is required to provide that lemma to solve this example.
example (x y z w : α) : x * y + z * w * x = x * w * z + y * x :=
by simp [add_comm]
-- lean 3.6 removes simp attributes from add_comm
-- i.e., now it is required to provide that lemma to solve this example.
|
6ddfc7b75c80963d7d8b502180b64346a29ebfbf | 94e33a31faa76775069b071adea97e86e218a8ee | /src/linear_algebra/exterior_algebra/basic.lean | faff4b56c2d68e1df2f461f52f42578dce518002 | [
"Apache-2.0"
] | permissive | urkud/mathlib | eab80095e1b9f1513bfb7f25b4fa82fa4fd02989 | 6379d39e6b5b279df9715f8011369a301b634e41 | refs/heads/master | 1,658,425,342,662 | 1,658,078,703,000 | 1,658,078,703,000 | 186,910,338 | 0 | 0 | Apache-2.0 | 1,568,512,083,000 | 1,557,958,709,000 | Lean | UTF-8 | Lean | false | false | 10,488 | lean | /-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhangir Azerbayev, Adam Topaz, Eric Wieser
-/
import algebra.ring_quot
import linear_algebra.clifford_algebra.basic
import linear_algebra.alternating
import group_theory.perm.sign
/-!
# Exterior Algebras
We construct the exterior algebra of a module `M` over a commutative semiring `R`.
## Notation
The exterior algebra of the `R`-module `M` is denoted as `exterior_algebra R M`.
It is endowed with the structure of an `R`-algebra.
Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that
`cond : ∀ m : M, f m * f m = 0`, there is a (unique) lift of `f` to an `R`-algebra morphism,
which is denoted `exterior_algebra.lift R f cond`.
The canonical linear map `M → exterior_algebra R M` is denoted `exterior_algebra.ι R`.
## Theorems
The main theorems proved ensure that `exterior_algebra R M` satisfies the universal property
of the exterior algebra.
1. `ι_comp_lift` is fact that the composition of `ι R` with `lift R f cond` agrees with `f`.
2. `lift_unique` ensures the uniqueness of `lift R f cond` with respect to 1.
## Definitions
* `ι_multi` is the `alternating_map` corresponding to the wedge product of `ι R m` terms.
## Implementation details
The exterior algebra of `M` is constructed as simply `clifford_algebra (0 : quadratic_form R M)`,
as this avoids us having to duplicate API.
-/
universes u1 u2 u3
variables (R : Type u1) [comm_ring R]
variables (M : Type u2) [add_comm_group M] [module R M]
/--
The exterior algebra of an `R`-module `M`.
-/
@[reducible]
def exterior_algebra := clifford_algebra (0 : quadratic_form R M)
namespace exterior_algebra
variables {M}
/--
The canonical linear map `M →ₗ[R] exterior_algebra R M`.
-/
@[reducible] def ι : M →ₗ[R] exterior_algebra R M := by exact clifford_algebra.ι _
variables {R}
/-- As well as being linear, `ι m` squares to zero -/
@[simp]
theorem ι_sq_zero (m : M) : (ι R m) * (ι R m) = 0 :=
(clifford_algebra.ι_sq_scalar _ m).trans $ map_zero _
variables {A : Type*} [semiring A] [algebra R A]
@[simp]
theorem comp_ι_sq_zero (g : exterior_algebra R M →ₐ[R] A)
(m : M) : g (ι R m) * g (ι R m) = 0 :=
by rw [←alg_hom.map_mul, ι_sq_zero, alg_hom.map_zero]
variables (R)
/--
Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition:
`cond : ∀ m : M, f m * f m = 0`, this is the canonical lift of `f` to a morphism of `R`-algebras
from `exterior_algebra R M` to `A`.
-/
@[simps symm_apply]
def lift : {f : M →ₗ[R] A // ∀ m, f m * f m = 0} ≃ (exterior_algebra R M →ₐ[R] A) :=
equiv.trans (equiv.subtype_equiv (equiv.refl _) $ by simp) $ clifford_algebra.lift _
@[simp]
theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) :
(lift R ⟨f, cond⟩).to_linear_map.comp (ι R) = f :=
clifford_algebra.ι_comp_lift f _
@[simp]
theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) (x) :
lift R ⟨f, cond⟩ (ι R x) = f x :=
clifford_algebra.lift_ι_apply f _ x
@[simp]
theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0)
(g : exterior_algebra R M →ₐ[R] A) : g.to_linear_map.comp (ι R) = f ↔ g = lift R ⟨f, cond⟩ :=
clifford_algebra.lift_unique f _ _
variables {R M}
@[simp]
theorem lift_comp_ι (g : exterior_algebra R M →ₐ[R] A) :
lift R ⟨g.to_linear_map.comp (ι R), comp_ι_sq_zero _⟩ = g :=
clifford_algebra.lift_comp_ι g
/-- See note [partially-applied ext lemmas]. -/
@[ext]
theorem hom_ext {f g : exterior_algebra R M →ₐ[R] A}
(h : f.to_linear_map.comp (ι R) = g.to_linear_map.comp (ι R)) : f = g :=
clifford_algebra.hom_ext h
/-- If `C` holds for the `algebra_map` of `r : R` into `exterior_algebra R M`, the `ι` of `x : M`,
and is preserved under addition and muliplication, then it holds for all of `exterior_algebra R M`.
-/
@[elab_as_eliminator]
lemma induction {C : exterior_algebra R M → Prop}
(h_grade0 : ∀ r, C (algebra_map R (exterior_algebra R M) r))
(h_grade1 : ∀ x, C (ι R x))
(h_mul : ∀ a b, C a → C b → C (a * b))
(h_add : ∀ a b, C a → C b → C (a + b))
(a : exterior_algebra R M) :
C a :=
clifford_algebra.induction h_grade0 h_grade1 h_mul h_add a
/-- The left-inverse of `algebra_map`. -/
def algebra_map_inv : exterior_algebra R M →ₐ[R] R :=
exterior_algebra.lift R ⟨(0 : M →ₗ[R] R), λ m, by simp⟩
variables (M)
lemma algebra_map_left_inverse :
function.left_inverse algebra_map_inv (algebra_map R $ exterior_algebra R M) :=
λ x, by simp [algebra_map_inv]
@[simp] lemma algebra_map_inj (x y : R) :
algebra_map R (exterior_algebra R M) x = algebra_map R (exterior_algebra R M) y ↔ x = y :=
(algebra_map_left_inverse M).injective.eq_iff
@[simp] lemma algebra_map_eq_zero_iff (x : R) :
algebra_map R (exterior_algebra R M) x = 0 ↔ x = 0 :=
map_eq_zero_iff (algebra_map _ _) (algebra_map_left_inverse _).injective
@[simp] lemma algebra_map_eq_one_iff (x : R) : algebra_map R (exterior_algebra R M) x = 1 ↔ x = 1 :=
map_eq_one_iff (algebra_map _ _) (algebra_map_left_inverse _).injective
variables {M}
/-- The canonical map from `exterior_algebra R M` into `triv_sq_zero_ext R M` that sends
`exterior_algebra.ι` to `triv_sq_zero_ext.inr`. -/
def to_triv_sq_zero_ext : exterior_algebra R M →ₐ[R] triv_sq_zero_ext R M :=
lift R ⟨triv_sq_zero_ext.inr_hom R M, λ m, triv_sq_zero_ext.inr_mul_inr R m m⟩
@[simp] lemma to_triv_sq_zero_ext_ι (x : M) :
to_triv_sq_zero_ext (ι R x) = triv_sq_zero_ext.inr x :=
lift_ι_apply _ _ _ _
/-- The left-inverse of `ι`.
As an implementation detail, we implement this using `triv_sq_zero_ext` which has a suitable
algebra structure. -/
def ι_inv : exterior_algebra R M →ₗ[R] M :=
(triv_sq_zero_ext.snd_hom R M).comp to_triv_sq_zero_ext.to_linear_map
lemma ι_left_inverse : function.left_inverse ι_inv (ι R : M → exterior_algebra R M) :=
λ x, by simp [ι_inv]
variables (R)
@[simp] lemma ι_inj (x y : M) : ι R x = ι R y ↔ x = y :=
ι_left_inverse.injective.eq_iff
variables {R}
@[simp] lemma ι_eq_zero_iff (x : M) : ι R x = 0 ↔ x = 0 :=
by rw [←ι_inj R x 0, linear_map.map_zero]
@[simp] lemma ι_eq_algebra_map_iff (x : M) (r : R) : ι R x = algebra_map R _ r ↔ x = 0 ∧ r = 0 :=
begin
refine ⟨λ h, _, _⟩,
{ have hf0 : to_triv_sq_zero_ext (ι R x) = (0, x), from to_triv_sq_zero_ext_ι _,
rw [h, alg_hom.commutes] at hf0,
have : r = 0 ∧ 0 = x := prod.ext_iff.1 hf0,
exact this.symm.imp_left eq.symm, },
{ rintro ⟨rfl, rfl⟩,
rw [linear_map.map_zero, ring_hom.map_zero] }
end
@[simp] lemma ι_ne_one [nontrivial R] (x : M) : ι R x ≠ 1 :=
begin
rw [←(algebra_map R (exterior_algebra R M)).map_one, ne.def, ι_eq_algebra_map_iff],
exact one_ne_zero ∘ and.right,
end
/-- The generators of the exterior algebra are disjoint from its scalars. -/
lemma ι_range_disjoint_one : disjoint (ι R).range (1 : submodule R (exterior_algebra R M)) :=
begin
rw submodule.disjoint_def,
rintros _ ⟨x, hx⟩ ⟨r, (rfl : algebra_map _ _ _ = _)⟩,
rw ι_eq_algebra_map_iff x at hx,
rw [hx.2, ring_hom.map_zero]
end
@[simp]
lemma ι_add_mul_swap (x y : M) : ι R x * ι R y + ι R y * ι R x = 0 :=
calc _ = ι R (x + y) * ι R (x + y) : by simp [mul_add, add_mul]
... = _ : ι_sq_zero _
lemma ι_mul_prod_list {n : ℕ} (f : fin n → M) (i : fin n) :
(ι R $ f i) * (list.of_fn $ λ i, ι R $ f i).prod = 0 :=
begin
induction n with n hn,
{ exact i.elim0, },
{ rw [list.of_fn_succ, list.prod_cons, ←mul_assoc],
by_cases h : i = 0,
{ rw [h, ι_sq_zero, zero_mul], },
{ replace hn := congr_arg ((*) $ ι R $ f 0) (hn (λ i, f $ fin.succ i) (i.pred h)),
simp only at hn,
rw [fin.succ_pred, ←mul_assoc, mul_zero] at hn,
refine (eq_zero_iff_eq_zero_of_add_eq_zero _).mp hn,
rw [← add_mul, ι_add_mul_swap, zero_mul], } }
end
variables (R)
/-- The product of `n` terms of the form `ι R m` is an alternating map.
This is a special case of `multilinear_map.mk_pi_algebra_fin`, and the exterior algebra version of
`tensor_algebra.tprod`. -/
def ι_multi (n : ℕ) : alternating_map R M (exterior_algebra R M) (fin n) :=
let F := (multilinear_map.mk_pi_algebra_fin R n (exterior_algebra R M)).comp_linear_map (λ i, ι R)
in
{ map_eq_zero_of_eq' := λ f x y hfxy hxy, begin
rw [multilinear_map.comp_linear_map_apply, multilinear_map.mk_pi_algebra_fin_apply],
wlog h : x < y := lt_or_gt_of_ne hxy using x y,
clear hxy,
induction n with n hn generalizing x y,
{ exact x.elim0, },
{ rw [list.of_fn_succ, list.prod_cons],
by_cases hx : x = 0,
-- one of the repeated terms is on the left
{ rw hx at hfxy h,
rw [hfxy, ←fin.succ_pred y (ne_of_lt h).symm],
exact ι_mul_prod_list (f ∘ fin.succ) _, },
-- ignore the left-most term and induct on the remaining ones, decrementing indices
{ convert mul_zero _,
refine hn (λ i, f $ fin.succ i)
(x.pred hx) (y.pred (ne_of_lt $ lt_of_le_of_lt x.zero_le h).symm)
(fin.pred_lt_pred_iff.mpr h) _,
simp only [fin.succ_pred],
exact hfxy, } }
end,
to_fun := F, ..F}
variables {R}
lemma ι_multi_apply {n : ℕ} (v : fin n → M) :
ι_multi R n v = (list.of_fn $ λ i, ι R (v i)).prod := rfl
@[simp] lemma ι_multi_zero_apply (v : fin 0 → M) : ι_multi R 0 v = 1 := rfl
@[simp] lemma ι_multi_succ_apply {n : ℕ} (v : fin n.succ → M) :
ι_multi R _ v = ι R (v 0) * ι_multi R _ (matrix.vec_tail v):=
(congr_arg list.prod (list.of_fn_succ _)).trans list.prod_cons
lemma ι_multi_succ_curry_left {n : ℕ} (m : M) :
(ι_multi R n.succ).curry_left m =
(algebra.lmul_left R (ι R m)).comp_alternating_map (ι_multi R n) :=
alternating_map.ext $ λ v, (ι_multi_succ_apply _).trans $ begin
simp_rw matrix.tail_cons,
refl,
end
end exterior_algebra
namespace tensor_algebra
variables {R M}
/-- The canonical image of the `tensor_algebra` in the `exterior_algebra`, which maps
`tensor_algebra.ι R x` to `exterior_algebra.ι R x`. -/
def to_exterior : tensor_algebra R M →ₐ[R] exterior_algebra R M :=
tensor_algebra.lift R (exterior_algebra.ι R : M →ₗ[R] exterior_algebra R M)
@[simp] lemma to_exterior_ι (m : M) : (tensor_algebra.ι R m).to_exterior = exterior_algebra.ι R m :=
by simp [to_exterior]
end tensor_algebra
|
3e08108fe92ca36c9d24cc197d9318d99ddc87a1 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/category/fold.lean | fdc1c97aac078f0a6e97fe895b007f2340ce46cd | [
"Apache-2.0"
] | permissive | gebner/mathlib | eab0150cc4f79ec45d2016a8c21750244a2e7ff0 | cc6a6edc397c55118df62831e23bfbd6e6c6b4ab | refs/heads/master | 1,625,574,853,976 | 1,586,712,827,000 | 1,586,712,827,000 | 99,101,412 | 1 | 0 | Apache-2.0 | 1,586,716,389,000 | 1,501,667,958,000 | Lean | UTF-8 | Lean | false | false | 14,639 | lean | /-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Sean Leather
List folds generalized to `traversable`. Informally, we can think of
`foldl` as a special case of `traverse` where we do not care about the
reconstructed data structure and, in a state monad, we care about the
final state.
The obvious way to define `foldl` would be to use the state monad but it
is nicer to reason about a more abstract interface with `fold_map` as a
primitive and `fold_map_hom` as a defining property.
def fold_map {α ω} [has_one ω] [has_mul ω] (f : α → ω) : t α → ω := ...
lemma fold_map_hom (α β)
[monoid α] [monoid β] (f : α → β) [is_monoid_hom f]
(g : γ → α) (x : t γ) :
f (fold_map g x) = fold_map (f ∘ g) x :=
...
`fold_map` uses a monoid ω to accumulate a value for every element of
a data structure and `fold_map_hom` uses a monoid homomorphism to
substitute the monoid used by `fold_map`. The two are sufficient to
define `foldl`, `foldr` and `to_list`. `to_list` permits the
formulation of specifications in terms of operations on lists.
Each fold function can be defined using a specialized
monoid. `to_list` uses a free monoid represented as a list with
concatenation while `foldl` uses endofunctions together with function
composition.
The definition through monoids uses `traverse` together with the
applicative functor `const m` (where `m` is the monoid). As an
implementation, `const` guarantees that no resource is spent on
reconstructing the structure during traversal.
A special class could be defined for `foldable`, similarly to Haskell,
but the author cannot think of instances of `foldable` that are not also
`traversable`.
-/
import tactic.squeeze
import algebra.free_monoid algebra.opposites
import data.list.defs
import category.traversable.instances category.traversable.lemmas
import category_theory.category
import category_theory.endomorphism
import category_theory.types
import category_theory.category.Kleisli
import category.applicative
universes u v
open ulift category_theory opposite
namespace monoid
variables {m : Type u → Type u} [monad m]
variables {α β : Type u}
/--
For a list, foldl f x [y₀,y₁] reduces as follows
calc foldl f x [y₀,y₁]
= foldl f (f x y₀) [y₁] : rfl
... = foldl f (f (f x y₀) y₁) [] : rfl
... = f (f x y₀) y₁ : rfl
with f : α → β → α
x : α
[y₀,y₁] : list β
We can view the above as a composition of functions:
... = f (f x y₀) y₁ : rfl
... = flip f y₁ (flip f y₀ x) : rfl
... = (flip f y₁ ∘ flip f y₀) x : rfl
We can use traverse and const to construct this composition:
calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x
= const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x
... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x
... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x
... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x
... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x
... = const.run ( flip f y₁ ∘ flip f y₀ ) x
... = f (f x y₀) y₁
And this is how `const` turns a monoid into an applicative functor and
how the monoid of endofunctions define `foldl`.
-/
@[reducible] def foldl (α : Type u) : Type u := (End α)ᵒᵖ
def foldl.mk (f : α → α) : foldl α := op f
def foldl.get (x : foldl α) : α → α := unop x
def foldl.of_free_monoid (f : β → α → β) (xs : free_monoid α) : monoid.foldl β :=
op $ flip (list.foldl f) xs
@[reducible] def foldr (α : Type u) : Type u := End α
def foldr.mk (f : α → α) : foldr α := f
def foldr.get (x : foldr α) : α → α := x
def foldr.of_free_monoid (f : α → β → β) (xs : free_monoid α) : monoid.foldr β :=
flip (list.foldr f) xs
@[reducible] def mfoldl (m : Type u → Type u) [monad m] (α : Type u) : Type u := opposite $ End $ Kleisli.mk m α
def mfoldl.mk (f : α → m α) : mfoldl m α := op f
def mfoldl.get (x : mfoldl m α) : α → m α := unop x
def mfoldl.of_free_monoid (f : β → α → m β) (xs : free_monoid α) : monoid.mfoldl m β :=
op $ flip (list.mfoldl f) xs
@[reducible] def mfoldr (m : Type u → Type u) [monad m] (α : Type u) : Type u :=
End $ Kleisli.mk m α
def mfoldr.mk (f : α → m α) : mfoldr m α := f
def mfoldr.get (x : mfoldr m α) : α → m α := x
def mfoldr.of_free_monoid (f : α → β → m β) (xs : free_monoid α) : monoid.mfoldr m β :=
flip (list.mfoldr f) xs
end monoid
namespace traversable
open monoid functor
section defs
variables {α β : Type u} {t : Type u → Type u} [traversable t]
def fold_map {α ω} [has_one ω] [has_mul ω] (f : α → ω) : t α → ω :=
traverse (const.mk' ∘ f)
def foldl (f : α → β → α) (x : α) (xs : t β) : α :=
(fold_map (foldl.mk ∘ flip f) xs).get x
def foldr (f : α → β → β) (x : β) (xs : t α) : β :=
(fold_map (foldr.mk ∘ f) xs).get x
/--
Conceptually, `to_list` collects all the elements of a collection
in a list. This idea is formalized by
`lemma to_list_spec (x : t α) : to_list x = fold_map free_monoid.mk x`.
The definition of `to_list` is based on `foldl` and `list.cons` for
speed. It is faster than using `fold_map free_monoid.mk` because, by
using `foldl` and `list.cons`, each insertion is done in constant
time. As a consequence, `to_list` performs in linear.
On the other hand, `fold_map free_monoid.mk` creates a singleton list
around each element and concatenates all the resulting lists. In
`xs ++ ys`, concatenation takes a time proportional to `length xs`. Since
the order in which concatenation is evaluated is unspecified, nothing
prevents each element of the traversable to be appended at the end
`xs ++ [x]` which would yield a `O(n²)` run time. -/
def to_list : t α → list α :=
list.reverse ∘ foldl (flip list.cons) []
def length (xs : t α) : ℕ :=
down $ foldl (λ l _, up $ l.down + 1) (up 0) xs
variables {m : Type u → Type u} [monad m]
def mfoldl (f : α → β → m α) (x : α) (xs : t β) : m α :=
(fold_map (mfoldl.mk ∘ flip f) xs).get x
def mfoldr (f : α → β → m β) (x : β) (xs : t α) : m β :=
(fold_map (mfoldr.mk ∘ f) xs).get x
end defs
section applicative_transformation
variables {α β γ : Type u}
open function (hiding const) is_monoid_hom
def map_fold [monoid α] [monoid β] (f : α → β) [is_monoid_hom f] :
applicative_transformation (const α) (const β) :=
{ app := λ x, f,
preserves_seq' := by { intros, simp only [map_mul f], },
preserves_pure' := by { intros, simp only [map_one f] } }
def free.mk : α → free_monoid α := list.ret
def free.map (f : α → β) : free_monoid α → free_monoid β := list.map f
lemma free.map_eq_map (f : α → β) (xs : list α) :
f <$> xs = free.map f xs := rfl
instance (f : α → β) : is_monoid_hom (free.map f) :=
{ map_mul := λ x y, by simp only [free.map, free_monoid.mul_def, list.map_append, free_add_monoid.add_def],
map_one := by simp only [free.map, free_monoid.one_def, list.map, free_add_monoid.zero_def] }
instance fold_foldl (f : β → α → β) :
is_monoid_hom (foldl.of_free_monoid f) :=
{ map_one := rfl,
map_mul := by intros; simp only [free_monoid.mul_def, foldl.of_free_monoid, flip, unop_op, list.foldl_append, op_inj_iff]; refl }
lemma foldl.unop_of_free_monoid (f : β → α → β) (xs : free_monoid α) (a : β) :
unop (foldl.of_free_monoid f xs) a = list.foldl f a xs := rfl
instance fold_foldr (f : α → β → β) :
is_monoid_hom (foldr.of_free_monoid f) :=
{ map_one := rfl,
map_mul := by intros; simp only [free_monoid.mul_def, foldr.of_free_monoid, list.foldr_append, flip]; refl }
variables (m : Type u → Type u) [monad m] [is_lawful_monad m]
@[simp]
lemma mfoldl.unop_of_free_monoid (f : β → α → m β) (xs : free_monoid α) (a : β) :
unop (mfoldl.of_free_monoid f xs) a = list.mfoldl f a xs := rfl
instance fold_mfoldl (f : β → α → m β) :
is_monoid_hom (mfoldl.of_free_monoid f) :=
{ map_one := rfl,
map_mul := by intros; apply unop_inj; ext; apply list.mfoldl_append }
instance fold_mfoldr (f : α → β → m β) :
is_monoid_hom (mfoldr.of_free_monoid f) :=
{ map_one := rfl,
map_mul := by intros; ext; apply list.mfoldr_append }
variables {t : Type u → Type u} [traversable t] [is_lawful_traversable t]
open is_lawful_traversable
lemma fold_map_hom
[monoid α] [monoid β] (f : α → β) [is_monoid_hom f]
(g : γ → α) (x : t γ) :
f (fold_map g x) = fold_map (f ∘ g) x :=
calc f (fold_map g x)
= f (traverse (const.mk' ∘ g) x) : rfl
... = (map_fold f).app _ (traverse (const.mk' ∘ g) x) : rfl
... = traverse ((map_fold f).app _ ∘ (const.mk' ∘ g)) x : naturality (map_fold f) _ _
... = fold_map (f ∘ g) x : rfl
lemma fold_map_hom_free
[monoid β] (f : free_monoid α → β) [is_monoid_hom f] (x : t α) :
f (fold_map free.mk x) = fold_map (f ∘ free.mk) x :=
fold_map_hom _ _ x
variable {m}
lemma fold_mfoldl_cons (f : α → β → m α) (x : β) (y : α) :
list.mfoldl f y (free.mk x) = f y x :=
by simp only [free.mk, list.ret, list.mfoldl, bind_pure]
lemma fold_mfoldr_cons (f : β → α → m α) (x : β) (y : α) :
list.mfoldr f y (free.mk x) = f x y :=
by simp only [free.mk, list.ret, list.mfoldr, pure_bind]
end applicative_transformation
section equalities
open is_lawful_traversable list (cons)
variables {α β γ : Type u}
variables {t : Type u → Type u} [traversable t] [is_lawful_traversable t]
@[simp]
lemma foldl.of_free_monoid_comp_free_mk (f : α → β → α) : foldl.of_free_monoid f ∘ free.mk = foldl.mk ∘ flip f := rfl
@[simp]
lemma foldr.of_free_monoid_comp_free_mk (f : β → α → α) : foldr.of_free_monoid f ∘ free.mk = foldr.mk ∘ f := rfl
@[simp]
lemma mfoldl.of_free_monoid_comp_free_mk {m} [monad m] [is_lawful_monad m] (f : α → β → m α) : mfoldl.of_free_monoid f ∘ free.mk = mfoldl.mk ∘ flip f :=
by ext; simp only [(∘), mfoldl.of_free_monoid, mfoldl.mk, flip, fold_mfoldl_cons]; refl
@[simp]
lemma mfoldr.of_free_monoid_comp_free_mk {m} [monad m] [is_lawful_monad m] (f : β → α → m α) : mfoldr.of_free_monoid f ∘ free.mk = mfoldr.mk ∘ f :=
by { ext, simp only [(∘), mfoldr.of_free_monoid, mfoldr.mk, flip, fold_mfoldr_cons] }
lemma to_list_spec (xs : t α) :
to_list xs = (fold_map free.mk xs : free_monoid _) :=
eq.symm $
calc fold_map free.mk xs
= (fold_map free.mk xs).reverse.reverse : by simp only [list.reverse_reverse]
... = (list.foldr cons [] (fold_map free.mk xs).reverse).reverse
: by simp only [list.foldr_eta]
... = (unop (foldl.of_free_monoid (flip cons) (fold_map free.mk xs)) []).reverse
: by simp only [flip,list.foldr_reverse,foldl.of_free_monoid, unop_op]
... = to_list xs : begin
rw fold_map_hom_free (foldl.of_free_monoid (flip cons)),
simp only [to_list, foldl, list.reverse_inj, foldl.get, foldl.of_free_monoid_comp_free_mk],
all_goals { apply_instance }
end
lemma fold_map_map [monoid γ] (f : α → β) (g : β → γ) (xs : t α) :
fold_map g (f <$> xs) = fold_map (g ∘ f) xs :=
by simp only [fold_map,traverse_map]
lemma foldl_to_list (f : α → β → α) (xs : t β) (x : α) :
foldl f x xs = list.foldl f x (to_list xs) :=
by { rw ← foldl.unop_of_free_monoid,
simp only [foldl, to_list_spec, fold_map_hom_free (foldl.of_free_monoid f), foldl.of_free_monoid_comp_free_mk, foldl.get] }
lemma foldr_to_list (f : α → β → β) (xs : t α) (x : β) :
foldr f x xs = list.foldr f x (to_list xs) :=
by { change _ = foldr.of_free_monoid _ _ _,
simp only [foldr, to_list_spec, fold_map_hom_free (foldr.of_free_monoid f), foldr.of_free_monoid_comp_free_mk, foldr.get] }
lemma to_list_map (f : α → β) (xs : t α) :
to_list (f <$> xs) = f <$> to_list xs :=
by simp only [to_list_spec,free.map_eq_map,fold_map_hom (free.map f), fold_map_map]; refl
@[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) :
foldl f a (g <$> l) = foldl (λ x y, f x (g y)) a l :=
by simp only [foldl, fold_map_map, (∘), flip]
@[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) :
foldr f a (g <$> l) = foldr (f ∘ g) a l :=
by simp only [foldr, fold_map_map, (∘), flip]
@[simp] theorem to_list_eq_self {xs : list α} : to_list xs = xs :=
begin
simp only [to_list_spec, fold_map, traverse],
induction xs,
case list.nil { refl },
case list.cons : _ _ ih { unfold list.traverse list.ret, rw ih, refl }
end
theorem length_to_list {xs : t α} : length xs = list.length (to_list xs) :=
begin
unfold length,
rw foldl_to_list,
generalize : to_list xs = ys,
let f := λ (n : ℕ) (a : α), n + 1,
transitivity list.foldl f 0 ys,
{ generalize : 0 = n,
induction ys with _ _ ih generalizing n,
{ simp only [list.foldl_nil] },
{ simp only [list.foldl, ih (n+1)] } },
{ induction ys with _ tl ih,
{ simp only [list.length, list.foldl_nil] },
{ simp only [list.foldl, list.length],
rw [← ih],
exact tl.foldl_hom (λx, x+1) f f 0 (λ n x, rfl) } }
end
variables {m : Type u → Type u} [monad m] [is_lawful_monad m]
lemma mfoldl_to_list {f : α → β → m α} {x : α} {xs : t β} :
mfoldl f x xs = list.mfoldl f x (to_list xs) :=
by { change _ = unop (mfoldl.of_free_monoid f (to_list xs)) x,
simp only [mfoldl, to_list_spec, fold_map_hom_free (mfoldl.of_free_monoid f), mfoldl.of_free_monoid_comp_free_mk, mfoldl.get] }
lemma mfoldr_to_list (f : α → β → m β) (x : β) (xs : t α) :
mfoldr f x xs = list.mfoldr f x (to_list xs) :=
by { change _ = mfoldr.of_free_monoid f (to_list xs) x,
simp only [mfoldr, to_list_spec, fold_map_hom_free (mfoldr.of_free_monoid f), mfoldr.of_free_monoid_comp_free_mk, mfoldr.get] }
@[simp] theorem mfoldl_map (g : β → γ) (f : α → γ → m α) (a : α) (l : t β) :
mfoldl f a (g <$> l) = mfoldl (λ x y, f x (g y)) a l :=
by simp only [mfoldl, fold_map_map, (∘), flip]
@[simp] theorem mfoldr_map (g : β → γ) (f : γ → α → m α) (a : α) (l : t β) :
mfoldr f a (g <$> l) = mfoldr (f ∘ g) a l :=
by simp only [mfoldr, fold_map_map, (∘), flip]
end equalities
end traversable
|
fc1e40072a997d5c10fc87a6ee8f27342511598f | 8b9f17008684d796c8022dab552e42f0cb6fb347 | /hott/init/tactic.hlean | 2c11101649dae7210b3ad8bbda10f7a4cb9f37fc | [
"Apache-2.0"
] | permissive | chubbymaggie/lean | 0d06ae25f9dd396306fb02190e89422ea94afd7b | d2c7b5c31928c98f545b16420d37842c43b4ae9a | refs/heads/master | 1,611,313,622,901 | 1,430,266,839,000 | 1,430,267,083,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,051 | hlean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: init.tactic
Author: Leonardo de Moura
This is just a trick to embed the 'tactic language' as a Lean
expression. We should view 'tactic' as automation that when execute
produces a term. tactic.builtin is just a "dummy" for creating the
definitions that are actually implemented in C++
-/
prelude
import init.datatypes init.reserved_notation init.num
inductive tactic :
Type := builtin : tactic
namespace tactic
-- Remark the following names are not arbitrary, the tactic module
-- uses them when converting Lean expressions into actual tactic objects.
-- The bultin 'by' construct triggers the process of converting a
-- a term of type 'tactic' into a tactic that sythesizes a term
opaque definition and_then (t1 t2 : tactic) : tactic := builtin
opaque definition or_else (t1 t2 : tactic) : tactic := builtin
opaque definition append (t1 t2 : tactic) : tactic := builtin
opaque definition interleave (t1 t2 : tactic) : tactic := builtin
opaque definition par (t1 t2 : tactic) : tactic := builtin
opaque definition fixpoint (f : tactic → tactic) : tactic := builtin
opaque definition repeat (t : tactic) : tactic := builtin
opaque definition at_most (t : tactic) (k : num) : tactic := builtin
opaque definition discard (t : tactic) (k : num) : tactic := builtin
opaque definition focus_at (t : tactic) (i : num) : tactic := builtin
opaque definition try_for (t : tactic) (ms : num) : tactic := builtin
opaque definition all_goals (t : tactic) : tactic := builtin
opaque definition now : tactic := builtin
opaque definition assumption : tactic := builtin
opaque definition eassumption : tactic := builtin
opaque definition state : tactic := builtin
opaque definition fail : tactic := builtin
opaque definition id : tactic := builtin
opaque definition beta : tactic := builtin
opaque definition info : tactic := builtin
opaque definition whnf : tactic := builtin
opaque definition rotate_left (k : num) := builtin
opaque definition rotate_right (k : num) := builtin
definition rotate (k : num) := rotate_left k
-- This is just a trick to embed expressions into tactics.
-- The nested expressions are "raw". They tactic should
-- elaborate them when it is executed.
inductive expr : Type :=
builtin : expr
inductive expr_list : Type :=
| nil : expr_list
| cons : expr → expr_list → expr_list
-- auxiliary type used to mark optional list of arguments
definition opt_expr_list := expr_list
-- auxiliary types used to mark that the expression (list) is an identifier (list)
definition identifier := expr
definition identifier_list := expr_list
definition opt_identifier_list := expr_list
opaque definition apply (e : expr) : tactic := builtin
opaque definition fapply (e : expr) : tactic := builtin
opaque definition rename (a b : identifier) : tactic := builtin
opaque definition intro (e : identifier) : tactic := builtin
opaque definition generalize (e : expr) : tactic := builtin
opaque definition clear (e : identifier) : tactic := builtin
opaque definition revert (e : identifier) : tactic := builtin
opaque definition refine (e : expr) : tactic := builtin
opaque definition exact (e : expr) : tactic := builtin
-- Relaxed version of exact that does not enforce goal type
opaque definition rexact (e : expr) : tactic := builtin
opaque definition check_expr (e : expr) : tactic := builtin
opaque definition trace (s : string) : tactic := builtin
-- rewrite_tac is just a marker for the builtin 'rewrite' notation
-- used to create instances of this tactic.
opaque definition rewrite_tac (e : expr_list) : tactic := builtin
opaque definition cases (id : identifier) (ids : opt_identifier_list) : tactic := builtin
opaque definition intros (ids : opt_identifier_list) : tactic := builtin
opaque definition generalizes (es : expr_list) : tactic := builtin
opaque definition clears (ids : identifier_list) : tactic := builtin
opaque definition reverts (ids : identifier_list) : tactic := builtin
opaque definition change (e : expr) : tactic := builtin
opaque definition assert_hypothesis (id : identifier) (e : expr) : tactic := builtin
opaque definition lettac (id : identifier) (e : expr) : tactic := builtin
definition try (t : tactic) : tactic := or_else t id
definition repeat1 (t : tactic) : tactic := and_then t (repeat t)
definition focus (t : tactic) : tactic := focus_at t 0
definition determ (t : tactic) : tactic := at_most t 1
definition trivial : tactic := or_else (apply eq.refl) assumption
definition do (n : num) (t : tactic) : tactic :=
nat.rec id (λn t', and_then t t') (nat.of_num n)
end tactic
tactic_infixl `;`:15 := tactic.and_then
tactic_notation `(` h `|` r:(foldl `|` (e r, tactic.or_else r e) h) `)` := r
|
e589379fef6cf8c80703f42da7157f4fea9fcd6d | 75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2 | /tests/lean/run/class8.lean | 70efc9c92cc8aee65d77b06b283bb995edcb9a5f | [
"Apache-2.0"
] | permissive | jroesch/lean | 30ef0860fa905d35b9ad6f76de1a4f65c9af6871 | 3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2 | refs/heads/master | 1,586,090,835,348 | 1,455,142,203,000 | 1,455,142,277,000 | 51,536,958 | 1 | 0 | null | 1,455,215,811,000 | 1,455,215,811,000 | null | UTF-8 | Lean | false | false | 1,096 | lean | import logic data.prod
open tactic prod
inductive inh [class] (A : Type) : Prop :=
intro : A -> inh A
attribute inh.intro [instance]
theorem inh_elim {A : Type} {B : Prop} (H1 : inh A) (H2 : A → B) : B
:= inh.rec H2 H1
theorem inh_exists {A : Type} {P : A → Prop} (H : ∃x, P x) : inh A
:= obtain w Hw, from H, inh.intro w
theorem inh_bool [instance] : inh Prop
:= inh.intro true
theorem inh_fun [instance] {A B : Type} [H : inh B] : inh (A → B)
:= inh.rec (λb, inh.intro (λa : A, b)) H
theorem pair_inh [instance] {A : Type} {B : Type} [H1 : inh A] [H2 : inh B] : inh (prod A B)
:= inh_elim H1 (λa, inh_elim H2 (λb, inh.intro (pair a b)))
definition assump := eassumption
tactic_hint assump
theorem tst {A B : Type} (H : inh B) : inh (A → B → B)
set_option trace.class_instances true
theorem T1 {A B C D : Type} {P : C → Prop} (a : A) (H1 : inh B) (H2 : ∃x, P x) : inh ((A → A) × B × (D → C) × Prop) :=
have h1 [visible] : inh A, from inh.intro a,
have h2 [visible] : inh C, from inh_exists H2,
by exact _
reveal T1
(*
print(get_env():find("T1"):value())
*)
|
451f653aefff0a87898df7982c25eb8563418350 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/geometry/euclidean/triangle.lean | c27a9f89ddaa985d4108818f1f5013622b992375 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 19,318 | lean | /-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Manuel Candales
-/
import geometry.euclidean.basic
import tactic.interval_cases
/-!
# Triangles
This file proves basic geometrical results about distances and angles
in (possibly degenerate) triangles in real inner product spaces and
Euclidean affine spaces. More specialized results, and results
developed for simplices in general rather than just for triangles, are
in separate files. Definitions and results that make sense in more
general affine spaces rather than just in the Euclidean case go under
`linear_algebra.affine_space`.
## Implementation notes
Results in this file are generally given in a form with only those
non-degeneracy conditions needed for the particular result, rather
than requiring affine independence of the points of a triangle
unnecessarily.
## References
* https://en.wikipedia.org/wiki/Pythagorean_theorem
* https://en.wikipedia.org/wiki/Law_of_cosines
* https://en.wikipedia.org/wiki/Pons_asinorum
* https://en.wikipedia.org/wiki/Sum_of_angles_of_a_triangle
-/
noncomputable theory
open_locale big_operators
open_locale classical
open_locale real
open_locale real_inner_product_space
namespace inner_product_geometry
/-!
### Geometrical results on triangles in real inner product spaces
This section develops some results on (possibly degenerate) triangles
in real inner product spaces, where those definitions and results can
most conveniently be developed in terms of vectors and then used to
deduce corresponding results for Euclidean affine spaces.
-/
variables {V : Type*} [inner_product_space ℝ V]
/-- Pythagorean theorem, if-and-only-if vector angle form. -/
lemma norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) :
∥x + y∥ * ∥x + y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ ↔ angle x y = π / 2 :=
begin
rw norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero,
exact inner_eq_zero_iff_angle_eq_pi_div_two x y
end
/-- Pythagorean theorem, vector angle form. -/
lemma norm_add_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) :
∥x + y∥ * ∥x + y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ :=
(norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h
/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector angle form. -/
lemma norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) :
∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ ↔ angle x y = π / 2 :=
begin
rw norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero,
exact inner_eq_zero_iff_angle_eq_pi_div_two x y
end
/-- Pythagorean theorem, subtracting vectors, vector angle form. -/
lemma norm_sub_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) :
∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ :=
(norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h
/-- Law of cosines (cosine rule), vector angle form. -/
lemma norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle
(x y : V) :
∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ - 2 * ∥x∥ * ∥y∥ * real.cos (angle x y) :=
by rw [(show 2 * ∥x∥ * ∥y∥ * real.cos (angle x y) =
2 * (real.cos (angle x y) * (∥x∥ * ∥y∥)), by ring),
cos_angle_mul_norm_mul_norm, ←real_inner_self_eq_norm_mul_norm,
←real_inner_self_eq_norm_mul_norm, ←real_inner_self_eq_norm_mul_norm,
real_inner_sub_sub_self, sub_add_eq_add_sub]
/-- Pons asinorum, vector angle form. -/
lemma angle_sub_eq_angle_sub_rev_of_norm_eq {x y : V} (h : ∥x∥ = ∥y∥) :
angle x (x - y) = angle y (y - x) :=
begin
refine real.inj_on_cos ⟨angle_nonneg _ _, angle_le_pi _ _⟩ ⟨angle_nonneg _ _, angle_le_pi _ _⟩ _,
rw [cos_angle, cos_angle, h, ←neg_sub, norm_neg, neg_sub,
inner_sub_right, inner_sub_right, real_inner_self_eq_norm_mul_norm,
real_inner_self_eq_norm_mul_norm, h, real_inner_comm x y]
end
/-- Converse of pons asinorum, vector angle form. -/
lemma norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi {x y : V}
(h : angle x (x - y) = angle y (y - x)) (hpi : angle x y ≠ π) : ∥x∥ = ∥y∥ :=
begin
replace h := real.arccos_inj_on
(abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x (x - y)))
(abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one y (y - x))) h,
by_cases hxy : x = y,
{ rw hxy },
{ rw [←norm_neg (y - x), neg_sub, mul_comm, mul_comm ∥y∥, div_eq_mul_inv, div_eq_mul_inv,
mul_inv_rev, mul_inv_rev, ←mul_assoc, ←mul_assoc] at h,
replace h :=
mul_right_cancel₀ (inv_ne_zero (λ hz, hxy (eq_of_sub_eq_zero (norm_eq_zero.1 hz)))) h,
rw [inner_sub_right, inner_sub_right, real_inner_comm x y, real_inner_self_eq_norm_mul_norm,
real_inner_self_eq_norm_mul_norm, mul_sub_right_distrib, mul_sub_right_distrib,
mul_self_mul_inv, mul_self_mul_inv, sub_eq_sub_iff_sub_eq_sub,
←mul_sub_left_distrib] at h,
by_cases hx0 : x = 0,
{ rw [hx0, norm_zero, inner_zero_left, zero_mul, zero_sub, neg_eq_zero] at h,
rw [hx0, norm_zero, h] },
{ by_cases hy0 : y = 0,
{ rw [hy0, norm_zero, inner_zero_right, zero_mul, sub_zero] at h,
rw [hy0, norm_zero, h] },
{ rw [inv_sub_inv (λ hz, hx0 (norm_eq_zero.1 hz)) (λ hz, hy0 (norm_eq_zero.1 hz)),
←neg_sub, ←mul_div_assoc, mul_comm, mul_div_assoc, ←mul_neg_one] at h,
symmetry,
by_contradiction hyx,
replace h := (mul_left_cancel₀ (sub_ne_zero_of_ne hyx) h).symm,
rw [real_inner_div_norm_mul_norm_eq_neg_one_iff, ←angle_eq_pi_iff] at h,
exact hpi h } } }
end
/-- The cosine of the sum of two angles in a possibly degenerate
triangle (where two given sides are nonzero), vector angle form. -/
lemma cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
real.cos (angle x (x - y) + angle y (y - x)) = -real.cos (angle x y) :=
begin
by_cases hxy : x = y,
{ rw [hxy, angle_self hy],
simp },
{ rw [real.cos_add, cos_angle, cos_angle, cos_angle],
have hxn : ∥x∥ ≠ 0 := (λ h, hx (norm_eq_zero.1 h)),
have hyn : ∥y∥ ≠ 0 := (λ h, hy (norm_eq_zero.1 h)),
have hxyn : ∥x - y∥ ≠ 0 := (λ h, hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h))),
apply mul_right_cancel₀ hxn,
apply mul_right_cancel₀ hyn,
apply mul_right_cancel₀ hxyn,
apply mul_right_cancel₀ hxyn,
have H1 : real.sin (angle x (x - y)) * real.sin (angle y (y - x)) *
∥x∥ * ∥y∥ * ∥x - y∥ * ∥x - y∥ =
(real.sin (angle x (x - y)) * (∥x∥ * ∥x - y∥)) *
(real.sin (angle y (y - x)) * (∥y∥ * ∥x - y∥)), { ring },
have H2 : ⟪x, x⟫ * (inner x x - inner x y - (inner x y - inner y y)) -
(inner x x - inner x y) * (inner x x - inner x y) =
inner x x * inner y y - inner x y * inner x y, { ring },
have H3 : ⟪y, y⟫ * (inner y y - inner x y - (inner x y - inner x x)) -
(inner y y - inner x y) * (inner y y - inner x y) =
inner x x * inner y y - inner x y * inner x y, { ring },
rw [mul_sub_right_distrib, mul_sub_right_distrib, mul_sub_right_distrib,
mul_sub_right_distrib, H1, sin_angle_mul_norm_mul_norm, norm_sub_rev x y,
sin_angle_mul_norm_mul_norm, norm_sub_rev y x, inner_sub_left, inner_sub_left,
inner_sub_right, inner_sub_right, inner_sub_right, inner_sub_right, real_inner_comm x y, H2,
H3, real.mul_self_sqrt (sub_nonneg_of_le (real_inner_mul_inner_self_le x y)),
real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm,
real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two],
field_simp [hxn, hyn, hxyn],
ring }
end
/-- The sine of the sum of two angles in a possibly degenerate
triangle (where two given sides are nonzero), vector angle form. -/
lemma sin_angle_sub_add_angle_sub_rev_eq_sin_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
real.sin (angle x (x - y) + angle y (y - x)) = real.sin (angle x y) :=
begin
by_cases hxy : x = y,
{ rw [hxy, angle_self hy],
simp },
{ rw [real.sin_add, cos_angle, cos_angle],
have hxn : ∥x∥ ≠ 0 := (λ h, hx (norm_eq_zero.1 h)),
have hyn : ∥y∥ ≠ 0 := (λ h, hy (norm_eq_zero.1 h)),
have hxyn : ∥x - y∥ ≠ 0 := (λ h, hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h))),
apply mul_right_cancel₀ hxn,
apply mul_right_cancel₀ hyn,
apply mul_right_cancel₀ hxyn,
apply mul_right_cancel₀ hxyn,
have H1 : real.sin (angle x (x - y)) * (⟪y, y - x⟫ / (∥y∥ * ∥y - x∥)) * ∥x∥ * ∥y∥ * ∥x - y∥ =
real.sin (angle x (x - y)) * (∥x∥ * ∥x - y∥) *
(⟪y, y - x⟫ / (∥y∥ * ∥y - x∥)) * ∥y∥, { ring },
have H2 : ⟪x, x - y⟫ / (∥x∥ * ∥y - x∥) * real.sin (angle y (y - x)) * ∥x∥ * ∥y∥ * ∥y - x∥ =
⟪x, x - y⟫ / (∥x∥ * ∥y - x∥) *
(real.sin (angle y (y - x)) * (∥y∥ * ∥y - x∥)) * ∥x∥, { ring },
have H3 : ⟪x, x⟫ * (⟪x, x⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪y, y⟫)) -
(⟪x, x⟫ - ⟪x, y⟫) * (⟪x, x⟫ - ⟪x, y⟫) =
⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫, { ring },
have H4 : ⟪y, y⟫ * (⟪y, y⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪x, x⟫)) -
(⟪y, y⟫ - ⟪x, y⟫) * (⟪y, y⟫ - ⟪x, y⟫) =
⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫, { ring },
rw [right_distrib, right_distrib, right_distrib, right_distrib, H1,
sin_angle_mul_norm_mul_norm, norm_sub_rev x y, H2, sin_angle_mul_norm_mul_norm,
norm_sub_rev y x, mul_assoc (real.sin (angle x y)), sin_angle_mul_norm_mul_norm,
inner_sub_left, inner_sub_left, inner_sub_right, inner_sub_right, inner_sub_right,
inner_sub_right, real_inner_comm x y, H3, H4, real_inner_self_eq_norm_mul_norm,
real_inner_self_eq_norm_mul_norm,
real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two],
field_simp [hxn, hyn, hxyn],
ring }
end
/-- The cosine of the sum of the angles of a possibly degenerate
triangle (where two given sides are nonzero), vector angle form. -/
lemma cos_angle_add_angle_sub_add_angle_sub_eq_neg_one {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
real.cos (angle x y + angle x (x - y) + angle y (y - x)) = -1 :=
by rw [add_assoc, real.cos_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy,
sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy, mul_neg, ←neg_add',
add_comm, ←sq, ←sq, real.sin_sq_add_cos_sq]
/-- The sine of the sum of the angles of a possibly degenerate
triangle (where two given sides are nonzero), vector angle form. -/
lemma sin_angle_add_angle_sub_add_angle_sub_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
real.sin (angle x y + angle x (x - y) + angle y (y - x)) = 0 :=
begin
rw [add_assoc, real.sin_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy,
sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy],
ring
end
/-- The sum of the angles of a possibly degenerate triangle (where the
two given sides are nonzero), vector angle form. -/
lemma angle_add_angle_sub_add_angle_sub_eq_pi {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
angle x y + angle x (x - y) + angle y (y - x) = π :=
begin
have hcos := cos_angle_add_angle_sub_add_angle_sub_eq_neg_one hx hy,
have hsin := sin_angle_add_angle_sub_add_angle_sub_eq_zero hx hy,
rw real.sin_eq_zero_iff at hsin,
cases hsin with n hn,
symmetry' at hn,
have h0 : 0 ≤ angle x y + angle x (x - y) + angle y (y - x) :=
add_nonneg (add_nonneg (angle_nonneg _ _) (angle_nonneg _ _)) (angle_nonneg _ _),
have h3 : angle x y + angle x (x - y) + angle y (y - x) ≤ π + π + π :=
add_le_add (add_le_add (angle_le_pi _ _) (angle_le_pi _ _)) (angle_le_pi _ _),
have h3lt : angle x y + angle x (x - y) + angle y (y - x) < π + π + π,
{ by_contradiction hnlt,
have hxy : angle x y = π,
{ by_contradiction hxy,
exact hnlt (add_lt_add_of_lt_of_le (add_lt_add_of_lt_of_le
(lt_of_le_of_ne (angle_le_pi _ _) hxy)
(angle_le_pi _ _)) (angle_le_pi _ _)) },
rw hxy at hnlt,
rw angle_eq_pi_iff at hxy,
rcases hxy with ⟨hx, ⟨r, ⟨hr, hxr⟩⟩⟩,
rw [hxr, ←one_smul ℝ x, ←mul_smul, mul_one, ←sub_smul, one_smul, sub_eq_add_neg,
angle_smul_right_of_pos _ _ (add_pos zero_lt_one (neg_pos_of_neg hr)), angle_self hx,
add_zero] at hnlt,
apply hnlt,
rw add_assoc,
exact add_lt_add_left (lt_of_le_of_lt (angle_le_pi _ _)
(lt_add_of_pos_right π real.pi_pos)) _ },
have hn0 : 0 ≤ n,
{ rw [hn, mul_nonneg_iff_left_nonneg_of_pos real.pi_pos] at h0,
norm_cast at h0,
exact h0 },
have hn3 : n < 3,
{ rw [hn, (show π + π + π = 3 * π, by ring)] at h3lt,
replace h3lt := lt_of_mul_lt_mul_right h3lt (le_of_lt real.pi_pos),
norm_cast at h3lt,
exact h3lt },
interval_cases n,
{ rw hn at hcos,
simp at hcos,
norm_num at hcos },
{ rw hn,
norm_num },
{ rw hn at hcos,
simp at hcos,
norm_num at hcos },
end
end inner_product_geometry
namespace euclidean_geometry
/-!
### Geometrical results on triangles in Euclidean affine spaces
This section develops some geometrical definitions and results on
(possible degenerate) triangles in Euclidean affine spaces.
-/
open inner_product_geometry
open_locale euclidean_geometry
variables {V : Type*} {P : Type*} [inner_product_space ℝ V] [metric_space P]
[normed_add_torsor V P]
include V
/-- **Pythagorean theorem**, if-and-only-if angle-at-point form. -/
lemma dist_sq_eq_dist_sq_add_dist_sq_iff_angle_eq_pi_div_two (p1 p2 p3 : P) :
dist p1 p3 * dist p1 p3 = dist p1 p2 * dist p1 p2 + dist p3 p2 * dist p3 p2 ↔
∠ p1 p2 p3 = π / 2 :=
by erw [dist_comm p3 p2, dist_eq_norm_vsub V p1 p3, dist_eq_norm_vsub V p1 p2,
dist_eq_norm_vsub V p2 p3,
←norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two,
vsub_sub_vsub_cancel_right p1, ←neg_vsub_eq_vsub_rev p2 p3, norm_neg]
/-- **Law of cosines** (cosine rule), angle-at-point form. -/
lemma dist_sq_eq_dist_sq_add_dist_sq_sub_two_mul_dist_mul_dist_mul_cos_angle
(p1 p2 p3 : P) :
dist p1 p3 * dist p1 p3 =
dist p1 p2 * dist p1 p2 + dist p3 p2 * dist p3 p2 -
2 * dist p1 p2 * dist p3 p2 * real.cos (∠ p1 p2 p3) :=
begin
rw [dist_eq_norm_vsub V p1 p3, dist_eq_norm_vsub V p1 p2, dist_eq_norm_vsub V p3 p2],
unfold angle,
convert norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle
(p1 -ᵥ p2 : V) (p3 -ᵥ p2 : V),
{ exact (vsub_sub_vsub_cancel_right p1 p3 p2).symm },
{ exact (vsub_sub_vsub_cancel_right p1 p3 p2).symm }
end
alias dist_sq_eq_dist_sq_add_dist_sq_sub_two_mul_dist_mul_dist_mul_cos_angle ← law_cos
/-- **Isosceles Triangle Theorem**: Pons asinorum, angle-at-point form. -/
lemma angle_eq_angle_of_dist_eq {p1 p2 p3 : P} (h : dist p1 p2 = dist p1 p3) :
∠ p1 p2 p3 = ∠ p1 p3 p2 :=
begin
rw [dist_eq_norm_vsub V p1 p2, dist_eq_norm_vsub V p1 p3] at h,
unfold angle,
convert angle_sub_eq_angle_sub_rev_of_norm_eq h,
{ exact (vsub_sub_vsub_cancel_left p3 p2 p1).symm },
{ exact (vsub_sub_vsub_cancel_left p2 p3 p1).symm }
end
/-- Converse of pons asinorum, angle-at-point form. -/
lemma dist_eq_of_angle_eq_angle_of_angle_ne_pi {p1 p2 p3 : P} (h : ∠ p1 p2 p3 = ∠ p1 p3 p2)
(hpi : ∠ p2 p1 p3 ≠ π) : dist p1 p2 = dist p1 p3 :=
begin
unfold angle at h hpi,
rw [dist_eq_norm_vsub V p1 p2, dist_eq_norm_vsub V p1 p3],
rw [←angle_neg_neg, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] at hpi,
rw [←vsub_sub_vsub_cancel_left p3 p2 p1, ←vsub_sub_vsub_cancel_left p2 p3 p1] at h,
exact norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi h hpi
end
/-- The **sum of the angles of a triangle** (possibly degenerate, where the
given vertex is distinct from the others), angle-at-point. -/
lemma angle_add_angle_add_angle_eq_pi {p1 p2 p3 : P} (h2 : p2 ≠ p1) (h3 : p3 ≠ p1) :
∠ p1 p2 p3 + ∠ p2 p3 p1 + ∠ p3 p1 p2 = π :=
begin
rw [add_assoc, add_comm, add_comm (∠ p2 p3 p1), angle_comm p2 p3 p1],
unfold angle,
rw [←angle_neg_neg (p1 -ᵥ p3), ←angle_neg_neg (p1 -ᵥ p2), neg_vsub_eq_vsub_rev,
neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev,
←vsub_sub_vsub_cancel_right p3 p2 p1, ←vsub_sub_vsub_cancel_right p2 p3 p1],
exact angle_add_angle_sub_add_angle_sub_eq_pi (λ he, h3 (vsub_eq_zero_iff_eq.1 he))
(λ he, h2 (vsub_eq_zero_iff_eq.1 he))
end
/-- **Stewart's Theorem**. -/
theorem dist_sq_mul_dist_add_dist_sq_mul_dist (a b c p : P) (h : ∠ b p c = π) :
dist a b ^ 2 * dist c p + dist a c ^ 2 * dist b p =
dist b c * (dist a p ^ 2 + dist b p * dist c p) :=
begin
rw [pow_two, pow_two, law_cos a p b, law_cos a p c,
eq_sub_of_add_eq (angle_add_angle_eq_pi_of_angle_eq_pi a h), real.cos_pi_sub,
dist_eq_add_dist_of_angle_eq_pi h],
ring,
end
/-- **Apollonius's Theorem**. -/
theorem dist_sq_add_dist_sq_eq_two_mul_dist_midpoint_sq_add_half_dist_sq (a b c : P) :
dist a b ^ 2 + dist a c ^ 2 = 2 * (dist a (midpoint ℝ b c) ^ 2 + (dist b c / 2) ^ 2) :=
begin
by_cases hbc : b = c,
{ simp [hbc, midpoint_self, dist_self, two_mul] },
{ let m := midpoint ℝ b c,
have : dist b c ≠ 0 := (dist_pos.mpr hbc).ne',
have hm := dist_sq_mul_dist_add_dist_sq_mul_dist a b c m (angle_midpoint_eq_pi b c hbc),
simp only [dist_left_midpoint, dist_right_midpoint, real.norm_two] at hm,
calc dist a b ^ 2 + dist a c ^ 2
= 2 / dist b c * (dist a b ^ 2 * (2⁻¹ * dist b c) + dist a c ^ 2 * (2⁻¹ * dist b c)) :
by { field_simp, ring }
... = 2 * (dist a (midpoint ℝ b c) ^ 2 + (dist b c / 2) ^ 2) :
by { rw hm, field_simp, ring } },
end
lemma dist_mul_of_eq_angle_of_dist_mul (a b c a' b' c' : P) (r : ℝ) (h : ∠ a' b' c' = ∠ a b c)
(hab : dist a' b' = r * dist a b) (hcb : dist c' b' = r * dist c b) :
dist a' c' = r * dist a c :=
begin
have h' : dist a' c' ^ 2 = (r * dist a c) ^ 2,
calc dist a' c' ^ 2
= dist a' b' ^ 2 + dist c' b' ^ 2 - 2 * dist a' b' * dist c' b' * real.cos (∠ a' b' c') :
by { simp [pow_two, law_cos a' b' c'] }
... = r ^ 2 * (dist a b ^ 2 + dist c b ^ 2 - 2 * dist a b * dist c b * real.cos (∠ a b c)) :
by { rw [h, hab, hcb], ring }
... = (r * dist a c) ^ 2 : by simp [pow_two, ← law_cos a b c, mul_pow],
by_cases hab₁ : a = b,
{ have hab'₁ : a' = b', { rw [← dist_eq_zero, hab, dist_eq_zero.mpr hab₁, mul_zero r] },
rw [hab₁, hab'₁, dist_comm b' c', dist_comm b c, hcb] },
{ have h1 : 0 ≤ r * dist a b, { rw ← hab, exact dist_nonneg },
have h2 : 0 ≤ r := nonneg_of_mul_nonneg_left h1 (dist_pos.mpr hab₁),
exact (sq_eq_sq dist_nonneg (mul_nonneg h2 dist_nonneg)).mp h' },
end
end euclidean_geometry
|
67bff2d37723f10305f5922a48c0434415090fb8 | 2a70b774d16dbdf5a533432ee0ebab6838df0948 | /_target/deps/mathlib/src/algebra/lie/basic.lean | f0113c66cb318ef85d751a6e159d1adc5bf3c480 | [
"Apache-2.0"
] | permissive | hjvromen/lewis | 40b035973df7c77ebf927afab7878c76d05ff758 | 105b675f73630f028ad5d890897a51b3c1146fb0 | refs/heads/master | 1,677,944,636,343 | 1,676,555,301,000 | 1,676,555,301,000 | 327,553,599 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 61,114 | lean | /-
Copyright (c) 2019 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import data.bracket
import algebra.algebra.basic
import linear_algebra.bilinear_form
import linear_algebra.matrix
import tactic.noncomm_ring
/-!
# Lie algebras
This file defines Lie rings, and Lie algebras over a commutative ring. It shows how these arise from
associative rings and algebras via the ring commutator. In particular it defines the Lie algebra
of endomorphisms of a module as well as of the algebra of square matrices over a commutative ring.
It also includes definitions of morphisms of Lie algebras, Lie subalgebras, Lie modules, Lie
submodules, and the quotient of a Lie algebra by an ideal.
## Notations
We introduce the notation ⁅x, y⁆ for the Lie bracket. Note that these are the Unicode "square with
quill" brackets rather than the usual square brackets.
Working over a fixed commutative ring `R`, we introduce the notations:
* `L →ₗ⁅R⁆ L'` for a morphism of Lie algebras,
* `L ≃ₗ⁅R⁆ L'` for an equivalence of Lie algebras,
* `M →ₗ⁅R,L⁆ N` for a morphism of Lie algebra modules `M`, `N` over a Lie algebra `L`,
* `M ≃ₗ⁅R,L⁆ N` for an equivalence of Lie algebra modules `M`, `N` over a Lie algebra `L`.
## Implementation notes
Lie algebras are defined as modules with a compatible Lie ring structure and thus, like modules,
are partially unbundled.
## References
* [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 1--3*][bourbaki1975]
## Tags
lie bracket, ring commutator, jacobi identity, lie ring, lie algebra
-/
universes u v w w₁ w₂
/-- A Lie ring is an additive group with compatible product, known as the bracket, satisfying the
Jacobi identity. The bracket is not associative unless it is identically zero. -/
@[protect_proj] class lie_ring (L : Type v) extends add_comm_group L, has_bracket L L :=
(add_lie : ∀ (x y z : L), ⁅x + y, z⁆ = ⁅x, z⁆ + ⁅y, z⁆)
(lie_add : ∀ (x y z : L), ⁅x, y + z⁆ = ⁅x, y⁆ + ⁅x, z⁆)
(lie_self : ∀ (x : L), ⁅x, x⁆ = 0)
(leibniz_lie : ∀ (x y z : L), ⁅x, ⁅y, z⁆⁆ = ⁅⁅x, y⁆, z⁆ + ⁅y, ⁅x, z⁆⁆)
/-- A Lie algebra is a module with compatible product, known as the bracket, satisfying the Jacobi
identity. Forgetting the scalar multiplication, every Lie algebra is a Lie ring. -/
@[protect_proj] class lie_algebra (R : Type u) (L : Type v) [comm_ring R] [lie_ring L] extends semimodule R L :=
(lie_smul : ∀ (t : R) (x y : L), ⁅x, t • y⁆ = t • ⁅x, y⁆)
/-- A Lie ring module is an additive group, together with an additive action of a
Lie ring on this group, such that the Lie bracket acts as the commutator of endomorphisms.
(For representations of Lie *algebras* see `lie_module`.) -/
@[protect_proj] class lie_ring_module (L : Type v) (M : Type w)
[lie_ring L] [add_comm_group M] extends has_bracket L M :=
(add_lie : ∀ (x y : L) (m : M), ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆)
(lie_add : ∀ (x : L) (m n : M), ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆)
(leibniz_lie : ∀ (x y : L) (m : M), ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆)
/-- A Lie module is a module over a commutative ring, together with a linear action of a Lie
algebra on this module, such that the Lie bracket acts as the commutator of endomorphisms. -/
@[protect_proj] class lie_module (R : Type u) (L : Type v) (M : Type w)
[comm_ring R] [lie_ring L] [lie_algebra R L] [add_comm_group M] [module R M] [lie_ring_module L M] :=
(smul_lie : ∀ (t : R) (x : L) (m : M), ⁅t • x, m⁆ = t • ⁅x, m⁆)
(lie_smul : ∀ (t : R) (x : L) (m : M), ⁅x, t • m⁆ = t • ⁅x, m⁆)
section basic_properties
variables {R : Type u} {L : Type v} {M : Type w}
variables [comm_ring R] [lie_ring L] [lie_algebra R L] [add_comm_group M] [module R M]
variables [lie_ring_module L M] [lie_module R L M]
variables (t : R) (x y z : L) (m n : M)
@[simp] lemma add_lie : ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ := lie_ring_module.add_lie x y m
@[simp] lemma lie_add : ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ := lie_ring_module.lie_add x m n
@[simp] lemma smul_lie : ⁅t • x, m⁆ = t • ⁅x, m⁆ := lie_module.smul_lie t x m
@[simp] lemma lie_smul : ⁅x, t • m⁆ = t • ⁅x, m⁆ := lie_module.lie_smul t x m
lemma leibniz_lie : ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ := lie_ring_module.leibniz_lie x y m
@[simp] lemma lie_zero : ⁅x, 0⁆ = (0 : M) := (add_monoid_hom.mk' _ (lie_add x)).map_zero
@[simp] lemma zero_lie : ⁅(0 : L), m⁆ = 0 :=
(add_monoid_hom.mk' (λ (x : L), ⁅x, m⁆) (λ x y, add_lie x y m)).map_zero
@[simp] lemma lie_self : ⁅x, x⁆ = 0 := lie_ring.lie_self x
instance lie_ring_self_module : lie_ring_module L L := { ..(infer_instance : lie_ring L) }
@[simp] lemma lie_skew : -⁅y, x⁆ = ⁅x, y⁆ :=
have h : ⁅x + y, x⁆ + ⁅x + y, y⁆ = 0, { rw ← lie_add, apply lie_self, },
by simpa [neg_eq_iff_add_eq_zero] using h
/-- Every Lie algebra is a module over itself. -/
instance lie_algebra_self_module : lie_module R L L :=
{ smul_lie := λ t x m, by rw [←lie_skew, ←lie_skew x m, lie_algebra.lie_smul, smul_neg],
lie_smul := by apply lie_algebra.lie_smul, }
@[simp] lemma neg_lie : ⁅-x, m⁆ = -⁅x, m⁆ :=
by { rw [←sub_eq_zero_iff_eq, sub_neg_eq_add, ←add_lie], simp, }
@[simp] lemma lie_neg : ⁅x, -m⁆ = -⁅x, m⁆ :=
by { rw [←sub_eq_zero_iff_eq, sub_neg_eq_add, ←lie_add], simp, }
@[simp] lemma gsmul_lie (a : ℤ) : ⁅a • x, m⁆ = a • ⁅x, m⁆ :=
add_monoid_hom.map_gsmul ⟨λ (x : L), ⁅x, m⁆, zero_lie m, λ _ _, add_lie _ _ _⟩ _ _
@[simp] lemma lie_gsmul (a : ℤ) : ⁅x, a • m⁆ = a • ⁅x, m⁆ :=
add_monoid_hom.map_gsmul ⟨λ (m : M), ⁅x, m⁆, lie_zero x, λ _ _, lie_add _ _ _⟩ _ _
@[simp] lemma lie_lie : ⁅⁅x, y⁆, m⁆ = ⁅x, ⁅y, m⁆⁆ - ⁅y, ⁅x, m⁆⁆ :=
by rw [leibniz_lie, add_sub_cancel]
lemma lie_jacobi : ⁅x, ⁅y, z⁆⁆ + ⁅y, ⁅z, x⁆⁆ + ⁅z, ⁅x, y⁆⁆ = 0 :=
by { rw [← neg_neg ⁅x, y⁆, lie_neg z, lie_skew y x, ← lie_skew, lie_lie], abel, }
end basic_properties
namespace lie_algebra
set_option old_structure_cmd true
/-- A morphism of Lie algebras is a linear map respecting the bracket operations. -/
structure morphism (R : Type u) (L : Type v) (L' : Type w)
[comm_ring R] [lie_ring L] [lie_algebra R L] [lie_ring L'] [lie_algebra R L']
extends linear_map R L L' :=
(map_lie : ∀ {x y : L}, to_fun ⁅x, y⁆ = ⁅to_fun x, to_fun y⁆)
attribute [nolint doc_blame] lie_algebra.morphism.to_linear_map
notation L ` →ₗ⁅`:25 R:25 `⁆ `:0 L':0 := morphism R L L'
section morphism_properties
variables {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁}
variables [comm_ring R] [lie_ring L₁] [lie_ring L₂] [lie_ring L₃]
variables [lie_algebra R L₁] [lie_algebra R L₂] [lie_algebra R L₃]
instance : has_coe (L₁ →ₗ⁅R⁆ L₂) (L₁ →ₗ[R] L₂) := ⟨morphism.to_linear_map⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (L₁ →ₗ⁅R⁆ L₂) := ⟨_, morphism.to_fun⟩
@[simp] lemma coe_mk (f : L₁ → L₂) (h₁ h₂ h₃) :
((⟨f, h₁, h₂, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = f := rfl
@[simp, norm_cast] lemma coe_to_linear_map (f : L₁ →ₗ⁅R⁆ L₂) : ((f : L₁ →ₗ[R] L₂) : L₁ → L₂) = f :=
rfl
@[simp] lemma map_lie (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f ⁅x, y⁆ = ⁅f x, f y⁆ := morphism.map_lie f
/-- The constant 0 map is a Lie algebra morphism. -/
instance : has_zero (L₁ →ₗ⁅R⁆ L₂) := ⟨{ map_lie := by simp, ..(0 : L₁ →ₗ[R] L₂)}⟩
/-- The identity map is a Lie algebra morphism. -/
instance : has_one (L₁ →ₗ⁅R⁆ L₁) := ⟨{ map_lie := by simp, ..(1 : L₁ →ₗ[R] L₁)}⟩
instance : inhabited (L₁ →ₗ⁅R⁆ L₂) := ⟨0⟩
lemma morphism.coe_injective : function.injective (λ f : L₁ →ₗ⁅R⁆ L₂, show L₁ → L₂, from f) :=
by rintro ⟨f, _⟩ ⟨g, _⟩ ⟨h⟩; congr
@[ext] lemma morphism.ext {f g : L₁ →ₗ⁅R⁆ L₂} (h : ∀ x, f x = g x) : f = g :=
morphism.coe_injective $ funext h
lemma morphism.ext_iff {f g : L₁ →ₗ⁅R⁆ L₂} : f = g ↔ ∀ x, f x = g x :=
⟨by { rintro rfl x, refl }, morphism.ext⟩
/-- The composition of morphisms is a morphism. -/
def morphism.comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : L₁ →ₗ⁅R⁆ L₃ :=
{ map_lie := λ x y, by { change f (g ⁅x, y⁆) = ⁅f (g x), f (g y)⁆, rw [map_lie, map_lie], },
..linear_map.comp f.to_linear_map g.to_linear_map }
@[simp] lemma morphism.comp_apply (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) (x : L₁) :
f.comp g x = f (g x) := rfl
@[norm_cast]
lemma morphism.comp_coe (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) :
(f : L₂ → L₃) ∘ (g : L₁ → L₂) = f.comp g := rfl
/-- The inverse of a bijective morphism is a morphism. -/
def morphism.inverse (f : L₁ →ₗ⁅R⁆ L₂) (g : L₂ → L₁)
(h₁ : function.left_inverse g f) (h₂ : function.right_inverse g f) : L₂ →ₗ⁅R⁆ L₁ :=
{ map_lie := λ x y,
calc g ⁅x, y⁆ = g ⁅f (g x), f (g y)⁆ : by { conv_lhs { rw [←h₂ x, ←h₂ y], }, }
... = g (f ⁅g x, g y⁆) : by rw map_lie
... = ⁅g x, g y⁆ : (h₁ _),
..linear_map.inverse f.to_linear_map g h₁ h₂ }
end morphism_properties
/-- An equivalence of Lie algebras is a morphism which is also a linear equivalence. We could
instead define an equivalence to be a morphism which is also a (plain) equivalence. However it is
more convenient to define via linear equivalence to get `.to_linear_equiv` for free. -/
structure equiv (R : Type u) (L : Type v) (L' : Type w)
[comm_ring R] [lie_ring L] [lie_algebra R L] [lie_ring L'] [lie_algebra R L']
extends L →ₗ⁅R⁆ L', L ≃ₗ[R] L'
attribute [nolint doc_blame] lie_algebra.equiv.to_morphism
attribute [nolint doc_blame] lie_algebra.equiv.to_linear_equiv
notation L ` ≃ₗ⁅`:50 R `⁆ ` L' := equiv R L L'
namespace equiv
variables {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁}
variables [comm_ring R] [lie_ring L₁] [lie_ring L₂] [lie_ring L₃]
variables [lie_algebra R L₁] [lie_algebra R L₂] [lie_algebra R L₃]
instance has_coe_to_lie_hom : has_coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ →ₗ⁅R⁆ L₂) := ⟨to_morphism⟩
instance has_coe_to_linear_equiv : has_coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ ≃ₗ[R] L₂) := ⟨to_linear_equiv⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (L₁ ≃ₗ⁅R⁆ L₂) := ⟨_, to_fun⟩
@[simp, norm_cast] lemma coe_to_lie_equiv (e : L₁ ≃ₗ⁅R⁆ L₂) : ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = e :=
rfl
@[simp, norm_cast] lemma coe_to_linear_equiv (e : L₁ ≃ₗ⁅R⁆ L₂) : ((e : L₁ ≃ₗ[R] L₂) : L₁ → L₂) = e :=
rfl
instance : has_one (L₁ ≃ₗ⁅R⁆ L₁) :=
⟨{ map_lie := λ x y, by { change ((1 : L₁→ₗ[R] L₁) ⁅x, y⁆) = ⁅(1 : L₁→ₗ[R] L₁) x, (1 : L₁→ₗ[R] L₁) y⁆, simp, },
..(1 : L₁ ≃ₗ[R] L₁)}⟩
@[simp] lemma one_apply (x : L₁) : (1 : (L₁ ≃ₗ⁅R⁆ L₁)) x = x := rfl
instance : inhabited (L₁ ≃ₗ⁅R⁆ L₁) := ⟨1⟩
/-- Lie algebra equivalences are reflexive. -/
@[refl]
def refl : L₁ ≃ₗ⁅R⁆ L₁ := 1
@[simp] lemma refl_apply (x : L₁) : (refl : L₁ ≃ₗ⁅R⁆ L₁) x = x := rfl
/-- Lie algebra equivalences are symmetric. -/
@[symm]
def symm (e : L₁ ≃ₗ⁅R⁆ L₂) : L₂ ≃ₗ⁅R⁆ L₁ :=
{ ..morphism.inverse e.to_morphism e.inv_fun e.left_inv e.right_inv,
..e.to_linear_equiv.symm }
@[simp] lemma symm_symm (e : L₁ ≃ₗ⁅R⁆ L₂) : e.symm.symm = e :=
by { cases e, refl, }
@[simp] lemma apply_symm_apply (e : L₁ ≃ₗ⁅R⁆ L₂) : ∀ x, e (e.symm x) = x :=
e.to_linear_equiv.apply_symm_apply
@[simp] lemma symm_apply_apply (e : L₁ ≃ₗ⁅R⁆ L₂) : ∀ x, e.symm (e x) = x :=
e.to_linear_equiv.symm_apply_apply
/-- Lie algebra equivalences are transitive. -/
@[trans]
def trans (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) : L₁ ≃ₗ⁅R⁆ L₃ :=
{ ..morphism.comp e₂.to_morphism e₁.to_morphism,
..linear_equiv.trans e₁.to_linear_equiv e₂.to_linear_equiv }
@[simp] lemma trans_apply (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) (x : L₁) :
(e₁.trans e₂) x = e₂ (e₁ x) := rfl
@[simp] lemma symm_trans_apply (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) (x : L₃) :
(e₁.trans e₂).symm x = e₁.symm (e₂.symm x) := rfl
end equiv
end lie_algebra
section lie_module_morphisms
variables (R : Type u) (L : Type v) (M : Type w) (N : Type w₁) (P : Type w₂)
variables [comm_ring R] [lie_ring L] [lie_algebra R L]
variables [add_comm_group M] [add_comm_group N] [add_comm_group P]
variables [module R M] [module R N] [module R P]
variables [lie_ring_module L M] [lie_ring_module L N] [lie_ring_module L P]
variables [lie_module R L M] [lie_module R L N] [lie_module R L P]
set_option old_structure_cmd true
/-- A morphism of Lie algebra modules is a linear map which commutes with the action of the Lie
algebra. -/
structure lie_module_hom extends M →ₗ[R] N :=
(map_lie : ∀ {x : L} {m : M}, to_fun ⁅x, m⁆ = ⁅x, to_fun m⁆)
attribute [nolint doc_blame] lie_module_hom.to_linear_map
notation M ` →ₗ⁅`:25 R,L:25 `⁆ `:0 N:0 := lie_module_hom R L M N
namespace lie_module_hom
variables {R L M N P}
instance : has_coe (M →ₗ⁅R,L⁆ N) (M →ₗ[R] N) := ⟨lie_module_hom.to_linear_map⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (M →ₗ⁅R,L⁆ N) := ⟨_, lie_module_hom.to_fun⟩
@[simp] lemma coe_mk (f : M → N) (h₁ h₂ h₃) :
((⟨f, h₁, h₂, h₃⟩ : M →ₗ⁅R,L⁆ N) : M → N) = f := rfl
@[simp, norm_cast] lemma coe_to_linear_map (f : M →ₗ⁅R,L⁆ N) : ((f : M →ₗ[R] N) : M → N) = f :=
rfl
@[simp] lemma map_lie' (f : M →ₗ⁅R,L⁆ N) (x : L) (m : M) : f ⁅x, m⁆ = ⁅x, f m⁆ :=
lie_module_hom.map_lie f
/-- The constant 0 map is a Lie module morphism. -/
instance : has_zero (M →ₗ⁅R,L⁆ N) := ⟨{ map_lie := by simp, ..(0 : M →ₗ[R] N) }⟩
/-- The identity map is a Lie module morphism. -/
instance : has_one (M →ₗ⁅R,L⁆ M) := ⟨{ map_lie := by simp, ..(1 : M →ₗ[R] M) }⟩
instance : inhabited (M →ₗ⁅R,L⁆ N) := ⟨0⟩
lemma coe_injective : function.injective (λ f : M →ₗ⁅R,L⁆ N, show M → N, from f) :=
by { rintros ⟨f, _⟩ ⟨g, _⟩ ⟨h⟩, congr, }
@[ext] lemma ext {f g : M →ₗ⁅R,L⁆ N} (h : ∀ m, f m = g m) : f = g :=
coe_injective $ funext h
lemma ext_iff {f g : M →ₗ⁅R,L⁆ N} : f = g ↔ ∀ m, f m = g m :=
⟨by { rintro rfl m, refl, }, ext⟩
/-- The composition of Lie module morphisms is a morphism. -/
def comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) : M →ₗ⁅R,L⁆ P :=
{ map_lie := λ x m, by { change f (g ⁅x, m⁆) = ⁅x, f (g m)⁆, rw [map_lie', map_lie'], },
..linear_map.comp f.to_linear_map g.to_linear_map }
@[simp] lemma comp_apply (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) (m : M) :
f.comp g m = f (g m) := rfl
@[norm_cast] lemma comp_coe (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) :
(f : N → P) ∘ (g : M → N) = f.comp g := rfl
/-- The inverse of a bijective morphism of Lie modules is a morphism of Lie modules. -/
def inverse (f : M →ₗ⁅R,L⁆ N) (g : N → M)
(h₁ : function.left_inverse g f) (h₂ : function.right_inverse g f) : N →ₗ⁅R,L⁆ M :=
{ map_lie := λ x n,
calc g ⁅x, n⁆ = g ⁅x, f (g n)⁆ : by rw h₂
... = g (f ⁅x, g n⁆) : by rw map_lie'
... = ⁅x, g n⁆ : (h₁ _),
..linear_map.inverse f.to_linear_map g h₁ h₂ }
end lie_module_hom
/-- An equivalence of Lie algebra modules is a linear equivalence which is also a morphism of
Lie algebra modules. -/
structure lie_module_equiv extends M ≃ₗ[R] N, M →ₗ⁅R,L⁆ N
attribute [nolint doc_blame] lie_module_equiv.to_lie_module_hom
attribute [nolint doc_blame] lie_module_equiv.to_linear_equiv
notation M ` ≃ₗ⁅`:25 R,L:25 `⁆ `:0 N:0 := lie_module_equiv R L M N
namespace lie_module_equiv
variables {R L M N P}
instance has_coe_to_lie_module_hom : has_coe (M ≃ₗ⁅R,L⁆ N) (M →ₗ⁅R,L⁆ N) := ⟨to_lie_module_hom⟩
instance has_coe_to_linear_equiv : has_coe (M ≃ₗ⁅R,L⁆ N) (M ≃ₗ[R] N) := ⟨to_linear_equiv⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (M ≃ₗ⁅R,L⁆ N) := ⟨_, to_fun⟩
@[simp, norm_cast] lemma coe_to_lie_module_hom (e : M ≃ₗ⁅R,L⁆ N) : ((e : M →ₗ⁅R,L⁆ N) : M → N) = e :=
rfl
@[simp, norm_cast] lemma coe_to_linear_equiv (e : M ≃ₗ⁅R,L⁆ N) : ((e : M ≃ₗ[R] N) : M → N) = e :=
rfl
instance : has_one (M ≃ₗ⁅R,L⁆ M) := ⟨{ map_lie := λ x m, rfl, ..(1 : M ≃ₗ[R] M) }⟩
@[simp] lemma one_apply (m : M) : (1 : (M ≃ₗ⁅R,L⁆ M)) m = m := rfl
instance : inhabited (M ≃ₗ⁅R,L⁆ M) := ⟨1⟩
/-- Lie module equivalences are reflexive. -/
@[refl] def refl : M ≃ₗ⁅R,L⁆ M := 1
@[simp] lemma refl_apply (m : M) : (refl : M ≃ₗ⁅R,L⁆ M) m = m := rfl
/-- Lie module equivalences are syemmtric. -/
@[symm] def symm (e : M ≃ₗ⁅R,L⁆ N) : N ≃ₗ⁅R,L⁆ M :=
{ ..lie_module_hom.inverse e.to_lie_module_hom e.inv_fun e.left_inv e.right_inv,
..(e : M ≃ₗ[R] N).symm }
@[simp] lemma symm_symm (e : M ≃ₗ⁅R,L⁆ N) : e.symm.symm = e :=
by { cases e, refl, }
@[simp] lemma apply_symm_apply (e : M ≃ₗ⁅R,L⁆ N) : ∀ x, e (e.symm x) = x :=
e.to_linear_equiv.apply_symm_apply
@[simp] lemma symm_apply_apply (e : M ≃ₗ⁅R,L⁆ N) : ∀ x, e.symm (e x) = x :=
e.to_linear_equiv.symm_apply_apply
/-- Lie module equivalences are transitive. -/
@[trans] def trans (e₁ : M ≃ₗ⁅R,L⁆ N) (e₂ : N ≃ₗ⁅R,L⁆ P) : M ≃ₗ⁅R,L⁆ P :=
{ ..lie_module_hom.comp e₂.to_lie_module_hom e₁.to_lie_module_hom,
..linear_equiv.trans e₁.to_linear_equiv e₂.to_linear_equiv }
@[simp] lemma trans_apply (e₁ : M ≃ₗ⁅R,L⁆ N) (e₂ : N ≃ₗ⁅R,L⁆ P) (m : M) :
(e₁.trans e₂) m = e₂ (e₁ m) := rfl
@[simp] lemma symm_trans_apply (e₁ : M ≃ₗ⁅R,L⁆ N) (e₂ : N ≃ₗ⁅R,L⁆ P) (p : P) :
(e₁.trans e₂).symm p = e₁.symm (e₂.symm p) := rfl
end lie_module_equiv
end lie_module_morphisms
section of_associative
variables {A : Type v} [ring A]
namespace ring_commutator
/-- The bracket operation for rings is the ring commutator, which captures the extent to which a
ring is commutative. It is identically zero exactly when the ring is commutative. -/
@[priority 100]
instance : has_bracket A A := ⟨λ x y, x*y - y*x⟩
lemma commutator (x y : A) : ⁅x, y⁆ = x*y - y*x := rfl
end ring_commutator
namespace lie_ring
/-- An associative ring gives rise to a Lie ring by taking the bracket to be the ring commutator. -/
@[priority 100]
instance of_associative_ring : lie_ring A :=
{ add_lie := by simp only [ring_commutator.commutator, right_distrib, left_distrib,
sub_eq_add_neg, add_comm, add_left_comm, forall_const, eq_self_iff_true, neg_add_rev],
lie_add := by simp only [ring_commutator.commutator, right_distrib, left_distrib,
sub_eq_add_neg, add_comm, add_left_comm, forall_const, eq_self_iff_true, neg_add_rev],
lie_self := by simp only [ring_commutator.commutator, forall_const, sub_self],
leibniz_lie := λ x y z, by { repeat {rw ring_commutator.commutator}, noncomm_ring, } }
lemma of_associative_ring_bracket (x y : A) : ⁅x, y⁆ = x*y - y*x := rfl
end lie_ring
/-- A Lie (ring) module is trivial iff all brackets vanish. -/
class lie_module.is_trivial (L : Type v) (M : Type w) [has_bracket L M] [has_zero M] : Prop :=
(trivial : ∀ (x : L) (m : M), ⁅x, m⁆ = 0)
@[simp] lemma trivial_lie_zero (L : Type v) (M : Type w)
[has_bracket L M] [has_zero M] [lie_module.is_trivial L M] (x : L) (m : M) : ⁅x, m⁆ = 0 :=
lie_module.is_trivial.trivial x m
/-- A Lie algebra is Abelian iff it is trivial as a Lie module over itself. -/
abbreviation is_lie_abelian (L : Type v) [has_bracket L L] [has_zero L] : Prop :=
lie_module.is_trivial L L
lemma commutative_ring_iff_abelian_lie_ring : is_commutative A (*) ↔ is_lie_abelian A :=
begin
have h₁ : is_commutative A (*) ↔ ∀ (a b : A), a * b = b * a := ⟨λ h, h.1, λ h, ⟨h⟩⟩,
have h₂ : is_lie_abelian A ↔ ∀ (a b : A), ⁅a, b⁆ = 0 := ⟨λ h, h.1, λ h, ⟨h⟩⟩,
simp only [h₁, h₂, lie_ring.of_associative_ring_bracket, sub_eq_zero],
end
namespace lie_algebra
variables {R : Type u} [comm_ring R] [algebra R A]
/-- An associative algebra gives rise to a Lie algebra by taking the bracket to be the ring
commutator. -/
@[priority 100]
instance of_associative_algebra : lie_algebra R A :=
{ lie_smul := λ t x y,
by rw [lie_ring.of_associative_ring_bracket, lie_ring.of_associative_ring_bracket,
algebra.mul_smul_comm, algebra.smul_mul_assoc, smul_sub], }
/-- The map `of_associative_algebra` associating a Lie algebra to an associative algebra is
functorial. -/
def of_associative_algebra_hom {B : Type w} [ring B] [algebra R B] (f : A →ₐ[R] B) : A →ₗ⁅R⁆ B :=
{ map_lie := λ x y, show f ⁅x,y⁆ = ⁅f x,f y⁆,
by simp only [lie_ring.of_associative_ring_bracket, alg_hom.map_sub, alg_hom.map_mul],
..f.to_linear_map, }
@[simp] lemma of_associative_algebra_hom_id : of_associative_algebra_hom (alg_hom.id R A) = 1 := rfl
@[simp] lemma of_associative_algebra_hom_apply {B : Type w} [ring B] [algebra R B]
(f : A →ₐ[R] B) (x : A) : of_associative_algebra_hom f x = f x := rfl
@[simp] lemma of_associative_algebra_hom_comp {B : Type w} {C : Type w₁}
[ring B] [ring C] [algebra R B] [algebra R C] (f : A →ₐ[R] B) (g : B →ₐ[R] C) :
of_associative_algebra_hom (g.comp f) =
(of_associative_algebra_hom g).comp (of_associative_algebra_hom f) := rfl
end lie_algebra
end of_associative
section adjoint_action
variables (R : Type u) (L : Type v) (M : Type w)
variables [comm_ring R] [lie_ring L] [lie_algebra R L] [add_comm_group M] [module R M]
variables [lie_ring_module L M] [lie_module R L M]
/-- A Lie module yields a Lie algebra morphism into the linear endomorphisms of the module. -/
def lie_module.to_endo_morphism : L →ₗ⁅R⁆ module.End R M :=
{ to_fun := λ x,
{ to_fun := λ m, ⁅x, m⁆,
map_add' := lie_add x,
map_smul' := λ t, lie_smul t x, },
map_add' := λ x y, by { ext m, apply add_lie, },
map_smul' := λ t x, by { ext m, apply smul_lie, },
map_lie := λ x y, by { ext m, apply lie_lie, }, }
/-- The adjoint action of a Lie algebra on itself. -/
def lie_algebra.ad : L →ₗ⁅R⁆ module.End R L := lie_module.to_endo_morphism R L L
@[simp] lemma lie_algebra.ad_apply (x y : L) : lie_algebra.ad R L x y = ⁅x, y⁆ := rfl
end adjoint_action
section lie_subalgebra
variables (R : Type u) (L : Type v) [comm_ring R] [lie_ring L] [lie_algebra R L]
set_option old_structure_cmd true
/-- A Lie subalgebra of a Lie algebra is submodule that is closed under the Lie bracket.
This is a sufficient condition for the subset itself to form a Lie algebra. -/
structure lie_subalgebra extends submodule R L :=
(lie_mem : ∀ {x y}, x ∈ carrier → y ∈ carrier → ⁅x, y⁆ ∈ carrier)
attribute [nolint doc_blame] lie_subalgebra.to_submodule
/-- The zero algebra is a subalgebra of any Lie algebra. -/
instance : has_zero (lie_subalgebra R L) :=
⟨{ lie_mem := λ x y hx hy, by { rw [((submodule.mem_bot R).1 hx), zero_lie],
exact submodule.zero_mem (0 : submodule R L), },
..(0 : submodule R L) }⟩
instance : inhabited (lie_subalgebra R L) := ⟨0⟩
instance : has_coe (lie_subalgebra R L) (set L) := ⟨lie_subalgebra.carrier⟩
instance : has_mem L (lie_subalgebra R L) := ⟨λ x L', x ∈ (L' : set L)⟩
instance lie_subalgebra_coe_submodule : has_coe (lie_subalgebra R L) (submodule R L) :=
⟨lie_subalgebra.to_submodule⟩
/-- A Lie subalgebra forms a new Lie ring. -/
instance lie_subalgebra_lie_ring (L' : lie_subalgebra R L) : lie_ring L' :=
{ bracket := λ x y, ⟨⁅x.val, y.val⁆, L'.lie_mem x.property y.property⟩,
lie_add := by { intros, apply set_coe.ext, apply lie_add, },
add_lie := by { intros, apply set_coe.ext, apply add_lie, },
lie_self := by { intros, apply set_coe.ext, apply lie_self, },
leibniz_lie := by { intros, apply set_coe.ext, apply leibniz_lie, } }
/-- A Lie subalgebra forms a new Lie algebra. -/
instance lie_subalgebra_lie_algebra (L' : lie_subalgebra R L) : lie_algebra R L' :=
{ lie_smul := by { intros, apply set_coe.ext, apply lie_smul } }
@[simp] lemma lie_subalgebra.mem_coe {L' : lie_subalgebra R L} {x : L} :
x ∈ (L' : set L) ↔ x ∈ L' := iff.rfl
@[simp] lemma lie_subalgebra.mem_coe' {L' : lie_subalgebra R L} {x : L} :
x ∈ (L' : submodule R L) ↔ x ∈ L' := iff.rfl
@[simp, norm_cast] lemma lie_subalgebra.coe_bracket (L' : lie_subalgebra R L) (x y : L') :
(↑⁅x, y⁆ : L) = ⁅(↑x : L), ↑y⁆ := rfl
@[ext] lemma lie_subalgebra.ext (L₁' L₂' : lie_subalgebra R L) (h : ∀ x, x ∈ L₁' ↔ x ∈ L₂') :
L₁' = L₂' :=
by { cases L₁', cases L₂', simp only [], ext x, exact h x, }
lemma lie_subalgebra.ext_iff (L₁' L₂' : lie_subalgebra R L) : L₁' = L₂' ↔ ∀ x, x ∈ L₁' ↔ x ∈ L₂' :=
⟨λ h x, by rw h, lie_subalgebra.ext R L L₁' L₂'⟩
/-- A subalgebra of an associative algebra is a Lie subalgebra of the associated Lie algebra. -/
def lie_subalgebra_of_subalgebra (A : Type v) [ring A] [algebra R A]
(A' : subalgebra R A) : lie_subalgebra R A :=
{ lie_mem := λ x y hx hy, by {
change ⁅x, y⁆ ∈ A', change x ∈ A' at hx, change y ∈ A' at hy,
rw lie_ring.of_associative_ring_bracket,
have hxy := A'.mul_mem hx hy,
have hyx := A'.mul_mem hy hx,
exact submodule.sub_mem A'.to_submodule hxy hyx, },
..A'.to_submodule }
variables {R L} {L₂ : Type w} [lie_ring L₂] [lie_algebra R L₂]
/-- The embedding of a Lie subalgebra into the ambient space as a Lie morphism. -/
def lie_subalgebra.incl (L' : lie_subalgebra R L) : L' →ₗ⁅R⁆ L :=
{ map_lie := λ x y, by { rw [linear_map.to_fun_eq_coe, submodule.subtype_apply], refl, },
..L'.to_submodule.subtype }
/-- The range of a morphism of Lie algebras is a Lie subalgebra. -/
def lie_algebra.morphism.range (f : L →ₗ⁅R⁆ L₂) : lie_subalgebra R L₂ :=
{ lie_mem := λ x y,
show x ∈ f.to_linear_map.range → y ∈ f.to_linear_map.range → ⁅x, y⁆ ∈ f.to_linear_map.range,
by { repeat { rw linear_map.mem_range }, rintros ⟨x', hx⟩ ⟨y', hy⟩, refine ⟨⁅x', y'⁆, _⟩,
rw [←hx, ←hy], change f ⁅x', y'⁆ = ⁅f x', f y'⁆, rw lie_algebra.map_lie, },
..f.to_linear_map.range }
@[simp] lemma lie_algebra.morphism.range_bracket (f : L →ₗ⁅R⁆ L₂) (x y : f.range) :
(↑⁅x, y⁆ : L₂) = ⁅(↑x : L₂), ↑y⁆ := rfl
/-- The image of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the
codomain. -/
def lie_subalgebra.map (f : L →ₗ⁅R⁆ L₂) (L' : lie_subalgebra R L) : lie_subalgebra R L₂ :=
{ lie_mem := λ x y hx hy, by {
erw submodule.mem_map at hx, rcases hx with ⟨x', hx', hx⟩, rw ←hx,
erw submodule.mem_map at hy, rcases hy with ⟨y', hy', hy⟩, rw ←hy,
erw submodule.mem_map,
exact ⟨⁅x', y'⁆, L'.lie_mem hx' hy', lie_algebra.map_lie f x' y'⟩, },
..((L' : submodule R L).map (f : L →ₗ[R] L₂))}
@[simp] lemma lie_subalgebra.mem_map_submodule (e : L ≃ₗ⁅R⁆ L₂) (L' : lie_subalgebra R L) (x : L₂) :
x ∈ L'.map (e : L →ₗ⁅R⁆ L₂) ↔ x ∈ (L' : submodule R L).map (e : L →ₗ[R] L₂) :=
iff.rfl
end lie_subalgebra
namespace lie_algebra
variables {R : Type u} {L₁ : Type v} {L₂ : Type w}
variables [comm_ring R] [lie_ring L₁] [lie_ring L₂] [lie_algebra R L₁] [lie_algebra R L₂]
namespace equiv
/-- An injective Lie algebra morphism is an equivalence onto its range. -/
noncomputable def of_injective (f : L₁ →ₗ⁅R⁆ L₂) (h : function.injective f) :
L₁ ≃ₗ⁅R⁆ f.range :=
have h' : (f : L₁ →ₗ[R] L₂).ker = ⊥ := linear_map.ker_eq_bot_of_injective h,
{ map_lie := λ x y, by { apply set_coe.ext,
simp only [linear_equiv.of_injective_apply, lie_algebra.morphism.range_bracket],
apply f.map_lie, },
..(linear_equiv.of_injective ↑f h')}
@[simp] lemma of_injective_apply (f : L₁ →ₗ⁅R⁆ L₂) (h : function.injective f) (x : L₁) :
↑(of_injective f h x) = f x := rfl
variables (L₁' L₁'' : lie_subalgebra R L₁) (L₂' : lie_subalgebra R L₂)
/-- Lie subalgebras that are equal as sets are equivalent as Lie algebras. -/
def of_eq (h : (L₁' : set L₁) = L₁'') : L₁' ≃ₗ⁅R⁆ L₁'' :=
{ map_lie := λ x y, by { apply set_coe.ext, simp, },
..(linear_equiv.of_eq ↑L₁' ↑L₁''
(by {ext x, change x ∈ (L₁' : set L₁) ↔ x ∈ (L₁'' : set L₁), rw h, } )) }
@[simp] lemma of_eq_apply (L L' : lie_subalgebra R L₁) (h : (L : set L₁) = L') (x : L) :
(↑(of_eq L L' h x) : L₁) = x := rfl
variables (e : L₁ ≃ₗ⁅R⁆ L₂)
/-- An equivalence of Lie algebras restricts to an equivalence from any Lie subalgebra onto its
image. -/
def of_subalgebra : L₁'' ≃ₗ⁅R⁆ (L₁''.map e : lie_subalgebra R L₂) :=
{ map_lie := λ x y, by { apply set_coe.ext, exact lie_algebra.map_lie (↑e : L₁ →ₗ⁅R⁆ L₂) ↑x ↑y, }
..(linear_equiv.of_submodule (e : L₁ ≃ₗ[R] L₂) ↑L₁'') }
@[simp] lemma of_subalgebra_apply (x : L₁'') : ↑(e.of_subalgebra _ x) = e x := rfl
/-- An equivalence of Lie algebras restricts to an equivalence from any Lie subalgebra onto its
image. -/
def of_subalgebras (h : L₁'.map ↑e = L₂') : L₁' ≃ₗ⁅R⁆ L₂' :=
{ map_lie := λ x y, by { apply set_coe.ext, exact lie_algebra.map_lie (↑e : L₁ →ₗ⁅R⁆ L₂) ↑x ↑y, },
..(linear_equiv.of_submodules (e : L₁ ≃ₗ[R] L₂) ↑L₁' ↑L₂' (by { rw ←h, refl, })) }
@[simp] lemma of_subalgebras_apply (h : L₁'.map ↑e = L₂') (x : L₁') :
↑(e.of_subalgebras _ _ h x) = e x := rfl
@[simp] lemma of_subalgebras_symm_apply (h : L₁'.map ↑e = L₂') (x : L₂') :
↑((e.of_subalgebras _ _ h).symm x) = e.symm x := rfl
end equiv
end lie_algebra
section lie_submodule
variables (R : Type u) (L : Type v) (M : Type w)
variables [comm_ring R] [lie_ring L] [lie_algebra R L] [add_comm_group M] [module R M]
variables [lie_ring_module L M] [lie_module R L M]
set_option old_structure_cmd true
/-- A Lie submodule of a Lie module is a submodule that is closed under the Lie bracket.
This is a sufficient condition for the subset itself to form a Lie module. -/
structure lie_submodule extends submodule R M :=
(lie_mem : ∀ {x : L} {m : M}, m ∈ carrier → ⁅x, m⁆ ∈ carrier)
attribute [nolint doc_blame] lie_submodule.to_submodule
namespace lie_submodule
/-- The zero module is a Lie submodule of any Lie module. -/
instance : has_zero (lie_submodule R L M) :=
⟨{ lie_mem := λ x m h, by { rw ((submodule.mem_bot R).1 h), apply lie_zero, },
..(0 : submodule R M)}⟩
instance : inhabited (lie_submodule R L M) := ⟨0⟩
instance coe_submodule : has_coe (lie_submodule R L M) (submodule R M) := ⟨to_submodule⟩
@[norm_cast]
lemma coe_to_submodule (N : lie_submodule R L M) : ((N : submodule R M) : set M) = N := rfl
instance has_mem : has_mem M (lie_submodule R L M) := ⟨λ x N, x ∈ (N : set M)⟩
@[simp] lemma mem_carrier (N : lie_submodule R L M) {x : M} : x ∈ N.carrier ↔ x ∈ (N : set M) :=
iff.rfl
@[simp] lemma mem_coe_submodule (N : lie_submodule R L M) {x : M} :
x ∈ (N : submodule R M) ↔ x ∈ N := iff.rfl
lemma mem_coe (N : lie_submodule R L M) {x : M} : x ∈ (N : set M) ↔ x ∈ N := iff.rfl
@[simp] lemma coe_to_set_mk (S : set M) (h₁ h₂ h₃ h₄) :
((⟨S, h₁, h₂, h₃, h₄⟩ : lie_submodule R L M) : set M) = S := rfl
@[simp] lemma coe_to_submodule_mk (p : submodule R M) (h) :
(({lie_mem := h, ..p} : lie_submodule R L M) : submodule R M) = p :=
by { cases p, refl, }
@[ext] lemma ext (N N' : lie_submodule R L M) (h : ∀ m, m ∈ N ↔ m ∈ N') : N = N' :=
by { cases N, cases N', simp only [], ext m, exact h m, }
instance (N : lie_submodule R L M) : lie_ring_module L N :=
{ bracket := λ (x : L) (m : N), ⟨⁅x, m.val⁆, N.lie_mem m.property⟩,
add_lie := by { intros x y m, apply set_coe.ext, apply add_lie, },
lie_add := by { intros x m n, apply set_coe.ext, apply lie_add, },
leibniz_lie := by { intros x y m, apply set_coe.ext, apply leibniz_lie, }, }
instance (N : lie_submodule R L M) : lie_module R L N :=
{ lie_smul := by { intros t x y, apply set_coe.ext, apply lie_smul, },
smul_lie := by { intros t x y, apply set_coe.ext, apply smul_lie, }, }
end lie_submodule
section lie_ideal
variables (L)
/-- An ideal of a Lie algebra is a Lie submodule of the Lie algebra as a Lie module over itself. -/
abbreviation lie_ideal := lie_submodule R L L
lemma lie_mem_right (I : lie_ideal R L) (x y : L) (h : y ∈ I) : ⁅x, y⁆ ∈ I := I.lie_mem h
lemma lie_mem_left (I : lie_ideal R L) (x y : L) (h : x ∈ I) : ⁅x, y⁆ ∈ I :=
by { rw [←lie_skew, ←neg_lie], apply lie_mem_right, assumption, }
/-- An ideal of a Lie algebra is a Lie subalgebra. -/
def lie_ideal_subalgebra (I : lie_ideal R L) : lie_subalgebra R L :=
{ lie_mem := by { intros x y hx hy, apply lie_mem_right, exact hy, },
..I.to_submodule, }
instance : has_coe (lie_ideal R L) (lie_subalgebra R L) := ⟨λ I, lie_ideal_subalgebra R L I⟩
end lie_ideal
end lie_submodule
namespace lie_submodule
variables {R : Type u} {L : Type v} {M : Type w}
variables [comm_ring R] [lie_ring L] [lie_algebra R L] [add_comm_group M] [module R M]
variables [lie_ring_module L M] [lie_module R L M]
variables (N N' : lie_submodule R L M) (I J : lie_ideal R L)
section lattice_structure
open set
lemma coe_injective : function.injective (coe : lie_submodule R L M → set M) :=
λ N N' h, by { cases N, cases N', simp only, exact h, }
lemma coe_submodule_injective : function.injective (coe : lie_submodule R L M → submodule R M) :=
λ N N' h, by { ext, rw [← mem_coe_submodule, h], refl, }
instance : partial_order (lie_submodule R L M) :=
{ le := λ N N', ∀ ⦃x⦄, x ∈ N → x ∈ N', -- Overriding `le` like this gives a better defeq.
..partial_order.lift (coe : lie_submodule R L M → set M) coe_injective }
lemma le_def : N ≤ N' ↔ (N : set M) ⊆ N' := iff.rfl
@[simp, norm_cast] lemma coe_submodule_le_coe_submodule : (N : submodule R M) ≤ N' ↔ N ≤ N' :=
iff.rfl
instance : has_bot (lie_submodule R L M) := ⟨0⟩
@[simp] lemma bot_coe : ((⊥ : lie_submodule R L M) : set M) = {0} := rfl
@[simp] lemma mem_bot (x : M) : x ∈ (⊥ : lie_submodule R L M) ↔ x = 0 := mem_singleton_iff
instance : has_top (lie_submodule R L M) :=
⟨{ lie_mem := λ x m h, mem_univ ⁅x, m⁆,
..(⊤ : submodule R M) }⟩
@[simp] lemma top_coe : ((⊤ : lie_submodule R L M) : set M) = univ := rfl
lemma mem_top (x : M) : x ∈ (⊤ : lie_submodule R L M) := mem_univ x
instance : has_inf (lie_submodule R L M) :=
⟨λ N N', { lie_mem := λ x m h, mem_inter (N.lie_mem h.1) (N'.lie_mem h.2),
..(N ⊓ N' : submodule R M) }⟩
instance : has_Inf (lie_submodule R L M) :=
⟨λ S, { lie_mem := λ x m h, by
{ simp only [submodule.mem_carrier, mem_Inter, submodule.Inf_coe, mem_set_of_eq,
forall_apply_eq_imp_iff₂, exists_imp_distrib] at *,
intros N hN, apply N.lie_mem (h N hN), },
..Inf {(s : submodule R M) | s ∈ S} }⟩
@[simp] lemma Inf_coe_to_submodule (S : set (lie_submodule R L M)) :
(↑(Inf S) : submodule R M) = Inf {(s : submodule R M) | s ∈ S} := rfl
@[simp] lemma Inf_coe (S : set (lie_submodule R L M)) : (↑(Inf S) : set M) = ⋂ s ∈ S, (s : set M) :=
begin
rw [← lie_submodule.coe_to_submodule, Inf_coe_to_submodule, submodule.Inf_coe],
ext m,
simpa only [mem_Inter, mem_set_of_eq, forall_apply_eq_imp_iff₂, exists_imp_distrib],
end
lemma Inf_glb (S : set (lie_submodule R L M)) : is_glb S (Inf S) :=
begin
have h : ∀ (N N' : lie_submodule R L M), (N : set M) ≤ N' ↔ N ≤ N', { intros, apply iff.rfl, },
simp only [is_glb.of_image h, Inf_coe, is_glb_binfi],
end
/-- The set of Lie submodules of a Lie module form a complete lattice.
We provide explicit values for the fields `bot`, `top`, `inf` to get more convenient definitions
than we would otherwise obtain from `complete_lattice_of_Inf`. -/
instance : complete_lattice (lie_submodule R L M) :=
{ bot := ⊥,
bot_le := λ N _ h, by { rw mem_bot at h, rw h, exact N.zero_mem', },
top := ⊤,
le_top := λ _ _ _, trivial,
inf := (⊓),
le_inf := λ N₁ N₂ N₃ h₁₂ h₁₃ m hm, ⟨h₁₂ hm, h₁₃ hm⟩,
inf_le_left := λ _ _ _, and.left,
inf_le_right := λ _ _ _, and.right,
..complete_lattice_of_Inf _ Inf_glb }
instance : add_comm_monoid (lie_submodule R L M) :=
{ add := (⊔),
add_assoc := λ _ _ _, sup_assoc,
zero := ⊥,
zero_add := λ _, bot_sup_eq,
add_zero := λ _, sup_bot_eq,
add_comm := λ _ _, sup_comm, }
@[simp] lemma add_eq_sup : N + N' = N ⊔ N' := rfl
@[norm_cast] lemma coe_sup :
(↑(N ⊔ N') : submodule R M) = (N : submodule R M) ⊔ (N' : submodule R M) :=
begin
have aux : ∀ (x : L) m, m ∈ (N ⊔ N' : submodule R M) → ⁅x,m⁆ ∈ (N ⊔ N' : submodule R M),
{ simp only [submodule.mem_sup],
rintro x m ⟨y, hy, z, hz, rfl⟩,
refine ⟨⁅x, y⁆, N.lie_mem hy, ⁅x, z⁆, N'.lie_mem hz, (lie_add _ _ _).symm⟩ },
refine le_antisymm (Inf_le ⟨{ lie_mem := aux, ..(N ⊔ N' : submodule R M) }, _⟩) _,
{ simp only [exists_prop, and_true, mem_set_of_eq, eq_self_iff_true, coe_to_submodule_mk,
← coe_submodule_le_coe_submodule, and_self, le_sup_left, le_sup_right] },
{ simp, },
end
lemma mem_sup (x : M) : x ∈ N ⊔ N' ↔ ∃ (y ∈ N) (z ∈ N'), y + z = x :=
by { erw [← submodule.mem_sup, ← coe_sup], refl, }
lemma eq_bot_iff : N = ⊥ ↔ ∀ (m : M), m ∈ N → m = 0 :=
by { rw eq_bot_iff, exact iff.rfl, }
section inclusion_maps
/-- The inclusion of a Lie submodule into its ambient space is a morphism of Lie modules. -/
def incl : N →ₗ⁅R,L⁆ M :=
{ map_lie := λ x m, rfl,
..submodule.subtype (N : submodule R M) }
@[simp] lemma incl_apply (m : N) : N.incl m = m := rfl
lemma incl_eq_val : (N.incl : N → M) = subtype.val := rfl
variables {N N'} (h : N ≤ N')
/-- Given two nested Lie submodules `N ⊆ N'`, the inclusion `N ↪ N'` is a morphism of Lie modules.-/
def hom_of_le : N →ₗ⁅R,L⁆ N' :=
{ map_lie := λ x m, rfl,
..submodule.of_le h }
@[simp] lemma coe_hom_of_le (m : N) : (hom_of_le h m : M) = m := rfl
lemma hom_of_le_apply (m : N) : hom_of_le h m = ⟨m.1, h m.2⟩ := rfl
end inclusion_maps
section lie_span
variables (R L) (s : set M)
/-- The `lie_span` of a set `s ⊆ M` is the smallest Lie submodule of `M` that contains `s`. -/
def lie_span : lie_submodule R L M := Inf {N | s ⊆ N}
variables {R L s}
lemma mem_lie_span {x : M} : x ∈ lie_span R L s ↔ ∀ N : lie_submodule R L M, s ⊆ N → x ∈ N :=
by { change x ∈ (lie_span R L s : set M) ↔ _, erw Inf_coe, exact mem_bInter_iff, }
lemma subset_lie_span : s ⊆ lie_span R L s :=
by { intros m hm, erw mem_lie_span, intros N hN, exact hN hm, }
lemma submodule_span_le_lie_span : submodule.span R s ≤ lie_span R L s :=
by { rw [submodule.span_le, coe_to_submodule], apply subset_lie_span, }
lemma lie_span_le {N} : lie_span R L s ≤ N ↔ s ⊆ N :=
begin
split,
{ exact subset.trans subset_lie_span, },
{ intros hs m hm, rw mem_lie_span at hm, exact hm _ hs, },
end
lemma lie_span_mono {t : set M} (h : s ⊆ t) : lie_span R L s ≤ lie_span R L t :=
by { rw lie_span_le, exact subset.trans h subset_lie_span, }
end lie_span
lemma well_founded_of_noetherian [is_noetherian R M] :
well_founded ((>) : lie_submodule R L M → lie_submodule R L M → Prop) :=
begin
let f : ((>) : lie_submodule R L M → lie_submodule R L M → Prop) →r
((>) : submodule R M → submodule R M → Prop) :=
{ to_fun := coe,
map_rel' := λ N N' h, h, },
apply f.well_founded, rw ← is_noetherian_iff_well_founded, apply_instance,
end
end lattice_structure
section lie_ideal_operations
/-- Given a Lie module `M` over a Lie algebra `L`, the set of Lie ideals of `L` acts on the set
of submodules of `M`. -/
instance : has_bracket (lie_ideal R L) (lie_submodule R L M) :=
⟨λ I N, lie_span R L { m | ∃ (x : I) (n : N), ⁅(x : L), (n : M)⁆ = m }⟩
lemma lie_ideal_oper_eq_span :
⁅I, N⁆ = lie_span R L { m | ∃ (x : I) (n : N), ⁅(x : L), (n : M)⁆ = m } := rfl
lemma lie_ideal_oper_eq_linear_span :
(↑⁅I, N⁆ : submodule R M) = submodule.span R { m | ∃ (x : I) (n : N), ⁅(x : L), (n : M)⁆ = m } :=
begin
apply le_antisymm,
{ let s := {m : M | ∃ (x : ↥I) (n : ↥N), ⁅(x : L), (n : M)⁆ = m},
have aux : ∀ (y : L) (m' ∈ submodule.span R s), ⁅y, m'⁆ ∈ submodule.span R s,
{ intros y m' hm', apply submodule.span_induction hm',
{ rintros m'' ⟨x, n, hm''⟩, rw [← hm'', leibniz_lie],
refine submodule.add_mem _ _ _; apply submodule.subset_span,
{ use [⟨⁅y, ↑x⁆, I.lie_mem x.property⟩, n], refl, },
{ use [x, ⟨⁅y, ↑n⁆, N.lie_mem n.property⟩], refl, }, },
{ simp only [lie_zero, submodule.zero_mem], },
{ intros m₁ m₂ hm₁ hm₂, rw lie_add, exact submodule.add_mem _ hm₁ hm₂, },
{ intros t m'' hm'', rw lie_smul, exact submodule.smul_mem _ t hm'', }, },
change _ ≤ ↑({ lie_mem := aux, ..submodule.span R s } : lie_submodule R L M),
rw [coe_submodule_le_coe_submodule, lie_ideal_oper_eq_span, lie_span_le],
exact submodule.subset_span, },
{ rw lie_ideal_oper_eq_span, apply submodule_span_le_lie_span, },
end
lemma lie_mem_lie (x : I) (m : N) : ⁅(x : L), (m : M)⁆ ∈ ⁅I, N⁆ :=
by { rw lie_ideal_oper_eq_span, apply subset_lie_span, use [x, m], }
lemma lie_comm : ⁅I, J⁆ = ⁅J, I⁆ :=
begin
suffices : ∀ (I J : lie_ideal R L), ⁅I, J⁆ ≤ ⁅J, I⁆, { exact le_antisymm (this I J) (this J I), },
clear I J, intros I J,
rw [lie_ideal_oper_eq_span, lie_span_le], rintros x ⟨y, z, h⟩, rw ← h,
rw [← lie_skew, ← lie_neg, ← submodule.coe_neg],
apply lie_mem_lie,
end
lemma lie_le_right : ⁅I, N⁆ ≤ N :=
begin
rw [lie_ideal_oper_eq_span, lie_span_le], rintros m ⟨x, n, hn⟩, rw ← hn,
exact N.lie_mem n.property,
end
lemma lie_le_left : ⁅I, J⁆ ≤ I :=
by { rw lie_comm, exact lie_le_right I J, }
lemma lie_le_inf : ⁅I, J⁆ ≤ I ⊓ J :=
by { rw le_inf_iff, exact ⟨lie_le_left I J, lie_le_right J I⟩, }
@[simp] lemma lie_bot : ⁅I, (⊥ : lie_submodule R L M)⁆ = ⊥ :=
by { rw eq_bot_iff, apply lie_le_right, }
@[simp] lemma bot_lie : ⁅(⊥ : lie_ideal R L), N⁆ = ⊥ :=
begin
suffices : ⁅(⊥ : lie_ideal R L), N⁆ ≤ ⊥, { exact le_bot_iff.mp this, },
rw [lie_ideal_oper_eq_span, lie_span_le], rintros m ⟨⟨x, hx⟩, n, hn⟩, rw ← hn,
change x ∈ (⊥ : lie_ideal R L) at hx, rw mem_bot at hx, simp [hx],
end
lemma mono_lie (h₁ : I ≤ J) (h₂ : N ≤ N') : ⁅I, N⁆ ≤ ⁅J, N'⁆ :=
begin
intros m h,
rw [lie_ideal_oper_eq_span, mem_lie_span] at h, rw [lie_ideal_oper_eq_span, mem_lie_span],
intros N hN, apply h, rintros m' ⟨⟨x, hx⟩, ⟨n, hn⟩, hm⟩, rw ← hm, apply hN,
use [⟨x, h₁ hx⟩, ⟨n, h₂ hn⟩], refl,
end
lemma mono_lie_left (h : I ≤ J) : ⁅I, N⁆ ≤ ⁅J, N⁆ := mono_lie _ _ _ _ h (le_refl N)
lemma mono_lie_right (h : N ≤ N') : ⁅I, N⁆ ≤ ⁅I, N'⁆ := mono_lie _ _ _ _ (le_refl I) h
@[simp] lemma lie_sup : ⁅I, N ⊔ N'⁆ = ⁅I, N⁆ ⊔ ⁅I, N'⁆ :=
begin
have h : ⁅I, N⁆ ⊔ ⁅I, N'⁆ ≤ ⁅I, N ⊔ N'⁆,
{ rw sup_le_iff, split; apply mono_lie_right; [exact le_sup_left, exact le_sup_right], },
suffices : ⁅I, N ⊔ N'⁆ ≤ ⁅I, N⁆ ⊔ ⁅I, N'⁆, { exact le_antisymm this h, }, clear h,
rw [lie_ideal_oper_eq_span, lie_span_le], rintros m ⟨x, ⟨n, hn⟩, h⟩, erw lie_submodule.mem_sup,
erw lie_submodule.mem_sup at hn, rcases hn with ⟨n₁, hn₁, n₂, hn₂, hn'⟩,
use ⁅(x : L), (⟨n₁, hn₁⟩ : N)⁆, split, { apply lie_mem_lie, },
use ⁅(x : L), (⟨n₂, hn₂⟩ : N')⁆, split, { apply lie_mem_lie, },
simp [← h, ← hn'],
end
@[simp] lemma sup_lie : ⁅I ⊔ J, N⁆ = ⁅I, N⁆ ⊔ ⁅J, N⁆ :=
begin
have h : ⁅I, N⁆ ⊔ ⁅J, N⁆ ≤ ⁅I ⊔ J, N⁆,
{ rw sup_le_iff, split; apply mono_lie_left; [exact le_sup_left, exact le_sup_right], },
suffices : ⁅I ⊔ J, N⁆ ≤ ⁅I, N⁆ ⊔ ⁅J, N⁆, { exact le_antisymm this h, }, clear h,
rw [lie_ideal_oper_eq_span, lie_span_le], rintros m ⟨⟨x, hx⟩, n, h⟩, erw lie_submodule.mem_sup,
erw lie_submodule.mem_sup at hx, rcases hx with ⟨x₁, hx₁, x₂, hx₂, hx'⟩,
use ⁅((⟨x₁, hx₁⟩ : I) : L), (n : N)⁆, split, { apply lie_mem_lie, },
use ⁅((⟨x₂, hx₂⟩ : J) : L), (n : N)⁆, split, { apply lie_mem_lie, },
simp [← h, ← hx'],
end
@[simp] lemma trivial_lie_oper_zero [lie_module.is_trivial L M] : ⁅I, N⁆ = ⊥ :=
begin
suffices : ⁅I, N⁆ ≤ ⊥, { exact le_bot_iff.mp this, },
rw [lie_ideal_oper_eq_span, lie_span_le],
rintros m ⟨x, n, h⟩, rw trivial_lie_zero at h, simp [← h],
end
end lie_ideal_operations
/-- The quotient of a Lie module by a Lie submodule. It is a Lie module. -/
abbreviation quotient := N.to_submodule.quotient
namespace quotient
variables {N I}
/-- Map sending an element of `M` to the corresponding element of `M/N`, when `N` is a
lie_submodule of the lie_module `N`. -/
abbreviation mk : M → N.quotient := submodule.quotient.mk
lemma is_quotient_mk (m : M) :
quotient.mk' m = (mk m : N.quotient) := rfl
/-- Given a Lie module `M` over a Lie algebra `L`, together with a Lie submodule `N ⊆ M`, there
is a natural linear map from `L` to the endomorphisms of `M` leaving `N` invariant. -/
def lie_submodule_invariant : L →ₗ[R] submodule.compatible_maps N.to_submodule N.to_submodule :=
linear_map.cod_restrict _ (lie_module.to_endo_morphism R L M) N.lie_mem
variables (N)
/-- Given a Lie module `M` over a Lie algebra `L`, together with a Lie submodule `N ⊆ M`, there
is a natural Lie algebra morphism from `L` to the linear endomorphism of the quotient `M/N`. -/
def action_as_endo_map : L →ₗ⁅R⁆ module.End R N.quotient :=
{ map_lie := λ x y, by { ext n, apply quotient.induction_on' n, intros m,
change mk ⁅⁅x, y⁆, m⁆ = mk (⁅x, ⁅y, m⁆⁆ - ⁅y, ⁅x, m⁆⁆),
congr, apply lie_lie, },
..linear_map.comp (submodule.mapq_linear (N : submodule R M) ↑N) lie_submodule_invariant }
/-- Given a Lie module `M` over a Lie algebra `L`, together with a Lie submodule `N ⊆ M`, there is
a natural bracket action of `L` on the quotient `M/N`. -/
def action_as_endo_map_bracket : has_bracket L N.quotient := ⟨λ x n, action_as_endo_map N x n⟩
instance lie_quotient_lie_ring_module : lie_ring_module L N.quotient :=
{ bracket := λ x n, (action_as_endo_map N : L →ₗ[R] module.End R N.quotient) x n,
add_lie := λ x y n, by { simp only [linear_map.map_add, linear_map.add_apply], },
lie_add := λ x m n, by { simp only [linear_map.map_add, linear_map.add_apply], },
leibniz_lie := λ x y m, show action_as_endo_map _ _ _ = _,
{ simp only [lie_algebra.map_lie, lie_ring.of_associative_ring_bracket, sub_add_cancel,
lie_algebra.coe_to_linear_map, linear_map.mul_app, linear_map.sub_apply], } }
/-- The quotient of a Lie module by a Lie submodule, is a Lie module. -/
instance lie_quotient_lie_module : lie_module R L N.quotient :=
{ smul_lie := λ t x m, show (_ : L →ₗ[R] module.End R N.quotient) _ _ = _,
{ simp only [linear_map.map_smul], refl, },
lie_smul := λ x t m, show (_ : L →ₗ[R] module.End R N.quotient) _ _ = _,
{ simp only [linear_map.map_smul], refl, }, }
instance lie_quotient_has_bracket : has_bracket (quotient I) (quotient I) :=
⟨begin
intros x y,
apply quotient.lift_on₂' x y (λ x' y', mk ⁅x', y'⁆),
intros x₁ x₂ y₁ y₂ h₁ h₂,
apply (submodule.quotient.eq I.to_submodule).2,
have h : ⁅x₁, x₂⁆ - ⁅y₁, y₂⁆ = ⁅x₁, x₂ - y₂⁆ + ⁅x₁ - y₁, y₂⁆ := by simp [-lie_skew, sub_eq_add_neg, add_assoc],
rw h,
apply submodule.add_mem,
{ apply lie_mem_right R L I x₁ (x₂ - y₂) h₂, },
{ apply lie_mem_left R L I (x₁ - y₁) y₂ h₁, },
end⟩
@[simp] lemma mk_bracket (x y : L) :
mk ⁅x, y⁆ = ⁅(mk x : quotient I), (mk y : quotient I)⁆ := rfl
instance lie_quotient_lie_ring : lie_ring (quotient I) :=
{ add_lie := by { intros x' y' z', apply quotient.induction_on₃' x' y' z', intros x y z,
repeat { rw is_quotient_mk <|>
rw ←mk_bracket <|>
rw ←submodule.quotient.mk_add, },
apply congr_arg, apply add_lie, },
lie_add := by { intros x' y' z', apply quotient.induction_on₃' x' y' z', intros x y z,
repeat { rw is_quotient_mk <|>
rw ←mk_bracket <|>
rw ←submodule.quotient.mk_add, },
apply congr_arg, apply lie_add, },
lie_self := by { intros x', apply quotient.induction_on' x', intros x,
rw [is_quotient_mk, ←mk_bracket],
apply congr_arg, apply lie_self, },
leibniz_lie := by { intros x' y' z', apply quotient.induction_on₃' x' y' z', intros x y z,
repeat { rw is_quotient_mk <|>
rw ←mk_bracket <|>
rw ←submodule.quotient.mk_add, },
apply congr_arg, apply leibniz_lie, } }
instance lie_quotient_lie_algebra : lie_algebra R (quotient I) :=
{ lie_smul := by { intros t x' y', apply quotient.induction_on₂' x' y', intros x y,
repeat { rw is_quotient_mk <|>
rw ←mk_bracket <|>
rw ←submodule.quotient.mk_smul, },
apply congr_arg, apply lie_smul, } }
end quotient
end lie_submodule
section lie_module
variables (R : Type u) (L : Type v) (M : Type w)
variables [comm_ring R] [lie_ring L] [lie_algebra R L] [add_comm_group M] [module R M]
variables [lie_ring_module L M] [lie_module R L M]
namespace lie_algebra
/-- The derived series of Lie ideals of a Lie algebra. -/
def derived_series : ℕ → lie_ideal R L
| 0 := ⊤
| (k + 1) := ⁅derived_series k, derived_series k⁆
end lie_algebra
namespace lie_module
/-- The lower central series of Lie submodules of a Lie module. -/
def lower_central_series : ℕ → lie_submodule R L M
| 0 := ⊤
| (k + 1) := ⁅(⊤ : lie_ideal R L), lower_central_series k⁆
lemma trivial_iff_derived_eq_bot : is_trivial L M ↔ lower_central_series R L M 1 = ⊥ :=
begin
split; intros h,
{ erw [eq_bot_iff, lie_submodule.lie_span_le], rintros m ⟨x, n, hn⟩, rw [← hn, h.trivial], simp,},
{ rw lie_submodule.eq_bot_iff at h, apply is_trivial.mk, intros x m, apply h,
apply lie_submodule.subset_lie_span, use [x, m], refl, },
end
open lie_algebra
lemma derived_series_le_lower_central_series (k : ℕ) :
derived_series R L k ≤ lower_central_series R L L k :=
begin
induction k with k h,
{ exact le_refl _, },
{ have h' : derived_series R L k ≤ ⊤, { by simp only [le_top], },
exact lie_submodule.mono_lie _ _ _ _ h' h, },
end
end lie_module
end lie_module
section lie_submodule_map_and_comap
variables {R : Type u} {L : Type v} {L' : Type w₂} {M : Type w} {M' : Type w₁}
variables [comm_ring R] [lie_ring L] [lie_algebra R L] [lie_ring L'] [lie_algebra R L']
variables [add_comm_group M] [module R M] [lie_ring_module L M] [lie_module R L M]
variables [add_comm_group M'] [module R M'] [lie_ring_module L M'] [lie_module R L M']
namespace lie_submodule
/-- A morphism of Lie modules `f : M → M'` pushes forward Lie submodules of `M` to Lie submodules
of `M'`. -/
def map (f : M →ₗ⁅R,L⁆ M') (N : lie_submodule R L M) : lie_submodule R L M' :=
{ lie_mem := λ x m' h, by
{ rcases h with ⟨m, hm, hfm⟩, use ⁅x, m⁆, split,
{ apply N.lie_mem hm, },
{ norm_cast at hfm, simp [hfm], }, },
..(N : submodule R M).map (f : M →ₗ[R] M') }
/-- A morphism of Lie modules `f : M → M'` pulls back Lie submodules of `M'` to Lie submodules of
`M`. -/
def comap (f : M →ₗ⁅R,L⁆ M') (N : lie_submodule R L M') : lie_submodule R L M :=
{ lie_mem := λ x m h, by { suffices : ⁅x, f m⁆ ∈ N, { simp [this], }, apply N.lie_mem h, },
..(N : submodule R M').comap (f : M →ₗ[R] M') }
lemma map_le_iff_le_comap {f : M →ₗ⁅R,L⁆ M'} {N : lie_submodule R L M} {N' : lie_submodule R L M'} :
map f N ≤ N' ↔ N ≤ comap f N' := set.image_subset_iff
lemma gc_map_comap (f : M →ₗ⁅R,L⁆ M') : galois_connection (map f) (comap f) :=
λ N N', map_le_iff_le_comap
end lie_submodule
namespace lie_ideal
/-- A morphism of Lie algebras `f : L → L'` pushes forward Lie ideals of `L` to Lie ideals of `L'`.
Note that unlike `lie_submodule.map`, we must take the `lie_span` of the image. Mathematically
this is because although `f` makes `L'` into a Lie module over `L`, in general the `L` submodules of
`L'` are not the same as the ideals of `L'`. -/
def map (f : L →ₗ⁅R⁆ L') (I : lie_ideal R L) : lie_ideal R L' :=
lie_submodule.lie_span R L' (f '' I)
/-- A morphism of Lie algebras `f : L → L'` pulls back Lie ideals of `L'` to Lie ideals of `L`.
Note that `f` makes `L'` into a Lie module over `L` (turning `f` into a morphism of Lie modules)
and so this is a special case of `lie_submodule.comap` but we do not exploit this fact. -/
def comap (f : L →ₗ⁅R⁆ L') (I : lie_ideal R L') : lie_ideal R L :=
{ lie_mem := λ x y h, by { suffices : ⁅f x, f y⁆ ∈ I, { simp [this], }, apply I.lie_mem h, },
..(I : submodule R L').comap (f : L →ₗ[R] L') }
lemma map_le_iff_le_comap {f : L →ₗ⁅R⁆ L'} {I : lie_ideal R L} {I' : lie_ideal R L'} :
map f I ≤ I' ↔ I ≤ comap f I' :=
by { erw lie_submodule.lie_span_le, exact set.image_subset_iff, }
lemma gc_map_comap (f : L →ₗ⁅R⁆ L') : galois_connection (map f) (comap f) :=
λ I I', map_le_iff_le_comap
/-- Regarding an ideal `I` as a subalgebra, the inclusion map into its ambient space is a morphism
of Lie algebras. -/
def incl (I : lie_ideal R L) : I →ₗ⁅R⁆ L := (I : lie_subalgebra R L).incl
@[simp] lemma incl_apply (I : lie_ideal R L) (x : I) : I.incl x = x := rfl
end lie_ideal
end lie_submodule_map_and_comap
section lie_algebra_properties
variables (R : Type u) (L : Type v) (M : Type w)
variables [comm_ring R] [lie_ring L] [lie_algebra R L] [add_comm_group M] [module R M]
variables [lie_ring_module L M] [lie_module R L M]
/-- A Lie module is irreducible if it is zero or its only non-trivial Lie submodule is itself. -/
class lie_module.is_irreducible : Prop :=
(irreducible : ∀ (N : lie_submodule R L M), N ≠ ⊥ → N = ⊤)
/-- A Lie module is nilpotent if its lower central series reaches 0 (in a finite number of steps).-/
class lie_module.is_nilpotent : Prop :=
(nilpotent : ∃ k, lie_module.lower_central_series R L M k = ⊥)
@[priority 100]
instance trivial_is_nilpotent [lie_module.is_trivial L M] : lie_module.is_nilpotent R L M :=
⟨by { use 1, change ⁅⊤, ⊤⁆ = ⊥, simp, }⟩
/-- A Lie algebra is simple if it is irreducible as a Lie module over itself via the adjoint
action, and it is non-Abelian. -/
class lie_algebra.is_simple extends lie_module.is_irreducible R L L : Prop :=
(non_abelian : ¬is_lie_abelian L)
/-- A Lie algebra is solvable if its derived series reaches 0 (in a finite number of steps). -/
class lie_algebra.is_solvable : Prop :=
(solvable : ∃ k, lie_algebra.derived_series R L k = ⊥)
@[priority 100]
instance is_solvable_of_is_nilpotent [hL : lie_module.is_nilpotent R L L] : lie_algebra.is_solvable R L :=
begin
obtain ⟨k, h⟩ : ∃ k, lie_module.lower_central_series R L L k = ⊥ := hL.nilpotent,
use k, rw ← le_bot_iff at h ⊢,
exact le_trans (lie_module.derived_series_le_lower_central_series R L k) h,
end
end lie_algebra_properties
namespace linear_equiv
variables {R : Type u} {M₁ : Type v} {M₂ : Type w}
variables [comm_ring R] [add_comm_group M₁] [module R M₁] [add_comm_group M₂] [module R M₂]
variables (e : M₁ ≃ₗ[R] M₂)
/-- A linear equivalence of two modules induces a Lie algebra equivalence of their endomorphisms. -/
def lie_conj : module.End R M₁ ≃ₗ⁅R⁆ module.End R M₂ :=
{ map_lie := λ f g, show e.conj ⁅f, g⁆ = ⁅e.conj f, e.conj g⁆,
by simp only [lie_ring.of_associative_ring_bracket, linear_map.mul_eq_comp, e.conj_comp,
linear_equiv.map_sub],
..e.conj }
@[simp] lemma lie_conj_apply (f : module.End R M₁) : e.lie_conj f = e.conj f := rfl
@[simp] lemma lie_conj_symm : e.lie_conj.symm = e.symm.lie_conj := rfl
end linear_equiv
namespace alg_equiv
variables {R : Type u} {A₁ : Type v} {A₂ : Type w}
variables [comm_ring R] [ring A₁] [ring A₂] [algebra R A₁] [algebra R A₂]
variables (e : A₁ ≃ₐ[R] A₂)
/-- An equivalence of associative algebras is an equivalence of associated Lie algebras. -/
def to_lie_equiv : A₁ ≃ₗ⁅R⁆ A₂ :=
{ to_fun := e.to_fun,
map_lie := λ x y, by simp [lie_ring.of_associative_ring_bracket],
..e.to_linear_equiv }
@[simp] lemma to_lie_equiv_apply (x : A₁) : e.to_lie_equiv x = e x := rfl
@[simp] lemma to_lie_equiv_symm_apply (x : A₂) : e.to_lie_equiv.symm x = e.symm x := rfl
end alg_equiv
section matrices
open_locale matrix
variables {R : Type u} [comm_ring R]
variables {n : Type w} [decidable_eq n] [fintype n]
/-! ### Matrices
An important class of Lie algebras are those arising from the associative algebra structure on
square matrices over a commutative ring.
-/
/-- The natural equivalence between linear endomorphisms of finite free modules and square matrices
is compatible with the Lie algebra structures. -/
def lie_equiv_matrix' : module.End R (n → R) ≃ₗ⁅R⁆ matrix n n R :=
{ map_lie := λ T S,
begin
let f := @linear_map.to_matrix' R _ n n _ _ _,
change f (T.comp S - S.comp T) = (f T) * (f S) - (f S) * (f T),
have h : ∀ (T S : module.End R _), f (T.comp S) = (f T) ⬝ (f S) := linear_map.to_matrix'_comp,
rw [linear_equiv.map_sub, h, h, matrix.mul_eq_mul, matrix.mul_eq_mul],
end,
..linear_map.to_matrix' }
@[simp] lemma lie_equiv_matrix'_apply (f : module.End R (n → R)) :
lie_equiv_matrix' f = f.to_matrix' := rfl
@[simp] lemma lie_equiv_matrix'_symm_apply (A : matrix n n R) :
(@lie_equiv_matrix' R _ n _ _).symm A = A.to_lin' := rfl
/-- An invertible matrix induces a Lie algebra equivalence from the space of matrices to itself. -/
noncomputable def matrix.lie_conj (P : matrix n n R) (h : is_unit P) :
matrix n n R ≃ₗ⁅R⁆ matrix n n R :=
((@lie_equiv_matrix' R _ n _ _).symm.trans (P.to_linear_equiv h).lie_conj).trans lie_equiv_matrix'
@[simp] lemma matrix.lie_conj_apply (P A : matrix n n R) (h : is_unit P) :
P.lie_conj h A = P ⬝ A ⬝ P⁻¹ :=
by simp [linear_equiv.conj_apply, matrix.lie_conj, linear_map.to_matrix'_comp,
linear_map.to_matrix'_to_lin']
@[simp] lemma matrix.lie_conj_symm_apply (P A : matrix n n R) (h : is_unit P) :
(P.lie_conj h).symm A = P⁻¹ ⬝ A ⬝ P :=
by simp [linear_equiv.symm_conj_apply, matrix.lie_conj, linear_map.to_matrix'_comp,
linear_map.to_matrix'_to_lin']
/-- For square matrices, the natural map that reindexes a matrix's rows and columns with equivalent
types is an equivalence of Lie algebras. -/
def matrix.reindex_lie_equiv {m : Type w₁} [decidable_eq m] [fintype m]
(e : n ≃ m) : matrix n n R ≃ₗ⁅R⁆ matrix m m R :=
{ map_lie := λ M N, by simp only [lie_ring.of_associative_ring_bracket, matrix.reindex_mul,
matrix.mul_eq_mul, linear_equiv.map_sub, linear_equiv.to_fun_apply],
..(matrix.reindex_linear_equiv e e) }
@[simp] lemma matrix.reindex_lie_equiv_apply {m : Type w₁} [decidable_eq m] [fintype m]
(e : n ≃ m) (M : matrix n n R) :
matrix.reindex_lie_equiv e M = λ i j, M (e.symm i) (e.symm j) :=
rfl
@[simp] lemma matrix.reindex_lie_equiv_symm_apply {m : Type w₁} [decidable_eq m] [fintype m]
(e : n ≃ m) (M : matrix m m R) :
(matrix.reindex_lie_equiv e).symm M = λ i j, M (e i) (e j) :=
rfl
end matrices
|
4c1efb21ba4a0ed7f93abf37db203baefa693b2a | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/group_theory/perm/basic.lean | 48d7bacdaf989cfbc2dc65b1e5ee6a87a2e8e2ef | [
"Apache-2.0"
] | permissive | JLimperg/aesop3 | 306cc6570c556568897ed2e508c8869667252e8a | a4a116f650cc7403428e72bd2e2c4cda300fe03f | refs/heads/master | 1,682,884,916,368 | 1,620,320,033,000 | 1,620,320,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,291 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
-/
import algebra.group.pi
import algebra.group_power
/-!
# The group of permutations (self-equivalences) of a type `α`
This file defines the `group` structure on `equiv.perm α`.
-/
universes u v
namespace equiv
variables {α : Type u}
namespace perm
instance perm_group : group (perm α) :=
{ mul := λ f g, equiv.trans g f,
one := equiv.refl α,
inv := equiv.symm,
mul_assoc := λ f g h, (trans_assoc _ _ _).symm,
one_mul := trans_refl,
mul_one := refl_trans,
mul_left_inv := trans_symm }
theorem mul_apply (f g : perm α) (x) : (f * g) x = f (g x) :=
equiv.trans_apply _ _ _
theorem one_apply (x) : (1 : perm α) x = x := rfl
@[simp] lemma inv_apply_self (f : perm α) (x) : f⁻¹ (f x) = x := f.symm_apply_apply x
@[simp] lemma apply_inv_self (f : perm α) (x) : f (f⁻¹ x) = x := f.apply_symm_apply x
lemma one_def : (1 : perm α) = equiv.refl α := rfl
lemma mul_def (f g : perm α) : f * g = g.trans f := rfl
lemma inv_def (f : perm α) : f⁻¹ = f.symm := rfl
@[simp] lemma coe_mul (f g : perm α) : ⇑(f * g) = f ∘ g := rfl
@[simp] lemma coe_one : ⇑(1 : perm α) = id := rfl
lemma eq_inv_iff_eq {f : perm α} {x y : α} : x = f⁻¹ y ↔ f x = y := f.eq_symm_apply
lemma inv_eq_iff_eq {f : perm α} {x y : α} : f⁻¹ x = y ↔ x = f y := f.symm_apply_eq
lemma gpow_apply_comm {α : Type*} (σ : equiv.perm α) (m n : ℤ) {x : α} :
(σ ^ m) ((σ ^ n) x) = (σ ^ n) ((σ ^ m) x) :=
by rw [←equiv.perm.mul_apply, ←equiv.perm.mul_apply, gpow_mul_comm]
/-! Lemmas about mixing `perm` with `equiv`. Because we have multiple ways to express
`equiv.refl`, `equiv.symm`, and `equiv.trans`, we want simp lemmas for every combination.
The assumption made here is that if you're using the group structure, you want to preserve it after
simp. -/
@[simp] lemma trans_one {α : Sort*} {β : Type*} (e : α ≃ β) : e.trans (1 : perm β) = e :=
equiv.trans_refl e
@[simp] lemma mul_refl (e : perm α) : e * equiv.refl α = e := equiv.trans_refl e
@[simp] lemma one_symm : (1 : perm α).symm = 1 := equiv.refl_symm
@[simp] lemma refl_inv : (equiv.refl α : perm α)⁻¹ = 1 := equiv.refl_symm
@[simp] lemma one_trans {α : Type*} {β : Sort*} (e : α ≃ β) : (1 : perm α).trans e = e :=
equiv.refl_trans e
@[simp] lemma refl_mul (e : perm α) : equiv.refl α * e = e := equiv.refl_trans e
@[simp] lemma inv_trans (e : perm α) : e⁻¹.trans e = 1 := equiv.symm_trans e
@[simp] lemma mul_symm (e : perm α) : e * e.symm = 1 := equiv.symm_trans e
@[simp] lemma trans_inv (e : perm α) : e.trans e⁻¹ = 1 := equiv.trans_symm e
@[simp] lemma symm_mul (e : perm α) : e.symm * e = 1 := equiv.trans_symm e
/-! Lemmas about `equiv.perm.sum_congr` re-expressed via the group structure. -/
@[simp] lemma sum_congr_mul {α β : Type*} (e : perm α) (f : perm β) (g : perm α) (h : perm β) :
sum_congr e f * sum_congr g h = sum_congr (e * g) (f * h) :=
sum_congr_trans g h e f
@[simp] lemma sum_congr_inv {α β : Type*} (e : perm α) (f : perm β) :
(sum_congr e f)⁻¹ = sum_congr e⁻¹ f⁻¹ :=
sum_congr_symm e f
@[simp] lemma sum_congr_one {α β : Type*} :
sum_congr (1 : perm α) (1 : perm β) = 1 :=
sum_congr_refl
/-- `equiv.perm.sum_congr` as a `monoid_hom`, with its two arguments bundled into a single `prod`.
This is particularly useful for its `monoid_hom.range` projection, which is the subgroup of
permutations which do not exchange elements between `α` and `β`. -/
@[simps]
def sum_congr_hom (α β : Type*) :
perm α × perm β →* perm (α ⊕ β) :=
{ to_fun := λ a, sum_congr a.1 a.2,
map_one' := sum_congr_one,
map_mul' := λ a b, (sum_congr_mul _ _ _ _).symm}
lemma sum_congr_hom_injective {α β : Type*} :
function.injective (sum_congr_hom α β) :=
begin
rintros ⟨⟩ ⟨⟩ h,
rw prod.mk.inj_iff,
split; ext i,
{ simpa using equiv.congr_fun h (sum.inl i), },
{ simpa using equiv.congr_fun h (sum.inr i), },
end
@[simp] lemma sum_congr_swap_one {α β : Type*} [decidable_eq α] [decidable_eq β] (i j : α) :
sum_congr (equiv.swap i j) (1 : perm β) = equiv.swap (sum.inl i) (sum.inl j) :=
sum_congr_swap_refl i j
@[simp] lemma sum_congr_one_swap {α β : Type*} [decidable_eq α] [decidable_eq β] (i j : β) :
sum_congr (1 : perm α) (equiv.swap i j) = equiv.swap (sum.inr i) (sum.inr j) :=
sum_congr_refl_swap i j
/-! Lemmas about `equiv.perm.sigma_congr_right` re-expressed via the group structure. -/
@[simp] lemma sigma_congr_right_mul {α : Type*} {β : α → Type*}
(F : Π a, perm (β a)) (G : Π a, perm (β a)) :
sigma_congr_right F * sigma_congr_right G = sigma_congr_right (F * G) :=
sigma_congr_right_trans G F
@[simp] lemma sigma_congr_right_inv {α : Type*} {β : α → Type*} (F : Π a, perm (β a)) :
(sigma_congr_right F)⁻¹ = sigma_congr_right (λ a, (F a)⁻¹) :=
sigma_congr_right_symm F
@[simp] lemma sigma_congr_right_one {α : Type*} {β : α → Type*} :
(sigma_congr_right (1 : Π a, equiv.perm $ β a)) = 1 :=
sigma_congr_right_refl
/-- `equiv.perm.sigma_congr_right` as a `monoid_hom`.
This is particularly useful for its `monoid_hom.range` projection, which is the subgroup of
permutations which do not exchange elements between fibers. -/
@[simps]
def sigma_congr_right_hom {α : Type*} (β : α → Type*) :
(Π a, perm (β a)) →* perm (Σ a, β a) :=
{ to_fun := sigma_congr_right,
map_one' := sigma_congr_right_one,
map_mul' := λ a b, (sigma_congr_right_mul _ _).symm }
lemma sigma_congr_right_hom_injective {α : Type*} {β : α → Type*} :
function.injective (sigma_congr_right_hom β) :=
begin
intros x y h,
ext a b,
simpa using equiv.congr_fun h ⟨a, b⟩,
end
/-- `equiv.perm.subtype_congr` as a `monoid_hom`. -/
@[simps] def subtype_congr_hom (p : α → Prop) [decidable_pred p] :
(perm {a // p a}) × (perm {a // ¬ p a}) →* perm α :=
{ to_fun := λ pair, perm.subtype_congr pair.fst pair.snd,
map_one' := perm.subtype_congr.refl,
map_mul' := λ _ _, (perm.subtype_congr.trans _ _ _ _).symm }
lemma subtype_congr_hom_injective (p : α → Prop) [decidable_pred p] :
function.injective (subtype_congr_hom p) :=
begin
rintros ⟨⟩ ⟨⟩ h,
rw prod.mk.inj_iff,
split;
ext i;
simpa using equiv.congr_fun h i
end
/-- If `e` is also a permutation, we can write `perm_congr`
completely in terms of the group structure. -/
@[simp] lemma perm_congr_eq_mul (e p : perm α) :
e.perm_congr p = e * p * e⁻¹ := rfl
section extend_domain
/-! Lemmas about `equiv.perm.extend_domain` re-expressed via the group structure. -/
variables {β : Type*} (e : perm α) {p : β → Prop} [decidable_pred p] (f : α ≃ subtype p)
@[simp] lemma extend_domain_one : extend_domain 1 f = 1 :=
extend_domain_refl f
@[simp] lemma extend_domain_inv : (e.extend_domain f)⁻¹ = e⁻¹.extend_domain f := rfl
@[simp] lemma extend_domain_mul (e e' : perm α) :
(e.extend_domain f) * (e'.extend_domain f) = (e * e').extend_domain f :=
extend_domain_trans _ _ _
end extend_domain
/-- If the permutation `f` fixes the subtype `{x // p x}`, then this returns the permutation
on `{x // p x}` induced by `f`. -/
def subtype_perm (f : perm α) {p : α → Prop} (h : ∀ x, p x ↔ p (f x)) : perm {x // p x} :=
⟨λ x, ⟨f x, (h _).1 x.2⟩, λ x, ⟨f⁻¹ x, (h (f⁻¹ x)).2 $ by simpa using x.2⟩,
λ _, by simp only [perm.inv_apply_self, subtype.coe_eta, subtype.coe_mk],
λ _, by simp only [perm.apply_inv_self, subtype.coe_eta, subtype.coe_mk]⟩
@[simp] lemma subtype_perm_apply (f : perm α) {p : α → Prop} (h : ∀ x, p x ↔ p (f x))
(x : {x // p x}) : subtype_perm f h x = ⟨f x, (h _).1 x.2⟩ := rfl
@[simp] lemma subtype_perm_one (p : α → Prop) (h : ∀ x, p x ↔ p ((1 : perm α) x)) :
@subtype_perm α 1 p h = 1 :=
equiv.ext $ λ ⟨_, _⟩, rfl
/-- The inclusion map of permutations on a subtype of `α` into permutations of `α`,
fixing the other points. -/
def of_subtype {p : α → Prop} [decidable_pred p] : perm (subtype p) →* perm α :=
{ to_fun := λ f,
⟨λ x, if h : p x then f ⟨x, h⟩ else x, λ x, if h : p x then f⁻¹ ⟨x, h⟩ else x,
λ x, have h : ∀ h : p x, p (f ⟨x, h⟩), from λ h, (f ⟨x, h⟩).2,
by { simp only [], split_ifs at *;
simp only [perm.inv_apply_self, subtype.coe_eta, subtype.coe_mk, not_true, *] at * },
λ x, have h : ∀ h : p x, p (f⁻¹ ⟨x, h⟩), from λ h, (f⁻¹ ⟨x, h⟩).2,
by { simp only [], split_ifs at *;
simp only [perm.apply_inv_self, subtype.coe_eta, subtype.coe_mk, not_true, *] at * }⟩,
map_one' := begin ext, dsimp, split_ifs; refl, end,
map_mul' := λ f g, equiv.ext $ λ x, begin
by_cases h : p x,
{ have h₁ : p (f (g ⟨x, h⟩)), from (f (g ⟨x, h⟩)).2,
have h₂ : p (g ⟨x, h⟩), from (g ⟨x, h⟩).2,
simp only [h, h₂, coe_fn_mk, perm.mul_apply, dif_pos, subtype.coe_eta] },
{ simp only [h, coe_fn_mk, perm.mul_apply, dif_neg, not_false_iff] }
end }
lemma of_subtype_subtype_perm {f : perm α} {p : α → Prop} [decidable_pred p]
(h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) :
of_subtype (subtype_perm f h₁) = f :=
equiv.ext $ λ x, begin
rw [of_subtype, subtype_perm],
by_cases hx : p x,
{ simp only [hx, coe_fn_mk, dif_pos, monoid_hom.coe_mk, subtype.coe_mk]},
{ haveI := classical.prop_decidable,
simp only [hx, not_not.mp (mt (h₂ x) hx), coe_fn_mk, dif_neg, not_false_iff,
monoid_hom.coe_mk] }
end
lemma of_subtype_apply_of_not_mem {p : α → Prop} [decidable_pred p]
(f : perm (subtype p)) {x : α} (hx : ¬ p x) :
of_subtype f x = x :=
dif_neg hx
lemma mem_iff_of_subtype_apply_mem {p : α → Prop} [decidable_pred p]
(f : perm (subtype p)) (x : α) :
p x ↔ p ((of_subtype f : α → α) x) :=
if h : p x then by simpa only [of_subtype, h, coe_fn_mk, dif_pos, true_iff, monoid_hom.coe_mk]
using (f ⟨x, h⟩).2
else by simp [h, of_subtype_apply_of_not_mem f h]
@[simp] lemma subtype_perm_of_subtype {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) :
subtype_perm (of_subtype f) (mem_iff_of_subtype_apply_mem f) = f :=
equiv.ext $ λ ⟨x, hx⟩, by { dsimp [subtype_perm, of_subtype],
simp only [show p x, from hx, dif_pos, subtype.coe_eta] }
instance perm_unique {n : Type*} [unique n] : unique (equiv.perm n) :=
{ default := 1,
uniq := λ σ, equiv.ext (λ i, subsingleton.elim _ _) }
@[simp] lemma default_perm {n : Type*} : default (equiv.perm n) = 1 := rfl
end perm
section swap
variables [decidable_eq α]
@[simp] lemma swap_inv (x y : α) : (swap x y)⁻¹ = swap x y := rfl
@[simp] lemma swap_mul_self (i j : α) : swap i j * swap i j = 1 := swap_swap i j
lemma swap_mul_eq_mul_swap (f : perm α) (x y : α) : swap x y * f = f * swap (f⁻¹ x) (f⁻¹ y) :=
equiv.ext $ λ z, begin
simp only [perm.mul_apply, swap_apply_def],
split_ifs;
simp only [perm.apply_inv_self, *, perm.eq_inv_iff_eq, eq_self_iff_true, not_true] at *
end
lemma mul_swap_eq_swap_mul (f : perm α) (x y : α) : f * swap x y = swap (f x) (f y) * f :=
by rw [swap_mul_eq_mul_swap, perm.inv_apply_self, perm.inv_apply_self]
lemma swap_apply_apply (f : perm α) (x y : α) : swap (f x) (f y) = f * swap x y * f⁻¹ :=
by rw [mul_swap_eq_swap_mul, mul_inv_cancel_right]
/-- Left-multiplying a permutation with `swap i j` twice gives the original permutation.
This specialization of `swap_mul_self` is useful when using cosets of permutations.
-/
@[simp]
lemma swap_mul_self_mul (i j : α) (σ : perm α) : equiv.swap i j * (equiv.swap i j * σ) = σ :=
by rw [←mul_assoc, swap_mul_self, one_mul]
/-- Right-multiplying a permutation with `swap i j` twice gives the original permutation.
This specialization of `swap_mul_self` is useful when using cosets of permutations.
-/
@[simp]
lemma mul_swap_mul_self (i j : α) (σ : perm α) : (σ * equiv.swap i j) * equiv.swap i j = σ :=
by rw [mul_assoc, swap_mul_self, mul_one]
/-- A stronger version of `mul_right_injective` -/
@[simp]
lemma swap_mul_involutive (i j : α) : function.involutive ((*) (equiv.swap i j)) :=
swap_mul_self_mul i j
/-- A stronger version of `mul_left_injective` -/
@[simp]
lemma mul_swap_involutive (i j : α) : function.involutive (* (equiv.swap i j)) :=
mul_swap_mul_self i j
@[simp] lemma swap_eq_one_iff {i j : α} : swap i j = (1 : perm α) ↔ i = j :=
swap_eq_refl_iff
lemma swap_mul_eq_iff {i j : α} {σ : perm α} : swap i j * σ = σ ↔ i = j :=
⟨(assume h, have swap_id : swap i j = 1 := mul_right_cancel (trans h (one_mul σ).symm),
by {rw [←swap_apply_right i j, swap_id], refl}),
(assume h, by erw [h, swap_self, one_mul])⟩
lemma mul_swap_eq_iff {i j : α} {σ : perm α} : σ * swap i j = σ ↔ i = j :=
⟨(assume h, have swap_id : swap i j = 1 := mul_left_cancel (trans h (one_mul σ).symm),
by {rw [←swap_apply_right i j, swap_id], refl}),
(assume h, by erw [h, swap_self, mul_one])⟩
lemma swap_mul_swap_mul_swap {x y z : α} (hwz: x ≠ y) (hxz : x ≠ z) :
swap y z * swap x y * swap y z = swap z x :=
equiv.ext $ λ n, by { simp only [swap_apply_def, perm.mul_apply], split_ifs; cc }
end swap
end equiv
|
ea8198c38b28fd9ee2fe2a4434b2501f2b6af151 | 07c76fbd96ea1786cc6392fa834be62643cea420 | /hott/types/pointed.hlean | 0b73686d78ed3a8adcd8bd50ae690eff7d9820f2 | [
"Apache-2.0"
] | permissive | fpvandoorn/lean2 | 5a430a153b570bf70dc8526d06f18fc000a60ad9 | 0889cf65b7b3cebfb8831b8731d89c2453dd1e9f | refs/heads/master | 1,592,036,508,364 | 1,545,093,958,000 | 1,545,093,958,000 | 75,436,854 | 0 | 0 | null | 1,480,718,780,000 | 1,480,718,780,000 | null | UTF-8 | Lean | false | false | 53,826 | hlean | /-
Copyright (c) 2014-2016 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer, Floris van Doorn
Early library ported from Coq HoTT, but greatly extended since.
The basic definitions are in init.pointed
See also .pointed2
-/
import .nat.basic ..prop_trunc
open is_trunc eq prod sigma nat equiv option is_equiv bool unit sigma.ops sum algebra function
namespace pointed
variables {A B : Type}
definition pointed_loop [instance] [constructor] (a : A) : pointed (a = a) :=
pointed.mk idp
definition pointed_fun_closed [constructor] (f : A → B) [H : pointed A] : pointed B :=
pointed.mk (f pt)
definition loop [reducible] [constructor] (A : Type*) : Type* :=
pointed.mk' (point A = point A)
definition loopn [reducible] : ℕ → Type* → Type*
| loopn 0 X := X
| loopn (n+1) X := loop (loopn n X)
notation `Ω` := loop
notation `Ω[`:95 n:0 `]`:0 := loopn n
namespace ops
-- this is in a separate namespace because it caused type class inference to loop in some places
definition is_trunc_pointed_MK [instance] [priority 1100] (n : ℕ₋₂) {A : Type} (a : A)
[H : is_trunc n A] : is_trunc n (pointed.MK A a) :=
H
end ops
definition is_trunc_loop [instance] [priority 1100] (A : Type*)
(n : ℕ₋₂) [H : is_trunc (n.+1) A] : is_trunc n (Ω A) :=
!is_trunc_eq
definition loopn_zero_eq [unfold_full] (A : Type*)
: Ω[0] A = A := rfl
definition loopn_succ_eq [unfold_full] (k : ℕ) (A : Type*)
: Ω[succ k] A = Ω (Ω[k] A) := rfl
definition rfln [constructor] [reducible] {n : ℕ} {A : Type*} : Ω[n] A := pt
definition refln [constructor] [reducible] (n : ℕ) (A : Type*) : Ω[n] A := pt
definition refln_eq_refl [unfold_full] (A : Type*) (n : ℕ) : rfln = rfl :> Ω[succ n] A := rfl
definition loopn_space [unfold 3] (A : Type) [H : pointed A] (n : ℕ) : Type :=
Ω[n] (pointed.mk' A)
definition loop_mul {k : ℕ} {A : Type*} (mul : A → A → A) : Ω[k] A → Ω[k] A → Ω[k] A :=
begin cases k with k, exact mul, exact concat end
definition pType_eq {A B : Type*} (f : A ≃ B) (p : f pt = pt) : A = B :=
begin
cases A with A a, cases B with B b, esimp at *,
fapply apdt011 @pType.mk,
{ apply ua f},
{ rewrite [cast_ua, p]},
end
definition pType_eq_elim {A B : Type*} (p : A = B :> Type*)
: Σ(p : carrier A = carrier B :> Type), Point A =[p] Point B :=
by induction p; exact ⟨idp, idpo⟩
definition pType.sigma_char.{u} [constructor] : pType.{u} ≃ Σ(X : Type.{u}), X :=
begin
fapply equiv.MK,
{ intro X, exact ⟨X, pt⟩ },
{ intro X, exact pointed.MK X.1 X.2 },
{ intro x, induction x with X x, reflexivity },
{ intro x, induction x with X x, reflexivity },
end
definition pType.eta_expand [constructor] (A : Type*) : Type* :=
pointed.MK A pt
definition add_point [constructor] (A : Type) : Type* :=
pointed.Mk (none : option A)
postfix `₊`:(max+1) := add_point
-- the inclusion A → A₊ is called "some", the extra point "pt" or "none" ("@none A")
end pointed
namespace pointed
/- truncated pointed types -/
definition ptrunctype_eq {n : ℕ₋₂} {A B : n-Type*}
(p : A = B :> Type) (q : Point A =[p] Point B) : A = B :=
begin
induction A with A HA a, induction B with B HB b, esimp at *,
induction q, esimp,
refine ap010 (ptrunctype.mk A) _ a,
exact !is_prop.elim
end
definition ptrunctype_eq_of_pType_eq {n : ℕ₋₂} {A B : n-Type*} (p : A = B :> Type*)
: A = B :=
begin
cases pType_eq_elim p with q r,
exact ptrunctype_eq q r
end
definition is_trunc_ptrunctype [instance] {n : ℕ₋₂} (A : n-Type*) : is_trunc n A :=
trunctype.struct A
end pointed open pointed
namespace pointed
variables {A B C D : Type*} {f g h : A →* B} {P : A → Type} {p₀ : P pt} {k k' l m : ppi P p₀}
/- categorical properties of pointed maps -/
definition pid [constructor] [refl] (A : Type*) : A →* A :=
pmap.mk id idp
definition pcompose [constructor] [trans] {A B C : Type*} (g : B →* C) (f : A →* B) : A →* C :=
pmap.mk (λa, g (f a)) (ap g (respect_pt f) ⬝ respect_pt g)
infixr ` ∘* `:60 := pcompose
definition pmap_of_map [constructor] {A B : Type} (f : A → B) (a : A) :
pointed.MK A a →* pointed.MK B (f a) :=
pmap.mk f idp
definition respect_pt_pcompose {A B C : Type*} (g : B →* C) (f : A →* B)
: respect_pt (g ∘* f) = ap g (respect_pt f) ⬝ respect_pt g :=
idp
definition passoc [constructor] (h : C →* D) (g : B →* C) (f : A →* B) : (h ∘* g) ∘* f ~* h ∘* (g ∘* f) :=
phomotopy.mk (λa, idp)
abstract !idp_con ⬝ whisker_right _ (!ap_con ⬝ whisker_right _ !ap_compose') ⬝ !con.assoc end
definition pid_pcompose [constructor] (f : A →* B) : pid B ∘* f ~* f :=
begin
fapply phomotopy.mk,
{ intro a, reflexivity},
{ reflexivity}
end
definition pcompose_pid [constructor] (f : A →* B) : f ∘* pid A ~* f :=
begin
fapply phomotopy.mk,
{ intro a, reflexivity},
{ reflexivity}
end
/- equivalences and equalities -/
protected definition ppi.sigma_char [constructor] {A : Type*} (B : A → Type) (b₀ : B pt) :
ppi B b₀ ≃ Σ(k : Πa, B a), k pt = b₀ :=
begin
fapply equiv.MK: intro x,
{ constructor, exact respect_pt x },
{ induction x, constructor, assumption },
{ induction x, reflexivity },
{ induction x, reflexivity }
end
definition pmap.sigma_char [constructor] (A B : Type*) : (A →* B) ≃ Σ(f : A → B), f pt = pt :=
!ppi.sigma_char
definition pmap.eta_expand [constructor] {A B : Type*} (f : A →* B) : A →* B :=
pmap.mk f (respect_pt f)
definition pmap_eta [constructor] {X Y : Type*} (f : X →* Y) : f ~* pmap.mk f (respect_pt f) :=
begin
fapply phomotopy.mk,
reflexivity,
esimp, exact !idp_con
end
definition pmap_eta_eq {A B : Type*} (f : A →* B) : pmap.mk f (respect_pt f) = f :=
begin induction f, reflexivity end
definition pmap_equiv_right (A : Type*) (B : Type)
: (Σ(b : B), A →* (pointed.Mk b)) ≃ (A → B) :=
begin
fapply equiv.MK,
{ intro u a, exact pmap.to_fun u.2 a},
{ intro f, refine ⟨f pt, _⟩, fapply pmap.mk,
intro a, esimp, exact f a,
reflexivity},
{ intro f, reflexivity},
{ intro u, cases u with b f, cases f with f p, esimp at *, induction p,
reflexivity}
end
/- some specific pointed maps -/
-- The constant pointed map between any two types
definition pconst [constructor] (A B : Type*) : A →* B :=
!ppi_const
-- the pointed type of pointed maps
definition ppmap [constructor] (A B : Type*) : Type* :=
@pppi A (λa, B)
infixr ` →** `:29 := ppmap
definition pcast [constructor] {A B : Type*} (p : A = B) : A →* B :=
pmap.mk (cast (ap pType.carrier p)) (by induction p; reflexivity)
definition pinverse [constructor] (X : Type*) : Ω X →* Ω X :=
pmap.mk eq.inverse idp
/-
we generalize the definition of ap1 to arbitrary paths, so that we can prove properties about it
using path induction (see for example ap1_gen_con and ap1_gen_con_natural)
-/
definition ap1_gen [reducible] [unfold 8 9 10] {A B : Type} (f : A → B) {a a' : A}
{b b' : B} (q : f a = b) (q' : f a' = b') (p : a = a') : b = b' :=
q⁻¹ ⬝ ap f p ⬝ q'
definition ap1_gen_idp [unfold 6] {A B : Type} (f : A → B) {a : A} {b : B} (q : f a = b) :
ap1_gen f q q idp = idp :=
con.left_inv q
definition ap1_gen_idp_left [unfold 6] {A B : Type} (f : A → B) {a a' : A} (p : a = a') :
ap1_gen f idp idp p = ap f p :=
proof idp_con (ap f p) qed
definition ap1_gen_idp_left_con {A B : Type} (f : A → B) {a : A} (p : a = a) (q : ap f p = idp) :
ap1_gen_idp_left f p ⬝ q = proof ap (concat idp) q qed :=
proof idp_con_idp q qed
definition ap1 [constructor] (f : A →* B) : Ω A →* Ω B :=
pmap.mk (λp, ap1_gen f (respect_pt f) (respect_pt f) p) (ap1_gen_idp f (respect_pt f))
definition apn (n : ℕ) (f : A →* B) : Ω[n] A →* Ω[n] B :=
begin
induction n with n IH,
{ exact f},
{ esimp [loopn], exact ap1 IH}
end
notation `Ω→`:(max+5) := ap1
notation `Ω→[`:95 n:0 `]`:0 := apn n
definition ptransport [constructor] {A : Type} (B : A → Type*) {a a' : A} (p : a = a')
: B a →* B a' :=
pmap.mk (transport B p) (apdt (λa, Point (B a)) p)
definition pmap_of_eq_pt [constructor] {A : Type} {a a' : A} (p : a = a') :
pointed.MK A a →* pointed.MK A a' :=
pmap.mk id p
definition pbool_pmap [constructor] {A : Type*} (a : A) : pbool →* A :=
pmap.mk (bool.rec pt a) idp
/- properties of pointed maps -/
definition apn_zero [unfold_full] (f : A →* B) : Ω→[0] f = f := idp
definition apn_succ [unfold_full] (n : ℕ) (f : A →* B) : Ω→[n + 1] f = Ω→ (Ω→[n] f) := idp
definition ap1_gen_con {A B : Type} (f : A → B) {a₁ a₂ a₃ : A} {b₁ b₂ b₃ : B}
(q₁ : f a₁ = b₁) (q₂ : f a₂ = b₂) (q₃ : f a₃ = b₃) (p₁ : a₁ = a₂) (p₂ : a₂ = a₃) :
ap1_gen f q₁ q₃ (p₁ ⬝ p₂) = ap1_gen f q₁ q₂ p₁ ⬝ ap1_gen f q₂ q₃ p₂ :=
begin induction p₂, induction q₃, induction q₂, reflexivity end
definition ap1_gen_inv {A B : Type} (f : A → B) {a₁ a₂ : A}
{b₁ b₂ : B} (q₁ : f a₁ = b₁) (q₂ : f a₂ = b₂) (p₁ : a₁ = a₂) :
ap1_gen f q₂ q₁ p₁⁻¹ = (ap1_gen f q₁ q₂ p₁)⁻¹ :=
begin induction p₁, induction q₁, induction q₂, reflexivity end
definition ap1_con {A B : Type*} (f : A →* B) (p q : Ω A) : ap1 f (p ⬝ q) = ap1 f p ⬝ ap1 f q :=
ap1_gen_con f (respect_pt f) (respect_pt f) (respect_pt f) p q
theorem ap1_inv (f : A →* B) (p : Ω A) : ap1 f p⁻¹ = (ap1 f p)⁻¹ :=
ap1_gen_inv f (respect_pt f) (respect_pt f) p
-- the following two facts are used for the suspension axiom to define spectrum cohomology
definition ap1_gen_con_natural {A B : Type} (f : A → B) {a₁ a₂ a₃ : A} {p₁ p₁' : a₁ = a₂}
{p₂ p₂' : a₂ = a₃}
{b₁ b₂ b₃ : B} (q₁ : f a₁ = b₁) (q₂ : f a₂ = b₂) (q₃ : f a₃ = b₃)
(r₁ : p₁ = p₁') (r₂ : p₂ = p₂') :
square (ap1_gen_con f q₁ q₂ q₃ p₁ p₂)
(ap1_gen_con f q₁ q₂ q₃ p₁' p₂')
(ap (ap1_gen f q₁ q₃) (r₁ ◾ r₂))
(ap (ap1_gen f q₁ q₂) r₁ ◾ ap (ap1_gen f q₂ q₃) r₂) :=
begin induction r₁, induction r₂, exact vrfl end
definition ap1_gen_con_idp {A B : Type} (f : A → B) {a : A} {b : B} (q : f a = b) :
ap1_gen_con f q q q idp idp ⬝ con.left_inv q ◾ con.left_inv q = con.left_inv q :=
by induction q; reflexivity
definition apn_con (n : ℕ) (f : A →* B) (p q : Ω[n+1] A)
: apn (n+1) f (p ⬝ q) = apn (n+1) f p ⬝ apn (n+1) f q :=
ap1_con (apn n f) p q
definition apn_inv (n : ℕ) (f : A →* B) (p : Ω[n+1] A) : apn (n+1) f p⁻¹ = (apn (n+1) f p)⁻¹ :=
ap1_inv (apn n f) p
definition is_equiv_ap1 (f : A →* B) [is_equiv f] : is_equiv (ap1 f) :=
begin
induction B with B b, induction f with f pf, esimp at *, cases pf, esimp,
refine is_equiv.homotopy_closed (ap f) _ _,
intro p, exact !idp_con⁻¹
end
definition pinverse_con [constructor] {X : Type*} (p q : Ω X)
: pinverse X (p ⬝ q) = pinverse X q ⬝ pinverse X p :=
!con_inv
definition pinverse_inv [constructor] {X : Type*} (p : Ω X)
: pinverse X p⁻¹ = (pinverse X p)⁻¹ :=
idp
definition is_equiv_pcast [instance] {A B : Type*} (p : A = B) : is_equiv (pcast p) :=
!is_equiv_cast
definition pcompose_pconst [constructor] (f : B →* C) : f ∘* pconst A B ~* pconst A C :=
phomotopy.mk (λa, respect_pt f) (idp_con _)⁻¹
definition pconst_pcompose [constructor] (f : A →* B) : pconst B C ∘* f ~* pconst A C :=
phomotopy.mk (λa, rfl) !ap_constant⁻¹
/- categorical properties of pointed homotopies -/
variable (k)
protected definition phomotopy.refl [constructor] : k ~* k :=
phomotopy.mk homotopy.rfl !idp_con
variable {k}
protected definition phomotopy.rfl [reducible] [constructor] [refl] : k ~* k :=
phomotopy.refl k
protected definition phomotopy.symm [constructor] [symm] (p : k ~* l) : l ~* k :=
phomotopy.mk p⁻¹ʰᵗʸ (inv_con_eq_of_eq_con (to_homotopy_pt p)⁻¹)
protected definition phomotopy.trans [constructor] [trans] (p : k ~* l) (q : l ~* m) :
k ~* m :=
phomotopy.mk (λa, p a ⬝ q a) (!con.assoc ⬝ whisker_left (p pt) (to_homotopy_pt q) ⬝ to_homotopy_pt p)
infix ` ⬝* `:75 := phomotopy.trans
postfix `⁻¹*`:(max+1) := phomotopy.symm
/- equalities and equivalences relating pointed homotopies -/
definition to_homotopy_pt_mk {A B : Type*} {f g : A →* B} (h : f ~ g)
(p : h pt ⬝ respect_pt g = respect_pt f) : to_homotopy_pt (phomotopy.mk h p) = p :=
to_right_inv !eq_con_inv_equiv_con_eq p
definition phomotopy.rec' [recursor] (B : k ~* l → Type)
(H : Π(h : k ~ l) (p : h pt ⬝ respect_pt l = respect_pt k), B (phomotopy.mk h p))
(h : k ~* l) : B h :=
begin
induction h with h p,
refine transport (λp, B (ppi.mk h p)) _ (H h (con_eq_of_eq_con_inv p)),
apply to_left_inv !eq_con_inv_equiv_con_eq p
end
definition phomotopy.eta_expand [constructor] (p : k ~* l) : k ~* l :=
phomotopy.mk p (to_homotopy_pt p)
definition is_trunc_ppi [instance] (n : ℕ₋₂) {A : Type*} (B : A → Type) (b₀ : B pt)
[Πa, is_trunc n (B a)] : is_trunc n (ppi B b₀) :=
is_trunc_equiv_closed_rev _ !ppi.sigma_char _
definition is_trunc_pmap [instance] (n : ℕ₋₂) (A B : Type*) [is_trunc n B] :
is_trunc n (A →* B) :=
!is_trunc_ppi
definition is_trunc_ppmap [instance] (n : ℕ₋₂) {A B : Type*} [is_trunc n B] :
is_trunc n (ppmap A B) :=
!is_trunc_pmap
definition phomotopy_of_eq [constructor] (p : k = l) : k ~* l :=
phomotopy.mk (ap010 ppi.to_fun p) begin induction p, refine !idp_con end
definition phomotopy_of_eq_idp (k : ppi P p₀) : phomotopy_of_eq idp = phomotopy.refl k :=
idp
definition pconcat_eq [constructor] (p : k ~* l) (q : l = m) : k ~* m :=
p ⬝* phomotopy_of_eq q
definition eq_pconcat [constructor] (p : k = l) (q : l ~* m) : k ~* m :=
phomotopy_of_eq p ⬝* q
infix ` ⬝*p `:75 := pconcat_eq
infix ` ⬝p* `:75 := eq_pconcat
definition pr1_phomotopy_eq {p q : k ~* l} (r : p = q) (a : A) : p a = q a :=
ap010 to_homotopy r a
definition pwhisker_left [constructor] (h : B →* C) (p : f ~* g) : h ∘* f ~* h ∘* g :=
phomotopy.mk (λa, ap h (p a))
abstract !con.assoc⁻¹ ⬝ whisker_right _ (!ap_con⁻¹ ⬝ ap02 _ (to_homotopy_pt p)) end
definition pwhisker_right [constructor] (h : C →* A) (p : f ~* g) : f ∘* h ~* g ∘* h :=
phomotopy.mk (λa, p (h a))
abstract !con.assoc⁻¹ ⬝ whisker_right _ (!ap_con_eq_con_ap)⁻¹ ⬝ !con.assoc ⬝
whisker_left _ (to_homotopy_pt p) end
definition pconcat2 [constructor] {A B C : Type*} {h i : B →* C} {f g : A →* B}
(q : h ~* i) (p : f ~* g) : h ∘* f ~* i ∘* g :=
pwhisker_left _ p ⬝* pwhisker_right _ q
variables (k l)
definition phomotopy.sigma_char [constructor]
: (k ~* l) ≃ Σ(p : k ~ l), p pt ⬝ respect_pt l = respect_pt k :=
begin
fapply equiv.MK : intros h,
{ exact ⟨h , to_homotopy_pt h⟩ },
{ cases h with h p, exact phomotopy.mk h p },
{ cases h with h p, exact ap (dpair h) (to_right_inv !eq_con_inv_equiv_con_eq p) },
{ induction h using phomotopy.rec' with h p,
exact ap (phomotopy.mk h) (to_right_inv !eq_con_inv_equiv_con_eq p) }
end
definition ppi_eq_equiv_internal : (k = l) ≃ (k ~* l) :=
calc (k = l) ≃ ppi.sigma_char P p₀ k = ppi.sigma_char P p₀ l
: eq_equiv_fn_eq (ppi.sigma_char P p₀) k l
... ≃ Σ(p : k = l),
pathover (λh, h pt = p₀) (respect_pt k) p (respect_pt l)
: sigma_eq_equiv _ _
... ≃ Σ(p : k = l),
respect_pt k = ap (λh, h pt) p ⬝ respect_pt l
: sigma_equiv_sigma_right
(λp, eq_pathover_equiv_Fl p (respect_pt k) (respect_pt l))
... ≃ Σ(p : k = l),
respect_pt k = apd10 p pt ⬝ respect_pt l
: sigma_equiv_sigma_right
(λp, equiv_eq_closed_right _ (whisker_right _ (ap_eq_apd10 p _)))
... ≃ Σ(p : k ~ l), respect_pt k = p pt ⬝ respect_pt l
: sigma_equiv_sigma_left' !eq_equiv_homotopy
... ≃ Σ(p : k ~ l), p pt ⬝ respect_pt l = respect_pt k
: sigma_equiv_sigma_right (λp, eq_equiv_eq_symm _ _)
... ≃ (k ~* l) : phomotopy.sigma_char k l
definition ppi_eq_equiv_internal_idp :
ppi_eq_equiv_internal k k idp = phomotopy.refl k :=
begin
apply ap (phomotopy.mk (homotopy.refl _)), induction k with k k₀,
esimp at * ⊢, induction k₀, reflexivity
end
definition ppi_eq_equiv [constructor] : (k = l) ≃ (k ~* l) :=
begin
refine equiv_change_fun (ppi_eq_equiv_internal k l) _,
{ apply phomotopy_of_eq },
{ intro p, induction p, exact ppi_eq_equiv_internal_idp k }
end
variables {k l}
definition pmap_eq_equiv [constructor] (f g : A →* B) : (f = g) ≃ (f ~* g) :=
ppi_eq_equiv f g
definition eq_of_phomotopy (p : k ~* l) : k = l :=
to_inv (ppi_eq_equiv k l) p
definition eq_of_phomotopy_refl (k : ppi P p₀) : eq_of_phomotopy (phomotopy.refl k) = idpath k :=
begin
apply to_inv_eq_of_eq, reflexivity
end
definition phomotopy_of_homotopy (h : k ~ l) [Πa, is_set (P a)] : k ~* l :=
begin
fapply phomotopy.mk,
{ exact h },
{ apply is_set.elim }
end
definition ppi_eq_of_homotopy [Πa, is_set (P a)] (p : k ~ l) : k = l :=
eq_of_phomotopy (phomotopy_of_homotopy p)
definition pmap_eq_of_homotopy [is_set B] (p : f ~ g) : f = g :=
ppi_eq_of_homotopy p
definition phomotopy_of_eq_of_phomotopy (p : k ~* l) : phomotopy_of_eq (eq_of_phomotopy p) = p :=
to_right_inv (ppi_eq_equiv k l) p
definition phomotopy_rec_eq [recursor] {Q : (k ~* k') → Type} (p : k ~* k')
(H : Π(q : k = k'), Q (phomotopy_of_eq q)) : Q p :=
phomotopy_of_eq_of_phomotopy p ▸ H (eq_of_phomotopy p)
definition phomotopy_rec_idp [recursor] {Q : Π {k' : ppi P p₀}, (k ~* k') → Type}
{k' : ppi P p₀} (H : k ~* k') (q : Q (phomotopy.refl k)) : Q H :=
begin
induction H using phomotopy_rec_eq with t,
induction t, exact phomotopy_of_eq_idp k ▸ q,
end
definition phomotopy_rec_idp' (Q : Π ⦃k' : ppi P p₀⦄, (k ~* k') → (k = k') → Type)
(q : Q phomotopy.rfl idp) ⦃k' : ppi P p₀⦄ (H : k ~* k') : Q H (eq_of_phomotopy H) :=
begin
induction H using phomotopy_rec_idp,
exact transport (Q phomotopy.rfl) !eq_of_phomotopy_refl⁻¹ q
end
attribute phomotopy.rec' [recursor]
definition phomotopy_rec_eq_phomotopy_of_eq {Q : (k ~* l) → Type} (p : k = l)
(H : Π(q : k = l), Q (phomotopy_of_eq q)) : phomotopy_rec_eq (phomotopy_of_eq p) H = H p :=
begin
unfold phomotopy_rec_eq,
refine ap (λp, p ▸ _) !adj ⬝ _,
refine !tr_compose⁻¹ ⬝ _,
apply apdt
end
definition phomotopy_rec_idp_refl {Q : Π{l}, (k ~* l) → Type} (H : Q (phomotopy.refl k)) :
phomotopy_rec_idp phomotopy.rfl H = H :=
!phomotopy_rec_eq_phomotopy_of_eq
definition phomotopy_rec_idp'_refl (Q : Π ⦃k' : ppi P p₀⦄, (k ~* k') → (k = k') → Type)
(q : Q phomotopy.rfl idp) :
phomotopy_rec_idp' Q q phomotopy.rfl = transport (Q phomotopy.rfl) !eq_of_phomotopy_refl⁻¹ q :=
!phomotopy_rec_idp_refl
/- maps out of or into contractible types -/
definition phomotopy_of_is_contr_cod [constructor] (k l : ppi P p₀) [Πa, is_contr (P a)] :
k ~* l :=
phomotopy.mk (λa, !eq_of_is_contr) !eq_of_is_contr
definition phomotopy_of_is_contr_cod_pmap [constructor] (f g : A →* B) [is_contr B] : f ~* g :=
phomotopy_of_is_contr_cod f g
definition phomotopy_of_is_contr_dom [constructor] (k l : ppi P p₀) [is_contr A] : k ~* l :=
begin
fapply phomotopy.mk,
{ intro a, exact eq_of_pathover_idp (change_path !is_prop.elim
(apd k !is_prop.elim ⬝op respect_pt k ⬝ (respect_pt l)⁻¹ ⬝o apd l !is_prop.elim)) },
rewrite [▸*, +is_prop_elim_self, +apd_idp, cono_idpo],
refine ap (λx, eq_of_pathover_idp (change_path x _)) !is_prop_elim_self ◾ idp ⬝ _,
xrewrite [change_path_idp, idpo_concato_eq, inv_con_cancel_right],
end
/- adjunction between (-)₊ : Type → Type* and pType.carrier : Type* → Type -/
definition pmap_equiv_left (A : Type) (B : Type*) : A₊ →* B ≃ (A → B) :=
begin
fapply equiv.MK,
{ intro f a, cases f with f p, exact f (some a) },
{ intro f, fconstructor,
intro a, cases a, exact pt, exact f a,
reflexivity },
{ intro f, reflexivity },
{ intro f, cases f with f p, esimp, fapply eq_of_phomotopy, fapply phomotopy.mk,
{ intro a, cases a; all_goals (esimp at *), exact p⁻¹ },
{ esimp, exact !con.left_inv }},
end
-- pmap_pbool_pequiv is the pointed equivalence
definition pmap_pbool_equiv [constructor] (B : Type*) : (pbool →* B) ≃ B :=
begin
fapply equiv.MK,
{ intro f, cases f with f p, exact f tt },
{ intro b, fconstructor,
intro u, cases u, exact pt, exact b,
reflexivity },
{ intro b, reflexivity },
{ intro f, cases f with f p, esimp, fapply eq_of_phomotopy, fapply phomotopy.mk,
{ intro a, cases a; all_goals (esimp at *), exact p⁻¹ },
{ esimp, exact !con.left_inv }},
end
/-
Pointed maps respecting pointed homotopies.
In general we need function extensionality for pap,
but for particular F we can do it without function extensionality.
This might be preferred, because such pointed homotopies compute. On the other hand,
when using function extensionality, it's easier to prove that if p is reflexivity, then the
resulting pointed homotopy is reflexivity
-/
definition pap (F : (A →* B) → (C →* D)) {f g : A →* B} (p : f ~* g) : F f ~* F g :=
begin
induction p using phomotopy_rec_idp, reflexivity
end
definition pap_refl (F : (A →* B) → (C →* D)) (f : A →* B) :
pap F (phomotopy.refl f) = phomotopy.refl (F f) :=
!phomotopy_rec_idp_refl
definition ap1_phomotopy {f g : A →* B} (p : f ~* g) : Ω→ f ~* Ω→ g :=
pap Ω→ p
notation `Ω⇒`:(max+5) := ap1_phomotopy
definition ap1_phomotopy_refl {X Y : Type*} (f : X →* Y) :
ap1_phomotopy (phomotopy.refl f) = phomotopy.refl (Ω→ f) :=
!pap_refl
--a proof not using function extensionality:
definition ap1_phomotopy_explicit {f g : A →* B} (p : f ~* g) : Ω→ f ~* Ω→ g :=
begin
induction p with p q, induction f with f pf, induction g with g pg, induction B with B b,
esimp at * ⊢, induction q, induction pg,
fapply phomotopy.mk,
{ intro l, refine _ ⬝ !idp_con⁻¹ᵖ, refine !con.assoc ⬝ _, apply inv_con_eq_of_eq_con,
apply ap_con_eq_con_ap},
{ induction A with A a, unfold [ap_con_eq_con_ap], generalize p a, generalize g a, intro b q,
induction q, reflexivity}
end
definition apn_phomotopy {f g : A →* B} (n : ℕ) (p : f ~* g) : apn n f ~* apn n g :=
begin
induction n with n IH,
{ exact p},
{ exact ap1_phomotopy IH}
end
-- the following two definitiongs are mostly the same, maybe we should remove one
definition ap_eq_of_phomotopy {A B : Type*} {f g : A →* B} (p : f ~* g) (a : A) :
ap (λf : A →* B, f a) (eq_of_phomotopy p) = p a :=
ap010 to_homotopy (phomotopy_of_eq_of_phomotopy p) a
definition to_fun_eq_of_phomotopy {A B : Type*} {f g : A →* B} (p : f ~* g) (a : A) :
ap010 pmap.to_fun (eq_of_phomotopy p) a = p a :=
begin
induction p using phomotopy_rec_idp,
exact ap (λx, ap010 pmap.to_fun x a) !eq_of_phomotopy_refl
end
definition ap1_eq_of_phomotopy {A B : Type*} {f g : A →* B} (p : f ~* g) :
ap Ω→ (eq_of_phomotopy p) = eq_of_phomotopy (ap1_phomotopy p) :=
begin
induction p using phomotopy_rec_idp,
refine ap02 _ !eq_of_phomotopy_refl ⬝ !eq_of_phomotopy_refl⁻¹ ⬝ ap eq_of_phomotopy _,
exact !ap1_phomotopy_refl⁻¹
end
/- pointed homotopies between the given pointed maps -/
definition ap1_pid [constructor] {A : Type*} : ap1 (pid A) ~* pid (Ω A) :=
begin
fapply phomotopy.mk,
{ intro p, esimp, refine !idp_con ⬝ !ap_id},
{ reflexivity}
end
definition ap1_pinverse [constructor] {A : Type*} : ap1 (pinverse A) ~* pinverse (Ω A) :=
begin
fapply phomotopy.mk,
{ intro p, refine !idp_con ⬝ _, exact !inv_eq_inv2⁻¹ },
{ reflexivity}
end
definition ap1_gen_compose {A B C : Type} (g : B → C) (f : A → B) {a₁ a₂ : A} {b₁ b₂ : B}
{c₁ c₂ : C} (q₁ : f a₁ = b₁) (q₂ : f a₂ = b₂) (r₁ : g b₁ = c₁) (r₂ : g b₂ = c₂) (p : a₁ = a₂) :
ap1_gen (g ∘ f) (ap g q₁ ⬝ r₁) (ap g q₂ ⬝ r₂) p = ap1_gen g r₁ r₂ (ap1_gen f q₁ q₂ p) :=
begin induction p, induction q₁, induction q₂, induction r₁, induction r₂, reflexivity end
definition ap1_gen_compose_idp {A B C : Type} (g : B → C) (f : A → B) {a : A}
{b : B} {c : C} (q : f a = b) (r : g b = c) :
ap1_gen_compose g f q q r r idp ⬝ (ap (ap1_gen g r r) (ap1_gen_idp f q) ⬝ ap1_gen_idp g r) =
ap1_gen_idp (g ∘ f) (ap g q ⬝ r) :=
begin induction q, induction r, reflexivity end
definition ap1_pcompose [constructor] {A B C : Type*} (g : B →* C) (f : A →* B) :
ap1 (g ∘* f) ~* ap1 g ∘* ap1 f :=
phomotopy.mk (ap1_gen_compose g f (respect_pt f) (respect_pt f) (respect_pt g) (respect_pt g))
(ap1_gen_compose_idp g f (respect_pt f) (respect_pt g))
definition ap1_pconst [constructor] (A B : Type*) : Ω→(pconst A B) ~* pconst (Ω A) (Ω B) :=
phomotopy.mk (λp, ap1_gen_idp_left (const A pt) p ⬝ ap_constant p pt) rfl
definition ap1_gen_con_left {A B : Type} {a a' : A} {b₀ b₁ b₂ : B}
{f : A → b₀ = b₁} {f' : A → b₁ = b₂} {q₀ q₁ : b₀ = b₁} {q₀' q₁' : b₁ = b₂}
(r₀ : f a = q₀) (r₁ : f a' = q₁) (r₀' : f' a = q₀') (r₁' : f' a' = q₁') (p : a = a') :
ap1_gen (λa, f a ⬝ f' a) (r₀ ◾ r₀') (r₁ ◾ r₁') p =
whisker_right q₀' (ap1_gen f r₀ r₁ p) ⬝ whisker_left q₁ (ap1_gen f' r₀' r₁' p) :=
begin induction r₀, induction r₁, induction r₀', induction r₁', induction p, reflexivity end
definition ap1_gen_con_left_idp {A B : Type} {a : A} {b₀ b₁ b₂ : B}
{f : A → b₀ = b₁} {f' : A → b₁ = b₂} {q₀ : b₀ = b₁} {q₁ : b₁ = b₂}
(r₀ : f a = q₀) (r₁ : f' a = q₁) :
ap1_gen_con_left r₀ r₀ r₁ r₁ idp =
!con.left_inv ⬝ (ap (whisker_right q₁) !con.left_inv ◾ ap (whisker_left _) !con.left_inv)⁻¹ :=
begin induction r₀, induction r₁, reflexivity end
definition ptransport_change_eq [constructor] {A : Type} (B : A → Type*) {a a' : A} {p q : a = a'}
(r : p = q) : ptransport B p ~* ptransport B q :=
phomotopy.mk (λb, ap (λp, transport B p b) r) begin induction r, apply idp_con end
definition apn_pid [constructor] {A : Type*} (n : ℕ) : apn n (pid A) ~* pid (Ω[n] A) :=
begin
induction n with n IH,
{ reflexivity},
{ exact ap1_phomotopy IH ⬝* ap1_pid}
end
definition apn_pconst (A B : Type*) (n : ℕ) :
apn n (pconst A B) ~* pconst (Ω[n] A) (Ω[n] B) :=
begin
induction n with n IH,
{ reflexivity },
{ exact ap1_phomotopy IH ⬝* !ap1_pconst }
end
definition apn_pcompose (n : ℕ) (g : B →* C) (f : A →* B) :
apn n (g ∘* f) ~* apn n g ∘* apn n f :=
begin
induction n with n IH,
{ reflexivity},
{ refine ap1_phomotopy IH ⬝* _, apply ap1_pcompose}
end
definition pcast_idp [constructor] {A : Type*} : pcast (idpath A) ~* pid A :=
by reflexivity
definition pinverse_pinverse (A : Type*) : pinverse A ∘* pinverse A ~* pid (Ω A) :=
begin
fapply phomotopy.mk,
{ apply inv_inv},
{ reflexivity}
end
definition pcast_ap_loop [constructor] {A B : Type*} (p : A = B) :
pcast (ap Ω p) ~* ap1 (pcast p) :=
begin
fapply phomotopy.mk,
{ intro a, induction p, esimp, exact (!idp_con ⬝ !ap_id)⁻¹},
{ induction p, reflexivity}
end
definition ap1_pmap_of_map [constructor] {A B : Type} (f : A → B) (a : A) :
ap1 (pmap_of_map f a) ~* pmap_of_map (ap f) (idpath a) :=
begin
fapply phomotopy.mk,
{ intro a, esimp, apply idp_con},
{ reflexivity}
end
/- pointed equivalences -/
structure pequiv (A B : Type*) :=
mk' :: (to_pmap : A →* B)
(to_pinv1 : B →* A)
(to_pinv2 : B →* A)
(pright_inv : to_pmap ∘* to_pinv1 ~* pid B)
(pleft_inv : to_pinv2 ∘* to_pmap ~* pid A)
infix ` ≃* `:25 := pequiv
definition pmap_of_pequiv [unfold 3] [coercion] [reducible] {A B : Type*} (f : A ≃* B) :
@ppi A (λa, B) pt :=
pequiv.to_pmap f
definition to_pinv [unfold 3] (f : A ≃* B) : B →* A :=
pequiv.to_pinv1 f
definition pleft_inv' (f : A ≃* B) : to_pinv f ∘* f ~* pid A :=
let g := to_pinv f in
let h := pequiv.to_pinv2 f in
calc g ∘* f ~* pid A ∘* (g ∘* f) : by exact !pid_pcompose⁻¹*
... ~* (h ∘* f) ∘* (g ∘* f) : by exact pwhisker_right _ (pequiv.pleft_inv f)⁻¹*
... ~* h ∘* (f ∘* g) ∘* f : by exact !passoc ⬝* pwhisker_left _ !passoc⁻¹*
... ~* h ∘* pid B ∘* f : by exact !pwhisker_left (!pwhisker_right !pequiv.pright_inv)
... ~* h ∘* f : by exact pwhisker_left _ !pid_pcompose
... ~* pid A : by exact pequiv.pleft_inv f
definition equiv_of_pequiv [coercion] [constructor] (f : A ≃* B) : A ≃ B :=
have is_equiv f, from adjointify f (to_pinv f) (pequiv.pright_inv f) (pleft_inv' f),
equiv.mk f _
attribute pointed._trans_of_equiv_of_pequiv pointed._trans_of_pmap_of_pequiv [unfold 3]
definition pequiv.to_is_equiv [instance] [constructor] (f : A ≃* B) :
is_equiv (pointed._trans_of_equiv_of_pequiv f) :=
adjointify f (to_pinv f) (pequiv.pright_inv f) (pleft_inv' f)
definition pequiv.to_is_equiv' [instance] [constructor] (f : A ≃* B) :
is_equiv (pointed._trans_of_pmap_of_pequiv f) :=
pequiv.to_is_equiv f
protected definition pequiv.MK [constructor] (f : A →* B) (g : B →* A)
(gf : g ∘* f ~* !pid) (fg : f ∘* g ~* !pid) : A ≃* B :=
pequiv.mk' f g g fg gf
definition pinv [constructor] (f : A →* B) (H : is_equiv f) : B →* A :=
pmap.mk f⁻¹ᶠ (ap f⁻¹ᶠ (respect_pt f)⁻¹ ⬝ (left_inv f pt))
definition pequiv_of_pmap [constructor] (f : A →* B) (H : is_equiv f) : A ≃* B :=
pequiv.mk' f (pinv f H) (pinv f H)
abstract begin
fapply phomotopy.mk, exact right_inv f,
induction f with f f₀, induction B with B b₀, esimp at *, induction f₀, esimp,
exact adj f pt ⬝ ap02 f !idp_con⁻¹
end end
abstract begin
fapply phomotopy.mk, exact left_inv f,
induction f with f f₀, induction B with B b₀, esimp at *, induction f₀, esimp,
exact !idp_con⁻¹ ⬝ !idp_con⁻¹
end end
definition pequiv.mk [constructor] (f : A → B) (H : is_equiv f) (p : f pt = pt) : A ≃* B :=
pequiv_of_pmap (pmap.mk f p) H
definition pequiv_of_equiv [constructor] (f : A ≃ B) (H : f pt = pt) : A ≃* B :=
pequiv.mk f _ H
protected definition pequiv.MK' [constructor] (f : A →* B) (g : B → A)
(gf : Πa, g (f a) = a) (fg : Πb, f (g b) = b) : A ≃* B :=
pequiv.mk f (adjointify f g fg gf) (respect_pt f)
/- reflexivity and symmetry (transitivity is below) -/
protected definition pequiv.refl [refl] [constructor] (A : Type*) : A ≃* A :=
pequiv.mk' (pid A) (pid A) (pid A) !pid_pcompose !pcompose_pid
protected definition pequiv.rfl [constructor] : A ≃* A :=
pequiv.refl A
protected definition pequiv.symm [symm] [constructor] (f : A ≃* B) : B ≃* A :=
pequiv.MK (to_pinv f) f (pequiv.pright_inv f) (pleft_inv' f)
postfix `⁻¹ᵉ*`:(max + 1) := pequiv.symm
definition pleft_inv (f : A ≃* B) : f⁻¹ᵉ* ∘* f ~* pid A :=
pleft_inv' f
definition pright_inv (f : A ≃* B) : f ∘* f⁻¹ᵉ* ~* pid B :=
pequiv.pright_inv f
definition to_pmap_pequiv_of_pmap {A B : Type*} (f : A →* B) (H : is_equiv f)
: pequiv.to_pmap (pequiv_of_pmap f H) = f :=
by reflexivity
definition to_pmap_pequiv_MK [constructor] (f : A →* B) (g : B →* A)
(gf : g ∘* f ~* !pid) (fg : f ∘* g ~* !pid) : pequiv.MK f g gf fg ~* f :=
by reflexivity
definition to_pinv_pequiv_MK [constructor] (f : A →* B) (g : B →* A)
(gf : g ∘* f ~* !pid) (fg : f ∘* g ~* !pid) : to_pinv (pequiv.MK f g gf fg) ~* g :=
by reflexivity
/- more on pointed equivalences -/
definition pequiv_ap [constructor] {A : Type} (B : A → Type*) {a a' : A} (p : a = a')
: B a ≃* B a' :=
pequiv_of_pmap (ptransport B p) !is_equiv_tr
definition pequiv_change_fun [constructor] (f : A ≃* B) (f' : A →* B) (Heq : f ~ f') : A ≃* B :=
pequiv_of_pmap f' (is_equiv.homotopy_closed f Heq _)
definition pequiv_change_inv [constructor] (f : A ≃* B) (f' : B →* A) (Heq : to_pinv f ~ f')
: A ≃* B :=
pequiv.MK' f f' (to_left_inv (equiv_change_inv f Heq)) (to_right_inv (equiv_change_inv f Heq))
definition pequiv_rect' (f : A ≃* B) (P : A → B → Type)
(g : Πb, P (f⁻¹ b) b) (a : A) : P a (f a) :=
left_inv f a ▸ g (f a)
definition pua {A B : Type*} (f : A ≃* B) : A = B :=
pType_eq (equiv_of_pequiv f) !respect_pt
definition pequiv_of_eq [constructor] {A B : Type*} (p : A = B) : A ≃* B :=
pequiv_of_pmap (pcast p) !is_equiv_tr
definition eq_of_pequiv {A B : Type*} (p : A ≃* B) : A = B :=
pType_eq (equiv_of_pequiv p) !respect_pt
definition peap {A B : Type*} (F : Type* → Type*) (p : A ≃* B) : F A ≃* F B :=
pequiv_of_pmap (pcast (ap F (eq_of_pequiv p))) begin cases eq_of_pequiv p, apply is_equiv_id end
-- definition pequiv.eta_expand [constructor] {A B : Type*} (f : A ≃* B) : A ≃* B :=
-- pequiv.mk' f (to_pinv f) (pequiv.to_pinv2 f) (pright_inv f) _
/-
the theorem pequiv_eq, which gives a condition for two pointed equivalences are equal
is in types.equiv to avoid circular imports
-/
/- computation rules of pointed homotopies, possibly combined with pointed equivalences -/
definition pcancel_left (f : B ≃* C) {g h : A →* B} (p : f ∘* g ~* f ∘* h) : g ~* h :=
begin
refine _⁻¹* ⬝* pwhisker_left f⁻¹ᵉ* p ⬝* _:
refine !passoc⁻¹* ⬝* _:
refine pwhisker_right _ (pleft_inv f) ⬝* _:
apply pid_pcompose
end
definition pcancel_right (f : A ≃* B) {g h : B →* C} (p : g ∘* f ~* h ∘* f) : g ~* h :=
begin
refine _⁻¹* ⬝* pwhisker_right f⁻¹ᵉ* p ⬝* _:
refine !passoc ⬝* _:
refine pwhisker_left _ (pright_inv f) ⬝* _:
apply pcompose_pid
end
definition phomotopy_pinv_right_of_phomotopy {f : A ≃* B} {g : B →* C} {h : A →* C}
(p : g ∘* f ~* h) : g ~* h ∘* f⁻¹ᵉ* :=
begin
refine _ ⬝* pwhisker_right _ p, symmetry,
refine !passoc ⬝* _,
refine pwhisker_left _ (pright_inv f) ⬝* _,
apply pcompose_pid
end
definition phomotopy_of_pinv_right_phomotopy {f : B ≃* A} {g : B →* C} {h : A →* C}
(p : g ∘* f⁻¹ᵉ* ~* h) : g ~* h ∘* f :=
begin
refine _ ⬝* pwhisker_right _ p, symmetry,
refine !passoc ⬝* _,
refine pwhisker_left _ (pleft_inv f) ⬝* _,
apply pcompose_pid
end
definition pinv_right_phomotopy_of_phomotopy {f : A ≃* B} {g : B →* C} {h : A →* C}
(p : h ~* g ∘* f) : h ∘* f⁻¹ᵉ* ~* g :=
(phomotopy_pinv_right_of_phomotopy p⁻¹*)⁻¹*
definition phomotopy_of_phomotopy_pinv_right {f : B ≃* A} {g : B →* C} {h : A →* C}
(p : h ~* g ∘* f⁻¹ᵉ*) : h ∘* f ~* g :=
(phomotopy_of_pinv_right_phomotopy p⁻¹*)⁻¹*
definition phomotopy_pinv_left_of_phomotopy {f : B ≃* C} {g : A →* B} {h : A →* C}
(p : f ∘* g ~* h) : g ~* f⁻¹ᵉ* ∘* h :=
begin
refine _ ⬝* pwhisker_left _ p, symmetry,
refine !passoc⁻¹* ⬝* _,
refine pwhisker_right _ (pleft_inv f) ⬝* _,
apply pid_pcompose
end
definition phomotopy_of_pinv_left_phomotopy {f : C ≃* B} {g : A →* B} {h : A →* C}
(p : f⁻¹ᵉ* ∘* g ~* h) : g ~* f ∘* h :=
begin
refine _ ⬝* pwhisker_left _ p, symmetry,
refine !passoc⁻¹* ⬝* _,
refine pwhisker_right _ (pright_inv f) ⬝* _,
apply pid_pcompose
end
definition pinv_left_phomotopy_of_phomotopy {f : B ≃* C} {g : A →* B} {h : A →* C}
(p : h ~* f ∘* g) : f⁻¹ᵉ* ∘* h ~* g :=
(phomotopy_pinv_left_of_phomotopy p⁻¹*)⁻¹*
definition phomotopy_of_phomotopy_pinv_left {f : C ≃* B} {g : A →* B} {h : A →* C}
(p : h ~* f⁻¹ᵉ* ∘* g) : f ∘* h ~* g :=
(phomotopy_of_pinv_left_phomotopy p⁻¹*)⁻¹*
definition pcompose2 {A B C : Type*} {g g' : B →* C} {f f' : A →* B} (q : g ~* g') (p : f ~* f') :
g ∘* f ~* g' ∘* f' :=
pwhisker_right f q ⬝* pwhisker_left g' p
infixr ` ◾* `:80 := pcompose2
definition phomotopy_pinv_of_phomotopy_pid {A B : Type*} {f : A →* B} {g : B ≃* A}
(p : g ∘* f ~* pid A) : f ~* g⁻¹ᵉ* :=
phomotopy_pinv_left_of_phomotopy p ⬝* !pcompose_pid
definition phomotopy_pinv_of_phomotopy_pid' {A B : Type*} {f : A →* B} {g : B ≃* A}
(p : f ∘* g ~* pid B) : f ~* g⁻¹ᵉ* :=
phomotopy_pinv_right_of_phomotopy p ⬝* !pid_pcompose
definition pinv_phomotopy_of_pid_phomotopy {A B : Type*} {f : A →* B} {g : B ≃* A}
(p : pid A ~* g ∘* f) : g⁻¹ᵉ* ~* f :=
(phomotopy_pinv_of_phomotopy_pid p⁻¹*)⁻¹*
definition pinv_phomotopy_of_pid_phomotopy' {A B : Type*} {f : A →* B} {g : B ≃* A}
(p : pid B ~* f ∘* g) : g⁻¹ᵉ* ~* f :=
(phomotopy_pinv_of_phomotopy_pid' p⁻¹*)⁻¹*
definition pinv_pcompose_cancel_left {A B C : Type*} (g : B ≃* C) (f : A →* B) :
g⁻¹ᵉ* ∘* (g ∘* f) ~* f :=
!passoc⁻¹* ⬝* pwhisker_right f !pleft_inv ⬝* !pid_pcompose
definition pcompose_pinv_cancel_left {A B C : Type*} (g : C ≃* B) (f : A →* B) :
g ∘* (g⁻¹ᵉ* ∘* f) ~* f :=
!passoc⁻¹* ⬝* pwhisker_right f !pright_inv ⬝* !pid_pcompose
definition pinv_pcompose_cancel_right {A B C : Type*} (g : B →* C) (f : B ≃* A) :
(g ∘* f⁻¹ᵉ*) ∘* f ~* g :=
!passoc ⬝* pwhisker_left g !pleft_inv ⬝* !pcompose_pid
definition pcompose_pinv_cancel_right {A B C : Type*} (g : B →* C) (f : A ≃* B) :
(g ∘* f) ∘* f⁻¹ᵉ* ~* g :=
!passoc ⬝* pwhisker_left g !pright_inv ⬝* !pcompose_pid
definition pinv_pinv {A B : Type*} (f : A ≃* B) : (f⁻¹ᵉ*)⁻¹ᵉ* ~* f :=
(phomotopy_pinv_of_phomotopy_pid (pleft_inv f))⁻¹*
definition pinv2 {A B : Type*} {f f' : A ≃* B} (p : f ~* f') : f⁻¹ᵉ* ~* f'⁻¹ᵉ* :=
phomotopy_pinv_of_phomotopy_pid (pinv_right_phomotopy_of_phomotopy (!pid_pcompose ⬝* p)⁻¹*)
postfix [parsing_only] `⁻²*`:(max+10) := pinv2
protected definition pequiv.trans [trans] [constructor] (f : A ≃* B) (g : B ≃* C) : A ≃* C :=
pequiv.MK (g ∘* f) (f⁻¹ᵉ* ∘* g⁻¹ᵉ*)
abstract !passoc ⬝* pwhisker_left _ (pinv_pcompose_cancel_left g f) ⬝* pleft_inv f end
abstract !passoc ⬝* pwhisker_left _ (pcompose_pinv_cancel_left f g⁻¹ᵉ*) ⬝* pright_inv g end
definition pequiv_compose {A B C : Type*} (g : B ≃* C) (f : A ≃* B) : A ≃* C :=
pequiv.trans f g
infix ` ⬝e* `:75 := pequiv.trans
infixr ` ∘*ᵉ `:60 := pequiv_compose
definition to_pmap_pequiv_trans {A B C : Type*} (f : A ≃* B) (g : B ≃* C)
: pequiv.to_pmap (f ⬝e* g) = g ∘* f :=
by reflexivity
definition to_fun_pequiv_trans {X Y Z : Type*} (f : X ≃* Y) (g :Y ≃* Z) : f ⬝e* g ~ g ∘ f :=
λx, idp
definition peconcat_eq {A B C : Type*} (p : A ≃* B) (q : B = C) : A ≃* C :=
p ⬝e* pequiv_of_eq q
definition eq_peconcat {A B C : Type*} (p : A = B) (q : B ≃* C) : A ≃* C :=
pequiv_of_eq p ⬝e* q
infix ` ⬝e*p `:75 := peconcat_eq
infix ` ⬝pe* `:75 := eq_peconcat
definition trans_pinv {A B C : Type*} (f : A ≃* B) (g : B ≃* C) :
(f ⬝e* g)⁻¹ᵉ* ~* f⁻¹ᵉ* ∘* g⁻¹ᵉ* :=
by reflexivity
definition pinv_trans_pinv_left {A B C : Type*} (f : B ≃* A) (g : B ≃* C) :
(f⁻¹ᵉ* ⬝e* g)⁻¹ᵉ* ~* f ∘* g⁻¹ᵉ* :=
by reflexivity
definition pinv_trans_pinv_right {A B C : Type*} (f : A ≃* B) (g : C ≃* B) :
(f ⬝e* g⁻¹ᵉ*)⁻¹ᵉ* ~* f⁻¹ᵉ* ∘* g :=
by reflexivity
definition pinv_trans_pinv_pinv {A B C : Type*} (f : B ≃* A) (g : C ≃* B) :
(f⁻¹ᵉ* ⬝e* g⁻¹ᵉ*)⁻¹ᵉ* ~* f ∘* g :=
by reflexivity
/- pointed equivalences between particular pointed types -/
definition loopn_pequiv_loopn [constructor] (n : ℕ) (f : A ≃* B) : Ω[n] A ≃* Ω[n] B :=
pequiv.MK (apn n f) (apn n f⁻¹ᵉ*)
abstract begin
induction n with n IH,
{ apply pleft_inv},
{ replace nat.succ n with n + 1,
rewrite [+apn_succ],
refine !ap1_pcompose⁻¹* ⬝* _,
refine ap1_phomotopy IH ⬝* _,
apply ap1_pid}
end end
abstract begin
induction n with n IH,
{ apply pright_inv},
{ replace nat.succ n with n + 1,
rewrite [+apn_succ],
refine !ap1_pcompose⁻¹* ⬝* _,
refine ap1_phomotopy IH ⬝* _,
apply ap1_pid}
end end
definition is_equiv_apn [constructor] (n : ℕ) (f : A →* B) (H : is_equiv f) : is_equiv (apn n f) :=
to_is_equiv (loopn_pequiv_loopn n (pequiv_of_pmap f H))
definition loop_pequiv_loop [constructor] (f : A ≃* B) : Ω A ≃* Ω B :=
loopn_pequiv_loopn 1 f
notation `Ω≃`:(max+5) := loop_pequiv_loop
notation `Ω≃[`:95 n:0 `]`:0 := loopn_pequiv_loopn n
definition loop_pequiv_eq_closed [constructor] {A : Type} {a a' : A} (p : a = a')
: pointed.MK (a = a) idp ≃* pointed.MK (a' = a') idp :=
pequiv_of_equiv (loop_equiv_eq_closed p) (con.left_inv p)
definition to_pmap_loopn_pequiv_loopn [constructor] (n : ℕ) (f : A ≃* B)
: loopn_pequiv_loopn n f ~* apn n f :=
by reflexivity
definition to_pinv_loopn_pequiv_loopn [constructor] (n : ℕ) (f : A ≃* B)
: (loopn_pequiv_loopn n f)⁻¹ᵉ* ~* apn n f⁻¹ᵉ* :=
by reflexivity
definition loopn_pequiv_loopn_con (n : ℕ) (f : A ≃* B) (p q : Ω[n+1] A)
: loopn_pequiv_loopn (n+1) f (p ⬝ q) =
loopn_pequiv_loopn (n+1) f p ⬝ loopn_pequiv_loopn (n+1) f q :=
ap1_con (loopn_pequiv_loopn n f) p q
definition loop_pequiv_loop_con {A B : Type*} (f : A ≃* B) (p q : Ω A)
: loop_pequiv_loop f (p ⬝ q) = loop_pequiv_loop f p ⬝ loop_pequiv_loop f q :=
loopn_pequiv_loopn_con 0 f p q
definition loopn_pequiv_loopn_rfl (n : ℕ) (A : Type*) :
loopn_pequiv_loopn n (pequiv.refl A) ~* pequiv.refl (Ω[n] A) :=
begin
exact !to_pmap_loopn_pequiv_loopn ⬝* apn_pid n,
end
definition loop_pequiv_loop_rfl (A : Type*) :
loop_pequiv_loop (pequiv.refl A) ~* pequiv.refl (Ω A) :=
loopn_pequiv_loopn_rfl 1 A
definition apn_pinv (n : ℕ) {A B : Type*} (f : A ≃* B) :
Ω→[n] f⁻¹ᵉ* ~* (loopn_pequiv_loopn n f)⁻¹ᵉ* :=
by reflexivity
definition pmap_functor [constructor] {A A' B B' : Type*} (f : A' →* A) (g : B →* B') :
ppmap A B →* ppmap A' B' :=
pmap.mk (λh, g ∘* h ∘* f)
abstract begin
fapply eq_of_phomotopy, fapply phomotopy.mk,
{ esimp, intro a, exact respect_pt g},
{ rewrite [▸*, ap_constant], exact !idp_con⁻¹ }
end end
definition pequiv_pinverse (A : Type*) : Ω A ≃* Ω A :=
pequiv_of_pmap (pinverse A) !is_equiv_eq_inverse
definition pequiv_of_eq_pt [constructor] {A : Type} {a a' : A} (p : a = a') :
pointed.MK A a ≃* pointed.MK A a' :=
pequiv_of_pmap (pmap_of_eq_pt p) !is_equiv_id
definition pointed_eta_pequiv [constructor] (A : Type*) : A ≃* pointed.MK A pt :=
pequiv.mk id !is_equiv_id idp
definition pbool_pequiv_add_point_unit [constructor] : pbool ≃* unit₊ :=
pequiv_of_equiv (bool_equiv_option_unit) idp
/- every pointed map is homotopic to one of the form `pmap_of_map _ _`, up to some
pointed equivalences -/
definition phomotopy_pmap_of_map {A B : Type*} (f : A →* B) :
(pointed_eta_pequiv B ⬝e* (pequiv_of_eq_pt (respect_pt f))⁻¹ᵉ*) ∘* f ∘*
(pointed_eta_pequiv A)⁻¹ᵉ* ~* pmap_of_map f pt :=
begin
fapply phomotopy.mk,
{ reflexivity},
{ symmetry, exact (!ap_id ⬝ !idp_con) ◾ (!idp_con ⬝ !ap_id) ⬝ !con.right_inv }
end
/- properties of iterated loop space -/
definition loopn_succ_in (n : ℕ) (A : Type*) : Ω[succ n] A ≃* Ω[n] (Ω A) :=
begin
induction n with n IH,
{ reflexivity},
{ exact loop_pequiv_loop IH}
end
definition loopn_add (n m : ℕ) (A : Type*) : Ω[n] (Ω[m] A) ≃* Ω[m+n] (A) :=
begin
induction n with n IH,
{ reflexivity},
{ exact loop_pequiv_loop IH}
end
definition loopn_succ_out (n : ℕ) (A : Type*) : Ω[succ n] A ≃* Ω(Ω[n] A) :=
by reflexivity
definition loopn_succ_in_con {n : ℕ} (p q : Ω[succ (succ n)] A) :
loopn_succ_in (succ n) A (p ⬝ q) =
loopn_succ_in (succ n) A p ⬝ loopn_succ_in (succ n) A q :=
!loop_pequiv_loop_con
definition loopn_loop_irrel (p : point A = point A) : Ω(pointed.Mk p) = Ω[2] A :=
begin
intros, fapply pType_eq,
{ esimp, transitivity _,
apply eq_equiv_fn_eq (equiv_eq_closed_right _ p⁻¹),
esimp, apply eq_equiv_eq_closed, apply con.right_inv, apply con.right_inv},
{ esimp, apply con.left_inv}
end
definition loopn_space_loop_irrel (n : ℕ) (p : point A = point A)
: Ω[succ n](pointed.Mk p) = Ω[succ (succ n)] A :> pType :=
calc
Ω[succ n](pointed.Mk p) = Ω[n](Ω (pointed.Mk p)) : eq_of_pequiv !loopn_succ_in
... = Ω[n] (Ω[2] A) : loopn_loop_irrel
... = Ω[2+n] A : eq_of_pequiv !loopn_add
... = Ω[n+2] A : by rewrite [nat.add_comm]
section psquare
/-
Squares of pointed maps
We treat expressions of the form
psquare f g h k :≡ k ∘* f ~* g ∘* h
as squares, where f is the top, g is the bottom, h is the left face and k is the right face.
These squares are very useful for naturality squares
-/
variables {A' A₀₀ A₂₀ A₄₀ A₀₂ A₂₂ A₄₂ A₀₄ A₂₄ A₄₄ : Type*}
{f₁₀ f₁₀' : A₀₀ →* A₂₀} {f₃₀ : A₂₀ →* A₄₀}
{f₁₂ f₁₂' : A₀₂ →* A₂₂} {f₃₂ : A₂₂ →* A₄₂}
{f₁₄ : A₀₄ →* A₂₄} {f₃₄ : A₂₄ →* A₄₄}
{f₀₁ f₀₁' : A₀₀ →* A₀₂} {f₂₁ f₂₁' : A₂₀ →* A₂₂} {f₄₁ : A₄₀ →* A₄₂}
{f₀₃ : A₀₂ →* A₀₄} {f₂₃ : A₂₂ →* A₂₄} {f₄₃ : A₄₂ →* A₄₄}
definition psquare [reducible] (f₁₀ : A₀₀ →* A₂₀) (f₁₂ : A₀₂ →* A₂₂)
(f₀₁ : A₀₀ →* A₀₂) (f₂₁ : A₂₀ →* A₂₂) : Type :=
f₂₁ ∘* f₁₀ ~* f₁₂ ∘* f₀₁
definition psquare_of_phomotopy (p : f₂₁ ∘* f₁₀ ~* f₁₂ ∘* f₀₁) : psquare f₁₀ f₁₂ f₀₁ f₂₁ :=
p
definition phomotopy_of_psquare (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) : f₂₁ ∘* f₁₀ ~* f₁₂ ∘* f₀₁ :=
p
definition hsquare_of_psquare (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) : hsquare f₁₀ f₁₂ f₀₁ f₂₁ :=
to_homotopy p
definition phdeg_square {f f' : A →* A'} (p : f ~* f') : psquare !pid !pid f f' :=
!pcompose_pid ⬝* p⁻¹* ⬝* !pid_pcompose⁻¹*
definition pvdeg_square {f f' : A →* A'} (p : f ~* f') : psquare f f' !pid !pid :=
!pid_pcompose ⬝* p ⬝* !pcompose_pid⁻¹*
variables (f₁₀ f₁₂ f₀₁ f₂₁)
definition phconst_square : psquare !pconst !pconst f₀₁ f₂₁ :=
!pcompose_pconst ⬝* !pconst_pcompose⁻¹*
definition pvconst_square : psquare f₁₀ f₁₂ !pconst !pconst :=
!pconst_pcompose ⬝* !pcompose_pconst⁻¹*
definition phrefl : psquare !pid !pid f₀₁ f₀₁ := phdeg_square phomotopy.rfl
definition pvrefl : psquare f₁₀ f₁₀ !pid !pid := pvdeg_square phomotopy.rfl
variables {f₁₀ f₁₂ f₀₁ f₂₁}
definition phrfl : psquare !pid !pid f₀₁ f₀₁ := phrefl f₀₁
definition pvrfl : psquare f₁₀ f₁₀ !pid !pid := pvrefl f₁₀
definition ptranspose (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) : psquare f₀₁ f₂₁ f₁₀ f₁₂ :=
p⁻¹*
definition phconcat (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) (q : psquare f₃₀ f₃₂ f₂₁ f₄₁) :
psquare (f₃₀ ∘* f₁₀) (f₃₂ ∘* f₁₂) f₀₁ f₄₁ :=
!passoc⁻¹* ⬝* pwhisker_right f₁₀ q ⬝* !passoc ⬝* pwhisker_left f₃₂ p ⬝* !passoc⁻¹*
definition pvconcat (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) (q : psquare f₁₂ f₁₄ f₀₃ f₂₃) :
psquare f₁₀ f₁₄ (f₀₃ ∘* f₀₁) (f₂₃ ∘* f₂₁) :=
!passoc ⬝* pwhisker_left _ p ⬝* !passoc⁻¹* ⬝* pwhisker_right _ q ⬝* !passoc
definition phinverse {f₁₀ : A₀₀ ≃* A₂₀} {f₁₂ : A₀₂ ≃* A₂₂} (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare f₁₀⁻¹ᵉ* f₁₂⁻¹ᵉ* f₂₁ f₀₁ :=
!pid_pcompose⁻¹* ⬝* pwhisker_right _ (pleft_inv f₁₂)⁻¹* ⬝* !passoc ⬝*
pwhisker_left _
(!passoc⁻¹* ⬝* pwhisker_right _ p⁻¹* ⬝* !passoc ⬝* pwhisker_left _ !pright_inv ⬝* !pcompose_pid)
definition pvinverse {f₀₁ : A₀₀ ≃* A₀₂} {f₂₁ : A₂₀ ≃* A₂₂} (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare f₁₂ f₁₀ f₀₁⁻¹ᵉ* f₂₁⁻¹ᵉ* :=
(phinverse p⁻¹*)⁻¹*
definition phomotopy_hconcat (q : f₀₁' ~* f₀₁) (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare f₁₀ f₁₂ f₀₁' f₂₁ :=
p ⬝* pwhisker_left f₁₂ q⁻¹*
definition hconcat_phomotopy (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) (q : f₂₁' ~* f₂₁) :
psquare f₁₀ f₁₂ f₀₁ f₂₁' :=
pwhisker_right f₁₀ q ⬝* p
definition phomotopy_vconcat (q : f₁₀' ~* f₁₀) (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare f₁₀' f₁₂ f₀₁ f₂₁ :=
pwhisker_left f₂₁ q ⬝* p
definition vconcat_phomotopy (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) (q : f₁₂' ~* f₁₂) :
psquare f₁₀ f₁₂' f₀₁ f₂₁ :=
p ⬝* pwhisker_right f₀₁ q⁻¹*
infix ` ⬝h* `:73 := phconcat
infix ` ⬝v* `:73 := pvconcat
infixl ` ⬝hp* `:72 := hconcat_phomotopy
infixr ` ⬝ph* `:72 := phomotopy_hconcat
infixl ` ⬝vp* `:72 := vconcat_phomotopy
infixr ` ⬝pv* `:72 := phomotopy_vconcat
postfix `⁻¹ʰ*`:(max+1) := phinverse
postfix `⁻¹ᵛ*`:(max+1) := pvinverse
definition pwhisker_tl (f : A →* A₀₀) (q : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare (f₁₀ ∘* f) f₁₂ (f₀₁ ∘* f) f₂₁ :=
!passoc⁻¹* ⬝* pwhisker_right f q ⬝* !passoc
definition ap1_psquare (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare (Ω→ f₁₀) (Ω→ f₁₂) (Ω→ f₀₁) (Ω→ f₂₁) :=
!ap1_pcompose⁻¹* ⬝* ap1_phomotopy p ⬝* !ap1_pcompose
definition apn_psquare (n : ℕ) (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare (Ω→[n] f₁₀) (Ω→[n] f₁₂) (Ω→[n] f₀₁) (Ω→[n] f₂₁) :=
!apn_pcompose⁻¹* ⬝* apn_phomotopy n p ⬝* !apn_pcompose
end psquare
definition pinverse_natural [constructor] {X Y : Type*} (f : X →* Y) :
psquare (pinverse X) (pinverse Y) (Ω→ f) (Ω→ f) :=
phomotopy.mk (ap1_gen_inv f (respect_pt f) (respect_pt f))
abstract begin
induction Y with Y y₀, induction f with f f₀, esimp at * ⊢, induction f₀, reflexivity
end end
definition pcast_natural [constructor] {A : Type} {B C : A → Type*} (f : Πa, B a →* C a)
{a₁ a₂ : A} (p : a₁ = a₂) : psquare (pcast (ap B p)) (pcast (ap C p)) (f a₁) (f a₂) :=
phomotopy.mk
begin induction p, reflexivity end
begin induction p, exact whisker_left idp !ap_id end
definition pequiv_of_eq_natural [constructor] {A : Type} {B C : A → Type*} (f : Πa, B a →* C a)
{a₁ a₂ : A} (p : a₁ = a₂) :
psquare (pequiv_of_eq (ap B p)) (pequiv_of_eq (ap C p)) (f a₁) (f a₂) :=
pcast_natural f p
definition loopn_succ_in_natural {A B : Type*} (n : ℕ) (f : A →* B) :
psquare (loopn_succ_in n A) (loopn_succ_in n B) (Ω→[n+1] f) (Ω→[n] (Ω→ f)) :=
begin
induction n with n IH,
{ exact phomotopy.rfl },
{ exact ap1_psquare IH }
end
definition loopn_succ_in_inv_natural {A B : Type*} (n : ℕ) (f : A →* B) :
psquare (loopn_succ_in n A)⁻¹ᵉ* (loopn_succ_in n B)⁻¹ᵉ* (Ω→[n] (Ω→ f)) (Ω→[n + 1] f) :=
(loopn_succ_in_natural n f)⁻¹ʰ*
definition pnatural_square {A B : Type} (X : B → Type*) {f g : A → B}
(h : Πa, X (f a) →* X (g a)) {a a' : A} (p : a = a') :
psquare (ptransport X (ap f p)) (ptransport X (ap g p)) (h a) (h a') :=
by induction p; exact !pcompose_pid ⬝* !pid_pcompose⁻¹*
end pointed
|
59e33f464fcaf03159164a0972882ae8c06ebdb2 | 0533ebfa09b11cf8a29da118dd1b86b94949511e | /src/exponential.lean | 5950b2c0bcd7ab74b6996160db91dbaf8cb97e92 | [
"MIT"
] | permissive | wudcscheme/Lean-RH | 89e9055aac68703876e750c23fb5327979a09822 | 870f78cc7c0715d03466d1211b0f032b425ec984 | refs/heads/main | 1,679,188,429,923 | 1,602,701,790,000 | 1,602,701,790,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,071 | lean | /- ------------------------------------------------------------------------- -|
| @project: riemann_hypothesis |
| @file: exponential.lean |
| @author: Brandon H. Gomes and Alex Kontorovich |
| @affil: Rutgers University |
|- ------------------------------------------------------------------------- -/
import .basic
/-!
-/
namespace riemann_hypothesis --——————————————————————————————————————————————————————————--
variables (α : Type*) (β : Type*)
variables [has_lt α] [has_zero α] [has_one α] [has_mul α] [has_inv α]
[has_lt β] [has_zero β] [has_add β] [has_sub β]
/--
-/
structure ExpLog
:= (exp : β → α)
(exp_homomorphism_zero : exp 0 = 1)
(exp_homomorphism : Π (x y), exp (x + y) = exp x * exp y)
(exp_homomorphism_inv : Π (x y), exp (x - y) = exp x * (exp y)⁻¹)
(exp_injective : Π {x y}, exp x = exp y → x = y)
(exp_monotonic : Π {x y}, x < y → exp x < exp y)
(exp_monotonic_reverse : Π {x y}, exp x < exp y → x < y)
(exp_positive : Π b, 0 < exp b)
(log : Π a : α, 0 < a → β)
(log_domain_irrel : Π x xpos y ypos, x = y → log x xpos = log y ypos)
(log_inverted : Π a apos, exp (log a apos) = a)
namespace ExpLog --——————————————————————————————————————————————————————————————————————--
variables {α β}
open algebra
/--
-/
def log_homomorphism_zero
[has_zero_lt_one α]
(ℯ : ExpLog α β)
: ℯ.log 1 has_zero_lt_one.lt = 0 :=
begin
refine ℯ.exp_injective _,
rw exp_homomorphism_zero,
rw ℯ.log_inverted _ has_zero_lt_one.lt,
end
/--
-/
def log_homomorphism
[has_mul_pos α]
(ℯ : ExpLog α β)
{x y}
(xpos ypos)
: ℯ.log (x * y) (has_mul_pos.lt xpos ypos)
= ℯ.log x xpos + ℯ.log y ypos :=
begin
refine ℯ.exp_injective _,
rw exp_homomorphism,
rw [ℯ.log_inverted, ℯ.log_inverted, ℯ.log_inverted],
end
/--
-/
def log_homomorphism_inv
[has_mul_pos α]
[has_inv_pos α]
(ℯ : ExpLog α β)
{x y}
(xpos ypos)
: ℯ.log (x * y⁻¹) (has_mul_pos.lt xpos (has_inv_pos.lt ypos))
= ℯ.log x xpos - ℯ.log y ypos :=
begin
refine ℯ.exp_injective _,
rw exp_homomorphism_inv,
rw [ℯ.log_inverted, ℯ.log_inverted, ℯ.log_inverted],
end
/--
-/
def log_monotonic
(ℯ : ExpLog α β)
{x y}
(xpos ypos)
: x < y → ℯ.log x xpos < ℯ.log y ypos :=
begin
intros x_lt_y,
rw [← ℯ.log_inverted _ xpos, ← ℯ.log_inverted _ ypos] at x_lt_y,
refine exp_monotonic_reverse _ x_lt_y,
end
/--
-/
def log_monotonic_reverse
(ℯ : ExpLog α β)
{x y}
(xpos ypos)
: ℯ.log x xpos < ℯ.log y ypos → x < y :=
begin
intros logx_lt_logy,
rw [← ℯ.log_inverted _ xpos, ← ℯ.log_inverted _ ypos],
refine exp_monotonic _ logx_lt_logy,
end
/--
-/
def log_lt_one_is_lt_zero
[has_zero_lt_one α]
(ℯ : ExpLog α β)
{a}
(apos)
: a < 1 → ℯ.log a apos < 0 :=
begin
intros a_lt_1,
rw ← ℯ.log_homomorphism_zero,
refine ℯ.log_monotonic _ _ a_lt_1,
end
/--
-/
def log_gt_one_is_gt_zero
[has_zero_lt_one α]
(ℯ : ExpLog α β)
{a}
(apos)
: a > 1 → ℯ.log a apos > 0 :=
begin
intros a_gt_1,
rw ← ℯ.log_homomorphism_zero,
refine ℯ.log_monotonic _ _ a_gt_1,
end
/--
-/
def exp_lt_zero_is_lt_one
(ℯ : ExpLog α β)
{b}
: b < 0 → ℯ.exp b < 1 :=
begin
intros b_lt_0,
rw ← ℯ.exp_homomorphism_zero,
refine ℯ.exp_monotonic b_lt_0,
end
/--
-/
def exp_gt_zero_is_gt_one
(ℯ : ExpLog α β)
{x}
: x > 0 → ℯ.exp x > 1 :=
begin
intros b_gt_0,
rw ← ℯ.exp_homomorphism_zero,
refine ℯ.exp_monotonic b_gt_0,
end
--———————————————————————————————————————————————————————————————————————————————————————--
variables [has_mul β]
/--
-/
def pow
(ℯ : ExpLog α β)
(a apos)
(b)
:= ℯ.exp (ℯ.log a apos * b)
/--
-/
def pow_domain_irrel
(ℯ : ExpLog α β)
(x xpos)
(y ypos)
(b)
: x = y → ℯ.pow x xpos b = ℯ.pow y ypos b :=
begin
intros x_eq_y,
rw [pow, pow],
rw log_domain_irrel _ _ _ _ _ x_eq_y,
end
/--
-/
def pow_homomorphism_zero
[has_mul_zero_is_zero β]
(ℯ : ExpLog α β)
(a apos)
: ℯ.pow a apos 0 = 1 :=
begin
rw pow,
rw has_mul_zero_is_zero.eq,
rw exp_homomorphism_zero,
end
/--
-/
def pow_homomorphism
[has_left_add_distributivity β]
(ℯ : ExpLog α β)
(a apos x y)
: ℯ.pow a apos (x + y) = ℯ.pow a apos x * ℯ.pow a apos y :=
begin
rw pow,
rw has_left_add_distributivity.eq,
rw exp_homomorphism,
rw [← pow, ← pow],
end
/--
-/
def pow_homomorphism_mul
[has_mul_pos α]
[has_right_add_distributivity β]
(ℯ : ExpLog α β)
(x xpos y ypos b)
: ℯ.pow (x * y) (has_mul_pos.lt xpos ypos) b = ℯ.pow x xpos b * ℯ.pow y ypos b :=
begin
rw pow,
rw log_homomorphism,
rw has_right_add_distributivity.eq,
rw exp_homomorphism,
rw [← pow, ← pow],
end
/--
-/
def pow_homomorphism_inv
[has_left_sub_distributivity β]
(ℯ : ExpLog α β)
(a apos x y)
: ℯ.pow a apos (x - y) = ℯ.pow a apos x * (ℯ.pow a apos y)⁻¹ :=
begin
rw pow,
rw has_left_sub_distributivity.eq,
rw exp_homomorphism_inv,
rw [← pow, ← pow],
end
/--
-/
def pow_id_at_one
[has_one β]
[has_right_unit β]
(ℯ : ExpLog α β)
(a apos)
: ℯ.pow a apos 1 = a :=
begin
rw pow,
rw has_right_unit.eq,
rw log_inverted,
end
/--
-/
def pow_homomorphism_one
[has_zero_lt_one α]
[has_zero_mul_is_zero β]
(ℯ : ExpLog α β)
(b)
: ℯ.pow 1 has_zero_lt_one.lt b = 1 :=
begin
rw pow,
rw log_homomorphism_zero,
rw has_zero_mul_is_zero.eq,
rw exp_homomorphism_zero,
end
/--
-/
def pow_positivity
(ℯ : ExpLog α β)
(a apos b)
: 0 < ℯ.pow a apos b
:= exp_positive _ _
/--
-/
def pow_neg_exponent_inverts
[has_one β]
[has_left_sub_distributivity β]
[has_mul_zero_is_zero β]
[has_left_unit α]
(ℯ : ExpLog α β)
(a apos b)
: ℯ.pow a apos (0 - b) = (ℯ.pow a apos b)⁻¹ :=
begin
rw pow_homomorphism_inv,
rw pow_homomorphism_zero,
rw has_left_unit.eq,
end
/--
-/
def pow_homomorphism_inv_from_neg
[has_one β]
[has_neg β]
[has_zero_sub_is_neg β]
[has_left_sub_distributivity β]
[has_mul_zero_is_zero β]
[has_left_unit α]
(ℯ : ExpLog α β)
(a apos x y)
: ℯ.pow a apos x * ℯ.pow a apos (-y) = ℯ.pow a apos (x - y) :=
begin
rw ← has_zero_sub_is_neg.eq,
rw pow_neg_exponent_inverts,
rw ← pow_homomorphism_inv,
end
/--
-/
def pow_succ_reduce
[has_lift_t nat β]
[has_one β]
[has_right_unit β]
[has_left_add_distributivity β]
[has_lift_add_comm nat β]
[has_lift_one_same nat β]
(ℯ : ExpLog α β)
(a apos)
(n : nat)
: ℯ.pow a apos ↑n.succ = ℯ.pow a apos ↑n * a :=
begin
rw ← nat.add_one,
rw has_lift_add_comm.eq,
rw pow_homomorphism,
rw has_lift_one_same.eq,
rw pow_id_at_one,
end
/--
-/
def pow_monotonic
[has_lt_pos_mul_preserves_right β]
(ℯ : ExpLog α β)
{x y}
(xpos ypos)
{b}
(bpos)
: x < y → ℯ.pow x xpos b < ℯ.pow y ypos b :=
begin
intros x_lt_y,
refine exp_monotonic _
(has_lt_pos_mul_preserves_right.lt bpos (log_monotonic _ _ _ x_lt_y)),
end
/--
-/
def nat_pow
[has_lift_t nat β]
(ℯ : ExpLog α β)
(a apos)
(n : nat)
:= ℯ.pow a apos ↑n
/--
-/
def nat_pow_to_nat_power
[has_one β]
[has_right_unit β]
[has_mul_zero_is_zero β]
[has_left_add_distributivity β]
[has_lift_t nat β]
[has_lift_zero_same nat β]
[has_lift_one_same nat β]
[has_lift_add_comm nat β]
(ℯ : ExpLog α β)
(a : α) (apos : 0 < a)
: nat.power a = ℯ.nat_pow a apos :=
begin
refine funext _,
intros n,
induction n with n hn,
rw nat.power,
rw nat_pow,
rw has_lift_zero_same.eq,
rw pow_homomorphism_zero,
rw nat.power,
rw nat.succ_eq_add_one,
rw nat_pow,
rw has_lift_add_comm.eq,
rw pow_homomorphism,
rw has_lift_one_same.eq,
rw pow_id_at_one,
rw hn,
rw nat_pow,
end
end ExpLog --————————————————————————————————————————————————————————————————————————————--
end riemann_hypothesis --————————————————————————————————————————————————————————————————--
|
dae56758802618e8261c58c67a7322512d278dab | 1abd1ed12aa68b375cdef28959f39531c6e95b84 | /src/algebra/big_operators/basic.lean | a3580a9e94ed7b839ee17a29010e7c0b77ede0eb | [
"Apache-2.0"
] | permissive | jumpy4/mathlib | d3829e75173012833e9f15ac16e481e17596de0f | af36f1a35f279f0e5b3c2a77647c6bf2cfd51a13 | refs/heads/master | 1,693,508,842,818 | 1,636,203,271,000 | 1,636,203,271,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 62,703 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import algebra.group.pi
import data.equiv.mul_add
import data.finset.fold
import data.fintype.basic
import data.set.pairwise
/-!
# Big operators
In this file we define products and sums indexed by finite sets (specifically, `finset`).
## Notation
We introduce the following notation, localized in `big_operators`.
To enable the notation, use `open_locale big_operators`.
Let `s` be a `finset α`, and `f : α → β` a function.
* `∏ x in s, f x` is notation for `finset.prod s f` (assuming `β` is a `comm_monoid`)
* `∑ x in s, f x` is notation for `finset.sum s f` (assuming `β` is an `add_comm_monoid`)
* `∏ x, f x` is notation for `finset.prod finset.univ f`
(assuming `α` is a `fintype` and `β` is a `comm_monoid`)
* `∑ x, f x` is notation for `finset.sum finset.univ f`
(assuming `α` is a `fintype` and `β` is an `add_comm_monoid`)
## Implementation Notes
The first arguments in all definitions and lemmas is the codomain of the function of the big
operator. This is necessary for the heuristic in `@[to_additive]`.
See the documentation of `to_additive.attr` for more information.
-/
universes u v w
variables {β : Type u} {α : Type v} {γ : Type w}
namespace finset
/--
`∏ x in s, f x` is the product of `f x`
as `x` ranges over the elements of the finite set `s`.
-/
@[to_additive "`∑ x in s, f` is the sum of `f x` as `x` ranges over the elements
of the finite set `s`."]
protected def prod [comm_monoid β] (s : finset α) (f : α → β) : β := (s.1.map f).prod
@[simp, to_additive] lemma prod_mk [comm_monoid β] (s : multiset α) (hs : s.nodup) (f : α → β) :
(⟨s, hs⟩ : finset α).prod f = (s.map f).prod :=
rfl
end finset
/--
There is no established mathematical convention
for the operator precedence of big operators like `∏` and `∑`.
We will have to make a choice.
Online discussions, such as https://math.stackexchange.com/q/185538/30839
seem to suggest that `∏` and `∑` should have the same precedence,
and that this should be somewhere between `*` and `+`.
The latter have precedence levels `70` and `65` respectively,
and we therefore choose the level `67`.
In practice, this means that parentheses should be placed as follows:
```lean
∑ k in K, (a k + b k) = ∑ k in K, a k + ∑ k in K, b k →
∏ k in K, a k * b k = (∏ k in K, a k) * (∏ k in K, b k)
```
(Example taken from page 490 of Knuth's *Concrete Mathematics*.)
-/
library_note "operator precedence of big operators"
localized "notation `∑` binders `, ` r:(scoped:67 f, finset.sum finset.univ f) := r"
in big_operators
localized "notation `∏` binders `, ` r:(scoped:67 f, finset.prod finset.univ f) := r"
in big_operators
localized "notation `∑` binders ` in ` s `, ` r:(scoped:67 f, finset.sum s f) := r"
in big_operators
localized "notation `∏` binders ` in ` s `, ` r:(scoped:67 f, finset.prod s f) := r"
in big_operators
open_locale big_operators
namespace finset
variables {s s₁ s₂ : finset α} {a : α} {f g : α → β}
@[to_additive] lemma prod_eq_multiset_prod [comm_monoid β] (s : finset α) (f : α → β) :
∏ x in s, f x = (s.1.map f).prod := rfl
@[to_additive]
theorem prod_eq_fold [comm_monoid β] (s : finset α) (f : α → β) :
∏ x in s, f x = s.fold (*) 1 f :=
rfl
@[simp] lemma sum_multiset_singleton (s : finset α) :
s.sum (λ x, {x}) = s.val :=
by simp only [sum_eq_multiset_sum, multiset.sum_map_singleton]
end finset
@[to_additive]
lemma monoid_hom.map_prod [comm_monoid β] [comm_monoid γ] (g : β →* γ) (f : α → β) (s : finset α) :
g (∏ x in s, f x) = ∏ x in s, g (f x) :=
by simp only [finset.prod_eq_multiset_prod, g.map_multiset_prod, multiset.map_map]
@[to_additive]
lemma mul_equiv.map_prod [comm_monoid β] [comm_monoid γ] (g : β ≃* γ) (f : α → β) (s : finset α) :
g (∏ x in s, f x) = ∏ x in s, g (f x) :=
g.to_monoid_hom.map_prod f s
lemma ring_hom.map_list_prod [semiring β] [semiring γ] (f : β →+* γ) (l : list β) :
f l.prod = (l.map f).prod :=
f.to_monoid_hom.map_list_prod l
lemma ring_hom.map_list_sum [non_assoc_semiring β] [non_assoc_semiring γ]
(f : β →+* γ) (l : list β) :
f l.sum = (l.map f).sum :=
f.to_add_monoid_hom.map_list_sum l
/-- A morphism into the opposite ring acts on the product by acting on the reversed elements -/
lemma ring_hom.unop_map_list_prod [semiring β] [semiring γ] (f : β →+* γᵒᵖ) (l : list β) :
opposite.unop (f l.prod) = (l.map (opposite.unop ∘ f)).reverse.prod :=
f.to_monoid_hom.unop_map_list_prod l
lemma ring_hom.map_multiset_prod [comm_semiring β] [comm_semiring γ] (f : β →+* γ)
(s : multiset β) :
f s.prod = (s.map f).prod :=
f.to_monoid_hom.map_multiset_prod s
lemma ring_hom.map_multiset_sum [non_assoc_semiring β] [non_assoc_semiring γ]
(f : β →+* γ) (s : multiset β) :
f s.sum = (s.map f).sum :=
f.to_add_monoid_hom.map_multiset_sum s
lemma ring_hom.map_prod [comm_semiring β] [comm_semiring γ] (g : β →+* γ) (f : α → β)
(s : finset α) :
g (∏ x in s, f x) = ∏ x in s, g (f x) :=
g.to_monoid_hom.map_prod f s
lemma ring_hom.map_sum [non_assoc_semiring β] [non_assoc_semiring γ]
(g : β →+* γ) (f : α → β) (s : finset α) :
g (∑ x in s, f x) = ∑ x in s, g (f x) :=
g.to_add_monoid_hom.map_sum f s
@[to_additive]
lemma monoid_hom.coe_prod [mul_one_class β] [comm_monoid γ] (f : α → β →* γ) (s : finset α) :
⇑(∏ x in s, f x) = ∏ x in s, f x :=
(monoid_hom.coe_fn β γ).map_prod _ _
-- See also `finset.prod_apply`, with the same conclusion
-- but with the weaker hypothesis `f : α → β → γ`.
@[simp, to_additive]
lemma monoid_hom.finset_prod_apply [mul_one_class β] [comm_monoid γ] (f : α → β →* γ)
(s : finset α) (b : β) : (∏ x in s, f x) b = ∏ x in s, f x b :=
(monoid_hom.eval b).map_prod _ _
variables {s s₁ s₂ : finset α} {a : α} {f g : α → β}
namespace finset
section comm_monoid
variables [comm_monoid β]
@[simp, to_additive]
lemma prod_empty {f : α → β} : (∏ x in (∅:finset α), f x) = 1 := rfl
@[simp, to_additive]
lemma prod_cons (h : a ∉ s) : (∏ x in (cons a s h), f x) = f a * ∏ x in s, f x :=
fold_cons h
@[simp, to_additive]
lemma prod_insert [decidable_eq α] : a ∉ s → (∏ x in (insert a s), f x) = f a * ∏ x in s, f x :=
fold_insert
/--
The product of `f` over `insert a s` is the same as
the product over `s`, as long as `a` is in `s` or `f a = 1`.
-/
@[simp, to_additive "The sum of `f` over `insert a s` is the same as
the sum over `s`, as long as `a` is in `s` or `f a = 0`."]
lemma prod_insert_of_eq_one_if_not_mem [decidable_eq α] (h : a ∉ s → f a = 1) :
∏ x in insert a s, f x = ∏ x in s, f x :=
begin
by_cases hm : a ∈ s,
{ simp_rw insert_eq_of_mem hm },
{ rw [prod_insert hm, h hm, one_mul] },
end
/--
The product of `f` over `insert a s` is the same as the product over `s`, as long as `f a = 1`.
-/
@[simp, to_additive "The sum of `f` over `insert a s` is the same as
the sum over `s`, as long as `f a = 0`."]
lemma prod_insert_one [decidable_eq α] (h : f a = 1) :
∏ x in insert a s, f x = ∏ x in s, f x :=
prod_insert_of_eq_one_if_not_mem (λ _, h)
@[simp, to_additive]
lemma prod_singleton : (∏ x in (singleton a), f x) = f a :=
eq.trans fold_singleton $ mul_one _
@[to_additive]
lemma prod_pair [decidable_eq α] {a b : α} (h : a ≠ b) :
(∏ x in ({a, b} : finset α), f x) = f a * f b :=
by rw [prod_insert (not_mem_singleton.2 h), prod_singleton]
@[simp, priority 1100, to_additive]
lemma prod_const_one : (∏ x in s, (1 : β)) = 1 :=
by simp only [finset.prod, multiset.map_const, multiset.prod_repeat, one_pow]
@[simp, to_additive]
lemma prod_image [decidable_eq α] {s : finset γ} {g : γ → α} :
(∀ x ∈ s, ∀ y ∈ s, g x = g y → x = y) → (∏ x in (s.image g), f x) = ∏ x in s, f (g x) :=
fold_image
@[simp, to_additive]
lemma prod_map (s : finset α) (e : α ↪ γ) (f : γ → β) :
(∏ x in (s.map e), f x) = ∏ x in s, f (e x) :=
by rw [finset.prod, finset.map_val, multiset.map_map]; refl
@[congr, to_additive]
lemma prod_congr (h : s₁ = s₂) : (∀ x ∈ s₂, f x = g x) → s₁.prod f = s₂.prod g :=
by rw [h]; exact fold_congr
attribute [congr] finset.sum_congr
@[to_additive]
lemma prod_union_inter [decidable_eq α] :
(∏ x in (s₁ ∪ s₂), f x) * (∏ x in (s₁ ∩ s₂), f x) = (∏ x in s₁, f x) * (∏ x in s₂, f x) :=
fold_union_inter
@[to_additive]
lemma prod_union [decidable_eq α] (h : disjoint s₁ s₂) :
(∏ x in (s₁ ∪ s₂), f x) = (∏ x in s₁, f x) * (∏ x in s₂, f x) :=
by rw [←prod_union_inter, (disjoint_iff_inter_eq_empty.mp h)]; exact (mul_one _).symm
@[to_additive]
lemma prod_filter_mul_prod_filter_not (s : finset α) (p : α → Prop) [decidable_pred p]
[decidable_pred (λ x, ¬p x)] (f : α → β) :
(∏ x in s.filter p, f x) * (∏ x in s.filter (λ x, ¬p x), f x) = ∏ x in s, f x :=
begin
haveI := classical.dec_eq α,
rw [← prod_union (filter_inter_filter_neg_eq p s).le, filter_union_filter_neg_eq]
end
end comm_monoid
end finset
section
open finset
variables [fintype α] [decidable_eq α] [comm_monoid β]
@[to_additive]
lemma is_compl.prod_mul_prod {s t : finset α} (h : is_compl s t) (f : α → β) :
(∏ i in s, f i) * (∏ i in t, f i) = ∏ i, f i :=
(finset.prod_union h.disjoint).symm.trans $ by rw [← finset.sup_eq_union, h.sup_eq_top]; refl
end
namespace finset
section comm_monoid
variables [comm_monoid β]
/-- Multiplying the products of a function over `s` and over `sᶜ` gives the whole product.
For a version expressed with subtypes, see `fintype.prod_subtype_mul_prod_subtype`. -/
@[to_additive "Adding the sums of a function over `s` and over `sᶜ` gives the whole sum.
For a version expressed with subtypes, see `fintype.sum_subtype_add_sum_subtype`. "]
lemma prod_mul_prod_compl [fintype α] [decidable_eq α] (s : finset α) (f : α → β) :
(∏ i in s, f i) * (∏ i in sᶜ, f i) = ∏ i, f i :=
is_compl_compl.prod_mul_prod f
@[to_additive]
lemma prod_compl_mul_prod [fintype α] [decidable_eq α] (s : finset α) (f : α → β) :
(∏ i in sᶜ, f i) * (∏ i in s, f i) = ∏ i, f i :=
is_compl_compl.symm.prod_mul_prod f
@[to_additive]
lemma prod_sdiff [decidable_eq α] (h : s₁ ⊆ s₂) :
(∏ x in (s₂ \ s₁), f x) * (∏ x in s₁, f x) = (∏ x in s₂, f x) :=
by rw [←prod_union sdiff_disjoint, sdiff_union_of_subset h]
@[simp, to_additive]
lemma prod_sum_elim [decidable_eq (α ⊕ γ)]
(s : finset α) (t : finset γ) (f : α → β) (g : γ → β) :
∏ x in s.map function.embedding.inl ∪ t.map function.embedding.inr, sum.elim f g x =
(∏ x in s, f x) * (∏ x in t, g x) :=
begin
rw [prod_union, prod_map, prod_map],
{ simp only [sum.elim_inl, function.embedding.inl_apply, function.embedding.inr_apply,
sum.elim_inr] },
{ simp only [disjoint_left, finset.mem_map, finset.mem_map],
rintros _ ⟨i, hi, rfl⟩ ⟨j, hj, H⟩,
cases H }
end
@[to_additive]
lemma prod_bUnion [decidable_eq α] {s : finset γ} {t : γ → finset α}
(hs : set.pairwise_disjoint ↑s t) :
(∏ x in (s.bUnion t), f x) = ∏ x in s, ∏ i in t x, f i :=
begin
haveI := classical.dec_eq γ,
induction s using finset.induction_on with x s hxs ih hd,
{ simp_rw [bUnion_empty, prod_empty] },
{ simp_rw [coe_insert, set.pairwise_disjoint_insert, mem_coe] at hs,
have : disjoint (t x) (finset.bUnion s t),
{ exact (disjoint_bUnion_right _ _ _).mpr (λ y hy, hs.2 y hy $ λ H, hxs $ H.substr hy) },
rw [bUnion_insert, prod_insert hxs, prod_union this, ih hs.1] }
end
@[to_additive]
lemma prod_product {s : finset γ} {t : finset α} {f : γ×α → β} :
(∏ x in s.product t, f x) = ∏ x in s, ∏ y in t, f (x, y) :=
begin
haveI := classical.dec_eq α, haveI := classical.dec_eq γ,
rw [product_eq_bUnion, prod_bUnion],
{ congr, funext, exact prod_image (λ _ _ _ _ H, (prod.mk.inj H).2) },
simp only [disjoint_iff_ne, mem_image],
rintro x _ y _ h ⟨i, z⟩ hz,
rw [inf_eq_inter, mem_inter, mem_image, mem_image] at hz,
obtain ⟨⟨_, _, rfl, _⟩, _, _, rfl, _⟩ := hz,
exact h rfl,
end
/-- An uncurried version of `finset.prod_product`. -/
@[to_additive "An uncurried version of `finset.sum_product`"]
lemma prod_product' {s : finset γ} {t : finset α} {f : γ → α → β} :
(∏ x in s.product t, f x.1 x.2) = ∏ x in s, ∏ y in t, f x y :=
prod_product
/-- Product over a sigma type equals the product of fiberwise products. For rewriting
in the reverse direction, use `finset.prod_sigma'`. -/
@[to_additive "Sum over a sigma type equals the sum of fiberwise sums. For rewriting
in the reverse direction, use `finset.sum_sigma'`"]
lemma prod_sigma {σ : α → Type*}
(s : finset α) (t : Π a, finset (σ a)) (f : sigma σ → β) :
(∏ x in s.sigma t, f x) = ∏ a in s, ∏ s in (t a), f ⟨a, s⟩ :=
by classical;
calc (∏ x in s.sigma t, f x) =
∏ x in s.bUnion (λ a, (t a).map (function.embedding.sigma_mk a)), f x : by rw sigma_eq_bUnion
... = ∏ a in s, ∏ x in (t a).map (function.embedding.sigma_mk a), f x :
prod_bUnion $ assume a₁ ha a₂ ha₂ h x hx,
by { simp only [inf_eq_inter, mem_inter, mem_map, function.embedding.sigma_mk_apply] at hx,
rcases hx with ⟨⟨y, hy, rfl⟩, ⟨z, hz, hz'⟩⟩, cc }
... = ∏ a in s, ∏ s in t a, f ⟨a, s⟩ :
prod_congr rfl $ λ _ _, prod_map _ _ _
@[to_additive]
lemma prod_sigma' {σ : α → Type*}
(s : finset α) (t : Π a, finset (σ a)) (f : Π a, σ a → β) :
(∏ a in s, ∏ s in (t a), f a s) = ∏ x in s.sigma t, f x.1 x.2 :=
eq.symm $ prod_sigma s t (λ x, f x.1 x.2)
@[to_additive]
lemma prod_fiberwise_of_maps_to [decidable_eq γ] {s : finset α} {t : finset γ} {g : α → γ}
(h : ∀ x ∈ s, g x ∈ t) (f : α → β) :
(∏ y in t, ∏ x in s.filter (λ x, g x = y), f x) = ∏ x in s, f x :=
begin
letI := classical.dec_eq α,
rw [← bUnion_filter_eq_of_maps_to h] {occs := occurrences.pos [2]},
refine (prod_bUnion $ λ x' hx y' hy hne, _).symm,
rw [function.on_fun, disjoint_filter],
rintros x hx rfl,
exact hne
end
@[to_additive]
lemma prod_image' [decidable_eq α] {s : finset γ} {g : γ → α} (h : γ → β)
(eq : ∀ c ∈ s, f (g c) = ∏ x in s.filter (λ c', g c' = g c), h x) :
(∏ x in s.image g, f x) = ∏ x in s, h x :=
calc (∏ x in s.image g, f x) = ∏ x in s.image g, ∏ x in s.filter (λ c', g c' = x), h x :
prod_congr rfl $ λ x hx, let ⟨c, hcs, hc⟩ := mem_image.1 hx in hc ▸ (eq c hcs)
... = ∏ x in s, h x : prod_fiberwise_of_maps_to (λ x, mem_image_of_mem g) _
@[to_additive]
lemma prod_mul_distrib : ∏ x in s, (f x * g x) = (∏ x in s, f x) * (∏ x in s, g x) :=
eq.trans (by rw one_mul; refl) fold_op_distrib
@[to_additive]
lemma prod_comm {s : finset γ} {t : finset α} {f : γ → α → β} :
(∏ x in s, ∏ y in t, f x y) = (∏ y in t, ∏ x in s, f x y) :=
begin
classical,
apply finset.induction_on s,
{ simp only [prod_empty, prod_const_one] },
{ intros _ _ H ih,
simp only [prod_insert H, prod_mul_distrib, ih] }
end
@[to_additive]
lemma prod_hom_rel [comm_monoid γ] {r : β → γ → Prop} {f : α → β} {g : α → γ} {s : finset α}
(h₁ : r 1 1) (h₂ : ∀ a b c, r b c → r (f a * b) (g a * c)) : r (∏ x in s, f x) (∏ x in s, g x) :=
by { delta finset.prod, apply multiset.prod_hom_rel; assumption }
@[to_additive]
lemma prod_eq_one {f : α → β} {s : finset α} (h : ∀ x ∈ s, f x = 1) : (∏ x in s, f x) = 1 :=
calc (∏ x in s, f x) = ∏ x in s, 1 : finset.prod_congr rfl h
... = 1 : finset.prod_const_one
@[to_additive]
lemma prod_subset_one_on_sdiff [decidable_eq α] (h : s₁ ⊆ s₂) (hg : ∀ x ∈ (s₂ \ s₁), g x = 1)
(hfg : ∀ x ∈ s₁, f x = g x) : ∏ i in s₁, f i = ∏ i in s₂, g i :=
begin
rw [← prod_sdiff h, prod_eq_one hg, one_mul],
exact prod_congr rfl hfg
end
@[to_additive]
lemma prod_subset (h : s₁ ⊆ s₂) (hf : ∀ x ∈ s₂, x ∉ s₁ → f x = 1) :
(∏ x in s₁, f x) = ∏ x in s₂, f x :=
by haveI := classical.dec_eq α; exact prod_subset_one_on_sdiff h (by simpa) (λ _ _, rfl)
@[to_additive]
lemma prod_filter_of_ne {p : α → Prop} [decidable_pred p] (hp : ∀ x ∈ s, f x ≠ 1 → p x) :
(∏ x in (s.filter p), f x) = (∏ x in s, f x) :=
prod_subset (filter_subset _ _) $ λ x,
by { classical, rw [not_imp_comm, mem_filter], exact λ h₁ h₂, ⟨h₁, hp _ h₁ h₂⟩ }
-- If we use `[decidable_eq β]` here, some rewrites fail because they find a wrong `decidable`
-- instance first; `{∀ x, decidable (f x ≠ 1)}` doesn't work with `rw ← prod_filter_ne_one`
@[to_additive]
lemma prod_filter_ne_one [∀ x, decidable (f x ≠ 1)] :
(∏ x in (s.filter $ λ x, f x ≠ 1), f x) = (∏ x in s, f x) :=
prod_filter_of_ne $ λ _ _, id
@[to_additive]
lemma prod_filter (p : α → Prop) [decidable_pred p] (f : α → β) :
(∏ a in s.filter p, f a) = (∏ a in s, if p a then f a else 1) :=
calc (∏ a in s.filter p, f a) = ∏ a in s.filter p, if p a then f a else 1 :
prod_congr rfl (assume a h, by rw [if_pos (mem_filter.1 h).2])
... = ∏ a in s, if p a then f a else 1 :
begin
refine prod_subset (filter_subset _ s) (assume x hs h, _),
rw [mem_filter, not_and] at h,
exact if_neg (h hs)
end
@[to_additive]
lemma prod_eq_single_of_mem {s : finset α} {f : α → β} (a : α) (h : a ∈ s)
(h₀ : ∀ b ∈ s, b ≠ a → f b = 1) : (∏ x in s, f x) = f a :=
begin
haveI := classical.dec_eq α,
calc (∏ x in s, f x) = ∏ x in {a}, f x :
begin
refine (prod_subset _ _).symm,
{ intros _ H, rwa mem_singleton.1 H },
{ simpa only [mem_singleton] }
end
... = f a : prod_singleton
end
@[to_additive]
lemma prod_eq_single {s : finset α} {f : α → β} (a : α)
(h₀ : ∀ b ∈ s, b ≠ a → f b = 1) (h₁ : a ∉ s → f a = 1) : (∏ x in s, f x) = f a :=
by haveI := classical.dec_eq α;
from classical.by_cases
(assume : a ∈ s, prod_eq_single_of_mem a this h₀)
(assume : a ∉ s,
(prod_congr rfl $ λ b hb, h₀ b hb $ by rintro rfl; cc).trans $
prod_const_one.trans (h₁ this).symm)
@[to_additive]
lemma prod_eq_mul_of_mem {s : finset α} {f : α → β} (a b : α) (ha : a ∈ s) (hb : b ∈ s) (hn : a ≠ b)
(h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) : (∏ x in s, f x) = (f a) * (f b) :=
begin
haveI := classical.dec_eq α;
let s' := ({a, b} : finset α),
have hu : s' ⊆ s,
{ refine insert_subset.mpr _, apply and.intro ha, apply singleton_subset_iff.mpr hb },
have hf : ∀ c ∈ s, c ∉ s' → f c = 1,
{ intros c hc hcs,
apply h₀ c hc,
apply not_or_distrib.mp,
intro hab,
apply hcs,
apply mem_insert.mpr,
rw mem_singleton,
exact hab },
rw ←prod_subset hu hf,
exact finset.prod_pair hn
end
@[to_additive]
lemma prod_eq_mul {s : finset α} {f : α → β} (a b : α) (hn : a ≠ b)
(h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) (ha : a ∉ s → f a = 1) (hb : b ∉ s → f b = 1) :
(∏ x in s, f x) = (f a) * (f b) :=
begin
haveI := classical.dec_eq α;
by_cases h₁ : a ∈ s; by_cases h₂ : b ∈ s,
{ exact prod_eq_mul_of_mem a b h₁ h₂ hn h₀ },
{ rw [hb h₂, mul_one],
apply prod_eq_single_of_mem a h₁,
exact λ c hc hca, h₀ c hc ⟨hca, ne_of_mem_of_not_mem hc h₂⟩ },
{ rw [ha h₁, one_mul],
apply prod_eq_single_of_mem b h₂,
exact λ c hc hcb, h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, hcb⟩ },
{ rw [ha h₁, hb h₂, mul_one],
exact trans
(prod_congr rfl (λ c hc, h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, ne_of_mem_of_not_mem hc h₂⟩))
prod_const_one }
end
@[to_additive]
lemma prod_attach {f : α → β} : (∏ x in s.attach, f x) = (∏ x in s, f x) :=
by haveI := classical.dec_eq α; exact
calc (∏ x in s.attach, f x.val) = (∏ x in (s.attach).image subtype.val, f x) :
by rw [prod_image]; exact assume x _ y _, subtype.eq
... = _ : by rw [attach_image_val]
/-- A product over `s.subtype p` equals one over `s.filter p`. -/
@[simp, to_additive "A sum over `s.subtype p` equals one over `s.filter p`."]
lemma prod_subtype_eq_prod_filter (f : α → β) {p : α → Prop} [decidable_pred p] :
∏ x in s.subtype p, f x = ∏ x in s.filter p, f x :=
begin
conv_lhs { erw ←prod_map (s.subtype p) (function.embedding.subtype _) f },
exact prod_congr (subtype_map _) (λ x hx, rfl)
end
/-- If all elements of a `finset` satisfy the predicate `p`, a product
over `s.subtype p` equals that product over `s`. -/
@[to_additive "If all elements of a `finset` satisfy the predicate `p`, a sum
over `s.subtype p` equals that sum over `s`."]
lemma prod_subtype_of_mem (f : α → β) {p : α → Prop} [decidable_pred p]
(h : ∀ x ∈ s, p x) : ∏ x in s.subtype p, f x = ∏ x in s, f x :=
by simp_rw [prod_subtype_eq_prod_filter, filter_true_of_mem h]
/-- A product of a function over a `finset` in a subtype equals a
product in the main type of a function that agrees with the first
function on that `finset`. -/
@[to_additive "A sum of a function over a `finset` in a subtype equals a
sum in the main type of a function that agrees with the first
function on that `finset`."]
lemma prod_subtype_map_embedding {p : α → Prop} {s : finset {x // p x}} {f : {x // p x} → β}
{g : α → β} (h : ∀ x : {x // p x}, x ∈ s → g x = f x) :
∏ x in s.map (function.embedding.subtype _), g x = ∏ x in s, f x :=
begin
rw finset.prod_map,
exact finset.prod_congr rfl h
end
@[to_additive]
lemma prod_finset_coe (f : α → β) (s : finset α) :
∏ (i : (s : set α)), f i = ∏ i in s, f i :=
prod_attach
@[to_additive]
lemma prod_subtype {p : α → Prop} {F : fintype (subtype p)} (s : finset α)
(h : ∀ x, x ∈ s ↔ p x) (f : α → β) :
∏ a in s, f a = ∏ a : subtype p, f a :=
have (∈ s) = p, from set.ext h, by { substI p, rw [←prod_finset_coe], congr }
@[to_additive] lemma prod_apply_dite {s : finset α} {p : α → Prop} {hp : decidable_pred p}
[decidable_pred (λ x, ¬ p x)] (f : Π (x : α), p x → γ) (g : Π (x : α), ¬p x → γ)
(h : γ → β) :
(∏ x in s, h (if hx : p x then f x hx else g x hx)) =
(∏ x in (s.filter p).attach, h (f x.1 (mem_filter.mp x.2).2)) *
(∏ x in (s.filter (λ x, ¬ p x)).attach, h (g x.1 (mem_filter.mp x.2).2)) :=
calc ∏ x in s, h (if hx : p x then f x hx else g x hx)
= (∏ x in s.filter p, h (if hx : p x then f x hx else g x hx)) *
(∏ x in s.filter (λ x, ¬ p x), h (if hx : p x then f x hx else g x hx)) :
(prod_filter_mul_prod_filter_not s p _).symm
... = (∏ x in (s.filter p).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx)) *
(∏ x in (s.filter (λ x, ¬ p x)).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx)) :
congr_arg2 _ prod_attach.symm prod_attach.symm
... = (∏ x in (s.filter p).attach, h (f x.1 (mem_filter.mp x.2).2)) *
(∏ x in (s.filter (λ x, ¬ p x)).attach, h (g x.1 (mem_filter.mp x.2).2)) :
congr_arg2 _
(prod_congr rfl (λ x hx, congr_arg h (dif_pos (mem_filter.mp x.2).2)))
(prod_congr rfl (λ x hx, congr_arg h (dif_neg (mem_filter.mp x.2).2)))
@[to_additive] lemma prod_apply_ite {s : finset α}
{p : α → Prop} {hp : decidable_pred p} (f g : α → γ) (h : γ → β) :
(∏ x in s, h (if p x then f x else g x)) =
(∏ x in s.filter p, h (f x)) * (∏ x in s.filter (λ x, ¬ p x), h (g x)) :=
trans (prod_apply_dite _ _ _)
(congr_arg2 _ (@prod_attach _ _ _ _ (h ∘ f)) (@prod_attach _ _ _ _ (h ∘ g)))
@[to_additive] lemma prod_dite {s : finset α} {p : α → Prop} {hp : decidable_pred p}
(f : Π (x : α), p x → β) (g : Π (x : α), ¬p x → β) :
(∏ x in s, if hx : p x then f x hx else g x hx) =
(∏ x in (s.filter p).attach, f x.1 (mem_filter.mp x.2).2) *
(∏ x in (s.filter (λ x, ¬ p x)).attach, g x.1 (mem_filter.mp x.2).2) :=
by simp [prod_apply_dite _ _ (λ x, x)]
@[to_additive] lemma prod_ite {s : finset α}
{p : α → Prop} {hp : decidable_pred p} (f g : α → β) :
(∏ x in s, if p x then f x else g x) =
(∏ x in s.filter p, f x) * (∏ x in s.filter (λ x, ¬ p x), g x) :=
by simp [prod_apply_ite _ _ (λ x, x)]
@[to_additive] lemma prod_ite_of_false {p : α → Prop} {hp : decidable_pred p} (f g : α → β)
(h : ∀ x ∈ s, ¬p x) : (∏ x in s, if p x then f x else g x) = (∏ x in s, g x) :=
by { rw prod_ite, simp [filter_false_of_mem h, filter_true_of_mem h] }
@[to_additive] lemma prod_ite_of_true {p : α → Prop} {hp : decidable_pred p} (f g : α → β)
(h : ∀ x ∈ s, p x) : (∏ x in s, if p x then f x else g x) = (∏ x in s, f x) :=
by { simp_rw ←(ite_not (p _)), apply prod_ite_of_false, simpa }
@[to_additive] lemma prod_apply_ite_of_false {p : α → Prop} {hp : decidable_pred p} (f g : α → γ)
(k : γ → β) (h : ∀ x ∈ s, ¬p x) :
(∏ x in s, k (if p x then f x else g x)) = (∏ x in s, k (g x)) :=
by { simp_rw apply_ite k, exact prod_ite_of_false _ _ h }
@[to_additive] lemma prod_apply_ite_of_true {p : α → Prop} {hp : decidable_pred p} (f g : α → γ)
(k : γ → β) (h : ∀ x ∈ s, p x) :
(∏ x in s, k (if p x then f x else g x)) = (∏ x in s, k (f x)) :=
by { simp_rw apply_ite k, exact prod_ite_of_true _ _ h }
@[to_additive]
lemma prod_extend_by_one [decidable_eq α] (s : finset α) (f : α → β) :
∏ i in s, (if i ∈ s then f i else 1) = ∏ i in s, f i :=
prod_congr rfl $ λ i hi, if_pos hi
@[simp, to_additive]
lemma prod_dite_eq [decidable_eq α] (s : finset α) (a : α) (b : Π x : α, a = x → β) :
(∏ x in s, (if h : a = x then b x h else 1)) = ite (a ∈ s) (b a rfl) 1 :=
begin
split_ifs with h,
{ rw [finset.prod_eq_single a, dif_pos rfl],
{ intros, rw dif_neg, cc },
{ cc } },
{ rw finset.prod_eq_one,
intros, rw dif_neg, intro, cc }
end
@[simp, to_additive]
lemma prod_dite_eq' [decidable_eq α] (s : finset α) (a : α) (b : Π x : α, x = a → β) :
(∏ x in s, (if h : x = a then b x h else 1)) = ite (a ∈ s) (b a rfl) 1 :=
begin
split_ifs with h,
{ rw [finset.prod_eq_single a, dif_pos rfl],
{ intros, rw dif_neg, cc },
{ cc } },
{ rw finset.prod_eq_one,
intros, rw dif_neg, intro, cc }
end
@[simp, to_additive] lemma prod_ite_eq [decidable_eq α] (s : finset α) (a : α) (b : α → β) :
(∏ x in s, (ite (a = x) (b x) 1)) = ite (a ∈ s) (b a) 1 :=
prod_dite_eq s a (λ x _, b x)
/--
When a product is taken over a conditional whose condition is an equality test on the index
and whose alternative is 1, then the product's value is either the term at that index or `1`.
The difference with `prod_ite_eq` is that the arguments to `eq` are swapped.
-/
@[simp, to_additive] lemma prod_ite_eq' [decidable_eq α] (s : finset α) (a : α) (b : α → β) :
(∏ x in s, (ite (x = a) (b x) 1)) = ite (a ∈ s) (b a) 1 :=
prod_dite_eq' s a (λ x _, b x)
@[to_additive]
lemma prod_ite_index (p : Prop) [decidable p] (s t : finset α) (f : α → β) :
(∏ x in if p then s else t, f x) = if p then ∏ x in s, f x else ∏ x in t, f x :=
apply_ite (λ s, ∏ x in s, f x) _ _ _
@[simp, to_additive]
lemma prod_dite_irrel (p : Prop) [decidable p] (s : finset α) (f : p → α → β) (g : ¬p → α → β):
(∏ x in s, if h : p then f h x else g h x) = if h : p then ∏ x in s, f h x else ∏ x in s, g h x :=
by { split_ifs with h; refl }
@[simp] lemma sum_pi_single' {ι M : Type*} [decidable_eq ι] [add_comm_monoid M]
(i : ι) (x : M) (s : finset ι) :
∑ j in s, pi.single i x j = if i ∈ s then x else 0 :=
sum_dite_eq' _ _ _
@[simp] lemma sum_pi_single {ι : Type*} {M : ι → Type*}
[decidable_eq ι] [Π i, add_comm_monoid (M i)] (i : ι) (f : Π i, M i) (s : finset ι) :
∑ j in s, pi.single j (f j) i = if i ∈ s then f i else 0 :=
sum_dite_eq _ _ _
/--
Reorder a product.
The difference with `prod_bij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
-/
@[to_additive "
Reorder a sum.
The difference with `sum_bij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
"]
lemma prod_bij {s : finset α} {t : finset γ} {f : α → β} {g : γ → β}
(i : Π a ∈ s, γ) (hi : ∀ a ha, i a ha ∈ t) (h : ∀ a ha, f a = g (i a ha))
(i_inj : ∀ a₁ a₂ ha₁ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂) (i_surj : ∀ b ∈ t, ∃ a ha, b = i a ha) :
(∏ x in s, f x) = (∏ x in t, g x) :=
congr_arg multiset.prod
(multiset.map_eq_map_of_bij_of_nodup f g s.2 t.2 i hi h i_inj i_surj)
/--
Reorder a product.
The difference with `prod_bij` is that the bijection is specified with an inverse, rather than
as a surjective injection.
-/
@[to_additive "
Reorder a sum.
The difference with `sum_bij` is that the bijection is specified with an inverse, rather than
as a surjective injection.
"]
lemma prod_bij' {s : finset α} {t : finset γ} {f : α → β} {g : γ → β}
(i : Π a ∈ s, γ) (hi : ∀ a ha, i a ha ∈ t) (h : ∀ a ha, f a = g (i a ha))
(j : Π a ∈ t, α) (hj : ∀ a ha, j a ha ∈ s) (left_inv : ∀ a ha, j (i a ha) (hi a ha) = a)
(right_inv : ∀ a ha, i (j a ha) (hj a ha) = a) :
(∏ x in s, f x) = (∏ x in t, g x) :=
begin
refine prod_bij i hi h _ _,
{intros a1 a2 h1 h2 eq, rw [←left_inv a1 h1, ←left_inv a2 h2], cc,},
{intros b hb, use j b hb, use hj b hb, exact (right_inv b hb).symm,},
end
@[to_additive]
lemma prod_bij_ne_one {s : finset α} {t : finset γ} {f : α → β} {g : γ → β}
(i : Π a ∈ s, f a ≠ 1 → γ) (hi : ∀ a h₁ h₂, i a h₁ h₂ ∈ t)
(i_inj : ∀ a₁ a₂ h₁₁ h₁₂ h₂₁ h₂₂, i a₁ h₁₁ h₁₂ = i a₂ h₂₁ h₂₂ → a₁ = a₂)
(i_surj : ∀ b ∈ t, g b ≠ 1 → ∃ a h₁ h₂, b = i a h₁ h₂)
(h : ∀ a h₁ h₂, f a = g (i a h₁ h₂)) :
(∏ x in s, f x) = (∏ x in t, g x) :=
by classical; exact
calc (∏ x in s, f x) = ∏ x in (s.filter $ λ x, f x ≠ 1), f x : prod_filter_ne_one.symm
... = ∏ x in (t.filter $ λ x, g x ≠ 1), g x :
prod_bij (assume a ha, i a (mem_filter.mp ha).1 (mem_filter.mp ha).2)
(assume a ha, (mem_filter.mp ha).elim $ λ h₁ h₂, mem_filter.mpr
⟨hi a h₁ h₂, λ hg, h₂ (hg ▸ h a h₁ h₂)⟩)
(assume a ha, (mem_filter.mp ha).elim $ h a)
(assume a₁ a₂ ha₁ ha₂,
(mem_filter.mp ha₁).elim $ λ ha₁₁ ha₁₂,
(mem_filter.mp ha₂).elim $ λ ha₂₁ ha₂₂, i_inj a₁ a₂ _ _ _ _)
(assume b hb, (mem_filter.mp hb).elim $ λ h₁ h₂,
let ⟨a, ha₁, ha₂, eq⟩ := i_surj b h₁ h₂ in ⟨a, mem_filter.mpr ⟨ha₁, ha₂⟩, eq⟩)
... = (∏ x in t, g x) : prod_filter_ne_one
@[to_additive] lemma prod_dite_of_false {p : α → Prop} {hp : decidable_pred p}
(h : ∀ x ∈ s, ¬ p x) (f : Π (x : α), p x → β) (g : Π (x : α), ¬p x → β) :
(∏ x in s, if hx : p x then f x hx else g x hx) =
∏ (x : s), g x.val (h x.val x.property) :=
prod_bij (λ x hx, ⟨x,hx⟩) (λ x hx, by simp) (λ a ha, by { dsimp, rw dif_neg })
(λ a₁ a₂ h₁ h₂ hh, congr_arg coe hh) (λ b hb, ⟨b.1, b.2, by simp⟩)
@[to_additive] lemma prod_dite_of_true {p : α → Prop} {hp : decidable_pred p}
(h : ∀ x ∈ s, p x) (f : Π (x : α), p x → β) (g : Π (x : α), ¬p x → β) :
(∏ x in s, if hx : p x then f x hx else g x hx) =
∏ (x : s), f x.val (h x.val x.property) :=
prod_bij (λ x hx, ⟨x,hx⟩) (λ x hx, by simp) (λ a ha, by { dsimp, rw dif_pos })
(λ a₁ a₂ h₁ h₂ hh, congr_arg coe hh) (λ b hb, ⟨b.1, b.2, by simp⟩)
@[to_additive]
lemma nonempty_of_prod_ne_one (h : (∏ x in s, f x) ≠ 1) : s.nonempty :=
s.eq_empty_or_nonempty.elim (λ H, false.elim $ h $ H.symm ▸ prod_empty) id
@[to_additive]
lemma exists_ne_one_of_prod_ne_one (h : (∏ x in s, f x) ≠ 1) : ∃ a ∈ s, f a ≠ 1 :=
begin
classical,
rw ← prod_filter_ne_one at h,
rcases nonempty_of_prod_ne_one h with ⟨x, hx⟩,
exact ⟨x, (mem_filter.1 hx).1, (mem_filter.1 hx).2⟩
end
@[to_additive]
lemma prod_range_succ_comm (f : ℕ → β) (n : ℕ) :
∏ x in range (n + 1), f x = f n * ∏ x in range n, f x :=
by rw [range_succ, prod_insert not_mem_range_self]
@[to_additive]
lemma prod_range_succ (f : ℕ → β) (n : ℕ) :
∏ x in range (n + 1), f x = (∏ x in range n, f x) * f n :=
by simp only [mul_comm, prod_range_succ_comm]
@[to_additive]
lemma prod_range_succ' (f : ℕ → β) :
∀ n : ℕ, (∏ k in range (n + 1), f k) = (∏ k in range n, f (k+1)) * f 0
| 0 := prod_range_succ _ _
| (n + 1) := by rw [prod_range_succ _ n, mul_right_comm, ← prod_range_succ', prod_range_succ]
@[to_additive]
lemma eventually_constant_prod {u : ℕ → β} {N : ℕ} (hu : ∀ n ≥ N, u n = 1) {n : ℕ} (hn : N ≤ n) :
∏ k in range (n + 1), u k = ∏ k in range (N + 1), u k :=
begin
obtain ⟨m, rfl : n = N + m⟩ := le_iff_exists_add.mp hn,
clear hn,
induction m with m hm,
{ simp },
erw [prod_range_succ, hm],
simp [hu]
end
@[to_additive]
lemma prod_range_add (f : ℕ → β) (n m : ℕ) :
∏ x in range (n + m), f x =
(∏ x in range n, f x) * (∏ x in range m, f (n + x)) :=
begin
induction m with m hm,
{ simp },
{ rw [nat.add_succ, prod_range_succ, hm, prod_range_succ, mul_assoc], },
end
@[to_additive]
lemma prod_range_add_div_prod_range {α : Type*} [comm_group α] (f : ℕ → α) (n m : ℕ) :
(∏ k in range (n + m), f k) / (∏ k in range n, f k) = ∏ k in finset.range m, f (n + k) :=
div_eq_of_eq_mul' (prod_range_add f n m)
@[to_additive]
lemma prod_range_zero (f : ℕ → β) :
∏ k in range 0, f k = 1 :=
by rw [range_zero, prod_empty]
@[to_additive sum_range_one]
lemma prod_range_one (f : ℕ → β) :
∏ k in range 1, f k = f 0 :=
by { rw [range_one], apply @prod_singleton β ℕ 0 f }
open multiset
@[to_additive] lemma prod_multiset_map_count [decidable_eq α] (s : multiset α)
{M : Type*} [comm_monoid M] (f : α → M) :
(s.map f).prod = ∏ m in s.to_finset, (f m) ^ (s.count m) :=
begin
induction s using multiset.induction_on with a s ih,
{ simp only [prod_const_one, count_zero, prod_zero, pow_zero, map_zero] },
simp only [multiset.prod_cons, map_cons, to_finset_cons, ih],
by_cases has : a ∈ s.to_finset,
{ rw [insert_eq_of_mem has, ← insert_erase has, prod_insert (not_mem_erase _ _),
prod_insert (not_mem_erase _ _), ← mul_assoc, count_cons_self, pow_succ],
congr' 1, refine prod_congr rfl (λ x hx, _),
rw [count_cons_of_ne (ne_of_mem_erase hx)] },
rw [prod_insert has, count_cons_self, count_eq_zero_of_not_mem (mt mem_to_finset.2 has), pow_one],
congr' 1, refine prod_congr rfl (λ x hx, _),
rw count_cons_of_ne,
rintro rfl, exact has hx
end
@[to_additive]
lemma prod_multiset_count [decidable_eq α] [comm_monoid α] (s : multiset α) :
s.prod = ∏ m in s.to_finset, m ^ (s.count m) :=
by { convert prod_multiset_map_count s id, rw map_id }
@[to_additive] lemma prod_mem_multiset [decidable_eq α]
(m : multiset α) (f : {x // x ∈ m} → β) (g : α → β)
(hfg : ∀ x, f x = g x) :
∏ (x : {x // x ∈ m}), f x = ∏ x in m.to_finset, g x :=
prod_bij (λ x _, x.1) (λ x _, multiset.mem_to_finset.mpr x.2)
(λ _ _, hfg _)
(λ _ _ _ _ h, by { ext, assumption })
(λ y hy, ⟨⟨y, multiset.mem_to_finset.mp hy⟩, finset.mem_univ _, rfl⟩)
/--
To prove a property of a product, it suffices to prove that
the property is multiplicative and holds on factors.
-/
@[to_additive "To prove a property of a sum, it suffices to prove that
the property is additive and holds on summands."]
lemma prod_induction {M : Type*} [comm_monoid M] (f : α → M) (p : M → Prop)
(p_mul : ∀ a b, p a → p b → p (a * b)) (p_one : p 1) (p_s : ∀ x ∈ s, p $ f x) :
p $ ∏ x in s, f x :=
multiset.prod_induction _ _ p_mul p_one (multiset.forall_mem_map_iff.mpr p_s)
/--
To prove a property of a product, it suffices to prove that
the property is multiplicative and holds on factors.
-/
@[to_additive "To prove a property of a sum, it suffices to prove that
the property is additive and holds on summands."]
lemma prod_induction_nonempty {M : Type*} [comm_monoid M] (f : α → M) (p : M → Prop)
(p_mul : ∀ a b, p a → p b → p (a * b)) (hs_nonempty : s.nonempty) (p_s : ∀ x ∈ s, p $ f x) :
p $ ∏ x in s, f x :=
multiset.prod_induction_nonempty p p_mul (by simp [nonempty_iff_ne_empty.mp hs_nonempty])
(multiset.forall_mem_map_iff.mpr p_s)
/--
For any product along `{0, ..., n-1}` of a commutative-monoid-valued function, we can verify that
it's equal to a different function just by checking ratios of adjacent terms.
This is a multiplicative discrete analogue of the fundamental theorem of calculus. -/
lemma prod_range_induction {M : Type*} [comm_monoid M]
(f s : ℕ → M) (h0 : s 0 = 1) (h : ∀ n, s (n + 1) = s n * f n) (n : ℕ) :
∏ k in finset.range n, f k = s n :=
begin
induction n with k hk,
{ simp only [h0, finset.prod_range_zero] },
{ simp only [hk, finset.prod_range_succ, h, mul_comm] }
end
/--
For any sum along `{0, ..., n-1}` of a commutative-monoid-valued function,
we can verify that it's equal to a different function
just by checking differences of adjacent terms.
This is a discrete analogue
of the fundamental theorem of calculus.
-/
lemma sum_range_induction {M : Type*} [add_comm_monoid M]
(f s : ℕ → M) (h0 : s 0 = 0) (h : ∀ n, s (n + 1) = s n + f n) (n : ℕ) :
∑ k in finset.range n, f k = s n :=
@prod_range_induction (multiplicative M) _ f s h0 h n
/-- A telescoping sum along `{0, ..., n-1}` of an additive commutative group valued function
reduces to the difference of the last and first terms.-/
lemma sum_range_sub {G : Type*} [add_comm_group G] (f : ℕ → G) (n : ℕ) :
∑ i in range n, (f (i+1) - f i) = f n - f 0 :=
by { apply sum_range_induction; simp }
lemma sum_range_sub' {G : Type*} [add_comm_group G] (f : ℕ → G) (n : ℕ) :
∑ i in range n, (f i - f (i+1)) = f 0 - f n :=
by { apply sum_range_induction; simp }
/-- A telescoping product along `{0, ..., n-1}` of a commutative group valued function
reduces to the ratio of the last and first factors.-/
@[to_additive]
lemma prod_range_div {M : Type*} [comm_group M] (f : ℕ → M) (n : ℕ) :
∏ i in range n, (f (i+1) * (f i)⁻¹) = f n * (f 0)⁻¹ :=
by simpa only [← div_eq_mul_inv] using @sum_range_sub (additive M) _ f n
@[to_additive]
lemma prod_range_div' {M : Type*} [comm_group M] (f : ℕ → M) (n : ℕ) :
∏ i in range n, (f i * (f (i+1))⁻¹) = (f 0) * (f n)⁻¹ :=
by simpa only [← div_eq_mul_inv] using @sum_range_sub' (additive M) _ f n
/--
A telescoping sum along `{0, ..., n-1}` of an `ℕ`-valued function
reduces to the difference of the last and first terms
when the function we are summing is monotone.
-/
lemma sum_range_sub_of_monotone {f : ℕ → ℕ} (h : monotone f) (n : ℕ) :
∑ i in range n, (f (i+1) - f i) = f n - f 0 :=
begin
refine sum_range_induction _ _ (tsub_self _) (λ n, _) _,
have h₁ : f n ≤ f (n+1) := h (nat.le_succ _),
have h₂ : f 0 ≤ f n := h (nat.zero_le _),
rw [tsub_add_eq_add_tsub h₂, add_tsub_cancel_of_le h₁],
end
@[simp, to_additive] lemma prod_const (b : β) : (∏ x in s, b) = b ^ s.card :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (by simp) (λ a s has ih,
by rw [prod_insert has, card_insert_of_not_mem has, pow_succ, ih])
@[to_additive]
lemma pow_eq_prod_const (b : β) : ∀ n, b ^ n = ∏ k in range n, b := by simp
@[to_additive sum_nsmul]
lemma prod_pow (s : finset α) (n : ℕ) (f : α → β) :
∏ x in s, f x ^ n = (∏ x in s, f x) ^ n :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (by simp) (by simp [mul_pow] {contextual := tt})
@[to_additive]
lemma prod_flip {n : ℕ} (f : ℕ → β) :
∏ r in range (n + 1), f (n - r) = ∏ k in range (n + 1), f k :=
begin
induction n with n ih,
{ rw [prod_range_one, prod_range_one] },
{ rw [prod_range_succ', prod_range_succ _ (nat.succ n)],
simp [← ih] }
end
@[to_additive]
lemma prod_involution {s : finset α} {f : α → β} :
∀ (g : Π a ∈ s, α)
(h : ∀ a ha, f a * f (g a ha) = 1)
(g_ne : ∀ a ha, f a ≠ 1 → g a ha ≠ a)
(g_mem : ∀ a ha, g a ha ∈ s)
(g_inv : ∀ a ha, g (g a ha) (g_mem a ha) = a),
(∏ x in s, f x) = 1 :=
by haveI := classical.dec_eq α;
haveI := classical.dec_eq β; exact
finset.strong_induction_on s
(λ s ih g h g_ne g_mem g_inv,
s.eq_empty_or_nonempty.elim (λ hs, hs.symm ▸ rfl)
(λ ⟨x, hx⟩,
have hmem : ∀ y ∈ (s.erase x).erase (g x hx), y ∈ s,
from λ y hy, (mem_of_mem_erase (mem_of_mem_erase hy)),
have g_inj : ∀ {x hx y hy}, g x hx = g y hy → x = y,
from λ x hx y hy h, by rw [← g_inv x hx, ← g_inv y hy]; simp [h],
have ih': ∏ y in erase (erase s x) (g x hx), f y = (1 : β) :=
ih ((s.erase x).erase (g x hx))
⟨subset.trans (erase_subset _ _) (erase_subset _ _),
λ h, not_mem_erase (g x hx) (s.erase x) (h (g_mem x hx))⟩
(λ y hy, g y (hmem y hy))
(λ y hy, h y (hmem y hy))
(λ y hy, g_ne y (hmem y hy))
(λ y hy, mem_erase.2 ⟨λ (h : g y _ = g x hx), by simpa [g_inj h] using hy,
mem_erase.2 ⟨λ (h : g y _ = x),
have y = g x hx, from g_inv y (hmem y hy) ▸ by simp [h],
by simpa [this] using hy, g_mem y (hmem y hy)⟩⟩)
(λ y hy, g_inv y (hmem y hy)),
if hx1 : f x = 1
then ih' ▸ eq.symm (prod_subset hmem
(λ y hy hy₁,
have y = x ∨ y = g x hx, by simp [hy] at hy₁; tauto,
this.elim (λ hy, hy.symm ▸ hx1)
(λ hy, h x hx ▸ hy ▸ hx1.symm ▸ (one_mul _).symm)))
else by rw [← insert_erase hx, prod_insert (not_mem_erase _ _),
← insert_erase (mem_erase.2 ⟨g_ne x hx hx1, g_mem x hx⟩),
prod_insert (not_mem_erase _ _), ih', mul_one, h x hx]))
/-- The product of the composition of functions `f` and `g`, is the product
over `b ∈ s.image g` of `f b` to the power of the cardinality of the fibre of `b`. See also
`finset.prod_image`. -/
lemma prod_comp [decidable_eq γ] (f : γ → β) (g : α → γ) :
∏ a in s, f (g a) = ∏ b in s.image g, f b ^ (s.filter (λ a, g a = b)).card :=
calc ∏ a in s, f (g a)
= ∏ x in (s.image g).sigma (λ b : γ, s.filter (λ a, g a = b)), f (g x.2) :
prod_bij (λ a ha, ⟨g a, a⟩) (by simp; tauto) (λ _ _, rfl) (by simp) (by finish)
... = ∏ b in s.image g, ∏ a in s.filter (λ a, g a = b), f (g a) : prod_sigma _ _ _
... = ∏ b in s.image g, ∏ a in s.filter (λ a, g a = b), f b :
prod_congr rfl (λ b hb, prod_congr rfl (by simp {contextual := tt}))
... = ∏ b in s.image g, f b ^ (s.filter (λ a, g a = b)).card :
prod_congr rfl (λ _ _, prod_const _)
@[to_additive]
lemma prod_piecewise [decidable_eq α] (s t : finset α) (f g : α → β) :
(∏ x in s, (t.piecewise f g) x) = (∏ x in s ∩ t, f x) * (∏ x in s \ t, g x) :=
by { rw [piecewise, prod_ite, filter_mem_eq_inter, ← sdiff_eq_filter], }
@[to_additive]
lemma prod_inter_mul_prod_diff [decidable_eq α] (s t : finset α) (f : α → β) :
(∏ x in s ∩ t, f x) * (∏ x in s \ t, f x) = (∏ x in s, f x) :=
by { convert (s.prod_piecewise t f f).symm, simp [finset.piecewise] }
@[to_additive]
lemma prod_eq_mul_prod_diff_singleton [decidable_eq α] {s : finset α} {i : α} (h : i ∈ s)
(f : α → β) : ∏ x in s, f x = f i * ∏ x in s \ {i}, f x :=
by { convert (s.prod_inter_mul_prod_diff {i} f).symm, simp [h] }
@[to_additive]
lemma prod_eq_prod_diff_singleton_mul [decidable_eq α] {s : finset α} {i : α} (h : i ∈ s)
(f : α → β) : ∏ x in s, f x = (∏ x in s \ {i}, f x) * f i :=
by { rw [prod_eq_mul_prod_diff_singleton h, mul_comm] }
@[to_additive]
lemma _root_.fintype.prod_eq_mul_prod_compl [decidable_eq α] [fintype α] (a : α) (f : α → β) :
∏ i, f i = (f a) * ∏ i in {a}ᶜ, f i :=
prod_eq_mul_prod_diff_singleton (mem_univ a) f
@[to_additive]
lemma _root_.fintype.prod_eq_prod_compl_mul [decidable_eq α] [fintype α] (a : α) (f : α → β) :
∏ i, f i = (∏ i in {a}ᶜ, f i) * f a :=
prod_eq_prod_diff_singleton_mul (mem_univ a) f
lemma dvd_prod_of_mem (f : α → β) {a : α} {s : finset α} (ha : a ∈ s) :
f a ∣ ∏ i in s, f i :=
begin
classical,
rw finset.prod_eq_mul_prod_diff_singleton ha,
exact dvd_mul_right _ _,
end
/-- A product can be partitioned into a product of products, each equivalent under a setoid. -/
@[to_additive "A sum can be partitioned into a sum of sums, each equivalent under a setoid."]
lemma prod_partition (R : setoid α) [decidable_rel R.r] :
(∏ x in s, f x) = ∏ xbar in s.image quotient.mk, ∏ y in s.filter (λ y, ⟦y⟧ = xbar), f y :=
begin
refine (finset.prod_image' f (λ x hx, _)).symm,
refl,
end
/-- If we can partition a product into subsets that cancel out, then the whole product cancels. -/
@[to_additive "If we can partition a sum into subsets that cancel out, then the whole sum cancels."]
lemma prod_cancels_of_partition_cancels (R : setoid α) [decidable_rel R.r]
(h : ∀ x ∈ s, (∏ a in s.filter (λ y, y ≈ x), f a) = 1) : (∏ x in s, f x) = 1 :=
begin
rw [prod_partition R, ←finset.prod_eq_one],
intros xbar xbar_in_s,
obtain ⟨x, x_in_s, xbar_eq_x⟩ := mem_image.mp xbar_in_s,
rw [←xbar_eq_x, filter_congr (λ y _, @quotient.eq _ R y x)],
apply h x x_in_s,
end
@[to_additive]
lemma prod_update_of_not_mem [decidable_eq α] {s : finset α} {i : α}
(h : i ∉ s) (f : α → β) (b : β) : (∏ x in s, function.update f i b x) = (∏ x in s, f x) :=
begin
apply prod_congr rfl (λ j hj, _),
have : j ≠ i, by { assume eq, rw eq at hj, exact h hj },
simp [this]
end
@[to_additive]
lemma prod_update_of_mem [decidable_eq α] {s : finset α} {i : α} (h : i ∈ s) (f : α → β) (b : β) :
(∏ x in s, function.update f i b x) = b * (∏ x in s \ (singleton i), f x) :=
by { rw [update_eq_piecewise, prod_piecewise], simp [h] }
/-- If a product of a `finset` of size at most 1 has a given value, so
do the terms in that product. -/
@[to_additive eq_of_card_le_one_of_sum_eq "If a sum of a `finset` of size at most 1 has a given
value, so do the terms in that sum."]
lemma eq_of_card_le_one_of_prod_eq {s : finset α} (hc : s.card ≤ 1) {f : α → β} {b : β}
(h : ∏ x in s, f x = b) : ∀ x ∈ s, f x = b :=
begin
intros x hx,
by_cases hc0 : s.card = 0,
{ exact false.elim (card_ne_zero_of_mem hx hc0) },
{ have h1 : s.card = 1 := le_antisymm hc (nat.one_le_of_lt (nat.pos_of_ne_zero hc0)),
rw card_eq_one at h1,
cases h1 with x2 hx2,
rw [hx2, mem_singleton] at hx,
simp_rw hx2 at h,
rw hx,
rw prod_singleton at h,
exact h }
end
/-- Taking a product over `s : finset α` is the same as multiplying the value on a single element
`f a` by the product of `s.erase a`. -/
@[to_additive "Taking a sum over `s : finset α` is the same as adding the value on a single element
`f a` to the sum over `s.erase a`."]
lemma mul_prod_erase [decidable_eq α] (s : finset α) (f : α → β) {a : α} (h : a ∈ s) :
f a * (∏ x in s.erase a, f x) = ∏ x in s, f x :=
by rw [← prod_insert (not_mem_erase a s), insert_erase h]
/-- A variant of `finset.mul_prod_erase` with the multiplication swapped. -/
@[to_additive "A variant of `finset.add_sum_erase` with the addition swapped."]
lemma prod_erase_mul [decidable_eq α] (s : finset α) (f : α → β) {a : α} (h : a ∈ s) :
(∏ x in s.erase a, f x) * f a = ∏ x in s, f x :=
by rw [mul_comm, mul_prod_erase s f h]
/-- If a function applied at a point is 1, a product is unchanged by
removing that point, if present, from a `finset`. -/
@[to_additive "If a function applied at a point is 0, a sum is unchanged by
removing that point, if present, from a `finset`."]
lemma prod_erase [decidable_eq α] (s : finset α) {f : α → β} {a : α} (h : f a = 1) :
∏ x in s.erase a, f x = ∏ x in s, f x :=
begin
rw ←sdiff_singleton_eq_erase,
refine prod_subset (sdiff_subset _ _) (λ x hx hnx, _),
rw sdiff_singleton_eq_erase at hnx,
rwa eq_of_mem_of_not_mem_erase hx hnx
end
/-- If a product is 1 and the function is 1 except possibly at one
point, it is 1 everywhere on the `finset`. -/
@[to_additive "If a sum is 0 and the function is 0 except possibly at one
point, it is 0 everywhere on the `finset`."]
lemma eq_one_of_prod_eq_one {s : finset α} {f : α → β} {a : α} (hp : ∏ x in s, f x = 1)
(h1 : ∀ x ∈ s, x ≠ a → f x = 1) : ∀ x ∈ s, f x = 1 :=
begin
intros x hx,
classical,
by_cases h : x = a,
{ rw h,
rw h at hx,
rw [←prod_subset (singleton_subset_iff.2 hx)
(λ t ht ha, h1 t ht (not_mem_singleton.1 ha)),
prod_singleton] at hp,
exact hp },
{ exact h1 x hx h }
end
lemma prod_pow_boole [decidable_eq α] (s : finset α) (f : α → β) (a : α) :
(∏ x in s, (f x)^(ite (a = x) 1 0)) = ite (a ∈ s) (f a) 1 :=
by simp
end comm_monoid
/-- If `f = g = h` everywhere but at `i`, where `f i = g i + h i`, then the product of `f` over `s`
is the sum of the products of `g` and `h`. -/
lemma prod_add_prod_eq [comm_semiring β] {s : finset α} {i : α} {f g h : α → β}
(hi : i ∈ s) (h1 : g i + h i = f i) (h2 : ∀ j ∈ s, j ≠ i → g j = f j)
(h3 : ∀ j ∈ s, j ≠ i → h j = f j) : ∏ i in s, g i + ∏ i in s, h i = ∏ i in s, f i :=
by { classical, simp_rw [prod_eq_mul_prod_diff_singleton hi, ← h1, right_distrib],
congr' 2; apply prod_congr rfl; simpa }
lemma card_eq_sum_ones (s : finset α) : s.card = ∑ _ in s, 1 :=
by simp
lemma sum_const_nat {m : ℕ} {f : α → ℕ} (h₁ : ∀ x ∈ s, f x = m) :
(∑ x in s, f x) = card s * m :=
begin
rw [← nat.nsmul_eq_mul, ← sum_const],
apply sum_congr rfl h₁
end
@[simp]
lemma sum_boole {s : finset α} {p : α → Prop} [non_assoc_semiring β] {hp : decidable_pred p} :
(∑ x in s, if p x then (1 : β) else (0 : β)) = (s.filter p).card :=
by simp [sum_ite]
lemma sum_comp [add_comm_monoid β] [decidable_eq γ] (f : γ → β) (g : α → γ) :
∑ a in s, f (g a) = ∑ b in s.image g, (s.filter (λ a, g a = b)).card • (f b) :=
@prod_comp (multiplicative β) _ _ _ _ _ _ _
attribute [to_additive "The sum of the composition of functions `f` and `g`, is the sum
over `b ∈ s.image g` of `f b` times of the cardinality of the fibre of `b`. See also
`finset.sum_image`."] prod_comp
lemma eq_sum_range_sub [add_comm_group β] (f : ℕ → β) (n : ℕ) :
f n = f 0 + ∑ i in range n, (f (i+1) - f i) :=
by rw [finset.sum_range_sub, add_sub_cancel'_right]
lemma eq_sum_range_sub' [add_comm_group β] (f : ℕ → β) (n : ℕ) :
f n = ∑ i in range (n + 1), if i = 0 then f 0 else f i - f (i - 1) :=
begin
conv_lhs { rw [finset.eq_sum_range_sub f] },
simp [finset.sum_range_succ', add_comm]
end
section opposite
open opposite
/-- Moving to the opposite additive commutative monoid commutes with summing. -/
@[simp] lemma op_sum [add_comm_monoid β] {s : finset α} (f : α → β) :
op (∑ x in s, f x) = ∑ x in s, op (f x) :=
(op_add_equiv : β ≃+ βᵒᵖ).map_sum _ _
@[simp] lemma unop_sum [add_comm_monoid β] {s : finset α} (f : α → βᵒᵖ) :
unop (∑ x in s, f x) = ∑ x in s, unop (f x) :=
(op_add_equiv : β ≃+ βᵒᵖ).symm.map_sum _ _
end opposite
section comm_group
variables [comm_group β]
@[simp, to_additive]
lemma prod_inv_distrib : (∏ x in s, (f x)⁻¹) = (∏ x in s, f x)⁻¹ :=
(monoid_hom.map_prod (comm_group.inv_monoid_hom : β →* β) f s).symm
@[to_additive zsmul_sum]
lemma prod_zpow (f : α → β) (s : finset α) (n : ℤ) :
(∏ a in s, f a) ^ n = ∏ a in s, (f a) ^ n :=
(zpow_group_hom n : β →* β).map_prod f s
end comm_group
@[simp] theorem card_sigma {σ : α → Type*} (s : finset α) (t : Π a, finset (σ a)) :
card (s.sigma t) = ∑ a in s, card (t a) :=
multiset.card_sigma _ _
lemma card_bUnion [decidable_eq β] {s : finset α} {t : α → finset β}
(h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → disjoint (t x) (t y)) :
(s.bUnion t).card = ∑ u in s, card (t u) :=
calc (s.bUnion t).card = ∑ i in s.bUnion t, 1 : by simp
... = ∑ a in s, ∑ i in t a, 1 : finset.sum_bUnion h
... = ∑ u in s, card (t u) : by simp
lemma card_bUnion_le [decidable_eq β] {s : finset α} {t : α → finset β} :
(s.bUnion t).card ≤ ∑ a in s, (t a).card :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (by simp)
(λ a s has ih,
calc ((insert a s).bUnion t).card ≤ (t a).card + (s.bUnion t).card :
by rw bUnion_insert; exact finset.card_union_le _ _
... ≤ ∑ a in insert a s, card (t a) :
by rw sum_insert has; exact add_le_add_left ih _)
theorem card_eq_sum_card_fiberwise [decidable_eq β] {f : α → β} {s : finset α} {t : finset β}
(H : ∀ x ∈ s, f x ∈ t) :
s.card = ∑ a in t, (s.filter (λ x, f x = a)).card :=
by simp only [card_eq_sum_ones, sum_fiberwise_of_maps_to H]
theorem card_eq_sum_card_image [decidable_eq β] (f : α → β) (s : finset α) :
s.card = ∑ a in s.image f, (s.filter (λ x, f x = a)).card :=
card_eq_sum_card_fiberwise (λ _, mem_image_of_mem _)
@[simp] lemma sum_sub_distrib [add_comm_group β] :
∑ x in s, (f x - g x) = (∑ x in s, f x) - (∑ x in s, g x) :=
by simpa only [sub_eq_add_neg] using sum_add_distrib.trans (congr_arg _ sum_neg_distrib)
section prod_eq_zero
variables [comm_monoid_with_zero β]
lemma prod_eq_zero (ha : a ∈ s) (h : f a = 0) : (∏ x in s, f x) = 0 :=
by { haveI := classical.dec_eq α, rw [←prod_erase_mul _ _ ha, h, mul_zero] }
lemma prod_boole {s : finset α} {p : α → Prop} [decidable_pred p] :
∏ i in s, ite (p i) (1 : β) (0 : β) = ite (∀ i ∈ s, p i) 1 0 :=
begin
split_ifs,
{ apply prod_eq_one,
intros i hi,
rw if_pos (h i hi) },
{ push_neg at h,
rcases h with ⟨i, hi, hq⟩,
apply prod_eq_zero hi,
rw [if_neg hq] },
end
variables [nontrivial β] [no_zero_divisors β]
lemma prod_eq_zero_iff : (∏ x in s, f x) = 0 ↔ (∃ a ∈ s, f a = 0) :=
begin
classical,
apply finset.induction_on s,
exact ⟨not.elim one_ne_zero, λ ⟨_, H, _⟩, H.elim⟩,
assume a s ha ih,
rw [prod_insert ha, mul_eq_zero, bex_def, exists_mem_insert, ih, ← bex_def]
end
theorem prod_ne_zero_iff : (∏ x in s, f x) ≠ 0 ↔ (∀ a ∈ s, f a ≠ 0) :=
by { rw [ne, prod_eq_zero_iff], push_neg }
end prod_eq_zero
section comm_group_with_zero
variables [comm_group_with_zero β]
@[simp]
lemma prod_inv_distrib' : (∏ x in s, (f x)⁻¹) = (∏ x in s, f x)⁻¹ :=
begin
classical,
by_cases h : ∃ x ∈ s, f x = 0,
{ simpa [prod_eq_zero_iff.mpr h, prod_eq_zero_iff] using h },
{ push_neg at h,
have h' := prod_ne_zero_iff.mpr h,
have hf : ∀ x ∈ s, (f x)⁻¹ * f x = 1 := λ x hx, inv_mul_cancel (h x hx),
apply mul_right_cancel₀ h',
simp [h, h', ← finset.prod_mul_distrib, prod_congr rfl hf] }
end
end comm_group_with_zero
@[to_additive]
lemma prod_unique_nonempty {α β : Type*} [comm_monoid β] [unique α]
(s : finset α) (f : α → β) (h : s.nonempty) :
(∏ x in s, f x) = f (default α) :=
begin
obtain ⟨a, ha⟩ := h,
have : s = {a},
{ ext b,
simpa [subsingleton.elim a b] using ha },
rw [this, finset.prod_singleton, subsingleton.elim a (default α)]
end
end finset
namespace fintype
open finset
/-- `fintype.prod_bijective` is a variant of `finset.prod_bij` that accepts `function.bijective`.
See `function.bijective.prod_comp` for a version without `h`. -/
@[to_additive "`fintype.sum_equiv` is a variant of `finset.sum_bij` that accepts
`function.bijective`.
See `function.bijective.sum_comp` for a version without `h`. "]
lemma prod_bijective {α β M : Type*} [fintype α] [fintype β] [comm_monoid M]
(e : α → β) (he : function.bijective e) (f : α → M) (g : β → M) (h : ∀ x, f x = g (e x)) :
∏ x : α, f x = ∏ x : β, g x :=
prod_bij
(λ x _, e x)
(λ x _, mem_univ (e x))
(λ x _, h x)
(λ x x' _ _ h, he.injective h)
(λ y _, (he.surjective y).imp $ λ a h, ⟨mem_univ _, h.symm⟩)
/-- `fintype.prod_equiv` is a specialization of `finset.prod_bij` that
automatically fills in most arguments.
See `equiv.prod_comp` for a version without `h`.
-/
@[to_additive "`fintype.sum_equiv` is a specialization of `finset.sum_bij` that
automatically fills in most arguments.
See `equiv.sum_comp` for a version without `h`.
"]
lemma prod_equiv {α β M : Type*} [fintype α] [fintype β] [comm_monoid M]
(e : α ≃ β) (f : α → M) (g : β → M) (h : ∀ x, f x = g (e x)) :
∏ x : α, f x = ∏ x : β, g x :=
prod_bijective e e.bijective f g h
@[to_additive]
lemma prod_finset_coe [comm_monoid β] :
∏ (i : (s : set α)), f i = ∏ i in s, f i :=
(finset.prod_subtype s (λ _, iff.rfl) f).symm
@[to_additive]
lemma prod_unique {α β : Type*} [comm_monoid β] [unique α] (f : α → β) :
(∏ x : α, f x) = f (default α) :=
by rw [univ_unique, prod_singleton]
@[to_additive] lemma prod_empty {α β : Type*} [comm_monoid β] [is_empty α] (f : α → β) :
(∏ x : α, f x) = 1 :=
by rw [eq_empty_of_is_empty (univ : finset α), finset.prod_empty]
@[to_additive]
lemma prod_subsingleton {α β : Type*} [comm_monoid β] [subsingleton α] (f : α → β) (a : α) :
(∏ x : α, f x) = f a :=
begin
haveI : unique α := unique_of_subsingleton a,
convert prod_unique f
end
@[to_additive]
lemma prod_subtype_mul_prod_subtype {α β : Type*} [fintype α] [comm_monoid β]
(p : α → Prop) (f : α → β) [decidable_pred p] :
(∏ (i : {x // p x}), f i) * (∏ i : {x // ¬ p x}, f i) = ∏ i, f i :=
begin
classical,
let s := {x | p x}.to_finset,
rw [← finset.prod_subtype s, ← finset.prod_subtype sᶜ],
{ exact finset.prod_mul_prod_compl _ _ },
{ simp },
{ simp }
end
end fintype
namespace list
@[to_additive] lemma prod_to_finset {M : Type*} [decidable_eq α] [comm_monoid M]
(f : α → M) : ∀ {l : list α} (hl : l.nodup), l.to_finset.prod f = (l.map f).prod
| [] _ := by simp
| (a :: l) hl := let ⟨not_mem, hl⟩ := list.nodup_cons.mp hl in
by simp [finset.prod_insert (mt list.mem_to_finset.mp not_mem), prod_to_finset hl]
end list
namespace multiset
variables [decidable_eq α]
@[simp] lemma to_finset_sum_count_eq (s : multiset α) :
(∑ a in s.to_finset, s.count a) = s.card :=
multiset.induction_on s rfl
(assume a s ih,
calc (∑ x in to_finset (a ::ₘ s), count x (a ::ₘ s)) =
∑ x in to_finset (a ::ₘ s), ((if x = a then 1 else 0) + count x s) :
finset.sum_congr rfl $ λ _ _, by split_ifs;
[simp only [h, count_cons_self, nat.one_add], simp only [count_cons_of_ne h, zero_add]]
... = card (a ::ₘ s) :
begin
by_cases a ∈ s.to_finset,
{ have : ∑ x in s.to_finset, ite (x = a) 1 0 = ∑ x in {a}, ite (x = a) 1 0,
{ rw [finset.sum_ite_eq', if_pos h, finset.sum_singleton, if_pos rfl], },
rw [to_finset_cons, finset.insert_eq_of_mem h, finset.sum_add_distrib, ih, this,
finset.sum_singleton, if_pos rfl, add_comm, card_cons] },
{ have ha : a ∉ s, by rwa mem_to_finset at h,
have : ∑ x in to_finset s, ite (x = a) 1 0 = ∑ x in to_finset s, 0, from
finset.sum_congr rfl (λ x hx, if_neg $ by rintro rfl; cc),
rw [to_finset_cons, finset.sum_insert h, if_pos rfl, finset.sum_add_distrib, this,
finset.sum_const_zero, ih, count_eq_zero_of_not_mem ha, zero_add, add_comm, card_cons] }
end)
lemma count_sum' {s : finset β} {a : α} {f : β → multiset α} :
count a (∑ x in s, f x) = ∑ x in s, count a (f x) :=
by { dunfold finset.sum, rw count_sum }
@[simp] lemma to_finset_sum_count_nsmul_eq (s : multiset α) :
(∑ a in s.to_finset, s.count a • {a}) = s :=
begin
apply ext', intro b,
rw count_sum',
have h : count b s = count b (count b s • {b}),
{ rw [count_nsmul, count_singleton_self, mul_one] },
rw h, clear h,
apply finset.sum_eq_single b,
{ intros c h hcb, rw count_nsmul, convert mul_zero (count c s),
apply count_eq_zero.mpr, exact finset.not_mem_singleton.mpr (ne.symm hcb) },
{ intro hb, rw [count_eq_zero_of_not_mem (mt mem_to_finset.2 hb), count_nsmul, zero_mul]}
end
theorem exists_smul_of_dvd_count (s : multiset α) {k : ℕ}
(h : ∀ (a : α), a ∈ s → k ∣ multiset.count a s) :
∃ (u : multiset α), s = k • u :=
begin
use ∑ a in s.to_finset, (s.count a / k) • {a},
have h₂ : ∑ (x : α) in s.to_finset, k • (count x s / k) • ({x} : multiset α) =
∑ (x : α) in s.to_finset, count x s • {x},
{ apply finset.sum_congr rfl,
intros x hx,
rw [← mul_nsmul, nat.mul_div_cancel' (h x (mem_to_finset.mp hx))] },
rw [← finset.sum_nsmul, h₂, to_finset_sum_count_nsmul_eq]
end
end multiset
@[simp, norm_cast] lemma nat.cast_sum [add_comm_monoid β] [has_one β] (s : finset α) (f : α → ℕ) :
↑(∑ x in s, f x : ℕ) = (∑ x in s, (f x : β)) :=
(nat.cast_add_monoid_hom β).map_sum f s
@[simp, norm_cast] lemma int.cast_sum [add_comm_group β] [has_one β] (s : finset α) (f : α → ℤ) :
↑(∑ x in s, f x : ℤ) = (∑ x in s, (f x : β)) :=
(int.cast_add_hom β).map_sum f s
@[simp, norm_cast] lemma nat.cast_prod {R : Type*} [comm_semiring R] (f : α → ℕ) (s : finset α) :
(↑∏ i in s, f i : R) = ∏ i in s, f i :=
(nat.cast_ring_hom R).map_prod _ _
@[simp, norm_cast] lemma int.cast_prod {R : Type*} [comm_ring R] (f : α → ℤ) (s : finset α) :
(↑∏ i in s, f i : R) = ∏ i in s, f i :=
(int.cast_ring_hom R).map_prod _ _
@[simp, norm_cast] lemma units.coe_prod {M : Type*} [comm_monoid M] (f : α → units M)
(s : finset α) : (↑∏ i in s, f i : M) = ∏ i in s, f i :=
(units.coe_hom M).map_prod _ _
lemma nat_abs_sum_le {ι : Type*} (s : finset ι) (f : ι → ℤ) :
(∑ i in s, f i).nat_abs ≤ ∑ i in s, (f i).nat_abs :=
begin
classical,
apply finset.induction_on s,
{ simp only [finset.sum_empty, int.nat_abs_zero] },
{ intros i s his IH,
simp only [his, finset.sum_insert, not_false_iff],
exact (int.nat_abs_add_le _ _).trans (add_le_add le_rfl IH) }
end
|
aa864192b00acaf1635a1f59429a5d9fd0cce64d | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/tactic/omega/coeffs.lean | 866d68d6519bd3d22158df0180cb2ac172f260d4 | [
"Apache-2.0"
] | permissive | Lix0120/mathlib | 0020745240315ed0e517cbf32e738d8f9811dd80 | e14c37827456fc6707f31b4d1d16f1f3a3205e91 | refs/heads/master | 1,673,102,855,024 | 1,604,151,044,000 | 1,604,151,044,000 | 308,930,245 | 0 | 0 | Apache-2.0 | 1,604,164,710,000 | 1,604,163,547,000 | null | UTF-8 | Lean | false | false | 10,628 | lean | /-
Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Seul Baek
-/
/-
Non-constant terms of linear constraints are represented
by storing their coefficients in integer lists.
-/
import data.list.func
import tactic.ring
import tactic.omega.misc
namespace omega
namespace coeffs
open list.func
variable {v : nat → int}
/-- `val_between v as l o` is the value (under valuation `v`) of the term
obtained taking the term represented by `(0, as)` and dropping all
subterms that include variables outside the range `[l,l+o)` -/
@[simp] def val_between (v : nat → int) (as : list int) (l : nat) : nat → int
| 0 := 0
| (o+1) := (val_between o) + (get (l+o) as * v (l+o))
@[simp] lemma val_between_nil {l : nat} :
∀ m, val_between v [] l m = 0
| 0 := by simp only [val_between]
| (m+1) :=
by simp only [val_between_nil m, omega.coeffs.val_between,
get_nil, zero_add, zero_mul, int.default_eq_zero]
/-- Evaluation of the nonconstant component of a normalized linear arithmetic term. -/
def val (v : nat → int) (as : list int) : int :=
val_between v as 0 as.length
@[simp] lemma val_nil : val v [] = 0 := rfl
lemma val_between_eq_of_le {as : list int} {l : nat} :
∀ m, as.length ≤ l + m →
val_between v as l m = val_between v as l (as.length - l)
| 0 h1 :=
begin rw (nat.sub_eq_zero_iff_le.elim_right _), apply h1 end
| (m+1) h1 :=
begin
rw le_iff_eq_or_lt at h1, cases h1,
{ rw [h1, add_comm l, nat.add_sub_cancel] },
have h2 : list.length as ≤ l + m,
{ rw ← nat.lt_succ_iff, apply h1 },
simpa [ get_eq_default_of_le _ h2, zero_mul, add_zero,
val_between ] using val_between_eq_of_le _ h2
end
lemma val_eq_of_le {as : list int} {k : nat} :
as.length ≤ k → val v as = val_between v as 0 k :=
begin
intro h1, unfold val,
rw [val_between_eq_of_le k _], refl,
rw zero_add, exact h1
end
lemma val_between_eq_val_between
{v w : nat → int} {as bs : list int} {l : nat} :
∀ {m}, (∀ x, l ≤ x → x < l + m → v x = w x) →
(∀ x, l ≤ x → x < l + m → get x as = get x bs) →
val_between v as l m = val_between w bs l m
| 0 h1 h2 := rfl
| (m+1) h1 h2 :=
begin
unfold val_between,
have h3 : l + m < l + (m + 1),
{ rw ← add_assoc, apply lt_add_one },
apply fun_mono_2,
apply val_between_eq_val_between; intros x h4 h5,
{ apply h1 _ h4 (lt_trans h5 h3) },
{ apply h2 _ h4 (lt_trans h5 h3) },
rw [h1 _ _ h3, h2 _ _ h3];
apply nat.le_add_right
end
open_locale list.func
lemma val_between_set {a : int} {l n : nat} :
∀ {m}, l ≤ n → n < l + m → val_between v ([] {n ↦ a}) l m = a * v n
| 0 h1 h2 :=
begin exfalso, apply lt_irrefl l (lt_of_le_of_lt h1 h2) end
| (m+1) h1 h2 :=
begin
rw [← add_assoc, nat.lt_succ_iff, le_iff_eq_or_lt] at h2,
cases h2; unfold val_between,
{ have h3 : val_between v ([] {l + m ↦ a}) l m = 0,
{ apply @eq.trans _ _ (val_between v [] l m),
{ apply val_between_eq_val_between,
{ intros, refl },
{ intros x h4 h5, rw [get_nil,
get_set_eq_of_ne, get_nil],
apply ne_of_lt h5 } },
apply val_between_nil },
rw h2,
simp only [h3, zero_add, list.func.get_set] },
{ have h3 : l + m ≠ n,
{ apply ne_of_gt h2 },
rw [@val_between_set m h1 h2, get_set_eq_of_ne _ _ h3],
simp only [h3, get_nil, add_zero, zero_mul, int.default_eq_zero] }
end
@[simp] lemma val_set {m : nat} {a : int} :
val v ([] {m ↦ a}) = a * v m :=
begin
apply val_between_set, apply zero_le,
apply lt_of_lt_of_le (lt_add_one _),
simp only [length_set, zero_add, le_max_right],
apply_instance,
end
lemma val_between_neg {as : list int} {l : nat} :
∀ {o}, val_between v (neg as) l o = -(val_between v as l o)
| 0 := rfl
| (o+1) :=
begin
unfold val_between,
rw [neg_add, neg_mul_eq_neg_mul],
apply fun_mono_2,
apply val_between_neg,
apply fun_mono_2 _ rfl,
apply get_neg
end
@[simp] lemma val_neg {as : list int} :
val v (neg as) = -(val v as) :=
by simpa only [val, length_neg] using val_between_neg
lemma val_between_add {is js : list int} {l : nat} :
∀ m, val_between v (add is js) l m =
(val_between v is l m) + (val_between v js l m)
| 0 := rfl
| (m+1) :=
by { simp only [val_between, val_between_add m,
list.func.get, get_add], ring }
@[simp] lemma val_add {is js : list int} :
val v (add is js) = (val v is) + (val v js) :=
begin
unfold val,
rw val_between_add, apply fun_mono_2;
apply val_between_eq_of_le;
rw [zero_add, length_add],
apply le_max_left, apply le_max_right
end
lemma val_between_sub {is js : list int} {l : nat} :
∀ m, val_between v (sub is js) l m =
(val_between v is l m) - (val_between v js l m)
| 0 := rfl
| (m+1) :=
by { simp only [val_between, val_between_sub m,
list.func.get, get_sub], ring }
@[simp] lemma val_sub {is js : list int} :
val v (sub is js) = (val v is) - (val v js) :=
begin
unfold val,
rw val_between_sub,
apply fun_mono_2;
apply val_between_eq_of_le;
rw [zero_add, length_sub],
apply le_max_left,
apply le_max_right
end
/-- `val_except k v as` is the value (under valuation `v`) of the term
obtained taking the term represented by `(0, as)` and dropping the
subterm that includes the `k`th variable. -/
def val_except (k : nat) (v : nat → int) (as) :=
val_between v as 0 k + val_between v as (k+1) (as.length - (k+1))
lemma val_except_eq_val_except
{k : nat} {is js : list int} {v w : nat → int} :
(∀ x ≠ k, v x = w x) → (∀ x ≠ k, get x is = get x js) →
val_except k v is = val_except k w js :=
begin
intros h1 h2, unfold val_except,
apply fun_mono_2,
{ apply val_between_eq_val_between;
intros x h3 h4;
[ {apply h1}, {apply h2} ];
apply ne_of_lt;
rw zero_add at h4;
apply h4 },
{ repeat { rw ← val_between_eq_of_le
((max is.length js.length) - (k+1)) },
{ apply val_between_eq_val_between;
intros x h3 h4;
[ {apply h1}, {apply h2} ];
apply ne.symm;
apply ne_of_lt;
rw nat.lt_iff_add_one_le;
exact h3 },
repeat { rw add_comm,
apply le_trans _ (nat.le_sub_add _ _),
{ apply le_max_right <|> apply le_max_left } } }
end
open_locale omega
lemma val_except_update_set
{n : nat} {as : list int} {i j : int} :
val_except n (v⟨n ↦ i⟩) (as {n ↦ j}) = val_except n v as :=
by apply val_except_eq_val_except update_eq_of_ne (get_set_eq_of_ne _)
lemma val_between_add_val_between {as : list int} {l m : nat} :
∀ {n}, val_between v as l m + val_between v as (l+m) n =
val_between v as l (m+n)
| 0 := by simp only [val_between, add_zero]
| (n+1) :=
begin
rw ← add_assoc,
unfold val_between,
rw add_assoc,
rw ← @val_between_add_val_between n,
ring,
end
lemma val_except_add_eq (n : nat) {as : list int} :
(val_except n v as) + ((get n as) * (v n)) = val v as :=
begin
unfold val_except, unfold val,
by_cases h1 : n + 1 ≤ as.length,
{ have h4 := @val_between_add_val_between v as 0 (n+1) (as.length - (n+1)),
have h5 : n + 1 + (as.length - (n + 1)) = as.length,
{ rw [add_comm, nat.sub_add_cancel h1] },
rw h5 at h4, apply eq.trans _ h4,
simp only [val_between, zero_add], ring },
have h2 : (list.length as - (n + 1)) = 0,
{ apply nat.sub_eq_zero_of_le
(le_trans (not_lt.1 h1) (nat.le_add_right _ _)) },
have h3 : val_between v as 0 (list.length as) =
val_between v as 0 (n + 1),
{ simpa only [val] using @val_eq_of_le v as (n+1)
(le_trans (not_lt.1 h1) (nat.le_add_right _ _)) },
simp only [add_zero, val_between, zero_add, h2, h3]
end
@[simp] lemma val_between_map_mul {i : int} {as: list int} {l : nat} :
∀ {m}, val_between v (list.map ((*) i) as) l m = i * val_between v as l m
| 0 := by simp only [val_between, mul_zero, list.map]
| (m+1) :=
begin
unfold val_between,
rw [@val_between_map_mul m, mul_add],
apply fun_mono_2 rfl,
by_cases h1 : l + m < as.length,
{ rw [get_map h1, mul_assoc] },
rw not_lt at h1,
rw [get_eq_default_of_le, get_eq_default_of_le];
try {simp}; apply h1
end
lemma forall_val_dvd_of_forall_mem_dvd {i : int} {as : list int} :
(∀ x ∈ as, i ∣ x) → (∀ n, i ∣ get n as) | h1 n :=
by { apply forall_val_of_forall_mem _ h1,
apply dvd_zero }
lemma dvd_val_between {i} {as: list int} {l : nat} :
∀ {m}, (∀ x ∈ as, i ∣ x) → (i ∣ val_between v as l m)
| 0 h1 := dvd_zero _
| (m+1) h1 :=
begin
unfold val_between,
apply dvd_add,
apply dvd_val_between h1,
apply dvd_mul_of_dvd_left,
by_cases h2 : get (l+m) as = 0,
{ rw h2, apply dvd_zero },
apply h1, apply mem_get_of_ne_zero h2
end
lemma dvd_val {as : list int} {i : int} :
(∀ x ∈ as, i ∣ x) → (i ∣ val v as) := by apply dvd_val_between
@[simp] lemma val_between_map_div
{as: list int} {i : int} {l : nat} (h1 : ∀ x ∈ as, i ∣ x) :
∀ {m}, val_between v (list.map (λ x, x / i) as) l m = (val_between v as l m) / i
| 0 := by simp only [int.zero_div, val_between, list.map]
| (m+1) :=
begin
unfold val_between,
rw [@val_between_map_div m, int.add_div_of_dvd (dvd_val_between h1)],
apply fun_mono_2 rfl,
{ apply calc get (l + m) (list.map (λ (x : ℤ), x / i) as) * v (l + m)
= ((get (l + m) as) / i) * v (l + m) :
begin
apply fun_mono_2 _ rfl,
rw get_map',
apply int.zero_div
end
... = get (l + m) as * v (l + m) / i :
begin
repeat {rw mul_comm _ (v (l+m))},
rw int.mul_div_assoc,
apply forall_val_dvd_of_forall_mem_dvd h1
end },
apply dvd_mul_of_dvd_left,
apply forall_val_dvd_of_forall_mem_dvd h1,
end
@[simp] lemma val_map_div {as : list int} {i : int} :
(∀ x ∈ as, i ∣ x) → val v (list.map (λ x, x / i) as) = (val v as) / i :=
by {intro h1, simpa only [val, list.length_map] using val_between_map_div h1}
lemma val_between_eq_zero {is: list int} {l : nat} :
∀ {m}, (∀ x : int, x ∈ is → x = 0) → val_between v is l m = 0
| 0 h1 := rfl
| (m+1) h1 :=
begin
have h2 := @forall_val_of_forall_mem _ _ is (λ x, x = 0) rfl h1,
simpa only [val_between, h2 (l+m), zero_mul, add_zero]
using @val_between_eq_zero m h1,
end
lemma val_eq_zero {is : list int} :
(∀ x : int, x ∈ is → x = 0) → val v is = 0 :=
by apply val_between_eq_zero
end coeffs
end omega
|
d16f7ba96569d8976ccd0e1460868339581d5d80 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/probability/independence/basic.lean | d7827c9312e8bb5332ed091c5966a51beac0ef84 | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 44,951 | lean | /-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import measure_theory.constructions.pi
/-!
# Independence of sets of sets and measure spaces (σ-algebras)
* A family of sets of sets `π : ι → set (set Ω)` is independent with respect to a measure `μ` if for
any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`,
`μ (⋂ i in s, f i) = ∏ i in s, μ (f i) `. It will be used for families of π-systems.
* A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a
measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they
define is independent. I.e., `m : ι → measurable_space Ω` is independent with respect to a
measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i in s, μ (f i)`.
* Independence of sets (or events in probabilistic parlance) is defined as independence of the
measurable space structures they generate: a set `s` generates the measurable space structure with
measurable sets `∅, s, sᶜ, univ`.
* Independence of functions (or random variables) is also defined as independence of the measurable
space structures they generate: a function `f` for which we have a measurable space `m` on the
codomain generates `measurable_space.comap f m`.
## Main statements
* `Indep_sets.Indep`: if π-systems are independent as sets of sets, then the
measurable space structures they generate are independent.
* `indep_sets.indep`: variant with two π-systems.
## Implementation notes
We provide one main definition of independence:
* `Indep_sets`: independence of a family of sets of sets `pi : ι → set (set Ω)`.
Three other independence notions are defined using `Indep_sets`:
* `Indep`: independence of a family of measurable space structures `m : ι → measurable_space Ω`,
* `Indep_set`: independence of a family of sets `s : ι → set Ω`,
* `Indep_fun`: independence of a family of functions. For measurable spaces
`m : Π (i : ι), measurable_space (β i)`, we consider functions `f : Π (i : ι), Ω → β i`.
Additionally, we provide four corresponding statements for two measurable space structures (resp.
sets of sets, sets, functions) instead of a family. These properties are denoted by the same names
as for a family, but without a capital letter, for example `indep_fun` is the version of `Indep_fun`
for two functions.
The definition of independence for `Indep_sets` uses finite sets (`finset`). An alternative and
equivalent way of defining independence would have been to use countable sets.
TODO: prove that equivalence.
Most of the definitions and lemma in this file list all variables instead of using the `variables`
keyword at the beginning of a section, for example
`lemma indep.symm {Ω} {m₁ m₂ : measurable_space Ω} [measurable_space Ω] {μ : measure Ω} ...` .
This is intentional, to be able to control the order of the `measurable_space` variables. Indeed
when defining `μ` in the example above, the measurable space used is the last one defined, here
`[measurable_space Ω]`, and not `m₁` or `m₂`.
## References
* Williams, David. Probability with martingales. Cambridge university press, 1991.
Part A, Chapter 4.
-/
open measure_theory measurable_space
open_locale big_operators measure_theory ennreal
namespace probability_theory
variables {Ω ι : Type*}
section definitions
/-- A family of sets of sets `π : ι → set (set Ω)` is independent with respect to a measure `μ` if
for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `μ (⋂ i in s, f i) = ∏ i in s, μ (f i) `.
It will be used for families of pi_systems. -/
def Indep_sets [measurable_space Ω] (π : ι → set (set Ω)) (μ : measure Ω . volume_tac) :
Prop :=
∀ (s : finset ι) {f : ι → set Ω} (H : ∀ i, i ∈ s → f i ∈ π i), μ (⋂ i ∈ s, f i) = ∏ i in s, μ (f i)
/-- Two sets of sets `s₁, s₂` are independent with respect to a measure `μ` if for any sets
`t₁ ∈ p₁, t₂ ∈ s₂`, then `μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/
def indep_sets [measurable_space Ω] (s1 s2 : set (set Ω)) (μ : measure Ω . volume_tac) : Prop :=
∀ t1 t2 : set Ω, t1 ∈ s1 → t2 ∈ s2 → μ (t1 ∩ t2) = μ t1 * μ t2
/-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a
measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they
define is independent. `m : ι → measurable_space Ω` is independent with respect to measure `μ` if
for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i in s, μ (f i) `. -/
def Indep (m : ι → measurable_space Ω) [measurable_space Ω] (μ : measure Ω . volume_tac) :
Prop :=
Indep_sets (λ x, {s | measurable_set[m x] s}) μ
/-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a
measure `μ` (defined on a third σ-algebra) if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`,
`μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/
def indep (m₁ m₂ : measurable_space Ω) [measurable_space Ω] (μ : measure Ω . volume_tac) :
Prop :=
indep_sets {s | measurable_set[m₁] s} {s | measurable_set[m₂] s} μ
/-- A family of sets is independent if the family of measurable space structures they generate is
independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/
def Indep_set [measurable_space Ω] (s : ι → set Ω) (μ : measure Ω . volume_tac) : Prop :=
Indep (λ i, generate_from {s i}) μ
/-- Two sets are independent if the two measurable space structures they generate are independent.
For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/
def indep_set [measurable_space Ω] (s t : set Ω) (μ : measure Ω . volume_tac) : Prop :=
indep (generate_from {s}) (generate_from {t}) μ
/-- A family of functions defined on the same space `Ω` and taking values in possibly different
spaces, each with a measurable space structure, is independent if the family of measurable space
structures they generate on `Ω` is independent. For a function `g` with codomain having measurable
space structure `m`, the generated measurable space structure is `measurable_space.comap g m`. -/
def Indep_fun [measurable_space Ω] {β : ι → Type*} (m : Π (x : ι), measurable_space (β x))
(f : Π (x : ι), Ω → β x) (μ : measure Ω . volume_tac) : Prop :=
Indep (λ x, measurable_space.comap (f x) (m x)) μ
/-- Two functions are independent if the two measurable space structures they generate are
independent. For a function `f` with codomain having measurable space structure `m`, the generated
measurable space structure is `measurable_space.comap f m`. -/
def indep_fun {β γ} [measurable_space Ω] [mβ : measurable_space β] [mγ : measurable_space γ]
(f : Ω → β) (g : Ω → γ) (μ : measure Ω . volume_tac) : Prop :=
indep (measurable_space.comap f mβ) (measurable_space.comap g mγ) μ
end definitions
section indep
@[symm] lemma indep_sets.symm {s₁ s₂ : set (set Ω)} [measurable_space Ω] {μ : measure Ω}
(h : indep_sets s₁ s₂ μ) :
indep_sets s₂ s₁ μ :=
by { intros t1 t2 ht1 ht2, rw [set.inter_comm, mul_comm], exact h t2 t1 ht2 ht1, }
@[symm] lemma indep.symm {m₁ m₂ : measurable_space Ω} [measurable_space Ω] {μ : measure Ω}
(h : indep m₁ m₂ μ) :
indep m₂ m₁ μ :=
indep_sets.symm h
lemma indep_bot_right (m' : measurable_space Ω) {m : measurable_space Ω}
{μ : measure Ω} [is_probability_measure μ] :
indep m' ⊥ μ :=
begin
intros s t hs ht,
rw [set.mem_set_of_eq, measurable_space.measurable_set_bot_iff] at ht,
cases ht,
{ rw [ht, set.inter_empty, measure_empty, mul_zero], },
{ rw [ht, set.inter_univ, measure_univ, mul_one], },
end
lemma indep_bot_left (m' : measurable_space Ω) {m : measurable_space Ω}
{μ : measure Ω} [is_probability_measure μ] :
indep ⊥ m' μ :=
(indep_bot_right m').symm
lemma indep_set_empty_right {m : measurable_space Ω} {μ : measure Ω} [is_probability_measure μ]
(s : set Ω) :
indep_set s ∅ μ :=
by { simp only [indep_set, generate_from_singleton_empty], exact indep_bot_right _, }
lemma indep_set_empty_left {m : measurable_space Ω} {μ : measure Ω} [is_probability_measure μ]
(s : set Ω) :
indep_set ∅ s μ :=
(indep_set_empty_right s).symm
lemma indep_sets_of_indep_sets_of_le_left {s₁ s₂ s₃: set (set Ω)} [measurable_space Ω]
{μ : measure Ω} (h_indep : indep_sets s₁ s₂ μ) (h31 : s₃ ⊆ s₁) :
indep_sets s₃ s₂ μ :=
λ t1 t2 ht1 ht2, h_indep t1 t2 (set.mem_of_subset_of_mem h31 ht1) ht2
lemma indep_sets_of_indep_sets_of_le_right {s₁ s₂ s₃: set (set Ω)} [measurable_space Ω]
{μ : measure Ω} (h_indep : indep_sets s₁ s₂ μ) (h32 : s₃ ⊆ s₂) :
indep_sets s₁ s₃ μ :=
λ t1 t2 ht1 ht2, h_indep t1 t2 ht1 (set.mem_of_subset_of_mem h32 ht2)
lemma indep_of_indep_of_le_left {m₁ m₂ m₃: measurable_space Ω} [measurable_space Ω]
{μ : measure Ω} (h_indep : indep m₁ m₂ μ) (h31 : m₃ ≤ m₁) :
indep m₃ m₂ μ :=
λ t1 t2 ht1 ht2, h_indep t1 t2 (h31 _ ht1) ht2
lemma indep_of_indep_of_le_right {m₁ m₂ m₃: measurable_space Ω} [measurable_space Ω]
{μ : measure Ω} (h_indep : indep m₁ m₂ μ) (h32 : m₃ ≤ m₂) :
indep m₁ m₃ μ :=
λ t1 t2 ht1 ht2, h_indep t1 t2 ht1 (h32 _ ht2)
lemma indep_sets.union [measurable_space Ω] {s₁ s₂ s' : set (set Ω)} {μ : measure Ω}
(h₁ : indep_sets s₁ s' μ) (h₂ : indep_sets s₂ s' μ) :
indep_sets (s₁ ∪ s₂) s' μ :=
begin
intros t1 t2 ht1 ht2,
cases (set.mem_union _ _ _).mp ht1 with ht1₁ ht1₂,
{ exact h₁ t1 t2 ht1₁ ht2, },
{ exact h₂ t1 t2 ht1₂ ht2, },
end
@[simp] lemma indep_sets.union_iff [measurable_space Ω] {s₁ s₂ s' : set (set Ω)}
{μ : measure Ω} :
indep_sets (s₁ ∪ s₂) s' μ ↔ indep_sets s₁ s' μ ∧ indep_sets s₂ s' μ :=
⟨λ h, ⟨indep_sets_of_indep_sets_of_le_left h (set.subset_union_left s₁ s₂),
indep_sets_of_indep_sets_of_le_left h (set.subset_union_right s₁ s₂)⟩,
λ h, indep_sets.union h.left h.right⟩
lemma indep_sets.Union [measurable_space Ω] {s : ι → set (set Ω)} {s' : set (set Ω)}
{μ : measure Ω} (hyp : ∀ n, indep_sets (s n) s' μ) :
indep_sets (⋃ n, s n) s' μ :=
begin
intros t1 t2 ht1 ht2,
rw set.mem_Union at ht1,
cases ht1 with n ht1,
exact hyp n t1 t2 ht1 ht2,
end
lemma indep_sets.bUnion [measurable_space Ω] {s : ι → set (set Ω)} {s' : set (set Ω)}
{μ : measure Ω} {u : set ι} (hyp : ∀ n ∈ u, indep_sets (s n) s' μ) :
indep_sets (⋃ n ∈ u, s n) s' μ :=
begin
intros t1 t2 ht1 ht2,
simp_rw set.mem_Union at ht1,
rcases ht1 with ⟨n, hpn, ht1⟩,
exact hyp n hpn t1 t2 ht1 ht2,
end
lemma indep_sets.inter [measurable_space Ω] {s₁ s' : set (set Ω)} (s₂ : set (set Ω))
{μ : measure Ω} (h₁ : indep_sets s₁ s' μ) :
indep_sets (s₁ ∩ s₂) s' μ :=
λ t1 t2 ht1 ht2, h₁ t1 t2 ((set.mem_inter_iff _ _ _).mp ht1).left ht2
lemma indep_sets.Inter [measurable_space Ω] {s : ι → set (set Ω)} {s' : set (set Ω)}
{μ : measure Ω} (h : ∃ n, indep_sets (s n) s' μ) :
indep_sets (⋂ n, s n) s' μ :=
by {intros t1 t2 ht1 ht2, cases h with n h, exact h t1 t2 (set.mem_Inter.mp ht1 n) ht2 }
lemma indep_sets.bInter [measurable_space Ω] {s : ι → set (set Ω)} {s' : set (set Ω)}
{μ : measure Ω} {u : set ι} (h : ∃ n ∈ u, indep_sets (s n) s' μ) :
indep_sets (⋂ n ∈ u, s n) s' μ :=
begin
intros t1 t2 ht1 ht2,
rcases h with ⟨n, hn, h⟩,
exact h t1 t2 (set.bInter_subset_of_mem hn ht1) ht2,
end
lemma indep_sets_singleton_iff [measurable_space Ω] {s t : set Ω} {μ : measure Ω} :
indep_sets {s} {t} μ ↔ μ (s ∩ t) = μ s * μ t :=
⟨λ h, h s t rfl rfl,
λ h s1 t1 hs1 ht1, by rwa [set.mem_singleton_iff.mp hs1, set.mem_singleton_iff.mp ht1]⟩
end indep
/-! ### Deducing `indep` from `Indep` -/
section from_Indep_to_indep
lemma Indep_sets.indep_sets {s : ι → set (set Ω)} [measurable_space Ω] {μ : measure Ω}
(h_indep : Indep_sets s μ) {i j : ι} (hij : i ≠ j) :
indep_sets (s i) (s j) μ :=
begin
classical,
intros t₁ t₂ ht₁ ht₂,
have hf_m : ∀ (x : ι), x ∈ {i, j} → (ite (x=i) t₁ t₂) ∈ s x,
{ intros x hx,
cases finset.mem_insert.mp hx with hx hx,
{ simp [hx, ht₁], },
{ simp [finset.mem_singleton.mp hx, hij.symm, ht₂], }, },
have h1 : t₁ = ite (i = i) t₁ t₂, by simp only [if_true, eq_self_iff_true],
have h2 : t₂ = ite (j = i) t₁ t₂, by simp only [hij.symm, if_false],
have h_inter : (⋂ (t : ι) (H : t ∈ ({i, j} : finset ι)), ite (t = i) t₁ t₂)
= (ite (i = i) t₁ t₂) ∩ (ite (j = i) t₁ t₂),
by simp only [finset.set_bInter_singleton, finset.set_bInter_insert],
have h_prod : (∏ (t : ι) in ({i, j} : finset ι), μ (ite (t = i) t₁ t₂))
= μ (ite (i = i) t₁ t₂) * μ (ite (j = i) t₁ t₂),
by simp only [hij, finset.prod_singleton, finset.prod_insert, not_false_iff,
finset.mem_singleton],
rw h1,
nth_rewrite 1 h2,
nth_rewrite 3 h2,
rw [← h_inter, ← h_prod, h_indep {i, j} hf_m],
end
lemma Indep.indep {m : ι → measurable_space Ω} [measurable_space Ω] {μ : measure Ω}
(h_indep : Indep m μ) {i j : ι} (hij : i ≠ j) :
indep (m i) (m j) μ :=
begin
change indep_sets ((λ x, measurable_set[m x]) i) ((λ x, measurable_set[m x]) j) μ,
exact Indep_sets.indep_sets h_indep hij,
end
lemma Indep_fun.indep_fun {m₀ : measurable_space Ω} {μ : measure Ω} {β : ι → Type*}
{m : Π x, measurable_space (β x)} {f : Π i, Ω → β i} (hf_Indep : Indep_fun m f μ)
{i j : ι} (hij : i ≠ j) :
indep_fun (f i) (f j) μ :=
hf_Indep.indep hij
end from_Indep_to_indep
/-!
## π-system lemma
Independence of measurable spaces is equivalent to independence of generating π-systems.
-/
section from_measurable_spaces_to_sets_of_sets
/-! ### Independence of measurable space structures implies independence of generating π-systems -/
lemma Indep.Indep_sets [measurable_space Ω] {μ : measure Ω} {m : ι → measurable_space Ω}
{s : ι → set (set Ω)} (hms : ∀ n, m n = generate_from (s n))
(h_indep : Indep m μ) :
Indep_sets s μ :=
λ S f hfs, h_indep S $ λ x hxS,
((hms x).symm ▸ measurable_set_generate_from (hfs x hxS) : measurable_set[m x] (f x))
lemma indep.indep_sets [measurable_space Ω] {μ : measure Ω} {s1 s2 : set (set Ω)}
(h_indep : indep (generate_from s1) (generate_from s2) μ) :
indep_sets s1 s2 μ :=
λ t1 t2 ht1 ht2, h_indep t1 t2 (measurable_set_generate_from ht1) (measurable_set_generate_from ht2)
end from_measurable_spaces_to_sets_of_sets
section from_pi_systems_to_measurable_spaces
/-! ### Independence of generating π-systems implies independence of measurable space structures -/
private lemma indep_sets.indep_aux {m2 : measurable_space Ω}
{m : measurable_space Ω} {μ : measure Ω} [is_probability_measure μ] {p1 p2 : set (set Ω)}
(h2 : m2 ≤ m) (hp2 : is_pi_system p2) (hpm2 : m2 = generate_from p2)
(hyp : indep_sets p1 p2 μ) {t1 t2 : set Ω} (ht1 : t1 ∈ p1) (ht2m : measurable_set[m2] t2) :
μ (t1 ∩ t2) = μ t1 * μ t2 :=
begin
let μ_inter := μ.restrict t1,
let ν := (μ t1) • μ,
have h_univ : μ_inter set.univ = ν set.univ,
by rw [measure.restrict_apply_univ, measure.smul_apply, smul_eq_mul, measure_univ, mul_one],
haveI : is_finite_measure μ_inter := @restrict.is_finite_measure Ω _ t1 μ ⟨measure_lt_top μ t1⟩,
rw [set.inter_comm, ← measure.restrict_apply (h2 t2 ht2m)],
refine ext_on_measurable_space_of_generate_finite m p2 (λ t ht, _) h2 hpm2 hp2 h_univ ht2m,
have ht2 : measurable_set[m] t,
{ refine h2 _ _,
rw hpm2,
exact measurable_set_generate_from ht, },
rw [measure.restrict_apply ht2, measure.smul_apply, set.inter_comm],
exact hyp t1 t ht1 ht,
end
lemma indep_sets.indep {m1 m2 : measurable_space Ω} {m : measurable_space Ω}
{μ : measure Ω} [is_probability_measure μ] {p1 p2 : set (set Ω)} (h1 : m1 ≤ m) (h2 : m2 ≤ m)
(hp1 : is_pi_system p1) (hp2 : is_pi_system p2) (hpm1 : m1 = generate_from p1)
(hpm2 : m2 = generate_from p2) (hyp : indep_sets p1 p2 μ) :
indep m1 m2 μ :=
begin
intros t1 t2 ht1 ht2,
let μ_inter := μ.restrict t2,
let ν := (μ t2) • μ,
have h_univ : μ_inter set.univ = ν set.univ,
by rw [measure.restrict_apply_univ, measure.smul_apply, smul_eq_mul, measure_univ, mul_one],
haveI : is_finite_measure μ_inter := @restrict.is_finite_measure Ω _ t2 μ ⟨measure_lt_top μ t2⟩,
rw [mul_comm, ← measure.restrict_apply (h1 t1 ht1)],
refine ext_on_measurable_space_of_generate_finite m p1 (λ t ht, _) h1 hpm1 hp1 h_univ ht1,
have ht1 : measurable_set[m] t,
{ refine h1 _ _,
rw hpm1,
exact measurable_set_generate_from ht, },
rw [measure.restrict_apply ht1, measure.smul_apply, smul_eq_mul, mul_comm],
exact indep_sets.indep_aux h2 hp2 hpm2 hyp ht ht2,
end
lemma indep_sets.indep' {m : measurable_space Ω}
{μ : measure Ω} [is_probability_measure μ] {p1 p2 : set (set Ω)}
(hp1m : ∀ s ∈ p1, measurable_set s) (hp2m : ∀ s ∈ p2, measurable_set s)
(hp1 : is_pi_system p1) (hp2 : is_pi_system p2) (hyp : indep_sets p1 p2 μ) :
indep (generate_from p1) (generate_from p2) μ :=
hyp.indep (generate_from_le hp1m) (generate_from_le hp2m) hp1 hp2 rfl rfl
variables {m0 : measurable_space Ω} {μ : measure Ω}
lemma indep_sets_pi_Union_Inter_of_disjoint [is_probability_measure μ]
{s : ι → set (set Ω)} {S T : set ι}
(h_indep : Indep_sets s μ) (hST : disjoint S T) :
indep_sets (pi_Union_Inter s S) (pi_Union_Inter s T) μ :=
begin
rintros t1 t2 ⟨p1, hp1, f1, ht1_m, ht1_eq⟩ ⟨p2, hp2, f2, ht2_m, ht2_eq⟩,
classical,
let g := λ i, ite (i ∈ p1) (f1 i) set.univ ∩ ite (i ∈ p2) (f2 i) set.univ,
have h_P_inter : μ (t1 ∩ t2) = ∏ n in p1 ∪ p2, μ (g n),
{ have hgm : ∀ i ∈ p1 ∪ p2, g i ∈ s i,
{ intros i hi_mem_union,
rw finset.mem_union at hi_mem_union,
cases hi_mem_union with hi1 hi2,
{ have hi2 : i ∉ p2 := λ hip2, set.disjoint_left.mp hST (hp1 hi1) (hp2 hip2),
simp_rw [g, if_pos hi1, if_neg hi2, set.inter_univ],
exact ht1_m i hi1, },
{ have hi1 : i ∉ p1 := λ hip1, set.disjoint_right.mp hST (hp2 hi2) (hp1 hip1),
simp_rw [g, if_neg hi1, if_pos hi2, set.univ_inter],
exact ht2_m i hi2, }, },
have h_p1_inter_p2 : ((⋂ x ∈ p1, f1 x) ∩ ⋂ x ∈ p2, f2 x)
= ⋂ i ∈ p1 ∪ p2, (ite (i ∈ p1) (f1 i) set.univ ∩ ite (i ∈ p2) (f2 i) set.univ),
{ ext1 x,
simp only [set.mem_ite_univ_right, set.mem_inter_iff, set.mem_Inter, finset.mem_union],
exact ⟨λ h i _, ⟨h.1 i, h.2 i⟩,
λ h, ⟨λ i hi, (h i (or.inl hi)).1 hi, λ i hi, (h i (or.inr hi)).2 hi⟩⟩, },
rw [ht1_eq, ht2_eq, h_p1_inter_p2, ← h_indep _ hgm], },
have h_μg : ∀ n, μ (g n) = (ite (n ∈ p1) (μ (f1 n)) 1) * (ite (n ∈ p2) (μ (f2 n)) 1),
{ intro n,
simp_rw g,
split_ifs,
{ exact absurd rfl (set.disjoint_iff_forall_ne.mp hST _ (hp1 h) _ (hp2 h_1)), },
all_goals { simp only [measure_univ, one_mul, mul_one, set.inter_univ, set.univ_inter], }, },
simp_rw [h_P_inter, h_μg, finset.prod_mul_distrib,
finset.prod_ite_mem (p1 ∪ p2) p1 (λ x, μ (f1 x)),
finset.union_inter_cancel_left, finset.prod_ite_mem (p1 ∪ p2) p2 (λ x, μ (f2 x)),
finset.union_inter_cancel_right, ht1_eq, ← h_indep p1 ht1_m, ht2_eq, ← h_indep p2 ht2_m],
end
lemma Indep_set.indep_generate_from_of_disjoint [is_probability_measure μ] {s : ι → set Ω}
(hsm : ∀ n, measurable_set (s n)) (hs : Indep_set s μ) (S T : set ι) (hST : disjoint S T) :
indep (generate_from {t | ∃ n ∈ S, s n = t}) (generate_from {t | ∃ k ∈ T, s k = t}) μ :=
begin
rw [← generate_from_pi_Union_Inter_singleton_left,
← generate_from_pi_Union_Inter_singleton_left],
refine indep_sets.indep'
(λ t ht, generate_from_pi_Union_Inter_le _ _ _ _ (measurable_set_generate_from ht))
(λ t ht, generate_from_pi_Union_Inter_le _ _ _ _ (measurable_set_generate_from ht))
_ _ _,
{ exact λ k, generate_from_le $ λ t ht, (set.mem_singleton_iff.1 ht).symm ▸ hsm k, },
{ exact λ k, generate_from_le $ λ t ht, (set.mem_singleton_iff.1 ht).symm ▸ hsm k, },
{ exact is_pi_system_pi_Union_Inter _ (λ k, is_pi_system.singleton _) _, },
{ exact is_pi_system_pi_Union_Inter _ (λ k, is_pi_system.singleton _) _, },
{ classical,
exact indep_sets_pi_Union_Inter_of_disjoint (Indep.Indep_sets (λ n, rfl) hs) hST, },
end
lemma indep_supr_of_disjoint [is_probability_measure μ] {m : ι → measurable_space Ω}
(h_le : ∀ i, m i ≤ m0) (h_indep : Indep m μ) {S T : set ι} (hST : disjoint S T) :
indep (⨆ i ∈ S, m i) (⨆ i ∈ T, m i) μ :=
begin
refine indep_sets.indep (supr₂_le (λ i _, h_le i)) (supr₂_le (λ i _, h_le i)) _ _
(generate_from_pi_Union_Inter_measurable_set m S).symm
(generate_from_pi_Union_Inter_measurable_set m T).symm _,
{ exact is_pi_system_pi_Union_Inter _ (λ n, @is_pi_system_measurable_set Ω (m n)) _, },
{ exact is_pi_system_pi_Union_Inter _ (λ n, @is_pi_system_measurable_set Ω (m n)) _ , },
{ classical,
exact indep_sets_pi_Union_Inter_of_disjoint h_indep hST, },
end
lemma indep_supr_of_directed_le {Ω} {m : ι → measurable_space Ω}
{m' m0 : measurable_space Ω} {μ : measure Ω} [is_probability_measure μ]
(h_indep : ∀ i, indep (m i) m' μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0)
(hm : directed (≤) m) :
indep (⨆ i, m i) m' μ :=
begin
let p : ι → set (set Ω) := λ n, {t | measurable_set[m n] t},
have hp : ∀ n, is_pi_system (p n) := λ n, @is_pi_system_measurable_set Ω (m n),
have h_gen_n : ∀ n, m n = generate_from (p n),
from λ n, (@generate_from_measurable_set Ω (m n)).symm,
have hp_supr_pi : is_pi_system (⋃ n, p n) := is_pi_system_Union_of_directed_le p hp hm,
let p' := {t : set Ω | measurable_set[m'] t},
have hp'_pi : is_pi_system p' := @is_pi_system_measurable_set Ω m',
have h_gen' : m' = generate_from p' := (@generate_from_measurable_set Ω m').symm,
-- the π-systems defined are independent
have h_pi_system_indep : indep_sets (⋃ n, p n) p' μ,
{ refine indep_sets.Union _,
simp_rw [h_gen_n, h_gen'] at h_indep,
exact λ n, (h_indep n).indep_sets, },
-- now go from π-systems to σ-algebras
refine indep_sets.indep (supr_le h_le) h_le' hp_supr_pi hp'_pi _ h_gen' h_pi_system_indep,
exact (generate_from_Union_measurable_set _).symm,
end
lemma Indep_set.indep_generate_from_lt [preorder ι] [is_probability_measure μ]
{s : ι → set Ω} (hsm : ∀ n, measurable_set (s n)) (hs : Indep_set s μ) (i : ι) :
indep (generate_from {s i}) (generate_from {t | ∃ j < i, s j = t}) μ :=
begin
convert hs.indep_generate_from_of_disjoint hsm {i} {j | j < i}
(set.disjoint_singleton_left.mpr (lt_irrefl _)),
simp only [set.mem_singleton_iff, exists_prop, exists_eq_left, set.set_of_eq_eq_singleton'],
end
lemma Indep_set.indep_generate_from_le [linear_order ι] [is_probability_measure μ]
{s : ι → set Ω} (hsm : ∀ n, measurable_set (s n)) (hs : Indep_set s μ)
(i : ι) {k : ι} (hk : i < k) :
indep (generate_from {s k}) (generate_from {t | ∃ j ≤ i, s j = t}) μ :=
begin
convert hs.indep_generate_from_of_disjoint hsm {k} {j | j ≤ i}
(set.disjoint_singleton_left.mpr hk.not_le),
simp only [set.mem_singleton_iff, exists_prop, exists_eq_left, set.set_of_eq_eq_singleton'],
end
lemma Indep_set.indep_generate_from_le_nat [is_probability_measure μ]
{s : ℕ → set Ω} (hsm : ∀ n, measurable_set (s n)) (hs : Indep_set s μ) (n : ℕ):
indep (generate_from {s (n + 1)}) (generate_from {t | ∃ k ≤ n, s k = t}) μ :=
hs.indep_generate_from_le hsm _ n.lt_succ_self
lemma indep_supr_of_monotone [semilattice_sup ι] {Ω} {m : ι → measurable_space Ω}
{m' m0 : measurable_space Ω} {μ : measure Ω} [is_probability_measure μ]
(h_indep : ∀ i, indep (m i) m' μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0) (hm : monotone m) :
indep (⨆ i, m i) m' μ :=
indep_supr_of_directed_le h_indep h_le h_le' (monotone.directed_le hm)
lemma indep_supr_of_antitone [semilattice_inf ι] {Ω} {m : ι → measurable_space Ω}
{m' m0 : measurable_space Ω} {μ : measure Ω} [is_probability_measure μ]
(h_indep : ∀ i, indep (m i) m' μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0) (hm : antitone m) :
indep (⨆ i, m i) m' μ :=
indep_supr_of_directed_le h_indep h_le h_le' (directed_of_inf hm)
lemma Indep_sets.pi_Union_Inter_of_not_mem {π : ι → set (set Ω)} {a : ι} {S : finset ι}
(hp_ind : Indep_sets π μ) (haS : a ∉ S) :
indep_sets (pi_Union_Inter π S) (π a) μ :=
begin
rintros t1 t2 ⟨s, hs_mem, ft1, hft1_mem, ht1_eq⟩ ht2_mem_pia,
rw [finset.coe_subset] at hs_mem,
classical,
let f := λ n, ite (n = a) t2 (ite (n ∈ s) (ft1 n) set.univ),
have h_f_mem : ∀ n ∈ insert a s, f n ∈ π n,
{ intros n hn_mem_insert,
simp_rw f,
cases (finset.mem_insert.mp hn_mem_insert) with hn_mem hn_mem,
{ simp [hn_mem, ht2_mem_pia], },
{ have hn_ne_a : n ≠ a, by { rintro rfl, exact haS (hs_mem hn_mem), },
simp [hn_ne_a, hn_mem, hft1_mem n hn_mem], }, },
have h_f_mem_pi : ∀ n ∈ s, f n ∈ π n, from λ x hxS, h_f_mem x (by simp [hxS]),
have h_t1 : t1 = ⋂ n ∈ s, f n,
{ suffices h_forall : ∀ n ∈ s, f n = ft1 n,
{ rw ht1_eq,
congr' with n x,
congr' with hns y,
simp only [(h_forall n hns).symm], },
intros n hnS,
have hn_ne_a : n ≠ a, by { rintro rfl, exact haS (hs_mem hnS), },
simp_rw [f, if_pos hnS, if_neg hn_ne_a], },
have h_μ_t1 : μ t1 = ∏ n in s, μ (f n), by rw [h_t1, ← hp_ind s h_f_mem_pi],
have h_t2 : t2 = f a, by { simp_rw [f], simp, },
have h_μ_inter : μ (t1 ∩ t2) = ∏ n in insert a s, μ (f n),
{ have h_t1_inter_t2 : t1 ∩ t2 = ⋂ n ∈ insert a s, f n,
by rw [h_t1, h_t2, finset.set_bInter_insert, set.inter_comm],
rw [h_t1_inter_t2, ← hp_ind (insert a s) h_f_mem], },
have has : a ∉ s := λ has_mem, haS (hs_mem has_mem),
rw [h_μ_inter, finset.prod_insert has, h_t2, mul_comm, h_μ_t1],
end
/-- The measurable space structures generated by independent pi-systems are independent. -/
theorem Indep_sets.Indep [is_probability_measure μ] (m : ι → measurable_space Ω)
(h_le : ∀ i, m i ≤ m0) (π : ι → set (set Ω)) (h_pi : ∀ n, is_pi_system (π n))
(h_generate : ∀ i, m i = generate_from (π i)) (h_ind : Indep_sets π μ) :
Indep m μ :=
begin
classical,
refine finset.induction _ _,
{ simp only [measure_univ, implies_true_iff, set.Inter_false, set.Inter_univ, finset.prod_empty,
eq_self_iff_true], },
intros a S ha_notin_S h_rec f hf_m,
have hf_m_S : ∀ x ∈ S, measurable_set[m x] (f x) := λ x hx, hf_m x (by simp [hx]),
rw [finset.set_bInter_insert, finset.prod_insert ha_notin_S, ← h_rec hf_m_S],
let p := pi_Union_Inter π S,
set m_p := generate_from p with hS_eq_generate,
have h_indep : indep m_p (m a) μ,
{ have hp : is_pi_system p := is_pi_system_pi_Union_Inter π h_pi S,
have h_le' : ∀ i, generate_from (π i) ≤ m0 := λ i, (h_generate i).symm.trans_le (h_le i),
have hm_p : m_p ≤ m0 := generate_from_pi_Union_Inter_le π h_le' S,
exact indep_sets.indep hm_p (h_le a) hp (h_pi a) hS_eq_generate (h_generate a)
(h_ind.pi_Union_Inter_of_not_mem ha_notin_S), },
refine h_indep.symm (f a) (⋂ n ∈ S, f n) (hf_m a (finset.mem_insert_self a S)) _,
have h_le_p : ∀ i ∈ S, m i ≤ m_p,
{ intros n hn,
rw [hS_eq_generate, h_generate n],
exact le_generate_from_pi_Union_Inter S hn, },
have h_S_f : ∀ i ∈ S, measurable_set[m_p] (f i) := λ i hi, (h_le_p i hi) (f i) (hf_m_S i hi),
exact S.measurable_set_bInter h_S_f,
end
end from_pi_systems_to_measurable_spaces
section indep_set
/-! ### Independence of measurable sets
We prove the following equivalences on `indep_set`, for measurable sets `s, t`.
* `indep_set s t μ ↔ μ (s ∩ t) = μ s * μ t`,
* `indep_set s t μ ↔ indep_sets {s} {t} μ`.
-/
variables {s t : set Ω} (S T : set (set Ω))
lemma indep_set_iff_indep_sets_singleton {m0 : measurable_space Ω}
(hs_meas : measurable_set s) (ht_meas : measurable_set t)
(μ : measure Ω . volume_tac) [is_probability_measure μ] :
indep_set s t μ ↔ indep_sets {s} {t} μ :=
⟨indep.indep_sets, λ h, indep_sets.indep
(generate_from_le (λ u hu, by rwa set.mem_singleton_iff.mp hu))
(generate_from_le (λ u hu, by rwa set.mem_singleton_iff.mp hu)) (is_pi_system.singleton s)
(is_pi_system.singleton t) rfl rfl h⟩
lemma indep_set_iff_measure_inter_eq_mul {m0 : measurable_space Ω}
(hs_meas : measurable_set s) (ht_meas : measurable_set t)
(μ : measure Ω . volume_tac) [is_probability_measure μ] :
indep_set s t μ ↔ μ (s ∩ t) = μ s * μ t :=
(indep_set_iff_indep_sets_singleton hs_meas ht_meas μ).trans indep_sets_singleton_iff
lemma indep_sets.indep_set_of_mem {m0 : measurable_space Ω} (hs : s ∈ S) (ht : t ∈ T)
(hs_meas : measurable_set s) (ht_meas : measurable_set t) (μ : measure Ω . volume_tac)
[is_probability_measure μ] (h_indep : indep_sets S T μ) :
indep_set s t μ :=
(indep_set_iff_measure_inter_eq_mul hs_meas ht_meas μ).mpr (h_indep s t hs ht)
lemma indep.indep_set_of_measurable_set {m₁ m₂ m0 : measurable_space Ω} {μ : measure Ω}
(h_indep : indep m₁ m₂ μ) {s t : set Ω} (hs : measurable_set[m₁] s) (ht : measurable_set[m₂] t) :
indep_set s t μ :=
begin
refine λ s' t' hs' ht', h_indep s' t' _ _,
{ refine generate_from_induction (λ u, measurable_set[m₁] u) {s} _ _ _ _ hs',
{ simp only [hs, set.mem_singleton_iff, set.mem_set_of_eq, forall_eq], },
{ exact @measurable_set.empty _ m₁, },
{ exact λ u hu, hu.compl, },
{ exact λ f hf, measurable_set.Union hf, }, },
{ refine generate_from_induction (λ u, measurable_set[m₂] u) {t} _ _ _ _ ht',
{ simp only [ht, set.mem_singleton_iff, set.mem_set_of_eq, forall_eq], },
{ exact @measurable_set.empty _ m₂, },
{ exact λ u hu, hu.compl, },
{ exact λ f hf, measurable_set.Union hf, },},
end
lemma indep_iff_forall_indep_set (m₁ m₂ : measurable_space Ω) {m0 : measurable_space Ω}
(μ : measure Ω) :
indep m₁ m₂ μ ↔ ∀ s t, measurable_set[m₁] s → measurable_set[m₂] t → indep_set s t μ :=
⟨λ h, λ s t hs ht, h.indep_set_of_measurable_set hs ht,
λ h s t hs ht, h s t hs ht s t (measurable_set_generate_from (set.mem_singleton s))
(measurable_set_generate_from (set.mem_singleton t))⟩
end indep_set
section indep_fun
/-! ### Independence of random variables
-/
variables {β β' γ γ' : Type*} {mΩ : measurable_space Ω} {μ : measure Ω} {f : Ω → β} {g : Ω → β'}
lemma indep_fun_iff_measure_inter_preimage_eq_mul
{mβ : measurable_space β} {mβ' : measurable_space β'} :
indep_fun f g μ
↔ ∀ s t, measurable_set s → measurable_set t
→ μ (f ⁻¹' s ∩ g ⁻¹' t) = μ (f ⁻¹' s) * μ (g ⁻¹' t) :=
begin
split; intro h,
{ refine λ s t hs ht, h (f ⁻¹' s) (g ⁻¹' t) ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩, },
{ rintros _ _ ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩, exact h s t hs ht, },
end
lemma Indep_fun_iff_measure_inter_preimage_eq_mul {ι : Type*} {β : ι → Type*}
(m : Π x, measurable_space (β x)) (f : Π i, Ω → β i) :
Indep_fun m f μ
↔ ∀ (S : finset ι) {sets : Π i : ι, set (β i)} (H : ∀ i, i ∈ S → measurable_set[m i] (sets i)),
μ (⋂ i ∈ S, (f i) ⁻¹' (sets i)) = ∏ i in S, μ ((f i) ⁻¹' (sets i)) :=
begin
refine ⟨λ h S sets h_meas, h _ (λ i hi_mem, ⟨sets i, h_meas i hi_mem, rfl⟩), _⟩,
intros h S setsΩ h_meas,
classical,
let setsβ : (Π i : ι, set (β i)) := λ i,
dite (i ∈ S) (λ hi_mem, (h_meas i hi_mem).some) (λ _, set.univ),
have h_measβ : ∀ i ∈ S, measurable_set[m i] (setsβ i),
{ intros i hi_mem,
simp_rw [setsβ, dif_pos hi_mem],
exact (h_meas i hi_mem).some_spec.1, },
have h_preim : ∀ i ∈ S, setsΩ i = (f i) ⁻¹' (setsβ i),
{ intros i hi_mem,
simp_rw [setsβ, dif_pos hi_mem],
exact (h_meas i hi_mem).some_spec.2.symm, },
have h_left_eq : μ (⋂ i ∈ S, setsΩ i) = μ (⋂ i ∈ S, (f i) ⁻¹' (setsβ i)),
{ congr' with i x,
simp only [set.mem_Inter],
split; intros h hi_mem; specialize h hi_mem,
{ rwa h_preim i hi_mem at h, },
{ rwa h_preim i hi_mem, }, },
have h_right_eq : (∏ i in S, μ (setsΩ i)) = ∏ i in S, μ ((f i) ⁻¹' (setsβ i)),
{ refine finset.prod_congr rfl (λ i hi_mem, _),
rw h_preim i hi_mem, },
rw [h_left_eq, h_right_eq],
exact h S h_measβ,
end
lemma indep_fun_iff_indep_set_preimage {mβ : measurable_space β} {mβ' : measurable_space β'}
[is_probability_measure μ] (hf : measurable f) (hg : measurable g) :
indep_fun f g μ ↔ ∀ s t, measurable_set s → measurable_set t → indep_set (f ⁻¹' s) (g ⁻¹' t) μ :=
begin
refine indep_fun_iff_measure_inter_preimage_eq_mul.trans _,
split; intros h s t hs ht; specialize h s t hs ht,
{ rwa indep_set_iff_measure_inter_eq_mul (hf hs) (hg ht) μ, },
{ rwa ← indep_set_iff_measure_inter_eq_mul (hf hs) (hg ht) μ, },
end
@[symm] lemma indep_fun.symm {mβ : measurable_space β} {f g : Ω → β} (hfg : indep_fun f g μ) :
indep_fun g f μ :=
hfg.symm
lemma indep_fun.ae_eq {mβ : measurable_space β} {f g f' g' : Ω → β}
(hfg : indep_fun f g μ) (hf : f =ᵐ[μ] f') (hg : g =ᵐ[μ] g') :
indep_fun f' g' μ :=
begin
rintro _ _ ⟨A, hA, rfl⟩ ⟨B, hB, rfl⟩,
have h1 : f ⁻¹' A =ᵐ[μ] f' ⁻¹' A := hf.fun_comp A,
have h2 : g ⁻¹' B =ᵐ[μ] g' ⁻¹' B := hg.fun_comp B,
rw [← measure_congr h1, ← measure_congr h2, ← measure_congr (h1.inter h2)],
exact hfg _ _ ⟨_, hA, rfl⟩ ⟨_, hB, rfl⟩
end
lemma indep_fun.comp {mβ : measurable_space β} {mβ' : measurable_space β'}
{mγ : measurable_space γ} {mγ' : measurable_space γ'} {φ : β → γ} {ψ : β' → γ'}
(hfg : indep_fun f g μ) (hφ : measurable φ) (hψ : measurable ψ) :
indep_fun (φ ∘ f) (ψ ∘ g) μ :=
begin
rintro _ _ ⟨A, hA, rfl⟩ ⟨B, hB, rfl⟩,
apply hfg,
{ exact ⟨φ ⁻¹' A, hφ hA, set.preimage_comp.symm⟩ },
{ exact ⟨ψ ⁻¹' B, hψ hB, set.preimage_comp.symm⟩ }
end
/-- If `f` is a family of mutually independent random variables (`Indep_fun m f μ`) and `S, T` are
two disjoint finite index sets, then the tuple formed by `f i` for `i ∈ S` is independent of the
tuple `(f i)_i` for `i ∈ T`. -/
lemma Indep_fun.indep_fun_finset [is_probability_measure μ]
{ι : Type*} {β : ι → Type*} {m : Π i, measurable_space (β i)}
{f : Π i, Ω → β i} (S T : finset ι) (hST : disjoint S T) (hf_Indep : Indep_fun m f μ)
(hf_meas : ∀ i, measurable (f i)) :
indep_fun (λ a (i : S), f i a) (λ a (i : T), f i a) μ :=
begin
-- We introduce π-systems, build from the π-system of boxes which generates `measurable_space.pi`.
let πSβ := (set.pi (set.univ : set S) ''
(set.pi (set.univ : set S) (λ i, {s : set (β i) | measurable_set[m i] s}))),
let πS := {s : set Ω | ∃ t ∈ πSβ, (λ a (i : S), f i a) ⁻¹' t = s},
have hπS_pi : is_pi_system πS := is_pi_system_pi.comap (λ a i, f i a),
have hπS_gen : measurable_space.pi.comap (λ a (i : S), f i a) = generate_from πS,
{ rw [generate_from_pi.symm, comap_generate_from],
{ congr' with s,
simp only [set.mem_image, set.mem_set_of_eq, exists_prop], },
{ apply_instance } },
let πTβ := (set.pi (set.univ : set T) ''
(set.pi (set.univ : set T) (λ i, {s : set (β i) | measurable_set[m i] s}))),
let πT := {s : set Ω | ∃ t ∈ πTβ, (λ a (i : T), f i a) ⁻¹' t = s},
have hπT_pi : is_pi_system πT := is_pi_system_pi.comap (λ a i, f i a),
have hπT_gen : measurable_space.pi.comap (λ a (i : T), f i a) = generate_from πT,
{ rw [generate_from_pi.symm, comap_generate_from],
{ congr' with s,
simp only [set.mem_image, set.mem_set_of_eq, exists_prop], },
{ apply_instance } },
-- To prove independence, we prove independence of the generating π-systems.
refine indep_sets.indep (measurable.comap_le (measurable_pi_iff.mpr (λ i, hf_meas i)))
(measurable.comap_le (measurable_pi_iff.mpr (λ i, hf_meas i))) hπS_pi hπT_pi hπS_gen hπT_gen _,
rintros _ _ ⟨s, ⟨sets_s, hs1, hs2⟩, rfl⟩ ⟨t, ⟨sets_t, ht1, ht2⟩, rfl⟩,
simp only [set.mem_univ_pi, set.mem_set_of_eq] at hs1 ht1,
rw [← hs2, ← ht2],
classical,
let sets_s' : (Π i : ι, set (β i)) := λ i, dite (i ∈ S) (λ hi, sets_s ⟨i, hi⟩) (λ _, set.univ),
have h_sets_s'_eq : ∀ {i} (hi : i ∈ S), sets_s' i = sets_s ⟨i, hi⟩,
{ intros i hi, simp_rw [sets_s', dif_pos hi], },
have h_sets_s'_univ : ∀ {i} (hi : i ∈ T), sets_s' i = set.univ,
{ intros i hi, simp_rw [sets_s', dif_neg (finset.disjoint_right.mp hST hi)], },
let sets_t' : (Π i : ι, set (β i)) := λ i, dite (i ∈ T) (λ hi, sets_t ⟨i, hi⟩) (λ _, set.univ),
have h_sets_t'_univ : ∀ {i} (hi : i ∈ S), sets_t' i = set.univ,
{ intros i hi, simp_rw [sets_t', dif_neg (finset.disjoint_left.mp hST hi)], },
have h_meas_s' : ∀ i ∈ S, measurable_set (sets_s' i),
{ intros i hi, rw h_sets_s'_eq hi, exact hs1 _, },
have h_meas_t' : ∀ i ∈ T, measurable_set (sets_t' i),
{ intros i hi, simp_rw [sets_t', dif_pos hi], exact ht1 _, },
have h_eq_inter_S : (λ (ω : Ω) (i : ↥S), f ↑i ω) ⁻¹' set.pi set.univ sets_s
= ⋂ i ∈ S, (f i) ⁻¹' (sets_s' i),
{ ext1 x,
simp only [set.mem_preimage, set.mem_univ_pi, set.mem_Inter],
split; intro h,
{ intros i hi, rw [h_sets_s'_eq hi], exact h ⟨i, hi⟩, },
{ rintros ⟨i, hi⟩, specialize h i hi, rw [h_sets_s'_eq hi] at h, exact h, }, },
have h_eq_inter_T : (λ (ω : Ω) (i : ↥T), f ↑i ω) ⁻¹' set.pi set.univ sets_t
= ⋂ i ∈ T, (f i) ⁻¹' (sets_t' i),
{ ext1 x,
simp only [set.mem_preimage, set.mem_univ_pi, set.mem_Inter],
split; intro h,
{ intros i hi, simp_rw [sets_t', dif_pos hi], exact h ⟨i, hi⟩, },
{ rintros ⟨i, hi⟩, specialize h i hi, simp_rw [sets_t', dif_pos hi] at h, exact h, }, },
rw Indep_fun_iff_measure_inter_preimage_eq_mul at hf_Indep,
rw [h_eq_inter_S, h_eq_inter_T, hf_Indep S h_meas_s', hf_Indep T h_meas_t'],
have h_Inter_inter : (⋂ i ∈ S, (f i) ⁻¹' (sets_s' i)) ∩ (⋂ i ∈ T, (f i) ⁻¹' (sets_t' i))
= ⋂ i ∈ (S ∪ T), (f i) ⁻¹' (sets_s' i ∩ sets_t' i),
{ ext1 x,
simp only [set.mem_inter_iff, set.mem_Inter, set.mem_preimage, finset.mem_union],
split; intro h,
{ intros i hi,
cases hi,
{ rw h_sets_t'_univ hi, exact ⟨h.1 i hi, set.mem_univ _⟩, },
{ rw h_sets_s'_univ hi, exact ⟨set.mem_univ _, h.2 i hi⟩, }, },
{ exact ⟨λ i hi, (h i (or.inl hi)).1, λ i hi, (h i (or.inr hi)).2⟩, }, },
rw [h_Inter_inter, hf_Indep (S ∪ T)],
swap, { intros i hi_mem,
rw finset.mem_union at hi_mem,
cases hi_mem,
{ rw [h_sets_t'_univ hi_mem, set.inter_univ], exact h_meas_s' i hi_mem, },
{ rw [h_sets_s'_univ hi_mem, set.univ_inter], exact h_meas_t' i hi_mem, }, },
rw finset.prod_union hST,
congr' 1,
{ refine finset.prod_congr rfl (λ i hi, _),
rw [h_sets_t'_univ hi, set.inter_univ], },
{ refine finset.prod_congr rfl (λ i hi, _),
rw [h_sets_s'_univ hi, set.univ_inter], },
end
lemma Indep_fun.indep_fun_prod [is_probability_measure μ]
{ι : Type*} {β : ι → Type*} {m : Π i, measurable_space (β i)}
{f : Π i, Ω → β i} (hf_Indep : Indep_fun m f μ) (hf_meas : ∀ i, measurable (f i))
(i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
indep_fun (λ a, (f i a, f j a)) (f k) μ :=
begin
classical,
have h_right : f k = (λ p : (Π j : ({k} : finset ι), β j), p ⟨k, finset.mem_singleton_self k⟩)
∘ (λ a (j : ({k} : finset ι)), f j a) := rfl,
have h_meas_right : measurable
(λ p : (Π j : ({k} : finset ι), β j), p ⟨k, finset.mem_singleton_self k⟩),
from measurable_pi_apply ⟨k, finset.mem_singleton_self k⟩,
let s : finset ι := {i, j},
have h_left : (λ ω, (f i ω, f j ω))
= (λ p : (Π l : s, β l), (p ⟨i, finset.mem_insert_self i _⟩,
p ⟨j, finset.mem_insert_of_mem (finset.mem_singleton_self _)⟩))
∘ (λ a (j : s), f j a),
{ ext1 a,
simp only [prod.mk.inj_iff],
split; refl, },
have h_meas_left : measurable (λ p : (Π l : s, β l), (p ⟨i, finset.mem_insert_self i _⟩,
p ⟨j, finset.mem_insert_of_mem (finset.mem_singleton_self _)⟩)),
from measurable.prod (measurable_pi_apply ⟨i, finset.mem_insert_self i {j}⟩)
(measurable_pi_apply ⟨j, finset.mem_insert_of_mem (finset.mem_singleton_self j)⟩),
rw [h_left, h_right],
refine (hf_Indep.indep_fun_finset s {k} _ hf_meas).comp h_meas_left h_meas_right,
rw finset.disjoint_singleton_right,
simp only [finset.mem_insert, finset.mem_singleton, not_or_distrib],
exact ⟨hik.symm, hjk.symm⟩,
end
@[to_additive]
lemma Indep_fun.mul [is_probability_measure μ]
{ι : Type*} {β : Type*} {m : measurable_space β} [has_mul β] [has_measurable_mul₂ β]
{f : ι → Ω → β} (hf_Indep : Indep_fun (λ _, m) f μ) (hf_meas : ∀ i, measurable (f i))
(i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
indep_fun (f i * f j) (f k) μ :=
begin
have : indep_fun (λ ω, (f i ω, f j ω)) (f k) μ := hf_Indep.indep_fun_prod hf_meas i j k hik hjk,
change indep_fun ((λ p : β × β, p.fst * p.snd) ∘ (λ ω, (f i ω, f j ω))) (id ∘ (f k)) μ,
exact indep_fun.comp this (measurable_fst.mul measurable_snd) measurable_id,
end
@[to_additive]
lemma Indep_fun.indep_fun_finset_prod_of_not_mem [is_probability_measure μ]
{ι : Type*} {β : Type*} {m : measurable_space β} [comm_monoid β] [has_measurable_mul₂ β]
{f : ι → Ω → β} (hf_Indep : Indep_fun (λ _, m) f μ) (hf_meas : ∀ i, measurable (f i))
{s : finset ι} {i : ι} (hi : i ∉ s) :
indep_fun (∏ j in s, f j) (f i) μ :=
begin
classical,
have h_right : f i = (λ p : (Π j : ({i} : finset ι), β), p ⟨i, finset.mem_singleton_self i⟩)
∘ (λ a (j : ({i} : finset ι)), f j a) := rfl,
have h_meas_right : measurable
(λ p : (Π j : ({i} : finset ι), β), p ⟨i, finset.mem_singleton_self i⟩),
from measurable_pi_apply ⟨i, finset.mem_singleton_self i⟩,
have h_left : (∏ j in s, f j) = (λ p : (Π j : s, β), ∏ j, p j) ∘ (λ a (j : s), f j a),
{ ext1 a,
simp only [function.comp_app],
have : (∏ (j : ↥s), f ↑j a) = (∏ (j : ↥s), f ↑j) a, by rw finset.prod_apply,
rw [this, finset.prod_coe_sort], },
have h_meas_left : measurable (λ p : (Π j : s, β), ∏ j, p j),
from finset.univ.measurable_prod (λ (j : ↥s) (H : j ∈ finset.univ), measurable_pi_apply j),
rw [h_left, h_right],
exact (hf_Indep.indep_fun_finset s {i} (finset.disjoint_singleton_left.mpr hi).symm hf_meas).comp
h_meas_left h_meas_right,
end
@[to_additive]
lemma Indep_fun.indep_fun_prod_range_succ [is_probability_measure μ]
{β : Type*} {m : measurable_space β} [comm_monoid β] [has_measurable_mul₂ β]
{f : ℕ → Ω → β} (hf_Indep : Indep_fun (λ _, m) f μ) (hf_meas : ∀ i, measurable (f i))
(n : ℕ) :
indep_fun (∏ j in finset.range n, f j) (f n) μ :=
hf_Indep.indep_fun_finset_prod_of_not_mem hf_meas finset.not_mem_range_self
lemma Indep_set.Indep_fun_indicator [has_zero β] [has_one β] {m : measurable_space β}
{s : ι → set Ω} (hs : Indep_set s μ) :
Indep_fun (λ n, m) (λ n, (s n).indicator (λ ω, 1)) μ :=
begin
classical,
rw Indep_fun_iff_measure_inter_preimage_eq_mul,
rintro S π hπ,
simp_rw set.indicator_const_preimage_eq_union,
refine @hs S (λ i, ite (1 ∈ π i) (s i) ∅ ∪ ite ((0 : β) ∈ π i) (s i)ᶜ ∅) (λ i hi, _),
have hsi : measurable_set[generate_from {s i}] (s i),
from measurable_set_generate_from (set.mem_singleton _),
refine measurable_set.union (measurable_set.ite' (λ _, hsi) (λ _, _))
(measurable_set.ite' (λ _, hsi.compl) (λ _, _)),
{ exact @measurable_set.empty _ (generate_from {s i}), },
{ exact @measurable_set.empty _ (generate_from {s i}), },
end
end indep_fun
end probability_theory
|
4a7fcc083e8a529eb47b003cbea82c3b4f283463 | 82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7 | /src/Init/Data.lean | 450482db3d83fd8de5e43b4d2779af1456a42a2b | [
"Apache-2.0"
] | permissive | banksonian/lean4 | 3a2e6b0f1eb63aa56ff95b8d07b2f851072d54dc | 78da6b3aa2840693eea354a41e89fc5b212a5011 | refs/heads/master | 1,673,703,624,165 | 1,605,123,551,000 | 1,605,123,551,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 546 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Data.Basic
import Init.Data.Nat
import Init.Data.Char
import Init.Data.String
import Init.Data.List
import Init.Data.Int
import Init.Data.Array
import Init.Data.ByteArray
import Init.Data.FloatArray
import Init.Data.Fin
import Init.Data.UInt
import Init.Data.Float
import Init.Data.Option
import Init.Data.Random
import Init.Data.ToString
import Init.Data.Range
|
0c92e51b65ff9b6d656d2087719de157f9b391de | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/algebra/big_operators/ring.lean | b79af2e3a9b8f9bc9210746cdd4a47745e7a46cc | [
"Apache-2.0"
] | permissive | dupuisf/mathlib | 62de4ec6544bf3b79086afd27b6529acfaf2c1bb | 8582b06b0a5d06c33ee07d0bdf7c646cae22cf36 | refs/heads/master | 1,669,494,854,016 | 1,595,692,409,000 | 1,595,692,409,000 | 272,046,630 | 0 | 0 | Apache-2.0 | 1,592,066,143,000 | 1,592,066,142,000 | null | UTF-8 | Lean | false | false | 7,041 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import algebra.big_operators.basic
import data.finset.pi
import data.finset.powerset
/-!
# Results about big operators with values in a (semi)ring
We prove results about big operators that involve some interaction between
multiplicative and additive structures on the values being combined.
-/
universes u v w
open_locale big_operators
variables {α : Type u} {β : Type v} {γ : Type w}
namespace finset
variables {s s₁ s₂ : finset α} {a : α} {b : β} {f g : α → β}
section semiring
variables [semiring β]
lemma sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=
(s.sum_hom (λ x, x * b)).symm
lemma mul_sum : b * (∑ x in s, f x) = ∑ x in s, b * f x :=
(s.sum_hom _).symm
lemma sum_mul_boole [decidable_eq α] (s : finset α) (f : α → β) (a : α) :
(∑ x in s, (f x * ite (a = x) 1 0)) = ite (a ∈ s) (f a) 0 :=
by simp
lemma sum_boole_mul [decidable_eq α] (s : finset α) (f : α → β) (a : α) :
(∑ x in s, (ite (a = x) 1 0) * f x) = ite (a ∈ s) (f a) 0 :=
by simp
end semiring
lemma sum_div [division_ring β] {s : finset α} {f : α → β} {b : β} :
(∑ x in s, f x) / b = ∑ x in s, f x / b :=
calc (∑ x in s, f x) / b = ∑ x in s, f x * (1 / b) : by rw [div_eq_mul_one_div, sum_mul]
... = ∑ x in s, f x / b : by { congr, ext, rw ← div_eq_mul_one_div (f x) b }
section comm_semiring
variables [comm_semiring β]
/-- The product over a sum can be written as a sum over the product of sets, `finset.pi`.
`finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/
lemma prod_sum {δ : α → Type*} [decidable_eq α] [∀a, decidable_eq (δ a)]
{s : finset α} {t : Πa, finset (δ a)} {f : Πa, δ a → β} :
(∏ a in s, ∑ b in (t a), f a b) =
∑ p in (s.pi t), ∏ x in s.attach, f x.1 (p x.1 x.2) :=
begin
induction s using finset.induction with a s ha ih,
{ rw [pi_empty, sum_singleton], refl },
{ have h₁ : ∀x ∈ t a, ∀y ∈ t a, ∀h : x ≠ y,
disjoint (image (pi.cons s a x) (pi s t)) (image (pi.cons s a y) (pi s t)),
{ assume x hx y hy h,
simp only [disjoint_iff_ne, mem_image],
rintros _ ⟨p₂, hp, eq₂⟩ _ ⟨p₃, hp₃, eq₃⟩ eq,
have : pi.cons s a x p₂ a (mem_insert_self _ _) = pi.cons s a y p₃ a (mem_insert_self _ _),
{ rw [eq₂, eq₃, eq] },
rw [pi.cons_same, pi.cons_same] at this,
exact h this },
rw [prod_insert ha, pi_insert ha, ih, sum_mul, sum_bind h₁],
refine sum_congr rfl (λ b _, _),
have h₂ : ∀p₁∈pi s t, ∀p₂∈pi s t, pi.cons s a b p₁ = pi.cons s a b p₂ → p₁ = p₂, from
assume p₁ h₁ p₂ h₂ eq, pi_cons_injective ha eq,
rw [sum_image h₂, mul_sum],
refine sum_congr rfl (λ g _, _),
rw [attach_insert, prod_insert, prod_image],
{ simp only [pi.cons_same],
congr', ext ⟨v, hv⟩, congr',
exact (pi.cons_ne (by rintro rfl; exact ha hv)).symm },
{ exact λ _ _ _ _, subtype.eq ∘ subtype.mk.inj },
{ simp only [mem_image], rintro ⟨⟨_, hm⟩, _, rfl⟩, exact ha hm } }
end
lemma sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : finset ι₁) (s₂ : finset ι₂)
(f₁ : ι₁ → β) (f₂ : ι₂ → β) :
(∑ x₁ in s₁, f₁ x₁) * (∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁.product s₂, f₁ p.1 * f₂ p.2 :=
by { rw [sum_product, sum_mul, sum_congr rfl], intros, rw mul_sum }
open_locale classical
/-- The product of `f a + g a` over all of `s` is the sum
over the powerset of `s` of the product of `f` over a subset `t` times
the product of `g` over the complement of `t` -/
lemma prod_add (f g : α → β) (s : finset α) :
∏ a in s, (f a + g a) = ∑ t in s.powerset, ((∏ a in t, f a) * (∏ a in (s \ t), g a)) :=
calc ∏ a in s, (f a + g a)
= ∏ a in s, ∑ p in ({true, false} : finset Prop), if p then f a else g a : by simp
... = ∑ p in (s.pi (λ _, {true, false}) : finset (Π a ∈ s, Prop)),
∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 : prod_sum
... = ∑ t in s.powerset, (∏ a in t, f a) * (∏ a in (s \ t), g a) : begin
refine eq.symm (sum_bij (λ t _ a _, a ∈ t) _ _ _ _),
{ simp [subset_iff]; tauto },
{ intros t ht,
erw [prod_ite (λ a : {a // a ∈ s}, f a.1) (λ a : {a // a ∈ s}, g a.1)],
refine congr_arg2 _
(prod_bij (λ (a : α) (ha : a ∈ t), ⟨a, mem_powerset.1 ht ha⟩)
_ _ _
(λ b hb, ⟨b, by cases b; finish⟩))
(prod_bij (λ (a : α) (ha : a ∈ s \ t), ⟨a, by simp * at *⟩)
_ _ _
(λ b hb, ⟨b, by cases b; finish⟩));
intros; simp * at *; simp * at * },
{ finish [function.funext_iff, finset.ext_iff, subset_iff] },
{ assume f hf,
exact ⟨s.filter (λ a : α, ∃ h : a ∈ s, f a h),
by simp, by funext; intros; simp *⟩ }
end
/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `finset`
gives `(a + b)^s.card`.-/
lemma sum_pow_mul_eq_add_pow
{α R : Type*} [comm_semiring R] (a b : R) (s : finset α) :
(∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card :=
begin
rw [← prod_const, prod_add],
refine finset.sum_congr rfl (λ t ht, _),
rw [prod_const, prod_const, ← card_sdiff (mem_powerset.1 ht)]
end
lemma prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :
∀ {s : finset α}, (∏ i in s, x ^ (f i)) = x ^ (∑ x in s, f x) :=
begin
apply finset.induction,
{ simp },
{ assume a s has H,
rw [finset.prod_insert has, finset.sum_insert has, pow_add, H] }
end
theorem dvd_sum {b : β} {s : finset α} {f : α → β}
(h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=
multiset.dvd_sum (λ y hy, by rcases multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx)
@[norm_cast]
lemma prod_nat_cast (s : finset α) (f : α → ℕ) :
↑(∏ x in s, f x : ℕ) = (∏ x in s, (f x : β)) :=
(nat.cast_ring_hom β).map_prod f s
end comm_semiring
/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets
of `s`, and over all subsets of `s` to which one adds `x`. -/
@[to_additive]
lemma prod_powerset_insert [decidable_eq α] [comm_monoid β] {s : finset α} {x : α} (h : x ∉ s) (f : finset α → β) :
(∏ a in (insert x s).powerset, f a) =
(∏ a in s.powerset, f a) * (∏ t in s.powerset, f (insert x t)) :=
begin
rw [powerset_insert, finset.prod_union, finset.prod_image],
{ assume t₁ h₁ t₂ h₂ heq,
rw [← finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h),
← finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq] },
{ rw finset.disjoint_iff_ne,
assume t₁ h₁ t₂ h₂,
rcases finset.mem_image.1 h₂ with ⟨t₃, h₃, H₃₂⟩,
rw ← H₃₂,
exact ne_insert_of_not_mem _ _ (not_mem_of_mem_powerset_of_not_mem h₁ h) }
end
end finset
|
af7c93549bb684b413c97fa91b21cdb422cf062f | 54518a41e0f0c03b53f961e37a3ac2fed5cfeaa9 | /src/zfc.lean | da68f3bad8a6668cec8415801e98481e29a35f22 | [
"Apache-2.0"
] | permissive | cipher1024/flypitch | 9110cbfc99aa2195fe0a903fffc7034cdb00e87c | 357cd9cc344d7b6ea0c1f5d7232956b9ddb39359 | refs/heads/master | 1,598,733,974,743 | 1,572,308,681,000 | 1,572,992,816,000 | 218,170,521 | 0 | 0 | Apache-2.0 | 1,572,308,724,000 | 1,572,308,723,000 | null | UTF-8 | Lean | false | false | 21,067 | lean | /-
Copyright (c) 2019 The Flypitch Project. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jesse Han, Floris van Doorn
-/
import .bfol .forcing .forcing_CH
open lattice
open bSet
open fol
local notation h :: t := dvector.cons h t
local notation `[` l:(foldr `, ` (h t, dvector.cons h t) dvector.nil `]`:0) := l
local infixr ` ⟹' `:65 := lattice.imp
local prefix `∃'` := bd_ex
local prefix `∼` := bd_not
local infixr ` ⊓' `:70 := bd_and
local infixr ` ⊔' `:70 := bd_or
local infix ` ⟹'' `:62 := bd_imp
local infix ` ⇔' `:50 := lattice.biimp
-- local infix ` ⇔ `:61 := bd_biimp
universe u
section ZFC
inductive ZFC_rel : ℕ → Type 1
| ε : ZFC_rel 2
inductive ZFC_func : ℕ → Type 1
| emptyset : ZFC_func 0
| pr : ZFC_func 2
| ω : ZFC_func 0
| P : ZFC_func 1
| Union : ZFC_func 1
def L_ZFC : Language.{1} :=
{ functions := ZFC_func,
relations := ZFC_rel }
end ZFC
section ZFC
variables {β : Type 0} [nontrivial_complete_boolean_algebra β]
def bSet_model_fun_map : Π {n : ℕ}, L_ZFC.functions n → dvector (bSet β) n → bSet β :=
begin
intros n S, induction S,
from λ _, bSet.empty,
from λ x, by {cases x, refine bSet.pair x_x _, cases x_xs, from x_xs_x},
from λ _, bSet.omega,
from λ x, by {cases x, exact bv_powerset x_x},
from λ x, by {cases x, from bv_union ‹_›}
end
def bSet_model_rel_map : Π {n : ℕ}, L_ZFC.relations n → dvector (bSet β) n → β :=
begin
intros n R, induction R,
intro x, cases x, cases x_xs,
from x_x ∈ᴮ x_xs_x
end
variable (β)
def V : bStructure L_ZFC (β) :=
{ carrier := (bSet β),
fun_map := by apply bSet_model_fun_map,
rel_map := by apply bSet_model_rel_map,
eq := bv_eq,
eq_refl := bv_eq_refl,
eq_symm := by apply bv_eq_symm,
eq_trans := by apply bv_eq_trans,
fun_congr :=
begin
intros n F, cases F,
{intros x y, cases x, cases y, simp},
tactic.rotate 1,
{intros x y, cases x, cases y, simp},
{intros x y, cases x, cases y, cases x_xs, cases y_xs,
change (_ ⊓ _ : β) ≤ (bv_powerset _) =ᴮ (bv_powerset _), simp,
tidy_context, apply bv_powerset_congr ‹_› },
{intros x y, cases x, cases y, cases x_xs, cases y_xs,
change (_ ⊓ _ : β) ≤ (bv_union _) =ᴮ (bv_union _), simp,
tidy_context, from bv_union_congr ‹_›},
{intros x y, cases x, cases y, cases x_xs, cases y_xs,
change (_ ⊓ (_ ⊓ _) : β) ≤ pair x_x x_xs_x =ᴮ pair y_x y_xs_x,
cases x_xs_xs, cases y_xs_xs, simp }
end,
rel_congr :=
begin
intros n R, cases R, intros x y,
cases x, cases y, cases x_xs, cases y_xs,
cases x_xs_xs, cases y_xs_xs,
change ((_ ⊓ _) ⊓ (_ ∈ᴮ _) : β) ≤ (_ ∈ᴮ _), simp,
tidy_context, apply mem_congr; from ‹_›
end}
@[simp] lemma carrier_V : ↥(V β) = bSet β := rfl
@[simp]lemma V_forall {C : (V β) → β} : (⨅(x : V β), C x) = (⨅(x : bSet β), C x) := rfl
@[simp]lemma V_exists {C : (V β) → β} : (⨆(x : V β), C x) = (⨆(x : bSet β), C x) := rfl
@[simp]lemma V_eq {a b} : (V β).eq a b = a =ᴮ b := rfl
@[instance]lemma V_β_nonempty : nonempty (V β) := ⟨bSet.empty⟩
lemma alpha_equiv₁ {C : (bSet β) → β} : (⨅(x : bSet β), C x) = ⨅(y : bSet β), C y := rfl
lemma alpha_equiv₂ {C : (bSet β) → β} : (⨆(x : bSet β), C x) = ⨆(y : bSet β), C y := rfl
def emptyset {n} : bounded_term L_ZFC n := bd_const ZFC_func.emptyset
notation `∅'` := emptyset
def omega {n} : bounded_term L_ZFC n := bd_const ZFC_func.ω
notation `ω'` := omega
def Powerset {n} : bounded_term L_ZFC n → bounded_term L_ZFC n := bd_app (bd_func ZFC_func.P)
notation `P'` := Powerset
def mem {n} (t₁ t₂ : bounded_term L_ZFC n) : bounded_formula L_ZFC n :=
@bounded_formula_of_relation L_ZFC 2 n ZFC_rel.ε t₁ t₂
local infix ` ∈'`:100 := _root_.mem
def pair' {n} (t₁ t₂ : bounded_term L_ZFC n) : bounded_term L_ZFC n :=
@bounded_term_of_function L_ZFC 2 n ZFC_func.pr t₁ t₂
def union' {n} : bounded_term L_ZFC n → bounded_term L_ZFC n := bd_app (bd_func ZFC_func.Union)
notation `⋃'` := union'
local prefix `&'`:max := bd_var
@[simp] lemma boolean_realize_bounded_formula_mem {n} {v : dvector (V β) n}
(t₁ t₂ : bounded_term L_ZFC n) :
boolean_realize_bounded_formula v (t₁ ∈' t₂) ([]) =
boolean_realize_bounded_term v t₁ ([]) ∈ᴮ boolean_realize_bounded_term v t₂ ([]) :=
by refl
@[simp] lemma boolean_realize_bounded_term_Union {n} {v : dvector (V β) n}
(t : bounded_term L_ZFC n) :
boolean_realize_bounded_term v (⋃' t) ([]) =
bv_union (boolean_realize_bounded_term v t ([])) :=
by refl
@[simp] lemma boolean_realize_bounded_term_Powerset {n} {v : dvector (V β) n}
(t : bounded_term L_ZFC n) :
boolean_realize_bounded_term v (P' t) ([]) =
bv_powerset (boolean_realize_bounded_term v t ([])) :=
by refl
@[simp] lemma boolean_realize_bounded_term_omega {n} {v : dvector (V β) n} :
boolean_realize_bounded_term v ω' ([]) = bSet.omega :=
by refl
@[simp] lemma boolean_realize_bounded_term_emptyset {n} {v : dvector (V β) n} :
boolean_realize_bounded_term v ∅' ([]) = bSet.empty :=
by refl
@[simp]lemma boolean_realize_bounded_term_pair {n} {v : dvector (V β) n}
(t₁ t₂ : bounded_term L_ZFC n) : boolean_realize_bounded_term v (pair' t₁ t₂) ([]) =
pair (boolean_realize_bounded_term v t₁ ([])) (boolean_realize_bounded_term v t₂ ([])) :=
by refl
@[simp] lemma fin_0 {n : ℕ} : (0 : fin (n+1)).1 = 0 := by refl
@[simp] lemma fin_1 {n : ℕ} : (1 : fin (n+2)).1 = 1 := by refl
@[simp] lemma fin_2 {n : ℕ} : (2 : fin (n+3)).1 = 2 := by refl
@[simp] lemma fin_3 {n : ℕ} : (3 : fin (n+4)).1 = 3 := by refl
def axiom_of_emptyset : sentence L_ZFC := ∀' (∼(&0 ∈' ∅'))
lemma bSet_models_emptyset : ⊤ ⊩[V β] axiom_of_emptyset :=
by {change ⊤ ≤ _, simp[axiom_of_emptyset, -top_le_iff], intro x, from empty_spec}
-- axiom of ordered pairs
-- ∀x y z w, (x, y) = (z, w) ↔ x = z ∧ y = w
def axiom_of_ordered_pairs : sentence L_ZFC :=
∀' ∀' ∀' ∀'(((pair' &'3 &'2 ≃ pair' &'1 &'0)) ⇔ (&'3 ≃ &'1 ⊓ &'2 ≃ &'0))
lemma bSet_models_ordered_pairs : ⊤ ⊩[V β] axiom_of_ordered_pairs :=
begin
change ⊤ ≤ _, simp[axiom_of_ordered_pairs], intros a b x y, tidy,
from eq_of_eq_pair_left, from eq_of_eq_pair_right
end
-- axiom of extensionality
-- ∀ x y, (∀ z, (z ∈ x ↔ z ∈ y)) → x = y
def axiom_of_extensionality : sentence L_ZFC :=
∀' ∀' (∀'(&'0 ∈' &'2 ⇔ &'0 ∈' &'1) ⟹ (&1 ≃ &0))
lemma bSet_models_extensionality : ⊤ ⊩[V β] axiom_of_extensionality :=
by { simp [forced_in, axiom_of_extensionality], exact bSet_axiom_of_extensionality }
-- axiom schema of "strong" collection
-- For every formula `ϕ(x,y,p)` with (at most) `n+2` free variables (`p` is a vector of length `n`),
-- ∀ p ∀ A, (∀ x ∈ A, ∃ y, ϕ(x,y,p)) ⟹
-- (∃ B, (∀ x ∈ A, ∃ y ∈ B, ϕ(x,y,p)) ∧ ∀ y ∈ B, ∃ x ∈ A, ϕ(x,y,p))
def axiom_of_collection {n} (ϕ : bounded_formula L_ZFC (n+2)) : sentence L_ZFC :=
bd_alls (n+1) $ (∀' (&'0 ∈' &'1 ⟹ ∃' (ϕ ↑' 1 # 2))) ⟹
(∃' (∀'(&'0 ∈' &'2 ⟹ ∃' (&'0 ∈' &'2 ⊓ (ϕ ↑' 2 # 2))) ⊓
∀'(&'0 ∈' &'1 ⟹ ∃' (&'0 ∈' &'3 ⊓' ((ϕ ↑' 3 # 2)[&'1/0] : _)))))
lemma lift2_helper {L n l} (f : bounded_preformula L n l) {k} (m : ℕ) :
f ↑' (k+2) # m = ((f ↑' (k+1) # m) ↑' 1 # m : _) :=
by { ext, simp only [lift_bounded_formula_fst], rw [lift_formula_at2_medium], refl, linarith }
lemma B_ext_left_realize_bounded_formula {n : ℕ} (ϕ : bounded_formula L_ZFC (n + 1)) (xs : dvector (V β) n) : ∀ (x y : V β), x =ᴮ y ⊓ (boolean_realize_bounded_formula (x::xs) ϕ dvector.nil) ≤ boolean_realize_bounded_formula (y::xs) ϕ dvector.nil :=
begin
intros x y,
suffices : (x =ᴮ y = ⨅ (m : fin (n+1)), (V β).eq ((x::xs).nth _ m.is_lt) ((y::xs).nth _ m.is_lt)),
by {rw this, apply boolean_realize_bounded_formula_congr, apply_instance},
refine le_antisymm _ _,
{ apply le_infi, rintro ⟨m,Hm⟩,
cases m,
{ refl },
{ rw [dvector.nth_cons, dvector.nth_cons],
{exact bSet.bv_refl, { exact nat.lt_of_succ_lt_succ Hm }},
}},
{ tidy_context, exact a ⟨0, dec_trivial⟩ }
end
lemma B_ext_right_realize_bounded_formula {n : ℕ} (ϕ : bounded_formula L_ZFC (n + 2)) (xs : dvector (V β) n) : ∀ (x y z : V β), x =ᴮ y ⊓ (boolean_realize_bounded_formula (z::x::xs) ϕ dvector.nil) ≤ boolean_realize_bounded_formula (z::y::xs) ϕ dvector.nil :=
begin
intros x y z,
suffices : (x =ᴮ y = ⨅ (m : fin (n+2)), (V β).eq ((z::x::xs).nth _ m.is_lt) ((z::y::xs).nth _ m.is_lt)),
by {rw this, apply boolean_realize_bounded_formula_congr, apply_instance},
refine le_antisymm _ _,
{ apply le_infi, rintro ⟨m,Hm⟩,
cases m,
{ exact bSet.bv_refl },
{ cases m,
{ refl },
{ repeat {rw dvector.nth_cons},
{ exact bSet.bv_refl, apply nat.lt_of_succ_lt_succ,
apply nat.lt_of_succ_lt_succ, from ‹_› }} }},
{ tidy_context, exact a ⟨1, dec_trivial⟩ }
end
lemma bSet_models_collection {n} (ϕ : bounded_formula L_ZFC (n+2)) : ⊤ ⊩[V β] axiom_of_collection ϕ :=
begin
change ⊤ ≤ _, simp only [axiom_of_collection, boolean_realize_sentence_bd_alls],
bv_intro xs, cases xs with _ u xs,
simp only
[ boolean_realize_bounded_formula_and,
boolean_realize_bounded_term, imp_top_iff_le,
boolean_realize_bounded_formula_ex, top_le_iff,
boolean_realize_bounded_formula, boolean_realize_formula_insert_lift2,
lift2_helper, boolean_realize_subst_formula0, fin_2 ],
have := bSet_axiom_of_collection
(λ a b : V β, boolean_realize_bounded_formula (b :: a :: xs) ϕ ([])) _ _ u,
simp only [lattice.top_le_iff, bSet.mem, lattice.imp_top_iff_le, lattice.le_infi_iff] at this,
exact this,
{ intros, apply B_ext_left_realize_bounded_formula },
{ intros, apply B_ext_right_realize_bounded_formula },
end
-- axiom of union
-- ∀ u x, x ∈ ⋃ u ↔ ∃ y ∈ u, x ∈ y
def axiom_of_union : sentence L_ZFC :=
∀' ∀' (&'0 ∈' ⋃' &'1 ⇔ (∃' (&'0 ∈' &'2 ⊓ &'1 ∈' &'0)))
lemma bSet_models_union : ⊤ ⊩[V β] axiom_of_union :=
begin
simp [-top_le_iff, forced_in, axiom_of_union, -lattice.le_inf_iff],
intros x z,
have := @bv_union_spec' _ _ x ⊤,
replace this := this z, dsimp at this,
bv_split, bv_split_goal
end
-- axiom of powerset
-- ∀ u x, x ∈ P(u) ↔ ∀ y ∈ x, y ∈ u
def axiom_of_powerset : sentence L_ZFC :=
∀' ∀' (&'0 ∈' P' &'1 ⇔ (∀' (&'0 ∈' &'1 ⟹ &'0 ∈' &'2)))
lemma bSet_models_powerset : ⊤ ⊩[V β] axiom_of_powerset :=
begin
simp [forced_in, axiom_of_powerset, -lattice.le_inf_iff, -top_le_iff],
intros x z, have := @bv_powerset_spec _ _ x z,
rw [subset_unfold'] at this,
apply le_inf, bv_imp_intro, exact this.mpr H, bv_imp_intro, exact this.mp H
end
/-- &1 ⊆ &0 ↔ ∀ z, (z ∈ &1 ⟹ z ∈ &0)-/
def subset'' {n} (t₁ t₂ : bounded_term L_ZFC n): bounded_formula L_ZFC n :=
∀' (&'0 ∈' (t₁ ↑ 1) ⟹ &'0 ∈' (t₂ ↑ 1))
local infix ` ⊆'`:100 := subset''
@[simp] lemma boolean_realize_bounded_formula_subset {n} {v : dvector (V β) n}
(t₁ t₂ : bounded_term L_ZFC n) :
boolean_realize_bounded_formula v (t₁ ⊆' t₂) ([]) =
boolean_realize_bounded_term v t₁ ([]) ⊆ᴮ boolean_realize_bounded_term v t₂ ([]) :=
by { simp [subset'', subset_unfold'] }
def is_transitive_f : bounded_formula L_ZFC 1 := ∀' ((&'0 ∈' &'1) ⟹ &'0 ⊆' &'1)
def epsilon_trichotomy_f : bounded_formula L_ZFC 1 :=
∀' ((&'0 ∈' &'1) ⟹''(∀' (&'0 ∈' &'2 ⟹'' (&'1 ≃ &'0 ⊔' &'1 ∈' &'0) ⊔' &'0 ∈' &'1)))
def epsilon_well_founded_f : bounded_formula L_ZFC 1 :=
∀' (((&'0 ⊆' &'1) ⟹'' ((∼(&'0 ≃ ∅')) ⟹'' ∃' (&'0 ∈' &'1 ⊓' (∀' (&'0 ∈' &'2 ⟹'' ∼(&'0 ∈' &'1)))))))
def ewo_f : bounded_formula L_ZFC 1 := epsilon_trichotomy_f ⊓' epsilon_well_founded_f
def Ord_f : bounded_formula L_ZFC 1 := ewo_f ⊓' is_transitive_f
@[simp]lemma Ord_f_is_Ord {x : V β} : boolean_realize_bounded_formula (by exact [x]) Ord_f dvector.nil = Ord x :=
by {simp [Ord_f,ewo_f,is_transitive_f,epsilon_well_founded_f, epsilon_trichotomy_f], refl}
-- this is the usual axiom of infinity, plus a characterization of omega as the least limit ordinal
def axiom_of_infinity : sentence L_ZFC :=
(∅' ∈' ω' ⊓' ∀'(&'0 ∈' ω' ⟹ ∃' (&'0 ∈' ω' ⊓' &'1 ∈' &'0)))
⊓' (∃' (Ord_f ⊓' ω' ≃ &'0))
⊓' ∀' (Ord_f ⟹ ((∅' ∈' &'0 ⊓' ∀'(&'0 ∈' &'1 ⟹ ∃' (&'0 ∈' &'2 ⊓' &'1 ∈' &'0))) ⟹ ω' ⊆' &0))
lemma bSet_models_infinity : ⊤ ⊩[V β] axiom_of_infinity :=
begin
simp [forced_in, axiom_of_infinity, boolean_realize_sentence,
-lattice.le_inf_iff, -top_le_iff],
refine le_inf _ _,
{ exact bSet_axiom_of_infinity' },
{ refine le_inf _ _,
{ apply bv_use bSet.omega, exact le_inf Ord_omega bv_refl },
{ exact omega_least_is_limit } }
end
-- axiom of regularity
-- ∀ x, x ≠ ∅ ⟹ ∃ y ∈ x, ∀ z ∈ x, ¬ (z ∈ y)
def axiom_of_regularity : sentence L_ZFC :=
∀' (∼(&0 ≃ ∅') ⟹ (∃' (&'0 ∈' &'1 ⊓ ∀' (&'0 ∈' &'2 ⟹ ∼(&'0 ∈' &'1)))))
lemma bSet_models_regularity : ⊤ ⊩[V β] axiom_of_regularity :=
begin
change ⊤ ≤ _, unfold axiom_of_regularity,
simp[-top_le_iff], intro x,
bv_imp_intro,
apply bSet_axiom_of_regularity, convert H
end
/- ∀ x, x ≠ ∅ ∧ ((∀ y, y ⊆ x ∧ ∀ w₁ w₂ ∈ y, w₁ ⊆ w₂ ∨ w₂ ⊆ w₁) → (⋃y) ∈ x)
→ ∃ c ∈ x, ∀ z ∈ x, c ⊆ z → c = z -/
def zorns_lemma : sentence L_ZFC :=
∀' (∼ (&'0 ≃ ∅')
⟹ (∀' (&'0 ⊆' &'1 ⊓' (∀' ∀' ((&'1 ∈' &'2 ⊓' &'0 ∈' &'2) ⟹ (&'1 ⊆' &'0 ⊔' &'0 ⊆' &'1)))
⟹ (⋃' &' 0 ∈' &'1)))
⟹ (∃' (&'0 ∈' &'1 ⊓ ∀' (&'0 ∈' &'2 ⟹ &'1 ⊆' &'0 ⟹ &'1 ≃ &'0 ))))
lemma bSet_models_Zorn : ⊤ ⊩[V β] zorns_lemma :=
begin
simp [forced_in, zorns_lemma, boolean_realize_sentence, -lattice.le_inf_iff, -top_le_iff, -lattice.le_infi_iff],
from bSet_zorns_lemma'
end
def ZFC : Theory L_ZFC :=
{axiom_of_emptyset, axiom_of_ordered_pairs, axiom_of_extensionality, axiom_of_union,
axiom_of_powerset, axiom_of_infinity, axiom_of_regularity, zorns_lemma} ∪
set.Union (λ(n : ℕ), axiom_of_collection '' (set.univ : set $ bounded_formula L_ZFC (n+2)))
theorem bSet_models_ZFC : ⊤ ⊩[V β] ZFC :=
begin
change ⊤ ≤ _, bv_intro f, bv_intro H,
repeat{auto_cases}; try{subst H}; try {cases H},
from bSet_models_Zorn _,
from bSet_models_regularity _,
from bSet_models_infinity _,
from bSet_models_powerset _,
from bSet_models_union _,
from bSet_models_extensionality _,
from bSet_models_ordered_pairs _,
from bSet_models_emptyset _,
from bSet_models_collection _ ‹_›
end
include β
theorem ZFC_consistent : is_consistent ZFC := consis_of_exists_bmodel (bSet_models_ZFC β)
omit β
/-- f is =ᴮ-extensional if for every w₁ w₂ v₁ v₂, if pair (w₁, v₁) and pair (w₂, v₂) ∈ f and
w₁ =ᴮ w₂, then v₁ =ᴮ v₂ -/
def is_func_f : bounded_formula L_ZFC 1 :=
∀' ∀' ∀' ∀' ((pair' &'3 &'1 ∈' &'4 ⊓' pair' &'2 &'0 ∈' &'4
⟹ (&'3 ≃ &'2 ⟹ &'1 ≃ &'0)))
@[simp]lemma realize_is_func_f {f : V β} : boolean_realize_bounded_formula (by exact [f]) is_func_f dvector.nil = is_func f :=
begin
simp[is_func_f, bSet.is_func], refl
end
def is_total'_f : bounded_formula L_ZFC 3 :=
(∀' (&'0 ∈' &'3 ⟹ (∃' (&'0 ∈' &'3 ⊓' (pair' &'1 &'0 ∈' &'2)))))
@[simp]lemma realize_is_total'_f {x y f : V β} : boolean_realize_bounded_formula (by exact [f, y, x]) is_total'_f dvector.nil = is_total x y f :=
begin
simp [bSet.is_total, is_total'_f]
end
-- is_total'_f₂ S y f is the same as is_total'_f y S f
def is_total'_f₂ : bounded_formula L_ZFC 3 :=
(∀' (&'0 ∈' &'2 ⟹ (∃' (&'0 ∈' &'4 ⊓' (pair' &'1 &'0 ∈' &'2)))))
@[simp]lemma realize_is_total'_f₂ {x y f : V β} : boolean_realize_bounded_formula (by exact [f, y, x]) is_total'_f₂ dvector.nil = is_total y x f :=
begin
rw [bSet.is_total, is_total'_f₂], simp, refl
end
def is_func'_f : bounded_formula L_ZFC 3 :=
(is_func_f.cast (dec_trivial)) ⊓' is_total'_f
def is_func'_f₂ : bounded_formula L_ZFC 3 :=
(is_func_f.cast dec_trivial) ⊓' is_total'_f₂
@[simp]lemma realize_is_func'_f {x y f : V β} : boolean_realize_bounded_formula (by exact [f, y, x]) is_func'_f dvector.nil = is_func' x y f :=
by simp [is_func'_f, is_func']
@[simp]lemma realize_is_func'_f₂ {x y f : V β} : boolean_realize_bounded_formula (by exact [f, y, x]) is_func'_f₂ dvector.nil = is_func' y x f :=
by simp [is_func'_f₂, is_func']
/-
`at_most_f x y` means
`∃ S, ∃ f, S ⊆ y ∧ f contains a function from S to x ∧ f surjects onto x`
In `bSet` it corresponds to the formula `larger_than y x`.
`at_most_f x y` is equivalent to `¬ y ≺ x`.
-/
def at_most_f : bounded_formula L_ZFC 2 :=
∃' (∃' (((&'1 ⊆' &'3) ⊓' (is_func'_f₂).cast (dec_trivial : 3 ≤ 4)) ⊓'
∀' ( &0 ∈' &3 ⟹ (∃' (&'0 ∈' &'3 ⊓' pair' &'0 &'1 ∈' &'2)))))
@[simp]lemma realize_at_most_f {x y : V β} :
boolean_realize_bounded_formula ([y,x]) at_most_f dvector.nil = larger_than x y :=
by simp[larger_than, at_most_f, is_func]
def is_inj_f : bounded_formula L_ZFC 1 :=
∀' ∀' ∀' ∀' (((pair' &'3 &'1 ∈' &'4 ⊓' pair' &'2 &'0 ∈' &'4) ⊓ &'1 ≃ &'0) ⟹ &'3 ≃ &'2)
@[simp]lemma realize_is_inj_f (f : V β) :
boolean_realize_bounded_formula (by exact [f]) is_inj_f dvector.nil = is_inj f :=
by {simp[is_inj_f, is_inj], refl}
def injects_into_f : bounded_formula L_ZFC 2 :=
∃' (is_func'_f ⊓' is_inj_f.cast (dec_trivial))
@[simp]lemma realize_injects_into {x y : V β} :
boolean_realize_bounded_formula (by exact [y,x]) injects_into_f dvector.nil = injects_into x y :=
by {simp[injects_into_f, injects_into]}
def non_empty_f : bounded_formula L_ZFC 1 := ∼(&'0 ≃ ∅')
@[simp]lemma non_empty_f_is_non_empty {x : V β} : boolean_realize_bounded_formula (by exact [x]) non_empty_f dvector.nil = not_empty x := by {simp[non_empty_f], refl}
/-- The continuum hypothesis is given by the formula
`∀x, x is an ordinal ⟹ x ≤ ω ∨ P(ω) ≤ x`.
Here `a ≤ b` means there is a surjection from a subset of `b` to `a`.
We have to perform two substitutions (`substmax_bounded_formula` and `[../0]`)
to apply `at_most_f` to the appropriate arguments. -/
def CH_f : sentence L_ZFC :=
∀' (Ord_f ⟹ (substmax_bounded_formula at_most_f ω' ⊔' at_most_f[Powerset omega/0]))
variable {β}
lemma CH_f_is_CH : ⟦CH_f⟧[V β] = CH₂ :=
begin
have h1 : ∀(x : V β), boolean_realize_bounded_formula ([x])
(substmax_bounded_formula at_most_f omega) ([]) =
boolean_realize_bounded_formula ([x,omega]) at_most_f ([]),
{ intro, refl },
have h2 : ∀(x : V β), boolean_realize_bounded_formula ([x]) (at_most_f[P' omega /0]) ([]) =
boolean_realize_bounded_formula (([bv_powerset omega, x] : dvector (V β) 2)) at_most_f ([]),
{ intro, refl },
-- note: once we have proven realize_substmax_bf and realize_subst0_bf, we can add them to this simp set
simp [-substmax_bounded_formula, CH_f, CH₂, neg_supr, sup_assoc, h1, h2, lattice.imp]
end
lemma CH_f_sound {Γ : β} : Γ ⊩[V β] CH_f ↔ Γ ≤ CH₂ :=
by {change _ ≤ _ ↔ _ ≤ _, rw CH_f_is_CH}
lemma neg_CH_f_sound {Γ : β} : Γ ⊩[V β] ∼CH_f ↔ Γ ≤ - CH₂ :=
by {change _ ≤ _ ↔ _ ≤ _, rw [boolean_realize_sentence_not, CH_f_is_CH]}
end ZFC
open pSet cardinal
section CH_unprovable
lemma V_𝔹_cohen_models_neg_CH : ⊤ ⊩[V 𝔹_cohen] ∼CH_f :=
begin
rw neg_CH_f_sound, exact neg_CH₂
end
instance V_𝔹_nonempty : nonempty (V 𝔹_cohen) := ⟨bSet.empty⟩
theorem CH_f_unprovable : ¬ (ZFC ⊢' CH_f) :=
unprovable_of_model_neg _ (bSet_models_ZFC _) (nontrivial.bot_lt_top) V_𝔹_cohen_models_neg_CH
end CH_unprovable
open collapse_algebra
section neg_CH_unprovable
instance V_𝔹_collapse_nonempty : nonempty (V 𝔹_collapse) := ⟨bSet.empty⟩
lemma V_𝔹_collapse_models_CH : ⊤ ⊩[V 𝔹_collapse] CH_f :=
by { rw CH_f_sound, exact CH₂_true }
theorem neg_CH_f_unprovable : ¬ (ZFC ⊢' ∼CH_f) :=
unprovable_of_model_neg (V 𝔹_collapse) (bSet_models_ZFC _)
(nontrivial.bot_lt_top) (by {rw forced_in_not, from V_𝔹_collapse_models_CH})
end neg_CH_unprovable
section
-- a nicer formulation of CH using formulae
@[simp] def Powerset_t : term L_ZFC → term L_ZFC := app (func ZFC_func.P)
@[simp] def omega_t : term L_ZFC := func ZFC_func.ω
@[simp] def leq_f : formula L_ZFC := at_most_f.fst
@[simp] def is_ordinal : formula L_ZFC := Ord_f.fst
def CH_formula : formula L_ZFC :=
∀' (is_ordinal ⟹ leq_f[omega_t//1] ⊔ leq_f[Powerset_t omega_t//0])
lemma CH_f_fst : CH_f.fst = CH_formula :=
by { simp [CH_f, CH_formula, -substmax_bounded_formula], refl }
end
|
1293eff74052906ccced2123181b6d73bbca9458 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/hott/719.hlean | 53ec8a4c63e7f287f9c9103cd19c02983d96c5f1 | [
"Apache-2.0"
] | permissive | soonhokong/lean | cb8aa01055ffe2af0fb99a16b4cda8463b882cd1 | 38607e3eb57f57f77c0ac114ad169e9e4262e24f | refs/heads/master | 1,611,187,284,081 | 1,450,766,737,000 | 1,476,122,547,000 | 11,513,992 | 2 | 0 | null | 1,401,763,102,000 | 1,374,182,235,000 | C++ | UTF-8 | Lean | false | false | 298 | hlean | -- HoTT
open eq
variables {A A' : Type} {a a' : A} {C : A → A' → Type} (p : a = a') (f : Π(b : A'), C a b) (b : A')
definition foo : (transport _ p f) b = p ▸ (f b) := sorry
definition bar : (p ▸ f) b = transport _ p (f b) := sorry
definition bla : (p ▸ f) b = p ▸ (f b) := sorry
|
492ad7763eb18d1b379c3647c6bf6630956abce8 | 69d4931b605e11ca61881fc4f66db50a0a875e39 | /src/analysis/normed_space/normed_group_quotient.lean | ec21486806d496287f58f9d60bce60d303d67881 | [
"Apache-2.0"
] | permissive | abentkamp/mathlib | d9a75d291ec09f4637b0f30cc3880ffb07549ee5 | 5360e476391508e092b5a1e5210bd0ed22dc0755 | refs/heads/master | 1,682,382,954,948 | 1,622,106,077,000 | 1,622,106,077,000 | 149,285,665 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 20,547 | lean | /-
Copyright (c) 2021 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Riccardo Brasca
-/
import analysis.normed_space.normed_group_hom
/-!
# Quotients of seminormed groups
For any `semi_normed_group M` and any `S : add_subgroup M`, we provide a `semi_normed_group`
structure on `quotient_add_group.quotient S` (abreviated `quotient S` in the following).
If `S` is closed, we provide `normed_group (quotient S)` (regardless of whether `M` itself is
separated). The two main properties of these structures are the underlying topology is the quotient
topology and the projection is a normed group homomorphism which is norm non-increasing
(better, it has operator norm exactly one unless `S` is dense in `M`). The corresponding
universal property is that every normed group hom defined on `M` which vanishes on `S` descends
to a normed group hom defined on `quotient S`.
This file also introduces a predicate `is_quotient` characterizing normed group homs that
are isomorphic to the canonical projection onto a normed group quotient.
## Main definitions
We use `M` and `N` to denote semi normed groups and `S : add_subgroup M`.
All the following definitions are in the `add_subgroup` namespace. Hence we can access
`add_subgroup.normed_mk S` as `S.normed_mk`.
* `semi_normed_group_quotient` : The seminormed group structure on the quotient by
an additive subgroup. This is an instance so there is no need to explictly use it.
* `normed_group_quotient` : The normed group structure on the quotient by
a closed additive subgroup. This is an instance so there is no need to explictly use it.
* `normed_mk S` : the normed group hom from `M` to `quotient S`.
* `lift S f hf`: implements the universal property of `quotient S`. Here
`(f : normed_group_hom M N)`, `(hf : ∀ s ∈ S, f s = 0)` and
`lift S f hf : normed_group_hom (quotient S) N`.
* `is_quotient`: given `f : normed_group_hom M N`, `is_quotient f` means `N` is isomorphic
to a quotient of `M` by a subgroup, with projection `f`. Technically it asserts `f` is
surjective and the norm of `f x` is the infimum of the norms of `x + m` for `m` in `f.ker`.
## Main results
* `norm_normed_mk` : the operator norm of the projection is `1` if the subspace is not dense.
* `is_quotient.norm_lift`: Provided `f : normed_hom M N` satisfies `is_quotient f`, for every
`n : N` and positive `ε`, there exists `m` such that `f m = n ∧ ∥m∥ < ∥n∥ + ε`.
## Implementation details
For any `semi_normed_group M` and any `S : add_subgroup M` we define a norm on `quotient S` by
`∥x∥ = Inf (norm '' {m | mk' S m = x})`. This formula is really an implementation detail, it
shouldn't be needed outside of this file setting up the theory.
Since `quotient S` is automatically a topological space (as any quotient of a topological space),
one needs to be careful while defining the `semi_normed_group` instance to avoid having two
different topologies on this quotient. This is not purely a technological issue.
Mathematically there is something to prove. The main point is proved in the auxiliary lemma
`quotient_nhd_basis` that has no use beyond this verification and states that zero in the quotient
admits as basis of neighborhoods in the quotient topology the sets `{x | ∥x∥ < ε}` for positive `ε`.
Once this mathematical point it settled, we have two topologies that are propositionaly equal. This
is not good enough for the type class system. As usual we ensure *definitional* equality
using forgetful inheritance, see Note [forgetful inheritance]. A (semi)-normed group structure
includes a uniform space structure which includes a topological space structure, together
with propositional fields asserting compatibility conditions.
The usual way to define a `semi_normed_group` is to let Lean build a uniform space structure
using the provided norm, and then trivially build a proof that the norm and uniform structure are
compatible. Here the uniform structure is provided using `topological_add_group.to_uniform_space`
which uses the topological structure and the group structure to build the uniform structure. This
uniform structure induces the correct topological structure by construction, but the fact that it
is compatible with the norm is not obvious; this is where the mathematical content explained in
the previous paragraph kicks in.
-/
noncomputable theory
open quotient_add_group metric set
open_locale topological_space nnreal
variables {M N : Type*} [semi_normed_group M] [semi_normed_group N]
/-- The definition of the norm on the quotient by an additive subgroup. -/
noncomputable
instance norm_on_quotient (S : add_subgroup M) : has_norm (quotient S) :=
{ norm := λ x, Inf (norm '' {m | mk' S m = x}) }
lemma image_norm_nonempty {S : add_subgroup M} :
∀ x : quotient S, (norm '' {m | mk' S m = x}).nonempty :=
begin
rintro ⟨m⟩,
rw set.nonempty_image_iff,
use m,
change mk' S m = _,
refl
end
lemma bdd_below_image_norm (s : set M) : bdd_below (norm '' s) :=
begin
use 0,
rintro _ ⟨x, hx, rfl⟩,
apply norm_nonneg
end
/-- The norm on the quotient satisfies `∥-x∥ = ∥x∥`. -/
lemma quotient_norm_neg {S : add_subgroup M} (x : quotient S) : ∥-x∥ = ∥x∥ :=
begin
suffices : norm '' {m | mk' S m = x} = norm '' {m | mk' S m = -x},
by simp only [this, norm],
ext r,
split,
{ rintros ⟨m, hm : mk' S m = x, rfl⟩,
subst hm,
rw ← norm_neg,
exact ⟨-m, by simp only [(mk' S).map_neg, set.mem_set_of_eq], rfl⟩ },
{ rintros ⟨m, hm : mk' S m = -x, rfl⟩,
use -m,
simp [hm] }
end
lemma quotient_norm_sub_rev {S : add_subgroup M} (x y: quotient S) : ∥x - y∥ = ∥y - x∥ :=
by rw [show x - y = -(y - x), by abel, quotient_norm_neg]
/-- The norm of the projection is smaller or equal to the norm of the original element. -/
lemma quotient_norm_mk_le (S : add_subgroup M) (m : M) :
∥mk' S m∥ ≤ ∥m∥ :=
begin
apply real.Inf_le,
use 0,
{ rintros _ ⟨n, h, rfl⟩,
apply norm_nonneg },
{ apply set.mem_image_of_mem,
rw set.mem_set_of_eq }
end
/-- The norm of the image under the natural morphism to the quotient. -/
lemma quotient_norm_mk_eq (S : add_subgroup M) (m : M) :
∥mk' S m∥ = Inf ((λ x, ∥m + x∥) '' S) :=
begin
change Inf _ = _,
congr' 1,
ext r,
simp_rw [coe_mk', eq_iff_sub_mem],
split,
{ rintros ⟨y, h, rfl⟩,
use [y - m, h],
simp },
{ rintros ⟨y, h, rfl⟩,
use m + y,
simpa using h },
end
/-- The quotient norm is nonnegative. -/
lemma quotient_norm_nonneg (S : add_subgroup M) : ∀ x : quotient S, 0 ≤ ∥x∥ :=
begin
rintros ⟨m⟩,
change 0 ≤ ∥mk' S m∥,
apply real.lb_le_Inf _ (image_norm_nonempty _),
rintros _ ⟨n, h, rfl⟩,
apply norm_nonneg
end
/-- The quotient norm is nonnegative. -/
lemma norm_mk_nonneg (S : add_subgroup M) (m : M) : 0 ≤ ∥mk' S m∥ :=
quotient_norm_nonneg S _
/-- The norm of the image of `m : M` in the quotient by `S` is zero if and only if `m` belongs
to the closure of `S`. -/
lemma quotient_norm_eq_zero_iff (S : add_subgroup M) (m : M) :
∥mk' S m∥ = 0 ↔ m ∈ closure (S : set M) :=
begin
have : 0 ≤ ∥mk' S m∥ := norm_mk_nonneg S m,
rw [← this.le_iff_eq, quotient_norm_mk_eq, real.Inf_le_iff],
simp_rw [zero_add],
{ calc (∀ ε > (0 : ℝ), ∃ r ∈ (λ x, ∥m + x∥) '' (S : set M), r < ε) ↔
(∀ ε > 0, (∃ x ∈ S, ∥m + x∥ < ε)) : by simp [set.bex_image_iff]
... ↔ ∀ ε > 0, (∃ x ∈ S, ∥m + -x∥ < ε) : _
... ↔ ∀ ε > 0, (∃ x ∈ S, x ∈ metric.ball m ε) : by simp [dist_eq_norm, ← sub_eq_add_neg,
norm_sub_rev]
... ↔ m ∈ closure ↑S : by simp [metric.mem_closure_iff, dist_comm],
apply forall_congr, intro ε, apply forall_congr, intro ε_pos,
rw [← S.exists_neg_mem_iff_exists_mem],
simp },
{ use 0,
rintro _ ⟨x, x_in, rfl⟩,
apply norm_nonneg },
rw set.nonempty_image_iff,
use [0, S.zero_mem]
end
/-- For any `x : quotient S` and any `0 < ε`, there is `m : M` such that `mk' S m = x`
and `∥m∥ < ∥x∥ + ε`. -/
lemma norm_mk_lt {S : add_subgroup M} (x : quotient S) {ε : ℝ} (hε : 0 < ε) :
∃ (m : M), mk' S m = x ∧ ∥m∥ < ∥x∥ + ε :=
begin
obtain ⟨_, ⟨m : M, H : mk' S m = x, rfl⟩, hnorm : ∥m∥ < ∥x∥ + ε⟩ :=
real.lt_Inf_add_pos (bdd_below_image_norm _) (image_norm_nonempty x) hε,
subst H,
exact ⟨m, rfl, hnorm⟩,
end
/-- For any `m : M` and any `0 < ε`, there is `s ∈ S` such that `∥m + s∥ < ∥mk' S m∥ + ε`. -/
lemma norm_mk_lt' (S : add_subgroup M) (m : M) {ε : ℝ} (hε : 0 < ε) :
∃ s ∈ S, ∥m + s∥ < ∥mk' S m∥ + ε :=
begin
obtain ⟨n : M, hn : mk' S n = mk' S m, hn' : ∥n∥ < ∥mk' S m∥ + ε⟩ :=
norm_mk_lt (quotient_add_group.mk' S m) hε,
erw [eq_comm, quotient_add_group.eq] at hn,
use [- m + n, hn],
rwa [add_neg_cancel_left]
end
/-- The quotient norm satisfies the triangle inequality. -/
lemma quotient_norm_add_le (S : add_subgroup M) (x y : quotient S) : ∥x + y∥ ≤ ∥x∥ + ∥y∥ :=
begin
refine le_of_forall_pos_le_add (λ ε hε, _),
replace hε := half_pos hε,
obtain ⟨m, rfl, hm : ∥m∥ < ∥mk' S m∥ + ε / 2⟩ := norm_mk_lt x hε,
obtain ⟨n, rfl, hn : ∥n∥ < ∥mk' S n∥ + ε / 2⟩ := norm_mk_lt y hε,
calc ∥mk' S m + mk' S n∥ = ∥mk' S (m + n)∥ : by rw (mk' S).map_add
... ≤ ∥m + n∥ : quotient_norm_mk_le S (m + n)
... ≤ ∥m∥ + ∥n∥ : norm_add_le _ _
... ≤ ∥mk' S m∥ + ∥mk' S n∥ + ε : by linarith
end
/-- The quotient norm of `0` is `0`. -/
lemma norm_mk_zero (S : add_subgroup M) : ∥(0 : quotient S)∥ = 0 :=
begin
erw quotient_norm_eq_zero_iff,
exact subset_closure S.zero_mem
end
/-- If `(m : M)` has norm equal to `0` in `quotient S` for a closed subgroup `S` of `M`, then
`m ∈ S`. -/
lemma norm_zero_eq_zero (S : add_subgroup M) (hS : is_closed (S : set M)) (m : M)
(h : ∥mk' S m∥ = 0) : m ∈ S :=
by rwa [quotient_norm_eq_zero_iff, hS.closure_eq] at h
lemma quotient_nhd_basis (S : add_subgroup M) :
(𝓝 (0 : quotient S)).has_basis (λ ε : ℝ, 0 < ε) (λ ε, {x | ∥x∥ < ε}) :=
⟨begin
intros U,
split,
{ intros U_in,
rw ← (mk' S).map_zero at U_in,
have := preimage_nhds_coinduced U_in,
rcases metric.mem_nhds_iff.mp this with ⟨ε, ε_pos, H⟩,
use [ε/2, half_pos ε_pos],
intros x x_in,
dsimp at x_in,
rcases norm_mk_lt x (half_pos ε_pos) with ⟨y, rfl, ry⟩,
apply H,
rw ball_0_eq,
dsimp,
linarith },
{ rintros ⟨ε, ε_pos, h⟩,
have : (mk' S) '' (ball (0 : M) ε) ⊆ {x | ∥x∥ < ε},
{ rintros - ⟨x, x_in, rfl⟩,
rw mem_ball_0_iff at x_in,
exact lt_of_le_of_lt (quotient_norm_mk_le S x) x_in },
apply filter.mem_sets_of_superset _ (set.subset.trans this h),
clear h U this,
apply is_open.mem_nhds,
{ change is_open ((mk' S) ⁻¹' _),
erw quotient_add_group.preimage_image_coe,
apply is_open_Union,
rintros ⟨s, s_in⟩,
exact (continuous_add_right s).is_open_preimage _ is_open_ball },
{ exact ⟨(0 : M), mem_ball_self ε_pos, (mk' S).map_zero⟩ } },
end⟩
/-- The seminormed group structure on the quotient by an additive subgroup. -/
noncomputable
instance add_subgroup.semi_normed_group_quotient (S : add_subgroup M) :
semi_normed_group (quotient S) :=
{ dist := λ x y, ∥x - y∥,
dist_self := λ x, by simp only [norm_mk_zero, sub_self],
dist_comm := quotient_norm_sub_rev,
dist_triangle := λ x y z,
begin
unfold dist,
have : x - z = (x - y) + (y - z) := by abel,
rw this,
exact quotient_norm_add_le S (x - y) (y - z)
end,
dist_eq := λ x y, rfl,
to_uniform_space := topological_add_group.to_uniform_space (quotient S),
uniformity_dist :=
begin
rw uniformity_eq_comap_nhds_zero',
have := (quotient_nhd_basis S).comap (λ (p : quotient S × quotient S), p.2 - p.1),
apply this.eq_of_same_basis,
have : ∀ ε : ℝ, (λ (p : quotient S × quotient S), p.snd - p.fst) ⁻¹' {x | ∥x∥ < ε} =
{p : quotient S × quotient S | ∥p.fst - p.snd∥ < ε},
{ intro ε,
ext x,
dsimp,
rw quotient_norm_sub_rev },
rw funext this,
refine filter.has_basis_binfi_principal _ set.nonempty_Ioi,
rintros ε (ε_pos : 0 < ε) η (η_pos : 0 < η),
refine ⟨min ε η, lt_min ε_pos η_pos, _, _⟩,
{ suffices : ∀ (a b : quotient S), ∥a - b∥ < ε → ∥a - b∥ < η → ∥a - b∥ < ε, by simpa,
exact λ a b h h', h },
{ simp }
end }
-- This is a sanity check left here on purpose to ensure that potential refactors won't destroy
-- this important property.
example (S : add_subgroup M) : (quotient.topological_space : topological_space $ quotient S) =
S.semi_normed_group_quotient.to_uniform_space.to_topological_space :=
rfl
/-- The quotient in the category of normed groups. -/
noncomputable
instance add_subgroup.normed_group_quotient (S : add_subgroup M) [hS : is_closed (S : set M)] :
normed_group (quotient S) :=
{ eq_of_dist_eq_zero :=
begin
rintros ⟨m⟩ ⟨m'⟩ (h : ∥mk' S m - mk' S m'∥ = 0),
erw [← (mk' S).map_sub, quotient_norm_eq_zero_iff, hS.closure_eq,
← quotient_add_group.eq_iff_sub_mem] at h,
exact h
end,
.. add_subgroup.semi_normed_group_quotient S }
-- This is a sanity check left here on purpose to ensure that potential refactors won't destroy
-- this important property.
example (S : add_subgroup M) [is_closed (S : set M)] :
S.semi_normed_group_quotient = normed_group.to_semi_normed_group := rfl
namespace add_subgroup
open normed_group_hom
/-- The morphism from a seminormed group to the quotient by a subgroup. -/
noncomputable
def normed_mk (S : add_subgroup M) : normed_group_hom M (quotient S) :=
{ bound' := ⟨1, λ m, by simpa [one_mul] using quotient_norm_mk_le _ m⟩,
.. quotient_add_group.mk' S }
/-- `S.normed_mk` agrees with `quotient_add_group.mk' S`. -/
@[simp]
lemma normed_mk.apply (S : add_subgroup M) (m : M) : normed_mk S m = quotient_add_group.mk' S m :=
rfl
/-- `S.normed_mk` is surjective. -/
lemma surjective_normed_mk (S : add_subgroup M) : function.surjective (normed_mk S) :=
surjective_quot_mk _
/-- The kernel of `S.normed_mk` is `S`. -/
lemma ker_normed_mk (S : add_subgroup M) : S.normed_mk.ker = S :=
quotient_add_group.ker_mk _
/-- The operator norm of the projection is at most `1`. -/
lemma norm_normed_mk_le (S : add_subgroup M) : ∥S.normed_mk∥ ≤ 1 :=
normed_group_hom.op_norm_le_bound _ zero_le_one (λ m, by simp [quotient_norm_mk_le])
/-- The operator norm of the projection is `1` if the subspace is not dense. -/
lemma norm_normed_mk (S : add_subgroup M) (h : (S.topological_closure : set M) ≠ univ) :
∥S.normed_mk∥ = 1 :=
begin
obtain ⟨x, hx⟩ := set.nonempty_compl.2 h,
let y := S.normed_mk x,
have hy : ∥y∥ ≠ 0,
{ intro h0,
exact set.not_mem_of_mem_compl hx ((quotient_norm_eq_zero_iff S x).1 h0) },
refine le_antisymm (norm_normed_mk_le S) (le_of_forall_pos_le_add (λ ε hε, _)),
suffices : 1 ≤ ∥S.normed_mk∥ + min ε ((1 : ℝ)/2),
{ exact le_add_of_le_add_left this (min_le_left ε ((1 : ℝ)/2)) },
have hδ := sub_pos.mpr (lt_of_le_of_lt (min_le_right ε ((1 : ℝ)/2)) one_half_lt_one),
have hδpos : 0 < min ε ((1 : ℝ)/2) := lt_min hε one_half_pos,
have hδnorm := mul_pos (div_pos hδpos hδ) (lt_of_le_of_ne (norm_nonneg y) hy.symm),
obtain ⟨m, hm, hlt⟩ := norm_mk_lt y hδnorm,
have hrw : ∥y∥ + min ε (1 / 2) / (1 - min ε (1 / 2)) * ∥y∥ =
∥y∥ * (1 + min ε (1 / 2) / (1 - min ε (1 / 2))) := by ring,
rw [hrw] at hlt,
have hm0 : ∥m∥ ≠ 0,
{ intro h0,
have hnorm := quotient_norm_mk_le S m,
rw [h0, hm] at hnorm,
replace hnorm := le_antisymm hnorm (norm_nonneg _),
simpa [hnorm] using hy },
replace hlt := (div_lt_div_right (lt_of_le_of_ne (norm_nonneg m) hm0.symm)).2 hlt,
simp only [hm0, div_self, ne.def, not_false_iff] at hlt,
have hrw₁ : ∥y∥ * (1 + min ε (1 / 2) / (1 - min ε (1 / 2))) / ∥m∥ =
(∥y∥ / ∥m∥) * (1 + min ε (1 / 2) / (1 - min ε (1 / 2))) := by ring,
rw [hrw₁] at hlt,
replace hlt := (inv_pos_lt_iff_one_lt_mul (lt_trans (div_pos hδpos hδ) (lt_one_add _))).2 hlt,
suffices : ∥S.normed_mk∥ ≥ 1 - min ε (1 / 2),
{ exact sub_le_iff_le_add.mp this },
calc ∥S.normed_mk∥ ≥ ∥(S.normed_mk) m∥ / ∥m∥ : ratio_le_op_norm S.normed_mk m
... = ∥y∥ / ∥m∥ : by rw [normed_mk.apply, hm]
... ≥ (1 + min ε (1 / 2) / (1 - min ε (1 / 2)))⁻¹ : le_of_lt hlt
... = 1 - min ε (1 / 2) : by field_simp [(ne_of_lt hδ).symm]
end
/-- The operator norm of the projection is `0` if the subspace is dense. -/
lemma norm_trivial_quotient_mk (S : add_subgroup M)
(h : (S.topological_closure : set M) = set.univ) : ∥S.normed_mk∥ = 0 :=
begin
refine le_antisymm (op_norm_le_bound _ (le_refl _) (λ x, _)) (norm_nonneg _),
have hker : x ∈ (S.normed_mk).ker.topological_closure,
{ rw [S.ker_normed_mk],
exact set.mem_of_eq_of_mem h trivial },
rw [ker_normed_mk] at hker,
simp only [(quotient_norm_eq_zero_iff S x).mpr hker, normed_mk.apply, zero_mul],
end
end add_subgroup
namespace normed_group_hom
/-- `is_quotient f`, for `f : M ⟶ N` means that `N` is isomorphic to the quotient of `M`
by the kernel of `f`. -/
structure is_quotient (f : normed_group_hom M N) : Prop :=
(surjective : function.surjective f)
(norm : ∀ x, ∥f x∥ = Inf ((λ m, ∥x + m∥) '' f.ker))
/-- Given `f : normed_group_hom M N` such that `f s = 0` for all `s ∈ S`, where,
`S : add_subgroup M` is closed, the induced morphism `normed_group_hom (quotient S) N`. -/
noncomputable
def lift {N : Type*} [semi_normed_group N] (S : add_subgroup M)
(f : normed_group_hom M N) (hf : ∀ s ∈ S, f s = 0) :
normed_group_hom (quotient S) N :=
{ bound' :=
begin
obtain ⟨c : ℝ≥0, hcpos : (0 : ℝ) < c, hc : f.bound_by c⟩ := f.bound,
refine ⟨c, λ mbar, le_of_forall_pos_le_add (λ ε hε, _)⟩,
obtain ⟨m : M, rfl : mk' S m = mbar, hmnorm : ∥m∥ < ∥mk' S m∥ + ε/c⟩ :=
norm_mk_lt mbar (div_pos hε hcpos),
calc ∥f m∥ ≤ c * ∥m∥ : hc m
... ≤ c*(∥mk' S m∥ + ε/c) : ((mul_lt_mul_left hcpos).mpr hmnorm).le
... = c * ∥mk' S m∥ + ε : by rw [mul_add, mul_div_cancel' _ hcpos.ne.symm]
end,
.. quotient_add_group.lift S f.to_add_monoid_hom hf }
lemma lift_mk {N : Type*} [semi_normed_group N] (S : add_subgroup M)
(f : normed_group_hom M N) (hf : ∀ s ∈ S, f s = 0) (m : M) :
lift S f hf (S.normed_mk m) = f m := rfl
lemma lift_unique {N : Type*} [semi_normed_group N] (S : add_subgroup M)
(f : normed_group_hom M N) (hf : ∀ s ∈ S, f s = 0)
(g : normed_group_hom (quotient S) N) :
g.comp (S.normed_mk) = f → g = lift S f hf :=
begin
intro h,
ext,
rcases add_subgroup.surjective_normed_mk _ x with ⟨x,rfl⟩,
change (g.comp (S.normed_mk) x) = _,
simpa only [h]
end
/-- `S.normed_mk` satisfies `is_quotient`. -/
lemma is_quotient_quotient (S : add_subgroup M) : is_quotient (S.normed_mk) :=
⟨S.surjective_normed_mk, λ m, by simpa [S.ker_normed_mk] using quotient_norm_mk_eq _ m⟩
lemma is_quotient.norm_lift {f : normed_group_hom M N} (hquot : is_quotient f) {ε : ℝ} (hε : 0 < ε)
(n : N) : ∃ (m : M), f m = n ∧ ∥m∥ < ∥n∥ + ε :=
begin
obtain ⟨m, rfl⟩ := hquot.surjective n,
have nonemp : ((λ m', ∥m + m'∥) '' f.ker).nonempty,
{ rw set.nonempty_image_iff,
exact ⟨0, is_add_submonoid.zero_mem⟩ },
have bdd : bdd_below ((λ m', ∥m + m'∥) '' f.ker),
{ use 0,
rintro _ ⟨x, hx, rfl⟩,
apply norm_nonneg },
rcases real.lt_Inf_add_pos bdd nonemp hε with
⟨_, ⟨⟨x, hx, rfl⟩, H : ∥m + x∥ < Inf ((λ (m' : M), ∥m + m'∥) '' f.ker) + ε⟩⟩,
exact ⟨m+x, by rw [f.map_add,(normed_group_hom.mem_ker f x).mp hx, add_zero],
by rwa hquot.norm⟩,
end
lemma is_quotient.norm_le {f : normed_group_hom M N} (hquot : is_quotient f) (m : M) :
∥f m∥ ≤ ∥m∥ :=
begin
rw hquot.norm,
apply real.Inf_le,
{ use 0,
rintros _ ⟨m', hm', rfl⟩,
apply norm_nonneg },
{ exact ⟨0, f.ker.zero_mem, by simp⟩ }
end
end normed_group_hom
|
5ab37b7812a320cf400b393468b00352060a75b1 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/number_theory/cyclotomic/rat.lean | 0b065fea48e53049f747a79712e6d34e6072ebaa | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 12,779 | lean | /-
Copyright (c) 2022 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import number_theory.cyclotomic.discriminant
import ring_theory.polynomial.eisenstein
/-!
# Ring of integers of `p ^ n`-th cyclotomic fields
We gather results about cyclotomic extensions of `ℚ`. In particular, we compute the ring of
integers of a `p ^ n`-th cyclotomic extension of `ℚ`.
## Main results
* `is_cyclotomic_extension.rat.is_integral_closure_adjoing_singleton_of_prime_pow`: if `K` is a
`p ^ k`-th cyclotomic extension of `ℚ`, then `(adjoin ℤ {ζ})` is the integral closure of
`ℤ` in `K`.
* `is_cyclotomic_extension.rat.cyclotomic_ring_is_integral_closure_of_prime_pow`: the integral
closure of `ℤ` inside `cyclotomic_field (p ^ k) ℚ` is `cyclotomic_ring (p ^ k) ℤ ℚ`.
-/
universes u
open algebra is_cyclotomic_extension polynomial number_field
open_locale cyclotomic number_field nat
variables {p : ℕ+} {k : ℕ} {K : Type u} [field K] [char_zero K] {ζ : K} [hp : fact (p : ℕ).prime]
include hp
namespace is_cyclotomic_extension.rat
/-- The discriminant of the power basis given by `ζ - 1`. -/
lemma discr_prime_pow_ne_two' [is_cyclotomic_extension {p ^ (k + 1)} ℚ K]
(hζ : is_primitive_root ζ ↑(p ^ (k + 1))) (hk : p ^ (k + 1) ≠ 2) :
discr ℚ (hζ.sub_one_power_basis ℚ).basis =
(-1) ^ (((p ^ (k + 1) : ℕ).totient) / 2) * p ^ ((p : ℕ) ^ k * ((p - 1) * (k + 1) - 1)) :=
begin
rw [← discr_prime_pow_ne_two hζ (cyclotomic.irreducible_rat (p ^ (k + 1)).pos) hk],
exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm
end
lemma discr_odd_prime' [is_cyclotomic_extension {p} ℚ K] (hζ : is_primitive_root ζ p)
(hodd : p ≠ 2) :
discr ℚ (hζ.sub_one_power_basis ℚ).basis = (-1) ^ (((p : ℕ) - 1) / 2) * p ^ ((p : ℕ) - 2) :=
begin
rw [← discr_odd_prime hζ (cyclotomic.irreducible_rat hp.out.pos) hodd],
exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm
end
/-- The discriminant of the power basis given by `ζ - 1`. Beware that in the cases `p ^ k = 1` and
`p ^ k = 2` the formula uses `1 / 2 = 0` and `0 - 1 = 0`. It is useful only to have a uniform
result. See also `is_cyclotomic_extension.rat.discr_prime_pow_eq_unit_mul_pow'`. -/
lemma discr_prime_pow' [is_cyclotomic_extension {p ^ k} ℚ K]
(hζ : is_primitive_root ζ ↑(p ^ k)) :
discr ℚ (hζ.sub_one_power_basis ℚ).basis =
(-1) ^ (((p ^ k : ℕ).totient) / 2) * p ^ ((p : ℕ) ^ (k - 1) * ((p - 1) * k - 1)) :=
begin
rw [← discr_prime_pow hζ (cyclotomic.irreducible_rat (p ^ k).pos)],
exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm
end
/-- If `p` is a prime and `is_cyclotomic_extension {p ^ k} K L`, then there are `u : ℤˣ` and
`n : ℕ` such that the discriminant of the power basis given by `ζ - 1` is `u * p ^ n`. Often this is
enough and less cumbersome to use than `is_cyclotomic_extension.rat.discr_prime_pow'`. -/
lemma discr_prime_pow_eq_unit_mul_pow' [is_cyclotomic_extension {p ^ k} ℚ K]
(hζ : is_primitive_root ζ ↑(p ^ k)) :
∃ (u : ℤˣ) (n : ℕ), discr ℚ (hζ.sub_one_power_basis ℚ).basis = u * p ^ n :=
begin
rw [hζ.discr_zeta_eq_discr_zeta_sub_one.symm],
exact discr_prime_pow_eq_unit_mul_pow hζ (cyclotomic.irreducible_rat (p ^ k).pos)
end
/-- If `K` is a `p ^ k`-th cyclotomic extension of `ℚ`, then `(adjoin ℤ {ζ})` is the
integral closure of `ℤ` in `K`. -/
lemma is_integral_closure_adjoing_singleton_of_prime_pow
[hcycl : is_cyclotomic_extension {p ^ k} ℚ K] (hζ : is_primitive_root ζ ↑(p ^ k)) :
is_integral_closure (adjoin ℤ ({ζ} : set K)) ℤ K :=
begin
refine ⟨subtype.val_injective, λ x, ⟨λ h, ⟨⟨x, _⟩, rfl⟩, _⟩⟩,
swap,
{ rintro ⟨y, rfl⟩,
exact is_integral.algebra_map (le_integral_closure_iff_is_integral.1
(adjoin_le_integral_closure (hζ.is_integral (p ^ k).pos)) _) },
let B := hζ.sub_one_power_basis ℚ,
have hint : is_integral ℤ B.gen := is_integral_sub (hζ.is_integral (p ^ k).pos)
is_integral_one,
have H := discr_mul_is_integral_mem_adjoin ℚ hint h,
obtain ⟨u, n, hun⟩ := discr_prime_pow_eq_unit_mul_pow' hζ,
rw [hun] at H,
replace H := subalgebra.smul_mem _ H u.inv,
rw [← smul_assoc, ← smul_mul_assoc, units.inv_eq_coe_inv, coe_coe, zsmul_eq_mul,
← int.cast_mul, units.inv_mul, int.cast_one, one_mul,
show (p : ℚ) ^ n • x = ((p : ℕ) : ℤ) ^ n • x, by simp [smul_def]] at H,
unfreezingI { cases k },
{ haveI : is_cyclotomic_extension {1} ℚ K := by simpa using hcycl,
have : x ∈ (⊥ : subalgebra ℚ K),
{ rw [singleton_one ℚ K],
exact mem_top },
obtain ⟨y, rfl⟩ := mem_bot.1 this,
replace h := (is_integral_algebra_map_iff (algebra_map ℚ K).injective).1 h,
obtain ⟨z, hz⟩ := is_integrally_closed.is_integral_iff.1 h,
rw [← hz, ← is_scalar_tower.algebra_map_apply],
exact subalgebra.algebra_map_mem _ _ },
{ have hmin : (minpoly ℤ B.gen).is_eisenstein_at (submodule.span ℤ {((p : ℕ) : ℤ)}),
{ have h₁ := minpoly.gcd_domain_eq_field_fractions' ℚ hint,
have h₂ := hζ.minpoly_sub_one_eq_cyclotomic_comp
(cyclotomic.irreducible_rat (p ^ _).pos),
rw [is_primitive_root.sub_one_power_basis_gen] at h₁,
rw [h₁, ← map_cyclotomic_int, show int.cast_ring_hom ℚ = algebra_map ℤ ℚ, by refl,
show ((X + 1)) = map (algebra_map ℤ ℚ) (X + 1), by simp, ← map_comp] at h₂,
haveI : char_zero ℚ := ordered_semiring.to_char_zero,
rw [is_primitive_root.sub_one_power_basis_gen, map_injective (algebra_map ℤ ℚ)
((algebra_map ℤ ℚ).injective_int) h₂],
exact cyclotomic_prime_pow_comp_X_add_one_is_eisenstein_at _ _ },
refine adjoin_le _ (mem_adjoin_of_smul_prime_pow_smul_of_minpoly_is_eiseinstein_at
(nat.prime_iff_prime_int.1 hp.out) hint h H hmin),
simp only [set.singleton_subset_iff, set_like.mem_coe],
exact subalgebra.sub_mem _ (self_mem_adjoin_singleton ℤ _) (subalgebra.one_mem _) }
end
lemma is_integral_closure_adjoing_singleton_of_prime [hcycl : is_cyclotomic_extension {p} ℚ K]
(hζ : is_primitive_root ζ ↑p) :
is_integral_closure (adjoin ℤ ({ζ} : set K)) ℤ K :=
begin
rw [← pow_one p] at hζ hcycl,
exactI is_integral_closure_adjoing_singleton_of_prime_pow hζ,
end
local attribute [-instance] cyclotomic_field.algebra
/-- The integral closure of `ℤ` inside `cyclotomic_field (p ^ k) ℚ` is
`cyclotomic_ring (p ^ k) ℤ ℚ`. -/
lemma cyclotomic_ring_is_integral_closure_of_prime_pow :
is_integral_closure (cyclotomic_ring (p ^ k) ℤ ℚ) ℤ (cyclotomic_field (p ^ k) ℚ) :=
begin
haveI : char_zero ℚ := ordered_semiring.to_char_zero,
haveI : is_cyclotomic_extension {p ^ k} ℚ (cyclotomic_field (p ^ k) ℚ),
{ convert cyclotomic_field.is_cyclotomic_extension (p ^ k) _,
{ exact subsingleton.elim _ _ },
{ exact ne_zero.char_zero } },
have hζ := zeta_spec (p ^ k) ℚ (cyclotomic_field (p ^ k) ℚ),
refine ⟨is_fraction_ring.injective _ _, λ x, ⟨λ h, ⟨⟨x, _⟩, rfl⟩, _⟩⟩,
{ have := (is_integral_closure_adjoing_singleton_of_prime_pow hζ).is_integral_iff,
obtain ⟨y, rfl⟩ := this.1 h,
convert adjoin_mono _ y.2,
{ simp only [eq_iff_true_of_subsingleton] },
{ simp only [eq_iff_true_of_subsingleton] },
{ simp only [pnat.pow_coe, set.singleton_subset_iff, set.mem_set_of_eq],
exact hζ.pow_eq_one } },
{ haveI : is_cyclotomic_extension {p ^ k} ℤ (cyclotomic_ring (p ^ k) ℤ ℚ),
{ convert cyclotomic_ring.is_cyclotomic_extension _ ℤ ℚ,
{ exact subsingleton.elim _ _ },
{ exact ne_zero.char_zero } },
rintro ⟨y, rfl⟩,
exact is_integral.algebra_map ((is_cyclotomic_extension.integral {p ^ k} ℤ _) _) }
end
lemma cyclotomic_ring_is_integral_closure_of_prime :
is_integral_closure (cyclotomic_ring p ℤ ℚ) ℤ (cyclotomic_field p ℚ) :=
begin
rw [← pow_one p],
exact cyclotomic_ring_is_integral_closure_of_prime_pow
end
end is_cyclotomic_extension.rat
section power_basis
open is_cyclotomic_extension.rat
namespace is_primitive_root
/-- The algebra isomorphism `adjoin ℤ {ζ} ≃ₐ[ℤ] (𝓞 K)`, where `ζ` is a primitive `p ^ k`-th root of
unity and `K` is a `p ^ k`-th cyclotomic extension of `ℚ`. -/
@[simps] noncomputable def _root_.is_primitive_root.adjoin_equiv_ring_of_integers
[hcycl : is_cyclotomic_extension {p ^ k} ℚ K] (hζ : is_primitive_root ζ ↑(p ^ k)) :
adjoin ℤ ({ζ} : set K) ≃ₐ[ℤ] (𝓞 K) :=
let _ := is_integral_closure_adjoing_singleton_of_prime_pow hζ in
by exactI (is_integral_closure.equiv ℤ (adjoin ℤ ({ζ} : set K)) K (𝓞 K))
/-- The integral `power_basis` of `𝓞 K` given by a primitive root of unity, where `K` is a `p ^ k`
cyclotomic extension of `ℚ`. -/
noncomputable def integral_power_basis [hcycl : is_cyclotomic_extension {p ^ k} ℚ K]
(hζ : is_primitive_root ζ ↑(p ^ k)) : power_basis ℤ (𝓞 K) :=
(adjoin.power_basis' (hζ.is_integral (p ^ k).pos)).map hζ.adjoin_equiv_ring_of_integers
@[simp] lemma integral_power_basis_gen [hcycl : is_cyclotomic_extension {p ^ k} ℚ K]
(hζ : is_primitive_root ζ ↑(p ^ k)) :
hζ.integral_power_basis.gen = ⟨ζ, hζ.is_integral (p ^ k).pos⟩ :=
subtype.ext $ show algebra_map _ K hζ.integral_power_basis.gen = _, by simpa [integral_power_basis]
@[simp] lemma integral_power_basis_dim [hcycl : is_cyclotomic_extension {p ^ k} ℚ K]
(hζ : is_primitive_root ζ ↑(p ^ k)) : hζ.integral_power_basis.dim = φ (p ^ k) :=
by simp [integral_power_basis, ←cyclotomic_eq_minpoly hζ, nat_degree_cyclotomic]
/-- The algebra isomorphism `adjoin ℤ {ζ} ≃ₐ[ℤ] (𝓞 K)`, where `ζ` is a primitive `p`-th root of
unity and `K` is a `p`-th cyclotomic extension of `ℚ`. -/
@[simps] noncomputable def _root_.is_primitive_root.adjoin_equiv_ring_of_integers'
[hcycl : is_cyclotomic_extension {p} ℚ K] (hζ : is_primitive_root ζ p) :
adjoin ℤ ({ζ} : set K) ≃ₐ[ℤ] (𝓞 K) :=
@adjoin_equiv_ring_of_integers p 1 K _ _ _ _ (by { convert hcycl, rw pow_one }) (by rwa pow_one)
/-- The integral `power_basis` of `𝓞 K` given by a primitive root of unity, where `K` is a `p`-th
cyclotomic extension of `ℚ`. -/
noncomputable def integral_power_basis' [hcycl : is_cyclotomic_extension {p} ℚ K]
(hζ : is_primitive_root ζ p) : power_basis ℤ (𝓞 K) :=
@integral_power_basis p 1 K _ _ _ _ (by { convert hcycl, rw pow_one }) (by rwa pow_one)
@[simp] lemma integral_power_basis'_gen [hcycl : is_cyclotomic_extension {p} ℚ K]
(hζ : is_primitive_root ζ p) : hζ.integral_power_basis'.gen = ⟨ζ, hζ.is_integral p.pos⟩ :=
@integral_power_basis_gen p 1 K _ _ _ _ (by { convert hcycl, rw pow_one }) (by rwa pow_one)
@[simp] lemma power_basis_int'_dim [hcycl : is_cyclotomic_extension {p} ℚ K]
(hζ : is_primitive_root ζ p) : hζ.integral_power_basis'.dim = φ p :=
by erw [@integral_power_basis_dim p 1 K _ _ _ _ (by { convert hcycl, rw pow_one })
(by rwa pow_one), pow_one]
/-- The integral `power_basis` of `𝓞 K` given by `ζ - 1`, where `K` is a `p ^ k` cyclotomic
extension of `ℚ`. -/
noncomputable def sub_one_integral_power_basis [is_cyclotomic_extension {p ^ k} ℚ K]
(hζ : is_primitive_root ζ ↑(p ^ k)) : power_basis ℤ (𝓞 K) :=
power_basis.of_gen_mem_adjoin' hζ.integral_power_basis (is_integral_of_mem_ring_of_integers $
subalgebra.sub_mem _ (hζ.is_integral (p ^ k).pos) (subalgebra.one_mem _))
begin
simp only [integral_power_basis_gen],
convert subalgebra.add_mem _
(self_mem_adjoin_singleton ℤ (⟨ζ - 1, _⟩ : 𝓞 K))
(subalgebra.one_mem _),
simp
end
@[simp] lemma sub_one_integral_power_basis_gen [is_cyclotomic_extension {p ^ k} ℚ K]
(hζ : is_primitive_root ζ ↑(p ^ k)) :
hζ.sub_one_integral_power_basis.gen =
⟨ζ - 1, subalgebra.sub_mem _ (hζ.is_integral (p ^ k).pos) (subalgebra.one_mem _)⟩ :=
by simp [sub_one_integral_power_basis]
/-- The integral `power_basis` of `𝓞 K` given by `ζ - 1`, where `K` is a `p`-th cyclotomic
extension of `ℚ`. -/
noncomputable def sub_one_integral_power_basis' [hcycl : is_cyclotomic_extension {p} ℚ K]
(hζ : is_primitive_root ζ p) : power_basis ℤ (𝓞 K) :=
@sub_one_integral_power_basis p 1 K _ _ _ _ (by { convert hcycl, rw pow_one }) (by rwa pow_one)
@[simp] lemma sub_one_integral_power_basis'_gen [hcycl : is_cyclotomic_extension {p} ℚ K]
(hζ : is_primitive_root ζ p) :
hζ.sub_one_integral_power_basis'.gen =
⟨ζ - 1, subalgebra.sub_mem _ (hζ.is_integral p.pos) (subalgebra.one_mem _)⟩ :=
@sub_one_integral_power_basis_gen p 1 K _ _ _ _ (by { convert hcycl, rw pow_one }) (by rwa pow_one)
end is_primitive_root
end power_basis
|
fa562a7e85f5061c72759029cd06434e9bb36008 | 649957717d58c43b5d8d200da34bf374293fe739 | /src/category_theory/adjunction/basic.lean | 90eda607d0b30d2580be063b09c2f9fdd9a4ba00 | [
"Apache-2.0"
] | permissive | Vtec234/mathlib | b50c7b21edea438df7497e5ed6a45f61527f0370 | fb1848bbbfce46152f58e219dc0712f3289d2b20 | refs/heads/master | 1,592,463,095,113 | 1,562,737,749,000 | 1,562,737,749,000 | 196,202,858 | 0 | 0 | Apache-2.0 | 1,562,762,338,000 | 1,562,762,337,000 | null | UTF-8 | Lean | false | false | 10,818 | lean | /-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Johan Commelin
-/
import category_theory.equivalence
import data.equiv.basic
namespace category_theory
open category
universes v₁ v₂ v₃ u₁ u₂ u₃ -- declare the `v`'s first; see `category_theory.category` for an explanation
local attribute [elab_simple] whisker_left whisker_right
variables {C : Type u₁} [𝒞 : category.{v₁} C] {D : Type u₂} [𝒟 : category.{v₂} D]
include 𝒞 𝒟
/--
`F ⊣ G` represents the data of an adjunction between two functors
`F : C ⥤ D` and `G : D ⥤ C`. `F` is the left adjoint and `G` is the right adjoint.
-/
structure adjunction (F : C ⥤ D) (G : D ⥤ C) :=
(hom_equiv : Π (X Y), (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y))
(unit : functor.id C ⟶ F.comp G)
(counit : G.comp F ⟶ functor.id D)
(hom_equiv_unit' : Π {X Y f}, (hom_equiv X Y) f = (unit : _ ⟶ _).app X ≫ G.map f . obviously)
(hom_equiv_counit' : Π {X Y g}, (hom_equiv X Y).symm g = F.map g ≫ counit.app Y . obviously)
infix ` ⊣ `:15 := adjunction
class is_left_adjoint (left : C ⥤ D) :=
(right : D ⥤ C)
(adj : left ⊣ right)
class is_right_adjoint (right : D ⥤ C) :=
(left : C ⥤ D)
(adj : left ⊣ right)
namespace adjunction
restate_axiom hom_equiv_unit'
restate_axiom hom_equiv_counit'
attribute [simp, priority 1] hom_equiv_unit hom_equiv_counit
section
variables {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) {X' X : C} {Y Y' : D}
@[simp, priority 1] lemma hom_equiv_naturality_left_symm (f : X' ⟶ X) (g : X ⟶ G.obj Y) :
(adj.hom_equiv X' Y).symm (f ≫ g) = F.map f ≫ (adj.hom_equiv X Y).symm g :=
by rw [hom_equiv_counit, F.map_comp, assoc, adj.hom_equiv_counit.symm]
@[simp] lemma hom_equiv_naturality_left (f : X' ⟶ X) (g : F.obj X ⟶ Y) :
(adj.hom_equiv X' Y) (F.map f ≫ g) = f ≫ (adj.hom_equiv X Y) g :=
by rw [← equiv.eq_symm_apply]; simp [-hom_equiv_unit]
@[simp, priority 1] lemma hom_equiv_naturality_right (f : F.obj X ⟶ Y) (g : Y ⟶ Y') :
(adj.hom_equiv X Y') (f ≫ g) = (adj.hom_equiv X Y) f ≫ G.map g :=
by rw [hom_equiv_unit, G.map_comp, ← assoc, ←hom_equiv_unit]
@[simp] lemma hom_equiv_naturality_right_symm (f : X ⟶ G.obj Y) (g : Y ⟶ Y') :
(adj.hom_equiv X Y').symm (f ≫ G.map g) = (adj.hom_equiv X Y).symm f ≫ g :=
by rw [equiv.symm_apply_eq]; simp [-hom_equiv_counit]
@[simp] lemma left_triangle :
(whisker_right adj.unit F) ≫ (whisker_left F adj.counit) = nat_trans.id _ :=
begin
ext1 X, dsimp,
erw [← adj.hom_equiv_counit, equiv.symm_apply_eq, adj.hom_equiv_unit],
simp
end
@[simp] lemma right_triangle :
(whisker_left G adj.unit) ≫ (whisker_right adj.counit G) = nat_trans.id _ :=
begin
ext1 Y, dsimp,
erw [← adj.hom_equiv_unit, ← equiv.eq_symm_apply, adj.hom_equiv_counit],
simp
end
@[simp] lemma left_triangle_components :
F.map (adj.unit.app X) ≫ adj.counit.app (F.obj X) = 𝟙 (F.obj X) :=
congr_arg (λ (t : nat_trans _ (functor.id C ⋙ F)), t.app X) adj.left_triangle
@[simp] lemma right_triangle_components {Y : D} :
adj.unit.app (G.obj Y) ≫ G.map (adj.counit.app Y) = 𝟙 (G.obj Y) :=
congr_arg (λ (t : nat_trans _ (G ⋙ functor.id C)), t.app Y) adj.right_triangle
@[simp] lemma left_triangle_components_assoc {Z : D} (f : F.obj X ⟶ Z) :
F.map (adj.unit.app X) ≫ adj.counit.app (F.obj X) ≫ f = f :=
by { rw [←assoc], dsimp, simp }
@[simp] lemma right_triangle_components_assoc {Y : D} {Z : C} (f : G.obj Y ⟶ Z) :
adj.unit.app (G.obj Y) ≫ G.map (adj.counit.app Y) ≫ f = f :=
by { rw [←assoc], dsimp, simp }
@[simp] lemma counit_naturality {X Y : D} (f : X ⟶ Y) :
F.map (G.map f) ≫ (adj.counit).app Y = (adj.counit).app X ≫ f :=
adj.counit.naturality f
@[simp] lemma unit_naturality {X Y : C} (f : X ⟶ Y) :
(adj.unit).app X ≫ G.map (F.map f) = f ≫ (adj.unit).app Y :=
(adj.unit.naturality f).symm
@[simp] lemma counit_naturality_assoc {X Y Z : D} (f : X ⟶ Y) (g : Y ⟶ Z) :
F.map (G.map f) ≫ (adj.counit).app Y ≫ g = (adj.counit).app X ≫ f ≫ g :=
by { rw [←assoc], dsimp, simp }
@[simp] lemma unit_naturality_assoc {X Y Z : C} (f : X ⟶ Y) (g : G.obj (F.obj Y) ⟶ Z) :
(adj.unit).app X ≫ G.map (F.map f) ≫ g = f ≫ (adj.unit).app Y ≫ g :=
by { rw [←assoc], dsimp, simp }
end
structure core_hom_equiv (F : C ⥤ D) (G : D ⥤ C) :=
(hom_equiv : Π (X Y), (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y))
(hom_equiv_naturality_left_symm' : Π {X' X Y} (f : X' ⟶ X) (g : X ⟶ G.obj Y),
(hom_equiv X' Y).symm (f ≫ g) = F.map f ≫ (hom_equiv X Y).symm g . obviously)
(hom_equiv_naturality_right' : Π {X Y Y'} (f : F.obj X ⟶ Y) (g : Y ⟶ Y'),
(hom_equiv X Y') (f ≫ g) = (hom_equiv X Y) f ≫ G.map g . obviously)
namespace core_hom_equiv
restate_axiom hom_equiv_naturality_left_symm'
restate_axiom hom_equiv_naturality_right'
attribute [simp, priority 1] hom_equiv_naturality_left_symm hom_equiv_naturality_right
variables {F : C ⥤ D} {G : D ⥤ C} (adj : core_hom_equiv F G) {X' X : C} {Y Y' : D}
@[simp] lemma hom_equiv_naturality_left (f : X' ⟶ X) (g : F.obj X ⟶ Y) :
(adj.hom_equiv X' Y) (F.map f ≫ g) = f ≫ (adj.hom_equiv X Y) g :=
by rw [← equiv.eq_symm_apply]; simp
@[simp] lemma hom_equiv_naturality_right_symm (f : X ⟶ G.obj Y) (g : Y ⟶ Y') :
(adj.hom_equiv X Y').symm (f ≫ G.map g) = (adj.hom_equiv X Y).symm f ≫ g :=
by rw [equiv.symm_apply_eq]; simp
end core_hom_equiv
structure core_unit_counit (F : C ⥤ D) (G : D ⥤ C) :=
(unit : functor.id C ⟶ F.comp G)
(counit : G.comp F ⟶ functor.id D)
(left_triangle' : whisker_right unit F ≫ whisker_left F counit = nat_trans.id _ . obviously)
(right_triangle' : whisker_left G unit ≫ whisker_right counit G = nat_trans.id _ . obviously)
namespace core_unit_counit
restate_axiom left_triangle'
restate_axiom right_triangle'
attribute [simp] left_triangle right_triangle
end core_unit_counit
variables {F : C ⥤ D} {G : D ⥤ C}
def mk_of_hom_equiv (adj : core_hom_equiv F G) : F ⊣ G :=
{ unit :=
{ app := λ X, (adj.hom_equiv X (F.obj X)) (𝟙 (F.obj X)),
naturality' :=
begin
intros,
erw [← adj.hom_equiv_naturality_left, ← adj.hom_equiv_naturality_right],
dsimp, simp
end },
counit :=
{ app := λ Y, (adj.hom_equiv _ _).inv_fun (𝟙 (G.obj Y)),
naturality' :=
begin
intros,
erw [← adj.hom_equiv_naturality_left_symm, ← adj.hom_equiv_naturality_right_symm],
dsimp, simp
end },
hom_equiv_unit' := λ X Y f, by erw [← adj.hom_equiv_naturality_right]; simp,
hom_equiv_counit' := λ X Y f, by erw [← adj.hom_equiv_naturality_left_symm]; simp,
.. adj }
def mk_of_unit_counit (adj : core_unit_counit F G) : F ⊣ G :=
{ hom_equiv := λ X Y,
{ to_fun := λ f, adj.unit.app X ≫ G.map f,
inv_fun := λ g, F.map g ≫ adj.counit.app Y,
left_inv := λ f, begin
change F.map (_ ≫ _) ≫ _ = _,
rw [F.map_comp, assoc, ←functor.comp_map, adj.counit.naturality, ←assoc],
convert id_comp _ f,
exact congr_arg (λ t : nat_trans _ _, t.app _) adj.left_triangle
end,
right_inv := λ g, begin
change _ ≫ G.map (_ ≫ _) = _,
rw [G.map_comp, ←assoc, ←functor.comp_map, ←adj.unit.naturality, assoc],
convert comp_id _ g,
exact congr_arg (λ t : nat_trans _ _, t.app _) adj.right_triangle
end },
.. adj }
section
omit 𝒟
def id : functor.id C ⊣ functor.id C :=
{ hom_equiv := λ X Y, equiv.refl _,
unit := 𝟙 _,
counit := 𝟙 _ }
end
section
variables {E : Type u₃} [ℰ : category.{v₃} E] (H : D ⥤ E) (I : E ⥤ D)
def comp (adj₁ : F ⊣ G) (adj₂ : H ⊣ I) : F ⋙ H ⊣ I ⋙ G :=
{ hom_equiv := λ X Z, equiv.trans (adj₂.hom_equiv _ _) (adj₁.hom_equiv _ _),
unit := adj₁.unit ≫
(whisker_left F $ whisker_right adj₂.unit G) ≫ (functor.associator _ _ _).inv,
counit := (functor.associator _ _ _).hom ≫
(whisker_left I $ whisker_right adj₁.counit H) ≫ adj₂.counit }
end
section construct_left
-- Construction of a left adjoint. In order to construct a left
-- adjoint to a functor G : D → C, it suffices to give the object part
-- of a functor F : C → D together with isomorphisms Hom(FX, Y) ≃
-- Hom(X, GY) natural in Y. The action of F on morphisms can be
-- constructed from this data.
variables {F_obj : C → D} {G}
variables (e : Π X Y, (F_obj X ⟶ Y) ≃ (X ⟶ G.obj Y))
variables (he : Π X Y Y' g h, e X Y' (h ≫ g) = e X Y h ≫ G.map g)
include he
private lemma he' {X Y Y'} (f g) : (e X Y').symm (f ≫ G.map g) = (e X Y).symm f ≫ g :=
by intros; rw [equiv.symm_apply_eq, he]; simp
def left_adjoint_of_equiv : C ⥤ D :=
{ obj := F_obj,
map := λ X X' f, (e X (F_obj X')).symm (f ≫ e X' (F_obj X') (𝟙 _)),
map_comp' := λ X X' X'' f f', begin
rw [equiv.symm_apply_eq, he, equiv.apply_symm_apply],
conv { to_rhs, rw [assoc, ←he, id_comp, equiv.apply_symm_apply] },
simp
end }
def adjunction_of_equiv_left : left_adjoint_of_equiv e he ⊣ G :=
mk_of_hom_equiv
{ hom_equiv := e,
hom_equiv_naturality_left_symm' :=
begin
intros,
erw [← he' e he, ← equiv.apply_eq_iff_eq],
simp [(he _ _ _ _ _).symm]
end }
end construct_left
section construct_right
-- Construction of a right adjoint, analogous to the above.
variables {F} {G_obj : D → C}
variables (e : Π X Y, (F.obj X ⟶ Y) ≃ (X ⟶ G_obj Y))
variables (he : Π X' X Y f g, e X' Y (F.map f ≫ g) = f ≫ e X Y g)
include he
private lemma he' {X' X Y} (f g) : F.map f ≫ (e X Y).symm g = (e X' Y).symm (f ≫ g) :=
by intros; rw [equiv.eq_symm_apply, he]; simp
def right_adjoint_of_equiv : D ⥤ C :=
{ obj := G_obj,
map := λ Y Y' g, (e (G_obj Y) Y') ((e (G_obj Y) Y).symm (𝟙 _) ≫ g),
map_comp' := λ Y Y' Y'' g g', begin
rw [← equiv.eq_symm_apply, ← he' e he, equiv.symm_apply_apply],
conv { to_rhs, rw [← assoc, he' e he, comp_id, equiv.symm_apply_apply] },
simp
end }
def adjunction_of_equiv_right : F ⊣ right_adjoint_of_equiv e he :=
mk_of_hom_equiv
{ hom_equiv := e,
hom_equiv_naturality_left_symm' := by intros; rw [equiv.symm_apply_eq, he]; simp,
hom_equiv_naturality_right' :=
begin
intros X Y Y' g h,
erw [←he, equiv.apply_eq_iff_eq, ←assoc, he' e he, comp_id, equiv.symm_apply_apply]
end }
end construct_right
end adjunction
open adjunction
namespace equivalence
def to_adjunction (e : C ≌ D) : e.functor ⊣ e.inverse :=
mk_of_unit_counit ⟨e.unit, e.counit, by { ext, exact e.functor_unit_comp X },
by { ext, exact e.unit_inverse_comp X }⟩
end equivalence
namespace functor
def adjunction (E : C ⥤ D) [is_equivalence E] : E ⊣ E.inv :=
(E.as_equivalence).to_adjunction
end functor
end category_theory
|
487e5476f05355e0b49cf6c11db75a129410c01e | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/pnat/prime.lean | fcd0e6f6fe8c1aacf5a2abaa7d2df6bb0643059a | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 7,503 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Neil Strickland
-/
import data.nat.prime
import data.pnat.basic
/-!
# Primality and GCD on pnat
This file extends the theory of `ℕ+` with `gcd`, `lcm` and `prime` functions, analogous to those on
`nat`.
-/
namespace nat.primes
instance coe_pnat : has_coe nat.primes ℕ+ := ⟨λ p, ⟨(p : ℕ), p.property.pos⟩⟩
theorem coe_pnat_nat (p : nat.primes) : ((p : ℕ+) : ℕ) = p := rfl
theorem coe_pnat_inj (p q : nat.primes) : (p : ℕ+) = (q : ℕ+) → p = q := λ h,
begin
replace h : ((p : ℕ+) : ℕ) = ((q : ℕ+) : ℕ) := congr_arg subtype.val h,
rw [coe_pnat_nat, coe_pnat_nat] at h,
exact subtype.eq h,
end
end nat.primes
namespace pnat
open _root_.nat
/-- The greatest common divisor (gcd) of two positive natural numbers,
viewed as positive natural number. -/
def gcd (n m : ℕ+) : ℕ+ :=
⟨nat.gcd (n : ℕ) (m : ℕ), nat.gcd_pos_of_pos_left (m : ℕ) n.pos⟩
/-- The least common multiple (lcm) of two positive natural numbers,
viewed as positive natural number. -/
def lcm (n m : ℕ+) : ℕ+ :=
⟨nat.lcm (n : ℕ) (m : ℕ),
by { let h := mul_pos n.pos m.pos,
rw [← gcd_mul_lcm (n : ℕ) (m : ℕ), mul_comm] at h,
exact pos_of_dvd_of_pos (dvd.intro (nat.gcd (n : ℕ) (m : ℕ)) rfl) h }⟩
@[simp] theorem gcd_coe (n m : ℕ+) : ((gcd n m) : ℕ) = nat.gcd n m := rfl
@[simp] theorem lcm_coe (n m : ℕ+) : ((lcm n m) : ℕ) = nat.lcm n m := rfl
theorem gcd_dvd_left (n m : ℕ+) : (gcd n m) ∣ n := dvd_iff.2 (nat.gcd_dvd_left (n : ℕ) (m : ℕ))
theorem gcd_dvd_right (n m : ℕ+) : (gcd n m) ∣ m := dvd_iff.2 (nat.gcd_dvd_right (n : ℕ) (m : ℕ))
theorem dvd_gcd {m n k : ℕ+} (hm : k ∣ m) (hn : k ∣ n) : k ∣ gcd m n :=
dvd_iff.2 (@nat.dvd_gcd (m : ℕ) (n : ℕ) (k : ℕ) (dvd_iff.1 hm) (dvd_iff.1 hn))
theorem dvd_lcm_left (n m : ℕ+) : n ∣ lcm n m := dvd_iff.2 (nat.dvd_lcm_left (n : ℕ) (m : ℕ))
theorem dvd_lcm_right (n m : ℕ+) : m ∣ lcm n m := dvd_iff.2 (nat.dvd_lcm_right (n : ℕ) (m : ℕ))
theorem lcm_dvd {m n k : ℕ+} (hm : m ∣ k) (hn : n ∣ k) : lcm m n ∣ k :=
dvd_iff.2 (@nat.lcm_dvd (m : ℕ) (n : ℕ) (k : ℕ) (dvd_iff.1 hm) (dvd_iff.1 hn))
theorem gcd_mul_lcm (n m : ℕ+) : (gcd n m) * (lcm n m) = n * m :=
subtype.eq (nat.gcd_mul_lcm (n : ℕ) (m : ℕ))
lemma eq_one_of_lt_two {n : ℕ+} : n < 2 → n = 1 :=
begin
intro h, apply le_antisymm, swap, apply pnat.one_le,
change n < 1 + 1 at h, rw pnat.lt_add_one_iff at h, apply h
end
section prime
/-! ### Prime numbers -/
/-- Primality predicate for `ℕ+`, defined in terms of `nat.prime`. -/
def prime (p : ℕ+) : Prop := (p : ℕ).prime
lemma prime.one_lt {p : ℕ+} : p.prime → 1 < p := nat.prime.one_lt
lemma prime_two : (2 : ℕ+).prime := nat.prime_two
lemma dvd_prime {p m : ℕ+} (pp : p.prime) :
(m ∣ p ↔ m = 1 ∨ m = p) := by { rw pnat.dvd_iff, rw nat.dvd_prime pp, simp }
lemma prime.ne_one {p : ℕ+} : p.prime → p ≠ 1 :=
by { intro pp, intro contra, apply nat.prime.ne_one pp, rw pnat.coe_eq_one_iff, apply contra }
@[simp]
lemma not_prime_one : ¬ (1: ℕ+).prime := nat.not_prime_one
lemma prime.not_dvd_one {p : ℕ+} :
p.prime → ¬ p ∣ 1 := λ pp : p.prime, by {rw dvd_iff, apply nat.prime.not_dvd_one pp}
lemma exists_prime_and_dvd {n : ℕ+} (hn : n ≠ 1) : (∃ (p : ℕ+), p.prime ∧ p ∣ n) :=
begin
obtain ⟨p, hp⟩ := nat.exists_prime_and_dvd (mt coe_eq_one_iff.mp hn),
existsi (⟨p, nat.prime.pos hp.left⟩ : ℕ+), rw dvd_iff, apply hp
end
end prime
section coprime
/-! ### Coprime numbers and gcd -/
/-- Two pnats are coprime if their gcd is 1. -/
def coprime (m n : ℕ+) : Prop := m.gcd n = 1
@[simp]
lemma coprime_coe {m n : ℕ+} : nat.coprime ↑m ↑n ↔ m.coprime n :=
by { unfold coprime, unfold nat.coprime, rw ← coe_inj, simp }
lemma coprime.mul {k m n : ℕ+} : m.coprime k → n.coprime k → (m * n).coprime k :=
by { repeat {rw ← coprime_coe}, rw mul_coe, apply nat.coprime.mul }
lemma coprime.mul_right {k m n : ℕ+} : k.coprime m → k.coprime n → k.coprime (m * n) :=
by { repeat {rw ← coprime_coe}, rw mul_coe, apply nat.coprime.mul_right }
lemma gcd_comm {m n : ℕ+} : m.gcd n = n.gcd m :=
by { apply eq, simp only [gcd_coe], apply nat.gcd_comm }
lemma gcd_eq_left_iff_dvd {m n : ℕ+} : m ∣ n ↔ m.gcd n = m :=
by { rw dvd_iff, rw nat.gcd_eq_left_iff_dvd, rw ← coe_inj, simp }
lemma gcd_eq_right_iff_dvd {m n : ℕ+} : m ∣ n ↔ n.gcd m = m :=
by { rw gcd_comm, apply gcd_eq_left_iff_dvd, }
lemma coprime.gcd_mul_left_cancel (m : ℕ+) {n k : ℕ+} :
k.coprime n → (k * m).gcd n = m.gcd n :=
begin
intro h, apply eq, simp only [gcd_coe, mul_coe],
apply nat.coprime.gcd_mul_left_cancel, simpa
end
lemma coprime.gcd_mul_right_cancel (m : ℕ+) {n k : ℕ+} :
k.coprime n → (m * k).gcd n = m.gcd n :=
begin
rw mul_comm, apply coprime.gcd_mul_left_cancel,
end
lemma coprime.gcd_mul_left_cancel_right (m : ℕ+) {n k : ℕ+} :
k.coprime m → m.gcd (k * n) = m.gcd n :=
begin
intro h, iterate 2 {rw gcd_comm, symmetry}, apply coprime.gcd_mul_left_cancel _ h,
end
lemma coprime.gcd_mul_right_cancel_right (m : ℕ+) {n k : ℕ+} :
k.coprime m → m.gcd (n * k) = m.gcd n :=
begin
rw mul_comm, apply coprime.gcd_mul_left_cancel_right,
end
@[simp]
lemma one_gcd {n : ℕ+} : gcd 1 n = 1 :=
by { rw ← gcd_eq_left_iff_dvd, apply one_dvd }
@[simp]
lemma gcd_one {n : ℕ+} : gcd n 1 = 1 := by { rw gcd_comm, apply one_gcd }
@[symm]
lemma coprime.symm {m n : ℕ+} : m.coprime n → n.coprime m :=
by { unfold coprime, rw gcd_comm, simp }
@[simp]
lemma one_coprime {n : ℕ+} : (1 : ℕ+).coprime n := one_gcd
@[simp]
lemma coprime_one {n : ℕ+} : n.coprime 1 := coprime.symm one_coprime
lemma coprime.coprime_dvd_left {m k n : ℕ+} :
m ∣ k → k.coprime n → m.coprime n :=
by { rw dvd_iff, repeat {rw ← coprime_coe}, apply nat.coprime.coprime_dvd_left }
lemma coprime.factor_eq_gcd_left {a b m n : ℕ+} (cop : m.coprime n) (am : a ∣ m) (bn : b ∣ n) :
a = (a * b).gcd m :=
begin
rw gcd_eq_left_iff_dvd at am,
conv_lhs {rw ← am}, symmetry,
apply coprime.gcd_mul_right_cancel a,
apply coprime.coprime_dvd_left bn cop.symm,
end
lemma coprime.factor_eq_gcd_right {a b m n : ℕ+} (cop : m.coprime n) (am : a ∣ m) (bn : b ∣ n) :
a = (b * a).gcd m :=
begin
rw mul_comm, apply coprime.factor_eq_gcd_left cop am bn,
end
lemma coprime.factor_eq_gcd_left_right {a b m n : ℕ+}
(cop : m.coprime n) (am : a ∣ m) (bn : b ∣ n) : a = m.gcd (a * b) :=
begin
rw gcd_comm, apply coprime.factor_eq_gcd_left cop am bn,
end
lemma coprime.factor_eq_gcd_right_right {a b m n : ℕ+}
(cop : m.coprime n) (am : a ∣ m) (bn : b ∣ n) : a = m.gcd (b * a) :=
begin
rw gcd_comm, apply coprime.factor_eq_gcd_right cop am bn,
end
lemma coprime.gcd_mul (k : ℕ+) {m n : ℕ+} (h: m.coprime n) :
k.gcd (m * n) = k.gcd m * k.gcd n :=
begin
rw ← coprime_coe at h, apply eq,
simp only [gcd_coe, mul_coe], apply nat.coprime.gcd_mul k h
end
lemma gcd_eq_left {m n : ℕ+} : m ∣ n → m.gcd n = m :=
by { rw dvd_iff, intro h, apply eq, simp only [gcd_coe], apply nat.gcd_eq_left h }
lemma coprime.pow {m n : ℕ+} (k l : ℕ) (h : m.coprime n) : (m ^ k).coprime (n ^ l) :=
begin
rw ← coprime_coe at *, simp only [pow_coe], apply nat.coprime.pow, apply h
end
end coprime
end pnat
|
4ad2240f7a01937f4d23b8503393557c811b0b73 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/621.lean | 40b9a4f411b3ef85d53cdb3fae41e6f785dfe6ca | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | leanprover/lean4 | 4bdf9790294964627eb9be79f5e8f6157780b4cc | f1f9dc0f2f531af3312398999d8b8303fa5f096b | refs/heads/master | 1,693,360,665,786 | 1,693,350,868,000 | 1,693,350,868,000 | 129,571,436 | 2,827 | 311 | Apache-2.0 | 1,694,716,156,000 | 1,523,760,560,000 | Lean | UTF-8 | Lean | false | false | 157 | lean | instance (ϕ : α → Prop) : CoeSort (Subtype ϕ) α where
coe := fun x => x.val
example (ϕ : α → Prop) (xs : Subtype ϕ) (x : xs) : True := trivial
|
74f43d209fdb0d748e3b453b6ea72a067b519d30 | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/ring_theory/valuation/basic.lean | 886d50e00bac8bdf75626854cdfea1f76ddea54b | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 14,693 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Johan Commelin, Patrick Massot
-/
import algebra.linear_ordered_comm_group_with_zero
import algebra.group_power
import ring_theory.ideal.operations
import algebra.punit_instances
/-!
# The basics of valuation theory.
The basic theory of valuations (non-archimedean norms) on a commutative ring,
following T. Wedhorn's unpublished notes “Adic Spaces” ([wedhorn_adic]).
The definition of a valuation we use here is Definition 1.22 of [wedhorn_adic].
A valuation on a ring `R` is a monoid homomorphism `v` to a linearly ordered
commutative group with zero, that in addition satisfies the following two axioms:
* `v 0 = 0`
* `∀ x y, v (x + y) ≤ max (v x) (v y)`
`valuation R Γ₀`is the type of valuations `R → Γ₀`, with a coercion to the underlying
function. If `v` is a valuation from `R` to `Γ₀` then the induced group
homomorphism `units(R) → Γ₀` is called `unit_map v`.
The equivalence "relation" `is_equiv v₁ v₂ : Prop` defined in 1.27 of [wedhorn_adic] is not strictly
speaking a relation, because `v₁ : valuation R Γ₁` and `v₂ : valuation R Γ₂` might
not have the same type. This corresponds in ZFC to the set-theoretic difficulty
that the class of all valuations (as `Γ₀` varies) on a ring `R` is not a set.
The "relation" is however reflexive, symmetric and transitive in the obvious
sense. Note that we use 1.27(iii) of [wedhorn_adic] as the definition of equivalence.
The support of a valuation `v : valuation R Γ₀` is `supp v`. If `J` is an ideal of `R`
with `h : J ⊆ supp v` then the induced valuation
on R / J = `ideal.quotient J` is `on_quot v h`.
## Main definitions
* `valuation R Γ₀`, the type of valuations on `R` with values in `Γ₀`
* `valuation.is_equiv`, the heterogeneous equivalence relation on valuations
* `valuation.supp`, the support of a valuation
-/
open_locale classical
noncomputable theory
local attribute [instance, priority 0] classical.DLO
open function ideal
-- universes u u₀ u₁ u₂ -- v is used for valuations
variables {R : Type*} -- This will be a ring, assumed commutative in some sections
variables {Γ₀ : Type*} [linear_ordered_comm_group_with_zero Γ₀]
variables {Γ'₀ : Type*} [linear_ordered_comm_group_with_zero Γ'₀]
variables {Γ''₀ : Type*} [linear_ordered_comm_group_with_zero Γ''₀]
set_option old_structure_cmd true
section
variables (R) (Γ₀) [ring R]
/-- The type of Γ₀-valued valuations on R. -/
@[nolint has_inhabited_instance]
structure valuation extends R →* Γ₀ :=
(map_zero' : to_fun 0 = 0)
(map_add' : ∀ x y, to_fun (x + y) ≤ max (to_fun x) (to_fun y))
run_cmd tactic.add_doc_string `valuation.to_monoid_hom "The `monoid_hom` underlying a valuation."
end
namespace valuation
section basic
variables (R) (Γ₀) [ring R]
/-- A valuation is coerced to the underlying function R → Γ₀. -/
instance : has_coe_to_fun (valuation R Γ₀) := { F := λ _, R → Γ₀, coe := valuation.to_fun }
/-- A valuation is coerced to a monoid morphism R → Γ₀. -/
instance : has_coe (valuation R Γ₀) (R →* Γ₀) := ⟨valuation.to_monoid_hom⟩
variables {R} {Γ₀} (v : valuation R Γ₀) {x y z : R}
@[simp, norm_cast] lemma coe_coe : ((v : R →* Γ₀) : R → Γ₀) = v := rfl
@[simp] lemma map_zero : v 0 = 0 := v.map_zero'
@[simp] lemma map_one : v 1 = 1 := v.map_one'
@[simp] lemma map_mul : ∀ x y, v (x * y) = v x * v y := v.map_mul'
@[simp] lemma map_add : ∀ x y, v (x + y) ≤ max (v x) (v y) := v.map_add'
@[simp] lemma map_pow : ∀ x (n:ℕ), v (x^n) = (v x)^n :=
v.to_monoid_hom.map_pow
@[ext] lemma ext {v₁ v₂ : valuation R Γ₀} (h : ∀ r, v₁ r = v₂ r) : v₁ = v₂ :=
by { cases v₁, cases v₂, congr, funext r, exact h r }
lemma ext_iff {v₁ v₂ : valuation R Γ₀} : v₁ = v₂ ↔ ∀ r, v₁ r = v₂ r :=
⟨λ h r, congr_arg _ h, ext⟩
-- The following definition is not an instance, because we have more than one `v` on a given `R`.
-- In addition, type class inference would not be able to infer `v`.
/-- A valuation gives a preorder on the underlying ring. -/
def to_preorder : preorder R := preorder.lift v
/-- If `v` is a valuation on a division ring then `v(x) = 0` iff `x = 0`. -/
@[simp] lemma zero_iff {K : Type*} [division_ring K]
(v : valuation K Γ₀) {x : K} : v x = 0 ↔ x = 0 :=
begin
split ; intro h,
{ contrapose! h,
exact ((is_unit.mk0 _ h).map (v : K →* Γ₀)).ne_zero },
{ exact h.symm ▸ v.map_zero },
end
lemma ne_zero_iff {K : Type*} [division_ring K]
(v : valuation K Γ₀) {x : K} : v x ≠ 0 ↔ x ≠ 0 :=
not_iff_not_of_iff v.zero_iff
@[simp] lemma map_inv {K : Type*} [division_ring K]
(v : valuation K Γ₀) {x : K} : v x⁻¹ = (v x)⁻¹ :=
begin
by_cases h : x = 0,
{ subst h, rw [inv_zero, v.map_zero, inv_zero] },
{ apply eq_inv_of_mul_right_eq_one,
rw [← v.map_mul, mul_inv_cancel h, v.map_one] }
end
lemma map_units_inv (x : units R) : v (x⁻¹ : units R) = (v x)⁻¹ :=
eq_inv_of_mul_right_eq_one $ by rw [← v.map_mul, units.mul_inv, v.map_one]
@[simp] theorem unit_map_eq (u : units R) :
(units.map (v : R →* Γ₀) u : Γ₀) = v u := rfl
theorem map_neg_one : v (-1) = 1 :=
begin
apply eq_one_of_pow_eq_one (nat.succ_ne_zero 1) (_ : _ ^ 2 = _),
rw [pow_two, ← v.map_mul, neg_one_mul, neg_neg, v.map_one],
end
@[simp] lemma map_neg (x : R) : v (-x) = v x :=
calc v (-x) = v (-1 * x) : by rw [neg_one_mul]
... = v (-1) * v x : map_mul _ _ _
... = v x : by rw [v.map_neg_one, one_mul]
lemma map_sub_swap (x y : R) : v (x - y) = v (y - x) :=
calc v (x - y) = v (-(y - x)) : by rw show x - y = -(y-x), by abel
... = _ : map_neg _ _
lemma map_sub_le_max (x y : R) : v (x - y) ≤ max (v x) (v y) :=
calc v (x - y) = v (x + -y) : by rw [sub_eq_add_neg]
... ≤ max (v x) (v $ -y) : v.map_add _ _
... = max (v x) (v y) : by rw map_neg
lemma map_add_of_distinct_val (h : v x ≠ v y) : v (x + y) = max (v x) (v y) :=
begin
suffices : ¬v (x + y) < max (v x) (v y),
from or_iff_not_imp_right.1 (le_iff_eq_or_lt.1 (v.map_add x y)) this,
intro h',
wlog vyx : v y < v x using x y,
{ apply lt_or_gt_of_ne h.symm },
{ rw max_eq_left_of_lt vyx at h',
apply lt_irrefl (v x),
calc v x = v ((x+y) - y) : by simp
... ≤ max (v $ x + y) (v y) : map_sub_le_max _ _ _
... < v x : max_lt h' vyx },
{ apply this h.symm,
rwa [add_comm, max_comm] at h' }
end
lemma map_eq_of_sub_lt (h : v (y - x) < v x) : v y = v x :=
begin
have := valuation.map_add_of_distinct_val v (ne_of_gt h).symm,
rw max_eq_right (le_of_lt h) at this,
simpa using this
end
/-- A ring homomorphism S → R induces a map valuation R Γ₀ → valuation S Γ₀ -/
def comap {S : Type*} [ring S] (f : S →+* R) (v : valuation R Γ₀) :
valuation S Γ₀ :=
by refine_struct { to_fun := v ∘ f, .. }; intros;
simp only [comp_app, map_one, map_mul, map_zero, map_add,
f.map_one, f.map_mul, f.map_zero, f.map_add]
@[simp] lemma comap_id : v.comap (ring_hom.id R) = v := ext $ λ r, rfl
lemma comap_comp {S₁ : Type*} {S₂ : Type*} [ring S₁] [ring S₂] (f : S₁ →+* S₂) (g : S₂ →+* R) :
v.comap (g.comp f) = (v.comap g).comap f :=
ext $ λ r, rfl
/-- A ≤-preserving group homomorphism Γ₀ → Γ'₀ induces a map valuation R Γ₀ → valuation R Γ'₀. -/
def map (f : Γ₀ →* Γ'₀) (h₀ : f 0 = 0) (hf : monotone f) (v : valuation R Γ₀) : valuation R Γ'₀ :=
{ to_fun := f ∘ v,
map_zero' := show f (v 0) = 0, by rw [v.map_zero, h₀],
map_add' := λ r s,
calc f (v (r + s)) ≤ f (max (v r) (v s)) : hf (v.map_add r s)
... = max (f (v r)) (f (v s)) : hf.map_max,
.. monoid_hom.comp f (v : R →* Γ₀) }
/-- Two valuations on R are defined to be equivalent if they induce the same preorder on R. -/
def is_equiv (v₁ : valuation R Γ₀) (v₂ : valuation R Γ'₀) : Prop :=
∀ r s, v₁ r ≤ v₁ s ↔ v₂ r ≤ v₂ s
end basic -- end of section
namespace is_equiv
variables [ring R]
variables {v : valuation R Γ₀}
variables {v₁ : valuation R Γ₀} {v₂ : valuation R Γ'₀} {v₃ : valuation R Γ''₀}
@[refl] lemma refl : v.is_equiv v :=
λ _ _, iff.refl _
@[symm] lemma symm (h : v₁.is_equiv v₂) : v₂.is_equiv v₁ :=
λ _ _, iff.symm (h _ _)
@[trans] lemma trans (h₁₂ : v₁.is_equiv v₂) (h₂₃ : v₂.is_equiv v₃) : v₁.is_equiv v₃ :=
λ _ _, iff.trans (h₁₂ _ _) (h₂₃ _ _)
lemma of_eq {v' : valuation R Γ₀} (h : v = v') : v.is_equiv v' :=
by { subst h }
lemma map {v' : valuation R Γ₀} (f : Γ₀ →* Γ'₀) (h₀ : f 0 = 0) (hf : monotone f) (inf : injective f)
(h : v.is_equiv v') :
(v.map f h₀ hf).is_equiv (v'.map f h₀ hf) :=
let H : strict_mono f := strict_mono_of_monotone_of_injective hf inf in
λ r s,
calc f (v r) ≤ f (v s) ↔ v r ≤ v s : by rw H.le_iff_le
... ↔ v' r ≤ v' s : h r s
... ↔ f (v' r) ≤ f (v' s) : by rw H.le_iff_le
/-- `comap` preserves equivalence. -/
lemma comap {S : Type*} [ring S] (f : S →+* R) (h : v₁.is_equiv v₂) :
(v₁.comap f).is_equiv (v₂.comap f) :=
λ r s, h (f r) (f s)
lemma val_eq (h : v₁.is_equiv v₂) {r s : R} :
v₁ r = v₁ s ↔ v₂ r = v₂ s :=
by simpa only [le_antisymm_iff] using and_congr (h r s) (h s r)
lemma ne_zero (h : v₁.is_equiv v₂) {r : R} :
v₁ r ≠ 0 ↔ v₂ r ≠ 0 :=
begin
have : v₁ r ≠ v₁ 0 ↔ v₂ r ≠ v₂ 0 := not_iff_not_of_iff h.val_eq,
rwa [v₁.map_zero, v₂.map_zero] at this,
end
end is_equiv -- end of namespace
lemma is_equiv_of_map_strict_mono [ring R] {v : valuation R Γ₀}
(f : Γ₀ →* Γ'₀) (h₀ : f 0 = 0) (H : strict_mono f) :
is_equiv (v.map f h₀ (H.monotone)) v :=
λ x y, ⟨H.le_iff_le.mp, λ h, H.monotone h⟩
lemma is_equiv_of_val_le_one {K : Type*} [division_ring K]
(v : valuation K Γ₀) (v' : valuation K Γ'₀) (h : ∀ {x:K}, v x ≤ 1 ↔ v' x ≤ 1) :
v.is_equiv v' :=
begin
intros x y,
by_cases hy : y = 0, { simp [hy, zero_iff], },
rw show y = 1 * y, by rw one_mul,
rw [← (inv_mul_cancel_right' hy x)],
iterate 2 {rw [v.map_mul _ y, v'.map_mul _ y]},
rw [v.map_one, v'.map_one],
split; intro H,
{ apply mul_le_mul_right',
replace hy := v.ne_zero_iff.mpr hy,
replace H := le_of_le_mul_right hy H,
rwa h at H, },
{ apply mul_le_mul_right',
replace hy := v'.ne_zero_iff.mpr hy,
replace H := le_of_le_mul_right hy H,
rwa h, },
end
section supp
variables [comm_ring R]
variables (v : valuation R Γ₀)
/-- The support of a valuation `v : R → Γ₀` is the ideal of `R` where `v` vanishes. -/
def supp : ideal R :=
{ carrier := {x | v x = 0},
zero_mem' := map_zero v,
add_mem' := λ x y hx hy, le_zero_iff.mp $
calc v (x + y) ≤ max (v x) (v y) : v.map_add x y
... ≤ 0 : max_le (le_zero_iff.mpr hx) (le_zero_iff.mpr hy),
smul_mem' := λ c x hx, calc v (c * x)
= v c * v x : map_mul v c x
... = v c * 0 : congr_arg _ hx
... = 0 : mul_zero _ }
@[simp] lemma mem_supp_iff (x : R) : x ∈ supp v ↔ v x = 0 := iff.rfl
-- @[simp] lemma mem_supp_iff' (x : R) : x ∈ (supp v : set R) ↔ v x = 0 := iff.rfl
/-- The support of a valuation is a prime ideal. -/
instance : ideal.is_prime (supp v) :=
⟨λ (h : v.supp = ⊤), one_ne_zero $ show (1 : Γ₀) = 0,
from calc 1 = v 1 : v.map_one.symm
... = 0 : show (1:R) ∈ supp v, by { rw h, trivial },
λ x y hxy, begin
show v x = 0 ∨ v y = 0,
change v (x * y) = 0 at hxy,
rw [v.map_mul x y] at hxy,
exact eq_zero_or_eq_zero_of_mul_eq_zero hxy
end⟩
lemma map_add_supp (a : R) {s : R} (h : s ∈ supp v) : v (a + s) = v a :=
begin
have aux : ∀ a s, v s = 0 → v (a + s) ≤ v a,
{ intros a' s' h', refine le_trans (v.map_add a' s') (max_le (le_refl _) _), simp [h'], },
apply le_antisymm (aux a s h),
calc v a = v (a + s + -s) : by simp
... ≤ v (a + s) : aux (a + s) (-s) (by rwa ←ideal.neg_mem_iff at h)
end
-- This causes a loop between `decidable_linear_order` and `linear_order`.
-- see https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.233733.20algebraic.20closure
local attribute [-instance] classical.DLO
/-- If `hJ : J ⊆ supp v` then `on_quot_val hJ` is the induced function on R/J as a function.
Note: it's just the function; the valuation is `on_quot hJ`. -/
def on_quot_val {J : ideal R} (hJ : J ≤ supp v) :
J.quotient → Γ₀ :=
λ q, quotient.lift_on' q v $ λ a b h,
calc v a = v (b + (a - b)) : by simp
... = v b : v.map_add_supp b (hJ h)
/-- The extension of valuation v on R to valuation on R/J if J ⊆ supp v -/
def on_quot {J : ideal R} (hJ : J ≤ supp v) :
valuation J.quotient Γ₀ :=
{ to_fun := v.on_quot_val hJ,
map_zero' := v.map_zero,
map_one' := v.map_one,
map_mul' := λ xbar ybar, quotient.ind₂' v.map_mul xbar ybar,
map_add' := λ xbar ybar, quotient.ind₂' v.map_add xbar ybar }
@[simp] lemma on_quot_comap_eq {J : ideal R} (hJ : J ≤ supp v) :
(v.on_quot hJ).comap (ideal.quotient.mk J) = v :=
ext $ λ r,
begin
refine @quotient.lift_on_beta _ _ (J.quotient_rel) v (λ a b h, _) _,
calc v a = v (b + (a - b)) : by simp
... = v b : v.map_add_supp b (hJ h)
end
lemma comap_supp {S : Type*} [comm_ring S] (f : S →+* R) :
supp (v.comap f) = ideal.comap f v.supp :=
ideal.ext $ λ x,
begin
rw [mem_supp_iff, ideal.mem_comap, mem_supp_iff],
refl,
end
lemma self_le_supp_comap (J : ideal R) (v : valuation (quotient J) Γ₀) :
J ≤ (v.comap (ideal.quotient.mk J)).supp :=
by { rw [comap_supp, ← ideal.map_le_iff_le_comap], simp }
@[simp] lemma comap_on_quot_eq (J : ideal R) (v : valuation J.quotient Γ₀) :
(v.comap (ideal.quotient.mk J)).on_quot (v.self_le_supp_comap J) = v :=
ext $ by { rintro ⟨x⟩, refl }
/-- The quotient valuation on R/J has support supp(v)/J if J ⊆ supp v. -/
lemma supp_quot {J : ideal R} (hJ : J ≤ supp v) :
supp (v.on_quot hJ) = (supp v).map (ideal.quotient.mk J) :=
begin
apply le_antisymm,
{ rintro ⟨x⟩ hx,
apply ideal.subset_span,
exact ⟨x, hx, rfl⟩ },
{ rw ideal.map_le_iff_le_comap,
intros x hx, exact hx }
end
lemma supp_quot_supp : supp (v.on_quot (le_refl _)) = 0 :=
by { rw supp_quot, exact ideal.map_quotient_self _ }
end supp -- end of section
end valuation
|
5eb1bdfead7c412e8d80171d0123b628f156c09a | 32317185abf7e7c963f4c67c190aec61af6b3628 | /hott/algebra/hott.hlean | b59b577e795718af0d1b9d7a24776906e6c03be3 | [
"Apache-2.0"
] | permissive | Andrew-Zipperer-unorganized/lean | 198a2317f21198cd8d26e7085e484b86277f17f7 | dcb35008e1474a0abebe632b1dced120e5f8c009 | refs/heads/master | 1,622,526,520,945 | 1,453,576,559,000 | 1,454,612,842,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,952 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
Theorems about algebra specific to HoTT
-/
import .group arity types.pi hprop_trunc types.unit .bundled
open equiv eq equiv.ops is_trunc unit
namespace algebra
definition trivial_group [constructor] : group unit :=
group.mk (λx y, star) _ (λx y z, idp) star (unit.rec idp) (unit.rec idp) (λx, star) (λx, idp)
definition Trivial_group [constructor] : Group :=
Group.mk _ trivial_group
notation `G0` := Trivial_group
open Group has_mul has_inv
-- we prove under which conditions two groups are equal
-- group and has_mul are classes. So, lean does not automatically generate
-- coercions between them anymore.
-- So, an application such as (@mul A G g h) in the following definition
-- is type incorrect if the coercion is not added (explicitly or implicitly).
local attribute group.to.has_mul [coercion]
local attribute group.to_has_inv [coercion]
universe variable l
variables {A B : Type.{l}}
definition group_eq {G H : group A} (same_mul' : Π(g h : A), @mul A G g h = @mul A H g h)
: G = H :=
begin
have foo : Π(g : A), @inv A G g = (@inv A G g * g) * @inv A H g,
from λg, !mul_inv_cancel_right⁻¹,
cases G with Gm Gs Gh1 G1 Gh2 Gh3 Gi Gh4,
cases H with Hm Hs Hh1 H1 Hh2 Hh3 Hi Hh4,
rewrite [↑[semigroup.to_has_mul,group.to_has_inv] at (same_mul,foo)],
have same_mul : Gm = Hm, from eq_of_homotopy2 same_mul',
cases same_mul,
have same_one : G1 = H1, from calc
G1 = Hm G1 H1 : Hh3
... = H1 : Gh2,
have same_inv : Gi = Hi, from eq_of_homotopy (take g, calc
Gi g = Hm (Hm (Gi g) g) (Hi g) : foo
... = Hm G1 (Hi g) : by rewrite Gh4
... = Hi g : Gh2),
cases same_one, cases same_inv,
have ps : Gs = Hs, from !is_hprop.elim,
have ph1 : Gh1 = Hh1, from !is_hprop.elim,
have ph2 : Gh2 = Hh2, from !is_hprop.elim,
have ph3 : Gh3 = Hh3, from !is_hprop.elim,
have ph4 : Gh4 = Hh4, from !is_hprop.elim,
cases ps, cases ph1, cases ph2, cases ph3, cases ph4, reflexivity
end
definition group_pathover {G : group A} {H : group B} {f : A ≃ B}
: (Π(g h : A), f (g * h) = f g * f h) → G =[ua f] H :=
begin
revert H,
eapply (rec_on_ua_idp' f),
intros H resp_mul,
esimp [equiv.refl] at resp_mul, esimp,
apply pathover_idp_of_eq, apply group_eq,
exact resp_mul
end
definition Group_eq {G H : Group} (f : carrier G ≃ carrier H)
(resp_mul : Π(g h : G), f (g * h) = f g * f h) : G = H :=
begin
cases G with Gc G, cases H with Hc H,
apply (apo011 mk (ua f)),
apply group_pathover, exact resp_mul
end
definition trivial_group_of_is_contr (G : Group) [H : is_contr G] : G = G0 :=
begin
fapply Group_eq,
{ apply equiv_unit_of_is_contr},
{ intros, reflexivity}
end
end algebra
|
6f558f524baa34f184ee084058f507f2c2944a23 | ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5 | /stage0/src/Lean/Elab/Binders.lean | 819778dc036e0d9fffc0e9ad29fcc3ac0547dc39 | [
"Apache-2.0"
] | permissive | dupuisf/lean4 | d082d13b01243e1de29ae680eefb476961221eef | 6a39c65bd28eb0e28c3870188f348c8914502718 | refs/heads/master | 1,676,948,755,391 | 1,610,665,114,000 | 1,610,665,114,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 23,725 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Elab.Term
import Lean.Parser.Term
namespace Lean.Elab.Term
open Meta
open Lean.Parser.Term
/--
Given syntax of the forms
a) (`:` term)?
b) `:` term
return `term` if it is present, or a hole if not. -/
private def expandBinderType (ref : Syntax) (stx : Syntax) : Syntax :=
if stx.getNumArgs == 0 then
mkHole ref
else
stx[1]
/-- Given syntax of the form `ident <|> hole`, return `ident`. If `hole`, then we create a new anonymous name. -/
private def expandBinderIdent (stx : Syntax) : TermElabM Syntax :=
match stx with
| `(_) => mkFreshIdent stx
| _ => pure stx
/-- Given syntax of the form `(ident >> " : ")?`, return `ident`, or a new instance name. -/
private def expandOptIdent (stx : Syntax) : TermElabM Syntax := do
if stx.isNone then
let id ← withFreshMacroScope <| MonadQuotation.addMacroScope `inst
return mkIdentFrom stx id
else
return stx[0]
structure BinderView where
id : Syntax
type : Syntax
bi : BinderInfo
partial def quoteAutoTactic : Syntax → TermElabM Syntax
| stx@(Syntax.ident _ _ _ _) => throwErrorAt stx "invalid auto tactic, identifier is not allowed"
| stx@(Syntax.node k args) => do
if stx.isAntiquot then
throwErrorAt stx "invalid auto tactic, antiquotation is not allowed"
else
let mut quotedArgs ← `(Array.empty)
for arg in args do
if k == nullKind && (arg.isAntiquotSuffixSplice || arg.isAntiquotSplice) then
throwErrorAt arg "invalid auto tactic, antiquotation is not allowed"
else
let quotedArg ← quoteAutoTactic arg
quotedArgs ← `(Array.push $quotedArgs $quotedArg)
`(Syntax.node $(quote k) $quotedArgs)
| Syntax.atom info val => `(Syntax.atom {} $(quote val))
| Syntax.missing => unreachable!
def declareTacticSyntax (tactic : Syntax) : TermElabM Name :=
withFreshMacroScope do
let name ← MonadQuotation.addMacroScope `_auto
let type := Lean.mkConst `Lean.Syntax
let tactic ← quoteAutoTactic tactic
let val ← elabTerm tactic type
let val ← instantiateMVars val
trace[Elab.autoParam]! val
let decl := Declaration.defnDecl { name := name, lparams := [], type := type, value := val, hints := ReducibilityHints.opaque,
safety := DefinitionSafety.safe }
addDecl decl
compileDecl decl
pure name
/-
Expand `optional (binderTactic <|> binderDefault)`
def binderTactic := parser! " := " >> " by " >> tacticParser
def binderDefault := parser! " := " >> termParser
-/
private def expandBinderModifier (type : Syntax) (optBinderModifier : Syntax) : TermElabM Syntax := do
if optBinderModifier.isNone then
pure type
else
let modifier := optBinderModifier[0]
let kind := modifier.getKind
if kind == `Lean.Parser.Term.binderDefault then
let defaultVal := modifier[1]
`(optParam $type $defaultVal)
else if kind == `Lean.Parser.Term.binderTactic then
let tac := modifier[2]
let name ← declareTacticSyntax tac
`(autoParam $type $(mkIdentFrom tac name))
else
throwUnsupportedSyntax
private def getBinderIds (ids : Syntax) : TermElabM (Array Syntax) :=
ids.getArgs.mapM fun id =>
let k := id.getKind
if k == identKind || k == `Lean.Parser.Term.hole then
pure id
else
throwErrorAt id "identifier or `_` expected"
/-
Recall that
```
def typeSpec := parser! " : " >> termParser
def optType : Parser := optional typeSpec
``` -/
def expandOptType (ref : Syntax) (optType : Syntax) : Syntax :=
if optType.isNone then
mkHole ref
else
optType[0][1]
private def matchBinder (stx : Syntax) : TermElabM (Array BinderView) :=
match stx with
| Syntax.node k args => do
if k == `Lean.Parser.Term.simpleBinder then
-- binderIdent+ >> optType
let ids ← getBinderIds args[0]
let type := expandOptType stx args[1]
ids.mapM fun id => do pure { id := (← expandBinderIdent id), type := type, bi := BinderInfo.default }
else if k == `Lean.Parser.Term.explicitBinder then
-- `(` binderIdent+ binderType (binderDefault <|> binderTactic)? `)`
let ids ← getBinderIds args[1]
let type := expandBinderType stx args[2]
let optModifier := args[3]
let type ← expandBinderModifier type optModifier
ids.mapM fun id => do pure { id := (← expandBinderIdent id), type := type, bi := BinderInfo.default }
else if k == `Lean.Parser.Term.implicitBinder then
-- `{` binderIdent+ binderType `}`
let ids ← getBinderIds args[1]
let type := expandBinderType stx args[2]
ids.mapM fun id => do pure { id := (← expandBinderIdent id), type := type, bi := BinderInfo.implicit }
else if k == `Lean.Parser.Term.instBinder then
-- `[` optIdent type `]`
let id ← expandOptIdent args[1]
let type := args[2]
pure #[ { id := id, type := type, bi := BinderInfo.instImplicit } ]
else
throwUnsupportedSyntax
| _ => throwUnsupportedSyntax
private def registerFailedToInferBinderTypeInfo (type : Expr) (ref : Syntax) : TermElabM Unit :=
registerCustomErrorIfMVar type ref "failed to infer binder type"
private partial def elabBinderViews {α} (binderViews : Array BinderView) (catchAutoBoundImplicit : Bool) (fvars : Array Expr) (k : Array Expr → TermElabM α)
: TermElabM α :=
let rec loop (i : Nat) (fvars : Array Expr) : TermElabM α := do
if h : i < binderViews.size then
let binderView := binderViews.get ⟨i, h⟩
if catchAutoBoundImplicit then
elabTypeWithAutoBoundImplicit binderView.type fun type => do
registerFailedToInferBinderTypeInfo type binderView.type
withLocalDecl binderView.id.getId binderView.bi type fun fvar =>
loop (i+1) (fvars.push fvar)
else
let type ← elabType binderView.type
registerFailedToInferBinderTypeInfo type binderView.type
withLocalDecl binderView.id.getId binderView.bi type fun fvar =>
loop (i+1) (fvars.push fvar)
else
k fvars
loop 0 fvars
private partial def elabBindersAux {α} (binders : Array Syntax) (catchAutoBoundImplicit : Bool) (k : Array Expr → TermElabM α) : TermElabM α :=
let rec loop (i : Nat) (fvars : Array Expr) : TermElabM α := do
if h : i < binders.size then
let binderViews ← matchBinder (binders.get ⟨i, h⟩)
elabBinderViews binderViews catchAutoBoundImplicit fvars <| loop (i+1)
else
k fvars
loop 0 #[]
/--
Elaborate the given binders (i.e., `Syntax` objects for `simpleBinder <|> bracketedBinder`),
update the local context, set of local instances, reset instance chache (if needed), and then
execute `x` with the updated context. -/
def elabBinders {α} (binders : Array Syntax) (k : Array Expr → TermElabM α) (catchAutoBoundImplicit := false) : TermElabM α :=
withoutPostponingUniverseConstraints do
if binders.isEmpty then
k #[]
else
elabBindersAux binders catchAutoBoundImplicit k
@[inline] def elabBinder {α} (binder : Syntax) (x : Expr → TermElabM α) (catchAutoBoundImplicit := false) : TermElabM α :=
elabBinders #[binder] (catchAutoBoundImplicit := catchAutoBoundImplicit) (fun fvars => x (fvars.get! 0))
@[builtinTermElab «forall»] def elabForall : TermElab := fun stx _ =>
match stx with
| `(forall $binders*, $term) =>
elabBinders binders fun xs => do
let e ← elabType term
mkForallFVars xs e
| _ => throwUnsupportedSyntax
@[builtinTermElab arrow] def elabArrow : TermElab :=
adaptExpander fun stx => match stx with
| `($dom:term -> $rng) => `(forall (a : $dom), $rng)
| _ => throwUnsupportedSyntax
@[builtinTermElab depArrow] def elabDepArrow : TermElab := fun stx _ =>
-- bracketedBinder `->` term
let binder := stx[0]
let term := stx[2]
elabBinders #[binder] fun xs => do
mkForallFVars xs (← elabType term)
/--
Auxiliary functions for converting `id_1 ... id_n` application into `#[id_1, ..., id_m]`
It is used at `expandFunBinders`. -/
private partial def getFunBinderIds? (stx : Syntax) : OptionT TermElabM (Array Syntax) :=
let convertElem (stx : Syntax) : OptionT TermElabM Syntax :=
match stx with
| `(_) => do let ident ← mkFreshIdent stx; pure ident
| `($id:ident) => pure id
| _ => failure
match stx with
| `($f $args*) => do
let mut acc := #[].push (← convertElem f)
for arg in args do
acc := acc.push (← convertElem arg)
return acc
| _ =>
return #[].push (← convertElem stx)
/--
Auxiliary function for expanding `fun` notation binders. Recall that `fun` parser is defined as
```
def funBinder : Parser := implicitBinder <|> instBinder <|> termParser maxPrec
parser! unicodeSymbol "λ" "fun" >> many1 funBinder >> "=>" >> termParser
```
to allow notation such as `fun (a, b) => a + b`, where `(a, b)` should be treated as a pattern.
The result is a pair `(explicitBinders, newBody)`, where `explicitBinders` is syntax of the form
```
`(` ident `:` term `)`
```
which can be elaborated using `elabBinders`, and `newBody` is the updated `body` syntax.
We update the `body` syntax when expanding the pattern notation.
Example: `fun (a, b) => a + b` expands into `fun _a_1 => match _a_1 with | (a, b) => a + b`.
See local function `processAsPattern` at `expandFunBindersAux`.
The resulting `Bool` is true if a pattern was found. We use it "mark" a macro expansion. -/
partial def expandFunBinders (binders : Array Syntax) (body : Syntax) : TermElabM (Array Syntax × Syntax × Bool) :=
let rec loop (body : Syntax) (i : Nat) (newBinders : Array Syntax) := do
if h : i < binders.size then
let binder := binders.get ⟨i, h⟩
let processAsPattern : Unit → TermElabM (Array Syntax × Syntax × Bool) := fun _ => do
let pattern := binder
let major ← mkFreshIdent binder
let (binders, newBody, _) ← loop body (i+1) (newBinders.push $ mkExplicitBinder major (mkHole binder))
let newBody ← `(match $major:ident with | $pattern => $newBody)
pure (binders, newBody, true)
match binder with
| Syntax.node `Lean.Parser.Term.implicitBinder _ => loop body (i+1) (newBinders.push binder)
| Syntax.node `Lean.Parser.Term.instBinder _ => loop body (i+1) (newBinders.push binder)
| Syntax.node `Lean.Parser.Term.explicitBinder _ => loop body (i+1) (newBinders.push binder)
| Syntax.node `Lean.Parser.Term.simpleBinder _ => loop body (i+1) (newBinders.push binder)
| Syntax.node `Lean.Parser.Term.hole _ =>
let ident ← mkFreshIdent binder
let type := binder
loop body (i+1) (newBinders.push $ mkExplicitBinder ident type)
| Syntax.node `Lean.Parser.Term.paren args =>
-- `(` (termParser >> parenSpecial)? `)`
-- parenSpecial := (tupleTail <|> typeAscription)?
let binderBody := binder[1]
if binderBody.isNone then processAsPattern ()
else
let idents := binderBody[0]
let special := binderBody[1]
if special.isNone then processAsPattern ()
else if special[0].getKind != `Lean.Parser.Term.typeAscription then
processAsPattern ()
else
-- typeAscription := `:` term
let type := special[0][1]
match (← getFunBinderIds? idents) with
| some idents => loop body (i+1) (newBinders ++ idents.map (fun ident => mkExplicitBinder ident type))
| none => processAsPattern ()
| Syntax.ident _ _ _ _ =>
let type := mkHole binder
loop body (i+1) (newBinders.push $ mkExplicitBinder binder type)
| _ => processAsPattern ()
else
pure (newBinders, body, false)
loop body 0 #[]
namespace FunBinders
structure State where
fvars : Array Expr := #[]
lctx : LocalContext
localInsts : LocalInstances
expectedType? : Option Expr := none
private def propagateExpectedType (fvar : Expr) (fvarType : Expr) (s : State) : TermElabM State := do
match s.expectedType? with
| none => pure s
| some expectedType =>
let expectedType ← whnfForall expectedType
match expectedType with
| Expr.forallE _ d b _ =>
discard <| isDefEq fvarType d
let b := b.instantiate1 fvar
pure { s with expectedType? := some b }
| _ => pure { s with expectedType? := none }
private partial def elabFunBinderViews (binderViews : Array BinderView) (i : Nat) (s : State) : TermElabM State :=
if h : i < binderViews.size then
let binderView := binderViews.get ⟨i, h⟩
withRef binderView.type $ withLCtx s.lctx s.localInsts do
let type ← elabType binderView.type
registerFailedToInferBinderTypeInfo type binderView.type
let fvarId ← mkFreshFVarId
let fvar := mkFVar fvarId
let s := { s with fvars := s.fvars.push fvar }
-- dbgTrace (toString binderView.id.getId ++ " : " ++ toString type)
/-
We do **not** want to support default and auto arguments in lambda abstractions.
Example: `fun (x : Nat := 10) => x+1`.
We do not believe this is an useful feature, and it would complicate the logic here.
-/
let lctx := s.lctx.mkLocalDecl fvarId binderView.id.getId type binderView.bi
let s ← withRef binderView.id $ propagateExpectedType fvar type s
let s := { s with lctx := lctx }
match (← isClass? type) with
| none => elabFunBinderViews binderViews (i+1) s
| some className =>
resettingSynthInstanceCache do
let localInsts := s.localInsts.push { className := className, fvar := mkFVar fvarId }
elabFunBinderViews binderViews (i+1) { s with localInsts := localInsts }
else
pure s
partial def elabFunBindersAux (binders : Array Syntax) (i : Nat) (s : State) : TermElabM State := do
if h : i < binders.size then
let binderViews ← matchBinder (binders.get ⟨i, h⟩)
let s ← elabFunBinderViews binderViews 0 s
elabFunBindersAux binders (i+1) s
else
pure s
end FunBinders
def elabFunBinders {α} (binders : Array Syntax) (expectedType? : Option Expr) (x : Array Expr → Option Expr → TermElabM α) : TermElabM α :=
if binders.isEmpty then
x #[] expectedType?
else do
let lctx ← getLCtx
let localInsts ← getLocalInstances
let s ← FunBinders.elabFunBindersAux binders 0 { lctx := lctx, localInsts := localInsts, expectedType? := expectedType? }
resettingSynthInstanceCacheWhen (s.localInsts.size > localInsts.size) $ withLCtx s.lctx s.localInsts $
x s.fvars s.expectedType?
/- Helper function for `expandEqnsIntoMatch` -/
private def getMatchAltsNumPatterns (matchAlts : Syntax) : Nat :=
let alt0 := matchAlts[0][0]
let pats := alt0[1].getSepArgs
pats.size
def expandWhereDecls (whereDecls : Syntax) (body : Syntax) : MacroM Syntax :=
match whereDecls with
| `(whereDecls|where $[$decls:letRecDecl $[;]?]*) => `(let rec $decls:letRecDecl,*; $body)
| _ => unreachable!
def expandWhereDeclsOpt (whereDeclsOpt : Syntax) (body : Syntax) : MacroM Syntax :=
if whereDeclsOpt.isNone then
body
else
expandWhereDecls whereDeclsOpt[0] body
/- Helper function for `expandMatchAltsIntoMatch` -/
private def expandMatchAltsIntoMatchAux (matchAlts : Syntax) (matchTactic : Bool) : Nat → Array Syntax → MacroM Syntax
| 0, discrs => do
if matchTactic then
`(tactic|match $[$discrs:term],* with $matchAlts:matchAlts)
else
`(match $[$discrs:term],* with $matchAlts:matchAlts)
| n+1, discrs => withFreshMacroScope do
let x ← `(x)
let body ← expandMatchAltsIntoMatchAux matchAlts matchTactic n (discrs.push x)
if matchTactic then
`(tactic| intro $x:term; $body:tactic)
else
`(@fun $x => $body)
/--
Expand `matchAlts` syntax into a full `match`-expression.
Example
```
| 0, true => alt_1
| i, _ => alt_2
```
expands into (for tactic == false)
```
fun x_1 x_2 =>
match x_1, x_2 with
| 0, true => alt_1
| i, _ => alt_2
```
and (for tactic == true)
```
intro x_1; intro x_2;
match x_1, x_2 with
| 0, true => alt_1
| i, _ => alt_2
```
-/
def expandMatchAltsIntoMatch (ref : Syntax) (matchAlts : Syntax) (tactic := false) : MacroM Syntax :=
withRef ref <| expandMatchAltsIntoMatchAux matchAlts tactic (getMatchAltsNumPatterns matchAlts) #[]
def expandMatchAltsIntoMatchTactic (ref : Syntax) (matchAlts : Syntax) : MacroM Syntax :=
withRef ref <| expandMatchAltsIntoMatchAux matchAlts true (getMatchAltsNumPatterns matchAlts) #[]
/--
Similar to `expandMatchAltsIntoMatch`, but supports an optional `where` clause.
Expand `matchAltsWhereDecls` into `let rec` + `match`-expression.
Example
```
| 0, true => ... f 0 ...
| i, _ => ... f i + g i ...
where
f x := g x + 1
g : Nat → Nat
| 0 => 1
| x+1 => f x
```
expands into
```
fux x_1 x_2 =>
let rec
f x := g x + 1,
g : Nat → Nat
| 0 => 1
| x+1 => f x
match x_1, x_2 with
| 0, true => ... f 0 ...
| i, _ => ... f i + g i ...
```
-/
def expandMatchAltsWhereDecls (matchAltsWhereDecls : Syntax) : MacroM Syntax :=
let matchAlts := matchAltsWhereDecls[0]
let whereDeclsOpt := matchAltsWhereDecls[1]
let rec loop (i : Nat) (discrs : Array Syntax) : MacroM Syntax :=
match i with
| 0 => do
let matchStx ← `(match $[$discrs:term],* with $matchAlts:matchAlts)
if whereDeclsOpt.isNone then
return matchStx
else
expandWhereDeclsOpt whereDeclsOpt matchStx
| n+1 => withFreshMacroScope do
let x ← `(x)
let body ← loop n (discrs.push x)
`(@fun $x => $body)
loop (getMatchAltsNumPatterns matchAlts) #[]
@[builtinTermElab «fun»] def elabFun : TermElab := fun stx expectedType? => match stx with
| `(fun $binders* => $body) => do
let (binders, body, expandedPattern) ← expandFunBinders binders body
if expandedPattern then
let newStx ← `(fun $binders* => $body)
withMacroExpansion stx newStx $ elabTerm newStx expectedType?
else
elabFunBinders binders expectedType? fun xs expectedType? => do
/- We ensure the expectedType here since it will force coercions to be applied if needed.
If we just use `elabTerm`, then we will need to a coercion `Coe (α → β) (α → δ)` whenever there is a coercion `Coe β δ`,
and another instance for the dependent version. -/
let e ← elabTermEnsuringType body expectedType?
mkLambdaFVars xs e
| `(fun $m:matchAlts) => do
let stxNew ← liftMacroM $ expandMatchAltsIntoMatch stx m
withMacroExpansion stx stxNew $ elabTerm stxNew expectedType?
| _ => throwUnsupportedSyntax
/- If `useLetExpr` is true, then a kernel let-expression `let x : type := val; body` is created.
Otherwise, we create a term of the form `(fun (x : type) => body) val`
The default elaboration order is `binders`, `typeStx`, `valStx`, and `body`.
If `elabBodyFirst == true`, then we use the order `binders`, `typeStx`, `body`, and `valStx`. -/
def elabLetDeclAux (n : Name) (binders : Array Syntax) (typeStx : Syntax) (valStx : Syntax) (body : Syntax)
(expectedType? : Option Expr) (useLetExpr : Bool) (elabBodyFirst : Bool) : TermElabM Expr := do
let (type, val, arity) ← elabBinders binders fun xs => do
let type ← elabType typeStx
registerCustomErrorIfMVar type typeStx "failed to infer 'let' declaration type"
if elabBodyFirst then
let type ← mkForallFVars xs type
let val ← mkFreshExprMVar type
pure (type, val, xs.size)
else
let val ← elabTermEnsuringType valStx type
let type ← mkForallFVars xs type
let val ← mkLambdaFVars xs val
pure (type, val, xs.size)
trace[Elab.let.decl]! "{n} : {type} := {val}"
let result ←
if useLetExpr then
withLetDecl n type val fun x => do
let body ← elabTerm body expectedType?
let body ← instantiateMVars body
mkLetFVars #[x] body
else
let f ← withLocalDecl n BinderInfo.default type fun x => do
let body ← elabTerm body expectedType?
let body ← instantiateMVars body
mkLambdaFVars #[x] body
pure $ mkApp f val
if elabBodyFirst then
forallBoundedTelescope type arity fun xs type => do
let valResult ← elabTermEnsuringType valStx type
let valResult ← mkLambdaFVars xs valResult
unless (← isDefEq val valResult) do
throwError "unexpected error when elaborating 'let'"
pure result
structure LetIdDeclView where
id : Name
binders : Array Syntax
type : Syntax
value : Syntax
def mkLetIdDeclView (letIdDecl : Syntax) : LetIdDeclView :=
-- `letIdDecl` is of the form `ident >> many bracketedBinder >> optType >> " := " >> termParser
let id := letIdDecl[0].getId
let binders := letIdDecl[1].getArgs
let optType := letIdDecl[2]
let type := expandOptType letIdDecl optType
let value := letIdDecl[4]
{ id := id, binders := binders, type := type, value := value }
def expandLetEqnsDecl (letDecl : Syntax) : MacroM Syntax := do
let ref := letDecl
let matchAlts := letDecl[3]
let val ← expandMatchAltsIntoMatch ref matchAlts
pure $ Syntax.node `Lean.Parser.Term.letIdDecl #[letDecl[0], letDecl[1], letDecl[2], mkAtomFrom ref " := ", val]
def elabLetDeclCore (stx : Syntax) (expectedType? : Option Expr) (useLetExpr : Bool) (elabBodyFirst : Bool) : TermElabM Expr := do
let ref := stx
let letDecl := stx[1][0]
let body := stx[3]
if letDecl.getKind == `Lean.Parser.Term.letIdDecl then
let { id := id, binders := binders, type := type, value := val } := mkLetIdDeclView letDecl
elabLetDeclAux id binders type val body expectedType? useLetExpr elabBodyFirst
else if letDecl.getKind == `Lean.Parser.Term.letPatDecl then
-- node `Lean.Parser.Term.letPatDecl $ try (termParser >> pushNone >> optType >> " := ") >> termParser
let pat := letDecl[0]
let optType := letDecl[2]
let type := expandOptType stx optType
let val := letDecl[4]
let stxNew ← `(let x : $type := $val; match x with | $pat => $body)
let stxNew := match useLetExpr, elabBodyFirst with
| true, false => stxNew
| true, true => stxNew.setKind `Lean.Parser.Term.«let*»
| false, true => stxNew.setKind `Lean.Parser.Term.«let!»
| false, false => unreachable!
withMacroExpansion stx stxNew $ elabTerm stxNew expectedType?
else if letDecl.getKind == `Lean.Parser.Term.letEqnsDecl then
let letDeclIdNew ← liftMacroM $ expandLetEqnsDecl letDecl
let declNew := stx[1].setArg 0 letDeclIdNew
let stxNew := stx.setArg 1 declNew
withMacroExpansion stx stxNew $ elabTerm stxNew expectedType?
else
throwUnsupportedSyntax
@[builtinTermElab «let»] def elabLetDecl : TermElab :=
fun stx expectedType? => elabLetDeclCore stx expectedType? true false
@[builtinTermElab «let!»] def elabLetBangDecl : TermElab :=
fun stx expectedType? => elabLetDeclCore stx expectedType? false false
@[builtinTermElab «let*»] def elabLetStarDecl : TermElab :=
fun stx expectedType? => elabLetDeclCore stx expectedType? true true
builtin_initialize registerTraceClass `Elab.let
end Lean.Elab.Term
|
20bc3802dcc9fb9dcc540231e53bc51209a8536c | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /stage0/src/Lean/Widget/InteractiveDiagnostic.lean | 59727ebf29e60bdfc720fbe3f216fd5050bd5da1 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | EdAyers/lean4 | 57ac632d6b0789cb91fab2170e8c9e40441221bd | 37ba0df5841bde51dbc2329da81ac23d4f6a4de4 | refs/heads/master | 1,676,463,245,298 | 1,660,619,433,000 | 1,660,619,433,000 | 183,433,437 | 1 | 0 | Apache-2.0 | 1,657,612,672,000 | 1,556,196,574,000 | Lean | UTF-8 | Lean | false | false | 8,095 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wojciech Nawrocki
-/
import Lean.Linter.UnusedVariables
import Lean.Server.Utils
import Lean.Widget.InteractiveGoal
namespace Lean.Widget
open Lsp Server
inductive MsgEmbed where
| expr : CodeWithInfos → MsgEmbed
| goal : InteractiveGoal → MsgEmbed
| lazyTrace : Nat → Name → WithRpcRef MessageData → MsgEmbed
deriving Inhabited, RpcEncodable
/-- We embed objects in LSP diagnostics by storing them in the tag of an empty subtree (`text ""`).
In other words, we terminate the `MsgEmbed`-tagged tree at embedded objects and instead store
the pretty-printed embed (which can itself be a `TaggedText`) in the tag. -/
abbrev InteractiveDiagnostic := Lsp.DiagnosticWith (TaggedText MsgEmbed)
deriving instance RpcEncodable for Lsp.DiagnosticWith
namespace InteractiveDiagnostic
open MsgEmbed
def toDiagnostic (diag : InteractiveDiagnostic) : Lsp.Diagnostic :=
{ diag with message := prettyTt diag.message }
where
prettyTt (tt : TaggedText MsgEmbed) : String :=
let tt : TaggedText MsgEmbed := tt.rewrite fun
| expr tt, _ => TaggedText.text tt.stripTags
| goal g, _ => TaggedText.text (toString g.pretty)
| lazyTrace _ _ _, subTt => subTt
tt.stripTags
end InteractiveDiagnostic
private def mkPPContext (nCtx : NamingContext) (ctx : MessageDataContext) : PPContext := {
env := ctx.env, mctx := ctx.mctx, lctx := ctx.lctx, opts := ctx.opts,
currNamespace := nCtx.currNamespace, openDecls := nCtx.openDecls
}
private inductive EmbedFmt
| /-- Tags denote `Info` objects. -/
expr (ctx : Elab.ContextInfo) (infos : Std.RBMap Nat Elab.Info compare)
| goal (ctx : Elab.ContextInfo) (lctx : LocalContext) (g : MVarId)
| /-- Some messages (in particular, traces) are too costly to print eagerly. Instead, we allow
the user to expand sub-traces interactively. -/
lazyTrace (nCtx : NamingContext) (ctx? : Option MessageDataContext) (cls : Name) (m : MessageData)
| /-- Ignore any tags in this subtree. -/
ignoreTags
deriving Inhabited
private abbrev MsgFmtM := StateT (Array EmbedFmt) IO
open MessageData in
/-- We first build a `Nat`-tagged `Format` with the most shallow tag, if any,
in every branch indexing into the array of embedded objects. -/
private partial def msgToInteractiveAux (msgData : MessageData) (hasWidgets : Bool) : IO (Format × Array EmbedFmt) :=
go { currNamespace := Name.anonymous, openDecls := [] } none msgData #[]
where
pushEmbed (e : EmbedFmt) : MsgFmtM Nat :=
modifyGet fun es => (es.size, es.push e)
withIgnoreTags (x : MsgFmtM Format) : MsgFmtM Format := do
let fmt ← x
let t ← pushEmbed EmbedFmt.ignoreTags
return Format.tag t fmt
go : NamingContext → Option MessageDataContext → MessageData → MsgFmtM Format
| _, _, ofFormat fmt => withIgnoreTags (pure fmt)
| _, _, ofLevel u => return format u
| _, _, ofName n => return format n
| nCtx, some ctx, ofSyntax s => withIgnoreTags (ppTerm (mkPPContext nCtx ctx) ⟨s⟩) -- HACK: might not be a term
| _, none, ofSyntax s => withIgnoreTags (pure s.formatStx)
| _, none, ofExpr e => return format (toString e)
| nCtx, some ctx, ofExpr e => do
let ci : Elab.ContextInfo := {
env := ctx.env
mctx := ctx.mctx
fileMap := default
options := ctx.opts
currNamespace := nCtx.currNamespace
openDecls := nCtx.openDecls
-- Hack: to make sure unique ids created at `ppExprWithInfos` do not collide with ones in `ctx.mctx`
ngen := { namePrefix := `_diag }
}
let (fmt, infos) ← ci.runMetaM ctx.lctx <| PrettyPrinter.ppExprWithInfos e
let t ← pushEmbed <| EmbedFmt.expr ci infos
return Format.tag t fmt
| _, none, ofGoal mvarId => pure $ "goal " ++ format (mkMVar mvarId)
| nCtx, some ctx, ofGoal mvarId => withIgnoreTags <| ppGoal (mkPPContext nCtx ctx) mvarId
| nCtx, _, withContext ctx d => go nCtx ctx d
| _, ctx, withNamingContext nCtx d => go nCtx ctx d
| nCtx, ctx, tagged t d => do
-- We postfix trace contexts with `_traceCtx` in order to detect them in messages.
if let .str cls "_traceCtx" := t then
-- When interactive trace exploration is possible, we hide traces which can otherwise
-- take significant resources to pretty-print.
if hasWidgets then
let f ← pushEmbed <| EmbedFmt.lazyTrace nCtx ctx cls d
return Format.tag f s!"[{cls}] (trace hidden)"
else
go nCtx ctx d
else
go nCtx ctx d
| nCtx, ctx, nest n d => Format.nest n <$> go nCtx ctx d
| nCtx, ctx, compose d₁ d₂ => do let d₁ ← go nCtx ctx d₁; let d₂ ← go nCtx ctx d₂; pure $ d₁ ++ d₂
| nCtx, ctx, group d => Format.group <$> go nCtx ctx d
| nCtx, ctx, node ds => Format.nest 2 <$> ds.foldlM (fun r d => do let d ← go nCtx ctx d; pure $ r ++ Format.line ++ d) Format.nil
partial def msgToInteractive (msgData : MessageData) (hasWidgets : Bool) (indent : Nat := 0) : IO (TaggedText MsgEmbed) := do
let (fmt, embeds) ← msgToInteractiveAux msgData hasWidgets
let tt := TaggedText.prettyTagged fmt indent
/- Here we rewrite a `TaggedText Nat` corresponding to a whole `MessageData` into one where
the tags are `TaggedText MsgEmbed`s corresponding to embedded objects with their subtree
empty (`text ""`). In other words, we terminate the `MsgEmbed`-tagged -tree at embedded objects
and store the pretty-printed embed (which can itself be a `TaggedText`) in the tag. -/
tt.rewriteM fun (n, col) subTt =>
match embeds.get! n with
| EmbedFmt.expr ctx infos =>
let subTt' := tagExprInfos ctx infos subTt
return TaggedText.tag (MsgEmbed.expr subTt') (TaggedText.text subTt.stripTags)
| EmbedFmt.goal _ _ _ =>
-- TODO(WN): use InteractiveGoal types here
unreachable!
| EmbedFmt.lazyTrace nCtx ctx? cls m =>
let msg :=
match ctx? with
| some ctx => MessageData.withNamingContext nCtx <| MessageData.withContext ctx m
| none => MessageData.withNamingContext nCtx m
return TaggedText.tag (MsgEmbed.lazyTrace col cls ⟨msg⟩) (TaggedText.text subTt.stripTags)
| EmbedFmt.ignoreTags => return TaggedText.text subTt.stripTags
/-- Transform a Lean Message concerning the given text into an LSP Diagnostic. -/
def msgToInteractiveDiagnostic (text : FileMap) (m : Message) (hasWidgets : Bool) : IO InteractiveDiagnostic := do
let low : Lsp.Position := text.leanPosToLspPos m.pos
let fullHigh := text.leanPosToLspPos <| m.endPos.getD m.pos
let high : Lsp.Position := match m.endPos with
| some endPos =>
/-
Truncate messages that are more than one line long.
This is a workaround to avoid big blocks of "red squiggly lines" on VS Code.
TODO: should it be a parameter?
-/
let endPos := if endPos.line > m.pos.line then { line := m.pos.line + 1, column := 0 } else endPos
text.leanPosToLspPos endPos
| none => low
let range : Range := ⟨low, high⟩
let fullRange : Range := ⟨low, fullHigh⟩
let severity? := some <| match m.severity with
| .information => .information
| .warning => .warning
| .error => .error
let source? := some "Lean 4"
let tags? :=
if m.data.isDeprecationWarning then some #[.deprecated]
else if m.data.isUnusedVariableWarning then some #[.unnecessary]
else none
let message ← try
msgToInteractive m.data hasWidgets
catch ex =>
pure <| TaggedText.text s!"[error when printing message: {ex.toString}]"
pure { range, fullRange, severity?, source?, message, tags? }
end Lean.Widget
|
12d3874f8774327b1935495989fb5aaff2dc17c7 | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /archive/sensitivity.lean | 915e06fa2a7732bdd81ae95bf0b8d9ce8ddcae47 | [
"Apache-2.0"
] | permissive | hikari0108/mathlib | b7ea2b7350497ab1a0b87a09d093ecc025a50dfa | a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901 | refs/heads/master | 1,690,483,608,260 | 1,631,541,580,000 | 1,631,541,580,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 15,669 | lean | /-
Copyright (c) 2019 Reid Barton, Johan Commelin, Jesse Han, Chris Hughes, Robert Y. Lewis,
Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Johan Commelin, Jesse Han, Chris Hughes, Robert Y. Lewis, Patrick Massot
-/
import tactic.fin_cases
import tactic.apply_fun
import linear_algebra.finite_dimensional
import linear_algebra.dual
import analysis.normed_space.basic
import data.real.sqrt
/-!
# Huang's sensitivity theorem
A formalization of Hao Huang's sensitivity theorem: in the hypercube of
dimension n ≥ 1, if one colors more than half the vertices then at least one
vertex has at least √n colored neighbors.
A fun summer collaboration by
Reid Barton, Johan Commelin, Jesse Han, Chris Hughes, Robert Y. Lewis, and Patrick Massot,
based on Don Knuth's account of the story
(https://www.cs.stanford.edu/~knuth/papers/huang.pdf),
using the Lean theorem prover (https://leanprover.github.io/),
by Leonardo de Moura at Microsoft Research, and his collaborators
(https://leanprover.github.io/people/),
and using Lean's user maintained mathematics library
(https://github.com/leanprover-community/mathlib).
The project was developed at https://github.com/leanprover-community/lean-sensitivity and is now
archived at https://github.com/leanprover-community/mathlib/blob/master/archive/sensitivity.lean
-/
/-! The next two lines assert we do not want to give a constructive proof,
but rather use classical logic. -/
noncomputable theory
open_locale classical
/-! We also want to use the notation `∑` for sums. -/
open_locale big_operators
notation `|`x`|` := abs x
notation `√` := real.sqrt
open function bool linear_map fintype finite_dimensional dual_pair
/-!
### The hypercube
Notations:
- `ℕ` denotes natural numbers (including zero).
- `fin n` = {0, ⋯ , n - 1}.
- `bool` = {`tt`, `ff`}.
-/
/-- The hypercube in dimension `n`. -/
@[derive [inhabited, fintype]] def Q (n : ℕ) := fin n → bool
/-- The projection from `Q (n + 1)` to `Q n` forgetting the first value
(ie. the image of zero). -/
def π {n : ℕ} : Q (n + 1) → Q n := λ p, p ∘ fin.succ
namespace Q
/-! `n` will always denote a natural number. -/
variable (n : ℕ)
/-- `Q 0` has a unique element. -/
instance : unique (Q 0) :=
⟨⟨λ _, tt⟩, by { intro, ext x, fin_cases x }⟩
/-- `Q n` has 2^n elements. -/
lemma card : card (Q n) = 2^n :=
by simp [Q]
/-! Until the end of this namespace, `n` will be an implicit argument (still
a natural number). -/
variable {n}
lemma succ_n_eq (p q : Q (n+1)) : p = q ↔ (p 0 = q 0 ∧ π p = π q) :=
begin
split,
{ rintro rfl, exact ⟨rfl, rfl⟩, },
{ rintros ⟨h₀, h⟩,
ext x,
by_cases hx : x = 0,
{ rwa hx },
{ rw ← fin.succ_pred x hx,
convert congr_fun h (fin.pred x hx) } }
end
/-- The adjacency relation defining the graph structure on `Q n`:
`p.adjacent q` if there is an edge from `p` to `q` in `Q n`. -/
def adjacent {n : ℕ} (p : Q n) : set (Q n) := λ q, ∃! i, p i ≠ q i
/-- In `Q 0`, no two vertices are adjacent. -/
lemma not_adjacent_zero (p q : Q 0) : ¬ p.adjacent q :=
by rintros ⟨v, _⟩; apply fin_zero_elim v
/-- If `p` and `q` in `Q (n+1)` have different values at zero then they are adjacent
iff their projections to `Q n` are equal. -/
lemma adj_iff_proj_eq {p q : Q (n+1)} (h₀ : p 0 ≠ q 0) :
p.adjacent q ↔ π p = π q :=
begin
split,
{ rintros ⟨i, h_eq, h_uni⟩,
ext x, by_contradiction hx,
apply fin.succ_ne_zero x,
rw [h_uni _ hx, h_uni _ h₀] },
{ intro heq,
use [0, h₀],
intros y hy,
contrapose! hy,
rw ←fin.succ_pred _ hy,
apply congr_fun heq }
end
/-- If `p` and `q` in `Q (n+1)` have the same value at zero then they are adjacent
iff their projections to `Q n` are adjacent. -/
lemma adj_iff_proj_adj {p q : Q (n+1)} (h₀ : p 0 = q 0) :
p.adjacent q ↔ (π p).adjacent (π q) :=
begin
split,
{ rintros ⟨i, h_eq, h_uni⟩,
have h_i : i ≠ 0, from λ h_i, absurd h₀ (by rwa h_i at h_eq),
use [i.pred h_i,
show p (fin.succ (fin.pred i _)) ≠ q (fin.succ (fin.pred i _)),
by rwa fin.succ_pred],
intros y hy,
simp [eq.symm (h_uni _ hy)] },
{ rintros ⟨i, h_eq, h_uni⟩,
use [i.succ, h_eq],
intros y hy,
rw [←fin.pred_inj, fin.pred_succ],
{ apply h_uni,
change p (fin.pred _ _).succ ≠ q (fin.pred _ _).succ,
simp [hy] },
{ contrapose! hy,
rw [hy, h₀] },
{ apply fin.succ_ne_zero } }
end
@[symm] lemma adjacent.symm {p q : Q n} : p.adjacent q ↔ q.adjacent p :=
by simp only [adjacent, ne_comm]
end Q
/-! ### The vector space -/
/-- The free vector space on vertices of a hypercube, defined inductively. -/
def V : ℕ → Type
| 0 := ℝ
| (n+1) := V n × V n
namespace V
variables (n : ℕ)
/-! `V n` is a real vector space whose equality relation is computable. -/
instance : decidable_eq (V n) :=
by { induction n ; { dunfold V, resetI, apply_instance } }
instance : add_comm_group (V n) :=
by { induction n ; { dunfold V, resetI, apply_instance } }
instance : module ℝ (V n) :=
by { induction n ; { dunfold V, resetI, apply_instance } }
end V
/-- The basis of `V` indexed by the hypercube, defined inductively. -/
noncomputable def e : Π {n}, Q n → V n
| 0 := λ _, (1:ℝ)
| (n+1) := λ x, cond (x 0) (e (π x), 0) (0, e (π x))
@[simp] lemma e_zero_apply (x : Q 0) : e x = (1 : ℝ) := rfl
/-- The dual basis to `e`, defined inductively. -/
noncomputable def ε : Π {n : ℕ} (p : Q n), V n →ₗ[ℝ] ℝ
| 0 _ := linear_map.id
| (n+1) p := cond (p 0) ((ε $ π p).comp $ linear_map.fst _ _ _)
((ε $ π p).comp $ linear_map.snd _ _ _)
variable {n : ℕ}
lemma duality (p q : Q n) : ε p (e q) = if p = q then 1 else 0 :=
begin
induction n with n IH,
{ rw (show p = q, from subsingleton.elim p q),
dsimp [ε, e],
simp },
{ dsimp [ε, e],
cases hp : p 0 ; cases hq : q 0,
all_goals {
repeat {rw cond_tt},
repeat {rw cond_ff},
simp only [linear_map.fst_apply, linear_map.snd_apply, linear_map.comp_apply, IH],
try { congr' 1, rw Q.succ_n_eq, finish },
try {
erw (ε _).map_zero,
have : p ≠ q, { intro h, rw p.succ_n_eq q at h, finish },
simp [this] } } }
end
/-- Any vector in `V n` annihilated by all `ε p`'s is zero. -/
lemma epsilon_total {v : V n} (h : ∀ p : Q n, (ε p) v = 0) : v = 0 :=
begin
induction n with n ih,
{ dsimp [ε] at h, exact h (λ _, tt) },
{ cases v with v₁ v₂,
ext ; change _ = (0 : V n) ; simp only ; apply ih ; intro p ;
[ let q : Q (n+1) := λ i, if h : i = 0 then tt else p (i.pred h),
let q : Q (n+1) := λ i, if h : i = 0 then ff else p (i.pred h)],
all_goals {
specialize h q,
rw [ε, show q 0 = tt, from rfl, cond_tt] at h <|>
rw [ε, show q 0 = ff, from rfl, cond_ff] at h,
rwa show p = π q, by { ext, simp [q, fin.succ_ne_zero, π] } } }
end
/-- `e` and `ε` are dual families of vectors. It implies that `e` is indeed a basis
and `ε` computes coefficients of decompositions of vectors on that basis. -/
def dual_pair_e_ε (n : ℕ) : dual_pair (@e n) (@ε n) :=
{ eval := duality,
total := @epsilon_total _ }
/-! We will now derive the dimension of `V`, first as a cardinal in `dim_V` and,
since this cardinal is finite, as a natural number in `finrank_V` -/
lemma dim_V : module.rank ℝ (V n) = 2^n :=
have module.rank ℝ (V n) = (2^n : ℕ),
by { rw [dim_eq_card_basis (dual_pair_e_ε _).basis, Q.card]; apply_instance },
by assumption_mod_cast
instance : finite_dimensional ℝ (V n) :=
finite_dimensional.of_fintype_basis (dual_pair_e_ε _).basis
lemma finrank_V : finrank ℝ (V n) = 2^n :=
have _ := @dim_V n,
by rw ←finrank_eq_dim at this; assumption_mod_cast
/-! ### The linear map -/
/-- The linear operator $f_n$ corresponding to Huang's matrix $A_n$,
defined inductively as a ℝ-linear map from `V n` to `V n`. -/
noncomputable def f : Π n, V n →ₗ[ℝ] V n
| 0 := 0
| (n+1) := linear_map.prod
(linear_map.coprod (f n) linear_map.id)
(linear_map.coprod linear_map.id (-f n))
/-! The preceding definition uses linear map constructions to automatically
get that `f` is linear, but its values are somewhat buried as a side-effect.
The next two lemmas unbury them. -/
@[simp] lemma f_zero : f 0 = 0 := rfl
lemma f_succ_apply (v : V (n+1)) :
f (n+1) v = (f n v.1 + v.2, v.1 - f n v.2) :=
begin
cases v,
rw f,
simp only [linear_map.id_apply, linear_map.prod_apply, prod.mk.inj_iff,
linear_map.neg_apply, sub_eq_add_neg, linear_map.coprod_apply],
exact ⟨rfl, rfl⟩
end
/-! In the next statement, the explicit conversion `(n : ℝ)` of `n` to a real number
is necessary since otherwise `n • v` refers to the multiplication defined
using only the addition of `V`. -/
lemma f_squared : ∀ v : V n, (f n) (f n v) = (n : ℝ) • v :=
begin
induction n with n IH; intro,
{ simpa only [nat.cast_zero, zero_smul] },
{ cases v, simp [f_succ_apply, IH, add_smul, add_assoc], abel }
end
/-! We now compute the matrix of `f` in the `e` basis (`p` is the line index,
`q` the column index). -/
lemma f_matrix :
∀ p q : Q n, |ε q (f n (e p))| = if q.adjacent p then 1 else 0 :=
begin
induction n with n IH,
{ intros p q,
dsimp [f],
simp [Q.not_adjacent_zero] },
{ intros p q,
have ite_nonneg : ite (π q = π p) (1 : ℝ) 0 ≥ 0,
{ split_ifs ; norm_num },
have f_map_zero := (show (V (n+0)) →ₗ[ℝ] (V n), from f n).map_zero,
dsimp [e, ε, f], cases hp : p 0 ; cases hq : q 0,
all_goals
{ repeat {rw cond_tt}, repeat {rw cond_ff},
simp [f_map_zero, hp, hq, IH, duality, abs_of_nonneg ite_nonneg, Q.adj_iff_proj_eq,
Q.adj_iff_proj_adj] } }
end
/-- The linear operator $g_m$ corresponding to Knuth's matrix $B_m$. -/
noncomputable def g (m : ℕ) : V m →ₗ[ℝ] V (m+1) :=
linear_map.prod (f m + √(m+1) • linear_map.id) linear_map.id
/-! In the following lemmas, `m` will denote a natural number. -/
variables {m : ℕ}
/-! Again we unpack what are the values of `g`. -/
lemma g_apply : ∀ v, g m v = (f m v + √(m+1) • v, v) :=
by delta g; simp
lemma g_injective : injective (g m) :=
begin
rw g,
intros x₁ x₂ h,
simp only [linear_map.prod_apply, linear_map.id_apply, prod.mk.inj_iff] at h,
exact h.right
end
lemma f_image_g (w : V (m + 1)) (hv : ∃ v, g m v = w) :
f (m + 1) w = √(m + 1) • w :=
begin
rcases hv with ⟨v, rfl⟩,
have : √(m+1) * √(m+1) = m+1 :=
real.mul_self_sqrt (by exact_mod_cast zero_le _),
simp [this, f_succ_apply, g_apply, f_squared, smul_add, add_smul, smul_smul],
abel
end
/-!
### The main proof
In this section, in order to enforce that `n` is positive, we write it as
`m + 1` for some natural number `m`. -/
/-! `dim X` will denote the dimension of a subspace `X` as a cardinal. -/
notation `dim` X:70 := module.rank ℝ ↥X
/-! `fdim X` will denote the (finite) dimension of a subspace `X` as a natural number. -/
notation `fdim` := finrank ℝ
/-! `Span S` will denote the ℝ-subspace spanned by `S`. -/
notation `Span` := submodule.span ℝ
/-! `Card X` will denote the cardinal of a subset of a finite type, as a
natural number. -/
notation `Card` X:70 := X.to_finset.card
/-! In the following, `⊓` and `⊔` will denote intersection and sums of ℝ-subspaces,
equipped with their subspace structures. The notations come from the general
theory of lattices, with inf and sup (also known as meet and join). -/
/-- If a subset `H` of `Q (m+1)` has cardinal at least `2^m + 1` then the
subspace of `V (m+1)` spanned by the corresponding basis vectors non-trivially
intersects the range of `g m`. -/
lemma exists_eigenvalue (H : set (Q (m + 1))) (hH : Card H ≥ 2^m + 1) :
∃ y ∈ Span (e '' H) ⊓ (g m).range, y ≠ (0 : _) :=
begin
let W := Span (e '' H),
let img := (g m).range,
suffices : 0 < dim (W ⊓ img),
{ simp only [exists_prop],
exact_mod_cast exists_mem_ne_zero_of_dim_pos this },
have dim_le : dim (W ⊔ img) ≤ 2^(m + 1),
{ convert ← dim_submodule_le (W ⊔ img),
apply dim_V },
have dim_add : dim (W ⊔ img) + dim (W ⊓ img) = dim W + 2^m,
{ convert ← dim_sup_add_dim_inf_eq W img,
rw ← dim_eq_of_injective (g m) g_injective,
apply dim_V },
have dimW : dim W = card H,
{ have li : linear_independent ℝ (set.restrict e H),
{ convert (dual_pair_e_ε _).basis.linear_independent.comp _ subtype.val_injective,
rw (dual_pair_e_ε _).coe_basis },
have hdW := dim_span li,
rw set.range_restrict at hdW,
convert hdW,
rw [← (dual_pair_e_ε _).coe_basis, cardinal.mk_image_eq (dual_pair_e_ε _).basis.injective,
cardinal.fintype_card] },
rw ← finrank_eq_dim ℝ at ⊢ dim_le dim_add dimW,
rw [← finrank_eq_dim ℝ, ← finrank_eq_dim ℝ] at dim_add,
norm_cast at ⊢ dim_le dim_add dimW,
rw pow_succ' at dim_le,
rw set.to_finset_card at hH,
linarith
end
/-- **Huang sensitivity theorem** also known as the **Huang degree theorem** -/
theorem huang_degree_theorem (H : set (Q (m + 1))) (hH : Card H ≥ 2^m + 1) :
∃ q, q ∈ H ∧ √(m + 1) ≤ Card (H ∩ q.adjacent) :=
begin
rcases exists_eigenvalue H hH with ⟨y, ⟨⟨y_mem_H, y_mem_g⟩, y_ne⟩⟩,
have coeffs_support : ((dual_pair_e_ε (m+1)).coeffs y).support ⊆ H.to_finset,
{ intros p p_in,
rw finsupp.mem_support_iff at p_in,
rw set.mem_to_finset,
exact (dual_pair_e_ε _).mem_of_mem_span y_mem_H p p_in },
obtain ⟨q, H_max⟩ : ∃ q : Q (m+1), ∀ q' : Q (m+1), |(ε q' : _) y| ≤ |ε q y|,
from fintype.exists_max _,
have H_q_pos : 0 < |ε q y|,
{ contrapose! y_ne,
exact epsilon_total (λ p, abs_nonpos_iff.mp (le_trans (H_max p) y_ne)) },
refine ⟨q, (dual_pair_e_ε _).mem_of_mem_span y_mem_H q (abs_pos.mp H_q_pos), _⟩,
let s := √(m+1),
suffices : s * |ε q y| ≤ ↑(_) * |ε q y|,
from (mul_le_mul_right H_q_pos).mp ‹_›,
let coeffs := (dual_pair_e_ε (m+1)).coeffs,
calc
s * |ε q y|
= |ε q (s • y)| :
by rw [map_smul, smul_eq_mul, abs_mul, abs_of_nonneg (real.sqrt_nonneg _)]
... = |ε q (f (m+1) y)| : by rw [← f_image_g y (by simpa using y_mem_g)]
... = |ε q (f (m+1) (lc _ (coeffs y)))| : by rw (dual_pair_e_ε _).lc_coeffs y
... = |(coeffs y).sum (λ (i : Q (m + 1)) (a : ℝ), a • ((ε q) ∘ (f (m + 1)) ∘
λ (i : Q (m + 1)), e i) i)| :
by erw [(f $ m + 1).map_finsupp_total, (ε q).map_finsupp_total, finsupp.total_apply]
... ≤ ∑ p in (coeffs y).support, |(coeffs y p) * (ε q $ f (m+1) $ e p)| :
norm_sum_le _ $ λ p, coeffs y p * _
... = ∑ p in (coeffs y).support, |coeffs y p| * ite (q.adjacent p) 1 0 :
by simp only [abs_mul, f_matrix]
... = ∑ p in (coeffs y).support.filter (Q.adjacent q), |coeffs y p| :
by simp [finset.sum_filter]
... ≤ ∑ p in (coeffs y).support.filter (Q.adjacent q), |coeffs y q| :
finset.sum_le_sum (λ p _, H_max p)
... = (((coeffs y).support.filter (Q.adjacent q)).card : ℝ) * |coeffs y q| :
by rw [finset.sum_const, nsmul_eq_mul]
... = (((coeffs y).support ∩ (Q.adjacent q).to_finset).card : ℝ) * |coeffs y q| :
by { congr' with x, simp, refl }
... ≤ (finset.card ((H ∩ Q.adjacent q).to_finset )) * |ε q y| :
begin
refine (mul_le_mul_right H_q_pos).2 _,
norm_cast,
apply finset.card_le_of_subset,
rw set.to_finset_inter,
convert finset.inter_subset_inter_right coeffs_support
end
end
|
1de38a7beba2df50967b7909202e5ae2aa9d5d21 | 8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3 | /src/group_theory/order_of_element.lean | ca61237dca5904a17859d1351306faac0b973515 | [
"Apache-2.0"
] | permissive | troyjlee/mathlib | e18d4b8026e32062ab9e89bc3b003a5d1cfec3f5 | 45e7eb8447555247246e3fe91c87066506c14875 | refs/heads/master | 1,689,248,035,046 | 1,629,470,528,000 | 1,629,470,528,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 39,286 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Julian Kuelshammer
-/
import algebra.pointwise
import group_theory.coset
import dynamics.periodic_pts
import algebra.iterate_hom
/-!
# Order of an element
This file defines the order of an element of a finite group. For a finite group `G` the order of
`x ∈ G` is the minimal `n ≥ 1` such that `x ^ n = 1`.
## Main definitions
* `is_of_fin_order` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite
order.
* `is_of_fin_add_order` is the additive analogue of `is_of_find_order`.
* `order_of x` defines the order of an element `x` of a monoid `G`, by convention its value is `0`
if `x` has infinite order.
* `add_order_of` is the additive analogue of `order_of`.
## Tags
order of an element
-/
open function nat
open_locale pointwise
universes u v
variables {G : Type u} {A : Type v}
variables {x y : G} {a b : A} {n m : ℕ}
section monoid_add_monoid
variables [monoid G] [add_monoid A]
section is_of_fin_order
lemma is_periodic_pt_add_iff_nsmul_eq_zero (a : A) :
is_periodic_pt ((+) a) n 0 ↔ n • a = 0 :=
by rw [is_periodic_pt, is_fixed_pt, add_left_iterate, add_zero]
@[to_additive is_periodic_pt_add_iff_nsmul_eq_zero]
lemma is_periodic_pt_mul_iff_pow_eq_one (x : G) : is_periodic_pt ((*) x) n 1 ↔ x ^ n = 1 :=
by rw [is_periodic_pt, is_fixed_pt, mul_left_iterate, mul_one]
/-- `is_of_fin_add_order` is a predicate on an element `a` of an additive monoid to be of finite
order, i.e. there exists `n ≥ 1` such that `n • a = 0`.-/
def is_of_fin_add_order (a : A) : Prop :=
(0 : A) ∈ periodic_pts ((+) a)
/-- `is_of_fin_order` is a predicate on an element `x` of a monoid to be of finite order, i.e. there
exists `n ≥ 1` such that `x ^ n = 1`.-/
@[to_additive is_of_fin_add_order]
def is_of_fin_order (x : G) : Prop :=
(1 : G) ∈ periodic_pts ((*) x)
lemma is_of_fin_add_order_of_mul_iff :
is_of_fin_add_order (additive.of_mul x) ↔ is_of_fin_order x := iff.rfl
lemma is_of_fin_order_of_add_iff :
is_of_fin_order (multiplicative.of_add a) ↔ is_of_fin_add_order a := iff.rfl
lemma is_of_fin_add_order_iff_nsmul_eq_zero (a : A) :
is_of_fin_add_order a ↔ ∃ n, 0 < n ∧ n • a = 0 :=
by { convert iff.rfl, simp only [exists_prop, is_periodic_pt_add_iff_nsmul_eq_zero] }
@[to_additive is_of_fin_add_order_iff_nsmul_eq_zero]
lemma is_of_fin_order_iff_pow_eq_one (x : G) :
is_of_fin_order x ↔ ∃ n, 0 < n ∧ x ^ n = 1 :=
by { convert iff.rfl, simp [is_periodic_pt_mul_iff_pow_eq_one] }
end is_of_fin_order
/-- `add_order_of a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `n • a = 0` if it
exists. Otherwise, i.e. if `a` is of infinite order, then `add_order_of a` is `0` by convention.-/
noncomputable def add_order_of (a : A) : ℕ :=
minimal_period ((+) a) 0
/-- `order_of x` is the order of the element `x`, i.e. the `n ≥ 1`, s.t. `x ^ n = 1` if it exists.
Otherwise, i.e. if `x` is of infinite order, then `order_of x` is `0` by convention.-/
@[to_additive add_order_of]
noncomputable def order_of (x : G) : ℕ :=
minimal_period ((*) x) 1
attribute [to_additive add_order_of] order_of
@[to_additive]
lemma commute.order_of_mul_dvd_lcm (h : commute x y) :
order_of (x * y) ∣ nat.lcm (order_of x) (order_of y) :=
begin
convert function.commute.minimal_period_of_comp_dvd_lcm h.function_commute_mul_left,
rw [order_of, comp_mul_left],
end
@[simp] lemma add_order_of_of_mul_eq_order_of (x : G) :
add_order_of (additive.of_mul x) = order_of x := rfl
@[simp] lemma order_of_of_add_eq_add_order_of (a : A) :
order_of (multiplicative.of_add a) = add_order_of a := rfl
@[to_additive add_order_of_pos']
lemma order_of_pos' (h : is_of_fin_order x) : 0 < order_of x :=
minimal_period_pos_of_mem_periodic_pts h
lemma pow_order_of_eq_one (x : G) : x ^ order_of x = 1 :=
begin
convert is_periodic_pt_minimal_period ((*) x) _,
rw [order_of, mul_left_iterate, mul_one],
end
lemma add_order_of_nsmul_eq_zero (a : A) : add_order_of a • a = 0 :=
begin
convert is_periodic_pt_minimal_period ((+) a) _,
rw [add_order_of, add_left_iterate, add_zero],
end
attribute [to_additive add_order_of_nsmul_eq_zero] pow_order_of_eq_one
@[to_additive add_order_of_eq_zero]
lemma order_of_eq_zero (h : ¬ is_of_fin_order x) : order_of x = 0 :=
by rwa [order_of, minimal_period, dif_neg]
lemma nsmul_ne_zero_of_lt_add_order_of' (n0 : n ≠ 0) (h : n < add_order_of a) :
n • a ≠ 0 :=
λ j, not_is_periodic_pt_of_pos_of_lt_minimal_period n0 h
((is_periodic_pt_add_iff_nsmul_eq_zero a).mpr j)
@[to_additive nsmul_ne_zero_of_lt_add_order_of']
lemma pow_eq_one_of_lt_order_of' (n0 : n ≠ 0) (h : n < order_of x) : x ^ n ≠ 1 :=
λ j, not_is_periodic_pt_of_pos_of_lt_minimal_period n0 h
((is_periodic_pt_mul_iff_pow_eq_one x).mpr j)
lemma add_order_of_le_of_nsmul_eq_zero (hn : 0 < n) (h : n • a = 0) : add_order_of a ≤ n :=
is_periodic_pt.minimal_period_le hn (by rwa is_periodic_pt_add_iff_nsmul_eq_zero)
@[to_additive add_order_of_le_of_nsmul_eq_zero]
lemma order_of_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : order_of x ≤ n :=
is_periodic_pt.minimal_period_le hn (by rwa is_periodic_pt_mul_iff_pow_eq_one)
@[simp] lemma order_of_one : order_of (1 : G) = 1 :=
by rw [order_of, one_mul_eq_id, minimal_period_id]
@[simp] lemma add_order_of_zero : add_order_of (0 : A) = 1 :=
by simp only [←order_of_of_add_eq_add_order_of, order_of_one, of_add_zero]
attribute [to_additive add_order_of_zero] order_of_one
@[simp] lemma order_of_eq_one_iff : order_of x = 1 ↔ x = 1 :=
by rw [order_of, is_fixed_point_iff_minimal_period_eq_one, is_fixed_pt, mul_one]
@[simp] lemma add_order_of_eq_one_iff : add_order_of a = 1 ↔ a = 0 :=
by simp [← order_of_of_add_eq_add_order_of]
attribute [to_additive add_order_of_eq_one_iff] order_of_eq_one_iff
lemma pow_eq_mod_order_of {n : ℕ} : x ^ n = x ^ (n % order_of x) :=
calc x ^ n = x ^ (n % order_of x + order_of x * (n / order_of x)) : by rw [nat.mod_add_div]
... = x ^ (n % order_of x) : by simp [pow_add, pow_mul, pow_order_of_eq_one]
lemma nsmul_eq_mod_add_order_of {n : ℕ} : n • a = (n % add_order_of a) • a :=
begin
apply multiplicative.of_add.injective,
rw [← order_of_of_add_eq_add_order_of, of_add_nsmul, of_add_nsmul, pow_eq_mod_order_of],
end
attribute [to_additive nsmul_eq_mod_add_order_of] pow_eq_mod_order_of
lemma order_of_dvd_of_pow_eq_one (h : x ^ n = 1) : order_of x ∣ n :=
is_periodic_pt.minimal_period_dvd ((is_periodic_pt_mul_iff_pow_eq_one _).mpr h)
lemma add_order_of_dvd_of_nsmul_eq_zero (h : n • a = 0) : add_order_of a ∣ n :=
is_periodic_pt.minimal_period_dvd ((is_periodic_pt_add_iff_nsmul_eq_zero _).mpr h)
attribute [to_additive add_order_of_dvd_of_nsmul_eq_zero] order_of_dvd_of_pow_eq_one
lemma add_order_of_dvd_iff_nsmul_eq_zero {n : ℕ} : add_order_of a ∣ n ↔ n • a = 0 :=
⟨λ h, by rw [nsmul_eq_mod_add_order_of, nat.mod_eq_zero_of_dvd h, zero_nsmul],
add_order_of_dvd_of_nsmul_eq_zero⟩
@[to_additive add_order_of_dvd_iff_nsmul_eq_zero]
lemma order_of_dvd_iff_pow_eq_one {n : ℕ} : order_of x ∣ n ↔ x ^ n = 1 :=
⟨λ h, by rw [pow_eq_mod_order_of, nat.mod_eq_zero_of_dvd h, pow_zero], order_of_dvd_of_pow_eq_one⟩
lemma exists_pow_eq_self_of_coprime (h : n.coprime (order_of x)) :
∃ m : ℕ, (x ^ n) ^ m = x :=
begin
by_cases h0 : order_of x = 0,
{ rw [h0, coprime_zero_right] at h,
exact ⟨1, by rw [h, pow_one, pow_one]⟩ },
by_cases h1 : order_of x = 1,
{ exact ⟨0, by rw [order_of_eq_one_iff.mp h1, one_pow, one_pow]⟩ },
obtain ⟨m, hm⟩ :=
exists_mul_mod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, h1⟩),
exact ⟨m, by rw [←pow_mul, pow_eq_mod_order_of, hm, pow_one]⟩,
end
lemma exists_nsmul_eq_self_of_coprime (a : A)
(h : coprime n (add_order_of a)) : ∃ m : ℕ, m • (n • a) = a :=
begin
change n.coprime (order_of (multiplicative.of_add a)) at h,
exact exists_pow_eq_self_of_coprime h,
end
attribute [to_additive exists_nsmul_eq_self_of_coprime] exists_pow_eq_self_of_coprime
lemma add_order_of_eq_add_order_of_iff {B : Type*} [add_monoid B] {b : B} :
add_order_of a = add_order_of b ↔ ∀ n : ℕ, n • a = 0 ↔ n • b = 0 :=
begin
simp_rw ← add_order_of_dvd_iff_nsmul_eq_zero,
exact ⟨λ h n, by rw h, λ h, nat.dvd_antisymm ((h _).mpr (dvd_refl _)) ((h _).mp (dvd_refl _))⟩,
end
@[to_additive add_order_of_eq_add_order_of_iff]
lemma order_of_eq_order_of_iff {H : Type*} [monoid H] {y : H} :
order_of x = order_of y ↔ ∀ n : ℕ, x ^ n = 1 ↔ y ^ n = 1 :=
by simp_rw [← is_periodic_pt_mul_iff_pow_eq_one, ← minimal_period_eq_minimal_period_iff, order_of]
lemma add_order_of_injective {B : Type*} [add_monoid B] (f : A →+ B)
(hf : function.injective f) (a : A) : add_order_of (f a) = add_order_of a :=
by simp_rw [add_order_of_eq_add_order_of_iff, ←f.map_nsmul, ←f.map_zero, hf.eq_iff, iff_self,
forall_const]
@[to_additive add_order_of_injective]
lemma order_of_injective {H : Type*} [monoid H] (f : G →* H)
(hf : function.injective f) (x : G) : order_of (f x) = order_of x :=
by simp_rw [order_of_eq_order_of_iff, ←f.map_pow, ←f.map_one, hf.eq_iff, iff_self, forall_const]
@[simp, norm_cast, to_additive] lemma order_of_submonoid {H : submonoid G}
(y : H) : order_of (y : G) = order_of y :=
order_of_injective H.subtype subtype.coe_injective y
variables (x)
lemma order_of_pow' (h : n ≠ 0) :
order_of (x ^ n) = order_of x / gcd (order_of x) n :=
begin
convert minimal_period_iterate_eq_div_gcd h,
simp only [order_of, mul_left_iterate],
end
variables (a)
lemma add_order_of_nsmul' (h : n ≠ 0) :
add_order_of (n • a) = add_order_of a / gcd (add_order_of a) n :=
by simpa [← order_of_of_add_eq_add_order_of, of_add_nsmul] using order_of_pow' _ h
attribute [to_additive add_order_of_nsmul'] order_of_pow'
variable (n)
lemma order_of_pow'' (h : is_of_fin_order x) :
order_of (x ^ n) = order_of x / gcd (order_of x) n :=
begin
convert minimal_period_iterate_eq_div_gcd' h,
simp only [order_of, mul_left_iterate],
end
lemma add_order_of_nsmul'' (h : is_of_fin_add_order a) :
add_order_of (n • a) = add_order_of a / gcd (add_order_of a) n :=
by simp [← order_of_of_add_eq_add_order_of, of_add_nsmul,
order_of_pow'' _ n (is_of_fin_order_of_add_iff.mpr h)]
attribute [to_additive add_order_of_nsmul''] order_of_pow''
section p_prime
variables {a x n} {p : ℕ} [hp : fact p.prime]
include hp
lemma add_order_of_eq_prime (hg : p • a = 0) (hg1 : a ≠ 0) : add_order_of a = p :=
minimal_period_eq_prime ((is_periodic_pt_add_iff_nsmul_eq_zero _).mpr hg)
(by rwa [is_fixed_pt, add_zero])
@[to_additive add_order_of_eq_prime]
lemma order_of_eq_prime (hg : x ^ p = 1) (hg1 : x ≠ 1) : order_of x = p :=
minimal_period_eq_prime ((is_periodic_pt_mul_iff_pow_eq_one _).mpr hg)
(by rwa [is_fixed_pt, mul_one])
lemma add_order_of_eq_prime_pow (hnot : ¬ (p ^ n) • a = 0) (hfin : (p ^ (n + 1)) • a = 0) :
add_order_of a = p ^ (n + 1) :=
begin
apply minimal_period_eq_prime_pow;
rwa is_periodic_pt_add_iff_nsmul_eq_zero,
end
@[to_additive add_order_of_eq_prime_pow]
lemma order_of_eq_prime_pow (hnot : ¬ x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) :
order_of x = p ^ (n + 1) :=
begin
apply minimal_period_eq_prime_pow;
rwa is_periodic_pt_mul_iff_pow_eq_one,
end
omit hp
-- An example on how to determine the order of an element of a finite group.
example : order_of (-1 : units ℤ) = 2 :=
begin
haveI : fact (prime 2) := ⟨prime_two⟩,
exact order_of_eq_prime (int.units_mul_self _) dec_trivial,
end
end p_prime
end monoid_add_monoid
section cancel_monoid
variables [left_cancel_monoid G] (x)
variables [add_left_cancel_monoid A] (a)
lemma pow_injective_aux (h : n ≤ m)
(hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=
by_contradiction $ assume ne : n ≠ m,
have h₁ : m - n > 0, from nat.pos_of_ne_zero (by simp [nat.sub_eq_iff_eq_add h, ne.symm]),
have h₂ : m = n + (m - n) := (nat.add_sub_of_le h).symm,
have h₃ : x ^ (m - n) = 1,
by { rw [h₂, pow_add] at eq, apply mul_left_cancel, convert eq.symm, exact mul_one (x ^ n) },
have le : order_of x ≤ m - n, from order_of_le_of_pow_eq_one h₁ h₃,
have lt : m - n < order_of x,
from (nat.sub_lt_left_iff_lt_add h).mpr $ nat.lt_add_left _ _ _ hm,
lt_irrefl _ (le.trans_lt lt)
-- TODO: This lemma was originally private, but this doesn't seem to work with `to_additive`,
-- therefore the private got removed.
lemma nsmul_injective_aux {n m : ℕ} (h : n ≤ m)
(hm : m < add_order_of a) (eq : n • a = m • a) : n = m :=
begin
apply_fun multiplicative.of_add at eq,
rw [of_add_nsmul, of_add_nsmul] at eq,
rw ← order_of_of_add_eq_add_order_of at hm,
exact pow_injective_aux (multiplicative.of_add a) h hm eq,
end
attribute [to_additive nsmul_injective_aux] pow_injective_aux
lemma nsmul_injective_of_lt_add_order_of {n m : ℕ}
(hn : n < add_order_of a) (hm : m < add_order_of a) (eq : n • a = m • a) : n = m :=
(le_total n m).elim
(assume h, nsmul_injective_aux a h hm eq)
(assume h, (nsmul_injective_aux a h hn eq.symm).symm)
@[to_additive nsmul_injective_of_lt_add_order_of]
lemma pow_injective_of_lt_order_of
(hn : n < order_of x) (hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=
(le_total n m).elim
(assume h, pow_injective_aux x h hm eq)
(assume h, (pow_injective_aux x h hn eq.symm).symm)
end cancel_monoid
section group
variables [group G] [add_group A] {x a} {i : ℤ}
@[to_additive add_order_of_dvd_iff_gsmul_eq_zero]
lemma order_of_dvd_iff_gpow_eq_one : (order_of x : ℤ) ∣ i ↔ x ^ i = 1 :=
begin
rcases int.eq_coe_or_neg i with ⟨i, rfl|rfl⟩,
{ rw [int.coe_nat_dvd, order_of_dvd_iff_pow_eq_one, gpow_coe_nat] },
{ rw [dvd_neg, int.coe_nat_dvd, gpow_neg, inv_eq_one, gpow_coe_nat,
order_of_dvd_iff_pow_eq_one] }
end
@[simp, norm_cast, to_additive] lemma order_of_subgroup {H : subgroup G}
(y: H) : order_of (y : G) = order_of y :=
order_of_injective H.subtype subtype.coe_injective y
lemma gpow_eq_mod_order_of : x ^ i = x ^ (i % order_of x) :=
calc x ^ i = x ^ (i % order_of x + order_of x * (i / order_of x)) :
by rw [int.mod_add_div]
... = x ^ (i % order_of x) :
by simp [gpow_add, gpow_mul, pow_order_of_eq_one]
lemma gsmul_eq_mod_add_order_of : i • a = (i % add_order_of a) • a :=
begin
apply multiplicative.of_add.injective,
simp [of_add_gsmul, gpow_eq_mod_order_of],
end
attribute [to_additive gsmul_eq_mod_add_order_of] gpow_eq_mod_order_of
@[to_additive add_order_of_eq_zero_iff] lemma order_of_eq_zero_iff :
order_of x = 0 ↔ ¬ is_of_fin_order x :=
⟨λ h H, (order_of_pos' H).ne' h, order_of_eq_zero⟩
@[to_additive nsmul_inj_iff_of_add_order_of_eq_zero]
lemma pow_inj_iff_of_order_of_eq_zero (h : order_of x = 0) {n m : ℕ} :
x ^ n = x ^ m ↔ n = m :=
begin
by_cases hx : x = 1,
{ rw [←order_of_eq_one_iff, h] at hx,
contradiction },
rw [order_of_eq_zero_iff, is_of_fin_order_iff_pow_eq_one] at h,
push_neg at h,
induction n with n IH generalizing m,
{ cases m,
{ simp },
{ simpa [eq_comm] using h m.succ m.zero_lt_succ } },
{ cases m,
{ simpa using h n.succ n.zero_lt_succ },
{ simp [pow_succ, IH] } }
end
lemma pow_inj_mod {n m : ℕ} :
x ^ n = x ^ m ↔ n % order_of x = m % order_of x :=
begin
cases (order_of x).zero_le.eq_or_lt with hx hx,
{ simp [pow_inj_iff_of_order_of_eq_zero, hx.symm] },
rw [pow_eq_mod_order_of, @pow_eq_mod_order_of _ _ _ m],
exact ⟨pow_injective_of_lt_order_of _ (nat.mod_lt _ hx) (nat.mod_lt _ hx), λ h, congr_arg _ h⟩
end
lemma nsmul_inj_mod {n m : ℕ} :
n • a = m • a ↔ n % add_order_of a = m % add_order_of a :=
begin
cases (add_order_of a).zero_le.eq_or_lt with hx hx,
{ simp [nsmul_inj_iff_of_add_order_of_eq_zero, hx.symm] },
rw [nsmul_eq_mod_add_order_of, @nsmul_eq_mod_add_order_of _ _ _ m],
refine ⟨nsmul_injective_of_lt_add_order_of a (nat.mod_lt n hx) (nat.mod_lt m hx), λ h, _⟩,
rw h
end
attribute [to_additive nsmul_inj_mod] pow_inj_mod
end group
section fintype
variables [fintype G] [fintype A]
section finite_monoid
variables [monoid G] [add_monoid A]
open_locale big_operators
lemma sum_card_add_order_of_eq_card_nsmul_eq_zero [decidable_eq A] (hn : 0 < n) :
∑ m in (finset.range n.succ).filter (∣ n), (finset.univ.filter (λ a : A, add_order_of a = m)).card
= (finset.univ.filter (λ a : A, n • a = 0)).card :=
calc ∑ m in (finset.range n.succ).filter (∣ n),
(finset.univ.filter (λ a : A, add_order_of a = m)).card
= _ : (finset.card_bUnion (by { intros, apply finset.disjoint_filter.2, cc })).symm
... = _ : congr_arg finset.card (finset.ext (begin
assume a,
suffices : add_order_of a ≤ n ∧ add_order_of a ∣ n ↔ n • a = 0,
{ simpa [nat.lt_succ_iff], },
exact ⟨λ h, let ⟨m, hm⟩ := h.2 in
by rw [hm, mul_comm, mul_nsmul, add_order_of_nsmul_eq_zero, nsmul_zero],
λ h, ⟨add_order_of_le_of_nsmul_eq_zero hn h, add_order_of_dvd_of_nsmul_eq_zero h⟩⟩
end))
@[to_additive sum_card_add_order_of_eq_card_nsmul_eq_zero]
lemma sum_card_order_of_eq_card_pow_eq_one [decidable_eq G] (hn : 0 < n) :
∑ m in (finset.range n.succ).filter (∣ n), (finset.univ.filter (λ x : G, order_of x = m)).card
= (finset.univ.filter (λ x : G, x ^ n = 1)).card :=
calc ∑ m in (finset.range n.succ).filter (∣ n), (finset.univ.filter (λ x : G, order_of x = m)).card
= _ : (finset.card_bUnion (by { intros, apply finset.disjoint_filter.2, cc })).symm
... = _ : congr_arg finset.card (finset.ext (begin
assume x,
suffices : order_of x ≤ n ∧ order_of x ∣ n ↔ x ^ n = 1,
{ simpa [nat.lt_succ_iff], },
exact ⟨λ h, let ⟨m, hm⟩ := h.2 in by rw [hm, pow_mul, pow_order_of_eq_one, one_pow],
λ h, ⟨order_of_le_of_pow_eq_one hn h, order_of_dvd_of_pow_eq_one h⟩⟩
end))
end finite_monoid
section finite_cancel_monoid
-- TODO: Of course everything also works for right_cancel_monoids.
variables [left_cancel_monoid G] [add_left_cancel_monoid A]
-- TODO: Use this to show that a finite left cancellative monoid is a group.
lemma exists_pow_eq_one (x : G) : is_of_fin_order x :=
begin
refine (is_of_fin_order_iff_pow_eq_one _).mpr _,
obtain ⟨i, j, a_eq, ne⟩ : ∃(i j : ℕ), x ^ i = x ^ j ∧ i ≠ j :=
by simpa only [not_forall, exists_prop] using (not_injective_infinite_fintype (λi:ℕ, x^i)),
wlog h'' : j ≤ i,
refine ⟨i - j, nat.sub_pos_of_lt (lt_of_le_of_ne h'' ne.symm), mul_right_injective (x^j) _⟩,
rw [mul_one, ← pow_add, ← a_eq, nat.add_sub_cancel' h''],
end
lemma exists_nsmul_eq_zero (a : A) : is_of_fin_add_order a :=
begin
rcases exists_pow_eq_one (multiplicative.of_add a) with ⟨i, hi1, hi2⟩,
refine ⟨i, hi1, multiplicative.of_add.injective _⟩,
rw [add_left_iterate, of_add_zero, of_add_eq_one, add_zero],
exact (is_periodic_pt_mul_iff_pow_eq_one (multiplicative.of_add a)).mp hi2,
end
attribute [to_additive exists_nsmul_eq_zero] exists_pow_eq_one
lemma add_order_of_le_card_univ : add_order_of a ≤ fintype.card A :=
finset.le_card_of_inj_on_range (• a)
(assume n _, finset.mem_univ _)
(assume i hi j hj, nsmul_injective_of_lt_add_order_of a hi hj)
@[to_additive add_order_of_le_card_univ]
lemma order_of_le_card_univ : order_of x ≤ fintype.card G :=
finset.le_card_of_inj_on_range ((^) x)
(assume n _, finset.mem_univ _)
(assume i hi j hj, pow_injective_of_lt_order_of x hi hj)
/-- This is the same as `add_order_of_pos' but with one fewer explicit assumption since this is
automatic in case of a finite cancellative additive monoid.-/
lemma add_order_of_pos (a : A) : 0 < add_order_of a := add_order_of_pos' (exists_nsmul_eq_zero _)
/-- This is the same as `order_of_pos' but with one fewer explicit assumption since this is
automatic in case of a finite cancellative monoid.-/
@[to_additive add_order_of_pos]
lemma order_of_pos (x : G) : 0 < order_of x := order_of_pos' (exists_pow_eq_one x)
open nat
/-- This is the same as `add_order_of_nsmul'` and `add_order_of_nsmul` but with one assumption less
which is automatic in the case of a finite cancellative additive monoid. -/
lemma add_order_of_nsmul (a : A) :
add_order_of (n • a) = add_order_of a / gcd (add_order_of a) n :=
add_order_of_nsmul'' _ _ (exists_nsmul_eq_zero _)
/-- This is the same as `order_of_pow'` and `order_of_pow''` but with one assumption less which is
automatic in the case of a finite cancellative monoid.-/
@[to_additive add_order_of_nsmul]
lemma order_of_pow (x : G) :
order_of (x ^ n) = order_of x / gcd (order_of x) n := order_of_pow'' _ _ (exists_pow_eq_one _)
lemma mem_multiples_iff_mem_range_add_order_of [decidable_eq A] :
b ∈ add_submonoid.multiples a ↔
b ∈ (finset.range (add_order_of a)).image ((• a) : ℕ → A) :=
finset.mem_range_iff_mem_finset_range_of_mod_eq' (add_order_of_pos a)
(assume i, nsmul_eq_mod_add_order_of.symm)
@[to_additive mem_multiples_iff_mem_range_add_order_of]
lemma mem_powers_iff_mem_range_order_of [decidable_eq G] :
y ∈ submonoid.powers x ↔ y ∈ (finset.range (order_of x)).image ((^) x : ℕ → G) :=
finset.mem_range_iff_mem_finset_range_of_mod_eq' (order_of_pos x)
(assume i, pow_eq_mod_order_of.symm)
noncomputable instance decidable_multiples [decidable_eq A] :
decidable_pred (∈ add_submonoid.multiples a) :=
begin
assume b,
apply decidable_of_iff' (b ∈ (finset.range (add_order_of a)).image (• a)),
exact mem_multiples_iff_mem_range_add_order_of,
end
@[to_additive decidable_multiples]
noncomputable instance decidable_powers [decidable_eq G] :
decidable_pred (∈ submonoid.powers x) :=
begin
assume y,
apply decidable_of_iff'
(y ∈ (finset.range (order_of x)).image ((^) x)),
exact mem_powers_iff_mem_range_order_of
end
/-- The equivalence between `fin (order_of x)` and `submonoid.powers x`, sending `i` to `x ^ i`. -/
noncomputable def fin_equiv_powers (x : G) :
fin (order_of x) ≃ (submonoid.powers x : set G) :=
equiv.of_bijective (λ n, ⟨x ^ ↑n, ⟨n, rfl⟩⟩) ⟨λ ⟨i, hi⟩ ⟨j, hj⟩ ij,
subtype.mk_eq_mk.2 (pow_injective_of_lt_order_of x hi hj (subtype.mk_eq_mk.1 ij)),
λ ⟨_, i, rfl⟩, ⟨⟨i % order_of x, mod_lt i (order_of_pos x)⟩, subtype.eq pow_eq_mod_order_of.symm⟩⟩
/-- The equivalence between `fin (add_order_of a)` and `add_submonoid.multiples a`,
sending `i` to `i • a`."-/
noncomputable def fin_equiv_multiples (a : A) :
fin (add_order_of a) ≃ (add_submonoid.multiples a : set A) :=
fin_equiv_powers (multiplicative.of_add a)
attribute [to_additive fin_equiv_multiples] fin_equiv_powers
@[simp] lemma fin_equiv_powers_apply {x : G} {n : fin (order_of x)} :
fin_equiv_powers x n = ⟨x ^ ↑n, n, rfl⟩ := rfl
@[simp] lemma fin_equiv_multiples_apply {a : A} {n : fin (add_order_of a)} :
fin_equiv_multiples a n = ⟨nsmul ↑n a, n, rfl⟩ := rfl
attribute [to_additive fin_equiv_multiples_apply] fin_equiv_powers_apply
@[simp] lemma fin_equiv_powers_symm_apply (x : G) (n : ℕ)
{hn : ∃ (m : ℕ), x ^ m = x ^ n} :
((fin_equiv_powers x).symm ⟨x ^ n, hn⟩) = ⟨n % order_of x, nat.mod_lt _ (order_of_pos x)⟩ :=
by rw [equiv.symm_apply_eq, fin_equiv_powers_apply, subtype.mk_eq_mk,
pow_eq_mod_order_of, fin.coe_mk]
@[simp] lemma fin_equiv_multiples_symm_apply (a : A) (n : ℕ)
{hn : ∃ (m : ℕ), m • a = n • a} :
((fin_equiv_multiples a).symm ⟨n • a, hn⟩) =
⟨n % add_order_of a, nat.mod_lt _ (add_order_of_pos a)⟩ :=
fin_equiv_powers_symm_apply (multiplicative.of_add a) n
attribute [to_additive fin_equiv_multiples_symm_apply] fin_equiv_powers_symm_apply
/-- The equivalence between `submonoid.powers` of two elements `x, y` of the same order, mapping
`x ^ i` to `y ^ i`. -/
noncomputable def powers_equiv_powers (h : order_of x = order_of y) :
(submonoid.powers x : set G) ≃ (submonoid.powers y : set G) :=
(fin_equiv_powers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_powers y))
/-- The equivalence between `submonoid.multiples` of two elements `a, b` of the same additive order,
mapping `i • a` to `i • b`. -/
noncomputable def multiples_equiv_multiples (h : add_order_of a = add_order_of b) :
(add_submonoid.multiples a : set A) ≃ (add_submonoid.multiples b : set A) :=
(fin_equiv_multiples a).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_multiples b))
attribute [to_additive multiples_equiv_multiples] powers_equiv_powers
@[simp]
lemma powers_equiv_powers_apply (h : order_of x = order_of y)
(n : ℕ) : powers_equiv_powers h ⟨x ^ n, n, rfl⟩ = ⟨y ^ n, n, rfl⟩ :=
begin
rw [powers_equiv_powers, equiv.trans_apply, equiv.trans_apply,
fin_equiv_powers_symm_apply, ← equiv.eq_symm_apply, fin_equiv_powers_symm_apply],
simp [h]
end
@[simp]
lemma multiples_equiv_multiples_apply (h : add_order_of a = add_order_of b)
(n : ℕ) : multiples_equiv_multiples h ⟨n • a, n, rfl⟩ = ⟨n • b, n, rfl⟩ :=
powers_equiv_powers_apply h n
attribute [to_additive multiples_equiv_multiples_apply] powers_equiv_powers_apply
lemma order_eq_card_powers [decidable_eq G] :
order_of x = fintype.card (submonoid.powers x : set G) :=
(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 ⟨fin_equiv_powers x⟩)
lemma add_order_of_eq_card_multiples [decidable_eq A] :
add_order_of a = fintype.card (add_submonoid.multiples a : set A) :=
(fintype.card_fin (add_order_of a)).symm.trans (fintype.card_eq.2 ⟨fin_equiv_multiples a⟩)
attribute [to_additive add_order_of_eq_card_multiples] order_eq_card_powers
end finite_cancel_monoid
section finite_group
variables [group G] [add_group A]
lemma exists_gpow_eq_one (x : G) : ∃ (i : ℤ) (H : i ≠ 0), x ^ (i : ℤ) = 1 :=
--lemma exists_gpow_eq_one (a : α) : ∃ (i : ℤ) (H : i ≠ 0), a ^ (i : ℤ) = 1 :=
begin
rcases exists_pow_eq_one x with ⟨w, hw1, hw2⟩,
refine ⟨w, int.coe_nat_ne_zero.mpr (ne_of_gt hw1), _⟩,
rw gpow_coe_nat,
exact (is_periodic_pt_mul_iff_pow_eq_one _).mp hw2,
end
lemma exists_gsmul_eq_zero (a : A) : ∃ (i : ℤ) (H : i ≠ 0), i • a = 0 :=
@exists_gpow_eq_one (multiplicative A) _ _ a
attribute [to_additive] exists_gpow_eq_one
lemma mem_multiples_iff_mem_gmultiples :
b ∈ add_submonoid.multiples a ↔ b ∈ add_subgroup.gmultiples a :=
⟨λ ⟨n, hn⟩, ⟨n, by simp * at *⟩, λ ⟨i, hi⟩, ⟨(i % add_order_of a).nat_abs,
by { simp only [nsmul_eq_smul] at hi ⊢,
rwa [← gsmul_coe_nat,
int.nat_abs_of_nonneg (int.mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2
(add_order_of_pos a))), ← gsmul_eq_mod_add_order_of] } ⟩⟩
open subgroup
@[to_additive mem_multiples_iff_mem_gmultiples]
lemma mem_powers_iff_mem_gpowers : y ∈ submonoid.powers x ↔ y ∈ gpowers x :=
⟨λ ⟨n, hn⟩, ⟨n, by simp * at *⟩,
λ ⟨i, hi⟩, ⟨(i % order_of x).nat_abs,
by rwa [← gpow_coe_nat, int.nat_abs_of_nonneg (int.mod_nonneg _
(int.coe_nat_ne_zero_iff_pos.2 (order_of_pos x))),
← gpow_eq_mod_order_of]⟩⟩
lemma multiples_eq_gmultiples (a : A) :
(add_submonoid.multiples a : set A) = add_subgroup.gmultiples a :=
set.ext $ λ y, mem_multiples_iff_mem_gmultiples
@[to_additive multiples_eq_gmultiples]
lemma powers_eq_gpowers (x : G) : (submonoid.powers x : set G) = gpowers x :=
set.ext $ λ x, mem_powers_iff_mem_gpowers
lemma mem_gmultiples_iff_mem_range_add_order_of [decidable_eq A] :
b ∈ add_subgroup.gmultiples a ↔ b ∈ (finset.range (add_order_of a)).image (• a) :=
by rw [← mem_multiples_iff_mem_gmultiples, mem_multiples_iff_mem_range_add_order_of]
@[to_additive mem_gmultiples_iff_mem_range_add_order_of]
lemma mem_gpowers_iff_mem_range_order_of [decidable_eq G] :
y ∈ subgroup.gpowers x ↔ y ∈ (finset.range (order_of x)).image ((^) x : ℕ → G) :=
by rw [← mem_powers_iff_mem_gpowers, mem_powers_iff_mem_range_order_of]
noncomputable instance decidable_gmultiples [decidable_eq A] :
decidable_pred (∈ add_subgroup.gmultiples a) :=
begin
simp_rw ←set_like.mem_coe,
rw ← multiples_eq_gmultiples,
exact decidable_multiples,
end
@[to_additive decidable_gmultiples]
noncomputable instance decidable_gpowers [decidable_eq G] :
decidable_pred (∈ subgroup.gpowers x) :=
begin
simp_rw ←set_like.mem_coe,
rw ← powers_eq_gpowers,
exact decidable_powers,
end
/-- The equivalence between `fin (order_of x)` and `subgroup.gpowers x`, sending `i` to `x ^ i`. -/
noncomputable def fin_equiv_gpowers (x : G) :
fin (order_of x) ≃ (subgroup.gpowers x : set G) :=
(fin_equiv_powers x).trans (equiv.set.of_eq (powers_eq_gpowers x))
/-- The equivalence between `fin (add_order_of a)` and `subgroup.gmultiples a`,
sending `i` to `i • a`. -/
noncomputable def fin_equiv_gmultiples (a : A) :
fin (add_order_of a) ≃ (add_subgroup.gmultiples a : set A) :=
fin_equiv_gpowers (multiplicative.of_add a)
attribute [to_additive fin_equiv_gmultiples] fin_equiv_gpowers
@[simp] lemma fin_equiv_gpowers_apply {n : fin (order_of x)} :
fin_equiv_gpowers x n = ⟨x ^ (n : ℕ), n, gpow_coe_nat x n⟩ := rfl
@[simp] lemma fin_equiv_gmultiples_apply {n : fin (add_order_of a)} :
fin_equiv_gmultiples a n = ⟨(n : ℕ) • a, n, gsmul_coe_nat a n⟩ :=
fin_equiv_gpowers_apply
attribute [to_additive fin_equiv_gmultiples_apply] fin_equiv_gpowers_apply
@[simp] lemma fin_equiv_gpowers_symm_apply (x : G) (n : ℕ)
{hn : ∃ (m : ℤ), x ^ m = x ^ n} :
((fin_equiv_gpowers x).symm ⟨x ^ n, hn⟩) = ⟨n % order_of x, nat.mod_lt _ (order_of_pos x)⟩ :=
by { rw [fin_equiv_gpowers, equiv.symm_trans_apply, equiv.set.of_eq_symm_apply],
exact fin_equiv_powers_symm_apply x n }
@[simp] lemma fin_equiv_gmultiples_symm_apply (a : A) (n : ℕ)
{hn : ∃ (m : ℤ), m • a = n • a} :
((fin_equiv_gmultiples a).symm ⟨n • a, hn⟩) =
⟨n % add_order_of a, nat.mod_lt _ (add_order_of_pos a)⟩ :=
fin_equiv_gpowers_symm_apply (multiplicative.of_add a) n
attribute [to_additive fin_equiv_gmultiples_symm_apply] fin_equiv_gpowers_symm_apply
/-- The equivalence between `subgroup.gpowers` of two elements `x, y` of the same order, mapping
`x ^ i` to `y ^ i`. -/
noncomputable def gpowers_equiv_gpowers (h : order_of x = order_of y) :
(subgroup.gpowers x : set G) ≃ (subgroup.gpowers y : set G) :=
(fin_equiv_gpowers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_gpowers y))
/-- The equivalence between `subgroup.gmultiples` of two elements `a, b` of the same additive order,
mapping `i • a` to `i • b`. -/
noncomputable def gmultiples_equiv_gmultiples (h : add_order_of a = add_order_of b) :
(add_subgroup.gmultiples a : set A) ≃ (add_subgroup.gmultiples b : set A) :=
(fin_equiv_gmultiples a).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_gmultiples b))
attribute [to_additive gmultiples_equiv_gmultiples] gpowers_equiv_gpowers
@[simp]
lemma gpowers_equiv_gpowers_apply (h : order_of x = order_of y)
(n : ℕ) : gpowers_equiv_gpowers h ⟨x ^ n, n, gpow_coe_nat x n⟩ = ⟨y ^ n, n, gpow_coe_nat y n⟩ :=
begin
rw [gpowers_equiv_gpowers, equiv.trans_apply, equiv.trans_apply,
fin_equiv_gpowers_symm_apply, ← equiv.eq_symm_apply, fin_equiv_gpowers_symm_apply],
simp [h]
end
@[simp]
lemma gmultiples_equiv_gmultiples_apply (h : add_order_of a = add_order_of b) (n : ℕ) :
gmultiples_equiv_gmultiples h ⟨n • a, n, gsmul_coe_nat a n⟩ = ⟨n • b, n, gsmul_coe_nat b n⟩ :=
gpowers_equiv_gpowers_apply h n
attribute [to_additive gmultiples_equiv_gmultiples_apply] gpowers_equiv_gpowers_apply
lemma order_eq_card_gpowers [decidable_eq G] :
order_of x = fintype.card (subgroup.gpowers x : set G) :=
(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 ⟨fin_equiv_gpowers x⟩)
lemma add_order_eq_card_gmultiples [decidable_eq A] :
add_order_of a = fintype.card (add_subgroup.gmultiples a : set A) :=
(fintype.card_fin (add_order_of a)).symm.trans (fintype.card_eq.2 ⟨fin_equiv_gmultiples a⟩)
attribute [to_additive add_order_eq_card_gmultiples] order_eq_card_gpowers
open quotient_group
/- TODO: use cardinal theory, introduce `card : set G → ℕ`, or setup decidability for cosets -/
lemma order_of_dvd_card_univ : order_of x ∣ fintype.card G :=
begin
classical,
have ft_prod : fintype (quotient (gpowers x) × (gpowers x)),
from fintype.of_equiv G group_equiv_quotient_times_subgroup,
have ft_s : fintype (gpowers x),
from @fintype.prod_right _ _ _ ft_prod _,
have ft_cosets : fintype (quotient (gpowers x)),
from @fintype.prod_left _ _ _ ft_prod ⟨⟨1, (gpowers x).one_mem⟩⟩,
have eq₁ : fintype.card G = @fintype.card _ ft_cosets * @fintype.card _ ft_s,
from calc fintype.card G = @fintype.card _ ft_prod :
@fintype.card_congr _ _ _ ft_prod group_equiv_quotient_times_subgroup
... = @fintype.card _ (@prod.fintype _ _ ft_cosets ft_s) :
congr_arg (@fintype.card _) $ subsingleton.elim _ _
... = @fintype.card _ ft_cosets * @fintype.card _ ft_s :
@fintype.card_prod _ _ ft_cosets ft_s,
have eq₂ : order_of x = @fintype.card _ ft_s,
from calc order_of x = _ : order_eq_card_gpowers
... = _ : congr_arg (@fintype.card _) $ subsingleton.elim _ _,
exact dvd.intro (@fintype.card (quotient (subgroup.gpowers x)) ft_cosets)
(by rw [eq₁, eq₂, mul_comm])
end
lemma add_order_of_dvd_card_univ : add_order_of a ∣ fintype.card A :=
begin
rw ← order_of_of_add_eq_add_order_of,
exact order_of_dvd_card_univ,
end
attribute [to_additive add_order_of_dvd_card_univ] order_of_dvd_card_univ
@[simp] lemma pow_card_eq_one : x ^ fintype.card G = 1 :=
let ⟨m, hm⟩ := @order_of_dvd_card_univ _ x _ _ in
by simp [hm, pow_mul, pow_order_of_eq_one]
@[simp] lemma card_nsmul_eq_zero {a : A} : fintype.card A • a = 0 :=
begin
apply multiplicative.of_add.injective,
rw [of_add_nsmul, of_add_zero],
exact pow_card_eq_one,
end
@[to_additive nsmul_eq_mod_card] lemma pow_eq_mod_card (n : ℕ) :
x ^ n = x ^ (n % fintype.card G) :=
by rw [pow_eq_mod_order_of, ←nat.mod_mod_of_dvd n order_of_dvd_card_univ,
← pow_eq_mod_order_of]
@[to_additive] lemma gpow_eq_mod_card (n : ℤ) :
x ^ n = x ^ (n % fintype.card G) :=
by by rw [gpow_eq_mod_order_of, ← int.mod_mod_of_dvd n (int.coe_nat_dvd.2 order_of_dvd_card_univ),
← gpow_eq_mod_order_of]
attribute [to_additive card_nsmul_eq_zero] pow_card_eq_one
/-- If `gcd(|G|,n)=1` then the `n`th power map is a bijection -/
@[simps] def pow_coprime (h : nat.coprime (fintype.card G) n) : G ≃ G :=
{ to_fun := λ g, g ^ n,
inv_fun := λ g, g ^ (nat.gcd_b (fintype.card G) n),
left_inv := λ g, by
{ have key : g ^ _ = g ^ _ := congr_arg (λ n : ℤ, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),
rwa [gpow_add, gpow_mul, gpow_mul, gpow_coe_nat, gpow_coe_nat, gpow_coe_nat,
h.gcd_eq_one, pow_one, pow_card_eq_one, one_gpow, one_mul, eq_comm] at key },
right_inv := λ g, by
{ have key : g ^ _ = g ^ _ := congr_arg (λ n : ℤ, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),
rwa [gpow_add, gpow_mul, gpow_mul', gpow_coe_nat, gpow_coe_nat, gpow_coe_nat,
h.gcd_eq_one, pow_one, pow_card_eq_one, one_gpow, one_mul, eq_comm] at key } }
@[simp] lemma pow_coprime_one (h : nat.coprime (fintype.card G) n) : pow_coprime h 1 = 1 :=
one_pow n
@[simp] lemma pow_coprime_inv (h : nat.coprime (fintype.card G) n) {g : G} :
pow_coprime h g⁻¹ = (pow_coprime h g)⁻¹ :=
inv_pow g n
lemma inf_eq_bot_of_coprime {G : Type*} [group G] {H K : subgroup G} [fintype H] [fintype K]
(h : nat.coprime (fintype.card H) (fintype.card K)) : H ⊓ K = ⊥ :=
begin
refine (H ⊓ K).eq_bot_iff_forall.mpr (λ x hx, _),
rw [←order_of_eq_one_iff, ←nat.dvd_one, ←h.gcd_eq_one, nat.dvd_gcd_iff],
exact ⟨(congr_arg (∣ fintype.card H) (order_of_subgroup ⟨x, hx.1⟩)).mpr order_of_dvd_card_univ,
(congr_arg (∣ fintype.card K) (order_of_subgroup ⟨x, hx.2⟩)).mpr order_of_dvd_card_univ⟩,
end
variable (a)
lemma image_range_add_order_of [decidable_eq A] :
finset.image (λ i, i • a) (finset.range (add_order_of a)) =
(add_subgroup.gmultiples a : set A).to_finset :=
by {ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_gmultiples_iff_mem_range_add_order_of] }
/-- TODO: Generalise to `submonoid.powers`.-/
@[to_additive image_range_add_order_of]
lemma image_range_order_of [decidable_eq G] :
finset.image (λ i, x ^ i) (finset.range (order_of x)) = (gpowers x : set G).to_finset :=
by { ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_gpowers_iff_mem_range_order_of] }
lemma gcd_nsmul_card_eq_zero_iff : n • a = 0 ↔ (gcd n (fintype.card A)) • a = 0 :=
⟨λ h, gcd_nsmul_eq_zero _ h $ card_nsmul_eq_zero,
λ h, let ⟨m, hm⟩ := gcd_dvd_left n (fintype.card A) in
by rw [hm, mul_comm, mul_nsmul, h, nsmul_zero]⟩
/-- TODO: Generalise to `finite_cancel_monoid`. -/
@[to_additive gcd_nsmul_card_eq_zero_iff]
lemma pow_gcd_card_eq_one_iff : x ^ n = 1 ↔ x ^ (gcd n (fintype.card G)) = 1 :=
⟨λ h, pow_gcd_eq_one _ h $ pow_card_eq_one,
λ h, let ⟨m, hm⟩ := gcd_dvd_left n (fintype.card G) in
by rw [hm, pow_mul, h, one_pow]⟩
end finite_group
end fintype
section pow_is_subgroup
/-- A nonempty idempotent subset of a finite cancellative monoid is a submonoid -/
def submonoid_of_idempotent {M : Type*} [left_cancel_monoid M] [fintype M] (S : set M)
(hS1 : S.nonempty) (hS2 : S * S = S) : submonoid M :=
have pow_mem : ∀ a : M, a ∈ S → ∀ n : ℕ, a ^ (n + 1) ∈ S :=
λ a ha, nat.rec (by rwa [zero_add, pow_one])
(λ n ih, (congr_arg2 (∈) (pow_succ a (n + 1)).symm hS2).mp (set.mul_mem_mul ha ih)),
{ carrier := S,
one_mem' := by {
obtain ⟨a, ha⟩ := hS1,
rw [←pow_order_of_eq_one a, ←nat.sub_add_cancel (order_of_pos a)],
exact pow_mem a ha (order_of a - 1) },
mul_mem' := λ a b ha hb, (congr_arg2 (∈) rfl hS2).mp (set.mul_mem_mul ha hb) }
/-- A nonempty idempotent subset of a finite group is a subgroup -/
def subgroup_of_idempotent {G : Type*} [group G] [fintype G] (S : set G)
(hS1 : S.nonempty) (hS2 : S * S = S) : subgroup G :=
{ carrier := S,
inv_mem' := λ a ha, by {
rw [←one_mul a⁻¹, ←pow_one a, ←pow_order_of_eq_one a, ←pow_sub a (order_of_pos a)],
exact (submonoid_of_idempotent S hS1 hS2).pow_mem ha (order_of a - 1) },
.. submonoid_of_idempotent S hS1 hS2 }
/-- If `S` is a nonempty subset of a finite group `G`, then `S ^ |G|` is a subgroup -/
def pow_card_subgroup {G : Type*} [group G] [fintype G] (S : set G) (hS : S.nonempty) :
subgroup G :=
have one_mem : (1 : G) ∈ (S ^ fintype.card G) := by
{ obtain ⟨a, ha⟩ := hS,
rw ← pow_card_eq_one,
exact set.pow_mem_pow ha (fintype.card G) },
subgroup_of_idempotent (S ^ (fintype.card G)) ⟨1, one_mem⟩ begin
classical,
refine (set.eq_of_subset_of_card_le
(λ b hb, (congr_arg (∈ _) (one_mul b)).mp (set.mul_mem_mul one_mem hb)) (ge_of_eq _)).symm,
change _ = fintype.card (_ * _ : set G),
rw [←pow_add, group.card_pow_eq_card_pow_card_univ S (fintype.card G) le_rfl,
group.card_pow_eq_card_pow_card_univ S (fintype.card G + fintype.card G) le_add_self],
end
end pow_is_subgroup
|
29f858b9f1dfd6a2b5a6d298efb111a2b102220a | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/Lean3Lib/all.lean | 82b039ff78a318d6b9d33ca67795f174f42ddf87 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,367 | lean | import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.Lean3Lib.data.buffer
import Mathlib.Lean3Lib.data.buffer.parser
import Mathlib.Lean3Lib.data.dlist
import Mathlib.Lean3Lib.data.lazy_list
import Mathlib.Lean3Lib.data.rbmap.default
import Mathlib.Lean3Lib.data.rbtree.basic
import Mathlib.Lean3Lib.data.rbtree.default
import Mathlib.Lean3Lib.data.rbtree.find
import Mathlib.Lean3Lib.data.rbtree.insert
import Mathlib.Lean3Lib.data.rbtree.main
import Mathlib.Lean3Lib.data.rbtree.min_max
import Mathlib.Lean3Lib.data.stream
import Mathlib.Lean3Lib.data.vector
import Mathlib.Lean3Lib.init.algebra.classes
import Mathlib.Lean3Lib.init.algebra.default
import Mathlib.Lean3Lib.init.algebra.functions
import Mathlib.Lean3Lib.init.algebra.order
import Mathlib.Lean3Lib.init.cc_lemmas
import Mathlib.Lean3Lib.init.classical
import Mathlib.Lean3Lib.init.coe
import Mathlib.Lean3Lib.init.control.alternative
import Mathlib.Lean3Lib.init.control.applicative
import Mathlib.Lean3Lib.init.control.combinators
import Mathlib.Lean3Lib.init.control.default
import Mathlib.Lean3Lib.init.control.except
import Mathlib.Lean3Lib.init.control.functor
import Mathlib.Lean3Lib.init.control.id
import Mathlib.Lean3Lib.init.control.lawful
import Mathlib.Lean3Lib.init.control.lift
import Mathlib.Lean3Lib.init.control.monad
import Mathlib.Lean3Lib.init.control.monad_fail
import Mathlib.Lean3Lib.init.control.option
import Mathlib.Lean3Lib.init.control.reader
import Mathlib.Lean3Lib.init.control.state
import Mathlib.Lean3Lib.init.core
import Mathlib.Lean3Lib.init.data.array.basic
import Mathlib.Lean3Lib.init.data.array.default
import Mathlib.Lean3Lib.init.data.array.slice
import Mathlib.Lean3Lib.init.data.basic
import Mathlib.Lean3Lib.init.data.bool.basic
import Mathlib.Lean3Lib.init.data.bool.default
import Mathlib.Lean3Lib.init.data.bool.lemmas
import Mathlib.Lean3Lib.init.data.char.basic
import Mathlib.Lean3Lib.init.data.char.classes
import Mathlib.Lean3Lib.init.data.char.default
import Mathlib.Lean3Lib.init.data.char.lemmas
import Mathlib.Lean3Lib.init.data.default
import Mathlib.Lean3Lib.init.data.fin.basic
import Mathlib.Lean3Lib.init.data.fin.default
import Mathlib.Lean3Lib.init.data.fin.ops
import Mathlib.Lean3Lib.init.data.int.basic
import Mathlib.Lean3Lib.init.data.int.bitwise
import Mathlib.Lean3Lib.init.data.int.comp_lemmas
import Mathlib.Lean3Lib.init.data.int.default
import Mathlib.Lean3Lib.init.data.int.order
import Mathlib.Lean3Lib.init.data.list.basic
import Mathlib.Lean3Lib.init.data.list.default
import Mathlib.Lean3Lib.init.data.list.instances
import Mathlib.Lean3Lib.init.data.list.lemmas
import Mathlib.Lean3Lib.init.data.list.qsort
import Mathlib.Lean3Lib.init.data.nat.basic
import Mathlib.Lean3Lib.init.data.nat.bitwise
import Mathlib.Lean3Lib.init.data.nat.default
import Mathlib.Lean3Lib.init.data.nat.div
import Mathlib.Lean3Lib.init.data.nat.gcd
import Mathlib.Lean3Lib.init.data.nat.lemmas
import Mathlib.Lean3Lib.init.data.option.basic
import Mathlib.Lean3Lib.init.data.option.instances
import Mathlib.Lean3Lib.init.data.ordering.basic
import Mathlib.Lean3Lib.init.data.ordering.default
import Mathlib.Lean3Lib.init.data.ordering.lemmas
import Mathlib.Lean3Lib.init.data.prod
import Mathlib.Lean3Lib.init.data.punit
import Mathlib.Lean3Lib.init.data.quot
import Mathlib.Lean3Lib.init.data.rbmap.basic
import Mathlib.Lean3Lib.init.data.rbmap.default
import Mathlib.Lean3Lib.init.data.rbtree.basic
import Mathlib.Lean3Lib.init.data.rbtree.default
import Mathlib.Lean3Lib.init.data.repr
import Mathlib.Lean3Lib.init.data.set
import Mathlib.Lean3Lib.init.data.setoid
import Mathlib.Lean3Lib.init.data.sigma.basic
import Mathlib.Lean3Lib.init.data.sigma.default
import Mathlib.Lean3Lib.init.data.sigma.lex
import Mathlib.Lean3Lib.init.data.string.basic
import Mathlib.Lean3Lib.init.data.string.default
import Mathlib.Lean3Lib.init.data.string.ops
import Mathlib.Lean3Lib.init.data.subtype.basic
import Mathlib.Lean3Lib.init.data.subtype.default
import Mathlib.Lean3Lib.init.data.subtype.instances
import Mathlib.Lean3Lib.init.data.sum.basic
import Mathlib.Lean3Lib.init.data.sum.default
import Mathlib.Lean3Lib.init.data.sum.instances
import Mathlib.Lean3Lib.init.data.to_string
import Mathlib.Lean3Lib.init.data.unsigned.basic
import Mathlib.Lean3Lib.init.data.unsigned.default
import Mathlib.Lean3Lib.init.data.unsigned.ops
import Mathlib.Lean3Lib.init.default
import Mathlib.Lean3Lib.init.function
import Mathlib.Lean3Lib.init.funext
import Mathlib.Lean3Lib.init.ite_simp
import Mathlib.Lean3Lib.init.logic
import Mathlib.Lean3Lib.init.meta.ac_tactics
import Mathlib.Lean3Lib.init.meta.async_tactic
import Mathlib.Lean3Lib.init.meta.attribute
import Mathlib.Lean3Lib.init.meta.backward
import Mathlib.Lean3Lib.init.meta.case_tag
import Mathlib.Lean3Lib.init.meta.comp_value_tactics
import Mathlib.Lean3Lib.init.meta.congr_lemma
import Mathlib.Lean3Lib.init.meta.congr_tactic
import Mathlib.Lean3Lib.init.meta.constructor_tactic
import Mathlib.Lean3Lib.init.meta.contradiction_tactic
import Mathlib.Lean3Lib.init.meta.converter.conv
import Mathlib.Lean3Lib.init.meta.converter.default
import Mathlib.Lean3Lib.init.meta.converter.interactive
import Mathlib.Lean3Lib.init.meta.declaration
import Mathlib.Lean3Lib.init.meta.decl_cmds
import Mathlib.Lean3Lib.init.meta.default
import Mathlib.Lean3Lib.init.meta.derive
import Mathlib.Lean3Lib.init.meta.environment
import Mathlib.Lean3Lib.init.meta.exceptional
import Mathlib.Lean3Lib.init.meta.expr
import Mathlib.Lean3Lib.init.meta.expr_address
import Mathlib.Lean3Lib.init.meta.float
import Mathlib.Lean3Lib.init.meta.format
import Mathlib.Lean3Lib.init.meta.fun_info
import Mathlib.Lean3Lib.init.meta.has_reflect
import Mathlib.Lean3Lib.init.meta.hole_command
import Mathlib.Lean3Lib.init.meta.injection_tactic
import Mathlib.Lean3Lib.init.meta.interaction_monad
import Mathlib.Lean3Lib.init.meta.interactive
import Mathlib.Lean3Lib.init.meta.interactive_base
import Mathlib.Lean3Lib.init.meta.json
import Mathlib.Lean3Lib.init.meta.lean.parser
import Mathlib.Lean3Lib.init.meta.level
import Mathlib.Lean3Lib.init.meta.local_context
import Mathlib.Lean3Lib.init.meta.match_tactic
import Mathlib.Lean3Lib.init.meta.mk_dec_eq_instance
import Mathlib.Lean3Lib.init.meta.mk_has_reflect_instance
import Mathlib.Lean3Lib.init.meta.mk_has_sizeof_instance
import Mathlib.Lean3Lib.init.meta.mk_inhabited_instance
import Mathlib.Lean3Lib.init.meta.module_info
import Mathlib.Lean3Lib.init.meta.name
import Mathlib.Lean3Lib.init.meta.occurrences
import Mathlib.Lean3Lib.init.meta.options
import Mathlib.Lean3Lib.init.meta.pexpr
import Mathlib.Lean3Lib.init.meta.rb_map
import Mathlib.Lean3Lib.init.meta.rec_util
import Mathlib.Lean3Lib.init.meta.ref
import Mathlib.Lean3Lib.init.meta.relation_tactics
import Mathlib.Lean3Lib.init.meta.rewrite_tactic
import Mathlib.Lean3Lib.init.meta.set_get_option_tactics
import Mathlib.Lean3Lib.init.meta.simp_tactic
import Mathlib.Lean3Lib.init.meta.smt.congruence_closure
import Mathlib.Lean3Lib.init.meta.smt.default
import Mathlib.Lean3Lib.init.meta.smt.ematch
import Mathlib.Lean3Lib.init.meta.smt.interactive
import Mathlib.Lean3Lib.init.meta.smt.rsimp
import Mathlib.Lean3Lib.init.meta.smt.smt_tactic
import Mathlib.Lean3Lib.init.meta.tactic
import Mathlib.Lean3Lib.init.meta.tagged_format
import Mathlib.Lean3Lib.init.meta.task
import Mathlib.Lean3Lib.init.meta.type_context
import Mathlib.Lean3Lib.init.meta.vm
import Mathlib.Lean3Lib.init.meta.well_founded_tactics
import Mathlib.Lean3Lib.init.meta.widget.basic
import Mathlib.Lean3Lib.init.meta.widget.default
import Mathlib.Lean3Lib.init.meta.widget.html_cmd
import Mathlib.Lean3Lib.init.meta.widget.interactive_expr
import Mathlib.Lean3Lib.init.meta.widget.replace_save_info
import Mathlib.Lean3Lib.init.meta.widget.tactic_component
import Mathlib.Lean3Lib.init.propext
import Mathlib.Lean3Lib.init.util
import Mathlib.Lean3Lib.init.version
import Mathlib.Lean3Lib.init.wf
import Mathlib.Lean3Lib.smt.arith
import Mathlib.Lean3Lib.smt.array
import Mathlib.Lean3Lib.smt.default
import Mathlib.Lean3Lib.smt.prove
import Mathlib.Lean3Lib.system.io
import Mathlib.Lean3Lib.system.io_interface
import Mathlib.Lean3Lib.system.random
import Mathlib.Lean3Lib.tools.debugger.cli
import Mathlib.Lean3Lib.tools.debugger.default
import Mathlib.Lean3Lib.tools.debugger.util
namespace Mathlib
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.