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
223c08e555526824b61aa8ceec2844a35d426db1
b19a1b7dc79c802247fdce4c04708e070863b4d2
/existential-quantifier.lean
2505da50527e79355fcab62d8dd3d82eec14de12
[]
no_license
utanapishtim/promethazine
99a1e80311fb20251a54ba78a534b23852b88c40
08a6f9bd6dd08feb3df8d4697e19ffc8d333b249
refs/heads/master
1,653,595,504,487
1,480,129,933,000
1,480,129,933,000
74,801,596
0
0
null
null
null
null
UTF-8
Lean
false
false
2,060
lean
/- 1. exists x : A, p x 2. ∃ x : A, p x 3. Exists (λ x : A, p x) (1-3) are all equivalent. -/ import data.nat open nat algebra example : ∃ x : ℕ , x > 0 := have H : 1 > 0, from succ_pos 0, exists.intro 1 H example (x : ℕ ) (H : x > 0) : ∃ y, y < x := exists.intro 0 H example (x y z : ℕ ) (Hxy : x < y) (Hyz : y < z) : ∃ w, x < w ∧ w < z := exists.intro y (and.intro Hxy Hyz) check @exists.intro section variable g : ℕ → ℕ → ℕ variable Hg : g 0 0 = 0 theorem gex1 : ∃ x, g x x = x := exists.intro 0 Hg theorem gex2 : ∃ x, g x 0 = x := exists.intro 0 Hg theorem gex3 : ∃ x, g 0 0 = x := exists.intro 0 Hg theorem gex4 : ∃ x, g x x = 0 := exists.intro 0 Hg set_option pp.implicit true -- display implict args check gex1 check gex2 check gex3 check gex4 end section definition is_even (a : nat) := ∃ b, a = 2 * b theorem even_plus_even {a b : nat} (H1 : is_even a) (H2 : is_even b) : is_even (a + b) := exists.elim H1 (λ (w1 : nat) (Hw1 : a = 2 * w1), exists.elim H2 (λ (w2 : nat) (Hw2 : b = 2 * w2), exists.intro (w1 + w2) (calc a + b = 2 * w1 + b : Hw1 ... = 2 * w1 + 2 * w2 : Hw2 ... = 2 * (w1 + w2) : left_distrib))) end section definition is_even (a : ℕ ) := ∃ b, a = 2 * b theorem even_plus_even {a b : ℕ } (H1 : is_even a) (H2 : is_even b) : is_even (a + b) := obtain (w1 : ℕ ) (Hw1 : a = 2 * w1), from H1, obtain (w2 : ℕ ) (Hw2 : b = 2 * w2), from H2, exists.intro (w1 + w2) (calc a + b = 2 * w1 + b : Hw1 ... = 2 * w1 + 2 * w2 : Hw2 ... = 2 * (w1 + w2) : left_distrib end open classical section variables (A : Type) (p : A → Prop) example (H : ¬ ∀ x, ¬ p x) : ∃ x, p x := by_contradiction (assume H1 : ¬ ∃ x, p x, have H2 : ∀ x, ¬ p x, from take x, assume H3 : p x, have H4 : ∃ x, p x, from exists.intro x H3, show false, from H1 H4, show false, from H H2) end
07d74ab1c5d2942fbc83cc8a7668d8e3b4cecf5a
2fbe653e4bc441efde5e5d250566e65538709888
/src/topology/metric_space/baire.lean
3d3b0ec15303fc91bc17efbfdd4640fd24bc865b
[ "Apache-2.0" ]
permissive
aceg00/mathlib
5e15e79a8af87ff7eb8c17e2629c442ef24e746b
8786ea6d6d46d6969ac9a869eb818bf100802882
refs/heads/master
1,649,202,698,930
1,580,924,783,000
1,580,924,783,000
149,197,272
0
0
Apache-2.0
1,537,224,208,000
1,537,224,207,000
null
UTF-8
Lean
false
false
15,214
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.metric_space.basic analysis.specific_limits /-! # Baire theorem In a complete metric space, a countable intersection of dense open subsets is dense. The good concept underlying the theorem is that of a Gδ set, i.e., a countable intersection of open sets. Then Baire theorem can also be formulated as the fact that a countable intersection of dense Gδ sets is a dense Gδ set. We prove Baire theorem, giving several different formulations that can be handy. We also prove the important consequence that, if the space is covered by a countable union of closed sets, then the union of their interiors is dense. The names of the theorems do not contain the string "Baire", but are instead built from the form of the statement. "Baire" is however in the docstring of all the theorems, to facilitate grep searches. -/ noncomputable theory open_locale classical open filter lattice encodable set variables {α : Type*} {β : Type*} {γ : Type*} section is_Gδ variable [topological_space α] /-- A Gδ set is a countable intersection of open sets. -/ def is_Gδ (s : set α) : Prop := ∃T : set (set α), (∀t ∈ T, is_open t) ∧ countable T ∧ s = (⋂₀ T) /-- An open set is a Gδ set. -/ lemma is_open.is_Gδ {s : set α} (h : is_open s) : is_Gδ s := ⟨{s}, by simp [h], countable_singleton _, (set.sInter_singleton _).symm⟩ lemma is_Gδ_bInter_of_open {ι : Type*} {I : set ι} (hI : countable I) {f : ι → set α} (hf : ∀i ∈ I, is_open (f i)) : is_Gδ (⋂i∈I, f i) := ⟨f '' I, by rwa ball_image_iff, countable_image _ hI, by rw sInter_image⟩ lemma is_Gδ_Inter_of_open {ι : Type*} [encodable ι] {f : ι → set α} (hf : ∀i, is_open (f i)) : is_Gδ (⋂i, f i) := ⟨range f, by rwa forall_range_iff, countable_range _, by rw sInter_range⟩ /-- A countable intersection of Gδ sets is a Gδ set. -/ lemma is_Gδ_sInter {S : set (set α)} (h : ∀s∈S, is_Gδ s) (hS : countable S) : is_Gδ (⋂₀ S) := begin have : ∀s : set α, ∃T : set (set α), s ∈ S → ((∀t ∈ T, is_open t) ∧ countable T ∧ s = (⋂₀ T)), { assume s, by_cases hs : s ∈ S, { simp [hs], exact h s hs }, { simp [hs] }}, choose T hT using this, refine ⟨⋃s∈S, T s, λt ht, _, _, _⟩, { simp only [exists_prop, set.mem_Union] at ht, rcases ht with ⟨s, hs, tTs⟩, exact (hT s hs).1 t tTs }, { exact countable_bUnion hS (λs hs, (hT s hs).2.1) }, { exact (sInter_bUnion (λs hs, (hT s hs).2.2)).symm } end /-- The union of two Gδ sets is a Gδ set. -/ lemma is_Gδ.union {s t : set α} (hs : is_Gδ s) (ht : is_Gδ t) : is_Gδ (s ∪ t) := begin rcases hs with ⟨S, Sopen, Scount, sS⟩, rcases ht with ⟨T, Topen, Tcount, tT⟩, rw [sS, tT, sInter_union_sInter], apply is_Gδ_bInter_of_open (countable_prod Scount Tcount), rintros ⟨a, b⟩ hab, simp only [set.prod_mk_mem_set_prod_eq] at hab, have aopen : is_open a := Sopen a hab.1, have bopen : is_open b := Topen b hab.2, simp [aopen, bopen, is_open_union] end end is_Gδ section Baire_theorem open metric variables [metric_space α] [complete_space α] /-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here when the source space is ℕ (and subsumed below by `dense_Inter_of_open` working with any encodable source space). -/ theorem dense_Inter_of_open_nat {f : ℕ → set α} (ho : ∀n, is_open (f n)) (hd : ∀n, closure (f n) = univ) : closure (⋂n, f n) = univ := begin let B : ℕ → ℝ := λn, ((1/2)^n : ℝ), have Bpos : ∀n, 0 < B n := λn, begin apply pow_pos, by norm_num end, /- Translate the density assumption into two functions `center` and `radius` associating to any n, x, δ, δpos a center and a positive radius such that `closed_ball center radius` is included both in `f n` and in `closed_ball x δ`. We can also require `radius ≤ (1/2)^(n+1), to ensure we get a Cauchy sequence later. -/ have : ∀n x δ, ∃y r, δ > 0 → (r > 0 ∧ r ≤ B (n+1) ∧ closed_ball y r ⊆ (closed_ball x δ) ∩ f n), { assume n x δ, by_cases δpos : δ > 0, { have : x ∈ closure (f n) := by simpa only [(hd n).symm] using mem_univ x, rcases mem_closure_iff'.1 this (δ/2) (half_pos δpos) with ⟨y, ys, xy⟩, rw dist_comm at xy, rcases is_open_iff.1 (ho n) y ys with ⟨r, rpos, hr⟩, refine ⟨y, min (min (δ/2) (r/2)) (B (n+1)), λ_, ⟨_, _, λz hz, ⟨_, _⟩⟩⟩, show 0 < min (min (δ / 2) (r/2)) (B (n+1)), from lt_min (lt_min (half_pos δpos) (half_pos rpos)) (Bpos (n+1)), show min (min (δ / 2) (r/2)) (B (n+1)) ≤ B (n+1), from min_le_right _ _, show z ∈ closed_ball x δ, from calc dist z x ≤ dist z y + dist y x : dist_triangle _ _ _ ... ≤ (min (min (δ / 2) (r/2)) (B (n+1))) + (δ/2) : add_le_add hz (le_of_lt xy) ... ≤ δ/2 + δ/2 : add_le_add (le_trans (min_le_left _ _) (min_le_left _ _)) (le_refl _) ... = δ : add_halves _, show z ∈ f n, from hr (calc dist z y ≤ min (min (δ / 2) (r/2)) (B (n+1)) : hz ... ≤ r/2 : le_trans (min_le_left _ _) (min_le_right _ _) ... < r : half_lt_self rpos) }, { use [x, 0] }}, choose center radius H using this, refine subset.antisymm (subset_univ _) (λx hx, _), refine metric.mem_closure_iff'.2 (λε εpos, _), /- ε is positive. We have to find a point in the ball of radius ε around x belonging to all `f n`. For this, we construct inductively a sequence `F n = (c n, r n)` such that the closed ball `closed_ball (c n) (r n)` is included in the previous ball and in `f n`, and such that `r n` is small enough to ensure that `c n` is a Cauchy sequence. Then `c n` converges to a limit which belongs to all the `f n`. -/ let F : ℕ → (α × ℝ) := λn, nat.rec_on n (prod.mk x (min (ε/2) 1)) (λn p, prod.mk (center n p.1 p.2) (radius n p.1 p.2)), let c : ℕ → α := λn, (F n).1, let r : ℕ → ℝ := λn, (F n).2, have rpos : ∀n, r n > 0, { assume n, induction n with n hn, exact lt_min (half_pos εpos) (zero_lt_one), exact (H n (c n) (r n) hn).1 }, have rB : ∀n, r n ≤ B n, { assume n, induction n with n hn, exact min_le_right _ _, exact (H n (c n) (r n) (rpos n)).2.1 }, have incl : ∀n, closed_ball (c (n+1)) (r (n+1)) ⊆ (closed_ball (c n) (r n)) ∩ (f n) := λn, (H n (c n) (r n) (rpos n)).2.2, have cdist : ∀n, dist (c n) (c (n+1)) ≤ B n, { assume n, rw dist_comm, have A : c (n+1) ∈ closed_ball (c (n+1)) (r (n+1)) := mem_closed_ball_self (le_of_lt (rpos (n+1))), have I := calc closed_ball (c (n+1)) (r (n+1)) ⊆ closed_ball (c n) (r n) : subset.trans (incl n) (inter_subset_left _ _) ... ⊆ closed_ball (c n) (B n) : closed_ball_subset_closed_ball (rB n), exact I A }, have : cauchy_seq c, { refine cauchy_seq_of_le_geometric (1/2) 1 (by norm_num) (λn, _), rw one_mul, exact cdist n }, -- as the sequence `c n` is Cauchy in a complete space, it converges to a limit `y`. rcases cauchy_seq_tendsto_of_complete this with ⟨y, ylim⟩, -- this point `y` will be the desired point. We will check that it belongs to all -- `f n` and to `ball x ε`. use y, simp only [exists_prop, set.mem_Inter], have I : ∀n, ∀m ≥ n, closed_ball (c m) (r m) ⊆ closed_ball (c n) (r n), { assume n, refine nat.le_induction _ (λm hnm h, _), { exact subset.refl _ }, { exact subset.trans (incl m) (subset.trans (inter_subset_left _ _) h) }}, have yball : ∀n, y ∈ closed_ball (c n) (r n), { assume n, refine mem_of_closed_of_tendsto (by simp) ylim is_closed_ball _, simp only [filter.mem_at_top_sets, nonempty_of_inhabited, set.mem_preimage], exact ⟨n, λm hm, I n m hm (mem_closed_ball_self (le_of_lt (rpos m)))⟩ }, split, show ∀n, y ∈ f n, { assume n, have : closed_ball (c (n+1)) (r (n+1)) ⊆ f n := subset.trans (incl n) (inter_subset_right _ _), exact this (yball (n+1)) }, show dist x y < ε, from calc dist x y = dist y x : dist_comm _ _ ... ≤ r 0 : yball 0 ... < ε : lt_of_le_of_lt (min_le_left _ _) (half_lt_self εpos) end /-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with ⋂₀. -/ theorem dense_sInter_of_open {S : set (set α)} (ho : ∀s∈S, is_open s) (hS : countable S) (hd : ∀s∈S, closure s = univ) : closure (⋂₀S) = univ := begin cases S.eq_empty_or_nonempty with h h, { simp [h] }, { rcases exists_surjective_of_countable h hS with ⟨f, hf⟩, have F : ∀n, f n ∈ S := λn, by rw hf; exact mem_range_self _, rw [hf, sInter_range], exact dense_Inter_of_open_nat (λn, ho _ (F n)) (λn, hd _ (F n)) } end /-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with an index set which is a countable set in any type. -/ theorem dense_bInter_of_open {S : set β} {f : β → set α} (ho : ∀s∈S, is_open (f s)) (hS : countable S) (hd : ∀s∈S, closure (f s) = univ) : closure (⋂s∈S, f s) = univ := begin rw ← sInter_image, apply dense_sInter_of_open, { rwa ball_image_iff }, { exact countable_image _ hS }, { rwa ball_image_iff } end /-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with an index set which is an encodable type. -/ theorem dense_Inter_of_open [encodable β] {f : β → set α} (ho : ∀s, is_open (f s)) (hd : ∀s, closure (f s) = univ) : closure (⋂s, f s) = univ := begin rw ← sInter_range, apply dense_sInter_of_open, { rwa forall_range_iff }, { exact countable_range _ }, { rwa forall_range_iff } end /-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with ⋂₀. -/ theorem dense_sInter_of_Gδ {S : set (set α)} (ho : ∀s∈S, is_Gδ s) (hS : countable S) (hd : ∀s∈S, closure s = univ) : closure (⋂₀S) = univ := begin -- the result follows from the result for a countable intersection of dense open sets, -- by rewriting each set as a countable intersection of open sets, which are of course dense. have : ∀s : set α, ∃T : set (set α), s ∈ S → ((∀t ∈ T, is_open t) ∧ countable T ∧ s = (⋂₀ T)), { assume s, by_cases hs : s ∈ S, { simp [hs], exact ho s hs }, { simp [hs] }}, choose T hT using this, have : ⋂₀ S = ⋂₀ (⋃s∈S, T s) := (sInter_bUnion (λs hs, (hT s hs).2.2)).symm, rw this, refine dense_sInter_of_open (λt ht, _) (countable_bUnion hS (λs hs, (hT s hs).2.1)) (λt ht, _), show is_open t, { simp only [exists_prop, set.mem_Union] at ht, rcases ht with ⟨s, hs, tTs⟩, exact (hT s hs).1 t tTs }, show closure t = univ, { simp only [exists_prop, set.mem_Union] at ht, rcases ht with ⟨s, hs, tTs⟩, apply subset.antisymm (subset_univ _), rw ← (hd s hs), apply closure_mono, have := sInter_subset_of_mem tTs, rwa ← (hT s hs).2.2 at this } end /-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with an index set which is a countable set in any type. -/ theorem dense_bInter_of_Gδ {S : set β} {f : β → set α} (ho : ∀s∈S, is_Gδ (f s)) (hS : countable S) (hd : ∀s∈S, closure (f s) = univ) : closure (⋂s∈S, f s) = univ := begin rw ← sInter_image, apply dense_sInter_of_Gδ, { rwa ball_image_iff }, { exact countable_image _ hS }, { rwa ball_image_iff } end /-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with an index set which is an encodable type. -/ theorem dense_Inter_of_Gδ [encodable β] {f : β → set α} (ho : ∀s, is_Gδ (f s)) (hd : ∀s, closure (f s) = univ) : closure (⋂s, f s) = univ := begin rw ← sInter_range, apply dense_sInter_of_Gδ, { rwa forall_range_iff }, { exact countable_range _ }, { rwa forall_range_iff } end /-- Baire theorem: if countably many closed sets cover the whole space, then their interiors are dense. Formulated here with an index set which is a countable set in any type. -/ theorem dense_bUnion_interior_of_closed {S : set β} {f : β → set α} (hc : ∀s∈S, is_closed (f s)) (hS : countable S) (hU : (⋃s∈S, f s) = univ) : closure (⋃s∈S, interior (f s)) = univ := begin let g := λs, - (frontier (f s)), have clos_g : closure (⋂s∈S, g s) = univ, { refine dense_bInter_of_open (λs hs, _) hS (λs hs, _), show is_open (g s), from is_open_compl_iff.2 is_closed_frontier, show closure (g s) = univ, { apply subset.antisymm (subset_univ _), simp [g, interior_frontier (hc s hs)] }}, have : (⋂s∈S, g s) ⊆ (⋃s∈S, interior (f s)), { assume x hx, have : x ∈ ⋃s∈S, f s, { have := mem_univ x, rwa ← hU at this }, rcases mem_bUnion_iff.1 this with ⟨s, hs, xs⟩, have : x ∈ g s := mem_bInter_iff.1 hx s hs, have : x ∈ interior (f s), { have : x ∈ f s \ (frontier (f s)) := mem_inter xs this, simpa [frontier, xs, closure_eq_of_is_closed (hc s hs)] using this }, exact mem_bUnion_iff.2 ⟨s, ⟨hs, this⟩⟩ }, have := closure_mono this, rw clos_g at this, exact subset.antisymm (subset_univ _) this end /-- Baire theorem: if countably many closed sets cover the whole space, then their interiors are dense. Formulated here with ⋃₀. -/ theorem dense_sUnion_interior_of_closed {S : set (set α)} (hc : ∀s∈S, is_closed s) (hS : countable S) (hU : (⋃₀ S) = univ) : closure (⋃s∈S, interior s) = univ := by rw sUnion_eq_bUnion at hU; exact dense_bUnion_interior_of_closed hc hS hU /-- Baire theorem: if countably many closed sets cover the whole space, then their interiors are dense. Formulated here with an index set which is an encodable type. -/ theorem dense_Union_interior_of_closed [encodable β] {f : β → set α} (hc : ∀s, is_closed (f s)) (hU : (⋃s, f s) = univ) : closure (⋃s, interior (f s)) = univ := begin rw ← bUnion_univ, apply dense_bUnion_interior_of_closed, { simp [hc] }, { apply countable_encodable }, { rwa ← bUnion_univ at hU } end /-- One of the most useful consequences of Baire theorem: if a countable union of closed sets covers the space, then one of the sets has nonempty interior. -/ theorem nonempty_interior_of_Union_of_closed [nonempty α] [encodable β] {f : β → set α} (hc : ∀s, is_closed (f s)) (hU : (⋃s, f s) = univ) : ∃s x ε, ε > 0 ∧ ball x ε ⊆ f s := begin have : ∃s, (interior (f s)).nonempty, { by_contradiction h, simp only [not_exists, not_nonempty_iff_eq_empty] at h, have := calc ∅ = closure (⋃s, interior (f s)) : by simp [h] ... = univ : dense_Union_interior_of_closed hc hU, exact univ_nonempty.ne_empty this.symm }, rcases this with ⟨s, hs⟩, rcases hs with ⟨x, hx⟩, rcases mem_nhds_iff.1 (mem_interior_iff_mem_nhds.1 hx) with ⟨ε, εpos, hε⟩, exact ⟨s, x, ε, εpos, hε⟩, end end Baire_theorem
c17a46a88d69813746c2fc8ab6ec407e4c155833
1dd482be3f611941db7801003235dc84147ec60a
/test/tidy.lean
221e1f07299ed1dfa3350390a4bc32b1599da056
[ "Apache-2.0" ]
permissive
sanderdahmen/mathlib
479039302bd66434bb5672c2a4cecf8d69981458
8f0eae75cd2d8b7a083cf935666fcce4565df076
refs/heads/master
1,587,491,322,775
1,549,672,060,000
1,549,672,060,000
169,748,224
0
0
Apache-2.0
1,549,636,694,000
1,549,636,694,000
null
UTF-8
Lean
false
false
1,154
lean
-- Copyright (c) 2018 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Scott Morrison import tactic.tidy open tactic namespace tidy.test meta def interactive_simp := `[simp] def tidy_test_0 : ∀ x : unit, x = unit.star := begin success_if_fail { chain [ interactive_simp ] }, intro1, induction x, refl end def tidy_test_1 (a : string): ∀ x : unit, x = unit.star := begin tidy -- intros x, exact dec_trivial end structure A := (z : ℕ) structure B := (a : A) (aa : a.z = 0) structure C := (a : A) (b : B) (ab : a.z = b.a.z) structure D := (a : B) (b : C) (ab : a.a.z = b.a.z) open tactic def d : D := begin tidy, -- /- obviously says -/ fsplit, work_on_goal 0 { fsplit, work_on_goal 0 { fsplit }, work_on_goal 1 { refl } }, work_on_goal 0 { fsplit, work_on_goal 0 { fsplit }, work_on_goal 1 { fsplit, work_on_goal 0 { fsplit }, work_on_goal 1 { refl } }, work_on_goal 1 { refl } }, refl end. def f : unit → unit → unit := by tidy -- intros a a_1, cases a_1, cases a, fsplit def g (P Q : Prop) (p : P) (h : P ↔ Q) : Q := by tidy end tidy.test
8931490d1f3c019ca370090cf5b46d98ac0923f7
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/yury_coe_sort_bug.lean
7d106c6a7fbd724112ba71dc3994e1dedcb18348
[ "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
146
lean
universe u instance {α : Type u} : has_coe_to_sort (set α) (Type u) := ⟨λ s, {x // x ∈ s}⟩ example : ↥({0} : set ℕ) := ⟨0, rfl⟩
9f2720a0a222d9743897a7519724bee602be08a0
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/algebra/char_p/basic_auto.lean
ccd7d02fce3a2cb7b3a8886ed2d91f4823776433
[]
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
12,567
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Kenny Lau, Joey van Langen, Casper Putz -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.fintype.basic import Mathlib.data.nat.choose.default import Mathlib.data.int.modeq import Mathlib.algebra.module.basic import Mathlib.algebra.iterate_hom import Mathlib.group_theory.order_of_element import Mathlib.algebra.group.type_tags import Mathlib.PostPort universes u l u_1 u_2 v namespace Mathlib /-! # Characteristic of semirings -/ /-- The generator of the kernel of the unique homomorphism ℕ → α for a semiring α -/ class char_p (α : Type u) [semiring α] (p : ℕ) where cast_eq_zero_iff : ∀ (x : ℕ), ↑x = 0 ↔ p ∣ x theorem char_p.cast_eq_zero (α : Type u) [semiring α] (p : ℕ) [char_p α p] : ↑p = 0 := iff.mpr (char_p.cast_eq_zero_iff α p p) (dvd_refl p) @[simp] theorem char_p.cast_card_eq_zero (R : Type u_1) [ring R] [fintype R] : ↑(fintype.card R) = 0 := sorry theorem char_p.int_cast_eq_zero_iff (R : Type u) [ring R] (p : ℕ) [char_p R p] (a : ℤ) : ↑a = 0 ↔ ↑p ∣ a := sorry theorem char_p.int_coe_eq_int_coe_iff (R : Type u_1) [ring R] (p : ℕ) [char_p R p] (a : ℤ) (b : ℤ) : ↑a = ↑b ↔ int.modeq (↑p) a b := sorry theorem char_p.eq (α : Type u) [semiring α] {p : ℕ} {q : ℕ} (c1 : char_p α p) (c2 : char_p α q) : p = q := nat.dvd_antisymm (iff.mp (char_p.cast_eq_zero_iff α p q) (char_p.cast_eq_zero α q)) (iff.mp (char_p.cast_eq_zero_iff α q p) (char_p.cast_eq_zero α p)) protected instance char_p.of_char_zero (α : Type u) [semiring α] [char_zero α] : char_p α 0 := char_p.mk fun (x : ℕ) => eq.mpr (id (Eq._oldrec (Eq.refl (↑x = 0 ↔ 0 ∣ x)) (propext zero_dvd_iff))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑x = 0 ↔ x = 0)) (Eq.symm nat.cast_zero))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑x = ↑0 ↔ x = 0)) (propext nat.cast_inj))) (iff.refl (x = 0)))) theorem char_p.exists (α : Type u) [semiring α] : ∃ (p : ℕ), char_p α p := sorry theorem char_p.exists_unique (α : Type u) [semiring α] : exists_unique fun (p : ℕ) => char_p α p := sorry theorem char_p.congr {R : Type u} [semiring R] {p : ℕ} (q : ℕ) [hq : char_p R q] (h : q = p) : char_p R p := h ▸ hq /-- Noncomputable function that outputs the unique characteristic of a semiring. -/ def ring_char (α : Type u) [semiring α] : ℕ := classical.some (char_p.exists_unique α) namespace ring_char theorem spec (R : Type u) [semiring R] (x : ℕ) : ↑x = 0 ↔ ring_char R ∣ x := sorry theorem eq (R : Type u) [semiring R] {p : ℕ} (C : char_p R p) : p = ring_char R := and.right (classical.some_spec (char_p.exists_unique R)) p C protected instance char_p (R : Type u) [semiring R] : char_p R (ring_char R) := char_p.mk (spec R) theorem of_eq {R : Type u} [semiring R] {p : ℕ} (h : ring_char R = p) : char_p R p := char_p.congr (ring_char R) h theorem eq_iff {R : Type u} [semiring R] {p : ℕ} : ring_char R = p ↔ char_p R p := { mp := of_eq, mpr := Eq.symm ∘ eq R } theorem dvd {R : Type u} [semiring R] {x : ℕ} (hx : ↑x = 0) : ring_char R ∣ x := iff.mp (spec R x) hx end ring_char theorem add_pow_char_of_commute (R : Type u) [semiring R] {p : ℕ} [fact (nat.prime p)] [char_p R p] (x : R) (y : R) (h : commute x y) : (x + y) ^ p = x ^ p + y ^ p := sorry theorem add_pow_char_pow_of_commute (R : Type u) [semiring R] {p : ℕ} [fact (nat.prime p)] [char_p R p] {n : ℕ} (x : R) (y : R) (h : commute x y) : (x + y) ^ p ^ n = x ^ p ^ n + y ^ p ^ n := sorry theorem sub_pow_char_of_commute (R : Type u) [ring R] {p : ℕ} [fact (nat.prime p)] [char_p R p] (x : R) (y : R) (h : commute x y) : (x - y) ^ p = x ^ p - y ^ p := sorry theorem sub_pow_char_pow_of_commute (R : Type u) [ring R] {p : ℕ} [fact (nat.prime p)] [char_p R p] {n : ℕ} (x : R) (y : R) (h : commute x y) : (x - y) ^ p ^ n = x ^ p ^ n - y ^ p ^ n := sorry theorem add_pow_char (α : Type u) [comm_semiring α] {p : ℕ} [fact (nat.prime p)] [char_p α p] (x : α) (y : α) : (x + y) ^ p = x ^ p + y ^ p := add_pow_char_of_commute α x y (commute.all x y) theorem add_pow_char_pow (R : Type u) [comm_semiring R] {p : ℕ} [fact (nat.prime p)] [char_p R p] {n : ℕ} (x : R) (y : R) : (x + y) ^ p ^ n = x ^ p ^ n + y ^ p ^ n := add_pow_char_pow_of_commute R x y (commute.all x y) theorem sub_pow_char (α : Type u) [comm_ring α] {p : ℕ} [fact (nat.prime p)] [char_p α p] (x : α) (y : α) : (x - y) ^ p = x ^ p - y ^ p := sub_pow_char_of_commute α x y (commute.all x y) theorem sub_pow_char_pow (R : Type u) [comm_ring R] {p : ℕ} [fact (nat.prime p)] [char_p R p] {n : ℕ} (x : R) (y : R) : (x - y) ^ p ^ n = x ^ p ^ n - y ^ p ^ n := sub_pow_char_pow_of_commute R x y (commute.all x y) theorem eq_iff_modeq_int (R : Type u_1) [ring R] (p : ℕ) [char_p R p] (a : ℤ) (b : ℤ) : ↑a = ↑b ↔ int.modeq (↑p) a b := sorry theorem char_p.neg_one_ne_one (R : Type u_1) [ring R] (p : ℕ) [char_p R p] [fact (bit0 1 < p)] : -1 ≠ 1 := sorry theorem ring_hom.char_p_iff_char_p {K : Type u_1} {L : Type u_2} [field K] [field L] (f : K →+* L) (p : ℕ) : char_p K p ↔ char_p L p := sorry /-- The frobenius map that sends x to x^p -/ def frobenius (R : Type u) [comm_semiring R] (p : ℕ) [fact (nat.prime p)] [char_p R p] : R →+* R := ring_hom.mk (fun (x : R) => x ^ p) sorry sorry sorry (add_pow_char R) theorem frobenius_def {R : Type u} [comm_semiring R] (p : ℕ) [fact (nat.prime p)] [char_p R p] (x : R) : coe_fn (frobenius R p) x = x ^ p := rfl theorem iterate_frobenius {R : Type u} [comm_semiring R] (p : ℕ) [fact (nat.prime p)] [char_p R p] (x : R) (n : ℕ) : nat.iterate (⇑(frobenius R p)) n x = x ^ p ^ n := sorry theorem frobenius_mul {R : Type u} [comm_semiring R] (p : ℕ) [fact (nat.prime p)] [char_p R p] (x : R) (y : R) : coe_fn (frobenius R p) (x * y) = coe_fn (frobenius R p) x * coe_fn (frobenius R p) y := ring_hom.map_mul (frobenius R p) x y theorem frobenius_one {R : Type u} [comm_semiring R] (p : ℕ) [fact (nat.prime p)] [char_p R p] : coe_fn (frobenius R p) 1 = 1 := one_pow p theorem monoid_hom.map_frobenius {R : Type u} [comm_semiring R] {S : Type v} [comm_semiring S] (f : R →* S) (p : ℕ) [fact (nat.prime p)] [char_p R p] [char_p S p] (x : R) : coe_fn f (coe_fn (frobenius R p) x) = coe_fn (frobenius S p) (coe_fn f x) := monoid_hom.map_pow f x p theorem ring_hom.map_frobenius {R : Type u} [comm_semiring R] {S : Type v} [comm_semiring S] (g : R →+* S) (p : ℕ) [fact (nat.prime p)] [char_p R p] [char_p S p] (x : R) : coe_fn g (coe_fn (frobenius R p) x) = coe_fn (frobenius S p) (coe_fn g x) := ring_hom.map_pow g x p theorem monoid_hom.map_iterate_frobenius {R : Type u} [comm_semiring R] {S : Type v} [comm_semiring S] (f : R →* S) (p : ℕ) [fact (nat.prime p)] [char_p R p] [char_p S p] (x : R) (n : ℕ) : coe_fn f (nat.iterate (⇑(frobenius R p)) n x) = nat.iterate (⇑(frobenius S p)) n (coe_fn f x) := function.semiconj.iterate_right (monoid_hom.map_frobenius f p) n x theorem ring_hom.map_iterate_frobenius {R : Type u} [comm_semiring R] {S : Type v} [comm_semiring S] (g : R →+* S) (p : ℕ) [fact (nat.prime p)] [char_p R p] [char_p S p] (x : R) (n : ℕ) : coe_fn g (nat.iterate (⇑(frobenius R p)) n x) = nat.iterate (⇑(frobenius S p)) n (coe_fn g x) := monoid_hom.map_iterate_frobenius (ring_hom.to_monoid_hom g) p x n theorem monoid_hom.iterate_map_frobenius {R : Type u} [comm_semiring R] (x : R) (f : R →* R) (p : ℕ) [fact (nat.prime p)] [char_p R p] (n : ℕ) : nat.iterate (⇑f) n (coe_fn (frobenius R p) x) = coe_fn (frobenius R p) (nat.iterate (⇑f) n x) := monoid_hom.iterate_map_pow f x n p theorem ring_hom.iterate_map_frobenius {R : Type u} [comm_semiring R] (x : R) (f : R →+* R) (p : ℕ) [fact (nat.prime p)] [char_p R p] (n : ℕ) : nat.iterate (⇑f) n (coe_fn (frobenius R p) x) = coe_fn (frobenius R p) (nat.iterate (⇑f) n x) := ring_hom.iterate_map_pow f x n p theorem frobenius_zero (R : Type u) [comm_semiring R] (p : ℕ) [fact (nat.prime p)] [char_p R p] : coe_fn (frobenius R p) 0 = 0 := ring_hom.map_zero (frobenius R p) theorem frobenius_add (R : Type u) [comm_semiring R] (p : ℕ) [fact (nat.prime p)] [char_p R p] (x : R) (y : R) : coe_fn (frobenius R p) (x + y) = coe_fn (frobenius R p) x + coe_fn (frobenius R p) y := ring_hom.map_add (frobenius R p) x y theorem frobenius_nat_cast (R : Type u) [comm_semiring R] (p : ℕ) [fact (nat.prime p)] [char_p R p] (n : ℕ) : coe_fn (frobenius R p) ↑n = ↑n := ring_hom.map_nat_cast (frobenius R p) n theorem frobenius_neg (R : Type u) [comm_ring R] (p : ℕ) [fact (nat.prime p)] [char_p R p] (x : R) : coe_fn (frobenius R p) (-x) = -coe_fn (frobenius R p) x := ring_hom.map_neg (frobenius R p) x theorem frobenius_sub (R : Type u) [comm_ring R] (p : ℕ) [fact (nat.prime p)] [char_p R p] (x : R) (y : R) : coe_fn (frobenius R p) (x - y) = coe_fn (frobenius R p) x - coe_fn (frobenius R p) y := ring_hom.map_sub (frobenius R p) x y theorem frobenius_inj (α : Type u) [comm_ring α] [no_zero_divisors α] (p : ℕ) [fact (nat.prime p)] [char_p α p] : function.injective ⇑(frobenius α p) := sorry namespace char_p theorem char_p_to_char_zero (α : Type u) [ring α] [char_p α 0] : char_zero α := char_zero_of_inj_zero fun (n : ℕ) (h0 : ↑n = 0) => eq_zero_of_zero_dvd (iff.mp (cast_eq_zero_iff α 0 n) h0) theorem cast_eq_mod (α : Type u) [ring α] (p : ℕ) [char_p α p] (k : ℕ) : ↑k = ↑(k % p) := sorry theorem char_ne_zero_of_fintype (α : Type u) [ring α] (p : ℕ) [hc : char_p α p] [fintype α] : p ≠ 0 := fun (h : p = 0) => (fun (this : char_zero α) => absurd nat.cast_injective (not_injective_infinite_fintype coe)) (char_p_to_char_zero α) theorem char_ne_one (α : Type u) [integral_domain α] (p : ℕ) [hc : char_p α p] : p ≠ 1 := sorry theorem char_is_prime_of_two_le (α : Type u) [integral_domain α] (p : ℕ) [hc : char_p α p] (hp : bit0 1 ≤ p) : nat.prime p := sorry theorem char_is_prime_or_zero (α : Type u) [integral_domain α] (p : ℕ) [hc : char_p α p] : nat.prime p ∨ p = 0 := sorry theorem char_is_prime_of_pos (α : Type u) [integral_domain α] (p : ℕ) [h : fact (0 < p)] [char_p α p] : fact (nat.prime p) := or.resolve_right (char_is_prime_or_zero α p) (iff.mp pos_iff_ne_zero h) theorem char_is_prime (α : Type u) [integral_domain α] [fintype α] (p : ℕ) [char_p α p] : nat.prime p := or.resolve_right (char_is_prime_or_zero α p) (char_ne_zero_of_fintype α p) protected instance subsingleton {R : Type u_1} [semiring R] [char_p R 1] : subsingleton R := subsingleton.intro ((fun (this : ∀ (r : R), r = 0) (a b : R) => (fun (this : a = b) => this) (eq.mpr (id (Eq._oldrec (Eq.refl (a = b)) (this a))) (eq.mpr (id (Eq._oldrec (Eq.refl (0 = b)) (this b))) (Eq.refl 0)))) fun (r : R) => Eq.trans (Eq.trans (Eq.trans (eq.mpr (id (Eq._oldrec (Eq.refl (r = 1 * r)) (one_mul r))) (Eq.refl r)) (eq.mpr (id (Eq._oldrec (Eq.refl (1 * r = ↑1 * r)) nat.cast_one)) (Eq.refl (1 * r)))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑1 * r = 0 * r)) (cast_eq_zero R 1))) (Eq.refl (0 * r)))) (eq.mpr (id (Eq._oldrec (Eq.refl (0 * r = 0)) (zero_mul r))) (Eq.refl 0))) theorem false_of_nontrivial_of_char_one {R : Type u_1} [semiring R] [nontrivial R] [char_p R 1] : False := false_of_nontrivial_of_subsingleton R theorem ring_char_ne_one {R : Type u_1} [semiring R] [nontrivial R] : ring_char R ≠ 1 := sorry theorem nontrivial_of_char_ne_one {v : ℕ} (hv : v ≠ 1) {R : Type u_1} [semiring R] [hr : char_p R v] : nontrivial R := sorry end char_p theorem char_p_of_ne_zero (n : ℕ) (R : Type u_1) [comm_ring R] [fintype R] (hn : fintype.card R = n) (hR : ∀ (i : ℕ), i < n → ↑i = 0 → i = 0) : char_p R n := sorry theorem char_p_of_prime_pow_injective (R : Type u_1) [comm_ring R] [fintype R] (p : ℕ) [hp : fact (nat.prime p)] (n : ℕ) (hn : fintype.card R = p ^ n) (hR : ∀ (i : ℕ), i ≤ n → ↑p ^ i = 0 → i = n) : char_p R (p ^ n) := sorry end Mathlib
3dfb2cabe1cb004287e12b438b016e4fffc26a52
e151e9053bfd6d71740066474fc500a087837323
/src/hott/init/path0.lean
bcef1451fcdc14e4d50afb1b08e7f77d717efcf7
[ "Apache-2.0" ]
permissive
daniel-carranza/hott3
15bac2d90589dbb952ef15e74b2837722491963d
913811e8a1371d3a5751d7d32ff9dec8aa6815d9
refs/heads/master
1,610,091,349,670
1,596,222,336,000
1,596,222,336,000
241,957,822
0
0
Apache-2.0
1,582,222,839,000
1,582,222,838,000
null
UTF-8
Lean
false
false
533
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Jakob von Raumer, Floris van Doorn Ported from Coq HoTT -/ import .meta.support universes u v w hott_theory namespace hott open function /- Path equality -/ inductive eq {A : Type u} (a : A) : A → Type u | refl : eq a hott_theory_cmd "open hott.eq" hott_theory_cmd "local infix ` = ` := hott.eq" @[hott, reducible] def rfl {A : Type u} {a : A} := eq.refl a end hott
1d17552e3e367547cb79ba908ab00ca6bee76f1a
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/tests/compiler/closure_bug6.lean
b06232e3b0b84f3beeeb30fdd4a63d77e7448737
[ "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
511
lean
def f (x : Nat) : Nat × (Nat → String) := let x1 := x + 1; let x2 := x + 2; let x3 := x + 3; let x4 := x + 4; let x5 := x + 5; let x6 := x + 6; let x7 := x + 7; let x8 := x + 8; let x9 := x + 9; let x10 := x + 10; let x11 := x + 11; let x12 := x + 12; let x13 := x + 13; let x14 := x + 14; let x15 := x + 15; let x16 := x + 16; let x17 := x + 17; (x, fun y => toString [x1, x2, x3, x4, x5, x6, x7, x8]) def main (xs : List String) : IO Unit := IO.println ((f (xs.headD "0").toNat!).2 (xs.headD "0").toNat!)
487f60d61b155b8049af3dd125af0e66af5c8f36
ce6917c5bacabee346655160b74a307b4a5ab620
/src/ch5/ex0710.lean
7ba25056d3c9f1fa73be0938f65ff4de9e8a4436
[]
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
232
lean
example (u w x y z : ℕ) (h₁ : x = y + z) (h₂ : w = u + x) : w = z + y + u := 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.
abc23c94f05a34ad129ed90af5df1905ad311a3c
fcf3ffa92a3847189ca669cb18b34ef6b2ec2859
/src/world5/level9.lean
64b4cf44ffe7c64b253304327e3334c3187eb782
[ "Apache-2.0" ]
permissive
nomoid/lean-proofs
4a80a97888699dee42b092b7b959b22d9aa0c066
b9f03a24623d1a1d111d6c2bbf53c617e2596d6a
refs/heads/master
1,674,955,317,080
1,607,475,706,000
1,607,475,706,000
314,104,281
0
0
null
null
null
null
UTF-8
Lean
false
false
421
lean
example (A B C D E F G H I J K L : Type) (f1 : A → B) (f2 : B → E) (f3 : E → D) (f4 : D → A) (f5 : E → F) (f6 : F → C) (f7 : B → C) (f8 : F → G) (f9 : G → J) (f10 : I → J) (f11 : J → I) (f12 : I → H) (f13 : E → H) (f14 : H → K) (f15 : I → L) : A → L := begin intro a, apply f15, apply f11, apply f9, apply f8, apply f5, apply f2, apply f1, exact a, end
05bcad6a1bb76cceae02ac04dae0111339e4b8ef
43390109ab88557e6090f3245c47479c123ee500
/src/Euclid_old/tarski_2.lean
029912439375e647d1b5e74273a98889237ea242
[ "Apache-2.0" ]
permissive
Ja1941/xena-UROP-2018
41f0956519f94d56b8bf6834a8d39473f4923200
b111fb87f343cf79eca3b886f99ee15c1dd9884b
refs/heads/master
1,662,355,955,139
1,590,577,325,000
1,590,577,325,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
22,537
lean
import Euclid.tarski_1 open classical set namespace Euclidean_plane variables {point : Type} [Euclidean_plane point] local attribute [instance] prop_decidable theorem six9 {a b p : point} : b ∈ ray p a → ray p a = ray p b := begin intro h, ext, split, intro h1, cases h with h h2, cases h2 with h2 h3, cases h1 with h1 h4, cases h4 with h4 h5, split, exact h2, split, exact h4, cases h3, cases h5, exact five1 h.symm h3 h5, right, exact three6b h5 h3, cases h5, left, exact three6b h3 h5, exact five3 h3 h5, intro h1, cases h with h h2, cases h2 with h2 h3, cases h1 with h1 h4, cases h4 with h4 h5, split, exact h, split, exact h4, cases h3, cases h5, left, exact three6b h3 h5, exact five3 h3 h5, cases h5, exact five1 h2.symm h3 h5, right, exact three6b h5 h3 end theorem six10 {a b c p q r : point} : sided a b c → sided p q r → eqd a b p q → eqd a c p r → cong a b c p q r := begin intro h, revert p q r, wlog h4 : distle a b a c, exact (five10 a b a c), introv h1 h2 h3, repeat {split}; try {assumption}, have h5 : distle p q p r, exact five6 h4 h2 h3, have h6 : B a b c, exact (six12 h).1 h4, have h7 : B p q r, exact (six12 h1).1 h5, exact (four3 h6.symm h7.symm h3.flip h2.flip).flip, have h1 := this h.symm a_1.symm a_3 a_2, repeat {split}, exact h1.2.2, exact h1.2.1.flip, exact h1.1 end theorem six10a {a b c a' b' c' : point} : sided a b c → cong a b c a' b' c' → sided a' b' c' := begin intro h, revert a' b' c', wlog h1 : B a b c := (h.2.2) using b c, introv h2, split, intro h_1, subst b', exact h.1.symm (id_eqd h2.1), split, intro h_1, subst c', exact h.2.1.symm (id_eqd h2.2.2), exact or.inl (four6 h1 h2), apply (this h.symm _).symm, exact ⟨a_1.2.2, a_1.2.1.flip, a_1.1⟩ end def l (a b : point) : set point := {x | col a b x} def line (k : set point) : Prop := ∃ a b, a ≠ b ∧ k = l a b lemma six14 {a b : point} : a ≠ b → line (l a b) := begin intro h, existsi a, existsi b, split, exact h, refl end theorem six15 {p q r : point} : p ≠ q → p ≠ r → B q p r → l p q = ray p q ∪ {p} ∪ ray p r := begin intros h h1 h2, ext, split, intro h3, cases em (x = p), left, right, rw h_1, simp, cases h3, left, left, split, exact h.symm, split, exact h_1, left, exact h3, cases h3, left, left, split, exact h.symm, split, exact h_1, right, exact h3.symm, right, split, exact h1.symm, split, exact h_1, exact five2 h.symm h2 h3.symm, intro h3, cases h3, cases h3, cases h3 with h3 h4, cases h4 with h4 h5, cases h5, left, exact h5, right, left, exact h5.symm, have : x = p, simpa using h3, right, left, rw this, exact three1 q p, cases h3 with h3 h4, cases h4 with h4 h5, right, right, cases h5, exact (three7b h2 h5 h1).symm, exact (three5a h2 h5).symm end theorem six16 {p q r : point} : p ≠ q → p ≠ r → r ∈ l p q → l p q = l p r := begin intros h h1 h2, ext, split, intro h3, exact five4 h h2 h3, intro h3, have : col p r q, exact (four11 h2).1, exact five4 h1 this h3 end theorem six16a {p q r : point} : sided p q r → l p q = l p r := λ h, six16 h.1.symm h.2.1.symm (four11 (six4.1 h).1).2.1 theorem six17 (p q : point) : l p q = l q p := begin ext, split, intro h1, exact (four11 h1).2.1, intro h1, exact (four11 h1).2.1 end theorem line.symm {a b : point} (h : line (l a b)) : line (l b a) := (six17 a b) ▸ h @[simp] theorem six17a (p q : point) : p ∈ l p q := (four11 (four12 p q)).1 @[simp] theorem six17b (p q : point) : q ∈ l p q := (four11 (four12 q p)).2.2.2.1 theorem six18 {a b : point} {L : set point} : line L → a ≠ b → a ∈ L → b ∈ L → L = l a b := begin intros h h1 h2 h3, cases h with p hp, cases hp with q hq, rw hq.2 at *, cases em (a = p), rw h at *, exact six16 hq.1 h1 h3, have ha : l p q = l p a, exact six16 hq.1 (ne.symm h) h2, rw ha at *, rw six17 p a at *, exact six16 h h1 h3 end theorem six18a {a p q : point} : a ∉ l p q → a ≠ p ∧ a ≠ q := begin intro h, split, intro h1, subst a, apply h, simp, intro h1, subst a, simpa using h end theorem six19 {a b : point} : a ≠ b → ∃! L : set point, line L ∧ a ∈ L ∧ b ∈ L := begin intro h, existsi l a b, split, split, existsi a, existsi b, split, exact h, refl, split; simp, intros y hy, exact six18 hy.1 h hy.2.1 hy.2.2 end theorem six20 {a b c : point} {A : set point} : line A → a ∈ A → b ∈ A → a ≠ b → col a b c → c ∈ A := begin intros h h1 h2 h3 h4, suffices : A = l a b, subst A, exact h4, exact six18 h h3 h1 h2 end theorem six21 {a b : point} {A B : set point} : a ≠ b → line A → line B → a ∈ A → a ∈ B → b ∈ A → b ∈ B → A = B := begin intros h h1 h2 h3 h4 h5 h6, apply unique_of_exists_unique (six19 h), repeat {split, assumption}, assumption, assumption end def is (x : point) (A B : set point) : Prop := line A ∧ line B ∧ A ≠ B ∧ x ∈ A ∧ x ∈ B theorem six21a {x y : point} {A B : set point} : line A → line B → A ≠ B → x ∈ A → x ∈ B → y ∈ A → y ∈ B → x = y := λ h h1 h2 h3 h4 h5 h6, classical.by_contradiction (λ h_1, h2 (six21 h_1 h h1 h3 h4 h5 h6)) theorem six22 {x : point} {A : set point} : line A → x ∈ A → ∃ y, x ≠ y ∧ A = l x y := begin intros h h1, have h2 := h, cases h with u hu, cases hu with v hv, cases em (u = x), rw h at *, constructor, exact hv, constructor, split, exact ne.symm h, have : u ∈ A, rw hv.2, simp, exact six18 h2 (ne.symm h) h1 this end theorem six23 {a b c : point} : col a b c ↔ ∃ (L : set point), line L ∧ a ∈ L ∧ b ∈ L ∧ c ∈ L := begin split, intro h, cases em (a = b), rw h_1 at *, cases em (b = c), rw h_2 at *, cases three14 c c with p hp, existsi l c p, split, exact six14 hp.2, simp, existsi l b c, split, exact six14 h_2, simp, existsi l a b, split, exact six14 h_1, simpa using h, intro h, cases h with L h, cases em (a = b), rw h_1, exact four12 b c, have : L = l a b, exact six18 h.1 h_1 h.2.1 h.2.2.1, rw this at *, exact h.2.2.2 end theorem six24 : ¬col (P1 : point) P2 P3 := begin have h := two_dim point, intro h1, cases h1, exact h.1 h1, cases h1, exact h.2.1 h1, exact h.2.2 h1 end theorem six25 {a b : point} : a ≠ b → ∃ c, ¬col a b c := begin intro h1, by_contradiction h2, rw not_exists at h2, simp at h2, apply @six24 point, apply six23.2, exact ⟨l a b, six14 h1, h2 P1, h2 P2, h2 P3⟩ end lemma six13a (a : point) : ¬line (l a a) := begin intro h, cases h with p hp, cases hp with q hq, cases six25 hq.1 with r hr, apply hr, suffices : r ∈ l a a, rw hq.2 at this, exact this, left, exact three3 a r end lemma six13 {a b : point} : line (l a b) → a ≠ b := begin intros h h1, subst b, apply six13a a, exact h end def tri (a b c : point) : Prop := a ≠ b ∧ b ≠ c ∧ a ≠ c theorem six26 {a b c : point} : ¬col a b c → tri a b c := begin intro h, split, intro h, rw h at *, exact h (four12 b c), split, intro h, rw h at *, exact h (four11 (four12 c a)).2.2.2.1, intro h, rw h at *, exact h (four11 (four12 c b)).1 end theorem six27 {a b c : point} {A : set point} : line A → a ∈ A → c ∈ A → B a b c → b ∈ A := begin intros h h1 h2 h3, cases em (a = c), rw h_1 at h3, have : c = b, exact bet_same h3, rwa this at h2, have h4 := six18 h h_1 h1 h2, rw h4, right, left, exact h3.symm end theorem six28 {a b c :point} : ¬col a b c → is a (l a b) (l a c) := begin intro h, split, exact six14 (six26 h).1, split, exact six14 (six26 h).2.2, split, intro h1, have h2 : c ∈ l a b, rw h1, simp, contradiction, simp end -- middle points def M (a m b : point) : Prop := B a m b ∧ eqd m a m b theorem M.symm {a b m : point} : M a m b → M b m a := begin intro h, split, exact h.1.symm, exact h.2.symm end theorem seven3 {a m : point} : M a m a ↔ a = m := begin split, intro h, exact bet_same h.1, intro h, rw h at *, split, exact three1 m m, exact eqd.refl m m end theorem seven4 (a p : point) : ∃! q, M p a q := begin cases em (a = p), rw h, existsi p, split, apply seven3.2, refl, intros y hy, cases hy with h1 h2, exact id_eqd h2.symm.flip, cases seg_cons a a p p with q hq, apply exists_unique.intro, exact ⟨hq.1, hq.2.symm⟩, intros y hy, apply unique_of_exists_unique (two12 a a p p (ne.symm h)), exact ⟨hy.1, hy.2.symm⟩, exact hq end noncomputable def S (a p : point) : point := classical.some (seven4 a p) theorem seven5 (a p : point) : M p a (S a p) := (classical.some_spec (seven4 a p)).1 theorem seven6 {a p q : point} : M p a q → q = S a p := begin intro h, exact unique_of_exists_unique (seven4 a p) h (classical.some_spec (seven4 a p)).1 end @[simp] theorem seven7 (a p : point) : S a (S a p) = p := begin cases seven5 a p with h1 h2, generalize hq : S a p = q, rw hq at *, cases seven5 a q with h3 h4, generalize hr : S a q = r, rw hr at *, cases em (q = a), rw h at *, have ha : a = r, exact id_eqd h4.symm, rw ha at *, exact id_eqd h2, apply unique_of_exists_unique (two12 a a p q h), split, exact h3, exact (eqd.trans h2 h4).symm, split, exact h1.symm, exact eqd.refl a p end theorem seven8 (a p : point) : ∃! q, S a q = p := begin existsi S a p, split, exact seven7 a p, intros q h, rw ←h, exact (seven7 a q).symm end theorem seven9 {a p q : point} : S a p = S a q → p = q := begin intro h, apply unique_of_exists_unique (seven8 a (S a p)), simp, rw ←h end theorem seven9a {a b : point} (p : point) : a ≠ b → S p a ≠ S p b := begin intros h h1, exact h (seven9 h1) end theorem seven10 {a p : point} : S a p = p ↔ p = a := begin split, intro h, have : M p a (S a p), exact seven5 a p, rw h at *, exact seven3.1 this, intro h, rw h, have : M a a (S a a), exact seven5 a a, cases this with h1 h2, exact id_eqd h2.symm.flip end @[simp] theorem seven11 (a : point) : S a a = a := begin apply seven10.2, refl end theorem seven12a {a p : point} : a ≠ p → a ≠ S a p := begin intros h h1, apply h, have h2 : S a a = a, exact seven11 a, exact seven9 (eq.trans h2 h1) end theorem seven12b {a p : point} : a ≠ p → p ≠ S a p := λ h h1, h.symm (seven10.1 h1.symm) theorem seven13 (a p q : point) : eqd p q (S a p) (S a q) := begin have hp : M p a (S a p), exact seven5 a p, have hq : M q a (S a q), exact seven5 a q, generalize hp' : S a p = p', generalize hq' : S a q = q', rw hp' at *, rw hq' at *, cases em (p = a), have : S a p = p, exact seven10.2 h, rw h at *, rw this at *, rw ←hp' at *, exact hq.2, cases seg_cons p q a p' with x hx, cases seg_cons p' q a x with x' hx', cases seg_cons q p a q' with y hy, cases seg_cons q' p a y with y' hy', have h1 : B a p x, exact three6a hp.1.symm hx.1, have h2 : B p p' x', exact three6a hx.1.symm hx'.1, have h3 : B a p' x', exact three6a hp.1 h2, have h4 : B a q y, exact three6a hq.1.symm hy.1, have h5 : B q q' y', exact three6a hy.1.symm hy'.1, have h6 : B a q' y', exact three6a hq.1 h5, have h7 : eqd a x y a, exact two11 h1 h4.symm hy.2.symm.flip hx.2, have h8 : eqd a x a x', exact two11 h1 h3 hp.2 (eqd.trans hx.2 hx'.2.symm), have h9 : eqd a x y' a, exact two11 h1 h6.symm hy'.2.symm.flip (eqd.trans hx.2 hq.2.flip), have h10 : B x a p', exact three5b hx.1.symm hp.1, have h11 : B y a q', exact three5b hy.1.symm hq.1, have h12 : afs x a x' y' y' a y x, repeat {split}, exact three6b h10 hx'.1, exact (three6b h11 hy'.1).symm, exact two4 h9, exact two5 (eqd.trans h8.symm h7), exact two5 (eqd.refl x y'), exact two4 h9.symm, have h13 : x ≠ a, intro h_1, rw h_1 at h1, exact h (bet_same h1).symm, have h14 : eqd x' y' y x, exact afive_seg h12 h13, have h15 : ifs y q a x y' q' a x', repeat {split}, exact h4.symm, exact h6.symm, exact eqd.trans h7.symm h9, exact hq.2.flip, exact two5 h14.symm, exact h8, have h16 := four2 h15, have h17 : ifs x p a q x' p' a q', repeat {split}, exact h1.symm, exact h3.symm, exact h8.flip, exact hp.2.flip, exact h16.flip, exact hq.2, exact four2 h17 end theorem seven15 (a : point) {p q r : point} : B p q r ↔ B (S a p) (S a q) (S a r) := begin split, intro h, apply four6 h, repeat {split}; exact seven13 a _ _, intro h, rw ←(seven7 a p), rw ←(seven7 a q), rw ←(seven7 a r), apply four6 h, repeat {split}; exact seven13 a _ _, end theorem seven16 (a : point) {p q r s : point}: eqd p q r s ↔ eqd (S a p) (S a q) (S a r) (S a s) := begin split, intro h, exact (seven13 a p q).symm.trans (h.trans (seven13 a r s)), intro h, have h1 := eqd.trans (seven13 a (S a p) (S a q)).symm (eqd.trans h (seven13 a (S a r) (S a s))), simpa using h1 end theorem seven16a (a : point) {p q r : point} : cong p q r (S a p) (S a q) (S a r) := begin repeat {split}; exact seven13 a _ _ end theorem seven14 (a : point) {p q r : point} : M p q r ↔ M (S a p) (S a q) (S a r) := begin split, intro h, cases h with h h1, split, exact (seven15 a).1 h, exact (seven16 a).1 h1, intro h, cases h with h h1, split, exact (seven15 a).2 h, exact (seven16 a).2 h1 end theorem S_of_col {p q r : point} (a : point) : col p q r ↔ col (S a p) (S a q) (S a r) := begin split, intro h, unfold col, repeat {cases h}; simp [(seven15 a).1 h], intro h, unfold col, repeat {cases h}; simp [(seven15 a).2 h] end theorem seven17 {a b p q : point} : M p a q → M p b q → a = b := begin intros h h1, have h2 := seven6 h, have h3 := seven13 a q b, have h4 := seven7 a p, rwa ←h2 at h4, rw h4 at h3, have h6 : eqd p b p (S a b), exact eqd.trans h1.2.flip h3, have h7 := seven13 a p b, rw ←h2 at h7, have h8 : eqd q b q (S a b), exact eqd.trans h1.2.symm.flip h7, have h9 : b = (S a b), exact four19 h1.1 h6 h8.flip, exact (seven10.1 h9.symm).symm end theorem seven18 {a b p : point} : S a p = S b p → a = b := begin intro h, generalize h1 : S a p = q, have h2 := seven5 a p, rw h1 at h2, have h3 := seven5 b p, rw (eq.trans h.symm h1) at h3, exact seven17 h2 h3 end theorem seven18a {a b p : point} : a ≠ b → S a p ≠ S b p:= λ h h1, h (seven18 h1) theorem seven19 {a b p : point} : S a (S b p) = S b (S a p) ↔ a = b := begin split, intro h, generalize h1 : S a p = q, have h2 := seven5 a p, rw h1 at *, have h3 := seven5 a (S b p), rw h at h3, cases h3 with h3 h4, have h5 := (seven15 b).1 h3, have h6 := (seven16 b).1 h4, rw seven7 b p at *, rw seven7 b q at *, have h7 : M p (S b a) q, split; assumption, have h8 : a = (S b a), exact seven17 h2 h7, exact seven10.1 h8.symm, intro h, rw h end theorem seven20 {a m b : point} : col a m b → eqd m a m b → a = b ∨ M a m b := begin intros h h1, cases h, right, split; assumption, cases h, left, have h2 := three3 b m, have h3 : eqd a b b b, exact four3 h.symm h2 h1.flip (eqd.refl b m), exact id_eqd h3, left, have h2 := three3 a m, have h3 : eqd b a a a, exact four3 h h2 h1.symm.flip (eqd.refl a m), exact id_eqd h3.flip end theorem seven21 {a b c d p : point} : ¬col a b c → b ≠ d → eqd a b c d → eqd b c d a → col a p c → col b p d → M a p c ∧ M b p d := begin intros h h1 h2 h3 h4 h5, cases four14 (four11 h5).1 (two5 (eqd.refl b d)) with q hq, have h6 := four13 (four11 h5).1 hq, have h7 : fs b d p a d b q c, split, exact (four11 h5).1, split, exact hq, split, exact h2.flip, exact h3.symm, have h8 : fs b d p c d b q a, split, exact (four11 h5).1, split, exact hq, split, exact h3, exact h2.symm.flip, have h9 := four16 h7 h1, have h10 := four16 h8 h1, have h11 : cong a p c c q a, split, exact h9.flip, split, exact h10, exact two5 (eqd.refl a c), have h12 : p = q, suffices : l a c ≠ l b d, apply six21a (six14 (six26 h).2.2) (six14 h1) this (four11 h4).1 (four11 h5).1 (four11 (four13 h4 h11)).2.2.2.1 (four11 h6).2.1, intro h_1, suffices : b ∉ l a c, simpa [h_1, (six17a b d)] using this, exact (four10 h).1, subst q, split, cases seven20 h4 h9, exact ((six26 h).2.2 h_1).elim, assumption, cases seven20 h5 (hq.2.2).flip, contradiction, assumption end def hourglass (a b c p q m n : point) : Prop := B a c p ∧ B b c q ∧ eqd c a c b ∧ eqd c p c q ∧ M a m b ∧ M p n q lemma seven23 {a b c p q m n : point} : hourglass a b c p q m n → distle c a c q → B m c n := begin intros h h_1, cases h with h h1, cases h1 with h1 h2, cases h2 with h2 h3, cases h3 with h3 h4, cases h4 with h4 h5, cases em (p = c), rw h_2 at *, have h_3 : q = c, exact id_eqd h3.symm.flip, rw h_3 at *, have h_4 : c = n, exact seven3.1 h5, rw h_4 at *, exact three1 m n, generalize h6 : S c p = a', generalize h7 : S c q = b', generalize h8 : S c n = m', have h9 : M a' m' b', have h_3 := (seven14 c).1 h5, rwa [h6, h7, h8] at h_3, have h10 : M p c a', have h10 := seven5 c p, rwa h6 at h10, have h11 : M q c b', have h11 := seven5 c q, rwa h7 at h11, have h12 : M n c m', have h12 := seven5 c n, rwa h8 at h12, have h13 : distle c a c a', exact five6 h_1 (eqd.refl c a) (eqd.trans h3.symm h10.2), cases em (a = c), rw h_3 at *, have : b = c, exact id_eqd h2.symm.flip, rw this at *, have : c = m, exact seven3.1 h4, rw this, exact three3 m n, have h_4 : a' ≠ c, intro h_4, rw h_4 at *, have : eqd c a c c, exact five9 h13 (five11 c c a), exact h_3 (id_eqd this.flip), have h14 : sided c a a', apply six3.2, split, exact h_3, split, exact h_4, existsi p, split, exact h_2, split, exact h, exact h10.1.symm, have h15 : B c a a', exact (six12 h14).1 h13, have h16 : distle c b c b', exact five6 h_1 h2 h11.2, have h_5 : q ≠ c, intro h_5, rw h_5 at *, exact h_2 (id_eqd h3.flip), cases em (b = c), rw h_6 at *, have : a = c, exact id_eqd h2.flip, rw this at *, have : c = m, exact seven3.1 h4, rw this, exact three3 m n, have h_7 : b' ≠ c, intro h_7, rw h_7 at *, have : eqd c b c c, exact five9 h16 (five11 c c b), exact h_6 (id_eqd this.flip), have h17 : sided c b b', apply six3.2, split, exact h_6, split, exact h_7, existsi q, split, exact h_5, split, exact h1, exact h11.1.symm, have h18 : B c b b', exact (six12 h17).1 h16, cases three17 h15.symm h18.symm h9.1 with r hr, have h19 : B r c n, exact three6a hr.1 h12.1.symm, suffices : r = m, rwa this at h19, have h20 : ifs a' a c m' b' b c m', repeat {split}, exact h15.symm, exact h18.symm, exact eqd.trans h10.2.symm.flip (eqd.trans h3.flip h11.2.flip), exact h2.flip, exact h9.2.flip, exact eqd.refl c m', have h20 := four2 h20, have h21 : col m' c r, right, left, exact hr.1.symm, have h22 : eqd r a r b, cases em (m' = c), rw h_8 at *, have : c = r, exact bet_same hr.1, rw this at *, exact h20.flip, exact four17 h_8 h21 h20.flip h2, have h23 : M a r b, split, exact hr.2, exact h22, exact seven17 h23 h4 end theorem seven22 {a b c p q m n : point} : hourglass a b c p q m n → B m c n := begin intro h, cases five10 c a c q, exact seven23 h h_1, cases h with h h1, cases h1 with h1 h2, cases h2 with h2 h3, cases h3 with h3 h4, cases h4 with h4 h5, have h6 : hourglass q p c b a n m, repeat {split}, exact h1.symm, exact h.symm, exact h3.symm, exact h2.symm, exact h5.1.symm, exact h5.2.symm, exact h4.1.symm, exact h4.2.symm, exact (seven23 h6 h_1).symm end theorem seven24 {a p : point} {A : set point} : line A → a ∈ A → (p ∈ A ↔ (S a p) ∈ A) := begin intros h h1, split, intro h2, cases em (a = p), have h3 := seven10.2 h_1.symm, rwa h3, have h3 := six18 h h_1 h1 h2, rw h3, have h4 := seven5 a p, right, right, exact h4.1.symm, intro h2, cases em (a = (S a p)), have h3 := seven10.2 h_1.symm, rw ←seven7 a p, rwa h3, have h3 := six18 h h_1 h1 h2, rw h3, have h4 := seven5 a p, right, right, exact h4.1 end theorem seven25 {a b c : point} : eqd c a c b → ∃ x, M a x b := begin intro h, cases em (col a c b), cases seven20 h_1 h, rw h_2 at *, existsi b, split, exact three1 b b, exact eqd.refl b b, constructor, exact h_2, cases three14 c a with p hp, cases seg_cons b a p c with q hq, cases pasch hp.1.symm hq.1.symm with r hr, cases pasch hp.1 hr.2 with x hx, existsi x, suffices : eqd x a x b, split, exact hx.1, exact this, suffices : eqd r a r b, have h1 : col c r x, right, left, exact hx.2, cases em (c = r), rw h_2 at hx, have : r = x, exact bet_same hx.2, rw this at *, exact this, exact four17 h_2 h1 h this, have h1 : afs c a p b c b q a, repeat {split}, exact hp.1, exact hq.1, exact h, exact hq.2.symm, exact h.symm, exact two5 (eqd.refl a b), have h2 : eqd p b q a, exact afive_seg h1 (six26 h_1).1.symm, cases four5 hr.2 h2.flip with r' hr', have h3 : ifs b r p a a r' q b, repeat {split}, exact hr.2, exact hr'.1, exact hr'.2.2.2, exact hr'.2.2.1, exact two4 (eqd.refl a b), exact hq.2.symm.flip, have h4 : ifs b r p q a r' q p, repeat {split}, exact hr.2, exact hr'.1, exact hr'.2.2.2, exact hr'.2.2.1, exact hq.2, exact two5 (eqd.refl p q), have h5 := four2 h3, have h6 := four2 h4, have h7 : cong a r q b r' p, split, exact h5.flip, split, exact h6, exact h2.symm.flip, have h8 : col a r q, left, exact hr.1, have h9 := four13 h8 h7, have h_2 : a ≠ q, intro h_2, rw ←h_2 at *, have : col a c b, right, left, exact hq.1, exact h_1 this, have h_3 : b ≠ p, intro h_3, rw ←h_3 at *, have : col a c b, right, right, exact hp.1.symm, exact h_1 this, have h10 : l a q ≠ l b p, intro h_4, suffices : a ∈ l b p, have h_6 : col a p c, right, right, exact hp.1, exact h_1 (five4 hp.2 h_6 (four11 this).2.2.2.2), rw ←h_4, simp, have h11 : col b p r, right, left, exact hr.2.symm, have h12 : col a q r', right, left, exact hr'.1.symm, suffices : r' = r, rwa this at h5, exact six21a (six14 h_2) (six14 h_3) h10 h12 (four11 h9).1 (four11 h8).1 h11 end end Euclidean_plane
c7f51dfb81ed641bffb5d080faf8b6c2f9a90530
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/topology/hom/open.lean
9225e3976caf1b0e9a075e9b1f356e405ec3db69
[ "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
4,459
lean
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import topology.continuous_function.basic /-! # Continuous open maps > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines bundled continuous open maps. We use the `fun_like` design, so each type of morphisms has a companion typeclass which is meant to be satisfied by itself and all stricter types. ## Types of morphisms * `continuous_open_map`: Continuous open maps. ## Typeclasses * `continuous_open_map_class` -/ open function variables {F α β γ δ : Type*} /-- The type of continuous open maps from `α` to `β`, aka Priestley homomorphisms. -/ structure continuous_open_map (α β : Type*) [topological_space α] [topological_space β] extends continuous_map α β := (map_open' : is_open_map to_fun) infixr ` →CO `:25 := continuous_open_map section set_option old_structure_cmd true /-- `continuous_open_map_class F α β` states that `F` is a type of continuous open maps. You should extend this class when you extend `continuous_open_map`. -/ class continuous_open_map_class (F : Type*) (α β : out_param $ Type*) [topological_space α] [topological_space β] extends continuous_map_class F α β := (map_open (f : F) : is_open_map f) end export continuous_open_map_class (map_open) instance [topological_space α] [topological_space β] [continuous_open_map_class F α β] : has_coe_t F (α →CO β) := ⟨λ f, ⟨f, map_open f⟩⟩ /-! ### Continuous open maps -/ namespace continuous_open_map variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ] instance : continuous_open_map_class (α →CO β) α β := { coe := λ f, f.to_fun, coe_injective' := λ f g h, by { obtain ⟨⟨_, _⟩, _⟩ := f, obtain ⟨⟨_, _⟩, _⟩ := g, congr' }, map_continuous := λ f, f.continuous_to_fun, map_open := λ f, f.map_open' } /-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun` directly. -/ instance : has_coe_to_fun (α →CO β) (λ _, α → β) := fun_like.has_coe_to_fun @[simp] lemma to_fun_eq_coe {f : α →CO β} : f.to_fun = (f : α → β) := rfl @[ext] lemma ext {f g : α →CO β} (h : ∀ a, f a = g a) : f = g := fun_like.ext f g h /-- Copy of a `continuous_open_map` with a new `continuous_map` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : α →CO β) (f' : α → β) (h : f' = f) : α →CO β := ⟨f.to_continuous_map.copy f' $ by exact h, h.symm.subst f.map_open'⟩ @[simp] lemma coe_copy (f : α →CO β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl lemma copy_eq (f : α →CO β) (f' : α → β) (h : f' = f) : f.copy f' h = f := fun_like.ext' h variables (α) /-- `id` as a `continuous_open_map`. -/ protected def id : α →CO α := ⟨continuous_map.id _, is_open_map.id⟩ instance : inhabited (α →CO α) := ⟨continuous_open_map.id _⟩ @[simp] lemma coe_id : ⇑(continuous_open_map.id α) = id := rfl variables {α} @[simp] lemma id_apply (a : α) : continuous_open_map.id α a = a := rfl /-- Composition of `continuous_open_map`s as a `continuous_open_map`. -/ def comp (f : β →CO γ) (g : α →CO β) : continuous_open_map α γ := ⟨f.to_continuous_map.comp g.to_continuous_map, f.map_open'.comp g.map_open'⟩ @[simp] lemma coe_comp (f : β →CO γ) (g : α →CO β) : (f.comp g : α → γ) = f ∘ g := rfl @[simp] lemma comp_apply (f : β →CO γ) (g : α →CO β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] lemma comp_assoc (f : γ →CO δ) (g : β →CO γ) (h : α →CO β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] lemma comp_id (f : α →CO β) : f.comp (continuous_open_map.id α) = f := ext $ λ a, rfl @[simp] lemma id_comp (f : α →CO β) : (continuous_open_map.id β).comp f = f := ext $ λ a, rfl lemma cancel_right {g₁ g₂ : β →CO γ} {f : α →CO β} (hf : surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨λ h, ext $ hf.forall.2 $ fun_like.ext_iff.1 h, congr_arg _⟩ lemma cancel_left {g : β →CO γ} {f₁ f₂ : α →CO β} (hg : injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨λ h, ext $ λ a, hg $ by rw [←comp_apply, h, comp_apply], congr_arg _⟩ end continuous_open_map
7cec1c74d639ee0c686390365b4519123a7aa4e4
367134ba5a65885e863bdc4507601606690974c1
/test/generalizes.lean
3040e595ef555ad0e746e9e03a0b2f33f970fdb1
[ "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
3,531
lean
/- Copyright (c) 2020 Jannis Limperg. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jannis Limperg -/ import tactic.generalizes universes u lemma example_from_docs₁ (P : ∀ n, fin n → Prop) (n : ℕ) (f : fin n) (p : ∀ n xs, P n xs) : P (nat.succ n) (fin.succ f) := begin generalizes [n'_eq : nat.succ n = n', f'_eq : fin.succ f == f'], guard_hyp n' : ℕ, guard_hyp n'_eq : n' = nat.succ n, guard_hyp f' : fin n', guard_hyp f'_eq : f' == fin.succ f, exact p n' f' -- Note: `generalizes` fails if we write `n + 1` instead of `nat.succ n` in -- the target because `kabstract` works with a notion of equality that is -- weaker than definitional equality. This is annoying, but we can't do much -- about it short of reimplementing `kabstract`. end lemma example_from_docs₂ (P : ∀ n, fin n → Prop) (n : ℕ) (f : fin n) (p : ∀ n xs, P n xs) : P (nat.succ n) (fin.succ f) := begin generalizes [(nat.succ n = n'), (fin.succ f == f')], guard_hyp n' : ℕ, success_if_fail { guard_hyp n'_eq : n' = nat.succ n }, guard_hyp f' : fin n', success_if_fail { guard_hyp f'_eq : f' == fin.succ f }, exact p n' f' end inductive Vec (α : Sort u) : ℕ → Sort (max 1 u) | nil : Vec 0 | cons {n} (x : α) (xs : Vec n) : Vec (n + 1) namespace Vec inductive eq {α} : ∀ (n m : ℕ), Vec α n → Vec α m → Prop | nil : eq 0 0 nil nil | cons {n m x y xs ys} : x = y → eq n m xs ys → eq (n + 1) (m + 1) (cons x xs) (cons y ys) inductive fancy_unit {α} : ∀ n, Vec α n → Prop | intro (n xs) : fancy_unit n xs -- An example of the difference between multiple calls to `generalize` and -- one call to `generalizes`. lemma test₁ {α n} {x : α} {xs} : fancy_unit (n + 1) (cons x xs) := begin -- Successive `generalize` invocations don't give us the right goal: -- The second generalisation fails due to the dependency between -- `xs' : Vec α (n + 1)` and `n + 1`. success_if_fail { generalize eq_xs' : cons x xs = xs', generalize eq_n' : n + 1 = n', exact fancy_unit.intro n' xs' }, -- `generalizes` gives us the expected result with everything generalised. generalizes [eq_n' : n + 1 = n', eq_xs' : cons x xs = xs'], guard_hyp n' : ℕ, guard_hyp eq_n' : n' = n + 1, guard_hyp xs' : Vec α n', guard_hyp eq_xs' : xs' == cons x xs, exact fancy_unit.intro n' xs' end -- We can also choose to introduce equations for only some of the generalised -- expressions. lemma test₂ {α n} {x : α} {xs} : fancy_unit (n + 1) (cons x xs) := begin generalizes [n + 1 = n', eq_xs' : cons x xs = xs'], guard_hyp n' : ℕ, success_if_fail { guard_hyp eq_n' : n' = n + 1 }, guard_hyp xs' : Vec α n', guard_hyp eq_xs' : xs' == cons x xs, exact fancy_unit.intro n' xs' end -- An example where `generalizes` enables a successful `induction` (though in -- this case, `cases` would suffice and already performs the generalisation). lemma eq_cons_inversion {α} {n m x y} {xs : Vec α n} {ys : Vec α m} : eq (n + 1) (m + 1) (cons x xs) (cons y ys) → eq n m xs ys := begin generalizes [ n'_eq : n + 1 = n' , m'_eq : m + 1 = m' , xs'_eq : cons x xs = xs' , ys'_eq : cons y ys = ys' ], intro h, induction h, case nil { cases n'_eq, }, case cons : n'' m'' x y xs'' ys'' eq_xy eq_xsys'' ih { cases n'_eq, clear n'_eq, cases m'_eq, clear m'_eq, cases xs'_eq, clear xs'_eq, cases ys'_eq, clear ys'_eq, exact eq_xsys'', } end end Vec
46e63571a3a70065dc2ca3707a2d911cb5e32390
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/category_theory/limits/constructions/over/products.lean
d6f9073a3ab12d7a309f00739437bfcf47691a09
[ "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
6,366
lean
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Reid Barton, Bhavik Mehta -/ import category_theory.over import category_theory.limits.shapes.pullbacks import category_theory.limits.shapes.wide_pullbacks import category_theory.limits.shapes.finite_products /-! # Products in the over category > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. Shows that products in the over category can be derived from wide pullbacks in the base category. The main result is `over_product_of_wide_pullback`, which says that if `C` has `J`-indexed wide pullbacks, then `over B` has `J`-indexed products. -/ universes w v u -- morphism levels before object levels. See note [category_theory universes]. open category_theory category_theory.limits variables {J : Type w} variables {C : Type u} [category.{v} C] variable {X : C} namespace category_theory.over namespace construct_products /-- (Implementation) Given a product diagram in `C/B`, construct the corresponding wide pullback diagram in `C`. -/ @[reducible] def wide_pullback_diagram_of_diagram_over (B : C) {J : Type w} (F : discrete J ⥤ over B) : wide_pullback_shape J ⥤ C := wide_pullback_shape.wide_cospan B (λ j, (F.obj ⟨j⟩).left) (λ j, (F.obj ⟨j⟩).hom) /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simps] def cones_equiv_inverse_obj (B : C) {J : Type w} (F : discrete J ⥤ over B) (c : cone F) : cone (wide_pullback_diagram_of_diagram_over B F) := { X := c.X.left, π := { app := λ X, option.cases_on X c.X.hom (λ (j : J), (c.π.app ⟨j⟩).left), -- `tidy` can do this using `case_bash`, but let's try to be a good `-T50000` citizen: naturality' := λ X Y f, begin dsimp, cases X; cases Y; cases f, { rw [category.id_comp, category.comp_id], }, { rw [over.w, category.id_comp], }, { rw [category.id_comp, category.comp_id], }, end } } /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simps] def cones_equiv_inverse (B : C) {J : Type w} (F : discrete J ⥤ over B) : cone F ⥤ cone (wide_pullback_diagram_of_diagram_over B F) := { obj := cones_equiv_inverse_obj B F, map := λ c₁ c₂ f, { hom := f.hom.left, w' := λ j, begin cases j, { simp }, { dsimp, rw ← f.w ⟨j⟩, refl } end } } local attribute [tidy] tactic.discrete_cases /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simps] def cones_equiv_functor (B : C) {J : Type w} (F : discrete J ⥤ over B) : cone (wide_pullback_diagram_of_diagram_over B F) ⥤ cone F := { obj := λ c, { X := over.mk (c.π.app none), π := { app := λ ⟨j⟩, over.hom_mk (c.π.app (some j)) (by apply c.w (wide_pullback_shape.hom.term j)) } }, map := λ c₁ c₂ f, { hom := over.hom_mk f.hom } } local attribute [tidy] tactic.case_bash /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simp] def cones_equiv_unit_iso (B : C) (F : discrete J ⥤ over B) : 𝟭 (cone (wide_pullback_diagram_of_diagram_over B F)) ≅ cones_equiv_functor B F ⋙ cones_equiv_inverse B F := nat_iso.of_components (λ _, cones.ext {hom := 𝟙 _, inv := 𝟙 _} (by tidy)) (by tidy) /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simp] def cones_equiv_counit_iso (B : C) (F : discrete J ⥤ over B) : cones_equiv_inverse B F ⋙ cones_equiv_functor B F ≅ 𝟭 (cone F) := nat_iso.of_components (λ _, cones.ext {hom := over.hom_mk (𝟙 _), inv := over.hom_mk (𝟙 _)} (by tidy)) (by tidy) -- TODO: Can we add `. obviously` to the second arguments of `nat_iso.of_components` and -- `cones.ext`? /-- (Impl) Establish an equivalence between the category of cones for `F` and for the "grown" `F`. -/ @[simps] def cones_equiv (B : C) (F : discrete J ⥤ over B) : cone (wide_pullback_diagram_of_diagram_over B F) ≌ cone F := { functor := cones_equiv_functor B F, inverse := cones_equiv_inverse B F, unit_iso := cones_equiv_unit_iso B F, counit_iso := cones_equiv_counit_iso B F, } /-- Use the above equivalence to prove we have a limit. -/ lemma has_over_limit_discrete_of_wide_pullback_limit {B : C} (F : discrete J ⥤ over B) [has_limit (wide_pullback_diagram_of_diagram_over B F)] : has_limit F := has_limit.mk { cone := _, is_limit := is_limit.of_right_adjoint (cones_equiv B F).functor (limit.is_limit (wide_pullback_diagram_of_diagram_over B F)) } /-- Given a wide pullback in `C`, construct a product in `C/B`. -/ lemma over_product_of_wide_pullback [has_limits_of_shape (wide_pullback_shape J) C] {B : C} : has_limits_of_shape (discrete J) (over B) := { has_limit := λ F, has_over_limit_discrete_of_wide_pullback_limit F } /-- Given a pullback in `C`, construct a binary product in `C/B`. -/ lemma over_binary_product_of_pullback [has_pullbacks C] {B : C} : has_binary_products (over B) := over_product_of_wide_pullback /-- Given all wide pullbacks in `C`, construct products in `C/B`. -/ lemma over_products_of_wide_pullbacks [has_wide_pullbacks.{w} C] {B : C} : has_products.{w} (over B) := λ J, over_product_of_wide_pullback /-- Given all finite wide pullbacks in `C`, construct finite products in `C/B`. -/ lemma over_finite_products_of_finite_wide_pullbacks [has_finite_wide_pullbacks C] {B : C} : has_finite_products (over B) := ⟨λ n, over_product_of_wide_pullback⟩ end construct_products local attribute [tidy] tactic.discrete_cases /-- Construct terminal object in the over category. This isn't an instance as it's not typically the way we want to define terminal objects. (For instance, this gives a terminal object which is different from the generic one given by `over_product_of_wide_pullback` above.) -/ lemma over_has_terminal (B : C) : has_terminal (over B) := { has_limit := λ F, has_limit.mk { cone := { X := over.mk (𝟙 _), π := { app := λ p, p.as.elim } }, is_limit := { lift := λ s, over.hom_mk _, fac' := λ _ j, j.as.elim, uniq' := λ s m _, begin ext, rw over.hom_mk_left, have := m.w, dsimp at this, rwa [category.comp_id, category.comp_id] at this end } } } end category_theory.over
62757dcaaf74fbe025717f753d832085b7a9aa8a
302c785c90d40ad3d6be43d33bc6a558354cc2cf
/src/order/filter/at_top_bot.lean
b4dd76b9093c2eb4782bbd53dfe049b90bc4b83f
[ "Apache-2.0" ]
permissive
ilitzroth/mathlib
ea647e67f1fdfd19a0f7bdc5504e8acec6180011
5254ef14e3465f6504306132fe3ba9cec9ffff16
refs/heads/master
1,680,086,661,182
1,617,715,647,000
1,617,715,647,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
56,845
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, Jeremy Avigad, Yury Kudryashov, Patrick Massot -/ import order.filter.bases import data.finset.preimage /-! # `at_top` and `at_bot` filters on preorded sets, monoids and groups. In this file we define the filters * `at_top`: corresponds to `n → +∞`; * `at_bot`: corresponds to `n → -∞`. Then we prove many lemmas like “if `f → +∞`, then `f ± c → +∞`”. -/ variables {ι ι' α β γ : Type*} open set open_locale classical filter big_operators namespace filter /-- `at_top` is the filter representing the limit `→ ∞` on an ordered set. It is generated by the collection of up-sets `{b | a ≤ b}`. (The preorder need not have a top element for this to be well defined, and indeed is trivial when a top element exists.) -/ def at_top [preorder α] : filter α := ⨅ a, 𝓟 (Ici a) /-- `at_bot` is the filter representing the limit `→ -∞` on an ordered set. It is generated by the collection of down-sets `{b | b ≤ a}`. (The preorder need not have a bottom element for this to be well defined, and indeed is trivial when a bottom element exists.) -/ def at_bot [preorder α] : filter α := ⨅ a, 𝓟 (Iic a) lemma mem_at_top [preorder α] (a : α) : {b : α | a ≤ b} ∈ @at_top α _ := mem_infi_sets a $ subset.refl _ lemma Ioi_mem_at_top [preorder α] [no_top_order α] (x : α) : Ioi x ∈ (at_top : filter α) := let ⟨z, hz⟩ := no_top x in mem_sets_of_superset (mem_at_top z) $ λ y h, lt_of_lt_of_le hz h lemma mem_at_bot [preorder α] (a : α) : {b : α | b ≤ a} ∈ @at_bot α _ := mem_infi_sets a $ subset.refl _ lemma Iio_mem_at_bot [preorder α] [no_bot_order α] (x : α) : Iio x ∈ (at_bot : filter α) := let ⟨z, hz⟩ := no_bot x in mem_sets_of_superset (mem_at_bot z) $ λ y h, lt_of_le_of_lt h hz lemma at_top_basis [nonempty α] [semilattice_sup α] : (@at_top α _).has_basis (λ _, true) Ici := has_basis_infi_principal (directed_of_sup $ λ a b, Ici_subset_Ici.2) lemma at_top_basis' [semilattice_sup α] (a : α) : (@at_top α _).has_basis (λ x, a ≤ x) Ici := ⟨λ t, (@at_top_basis α ⟨a⟩ _).mem_iff.trans ⟨λ ⟨x, _, hx⟩, ⟨x ⊔ a, le_sup_right, λ y hy, hx (le_trans le_sup_left hy)⟩, λ ⟨x, _, hx⟩, ⟨x, trivial, hx⟩⟩⟩ lemma at_bot_basis [nonempty α] [semilattice_inf α] : (@at_bot α _).has_basis (λ _, true) Iic := @at_top_basis (order_dual α) _ _ lemma at_bot_basis' [semilattice_inf α] (a : α) : (@at_bot α _).has_basis (λ x, x ≤ a) Iic := @at_top_basis' (order_dual α) _ _ @[instance] lemma at_top_ne_bot [nonempty α] [semilattice_sup α] : ne_bot (at_top : filter α) := at_top_basis.ne_bot_iff.2 $ λ a _, nonempty_Ici @[instance] lemma at_bot_ne_bot [nonempty α] [semilattice_inf α] : ne_bot (at_bot : filter α) := @at_top_ne_bot (order_dual α) _ _ @[simp] lemma mem_at_top_sets [nonempty α] [semilattice_sup α] {s : set α} : s ∈ (at_top : filter α) ↔ ∃a:α, ∀b≥a, b ∈ s := at_top_basis.mem_iff.trans $ exists_congr $ λ _, exists_const _ @[simp] lemma mem_at_bot_sets [nonempty α] [semilattice_inf α] {s : set α} : s ∈ (at_bot : filter α) ↔ ∃a:α, ∀b≤a, b ∈ s := @mem_at_top_sets (order_dual α) _ _ _ @[simp] lemma eventually_at_top [semilattice_sup α] [nonempty α] {p : α → Prop} : (∀ᶠ x in at_top, p x) ↔ (∃ a, ∀ b ≥ a, p b) := mem_at_top_sets @[simp] lemma eventually_at_bot [semilattice_inf α] [nonempty α] {p : α → Prop} : (∀ᶠ x in at_bot, p x) ↔ (∃ a, ∀ b ≤ a, p b) := mem_at_bot_sets lemma eventually_ge_at_top [preorder α] (a : α) : ∀ᶠ x in at_top, a ≤ x := mem_at_top a lemma eventually_le_at_bot [preorder α] (a : α) : ∀ᶠ x in at_bot, x ≤ a := mem_at_bot a lemma eventually_gt_at_top [preorder α] [no_top_order α] (a : α) : ∀ᶠ x in at_top, a < x := Ioi_mem_at_top a lemma eventually_lt_at_bot [preorder α] [no_bot_order α] (a : α) : ∀ᶠ x in at_bot, x < a := Iio_mem_at_bot a lemma at_top_basis_Ioi [nonempty α] [semilattice_sup α] [no_top_order α] : (@at_top α _).has_basis (λ _, true) Ioi := at_top_basis.to_has_basis (λ a ha, ⟨a, ha, Ioi_subset_Ici_self⟩) $ λ a ha, (no_top a).imp $ λ b hb, ⟨ha, Ici_subset_Ioi.2 hb⟩ lemma at_top_countable_basis [nonempty α] [semilattice_sup α] [encodable α] : has_countable_basis (at_top : filter α) (λ _, true) Ici := { countable := countable_encodable _, .. at_top_basis } lemma at_bot_countable_basis [nonempty α] [semilattice_inf α] [encodable α] : has_countable_basis (at_bot : filter α) (λ _, true) Iic := { countable := countable_encodable _, .. at_bot_basis } lemma is_countably_generated_at_top [nonempty α] [semilattice_sup α] [encodable α] : (at_top : filter $ α).is_countably_generated := at_top_countable_basis.is_countably_generated lemma is_countably_generated_at_bot [nonempty α] [semilattice_inf α] [encodable α] : (at_bot : filter $ α).is_countably_generated := at_bot_countable_basis.is_countably_generated lemma order_top.at_top_eq (α) [order_top α] : (at_top : filter α) = pure ⊤ := le_antisymm (le_pure_iff.2 $ (eventually_ge_at_top ⊤).mono $ λ b, top_unique) (le_infi $ λ b, le_principal_iff.2 le_top) lemma order_bot.at_bot_eq (α) [order_bot α] : (at_bot : filter α) = pure ⊥ := @order_top.at_top_eq (order_dual α) _ @[nontriviality] lemma subsingleton.at_top_eq (α) [subsingleton α] [preorder α] : (at_top : filter α) = ⊤ := begin refine top_unique (λ s hs x, _), letI : unique α := ⟨⟨x⟩, λ y, subsingleton.elim y x⟩, rw [at_top, infi_unique, unique.default_eq x, mem_principal_sets] at hs, exact hs left_mem_Ici end @[nontriviality] lemma subsingleton.at_bot_eq (α) [subsingleton α] [preorder α] : (at_bot : filter α) = ⊤ := subsingleton.at_top_eq (order_dual α) lemma tendsto_at_top_pure [order_top α] (f : α → β) : tendsto f at_top (pure $ f ⊤) := (order_top.at_top_eq α).symm ▸ tendsto_pure_pure _ _ lemma tendsto_at_bot_pure [order_bot α] (f : α → β) : tendsto f at_bot (pure $ f ⊥) := @tendsto_at_top_pure (order_dual α) _ _ _ lemma eventually.exists_forall_of_at_top [semilattice_sup α] [nonempty α] {p : α → Prop} (h : ∀ᶠ x in at_top, p x) : ∃ a, ∀ b ≥ a, p b := eventually_at_top.mp h lemma eventually.exists_forall_of_at_bot [semilattice_inf α] [nonempty α] {p : α → Prop} (h : ∀ᶠ x in at_bot, p x) : ∃ a, ∀ b ≤ a, p b := eventually_at_bot.mp h lemma frequently_at_top [semilattice_sup α] [nonempty α] {p : α → Prop} : (∃ᶠ x in at_top, p x) ↔ (∀ a, ∃ b ≥ a, p b) := by simp [at_top_basis.frequently_iff] lemma frequently_at_bot [semilattice_inf α] [nonempty α] {p : α → Prop} : (∃ᶠ x in at_bot, p x) ↔ (∀ a, ∃ b ≤ a, p b) := @frequently_at_top (order_dual α) _ _ _ lemma frequently_at_top' [semilattice_sup α] [nonempty α] [no_top_order α] {p : α → Prop} : (∃ᶠ x in at_top, p x) ↔ (∀ a, ∃ b > a, p b) := by simp [at_top_basis_Ioi.frequently_iff] lemma frequently_at_bot' [semilattice_inf α] [nonempty α] [no_bot_order α] {p : α → Prop} : (∃ᶠ x in at_bot, p x) ↔ (∀ a, ∃ b < a, p b) := @frequently_at_top' (order_dual α) _ _ _ _ lemma frequently.forall_exists_of_at_top [semilattice_sup α] [nonempty α] {p : α → Prop} (h : ∃ᶠ x in at_top, p x) : ∀ a, ∃ b ≥ a, p b := frequently_at_top.mp h lemma frequently.forall_exists_of_at_bot [semilattice_inf α] [nonempty α] {p : α → Prop} (h : ∃ᶠ x in at_bot, p x) : ∀ a, ∃ b ≤ a, p b := frequently_at_bot.mp h lemma map_at_top_eq [nonempty α] [semilattice_sup α] {f : α → β} : at_top.map f = (⨅a, 𝓟 $ f '' {a' | a ≤ a'}) := (at_top_basis.map _).eq_infi lemma map_at_bot_eq [nonempty α] [semilattice_inf α] {f : α → β} : at_bot.map f = (⨅a, 𝓟 $ f '' {a' | a' ≤ a}) := @map_at_top_eq (order_dual α) _ _ _ _ lemma tendsto_at_top [preorder β] {m : α → β} {f : filter α} : tendsto m f at_top ↔ (∀b, ∀ᶠ a in f, b ≤ m a) := by simp only [at_top, tendsto_infi, tendsto_principal, mem_Ici] lemma tendsto_at_bot [preorder β] {m : α → β} {f : filter α} : tendsto m f at_bot ↔ (∀b, ∀ᶠ a in f, m a ≤ b) := @tendsto_at_top α (order_dual β) _ m f lemma tendsto_at_top_mono' [preorder β] (l : filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂) : tendsto f₁ l at_top → tendsto f₂ l at_top := assume h₁, tendsto_at_top.2 $ λ b, mp_sets (tendsto_at_top.1 h₁ b) (monotone_mem_sets (λ a ha ha₁, le_trans ha₁ ha) h) lemma tendsto_at_bot_mono' [preorder β] (l : filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂) : tendsto f₂ l at_bot → tendsto f₁ l at_bot := @tendsto_at_top_mono' _ (order_dual β) _ _ _ _ h lemma tendsto_at_top_mono [preorder β] {l : filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) : tendsto f l at_top → tendsto g l at_top := tendsto_at_top_mono' l $ eventually_of_forall h lemma tendsto_at_bot_mono [preorder β] {l : filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) : tendsto g l at_bot → tendsto f l at_bot := @tendsto_at_top_mono _ (order_dual β) _ _ _ _ h /-! ### Sequences -/ lemma inf_map_at_top_ne_bot_iff [semilattice_sup α] [nonempty α] {F : filter β} {u : α → β} : ne_bot (F ⊓ (map u at_top)) ↔ ∀ U ∈ F, ∀ N, ∃ n ≥ N, u n ∈ U := by simp_rw [inf_ne_bot_iff_frequently_left, frequently_map, frequently_at_top]; refl lemma inf_map_at_bot_ne_bot_iff [semilattice_inf α] [nonempty α] {F : filter β} {u : α → β} : ne_bot (F ⊓ (map u at_bot)) ↔ ∀ U ∈ F, ∀ N, ∃ n ≤ N, u n ∈ U := @inf_map_at_top_ne_bot_iff (order_dual α) _ _ _ _ _ lemma extraction_of_frequently_at_top' {P : ℕ → Prop} (h : ∀ N, ∃ n > N, P n) : ∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P (φ n) := begin choose u hu using h, cases forall_and_distrib.mp hu with hu hu', exact ⟨u ∘ (nat.rec 0 (λ n v, u v)), strict_mono.nat (λ n, hu _), λ n, hu' _⟩, end lemma extraction_of_frequently_at_top {P : ℕ → Prop} (h : ∃ᶠ n in at_top, P n) : ∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P (φ n) := begin rw frequently_at_top' at h, exact extraction_of_frequently_at_top' h, end lemma extraction_of_eventually_at_top {P : ℕ → Prop} (h : ∀ᶠ n in at_top, P n) : ∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P (φ n) := extraction_of_frequently_at_top h.frequently lemma exists_le_of_tendsto_at_top [semilattice_sup α] [preorder β] {u : α → β} (h : tendsto u at_top at_top) (a : α) (b : β) : ∃ a' ≥ a, b ≤ u a' := begin have : ∀ᶠ x in at_top, a ≤ x ∧ b ≤ u x := (eventually_ge_at_top a).and (h.eventually $ eventually_ge_at_top b), haveI : nonempty α := ⟨a⟩, rcases this.exists with ⟨a', ha, hb⟩, exact ⟨a', ha, hb⟩ end @[nolint ge_or_gt] -- see Note [nolint_ge] lemma exists_le_of_tendsto_at_bot [semilattice_sup α] [preorder β] {u : α → β} (h : tendsto u at_top at_bot) : ∀ a b, ∃ a' ≥ a, u a' ≤ b := @exists_le_of_tendsto_at_top _ (order_dual β) _ _ _ h lemma exists_lt_of_tendsto_at_top [semilattice_sup α] [preorder β] [no_top_order β] {u : α → β} (h : tendsto u at_top at_top) (a : α) (b : β) : ∃ a' ≥ a, b < u a' := begin cases no_top b with b' hb', rcases exists_le_of_tendsto_at_top h a b' with ⟨a', ha', ha''⟩, exact ⟨a', ha', lt_of_lt_of_le hb' ha''⟩ end @[nolint ge_or_gt] -- see Note [nolint_ge] lemma exists_lt_of_tendsto_at_bot [semilattice_sup α] [preorder β] [no_bot_order β] {u : α → β} (h : tendsto u at_top at_bot) : ∀ a b, ∃ a' ≥ a, u a' < b := @exists_lt_of_tendsto_at_top _ (order_dual β) _ _ _ _ h /-- If `u` is a sequence which is unbounded above, then after any point, it reaches a value strictly greater than all previous values. -/ lemma high_scores [linear_order β] [no_top_order β] {u : ℕ → β} (hu : tendsto u at_top at_top) : ∀ N, ∃ n ≥ N, ∀ k < n, u k < u n := begin intros N, let A := finset.image u (finset.range $ N+1), -- A = {u 0, ..., u N} have Ane : A.nonempty, from ⟨u 0, finset.mem_image_of_mem _ (finset.mem_range.mpr $ nat.zero_lt_succ _)⟩, let M := finset.max' A Ane, have ex : ∃ n ≥ N, M < u n, from exists_lt_of_tendsto_at_top hu _ _, obtain ⟨n, hnN, hnM, hn_min⟩ : ∃ n, N ≤ n ∧ M < u n ∧ ∀ k, N ≤ k → k < n → u k ≤ M, { use nat.find ex, rw ← and_assoc, split, { simpa using nat.find_spec ex }, { intros k hk hk', simpa [hk] using nat.find_min ex hk' } }, use [n, hnN], intros k hk, by_cases H : k ≤ N, { have : u k ∈ A, from finset.mem_image_of_mem _ (finset.mem_range.mpr $ nat.lt_succ_of_le H), have : u k ≤ M, from finset.le_max' A (u k) this, exact lt_of_le_of_lt this hnM }, { push_neg at H, calc u k ≤ M : hn_min k (le_of_lt H) hk ... < u n : hnM }, end /-- If `u` is a sequence which is unbounded below, then after any point, it reaches a value strictly smaller than all previous values. -/ @[nolint ge_or_gt] -- see Note [nolint_ge] lemma low_scores [linear_order β] [no_bot_order β] {u : ℕ → β} (hu : tendsto u at_top at_bot) : ∀ N, ∃ n ≥ N, ∀ k < n, u n < u k := @high_scores (order_dual β) _ _ _ hu /-- If `u` is a sequence which is unbounded above, then it `frequently` reaches a value strictly greater than all previous values. -/ lemma frequently_high_scores [linear_order β] [no_top_order β] {u : ℕ → β} (hu : tendsto u at_top at_top) : ∃ᶠ n in at_top, ∀ k < n, u k < u n := by simpa [frequently_at_top] using high_scores hu /-- If `u` is a sequence which is unbounded below, then it `frequently` reaches a value strictly smaller than all previous values. -/ lemma frequently_low_scores [linear_order β] [no_bot_order β] {u : ℕ → β} (hu : tendsto u at_top at_bot) : ∃ᶠ n in at_top, ∀ k < n, u n < u k := @frequently_high_scores (order_dual β) _ _ _ hu lemma strict_mono_subseq_of_tendsto_at_top {β : Type*} [linear_order β] [no_top_order β] {u : ℕ → β} (hu : tendsto u at_top at_top) : ∃ φ : ℕ → ℕ, strict_mono φ ∧ strict_mono (u ∘ φ) := let ⟨φ, h, h'⟩ := extraction_of_frequently_at_top (frequently_high_scores hu) in ⟨φ, h, λ n m hnm, h' m _ (h hnm)⟩ lemma strict_mono_subseq_of_id_le {u : ℕ → ℕ} (hu : ∀ n, n ≤ u n) : ∃ φ : ℕ → ℕ, strict_mono φ ∧ strict_mono (u ∘ φ) := strict_mono_subseq_of_tendsto_at_top (tendsto_at_top_mono hu tendsto_id) lemma strict_mono_tendsto_at_top {φ : ℕ → ℕ} (h : strict_mono φ) : tendsto φ at_top at_top := tendsto_at_top_mono h.id_le tendsto_id section ordered_add_comm_monoid variables [ordered_add_comm_monoid β] {l : filter α} {f g : α → β} lemma tendsto_at_top_add_nonneg_left' (hf : ∀ᶠ x in l, 0 ≤ f x) (hg : tendsto g l at_top) : tendsto (λ x, f x + g x) l at_top := tendsto_at_top_mono' l (hf.mono (λ x, le_add_of_nonneg_left)) hg lemma tendsto_at_bot_add_nonpos_left' (hf : ∀ᶠ x in l, f x ≤ 0) (hg : tendsto g l at_bot) : tendsto (λ x, f x + g x) l at_bot := @tendsto_at_top_add_nonneg_left' _ (order_dual β) _ _ _ _ hf hg lemma tendsto_at_top_add_nonneg_left (hf : ∀ x, 0 ≤ f x) (hg : tendsto g l at_top) : tendsto (λ x, f x + g x) l at_top := tendsto_at_top_add_nonneg_left' (eventually_of_forall hf) hg lemma tendsto_at_bot_add_nonpos_left (hf : ∀ x, f x ≤ 0) (hg : tendsto g l at_bot) : tendsto (λ x, f x + g x) l at_bot := @tendsto_at_top_add_nonneg_left _ (order_dual β) _ _ _ _ hf hg lemma tendsto_at_top_add_nonneg_right' (hf : tendsto f l at_top) (hg : ∀ᶠ x in l, 0 ≤ g x) : tendsto (λ x, f x + g x) l at_top := tendsto_at_top_mono' l (monotone_mem_sets (λ x, le_add_of_nonneg_right) hg) hf lemma tendsto_at_bot_add_nonpos_right' (hf : tendsto f l at_bot) (hg : ∀ᶠ x in l, g x ≤ 0) : tendsto (λ x, f x + g x) l at_bot := @tendsto_at_top_add_nonneg_right' _ (order_dual β) _ _ _ _ hf hg lemma tendsto_at_top_add_nonneg_right (hf : tendsto f l at_top) (hg : ∀ x, 0 ≤ g x) : tendsto (λ x, f x + g x) l at_top := tendsto_at_top_add_nonneg_right' hf (eventually_of_forall hg) lemma tendsto_at_bot_add_nonpos_right (hf : tendsto f l at_bot) (hg : ∀ x, g x ≤ 0) : tendsto (λ x, f x + g x) l at_bot := @tendsto_at_top_add_nonneg_right _ (order_dual β) _ _ _ _ hf hg lemma tendsto_at_top_add (hf : tendsto f l at_top) (hg : tendsto g l at_top) : tendsto (λ x, f x + g x) l at_top := tendsto_at_top_add_nonneg_left' (tendsto_at_top.mp hf 0) hg lemma tendsto_at_bot_add (hf : tendsto f l at_bot) (hg : tendsto g l at_bot) : tendsto (λ x, f x + g x) l at_bot := @tendsto_at_top_add _ (order_dual β) _ _ _ _ hf hg lemma tendsto.nsmul_at_top (hf : tendsto f l at_top) {n : ℕ} (hn : 0 < n) : tendsto (λ x, n •ℕ f x) l at_top := tendsto_at_top.2 $ λ y, (tendsto_at_top.1 hf y).mp $ (tendsto_at_top.1 hf 0).mono $ λ x h₀ hy, calc y ≤ f x : hy ... = 1 •ℕ f x : (one_nsmul _).symm ... ≤ n •ℕ f x : nsmul_le_nsmul h₀ hn lemma tendsto.nsmul_at_bot (hf : tendsto f l at_bot) {n : ℕ} (hn : 0 < n) : tendsto (λ x, n •ℕ f x) l at_bot := @tendsto.nsmul_at_top α (order_dual β) _ l f hf n hn lemma tendsto_bit0_at_top : tendsto bit0 (at_top : filter β) at_top := tendsto_at_top_add tendsto_id tendsto_id lemma tendsto_bit0_at_bot : tendsto bit0 (at_bot : filter β) at_bot := tendsto_at_bot_add tendsto_id tendsto_id end ordered_add_comm_monoid section ordered_cancel_add_comm_monoid variables [ordered_cancel_add_comm_monoid β] {l : filter α} {f g : α → β} lemma tendsto_at_top_of_add_const_left (C : β) (hf : tendsto (λ x, C + f x) l at_top) : tendsto f l at_top := tendsto_at_top.2 $ assume b, (tendsto_at_top.1 hf (C + b)).mono (λ x, le_of_add_le_add_left) lemma tendsto_at_bot_of_add_const_left (C : β) (hf : tendsto (λ x, C + f x) l at_bot) : tendsto f l at_bot := @tendsto_at_top_of_add_const_left _ (order_dual β) _ _ _ C hf lemma tendsto_at_top_of_add_const_right (C : β) (hf : tendsto (λ x, f x + C) l at_top) : tendsto f l at_top := tendsto_at_top.2 $ assume b, (tendsto_at_top.1 hf (b + C)).mono (λ x, le_of_add_le_add_right) lemma tendsto_at_bot_of_add_const_right (C : β) (hf : tendsto (λ x, f x + C) l at_bot) : tendsto f l at_bot := @tendsto_at_top_of_add_const_right _ (order_dual β) _ _ _ C hf lemma tendsto_at_top_of_add_bdd_above_left' (C) (hC : ∀ᶠ x in l, f x ≤ C) (h : tendsto (λ x, f x + g x) l at_top) : tendsto g l at_top := tendsto_at_top_of_add_const_left C (tendsto_at_top_mono' l (hC.mono (λ x hx, add_le_add_right hx (g x))) h) lemma tendsto_at_bot_of_add_bdd_below_left' (C) (hC : ∀ᶠ x in l, C ≤ f x) (h : tendsto (λ x, f x + g x) l at_bot) : tendsto g l at_bot := @tendsto_at_top_of_add_bdd_above_left' _ (order_dual β) _ _ _ _ C hC h lemma tendsto_at_top_of_add_bdd_above_left (C) (hC : ∀ x, f x ≤ C) : tendsto (λ x, f x + g x) l at_top → tendsto g l at_top := tendsto_at_top_of_add_bdd_above_left' C (univ_mem_sets' hC) lemma tendsto_at_bot_of_add_bdd_below_left (C) (hC : ∀ x, C ≤ f x) : tendsto (λ x, f x + g x) l at_bot → tendsto g l at_bot := @tendsto_at_top_of_add_bdd_above_left _ (order_dual β) _ _ _ _ C hC lemma tendsto_at_top_of_add_bdd_above_right' (C) (hC : ∀ᶠ x in l, g x ≤ C) (h : tendsto (λ x, f x + g x) l at_top) : tendsto f l at_top := tendsto_at_top_of_add_const_right C (tendsto_at_top_mono' l (hC.mono (λ x hx, add_le_add_left hx (f x))) h) lemma tendsto_at_bot_of_add_bdd_below_right' (C) (hC : ∀ᶠ x in l, C ≤ g x) (h : tendsto (λ x, f x + g x) l at_bot) : tendsto f l at_bot := @tendsto_at_top_of_add_bdd_above_right' _ (order_dual β) _ _ _ _ C hC h lemma tendsto_at_top_of_add_bdd_above_right (C) (hC : ∀ x, g x ≤ C) : tendsto (λ x, f x + g x) l at_top → tendsto f l at_top := tendsto_at_top_of_add_bdd_above_right' C (univ_mem_sets' hC) lemma tendsto_at_bot_of_add_bdd_below_right (C) (hC : ∀ x, C ≤ g x) : tendsto (λ x, f x + g x) l at_bot → tendsto f l at_bot := @tendsto_at_top_of_add_bdd_above_right _ (order_dual β) _ _ _ _ C hC end ordered_cancel_add_comm_monoid section ordered_group variables [ordered_add_comm_group β] (l : filter α) {f g : α → β} lemma tendsto_at_top_add_left_of_le' (C : β) (hf : ∀ᶠ x in l, C ≤ f x) (hg : tendsto g l at_top) : tendsto (λ x, f x + g x) l at_top := @tendsto_at_top_of_add_bdd_above_left' _ _ _ l (λ x, -(f x)) (λ x, f x + g x) (-C) (by simpa) (by simpa) lemma tendsto_at_bot_add_left_of_ge' (C : β) (hf : ∀ᶠ x in l, f x ≤ C) (hg : tendsto g l at_bot) : tendsto (λ x, f x + g x) l at_bot := @tendsto_at_top_add_left_of_le' _ (order_dual β) _ _ _ _ C hf hg lemma tendsto_at_top_add_left_of_le (C : β) (hf : ∀ x, C ≤ f x) (hg : tendsto g l at_top) : tendsto (λ x, f x + g x) l at_top := tendsto_at_top_add_left_of_le' l C (univ_mem_sets' hf) hg lemma tendsto_at_bot_add_left_of_ge (C : β) (hf : ∀ x, f x ≤ C) (hg : tendsto g l at_bot) : tendsto (λ x, f x + g x) l at_bot := @tendsto_at_top_add_left_of_le _ (order_dual β) _ _ _ _ C hf hg lemma tendsto_at_top_add_right_of_le' (C : β) (hf : tendsto f l at_top) (hg : ∀ᶠ x in l, C ≤ g x) : tendsto (λ x, f x + g x) l at_top := @tendsto_at_top_of_add_bdd_above_right' _ _ _ l (λ x, f x + g x) (λ x, -(g x)) (-C) (by simp [hg]) (by simp [hf]) lemma tendsto_at_bot_add_right_of_ge' (C : β) (hf : tendsto f l at_bot) (hg : ∀ᶠ x in l, g x ≤ C) : tendsto (λ x, f x + g x) l at_bot := @tendsto_at_top_add_right_of_le' _ (order_dual β) _ _ _ _ C hf hg lemma tendsto_at_top_add_right_of_le (C : β) (hf : tendsto f l at_top) (hg : ∀ x, C ≤ g x) : tendsto (λ x, f x + g x) l at_top := tendsto_at_top_add_right_of_le' l C hf (univ_mem_sets' hg) lemma tendsto_at_bot_add_right_of_ge (C : β) (hf : tendsto f l at_bot) (hg : ∀ x, g x ≤ C) : tendsto (λ x, f x + g x) l at_bot := @tendsto_at_top_add_right_of_le _ (order_dual β) _ _ _ _ C hf hg lemma tendsto_at_top_add_const_left (C : β) (hf : tendsto f l at_top) : tendsto (λ x, C + f x) l at_top := tendsto_at_top_add_left_of_le' l C (univ_mem_sets' $ λ _, le_refl C) hf lemma tendsto_at_bot_add_const_left (C : β) (hf : tendsto f l at_bot) : tendsto (λ x, C + f x) l at_bot := @tendsto_at_top_add_const_left _ (order_dual β) _ _ _ C hf lemma tendsto_at_top_add_const_right (C : β) (hf : tendsto f l at_top) : tendsto (λ x, f x + C) l at_top := tendsto_at_top_add_right_of_le' l C hf (univ_mem_sets' $ λ _, le_refl C) lemma tendsto_at_bot_add_const_right (C : β) (hf : tendsto f l at_bot) : tendsto (λ x, f x + C) l at_bot := @tendsto_at_top_add_const_right _ (order_dual β) _ _ _ C hf lemma tendsto_neg_at_top_at_bot : tendsto (has_neg.neg : β → β) at_top at_bot := begin simp only [tendsto_at_bot, neg_le], exact λ b, eventually_ge_at_top _ end lemma tendsto_neg_at_bot_at_top : tendsto (has_neg.neg : β → β) at_bot at_top := @tendsto_neg_at_top_at_bot (order_dual β) _ end ordered_group section ordered_semiring variables [ordered_semiring α] {l : filter β} {f g : β → α} lemma tendsto_bit1_at_top : tendsto bit1 (at_top : filter α) at_top := tendsto_at_top_add_nonneg_right tendsto_bit0_at_top (λ _, zero_le_one) lemma tendsto.at_top_mul_at_top (hf : tendsto f l at_top) (hg : tendsto g l at_top) : tendsto (λ x, f x * g x) l at_top := begin refine tendsto_at_top_mono' _ _ hg, filter_upwards [hg.eventually (eventually_ge_at_top 0), hf.eventually (eventually_ge_at_top 1)], exact λ x, le_mul_of_one_le_left end lemma tendsto_mul_self_at_top : tendsto (λ x : α, x * x) at_top at_top := tendsto_id.at_top_mul_at_top tendsto_id /-- The monomial function `x^n` tends to `+∞` at `+∞` for any positive natural `n`. A version for positive real powers exists as `tendsto_rpow_at_top`. -/ lemma tendsto_pow_at_top {n : ℕ} (hn : 1 ≤ n) : tendsto (λ x : α, x ^ n) at_top at_top := begin refine tendsto_at_top_mono' _ ((eventually_ge_at_top 1).mono $ λ x hx, _) tendsto_id, simpa only [pow_one] using pow_le_pow hx hn end end ordered_semiring lemma zero_pow_eventually_eq [monoid_with_zero α] : (λ n : ℕ, (0 : α) ^ n) =ᶠ[at_top] (λ n, 0) := eventually_at_top.2 ⟨1, λ n hn, zero_pow (zero_lt_one.trans_le hn)⟩ section ordered_ring variables [ordered_ring α] {l : filter β} {f g : β → α} lemma tendsto.at_top_mul_at_bot (hf : tendsto f l at_top) (hg : tendsto g l at_bot) : tendsto (λ x, f x * g x) l at_bot := have _ := (hf.at_top_mul_at_top $ tendsto_neg_at_bot_at_top.comp hg), by simpa only [(∘), neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_at_top_at_bot.comp this lemma tendsto.at_bot_mul_at_top (hf : tendsto f l at_bot) (hg : tendsto g l at_top) : tendsto (λ x, f x * g x) l at_bot := have tendsto (λ x, (-f x) * g x) l at_top := ( (tendsto_neg_at_bot_at_top.comp hf).at_top_mul_at_top hg), by simpa only [(∘), neg_mul_eq_neg_mul, neg_neg] using tendsto_neg_at_top_at_bot.comp this lemma tendsto.at_bot_mul_at_bot (hf : tendsto f l at_bot) (hg : tendsto g l at_bot) : tendsto (λ x, f x * g x) l at_top := have tendsto (λ x, (-f x) * (-g x)) l at_top := (tendsto_neg_at_bot_at_top.comp hf).at_top_mul_at_top (tendsto_neg_at_bot_at_top.comp hg), by simpa only [neg_mul_neg] using this end ordered_ring section linear_ordered_add_comm_group variables [linear_ordered_add_comm_group α] /-- $\lim_{x\to+\infty}|x|=+\infty$ -/ lemma tendsto_abs_at_top_at_top : tendsto (abs : α → α) at_top at_top := tendsto_at_top_mono le_abs_self tendsto_id /-- $\lim_{x\to-\infty}|x|=+\infty$ -/ lemma tendsto_abs_at_bot_at_top : tendsto (abs : α → α) at_bot at_top := tendsto_at_top_mono neg_le_abs_self tendsto_neg_at_bot_at_top end linear_ordered_add_comm_group section linear_ordered_semiring variables [linear_ordered_semiring α] {l : filter β} {f : β → α} lemma tendsto.at_top_of_const_mul {c : α} (hc : 0 < c) (hf : tendsto (λ x, c * f x) l at_top) : tendsto f l at_top := tendsto_at_top.2 $ λ b, (tendsto_at_top.1 hf (c * b)).mono $ λ x hx, le_of_mul_le_mul_left hx hc lemma tendsto.at_top_of_mul_const {c : α} (hc : 0 < c) (hf : tendsto (λ x, f x * c) l at_top) : tendsto f l at_top := tendsto_at_top.2 $ λ b, (tendsto_at_top.1 hf (b * c)).mono $ λ x hx, le_of_mul_le_mul_right hx hc end linear_ordered_semiring lemma nonneg_of_eventually_pow_nonneg [linear_ordered_ring α] {a : α} (h : ∀ᶠ n in at_top, 0 ≤ a ^ (n : ℕ)) : 0 ≤ a := let ⟨n, hn⟩ := (tendsto_bit1_at_top.eventually h).exists in pow_bit1_nonneg_iff.1 hn section linear_ordered_field variables [linear_ordered_field α] {l : filter β} {f : β → α} {r : α} /-- If a function tends to infinity along a filter, then this function multiplied by a positive constant (on the left) also tends to infinity. For a version working in `ℕ` or `ℤ`, use `filter.tendsto.const_mul_at_top'` instead. -/ lemma tendsto.const_mul_at_top (hr : 0 < r) (hf : tendsto f l at_top) : tendsto (λx, r * f x) l at_top := tendsto.at_top_of_const_mul (inv_pos.2 hr) $ by simpa only [inv_mul_cancel_left' hr.ne'] /-- If a function tends to infinity along a filter, then this function multiplied by a positive constant (on the right) also tends to infinity. For a version working in `ℕ` or `ℤ`, use `filter.tendsto.at_top_mul_const'` instead. -/ lemma tendsto.at_top_mul_const (hr : 0 < r) (hf : tendsto f l at_top) : tendsto (λx, f x * r) l at_top := by simpa only [mul_comm] using hf.const_mul_at_top hr /-- If a function tends to infinity along a filter, then this function divided by a positive constant also tends to infinity. -/ lemma tendsto.at_top_div_const (hr : 0 < r) (hf : tendsto f l at_top) : tendsto (λx, f x / r) l at_top := by simpa only [div_eq_mul_inv] using hf.at_top_mul_const (inv_pos.2 hr) /-- If a function tends to infinity along a filter, then this function multiplied by a negative constant (on the left) tends to negative infinity. -/ lemma tendsto.neg_const_mul_at_top (hr : r < 0) (hf : tendsto f l at_top) : tendsto (λ x, r * f x) l at_bot := by simpa only [(∘), neg_mul_eq_neg_mul, neg_neg] using tendsto_neg_at_top_at_bot.comp (hf.const_mul_at_top (neg_pos.2 hr)) /-- If a function tends to infinity along a filter, then this function multiplied by a negative constant (on the right) tends to negative infinity. -/ lemma tendsto.at_top_mul_neg_const (hr : r < 0) (hf : tendsto f l at_top) : tendsto (λ x, f x * r) l at_bot := by simpa only [mul_comm] using hf.neg_const_mul_at_top hr /-- If a function tends to negative infinity along a filter, then this function multiplied by a positive constant (on the left) also tends to negative infinity. -/ lemma tendsto.const_mul_at_bot (hr : 0 < r) (hf : tendsto f l at_bot) : tendsto (λx, r * f x) l at_bot := by simpa only [(∘), neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_at_top_at_bot.comp ((tendsto_neg_at_bot_at_top.comp hf).const_mul_at_top hr) /-- If a function tends to negative infinity along a filter, then this function multiplied by a positive constant (on the right) also tends to negative infinity. -/ lemma tendsto.at_bot_mul_const (hr : 0 < r) (hf : tendsto f l at_bot) : tendsto (λx, f x * r) l at_bot := by simpa only [mul_comm] using hf.const_mul_at_bot hr /-- If a function tends to negative infinity along a filter, then this function divided by a positive constant also tends to negative infinity. -/ lemma tendsto.at_bot_div_const (hr : 0 < r) (hf : tendsto f l at_bot) : tendsto (λx, f x / r) l at_bot := by simpa only [div_eq_mul_inv] using hf.at_bot_mul_const (inv_pos.2 hr) /-- If a function tends to negative infinity along a filter, then this function multiplied by a negative constant (on the left) tends to positive infinity. -/ lemma tendsto.neg_const_mul_at_bot (hr : r < 0) (hf : tendsto f l at_bot) : tendsto (λ x, r * f x) l at_top := by simpa only [(∘), neg_mul_eq_neg_mul, neg_neg] using tendsto_neg_at_bot_at_top.comp (hf.const_mul_at_bot (neg_pos.2 hr)) /-- If a function tends to negative infinity along a filter, then this function multiplied by a negative constant (on the right) tends to positive infinity. -/ lemma tendsto.at_bot_mul_neg_const (hr : r < 0) (hf : tendsto f l at_bot) : tendsto (λ x, f x * r) l at_top := by simpa only [mul_comm] using hf.neg_const_mul_at_bot hr lemma tendsto_const_mul_pow_at_top {c : α} {n : ℕ} (hn : 1 ≤ n) (hc : 0 < c) : tendsto (λ x, c * x^n) at_top at_top := tendsto.const_mul_at_top hc (tendsto_pow_at_top hn) lemma tendsto_neg_const_mul_pow_at_top {c : α} {n : ℕ} (hn : 1 ≤ n) (hc : c < 0) : tendsto (λ x, c * x^n) at_top at_bot := tendsto.neg_const_mul_at_top hc (tendsto_pow_at_top hn) end linear_ordered_field open_locale filter lemma tendsto_at_top' [nonempty α] [semilattice_sup α] {f : α → β} {l : filter β} : tendsto f at_top l ↔ (∀s ∈ l, ∃a, ∀b≥a, f b ∈ s) := by simp only [tendsto_def, mem_at_top_sets]; refl lemma tendsto_at_bot' [nonempty α] [semilattice_inf α] {f : α → β} {l : filter β} : tendsto f at_bot l ↔ (∀s ∈ l, ∃a, ∀b≤a, f b ∈ s) := @tendsto_at_top' (order_dual α) _ _ _ _ _ theorem tendsto_at_top_principal [nonempty β] [semilattice_sup β] {f : β → α} {s : set α} : tendsto f at_top (𝓟 s) ↔ ∃N, ∀n≥N, f n ∈ s := by rw [tendsto_iff_comap, comap_principal, le_principal_iff, mem_at_top_sets]; refl theorem tendsto_at_bot_principal [nonempty β] [semilattice_inf β] {f : β → α} {s : set α} : tendsto f at_bot (𝓟 s) ↔ ∃N, ∀n≤N, f n ∈ s := @tendsto_at_top_principal _ (order_dual β) _ _ _ _ /-- A function `f` grows to `+∞` independent of an order-preserving embedding `e`. -/ lemma tendsto_at_top_at_top [nonempty α] [semilattice_sup α] [preorder β] {f : α → β} : tendsto f at_top at_top ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → b ≤ f a := iff.trans tendsto_infi $ forall_congr $ assume b, tendsto_at_top_principal lemma tendsto_at_top_at_bot [nonempty α] [semilattice_sup α] [preorder β] {f : α → β} : tendsto f at_top at_bot ↔ ∀ (b : β), ∃ (i : α), ∀ (a : α), i ≤ a → f a ≤ b := @tendsto_at_top_at_top α (order_dual β) _ _ _ f lemma tendsto_at_bot_at_top [nonempty α] [semilattice_inf α] [preorder β] {f : α → β} : tendsto f at_bot at_top ↔ ∀ (b : β), ∃ (i : α), ∀ (a : α), a ≤ i → b ≤ f a := @tendsto_at_top_at_top (order_dual α) β _ _ _ f lemma tendsto_at_bot_at_bot [nonempty α] [semilattice_inf α] [preorder β] {f : α → β} : tendsto f at_bot at_bot ↔ ∀ (b : β), ∃ (i : α), ∀ (a : α), a ≤ i → f a ≤ b := @tendsto_at_top_at_top (order_dual α) (order_dual β) _ _ _ f lemma tendsto_at_top_at_top_of_monotone [preorder α] [preorder β] {f : α → β} (hf : monotone f) (h : ∀ b, ∃ a, b ≤ f a) : tendsto f at_top at_top := tendsto_infi.2 $ λ b, tendsto_principal.2 $ let ⟨a, ha⟩ := h b in mem_sets_of_superset (mem_at_top a) $ λ a' ha', le_trans ha (hf ha') lemma tendsto_at_bot_at_bot_of_monotone [preorder α] [preorder β] {f : α → β} (hf : monotone f) (h : ∀ b, ∃ a, f a ≤ b) : tendsto f at_bot at_bot := tendsto_infi.2 $ λ b, tendsto_principal.2 $ let ⟨a, ha⟩ := h b in mem_sets_of_superset (mem_at_bot a) $ λ a' ha', le_trans (hf ha') ha lemma tendsto_at_top_at_top_iff_of_monotone [nonempty α] [semilattice_sup α] [preorder β] {f : α → β} (hf : monotone f) : tendsto f at_top at_top ↔ ∀ b : β, ∃ a : α, b ≤ f a := tendsto_at_top_at_top.trans $ forall_congr $ λ b, exists_congr $ λ a, ⟨λ h, h a (le_refl a), λ h a' ha', le_trans h $ hf ha'⟩ lemma tendsto_at_bot_at_bot_iff_of_monotone [nonempty α] [semilattice_inf α] [preorder β] {f : α → β} (hf : monotone f) : tendsto f at_bot at_bot ↔ ∀ b : β, ∃ a : α, f a ≤ b := tendsto_at_bot_at_bot.trans $ forall_congr $ λ b, exists_congr $ λ a, ⟨λ h, h a (le_refl a), λ h a' ha', le_trans (hf ha') h⟩ alias tendsto_at_top_at_top_of_monotone ← monotone.tendsto_at_top_at_top alias tendsto_at_bot_at_bot_of_monotone ← monotone.tendsto_at_bot_at_bot alias tendsto_at_top_at_top_iff_of_monotone ← monotone.tendsto_at_top_at_top_iff alias tendsto_at_bot_at_bot_iff_of_monotone ← monotone.tendsto_at_bot_at_bot_iff lemma tendsto_at_top_embedding [preorder β] [preorder γ] {f : α → β} {e : β → γ} {l : filter α} (hm : ∀b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀c, ∃b, c ≤ e b) : tendsto (e ∘ f) l at_top ↔ tendsto f l at_top := begin refine ⟨_, (tendsto_at_top_at_top_of_monotone (λ b₁ b₂, (hm b₁ b₂).2) hu).comp⟩, rw [tendsto_at_top, tendsto_at_top], exact λ hc b, (hc (e b)).mono (λ a, (hm b (f a)).1) end /-- A function `f` goes to `-∞` independent of an order-preserving embedding `e`. -/ lemma tendsto_at_bot_embedding [preorder β] [preorder γ] {f : α → β} {e : β → γ} {l : filter α} (hm : ∀b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀c, ∃b, e b ≤ c) : tendsto (e ∘ f) l at_bot ↔ tendsto f l at_bot := @tendsto_at_top_embedding α (order_dual β) (order_dual γ) _ _ f e l (function.swap hm) hu lemma tendsto_finset_range : tendsto finset.range at_top at_top := finset.range_mono.tendsto_at_top_at_top finset.exists_nat_subset_range lemma at_top_finset_eq_infi : (at_top : filter $ finset α) = ⨅ x : α, 𝓟 (Ici {x}) := begin refine le_antisymm (le_infi (λ i, le_principal_iff.2 $ mem_at_top {i})) _, refine le_infi (λ s, le_principal_iff.2 $ mem_infi_iff.2 _), refine ⟨↑s, s.finite_to_set, _, λ i, mem_principal_self _, _⟩, simp only [subset_def, mem_Inter, set_coe.forall, mem_Ici, finset.le_iff_subset, finset.mem_singleton, finset.subset_iff, forall_eq], dsimp, exact λ t, id end /-- If `f` is a monotone sequence of `finset`s and each `x` belongs to one of `f n`, then `tendsto f at_top at_top`. -/ lemma tendsto_at_top_finset_of_monotone [preorder β] {f : β → finset α} (h : monotone f) (h' : ∀ x : α, ∃ n, x ∈ f n) : tendsto f at_top at_top := begin simp only [at_top_finset_eq_infi, tendsto_infi, tendsto_principal], intro a, rcases h' a with ⟨b, hb⟩, exact eventually.mono (mem_at_top b) (λ b' hb', le_trans (finset.singleton_subset_iff.2 hb) (h hb')), end alias tendsto_at_top_finset_of_monotone ← monotone.tendsto_at_top_finset lemma tendsto_finset_image_at_top_at_top {i : β → γ} {j : γ → β} (h : function.left_inverse j i) : tendsto (finset.image j) at_top at_top := (finset.image_mono j).tendsto_at_top_finset $ assume a, ⟨{i a}, by simp only [finset.image_singleton, h a, finset.mem_singleton]⟩ lemma tendsto_finset_preimage_at_top_at_top {f : α → β} (hf : function.injective f) : tendsto (λ s : finset β, s.preimage f (hf.inj_on _)) at_top at_top := (finset.monotone_preimage hf).tendsto_at_top_finset $ λ x, ⟨{f x}, finset.mem_preimage.2 $ finset.mem_singleton_self _⟩ lemma prod_at_top_at_top_eq {β₁ β₂ : Type*} [semilattice_sup β₁] [semilattice_sup β₂] : (at_top : filter β₁) ×ᶠ (at_top : filter β₂) = (at_top : filter (β₁ × β₂)) := begin by_cases ne : nonempty β₁ ∧ nonempty β₂, { cases ne, resetI, simp [at_top, prod_infi_left, prod_infi_right, infi_prod], exact infi_comm }, { rw not_and_distrib at ne, cases ne; { have : ¬ (nonempty (β₁ × β₂)), by simp [ne], rw [at_top.filter_eq_bot_of_not_nonempty ne, at_top.filter_eq_bot_of_not_nonempty this], simp only [bot_prod, prod_bot] } } end lemma prod_at_bot_at_bot_eq {β₁ β₂ : Type*} [semilattice_inf β₁] [semilattice_inf β₂] : (at_bot : filter β₁) ×ᶠ (at_bot : filter β₂) = (at_bot : filter (β₁ × β₂)) := @prod_at_top_at_top_eq (order_dual β₁) (order_dual β₂) _ _ lemma prod_map_at_top_eq {α₁ α₂ β₁ β₂ : Type*} [semilattice_sup β₁] [semilattice_sup β₂] (u₁ : β₁ → α₁) (u₂ : β₂ → α₂) : (map u₁ at_top) ×ᶠ (map u₂ at_top) = map (prod.map u₁ u₂) at_top := by rw [prod_map_map_eq, prod_at_top_at_top_eq, prod.map_def] lemma prod_map_at_bot_eq {α₁ α₂ β₁ β₂ : Type*} [semilattice_inf β₁] [semilattice_inf β₂] (u₁ : β₁ → α₁) (u₂ : β₂ → α₂) : (map u₁ at_bot) ×ᶠ (map u₂ at_bot) = map (prod.map u₁ u₂) at_bot := @prod_map_at_top_eq _ _ (order_dual β₁) (order_dual β₂) _ _ _ _ /-- A function `f` maps upwards closed sets (at_top sets) to upwards closed sets when it is a Galois insertion. The Galois "insertion" and "connection" is weakened to only require it to be an insertion and a connetion above `b'`. -/ lemma map_at_top_eq_of_gc [semilattice_sup α] [semilattice_sup β] {f : α → β} (g : β → α) (b' : β) (hf : monotone f) (gc : ∀a, ∀b≥b', f a ≤ b ↔ a ≤ g b) (hgi : ∀b≥b', b ≤ f (g b)) : map f at_top = at_top := begin refine le_antisymm (hf.tendsto_at_top_at_top $ λ b, ⟨g (b ⊔ b'), le_sup_left.trans $ hgi _ le_sup_right⟩) _, rw [@map_at_top_eq _ _ ⟨g b'⟩], refine le_infi (λ a, infi_le_of_le (f a ⊔ b') $ principal_mono.2 $ λ b hb, _), rw [mem_Ici, sup_le_iff] at hb, exact ⟨g b, (gc _ _ hb.2).1 hb.1, le_antisymm ((gc _ _ hb.2).2 (le_refl _)) (hgi _ hb.2)⟩ end lemma map_at_bot_eq_of_gc [semilattice_inf α] [semilattice_inf β] {f : α → β} (g : β → α) (b' : β) (hf : monotone f) (gc : ∀a, ∀b≤b', b ≤ f a ↔ g b ≤ a) (hgi : ∀b≤b', f (g b) ≤ b) : map f at_bot = at_bot := @map_at_top_eq_of_gc (order_dual α) (order_dual β) _ _ _ _ _ hf.order_dual gc hgi lemma map_coe_at_top_of_Ici_subset [semilattice_sup α] {a : α} {s : set α} (h : Ici a ⊆ s) : map (coe : s → α) at_top = at_top := begin have : directed (≥) (λ x : s, 𝓟 (Ici x)), { intros x y, use ⟨x ⊔ y ⊔ a, h le_sup_right⟩, simp only [ge_iff_le, principal_mono, Ici_subset_Ici, ← subtype.coe_le_coe, subtype.coe_mk], exact ⟨le_sup_left.trans le_sup_left, le_sup_right.trans le_sup_left⟩ }, haveI : nonempty s := ⟨⟨a, h le_rfl⟩⟩, simp only [le_antisymm_iff, at_top, le_infi_iff, le_principal_iff, mem_map, mem_set_of_eq, map_infi_eq this, map_principal], split, { intro x, refine mem_sets_of_superset (mem_infi_sets ⟨x ⊔ a, h le_sup_right⟩ (mem_principal_self _)) _, rintro _ ⟨y, hy, rfl⟩, exact le_trans le_sup_left (subtype.coe_le_coe.2 hy) }, { intro x, filter_upwards [mem_at_top (↑x ⊔ a)], intros b hb, exact ⟨⟨b, h $ le_sup_right.trans hb⟩, subtype.coe_le_coe.1 (le_sup_left.trans hb), rfl⟩ } end /-- The image of the filter `at_top` on `Ici a` under the coercion equals `at_top`. -/ @[simp] lemma map_coe_Ici_at_top [semilattice_sup α] (a : α) : map (coe : Ici a → α) at_top = at_top := map_coe_at_top_of_Ici_subset (subset.refl _) /-- The image of the filter `at_top` on `Ioi a` under the coercion equals `at_top`. -/ @[simp] lemma map_coe_Ioi_at_top [semilattice_sup α] [no_top_order α] (a : α) : map (coe : Ioi a → α) at_top = at_top := begin rcases no_top a with ⟨b, hb⟩, exact map_coe_at_top_of_Ici_subset (Ici_subset_Ioi.2 hb) end /-- The `at_top` filter for an open interval `Ioi a` comes from the `at_top` filter in the ambient order. -/ lemma at_top_Ioi_eq [semilattice_sup α] (a : α) : at_top = comap (coe : Ioi a → α) at_top := begin nontriviality, rcases nontrivial_iff_nonempty.1 ‹_› with ⟨b, hb⟩, rw [← map_coe_at_top_of_Ici_subset (Ici_subset_Ioi.2 hb), comap_map subtype.coe_injective] end /-- The `at_top` filter for an open interval `Ici a` comes from the `at_top` filter in the ambient order. -/ lemma at_top_Ici_eq [semilattice_sup α] (a : α) : at_top = comap (coe : Ici a → α) at_top := by rw [← map_coe_Ici_at_top a, comap_map subtype.coe_injective] /-- The `at_bot` filter for an open interval `Iio a` comes from the `at_bot` filter in the ambient order. -/ @[simp] lemma map_coe_Iio_at_bot [semilattice_inf α] [no_bot_order α] (a : α) : map (coe : Iio a → α) at_bot = at_bot := @map_coe_Ioi_at_top (order_dual α) _ _ _ /-- The `at_bot` filter for an open interval `Iio a` comes from the `at_bot` filter in the ambient order. -/ lemma at_bot_Iio_eq [semilattice_inf α] (a : α) : at_bot = comap (coe : Iio a → α) at_bot := @at_top_Ioi_eq (order_dual α) _ _ /-- The `at_bot` filter for an open interval `Iic a` comes from the `at_bot` filter in the ambient order. -/ @[simp] lemma map_coe_Iic_at_bot [semilattice_inf α] (a : α) : map (coe : Iic a → α) at_bot = at_bot := @map_coe_Ici_at_top (order_dual α) _ _ /-- The `at_bot` filter for an open interval `Iic a` comes from the `at_bot` filter in the ambient order. -/ lemma at_bot_Iic_eq [semilattice_inf α] (a : α) : at_bot = comap (coe : Iic a → α) at_bot := @at_top_Ici_eq (order_dual α) _ _ lemma tendsto_Ioi_at_top [semilattice_sup α] {a : α} {f : β → Ioi a} {l : filter β} : tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l at_top := by rw [at_top_Ioi_eq, tendsto_comap_iff] lemma tendsto_Iio_at_bot [semilattice_inf α] {a : α} {f : β → Iio a} {l : filter β} : tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l at_bot := by rw [at_bot_Iio_eq, tendsto_comap_iff] lemma tendsto_Ici_at_top [semilattice_sup α] {a : α} {f : β → Ici a} {l : filter β} : tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l at_top := by rw [at_top_Ici_eq, tendsto_comap_iff] lemma tendsto_Iic_at_bot [semilattice_inf α] {a : α} {f : β → Iic a} {l : filter β} : tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l at_bot := by rw [at_bot_Iic_eq, tendsto_comap_iff] @[simp] lemma tendsto_comp_coe_Ioi_at_top [semilattice_sup α] [no_top_order α] {a : α} {f : α → β} {l : filter β} : tendsto (λ x : Ioi a, f x) at_top l ↔ tendsto f at_top l := by rw [← map_coe_Ioi_at_top a, tendsto_map'_iff] @[simp] lemma tendsto_comp_coe_Ici_at_top [semilattice_sup α] {a : α} {f : α → β} {l : filter β} : tendsto (λ x : Ici a, f x) at_top l ↔ tendsto f at_top l := by rw [← map_coe_Ici_at_top a, tendsto_map'_iff] @[simp] lemma tendsto_comp_coe_Iio_at_bot [semilattice_inf α] [no_bot_order α] {a : α} {f : α → β} {l : filter β} : tendsto (λ x : Iio a, f x) at_bot l ↔ tendsto f at_bot l := by rw [← map_coe_Iio_at_bot a, tendsto_map'_iff] @[simp] lemma tendsto_comp_coe_Iic_at_bot [semilattice_inf α] {a : α} {f : α → β} {l : filter β} : tendsto (λ x : Iic a, f x) at_bot l ↔ tendsto f at_bot l := by rw [← map_coe_Iic_at_bot a, tendsto_map'_iff] lemma map_add_at_top_eq_nat (k : ℕ) : map (λa, a + k) at_top = at_top := map_at_top_eq_of_gc (λa, a - k) k (assume a b h, add_le_add_right h k) (assume a b h, (nat.le_sub_right_iff_add_le h).symm) (assume a h, by rw [nat.sub_add_cancel h]) lemma map_sub_at_top_eq_nat (k : ℕ) : map (λa, a - k) at_top = at_top := map_at_top_eq_of_gc (λa, a + k) 0 (assume a b h, nat.sub_le_sub_right h _) (assume a b _, nat.sub_le_right_iff_le_add) (assume b _, by rw [nat.add_sub_cancel]) lemma tendsto_add_at_top_nat (k : ℕ) : tendsto (λa, a + k) at_top at_top := le_of_eq (map_add_at_top_eq_nat k) lemma tendsto_sub_at_top_nat (k : ℕ) : tendsto (λa, a - k) at_top at_top := le_of_eq (map_sub_at_top_eq_nat k) lemma tendsto_add_at_top_iff_nat {f : ℕ → α} {l : filter α} (k : ℕ) : tendsto (λn, f (n + k)) at_top l ↔ tendsto f at_top l := show tendsto (f ∘ (λn, n + k)) at_top l ↔ tendsto f at_top l, by rw [← tendsto_map'_iff, map_add_at_top_eq_nat] lemma map_div_at_top_eq_nat (k : ℕ) (hk : 0 < k) : map (λa, a / k) at_top = at_top := map_at_top_eq_of_gc (λb, b * k + (k - 1)) 1 (assume a b h, nat.div_le_div_right h) (assume a b _, calc a / k ≤ b ↔ a / k < b + 1 : by rw [← nat.succ_eq_add_one, nat.lt_succ_iff] ... ↔ a < (b + 1) * k : nat.div_lt_iff_lt_mul _ _ hk ... ↔ _ : begin cases k, exact (lt_irrefl _ hk).elim, simp [mul_add, add_mul, nat.succ_add, nat.lt_succ_iff] end) (assume b _, calc b = (b * k) / k : by rw [nat.mul_div_cancel b hk] ... ≤ (b * k + (k - 1)) / k : nat.div_le_div_right $ nat.le_add_right _ _) /-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded above, then `tendsto u at_top at_top`. -/ lemma tendsto_at_top_at_top_of_monotone' [preorder ι] [linear_order α] {u : ι → α} (h : monotone u) (H : ¬bdd_above (range u)) : tendsto u at_top at_top := begin apply h.tendsto_at_top_at_top, intro b, rcases not_bdd_above_iff.1 H b with ⟨_, ⟨N, rfl⟩, hN⟩, exact ⟨N, le_of_lt hN⟩, end /-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded below, then `tendsto u at_bot at_bot`. -/ lemma tendsto_at_bot_at_bot_of_monotone' [preorder ι] [linear_order α] {u : ι → α} (h : monotone u) (H : ¬bdd_below (range u)) : tendsto u at_bot at_bot := @tendsto_at_top_at_top_of_monotone' (order_dual ι) (order_dual α) _ _ _ h.order_dual H lemma unbounded_of_tendsto_at_top [nonempty α] [semilattice_sup α] [preorder β] [no_top_order β] {f : α → β} (h : tendsto f at_top at_top) : ¬ bdd_above (range f) := begin rintros ⟨M, hM⟩, cases mem_at_top_sets.mp (h $ Ioi_mem_at_top M) with a ha, apply lt_irrefl M, calc M < f a : ha a (le_refl _) ... ≤ M : hM (set.mem_range_self a) end lemma unbounded_of_tendsto_at_bot [nonempty α] [semilattice_sup α] [preorder β] [no_bot_order β] {f : α → β} (h : tendsto f at_top at_bot) : ¬ bdd_below (range f) := @unbounded_of_tendsto_at_top _ (order_dual β) _ _ _ _ _ h lemma unbounded_of_tendsto_at_top' [nonempty α] [semilattice_inf α] [preorder β] [no_top_order β] {f : α → β} (h : tendsto f at_bot at_top) : ¬ bdd_above (range f) := @unbounded_of_tendsto_at_top (order_dual α) _ _ _ _ _ _ h lemma unbounded_of_tendsto_at_bot' [nonempty α] [semilattice_inf α] [preorder β] [no_bot_order β] {f : α → β} (h : tendsto f at_bot at_bot) : ¬ bdd_below (range f) := @unbounded_of_tendsto_at_top (order_dual α) (order_dual β) _ _ _ _ _ h /-- If a monotone function `u : ι → α` tends to `at_top` along *some* non-trivial filter `l`, then it tends to `at_top` along `at_top`. -/ lemma tendsto_at_top_of_monotone_of_filter [preorder ι] [preorder α] {l : filter ι} {u : ι → α} (h : monotone u) [ne_bot l] (hu : tendsto u l at_top) : tendsto u at_top at_top := h.tendsto_at_top_at_top $ λ b, (hu.eventually (mem_at_top b)).exists /-- If a monotone function `u : ι → α` tends to `at_bot` along *some* non-trivial filter `l`, then it tends to `at_bot` along `at_bot`. -/ lemma tendsto_at_bot_of_monotone_of_filter [preorder ι] [preorder α] {l : filter ι} {u : ι → α} (h : monotone u) [ne_bot l] (hu : tendsto u l at_bot) : tendsto u at_bot at_bot := @tendsto_at_top_of_monotone_of_filter (order_dual ι) (order_dual α) _ _ _ _ h.order_dual _ hu lemma tendsto_at_top_of_monotone_of_subseq [preorder ι] [preorder α] {u : ι → α} {φ : ι' → ι} (h : monotone u) {l : filter ι'} [ne_bot l] (H : tendsto (u ∘ φ) l at_top) : tendsto u at_top at_top := tendsto_at_top_of_monotone_of_filter h (tendsto_map' H) lemma tendsto_at_bot_of_monotone_of_subseq [preorder ι] [preorder α] {u : ι → α} {φ : ι' → ι} (h : monotone u) {l : filter ι'} [ne_bot l] (H : tendsto (u ∘ φ) l at_bot) : tendsto u at_bot at_bot := tendsto_at_bot_of_monotone_of_filter h (tendsto_map' H) /-- Let `f` and `g` be two maps to the same commutative monoid. This lemma gives a sufficient condition for comparison of the filter `at_top.map (λ s, ∏ b in s, f b)` with `at_top.map (λ s, ∏ b in s, g b)`. This is useful to compare the set of limit points of `Π b in s, f b` as `s → at_top` with the similar set for `g`. -/ @[to_additive] lemma map_at_top_finset_prod_le_of_prod_eq [comm_monoid α] {f : β → α} {g : γ → α} (h_eq : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ ∏ x in u', g x = ∏ b in v', f b) : at_top.map (λs:finset β, ∏ b in s, f b) ≤ at_top.map (λs:finset γ, ∏ x in s, g x) := by rw [map_at_top_eq, map_at_top_eq]; from (le_infi $ assume b, let ⟨v, hv⟩ := h_eq b in infi_le_of_le v $ by simp [set.image_subset_iff]; exact hv) lemma has_antimono_basis.tendsto [semilattice_sup ι] [nonempty ι] {l : filter α} {p : ι → Prop} {s : ι → set α} (hl : l.has_antimono_basis p s) {φ : ι → α} (h : ∀ i : ι, φ i ∈ s i) : tendsto φ at_top l := (at_top_basis.tendsto_iff hl.to_has_basis).2 $ assume i hi, ⟨i, trivial, λ j hij, hl.decreasing hi (hl.mono hij hi) hij (h j)⟩ namespace is_countably_generated /-- An abstract version of continuity of sequentially continuous functions on metric spaces: if a filter `k` is countably generated then `tendsto f k l` iff for every sequence `u` converging to `k`, `f ∘ u` tends to `l`. -/ lemma tendsto_iff_seq_tendsto {f : α → β} {k : filter α} {l : filter β} (hcb : k.is_countably_generated) : tendsto f k l ↔ (∀ x : ℕ → α, tendsto x at_top k → tendsto (f ∘ x) at_top l) := suffices (∀ x : ℕ → α, tendsto x at_top k → tendsto (f ∘ x) at_top l) → tendsto f k l, from ⟨by intros; apply tendsto.comp; assumption, by assumption⟩, begin rcases hcb.exists_antimono_basis with ⟨g, gbasis, gmon, -⟩, contrapose, simp only [not_forall, gbasis.tendsto_left_iff, exists_const, not_exists, not_imp], rintro ⟨B, hBl, hfBk⟩, choose x h using hfBk, use x, split, { exact (at_top_basis.tendsto_iff gbasis).2 (λ i _, ⟨i, trivial, λ j hj, gmon trivial trivial hj (h j).1⟩) }, { simp only [tendsto_at_top', (∘), not_forall, not_exists], use [B, hBl], intro i, use [i, (le_refl _)], apply (h i).right }, end lemma tendsto_of_seq_tendsto {f : α → β} {k : filter α} {l : filter β} (hcb : k.is_countably_generated) : (∀ x : ℕ → α, tendsto x at_top k → tendsto (f ∘ x) at_top l) → tendsto f k l := hcb.tendsto_iff_seq_tendsto.2 lemma subseq_tendsto {f : filter α} (hf : is_countably_generated f) {u : ℕ → α} (hx : ne_bot (f ⊓ map u at_top)) : ∃ (θ : ℕ → ℕ), (strict_mono θ) ∧ (tendsto (u ∘ θ) at_top f) := begin rcases hf.exists_antimono_basis with ⟨B, h⟩, have : ∀ N, ∃ n ≥ N, u n ∈ B N, from λ N, filter.inf_map_at_top_ne_bot_iff.mp hx _ (h.to_has_basis.mem_of_mem trivial) N, choose φ hφ using this, cases forall_and_distrib.mp hφ with φ_ge φ_in, have lim_uφ : tendsto (u ∘ φ) at_top f, from h.tendsto φ_in, have lim_φ : tendsto φ at_top at_top, from (tendsto_at_top_mono φ_ge tendsto_id), obtain ⟨ψ, hψ, hψφ⟩ : ∃ ψ : ℕ → ℕ, strict_mono ψ ∧ strict_mono (φ ∘ ψ), from strict_mono_subseq_of_tendsto_at_top lim_φ, exact ⟨φ ∘ ψ, hψφ, lim_uφ.comp $ strict_mono_tendsto_at_top hψ⟩, end end is_countably_generated end filter open filter finset section variables {R : Type*} [linear_ordered_semiring R] lemma exists_lt_mul_self (a : R) : ∃ x ≥ 0, a < x * x := let ⟨x, hxa, hx0⟩ :=((tendsto_mul_self_at_top.eventually (eventually_gt_at_top a)).and (eventually_ge_at_top 0)).exists in ⟨x, hx0, hxa⟩ lemma exists_le_mul_self (a : R) : ∃ x ≥ 0, a ≤ x * x := let ⟨x, hx0, hxa⟩ := exists_lt_mul_self a in ⟨x, hx0, hxa.le⟩ end namespace order_iso variables [preorder α] [preorder β] @[simp] lemma comap_at_top (e : α ≃o β) : comap e at_top = at_top := by simp [at_top, ← e.surjective.infi_comp] @[simp] lemma comap_at_bot (e : α ≃o β) : comap e at_bot = at_bot := e.dual.comap_at_top @[simp] lemma map_at_top (e : α ≃o β) : map ⇑e at_top = at_top := by rw [← e.comap_at_top, map_comap_of_surjective e.surjective] @[simp] lemma map_at_bot (e : α ≃o β) : map ⇑e at_bot = at_bot := e.dual.map_at_top lemma tendsto_at_top (e : α ≃o β) : tendsto e at_top at_top := e.map_at_top.le lemma tendsto_at_bot (e : α ≃o β) : tendsto e at_bot at_bot := e.map_at_bot.le @[simp] lemma tendsto_at_top_iff {l : filter γ} {f : γ → α} (e : α ≃o β) : tendsto (λ x, e (f x)) l at_top ↔ tendsto f l at_top := by rw [← e.comap_at_top, tendsto_comap_iff] @[simp] lemma tendsto_at_bot_iff {l : filter γ} {f : γ → α} (e : α ≃o β) : tendsto (λ x, e (f x)) l at_bot ↔ tendsto f l at_bot := e.dual.tendsto_at_top_iff end order_iso /-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g` to a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters `at_top.map (λ s, ∏ i in s, f (g i))` and `at_top.map (λ s, ∏ i in s, f i)` coincide. The additive version of this lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under the same assumptions.-/ @[to_additive] lemma function.injective.map_at_top_finset_prod_eq [comm_monoid α] {g : γ → β} (hg : function.injective g) {f : β → α} (hf : ∀ x ∉ set.range g, f x = 1) : map (λ s, ∏ i in s, f (g i)) at_top = map (λ s, ∏ i in s, f i) at_top := begin apply le_antisymm; refine map_at_top_finset_prod_le_of_prod_eq (λ s, _), { refine ⟨s.preimage g (hg.inj_on _), λ t ht, _⟩, refine ⟨t.image g ∪ s, finset.subset_union_right _ _, _⟩, rw [← finset.prod_image (hg.inj_on _)], refine (prod_subset (subset_union_left _ _) _).symm, simp only [finset.mem_union, finset.mem_image], refine λ y hy hyt, hf y (mt _ hyt), rintros ⟨x, rfl⟩, exact ⟨x, ht (finset.mem_preimage.2 $ hy.resolve_left hyt), rfl⟩ }, { refine ⟨s.image g, λ t ht, _⟩, simp only [← prod_preimage _ _ (hg.inj_on _) _ (λ x _, hf x)], exact ⟨_, (image_subset_iff_subset_preimage _).1 ht, rfl⟩ } end /-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g` to an additive commutative monoid. Suppose that `f x = 0` outside of the range of `g`. Then the filters `at_top.map (λ s, ∑ i in s, f (g i))` and `at_top.map (λ s, ∑ i in s, f i)` coincide. This lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under the same assumptions.-/ add_decl_doc function.injective.map_at_top_finset_sum_eq
2fc1da501cf9ecd61a405d167b9e30762fef665c
9dc8cecdf3c4634764a18254e94d43da07142918
/src/data/ordmap/ordset.lean
f3a2d52782cb10130a8b205160c0c9947fc3dca1
[ "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
69,255
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.ordmap.ordnode import algebra.order.ring import data.nat.dist import tactic.linarith /-! # Verification of the `ordnode α` datatype This file proves the correctness of the operations in `data.ordmap.ordnode`. The public facing version is the type `ordset α`, which is a wrapper around `ordnode α` which includes the correctness invariant of the type, and it exposes parallel operations like `insert` as functions on `ordset` that do the same thing but bundle the correctness proofs. The advantage is that it is possible to, for example, prove that the result of `find` on `insert` will actually find the element, while `ordnode` cannot guarantee this if the input tree did not satisfy the type invariants. ## Main definitions * `ordset α`: A well formed set of values of type `α` ## Implementation notes The majority of this file is actually in the `ordnode` namespace, because we first have to prove the correctness of all the operations (and defining what correctness means here is actually somewhat subtle). So all the actual `ordset` operations are at the very end, once we have all the theorems. An `ordnode α` is an inductive type which describes a tree which stores the `size` at internal nodes. The correctness invariant of an `ordnode α` is: * `ordnode.sized t`: All internal `size` fields must match the actual measured size of the tree. (This is not hard to satisfy.) * `ordnode.balanced t`: Unless the tree has the form `()` or `((a) b)` or `(a (b))` (that is, nil or a single singleton subtree), the two subtrees must satisfy `size l ≤ δ * size r` and `size r ≤ δ * size l`, where `δ := 3` is a global parameter of the data structure (and this property must hold recursively at subtrees). This is why we say this is a "size balanced tree" data structure. * `ordnode.bounded lo hi t`: The members of the tree must be in strictly increasing order, meaning that if `a` is in the left subtree and `b` is the root, then `a ≤ b` and `¬ (b ≤ a)`. We enforce this using `ordnode.bounded` which includes also a global upper and lower bound. Because the `ordnode` file was ported from Haskell, the correctness invariants of some of the functions have not been spelled out, and some theorems like `ordnode.valid'.balance_l_aux` show very intricate assumptions on the sizes, which may need to be revised if it turns out some operations violate these assumptions, because there is a decent amount of slop in the actual data structure invariants, so the theorem will go through with multiple choices of assumption. **Note:** This file is incomplete, in the sense that the intent is to have verified versions and lemmas about all the definitions in `ordnode.lean`, but at the moment only a few operations are verified (the hard part should be out of the way, but still). Contributors are encouraged to pick this up and finish the job, if it appeals to you. ## Tags ordered map, ordered set, data structure, verified programming -/ variable {α : Type*} namespace ordnode /-! ### delta and ratio -/ theorem not_le_delta {s} (H : 1 ≤ s) : ¬ s ≤ delta * 0 := not_le_of_gt H theorem delta_lt_false {a b : ℕ} (h₁ : delta * a < b) (h₂ : delta * b < a) : false := not_le_of_lt (lt_trans ((mul_lt_mul_left dec_trivial).2 h₁) h₂) $ by simpa [mul_assoc] using nat.mul_le_mul_right a (dec_trivial : 1 ≤ delta * delta) /-! ### `singleton` -/ /-! ### `size` and `empty` -/ /-- O(n). Computes the actual number of elements in the set, ignoring the cached `size` field. -/ def real_size : ordnode α → ℕ | nil := 0 | (node _ l _ r) := real_size l + real_size r + 1 /-! ### `sized` -/ /-- The `sized` property asserts that all the `size` fields in nodes match the actual size of the respective subtrees. -/ def sized : ordnode α → Prop | nil := true | (node s l _ r) := s = size l + size r + 1 ∧ sized l ∧ sized r theorem sized.node' {l x r} (hl : @sized α l) (hr : sized r) : sized (node' l x r) := ⟨rfl, hl, hr⟩ theorem sized.eq_node' {s l x r} (h : @sized α (node s l x r)) : node s l x r = node' l x r := by rw h.1; refl theorem sized.size_eq {s l x r} (H : sized (@node α s l x r)) : size (@node α s l x r) = size l + size r + 1 := H.1 @[elab_as_eliminator] theorem sized.induction {t} (hl : @sized α t) {C : ordnode α → Prop} (H0 : C nil) (H1 : ∀ l x r, C l → C r → C (node' l x r)) : C t := begin induction t, {exact H0}, rw hl.eq_node', exact H1 _ _ _ (t_ih_l hl.2.1) (t_ih_r hl.2.2) end theorem size_eq_real_size : ∀ {t : ordnode α}, sized t → size t = real_size t | nil _ := rfl | (node s l x r) ⟨h₁, h₂, h₃⟩ := by rw [size, h₁, size_eq_real_size h₂, size_eq_real_size h₃]; refl @[simp] theorem sized.size_eq_zero {t : ordnode α} (ht : sized t) : size t = 0 ↔ t = nil := by cases t; [simp, simp [ht.1]] theorem sized.pos {s l x r} (h : sized (@node α s l x r)) : 0 < s := by rw h.1; apply nat.le_add_left /-! `dual` -/ theorem dual_dual : ∀ (t : ordnode α), dual (dual t) = t | nil := rfl | (node s l x r) := by rw [dual, dual, dual_dual, dual_dual] @[simp] theorem size_dual (t : ordnode α) : size (dual t) = size t := by cases t; refl /-! `balanced` -/ /-- The `balanced_sz l r` asserts that a hypothetical tree with children of sizes `l` and `r` is balanced: either `l ≤ δ * r` and `r ≤ δ * r`, or the tree is trivial with a singleton on one side and nothing on the other. -/ def balanced_sz (l r : ℕ) : Prop := l + r ≤ 1 ∨ (l ≤ delta * r ∧ r ≤ delta * l) instance balanced_sz.dec : decidable_rel balanced_sz := λ l r, or.decidable /-- The `balanced t` asserts that the tree `t` satisfies the balance invariants (at every level). -/ def balanced : ordnode α → Prop | nil := true | (node _ l _ r) := balanced_sz (size l) (size r) ∧ balanced l ∧ balanced r instance balanced.dec : decidable_pred (@balanced α) | t := by induction t; unfold balanced; resetI; apply_instance theorem balanced_sz.symm {l r : ℕ} : balanced_sz l r → balanced_sz r l := or.imp (by rw add_comm; exact id) and.symm theorem balanced_sz_zero {l : ℕ} : balanced_sz l 0 ↔ l ≤ 1 := by simp [balanced_sz] { contextual := tt } theorem balanced_sz_up {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l) (H : balanced_sz l r₁) : balanced_sz l r₂ := begin refine or_iff_not_imp_left.2 (λ h, _), refine ⟨_, h₂.resolve_left h⟩, cases H, { cases r₂, { cases h (le_trans (nat.add_le_add_left (nat.zero_le _) _) H) }, { exact le_trans (le_trans (nat.le_add_right _ _) H) (nat.le_add_left 1 _) } }, { exact le_trans H.1 (nat.mul_le_mul_left _ h₁) } end theorem balanced_sz_down {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ l ≤ delta * r₁) (H : balanced_sz l r₂) : balanced_sz l r₁ := have l + r₂ ≤ 1 → balanced_sz l r₁, from λ H, or.inl (le_trans (nat.add_le_add_left h₁ _) H), or.cases_on H this (λ H, or.cases_on h₂ this (λ h₂, or.inr ⟨h₂, le_trans h₁ H.2⟩)) theorem balanced.dual : ∀ {t : ordnode α}, balanced t → balanced (dual t) | nil h := ⟨⟩ | (node s l x r) ⟨b, bl, br⟩ := ⟨by rw [size_dual, size_dual]; exact b.symm, br.dual, bl.dual⟩ /-! ### `rotate` and `balance` -/ /-- Build a tree from three nodes, left associated (ignores the invariants). -/ def node3_l (l : ordnode α) (x : α) (m : ordnode α) (y : α) (r : ordnode α) : ordnode α := node' (node' l x m) y r /-- Build a tree from three nodes, right associated (ignores the invariants). -/ def node3_r (l : ordnode α) (x : α) (m : ordnode α) (y : α) (r : ordnode α) : ordnode α := node' l x (node' m y r) /-- Build a tree from three nodes, with `a () b -> (a ()) b` and `a (b c) d -> ((a b) (c d))`. -/ def node4_l : ordnode α → α → ordnode α → α → ordnode α → ordnode α | l x (node _ ml y mr) z r := node' (node' l x ml) y (node' mr z r) | l x nil z r := node3_l l x nil z r -- should not happen /-- Build a tree from three nodes, with `a () b -> a (() b)` and `a (b c) d -> ((a b) (c d))`. -/ def node4_r : ordnode α → α → ordnode α → α → ordnode α → ordnode α | l x (node _ ml y mr) z r := node' (node' l x ml) y (node' mr z r) | l x nil z r := node3_r l x nil z r -- should not happen /-- Concatenate two nodes, performing a left rotation `x (y z) -> ((x y) z)` if balance is upset. -/ def rotate_l : ordnode α → α → ordnode α → ordnode α | l x (node _ m y r) := if size m < ratio * size r then node3_l l x m y r else node4_l l x m y r | l x nil := node' l x nil -- should not happen /-- Concatenate two nodes, performing a right rotation `(x y) z -> (x (y z))` if balance is upset. -/ def rotate_r : ordnode α → α → ordnode α → ordnode α | (node _ l x m) y r := if size m < ratio * size l then node3_r l x m y r else node4_r l x m y r | nil y r := node' nil y r -- should not happen /-- A left balance operation. This will rebalance a concatenation, assuming the original nodes are not too far from balanced. -/ def balance_l' (l : ordnode α) (x : α) (r : ordnode α) : ordnode α := if size l + size r ≤ 1 then node' l x r else if size l > delta * size r then rotate_r l x r else node' l x r /-- A right balance operation. This will rebalance a concatenation, assuming the original nodes are not too far from balanced. -/ def balance_r' (l : ordnode α) (x : α) (r : ordnode α) : ordnode α := if size l + size r ≤ 1 then node' l x r else if size r > delta * size l then rotate_l l x r else node' l x r /-- The full balance operation. This is the same as `balance`, but with less manual inlining. It is somewhat easier to work with this version in proofs. -/ def balance' (l : ordnode α) (x : α) (r : ordnode α) : ordnode α := if size l + size r ≤ 1 then node' l x r else if size r > delta * size l then rotate_l l x r else if size l > delta * size r then rotate_r l x r else node' l x r theorem dual_node' (l : ordnode α) (x : α) (r : ordnode α) : dual (node' l x r) = node' (dual r) x (dual l) := by simp [node', add_comm] theorem dual_node3_l (l : ordnode α) (x : α) (m : ordnode α) (y : α) (r : ordnode α) : dual (node3_l l x m y r) = node3_r (dual r) y (dual m) x (dual l) := by simp [node3_l, node3_r, dual_node'] theorem dual_node3_r (l : ordnode α) (x : α) (m : ordnode α) (y : α) (r : ordnode α) : dual (node3_r l x m y r) = node3_l (dual r) y (dual m) x (dual l) := by simp [node3_l, node3_r, dual_node'] theorem dual_node4_l (l : ordnode α) (x : α) (m : ordnode α) (y : α) (r : ordnode α) : dual (node4_l l x m y r) = node4_r (dual r) y (dual m) x (dual l) := by cases m; simp [node4_l, node4_r, dual_node3_l, dual_node'] theorem dual_node4_r (l : ordnode α) (x : α) (m : ordnode α) (y : α) (r : ordnode α) : dual (node4_r l x m y r) = node4_l (dual r) y (dual m) x (dual l) := by cases m; simp [node4_l, node4_r, dual_node3_r, dual_node'] theorem dual_rotate_l (l : ordnode α) (x : α) (r : ordnode α) : dual (rotate_l l x r) = rotate_r (dual r) x (dual l) := by cases r; simp [rotate_l, rotate_r, dual_node']; split_ifs; simp [dual_node3_l, dual_node4_l] theorem dual_rotate_r (l : ordnode α) (x : α) (r : ordnode α) : dual (rotate_r l x r) = rotate_l (dual r) x (dual l) := by rw [← dual_dual (rotate_l _ _ _), dual_rotate_l, dual_dual, dual_dual] theorem dual_balance' (l : ordnode α) (x : α) (r : ordnode α) : dual (balance' l x r) = balance' (dual r) x (dual l) := begin simp [balance', add_comm], split_ifs; simp [dual_node', dual_rotate_l, dual_rotate_r], cases delta_lt_false h_1 h_2 end theorem dual_balance_l (l : ordnode α) (x : α) (r : ordnode α) : dual (balance_l l x r) = balance_r (dual r) x (dual l) := begin unfold balance_l balance_r, cases r with rs rl rx rr, { cases l with ls ll lx lr, {refl}, cases ll with lls lll llx llr; cases lr with lrs lrl lrx lrr; dsimp only [dual]; try {refl}, split_ifs; repeat {simp [h, add_comm]} }, { cases l with ls ll lx lr, {refl}, dsimp only [dual], split_ifs, swap, {simp [add_comm]}, cases ll with lls lll llx llr; cases lr with lrs lrl lrx lrr; try {refl}, dsimp only [dual], split_ifs; simp [h, add_comm] }, end theorem dual_balance_r (l : ordnode α) (x : α) (r : ordnode α) : dual (balance_r l x r) = balance_l (dual r) x (dual l) := by rw [← dual_dual (balance_l _ _ _), dual_balance_l, dual_dual, dual_dual] theorem sized.node3_l {l x m y r} (hl : @sized α l) (hm : sized m) (hr : sized r) : sized (node3_l l x m y r) := (hl.node' hm).node' hr theorem sized.node3_r {l x m y r} (hl : @sized α l) (hm : sized m) (hr : sized r) : sized (node3_r l x m y r) := hl.node' (hm.node' hr) theorem sized.node4_l {l x m y r} (hl : @sized α l) (hm : sized m) (hr : sized r) : sized (node4_l l x m y r) := by cases m; [exact (hl.node' hm).node' hr, exact (hl.node' hm.2.1).node' (hm.2.2.node' hr)] theorem node3_l_size {l x m y r} : size (@node3_l α l x m y r) = size l + size m + size r + 2 := by dsimp [node3_l, node', size]; rw add_right_comm _ 1 theorem node3_r_size {l x m y r} : size (@node3_r α l x m y r) = size l + size m + size r + 2 := by dsimp [node3_r, node', size]; rw [← add_assoc, ← add_assoc] theorem node4_l_size {l x m y r} (hm : sized m) : size (@node4_l α l x m y r) = size l + size m + size r + 2 := by cases m; simp [node4_l, node3_l, node', add_comm, add_left_comm]; [skip, simp [size, hm.1]]; rw [← add_assoc, ← bit0]; simp [add_comm, add_left_comm] theorem sized.dual : ∀ {t : ordnode α} (h : sized t), sized (dual t) | nil h := ⟨⟩ | (node s l x r) ⟨rfl, sl, sr⟩ := ⟨by simp [size_dual, add_comm], sized.dual sr, sized.dual sl⟩ theorem sized.dual_iff {t : ordnode α} : sized (dual t) ↔ sized t := ⟨λ h, by rw ← dual_dual t; exact h.dual, sized.dual⟩ theorem sized.rotate_l {l x r} (hl : @sized α l) (hr : sized r) : sized (rotate_l l x r) := begin cases r, {exact hl.node' hr}, rw rotate_l, split_ifs, { exact hl.node3_l hr.2.1 hr.2.2 }, { exact hl.node4_l hr.2.1 hr.2.2 } end theorem sized.rotate_r {l x r} (hl : @sized α l) (hr : sized r) : sized (rotate_r l x r) := sized.dual_iff.1 $ by rw dual_rotate_r; exact hr.dual.rotate_l hl.dual theorem sized.rotate_l_size {l x r} (hm : sized r) : size (@rotate_l α l x r) = size l + size r + 1 := begin cases r; simp [rotate_l], simp [size, hm.1, add_comm, add_left_comm], rw [← add_assoc, ← bit0], simp, split_ifs; simp [node3_l_size, node4_l_size hm.2.1, add_comm, add_left_comm] end theorem sized.rotate_r_size {l x r} (hl : sized l) : size (@rotate_r α l x r) = size l + size r + 1 := by rw [← size_dual, dual_rotate_r, hl.dual.rotate_l_size, size_dual, size_dual, add_comm (size l)] theorem sized.balance' {l x r} (hl : @sized α l) (hr : sized r) : sized (balance' l x r) := begin unfold balance', split_ifs, { exact hl.node' hr }, { exact hl.rotate_l hr }, { exact hl.rotate_r hr }, { exact hl.node' hr } end theorem size_balance' {l x r} (hl : @sized α l) (hr : sized r) : size (@balance' α l x r) = size l + size r + 1 := begin unfold balance', split_ifs, { refl }, { exact hr.rotate_l_size }, { exact hl.rotate_r_size }, { refl } end /-! ## `all`, `any`, `emem`, `amem` -/ theorem all.imp {P Q : α → Prop} (H : ∀ a, P a → Q a) : ∀ {t}, all P t → all Q t | nil h := ⟨⟩ | (node _ l x r) ⟨h₁, h₂, h₃⟩ := ⟨h₁.imp, H _ h₂, h₃.imp⟩ theorem any.imp {P Q : α → Prop} (H : ∀ a, P a → Q a) : ∀ {t}, any P t → any Q t | nil := id | (node _ l x r) := or.imp any.imp $ or.imp (H _) any.imp theorem all_singleton {P : α → Prop} {x : α} : all P (singleton x) ↔ P x := ⟨λ h, h.2.1, λ h, ⟨⟨⟩, h, ⟨⟩⟩⟩ theorem any_singleton {P : α → Prop} {x : α} : any P (singleton x) ↔ P x := ⟨by rintro (⟨⟨⟩⟩ | h | ⟨⟨⟩⟩); exact h, λ h, or.inr (or.inl h)⟩ theorem all_dual {P : α → Prop} : ∀ {t : ordnode α}, all P (dual t) ↔ all P t | nil := iff.rfl | (node s l x r) := ⟨λ ⟨hr, hx, hl⟩, ⟨all_dual.1 hl, hx, all_dual.1 hr⟩, λ ⟨hl, hx, hr⟩, ⟨all_dual.2 hr, hx, all_dual.2 hl⟩⟩ theorem all_iff_forall {P : α → Prop} : ∀ {t}, all P t ↔ ∀ x, emem x t → P x | nil := (iff_true_intro $ by rintro _ ⟨⟩).symm | (node _ l x r) := by simp [all, emem, all_iff_forall, any, or_imp_distrib, forall_and_distrib] theorem any_iff_exists {P : α → Prop} : ∀ {t}, any P t ↔ ∃ x, emem x t ∧ P x | nil := ⟨by rintro ⟨⟩, by rintro ⟨_, ⟨⟩, _⟩⟩ | (node _ l x r) := by simp [any, emem, any_iff_exists, or_and_distrib_right, exists_or_distrib] theorem emem_iff_all {x : α} {t} : emem x t ↔ ∀ P, all P t → P x := ⟨λ h P al, all_iff_forall.1 al _ h, λ H, H _ $ all_iff_forall.2 $ λ _, id⟩ theorem all_node' {P l x r} : @all α P (node' l x r) ↔ all P l ∧ P x ∧ all P r := iff.rfl theorem all_node3_l {P l x m y r} : @all α P (node3_l l x m y r) ↔ all P l ∧ P x ∧ all P m ∧ P y ∧ all P r := by simp [node3_l, all_node', and_assoc] theorem all_node3_r {P l x m y r} : @all α P (node3_r l x m y r) ↔ all P l ∧ P x ∧ all P m ∧ P y ∧ all P r := iff.rfl theorem all_node4_l {P l x m y r} : @all α P (node4_l l x m y r) ↔ all P l ∧ P x ∧ all P m ∧ P y ∧ all P r := by cases m; simp [node4_l, all_node', all, all_node3_l, and_assoc] theorem all_node4_r {P l x m y r} : @all α P (node4_r l x m y r) ↔ all P l ∧ P x ∧ all P m ∧ P y ∧ all P r := by cases m; simp [node4_r, all_node', all, all_node3_r, and_assoc] theorem all_rotate_l {P l x r} : @all α P (rotate_l l x r) ↔ all P l ∧ P x ∧ all P r := by cases r; simp [rotate_l, all_node']; split_ifs; simp [all_node3_l, all_node4_l, all] theorem all_rotate_r {P l x r} : @all α P (rotate_r l x r) ↔ all P l ∧ P x ∧ all P r := by rw [← all_dual, dual_rotate_r, all_rotate_l]; simp [all_dual, and_comm, and.left_comm] theorem all_balance' {P l x r} : @all α P (balance' l x r) ↔ all P l ∧ P x ∧ all P r := by rw balance'; split_ifs; simp [all_node', all_rotate_l, all_rotate_r] /-! ### `to_list` -/ theorem foldr_cons_eq_to_list : ∀ (t : ordnode α) (r : list α), t.foldr list.cons r = to_list t ++ r | nil r := rfl | (node _ l x r) r' := by rw [foldr, foldr_cons_eq_to_list, foldr_cons_eq_to_list, ← list.cons_append, ← list.append_assoc, ← foldr_cons_eq_to_list]; refl @[simp] theorem to_list_nil : to_list (@nil α) = [] := rfl @[simp] theorem to_list_node (s l x r) : to_list (@node α s l x r) = to_list l ++ x :: to_list r := by rw [to_list, foldr, foldr_cons_eq_to_list]; refl theorem emem_iff_mem_to_list {x : α} {t} : emem x t ↔ x ∈ to_list t := by unfold emem; induction t; simp [any, *, or_assoc] theorem length_to_list' : ∀ t : ordnode α, (to_list t).length = t.real_size | nil := rfl | (node _ l _ r) := by rw [to_list_node, list.length_append, list.length_cons, length_to_list', length_to_list']; refl theorem length_to_list {t : ordnode α} (h : sized t) : (to_list t).length = t.size := by rw [length_to_list', size_eq_real_size h] theorem equiv_iff {t₁ t₂ : ordnode α} (h₁ : sized t₁) (h₂ : sized t₂) : equiv t₁ t₂ ↔ to_list t₁ = to_list t₂ := and_iff_right_of_imp $ λ h, by rw [← length_to_list h₁, h, length_to_list h₂] /-! ### `mem` -/ theorem pos_size_of_mem [has_le α] [@decidable_rel α (≤)] {x : α} {t : ordnode α} (h : sized t) (h_mem : x ∈ t) : 0 < size t := by { cases t, { contradiction }, { simp [h.1] } } /-! ### `(find/erase/split)_(min/max)` -/ theorem find_min'_dual : ∀ t (x : α), find_min' (dual t) x = find_max' x t | nil x := rfl | (node _ l x r) _ := find_min'_dual r x theorem find_max'_dual (t) (x : α) : find_max' x (dual t) = find_min' t x := by rw [← find_min'_dual, dual_dual] theorem find_min_dual : ∀ t : ordnode α, find_min (dual t) = find_max t | nil := rfl | (node _ l x r) := congr_arg some $ find_min'_dual _ _ theorem find_max_dual (t : ordnode α) : find_max (dual t) = find_min t := by rw [← find_min_dual, dual_dual] theorem dual_erase_min : ∀ t : ordnode α, dual (erase_min t) = erase_max (dual t) | nil := rfl | (node _ nil x r) := rfl | (node _ l@(node _ _ _ _) x r) := by rw [erase_min, dual_balance_r, dual_erase_min, dual, dual, dual, erase_max] theorem dual_erase_max (t : ordnode α) : dual (erase_max t) = erase_min (dual t) := by rw [← dual_dual (erase_min _), dual_erase_min, dual_dual] theorem split_min_eq : ∀ s l (x : α) r, split_min' l x r = (find_min' l x, erase_min (node s l x r)) | _ nil x r := rfl | _ (node ls ll lx lr) x r := by rw [split_min', split_min_eq, split_min', find_min', erase_min] theorem split_max_eq : ∀ s l (x : α) r, split_max' l x r = (erase_max (node s l x r), find_max' x r) | _ l x nil := rfl | _ l x (node ls ll lx lr) := by rw [split_max', split_max_eq, split_max', find_max', erase_max] @[elab_as_eliminator] theorem find_min'_all {P : α → Prop} : ∀ t (x : α), all P t → P x → P (find_min' t x) | nil x h hx := hx | (node _ ll lx lr) x ⟨h₁, h₂, h₃⟩ hx := find_min'_all _ _ h₁ h₂ @[elab_as_eliminator] theorem find_max'_all {P : α → Prop} : ∀ (x : α) t, P x → all P t → P (find_max' x t) | x nil hx h := hx | x (node _ ll lx lr) hx ⟨h₁, h₂, h₃⟩ := find_max'_all _ _ h₂ h₃ /-! ### `glue` -/ /-! ### `merge` -/ @[simp] theorem merge_nil_left (t : ordnode α) : merge t nil = t := by cases t; refl @[simp] theorem merge_nil_right (t : ordnode α) : merge nil t = t := rfl @[simp] theorem merge_node {ls ll lx lr rs rl rx rr} : merge (@node α ls ll lx lr) (node rs rl rx rr) = if delta * ls < rs then balance_l (merge (node ls ll lx lr) rl) rx rr else if delta * rs < ls then balance_r ll lx (merge lr (node rs rl rx rr)) else glue (node ls ll lx lr) (node rs rl rx rr) := rfl /-! ### `insert` -/ theorem dual_insert [preorder α] [is_total α (≤)] [@decidable_rel α (≤)] (x : α) : ∀ t : ordnode α, dual (ordnode.insert x t) = @ordnode.insert αᵒᵈ _ _ x (dual t) | nil := rfl | (node _ l y r) := begin have : @cmp_le αᵒᵈ _ _ x y = cmp_le y x := rfl, rw [ordnode.insert, dual, ordnode.insert, this, ← cmp_le_swap x y], cases cmp_le x y; simp [ordering.swap, ordnode.insert, dual_balance_l, dual_balance_r, dual_insert] end /-! ### `balance` properties -/ theorem balance_eq_balance' {l x r} (hl : balanced l) (hr : balanced r) (sl : sized l) (sr : sized r) : @balance α l x r = balance' l x r := begin cases l with ls ll lx lr, { cases r with rs rl rx rr, { refl }, { rw sr.eq_node' at hr ⊢, cases rl with rls rll rlx rlr; cases rr with rrs rrl rrx rrr; dsimp [balance, balance'], { refl }, { have : size rrl = 0 ∧ size rrr = 0, { have := balanced_sz_zero.1 hr.1.symm, rwa [size, sr.2.2.1, nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this }, cases sr.2.2.2.1.size_eq_zero.1 this.1, cases sr.2.2.2.2.size_eq_zero.1 this.2, obtain rfl : rrs = 1 := sr.2.2.1, rw [if_neg, if_pos, rotate_l, if_pos], {refl}, all_goals {exact dec_trivial} }, { have : size rll = 0 ∧ size rlr = 0, { have := balanced_sz_zero.1 hr.1, rwa [size, sr.2.1.1, nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this }, cases sr.2.1.2.1.size_eq_zero.1 this.1, cases sr.2.1.2.2.size_eq_zero.1 this.2, obtain rfl : rls = 1 := sr.2.1.1, rw [if_neg, if_pos, rotate_l, if_neg], {refl}, all_goals {exact dec_trivial} }, { symmetry, rw [zero_add, if_neg, if_pos, rotate_l], { split_ifs, { simp [node3_l, node', add_comm, add_left_comm] }, { simp [node4_l, node', sr.2.1.1, add_comm, add_left_comm] } }, { exact dec_trivial }, { exact not_le_of_gt (nat.succ_lt_succ (add_pos sr.2.1.pos sr.2.2.pos)) } } } }, { cases r with rs rl rx rr, { rw sl.eq_node' at hl ⊢, cases ll with lls lll llx llr; cases lr with lrs lrl lrx lrr; dsimp [balance, balance'], { refl }, { have : size lrl = 0 ∧ size lrr = 0, { have := balanced_sz_zero.1 hl.1.symm, rwa [size, sl.2.2.1, nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this }, cases sl.2.2.2.1.size_eq_zero.1 this.1, cases sl.2.2.2.2.size_eq_zero.1 this.2, obtain rfl : lrs = 1 := sl.2.2.1, rw [if_neg, if_neg, if_pos, rotate_r, if_neg], {refl}, all_goals {exact dec_trivial} }, { have : size lll = 0 ∧ size llr = 0, { have := balanced_sz_zero.1 hl.1, rwa [size, sl.2.1.1, nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this }, cases sl.2.1.2.1.size_eq_zero.1 this.1, cases sl.2.1.2.2.size_eq_zero.1 this.2, obtain rfl : lls = 1 := sl.2.1.1, rw [if_neg, if_neg, if_pos, rotate_r, if_pos], {refl}, all_goals {exact dec_trivial} }, { symmetry, rw [if_neg, if_neg, if_pos, rotate_r], { split_ifs, { simp [node3_r, node', add_comm, add_left_comm] }, { simp [node4_r, node', sl.2.2.1, add_comm, add_left_comm] } }, { exact dec_trivial }, { exact dec_trivial }, { exact not_le_of_gt (nat.succ_lt_succ (add_pos sl.2.1.pos sl.2.2.pos)) } } }, { simp [balance, balance'], symmetry, rw [if_neg], { split_ifs, { have rd : delta ≤ size rl + size rr, { have := lt_of_le_of_lt (nat.mul_le_mul_left _ sl.pos) h, rwa [sr.1, nat.lt_succ_iff] at this }, cases rl with rls rll rlx rlr, { rw [size, zero_add] at rd, exact absurd (le_trans rd (balanced_sz_zero.1 hr.1.symm)) dec_trivial }, cases rr with rrs rrl rrx rrr, { exact absurd (le_trans rd (balanced_sz_zero.1 hr.1)) dec_trivial }, dsimp [rotate_l], split_ifs, { simp [node3_l, node', sr.1, add_comm, add_left_comm] }, { simp [node4_l, node', sr.1, sr.2.1.1, add_comm, add_left_comm] } }, { have ld : delta ≤ size ll + size lr, { have := lt_of_le_of_lt (nat.mul_le_mul_left _ sr.pos) h_1, rwa [sl.1, nat.lt_succ_iff] at this }, cases ll with lls lll llx llr, { rw [size, zero_add] at ld, exact absurd (le_trans ld (balanced_sz_zero.1 hl.1.symm)) dec_trivial }, cases lr with lrs lrl lrx lrr, { exact absurd (le_trans ld (balanced_sz_zero.1 hl.1)) dec_trivial }, dsimp [rotate_r], split_ifs, { simp [node3_r, node', sl.1, add_comm, add_left_comm] }, { simp [node4_r, node', sl.1, sl.2.2.1, add_comm, add_left_comm] } }, { simp [node'] } }, { exact not_le_of_gt (add_le_add sl.pos sr.pos : 2 ≤ ls + rs) } } } end theorem balance_l_eq_balance {l x r} (sl : sized l) (sr : sized r) (H1 : size l = 0 → size r ≤ 1) (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) : @balance_l α l x r = balance l x r := begin cases r with rs rl rx rr, { refl }, { cases l with ls ll lx lr, { have : size rl = 0 ∧ size rr = 0, { have := H1 rfl, rwa [size, sr.1, nat.succ_le_succ_iff, le_zero_iff, add_eq_zero_iff] at this }, cases sr.2.1.size_eq_zero.1 this.1, cases sr.2.2.size_eq_zero.1 this.2, rw sr.eq_node', refl }, { replace H2 : ¬ rs > delta * ls := not_lt_of_le (H2 sl.pos sr.pos), simp [balance_l, balance, H2]; split_ifs; simp [add_comm] } } end /-- `raised n m` means `m` is either equal or one up from `n`. -/ def raised (n m : ℕ) : Prop := m = n ∨ m = n + 1 theorem raised_iff {n m} : raised n m ↔ n ≤ m ∧ m ≤ n + 1 := begin split, rintro (rfl | rfl), { exact ⟨le_rfl, nat.le_succ _⟩ }, { exact ⟨nat.le_succ _, le_rfl⟩ }, { rintro ⟨h₁, h₂⟩, rcases eq_or_lt_of_le h₁ with rfl | h₁, { exact or.inl rfl }, { exact or.inr (le_antisymm h₂ h₁) } } end theorem raised.dist_le {n m} (H : raised n m) : nat.dist n m ≤ 1 := by cases raised_iff.1 H with H1 H2; rwa [nat.dist_eq_sub_of_le H1, tsub_le_iff_left] theorem raised.dist_le' {n m} (H : raised n m) : nat.dist m n ≤ 1 := by rw nat.dist_comm; exact H.dist_le theorem raised.add_left (k) {n m} (H : raised n m) : raised (k + n) (k + m) := begin rcases H with rfl | rfl, { exact or.inl rfl }, { exact or.inr rfl } end theorem raised.add_right (k) {n m} (H : raised n m) : raised (n + k) (m + k) := by rw [add_comm, add_comm m]; exact H.add_left _ theorem raised.right {l x₁ x₂ r₁ r₂} (H : raised (size r₁) (size r₂)) : raised (size (@node' α l x₁ r₁)) (size (@node' α l x₂ r₂)) := begin dsimp [node', size], generalize_hyp : size r₂ = m at H ⊢, rcases H with rfl | rfl, { exact or.inl rfl }, { exact or.inr rfl } end theorem balance_l_eq_balance' {l x r} (hl : balanced l) (hr : balanced r) (sl : sized l) (sr : sized r) (H : (∃ l', raised l' (size l) ∧ balanced_sz l' (size r)) ∨ (∃ r', raised (size r) r' ∧ balanced_sz (size l) r')) : @balance_l α l x r = balance' l x r := begin rw [← balance_eq_balance' hl hr sl sr, balance_l_eq_balance sl sr], { intro l0, rw l0 at H, rcases H with ⟨_, ⟨⟨⟩⟩|⟨⟨⟩⟩, H⟩ | ⟨r', e, H⟩, { exact balanced_sz_zero.1 H.symm }, exact le_trans (raised_iff.1 e).1 (balanced_sz_zero.1 H.symm) }, { intros l1 r1, rcases H with ⟨l', e, H | ⟨H₁, H₂⟩⟩ | ⟨r', e, H | ⟨H₁, H₂⟩⟩, { exact le_trans (le_trans (nat.le_add_left _ _) H) (mul_pos dec_trivial l1 : (0:ℕ)<_) }, { exact le_trans H₂ (nat.mul_le_mul_left _ (raised_iff.1 e).1) }, { cases raised_iff.1 e, unfold delta, linarith }, { exact le_trans (raised_iff.1 e).1 H₂ } } end theorem balance_sz_dual {l r} (H : (∃ l', raised (@size α l) l' ∧ balanced_sz l' (@size α r)) ∨ ∃ r', raised r' (size r) ∧ balanced_sz (size l) r') : (∃ l', raised l' (size (dual r)) ∧ balanced_sz l' (size (dual l))) ∨ ∃ r', raised (size (dual l)) r' ∧ balanced_sz (size (dual r)) r' := begin rw [size_dual, size_dual], exact H.symm.imp (Exists.imp $ λ _, and.imp_right balanced_sz.symm) (Exists.imp $ λ _, and.imp_right balanced_sz.symm) end theorem size_balance_l {l x r} (hl : balanced l) (hr : balanced r) (sl : sized l) (sr : sized r) (H : (∃ l', raised l' (size l) ∧ balanced_sz l' (size r)) ∨ (∃ r', raised (size r) r' ∧ balanced_sz (size l) r')) : size (@balance_l α l x r) = size l + size r + 1 := by rw [balance_l_eq_balance' hl hr sl sr H, size_balance' sl sr] theorem all_balance_l {P l x r} (hl : balanced l) (hr : balanced r) (sl : sized l) (sr : sized r) (H : (∃ l', raised l' (size l) ∧ balanced_sz l' (size r)) ∨ (∃ r', raised (size r) r' ∧ balanced_sz (size l) r')) : all P (@balance_l α l x r) ↔ all P l ∧ P x ∧ all P r := by rw [balance_l_eq_balance' hl hr sl sr H, all_balance'] theorem balance_r_eq_balance' {l x r} (hl : balanced l) (hr : balanced r) (sl : sized l) (sr : sized r) (H : (∃ l', raised (size l) l' ∧ balanced_sz l' (size r)) ∨ (∃ r', raised r' (size r) ∧ balanced_sz (size l) r')) : @balance_r α l x r = balance' l x r := by rw [← dual_dual (balance_r l x r), dual_balance_r, balance_l_eq_balance' hr.dual hl.dual sr.dual sl.dual (balance_sz_dual H), ← dual_balance', dual_dual] theorem size_balance_r {l x r} (hl : balanced l) (hr : balanced r) (sl : sized l) (sr : sized r) (H : (∃ l', raised (size l) l' ∧ balanced_sz l' (size r)) ∨ (∃ r', raised r' (size r) ∧ balanced_sz (size l) r')) : size (@balance_r α l x r) = size l + size r + 1 := by rw [balance_r_eq_balance' hl hr sl sr H, size_balance' sl sr] theorem all_balance_r {P l x r} (hl : balanced l) (hr : balanced r) (sl : sized l) (sr : sized r) (H : (∃ l', raised (size l) l' ∧ balanced_sz l' (size r)) ∨ (∃ r', raised r' (size r) ∧ balanced_sz (size l) r')) : all P (@balance_r α l x r) ↔ all P l ∧ P x ∧ all P r := by rw [balance_r_eq_balance' hl hr sl sr H, all_balance'] /-! ### `bounded` -/ section variable [preorder α] /-- `bounded t lo hi` says that every element `x ∈ t` is in the range `lo < x < hi`, and also this property holds recursively in subtrees, making the full tree a BST. The bounds can be set to `lo = ⊥` and `hi = ⊤` if we care only about the internal ordering constraints. -/ def bounded : ordnode α → with_bot α → with_top α → Prop | nil (some a) (some b) := a < b | nil _ _ := true | (node _ l x r) o₁ o₂ := bounded l o₁ ↑x ∧ bounded r ↑x o₂ theorem bounded.dual : ∀ {t : ordnode α} {o₁ o₂} (h : bounded t o₁ o₂), @bounded αᵒᵈ _ (dual t) o₂ o₁ | nil o₁ o₂ h := by cases o₁; cases o₂; try {trivial}; exact h | (node s l x r) _ _ ⟨ol, or⟩ := ⟨or.dual, ol.dual⟩ theorem bounded.dual_iff {t : ordnode α} {o₁ o₂} : bounded t o₁ o₂ ↔ @bounded αᵒᵈ _ (dual t) o₂ o₁ := ⟨bounded.dual, λ h, by have := bounded.dual h; rwa [dual_dual, order_dual.preorder.dual_dual] at this⟩ theorem bounded.weak_left : ∀ {t : ordnode α} {o₁ o₂}, bounded t o₁ o₂ → bounded t ⊥ o₂ | nil o₁ o₂ h := by cases o₂; try {trivial}; exact h | (node s l x r) _ _ ⟨ol, or⟩ := ⟨ol.weak_left, or⟩ theorem bounded.weak_right : ∀ {t : ordnode α} {o₁ o₂}, bounded t o₁ o₂ → bounded t o₁ ⊤ | nil o₁ o₂ h := by cases o₁; try {trivial}; exact h | (node s l x r) _ _ ⟨ol, or⟩ := ⟨ol, or.weak_right⟩ theorem bounded.weak {t : ordnode α} {o₁ o₂} (h : bounded t o₁ o₂) : bounded t ⊥ ⊤ := h.weak_left.weak_right theorem bounded.mono_left {x y : α} (xy : x ≤ y) : ∀ {t : ordnode α} {o}, bounded t ↑y o → bounded t ↑x o | nil none h := ⟨⟩ | nil (some z) h := lt_of_le_of_lt xy h | (node s l z r) o ⟨ol, or⟩ := ⟨ol.mono_left, or⟩ theorem bounded.mono_right {x y : α} (xy : x ≤ y) : ∀ {t : ordnode α} {o}, bounded t o ↑x → bounded t o ↑y | nil none h := ⟨⟩ | nil (some z) h := lt_of_lt_of_le h xy | (node s l z r) o ⟨ol, or⟩ := ⟨ol, or.mono_right⟩ theorem bounded.to_lt : ∀ {t : ordnode α} {x y : α}, bounded t x y → x < y | nil x y h := h | (node _ l y r) x z ⟨h₁, h₂⟩ := lt_trans h₁.to_lt h₂.to_lt theorem bounded.to_nil {t : ordnode α} : ∀ {o₁ o₂}, bounded t o₁ o₂ → bounded nil o₁ o₂ | none _ h := ⟨⟩ | (some _) none h := ⟨⟩ | (some x) (some y) h := h.to_lt theorem bounded.trans_left {t₁ t₂ : ordnode α} {x : α} : ∀ {o₁ o₂}, bounded t₁ o₁ ↑x → bounded t₂ ↑x o₂ → bounded t₂ o₁ o₂ | none o₂ h₁ h₂ := h₂.weak_left | (some y) o₂ h₁ h₂ := h₂.mono_left (le_of_lt h₁.to_lt) theorem bounded.trans_right {t₁ t₂ : ordnode α} {x : α} : ∀ {o₁ o₂}, bounded t₁ o₁ ↑x → bounded t₂ ↑x o₂ → bounded t₁ o₁ o₂ | o₁ none h₁ h₂ := h₁.weak_right | o₁ (some y) h₁ h₂ := h₁.mono_right (le_of_lt h₂.to_lt) theorem bounded.mem_lt : ∀ {t o} {x : α}, bounded t o ↑x → all (< x) t | nil o x _ := ⟨⟩ | (node _ l y r) o x ⟨h₁, h₂⟩ := ⟨h₁.mem_lt.imp (λ z h, lt_trans h h₂.to_lt), h₂.to_lt, h₂.mem_lt⟩ theorem bounded.mem_gt : ∀ {t o} {x : α}, bounded t ↑x o → all (> x) t | nil o x _ := ⟨⟩ | (node _ l y r) o x ⟨h₁, h₂⟩ := ⟨h₁.mem_gt, h₁.to_lt, h₂.mem_gt.imp (λ z, lt_trans h₁.to_lt)⟩ theorem bounded.of_lt : ∀ {t o₁ o₂} {x : α}, bounded t o₁ o₂ → bounded nil o₁ ↑x → all (< x) t → bounded t o₁ ↑x | nil o₁ o₂ x _ hn _ := hn | (node _ l y r) o₁ o₂ x ⟨h₁, h₂⟩ hn ⟨al₁, al₂, al₃⟩ := ⟨h₁, h₂.of_lt al₂ al₃⟩ theorem bounded.of_gt : ∀ {t o₁ o₂} {x : α}, bounded t o₁ o₂ → bounded nil ↑x o₂ → all (> x) t → bounded t ↑x o₂ | nil o₁ o₂ x _ hn _ := hn | (node _ l y r) o₁ o₂ x ⟨h₁, h₂⟩ hn ⟨al₁, al₂, al₃⟩ := ⟨h₁.of_gt al₂ al₁, h₂⟩ theorem bounded.to_sep {t₁ t₂ o₁ o₂} {x : α} (h₁ : bounded t₁ o₁ ↑x) (h₂ : bounded t₂ ↑x o₂) : t₁.all (λ y, t₂.all (λ z : α, y < z)) := h₁.mem_lt.imp $ λ y yx, h₂.mem_gt.imp $ λ z xz, lt_trans yx xz end /-! ### `valid` -/ section variable [preorder α] /-- The validity predicate for an `ordnode` subtree. This asserts that the `size` fields are correct, the tree is balanced, and the elements of the tree are organized according to the ordering. This version of `valid` also puts all elements in the tree in the interval `(lo, hi)`. -/ structure valid' (lo : with_bot α) (t : ordnode α) (hi : with_top α) : Prop := (ord : t.bounded lo hi) (sz : t.sized) (bal : t.balanced) /-- The validity predicate for an `ordnode` subtree. This asserts that the `size` fields are correct, the tree is balanced, and the elements of the tree are organized according to the ordering. -/ def valid (t : ordnode α) : Prop := valid' ⊥ t ⊤ theorem valid'.mono_left {x y : α} (xy : x ≤ y) {t : ordnode α} {o} (h : valid' ↑y t o) : valid' ↑x t o := ⟨h.1.mono_left xy, h.2, h.3⟩ theorem valid'.mono_right {x y : α} (xy : x ≤ y) {t : ordnode α} {o} (h : valid' o t ↑x) : valid' o t ↑y := ⟨h.1.mono_right xy, h.2, h.3⟩ theorem valid'.trans_left {t₁ t₂ : ordnode α} {x : α} {o₁ o₂} (h : bounded t₁ o₁ ↑x) (H : valid' ↑x t₂ o₂) : valid' o₁ t₂ o₂ := ⟨h.trans_left H.1, H.2, H.3⟩ theorem valid'.trans_right {t₁ t₂ : ordnode α} {x : α} {o₁ o₂} (H : valid' o₁ t₁ ↑x) (h : bounded t₂ ↑x o₂) : valid' o₁ t₁ o₂ := ⟨H.1.trans_right h, H.2, H.3⟩ theorem valid'.of_lt {t : ordnode α} {x : α} {o₁ o₂} (H : valid' o₁ t o₂) (h₁ : bounded nil o₁ ↑x) (h₂ : all (< x) t) : valid' o₁ t ↑x := ⟨H.1.of_lt h₁ h₂, H.2, H.3⟩ theorem valid'.of_gt {t : ordnode α} {x : α} {o₁ o₂} (H : valid' o₁ t o₂) (h₁ : bounded nil ↑x o₂) (h₂ : all (> x) t) : valid' ↑x t o₂ := ⟨H.1.of_gt h₁ h₂, H.2, H.3⟩ theorem valid'.valid {t o₁ o₂} (h : @valid' α _ o₁ t o₂) : valid t := ⟨h.1.weak, h.2, h.3⟩ theorem valid'_nil {o₁ o₂} (h : bounded nil o₁ o₂) : valid' o₁ (@nil α) o₂ := ⟨h, ⟨⟩, ⟨⟩⟩ theorem valid_nil : valid (@nil α) := valid'_nil ⟨⟩ theorem valid'.node {s l x r o₁ o₂} (hl : valid' o₁ l ↑x) (hr : valid' ↑x r o₂) (H : balanced_sz (size l) (size r)) (hs : s = size l + size r + 1) : valid' o₁ (@node α s l x r) o₂ := ⟨⟨hl.1, hr.1⟩, ⟨hs, hl.2, hr.2⟩, ⟨H, hl.3, hr.3⟩⟩ theorem valid'.dual : ∀ {t : ordnode α} {o₁ o₂} (h : valid' o₁ t o₂), @valid' αᵒᵈ _ o₂ (dual t) o₁ | nil o₁ o₂ h := valid'_nil h.1.dual | (node s l x r) o₁ o₂ ⟨⟨ol, or⟩, ⟨rfl, sl, sr⟩, ⟨b, bl, br⟩⟩ := let ⟨ol', sl', bl'⟩ := valid'.dual ⟨ol, sl, bl⟩, ⟨or', sr', br'⟩ := valid'.dual ⟨or, sr, br⟩ in ⟨⟨or', ol'⟩, ⟨by simp [size_dual, add_comm], sr', sl'⟩, ⟨by rw [size_dual, size_dual]; exact b.symm, br', bl'⟩⟩ theorem valid'.dual_iff {t : ordnode α} {o₁ o₂} : valid' o₁ t o₂ ↔ @valid' αᵒᵈ _ o₂ (dual t) o₁ := ⟨valid'.dual, λ h, by have := valid'.dual h; rwa [dual_dual, order_dual.preorder.dual_dual] at this⟩ theorem valid.dual {t : ordnode α} : valid t → @valid αᵒᵈ _ (dual t) := valid'.dual theorem valid.dual_iff {t : ordnode α} : valid t ↔ @valid αᵒᵈ _ (dual t) := valid'.dual_iff theorem valid'.left {s l x r o₁ o₂} (H : valid' o₁ (@node α s l x r) o₂) : valid' o₁ l x := ⟨H.1.1, H.2.2.1, H.3.2.1⟩ theorem valid'.right {s l x r o₁ o₂} (H : valid' o₁ (@node α s l x r) o₂) : valid' ↑x r o₂ := ⟨H.1.2, H.2.2.2, H.3.2.2⟩ theorem valid.left {s l x r} (H : valid (@node α s l x r)) : valid l := H.left.valid theorem valid.right {s l x r} (H : valid (@node α s l x r)) : valid r := H.right.valid theorem valid.size_eq {s l x r} (H : valid (@node α s l x r)) : size (@node α s l x r) = size l + size r + 1 := H.2.1 theorem valid'.node' {l x r o₁ o₂} (hl : valid' o₁ l ↑x) (hr : valid' ↑x r o₂) (H : balanced_sz (size l) (size r)) : valid' o₁ (@node' α l x r) o₂ := hl.node hr H rfl theorem valid'_singleton {x : α} {o₁ o₂} (h₁ : bounded nil o₁ ↑x) (h₂ : bounded nil ↑x o₂) : valid' o₁ (singleton x : ordnode α) o₂ := (valid'_nil h₁).node (valid'_nil h₂) (or.inl zero_le_one) rfl theorem valid_singleton {x : α} : valid (singleton x : ordnode α) := valid'_singleton ⟨⟩ ⟨⟩ theorem valid'.node3_l {l x m y r o₁ o₂} (hl : valid' o₁ l ↑x) (hm : valid' ↑x m ↑y) (hr : valid' ↑y r o₂) (H1 : balanced_sz (size l) (size m)) (H2 : balanced_sz (size l + size m + 1) (size r)) : valid' o₁ (@node3_l α l x m y r) o₂ := (hl.node' hm H1).node' hr H2 theorem valid'.node3_r {l x m y r o₁ o₂} (hl : valid' o₁ l ↑x) (hm : valid' ↑x m ↑y) (hr : valid' ↑y r o₂) (H1 : balanced_sz (size l) (size m + size r + 1)) (H2 : balanced_sz (size m) (size r)) : valid' o₁ (@node3_r α l x m y r) o₂ := hl.node' (hm.node' hr H2) H1 theorem valid'.node4_l_lemma₁ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9) (mr₂ : b + c + 1 ≤ 3 * d) (mm₁ : b ≤ 3 * c) : b < 3 * a + 1 := by linarith theorem valid'.node4_l_lemma₂ {b c d : ℕ} (mr₂ : b + c + 1 ≤ 3 * d) : c ≤ 3 * d := by linarith theorem valid'.node4_l_lemma₃ {b c d : ℕ} (mr₁ : 2 * d ≤ b + c + 1) (mm₁ : b ≤ 3 * c) : d ≤ 3 * c := by linarith theorem valid'.node4_l_lemma₄ {a b c d : ℕ} (lr₁ : 3 * a ≤ b + c + 1 + d) (mr₂ : b + c + 1 ≤ 3 * d) (mm₁ : b ≤ 3 * c) : a + b + 1 ≤ 3 * (c + d + 1) := by linarith theorem valid'.node4_l_lemma₅ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9) (mr₁ : 2 * d ≤ b + c + 1) (mm₂ : c ≤ 3 * b) : c + d + 1 ≤ 3 * (a + b + 1) := by linarith theorem valid'.node4_l {l x m y r o₁ o₂} (hl : valid' o₁ l ↑x) (hm : valid' ↑x m ↑y) (hr : valid' ↑y r o₂) (Hm : 0 < size m) (H : (size l = 0 ∧ size m = 1 ∧ size r ≤ 1) ∨ (0 < size l ∧ ratio * size r ≤ size m ∧ delta * size l ≤ size m + size r ∧ 3 * (size m + size r) ≤ 16 * size l + 9 ∧ size m ≤ delta * size r)) : valid' o₁ (@node4_l α l x m y r) o₂ := begin cases m with s ml z mr, {cases Hm}, suffices : balanced_sz (size l) (size ml) ∧ balanced_sz (size mr) (size r) ∧ balanced_sz (size l + size ml + 1) (size mr + size r + 1), from (valid'.node' (hl.node' hm.left this.1) (hm.right.node' hr this.2.1) this.2.2), rcases H with ⟨l0, m1, r0⟩ | ⟨l0, mr₁, lr₁, lr₂, mr₂⟩, { rw [hm.2.size_eq, nat.succ_inj', add_eq_zero_iff] at m1, rw [l0, m1.1, m1.2], rcases size r with _|_|_; exact dec_trivial }, { cases nat.eq_zero_or_pos (size r) with r0 r0, { rw r0 at mr₂, cases not_le_of_lt Hm mr₂ }, rw [hm.2.size_eq] at lr₁ lr₂ mr₁ mr₂, by_cases mm : size ml + size mr ≤ 1, { have r1 := le_antisymm ((mul_le_mul_left dec_trivial).1 (le_trans mr₁ (nat.succ_le_succ mm) : _ ≤ ratio * 1)) r0, rw [r1, add_assoc] at lr₁, have l1 := le_antisymm ((mul_le_mul_left dec_trivial).1 (le_trans lr₁ (add_le_add_right mm 2) : _ ≤ delta * 1)) l0, rw [l1, r1], cases size ml; cases size mr, { exact dec_trivial }, { rw zero_add at mm, rcases mm with _|⟨_,⟨⟩⟩, exact dec_trivial }, { rcases mm with _|⟨_,⟨⟩⟩, exact dec_trivial }, { rw nat.succ_add at mm, rcases mm with _|⟨_,⟨⟩⟩ } }, rcases hm.3.1.resolve_left mm with ⟨mm₁, mm₂⟩, cases nat.eq_zero_or_pos (size ml) with ml0 ml0, { rw [ml0, mul_zero, le_zero_iff] at mm₂, rw [ml0, mm₂] at mm, cases mm dec_trivial }, have : 2 * size l ≤ size ml + size mr + 1, { have := nat.mul_le_mul_left _ lr₁, rw [mul_left_comm, mul_add] at this, have := le_trans this (add_le_add_left mr₁ _), rw [← nat.succ_mul] at this, exact (mul_le_mul_left dec_trivial).1 this }, refine ⟨or.inr ⟨_, _⟩, or.inr ⟨_, _⟩, or.inr ⟨_, _⟩⟩, { refine (mul_le_mul_left dec_trivial).1 (le_trans this _), rw [two_mul, nat.succ_le_iff], refine add_lt_add_of_lt_of_le _ mm₂, simpa using (mul_lt_mul_right ml0).2 (dec_trivial:1<3) }, { exact nat.le_of_lt_succ (valid'.node4_l_lemma₁ lr₂ mr₂ mm₁) }, { exact valid'.node4_l_lemma₂ mr₂ }, { exact valid'.node4_l_lemma₃ mr₁ mm₁ }, { exact valid'.node4_l_lemma₄ lr₁ mr₂ mm₁ }, { exact valid'.node4_l_lemma₅ lr₂ mr₁ mm₂ } } end theorem valid'.rotate_l_lemma₁ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (hb₂ : c ≤ 3 * b) : a ≤ 3 * b := by linarith theorem valid'.rotate_l_lemma₂ {a b c : ℕ} (H3 : 2 * (b + c) ≤ 9 * a + 3) (h : b < 2 * c) : b < 3 * a + 1 := by linarith theorem valid'.rotate_l_lemma₃ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (h : b < 2 * c) : a + b < 3 * c := by linarith theorem valid'.rotate_l_lemma₄ {a b : ℕ} (H3 : 2 * b ≤ 9 * a + 3) : 3 * b ≤ 16 * a + 9 := by linarith theorem valid'.rotate_l {l x r o₁ o₂} (hl : valid' o₁ l ↑x) (hr : valid' ↑x r o₂) (H1 : ¬ size l + size r ≤ 1) (H2 : delta * size l < size r) (H3 : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3) : valid' o₁ (@rotate_l α l x r) o₂ := begin cases r with rs rl rx rr, {cases H2}, rw [hr.2.size_eq, nat.lt_succ_iff] at H2, rw [hr.2.size_eq] at H3, replace H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2 := H3.imp (@nat.le_of_add_le_add_right 2 _ _) nat.le_of_succ_le_succ, have H3_0 : size l = 0 → size rl + size rr ≤ 2, { intro l0, rw l0 at H3, exact (or_iff_right_of_imp $ by exact λ h, (mul_le_mul_left dec_trivial).1 (le_trans h dec_trivial)).1 H3 }, have H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3 := λ l0 : 1 ≤ size l, (or_iff_left_of_imp $ by intro; linarith).1 H3, have ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1, {intros, linarith}, have hlp : size l > 0 → ¬ size rl + size rr ≤ 1 := λ l0 hb, absurd (le_trans (le_trans (nat.mul_le_mul_left _ l0) H2) hb) dec_trivial, rw rotate_l, split_ifs, { have rr0 : size rr > 0 := (mul_lt_mul_left dec_trivial).1 (lt_of_le_of_lt (nat.zero_le _) h : ratio * 0 < _), suffices : balanced_sz (size l) (size rl) ∧ balanced_sz (size l + size rl + 1) (size rr), { exact hl.node3_l hr.left hr.right this.1 this.2 }, cases nat.eq_zero_or_pos (size l) with l0 l0, { rw l0, replace H3 := H3_0 l0, have := hr.3.1, cases nat.eq_zero_or_pos (size rl) with rl0 rl0, { rw rl0 at this ⊢, rw le_antisymm (balanced_sz_zero.1 this.symm) rr0, exact dec_trivial }, have rr1 : size rr = 1 := le_antisymm (ablem rl0 H3) rr0, rw add_comm at H3, rw [rr1, show size rl = 1, from le_antisymm (ablem rr0 H3) rl0], exact dec_trivial }, replace H3 := H3p l0, rcases hr.3.1.resolve_left (hlp l0) with ⟨hb₁, hb₂⟩, refine ⟨or.inr ⟨_, _⟩, or.inr ⟨_, _⟩⟩, { exact valid'.rotate_l_lemma₁ H2 hb₂ }, { exact nat.le_of_lt_succ (valid'.rotate_l_lemma₂ H3 h) }, { exact valid'.rotate_l_lemma₃ H2 h }, { exact le_trans hb₂ (nat.mul_le_mul_left _ $ le_trans (nat.le_add_left _ _) (nat.le_add_right _ _)) } }, { cases nat.eq_zero_or_pos (size rl) with rl0 rl0, { rw [rl0, not_lt, le_zero_iff, nat.mul_eq_zero] at h, replace h := h.resolve_left dec_trivial, rw [rl0, h, le_zero_iff, nat.mul_eq_zero] at H2, rw [hr.2.size_eq, rl0, h, H2.resolve_left dec_trivial] at H1, cases H1 dec_trivial }, refine hl.node4_l hr.left hr.right rl0 _, cases nat.eq_zero_or_pos (size l) with l0 l0, { replace H3 := H3_0 l0, cases nat.eq_zero_or_pos (size rr) with rr0 rr0, { have := hr.3.1, rw rr0 at this, exact or.inl ⟨l0, le_antisymm (balanced_sz_zero.1 this) rl0, rr0.symm ▸ zero_le_one⟩ }, exact or.inl ⟨l0, le_antisymm (ablem rr0 $ by rwa add_comm) rl0, ablem rl0 H3⟩ }, exact or.inr ⟨l0, not_lt.1 h, H2, valid'.rotate_l_lemma₄ (H3p l0), (hr.3.1.resolve_left (hlp l0)).1⟩ } end theorem valid'.rotate_r {l x r o₁ o₂} (hl : valid' o₁ l ↑x) (hr : valid' ↑x r o₂) (H1 : ¬ size l + size r ≤ 1) (H2 : delta * size r < size l) (H3 : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3) : valid' o₁ (@rotate_r α l x r) o₂ := begin refine valid'.dual_iff.2 _, rw dual_rotate_r, refine hr.dual.rotate_l hl.dual _ _ _, { rwa [size_dual, size_dual, add_comm] }, { rwa [size_dual, size_dual] }, { rwa [size_dual, size_dual] } end theorem valid'.balance'_aux {l x r o₁ o₂} (hl : valid' o₁ l ↑x) (hr : valid' ↑x r o₂) (H₁ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3) (H₂ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : valid' o₁ (@balance' α l x r) o₂ := begin rw balance', split_ifs, { exact hl.node' hr (or.inl h) }, { exact hl.rotate_l hr h h_1 H₁ }, { exact hl.rotate_r hr h h_2 H₂ }, { exact hl.node' hr (or.inr ⟨not_lt.1 h_2, not_lt.1 h_1⟩) } end theorem valid'.balance'_lemma {α l l' r r'} (H1 : balanced_sz l' r') (H2 : nat.dist (@size α l) l' ≤ 1 ∧ size r = r' ∨ nat.dist (size r) r' ≤ 1 ∧ size l = l') : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3 := begin suffices : @size α r ≤ 3 * (size l + 1), { cases nat.eq_zero_or_pos (size l) with l0 l0, { apply or.inr, rwa l0 at this }, change 1 ≤ _ at l0, apply or.inl, linarith }, rcases H2 with ⟨hl, rfl⟩ | ⟨hr, rfl⟩; rcases H1 with h | ⟨h₁, h₂⟩, { exact le_trans (nat.le_add_left _ _) (le_trans h (nat.le_add_left _ _)) }, { exact le_trans h₂ (nat.mul_le_mul_left _ $ le_trans (nat.dist_tri_right _ _) (nat.add_le_add_left hl _)) }, { exact le_trans (nat.dist_tri_left' _ _) (le_trans (add_le_add hr (le_trans (nat.le_add_left _ _) h)) dec_trivial) }, { rw nat.mul_succ, exact le_trans (nat.dist_tri_right' _ _) (add_le_add h₂ (le_trans hr dec_trivial)) }, end theorem valid'.balance' {l x r o₁ o₂} (hl : valid' o₁ l ↑x) (hr : valid' ↑x r o₂) (H : ∃ l' r', balanced_sz l' r' ∧ (nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ nat.dist (size r) r' ≤ 1 ∧ size l = l')) : valid' o₁ (@balance' α l x r) o₂ := let ⟨l', r', H1, H2⟩ := H in valid'.balance'_aux hl hr (valid'.balance'_lemma H1 H2) (valid'.balance'_lemma H1.symm H2.symm) theorem valid'.balance {l x r o₁ o₂} (hl : valid' o₁ l ↑x) (hr : valid' ↑x r o₂) (H : ∃ l' r', balanced_sz l' r' ∧ (nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ nat.dist (size r) r' ≤ 1 ∧ size l = l')) : valid' o₁ (@balance α l x r) o₂ := by rw balance_eq_balance' hl.3 hr.3 hl.2 hr.2; exact hl.balance' hr H theorem valid'.balance_l_aux {l x r o₁ o₂} (hl : valid' o₁ l ↑x) (hr : valid' ↑x r o₂) (H₁ : size l = 0 → size r ≤ 1) (H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) (H₃ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : valid' o₁ (@balance_l α l x r) o₂ := begin rw [balance_l_eq_balance hl.2 hr.2 H₁ H₂, balance_eq_balance' hl.3 hr.3 hl.2 hr.2], refine hl.balance'_aux hr (or.inl _) H₃, cases nat.eq_zero_or_pos (size r) with r0 r0, { rw r0, exact nat.zero_le _ }, cases nat.eq_zero_or_pos (size l) with l0 l0, { rw l0, exact le_trans (nat.mul_le_mul_left _ (H₁ l0)) dec_trivial }, replace H₂ : _ ≤ 3 * _ := H₂ l0 r0, linarith end theorem valid'.balance_l {l x r o₁ o₂} (hl : valid' o₁ l ↑x) (hr : valid' ↑x r o₂) (H : (∃ l', raised l' (size l) ∧ balanced_sz l' (size r)) ∨ (∃ r', raised (size r) r' ∧ balanced_sz (size l) r')) : valid' o₁ (@balance_l α l x r) o₂ := begin rw balance_l_eq_balance' hl.3 hr.3 hl.2 hr.2 H, refine hl.balance' hr _, rcases H with ⟨l', e, H⟩ | ⟨r', e, H⟩, { exact ⟨_, _, H, or.inl ⟨e.dist_le', rfl⟩⟩ }, { exact ⟨_, _, H, or.inr ⟨e.dist_le, rfl⟩⟩ }, end theorem valid'.balance_r_aux {l x r o₁ o₂} (hl : valid' o₁ l ↑x) (hr : valid' ↑x r o₂) (H₁ : size r = 0 → size l ≤ 1) (H₂ : 1 ≤ size r → 1 ≤ size l → size l ≤ delta * size r) (H₃ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3) : valid' o₁ (@balance_r α l x r) o₂ := begin rw [valid'.dual_iff, dual_balance_r], have := hr.dual.balance_l_aux hl.dual, rw [size_dual, size_dual] at this, exact this H₁ H₂ H₃ end theorem valid'.balance_r {l x r o₁ o₂} (hl : valid' o₁ l ↑x) (hr : valid' ↑x r o₂) (H : (∃ l', raised (size l) l' ∧ balanced_sz l' (size r)) ∨ (∃ r', raised r' (size r) ∧ balanced_sz (size l) r')) : valid' o₁ (@balance_r α l x r) o₂ := by rw [valid'.dual_iff, dual_balance_r]; exact hr.dual.balance_l hl.dual (balance_sz_dual H) theorem valid'.erase_max_aux {s l x r o₁ o₂} (H : valid' o₁ (node s l x r) o₂) : valid' o₁ (@erase_max α (node' l x r)) ↑(find_max' x r) ∧ size (node' l x r) = size (erase_max (node' l x r)) + 1 := begin have := H.2.eq_node', rw this at H, clear this, induction r with rs rl rx rr IHrl IHrr generalizing l x o₁, { exact ⟨H.left, rfl⟩ }, have := H.2.2.2.eq_node', rw this at H ⊢, rcases IHrr H.right with ⟨h, e⟩, refine ⟨valid'.balance_l H.left h (or.inr ⟨_, or.inr e, H.3.1⟩), _⟩, rw [erase_max, size_balance_l H.3.2.1 h.3 H.2.2.1 h.2 (or.inr ⟨_, or.inr e, H.3.1⟩)], rw [size, e], refl end theorem valid'.erase_min_aux {s l x r o₁ o₂} (H : valid' o₁ (node s l x r) o₂) : valid' ↑(find_min' l x) (@erase_min α (node' l x r)) o₂ ∧ size (node' l x r) = size (erase_min (node' l x r)) + 1 := by have := H.dual.erase_max_aux; rwa [← dual_node', size_dual, ← dual_erase_min, size_dual, ← valid'.dual_iff, find_max'_dual] at this theorem erase_min.valid : ∀ {t} (h : @valid α _ t), valid (erase_min t) | nil _ := valid_nil | (node _ l x r) h := by rw h.2.eq_node'; exact h.erase_min_aux.1.valid theorem erase_max.valid {t} (h : @valid α _ t) : valid (erase_max t) := by rw [valid.dual_iff, dual_erase_max]; exact erase_min.valid h.dual theorem valid'.glue_aux {l r o₁ o₂} (hl : valid' o₁ l o₂) (hr : valid' o₁ r o₂) (sep : l.all (λ x, r.all (λ y, x < y))) (bal : balanced_sz (size l) (size r)) : valid' o₁ (@glue α l r) o₂ ∧ size (glue l r) = size l + size r := begin cases l with ls ll lx lr, {exact ⟨hr, (zero_add _).symm⟩ }, cases r with rs rl rx rr, {exact ⟨hl, rfl⟩ }, dsimp [glue], split_ifs, { rw [split_max_eq, glue], cases valid'.erase_max_aux hl with v e, suffices H, refine ⟨valid'.balance_r v (hr.of_gt _ _) H, _⟩, { refine find_max'_all lx lr hl.1.2.to_nil (sep.2.2.imp _), exact λ x h, hr.1.2.to_nil.mono_left (le_of_lt h.2.1) }, { exact @find_max'_all _ (λ a, all (> a) (node rs rl rx rr)) lx lr sep.2.1 sep.2.2 }, { rw [size_balance_r v.3 hr.3 v.2 hr.2 H, add_right_comm, ← e, hl.2.1], refl }, { refine or.inl ⟨_, or.inr e, _⟩, rwa hl.2.eq_node' at bal } }, { rw [split_min_eq, glue], cases valid'.erase_min_aux hr with v e, suffices H, refine ⟨valid'.balance_l (hl.of_lt _ _) v H, _⟩, { refine @find_min'_all _ (λ a, bounded nil o₁ ↑a) rl rx (sep.2.1.1.imp _) hr.1.1.to_nil, exact λ y h, hl.1.1.to_nil.mono_right (le_of_lt h) }, { exact @find_min'_all _ (λ a, all (< a) (node ls ll lx lr)) rl rx (all_iff_forall.2 $ λ x hx, sep.imp $ λ y hy, all_iff_forall.1 hy.1 _ hx) (sep.imp $ λ y hy, hy.2.1) }, { rw [size_balance_l hl.3 v.3 hl.2 v.2 H, add_assoc, ← e, hr.2.1], refl }, { refine or.inr ⟨_, or.inr e, _⟩, rwa hr.2.eq_node' at bal } }, end theorem valid'.glue {l x r o₁ o₂} (hl : valid' o₁ l ↑(x:α)) (hr : valid' ↑x r o₂) : balanced_sz (size l) (size r) → valid' o₁ (@glue α l r) o₂ ∧ size (@glue α l r) = size l + size r := valid'.glue_aux (hl.trans_right hr.1) (hr.trans_left hl.1) (hl.1.to_sep hr.1) theorem valid'.merge_lemma {a b c : ℕ} (h₁ : 3 * a < b + c + 1) (h₂ : b ≤ 3 * c) : 2 * (a + b) ≤ 9 * c + 5 := by linarith theorem valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t} (hl : valid' o₁ (@node α ls ll lx lr) o₂) (hr : valid' o₁ (node rs rl rx rr) o₂) (h : delta * ls < rs) (v : valid' o₁ t ↑rx) (e : size t = ls + size rl) : valid' o₁ (balance_l t rx rr) o₂ ∧ size (balance_l t rx rr) = ls + rs := begin rw hl.2.1 at e, rw [hl.2.1, hr.2.1, delta] at h, rcases hr.3.1 with H|⟨hr₁, hr₂⟩, {linarith}, suffices H₂, suffices H₁, refine ⟨valid'.balance_l_aux v hr.right H₁ H₂ _, _⟩, { rw e, exact or.inl (valid'.merge_lemma h hr₁) }, { rw [balance_l_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2, size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1], simp [add_comm, add_left_comm] }, { rw [e, add_right_comm], rintro ⟨⟩ }, { intros _ h₁, rw e, unfold delta at hr₂ ⊢, linarith } end theorem valid'.merge_aux {l r o₁ o₂} (hl : valid' o₁ l o₂) (hr : valid' o₁ r o₂) (sep : l.all (λ x, r.all (λ y, x < y))) : valid' o₁ (@merge α l r) o₂ ∧ size (merge l r) = size l + size r := begin induction l with ls ll lx lr IHll IHlr generalizing o₁ o₂ r, { exact ⟨hr, (zero_add _).symm⟩ }, induction r with rs rl rx rr IHrl IHrr generalizing o₁ o₂, { exact ⟨hl, rfl⟩ }, rw [merge_node], split_ifs, { cases IHrl (sep.imp $ λ x h, h.1) (hl.of_lt hr.1.1.to_nil $ sep.imp $ λ x h, h.2.1) hr.left with v e, exact valid'.merge_aux₁ hl hr h v e }, { cases IHlr hl.right (hr.of_gt hl.1.2.to_nil sep.2.1) sep.2.2 with v e, have := valid'.merge_aux₁ hr.dual hl.dual h_1 v.dual, rw [size_dual, add_comm, size_dual, ← dual_balance_r, ← valid'.dual_iff, size_dual, add_comm rs] at this, exact this e }, { refine valid'.glue_aux hl hr sep (or.inr ⟨not_lt.1 h_1, not_lt.1 h⟩) } end theorem valid.merge {l r} (hl : valid l) (hr : valid r) (sep : l.all (λ x, r.all (λ y, x < y))) : valid (@merge α l r) := (valid'.merge_aux hl hr sep).1 theorem insert_with.valid_aux [is_total α (≤)] [@decidable_rel α (≤)] (f : α → α) (x : α) (hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) : ∀ {t o₁ o₂}, valid' o₁ t o₂ → bounded nil o₁ ↑x → bounded nil ↑x o₂ → valid' o₁ (insert_with f x t) o₂ ∧ raised (size t) (size (insert_with f x t)) | nil o₁ o₂ _ bl br := ⟨valid'_singleton bl br, or.inr rfl⟩ | (node sz l y r) o₁ o₂ h bl br := begin rw [insert_with, cmp_le], split_ifs; rw [insert_with], { rcases h with ⟨⟨lx, xr⟩, hs, hb⟩, rcases hf _ ⟨h_1, h_2⟩ with ⟨xf, fx⟩, refine ⟨⟨⟨lx.mono_right (le_trans h_2 xf), xr.mono_left (le_trans fx h_1)⟩, hs, hb⟩, or.inl rfl⟩ }, { rcases insert_with.valid_aux h.left bl (lt_of_le_not_le h_1 h_2) with ⟨vl, e⟩, suffices H, { refine ⟨vl.balance_l h.right H, _⟩, rw [size_balance_l vl.3 h.3.2.2 vl.2 h.2.2.2 H, h.2.size_eq], refine (e.add_right _).add_right _ }, { exact or.inl ⟨_, e, h.3.1⟩ } }, { have : y < x := lt_of_le_not_le ((total_of (≤) _ _).resolve_left h_1) h_1, rcases insert_with.valid_aux h.right this br with ⟨vr, e⟩, suffices H, { refine ⟨h.left.balance_r vr H, _⟩, rw [size_balance_r h.3.2.1 vr.3 h.2.2.1 vr.2 H, h.2.size_eq], refine (e.add_left _).add_right _ }, { exact or.inr ⟨_, e, h.3.1⟩ } }, end theorem insert_with.valid [is_total α (≤)] [@decidable_rel α (≤)] (f : α → α) (x : α) (hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) {t} (h : valid t) : valid (insert_with f x t) := (insert_with.valid_aux _ _ hf h ⟨⟩ ⟨⟩).1 theorem insert_eq_insert_with [@decidable_rel α (≤)] (x : α) : ∀ t, ordnode.insert x t = insert_with (λ _, x) x t | nil := rfl | (node _ l y r) := by unfold ordnode.insert insert_with; cases cmp_le x y; unfold ordnode.insert insert_with; simp [insert_eq_insert_with] theorem insert.valid [is_total α (≤)] [@decidable_rel α (≤)] (x : α) {t} (h : valid t) : valid (ordnode.insert x t) := by rw insert_eq_insert_with; exact insert_with.valid _ _ (λ _ _, ⟨le_rfl, le_rfl⟩) h theorem insert'_eq_insert_with [@decidable_rel α (≤)] (x : α) : ∀ t, insert' x t = insert_with id x t | nil := rfl | (node _ l y r) := by unfold insert' insert_with; cases cmp_le x y; unfold insert' insert_with; simp [insert'_eq_insert_with] theorem insert'.valid [is_total α (≤)] [@decidable_rel α (≤)] (x : α) {t} (h : valid t) : valid (insert' x t) := by rw insert'_eq_insert_with; exact insert_with.valid _ _ (λ _, id) h theorem valid'.map_aux {β} [preorder β] {f : α → β} (f_strict_mono : strict_mono f) {t a₁ a₂} (h : valid' a₁ t a₂) : valid' (option.map f a₁) (map f t) (option.map f a₂) ∧ (map f t).size = t.size := begin induction t generalizing a₁ a₂, { simp [map], apply valid'_nil, cases a₁, { trivial }, cases a₂, { trivial }, simp [bounded], exact f_strict_mono h.ord }, { have t_ih_l' := t_ih_l h.left, have t_ih_r' := t_ih_r h.right, clear t_ih_l t_ih_r, cases t_ih_l' with t_l_valid t_l_size, cases t_ih_r' with t_r_valid t_r_size, simp [map], split, { exact and.intro t_l_valid.ord t_r_valid.ord }, { repeat { split }, { rw [t_l_size, t_r_size], exact h.sz.1 }, { exact t_l_valid.sz }, { exact t_r_valid.sz } }, { repeat { split }, { rw [t_l_size, t_r_size], exact h.bal.1 }, { exact t_l_valid.bal }, { exact t_r_valid.bal } } }, end theorem map.valid {β} [preorder β] {f : α → β} (f_strict_mono : strict_mono f) {t} (h : valid t) : valid (map f t) := (valid'.map_aux f_strict_mono h).1 theorem valid'.erase_aux [@decidable_rel α (≤)] (x : α) {t a₁ a₂} (h : valid' a₁ t a₂) : valid' a₁ (erase x t) a₂ ∧ raised (erase x t).size t.size := begin induction t generalizing a₁ a₂, { simp [erase, raised], exact h }, { simp [erase], have t_ih_l' := t_ih_l h.left, have t_ih_r' := t_ih_r h.right, clear t_ih_l t_ih_r, cases t_ih_l' with t_l_valid t_l_size, cases t_ih_r' with t_r_valid t_r_size, cases (cmp_le x t_x); simp [erase._match_1]; rw h.sz.1, { suffices h_balanceable, split, { exact valid'.balance_r t_l_valid h.right h_balanceable }, { rw size_balance_r t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz h_balanceable, repeat { apply raised.add_right }, exact t_l_size }, { left, existsi t_l.size, exact (and.intro t_l_size h.bal.1) } }, { have h_glue := valid'.glue h.left h.right h.bal.1, cases h_glue with h_glue_valid h_glue_sized, split, { exact h_glue_valid }, { right, rw h_glue_sized } }, { suffices h_balanceable, split, { exact valid'.balance_l h.left t_r_valid h_balanceable }, { rw size_balance_l h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz h_balanceable, apply raised.add_right, apply raised.add_left, exact t_r_size }, { right, existsi t_r.size, exact (and.intro t_r_size h.bal.1) } } }, end theorem erase.valid [@decidable_rel α (≤)] (x : α) {t} (h : valid t) : valid (erase x t) := (valid'.erase_aux x h).1 theorem size_erase_of_mem [@decidable_rel α (≤)] {x : α} {t a₁ a₂} (h : valid' a₁ t a₂) (h_mem : x ∈ t) : size (erase x t) = size t - 1 := begin induction t generalizing a₁ a₂ h h_mem, { contradiction }, { have t_ih_l' := t_ih_l h.left, have t_ih_r' := t_ih_r h.right, clear t_ih_l t_ih_r, unfold has_mem.mem mem at h_mem, unfold erase, cases (cmp_le x t_x); simp [mem._match_1] at h_mem; simp [erase._match_1], { have t_ih_l := t_ih_l' h_mem, clear t_ih_l' t_ih_r', have t_l_h := valid'.erase_aux x h.left, cases t_l_h with t_l_valid t_l_size, rw size_balance_r t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz (or.inl (exists.intro t_l.size (and.intro t_l_size h.bal.1))), rw [t_ih_l, h.sz.1], have h_pos_t_l_size := pos_size_of_mem h.left.sz h_mem, cases t_l.size with t_l_size, { cases h_pos_t_l_size }, simp [nat.succ_add] }, { rw [(valid'.glue h.left h.right h.bal.1).2, h.sz.1], refl }, { have t_ih_r := t_ih_r' h_mem, clear t_ih_l' t_ih_r', have t_r_h := valid'.erase_aux x h.right, cases t_r_h with t_r_valid t_r_size, rw size_balance_l h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz (or.inr (exists.intro t_r.size (and.intro t_r_size h.bal.1))), rw [t_ih_r, h.sz.1], have h_pos_t_r_size := pos_size_of_mem h.right.sz h_mem, cases t_r.size with t_r_size, { cases h_pos_t_r_size }, simp [nat.succ_add, nat.add_succ] } }, end end end ordnode /-- An `ordset α` is a finite set of values, represented as a tree. The operations on this type maintain that the tree is balanced and correctly stores subtree sizes at each level. The correctness property of the tree is baked into the type, so all operations on this type are correct by construction. -/ def ordset (α : Type*) [preorder α] := {t : ordnode α // t.valid} namespace ordset open ordnode variable [preorder α] /-- O(1). The empty set. -/ def nil : ordset α := ⟨nil, ⟨⟩, ⟨⟩, ⟨⟩⟩ /-- O(1). Get the size of the set. -/ def size (s : ordset α) : ℕ := s.1.size /-- O(1). Construct a singleton set containing value `a`. -/ protected def singleton (a : α) : ordset α := ⟨singleton a, valid_singleton⟩ instance : has_emptyc (ordset α) := ⟨nil⟩ instance : inhabited (ordset α) := ⟨nil⟩ instance : has_singleton α (ordset α) := ⟨ordset.singleton⟩ /-- O(1). Is the set empty? -/ def empty (s : ordset α) : Prop := s = ∅ theorem empty_iff {s : ordset α} : s = ∅ ↔ s.1.empty := ⟨λ h, by cases h; exact rfl, λ h, by cases s; cases s_val; [exact rfl, cases h]⟩ instance : decidable_pred (@empty α _) := λ s, decidable_of_iff' _ empty_iff /-- O(log n). Insert an element into the set, preserving balance and the BST property. If an equivalent element is already in the set, this replaces it. -/ protected def insert [is_total α (≤)] [@decidable_rel α (≤)] (x : α) (s : ordset α) : ordset α := ⟨ordnode.insert x s.1, insert.valid _ s.2⟩ instance [is_total α (≤)] [@decidable_rel α (≤)] : has_insert α (ordset α) := ⟨ordset.insert⟩ /-- O(log n). Insert an element into the set, preserving balance and the BST property. If an equivalent element is already in the set, the set is returned as is. -/ def insert' [is_total α (≤)] [@decidable_rel α (≤)] (x : α) (s : ordset α) : ordset α := ⟨insert' x s.1, insert'.valid _ s.2⟩ section variables [@decidable_rel α (≤)] /-- O(log n). Does the set contain the element `x`? That is, is there an element that is equivalent to `x` in the order? -/ def mem (x : α) (s : ordset α) : bool := x ∈ s.val /-- O(log n). Retrieve an element in the set that is equivalent to `x` in the order, if it exists. -/ def find (x : α) (s : ordset α) : option α := ordnode.find x s.val instance : has_mem α (ordset α) := ⟨λ x s, mem x s⟩ instance mem.decidable (x : α) (s : ordset α) : decidable (x ∈ s) := bool.decidable_eq _ _ theorem pos_size_of_mem {x : α} {t : ordset α} (h_mem : x ∈ t) : 0 < size t := begin simp [has_mem.mem, mem] at h_mem, apply ordnode.pos_size_of_mem t.property.sz h_mem, end end /-- O(log n). Remove an element from the set equivalent to `x`. Does nothing if there is no such element. -/ def erase [@decidable_rel α (≤)] (x : α) (s : ordset α) : ordset α := ⟨ordnode.erase x s.val, ordnode.erase.valid x s.property⟩ /-- O(n). Map a function across a tree, without changing the structure. -/ def map {β} [preorder β] (f : α → β) (f_strict_mono : strict_mono f) (s : ordset α) : ordset β := ⟨ordnode.map f s.val, ordnode.map.valid f_strict_mono s.property⟩ end ordset
3bc22c2e798a304e55f198e82a76588e77d02aa8
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/mergeSortCPDT.lean
d7a7ccca4a91fef289da38bddf5931e415e2be91
[ "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
1,709
lean
def List.insert (p : α → α → Bool) (a : α) (bs : List α) : List α := match bs with | [] => [a] | b :: bs' => if p a b then a :: bs else b :: bs'.insert p a def List.merge (p : α → α → Bool) (as bs : List α) : List α := match as with | [] => bs | a :: as' => insert p a (merge p as' bs) def List.split (as : List α) : List α × List α := match as with | [] => ([], []) | [a] => ([a], []) | a :: b :: as => let (as, bs) := split as (a :: as, b :: bs) @[simp] def List.atLeast2 (as : List α) : Bool := match as with | [] => false | [_] => false | _::_::_ => true theorem List.length_split_of_atLeast2 {as : List α} (h : as.atLeast2) : as.split.1.length < as.length ∧ as.split.2.length < as.length := by match as with | [] => simp at h | [_] => simp at h | [_, _] => simp [split] | [_, _, _] => simp [split] | a::b::c::d::as => -- TODO: simplify using linear arith and more automation have : (c::d::as).atLeast2 := by simp_arith have ih := length_split_of_atLeast2 this simp_arith [split] at ih |- have ⟨ih₁, ih₂⟩ := ih exact ⟨Nat.le_trans ih₁ (by simp_arith), Nat.le_trans ih₂ (by simp_arith)⟩ def List.mergeSort (p : α → α → Bool) (as : List α) : List α := if h : as.atLeast2 then match he:as.split with | (as', bs') => -- TODO: simplify using more automation have ⟨h₁, h₂⟩ := length_split_of_atLeast2 h have : as'.length < as.length := by simp [he] at h₁; assumption have : bs'.length < as.length := by simp [he] at h₂; assumption merge p (mergeSort p as') (mergeSort p bs') else as termination_by _ as => as.length
39b0264e1c06257cfcdd323b7476ce44c3c3518f
fffbc47930dc6615e66ece42324ce57a21d5b64b
/src/group_theory/subgroup.lean
85a8e4d3697c529282cc2da7c6136abc3a7eebde
[ "Apache-2.0" ]
permissive
skbaek/mathlib
3caae8ae413c66862293a95fd2fbada3647b1228
f25340175631cdc85ad768a262433f968d0d6450
refs/heads/master
1,588,130,123,636
1,558,287,609,000
1,558,287,609,000
160,935,713
0
0
Apache-2.0
1,544,271,146,000
1,544,271,146,000
null
UTF-8
Lean
false
false
30,885
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, Mitchell Rowett, Scott Morrison, Johan Commelin, Mario Carneiro -/ import group_theory.submonoid open set function variables {α : Type*} {β : Type*} {a a₁ a₂ b c: α} section group variables [group α] [add_group β] @[to_additive injective_add] lemma injective_mul {a : α} : injective ((*) a) := assume a₁ a₂ h, have a⁻¹ * a * a₁ = a⁻¹ * a * a₂, by rw [mul_assoc, mul_assoc, h], by rwa [inv_mul_self, one_mul, one_mul] at this /-- `s` is a subgroup: a set containing 1 and closed under multiplication and inverse. -/ class is_subgroup (s : set α) extends is_submonoid s : Prop := (inv_mem {a} : a ∈ s → a⁻¹ ∈ s) /-- `s` is an additive subgroup: a set containing 0 and closed under addition and negation. -/ class is_add_subgroup (s : set β) extends is_add_submonoid s : Prop := (neg_mem {a} : a ∈ s → -a ∈ s) attribute [to_additive is_add_subgroup] is_subgroup attribute [to_additive is_add_subgroup.to_is_add_submonoid] is_subgroup.to_is_submonoid attribute [to_additive is_add_subgroup.neg_mem] is_subgroup.inv_mem attribute [to_additive is_add_subgroup.mk] is_subgroup.mk instance additive.is_add_subgroup (s : set α) [is_subgroup s] : @is_add_subgroup (additive α) _ s := ⟨@is_subgroup.inv_mem _ _ _ _⟩ theorem additive.is_add_subgroup_iff {s : set α} : @is_add_subgroup (additive α) _ s ↔ is_subgroup s := ⟨by rintro ⟨⟨h₁, h₂⟩, h₃⟩; exact @is_subgroup.mk α _ _ ⟨h₁, @h₂⟩ @h₃, λ h, by resetI; apply_instance⟩ instance multiplicative.is_subgroup (s : set β) [is_add_subgroup s] : @is_subgroup (multiplicative β) _ s := ⟨@is_add_subgroup.neg_mem _ _ _ _⟩ theorem multiplicative.is_subgroup_iff {s : set β} : @is_subgroup (multiplicative β) _ s ↔ is_add_subgroup s := ⟨by rintro ⟨⟨h₁, h₂⟩, h₃⟩; exact @is_add_subgroup.mk β _ _ ⟨h₁, @h₂⟩ @h₃, λ h, by resetI; apply_instance⟩ instance subtype.group {s : set α} [is_subgroup s] : group s := by subtype_instance instance subtype.add_group {s : set β} [is_add_subgroup s] : add_group s := by subtype_instance attribute [to_additive subtype.add_group] subtype.group attribute [to_additive subtype.add_group._proof_1] subtype.group._proof_1 attribute [to_additive subtype.add_group._proof_2] subtype.group._proof_2 attribute [to_additive subtype.add_group._proof_3] subtype.group._proof_3 attribute [to_additive subtype.add_group._proof_4] subtype.group._proof_4 attribute [to_additive subtype.add_group._proof_5] subtype.group._proof_5 attribute [to_additive subtype.add_group.equations._eqn_1] subtype.group.equations._eqn_1 instance subtype.comm_group {α : Type*} [comm_group α] {s : set α} [is_subgroup s] : comm_group s := by subtype_instance instance subtype.add_comm_group {α : Type*} [add_comm_group α] {s : set α} [is_add_subgroup s] : add_comm_group s := by subtype_instance attribute [to_additive subtype.add_comm_group] subtype.comm_group @[simp, to_additive is_add_subgroup.coe_neg] lemma is_subgroup.coe_inv {s : set α} [is_subgroup s] (a : s) : ((a⁻¹ : s) : α) = a⁻¹ := rfl @[simp] lemma is_subgroup.coe_gpow {s : set α} [is_subgroup s] (a : s) (n : ℤ) : ((a ^ n : s) : α) = a ^ n := by induction n; simp [is_submonoid.coe_pow a] @[simp] lemma is_add_subgroup.gsmul_coe {β : Type*} [add_group β] {s : set β} [is_add_subgroup s] (a : s) (n : ℤ) : ((gsmul n a : s) : β) = gsmul n a := by induction n; simp [is_add_submonoid.smul_coe a] attribute [to_additive is_add_subgroup.gsmul_coe] is_subgroup.coe_gpow theorem is_subgroup.of_div (s : set α) (one_mem : (1:α) ∈ s) (div_mem : ∀{a b:α}, a ∈ s → b ∈ s → a * b⁻¹ ∈ s): is_subgroup s := have inv_mem : ∀a, a ∈ s → a⁻¹ ∈ s, from assume a ha, have 1 * a⁻¹ ∈ s, from div_mem one_mem ha, by simpa, { inv_mem := inv_mem, mul_mem := assume a b ha hb, have a * b⁻¹⁻¹ ∈ s, from div_mem ha (inv_mem b hb), by simpa, one_mem := one_mem } theorem is_add_subgroup.of_sub (s : set β) (zero_mem : (0:β) ∈ s) (sub_mem : ∀{a b:β}, a ∈ s → b ∈ s → a - b ∈ s): is_add_subgroup s := multiplicative.is_subgroup_iff.1 $ @is_subgroup.of_div (multiplicative β) _ _ zero_mem @sub_mem @[to_additive is_add_subgroup.inter] instance is_subgroup.inter (s₁ s₂ : set α) [is_subgroup s₁] [is_subgroup s₂] : is_subgroup (s₁ ∩ s₂) := { inv_mem := λ x hx, ⟨is_subgroup.inv_mem hx.1, is_subgroup.inv_mem hx.2⟩, ..is_submonoid.inter s₁ s₂ } @[to_additive is_add_subgroup_Union_of_directed] lemma is_subgroup_Union_of_directed {ι : Type*} [hι : nonempty ι] (s : ι → set α) [∀ i, is_subgroup (s i)] (directed : ∀ i j, ∃ k, s i ⊆ s k ∧ s j ⊆ s k) : is_subgroup (⋃i, s i) := { inv_mem := λ a ha, let ⟨i, hi⟩ := set.mem_Union.1 ha in set.mem_Union.2 ⟨i, is_subgroup.inv_mem hi⟩, to_is_submonoid := is_submonoid_Union_of_directed s directed } def gpowers (x : α) : set α := set.range ((^) x : ℤ → α) def gmultiples (x : β) : set β := set.range (λ i, gsmul i x) attribute [to_additive gmultiples] gpowers instance gpowers.is_subgroup (x : α) : is_subgroup (gpowers x) := { one_mem := ⟨(0:ℤ), by simp⟩, mul_mem := assume x₁ x₂ ⟨i₁, h₁⟩ ⟨i₂, h₂⟩, ⟨i₁ + i₂, by simp [gpow_add, *]⟩, inv_mem := assume x₀ ⟨i, h⟩, ⟨-i, by simp [h.symm]⟩ } instance gmultiples.is_add_subgroup (x : β) : is_add_subgroup (gmultiples x) := multiplicative.is_subgroup_iff.1 $ gpowers.is_subgroup _ attribute [to_additive gmultiples.is_add_subgroup] gpowers.is_subgroup lemma is_subgroup.gpow_mem {a : α} {s : set α} [is_subgroup s] (h : a ∈ s) : ∀{i:ℤ}, a ^ i ∈ s | (n : ℕ) := is_submonoid.pow_mem h | -[1+ n] := is_subgroup.inv_mem (is_submonoid.pow_mem h) lemma is_add_subgroup.gsmul_mem {a : β} {s : set β} [is_add_subgroup s] : a ∈ s → ∀{i:ℤ}, gsmul i a ∈ s := @is_subgroup.gpow_mem (multiplicative β) _ _ _ _ lemma mem_gpowers {a : α} : a ∈ gpowers a := ⟨1, by simp⟩ lemma mem_gmultiples {a : β} : a ∈ gmultiples a := ⟨1, by simp⟩ attribute [to_additive mem_gmultiples] mem_gpowers end group namespace is_subgroup open is_submonoid variables [group α] (s : set α) [is_subgroup s] @[to_additive is_add_subgroup.neg_mem_iff] lemma inv_mem_iff : a⁻¹ ∈ s ↔ a ∈ s := ⟨λ h, by simpa using inv_mem h, inv_mem⟩ @[to_additive is_add_subgroup.add_mem_cancel_left] lemma mul_mem_cancel_left (h : a ∈ s) : b * a ∈ s ↔ b ∈ s := ⟨λ hba, by simpa using mul_mem hba (inv_mem h), λ hb, mul_mem hb h⟩ @[to_additive is_add_subgroup.add_mem_cancel_right] lemma mul_mem_cancel_right (h : a ∈ s) : a * b ∈ s ↔ b ∈ s := ⟨λ hab, by simpa using mul_mem (inv_mem h) hab, mul_mem h⟩ end is_subgroup theorem is_add_subgroup.sub_mem {α} [add_group α] (s : set α) [is_add_subgroup s] (a b : α) (ha : a ∈ s) (hb : b ∈ s) : a - b ∈ s := is_add_submonoid.add_mem ha (is_add_subgroup.neg_mem hb) namespace group open is_submonoid is_subgroup variables [group α] {s : set α} inductive in_closure (s : set α) : α → Prop | basic {a : α} : a ∈ s → in_closure a | one : in_closure 1 | inv {a : α} : in_closure a → in_closure a⁻¹ | mul {a b : α} : in_closure a → in_closure b → in_closure (a * b) /-- `group.closure s` is the subgroup closed over `s`, i.e. the smallest subgroup containg s. -/ def closure (s : set α) : set α := {a | in_closure s a } lemma mem_closure {a : α} : a ∈ s → a ∈ closure s := in_closure.basic instance closure.is_subgroup (s : set α) : is_subgroup (closure s) := { one_mem := in_closure.one s, mul_mem := assume a b, in_closure.mul, inv_mem := assume a, in_closure.inv } theorem subset_closure {s : set α} : s ⊆ closure s := λ a, mem_closure theorem closure_subset {s t : set α} [is_subgroup t] (h : s ⊆ t) : closure s ⊆ t := assume a ha, by induction ha; simp [h _, *, one_mem, mul_mem, inv_mem_iff] lemma closure_subset_iff (s t : set α) [is_subgroup t] : closure s ⊆ t ↔ s ⊆ t := ⟨assume h b ha, h (mem_closure ha), assume h b ha, closure_subset h ha⟩ theorem closure_mono {s t : set α} (h : s ⊆ t) : closure s ⊆ closure t := closure_subset $ set.subset.trans h subset_closure theorem exists_list_of_mem_closure {s : set α} {a : α} (h : a ∈ closure s) : (∃l:list α, (∀x∈l, x ∈ s ∨ x⁻¹ ∈ s) ∧ l.prod = a) := in_closure.rec_on h (λ x hxs, ⟨[x], list.forall_mem_singleton.2 $ or.inl hxs, one_mul _⟩) ⟨[], list.forall_mem_nil _, rfl⟩ (λ x _ ⟨L, HL1, HL2⟩, ⟨L.reverse.map has_inv.inv, λ x hx, let ⟨y, hy1, hy2⟩ := list.exists_of_mem_map hx in hy2 ▸ or.imp id (by rw [inv_inv]; exact id) (HL1 _ $ list.mem_reverse.1 hy1).symm, HL2 ▸ list.rec_on L one_inv.symm (λ hd tl ih, by rw [list.reverse_cons, list.map_append, list.prod_append, ih, list.map_singleton, list.prod_cons, list.prod_nil, mul_one, list.prod_cons, mul_inv_rev])⟩) (λ x y hx hy ⟨L1, HL1, HL2⟩ ⟨L2, HL3, HL4⟩, ⟨L1 ++ L2, list.forall_mem_append.2 ⟨HL1, HL3⟩, by rw [list.prod_append, HL2, HL4]⟩) theorem mclosure_subset {s : set α} : monoid.closure s ⊆ closure s := monoid.closure_subset $ subset_closure theorem mclosure_inv_subset {s : set α} : monoid.closure (has_inv.inv ⁻¹' s) ⊆ closure s := monoid.closure_subset $ λ x hx, inv_inv x ▸ (is_subgroup.inv_mem $ subset_closure hx) theorem closure_eq_mclosure {s : set α} : closure s = monoid.closure (s ∪ has_inv.inv ⁻¹' s) := set.subset.antisymm (@closure_subset _ _ _ (monoid.closure (s ∪ has_inv.inv ⁻¹' s)) { inv_mem := λ x hx, monoid.in_closure.rec_on hx (λ x hx, or.cases_on hx (λ hx, monoid.subset_closure $ or.inr $ show x⁻¹⁻¹ ∈ s, from (inv_inv x).symm ▸ hx) (λ hx, monoid.subset_closure $ or.inl hx)) ((@one_inv α _).symm ▸ is_submonoid.one_mem _) (λ x y hx hy ihx ihy, (mul_inv_rev x y).symm ▸ is_submonoid.mul_mem ihy ihx) } (set.subset.trans (set.subset_union_left _ _) monoid.subset_closure)) (monoid.closure_subset $ set.union_subset subset_closure $ λ x hx, inv_inv x ▸ (is_subgroup.inv_mem $ subset_closure hx)) theorem mem_closure_union_iff {α : Type*} [comm_group α] {s t : set α} {x : α} : x ∈ closure (s ∪ t) ↔ ∃ y ∈ closure s, ∃ z ∈ closure t, y * z = x := begin simp only [closure_eq_mclosure, monoid.mem_closure_union_iff, exists_prop, preimage_union], split, { rintro ⟨_, ⟨ys, hys, yt, hyt, rfl⟩, _, ⟨zs, hzs, zt, hzt, rfl⟩, rfl⟩, refine ⟨_, ⟨_, hys, _, hzs, rfl⟩, _, ⟨_, hyt, _, hzt, rfl⟩, _⟩, rw [mul_assoc, mul_assoc, mul_left_comm zs], refl }, { rintro ⟨_, ⟨ys, hys, zs, hzs, rfl⟩, _, ⟨yt, hyt, zt, hzt, rfl⟩, rfl⟩, refine ⟨_, ⟨ys, hys, yt, hyt, rfl⟩, _, ⟨zs, hzs, zt, hzt, rfl⟩, _⟩, rw [mul_assoc, mul_assoc, mul_left_comm yt], refl } end theorem gpowers_eq_closure {a : α} : gpowers a = closure {a} := subset.antisymm (assume x h, match x, h with _, ⟨i, rfl⟩ := gpow_mem (mem_closure $ by simp) end) (closure_subset $ by simp [mem_gpowers]) end group namespace add_group open is_add_submonoid is_add_subgroup variables [add_group α] {s : set α} /-- `add_group.closure s` is the additive subgroup closed over `s`, i.e. the smallest subgroup containg s. -/ def closure (s : set α) : set α := @group.closure (multiplicative α) _ s attribute [to_additive add_group.closure] group.closure lemma mem_closure {a : α} : a ∈ s → a ∈ closure s := group.mem_closure attribute [to_additive add_group.mem_closure] group.mem_closure instance closure.is_add_subgroup (s : set α) : is_add_subgroup (closure s) := multiplicative.is_subgroup_iff.1 $ group.closure.is_subgroup _ attribute [to_additive add_group.closure.is_add_subgroup] group.closure.is_subgroup attribute [to_additive add_group.subset_closure] group.subset_closure theorem closure_subset {s t : set α} [is_add_subgroup t] : s ⊆ t → closure s ⊆ t := group.closure_subset attribute [to_additive add_group.closure_subset] group.closure_subset attribute [to_additive add_group.closure_subset_iff] group.closure_subset_iff theorem gmultiples_eq_closure {a : α} : gmultiples a = closure {a} := group.gpowers_eq_closure attribute [to_additive add_group.gmultiples_eq_closure] group.gpowers_eq_closure @[elab_as_eliminator] theorem in_closure.rec_on {C : α → Prop} {a : α} (H : a ∈ closure s) (H1 : ∀ {a : α}, a ∈ s → C a) (H2 : C 0) (H3 : ∀ {a : α}, a ∈ closure s → C a → C (-a)) (H4 : ∀ {a b : α}, a ∈ closure s → b ∈ closure s → C a → C b → C (a + b)) : C a := group.in_closure.rec_on H (λ _, H1) H2 (λ _, H3) (λ _ _, H4) theorem closure_mono {s t : set α} (h : s ⊆ t) : closure s ⊆ closure t := closure_subset $ set.subset.trans h subset_closure theorem exists_list_of_mem_closure {s : set α} {a : α} (h : a ∈ closure s) : (∃l:list α, (∀x∈l, x ∈ s ∨ -x ∈ s) ∧ l.sum = a) := group.exists_list_of_mem_closure h theorem mclosure_subset {s : set α} : add_monoid.closure s ⊆ closure s := group.mclosure_subset theorem mclosure_inv_subset {s : set α} : add_monoid.closure (has_neg.neg ⁻¹' s) ⊆ closure s := group.mclosure_inv_subset theorem closure_eq_mclosure {s : set α} : closure s = add_monoid.closure (s ∪ has_neg.neg ⁻¹' s) := group.closure_eq_mclosure theorem mem_closure_union_iff {α : Type*} [add_comm_group α] {s t : set α} {x : α} : x ∈ closure (s ∪ t) ↔ ∃ y ∈ closure s, ∃ z ∈ closure t, y + z = x := group.mem_closure_union_iff end add_group class normal_subgroup [group α] (s : set α) extends is_subgroup s : Prop := (normal : ∀ n ∈ s, ∀ g : α, g * n * g⁻¹ ∈ s) class normal_add_subgroup [add_group α] (s : set α) extends is_add_subgroup s : Prop := (normal : ∀ n ∈ s, ∀ g : α, g + n - g ∈ s) attribute [to_additive normal_add_subgroup] normal_subgroup attribute [to_additive normal_add_subgroup.to_is_add_subgroup] normal_subgroup.to_is_subgroup attribute [to_additive normal_add_subgroup.normal] normal_subgroup.normal attribute [to_additive normal_add_subgroup.mk] normal_subgroup.mk @[to_additive normal_add_subgroup_of_add_comm_group] lemma normal_subgroup_of_comm_group [comm_group α] (s : set α) [hs : is_subgroup s] : normal_subgroup s := { normal := λ n hn g, by rwa [mul_right_comm, mul_right_inv, one_mul], ..hs } instance additive.normal_add_subgroup [group α] (s : set α) [normal_subgroup s] : @normal_add_subgroup (additive α) _ s := ⟨@normal_subgroup.normal _ _ _ _⟩ theorem additive.normal_add_subgroup_iff [group α] {s : set α} : @normal_add_subgroup (additive α) _ s ↔ normal_subgroup s := ⟨by rintro ⟨h₁, h₂⟩; exact @normal_subgroup.mk α _ _ (additive.is_add_subgroup_iff.1 h₁) @h₂, λ h, by resetI; apply_instance⟩ instance multiplicative.normal_subgroup [add_group α] (s : set α) [normal_add_subgroup s] : @normal_subgroup (multiplicative α) _ s := ⟨@normal_add_subgroup.normal _ _ _ _⟩ theorem multiplicative.normal_subgroup_iff [add_group α] {s : set α} : @normal_subgroup (multiplicative α) _ s ↔ normal_add_subgroup s := ⟨by rintro ⟨h₁, h₂⟩; exact @normal_add_subgroup.mk α _ _ (multiplicative.is_subgroup_iff.1 h₁) @h₂, λ h, by resetI; apply_instance⟩ namespace is_subgroup variable [group α] -- Normal subgroup properties lemma mem_norm_comm {s : set α} [normal_subgroup s] {a b : α} (hab : a * b ∈ s) : b * a ∈ s := have h : a⁻¹ * (a * b) * a⁻¹⁻¹ ∈ s, from normal_subgroup.normal (a * b) hab a⁻¹, by simp at h; exact h lemma mem_norm_comm_iff {s : set α} [normal_subgroup s] {a b : α} : a * b ∈ s ↔ b * a ∈ s := ⟨mem_norm_comm, mem_norm_comm⟩ /-- The trivial subgroup -/ def trivial (α : Type*) [group α] : set α := {1} @[simp] lemma mem_trivial [group α] {g : α} : g ∈ trivial α ↔ g = 1 := mem_singleton_iff instance trivial_normal : normal_subgroup (trivial α) := by refine {..}; simp [trivial] {contextual := tt} lemma trivial_eq_closure : trivial α = group.closure ∅ := subset.antisymm (by simp [set.subset_def, is_submonoid.one_mem]) (group.closure_subset $ by simp) lemma eq_trivial_iff {H : set α} [is_subgroup H] : H = trivial α ↔ (∀ x ∈ H, x = (1 : α)) := by simp only [set.ext_iff, is_subgroup.mem_trivial]; exact ⟨λ h x, (h x).1, λ h x, ⟨h x, λ hx, hx.symm ▸ is_submonoid.one_mem H⟩⟩ instance univ_subgroup : normal_subgroup (@univ α) := by refine {..}; simp def center (α : Type*) [group α] : set α := {z | ∀ g, g * z = z * g} lemma mem_center {a : α} : a ∈ center α ↔ ∀g, g * a = a * g := iff.rfl instance center_normal : normal_subgroup (center α) := { one_mem := by simp [center], mul_mem := assume a b ha hb g, by rw [←mul_assoc, mem_center.2 ha g, mul_assoc, mem_center.2 hb g, ←mul_assoc], inv_mem := assume a ha g, calc g * a⁻¹ = a⁻¹ * (g * a) * a⁻¹ : by simp [ha g] ... = a⁻¹ * g : by rw [←mul_assoc, mul_assoc]; simp, normal := assume n ha g h, calc h * (g * n * g⁻¹) = h * n : by simp [ha g, mul_assoc] ... = g * g⁻¹ * n * h : by rw ha h; simp ... = g * n * g⁻¹ * h : by rw [mul_assoc g, ha g⁻¹, ←mul_assoc] } def normalizer (s : set α) : set α := {g : α | ∀ n, n ∈ s ↔ g * n * g⁻¹ ∈ s} instance (s : set α) [is_subgroup s] : is_subgroup (normalizer s) := { one_mem := by simp [normalizer], mul_mem := λ a b (ha : ∀ n, n ∈ s ↔ a * n * a⁻¹ ∈ s) (hb : ∀ n, n ∈ s ↔ b * n * b⁻¹ ∈ s) n, by rw [mul_inv_rev, ← mul_assoc, mul_assoc a, mul_assoc a, ← ha, ← hb], inv_mem := λ a (ha : ∀ n, n ∈ s ↔ a * n * a⁻¹ ∈ s) n, by rw [ha (a⁻¹ * n * a⁻¹⁻¹)]; simp [mul_assoc] } lemma subset_normalizer (s : set α) [is_subgroup s] : s ⊆ normalizer s := λ g hg n, by rw [is_subgroup.mul_mem_cancel_left _ ((is_subgroup.inv_mem_iff _).2 hg), is_subgroup.mul_mem_cancel_right _ hg] instance (s : set α) [is_subgroup s] : normal_subgroup (subtype.val ⁻¹' s : set (normalizer s)) := { one_mem := show (1 : α) ∈ s, from is_submonoid.one_mem _, mul_mem := λ a b ha hb, show (a * b : α) ∈ s, from is_submonoid.mul_mem ha hb, inv_mem := λ a ha, show (a⁻¹ : α) ∈ s, from is_subgroup.inv_mem ha, normal := λ a ha ⟨m, hm⟩, (hm a).1 ha } end is_subgroup namespace is_add_subgroup variable [add_group α] attribute [to_additive is_add_subgroup.mem_norm_comm] is_subgroup.mem_norm_comm attribute [to_additive is_add_subgroup.mem_norm_comm_iff] is_subgroup.mem_norm_comm_iff /-- The trivial subgroup -/ def trivial (α : Type*) [add_group α] : set α := {0} attribute [to_additive is_add_subgroup.trivial] is_subgroup.trivial attribute [to_additive is_add_subgroup.trivial.equations._eqn_1] is_subgroup.trivial.equations._eqn_1 attribute [to_additive is_add_subgroup.mem_trivial] is_subgroup.mem_trivial instance trivial_normal : normal_add_subgroup (trivial α) := multiplicative.normal_subgroup_iff.1 is_subgroup.trivial_normal attribute [to_additive is_add_subgroup.trivial_normal] is_subgroup.trivial_normal attribute [to_additive is_add_subgroup.trivial_eq_closure] is_subgroup.trivial_eq_closure attribute [to_additive is_add_subgroup.eq_trivial_iff] is_subgroup.eq_trivial_iff instance univ_add_subgroup : normal_add_subgroup (@univ α) := multiplicative.normal_subgroup_iff.1 is_subgroup.univ_subgroup attribute [to_additive is_add_subgroup.univ_add_subgroup] is_subgroup.univ_subgroup def center (α : Type*) [add_group α] : set α := {z | ∀ g, g + z = z + g} attribute [to_additive is_add_subgroup.center] is_subgroup.center attribute [to_additive is_add_subgroup.mem_center] is_subgroup.mem_center instance center_normal : normal_add_subgroup (center α) := multiplicative.normal_subgroup_iff.1 is_subgroup.center_normal end is_add_subgroup -- Homomorphism subgroups namespace is_group_hom open is_submonoid is_subgroup variables [group α] [group β] @[to_additive is_add_group_hom.ker] def ker (f : α → β) [is_group_hom f] : set α := preimage f (trivial β) attribute [to_additive is_add_group_hom.ker.equations._eqn_1] ker.equations._eqn_1 @[to_additive is_add_group_hom.mem_ker] lemma mem_ker (f : α → β) [is_group_hom f] {x : α} : x ∈ ker f ↔ f x = 1 := mem_trivial @[to_additive is_add_group_hom.map_zero_ker_neg] lemma one_ker_inv (f : α → β) [is_group_hom f] {a b : α} (h : f (a * b⁻¹) = 1) : f a = f b := begin rw [map_mul f, map_inv f] at h, rw [←inv_inv (f b), eq_inv_of_mul_eq_one h] end @[to_additive is_add_group_hom.map_zero_ker_neg'] lemma one_ker_inv' (f : α → β) [is_group_hom f] {a b : α} (h : f (a⁻¹ * b) = 1) : f a = f b := begin rw [map_mul f, map_inv f] at h, apply eq_of_inv_eq_inv, rw eq_inv_of_mul_eq_one h end @[to_additive is_add_group_hom.map_neg_ker_zero] lemma inv_ker_one (f : α → β) [is_group_hom f] {a b : α} (h : f a = f b) : f (a * b⁻¹) = 1 := have f a * (f b)⁻¹ = 1, by rw [h, mul_right_inv], by rwa [←map_inv f, ←map_mul f] at this @[to_additive is_add_group_hom.map_neg_ker_zero'] lemma inv_ker_one' (f : α → β) [is_group_hom f] {a b : α} (h : f a = f b) : f (a⁻¹ * b) = 1 := have (f a)⁻¹ * f b = 1, by rw [h, mul_left_inv], by rwa [←map_inv f, ←map_mul f] at this @[to_additive is_add_group_hom.map_zero_iff_ker_neg] lemma one_iff_ker_inv (f : α → β) [is_group_hom f] (a b : α) : f a = f b ↔ f (a * b⁻¹) = 1 := ⟨inv_ker_one f, one_ker_inv f⟩ @[to_additive is_add_group_hom.map_zero_iff_ker_neg'] lemma one_iff_ker_inv' (f : α → β) [is_group_hom f] (a b : α) : f a = f b ↔ f (a⁻¹ * b) = 1 := ⟨inv_ker_one' f, one_ker_inv' f⟩ @[to_additive is_add_group_hom.map_neg_iff_ker] lemma inv_iff_ker (f : α → β) [w : is_group_hom f] (a b : α) : f a = f b ↔ a * b⁻¹ ∈ ker f := by rw [mem_ker]; exact one_iff_ker_inv _ _ _ @[to_additive is_add_group_hom.map_neg_iff_ker'] lemma inv_iff_ker' (f : α → β) [w : is_group_hom f] (a b : α) : f a = f b ↔ a⁻¹ * b ∈ ker f := by rw [mem_ker]; exact one_iff_ker_inv' _ _ _ instance image_subgroup (f : α → β) [is_group_hom f] (s : set α) [is_subgroup s] : is_subgroup (f '' s) := { mul_mem := assume a₁ a₂ ⟨b₁, hb₁, eq₁⟩ ⟨b₂, hb₂, eq₂⟩, ⟨b₁ * b₂, mul_mem hb₁ hb₂, by simp [eq₁, eq₂, map_mul f]⟩, one_mem := ⟨1, one_mem s, map_one f⟩, inv_mem := assume a ⟨b, hb, eq⟩, ⟨b⁻¹, inv_mem hb, by rw map_inv f; simp *⟩ } attribute [to_additive is_add_group_hom.image_add_subgroup._match_1] is_group_hom.image_subgroup._match_1 attribute [to_additive is_add_group_hom.image_add_subgroup._match_2] is_group_hom.image_subgroup._match_2 attribute [to_additive is_add_group_hom.image_add_subgroup._match_3] is_group_hom.image_subgroup._match_3 attribute [to_additive is_add_group_hom.image_add_subgroup] is_group_hom.image_subgroup attribute [to_additive is_add_group_hom.image_add_subgroup._match_1.equations._eqn_1] is_group_hom.image_subgroup._match_1.equations._eqn_1 attribute [to_additive is_add_group_hom.image_add_subgroup._match_2.equations._eqn_1] is_group_hom.image_subgroup._match_2.equations._eqn_1 attribute [to_additive is_add_group_hom.image_add_subgroup._match_3.equations._eqn_1] is_group_hom.image_subgroup._match_3.equations._eqn_1 attribute [to_additive is_add_group_hom.image_add_subgroup.equations._eqn_1] is_group_hom.image_subgroup.equations._eqn_1 instance range_subgroup (f : α → β) [is_group_hom f] : is_subgroup (set.range f) := @set.image_univ _ _ f ▸ is_group_hom.image_subgroup f set.univ attribute [to_additive is_add_group_hom.range_add_subgroup] is_group_hom.range_subgroup attribute [to_additive is_add_group_hom.range_add_subgroup.equations._eqn_1] is_group_hom.range_subgroup.equations._eqn_1 local attribute [simp] one_mem inv_mem mul_mem normal_subgroup.normal instance preimage (f : α → β) [is_group_hom f] (s : set β) [is_subgroup s] : is_subgroup (f ⁻¹' s) := by refine {..}; simp [map_mul f, map_one f, map_inv f, @inv_mem β _ s] {contextual:=tt} attribute [to_additive is_add_group_hom.preimage] is_group_hom.preimage attribute [to_additive is_add_group_hom.preimage.equations._eqn_1] is_group_hom.preimage.equations._eqn_1 instance preimage_normal (f : α → β) [is_group_hom f] (s : set β) [normal_subgroup s] : normal_subgroup (f ⁻¹' s) := ⟨by simp [map_mul f, map_inv f] {contextual:=tt}⟩ attribute [to_additive is_add_group_hom.preimage_normal] is_group_hom.preimage_normal attribute [to_additive is_add_group_hom.preimage_normal.equations._eqn_1] is_group_hom.preimage_normal.equations._eqn_1 instance normal_subgroup_ker (f : α → β) [is_group_hom f] : normal_subgroup (ker f) := is_group_hom.preimage_normal f (trivial β) attribute [to_additive is_add_group_hom.normal_subgroup_ker] is_group_hom.normal_subgroup_ker attribute [to_additive is_add_group_hom.normal_subgroup_ker.equations._eqn_1] is_group_hom.normal_subgroup_ker.equations._eqn_1 @[to_additive is_add_group_hom.inj_of_trivial_ker] lemma inj_of_trivial_ker (f : α → β) [is_group_hom f] (h : ker f = trivial α) : function.injective f := begin intros a₁ a₂ hfa, simp [ext_iff, ker, is_subgroup.trivial] at h, have ha : a₁ * a₂⁻¹ = 1, by rw ←h; exact inv_ker_one f hfa, rw [eq_inv_of_mul_eq_one ha, inv_inv a₂] end @[to_additive is_add_group_hom.trivial_ker_of_inj] lemma trivial_ker_of_inj (f : α → β) [is_group_hom f] (h : function.injective f) : ker f = trivial α := set.ext $ assume x, iff.intro (assume hx, suffices f x = f 1, by simpa using h this, by simp [map_one f]; rwa [mem_ker] at hx) (by simp [mem_ker, is_group_hom.map_one f] {contextual := tt}) @[to_additive is_add_group_hom.inj_iff_trivial_ker] lemma inj_iff_trivial_ker (f : α → β) [is_group_hom f] : function.injective f ↔ ker f = trivial α := ⟨trivial_ker_of_inj f, inj_of_trivial_ker f⟩ @[to_additive is_add_group_hom.trivial_ker_iff_eq_zero] lemma trivial_ker_iff_eq_one (f : α → β) [is_group_hom f] : ker f = trivial α ↔ ∀ x, f x = 1 → x = 1 := by rw set.ext_iff; simp [ker]; exact ⟨λ h x hx, (h x).1 hx, λ h x, ⟨h x, λ hx, by rw [hx, map_one f]⟩⟩ end is_group_hom instance subtype_val.is_group_hom [group α] {s : set α} [is_subgroup s] : is_group_hom (subtype.val : s → α) := { ..subtype_val.is_monoid_hom } instance subtype_val.is_add_group_hom [add_group α] {s : set α} [is_add_subgroup s] : is_add_group_hom (subtype.val : s → α) := { ..subtype_val.is_add_monoid_hom } attribute [to_additive subtype_val.is_group_hom] subtype_val.is_add_group_hom instance coe.is_group_hom [group α] {s : set α} [is_subgroup s] : is_group_hom (coe : s → α) := { ..subtype_val.is_monoid_hom } instance coe.is_add_group_hom [add_group α] {s : set α} [is_add_subgroup s] : is_add_group_hom (coe : s → α) := { ..subtype_val.is_add_monoid_hom } attribute [to_additive coe.is_group_hom] coe.is_add_group_hom instance subtype_mk.is_group_hom [group α] [group β] {s : set α} [is_subgroup s] (f : β → α) [is_group_hom f] (h : ∀ x, f x ∈ s) : is_group_hom (λ x, (⟨f x, h x⟩ : s)) := { ..subtype_mk.is_monoid_hom f h } instance subtype_mk.is_add_group_hom [add_group α] [add_group β] {s : set α} [is_add_subgroup s] (f : β → α) [is_add_group_hom f] (h : ∀ x, f x ∈ s) : is_add_group_hom (λ x, (⟨f x, h x⟩ : s)) := { ..subtype_mk.is_add_monoid_hom f h } attribute [to_additive subtype_mk.is_group_hom] subtype_mk.is_add_group_hom instance set_inclusion.is_group_hom [group α] {s t : set α} [is_subgroup s] [is_subgroup t] (h : s ⊆ t) : is_group_hom (set.inclusion h) := subtype_mk.is_group_hom _ _ instance set_inclusion.is_add_group_hom [add_group α] {s t : set α} [is_add_subgroup s] [is_add_subgroup t] (h : s ⊆ t) : is_add_group_hom (set.inclusion h) := subtype_mk.is_add_group_hom _ _ attribute [to_additive set_inclusion.is_group_hom] set_inclusion.is_add_group_hom section simple_group class simple_group (α : Type*) [group α] : Prop := (simple : ∀ (N : set α) [normal_subgroup N], N = is_subgroup.trivial α ∨ N = set.univ) class simple_add_group (α : Type*) [add_group α] : Prop := (simple : ∀ (N : set α) [normal_add_subgroup N], N = is_add_subgroup.trivial α ∨ N = set.univ) attribute [to_additive simple_add_group] simple_group theorem additive.simple_add_group_iff [group α] : simple_add_group (additive α) ↔ simple_group α := ⟨λ hs, ⟨λ N h, @simple_add_group.simple _ _ hs _ (by exactI additive.normal_add_subgroup_iff.2 h)⟩, λ hs, ⟨λ N h, @simple_group.simple _ _ hs _ (by exactI additive.normal_add_subgroup_iff.1 h)⟩⟩ instance additive.simple_add_group [group α] [simple_group α] : simple_add_group (additive α) := additive.simple_add_group_iff.2 (by apply_instance) theorem multiplicative.simple_group_iff [add_group α] : simple_group (multiplicative α) ↔ simple_add_group α := ⟨λ hs, ⟨λ N h, @simple_group.simple _ _ hs _ (by exactI multiplicative.normal_subgroup_iff.2 h)⟩, λ hs, ⟨λ N h, @simple_add_group.simple _ _ hs _ (by exactI multiplicative.normal_subgroup_iff.1 h)⟩⟩ instance multiplicative.simple_group [add_group α] [simple_add_group α] : simple_group (multiplicative α) := multiplicative.simple_group_iff.2 (by apply_instance) lemma simple_group_of_surjective [group α] [group β] [simple_group α] (f : α → β) [is_group_hom f] (hf : function.surjective f) : simple_group β := ⟨λ H iH, have normal_subgroup (f ⁻¹' H), by resetI; apply_instance, begin resetI, cases simple_group.simple (f ⁻¹' H) with h h, { refine or.inl (is_subgroup.eq_trivial_iff.2 (λ x hx, _)), cases hf x with y hy, rw ← hy at hx, rw [← hy, is_subgroup.eq_trivial_iff.1 h y hx, is_group_hom.map_one f] }, { refine or.inr (set.eq_univ_of_forall (λ x, _)), cases hf x with y hy, rw set.eq_univ_iff_forall at h, rw ← hy, exact h y } end⟩ lemma simple_add_group_of_surjective [add_group α] [add_group β] [simple_add_group α] (f : α → β) [is_add_group_hom f] (hf : function.surjective f) : simple_add_group β := multiplicative.simple_group_iff.1 (@simple_group_of_surjective (multiplicative α) (multiplicative β) _ _ _ f _ hf) attribute [to_additive simple_add_group_of_surjective] simple_group_of_surjective end simple_group
8ffdf046b3f1e2d1ea001fca9d29a8e6ea36ff6a
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/stage0/src/Init/Data/Nat/Linear.lean
9115fbf3923351c56e8f82855937624082e1e903
[ "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
30,043
lean
/- Copyright (c) 2022 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import Init.Coe import Init.Classical import Init.SimpLemmas import Init.Data.Nat.Basic import Init.Data.List.Basic import Init.Data.Prod namespace Nat.Linear /-! Helper definitions and theorems for constructing linear arithmetic proofs. -/ abbrev Var := Nat abbrev Context := List Nat /-- When encoding polynomials. We use `fixedVar` for encoding numerals. The denotation of `fixedVar` is always `1`. -/ def fixedVar := 100000000 -- Any big number should work here def Var.denote (ctx : Context) (v : Var) : Nat := bif v == fixedVar then 1 else go ctx v where go : List Nat → Nat → Nat | [], _ => 0 | a::_, 0 => a | _::as, i+1 => go as i inductive Expr where | num (v : Nat) | var (i : Var) | add (a b : Expr) | mulL (k : Nat) (a : Expr) | mulR (a : Expr) (k : Nat) deriving Inhabited def Expr.denote (ctx : Context) : Expr → Nat | Expr.add a b => Nat.add (denote ctx a) (denote ctx b) | Expr.num k => k | Expr.var v => v.denote ctx | Expr.mulL k e => Nat.mul k (denote ctx e) | Expr.mulR e k => Nat.mul (denote ctx e) k abbrev Poly := List (Nat × Var) def Poly.denote (ctx : Context) (p : Poly) : Nat := match p with | [] => 0 | (k, v) :: p => Nat.add (Nat.mul k (v.denote ctx)) (denote ctx p) def Poly.insertSorted (k : Nat) (v : Var) (p : Poly) : Poly := match p with | [] => [(k, v)] | (k', v') :: p => bif Nat.blt v v' then (k, v) :: (k', v') :: p else (k', v') :: insertSorted k v p def Poly.sort (p : Poly) : Poly := let rec go (p : Poly) (r : Poly) : Poly := match p with | [] => r | (k, v) :: p => go p (r.insertSorted k v) go p [] def Poly.fuse (p : Poly) : Poly := match p with | [] => [] | (k, v) :: p => match fuse p with | [] => [(k, v)] | (k', v') :: p' => bif v == v' then (Nat.add k k', v)::p' else (k, v) :: (k', v') :: p' def Poly.mul (k : Nat) (p : Poly) : Poly := bif k == 0 then [] else bif k == 1 then p else go p where go : Poly → Poly | [] => [] | (k', v) :: p => (Nat.mul k k', v) :: go p def Poly.cancelAux (fuel : Nat) (m₁ m₂ r₁ r₂ : Poly) : Poly × Poly := match fuel with | 0 => (r₁.reverse ++ m₁, r₂.reverse ++ m₂) | fuel + 1 => match m₁, m₂ with | m₁, [] => (r₁.reverse ++ m₁, r₂.reverse) | [], m₂ => (r₁.reverse, r₂.reverse ++ m₂) | (k₁, v₁) :: m₁, (k₂, v₂) :: m₂ => bif Nat.blt v₁ v₂ then cancelAux fuel m₁ ((k₂, v₂) :: m₂) ((k₁, v₁) :: r₁) r₂ else bif Nat.blt v₂ v₁ then cancelAux fuel ((k₁, v₁) :: m₁) m₂ r₁ ((k₂, v₂) :: r₂) else bif Nat.blt k₁ k₂ then cancelAux fuel m₁ m₂ r₁ ((Nat.sub k₂ k₁, v₁) :: r₂) else bif Nat.blt k₂ k₁ then cancelAux fuel m₁ m₂ ((Nat.sub k₁ k₂, v₁) :: r₁) r₂ else cancelAux fuel m₁ m₂ r₁ r₂ def hugeFuel := 1000000 -- any big number should work def Poly.cancel (p₁ p₂ : Poly) : Poly × Poly := cancelAux hugeFuel p₁ p₂ [] [] def Poly.isNum? (p : Poly) : Option Nat := match p with | [] => some 0 | [(k, v)] => bif v == fixedVar then some k else none | _ => none def Poly.isZero (p : Poly) : Bool := match p with | [] => true | _ => false def Poly.isNonZero (p : Poly) : Bool := match p with | [] => false | (k, v) :: p => bif v == fixedVar then k > 0 else isNonZero p def Poly.denote_eq (ctx : Context) (mp : Poly × Poly) : Prop := mp.1.denote ctx = mp.2.denote ctx def Poly.denote_le (ctx : Context) (mp : Poly × Poly) : Prop := mp.1.denote ctx ≤ mp.2.denote ctx def Poly.combineAux (fuel : Nat) (p₁ p₂ : Poly) : Poly := match fuel with | 0 => p₁ ++ p₂ | fuel + 1 => match p₁, p₂ with | p₁, [] => p₁ | [], p₂ => p₂ | (k₁, v₁) :: p₁, (k₂, v₂) :: p₂ => bif Nat.blt v₁ v₂ then (k₁, v₁) :: combineAux fuel p₁ ((k₂, v₂) :: p₂) else bif Nat.blt v₂ v₁ then (k₂, v₂) :: combineAux fuel ((k₁, v₁) :: p₁) p₂ else (Nat.add k₁ k₂, v₁) :: combineAux fuel p₁ p₂ def Poly.combine (p₁ p₂ : Poly) : Poly := combineAux hugeFuel p₁ p₂ def Expr.toPoly : Expr → Poly | Expr.num k => bif k == 0 then [] else [ (k, fixedVar) ] | Expr.var i => [(1, i)] | Expr.add a b => a.toPoly ++ b.toPoly | Expr.mulL k a => a.toPoly.mul k | Expr.mulR a k => a.toPoly.mul k def Poly.norm (p : Poly) : Poly := p.sort.fuse def Expr.toNormPoly (e : Expr) : Poly := e.toPoly.norm def Expr.inc (e : Expr) : Expr := Expr.add e (Expr.num 1) structure PolyCnstr where eq : Bool lhs : Poly rhs : Poly deriving BEq -- TODO: implement LawfulBEq generator companion for BEq instance : LawfulBEq PolyCnstr where eq_of_beq {a b} h := by cases a; rename_i eq₁ lhs₁ rhs₁ cases b; rename_i eq₂ lhs₂ rhs₂ have h : eq₁ == eq₂ && lhs₁ == lhs₂ && rhs₁ == rhs₂ := h simp at h have ⟨⟨h₁, h₂⟩, h₃⟩ := h rw [h₁, h₂, h₃] rfl {a} := by cases a; rename_i eq lhs rhs show (eq == eq && lhs == lhs && rhs == rhs) = true simp [LawfulBEq.rfl] def PolyCnstr.mul (k : Nat) (c : PolyCnstr) : PolyCnstr := { c with lhs := c.lhs.mul k, rhs := c.rhs.mul k } def PolyCnstr.combine (c₁ c₂ : PolyCnstr) : PolyCnstr := let (lhs, rhs) := Poly.cancel (c₁.lhs.combine c₂.lhs) (c₁.rhs.combine c₂.rhs) { eq := c₁.eq && c₂.eq, lhs, rhs } structure ExprCnstr where eq : Bool lhs : Expr rhs : Expr def PolyCnstr.denote (ctx : Context) (c : PolyCnstr) : Prop := bif c.eq then Poly.denote_eq ctx (c.lhs, c.rhs) else Poly.denote_le ctx (c.lhs, c.rhs) def PolyCnstr.norm (c : PolyCnstr) : PolyCnstr := let (lhs, rhs) := Poly.cancel c.lhs.sort.fuse c.rhs.sort.fuse { eq := c.eq, lhs, rhs } def PolyCnstr.isUnsat (c : PolyCnstr) : Bool := bif c.eq then (c.lhs.isZero && c.rhs.isNonZero) || (c.lhs.isNonZero && c.rhs.isZero) else c.lhs.isNonZero && c.rhs.isZero def PolyCnstr.isValid (c : PolyCnstr) : Bool := bif c.eq then c.lhs.isZero && c.rhs.isZero else c.lhs.isZero def ExprCnstr.denote (ctx : Context) (c : ExprCnstr) : Prop := bif c.eq then c.lhs.denote ctx = c.rhs.denote ctx else c.lhs.denote ctx ≤ c.rhs.denote ctx def ExprCnstr.toPoly (c : ExprCnstr) : PolyCnstr := { c with lhs := c.lhs.toPoly, rhs := c.rhs.toPoly } def ExprCnstr.toNormPoly (c : ExprCnstr) : PolyCnstr := let (lhs, rhs) := Poly.cancel c.lhs.toNormPoly c.rhs.toNormPoly { c with lhs, rhs } abbrev Certificate := List (Nat × ExprCnstr) def Certificate.combineHyps (c : PolyCnstr) (hs : Certificate) : PolyCnstr := match hs with | [] => c | (k, c') :: hs => combineHyps (PolyCnstr.combine c (c'.toNormPoly.mul (Nat.add k 1))) hs def Certificate.combine (hs : Certificate) : PolyCnstr := match hs with | [] => { eq := true, lhs := [], rhs := [] } | (k, c) :: hs => combineHyps (c.toNormPoly.mul (Nat.add k 1)) hs def Certificate.denote (ctx : Context) (c : Certificate) : Prop := match c with | [] => False | (_, c)::hs => c.denote ctx → denote ctx hs def monomialToExpr (k : Nat) (v : Var) : Expr := bif v == fixedVar then Expr.num k else bif k == 1 then Expr.var v else Expr.mulL k (Expr.var v) def Poly.toExpr (p : Poly) : Expr := match p with | [] => Expr.num 0 | (k, v) :: p => go (monomialToExpr k v) p where go (e : Expr) (p : Poly) : Expr := match p with | [] => e | (k, v) :: p => go (Expr.add e (monomialToExpr k v)) p def PolyCnstr.toExpr (c : PolyCnstr) : ExprCnstr := { c with lhs := c.lhs.toExpr, rhs := c.rhs.toExpr } attribute [local simp] Nat.add_comm Nat.add_assoc Nat.add_left_comm Nat.right_distrib Nat.left_distrib Nat.mul_assoc Nat.mul_comm attribute [local simp] Poly.denote Expr.denote Poly.insertSorted Poly.sort Poly.sort.go Poly.fuse Poly.cancelAux attribute [local simp] Poly.mul Poly.mul.go theorem Poly.denote_insertSorted (ctx : Context) (k : Nat) (v : Var) (p : Poly) : (p.insertSorted k v).denote ctx = p.denote ctx + k * v.denote ctx := by match p with | [] => simp | (k', v') :: p => by_cases h : Nat.blt v v' <;> simp [h, denote_insertSorted] attribute [local simp] Poly.denote_insertSorted theorem Poly.denote_sort_go (ctx : Context) (p : Poly) (r : Poly) : (sort.go p r).denote ctx = p.denote ctx + r.denote ctx := by match p with | [] => simp | (k, v):: p => simp [denote_sort_go] attribute [local simp] Poly.denote_sort_go theorem Poly.denote_sort (ctx : Context) (m : Poly) : m.sort.denote ctx = m.denote ctx := by simp attribute [local simp] Poly.denote_sort theorem Poly.denote_append (ctx : Context) (p q : Poly) : (p ++ q).denote ctx = p.denote ctx + q.denote ctx := by match p with | [] => simp | (k, v) :: p => simp [denote_append] attribute [local simp] Poly.denote_append theorem Poly.denote_cons (ctx : Context) (k : Nat) (v : Var) (p : Poly) : denote ctx ((k, v) :: p) = k * v.denote ctx + p.denote ctx := by match p with | [] => simp | _ :: m => simp [denote_cons] attribute [local simp] Poly.denote_cons theorem Poly.denote_reverseAux (ctx : Context) (p q : Poly) : denote ctx (List.reverseAux p q) = denote ctx (p ++ q) := by match p with | [] => simp [List.reverseAux] | (k, v) :: p => simp [List.reverseAux, denote_reverseAux] attribute [local simp] Poly.denote_reverseAux theorem Poly.denote_reverse (ctx : Context) (p : Poly) : denote ctx (List.reverse p) = denote ctx p := by simp [List.reverse] attribute [local simp] Poly.denote_reverse theorem Poly.denote_fuse (ctx : Context) (p : Poly) : p.fuse.denote ctx = p.denote ctx := by match p with | [] => rfl | (k, v) :: p => have ih := denote_fuse ctx p simp split case _ h => simp [← ih, h] case _ k' v' p' h => by_cases he : v == v' <;> simp [he, ← ih, h]; rw [eq_of_beq he] attribute [local simp] Poly.denote_fuse theorem Poly.denote_mul (ctx : Context) (k : Nat) (p : Poly) : (p.mul k).denote ctx = k * p.denote ctx := by simp by_cases h : k == 0 <;> simp [h]; simp [eq_of_beq h] by_cases h : k == 1 <;> simp [h]; simp [eq_of_beq h] induction p with | nil => simp | cons kv m ih => cases kv with | _ k' v => simp [ih] private theorem eq_of_not_blt_eq_true (h₁ : ¬ (Nat.blt x y = true)) (h₂ : ¬ (Nat.blt y x = true)) : x = y := have h₁ : ¬ x < y := fun h => h₁ (Nat.blt_eq.mpr h) have h₂ : ¬ y < x := fun h => h₂ (Nat.blt_eq.mpr h) Nat.le_antisymm (Nat.ge_of_not_lt h₂) (Nat.ge_of_not_lt h₁) attribute [local simp] Poly.denote_mul theorem Poly.denote_eq_cancelAux (ctx : Context) (fuel : Nat) (m₁ m₂ r₁ r₂ : Poly) (h : denote_eq ctx (r₁.reverse ++ m₁, r₂.reverse ++ m₂)) : denote_eq ctx (cancelAux fuel m₁ m₂ r₁ r₂) := by induction fuel generalizing m₁ m₂ r₁ r₂ with | zero => assumption | succ fuel ih => simp split <;> simp at h <;> try assumption rename_i k₁ v₁ m₁ k₂ v₂ m₂ by_cases hltv : Nat.blt v₁ v₂ <;> simp [hltv] · apply ih; simp [denote_eq] at h |-; assumption · by_cases hgtv : Nat.blt v₂ v₁ <;> simp [hgtv] · apply ih; simp [denote_eq] at h |-; assumption · have heqv : v₁ = v₂ := eq_of_not_blt_eq_true hltv hgtv; subst heqv by_cases hltk : Nat.blt k₁ k₂ <;> simp [hltk] · apply ih simp [denote_eq] at h |- have haux : k₁ * Var.denote ctx v₁ ≤ k₂ * Var.denote ctx v₁ := Nat.mul_le_mul_right _ (Nat.le_of_lt (Nat.blt_eq.mp hltk)) rw [Nat.mul_sub_right_distrib, ← Nat.add_assoc, ← Nat.add_sub_assoc haux] apply Eq.symm apply Nat.sub_eq_of_eq_add simp [h] · by_cases hgtk : Nat.blt k₂ k₁ <;> simp [hgtk] · apply ih simp [denote_eq] at h |- have haux : k₂ * Var.denote ctx v₁ ≤ k₁ * Var.denote ctx v₁ := Nat.mul_le_mul_right _ (Nat.le_of_lt (Nat.blt_eq.mp hgtk)) rw [Nat.mul_sub_right_distrib, ← Nat.add_assoc, ← Nat.add_sub_assoc haux] apply Nat.sub_eq_of_eq_add simp [h] · have heqk : k₁ = k₂ := eq_of_not_blt_eq_true hltk hgtk; subst heqk apply ih simp [denote_eq] at h |- rw [← Nat.add_assoc, ← Nat.add_assoc] at h exact Nat.add_right_cancel h theorem Poly.of_denote_eq_cancelAux (ctx : Context) (fuel : Nat) (m₁ m₂ r₁ r₂ : Poly) (h : denote_eq ctx (cancelAux fuel m₁ m₂ r₁ r₂)) : denote_eq ctx (r₁.reverse ++ m₁, r₂.reverse ++ m₂) := by induction fuel generalizing m₁ m₂ r₁ r₂ with | zero => assumption | succ fuel ih => simp at h split at h <;> simp <;> try assumption rename_i k₁ v₁ m₁ k₂ v₂ m₂ by_cases hltv : Nat.blt v₁ v₂ <;> simp [hltv] at h · have ih := ih (h := h); simp [denote_eq] at ih ⊢; assumption · by_cases hgtv : Nat.blt v₂ v₁ <;> simp [hgtv] at h · have ih := ih (h := h); simp [denote_eq] at ih ⊢; assumption · have heqv : v₁ = v₂ := eq_of_not_blt_eq_true hltv hgtv; subst heqv by_cases hltk : Nat.blt k₁ k₂ <;> simp [hltk] at h · have ih := ih (h := h); simp [denote_eq] at ih ⊢ have haux : k₁ * Var.denote ctx v₁ ≤ k₂ * Var.denote ctx v₁ := Nat.mul_le_mul_right _ (Nat.le_of_lt (Nat.blt_eq.mp hltk)) rw [Nat.mul_sub_right_distrib, ← Nat.add_assoc, ← Nat.add_sub_assoc haux] at ih have ih := Nat.eq_add_of_sub_eq (Nat.le_trans haux (Nat.le_add_left ..)) ih.symm simp at ih rw [ih] · by_cases hgtk : Nat.blt k₂ k₁ <;> simp [hgtk] at h · have ih := ih (h := h); simp [denote_eq] at ih ⊢ have haux : k₂ * Var.denote ctx v₁ ≤ k₁ * Var.denote ctx v₁ := Nat.mul_le_mul_right _ (Nat.le_of_lt (Nat.blt_eq.mp hgtk)) rw [Nat.mul_sub_right_distrib, ← Nat.add_assoc, ← Nat.add_sub_assoc haux] at ih have ih := Nat.eq_add_of_sub_eq (Nat.le_trans haux (Nat.le_add_left ..)) ih simp at ih rw [ih] · have heqk : k₁ = k₂ := eq_of_not_blt_eq_true hltk hgtk; subst heqk have ih := ih (h := h); simp [denote_eq] at ih ⊢ rw [← Nat.add_assoc, ih, Nat.add_assoc] theorem Poly.denote_eq_cancel {ctx : Context} {m₁ m₂ : Poly} (h : denote_eq ctx (m₁, m₂)) : denote_eq ctx (cancel m₁ m₂) := by simp; apply denote_eq_cancelAux; simp [h] theorem Poly.of_denote_eq_cancel {ctx : Context} {m₁ m₂ : Poly} (h : denote_eq ctx (cancel m₁ m₂)) : denote_eq ctx (m₁, m₂) := by simp at h have := Poly.of_denote_eq_cancelAux (h := h) simp at this assumption theorem Poly.denote_eq_cancel_eq (ctx : Context) (m₁ m₂ : Poly) : denote_eq ctx (cancel m₁ m₂) = denote_eq ctx (m₁, m₂) := propext <| Iff.intro (fun h => of_denote_eq_cancel h) (fun h => denote_eq_cancel h) attribute [local simp] Poly.denote_eq_cancel_eq theorem Poly.denote_le_cancelAux (ctx : Context) (fuel : Nat) (m₁ m₂ r₁ r₂ : Poly) (h : denote_le ctx (r₁.reverse ++ m₁, r₂.reverse ++ m₂)) : denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂) := by induction fuel generalizing m₁ m₂ r₁ r₂ with | zero => assumption | succ fuel ih => simp split <;> simp at h <;> try assumption rename_i k₁ v₁ m₁ k₂ v₂ m₂ by_cases hltv : Nat.blt v₁ v₂ <;> simp [hltv] · apply ih; simp [denote_le] at h |-; assumption · by_cases hgtv : Nat.blt v₂ v₁ <;> simp [hgtv] · apply ih; simp [denote_le] at h |-; assumption · have heqv : v₁ = v₂ := eq_of_not_blt_eq_true hltv hgtv; subst heqv by_cases hltk : Nat.blt k₁ k₂ <;> simp [hltk] · apply ih simp [denote_le] at h |- have haux : k₁ * Var.denote ctx v₁ ≤ k₂ * Var.denote ctx v₁ := Nat.mul_le_mul_right _ (Nat.le_of_lt (Nat.blt_eq.mp hltk)) rw [Nat.mul_sub_right_distrib, ← Nat.add_assoc, ← Nat.add_sub_assoc haux] apply Nat.le_sub_of_add_le simp [h] · by_cases hgtk : Nat.blt k₂ k₁ <;> simp [hgtk] · apply ih simp [denote_le] at h |- have haux : k₂ * Var.denote ctx v₁ ≤ k₁ * Var.denote ctx v₁ := Nat.mul_le_mul_right _ (Nat.le_of_lt (Nat.blt_eq.mp hgtk)) rw [Nat.mul_sub_right_distrib, ← Nat.add_assoc, ← Nat.add_sub_assoc haux] apply Nat.sub_le_of_le_add simp [h] · have heqk : k₁ = k₂ := eq_of_not_blt_eq_true hltk hgtk; subst heqk apply ih simp [denote_le] at h |- rw [← Nat.add_assoc, ← Nat.add_assoc] at h apply Nat.le_of_add_le_add_right h done theorem Poly.of_denote_le_cancelAux (ctx : Context) (fuel : Nat) (m₁ m₂ r₁ r₂ : Poly) (h : denote_le ctx (cancelAux fuel m₁ m₂ r₁ r₂)) : denote_le ctx (r₁.reverse ++ m₁, r₂.reverse ++ m₂) := by induction fuel generalizing m₁ m₂ r₁ r₂ with | zero => assumption | succ fuel ih => simp at h split at h <;> simp <;> try assumption rename_i k₁ v₁ m₁ k₂ v₂ m₂ by_cases hltv : Nat.blt v₁ v₂ <;> simp [hltv] at h · have ih := ih (h := h); simp [denote_le] at ih ⊢; assumption · by_cases hgtv : Nat.blt v₂ v₁ <;> simp [hgtv] at h · have ih := ih (h := h); simp [denote_le] at ih ⊢; assumption · have heqv : v₁ = v₂ := eq_of_not_blt_eq_true hltv hgtv; subst heqv by_cases hltk : Nat.blt k₁ k₂ <;> simp [hltk] at h · have ih := ih (h := h); simp [denote_le] at ih ⊢ have haux : k₁ * Var.denote ctx v₁ ≤ k₂ * Var.denote ctx v₁ := Nat.mul_le_mul_right _ (Nat.le_of_lt (Nat.blt_eq.mp hltk)) rw [Nat.mul_sub_right_distrib, ← Nat.add_assoc, ← Nat.add_sub_assoc haux] at ih have := Nat.add_le_of_le_sub (Nat.le_trans haux (Nat.le_add_left ..)) ih simp at this exact this · by_cases hgtk : Nat.blt k₂ k₁ <;> simp [hgtk] at h · have ih := ih (h := h); simp [denote_le] at ih ⊢ have haux : k₂ * Var.denote ctx v₁ ≤ k₁ * Var.denote ctx v₁ := Nat.mul_le_mul_right _ (Nat.le_of_lt (Nat.blt_eq.mp hgtk)) rw [Nat.mul_sub_right_distrib, ← Nat.add_assoc, ← Nat.add_sub_assoc haux] at ih have := Nat.le_add_of_sub_le ih simp at this exact this · have heqk : k₁ = k₂ := eq_of_not_blt_eq_true hltk hgtk; subst heqk have ih := ih (h := h); simp [denote_le] at ih ⊢ have := Nat.add_le_add_right ih (k₁ * Var.denote ctx v₁) simp at this exact this theorem Poly.denote_le_cancel {ctx : Context} {m₁ m₂ : Poly} (h : denote_le ctx (m₁, m₂)) : denote_le ctx (cancel m₁ m₂) := by simp; apply denote_le_cancelAux; simp [h] theorem Poly.of_denote_le_cancel {ctx : Context} {m₁ m₂ : Poly} (h : denote_le ctx (cancel m₁ m₂)) : denote_le ctx (m₁, m₂) := by simp at h have := Poly.of_denote_le_cancelAux (h := h) simp at this assumption theorem Poly.denote_le_cancel_eq (ctx : Context) (m₁ m₂ : Poly) : denote_le ctx (cancel m₁ m₂) = denote_le ctx (m₁, m₂) := propext <| Iff.intro (fun h => of_denote_le_cancel h) (fun h => denote_le_cancel h) attribute [local simp] Poly.denote_le_cancel_eq theorem Poly.denote_combineAux (ctx : Context) (fuel : Nat) (p₁ p₂ : Poly) : (p₁.combineAux fuel p₂).denote ctx = p₁.denote ctx + p₂.denote ctx := by induction fuel generalizing p₁ p₂ with simp [combineAux] | succ fuel ih => split <;> simp rename_i k₁ v₁ p₁ k₂ v₂ p₂ by_cases hltv : Nat.blt v₁ v₂ <;> simp [hltv, ih] by_cases hgtv : Nat.blt v₂ v₁ <;> simp [hgtv, ih] have heqv : v₁ = v₂ := eq_of_not_blt_eq_true hltv hgtv simp [heqv] theorem Poly.denote_combine (ctx : Context) (p₁ p₂ : Poly) : (p₁.combine p₂).denote ctx = p₁.denote ctx + p₂.denote ctx := by simp [combine, denote_combineAux] attribute [local simp] Poly.denote_combine theorem Expr.denote_toPoly (ctx : Context) (e : Expr) : e.toPoly.denote ctx = e.denote ctx := by induction e with | num k => by_cases h : k == 0 <;> simp [toPoly, h, Var.denote]; simp [eq_of_beq h] | var i => simp [toPoly] | add a b iha ihb => simp [toPoly, iha, ihb] | mulL k a ih => simp [toPoly, ih, -Poly.mul] | mulR k a ih => simp [toPoly, ih, -Poly.mul] attribute [local simp] Expr.denote_toPoly theorem Expr.eq_of_toNormPoly (ctx : Context) (a b : Expr) (h : a.toNormPoly = b.toNormPoly) : a.denote ctx = b.denote ctx := by simp [toNormPoly, Poly.norm] at h have h := congrArg (Poly.denote ctx) h simp at h assumption theorem Expr.of_cancel_eq (ctx : Context) (a b c d : Expr) (h : Poly.cancel a.toNormPoly b.toNormPoly = (c.toPoly, d.toPoly)) : (a.denote ctx = b.denote ctx) = (c.denote ctx = d.denote ctx) := by have := Poly.denote_eq_cancel_eq ctx a.toNormPoly b.toNormPoly rw [h] at this simp [toNormPoly, Poly.norm, Poly.denote_eq] at this exact this.symm theorem Expr.of_cancel_le (ctx : Context) (a b c d : Expr) (h : Poly.cancel a.toNormPoly b.toNormPoly = (c.toPoly, d.toPoly)) : (a.denote ctx ≤ b.denote ctx) = (c.denote ctx ≤ d.denote ctx) := by have := Poly.denote_le_cancel_eq ctx a.toNormPoly b.toNormPoly rw [h] at this simp [toNormPoly, Poly.norm,Poly.denote_le] at this exact this.symm theorem Expr.of_cancel_lt (ctx : Context) (a b c d : Expr) (h : Poly.cancel a.inc.toNormPoly b.toNormPoly = (c.inc.toPoly, d.toPoly)) : (a.denote ctx < b.denote ctx) = (c.denote ctx < d.denote ctx) := of_cancel_le ctx a.inc b c.inc d h theorem ExprCnstr.toPoly_norm_eq (c : ExprCnstr) : c.toPoly.norm = c.toNormPoly := rfl theorem ExprCnstr.denote_toPoly (ctx : Context) (c : ExprCnstr) : c.toPoly.denote ctx = c.denote ctx := by cases c; rename_i eq lhs rhs simp [ExprCnstr.denote, PolyCnstr.denote, ExprCnstr.toPoly]; by_cases h : eq = true <;> simp [h] · simp [Poly.denote_eq, Expr.toPoly] · simp [Poly.denote_le, Expr.toPoly] attribute [local simp] ExprCnstr.denote_toPoly theorem ExprCnstr.denote_toNormPoly (ctx : Context) (c : ExprCnstr) : c.toNormPoly.denote ctx = c.denote ctx := by cases c; rename_i eq lhs rhs simp [ExprCnstr.denote, PolyCnstr.denote, ExprCnstr.toNormPoly] by_cases h : eq = true <;> simp [h] · rw [Poly.denote_eq_cancel_eq]; simp [Poly.denote_eq, Expr.toNormPoly, Poly.norm] · rw [Poly.denote_le_cancel_eq]; simp [Poly.denote_le, Expr.toNormPoly, Poly.norm] attribute [local simp] ExprCnstr.denote_toNormPoly theorem Poly.mul.go_denote (ctx : Context) (k : Nat) (p : Poly) : (Poly.mul.go k p).denote ctx = k * p.denote ctx := by match p with | [] => rfl | (k', v) :: p => simp [Poly.mul.go, go_denote] attribute [local simp] Poly.mul.go_denote section attribute [-simp] Nat.right_distrib Nat.left_distrib theorem PolyCnstr.denote_mul (ctx : Context) (k : Nat) (c : PolyCnstr) : (c.mul (k+1)).denote ctx = c.denote ctx := by cases c; rename_i eq lhs rhs have : k ≠ 0 → k + 1 ≠ 1 := by intro h; match k with | 0 => contradiction | k+1 => simp; apply Nat.succ_ne_zero have : ¬ (k == 0) → (k + 1 == 1) = false := fun h => beq_false_of_ne (this (ne_of_beq_false (Bool.of_not_eq_true h))) have : ¬ ((k + 1 == 0) = true) := fun h => absurd (eq_of_beq h) (Nat.succ_ne_zero k) have : (1 == 0) = false := rfl have : (1 == 1) = true := rfl by_cases he : eq = true <;> simp [he, PolyCnstr.mul, PolyCnstr.denote, Poly.denote_le, Poly.denote_eq] <;> by_cases hk : k == 0 <;> (try simp [eq_of_beq hk]) <;> simp [*] <;> apply propext <;> apply Iff.intro <;> intro h · exact Nat.eq_of_mul_eq_mul_left (Nat.zero_lt_succ _) h · rw [h] · exact Nat.le_of_mul_le_mul_left h (Nat.zero_lt_succ _) · apply Nat.mul_le_mul_left _ h end attribute [local simp] PolyCnstr.denote_mul theorem PolyCnstr.denote_combine {ctx : Context} {c₁ c₂ : PolyCnstr} (h₁ : c₁.denote ctx) (h₂ : c₂.denote ctx) : (c₁.combine c₂).denote ctx := by cases c₁; cases c₂; rename_i eq₁ lhs₁ rhs₁ eq₂ lhs₂ rhs₂ simp [denote] at h₁ h₂ simp [PolyCnstr.combine, denote] by_cases he₁ : eq₁ = true <;> by_cases he₂ : eq₂ = true <;> simp [he₁, he₂] at h₁ h₂ |- · rw [Poly.denote_eq_cancel_eq]; simp [Poly.denote_eq] at h₁ h₂ |-; simp [h₁, h₂] · rw [Poly.denote_le_cancel_eq]; simp [Poly.denote_eq, Poly.denote_le] at h₁ h₂ |-; rw [h₁]; apply Nat.add_le_add_left h₂ · rw [Poly.denote_le_cancel_eq]; simp [Poly.denote_eq, Poly.denote_le] at h₁ h₂ |-; rw [h₂]; apply Nat.add_le_add_right h₁ · rw [Poly.denote_le_cancel_eq]; simp [Poly.denote_eq, Poly.denote_le] at h₁ h₂ |-; apply Nat.add_le_add h₁ h₂ attribute [local simp] PolyCnstr.denote_combine theorem Poly.isNum?_eq_some (ctx : Context) {p : Poly} {k : Nat} : p.isNum? = some k → p.denote ctx = k := by simp [isNum?] split next => intro h; injection h; subst k; simp next k v => by_cases h : v == fixedVar <;> simp [h]; intros; simp [Var.denote, eq_of_beq h]; assumption next => intros; contradiction theorem Poly.of_isZero (ctx : Context) {p : Poly} (h : isZero p = true) : p.denote ctx = 0 := by simp [isZero] at h split at h · simp · contradiction theorem Poly.of_isNonZero (ctx : Context) {p : Poly} (h : isNonZero p = true) : p.denote ctx > 0 := by match p with | [] => contradiction | (k, v) :: p => by_cases he : v == fixedVar <;> simp [he, isNonZero] at h ⊢ · simp [eq_of_beq he, Var.denote]; apply Nat.lt_of_succ_le; exact Nat.le_trans h (Nat.le_add_right ..) · have ih := of_isNonZero ctx h exact Nat.le_trans ih (Nat.le_add_right ..) theorem PolyCnstr.eq_false_of_isUnsat (ctx : Context) {c : PolyCnstr} : c.isUnsat → c.denote ctx = False := by cases c; rename_i eq lhs rhs simp [isUnsat] by_cases he : eq = true <;> simp [he, denote, Poly.denote_eq, Poly.denote_le] · intro | Or.inl ⟨h₁, h₂⟩ => simp [Poly.of_isZero, h₁]; have := Nat.not_eq_zero_of_lt (Poly.of_isNonZero ctx h₂); simp [this.symm] | Or.inr ⟨h₁, h₂⟩ => simp [Poly.of_isZero, h₂]; have := Nat.not_eq_zero_of_lt (Poly.of_isNonZero ctx h₁); simp [this] · intro ⟨h₁, h₂⟩ simp [Poly.of_isZero, h₂] have := Nat.not_eq_zero_of_lt (Poly.of_isNonZero ctx h₁) simp [this] done theorem PolyCnstr.eq_true_of_isValid (ctx : Context) {c : PolyCnstr} : c.isValid → c.denote ctx = True := by cases c; rename_i eq lhs rhs simp [isValid] by_cases he : eq = true <;> simp [he, denote, Poly.denote_eq, Poly.denote_le] · intro ⟨h₁, h₂⟩ simp [Poly.of_isZero, h₁, h₂] · intro h simp [Poly.of_isZero, h] theorem ExprCnstr.eq_false_of_isUnsat (ctx : Context) (c : ExprCnstr) (h : c.toNormPoly.isUnsat) : c.denote ctx = False := by have := PolyCnstr.eq_false_of_isUnsat ctx h simp at this assumption theorem ExprCnstr.eq_true_of_isValid (ctx : Context) (c : ExprCnstr) (h : c.toNormPoly.isValid) : c.denote ctx = True := by have := PolyCnstr.eq_true_of_isValid ctx h simp at this assumption theorem Certificate.of_combineHyps (ctx : Context) (c : PolyCnstr) (cs : Certificate) (h : (combineHyps c cs).denote ctx → False) : c.denote ctx → cs.denote ctx := by match cs with | [] => simp [combineHyps, denote] at *; exact h | (k, c')::cs => intro h₁ h₂ have := PolyCnstr.denote_combine (ctx := ctx) (c₂ := PolyCnstr.mul (k + 1) (ExprCnstr.toNormPoly c')) h₁ simp at this have := this h₂ have ih := of_combineHyps ctx (PolyCnstr.combine c (PolyCnstr.mul (k + 1) (ExprCnstr.toNormPoly c'))) cs exact ih h this theorem Certificate.of_combine (ctx : Context) (cs : Certificate) (h : cs.combine.denote ctx → False) : cs.denote ctx := by match cs with | [] => simp [combine, PolyCnstr.denote, Poly.denote_eq] at h | (k, c)::cs => simp [denote, combine] at * intro h' apply of_combineHyps (h := h) simp [h'] theorem Certificate.of_combine_isUnsat (ctx : Context) (cs : Certificate) (h : cs.combine.isUnsat) : cs.denote ctx := have h := PolyCnstr.eq_false_of_isUnsat ctx h of_combine ctx cs (fun h' => Eq.mp h h') theorem denote_monomialToExpr (ctx : Context) (k : Nat) (v : Var) : (monomialToExpr k v).denote ctx = k * v.denote ctx := by simp [monomialToExpr] by_cases h : v == fixedVar <;> simp [h, Expr.denote] · simp [eq_of_beq h, Var.denote] · by_cases h : k == 1 <;> simp [h, Expr.denote]; simp [eq_of_beq h] attribute [local simp] denote_monomialToExpr theorem Poly.denote_toExpr_go (ctx : Context) (e : Expr) (p : Poly) : (toExpr.go e p).denote ctx = e.denote ctx + p.denote ctx := by induction p generalizing e with | nil => simp [toExpr.go, Poly.denote] | cons kv p ih => cases kv; simp [toExpr.go, ih, Expr.denote, Poly.denote] attribute [local simp] Poly.denote_toExpr_go theorem Poly.denote_toExpr (ctx : Context) (p : Poly) : p.toExpr.denote ctx = p.denote ctx := by match p with | [] => simp [toExpr, Expr.denote, Poly.denote] | (k, v) :: p => simp [toExpr, Expr.denote, Poly.denote] theorem ExprCnstr.eq_of_toNormPoly_eq (ctx : Context) (c d : ExprCnstr) (h : c.toNormPoly == d.toPoly) : c.denote ctx = d.denote ctx := by have h := congrArg (PolyCnstr.denote ctx) (eq_of_beq h) simp at h assumption theorem Expr.eq_of_toNormPoly_eq (ctx : Context) (e e' : Expr) (h : e.toNormPoly == e'.toPoly) : e.denote ctx = e'.denote ctx := by have h := congrArg (Poly.denote ctx) (eq_of_beq h) simp [Expr.toNormPoly, Poly.norm] at h assumption end Nat.Linear
0c7ccda8d94bf79e16a8a6b3d51a29ce69eebba3
432d948a4d3d242fdfb44b81c9e1b1baacd58617
/src/topology/omega_complete_partial_order.lean
5fb806afeed53e00e31e340780acea151512ce09
[ "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
5,254
lean
/- Copyright (c) 2020 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import topology.basic import order.omega_complete_partial_order /-! # Scott Topological Spaces A type of topological spaces whose notion of continuity is equivalent to continuity in ωCPOs. ## Reference * https://ncatlab.org/nlab/show/Scott+topology -/ open omega_complete_partial_order open_locale classical universes u namespace Scott /-- -/ def is_ωSup {α : Type u} [preorder α] (c : chain α) (x : α) : Prop := (∀ i, c i ≤ x) ∧ (∀ y, (∀ i, c i ≤ y) → x ≤ y) variables (α : Type u) [omega_complete_partial_order α] local attribute [irreducible] set /-- The characteristic function of open sets is monotone and preserves the limits of chains. -/ def is_open (s : set α) : Prop := continuous' (λ x, x ∈ s) theorem is_open_univ : is_open α set.univ := ⟨λ x y h, by simp only [set.mem_univ]; refl', by convert @complete_lattice.top_continuous α Prop _ _; ext; simp ⟩ theorem is_open_inter (s t : set α) : is_open α s → is_open α t → is_open α (s ∩ t) := begin simp only [is_open, exists_imp_distrib, continuous'], intros h₀ h₁ h₂ h₃, rw ← set.inf_eq_inter, let s' : α →ₘ Prop := ⟨λ x, x ∈ s, h₀⟩, let t' : α →ₘ Prop := ⟨λ x, x ∈ t, h₂⟩, split, { change omega_complete_partial_order.continuous (s' ⊓ t'), haveI : is_total Prop (≤) := ⟨ @le_total Prop _ ⟩, apply complete_lattice.inf_continuous; assumption }, { intros x y h, apply and_implies; solve_by_elim [h₀ h, h₂ h], } end theorem is_open_sUnion : ∀s, (∀t∈s, is_open α t) → is_open α (⋃₀ s) := begin introv h₀, suffices : is_open α ({ x | Sup (flip (∈) '' s) x }), { convert this, ext, simp only [set.sUnion, Sup, set.mem_image, set.mem_set_of_eq, supr, conditionally_complete_lattice.Sup, exists_exists_and_eq_and, complete_lattice.Sup, exists_prop, set.mem_range, set_coe.exists, eq_iff_iff, subtype.coe_mk], tauto, }, dsimp [is_open] at *, apply complete_lattice.Sup_continuous' _, introv ht, specialize h₀ { x | t x } _, { simp only [flip, set.mem_image] at *, rcases ht with ⟨x,h₀,h₁⟩, subst h₁, simpa, }, { simpa using h₀ } end end Scott /-- A Scott topological space is defined on preorders such that their open sets, seen as a function `α → Prop`, preserves the joins of ω-chains -/ @[reducible] def Scott (α : Type u) := α instance Scott.topological_space (α : Type u) [omega_complete_partial_order α] : topological_space (Scott α) := { is_open := Scott.is_open α, is_open_univ := Scott.is_open_univ α, is_open_inter := Scott.is_open_inter α, is_open_sUnion := Scott.is_open_sUnion α } section not_below variables {α : Type*} [omega_complete_partial_order α] (y : Scott α) /-- `not_below` is an open set in `Scott α` used to prove the monotonicity of continuous functions -/ def not_below := { x | ¬ x ≤ y } lemma not_below_is_open : is_open (not_below y) := begin have h : monotone (not_below y), { intros x y' h, simp only [not_below, set_of, le_iff_imp], intros h₀ h₁, apply h₀ (le_trans h h₁) }, existsi h, rintros c, apply eq_of_forall_ge_iff, intro z, rw ωSup_le_iff, simp only [ωSup_le_iff, not_below, set.mem_set_of_eq, le_iff_imp, preorder_hom.coe_fun_mk, chain.map_to_fun, function.comp_app, exists_imp_distrib, not_forall], end end not_below open Scott (hiding is_open) open omega_complete_partial_order lemma is_ωSup_ωSup {α} [omega_complete_partial_order α] (c : chain α) : is_ωSup c (ωSup c) := begin split, { apply le_ωSup, }, { apply ωSup_le, }, end lemma Scott_continuous_of_continuous {α β} [omega_complete_partial_order α] [omega_complete_partial_order β] (f : Scott α → Scott β) (hf : continuous f) : omega_complete_partial_order.continuous' f := begin simp only [continuous_def, (⁻¹')] at hf, have h : monotone f, { intros x y h, cases (hf {x | ¬ x ≤ f y} (not_below_is_open _)) with hf hf', clear hf', specialize hf h, simp only [set.preimage, set_of, (∈), set.mem, le_iff_imp] at hf, by_contradiction H, apply hf H (le_refl (f y)) }, existsi h, intro c, apply eq_of_forall_ge_iff, intro z, specialize (hf _ (not_below_is_open z)), cases hf, specialize hf_h c, simp only [not_below, preorder_hom.coe_fun_mk, eq_iff_iff, set.mem_set_of_eq] at hf_h, rw [← not_iff_not], simp only [ωSup_le_iff, hf_h, ωSup, supr, Sup, complete_lattice.Sup, complete_semilattice_Sup.Sup, exists_prop, set.mem_range, preorder_hom.coe_fun_mk, chain.map_to_fun, function.comp_app, eq_iff_iff, not_forall], tauto, end lemma continuous_of_Scott_continuous {α β} [omega_complete_partial_order α] [omega_complete_partial_order β] (f : Scott α → Scott β) (hf : omega_complete_partial_order.continuous' f) : continuous f := begin rw continuous_def, intros s hs, change continuous' (s ∘ f), cases hs with hs hs', cases hf with hf hf', apply continuous.of_bundled, apply continuous_comp _ _ hf' hs', end
fa09b45f36938ccd5d3bc42b371c1ec9f2043032
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/ring_theory/polynomial/basic.lean
e52467169c4c4c366a0da1a007855ce0632044e3
[]
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
20,234
lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau # Ring-theoretic supplement of data.polynomial. ## Main results * `mv_polynomial.integral_domain`: If a ring is an integral domain, then so is its polynomial ring over finitely many variables. * `polynomial.is_noetherian_ring`: Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring. * `polynomial.wf_dvd_monoid`: If an integral domain is a `wf_dvd_monoid`, then so is its polynomial ring. * `polynomial.unique_factorization_monoid`: If an integral domain is a `unique_factorization_monoid`, then so is its polynomial ring. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.algebra.char_p.basic import Mathlib.data.mv_polynomial.comm_ring import Mathlib.data.mv_polynomial.equiv import Mathlib.data.polynomial.field_division import Mathlib.ring_theory.principal_ideal_domain import Mathlib.ring_theory.polynomial.content import Mathlib.PostPort universes u u_1 v w namespace Mathlib namespace polynomial protected instance char_p {R : Type u} [semiring R] (p : ℕ) [h : char_p R p] : char_p (polynomial R) p := sorry /-- The `R`-submodule of `R[X]` consisting of polynomials of degree ≤ `n`. -/ def degree_le (R : Type u) [comm_ring R] (n : with_bot ℕ) : submodule R (polynomial R) := infi fun (k : ℕ) => infi fun (h : ↑k > n) => linear_map.ker (lcoeff R k) /-- The `R`-submodule of `R[X]` consisting of polynomials of degree < `n`. -/ def degree_lt (R : Type u) [comm_ring R] (n : ℕ) : submodule R (polynomial R) := infi fun (k : ℕ) => infi fun (h : k ≥ n) => linear_map.ker (lcoeff R k) theorem mem_degree_le {R : Type u} [comm_ring R] {n : with_bot ℕ} {f : polynomial R} : f ∈ degree_le R n ↔ degree f ≤ n := sorry theorem degree_le_mono {R : Type u} [comm_ring R] {m : with_bot ℕ} {n : with_bot ℕ} (H : m ≤ n) : degree_le R m ≤ degree_le R n := fun (f : polynomial R) (hf : f ∈ degree_le R m) => iff.mpr mem_degree_le (le_trans (iff.mp mem_degree_le hf) H) theorem degree_le_eq_span_X_pow {R : Type u} [comm_ring R] {n : ℕ} : degree_le R ↑n = submodule.span R ↑(finset.image (fun (n : ℕ) => X ^ n) (finset.range (n + 1))) := sorry theorem mem_degree_lt {R : Type u} [comm_ring R] {n : ℕ} {f : polynomial R} : f ∈ degree_lt R n ↔ degree f < ↑n := sorry theorem degree_lt_mono {R : Type u} [comm_ring R] {m : ℕ} {n : ℕ} (H : m ≤ n) : degree_lt R m ≤ degree_lt R n := fun (f : polynomial R) (hf : f ∈ degree_lt R m) => iff.mpr mem_degree_lt (lt_of_lt_of_le (iff.mp mem_degree_lt hf) (iff.mpr with_bot.coe_le_coe H)) theorem degree_lt_eq_span_X_pow {R : Type u} [comm_ring R] {n : ℕ} : degree_lt R n = submodule.span R ↑(finset.image (fun (n : ℕ) => X ^ n) (finset.range n)) := sorry /-- The first `n` coefficients on `degree_lt n` form a linear equivalence with `fin n → F`. -/ def degree_lt_equiv (F : Type u_1) [field F] (n : ℕ) : linear_equiv F (↥(degree_lt F n)) (fin n → F) := linear_equiv.mk (fun (p : ↥(degree_lt F n)) (n_1 : fin n) => coeff ↑p ↑n_1) sorry sorry (fun (f : fin n → F) => { val := finset.sum finset.univ fun (i : fin n) => coe_fn (monomial ↑i) (f i), property := sorry }) sorry sorry /-- Given a polynomial, return the polynomial whose coefficients are in the ring closure of the original coefficients. -/ def restriction {R : Type u} [comm_ring R] (p : polynomial R) : polynomial ↥(ring.closure ↑(finsupp.frange p)) := finsupp.mk (finsupp.support p) (fun (i : ℕ) => { val := finsupp.to_fun p i, property := sorry }) sorry @[simp] theorem coeff_restriction {R : Type u} [comm_ring R] {p : polynomial R} {n : ℕ} : ↑(coeff (restriction p) n) = coeff p n := rfl @[simp] theorem coeff_restriction' {R : Type u} [comm_ring R] {p : polynomial R} {n : ℕ} : subtype.val (coeff (restriction p) n) = coeff p n := rfl @[simp] theorem map_restriction {R : Type u} [comm_ring R] (p : polynomial R) : map (algebra_map (↥(ring.closure ↑(finsupp.frange p))) R) (restriction p) = p := sorry @[simp] theorem degree_restriction {R : Type u} [comm_ring R] {p : polynomial R} : degree (restriction p) = degree p := rfl @[simp] theorem nat_degree_restriction {R : Type u} [comm_ring R] {p : polynomial R} : nat_degree (restriction p) = nat_degree p := rfl @[simp] theorem monic_restriction {R : Type u} [comm_ring R] {p : polynomial R} : monic (restriction p) ↔ monic p := { mp := fun (H : monic (restriction p)) => congr_arg subtype.val H, mpr := fun (H : monic p) => subtype.eq H } @[simp] theorem restriction_zero {R : Type u} [comm_ring R] : restriction 0 = 0 := rfl @[simp] theorem restriction_one {R : Type u} [comm_ring R] : restriction 1 = 1 := sorry theorem eval₂_restriction {R : Type u} [comm_ring R] {S : Type v} [ring S] {f : R →+* S} {x : S} {p : polynomial R} : eval₂ f x p = eval₂ (ring_hom.comp f (is_subring.subtype (ring.closure ↑(finsupp.frange p)))) x (restriction p) := id (Eq.refl (finsupp.sum p fun (e : ℕ) (a : R) => coe_fn f a * x ^ e)) /-- Given a polynomial `p` and a subring `T` that contains the coefficients of `p`, return the corresponding polynomial whose coefficients are in `T. -/ def to_subring {R : Type u} [comm_ring R] (p : polynomial R) (T : set R) [is_subring T] (hp : ↑(finsupp.frange p) ⊆ T) : polynomial ↥T := finsupp.mk (finsupp.support p) (fun (i : ℕ) => { val := finsupp.to_fun p i, property := sorry }) sorry @[simp] theorem coeff_to_subring {R : Type u} [comm_ring R] (p : polynomial R) (T : set R) [is_subring T] (hp : ↑(finsupp.frange p) ⊆ T) {n : ℕ} : ↑(coeff (to_subring p T hp) n) = coeff p n := rfl @[simp] theorem coeff_to_subring' {R : Type u} [comm_ring R] (p : polynomial R) (T : set R) [is_subring T] (hp : ↑(finsupp.frange p) ⊆ T) {n : ℕ} : subtype.val (coeff (to_subring p T hp) n) = coeff p n := rfl @[simp] theorem degree_to_subring {R : Type u} [comm_ring R] (p : polynomial R) (T : set R) [is_subring T] (hp : ↑(finsupp.frange p) ⊆ T) : degree (to_subring p T hp) = degree p := rfl @[simp] theorem nat_degree_to_subring {R : Type u} [comm_ring R] (p : polynomial R) (T : set R) [is_subring T] (hp : ↑(finsupp.frange p) ⊆ T) : nat_degree (to_subring p T hp) = nat_degree p := rfl @[simp] theorem monic_to_subring {R : Type u} [comm_ring R] (p : polynomial R) (T : set R) [is_subring T] (hp : ↑(finsupp.frange p) ⊆ T) : monic (to_subring p T hp) ↔ monic p := { mp := fun (H : monic (to_subring p T hp)) => congr_arg subtype.val H, mpr := fun (H : monic p) => subtype.eq H } @[simp] theorem to_subring_zero {R : Type u} [comm_ring R] (T : set R) [is_subring T] : to_subring 0 T (set.empty_subset T) = 0 := rfl @[simp] theorem to_subring_one {R : Type u} [comm_ring R] (T : set R) [is_subring T] : to_subring 1 T (set.subset.trans (iff.mpr finset.coe_subset finsupp.frange_single) (iff.mpr finset.singleton_subset_set_iff is_submonoid.one_mem)) = 1 := sorry @[simp] theorem map_to_subring {R : Type u} [comm_ring R] (p : polynomial R) (T : set R) [is_subring T] (hp : ↑(finsupp.frange p) ⊆ T) : map (is_subring.subtype T) (to_subring p T hp) = p := ext fun (n : ℕ) => coeff_map (is_subring.subtype T) n /-- Given a polynomial whose coefficients are in some subring, return the corresponding polynomial whose coefificents are in the ambient ring. -/ def of_subring {R : Type u} [comm_ring R] (T : set R) [is_subring T] (p : polynomial ↥T) : polynomial R := finsupp.mk (finsupp.support p) (subtype.val ∘ finsupp.to_fun p) sorry @[simp] theorem frange_of_subring {R : Type u} [comm_ring R] (T : set R) [is_subring T] {p : polynomial ↥T} : ↑(finsupp.frange (of_subring T p)) ⊆ T := sorry end polynomial namespace ideal /-- If every coefficient of a polynomial is in an ideal `I`, then so is the polynomial itself -/ theorem polynomial_mem_ideal_of_coeff_mem_ideal {R : Type u} [comm_ring R] (I : ideal (polynomial R)) (p : polynomial R) (hp : ∀ (n : ℕ), polynomial.coeff p n ∈ comap polynomial.C I) : p ∈ I := polynomial.sum_C_mul_X_eq p ▸ submodule.sum_mem I fun (n : ℕ) (hn : n ∈ finsupp.support p) => mul_mem_right I (polynomial.X ^ n) (hp n) /-- The push-forward of an ideal `I` of `R` to `polynomial R` via inclusion is exactly the set of polynomials whose coefficients are in `I` -/ theorem mem_map_C_iff {R : Type u} [comm_ring R] {I : ideal R} {f : polynomial R} : f ∈ map polynomial.C I ↔ ∀ (n : ℕ), polynomial.coeff f n ∈ I := sorry theorem quotient_map_C_eq_zero {R : Type u} [comm_ring R] {I : ideal R} (a : R) (H : a ∈ I) : coe_fn (ring_hom.comp (quotient.mk (map polynomial.C I)) polynomial.C) a = 0 := sorry theorem eval₂_C_mk_eq_zero {R : Type u} [comm_ring R] {I : ideal R} (f : polynomial R) (H : f ∈ map polynomial.C I) : coe_fn (polynomial.eval₂_ring_hom (ring_hom.comp polynomial.C (quotient.mk I)) polynomial.X) f = 0 := sorry /-- If `I` is an ideal of `R`, then the ring polynomials over the quotient ring `I.quotient` is isomorphic to the quotient of `polynomial R` by the ideal `map C I`, where `map C I` contains exactly the polynomials whose coefficients all lie in `I` -/ def polynomial_quotient_equiv_quotient_polynomial {R : Type u} [comm_ring R] (I : ideal R) : polynomial (quotient I) ≃+* quotient (map polynomial.C I) := ring_equiv.mk ⇑(polynomial.eval₂_ring_hom (quotient.lift I (ring_hom.comp (quotient.mk (map polynomial.C I)) polynomial.C) quotient_map_C_eq_zero) (coe_fn (quotient.mk (map polynomial.C I)) polynomial.X)) ⇑(quotient.lift (map polynomial.C I) (polynomial.eval₂_ring_hom (ring_hom.comp polynomial.C (quotient.mk I)) polynomial.X) eval₂_C_mk_eq_zero) sorry sorry sorry sorry /-- If `P` is a prime ideal of `R`, then `R[x]/(P)` is an integral domain. -/ theorem is_integral_domain_map_C_quotient {R : Type u} [comm_ring R] {P : ideal R} (H : is_prime P) : is_integral_domain (quotient (map polynomial.C P)) := ring_equiv.is_integral_domain (polynomial (quotient P)) (integral_domain.to_is_integral_domain (polynomial (quotient P))) (ring_equiv.symm (polynomial_quotient_equiv_quotient_polynomial P)) /-- If `P` is a prime ideal of `R`, then `P.R[x]` is a prime ideal of `R[x]`. -/ theorem is_prime_map_C_of_is_prime {R : Type u} [comm_ring R] {P : ideal R} (H : is_prime P) : is_prime (map polynomial.C P) := iff.mp (quotient.is_integral_domain_iff_prime (map polynomial.C P)) (is_integral_domain_map_C_quotient H) /-- Given any ring `R` and an ideal `I` of `polynomial R`, we get a map `R → R[x] → R[x]/I`. If we let `R` be the image of `R` in `R[x]/I` then we also have a map `R[x] → R'[x]`. In particular we can map `I` across this map, to get `I'` and a new map `R' → R'[x] → R'[x]/I`. This theorem shows `I'` will not contain any non-zero constant polynomials -/ theorem eq_zero_of_polynomial_mem_map_range {R : Type u} [comm_ring R] (I : ideal (polynomial R)) (x : ↥(ring_hom.range (ring_hom.comp (quotient.mk I) polynomial.C))) (hx : coe_fn polynomial.C x ∈ map (polynomial.map_ring_hom (ring_hom.range_restrict (ring_hom.comp (quotient.mk I) polynomial.C))) I) : x = 0 := sorry /-- `polynomial R` is never a field for any ring `R`. -/ theorem polynomial_not_is_field {R : Type u} [comm_ring R] : ¬is_field (polynomial R) := sorry /-- The only constant in a maximal ideal over a field is `0`. -/ theorem eq_zero_of_constant_mem_of_maximal {R : Type u} [comm_ring R] (hR : is_field R) (I : ideal (polynomial R)) [hI : is_maximal I] (x : R) (hx : coe_fn polynomial.C x ∈ I) : x = 0 := sorry /-- Transport an ideal of `R[X]` to an `R`-submodule of `R[X]`. -/ def of_polynomial {R : Type u} [comm_ring R] (I : ideal (polynomial R)) : submodule R (polynomial R) := submodule.mk (submodule.carrier I) sorry sorry sorry theorem mem_of_polynomial {R : Type u} [comm_ring R] {I : ideal (polynomial R)} (x : polynomial R) : x ∈ of_polynomial I ↔ x ∈ I := iff.rfl /-- Given an ideal `I` of `R[X]`, make the `R`-submodule of `I` consisting of polynomials of degree ≤ `n`. -/ def degree_le {R : Type u} [comm_ring R] (I : ideal (polynomial R)) (n : with_bot ℕ) : submodule R (polynomial R) := polynomial.degree_le R n ⊓ of_polynomial I /-- Given an ideal `I` of `R[X]`, make the ideal in `R` of leading coefficients of polynomials in `I` with degree ≤ `n`. -/ def leading_coeff_nth {R : Type u} [comm_ring R] (I : ideal (polynomial R)) (n : ℕ) : ideal R := submodule.map (polynomial.lcoeff R n) (degree_le I ↑n) theorem mem_leading_coeff_nth {R : Type u} [comm_ring R] (I : ideal (polynomial R)) (n : ℕ) (x : R) : x ∈ leading_coeff_nth I n ↔ ∃ (p : polynomial R), ∃ (H : p ∈ I), polynomial.degree p ≤ ↑n ∧ polynomial.leading_coeff p = x := sorry theorem mem_leading_coeff_nth_zero {R : Type u} [comm_ring R] (I : ideal (polynomial R)) (x : R) : x ∈ leading_coeff_nth I 0 ↔ coe_fn polynomial.C x ∈ I := sorry theorem leading_coeff_nth_mono {R : Type u} [comm_ring R] (I : ideal (polynomial R)) {m : ℕ} {n : ℕ} (H : m ≤ n) : leading_coeff_nth I m ≤ leading_coeff_nth I n := sorry /-- Given an ideal `I` in `R[X]`, make the ideal in `R` of the leading coefficients in `I`. -/ def leading_coeff {R : Type u} [comm_ring R] (I : ideal (polynomial R)) : ideal R := supr fun (n : ℕ) => leading_coeff_nth I n theorem mem_leading_coeff {R : Type u} [comm_ring R] (I : ideal (polynomial R)) (x : R) : x ∈ leading_coeff I ↔ ∃ (p : polynomial R), ∃ (H : p ∈ I), polynomial.leading_coeff p = x := sorry theorem is_fg_degree_le {R : Type u} [comm_ring R] (I : ideal (polynomial R)) [is_noetherian_ring R] (n : ℕ) : submodule.fg (degree_le I ↑n) := sorry end ideal namespace polynomial protected instance wf_dvd_monoid {R : Type u_1} [integral_domain R] [wf_dvd_monoid R] : wf_dvd_monoid (polynomial R) := sorry end polynomial /-- Hilbert basis theorem: a polynomial ring over a noetherian ring is a noetherian ring. -/ protected instance polynomial.is_noetherian_ring {R : Type u} [comm_ring R] [is_noetherian_ring R] : is_noetherian_ring (polynomial R) := sorry namespace polynomial theorem exists_irreducible_of_degree_pos {R : Type u} [integral_domain R] [wf_dvd_monoid R] {f : polynomial R} (hf : 0 < degree f) : ∃ (g : polynomial R), irreducible g ∧ g ∣ f := wf_dvd_monoid.exists_irreducible_factor (fun (huf : is_unit f) => ne_of_gt hf (degree_eq_zero_of_is_unit huf)) fun (hf0 : f = 0) => not_lt_of_lt hf (Eq.symm hf0 ▸ Eq.symm degree_zero ▸ with_bot.bot_lt_coe 0) theorem exists_irreducible_of_nat_degree_pos {R : Type u} [integral_domain R] [wf_dvd_monoid R] {f : polynomial R} (hf : 0 < nat_degree f) : ∃ (g : polynomial R), irreducible g ∧ g ∣ f := sorry theorem exists_irreducible_of_nat_degree_ne_zero {R : Type u} [integral_domain R] [wf_dvd_monoid R] {f : polynomial R} (hf : nat_degree f ≠ 0) : ∃ (g : polynomial R), irreducible g ∧ g ∣ f := exists_irreducible_of_nat_degree_pos (nat.pos_of_ne_zero hf) theorem linear_independent_powers_iff_eval₂ {R : Type u} {M : Type w} [comm_ring R] [add_comm_group M] [module R M] (f : linear_map R M M) (v : M) : (linear_independent R fun (n : ℕ) => coe_fn (f ^ n) v) ↔ ∀ (p : polynomial R), coe_fn (coe_fn (aeval f) p) v = 0 → p = 0 := sorry theorem disjoint_ker_aeval_of_coprime {R : Type u} {M : Type w} [comm_ring R] [add_comm_group M] [module R M] (f : linear_map R M M) {p : polynomial R} {q : polynomial R} (hpq : is_coprime p q) : disjoint (linear_map.ker (coe_fn (aeval f) p)) (linear_map.ker (coe_fn (aeval f) q)) := sorry theorem sup_aeval_range_eq_top_of_coprime {R : Type u} {M : Type w} [comm_ring R] [add_comm_group M] [module R M] (f : linear_map R M M) {p : polynomial R} {q : polynomial R} (hpq : is_coprime p q) : linear_map.range (coe_fn (aeval f) p) ⊔ linear_map.range (coe_fn (aeval f) q) = ⊤ := sorry theorem sup_ker_aeval_le_ker_aeval_mul {R : Type u} {M : Type w} [comm_ring R] [add_comm_group M] [module R M] {f : linear_map R M M} {p : polynomial R} {q : polynomial R} : linear_map.ker (coe_fn (aeval f) p) ⊔ linear_map.ker (coe_fn (aeval f) q) ≤ linear_map.ker (coe_fn (aeval f) (p * q)) := sorry theorem sup_ker_aeval_eq_ker_aeval_mul_of_coprime {R : Type u} {M : Type w} [comm_ring R] [add_comm_group M] [module R M] (f : linear_map R M M) {p : polynomial R} {q : polynomial R} (hpq : is_coprime p q) : linear_map.ker (coe_fn (aeval f) p) ⊔ linear_map.ker (coe_fn (aeval f) q) = linear_map.ker (coe_fn (aeval f) (p * q)) := sorry end polynomial namespace mv_polynomial theorem is_noetherian_ring_fin_0 {R : Type u} [comm_ring R] [is_noetherian_ring R] : is_noetherian_ring (mv_polynomial (fin 0) R) := is_noetherian_ring_of_ring_equiv R (ring_equiv.trans (ring_equiv.symm (pempty_ring_equiv R)) (ring_equiv_of_equiv R (equiv.symm fin_zero_equiv'))) theorem is_noetherian_ring_fin {R : Type u} [comm_ring R] [is_noetherian_ring R] {n : ℕ} : is_noetherian_ring (mv_polynomial (fin n) R) := sorry /-- The multivariate polynomial ring in finitely many variables over a noetherian ring is itself a noetherian ring. -/ protected instance is_noetherian_ring {R : Type u} {σ : Type v} [comm_ring R] [fintype σ] [is_noetherian_ring R] : is_noetherian_ring (mv_polynomial σ R) := trunc.induction_on (fintype.equiv_fin σ) fun (e : σ ≃ fin (fintype.card σ)) => is_noetherian_ring_of_ring_equiv (mv_polynomial (fin (fintype.card σ)) R) (ring_equiv_of_equiv R (equiv.symm e)) theorem is_integral_domain_fin_zero (R : Type u) [comm_ring R] (hR : is_integral_domain R) : is_integral_domain (mv_polynomial (fin 0) R) := ring_equiv.is_integral_domain R hR (ring_equiv.trans (ring_equiv_of_equiv R fin_zero_equiv') (pempty_ring_equiv R)) /-- Auxilliary lemma: Multivariate polynomials over an integral domain with variables indexed by `fin n` form an integral domain. This fact is proven inductively, and then used to prove the general case without any finiteness hypotheses. See `mv_polynomial.integral_domain` for the general case. -/ theorem is_integral_domain_fin (R : Type u) [comm_ring R] (hR : is_integral_domain R) (n : ℕ) : is_integral_domain (mv_polynomial (fin n) R) := sorry theorem is_integral_domain_fintype (R : Type u) (σ : Type v) [comm_ring R] [fintype σ] (hR : is_integral_domain R) : is_integral_domain (mv_polynomial σ R) := sorry /-- Auxilliary definition: Multivariate polynomials in finitely many variables over an integral domain form an integral domain. This fact is proven by transport of structure from the `mv_polynomial.integral_domain_fin`, and then used to prove the general case without finiteness hypotheses. See `mv_polynomial.integral_domain` for the general case. -/ def integral_domain_fintype (R : Type u) (σ : Type v) [integral_domain R] [fintype σ] : integral_domain (mv_polynomial σ R) := is_integral_domain.to_integral_domain (mv_polynomial σ R) sorry protected theorem eq_zero_or_eq_zero_of_mul_eq_zero {R : Type u} [integral_domain R] {σ : Type v} (p : mv_polynomial σ R) (q : mv_polynomial σ R) (h : p * q = 0) : p = 0 ∨ q = 0 := sorry /-- The multivariate polynomial ring over an integral domain is an integral domain. -/ protected instance integral_domain {R : Type u} {σ : Type v} [integral_domain R] : integral_domain (mv_polynomial σ R) := integral_domain.mk comm_ring.add sorry comm_ring.zero sorry sorry comm_ring.neg comm_ring.sub sorry sorry comm_ring.mul sorry comm_ring.one sorry sorry sorry sorry sorry sorry mv_polynomial.eq_zero_or_eq_zero_of_mul_eq_zero theorem map_mv_polynomial_eq_eval₂ {R : Type u} {σ : Type v} [comm_ring R] {S : Type u_1} [comm_ring S] [fintype σ] (ϕ : mv_polynomial σ R →+* S) (p : mv_polynomial σ R) : coe_fn ϕ p = eval₂ (ring_hom.comp ϕ C) (fun (s : σ) => coe_fn ϕ (X s)) p := sorry end mv_polynomial namespace polynomial protected instance unique_factorization_monoid {D : Type u} [integral_domain D] [unique_factorization_monoid D] : unique_factorization_monoid (polynomial D) := Mathlib.ufm_of_gcd_of_wf_dvd_monoid
981c3c09be8864fcb0b7d056b76a1686bc03a618
367134ba5a65885e863bdc4507601606690974c1
/src/geometry/manifold/times_cont_mdiff.lean
2e9edabc88ad875f4726988e0e2bd2932a65a9c6
[ "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
79,989
lean
/- Copyright (c) 2020 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 geometry.manifold.mfderiv import geometry.manifold.local_invariant_properties /-! # Smooth functions between smooth manifolds We define `Cⁿ` functions between smooth manifolds, as functions which are `Cⁿ` in charts, and prove basic properties of these notions. ## Main definitions and statements Let `M ` and `M'` be two smooth manifolds, with respect to model with corners `I` and `I'`. Let `f : M → M'`. * `times_cont_mdiff_within_at I I' n f s x` states that the function `f` is `Cⁿ` within the set `s` around the point `x`. * `times_cont_mdiff_at I I' n f x` states that the function `f` is `Cⁿ` around `x`. * `times_cont_mdiff_on I I' n f s` states that the function `f` is `Cⁿ` on the set `s` * `times_cont_mdiff I I' n f` states that the function `f` is `Cⁿ`. * `times_cont_mdiff_on.comp` gives the invariance of the `Cⁿ` property under composition * `times_cont_mdiff_on.times_cont_mdiff_on_tangent_map_within` states that the bundled derivative of a `Cⁿ` function in a domain is `Cᵐ` when `m + 1 ≤ n`. * `times_cont_mdiff.times_cont_mdiff_tangent_map` states that the bundled derivative of a `Cⁿ` function is `Cᵐ` when `m + 1 ≤ n`. * `times_cont_mdiff_iff_times_cont_diff` states that, for functions between vector spaces, manifold-smoothness is equivalent to usual smoothness. We also give many basic properties of smooth functions between manifolds, following the API of smooth functions between vector spaces. ## Implementation details Many properties follow for free from the corresponding properties of functions in vector spaces, as being `Cⁿ` is a local property invariant under the smooth groupoid. We take advantage of the general machinery developed in `local_invariant_properties.lean` to get these properties automatically. For instance, the fact that being `Cⁿ` does not depend on the chart one considers is given by `lift_prop_within_at_indep_chart`. For this to work, the definition of `times_cont_mdiff_within_at` and friends has to follow definitionally the setup of local invariant properties. Still, we recast the definition in terms of extended charts in `times_cont_mdiff_on_iff` and `times_cont_mdiff_iff`. -/ open set filter charted_space smooth_manifold_with_corners open_locale topological_space manifold /-! ### Definition of smooth functions between manifolds -/ variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] -- declare a smooth manifold `M` over the pair `(E, H)`. {E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H) {M : Type*} [topological_space M] [charted_space H M] [Is : smooth_manifold_with_corners I M] -- declare a smooth manifold `M'` over the pair `(E', H')`. {E' : Type*} [normed_group E'] [normed_space 𝕜 E'] {H' : Type*} [topological_space H'] (I' : model_with_corners 𝕜 E' H') {M' : Type*} [topological_space M'] [charted_space H' M'] [I's : smooth_manifold_with_corners I' M'] -- declare a smooth manifold `N` over the pair `(F, G)`. {F : Type*} [normed_group F] [normed_space 𝕜 F] {G : Type*} [topological_space G] {J : model_with_corners 𝕜 F G} {N : Type*} [topological_space N] [charted_space G N] [Js : smooth_manifold_with_corners J N] -- declare a smooth manifold `N'` over the pair `(F', G')`. {F' : Type*} [normed_group F'] [normed_space 𝕜 F'] {G' : Type*} [topological_space G'] {J' : model_with_corners 𝕜 F' G'} {N' : Type*} [topological_space N'] [charted_space G' N'] [J's : smooth_manifold_with_corners J' N'] -- declare functions, sets, points and smoothness indices {f f₁ : M → M'} {s s₁ t : set M} {x : M} {m n : with_top ℕ} /-- Property in the model space of a model with corners of being `C^n` within at set at a point, when read in the model vector space. This property will be lifted to manifolds to define smooth functions between manifolds. -/ def times_cont_diff_within_at_prop (n : with_top ℕ) (f s x) : Prop := times_cont_diff_within_at 𝕜 n (I' ∘ f ∘ I.symm) (range I ∩ I.symm ⁻¹' s) (I x) /-- Being `Cⁿ` in the model space is a local property, invariant under smooth maps. Therefore, it will lift nicely to manifolds. -/ lemma times_cont_diff_within_at_local_invariant_prop (n : with_top ℕ) : (times_cont_diff_groupoid ∞ I).local_invariant_prop (times_cont_diff_groupoid ∞ I') (times_cont_diff_within_at_prop I I' n) := { is_local := begin assume s x u f u_open xu, have : range I ∩ I.symm ⁻¹' (s ∩ u) = (range I ∩ I.symm ⁻¹' s) ∩ I.symm ⁻¹' u, by simp only [inter_assoc, preimage_inter], rw [times_cont_diff_within_at_prop, times_cont_diff_within_at_prop, this], symmetry, apply times_cont_diff_within_at_inter, have : u ∈ 𝓝 (I.symm (I x)), by { rw [model_with_corners.left_inv], exact mem_nhds_sets u_open xu }, apply continuous_at.preimage_mem_nhds I.continuous_symm.continuous_at this, end, right_invariance := begin assume s x f e he hx h, rw times_cont_diff_within_at_prop at h ⊢, have : I x = (I ∘ e.symm ∘ I.symm) (I (e x)), by simp only [hx] with mfld_simps, rw this at h, have : I (e x) ∈ (I.symm) ⁻¹' e.target ∩ range ⇑I, by simp only [hx] with mfld_simps, have := ((mem_groupoid_of_pregroupoid.2 he).2.times_cont_diff_within_at this).of_le le_top, convert h.comp' _ this using 1, { ext y, simp only with mfld_simps }, { mfld_set_tac } end, congr := begin assume s x f g h hx hf, apply hf.congr, { assume y hy, simp only with mfld_simps at hy, simp only [h, hy] with mfld_simps }, { simp only [hx] with mfld_simps } end, left_invariance := begin assume s x f e' he' hs hx h, rw times_cont_diff_within_at_prop at h ⊢, have A : (I' ∘ f ∘ I.symm) (I x) ∈ (I'.symm ⁻¹' e'.source ∩ range I'), by simp only [hx] with mfld_simps, have := ((mem_groupoid_of_pregroupoid.2 he').1.times_cont_diff_within_at A).of_le le_top, convert this.comp _ h _, { ext y, simp only with mfld_simps }, { assume y hy, simp only with mfld_simps at hy, simpa only [hy] with mfld_simps using hs hy.2 } end } lemma times_cont_diff_within_at_local_invariant_prop_mono (n : with_top ℕ) ⦃s x t⦄ ⦃f : H → H'⦄ (hts : t ⊆ s) (h : times_cont_diff_within_at_prop I I' n f s x) : times_cont_diff_within_at_prop I I' n f t x := begin apply h.mono (λ y hy, _), simp only with mfld_simps at hy, simp only [hy, hts _] with mfld_simps end lemma times_cont_diff_within_at_local_invariant_prop_id (x : H) : times_cont_diff_within_at_prop I I ∞ id univ x := begin simp [times_cont_diff_within_at_prop], have : times_cont_diff_within_at 𝕜 ∞ id (range I) (I x) := times_cont_diff_id.times_cont_diff_at.times_cont_diff_within_at, apply this.congr (λ y hy, _), { simp only with mfld_simps }, { simp only [model_with_corners.right_inv I hy] with mfld_simps } end /-- A function is `n` times continuously differentiable within a set at a point in a manifold if it is continuous and it is `n` times continuously differentiable in this set around this point, when read in the preferred chart at this point. -/ def times_cont_mdiff_within_at (n : with_top ℕ) (f : M → M') (s : set M) (x : M) := lift_prop_within_at (times_cont_diff_within_at_prop I I' n) f s x /-- Abbreviation for `times_cont_mdiff_within_at I I' ⊤ f s x`. See also documentation for `smooth`. -/ @[reducible] def smooth_within_at (f : M → M') (s : set M) (x : M) := times_cont_mdiff_within_at I I' ⊤ f s x /-- A function is `n` times continuously differentiable at a point in a manifold if it is continuous and it is `n` times continuously differentiable around this point, when read in the preferred chart at this point. -/ def times_cont_mdiff_at (n : with_top ℕ) (f : M → M') (x : M) := times_cont_mdiff_within_at I I' n f univ x /-- Abbreviation for `times_cont_mdiff_at I I' ⊤ f x`. See also documentation for `smooth`. -/ @[reducible] def smooth_at (f : M → M') (x : M) := times_cont_mdiff_at I I' ⊤ f x /-- A function is `n` times continuously differentiable in a set of a manifold if it is continuous and, for any pair of points, it is `n` times continuously differentiable on this set in the charts around these points. -/ def times_cont_mdiff_on (n : with_top ℕ) (f : M → M') (s : set M) := ∀ x ∈ s, times_cont_mdiff_within_at I I' n f s x /-- Abbreviation for `times_cont_mdiff_on I I' ⊤ f s`. See also documentation for `smooth`. -/ @[reducible] def smooth_on (f : M → M') (s : set M) := times_cont_mdiff_on I I' ⊤ f s /-- A function is `n` times continuously differentiable in a manifold if it is continuous and, for any pair of points, it is `n` times continuously differentiable in the charts around these points. -/ def times_cont_mdiff (n : with_top ℕ) (f : M → M') := ∀ x, times_cont_mdiff_at I I' n f x /-- Abbreviation for `times_cont_mdiff I I' ⊤ f`. Short note to work with these abbreviations: a lemma of the form `times_cont_mdiff_foo.bar` will apply fine to an assumption `smooth_foo` using dot notation or normal notation. If the consequence `bar` of the lemma involves `times_cont_diff`, it is still better to restate the lemma replacing `times_cont_diff` with `smooth` both in the assumption and in the conclusion, to make it possible to use `smooth` consistently. This also applies to `smooth_at`, `smooth_on` and `smooth_within_at`.-/ @[reducible] def smooth (f : M → M') := times_cont_mdiff I I' ⊤ f /-! ### Basic properties of smooth functions between manifolds -/ variables {I I'} lemma times_cont_mdiff.smooth (h : times_cont_mdiff I I' ⊤ f) : smooth I I' f := h lemma smooth.times_cont_mdiff (h : smooth I I' f) : times_cont_mdiff I I' ⊤ f := h lemma times_cont_mdiff_on.smooth_on (h : times_cont_mdiff_on I I' ⊤ f s) : smooth_on I I' f s := h lemma smooth_on.times_cont_mdiff_on (h : smooth_on I I' f s) : times_cont_mdiff_on I I' ⊤ f s := h lemma times_cont_mdiff_at.smooth_at (h : times_cont_mdiff_at I I' ⊤ f x) : smooth_at I I' f x := h lemma smooth_at.times_cont_mdiff_at (h : smooth_at I I' f x) : times_cont_mdiff_at I I' ⊤ f x := h lemma times_cont_mdiff_within_at.smooth_within_at (h : times_cont_mdiff_within_at I I' ⊤ f s x) : smooth_within_at I I' f s x := h lemma smooth_within_at.times_cont_mdiff_within_at (h : smooth_within_at I I' f s x) : times_cont_mdiff_within_at I I' ⊤ f s x := h lemma times_cont_mdiff.times_cont_mdiff_at (h : times_cont_mdiff I I' n f) : times_cont_mdiff_at I I' n f x := h x lemma smooth.smooth_at (h : smooth I I' f) : smooth_at I I' f x := times_cont_mdiff.times_cont_mdiff_at h lemma times_cont_mdiff_within_at_univ : times_cont_mdiff_within_at I I' n f univ x ↔ times_cont_mdiff_at I I' n f x := iff.rfl lemma smooth_at_univ : smooth_within_at I I' f univ x ↔ smooth_at I I' f x := times_cont_mdiff_within_at_univ lemma times_cont_mdiff_on_univ : times_cont_mdiff_on I I' n f univ ↔ times_cont_mdiff I I' n f := by simp only [times_cont_mdiff_on, times_cont_mdiff, times_cont_mdiff_within_at_univ, forall_prop_of_true, mem_univ] lemma smooth_on_univ : smooth_on I I' f univ ↔ smooth I I' f := times_cont_mdiff_on_univ /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart. -/ lemma times_cont_mdiff_within_at_iff : times_cont_mdiff_within_at I I' n f s x ↔ continuous_within_at f s x ∧ times_cont_diff_within_at 𝕜 n ((ext_chart_at I' (f x)) ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' (f x)).source)) (ext_chart_at I x x) := begin rw [times_cont_mdiff_within_at, lift_prop_within_at, times_cont_diff_within_at_prop], congr' 3, mfld_set_tac end /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart. This form states smoothness of `f` written in the `ext_chart_at`s within the set `(ext_chart_at I x).symm ⁻¹' s ∩ range I`. This set is larger than the set `(ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' (f x)).source)` used in `times_cont_mdiff_within_at_iff` but their germs at `ext_chart_at I x x` are equal. It may be useful to rewrite using `times_cont_mdiff_within_at_iff''` in the *assumptions* of a lemma and using `times_cont_mdiff_within_at_iff` in the goal. -/ lemma times_cont_mdiff_within_at_iff'' : times_cont_mdiff_within_at I I' n f s x ↔ continuous_within_at f s x ∧ times_cont_diff_within_at 𝕜 n (written_in_ext_chart_at I I' x f) ((ext_chart_at I x).symm ⁻¹' s ∩ range I) (ext_chart_at I x x) := begin rw [times_cont_mdiff_within_at_iff, and.congr_right_iff], set e := ext_chart_at I x, set e' := ext_chart_at I' (f x), refine λ hc, times_cont_diff_within_at_congr_nhds _, rw [← e.image_source_inter_eq', ← ext_chart_at_map_nhds_within_eq_image, ← ext_chart_at_map_nhds_within, inter_comm, nhds_within_inter_of_mem], exact hc (ext_chart_at_source_mem_nhds _ _) end /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart in the target. -/ lemma times_cont_mdiff_within_at_iff_target : times_cont_mdiff_within_at I I' n f s x ↔ continuous_within_at f s x ∧ times_cont_mdiff_within_at I 𝓘(𝕜, E') n ((ext_chart_at I' (f x)) ∘ f) (s ∩ f ⁻¹' (ext_chart_at I' (f x)).source) x := begin rw [times_cont_mdiff_within_at, times_cont_mdiff_within_at, lift_prop_within_at, lift_prop_within_at, ← and_assoc], have cont : (continuous_within_at f s x ∧ continuous_within_at ((I' ∘ (chart_at H' (f x))) ∘ f) (s ∩ f ⁻¹' (chart_at H' (f x)).to_local_equiv.source) x) ↔ continuous_within_at f s x, { refine ⟨λ h, h.1, λ h, ⟨h, _⟩⟩, have h₁ : continuous_within_at _ univ ((chart_at H' (f x)) (f x)), { exact (model_with_corners.continuous I').continuous_within_at }, have h₂ := (chart_at H' (f x)).continuous_to_fun.continuous_within_at (mem_chart_source _ _), convert (h₁.comp' h₂).comp' h, simp }, simp [cont, times_cont_diff_within_at_prop] end lemma smooth_within_at_iff : smooth_within_at I I' f s x ↔ continuous_within_at f s x ∧ times_cont_diff_within_at 𝕜 ∞ ((ext_chart_at I' (f x)) ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' (f x)).source)) (ext_chart_at I x x) := times_cont_mdiff_within_at_iff lemma smooth_within_at_iff_target : smooth_within_at I I' f s x ↔ continuous_within_at f s x ∧ smooth_within_at I 𝓘(𝕜, E') ((ext_chart_at I' (f x)) ∘ f) (s ∩ f ⁻¹' (ext_chart_at I' (f x)).source) x := times_cont_mdiff_within_at_iff_target lemma times_cont_mdiff_at_ext_chart_at : times_cont_mdiff_at I 𝓘(𝕜, E) n (ext_chart_at I x) x := begin rw [times_cont_mdiff_at, times_cont_mdiff_within_at_iff], refine ⟨(ext_chart_at_continuous_at _ _).continuous_within_at, _⟩, refine times_cont_diff_within_at_id.congr _ _; simp only with mfld_simps { contextual := tt } end include Is I's /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart. -/ lemma times_cont_mdiff_within_at_iff' {x' : M} {y : M'} (hx : x' ∈ (chart_at H x).source) (hy : f x' ∈ (chart_at H' y).source) : times_cont_mdiff_within_at I I' n f s x' ↔ continuous_within_at f s x' ∧ times_cont_diff_within_at 𝕜 n ((ext_chart_at I' y) ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' y).source)) (ext_chart_at I x x') := begin refine ((times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_indep_chart (structure_groupoid.chart_mem_maximal_atlas _ x) hx (structure_groupoid.chart_mem_maximal_atlas _ y) hy).trans _, rw [times_cont_diff_within_at_prop, iff_eq_eq], congr' 2, mfld_set_tac end omit I's lemma times_cont_mdiff_at_ext_chart_at' {x' : M} (h : x' ∈ (chart_at H x).source) : times_cont_mdiff_at I 𝓘(𝕜, E) n (ext_chart_at I x) x' := begin refine (times_cont_mdiff_within_at_iff' h (mem_chart_source _ _)).2 _, refine ⟨(ext_chart_at_continuous_at' _ _ _).continuous_within_at, _⟩, { rwa ext_chart_at_source }, refine times_cont_diff_within_at_id.congr' _ _; simp only [h] with mfld_simps { contextual := tt } end include I's /-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any extended chart. -/ lemma times_cont_mdiff_on_iff : times_cont_mdiff_on I I' n f s ↔ continuous_on f s ∧ ∀ (x : M) (y : M'), times_cont_diff_on 𝕜 n ((ext_chart_at I' y) ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' y).source)) := begin split, { assume h, refine ⟨λ x hx, (h x hx).1, λ x y z hz, _⟩, simp only with mfld_simps at hz, let w := (ext_chart_at I x).symm z, have : w ∈ s, by simp only [w, hz] with mfld_simps, specialize h w this, have w1 : w ∈ (chart_at H x).source, by simp only [w, hz] with mfld_simps, have w2 : f w ∈ (chart_at H' y).source, by simp only [w, hz] with mfld_simps, convert (((times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_indep_chart (structure_groupoid.chart_mem_maximal_atlas _ x) w1 (structure_groupoid.chart_mem_maximal_atlas _ y) w2).1 h).2 using 1, { mfld_set_tac }, { simp only [w, hz] with mfld_simps } }, { rintros ⟨hcont, hdiff⟩ x hx, refine ⟨hcont x hx, _⟩, have Z := hdiff x (f x) (ext_chart_at I x x) (by simp only [hx] with mfld_simps), dsimp [times_cont_diff_within_at_prop], convert Z using 1, mfld_set_tac } end /-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any extended chart in the target. -/ lemma times_cont_mdiff_on_iff_target : times_cont_mdiff_on I I' n f s ↔ continuous_on f s ∧ ∀ (y : M'), times_cont_mdiff_on I 𝓘(𝕜, E') n ((ext_chart_at I' y) ∘ f) (s ∩ f ⁻¹' (ext_chart_at I' y).source) := begin inhabit E', simp only [times_cont_mdiff_on_iff, model_with_corners.source_eq, chart_at_self_eq, local_homeomorph.refl_local_equiv, local_equiv.refl_trans, ext_chart_at.equations._eqn_1, set.preimage_univ, set.inter_univ, and.congr_right_iff], intros h, split, { refine λ h' y, ⟨_, λ x _, h' x y⟩, have h'' : continuous_on _ univ := (model_with_corners.continuous I').continuous_on, convert (h''.comp' (chart_at H' y).continuous_to_fun).comp' h, simp }, { exact λ h' x y, (h' y).2 x (default E') } end lemma smooth_on_iff : smooth_on I I' f s ↔ continuous_on f s ∧ ∀ (x : M) (y : M'), times_cont_diff_on 𝕜 ⊤ ((ext_chart_at I' y) ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' y).source)) := times_cont_mdiff_on_iff lemma smooth_on_iff_target : smooth_on I I' f s ↔ continuous_on f s ∧ ∀ (y : M'), smooth_on I 𝓘(𝕜, E') ((ext_chart_at I' y) ∘ f) (s ∩ f ⁻¹' (ext_chart_at I' y).source) := times_cont_mdiff_on_iff_target /-- One can reformulate smoothness as continuity and smoothness in any extended chart. -/ lemma times_cont_mdiff_iff : times_cont_mdiff I I' n f ↔ continuous f ∧ ∀ (x : M) (y : M'), times_cont_diff_on 𝕜 n ((ext_chart_at I' y) ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (f ⁻¹' (ext_chart_at I' y).source)) := by simp [← times_cont_mdiff_on_univ, times_cont_mdiff_on_iff, continuous_iff_continuous_on_univ] /-- One can reformulate smoothness as continuity and smoothness in any extended chart in the target. -/ lemma times_cont_mdiff_iff_target : times_cont_mdiff I I' n f ↔ continuous f ∧ ∀ (y : M'), times_cont_mdiff_on I 𝓘(𝕜, E') n ((ext_chart_at I' y) ∘ f) (f ⁻¹' (ext_chart_at I' y).source) := begin rw [← times_cont_mdiff_on_univ, times_cont_mdiff_on_iff_target], simp [continuous_iff_continuous_on_univ] end lemma smooth_iff : smooth I I' f ↔ continuous f ∧ ∀ (x : M) (y : M'), times_cont_diff_on 𝕜 ⊤ ((ext_chart_at I' y) ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (f ⁻¹' (ext_chart_at I' y).source)) := times_cont_mdiff_iff lemma smooth_iff_target : smooth I I' f ↔ continuous f ∧ ∀ (y : M'), smooth_on I 𝓘(𝕜, E') ((ext_chart_at I' y) ∘ f) (f ⁻¹' (ext_chart_at I' y).source) := times_cont_mdiff_iff_target omit Is I's /-! ### Deducing smoothness from higher smoothness -/ lemma times_cont_mdiff_within_at.of_le (hf : times_cont_mdiff_within_at I I' n f s x) (le : m ≤ n) : times_cont_mdiff_within_at I I' m f s x := ⟨hf.1, hf.2.of_le le⟩ lemma times_cont_mdiff_at.of_le (hf : times_cont_mdiff_at I I' n f x) (le : m ≤ n) : times_cont_mdiff_at I I' m f x := times_cont_mdiff_within_at.of_le hf le lemma times_cont_mdiff_on.of_le (hf : times_cont_mdiff_on I I' n f s) (le : m ≤ n) : times_cont_mdiff_on I I' m f s := λ x hx, (hf x hx).of_le le lemma times_cont_mdiff.of_le (hf : times_cont_mdiff I I' n f) (le : m ≤ n) : times_cont_mdiff I I' m f := λ x, (hf x).of_le le /-! ### Deducing smoothness from smoothness one step beyond -/ lemma times_cont_mdiff_within_at.of_succ {n : ℕ} (h : times_cont_mdiff_within_at I I' n.succ f s x) : times_cont_mdiff_within_at I I' n f s x := h.of_le (with_top.coe_le_coe.2 (nat.le_succ n)) lemma times_cont_mdiff_at.of_succ {n : ℕ} (h : times_cont_mdiff_at I I' n.succ f x) : times_cont_mdiff_at I I' n f x := times_cont_mdiff_within_at.of_succ h lemma times_cont_mdiff_on.of_succ {n : ℕ} (h : times_cont_mdiff_on I I' n.succ f s) : times_cont_mdiff_on I I' n f s := λ x hx, (h x hx).of_succ lemma times_cont_mdiff.of_succ {n : ℕ} (h : times_cont_mdiff I I' n.succ f) : times_cont_mdiff I I' n f := λ x, (h x).of_succ /-! ### Deducing continuity from smoothness-/ lemma times_cont_mdiff_within_at.continuous_within_at (hf : times_cont_mdiff_within_at I I' n f s x) : continuous_within_at f s x := hf.1 lemma times_cont_mdiff_at.continuous_at (hf : times_cont_mdiff_at I I' n f x) : continuous_at f x := (continuous_within_at_univ _ _ ).1 $ times_cont_mdiff_within_at.continuous_within_at hf lemma times_cont_mdiff_on.continuous_on (hf : times_cont_mdiff_on I I' n f s) : continuous_on f s := λ x hx, (hf x hx).continuous_within_at lemma times_cont_mdiff.continuous (hf : times_cont_mdiff I I' n f) : continuous f := continuous_iff_continuous_at.2 $ λ x, (hf x).continuous_at /-! ### Deducing differentiability from smoothness -/ lemma times_cont_mdiff_within_at.mdifferentiable_within_at (hf : times_cont_mdiff_within_at I I' n f s x) (hn : 1 ≤ n) : mdifferentiable_within_at I I' f s x := begin suffices h : mdifferentiable_within_at I I' f (s ∩ (f ⁻¹' (ext_chart_at I' (f x)).source)) x, { rwa mdifferentiable_within_at_inter' at h, apply (hf.1).preimage_mem_nhds_within, exact mem_nhds_sets (ext_chart_at_open_source I' (f x)) (mem_ext_chart_source I' (f x)) }, rw mdifferentiable_within_at_iff, exact ⟨hf.1.mono (inter_subset_left _ _), (hf.2.differentiable_within_at hn).mono (by mfld_set_tac)⟩, end lemma times_cont_mdiff_at.mdifferentiable_at (hf : times_cont_mdiff_at I I' n f x) (hn : 1 ≤ n) : mdifferentiable_at I I' f x := mdifferentiable_within_at_univ.1 $ times_cont_mdiff_within_at.mdifferentiable_within_at hf hn lemma times_cont_mdiff_on.mdifferentiable_on (hf : times_cont_mdiff_on I I' n f s) (hn : 1 ≤ n) : mdifferentiable_on I I' f s := λ x hx, (hf x hx).mdifferentiable_within_at hn lemma times_cont_mdiff.mdifferentiable (hf : times_cont_mdiff I I' n f) (hn : 1 ≤ n) : mdifferentiable I I' f := λ x, (hf x).mdifferentiable_at hn lemma smooth.mdifferentiable (hf : smooth I I' f) : mdifferentiable I I' f := times_cont_mdiff.mdifferentiable hf le_top lemma smooth.mdifferentiable_at (hf : smooth I I' f) : mdifferentiable_at I I' f x := hf.mdifferentiable x lemma smooth.mdifferentiable_within_at (hf : smooth I I' f) : mdifferentiable_within_at I I' f s x := hf.mdifferentiable_at.mdifferentiable_within_at /-! ### `C^∞` smoothness -/ lemma times_cont_mdiff_within_at_top : smooth_within_at I I' f s x ↔ (∀n:ℕ, times_cont_mdiff_within_at I I' n f s x) := ⟨λ h n, ⟨h.1, times_cont_diff_within_at_top.1 h.2 n⟩, λ H, ⟨(H 0).1, times_cont_diff_within_at_top.2 (λ n, (H n).2)⟩⟩ lemma times_cont_mdiff_at_top : smooth_at I I' f x ↔ (∀n:ℕ, times_cont_mdiff_at I I' n f x) := times_cont_mdiff_within_at_top lemma times_cont_mdiff_on_top : smooth_on I I' f s ↔ (∀n:ℕ, times_cont_mdiff_on I I' n f s) := ⟨λ h n, h.of_le le_top, λ h x hx, times_cont_mdiff_within_at_top.2 (λ n, h n x hx)⟩ lemma times_cont_mdiff_top : smooth I I' f ↔ (∀n:ℕ, times_cont_mdiff I I' n f) := ⟨λ h n, h.of_le le_top, λ h x, times_cont_mdiff_within_at_top.2 (λ n, h n x)⟩ lemma times_cont_mdiff_within_at_iff_nat : times_cont_mdiff_within_at I I' n f s x ↔ (∀m:ℕ, (m : with_top ℕ) ≤ n → times_cont_mdiff_within_at I I' m f s x) := begin refine ⟨λ h m hm, h.of_le hm, λ h, _⟩, cases n, { exact times_cont_mdiff_within_at_top.2 (λ n, h n le_top) }, { exact h n (le_refl _) } end /-! ### Restriction to a smaller set -/ lemma times_cont_mdiff_within_at.mono (hf : times_cont_mdiff_within_at I I' n f s x) (hts : t ⊆ s) : times_cont_mdiff_within_at I I' n f t x := structure_groupoid.local_invariant_prop.lift_prop_within_at_mono (times_cont_diff_within_at_local_invariant_prop_mono I I' n) hf hts lemma times_cont_mdiff_at.times_cont_mdiff_within_at (hf : times_cont_mdiff_at I I' n f x) : times_cont_mdiff_within_at I I' n f s x := times_cont_mdiff_within_at.mono hf (subset_univ _) lemma smooth_at.smooth_within_at (hf : smooth_at I I' f x) : smooth_within_at I I' f s x := times_cont_mdiff_at.times_cont_mdiff_within_at hf lemma times_cont_mdiff_on.mono (hf : times_cont_mdiff_on I I' n f s) (hts : t ⊆ s) : times_cont_mdiff_on I I' n f t := λ x hx, (hf x (hts hx)).mono hts lemma times_cont_mdiff.times_cont_mdiff_on (hf : times_cont_mdiff I I' n f) : times_cont_mdiff_on I I' n f s := λ x hx, (hf x).times_cont_mdiff_within_at lemma smooth.smooth_on (hf : smooth I I' f) : smooth_on I I' f s := times_cont_mdiff.times_cont_mdiff_on hf lemma times_cont_mdiff_within_at_inter' (ht : t ∈ 𝓝[s] x) : times_cont_mdiff_within_at I I' n f (s ∩ t) x ↔ times_cont_mdiff_within_at I I' n f s x := (times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_inter' ht lemma times_cont_mdiff_within_at_inter (ht : t ∈ 𝓝 x) : times_cont_mdiff_within_at I I' n f (s ∩ t) x ↔ times_cont_mdiff_within_at I I' n f s x := (times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_inter ht lemma times_cont_mdiff_within_at.times_cont_mdiff_at (h : times_cont_mdiff_within_at I I' n f s x) (ht : s ∈ 𝓝 x) : times_cont_mdiff_at I I' n f x := (times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_at_of_lift_prop_within_at h ht lemma smooth_within_at.smooth_at (h : smooth_within_at I I' f s x) (ht : s ∈ 𝓝 x) : smooth_at I I' f x := times_cont_mdiff_within_at.times_cont_mdiff_at h ht include Is I's /-- A function is `C^n` within a set at a point, for `n : ℕ`, if and only if it is `C^n` on a neighborhood of this point. -/ lemma times_cont_mdiff_within_at_iff_times_cont_mdiff_on_nhds {n : ℕ} : times_cont_mdiff_within_at I I' n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, times_cont_mdiff_on I I' n f u := begin split, { assume h, -- the property is true in charts. We will pull such a good neighborhood in the chart to the -- manifold. For this, we need to restrict to a small enough set where everything makes sense obtain ⟨o, o_open, xo, ho, h'o⟩ : ∃ (o : set M), is_open o ∧ x ∈ o ∧ o ⊆ (chart_at H x).source ∧ o ∩ s ⊆ f ⁻¹' (chart_at H' (f x)).source, { have : (chart_at H' (f x)).source ∈ 𝓝 (f x) := mem_nhds_sets (local_homeomorph.open_source _) (mem_chart_source H' (f x)), rcases mem_nhds_within.1 (h.1.preimage_mem_nhds_within this) with ⟨u, u_open, xu, hu⟩, refine ⟨u ∩ (chart_at H x).source, _, ⟨xu, mem_chart_source _ _⟩, _, _⟩, { exact is_open_inter u_open (local_homeomorph.open_source _) }, { assume y hy, exact hy.2 }, { assume y hy, exact hu ⟨hy.1.1, hy.2⟩ } }, have h' : times_cont_mdiff_within_at I I' n f (s ∩ o) x := h.mono (inter_subset_left _ _), simp only [times_cont_mdiff_within_at, lift_prop_within_at, times_cont_diff_within_at_prop] at h', -- let `u` be a good neighborhood in the chart where the function is smooth rcases h.2.times_cont_diff_on (le_refl _) with ⟨u, u_nhds, u_subset, hu⟩, -- pull it back to the manifold, and intersect with a suitable neighborhood of `x`, to get the -- desired good neighborhood `v`. let v := ((insert x s) ∩ o) ∩ (ext_chart_at I x) ⁻¹' u, have v_incl : v ⊆ (chart_at H x).source := λ y hy, ho hy.1.2, have v_incl' : ∀ y ∈ v, f y ∈ (chart_at H' (f x)).source, { assume y hy, rcases hy.1.1 with rfl|h', { simp only with mfld_simps }, { apply h'o ⟨hy.1.2, h'⟩ } }, refine ⟨v, _, _⟩, show v ∈ 𝓝[insert x s] x, { rw nhds_within_restrict _ xo o_open, refine filter.inter_mem_sets self_mem_nhds_within _, suffices : u ∈ 𝓝[(ext_chart_at I x) '' (insert x s ∩ o)] (ext_chart_at I x x), from (ext_chart_at_continuous_at I x).continuous_within_at.preimage_mem_nhds_within' this, apply nhds_within_mono _ _ u_nhds, rw image_subset_iff, assume y hy, rcases hy.1 with rfl|h', { simp only [mem_insert_iff] with mfld_simps }, { simp only [mem_insert_iff, ho hy.2, h', h'o ⟨hy.2, h'⟩] with mfld_simps } }, show times_cont_mdiff_on I I' n f v, { assume y hy, apply (((times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_indep_chart (structure_groupoid.chart_mem_maximal_atlas _ x) (v_incl hy) (structure_groupoid.chart_mem_maximal_atlas _ (f x)) (v_incl' y hy))).2, split, { apply (((ext_chart_at_continuous_on_symm I' (f x) _ _).comp' (hu _ hy.2).continuous_within_at).comp' (ext_chart_at_continuous_on I x _ _)).congr_mono, { assume z hz, simp only [v_incl hz, v_incl' z hz] with mfld_simps }, { assume z hz, simp only [v_incl hz, v_incl' z hz] with mfld_simps, exact hz.2 }, { simp only [v_incl hy, v_incl' y hy] with mfld_simps }, { simp only [v_incl hy, v_incl' y hy] with mfld_simps }, { simp only [v_incl hy] with mfld_simps } }, { apply hu.mono, { assume z hz, simp only [v] with mfld_simps at hz, have : I ((chart_at H x) (((chart_at H x).symm) (I.symm z))) ∈ u, by simp only [hz], simpa only [hz] with mfld_simps using this }, { have exty : I (chart_at H x y) ∈ u := hy.2, simp only [v_incl hy, v_incl' y hy, exty, hy.1.1, hy.1.2] with mfld_simps } } } }, { rintros ⟨u, u_nhds, hu⟩, have : times_cont_mdiff_within_at I I' ↑n f (insert x s ∩ u) x, { have : x ∈ insert x s := mem_insert x s, exact hu.mono (inter_subset_right _ _) _ ⟨this, mem_of_mem_nhds_within this u_nhds⟩ }, rw times_cont_mdiff_within_at_inter' u_nhds at this, exact this.mono (subset_insert x s) } end /-- A function is `C^n` at a point, for `n : ℕ`, if and only if it is `C^n` on a neighborhood of this point. -/ lemma times_cont_mdiff_at_iff_times_cont_mdiff_on_nhds {n : ℕ} : times_cont_mdiff_at I I' n f x ↔ ∃ u ∈ 𝓝 x, times_cont_mdiff_on I I' n f u := by simp [← times_cont_mdiff_within_at_univ, times_cont_mdiff_within_at_iff_times_cont_mdiff_on_nhds, nhds_within_univ] omit Is I's /-! ### Congruence lemmas -/ lemma times_cont_mdiff_within_at.congr (h : times_cont_mdiff_within_at I I' n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : times_cont_mdiff_within_at I I' n f₁ s x := (times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_congr h h₁ hx lemma times_cont_mdiff_within_at_congr (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : times_cont_mdiff_within_at I I' n f₁ s x ↔ times_cont_mdiff_within_at I I' n f s x := (times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_congr_iff h₁ hx lemma times_cont_mdiff_within_at.congr_of_eventually_eq (h : times_cont_mdiff_within_at I I' n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : times_cont_mdiff_within_at I I' n f₁ s x := (times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_congr_of_eventually_eq h h₁ hx lemma filter.eventually_eq.times_cont_mdiff_within_at_iff (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : times_cont_mdiff_within_at I I' n f₁ s x ↔ times_cont_mdiff_within_at I I' n f s x := (times_cont_diff_within_at_local_invariant_prop I I' n) .lift_prop_within_at_congr_iff_of_eventually_eq h₁ hx lemma times_cont_mdiff_at.congr_of_eventually_eq (h : times_cont_mdiff_at I I' n f x) (h₁ : f₁ =ᶠ[𝓝 x] f) : times_cont_mdiff_at I I' n f₁ x := (times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_at_congr_of_eventually_eq h h₁ lemma filter.eventually_eq.times_cont_mdiff_at_iff (h₁ : f₁ =ᶠ[𝓝 x] f) : times_cont_mdiff_at I I' n f₁ x ↔ times_cont_mdiff_at I I' n f x := (times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_at_congr_iff_of_eventually_eq h₁ lemma times_cont_mdiff_on.congr (h : times_cont_mdiff_on I I' n f s) (h₁ : ∀ y ∈ s, f₁ y = f y) : times_cont_mdiff_on I I' n f₁ s := (times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_on_congr h h₁ lemma times_cont_mdiff_on_congr (h₁ : ∀ y ∈ s, f₁ y = f y) : times_cont_mdiff_on I I' n f₁ s ↔ times_cont_mdiff_on I I' n f s := (times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_on_congr_iff h₁ /-! ### Locality -/ /-- Being `C^n` is a local property. -/ lemma times_cont_mdiff_on_of_locally_times_cont_mdiff_on (h : ∀x∈s, ∃u, is_open u ∧ x ∈ u ∧ times_cont_mdiff_on I I' n f (s ∩ u)) : times_cont_mdiff_on I I' n f s := (times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_on_of_locally_lift_prop_on h lemma times_cont_mdiff_of_locally_times_cont_mdiff_on (h : ∀x, ∃u, is_open u ∧ x ∈ u ∧ times_cont_mdiff_on I I' n f u) : times_cont_mdiff I I' n f := (times_cont_diff_within_at_local_invariant_prop I I' n).lift_prop_of_locally_lift_prop_on h /-! ### Smoothness of the composition of smooth functions between manifolds -/ section composition variables {E'' : Type*} [normed_group E''] [normed_space 𝕜 E''] {H'' : Type*} [topological_space H''] {I'' : model_with_corners 𝕜 E'' H''} {M'' : Type*} [topological_space M''] [charted_space H'' M''] /-- The composition of `C^n` functions within domains at points is `C^n`. -/ lemma times_cont_mdiff_within_at.comp {t : set M'} {g : M' → M''} (x : M) (hg : times_cont_mdiff_within_at I' I'' n g t (f x)) (hf : times_cont_mdiff_within_at I I' n f s x) (st : maps_to f s t) : times_cont_mdiff_within_at I I'' n (g ∘ f) s x := begin rw times_cont_mdiff_within_at_iff'' at hg hf ⊢, refine ⟨hg.1.comp hf.1 st, _⟩, set e := ext_chart_at I x, set e' := ext_chart_at I' (f x), set e'' := ext_chart_at I'' (g (f x)), have : e' (f x) = (written_in_ext_chart_at I I' x f) (e x), by simp only [e, e'] with mfld_simps, rw this at hg, have A : {y | y ∈ e.target ∧ f (e.symm y) ∈ t ∧ f (e.symm y) ∈ e'.source ∧ g (f (e.symm y)) ∈ e''.source} ∈ 𝓝[e.symm ⁻¹' s ∩ range I] e x, { simp only [← ext_chart_at_map_nhds_within, mem_map, mem_preimage], filter_upwards [hf.1.tendsto (ext_chart_at_source_mem_nhds I' (f x)), (hg.1.comp hf.1 st).tendsto (ext_chart_at_source_mem_nhds I'' (g (f x))), (inter_mem_nhds_within s (ext_chart_at_source_mem_nhds I x))], rintros x' (hfx' : f x' ∈ _) (hgfx' : g (f x') ∈ _) ⟨hx's, hx'⟩, simp only [e.map_source hx', mem_preimage, true_and, e.left_inv hx', st hx's, *] }, refine ((hg.2.comp _ (hf.2.mono (inter_subset_right _ _)) (inter_subset_left _ _)).mono_of_mem (inter_mem_sets _ self_mem_nhds_within)).congr_of_eventually_eq _ _, { filter_upwards [A], rintro x' ⟨hx', ht, hfx', hgfx'⟩, simp only [*, mem_preimage, written_in_ext_chart_at, (∘), mem_inter_eq, e'.left_inv, true_and], exact mem_range_self _ }, { filter_upwards [A], rintro x' ⟨hx', ht, hfx', hgfx'⟩, simp only [*, (∘), written_in_ext_chart_at, e'.left_inv] }, { simp only [written_in_ext_chart_at, (∘), mem_ext_chart_source, e.left_inv, e'.left_inv] } end /-- The composition of `C^n` functions on domains is `C^n`. -/ lemma times_cont_mdiff_on.comp {t : set M'} {g : M' → M''} (hg : times_cont_mdiff_on I' I'' n g t) (hf : times_cont_mdiff_on I I' n f s) (st : s ⊆ f ⁻¹' t) : times_cont_mdiff_on I I'' n (g ∘ f) s := λ x hx, (hg _ (st hx)).comp x (hf x hx) st /-- The composition of `C^n` functions on domains is `C^n`. -/ lemma times_cont_mdiff_on.comp' {t : set M'} {g : M' → M''} (hg : times_cont_mdiff_on I' I'' n g t) (hf : times_cont_mdiff_on I I' n f s) : times_cont_mdiff_on I I'' n (g ∘ f) (s ∩ f ⁻¹' t) := hg.comp (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _) /-- The composition of `C^n` functions is `C^n`. -/ lemma times_cont_mdiff.comp {g : M' → M''} (hg : times_cont_mdiff I' I'' n g) (hf : times_cont_mdiff I I' n f) : times_cont_mdiff I I'' n (g ∘ f) := begin rw ← times_cont_mdiff_on_univ at hf hg ⊢, exact hg.comp hf subset_preimage_univ, end /-- The composition of `C^n` functions within domains at points is `C^n`. -/ lemma times_cont_mdiff_within_at.comp' {t : set M'} {g : M' → M''} (x : M) (hg : times_cont_mdiff_within_at I' I'' n g t (f x)) (hf : times_cont_mdiff_within_at I I' n f s x) : times_cont_mdiff_within_at I I'' n (g ∘ f) (s ∩ f⁻¹' t) x := hg.comp x (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _) /-- The composition of `C^n` functions at points is `C^n`. -/ lemma times_cont_mdiff_at.comp {g : M' → M''} (x : M) (hg : times_cont_mdiff_at I' I'' n g (f x)) (hf : times_cont_mdiff_at I I' n f x) : times_cont_mdiff_at I I'' n (g ∘ f) x := hg.comp x hf (maps_to_univ _ _) lemma times_cont_mdiff.comp_times_cont_mdiff_on {f : M → M'} {g : M' → M''} {s : set M} (hg : times_cont_mdiff I' I'' n g) (hf : times_cont_mdiff_on I I' n f s) : times_cont_mdiff_on I I'' n (g ∘ f) s := hg.times_cont_mdiff_on.comp hf set.subset_preimage_univ lemma smooth.comp_smooth_on {f : M → M'} {g : M' → M''} {s : set M} (hg : smooth I' I'' g) (hf : smooth_on I I' f s) : smooth_on I I'' (g ∘ f) s := hg.smooth_on.comp hf set.subset_preimage_univ end composition /-! ### Atlas members are smooth -/ section atlas variables {e : local_homeomorph M H} include Is /-- An atlas member is `C^n` for any `n`. -/ lemma times_cont_mdiff_on_of_mem_maximal_atlas (h : e ∈ maximal_atlas I M) : times_cont_mdiff_on I I n e e.source := times_cont_mdiff_on.of_le ((times_cont_diff_within_at_local_invariant_prop I I ∞).lift_prop_on_of_mem_maximal_atlas (times_cont_diff_within_at_local_invariant_prop_id I) h) le_top /-- The inverse of an atlas member is `C^n` for any `n`. -/ lemma times_cont_mdiff_on_symm_of_mem_maximal_atlas (h : e ∈ maximal_atlas I M) : times_cont_mdiff_on I I n e.symm e.target := times_cont_mdiff_on.of_le ((times_cont_diff_within_at_local_invariant_prop I I ∞).lift_prop_on_symm_of_mem_maximal_atlas (times_cont_diff_within_at_local_invariant_prop_id I) h) le_top lemma times_cont_mdiff_on_chart : times_cont_mdiff_on I I n (chart_at H x) (chart_at H x).source := times_cont_mdiff_on_of_mem_maximal_atlas ((times_cont_diff_groupoid ⊤ I).chart_mem_maximal_atlas x) lemma times_cont_mdiff_on_chart_symm : times_cont_mdiff_on I I n (chart_at H x).symm (chart_at H x).target := times_cont_mdiff_on_symm_of_mem_maximal_atlas ((times_cont_diff_groupoid ⊤ I).chart_mem_maximal_atlas x) end atlas /-! ### The identity is smooth -/ section id lemma times_cont_mdiff_id : times_cont_mdiff I I n (id : M → M) := times_cont_mdiff.of_le ((times_cont_diff_within_at_local_invariant_prop I I ∞).lift_prop_id (times_cont_diff_within_at_local_invariant_prop_id I)) le_top lemma smooth_id : smooth I I (id : M → M) := times_cont_mdiff_id lemma times_cont_mdiff_on_id : times_cont_mdiff_on I I n (id : M → M) s := times_cont_mdiff_id.times_cont_mdiff_on lemma smooth_on_id : smooth_on I I (id : M → M) s := times_cont_mdiff_on_id lemma times_cont_mdiff_at_id : times_cont_mdiff_at I I n (id : M → M) x := times_cont_mdiff_id.times_cont_mdiff_at lemma smooth_at_id : smooth_at I I (id : M → M) x := times_cont_mdiff_at_id lemma times_cont_mdiff_within_at_id : times_cont_mdiff_within_at I I n (id : M → M) s x := times_cont_mdiff_at_id.times_cont_mdiff_within_at lemma smooth_within_at_id : smooth_within_at I I (id : M → M) s x := times_cont_mdiff_within_at_id end id /-! ### Constants are smooth -/ section id variable {c : M'} lemma times_cont_mdiff_const : times_cont_mdiff I I' n (λ (x : M), c) := begin assume x, refine ⟨continuous_within_at_const, _⟩, simp only [times_cont_diff_within_at_prop, (∘)], exact times_cont_diff_within_at_const, end lemma smooth_const : smooth I I' (λ (x : M), c) := times_cont_mdiff_const lemma times_cont_mdiff_on_const : times_cont_mdiff_on I I' n (λ (x : M), c) s := times_cont_mdiff_const.times_cont_mdiff_on lemma smooth_on_const : smooth_on I I' (λ (x : M), c) s := times_cont_mdiff_on_const lemma times_cont_mdiff_at_const : times_cont_mdiff_at I I' n (λ (x : M), c) x := times_cont_mdiff_const.times_cont_mdiff_at lemma smooth_at_const : smooth_at I I' (λ (x : M), c) x := times_cont_mdiff_at_const lemma times_cont_mdiff_within_at_const : times_cont_mdiff_within_at I I' n (λ (x : M), c) s x := times_cont_mdiff_at_const.times_cont_mdiff_within_at lemma smooth_within_at_const : smooth_within_at I I' (λ (x : M), c) s x := times_cont_mdiff_within_at_const end id /-! ### Equivalence with the basic definition for functions between vector spaces -/ section vector_space lemma times_cont_mdiff_within_at_iff_times_cont_diff_within_at {f : E → E'} {s : set E} {x : E} : times_cont_mdiff_within_at 𝓘(𝕜, E) 𝓘(𝕜, E') n f s x ↔ times_cont_diff_within_at 𝕜 n f s x := begin simp only [times_cont_mdiff_within_at, lift_prop_within_at, times_cont_diff_within_at_prop, iff_def] with mfld_simps {contextual := tt}, exact times_cont_diff_within_at.continuous_within_at end alias times_cont_mdiff_within_at_iff_times_cont_diff_within_at ↔ times_cont_mdiff_within_at.times_cont_diff_within_at times_cont_diff_within_at.times_cont_mdiff_within_at lemma times_cont_mdiff_at_iff_times_cont_diff_at {f : E → E'} {x : E} : times_cont_mdiff_at 𝓘(𝕜, E) 𝓘(𝕜, E') n f x ↔ times_cont_diff_at 𝕜 n f x := by rw [← times_cont_mdiff_within_at_univ, times_cont_mdiff_within_at_iff_times_cont_diff_within_at, times_cont_diff_within_at_univ] alias times_cont_mdiff_at_iff_times_cont_diff_at ↔ times_cont_mdiff_at.times_cont_diff_at times_cont_diff_at.times_cont_mdiff_at lemma times_cont_mdiff_on_iff_times_cont_diff_on {f : E → E'} {s : set E} : times_cont_mdiff_on 𝓘(𝕜, E) 𝓘(𝕜, E') n f s ↔ times_cont_diff_on 𝕜 n f s := forall_congr $ by simp [times_cont_mdiff_within_at_iff_times_cont_diff_within_at] alias times_cont_mdiff_on_iff_times_cont_diff_on ↔ times_cont_mdiff_on.times_cont_diff_on times_cont_diff_on.times_cont_mdiff_on lemma times_cont_mdiff_iff_times_cont_diff {f : E → E'} : times_cont_mdiff 𝓘(𝕜, E) 𝓘(𝕜, E') n f ↔ times_cont_diff 𝕜 n f := by rw [← times_cont_diff_on_univ, ← times_cont_mdiff_on_univ, times_cont_mdiff_on_iff_times_cont_diff_on] alias times_cont_mdiff_iff_times_cont_diff ↔ times_cont_mdiff.times_cont_diff times_cont_diff.times_cont_mdiff end vector_space /-! ### The tangent map of a smooth function is smooth -/ section tangent_map /-- If a function is `C^n` with `1 ≤ n` on a domain with unique derivatives, then its bundled derivative is continuous. In this auxiliary lemma, we prove this fact when the source and target space are model spaces in models with corners. The general fact is proved in `times_cont_mdiff_on.continuous_on_tangent_map_within`-/ lemma times_cont_mdiff_on.continuous_on_tangent_map_within_aux {f : H → H'} {s : set H} (hf : times_cont_mdiff_on I I' n f s) (hn : 1 ≤ n) (hs : unique_mdiff_on I s) : continuous_on (tangent_map_within I I' f s) ((tangent_bundle.proj I H) ⁻¹' s) := begin suffices h : continuous_on (λ (p : H × E), (f p.fst, (fderiv_within 𝕜 (written_in_ext_chart_at I I' p.fst f) (I.symm ⁻¹' s ∩ range I) ((ext_chart_at I p.fst) p.fst) : E →L[𝕜] E') p.snd)) (prod.fst ⁻¹' s), { have A := (tangent_bundle_model_space_homeomorph H I).continuous, rw continuous_iff_continuous_on_univ at A, have B := ((tangent_bundle_model_space_homeomorph H' I').symm.continuous.comp_continuous_on h) .comp' A, have : (univ ∩ ⇑(tangent_bundle_model_space_homeomorph H I) ⁻¹' (prod.fst ⁻¹' s)) = tangent_bundle.proj I H ⁻¹' s, by { ext ⟨x, v⟩, simp only with mfld_simps }, rw this at B, apply B.congr, rintros ⟨x, v⟩ hx, dsimp [tangent_map_within], ext, { refl }, simp only with mfld_simps, apply congr_fun, apply congr_arg, rw mdifferentiable_within_at.mfderiv_within (hf.mdifferentiable_on hn x hx), refl }, suffices h : continuous_on (λ (p : H × E), (fderiv_within 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I p.fst) : E →L[𝕜] E') p.snd) (prod.fst ⁻¹' s), { dsimp [written_in_ext_chart_at, ext_chart_at], apply continuous_on.prod (continuous_on.comp hf.continuous_on continuous_fst.continuous_on (subset.refl _)), apply h.congr, assume p hp, refl }, suffices h : continuous_on (fderiv_within 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I)) (I '' s), { have C := continuous_on.comp h I.continuous_to_fun.continuous_on (subset.refl _), have A : continuous (λq : (E →L[𝕜] E') × E, q.1 q.2) := is_bounded_bilinear_map_apply.continuous, have B : continuous_on (λp : H × E, (fderiv_within 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I p.1), p.2)) (prod.fst ⁻¹' s), { apply continuous_on.prod _ continuous_snd.continuous_on, refine (continuous_on.comp C continuous_fst.continuous_on _ : _), exact preimage_mono (subset_preimage_image _ _) }, exact A.comp_continuous_on B }, rw times_cont_mdiff_on_iff at hf, let x : H := I.symm (0 : E), let y : H' := I'.symm (0 : E'), have A := hf.2 x y, simp only [I.image_eq, inter_comm] with mfld_simps at A ⊢, apply A.continuous_on_fderiv_within _ hn, convert hs.unique_diff_on x using 1, simp only [inter_comm] with mfld_simps end /-- If a function is `C^n` on a domain with unique derivatives, then its bundled derivative is `C^m` when `m+1 ≤ n`. In this auxiliary lemma, we prove this fact when the source and target space are model spaces in models with corners. The general fact is proved in `times_cont_mdiff_on.times_cont_mdiff_on_tangent_map_within` -/ lemma times_cont_mdiff_on.times_cont_mdiff_on_tangent_map_within_aux {f : H → H'} {s : set H} (hf : times_cont_mdiff_on I I' n f s) (hmn : m + 1 ≤ n) (hs : unique_mdiff_on I s) : times_cont_mdiff_on I.tangent I'.tangent m (tangent_map_within I I' f s) ((tangent_bundle.proj I H) ⁻¹' s) := begin have m_le_n : m ≤ n, { apply le_trans _ hmn, have : m + 0 ≤ m + 1 := add_le_add_left (zero_le _) _, simpa only [add_zero] using this }, have one_le_n : 1 ≤ n, { apply le_trans _ hmn, change 0 + 1 ≤ m + 1, exact add_le_add_right (zero_le _) _ }, have U': unique_diff_on 𝕜 (range I ∩ I.symm ⁻¹' s), { assume y hy, simpa only [unique_mdiff_on, unique_mdiff_within_at, hy.1, inter_comm] with mfld_simps using hs (I.symm y) hy.2 }, have U : unique_diff_on 𝕜 (set.prod (range I ∩ I.symm ⁻¹' s) (univ : set E)) := U'.prod unique_diff_on_univ, rw times_cont_mdiff_on_iff, refine ⟨hf.continuous_on_tangent_map_within_aux one_le_n hs, λp q, _⟩, have A : (range I).prod univ ∩ ((equiv.sigma_equiv_prod H E).symm ∘ λ (p : E × E), ((I.symm) p.fst, p.snd)) ⁻¹' (tangent_bundle.proj I H ⁻¹' s) = set.prod (range I ∩ I.symm ⁻¹' s) univ, by { ext ⟨x, v⟩, simp only with mfld_simps }, suffices h : times_cont_diff_on 𝕜 m (((λ (p : H' × E'), (I' p.fst, p.snd)) ∘ (equiv.sigma_equiv_prod H' E')) ∘ tangent_map_within I I' f s ∘ ((equiv.sigma_equiv_prod H E).symm) ∘ λ (p : E × E), (I.symm p.fst, p.snd)) ((range ⇑I ∩ ⇑(I.symm) ⁻¹' s).prod univ), by simpa [A] using h, change times_cont_diff_on 𝕜 m (λ (p : E × E), ((I' (f (I.symm p.fst)), ((mfderiv_within I I' f s (I.symm p.fst)) : E → E') p.snd) : E' × E')) (set.prod (range I ∩ I.symm ⁻¹' s) univ), -- check that all bits in this formula are `C^n` have hf' := times_cont_mdiff_on_iff.1 hf, have A : times_cont_diff_on 𝕜 m (I' ∘ f ∘ I.symm) (range I ∩ I.symm ⁻¹' s) := by simpa only with mfld_simps using (hf'.2 (I.symm 0) (I'.symm 0)).of_le m_le_n, have B : times_cont_diff_on 𝕜 m ((I' ∘ f ∘ I.symm) ∘ prod.fst) (set.prod (range I ∩ I.symm ⁻¹' s) (univ : set E)) := A.comp (times_cont_diff_fst.times_cont_diff_on) (prod_subset_preimage_fst _ _), suffices C : times_cont_diff_on 𝕜 m (λ (p : E × E), ((fderiv_within 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) p.1 : _) p.2)) (set.prod (range I ∩ I.symm ⁻¹' s) univ), { apply times_cont_diff_on.prod B _, apply C.congr (λp hp, _), simp only with mfld_simps at hp, simp only [mfderiv_within, hf.mdifferentiable_on one_le_n _ hp.2, hp.1, dif_pos] with mfld_simps }, have D : times_cont_diff_on 𝕜 m (λ x, (fderiv_within 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) x)) (range I ∩ I.symm ⁻¹' s), { have : times_cont_diff_on 𝕜 n (I' ∘ f ∘ I.symm) (range I ∩ I.symm ⁻¹' s) := by simpa only with mfld_simps using (hf'.2 (I.symm 0) (I'.symm 0)), simpa only [inter_comm] using this.fderiv_within U' hmn }, have := D.comp (times_cont_diff_fst.times_cont_diff_on) (prod_subset_preimage_fst _ _), have := times_cont_diff_on.prod this (times_cont_diff_snd.times_cont_diff_on), exact is_bounded_bilinear_map_apply.times_cont_diff.comp_times_cont_diff_on this, end include Is I's /-- If a function is `C^n` on a domain with unique derivatives, then its bundled derivative is `C^m` when `m+1 ≤ n`. -/ theorem times_cont_mdiff_on.times_cont_mdiff_on_tangent_map_within (hf : times_cont_mdiff_on I I' n f s) (hmn : m + 1 ≤ n) (hs : unique_mdiff_on I s) : times_cont_mdiff_on I.tangent I'.tangent m (tangent_map_within I I' f s) ((tangent_bundle.proj I M) ⁻¹' s) := begin /- The strategy of the proof is to avoid unfolding the definitions, and reduce by functoriality to the case of functions on the model spaces, where we have already proved the result. Let `l` and `r` be the charts to the left and to the right, so that we have ``` l^{-1} f r H --------> M ---> M' ---> H' ``` Then the tangent map `T(r ∘ f ∘ l)` is smooth by a previous result. Consider the composition ``` Tl T(r ∘ f ∘ l^{-1}) Tr^{-1} TM -----> TH -------------------> TH' ---------> TM' ``` where `Tr^{-1}` and `Tl` are the tangent maps of `r^{-1}` and `l`. Writing `Tl` and `Tr^{-1}` as composition of charts (called `Dl` and `il` for `l` and `Dr` and `ir` in the proof below), it follows that they are smooth. The composition of all these maps is `Tf`, and is therefore smooth as a composition of smooth maps. -/ have m_le_n : m ≤ n, { apply le_trans _ hmn, have : m + 0 ≤ m + 1 := add_le_add_left (zero_le _) _, simpa only [add_zero] }, have one_le_n : 1 ≤ n, { apply le_trans _ hmn, change 0 + 1 ≤ m + 1, exact add_le_add_right (zero_le _) _ }, /- First step: local reduction on the space, to a set `s'` which is contained in chart domains. -/ refine times_cont_mdiff_on_of_locally_times_cont_mdiff_on (λp hp, _), have hf' := times_cont_mdiff_on_iff.1 hf, simp [tangent_bundle.proj] at hp, let l := chart_at H p.1, set Dl := chart_at (model_prod H E) p with hDl, let r := chart_at H' (f p.1), let Dr := chart_at (model_prod H' E') (tangent_map_within I I' f s p), let il := chart_at (model_prod H E) (tangent_map I I l p), let ir := chart_at (model_prod H' E') (tangent_map I I' (r ∘ f) p), let s' := f ⁻¹' r.source ∩ s ∩ l.source, let s'_lift := (tangent_bundle.proj I M)⁻¹' s', let s'l := l.target ∩ l.symm ⁻¹' s', let s'l_lift := (tangent_bundle.proj I H) ⁻¹' s'l, rcases continuous_on_iff'.1 hf'.1 r.source r.open_source with ⟨o, o_open, ho⟩, suffices h : times_cont_mdiff_on I.tangent I'.tangent m (tangent_map_within I I' f s) s'_lift, { refine ⟨(tangent_bundle.proj I M)⁻¹' (o ∩ l.source), _, _, _⟩, show is_open ((tangent_bundle.proj I M)⁻¹' (o ∩ l.source)), from (is_open_inter o_open l.open_source).preimage (tangent_bundle_proj_continuous _ _) , show p ∈ tangent_bundle.proj I M ⁻¹' (o ∩ l.source), { simp [tangent_bundle.proj] at ⊢, have : p.1 ∈ f ⁻¹' r.source ∩ s, by simp [hp], rw ho at this, exact this.1 }, { have : tangent_bundle.proj I M ⁻¹' s ∩ tangent_bundle.proj I M ⁻¹' (o ∩ l.source) = s'_lift, { dsimp only [s'_lift, s'], rw [ho], mfld_set_tac }, rw this, exact h } }, /- Second step: check that all functions are smooth, and use the chain rule to write the bundled derivative as a composition of a function between model spaces and of charts. Convention: statements about the differentiability of `a ∘ b ∘ c` are named `diff_abc`. Statements about differentiability in the bundle have a `_lift` suffix. -/ have U' : unique_mdiff_on I s', { apply unique_mdiff_on.inter _ l.open_source, rw [ho, inter_comm], exact hs.inter o_open }, have U'l : unique_mdiff_on I s'l := U'.unique_mdiff_on_preimage (mdifferentiable_chart _ _), have diff_f : times_cont_mdiff_on I I' n f s' := hf.mono (by mfld_set_tac), have diff_r : times_cont_mdiff_on I' I' n r r.source := times_cont_mdiff_on_chart, have diff_rf : times_cont_mdiff_on I I' n (r ∘ f) s', { apply times_cont_mdiff_on.comp diff_r diff_f (λx hx, _), simp only [s'] with mfld_simps at hx, simp only [hx] with mfld_simps }, have diff_l : times_cont_mdiff_on I I n l.symm s'l, { have A : times_cont_mdiff_on I I n l.symm l.target := times_cont_mdiff_on_chart_symm, exact A.mono (by mfld_set_tac) }, have diff_rfl : times_cont_mdiff_on I I' n (r ∘ f ∘ l.symm) s'l, { apply times_cont_mdiff_on.comp diff_rf diff_l, mfld_set_tac }, have diff_rfl_lift : times_cont_mdiff_on I.tangent I'.tangent m (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l) s'l_lift := diff_rfl.times_cont_mdiff_on_tangent_map_within_aux hmn U'l, have diff_irrfl_lift : times_cont_mdiff_on I.tangent I'.tangent m (ir ∘ (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l)) s'l_lift, { have A : times_cont_mdiff_on I'.tangent I'.tangent m ir ir.source := times_cont_mdiff_on_chart, exact times_cont_mdiff_on.comp A diff_rfl_lift (λp hp, by simp only [ir] with mfld_simps) }, have diff_Drirrfl_lift : times_cont_mdiff_on I.tangent I'.tangent m (Dr.symm ∘ (ir ∘ (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l))) s'l_lift, { have A : times_cont_mdiff_on I'.tangent I'.tangent m Dr.symm Dr.target := times_cont_mdiff_on_chart_symm, apply times_cont_mdiff_on.comp A diff_irrfl_lift (λp hp, _), simp only [s'l_lift, tangent_bundle.proj] with mfld_simps at hp, simp only [ir, @local_equiv.refl_coe (model_prod H' E'), hp] with mfld_simps }, -- conclusion of this step: the composition of all the maps above is smooth have diff_DrirrflilDl : times_cont_mdiff_on I.tangent I'.tangent m (Dr.symm ∘ (ir ∘ (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l)) ∘ (il.symm ∘ Dl)) s'_lift, { have A : times_cont_mdiff_on I.tangent I.tangent m Dl Dl.source := times_cont_mdiff_on_chart, have A' : times_cont_mdiff_on I.tangent I.tangent m Dl s'_lift, { apply A.mono (λp hp, _), simp only [s'_lift, tangent_bundle.proj] with mfld_simps at hp, simp only [Dl, hp] with mfld_simps }, have B : times_cont_mdiff_on I.tangent I.tangent m il.symm il.target := times_cont_mdiff_on_chart_symm, have C : times_cont_mdiff_on I.tangent I.tangent m (il.symm ∘ Dl) s'_lift := times_cont_mdiff_on.comp B A' (λp hp, by simp only [il] with mfld_simps), apply times_cont_mdiff_on.comp diff_Drirrfl_lift C (λp hp, _), simp only [s'_lift, tangent_bundle.proj] with mfld_simps at hp, simp only [il, s'l_lift, hp, tangent_bundle.proj] with mfld_simps }, /- Third step: check that the composition of all the maps indeed coincides with the derivative we are looking for -/ have eq_comp : ∀q ∈ s'_lift, tangent_map_within I I' f s q = (Dr.symm ∘ ir ∘ (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l) ∘ (il.symm ∘ Dl)) q, { assume q hq, simp only [s'_lift, tangent_bundle.proj] with mfld_simps at hq, have U'q : unique_mdiff_within_at I s' q.1, by { apply U', simp only [hq, s'] with mfld_simps }, have U'lq : unique_mdiff_within_at I s'l (Dl q).1, by { apply U'l, simp only [hq, s'l] with mfld_simps }, have A : tangent_map_within I I' ((r ∘ f) ∘ l.symm) s'l (il.symm (Dl q)) = tangent_map_within I I' (r ∘ f) s' (tangent_map_within I I l.symm s'l (il.symm (Dl q))), { refine tangent_map_within_comp_at (il.symm (Dl q)) _ _ (λp hp, _) U'lq, { apply diff_rf.mdifferentiable_on one_le_n, simp only [hq] with mfld_simps }, { apply diff_l.mdifferentiable_on one_le_n, simp only [s'l, hq] with mfld_simps }, { simp only with mfld_simps at hp, simp only [hp] with mfld_simps } }, have B : tangent_map_within I I l.symm s'l (il.symm (Dl q)) = q, { have : tangent_map_within I I l.symm s'l (il.symm (Dl q)) = tangent_map I I l.symm (il.symm (Dl q)), { refine tangent_map_within_eq_tangent_map U'lq _, refine mdifferentiable_at_atlas_symm _ (chart_mem_atlas _ _) _, simp only [hq] with mfld_simps }, rw [this, tangent_map_chart_symm, hDl], { simp only [hq] with mfld_simps, have : q ∈ (chart_at (model_prod H E) p).source, by simp only [hq] with mfld_simps, exact (chart_at (model_prod H E) p).left_inv this }, { simp only [hq] with mfld_simps } }, have C : tangent_map_within I I' (r ∘ f) s' q = tangent_map_within I' I' r r.source (tangent_map_within I I' f s' q), { refine tangent_map_within_comp_at q _ _ (λr hr, _) U'q, { apply diff_r.mdifferentiable_on one_le_n, simp only [hq] with mfld_simps }, { apply diff_f.mdifferentiable_on one_le_n, simp only [hq] with mfld_simps }, { simp only [s'] with mfld_simps at hr, simp only [hr] with mfld_simps } }, have D : Dr.symm (ir (tangent_map_within I' I' r r.source (tangent_map_within I I' f s' q))) = tangent_map_within I I' f s' q, { have A : tangent_map_within I' I' r r.source (tangent_map_within I I' f s' q) = tangent_map I' I' r (tangent_map_within I I' f s' q), { apply tangent_map_within_eq_tangent_map, { apply is_open.unique_mdiff_within_at _ r.open_source, simp [hq] }, { refine mdifferentiable_at_atlas _ (chart_mem_atlas _ _) _, simp only [hq] with mfld_simps } }, have : f p.1 = (tangent_map_within I I' f s p).1 := rfl, rw [A], dsimp [r, Dr], rw [this, tangent_map_chart], { simp only [hq] with mfld_simps, have : tangent_map_within I I' f s' q ∈ (chart_at (model_prod H' E') (tangent_map_within I I' f s p)).source, by simp only [hq] with mfld_simps, exact (chart_at (model_prod H' E') (tangent_map_within I I' f s p)).left_inv this }, { simp only [hq] with mfld_simps } }, have E : tangent_map_within I I' f s' q = tangent_map_within I I' f s q, { refine tangent_map_within_subset (by mfld_set_tac) U'q _, apply hf.mdifferentiable_on one_le_n, simp only [hq] with mfld_simps }, simp only [(∘), A, B, C, D, E.symm] }, exact diff_DrirrflilDl.congr eq_comp, end /-- If a function is `C^n` on a domain with unique derivatives, with `1 ≤ n`, then its bundled derivative is continuous there. -/ theorem times_cont_mdiff_on.continuous_on_tangent_map_within (hf : times_cont_mdiff_on I I' n f s) (hmn : 1 ≤ n) (hs : unique_mdiff_on I s) : continuous_on (tangent_map_within I I' f s) ((tangent_bundle.proj I M) ⁻¹' s) := begin have : times_cont_mdiff_on I.tangent I'.tangent 0 (tangent_map_within I I' f s) ((tangent_bundle.proj I M) ⁻¹' s) := hf.times_cont_mdiff_on_tangent_map_within hmn hs, exact this.continuous_on end /-- If a function is `C^n`, then its bundled derivative is `C^m` when `m+1 ≤ n`. -/ theorem times_cont_mdiff.times_cont_mdiff_tangent_map (hf : times_cont_mdiff I I' n f) (hmn : m + 1 ≤ n) : times_cont_mdiff I.tangent I'.tangent m (tangent_map I I' f) := begin rw ← times_cont_mdiff_on_univ at hf ⊢, convert hf.times_cont_mdiff_on_tangent_map_within hmn unique_mdiff_on_univ, rw tangent_map_within_univ end /-- If a function is `C^n`, with `1 ≤ n`, then its bundled derivative is continuous. -/ theorem times_cont_mdiff.continuous_tangent_map (hf : times_cont_mdiff I I' n f) (hmn : 1 ≤ n) : continuous (tangent_map I I' f) := begin rw ← times_cont_mdiff_on_univ at hf, rw continuous_iff_continuous_on_univ, convert hf.continuous_on_tangent_map_within hmn unique_mdiff_on_univ, rw tangent_map_within_univ end end tangent_map /-! ### Smoothness of the projection in a basic smooth bundle -/ namespace basic_smooth_bundle_core variables (Z : basic_smooth_bundle_core I M E') lemma times_cont_mdiff_proj : times_cont_mdiff ((I.prod 𝓘(𝕜, E'))) I n Z.to_topological_fiber_bundle_core.proj := begin assume x, rw [times_cont_mdiff_at, times_cont_mdiff_within_at_iff], refine ⟨Z.to_topological_fiber_bundle_core.continuous_proj.continuous_at.continuous_within_at, _⟩, simp only [(∘), chart_at, chart] with mfld_simps, apply times_cont_diff_within_at_fst.congr, { rintros ⟨a, b⟩ hab, simp only with mfld_simps at hab, simp only [hab] with mfld_simps }, { simp only with mfld_simps } end lemma smooth_proj : smooth ((I.prod 𝓘(𝕜, E'))) I Z.to_topological_fiber_bundle_core.proj := times_cont_mdiff_proj Z lemma times_cont_mdiff_on_proj {s : set (Z.to_topological_fiber_bundle_core.total_space)} : times_cont_mdiff_on ((I.prod 𝓘(𝕜, E'))) I n Z.to_topological_fiber_bundle_core.proj s := Z.times_cont_mdiff_proj.times_cont_mdiff_on lemma smooth_on_proj {s : set (Z.to_topological_fiber_bundle_core.total_space)} : smooth_on ((I.prod 𝓘(𝕜, E'))) I Z.to_topological_fiber_bundle_core.proj s := times_cont_mdiff_on_proj Z lemma times_cont_mdiff_at_proj {p : Z.to_topological_fiber_bundle_core.total_space} : times_cont_mdiff_at ((I.prod 𝓘(𝕜, E'))) I n Z.to_topological_fiber_bundle_core.proj p := Z.times_cont_mdiff_proj.times_cont_mdiff_at lemma smooth_at_proj {p : Z.to_topological_fiber_bundle_core.total_space} : smooth_at ((I.prod 𝓘(𝕜, E'))) I Z.to_topological_fiber_bundle_core.proj p := Z.times_cont_mdiff_at_proj lemma times_cont_mdiff_within_at_proj {s : set (Z.to_topological_fiber_bundle_core.total_space)} {p : Z.to_topological_fiber_bundle_core.total_space} : times_cont_mdiff_within_at ((I.prod 𝓘(𝕜, E'))) I n Z.to_topological_fiber_bundle_core.proj s p := Z.times_cont_mdiff_at_proj.times_cont_mdiff_within_at lemma smooth_within_at_proj {s : set (Z.to_topological_fiber_bundle_core.total_space)} {p : Z.to_topological_fiber_bundle_core.total_space} : smooth_within_at ((I.prod 𝓘(𝕜, E'))) I Z.to_topological_fiber_bundle_core.proj s p := Z.times_cont_mdiff_within_at_proj /-- If an element of `E'` is invariant under all coordinate changes, then one can define a corresponding section of the fiber bundle, which is smooth. This applies in particular to the zero section of a vector bundle. Another example (not yet defined) would be the identity section of the endomorphism bundle of a vector bundle. -/ lemma smooth_const_section (v : E') (h : ∀ (i j : atlas H M), ∀ x ∈ i.1.source ∩ j.1.source, Z.coord_change i j (i.1 x) v = v) : smooth I ((I.prod 𝓘(𝕜, E'))) (show M → Z.to_topological_fiber_bundle_core.total_space, from λ x, ⟨x, v⟩) := begin assume x, rw [times_cont_mdiff_at, times_cont_mdiff_within_at_iff], split, { apply continuous.continuous_within_at, apply topological_fiber_bundle_core.continuous_const_section, assume i j y hy, exact h _ _ _ hy }, { have : times_cont_diff 𝕜 ⊤ (λ (y : E), (y, v)) := times_cont_diff_id.prod times_cont_diff_const, apply this.times_cont_diff_within_at.congr, { assume y hy, simp only with mfld_simps at hy, simp only [chart, hy, chart_at, prod.mk.inj_iff, to_topological_fiber_bundle_core] with mfld_simps, apply h, simp only [hy] with mfld_simps }, { simp only [chart, chart_at, prod.mk.inj_iff, to_topological_fiber_bundle_core] with mfld_simps, apply h, simp only with mfld_simps } } end end basic_smooth_bundle_core /-! ### Smoothness of the tangent bundle projection -/ namespace tangent_bundle include Is lemma times_cont_mdiff_proj : times_cont_mdiff I.tangent I n (proj I M) := basic_smooth_bundle_core.times_cont_mdiff_proj _ lemma smooth_proj : smooth I.tangent I (proj I M) := basic_smooth_bundle_core.smooth_proj _ lemma times_cont_mdiff_on_proj {s : set (tangent_bundle I M)} : times_cont_mdiff_on I.tangent I n (proj I M) s := basic_smooth_bundle_core.times_cont_mdiff_on_proj _ lemma smooth_on_proj {s : set (tangent_bundle I M)} : smooth_on I.tangent I (proj I M) s := basic_smooth_bundle_core.smooth_on_proj _ lemma times_cont_mdiff_at_proj {p : tangent_bundle I M} : times_cont_mdiff_at I.tangent I n (proj I M) p := basic_smooth_bundle_core.times_cont_mdiff_at_proj _ lemma smooth_at_proj {p : tangent_bundle I M} : smooth_at I.tangent I (proj I M) p := basic_smooth_bundle_core.smooth_at_proj _ lemma times_cont_mdiff_within_at_proj {s : set (tangent_bundle I M)} {p : tangent_bundle I M} : times_cont_mdiff_within_at I.tangent I n (proj I M) s p := basic_smooth_bundle_core.times_cont_mdiff_within_at_proj _ lemma smooth_within_at_proj {s : set (tangent_bundle I M)} {p : tangent_bundle I M} : smooth_within_at I.tangent I (proj I M) s p := basic_smooth_bundle_core.smooth_within_at_proj _ variables (I M) /-- The zero section of the tangent bundle -/ def zero_section : M → tangent_bundle I M := λ x, ⟨x, 0⟩ variables {I M} lemma smooth_zero_section : smooth I I.tangent (zero_section I M) := begin apply basic_smooth_bundle_core.smooth_const_section (tangent_bundle_core I M) 0, assume i j x hx, simp only [tangent_bundle_core, continuous_linear_map.map_zero] with mfld_simps end /-- The derivative of the zero section of the tangent bundle maps `⟨x, v⟩` to `⟨⟨x, 0⟩, ⟨v, 0⟩⟩`. Note that, as currently framed, this is a statement in coordinates, thus reliant on the choice of the coordinate system we use on the tangent bundle. However, the result itself is coordinate-dependent only to the extent that the coordinates determine a splitting of the tangent bundle. Moreover, there is a canonical splitting at each point of the zero section (since there is a canonical horizontal space there, the tangent space to the zero section, in addition to the canonical vertical space which is the kernel of the derivative of the projection), and this canonical splitting is also the one that comes from the coordinates on the tangent bundle in our definitions. So this statement is not as crazy as it may seem. TODO define splittings of vector bundles; state this result invariantly. -/ lemma tangent_map_tangent_bundle_pure (p : tangent_bundle I M) : tangent_map I I.tangent (tangent_bundle.zero_section I M) p = ⟨⟨p.1, 0⟩, ⟨p.2, 0⟩⟩ := begin rcases p with ⟨x, v⟩, have N : I.symm ⁻¹' (chart_at H x).target ∈ 𝓝 (I ((chart_at H x) x)), { apply mem_nhds_sets, apply (local_homeomorph.open_target _).preimage I.continuous_inv_fun, simp only with mfld_simps }, have A : mdifferentiable_at I I.tangent (λ (x : M), (⟨x, 0⟩ : tangent_bundle I M)) x := tangent_bundle.smooth_zero_section.mdifferentiable_at, have B : fderiv_within 𝕜 (λ (x_1 : E), (x_1, (0 : E))) (set.range ⇑I) (I ((chart_at H x) x)) v = (v, 0), { rw [fderiv_within_eq_fderiv, differentiable_at.fderiv_prod], { simp }, { exact differentiable_at_id' }, { exact differentiable_at_const _ }, { exact model_with_corners.unique_diff_at_image I }, { exact differentiable_at_id'.prod (differentiable_at_const _) } }, simp only [tangent_bundle.zero_section, tangent_map, mfderiv, A, dif_pos, chart_at, basic_smooth_bundle_core.chart, basic_smooth_bundle_core.to_topological_fiber_bundle_core, tangent_bundle_core, function.comp, continuous_linear_map.map_zero] with mfld_simps, rw ← fderiv_within_inter N (I.unique_diff (I ((chart_at H x) x)) (set.mem_range_self _)) at B, rw [← fderiv_within_inter N (I.unique_diff (I ((chart_at H x) x)) (set.mem_range_self _)), ← B], congr' 1, apply fderiv_within_congr _ (λ y hy, _), { simp only with mfld_simps, }, { apply unique_diff_within_at.inter (I.unique_diff _ _) N, simp only with mfld_simps }, { simp only with mfld_simps at hy, simp only [hy] with mfld_simps }, end end tangent_bundle /-! ### Smoothness of standard maps associated to the product of manifolds -/ section prod_mk lemma times_cont_mdiff_within_at.prod_mk {f : M → M'} {g : M → N'} (hf : times_cont_mdiff_within_at I I' n f s x) (hg : times_cont_mdiff_within_at I J' n g s x) : times_cont_mdiff_within_at I (I'.prod J') n (λ x, (f x, g x)) s x := begin rw times_cont_mdiff_within_at_iff at *, refine ⟨hf.1.prod hg.1, (hf.2.mono _).prod (hg.2.mono _)⟩; mfld_set_tac, end lemma times_cont_mdiff_at.prod_mk {f : M → M'} {g : M → N'} (hf : times_cont_mdiff_at I I' n f x) (hg : times_cont_mdiff_at I J' n g x) : times_cont_mdiff_at I (I'.prod J') n (λ x, (f x, g x)) x := hf.prod_mk hg lemma times_cont_mdiff_on.prod_mk {f : M → M'} {g : M → N'} (hf : times_cont_mdiff_on I I' n f s) (hg : times_cont_mdiff_on I J' n g s) : times_cont_mdiff_on I (I'.prod J') n (λ x, (f x, g x)) s := λ x hx, (hf x hx).prod_mk (hg x hx) lemma times_cont_mdiff.prod_mk {f : M → M'} {g : M → N'} (hf : times_cont_mdiff I I' n f) (hg : times_cont_mdiff I J' n g) : times_cont_mdiff I (I'.prod J') n (λ x, (f x, g x)) := λ x, (hf x).prod_mk (hg x) lemma smooth_within_at.prod_mk {f : M → M'} {g : M → N'} (hf : smooth_within_at I I' f s x) (hg : smooth_within_at I J' g s x) : smooth_within_at I (I'.prod J') (λ x, (f x, g x)) s x := hf.prod_mk hg lemma smooth_at.prod_mk {f : M → M'} {g : M → N'} (hf : smooth_at I I' f x) (hg : smooth_at I J' g x) : smooth_at I (I'.prod J') (λ x, (f x, g x)) x := hf.prod_mk hg lemma smooth_on.prod_mk {f : M → M'} {g : M → N'} (hf : smooth_on I I' f s) (hg : smooth_on I J' g s) : smooth_on I (I'.prod J') (λ x, (f x, g x)) s := hf.prod_mk hg lemma smooth.prod_mk {f : M → M'} {g : M → N'} (hf : smooth I I' f) (hg : smooth I J' g) : smooth I (I'.prod J') (λ x, (f x, g x)) := hf.prod_mk hg end prod_mk section projections lemma times_cont_mdiff_within_at_fst {s : set (M × N)} {p : M × N} : times_cont_mdiff_within_at (I.prod J) I n prod.fst s p := begin rw times_cont_mdiff_within_at_iff, refine ⟨continuous_within_at_fst, _⟩, refine times_cont_diff_within_at_fst.congr (λ y hy, _) _, { simp only with mfld_simps at hy, simp only [hy] with mfld_simps }, { simp only with mfld_simps } end lemma times_cont_mdiff_at_fst {p : M × N} : times_cont_mdiff_at (I.prod J) I n prod.fst p := times_cont_mdiff_within_at_fst lemma times_cont_mdiff_on_fst {s : set (M × N)} : times_cont_mdiff_on (I.prod J) I n prod.fst s := λ x hx, times_cont_mdiff_within_at_fst lemma times_cont_mdiff_fst : times_cont_mdiff (I.prod J) I n (@prod.fst M N) := λ x, times_cont_mdiff_at_fst lemma smooth_within_at_fst {s : set (M × N)} {p : M × N} : smooth_within_at (I.prod J) I prod.fst s p := times_cont_mdiff_within_at_fst lemma smooth_at_fst {p : M × N} : smooth_at (I.prod J) I prod.fst p := times_cont_mdiff_at_fst lemma smooth_on_fst {s : set (M × N)} : smooth_on (I.prod J) I prod.fst s := times_cont_mdiff_on_fst lemma smooth_fst : smooth (I.prod J) I (@prod.fst M N) := times_cont_mdiff_fst lemma times_cont_mdiff_within_at_snd {s : set (M × N)} {p : M × N} : times_cont_mdiff_within_at (I.prod J) J n prod.snd s p := begin rw times_cont_mdiff_within_at_iff, refine ⟨continuous_within_at_snd, _⟩, refine times_cont_diff_within_at_snd.congr (λ y hy, _) _, { simp only with mfld_simps at hy, simp only [hy] with mfld_simps }, { simp only with mfld_simps } end lemma times_cont_mdiff_at_snd {p : M × N} : times_cont_mdiff_at (I.prod J) J n prod.snd p := times_cont_mdiff_within_at_snd lemma times_cont_mdiff_on_snd {s : set (M × N)} : times_cont_mdiff_on (I.prod J) J n prod.snd s := λ x hx, times_cont_mdiff_within_at_snd lemma times_cont_mdiff_snd : times_cont_mdiff (I.prod J) J n (@prod.snd M N) := λ x, times_cont_mdiff_at_snd lemma smooth_within_at_snd {s : set (M × N)} {p : M × N} : smooth_within_at (I.prod J) J prod.snd s p := times_cont_mdiff_within_at_snd lemma smooth_at_snd {p : M × N} : smooth_at (I.prod J) J prod.snd p := times_cont_mdiff_at_snd lemma smooth_on_snd {s : set (M × N)} : smooth_on (I.prod J) J prod.snd s := times_cont_mdiff_on_snd lemma smooth_snd : smooth (I.prod J) J (@prod.snd M N) := times_cont_mdiff_snd lemma smooth_iff_proj_smooth {f : M → M' × N'} : (smooth I (I'.prod J') f) ↔ (smooth I I' (prod.fst ∘ f)) ∧ (smooth I J' (prod.snd ∘ f)) := begin split, { intro h, exact ⟨smooth_fst.comp h, smooth_snd.comp h⟩ }, { rintro ⟨h_fst, h_snd⟩, simpa only [prod.mk.eta] using h_fst.prod_mk h_snd, } end end projections section prod_map variables {g : N → N'} {r : set N} {y : N} /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ lemma times_cont_mdiff_within_at.prod_map' {p : M × N} (hf : times_cont_mdiff_within_at I I' n f s p.1) (hg : times_cont_mdiff_within_at J J' n g r p.2) : times_cont_mdiff_within_at (I.prod J) (I'.prod J') n (prod.map f g) (s.prod r) p := (hf.comp p times_cont_mdiff_within_at_fst (prod_subset_preimage_fst _ _)).prod_mk $ hg.comp p times_cont_mdiff_within_at_snd (prod_subset_preimage_snd _ _) lemma times_cont_mdiff_within_at.prod_map (hf : times_cont_mdiff_within_at I I' n f s x) (hg : times_cont_mdiff_within_at J J' n g r y) : times_cont_mdiff_within_at (I.prod J) (I'.prod J') n (prod.map f g) (s.prod r) (x, y) := times_cont_mdiff_within_at.prod_map' hf hg lemma times_cont_mdiff_at.prod_map (hf : times_cont_mdiff_at I I' n f x) (hg : times_cont_mdiff_at J J' n g y) : times_cont_mdiff_at (I.prod J) (I'.prod J') n (prod.map f g) (x, y) := begin rw ← times_cont_mdiff_within_at_univ at *, convert hf.prod_map hg, exact univ_prod_univ.symm end lemma times_cont_mdiff_at.prod_map' {p : M × N} (hf : times_cont_mdiff_at I I' n f p.1) (hg : times_cont_mdiff_at J J' n g p.2) : times_cont_mdiff_at (I.prod J) (I'.prod J') n (prod.map f g) p := begin rcases p, exact hf.prod_map hg end lemma times_cont_mdiff_on.prod_map (hf : times_cont_mdiff_on I I' n f s) (hg : times_cont_mdiff_on J J' n g r) : times_cont_mdiff_on (I.prod J) (I'.prod J') n (prod.map f g) (s.prod r) := (hf.comp times_cont_mdiff_on_fst (prod_subset_preimage_fst _ _)).prod_mk $ hg.comp (times_cont_mdiff_on_snd) (prod_subset_preimage_snd _ _) lemma times_cont_mdiff.prod_map (hf : times_cont_mdiff I I' n f) (hg : times_cont_mdiff J J' n g) : times_cont_mdiff (I.prod J) (I'.prod J') n (prod.map f g) := begin assume p, exact (hf p.1).prod_map' (hg p.2) end lemma smooth_within_at.prod_map (hf : smooth_within_at I I' f s x) (hg : smooth_within_at J J' g r y) : smooth_within_at (I.prod J) (I'.prod J') (prod.map f g) (s.prod r) (x, y) := hf.prod_map hg lemma smooth_at.prod_map (hf : smooth_at I I' f x) (hg : smooth_at J J' g y) : smooth_at (I.prod J) (I'.prod J') (prod.map f g) (x, y) := hf.prod_map hg lemma smooth_on.prod_map (hf : smooth_on I I' f s) (hg : smooth_on J J' g r) : smooth_on (I.prod J) (I'.prod J') (prod.map f g) (s.prod r) := hf.prod_map hg lemma smooth.prod_map (hf : smooth I I' f) (hg : smooth J J' g) : smooth (I.prod J) (I'.prod J') (prod.map f g) := hf.prod_map hg end prod_map /-! ### Linear maps between normed spaces are smooth -/ lemma continuous_linear_map.times_cont_mdiff (L : E →L[𝕜] F) : times_cont_mdiff 𝓘(𝕜, E) 𝓘(𝕜, F) n L := begin rw times_cont_mdiff_iff, refine ⟨L.cont, λ x y, _⟩, simp only with mfld_simps, rw times_cont_diff_on_univ, exact continuous_linear_map.times_cont_diff L, end /-! ### Smoothness of standard operations -/ variables {V : Type*} [normed_group V] [normed_space 𝕜 V] /-- On any vector space, multiplication by a scalar is a smooth operation. -/ lemma smooth_smul : smooth (𝓘(𝕜).prod 𝓘(𝕜, V)) 𝓘(𝕜, V) (λp : 𝕜 × V, p.1 • p.2) := begin rw smooth_iff, refine ⟨continuous_smul, λ x y, _⟩, simp only [prod.mk.eta] with mfld_simps, rw times_cont_diff_on_univ, exact times_cont_diff_smul, end lemma smooth.smul {N : Type*} [topological_space N] [charted_space H N] {f : N → 𝕜} {g : N → V} (hf : smooth I 𝓘(𝕜) f) (hg : smooth I 𝓘(𝕜, V) g) : smooth I 𝓘(𝕜, V) (λ p, f p • g p) := smooth_smul.comp (hf.prod_mk hg)
1b5b41f09636e8c553116b12471f6c4454698961
36c7a18fd72e5b57229bd8ba36493daf536a19ce
/tests/lean/run/blast_ematch1.lean
e95ead910c040efbb029833eebb5556fc727aec0
[ "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
341
lean
import data.nat open nat constant f : nat → nat constant g : nat → nat definition lemma1 [forward] : ∀ x, (:g (f x):) = x := sorry set_option blast.init_depth 10 set_option blast.inc_depth 1000 set_option blast.subst false set_option blast.ematch true example (a b c : nat) : a = f b → a = f c → g a ≠ b → false := by blast
7654c1dda0faf9a88c36151fbd9c05abecf27dbd
80d0f8071ea62262937ab36f5887a61735adea09
/src/certigrad/aevb/transformations.lean
a62c94cbaf5e74f0a7e3bc818b297f132fac8551
[ "Apache-2.0" ]
permissive
wudcscheme/certigrad
94805fa6a61f993c69a824429a103c9613a65a48
c9a06e93f1ec58196d6d3b8563b29868d916727f
refs/heads/master
1,679,386,475,077
1,551,651,022,000
1,551,651,022,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
3,578
lean
/- Copyright (c) 2017 Daniel Selsam. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Daniel Selsam Proofs that integrating out the KL and reparametizing are sound when applied to the naive variational encoder. -/ import .util .prog .graph ..prove_model_ok ..kl namespace certigrad namespace aevb open graph list tactic certigrad.tactic meta def prove_transformation (e : pexpr) := do whnf_target, [tgt, idx, H_at_idx, θ] ← intro_lst [`tgt, `idx, `H_at_idx, `θ] | failed, forall_idxs prove_model_base (do H_at_idx ← get_local `H_at_idx, mk_app `and.right [H_at_idx] >>= note `H_tgt_eq, H_tgt_eq_type ← get_local `H_tgt_eq >>= infer_type, s ← join_user_simp_lemmas true [`cgsimp], (H_tgt_eq_new_type, pr) ← simplify s H_tgt_eq_type {}, get_local `H_tgt_eq >>= λ H_tgt_eq, replace_hyp H_tgt_eq H_tgt_eq_new_type pr, get_local `H_tgt_eq >>= subst, to_expr e >>= apply, all_goals (cgsimp >> try prove_is_mvn_integrable >> try prove_preconditions)) idx #print "proving integrate_kl_sound..." lemma integrate_kl_sound (a : arch) (ws : weights a) (x_data : T [a^.n_in, a^.n_x]) : let g₀ : graph := graph_naive a x_data, fdict : env := mk_input_dict ws x_data g₀ in ∀ (tgt : reference) (idx : ℕ) (H_at_idx : at_idx g₀^.targets idx tgt) (θ : T tgt.2), E (graph.to_dist (λ m, ⟦sum_costs m (integrate_kl g₀)^.costs⟧) (env.insert tgt θ fdict) (integrate_kl g₀)^.nodes) dvec.head = E (graph.to_dist (λ m, ⟦sum_costs m g₀^.costs⟧) (env.insert tgt θ fdict) g₀^.nodes) dvec.head := by prove_transformation ```(integrate_mvn_kl_correct (ID.str label.encoding_loss) [ID.str label.decoding_loss] (graph_naive a x_data)^.nodes) #print "proving reparam_sound..." lemma reparam_sound (a : arch) (ws : weights a) (x_data : T [a^.n_in, a^.n_x]) : let g₁ : graph := integrate_kl (graph_naive a x_data), fdict : env := mk_input_dict ws x_data g₁ in ∀ (tgt : reference) (idx : ℕ) (H_at_idx : at_idx g₁^.targets idx tgt) (θ : T tgt.2), E (graph.to_dist (λ m, ⟦sum_costs m (reparam g₁)^.costs⟧) (env.insert tgt θ fdict) (reparam g₁)^.nodes) dvec.head = E (graph.to_dist (λ m, ⟦sum_costs m g₁^.costs⟧) (env.insert tgt θ fdict) g₁^.nodes) dvec.head := by prove_transformation ```(reparameterize_correct [ID.str label.encoding_loss, ID.str label.decoding_loss] (integrate_kl $ graph_naive a x_data)^.nodes _ (ID.str label.ε, [a^.nz, a^.bs])) #print "proving aevb_transformations_sound..." lemma aevb_transformations_sound {a : arch} (ws : weights a) (x_data : T [a^.n_in, a^.n_x]) : let g₀ : graph := naive_aevb a x_data, g_aevb : graph := reparam (integrate_kl g₀), fdict : env := mk_input_dict ws x_data g₀ in ∀ (tgt : reference) (idx : ℕ) (H_at_idx : at_idx g₀^.targets idx tgt) (θ : T tgt.2), E (graph.to_dist (λ m, ⟦sum_costs m g₀^.costs⟧) (env.insert tgt θ fdict) g₀^.nodes) dvec.head = E (graph.to_dist (λ m, ⟦sum_costs m g_aevb^.costs⟧) (env.insert tgt θ fdict) g_aevb^.nodes) dvec.head := begin whnf_target, intros tgt idx H_at_idx θ, -- TODO(dhs): this is annoying, rw and simp should whnf the let note H₁ := @reparam_sound a ws x_data tgt idx, note H₂ := @integrate_kl_sound a ws x_data tgt idx, simp only [naive_aevb_as_graph] at *, erw [H₁, H₂], all_goals { assumption } end end aevb end certigrad
c3536dbbdd4d52e60410ddb0297ea2ec437f63b1
d406927ab5617694ec9ea7001f101b7c9e3d9702
/counterexamples/phillips.lean
95067c8ce8e4114634ca3a4b38221291d9fb5d21
[ "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
28,990
lean
/- Copyright (c) 2021 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 analysis.normed_space.hahn_banach.extension import measure_theory.measure.lebesgue /-! # A counterexample on Pettis integrability There are several theories of integration for functions taking values in Banach spaces. Bochner integration, requiring approximation by simple functions, is the analogue of the one-dimensional theory. It is very well behaved, but only works for functions with second-countable range. For functions `f` taking values in a larger Banach space `B`, one can define the Dunford integral as follows. Assume that, for all continuous linear functional `φ`, the function `φ ∘ f` is measurable (we say that `f` is weakly measurable, or scalarly measurable) and integrable. Then `φ ↦ ∫ φ ∘ f` is continuous (by the closed graph theorem), and therefore defines an element of the bidual `B**`. This is the Dunford integral of `f`. This Dunford integral is not usable in practice as it does not belong to the right space. Let us say that a function is Pettis integrable if its Dunford integral belongs to the canonical image of `B` in `B**`. In this case, we define the Pettis integral as the Dunford integral inside `B`. This integral is very general, but not really usable to do analysis. This file illustrates this, by giving an example of a function with nice properties but which is *not* Pettis-integrable. This function: - is defined from `[0, 1]` to a complete Banach space; - is weakly measurable; - has norm everywhere bounded by `1` (in particular, its norm is integrable); - and yet it is not Pettis-integrable with respect to Lebesgue measure. This construction is due to [Ralph S. Phillips, *Integration in a convex linear topological space*][phillips1940], in Example 10.8. It requires the continuum hypothesis. The example is the following. Under the continuum hypothesis, one can find a subset of `ℝ²` which, along each vertical line, only misses a countable set of points, while it is countable along each horizontal line. This is due to Sierpinski, and formalized in `sierpinski_pathological_family`. (In fact, Sierpinski proves that the existence of such a set is equivalent to the continuum hypothesis). Let `B` be the set of all bounded functions on `ℝ` (we are really talking about everywhere defined functions here). Define `f : ℝ → B` by taking `f x` to be the characteristic function of the vertical slice at position `x` of Sierpinski's set. It is our counterexample. To show that it is weakly measurable, we should consider `φ ∘ f` where `φ` is an arbitrary continuous linear form on `B`. There is no reasonable classification of such linear forms (they can be very wild). But if one restricts such a linear form to characteristic functions, one gets a finitely additive signed "measure". Such a "measure" can be decomposed into a discrete part (supported on a countable set) and a continuous part (giving zero mass to countable sets). For all but countably many points, `f x` will not intersect the discrete support of `φ` thanks to the definition of the Sierpinski set. This implies that `φ ∘ f` is constant outside of a countable set, and equal to the total mass of the continuous part of `φ` there. In particular, it is measurable (and its integral is the total mass of the continuous part of `φ`). Assume that `f` has a Pettis integral `g`. For all continuous linear form `φ`, then `φ g` should be the total mass of the continuous part of `φ`. Taking for `φ` the evaluation at the point `x` (which has no continuous part), one gets `g x = 0`. Take then for `φ` the Lebesgue integral on `[0, 1]` (or rather an arbitrary extension of Lebesgue integration to all bounded functions, thanks to Hahn-Banach). Then `φ g` should be the total mass of the continuous part of `φ`, which is `1`. This contradicts the fact that `g = 0`, and concludes the proof that `f` has no Pettis integral. ## Implementation notes The space of all bounded functions is defined as the space of all bounded continuous functions on a discrete copy of the original type, as mathlib only contains the space of all bounded continuous functions (which is the useful one). -/ universe u variables {α : Type u} open set bounded_continuous_function measure_theory open cardinal (aleph) open_locale cardinal bounded_continuous_function noncomputable theory /-- A copy of a type, endowed with the discrete topology -/ def discrete_copy (α : Type u) : Type u := α instance : topological_space (discrete_copy α) := ⊥ instance : discrete_topology (discrete_copy α) := ⟨rfl⟩ instance [inhabited α] : inhabited (discrete_copy α) := ⟨show α, from default⟩ namespace phillips_1940 /-! ### Extending the integral Thanks to Hahn-Banach, one can define a (non-canonical) continuous linear functional on the space of all bounded functions, coinciding with the integral on the integrable ones. -/ /-- The subspace of integrable functions in the space of all bounded functions on a type. This is a technical device, used to apply Hahn-Banach theorem to construct an extension of the integral to all bounded functions. -/ def bounded_integrable_functions [measurable_space α] (μ : measure α) : subspace ℝ (discrete_copy α →ᵇ ℝ) := { carrier := {f | integrable f μ}, zero_mem' := integrable_zero _ _ _, add_mem' := λ f g hf hg, integrable.add hf hg, smul_mem' := λ c f hf, integrable.smul c hf } /-- The integral, as a continuous linear map on the subspace of integrable functions in the space of all bounded functions on a type. This is a technical device, that we will extend through Hahn-Banach. -/ def bounded_integrable_functions_integral_clm [measurable_space α] (μ : measure α) [is_finite_measure μ] : bounded_integrable_functions μ →L[ℝ] ℝ := linear_map.mk_continuous { to_fun := λ f, ∫ x, f x ∂μ, map_add' := λ f g, integral_add f.2 g.2, map_smul' := λ c f, integral_smul _ _ } (μ univ).to_real begin assume f, rw mul_comm, apply norm_integral_le_of_norm_le_const, apply filter.eventually_of_forall, assume x, exact bounded_continuous_function.norm_coe_le_norm f x, end /-- Given a measure, there exists a continuous linear form on the space of all bounded functions (not necessarily measurable) that coincides with the integral on bounded measurable functions. -/ lemma exists_linear_extension_to_bounded_functions [measurable_space α] (μ : measure α) [is_finite_measure μ] : ∃ φ : (discrete_copy α →ᵇ ℝ) →L[ℝ] ℝ, ∀ (f : discrete_copy α →ᵇ ℝ), integrable f μ → φ f = ∫ x, f x ∂μ := begin rcases exists_extension_norm_eq _ (bounded_integrable_functions_integral_clm μ) with ⟨φ, hφ⟩, exact ⟨φ, λ f hf, hφ.1 ⟨f, hf⟩⟩, end /-- An arbitrary extension of the integral to all bounded functions, as a continuous linear map. It is not at all canonical, and constructed using Hahn-Banach. -/ def _root_.measure_theory.measure.extension_to_bounded_functions [measurable_space α] (μ : measure α) [is_finite_measure μ] : (discrete_copy α →ᵇ ℝ) →L[ℝ] ℝ := (exists_linear_extension_to_bounded_functions μ).some lemma extension_to_bounded_functions_apply [measurable_space α] (μ : measure α) [is_finite_measure μ] (f : discrete_copy α →ᵇ ℝ) (hf : integrable f μ) : μ.extension_to_bounded_functions f = ∫ x, f x ∂μ := (exists_linear_extension_to_bounded_functions μ).some_spec f hf /-! ### Additive measures on the space of all sets We define bounded finitely additive signed measures on the space of all subsets of a type `α`, and show that such an object can be split into a discrete part and a continuous part. -/ /-- A bounded signed finitely additive measure defined on *all* subsets of a type. -/ structure bounded_additive_measure (α : Type u) := (to_fun : set α → ℝ) (additive' : ∀ s t, disjoint s t → to_fun (s ∪ t) = to_fun s + to_fun t) (exists_bound : ∃ (C : ℝ), ∀ s, |to_fun s| ≤ C) instance : inhabited (bounded_additive_measure α) := ⟨{ to_fun := λ s, 0, additive' := λ s t hst, by simp, exists_bound := ⟨0, λ s, by simp⟩ }⟩ instance : has_coe_to_fun (bounded_additive_measure α) (λ _, set α → ℝ) := ⟨λ f, f.to_fun⟩ namespace bounded_additive_measure /-- A constant bounding the mass of any set for `f`. -/ def C (f : bounded_additive_measure α) := f.exists_bound.some lemma additive (f : bounded_additive_measure α) (s t : set α) (h : disjoint s t) : f (s ∪ t) = f s + f t := f.additive' s t h lemma abs_le_bound (f : bounded_additive_measure α) (s : set α) : |f s| ≤ f.C := f.exists_bound.some_spec s lemma le_bound (f : bounded_additive_measure α) (s : set α) : f s ≤ f.C := le_trans (le_abs_self _) (f.abs_le_bound s) @[simp] lemma empty (f : bounded_additive_measure α) : f ∅ = 0 := begin have : (∅ : set α) = ∅ ∪ ∅, by simp only [empty_union], apply_fun f at this, rwa [f.additive _ _ (empty_disjoint _), self_eq_add_left] at this, end instance : has_neg (bounded_additive_measure α) := ⟨λ f, { to_fun := λ s, - f s, additive' := λ s t hst, by simp only [f.additive s t hst, add_comm, neg_add_rev], exists_bound := ⟨f.C, λ s, by simp [f.abs_le_bound]⟩ }⟩ @[simp] lemma neg_apply (f : bounded_additive_measure α) (s : set α) : (-f) s = - (f s) := rfl /-- Restricting a bounded additive measure to a subset still gives a bounded additive measure. -/ def restrict (f : bounded_additive_measure α) (t : set α) : bounded_additive_measure α := { to_fun := λ s, f (t ∩ s), additive' := λ s s' h, begin rw [← f.additive (t ∩ s) (t ∩ s'), inter_union_distrib_left], exact h.mono (inter_subset_right _ _) (inter_subset_right _ _), end, exists_bound := ⟨f.C, λ s, f.abs_le_bound _⟩ } @[simp] lemma restrict_apply (f : bounded_additive_measure α) (s t : set α) : f.restrict s t = f (s ∩ t) := rfl /-- There is a maximal countable set of positive measure, in the sense that any countable set not intersecting it has nonpositive measure. Auxiliary lemma to prove `exists_discrete_support`. -/ lemma exists_discrete_support_nonpos (f : bounded_additive_measure α) : ∃ (s : set α), s.countable ∧ (∀ t : set α, t.countable → f (t \ s) ≤ 0) := begin /- The idea of the proof is to construct the desired set inductively, adding at each step a countable set with close to maximal measure among those points that have not already been chosen. Doing this countably many steps will be enough. Indeed, otherwise, a remaining set would have positive measure `ε`. This means that at each step the set we have added also had a large measure, say at least `ε / 2`. After `n` steps, the set we have constructed has therefore measure at least `n * ε / 2`. This is a contradiction since the measures have to remain uniformly bounded. We argue from the start by contradiction, as this means that our inductive construction will never be stuck, so we won't have to consider this case separately. In this proof, we use explicit coercions `↑s` for `s : A` as otherwise the system tries to find a `has_coe_to_fun` instance on `↥A`, which is too costly. -/ by_contra' h, -- We will formulate things in terms of the type of countable subsets of `α`, as this is more -- convenient to formalize the inductive construction. let A : set (set α) := {t | t.countable}, let empty : A := ⟨∅, countable_empty⟩, haveI : nonempty A := ⟨empty⟩, -- given a countable set `s`, one can find a set `t` in its complement with measure close to -- maximal. have : ∀ (s : A), ∃ (t : A), (∀ (u : A), f (↑u \ ↑s) ≤ 2 * f (↑t \ ↑s)), { assume s, have B : bdd_above (range (λ (u : A), f (↑u \ ↑s))), { refine ⟨f.C, λ x hx, _⟩, rcases hx with ⟨u, hu⟩, rw ← hu, exact f.le_bound _ }, let S := supr (λ (t : A), f (↑t \ ↑s)), have S_pos : 0 < S, { rcases h s.1 s.2 with ⟨t, t_count, ht⟩, apply ht.trans_le, let t' : A := ⟨t, t_count⟩, change f (↑t' \ ↑s) ≤ S, exact le_csupr B t' }, rcases exists_lt_of_lt_csupr (half_lt_self S_pos) with ⟨t, ht⟩, refine ⟨t, λ u, _⟩, calc f (↑u \ ↑s) ≤ S : le_csupr B _ ... = 2 * (S / 2) : by ring ... ≤ 2 * f (↑t \ ↑s) : mul_le_mul_of_nonneg_left ht.le (by norm_num) }, choose! F hF using this, -- iterate the above construction, by adding at each step a set with measure close to maximal in -- the complement of already chosen points. This is the set `s n` at step `n`. let G : A → A := λ u, ⟨(↑u : set α) ∪ ↑(F u), u.2.union (F u).2⟩, let s : ℕ → A := λ n, G^[n] empty, -- We will get a contradiction from the fact that there is a countable set `u` with positive -- measure in the complement of `⋃ n, s n`. rcases h (⋃ n, ↑(s n)) (countable_Union (λ n, (s n).2)) with ⟨t, t_count, ht⟩, let u : A := ⟨t \ ⋃ n, ↑(s n), t_count.mono (diff_subset _ _)⟩, set ε := f (↑u) with hε, have ε_pos : 0 < ε := ht, have I1 : ∀ n, ε / 2 ≤ f (↑(s (n+1)) \ ↑(s n)), { assume n, rw [div_le_iff' (show (0 : ℝ) < 2, by norm_num), hε], convert hF (s n) u using 3, { dsimp [u], ext x, simp only [not_exists, mem_Union, mem_diff], tauto }, { simp only [s, function.iterate_succ', subtype.coe_mk, union_diff_left] } }, have I2 : ∀ (n : ℕ), (n : ℝ) * (ε / 2) ≤ f (↑(s n)), { assume n, induction n with n IH, { simp only [s, bounded_additive_measure.empty, id.def, nat.cast_zero, zero_mul, function.iterate_zero, subtype.coe_mk], }, { have : (↑(s (n+1)) : set α) = (↑(s (n+1)) \ ↑(s n)) ∪ ↑(s n), by simp only [s, function.iterate_succ', union_comm, union_diff_self, subtype.coe_mk, union_diff_left], rw [nat.succ_eq_add_one, this, f.additive], swap, { rw disjoint.comm, apply disjoint_diff }, calc ((n + 1 : ℕ) : ℝ) * (ε / 2) = ε / 2 + n * (ε / 2) : by simp only [nat.cast_succ]; ring ... ≤ f (↑(s (n + 1 : ℕ)) \ ↑(s n)) + f (↑(s n)) : add_le_add (I1 n) IH } }, rcases exists_nat_gt (f.C / (ε / 2)) with ⟨n, hn⟩, have : (n : ℝ) ≤ f.C / (ε / 2), by { rw le_div_iff (half_pos ε_pos), exact (I2 n).trans (f.le_bound _) }, exact lt_irrefl _ (this.trans_lt hn) end lemma exists_discrete_support (f : bounded_additive_measure α) : ∃ s : set α, s.countable ∧ (∀ t : set α, t.countable → f (t \ s) = 0) := begin rcases f.exists_discrete_support_nonpos with ⟨s₁, s₁_count, h₁⟩, rcases (-f).exists_discrete_support_nonpos with ⟨s₂, s₂_count, h₂⟩, refine ⟨s₁ ∪ s₂, s₁_count.union s₂_count, λ t ht, le_antisymm _ _⟩, { have : t \ (s₁ ∪ s₂) = (t \ (s₁ ∪ s₂)) \ s₁, by rw [diff_diff, union_comm, union_assoc, union_self], rw this, exact h₁ _ (ht.mono (diff_subset _ _)) }, { have : t \ (s₁ ∪ s₂) = (t \ (s₁ ∪ s₂)) \ s₂, by rw [diff_diff, union_assoc, union_self], rw this, simp only [neg_nonpos, neg_apply] at h₂, exact h₂ _ (ht.mono (diff_subset _ _)) }, end /-- A countable set outside of which the measure gives zero mass to countable sets. We are not claiming this set is unique, but we make an arbitrary choice of such a set. -/ def discrete_support (f : bounded_additive_measure α) : set α := (exists_discrete_support f).some lemma countable_discrete_support (f : bounded_additive_measure α) : f.discrete_support.countable := (exists_discrete_support f).some_spec.1 lemma apply_countable (f : bounded_additive_measure α) (t : set α) (ht : t.countable) : f (t \ f.discrete_support) = 0 := (exists_discrete_support f).some_spec.2 t ht /-- The discrete part of a bounded additive measure, obtained by restricting the measure to its countable support. -/ def discrete_part (f : bounded_additive_measure α) : bounded_additive_measure α := f.restrict f.discrete_support /-- The continuous part of a bounded additive measure, giving zero measure to every countable set. -/ def continuous_part (f : bounded_additive_measure α) : bounded_additive_measure α := f.restrict (univ \ f.discrete_support) lemma eq_add_parts (f : bounded_additive_measure α) (s : set α) : f s = f.discrete_part s + f.continuous_part s := begin simp only [discrete_part, continuous_part, restrict_apply], rw [← f.additive, ← inter_distrib_right], { simp only [union_univ, union_diff_self, univ_inter] }, { have : disjoint f.discrete_support (univ \ f.discrete_support) := disjoint_diff, exact this.mono (inter_subset_left _ _) (inter_subset_left _ _) } end lemma discrete_part_apply (f : bounded_additive_measure α) (s : set α) : f.discrete_part s = f (f.discrete_support ∩ s) := rfl lemma continuous_part_apply_eq_zero_of_countable (f : bounded_additive_measure α) (s : set α) (hs : s.countable) : f.continuous_part s = 0 := begin simp [continuous_part], convert f.apply_countable s hs using 2, ext x, simp [and_comm] end lemma continuous_part_apply_diff (f : bounded_additive_measure α) (s t : set α) (hs : s.countable) : f.continuous_part (t \ s) = f.continuous_part t := begin conv_rhs { rw ← diff_union_inter t s }, rw [additive, self_eq_add_right], { exact continuous_part_apply_eq_zero_of_countable _ _ (hs.mono (inter_subset_right _ _)) }, { exact disjoint.mono_right (inter_subset_right _ _) (disjoint.comm.1 disjoint_diff) }, end end bounded_additive_measure open bounded_additive_measure section /-! ### Relationship between continuous functionals and finitely additive measures. -/ lemma norm_indicator_le_one (s : set α) (x : α) : ‖(indicator s (1 : α → ℝ)) x‖ ≤ 1 := by { simp only [indicator, pi.one_apply], split_ifs; norm_num } /-- A functional in the dual space of bounded functions gives rise to a bounded additive measure, by applying the functional to the indicator functions. -/ def _root_.continuous_linear_map.to_bounded_additive_measure [topological_space α] [discrete_topology α] (f : (α →ᵇ ℝ) →L[ℝ] ℝ) : bounded_additive_measure α := { to_fun := λ s, f (of_normed_add_comm_group_discrete (indicator s 1) 1 (norm_indicator_le_one s)), additive' := λ s t hst, begin have : of_normed_add_comm_group_discrete (indicator (s ∪ t) 1) 1 (norm_indicator_le_one _) = of_normed_add_comm_group_discrete (indicator s 1) 1 (norm_indicator_le_one s) + of_normed_add_comm_group_discrete (indicator t 1) 1 (norm_indicator_le_one t), by { ext x, simp [indicator_union_of_disjoint hst], }, rw [this, f.map_add], end, exists_bound := ⟨‖f‖, λ s, begin have I : ‖of_normed_add_comm_group_discrete (indicator s 1) 1 (norm_indicator_le_one s)‖ ≤ 1, by apply norm_of_normed_add_comm_group_le _ zero_le_one, apply le_trans (f.le_op_norm _), simpa using mul_le_mul_of_nonneg_left I (norm_nonneg f), end⟩ } @[simp] lemma continuous_part_eval_clm_eq_zero [topological_space α] [discrete_topology α] (s : set α) (x : α) : (eval_clm ℝ x).to_bounded_additive_measure.continuous_part s = 0 := let f := (eval_clm ℝ x).to_bounded_additive_measure in calc f.continuous_part s = f.continuous_part (s \ {x}) : (continuous_part_apply_diff _ _ _ (countable_singleton x)).symm ... = f ((univ \ f.discrete_support) ∩ (s \ {x})) : rfl ... = indicator ((univ \ f.discrete_support) ∩ (s \ {x})) 1 x : rfl ... = 0 : by simp lemma to_functions_to_measure [measurable_space α] (μ : measure α) [is_finite_measure μ] (s : set α) (hs : measurable_set s) : μ.extension_to_bounded_functions.to_bounded_additive_measure s = (μ s).to_real := begin change μ.extension_to_bounded_functions (of_normed_add_comm_group_discrete (indicator s 1) 1 (norm_indicator_le_one s)) = (μ s).to_real, rw extension_to_bounded_functions_apply, { change ∫ x, s.indicator (λ y, (1 : ℝ)) x ∂μ = _, simp [integral_indicator hs] }, { change integrable (indicator s 1) μ, have : integrable (λ x, (1 : ℝ)) μ := integrable_const (1 : ℝ), apply this.mono' (measurable.indicator (@measurable_const _ _ _ _ (1 : ℝ)) hs).ae_strongly_measurable, apply filter.eventually_of_forall, exact norm_indicator_le_one _ } end lemma to_functions_to_measure_continuous_part [measurable_space α] [measurable_singleton_class α] (μ : measure α) [is_finite_measure μ] [has_no_atoms μ] (s : set α) (hs : measurable_set s) : μ.extension_to_bounded_functions.to_bounded_additive_measure.continuous_part s = (μ s).to_real := begin let f := μ.extension_to_bounded_functions.to_bounded_additive_measure, change f ((univ \ f.discrete_support) ∩ s) = (μ s).to_real, rw to_functions_to_measure, swap, { exact measurable_set.inter (measurable_set.univ.diff (countable.measurable_set f.countable_discrete_support)) hs }, congr' 1, rw [inter_comm, ← inter_diff_assoc, inter_univ], exact measure_diff_null (f.countable_discrete_support.measure_zero _) end end /-! ### A set in `ℝ²` large along verticals, small along horizontals We construct a subset of `ℝ²`, given as a family of sets, which is large along verticals (i.e., it only misses a countable set along each vertical) but small along horizontals (it is countable along horizontals). Such a set can not be measurable as it would contradict Fubini theorem. We need the continuum hypothesis to construct it. -/ theorem sierpinski_pathological_family (Hcont : #ℝ = aleph 1) : ∃ (f : ℝ → set ℝ), (∀ x, (univ \ f x).countable) ∧ (∀ y, {x : ℝ | y ∈ f x}.countable) := begin rcases cardinal.ord_eq ℝ with ⟨r, hr, H⟩, resetI, refine ⟨λ x, {y | r x y}, λ x, _, λ y, _⟩, { have : univ \ {y | r x y} = {y | r y x} ∪ {x}, { ext y, simp only [true_and, mem_univ, mem_set_of_eq, mem_insert_iff, union_singleton, mem_diff], rcases trichotomous_of r x y with h|rfl|h, { simp only [h, not_or_distrib, false_iff, not_true], split, { rintros rfl, exact irrefl_of r y h }, { exact asymm h } }, { simp only [true_or, eq_self_iff_true, iff_true], exact irrefl x }, { simp only [h, iff_true, or_true], exact asymm h } }, rw this, apply countable.union _ (countable_singleton _), rw [cardinal.countable_iff_lt_aleph_one, ← Hcont], exact cardinal.card_typein_lt r x H }, { rw [cardinal.countable_iff_lt_aleph_one, ← Hcont], exact cardinal.card_typein_lt r y H } end /-- A family of sets in `ℝ` which only miss countably many points, but such that any point is contained in only countably many of them. -/ def spf (Hcont : #ℝ = aleph 1) (x : ℝ) : set ℝ := (sierpinski_pathological_family Hcont).some x lemma countable_compl_spf (Hcont : #ℝ = aleph 1) (x : ℝ) : (univ \ spf Hcont x).countable := (sierpinski_pathological_family Hcont).some_spec.1 x lemma countable_spf_mem (Hcont : #ℝ = aleph 1) (y : ℝ) : {x | y ∈ spf Hcont x}.countable := (sierpinski_pathological_family Hcont).some_spec.2 y /-! ### A counterexample for the Pettis integral We construct a function `f` from `[0,1]` to a complete Banach space `B`, which is weakly measurable (i.e., for any continuous linear form `φ` on `B` the function `φ ∘ f` is measurable), bounded in norm (i.e., for all `x`, one has `‖f x‖ ≤ 1`), and still `f` has no Pettis integral. This construction, due to Phillips, requires the continuum hypothesis. We will take for `B` the space of all bounded functions on `ℝ`, with the supremum norm (no measure here, we are really talking of everywhere defined functions). And `f x` will be the characteristic function of a set which is large (it has countable complement), as in the Sierpinski pathological family. -/ /-- A family of bounded functions `f_x` from `ℝ` (seen with the discrete topology) to `ℝ` (in fact taking values in `{0, 1}`), indexed by a real parameter `x`, corresponding to the characteristic functions of the different fibers of the Sierpinski pathological family -/ def f (Hcont : #ℝ = aleph 1) (x : ℝ) : (discrete_copy ℝ →ᵇ ℝ) := of_normed_add_comm_group_discrete (indicator (spf Hcont x) 1) 1 (norm_indicator_le_one _) lemma apply_f_eq_continuous_part (Hcont : #ℝ = aleph 1) (φ : (discrete_copy ℝ →ᵇ ℝ) →L[ℝ] ℝ) (x : ℝ) (hx : φ.to_bounded_additive_measure.discrete_support ∩ spf Hcont x = ∅) : φ (f Hcont x) = φ.to_bounded_additive_measure.continuous_part univ := begin set ψ := φ.to_bounded_additive_measure with hψ, have : φ (f Hcont x) = ψ (spf Hcont x) := rfl, have U : univ = spf Hcont x ∪ (univ \ spf Hcont x), by simp only [union_univ, union_diff_self], rw [this, eq_add_parts, discrete_part_apply, hx, ψ.empty, zero_add, U, ψ.continuous_part.additive _ _ (disjoint_diff), ψ.continuous_part_apply_eq_zero_of_countable _ (countable_compl_spf Hcont x), add_zero], end lemma countable_ne (Hcont : #ℝ = aleph 1) (φ : (discrete_copy ℝ →ᵇ ℝ) →L[ℝ] ℝ) : {x | φ.to_bounded_additive_measure.continuous_part univ ≠ φ (f Hcont x)}.countable := begin have A : {x | φ.to_bounded_additive_measure.continuous_part univ ≠ φ (f Hcont x)} ⊆ {x | φ.to_bounded_additive_measure.discrete_support ∩ spf Hcont x ≠ ∅}, { assume x hx, contrapose! hx, simp only [not_not, mem_set_of_eq] at hx, simp [apply_f_eq_continuous_part Hcont φ x hx], }, have B : {x | φ.to_bounded_additive_measure.discrete_support ∩ spf Hcont x ≠ ∅} ⊆ ⋃ y ∈ φ.to_bounded_additive_measure.discrete_support, {x | y ∈ spf Hcont x}, { assume x hx, dsimp at hx, rw [← ne.def, ne_empty_iff_nonempty] at hx, simp only [exists_prop, mem_Union, mem_set_of_eq], exact hx }, apply countable.mono (subset.trans A B), exact countable.bUnion (countable_discrete_support _) (λ a ha, countable_spf_mem Hcont a), end lemma comp_ae_eq_const (Hcont : #ℝ = aleph 1) (φ : (discrete_copy ℝ →ᵇ ℝ) →L[ℝ] ℝ) : ∀ᵐ x ∂(volume.restrict (Icc (0 : ℝ) 1)), φ.to_bounded_additive_measure.continuous_part univ = φ (f Hcont x) := begin apply ae_restrict_of_ae, refine measure_mono_null _ ((countable_ne Hcont φ).measure_zero _), assume x, simp only [imp_self, mem_set_of_eq, mem_compl_iff], end lemma integrable_comp (Hcont : #ℝ = aleph 1) (φ : (discrete_copy ℝ →ᵇ ℝ) →L[ℝ] ℝ) : integrable_on (λ x, φ (f Hcont x)) (Icc 0 1) := begin have : integrable_on (λ x, φ.to_bounded_additive_measure.continuous_part univ) (Icc (0 : ℝ) 1) volume, by simp [integrable_on_const], apply integrable.congr this (comp_ae_eq_const Hcont φ), end lemma integral_comp (Hcont : #ℝ = aleph 1) (φ : (discrete_copy ℝ →ᵇ ℝ) →L[ℝ] ℝ) : ∫ x in Icc 0 1, φ (f Hcont x) = φ.to_bounded_additive_measure.continuous_part univ := begin rw ← integral_congr_ae (comp_ae_eq_const Hcont φ), simp, end /-! The next few statements show that the function `f Hcont : ℝ → (discrete_copy ℝ →ᵇ ℝ)` takes its values in a complete space, is scalarly measurable, is everywhere bounded by `1`, and still has no Pettis integral. -/ example : complete_space (discrete_copy ℝ →ᵇ ℝ) := by apply_instance /-- The function `f Hcont : ℝ → (discrete_copy ℝ →ᵇ ℝ)` is scalarly measurable. -/ lemma measurable_comp (Hcont : #ℝ = aleph 1) (φ : (discrete_copy ℝ →ᵇ ℝ) →L[ℝ] ℝ) : measurable (λ x, φ (f Hcont x)) := begin have : measurable (λ x, φ.to_bounded_additive_measure.continuous_part univ) := measurable_const, refine this.measurable_of_countable_ne _, exact countable_ne Hcont φ, end /-- The function `f Hcont : ℝ → (discrete_copy ℝ →ᵇ ℝ)` is uniformly bounded by `1` in norm. -/ lemma norm_bound (Hcont : #ℝ = aleph 1) (x : ℝ) : ‖f Hcont x‖ ≤ 1 := norm_of_normed_add_comm_group_le _ zero_le_one _ /-- The function `f Hcont : ℝ → (discrete_copy ℝ →ᵇ ℝ)` has no Pettis integral. -/ theorem no_pettis_integral (Hcont : #ℝ = aleph 1) : ¬ ∃ (g : discrete_copy ℝ →ᵇ ℝ), ∀ (φ : (discrete_copy ℝ →ᵇ ℝ) →L[ℝ] ℝ), ∫ x in Icc 0 1, φ (f Hcont x) = φ g := begin rintros ⟨g, h⟩, simp only [integral_comp] at h, have : g = 0, { ext x, have : g x = eval_clm ℝ x g := rfl, rw [this, ← h], simp }, simp only [this, continuous_linear_map.map_zero] at h, specialize h (volume.restrict (Icc (0 : ℝ) 1)).extension_to_bounded_functions, simp_rw [to_functions_to_measure_continuous_part _ _ measurable_set.univ] at h, simpa using h, end end phillips_1940
4019d959af02878663e227030fca9cd6daae2ff3
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/topology/semicontinuous.lean
6b4887f926a4ad17a74ac052813f2a43f565826f
[ "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
43,522
lean
/- Copyright (c) 2021 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.continuous_on import algebra.indicator_function import topology.algebra.group import topology.algebra.ordered.liminf_limsup import topology.instances.ennreal /-! # Semicontinuous maps A function `f` from a topological space `α` to an ordered space `β` is lower semicontinuous at a point `x` if, for any `y < f x`, for any `x'` close enough to `x`, one has `f x' > y`. In other words, `f` can jump up, but it can not jump down. Upper semicontinuous functions are defined similarly. This file introduces these notions, and a basic API around them mimicking the API for continuous functions. ## Main definitions and results We introduce 4 definitions related to lower semicontinuity: * `lower_semicontinuous_within_at f s x` * `lower_semicontinuous_at f x` * `lower_semicontinuous_on f s` * `lower_semicontinuous f` We build a basic API using dot notation around these notions, and we prove that * constant functions are lower semicontinuous; * `indicator s (λ _, y)` is lower semicontinuous when `s` is open and `0 ≤ y`, or when `s` is closed and `y ≤ 0`; * continuous functions are lower semicontinuous; * composition with a continuous monotone functions maps lower semicontinuous functions to lower semicontinuous functions. If the function is anti-monotone, it instead maps lower semicontinuous functions to upper semicontinuous functions; * a sum of two (or finitely many) lower semicontinuous functions is lower semicontinuous; * a supremum of a family of lower semicontinuous functions is lower semicontinuous; * An infinite sum of `ℝ≥0∞`-valued lower semicontinuous functions is lower semicontinuous. Similar results are stated and proved for upper semicontinuity. We also prove that a function is continuous if and only if it is both lower and upper semicontinuous. ## Implementation details All the nontrivial results for upper semicontinuous functions are deduced from the corresponding ones for lower semicontinuous functions using `order_dual`. -/ open_locale topological_space big_operators ennreal open set variables {α : Type*} [topological_space α] {β : Type*} [preorder β] {f g : α → β} {x : α} {s t : set α} {y z : β} /-! ### Main definitions -/ /-- A real function `f` is lower semicontinuous at `x` within a set `s` if, for any `ε > 0`, for all `x'` close enough to `x` in `s`, then `f x'` is at least `f x - ε`. We formulate this in a general preordered space, using an arbitrary `y < f x` instead of `f x - ε`. -/ def lower_semicontinuous_within_at (f : α → β) (s : set α) (x : α) := ∀ y < f x, ∀ᶠ x' in 𝓝[s] x, y < f x' /-- A real function `f` is lower semicontinuous on a set `s` if, for any `ε > 0`, for any `x ∈ s`, for all `x'` close enough to `x` in `s`, then `f x'` is at least `f x - ε`. We formulate this in a general preordered space, using an arbitrary `y < f x` instead of `f x - ε`.-/ def lower_semicontinuous_on (f : α → β) (s : set α) := ∀ x ∈ s, lower_semicontinuous_within_at f s x /-- A real function `f` is lower semicontinuous at `x` if, for any `ε > 0`, for all `x'` close enough to `x`, then `f x'` is at least `f x - ε`. We formulate this in a general preordered space, using an arbitrary `y < f x` instead of `f x - ε`. -/ def lower_semicontinuous_at (f : α → β) (x : α) := ∀ y < f x, ∀ᶠ x' in 𝓝 x, y < f x' /-- A real function `f` is lower semicontinuous if, for any `ε > 0`, for any `x`, for all `x'` close enough to `x`, then `f x'` is at least `f x - ε`. We formulate this in a general preordered space, using an arbitrary `y < f x` instead of `f x - ε`. -/ def lower_semicontinuous (f : α → β) := ∀ x, lower_semicontinuous_at f x /-- A real function `f` is upper semicontinuous at `x` within a set `s` if, for any `ε > 0`, for all `x'` close enough to `x` in `s`, then `f x'` is at most `f x + ε`. We formulate this in a general preordered space, using an arbitrary `y > f x` instead of `f x + ε`. -/ def upper_semicontinuous_within_at (f : α → β) (s : set α) (x : α) := ∀ y, f x < y → ∀ᶠ x' in 𝓝[s] x, f x' < y /-- A real function `f` is upper semicontinuous on a set `s` if, for any `ε > 0`, for any `x ∈ s`, for all `x'` close enough to `x` in `s`, then `f x'` is at most `f x + ε`. We formulate this in a general preordered space, using an arbitrary `y > f x` instead of `f x + ε`.-/ def upper_semicontinuous_on (f : α → β) (s : set α) := ∀ x ∈ s, upper_semicontinuous_within_at f s x /-- A real function `f` is upper semicontinuous at `x` if, for any `ε > 0`, for all `x'` close enough to `x`, then `f x'` is at most `f x + ε`. We formulate this in a general preordered space, using an arbitrary `y > f x` instead of `f x + ε`. -/ def upper_semicontinuous_at (f : α → β) (x : α) := ∀ y, f x < y → ∀ᶠ x' in 𝓝 x, f x' < y /-- A real function `f` is upper semicontinuous if, for any `ε > 0`, for any `x`, for all `x'` close enough to `x`, then `f x'` is at most `f x + ε`. We formulate this in a general preordered space, using an arbitrary `y > f x` instead of `f x + ε`.-/ def upper_semicontinuous (f : α → β) := ∀ x, upper_semicontinuous_at f x /-! ### Lower semicontinuous functions -/ /-! #### Basic dot notation interface for lower semicontinuity -/ lemma lower_semicontinuous_within_at.mono (h : lower_semicontinuous_within_at f s x) (hst : t ⊆ s) : lower_semicontinuous_within_at f t x := λ y hy, filter.eventually.filter_mono (nhds_within_mono _ hst) (h y hy) lemma lower_semicontinuous_within_at_univ_iff : lower_semicontinuous_within_at f univ x ↔ lower_semicontinuous_at f x := by simp [lower_semicontinuous_within_at, lower_semicontinuous_at, nhds_within_univ] lemma lower_semicontinuous_at.lower_semicontinuous_within_at (s : set α) (h : lower_semicontinuous_at f x) : lower_semicontinuous_within_at f s x := λ y hy, filter.eventually.filter_mono nhds_within_le_nhds (h y hy) lemma lower_semicontinuous_on.lower_semicontinuous_within_at (h : lower_semicontinuous_on f s) (hx : x ∈ s) : lower_semicontinuous_within_at f s x := h x hx lemma lower_semicontinuous_on.mono (h : lower_semicontinuous_on f s) (hst : t ⊆ s) : lower_semicontinuous_on f t := λ x hx, (h x (hst hx)).mono hst lemma lower_semicontinuous_on_univ_iff : lower_semicontinuous_on f univ ↔ lower_semicontinuous f := by simp [lower_semicontinuous_on, lower_semicontinuous, lower_semicontinuous_within_at_univ_iff] lemma lower_semicontinuous.lower_semicontinuous_at (h : lower_semicontinuous f) (x : α) : lower_semicontinuous_at f x := h x lemma lower_semicontinuous.lower_semicontinuous_within_at (h : lower_semicontinuous f) (s : set α) (x : α) : lower_semicontinuous_within_at f s x := (h x).lower_semicontinuous_within_at s lemma lower_semicontinuous.lower_semicontinuous_on (h : lower_semicontinuous f) (s : set α) : lower_semicontinuous_on f s := λ x hx, h.lower_semicontinuous_within_at s x /-! #### Constants -/ lemma lower_semicontinuous_within_at_const : lower_semicontinuous_within_at (λ x, z) s x := λ y hy, filter.eventually_of_forall (λ x, hy) lemma lower_semicontinuous_at_const : lower_semicontinuous_at (λ x, z) x := λ y hy, filter.eventually_of_forall (λ x, hy) lemma lower_semicontinuous_on_const : lower_semicontinuous_on (λ x, z) s := λ x hx, lower_semicontinuous_within_at_const lemma lower_semicontinuous_const : lower_semicontinuous (λ (x : α), z) := λ x, lower_semicontinuous_at_const /-! #### Indicators -/ section variables [has_zero β] lemma is_open.lower_semicontinuous_indicator (hs : is_open s) (hy : 0 ≤ y) : lower_semicontinuous (indicator s (λ x, y)) := begin assume x z hz, by_cases h : x ∈ s; simp [h] at hz, { filter_upwards [hs.mem_nhds h], simp [hz] { contextual := tt} }, { apply filter.eventually_of_forall (λ x', _), by_cases h' : x' ∈ s; simp [h', hz.trans_le hy, hz] } end lemma is_open.lower_semicontinuous_on_indicator (hs : is_open s) (hy : 0 ≤ y) : lower_semicontinuous_on (indicator s (λ x, y)) t := (hs.lower_semicontinuous_indicator hy).lower_semicontinuous_on t lemma is_open.lower_semicontinuous_at_indicator (hs : is_open s) (hy : 0 ≤ y) : lower_semicontinuous_at (indicator s (λ x, y)) x := (hs.lower_semicontinuous_indicator hy).lower_semicontinuous_at x lemma is_open.lower_semicontinuous_within_at_indicator (hs : is_open s) (hy : 0 ≤ y) : lower_semicontinuous_within_at (indicator s (λ x, y)) t x := (hs.lower_semicontinuous_indicator hy).lower_semicontinuous_within_at t x lemma is_closed.lower_semicontinuous_indicator (hs : is_closed s) (hy : y ≤ 0) : lower_semicontinuous (indicator s (λ x, y)) := begin assume x z hz, by_cases h : x ∈ s; simp [h] at hz, { apply filter.eventually_of_forall (λ x', _), by_cases h' : x' ∈ s; simp [h', hz, hz.trans_le hy], }, { filter_upwards [hs.is_open_compl.mem_nhds h], simp [hz] { contextual := tt } } end lemma is_closed.lower_semicontinuous_on_indicator (hs : is_closed s) (hy : y ≤ 0) : lower_semicontinuous_on (indicator s (λ x, y)) t := (hs.lower_semicontinuous_indicator hy).lower_semicontinuous_on t lemma is_closed.lower_semicontinuous_at_indicator (hs : is_closed s) (hy : y ≤ 0) : lower_semicontinuous_at (indicator s (λ x, y)) x := (hs.lower_semicontinuous_indicator hy).lower_semicontinuous_at x lemma is_closed.lower_semicontinuous_within_at_indicator (hs : is_closed s) (hy : y ≤ 0) : lower_semicontinuous_within_at (indicator s (λ x, y)) t x := (hs.lower_semicontinuous_indicator hy).lower_semicontinuous_within_at t x end /-! #### Relationship with continuity -/ theorem lower_semicontinuous_iff_is_open : lower_semicontinuous f ↔ ∀ y, is_open (f ⁻¹' (Ioi y)) := ⟨λ H y, is_open_iff_mem_nhds.2 (λ x hx, H x y hx), λ H x y y_lt, is_open.mem_nhds (H y) y_lt⟩ lemma lower_semicontinuous.is_open_preimage (hf : lower_semicontinuous f) (y : β) : is_open (f ⁻¹' (Ioi y)) := lower_semicontinuous_iff_is_open.1 hf y section variables {γ : Type*} [linear_order γ] [topological_space γ] [order_topology γ] lemma continuous_within_at.lower_semicontinuous_within_at {f : α → γ} (h : continuous_within_at f s x) : lower_semicontinuous_within_at f s x := λ y hy, h (Ioi_mem_nhds hy) lemma continuous_at.lower_semicontinuous_at {f : α → γ} (h : continuous_at f x) : lower_semicontinuous_at f x := λ y hy, h (Ioi_mem_nhds hy) lemma continuous_on.lower_semicontinuous_on {f : α → γ} (h : continuous_on f s) : lower_semicontinuous_on f s := λ x hx, (h x hx).lower_semicontinuous_within_at lemma continuous.lower_semicontinuous {f : α → γ} (h : continuous f) : lower_semicontinuous f := λ x, h.continuous_at.lower_semicontinuous_at end /-! ### Composition -/ section variables {γ : Type*} [linear_order γ] [topological_space γ] [order_topology γ] variables {δ : Type*} [linear_order δ] [topological_space δ] [order_topology δ] lemma continuous_at.comp_lower_semicontinuous_within_at {g : γ → δ} {f : α → γ} (hg : continuous_at g (f x)) (hf : lower_semicontinuous_within_at f s x) (gmon : monotone g) : lower_semicontinuous_within_at (g ∘ f) s x := begin assume y hy, by_cases h : ∃ l, l < f x, { obtain ⟨z, zlt, hz⟩ : ∃ z < f x, Ioc z (f x) ⊆ g ⁻¹' (Ioi y) := exists_Ioc_subset_of_mem_nhds (hg (Ioi_mem_nhds hy)) h, filter_upwards [hf z zlt], assume a ha, calc y < g (min (f x) (f a)) : hz (by simp [zlt, ha, le_refl]) ... ≤ g (f a) : gmon (min_le_right _ _) }, { simp only [not_exists, not_lt] at h, exact filter.eventually_of_forall (λ a, hy.trans_le (gmon (h (f a)))) } end lemma continuous_at.comp_lower_semicontinuous_at {g : γ → δ} {f : α → γ} (hg : continuous_at g (f x)) (hf : lower_semicontinuous_at f x) (gmon : monotone g) : lower_semicontinuous_at (g ∘ f) x := begin simp only [← lower_semicontinuous_within_at_univ_iff] at hf ⊢, exact hg.comp_lower_semicontinuous_within_at hf gmon end lemma continuous.comp_lower_semicontinuous_on {g : γ → δ} {f : α → γ} (hg : continuous g) (hf : lower_semicontinuous_on f s) (gmon : monotone g) : lower_semicontinuous_on (g ∘ f) s := λ x hx, (hg.continuous_at).comp_lower_semicontinuous_within_at (hf x hx) gmon lemma continuous.comp_lower_semicontinuous {g : γ → δ} {f : α → γ} (hg : continuous g) (hf : lower_semicontinuous f) (gmon : monotone g) : lower_semicontinuous (g ∘ f) := λ x, (hg.continuous_at).comp_lower_semicontinuous_at (hf x) gmon lemma continuous_at.comp_lower_semicontinuous_within_at_antitone {g : γ → δ} {f : α → γ} (hg : continuous_at g (f x)) (hf : lower_semicontinuous_within_at f s x) (gmon : antitone g) : upper_semicontinuous_within_at (g ∘ f) s x := @continuous_at.comp_lower_semicontinuous_within_at α _ x s γ _ _ _ (order_dual δ) _ _ _ g f hg hf gmon lemma continuous_at.comp_lower_semicontinuous_at_antitone {g : γ → δ} {f : α → γ} (hg : continuous_at g (f x)) (hf : lower_semicontinuous_at f x) (gmon : antitone g) : upper_semicontinuous_at (g ∘ f) x := @continuous_at.comp_lower_semicontinuous_at α _ x γ _ _ _ (order_dual δ) _ _ _ g f hg hf gmon lemma continuous.comp_lower_semicontinuous_on_antitone {g : γ → δ} {f : α → γ} (hg : continuous g) (hf : lower_semicontinuous_on f s) (gmon : antitone g) : upper_semicontinuous_on (g ∘ f) s := λ x hx, (hg.continuous_at).comp_lower_semicontinuous_within_at_antitone (hf x hx) gmon lemma continuous.comp_lower_semicontinuous_antitone {g : γ → δ} {f : α → γ} (hg : continuous g) (hf : lower_semicontinuous f) (gmon : antitone g) : upper_semicontinuous (g ∘ f) := λ x, (hg.continuous_at).comp_lower_semicontinuous_at_antitone (hf x) gmon end /-! #### Addition -/ section variables {ι : Type*} {γ : Type*} [linear_ordered_add_comm_monoid γ] [topological_space γ] [order_topology γ] /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `ereal`. The unprimed version of the lemma uses `[has_continuous_add]`. -/ lemma lower_semicontinuous_within_at.add' {f g : α → γ} (hf : lower_semicontinuous_within_at f s x) (hg : lower_semicontinuous_within_at g s x) (hcont : continuous_at (λ (p : γ × γ), p.1 + p.2) (f x, g x)) : lower_semicontinuous_within_at (λ z, f z + g z) s x := begin assume y hy, obtain ⟨u, v, u_open, xu, v_open, xv, h⟩ : ∃ (u v : set γ), is_open u ∧ f x ∈ u ∧ is_open v ∧ g x ∈ v ∧ u.prod v ⊆ {p : γ × γ | y < p.fst + p.snd} := mem_nhds_prod_iff'.1 (hcont (is_open_Ioi.mem_nhds hy)), by_cases hx₁ : ∃ l, l < f x, { obtain ⟨z₁, z₁lt, h₁⟩ : ∃ z₁ < f x, Ioc z₁ (f x) ⊆ u := exists_Ioc_subset_of_mem_nhds (u_open.mem_nhds xu) hx₁, by_cases hx₂ : ∃ l, l < g x, { obtain ⟨z₂, z₂lt, h₂⟩ : ∃ z₂ < g x, Ioc z₂ (g x) ⊆ v := exists_Ioc_subset_of_mem_nhds (v_open.mem_nhds xv) hx₂, filter_upwards [hf z₁ z₁lt, hg z₂ z₂lt], assume z h₁z h₂z, have A1 : min (f z) (f x) ∈ u, { by_cases H : f z ≤ f x, { simp [H], exact h₁ ⟨h₁z, H⟩ }, { simp [le_of_not_le H], exact h₁ ⟨z₁lt, le_refl _⟩, } }, have A2 : min (g z) (g x) ∈ v, { by_cases H : g z ≤ g x, { simp [H], exact h₂ ⟨h₂z, H⟩ }, { simp [le_of_not_le H], exact h₂ ⟨z₂lt, le_refl _⟩, } }, have : (min (f z) (f x), min (g z) (g x)) ∈ u.prod v := ⟨A1, A2⟩, calc y < min (f z) (f x) + min (g z) (g x) : h this ... ≤ f z + g z : add_le_add (min_le_left _ _) (min_le_left _ _) }, { simp only [not_exists, not_lt] at hx₂, filter_upwards [hf z₁ z₁lt], assume z h₁z, have A1 : min (f z) (f x) ∈ u, { by_cases H : f z ≤ f x, { simp [H], exact h₁ ⟨h₁z, H⟩ }, { simp [le_of_not_le H], exact h₁ ⟨z₁lt, le_refl _⟩, } }, have : (min (f z) (f x), g x) ∈ u.prod v := ⟨A1, xv⟩, calc y < min (f z) (f x) + g x : h this ... ≤ f z + g z : add_le_add (min_le_left _ _) (hx₂ (g z)) } }, { simp only [not_exists, not_lt] at hx₁, by_cases hx₂ : ∃ l, l < g x, { obtain ⟨z₂, z₂lt, h₂⟩ : ∃ z₂ < g x, Ioc z₂ (g x) ⊆ v := exists_Ioc_subset_of_mem_nhds (v_open.mem_nhds xv) hx₂, filter_upwards [hg z₂ z₂lt], assume z h₂z, have A2 : min (g z) (g x) ∈ v, { by_cases H : g z ≤ g x, { simp [H], exact h₂ ⟨h₂z, H⟩ }, { simp [le_of_not_le H], exact h₂ ⟨z₂lt, le_refl _⟩, } }, have : (f x, min (g z) (g x)) ∈ u.prod v := ⟨xu, A2⟩, calc y < f x + min (g z) (g x) : h this ... ≤ f z + g z : add_le_add (hx₁ (f z)) (min_le_left _ _) }, { simp only [not_exists, not_lt] at hx₁ hx₂, apply filter.eventually_of_forall, assume z, have : (f x, g x) ∈ u.prod v := ⟨xu, xv⟩, calc y < f x + g x : h this ... ≤ f z + g z : add_le_add (hx₁ (f z)) (hx₂ (g z)) } }, end /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `ereal`. The unprimed version of the lemma uses `[has_continuous_add]`. -/ lemma lower_semicontinuous_at.add' {f g : α → γ} (hf : lower_semicontinuous_at f x) (hg : lower_semicontinuous_at g x) (hcont : continuous_at (λ (p : γ × γ), p.1 + p.2) (f x, g x)) : lower_semicontinuous_at (λ z, f z + g z) x := by { simp_rw [← lower_semicontinuous_within_at_univ_iff] at *, exact hf.add' hg hcont } /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `ereal`. The unprimed version of the lemma uses `[has_continuous_add]`. -/ lemma lower_semicontinuous_on.add' {f g : α → γ} (hf : lower_semicontinuous_on f s) (hg : lower_semicontinuous_on g s) (hcont : ∀ x ∈ s, continuous_at (λ (p : γ × γ), p.1 + p.2) (f x, g x)) : lower_semicontinuous_on (λ z, f z + g z) s := λ x hx, (hf x hx).add' (hg x hx) (hcont x hx) /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `ereal`. The unprimed version of the lemma uses `[has_continuous_add]`. -/ lemma lower_semicontinuous.add' {f g : α → γ} (hf : lower_semicontinuous f) (hg : lower_semicontinuous g) (hcont : ∀ x, continuous_at (λ (p : γ × γ), p.1 + p.2) (f x, g x)) : lower_semicontinuous (λ z, f z + g z) := λ x, (hf x).add' (hg x) (hcont x) variable [has_continuous_add γ] /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with `[has_continuous_add]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `ereal`. -/ lemma lower_semicontinuous_within_at.add {f g : α → γ} (hf : lower_semicontinuous_within_at f s x) (hg : lower_semicontinuous_within_at g s x) : lower_semicontinuous_within_at (λ z, f z + g z) s x := hf.add' hg continuous_add.continuous_at /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with `[has_continuous_add]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `ereal`. -/ lemma lower_semicontinuous_at.add {f g : α → γ} (hf : lower_semicontinuous_at f x) (hg : lower_semicontinuous_at g x) : lower_semicontinuous_at (λ z, f z + g z) x := hf.add' hg continuous_add.continuous_at /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with `[has_continuous_add]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `ereal`. -/ lemma lower_semicontinuous_on.add {f g : α → γ} (hf : lower_semicontinuous_on f s) (hg : lower_semicontinuous_on g s) : lower_semicontinuous_on (λ z, f z + g z) s := hf.add' hg (λ x hx, continuous_add.continuous_at) /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with `[has_continuous_add]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `ereal`. -/ lemma lower_semicontinuous.add {f g : α → γ} (hf : lower_semicontinuous f) (hg : lower_semicontinuous g) : lower_semicontinuous (λ z, f z + g z) := hf.add' hg (λ x, continuous_add.continuous_at) lemma lower_semicontinuous_within_at_sum {f : ι → α → γ} {a : finset ι} (ha : ∀ i ∈ a, lower_semicontinuous_within_at (f i) s x) : lower_semicontinuous_within_at (λ z, (∑ i in a, f i z)) s x := begin classical, induction a using finset.induction_on with i a ia IH generalizing ha, { exact lower_semicontinuous_within_at_const }, { simp only [ia, finset.sum_insert, not_false_iff], exact lower_semicontinuous_within_at.add (ha _ (finset.mem_insert_self i a)) (IH (λ j ja, ha j (finset.mem_insert_of_mem ja))) } end lemma lower_semicontinuous_at_sum {f : ι → α → γ} {a : finset ι} (ha : ∀ i ∈ a, lower_semicontinuous_at (f i) x) : lower_semicontinuous_at (λ z, (∑ i in a, f i z)) x := begin simp_rw [← lower_semicontinuous_within_at_univ_iff] at *, exact lower_semicontinuous_within_at_sum ha end lemma lower_semicontinuous_on_sum {f : ι → α → γ} {a : finset ι} (ha : ∀ i ∈ a, lower_semicontinuous_on (f i) s) : lower_semicontinuous_on (λ z, (∑ i in a, f i z)) s := λ x hx, lower_semicontinuous_within_at_sum (λ i hi, ha i hi x hx) lemma lower_semicontinuous_sum {f : ι → α → γ} {a : finset ι} (ha : ∀ i ∈ a, lower_semicontinuous (f i)) : lower_semicontinuous (λ z, (∑ i in a, f i z)) := λ x, lower_semicontinuous_at_sum (λ i hi, ha i hi x) end /-! #### Supremum -/ section variables {ι : Sort*} {δ : Type*} [complete_linear_order δ] lemma lower_semicontinuous_within_at_supr {f : ι → α → δ} (h : ∀ i, lower_semicontinuous_within_at (f i) s x) : lower_semicontinuous_within_at (λ x', ⨆ i, f i x') s x := begin assume y hy, rcases lt_supr_iff.1 hy with ⟨i, hi⟩, filter_upwards [h i y hi], assume x' hx', exact lt_supr_iff.2 ⟨i, hx'⟩, end lemma lower_semicontinuous_within_at_bsupr {p : ι → Prop} {f : Π i (h : p i), α → δ} (h : ∀ i hi, lower_semicontinuous_within_at (f i hi) s x) : lower_semicontinuous_within_at (λ x', ⨆ i hi, f i hi x') s x := lower_semicontinuous_within_at_supr $ λ i, lower_semicontinuous_within_at_supr $ λ hi, h i hi lemma lower_semicontinuous_at_supr {f : ι → α → δ} (h : ∀ i, lower_semicontinuous_at (f i) x) : lower_semicontinuous_at (λ x', ⨆ i, f i x') x := begin simp_rw [← lower_semicontinuous_within_at_univ_iff] at *, exact lower_semicontinuous_within_at_supr h end lemma lower_semicontinuous_at_bsupr {p : ι → Prop} {f : Π i (h : p i), α → δ} (h : ∀ i hi, lower_semicontinuous_at (f i hi) x) : lower_semicontinuous_at (λ x', ⨆ i hi, f i hi x') x := lower_semicontinuous_at_supr $ λ i, lower_semicontinuous_at_supr $ λ hi, h i hi lemma lower_semicontinuous_on_supr {f : ι → α → δ} (h : ∀ i, lower_semicontinuous_on (f i) s) : lower_semicontinuous_on (λ x', ⨆ i, f i x') s := λ x hx, lower_semicontinuous_within_at_supr (λ i, h i x hx) lemma lower_semicontinuous_on_bsupr {p : ι → Prop} {f : Π i (h : p i), α → δ} (h : ∀ i hi, lower_semicontinuous_on (f i hi) s) : lower_semicontinuous_on (λ x', ⨆ i hi, f i hi x') s := lower_semicontinuous_on_supr $ λ i, lower_semicontinuous_on_supr $ λ hi, h i hi lemma lower_semicontinuous_supr {f : ι → α → δ} (h : ∀ i, lower_semicontinuous (f i)) : lower_semicontinuous (λ x', ⨆ i, f i x') := λ x, lower_semicontinuous_at_supr (λ i, h i x) lemma lower_semicontinuous_bsupr {p : ι → Prop} {f : Π i (h : p i), α → δ} (h : ∀ i hi, lower_semicontinuous (f i hi)) : lower_semicontinuous (λ x', ⨆ i hi, f i hi x') := lower_semicontinuous_supr $ λ i, lower_semicontinuous_supr $ λ hi, h i hi end /-! #### Infinite sums -/ section variables {ι : Type*} lemma lower_semicontinuous_within_at_tsum {f : ι → α → ℝ≥0∞} (h : ∀ i, lower_semicontinuous_within_at (f i) s x) : lower_semicontinuous_within_at (λ x', ∑' i, f i x') s x := begin simp_rw ennreal.tsum_eq_supr_sum, apply lower_semicontinuous_within_at_supr (λ b, _), exact lower_semicontinuous_within_at_sum (λ i hi, h i), end lemma lower_semicontinuous_at_tsum {f : ι → α → ℝ≥0∞} (h : ∀ i, lower_semicontinuous_at (f i) x) : lower_semicontinuous_at (λ x', ∑' i, f i x') x := begin simp_rw [← lower_semicontinuous_within_at_univ_iff] at *, exact lower_semicontinuous_within_at_tsum h end lemma lower_semicontinuous_on_tsum {f : ι → α → ℝ≥0∞} (h : ∀ i, lower_semicontinuous_on (f i) s) : lower_semicontinuous_on (λ x', ∑' i, f i x') s := λ x hx, lower_semicontinuous_within_at_tsum (λ i, h i x hx) lemma lower_semicontinuous_tsum {f : ι → α → ℝ≥0∞} (h : ∀ i, lower_semicontinuous (f i)) : lower_semicontinuous (λ x', ∑' i, f i x') := λ x, lower_semicontinuous_at_tsum (λ i, h i x) end /-! ### Upper semicontinuous functions -/ /-! #### Basic dot notation interface for upper semicontinuity -/ lemma upper_semicontinuous_within_at.mono (h : upper_semicontinuous_within_at f s x) (hst : t ⊆ s) : upper_semicontinuous_within_at f t x := λ y hy, filter.eventually.filter_mono (nhds_within_mono _ hst) (h y hy) lemma upper_semicontinuous_within_at_univ_iff : upper_semicontinuous_within_at f univ x ↔ upper_semicontinuous_at f x := by simp [upper_semicontinuous_within_at, upper_semicontinuous_at, nhds_within_univ] lemma upper_semicontinuous_at.upper_semicontinuous_within_at (s : set α) (h : upper_semicontinuous_at f x) : upper_semicontinuous_within_at f s x := λ y hy, filter.eventually.filter_mono nhds_within_le_nhds (h y hy) lemma upper_semicontinuous_on.upper_semicontinuous_within_at (h : upper_semicontinuous_on f s) (hx : x ∈ s) : upper_semicontinuous_within_at f s x := h x hx lemma upper_semicontinuous_on.mono (h : upper_semicontinuous_on f s) (hst : t ⊆ s) : upper_semicontinuous_on f t := λ x hx, (h x (hst hx)).mono hst lemma upper_semicontinuous_on_univ_iff : upper_semicontinuous_on f univ ↔ upper_semicontinuous f := by simp [upper_semicontinuous_on, upper_semicontinuous, upper_semicontinuous_within_at_univ_iff] lemma upper_semicontinuous.upper_semicontinuous_at (h : upper_semicontinuous f) (x : α) : upper_semicontinuous_at f x := h x lemma upper_semicontinuous.upper_semicontinuous_within_at (h : upper_semicontinuous f) (s : set α) (x : α) : upper_semicontinuous_within_at f s x := (h x).upper_semicontinuous_within_at s lemma upper_semicontinuous.upper_semicontinuous_on (h : upper_semicontinuous f) (s : set α) : upper_semicontinuous_on f s := λ x hx, h.upper_semicontinuous_within_at s x /-! #### Constants -/ lemma upper_semicontinuous_within_at_const : upper_semicontinuous_within_at (λ x, z) s x := λ y hy, filter.eventually_of_forall (λ x, hy) lemma upper_semicontinuous_at_const : upper_semicontinuous_at (λ x, z) x := λ y hy, filter.eventually_of_forall (λ x, hy) lemma upper_semicontinuous_on_const : upper_semicontinuous_on (λ x, z) s := λ x hx, upper_semicontinuous_within_at_const lemma upper_semicontinuous_const : upper_semicontinuous (λ (x : α), z) := λ x, upper_semicontinuous_at_const /-! #### Indicators -/ section variables [has_zero β] lemma is_open.upper_semicontinuous_indicator (hs : is_open s) (hy : y ≤ 0) : upper_semicontinuous (indicator s (λ x, y)) := @is_open.lower_semicontinuous_indicator α _ (order_dual β) _ s y _ hs hy lemma is_open.upper_semicontinuous_on_indicator (hs : is_open s) (hy : y ≤ 0) : upper_semicontinuous_on (indicator s (λ x, y)) t := (hs.upper_semicontinuous_indicator hy).upper_semicontinuous_on t lemma is_open.upper_semicontinuous_at_indicator (hs : is_open s) (hy : y ≤ 0) : upper_semicontinuous_at (indicator s (λ x, y)) x := (hs.upper_semicontinuous_indicator hy).upper_semicontinuous_at x lemma is_open.upper_semicontinuous_within_at_indicator (hs : is_open s) (hy : y ≤ 0) : upper_semicontinuous_within_at (indicator s (λ x, y)) t x := (hs.upper_semicontinuous_indicator hy).upper_semicontinuous_within_at t x lemma is_closed.upper_semicontinuous_indicator (hs : is_closed s) (hy : 0 ≤ y) : upper_semicontinuous (indicator s (λ x, y)) := @is_closed.lower_semicontinuous_indicator α _ (order_dual β) _ s y _ hs hy lemma is_closed.upper_semicontinuous_on_indicator (hs : is_closed s) (hy : 0 ≤ y) : upper_semicontinuous_on (indicator s (λ x, y)) t := (hs.upper_semicontinuous_indicator hy).upper_semicontinuous_on t lemma is_closed.upper_semicontinuous_at_indicator (hs : is_closed s) (hy : 0 ≤ y) : upper_semicontinuous_at (indicator s (λ x, y)) x := (hs.upper_semicontinuous_indicator hy).upper_semicontinuous_at x lemma is_closed.upper_semicontinuous_within_at_indicator (hs : is_closed s) (hy : 0 ≤ y) : upper_semicontinuous_within_at (indicator s (λ x, y)) t x := (hs.upper_semicontinuous_indicator hy).upper_semicontinuous_within_at t x end /-! #### Relationship with continuity -/ theorem upper_semicontinuous_iff_is_open : upper_semicontinuous f ↔ ∀ y, is_open (f ⁻¹' (Iio y)) := ⟨λ H y, is_open_iff_mem_nhds.2 (λ x hx, H x y hx), λ H x y y_lt, is_open.mem_nhds (H y) y_lt⟩ lemma upper_semicontinuous.is_open_preimage (hf : upper_semicontinuous f) (y : β) : is_open (f ⁻¹' (Iio y)) := upper_semicontinuous_iff_is_open.1 hf y section variables {γ : Type*} [linear_order γ] [topological_space γ] [order_topology γ] lemma continuous_within_at.upper_semicontinuous_within_at {f : α → γ} (h : continuous_within_at f s x) : upper_semicontinuous_within_at f s x := λ y hy, h (Iio_mem_nhds hy) lemma continuous_at.upper_semicontinuous_at {f : α → γ} (h : continuous_at f x) : upper_semicontinuous_at f x := λ y hy, h (Iio_mem_nhds hy) lemma continuous_on.upper_semicontinuous_on {f : α → γ} (h : continuous_on f s) : upper_semicontinuous_on f s := λ x hx, (h x hx).upper_semicontinuous_within_at lemma continuous.upper_semicontinuous {f : α → γ} (h : continuous f) : upper_semicontinuous f := λ x, h.continuous_at.upper_semicontinuous_at end /-! ### Composition -/ section variables {γ : Type*} [linear_order γ] [topological_space γ] [order_topology γ] variables {δ : Type*} [linear_order δ] [topological_space δ] [order_topology δ] lemma continuous_at.comp_upper_semicontinuous_within_at {g : γ → δ} {f : α → γ} (hg : continuous_at g (f x)) (hf : upper_semicontinuous_within_at f s x) (gmon : monotone g) : upper_semicontinuous_within_at (g ∘ f) s x := @continuous_at.comp_lower_semicontinuous_within_at α _ x s (order_dual γ) _ _ _ (order_dual δ) _ _ _ g f hg hf (λ x y hxy, gmon hxy) lemma continuous_at.comp_upper_semicontinuous_at {g : γ → δ} {f : α → γ} (hg : continuous_at g (f x)) (hf : upper_semicontinuous_at f x) (gmon : monotone g) : upper_semicontinuous_at (g ∘ f) x := @continuous_at.comp_lower_semicontinuous_at α _ x (order_dual γ) _ _ _ (order_dual δ) _ _ _ g f hg hf (λ x y hxy, gmon hxy) lemma continuous.comp_upper_semicontinuous_on {g : γ → δ} {f : α → γ} (hg : continuous g) (hf : upper_semicontinuous_on f s) (gmon : monotone g) : upper_semicontinuous_on (g ∘ f) s := λ x hx, (hg.continuous_at).comp_upper_semicontinuous_within_at (hf x hx) gmon lemma continuous.comp_upper_semicontinuous {g : γ → δ} {f : α → γ} (hg : continuous g) (hf : upper_semicontinuous f) (gmon : monotone g) : upper_semicontinuous (g ∘ f) := λ x, (hg.continuous_at).comp_upper_semicontinuous_at (hf x) gmon lemma continuous_at.comp_upper_semicontinuous_within_at_antitone {g : γ → δ} {f : α → γ} (hg : continuous_at g (f x)) (hf : upper_semicontinuous_within_at f s x) (gmon : antitone g) : lower_semicontinuous_within_at (g ∘ f) s x := @continuous_at.comp_upper_semicontinuous_within_at α _ x s γ _ _ _ (order_dual δ) _ _ _ g f hg hf gmon lemma continuous_at.comp_upper_semicontinuous_at_antitone {g : γ → δ} {f : α → γ} (hg : continuous_at g (f x)) (hf : upper_semicontinuous_at f x) (gmon : antitone g) : lower_semicontinuous_at (g ∘ f) x := @continuous_at.comp_upper_semicontinuous_at α _ x γ _ _ _ (order_dual δ) _ _ _ g f hg hf gmon lemma continuous.comp_upper_semicontinuous_on_antitone {g : γ → δ} {f : α → γ} (hg : continuous g) (hf : upper_semicontinuous_on f s) (gmon : antitone g) : lower_semicontinuous_on (g ∘ f) s := λ x hx, (hg.continuous_at).comp_upper_semicontinuous_within_at_antitone (hf x hx) gmon lemma continuous.comp_upper_semicontinuous_antitone {g : γ → δ} {f : α → γ} (hg : continuous g) (hf : upper_semicontinuous f) (gmon : antitone g) : lower_semicontinuous (g ∘ f) := λ x, (hg.continuous_at).comp_upper_semicontinuous_at_antitone (hf x) gmon end /-! #### Addition -/ section variables {ι : Type*} {γ : Type*} [linear_ordered_add_comm_monoid γ] [topological_space γ] [order_topology γ] /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `ereal`. The unprimed version of the lemma uses `[has_continuous_add]`. -/ lemma upper_semicontinuous_within_at.add' {f g : α → γ} (hf : upper_semicontinuous_within_at f s x) (hg : upper_semicontinuous_within_at g s x) (hcont : continuous_at (λ (p : γ × γ), p.1 + p.2) (f x, g x)) : upper_semicontinuous_within_at (λ z, f z + g z) s x := @lower_semicontinuous_within_at.add' α _ x s (order_dual γ) _ _ _ _ _ hf hg hcont /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `ereal`. The unprimed version of the lemma uses `[has_continuous_add]`. -/ lemma upper_semicontinuous_at.add' {f g : α → γ} (hf : upper_semicontinuous_at f x) (hg : upper_semicontinuous_at g x) (hcont : continuous_at (λ (p : γ × γ), p.1 + p.2) (f x, g x)) : upper_semicontinuous_at (λ z, f z + g z) x := by { simp_rw [← upper_semicontinuous_within_at_univ_iff] at *, exact hf.add' hg hcont } /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `ereal`. The unprimed version of the lemma uses `[has_continuous_add]`. -/ lemma upper_semicontinuous_on.add' {f g : α → γ} (hf : upper_semicontinuous_on f s) (hg : upper_semicontinuous_on g s) (hcont : ∀ x ∈ s, continuous_at (λ (p : γ × γ), p.1 + p.2) (f x, g x)) : upper_semicontinuous_on (λ z, f z + g z) s := λ x hx, (hf x hx).add' (hg x hx) (hcont x hx) /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `ereal`. The unprimed version of the lemma uses `[has_continuous_add]`. -/ lemma upper_semicontinuous.add' {f g : α → γ} (hf : upper_semicontinuous f) (hg : upper_semicontinuous g) (hcont : ∀ x, continuous_at (λ (p : γ × γ), p.1 + p.2) (f x, g x)) : upper_semicontinuous (λ z, f z + g z) := λ x, (hf x).add' (hg x) (hcont x) variable [has_continuous_add γ] /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with `[has_continuous_add]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `ereal`. -/ lemma upper_semicontinuous_within_at.add {f g : α → γ} (hf : upper_semicontinuous_within_at f s x) (hg : upper_semicontinuous_within_at g s x) : upper_semicontinuous_within_at (λ z, f z + g z) s x := hf.add' hg continuous_add.continuous_at /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with `[has_continuous_add]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `ereal`. -/ lemma upper_semicontinuous_at.add {f g : α → γ} (hf : upper_semicontinuous_at f x) (hg : upper_semicontinuous_at g x) : upper_semicontinuous_at (λ z, f z + g z) x := hf.add' hg continuous_add.continuous_at /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with `[has_continuous_add]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `ereal`. -/ lemma upper_semicontinuous_on.add {f g : α → γ} (hf : upper_semicontinuous_on f s) (hg : upper_semicontinuous_on g s) : upper_semicontinuous_on (λ z, f z + g z) s := hf.add' hg (λ x hx, continuous_add.continuous_at) /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with `[has_continuous_add]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `ereal`. -/ lemma upper_semicontinuous.add {f g : α → γ} (hf : upper_semicontinuous f) (hg : upper_semicontinuous g) : upper_semicontinuous (λ z, f z + g z) := hf.add' hg (λ x, continuous_add.continuous_at) lemma upper_semicontinuous_within_at_sum {f : ι → α → γ} {a : finset ι} (ha : ∀ i ∈ a, upper_semicontinuous_within_at (f i) s x) : upper_semicontinuous_within_at (λ z, (∑ i in a, f i z)) s x := @lower_semicontinuous_within_at_sum α _ x s ι (order_dual γ) _ _ _ _ f a ha lemma upper_semicontinuous_at_sum {f : ι → α → γ} {a : finset ι} (ha : ∀ i ∈ a, upper_semicontinuous_at (f i) x) : upper_semicontinuous_at (λ z, (∑ i in a, f i z)) x := begin simp_rw [← upper_semicontinuous_within_at_univ_iff] at *, exact upper_semicontinuous_within_at_sum ha end lemma upper_semicontinuous_on_sum {f : ι → α → γ} {a : finset ι} (ha : ∀ i ∈ a, upper_semicontinuous_on (f i) s) : upper_semicontinuous_on (λ z, (∑ i in a, f i z)) s := λ x hx, upper_semicontinuous_within_at_sum (λ i hi, ha i hi x hx) lemma upper_semicontinuous_sum {f : ι → α → γ} {a : finset ι} (ha : ∀ i ∈ a, upper_semicontinuous (f i)) : upper_semicontinuous (λ z, (∑ i in a, f i z)) := λ x, upper_semicontinuous_at_sum (λ i hi, ha i hi x) end /-! #### Infimum -/ section variables {ι : Sort*} {δ : Type*} [complete_linear_order δ] lemma upper_semicontinuous_within_at_infi {f : ι → α → δ} (h : ∀ i, upper_semicontinuous_within_at (f i) s x) : upper_semicontinuous_within_at (λ x', ⨅ i, f i x') s x := @lower_semicontinuous_within_at_supr α _ x s ι (order_dual δ) _ f h lemma upper_semicontinuous_within_at_binfi {p : ι → Prop} {f : Π i (h : p i), α → δ} (h : ∀ i hi, upper_semicontinuous_within_at (f i hi) s x) : upper_semicontinuous_within_at (λ x', ⨅ i hi, f i hi x') s x := upper_semicontinuous_within_at_infi $ λ i, upper_semicontinuous_within_at_infi $ λ hi, h i hi lemma upper_semicontinuous_at_infi {f : ι → α → δ} (h : ∀ i, upper_semicontinuous_at (f i) x) : upper_semicontinuous_at (λ x', ⨅ i, f i x') x := @lower_semicontinuous_at_supr α _ x ι (order_dual δ) _ f h lemma upper_semicontinuous_at_binfi {p : ι → Prop} {f : Π i (h : p i), α → δ} (h : ∀ i hi, upper_semicontinuous_at (f i hi) x) : upper_semicontinuous_at (λ x', ⨅ i hi, f i hi x') x := upper_semicontinuous_at_infi $ λ i, upper_semicontinuous_at_infi $ λ hi, h i hi lemma upper_semicontinuous_on_infi {f : ι → α → δ} (h : ∀ i, upper_semicontinuous_on (f i) s) : upper_semicontinuous_on (λ x', ⨅ i, f i x') s := λ x hx, upper_semicontinuous_within_at_infi (λ i, h i x hx) lemma upper_semicontinuous_on_binfi {p : ι → Prop} {f : Π i (h : p i), α → δ} (h : ∀ i hi, upper_semicontinuous_on (f i hi) s) : upper_semicontinuous_on (λ x', ⨅ i hi, f i hi x') s := upper_semicontinuous_on_infi $ λ i, upper_semicontinuous_on_infi $ λ hi, h i hi lemma upper_semicontinuous_infi {f : ι → α → δ} (h : ∀ i, upper_semicontinuous (f i)) : upper_semicontinuous (λ x', ⨅ i, f i x') := λ x, upper_semicontinuous_at_infi (λ i, h i x) lemma upper_semicontinuous_binfi {p : ι → Prop} {f : Π i (h : p i), α → δ} (h : ∀ i hi, upper_semicontinuous (f i hi)) : upper_semicontinuous (λ x', ⨅ i hi, f i hi x') := upper_semicontinuous_infi $ λ i, upper_semicontinuous_infi $ λ hi, h i hi end section variables {γ : Type*} [linear_order γ] [topological_space γ] [order_topology γ] lemma continuous_within_at_iff_lower_upper_semicontinuous_within_at {f : α → γ} : continuous_within_at f s x ↔ lower_semicontinuous_within_at f s x ∧ upper_semicontinuous_within_at f s x:= begin refine ⟨λ h, ⟨h.lower_semicontinuous_within_at, h.upper_semicontinuous_within_at⟩, _⟩, rintros ⟨h₁, h₂⟩, assume v hv, simp only [filter.mem_map], by_cases Hl : ∃ l, l < f x, { rcases exists_Ioc_subset_of_mem_nhds hv Hl with ⟨l, lfx, hl⟩, by_cases Hu : ∃ u, f x < u, { rcases exists_Ico_subset_of_mem_nhds hv Hu with ⟨u, fxu, hu⟩, filter_upwards [h₁ l lfx, h₂ u fxu], assume a lfa fau, cases le_or_gt (f a) (f x) with h h, { exact hl ⟨lfa, h⟩ }, { exact hu ⟨le_of_lt h, fau⟩ } }, { simp only [not_exists, not_lt] at Hu, filter_upwards [h₁ l lfx], assume a lfa, exact hl ⟨lfa, Hu (f a)⟩ } }, { simp only [not_exists, not_lt] at Hl, by_cases Hu : ∃ u, f x < u, { rcases exists_Ico_subset_of_mem_nhds hv Hu with ⟨u, fxu, hu⟩, filter_upwards [h₂ u fxu], assume a lfa, apply hu, exact ⟨Hl (f a), lfa⟩ }, { simp only [not_exists, not_lt] at Hu, apply filter.eventually_of_forall, assume a, have : f a = f x := le_antisymm (Hu _) (Hl _), rw this, exact mem_of_mem_nhds hv } } end lemma continuous_at_iff_lower_upper_semicontinuous_at {f : α → γ} : continuous_at f x ↔ (lower_semicontinuous_at f x ∧ upper_semicontinuous_at f x) := by simp_rw [← continuous_within_at_univ, ← lower_semicontinuous_within_at_univ_iff, ← upper_semicontinuous_within_at_univ_iff, continuous_within_at_iff_lower_upper_semicontinuous_within_at] lemma continuous_on_iff_lower_upper_semicontinuous_on {f : α → γ} : continuous_on f s ↔ (lower_semicontinuous_on f s ∧ upper_semicontinuous_on f s) := begin simp only [continuous_on, continuous_within_at_iff_lower_upper_semicontinuous_within_at], exact ⟨λ H, ⟨λ x hx, (H x hx).1, λ x hx, (H x hx).2⟩, λ H x hx, ⟨H.1 x hx, H.2 x hx⟩⟩ end lemma continuous_iff_lower_upper_semicontinuous {f : α → γ} : continuous f ↔ (lower_semicontinuous f ∧ upper_semicontinuous f) := by simp_rw [continuous_iff_continuous_on_univ, continuous_on_iff_lower_upper_semicontinuous_on, lower_semicontinuous_on_univ_iff, upper_semicontinuous_on_univ_iff] end
9c387fbd3aa2c45b0ed9a47c7aadd14a16ffc644
77c5b91fae1b966ddd1db969ba37b6f0e4901e88
/src/ring_theory/henselian.lean
4136ed06e7e2e595cf6c53b8e895127981739f07
[ "Apache-2.0" ]
permissive
dexmagic/mathlib
ff48eefc56e2412429b31d4fddd41a976eb287ce
7a5d15a955a92a90e1d398b2281916b9c41270b2
refs/heads/master
1,693,481,322,046
1,633,360,193,000
1,633,360,193,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
11,821
lean
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import data.polynomial.taylor import ring_theory.ideal.local_ring import linear_algebra.adic_completion /-! # Henselian rings In this file we set up the basic theory of Henselian (local) rings. A ring `R` is *Henselian* at an ideal `I` if the following conditions hold: * `I` is contained in the Jacobson radical of `R` * for every polynomial `f` over `R`, with a *simple* root `a₀` over the quotient ring `R/I`, there exists a lift `a : R` of `a₀` that is a root of `f`. (Here, saying that a root `b` of a polynomial `g` is *simple* means that `g.derivative.eval b` is a unit. Warning: if `R/I` is not a field then it is not enough to assume that `g` has a factorization into monic linear factors in which `X - b` shows up only once; for example `1` is not a simple root of `X^2-1` over `ℤ/4ℤ`.) A local ring `R` is *Henselian* if it is Henselian at its maximal ideal. In this case the first condition is automatic, and in the second condition we may ask for `f.derivative.eval a ≠ 0`, since the quotient ring `R/I` is a field in this case. ## Main declarations * `henselian_ring`: a typeclass on commutative rings, asserting that the ring is Henselian at the ideal `I`. * `henselian_local_ring`: a typeclass on commutative rings, asserting that the ring is local Henselian. * `field.henselian`: fields are Henselian local rings * `henselian.tfae`: equivalent ways of expressing the Henselian property for local rings * `is_adic_complete.henselian`: a ring `R` with ideal `I` that is `I`-adically complete is Henselian at `I` ## References https://stacks.math.columbia.edu/tag/04GE ## Todo After a good API for etale ring homomorphisms has been developed, we can give more equivalent characterization os Henselian rings. In particular, this can give a proof that factorizations into coprime polynomials can be lifted from the residue field to the Henselian ring. The following gist contains some code sketches in that direction. https://gist.github.com/jcommelin/47d94e4af092641017a97f7f02bf9598 -/ noncomputable theory universe variables u v open_locale big_operators open local_ring polynomial function lemma is_local_ring_hom_of_le_jacobson_bot {R : Type*} [comm_ring R] (I : ideal R) (h : I ≤ ideal.jacobson ⊥) : is_local_ring_hom (ideal.quotient.mk I) := begin constructor, intros a h, have : is_unit (ideal.quotient.mk (ideal.jacobson ⊥) a), { rw [is_unit_iff_exists_inv] at *, obtain ⟨b, hb⟩ := h, obtain ⟨b, rfl⟩ := ideal.quotient.mk_surjective b, use ideal.quotient.mk _ b, rw [←(ideal.quotient.mk _).map_one, ←(ideal.quotient.mk _).map_mul, ideal.quotient.eq] at ⊢ hb, exact h hb }, obtain ⟨⟨x, y, h1, h2⟩, rfl : x = _⟩ := this, obtain ⟨y, rfl⟩ := ideal.quotient.mk_surjective y, rw [← (ideal.quotient.mk _).map_mul, ← (ideal.quotient.mk _).map_one, ideal.quotient.eq, ideal.mem_jacobson_bot] at h1 h2, specialize h1 1, simp at h1, exact h1.1, end /-- A ring `R` is *Henselian* at an ideal `I` if the following condition holds: for every polynomial `f` over `R`, with a *simple* root `a₀` over the quotient ring `R/I`, there exists a lift `a : R` of `a₀` that is a root of `f`. (Here, saying that a root `b` of a polynomial `g` is *simple* means that `g.derivative.eval b` is a unit. Warning: if `R/I` is not a field then it is not enough to assume that `g` has a factorization into monic linear factors in which `X - b` shows up only once; for example `1` is not a simple root of `X^2-1` over `ℤ/4ℤ`.) -/ class henselian_ring (R : Type*) [comm_ring R] (I : ideal R) : Prop := (jac : I ≤ ideal.jacobson ⊥) (is_henselian : ∀ (f : polynomial R) (hf : f.monic) (a₀ : R) (h₁ : f.eval a₀ ∈ I) (h₂ : is_unit (ideal.quotient.mk I (f.derivative.eval a₀))), ∃ a : R, f.is_root a ∧ (a - a₀ ∈ I)) /-- A local ring `R` is *Henselian* if the following condition holds: for every polynomial `f` over `R`, with a *simple* root `a₀` over the residue field, there exists a lift `a : R` of `a₀` that is a root of `f`. (Recall that a root `b` of a polynomial `g` is *simple* if it is not a double root, so if `g.derivative.eval b ≠ 0`.) In other words, `R` is local Henselian if it is Henselian at the ideal `I`, in the sense of `henselian_ring`. -/ class henselian_local_ring (R : Type*) [comm_ring R] extends local_ring R : Prop := (is_henselian : ∀ (f : polynomial R) (hf : f.monic) (a₀ : R) (h₁ : f.eval a₀ ∈ maximal_ideal R) (h₂ : is_unit (f.derivative.eval a₀)), ∃ a : R, f.is_root a ∧ (a - a₀ ∈ maximal_ideal R)) @[priority 100] -- see Note [lower instance priority] instance field.henselian (K : Type*) [field K] : henselian_local_ring K := { is_henselian := λ f hf a₀ h₁ h₂, begin refine ⟨a₀, _, _⟩; rwa [(maximal_ideal K).eq_bot_of_prime, ideal.mem_bot] at *, rw sub_self, end } lemma henselian_local_ring.tfae (R : Type u) [comm_ring R] [local_ring R] : tfae [ henselian_local_ring R, ∀ (f : polynomial R) (hf : f.monic) (a₀ : residue_field R) (h₁ : aeval a₀ f = 0) (h₂ : aeval a₀ f.derivative ≠ 0), ∃ a : R, f.is_root a ∧ (residue R a = a₀), ∀ {K : Type u} [field K], by exactI ∀ (φ : R →+* K) (hφ : surjective φ) (f : polynomial R) (hf : f.monic) (a₀ : K) (h₁ : f.eval₂ φ a₀ = 0) (h₂ : f.derivative.eval₂ φ a₀ ≠ 0), ∃ a : R, f.is_root a ∧ (φ a = a₀)] := begin tfae_have _3_2 : 3 → 2, { intro H, exact H (residue R) ideal.quotient.mk_surjective, }, tfae_have _2_1 : 2 → 1, { intros H, constructor, intros f hf a₀ h₁ h₂, specialize H f hf (residue R a₀), have aux := flip mem_nonunits_iff.mp h₂, simp only [aeval_def, ring_hom.algebra_map_to_algebra, eval₂_at_apply, ← ideal.quotient.eq_zero_iff_mem, ← local_ring.mem_maximal_ideal] at H h₁ aux, obtain ⟨a, ha₁, ha₂⟩ := H h₁ aux, refine ⟨a, ha₁, _⟩, rw ← ideal.quotient.eq_zero_iff_mem, rwa [← sub_eq_zero, ← ring_hom.map_sub] at ha₂, }, tfae_have _1_3 : 1 → 3, { introsI hR K _K φ hφ f hf a₀ h₁ h₂, obtain ⟨a₀, rfl⟩ := hφ a₀, have H := henselian_local_ring.is_henselian f hf a₀, simp only [← ker_eq_maximal_ideal φ hφ, eval₂_at_apply, φ.mem_ker] at H h₁ h₂, obtain ⟨a, ha₁, ha₂⟩ := H h₁ _, { refine ⟨a, ha₁, _⟩, rwa [φ.map_sub, sub_eq_zero] at ha₂, }, { contrapose! h₂, rwa [← mem_nonunits_iff, ← local_ring.mem_maximal_ideal, ← local_ring.ker_eq_maximal_ideal φ hφ, φ.mem_ker] at h₂, } }, tfae_finish, end instance (R : Type*) [comm_ring R] [hR : henselian_local_ring R] : henselian_ring R (maximal_ideal R) := { jac := by { rw [ideal.jacobson, le_Inf_iff], rintro I ⟨-, hI⟩, exact (eq_maximal_ideal hI).ge }, is_henselian := begin intros f hf a₀ h₁ h₂, refine henselian_local_ring.is_henselian f hf a₀ h₁ _, contrapose! h₂, rw [← mem_nonunits_iff, ← local_ring.mem_maximal_ideal, ← ideal.quotient.eq_zero_iff_mem] at h₂, rw h₂, exact not_is_unit_zero end } /-- A ring `R` that is `I`-adically complete is Henselian at `I`. -/ @[priority 100] -- see Note [lower instance priority] instance is_adic_complete.henselian_ring (R : Type*) [comm_ring R] (I : ideal R) [is_adic_complete I R] : henselian_ring R I := { jac := is_adic_complete.le_jacobson_bot _, is_henselian := begin intros f hf a₀ h₁ h₂, classical, let f' := f.derivative, -- we define a sequence `c n` by starting at `a₀` and then continually -- applying the function sending `b` to `b - f(b)/f'(b)` (Newton's method). -- Note that `f'.eval b` is a unit, because `b` has the same residue as `a₀` modulo `I`. let c : ℕ → R := λ n, nat.rec_on n a₀ (λ _ b, b - f.eval b * ring.inverse (f'.eval b)), have hc : ∀ n, c (n+1) = c n - f.eval (c n) * ring.inverse (f'.eval (c n)), { intro n, dsimp only [c, nat.rec_add_one], refl, }, -- we now spend some time determining properties of the sequence `c : ℕ → R` -- `hc_mod`: for every `n`, we have `c n ≡ a₀ [SMOD I]` -- `hf'c` : for every `n`, `f'.eval (c n)` is a unit -- `hfcI` : for every `n`, `f.eval (c n)` is contained in `I ^ (n+1)` have hc_mod : ∀ n, c n ≡ a₀ [SMOD I], { intro n, induction n with n ih, { refl }, rw [nat.succ_eq_add_one, hc, sub_eq_add_neg, ← add_zero a₀], refine ih.add _, rw [smodeq.zero, ideal.neg_mem_iff], refine I.mul_mem_right _ _, rw [← smodeq.zero] at h₁ ⊢, exact (ih.eval f).trans h₁, }, have hf'c : ∀ n, is_unit (f'.eval (c n)), { intro n, haveI := is_local_ring_hom_of_le_jacobson_bot I (is_adic_complete.le_jacobson_bot I), apply is_unit_of_map_unit (ideal.quotient.mk I), convert h₂ using 1, exact smodeq.def.mp ((hc_mod n).eval _), }, have hfcI : ∀ n, f.eval (c n) ∈ I ^ (n+1), { intro n, induction n with n ih, { simpa only [pow_one] }, simp only [nat.succ_eq_add_one], rw [← taylor_eval_sub (c n), hc], simp only [sub_eq_add_neg, add_neg_cancel_comm], rw [eval_eq_sum, sum_over_range' _ _ _ (lt_add_of_pos_right _ zero_lt_two), ← finset.sum_range_add_sum_Ico _ (nat.le_add_left _ _)], swap, { intro i, rw zero_mul }, refine ideal.add_mem _ _ _, { simp only [finset.sum_range_succ, taylor_coeff_one, mul_one, pow_one, taylor_coeff_zero, mul_neg_eq_neg_mul_symm, finset.sum_singleton, finset.range_one, pow_zero], rw [mul_left_comm, ring.mul_inverse_cancel _ (hf'c n), mul_one, add_neg_self], exact ideal.zero_mem _ }, { refine submodule.sum_mem _ _, simp only [finset.Ico.mem], rintro i ⟨h2i, hi⟩, have aux : n + 2 ≤ i * (n + 1), { transitivity 2 * (n + 1); nlinarith only [h2i], }, refine ideal.mul_mem_left _ _ (ideal.pow_le_pow aux _), rw [pow_mul'], refine ideal.pow_mem_pow ((ideal.neg_mem_iff _).2 $ ideal.mul_mem_right _ _ ih) _, } }, -- we are now in the position to show that `c : ℕ → R` is a Cauchy sequence have aux : ∀ m n, m ≤ n → c m ≡ c n [SMOD (I ^ m • ⊤ : ideal R)], { intros m n hmn, rw [← ideal.one_eq_top, algebra.id.smul_eq_mul, mul_one], obtain ⟨k, rfl⟩ := nat.exists_eq_add_of_le hmn, clear hmn, induction k with k ih, { rw add_zero, }, rw [nat.succ_eq_add_one, ← add_assoc, hc, ← add_zero (c m), sub_eq_add_neg], refine ih.add _, symmetry, rw [smodeq.zero, ideal.neg_mem_iff], refine ideal.mul_mem_right _ _ (ideal.pow_le_pow _ (hfcI _)), rw [add_assoc], exact le_self_add }, -- hence the sequence converges to some limit point `a`, which is the `a` we are looking for obtain ⟨a, ha⟩ := is_precomplete.prec' c aux, refine ⟨a, _, _⟩, { show f.is_root a, suffices : ∀ n, f.eval a ≡ 0 [SMOD (I ^ n • ⊤ : ideal R)], { from is_Hausdorff.haus' _ this }, intro n, specialize ha n, rw [← ideal.one_eq_top, algebra.id.smul_eq_mul, mul_one] at ha ⊢, refine (ha.symm.eval f).trans _, rw [smodeq.zero], exact ideal.pow_le_pow le_self_add (hfcI _), }, { show a - a₀ ∈ I, specialize ha 1, rw [hc, pow_one, ← ideal.one_eq_top, algebra.id.smul_eq_mul, mul_one, sub_eq_add_neg] at ha, rw [← smodeq.sub_mem, ← add_zero a₀], refine ha.symm.trans (smodeq.refl.add _), rw [smodeq.zero, ideal.neg_mem_iff], exact ideal.mul_mem_right _ _ h₁, } end }
8b12bcb8340b52a9f6a60c040833baa705ff4078
491068d2ad28831e7dade8d6dff871c3e49d9431
/library/data/equiv.lean
509d0ac7eba6a8dab4659264fd2602df49cabd23
[ "Apache-2.0" ]
permissive
davidmueller13/lean
65a3ed141b4088cd0a268e4de80eb6778b21a0e9
c626e2e3c6f3771e07c32e82ee5b9e030de5b050
refs/heads/master
1,611,278,313,401
1,444,021,177,000
1,444,021,177,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
16,469
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 In the standard library we cannot assume the univalence axiom. We say two types are equivalent if they are isomorphic. Two equivalent types have the same cardinality. -/ import data.sum data.nat open function structure equiv [class] (A B : Type) := (to_fun : A → B) (inv_fun : B → A) (left_inv : left_inverse inv_fun to_fun) (right_inv : right_inverse inv_fun to_fun) namespace equiv definition perm [reducible] (A : Type) := equiv A A infix ` ≃ `:50 := equiv definition fn {A B : Type} (e : equiv A B) : A → B := @equiv.to_fun A B e infixr ` ∙ `:100 := fn definition inv {A B : Type} [e : equiv A B] : B → A := @equiv.inv_fun A B e lemma eq_of_to_fun_eq {A B : Type} : ∀ {e₁ e₂ : equiv A B}, fn e₁ = fn e₂ → e₁ = e₂ | (mk f₁ g₁ l₁ r₁) (mk f₂ g₂ l₂ r₂) h := assert f₁ = f₂, from h, assert g₁ = g₂, from funext (λ x, assert f₁ (g₁ x) = f₂ (g₂ x), from eq.trans (r₁ x) (eq.symm (r₂ x)), have f₁ (g₁ x) = f₁ (g₂ x), by rewrite [-h at this]; exact this, show g₁ x = g₂ x, from injective_of_left_inverse l₁ this), by congruence; repeat assumption protected definition refl [refl] (A : Type) : A ≃ A := mk (@id A) (@id A) (λ x, rfl) (λ x, rfl) protected definition symm [symm] {A B : Type} : A ≃ B → B ≃ A | (mk f g h₁ h₂) := mk g f h₂ h₁ protected definition trans [trans] {A B C : Type} : A ≃ B → B ≃ C → A ≃ C | (mk f₁ g₁ l₁ r₁) (mk f₂ g₂ l₂ r₂) := mk (f₂ ∘ f₁) (g₁ ∘ g₂) (show ∀ x, g₁ (g₂ (f₂ (f₁ x))) = x, by intros; rewrite [l₂, l₁]; reflexivity) (show ∀ x, f₂ (f₁ (g₁ (g₂ x))) = x, by intros; rewrite [r₁, r₂]; reflexivity) abbreviation id {A : Type} := equiv.refl A namespace ops postfix ⁻¹ := equiv.symm postfix ⁻¹ := equiv.inv notation e₁ ∘ e₂ := equiv.trans e₂ e₁ end ops open equiv.ops lemma id_apply {A : Type} (x : A) : id ∙ x = x := rfl lemma compose_apply {A B C : Type} (g : B ≃ C) (f : A ≃ B) (x : A) : (g ∘ f) ∙ x = g ∙ f ∙ x := begin cases g, cases f, esimp end lemma inverse_apply_apply {A B : Type} : ∀ (e : A ≃ B) (x : A), e⁻¹ ∙ e ∙ x = x | (mk f₁ g₁ l₁ r₁) x := begin unfold [equiv.symm, fn], rewrite l₁ end lemma eq_iff_eq_of_injective {A B : Type} {f : A → B} (inj : injective f) (a b : A) : f a = f b ↔ a = b := iff.intro (suppose f a = f b, inj this) (suppose a = b, by rewrite this) lemma apply_eq_iff_eq {A B : Type} : ∀ (f : A ≃ B) (x y : A), f ∙ x = f ∙ y ↔ x = y | (mk f₁ g₁ l₁ r₁) x y := eq_iff_eq_of_injective (injective_of_left_inverse l₁) x y lemma apply_eq_iff_eq_inverse_apply {A B : Type} : ∀ (f : A ≃ B) (x : A) (y : B), f ∙ x = y ↔ x = f⁻¹ ∙ y | (mk f₁ g₁ l₁ r₁) x y := begin esimp, unfold [equiv.symm, fn], apply iff.intro, suppose f₁ x = y, by subst y; rewrite l₁, suppose x = g₁ y, by subst x; rewrite r₁ end definition false_equiv_empty : empty ≃ false := mk (λ e, empty.rec _ e) (λ h, false.rec _ h) (λ e, empty.rec _ e) (λ h, false.rec _ h) definition arrow_congr [congr] {A₁ B₁ A₂ B₂ : Type} : A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ → B₁) ≃ (A₂ → B₂) | (mk f₁ g₁ l₁ r₁) (mk f₂ g₂ l₂ r₂) := mk (λ (h : A₁ → B₁) (a : A₂), f₂ (h (g₁ a))) (λ (h : A₂ → B₂) (a : A₁), g₂ (h (f₁ a))) (λ h, funext (λ a, by rewrite [l₁, l₂]; reflexivity)) (λ h, funext (λ a, by rewrite [r₁, r₂]; reflexivity)) section open unit definition arrow_unit_equiv_unit [simp] (A : Type) : (A → unit) ≃ unit := mk (λ f, star) (λ u, (λ f, star)) (λ f, funext (λ x, by cases (f x); reflexivity)) (λ u, by cases u; reflexivity) definition unit_arrow_equiv [simp] (A : Type) : (unit → A) ≃ A := mk (λ f, f star) (λ a, (λ u, a)) (λ f, funext (λ x, by cases x; reflexivity)) (λ u, rfl) definition empty_arrow_equiv_unit [simp] (A : Type) : (empty → A) ≃ unit := mk (λ f, star) (λ u, λ e, empty.rec _ e) (λ f, funext (λ x, empty.rec _ x)) (λ u, by cases u; reflexivity) definition false_arrow_equiv_unit [simp] (A : Type) : (false → A) ≃ unit := calc (false → A) ≃ (empty → A) : arrow_congr false_equiv_empty !equiv.refl ... ≃ unit : empty_arrow_equiv_unit end definition prod_congr [congr] {A₁ B₁ A₂ B₂ : Type} : A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ × B₁) ≃ (A₂ × B₂) | (mk f₁ g₁ l₁ r₁) (mk f₂ g₂ l₂ r₂) := mk (λ p, match p with (a₁, b₁) := (f₁ a₁, f₂ b₁) end) (λ p, match p with (a₂, b₂) := (g₁ a₂, g₂ b₂) end) (λ p, begin cases p, esimp, rewrite [l₁, l₂], reflexivity end) (λ p, begin cases p, esimp, rewrite [r₁, r₂], reflexivity end) definition prod_comm [simp] (A B : Type) : (A × B) ≃ (B × A) := mk (λ p, match p with (a, b) := (b, a) end) (λ p, match p with (b, a) := (a, b) end) (λ p, begin cases p, esimp end) (λ p, begin cases p, esimp end) definition prod_assoc [simp] (A B C : Type) : ((A × B) × C) ≃ (A × (B × C)) := mk (λ t, match t with ((a, b), c) := (a, (b, c)) end) (λ t, match t with (a, (b, c)) := ((a, b), c) end) (λ t, begin cases t with ab c, cases ab, esimp end) (λ t, begin cases t with a bc, cases bc, esimp end) section open unit prod.ops definition prod_unit_right [simp] (A : Type) : (A × unit) ≃ A := mk (λ p, p.1) (λ a, (a, star)) (λ p, begin cases p with a u, cases u, esimp end) (λ a, rfl) definition prod_unit_left [simp] (A : Type) : (unit × A) ≃ A := calc (unit × A) ≃ (A × unit) : prod_comm ... ≃ A : prod_unit_right definition prod_empty_right [simp] (A : Type) : (A × empty) ≃ empty := mk (λ p, empty.rec _ p.2) (λ e, empty.rec _ e) (λ p, empty.rec _ p.2) (λ e, empty.rec _ e) definition prod_empty_left [simp] (A : Type) : (empty × A) ≃ empty := calc (empty × A) ≃ (A × empty) : prod_comm ... ≃ empty : prod_empty_right end section open sum definition sum_congr [congr] {A₁ B₁ A₂ B₂ : Type} : A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ + B₁) ≃ (A₂ + B₂) | (mk f₁ g₁ l₁ r₁) (mk f₂ g₂ l₂ r₂) := mk (λ s, match s with inl a₁ := inl (f₁ a₁) | inr b₁ := inr (f₂ b₁) end) (λ s, match s with inl a₂ := inl (g₁ a₂) | inr b₂ := inr (g₂ b₂) end) (λ s, begin cases s, {esimp, rewrite l₁, reflexivity}, {esimp, rewrite l₂, reflexivity} end) (λ s, begin cases s, {esimp, rewrite r₁, reflexivity}, {esimp, rewrite r₂, reflexivity} end) open bool unit definition bool_equiv_unit_sum_unit : bool ≃ (unit + unit) := mk (λ b, match b with tt := inl star | ff := inr star end) (λ s, match s with inl star := tt | inr star := ff end) (λ b, begin cases b, esimp, esimp end) (λ s, begin cases s with u u, {cases u, esimp}, {cases u, esimp} end) definition sum_comm [simp] (A B : Type) : (A + B) ≃ (B + A) := mk (λ s, match s with inl a := inr a | inr b := inl b end) (λ s, match s with inl b := inr b | inr a := inl a end) (λ s, begin cases s, esimp, esimp end) (λ s, begin cases s, esimp, esimp end) definition sum_assoc [simp] (A B C : Type) : ((A + B) + C) ≃ (A + (B + C)) := mk (λ s, match s with inl (inl a) := inl a | inl (inr b) := inr (inl b) | inr c := inr (inr c) end) (λ s, match s with inl a := inl (inl a) | inr (inl b) := inl (inr b) | inr (inr c) := inr c end) (λ s, begin cases s with ab c, cases ab, repeat esimp end) (λ s, begin cases s with a bc, esimp, cases bc, repeat esimp end) definition sum_empty_right [simp] (A : Type) : (A + empty) ≃ A := mk (λ s, match s with inl a := a | inr e := empty.rec _ e end) (λ a, inl a) (λ s, begin cases s with a e, esimp, exact empty.rec _ e end) (λ a, rfl) definition sum_empty_left [simp] (A : Type) : (empty + A) ≃ A := calc (empty + A) ≃ (A + empty) : sum_comm ... ≃ A : sum_empty_right end section open prod.ops definition arrow_prod_equiv_prod_arrow (A B C : Type) : (C → A × B) ≃ ((C → A) × (C → B)) := mk (λ f, (λ c, (f c).1, λ c, (f c).2)) (λ p, λ c, (p.1 c, p.2 c)) (λ f, funext (λ c, begin esimp, cases f c, esimp end)) (λ p, begin cases p, esimp end) definition arrow_arrow_equiv_prod_arrow (A B C : Type) : (A → B → C) ≃ (A × B → C) := mk (λ f, λ p, f p.1 p.2) (λ f, λ a b, f (a, b)) (λ f, rfl) (λ f, funext (λ p, begin cases p, esimp end)) open sum definition sum_arrow_equiv_prod_arrow (A B C : Type) : ((A + B) → C) ≃ ((A → C) × (B → C)) := mk (λ f, (λ a, f (inl a), λ b, f (inr b))) (λ p, (λ s, match s with inl a := p.1 a | inr b := p.2 b end)) (λ f, funext (λ s, begin cases s, esimp, esimp end)) (λ p, begin cases p, esimp end) definition sum_prod_distrib (A B C : Type) : ((A + B) × C) ≃ ((A × C) + (B × C)) := mk (λ p, match p with (inl a, c) := inl (a, c) | (inr b, c) := inr (b, c) end) (λ s, match s with inl (a, c) := (inl a, c) | inr (b, c) := (inr b, c) end) (λ p, begin cases p with ab c, cases ab, repeat esimp end) (λ s, begin cases s with ac bc, cases ac, esimp, cases bc, esimp end) definition prod_sum_distrib (A B C : Type) : (A × (B + C)) ≃ ((A × B) + (A × C)) := calc (A × (B + C)) ≃ ((B + C) × A) : prod_comm ... ≃ ((B × A) + (C × A)) : sum_prod_distrib ... ≃ ((A × B) + (A × C)) : sum_congr !prod_comm !prod_comm definition bool_prod_equiv_sum (A : Type) : (bool × A) ≃ (A + A) := calc (bool × A) ≃ ((unit + unit) × A) : prod_congr bool_equiv_unit_sum_unit !equiv.refl ... ≃ (A × (unit + unit)) : prod_comm ... ≃ ((A × unit) + (A × unit)) : prod_sum_distrib ... ≃ (A + A) : sum_congr !prod_unit_right !prod_unit_right end section open sum nat unit prod.ops definition nat_equiv_nat_sum_unit : nat ≃ (nat + unit) := mk (λ n, match n with zero := inr star | succ a := inl a end) (λ s, match s with inl n := succ n | inr star := zero end) (λ n, begin cases n, repeat esimp end) (λ s, begin cases s with a u, esimp, {cases u, esimp} end) definition nat_sum_unit_equiv_nat [simp] : (nat + unit) ≃ nat := equiv.symm nat_equiv_nat_sum_unit definition nat_prod_nat_equiv_nat [simp] : (nat × nat) ≃ nat := mk (λ p, mkpair p.1 p.2) (λ n, unpair n) (λ p, begin cases p, apply unpair_mkpair end) (λ n, mkpair_unpair n) definition nat_sum_bool_equiv_nat [simp] : (nat + bool) ≃ nat := calc (nat + bool) ≃ (nat + (unit + unit)) : sum_congr !equiv.refl bool_equiv_unit_sum_unit ... ≃ ((nat + unit) + unit) : sum_assoc ... ≃ (nat + unit) : sum_congr nat_sum_unit_equiv_nat !equiv.refl ... ≃ nat : nat_sum_unit_equiv_nat open decidable definition nat_sum_nat_equiv_nat [simp] : (nat + nat) ≃ nat := mk (λ s, match s with inl n := 2*n | inr n := 2*n+1 end) (λ n, if even n then inl (n div 2) else inr ((n - 1) div 2)) (λ s, begin have two_gt_0 : 2 > zero, from dec_trivial, cases s, {esimp, rewrite [if_pos (even_two_mul _), mul_div_cancel_left _ two_gt_0]}, {esimp, rewrite [if_neg (not_even_two_mul_plus_one _), add_sub_cancel, mul_div_cancel_left _ two_gt_0]} end) (λ n, by_cases (λ h : even n, begin rewrite [if_pos h], esimp, rewrite [mul_div_cancel' (dvd_of_even h)] end) (λ h : ¬ even n, begin rewrite [if_neg h], esimp, cases n, {exact absurd even_zero h}, {rewrite [-add_one, add_sub_cancel, mul_div_cancel' (dvd_of_even (even_of_odd_succ (odd_of_not_even h)))]} end)) definition prod_equiv_of_equiv_nat {A : Type} : A ≃ nat → (A × A) ≃ A := take e, calc (A × A) ≃ (nat × nat) : prod_congr e e ... ≃ nat : nat_prod_nat_equiv_nat ... ≃ A : equiv.symm e end section open decidable definition decidable_eq_of_equiv {A B : Type} [h : decidable_eq A] : A ≃ B → decidable_eq B | (mk f g l r) := take b₁ b₂, match h (g b₁) (g b₂) with | inl he := inl (assert aux : f (g b₁) = f (g b₂), from congr_arg f he, begin rewrite *r at aux, exact aux end) | inr hn := inr (λ b₁eqb₂, by subst b₁eqb₂; exact absurd rfl hn) end end definition inhabited_of_equiv {A B : Type} [h : inhabited A] : A ≃ B → inhabited B | (mk f g l r) := inhabited.mk (f (inhabited.value h)) section open subtype definition subtype_equiv_of_subtype {A B : Type} {p : A → Prop} : A ≃ B → {a : A | p a} ≃ {b : B | p b⁻¹} | (mk f g l r) := mk (λ s, match s with tag v h := tag (f v) (eq.rec_on (eq.symm (l v)) h) end) (λ s, match s with tag v h := tag (g v) (eq.rec_on (eq.symm (r v)) h) end) (λ s, begin cases s, esimp, congruence, rewrite l, reflexivity end) (λ s, begin cases s, esimp, congruence, rewrite r, reflexivity end) end section swap variable {A : Type} variable [h : decidable_eq A] include h open decidable definition swap_core (a b r : A) : A := if r = a then b else if r = b then a else r lemma swap_core_swap_core (r a b : A) : swap_core a b (swap_core a b r) = r := by_cases (suppose r = a, by_cases (suppose r = b, begin unfold swap_core, rewrite [if_pos `r = a`, if_pos (eq.refl b), -`r = a`, -`r = b`, if_pos (eq.refl r)] end) (suppose ¬ r = b, assert b ≠ a, from assume h, begin rewrite h at this, contradiction end, begin unfold swap_core, rewrite [*if_pos `r = a`, if_pos (eq.refl b), if_neg `b ≠ a`, `r = a`] end)) (suppose ¬ r = a, by_cases (suppose r = b, begin unfold swap_core, rewrite [if_neg `¬ r = a`, *if_pos `r = b`, if_pos (eq.refl a), this] end) (suppose ¬ r = b, begin unfold swap_core, rewrite [*if_neg `¬ r = a`, *if_neg `¬ r = b`, if_neg `¬ r = a`] end)) lemma swap_core_self (r a : A) : swap_core a a r = r := by_cases (suppose r = a, begin unfold swap_core, rewrite [*if_pos this, this] end) (suppose r ≠ a, begin unfold swap_core, rewrite [*if_neg this] end) lemma swap_core_comm (r a b : A) : swap_core a b r = swap_core b a r := by_cases (suppose r = a, by_cases (suppose r = b, begin unfold swap_core, rewrite [if_pos `r = a`, if_pos `r = b`, -`r = a`, -`r = b`] end) (suppose ¬ r = b, begin unfold swap_core, rewrite [*if_pos `r = a`, if_neg `¬ r = b`] end)) (suppose ¬ r = a, by_cases (suppose r = b, begin unfold swap_core, rewrite [if_neg `¬ r = a`, *if_pos `r = b`] end) (suppose ¬ r = b, begin unfold swap_core, rewrite [*if_neg `¬ r = a`, *if_neg `¬ r = b`] end)) definition swap (a b : A) : perm A := mk (swap_core a b) (swap_core a b) (λ x, abstract by rewrite swap_core_swap_core end) (λ x, abstract by rewrite swap_core_swap_core end) lemma swap_self (a : A) : swap a a = id := eq_of_to_fun_eq (funext (λ x, begin unfold [swap, fn], rewrite swap_core_self end)) lemma swap_comm (a b : A) : swap a b = swap b a := eq_of_to_fun_eq (funext (λ x, begin unfold [swap, fn], rewrite swap_core_comm end)) lemma swap_apply_def (a b : A) (x : A) : swap a b ∙ x = if x = a then b else if x = b then a else x := rfl lemma swap_apply_left (a b : A) : swap a b ∙ a = b := if_pos rfl lemma swap_apply_right (a b : A) : swap a b ∙ b = a := by_cases (suppose b = a, by rewrite [swap_apply_def, this, *if_pos rfl]) (suppose b ≠ a, by rewrite [swap_apply_def, if_pos rfl, if_neg this]) lemma swap_apply_of_ne_of_ne {a b : A} {x : A} : x ≠ a → x ≠ b → swap a b ∙ x = x := assume h₁ h₂, by rewrite [swap_apply_def, if_neg h₁, if_neg h₂] lemma swap_swap (a b : A) : swap a b ∘ swap a b = id := eq_of_to_fun_eq (funext (λ x, begin unfold [swap, fn, equiv.trans, equiv.refl], rewrite swap_core_swap_core end)) lemma swap_compose_apply (a b : A) (π : perm A) (x : A) : (swap a b ∘ π) ∙ x = if π ∙ x = a then b else if π ∙ x = b then a else π ∙ x := begin cases π, reflexivity end end swap end equiv
b2d454148864689b92029c7f156b11abda080a4c
71ee8429ef01e62a6317ad385210fc1ce73da17e
/src/UROP.lean
9f18a13a4eb323b93848cdfc649898a3df25e42d
[]
no_license
qsmy41/ICL-UROP---LeanProver
03207ac6b64b00fbb9039a6fa48abf847e91533f
20aa66d479c5edd0706819d641d2f642432e6adb
refs/heads/master
1,669,959,783,081
1,598,028,742,000
1,598,028,742,000
285,318,189
0
0
null
null
null
null
UTF-8
Lean
false
false
9,126
lean
import topology.algebra.infinite_sum import data.real.basic import data.real.nnreal import algebra.geom_sum open_locale big_operators open_locale classical open finset notation `|`x`|` := abs x def seq_limit (u : ℕ → ℝ) (l : ℝ) : Prop := ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε def non_decreasing (u : ℕ → ℝ) := ∀ n m, n ≤ m → u n ≤ u m def is_seq_sup (M : ℝ) (u : ℕ → ℝ) := (∀ n, u n ≤ M) ∧ ∀ ε > 0, ∃ n₀, u n₀ ≥ M - ε /- The following is a lemma proven from exercises -/ lemma bounded_above_and_increasing_func_converges_to_sup (M : ℝ) (u : ℕ → ℝ) (h : is_seq_sup M u) (h' : non_decreasing u) : seq_limit u M := begin -- get rid off most of the ∀, ∃ statements intros ε ε_pos, cases h with ha hb, cases hb ε ε_pos with n₀ un₀, use n₀, intros n, specialize h' n₀ n, intros h'l, -- gather hypothesis to prove the desired result have inter₁ : u n₀ ≤ u n, { apply h', exact h'l, }, have inter₂ : u n ≥ M - ε, { linarith, }, have inter₃ : M + ε ≥ u n, { specialize ha n, linarith, }, have inter₂' : M - u n ≤ ε, { linarith, }, have inter₃' : u n - M ≤ ε, { linarith, }, rw abs_le, split, repeat { linarith, }, end lemma bounded_above_and_increasing_func_converges (u : ℕ → ℝ) (bounded_above : ∃ x : ℝ, ∀ n : ℕ, u n ≤ x) (increasing : non_decreasing u) : ∃ l : ℝ, seq_limit u l := begin have non_empty : (∃ (x : ℝ), x ∈ set.range u), { use u 1, use 1, }, -- prove that ∃ supremum have inter : (∃ (x : ℝ), ∀ (y : ℝ), x ≤ y ↔ ∀ (z : ℝ), z ∈ set.range u → z ≤ y), { refine real.exists_sup (set.range u) non_empty _, cases bounded_above with x hx, use x, intros y hy, cases hy with n hn, specialize hx n, linarith, }, -- in inter, x is sup, y is upper bounds, z is (u n) cases inter with M hM, cases bounded_above with x hx, -- simplify the expression /- Note: inter' should not prematurely specify y, - e.g. have inter' : M ≤ x ↔ ∀ (n : ℕ), u n ≤ x, - otherwise cannot be used as the Prop to be contraposed -/ have inter' : ∀ y : ℝ, M ≤ y ↔ ∀ n : ℕ, u n ≤ y, { intros y, rw hM, exact set.forall_range_iff, }, -- necessary lemma to be proved so as to prove the current lemma have is_sup : ∀ ε > 0, ∃ n₀, u n₀ ≥ M - ε, { contrapose! inter', rcases inter' with ⟨ε, ε_pos, hε⟩, use (M - ε / 2), rw not_iff, rw not_le, split, { intros h1 n, specialize hε n, linarith, }, { intro h, linarith, }, }, -- use everything proved previously to prove the proposition! use M, refine bounded_above_and_increasing_func_converges_to_sup M u _ increasing, split, { specialize inter' M, apply inter'.1, linarith, }, { exact is_sup, }, end -- The following two lemmas thanks to Jason KY def partial_sum_to (a : ℕ → ℝ) (n : ℕ) := finset.sum (finset.range n) a notation `∑` a := partial_sum_to a lemma sum_diff {a : ℕ → ℝ} {n m : ℕ} (h₁ : n < m) : (∑ a) m - (∑ a) n = finset.sum (finset.Ico n m) a := begin unfold partial_sum_to, induction m with k hk, { exfalso, from nat.not_succ_le_zero n h₁, }, { rw [finset.sum_range_succ, finset.sum_Ico_succ_top], swap, from nat.lt_succ_iff.mp h₁, simp, cases nat.lt_succ_iff_lt_or_eq.mp h₁, { specialize hk h, linarith, }, -- the line below somehow doesn't work for proving the first case -- {rw [←sub_eq_add_neg, hk h]}, { rw h, simp, }, } end lemma sum_pos {a : ℕ → ℝ} {n m : ℕ} (h₁ : ∀ k : ℕ, 0 ≤ a k) : 0 ≤ finset.sum (finset.Ico n m) a := begin induction m with k hk, { rw finset.Ico.eq_empty_iff.mpr (zero_le n), simp, }, { cases le_or_lt n k, { rw finset.sum_Ico_succ_top h, from add_nonneg hk (h₁ k), }, { rw finset.Ico.eq_empty_iff.mpr (nat.succ_le_iff.mpr h), simp, }, }, end /- The question to be proven in this project: - Suppose aₙ ≥ 0 ∀ n and converges to a ∈ [0,1). Prove ∑_{n=1}^∞ aₙ^n converges. - you can jump to where "MARK !!!" is to see the core of the proof -/ lemma series_of_root_numbers_converges (a : ℕ → ℝ) (l : ℝ) (h_seq : seq_limit a l) (hu : ∀ n : ℕ, a n ≥ 0) (hl : l ∈ set.Ico (0 : ℝ) 1): ∃ x : ℝ, seq_limit (λ N : ℕ , (∑ (λ n : ℕ, a n ^ n)) N) x := begin have hann : ∀ n : ℕ, a n ^ n ≥ 0, { intros n, specialize hu n, exact pow_nonneg hu n, }, apply bounded_above_and_increasing_func_converges, { -- prove that the series is bounded above unfold seq_limit at h_seq, have l_nonneg: l ≥ 0, { exact hl.left, }, have l_lt_1: l < 1, { exact hl.right, }, specialize h_seq ((1 - l) / 2) (by linarith), cases h_seq with N hN, let A : ℝ := (1 + l) / 2, have A_pos : A > 0, { have inter : (1 + l) / 2 > 0, { linarith, }, exact inter, }, -- Below is the upper bound of the series use (((∑ (λ n : ℕ, a n ^ n)) N) + A ^ N / (1 - A)), intro n, let hN' := hN n, have hAN_pos : A ^ N > 0, { exact pow_pos A_pos N, }, have hAn_pos : A ^ n > 0, { exact pow_pos A_pos n, }, by_cases n ≤ N, { -- trivial but unfortunately long proof... have hAN : A ^ N / (1 - A) > 0, { have temp : 1 - A > 0, { have inter : (1 - (1 + l) / 2 > 0), { linarith, }, exact inter, }, exact div_pos hAN_pos temp, }, by_cases h' : n = N, { rw h', linarith, }, { refine sub_nonneg.mp _, have temp_add_sub_comm: ∀ x y z : ℝ, x + y - z = x - z + y, { intros x y z, ring, }, rw temp_add_sub_comm, have hnN : n < N, { exact lt_of_le_of_ne h h', }, rw sum_diff hnN, have nonneg_sum_diff : 0 ≤ finset.sum (finset.Ico n N) (λ n : ℕ, a n ^ n), { exact sum_pos hann, }, linarith, }, }, { push_neg at h, have h' : N ≤ n, { linarith, }, have A_le_1: A < 1, { have inter : (1 + l) / 2 < 1, { linarith, }, exact inter, }, specialize hN' h', -- The following cᵢ's are for deducing each line in the calc block later have c₁ : (∑λ (n : ℕ), a n ^ n) n - (∑λ (n : ℕ), a n ^ n) N = finset.sum (finset.Ico N n) (λ (n : ℕ), a n ^ n), { exact sum_diff h, }, have c₂ : finset.sum (finset.Ico N n) (λ (n : ℕ), a n ^ n) ≤ finset.sum (finset.Ico N n) (λ (n : ℕ), A ^ n), { have temp : ∀ x ∈ Ico N n, a x ^ x ≤ A ^ x, { intros n' hn'Nn, have haA : a n' ≤ (1 + l) / 2, { specialize hN n' _, { rw abs_le at hN, cases hN, linarith, }, { rwa Ico.mem at hn'Nn, linarith, }, }, exact pow_le_pow_of_le_left (hu n') haA n', }, exact sum_le_sum temp, }, have c₃ : finset.sum (finset.Ico N n) (λ (n : ℕ), A ^ n) = (A ^ n - A ^ N) / (A - 1), { by exact geom_sum_Ico (by linarith) h', }, have c₄ : (A ^ n - A ^ N) / (A - 1) = (A ^ N - A ^ n) / (1 - A), { have inter₁ : A - 1 ≠ 0, { linarith, }, have inter₂ : 1 - A ≠ 0, { linarith, }, rw div_eq_div_iff inter₁ inter₂, linarith, }, have c₅ : (A ^ N - A ^ n) / (1 - A) ≤ A ^ N / (1 - A), { apply div_le_div, repeat { linarith, }, }, -- MARK !!! -- The following calc block is the holy grail of the proof! calc (∑λ (n : ℕ), a n ^ n) n = (∑λ (n : ℕ), a n ^ n) N + finset.sum (finset.Ico N n) (λ (n : ℕ), a n ^ n) : by linarith ... ≤ (∑λ (n : ℕ), a n ^ n) N + finset.sum (finset.Ico N n) (λ (n : ℕ), A ^ n) : by linarith ... = (∑λ (n : ℕ), a n ^ n) N + (A ^ n - A ^ N) / (A - 1) : by linarith ... = (∑λ (n : ℕ), a n ^ n) N + (A ^ N - A ^ n) / (1 - A) : by linarith ... ≤ (∑λ (n : ℕ), a n ^ n) N + A ^ N / (1 - A) : by linarith, }, }, { -- prove that the series is monotonically increasing unfold non_decreasing, intros n m hnm, rw le_iff_lt_or_eq at hnm, cases hnm with hl he, { refine sub_nonneg.mp _, rw sum_diff hl, exact sum_pos hann, }, { rw le_iff_lt_or_eq, right, rwa he, }, }, end /- potentially more general version: lemma series_of_root_numbers_converges (a : ℕ → ℝ) (l : ℝ) (h_seq : seq_limit a l) (hu : ∀ n : ℕ, a n ≥ 0) (l_pos : l ≥ 0) (l_lt_one: l < 1) : ∃ x : ℝ, has_sum (λ n, (a n) ^ n) x := begin sorry end -/
57de5ad1358491f6a182750159a4c1ff8f93d98e
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/analysis/convex/partition_of_unity.lean
1518123f8863671210ba99bb333351a8e7a0c528
[ "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
3,738
lean
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import topology.partition_of_unity import analysis.convex.combination /-! # Partition of unity and convex sets > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. In this file we prove the following lemma, see `exists_continuous_forall_mem_convex_of_local`. Let `X` be a normal paracompact topological space (e.g., any extended metric space). Let `E` be a topological real vector space. Let `t : X → set E` be a family of convex sets. Suppose that for each point `x : X`, there exists a neighborhood `U ∈ 𝓝 X` and a function `g : X → E` that is continuous on `U` and sends each `y ∈ U` to a point of `t y`. Then there exists a continuous map `g : C(X, E)` such that `g x ∈ t x` for all `x`. We also formulate a useful corollary, see `exists_continuous_forall_mem_convex_of_local_const`, that assumes that local functions `g` are constants. ## Tags partition of unity -/ open set function open_locale big_operators topology variables {ι X E : Type*} [topological_space X] [add_comm_group E] [module ℝ E] lemma partition_of_unity.finsum_smul_mem_convex {s : set X} (f : partition_of_unity ι X s) {g : ι → X → E} {t : set E} {x : X} (hx : x ∈ s) (hg : ∀ i, f i x ≠ 0 → g i x ∈ t) (ht : convex ℝ t) : ∑ᶠ i, f i x • g i x ∈ t := ht.finsum_mem (λ i, f.nonneg _ _) (f.sum_eq_one hx) hg variables [normal_space X] [paracompact_space X] [topological_space E] [has_continuous_add E] [has_continuous_smul ℝ E] {t : X → set E} /-- Let `X` be a normal paracompact topological space (e.g., any extended metric space). Let `E` be a topological real vector space. Let `t : X → set E` be a family of convex sets. Suppose that for each point `x : X`, there exists a neighborhood `U ∈ 𝓝 X` and a function `g : X → E` that is continuous on `U` and sends each `y ∈ U` to a point of `t y`. Then there exists a continuous map `g : C(X, E)` such that `g x ∈ t x` for all `x`. See also `exists_continuous_forall_mem_convex_of_local_const`. -/ lemma exists_continuous_forall_mem_convex_of_local (ht : ∀ x, convex ℝ (t x)) (H : ∀ x : X, ∃ (U ∈ 𝓝 x) (g : X → E), continuous_on g U ∧ ∀ y ∈ U, g y ∈ t y) : ∃ g : C(X, E), ∀ x, g x ∈ t x := begin choose U hU g hgc hgt using H, obtain ⟨f, hf⟩ := partition_of_unity.exists_is_subordinate is_closed_univ (λ x, interior (U x)) (λ x, is_open_interior) (λ x hx, mem_Union.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x)⟩), refine ⟨⟨λ x, ∑ᶠ i, f i x • g i x, hf.continuous_finsum_smul (λ i, is_open_interior) $ λ i, (hgc i).mono interior_subset⟩, λ x, f.finsum_smul_mem_convex (mem_univ x) (λ i hi, hgt _ _ _) (ht _)⟩, exact interior_subset (hf _ $ subset_closure hi) end /-- Let `X` be a normal paracompact topological space (e.g., any extended metric space). Let `E` be a topological real vector space. Let `t : X → set E` be a family of convex sets. Suppose that for each point `x : X`, there exists a vector `c : E` that belongs to `t y` for all `y` in a neighborhood of `x`. Then there exists a continuous map `g : C(X, E)` such that `g x ∈ t x` for all `x`. See also `exists_continuous_forall_mem_convex_of_local`. -/ lemma exists_continuous_forall_mem_convex_of_local_const (ht : ∀ x, convex ℝ (t x)) (H : ∀ x : X, ∃ c : E, ∀ᶠ y in 𝓝 x, c ∈ t y) : ∃ g : C(X, E), ∀ x, g x ∈ t x := exists_continuous_forall_mem_convex_of_local ht $ λ x, let ⟨c, hc⟩ := H x in ⟨_, hc, λ _, c, continuous_on_const, λ y, id⟩
b98bd8afb40069eea64e74926ebb7ba57798abc2
9b9a16fa2cb737daee6b2785474678b6fa91d6d4
/src/category_theory/limits/preserves.lean
9069f97ed5ba77f57901cba6aeda883855343c5c
[ "Apache-2.0" ]
permissive
johoelzl/mathlib
253f46daa30b644d011e8e119025b01ad69735c4
592e3c7a2dfbd5826919b4605559d35d4d75938f
refs/heads/master
1,625,657,216,488
1,551,374,946,000
1,551,374,946,000
98,915,829
0
0
Apache-2.0
1,522,917,267,000
1,501,524,499,000
Lean
UTF-8
Lean
false
false
10,235
lean
-- Copyright (c) 2018 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Scott Morrison, Reid Barton -- Preservation and reflection of (co)limits. import category_theory.whiskering import category_theory.limits.limits open category_theory namespace category_theory.limits universes v u₁ u₂ u₃ -- declare the `v`'s first; see `category_theory.category` for an explanation variables {C : Type u₁} [𝒞 : category.{v} C] variables {D : Type u₂} [𝒟 : category.{v} D] include 𝒞 𝒟 variables {J : Type v} [small_category J] {K : J ⥤ C} /- Note on "preservation of (co)limits" There are various distinct notions of "preserving limits". The one we aim to capture here is: A functor F : C → D "preserves limits" if it sends every limit cone in C to a limit cone in D. Informally, F preserves all the limits which exist in C. Note that: * Of course, we do not want to require F to *strictly* take chosen limit cones of C to chosen limit cones of D. Indeed, the above definition makes no reference to a choice of limit cones so it makes sense without any conditions on C or D. * Some diagrams in C may have no limit. In this case, there is no condition on the behavior of F on such diagrams. There are other notions (such as "flat functor") which impose conditions also on diagrams in C with no limits, but these are not considered here. In order to be able to express the property of preserving limits of a certain form, we say that a functor F preserves the limit of a diagram K if F sends every limit cone on K to a limit cone. This is vacuously satisfied when K does not admit a limit, which is consistent with the above definition of "preserves limits". -/ class preserves_limit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) := (preserves : Π {c : cone K}, is_limit c → is_limit (F.map_cone c)) class preserves_colimit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) := (preserves : Π {c : cocone K}, is_colimit c → is_colimit (F.map_cocone c)) @[class] def preserves_limits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) := Π {K : J ⥤ C}, preserves_limit K F @[class] def preserves_colimits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) := Π {K : J ⥤ C}, preserves_colimit K F @[class] def preserves_limits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) := Π {J : Type v} {𝒥 : small_category J}, by exactI preserves_limits_of_shape J F @[class] def preserves_colimits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) := Π {J : Type v} {𝒥 : small_category J}, by exactI preserves_colimits_of_shape J F instance preserves_limit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : subsingleton (preserves_limit K F) := by split; rintros ⟨a⟩ ⟨b⟩; congr instance preserves_colimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : subsingleton (preserves_colimit K F) := by split; rintros ⟨a⟩ ⟨b⟩; congr instance preserves_limits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) : subsingleton (preserves_limits_of_shape J F) := by split; intros; funext; apply subsingleton.elim instance preserves_colimits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) : subsingleton (preserves_colimits_of_shape J F) := by split; intros; funext; apply subsingleton.elim instance preserves_limits_subsingleton (F : C ⥤ D) : subsingleton (preserves_limits F) := by split; intros; funext; resetI; apply subsingleton.elim instance preserves_colimits_subsingleton (F : C ⥤ D) : subsingleton (preserves_colimits F) := by split; intros; funext; resetI; apply subsingleton.elim instance preserves_limit_of_preserves_limits_of_shape (F : C ⥤ D) [H : preserves_limits_of_shape J F] : preserves_limit K F := H instance preserves_colimit_of_preserves_colimits_of_shape (F : C ⥤ D) [H : preserves_colimits_of_shape J F] : preserves_colimit K F := H instance preserves_limits_of_shape_of_preserves_limits (F : C ⥤ D) [H : preserves_limits F] : preserves_limits_of_shape J F := @H J _ instance preserves_colimits_of_shape_of_preserves_colimits (F : C ⥤ D) [H : preserves_colimits F] : preserves_colimits_of_shape J F := @H J _ instance id_preserves_limits : preserves_limits (functor.id C) := λ J 𝒥 K, by exactI ⟨λ c h, ⟨λ s, h.lift ⟨s.X, λ j, s.π.app j, λ j j' f, s.π.naturality f⟩, by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j, by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ instance id_preserves_colimits : preserves_colimits (functor.id C) := λ J 𝒥 K, by exactI ⟨λ c h, ⟨λ s, h.desc ⟨s.X, λ j, s.ι.app j, λ j j' f, s.ι.naturality f⟩, by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j, by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ section variables {E : Type u₃} [ℰ : category.{v} E] variables (F : C ⥤ D) (G : D ⥤ E) local attribute [elab_simple] preserves_limit.preserves preserves_colimit.preserves instance comp_preserves_limit [preserves_limit K F] [preserves_limit (K ⋙ F) G] : preserves_limit K (F ⋙ G) := ⟨λ c h, preserves_limit.preserves G (preserves_limit.preserves F h)⟩ instance comp_preserves_colimit [preserves_colimit K F] [preserves_colimit (K ⋙ F) G] : preserves_colimit K (F ⋙ G) := ⟨λ c h, preserves_colimit.preserves G (preserves_colimit.preserves F h)⟩ end /-- If F preserves one limit cone for the diagram K, then it preserves any limit cone for K. -/ def preserves_limit_of_preserves_limit_cone {F : C ⥤ D} {t : cone K} (h : is_limit t) (hF : is_limit (F.map_cone t)) : preserves_limit K F := ⟨λ t' h', is_limit.of_iso_limit hF (functor.on_iso _ (is_limit.unique h h'))⟩ /-- If F preserves one colimit cocone for the diagram K, then it preserves any colimit cocone for K. -/ def preserves_colimit_of_preserves_colimit_cocone {F : C ⥤ D} {t : cocone K} (h : is_colimit t) (hF : is_colimit (F.map_cocone t)) : preserves_colimit K F := ⟨λ t' h', is_colimit.of_iso_colimit hF (functor.on_iso _ (is_colimit.unique h h'))⟩ /- A functor F : C → D reflects limits if whenever the image of a cone under F is a limit cone in D, the cone was already a limit cone in C. Note that again we do not assume a priori that D actually has any limits. -/ class reflects_limit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) := (reflects : Π {c : cone K}, is_limit (F.map_cone c) → is_limit c) class reflects_colimit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) := (reflects : Π {c : cocone K}, is_colimit (F.map_cocone c) → is_colimit c) @[class] def reflects_limits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) := Π {K : J ⥤ C}, reflects_limit K F @[class] def reflects_colimits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) := Π {K : J ⥤ C}, reflects_colimit K F @[class] def reflects_limits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) := Π {J : Type v} {𝒥 : small_category J}, by exactI reflects_limits_of_shape J F @[class] def reflects_colimits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) := Π {J : Type v} {𝒥 : small_category J}, by exactI reflects_colimits_of_shape J F instance reflects_limit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : subsingleton (reflects_limit K F) := by split; rintros ⟨a⟩ ⟨b⟩; congr instance reflects_colimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : subsingleton (reflects_colimit K F) := by split; rintros ⟨a⟩ ⟨b⟩; congr instance reflects_limits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) : subsingleton (reflects_limits_of_shape J F) := by split; intros; funext; apply subsingleton.elim instance reflects_colimits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) : subsingleton (reflects_colimits_of_shape J F) := by split; intros; funext; apply subsingleton.elim instance reflects_limits_subsingleton (F : C ⥤ D) : subsingleton (reflects_limits F) := by split; intros; funext; resetI; apply subsingleton.elim instance reflects_colimits_subsingleton (F : C ⥤ D) : subsingleton (reflects_colimits F) := by split; intros; funext; resetI; apply subsingleton.elim instance reflects_limit_of_reflects_limits_of_shape (K : J ⥤ C) (F : C ⥤ D) [H : reflects_limits_of_shape J F] : reflects_limit K F := H instance reflects_colimit_of_reflects_colimits_of_shape (K : J ⥤ C) (F : C ⥤ D) [H : reflects_colimits_of_shape J F] : reflects_colimit K F := H instance reflects_limits_of_shape_of_reflects_limits (F : C ⥤ D) [H : reflects_limits F] : reflects_limits_of_shape J F := @H J _ instance reflects_colimits_of_shape_of_reflects_colimits (F : C ⥤ D) [H : reflects_colimits F] : reflects_colimits_of_shape J F := @H J _ instance id_reflects_limits : reflects_limits (functor.id C) := λ J 𝒥 K, by exactI ⟨λ c h, ⟨λ s, h.lift ⟨s.X, λ j, s.π.app j, λ j j' f, s.π.naturality f⟩, by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j, by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ instance id_reflects_colimits : reflects_colimits (functor.id C) := λ J 𝒥 K, by exactI ⟨λ c h, ⟨λ s, h.desc ⟨s.X, λ j, s.ι.app j, λ j j' f, s.ι.naturality f⟩, by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j, by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ section variables {E : Type u₃} [ℰ : category.{v} E] variables (F : C ⥤ D) (G : D ⥤ E) instance comp_reflects_limit [reflects_limit K F] [reflects_limit (K ⋙ F) G] : reflects_limit K (F ⋙ G) := ⟨λ c h, reflects_limit.reflects (reflects_limit.reflects h)⟩ instance comp_reflects_colimit [reflects_colimit K F] [reflects_colimit (K ⋙ F) G] : reflects_colimit K (F ⋙ G) := ⟨λ c h, reflects_colimit.reflects (reflects_colimit.reflects h)⟩ end end category_theory.limits
f11709f571df547407272b606ab88462fbe61d73
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/measure_theory/measure/haar.lean
0883a2c3ba646b3bbbdc18c9d8912ffd94f6e1f4
[ "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
38,932
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.measure.content import measure_theory.group.prod import group_theory.divisible import topology.algebra.group.compact /-! # Haar measure In this file we prove the existence and uniqueness (up to scalar multiples) of Haar measure for a locally compact Hausdorff topological group. For the construction, we follow the write-up by Jonathan Gleason, *Existence and Uniqueness of Haar Measure*. This is essentially the same argument as in https://en.wikipedia.org/wiki/Haar_measure#A_construction_using_compact_subsets. We construct the Haar measure first on compact sets. For this we define `(K : U)` as the (smallest) number of left-translates of `U` that are needed to cover `K` (`index` in the formalization). Then we define a function `h` on compact sets as `lim_U (K : U) / (K₀ : U)`, where `U` becomes a smaller and smaller open neighborhood of `1`, and `K₀` is a fixed compact set with nonempty interior. This function is `chaar` in the formalization, and we define the limit formally using Tychonoff's theorem. This function `h` forms a content, which we can extend to an outer measure and then a measure (`haar_measure`). We normalize the Haar measure so that the measure of `K₀` is `1`. We show that for second countable spaces any left invariant Borel measure is a scalar multiple of the Haar measure. Note that `μ` need not coincide with `h` on compact sets, according to [halmos1950measure, ch. X, §53 p.233]. However, we know that `h(K)` lies between `μ(Kᵒ)` and `μ(K)`, where `ᵒ` denotes the interior. ## Main Declarations * `haar_measure`: the Haar measure on a locally compact Hausdorff group. This is a left invariant regular measure. It takes as argument a compact set of the group (with non-empty interior), and is normalized so that the measure of the given set is 1. * `haar_measure_self`: the Haar measure is normalized. * `is_left_invariant_haar_measure`: the Haar measure is left invariant. * `regular_haar_measure`: the Haar measure is a regular measure. * `is_haar_measure_haar_measure`: the Haar measure satisfies the `is_haar_measure` typeclass, i.e., it is invariant and gives finite mass to compact sets and positive mass to nonempty open sets. * `haar` : some choice of a Haar measure, on a locally compact Hausdorff group, constructed as `haar_measure K` where `K` is some arbitrary choice of a compact set with nonempty interior. * `haar_measure_unique`: Every σ-finite left invariant measure on a locally compact Hausdorff group is a scalar multiple of the Haar measure. ## References * Paul Halmos (1950), Measure Theory, §53 * Jonathan Gleason, Existence and Uniqueness of Haar Measure - Note: step 9, page 8 contains a mistake: the last defined `μ` does not extend the `μ` on compact sets, see Halmos (1950) p. 233, bottom of the page. This makes some other steps (like step 11) invalid. * https://en.wikipedia.org/wiki/Haar_measure -/ noncomputable theory open set has_inv function topological_space measurable_space open_locale nnreal classical ennreal pointwise topological_space namespace measure_theory namespace measure section group variables {G : Type*} [group G] /-! We put the internal functions in the construction of the Haar measure in a namespace, so that the chosen names don't clash with other declarations. We first define a couple of the functions before proving the properties (that require that `G` is a topological group). -/ namespace haar /-- The index or Haar covering number or ratio of `K` w.r.t. `V`, denoted `(K : V)`: it is the smallest number of (left) translates of `V` that is necessary to cover `K`. It is defined to be 0 if no finite number of translates cover `K`. -/ @[to_additive add_index "additive version of `measure_theory.measure.haar.index`"] def index (K V : set G) : ℕ := Inf $ finset.card '' {t : finset G | K ⊆ ⋃ g ∈ t, (λ h, g * h) ⁻¹' V } @[to_additive add_index_empty] lemma index_empty {V : set G} : index ∅ V = 0 := begin simp only [index, nat.Inf_eq_zero], left, use ∅, simp only [finset.card_empty, empty_subset, mem_set_of_eq, eq_self_iff_true, and_self], end variables [topological_space G] /-- `prehaar K₀ U K` is a weighted version of the index, defined as `(K : U)/(K₀ : U)`. In the applications `K₀` is compact with non-empty interior, `U` is open containing `1`, and `K` is any compact set. The argument `K` is a (bundled) compact set, so that we can consider `prehaar K₀ U` as an element of `haar_product` (below). -/ @[to_additive "additive version of `measure_theory.measure.haar.prehaar`"] def prehaar (K₀ U : set G) (K : compacts G) : ℝ := (index (K : set G) U : ℝ) / index K₀ U @[to_additive] lemma prehaar_empty (K₀ : positive_compacts G) {U : set G} : prehaar (K₀ : set G) U ⊥ = 0 := by rw [prehaar, compacts.coe_bot, index_empty, nat.cast_zero, zero_div] @[to_additive] lemma prehaar_nonneg (K₀ : positive_compacts G) {U : set G} (K : compacts G) : 0 ≤ prehaar (K₀ : set G) U K := by apply div_nonneg; norm_cast; apply zero_le /-- `haar_product K₀` is the product of intervals `[0, (K : K₀)]`, for all compact sets `K`. For all `U`, we can show that `prehaar K₀ U ∈ haar_product K₀`. -/ @[to_additive "additive version of `measure_theory.measure.haar.haar_product`"] def haar_product (K₀ : set G) : set (compacts G → ℝ) := pi univ (λ K, Icc 0 $ index (K : set G) K₀) @[simp, to_additive] lemma mem_prehaar_empty {K₀ : set G} {f : compacts G → ℝ} : f ∈ haar_product K₀ ↔ ∀ K : compacts G, f K ∈ Icc (0 : ℝ) (index (K : set G) K₀) := by simp only [haar_product, pi, forall_prop_of_true, mem_univ, mem_set_of_eq] /-- The closure of the collection of elements of the form `prehaar K₀ U`, for `U` open neighbourhoods of `1`, contained in `V`. The closure is taken in the space `compacts G → ℝ`, with the topology of pointwise convergence. We show that the intersection of all these sets is nonempty, and the Haar measure on compact sets is defined to be an element in the closure of this intersection. -/ @[to_additive "additive version of `measure_theory.measure.haar.cl_prehaar`"] def cl_prehaar (K₀ : set G) (V : open_nhds_of (1 : G)) : set (compacts G → ℝ) := closure $ prehaar K₀ '' { U : set G | U ⊆ V.1 ∧ is_open U ∧ (1 : G) ∈ U } variables [topological_group G] /-! ### Lemmas about `index` -/ /-- If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined, there is a finite set `t` satisfying the desired properties. -/ @[to_additive add_index_defined "If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined, there is a finite set `t` satisfying the desired properties."] lemma index_defined {K V : set G} (hK : is_compact K) (hV : (interior V).nonempty) : ∃ n : ℕ, n ∈ finset.card '' {t : finset G | K ⊆ ⋃ g ∈ t, (λ h, g * h) ⁻¹' V } := by { rcases compact_covered_by_mul_left_translates hK hV with ⟨t, ht⟩, exact ⟨t.card, t, ht, rfl⟩ } @[to_additive add_index_elim] lemma index_elim {K V : set G} (hK : is_compact K) (hV : (interior V).nonempty) : ∃ (t : finset G), K ⊆ (⋃ g ∈ t, (λ h, g * h) ⁻¹' V) ∧ finset.card t = index K V := by { have := nat.Inf_mem (index_defined hK hV), rwa [mem_image] at this } @[to_additive le_add_index_mul] lemma le_index_mul (K₀ : positive_compacts G) (K : compacts G) {V : set G} (hV : (interior V).nonempty) : index (K : set G) V ≤ index (K : set G) K₀ * index (K₀ : set G) V := begin obtain ⟨s, h1s, h2s⟩ := index_elim K.is_compact K₀.interior_nonempty, obtain ⟨t, h1t, h2t⟩ := index_elim K₀.is_compact hV, rw [← h2s, ← h2t, mul_comm], refine le_trans _ finset.card_mul_le, apply nat.Inf_le, refine ⟨_, _, rfl⟩, rw [mem_set_of_eq], refine subset.trans h1s _, apply Union₂_subset, intros g₁ hg₁, rw preimage_subset_iff, intros g₂ hg₂, have := h1t hg₂, rcases this with ⟨_, ⟨g₃, rfl⟩, A, ⟨hg₃, rfl⟩, h2V⟩, rw [mem_preimage, ← mul_assoc] at h2V, exact mem_bUnion (finset.mul_mem_mul hg₃ hg₁) h2V end @[to_additive add_index_pos] lemma index_pos (K : positive_compacts G) {V : set G} (hV : (interior V).nonempty) : 0 < index (K : set G) V := begin unfold index, rw [nat.Inf_def, nat.find_pos, mem_image], { rintro ⟨t, h1t, h2t⟩, rw [finset.card_eq_zero] at h2t, subst h2t, obtain ⟨g, hg⟩ := K.interior_nonempty, show g ∈ (∅ : set G), convert h1t (interior_subset hg), symmetry, apply bUnion_empty }, { exact index_defined K.is_compact hV } end @[to_additive add_index_mono] lemma index_mono {K K' V : set G} (hK' : is_compact K') (h : K ⊆ K') (hV : (interior V).nonempty) : index K V ≤ index K' V := begin rcases index_elim hK' hV with ⟨s, h1s, h2s⟩, apply nat.Inf_le, rw [mem_image], refine ⟨s, subset.trans h h1s, h2s⟩ end @[to_additive add_index_union_le] lemma index_union_le (K₁ K₂ : compacts G) {V : set G} (hV : (interior V).nonempty) : index (K₁.1 ∪ K₂.1) V ≤ index K₁.1 V + index K₂.1 V := begin rcases index_elim K₁.2 hV with ⟨s, h1s, h2s⟩, rcases index_elim K₂.2 hV with ⟨t, h1t, h2t⟩, rw [← h2s, ← h2t], refine le_trans _ (finset.card_union_le _ _), apply nat.Inf_le, refine ⟨_, _, rfl⟩, rw [mem_set_of_eq], apply union_subset; refine subset.trans (by assumption) _; apply bUnion_subset_bUnion_left; intros g hg; simp only [mem_def] at hg; simp only [mem_def, multiset.mem_union, finset.union_val, hg, or_true, true_or] end @[to_additive add_index_union_eq] lemma index_union_eq (K₁ K₂ : compacts G) {V : set G} (hV : (interior V).nonempty) (h : disjoint (K₁.1 * V⁻¹) (K₂.1 * V⁻¹)) : index (K₁.1 ∪ K₂.1) V = index K₁.1 V + index K₂.1 V := begin apply le_antisymm (index_union_le K₁ K₂ hV), rcases index_elim (K₁.2.union K₂.2) hV with ⟨s, h1s, h2s⟩, rw [← h2s], have : ∀ (K : set G) , K ⊆ (⋃ g ∈ s, (λ h, g * h) ⁻¹' V) → index K V ≤ (s.filter (λ g, ((λ (h : G), g * h) ⁻¹' V ∩ K).nonempty)).card, { intros K hK, apply nat.Inf_le, refine ⟨_, _, rfl⟩, rw [mem_set_of_eq], intros g hg, rcases hK hg with ⟨_, ⟨g₀, rfl⟩, _, ⟨h1g₀, rfl⟩, h2g₀⟩, simp only [mem_preimage] at h2g₀, simp only [mem_Union], use g₀, split, { simp only [finset.mem_filter, h1g₀, true_and], use g, simp only [hg, h2g₀, mem_inter_iff, mem_preimage, and_self] }, exact h2g₀ }, refine le_trans (add_le_add (this K₁.1 $ subset.trans (subset_union_left _ _) h1s) (this K₂.1 $ subset.trans (subset_union_right _ _) h1s)) _, rw [← finset.card_union_eq, finset.filter_union_right], exact s.card_filter_le _, apply finset.disjoint_filter.mpr, rintro g₁ h1g₁ ⟨g₂, h1g₂, h2g₂⟩ ⟨g₃, h1g₃, h2g₃⟩, simp only [mem_preimage] at h1g₃ h1g₂, refine h.le_bot (_ : g₁⁻¹ ∈ _), split; simp only [set.mem_inv, set.mem_mul, exists_exists_and_eq_and, exists_and_distrib_left], { refine ⟨_, h2g₂, (g₁ * g₂)⁻¹, _, _⟩, simp only [inv_inv, h1g₂], simp only [mul_inv_rev, mul_inv_cancel_left] }, { refine ⟨_, h2g₃, (g₁ * g₃)⁻¹, _, _⟩, simp only [inv_inv, h1g₃], simp only [mul_inv_rev, mul_inv_cancel_left] } end @[to_additive add_left_add_index_le] lemma mul_left_index_le {K : set G} (hK : is_compact K) {V : set G} (hV : (interior V).nonempty) (g : G) : index ((λ h, g * h) '' K) V ≤ index K V := begin rcases index_elim hK hV with ⟨s, h1s, h2s⟩, rw [← h2s], apply nat.Inf_le, rw [mem_image], refine ⟨s.map (equiv.mul_right g⁻¹).to_embedding, _, finset.card_map _⟩, { simp only [mem_set_of_eq], refine subset.trans (image_subset _ h1s) _, rintro _ ⟨g₁, ⟨_, ⟨g₂, rfl⟩, ⟨_, ⟨hg₂, rfl⟩, hg₁⟩⟩, rfl⟩, simp only [mem_preimage] at hg₁, simp only [exists_prop, mem_Union, finset.mem_map, equiv.coe_mul_right, exists_exists_and_eq_and, mem_preimage, equiv.to_embedding_apply], refine ⟨_, hg₂, _⟩, simp only [mul_assoc, hg₁, inv_mul_cancel_left] } end @[to_additive is_left_invariant_add_index] lemma is_left_invariant_index {K : set G} (hK : is_compact K) (g : G) {V : set G} (hV : (interior V).nonempty) : index ((λ h, g * h) '' K) V = index K V := begin refine le_antisymm (mul_left_index_le hK hV g) _, convert mul_left_index_le (hK.image $ continuous_mul_left g) hV g⁻¹, rw [image_image], symmetry, convert image_id' _, ext h, apply inv_mul_cancel_left end /-! ### Lemmas about `prehaar` -/ @[to_additive add_prehaar_le_add_index] lemma prehaar_le_index (K₀ : positive_compacts G) {U : set G} (K : compacts G) (hU : (interior U).nonempty) : prehaar (K₀ : set G) U K ≤ index (K : set G) K₀ := begin unfold prehaar, rw [div_le_iff]; norm_cast, { apply le_index_mul K₀ K hU }, { exact index_pos K₀ hU } end @[to_additive] lemma prehaar_pos (K₀ : positive_compacts G) {U : set G} (hU : (interior U).nonempty) {K : set G} (h1K : is_compact K) (h2K : (interior K).nonempty) : 0 < prehaar (K₀ : set G) U ⟨K, h1K⟩ := by { apply div_pos; norm_cast, apply index_pos ⟨⟨K, h1K⟩, h2K⟩ hU, exact index_pos K₀ hU } @[to_additive] lemma prehaar_mono {K₀ : positive_compacts G} {U : set G} (hU : (interior U).nonempty) {K₁ K₂ : compacts G} (h : (K₁ : set G) ⊆ K₂.1) : prehaar (K₀ : set G) U K₁ ≤ prehaar (K₀ : set G) U K₂ := begin simp only [prehaar], rw [div_le_div_right], exact_mod_cast index_mono K₂.2 h hU, exact_mod_cast index_pos K₀ hU end @[to_additive] lemma prehaar_self {K₀ : positive_compacts G} {U : set G} (hU : (interior U).nonempty) : prehaar (K₀ : set G) U K₀.to_compacts = 1 := div_self $ ne_of_gt $ by exact_mod_cast index_pos K₀ hU @[to_additive] lemma prehaar_sup_le {K₀ : positive_compacts G} {U : set G} (K₁ K₂ : compacts G) (hU : (interior U).nonempty) : prehaar (K₀ : set G) U (K₁ ⊔ K₂) ≤ prehaar (K₀ : set G) U K₁ + prehaar (K₀ : set G) U K₂ := begin simp only [prehaar], rw [div_add_div_same, div_le_div_right], exact_mod_cast index_union_le K₁ K₂ hU, exact_mod_cast index_pos K₀ hU end @[to_additive] lemma prehaar_sup_eq {K₀ : positive_compacts G} {U : set G} {K₁ K₂ : compacts G} (hU : (interior U).nonempty) (h : disjoint (K₁.1 * U⁻¹) (K₂.1 * U⁻¹)) : prehaar (K₀ : set G) U (K₁ ⊔ K₂) = prehaar (K₀ : set G) U K₁ + prehaar (K₀ : set G) U K₂ := by { simp only [prehaar], rw [div_add_div_same], congr', exact_mod_cast index_union_eq K₁ K₂ hU h } @[to_additive] lemma is_left_invariant_prehaar {K₀ : positive_compacts G} {U : set G} (hU : (interior U).nonempty) (g : G) (K : compacts G) : prehaar (K₀ : set G) U (K.map _ $ continuous_mul_left g) = prehaar (K₀ : set G) U K := by simp only [prehaar, compacts.coe_map, is_left_invariant_index K.is_compact _ hU] /-! ### Lemmas about `haar_product` -/ @[to_additive] lemma prehaar_mem_haar_product (K₀ : positive_compacts G) {U : set G} (hU : (interior U).nonempty) : prehaar (K₀ : set G) U ∈ haar_product (K₀ : set G) := by { rintro ⟨K, hK⟩ h2K, rw [mem_Icc], exact ⟨prehaar_nonneg K₀ _, prehaar_le_index K₀ _ hU⟩ } @[to_additive] lemma nonempty_Inter_cl_prehaar (K₀ : positive_compacts G) : (haar_product (K₀ : set G) ∩ ⋂ (V : open_nhds_of (1 : G)), cl_prehaar K₀ V).nonempty := begin have : is_compact (haar_product (K₀ : set G)), { apply is_compact_univ_pi, intro K, apply is_compact_Icc }, refine this.inter_Inter_nonempty (cl_prehaar K₀) (λ s, is_closed_closure) (λ t, _), let V₀ := ⋂ (V ∈ t), (V : open_nhds_of 1).1, have h1V₀ : is_open V₀, { apply is_open_bInter, apply finset.finite_to_set, rintro ⟨V, hV⟩ h2V, exact hV.1 }, have h2V₀ : (1 : G) ∈ V₀, { simp only [mem_Inter], rintro ⟨V, hV⟩ h2V, exact hV.2 }, refine ⟨prehaar K₀ V₀, _⟩, split, { apply prehaar_mem_haar_product K₀, use 1, rwa h1V₀.interior_eq }, { simp only [mem_Inter], rintro ⟨V, hV⟩ h2V, apply subset_closure, apply mem_image_of_mem, rw [mem_set_of_eq], exact ⟨subset.trans (Inter_subset _ ⟨V, hV⟩) (Inter_subset _ h2V), h1V₀, h2V₀⟩ }, end /-! ### Lemmas about `chaar` -/ /-- This is the "limit" of `prehaar K₀ U K` as `U` becomes a smaller and smaller open neighborhood of `(1 : G)`. More precisely, it is defined to be an arbitrary element in the intersection of all the sets `cl_prehaar K₀ V` in `haar_product K₀`. This is roughly equal to the Haar measure on compact sets, but it can differ slightly. We do know that `haar_measure K₀ (interior K) ≤ chaar K₀ K ≤ haar_measure K₀ K`. -/ @[to_additive add_chaar "additive version of `measure_theory.measure.haar.chaar`"] def chaar (K₀ : positive_compacts G) (K : compacts G) : ℝ := classical.some (nonempty_Inter_cl_prehaar K₀) K @[to_additive add_chaar_mem_add_haar_product] lemma chaar_mem_haar_product (K₀ : positive_compacts G) : chaar K₀ ∈ haar_product (K₀ : set G) := (classical.some_spec (nonempty_Inter_cl_prehaar K₀)).1 @[to_additive add_chaar_mem_cl_add_prehaar] lemma chaar_mem_cl_prehaar (K₀ : positive_compacts G) (V : open_nhds_of (1 : G)) : chaar K₀ ∈ cl_prehaar (K₀ : set G) V := by { have := (classical.some_spec (nonempty_Inter_cl_prehaar K₀)).2, rw [mem_Inter] at this, exact this V } @[to_additive add_chaar_nonneg] lemma chaar_nonneg (K₀ : positive_compacts G) (K : compacts G) : 0 ≤ chaar K₀ K := by { have := chaar_mem_haar_product K₀ K (mem_univ _), rw mem_Icc at this, exact this.1 } @[to_additive add_chaar_empty] lemma chaar_empty (K₀ : positive_compacts G) : chaar K₀ ⊥ = 0 := begin let eval : (compacts G → ℝ) → ℝ := λ f, f ⊥, have : continuous eval := continuous_apply ⊥, show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)}, apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩), unfold cl_prehaar, rw is_closed.closure_subset_iff, { rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, apply prehaar_empty }, { apply continuous_iff_is_closed.mp this, exact is_closed_singleton }, end @[to_additive add_chaar_self] lemma chaar_self (K₀ : positive_compacts G) : chaar K₀ K₀.to_compacts = 1 := begin let eval : (compacts G → ℝ) → ℝ := λ f, f K₀.to_compacts, have : continuous eval := continuous_apply _, show chaar K₀ ∈ eval ⁻¹' {(1 : ℝ)}, apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩), unfold cl_prehaar, rw is_closed.closure_subset_iff, { rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, apply prehaar_self, rw h2U.interior_eq, exact ⟨1, h3U⟩ }, { apply continuous_iff_is_closed.mp this, exact is_closed_singleton } end @[to_additive add_chaar_mono] lemma chaar_mono {K₀ : positive_compacts G} {K₁ K₂ : compacts G} (h : (K₁ : set G) ⊆ K₂) : chaar K₀ K₁ ≤ chaar K₀ K₂ := begin let eval : (compacts G → ℝ) → ℝ := λ f, f K₂ - f K₁, have : continuous eval := (continuous_apply K₂).sub (continuous_apply K₁), rw [← sub_nonneg], show chaar K₀ ∈ eval ⁻¹' (Ici (0 : ℝ)), apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩), unfold cl_prehaar, rw is_closed.closure_subset_iff, { rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, simp only [mem_preimage, mem_Ici, eval, sub_nonneg], apply prehaar_mono _ h, rw h2U.interior_eq, exact ⟨1, h3U⟩ }, { apply continuous_iff_is_closed.mp this, exact is_closed_Ici }, end @[to_additive add_chaar_sup_le] lemma chaar_sup_le {K₀ : positive_compacts G} (K₁ K₂ : compacts G) : chaar K₀ (K₁ ⊔ K₂) ≤ chaar K₀ K₁ + chaar K₀ K₂ := begin let eval : (compacts G → ℝ) → ℝ := λ f, f K₁ + f K₂ - f (K₁ ⊔ K₂), have : continuous eval := ((@continuous_add ℝ _ _ _).comp ((continuous_apply K₁).prod_mk (continuous_apply K₂))).sub (continuous_apply (K₁ ⊔ K₂)), rw [← sub_nonneg], show chaar K₀ ∈ eval ⁻¹' (Ici (0 : ℝ)), apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩), unfold cl_prehaar, rw is_closed.closure_subset_iff, { rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, simp only [mem_preimage, mem_Ici, eval, sub_nonneg], apply prehaar_sup_le, rw h2U.interior_eq, exact ⟨1, h3U⟩ }, { apply continuous_iff_is_closed.mp this, exact is_closed_Ici }, end @[to_additive add_chaar_sup_eq] lemma chaar_sup_eq [t2_space G] {K₀ : positive_compacts G} {K₁ K₂ : compacts G} (h : disjoint K₁.1 K₂.1) : chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂ := begin rcases is_compact_is_compact_separated K₁.2 K₂.2 h with ⟨U₁, U₂, h1U₁, h1U₂, h2U₁, h2U₂, hU⟩, rcases compact_open_separated_mul_right K₁.2 h1U₁ h2U₁ with ⟨L₁, h1L₁, h2L₁⟩, rcases mem_nhds_iff.mp h1L₁ with ⟨V₁, h1V₁, h2V₁, h3V₁⟩, replace h2L₁ := subset.trans (mul_subset_mul_left h1V₁) h2L₁, rcases compact_open_separated_mul_right K₂.2 h1U₂ h2U₂ with ⟨L₂, h1L₂, h2L₂⟩, rcases mem_nhds_iff.mp h1L₂ with ⟨V₂, h1V₂, h2V₂, h3V₂⟩, replace h2L₂ := subset.trans (mul_subset_mul_left h1V₂) h2L₂, let eval : (compacts G → ℝ) → ℝ := λ f, f K₁ + f K₂ - f (K₁ ⊔ K₂), have : continuous eval := ((@continuous_add ℝ _ _ _).comp ((continuous_apply K₁).prod_mk (continuous_apply K₂))).sub (continuous_apply (K₁ ⊔ K₂)), rw [eq_comm, ← sub_eq_zero], show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)}, let V := V₁ ∩ V₂, apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨V⁻¹, (is_open.inter h2V₁ h2V₂).preimage continuous_inv, by simp only [mem_inv, inv_one, h3V₁, h3V₂, V, mem_inter_iff, true_and]⟩), unfold cl_prehaar, rw is_closed.closure_subset_iff, { rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, simp only [mem_preimage, eval, sub_eq_zero, mem_singleton_iff], rw [eq_comm], apply prehaar_sup_eq, { rw h2U.interior_eq, exact ⟨1, h3U⟩ }, { refine disjoint_of_subset _ _ hU, { refine subset.trans (mul_subset_mul subset.rfl _) h2L₁, exact subset.trans (inv_subset.mpr h1U) (inter_subset_left _ _) }, { refine subset.trans (mul_subset_mul subset.rfl _) h2L₂, exact subset.trans (inv_subset.mpr h1U) (inter_subset_right _ _) }}}, { apply continuous_iff_is_closed.mp this, exact is_closed_singleton } end @[to_additive is_left_invariant_add_chaar] lemma is_left_invariant_chaar {K₀ : positive_compacts G} (g : G) (K : compacts G) : chaar K₀ (K.map _ $ continuous_mul_left g) = chaar K₀ K := begin let eval : (compacts G → ℝ) → ℝ := λ f, f (K.map _ $ continuous_mul_left g) - f K, have : continuous eval := (continuous_apply (K.map _ _)).sub (continuous_apply K), rw [← sub_eq_zero], show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)}, apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩), unfold cl_prehaar, rw is_closed.closure_subset_iff, { rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, simp only [mem_singleton_iff, mem_preimage, eval, sub_eq_zero], apply is_left_invariant_prehaar, rw h2U.interior_eq, exact ⟨1, h3U⟩ }, { apply continuous_iff_is_closed.mp this, exact is_closed_singleton }, end variable [t2_space G] /-- The function `chaar` interpreted in `ℝ≥0`, as a content -/ @[to_additive "additive version of `measure_theory.measure.haar.haar_content`"] def haar_content (K₀ : positive_compacts G) : content G := { to_fun := λ K, ⟨chaar K₀ K, chaar_nonneg _ _⟩, mono' := λ K₁ K₂ h, by simp only [←nnreal.coe_le_coe, subtype.coe_mk, chaar_mono, h], sup_disjoint' := λ K₁ K₂ h, by { simp only [chaar_sup_eq h], refl }, sup_le' := λ K₁ K₂, by simp only [←nnreal.coe_le_coe, nnreal.coe_add, subtype.coe_mk, chaar_sup_le] } /-! We only prove the properties for `haar_content` that we use at least twice below. -/ @[to_additive] lemma haar_content_apply (K₀ : positive_compacts G) (K : compacts G) : haar_content K₀ K = show nnreal, from ⟨chaar K₀ K, chaar_nonneg _ _⟩ := rfl /-- The variant of `chaar_self` for `haar_content` -/ @[to_additive "The variant of `add_chaar_self` for `add_haar_content`."] lemma haar_content_self {K₀ : positive_compacts G} : haar_content K₀ K₀.to_compacts = 1 := by { simp_rw [← ennreal.coe_one, haar_content_apply, ennreal.coe_eq_coe, chaar_self], refl } /-- The variant of `is_left_invariant_chaar` for `haar_content` -/ @[to_additive "The variant of `is_left_invariant_add_chaar` for `add_haar_content`"] lemma is_left_invariant_haar_content {K₀ : positive_compacts G} (g : G) (K : compacts G) : haar_content K₀ (K.map _ $ continuous_mul_left g) = haar_content K₀ K := by simpa only [ennreal.coe_eq_coe, ←nnreal.coe_eq, haar_content_apply] using is_left_invariant_chaar g K @[to_additive] lemma haar_content_outer_measure_self_pos {K₀ : positive_compacts G} : 0 < (haar_content K₀).outer_measure K₀ := begin apply ennreal.zero_lt_one.trans_le, rw [content.outer_measure_eq_infi], refine le_infi₂ (λ U hU, le_infi $ λ hK₀, le_trans _ $ le_supr₂ K₀.to_compacts hK₀), exact haar_content_self.ge, end end haar open haar /-! ### The Haar measure -/ variables [topological_space G] [t2_space G] [topological_group G] [measurable_space G] [borel_space G] /-- The Haar measure on the locally compact group `G`, scaled so that `haar_measure K₀ K₀ = 1`. -/ @[to_additive "The Haar measure on the locally compact additive group `G`, scaled so that `add_haar_measure K₀ K₀ = 1`."] def haar_measure (K₀ : positive_compacts G) : measure G := ((haar_content K₀).outer_measure K₀)⁻¹ • (haar_content K₀).measure @[to_additive] lemma haar_measure_apply {K₀ : positive_compacts G} {s : set G} (hs : measurable_set s) : haar_measure K₀ s = (haar_content K₀).outer_measure s / (haar_content K₀).outer_measure K₀ := begin change (((haar_content K₀).outer_measure) K₀)⁻¹ * (haar_content K₀).measure s = _, simp only [hs, div_eq_mul_inv, mul_comm, content.measure_apply], end @[to_additive] instance is_mul_left_invariant_haar_measure (K₀ : positive_compacts G) : is_mul_left_invariant (haar_measure K₀) := begin rw [← forall_measure_preimage_mul_iff], intros g A hA, rw [haar_measure_apply hA, haar_measure_apply (measurable_const_mul g hA)], congr' 1, apply content.is_mul_left_invariant_outer_measure, apply is_left_invariant_haar_content, end @[to_additive] lemma haar_measure_self {K₀ : positive_compacts G} : haar_measure K₀ K₀ = 1 := begin haveI : locally_compact_space G := K₀.locally_compact_space_of_group, rw [haar_measure_apply K₀.is_compact.measurable_set, ennreal.div_self], { rw [← pos_iff_ne_zero], exact haar_content_outer_measure_self_pos }, { exact (content.outer_measure_lt_top_of_is_compact _ K₀.is_compact).ne } end /-- The Haar measure is regular. -/ @[to_additive "The additive Haar measure is regular."] instance regular_haar_measure {K₀ : positive_compacts G} : (haar_measure K₀).regular := begin haveI : locally_compact_space G := K₀.locally_compact_space_of_group, apply regular.smul, rw ennreal.inv_ne_top, exact haar_content_outer_measure_self_pos.ne', end /-- The Haar measure is sigma-finite in a second countable group. -/ @[to_additive "The additive Haar measure is sigma-finite in a second countable group."] instance sigma_finite_haar_measure [second_countable_topology G] {K₀ : positive_compacts G} : sigma_finite (haar_measure K₀) := by { haveI : locally_compact_space G := K₀.locally_compact_space_of_group, apply_instance, } /-- The Haar measure is a Haar measure, i.e., it is invariant and gives finite mass to compact sets and positive mass to nonempty open sets. -/ @[to_additive "The additive Haar measure is an additive Haar measure, i.e., it is invariant and gives finite mass to compact sets and positive mass to nonempty open sets."] instance is_haar_measure_haar_measure (K₀ : positive_compacts G) : is_haar_measure (haar_measure K₀) := begin apply is_haar_measure_of_is_compact_nonempty_interior (haar_measure K₀) K₀ K₀.is_compact K₀.interior_nonempty, { simp only [haar_measure_self], exact one_ne_zero }, { simp only [haar_measure_self], exact ennreal.coe_ne_top }, end /-- `haar` is some choice of a Haar measure, on a locally compact group. -/ @[reducible, to_additive "`add_haar` is some choice of a Haar measure, on a locally compact additive group."] def haar [locally_compact_space G] : measure G := haar_measure $ classical.arbitrary _ section second_countable variables [second_countable_topology G] /-- The Haar measure is unique up to scaling. More precisely: every σ-finite left invariant measure is a scalar multiple of the Haar measure. This is slightly weaker than assuming that `μ` is a Haar measure (in particular we don't require `μ ≠ 0`). -/ @[to_additive "The additive Haar measure is unique up to scaling. More precisely: every σ-finite left invariant measure is a scalar multiple of the additive Haar measure. This is slightly weaker than assuming that `μ` is an additive Haar measure (in particular we don't require `μ ≠ 0`)."] theorem haar_measure_unique (μ : measure G) [sigma_finite μ] [is_mul_left_invariant μ] (K₀ : positive_compacts G) : μ = μ K₀ • haar_measure K₀ := (measure_eq_div_smul μ (haar_measure K₀) K₀.is_compact.measurable_set (measure_pos_of_nonempty_interior _ K₀.interior_nonempty).ne' K₀.is_compact.measure_lt_top.ne).trans (by rw [haar_measure_self, div_one]) example [locally_compact_space G] (μ : measure G) [is_haar_measure μ] (K₀ : positive_compacts G) : μ = μ K₀.1 • haar_measure K₀ := haar_measure_unique μ K₀ /-- To show that an invariant σ-finite measure is regular it is sufficient to show that it is finite on some compact set with non-empty interior. -/ @[to_additive "To show that an invariant σ-finite measure is regular it is sufficient to show that it is finite on some compact set with non-empty interior."] theorem regular_of_is_mul_left_invariant {μ : measure G} [sigma_finite μ] [is_mul_left_invariant μ] {K : set G} (hK : is_compact K) (h2K : (interior K).nonempty) (hμK : μ K ≠ ∞) : regular μ := by { rw [haar_measure_unique μ ⟨⟨K, hK⟩, h2K⟩], exact regular.smul hμK } @[to_additive is_add_haar_measure_eq_smul_is_add_haar_measure] theorem is_haar_measure_eq_smul_is_haar_measure [locally_compact_space G] (μ ν : measure G) [is_haar_measure μ] [is_haar_measure ν] : ∃ (c : ℝ≥0∞), c ≠ 0 ∧ c ≠ ∞ ∧ μ = c • ν := begin have K : positive_compacts G := classical.arbitrary _, have νpos : 0 < ν K := measure_pos_of_nonempty_interior _ K.interior_nonempty, have νne : ν K ≠ ∞ := K.is_compact.measure_lt_top.ne, refine ⟨μ K / ν K, _, _, _⟩, { simp only [νne, (μ.measure_pos_of_nonempty_interior K.interior_nonempty).ne', ne.def, ennreal.div_zero_iff, not_false_iff, or_self] }, { simp only [div_eq_mul_inv, νpos.ne', (K.is_compact.measure_lt_top).ne, or_self, ennreal.inv_eq_top, with_top.mul_eq_top_iff, ne.def, not_false_iff, and_false, false_and] }, { calc μ = μ K • haar_measure K : haar_measure_unique μ K ... = (μ K / ν K) • (ν K • haar_measure K) : by rw [smul_smul, div_eq_mul_inv, mul_assoc, ennreal.inv_mul_cancel νpos.ne' νne, mul_one] ... = (μ K / ν K) • ν : by rw ← haar_measure_unique ν K } end @[priority 90, to_additive] -- see Note [lower instance priority] instance regular_of_is_haar_measure [locally_compact_space G] (μ : measure G) [is_haar_measure μ] : regular μ := begin have K : positive_compacts G := classical.arbitrary _, obtain ⟨c, c0, ctop, hμ⟩ : ∃ (c : ℝ≥0∞), (c ≠ 0) ∧ (c ≠ ∞) ∧ (μ = c • haar_measure K) := is_haar_measure_eq_smul_is_haar_measure μ _, rw hμ, exact regular.smul ctop, end /-- **Steinhaus Theorem** In any locally compact group `G` with a haar measure `μ`, for any measurable set `E` of positive measure, the set `E / E` is a neighbourhood of `1`. -/ @[to_additive "**Steinhaus Theorem** In any locally compact group `G` with a haar measure `μ`, for any measurable set `E` of positive measure, the set `E - E` is a neighbourhood of `0`."] theorem div_mem_nhds_one_of_haar_pos (μ : measure G) [is_haar_measure μ] [locally_compact_space G] (E : set G) (hE : measurable_set E) (hEpos : 0 < μ E) : E / E ∈ 𝓝 (1 : G) := begin /- For any regular measure `μ` and set `E` of positive measure, we can find a compact set `K` of positive measure inside `E`. Further, for any outer regular measure `μ` there exists an open set `U` containing `K` with measure arbitrarily close to `K` (here `μ U < 2 * μ K` suffices). Then, we can pick an open neighborhood of `1`, say `V` such that such that `V * K` is contained in `U`. Now note that for any `v` in `V`, the sets `K` and `{v} * K` can not be disjoint because they are both of measure `μ K` (since `μ` is left regular) and also contained in `U`, yet we have that `μ U < 2 * μ K`. This show that `K / K` contains the neighborhood `V` of `1`, and therefore that it is itself such a neighborhood. -/ obtain ⟨L, hL, hLE, hLpos, hLtop⟩ : ∃ (L : set G), measurable_set L ∧ L ⊆ E ∧ 0 < μ L ∧ μ L < ∞, from exists_subset_measure_lt_top hE hEpos, obtain ⟨K, hKL, hK, hKpos⟩ : ∃ (K : set G) (H : K ⊆ L), is_compact K ∧ 0 < μ K, from measurable_set.exists_lt_is_compact_of_ne_top hL (ne_of_lt hLtop) hLpos, have hKtop : μ K ≠ ∞, { apply ne_top_of_le_ne_top (ne_of_lt hLtop), apply measure_mono hKL }, obtain ⟨U, hUK, hU, hμUK⟩ : ∃ (U : set G) (H : U ⊇ K), is_open U ∧ μ U < μ K + μ K, from set.exists_is_open_lt_add K hKtop hKpos.ne', obtain ⟨V, hV1, hVKU⟩ : ∃ (V ∈ 𝓝 (1 : G)), V * K ⊆ U, from compact_open_separated_mul_left hK hU hUK, have hv : ∀ (v : G), v ∈ V → ¬ disjoint ({v}* K) K, { intros v hv hKv, have hKvsub : {v} * K ∪ K ⊆ U, { apply set.union_subset _ hUK, apply subset_trans _ hVKU, apply set.mul_subset_mul _ (set.subset.refl K), simp only [set.singleton_subset_iff, hv] }, replace hKvsub := @measure_mono _ _ μ _ _ hKvsub, have hcontr := lt_of_le_of_lt hKvsub hμUK, rw measure_union hKv (is_compact.measurable_set hK) at hcontr, have hKtranslate : μ ({v} * K) = μ K, by simp only [singleton_mul, image_mul_left, measure_preimage_mul], rw [hKtranslate, lt_self_iff_false] at hcontr, assumption }, suffices : V ⊆ E / E, from filter.mem_of_superset hV1 this, assume v hvV, obtain ⟨x, hxK, hxvK⟩ : ∃ (x : G), x ∈ {v} * K ∧ x ∈ K, from set.not_disjoint_iff.1 (hv v hvV), refine ⟨x, v⁻¹ * x, hLE (hKL hxvK), _, _⟩, { apply hKL.trans hLE, simpa only [singleton_mul, image_mul_left, mem_preimage] using hxK }, { simp only [div_eq_iff_eq_mul, ← mul_assoc, mul_right_inv, one_mul] }, end end second_countable end group section comm_group variables {G : Type*} [comm_group G] [topological_space G] [topological_group G] [t2_space G] [measurable_space G] [borel_space G] [second_countable_topology G] (μ : measure G) [is_haar_measure μ] /-- Any Haar measure is invariant under inversion in an abelian group. -/ @[priority 100, to_additive "Any additive Haar measure is invariant under negation in an abelian group."] instance is_haar_measure.is_inv_invariant [locally_compact_space G] : is_inv_invariant μ := begin -- the image measure is a Haar measure. By uniqueness up to multiplication, it is of the form -- `c μ`. Applying again inversion, one gets the measure `c^2 μ`. But since inversion is an -- involution, this is also `μ`. Hence, `c^2 = 1`, which implies `c = 1`. constructor, haveI : is_haar_measure (measure.map has_inv.inv μ) := (mul_equiv.inv G).is_haar_measure_map μ continuous_inv continuous_inv, obtain ⟨c, cpos, clt, hc⟩ : ∃ (c : ℝ≥0∞), (c ≠ 0) ∧ (c ≠ ∞) ∧ (measure.map has_inv.inv μ = c • μ) := is_haar_measure_eq_smul_is_haar_measure _ _, have : map has_inv.inv (map has_inv.inv μ) = c^2 • μ, by simp only [hc, smul_smul, pow_two, measure.map_smul], have μeq : μ = c^2 • μ, { rw [map_map continuous_inv.measurable continuous_inv.measurable] at this, { simpa only [inv_involutive, involutive.comp_self, map_id] }, all_goals { apply_instance } }, have K : positive_compacts G := classical.arbitrary _, have : c^2 * μ K = 1^2 * μ K, by { conv_rhs { rw μeq }, simp, }, have : c^2 = 1^2 := (ennreal.mul_eq_mul_right (measure_pos_of_nonempty_interior _ K.interior_nonempty).ne' K.is_compact.measure_lt_top.ne).1 this, have : c = 1 := (ennreal.pow_strict_mono two_ne_zero).injective this, rw [measure.inv, hc, this, one_smul] end @[to_additive] lemma measure_preserving_zpow [compact_space G] [rootable_by G ℤ] {n : ℤ} (hn : n ≠ 0) : measure_preserving (λ (g : G), g^n) μ μ := { measurable := (continuous_zpow n).measurable, map_eq := begin let f := @zpow_group_hom G _ n, have hf : continuous f := continuous_zpow n, haveI : (μ.map f).is_haar_measure := is_haar_measure_map μ f hf (rootable_by.surjective_pow G ℤ hn) (by simp), obtain ⟨C, -, -, hC⟩ := is_haar_measure_eq_smul_is_haar_measure (μ.map f) μ, suffices : C = 1, { rwa [this, one_smul] at hC, }, have h_univ : (μ.map f) univ = μ univ, { rw [map_apply_of_ae_measurable hf.measurable.ae_measurable measurable_set.univ, preimage_univ], }, have hμ₀ : μ univ ≠ 0 := is_open_pos_measure.open_pos univ is_open_univ univ_nonempty, have hμ₁ : μ univ ≠ ∞ := compact_space.is_finite_measure.measure_univ_lt_top.ne, rwa [hC, smul_apply, algebra.id.smul_eq_mul, mul_comm, ← ennreal.eq_div_iff hμ₀ hμ₁, ennreal.div_self hμ₀ hμ₁] at h_univ, end, } @[to_additive] lemma measure_preserving.zpow [compact_space G] [rootable_by G ℤ] {n : ℤ} (hn : n ≠ 0) {X : Type*} [measurable_space X] {μ' : measure X} {f : X → G} (hf : measure_preserving f μ' μ) : measure_preserving (λ x, (f x)^n) μ' μ := (measure_preserving_zpow μ hn).comp hf end comm_group end measure end measure_theory
c0436d1f769984ebffa37e610d0f059742ea9098
26ac254ecb57ffcb886ff709cf018390161a9225
/src/algebra/group/units.lean
53a89033992994f69ecc6ee21bb6a435dfb48b6c
[ "Apache-2.0" ]
permissive
eric-wieser/mathlib
42842584f584359bbe1fc8b88b3ff937c8acd72d
d0df6b81cd0920ad569158c06a3fd5abb9e63301
refs/heads/master
1,669,546,404,255
1,595,254,668,000
1,595,254,668,000
281,173,504
0
0
Apache-2.0
1,595,263,582,000
1,595,263,581,000
null
UTF-8
Lean
false
false
11,576
lean
/- Copyright (c) 2017 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johannes Hölzl, Chris Hughes, Jens Wagemaker -/ import algebra.group.basic /-! # Units (i.e., invertible elements) of a multiplicative monoid -/ universe u variable {α : Type u} /-- Units of a monoid, bundled version. An element of a `monoid` is a unit if it has a two-sided inverse. This version bundles the inverse element so that it can be computed. For a predicate see `is_unit`. -/ structure units (α : Type u) [monoid α] := (val : α) (inv : α) (val_inv : val * inv = 1) (inv_val : inv * val = 1) /-- Units of an add_monoid, bundled version. An element of an add_monoid is a unit if it has a two-sided additive inverse. This version bundles the inverse element so that it can be computed. For a predicate see `is_add_unit`. -/ structure add_units (α : Type u) [add_monoid α] := (val : α) (neg : α) (val_neg : val + neg = 0) (neg_val : neg + val = 0) attribute [to_additive add_units] units namespace units variables [monoid α] @[to_additive] instance : has_coe (units α) α := ⟨val⟩ @[simp, to_additive] lemma coe_mk (a : α) (b h₁ h₂) : ↑(units.mk a b h₁ h₂) = a := rfl @[ext, to_additive] theorem ext : function.injective (coe : units α → α) | ⟨v, i₁, vi₁, iv₁⟩ ⟨v', i₂, vi₂, iv₂⟩ e := by change v = v' at e; subst v'; congr; simpa only [iv₂, vi₁, one_mul, mul_one] using mul_assoc i₂ v i₁ @[to_additive] theorem ext_iff {a b : units α} : a = b ↔ (a : α) = b := ext.eq_iff.symm @[to_additive] instance [decidable_eq α] : decidable_eq (units α) := λ a b, decidable_of_iff' _ ext_iff /-- Units of a monoid form a group. -/ @[to_additive] instance : group (units α) := { mul := λ u₁ u₂, ⟨u₁.val * u₂.val, u₂.inv * u₁.inv, by rw [mul_assoc, ← mul_assoc u₂.val, val_inv, one_mul, val_inv], by rw [mul_assoc, ← mul_assoc u₁.inv, inv_val, one_mul, inv_val]⟩, one := ⟨1, 1, one_mul 1, one_mul 1⟩, mul_one := λ u, ext $ mul_one u, one_mul := λ u, ext $ one_mul u, mul_assoc := λ u₁ u₂ u₃, ext $ mul_assoc u₁ u₂ u₃, inv := λ u, ⟨u.2, u.1, u.4, u.3⟩, mul_left_inv := λ u, ext u.inv_val } variables (a b : units α) {c : units α} @[simp, norm_cast, to_additive] lemma coe_mul : (↑(a * b) : α) = a * b := rfl attribute [norm_cast] add_units.coe_add @[simp, norm_cast, to_additive] lemma coe_one : ((1 : units α) : α) = 1 := rfl attribute [norm_cast] add_units.coe_zero @[to_additive] lemma val_coe : (↑a : α) = a.val := rfl @[norm_cast, to_additive] lemma coe_inv : ((a⁻¹ : units α) : α) = a.inv := rfl attribute [norm_cast] add_units.coe_neg @[simp, to_additive] lemma inv_mul : (↑a⁻¹ * a : α) = 1 := inv_val _ @[simp, to_additive] lemma mul_inv : (a * ↑a⁻¹ : α) = 1 := val_inv _ @[to_additive] lemma inv_mul_of_eq {u : units α} {a : α} (h : ↑u = a) : ↑u⁻¹ * a = 1 := by { rw [←h, u.inv_mul], } @[to_additive] lemma mul_inv_of_eq {u : units α} {a : α} (h : ↑u = a) : a * ↑u⁻¹ = 1 := by { rw [←h, u.mul_inv], } @[simp, to_additive] lemma mul_inv_cancel_left (a : units α) (b : α) : (a:α) * (↑a⁻¹ * b) = b := by rw [← mul_assoc, mul_inv, one_mul] @[simp, to_additive] lemma inv_mul_cancel_left (a : units α) (b : α) : (↑a⁻¹:α) * (a * b) = b := by rw [← mul_assoc, inv_mul, one_mul] @[simp, to_additive] lemma mul_inv_cancel_right (a : α) (b : units α) : a * b * ↑b⁻¹ = a := by rw [mul_assoc, mul_inv, mul_one] @[simp, to_additive] lemma inv_mul_cancel_right (a : α) (b : units α) : a * ↑b⁻¹ * b = a := by rw [mul_assoc, inv_mul, mul_one] @[to_additive] instance : inhabited (units α) := ⟨1⟩ @[to_additive] instance {α} [comm_monoid α] : comm_group (units α) := { mul_comm := λ u₁ u₂, ext $ mul_comm _ _, ..units.group } @[to_additive] instance [has_repr α] : has_repr (units α) := ⟨repr ∘ val⟩ @[simp, to_additive] theorem mul_right_inj (a : units α) {b c : α} : (a:α) * b = a * c ↔ b = c := ⟨λ h, by simpa only [inv_mul_cancel_left] using congr_arg ((*) ↑(a⁻¹ : units α)) h, congr_arg _⟩ @[simp, to_additive] theorem mul_left_inj (a : units α) {b c : α} : b * a = c * a ↔ b = c := ⟨λ h, by simpa only [mul_inv_cancel_right] using congr_arg (* ↑(a⁻¹ : units α)) h, congr_arg _⟩ @[to_additive] theorem eq_mul_inv_iff_mul_eq {a b : α} : a = b * ↑c⁻¹ ↔ a * c = b := ⟨λ h, by rw [h, inv_mul_cancel_right], λ h, by rw [← h, mul_inv_cancel_right]⟩ @[to_additive] theorem eq_inv_mul_iff_mul_eq {a c : α} : a = ↑b⁻¹ * c ↔ ↑b * a = c := ⟨λ h, by rw [h, mul_inv_cancel_left], λ h, by rw [← h, inv_mul_cancel_left]⟩ @[to_additive] theorem inv_mul_eq_iff_eq_mul {b c : α} : ↑a⁻¹ * b = c ↔ b = a * c := ⟨λ h, by rw [← h, mul_inv_cancel_left], λ h, by rw [h, inv_mul_cancel_left]⟩ @[to_additive] theorem mul_inv_eq_iff_eq_mul {a c : α} : a * ↑b⁻¹ = c ↔ a = c * b := ⟨λ h, by rw [← h, inv_mul_cancel_right], λ h, by rw [h, mul_inv_cancel_right]⟩ lemma inv_eq_of_mul_eq_one {u : units α} {a : α} (h : ↑u * a = 1) : ↑u⁻¹ = a := calc ↑u⁻¹ = ↑u⁻¹ * 1 : by rw mul_one ... = ↑u⁻¹ * ↑u * a : by rw [←h, ←mul_assoc] ... = a : by rw [u.inv_mul, one_mul] lemma inv_unique {u₁ u₂ : units α} (h : (↑u₁ : α) = ↑u₂) : (↑u₁⁻¹ : α) = ↑u₂⁻¹ := suffices ↑u₁ * (↑u₂⁻¹ : α) = 1, by exact inv_eq_of_mul_eq_one this, by rw [h, u₂.mul_inv] end units /-- For `a, b` in a `comm_monoid` such that `a * b = 1`, makes a unit out of `a`. -/ @[to_additive "For `a, b` in an `add_comm_monoid` such that `a + b = 0`, makes an add_unit out of `a`."] def units.mk_of_mul_eq_one [comm_monoid α] (a b : α) (hab : a * b = 1) : units α := ⟨a, b, hab, (mul_comm b a).trans hab⟩ @[simp, to_additive] lemma units.coe_mk_of_mul_eq_one [comm_monoid α] {a b : α} (h : a * b = 1) : (units.mk_of_mul_eq_one a b h : α) = a := rfl section monoid variables [monoid α] {a b c : α} /-- Partial division. It is defined when the second argument is invertible, and unlike the division operator in `division_ring` it is not totalized at zero. -/ def divp (a : α) (u) : α := a * (u⁻¹ : units α) infix ` /ₚ `:70 := divp @[simp] theorem divp_self (u : units α) : (u : α) /ₚ u = 1 := units.mul_inv _ @[simp] theorem divp_one (a : α) : a /ₚ 1 = a := mul_one _ theorem divp_assoc (a b : α) (u : units α) : a * b /ₚ u = a * (b /ₚ u) := mul_assoc _ _ _ @[simp] theorem divp_inv (u : units α) : a /ₚ u⁻¹ = a * u := rfl @[simp] theorem divp_mul_cancel (a : α) (u : units α) : a /ₚ u * u = a := (mul_assoc _ _ _).trans $ by rw [units.inv_mul, mul_one] @[simp] theorem mul_divp_cancel (a : α) (u : units α) : (a * u) /ₚ u = a := (mul_assoc _ _ _).trans $ by rw [units.mul_inv, mul_one] @[simp] theorem divp_left_inj (u : units α) {a b : α} : a /ₚ u = b /ₚ u ↔ a = b := units.mul_left_inj _ theorem divp_divp_eq_divp_mul (x : α) (u₁ u₂ : units α) : (x /ₚ u₁) /ₚ u₂ = x /ₚ (u₂ * u₁) := by simp only [divp, mul_inv_rev, units.coe_mul, mul_assoc] theorem divp_eq_iff_mul_eq {x : α} {u : units α} {y : α} : x /ₚ u = y ↔ y * u = x := u.mul_left_inj.symm.trans $ by rw [divp_mul_cancel]; exact ⟨eq.symm, eq.symm⟩ theorem divp_eq_one_iff_eq {a : α} {u : units α} : a /ₚ u = 1 ↔ a = u := (units.mul_left_inj u).symm.trans $ by rw [divp_mul_cancel, one_mul] @[simp] theorem one_divp (u : units α) : 1 /ₚ u = ↑u⁻¹ := one_mul _ end monoid section comm_monoid variables [comm_monoid α] theorem divp_eq_divp_iff {x y : α} {ux uy : units α} : x /ₚ ux = y /ₚ uy ↔ x * uy = y * ux := by rw [divp_eq_iff_mul_eq, mul_comm, ← divp_assoc, divp_eq_iff_mul_eq, mul_comm y ux] theorem divp_mul_divp (x y : α) (ux uy : units α) : (x /ₚ ux) * (y /ₚ uy) = (x * y) /ₚ (ux * uy) := by rw [← divp_divp_eq_divp_mul, divp_assoc, mul_comm x, divp_assoc, mul_comm] end comm_monoid /-! # `is_unit` predicate In this file we define the `is_unit` predicate on a `monoid`, and prove a few basic properties. For the bundled version see `units`. See also `prime`, `associated`, and `irreducible` in `algebra/associated`. -/ section is_unit variables {M : Type*} {N : Type*} /-- An element `a : M` of a monoid is a unit if it has a two-sided inverse. The actual definition says that `a` is equal to some `u : units M`, where `units M` is a bundled version of `is_unit`. -/ @[to_additive is_add_unit "An element `a : M` of an add_monoid is an `add_unit` if it has a two-sided additive inverse. The actual definition says that `a` is equal to some `u : add_units M`, where `add_units M` is a bundled version of `is_add_unit`."] def is_unit [monoid M] (a : M) : Prop := ∃ u : units M, (u : M) = a @[simp, to_additive is_add_unit_add_unit] lemma is_unit_unit [monoid M] (u : units M) : is_unit (u : M) := ⟨u, rfl⟩ @[simp, to_additive is_add_unit_zero] theorem is_unit_one [monoid M] : is_unit (1:M) := ⟨1, rfl⟩ @[to_additive is_add_unit_of_add_eq_zero] theorem is_unit_of_mul_eq_one [comm_monoid M] (a b : M) (h : a * b = 1) : is_unit a := ⟨units.mk_of_mul_eq_one a b h, rfl⟩ @[to_additive is_add_unit_iff_exists_neg] theorem is_unit_iff_exists_inv [comm_monoid M] {a : M} : is_unit a ↔ ∃ b, a * b = 1 := ⟨by rintro ⟨⟨a, b, hab, _⟩, rfl⟩; exact ⟨b, hab⟩, λ ⟨b, hab⟩, is_unit_of_mul_eq_one _ b hab⟩ @[to_additive is_add_unit_iff_exists_neg'] theorem is_unit_iff_exists_inv' [comm_monoid M] {a : M} : is_unit a ↔ ∃ b, b * a = 1 := by simp [is_unit_iff_exists_inv, mul_comm] /-- Multiplication by a `u : units M` doesn't affect `is_unit`. -/ @[simp, to_additive is_add_unit_add_add_units "Addition of a `u : add_units M` doesn't affect `is_add_unit`."] theorem units.is_unit_mul_units [monoid M] (a : M) (u : units M) : is_unit (a * u) ↔ is_unit a := iff.intro (assume ⟨v, hv⟩, have is_unit (a * ↑u * ↑u⁻¹), by existsi v * u⁻¹; rw [←hv, units.coe_mul], by rwa [mul_assoc, units.mul_inv, mul_one] at this) (assume ⟨v, hv⟩, hv ▸ ⟨v * u, (units.coe_mul v u).symm⟩) lemma is_unit.mul [monoid M] {x y : M} : is_unit x → is_unit y → is_unit (x * y) := by { rintros ⟨x, rfl⟩ ⟨y, rfl⟩, exact ⟨x * y, units.coe_mul _ _⟩ } @[to_additive is_add_unit_of_add_is_add_unit_left] theorem is_unit_of_mul_is_unit_left [comm_monoid M] {x y : M} (hu : is_unit (x * y)) : is_unit x := let ⟨z, hz⟩ := is_unit_iff_exists_inv.1 hu in is_unit_iff_exists_inv.2 ⟨y * z, by rwa ← mul_assoc⟩ @[to_additive] theorem is_unit_of_mul_is_unit_right [comm_monoid M] {x y : M} (hu : is_unit (x * y)) : is_unit y := @is_unit_of_mul_is_unit_left _ _ y x $ by rwa mul_comm @[to_additive] theorem is_unit.mul_right_inj [monoid M] {a b c : M} (ha : is_unit a) : a * b = a * c ↔ b = c := by cases ha with a ha; rw [←ha, units.mul_right_inj] @[to_additive] theorem is_unit.mul_left_inj [monoid M] {a b c : M} (ha : is_unit a) : b * a = c * a ↔ b = c := by cases ha with a ha; rw [←ha, units.mul_left_inj] /-- The element of the group of units, corresponding to an element of a monoid which is a unit. -/ noncomputable def is_unit.unit [monoid M] {a : M} (h : is_unit a) : units M := classical.some h lemma is_unit.unit_spec [monoid M] {a : M} (h : is_unit a) : ↑h.unit = a := classical.some_spec h end is_unit
bc95300f9a2755f9567619ea1b2057a873a731d4
54deab7025df5d2df4573383df7e1e5497b7a2c2
/data/rat.lean
4e62dd74d1cfddae34725eff688497d4381528b7
[ "Apache-2.0" ]
permissive
HGldJ1966/mathlib
f8daac93a5b4ae805cfb0ecebac21a9ce9469009
c5c5b504b918a6c5e91e372ee29ed754b0513e85
refs/heads/master
1,611,340,395,683
1,503,040,489,000
1,503,040,489,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
23,843
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 Introduces the rational numbers as discrete, linear ordered field. -/ import data.nat.gcd data.pnat data.int.basic pending /- linorder -/ section linear_order_cases_on universes u v variables {α : Type u} [decidable_linear_order α] {β : Sort v} def linear_order_cases_on (a b : α) (h_eq : a = b → β) (h_lt : a < b → β) (h_gt : a > b → β) : β := if h₁ : a = b then h_eq h₁ else if h₂ : a < b then h_lt h₂ else h_gt ((lt_or_gt_of_ne h₁).resolve_left h₂) variables {a b : α} {h_eq : a = b → β} {h_lt : a < b → β} {h_gt : a > b → β} @[simp] theorem linear_order_cases_on_eq (h : a = b) : linear_order_cases_on a b h_eq h_lt h_gt = h_eq h := dif_pos h @[simp] theorem linear_order_cases_on_lt (h : a < b) : linear_order_cases_on a b h_eq h_lt h_gt = h_lt h := eq.trans (dif_neg $ ne_of_lt h) $ dif_pos h @[simp] theorem linear_order_cases_on_gt (h : a > b) : linear_order_cases_on a b h_eq h_lt h_gt = h_gt h := eq.trans (dif_neg $ (ne_of_lt h).symm) (dif_neg $ not_lt_of_ge $ le_of_lt h) end linear_order_cases_on /- linorder ring -/ section ordered_ring universes u variables {α : Type u} [linear_ordered_ring α] {a b : α} theorem mul_nonneg_iff_right_nonneg_of_pos (h : 0 < a) : 0 ≤ b * a ↔ 0 ≤ b := ⟨assume : 0 ≤ b * a, nonneg_of_mul_nonneg_right this h, assume : 0 ≤ b, mul_nonneg this $ le_of_lt h⟩ end ordered_ring /- rational numbers -/ structure rat := mk' :: (num : ℤ) (denom : ℕ) (pos : denom > 0) (cop : num.nat_abs.coprime denom) notation `ℚ` := rat namespace rat def of_int (n : ℤ) : ℚ := ⟨n, 1, nat.one_pos, nat.coprime_one_right _⟩ instance coe_int_rat : has_coe ℤ ℚ := ⟨of_int⟩ instance coe_nat_rat : has_coe ℕ ℚ := ⟨of_int ∘ int.of_nat⟩ instance : has_zero ℚ := ⟨(0 : ℤ)⟩ instance : has_one ℚ := ⟨(1 : ℤ)⟩ def mk_pnat (n : ℤ) : ℕ+ → ℚ | ⟨d, dpos⟩ := let n' := n.nat_abs, g := n'.gcd d in ⟨n / g, d / g, begin apply (nat.le_div_iff_mul_le _ _ (nat.gcd_pos_of_pos_right _ dpos)).2, simp, exact nat.le_of_dvd dpos (nat.gcd_dvd_right _ _) end, begin have : int.nat_abs (n / ↑g) = n' / g, { cases int.nat_abs_eq n with e e; rw e, { refl }, rw [int.neg_div_of_dvd, int.nat_abs_neg], { refl }, exact int.coe_nat_dvd_coe_nat_of_dvd (nat.gcd_dvd_left _ _) }, rw this, exact nat.coprime_div_gcd_div_gcd (nat.gcd_pos_of_pos_right _ dpos) end⟩ def mk_nat (n : ℤ) (d : ℕ) : ℚ := if d0 : d = 0 then 0 else mk_pnat n ⟨d, nat.pos_of_ne_zero d0⟩ def mk : ℤ → ℤ → ℚ | n (int.of_nat d) := mk_nat n d | n -[1+ d] := mk_pnat (-n) d.succ_pnat local infix ` /. `:70 := mk theorem mk_pnat_eq (n d h) : mk_pnat n ⟨d, h⟩ = n /. d := by change n /. d with dite _ _ _; simp [ne_of_gt h] theorem mk_nat_eq (n d) : mk_nat n d = n /. d := rfl @[simp] theorem mk_zero (n) : n /. 0 = 0 := rfl @[simp] theorem zero_mk_pnat (n) : mk_pnat 0 n = 0 := by cases n; simp [mk_pnat]; change int.nat_abs 0 with 0; simp *; refl @[simp] theorem zero_mk_nat (n) : mk_nat 0 n = 0 := by by_cases n = 0; simp [*, mk_nat] @[simp] theorem zero_mk (n) : 0 /. n = 0 := by cases n; simp [mk] private lemma gcd_abs_eq_left {a b} : (nat.gcd (int.nat_abs a) b : ℤ) ∣ a := int.coe_nat_dvd_right.1 (int.coe_nat_dvd_coe_nat_of_dvd $ nat.gcd_dvd_left (int.nat_abs a) b) @[simp] theorem mk_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 := begin constructor; intro h; [skip, {subst a, simp}], have : ∀ {a b}, mk_pnat a b = 0 → a = 0, { intros a b e, cases b with b h, injection e with e, apply int.eq_mul_of_div_eq_right gcd_abs_eq_left e }, cases b with b; simp [mk, mk_nat] at h, { simp [mt (congr_arg int.of_nat) b0] at h, exact this h }, { apply neg_inj, simp [this h] } end theorem mk_eq : ∀ {a b c d : ℤ} (hb : b ≠ 0) (hd : d ≠ 0), a /. b = c /. d ↔ a * d = c * b := suffices ∀ a b c d hb hd, mk_pnat a ⟨b, hb⟩ = mk_pnat c ⟨d, hd⟩ ↔ a * d = c * b, begin intros, cases b with b b; simp [mk, mk_nat, nat.succ_pnat], simp [mt (congr_arg int.of_nat) hb], all_goals { cases d with d d; simp [mk, mk_nat, nat.succ_pnat], simp [mt (congr_arg int.of_nat) hd], all_goals { rw this, try {refl} } }, { change a * ↑(d.succ) = -c * ↑b ↔ a * -(d.succ) = c * b, constructor; intro h; apply neg_inj; simp at h; simp [h] }, { change -a * ↑d = c * b.succ ↔ a * d = c * -b.succ, constructor; intro h; apply neg_inj; simp at h; simp [h] }, { change -a * d.succ = -c * b.succ ↔ a * -d.succ = c * -b.succ, simp } end, begin intros, simp [mk_pnat], constructor; intro h, { injection h with ha hb, have ha, { have dv := @gcd_abs_eq_left, have := int.eq_mul_of_div_eq_right dv ha, rw ← int.mul_div_assoc _ dv at this, exact int.eq_mul_of_div_eq_left (dvd_mul_of_dvd_right dv _) this.symm }, have hb, { have dv := λ {a b}, nat.gcd_dvd_right (int.nat_abs a) b, have := nat.eq_mul_of_div_eq_right dv hb, rw ← nat.mul_div_assoc _ dv at this, exact nat.eq_mul_of_div_eq_left (dvd_mul_of_dvd_right dv _) this.symm }, apply eq_of_mul_eq_mul_right _, { rw [mul_assoc, mul_assoc], have := congr (congr_arg (*) ha.symm) (congr_arg coe hb), simp [int.coe_nat_mul] at this, assumption }, { apply mt int.coe_nat_inj, apply ne_of_gt, apply mul_pos; apply nat.gcd_pos_of_pos_right; assumption } }, { have : ∀ a c, a * d = c * b → a / nat.gcd a b = c / nat.gcd c d ∧ b / nat.gcd a b = d / nat.gcd c d, { intros a c h, have bd : b / nat.gcd a b = d / nat.gcd c d, { have : ∀ {a c} (b>0) (d>0), a * d = c * b → b / nat.gcd a b ≤ d / nat.gcd c d, tactic.swap, { exact le_antisymm (this _ hb _ hd h) (this _ hd _ hb h.symm) }, intros a c b hb d hd h, have gb0 := nat.gcd_pos_of_pos_right a hb, have gd0 := nat.gcd_pos_of_pos_right c hd, apply nat.le_of_dvd, apply (nat.le_div_iff_mul_le _ _ gd0).2, simp, apply nat.le_of_dvd hd (nat.gcd_dvd_right _ _), apply nat.dvd_of_coprime_of_dvd_mul_left, exact nat.coprime_swap (nat.coprime_div_gcd_div_gcd gb0), refine ⟨c / c.gcd d, _⟩, rw [← nat.mul_div_assoc _ (nat.gcd_dvd_left _ _), ← nat.mul_div_assoc _ (nat.gcd_dvd_right _ _)], apply congr_arg (/ c.gcd d), rw [mul_comm, ← nat.mul_div_assoc _ (nat.gcd_dvd_left _ _), mul_comm, h, nat.mul_div_assoc _ (nat.gcd_dvd_right _ _), mul_comm] }, refine ⟨_, bd⟩, apply nat.eq_of_mul_eq_mul_left hb, rw [← nat.mul_div_assoc _ (nat.gcd_dvd_left _ _), mul_comm, nat.mul_div_assoc _ (nat.gcd_dvd_right _ _), bd, ← nat.mul_div_assoc _ (nat.gcd_dvd_right _ _), h, mul_comm, nat.mul_div_assoc _ (nat.gcd_dvd_left _ _)] }, have ha := this a.nat_abs c.nat_abs begin have := congr_arg int.nat_abs h, simp [int.nat_abs_mul] at this, exact this end, tactic.congr_core, { have hs := congr_arg int.sign h, simp [int.sign_eq_one_of_pos (int.coe_nat_lt_coe_nat_of_lt hb), int.sign_eq_one_of_pos (int.coe_nat_lt_coe_nat_of_lt hd)] at hs, conv in a { rw ← int.sign_mul_nat_abs a }, conv in c { rw ← int.sign_mul_nat_abs c }, rw [int.mul_div_assoc, int.mul_div_assoc], exact congr (congr_arg (*) hs) (congr_arg coe ha.left), all_goals { exact int.coe_nat_dvd_coe_nat_of_dvd (nat.gcd_dvd_left _ _) } }, { exact ha.right } } end @[simp] theorem div_mk_div_cancel_left {a b c : ℤ} (c0 : c ≠ 0) : (a * c) /. (b * c) = a /. b := begin by_cases b = 0 with b0, { subst b0, simp }, apply (mk_eq (mul_ne_zero b0 c0) b0).2, simp end theorem num_denom : ∀ a : ℚ, a = a.num /. a.denom | ⟨n, d, h, (c:_=1)⟩ := begin change _ = mk_nat n d, simp [mk_nat, ne_of_gt h, mk_pnat], tactic.congr_core; `[rw c, simp [int.coe_nat_one]] end theorem num_denom' (n d h c) : (⟨n, d, h, c⟩ : ℚ) = n /. d := num_denom _ @[elab_as_eliminator] theorem {u} num_denom_cases_on {C : ℚ → Sort u} : ∀ (a : ℚ) (H : ∀ n d, d > 0 → (int.nat_abs n).coprime d → C (n /. d)), C a | ⟨n, d, h, c⟩ H := by rw num_denom'; exact H n d h c @[elab_as_eliminator] theorem {u} num_denom_cases_on' {C : ℚ → Sort u} (a : ℚ) (H : ∀ (n:ℤ) (d:ℕ), (d:ℤ) ≠ 0 → C (n /. d)) : C a := num_denom_cases_on a $ λ n d h c, H n d $ ne_of_gt (int.coe_nat_lt_coe_nat_of_lt h) protected def add : ℚ → ℚ → ℚ | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := mk_pnat (n₁ * d₂ + n₂ * d₁) ⟨d₁ * d₂, mul_pos h₁ h₂⟩ instance : has_add ℚ := ⟨rat.add⟩ theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ → ℤ → ℤ) (f₂ : ℤ → ℤ → ℤ → ℤ → ℤ) (fv : ∀ {n₁ d₁ h₁ c₁ n₂ d₂ h₂ c₂}, f ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ = f₁ n₁ d₁ n₂ d₂ /. f₂ n₁ d₁ n₂ d₂) (f0 : ∀ {n₁ d₁ n₂ d₂} (d₁0 : d₁ ≠ 0) (d₂0 : d₂ ≠ 0), f₂ n₁ d₁ n₂ d₂ ≠ 0) (a b c d : ℤ) (b0 : b ≠ 0) (d0 : d ≠ 0) (H : ∀ {n₁ d₁ n₂ d₂} (h₁ : a * d₁ = n₁ * b) (h₂ : c * d₂ = n₂ * d), f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂) : f (a /. b) (c /. d) = f₁ a b c d /. f₂ a b c d := begin generalize ha : a /. b = x, cases x with n₁ d₁ h₁ c₁, rw num_denom' at ha, generalize hc : c /. d = x, cases x with n₂ d₂ h₂ c₂, rw num_denom' at hc, rw fv, have d₁0 := ne_of_gt (int.coe_nat_lt_coe_nat_of_lt h₁), have d₂0 := ne_of_gt (int.coe_nat_lt_coe_nat_of_lt h₂), exact (mk_eq (f0 d₁0 d₂0) (f0 b0 d0)).2 (H ((mk_eq b0 d₁0).1 ha) ((mk_eq d0 d₂0).1 hc)) end @[simp] theorem add_def {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) : a /. b + c /. d = (a * d + c * b) /. (b * d) := begin apply lift_binop_eq rat.add; intros; try {assumption}, { apply mk_pnat_eq }, { apply mul_ne_zero d₁0 d₂0 }, calc (n₁ * d₂ + n₂ * d₁) * (b * d) = (n₁ * b) * d₂ * d + (n₂ * d) * (d₁ * b) : by simp [mul_add, add_mul] ... = (a * d₁) * d₂ * d + (c * d₂) * (d₁ * b) : by rw [h₁, h₂] ... = (a * d + c * b) * (d₁ * d₂) : by simp [mul_add, add_mul] end protected def neg : ℚ → ℚ | ⟨n, d, h, c⟩ := ⟨-n, d, h, by simp [c]⟩ instance : has_neg ℚ := ⟨rat.neg⟩ @[simp] theorem neg_def {a b : ℤ} : -(a /. b) = -a /. b := begin by_cases b = 0 with b0, { subst b0, simp, refl }, generalize ha : a /. b = x, cases x with n₁ d₁ h₁ c₁, rw num_denom' at ha, show rat.mk' _ _ _ _ = _, rw num_denom', have d0 := ne_of_gt (int.coe_nat_lt_coe_nat_of_lt h₁), apply (mk_eq d0 b0).2, have h₁ := (mk_eq b0 d0).1 ha, simp only [neg_mul_eq_neg_mul_symm, congr_arg has_neg.neg h₁] end protected def mul : ℚ → ℚ → ℚ | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := mk_pnat (n₁ * n₂) ⟨d₁ * d₂, mul_pos h₁ h₂⟩ instance : has_mul ℚ := ⟨rat.mul⟩ @[simp] theorem mul_def {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) : (a /. b) * (c /. d) = (a * c) /. (b * d) := begin apply lift_binop_eq rat.mul; intros; try {assumption}, { apply mk_pnat_eq }, { apply mul_ne_zero d₁0 d₂0 }, cc end protected def inv : ℚ → ℚ | ⟨(n+1:ℕ), d, h, c⟩ := ⟨d, n+1, n.succ_pos, nat.coprime_swap c⟩ | ⟨0, d, h, c⟩ := 0 | ⟨-[1+ n], d, h, c⟩ := ⟨-d, n+1, n.succ_pos, nat.coprime_swap $ by simp; exact c⟩ instance : has_inv ℚ := ⟨rat.inv⟩ @[simp] theorem inv_def {a b : ℤ} : (a /. b)⁻¹ = b /. a := begin by_cases a = 0 with a0, { subst a0, simp, refl }, by_cases b = 0 with b0, { subst b0, simp, refl }, generalize ha : a /. b = x, cases x with n d h c, rw num_denom' at ha, refine eq.trans (_ : rat.inv ⟨n, d, h, c⟩ = d /. n) _, { cases n with n; [cases n with n, skip], { refl }, { change int.of_nat n.succ with (n+1:ℕ), simp [rat.inv], rw num_denom' }, { simp [rat.inv], rw num_denom', refl } }, have n0 : n ≠ 0, { refine mt (λ (n0 : n = 0), _) a0, subst n0, simp at ha, exact (mk_eq_zero b0).1 ha }, have d0 := ne_of_gt (int.coe_nat_lt_coe_nat_of_lt h), have ha := (mk_eq b0 d0).1 ha, apply (mk_eq n0 a0).2, cc end variables (a b c : ℚ) protected theorem add_zero : a + 0 = a := num_denom_cases_on' a $ λ n d h, by rw [← zero_mk d]; simp [h, -zero_mk] protected theorem zero_add : 0 + a = a := num_denom_cases_on' a $ λ n d h, by rw [← zero_mk d]; simp [h, -zero_mk] protected theorem add_comm : a + b = b + a := num_denom_cases_on' a $ λ n₁ d₁ h₁, num_denom_cases_on' b $ λ n₂ d₂ h₂, by simp [h₁, h₂] protected theorem add_assoc : a + b + c = a + (b + c) := num_denom_cases_on' a $ λ n₁ d₁ h₁, num_denom_cases_on' b $ λ n₂ d₂ h₂, num_denom_cases_on' c $ λ n₃ d₃ h₃, by simp [h₁, h₂, h₃, mul_ne_zero, mul_add] protected theorem add_left_neg : -a + a = 0 := num_denom_cases_on' a $ λ n d h, by simp [h] protected theorem mul_one : a * 1 = a := num_denom_cases_on' a $ λ n d h, by change (1:ℚ) with 1 /. 1; simp [h] protected theorem one_mul : 1 * a = a := num_denom_cases_on' a $ λ n d h, by change (1:ℚ) with 1 /. 1; simp [h] protected theorem mul_comm : a * b = b * a := num_denom_cases_on' a $ λ n₁ d₁ h₁, num_denom_cases_on' b $ λ n₂ d₂ h₂, by simp [h₁, h₂] protected theorem mul_assoc : a * b * c = a * (b * c) := num_denom_cases_on' a $ λ n₁ d₁ h₁, num_denom_cases_on' b $ λ n₂ d₂ h₂, num_denom_cases_on' c $ λ n₃ d₃ h₃, by simp [h₁, h₂, h₃, mul_ne_zero] protected theorem add_mul : (a + b) * c = a * c + b * c := num_denom_cases_on' a $ λ n₁ d₁ h₁, num_denom_cases_on' b $ λ n₂ d₂ h₂, num_denom_cases_on' c $ λ n₃ d₃ h₃, by simp [h₁, h₂, h₃, mul_ne_zero]; refine (div_mk_div_cancel_left h₃).symm.trans _; simp [mul_add] protected theorem mul_add : a * (b + c) = a * b + a * c := by rw [rat.mul_comm, rat.add_mul, rat.mul_comm, rat.mul_comm c a] protected theorem zero_ne_one : 0 ≠ (1:ℚ) := mt (λ (h : 0 = 1 /. 1), (mk_eq_zero one_ne_zero).1 h.symm) one_ne_zero protected theorem mul_inv_cancel : a ≠ 0 → a * a⁻¹ = 1 := num_denom_cases_on' a $ λ n d h a0, have n0 : n ≠ 0, from mt (by intro e; subst e; simp) a0, by simp [h, n0]; exact eq.trans (by simp) (@div_mk_div_cancel_left 1 1 _ n0) protected theorem inv_mul_cancel (h : a ≠ 0) : a⁻¹ * a = 1 := eq.trans (rat.mul_comm _ _) (rat.mul_inv_cancel _ h) instance : decidable_eq ℚ := by tactic.mk_dec_eq_instance instance field_rat : discrete_field ℚ := { zero := 0, add := rat.add, neg := rat.neg, one := 1, mul := rat.mul, inv := rat.inv, zero_add := rat.zero_add, add_zero := rat.add_zero, add_comm := rat.add_comm, add_assoc := rat.add_assoc, add_left_neg := rat.add_left_neg, mul_one := rat.mul_one, one_mul := rat.one_mul, mul_comm := rat.mul_comm, mul_assoc := rat.mul_assoc, left_distrib := rat.mul_add, right_distrib := rat.add_mul, zero_ne_one := rat.zero_ne_one, mul_inv_cancel := rat.mul_inv_cancel, inv_mul_cancel := rat.inv_mul_cancel, has_decidable_eq := rat.decidable_eq, inv_zero := rfl } protected def nonneg : ℚ → Prop | ⟨n, d, h, c⟩ := n ≥ 0 @[simp] theorem mk_nonneg (a : ℤ) {b : ℤ} (h : b > 0) : (a /. b).nonneg ↔ a ≥ 0 := begin generalize ha : a /. b = x, cases x with n₁ d₁ h₁ c₁, rw num_denom' at ha, simp [rat.nonneg], have d0 := int.coe_nat_lt_coe_nat_of_lt h₁, have := (mk_eq (ne_of_gt h) (ne_of_gt d0)).1 ha, constructor; intro h₂, { apply nonneg_of_mul_nonneg_right _ d0, rw this, exact mul_nonneg h₂ (le_of_lt h) }, { apply nonneg_of_mul_nonneg_right _ h, rw ← this, exact mul_nonneg h₂ (int.coe_zero_le _) }, end protected def nonneg_add {a b} : rat.nonneg a → rat.nonneg b → rat.nonneg (a + b) := num_denom_cases_on' a $ λ n₁ d₁ h₁, num_denom_cases_on' b $ λ n₂ d₂ h₂, begin have d₁0 : (d₁:ℤ) > 0 := lt_of_le_of_ne (int.coe_zero_le _) h₁.symm, have d₂0 : (d₂:ℤ) > 0 := lt_of_le_of_ne (int.coe_zero_le _) h₂.symm, simp [d₁0, d₂0, h₁, h₂, mul_pos d₁0 d₂0], intros n₁0 n₂0, apply add_nonneg; apply mul_nonneg; {assumption <|> apply int.coe_zero_le} end protected def nonneg_mul {a b} : rat.nonneg a → rat.nonneg b → rat.nonneg (a * b) := num_denom_cases_on' a $ λ n₁ d₁ h₁, num_denom_cases_on' b $ λ n₂ d₂ h₂, begin have d₁0 : (d₁:ℤ) > 0 := lt_of_le_of_ne (int.coe_zero_le _) h₁.symm, have d₂0 : (d₂:ℤ) > 0 := lt_of_le_of_ne (int.coe_zero_le _) h₂.symm, simp [d₁0, d₂0, h₁, h₂, mul_pos d₁0 d₂0], exact mul_nonneg end protected def nonneg_antisymm {a} : rat.nonneg a → rat.nonneg (-a) → a = 0 := num_denom_cases_on' a $ λ n d h, begin have d0 : (d:ℤ) > 0 := lt_of_le_of_ne (int.coe_zero_le _) h.symm, simp [d0, h], exact λ h₁ h₂, le_antisymm (nonpos_of_neg_nonneg h₂) h₁ end protected def nonneg_total : rat.nonneg a ∨ rat.nonneg (-a) := by cases a with n; exact or.imp_right neg_nonneg_of_nonpos (le_total 0 n) instance decidable_nonneg : decidable (rat.nonneg a) := by cases a; unfold rat.nonneg; apply_instance protected def le (a b : ℚ) := rat.nonneg (b - a) instance : has_le ℚ := ⟨rat.le⟩ instance decidable_le : decidable_rel ((≤) : ℚ → ℚ → Prop) := show ∀ a b, decidable (rat.nonneg (b - a)), by intros; apply_instance protected theorem le_refl : a ≤ a := show rat.nonneg (a - a), begin rw [sub_self], exact le_refl (0 : int) end protected theorem le_total : a ≤ b ∨ b ≤ a := by have := rat.nonneg_total (b - a); rwa neg_sub at this protected theorem le_antisymm {a b : ℚ} (hab : a ≤ b) (hba : b ≤ a) : a = b := by have := eq_neg_of_add_eq_zero (rat.nonneg_antisymm hba $ by simp; assumption); rwa neg_neg at this protected theorem le_trans {a b c : ℚ} (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c := by have := rat.nonneg_add hab hbc; simp at this; exact this instance : linear_order ℚ := { le := rat.le, lt := λa b, ¬ b ≤ a, lt_iff_le_not_le := assume a b, iff.intro (assume h, ⟨or.resolve_left (rat.le_total _ _) h, h⟩) (assume ⟨h1, h2⟩, h2), le_refl := rat.le_refl, le_trans := @rat.le_trans, le_antisymm := @rat.le_antisymm, le_total := rat.le_total } theorem nonneg_iff_zero_le {a} : rat.nonneg a ↔ 0 ≤ a := show rat.nonneg a ↔ rat.nonneg (a - 0), by simp protected theorem add_le_add_left {a b c : ℚ} : c + a ≤ c + b ↔ a ≤ b := by unfold has_le.le rat.le; rw add_sub_add_left_eq_sub protected theorem mul_nonneg {a b : ℚ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b := by simp [nonneg_iff_zero_le.symm] at *; exact rat.nonneg_mul ha hb instance : discrete_linear_ordered_field ℚ := { rat.field_rat with le := (≤), lt := (<), le_refl := le_refl, le_trans := @rat.le_trans, le_antisymm := assume a b, le_antisymm, le_total := le_total, lt_iff_le_not_le := @lt_iff_le_not_le _ _, zero_lt_one := show ¬ (0:ℤ) ≤ -1, from dec_trivial, add_le_add_left := assume a b ab c, rat.add_le_add_left.2 ab, add_lt_add_left := assume a b ab c ba, ab $ rat.add_le_add_left.1 ba, mul_nonneg := @rat.mul_nonneg, mul_pos := assume a b ha hb, lt_of_le_of_ne (rat.mul_nonneg (le_of_lt ha) (le_of_lt hb)) (mul_ne_zero (ne_of_lt ha).symm (ne_of_lt hb).symm).symm, decidable_eq := by apply_instance, decidable_le := assume a b, rat.decidable_nonneg (b - a), decidable_lt := by apply_instance } lemma coe_int_eq_mk (z : ℤ) : ↑z = rat.mk z 1 := show rat.of_int z = rat.mk_nat z 1, by unfold rat.of_int rat.mk_nat; simp [rat.mk_pnat, int.coe_nat_one] lemma coe_nat_rat_eq_mk (n : ℕ) : ↑n = rat.mk ↑n 1 := coe_int_eq_mk _ lemma coe_int_add (z₁ z₂ : ℤ) : ↑(z₁ + z₂) = (↑z₁ + ↑z₂ : ℚ) := by simp [coe_int_eq_mk] lemma coe_int_sub (z₁ z₂ : ℤ) : ↑(z₁ - z₂) = (↑z₁ - ↑z₂ : ℚ) := by simp [coe_int_eq_mk] lemma coe_int_one : ↑(1 : ℤ) = (1 : ℚ) := rfl lemma le_of_of_int_le_of_int {z₁ z₂ : ℤ} (h : (↑z₁ : ℚ) ≤ ↑z₂) : z₁ ≤ z₂ := have rat.nonneg ↑(z₂ - z₁), by rwa [coe_int_sub], have 0 ≤ z₂ - z₁, by rwa [coe_int_eq_mk, rat.mk_nonneg] at this; exact zero_lt_one, have z₁ + 0 ≤ z₂, from add_le_of_le_sub_left this, by simp [*] at * def floor : ℚ → ℤ | ⟨n, d, h, c⟩ := n / d def ceil (r : ℚ) : ℤ := -(floor (-r)) /- nat ceiling -/ lemma exists_upper_nat_bound (q:ℚ) : ∃n:ℕ, q ≤ ↑n := rat.num_denom_cases_on' q $ λn d h₁, have h₂ : ↑d > (0:int), from lt_of_le_of_ne (int.coe_zero_le d) h₁.symm, have h₃ : (1:int) ≤ ↑d, from calc 1 = 0 + 1 : by simp ... ≤ (↑d:int) : int.add_one_le_of_lt h₂, have n ≤ ↑d * ↑(int.to_nat n), from calc n ≤ 1 * ↑(int.to_nat n) : begin simp, cases n, apply le_refl, simp [int.to_nat] end ... ≤ ↑d * ↑(int.to_nat n): mul_le_mul h₃ (le_refl _) (int.coe_zero_le _) (int.coe_zero_le _), ⟨int.to_nat n, show rat.nonneg (↑(int.to_nat n) - rat.mk n ↑d), begin simp [h₁, h₂, coe_nat_rat_eq_mk, mk_nonneg], rw [add_comm, ←sub_eq_add_neg, ge], apply le_sub_left_of_add_le, simp, assumption end⟩ def nat_ceil (q : ℚ) : ℕ := nat.find (exists_upper_nat_bound q) lemma nat_ceil_spec {q : ℚ} : q ≤ nat_ceil q := nat.find_spec (exists_upper_nat_bound q) lemma nat_ceil_min {q : ℚ} {n : ℕ} : q ≤ n → nat_ceil q ≤ n := nat.find_min' (exists_upper_nat_bound q) lemma nat_ceil_mono {q₁ q₂ : ℚ} (h : q₁ ≤ q₂) : nat_ceil q₁ ≤ nat_ceil q₂ := nat_ceil_min $ le_trans h nat_ceil_spec @[simp] lemma nat_ceil_zero : nat_ceil 0 = 0 := le_antisymm (nat_ceil_min $ le_refl _) (nat.zero_le _) lemma nat_ceil_add_one_eq {q : ℚ} (hq : 0 ≤ q) : nat_ceil (q + 1) = nat_ceil q + 1 := le_antisymm (nat_ceil_min $ show q + 1 ≤ ↑(int.of_nat $ nat_ceil q + 1), begin simp [int.of_nat_add, int.of_nat_one, coe_int_add, coe_int_one, -add_comm], exact add_le_add_right nat_ceil_spec 1 end) (have (↑(1:ℤ):ℚ) ≤ nat_ceil (q + 1), from le_trans (le_add_of_nonneg_left hq) nat_ceil_spec, have h1le : 1 ≤ nat_ceil (q + 1), from (int.coe_nat_le_coe_nat_iff _ _).mp $ le_of_of_int_le_of_int this, have nat_ceil q ≤ nat_ceil (q + 1) - 1, from nat_ceil_min $ show q ≤ ↑(int.of_nat (nat_ceil (q + 1) - 1)), begin rw [int.of_nat_sub h1le], simp [-sub_eq_add_neg, coe_int_sub, int.of_nat_one, coe_int_one], exact le_sub_right_of_add_le nat_ceil_spec end, show nat_ceil q + 1 ≤ nat_ceil (q + 1), from (nat.add_le_to_le_sub _ h1le).mpr this) lemma nat_ceil_lt_add_one {q : ℚ} (hq : q ≥ 0) : ↑(nat_ceil q) < q + 1 := lt_of_not_ge $ assume h : q + 1 ≤ ↑(nat_ceil q), have nat_ceil q + 0 = nat_ceil q + 1, from calc nat_ceil q + 0 = nat_ceil q : by simp ... = nat_ceil (q + 1) : le_antisymm (nat_ceil_mono $ le_add_of_le_of_nonneg (le_refl _) zero_le_one) (nat_ceil_min h) ... = nat_ceil q + 1 : nat_ceil_add_one_eq hq, nat.no_confusion $ eq_of_add_eq_add_left this end rat
bca4ad00989b9e3bdffc06989bf1bd8d16e152c1
94e33a31faa76775069b071adea97e86e218a8ee
/src/data/finite/defs.lean
3ca11998c357743d6f13a01119edbde001799f1f
[ "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
2,952
lean
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import logic.equiv.basic /-! # Definition of the `finite` typeclass This file defines a typeclass `finite` saying that `α : Sort*` is finite. A type is `finite` if it is equivalent to `fin n` for some `n`. The `finite` predicate has no computational relevance and, being `Prop`-valued, gets to enjoy proof irrelevance -- it represents the mere fact that the type is finite. While the `fintype` class also represents finiteness of a type, a key difference is that a `fintype` instance represents finiteness in a computable way: it gives a concrete algorithm to produce a `finset` whose elements enumerate the terms of the given type. As such, one generally relies on congruence lemmas when rewriting expressions involving `fintype` instances. Every `fintype` instance automatically gives a `finite` instance, see `fintype.finite`, but not vice versa. Every `fintype` instance should be computable since they are meant for computation. If it's not possible to write a computable `fintype` instance, one should prefer writing a `finite` instance instead. ## Main definitions * `finite α` denotes that `α` is a finite type. ## Implementation notes The definition of `finite α` is not just `nonempty (fintype α)` since `fintype` requires that `α : Type*`, and the definition in this module allows for `α : Sort*`. This means we can write the instance `finite.prop`. ## Tags finite, fintype -/ universes u v open function variables {α β : Sort*} /-- A type is `finite` if it is in bijective correspondence to some `fin n`. While this could be defined as `nonempty (fintype α)`, it is defined in this way to allow there to be `finite` instances for propositions. -/ class inductive finite (α : Sort*) : Prop | intro {n : ℕ} : α ≃ fin n → finite lemma finite_iff_exists_equiv_fin {α : Sort*} : finite α ↔ ∃ n, nonempty (α ≃ fin n) := ⟨λ ⟨e⟩, ⟨_, ⟨e⟩⟩, λ ⟨n, ⟨e⟩⟩, ⟨e⟩⟩ lemma finite.exists_equiv_fin (α : Sort*) [h : finite α] : ∃ (n : ℕ), nonempty (α ≃ fin n) := finite_iff_exists_equiv_fin.mp h lemma finite.of_equiv (α : Sort*) [h : finite α] (f : α ≃ β) : finite β := by { casesI h with n e, exact finite.intro (f.symm.trans e) } lemma equiv.finite_iff (f : α ≃ β) : finite α ↔ finite β := ⟨λ _, by exactI finite.of_equiv _ f, λ _, by exactI finite.of_equiv _ f.symm⟩ lemma function.bijective.finite_iff {f : α → β} (h : bijective f) : finite α ↔ finite β := (equiv.of_bijective f h).finite_iff namespace finite lemma of_bijective [finite α] {f : α → β} (h : bijective f) : finite β := h.finite_iff.mp ‹_› instance [finite α] : finite (plift α) := of_equiv α equiv.plift.symm instance {α : Type v} [finite α] : finite (ulift.{u} α) := of_equiv α equiv.ulift.symm end finite
850fc6f3dbf194f1cbeb41aabd842cf73ea086ba
7cef822f3b952965621309e88eadf618da0c8ae9
/src/topology/instances/real.lean
1a611bc66cbe67e4599f0697dcd8f325a6928332
[ "Apache-2.0" ]
permissive
rmitta/mathlib
8d90aee30b4db2b013e01f62c33f297d7e64a43d
883d974b608845bad30ae19e27e33c285200bf84
refs/heads/master
1,585,776,832,544
1,576,874,096,000
1,576,874,096,000
153,663,165
0
2
Apache-2.0
1,544,806,490,000
1,539,884,365,000
Lean
UTF-8
Lean
false
false
16,412
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 The real numbers ℝ. They are constructed as the topological completion of ℚ. With the following steps: (1) prove that ℚ forms a uniform space. (2) subtraction and addition are uniform continuous functions in this space (3) for multiplication and inverse this only holds on bounded subsets (4) ℝ is defined as separated Cauchy filters over ℚ (the separation requires a quotient construction) (5) extend the uniform continuous functions along the completion (6) proof field properties using the principle of extension of identities TODO generalizations: * topological groups & rings * order topologies * Archimedean fields -/ import topology.metric_space.basic topology.algebra.uniform_group topology.algebra.ring tactic.linarith noncomputable theory open classical set lattice filter topological_space metric open_locale classical open_locale topological_space universes u v w variables {α : Type u} {β : Type v} {γ : Type w} instance : metric_space ℚ := metric_space.induced coe rat.cast_injective real.metric_space theorem rat.dist_eq (x y : ℚ) : dist x y = abs (x - y) := rfl @[elim_cast, simp] lemma rat.dist_cast (x y : ℚ) : dist (x : ℝ) y = dist x y := rfl section low_prio -- we want to ignore this instance for the next declaration local attribute [instance, priority 10] int.uniform_space instance : metric_space ℤ := begin letI M := metric_space.induced coe int.cast_injective real.metric_space, refine @metric_space.replace_uniformity _ int.uniform_space M (le_antisymm refl_le_uniformity $ λ r ru, mem_uniformity_dist.2 ⟨1, zero_lt_one, λ a b h, mem_principal_sets.1 ru $ dist_le_zero.1 (_ : (abs (a - b) : ℝ) ≤ 0)⟩), simpa using (@int.cast_le ℝ _ _ 0).2 (int.lt_add_one_iff.1 $ (@int.cast_lt ℝ _ (abs (a - b)) 1).1 $ by simpa using h) end end low_prio theorem int.dist_eq (x y : ℤ) : dist x y = abs (x - y) := rfl @[elim_cast, simp] theorem int.dist_cast_real (x y : ℤ) : dist (x : ℝ) y = dist x y := rfl @[elim_cast, simp] theorem int.dist_cast_rat (x y : ℤ) : dist (x : ℚ) y = dist x y := by rw [← int.dist_cast_real, ← rat.dist_cast]; congr' 1; norm_cast theorem uniform_continuous_of_rat : uniform_continuous (coe : ℚ → ℝ) := uniform_continuous_comap theorem uniform_embedding_of_rat : uniform_embedding (coe : ℚ → ℝ) := uniform_embedding_comap rat.cast_injective theorem dense_embedding_of_rat : dense_embedding (coe : ℚ → ℝ) := uniform_embedding_of_rat.dense_embedding $ λ x, mem_closure_iff_nhds.2 $ λ t ht, let ⟨ε,ε0, hε⟩ := mem_nhds_iff.1 ht in let ⟨q, h⟩ := exists_rat_near x ε0 in ne_empty_iff_exists_mem.2 ⟨_, hε (mem_ball'.2 h), q, rfl⟩ theorem embedding_of_rat : embedding (coe : ℚ → ℝ) := dense_embedding_of_rat.to_embedding theorem continuous_of_rat : continuous (coe : ℚ → ℝ) := uniform_continuous_of_rat.continuous theorem real.uniform_continuous_add : uniform_continuous (λp : ℝ × ℝ, p.1 + p.2) := metric.uniform_continuous_iff.2 $ λ ε ε0, let ⟨δ, δ0, Hδ⟩ := rat_add_continuous_lemma abs ε0 in ⟨δ, δ0, λ a b h, let ⟨h₁, h₂⟩ := max_lt_iff.1 h in Hδ h₁ h₂⟩ -- TODO(Mario): Find a way to use rat_add_continuous_lemma theorem rat.uniform_continuous_add : uniform_continuous (λp : ℚ × ℚ, p.1 + p.2) := uniform_embedding_of_rat.to_uniform_inducing.uniform_continuous_iff.2 $ by simp [(∘)]; exact real.uniform_continuous_add.comp ((uniform_continuous_of_rat.comp uniform_continuous_fst).prod_mk (uniform_continuous_of_rat.comp uniform_continuous_snd)) theorem real.uniform_continuous_neg : uniform_continuous (@has_neg.neg ℝ _) := metric.uniform_continuous_iff.2 $ λ ε ε0, ⟨_, ε0, λ a b h, by rw dist_comm at h; simpa [real.dist_eq] using h⟩ theorem rat.uniform_continuous_neg : uniform_continuous (@has_neg.neg ℚ _) := metric.uniform_continuous_iff.2 $ λ ε ε0, ⟨_, ε0, λ a b h, by rw dist_comm at h; simpa [rat.dist_eq] using h⟩ instance : uniform_add_group ℝ := uniform_add_group.mk' real.uniform_continuous_add real.uniform_continuous_neg instance : uniform_add_group ℚ := uniform_add_group.mk' rat.uniform_continuous_add rat.uniform_continuous_neg -- short-circuit type class inference instance : topological_add_group ℝ := by apply_instance instance : topological_add_group ℚ := by apply_instance instance : orderable_topology ℚ := induced_orderable_topology _ (λ x y, rat.cast_lt) (@exists_rat_btwn _ _ _) lemma real.is_topological_basis_Ioo_rat : @is_topological_basis ℝ _ (⋃(a b : ℚ) (h : a < b), {Ioo a b}) := is_topological_basis_of_open_of_nhds (by simp [is_open_Ioo] {contextual:=tt}) (assume a v hav hv, let ⟨l, u, hl, hu, h⟩ := (mem_nhds_unbounded (no_top _) (no_bot _)).mp (mem_nhds_sets hv hav), ⟨q, hlq, hqa⟩ := exists_rat_btwn hl, ⟨p, hap, hpu⟩ := exists_rat_btwn hu in ⟨Ioo q p, by simp; exact ⟨q, p, rat.cast_lt.1 $ lt_trans hqa hap, rfl⟩, ⟨hqa, hap⟩, assume a' ⟨hqa', ha'p⟩, h _ (lt_trans hlq hqa') (lt_trans ha'p hpu)⟩) instance : second_countable_topology ℝ := ⟨⟨(⋃(a b : ℚ) (h : a < b), {Ioo a b}), by simp [countable_Union, countable_Union_Prop], real.is_topological_basis_Ioo_rat.2.2⟩⟩ /- TODO(Mario): Prove that these are uniform isomorphisms instead of uniform embeddings lemma uniform_embedding_add_rat {r : ℚ} : uniform_embedding (λp:ℚ, p + r) := _ lemma uniform_embedding_mul_rat {q : ℚ} (hq : q ≠ 0) : uniform_embedding ((*) q) := _ -/ lemma real.uniform_continuous_inv (s : set ℝ) {r : ℝ} (r0 : 0 < r) (H : ∀ x ∈ s, r ≤ abs x) : uniform_continuous (λp:s, p.1⁻¹) := metric.uniform_continuous_iff.2 $ λ ε ε0, let ⟨δ, δ0, Hδ⟩ := rat_inv_continuous_lemma abs ε0 r0 in ⟨δ, δ0, λ a b h, Hδ (H _ a.2) (H _ b.2) h⟩ lemma real.uniform_continuous_abs : uniform_continuous (abs : ℝ → ℝ) := metric.uniform_continuous_iff.2 $ λ ε ε0, ⟨ε, ε0, λ a b, lt_of_le_of_lt (abs_abs_sub_abs_le_abs_sub _ _)⟩ lemma real.continuous_abs : continuous (abs : ℝ → ℝ) := real.uniform_continuous_abs.continuous lemma rat.uniform_continuous_abs : uniform_continuous (abs : ℚ → ℚ) := metric.uniform_continuous_iff.2 $ λ ε ε0, ⟨ε, ε0, λ a b h, lt_of_le_of_lt (by simpa [rat.dist_eq] using abs_abs_sub_abs_le_abs_sub _ _) h⟩ lemma rat.continuous_abs : continuous (abs : ℚ → ℚ) := rat.uniform_continuous_abs.continuous lemma real.tendsto_inv {r : ℝ} (r0 : r ≠ 0) : tendsto (λq, q⁻¹) (𝓝 r) (𝓝 r⁻¹) := by rw ← abs_pos_iff at r0; exact tendsto_of_uniform_continuous_subtype (real.uniform_continuous_inv {x | abs r / 2 < abs x} (half_pos r0) (λ x h, le_of_lt h)) (mem_nhds_sets (real.continuous_abs _ $ is_open_lt' (abs r / 2)) (half_lt_self r0)) lemma real.continuous_inv : continuous (λa:{r:ℝ // r ≠ 0}, a.val⁻¹) := continuous_iff_continuous_at.mpr $ assume ⟨r, hr⟩, tendsto.comp (real.tendsto_inv hr) (continuous_iff_continuous_at.mp continuous_subtype_val _) lemma real.continuous.inv [topological_space α] {f : α → ℝ} (h : ∀a, f a ≠ 0) (hf : continuous f) : continuous (λa, (f a)⁻¹) := show continuous ((has_inv.inv ∘ @subtype.val ℝ (λr, r ≠ 0)) ∘ λa, ⟨f a, h a⟩), from real.continuous_inv.comp (continuous_subtype_mk _ hf) lemma real.uniform_continuous_mul_const {x : ℝ} : uniform_continuous ((*) x) := metric.uniform_continuous_iff.2 $ λ ε ε0, begin cases no_top (abs x) with y xy, have y0 := lt_of_le_of_lt (abs_nonneg _) xy, refine ⟨_, div_pos ε0 y0, λ a b h, _⟩, rw [real.dist_eq, ← mul_sub, abs_mul, ← mul_div_cancel' ε (ne_of_gt y0)], exact mul_lt_mul' (le_of_lt xy) h (abs_nonneg _) y0 end lemma real.uniform_continuous_mul (s : set (ℝ × ℝ)) {r₁ r₂ : ℝ} (H : ∀ x ∈ s, abs (x : ℝ × ℝ).1 < r₁ ∧ abs x.2 < r₂) : uniform_continuous (λp:s, p.1.1 * p.1.2) := metric.uniform_continuous_iff.2 $ λ ε ε0, let ⟨δ, δ0, Hδ⟩ := rat_mul_continuous_lemma abs ε0 in ⟨δ, δ0, λ a b h, let ⟨h₁, h₂⟩ := max_lt_iff.1 h in Hδ (H _ a.2).1 (H _ b.2).2 h₁ h₂⟩ protected lemma real.continuous_mul : continuous (λp : ℝ × ℝ, p.1 * p.2) := continuous_iff_continuous_at.2 $ λ ⟨a₁, a₂⟩, tendsto_of_uniform_continuous_subtype (real.uniform_continuous_mul ({x | abs x < abs a₁ + 1}.prod {x | abs x < abs a₂ + 1}) (λ x, id)) (mem_nhds_sets (is_open_prod (real.continuous_abs _ $ is_open_gt' (abs a₁ + 1)) (real.continuous_abs _ $ is_open_gt' (abs a₂ + 1))) ⟨lt_add_one (abs a₁), lt_add_one (abs a₂)⟩) instance : topological_ring ℝ := { continuous_mul := real.continuous_mul, ..real.topological_add_group } instance : topological_semiring ℝ := by apply_instance -- short-circuit type class inference lemma rat.continuous_mul : continuous (λp : ℚ × ℚ, p.1 * p.2) := embedding_of_rat.continuous_iff.2 $ by simp [(∘)]; exact real.continuous_mul.comp ((continuous_of_rat.comp continuous_fst).prod_mk (continuous_of_rat.comp continuous_snd)) instance : topological_ring ℚ := { continuous_mul := rat.continuous_mul, ..rat.topological_add_group } theorem real.ball_eq_Ioo (x ε : ℝ) : ball x ε = Ioo (x - ε) (x + ε) := set.ext $ λ y, by rw [mem_ball, real.dist_eq, abs_sub_lt_iff, sub_lt_iff_lt_add', and_comm, sub_lt]; refl theorem real.Ioo_eq_ball (x y : ℝ) : Ioo x y = ball ((x + y) / 2) ((y - x) / 2) := by rw [real.ball_eq_Ioo, ← sub_div, add_comm, ← sub_add, add_sub_cancel', add_self_div_two, ← add_div, add_assoc, add_sub_cancel'_right, add_self_div_two] lemma real.totally_bounded_Ioo (a b : ℝ) : totally_bounded (Ioo a b) := metric.totally_bounded_iff.2 $ λ ε ε0, begin rcases exists_nat_gt ((b - a) / ε) with ⟨n, ba⟩, rw [div_lt_iff' ε0, sub_lt_iff_lt_add'] at ba, let s := (λ i:ℕ, a + ε * i) '' {i:ℕ | i < n}, refine ⟨s, finite_image _ ⟨set.fintype_lt_nat _⟩, λ x h, _⟩, rcases h with ⟨ax, xb⟩, let i : ℕ := ⌊(x - a) / ε⌋.to_nat, have : (i : ℤ) = ⌊(x - a) / ε⌋ := int.to_nat_of_nonneg (floor_nonneg.2 $ le_of_lt (div_pos (sub_pos.2 ax) ε0)), simp, refine ⟨_, ⟨i, _, rfl⟩, _⟩, { rw [← int.coe_nat_lt, this], refine int.cast_lt.1 (lt_of_le_of_lt (floor_le _) _), rw [int.cast_coe_nat, div_lt_iff' ε0, sub_lt_iff_lt_add'], exact lt_trans xb ba }, { rw [real.dist_eq, ← int.cast_coe_nat, this, abs_of_nonneg, ← sub_sub, sub_lt_iff_lt_add'], { have := lt_floor_add_one ((x - a) / ε), rwa [div_lt_iff' ε0, mul_add, mul_one] at this }, { have := floor_le ((x - a) / ε), rwa [ge, sub_nonneg, ← le_sub_iff_add_le', ← le_div_iff' ε0] } } end lemma real.totally_bounded_ball (x ε : ℝ) : totally_bounded (ball x ε) := by rw real.ball_eq_Ioo; apply real.totally_bounded_Ioo lemma real.totally_bounded_Ico (a b : ℝ) : totally_bounded (Ico a b) := let ⟨c, ac⟩ := no_bot a in totally_bounded_subset (by exact λ x ⟨h₁, h₂⟩, ⟨lt_of_lt_of_le ac h₁, h₂⟩) (real.totally_bounded_Ioo c b) lemma real.totally_bounded_Icc (a b : ℝ) : totally_bounded (Icc a b) := let ⟨c, bc⟩ := no_top b in totally_bounded_subset (by exact λ x ⟨h₁, h₂⟩, ⟨h₁, lt_of_le_of_lt h₂ bc⟩) (real.totally_bounded_Ico a c) lemma rat.totally_bounded_Icc (a b : ℚ) : totally_bounded (Icc a b) := begin have := totally_bounded_preimage uniform_embedding_of_rat (real.totally_bounded_Icc a b), rwa (set.ext (λ q, _) : Icc _ _ = _), simp end -- TODO(Mario): Generalize to first-countable uniform spaces? instance : complete_space ℝ := ⟨λ f cf, begin let g : ℕ → {ε:ℝ//ε>0} := λ n, ⟨n.to_pnat'⁻¹, inv_pos (nat.cast_pos.2 n.to_pnat'.pos)⟩, choose S hS hS_dist using show ∀n:ℕ, ∃t ∈ f.sets, ∀ x y ∈ t, dist x y < g n, from assume n, let ⟨t, tf, h⟩ := (metric.cauchy_iff.1 cf).2 (g n).1 (g n).2 in ⟨t, tf, h⟩, let F : ℕ → set ℝ := λn, ⋂i≤n, S i, have hF : ∀n, F n ∈ f.sets := assume n, Inter_mem_sets (finite_le_nat n) (λ i _, hS i), have hF_dist : ∀n, ∀ x y ∈ F n, dist x y < g n := assume n x y hx hy, have F n ⊆ S n := bInter_subset_of_mem (le_refl n), (hS_dist n) _ _ (this hx) (this hy), choose G hG using assume n:ℕ, inhabited_of_mem_sets cf.1 (hF n), have hg : ∀ ε > 0, ∃ n, ∀ j ≥ n, (g j : ℝ) < ε, { intros ε ε0, cases exists_nat_gt ε⁻¹ with n hn, refine ⟨n, λ j nj, _⟩, have hj := lt_of_lt_of_le hn (nat.cast_le.2 nj), have j0 := lt_trans (inv_pos ε0) hj, have jε := (inv_lt j0 ε0).2 hj, rwa ← pnat.to_pnat'_coe (nat.cast_pos.1 j0) at jε }, let c : cau_seq ℝ abs, { refine ⟨λ n, G n, λ ε ε0, _⟩, cases hg _ ε0 with n hn, refine ⟨n, λ j jn, _⟩, have : F j ⊆ F n := bInter_subset_bInter_left (λ i h, @le_trans _ _ i n j h jn), exact lt_trans (hF_dist n _ _ (this (hG j)) (hG n)) (hn _ $ le_refl _) }, refine ⟨cau_seq.lim c, λ s h, _⟩, rcases metric.mem_nhds_iff.1 h with ⟨ε, ε0, hε⟩, cases exists_forall_ge_and (hg _ $ half_pos ε0) (cau_seq.equiv_lim c _ $ half_pos ε0) with n hn, cases hn _ (le_refl _) with h₁ h₂, refine sets_of_superset _ (hF n) (subset.trans _ $ subset.trans (ball_half_subset (G n) h₂) hε), exact λ x h, lt_trans ((hF_dist n) x (G n) h (hG n)) h₁ end⟩ lemma tendsto_coe_nat_real_at_top_iff {f : α → ℕ} {l : filter α} : tendsto (λ n, (f n : ℝ)) l at_top ↔ tendsto f l at_top := tendsto_at_top_embedding (assume a₁ a₂, nat.cast_le) $ assume r, let ⟨n, hn⟩ := exists_nat_gt r in ⟨n, le_of_lt hn⟩ lemma tendsto_coe_nat_real_at_top_at_top : tendsto (coe : ℕ → ℝ) at_top at_top := tendsto_coe_nat_real_at_top_iff.2 tendsto_id lemma tendsto_coe_int_real_at_top_iff {f : α → ℤ} {l : filter α} : tendsto (λ n, (f n : ℝ)) l at_top ↔ tendsto f l at_top := tendsto_at_top_embedding (assume a₁ a₂, int.cast_le) $ assume r, let ⟨n, hn⟩ := exists_nat_gt r in ⟨(n:ℤ), le_of_lt $ by rwa [int.cast_coe_nat]⟩ lemma tendsto_coe_int_real_at_top_at_top : tendsto (coe : ℤ → ℝ) at_top at_top := tendsto_coe_int_real_at_top_iff.2 tendsto_id section lemma closure_of_rat_image_lt {q : ℚ} : closure ((coe:ℚ → ℝ) '' {x | q < x}) = {r | ↑q ≤ r} := subset.antisymm ((closure_subset_iff_subset_of_is_closed (is_closed_ge' _)).2 (image_subset_iff.2 $ λ p h, le_of_lt $ (@rat.cast_lt ℝ _ _ _).2 h)) $ λ x hx, mem_closure_iff_nhds.2 $ λ t ht, let ⟨ε, ε0, hε⟩ := metric.mem_nhds_iff.1 ht in let ⟨p, h₁, h₂⟩ := exists_rat_btwn ((lt_add_iff_pos_right x).2 ε0) in ne_empty_iff_exists_mem.2 ⟨_, hε (show abs _ < _, by rwa [abs_of_nonneg (le_of_lt $ sub_pos.2 h₁), sub_lt_iff_lt_add']), p, rat.cast_lt.1 (@lt_of_le_of_lt ℝ _ _ _ _ hx h₁), rfl⟩ /- TODO(Mario): Put these back only if needed later lemma closure_of_rat_image_le_eq {q : ℚ} : closure ((coe:ℚ → ℝ) '' {x | q ≤ x}) = {r | ↑q ≤ r} := _ lemma closure_of_rat_image_le_le_eq {a b : ℚ} (hab : a ≤ b) : closure (of_rat '' {q:ℚ | a ≤ q ∧ q ≤ b}) = {r:ℝ | of_rat a ≤ r ∧ r ≤ of_rat b} := _-/ lemma compact_Icc {a b : ℝ} : compact (Icc a b) := compact_of_totally_bounded_is_closed (real.totally_bounded_Icc a b) (is_closed_inter (is_closed_ge' a) (is_closed_le' b)) instance : proper_space ℝ := { compact_ball := λx r, by rw closed_ball_Icc; apply compact_Icc } lemma real.bounded_iff_bdd_below_bdd_above {s : set ℝ} : bounded s ↔ bdd_below s ∧ bdd_above s := ⟨begin assume bdd, rcases (bounded_iff_subset_ball 0).1 bdd with ⟨r, hr⟩, -- hr : s ⊆ closed_ball 0 r rw closed_ball_Icc at hr, -- hr : s ⊆ Icc (0 - r) (0 + r) exact ⟨⟨-r, λy hy, by simpa using (hr hy).1⟩, ⟨r, λy hy, by simpa using (hr hy).2⟩⟩ end, begin rintros ⟨⟨m, hm⟩, ⟨M, hM⟩⟩, have I : s ⊆ Icc m M := λx hx, ⟨hm hx, hM hx⟩, have : Icc m M = closed_ball ((m+M)/2) ((M-m)/2) := by rw closed_ball_Icc; congr; ring, rw this at I, exact bounded.subset I bounded_closed_ball end⟩ end
f51eac249d67409ee452251441771e29e8a3db56
ebbdcbd7ddc89a9ef7c3b397b301d5f5272a918f
/qp/p1_categories/c3_wtypes/s6_inductive.lean
71b3978447ca4c83ad8da9f80f72f0ee6e77bb16
[]
no_license
intoverflow/qvr
34b9ef23604738381ca20b7d622fd0399d88f2dd
0cfcd33fe4bf8d93851a00cec5bfd21e77105d74
refs/heads/master
1,616,591,570,371
1,492,575,772,000
1,492,575,772,000
80,061,627
0
0
null
null
null
null
UTF-8
Lean
false
false
7,337
lean
/- ----------------------------------------------------------------------- Inductive types. ----------------------------------------------------------------------- -/ import .s5_wtypes namespace qp open stdaux universe variables ℓobj ℓhom /- ----------------------------------------------------------------------- Inductive signatures. ----------------------------------------------------------------------- -/ /-! #brief Signature for a constructor. -/ structure ConSig (C : Cat.{ℓobj ℓhom}) : Type ℓobj := (rec_arity : ℕ) (args : list C^.obj) /-! #brief The non-recursive arguments of a constructor signature. -/ definition ConSig.arg {C : Cat.{ℓobj ℓhom}} [C_HasAllFinProducts : HasAllFinProducts C] (conσ : ConSig C) : C^.obj := finproduct C conσ^.args /-! #brief An inductive signature. -/ definition IndSig (C : Cat.{ℓobj ℓhom}) : Type ℓobj := list (ConSig C) /- ----------------------------------------------------------------------- Representing hom for a constructor. ----------------------------------------------------------------------- -/ /-! #brief The domain of the representing hom for a constructor. -/ definition ConSig.rep.dom {C : Cat.{ℓobj ℓhom}} [C_HasAllFinProducts : HasAllFinProducts C] [C_HasAllFinCoProducts : HasAllFinCoProducts C] (conσ : ConSig C) : C^.obj := fincoproduct C (list.repeat conσ^.arg conσ^.rec_arity) /-! #brief The codomain of the representing hom for a constructor. -/ definition ConSig.rep.codom {C : Cat.{ℓobj ℓhom}} [C_HasAllFinProducts : HasAllFinProducts C] [C_HasAllFinCoProducts : HasAllFinCoProducts C] (conσ : ConSig C) : C^.obj := conσ^.arg /-! #brief The domain/codomain pair of the representing hom for a constructor. -/ definition ConSig.rep.dom_codom {C : Cat.{ℓobj ℓhom}} [C_HasAllFinProducts : HasAllFinProducts C] [C_HasAllFinCoProducts : HasAllFinCoProducts C] (conσ : ConSig C) : prod C^.obj C^.obj := (conσ^.rep.dom, conσ^.rep.codom) /-! #brief The representing hom for a constructor. -/ definition ConSig.rep {C : Cat.{ℓobj ℓhom}} [C_HasAllFinProducts : HasAllFinProducts C] [C_HasAllFinCoProducts : HasAllFinCoProducts C] (conσ : ConSig C) : C^.hom conσ^.rep.dom conσ^.rep.codom := fincoproduct.univ C (list.repeat conσ^.arg conσ^.rec_arity) (HomsIn.repeat (C^.id conσ^.arg) conσ^.rec_arity) /- ----------------------------------------------------------------------- Polynomial endo-functors induced by inductive signatures. ----------------------------------------------------------------------- -/ /-! #brief The polynomial endo-functor associated with a constructor. -/ definition ConSig.PolyEndoFun {C : Cat.{ℓobj ℓhom}} [C_HasFinal : HasFinal C] [C_HasAllPullbacks : HasAllPullbacks C] [C_HasDepProd : HasAllDepProd C] [C_HasAllFinProducts : HasAllFinProducts C] [C_HasAllFinCoProducts : HasAllFinCoProducts C] (conσ : ConSig C) : PolyEndoFun C := PolyEndoFun.of_hom conσ^.rep /-! #brief The polynomial endo-functor associated with an inductive signature. -/ definition IndSig.PolyEndoFun {C : Cat.{ℓobj ℓhom}} [C_HasFinal : HasFinal C] [C_HasAllPullbacks : HasAllPullbacks C] [C_HasDepProd : HasAllDepProd C] [C_HasAllFinProducts : HasAllFinProducts C] [C_HasAllFinCoProducts : HasAllFinCoProducts C] (indσ : IndSig C) : PolyEndoFun C := PolyEndoFun.sum (list.map ConSig.PolyEndoFun indσ) /- ----------------------------------------------------------------------- Categories with inductive types. ----------------------------------------------------------------------- -/ /-! #brief A category with an inductive type. -/ @[class] definition HasIndType (C : Cat.{ℓobj ℓhom}) [C_HasFinal : HasFinal C] [C_HasAllPullbacks : HasAllPullbacks C] [C_HasDepProd : HasAllDepProd C] [C_HasAllFinProducts : HasAllFinProducts C] [C_HasAllFinCoProducts : HasAllFinCoProducts C] (indσ : IndSig C) := HasWType C indσ^.PolyEndoFun /-! #brief An inductive type. -/ definition IndSig.prim {C : Cat.{ℓobj ℓhom}} [C_HasFinal : HasFinal C] [C_HasAllPullbacks : HasAllPullbacks C] [C_HasDepProd : HasAllDepProd C] [C_HasAllFinProducts : HasAllFinProducts C] [C_HasAllFinCoProducts : HasAllFinCoProducts C] (indσ : IndSig C) [σ_HasIndType : HasIndType C indσ] : C^.obj := @wtype.carr C C_HasAllFinProducts C_HasFinal C_HasAllPullbacks C_HasDepProd indσ^.PolyEndoFun σ_HasIndType /-! #brief Primitive folding an inductive type. -/ definition IndSig.prim_fold {C : Cat.{ℓobj ℓhom}} [C_HasFinal : HasFinal C] [C_HasAllPullbacks : HasAllPullbacks C] [C_HasDepProd : HasAllDepProd C] [C_HasAllFinProducts : HasAllFinProducts C] [C_HasAllFinCoProducts : HasAllFinCoProducts C] (indσ : IndSig C) [σ_HasIndType : HasIndType C indσ] : C^.hom (indσ^.PolyEndoFun^.endo^.obj indσ^.prim) indσ^.prim := @wtype.fold C C_HasAllFinProducts C_HasFinal C_HasAllPullbacks C_HasDepProd indσ^.PolyEndoFun σ_HasIndType /-! #brief Primitive unfolding an inductive type. -/ definition IndSig.prim_unfold {C : Cat.{ℓobj ℓhom}} [C_HasFinal : HasFinal C] [C_HasAllPullbacks : HasAllPullbacks C] [C_HasDepProd : HasAllDepProd C] [C_HasAllFinProducts : HasAllFinProducts C] [C_HasAllFinCoProducts : HasAllFinCoProducts C] (indσ : IndSig C) [σ_HasIndType : HasIndType C indσ] : C^.hom indσ^.prim (indσ^.PolyEndoFun^.endo^.obj indσ^.prim) := @wtype.unfold C C_HasAllFinProducts C_HasFinal C_HasAllPullbacks C_HasDepProd indσ^.PolyEndoFun σ_HasIndType /-! #brief Primitive fold/unfold is an iso. -/ definition IndSig.prim_iso (C : Cat.{ℓobj ℓhom}) [C_HasFinal : HasFinal C] [C_HasAllPullbacks : HasAllPullbacks C] [C_HasDepProd : HasAllDepProd C] [C_HasAllFinProducts : HasAllFinProducts C] [C_HasAllFinCoProducts : HasAllFinCoProducts C] (indσ : IndSig C) [σ_HasIndType : HasIndType C indσ] : Iso indσ^.prim_fold indσ^.prim_unfold := @wtype.iso C C_HasAllFinProducts C_HasFinal C_HasAllPullbacks C_HasDepProd indσ^.PolyEndoFun σ_HasIndType /-! #brief Arguments for the n-th constructor. -/ definition IndSig.con_arg {C : Cat.{ℓobj ℓhom}} [C_HasFinal : HasFinal C] [C_HasAllPullbacks : HasAllPullbacks C] [C_HasDepProd : HasAllDepProd C] [C_HasAllFinProducts : HasAllFinProducts C] [C_HasAllFinCoProducts : HasAllFinCoProducts C] (indσ : IndSig C) [indσ_HasIndType : HasIndType C indσ] (σ : ConSig C) : C^.obj := finproduct C ((list.repeat indσ^.prim σ^.rec_arity) ++ σ^.args) /-! #brief Decomposition of an inductive type in terms of its constructors. -/ definition IndSig.type {C : Cat.{ℓobj ℓhom}} [C_HasFinal : HasFinal C] [C_HasAllPullbacks : HasAllPullbacks C] [C_HasDepProd : HasAllDepProd C] [C_HasAllFinProducts : HasAllFinProducts C] [C_HasAllFinCoProducts : HasAllFinCoProducts C] (indσ : IndSig C) [indσ_HasIndType : HasIndType C indσ] : C^.obj := fincoproduct C (list.map indσ^.con_arg indσ) end qp
51864083a837fcc238f967448dec0c7b593906c1
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/analysis/calculus/fderiv_symmetric.lean
34f00e42edab502fb09a34fca3aa78f0fa5b86ca
[ "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
19,022
lean
/- Copyright (c) 2021 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 analysis.calculus.deriv import analysis.calculus.mean_value import analysis.convex.topology /-! # Symmetry of the second derivative We show that, over the reals, the second derivative is symmetric. The most precise result is `convex.second_derivative_within_at_symmetric`. It asserts that, if a function is differentiable inside a convex set `s` with nonempty interior, and has a second derivative within `s` at a point `x`, then this second derivative at `x` is symmetric. Note that this result does not require continuity of the first derivative. The following particular cases of this statement are especially relevant: `second_derivative_symmetric_of_eventually` asserts that, if a function is differentiable on a neighborhood of `x`, and has a second derivative at `x`, then this second derivative is symmetric. `second_derivative_symmetric` asserts that, if a function is differentiable, and has a second derivative at `x`, then this second derivative is symmetric. ## Implementation note For the proof, we obtain an asymptotic expansion to order two of `f (x + v + w) - f (x + v)`, by using the mean value inequality applied to a suitable function along the segment `[x + v, x + v + w]`. This expansion involves `f'' ⬝ w` as we move along a segment directed by `w` (see `convex.taylor_approx_two_segment`). Consider the alternate sum `f (x + v + w) + f x - f (x + v) - f (x + w)`, corresponding to the values of `f` along a rectangle based at `x` with sides `v` and `w`. One can write it using the two sides directed by `w`, as `(f (x + v + w) - f (x + v)) - (f (x + w) - f x)`. Together with the previous asymptotic expansion, one deduces that it equals `f'' v w + o(1)` when `v, w` tends to `0`. Exchanging the roles of `v` and `w`, one instead gets an asymptotic expansion `f'' w v`, from which the equality `f'' v w = f'' w v` follows. In our most general statement, we only assume that `f` is differentiable inside a convex set `s`, so a few modifications have to be made. Since we don't assume continuity of `f` at `x`, we consider instead the rectangle based at `x + v + w` with sides `v` and `w`, in `convex.is_o_alternate_sum_square`, but the argument is essentially the same. It only works when `v` and `w` both point towards the interior of `s`, to make sure that all the sides of the rectangle are contained in `s` by convexity. The general case follows by linearity, though. -/ open asymptotics set open_locale topological_space variables {E F : Type*} [normed_add_comm_group E] [normed_space ℝ E] [normed_add_comm_group F] [normed_space ℝ F] {s : set E} (s_conv : convex ℝ s) {f : E → F} {f' : E → (E →L[ℝ] F)} {f'' : E →L[ℝ] (E →L[ℝ] F)} (hf : ∀ x ∈ interior s, has_fderiv_at f (f' x) x) {x : E} (xs : x ∈ s) (hx : has_fderiv_within_at f' f'' (interior s) x) include s_conv xs hx hf /-- Assume that `f` is differentiable inside a convex set `s`, and that its derivative `f'` is differentiable at a point `x`. Then, given two vectors `v` and `w` pointing inside `s`, one can Taylor-expand to order two the function `f` on the segment `[x + h v, x + h (v + w)]`, giving a bilinear estimate for `f (x + hv + hw) - f (x + hv)` in terms of `f' w` and of `f'' ⬝ w`, up to `o(h^2)`. This is a technical statement used to show that the second derivative is symmetric. -/ lemma convex.taylor_approx_two_segment {v w : E} (hv : x + v ∈ interior s) (hw : x + v + w ∈ interior s) : (λ h : ℝ, f (x + h • v + h • w) - f (x + h • v) - h • f' x w - h^2 • f'' v w - (h^2/2) • f'' w w) =o[𝓝[>] 0] (λ h, h^2) := begin -- it suffices to check that the expression is bounded by `ε * ((‖v‖ + ‖w‖) * ‖w‖) * h^2` for -- small enough `h`, for any positive `ε`. apply is_o.trans_is_O (is_o_iff.2 (λ ε εpos, _)) (is_O_const_mul_self ((‖v‖ + ‖w‖) * ‖w‖) _ _), -- consider a ball of radius `δ` around `x` in which the Taylor approximation for `f''` is -- good up to `δ`. rw [has_fderiv_within_at, has_fderiv_at_filter, is_o_iff] at hx, rcases metric.mem_nhds_within_iff.1 (hx εpos) with ⟨δ, δpos, sδ⟩, have E1 : ∀ᶠ h in 𝓝[>] (0:ℝ), h * (‖v‖ + ‖w‖) < δ, { have : filter.tendsto (λ h, h * (‖v‖ + ‖w‖)) (𝓝[>] (0:ℝ)) (𝓝 (0 * (‖v‖ + ‖w‖))) := (continuous_id.mul continuous_const).continuous_within_at, apply (tendsto_order.1 this).2 δ, simpa only [zero_mul] using δpos }, have E2 : ∀ᶠ h in 𝓝[>] (0:ℝ), (h : ℝ) < 1 := mem_nhds_within_Ioi_iff_exists_Ioo_subset.2 ⟨(1 : ℝ), by simp only [mem_Ioi, zero_lt_one], λ x hx, hx.2⟩, filter_upwards [E1, E2, self_mem_nhds_within] with h hδ h_lt_1 hpos, -- we consider `h` small enough that all points under consideration belong to this ball, -- and also with `0 < h < 1`. replace hpos : 0 < h := hpos, have xt_mem : ∀ t ∈ Icc (0 : ℝ) 1, x + h • v + (t * h) • w ∈ interior s, { assume t ht, have : x + h • v ∈ interior s := s_conv.add_smul_mem_interior xs hv ⟨hpos, h_lt_1.le⟩, rw [← smul_smul], apply s_conv.interior.add_smul_mem this _ ht, rw add_assoc at hw, rw [add_assoc, ← smul_add], exact s_conv.add_smul_mem_interior xs hw ⟨hpos, h_lt_1.le⟩ }, -- define a function `g` on `[0,1]` (identified with `[v, v + w]`) such that `g 1 - g 0` is the -- quantity to be estimated. We will check that its derivative is given by an explicit -- expression `g'`, that we can bound. Then the desired bound for `g 1 - g 0` follows from the -- mean value inequality. let g := λ t, f (x + h • v + (t * h) • w) - (t * h) • f' x w - (t * h^2) • f'' v w - ((t * h)^2/2) • f'' w w, set g' := λ t, f' (x + h • v + (t * h) • w) (h • w) - h • f' x w - h^2 • f'' v w - (t * h^2) • f'' w w with hg', -- check that `g'` is the derivative of `g`, by a straightforward computation have g_deriv : ∀ t ∈ Icc (0 : ℝ) 1, has_deriv_within_at g (g' t) (Icc 0 1) t, { assume t ht, apply_rules [has_deriv_within_at.sub, has_deriv_within_at.add], { refine (hf _ _).comp_has_deriv_within_at _ _, { exact xt_mem t ht }, apply_rules [has_deriv_at.has_deriv_within_at, has_deriv_at.const_add, has_deriv_at.smul_const, has_deriv_at_mul_const] }, { apply_rules [has_deriv_at.has_deriv_within_at, has_deriv_at.smul_const, has_deriv_at_mul_const] }, { apply_rules [has_deriv_at.has_deriv_within_at, has_deriv_at.smul_const, has_deriv_at_mul_const] }, { suffices H : has_deriv_within_at (λ u, ((u * h) ^ 2 / 2) • f'' w w) (((((2 : ℕ) : ℝ) * (t * h) ^ (2 - 1) * (1 * h))/2) • f'' w w) (Icc 0 1) t, { convert H using 2, simp only [one_mul, nat.cast_bit0, pow_one, nat.cast_one], ring }, apply_rules [has_deriv_at.has_deriv_within_at, has_deriv_at.smul_const, has_deriv_at_id', has_deriv_at.pow, has_deriv_at.mul_const] } }, -- check that `g'` is uniformly bounded, with a suitable bound `ε * ((‖v‖ + ‖w‖) * ‖w‖) * h^2`. have g'_bound : ∀ t ∈ Ico (0 : ℝ) 1, ‖g' t‖ ≤ ε * ((‖v‖ + ‖w‖) * ‖w‖) * h^2, { assume t ht, have I : ‖h • v + (t * h) • w‖ ≤ h * (‖v‖ + ‖w‖) := calc ‖h • v + (t * h) • w‖ ≤ ‖h • v‖ + ‖(t * h) • w‖ : norm_add_le _ _ ... = h * ‖v‖ + t * (h * ‖w‖) : by simp only [norm_smul, real.norm_eq_abs, hpos.le, abs_of_nonneg, abs_mul, ht.left, mul_assoc] ... ≤ h * ‖v‖ + 1 * (h * ‖w‖) : add_le_add le_rfl (mul_le_mul_of_nonneg_right ht.2.le (mul_nonneg hpos.le (norm_nonneg _))) ... = h * (‖v‖ + ‖w‖) : by ring, calc ‖g' t‖ = ‖(f' (x + h • v + (t * h) • w) - f' x - f'' (h • v + (t * h) • w)) (h • w)‖ : begin rw hg', have : h * (t * h) = t * (h * h), by ring, simp only [continuous_linear_map.coe_sub', continuous_linear_map.map_add, pow_two, continuous_linear_map.add_apply, pi.smul_apply, smul_sub, smul_add, smul_smul, ← sub_sub, continuous_linear_map.coe_smul', pi.sub_apply, continuous_linear_map.map_smul, this] end ... ≤ ‖f' (x + h • v + (t * h) • w) - f' x - f'' (h • v + (t * h) • w)‖ * ‖h • w‖ : continuous_linear_map.le_op_norm _ _ ... ≤ (ε * ‖h • v + (t * h) • w‖) * (‖h • w‖) : begin apply mul_le_mul_of_nonneg_right _ (norm_nonneg _), have H : x + h • v + (t * h) • w ∈ metric.ball x δ ∩ interior s, { refine ⟨_, xt_mem t ⟨ht.1, ht.2.le⟩⟩, rw [add_assoc, add_mem_ball_iff_norm], exact I.trans_lt hδ }, simpa only [mem_set_of_eq, add_assoc x, add_sub_cancel'] using sδ H, end ... ≤ (ε * (‖h • v‖ + ‖h • w‖)) * (‖h • w‖) : begin apply mul_le_mul_of_nonneg_right _ (norm_nonneg _), apply mul_le_mul_of_nonneg_left _ (εpos.le), apply (norm_add_le _ _).trans, refine add_le_add le_rfl _, simp only [norm_smul, real.norm_eq_abs, abs_mul, abs_of_nonneg, ht.1, hpos.le, mul_assoc], exact mul_le_of_le_one_left (mul_nonneg hpos.le (norm_nonneg _)) ht.2.le, end ... = ε * ((‖v‖ + ‖w‖) * ‖w‖) * h^2 : by { simp only [norm_smul, real.norm_eq_abs, abs_mul, abs_of_nonneg, hpos.le], ring } }, -- conclude using the mean value inequality have I : ‖g 1 - g 0‖ ≤ ε * ((‖v‖ + ‖w‖) * ‖w‖) * h^2, by simpa only [mul_one, sub_zero] using norm_image_sub_le_of_norm_deriv_le_segment' g_deriv g'_bound 1 (right_mem_Icc.2 zero_le_one), convert I using 1, { congr' 1, dsimp only [g], simp only [nat.one_ne_zero, add_zero, one_mul, zero_div, zero_mul, sub_zero, zero_smul, ne.def, not_false_iff, bit0_eq_zero, zero_pow'], abel }, { simp only [real.norm_eq_abs, abs_mul, add_nonneg (norm_nonneg v) (norm_nonneg w), abs_of_nonneg, mul_assoc, pow_bit0_abs, norm_nonneg, abs_pow] } end /-- One can get `f'' v w` as the limit of `h ^ (-2)` times the alternate sum of the values of `f` along the vertices of a quadrilateral with sides `h v` and `h w` based at `x`. In a setting where `f` is not guaranteed to be continuous at `f`, we can still get this if we use a quadrilateral based at `h v + h w`. -/ lemma convex.is_o_alternate_sum_square {v w : E} (h4v : x + (4 : ℝ) • v ∈ interior s) (h4w : x + (4 : ℝ) • w ∈ interior s) : (λ h : ℝ, f (x + h • (2 • v + 2 • w)) + f (x + h • (v + w)) - f (x + h • (2 • v + w)) - f (x + h • (v + 2 • w)) - h^2 • f'' v w) =o[𝓝[>] 0] (λ h, h^2) := begin have A : (1 : ℝ)/2 ∈ Ioc (0 : ℝ) 1 := ⟨by norm_num, by norm_num⟩, have B : (1 : ℝ)/2 ∈ Icc (0 : ℝ) 1 := ⟨by norm_num, by norm_num⟩, have C : ∀ (w : E), (2 : ℝ) • w = 2 • w := λ w, by simp only [two_smul], have h2v2w : x + (2 : ℝ) • v + (2 : ℝ) • w ∈ interior s, { convert s_conv.interior.add_smul_sub_mem h4v h4w B using 1, simp only [smul_sub, smul_smul, one_div, add_sub_add_left_eq_sub, mul_add, add_smul], norm_num, simp only [show (4 : ℝ) = (2 : ℝ) + (2 : ℝ), by norm_num, add_smul], abel }, have h2vww : x + (2 • v + w) + w ∈ interior s, { convert h2v2w using 1, simp only [two_smul], abel }, have h2v : x + (2 : ℝ) • v ∈ interior s, { convert s_conv.add_smul_sub_mem_interior xs h4v A using 1, simp only [smul_smul, one_div, add_sub_cancel', add_right_inj], norm_num }, have h2w : x + (2 : ℝ) • w ∈ interior s, { convert s_conv.add_smul_sub_mem_interior xs h4w A using 1, simp only [smul_smul, one_div, add_sub_cancel', add_right_inj], norm_num }, have hvw : x + (v + w) ∈ interior s, { convert s_conv.add_smul_sub_mem_interior xs h2v2w A using 1, simp only [smul_smul, one_div, add_sub_cancel', add_right_inj, smul_add, smul_sub], norm_num, abel }, have h2vw : x + (2 • v + w) ∈ interior s, { convert s_conv.interior.add_smul_sub_mem h2v h2v2w B using 1, simp only [smul_add, smul_sub, smul_smul, ← C], norm_num, abel }, have hvww : x + (v + w) + w ∈ interior s, { convert s_conv.interior.add_smul_sub_mem h2w h2v2w B using 1, simp only [one_div, add_sub_cancel', inv_smul_smul₀, add_sub_add_right_eq_sub, ne.def, not_false_iff, bit0_eq_zero, one_ne_zero], rw two_smul, abel }, have TA1 := s_conv.taylor_approx_two_segment hf xs hx h2vw h2vww, have TA2 := s_conv.taylor_approx_two_segment hf xs hx hvw hvww, convert TA1.sub TA2, ext h, simp only [two_smul, smul_add, ← add_assoc, continuous_linear_map.map_add, continuous_linear_map.add_apply, pi.smul_apply, continuous_linear_map.coe_smul', continuous_linear_map.map_smul], abel, end /-- Assume that `f` is differentiable inside a convex set `s`, and that its derivative `f'` is differentiable at a point `x`. Then, given two vectors `v` and `w` pointing inside `s`, one has `f'' v w = f'' w v`. Superseded by `convex.second_derivative_within_at_symmetric`, which removes the assumption that `v` and `w` point inside `s`. -/ lemma convex.second_derivative_within_at_symmetric_of_mem_interior {v w : E} (h4v : x + (4 : ℝ) • v ∈ interior s) (h4w : x + (4 : ℝ) • w ∈ interior s) : f'' w v = f'' v w := begin have A : (λ h : ℝ, h^2 • (f'' w v- f'' v w)) =o[𝓝[>] 0] (λ h, h^2), { convert (s_conv.is_o_alternate_sum_square hf xs hx h4v h4w).sub (s_conv.is_o_alternate_sum_square hf xs hx h4w h4v), ext h, simp only [add_comm, smul_add, smul_sub], abel }, have B : (λ h : ℝ, f'' w v - f'' v w) =o[𝓝[>] 0] (λ h, (1 : ℝ)), { have : (λ h : ℝ, 1/h^2) =O[𝓝[>] 0] (λ h, 1/h^2) := is_O_refl _ _, have C := this.smul_is_o A, apply C.congr' _ _, { filter_upwards [self_mem_nhds_within], assume h hpos, rw [← one_smul ℝ (f'' w v - f'' v w), smul_smul, smul_smul], congr' 1, field_simp [has_lt.lt.ne' hpos] }, { filter_upwards [self_mem_nhds_within] with _ hpos, field_simp [has_lt.lt.ne' hpos, has_smul.smul], }, }, simpa only [sub_eq_zero] using is_o_const_const_iff.1 B, end omit s_conv xs hx hf /-- If a function is differentiable inside a convex set with nonempty interior, and has a second derivative at a point of this convex set, then this second derivative is symmetric. -/ theorem convex.second_derivative_within_at_symmetric {s : set E} (s_conv : convex ℝ s) (hne : (interior s).nonempty) {f : E → F} {f' : E → (E →L[ℝ] F)} {f'' : E →L[ℝ] (E →L[ℝ] F)} (hf : ∀ x ∈ interior s, has_fderiv_at f (f' x) x) {x : E} (xs : x ∈ s) (hx : has_fderiv_within_at f' f'' (interior s) x) (v w : E) : f'' v w = f'' w v := begin /- we work around a point `x + 4 z` in the interior of `s`. For any vector `m`, then `x + 4 (z + t m)` also belongs to the interior of `s` for small enough `t`. This means that we will be able to apply `second_derivative_within_at_symmetric_of_mem_interior` to show that `f''` is symmetric, after cancelling all the contributions due to `z`. -/ rcases hne with ⟨y, hy⟩, obtain ⟨z, hz⟩ : ∃ z, z = ((1:ℝ) / 4) • (y - x) := ⟨((1:ℝ) / 4) • (y - x), rfl⟩, have A : ∀ (m : E), filter.tendsto (λ (t : ℝ), x + (4 : ℝ) • (z + t • m)) (𝓝 0) (𝓝 y), { assume m, have : x + (4 : ℝ) • (z + (0 : ℝ) • m) = y, by simp [hz], rw ← this, refine tendsto_const_nhds.add _, refine tendsto_const_nhds.smul _, refine tendsto_const_nhds.add _, exact continuous_at_id.smul continuous_at_const }, have B : ∀ (m : E), ∀ᶠ t in 𝓝[>] (0 : ℝ), x + (4 : ℝ) • (z + t • m) ∈ interior s, { assume m, apply nhds_within_le_nhds, apply A m, rw [mem_interior_iff_mem_nhds] at hy, exact interior_mem_nhds.2 hy }, -- we choose `t m > 0` such that `x + 4 (z + (t m) m)` belongs to the interior of `s`, for any -- vector `m`. choose t ts tpos using λ m, ((B m).and self_mem_nhds_within).exists, -- applying `second_derivative_within_at_symmetric_of_mem_interior` to the vectors `z` -- and `z + (t m) m`, we deduce that `f'' m z = f'' z m` for all `m`. have C : ∀ (m : E), f'' m z = f'' z m, { assume m, have : f'' (z + t m • m) (z + t 0 • 0) = f'' (z + t 0 • 0) (z + t m • m) := s_conv.second_derivative_within_at_symmetric_of_mem_interior hf xs hx (ts 0) (ts m), simp only [continuous_linear_map.map_add, continuous_linear_map.map_smul, add_right_inj, continuous_linear_map.add_apply, pi.smul_apply, continuous_linear_map.coe_smul', add_zero, continuous_linear_map.zero_apply, smul_zero, continuous_linear_map.map_zero] at this, exact smul_right_injective F (tpos m).ne' this }, -- applying `second_derivative_within_at_symmetric_of_mem_interior` to the vectors `z + (t v) v` -- and `z + (t w) w`, we deduce that `f'' v w = f'' w v`. Cross terms involving `z` can be -- eliminated thanks to the fact proved above that `f'' m z = f'' z m`. have : f'' (z + t v • v) (z + t w • w) = f'' (z + t w • w) (z + t v • v) := s_conv.second_derivative_within_at_symmetric_of_mem_interior hf xs hx (ts w) (ts v), simp only [continuous_linear_map.map_add, continuous_linear_map.map_smul, smul_add, smul_smul, continuous_linear_map.add_apply, pi.smul_apply, continuous_linear_map.coe_smul', C] at this, rw ← sub_eq_zero at this, abel at this, simp only [one_zsmul, neg_smul, sub_eq_zero, mul_comm, ← sub_eq_add_neg] at this, apply smul_right_injective F _ this, simp [(tpos v).ne', (tpos w).ne'] end /-- If a function is differentiable around `x`, and has two derivatives at `x`, then the second derivative is symmetric. -/ theorem second_derivative_symmetric_of_eventually {f : E → F} {f' : E → (E →L[ℝ] F)} {f'' : E →L[ℝ] (E →L[ℝ] F)} (hf : ∀ᶠ y in 𝓝 x, has_fderiv_at f (f' y) y) (hx : has_fderiv_at f' f'' x) (v w : E) : f'' v w = f'' w v := begin rcases metric.mem_nhds_iff.1 hf with ⟨ε, εpos, hε⟩, have A : (interior (metric.ball x ε)).nonempty, by rwa [metric.is_open_ball.interior_eq, metric.nonempty_ball], exact convex.second_derivative_within_at_symmetric (convex_ball x ε) A (λ y hy, hε (interior_subset hy)) (metric.mem_ball_self εpos) hx.has_fderiv_within_at v w, end /-- If a function is differentiable, and has two derivatives at `x`, then the second derivative is symmetric. -/ theorem second_derivative_symmetric {f : E → F} {f' : E → (E →L[ℝ] F)} {f'' : E →L[ℝ] (E →L[ℝ] F)} (hf : ∀ y, has_fderiv_at f (f' y) y) (hx : has_fderiv_at f' f'' x) (v w : E) : f'' v w = f'' w v := second_derivative_symmetric_of_eventually (filter.eventually_of_forall hf) hx v w
74c43e39aae082a4d6f2a92e9a31d38c3a18a6a4
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/noindexAnnotation.lean
f6578f118ee0427ed38415fca30991016b91ec03
[ "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
320
lean
structure Fin2 (n : Nat) := (val : Nat) (isLt : val < n) protected def Fin2.ofNat {n : Nat} (a : Nat) : Fin2 (Nat.succ n) := ⟨a % Nat.succ n, Nat.mod_lt _ (Nat.zero_lt_succ _)⟩ instance : OfNat (Fin2 (no_index (n+1))) i where ofNat := Fin2.ofNat i def ex1 : Fin2 (9 + 1) := 0 def ex2 : Fin2 10 := 0
a44ec8c6a5c772d09a6c9e82b70a35a64a0cfc78
02005f45e00c7ecf2c8ca5db60251bd1e9c860b5
/src/algebra/ordered_monoid.lean
de6ead14e17fc813f2dc0b1669e73ebacaa4fc9d
[ "Apache-2.0" ]
permissive
anthony2698/mathlib
03cd69fe5c280b0916f6df2d07c614c8e1efe890
407615e05814e98b24b2ff322b14e8e3eb5e5d67
refs/heads/master
1,678,792,774,873
1,614,371,563,000
1,614,371,563,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
42,850
lean
/- Copyright (c) 2016 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, Johannes Hölzl -/ import algebra.group.with_one import algebra.group.type_tags import algebra.group.prod import algebra.order_functions import order.bounded_lattice /-! # Ordered monoids This file develops the basics of ordered monoids. ## Implementation details Unfortunately, the number of `'` appended to lemmas in this file may differ between the multiplicative and the additive version of a lemma. The reason is that we did not want to change existing names in the library. -/ set_option old_structure_cmd true universe u variable {α : Type u} /-- An ordered commutative monoid is a commutative monoid with a partial order such that * `a ≤ b → c * a ≤ c * b` (multiplication is monotone) * `a * b < a * c → b < c`. -/ @[protect_proj, ancestor comm_monoid partial_order] class ordered_comm_monoid (α : Type*) extends comm_monoid α, partial_order α := (mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b) (lt_of_mul_lt_mul_left : ∀ a b c : α, a * b < a * c → b < c) /-- An ordered (additive) commutative monoid is a commutative monoid with a partial order such that * `a ≤ b → c + a ≤ c + b` (addition is monotone) * `a + b < a + c → b < c`. -/ @[protect_proj, ancestor add_comm_monoid partial_order] class ordered_add_comm_monoid (α : Type*) extends add_comm_monoid α, partial_order α := (add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b) (lt_of_add_lt_add_left : ∀ a b c : α, a + b < a + c → b < c) attribute [to_additive] ordered_comm_monoid /-- A linearly ordered commutative monoid with a zero element. -/ class linear_ordered_comm_monoid_with_zero (α : Type*) extends linear_order α, comm_monoid_with_zero α, ordered_comm_monoid α := (zero_le_one : (0:α) ≤ 1) (lt_of_mul_lt_mul_left := λ x y z, by { apply imp_of_not_imp_not, intro h, apply not_lt_of_le, apply mul_le_mul_left, -- type-class inference uses `a : linear_order α` which it can't unfold, unless we provide this! -- `lt_iff_le_not_le` gets filled incorrectly with `autoparam` if we don't provide that field. letI : linear_order α := by refine { le := le, lt := lt, lt_iff_le_not_le := _, .. }; assumption, exact le_of_not_lt h }) section ordered_comm_monoid variables [ordered_comm_monoid α] {a b c d : α} @[to_additive add_le_add_left] lemma mul_le_mul_left' (h : a ≤ b) (c) : c * a ≤ c * b := ordered_comm_monoid.mul_le_mul_left a b h c @[to_additive add_le_add_right] lemma mul_le_mul_right' (h : a ≤ b) (c) : a * c ≤ b * c := by { convert mul_le_mul_left' h c using 1; rw mul_comm } @[to_additive] lemma mul_lt_of_mul_lt_left (h : a * b < c) (hle : d ≤ b) : a * d < c := (mul_le_mul_left' hle a).trans_lt h @[to_additive] lemma mul_lt_of_mul_lt_right (h : a * b < c) (hle : d ≤ a) : d * b < c := (mul_le_mul_right' hle b).trans_lt h @[to_additive] lemma mul_le_of_mul_le_left (h : a * b ≤ c) (hle : d ≤ b) : a * d ≤ c := (mul_le_mul_left' hle a).trans h @[to_additive] lemma mul_le_of_mul_le_right (h : a * b ≤ c) (hle : d ≤ a) : d * b ≤ c := (mul_le_mul_right' hle b).trans h @[to_additive] lemma lt_mul_of_lt_mul_left (h : a < b * c) (hle : c ≤ d) : a < b * d := h.trans_le (mul_le_mul_left' hle b) @[to_additive] lemma lt_mul_of_lt_mul_right (h : a < b * c) (hle : b ≤ d) : a < d * c := h.trans_le (mul_le_mul_right' hle c) @[to_additive] lemma le_mul_of_le_mul_left (h : a ≤ b * c) (hle : c ≤ d) : a ≤ b * d := h.trans (mul_le_mul_left' hle b) @[to_additive] lemma le_mul_of_le_mul_right (h : a ≤ b * c) (hle : b ≤ d) : a ≤ d * c := h.trans (mul_le_mul_right' hle c) @[to_additive lt_of_add_lt_add_left] lemma lt_of_mul_lt_mul_left' : a * b < a * c → b < c := ordered_comm_monoid.lt_of_mul_lt_mul_left a b c @[to_additive lt_of_add_lt_add_right] lemma lt_of_mul_lt_mul_right' (h : a * b < c * b) : a < c := lt_of_mul_lt_mul_left' (show b * a < b * c, begin rw [mul_comm b a, mul_comm b c], assumption end) @[to_additive add_le_add] lemma mul_le_mul' (h₁ : a ≤ b) (h₂ : c ≤ d) : a * c ≤ b * d := (mul_le_mul_right' h₁ _).trans $ mul_le_mul_left' h₂ _ @[to_additive] lemma mul_le_mul_three {e f : α} (h₁ : a ≤ d) (h₂ : b ≤ e) (h₃ : c ≤ f) : a * b * c ≤ d * e * f := mul_le_mul' (mul_le_mul' h₁ h₂) h₃ -- here we start using properties of one. @[to_additive le_add_of_nonneg_right] lemma le_mul_of_one_le_right' (h : 1 ≤ b) : a ≤ a * b := by simpa only [mul_one] using mul_le_mul_left' h a @[to_additive le_add_of_nonneg_left] lemma le_mul_of_one_le_left' (h : 1 ≤ b) : a ≤ b * a := by simpa only [one_mul] using mul_le_mul_right' h a @[to_additive add_le_of_nonpos_right] lemma mul_le_of_le_one_right' (h : b ≤ 1) : a * b ≤ a := by simpa only [mul_one] using mul_le_mul_left' h a @[to_additive add_le_of_nonpos_left] lemma mul_le_of_le_one_left' (h : b ≤ 1) : b * a ≤ a := by simpa only [one_mul] using mul_le_mul_right' h a @[to_additive] lemma lt_of_mul_lt_of_one_le_left (h : a * b < c) (hle : 1 ≤ b) : a < c := (le_mul_of_one_le_right' hle).trans_lt h @[to_additive] lemma lt_of_mul_lt_of_one_le_right (h : a * b < c) (hle : 1 ≤ a) : b < c := (le_mul_of_one_le_left' hle).trans_lt h @[to_additive] lemma le_of_mul_le_of_one_le_left (h : a * b ≤ c) (hle : 1 ≤ b) : a ≤ c := (le_mul_of_one_le_right' hle).trans h @[to_additive] lemma le_of_mul_le_of_one_le_right (h : a * b ≤ c) (hle : 1 ≤ a) : b ≤ c := (le_mul_of_one_le_left' hle).trans h @[to_additive] lemma lt_of_lt_mul_of_le_one_left (h : a < b * c) (hle : c ≤ 1) : a < b := h.trans_le (mul_le_of_le_one_right' hle) @[to_additive] lemma lt_of_lt_mul_of_le_one_right (h : a < b * c) (hle : b ≤ 1) : a < c := h.trans_le (mul_le_of_le_one_left' hle) @[to_additive] lemma le_of_le_mul_of_le_one_left (h : a ≤ b * c) (hle : c ≤ 1) : a ≤ b := h.trans (mul_le_of_le_one_right' hle) @[to_additive] lemma le_of_le_mul_of_le_one_right (h : a ≤ b * c) (hle : b ≤ 1) : a ≤ c := h.trans (mul_le_of_le_one_left' hle) @[to_additive] lemma le_mul_of_one_le_of_le (ha : 1 ≤ a) (hbc : b ≤ c) : b ≤ a * c := one_mul b ▸ mul_le_mul' ha hbc @[to_additive] lemma le_mul_of_le_of_one_le (hbc : b ≤ c) (ha : 1 ≤ a) : b ≤ c * a := mul_one b ▸ mul_le_mul' hbc ha @[to_additive add_nonneg] lemma one_le_mul (ha : 1 ≤ a) (hb : 1 ≤ b) : 1 ≤ a * b := le_mul_of_one_le_of_le ha hb @[to_additive add_pos_of_pos_of_nonneg] lemma one_lt_mul_of_lt_of_le' (ha : 1 < a) (hb : 1 ≤ b) : 1 < a * b := lt_of_lt_of_le ha $ le_mul_of_one_le_right' hb @[to_additive add_pos_of_nonneg_of_pos] lemma one_lt_mul_of_le_of_lt' (ha : 1 ≤ a) (hb : 1 < b) : 1 < a * b := lt_of_lt_of_le hb $ le_mul_of_one_le_left' ha @[to_additive add_pos] lemma one_lt_mul' (ha : 1 < a) (hb : 1 < b) : 1 < a * b := one_lt_mul_of_lt_of_le' ha hb.le @[to_additive add_nonpos] lemma mul_le_one' (ha : a ≤ 1) (hb : b ≤ 1) : a * b ≤ 1 := one_mul (1:α) ▸ (mul_le_mul' ha hb) @[to_additive] lemma mul_le_of_le_one_of_le' (ha : a ≤ 1) (hbc : b ≤ c) : a * b ≤ c := one_mul c ▸ mul_le_mul' ha hbc @[to_additive] lemma mul_le_of_le_of_le_one' (hbc : b ≤ c) (ha : a ≤ 1) : b * a ≤ c := mul_one c ▸ mul_le_mul' hbc ha @[to_additive] lemma mul_lt_one_of_lt_one_of_le_one' (ha : a < 1) (hb : b ≤ 1) : a * b < 1 := (mul_le_of_le_of_le_one' le_rfl hb).trans_lt ha @[to_additive] lemma mul_lt_one_of_le_one_of_lt_one' (ha : a ≤ 1) (hb : b < 1) : a * b < 1 := (mul_le_of_le_one_of_le' ha le_rfl).trans_lt hb @[to_additive] lemma mul_lt_one' (ha : a < 1) (hb : b < 1) : a * b < 1 := mul_lt_one_of_le_one_of_lt_one' ha.le hb @[to_additive] lemma lt_mul_of_one_le_of_lt' (ha : 1 ≤ a) (hbc : b < c) : b < a * c := hbc.trans_le $ le_mul_of_one_le_left' ha @[to_additive] lemma lt_mul_of_lt_of_one_le' (hbc : b < c) (ha : 1 ≤ a) : b < c * a := hbc.trans_le $ le_mul_of_one_le_right' ha @[to_additive] lemma lt_mul_of_one_lt_of_lt' (ha : 1 < a) (hbc : b < c) : b < a * c := lt_mul_of_one_le_of_lt' ha.le hbc @[to_additive] lemma lt_mul_of_lt_of_one_lt' (hbc : b < c) (ha : 1 < a) : b < c * a := lt_mul_of_lt_of_one_le' hbc ha.le @[to_additive] lemma mul_lt_of_le_one_of_lt' (ha : a ≤ 1) (hbc : b < c) : a * b < c := lt_of_le_of_lt (mul_le_of_le_one_of_le' ha le_rfl) hbc @[to_additive] lemma mul_lt_of_lt_of_le_one' (hbc : b < c) (ha : a ≤ 1) : b * a < c := lt_of_le_of_lt (mul_le_of_le_of_le_one' le_rfl ha) hbc @[to_additive] lemma mul_lt_of_lt_one_of_lt' (ha : a < 1) (hbc : b < c) : a * b < c := mul_lt_of_le_one_of_lt' ha.le hbc @[to_additive] lemma mul_lt_of_lt_of_lt_one' (hbc : b < c) (ha : a < 1) : b * a < c := mul_lt_of_lt_of_le_one' hbc ha.le @[to_additive] lemma mul_eq_one_iff' (ha : 1 ≤ a) (hb : 1 ≤ b) : a * b = 1 ↔ a = 1 ∧ b = 1 := iff.intro (assume hab : a * b = 1, have a ≤ 1, from hab ▸ le_mul_of_le_of_one_le le_rfl hb, have a = 1, from le_antisymm this ha, have b ≤ 1, from hab ▸ le_mul_of_one_le_of_le ha le_rfl, have b = 1, from le_antisymm this hb, and.intro ‹a = 1› ‹b = 1›) (assume ⟨ha', hb'⟩, by rw [ha', hb', mul_one]) section mono variables {β : Type*} [preorder β] {f g : β → α} @[to_additive monotone.add] lemma monotone.mul' (hf : monotone f) (hg : monotone g) : monotone (λ x, f x * g x) := λ x y h, mul_le_mul' (hf h) (hg h) @[to_additive monotone.add_const] lemma monotone.mul_const' (hf : monotone f) (a : α) : monotone (λ x, f x * a) := hf.mul' monotone_const @[to_additive monotone.const_add] lemma monotone.const_mul' (hf : monotone f) (a : α) : monotone (λ x, a * f x) := monotone_const.mul' hf end mono end ordered_comm_monoid lemma bit0_pos [ordered_add_comm_monoid α] {a : α} (h : 0 < a) : 0 < bit0 a := add_pos h h namespace units @[to_additive] instance [monoid α] [preorder α] : preorder (units α) := preorder.lift (coe : units α → α) @[simp, norm_cast, to_additive] theorem coe_le_coe [monoid α] [preorder α] {a b : units α} : (a : α) ≤ b ↔ a ≤ b := iff.rfl -- should `to_additive` do this? attribute [norm_cast] add_units.coe_le_coe @[simp, norm_cast, to_additive] theorem coe_lt_coe [monoid α] [preorder α] {a b : units α} : (a : α) < b ↔ a < b := iff.rfl attribute [norm_cast] add_units.coe_lt_coe @[to_additive] instance [monoid α] [partial_order α] : partial_order (units α) := partial_order.lift coe units.ext @[to_additive] instance [monoid α] [linear_order α] : linear_order (units α) := linear_order.lift coe units.ext @[simp, norm_cast, to_additive] theorem max_coe [monoid α] [linear_order α] {a b : units α} : (↑(max a b) : α) = max a b := by by_cases b ≤ a; simp [max, h] attribute [norm_cast] add_units.max_coe @[simp, norm_cast, to_additive] theorem min_coe [monoid α] [linear_order α] {a b : units α} : (↑(min a b) : α) = min a b := by by_cases a ≤ b; simp [min, h] attribute [norm_cast] add_units.min_coe end units namespace with_zero local attribute [semireducible] with_zero instance [preorder α] : preorder (with_zero α) := with_bot.preorder instance [partial_order α] : partial_order (with_zero α) := with_bot.partial_order instance [partial_order α] : order_bot (with_zero α) := with_bot.order_bot lemma zero_le [partial_order α] (a : with_zero α) : 0 ≤ a := order_bot.bot_le a lemma zero_lt_coe [partial_order α] (a : α) : (0 : with_zero α) < a := with_bot.bot_lt_coe a @[simp, norm_cast] lemma coe_lt_coe [partial_order α] {a b : α} : (a : with_zero α) < b ↔ a < b := with_bot.coe_lt_coe @[simp, norm_cast] lemma coe_le_coe [partial_order α] {a b : α} : (a : with_zero α) ≤ b ↔ a ≤ b := with_bot.coe_le_coe instance [lattice α] : lattice (with_zero α) := with_bot.lattice instance [linear_order α] : linear_order (with_zero α) := with_bot.linear_order lemma mul_le_mul_left {α : Type u} [ordered_comm_monoid α] : ∀ (a b : with_zero α), a ≤ b → ∀ (c : with_zero α), c * a ≤ c * b := begin rintro (_ | a) (_ | b) h (_ | c), { apply with_zero.zero_le }, { apply with_zero.zero_le }, { apply with_zero.zero_le }, { apply with_zero.zero_le }, { apply with_zero.zero_le }, { exact false.elim (not_lt_of_le h (with_zero.zero_lt_coe a))}, { apply with_zero.zero_le }, { simp_rw [some_eq_coe] at h ⊢, norm_cast at h ⊢, exact mul_le_mul_left' h c } end lemma lt_of_mul_lt_mul_left {α : Type u} [ordered_comm_monoid α] : ∀ (a b c : with_zero α), a * b < a * c → b < c := begin rintro (_ | a) (_ | b) (_ | c) h, { exact false.elim (lt_irrefl none h) }, { exact false.elim (lt_irrefl none h) }, { exact false.elim (lt_irrefl none h) }, { exact false.elim (lt_irrefl none h) }, { exact false.elim (lt_irrefl none h) }, { exact with_zero.zero_lt_coe c }, { exact false.elim (not_le_of_lt h (with_zero.zero_le _)) }, { simp_rw [some_eq_coe] at h ⊢, norm_cast at h ⊢, apply lt_of_mul_lt_mul_left' h } end instance [ordered_comm_monoid α] : ordered_comm_monoid (with_zero α) := { mul_le_mul_left := with_zero.mul_le_mul_left, lt_of_mul_lt_mul_left := with_zero.lt_of_mul_lt_mul_left, ..with_zero.comm_monoid_with_zero, ..with_zero.partial_order } /- Note 1 : the below is not an instance because it requires `zero_le`. It seems like a rather pathological definition because α already has a zero. Note 2 : there is no multiplicative analogue because it does not seem necessary. Mathematicians might be more likely to use the order-dual version, where all elements are ≤ 1 and then 1 is the top element. -/ /-- If `0` is the least element in `α`, then `with_zero α` is an `ordered_add_comm_monoid`. -/ def ordered_add_comm_monoid [ordered_add_comm_monoid α] (zero_le : ∀ a : α, 0 ≤ a) : ordered_add_comm_monoid (with_zero α) := begin suffices, refine { add_le_add_left := this, ..with_zero.partial_order, ..with_zero.add_comm_monoid, .. }, { intros a b c h, have h' := lt_iff_le_not_le.1 h, rw lt_iff_le_not_le at ⊢, refine ⟨λ b h₂, _, λ h₂, h'.2 $ this _ _ h₂ _⟩, cases h₂, cases c with c, { cases h'.2 (this _ _ bot_le a) }, { refine ⟨_, rfl, _⟩, cases a with a, { exact with_bot.some_le_some.1 h'.1 }, { exact le_of_lt (lt_of_add_lt_add_left $ with_bot.some_lt_some.1 h), } } }, { intros a b h c ca h₂, cases b with b, { rw le_antisymm h bot_le at h₂, exact ⟨_, h₂, le_refl _⟩ }, cases a with a, { change c + 0 = some ca at h₂, simp at h₂, simp [h₂], exact ⟨_, rfl, by simpa using add_le_add_left (zero_le b) _⟩ }, { simp at h, cases c with c; change some _ = _ at h₂; simp [-add_comm] at h₂; subst ca; refine ⟨_, rfl, _⟩, { exact h }, { exact add_le_add_left h _ } } } end end with_zero namespace with_top section has_one variables [has_one α] @[to_additive] instance : has_one (with_top α) := ⟨(1 : α)⟩ @[simp, to_additive] lemma coe_one : ((1 : α) : with_top α) = 1 := rfl @[simp, to_additive] lemma coe_eq_one {a : α} : (a : with_top α) = 1 ↔ a = 1 := coe_eq_coe @[simp, to_additive] theorem one_eq_coe {a : α} : 1 = (a : with_top α) ↔ a = 1 := by rw [eq_comm, coe_eq_one] attribute [norm_cast] coe_one coe_eq_one coe_zero coe_eq_zero one_eq_coe zero_eq_coe @[simp, to_additive] theorem top_ne_one : ⊤ ≠ (1 : with_top α) . @[simp, to_additive] theorem one_ne_top : (1 : with_top α) ≠ ⊤ . end has_one instance [has_add α] : has_add (with_top α) := ⟨λ o₁ o₂, o₁.bind (λ a, o₂.map (λ b, a + b))⟩ local attribute [reducible] with_zero instance [add_semigroup α] : add_semigroup (with_top α) := { add := (+), ..@additive.add_semigroup _ $ @with_zero.semigroup (multiplicative α) _ } @[norm_cast] lemma coe_add [has_add α] {a b : α} : ((a + b : α) : with_top α) = a + b := rfl @[norm_cast] lemma coe_bit0 [has_add α] {a : α} : ((bit0 a : α) : with_top α) = bit0 a := rfl @[norm_cast] lemma coe_bit1 [has_add α] [has_one α] {a : α} : ((bit1 a : α) : with_top α) = bit1 a := rfl @[simp] lemma add_top [has_add α] : ∀{a : with_top α}, a + ⊤ = ⊤ | none := rfl | (some a) := rfl @[simp] lemma top_add [has_add α] {a : with_top α} : ⊤ + a = ⊤ := rfl lemma add_eq_top [has_add α] {a b : with_top α} : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := by {cases a; cases b; simp [none_eq_top, some_eq_coe, ←with_top.coe_add, ←with_zero.coe_add]} lemma add_lt_top [has_add α] [partial_order α] {a b : with_top α} : a + b < ⊤ ↔ a < ⊤ ∧ b < ⊤ := by simp [lt_top_iff_ne_top, add_eq_top, not_or_distrib] lemma add_eq_coe [has_add α] : ∀ {a b : with_top α} {c : α}, a + b = c ↔ ∃ (a' b' : α), ↑a' = a ∧ ↑b' = b ∧ a' + b' = c | none b c := by simp [none_eq_top] | (some a) none c := by simp [none_eq_top] | (some a) (some b) c := by simp only [some_eq_coe, ← coe_add, coe_eq_coe, exists_and_distrib_left, exists_eq_left] instance [add_comm_semigroup α] : add_comm_semigroup (with_top α) := { ..@additive.add_comm_semigroup _ $ @with_zero.comm_semigroup (multiplicative α) _ } instance [add_monoid α] : add_monoid (with_top α) := { zero := some 0, add := (+), ..@additive.add_monoid _ $ @monoid_with_zero.to_monoid _ $ @with_zero.monoid_with_zero (multiplicative α) _ } instance [add_comm_monoid α] : add_comm_monoid (with_top α) := { zero := 0, add := (+), ..@additive.add_comm_monoid _ $ @comm_monoid_with_zero.to_comm_monoid _ $ @with_zero.comm_monoid_with_zero (multiplicative α) _ } instance [ordered_add_comm_monoid α] : ordered_add_comm_monoid (with_top α) := { add_le_add_left := begin rintros a b h (_|c), { simp [none_eq_top] }, rcases b with (_|b), { simp [none_eq_top] }, rcases le_coe_iff.1 h with ⟨a, rfl, h⟩, simp only [some_eq_coe, ← coe_add, coe_le_coe] at h ⊢, exact add_le_add_left h c end, lt_of_add_lt_add_left := begin intros a b c h, rcases lt_iff_exists_coe.1 h with ⟨ab, hab, hlt⟩, rcases add_eq_coe.1 hab with ⟨a, b, rfl, rfl, rfl⟩, rw coe_lt_iff, rintro c rfl, exact lt_of_add_lt_add_left (coe_lt_coe.1 hlt) end, ..with_top.partial_order, ..with_top.add_comm_monoid } /-- Coercion from `α` to `with_top α` as an `add_monoid_hom`. -/ def coe_add_hom [add_monoid α] : α →+ with_top α := ⟨coe, rfl, λ _ _, rfl⟩ @[simp] lemma coe_coe_add_hom [add_monoid α] : ⇑(coe_add_hom : α →+ with_top α) = coe := rfl @[simp] lemma zero_lt_top [ordered_add_comm_monoid α] : (0 : with_top α) < ⊤ := coe_lt_top 0 @[simp, norm_cast] lemma zero_lt_coe [ordered_add_comm_monoid α] (a : α) : (0 : with_top α) < a ↔ 0 < a := coe_lt_coe end with_top namespace with_bot instance [has_zero α] : has_zero (with_bot α) := with_top.has_zero instance [has_one α] : has_one (with_bot α) := with_top.has_one instance [add_semigroup α] : add_semigroup (with_bot α) := with_top.add_semigroup instance [add_comm_semigroup α] : add_comm_semigroup (with_bot α) := with_top.add_comm_semigroup instance [add_monoid α] : add_monoid (with_bot α) := with_top.add_monoid instance [add_comm_monoid α] : add_comm_monoid (with_bot α) := with_top.add_comm_monoid instance [ordered_add_comm_monoid α] : ordered_add_comm_monoid (with_bot α) := begin suffices, refine { add_le_add_left := this, ..with_bot.partial_order, ..with_bot.add_comm_monoid, ..}, { intros a b c h, have h' := h, rw lt_iff_le_not_le at h' ⊢, refine ⟨λ b h₂, _, λ h₂, h'.2 $ this _ _ h₂ _⟩, cases h₂, cases a with a, { exact (not_le_of_lt h).elim bot_le }, cases c with c, { exact (not_le_of_lt h).elim bot_le }, { exact ⟨_, rfl, le_of_lt (lt_of_add_lt_add_left $ with_bot.some_lt_some.1 h)⟩ } }, { intros a b h c ca h₂, cases c with c, {cases h₂}, cases a with a; cases h₂, cases b with b, {cases le_antisymm h bot_le}, simp at h, exact ⟨_, rfl, add_le_add_left h _⟩, } end -- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast` lemma coe_zero [has_zero α] : ((0 : α) : with_bot α) = 0 := rfl -- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast` lemma coe_one [has_one α] : ((1 : α) : with_bot α) = 1 := rfl -- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast` lemma coe_eq_zero {α : Type*} [add_monoid α] {a : α} : (a : with_bot α) = 0 ↔ a = 0 := by norm_cast -- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast` lemma coe_add [add_semigroup α] (a b : α) : ((a + b : α) : with_bot α) = a + b := by norm_cast -- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast` lemma coe_bit0 [add_semigroup α] {a : α} : ((bit0 a : α) : with_bot α) = bit0 a := by norm_cast -- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast` lemma coe_bit1 [add_semigroup α] [has_one α] {a : α} : ((bit1 a : α) : with_bot α) = bit1 a := by norm_cast @[simp] lemma bot_add [ordered_add_comm_monoid α] (a : with_bot α) : ⊥ + a = ⊥ := rfl @[simp] lemma add_bot [ordered_add_comm_monoid α] (a : with_bot α) : a + ⊥ = ⊥ := by cases a; refl end with_bot /-- A canonically ordered additive monoid is an ordered commutative additive monoid in which the ordering coincides with the subtractibility relation, which is to say, `a ≤ b` iff there exists `c` with `b = a + c`. This is satisfied by the natural numbers, for example, but not the integers or other nontrivial `ordered_add_comm_group`s. -/ @[protect_proj, ancestor ordered_add_comm_monoid order_bot] class canonically_ordered_add_monoid (α : Type*) extends ordered_add_comm_monoid α, order_bot α := (le_iff_exists_add : ∀ a b : α, a ≤ b ↔ ∃ c, b = a + c) /-- A canonically ordered monoid is an ordered commutative monoid in which the ordering coincides with the divisibility relation, which is to say, `a ≤ b` iff there exists `c` with `b = a * c`. Example seem rare; it seems more likely that the `order_dual` of a naturally-occurring lattice satisfies this than the lattice itself (for example, dual of the lattice of ideals of a PID or Dedekind domain satisfy this; collections of all things ≤ 1 seem to be more natural that collections of all things ≥ 1). -/ @[protect_proj, ancestor ordered_comm_monoid order_bot, to_additive] class canonically_ordered_monoid (α : Type*) extends ordered_comm_monoid α, order_bot α := (le_iff_exists_mul : ∀ a b : α, a ≤ b ↔ ∃ c, b = a * c) section canonically_ordered_monoid variables [canonically_ordered_monoid α] {a b c d : α} @[to_additive] lemma le_iff_exists_mul : a ≤ b ↔ ∃c, b = a * c := canonically_ordered_monoid.le_iff_exists_mul a b @[to_additive] lemma self_le_mul_right (a b : α) : a ≤ a * b := le_iff_exists_mul.mpr ⟨b, rfl⟩ @[to_additive] lemma self_le_mul_left (a b : α) : a ≤ b * a := by { rw [mul_comm], exact self_le_mul_right a b } @[simp, to_additive zero_le] lemma one_le (a : α) : 1 ≤ a := le_iff_exists_mul.mpr ⟨a, by simp⟩ @[simp, to_additive] lemma bot_eq_one : (⊥ : α) = 1 := le_antisymm bot_le (one_le ⊥) @[simp, to_additive] lemma mul_eq_one_iff : a * b = 1 ↔ a = 1 ∧ b = 1 := mul_eq_one_iff' (one_le _) (one_le _) @[simp, to_additive] lemma le_one_iff_eq_one : a ≤ 1 ↔ a = 1 := iff.intro (assume h, le_antisymm h (one_le a)) (assume h, h ▸ le_refl a) @[to_additive] lemma one_lt_iff_ne_one : 1 < a ↔ a ≠ 1 := iff.intro ne_of_gt $ assume hne, lt_of_le_of_ne (one_le _) hne.symm @[to_additive] lemma exists_pos_mul_of_lt (h : a < b) : ∃ c > 1, a * c = b := begin obtain ⟨c, hc⟩ := le_iff_exists_mul.1 h.le, refine ⟨c, one_lt_iff_ne_one.2 _, hc.symm⟩, rintro rfl, simpa [hc, lt_irrefl] using h end @[to_additive] lemma le_mul_left (h : a ≤ c) : a ≤ b * c := calc a = 1 * a : by simp ... ≤ b * c : mul_le_mul' (one_le _) h @[to_additive] lemma le_mul_right (h : a ≤ b) : a ≤ b * c := calc a = a * 1 : by simp ... ≤ b * c : mul_le_mul' h (one_le _) local attribute [semireducible] with_zero -- This instance looks absurd: a monoid already has a zero /-- Adding a new zero to a canonically ordered additive monoid produces another one. -/ instance with_zero.canonically_ordered_add_monoid {α : Type u} [canonically_ordered_add_monoid α] : canonically_ordered_add_monoid (with_zero α) := { le_iff_exists_add := λ a b, begin cases a with a, { exact iff_of_true bot_le ⟨b, (zero_add b).symm⟩ }, cases b with b, { exact iff_of_false (mt (le_antisymm bot_le) (by simp)) (λ ⟨c, h⟩, by cases c; cases h) }, { simp [le_iff_exists_add, -add_comm], split; intro h; rcases h with ⟨c, h⟩, { exact ⟨some c, congr_arg some h⟩ }, { cases c; cases h, { exact ⟨_, (add_zero _).symm⟩ }, { exact ⟨_, rfl⟩ } } } end, bot := 0, bot_le := assume a a' h, option.no_confusion h, .. with_zero.ordered_add_comm_monoid zero_le } instance with_top.canonically_ordered_add_monoid {α : Type u} [canonically_ordered_add_monoid α] : canonically_ordered_add_monoid (with_top α) := { le_iff_exists_add := assume a b, match a, b with | a, none := show a ≤ ⊤ ↔ ∃c, ⊤ = a + c, by simp; refine ⟨⊤, _⟩; cases a; refl | (some a), (some b) := show (a:with_top α) ≤ ↑b ↔ ∃c:with_top α, ↑b = ↑a + c, begin simp [canonically_ordered_add_monoid.le_iff_exists_add, -add_comm], split, { rintro ⟨c, rfl⟩, refine ⟨c, _⟩, norm_cast }, { exact assume h, match b, h with _, ⟨some c, rfl⟩ := ⟨_, rfl⟩ end } end | none, some b := show (⊤ : with_top α) ≤ b ↔ ∃c:with_top α, ↑b = ⊤ + c, by simp end, .. with_top.order_bot, .. with_top.ordered_add_comm_monoid } end canonically_ordered_monoid /-- A canonically linear-ordered additive monoid is a canonically ordered additive monoid whose ordering is a linear order. -/ @[protect_proj, ancestor canonically_ordered_add_monoid linear_order] class canonically_linear_ordered_add_monoid (α : Type*) extends canonically_ordered_add_monoid α, linear_order α /-- A canonically linear-ordered monoid is a canonically ordered monoid whose ordering is a linear order. -/ @[protect_proj, ancestor canonically_ordered_monoid linear_order, to_additive] class canonically_linear_ordered_monoid (α : Type*) extends canonically_ordered_monoid α, linear_order α section canonically_linear_ordered_monoid variables @[priority 100, to_additive] -- see Note [lower instance priority] instance canonically_linear_ordered_monoid.semilattice_sup_bot [canonically_linear_ordered_monoid α] : semilattice_sup_bot α := { ..lattice_of_linear_order, ..canonically_ordered_monoid.to_order_bot α } instance with_top.canonically_linear_ordered_add_monoid (α : Type*) [canonically_linear_ordered_add_monoid α] : canonically_linear_ordered_add_monoid (with_top α) := { .. (infer_instance : canonically_ordered_add_monoid (with_top α)), .. (infer_instance : linear_order (with_top α)) } @[to_additive] lemma min_mul_distrib [canonically_linear_ordered_monoid α] (a b c : α) : min a (b * c) = min a (min a b * min a c) := begin cases le_total a b with hb hb, { simp [hb, le_mul_right] }, { cases le_total a c with hc hc, { simp [hc, le_mul_left] }, { simp [hb, hc] } } end @[to_additive] lemma min_mul_distrib' [canonically_linear_ordered_monoid α] (a b c : α) : min (a * b) c = min (min a c * min b c) c := by simpa [min_comm _ c] using min_mul_distrib c a b end canonically_linear_ordered_monoid /-- An ordered cancellative additive commutative monoid is an additive commutative monoid with a partial order, in which addition is cancellative and monotone. -/ @[protect_proj, ancestor add_cancel_comm_monoid partial_order] class ordered_cancel_add_comm_monoid (α : Type u) extends add_cancel_comm_monoid α, partial_order α := (add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b) (le_of_add_le_add_left : ∀ a b c : α, a + b ≤ a + c → b ≤ c) /-- An ordered cancellative commutative monoid is a commutative monoid with a partial order, in which multiplication is cancellative and monotone. -/ @[protect_proj, ancestor cancel_comm_monoid partial_order, to_additive] class ordered_cancel_comm_monoid (α : Type u) extends cancel_comm_monoid α, partial_order α := (mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b) (le_of_mul_le_mul_left : ∀ a b c : α, a * b ≤ a * c → b ≤ c) section ordered_cancel_comm_monoid variables [ordered_cancel_comm_monoid α] {a b c d : α} @[to_additive le_of_add_le_add_left] lemma le_of_mul_le_mul_left' : ∀ {a b c : α}, a * b ≤ a * c → b ≤ c := ordered_cancel_comm_monoid.le_of_mul_le_mul_left @[priority 100, to_additive] -- see Note [lower instance priority] instance ordered_cancel_comm_monoid.to_ordered_comm_monoid : ordered_comm_monoid α := { lt_of_mul_lt_mul_left := λ a b c h, lt_of_le_not_le (le_of_mul_le_mul_left' h.le) $ mt (λ h, ordered_cancel_comm_monoid.mul_le_mul_left _ _ h _) (not_le_of_gt h), ..‹ordered_cancel_comm_monoid α› } @[to_additive add_lt_add_left] lemma mul_lt_mul_left' (h : a < b) (c : α) : c * a < c * b := lt_of_le_not_le (mul_le_mul_left' h.le _) $ mt le_of_mul_le_mul_left' (not_le_of_gt h) @[to_additive add_lt_add_right] lemma mul_lt_mul_right' (h : a < b) (c : α) : a * c < b * c := begin rw [mul_comm a c, mul_comm b c], exact (mul_lt_mul_left' h c) end @[to_additive add_lt_add] lemma mul_lt_mul''' (h₁ : a < b) (h₂ : c < d) : a * c < b * d := lt_trans (mul_lt_mul_right' h₁ c) (mul_lt_mul_left' h₂ b) @[to_additive] lemma mul_lt_mul_of_le_of_lt (h₁ : a ≤ b) (h₂ : c < d) : a * c < b * d := lt_of_le_of_lt (mul_le_mul_right' h₁ _) (mul_lt_mul_left' h₂ b) @[to_additive] lemma mul_lt_mul_of_lt_of_le (h₁ : a < b) (h₂ : c ≤ d) : a * c < b * d := lt_of_lt_of_le (mul_lt_mul_right' h₁ c) (mul_le_mul_left' h₂ _) @[to_additive lt_add_of_pos_right] lemma lt_mul_of_one_lt_right' (a : α) {b : α} (h : 1 < b) : a < a * b := have a * 1 < a * b, from mul_lt_mul_left' h a, by rwa [mul_one] at this @[to_additive lt_add_of_pos_left] lemma lt_mul_of_one_lt_left' (a : α) {b : α} (h : 1 < b) : a < b * a := have 1 * a < b * a, from mul_lt_mul_right' h a, by rwa [one_mul] at this @[to_additive le_of_add_le_add_right] lemma le_of_mul_le_mul_right' (h : a * b ≤ c * b) : a ≤ c := le_of_mul_le_mul_left' (show b * a ≤ b * c, begin rw [mul_comm b a, mul_comm b c], assumption end) @[to_additive] lemma mul_lt_one (ha : a < 1) (hb : b < 1) : a * b < 1 := one_mul (1:α) ▸ (mul_lt_mul''' ha hb) @[to_additive] lemma mul_lt_one_of_lt_one_of_le_one (ha : a < 1) (hb : b ≤ 1) : a * b < 1 := one_mul (1:α) ▸ (mul_lt_mul_of_lt_of_le ha hb) @[to_additive] lemma mul_lt_one_of_le_one_of_lt_one (ha : a ≤ 1) (hb : b < 1) : a * b < 1 := one_mul (1:α) ▸ (mul_lt_mul_of_le_of_lt ha hb) @[to_additive] lemma lt_mul_of_one_lt_of_le (ha : 1 < a) (hbc : b ≤ c) : b < a * c := one_mul b ▸ mul_lt_mul_of_lt_of_le ha hbc @[to_additive] lemma lt_mul_of_le_of_one_lt (hbc : b ≤ c) (ha : 1 < a) : b < c * a := mul_one b ▸ mul_lt_mul_of_le_of_lt hbc ha @[to_additive] lemma mul_le_of_le_one_of_le (ha : a ≤ 1) (hbc : b ≤ c) : a * b ≤ c := one_mul c ▸ mul_le_mul' ha hbc @[to_additive] lemma mul_le_of_le_of_le_one (hbc : b ≤ c) (ha : a ≤ 1) : b * a ≤ c := mul_one c ▸ mul_le_mul' hbc ha @[to_additive] lemma mul_lt_of_lt_one_of_le (ha : a < 1) (hbc : b ≤ c) : a * b < c := one_mul c ▸ mul_lt_mul_of_lt_of_le ha hbc @[to_additive] lemma mul_lt_of_le_of_lt_one (hbc : b ≤ c) (ha : a < 1) : b * a < c := mul_one c ▸ mul_lt_mul_of_le_of_lt hbc ha @[to_additive] lemma lt_mul_of_one_le_of_lt (ha : 1 ≤ a) (hbc : b < c) : b < a * c := one_mul b ▸ mul_lt_mul_of_le_of_lt ha hbc @[to_additive] lemma lt_mul_of_lt_of_one_le (hbc : b < c) (ha : 1 ≤ a) : b < c * a := mul_one b ▸ mul_lt_mul_of_lt_of_le hbc ha @[to_additive] lemma lt_mul_of_one_lt_of_lt (ha : 1 < a) (hbc : b < c) : b < a * c := one_mul b ▸ mul_lt_mul''' ha hbc @[to_additive] lemma lt_mul_of_lt_of_one_lt (hbc : b < c) (ha : 1 < a) : b < c * a := mul_one b ▸ mul_lt_mul''' hbc ha @[to_additive] lemma mul_lt_of_le_one_of_lt (ha : a ≤ 1) (hbc : b < c) : a * b < c := one_mul c ▸ mul_lt_mul_of_le_of_lt ha hbc @[to_additive] lemma mul_lt_of_lt_of_le_one (hbc : b < c) (ha : a ≤ 1) : b * a < c := mul_one c ▸ mul_lt_mul_of_lt_of_le hbc ha @[to_additive] lemma mul_lt_of_lt_one_of_lt (ha : a < 1) (hbc : b < c) : a * b < c := one_mul c ▸ mul_lt_mul''' ha hbc @[to_additive] lemma mul_lt_of_lt_of_lt_one (hbc : b < c) (ha : a < 1) : b * a < c := mul_one c ▸ mul_lt_mul''' hbc ha @[simp, to_additive] lemma mul_le_mul_iff_left (a : α) {b c : α} : a * b ≤ a * c ↔ b ≤ c := ⟨le_of_mul_le_mul_left', λ h, mul_le_mul_left' h _⟩ @[simp, to_additive] lemma mul_le_mul_iff_right (c : α) : a * c ≤ b * c ↔ a ≤ b := mul_comm c a ▸ mul_comm c b ▸ mul_le_mul_iff_left c @[simp, to_additive] lemma mul_lt_mul_iff_left (a : α) {b c : α} : a * b < a * c ↔ b < c := ⟨lt_of_mul_lt_mul_left', λ h, mul_lt_mul_left' h _⟩ @[simp, to_additive] lemma mul_lt_mul_iff_right (c : α) : a * c < b * c ↔ a < b := mul_comm c a ▸ mul_comm c b ▸ mul_lt_mul_iff_left c @[simp, to_additive le_add_iff_nonneg_right] lemma le_mul_iff_one_le_right' (a : α) {b : α} : a ≤ a * b ↔ 1 ≤ b := have a * 1 ≤ a * b ↔ 1 ≤ b, from mul_le_mul_iff_left a, by rwa mul_one at this @[simp, to_additive le_add_iff_nonneg_left] lemma le_mul_iff_one_le_left' (a : α) {b : α} : a ≤ b * a ↔ 1 ≤ b := by rw [mul_comm, le_mul_iff_one_le_right'] @[simp, to_additive lt_add_iff_pos_right] lemma lt_mul_iff_one_lt_right' (a : α) {b : α} : a < a * b ↔ 1 < b := have a * 1 < a * b ↔ 1 < b, from mul_lt_mul_iff_left a, by rwa mul_one at this @[simp, to_additive lt_add_iff_pos_left] lemma lt_mul_iff_one_lt_left' (a : α) {b : α} : a < b * a ↔ 1 < b := by rw [mul_comm, lt_mul_iff_one_lt_right'] @[simp, to_additive add_le_iff_nonpos_left] lemma mul_le_iff_le_one_left' : a * b ≤ b ↔ a ≤ 1 := by { convert mul_le_mul_iff_right b, rw [one_mul] } @[simp, to_additive add_le_iff_nonpos_right] lemma mul_le_iff_le_one_right' : a * b ≤ a ↔ b ≤ 1 := by { convert mul_le_mul_iff_left a, rw [mul_one] } @[simp, to_additive add_lt_iff_neg_right] lemma mul_lt_iff_lt_one_right' : a * b < b ↔ a < 1 := by { convert mul_lt_mul_iff_right b, rw [one_mul] } @[simp, to_additive add_lt_iff_neg_left] lemma mul_lt_iff_lt_one_left' : a * b < a ↔ b < 1 := by { convert mul_lt_mul_iff_left a, rw [mul_one] } @[to_additive] lemma mul_eq_one_iff_eq_one_of_one_le (ha : 1 ≤ a) (hb : 1 ≤ b) : a * b = 1 ↔ a = 1 ∧ b = 1 := ⟨λ hab : a * b = 1, by split; apply le_antisymm; try {assumption}; rw ← hab; simp [ha, hb], λ ⟨ha', hb'⟩, by rw [ha', hb', mul_one]⟩ section mono variables {β : Type*} [preorder β] {f g : β → α} @[to_additive monotone.add_strict_mono] lemma monotone.mul_strict_mono' (hf : monotone f) (hg : strict_mono g) : strict_mono (λ x, f x * g x) := λ x y h, mul_lt_mul_of_le_of_lt (hf $ le_of_lt h) (hg h) @[to_additive strict_mono.add_monotone] lemma strict_mono.mul_monotone' (hf : strict_mono f) (hg : monotone g) : strict_mono (λ x, f x * g x) := λ x y h, mul_lt_mul_of_lt_of_le (hf h) (hg $ le_of_lt h) @[to_additive strict_mono.add_const] lemma strict_mono.mul_const' (hf : strict_mono f) (c : α) : strict_mono (λ x, f x * c) := hf.mul_monotone' monotone_const @[to_additive strict_mono.const_add] lemma strict_mono.const_mul' (hf : strict_mono f) (c : α) : strict_mono (λ x, c * f x) := monotone_const.mul_strict_mono' hf end mono end ordered_cancel_comm_monoid section ordered_cancel_add_comm_monoid variable [ordered_cancel_add_comm_monoid α] lemma with_top.add_lt_add_iff_left : ∀{a b c : with_top α}, a < ⊤ → (a + c < a + b ↔ c < b) | none := assume b c h, (lt_irrefl ⊤ h).elim | (some a) := begin assume b c h, cases b; cases c; simp [with_top.none_eq_top, with_top.some_eq_coe, with_top.coe_lt_top, with_top.coe_lt_coe], { norm_cast, exact with_top.coe_lt_top _ }, { norm_cast, exact add_lt_add_iff_left _ } end lemma with_bot.add_lt_add_iff_left : ∀{a b c : with_bot α}, ⊥ < a → (a + c < a + b ↔ c < b) | none := assume b c h, (lt_irrefl ⊥ h).elim | (some a) := begin assume b c h, cases b; cases c; simp [with_bot.none_eq_bot, with_bot.some_eq_coe, with_bot.bot_lt_coe, with_bot.coe_lt_coe], { norm_cast, exact with_bot.bot_lt_coe _ }, { norm_cast, exact add_lt_add_iff_left _ } end local attribute [reducible] with_zero lemma with_top.add_lt_add_iff_right {a b c : with_top α} : a < ⊤ → (c + a < b + a ↔ c < b) := by simpa [add_comm] using @with_top.add_lt_add_iff_left _ _ a b c lemma with_bot.add_lt_add_iff_right {a b c : with_bot α} : ⊥ < a → (c + a < b + a ↔ c < b) := by simpa [add_comm] using @with_bot.add_lt_add_iff_left _ _ a b c end ordered_cancel_add_comm_monoid /-! Some lemmas about types that have an ordering and a binary operation, with no rules relating them. -/ @[to_additive] lemma fn_min_mul_fn_max {β} [linear_order α] [comm_semigroup β] (f : α → β) (n m : α) : f (min n m) * f (max n m) = f n * f m := by { cases le_total n m with h h; simp [h, mul_comm] } @[to_additive] lemma min_mul_max [linear_order α] [comm_semigroup α] (n m : α) : min n m * max n m = n * m := fn_min_mul_fn_max id n m /-- A linearly ordered cancellative additive commutative monoid is an additive commutative monoid with a decidable linear order in which addition is cancellative and monotone. -/ @[protect_proj, ancestor ordered_cancel_add_comm_monoid linear_order] class linear_ordered_cancel_add_comm_monoid (α : Type u) extends ordered_cancel_add_comm_monoid α, linear_order α /-- A linearly ordered cancellative commutative monoid is a commutative monoid with a linear order in which multiplication is cancellative and monotone. -/ @[protect_proj, ancestor ordered_cancel_comm_monoid linear_order, to_additive] class linear_ordered_cancel_comm_monoid (α : Type u) extends ordered_cancel_comm_monoid α, linear_order α section linear_ordered_cancel_comm_monoid variables [linear_ordered_cancel_comm_monoid α] @[to_additive] lemma min_mul_mul_left (a b c : α) : min (a * b) (a * c) = a * min b c := (monotone_id.const_mul' a).map_min.symm @[to_additive] lemma min_mul_mul_right (a b c : α) : min (a * c) (b * c) = min a b * c := (monotone_id.mul_const' c).map_min.symm @[to_additive] lemma max_mul_mul_left (a b c : α) : max (a * b) (a * c) = a * max b c := (monotone_id.const_mul' a).map_max.symm @[to_additive] lemma max_mul_mul_right (a b c : α) : max (a * c) (b * c) = max a b * c := (monotone_id.mul_const' c).map_max.symm @[to_additive] lemma min_le_mul_of_one_le_right {a b : α} (hb : 1 ≤ b) : min a b ≤ a * b := min_le_iff.2 $ or.inl $ le_mul_of_one_le_right' hb @[to_additive] lemma min_le_mul_of_one_le_left {a b : α} (ha : 1 ≤ a) : min a b ≤ a * b := min_le_iff.2 $ or.inr $ le_mul_of_one_le_left' ha @[to_additive] lemma max_le_mul_of_one_le {a b : α} (ha : 1 ≤ a) (hb : 1 ≤ b) : max a b ≤ a * b := max_le_iff.2 ⟨le_mul_of_one_le_right' hb, le_mul_of_one_le_left' ha⟩ end linear_ordered_cancel_comm_monoid namespace order_dual @[to_additive] instance [ordered_comm_monoid α] : ordered_comm_monoid (order_dual α) := { mul_le_mul_left := λ a b h c, @mul_le_mul_left' α _ b a h _, lt_of_mul_lt_mul_left := λ a b c h, @lt_of_mul_lt_mul_left' α _ a c b h, ..order_dual.partial_order α, ..show comm_monoid α, by apply_instance } @[to_additive] instance [ordered_cancel_comm_monoid α] : ordered_cancel_comm_monoid (order_dual α) := { le_of_mul_le_mul_left := λ a b c : α, le_of_mul_le_mul_left', mul_left_cancel := @mul_left_cancel α _, mul_right_cancel := @mul_right_cancel α _, ..order_dual.ordered_comm_monoid } @[to_additive] instance [linear_ordered_cancel_comm_monoid α] : linear_ordered_cancel_comm_monoid (order_dual α) := { .. order_dual.linear_order α, .. order_dual.ordered_cancel_comm_monoid } end order_dual namespace prod variables {M N : Type*} @[to_additive] instance [ordered_cancel_comm_monoid M] [ordered_cancel_comm_monoid N] : ordered_cancel_comm_monoid (M × N) := { mul_le_mul_left := λ a b h c, ⟨mul_le_mul_left' h.1 _, mul_le_mul_left' h.2 _⟩, le_of_mul_le_mul_left := λ a b c h, ⟨le_of_mul_le_mul_left' h.1, le_of_mul_le_mul_left' h.2⟩, .. prod.comm_monoid, .. prod.left_cancel_semigroup, .. prod.right_cancel_semigroup, .. prod.partial_order M N } end prod section type_tags instance : Π [preorder α], preorder (multiplicative α) := id instance : Π [preorder α], preorder (additive α) := id instance : Π [partial_order α], partial_order (multiplicative α) := id instance : Π [partial_order α], partial_order (additive α) := id instance : Π [linear_order α], linear_order (multiplicative α) := id instance : Π [linear_order α], linear_order (additive α) := id instance [ordered_add_comm_monoid α] : ordered_comm_monoid (multiplicative α) := { mul_le_mul_left := @ordered_add_comm_monoid.add_le_add_left α _, lt_of_mul_lt_mul_left := @ordered_add_comm_monoid.lt_of_add_lt_add_left α _, ..multiplicative.partial_order, ..multiplicative.comm_monoid } instance [ordered_comm_monoid α] : ordered_add_comm_monoid (additive α) := { add_le_add_left := @ordered_comm_monoid.mul_le_mul_left α _, lt_of_add_lt_add_left := @ordered_comm_monoid.lt_of_mul_lt_mul_left α _, ..additive.partial_order, ..additive.add_comm_monoid } instance [ordered_cancel_add_comm_monoid α] : ordered_cancel_comm_monoid (multiplicative α) := { le_of_mul_le_mul_left := @ordered_cancel_add_comm_monoid.le_of_add_le_add_left α _, ..multiplicative.right_cancel_semigroup, ..multiplicative.left_cancel_semigroup, ..multiplicative.ordered_comm_monoid } instance [ordered_cancel_comm_monoid α] : ordered_cancel_add_comm_monoid (additive α) := { le_of_add_le_add_left := @ordered_cancel_comm_monoid.le_of_mul_le_mul_left α _, ..additive.add_right_cancel_semigroup, ..additive.add_left_cancel_semigroup, ..additive.ordered_add_comm_monoid } end type_tags
25e7b2a17f52d367adfe1799b60b98bec3a3c8e6
4a092885406df4e441e9bb9065d9405dacb94cd8
/src/valuation/topology.lean
3a05ade7adc9242dabc9edd99a8361216f3ea5c0
[ "Apache-2.0" ]
permissive
semorrison/lean-perfectoid-spaces
78c1572cedbfae9c3e460d8aaf91de38616904d8
bb4311dff45791170bcb1b6a983e2591bee88a19
refs/heads/master
1,588,841,765,494
1,554,805,620,000
1,554,805,620,000
180,353,546
0
1
null
1,554,809,880,000
1,554,809,880,000
null
UTF-8
Lean
false
false
3,086
lean
/- In this file, we define the topology induced by a valuation on a ring valuation.topology {Γ : Type*} [linear_ordered_comm_group Γ] {R : Type*} [ring R] : valuation R Γ → topological_space R -/ import for_mathlib.nonarchimedean.basic import valuation.basic local attribute [instance] classical.prop_decidable noncomputable theory local attribute [instance, priority 0] classical.decidable_linear_order open set valuation with_zero variables {Γ : Type*} [linear_ordered_comm_group Γ] variables {R : Type*} [ring R] (v : valuation R Γ) instance valuation.lt_is_add_subgroup (γ : Γ): is_add_subgroup {x | v x < γ} := { zero_mem := by simp only [valuation.map_zero, mem_set_of_eq] ; apply with_zero.zero_lt_some, add_mem := λ x y x_in y_in, lt_of_le_of_lt (map_add_le_max v x y) (max_lt x_in y_in), neg_mem := λ x x_in, by rwa [mem_set_of_eq, map_neg] } def valuation.ring_with_zero_nhd {R : Type*} [ring R] (v : valuation R Γ) : ring_with_zero_nhd R := of_subgroups (λ γ : Γ, {k | v k < γ}) (begin intros γ₁ γ₂, use min γ₁ γ₂, simp only [set_of_subset_set_of, subset_inter_iff], split ; intros x x_lt ; rw coe_min at x_lt, { apply lt_of_lt_of_le x_lt (min_le_left _ _) }, { apply lt_of_lt_of_le x_lt (min_le_right _ _) } end) (begin intros x γ, by_cases Hx : ∃ γ : Γ, v x = γ, { cases Hx with γx Hx, simp only [Hx, image_subset_iff, set_of_subset_set_of, preimage_set_of_eq, valuation.map_mul], use γx⁻¹*γ, intros y vy_lt, rw ← with_zero.mul_coe at vy_lt, apply actual_ordered_comm_monoid.lt_of_mul_lt_mul_left (γx⁻¹ : with_zero Γ), rwa [← mul_assoc, with_zero.mul_left_inv _ (coe_ne_zero), one_mul, inv_coe] }, { rw [← ne_zero_iff_exists, not_not] at Hx, use 1, intros y y_in, rcases (mem_image _ _ _).1 y_in with ⟨t, t_in, xty⟩, rw ← xty, simp [Hx], exact none_lt_some, } end) (begin intros x γ, simp [image_subset_iff], induction v x using with_zero.cases_on, { simp, use 1, intros _ _, exact zero_lt_some }, { use a⁻¹*γ, intros y vy_lt, rw mul_comm, rw ← with_zero.mul_coe at vy_lt, apply actual_ordered_comm_monoid.lt_of_mul_lt_mul_left (a⁻¹ : with_zero Γ), rwa [← mul_assoc, with_zero.mul_left_inv _ (coe_ne_zero), one_mul, inv_coe] } end) (begin intro γ, by_cases h : γ < 1, { have : (γ*γ : with_zero Γ) < γ, { rw mul_coe, rw some_lt_some, have := linear_ordered_comm_group.mul_lt_right γ h, rwa one_mul at this }, use γ, rintro x ⟨r, r_in, s, s_in, rfl⟩, refine lt_trans _ this, rw valuation.map_mul, exact with_zero.mul_lt_mul r_in s_in}, { rw [not_lt] at h, replace h := some_le_some_of_le h, use 1, rintro x ⟨r, r_in, s, s_in, rfl⟩, refine lt_of_lt_of_le _ h, rw [valuation.map_mul, show (1: Γ) = 1*1, from (mul_one _).symm, ← mul_coe], exact with_zero.mul_lt_mul r_in s_in} end)
824d47c5d43b8dcbc17a369c306a3ade3687f0c5
c9ba4946202cfd1e2586e71960dfed00503dcdf4
/src/meta_k/meta_var.lean
a076f0ae0c74461124b800bbf2cde14c65e44785
[]
no_license
ammkrn/learning_semantics_of_k
f55f669b369e32ef8407c16521b21ac5c106dc4d
c1487b538e1decc0f1fd389cd36bc36d2da012ab
refs/heads/master
1,588,081,593,954
1,552,449,093,000
1,552,449,093,000
175,315,800
0
0
null
null
null
null
UTF-8
Lean
false
false
1,801
lean
import .meta_sort -- ############################################# -- ##### meta_variable ################### @[derive decidable_eq] inductive meta_variable : Type | mk : #String → #Sort → meta_variable instance : inhabited meta_variable := inhabited.mk (meta_variable.mk ("default_#Variable") (%Sort)) notation `#Variable` := meta_variable notation `#variable` := meta_variable.mk notation `#VariableList` := list meta_variable definition meta_variable_get_sort : meta_variable → meta_sort | (meta_variable.mk (str) (s)) := s instance meta_variable.has_sort : has_sort meta_variable meta_sort := ⟨ meta_variable_get_sort ⟩ definition meta_variable_to_string : meta_variable → string | (meta_variable.mk (str) (sort)) := (repr str) ++ " : " ++ (repr (meta_sort_name sort)) definition get_meta_variable_name : meta_variable → string | (meta_variable.mk (str) (sort)) := (repr str) instance : has_name meta_variable := ⟨ get_meta_variable_name ⟩ instance meta_variableiable.is_Variable : is_Variable meta_variable := ⟨ meta_variable_to_string ⟩ -- ########## Coercions/lifts def meta_variable.to_meta_sort : #Variable → #Sort := λ v : #Variable, %Variable instance meta_variable_to_meta_sort_lift : has_lift meta_variable #Sort := ⟨ meta_variable.to_meta_sort ⟩ instance : has_repr meta_variable := has_repr.mk (meta_variable_to_string) def meta_sort.to_meta_variable : #Sort → #Variable | s := #variable (meta_sort_name s) s instance meta_sort_to_meta_variable_lift : has_lift #Sort #Variable := ⟨ meta_sort.to_meta_variable ⟩ def delete_variable_list {V : Type} [is_Variable V] [decidable_eq V]: V → list V → list V | v [] := [] | v (hd :: tl) := if v = hd then delete_variable_list v tl else hd :: (delete_variable_list v tl)
76c7cb014bec8ba6e700816adaf3638ce82f25db
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/analysis/calculus/taylor.lean
f7040ff75e28c8c41a5b9d8a16f1e465f000db3f
[ "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
18,606
lean
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import analysis.calculus.iterated_deriv import analysis.calculus.mean_value import data.polynomial.module /-! # Taylor's theorem > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylor_coeff_within`: the Taylor coefficient using `deriv_within` * `taylor_within`: the Taylor polynomial using `deriv_within` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open_locale big_operators interval topology nat open set variables {𝕜 E F : Type*} variables [normed_add_comm_group E] [normed_space ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylor_coeff_within (f : ℝ → E) (k : ℕ) (s : set ℝ) (x₀ : ℝ) : E := (k! : ℝ)⁻¹ • (iterated_deriv_within k f s x₀) /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylor_within (f : ℝ → E) (n : ℕ) (s : set ℝ) (x₀ : ℝ) : polynomial_module ℝ E := (finset.range (n+1)).sum (λ k, polynomial_module.comp (polynomial.X - polynomial.C x₀) (polynomial_module.single ℝ k (taylor_coeff_within f k s x₀))) /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylor_within_eval (f : ℝ → E) (n : ℕ) (s : set ℝ) (x₀ x : ℝ) : E := polynomial_module.eval x (taylor_within f n s x₀) lemma taylor_within_succ (f : ℝ → E) (n : ℕ) (s : set ℝ) (x₀ : ℝ) : taylor_within f (n+1) s x₀ = taylor_within f n s x₀ + polynomial_module.comp (polynomial.X - polynomial.C x₀) (polynomial_module.single ℝ (n+1) (taylor_coeff_within f (n+1) s x₀)) := begin dunfold taylor_within, rw finset.sum_range_succ, end @[simp] lemma taylor_within_eval_succ (f : ℝ → E) (n : ℕ) (s : set ℝ) (x₀ x : ℝ) : taylor_within_eval f (n+1) s x₀ x = taylor_within_eval f n s x₀ x + (((n + 1 : ℝ) * n!)⁻¹ * (x - x₀)^(n+1)) • iterated_deriv_within (n + 1) f s x₀ := begin simp_rw [taylor_within_eval, taylor_within_succ, linear_map.map_add, polynomial_module.comp_eval], congr, simp only [polynomial.eval_sub, polynomial.eval_X, polynomial.eval_C, polynomial_module.eval_single, mul_inv_rev], dunfold taylor_coeff_within, rw [←mul_smul, mul_comm, nat.factorial_succ, nat.cast_mul, nat.cast_add, nat.cast_one, mul_inv_rev], end /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] lemma taylor_within_zero_eval (f : ℝ → E) (s : set ℝ) (x₀ x : ℝ) : taylor_within_eval f 0 s x₀ x = f x₀ := begin dunfold taylor_within_eval, dunfold taylor_within, dunfold taylor_coeff_within, simp, end /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] lemma taylor_within_eval_self (f : ℝ → E) (n : ℕ) (s : set ℝ) (x₀ : ℝ) : taylor_within_eval f n s x₀ x₀ = f x₀ := begin induction n with k hk, { exact taylor_within_zero_eval _ _ _ _}, simp [hk] end lemma taylor_within_apply (f : ℝ → E) (n : ℕ) (s : set ℝ) (x₀ x : ℝ) : taylor_within_eval f n s x₀ x = ∑ k in finset.range (n+1), ((k! : ℝ)⁻¹ * (x - x₀)^k) • iterated_deriv_within k f s x₀ := begin induction n with k hk, { simp }, rw [taylor_within_eval_succ, finset.sum_range_succ, hk], simp, end /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylor_within_eval f n s x₀ x` is continuous in `x₀`. -/ lemma continuous_on_taylor_within_eval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : set ℝ} (hs : unique_diff_on ℝ s) (hf : cont_diff_on ℝ n f s) : continuous_on (λ t, taylor_within_eval f n s t x) s := begin simp_rw taylor_within_apply, refine continuous_on_finset_sum (finset.range (n+1)) (λ i hi, _), refine (continuous_on_const.mul ((continuous_on_const.sub continuous_on_id).pow _)).smul _, rw cont_diff_on_iff_continuous_on_differentiable_on_deriv hs at hf, cases hf, specialize hf_left i, simp only [finset.mem_range] at hi, refine (hf_left _), simp only [with_top.coe_le_coe], exact nat.lt_succ_iff.mp hi, end /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ lemma monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : has_deriv_at (λ y, (x - y)^(n+1)) (-(n+1) * (x - t)^n) t := begin simp_rw sub_eq_neg_add, rw [←neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ←mul_assoc], convert @has_deriv_at.pow _ _ _ _ _ (n+1) ((has_deriv_at_id t).neg.add_const x), simp only [nat.cast_add, nat.cast_one], end lemma has_deriv_within_at_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : set ℝ} (ht : unique_diff_within_at ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : differentiable_within_at ℝ (iterated_deriv_within (k+1) f s) s y) : has_deriv_within_at (λ z, (((k+1 : ℝ) * k!)⁻¹ * (x - z)^(k+1)) • iterated_deriv_within (k+1) f s z) ((((k+1 : ℝ) * k!)⁻¹ * (x - y)^(k+1)) • iterated_deriv_within (k+2) f s y - ((k! : ℝ)⁻¹ * (x - y)^k) • iterated_deriv_within (k+1) f s y) t y := begin replace hf : has_deriv_within_at (iterated_deriv_within (k+1) f s) (iterated_deriv_within (k+2) f s y) t y := begin convert (hf.mono_of_mem hs).has_deriv_within_at, rw iterated_deriv_within_succ (ht.mono_nhds (nhds_within_le_iff.mpr hs)), exact (deriv_within_of_mem hs ht hf).symm end, have : has_deriv_within_at (λ t, (((k+1 : ℝ) * k!)⁻¹ * (x - t)^(k+1))) (-((k! : ℝ)⁻¹ * (x - y)^k)) t y, { -- Commuting the factors: have : (-((k! : ℝ)⁻¹ * (x - y)^k)) = (((k+1 : ℝ) * k!)⁻¹ * (-(k+1) *(x - y)^k)), { field_simp [nat.cast_add_one_ne_zero k, nat.factorial_ne_zero k], ring_nf }, rw this, exact (monomial_has_deriv_aux y x _).has_deriv_within_at.const_mul _ }, convert this.smul hf, field_simp [nat.cast_add_one_ne_zero k, nat.factorial_ne_zero k], rw [neg_div, neg_smul, sub_eq_add_neg], end /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ lemma has_deriv_within_at_taylor_within_eval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : set ℝ} (hs'_unique : unique_diff_within_at ℝ s' y) (hs_unique : unique_diff_on ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : cont_diff_on ℝ n f s) (hf' : differentiable_within_at ℝ (iterated_deriv_within n f s) s y) : has_deriv_within_at (λ t, taylor_within_eval f n s t x) (((n! : ℝ)⁻¹ * (x - y)^n) • (iterated_deriv_within (n+1) f s y)) s' y := begin induction n with k hk, { simp only [taylor_within_zero_eval, nat.factorial_zero, nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul], simp only [iterated_deriv_within_zero] at hf', rw iterated_deriv_within_one (hs_unique _ (h hy)), exact hf'.has_deriv_within_at.mono h }, simp_rw [nat.add_succ, taylor_within_eval_succ], simp only [add_zero, nat.factorial_succ, nat.cast_mul, nat.cast_add, nat.cast_one], have hdiff : differentiable_on ℝ (iterated_deriv_within k f s) s', { have coe_lt_succ : (k : with_top ℕ) < k.succ := nat.cast_lt.2 k.lt_succ_self, refine differentiable_on.mono _ h, exact hf.differentiable_on_iterated_deriv_within coe_lt_succ hs_unique }, specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs'), convert hk.add (has_deriv_within_at_taylor_coeff_within hs'_unique (nhds_within_mono _ h self_mem_nhds_within) hf'), exact (add_sub_cancel'_right _ _).symm end /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ lemma taylor_within_eval_has_deriv_at_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : cont_diff_on ℝ n f (Icc a b)) (hf' : differentiable_on ℝ (iterated_deriv_within n f (Icc a b)) (Ioo a b)) : has_deriv_at (λ y, taylor_within_eval f n (Icc a b) y x) (((n! : ℝ)⁻¹ * (x - t)^n) • (iterated_deriv_within (n+1) f (Icc a b) t)) t := have h_nhds : Ioo a b ∈ 𝓝 t := is_open_Ioo.mem_nhds ht, have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhds_within_le_nhds h_nhds, (has_deriv_within_at_taylor_within_eval (unique_diff_within_at_Ioo ht) (unique_diff_on_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf $ (hf' t ht).mono_of_mem h_nhds').has_deriv_at h_nhds /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ lemma has_deriv_within_taylor_within_eval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : cont_diff_on ℝ n f (Icc a b)) (hf' : differentiable_on ℝ (iterated_deriv_within n f (Icc a b)) (Icc a b)) : has_deriv_within_at (λ y, taylor_within_eval f n (Icc a b) y x) (((n! : ℝ)⁻¹ * (x - t)^n) • (iterated_deriv_within (n+1) f (Icc a b) t)) (Icc a b) t := has_deriv_within_at_taylor_within_eval (unique_diff_on_Icc hx t ht) (unique_diff_on_Icc hx) self_mem_nhds_within ht rfl.subset hf (hf' t ht) /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists a `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ lemma taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : cont_diff_on ℝ n f (Icc x₀ x)) (hf' : differentiable_on ℝ (iterated_deriv_within n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : continuous_on g (Icc x₀ x)) (gdiff : ∀ (x_1 : ℝ), x_1 ∈ Ioo x₀ x → has_deriv_at g (g' x_1) x_1) (g'_ne : ∀ (x_1 : ℝ), x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ (x' : ℝ) (hx' : x' ∈ Ioo x₀ x), f x - taylor_within_eval f n (Icc x₀ x) x₀ x = ((x - x')^n /n! * (g x - g x₀) / g' x') • (iterated_deriv_within (n+1) f (Icc x₀ x) x') := begin -- We apply the mean value theorem rcases exists_ratio_has_deriv_at_eq_ratio_slope (λ t, taylor_within_eval f n (Icc x₀ x) t x) (λ t, ((n! : ℝ)⁻¹ * (x - t)^n) • (iterated_deriv_within (n+1) f (Icc x₀ x) t)) hx (continuous_on_taylor_within_eval (unique_diff_on_Icc hx) hf) (λ _ hy, taylor_within_eval_has_deriv_at_Ioo x hx hy hf hf') g g' gcont gdiff with ⟨y, hy, h⟩, use [y, hy], -- The rest is simplifications and trivial calculations simp only [taylor_within_eval_self] at h, rw [mul_comm, ←div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h, rw ←h, field_simp [g'_ne y hy, n.factorial_ne_zero], ring, end /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists a `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ lemma taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : cont_diff_on ℝ n f (Icc x₀ x)) (hf' : differentiable_on ℝ (iterated_deriv_within n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ (x' : ℝ) (hx' : x' ∈ Ioo x₀ x), f x - taylor_within_eval f n (Icc x₀ x) x₀ x = (iterated_deriv_within (n+1) f (Icc x₀ x) x') * (x - x₀)^(n+1) /(n+1)! := begin have gcont : continuous_on (λ (t : ℝ), (x - t) ^ (n + 1)) (Icc x₀ x) := by { refine continuous.continuous_on _, continuity }, have xy_ne : ∀ (y : ℝ), y ∈ Ioo x₀ x → (x - y)^n ≠ 0 := begin intros y hy, refine pow_ne_zero _ _, rw [mem_Ioo] at hy, rw sub_ne_zero, exact hy.2.ne.symm, end, have hg' : ∀ (y : ℝ), y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := λ y hy, mul_ne_zero (neg_ne_zero.mpr (nat.cast_add_one_ne_zero n)) (xy_ne y hy), -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (λ y _, monomial_has_deriv_aux y x _) hg' with ⟨y, hy, h⟩, use [y, hy], simp only [sub_self, zero_pow', ne.def, nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h, rw [h, neg_div, ←div_neg, neg_mul, neg_neg], field_simp [n.cast_add_one_ne_zero, n.factorial_ne_zero, xy_ne y hy], ring, end /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists a `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ lemma taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : cont_diff_on ℝ n f (Icc x₀ x)) (hf' : differentiable_on ℝ (iterated_deriv_within n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ (x' : ℝ) (hx' : x' ∈ Ioo x₀ x), f x - taylor_within_eval f n (Icc x₀ x) x₀ x = (iterated_deriv_within (n+1) f (Icc x₀ x) x') * (x - x')^n /n! * (x - x₀) := begin have gcont : continuous_on id (Icc x₀ x) := continuous.continuous_on (by continuity), have gdiff : (∀ (x_1 : ℝ), x_1 ∈ Ioo x₀ x → has_deriv_at id ((λ (t : ℝ), (1 : ℝ)) x_1) x_1) := λ _ _, has_deriv_at_id _, -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff (λ _ _, by simp) with ⟨y, hy, h⟩, use [y, hy], rw h, field_simp [n.factorial_ne_zero], ring, end /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ lemma taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≤ b) (hf : cont_diff_on ℝ (n+1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iterated_deriv_within (n + 1) f (Icc a b) y‖ ≤ C) : ‖f x - taylor_within_eval f n (Icc a b) a x‖ ≤ C * (x - a)^(n+1) / n! := begin rcases eq_or_lt_of_le hab with rfl|h, { rw [Icc_self, mem_singleton_iff] at hx, simp [hx] }, -- The nth iterated derivative is differentiable have hf' : differentiable_on ℝ (iterated_deriv_within n f (Icc a b)) (Icc a b) := hf.differentiable_on_iterated_deriv_within (with_top.coe_lt_coe.mpr n.lt_succ_self) (unique_diff_on_Icc h), -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ (y : ℝ) (hy : y ∈ Ico a x), ‖((n! : ℝ)⁻¹ * (x - y) ^ n) • iterated_deriv_within (n + 1) f (Icc a b) y‖ ≤ (n! : ℝ)⁻¹ * |(x - a)|^n * C, { rintro y ⟨hay, hyx⟩, rw [norm_smul, real.norm_eq_abs], -- Estimate the iterated derivative by `C` refine mul_le_mul _ (hC y ⟨hay, hyx.le.trans hx.2⟩) (by positivity) (by positivity), -- The rest is a trivial calculation rw [abs_mul, abs_pow, abs_inv, nat.abs_cast], mono* with [0 ≤ (n! : ℝ)⁻¹], any_goals { positivity }, linarith [hx.1, hyx] }, -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, has_deriv_within_at (λ y, taylor_within_eval f n (Icc a b) y x) (((↑n!)⁻¹ * (x - t) ^ n) • iterated_deriv_within (n + 1) f (Icc a b) t) (Icc a x) t, { assume t ht, have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2, exact (has_deriv_within_taylor_within_eval_at_Icc x h (I ht) hf.of_succ hf').mono I }, have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1), simp only [taylor_within_eval_self] at this, refine this.trans_eq _, -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)], ring_exp, end /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ lemma exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≤ b) (hf : cont_diff_on ℝ (n+1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylor_within_eval f n (Icc a b) a x‖ ≤ C * (x - a)^(n+1) := begin rcases eq_or_lt_of_le hab with rfl|h, { refine ⟨0, λ x hx, _⟩, have : a = x, by simpa [← le_antisymm_iff] using hx, simp [← this] }, -- We estimate by the supremum of the norm of the iterated derivative let g : ℝ → ℝ := λ y, ‖iterated_deriv_within (n + 1) f (Icc a b) y‖, use [has_Sup.Sup (g '' Icc a b) / n!], intros x hx, rw div_mul_eq_mul_div₀, refine taylor_mean_remainder_bound hab hf hx (λ y, _), exact (hf.continuous_on_iterated_deriv_within rfl.le $ unique_diff_on_Icc h) .norm.le_Sup_image_Icc, end
e0b23c88714ad0b4b11d5bc5efaae8cacf9ad78e
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/src/Init/Lean/Compiler/IR/EmitC.lean
b73803fbb31c3ed0f27d81d30351e4c6036bdea2
[ "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
24,506
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 -/ prelude import Init.Control.Conditional import Init.Lean.Runtime import Init.Lean.Compiler.NameMangling import Init.Lean.Compiler.ExportAttr import Init.Lean.Compiler.InitAttr import Init.Lean.Compiler.IR.CompilerM import Init.Lean.Compiler.IR.EmitUtil import Init.Lean.Compiler.IR.NormIds import Init.Lean.Compiler.IR.SimpCase import Init.Lean.Compiler.IR.Boxing namespace Lean namespace IR open ExplicitBoxing (requiresBoxedVersion mkBoxedName isBoxedName) namespace EmitC def leanMainFn := "_lean_main" structure Context := (env : Environment) (modName : Name) (jpMap : JPParamsMap := {}) (mainFn : FunId := arbitrary _) (mainParams : Array Param := #[]) abbrev M := ReaderT Context (EStateM String String) def getEnv : M Environment := Context.env <$> read def getModName : M Name := Context.modName <$> read def getDecl (n : Name) : M Decl := do env ← getEnv; match findEnvDecl env n with | some d => pure d | none => throw ("unknown declaration '" ++ toString n ++ "'") @[inline] def emit {α : Type} [HasToString α] (a : α) : M Unit := modify (fun out => out ++ toString a) @[inline] def emitLn {α : Type} [HasToString α] (a : α) : M Unit := emit a *> emit "\n" def emitLns {α : Type} [HasToString α] (as : List α) : M Unit := as.forM $ fun a => emitLn a def argToCString (x : Arg) : String := match x with | Arg.var x => toString x | _ => "lean_box(0)" def emitArg (x : Arg) : M Unit := emit (argToCString x) def toCType : IRType → String | IRType.float => "double" | IRType.uint8 => "uint8_t" | IRType.uint16 => "uint16_t" | IRType.uint32 => "uint32_t" | IRType.uint64 => "uint64_t" | IRType.usize => "size_t" | IRType.object => "lean_object*" | IRType.tobject => "lean_object*" | IRType.irrelevant => "lean_object*" | IRType.struct _ _ => panic! "not implemented yet" | IRType.union _ _ => panic! "not implemented yet" def throwInvalidExportName {α : Type} (n : Name) : M α := throw ("invalid export name '" ++ toString n ++ "'") def toCName (n : Name) : M String := do env ← getEnv; -- TODO: we should support simple export names only match getExportNameFor env n with | some (Name.str Name.anonymous s _) => pure s | some _ => throwInvalidExportName n | none => if n == `main then pure leanMainFn else pure n.mangle def emitCName (n : Name) : M Unit := toCName n >>= emit def toCInitName (n : Name) : M String := do env ← getEnv; -- TODO: we should support simple export names only match getExportNameFor env n with | some (Name.str Name.anonymous s _) => pure $ "_init_" ++ s | some _ => throwInvalidExportName n | none => pure ("_init_" ++ n.mangle) def emitCInitName (n : Name) : M Unit := toCInitName n >>= emit def emitFnDeclAux (decl : Decl) (cppBaseName : String) (addExternForConsts : Bool) : M Unit := do let ps := decl.params; env ← getEnv; when (ps.isEmpty && addExternForConsts) (emit "extern "); emit (toCType decl.resultType ++ " " ++ cppBaseName); unless (ps.isEmpty) $ do { emit "("; -- We omit irrelevant parameters for extern constants let ps := if isExternC env decl.name then ps.filter (fun p => !p.ty.isIrrelevant) else ps; if ps.size > closureMaxArgs && isBoxedName decl.name then emit "lean_object**" else ps.size.forM $ fun i => do { when (i > 0) (emit ", "); emit (toCType (ps.get! i).ty) }; emit ")" }; emitLn ";" def emitFnDecl (decl : Decl) (addExternForConsts : Bool) : M Unit := do cppBaseName ← toCName decl.name; emitFnDeclAux decl cppBaseName addExternForConsts def emitExternDeclAux (decl : Decl) (cNameStr : String) : M Unit := do let cName := mkNameSimple cNameStr; env ← getEnv; let extC := isExternC env decl.name; emitFnDeclAux decl cNameStr (!extC) def emitFnDecls : M Unit := do env ← getEnv; let decls := getDecls env; let modDecls : NameSet := decls.foldl (fun s d => s.insert d.name) {}; let usedDecls : NameSet := decls.foldl (fun s d => collectUsedDecls env d (s.insert d.name)) {}; let usedDecls := usedDecls.toList; usedDecls.forM $ fun n => do decl ← getDecl n; match getExternNameFor env `c decl.name with | some cName => emitExternDeclAux decl cName | none => emitFnDecl decl (!modDecls.contains n) def emitMainFn : M Unit := do d ← getDecl `main; match d with | Decl.fdecl f xs t b => do unless (xs.size == 2 || xs.size == 1) (throw "invalid main function, incorrect arity when generating code"); env ← getEnv; let usesLeanAPI := usesModuleFrom env `Init.Lean; if usesLeanAPI then emitLn "void lean_initialize();" else emitLn "void lean_initialize_runtime_module();"; emitLn "int main(int argc, char ** argv) {\nlean_object* in; lean_object* res;"; if usesLeanAPI then emitLn "lean_initialize();" else emitLn "lean_initialize_runtime_module();"; modName ← getModName; emitLn ("res = initialize_" ++ (modName.mangle "") ++ "(lean_io_mk_world());"); emitLns ["lean_io_mark_end_initialization();", "if (lean_io_result_is_ok(res)) {", "lean_dec_ref(res);", "lean_init_task_manager();"]; if xs.size == 2 then do { emitLns ["in = lean_box(0);", "int i = argc;", "while (i > 1) {", " lean_object* n;", " i--;", " n = lean_alloc_ctor(1,2,0); lean_ctor_set(n, 0, lean_mk_string(argv[i])); lean_ctor_set(n, 1, in);", " in = n;", "}"]; emitLn ("res = " ++ leanMainFn ++ "(in, lean_io_mk_world());") } else do { emitLn ("res = " ++ leanMainFn ++ "(lean_io_mk_world());") }; emitLn "}"; emitLns ["if (lean_io_result_is_ok(res)) {", " int ret = lean_unbox(lean_io_result_get_value(res));", " lean_dec_ref(res);", " return ret;", "} else {", " lean_io_result_show_error(res);", " lean_dec_ref(res);", " return 1;", "}"]; emitLn "}" | other => throw "function declaration expected" def hasMainFn : M Bool := do env ← getEnv; let decls := getDecls env; pure $ decls.any (fun d => d.name == `main) def emitMainFnIfNeeded : M Unit := whenM hasMainFn emitMainFn def emitFileHeader : M Unit := do env ← getEnv; modName ← getModName; emitLn "// Lean compiler output"; emitLn ("// Module: " ++ toString modName); emit "// Imports:"; env.imports.forM $ fun m => emit (" " ++ toString m); emitLn ""; emitLn "#include \"runtime/lean.h\""; emitLns [ "#if defined(__clang__)", "#pragma clang diagnostic ignored \"-Wunused-parameter\"", "#pragma clang diagnostic ignored \"-Wunused-label\"", "#elif defined(__GNUC__) && !defined(__CLANG__)", "#pragma GCC diagnostic ignored \"-Wunused-parameter\"", "#pragma GCC diagnostic ignored \"-Wunused-label\"", "#pragma GCC diagnostic ignored \"-Wunused-but-set-variable\"", "#endif", "#ifdef __cplusplus", "extern \"C\" {", "#endif" ] def emitFileFooter : M Unit := emitLns [ "#ifdef __cplusplus", "}", "#endif" ] def throwUnknownVar {α : Type} (x : VarId) : M α := throw ("unknown variable '" ++ toString x ++ "'") def getJPParams (j : JoinPointId) : M (Array Param) := do ctx ← read; match ctx.jpMap.find? j with | some ps => pure ps | none => throw "unknown join point" def declareVar (x : VarId) (t : IRType) : M Unit := do emit (toCType t); emit " "; emit x; emit "; " def declareParams (ps : Array Param) : M Unit := ps.forM $ fun p => declareVar p.x p.ty partial def declareVars : FnBody → Bool → M Bool | e@(FnBody.vdecl x t _ b), d => do ctx ← read; if isTailCallTo ctx.mainFn e then pure d else declareVar x t *> declareVars b true | FnBody.jdecl j xs _ b, d => declareParams xs *> declareVars b (d || xs.size > 0) | e, d => if e.isTerminal then pure d else declareVars e.body d def emitTag (x : VarId) (xType : IRType) : M Unit := do if xType.isObj then do emit "lean_obj_tag("; emit x; emit ")" else emit x def isIf (alts : Array Alt) : Option (Nat × FnBody × FnBody) := if alts.size != 2 then none else match alts.get! 0 with | Alt.ctor c b => some (c.cidx, b, (alts.get! 1).body) | _ => none def emitIf (emitBody : FnBody → M Unit) (x : VarId) (xType : IRType) (tag : Nat) (t : FnBody) (e : FnBody) : M Unit := do emit "if ("; emitTag x xType; emit " == "; emit tag; emitLn ")"; emitBody t; emitLn "else"; emitBody e def emitCase (emitBody : FnBody → M Unit) (x : VarId) (xType : IRType) (alts : Array Alt) : M Unit := match isIf alts with | some (tag, t, e) => emitIf emitBody x xType tag t e | _ => do emit "switch ("; emitTag x xType; emitLn ") {"; let alts := ensureHasDefault alts; alts.forM $ fun alt => match alt with | Alt.ctor c b => emit "case " *> emit c.cidx *> emitLn ":" *> emitBody b | Alt.default b => emitLn "default: " *> emitBody b; emitLn "}" def emitInc (x : VarId) (n : Nat) (checkRef : Bool) : M Unit := do emit $ if checkRef then (if n == 1 then "lean_inc" else "lean_inc_n") else (if n == 1 then "lean_inc_ref" else "lean_inc_ref_n"); emit "(" *> emit x; when (n != 1) (emit ", " *> emit n); emitLn ");" def emitDec (x : VarId) (n : Nat) (checkRef : Bool) : M Unit := do emit (if checkRef then "lean_dec" else "lean_dec_ref"); emit "("; emit x; when (n != 1) (do emit ", "; emit n); emitLn ");" def emitDel (x : VarId) : M Unit := do emit "lean_free_object("; emit x; emitLn ");" def emitSetTag (x : VarId) (i : Nat) : M Unit := do emit "lean_ctor_set_tag("; emit x; emit ", "; emit i; emitLn ");" def emitSet (x : VarId) (i : Nat) (y : Arg) : M Unit := do emit "lean_ctor_set("; emit x; emit ", "; emit i; emit ", "; emitArg y; emitLn ");" def emitOffset (n : Nat) (offset : Nat) : M Unit := if n > 0 then do emit "sizeof(void*)*"; emit n; when (offset > 0) (emit " + " *> emit offset) else emit offset def emitUSet (x : VarId) (n : Nat) (y : VarId) : M Unit := do emit "lean_ctor_set_usize("; emit x; emit ", "; emit n; emit ", "; emit y; emitLn ");" def emitSSet (x : VarId) (n : Nat) (offset : Nat) (y : VarId) (t : IRType) : M Unit := do match t with | IRType.float => throw "floats are not supported yet" | IRType.uint8 => emit "lean_ctor_set_uint8" | IRType.uint16 => emit "lean_ctor_set_uint16" | IRType.uint32 => emit "lean_ctor_set_uint32" | IRType.uint64 => emit "lean_ctor_set_uint64" | _ => throw "invalid instruction"; emit "("; emit x; emit ", "; emitOffset n offset; emit ", "; emit y; emitLn ");" def emitJmp (j : JoinPointId) (xs : Array Arg) : M Unit := do ps ← getJPParams j; unless (xs.size == ps.size) (throw "invalid goto"); xs.size.forM $ fun i => do { let p := ps.get! i; let x := xs.get! i; emit p.x; emit " = "; emitArg x; emitLn ";" }; emit "goto "; emit j; emitLn ";" def emitLhs (z : VarId) : M Unit := do emit z; emit " = " def emitArgs (ys : Array Arg) : M Unit := ys.size.forM $ fun i => do when (i > 0) (emit ", "); emitArg (ys.get! i) def emitCtorScalarSize (usize : Nat) (ssize : Nat) : M Unit := if usize == 0 then emit ssize else if ssize == 0 then emit "sizeof(size_t)*" *> emit usize else emit "sizeof(size_t)*" *> emit usize *> emit " + " *> emit ssize def emitAllocCtor (c : CtorInfo) : M Unit := do emit "lean_alloc_ctor("; emit c.cidx; emit ", "; emit c.size; emit ", "; emitCtorScalarSize c.usize c.ssize; emitLn ");" def emitCtorSetArgs (z : VarId) (ys : Array Arg) : M Unit := ys.size.forM $ fun i => do emit "lean_ctor_set("; emit z; emit ", "; emit i; emit ", "; emitArg (ys.get! i); emitLn ");" def emitCtor (z : VarId) (c : CtorInfo) (ys : Array Arg) : M Unit := do emitLhs z; if c.size == 0 && c.usize == 0 && c.ssize == 0 then do emit "lean_box("; emit c.cidx; emitLn ");" else do emitAllocCtor c; emitCtorSetArgs z ys def emitReset (z : VarId) (n : Nat) (x : VarId) : M Unit := do emit "if (lean_is_exclusive("; emit x; emitLn ")) {"; n.forM $ fun i => do { emit " lean_ctor_release("; emit x; emit ", "; emit i; emitLn ");" }; emit " "; emitLhs z; emit x; emitLn ";"; emitLn "} else {"; emit " lean_dec_ref("; emit x; emitLn ");"; emit " "; emitLhs z; emitLn "lean_box(0);"; emitLn "}" def emitReuse (z : VarId) (x : VarId) (c : CtorInfo) (updtHeader : Bool) (ys : Array Arg) : M Unit := do emit "if (lean_is_scalar("; emit x; emitLn ")) {"; emit " "; emitLhs z; emitAllocCtor c; emitLn "} else {"; emit " "; emitLhs z; emit x; emitLn ";"; when updtHeader (do emit " lean_ctor_set_tag("; emit z; emit ", "; emit c.cidx; emitLn ");"); emitLn "}"; emitCtorSetArgs z ys def emitProj (z : VarId) (i : Nat) (x : VarId) : M Unit := do emitLhs z; emit "lean_ctor_get("; emit x; emit ", "; emit i; emitLn ");" def emitUProj (z : VarId) (i : Nat) (x : VarId) : M Unit := do emitLhs z; emit "lean_ctor_get_usize("; emit x; emit ", "; emit i; emitLn ");" def emitSProj (z : VarId) (t : IRType) (n offset : Nat) (x : VarId) : M Unit := do emitLhs z; match t with | IRType.float => throw "floats are not supported yet" | IRType.uint8 => emit "lean_ctor_get_uint8" | IRType.uint16 => emit "lean_ctor_get_uint16" | IRType.uint32 => emit "lean_ctor_get_uint32" | IRType.uint64 => emit "lean_ctor_get_uint64" | _ => throw "invalid instruction"; emit "("; emit x; emit ", "; emitOffset n offset; emitLn ");" def toStringArgs (ys : Array Arg) : List String := ys.toList.map argToCString def emitSimpleExternalCall (f : String) (ps : Array Param) (ys : Array Arg) : M Unit := do emit f; emit "("; -- We must remove irrelevant arguments to extern calls. ys.size.foldM (fun i (first : Bool) => if (ps.get! i).ty.isIrrelevant then pure first else do unless first (emit ", "); emitArg (ys.get! i); pure false) true; emitLn ");"; pure () def emitExternCall (f : FunId) (ps : Array Param) (extData : ExternAttrData) (ys : Array Arg) : M Unit := match getExternEntryFor extData `c with | some (ExternEntry.standard _ extFn) => emitSimpleExternalCall extFn ps ys | some (ExternEntry.inline _ pat) => do emit (expandExternPattern pat (toStringArgs ys)); emitLn ";" | some (ExternEntry.foreign _ extFn) => emitSimpleExternalCall extFn ps ys | _ => throw ("failed to emit extern application '" ++ toString f ++ "'") def emitFullApp (z : VarId) (f : FunId) (ys : Array Arg) : M Unit := do emitLhs z; decl ← getDecl f; match decl with | Decl.extern _ ps _ extData => emitExternCall f ps extData ys | _ => do emitCName f; when (ys.size > 0) (do emit "("; emitArgs ys; emit ")"); emitLn ";" def emitPartialApp (z : VarId) (f : FunId) (ys : Array Arg) : M Unit := do decl ← getDecl f; let arity := decl.params.size; emitLhs z; emit "lean_alloc_closure((void*)("; emitCName f; emit "), "; emit arity; emit ", "; emit ys.size; emitLn ");"; ys.size.forM $ fun i => do { let y := ys.get! i; emit "lean_closure_set("; emit z; emit ", "; emit i; emit ", "; emitArg y; emitLn ");" } def emitApp (z : VarId) (f : VarId) (ys : Array Arg) : M Unit := if ys.size > closureMaxArgs then do emit "{ lean_object* _aargs[] = {"; emitArgs ys; emitLn "};"; emitLhs z; emit "lean_apply_m("; emit f; emit ", "; emit ys.size; emitLn ", _aargs); }" else do emitLhs z; emit "lean_apply_"; emit ys.size; emit "("; emit f; emit ", "; emitArgs ys; emitLn ");" def emitBoxFn (xType : IRType) : M Unit := match xType with | IRType.usize => emit "lean_box_usize" | IRType.uint32 => emit "lean_box_uint32" | IRType.uint64 => emit "lean_box_uint64" | IRType.float => throw "floats are not supported yet" | other => emit "lean_box" def emitBox (z : VarId) (x : VarId) (xType : IRType) : M Unit := do emitLhs z; emitBoxFn xType; emit "("; emit x; emitLn ");" def emitUnbox (z : VarId) (t : IRType) (x : VarId) : M Unit := do emitLhs z; match t with | IRType.usize => emit "lean_unbox_usize" | IRType.uint32 => emit "lean_unbox_uint32" | IRType.uint64 => emit "lean_unbox_uint64" | IRType.float => throw "floats are not supported yet" | other => emit "lean_unbox"; emit "("; emit x; emitLn ");" def emitIsShared (z : VarId) (x : VarId) : M Unit := do emitLhs z; emit "!lean_is_exclusive("; emit x; emitLn ");" def emitIsTaggedPtr (z : VarId) (x : VarId) : M Unit := do emitLhs z; emit "!lean_is_scalar("; emit x; emitLn ");" def toHexDigit (c : Nat) : String := String.singleton c.digitChar def quoteString (s : String) : String := let q := "\""; let q := s.foldl (fun q c => q ++ if c == '\n' then "\\n" else if c == '\n' then "\\t" else if c == '\\' then "\\\\" else if c == '\"' then "\\\"" else if c.toNat <= 31 then "\\x" ++ toHexDigit (c.toNat / 16) ++ toHexDigit (c.toNat % 16) -- TODO(Leo): we should use `\unnnn` for escaping unicode characters. else String.singleton c) q; q ++ "\"" def emitNumLit (t : IRType) (v : Nat) : M Unit := if t.isObj then do if v < uint32Sz then emit "lean_unsigned_to_nat(" *> emit v *> emit "u)" else emit "lean_cstr_to_nat(\"" *> emit v *> emit "\")" else emit v def emitLit (z : VarId) (t : IRType) (v : LitVal) : M Unit := emitLhs z *> match v with | LitVal.num v => emitNumLit t v *> emitLn ";" | LitVal.str v => do emit "lean_mk_string("; emit (quoteString v); emitLn ");" def emitVDecl (z : VarId) (t : IRType) (v : Expr) : M Unit := match v with | Expr.ctor c ys => emitCtor z c ys | Expr.reset n x => emitReset z n x | Expr.reuse x c u ys => emitReuse z x c u ys | Expr.proj i x => emitProj z i x | Expr.uproj i x => emitUProj z i x | Expr.sproj n o x => emitSProj z t n o x | Expr.fap c ys => emitFullApp z c ys | Expr.pap c ys => emitPartialApp z c ys | Expr.ap x ys => emitApp z x ys | Expr.box t x => emitBox z x t | Expr.unbox x => emitUnbox z t x | Expr.isShared x => emitIsShared z x | Expr.isTaggedPtr x => emitIsTaggedPtr z x | Expr.lit v => emitLit z t v def isTailCall (x : VarId) (v : Expr) (b : FnBody) : M Bool := do ctx ← read; match v, b with | Expr.fap f _, FnBody.ret (Arg.var y) => pure $ f == ctx.mainFn && x == y | _, _ => pure false def paramEqArg (p : Param) (x : Arg) : Bool := match x with | Arg.var x => p.x == x | _ => false /- Given `[p_0, ..., p_{n-1}]`, `[y_0, ..., y_{n-1}]`, representing the assignments ``` p_0 := y_0, ... p_{n-1} := y_{n-1} ``` Return true iff we have `(i, j)` where `j > i`, and `y_j == p_i`. That is, we have ``` p_i := y_i, ... p_j := p_i, -- p_i was overwritten above ``` -/ def overwriteParam (ps : Array Param) (ys : Array Arg) : Bool := let n := ps.size; n.any $ fun i => let p := ps.get! i; (i+1, n).anyI $ fun j => paramEqArg p (ys.get! j) def emitTailCall (v : Expr) : M Unit := match v with | Expr.fap _ ys => do ctx ← read; let ps := ctx.mainParams; unless (ps.size == ys.size) (throw "invalid tail call"); if overwriteParam ps ys then do { emitLn "{"; ps.size.forM $ fun i => do { let p := ps.get! i; let y := ys.get! i; unless (paramEqArg p y) $ do { emit (toCType p.ty); emit " _tmp_"; emit i; emit " = "; emitArg y; emitLn ";" } }; ps.size.forM $ fun i => do { let p := ps.get! i; let y := ys.get! i; unless (paramEqArg p y) (do emit p.x; emit " = _tmp_"; emit i; emitLn ";") }; emitLn "}" } else do { ys.size.forM $ fun i => do { let p := ps.get! i; let y := ys.get! i; unless (paramEqArg p y) (do emit p.x; emit " = "; emitArg y; emitLn ";") } }; emitLn "goto _start;" | _ => throw "bug at emitTailCall" partial def emitBlock (emitBody : FnBody → M Unit) : FnBody → M Unit | FnBody.jdecl j xs v b => emitBlock b | d@(FnBody.vdecl x t v b) => do ctx ← read; if isTailCallTo ctx.mainFn d then emitTailCall v else emitVDecl x t v *> emitBlock b | FnBody.inc x n c p b => unless p (emitInc x n c) *> emitBlock b | FnBody.dec x n c p b => unless p (emitDec x n c) *> emitBlock b | FnBody.del x b => emitDel x *> emitBlock b | FnBody.setTag x i b => emitSetTag x i *> emitBlock b | FnBody.set x i y b => emitSet x i y *> emitBlock b | FnBody.uset x i y b => emitUSet x i y *> emitBlock b | FnBody.sset x i o y t b => emitSSet x i o y t *> emitBlock b | FnBody.mdata _ b => emitBlock b | FnBody.ret x => emit "return " *> emitArg x *> emitLn ";" | FnBody.case _ x xType alts => emitCase emitBody x xType alts | FnBody.jmp j xs => emitJmp j xs | FnBody.unreachable => emitLn "lean_panic_unreachable();" partial def emitJPs (emitBody : FnBody → M Unit) : FnBody → M Unit | FnBody.jdecl j xs v b => do emit j; emitLn ":"; emitBody v; emitJPs b | e => unless e.isTerminal (emitJPs e.body) partial def emitFnBody : FnBody → M Unit | b => do emitLn "{"; declared ← declareVars b false; when declared (emitLn ""); emitBlock emitFnBody b; emitJPs emitFnBody b; emitLn "}" def emitDeclAux (d : Decl) : M Unit := do env ← getEnv; let (vMap, jpMap) := mkVarJPMaps d; adaptReader (fun (ctx : Context) => { jpMap := jpMap, .. ctx }) $ do unless (hasInitAttr env d.name) $ match d with | Decl.fdecl f xs t b => do baseName ← toCName f; emit (toCType t); emit " "; if xs.size > 0 then do { emit baseName; emit "("; if xs.size > closureMaxArgs && isBoxedName d.name then emit "lean_object** _args" else xs.size.forM $ fun i => do { when (i > 0) (emit ", "); let x := xs.get! i; emit (toCType x.ty); emit " "; emit x.x }; emit ")" } else do { emit ("_init_" ++ baseName ++ "()") }; emitLn " {"; when (xs.size > closureMaxArgs && isBoxedName d.name) $ xs.size.forM $ fun i => do { let x := xs.get! i; emit "lean_object* "; emit x.x; emit " = _args["; emit i; emitLn "];" }; emitLn "_start:"; adaptReader (fun (ctx : Context) => { mainFn := f, mainParams := xs, .. ctx }) (emitFnBody b); emitLn "}" | _ => pure () def emitDecl (d : Decl) : M Unit := let d := d.normalizeIds; -- ensure we don't have gaps in the variable indices catch (emitDeclAux d) (fun err => throw (err ++ "\ncompiling:\n" ++ toString d)) def emitFns : M Unit := do env ← getEnv; let decls := getDecls env; decls.reverse.forM emitDecl def emitMarkPersistent (d : Decl) (n : Name) : M Unit := when d.resultType.isObj $ do { emit "lean_mark_persistent("; emitCName n; emitLn ");" } def emitDeclInit (d : Decl) : M Unit := do env ← getEnv; let n := d.name; if isIOUnitInitFn env n then do { emit "res = "; emitCName n; emitLn "(lean_io_mk_world());"; emitLn "if (lean_io_result_is_error(res)) return res;"; emitLn "lean_dec_ref(res);" } else when (d.params.size == 0) $ match getInitFnNameFor env d.name with | some initFn => do { emit "res = "; emitCName initFn; emitLn "(lean_io_mk_world());"; emitLn "if (lean_io_result_is_error(res)) return res;"; emitCName n; emitLn " = lean_io_result_get_value(res);"; emitMarkPersistent d n; emitLn "lean_dec_ref(res);" } | _ => do { emitCName n; emit " = "; emitCInitName n; emitLn "();"; emitMarkPersistent d n } def emitInitFn : M Unit := do env ← getEnv; modName ← getModName; env.imports.forM $ fun imp => emitLn ("lean_object* initialize_" ++ imp.module.mangle "" ++ "(lean_object*);"); emitLns [ "static bool _G_initialized = false;", "lean_object* initialize_" ++ modName.mangle "" ++ "(lean_object* w) {", "lean_object * res;", "if (_G_initialized) return lean_mk_io_result(lean_box(0));", "_G_initialized = true;" ]; env.imports.forM $ fun imp => emitLns [ "res = initialize_" ++ imp.module.mangle "" ++ "(lean_io_mk_world());", "if (lean_io_result_is_error(res)) return res;", "lean_dec_ref(res);"]; let decls := getDecls env; decls.reverse.forM emitDeclInit; emitLns ["return lean_mk_io_result(lean_box(0));", "}"] def main : M Unit := do emitFileHeader; emitFnDecls; emitFns; emitInitFn; emitMainFnIfNeeded; emitFileFooter end EmitC @[export lean_ir_emit_c] def emitC (env : Environment) (modName : Name) : Except String String := match (EmitC.main { env := env, modName := modName }).run "" with | EStateM.Result.ok _ s => Except.ok s | EStateM.Result.error err _ => Except.error err end IR end Lean
7e3aa214a28bc3d4d40ccdb46e7c3a3571193370
ad3e8f15221a986da27c99f371922c0b3f5792b6
/src/week05/e01_matroids.lean
925b7493516acd4035ef265e8fbf2ec6a83f94e2
[]
no_license
VArtem/lean-itmo
a0e1424c8cc4c2de2ac85ab6fd4a12d80e9b85f1
dc44cd06f9f5b984d051831b3aaa7364e64c2dc4
refs/heads/main
1,683,761,214,467
1,622,821,295,000
1,622,821,295,000
357,236,048
12
0
null
null
null
null
UTF-8
Lean
false
false
8,048
lean
import data.finset import data.fintype.basic import tactic import week05.solutions.e00_intro open finset structure matroid (α : Type*) [fintype α] [decidable_eq α] := (ind : set (finset α)) (ind_empty : ind ∅) (ind_subset : ∀ ⦃A B⦄, A ⊆ B → ind B → ind A) (ind_exchange : ∀ (A B : finset α), ind A → ind B → A.card < B.card → (∃ (c ∈ B), (c ∉ A) ∧ ind (insert c A))) namespace matroid attribute [simp] matroid.ind_empty variables {α : Type} [fintype α] [decidable_eq α] {A B X : finset α} {m : matroid α} -- Попробуйте доказать в term mode lemma dep_superset {A B} : A ⊆ B → ¬m.ind A → ¬m.ind B := sorry -- Базой множества A называется независимое множество B, что B ⊆ A, и для любого x ∈ A \ B, B ∪ {x} зависимо -- x ∈ A \ B - неудобное определение, потому что везде придется переписывать mem_sdiff -- Аналогично, для вставки x в B есть `insert x B` def base_of (m : matroid α) (X A : finset α) := A ⊆ X ∧ m.ind A ∧ ∀ x ∈ X, x ∉ A → ¬m.ind (insert x A) lemma base_of_ind : m.base_of X A → m.ind A := λ h, h.2.1 lemma base_of_subset : m.base_of X A → A ⊆ X := λ h, h.1 lemma base_of_dep_of_insert {x} : m.base_of X A → x ∈ X → x ∉ A → ¬m.ind (insert x A) := λ h hX hA, h.2.2 x hX hA -- База матроида - аналогично, но без ограничения на подмножество def base (m : matroid α) (B : finset α) := m.ind B ∧ ∀ x ∉ B, ¬m.ind (insert x B) lemma base_ind : m.base A → m.ind A := λ h, h.1 @[simp] lemma base_of_univ_iff_base {A : finset α} : m.base_of univ A ↔ m.base A := sorry -- Секция с доказательствами про `base_of` section base_of -- A независимо тогда и только тогда, когда A - база A lemma ind_iff_base_of_self : m.ind A ↔ m.base_of A A := begin sorry, end -- Все базы множества равномощны -- Вспомните/подумайте про математическое доказательство от противного -- Тактика `wlog` поможет сократить количество случаев, когда весь контекст симметричен относительно `A и B` lemma base_of_card_eq (hA : m.base_of X A) (hB : m.base_of X B) : A.card = B.card := begin by_contradiction hne, wlog h : A.card < B.card := lt_or_gt_of_ne hne using [A B, B A], sorry, end -- Любое независимое подмножество X можно достроить до базы X -- `by_contradiction` доказывает цель от противного -- `push_neg` проталкивает отрицания максимально внутрь утверждения или цели -- Также может помочь `nat.le_induction` #check @nat.le_induction lemma exists_base_of_superset_of_ind : A ⊆ X → m.ind A → ∃ B, A ⊆ B ∧ m.base_of X B := begin intros hAX hA, by_contradiction, push_neg at h, suffices ind_unbounded : ∀ k ≥ A.card, ∃ B, A ⊆ B ∧ B ⊆ X ∧ m.ind B ∧ B.card = k, { sorry, }, apply nat.le_induction, { sorry, }, { sorry, } end -- У каждого подмножества X существует база theorem exists_base_of (m : matroid α) (X : finset α): ∃ A, m.base_of X A := begin sorry, end -- Мощность независимого подмножества A ⊆ X не больше мощности базы X lemma ind_card_le_base_of_card : A ⊆ X → m.ind A → m.base_of X B → A.card ≤ B.card := begin sorry, end end base_of -- Теорема о базах матроида section base lemma base_eq_card (hA : m.base A) (hB : m.base B) : A.card = B.card := sorry lemma ind_subset_base (hA : m.ind A) : ∃ B, A ⊆ B ∧ m.base B := begin sorry, end theorem exists_base : ∃ A, m.base A := begin sorry, end theorem base_not_subset {A B} : m.base A → m.base B → A ⊆ B → A = B := begin sorry, end lemma ind_and_card_eq_card_base_iff_base {A B} (Abase : m.base A) : (m.ind B ∧ A.card = B.card) ↔ m.base B := begin sorry, end -- Почитайте про тактику `finish`: https://leanprover-community.github.io/mathlib_docs/tactics.html#finish%20/%20clarify%20/%20safe theorem base_exchange {A B} : m.base A → m.base B → ∀ x ∈ A \ B, ∃ b ∈ (B \ A), m.base (insert b (A.erase x)) := begin sorry, end end base -- Цикл матроида это минимальное по включению зависимое множество def circuit (m : matroid α) (A : finset α) := ¬ m.ind A ∧ ∀ x ∈ A, m.ind (A.erase x) section circuit theorem not_circuit : ¬ m.circuit ∅ := λ ⟨empty_dep, _⟩, empty_dep m.ind_empty lemma circuit_ssubset : m.circuit A → B ⊂ A → m.ind B := begin sorry, end theorem circuit_not_subset {A B} : m.circuit A → m.circuit B → A ⊆ B → A = B := begin sorry, end -- Чтобы доказать эту лемму от противного, нужно доказать утверждение вида -- "Если A зависимо и у него нет подмножеств-циклов, -- то для всех k от 0 до |A| существует зависимое множество размера k" -- Для этого я рекомендую использовать индукцию по убыванию k -- В mathlib это nat.decreasing_induction lemma ind_iff_no_circuit_subset (A) : m.ind A ↔ ∀ C ⊆ A, ¬m.circuit C := begin split, { sorry, }, { intros h, by_contradiction Aind, suffices subsets_dep : ∀ k ≤ A.card, ∃ B ⊆ A, B.card = k ∧ ¬ m.ind B, { sorry, }, intros k k_le_card, refine nat.decreasing_induction _ k_le_card _, { sorry, }, { sorry, } } end lemma dep_iff_contains_circuit (A) : ¬ m.ind A ↔ ∃ C ⊆ A, m.circuit C := begin sorry, end end circuit -- Есть несколько способов определить ранговую функцию в матроиде -- Я выбрал следующий: возьмем все независимые подмножества A и возьмем максимальную мощность среди них -- Для такого определения нужно, чтобы проверка на независимость в матроиде была разрешимой variable [decidable_pred m.ind] def rank (m : matroid α) [decidable_pred m.ind] (A : finset α) : ℕ := sup (filter m.ind (powerset A)) card section rank @[simp] lemma rank_def : rank m A = sup (filter m.ind (powerset A)) card := rfl @[simp] lemma rank_empty : rank m ∅ = 0 := begin sorry, end -- Если B - база A, то ранг А равен мощности B -- Леммы про `sup` здесь полезны: `finset.sup_le` и `le_sup` lemma rank_eq_base_of_card (Bbase : m.base_of A B) : rank m A = B.card := begin sorry, end lemma rank_exists_base_of (m : matroid α) [decidable_pred m.ind] (A : finset α) : ∃ (B : finset α), m.rank A = B.card ∧ m.base_of A B := begin sorry, end theorem rank_le_card : rank m A ≤ A.card := begin sorry, end @[simp] lemma rank_le_of_subset (hAB : A ⊆ B) : rank m A ≤ rank m B := begin sorry, end @[simp] lemma rank_ind : rank m A = A.card ↔ m.ind A := begin sorry, end -- Сложный финальный босс! -- http://neerc.ifmo.ru/wiki/index.php?title=%D0%A0%D0%B0%D0%BD%D0%B3%D0%BE%D0%B2%D0%B0%D1%8F_%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F,_%D0%BF%D0%BE%D0%BB%D1%83%D0%BC%D0%BE%D0%B4%D1%83%D0%BB%D1%8F%D1%80%D0%BD%D0%BE%D1%81%D1%82%D1%8C theorem rank_submodular : m.rank (A ∩ B) + m.rank (A ∪ B) ≤ m.rank A + m.rank B := begin sorry, end end rank end matroid
f73c9a69441964bc53360eb06473ac7f9a947a28
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/ring_theory/witt_vector/verschiebung.lean
d4062f4d140d29fea189259ed8ea606c16dc063e
[ "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
5,950
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 ring_theory.witt_vector.basic import ring_theory.witt_vector.is_poly /-! ## The Verschiebung operator ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ namespace witt_vector open mv_polynomial variables {p : ℕ} {R S : Type*} [hp : fact p.prime] [comm_ring R] [comm_ring S] local notation `𝕎` := witt_vector p -- type as `\bbW` noncomputable theory /-- `verschiebung_fun x` shifts the coefficients of `x` up by one, by inserting 0 as the 0th coefficient. `x.coeff i` then becomes `(verchiebung_fun x).coeff (i + 1)`. `verschiebung_fun` is the underlying function of the additive monoid hom `witt_vector.verschiebung`. -/ def verschiebung_fun (x : 𝕎 R) : 𝕎 R := mk p $ λ n, if n = 0 then 0 else x.coeff (n - 1) lemma verschiebung_fun_coeff (x : 𝕎 R) (n : ℕ) : (verschiebung_fun x).coeff n = if n = 0 then 0 else x.coeff (n - 1) := by rw [verschiebung_fun, coeff_mk] lemma verschiebung_fun_coeff_zero (x : 𝕎 R) : (verschiebung_fun x).coeff 0 = 0 := by rw [verschiebung_fun_coeff, if_pos rfl] @[simp] lemma verschiebung_fun_coeff_succ (x : 𝕎 R) (n : ℕ) : (verschiebung_fun x).coeff n.succ = x.coeff n := rfl include hp @[ghost_simps] lemma ghost_component_zero_verschiebung_fun (x : 𝕎 R) : ghost_component 0 (verschiebung_fun x) = 0 := by rw [ghost_component_apply, aeval_witt_polynomial, finset.range_one, finset.sum_singleton, verschiebung_fun_coeff_zero, pow_zero, pow_zero, pow_one, one_mul] @[ghost_simps] lemma ghost_component_verschiebung_fun (x : 𝕎 R) (n : ℕ) : ghost_component (n + 1) (verschiebung_fun x) = p * ghost_component n x := begin simp only [ghost_component_apply, aeval_witt_polynomial], rw [finset.sum_range_succ', verschiebung_fun_coeff, if_pos rfl, zero_pow (pow_pos hp.1.pos _), mul_zero, add_zero, finset.mul_sum, finset.sum_congr rfl], rintro i -, simp only [pow_succ, mul_assoc, verschiebung_fun_coeff, if_neg (nat.succ_ne_zero i), nat.succ_sub_succ, tsub_zero] end omit hp /-- The 0th Verschiebung polynomial is 0. For `n > 0`, the `n`th Verschiebung polynomial is the variable `X (n-1)`. -/ def verschiebung_poly (n : ℕ) : mv_polynomial ℕ ℤ := if n = 0 then 0 else X (n-1) @[simp] lemma verschiebung_poly_zero : verschiebung_poly 0 = 0 := rfl lemma aeval_verschiebung_poly' (x : 𝕎 R) (n : ℕ) : aeval x.coeff (verschiebung_poly n) = (verschiebung_fun x).coeff n := begin cases n, { simp only [verschiebung_poly, verschiebung_fun_coeff_zero, if_pos rfl, alg_hom.map_zero] }, { rw [verschiebung_poly, verschiebung_fun_coeff_succ, if_neg (n.succ_ne_zero), aeval_X, nat.succ_eq_add_one, add_tsub_cancel_right] } end variable (p) /-- `witt_vector.verschiebung` has polynomial structure given by `witt_vector.verschiebung_poly`. -/ @[is_poly] lemma verschiebung_fun_is_poly : is_poly p (λ R _Rcr, @verschiebung_fun p R _Rcr) := begin use verschiebung_poly, simp only [aeval_verschiebung_poly', eq_self_iff_true, forall_3_true_iff] end variable {p} include hp /-- `verschiebung x` shifts the coefficients of `x` up by one, by inserting 0 as the 0th coefficient. `x.coeff i` then becomes `(verchiebung x).coeff (i + 1)`. This is a additive monoid hom with underlying function `verschiebung_fun`. -/ noncomputable def verschiebung : 𝕎 R →+ 𝕎 R := { to_fun := verschiebung_fun, map_zero' := by ext ⟨⟩; rw [verschiebung_fun_coeff]; simp only [if_true, eq_self_iff_true, zero_coeff, if_t_t], map_add' := by { ghost_calc _ _, rintro ⟨⟩; ghost_simp } } omit hp /-- `witt_vector.verschiebung` is a polynomial function. -/ @[is_poly] lemma verschiebung_is_poly : is_poly p (λ R _Rcr, @verschiebung p R hp _Rcr) := verschiebung_fun_is_poly p include hp /-- verschiebung is a natural transformation -/ @[simp] lemma map_verschiebung (f : R →+* S) (x : 𝕎 R) : map f (verschiebung x) = verschiebung (map f x) := by { ext ⟨-, -⟩, exact f.map_zero, refl } @[ghost_simps] lemma ghost_component_zero_verschiebung (x : 𝕎 R) : ghost_component 0 (verschiebung x) = 0 := ghost_component_zero_verschiebung_fun _ @[ghost_simps] lemma ghost_component_verschiebung (x : 𝕎 R) (n : ℕ) : ghost_component (n + 1) (verschiebung x) = p * ghost_component n x := ghost_component_verschiebung_fun _ _ @[simp] lemma verschiebung_coeff_zero (x : 𝕎 R) : (verschiebung x).coeff 0 = 0 := rfl -- simp_nf complains if this is simp lemma verschiebung_coeff_add_one (x : 𝕎 R) (n : ℕ) : (verschiebung x).coeff (n + 1) = x.coeff n := rfl @[simp] lemma verschiebung_coeff_succ (x : 𝕎 R) (n : ℕ) : (verschiebung x).coeff n.succ = x.coeff n := rfl lemma aeval_verschiebung_poly (x : 𝕎 R) (n : ℕ) : aeval x.coeff (verschiebung_poly n) = (verschiebung x).coeff n := aeval_verschiebung_poly' x n @[simp] lemma bind₁_verschiebung_poly_witt_polynomial (n : ℕ) : bind₁ verschiebung_poly (witt_polynomial p ℤ n) = if n = 0 then 0 else p * witt_polynomial p ℤ (n-1) := begin apply mv_polynomial.funext, intro x, split_ifs with hn, { simp only [hn, verschiebung_poly_zero, witt_polynomial_zero, bind₁_X_right] }, { obtain ⟨n, rfl⟩ := nat.exists_eq_succ_of_ne_zero hn, rw [nat.succ_eq_add_one, add_tsub_cancel_right, ring_hom.map_mul, ring_hom.map_nat_cast, hom_bind₁], calc _ = ghost_component (n + 1) (verschiebung $ mk p x) : _ ... = _ : _, { apply eval₂_hom_congr (ring_hom.ext_int _ _) _ rfl, simp only [←aeval_verschiebung_poly, coeff_mk], funext k, exact eval₂_hom_congr (ring_hom.ext_int _ _) rfl rfl }, { rw [ghost_component_verschiebung], congr' 1, exact eval₂_hom_congr (ring_hom.ext_int _ _) rfl rfl } } end end witt_vector
9fb57e48d9eaa856924b9b32b5a0abe28d9da5a8
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
/library/standard/data/bool.lean
9ed4ceeaeb634ae5d56ae946519a21a0c0538a07
[ "Apache-2.0" ]
permissive
codyroux/lean
7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3
0cca265db19f7296531e339192e9b9bae4a31f8b
refs/heads/master
1,610,909,964,159
1,407,084,399,000
1,416,857,075,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
4,589
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 ---------------------------------------------------------------------------------------------------- import logic.connectives.basic logic.classes.decidable logic.classes.inhabited using eq_proofs decidable namespace bool inductive bool : Type := | ff : bool | tt : bool theorem induction_on {p : bool → Prop} (b : bool) (H0 : p ff) (H1 : p tt) : p b := bool_rec H0 H1 b theorem inhabited_bool [instance] : inhabited bool := inhabited_intro ff definition cond {A : Type} (b : bool) (t e : A) := bool_rec e t b theorem dichotomy (b : bool) : b = ff ∨ b = tt := induction_on b (or_inl (refl ff)) (or_inr (refl tt)) theorem cond_ff {A : Type} (t e : A) : cond ff t e = e := refl (cond ff t e) theorem cond_tt {A : Type} (t e : A) : cond tt t e = t := refl (cond tt t e) theorem ff_ne_tt : ¬ ff = tt := assume H : ff = tt, absurd (calc true = cond tt true false : (cond_tt _ _)⁻¹ ... = cond ff true false : {H⁻¹} ... = false : cond_ff _ _) true_ne_false theorem decidable_eq [instance] (a b : bool) : decidable (a = b) := bool_rec (bool_rec (inl (refl ff)) (inr ff_ne_tt) b) (bool_rec (inr (ne_symm ff_ne_tt)) (inl (refl tt)) b) a definition bor (a b : bool) := bool_rec (bool_rec ff tt b) tt a theorem bor_tt_left (a : bool) : bor tt a = tt := refl (bor tt a) infixl `||`:65 := bor theorem bor_tt_right (a : bool) : a || tt = tt := induction_on a (refl (ff || tt)) (refl (tt || tt)) theorem bor_ff_left (a : bool) : ff || a = a := induction_on a (refl (ff || ff)) (refl (ff || tt)) theorem bor_ff_right (a : bool) : a || ff = a := induction_on a (refl (ff || ff)) (refl (tt || ff)) theorem bor_id (a : bool) : a || a = a := induction_on a (refl (ff || ff)) (refl (tt || tt)) theorem bor_comm (a b : bool) : a || b = b || a := induction_on a (induction_on b (refl (ff || ff)) (refl (ff || tt))) (induction_on b (refl (tt || ff)) (refl (tt || tt))) theorem bor_assoc (a b c : bool) : (a || b) || c = a || (b || c) := induction_on a (calc (ff || b) || c = b || c : {bor_ff_left b} ... = ff || (b || c) : bor_ff_left (b || c)⁻¹) (calc (tt || b) || c = tt || c : {bor_tt_left b} ... = tt : bor_tt_left c ... = tt || (b || c) : bor_tt_left (b || c)⁻¹) theorem bor_to_or {a b : bool} : a || b = tt → a = tt ∨ b = tt := bool_rec (assume H : ff || b = tt, have Hb : b = tt, from (bor_ff_left b) ▸ H, or_inr Hb) (assume H, or_inl (refl tt)) a definition band (a b : bool) := bool_rec ff (bool_rec ff tt b) a infixl `&&`:75 := band theorem band_ff_left (a : bool) : ff && a = ff := refl (ff && a) theorem band_tt_left (a : bool) : tt && a = a := induction_on a (refl (tt && ff)) (refl (tt && tt)) theorem band_ff_right (a : bool) : a && ff = ff := induction_on a (refl (ff && ff)) (refl (tt && ff)) theorem band_tt_right (a : bool) : a && tt = a := induction_on a (refl (ff && tt)) (refl (tt && tt)) theorem band_id (a : bool) : a && a = a := induction_on a (refl (ff && ff)) (refl (tt && tt)) theorem band_comm (a b : bool) : a && b = b && a := induction_on a (induction_on b (refl (ff && ff)) (refl (ff && tt))) (induction_on b (refl (tt && ff)) (refl (tt && tt))) theorem band_assoc (a b c : bool) : (a && b) && c = a && (b && c) := induction_on a (calc (ff && b) && c = ff && c : {band_ff_left b} ... = ff : band_ff_left c ... = ff && (b && c) : band_ff_left (b && c)⁻¹) (calc (tt && b) && c = b && c : {band_tt_left b} ... = tt && (b && c) : band_tt_left (b && c)⁻¹) theorem band_eq_tt_elim_left {a b : bool} (H : a && b = tt) : a = tt := or_elim (dichotomy a) (assume H0 : a = ff, absurd_elim (a = tt) (calc ff = ff && b : (band_ff_left _)⁻¹ ... = a && b : {H0⁻¹} ... = tt : H) ff_ne_tt) (assume H1 : a = tt, H1) theorem band_eq_tt_elim_right {a b : bool} (H : a && b = tt) : b = tt := band_eq_tt_elim_left (trans (band_comm b a) H) definition bnot (a : bool) := bool_rec tt ff a prefix `!`:85 := bnot theorem bnot_bnot (a : bool) : !!a = a := induction_on a (refl (!!ff)) (refl (!!tt)) theorem bnot_false : !ff = tt := refl _ theorem bnot_true : !tt = ff := refl _ end
ebaf842d6a735fab6c819d9bfe7eae02a116fa75
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/analysis/box_integral/box/subbox_induction.lean
c1925670044133e245a44f6e11c602a2651d6354
[ "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
7,996
lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import analysis.box_integral.box.basic import analysis.specific_limits /-! # Induction on subboxes In this file we prove the following induction principle for `box_integral.box`, see `box_integral.box.subbox_induction_on`. Let `p` be a predicate on `box_integral.box ι`, let `I` be a box. Suppose that the following two properties hold true. * Consider a smaller box `J ≤ I`. The hyperplanes passing through the center of `J` split it into `2 ^ n` boxes. If `p` holds true on each of these boxes, then it is true on `J`. * For each `z` in the closed box `I.Icc` there exists a neighborhood `U` of `z` within `I.Icc` such that for every box `J ≤ I` such that `z ∈ J.Icc ⊆ U`, if `J` is homothetic to `I` with a coefficient of the form `1 / 2 ^ m`, then `p` is true on `J`. Then `p I` is true. ## Tags rectangular box, induction -/ open set finset function filter metric open_locale classical topological_space filter ennreal noncomputable theory namespace box_integral namespace box variables {ι : Type*} {I J : box ι} /-- For a box `I`, the hyperplanes passing through its center split `I` into `2 ^ card ι` boxes. `box_integral.box.split_center_box I s` is one of these boxes. See also `box_integral.partition.split_center` for the corresponding `box_integral.partition`. -/ def split_center_box (I : box ι) (s : set ι) : box ι := { lower := s.piecewise (λ i, (I.lower i + I.upper i) / 2) I.lower, upper := s.piecewise I.upper (λ i, (I.lower i + I.upper i) / 2), lower_lt_upper := λ i, by { dunfold set.piecewise, split_ifs; simp only [left_lt_add_div_two, add_div_two_lt_right, I.lower_lt_upper] } } lemma mem_split_center_box {s : set ι} {y : ι → ℝ} : y ∈ I.split_center_box s ↔ y ∈ I ∧ ∀ i, (I.lower i + I.upper i) / 2 < y i ↔ i ∈ s := begin simp only [split_center_box, mem_def, ← forall_and_distrib], refine forall_congr (λ i, _), dunfold set.piecewise, split_ifs with hs; simp only [hs, iff_true, iff_false, not_lt], exacts [⟨λ H, ⟨⟨(left_lt_add_div_two.2 (I.lower_lt_upper i)).trans H.1, H.2⟩, H.1⟩, λ H, ⟨H.2, H.1.2⟩⟩, ⟨λ H, ⟨⟨H.1, H.2.trans (add_div_two_lt_right.2 (I.lower_lt_upper i)).le⟩, H.2⟩, λ H, ⟨H.1.1, H.2⟩⟩] end lemma split_center_box_le (I : box ι) (s : set ι) : I.split_center_box s ≤ I := λ x hx, (mem_split_center_box.1 hx).1 lemma disjoint_split_center_box (I : box ι) {s t : set ι} (h : s ≠ t) : disjoint (I.split_center_box s : set (ι → ℝ)) (I.split_center_box t) := begin rintro y ⟨hs, ht⟩, apply h, ext i, rw [mem_coe, mem_split_center_box] at hs ht, rw [← hs.2, ← ht.2] end lemma injective_split_center_box (I : box ι) : injective I.split_center_box := λ s t H, by_contra $ λ Hne, (I.disjoint_split_center_box Hne).ne (nonempty_coe _).ne_empty (H ▸ rfl) @[simp] lemma exists_mem_split_center_box {I : box ι} {x : ι → ℝ} : (∃ s, x ∈ I.split_center_box s) ↔ x ∈ I := ⟨λ ⟨s, hs⟩, I.split_center_box_le s hs, λ hx, ⟨{i | (I.lower i + I.upper i) / 2 < x i}, mem_split_center_box.2 ⟨hx, λ i, iff.rfl⟩⟩⟩ /-- `box_integral.box.split_center_box` bundled as a `function.embedding`. -/ @[simps] def split_center_box_emb (I : box ι) : set ι ↪ box ι := ⟨split_center_box I, injective_split_center_box I⟩ @[simp] lemma Union_coe_split_center_box (I : box ι) : (⋃ s, (I.split_center_box s : set (ι → ℝ))) = I := by { ext x, simp } @[simp] lemma upper_sub_lower_split_center_box (I : box ι) (s : set ι) (i : ι) : (I.split_center_box s).upper i - (I.split_center_box s).lower i = (I.upper i - I.lower i) / 2 := by by_cases hs : i ∈ s; field_simp [split_center_box, hs, mul_two, two_mul] /-- Let `p` be a predicate on `box ι`, let `I` be a box. Suppose that the following two properties hold true. * `H_ind` : Consider a smaller box `J ≤ I`. The hyperplanes passing through the center of `J` split it into `2 ^ n` boxes. If `p` holds true on each of these boxes, then it true on `J`. * `H_nhds` : For each `z` in the closed box `I.Icc` there exists a neighborhood `U` of `z` within `I.Icc` such that for every box `J ≤ I` such that `z ∈ J.Icc ⊆ U`, if `J` is homothetic to `I` with a coefficient of the form `1 / 2 ^ m`, then `p` is true on `J`. Then `p I` is true. See also `box_integral.box.subbox_induction_on` for a version using `box_integral.prepartition.split_center` instead of `box_integral.box.split_center_box`. The proof still works if we assume `H_ind` only for subboxes `J ≤ I` that are homothetic to `I` with a coefficient of the form `2⁻ᵐ` but we do not need this generalization yet. -/ @[elab_as_eliminator] lemma subbox_induction_on' {p : box ι → Prop} (I : box ι) (H_ind : ∀ J ≤ I, (∀ s, p (split_center_box J s)) → p J) (H_nhds : ∀ z ∈ I.Icc, ∃ (U ∈ 𝓝[I.Icc] z), ∀ (J ≤ I) (m : ℕ), z ∈ J.Icc → J.Icc ⊆ U → (∀ i, J.upper i - J.lower i = (I.upper i - I.lower i) / 2 ^ m) → p J) : p I := begin by_contra hpI, -- First we use `H_ind` to construct a decreasing sequence of boxes such that `∀ m, ¬p (J m)`. replace H_ind := λ J hJ, not_imp_not.2 (H_ind J hJ), simp only [exists_imp_distrib, not_forall] at H_ind, choose! s hs using H_ind, set J : ℕ → box ι := λ m, (λ J, split_center_box J (s J))^[m] I, have J_succ : ∀ m, J (m + 1) = split_center_box (J m) (s $ J m) := λ m, iterate_succ_apply' _ _ _, -- Now we prove some properties of `J` have hJmono : antitone J, from antitone_nat_of_succ_le (λ n, by simpa [J_succ] using split_center_box_le _ _), have hJle : ∀ m, J m ≤ I, from λ m, hJmono (zero_le m), have hJp : ∀ m, ¬p (J m), from λ m, nat.rec_on m hpI (λ m, by simpa only [J_succ] using hs (J m) (hJle m)), have hJsub : ∀ m i, (J m).upper i - (J m).lower i = (I.upper i - I.lower i) / 2 ^ m, { intros m i, induction m with m ihm, { simp [J] }, simp only [pow_succ', J_succ, upper_sub_lower_split_center_box, ihm, div_div_eq_div_mul] }, have h0 : J 0 = I, from rfl, -- Now we clear unneeded assumptions clear_value J, clear hpI hs J_succ s, -- Let `z` be the unique common point of all `(J m).Icc`. Then `H_nhds` proves `p (J m)` for -- sufficiently large `m`. This contradicts `hJp`. set z : ι → ℝ := ⨆ m, (J m).lower, have hzJ : ∀ m, z ∈ (J m).Icc, from mem_Inter.1 (csupr_mem_Inter_Icc_of_antitone_Icc ((@box.Icc ι).monotone.comp_antitone hJmono) (λ m, (J m).lower_le_upper)), have hJl_mem : ∀ m, (J m).lower ∈ I.Icc, from λ m, le_iff_Icc.1 (hJle m) (J m).lower_mem_Icc, have hJu_mem : ∀ m, (J m).upper ∈ I.Icc, from λ m, le_iff_Icc.1 (hJle m) (J m).upper_mem_Icc, have hJlz : tendsto (λ m, (J m).lower) at_top (𝓝 z), from tendsto_at_top_csupr (antitone_lower.comp hJmono) ⟨I.upper, λ x ⟨m, hm⟩, hm ▸ (hJl_mem m).2⟩, have hJuz : tendsto (λ m, (J m).upper) at_top (𝓝 z), { suffices : tendsto (λ m, (J m).upper - (J m).lower) at_top (𝓝 0), by simpa using hJlz.add this, refine tendsto_pi.2 (λ i, _), simpa [hJsub] using tendsto_const_nhds.div_at_top (tendsto_pow_at_top_at_top_of_one_lt (@one_lt_two ℝ _ _)) }, replace hJlz : tendsto (λ m, (J m).lower) at_top (𝓝[Icc I.lower I.upper] z), from tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ hJlz (eventually_of_forall hJl_mem), replace hJuz : tendsto (λ m, (J m).upper) at_top (𝓝[Icc I.lower I.upper] z), from tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ hJuz (eventually_of_forall hJu_mem), rcases H_nhds z (h0 ▸ hzJ 0) with ⟨U, hUz, hU⟩, rcases (tendsto_lift'.1 (hJlz.Icc hJuz) U hUz).exists with ⟨m, hUm⟩, exact hJp m (hU (J m) (hJle m) m (hzJ m) hUm (hJsub m)) end end box end box_integral
b6a169cd7853dff44cf3e8db520ee72dd5a90473
2fbe653e4bc441efde5e5d250566e65538709888
/src/topology/separation.lean
7fe4cfbdfe5f43b822edcd2a49fd11e350a47d8f
[ "Apache-2.0" ]
permissive
aceg00/mathlib
5e15e79a8af87ff7eb8c17e2629c442ef24e746b
8786ea6d6d46d6969ac9a869eb818bf100802882
refs/heads/master
1,649,202,698,930
1,580,924,783,000
1,580,924,783,000
149,197,272
0
0
Apache-2.0
1,537,224,208,000
1,537,224,207,000
null
UTF-8
Lean
false
false
16,753
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 Separation properties of topological spaces. -/ import topology.subset_properties open set filter lattice open_locale topological_space local attribute [instance] classical.prop_decidable -- TODO: use "open_locale classical" universes u v variables {α : Type u} {β : Type v} [topological_space α] section separation /-- A T₀ space, also known as a Kolmogorov space, is a topological space where for every pair `x ≠ y`, there is an open set containing one but not the other. -/ class t0_space (α : Type u) [topological_space α] : Prop := (t0 : ∀ x y, x ≠ y → ∃ U:set α, is_open U ∧ (xor (x ∈ U) (y ∈ U))) theorem exists_open_singleton_of_fintype [t0_space α] [f : fintype α] [decidable_eq α] [ha : nonempty α] : ∃ x:α, is_open ({x}:set α) := have H : ∀ (T : finset α), T ≠ ∅ → ∃ x ∈ T, ∃ u, is_open u ∧ {x} = {y | y ∈ T} ∩ u := begin intro T, apply finset.case_strong_induction_on T, { intro h, exact (h rfl).elim }, { intros x S hxS ih h, by_cases hs : S = ∅, { existsi [x, finset.mem_insert_self x S, univ, is_open_univ], rw [hs, inter_univ], refl }, { rcases ih S (finset.subset.refl S) hs with ⟨y, hy, V, hv1, hv2⟩, by_cases hxV : x ∈ V, { cases t0_space.t0 x y (λ hxy, hxS $ by rwa hxy) with U hu, rcases hu with ⟨hu1, ⟨hu2, hu3⟩ | ⟨hu2, hu3⟩⟩, { existsi [x, finset.mem_insert_self x S, U ∩ V, is_open_inter hu1 hv1], apply set.ext, intro z, split, { intro hzx, rw set.mem_singleton_iff at hzx, rw hzx, exact ⟨finset.mem_insert_self x S, ⟨hu2, hxV⟩⟩ }, { intro hz, rw set.mem_singleton_iff, rcases hz with ⟨hz1, hz2, hz3⟩, cases finset.mem_insert.1 hz1 with hz4 hz4, { exact hz4 }, { have h1 : z ∈ {y : α | y ∈ S} ∩ V, { exact ⟨hz4, hz3⟩ }, rw ← hv2 at h1, rw set.mem_singleton_iff at h1, rw h1 at hz2, exact (hu3 hz2).elim } } }, { existsi [y, finset.mem_insert_of_mem hy, U ∩ V, is_open_inter hu1 hv1], apply set.ext, intro z, split, { intro hz, rw set.mem_singleton_iff at hz, rw hz, refine ⟨finset.mem_insert_of_mem hy, hu2, _⟩, have h1 : y ∈ {y} := set.mem_singleton y, rw hv2 at h1, exact h1.2 }, { intro hz, rw set.mem_singleton_iff, cases hz with hz1 hz2, cases finset.mem_insert.1 hz1 with hz3 hz3, { rw hz3 at hz2, exact (hu3 hz2.1).elim }, { have h1 : z ∈ {y : α | y ∈ S} ∩ V := ⟨hz3, hz2.2⟩, rw ← hv2 at h1, rw set.mem_singleton_iff at h1, exact h1 } } } }, { existsi [y, finset.mem_insert_of_mem hy, V, hv1], apply set.ext, intro z, split, { intro hz, rw set.mem_singleton_iff at hz, rw hz, split, { exact finset.mem_insert_of_mem hy }, { have h1 : y ∈ {y} := set.mem_singleton y, rw hv2 at h1, exact h1.2 } }, { intro hz, rw hv2, cases hz with hz1 hz2, cases finset.mem_insert.1 hz1 with hz3 hz3, { rw hz3 at hz2, exact (hxV hz2).elim }, { exact ⟨hz3, hz2⟩ } } } } } end, begin apply nonempty.elim ha, intro x, specialize H finset.univ (finset.ne_empty_of_mem $ finset.mem_univ x), rcases H with ⟨y, hyf, U, hu1, hu2⟩, existsi y, have h1 : {y : α | y ∈ finset.univ} = (univ : set α), { exact set.eq_univ_of_forall (λ x : α, by rw mem_set_of_eq; exact finset.mem_univ x) }, rw h1 at hu2, rw set.univ_inter at hu2, rw hu2, exact hu1 end /-- A T₁ space, also known as a Fréchet space, is a topological space where every singleton set is closed. Equivalently, for every pair `x ≠ y`, there is an open set containing `x` and not `y`. -/ class t1_space (α : Type u) [topological_space α] : Prop := (t1 : ∀x, is_closed ({x} : set α)) lemma is_closed_singleton [t1_space α] {x : α} : is_closed ({x} : set α) := t1_space.t1 x @[priority 100] -- see Note [lower instance priority] instance t1_space.t0_space [t1_space α] : t0_space α := ⟨λ x y h, ⟨-{x}, is_open_compl_iff.2 is_closed_singleton, or.inr ⟨λ hyx, or.cases_on hyx h.symm id, λ hx, hx $ or.inl rfl⟩⟩⟩ lemma compl_singleton_mem_nhds [t1_space α] {x y : α} (h : y ≠ x) : - {x} ∈ 𝓝 y := mem_nhds_sets is_closed_singleton $ by rwa [mem_compl_eq, mem_singleton_iff] @[simp] lemma closure_singleton [t1_space α] {a : α} : closure ({a} : set α) = {a} := closure_eq_of_is_closed is_closed_singleton /-- A T₂ space, also known as a Hausdorff space, is one in which for every `x ≠ y` there exists disjoint open sets around `x` and `y`. This is the most widely used of the separation axioms. -/ class t2_space (α : Type u) [topological_space α] : Prop := (t2 : ∀x y, x ≠ y → ∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅) lemma t2_separation [t2_space α] {x y : α} (h : x ≠ y) : ∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅ := t2_space.t2 x y h @[priority 100] -- see Note [lower instance priority] instance t2_space.t1_space [t2_space α] : t1_space α := ⟨λ x, is_open_iff_forall_mem_open.2 $ λ y hxy, let ⟨u, v, hu, hv, hyu, hxv, huv⟩ := t2_separation (mt mem_singleton_of_eq hxy) in ⟨u, λ z hz1 hz2, ((ext_iff _ _).1 huv x).1 ⟨mem_singleton_iff.1 hz2 ▸ hz1, hxv⟩, hu, hyu⟩⟩ lemma eq_of_nhds_ne_bot [ht : t2_space α] {x y : α} (h : 𝓝 x ⊓ 𝓝 y ≠ ⊥) : x = y := classical.by_contradiction $ assume : x ≠ y, let ⟨u, v, hu, hv, hx, hy, huv⟩ := t2_space.t2 x y this in have u ∩ v ∈ 𝓝 x ⊓ 𝓝 y, from inter_mem_inf_sets (mem_nhds_sets hu hx) (mem_nhds_sets hv hy), h $ empty_in_sets_eq_bot.mp $ huv ▸ this lemma t2_iff_nhds : t2_space α ↔ ∀ {x y : α}, 𝓝 x ⊓ 𝓝 y ≠ ⊥ → x = y := ⟨assume h, by exactI λ x y, eq_of_nhds_ne_bot, assume h, ⟨assume x y xy, have 𝓝 x ⊓ 𝓝 y = ⊥ := classical.by_contradiction (mt h xy), let ⟨u', hu', v', hv', u'v'⟩ := empty_in_sets_eq_bot.mpr this, ⟨u, uu', uo, hu⟩ := mem_nhds_sets_iff.mp hu', ⟨v, vv', vo, hv⟩ := mem_nhds_sets_iff.mp hv' in ⟨u, v, uo, vo, hu, hv, disjoint.eq_bot $ disjoint_mono uu' vv' u'v'⟩⟩⟩ lemma t2_iff_ultrafilter : t2_space α ↔ ∀ f {x y : α}, is_ultrafilter f → f ≤ 𝓝 x → f ≤ 𝓝 y → x = y := t2_iff_nhds.trans ⟨assume h f x y u fx fy, h $ ne_bot_of_le_ne_bot u.1 (le_inf fx fy), assume h x y xy, let ⟨f, hf, uf⟩ := exists_ultrafilter xy in h f uf (le_trans hf lattice.inf_le_left) (le_trans hf lattice.inf_le_right)⟩ @[simp] lemma nhds_eq_nhds_iff {a b : α} [t2_space α] : 𝓝 a = 𝓝 b ↔ a = b := ⟨assume h, eq_of_nhds_ne_bot $ by rw [h, inf_idem]; exact nhds_ne_bot, assume h, h ▸ rfl⟩ @[simp] lemma nhds_le_nhds_iff {a b : α} [t2_space α] : 𝓝 a ≤ 𝓝 b ↔ a = b := ⟨assume h, eq_of_nhds_ne_bot $ by rw [inf_of_le_left h]; exact nhds_ne_bot, assume h, h ▸ le_refl _⟩ lemma tendsto_nhds_unique [t2_space α] {f : β → α} {l : filter β} {a b : α} (hl : l ≠ ⊥) (ha : tendsto f l (𝓝 a)) (hb : tendsto f l (𝓝 b)) : a = b := eq_of_nhds_ne_bot $ ne_bot_of_le_ne_bot (map_ne_bot hl) $ le_inf ha hb section lim variables [inhabited α] [t2_space α] {f : filter α} lemma lim_eq {a : α} (hf : f ≠ ⊥) (h : f ≤ 𝓝 a) : lim f = a := eq_of_nhds_ne_bot $ ne_bot_of_le_ne_bot hf $ le_inf (lim_spec ⟨_, h⟩) h @[simp] lemma lim_nhds_eq {a : α} : lim (𝓝 a) = a := lim_eq nhds_ne_bot (le_refl _) @[simp] lemma lim_nhds_eq_of_closure {a : α} {s : set α} (h : a ∈ closure s) : lim (𝓝 a ⊓ principal s) = a := lim_eq begin rw [closure_eq_nhds] at h, exact h end inf_le_left end lim @[priority 100] -- see Note [lower instance priority] instance t2_space_discrete {α : Type*} [topological_space α] [discrete_topology α] : t2_space α := { t2 := assume x y hxy, ⟨{x}, {y}, is_open_discrete _, is_open_discrete _, mem_insert _ _, mem_insert _ _, eq_empty_iff_forall_not_mem.2 $ by intros z hz; cases eq_of_mem_singleton hz.1; cases eq_of_mem_singleton hz.2; cc⟩ } private lemma separated_by_f {α : Type*} {β : Type*} [tα : topological_space α] [tβ : topological_space β] [t2_space β] (f : α → β) (hf : tα ≤ tβ.induced f) {x y : α} (h : f x ≠ f y) : ∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅ := let ⟨u, v, uo, vo, xu, yv, uv⟩ := t2_separation h in ⟨f ⁻¹' u, f ⁻¹' v, hf _ ⟨u, uo, rfl⟩, hf _ ⟨v, vo, rfl⟩, xu, yv, by rw [←preimage_inter, uv, preimage_empty]⟩ instance {α : Type*} {p : α → Prop} [t : topological_space α] [t2_space α] : t2_space (subtype p) := ⟨assume x y h, separated_by_f subtype.val (le_refl _) (mt subtype.eq h)⟩ instance {α : Type*} {β : Type*} [t₁ : topological_space α] [t2_space α] [t₂ : topological_space β] [t2_space β] : t2_space (α × β) := ⟨assume ⟨x₁,x₂⟩ ⟨y₁,y₂⟩ h, or.elim (not_and_distrib.mp (mt prod.ext_iff.mpr h)) (λ h₁, separated_by_f prod.fst inf_le_left h₁) (λ h₂, separated_by_f prod.snd inf_le_right h₂)⟩ instance Pi.t2_space {α : Type*} {β : α → Type v} [t₂ : Πa, topological_space (β a)] [Πa, t2_space (β a)] : t2_space (Πa, β a) := ⟨assume x y h, let ⟨i, hi⟩ := not_forall.mp (mt funext h) in separated_by_f (λz, z i) (infi_le _ i) hi⟩ lemma is_closed_diagonal [t2_space α] : is_closed {p:α×α | p.1 = p.2} := is_closed_iff_nhds.mpr $ assume ⟨a₁, a₂⟩ h, eq_of_nhds_ne_bot $ assume : 𝓝 a₁ ⊓ 𝓝 a₂ = ⊥, h $ let ⟨t₁, ht₁, t₂, ht₂, (h' : t₁ ∩ t₂ ⊆ ∅)⟩ := by rw [←empty_in_sets_eq_bot, mem_inf_sets] at this; exact this in begin change t₁ ∈ 𝓝 a₁ at ht₁, change t₂ ∈ 𝓝 a₂ at ht₂, rw [nhds_prod_eq, ←empty_in_sets_eq_bot], apply filter.sets_of_superset, apply inter_mem_inf_sets (prod_mem_prod ht₁ ht₂) (mem_principal_sets.mpr (subset.refl _)), exact assume ⟨x₁, x₂⟩ ⟨⟨hx₁, hx₂⟩, (heq : x₁ = x₂)⟩, show false, from @h' x₁ ⟨hx₁, heq.symm ▸ hx₂⟩ end variables [topological_space β] lemma is_closed_eq [t2_space α] {f g : β → α} (hf : continuous f) (hg : continuous g) : is_closed {x:β | f x = g x} := continuous_iff_is_closed.mp (hf.prod_mk hg) _ is_closed_diagonal lemma diagonal_eq_range_diagonal_map {α : Type*} : {p:α×α | p.1 = p.2} = range (λx, (x,x)) := ext $ assume p, iff.intro (assume h, ⟨p.1, prod.ext_iff.2 ⟨rfl, h⟩⟩) (assume ⟨x, hx⟩, show p.1 = p.2, by rw ←hx) lemma prod_subset_compl_diagonal_iff_disjoint {α : Type*} {s t : set α} : set.prod s t ⊆ - {p:α×α | p.1 = p.2} ↔ s ∩ t = ∅ := by rw [eq_empty_iff_forall_not_mem, subset_compl_comm, diagonal_eq_range_diagonal_map, range_subset_iff]; simp lemma compact_compact_separated [t2_space α] {s t : set α} (hs : compact s) (ht : compact t) (hst : s ∩ t = ∅) : ∃u v : set α, is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ u ∩ v = ∅ := by simp only [prod_subset_compl_diagonal_iff_disjoint.symm] at ⊢ hst; exact generalized_tube_lemma hs ht is_closed_diagonal hst lemma closed_of_compact [t2_space α] (s : set α) (hs : compact s) : is_closed s := is_open_compl_iff.mpr $ is_open_iff_forall_mem_open.mpr $ assume x hx, let ⟨u, v, uo, vo, su, xv, uv⟩ := compact_compact_separated hs (compact_singleton : compact {x}) (by rwa [inter_comm, ←subset_compl_iff_disjoint, singleton_subset_iff]) in have v ⊆ -s, from subset_compl_comm.mp (subset.trans su (subset_compl_iff_disjoint.mpr uv)), ⟨v, this, vo, by simpa using xv⟩ lemma locally_compact_of_compact_nhds [t2_space α] (h : ∀ x : α, ∃ s, s ∈ 𝓝 x ∧ compact s) : locally_compact_space α := ⟨assume x n hn, let ⟨u, un, uo, xu⟩ := mem_nhds_sets_iff.mp hn in let ⟨k, kx, kc⟩ := h x in -- K is compact but not necessarily contained in N. -- K \ U is again compact and doesn't contain x, so -- we may find open sets V, W separating x from K \ U. -- Then K \ W is a compact neighborhood of x contained in U. let ⟨v, w, vo, wo, xv, kuw, vw⟩ := compact_compact_separated compact_singleton (compact_diff kc uo) (by rw [singleton_inter_eq_empty]; exact λ h, h.2 xu) in have wn : -w ∈ 𝓝 x, from mem_nhds_sets_iff.mpr ⟨v, subset_compl_iff_disjoint.mpr vw, vo, singleton_subset_iff.mp xv⟩, ⟨k - w, filter.inter_mem_sets kx wn, subset.trans (diff_subset_comm.mp kuw) un, compact_diff kc wo⟩⟩ @[priority 100] -- see Note [lower instance priority] instance locally_compact_of_compact [t2_space α] [compact_space α] : locally_compact_space α := locally_compact_of_compact_nhds (assume x, ⟨univ, mem_nhds_sets is_open_univ trivial, compact_univ⟩) end separation section regularity section prio set_option default_priority 100 -- see Note [default priority] /-- A T₃ space, also known as a regular space (although this condition sometimes omits T₂), is one in which for every closed `C` and `x ∉ C`, there exist disjoint open sets containing `x` and `C` respectively. -/ class regular_space (α : Type u) [topological_space α] extends t1_space α : Prop := (regular : ∀{s:set α} {a}, is_closed s → a ∉ s → ∃t, is_open t ∧ s ⊆ t ∧ 𝓝 a ⊓ principal t = ⊥) end prio lemma nhds_is_closed [regular_space α] {a : α} {s : set α} (h : s ∈ 𝓝 a) : ∃t∈(𝓝 a), t ⊆ s ∧ is_closed t := let ⟨s', h₁, h₂, h₃⟩ := mem_nhds_sets_iff.mp h in have ∃t, is_open t ∧ -s' ⊆ t ∧ 𝓝 a ⊓ principal t = ⊥, from regular_space.regular (is_closed_compl_iff.mpr h₂) (not_not_intro h₃), let ⟨t, ht₁, ht₂, ht₃⟩ := this in ⟨-t, mem_sets_of_eq_bot $ by rwa [lattice.neg_neg], subset.trans (compl_subset_comm.1 ht₂) h₁, is_closed_compl_iff.mpr ht₁⟩ variable (α) @[priority 100] -- see Note [lower instance priority] instance regular_space.t2_space [regular_space α] : t2_space α := ⟨λ x y hxy, let ⟨s, hs, hys, hxs⟩ := regular_space.regular is_closed_singleton (mt mem_singleton_iff.1 hxy), ⟨t, hxt, u, hsu, htu⟩ := empty_in_sets_eq_bot.2 hxs, ⟨v, hvt, hv, hxv⟩ := mem_nhds_sets_iff.1 hxt in ⟨v, s, hv, hs, hxv, singleton_subset_iff.1 hys, eq_empty_of_subset_empty $ λ z ⟨hzv, hzs⟩, htu ⟨hvt hzv, hsu hzs⟩⟩⟩ end regularity section normality section prio set_option default_priority 100 -- see Note [default priority] /-- A T₄ space, also known as a normal space (although this condition sometimes omits T₂), is one in which for every pair of disjoint closed sets `C` and `D`, there exist disjoint open sets containing `C` and `D` respectively. -/ class normal_space (α : Type u) [topological_space α] extends t1_space α : Prop := (normal : ∀ s t : set α, is_closed s → is_closed t → disjoint s t → ∃ u v, is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ disjoint u v) end prio theorem normal_separation [normal_space α] (s t : set α) (H1 : is_closed s) (H2 : is_closed t) (H3 : disjoint s t) : ∃ u v, is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ disjoint u v := normal_space.normal s t H1 H2 H3 @[priority 100] -- see Note [lower instance priority] instance normal_space.regular_space [normal_space α] : regular_space α := { regular := λ s x hs hxs, let ⟨u, v, hu, hv, hsu, hxv, huv⟩ := normal_separation s {x} hs is_closed_singleton (λ _ ⟨hx, hy⟩, hxs $ set.mem_of_eq_of_mem (set.eq_of_mem_singleton hy).symm hx) in ⟨u, hu, hsu, filter.empty_in_sets_eq_bot.1 $ filter.mem_inf_sets.2 ⟨v, mem_nhds_sets hv (set.singleton_subset_iff.1 hxv), u, filter.mem_principal_self u, set.inter_comm u v ▸ huv⟩⟩ } -- We can't make this an instance because it could cause an instance loop. lemma normal_of_compact_t2 [compact_space α] [t2_space α] : normal_space α := begin refine ⟨assume s t hs ht st, _⟩, simp only [disjoint_iff], exact compact_compact_separated hs.compact ht.compact st.eq_bot end end normality
9d0cf1b2c4aea7dad04f11507793494f575d116e
5ae26df177f810c5006841e9c73dc56e01b978d7
/src/category_theory/Cat.lean
2dd3f9faf508c403aca55021d06d4b55ee44d51c
[ "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,296
lean
import category_theory.concrete_category /-! Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov # Category of categories This file contains definition of category `Cat` of all categories. In this category objects are categories and morphisms are functors between these categories. ## Implementation notes Though `Cat` is not a concrete category, we use `bundled` to define its carrier type. -/ universes v u namespace category_theory /-- Category of categories. -/ def Cat := bundled category.{v u} namespace Cat instance str (C : Cat.{v u}) : category.{v u} C.α := C.str def of (C : Type u) [category.{v} C] : Cat.{v u} := mk_ob C /-- Category structure on `Cat` -/ instance category : category.{(max u v)+1 (max v (u+1))} Cat.{v u} := { hom := λ C D, C.α ⥤ D.α, id := λ C, 𝟭 C.α, comp := λ C D E F G, F ⋙ G, id_comp' := λ C D F, by cases F; refl, comp_id' := λ C D F, by cases F; refl, assoc' := by intros; refl } /-- Functor that gets the set of objects of a category. It is not called `forget`, because it is not a faithful functor. -/ def objects : Cat.{v u} ⥤ Type u := { obj := bundled.α, map := λ C D F, F.obj } end Cat end category_theory
fd50d1e7b880f7aa3b0470219566b28be6456c0c
69d4931b605e11ca61881fc4f66db50a0a875e39
/src/algebra/lie/basic.lean
e6b6f86a052d8bd7fd89a5f29ff1dc23f0e34e83
[ "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
25,665
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 tactic.noncomm_ring /-! # Lie algebras This file defines Lie rings and Lie algebras over a commutative ring together with their modules, morphisms and equivalences, as well as various lemmas to make these definitions usable. ## Main definitions * `lie_ring` * `lie_algebra` * `lie_ring_module` * `lie_module` * `lie_hom` * `lie_equiv` * `lie_module_hom` * `lie_module_equiv` ## Notation 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, jacobi identity, lie ring, lie algebra, lie module -/ universes u v w w₁ w₂ /-- A Lie ring is an additive group with compatible product, known as the bracket, satisfying the Jacobi identity. -/ @[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 module 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} {N : Type w₁} variables [comm_ring R] [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 N] [module R N] [lie_ring_module L N] [lie_module R L N] 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, sub_neg_eq_add, ←add_lie], simp, } @[simp] lemma lie_neg : ⁅x, -m⁆ = -⁅x, m⁆ := by { rw [←sub_eq_zero, sub_neg_eq_add, ←lie_add], simp, } @[simp] lemma sub_lie : ⁅x - y, m⁆ = ⁅x, m⁆ - ⁅y, m⁆ := by simp [sub_eq_add_neg] @[simp] lemma lie_sub : ⁅x, m - n⁆ = ⁅x, m⁆ - ⁅x, n⁆ := by simp [sub_eq_add_neg] @[simp] lemma nsmul_lie (n : ℕ) : ⁅n • x, m⁆ = n • ⁅x, m⁆ := add_monoid_hom.map_nsmul ⟨λ (x : L), ⁅x, m⁆, zero_lie m, λ _ _, add_lie _ _ _⟩ _ _ @[simp] lemma lie_nsmul (n : ℕ) : ⁅x, n • m⁆ = n • ⁅x, m⁆ := add_monoid_hom.map_nsmul ⟨λ (m : M), ⁅x, m⁆, lie_zero x, λ _ _, lie_add _ _ _⟩ _ _ @[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, } instance : lie_ring_module L (M →ₗ[R] N) := { bracket := λ x f, { to_fun := λ m, ⁅x, f m⁆ - f ⁅x, m⁆, map_add' := λ m n, by { simp only [lie_add, linear_map.map_add], abel, }, map_smul' := λ t m, by simp only [smul_sub, linear_map.map_smul, lie_smul], }, add_lie := λ x y f, by { ext n, simp only [add_lie, linear_map.coe_mk, linear_map.add_apply, linear_map.map_add], abel, }, lie_add := λ x f g, by { ext n, simp only [linear_map.coe_mk, lie_add, linear_map.add_apply], abel, }, leibniz_lie := λ x y f, by { ext n, simp only [lie_lie, linear_map.coe_mk, linear_map.map_sub, linear_map.add_apply, lie_sub], abel, }, } @[simp] lemma lie_hom.lie_apply (f : M →ₗ[R] N) (x : L) (m : M) : ⁅x, f⁆ m = ⁅x, f m⁆ - f ⁅x, m⁆ := rfl instance : lie_module R L (M →ₗ[R] N) := { smul_lie := λ t x f, by { ext n, simp only [smul_sub, smul_lie, linear_map.smul_apply, lie_hom.lie_apply, linear_map.map_smul], }, lie_smul := λ t x f, by { ext n, simp only [smul_sub, linear_map.smul_apply, lie_hom.lie_apply, lie_smul], }, } end basic_properties set_option old_structure_cmd true /-- A morphism of Lie algebras is a linear map respecting the bracket operations. -/ structure lie_hom (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' := (map_lie' : ∀ {x y : L}, to_fun ⁅x, y⁆ = ⁅to_fun x, to_fun y⁆) attribute [nolint doc_blame] lie_hom.to_linear_map notation L ` →ₗ⁅`:25 R:25 `⁆ `:0 L':0 := lie_hom R L L' namespace lie_hom 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₂) := ⟨lie_hom.to_linear_map⟩ /-- see Note [function coercion] -/ instance : has_coe_to_fun (L₁ →ₗ⁅R⁆ L₂) := ⟨_, lie_hom.to_fun⟩ initialize_simps_projections lie_hom (to_fun → apply) @[simp, norm_cast] lemma coe_to_linear_map (f : L₁ →ₗ⁅R⁆ L₂) : ((f : L₁ →ₗ[R] L₂) : L₁ → L₂) = f := rfl @[simp] lemma map_smul (f : L₁ →ₗ⁅R⁆ L₂) (c : R) (x : L₁) : f (c • x) = c • f x := linear_map.map_smul (f : L₁ →ₗ[R] L₂) c x @[simp] lemma map_add (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f (x + y) = (f x) + (f y) := linear_map.map_add (f : L₁ →ₗ[R] L₂) x y @[simp] lemma map_sub (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f (x - y) = (f x) - (f y) := linear_map.map_sub (f : L₁ →ₗ[R] L₂) x y @[simp] lemma map_neg (f : L₁ →ₗ⁅R⁆ L₂) (x : L₁) : f (-x) = -(f x) := linear_map.map_neg (f : L₁ →ₗ[R] L₂) x @[simp] lemma map_lie (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f ⁅x, y⁆ = ⁅f x, f y⁆ := lie_hom.map_lie' f @[simp] lemma map_zero (f : L₁ →ₗ⁅R⁆ L₂) : f 0 = 0 := (f : L₁ →ₗ[R] L₂).map_zero /-- The constant 0 map is a Lie algebra morphism. -/ instance : has_zero (L₁ →ₗ⁅R⁆ L₂) := ⟨{ map_lie' := by simp, ..(0 : L₁ →ₗ[R] L₂)}⟩ @[norm_cast, simp] lemma coe_zero : ((0 : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = 0 := rfl lemma zero_apply (x : L₁) : (0 : L₁ →ₗ⁅R⁆ L₂) x = 0 := rfl /-- 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 coe_injective : function.injective (λ f : L₁ →ₗ⁅R⁆ L₂, show L₁ → L₂, from f) := by rintro ⟨f, _⟩ ⟨g, _⟩ ⟨h⟩; congr @[ext] lemma ext {f g : L₁ →ₗ⁅R⁆ L₂} (h : ∀ x, f x = g x) : f = g := coe_injective $ funext h lemma ext_iff {f g : L₁ →ₗ⁅R⁆ L₂} : f = g ↔ ∀ x, f x = g x := ⟨by { rintro rfl x, refl }, ext⟩ @[simp] lemma mk_coe (f : L₁ →ₗ⁅R⁆ L₂) (h₁ h₂ h₃) : (⟨f, h₁, h₂, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) = f := by { ext, refl, } @[simp] lemma coe_mk (f : L₁ → L₂) (h₁ h₂ h₃) : ((⟨f, h₁, h₂, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = f := rfl @[norm_cast, simp] lemma coe_linear_mk (f : L₁ →ₗ[R] L₂) (h₁ h₂ h₃) : ((⟨f, h₁, h₂, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) : L₁ →ₗ[R] L₂) = ⟨f, h₁, h₂⟩ := by { ext, refl, } /-- The composition of morphisms is a morphism. -/ def 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 } lemma comp_apply (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) (x : L₁) : f.comp g x = f (g x) := rfl @[norm_cast, simp] lemma coe_comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : (f.comp g : L₁ → L₃) = f ∘ g := rfl @[norm_cast, simp] lemma coe_linear_map_comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : (f.comp g : L₁ →ₗ[R] L₃) = (f : L₂ →ₗ[R] L₃).comp (g : L₁ →ₗ[R] L₂) := rfl /-- The inverse of a bijective morphism is a morphism. -/ def 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 lie_hom /-- 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 lie_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_equiv.to_lie_hom attribute [nolint doc_blame] lie_equiv.to_linear_equiv notation L ` ≃ₗ⁅`:50 R `⁆ ` L' := lie_equiv R L L' namespace lie_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_lie_hom⟩ 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₁ := { ..lie_hom.inverse e.to_lie_hom 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₃ := { ..lie_hom.comp e₂.to_lie_hom e₁.to_lie_hom, ..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 lemma bijective (e : L₁ ≃ₗ⁅R⁆ L₂) : function.bijective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) := e.to_linear_equiv.bijective lemma injective (e : L₁ ≃ₗ⁅R⁆ L₂) : function.injective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) := e.to_linear_equiv.injective lemma surjective (e : L₁ ≃ₗ⁅R⁆ L₂) : function.surjective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) := e.to_linear_equiv.surjective end lie_equiv 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, norm_cast] lemma coe_to_linear_map (f : M →ₗ⁅R,L⁆ N) : ((f : M →ₗ[R] N) : M → N) = f := rfl @[simp] lemma map_smul (f : M →ₗ⁅R,L⁆ N) (c : R) (x : M) : f (c • x) = c • f x := linear_map.map_smul (f : M →ₗ[R] N) c x @[simp] lemma map_add (f : M →ₗ⁅R,L⁆ N) (x y : M) : f (x + y) = (f x) + (f y) := linear_map.map_add (f : M →ₗ[R] N) x y @[simp] lemma map_sub (f : M →ₗ⁅R,L⁆ N) (x y : M) : f (x - y) = (f x) - (f y) := linear_map.map_sub (f : M →ₗ[R] N) x y @[simp] lemma map_neg (f : M →ₗ⁅R,L⁆ N) (x : M) : f (-x) = -(f x) := linear_map.map_neg (f : M →ₗ[R] N) x @[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 lemma map_lie₂ (f : M →ₗ⁅R,L⁆ N →ₗ[R] P) (x : L) (m : M) (n : N) : ⁅x, f m n⁆ = f ⁅x, m⁆ n + f m ⁅x, n⁆ := by simp only [sub_add_cancel, map_lie, lie_hom.lie_apply] @[simp] lemma map_zero (f : M →ₗ⁅R,L⁆ N) : f 0 = 0 := linear_map.map_zero (f : M →ₗ[R] N) /-- The constant 0 map is a Lie module morphism. -/ instance : has_zero (M →ₗ⁅R,L⁆ N) := ⟨{ map_lie' := by simp, ..(0 : M →ₗ[R] N) }⟩ @[norm_cast, simp] lemma coe_zero : ((0 : M →ₗ⁅R,L⁆ N) : M → N) = 0 := rfl lemma zero_apply (m : M) : (0 : M →ₗ⁅R,L⁆ N) m = 0 := rfl /-- 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⟩ @[simp] lemma mk_coe (f : M →ₗ⁅R,L⁆ N) (h₁ h₂ h₃) : (⟨f, h₁, h₂, h₃⟩ : M →ₗ⁅R,L⁆ N) = f := by { ext, refl, } @[simp] lemma coe_mk (f : M → N) (h₁ h₂ h₃) : ((⟨f, h₁, h₂, h₃⟩ : M →ₗ⁅R,L⁆ N) : M → N) = f := rfl @[norm_cast, simp] lemma coe_linear_mk (f : M →ₗ[R] N) (h₁ h₂ h₃) : ((⟨f, h₁, h₂, h₃⟩ : M →ₗ⁅R,L⁆ N) : M →ₗ[R] N) = ⟨f, h₁, h₂⟩ := by { ext, refl, } /-- 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 } 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, simp] lemma coe_comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) : (f.comp g : M → P) = f ∘ g := rfl @[norm_cast, simp] lemma coe_linear_map_comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) : (f.comp g : M →ₗ[R] P) = (f : N →ₗ[R] P).comp (g : M →ₗ[R] N) := 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₂ } instance : has_add (M →ₗ⁅R,L⁆ N) := { add := λ f g, { map_lie' := by simp, ..((f : M →ₗ[R] N) + (g : M →ₗ[R] N)) }, } instance : has_sub (M →ₗ⁅R,L⁆ N) := { sub := λ f g, { map_lie' := by simp, ..((f : M →ₗ[R] N) - (g : M →ₗ[R] N)) }, } instance : has_neg (M →ₗ⁅R,L⁆ N) := { neg := λ f, { map_lie' := by simp, ..(-(f : (M →ₗ[R] N))) }, } @[norm_cast, simp] lemma coe_add (f g : M →ₗ⁅R,L⁆ N) : ⇑(f + g) = f + g := rfl lemma add_apply (f g : M →ₗ⁅R,L⁆ N) (m : M) : (f + g) m = f m + g m := rfl @[norm_cast, simp] lemma coe_sub (f g : M →ₗ⁅R,L⁆ N) : ⇑(f - g) = f - g := rfl lemma sub_apply (f g : M →ₗ⁅R,L⁆ N) (m : M) : (f - g) m = f m - g m := rfl @[norm_cast, simp] lemma coe_neg (f : M →ₗ⁅R,L⁆ N) : ⇑(-f) = -f := rfl lemma neg_apply (f : M →ₗ⁅R,L⁆ N) (m : M) : (-f) m = -(f m) := rfl instance : add_comm_group (M →ₗ⁅R,L⁆ N) := { zero := 0, add := (+), neg := has_neg.neg, sub := has_sub.sub, nsmul := λ n f, { map_lie' := λ x m, by simp, ..(n • (f : M →ₗ[R] N)) }, nsmul_zero' := λ f, by { ext, simp, }, nsmul_succ' := λ n f, by { ext, simp [nat.succ_eq_one_add, add_nsmul], }, ..(coe_injective.add_comm_group _ coe_zero coe_add coe_neg coe_sub : add_comm_group (M →ₗ⁅R,L⁆ N)) } instance : has_scalar R (M →ₗ⁅R,L⁆ N) := { smul := λ t f, { map_lie' := by simp, ..(t • (f : M →ₗ[R] N)) }, } @[norm_cast, simp] lemma coe_smul (t : R) (f : M →ₗ⁅R,L⁆ N) : ⇑(t • f) = t • f := rfl lemma smul_apply (t : R) (f : M →ₗ⁅R,L⁆ N) (m : M) : (t • f) m = t • (f m) := rfl instance : module R (M →ₗ⁅R,L⁆ N) := function.injective.module R ⟨to_fun, rfl, coe_add⟩ coe_injective coe_smul 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, M ≃ N attribute [nolint doc_blame] lie_module_equiv.to_equiv 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_equiv : has_coe (M ≃ₗ⁅R,L⁆ N) (M ≃ N) := ⟨to_equiv⟩ 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] lemma coe_mk (f : M → N) (h₁ h₂ F h₃ h₄ h₅) : ((⟨f, h₁, h₂, F, h₃, h₄, h₅⟩ : M ≃ₗ⁅R,L⁆ N) : M → N) = f := rfl @[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 lemma to_equiv_injective : function.injective (to_equiv : (M ≃ₗ⁅R,L⁆ N) → M ≃ N) := λ ⟨_, _, _, _, _, _, _⟩ ⟨_, _, _, _, _, _, _⟩ h, lie_module_equiv.mk.inj_eq.mpr (equiv.mk.inj h) @[ext] lemma ext (e₁ e₂ : M ≃ₗ⁅R,L⁆ N) (h : ∀ m, e₁ m = e₂ m) : e₁ = e₂ := to_equiv_injective (equiv.ext h) 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
477225f06fb61f74eb569f4293b1915fb3f9a8dc
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/category_theory/category/Cat.lean
7dece7b014a0f8541d5934da5fb87ef2ea11fffc
[ "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
2,430
lean
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import category_theory.concrete_category import category_theory.discrete_category import category_theory.eq_to_hom /-! # Category of categories This file contains the definition of the category `Cat` of all categories. In this category objects are categories and morphisms are functors between these categories. ## Implementation notes Though `Cat` is not a concrete category, we use `bundled` to define its carrier type. -/ universes v u namespace category_theory /-- Category of categories. -/ def Cat := bundled category.{v u} namespace Cat instance : inhabited Cat := ⟨⟨Type u, category_theory.types⟩⟩ instance : has_coe_to_sort Cat := { S := Type u, coe := bundled.α } instance str (C : Cat.{v u}) : category.{v u} C := C.str /-- Construct a bundled `Cat` from the underlying type and the typeclass. -/ def of (C : Type u) [category.{v} C] : Cat.{v u} := bundled.of C /-- Category structure on `Cat` -/ instance category : large_category.{max v u} Cat.{v u} := { hom := λ C D, C ⥤ D, id := λ C, 𝟭 C, comp := λ C D E F G, F ⋙ G, id_comp' := λ C D F, by cases F; refl, comp_id' := λ C D F, by cases F; refl, assoc' := by intros; refl } /-- Functor that gets the set of objects of a category. It is not called `forget`, because it is not a faithful functor. -/ def objects : Cat.{v u} ⥤ Type u := { obj := λ C, C, map := λ C D F, F.obj } /-- Any isomorphism in `Cat` induces an equivalence of the underlying categories. -/ def equiv_of_iso {C D : Cat} (γ : C ≅ D) : C ≌ D := { functor := γ.hom, inverse := γ.inv, unit_iso := eq_to_iso $ eq.symm γ.hom_inv_id, counit_iso := eq_to_iso γ.inv_hom_id } end Cat /-- Embedding `Type` into `Cat` as discrete categories. This ought to be modelled as a 2-functor! -/ @[simps] def Type_to_Cat : Type u ⥤ Cat := { obj := λ X, Cat.of (discrete X), map := λ X Y f, discrete.functor f, map_id' := λ X, begin apply functor.ext, tidy, end, map_comp' := λ X Y Z f g, begin apply functor.ext, tidy, end } instance : faithful Type_to_Cat := {} instance : full Type_to_Cat := { preimage := λ X Y F, F.obj, witness' := begin intros X Y F, apply functor.ext, { intros x y f, dsimp, ext, }, { intros x, refl, } end } end category_theory
11e0dfe4311c6cbcd96cf7a20f69f6569d26c35f
e0f9ba56b7fedc16ef8697f6caeef5898b435143
/src/algebra/char_zero.lean
178cd0e9180b56cb89d6a3bc32ad6c0b597b2302
[ "Apache-2.0" ]
permissive
anrddh/mathlib
6a374da53c7e3a35cb0298b0cd67824efef362b4
a4266a01d2dcb10de19369307c986d038c7bb6a6
refs/heads/master
1,656,710,827,909
1,589,560,456,000
1,589,560,456,000
264,271,800
0
0
Apache-2.0
1,589,568,062,000
1,589,568,061,000
null
UTF-8
Lean
false
false
3,284
lean
/- Copyright (c) 2014 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro Natural homomorphism from the natural numbers into a monoid with one. -/ import algebra.field import tactic.wlog /-- Typeclass for monoids with characteristic zero. (This is usually stated on fields but it makes sense for any additive monoid with 1.) -/ class char_zero (α : Type*) [add_monoid α] [has_one α] : Prop := (cast_injective : function.injective (coe : ℕ → α)) theorem char_zero_of_inj_zero {α : Type*} [add_monoid α] [has_one α] (add_left_cancel : ∀ a b c : α, a + b = a + c → b = c) (H : ∀ n:ℕ, (n:α) = 0 → n = 0) : char_zero α := ⟨λ m n, begin assume h, wlog hle : m ≤ n, cases nat.le.dest hle with k e, suffices : k = 0, by rw [← e, this, add_zero], apply H, apply add_left_cancel n, rw [← h, ← nat.cast_add, e, add_zero, h] end⟩ -- We have no `left_cancel_add_monoid`, so we restate it for `add_group` -- and `ordered_cancel_comm_monoid`. theorem add_group.char_zero_of_inj_zero {α : Type*} [add_group α] [has_one α] (H : ∀ n:ℕ, (n:α) = 0 → n = 0) : char_zero α := char_zero_of_inj_zero (@add_left_cancel _ _) H theorem ordered_cancel_comm_monoid.char_zero_of_inj_zero {α : Type*} [ordered_cancel_add_comm_monoid α] [has_one α] (H : ∀ n:ℕ, (n:α) = 0 → n = 0) : char_zero α := char_zero_of_inj_zero (@add_left_cancel _ _) H @[priority 100] -- see Note [lower instance priority] instance linear_ordered_semiring.to_char_zero {α : Type*} [linear_ordered_semiring α] : char_zero α := ordered_cancel_comm_monoid.char_zero_of_inj_zero $ λ n h, nat.eq_zero_of_le_zero $ (@nat.cast_le α _ _ _).1 (le_of_eq h) namespace nat variables {α : Type*} [add_monoid α] [has_one α] [char_zero α] theorem cast_injective : function.injective (coe : ℕ → α) := char_zero.cast_injective @[simp, norm_cast] theorem cast_inj {m n : ℕ} : (m : α) = n ↔ m = n := cast_injective.eq_iff @[simp, norm_cast] theorem cast_eq_zero {n : ℕ} : (n : α) = 0 ↔ n = 0 := by rw [← cast_zero, cast_inj] @[norm_cast] theorem cast_ne_zero {n : ℕ} : (n : α) ≠ 0 ↔ n ≠ 0 := not_congr cast_eq_zero lemma cast_add_one_ne_zero (n : ℕ) : (n + 1 : α) ≠ 0 := by exact_mod_cast n.succ_ne_zero end nat @[field_simps] lemma two_ne_zero' {α : Type*} [add_monoid α] [has_one α] [char_zero α] : (2:α) ≠ 0 := have ((2:ℕ):α) ≠ 0, from nat.cast_ne_zero.2 dec_trivial, by rwa [nat.cast_succ, nat.cast_one] at this section variables {α : Type*} [domain α] [char_zero α] lemma add_self_eq_zero {a : α} : a + a = 0 ↔ a = 0 := by simp only [(two_mul a).symm, mul_eq_zero, two_ne_zero', false_or] lemma bit0_eq_zero {a : α} : bit0 a = 0 ↔ a = 0 := add_self_eq_zero end section variables {α : Type*} [division_ring α] [char_zero α] @[simp] lemma half_add_self (a : α) : (a + a) / 2 = a := by rw [← mul_two, mul_div_cancel a two_ne_zero'] @[simp] lemma add_halves' (a : α) : a / 2 + a / 2 = a := by rw [← add_div, half_add_self] lemma sub_half (a : α) : a - a / 2 = a / 2 := by rw [sub_eq_iff_eq_add, add_halves'] lemma half_sub (a : α) : a / 2 - a = - (a / 2) := by rw [← neg_sub, sub_half] end
19223dfa9e31ae3a7d3b1c13a1effab1e8d05b37
618003631150032a5676f229d13a079ac875ff77
/src/analysis/normed_space/hahn_banach.lean
834d7cc545c2a11e36cf2511f6d72126a33cf77f
[ "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
1,406
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.normed_space.operator_norm import analysis.convex.cone /-! # Hahn-Banach theorem In this file we prove a version of Hahn-Banach theorem for continuous linear functions on normed spaces. ## TODO Prove some corollaries -/ variables {E : Type*} [normed_group E] [normed_space ℝ E] /-- Hahn-Banach theorem for continuous linear functions. -/ 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
dc3eb9ebf579cf77f74aabe60c56fe49a670257a
947fa6c38e48771ae886239b4edce6db6e18d0fb
/src/analysis/convex/cone.lean
e3502abb3577f0093ddd5025660012a47abf4dcb
[ "Apache-2.0" ]
permissive
ramonfmir/mathlib
c5dc8b33155473fab97c38bd3aa6723dc289beaa
14c52e990c17f5a00c0cc9e09847af16fabbed25
refs/heads/master
1,661,979,343,526
1,660,830,384,000
1,660,830,384,000
182,072,989
0
0
null
1,555,585,876,000
1,555,585,876,000
null
UTF-8
Lean
false
false
29,366
lean
/- Copyright (c) 2020 Yury Kudryashov All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Frédéric Dupuis -/ import analysis.convex.hull import analysis.inner_product_space.basic /-! # Convex cones In a `𝕜`-module `E`, we define a convex cone as a set `s` such that `a • x + b • y ∈ s` whenever `x, y ∈ s` and `a, b > 0`. We prove that convex cones form a `complete_lattice`, and define their images (`convex_cone.map`) and preimages (`convex_cone.comap`) under linear maps. We define pointed, blunt, flat and salient cones, and prove the correspondence between convex cones and ordered modules. We also define `convex.to_cone` to be the minimal cone that includes a given convex set. We define `set.inner_dual_cone` to be the cone consisting of all points `y` such that for all points `x` in a given set `0 ≤ ⟪ x, y ⟫`. ## Main statements We prove two extension theorems: * `riesz_extension`: [M. Riesz extension theorem](https://en.wikipedia.org/wiki/M._Riesz_extension_theorem) says that if `s` is a convex cone in a real vector space `E`, `p` is a submodule of `E` such that `p + s = E`, and `f` is a linear function `p → ℝ` which is nonnegative on `p ∩ s`, then there exists a globally defined linear function `g : E → ℝ` that agrees with `f` on `p`, and is nonnegative on `s`. * `exists_extension_of_le_sublinear`: Hahn-Banach theorem: if `N : E → ℝ` is a sublinear map, `f` is a linear map defined on a subspace of `E`, and `f x ≤ N x` for all `x` in the domain of `f`, then `f` can be extended to the whole space to a linear map `g` such that `g x ≤ N x` for all `x` ## Implementation notes While `convex 𝕜` is a predicate on sets, `convex_cone 𝕜 E` is a bundled convex cone. ## References * https://en.wikipedia.org/wiki/Convex_cone -/ open set linear_map open_locale classical pointwise variables {𝕜 E F G : Type*} /-! ### Definition of `convex_cone` and basic properties -/ section definitions variables (𝕜 E) [ordered_semiring 𝕜] /-- A convex cone is a subset `s` of a `𝕜`-module such that `a • x + b • y ∈ s` whenever `a, b > 0` and `x, y ∈ s`. -/ structure convex_cone [add_comm_monoid E] [has_smul 𝕜 E] := (carrier : set E) (smul_mem' : ∀ ⦃c : 𝕜⦄, 0 < c → ∀ ⦃x : E⦄, x ∈ carrier → c • x ∈ carrier) (add_mem' : ∀ ⦃x⦄ (hx : x ∈ carrier) ⦃y⦄ (hy : y ∈ carrier), x + y ∈ carrier) end definitions variables {𝕜 E} namespace convex_cone section ordered_semiring variables [ordered_semiring 𝕜] [add_comm_monoid E] section has_smul variables [has_smul 𝕜 E] (S T : convex_cone 𝕜 E) instance : set_like (convex_cone 𝕜 E) E := { coe := carrier, coe_injective' := λ S T h, by cases S; cases T; congr' } @[simp] lemma coe_mk {s : set E} {h₁ h₂} : ↑(@mk 𝕜 _ _ _ _ s h₁ h₂) = s := rfl @[simp] lemma mem_mk {s : set E} {h₁ h₂ x} : x ∈ @mk 𝕜 _ _ _ _ s h₁ h₂ ↔ x ∈ s := iff.rfl /-- Two `convex_cone`s are equal if they have the same elements. -/ @[ext] theorem ext {S T : convex_cone 𝕜 E} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := set_like.ext h lemma smul_mem {c : 𝕜} {x : E} (hc : 0 < c) (hx : x ∈ S) : c • x ∈ S := S.smul_mem' hc hx lemma add_mem ⦃x⦄ (hx : x ∈ S) ⦃y⦄ (hy : y ∈ S) : x + y ∈ S := S.add_mem' hx hy instance : add_mem_class (convex_cone 𝕜 E) E := { add_mem := λ c a b ha hb, add_mem c ha hb } instance : has_inf (convex_cone 𝕜 E) := ⟨λ S T, ⟨S ∩ T, λ c hc x hx, ⟨S.smul_mem hc hx.1, T.smul_mem hc hx.2⟩, λ x hx y hy, ⟨S.add_mem hx.1 hy.1, T.add_mem hx.2 hy.2⟩⟩⟩ @[simp] lemma coe_inf : ((S ⊓ T : convex_cone 𝕜 E) : set E) = ↑S ∩ ↑T := rfl lemma mem_inf {x} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := iff.rfl instance : has_Inf (convex_cone 𝕜 E) := ⟨λ S, ⟨⋂ s ∈ S, ↑s, λ c hc x hx, mem_bInter $ λ s hs, s.smul_mem hc $ mem_Inter₂.1 hx s hs, λ x hx y hy, mem_bInter $ λ s hs, s.add_mem (mem_Inter₂.1 hx s hs) (mem_Inter₂.1 hy s hs)⟩⟩ @[simp] lemma coe_Inf (S : set (convex_cone 𝕜 E)) : ↑(Inf S) = ⋂ s ∈ S, (s : set E) := rfl lemma mem_Inf {x : E} {S : set (convex_cone 𝕜 E)} : x ∈ Inf S ↔ ∀ s ∈ S, x ∈ s := mem_Inter₂ @[simp] lemma coe_infi {ι : Sort*} (f : ι → convex_cone 𝕜 E) : ↑(infi f) = ⋂ i, (f i : set E) := by simp [infi] lemma mem_infi {ι : Sort*} {x : E} {f : ι → convex_cone 𝕜 E} : x ∈ infi f ↔ ∀ i, x ∈ f i := mem_Inter₂.trans $ by simp variables (𝕜) instance : has_bot (convex_cone 𝕜 E) := ⟨⟨∅, λ c hc x, false.elim, λ x, false.elim⟩⟩ lemma mem_bot (x : E) : x ∈ (⊥ : convex_cone 𝕜 E) = false := rfl @[simp] lemma coe_bot : ↑(⊥ : convex_cone 𝕜 E) = (∅ : set E) := rfl instance : has_top (convex_cone 𝕜 E) := ⟨⟨univ, λ c hc x hx, mem_univ _, λ x hx y hy, mem_univ _⟩⟩ lemma mem_top (x : E) : x ∈ (⊤ : convex_cone 𝕜 E) := mem_univ x @[simp] lemma coe_top : ↑(⊤ : convex_cone 𝕜 E) = (univ : set E) := rfl instance : complete_lattice (convex_cone 𝕜 E) := { le := (≤), lt := (<), bot := (⊥), bot_le := λ S x, false.elim, top := (⊤), le_top := λ S x hx, mem_top 𝕜 x, inf := (⊓), Inf := has_Inf.Inf, sup := λ a b, Inf {x | a ≤ x ∧ b ≤ x}, Sup := λ s, Inf {T | ∀ S ∈ s, S ≤ T}, le_sup_left := λ a b, λ x hx, mem_Inf.2 $ λ s hs, hs.1 hx, le_sup_right := λ a b, λ x hx, mem_Inf.2 $ λ s hs, hs.2 hx, sup_le := λ a b c ha hb x hx, mem_Inf.1 hx c ⟨ha, hb⟩, le_inf := λ a b c ha hb x hx, ⟨ha hx, hb hx⟩, inf_le_left := λ a b x, and.left, inf_le_right := λ a b x, and.right, le_Sup := λ s p hs x hx, mem_Inf.2 $ λ t ht, ht p hs hx, Sup_le := λ s p hs x hx, mem_Inf.1 hx p hs, le_Inf := λ s a ha x hx, mem_Inf.2 $ λ t ht, ha t ht hx, Inf_le := λ s a ha x hx, mem_Inf.1 hx _ ha, .. set_like.partial_order } instance : inhabited (convex_cone 𝕜 E) := ⟨⊥⟩ end has_smul section module variables [module 𝕜 E] (S : convex_cone 𝕜 E) protected lemma convex : convex 𝕜 (S : set E) := convex_iff_forall_pos.2 $ λ x y hx hy a b ha hb hab, S.add_mem (S.smul_mem ha hx) (S.smul_mem hb hy) end module end ordered_semiring section linear_ordered_field variables [linear_ordered_field 𝕜] section add_comm_monoid variables [add_comm_monoid E] [add_comm_monoid F] [add_comm_monoid G] section mul_action variables [mul_action 𝕜 E] (S : convex_cone 𝕜 E) lemma smul_mem_iff {c : 𝕜} (hc : 0 < c) {x : E} : c • x ∈ S ↔ x ∈ S := ⟨λ h, inv_smul_smul₀ hc.ne' x ▸ S.smul_mem (inv_pos.2 hc) h, S.smul_mem hc⟩ end mul_action section module variables [module 𝕜 E] [module 𝕜 F] [module 𝕜 G] /-- The image of a convex cone under a `𝕜`-linear map is a convex cone. -/ def map (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 E) : convex_cone 𝕜 F := { carrier := f '' S, smul_mem' := λ c hc y ⟨x, hx, hy⟩, hy ▸ f.map_smul c x ▸ mem_image_of_mem f (S.smul_mem hc hx), add_mem' := λ y₁ ⟨x₁, hx₁, hy₁⟩ y₂ ⟨x₂, hx₂, hy₂⟩, hy₁ ▸ hy₂ ▸ f.map_add x₁ x₂ ▸ mem_image_of_mem f (S.add_mem hx₁ hx₂) } @[simp] lemma mem_map {f : E →ₗ[𝕜] F} {S : convex_cone 𝕜 E} {y : F} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y := mem_image_iff_bex lemma map_map (g : F →ₗ[𝕜] G) (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 E) : (S.map f).map g = S.map (g.comp f) := set_like.coe_injective $ image_image g f S @[simp] lemma map_id (S : convex_cone 𝕜 E) : S.map linear_map.id = S := set_like.coe_injective $ image_id _ /-- The preimage of a convex cone under a `𝕜`-linear map is a convex cone. -/ def comap (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 F) : convex_cone 𝕜 E := { carrier := f ⁻¹' S, smul_mem' := λ c hc x hx, by { rw [mem_preimage, f.map_smul c], exact S.smul_mem hc hx }, add_mem' := λ x hx y hy, by { rw [mem_preimage, f.map_add], exact S.add_mem hx hy } } @[simp] lemma coe_comap (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 F) : (S.comap f : set E) = f ⁻¹' S := rfl @[simp] lemma comap_id (S : convex_cone 𝕜 E) : S.comap linear_map.id = S := set_like.coe_injective preimage_id lemma comap_comap (g : F →ₗ[𝕜] G) (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 G) : (S.comap g).comap f = S.comap (g.comp f) := set_like.coe_injective $ preimage_comp.symm @[simp] lemma mem_comap {f : E →ₗ[𝕜] F} {S : convex_cone 𝕜 F} {x : E} : x ∈ S.comap f ↔ f x ∈ S := iff.rfl end module end add_comm_monoid section ordered_add_comm_group variables [ordered_add_comm_group E] [module 𝕜 E] /-- Constructs an ordered module given an `ordered_add_comm_group`, a cone, and a proof that the order relation is the one defined by the cone. -/ lemma to_ordered_smul (S : convex_cone 𝕜 E) (h : ∀ x y : E, x ≤ y ↔ y - x ∈ S) : ordered_smul 𝕜 E := ordered_smul.mk' begin intros x y z xy hz, rw [h (z • x) (z • y), ←smul_sub z y x], exact smul_mem S hz ((h x y).mp xy.le), end end ordered_add_comm_group end linear_ordered_field /-! ### Convex cones with extra properties -/ section ordered_semiring variables [ordered_semiring 𝕜] section add_comm_monoid variables [add_comm_monoid E] [has_smul 𝕜 E] (S : convex_cone 𝕜 E) /-- A convex cone is pointed if it includes `0`. -/ def pointed (S : convex_cone 𝕜 E) : Prop := (0 : E) ∈ S /-- A convex cone is blunt if it doesn't include `0`. -/ def blunt (S : convex_cone 𝕜 E) : Prop := (0 : E) ∉ S lemma pointed_iff_not_blunt (S : convex_cone 𝕜 E) : S.pointed ↔ ¬S.blunt := ⟨λ h₁ h₂, h₂ h₁, not_not.mp⟩ lemma blunt_iff_not_pointed (S : convex_cone 𝕜 E) : S.blunt ↔ ¬S.pointed := by rw [pointed_iff_not_blunt, not_not] lemma pointed.mono {S T : convex_cone 𝕜 E} (h : S ≤ T) : S.pointed → T.pointed := @h _ lemma blunt.anti {S T : convex_cone 𝕜 E} (h : T ≤ S) : S.blunt → T.blunt := (∘ @@h) end add_comm_monoid section add_comm_group variables [add_comm_group E] [has_smul 𝕜 E] (S : convex_cone 𝕜 E) /-- A convex cone is flat if it contains some nonzero vector `x` and its opposite `-x`. -/ def flat : Prop := ∃ x ∈ S, x ≠ (0 : E) ∧ -x ∈ S /-- A convex cone is salient if it doesn't include `x` and `-x` for any nonzero `x`. -/ def salient : Prop := ∀ x ∈ S, x ≠ (0 : E) → -x ∉ S lemma salient_iff_not_flat (S : convex_cone 𝕜 E) : S.salient ↔ ¬S.flat := begin split, { rintros h₁ ⟨x, xs, H₁, H₂⟩, exact h₁ x xs H₁ H₂ }, { intro h, unfold flat at h, push_neg at h, exact h } end lemma flat.mono {S T : convex_cone 𝕜 E} (h : S ≤ T) : S.flat → T.flat | ⟨x, hxS, hx, hnxS⟩ := ⟨x, h hxS, hx, h hnxS⟩ lemma salient.anti {S T : convex_cone 𝕜 E} (h : T ≤ S) : S.salient → T.salient := λ hS x hxT hx hnT, hS x (h hxT) hx (h hnT) /-- A flat cone is always pointed (contains `0`). -/ lemma flat.pointed {S : convex_cone 𝕜 E} (hS : S.flat) : S.pointed := begin obtain ⟨x, hx, _, hxneg⟩ := hS, rw [pointed, ←add_neg_self x], exact add_mem S hx hxneg, end /-- A blunt cone (one not containing `0`) is always salient. -/ lemma blunt.salient {S : convex_cone 𝕜 E} : S.blunt → S.salient := begin rw [salient_iff_not_flat, blunt_iff_not_pointed], exact mt flat.pointed, end /-- A pointed convex cone defines a preorder. -/ def to_preorder (h₁ : S.pointed) : preorder E := { le := λ x y, y - x ∈ S, le_refl := λ x, by change x - x ∈ S; rw [sub_self x]; exact h₁, le_trans := λ x y z xy zy, by simpa using add_mem S zy xy } /-- A pointed and salient cone defines a partial order. -/ def to_partial_order (h₁ : S.pointed) (h₂ : S.salient) : partial_order E := { le_antisymm := begin intros a b ab ba, by_contradiction h, have h' : b - a ≠ 0 := λ h'', h (eq_of_sub_eq_zero h'').symm, have H := h₂ (b-a) ab h', rw neg_sub b a at H, exact H ba, end, ..to_preorder S h₁ } /-- A pointed and salient cone defines an `ordered_add_comm_group`. -/ def to_ordered_add_comm_group (h₁ : S.pointed) (h₂ : S.salient) : ordered_add_comm_group E := { add_le_add_left := begin intros a b hab c, change c + b - (c + a) ∈ S, rw add_sub_add_left_eq_sub, exact hab, end, ..to_partial_order S h₁ h₂, ..show add_comm_group E, by apply_instance } end add_comm_group end ordered_semiring /-! ### Positive cone of an ordered module -/ section positive_cone variables (𝕜 E) [ordered_semiring 𝕜] [ordered_add_comm_group E] [module 𝕜 E] [ordered_smul 𝕜 E] /-- The positive cone is the convex cone formed by the set of nonnegative elements in an ordered module. -/ def positive : convex_cone 𝕜 E := { carrier := set.Ici 0, smul_mem' := λ c hc x (hx : _ ≤ _), smul_nonneg hc.le hx, add_mem' := λ x (hx : _ ≤ _) y (hy : _ ≤ _), add_nonneg hx hy } @[simp] lemma mem_positive {x : E} : x ∈ positive 𝕜 E ↔ 0 ≤ x := iff.rfl @[simp] lemma coe_positive : ↑(positive 𝕜 E) = set.Ici (0 : E) := rfl /-- The positive cone of an ordered module is always salient. -/ lemma salient_positive : salient (positive 𝕜 E) := λ x xs hx hx', lt_irrefl (0 : E) (calc 0 < x : lt_of_le_of_ne xs hx.symm ... ≤ x + (-x) : le_add_of_nonneg_right hx' ... = 0 : add_neg_self x) /-- The positive cone of an ordered module is always pointed. -/ lemma pointed_positive : pointed (positive 𝕜 E) := le_refl 0 /-- The cone of strictly positive elements. Note that this naming diverges from the mathlib convention of `pos` and `nonneg` due to "positive cone" (`convex_cone.positive`) being established terminology for the non-negative elements. -/ def strictly_positive : convex_cone 𝕜 E := { carrier := set.Ioi 0, smul_mem' := λ c hc x (hx : _ < _), smul_pos hc hx, add_mem' := λ x hx y hy, add_pos hx hy } @[simp] lemma mem_strictly_positive {x : E} : x ∈ strictly_positive 𝕜 E ↔ 0 < x := iff.rfl @[simp] lemma coe_strictly_positive : ↑(strictly_positive 𝕜 E) = set.Ioi (0 : E) := rfl lemma positive_le_strictly_positive : strictly_positive 𝕜 E ≤ positive 𝕜 E := λ x, le_of_lt /-- The strictly positive cone of an ordered module is always salient. -/ lemma salient_strictly_positive : salient (strictly_positive 𝕜 E) := (salient_positive 𝕜 E).anti $ positive_le_strictly_positive 𝕜 E /-- The strictly positive cone of an ordered module is always blunt. -/ lemma blunt_strictly_positive : blunt (strictly_positive 𝕜 E) := lt_irrefl 0 end positive_cone end convex_cone /-! ### Cone over a convex set -/ section cone_from_convex variables [linear_ordered_field 𝕜] [add_comm_group E] [module 𝕜 E] namespace convex /-- The set of vectors proportional to those in a convex set forms a convex cone. -/ def to_cone (s : set E) (hs : convex 𝕜 s) : convex_cone 𝕜 E := begin apply convex_cone.mk (⋃ (c : 𝕜) (H : 0 < c), c • s); simp only [mem_Union, mem_smul_set], { rintros c c_pos _ ⟨c', c'_pos, x, hx, rfl⟩, exact ⟨c * c', mul_pos c_pos c'_pos, x, hx, (smul_smul _ _ _).symm⟩ }, { rintros _ ⟨cx, cx_pos, x, hx, rfl⟩ _ ⟨cy, cy_pos, y, hy, rfl⟩, have : 0 < cx + cy, from add_pos cx_pos cy_pos, refine ⟨_, this, _, convex_iff_div.1 hs hx hy cx_pos.le cy_pos.le this, _⟩, simp only [smul_add, smul_smul, mul_div_assoc', mul_div_cancel_left _ this.ne'] } end variables {s : set E} (hs : convex 𝕜 s) {x : E} lemma mem_to_cone : x ∈ hs.to_cone s ↔ ∃ (c : 𝕜), 0 < c ∧ ∃ y ∈ s, c • y = x := by simp only [to_cone, convex_cone.mem_mk, mem_Union, mem_smul_set, eq_comm, exists_prop] lemma mem_to_cone' : x ∈ hs.to_cone s ↔ ∃ (c : 𝕜), 0 < c ∧ c • x ∈ s := begin refine hs.mem_to_cone.trans ⟨_, _⟩, { rintros ⟨c, hc, y, hy, rfl⟩, exact ⟨c⁻¹, inv_pos.2 hc, by rwa [smul_smul, inv_mul_cancel hc.ne', one_smul]⟩ }, { rintros ⟨c, hc, hcx⟩, exact ⟨c⁻¹, inv_pos.2 hc, _, hcx, by rw [smul_smul, inv_mul_cancel hc.ne', one_smul]⟩ } end lemma subset_to_cone : s ⊆ hs.to_cone s := λ x hx, hs.mem_to_cone'.2 ⟨1, zero_lt_one, by rwa one_smul⟩ /-- `hs.to_cone s` is the least cone that includes `s`. -/ lemma to_cone_is_least : is_least { t : convex_cone 𝕜 E | s ⊆ t } (hs.to_cone s) := begin refine ⟨hs.subset_to_cone, λ t ht x hx, _⟩, rcases hs.mem_to_cone.1 hx with ⟨c, hc, y, hy, rfl⟩, exact t.smul_mem hc (ht hy) end lemma to_cone_eq_Inf : hs.to_cone s = Inf { t : convex_cone 𝕜 E | s ⊆ t } := hs.to_cone_is_least.is_glb.Inf_eq.symm end convex lemma convex_hull_to_cone_is_least (s : set E) : is_least {t : convex_cone 𝕜 E | s ⊆ t} ((convex_convex_hull 𝕜 s).to_cone _) := begin convert (convex_convex_hull 𝕜 s).to_cone_is_least, ext t, exact ⟨λ h, convex_hull_min h t.convex, (subset_convex_hull 𝕜 s).trans⟩, end lemma convex_hull_to_cone_eq_Inf (s : set E) : (convex_convex_hull 𝕜 s).to_cone _ = Inf {t : convex_cone 𝕜 E | s ⊆ t} := eq.symm $ is_glb.Inf_eq $ is_least.is_glb $ convex_hull_to_cone_is_least s end cone_from_convex /-! ### M. Riesz extension theorem Given a convex cone `s` in a vector space `E`, a submodule `p`, and a linear `f : p → ℝ`, assume that `f` is nonnegative on `p ∩ s` and `p + s = E`. Then there exists a globally defined linear function `g : E → ℝ` that agrees with `f` on `p`, and is nonnegative on `s`. We prove this theorem using Zorn's lemma. `riesz_extension.step` is the main part of the proof. It says that if the domain `p` of `f` is not the whole space, then `f` can be extended to a larger subspace `p ⊔ span ℝ {y}` without breaking the non-negativity condition. In `riesz_extension.exists_top` we use Zorn's lemma to prove that we can extend `f` to a linear map `g` on `⊤ : submodule E`. Mathematically this is the same as a linear map on `E` but in Lean `⊤ : submodule E` is isomorphic but is not equal to `E`. In `riesz_extension` we use this isomorphism to prove the theorem. -/ variables [add_comm_group E] [module ℝ E] namespace riesz_extension open submodule variables (s : convex_cone ℝ E) (f : E →ₗ.[ℝ] ℝ) /-- Induction step in M. Riesz extension theorem. Given a convex cone `s` in a vector space `E`, a partially defined linear map `f : f.domain → ℝ`, assume that `f` is nonnegative on `f.domain ∩ p` and `p + s = E`. If `f` is not defined on the whole `E`, then we can extend it to a larger submodule without breaking the non-negativity condition. -/ lemma step (nonneg : ∀ x : f.domain, (x : E) ∈ s → 0 ≤ f x) (dense : ∀ y, ∃ x : f.domain, (x : E) + y ∈ s) (hdom : f.domain ≠ ⊤) : ∃ g, f < g ∧ ∀ x : g.domain, (x : E) ∈ s → 0 ≤ g x := begin obtain ⟨y, -, hy⟩ : ∃ (y : E) (h : y ∈ ⊤), y ∉ f.domain, { exact @set_like.exists_of_lt (submodule ℝ E) _ _ _ _ (lt_top_iff_ne_top.2 hdom) }, obtain ⟨c, le_c, c_le⟩ : ∃ c, (∀ x : f.domain, -(x:E) - y ∈ s → f x ≤ c) ∧ (∀ x : f.domain, (x:E) + y ∈ s → c ≤ f x), { set Sp := f '' {x : f.domain | (x:E) + y ∈ s}, set Sn := f '' {x : f.domain | -(x:E) - y ∈ s}, suffices : (upper_bounds Sn ∩ lower_bounds Sp).nonempty, by simpa only [set.nonempty, upper_bounds, lower_bounds, ball_image_iff] using this, refine exists_between_of_forall_le (nonempty.image f _) (nonempty.image f (dense y)) _, { rcases (dense (-y)) with ⟨x, hx⟩, rw [← neg_neg x, add_subgroup_class.coe_neg, ← sub_eq_add_neg] at hx, exact ⟨_, hx⟩ }, rintros a ⟨xn, hxn, rfl⟩ b ⟨xp, hxp, rfl⟩, have := s.add_mem hxp hxn, rw [add_assoc, add_sub_cancel'_right, ← sub_eq_add_neg, ← add_subgroup_class.coe_sub] at this, replace := nonneg _ this, rwa [f.map_sub, sub_nonneg] at this }, have hy' : y ≠ 0, from λ hy₀, hy (hy₀.symm ▸ zero_mem _), refine ⟨f.sup_span_singleton y (-c) hy, _, _⟩, { refine lt_iff_le_not_le.2 ⟨f.left_le_sup _ _, λ H, _⟩, replace H := linear_pmap.domain_mono.monotone H, rw [linear_pmap.domain_sup_span_singleton, sup_le_iff, span_le, singleton_subset_iff] at H, exact hy H.2 }, { rintros ⟨z, hz⟩ hzs, rcases mem_sup.1 hz with ⟨x, hx, y', hy', rfl⟩, rcases mem_span_singleton.1 hy' with ⟨r, rfl⟩, simp only [subtype.coe_mk] at hzs, erw [linear_pmap.sup_span_singleton_apply_mk _ _ _ _ _ hx, smul_neg, ← sub_eq_add_neg, sub_nonneg], rcases lt_trichotomy r 0 with hr|hr|hr, { have : -(r⁻¹ • x) - y ∈ s, by rwa [← s.smul_mem_iff (neg_pos.2 hr), smul_sub, smul_neg, neg_smul, neg_neg, smul_smul, mul_inv_cancel hr.ne, one_smul, sub_eq_add_neg, neg_smul, neg_neg], replace := le_c (r⁻¹ • ⟨x, hx⟩) this, rwa [← mul_le_mul_left (neg_pos.2 hr), neg_mul, neg_mul, neg_le_neg_iff, f.map_smul, smul_eq_mul, ← mul_assoc, mul_inv_cancel hr.ne, one_mul] at this }, { subst r, simp only [zero_smul, add_zero] at hzs ⊢, apply nonneg, exact hzs }, { have : r⁻¹ • x + y ∈ s, by rwa [← s.smul_mem_iff hr, smul_add, smul_smul, mul_inv_cancel hr.ne', one_smul], replace := c_le (r⁻¹ • ⟨x, hx⟩) this, rwa [← mul_le_mul_left hr, f.map_smul, smul_eq_mul, ← mul_assoc, mul_inv_cancel hr.ne', one_mul] at this } } end theorem exists_top (p : E →ₗ.[ℝ] ℝ) (hp_nonneg : ∀ x : p.domain, (x : E) ∈ s → 0 ≤ p x) (hp_dense : ∀ y, ∃ x : p.domain, (x : E) + y ∈ s) : ∃ q ≥ p, q.domain = ⊤ ∧ ∀ x : q.domain, (x : E) ∈ s → 0 ≤ q x := begin replace hp_nonneg : p ∈ { p | _ }, by { rw mem_set_of_eq, exact hp_nonneg }, obtain ⟨q, hqs, hpq, hq⟩ := zorn_nonempty_partial_order₀ _ _ _ hp_nonneg, { refine ⟨q, hpq, _, hqs⟩, contrapose! hq, rcases step s q hqs _ hq with ⟨r, hqr, hr⟩, { exact ⟨r, hr, hqr.le, hqr.ne'⟩ }, { exact λ y, let ⟨x, hx⟩ := hp_dense y in ⟨of_le hpq.left x, hx⟩ } }, { intros c hcs c_chain y hy, clear hp_nonneg hp_dense p, have cne : c.nonempty := ⟨y, hy⟩, refine ⟨linear_pmap.Sup c c_chain.directed_on, _, λ _, linear_pmap.le_Sup c_chain.directed_on⟩, rintros ⟨x, hx⟩ hxs, have hdir : directed_on (≤) (linear_pmap.domain '' c), from directed_on_image.2 (c_chain.directed_on.mono linear_pmap.domain_mono.monotone), rcases (mem_Sup_of_directed (cne.image _) hdir).1 hx with ⟨_, ⟨f, hfc, rfl⟩, hfx⟩, have : f ≤ linear_pmap.Sup c c_chain.directed_on, from linear_pmap.le_Sup _ hfc, convert ← hcs hfc ⟨x, hfx⟩ hxs, apply this.2, refl } end end riesz_extension /-- M. **Riesz extension theorem**: given a convex cone `s` in a vector space `E`, a submodule `p`, and a linear `f : p → ℝ`, assume that `f` is nonnegative on `p ∩ s` and `p + s = E`. Then there exists a globally defined linear function `g : E → ℝ` that agrees with `f` on `p`, and is nonnegative on `s`. -/ theorem riesz_extension (s : convex_cone ℝ E) (f : E →ₗ.[ℝ] ℝ) (nonneg : ∀ x : f.domain, (x : E) ∈ s → 0 ≤ f x) (dense : ∀ y, ∃ x : f.domain, (x : E) + y ∈ s) : ∃ g : E →ₗ[ℝ] ℝ, (∀ x : f.domain, g x = f x) ∧ (∀ x ∈ s, 0 ≤ g x) := begin rcases riesz_extension.exists_top s f nonneg dense with ⟨⟨g_dom, g⟩, ⟨hpg, hfg⟩, htop, hgs⟩, clear hpg, refine ⟨g ∘ₗ ↑(linear_equiv.of_top _ htop).symm, _, _⟩; simp only [comp_apply, linear_equiv.coe_coe, linear_equiv.of_top_symm_apply], { exact λ x, (hfg (submodule.coe_mk _ _).symm).symm }, { exact λ x hx, hgs ⟨x, _⟩ hx } end /-- **Hahn-Banach theorem**: if `N : E → ℝ` is a sublinear map, `f` is a linear map defined on a subspace of `E`, and `f x ≤ N x` for all `x` in the domain of `f`, then `f` can be extended to the whole space to a linear map `g` such that `g x ≤ N x` for all `x`. -/ theorem exists_extension_of_le_sublinear (f : E →ₗ.[ℝ] ℝ) (N : E → ℝ) (N_hom : ∀ (c : ℝ), 0 < c → ∀ x, N (c • x) = c * N x) (N_add : ∀ x y, N (x + y) ≤ N x + N y) (hf : ∀ x : f.domain, f x ≤ N x) : ∃ g : E →ₗ[ℝ] ℝ, (∀ x : f.domain, g x = f x) ∧ (∀ x, g x ≤ N x) := begin let s : convex_cone ℝ (E × ℝ) := { carrier := {p : E × ℝ | N p.1 ≤ p.2 }, smul_mem' := λ c hc p hp, calc N (c • p.1) = c * N p.1 : N_hom c hc p.1 ... ≤ c * p.2 : mul_le_mul_of_nonneg_left hp hc.le, add_mem' := λ x hx y hy, (N_add _ _).trans (add_le_add hx hy) }, obtain ⟨g, g_eq, g_nonneg⟩ := riesz_extension s ((-f).coprod (linear_map.id.to_pmap ⊤)) _ _; try { simp only [linear_pmap.coprod_apply, to_pmap_apply, id_apply, linear_pmap.neg_apply, ← sub_eq_neg_add, sub_nonneg, subtype.coe_mk] at * }, replace g_eq : ∀ (x : f.domain) (y : ℝ), g (x, y) = y - f x, { intros x y, simpa only [subtype.coe_mk, subtype.coe_eta] using g_eq ⟨(x, y), ⟨x.2, trivial⟩⟩ }, { refine ⟨-g.comp (inl ℝ E ℝ), _, _⟩; simp only [neg_apply, inl_apply, comp_apply], { intro x, simp [g_eq x 0] }, { intro x, have A : (x, N x) = (x, 0) + (0, N x), by simp, have B := g_nonneg ⟨x, N x⟩ (le_refl (N x)), rw [A, map_add, ← neg_le_iff_add_nonneg'] at B, have C := g_eq 0 (N x), simp only [submodule.coe_zero, f.map_zero, sub_zero] at C, rwa ← C } }, { exact λ x hx, le_trans (hf _) hx }, { rintros ⟨x, y⟩, refine ⟨⟨(0, N x - y), ⟨f.domain.zero_mem, trivial⟩⟩, _⟩, simp only [convex_cone.mem_mk, mem_set_of_eq, subtype.coe_mk, prod.fst_add, prod.snd_add, zero_add, sub_add_cancel] } end /-! ### The dual cone -/ section dual variables {H : Type*} [inner_product_space ℝ H] (s t : set H) open_locale real_inner_product_space /-- The dual cone is the cone consisting of all points `y` such that for all points `x` in a given set `0 ≤ ⟪ x, y ⟫`. -/ def set.inner_dual_cone (s : set H) : convex_cone ℝ H := { carrier := { y | ∀ x ∈ s, 0 ≤ ⟪ x, y ⟫ }, smul_mem' := λ c hc y hy x hx, begin rw real_inner_smul_right, exact mul_nonneg hc.le (hy x hx) end, add_mem' := λ u hu v hv x hx, begin rw inner_add_right, exact add_nonneg (hu x hx) (hv x hx) end } @[simp] lemma mem_inner_dual_cone (y : H) (s : set H) : y ∈ s.inner_dual_cone ↔ ∀ x ∈ s, 0 ≤ ⟪ x, y ⟫ := iff.rfl @[simp] lemma inner_dual_cone_empty : (∅ : set H).inner_dual_cone = ⊤ := eq_top_iff.mpr $ λ x hy y, false.elim lemma inner_dual_cone_le_inner_dual_cone (h : t ⊆ s) : s.inner_dual_cone ≤ t.inner_dual_cone := λ y hy x hx, hy x (h hx) lemma pointed_inner_dual_cone : s.inner_dual_cone.pointed := λ x hx, by rw inner_zero_right /-- The inner dual cone of a singleton is given by the preimage of the positive cone under the linear map `λ y, ⟪x, y⟫`. -/ lemma inner_dual_cone_singleton (x : H) : ({x} : set H).inner_dual_cone = (convex_cone.positive ℝ ℝ).comap (innerₛₗ x) := convex_cone.ext $ λ i, forall_eq lemma inner_dual_cone_union (s t : set H) : (s ∪ t).inner_dual_cone = s.inner_dual_cone ⊓ t.inner_dual_cone := le_antisymm (le_inf (λ x hx y hy, hx _ $ or.inl hy) (λ x hx y hy, hx _ $ or.inr hy)) (λ x hx y, or.rec (hx.1 _) (hx.2 _)) lemma inner_dual_cone_insert (x : H) (s : set H) : (insert x s).inner_dual_cone = set.inner_dual_cone {x} ⊓ s.inner_dual_cone := by rw [insert_eq, inner_dual_cone_union] lemma inner_dual_cone_Union {ι : Sort*} (f : ι → set H) : (⋃ i, f i).inner_dual_cone = ⨅ i, (f i).inner_dual_cone := begin refine le_antisymm (le_infi $ λ i x hx y hy, hx _ $ mem_Union_of_mem _ hy) _, intros x hx y hy, rw [convex_cone.mem_infi] at hx, obtain ⟨j, hj⟩ := mem_Union.mp hy, exact hx _ _ hj, end lemma inner_dual_cone_sUnion (S : set (set H)) : (⋃₀ S).inner_dual_cone = Inf (set.inner_dual_cone '' S) := by simp_rw [Inf_image, sUnion_eq_bUnion, inner_dual_cone_Union] /-- The dual cone of `s` equals the intersection of dual cones of the points in `s`. -/ lemma inner_dual_cone_eq_Inter_inner_dual_cone_singleton : (s.inner_dual_cone : set H) = ⋂ i : s, (({i} : set H).inner_dual_cone : set H) := by rw [←convex_cone.coe_infi, ←inner_dual_cone_Union, Union_of_singleton_coe] lemma is_closed_inner_dual_cone : is_closed (s.inner_dual_cone : set H) := begin -- reduce the problem to showing that dual cone of a singleton `{x}` is closed rw inner_dual_cone_eq_Inter_inner_dual_cone_singleton, apply is_closed_Inter, intros x, -- the dual cone of a singleton `{x}` is the preimage of `[0, ∞)` under `inner x` have h : ↑({x} : set H).inner_dual_cone = (inner x : H → ℝ) ⁻¹' set.Ici 0, { rw [inner_dual_cone_singleton, convex_cone.coe_comap, convex_cone.coe_positive, innerₛₗ_apply_coe] }, -- the preimage is closed as `inner x` is continuous and `[0, ∞)` is closed rw h, exact is_closed_Ici.preimage (by continuity), end end dual
38c08e00be00d7e661eb2abc43ff3f079ab05513
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/data/bracket.lean
c0b544c455aedfab4ccb64b02f61ff04c932e4ab
[ "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
1,567
lean
/- Copyright (c) 2021 Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Lutz, Oliver Nash -/ /-! # Bracket Notation > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file provides notation which can be used for the Lie bracket, for the commutator of two subgroups, and for other similar operations. ## Main Definitions * `has_bracket L M` for a binary operation that takes something in `L` and something in `M` and produces something in `M`. Defining an instance of this structure gives access to the notation `⁅ ⁆` ## Notation We introduce the notation `⁅x, y⁆` for the `bracket` of any `has_bracket` structure. Note that these are the Unicode "square with quill" brackets rather than the usual square brackets. -/ /-- The has_bracket class has three intended uses: 1. for certain binary operations on structures, like the product `⁅x, y⁆` of two elements `x`, `y` in a Lie algebra or the commutator of two elements `x` and `y` in a group. 2. for certain actions of one structure on another, like the action `⁅x, m⁆` of an element `x` of a Lie algebra on an element `m` in one of its modules (analogous to `has_smul` in the associative setting). 3. for binary operations on substructures, like the commutator `⁅H, K⁆` of two subgroups `H` and `K` of a group. -/ class has_bracket (L M : Type*) := (bracket : L → M → M) notation `⁅`x`, `y`⁆` := has_bracket.bracket x y
41644d23a361aabda19b5319f3510c4e86a668f2
4b4a91d762ac3b6ef8f164899a6a26fc125eddd6
/src/level_3_another_perspective_on_actions.lean
4a430fe88167bbd0fafcee181819250ebbf76dd8
[ "Apache-2.0" ]
permissive
ImperialCollegeLondon/group-action-exercises
955ceba8edb7eba7b8916690083829d321909aee
197b1a0e53ec8d84bf3903c9ab5cddf615a44816
refs/heads/master
1,686,020,547,415
1,625,354,242,000
1,625,354,242,000
382,577,731
2
0
null
null
null
null
UTF-8
Lean
false
false
1,632
lean
/- Apache 2, because everyone else is doing it Written by Kevin Buzzard summer 2021 in his shed. Powered by `mathlib`, the leanprover-community, without which nothing would have happened. Thanks to Leo and everyone at Microsoft Research for Lean. -/ -- This imports all user tactics and a whole bunch of basic mathematics import tactic import group_theory.group_action.basic -- group actions import data.setoid.partition /-! # Level 3 : actions are certain group homomorphisms A mathematician might say: "to give a left action of G on S is to give a group homomorphism `G → Aut(S)`". This sentence is problematic but can be fixed. ## Introduction : saying what we mean by "to give X is to give Y" Two types `X` and `Y` can "represent the same data". For example if `S` is a type then the type of equivalence relations on `S` and the type of partitions of `S` are two ways of formalising the same mathematical idea. We formalise the idea that `X` and `Y` are somehow "the same" This sentence is problematic, because whilst it claims that there is some "canonical" construction between two things, it leaves implicit the actual construction. Global class field theory teaches us that sometimes there is more than one "canonical" way to normalise bijections. Lean would prefer, in simple cases like this, that we spell the bijection out. -/ /- ## Introduction We know what a mathematician means when they say "let G be a group" or "let S be a set/type". But what do they mean when they say "Assume G acts on S", or "assume S is a G-set"? Here is a precise answer. ## Section 2.1 : Definition of group actions
fa84e37078e5eda5b97a72df890f11b409bec885
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/analysis/normed_space/linear_isometry.lean
6db54d679028d8cc40ca35b0c4d18eaa102102f2
[ "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
25,128
lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Frédéric Dupuis, Heather Macbeth -/ import analysis.normed.group.basic import topology.algebra.module.basic import linear_algebra.basis /-! # (Semi-)linear isometries In this file we define `linear_isometry σ₁₂ E E₂` (notation: `E →ₛₗᵢ[σ₁₂] E₂`) to be a semilinear isometric embedding of `E` into `E₂` and `linear_isometry_equiv` (notation: `E ≃ₛₗᵢ[σ₁₂] E₂`) to be a semilinear isometric equivalence between `E` and `E₂`. The notation for the associated purely linear concepts is `E →ₗᵢ[R] E₂`, `E ≃ₗᵢ[R] E₂`, and `E →ₗᵢ⋆[R] E₂`, `E ≃ₗᵢ⋆[R] E₂` for the star-linear versions. We also prove some trivial lemmas and provide convenience constructors. Since a lot of elementary properties don't require `∥x∥ = 0 → x = 0` we start setting up the theory for `semi_normed_group` and we specialize to `normed_group` when needed. -/ open function set variables {R R₂ R₃ R₄ E E₂ E₃ E₄ F : Type*} [semiring R] [semiring R₂] [semiring R₃] [semiring R₄] {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R} {σ₁₃ : R →+* R₃} {σ₃₁ : R₃ →+* R} {σ₁₄ : R →+* R₄} {σ₄₁ : R₄ →+* R} {σ₂₃ : R₂ →+* R₃} {σ₃₂ : R₃ →+* R₂} {σ₂₄ : R₂ →+* R₄} {σ₄₂ : R₄ →+* R₂} {σ₃₄ : R₃ →+* R₄} {σ₄₃ : R₄ →+* R₃} [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂] [ring_hom_inv_pair σ₁₃ σ₃₁] [ring_hom_inv_pair σ₃₁ σ₁₃] [ring_hom_inv_pair σ₂₃ σ₃₂] [ring_hom_inv_pair σ₃₂ σ₂₃] [ring_hom_inv_pair σ₁₄ σ₄₁] [ring_hom_inv_pair σ₄₁ σ₁₄] [ring_hom_inv_pair σ₂₄ σ₄₂] [ring_hom_inv_pair σ₄₂ σ₂₄] [ring_hom_inv_pair σ₃₄ σ₄₃] [ring_hom_inv_pair σ₄₃ σ₃₄] [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃] [ring_hom_comp_triple σ₁₂ σ₂₄ σ₁₄] [ring_hom_comp_triple σ₂₃ σ₃₄ σ₂₄] [ring_hom_comp_triple σ₁₃ σ₃₄ σ₁₄] [ring_hom_comp_triple σ₃₂ σ₂₁ σ₃₁] [ring_hom_comp_triple σ₄₂ σ₂₁ σ₄₁] [ring_hom_comp_triple σ₄₃ σ₃₂ σ₄₂] [ring_hom_comp_triple σ₄₃ σ₃₁ σ₄₁] [semi_normed_group E] [semi_normed_group E₂] [semi_normed_group E₃] [semi_normed_group E₄] [module R E] [module R₂ E₂] [module R₃ E₃] [module R₄ E₄] [normed_group F] [module R F] /-- A `σ₁₂`-semilinear isometric embedding of a normed `R`-module into an `R₂`-module. -/ structure linear_isometry (σ₁₂ : R →+* R₂) (E E₂ : Type*) [semi_normed_group E] [semi_normed_group E₂] [module R E] [module R₂ E₂] extends E →ₛₗ[σ₁₂] E₂ := (norm_map' : ∀ x, ∥to_linear_map x∥ = ∥x∥) notation E ` →ₛₗᵢ[`:25 σ₁₂:25 `] `:0 E₂:0 := linear_isometry σ₁₂ E E₂ notation E ` →ₗᵢ[`:25 R:25 `] `:0 E₂:0 := linear_isometry (ring_hom.id R) E E₂ notation E ` →ₗᵢ⋆[`:25 R:25 `] `:0 E₂:0 := linear_isometry (star_ring_end R) E E₂ namespace linear_isometry /-- We use `f₁` when we need the domain to be a `normed_space`. -/ variables (f : E →ₛₗᵢ[σ₁₂] E₂) (f₁ : F →ₛₗᵢ[σ₁₂] E₂) lemma to_linear_map_injective : injective (to_linear_map : (E →ₛₗᵢ[σ₁₂] E₂) → (E →ₛₗ[σ₁₂] E₂)) | ⟨f, _⟩ ⟨g, _⟩ rfl := rfl @[simp] lemma to_linear_map_inj {f g : E →ₛₗᵢ[σ₁₂] E₂} : f.to_linear_map = g.to_linear_map ↔ f = g := to_linear_map_injective.eq_iff instance : add_monoid_hom_class (E →ₛₗᵢ[σ₁₂] E₂) E E₂ := { coe := λ e, e.to_fun, coe_injective' := λ f g h, to_linear_map_injective (fun_like.coe_injective h), map_add := λ f, map_add f.to_linear_map, map_zero := λ f, map_zero f.to_linear_map } /-- Helper instance for when there's too many metavariables to apply `to_fun.to_coe_fn` directly. -/ instance : has_coe_to_fun (E →ₛₗᵢ[σ₁₂] E₂) (λ _, E → E₂) := ⟨λ f, f.to_fun⟩ @[simp] lemma coe_to_linear_map : ⇑f.to_linear_map = f := rfl lemma coe_injective : @injective (E →ₛₗᵢ[σ₁₂] E₂) (E → E₂) coe_fn := fun_like.coe_injective @[ext] lemma ext {f g : E →ₛₗᵢ[σ₁₂] E₂} (h : ∀ x, f x = g x) : f = g := coe_injective $ funext h protected lemma congr_arg {f : E →ₛₗᵢ[σ₁₂] E₂} : Π {x x' : E}, x = x' → f x = f x' | _ _ rfl := rfl protected lemma congr_fun {f g : E →ₛₗᵢ[σ₁₂] E₂} (h : f = g) (x : E) : f x = g x := h ▸ rfl @[simp] lemma map_zero : f 0 = 0 := f.to_linear_map.map_zero @[simp] lemma map_add (x y : E) : f (x + y) = f x + f y := f.to_linear_map.map_add x y @[simp] lemma map_neg (x : E) : f (- x) = - f x := f.to_linear_map.map_neg x @[simp] lemma map_sub (x y : E) : f (x - y) = f x - f y := f.to_linear_map.map_sub x y @[simp] lemma map_smulₛₗ (c : R) (x : E) : f (c • x) = σ₁₂ c • f x := f.to_linear_map.map_smulₛₗ c x @[simp] lemma map_smul [module R E₂] (f : E →ₗᵢ[R] E₂) (c : R) (x : E) : f (c • x) = c • f x := f.to_linear_map.map_smul c x @[simp] lemma norm_map (x : E) : ∥f x∥ = ∥x∥ := f.norm_map' x @[simp] lemma nnnorm_map (x : E) : nnnorm (f x) = nnnorm x := nnreal.eq $ f.norm_map x protected lemma isometry : isometry f := f.to_linear_map.to_add_monoid_hom.isometry_of_norm f.norm_map @[simp] lemma is_complete_image_iff {s : set E} : is_complete (f '' s) ↔ is_complete s := is_complete_image_iff f.isometry.uniform_inducing lemma is_complete_map_iff [ring_hom_surjective σ₁₂] {p : submodule R E} : is_complete (p.map f.to_linear_map : set E₂) ↔ is_complete (p : set E) := f.is_complete_image_iff instance complete_space_map [ring_hom_surjective σ₁₂] (p : submodule R E) [complete_space p] : complete_space (p.map f.to_linear_map) := (f.is_complete_map_iff.2 $ complete_space_coe_iff_is_complete.1 ‹_›).complete_space_coe @[simp] lemma dist_map (x y : E) : dist (f x) (f y) = dist x y := f.isometry.dist_eq x y @[simp] lemma edist_map (x y : E) : edist (f x) (f y) = edist x y := f.isometry.edist_eq x y protected lemma injective : injective f₁ := f₁.isometry.injective @[simp] lemma map_eq_iff {x y : F} : f₁ x = f₁ y ↔ x = y := f₁.injective.eq_iff lemma map_ne {x y : F} (h : x ≠ y) : f₁ x ≠ f₁ y := f₁.injective.ne h protected lemma lipschitz : lipschitz_with 1 f := f.isometry.lipschitz protected lemma antilipschitz : antilipschitz_with 1 f := f.isometry.antilipschitz @[continuity] protected lemma continuous : continuous f := f.isometry.continuous lemma ediam_image (s : set E) : emetric.diam (f '' s) = emetric.diam s := f.isometry.ediam_image s lemma ediam_range : emetric.diam (range f) = emetric.diam (univ : set E) := f.isometry.ediam_range lemma diam_image (s : set E) : metric.diam (f '' s) = metric.diam s := f.isometry.diam_image s lemma diam_range : metric.diam (range f) = metric.diam (univ : set E) := f.isometry.diam_range /-- Interpret a linear isometry as a continuous linear map. -/ def to_continuous_linear_map : E →SL[σ₁₂] E₂ := ⟨f.to_linear_map, f.continuous⟩ lemma to_continuous_linear_map_injective : function.injective (to_continuous_linear_map : _ → E →SL[σ₁₂] E₂) := λ x y h, coe_injective (congr_arg _ h : ⇑x.to_continuous_linear_map = _) @[simp] lemma to_continuous_linear_map_inj {f g : E →ₛₗᵢ[σ₁₂] E₂} : f.to_continuous_linear_map = g.to_continuous_linear_map ↔ f = g := to_continuous_linear_map_injective.eq_iff @[simp] lemma coe_to_continuous_linear_map : ⇑f.to_continuous_linear_map = f := rfl @[simp] lemma comp_continuous_iff {α : Type*} [topological_space α] {g : α → E} : continuous (f ∘ g) ↔ continuous g := f.isometry.comp_continuous_iff /-- The identity linear isometry. -/ def id : E →ₗᵢ[R] E := ⟨linear_map.id, λ x, rfl⟩ @[simp] lemma coe_id : ((id : E →ₗᵢ[R] E) : E → E) = _root_.id := rfl @[simp] lemma id_apply (x : E) : (id : E →ₗᵢ[R] E) x = x := rfl @[simp] lemma id_to_linear_map : (id.to_linear_map : E →ₗ[R] E) = linear_map.id := rfl instance : inhabited (E →ₗᵢ[R] E) := ⟨id⟩ /-- Composition of linear isometries. -/ def comp (g : E₂ →ₛₗᵢ[σ₂₃] E₃) (f : E →ₛₗᵢ[σ₁₂] E₂) : E →ₛₗᵢ[σ₁₃] E₃ := ⟨g.to_linear_map.comp f.to_linear_map, λ x, (g.norm_map _).trans (f.norm_map _)⟩ include σ₁₃ @[simp] lemma coe_comp (g : E₂ →ₛₗᵢ[σ₂₃] E₃) (f : E →ₛₗᵢ[σ₁₂] E₂) : ⇑(g.comp f) = g ∘ f := rfl omit σ₁₃ @[simp] lemma id_comp : (id : E₂ →ₗᵢ[R₂] E₂).comp f = f := ext $ λ x, rfl @[simp] lemma comp_id : f.comp id = f := ext $ λ x, rfl include σ₁₃ σ₂₄ σ₁₄ lemma comp_assoc (f : E₃ →ₛₗᵢ[σ₃₄] E₄) (g : E₂ →ₛₗᵢ[σ₂₃] E₃) (h : E →ₛₗᵢ[σ₁₂] E₂) : (f.comp g).comp h = f.comp (g.comp h) := rfl omit σ₁₃ σ₂₄ σ₁₄ instance : monoid (E →ₗᵢ[R] E) := { one := id, mul := comp, mul_assoc := comp_assoc, one_mul := id_comp, mul_one := comp_id } @[simp] lemma coe_one : ((1 : E →ₗᵢ[R] E) : E → E) = _root_.id := rfl @[simp] lemma coe_mul (f g : E →ₗᵢ[R] E) : ⇑(f * g) = f ∘ g := rfl lemma one_def : (1 : E →ₗᵢ[R] E) = id := rfl lemma mul_def (f g : E →ₗᵢ[R] E) : (f * g : E →ₗᵢ[R] E) = f.comp g := rfl end linear_isometry /-- Construct a `linear_isometry` from a `linear_map` satisfying `isometry`. -/ def linear_map.to_linear_isometry (f : E →ₛₗ[σ₁₂] E₂) (hf : isometry f) : E →ₛₗᵢ[σ₁₂] E₂ := { norm_map' := by { simp_rw [←dist_zero_right, ←f.map_zero], exact λ x, hf.dist_eq x _ }, .. f } namespace submodule variables {R' : Type*} [ring R'] [module R' E] (p : submodule R' E) /-- `submodule.subtype` as a `linear_isometry`. -/ def subtypeₗᵢ : p →ₗᵢ[R'] E := ⟨p.subtype, λ x, rfl⟩ @[simp] lemma coe_subtypeₗᵢ : ⇑p.subtypeₗᵢ = p.subtype := rfl @[simp] lemma subtypeₗᵢ_to_linear_map : p.subtypeₗᵢ.to_linear_map = p.subtype := rfl /-- `submodule.subtype` as a `continuous_linear_map`. -/ def subtypeL : p →L[R'] E := p.subtypeₗᵢ.to_continuous_linear_map @[simp] lemma coe_subtypeL : (p.subtypeL : p →ₗ[R'] E) = p.subtype := rfl @[simp] lemma coe_subtypeL' : ⇑p.subtypeL = p.subtype := rfl @[simp] lemma range_subtypeL : p.subtypeL.range = p := range_subtype _ @[simp] lemma ker_subtypeL : p.subtypeL.ker = ⊥ := ker_subtype _ end submodule /-- A semilinear isometric equivalence between two normed vector spaces. -/ structure linear_isometry_equiv (σ₁₂ : R →+* R₂) {σ₂₁ : R₂ →+* R} [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂] (E E₂ : Type*) [semi_normed_group E] [semi_normed_group E₂] [module R E] [module R₂ E₂] extends E ≃ₛₗ[σ₁₂] E₂ := (norm_map' : ∀ x, ∥to_linear_equiv x∥ = ∥x∥) notation E ` ≃ₛₗᵢ[`:25 σ₁₂:25 `] `:0 E₂:0 := linear_isometry_equiv σ₁₂ E E₂ notation E ` ≃ₗᵢ[`:25 R:25 `] `:0 E₂:0 := linear_isometry_equiv (ring_hom.id R) E E₂ notation E ` ≃ₗᵢ⋆[`:25 R:25 `] `:0 E₂:0 := linear_isometry_equiv (star_ring_end R) E E₂ namespace linear_isometry_equiv variables (e : E ≃ₛₗᵢ[σ₁₂] E₂) include σ₂₁ lemma to_linear_equiv_injective : injective (to_linear_equiv : (E ≃ₛₗᵢ[σ₁₂] E₂) → (E ≃ₛₗ[σ₁₂] E₂)) | ⟨e, _⟩ ⟨_, _⟩ rfl := rfl @[simp] lemma to_linear_equiv_inj {f g : E ≃ₛₗᵢ[σ₁₂] E₂} : f.to_linear_equiv = g.to_linear_equiv ↔ f = g := to_linear_equiv_injective.eq_iff instance : add_monoid_hom_class (E ≃ₛₗᵢ[σ₁₂] E₂) E E₂ := { coe := λ e, e.to_fun, coe_injective' := λ f g h, to_linear_equiv_injective (fun_like.coe_injective h), map_add := λ f, map_add f.to_linear_equiv, map_zero := λ f, map_zero f.to_linear_equiv } /-- Helper instance for when there's too many metavariables to apply `to_fun.to_coe_fn` directly. -/ instance : has_coe_to_fun (E ≃ₛₗᵢ[σ₁₂] E₂) (λ _, E → E₂) := ⟨λ f, f.to_fun⟩ lemma coe_injective : @function.injective (E ≃ₛₗᵢ[σ₁₂] E₂) (E → E₂) coe_fn := fun_like.coe_injective @[simp] lemma coe_mk (e : E ≃ₛₗ[σ₁₂] E₂) (he : ∀ x, ∥e x∥ = ∥x∥) : ⇑(mk e he) = e := rfl @[simp] lemma coe_to_linear_equiv (e : E ≃ₛₗᵢ[σ₁₂] E₂) : ⇑e.to_linear_equiv = e := rfl @[ext] lemma ext {e e' : E ≃ₛₗᵢ[σ₁₂] E₂} (h : ∀ x, e x = e' x) : e = e' := to_linear_equiv_injective $ linear_equiv.ext h protected lemma congr_arg {f : E ≃ₛₗᵢ[σ₁₂] E₂} : Π {x x' : E}, x = x' → f x = f x' | _ _ rfl := rfl protected lemma congr_fun {f g : E ≃ₛₗᵢ[σ₁₂] E₂} (h : f = g) (x : E) : f x = g x := h ▸ rfl /-- Construct a `linear_isometry_equiv` from a `linear_equiv` and two inequalities: `∀ x, ∥e x∥ ≤ ∥x∥` and `∀ y, ∥e.symm y∥ ≤ ∥y∥`. -/ def of_bounds (e : E ≃ₛₗ[σ₁₂] E₂) (h₁ : ∀ x, ∥e x∥ ≤ ∥x∥) (h₂ : ∀ y, ∥e.symm y∥ ≤ ∥y∥) : E ≃ₛₗᵢ[σ₁₂] E₂ := ⟨e, λ x, le_antisymm (h₁ x) $ by simpa only [e.symm_apply_apply] using h₂ (e x)⟩ @[simp] lemma norm_map (x : E) : ∥e x∥ = ∥x∥ := e.norm_map' x /-- Reinterpret a `linear_isometry_equiv` as a `linear_isometry`. -/ def to_linear_isometry : E →ₛₗᵢ[σ₁₂] E₂ := ⟨e.1, e.2⟩ lemma to_linear_isometry_injective : function.injective (to_linear_isometry : _ → E →ₛₗᵢ[σ₁₂] E₂) := λ x y h, coe_injective (congr_arg _ h : ⇑x.to_linear_isometry = _) @[simp] lemma to_linear_isometry_inj {f g : E ≃ₛₗᵢ[σ₁₂] E₂} : f.to_linear_isometry = g.to_linear_isometry ↔ f = g := to_linear_isometry_injective.eq_iff @[simp] lemma coe_to_linear_isometry : ⇑e.to_linear_isometry = e := rfl protected lemma isometry : isometry e := e.to_linear_isometry.isometry /-- Reinterpret a `linear_isometry_equiv` as an `isometric`. -/ def to_isometric : E ≃ᵢ E₂ := ⟨e.to_linear_equiv.to_equiv, e.isometry⟩ lemma to_isometric_injective : function.injective (to_isometric : (E ≃ₛₗᵢ[σ₁₂] E₂) → E ≃ᵢ E₂) := λ x y h, coe_injective (congr_arg _ h : ⇑x.to_isometric = _) @[simp] lemma to_isometric_inj {f g : E ≃ₛₗᵢ[σ₁₂] E₂} : f.to_isometric = g.to_isometric ↔ f = g := to_isometric_injective.eq_iff @[simp] lemma coe_to_isometric : ⇑e.to_isometric = e := rfl lemma range_eq_univ (e : E ≃ₛₗᵢ[σ₁₂] E₂) : set.range e = set.univ := by { rw ← coe_to_isometric, exact isometric.range_eq_univ _, } /-- Reinterpret a `linear_isometry_equiv` as an `homeomorph`. -/ def to_homeomorph : E ≃ₜ E₂ := e.to_isometric.to_homeomorph lemma to_homeomorph_injective : function.injective (to_homeomorph : (E ≃ₛₗᵢ[σ₁₂] E₂) → E ≃ₜ E₂) := λ x y h, coe_injective (congr_arg _ h : ⇑x.to_homeomorph = _) @[simp] lemma to_homeomorph_inj {f g : E ≃ₛₗᵢ[σ₁₂] E₂} : f.to_homeomorph = g.to_homeomorph ↔ f = g := to_homeomorph_injective.eq_iff @[simp] lemma coe_to_homeomorph : ⇑e.to_homeomorph = e := rfl protected lemma continuous : continuous e := e.isometry.continuous protected lemma continuous_at {x} : continuous_at e x := e.continuous.continuous_at protected lemma continuous_on {s} : continuous_on e s := e.continuous.continuous_on protected lemma continuous_within_at {s x} : continuous_within_at e s x := e.continuous.continuous_within_at /-- Interpret a `linear_isometry_equiv` as a continuous linear equiv. -/ def to_continuous_linear_equiv : E ≃SL[σ₁₂] E₂ := { .. e.to_linear_isometry.to_continuous_linear_map, .. e.to_homeomorph } lemma to_continuous_linear_equiv_injective : function.injective (to_continuous_linear_equiv : _ → E ≃SL[σ₁₂] E₂) := λ x y h, coe_injective (congr_arg _ h : ⇑x.to_continuous_linear_equiv = _) @[simp] lemma to_continuous_linear_equiv_inj {f g : E ≃ₛₗᵢ[σ₁₂] E₂} : f.to_continuous_linear_equiv = g.to_continuous_linear_equiv ↔ f = g := to_continuous_linear_equiv_injective.eq_iff @[simp] lemma coe_to_continuous_linear_equiv : ⇑e.to_continuous_linear_equiv = e := rfl omit σ₂₁ variables (R E) /-- Identity map as a `linear_isometry_equiv`. -/ def refl : E ≃ₗᵢ[R] E := ⟨linear_equiv.refl R E, λ x, rfl⟩ variables {R E} instance : inhabited (E ≃ₗᵢ[R] E) := ⟨refl R E⟩ @[simp] lemma coe_refl : ⇑(refl R E) = id := rfl /-- The inverse `linear_isometry_equiv`. -/ def symm : E₂ ≃ₛₗᵢ[σ₂₁] E := ⟨e.to_linear_equiv.symm, λ x, (e.norm_map _).symm.trans $ congr_arg norm $ e.to_linear_equiv.apply_symm_apply x⟩ @[simp] lemma apply_symm_apply (x : E₂) : e (e.symm x) = x := e.to_linear_equiv.apply_symm_apply x @[simp] lemma symm_apply_apply (x : E) : e.symm (e x) = x := e.to_linear_equiv.symm_apply_apply x @[simp] lemma map_eq_zero_iff {x : E} : e x = 0 ↔ x = 0 := e.to_linear_equiv.map_eq_zero_iff @[simp] lemma symm_symm : e.symm.symm = e := ext $ λ x, rfl @[simp] lemma to_linear_equiv_symm : e.to_linear_equiv.symm = e.symm.to_linear_equiv := rfl @[simp] lemma to_isometric_symm : e.to_isometric.symm = e.symm.to_isometric := rfl @[simp] lemma to_homeomorph_symm : e.to_homeomorph.symm = e.symm.to_homeomorph := rfl include σ₃₁ σ₃₂ /-- Composition of `linear_isometry_equiv`s as a `linear_isometry_equiv`. -/ def trans (e' : E₂ ≃ₛₗᵢ[σ₂₃] E₃) : E ≃ₛₗᵢ[σ₁₃] E₃ := ⟨e.to_linear_equiv.trans e'.to_linear_equiv, λ x, (e'.norm_map _).trans (e.norm_map _)⟩ include σ₁₃ σ₂₁ @[simp] lemma coe_trans (e₁ : E ≃ₛₗᵢ[σ₁₂] E₂) (e₂ : E₂ ≃ₛₗᵢ[σ₂₃] E₃) : ⇑(e₁.trans e₂) = e₂ ∘ e₁ := rfl @[simp] lemma to_linear_equiv_trans (e' : E₂ ≃ₛₗᵢ[σ₂₃] E₃) : (e.trans e').to_linear_equiv = e.to_linear_equiv.trans e'.to_linear_equiv := rfl omit σ₁₃ σ₂₁ σ₃₁ σ₃₂ @[simp] lemma trans_refl : e.trans (refl R₂ E₂) = e := ext $ λ x, rfl @[simp] lemma refl_trans : (refl R E).trans e = e := ext $ λ x, rfl @[simp] lemma self_trans_symm : e.trans e.symm = refl R E := ext e.symm_apply_apply @[simp] lemma symm_trans_self : e.symm.trans e = refl R₂ E₂ := ext e.apply_symm_apply @[simp] lemma symm_comp_self : e.symm ∘ e = id := funext e.symm_apply_apply @[simp] lemma self_comp_symm : e ∘ e.symm = id := e.symm.symm_comp_self include σ₁₃ σ₂₁ σ₃₂ σ₃₁ @[simp] lemma coe_symm_trans (e₁ : E ≃ₛₗᵢ[σ₁₂] E₂) (e₂ : E₂ ≃ₛₗᵢ[σ₂₃] E₃) : ⇑(e₁.trans e₂).symm = e₁.symm ∘ e₂.symm := rfl include σ₁₄ σ₄₁ σ₄₂ σ₄₃ σ₂₄ lemma trans_assoc (eEE₂ : E ≃ₛₗᵢ[σ₁₂] E₂) (eE₂E₃ : E₂ ≃ₛₗᵢ[σ₂₃] E₃) (eE₃E₄ : E₃ ≃ₛₗᵢ[σ₃₄] E₄) : eEE₂.trans (eE₂E₃.trans eE₃E₄) = (eEE₂.trans eE₂E₃).trans eE₃E₄ := rfl omit σ₂₁ σ₃₁ σ₄₁ σ₃₂ σ₄₂ σ₄₃ σ₁₃ σ₂₄ σ₁₄ instance : group (E ≃ₗᵢ[R] E) := { mul := λ e₁ e₂, e₂.trans e₁, one := refl _ _, inv := symm, one_mul := trans_refl, mul_one := refl_trans, mul_assoc := λ _ _ _, trans_assoc _ _ _, mul_left_inv := self_trans_symm } @[simp] lemma coe_one : ⇑(1 : E ≃ₗᵢ[R] E) = id := rfl @[simp] lemma coe_mul (e e' : E ≃ₗᵢ[R] E) : ⇑(e * e') = e ∘ e' := rfl @[simp] lemma coe_inv (e : E ≃ₗᵢ[R] E) : ⇑(e⁻¹) = e.symm := rfl lemma one_def : (1 : E ≃ₗᵢ[R] E) = refl _ _ := rfl lemma mul_def (e e' : E ≃ₗᵢ[R] E) : (e * e' : E ≃ₗᵢ[R] E) = e'.trans e := rfl lemma inv_def (e : E ≃ₗᵢ[R] E) : (e⁻¹ : E ≃ₗᵢ[R] E) = e.symm := rfl include σ₂₁ /-- Reinterpret a `linear_isometry_equiv` as a `continuous_linear_equiv`. -/ instance : has_coe_t (E ≃ₛₗᵢ[σ₁₂] E₂) (E ≃SL[σ₁₂] E₂) := ⟨λ e, ⟨e.to_linear_equiv, e.continuous, e.to_isometric.symm.continuous⟩⟩ instance : has_coe_t (E ≃ₛₗᵢ[σ₁₂] E₂) (E →SL[σ₁₂] E₂) := ⟨λ e, ↑(e : E ≃SL[σ₁₂] E₂)⟩ @[simp] lemma coe_coe : ⇑(e : E ≃SL[σ₁₂] E₂) = e := rfl @[simp] lemma coe_coe' : ((e : E ≃SL[σ₁₂] E₂) : E →SL[σ₁₂] E₂) = e := rfl @[simp] lemma coe_coe'' : ⇑(e : E →SL[σ₁₂] E₂) = e := rfl omit σ₂₁ @[simp] lemma map_zero : e 0 = 0 := e.1.map_zero @[simp] lemma map_add (x y : E) : e (x + y) = e x + e y := e.1.map_add x y @[simp] lemma map_sub (x y : E) : e (x - y) = e x - e y := e.1.map_sub x y @[simp] lemma map_smulₛₗ (c : R) (x : E) : e (c • x) = σ₁₂ c • e x := e.1.map_smulₛₗ c x @[simp] lemma map_smul [module R E₂] {e : E ≃ₗᵢ[R] E₂} (c : R) (x : E) : e (c • x) = c • e x := e.1.map_smul c x @[simp] lemma nnnorm_map (x : E) : nnnorm (e x) = nnnorm x := e.to_linear_isometry.nnnorm_map x @[simp] lemma dist_map (x y : E) : dist (e x) (e y) = dist x y := e.to_linear_isometry.dist_map x y @[simp] lemma edist_map (x y : E) : edist (e x) (e y) = edist x y := e.to_linear_isometry.edist_map x y protected lemma bijective : bijective e := e.1.bijective protected lemma injective : injective e := e.1.injective protected lemma surjective : surjective e := e.1.surjective @[simp] lemma map_eq_iff {x y : E} : e x = e y ↔ x = y := e.injective.eq_iff lemma map_ne {x y : E} (h : x ≠ y) : e x ≠ e y := e.injective.ne h protected lemma lipschitz : lipschitz_with 1 e := e.isometry.lipschitz protected lemma antilipschitz : antilipschitz_with 1 e := e.isometry.antilipschitz @[simp] lemma ediam_image (s : set E) : emetric.diam (e '' s) = emetric.diam s := e.isometry.ediam_image s @[simp] lemma diam_image (s : set E) : metric.diam (e '' s) = metric.diam s := e.isometry.diam_image s variables {α : Type*} [topological_space α] @[simp] lemma comp_continuous_on_iff {f : α → E} {s : set α} : continuous_on (e ∘ f) s ↔ continuous_on f s := e.isometry.comp_continuous_on_iff @[simp] lemma comp_continuous_iff {f : α → E} : continuous (e ∘ f) ↔ continuous f := e.isometry.comp_continuous_iff instance complete_space_map (p : submodule R E) [complete_space p] : complete_space (p.map (e.to_linear_equiv : E →ₛₗ[σ₁₂] E₂)) := e.to_linear_isometry.complete_space_map p include σ₂₁ /-- Construct a linear isometry equiv from a surjective linear isometry. -/ noncomputable def of_surjective (f : F →ₛₗᵢ[σ₁₂] E₂) (hfr : function.surjective f) : F ≃ₛₗᵢ[σ₁₂] E₂ := { norm_map' := f.norm_map, .. linear_equiv.of_bijective f.to_linear_map f.injective hfr } @[simp] lemma coe_of_surjective (f : F →ₛₗᵢ[σ₁₂] E₂) (hfr : function.surjective f) : ⇑(linear_isometry_equiv.of_surjective f hfr) = f := by { ext, refl } omit σ₂₁ variables (R) /-- The negation operation on a normed space `E`, considered as a linear isometry equivalence. -/ def neg : E ≃ₗᵢ[R] E := { norm_map' := norm_neg, .. linear_equiv.neg R } variables {R} @[simp] lemma coe_neg : (neg R : E → E) = λ x, -x := rfl @[simp] lemma symm_neg : (neg R : E ≃ₗᵢ[R] E).symm = neg R := rfl variables (R E E₂ E₃) /-- The natural equivalence `(E × E₂) × E₃ ≃ E × (E₂ × E₃)` is a linear isometry. -/ noncomputable def prod_assoc [module R E₂] [module R E₃] : (E × E₂) × E₃ ≃ₗᵢ[R] E × E₂ × E₃ := { to_fun := equiv.prod_assoc E E₂ E₃, inv_fun := (equiv.prod_assoc E E₂ E₃).symm, map_add' := by simp, map_smul' := by simp, norm_map' := begin rintros ⟨⟨e, f⟩, g⟩, simp only [linear_equiv.coe_mk, equiv.prod_assoc_apply, prod.norm_def, max_assoc], end, .. equiv.prod_assoc E E₂ E₃, } @[simp] lemma coe_prod_assoc [module R E₂] [module R E₃] : (prod_assoc R E E₂ E₃ : (E × E₂) × E₃ → E × E₂ × E₃) = equiv.prod_assoc E E₂ E₃ := rfl @[simp] lemma coe_prod_assoc_symm [module R E₂] [module R E₃] : ((prod_assoc R E E₂ E₃).symm : E × E₂ × E₃ → (E × E₂) × E₃) = (equiv.prod_assoc E E₂ E₃).symm := rfl end linear_isometry_equiv /-- Two linear isometries are equal if they are equal on basis vectors. -/ lemma basis.ext_linear_isometry {ι : Type*} (b : basis ι R E) {f₁ f₂ : E →ₛₗᵢ[σ₁₂] E₂} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := linear_isometry.to_linear_map_injective $ b.ext h include σ₂₁ /-- Two linear isometric equivalences are equal if they are equal on basis vectors. -/ lemma basis.ext_linear_isometry_equiv {ι : Type*} (b : basis ι R E) {f₁ f₂ : E ≃ₛₗᵢ[σ₁₂] E₂} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := linear_isometry_equiv.to_linear_equiv_injective $ b.ext' h omit σ₂₁
eb314d11a927d05119008b46b5765da282215869
12ba6fe891179eac82e287c24c8812a046221563
/src/compressions/ij.lean
abddb39fa556f99ee8567b87061aad90b22840d1
[]
no_license
b-mehta/combinatorics
eca586b4cb7b5e1fd22ec3288f5a2cb4ed6ce4dd
2a8b30709d35f124f3fc9baa5652d231389e9f63
refs/heads/master
1,653,708,057,336
1,626,885,184,000
1,626,885,184,000
228,850,404
19
0
null
null
null
null
UTF-8
Lean
false
false
8,299
lean
/- ij compressions -/ import data.finset import shadows open finset variable {α : Type*} variables [decidable_eq α] namespace ij def compress (i j : α) (A : finset α) : finset α := if j ∈ A ∧ i ∉ A then insert i (A.erase j) else A lemma compressed_set (i j : α) {A : finset α} : ¬ (j ∈ compress i j A ∧ i ∉ compress i j A) := begin intro, rw compress at a, split_ifs at a, apply a.2, apply mem_insert_self, exact h a end lemma compress_idem (i j : α) (A : finset α) : compress i j (compress i j A) = compress i j A := begin rw compress, split_ifs, exfalso, apply compressed_set _ _ h, refl end @[reducible] def compress_remains (i j : α) (𝒜 : finset (finset α)) : finset (finset α) := 𝒜.filter (λ A, compress i j A ∈ 𝒜) @[reducible] def compress_motion (i j : α) (𝒜 : finset (finset α)) : finset (finset α) := (𝒜.filter (λ A, compress i j A ∉ 𝒜)).image (compress i j) def compress_family (i j : α) (𝒜 : finset (finset α)) : finset (finset α) := compress_motion i j 𝒜 ∪ compress_remains i j 𝒜 lemma mem_compress_remains (𝒜 : finset (finset α)) (i j : α) (A : finset α) : A ∈ compress_remains i j 𝒜 ↔ A ∈ 𝒜 ∧ compress i j A ∈ 𝒜 := by rw mem_filter lemma mem_compress_motion (𝒜 : finset (finset α)) (i j : α) (A : finset α) : A ∈ compress_motion i j 𝒜 ↔ A ∉ 𝒜 ∧ (∃ B ∈ 𝒜, compress i j B = A) := begin simp [compress_motion], split; rintro ⟨p, q, r⟩, exact ⟨r ▸ q.2, p, ⟨q.1, r⟩⟩, exact ⟨q, ⟨r.1, r.2.symm ▸ p⟩, r.2⟩, end lemma mem_compress (𝒜 : finset (finset α)) (i j : α) (A : finset α) : A ∈ compress_family i j 𝒜 ↔ (A ∉ 𝒜 ∧ (∃ B ∈ 𝒜, compress i j B = A)) ∨ (A ∈ 𝒜 ∧ compress i j A ∈ 𝒜) := by rw [compress_family, mem_union, mem_compress_remains, mem_compress_motion] lemma compress_disjoint (𝒜 : finset (finset α)) (i j : α) : disjoint (compress_motion i j 𝒜) (compress_remains i j 𝒜) := begin rw disjoint_left, intros A HA HB, rw mem_compress_remains at HB, rw mem_compress_motion at HA, exact HA.1 HB.1 end lemma inj_ish {i j : α} {A B : finset α} (hA : j ∈ A ∧ i ∉ A) (hB : j ∈ B ∧ i ∉ B) (Z : insert i (erase A j) = insert i (erase B j)) : A = B := begin ext x, by_cases h₁: (x=j), rw h₁, simp [hA, hB], by_cases h₂: (x=i), rw h₂, simp [hA, hB], rw ext at Z, replace Z := Z x, simp [mem_insert, mem_erase, h₁, h₂] at Z, assumption end lemma compressed_size (𝒜 : finset (finset α)) (i j : α) : (compress_family i j 𝒜).card = 𝒜.card := begin rw [compress_family, card_disjoint_union (compress_disjoint _ _ _), card_image_of_inj_on], rw [← card_disjoint_union, union_comm, filter_union_filter_neg_eq], rw [disjoint_iff_inter_eq_empty, inter_comm], apply filter_inter_filter_neg_eq, intros A HX Y HY Z, rw mem_filter at HX HY, rw compress at HX Z, split_ifs at HX Z, rw compress at HY Z, split_ifs at HY Z, exact inj_ish h h_1 Z, all_goals {tauto} end lemma insert_erase_comm {i j : α} {A : finset α} (h : i ≠ j) : insert i (erase A j) = erase (insert i A) j := begin simp only [ext, mem_insert, mem_erase], intro x, split; intro p, cases p, split, rw p, all_goals {tauto}, end lemma compress_moved {𝒜 : finset (finset α)} {i j : α} {A : finset α} (h₁ : A ∈ compress_family i j 𝒜) (h₂ : A ∉ 𝒜) : i ∈ A ∧ j ∉ A ∧ erase (insert j A) i ∈ 𝒜 := begin rw mem_compress at h₁, rcases h₁ with ⟨_, B, H, HB⟩ | _, rw compress at HB, split_ifs at HB, rw ← HB, refine ⟨mem_insert_self _ _, _, _⟩, rw mem_insert, intro, rcases a with rfl, tauto, exact not_mem_erase j B a, have: erase (insert j (insert i (erase B j))) i = B, rw [insert_erase_comm, insert_erase (mem_insert_of_mem h.1), erase_insert h.2], rintro rfl, tauto, rwa this, rw HB at H, tauto, tauto end lemma compress_held {𝒜 : finset (finset α)} {i j : α} {A : finset α} (h₁ : j ∈ A) (h₂ : A ∈ compress_family i j 𝒜) : A ∈ 𝒜 := begin rw mem_compress at h₂, rcases h₂ with ⟨_, B, H, HB⟩ | _, rw ← HB at h₁, rw compress at HB h₁, split_ifs at HB h₁, rw mem_insert at h₁, rcases h₁ with rfl | h₁, tauto, exfalso, exact not_mem_erase _ _ h₁, rwa ← HB, tauto end lemma compress_both {𝒜 : finset (finset α)} {i j : α} {A : finset α} (h₁ : A ∈ compress_family i j 𝒜) (h₂ : j ∈ A) (h₃ : i ∉ A) : erase (insert i A) j ∈ 𝒜 := begin have: A ∈ 𝒜, apply compress_held h₂ h₁, rw mem_compress at h₁, replace h₁ : compress i j A ∈ 𝒜, tauto, rw compress at h₁, have: j ∈ A ∧ i ∉ A := ⟨h₂, h₃⟩, split_ifs at h₁, rwa ← insert_erase_comm, intro, rw a at *, tauto, end lemma compression_reduces_shadow {𝒜 : finset (finset α)} {i j : α} : (∂ compress_family i j 𝒜).card ≤ (∂𝒜).card := begin set 𝒜' := compress_family i j 𝒜, suffices: (∂𝒜' \ ∂𝒜).card ≤ (∂𝒜 \ ∂𝒜').card, suffices z: card (∂𝒜' \ ∂𝒜 ∪ ∂𝒜' ∩ ∂𝒜) ≤ card (∂𝒜 \ ∂𝒜' ∪ ∂𝒜 ∩ ∂𝒜'), rwa [sdiff_union_inter, sdiff_union_inter] at z, rw [card_disjoint_union, card_disjoint_union, inter_comm], apply add_le_add_right ‹_›, any_goals { apply sdiff_inter_inter }, have q₁: ∀ B ∈ ∂𝒜' \ ∂𝒜, i ∈ B ∧ j ∉ B ∧ erase (insert j B) i ∈ ∂𝒜 \ ∂𝒜', intros B HB, obtain ⟨k, k'⟩: B ∈ ∂𝒜' ∧ B ∉ ∂𝒜 := mem_sdiff.1 HB, have m: ∀ y ∉ B, insert y B ∉ 𝒜, intros y _ _, apply k', rw mem_shadow', exact ⟨y, H, a⟩, rcases mem_shadow'.1 k with ⟨x, _, _⟩, have q := compress_moved ‹insert x B ∈ 𝒜'› (m _ ‹x ∉ B›), rw insert.comm at q, have: j ∉ B := q.2.1 ∘ mem_insert_of_mem, have: i ≠ j, rintro rfl, tauto, have: x ≠ i, intro a, rw a at *, rw [erase_insert] at q, exact m _ ‹j ∉ B› q.2.2, rw mem_insert, tauto, have: x ≠ j, intro a, rw a at q, exact q.2.1 (mem_insert_self _ _), have: i ∈ B := mem_of_mem_insert_of_ne q.1 ‹x ≠ i›.symm, refine ⟨‹_›, ‹_›, _⟩, rw mem_sdiff, split, rw mem_shadow', rw ← insert_erase_comm ‹x ≠ i› at q, exact ⟨x, λ a, ‹x ∉ B› (mem_of_mem_insert_of_ne (mem_of_mem_erase a) ‹x ≠ j›), q.2.2⟩, intro a, rw mem_shadow' at a, rcases a with ⟨y, yH, H⟩, have: y ≠ i, intro b, rw [b, insert_erase (mem_insert_of_mem ‹i ∈ B›)] at H, exact m _ ‹j ∉ B› (compress_held (mem_insert_self _ _) H), have: y ≠ j, simp [‹y ≠ i›, not_or_distrib] at yH, exact yH.1, have: y ∉ B, simp [‹y ≠ i›, ‹y ≠ j›] at yH, assumption, have: j ∈ insert y (erase (insert j B) i), simp [‹i ≠ j›.symm], have: i ∉ insert y (erase (insert j B) i), simp [‹y ≠ i›.symm], have := compress_both H ‹_› ‹_›, rw [insert.comm, ← insert_erase_comm ‹y ≠ j›, insert_erase (mem_insert_of_mem ‹i ∈ B›), erase_insert ‹j ∉ B›] at this, exact m _ ‹y ∉ B› ‹insert y B ∈ 𝒜›, set f := (λ (B : finset α), erase (insert j B) i), apply card_le_card_of_inj_on f, intros _ HB, exact (q₁ _ HB).2.2, intros B₁ HB₁ B₂ HB₂ f₁, have z₁ := q₁ B₁ HB₁, have z₂ := q₁ B₂ HB₂, have: j ≠ i := (ne_of_mem_of_not_mem z₁.1 z₁.2.1).symm, rw ← insert_erase_comm ‹j ≠ i› at z₁ z₂, apply inj_ish ⟨z₁.1, z₁.2.1⟩ ⟨z₂.1, z₂.2.1⟩, convert f₁, all_goals {rw insert_erase_comm ‹j ≠ i›} end end ij
e491f108bca7710b96ad47c4411d48a41bd3f992
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/structuralEqns.lean
4bcb423ec99ed4444cc24e3609ef7759f1c6be5f
[ "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
528
lean
import Lean open Lean open Lean.Meta def tst (declName : Name) : MetaM Unit := do IO.println (← getUnfoldEqnFor? declName) def foo (xs ys zs : List Nat) : List Nat := match (xs, ys) with | (xs', ys') => match zs with | z::zs => foo xs ys zs | _ => match ys' with | [] => [1] | _ => [2] #eval tst ``foo #check foo._unfold def bar (xs ys : List Nat) : List Nat := match xs ++ [], ys ++ [] with | xs', ys' => xs' ++ ys' #print bar -- should not contain either `let _discr` aux binding
cb7cd9f93b89d53239bd8ea5769d949de9031eb9
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/src/Lean/Elab/Macro.lean
cc72665f1e7f559734af79fb17031723d7c78a96
[ "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
1,950
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.MacroArgUtil namespace Lean.Elab.Command open Lean.Syntax open Lean.Parser.Term hiding macroArg open Lean.Parser.Command @[builtinCommandElab Lean.Parser.Command.macro] def elabMacro : CommandElab | `($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind macro%$tk$[:$prec?]? $[(name := $name?)]? $[(priority := $prio?)]? $args:macroArg* : $cat => $rhs) => -- exclude command prefix from synthetic position used for e.g. jumping to the macro definition withRef (mkNullNode #[tk, rhs]) do let prio ← liftMacroM <| evalOptPrio prio? let (stxParts, patArgs) := (← args.mapM expandMacroArg).unzip -- name let name ← match name? with | some name => pure name.getId | none => liftMacroM <| mkNameFromParserSyntax cat.getId (mkNullNode stxParts) /- The command `syntax [<kind>] ...` adds the current namespace to the syntax node kind. So, we must include current namespace when we create a pattern for the following `macro_rules` commands. -/ let pat := ⟨mkNode ((← getCurrNamespace) ++ name) patArgs⟩ let stxCmd ← `($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind syntax$[:$prec?]? (name := $(← mkIdentFromRef name)) (priority := $(quote prio):num) $[$stxParts]* : $cat) let rhs := rhs.raw let macroRulesCmd ← if rhs.getArgs.size == 1 then -- `rhs` is a `term` let rhs := ⟨rhs[0]⟩ `($[$doc?:docComment]? macro_rules | `($pat) => $rhs) else -- `rhs` is of the form `` `( $body ) `` let rhsBody := ⟨rhs[1]⟩ `($[$doc?:docComment]? macro_rules | `($pat) => `($rhsBody)) elabCommand <| mkNullNode #[stxCmd, macroRulesCmd] | _ => throwUnsupportedSyntax end Lean.Elab.Command
0a2f7df9b5cf86fd965fff6faca02ac622c65e44
f4bff2062c030df03d65e8b69c88f79b63a359d8
/src/game/sets/sets_level04.lean
17367803d21cad16cadd3cf8ff33091af433c3d8
[ "Apache-2.0" ]
permissive
adastra7470/real-number-game
776606961f52db0eb824555ed2f8e16f92216ea3
f9dcb7d9255a79b57e62038228a23346c2dc301b
refs/heads/master
1,669,221,575,893
1,594,669,800,000
1,594,669,800,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,402
lean
import game.sets.sets_level03 -- hide namespace xena -- hide open_locale classical -- hide variable X : Type --hide /- # Chapter 1 : Sets ## Level 4 -/ /- Axiom : ext_iff : A = B ↔ ∀ x : X, x ∈ A ↔ x ∈ B -/ /- To prove that two sets are equal, one needs to use the axiom of extensionality: two sets are equal if and only if they have the same elements. In Lean's maths library this axiom is called `ext_iff`. ``` lemma ext_diff : A = B ↔ ∀ x : X, x ∈ A ↔ x ∈ B ``` -/ /- Hint: A word on coding style After a `split` statement, one goal turns into two. A good programming style would be to use `{}` brackets to work on each goal individually, like this: ``` begin split, { insert, proof of, first goal }, { insert, proof of, second goal } end ``` This way you only ever have one goal to work on, and your code becomes easier to read. After `split` you might want to write ``` { sorry}, { sorry} ``` so that your code has no errors while you're working on it. -/ /- Hint : Stuck? To prove the theorem below, remember that you can use `split` to change the goal into two goals, corresponding to the left-right and right-left implication, respectively. For the first goal, after `intro h,` the equality of the two sets can be manipulated using `rw ext_iff`. -/ /- Hint: rewrite failures and the `simp_rw` tactic `rw` doesn't work "under a binder". In other words, if your goal is `⊢ ∀ (x : X), x ∈ B ↔ x ∈ A ∪ B` then `rw mem_union_iff` won't work! It's the `∀` which is blocking it. Either do `intro x` (and then the `rw` will work), or use a more powerful rewrite tactic called `simp_rw`, which will work -/ /- Lemma If $A$ and $B$ are sets of any type $X$, then $$ A \subseteq B \iff A \cup B = B.$$ -/ theorem subset_iff_union_eq (A : set X) (B : set X) : A ⊆ B ↔ B = A ∪ B := begin rw subset_iff, split, { intro h, rw ext_iff, -- can't rewrite under a binder simp_rw mem_union_iff, intro x, specialize h x, -- or replace h := h x, tauto! }, { intro h, intros x hA, rw h, rw mem_union_iff, tauto! } end --begin hide -- theorem subset_iff_union_eq' (A : set X) (B : set X) : A ⊆ B ↔ B = A ∪ B := -- begin -- rw subset_iff, -- rw ext_iff, -- apply forall_congr, -- intro x, -- rw mem_union_iff, -- tauto!, -- end --end hide end xena --hide
2b316563e7237fd0d94b1675f77827120df4b20b
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/pkg/misc/lakefile.lean
c4010eb6bb19b1bd98ac1e955b4a5f810a62b192
[ "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
79
lean
import Lake open System Lake DSL package misc @[default_target] lean_lib Misc
c650e43388868dc7a7b611f93481629149da985b
63abd62053d479eae5abf4951554e1064a4c45b4
/src/ring_theory/integral_closure.lean
3f30bcd8746081e7ac49ccab96bcc33ad5ac97e8
[ "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
21,769
lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import ring_theory.algebra_tower import ring_theory.polynomial.scale_roots /-! # Integral closure of a subring. If A is an R-algebra then `a : A` is integral over R if it is a root of a monic polynomial with coefficients in R. Enough theory is developed to prove that integral elements form a sub-R-algebra of A. ## Main definitions Let `R` be a `comm_ring` and let `A` be an R-algebra. * `ring_hom.is_integral_elem (f : R →+* A) (x : A)` : `x` is integral with respect to the map `f`, * `is_integral (x : A)` : `x` is integral over `R`, i.e., is a root of a monic polynomial with coefficients in `R`. * `integral_closure R A` : the integral closure of `R` in `A`, regarded as a sub-`R`-algebra of `A`. -/ open_locale classical open_locale big_operators open polynomial submodule section ring variables {R A : Type*} variables [comm_ring R] [ring A] /-- An element `x` of `A` is said to be integral over `R` with respect to `f` if it is a root of a monic polynomial `p : polynomial R` evaluated under `f` -/ def ring_hom.is_integral_elem (f : R →+* A) (x : A) := ∃ p : polynomial R, monic p ∧ eval₂ f x p = 0 /-- A ring homomorphism `f : R →+* A` is said to be integral if every element `A` is integral with respect to the map `f` -/ def ring_hom.is_integral (f : R →+* A) := ∀ x : A, f.is_integral_elem x variables [algebra R A] (R) /-- An element `x` of an algebra `A` over a commutative ring `R` is said to be *integral*, if it is a root of some monic polynomial `p : polynomial R`. Equivalently, the element is integral over `R` with respect to the induced `algebra_map` -/ def is_integral (x : A) : Prop := (algebra_map R A).is_integral_elem x variable (A) /-- An algebra is integral if every element of the extension is integral over the base ring -/ def algebra.is_integral : Prop := (algebra_map R A).is_integral variables {R A} theorem is_integral_algebra_map {x : R} : is_integral R (algebra_map R A x) := ⟨X - C x, monic_X_sub_C _, by simp⟩ theorem is_integral_of_noetherian (H : is_noetherian R A) (x : A) : is_integral R x := begin let leval : @linear_map R (polynomial R) A _ _ _ _ _ := (aeval x).to_linear_map, let D : ℕ → submodule R A := λ n, (degree_le R n).map leval, let M := well_founded.min (is_noetherian_iff_well_founded.1 H) (set.range D) ⟨_, ⟨0, rfl⟩⟩, have HM : M ∈ set.range D := well_founded.min_mem _ _ _, cases HM with N HN, have HM : ¬M < D (N+1) := well_founded.not_lt_min (is_noetherian_iff_well_founded.1 H) (set.range D) _ ⟨N+1, rfl⟩, rw ← HN at HM, have HN2 : D (N+1) ≤ D N := classical.by_contradiction (λ H, HM (lt_of_le_not_le (map_mono (degree_le_mono (with_bot.coe_le_coe.2 (nat.le_succ N)))) H)), have HN3 : leval (X^(N+1)) ∈ D N, { exact HN2 (mem_map_of_mem (mem_degree_le.2 (degree_X_pow_le _))) }, rcases HN3 with ⟨p, hdp, hpe⟩, refine ⟨X^(N+1) - p, monic_X_pow_sub (mem_degree_le.1 hdp), _⟩, show leval (X ^ (N + 1) - p) = 0, rw [linear_map.map_sub, hpe, sub_self] end theorem is_integral_of_submodule_noetherian (S : subalgebra R A) (H : is_noetherian R (S : submodule R A)) (x : A) (hx : x ∈ S) : is_integral R x := begin letI : algebra R S := S.algebra, letI : ring S := S.ring R A, suffices : is_integral R (⟨x, hx⟩ : S), { rcases this with ⟨p, hpm, hpx⟩, replace hpx := congr_arg subtype.val hpx, refine ⟨p, hpm, eq.trans _ hpx⟩, simp only [aeval_def, eval₂, finsupp.sum], rw ← p.support.sum_hom subtype.val, { refine finset.sum_congr rfl (λ n hn, _), change _ = _ * _, rw is_monoid_hom.map_pow coe, refl, split; intros; refl }, refine { map_add := _, map_zero := _ }; intros; refl }, refine is_integral_of_noetherian H ⟨x, hx⟩ end end ring section variables {R : Type*} {A : Type*} {B : Type*} variables [comm_ring R] [comm_ring A] [comm_ring B] variables [algebra R A] [algebra R B] theorem is_integral_alg_hom (f : A →ₐ[R] B) {x : A} (hx : is_integral R x) : is_integral R (f x) := let ⟨p, hp, hpx⟩ := hx in ⟨p, hp, by rw [← aeval_def, aeval_alg_hom_apply, aeval_def, hpx, f.map_zero]⟩ theorem is_integral_of_is_scalar_tower [algebra A B] [is_scalar_tower R A B] (x : B) (hx : is_integral R x) : is_integral A x := let ⟨p, hp, hpx⟩ := hx in ⟨p.map $ algebra_map R A, monic_map _ hp, by rw [← aeval_def, ← is_scalar_tower.aeval_apply, aeval_def, hpx]⟩ section local attribute [instance] subset.comm_ring algebra.of_is_subring theorem is_integral_of_subring {x : A} (T : set R) [is_subring T] (hx : is_integral T x) : is_integral R x := is_integral_of_is_scalar_tower x hx theorem is_integral_iff_is_integral_closure_finite {r : A} : is_integral R r ↔ ∃ s : set R, s.finite ∧ is_integral (ring.closure s) r := begin split; intro hr, { rcases hr with ⟨p, hmp, hpr⟩, refine ⟨_, set.finite_mem_finset _, p.restriction, subtype.eq hmp, _⟩, erw [← aeval_def, is_scalar_tower.aeval_apply _ R, map_restriction, aeval_def, hpr] }, rcases hr with ⟨s, hs, hsr⟩, exact is_integral_of_subring _ hsr end end theorem fg_adjoin_singleton_of_integral (x : A) (hx : is_integral R x) : (algebra.adjoin R ({x} : set A) : submodule R A).fg := begin rcases hx with ⟨f, hfm, hfx⟩, existsi finset.image ((^) x) (finset.range (nat_degree f + 1)), apply le_antisymm, { rw span_le, intros s hs, rw finset.mem_coe at hs, rcases finset.mem_image.1 hs with ⟨k, hk, rfl⟩, clear hk, exact is_submonoid.pow_mem (algebra.subset_adjoin (set.mem_singleton _)) }, intros r hr, change r ∈ algebra.adjoin R ({x} : set A) at hr, rw algebra.adjoin_singleton_eq_range at hr, rcases (aeval x).mem_range.mp hr with ⟨p, rfl⟩, rw ← mod_by_monic_add_div p hfm, rw ← aeval_def at hfx, rw [alg_hom.map_add, alg_hom.map_mul, hfx, zero_mul, add_zero], have : degree (p %ₘ f) ≤ degree f := degree_mod_by_monic_le p hfm, generalize_hyp : p %ₘ f = q at this ⊢, rw [← sum_C_mul_X_eq q, aeval_def, eval₂_sum, finsupp.sum], refine sum_mem _ (λ k hkq, _), rw [eval₂_mul, eval₂_C, eval₂_pow, eval₂_X, ← algebra.smul_def], refine smul_mem _ _ (subset_span _), rw finset.mem_coe, refine finset.mem_image.2 ⟨_, _, rfl⟩, rw [finset.mem_range, nat.lt_succ_iff], refine le_of_not_lt (λ hk, _), rw [degree_le_iff_coeff_zero] at this, rw [finsupp.mem_support_iff] at hkq, apply hkq, apply this, exact lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 hk) end theorem fg_adjoin_of_finite {s : set A} (hfs : s.finite) (his : ∀ x ∈ s, is_integral R x) : (algebra.adjoin R s : submodule R A).fg := set.finite.induction_on hfs (λ _, ⟨{1}, submodule.ext $ λ x, by { erw [algebra.adjoin_empty, finset.coe_singleton, ← one_eq_span, one_eq_map_top, map_top, linear_map.mem_range, algebra.mem_bot], refl }⟩) (λ a s has hs ih his, by rw [← set.union_singleton, algebra.adjoin_union_coe_submodule]; exact fg_mul _ _ (ih $ λ i hi, his i $ set.mem_insert_of_mem a hi) (fg_adjoin_singleton_of_integral _ $ his a $ set.mem_insert a s)) his theorem is_integral_of_mem_of_fg (S : subalgebra R A) (HS : (S : submodule R A).fg) (x : A) (hx : x ∈ S) : is_integral R x := begin cases HS with y hy, obtain ⟨lx, hlx1, hlx2⟩ : ∃ (l : A →₀ R) (H : l ∈ finsupp.supported R R ↑y), (finsupp.total A A R id) l = x, { rwa [←(@finsupp.mem_span_iff_total A A R _ _ _ id ↑y x), set.image_id ↑y, hy] }, have hyS : ∀ {p}, p ∈ y → p ∈ S := λ p hp, show p ∈ (S : submodule R A), by { rw ← hy, exact subset_span hp }, have : ∀ (jk : (↑(y.product y) : set (A × A))), jk.1.1 * jk.1.2 ∈ (S : submodule R A) := λ jk, S.mul_mem (hyS (finset.mem_product.1 jk.2).1) (hyS (finset.mem_product.1 jk.2).2), rw [← hy, ← set.image_id ↑y] at this, simp only [finsupp.mem_span_iff_total] at this, choose ly hly1 hly2, let S₀ : set R := ring.closure ↑(lx.frange ∪ finset.bind finset.univ (finsupp.frange ∘ ly)), refine is_integral_of_subring S₀ _, letI : comm_ring S₀ := @subtype.comm_ring _ _ _ ring.closure.is_subring, letI : algebra S₀ A := algebra.of_is_subring _, have : span S₀ (insert 1 ↑y : set A) * span S₀ (insert 1 ↑y : set A) ≤ span S₀ (insert 1 ↑y : set A), { rw span_mul_span, refine span_le.2 (λ z hz, _), rcases set.mem_mul.1 hz with ⟨p, q, rfl | hp, hq, rfl⟩, { rw one_mul, exact subset_span hq }, rcases hq with rfl | hq, { rw mul_one, exact subset_span (or.inr hp) }, erw ← hly2 ⟨(p, q), finset.mem_product.2 ⟨hp, hq⟩⟩, rw [finsupp.total_apply, finsupp.sum], refine (span S₀ (insert 1 ↑y : set A)).sum_mem (λ t ht, _), have : ly ⟨(p, q), finset.mem_product.2 ⟨hp, hq⟩⟩ t ∈ S₀ := ring.subset_closure (finset.mem_union_right _ $ finset.mem_bind.2 ⟨⟨(p, q), finset.mem_product.2 ⟨hp, hq⟩⟩, finset.mem_univ _, finsupp.mem_frange.2 ⟨finsupp.mem_support_iff.1 ht, _, rfl⟩⟩), change (⟨_, this⟩ : S₀) • t ∈ _, exact smul_mem _ _ (subset_span $ or.inr $ hly1 _ ht) }, haveI : is_subring (span S₀ (insert 1 ↑y : set A) : set A) := { one_mem := subset_span $ or.inl rfl, mul_mem := λ p q hp hq, this $ mul_mem_mul hp hq, zero_mem := (span S₀ (insert 1 ↑y : set A)).zero_mem, add_mem := λ _ _, (span S₀ (insert 1 ↑y : set A)).add_mem, neg_mem := λ _, (span S₀ (insert 1 ↑y : set A)).neg_mem }, have : span S₀ (insert 1 ↑y : set A) = algebra.adjoin S₀ (↑y : set A), { refine le_antisymm (span_le.2 $ set.insert_subset.2 ⟨(algebra.adjoin S₀ ↑y).one_mem, algebra.subset_adjoin⟩) (λ z hz, _), rw [subalgebra.mem_to_submodule, algebra.mem_adjoin_iff] at hz, rw ← submodule.mem_coe, refine ring.closure_subset (set.union_subset (set.range_subset_iff.2 $ λ t, _) (λ t ht, subset_span $ or.inr ht)) hz, rw algebra.algebra_map_eq_smul_one, exact smul_mem (span S₀ (insert 1 ↑y : set A)) _ (subset_span $ or.inl rfl) }, haveI : is_noetherian_ring ↥S₀ := is_noetherian_ring_closure _ (finset.finite_to_set _), refine is_integral_of_submodule_noetherian (algebra.adjoin S₀ ↑y) (is_noetherian_of_fg_of_noetherian _ ⟨insert 1 y, by rw [finset.coe_insert, this]⟩) _ _, rw [← hlx2, finsupp.total_apply, finsupp.sum], refine subalgebra.sum_mem _ (λ r hr, _), have : lx r ∈ S₀ := ring.subset_closure (finset.mem_union_left _ (finset.mem_image_of_mem _ hr)), change (⟨_, this⟩ : S₀) • r ∈ _, rw finsupp.mem_supported at hlx1, exact subalgebra.smul_mem _ (algebra.subset_adjoin $ hlx1 hr) _ end theorem is_integral_of_mem_closure {x y z : A} (hx : is_integral R x) (hy : is_integral R y) (hz : z ∈ ring.closure ({x, y} : set A)) : is_integral R z := begin have := fg_mul _ _ (fg_adjoin_singleton_of_integral x hx) (fg_adjoin_singleton_of_integral y hy), rw [← algebra.adjoin_union_coe_submodule, set.singleton_union] at this, exact is_integral_of_mem_of_fg (algebra.adjoin R {x, y}) this z (algebra.mem_adjoin_iff.2 $ ring.closure_mono (set.subset_union_right _ _) hz) end theorem is_integral_zero : is_integral R (0:A) := (algebra_map R A).map_zero ▸ is_integral_algebra_map theorem is_integral_one : is_integral R (1:A) := (algebra_map R A).map_one ▸ is_integral_algebra_map theorem is_integral_add {x y : A} (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x + y) := is_integral_of_mem_closure hx hy (is_add_submonoid.add_mem (ring.subset_closure (or.inl rfl)) (ring.subset_closure (or.inr rfl))) theorem is_integral_neg {x : A} (hx : is_integral R x) : is_integral R (-x) := is_integral_of_mem_closure hx hx (is_add_subgroup.neg_mem (ring.subset_closure (or.inl rfl))) theorem is_integral_sub {x y : A} (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x - y) := is_integral_add hx (is_integral_neg hy) theorem is_integral_mul {x y : A} (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x * y) := is_integral_of_mem_closure hx hy (is_submonoid.mul_mem (ring.subset_closure (or.inl rfl)) (ring.subset_closure (or.inr rfl))) variables (R A) /-- The integral closure of R in an R-algebra A. -/ def integral_closure : subalgebra R A := { carrier := { r | is_integral R r }, zero_mem' := is_integral_zero, one_mem' := is_integral_one, add_mem' := λ _ _, is_integral_add, mul_mem' := λ _ _, is_integral_mul, algebra_map_mem' := λ x, is_integral_algebra_map } theorem mem_integral_closure_iff_mem_fg {r : A} : r ∈ integral_closure R A ↔ ∃ M : subalgebra R A, (M : submodule R A).fg ∧ r ∈ M := ⟨λ hr, ⟨algebra.adjoin R {r}, fg_adjoin_singleton_of_integral _ hr, algebra.subset_adjoin rfl⟩, λ ⟨M, Hf, hrM⟩, is_integral_of_mem_of_fg M Hf _ hrM⟩ variables {R} {A} /-- Mapping an integral closure along an `alg_equiv` gives the integral closure. -/ lemma integral_closure_map_alg_equiv (f : A ≃ₐ[R] B) : (integral_closure R A).map (f : A →ₐ[R] B) = integral_closure R B := begin ext y, rw subalgebra.mem_map, split, { rintros ⟨x, hx, rfl⟩, exact is_integral_alg_hom f hx }, { intro hy, use [f.symm y, is_integral_alg_hom (f.symm : B →ₐ[R] A) hy], simp } end lemma integral_closure.is_integral (x : integral_closure R A) : is_integral R x := let ⟨p, hpm, hpx⟩ := x.2 in ⟨p, hpm, subtype.eq $ by rwa [← aeval_def, subtype.val_eq_coe, ← subalgebra.val_apply, aeval_alg_hom_apply] at hpx⟩ theorem is_integral_of_is_integral_mul_unit {x y : A} {r : R} (hr : algebra_map R A r * y = 1) (hx : is_integral R (x * y)) : is_integral R x := begin obtain ⟨p, ⟨p_monic, hp⟩⟩ := hx, refine ⟨scale_roots p r, ⟨(monic_scale_roots_iff r).2 p_monic, _⟩⟩, convert scale_roots_aeval_eq_zero hp, rw [mul_comm x y, ← mul_assoc, hr, one_mul], end end section algebra open algebra variables {R : Type*} {A : Type*} {B : Type*} variables [comm_ring R] [comm_ring A] [comm_ring B] variables [algebra A B] [algebra R B] lemma is_integral_trans_aux (x : B) {p : polynomial A} (pmonic : monic p) (hp : aeval x p = 0) : is_integral (adjoin R (↑(p.map $ algebra_map A B).frange : set B)) x := begin generalize hS : (↑(p.map $ algebra_map A B).frange : set B) = S, have coeffs_mem : ∀ i, (p.map $ algebra_map A B).coeff i ∈ adjoin R S, { intro i, by_cases hi : (p.map $ algebra_map A B).coeff i = 0, { rw hi, exact subalgebra.zero_mem _ }, rw ← hS, exact subset_adjoin (finsupp.mem_frange.2 ⟨hi, i, rfl⟩) }, obtain ⟨q, hq⟩ : ∃ q : polynomial (adjoin R S), q.map (algebra_map (adjoin R S) B) = (p.map $ algebra_map A B), { rw ← set.mem_range, exact (polynomial.mem_map_range _).2 (λ i, ⟨⟨_, coeffs_mem i⟩, rfl⟩) }, use q, split, { suffices h : (q.map (algebra_map (adjoin R S) B)).monic, { refine monic_of_injective _ h, exact subtype.val_injective }, { rw hq, exact monic_map _ pmonic } }, { convert hp using 1, replace hq := congr_arg (eval x) hq, convert hq using 1; symmetry; apply eval_map }, end variables [algebra R A] [is_scalar_tower R A B] /-- If A is an R-algebra all of whose elements are integral over R, and x is an element of an A-algebra that is integral over A, then x is integral over R.-/ lemma is_integral_trans (A_int : is_integral R A) (x : B) (hx : is_integral A x) : is_integral R x := begin rcases hx with ⟨p, pmonic, hp⟩, let S : set B := ↑(p.map $ algebra_map A B).frange, refine is_integral_of_mem_of_fg (adjoin R (S ∪ {x})) _ _ (subset_adjoin $ or.inr rfl), refine fg_trans (fg_adjoin_of_finite (finset.finite_to_set _) (λ x hx, _)) _, { rw [finset.mem_coe, finsupp.mem_frange] at hx, rcases hx with ⟨_, i, rfl⟩, show is_integral R ((p.map $ algebra_map A B).coeff i), rw coeff_map, convert is_integral_alg_hom (is_scalar_tower.to_alg_hom R A B) (A_int _) }, { apply fg_adjoin_singleton_of_integral, exact is_integral_trans_aux _ pmonic hp } end /-- If A is an R-algebra all of whose elements are integral over R, and B is an A-algebra all of whose elements are integral over A, then all elements of B are integral over R.-/ lemma algebra.is_integral_trans (hA : is_integral R A) (hB : is_integral A B) : is_integral R B := λ x, is_integral_trans hA x (hB x) lemma is_integral_of_surjective (h : function.surjective (algebra_map R A)) : is_integral R A := λ x, (h x).rec_on (λ y hy, (hy ▸ is_integral_algebra_map : is_integral R x)) /-- If `R → A → B` is an algebra tower with `A → B` injective, then if the entire tower is an integral extension so is `R → A` -/ lemma is_integral_tower_bot_of_is_integral (H : function.injective (algebra_map A B)) {x : A} (h : is_integral R (algebra_map A B x)) : is_integral R x := begin rcases h with ⟨p, ⟨hp, hp'⟩⟩, refine ⟨p, ⟨hp, _⟩⟩, rw [is_scalar_tower.algebra_map_eq R A B, ← eval₂_map, eval₂_hom, ← ring_hom.map_zero (algebra_map A B)] at hp', rw [eval₂_eq_eval_map], exact H hp', end lemma is_integral_tower_bot_of_is_integral_field {R A B : Type*} [comm_ring R] [field A] [comm_ring B] [nontrivial B] [algebra R A] [algebra A B] [algebra R B] [is_scalar_tower R A B] {x : A} (h : is_integral R (algebra_map A B x)) : is_integral R x := is_integral_tower_bot_of_is_integral (algebra_map A B).injective h /-- If `R → A → B` is an algebra tower, then if the entire tower is an integral extension so is `A → B` -/ lemma is_integral_tower_top_of_is_integral {x : B} (h : is_integral R x) : is_integral A x := begin rcases h with ⟨p, ⟨hp, hp'⟩⟩, refine ⟨p.map (algebra_map R A), ⟨monic_map (algebra_map R A) hp, _⟩⟩, rw [is_scalar_tower.algebra_map_eq R A B, ← eval₂_map] at hp', exact hp', end lemma is_integral_quotient_of_is_integral {I : ideal A} (hRA : is_integral R A) : is_integral (I.comap (algebra_map R A)).quotient I.quotient := begin rintros ⟨x⟩, obtain ⟨p, ⟨p_monic, hpx⟩⟩ := hRA x, refine ⟨p.map (ideal.quotient.mk _), ⟨monic_map _ p_monic, _⟩⟩, simpa only [aeval_def, hom_eval₂, eval₂_map] using congr_arg (ideal.quotient.mk I) hpx end /-- If the integral extension `R → S` is injective, and `S` is a field, then `R` is also a field -/ lemma is_field_of_is_integral_of_is_field {R S : Type*} [integral_domain R] [integral_domain S] [algebra R S] (H : is_integral R S) (hRS : function.injective (algebra_map R S)) (hS : is_field S) : is_field R := begin refine ⟨⟨0, 1, zero_ne_one⟩, mul_comm, λ a ha, _⟩, -- Let `a_inv` be the inverse of `algebra_map R S a`, -- then we need to show that `a_inv` is of the form `algebra_map R S b`. obtain ⟨a_inv, ha_inv⟩ := hS.mul_inv_cancel (λ h, ha (hRS (trans h (ring_hom.map_zero _).symm))), -- Let `p : polynomial R` be monic with root `a_inv`, -- and `q` be `p` with coefficients reversed (so `q(a) = q'(a) * a + 1`). -- We claim that `q(a) = 0`, so `-q'(a)` is the inverse of `a`. obtain ⟨p, p_monic, hp⟩ := H a_inv, use -∑ (i : ℕ) in finset.range p.nat_degree, (p.coeff i) * a ^ (p.nat_degree - i - 1), -- `q(a) = 0`, because multiplying everything with `a_inv^n` gives `p(a_inv) = 0`. -- TODO: this could be a lemma for `polynomial.reverse`. have hq : ∑ (i : ℕ) in finset.range (p.nat_degree + 1), (p.coeff i) * a ^ (p.nat_degree - i) = 0, { apply (algebra_map R S).injective_iff.mp hRS, have a_inv_ne_zero : a_inv ≠ 0 := right_ne_zero_of_mul (mt ha_inv.symm.trans one_ne_zero), refine (mul_eq_zero.mp _).resolve_right (pow_ne_zero p.nat_degree a_inv_ne_zero), rw [eval₂_eq_sum_range] at hp, rw [ring_hom.map_sum, finset.sum_mul], refine (finset.sum_congr rfl (λ i hi, _)).trans hp, rw [ring_hom.map_mul, mul_assoc], congr, have : a_inv ^ p.nat_degree = a_inv ^ (p.nat_degree - i) * a_inv ^ i, { rw [← pow_add a_inv, nat.sub_add_cancel (nat.le_of_lt_succ (finset.mem_range.mp hi))] }, rw [ring_hom.map_pow, this, ← mul_assoc, ← mul_pow, ha_inv, one_pow, one_mul] }, -- Since `q(a) = 0` and `q(a) = q'(a) * a + 1`, we have `a * -q'(a) = 1`. -- TODO: we could use a lemma for `polynomial.div_X` here. rw [finset.sum_range_succ, p_monic.coeff_nat_degree, one_mul, nat.sub_self, pow_zero, add_eq_zero_iff_eq_neg, eq_comm] at hq, rw [mul_comm, ← neg_mul_eq_neg_mul, finset.sum_mul], convert hq using 2, refine finset.sum_congr rfl (λ i hi, _), have : 1 ≤ p.nat_degree - i := nat.le_sub_left_of_add_le (finset.mem_range.mp hi), rw [mul_assoc, ← pow_succ', nat.sub_add_cancel this] end end algebra section local attribute [instance] subset.comm_ring algebra.of_is_subring theorem integral_closure_idem {R : Type*} {A : Type*} [comm_ring R] [comm_ring A] [algebra R A] : integral_closure (integral_closure R A : set A) A = ⊥ := eq_bot_iff.2 $ λ x hx, algebra.mem_bot.2 ⟨⟨x, @is_integral_trans _ _ _ _ _ _ _ _ (integral_closure R A).algebra _ integral_closure.is_integral x hx⟩, rfl⟩ end section integral_domain variables {R S : Type*} [comm_ring R] [integral_domain S] [algebra R S] instance : integral_domain (integral_closure R S) := { exists_pair_ne := ⟨0, 1, mt subtype.ext_iff_val.mp zero_ne_one⟩, eq_zero_or_eq_zero_of_mul_eq_zero := λ ⟨a, ha⟩ ⟨b, hb⟩ h, or.imp subtype.ext_iff_val.mpr subtype.ext_iff_val.mpr (eq_zero_or_eq_zero_of_mul_eq_zero (subtype.ext_iff_val.mp h)), ..(integral_closure R S).comm_ring R S } end integral_domain
4cb6bcc252fe666f5f71d0425036b446c1c3e7f0
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/tactic/omega/nat/sub_elim.lean
6922491a6d38c3f7a2e97f9fbb2c5ed77c90ac3c
[ "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
5,710
lean
/- Copyright (c) 2019 Seul Baek. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Seul Baek -/ /- Subtraction elimination for linear natural number arithmetic. Works by repeatedly rewriting goals of the preform `P[t-s]` into `P[x] ∧ (t = s + x ∨ (t ≤ s ∧ x = 0))`, where `x` is fresh. -/ import tactic.omega.nat.form namespace omega namespace nat open_locale omega.nat namespace preterm /-- Find subtraction inside preterm and return its operands -/ def sub_terms : preterm → option (preterm × preterm) | (& i) := none | (i ** n) := none | (t +* s) := t.sub_terms <|> s.sub_terms | (t -* s) := t.sub_terms <|> s.sub_terms <|> some (t,s) /-- Find (t - s) inside a preterm and replace it with variable k -/ def sub_subst (t s : preterm) (k : nat) : preterm → preterm | t@(& m) := t | t@(m ** n) := t | (x +* y) := x.sub_subst +* y.sub_subst | (x -* y) := if x = t ∧ y = s then (1 ** k) else x.sub_subst -* y.sub_subst lemma val_sub_subst {k : nat} {x y : preterm} {v : nat → nat} : ∀ {t : preterm}, t.fresh_index ≤ k → (sub_subst x y k t).val (update k (x.val v - y.val v) v) = t.val v | (& m) h1 := rfl | (m ** n) h1 := begin have h2 : n ≠ k := ne_of_lt h1, simp only [sub_subst, preterm.val], rw update_eq_of_ne _ h2, end | (t +* s) h1 := begin simp only [sub_subst, val_add], apply fun_mono_2; apply val_sub_subst (le_trans _ h1), apply le_max_left, apply le_max_right end | (t -* s) h1 := begin simp only [sub_subst, val_sub], by_cases h2 : t = x ∧ s = y, { rw if_pos h2, simp only [val_var, one_mul], rw [update_eq, h2.left, h2.right] }, { rw if_neg h2, simp only [val_sub, sub_subst], apply fun_mono_2; apply val_sub_subst (le_trans _ h1), apply le_max_left, apply le_max_right, } end end preterm namespace preform /-- Find subtraction inside preform and return its operands -/ def sub_terms : preform → option (preterm × preterm) | (t =* s) := t.sub_terms <|> s.sub_terms | (t ≤* s) := t.sub_terms <|> s.sub_terms | (¬* p) := p.sub_terms | (p ∨* q) := p.sub_terms <|> q.sub_terms | (p ∧* q) := p.sub_terms <|> q.sub_terms /-- Find (t - s) inside a preform and replace it with variable k -/ @[simp] def sub_subst (x y : preterm) (k : nat) : preform → preform | (t =* s) := preterm.sub_subst x y k t =* preterm.sub_subst x y k s | (t ≤* s) := preterm.sub_subst x y k t ≤* preterm.sub_subst x y k s | (¬* p) := ¬* p.sub_subst | (p ∨* q) := p.sub_subst ∨* q.sub_subst | (p ∧* q) := p.sub_subst ∧* q.sub_subst end preform /-- Preform which asserts that the value of variable k is the truncated difference between preterms t and s -/ def is_diff (t s : preterm) (k : nat) : preform := ((t =* (s +* (1 ** k))) ∨* (t ≤* s ∧* ((1 ** k) =* &0))) lemma holds_is_diff {t s : preterm} {k : nat} {v : nat → nat} : v k = t.val v - s.val v → (is_diff t s k).holds v := begin intro h1, simp only [preform.holds, is_diff, if_pos (eq.refl 1), preterm.val_add, preterm.val_var, preterm.val_const], by_cases h2 : t.val v ≤ s.val v, { right, refine ⟨h2,_⟩, rw [h1, one_mul, nat.sub_eq_zero_iff_le], exact h2 }, { left, rw [h1, one_mul, add_comm, nat.sub_add_cancel _], rw not_le at h2, apply le_of_lt h2 } end /-- Helper function for sub_elim -/ def sub_elim_core (t s : preterm) (k : nat) (p : preform) : preform := (preform.sub_subst t s k p) ∧* (is_diff t s k) /-- Return de Brujin index of fresh variable that does not occur in any of the arguments -/ def sub_fresh_index (t s : preterm) (p : preform) : nat := max p.fresh_index (max t.fresh_index s.fresh_index) /-- Return a new preform with all subtractions eliminated -/ def sub_elim (t s : preterm) (p : preform) : preform := sub_elim_core t s (sub_fresh_index t s p) p lemma sub_subst_equiv {k : nat} {x y : preterm} {v : nat → nat} : ∀ p : preform, p.fresh_index ≤ k → ((preform.sub_subst x y k p).holds (update k (x.val v - y.val v) v) ↔ (p.holds v)) | (t =* s) h1 := begin simp only [preform.holds, preform.sub_subst], apply pred_mono_2; apply preterm.val_sub_subst (le_trans _ h1), apply le_max_left, apply le_max_right end | (t ≤* s) h1 := begin simp only [preform.holds, preform.sub_subst], apply pred_mono_2; apply preterm.val_sub_subst (le_trans _ h1), apply le_max_left, apply le_max_right end | (¬* p) h1 := by { apply not_iff_not_of_iff, apply sub_subst_equiv p h1 } | (p ∨* q) h1 := begin simp only [preform.holds, preform.sub_subst], apply pred_mono_2; apply propext; apply sub_subst_equiv _ (le_trans _ h1), apply le_max_left, apply le_max_right end | (p ∧* q) h1 := begin simp only [preform.holds, preform.sub_subst], apply pred_mono_2; apply propext; apply sub_subst_equiv _ (le_trans _ h1), apply le_max_left, apply le_max_right end lemma sat_sub_elim {t s : preterm} {p : preform} : p.sat → (sub_elim t s p).sat := begin intro h1, simp only [sub_elim, sub_elim_core], cases h1 with v h1, refine ⟨update (sub_fresh_index t s p) (t.val v - s.val v) v, _⟩, constructor, { apply (sub_subst_equiv p _).elim_right h1, apply le_max_left }, { apply holds_is_diff, rw update_eq, apply fun_mono_2; apply preterm.val_constant; intros x h2; rw update_eq_of_ne _ (ne.symm (ne_of_gt _)); apply lt_of_lt_of_le h2; apply le_trans _ (le_max_right _ _), apply le_max_left, apply le_max_right } end lemma unsat_of_unsat_sub_elim (t s : preterm) (p : preform) : (sub_elim t s p).unsat → p.unsat := mt sat_sub_elim end nat end omega
8e8a953327cc75d6ecbc0bfeb027ba64e186fe2e
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/int/cast.lean
d736bd02e8c47f6763a422e34a2790d00b09cb78
[]
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,042
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 Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.int.basic import Mathlib.data.nat.cast import Mathlib.PostPort universes u_1 u_2 namespace Mathlib namespace int /- cast (injection into groups with one) -/ @[simp] theorem nat_cast_eq_coe_nat (n : ℕ) : ↑n = ↑n := sorry /-- Coercion `ℕ → ℤ` as a `ring_hom`. -/ def of_nat_hom : ℕ →+* ℤ := ring_hom.mk coe sorry of_nat_mul sorry of_nat_add /-- Canonical homomorphism from the integers to any ring(-like) structure `α` -/ protected def cast {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] : ℤ → α := sorry -- see Note [coercion into rings] protected instance cast_coe {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] : has_coe_t ℤ α := has_coe_t.mk int.cast @[simp] theorem cast_zero {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] : ↑0 = 0 := rfl theorem cast_of_nat {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] (n : ℕ) : ↑(Int.ofNat n) = ↑n := rfl @[simp] theorem cast_coe_nat {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] (n : ℕ) : ↑↑n = ↑n := rfl theorem cast_coe_nat' {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] (n : ℕ) : ↑↑n = ↑n := sorry @[simp] theorem cast_neg_succ_of_nat {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] (n : ℕ) : ↑(Int.negSucc n) = -(↑n + 1) := rfl @[simp] theorem cast_one {α : Type u_1} [add_monoid α] [HasOne α] [Neg α] : ↑1 = 1 := nat.cast_one @[simp] theorem cast_sub_nat_nat {α : Type u_1} [add_group α] [HasOne α] (m : ℕ) (n : ℕ) : ↑(sub_nat_nat m n) = ↑m - ↑n := sorry @[simp] theorem cast_neg_of_nat {α : Type u_1} [add_group α] [HasOne α] (n : ℕ) : ↑(neg_of_nat n) = -↑n := nat.cases_on n (idRhs (0 = -0) (Eq.symm neg_zero)) fun (n : ℕ) => idRhs (↑(neg_of_nat (n + 1)) = ↑(neg_of_nat (n + 1))) rfl @[simp] theorem cast_add {α : Type u_1} [add_group α] [HasOne α] (m : ℤ) (n : ℤ) : ↑(m + n) = ↑m + ↑n := sorry @[simp] theorem cast_neg {α : Type u_1} [add_group α] [HasOne α] (n : ℤ) : ↑(-n) = -↑n := int.cases_on n (fun (n : ℕ) => idRhs (↑(neg_of_nat n) = -↑n) (cast_neg_of_nat n)) fun (n : ℕ) => idRhs (↑(-Int.negSucc n) = --↑(-Int.negSucc n)) (Eq.symm (neg_neg ↑(-Int.negSucc n))) @[simp] theorem cast_sub {α : Type u_1} [add_group α] [HasOne α] (m : ℤ) (n : ℤ) : ↑(m - n) = ↑m - ↑n := sorry @[simp] theorem cast_mul {α : Type u_1} [ring α] (m : ℤ) (n : ℤ) : ↑(m * n) = ↑m * ↑n := sorry /-- `coe : ℤ → α` as an `add_monoid_hom`. -/ def cast_add_hom (α : Type u_1) [add_group α] [HasOne α] : ℤ →+ α := add_monoid_hom.mk coe sorry cast_add @[simp] theorem coe_cast_add_hom {α : Type u_1} [add_group α] [HasOne α] : ⇑(cast_add_hom α) = coe := rfl /-- `coe : ℤ → α` as a `ring_hom`. -/ def cast_ring_hom (α : Type u_1) [ring α] : ℤ →+* α := ring_hom.mk coe sorry cast_mul sorry sorry @[simp] theorem coe_cast_ring_hom {α : Type u_1} [ring α] : ⇑(cast_ring_hom α) = coe := rfl theorem cast_commute {α : Type u_1} [ring α] (m : ℤ) (x : α) : commute (↑m) x := int.cases_on m (fun (n : ℕ) => nat.cast_commute n x) fun (n : ℕ) => commute.neg_left (nat.cast_commute (n + 1) x) theorem commute_cast {α : Type u_1} [ring α] (x : α) (m : ℤ) : commute x ↑m := commute.symm (cast_commute m x) @[simp] theorem coe_nat_bit0 (n : ℕ) : ↑(bit0 n) = bit0 ↑n := sorry @[simp] theorem coe_nat_bit1 (n : ℕ) : ↑(bit1 n) = bit1 ↑n := sorry @[simp] theorem cast_bit0 {α : Type u_1} [ring α] (n : ℤ) : ↑(bit0 n) = bit0 ↑n := cast_add n n @[simp] theorem cast_bit1 {α : Type u_1} [ring α] (n : ℤ) : ↑(bit1 n) = bit1 ↑n := sorry theorem cast_two {α : Type u_1} [ring α] : ↑(bit0 1) = bit0 1 := sorry theorem cast_mono {α : Type u_1} [ordered_ring α] : monotone coe := sorry @[simp] theorem cast_nonneg {α : Type u_1} [ordered_ring α] [nontrivial α] {n : ℤ} : 0 ≤ ↑n ↔ 0 ≤ n := sorry @[simp] theorem cast_le {α : Type u_1} [ordered_ring α] [nontrivial α] {m : ℤ} {n : ℤ} : ↑m ≤ ↑n ↔ m ≤ n := sorry theorem cast_strict_mono {α : Type u_1} [ordered_ring α] [nontrivial α] : strict_mono coe := strict_mono_of_le_iff_le fun (m n : ℤ) => iff.symm cast_le @[simp] theorem cast_lt {α : Type u_1} [ordered_ring α] [nontrivial α] {m : ℤ} {n : ℤ} : ↑m < ↑n ↔ m < n := strict_mono.lt_iff_lt cast_strict_mono @[simp] theorem cast_nonpos {α : Type u_1} [ordered_ring α] [nontrivial α] {n : ℤ} : ↑n ≤ 0 ↔ n ≤ 0 := eq.mpr (id (Eq._oldrec (Eq.refl (↑n ≤ 0 ↔ n ≤ 0)) (Eq.symm cast_zero))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑n ≤ ↑0 ↔ n ≤ 0)) (propext cast_le))) (iff.refl (n ≤ 0))) @[simp] theorem cast_pos {α : Type u_1} [ordered_ring α] [nontrivial α] {n : ℤ} : 0 < ↑n ↔ 0 < n := eq.mpr (id (Eq._oldrec (Eq.refl (0 < ↑n ↔ 0 < n)) (Eq.symm cast_zero))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑0 < ↑n ↔ 0 < n)) (propext cast_lt))) (iff.refl (0 < n))) @[simp] theorem cast_lt_zero {α : Type u_1} [ordered_ring α] [nontrivial α] {n : ℤ} : ↑n < 0 ↔ n < 0 := eq.mpr (id (Eq._oldrec (Eq.refl (↑n < 0 ↔ n < 0)) (Eq.symm cast_zero))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑n < ↑0 ↔ n < 0)) (propext cast_lt))) (iff.refl (n < 0))) @[simp] theorem cast_min {α : Type u_1} [linear_ordered_ring α] {a : ℤ} {b : ℤ} : ↑(min a b) = min ↑a ↑b := monotone.map_min cast_mono @[simp] theorem cast_max {α : Type u_1} [linear_ordered_ring α] {a : ℤ} {b : ℤ} : ↑(max a b) = max ↑a ↑b := monotone.map_max cast_mono @[simp] theorem cast_abs {α : Type u_1} [linear_ordered_ring α] {q : ℤ} : ↑(abs q) = abs ↑q := sorry theorem coe_int_dvd {α : Type u_1} [comm_ring α] (m : ℤ) (n : ℤ) (h : m ∣ n) : ↑m ∣ ↑n := ring_hom.map_dvd (cast_ring_hom α) h end int namespace add_monoid_hom /-- Two additive monoid homomorphisms `f`, `g` from `ℤ` to an additive monoid are equal if `f 1 = g 1`. -/ theorem ext_int {A : Type u_1} [add_monoid A] {f : ℤ →+ A} {g : ℤ →+ A} (h1 : coe_fn f 1 = coe_fn g 1) : f = g := sorry theorem eq_int_cast_hom {A : Type u_1} [add_group A] [HasOne A] (f : ℤ →+ A) (h1 : coe_fn f 1 = 1) : f = int.cast_add_hom A := sorry theorem eq_int_cast {A : Type u_1} [add_group A] [HasOne A] (f : ℤ →+ A) (h1 : coe_fn f 1 = 1) (n : ℤ) : coe_fn f n = ↑n := iff.mp ext_iff (eq_int_cast_hom f h1) end add_monoid_hom namespace monoid_hom theorem ext_int {M : Type u_1} [monoid M] {f : multiplicative ℤ →* M} {g : multiplicative ℤ →* M} (h1 : coe_fn f (coe_fn multiplicative.of_add 1) = coe_fn g (coe_fn multiplicative.of_add 1)) : f = g := ext fun (x : multiplicative ℤ) => iff.mp add_monoid_hom.ext_iff (add_monoid_hom.ext_int h1) x end monoid_hom namespace ring_hom @[simp] theorem eq_int_cast {α : Type u_1} [ring α] (f : ℤ →+* α) (n : ℤ) : coe_fn f n = ↑n := add_monoid_hom.eq_int_cast (to_add_monoid_hom f) (map_one f) n theorem eq_int_cast' {α : Type u_1} [ring α] (f : ℤ →+* α) : f = int.cast_ring_hom α := ext (eq_int_cast f) @[simp] theorem map_int_cast {α : Type u_1} {β : Type u_2} [ring α] [ring β] (f : α →+* β) (n : ℤ) : coe_fn f ↑n = ↑n := eq_int_cast (comp f (int.cast_ring_hom α)) n theorem ext_int {R : Type u_1} [semiring R] (f : ℤ →+* R) (g : ℤ →+* R) : f = g := coe_add_monoid_hom_injective (add_monoid_hom.ext_int (Eq.trans (map_one f) (Eq.symm (map_one g)))) protected instance int.subsingleton_ring_hom {R : Type u_1} [semiring R] : subsingleton (ℤ →+* R) := subsingleton.intro ext_int end ring_hom @[simp] theorem int.cast_id (n : ℤ) : ↑n = n := Eq.symm (ring_hom.eq_int_cast (ring_hom.id ℤ) n)
acbc0310a4d74c8834baa253d47b172884c186a3
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/topology/metric_space/lipschitz.lean
072e502ec9da9cb6bc9f77580b614c54d41c3fcc
[ "Apache-2.0" ]
permissive
fpvandoorn/mathlib
b21ab4068db079cbb8590b58fda9cc4bc1f35df4
b3433a51ea8bc07c4159c1073838fc0ee9b8f227
refs/heads/master
1,624,791,089,608
1,556,715,231,000
1,556,715,231,000
165,722,980
5
0
Apache-2.0
1,552,657,455,000
1,547,494,646,000
Lean
UTF-8
Lean
false
false
5,507
lean
/- Copyright (c) 2018 Rohan Mitta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes Hölzl Lipschitz functions and the Banach fixed-point theorem -/ import topology.metric_space.basic analysis.specific_limits open filter variables {α : Type*} {β : Type*} {γ : Type*} lemma fixed_point_of_tendsto_iterate [topological_space α] [t2_space α] {f : α → α} {x : α} (hf : tendsto f (nhds x) (nhds (f x))) (hx : ∃ x₀ : α, tendsto (λ n, f^[n] x₀) at_top (nhds x)) : f x = x := begin rcases hx with ⟨x₀, hx⟩, refine tendsto_nhds_unique at_top_ne_bot _ hx, rw [← tendsto_add_at_top_iff_nat 1, funext (assume n, nat.iterate_succ' f n x₀)], exact hx.comp hf end /-- A Lipschitz function is uniformly continuous -/ lemma uniform_continuous_of_lipschitz [metric_space α] [metric_space β] {K : ℝ} {f : α → β} (H : ∀x y, dist (f x) (f y) ≤ K * dist x y) : uniform_continuous f := begin have : 0 < max K 1 := lt_of_lt_of_le zero_lt_one (le_max_right K 1), refine metric.uniform_continuous_iff.2 (λε εpos, _), exact ⟨ε/max K 1, div_pos εpos this, assume y x Dyx, calc dist (f y) (f x) ≤ K * dist y x : H y x ... ≤ max K 1 * dist y x : mul_le_mul_of_nonneg_right (le_max_left K 1) (dist_nonneg) ... < max K 1 * (ε/max K 1) : mul_lt_mul_of_pos_left Dyx this ... = ε : mul_div_cancel' _ (ne_of_gt this)⟩ end /-- A Lipschitz function is continuous -/ lemma continuous_of_lipschitz [metric_space α] [metric_space β] {K : ℝ} {f : α → β} (H : ∀x y, dist (f x) (f y) ≤ K * dist x y) : continuous f := uniform_continuous.continuous (uniform_continuous_of_lipschitz H) lemma uniform_continuous_of_le_add [metric_space α] {f : α → ℝ} (K : ℝ) (h : ∀x y, f x ≤ f y + K * dist x y) : uniform_continuous f := begin have I : ∀ (x y : α), f x - f y ≤ K * dist x y := λx y, calc f x - f y ≤ (f y + K * dist x y) - f y : add_le_add (h x y) (le_refl _) ... = K * dist x y : by ring, refine @uniform_continuous_of_lipschitz _ _ _ _ K _ (λx y, _), rw real.dist_eq, refine abs_sub_le_iff.2 ⟨_, _⟩, { exact I x y }, { rw dist_comm, exact I y x } end /-- `lipschitz_with K f`: the function `f` is Lipschitz continuous w.r.t. the Lipschitz constant `K`. -/ def lipschitz_with [metric_space α] [metric_space β] (K : ℝ) (f : α → β) := 0 ≤ K ∧ ∀x y, dist (f x) (f y) ≤ K * dist x y namespace lipschitz_with variables [metric_space α] [metric_space β] [metric_space γ] {K : ℝ} protected lemma weaken (K' : ℝ) {f : α → β} (hf : lipschitz_with K f) (h : K ≤ K') : lipschitz_with K' f := ⟨le_trans hf.1 h, assume x y, le_trans (hf.2 x y) $ mul_le_mul_of_nonneg_right h dist_nonneg⟩ protected lemma to_uniform_continuous {f : α → β} (hf : lipschitz_with K f) : uniform_continuous f := uniform_continuous_of_lipschitz hf.2 protected lemma to_continuous {f : α → β} (hf : lipschitz_with K f) : continuous f := continuous_of_lipschitz hf.2 protected lemma const (b : β) : lipschitz_with 0 (λa:α, b) := ⟨le_refl 0, assume x y, by simp⟩ protected lemma id : lipschitz_with 1 (@id α) := ⟨zero_le_one, by simp [le_refl]⟩ protected lemma comp {Kf Kg : ℝ} {f : β → γ} {g : α → β} (hf : lipschitz_with Kf f) (hg : lipschitz_with Kg g) : lipschitz_with (Kf * Kg) (f ∘ g) := ⟨mul_nonneg hf.1 hg.1, assume x y, calc dist (f (g x)) (f (g y)) ≤ Kf * dist (g x) (g y) : hf.2 _ _ ... ≤ Kf * (Kg * dist x y) : mul_le_mul_of_nonneg_left (hg.2 _ _) hf.1 ... = (Kf * Kg) * dist x y : by rw mul_assoc⟩ protected lemma iterate {f : α → α} (hf : lipschitz_with K f) : ∀n, lipschitz_with (K ^ n) (f^[n]) | 0 := lipschitz_with.id | (n + 1) := by rw [← nat.succ_eq_add_one, pow_succ, mul_comm]; exact (iterate n).comp hf section contraction variables {f : α → α} {x y : α} lemma dist_inequality_of_contraction (hK₁ : K < 1) (hf : lipschitz_with K f) : dist x y ≤ (dist x (f x) + dist y (f y)) / (1 - K) := suffices dist x y ≤ dist x (f x) + (dist y (f y) + K * dist x y), by rwa [le_div_iff (sub_pos_of_lt hK₁), mul_comm, sub_mul, one_mul, sub_le_iff_le_add, add_assoc], calc dist x y ≤ dist x (f x) + dist y (f x) : dist_triangle_right x y (f x) ... ≤ dist x (f x) + (dist y (f y) + dist (f x) (f y)) : add_le_add_left (dist_triangle_right y (f x) (f y)) _ ... ≤ dist x (f x) + (dist y (f y) + K * dist x y) : add_le_add_left (add_le_add_left (hf.2 _ _) _) _ theorem fixed_point_unique_of_contraction (hK : K < 1) (hf : lipschitz_with K f) (hx : f x = x) (hy : f y = y) : x = y := dist_le_zero.1 $ le_trans (dist_inequality_of_contraction hK hf) $ by rewrite [iff.mpr dist_eq_zero hx.symm, iff.mpr dist_eq_zero hy.symm]; simp /-- Banach fixed-point theorem, contraction mapping theorem -/ theorem exists_fixed_point_of_contraction [hα : nonempty α] [complete_space α] (hK : K < 1) (hf : lipschitz_with K f) : ∃x, f x = x := let ⟨x₀⟩ := hα in have cauchy_seq (λ n, f^[n] x₀) := begin refine cauchy_seq_of_le_geometric K (dist x₀ (f x₀)) hK (λn, _), rw [nat.iterate_succ f n x₀, mul_comm], exact and.right (hf.iterate n) x₀ (f x₀) end, let ⟨x, hx⟩ := cauchy_seq_tendsto_of_complete this in ⟨x, fixed_point_of_tendsto_iterate (hf.to_uniform_continuous.continuous.tendsto x) ⟨x₀, hx⟩⟩ end contraction end lipschitz_with
6a24b995563f9208a2338a429779d62bc71da5e1
316671bfe98dfae2abac483407a5ae2daca54b1b
/04_Disjunction/00_intro.lean
4e8623eeba468f19fa06566b4c083ad101b9fa12
[]
no_license
chasedawson/cs-dm
9b38bd7b0bd411a9f7713f5d613b8a0b2fdcd28b
ac3cca3eadc56a6355c8e9a56a39ed7eb1db55cb
refs/heads/master
1,585,360,471,246
1,536,097,455,000
1,536,097,455,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
114
lean
-- UNDER CONSTRUCTION /- P ----- (∨-intro-left) P ∨ Q Q ----- (∨-intro-right) P ∨ Q -/
acde7599d003738d4084bf35b58fa1659449c757
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/ring_theory/multiplicity.lean
e48057423a0f9fc7f2eb65d9a039f8aa846ee350
[ "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
22,676
lean
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Chris Hughes -/ import algebra.associated import algebra.big_operators.basic import ring_theory.valuation.basic /-! # Multiplicity of a divisor For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves several basic results on it. ## Main definitions * `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers `n`. * `multiplicity.finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite. -/ variables {α : Type*} open nat part open_locale big_operators /-- `multiplicity a b` returns the largest natural number `n` such that `a ^ n ∣ b`, as an `part_enat` or natural with infinity. If `∀ n, a ^ n ∣ b`, then it returns `⊤`-/ def multiplicity [monoid α] [decidable_rel ((∣) : α → α → Prop)] (a b : α) : part_enat := part_enat.find $ λ n, ¬a ^ (n + 1) ∣ b namespace multiplicity section monoid variables [monoid α] /-- `multiplicity.finite a b` indicates that the multiplicity of `a` in `b` is finite. -/ @[reducible] def finite (a b : α) : Prop := ∃ n : ℕ, ¬a ^ (n + 1) ∣ b lemma finite_iff_dom [decidable_rel ((∣) : α → α → Prop)] {a b : α} : finite a b ↔ (multiplicity a b).dom := iff.rfl lemma finite_def {a b : α} : finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b := iff.rfl lemma not_dvd_one_of_finite_one_right {a : α} : finite a 1 → ¬a ∣ 1 := λ ⟨n, hn⟩ ⟨d, hd⟩, hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩ @[norm_cast] theorem int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := begin apply part.ext', { repeat { rw [← finite_iff_dom, finite_def] }, norm_cast }, { intros h1 h2, apply _root_.le_antisymm; { apply nat.find_mono, norm_cast, simp } } end lemma not_finite_iff_forall {a b : α} : (¬ finite a b) ↔ ∀ n : ℕ, a ^ n ∣ b := ⟨λ h n, nat.cases_on n (by { rw pow_zero, exact one_dvd _ }) (by simpa [finite, not_not] using h), by simp [finite, multiplicity, not_not]; tauto⟩ lemma not_unit_of_finite {a b : α} (h : finite a b) : ¬is_unit a := let ⟨n, hn⟩ := h in hn ∘ is_unit.dvd ∘ is_unit.pow (n + 1) lemma finite_of_finite_mul_right {a b c : α} : finite a (b * c) → finite a b := λ ⟨n, hn⟩, ⟨n, λ h, hn (h.trans (dvd_mul_right _ _))⟩ variable [decidable_rel ((∣) : α → α → Prop)] lemma pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} : (k : part_enat) ≤ multiplicity a b → a ^ k ∣ b := by { rw ← part_enat.some_eq_coe, exact nat.cases_on k (λ _, by { rw pow_zero, exact one_dvd _ }) (λ k ⟨h₁, h₂⟩, by_contradiction (λ hk, (nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk))) } lemma pow_multiplicity_dvd {a b : α} (h : finite a b) : a ^ get (multiplicity a b) h ∣ b := pow_dvd_of_le_multiplicity (by rw part_enat.coe_get) lemma is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := λ h, by rw [part_enat.lt_coe_iff] at hm; exact nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h) lemma is_greatest' {a b : α} {m : ℕ} (h : finite a b) (hm : get (multiplicity a b) h < m) : ¬a ^ m ∣ b := is_greatest (by rwa [← part_enat.coe_lt_coe, part_enat.coe_get] at hm) lemma pos_of_dvd {a b : α} (hfin : finite a b) (hdiv : a ∣ b) : 0 < (multiplicity a b).get hfin := begin refine zero_lt_iff.2 (λ h, _), simpa [hdiv] using (is_greatest' hfin (lt_one_iff.mpr h)), end lemma unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) : (k : part_enat) = multiplicity a b := le_antisymm (le_of_not_gt (λ hk', is_greatest hk' hk)) $ have finite a b, from ⟨k, hsucc⟩, by { rw [part_enat.le_coe_iff], exact ⟨this, nat.find_min' _ hsucc⟩ } lemma unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬ a ^ (k + 1) ∣ b) : k = get (multiplicity a b) ⟨k, hsucc⟩ := by rw [← part_enat.coe_inj, part_enat.coe_get, unique hk hsucc] lemma le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) : (k : part_enat) ≤ multiplicity a b := le_of_not_gt $ λ hk', is_greatest hk' hk lemma pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} : a ^ k ∣ b ↔ (k : part_enat) ≤ multiplicity a b := ⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩ lemma multiplicity_lt_iff_neg_dvd {a b : α} {k : ℕ} : multiplicity a b < (k : part_enat) ↔ ¬ a ^ k ∣ b := by { rw [pow_dvd_iff_le_multiplicity, not_le] } lemma eq_coe_iff {a b : α} {n : ℕ} : multiplicity a b = (n : part_enat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := begin rw [← part_enat.some_eq_coe], exact ⟨λ h, let ⟨h₁, h₂⟩ := eq_some_iff.1 h in h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by { rw [part_enat.lt_coe_iff], exact ⟨h₁, lt_succ_self _⟩ })⟩, λ h, eq_some_iff.2 ⟨⟨n, h.2⟩, eq.symm $ unique' h.1 h.2⟩⟩ end lemma eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b := (part_enat.find_eq_top_iff _).trans $ by { simp only [not_not], exact ⟨λ h n, nat.cases_on n (by { rw pow_zero, exact one_dvd _}) (λ n, h _), λ h n, h _⟩ } @[simp] lemma is_unit_left {a : α} (b : α) (ha : is_unit a) : multiplicity a b = ⊤ := eq_top_iff.2 (λ _, is_unit.dvd (ha.pow _)) @[simp] lemma one_left (b : α) : multiplicity 1 b = ⊤ := is_unit_left b is_unit_one @[simp] lemma get_one_right {a : α} (ha : finite a 1) : get (multiplicity a 1) ha = 0 := begin rw [part_enat.get_eq_iff_eq_coe, eq_coe_iff, pow_zero], simp [not_dvd_one_of_finite_one_right ha], end @[simp] lemma unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ := is_unit_left a u.is_unit lemma multiplicity_eq_zero_of_not_dvd {a b : α} (ha : ¬a ∣ b) : multiplicity a b = 0 := by { rw [← nat.cast_zero, eq_coe_iff], simpa } lemma eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬ finite a b := part.eq_none_iff' lemma ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ finite a b := by rw [ne.def, eq_top_iff_not_finite, not_not] lemma lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ finite a b := by rw [lt_top_iff_ne_top, ne_top_iff_finite] lemma exists_eq_pow_mul_and_not_dvd {a b : α} (hfin : finite a b) : ∃ (c : α), b = a ^ ((multiplicity a b).get hfin) * c ∧ ¬ a ∣ c := begin obtain ⟨c, hc⟩ := multiplicity.pow_multiplicity_dvd hfin, refine ⟨c, hc, _⟩, rintro ⟨k, hk⟩, rw [hk, ← mul_assoc, ← pow_succ'] at hc, have h₁ : a ^ ((multiplicity a b).get hfin + 1) ∣ b := ⟨k, hc⟩, exact (multiplicity.eq_coe_iff.1 (by simp)).2 h₁, end open_locale classical lemma multiplicity_le_multiplicity_iff {a b c d : α} : multiplicity a b ≤ multiplicity c d ↔ (∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d) := ⟨λ h n hab, (pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h)), λ h, if hab : finite a b then by rw [← part_enat.coe_get (finite_iff_dom.1 hab)]; exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _)) else have ∀ n : ℕ, c ^ n ∣ d, from λ n, h n (not_finite_iff_forall.1 hab _), by rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩ lemma multiplicity_eq_multiplicity_iff {a b c d : α} : multiplicity a b = multiplicity c d ↔ (∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d) := ⟨λ h n, ⟨multiplicity_le_multiplicity_iff.mp h.le n, multiplicity_le_multiplicity_iff.mp h.ge n⟩, λ h, le_antisymm (multiplicity_le_multiplicity_iff.mpr (λ n, (h n).mp)) (multiplicity_le_multiplicity_iff.mpr (λ n, (h n).mpr))⟩ lemma multiplicity_le_multiplicity_of_dvd_right {a b c : α} (h : b ∣ c) : multiplicity a b ≤ multiplicity a c := multiplicity_le_multiplicity_iff.2 $ λ n hb, hb.trans h lemma eq_of_associated_right {a b c : α} (h : associated b c) : multiplicity a b = multiplicity a c := le_antisymm (multiplicity_le_multiplicity_of_dvd_right h.dvd) (multiplicity_le_multiplicity_of_dvd_right h.symm.dvd) lemma dvd_of_multiplicity_pos {a b : α} (h : (0 : part_enat) < multiplicity a b) : a ∣ b := begin rw ← pow_one a, apply pow_dvd_of_le_multiplicity, simpa only [nat.cast_one, part_enat.pos_iff_one_le] using h end lemma dvd_iff_multiplicity_pos {a b : α} : (0 : part_enat) < multiplicity a b ↔ a ∣ b := ⟨dvd_of_multiplicity_pos, λ hdvd, lt_of_le_of_ne (zero_le _) (λ heq, is_greatest (show multiplicity a b < ↑1, by simpa only [heq, nat.cast_zero] using part_enat.coe_lt_coe.mpr zero_lt_one) (by rwa pow_one a))⟩ lemma finite_nat_iff {a b : ℕ} : finite a b ↔ (a ≠ 1 ∧ 0 < b) := begin rw [← not_iff_not, not_finite_iff_forall, not_and_distrib, ne.def, not_not, not_lt, le_zero_iff], exact ⟨λ h, or_iff_not_imp_right.2 (λ hb, have ha : a ≠ 0, from λ ha, by simpa [ha] using h 1, by_contradiction (λ ha1 : a ≠ 1, have ha_gt_one : 1 < a, from lt_of_not_ge (λ ha', by { clear h, revert ha ha1, dec_trivial! }), not_lt_of_ge (le_of_dvd (nat.pos_of_ne_zero hb) (h b)) (lt_pow_self ha_gt_one b))), λ h, by cases h; simp *⟩ end alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos end monoid section comm_monoid variables [comm_monoid α] lemma finite_of_finite_mul_left {a b c : α} : finite a (b * c) → finite a c := by rw mul_comm; exact finite_of_finite_mul_right variable [decidable_rel ((∣) : α → α → Prop)] lemma is_unit_right {a b : α} (ha : ¬is_unit a) (hb : is_unit b) : multiplicity a b = 0 := eq_coe_iff.2 ⟨show a ^ 0 ∣ b, by simp only [pow_zero, one_dvd], by { rw pow_one, exact λ h, mt (is_unit_of_dvd_unit h) ha hb }⟩ lemma one_right {a : α} (ha : ¬is_unit a) : multiplicity a 1 = 0 := is_unit_right ha is_unit_one lemma unit_right {a : α} (ha : ¬is_unit a) (u : αˣ) : multiplicity a u = 0 := is_unit_right ha u.is_unit open_locale classical lemma multiplicity_le_multiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) : multiplicity b c ≤ multiplicity a c := multiplicity_le_multiplicity_iff.2 $ λ n h, (pow_dvd_pow_of_dvd hdvd n).trans h lemma eq_of_associated_left {a b c : α} (h : associated a b) : multiplicity b c = multiplicity a c := le_antisymm (multiplicity_le_multiplicity_of_dvd_left h.dvd) (multiplicity_le_multiplicity_of_dvd_left h.symm.dvd) alias dvd_iff_multiplicity_pos ↔ _ _root_.has_dvd.dvd.multiplicity_pos end comm_monoid section monoid_with_zero variable [monoid_with_zero α] lemma ne_zero_of_finite {a b : α} (h : finite a b) : b ≠ 0 := let ⟨n, hn⟩ := h in λ hb, by simpa [hb] using hn variable [decidable_rel ((∣) : α → α → Prop)] @[simp] protected lemma zero (a : α) : multiplicity a 0 = ⊤ := part.eq_none_iff.2 (λ n ⟨⟨k, hk⟩, _⟩, hk (dvd_zero _)) @[simp] lemma multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 := begin apply multiplicity.multiplicity_eq_zero_of_not_dvd, rwa zero_dvd_iff, end end monoid_with_zero section comm_monoid_with_zero variable [comm_monoid_with_zero α] variable [decidable_rel ((∣) : α → α → Prop)] lemma multiplicity_mk_eq_multiplicity [decidable_rel ((∣) : associates α → associates α → Prop)] {a b : α} : multiplicity (associates.mk a) (associates.mk b) = multiplicity a b := begin by_cases h : finite a b, { rw ← part_enat.coe_get (finite_iff_dom.mp h), refine (multiplicity.unique (show (associates.mk a)^(((multiplicity a b).get h)) ∣ associates.mk b, from _) _).symm ; rw [← associates.mk_pow, associates.mk_dvd_mk], { exact pow_multiplicity_dvd h }, { exact is_greatest ((part_enat.lt_coe_iff _ _).mpr (exists.intro (finite_iff_dom.mp h) (nat.lt_succ_self _))) } }, { suffices : ¬ (finite (associates.mk a) (associates.mk b)), { rw [finite_iff_dom, part_enat.not_dom_iff_eq_top] at h this, rw [h, this] }, refine not_finite_iff_forall.mpr (λ n, by { rw [← associates.mk_pow, associates.mk_dvd_mk], exact not_finite_iff_forall.mp h n }) } end end comm_monoid_with_zero section semiring variables [semiring α] [decidable_rel ((∣) : α → α → Prop)] lemma min_le_multiplicity_add {p a b : α} : min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) := (le_total (multiplicity p a) (multiplicity p b)).elim (λ h, by rw [min_eq_left h, multiplicity_le_multiplicity_iff]; exact λ n hn, dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn)) (λ h, by rw [min_eq_right h, multiplicity_le_multiplicity_iff]; exact λ n hn, dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn) end semiring section ring variables [ring α] [decidable_rel ((∣) : α → α → Prop)] @[simp] protected lemma neg (a b : α) : multiplicity a (-b) = multiplicity a b := part.ext' (by simp only [multiplicity, part_enat.find, dvd_neg]) (λ h₁ h₂, part_enat.coe_inj.1 (by rw [part_enat.coe_get]; exact eq.symm (unique ((dvd_neg _ _).2 (pow_multiplicity_dvd _)) (mt (dvd_neg _ _).1 (is_greatest' _ (lt_succ_self _)))))) theorem int.nat_abs (a : ℕ) (b : ℤ) : multiplicity a b.nat_abs = multiplicity (a : ℤ) b := begin cases int.nat_abs_eq b with h h; conv_rhs { rw h }, { rw [int.coe_nat_multiplicity], }, { rw [multiplicity.neg, int.coe_nat_multiplicity], }, end lemma multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) : multiplicity p (a + b) = multiplicity p b := begin apply le_antisymm, { apply part_enat.le_of_lt_add_one, cases part_enat.ne_top_iff.mp (part_enat.ne_top_of_lt h) with k hk, rw [hk], rw_mod_cast [multiplicity_lt_iff_neg_dvd], intro h_dvd, rw [← dvd_add_iff_right] at h_dvd, apply multiplicity.is_greatest _ h_dvd, rw [hk], apply_mod_cast nat.lt_succ_self, rw [pow_dvd_iff_le_multiplicity, nat.cast_add, ← hk, nat.cast_one], exact part_enat.add_one_le_of_lt h }, { convert min_le_multiplicity_add, rw [min_eq_right (le_of_lt h)] } end lemma multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) : multiplicity p (a - b) = multiplicity p b := by { rw [sub_eq_add_neg, multiplicity_add_of_gt]; rwa [multiplicity.neg] } lemma multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) : multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := begin rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with hab|hab|hab, { rw [add_comm, multiplicity_add_of_gt hab, min_eq_left], exact le_of_lt hab }, { contradiction }, { rw [multiplicity_add_of_gt hab, min_eq_right], exact le_of_lt hab}, end end ring section cancel_comm_monoid_with_zero variables [cancel_comm_monoid_with_zero α] lemma finite_mul_aux {p : α} (hp : prime p) : ∀ {n m : ℕ} {a b : α}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b | n m := λ a b ha hb ⟨s, hs⟩, have p ∣ a * b, from ⟨p ^ (n + m) * s, by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩, (hp.2.2 a b this).elim (λ ⟨x, hx⟩, have hn0 : 0 < n, from nat.pos_of_ne_zero (λ hn0, by clear _fun_match _fun_match; simpa [hx, hn0] using ha), have wf : (n - 1) < n, from tsub_lt_self hn0 dec_trivial, have hpx : ¬ p ^ (n - 1 + 1) ∣ x, from λ ⟨y, hy⟩, ha (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 $ by rw [tsub_add_cancel_of_le (succ_le_of_lt hn0)] at hy; simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩), have 1 ≤ n + m, from le_trans hn0 (nat.le_add_right n m), finite_mul_aux hpx hb ⟨s, mul_right_cancel₀ hp.1 begin rw [tsub_add_eq_add_tsub (succ_le_of_lt hn0), tsub_add_cancel_of_le this], clear _fun_match _fun_match finite_mul_aux, simp [*, mul_comm, mul_assoc, mul_left_comm, pow_add] at * end⟩) (λ ⟨x, hx⟩, have hm0 : 0 < m, from nat.pos_of_ne_zero (λ hm0, by clear _fun_match _fun_match; simpa [hx, hm0] using hb), have wf : (m - 1) < m, from tsub_lt_self hm0 dec_trivial, have hpx : ¬ p ^ (m - 1 + 1) ∣ x, from λ ⟨y, hy⟩, hb (hx.symm ▸ ⟨y, mul_right_cancel₀ hp.1 $ by rw [tsub_add_cancel_of_le (succ_le_of_lt hm0)] at hy; simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩), finite_mul_aux ha hpx ⟨s, mul_right_cancel₀ hp.1 begin rw [add_assoc, tsub_add_cancel_of_le (succ_le_of_lt hm0)], clear _fun_match _fun_match finite_mul_aux, simp [*, mul_comm, mul_assoc, mul_left_comm, pow_add] at * end⟩) lemma finite_mul {p a b : α} (hp : prime p) : finite p a → finite p b → finite p (a * b) := λ ⟨n, hn⟩ ⟨m, hm⟩, ⟨n + m, finite_mul_aux hp hn hm⟩ lemma finite_mul_iff {p a b : α} (hp : prime p) : finite p (a * b) ↔ finite p a ∧ finite p b := ⟨λ h, ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, λ h, finite_mul hp h.1 h.2⟩ lemma finite_pow {p a : α} (hp : prime p) : Π {k : ℕ} (ha : finite p a), finite p (a ^ k) | 0 ha := ⟨0, by simp [mt is_unit_iff_dvd_one.2 hp.2.1]⟩ | (k+1) ha := by rw [pow_succ]; exact finite_mul hp ha (finite_pow ha) variable [decidable_rel ((∣) : α → α → Prop)] @[simp] lemma multiplicity_self {a : α} (ha : ¬is_unit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := by { rw ← nat.cast_one, exact eq_coe_iff.2 ⟨by simp, λ ⟨b, hb⟩, ha (is_unit_iff_dvd_one.2 ⟨b, mul_left_cancel₀ ha0 $ by { clear _fun_match, simpa [pow_succ, mul_assoc] using hb }⟩)⟩ } @[simp] lemma get_multiplicity_self {a : α} (ha : finite a a) : get (multiplicity a a) ha = 1 := part_enat.get_eq_iff_eq_coe.2 (eq_coe_iff.2 ⟨by simp, λ ⟨b, hb⟩, by rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc, mul_right_inj' (ne_zero_of_finite ha)] at hb; exact mt is_unit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by clear _fun_match; simp * at *⟩⟩) protected lemma mul' {p a b : α} (hp : prime p) (h : (multiplicity p (a * b)).dom) : get (multiplicity p (a * b)) h = get (multiplicity p a) ((finite_mul_iff hp).1 h).1 + get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a, from pow_multiplicity_dvd _, have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b, from pow_multiplicity_dvd _, have hpoweq : p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 + get (multiplicity p b) ((finite_mul_iff hp).1 h).2) = p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 * p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2, by simp [pow_add], have hdiv : p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 + get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣ a * b, by rw [hpoweq]; apply mul_dvd_mul; assumption, have hsucc : ¬p ^ ((get (multiplicity p a) ((finite_mul_iff hp).1 h).1 + get (multiplicity p b) ((finite_mul_iff hp).1 h).2) + 1) ∣ a * b, from λ h, by exact not_or (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _)) (_root_.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h), by rw [← part_enat.coe_inj, part_enat.coe_get, eq_coe_iff]; exact ⟨hdiv, hsucc⟩ open_locale classical protected lemma mul {p a b : α} (hp : prime p) : multiplicity p (a * b) = multiplicity p a + multiplicity p b := if h : finite p a ∧ finite p b then by rw [← part_enat.coe_get (finite_iff_dom.1 h.1), ← part_enat.coe_get (finite_iff_dom.1 h.2), ← part_enat.coe_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← nat.cast_add, part_enat.coe_inj, multiplicity.mul' hp]; refl else begin rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)], cases not_and_distrib.1 h with h h; simp [eq_top_iff_not_finite.2 h] end lemma finset.prod {β : Type*} {p : α} (hp : prime p) (s : finset β) (f : β → α) : multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) := begin classical, induction s using finset.induction with a s has ih h, { simp only [finset.sum_empty, finset.prod_empty], convert one_right hp.not_unit }, { simp [has, ← ih], convert multiplicity.mul hp } end protected lemma pow' {p a : α} (hp : prime p) (ha : finite p a) : ∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha | 0 := by simp [one_right hp.not_unit] | (k+1) := have multiplicity p (a ^ (k + 1)) = multiplicity p (a * a ^ k), by rw pow_succ, by rw [get_eq_get_of_eq _ _ this, multiplicity.mul' hp, pow', add_mul, one_mul, add_comm] lemma pow {p a : α} (hp : prime p) : ∀ {k : ℕ}, multiplicity p (a ^ k) = k • (multiplicity p a) | 0 := by simp [one_right hp.not_unit] | (succ k) := by simp [pow_succ, succ_nsmul, pow, multiplicity.mul hp] lemma multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬ is_unit p) (n : ℕ) : multiplicity p (p ^ n) = n := by { rw [eq_coe_iff], use dvd_rfl, rw [pow_dvd_pow_iff h0 hu], apply nat.not_succ_le_self } lemma multiplicity_pow_self_of_prime {p : α} (hp : prime p) (n : ℕ) : multiplicity p (p ^ n) = n := multiplicity_pow_self hp.ne_zero hp.not_unit n end cancel_comm_monoid_with_zero section valuation variables {R : Type*} [comm_ring R] [is_domain R] {p : R} [decidable_rel (has_dvd.dvd : R → R → Prop)] /-- `multiplicity` of a prime inan integral domain as an additive valuation to `part_enat`. -/ noncomputable def add_valuation (hp : prime p) : add_valuation R part_enat := add_valuation.of (multiplicity p) (multiplicity.zero _) (one_right hp.not_unit) (λ _ _, min_le_multiplicity_add) (λ a b, multiplicity.mul hp) @[simp] lemma add_valuation_apply {hp : prime p} {r : R} : add_valuation hp r = multiplicity p r := rfl end valuation end multiplicity section nat open multiplicity lemma multiplicity_eq_zero_of_coprime {p a b : ℕ} (hp : p ≠ 1) (hle : multiplicity p a ≤ multiplicity p b) (hab : nat.coprime a b) : multiplicity p a = 0 := begin rw [multiplicity_le_multiplicity_iff] at hle, rw [← nonpos_iff_eq_zero, ← not_lt, part_enat.pos_iff_one_le, ← nat.cast_one, ← pow_dvd_iff_le_multiplicity], assume h, have := nat.dvd_gcd h (hle _ h), rw [coprime.gcd_eq_one hab, nat.dvd_one, pow_one] at this, exact hp this end end nat
ace8306a248d90e5148dc1c07a274cc9abf802a3
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/run/eq23.lean
e82fde3542e54bebf9a37618f2f8b012ca86eba7
[ "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
594
lean
open nat inductive tree (A : Type) := | leaf : A → tree A | node : tree_list A → tree A with tree_list := | nil : tree_list A | cons : tree A → tree_list A → tree_list A namespace tree_list definition len {A : Type} : tree_list A → nat | len (nil _) := 0 | len (cons t l) := len l + 1 theorem len_nil {A : Type} : len (nil A) = 0 := rfl theorem len_cons {A : Type} (t : tree A) (l : tree_list A) : len (cons t l) = len l + 1 := rfl variables (A : Type) (t1 t2 t3 : tree A) example : len (cons t1 (cons t2 (cons t3 (nil A)))) = 3 := rfl print definition len end tree_list
ff0c624464a594b463575207e65db4f531c361bc
05b503addd423dd68145d68b8cde5cd595d74365
/src/data/polynomial.lean
b989c57a3cbd7b39bcbe7b27e53ec8e8b6e75853
[ "Apache-2.0" ]
permissive
aestriplex/mathlib
77513ff2b176d74a3bec114f33b519069788811d
e2fa8b2b1b732d7c25119229e3cdfba8370cb00f
refs/heads/master
1,621,969,960,692
1,586,279,279,000
1,586,279,279,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
105,460
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker Theory of univariate polynomials, represented as `add_monoid_algebra α ℕ`, where α is a commutative semiring. -/ import data.monoid_algebra ring_theory.algebra import algebra.gcd_domain ring_theory.euclidean_domain ring_theory.multiplicity import tactic.ring_exp noncomputable theory local attribute [instance, priority 100] classical.prop_decidable local attribute [instance, priority 10] is_semiring_hom.comp is_ring_hom.comp /-- `polynomial α` is the type of univariate polynomials over `α`. Polynomials should be seen as (semi-)rings with the additional constructor `X`. The embedding from α is called `C`. -/ def polynomial (α : Type*) [comm_semiring α] := add_monoid_algebra α ℕ open finsupp finset add_monoid_algebra namespace polynomial universes u v variables {α : Type u} {β : Type v} {a b : α} {m n : ℕ} section comm_semiring variables [comm_semiring α] {p q r : polynomial α} instance : inhabited (polynomial α) := finsupp.inhabited instance : comm_semiring (polynomial α) := add_monoid_algebra.comm_semiring instance : has_scalar α (polynomial α) := add_monoid_algebra.has_scalar instance : semimodule α (polynomial α) := add_monoid_algebra.semimodule /-- the coercion turning a `polynomial` into the function which reports the coefficient of a given monomial `X^n` -/ def coeff_coe_to_fun : has_coe_to_fun (polynomial α) := finsupp.has_coe_to_fun local attribute [instance] coeff_coe_to_fun @[simp] lemma support_zero : (0 : polynomial α).support = ∅ := rfl /-- `monomial s a` is the monomial `a * X^s` -/ @[reducible] def monomial (n : ℕ) (a : α) : polynomial α := finsupp.single n a /-- `C a` is the constant polynomial `a`. -/ def C (a : α) : polynomial α := monomial 0 a /-- `X` is the polynomial variable (aka indeterminant). -/ def X : polynomial α := monomial 1 1 /-- coeff p n is the coefficient of X^n in p -/ def coeff (p : polynomial α) := p.to_fun @[simp] lemma coeff_mk (s) (f) (h) : coeff (finsupp.mk s f h : polynomial α) = f := rfl instance [has_repr α] : has_repr (polynomial α) := ⟨λ p, if p = 0 then "0" else (p.support.sort (≤)).foldr (λ n a, a ++ (if a = "" then "" else " + ") ++ if n = 0 then "C (" ++ repr (coeff p n) ++ ")" else if n = 1 then if (coeff p n) = 1 then "X" else "C (" ++ repr (coeff p n) ++ ") * X" else if (coeff p n) = 1 then "X ^ " ++ repr n else "C (" ++ repr (coeff p n) ++ ") * X ^ " ++ repr n) ""⟩ theorem ext_iff {p q : polynomial α} : p = q ↔ ∀ n, coeff p n = coeff q n := ⟨λ h n, h ▸ rfl, finsupp.ext⟩ @[ext] lemma ext {p q : polynomial α} : (∀ n, coeff p n = coeff q n) → p = q := (@ext_iff _ _ p q).2 /-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`. `degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise `degree 0 = ⊥`. -/ def degree (p : polynomial α) : with_bot ℕ := p.support.sup some lemma degree_lt_wf : well_founded (λp q : polynomial α, degree p < degree q) := inv_image.wf degree (with_bot.well_founded_lt nat.lt_wf) instance : has_well_founded (polynomial α) := ⟨_, degree_lt_wf⟩ /-- `nat_degree p` forces `degree p` to ℕ, by defining nat_degree 0 = 0. -/ def nat_degree (p : polynomial α) : ℕ := (degree p).get_or_else 0 lemma single_eq_C_mul_X : ∀{n}, monomial n a = C a * X^n | 0 := (mul_one _).symm | (n+1) := calc monomial (n + 1) a = monomial n a * X : by rw [X, single_mul_single, mul_one] ... = (C a * X^n) * X : by rw [single_eq_C_mul_X] ... = C a * X^(n+1) : by simp only [pow_add, mul_assoc, pow_one] lemma sum_C_mul_X_eq (p : polynomial α) : p.sum (λn a, C a * X^n) = p := eq.trans (sum_congr rfl $ assume n hn, single_eq_C_mul_X.symm) (finsupp.sum_single _) @[elab_as_eliminator] protected lemma induction_on {M : polynomial α → Prop} (p : polynomial α) (h_C : ∀a, M (C a)) (h_add : ∀p q, M p → M q → M (p + q)) (h_monomial : ∀(n : ℕ) (a : α), M (C a * X^n) → M (C a * X^(n+1))) : M p := have ∀{n:ℕ} {a}, M (C a * X^n), begin assume n a, induction n with n ih, { simp only [pow_zero, mul_one, h_C] }, { exact h_monomial _ _ ih } end, finsupp.induction p (suffices M (C 0), by { convert this, exact single_zero.symm, }, h_C 0) (assume n a p _ _ hp, suffices M (C a * X^n + p), by { convert this, exact single_eq_C_mul_X }, h_add _ _ this hp) @[simp] lemma C_0 : C (0 : α) = 0 := single_zero @[simp] lemma C_1 : C (1 : α) = 1 := rfl @[simp] lemma C_mul : C (a * b) = C a * C b := (@single_mul_single _ _ _ _ 0 0 a b).symm @[simp] lemma C_add : C (a + b) = C a + C b := finsupp.single_add instance C.is_semiring_hom : is_semiring_hom (C : α → polynomial α) := ⟨C_0, C_1, λ _ _, C_add, λ _ _, C_mul⟩ @[simp] lemma C_pow : C (a ^ n) = C a ^ n := is_semiring_hom.map_pow _ _ _ lemma nat_cast_eq_C (n : ℕ) : (n : polynomial α) = C n := by refine (nat.eq_cast (λ n, C (n : α)) _ _ _ n).symm; simp section coeff lemma apply_eq_coeff : p n = coeff p n := rfl @[simp] lemma coeff_zero (n : ℕ) : coeff (0 : polynomial α) n = 0 := rfl lemma coeff_single : coeff (single n a) m = if n = m then a else 0 := by { dsimp [single, finsupp.single], congr } @[simp] lemma coeff_one_zero : coeff (1 : polynomial α) 0 = 1 := coeff_single @[simp] lemma coeff_add (p q : polynomial α) (n : ℕ) : coeff (p + q) n = coeff p n + coeff q n := rfl instance coeff.is_add_monoid_hom {n : ℕ} : is_add_monoid_hom (λ p : polynomial α, p.coeff n) := { map_add := λ p q, coeff_add p q n, map_zero := coeff_zero _ } lemma coeff_C : coeff (C a) n = ite (n = 0) a 0 := by simp [coeff, eq_comm, C, monomial, single]; congr @[simp] lemma coeff_C_zero : coeff (C a) 0 = a := coeff_single @[simp] lemma coeff_X_one : coeff (X : polynomial α) 1 = 1 := coeff_single @[simp] lemma coeff_X_zero : coeff (X : polynomial α) 0 = 0 := coeff_single lemma coeff_X : coeff (X : polynomial α) n = if 1 = n then 1 else 0 := coeff_single lemma coeff_C_mul_X (x : α) (k n : ℕ) : coeff (C x * X^k : polynomial α) n = if n = k then x else 0 := by rw [← single_eq_C_mul_X]; simp [monomial, single, eq_comm, coeff]; congr lemma coeff_sum [comm_semiring β] (n : ℕ) (f : ℕ → α → polynomial β) : coeff (p.sum f) n = p.sum (λ a b, coeff (f a b) n) := finsupp.sum_apply @[simp] lemma coeff_C_mul (p : polynomial α) : coeff (C a * p) n = a * coeff p n := begin conv in (a * _) { rw [← @sum_single _ _ _ p, coeff_sum] }, rw [mul_def, C, sum_single_index], { simp [coeff_single, finsupp.mul_sum, coeff_sum], apply sum_congr rfl, assume i hi, by_cases i = n; simp [h] }, { simp [finsupp.sum], erw [add_monoid.smul_zero], }, -- TODO why doesn't simp do this? end @[simp] lemma coeff_smul (p : polynomial α) (r : α) (n : ℕ) : coeff (r • p) n = r * coeff p n := finsupp.smul_apply lemma C_mul' (a : α) (f : polynomial α) : C a * f = a • f := ext $ λ n, coeff_C_mul f @[simp, priority 990] lemma coeff_one (n : ℕ) : coeff (1 : polynomial α) n = if 0 = n then 1 else 0 := coeff_single @[simp] lemma coeff_X_pow (k n : ℕ) : coeff (X^k : polynomial α) n = if n = k then 1 else 0 := by simpa only [C_1, one_mul] using coeff_C_mul_X (1:α) k n lemma coeff_mul (p q : polynomial α) (n : ℕ) : coeff (p * q) n = (nat.antidiagonal n).sum (λ x, coeff p x.1 * coeff q x.2) := have hite : ∀ a : ℕ × ℕ, ite (a.1 + a.2 = n) (coeff p (a.fst) * coeff q (a.snd)) 0 ≠ 0 → a.1 + a.2 = n, from λ a ha, by_contradiction (λ h, absurd (eq.refl (0 : α)) (by rwa if_neg h at ha)), calc coeff (p * q) n = p.support.sum (λ a, q.support.sum (λ b, ite (a + b = n) (coeff p a * coeff q b) 0)) : by simp only [mul_def, coeff_sum, coeff_single]; refl ... = (p.support.product q.support).sum (λ v : ℕ × ℕ, ite (v.1 + v.2 = n) (coeff p v.1 * coeff q v.2) 0) : by rw sum_product ... = (nat.antidiagonal n).sum (λ x, coeff p x.1 * coeff q x.2) : begin refine sum_bij_ne_zero (λ x _ _, x) (λ x _ hx, nat.mem_antidiagonal.2 (hite x hx)) (λ _ _ _ _ _ _ h, h) (λ x h₁ h₂, ⟨x, _, _, rfl⟩) _, { rw [mem_product, mem_support_iff, mem_support_iff], exact ⟨ne_zero_of_mul_ne_zero_right h₂, ne_zero_of_mul_ne_zero_left h₂⟩ }, { rw nat.mem_antidiagonal at h₁, rwa [if_pos h₁] }, { intros x h hx, rw [if_pos (hite x hx)] } end theorem coeff_mul_X_pow (p : polynomial α) (n d : ℕ) : coeff (p * polynomial.X ^ n) (d + n) = coeff p d := begin rw [coeff_mul, sum_eq_single (d,n), coeff_X_pow, if_pos rfl, mul_one], { rintros ⟨i,j⟩ h1 h2, rw [coeff_X_pow, if_neg, mul_zero], rintro rfl, apply h2, rw [nat.mem_antidiagonal, add_right_cancel_iff] at h1, subst h1 }, { exact λ h1, (h1 (nat.mem_antidiagonal.2 rfl)).elim } end theorem coeff_mul_X (p : polynomial α) (n : ℕ) : coeff (p * X) (n + 1) = coeff p n := by simpa only [pow_one] using coeff_mul_X_pow p 1 n theorem mul_X_pow_eq_zero {p : polynomial α} {n : ℕ} (H : p * X ^ n = 0) : p = 0 := ext $ λ k, (coeff_mul_X_pow p n k).symm.trans $ ext_iff.1 H (k+n) end coeff lemma C_inj : C a = C b ↔ a = b := ⟨λ h, coeff_C_zero.symm.trans (h.symm ▸ coeff_C_zero), congr_arg C⟩ section eval₂ variables [semiring β] variables (f : α → β) (x : β) open is_semiring_hom /-- Evaluate a polynomial `p` given a ring hom `f` from the scalar ring to the target and a value `x` for the variable in the target -/ def eval₂ (p : polynomial α) : β := p.sum (λ e a, f a * x ^ e) variables [is_semiring_hom f] @[simp] lemma eval₂_C : (C a).eval₂ f x = f a := (sum_single_index $ by rw [map_zero f, zero_mul]).trans $ by rw [pow_zero, mul_one] @[simp] lemma eval₂_X : X.eval₂ f x = x := (sum_single_index $ by rw [map_zero f, zero_mul]).trans $ by rw [map_one f, one_mul, pow_one] @[simp] lemma eval₂_zero : (0 : polynomial α).eval₂ f x = 0 := finsupp.sum_zero_index @[simp] lemma eval₂_add : (p + q).eval₂ f x = p.eval₂ f x + q.eval₂ f x := finsupp.sum_add_index (λ _, by rw [map_zero f, zero_mul]) (λ _ _ _, by rw [map_add f, add_mul]) @[simp] lemma eval₂_one : (1 : polynomial α).eval₂ f x = 1 := by rw [← C_1, eval₂_C, map_one f] instance eval₂.is_add_monoid_hom : is_add_monoid_hom (eval₂ f x) := { map_zero := eval₂_zero _ _, map_add := λ _ _, eval₂_add _ _ } end eval₂ section eval₂ variables [comm_semiring β] variables (f : α → β) [is_semiring_hom f] (x : β) open is_semiring_hom @[simp] lemma eval₂_mul : (p * q).eval₂ f x = p.eval₂ f x * q.eval₂ f x := begin dunfold eval₂, rw [mul_def, finsupp.sum_mul _ p], simp only [finsupp.mul_sum _ q], rw [sum_sum_index], { apply sum_congr rfl, assume i hi, dsimp only, rw [sum_sum_index], { apply sum_congr rfl, assume j hj, dsimp only, rw [sum_single_index, map_mul f, pow_add], { simp only [mul_assoc, mul_left_comm] }, { rw [map_zero f, zero_mul] } }, { intro, rw [map_zero f, zero_mul] }, { intros, rw [map_add f, add_mul] } }, { intro, rw [map_zero f, zero_mul] }, { intros, rw [map_add f, add_mul] } end instance eval₂.is_semiring_hom : is_semiring_hom (eval₂ f x) := ⟨eval₂_zero _ _, eval₂_one _ _, λ _ _, eval₂_add _ _, λ _ _, eval₂_mul _ _⟩ lemma eval₂_pow (n : ℕ) : (p ^ n).eval₂ f x = p.eval₂ f x ^ n := map_pow _ _ _ lemma eval₂_sum (p : polynomial α) (g : ℕ → α → polynomial α) (x : β) : (p.sum g).eval₂ f x = p.sum (λ n a, (g n a).eval₂ f x) := finsupp.sum_sum_index (by simp [is_add_monoid_hom.map_zero f]) (by intros; simp [right_distrib, is_add_monoid_hom.map_add f]) end eval₂ section eval variable {x : α} /-- `eval x p` is the evaluation of the polynomial `p` at `x` -/ def eval : α → polynomial α → α := eval₂ id @[simp] lemma eval_C : (C a).eval x = a := eval₂_C _ _ @[simp] lemma eval_X : X.eval x = x := eval₂_X _ _ @[simp] lemma eval_zero : (0 : polynomial α).eval x = 0 := eval₂_zero _ _ @[simp] lemma eval_add : (p + q).eval x = p.eval x + q.eval x := eval₂_add _ _ @[simp] lemma eval_one : (1 : polynomial α).eval x = 1 := eval₂_one _ _ @[simp] lemma eval_mul : (p * q).eval x = p.eval x * q.eval x := eval₂_mul _ _ instance eval.is_semiring_hom : is_semiring_hom (eval x) := eval₂.is_semiring_hom _ _ @[simp] lemma eval_pow (n : ℕ) : (p ^ n).eval x = p.eval x ^ n := eval₂_pow _ _ _ lemma eval_sum (p : polynomial α) (f : ℕ → α → polynomial α) (x : α) : (p.sum f).eval x = p.sum (λ n a, (f n a).eval x) := eval₂_sum _ _ _ _ lemma eval₂_hom [comm_semiring β] (f : α → β) [is_semiring_hom f] (x : α) : p.eval₂ f (f x) = f (p.eval x) := polynomial.induction_on p (by simp) (by simp [is_semiring_hom.map_add f] {contextual := tt}) (by simp [is_semiring_hom.map_mul f, eval_pow, is_semiring_hom.map_pow f, pow_succ', (mul_assoc _ _ _).symm] {contextual := tt}) /-- `is_root p x` implies `x` is a root of `p`. The evaluation of `p` at `x` is zero -/ def is_root (p : polynomial α) (a : α) : Prop := p.eval a = 0 instance [decidable_eq α] : decidable (is_root p a) := by unfold is_root; apply_instance @[simp] lemma is_root.def : is_root p a ↔ p.eval a = 0 := iff.rfl lemma root_mul_left_of_is_root (p : polynomial α) {q : polynomial α} : is_root q a → is_root (p * q) a := λ H, by rw [is_root, eval_mul, is_root.def.1 H, mul_zero] lemma root_mul_right_of_is_root {p : polynomial α} (q : polynomial α) : is_root p a → is_root (p * q) a := λ H, by rw [is_root, eval_mul, is_root.def.1 H, zero_mul] lemma coeff_zero_eq_eval_zero (p : polynomial α) : coeff p 0 = p.eval 0 := calc coeff p 0 = coeff p 0 * 0 ^ 0 : by simp ... = p.eval 0 : eq.symm $ finset.sum_eq_single _ (λ b _ hb, by simp [zero_pow (nat.pos_of_ne_zero hb)]) (by simp) lemma zero_is_root_of_coeff_zero_eq_zero {p : polynomial α} (hp : p.coeff 0 = 0) : is_root p 0 := by rwa coeff_zero_eq_eval_zero at hp end eval section comp def comp (p q : polynomial α) : polynomial α := p.eval₂ C q lemma eval₂_comp [comm_semiring β] (f : α → β) [is_semiring_hom f] {x : β} : (p.comp q).eval₂ f x = p.eval₂ f (q.eval₂ f x) := show (p.sum (λ e a, C a * q ^ e)).eval₂ f x = p.eval₂ f (eval₂ f x q), by simp only [eval₂_mul, eval₂_C, eval₂_pow, eval₂_sum]; refl lemma eval_comp : (p.comp q).eval a = p.eval (q.eval a) := eval₂_comp _ @[simp] lemma comp_X : p.comp X = p := begin refine ext (λ n, _), rw [comp, eval₂], conv in (C _ * _) { rw ← single_eq_C_mul_X }, rw finsupp.sum_single end @[simp] lemma X_comp : X.comp p = p := eval₂_X _ _ @[simp] lemma comp_C : p.comp (C a) = C (p.eval a) := begin dsimp [comp, eval₂, eval, finsupp.sum], rw [← p.support.sum_hom (@C α _)], apply finset.sum_congr rfl; simp end @[simp] lemma C_comp : (C a).comp p = C a := eval₂_C _ _ @[simp] lemma comp_zero : p.comp (0 : polynomial α) = C (p.eval 0) := by rw [← C_0, comp_C] @[simp] lemma zero_comp : comp (0 : polynomial α) p = 0 := by rw [← C_0, C_comp] @[simp] lemma comp_one : p.comp 1 = C (p.eval 1) := by rw [← C_1, comp_C] @[simp] lemma one_comp : comp (1 : polynomial α) p = 1 := by rw [← C_1, C_comp] instance : is_semiring_hom (λ q : polynomial α, q.comp p) := by unfold comp; apply_instance @[simp] lemma add_comp : (p + q).comp r = p.comp r + q.comp r := eval₂_add _ _ @[simp] lemma mul_comp : (p * q).comp r = p.comp r * q.comp r := eval₂_mul _ _ end comp /-- `leading_coeff p` gives the coefficient of the highest power of `X` in `p`-/ def leading_coeff (p : polynomial α) : α := coeff p (nat_degree p) /-- a polynomial is `monic` if its leading coefficient is 1 -/ def monic (p : polynomial α) := leading_coeff p = (1 : α) lemma monic.def : monic p ↔ leading_coeff p = 1 := iff.rfl instance monic.decidable [decidable_eq α] : decidable (monic p) := by unfold monic; apply_instance @[simp] lemma monic.leading_coeff {p : polynomial α} (hp : p.monic) : leading_coeff p = 1 := hp @[simp] lemma degree_zero : degree (0 : polynomial α) = ⊥ := rfl @[simp] lemma nat_degree_zero : nat_degree (0 : polynomial α) = 0 := rfl @[simp] lemma degree_C (ha : a ≠ 0) : degree (C a) = (0 : with_bot ℕ) := show sup (ite (a = 0) ∅ {0}) some = 0, by rw if_neg ha; refl lemma degree_C_le : degree (C a) ≤ (0 : with_bot ℕ) := by by_cases h : a = 0; [rw [h, C_0], rw [degree_C h]]; [exact bot_le, exact le_refl _] lemma degree_one_le : degree (1 : polynomial α) ≤ (0 : with_bot ℕ) := by rw [← C_1]; exact degree_C_le lemma degree_eq_bot : degree p = ⊥ ↔ p = 0 := ⟨λ h, by rw [degree, ← max_eq_sup_with_bot] at h; exact support_eq_empty.1 (max_eq_none.1 h), λ h, h.symm ▸ rfl⟩ lemma degree_eq_nat_degree (hp : p ≠ 0) : degree p = (nat_degree p : with_bot ℕ) := let ⟨n, hn⟩ := classical.not_forall.1 (mt option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) in have hn : degree p = some n := not_not.1 hn, by rw [nat_degree, hn]; refl lemma degree_eq_iff_nat_degree_eq {p : polynomial α} {n : ℕ} (hp : p ≠ 0) : p.degree = n ↔ p.nat_degree = n := by rw [degree_eq_nat_degree hp, with_bot.coe_eq_coe] lemma degree_eq_iff_nat_degree_eq_of_pos {p : polynomial α} {n : ℕ} (hn : n > 0) : p.degree = n ↔ p.nat_degree = n := begin split, { intro H, rwa ← degree_eq_iff_nat_degree_eq, rintro rfl, rw degree_zero at H, exact option.no_confusion H }, { intro H, rwa degree_eq_iff_nat_degree_eq, rintro rfl, rw nat_degree_zero at H, rw H at hn, exact lt_irrefl _ hn } end lemma nat_degree_eq_of_degree_eq_some {p : polynomial α} {n : ℕ} (h : degree p = n) : nat_degree p = n := have hp0 : p ≠ 0, from λ hp0, by rw hp0 at h; exact option.no_confusion h, option.some_inj.1 $ show (nat_degree p : with_bot ℕ) = n, by rwa [← degree_eq_nat_degree hp0] @[simp] lemma degree_le_nat_degree : degree p ≤ nat_degree p := begin by_cases hp : p = 0, { rw hp, exact bot_le }, rw [degree_eq_nat_degree hp], exact le_refl _ end lemma nat_degree_eq_of_degree_eq [comm_semiring β] {q : polynomial β} (h : degree p = degree q) : nat_degree p = nat_degree q := by unfold nat_degree; rw h lemma le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : with_bot ℕ) ≤ degree p := show @has_le.le (with_bot ℕ) _ (some n : with_bot ℕ) (p.support.sup some : with_bot ℕ), from finset.le_sup (finsupp.mem_support_iff.2 h) lemma le_nat_degree_of_ne_zero (h : coeff p n ≠ 0) : n ≤ nat_degree p := begin rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree], exact le_degree_of_ne_zero h, { assume h, subst h, exact h rfl } end lemma degree_le_degree (h : coeff q (nat_degree p) ≠ 0) : degree p ≤ degree q := begin by_cases hp : p = 0, { rw hp, exact bot_le }, { rw degree_eq_nat_degree hp, exact le_degree_of_ne_zero h } end @[simp] lemma nat_degree_C (a : α) : nat_degree (C a) = 0 := begin by_cases ha : a = 0, { have : C a = 0, { rw [ha, C_0] }, rw [nat_degree, degree_eq_bot.2 this], refl }, { rw [nat_degree, degree_C ha], refl } end @[simp] lemma nat_degree_one : nat_degree (1 : polynomial α) = 0 := nat_degree_C 1 @[simp] lemma nat_degree_nat_cast (n : ℕ) : nat_degree (n : polynomial α) = 0 := by simp [nat_cast_eq_C] @[simp] lemma degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n := by rw [← single_eq_C_mul_X, degree, support_single_ne_zero ha]; refl lemma degree_monomial_le (n : ℕ) (a : α) : degree (C a * X ^ n) ≤ n := if h : a = 0 then by rw [h, C_0, zero_mul]; exact bot_le else le_of_eq (degree_monomial n h) lemma coeff_eq_zero_of_degree_lt (h : degree p < n) : coeff p n = 0 := not_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h)) lemma coeff_eq_zero_of_nat_degree_lt {p : polynomial α} {n : ℕ} (h : p.nat_degree < n) : p.coeff n = 0 := begin apply coeff_eq_zero_of_degree_lt, by_cases hp : p = 0, { subst hp, exact with_bot.bot_lt_coe n }, { rwa [degree_eq_nat_degree hp, with_bot.coe_lt_coe] } end -- TODO find a home (this file) @[simp] lemma finset_sum_coeff (s : finset β) (f : β → polynomial α) (n : ℕ) : coeff (s.sum f) n = s.sum (λ b, coeff (f b) n) := (s.sum_hom (λ q : polynomial α, q.coeff n)).symm -- We need the explicit `decidable` argument here because an exotic one shows up in a moment! lemma ite_le_nat_degree_coeff (p : polynomial α) (n : ℕ) (I : decidable (n < 1 + nat_degree p)) : @ite (n < 1 + nat_degree p) I _ (coeff p n) 0 = coeff p n := begin split_ifs, { refl }, { exact (coeff_eq_zero_of_nat_degree_lt (not_le.1 (λ w, h (nat.lt_one_add_iff.2 w)))).symm, } end lemma as_sum (p : polynomial α) : p = (range (p.nat_degree + 1)).sum (λ i, C (p.coeff i) * X^i) := begin ext n, simp only [add_comm, coeff_X_pow, coeff_C_mul, finset.mem_range, finset.sum_mul_boole, finset_sum_coeff, ite_le_nat_degree_coeff], end lemma monic.as_sum {p : polynomial α} (hp : p.monic) : p = X^(p.nat_degree) + ((finset.range p.nat_degree).sum $ λ i, C (p.coeff i) * X^i) := begin conv_lhs { rw [p.as_sum, finset.sum_range_succ] }, suffices : C (p.coeff p.nat_degree) = 1, { rw [this, one_mul] }, exact congr_arg C hp end section map variables [comm_semiring β] variables (f : α → β) /-- `map f p` maps a polynomial `p` across a ring hom `f` -/ def map : polynomial α → polynomial β := eval₂ (C ∘ f) X variables [is_semiring_hom f] instance is_semiring_hom_C_f : is_semiring_hom (C ∘ f) := is_semiring_hom.comp _ _ @[simp] lemma map_C : (C a).map f = C (f a) := eval₂_C _ _ @[simp] lemma map_X : X.map f = X := eval₂_X _ _ @[simp] lemma map_zero : (0 : polynomial α).map f = 0 := eval₂_zero _ _ @[simp] lemma map_add : (p + q).map f = p.map f + q.map f := eval₂_add _ _ @[simp] lemma map_one : (1 : polynomial α).map f = 1 := eval₂_one _ _ @[simp] lemma map_mul : (p * q).map f = p.map f * q.map f := eval₂_mul _ _ instance map.is_semiring_hom : is_semiring_hom (map f) := eval₂.is_semiring_hom _ _ @[simp] lemma map_pow (n : ℕ) : (p ^ n).map f = p.map f ^ n := eval₂_pow _ _ _ lemma coeff_map (n : ℕ) : coeff (p.map f) n = f (coeff p n) := begin rw [map, eval₂, coeff_sum], conv_rhs { rw [← sum_C_mul_X_eq p, coeff_sum, finsupp.sum, ← p.support.sum_hom f], }, refine finset.sum_congr rfl (λ x hx, _), simp [function.comp, coeff_C_mul_X, is_semiring_hom.map_mul f], split_ifs; simp [is_semiring_hom.map_zero f], end lemma map_map {γ : Type*} [comm_semiring γ] (g : β → γ) [is_semiring_hom g] (p : polynomial α) : (p.map f).map g = p.map (λ x, g (f x)) := ext (by simp [coeff_map]) lemma eval₂_map {γ : Type*} [comm_semiring γ] (g : β → γ) [is_semiring_hom g] (x : γ) : (p.map f).eval₂ g x = p.eval₂ (λ y, g (f y)) x := polynomial.induction_on p (by simp) (by simp [is_semiring_hom.map_add f] {contextual := tt}) (by simp [is_semiring_hom.map_mul f, is_semiring_hom.map_pow f, pow_succ', (mul_assoc _ _ _).symm] {contextual := tt}) lemma eval_map (x : β) : (p.map f).eval x = p.eval₂ f x := eval₂_map _ _ _ @[simp] lemma map_id : p.map id = p := by simp [id, polynomial.ext_iff, coeff_map] lemma mem_map_range {p : polynomial β} : p ∈ set.range (map f) ↔ ∀ n, p.coeff n ∈ (set.range f) := begin split, { rintro ⟨p, rfl⟩ n, rw coeff_map, exact set.mem_range_self _ }, { intro h, rw p.as_sum, apply is_add_submonoid.finset_sum_mem, intros i hi, rcases h i with ⟨c, hc⟩, use [C c * X^i], rw [map_mul, map_C, hc, map_pow, map_X] } end end map section variables {γ : Type*} [comm_semiring β] [comm_semiring γ] variables (f : α → β) (g : β → γ) [is_semiring_hom f] [is_semiring_hom g] (p) lemma hom_eval₂ (x : β) : g (p.eval₂ f x) = p.eval₂ (g ∘ f) (g x) := begin apply polynomial.induction_on p; clear p, { intros a, rw [eval₂_C, eval₂_C] }, { intros p q hp hq, simp only [hp, hq, eval₂_add, is_semiring_hom.map_add g] }, { intros n a ih, replace ih := congr_arg (λ y, y * g x) ih, simpa [pow_succ', is_semiring_hom.map_mul g, (mul_assoc _ _ _).symm, eval₂_C, eval₂_mul, eval₂_X] using ih } end end lemma coeff_nat_degree_eq_zero_of_degree_lt (h : degree p < degree q) : coeff p (nat_degree q) = 0 := coeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_nat_degree) lemma ne_zero_of_degree_gt {n : with_bot ℕ} (h : n < degree p) : p ≠ 0 := mt degree_eq_bot.2 (ne.symm (ne_of_lt (lt_of_le_of_lt bot_le h))) lemma eq_C_of_degree_le_zero (h : degree p ≤ 0) : p = C (coeff p 0) := begin refine ext (λ n, _), cases n, { simp }, { have : degree p < ↑(nat.succ n) := lt_of_le_of_lt h (with_bot.some_lt_some.2 (nat.succ_pos _)), rw [coeff_C, if_neg (nat.succ_ne_zero _), coeff_eq_zero_of_degree_lt this] } end lemma eq_C_of_degree_eq_zero (h : degree p = 0) : p = C (coeff p 0) := eq_C_of_degree_le_zero (h ▸ le_refl _) lemma degree_le_zero_iff : degree p ≤ 0 ↔ p = C (coeff p 0) := ⟨eq_C_of_degree_le_zero, λ h, h.symm ▸ degree_C_le⟩ lemma degree_add_le (p q : polynomial α) : degree (p + q) ≤ max (degree p) (degree q) := calc degree (p + q) = ((p + q).support).sup some : rfl ... ≤ (p.support ∪ q.support).sup some : by convert sup_mono support_add ... = p.support.sup some ⊔ q.support.sup some : by convert sup_union ... = _ : with_bot.sup_eq_max _ _ @[simp] lemma leading_coeff_zero : leading_coeff (0 : polynomial α) = 0 := rfl @[simp] lemma leading_coeff_eq_zero : leading_coeff p = 0 ↔ p = 0 := ⟨λ h, by_contradiction $ λ hp, mt mem_support_iff.1 (not_not.2 h) (mem_of_max (degree_eq_nat_degree hp)), λ h, h.symm ▸ leading_coeff_zero⟩ lemma leading_coeff_eq_zero_iff_deg_eq_bot : leading_coeff p = 0 ↔ degree p = ⊥ := by rw [leading_coeff_eq_zero, degree_eq_bot] lemma degree_add_eq_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q := le_antisymm (max_eq_right_of_lt h ▸ degree_add_le _ _) $ degree_le_degree $ begin rw [coeff_add, coeff_nat_degree_eq_zero_of_degree_lt h, zero_add], exact mt leading_coeff_eq_zero.1 (ne_zero_of_degree_gt h) end lemma degree_add_C (hp : 0 < degree p) : degree (p + C a) = degree p := add_comm (C a) p ▸ degree_add_eq_of_degree_lt $ lt_of_le_of_lt degree_C_le hp lemma degree_add_eq_of_leading_coeff_add_ne_zero (h : leading_coeff p + leading_coeff q ≠ 0) : degree (p + q) = max p.degree q.degree := le_antisymm (degree_add_le _ _) $ match lt_trichotomy (degree p) (degree q) with | or.inl hlt := by rw [degree_add_eq_of_degree_lt hlt, max_eq_right_of_lt hlt]; exact le_refl _ | or.inr (or.inl heq) := le_of_not_gt $ assume hlt : max (degree p) (degree q) > degree (p + q), h $ show leading_coeff p + leading_coeff q = 0, begin rw [heq, max_self] at hlt, rw [leading_coeff, leading_coeff, nat_degree_eq_of_degree_eq heq, ← coeff_add], exact coeff_nat_degree_eq_zero_of_degree_lt hlt end | or.inr (or.inr hlt) := by rw [add_comm, degree_add_eq_of_degree_lt hlt, max_eq_left_of_lt hlt]; exact le_refl _ end lemma degree_erase_le (p : polynomial α) (n : ℕ) : degree (p.erase n) ≤ degree p := by convert sup_mono (erase_subset _ _) lemma degree_erase_lt (hp : p ≠ 0) : degree (p.erase (nat_degree p)) < degree p := lt_of_le_of_ne (degree_erase_le _ _) $ (degree_eq_nat_degree hp).symm ▸ (by convert λ h, not_mem_erase _ _ (mem_of_max h)) lemma degree_sum_le (s : finset β) (f : β → polynomial α) : degree (s.sum f) ≤ s.sup (λ b, degree (f b)) := finset.induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) $ assume a s has ih, calc degree ((insert a s).sum f) ≤ max (degree (f a)) (degree (s.sum f)) : by rw sum_insert has; exact degree_add_le _ _ ... ≤ _ : by rw [sup_insert, with_bot.sup_eq_max]; exact max_le_max (le_refl _) ih lemma degree_mul_le (p q : polynomial α) : degree (p * q) ≤ degree p + degree q := calc degree (p * q) ≤ (p.support).sup (λi, degree (sum q (λj a, C (coeff p i * a) * X ^ (i + j)))) : by simp only [single_eq_C_mul_X.symm]; exact degree_sum_le _ _ ... ≤ p.support.sup (λi, q.support.sup (λj, degree (C (coeff p i * coeff q j) * X ^ (i + j)))) : finset.sup_mono_fun (assume i hi, degree_sum_le _ _) ... ≤ degree p + degree q : begin refine finset.sup_le (λ a ha, finset.sup_le (λ b hb, le_trans (degree_monomial_le _ _) _)), rw [with_bot.coe_add], rw mem_support_iff at ha hb, exact add_le_add' (le_degree_of_ne_zero ha) (le_degree_of_ne_zero hb) end lemma degree_pow_le (p : polynomial α) : ∀ n, degree (p ^ n) ≤ add_monoid.smul n (degree p) | 0 := by rw [pow_zero, add_monoid.zero_smul]; exact degree_one_le | (n+1) := calc degree (p ^ (n + 1)) ≤ degree p + degree (p ^ n) : by rw pow_succ; exact degree_mul_le _ _ ... ≤ _ : by rw succ_smul; exact add_le_add' (le_refl _) (degree_pow_le _) @[simp] lemma leading_coeff_monomial (a : α) (n : ℕ) : leading_coeff (C a * X ^ n) = a := begin by_cases ha : a = 0, { simp only [ha, C_0, zero_mul, leading_coeff_zero] }, { rw [leading_coeff, nat_degree, degree_monomial _ ha, ← single_eq_C_mul_X], exact @finsupp.single_eq_same _ _ _ n a } end @[simp] lemma leading_coeff_C (a : α) : leading_coeff (C a) = a := suffices leading_coeff (C a * X^0) = a, by rwa [pow_zero, mul_one] at this, leading_coeff_monomial a 0 @[simp] lemma leading_coeff_X : leading_coeff (X : polynomial α) = 1 := suffices leading_coeff (C (1:α) * X^1) = 1, by rwa [C_1, pow_one, one_mul] at this, leading_coeff_monomial 1 1 @[simp] lemma monic_X : monic (X : polynomial α) := leading_coeff_X @[simp] lemma leading_coeff_one : leading_coeff (1 : polynomial α) = 1 := suffices leading_coeff (C (1:α) * X^0) = 1, by rwa [C_1, pow_zero, mul_one] at this, leading_coeff_monomial 1 0 @[simp] lemma monic_one : monic (1 : polynomial α) := leading_coeff_C _ lemma monic.ne_zero_of_zero_ne_one (h : (0:α) ≠ 1) {p : polynomial α} (hp : p.monic) : p ≠ 0 := by { contrapose! h, rwa [h] at hp } lemma monic.ne_zero {α : Type*} [nonzero_comm_ring α] {p : polynomial α} (hp : p.monic) : p ≠ 0 := hp.ne_zero_of_zero_ne_one $ zero_ne_one lemma leading_coeff_add_of_degree_lt (h : degree p < degree q) : leading_coeff (p + q) = leading_coeff q := have coeff p (nat_degree q) = 0, from coeff_nat_degree_eq_zero_of_degree_lt h, by simp only [leading_coeff, nat_degree_eq_of_degree_eq (degree_add_eq_of_degree_lt h), this, coeff_add, zero_add] lemma leading_coeff_add_of_degree_eq (h : degree p = degree q) (hlc : leading_coeff p + leading_coeff q ≠ 0) : leading_coeff (p + q) = leading_coeff p + leading_coeff q := have nat_degree (p + q) = nat_degree p, by apply nat_degree_eq_of_degree_eq; rw [degree_add_eq_of_leading_coeff_add_ne_zero hlc, h, max_self], by simp only [leading_coeff, this, nat_degree_eq_of_degree_eq h, coeff_add] @[simp] lemma coeff_mul_degree_add_degree (p q : polynomial α) : coeff (p * q) (nat_degree p + nat_degree q) = leading_coeff p * leading_coeff q := calc coeff (p * q) (nat_degree p + nat_degree q) = (nat.antidiagonal (nat_degree p + nat_degree q)).sum (λ x, coeff p x.1 * coeff q x.2) : coeff_mul _ _ _ ... = coeff p (nat_degree p) * coeff q (nat_degree q) : begin refine finset.sum_eq_single (nat_degree p, nat_degree q) _ _, { rintro ⟨i,j⟩ h₁ h₂, rw nat.mem_antidiagonal at h₁, by_cases H : nat_degree p < i, { rw [coeff_eq_zero_of_degree_lt (lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 H)), zero_mul] }, { rw not_lt_iff_eq_or_lt at H, cases H, { subst H, rw add_left_cancel_iff at h₁, dsimp at h₁, subst h₁, exfalso, exact h₂ rfl }, { suffices : nat_degree q < j, { rw [coeff_eq_zero_of_degree_lt (lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 this)), mul_zero] }, { by_contra H', rw not_lt at H', exact ne_of_lt (nat.lt_of_lt_of_le (nat.add_lt_add_right H j) (nat.add_le_add_left H' _)) h₁ } } } }, { intro H, exfalso, apply H, rw nat.mem_antidiagonal } end lemma degree_mul_eq' (h : leading_coeff p * leading_coeff q ≠ 0) : degree (p * q) = degree p + degree q := have hp : p ≠ 0 := by refine mt _ h; exact λ hp, by rw [hp, leading_coeff_zero, zero_mul], have hq : q ≠ 0 := by refine mt _ h; exact λ hq, by rw [hq, leading_coeff_zero, mul_zero], le_antisymm (degree_mul_le _ _) begin rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq], refine le_degree_of_ne_zero _, rwa coeff_mul_degree_add_degree end lemma nat_degree_mul_eq' (h : leading_coeff p * leading_coeff q ≠ 0) : nat_degree (p * q) = nat_degree p + nat_degree q := have hp : p ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, zero_mul]), have hq : q ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, mul_zero]), have hpq : p * q ≠ 0 := λ hpq, by rw [← coeff_mul_degree_add_degree, hpq, coeff_zero] at h; exact h rfl, option.some_inj.1 (show (nat_degree (p * q) : with_bot ℕ) = nat_degree p + nat_degree q, by rw [← degree_eq_nat_degree hpq, degree_mul_eq' h, degree_eq_nat_degree hp, degree_eq_nat_degree hq]) lemma leading_coeff_mul' (h : leading_coeff p * leading_coeff q ≠ 0) : leading_coeff (p * q) = leading_coeff p * leading_coeff q := begin unfold leading_coeff, rw [nat_degree_mul_eq' h, coeff_mul_degree_add_degree], refl end lemma leading_coeff_pow' : leading_coeff p ^ n ≠ 0 → leading_coeff (p ^ n) = leading_coeff p ^ n := nat.rec_on n (by simp) $ λ n ih h, have h₁ : leading_coeff p ^ n ≠ 0 := λ h₁, h $ by rw [pow_succ, h₁, mul_zero], have h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 := by rwa [pow_succ, ← ih h₁] at h, by rw [pow_succ, pow_succ, leading_coeff_mul' h₂, ih h₁] lemma degree_pow_eq' : ∀ {n}, leading_coeff p ^ n ≠ 0 → degree (p ^ n) = add_monoid.smul n (degree p) | 0 := λ h, by rw [pow_zero, ← C_1] at *; rw [degree_C h, add_monoid.zero_smul] | (n+1) := λ h, have h₁ : leading_coeff p ^ n ≠ 0 := λ h₁, h $ by rw [pow_succ, h₁, mul_zero], have h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 := by rwa [pow_succ, ← leading_coeff_pow' h₁] at h, by rw [pow_succ, degree_mul_eq' h₂, succ_smul, degree_pow_eq' h₁] lemma nat_degree_pow_eq' {n : ℕ} (h : leading_coeff p ^ n ≠ 0) : nat_degree (p ^ n) = n * nat_degree p := if hp0 : p = 0 then if hn0 : n = 0 then by simp * else by rw [hp0, zero_pow (nat.pos_of_ne_zero hn0)]; simp else have hpn : p ^ n ≠ 0, from λ hpn0, have h1 : _ := h, by rw [← leading_coeff_pow' h1, hpn0, leading_coeff_zero] at h; exact h rfl, option.some_inj.1 $ show (nat_degree (p ^ n) : with_bot ℕ) = (n * nat_degree p : ℕ), by rw [← degree_eq_nat_degree hpn, degree_pow_eq' h, degree_eq_nat_degree hp0, ← with_bot.coe_smul]; simp @[simp] lemma leading_coeff_X_pow : ∀ n : ℕ, leading_coeff ((X : polynomial α) ^ n) = 1 | 0 := by simp | (n+1) := if h10 : (1 : α) = 0 then by rw [pow_succ, ← one_mul X, ← C_1, h10]; simp else have h : leading_coeff (X : polynomial α) * leading_coeff (X ^ n) ≠ 0, by rw [leading_coeff_X, leading_coeff_X_pow n, one_mul]; exact h10, by rw [pow_succ, leading_coeff_mul' h, leading_coeff_X, leading_coeff_X_pow, one_mul] lemma nat_degree_comp_le : nat_degree (p.comp q) ≤ nat_degree p * nat_degree q := if h0 : p.comp q = 0 then by rw [h0, nat_degree_zero]; exact nat.zero_le _ else with_bot.coe_le_coe.1 $ calc ↑(nat_degree (p.comp q)) = degree (p.comp q) : (degree_eq_nat_degree h0).symm ... ≤ _ : degree_sum_le _ _ ... ≤ _ : sup_le (λ n hn, calc degree (C (coeff p n) * q ^ n) ≤ degree (C (coeff p n)) + degree (q ^ n) : degree_mul_le _ _ ... ≤ nat_degree (C (coeff p n)) + add_monoid.smul n (degree q) : add_le_add' degree_le_nat_degree (degree_pow_le _ _) ... ≤ nat_degree (C (coeff p n)) + add_monoid.smul n (nat_degree q) : add_le_add_left' (add_monoid.smul_le_smul_of_le_right (@degree_le_nat_degree _ _ q) n) ... = (n * nat_degree q : ℕ) : by rw [nat_degree_C, with_bot.coe_zero, zero_add, ← with_bot.coe_smul, add_monoid.smul_eq_mul]; simp ... ≤ (nat_degree p * nat_degree q : ℕ) : with_bot.coe_le_coe.2 $ mul_le_mul_of_nonneg_right (le_nat_degree_of_ne_zero (finsupp.mem_support_iff.1 hn)) (nat.zero_le _)) lemma degree_map_le [comm_semiring β] (f : α → β) [is_semiring_hom f] : degree (p.map f) ≤ degree p := if h : p.map f = 0 then by simp [h] else begin rw [degree_eq_nat_degree h], refine le_degree_of_ne_zero (mt (congr_arg f) _), rw [← coeff_map f, is_semiring_hom.map_zero f], exact mt leading_coeff_eq_zero.1 h end lemma subsingleton_of_monic_zero (h : monic (0 : polynomial α)) : (∀ p q : polynomial α, p = q) ∧ (∀ a b : α, a = b) := by rw [monic.def, leading_coeff_zero] at h; exact ⟨λ p q, by rw [← mul_one p, ← mul_one q, ← C_1, ← h, C_0, mul_zero, mul_zero], λ a b, by rw [← mul_one a, ← mul_one b, ← h, mul_zero, mul_zero]⟩ lemma degree_map_eq_of_leading_coeff_ne_zero [comm_semiring β] (f : α → β) [is_semiring_hom f] (hf : f (leading_coeff p) ≠ 0) : degree (p.map f) = degree p := le_antisymm (degree_map_le f) $ have hp0 : p ≠ 0, from λ hp0, by simpa [hp0, is_semiring_hom.map_zero f] using hf, begin rw [degree_eq_nat_degree hp0], refine le_degree_of_ne_zero _, rw [coeff_map], exact hf end lemma monic_map [comm_semiring β] (f : α → β) [is_semiring_hom f] (hp : monic p) : monic (p.map f) := if h : (0 : β) = 1 then by haveI := subsingleton_of_zero_eq_one β h; exact subsingleton.elim _ _ else have f (leading_coeff p) ≠ 0, by rwa [show _ = _, from hp, is_semiring_hom.map_one f, ne.def, eq_comm], by erw [monic, leading_coeff, nat_degree_eq_of_degree_eq (degree_map_eq_of_leading_coeff_ne_zero f this), coeff_map, ← leading_coeff, show _ = _, from hp, is_semiring_hom.map_one f] lemma zero_le_degree_iff {p : polynomial α} : 0 ≤ degree p ↔ p ≠ 0 := by rw [ne.def, ← degree_eq_bot]; cases degree p; exact dec_trivial @[simp] lemma coeff_mul_X_zero (p : polynomial α) : coeff (p * X) 0 = 0 := by rw [coeff_mul, nat.antidiagonal_zero]; simp only [polynomial.coeff_X_zero, finset.insert_empty_eq_singleton, finset.sum_singleton, mul_zero] end comm_semiring instance subsingleton [subsingleton α] [comm_semiring α] : subsingleton (polynomial α) := ⟨λ _ _, ext (λ _, subsingleton.elim _ _)⟩ section comm_semiring variables [comm_semiring α] {p q r : polynomial α} lemma ne_zero_of_monic_of_zero_ne_one (hp : monic p) (h : (0 : α) ≠ 1) : p ≠ 0 := mt (congr_arg leading_coeff) $ by rw [monic.def.1 hp, leading_coeff_zero]; cc lemma eq_X_add_C_of_degree_le_one (h : degree p ≤ 1) : p = C (p.coeff 1) * X + C (p.coeff 0) := ext (λ n, nat.cases_on n (by simp) (λ n, nat.cases_on n (by simp [coeff_C]) (λ m, have degree p < m.succ.succ, from lt_of_le_of_lt h dec_trivial, by simp [coeff_eq_zero_of_degree_lt this, coeff_C, nat.succ_ne_zero, coeff_X, nat.succ_inj', @eq_comm ℕ 0]))) lemma eq_X_add_C_of_degree_eq_one (h : degree p = 1) : p = C (p.leading_coeff) * X + C (p.coeff 0) := (eq_X_add_C_of_degree_le_one (show degree p ≤ 1, from h ▸ le_refl _)).trans (by simp [leading_coeff, nat_degree_eq_of_degree_eq_some h]) theorem degree_C_mul_X_pow_le (r : α) (n : ℕ) : degree (C r * X^n) ≤ n := begin rw [← single_eq_C_mul_X], refine finset.sup_le (λ b hb, _), rw list.eq_of_mem_singleton (finsupp.support_single_subset hb), exact le_refl _ end theorem degree_X_pow_le (n : ℕ) : degree (X^n : polynomial α) ≤ n := by simpa only [C_1, one_mul] using degree_C_mul_X_pow_le (1:α) n theorem degree_X_le : degree (X : polynomial α) ≤ 1 := by simpa only [C_1, one_mul, pow_one] using degree_C_mul_X_pow_le (1:α) 1 section injective open function variables [comm_semiring β] {f : α → β} [is_semiring_hom f] (hf : function.injective f) include hf lemma degree_map_eq_of_injective (p : polynomial α) : degree (p.map f) = degree p := if h : p = 0 then by simp [h] else degree_map_eq_of_leading_coeff_ne_zero _ (by rw [← is_semiring_hom.map_zero f]; exact mt hf.eq_iff.1 (mt leading_coeff_eq_zero.1 h)) lemma degree_map' (p : polynomial α) : degree (p.map f) = degree p := p.degree_map_eq_of_injective hf lemma nat_degree_map' (p : polynomial α) : nat_degree (p.map f) = nat_degree p := nat_degree_eq_of_degree_eq (degree_map' hf p) lemma map_injective (p : polynomial α) : injective (map f : polynomial α → polynomial β) := λ p q h, ext $ λ m, hf $ begin rw ext_iff at h, specialize h m, rw [coeff_map f, coeff_map f] at h, exact h end lemma leading_coeff_of_injective (p : polynomial α) : leading_coeff (p.map f) = f (leading_coeff p) := begin delta leading_coeff, rw [coeff_map f, nat_degree_map' hf p] end lemma monic_of_injective {p : polynomial α} (hp : (p.map f).monic) : p.monic := begin apply hf, rw [← leading_coeff_of_injective hf, hp.leading_coeff, is_semiring_hom.map_one f] end end injective theorem monic_of_degree_le (n : ℕ) (H1 : degree p ≤ n) (H2 : coeff p n = 1) : monic p := decidable.by_cases (assume H : degree p < n, @subsingleton.elim _ (subsingleton_of_zero_eq_one α $ H2 ▸ (coeff_eq_zero_of_degree_lt H).symm) _ _) (assume H : ¬degree p < n, by rwa [monic, leading_coeff, nat_degree, (lt_or_eq_of_le H1).resolve_left H]) theorem monic_X_pow_add {n : ℕ} (H : degree p ≤ n) : monic (X ^ (n+1) + p) := have H1 : degree p < n+1, from lt_of_le_of_lt H (with_bot.coe_lt_coe.2 (nat.lt_succ_self n)), monic_of_degree_le (n+1) (le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H1))) (by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H1, add_zero]) theorem monic_X_add_C (x : α) : monic (X + C x) := pow_one (X : polynomial α) ▸ monic_X_pow_add degree_C_le theorem degree_le_iff_coeff_zero (f : polynomial α) (n : with_bot ℕ) : degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 := ⟨λ (H : finset.sup (f.support) some ≤ n) m (Hm : n < (m : with_bot ℕ)), decidable.of_not_not $ λ H4, have H1 : m ∉ f.support, from λ H2, not_lt_of_ge ((finset.sup_le_iff.1 H) m H2 : ((m : with_bot ℕ) ≤ n)) Hm, H1 $ (finsupp.mem_support_to_fun f m).2 H4, λ H, finset.sup_le $ λ b Hb, decidable.of_not_not $ λ Hn, (finsupp.mem_support_to_fun f b).1 Hb $ H b $ lt_of_not_ge Hn⟩ theorem nat_degree_le_of_degree_le {p : polynomial α} {n : ℕ} (H : degree p ≤ n) : nat_degree p ≤ n := show option.get_or_else (degree p) 0 ≤ n, from match degree p, H with | none, H := zero_le _ | (some d), H := with_bot.coe_le_coe.1 H end theorem leading_coeff_mul_X_pow {p : polynomial α} {n : ℕ} : leading_coeff (p * X ^ n) = leading_coeff p := decidable.by_cases (assume H : leading_coeff p = 0, by rw [H, leading_coeff_eq_zero.1 H, zero_mul, leading_coeff_zero]) (assume H : leading_coeff p ≠ 0, by rw [leading_coeff_mul', leading_coeff_X_pow, mul_one]; rwa [leading_coeff_X_pow, mul_one]) lemma monic_mul (hp : monic p) (hq : monic q) : monic (p * q) := if h0 : (0 : α) = 1 then by haveI := subsingleton_of_zero_eq_one _ h0; exact subsingleton.elim _ _ else have leading_coeff p * leading_coeff q ≠ 0, by simp [monic.def.1 hp, monic.def.1 hq, ne.symm h0], by rw [monic.def, leading_coeff_mul' this, monic.def.1 hp, monic.def.1 hq, one_mul] lemma monic_pow (hp : monic p) : ∀ (n : ℕ), monic (p ^ n) | 0 := monic_one | (n+1) := monic_mul hp (monic_pow n) lemma multiplicity_finite_of_degree_pos_of_monic (hp : (0 : with_bot ℕ) < degree p) (hmp : monic p) (hq : q ≠ 0) : multiplicity.finite p q := have zn0 : (0 : α) ≠ 1, from λ h, by haveI := subsingleton_of_zero_eq_one _ h; exact hq (subsingleton.elim _ _), ⟨nat_degree q, λ ⟨r, hr⟩, have hp0 : p ≠ 0, from λ hp0, by simp [hp0] at hp; contradiction, have hr0 : r ≠ 0, from λ hr0, by simp * at *, have hpn1 : leading_coeff p ^ (nat_degree q + 1) = 1, by simp [show _ = _, from hmp], have hpn0' : leading_coeff p ^ (nat_degree q + 1) ≠ 0, from hpn1.symm ▸ zn0.symm, have hpnr0 : leading_coeff (p ^ (nat_degree q + 1)) * leading_coeff r ≠ 0, by simp only [leading_coeff_pow' hpn0', leading_coeff_eq_zero, hpn1, one_pow, one_mul, ne.def, hr0]; simp, have hpn0 : p ^ (nat_degree q + 1) ≠ 0, from mt leading_coeff_eq_zero.2 $ by rw [leading_coeff_pow' hpn0', show _ = _, from hmp, one_pow]; exact zn0.symm, have hnp : 0 < nat_degree p, by rw [← with_bot.coe_lt_coe, ← degree_eq_nat_degree hp0]; exact hp, begin have := congr_arg nat_degree hr, rw [nat_degree_mul_eq' hpnr0, nat_degree_pow_eq' hpn0', add_mul, add_assoc] at this, exact ne_of_lt (lt_add_of_le_of_pos (le_mul_of_one_le_right' (nat.zero_le _) hnp) (add_pos_of_pos_of_nonneg (by rwa one_mul) (nat.zero_le _))) this end⟩ end comm_semiring section nonzero_comm_semiring variables [nonzero_comm_semiring α] {p q : polynomial α} instance : nonzero_comm_semiring (polynomial α) := { zero_ne_one := λ (h : (0 : polynomial α) = 1), @zero_ne_one α _ $ calc (0 : α) = eval 0 0 : eval_zero.symm ... = eval 0 1 : congr_arg _ h ... = 1 : eval_C, ..polynomial.comm_semiring } @[simp] lemma degree_one : degree (1 : polynomial α) = (0 : with_bot ℕ) := degree_C (show (1 : α) ≠ 0, from zero_ne_one.symm) @[simp] lemma degree_X : degree (X : polynomial α) = 1 := begin unfold X degree monomial single finsupp.support, rw if_neg (zero_ne_one).symm, refl end lemma X_ne_zero : (X : polynomial α) ≠ 0 := mt (congr_arg (λ p, coeff p 1)) (by simp) @[simp] lemma degree_X_pow : ∀ (n : ℕ), degree ((X : polynomial α) ^ n) = n | 0 := by simp only [pow_zero, degree_one]; refl | (n+1) := have h : leading_coeff (X : polynomial α) * leading_coeff (X ^ n) ≠ 0, by rw [leading_coeff_X, leading_coeff_X_pow n, one_mul]; exact zero_ne_one.symm, by rw [pow_succ, degree_mul_eq' h, degree_X, degree_X_pow, add_comm]; refl @[simp] lemma not_monic_zero : ¬monic (0 : polynomial α) := by simpa only [monic, leading_coeff_zero] using zero_ne_one lemma ne_zero_of_monic (h : monic p) : p ≠ 0 := λ h₁, @not_monic_zero α _ (h₁ ▸ h) end nonzero_comm_semiring section comm_semiring variables [comm_semiring α] {p q : polynomial α} /-- `dix_X p` return a polynomial `q` such that `q * X + C (p.coeff 0) = p`. It can be used in a semiring where the usual division algorithm is not possible -/ def div_X (p : polynomial α) : polynomial α := { to_fun := λ n, p.coeff (n + 1), support := ⟨(p.support.filter (> 0)).1.map (λ n, n - 1), multiset.nodup_map_on begin simp only [finset.mem_def.symm, finset.mem_erase, finset.mem_filter], assume x hx y hy hxy, rwa [← @add_right_cancel_iff _ _ 1, nat.sub_add_cancel hx.2, nat.sub_add_cancel hy.2] at hxy end (p.support.filter (> 0)).2⟩, mem_support_to_fun := λ n, suffices (∃ (a : ℕ), (¬coeff p a = 0 ∧ a > 0) ∧ a - 1 = n) ↔ ¬coeff p (n + 1) = 0, by simpa [finset.mem_def.symm, apply_eq_coeff], ⟨λ ⟨a, ha⟩, by rw [← ha.2, nat.sub_add_cancel ha.1.2]; exact ha.1.1, λ h, ⟨n + 1, ⟨h, nat.succ_pos _⟩, nat.succ_sub_one _⟩⟩ } lemma div_X_mul_X_add (p : polynomial α) : div_X p * X + C (p.coeff 0) = p := ext $ λ n, nat.cases_on n (by simp) (by simp [coeff_C, nat.succ_ne_zero, coeff_mul_X, div_X]) @[simp] lemma div_X_C (a : α) : div_X (C a) = 0 := ext $ λ n, by cases n; simp [div_X, coeff_C]; simp [coeff] lemma div_X_eq_zero_iff : div_X p = 0 ↔ p = C (p.coeff 0) := ⟨λ h, by simpa [eq_comm, h] using div_X_mul_X_add p, λ h, by rw [h, div_X_C]⟩ lemma div_X_add : div_X (p + q) = div_X p + div_X q := ext $ by simp [div_X] def nonzero_comm_semiring.of_polynomial_ne (h : p ≠ q) : nonzero_comm_semiring α := { zero_ne_one := λ h01 : 0 = 1, h $ by rw [← mul_one p, ← mul_one q, ← C_1, ← h01, C_0, mul_zero, mul_zero], ..show comm_semiring α, by apply_instance } lemma degree_lt_degree_mul_X (hp : p ≠ 0) : p.degree < (p * X).degree := by letI := nonzero_comm_semiring.of_polynomial_ne hp; exact have leading_coeff p * leading_coeff X ≠ 0, by simpa, by erw [degree_mul_eq' this, degree_eq_nat_degree hp, degree_X, ← with_bot.coe_one, ← with_bot.coe_add, with_bot.coe_lt_coe]; exact nat.lt_succ_self _ lemma degree_div_X_lt (hp0 : p ≠ 0) : (div_X p).degree < p.degree := by letI := nonzero_comm_semiring.of_polynomial_ne hp0; exact calc (div_X p).degree < (div_X p * X + C (p.coeff 0)).degree : if h : degree p ≤ 0 then begin have h' : C (p.coeff 0) ≠ 0, by rwa [← eq_C_of_degree_le_zero h], rw [eq_C_of_degree_le_zero h, div_X_C, degree_zero, zero_mul, zero_add], exact lt_of_le_of_ne bot_le (ne.symm (mt degree_eq_bot.1 $ by simp [h'])), end else have hXp0 : div_X p ≠ 0, by simpa [div_X_eq_zero_iff, -not_le, degree_le_zero_iff] using h, have leading_coeff (div_X p) * leading_coeff X ≠ 0, by simpa, have degree (C (p.coeff 0)) < degree (div_X p * X), from calc degree (C (p.coeff 0)) ≤ 0 : degree_C_le ... < 1 : dec_trivial ... = degree (X : polynomial α) : degree_X.symm ... ≤ degree (div_X p * X) : by rw [← zero_add (degree X), degree_mul_eq' this]; exact add_le_add' (by rw [zero_le_degree_iff, ne.def, div_X_eq_zero_iff]; exact λ h0, h (h0.symm ▸ degree_C_le)) (le_refl _), by rw [add_comm, degree_add_eq_of_degree_lt this]; exact degree_lt_degree_mul_X hXp0 ... = p.degree : by rw div_X_mul_X_add @[elab_as_eliminator] noncomputable def rec_on_horner {M : polynomial α → Sort*} : Π (p : polynomial α), M 0 → (Π p a, coeff p 0 = 0 → a ≠ 0 → M p → M (p + C a)) → (Π p, p ≠ 0 → M p → M (p * X)) → M p | p := λ M0 MC MX, if hp : p = 0 then eq.rec_on hp.symm M0 else have wf : degree (div_X p) < degree p, from degree_div_X_lt hp, by rw [← div_X_mul_X_add p] at *; exact if hcp0 : coeff p 0 = 0 then by rw [hcp0, C_0, add_zero]; exact MX _ (λ h : div_X p = 0, by simpa [h, hcp0] using hp) (rec_on_horner _ M0 MC MX) else MC _ _ (coeff_mul_X_zero _) hcp0 (if hpX0 : div_X p = 0 then show M (div_X p * X), by rw [hpX0, zero_mul]; exact M0 else MX (div_X p) hpX0 (rec_on_horner _ M0 MC MX)) using_well_founded {dec_tac := tactic.assumption} @[elab_as_eliminator] lemma degree_pos_induction_on {P : polynomial α → Prop} (p : polynomial α) (h0 : 0 < degree p) (hC : ∀ {a}, a ≠ 0 → P (C a * X)) (hX : ∀ {p}, 0 < degree p → P p → P (p * X)) (hadd : ∀ {p} {a}, 0 < degree p → P p → P (p + C a)) : P p := rec_on_horner p (λ h, by rw degree_zero at h; exact absurd h dec_trivial) (λ p a _ _ ih h0, have 0 < degree p, from lt_of_not_ge (λ h, (not_lt_of_ge degree_C_le) $ by rwa [eq_C_of_degree_le_zero h, ← C_add] at h0), hadd this (ih this)) (λ p _ ih h0', if h0 : 0 < degree p then hX h0 (ih h0) else by rw [eq_C_of_degree_le_zero (le_of_not_gt h0)] at *; exact hC (λ h : coeff p 0 = 0, by simpa [h, nat.not_lt_zero] using h0')) h0 end comm_semiring section comm_ring variables [comm_ring α] {p q : polynomial α} instance : comm_ring (polynomial α) := add_monoid_algebra.comm_ring instance : module α (polynomial α) := add_monoid_algebra.module variable (α) def lcoeff (n : ℕ) : polynomial α →ₗ α := { to_fun := λ f, coeff f n, add := λ f g, coeff_add f g n, smul := λ r p, coeff_smul p r n } variable {α} @[simp] lemma lcoeff_apply (n : ℕ) (f : polynomial α) : lcoeff α n f = coeff f n := rfl instance C.is_ring_hom : is_ring_hom (@C α _) := by apply is_ring_hom.of_semiring lemma int_cast_eq_C (n : ℤ) : (n : polynomial α) = C n := ((ring_hom.of C).map_int_cast n).symm @[simp] lemma C_neg : C (-a) = -C a := is_ring_hom.map_neg C @[simp] lemma C_sub : C (a - b) = C a - C b := is_ring_hom.map_sub C instance eval₂.is_ring_hom {β} [comm_ring β] (f : α → β) [is_ring_hom f] {x : β} : is_ring_hom (eval₂ f x) := by apply is_ring_hom.of_semiring instance eval.is_ring_hom {x : α} : is_ring_hom (eval x) := eval₂.is_ring_hom _ instance map.is_ring_hom {β} [comm_ring β] (f : α → β) [is_ring_hom f] : is_ring_hom (map f) := eval₂.is_ring_hom (C ∘ f) @[simp] lemma map_sub {β} [comm_ring β] (f : α → β) [is_ring_hom f] : (p - q).map f = p.map f - q.map f := is_ring_hom.map_sub _ @[simp] lemma map_neg {β} [comm_ring β] (f : α → β) [is_ring_hom f] : (-p).map f = -(p.map f) := is_ring_hom.map_neg _ @[simp] lemma degree_neg (p : polynomial α) : degree (-p) = degree p := by unfold degree; rw support_neg @[simp] lemma nat_degree_neg (p : polynomial α) : nat_degree (-p) = nat_degree p := by simp [nat_degree] @[simp] lemma nat_degree_int_cast (n : ℤ) : nat_degree (n : polynomial α) = 0 := by simp [int_cast_eq_C] @[simp] lemma coeff_neg (p : polynomial α) (n : ℕ) : coeff (-p) n = -coeff p n := rfl @[simp] lemma coeff_sub (p q : polynomial α) (n : ℕ) : coeff (p - q) n = coeff p n - coeff q n := rfl @[simp] lemma eval₂_neg {β} [comm_ring β] (f : α → β) [is_ring_hom f] {x : β} : (-p).eval₂ f x = -p.eval₂ f x := is_ring_hom.map_neg _ @[simp] lemma eval₂_sub {β} [comm_ring β] (f : α → β) [is_ring_hom f] {x : β} : (p - q).eval₂ f x = p.eval₂ f x - q.eval₂ f x := is_ring_hom.map_sub _ @[simp] lemma eval_neg (p : polynomial α) (x : α) : (-p).eval x = -p.eval x := is_ring_hom.map_neg _ @[simp] lemma eval_sub (p q : polynomial α) (x : α) : (p - q).eval x = p.eval x - q.eval x := is_ring_hom.map_sub _ section aeval /-- `R[X]` is the generator of the category `R-Alg`. -/ instance polynomial (R : Type u) [comm_ring R] : algebra R (polynomial R) := { to_fun := polynomial.C, commutes' := λ _ _, mul_comm _ _, smul_def' := λ c p, (polynomial.C_mul' c p).symm, .. polynomial.module } variables (R : Type u) (A : Type v) variables [comm_ring R] [comm_ring A] [algebra R A] variables (x : A) /-- Given a valuation `x` of the variable in an `R`-algebra `A`, `aeval R A x` is the unique `R`-algebra homomorphism from `R[X]` to `A` sending `X` to `x`. -/ def aeval : polynomial R →ₐ[R] A := { commutes' := λ r, eval₂_C _ _, ..ring_hom.of (eval₂ (algebra_map A) x) } theorem aeval_def (p : polynomial R) : aeval R A x p = eval₂ (algebra_map A) x p := rfl @[simp] lemma aeval_X : aeval R A x X = x := eval₂_X _ x @[simp] lemma aeval_C (r : R) : aeval R A x (C r) = algebra_map A r := eval₂_C _ x instance aeval.is_ring_hom : is_ring_hom (aeval R A x) := by apply_instance theorem eval_unique (φ : polynomial R →ₐ[R] A) (p) : φ p = eval₂ (algebra_map A) (φ X) p := begin apply polynomial.induction_on p, { intro r, rw eval₂_C, exact φ.commutes r }, { intros f g ih1 ih2, rw [is_ring_hom.map_add φ, ih1, ih2, eval₂_add] }, { intros n r ih, rw [pow_succ', ← mul_assoc, is_ring_hom.map_mul φ, eval₂_mul (algebra_map A : R → A), eval₂_X, ih] } end end aeval lemma degree_sub_lt (hd : degree p = degree q) (hp0 : p ≠ 0) (hlc : leading_coeff p = leading_coeff q) : degree (p - q) < degree p := have hp : single (nat_degree p) (leading_coeff p) + p.erase (nat_degree p) = p := finsupp.single_add_erase, have hq : single (nat_degree q) (leading_coeff q) + q.erase (nat_degree q) = q := finsupp.single_add_erase, have hd' : nat_degree p = nat_degree q := by unfold nat_degree; rw hd, have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0), calc degree (p - q) = degree (erase (nat_degree q) p + -erase (nat_degree q) q) : by conv {to_lhs, rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]} ... ≤ max (degree (erase (nat_degree q) p)) (degree (erase (nat_degree q) q)) : degree_neg (erase (nat_degree q) q) ▸ degree_add_le _ _ ... < degree p : max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩ lemma ne_zero_of_ne_zero_of_monic (hp : p ≠ 0) (hq : monic q) : q ≠ 0 | h := begin rw [h, monic.def, leading_coeff_zero] at hq, rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp, exact hp rfl end lemma div_wf_lemma (h : degree q ≤ degree p ∧ p ≠ 0) (hq : monic q) : degree (p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) < degree p := have hp : leading_coeff p ≠ 0 := mt leading_coeff_eq_zero.1 h.2, have hpq : leading_coeff (C (leading_coeff p) * X ^ (nat_degree p - nat_degree q)) * leading_coeff q ≠ 0, by rwa [leading_coeff_monomial, monic.def.1 hq, mul_one], if h0 : p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q = 0 then h0.symm ▸ (lt_of_not_ge $ mt le_bot_iff.1 (mt degree_eq_bot.1 h.2)) else have hq0 : q ≠ 0 := ne_zero_of_ne_zero_of_monic h.2 hq, have hlt : nat_degree q ≤ nat_degree p := with_bot.coe_le_coe.1 (by rw [← degree_eq_nat_degree h.2, ← degree_eq_nat_degree hq0]; exact h.1), degree_sub_lt (by rw [degree_mul_eq' hpq, degree_monomial _ hp, degree_eq_nat_degree h.2, degree_eq_nat_degree hq0, ← with_bot.coe_add, nat.sub_add_cancel hlt]) h.2 (by rw [leading_coeff_mul' hpq, leading_coeff_monomial, monic.def.1 hq, mul_one]) noncomputable def div_mod_by_monic_aux : Π (p : polynomial α) {q : polynomial α}, monic q → polynomial α × polynomial α | p := λ q hq, if h : degree q ≤ degree p ∧ p ≠ 0 then let z := C (leading_coeff p) * X^(nat_degree p - nat_degree q) in have wf : _ := div_wf_lemma h hq, let dm := div_mod_by_monic_aux (p - z * q) hq in ⟨z + dm.1, dm.2⟩ else ⟨0, p⟩ using_well_founded {dec_tac := tactic.assumption} /-- `div_by_monic` gives the quotient of `p` by a monic polynomial `q`. -/ def div_by_monic (p q : polynomial α) : polynomial α := if hq : monic q then (div_mod_by_monic_aux p hq).1 else 0 /-- `mod_by_monic` gives the remainder of `p` by a monic polynomial `q`. -/ def mod_by_monic (p q : polynomial α) : polynomial α := if hq : monic q then (div_mod_by_monic_aux p hq).2 else p infixl ` /ₘ ` : 70 := div_by_monic infixl ` %ₘ ` : 70 := mod_by_monic lemma degree_mod_by_monic_lt : ∀ (p : polynomial α) {q : polynomial α} (hq : monic q) (hq0 : q ≠ 0), degree (p %ₘ q) < degree q | p := λ q hq hq0, if h : degree q ≤ degree p ∧ p ≠ 0 then have wf : _ := div_wf_lemma ⟨h.1, h.2⟩ hq, have degree ((p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) %ₘ q) < degree q := degree_mod_by_monic_lt (p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) hq hq0, begin unfold mod_by_monic at this ⊢, unfold div_mod_by_monic_aux, rw dif_pos hq at this ⊢, rw if_pos h, exact this end else or.cases_on (not_and_distrib.1 h) begin unfold mod_by_monic div_mod_by_monic_aux, rw [dif_pos hq, if_neg h], exact lt_of_not_ge, end begin assume hp, unfold mod_by_monic div_mod_by_monic_aux, rw [dif_pos hq, if_neg h, not_not.1 hp], exact lt_of_le_of_ne bot_le (ne.symm (mt degree_eq_bot.1 hq0)), end using_well_founded {dec_tac := tactic.assumption} lemma mod_by_monic_eq_sub_mul_div : ∀ (p : polynomial α) {q : polynomial α} (hq : monic q), p %ₘ q = p - q * (p /ₘ q) | p := λ q hq, if h : degree q ≤ degree p ∧ p ≠ 0 then have wf : _ := div_wf_lemma h hq, have ih : _ := mod_by_monic_eq_sub_mul_div (p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) hq, begin unfold mod_by_monic div_by_monic div_mod_by_monic_aux, rw [dif_pos hq, if_pos h], rw [mod_by_monic, dif_pos hq] at ih, refine ih.trans _, unfold div_by_monic, rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub, mul_comm] end else begin unfold mod_by_monic div_by_monic div_mod_by_monic_aux, rw [dif_pos hq, if_neg h, dif_pos hq, if_neg h, mul_zero, sub_zero] end using_well_founded {dec_tac := tactic.assumption} lemma mod_by_monic_add_div (p : polynomial α) {q : polynomial α} (hq : monic q) : p %ₘ q + q * (p /ₘ q) = p := eq_sub_iff_add_eq.1 (mod_by_monic_eq_sub_mul_div p hq) @[simp] lemma zero_mod_by_monic (p : polynomial α) : 0 %ₘ p = 0 := begin unfold mod_by_monic div_mod_by_monic_aux, by_cases hp : monic p, { rw [dif_pos hp, if_neg (mt and.right (not_not_intro rfl))] }, { rw [dif_neg hp] } end @[simp] lemma zero_div_by_monic (p : polynomial α) : 0 /ₘ p = 0 := begin unfold div_by_monic div_mod_by_monic_aux, by_cases hp : monic p, { rw [dif_pos hp, if_neg (mt and.right (not_not_intro rfl))] }, { rw [dif_neg hp] } end @[simp] lemma mod_by_monic_zero (p : polynomial α) : p %ₘ 0 = p := if h : monic (0 : polynomial α) then (subsingleton_of_monic_zero h).1 _ _ else by unfold mod_by_monic div_mod_by_monic_aux; rw dif_neg h @[simp] lemma div_by_monic_zero (p : polynomial α) : p /ₘ 0 = 0 := if h : monic (0 : polynomial α) then (subsingleton_of_monic_zero h).1 _ _ else by unfold div_by_monic div_mod_by_monic_aux; rw dif_neg h lemma div_by_monic_eq_of_not_monic (p : polynomial α) (hq : ¬monic q) : p /ₘ q = 0 := dif_neg hq lemma mod_by_monic_eq_of_not_monic (p : polynomial α) (hq : ¬monic q) : p %ₘ q = p := dif_neg hq lemma mod_by_monic_eq_self_iff (hq : monic q) (hq0 : q ≠ 0) : p %ₘ q = p ↔ degree p < degree q := ⟨λ h, h ▸ degree_mod_by_monic_lt _ hq hq0, λ h, have ¬ degree q ≤ degree p := not_le_of_gt h, by unfold mod_by_monic div_mod_by_monic_aux; rw [dif_pos hq, if_neg (mt and.left this)]⟩ lemma div_by_monic_eq_zero_iff (hq : monic q) (hq0 : q ≠ 0) : p /ₘ q = 0 ↔ degree p < degree q := ⟨λ h, by have := mod_by_monic_add_div p hq; rwa [h, mul_zero, add_zero, mod_by_monic_eq_self_iff hq hq0] at this, λ h, have ¬ degree q ≤ degree p := not_le_of_gt h, by unfold div_by_monic div_mod_by_monic_aux; rw [dif_pos hq, if_neg (mt and.left this)]⟩ lemma degree_add_div_by_monic (hq : monic q) (h : degree q ≤ degree p) : degree q + degree (p /ₘ q) = degree p := if hq0 : q = 0 then have ∀ (p : polynomial α), p = 0, from λ p, (@subsingleton_of_monic_zero α _ (hq0 ▸ hq)).1 _ _, by rw [this (p /ₘ q), this p, this q]; refl else have hdiv0 : p /ₘ q ≠ 0 := by rwa [(≠), div_by_monic_eq_zero_iff hq hq0, not_lt], have hlc : leading_coeff q * leading_coeff (p /ₘ q) ≠ 0 := by rwa [monic.def.1 hq, one_mul, (≠), leading_coeff_eq_zero], have hmod : degree (p %ₘ q) < degree (q * (p /ₘ q)) := calc degree (p %ₘ q) < degree q : degree_mod_by_monic_lt _ hq hq0 ... ≤ _ : by rw [degree_mul_eq' hlc, degree_eq_nat_degree hq0, degree_eq_nat_degree hdiv0, ← with_bot.coe_add, with_bot.coe_le_coe]; exact nat.le_add_right _ _, calc degree q + degree (p /ₘ q) = degree (q * (p /ₘ q)) : eq.symm (degree_mul_eq' hlc) ... = degree (p %ₘ q + q * (p /ₘ q)) : (degree_add_eq_of_degree_lt hmod).symm ... = _ : congr_arg _ (mod_by_monic_add_div _ hq) lemma degree_div_by_monic_le (p q : polynomial α) : degree (p /ₘ q) ≤ degree p := if hp0 : p = 0 then by simp only [hp0, zero_div_by_monic, le_refl] else if hq : monic q then have hq0 : q ≠ 0 := ne_zero_of_ne_zero_of_monic hp0 hq, if h : degree q ≤ degree p then by rw [← degree_add_div_by_monic hq h, degree_eq_nat_degree hq0, degree_eq_nat_degree (mt (div_by_monic_eq_zero_iff hq hq0).1 (not_lt.2 h))]; exact with_bot.coe_le_coe.2 (nat.le_add_left _ _) else by unfold div_by_monic div_mod_by_monic_aux; simp only [dif_pos hq, h, false_and, if_false, degree_zero, bot_le] else (div_by_monic_eq_of_not_monic p hq).symm ▸ bot_le lemma degree_div_by_monic_lt (p : polynomial α) {q : polynomial α} (hq : monic q) (hp0 : p ≠ 0) (h0q : 0 < degree q) : degree (p /ₘ q) < degree p := have hq0 : q ≠ 0 := ne_zero_of_ne_zero_of_monic hp0 hq, if hpq : degree p < degree q then begin rw [(div_by_monic_eq_zero_iff hq hq0).2 hpq, degree_eq_nat_degree hp0], exact with_bot.bot_lt_some _ end else begin rw [← degree_add_div_by_monic hq (not_lt.1 hpq), degree_eq_nat_degree hq0, degree_eq_nat_degree (mt (div_by_monic_eq_zero_iff hq hq0).1 hpq)], exact with_bot.coe_lt_coe.2 (nat.lt_add_of_pos_left (with_bot.coe_lt_coe.1 $ (degree_eq_nat_degree hq0) ▸ h0q)) end lemma div_mod_by_monic_unique {f g} (q r : polynomial α) (hg : monic g) (h : r + g * q = f ∧ degree r < degree g) : f /ₘ g = q ∧ f %ₘ g = r := if hg0 : g = 0 then by split; exact (subsingleton_of_monic_zero (hg0 ▸ hg : monic (0 : polynomial α))).1 _ _ else have h₁ : r - f %ₘ g = -g * (q - f /ₘ g), from eq_of_sub_eq_zero (by rw [← sub_eq_zero_of_eq (h.1.trans (mod_by_monic_add_div f hg).symm)]; simp [mul_add, mul_comm, sub_eq_add_neg, add_comm, add_left_comm]), have h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g)), by simp [h₁], have h₄ : degree (r - f %ₘ g) < degree g, from calc degree (r - f %ₘ g) ≤ max (degree r) (degree (-(f %ₘ g))) : degree_add_le _ _ ... < degree g : max_lt_iff.2 ⟨h.2, by rw degree_neg; exact degree_mod_by_monic_lt _ hg hg0⟩, have h₅ : q - (f /ₘ g) = 0, from by_contradiction (λ hqf, not_le_of_gt h₄ $ calc degree g ≤ degree g + degree (q - f /ₘ g) : by erw [degree_eq_nat_degree hg0, degree_eq_nat_degree hqf, with_bot.coe_le_coe]; exact nat.le_add_right _ _ ... = degree (r - f %ₘ g) : by rw [h₂, degree_mul_eq']; simpa [monic.def.1 hg]), ⟨eq.symm $ eq_of_sub_eq_zero h₅, eq.symm $ eq_of_sub_eq_zero $ by simpa [h₅] using h₁⟩ lemma map_mod_div_by_monic [comm_ring β] (f : α → β) [is_semiring_hom f] (hq : monic q) : (p /ₘ q).map f = p.map f /ₘ q.map f ∧ (p %ₘ q).map f = p.map f %ₘ q.map f := if h01 : (0 : β) = 1 then by haveI := subsingleton_of_zero_eq_one β h01; exact ⟨subsingleton.elim _ _, subsingleton.elim _ _⟩ else have h01α : (0 : α) ≠ 1, from mt (congr_arg f) (by rwa [is_semiring_hom.map_one f, is_semiring_hom.map_zero f]), have map f p /ₘ map f q = map f (p /ₘ q) ∧ map f p %ₘ map f q = map f (p %ₘ q), from (div_mod_by_monic_unique ((p /ₘ q).map f) _ (monic_map f hq) ⟨eq.symm $ by rw [← map_mul, ← map_add, mod_by_monic_add_div _ hq], calc _ ≤ degree (p %ₘ q) : degree_map_le _ ... < degree q : degree_mod_by_monic_lt _ hq $ (ne_zero_of_monic_of_zero_ne_one hq h01α) ... = _ : eq.symm $ degree_map_eq_of_leading_coeff_ne_zero _ (by rw [monic.def.1 hq, is_semiring_hom.map_one f]; exact ne.symm h01)⟩), ⟨this.1.symm, this.2.symm⟩ lemma map_div_by_monic [comm_ring β] (f : α → β) [is_semiring_hom f] (hq : monic q) : (p /ₘ q).map f = p.map f /ₘ q.map f := (map_mod_div_by_monic f hq).1 lemma map_mod_by_monic [comm_ring β] (f : α → β) [is_semiring_hom f] (hq : monic q) : (p %ₘ q).map f = p.map f %ₘ q.map f := (map_mod_div_by_monic f hq).2 lemma dvd_iff_mod_by_monic_eq_zero (hq : monic q) : p %ₘ q = 0 ↔ q ∣ p := ⟨λ h, by rw [← mod_by_monic_add_div p hq, h, zero_add]; exact dvd_mul_right _ _, λ h, if hq0 : q = 0 then by rw hq0 at hq; exact (subsingleton_of_monic_zero hq).1 _ _ else let ⟨r, hr⟩ := exists_eq_mul_right_of_dvd h in by_contradiction (λ hpq0, have hmod : p %ₘ q = q * (r - p /ₘ q) := by rw [mod_by_monic_eq_sub_mul_div _ hq, mul_sub, ← hr], have degree (q * (r - p /ₘ q)) < degree q := hmod ▸ degree_mod_by_monic_lt _ hq hq0, have hrpq0 : leading_coeff (r - p /ₘ q) ≠ 0 := λ h, hpq0 $ leading_coeff_eq_zero.1 (by rw [hmod, leading_coeff_eq_zero.1 h, mul_zero, leading_coeff_zero]), have hlc : leading_coeff q * leading_coeff (r - p /ₘ q) ≠ 0 := by rwa [monic.def.1 hq, one_mul], by rw [degree_mul_eq' hlc, degree_eq_nat_degree hq0, degree_eq_nat_degree (mt leading_coeff_eq_zero.2 hrpq0)] at this; exact not_lt_of_ge (nat.le_add_right _ _) (with_bot.some_lt_some.1 this))⟩ @[simp] lemma mod_by_monic_one (p : polynomial α) : p %ₘ 1 = 0 := (dvd_iff_mod_by_monic_eq_zero monic_one).2 (one_dvd _) @[simp] lemma div_by_monic_one (p : polynomial α) : p /ₘ 1 = p := by conv_rhs { rw [← mod_by_monic_add_div p monic_one] }; simp lemma degree_pos_of_root (hp : p ≠ 0) (h : is_root p a) : 0 < degree p := lt_of_not_ge $ λ hlt, begin have := eq_C_of_degree_le_zero hlt, rw [is_root, this, eval_C] at h, exact hp (finsupp.ext (λ n, show coeff p n = 0, from nat.cases_on n h (λ _, coeff_eq_zero_of_degree_lt (lt_of_le_of_lt hlt (with_bot.coe_lt_coe.2 (nat.succ_pos _)))))), end theorem monic_X_sub_C (x : α) : monic (X - C x) := by simpa only [C_neg] using monic_X_add_C (-x) theorem monic_X_pow_sub {n : ℕ} (H : degree p ≤ n) : monic (X ^ (n+1) - p) := monic_X_pow_add ((degree_neg p).symm ▸ H) theorem degree_mod_by_monic_le (p : polynomial α) {q : polynomial α} (hq : monic q) : degree (p %ₘ q) ≤ degree q := decidable.by_cases (assume H : q = 0, by rw [monic, H, leading_coeff_zero] at hq; have : (0:polynomial α) = 1 := (by rw [← C_0, ← C_1, hq]); rw [eq_zero_of_zero_eq_one _ this (p %ₘ q), eq_zero_of_zero_eq_one _ this q]; exact le_refl _) (assume H : q ≠ 0, le_of_lt $ degree_mod_by_monic_lt _ hq H) lemma root_X_sub_C : is_root (X - C a) b ↔ a = b := by rw [is_root.def, eval_sub, eval_X, eval_C, sub_eq_zero_iff_eq, eq_comm] def nonzero_comm_ring.of_polynomial_ne (h : p ≠ q) : nonzero_comm_ring α := { zero := 0, one := 1, zero_ne_one := λ h01, h $ by rw [← one_mul p, ← one_mul q, ← C_1, ← h01, C_0, zero_mul, zero_mul], ..show comm_ring α, by apply_instance } end comm_ring section nonzero_comm_ring variables [nonzero_comm_ring α] {p q : polynomial α} instance : nonzero_comm_ring (polynomial α) := { ..polynomial.nonzero_comm_semiring, ..polynomial.comm_ring } @[simp] lemma degree_X_sub_C (a : α) : degree (X - C a) = 1 := begin rw [sub_eq_add_neg, add_comm, ← @degree_X α], by_cases ha : a = 0, { simp only [ha, C_0, neg_zero, zero_add] }, exact degree_add_eq_of_degree_lt (by rw [degree_X, degree_neg, degree_C ha]; exact dec_trivial) end lemma degree_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : α) : degree ((X : polynomial α) ^ n - C a) = n := have degree (-C a) < degree ((X : polynomial α) ^ n), from calc degree (-C a) ≤ 0 : by rw degree_neg; exact degree_C_le ... < degree ((X : polynomial α) ^ n) : by rwa [degree_X_pow]; exact with_bot.coe_lt_coe.2 hn, by rw [sub_eq_add_neg, add_comm, degree_add_eq_of_degree_lt this, degree_X_pow] lemma X_pow_sub_C_ne_zero {n : ℕ} (hn : 0 < n) (a : α) : (X : polynomial α) ^ n - C a ≠ 0 := mt degree_eq_bot.2 (show degree ((X : polynomial α) ^ n - C a) ≠ ⊥, by rw degree_X_pow_sub_C hn; exact dec_trivial) end nonzero_comm_ring section comm_ring variables [comm_ring α] {p q : polynomial α} @[simp] lemma mod_by_monic_X_sub_C_eq_C_eval (p : polynomial α) (a : α) : p %ₘ (X - C a) = C (p.eval a) := if h0 : (0 : α) = 1 then by letI := subsingleton_of_zero_eq_one α h0; exact subsingleton.elim _ _ else by letI : nonzero_comm_ring α := nonzero_comm_ring.of_ne h0; exact have h : (p %ₘ (X - C a)).eval a = p.eval a := by rw [mod_by_monic_eq_sub_mul_div _ (monic_X_sub_C a), eval_sub, eval_mul, eval_sub, eval_X, eval_C, sub_self, zero_mul, sub_zero], have degree (p %ₘ (X - C a)) < 1 := degree_X_sub_C a ▸ degree_mod_by_monic_lt p (monic_X_sub_C a) ((degree_X_sub_C a).symm ▸ ne_zero_of_monic (monic_X_sub_C _)), have degree (p %ₘ (X - C a)) ≤ 0 := begin cases (degree (p %ₘ (X - C a))), { exact bot_le }, { exact with_bot.some_le_some.2 (nat.le_of_lt_succ (with_bot.some_lt_some.1 this)) } end, begin rw [eq_C_of_degree_le_zero this, eval_C] at h, rw [eq_C_of_degree_le_zero this, h] end lemma mul_div_by_monic_eq_iff_is_root : (X - C a) * (p /ₘ (X - C a)) = p ↔ is_root p a := ⟨λ h, by rw [← h, is_root.def, eval_mul, eval_sub, eval_X, eval_C, sub_self, zero_mul], λ h : p.eval a = 0, by conv {to_rhs, rw ← mod_by_monic_add_div p (monic_X_sub_C a)}; rw [mod_by_monic_X_sub_C_eq_C_eval, h, C_0, zero_add]⟩ lemma dvd_iff_is_root : (X - C a) ∣ p ↔ is_root p a := ⟨λ h, by rwa [← dvd_iff_mod_by_monic_eq_zero (monic_X_sub_C _), mod_by_monic_X_sub_C_eq_C_eval, ← C_0, C_inj] at h, λ h, ⟨(p /ₘ (X - C a)), by rw mul_div_by_monic_eq_iff_is_root.2 h⟩⟩ lemma mod_by_monic_X (p : polynomial α) : p %ₘ X = C (p.eval 0) := by rw [← mod_by_monic_X_sub_C_eq_C_eval, C_0, sub_zero] section multiplicity def decidable_dvd_monic (p : polynomial α) (hq : monic q) : decidable (q ∣ p) := decidable_of_iff (p %ₘ q = 0) (dvd_iff_mod_by_monic_eq_zero hq) open_locale classical lemma multiplicity_X_sub_C_finite (a : α) (h0 : p ≠ 0) : multiplicity.finite (X - C a) p := multiplicity_finite_of_degree_pos_of_monic (have (0 : α) ≠ 1, from (λ h, by haveI := subsingleton_of_zero_eq_one _ h; exact h0 (subsingleton.elim _ _)), by letI : nonzero_comm_ring α := { zero_ne_one := this, ..show comm_ring α, by apply_instance }; rw degree_X_sub_C; exact dec_trivial) (monic_X_sub_C _) h0 def root_multiplicity (a : α) (p : polynomial α) : ℕ := if h0 : p = 0 then 0 else let I : decidable_pred (λ n : ℕ, ¬(X - C a) ^ (n + 1) ∣ p) := λ n, @not.decidable _ (decidable_dvd_monic p (monic_pow (monic_X_sub_C a) (n + 1))) in by exactI nat.find (multiplicity_X_sub_C_finite a h0) lemma root_multiplicity_eq_multiplicity (p : polynomial α) (a : α) : root_multiplicity a p = if h0 : p = 0 then 0 else (multiplicity (X - C a) p).get (multiplicity_X_sub_C_finite a h0) := by simp [multiplicity, root_multiplicity, roption.dom]; congr; funext; congr lemma pow_root_multiplicity_dvd (p : polynomial α) (a : α) : (X - C a) ^ root_multiplicity a p ∣ p := if h : p = 0 then by simp [h] else by rw [root_multiplicity_eq_multiplicity, dif_neg h]; exact multiplicity.pow_multiplicity_dvd _ lemma div_by_monic_mul_pow_root_multiplicity_eq (p : polynomial α) (a : α) : p /ₘ ((X - C a) ^ root_multiplicity a p) * (X - C a) ^ root_multiplicity a p = p := have monic ((X - C a) ^ root_multiplicity a p), from monic_pow (monic_X_sub_C _) _, by conv_rhs { rw [← mod_by_monic_add_div p this, (dvd_iff_mod_by_monic_eq_zero this).2 (pow_root_multiplicity_dvd _ _)] }; simp [mul_comm] lemma eval_div_by_monic_pow_root_multiplicity_ne_zero {p : polynomial α} (a : α) (hp : p ≠ 0) : (p /ₘ ((X - C a) ^ root_multiplicity a p)).eval a ≠ 0 := begin letI : nonzero_comm_ring α := nonzero_comm_ring.of_polynomial_ne hp, rw [ne.def, ← is_root.def, ← dvd_iff_is_root], rintros ⟨q, hq⟩, have := div_by_monic_mul_pow_root_multiplicity_eq p a, rw [mul_comm, hq, ← mul_assoc, ← pow_succ', root_multiplicity_eq_multiplicity, dif_neg hp] at this, exact multiplicity.is_greatest' (multiplicity_finite_of_degree_pos_of_monic (show (0 : with_bot ℕ) < degree (X - C a), by rw degree_X_sub_C; exact dec_trivial) _ hp) (nat.lt_succ_self _) (dvd_of_mul_right_eq _ this) end end multiplicity end comm_ring section integral_domain variables [integral_domain α] {p q : polynomial α} @[simp] lemma degree_mul_eq : degree (p * q) = degree p + degree q := if hp0 : p = 0 then by simp only [hp0, degree_zero, zero_mul, with_bot.bot_add] else if hq0 : q = 0 then by simp only [hq0, degree_zero, mul_zero, with_bot.add_bot] else degree_mul_eq' $ mul_ne_zero (mt leading_coeff_eq_zero.1 hp0) (mt leading_coeff_eq_zero.1 hq0) @[simp] lemma degree_pow_eq (p : polynomial α) (n : ℕ) : degree (p ^ n) = add_monoid.smul n (degree p) := by induction n; [simp only [pow_zero, degree_one, add_monoid.zero_smul], simp only [*, pow_succ, succ_smul, degree_mul_eq]] @[simp] lemma leading_coeff_mul (p q : polynomial α) : leading_coeff (p * q) = leading_coeff p * leading_coeff q := begin by_cases hp : p = 0, { simp only [hp, zero_mul, leading_coeff_zero] }, { by_cases hq : q = 0, { simp only [hq, mul_zero, leading_coeff_zero] }, { rw [leading_coeff_mul'], exact mul_ne_zero (mt leading_coeff_eq_zero.1 hp) (mt leading_coeff_eq_zero.1 hq) } } end @[simp] lemma leading_coeff_pow (p : polynomial α) (n : ℕ) : leading_coeff (p ^ n) = leading_coeff p ^ n := by induction n; [simp only [pow_zero, leading_coeff_one], simp only [*, pow_succ, leading_coeff_mul]] instance : integral_domain (polynomial α) := { eq_zero_or_eq_zero_of_mul_eq_zero := λ a b h, begin have : leading_coeff 0 = leading_coeff a * leading_coeff b := h ▸ leading_coeff_mul a b, rw [leading_coeff_zero, eq_comm] at this, erw [← leading_coeff_eq_zero, ← leading_coeff_eq_zero], exact eq_zero_or_eq_zero_of_mul_eq_zero this end, ..polynomial.nonzero_comm_ring } lemma nat_degree_mul_eq (hp : p ≠ 0) (hq : q ≠ 0) : nat_degree (p * q) = nat_degree p + nat_degree q := by rw [← with_bot.coe_eq_coe, ← degree_eq_nat_degree (mul_ne_zero hp hq), with_bot.coe_add, ← degree_eq_nat_degree hp, ← degree_eq_nat_degree hq, degree_mul_eq] @[simp] lemma nat_degree_pow_eq (p : polynomial α) (n : ℕ) : nat_degree (p ^ n) = n * nat_degree p := if hp0 : p = 0 then if hn0 : n = 0 then by simp [hp0, hn0] else by rw [hp0, zero_pow (nat.pos_of_ne_zero hn0)]; simp else nat_degree_pow_eq' (by rw [← leading_coeff_pow, ne.def, leading_coeff_eq_zero]; exact pow_ne_zero _ hp0) lemma root_or_root_of_root_mul (h : is_root (p * q) a) : is_root p a ∨ is_root q a := by rw [is_root, eval_mul] at h; exact eq_zero_or_eq_zero_of_mul_eq_zero h lemma degree_le_mul_left (p : polynomial α) (hq : q ≠ 0) : degree p ≤ degree (p * q) := if hp : p = 0 then by simp only [hp, zero_mul, le_refl] else by rw [degree_mul_eq, degree_eq_nat_degree hp, degree_eq_nat_degree hq]; exact with_bot.coe_le_coe.2 (nat.le_add_right _ _) lemma exists_finset_roots : ∀ {p : polynomial α} (hp : p ≠ 0), ∃ s : finset α, (s.card : with_bot ℕ) ≤ degree p ∧ ∀ x, x ∈ s ↔ is_root p x | p := λ hp, by haveI := classical.prop_decidable (∃ x, is_root p x); exact if h : ∃ x, is_root p x then let ⟨x, hx⟩ := h in have hpd : 0 < degree p := degree_pos_of_root hp hx, have hd0 : p /ₘ (X - C x) ≠ 0 := λ h, by rw [← mul_div_by_monic_eq_iff_is_root.2 hx, h, mul_zero] at hp; exact hp rfl, have wf : degree (p /ₘ _) < degree p := degree_div_by_monic_lt _ (monic_X_sub_C x) hp ((degree_X_sub_C x).symm ▸ dec_trivial), let ⟨t, htd, htr⟩ := @exists_finset_roots (p /ₘ (X - C x)) hd0 in have hdeg : degree (X - C x) ≤ degree p := begin rw [degree_X_sub_C, degree_eq_nat_degree hp], rw degree_eq_nat_degree hp at hpd, exact with_bot.coe_le_coe.2 (with_bot.coe_lt_coe.1 hpd) end, have hdiv0 : p /ₘ (X - C x) ≠ 0 := mt (div_by_monic_eq_zero_iff (monic_X_sub_C x) (ne_zero_of_monic (monic_X_sub_C x))).1 $ not_lt.2 hdeg, ⟨insert x t, calc (card (insert x t) : with_bot ℕ) ≤ card t + 1 : with_bot.coe_le_coe.2 $ finset.card_insert_le _ _ ... ≤ degree p : by rw [← degree_add_div_by_monic (monic_X_sub_C x) hdeg, degree_X_sub_C, add_comm]; exact add_le_add' (le_refl (1 : with_bot ℕ)) htd, begin assume y, rw [mem_insert, htr, eq_comm, ← root_X_sub_C], conv {to_rhs, rw ← mul_div_by_monic_eq_iff_is_root.2 hx}, exact ⟨λ h, or.cases_on h (root_mul_right_of_is_root _) (root_mul_left_of_is_root _), root_or_root_of_root_mul⟩ end⟩ else ⟨∅, (degree_eq_nat_degree hp).symm ▸ with_bot.coe_le_coe.2 (nat.zero_le _), by simpa only [not_mem_empty, false_iff, not_exists] using h⟩ using_well_founded {dec_tac := tactic.assumption} /-- `roots p` noncomputably gives a finset containing all the roots of `p` -/ noncomputable def roots (p : polynomial α) : finset α := if h : p = 0 then ∅ else classical.some (exists_finset_roots h) lemma card_roots (hp0 : p ≠ 0) : ((roots p).card : with_bot ℕ) ≤ degree p := begin unfold roots, rw dif_neg hp0, exact (classical.some_spec (exists_finset_roots hp0)).1 end lemma card_roots' {p : polynomial α} (hp0 : p ≠ 0) : p.roots.card ≤ nat_degree p := with_bot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq $ degree_eq_nat_degree hp0)) lemma card_roots_sub_C {p : polynomial α} {a : α} (hp0 : 0 < degree p) : ((p - C a).roots.card : with_bot ℕ) ≤ degree p := calc ((p - C a).roots.card : with_bot ℕ) ≤ degree (p - C a) : card_roots $ mt sub_eq_zero.1 $ λ h, not_le_of_gt hp0 $ h.symm ▸ degree_C_le ... = degree p : by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0 lemma card_roots_sub_C' {p : polynomial α} {a : α} (hp0 : 0 < degree p) : (p - C a).roots.card ≤ nat_degree p := with_bot.coe_le_coe.1 (le_trans (card_roots_sub_C hp0) (le_of_eq $ degree_eq_nat_degree (λ h, by simp [*, lt_irrefl] at *))) @[simp] lemma mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ is_root p a := by unfold roots; rw dif_neg hp; exact (classical.some_spec (exists_finset_roots hp)).2 _ @[simp] lemma mem_roots_sub_C {p : polynomial α} {a x : α} (hp0 : 0 < degree p) : x ∈ (p - C a).roots ↔ p.eval x = a := (mem_roots (show p - C a ≠ 0, from mt sub_eq_zero.1 $ λ h, not_le_of_gt hp0 $ h.symm ▸ degree_C_le)).trans (by rw [is_root.def, eval_sub, eval_C, sub_eq_zero]) lemma card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : α) : (roots ((X : polynomial α) ^ n - C a)).card ≤ n := with_bot.coe_le_coe.1 $ calc ((roots ((X : polynomial α) ^ n - C a)).card : with_bot ℕ) ≤ degree ((X : polynomial α) ^ n - C a) : card_roots (X_pow_sub_C_ne_zero hn a) ... = n : degree_X_pow_sub_C hn a /-- `nth_roots n a` noncomputably returns the solutions to `x ^ n = a`-/ def nth_roots {α : Type*} [integral_domain α] (n : ℕ) (a : α) : finset α := roots ((X : polynomial α) ^ n - C a) @[simp] lemma mem_nth_roots {α : Type*} [integral_domain α] {n : ℕ} (hn : 0 < n) {a x : α} : x ∈ nth_roots n a ↔ x ^ n = a := by rw [nth_roots, mem_roots (X_pow_sub_C_ne_zero hn a), is_root.def, eval_sub, eval_C, eval_pow, eval_X, sub_eq_zero_iff_eq] lemma card_nth_roots {α : Type*} [integral_domain α] (n : ℕ) (a : α) : (nth_roots n a).card ≤ n := if hn : n = 0 then if h : (X : polynomial α) ^ n - C a = 0 then by simp only [nat.zero_le, nth_roots, roots, h, dif_pos rfl, card_empty] else with_bot.coe_le_coe.1 (le_trans (card_roots h) (by rw [hn, pow_zero, ← C_1, ← @is_ring_hom.map_sub _ _ _ _ (@C α _)]; exact degree_C_le)) else by rw [← with_bot.coe_le_coe, ← degree_X_pow_sub_C (nat.pos_of_ne_zero hn) a]; exact card_roots (X_pow_sub_C_ne_zero (nat.pos_of_ne_zero hn) a) lemma coeff_comp_degree_mul_degree (hqd0 : nat_degree q ≠ 0) : coeff (p.comp q) (nat_degree p * nat_degree q) = leading_coeff p * leading_coeff q ^ nat_degree p := if hp0 : p = 0 then by simp [hp0] else calc coeff (p.comp q) (nat_degree p * nat_degree q) = p.sum (λ n a, coeff (C a * q ^ n) (nat_degree p * nat_degree q)) : by rw [comp, eval₂, coeff_sum] ... = coeff (C (leading_coeff p) * q ^ nat_degree p) (nat_degree p * nat_degree q) : finset.sum_eq_single _ begin assume b hbs hbp, have hq0 : q ≠ 0, from λ hq0, hqd0 (by rw [hq0, nat_degree_zero]), have : coeff p b ≠ 0, rwa [← apply_eq_coeff, ← finsupp.mem_support_iff], dsimp [apply_eq_coeff], refine coeff_eq_zero_of_degree_lt _, rw [degree_mul_eq, degree_C this, degree_pow_eq, zero_add, degree_eq_nat_degree hq0, ← with_bot.coe_smul, add_monoid.smul_eq_mul, with_bot.coe_lt_coe, nat.cast_id], exact (mul_lt_mul_right (nat.pos_of_ne_zero hqd0)).2 (lt_of_le_of_ne (with_bot.coe_le_coe.1 (by rw ← degree_eq_nat_degree hp0; exact le_sup hbs)) hbp) end (by rw [finsupp.mem_support_iff, apply_eq_coeff, ← leading_coeff, ne.def, leading_coeff_eq_zero, classical.not_not]; simp {contextual := tt}) ... = _ : have coeff (q ^ nat_degree p) (nat_degree p * nat_degree q) = leading_coeff (q ^ nat_degree p), by rw [leading_coeff, nat_degree_pow_eq], by rw [coeff_C_mul, this, leading_coeff_pow] lemma nat_degree_comp : nat_degree (p.comp q) = nat_degree p * nat_degree q := le_antisymm nat_degree_comp_le (if hp0 : p = 0 then by rw [hp0, zero_comp, nat_degree_zero, zero_mul] else if hqd0 : nat_degree q = 0 then have degree q ≤ 0, by rw [← with_bot.coe_zero, ← hqd0]; exact degree_le_nat_degree, by rw [eq_C_of_degree_le_zero this]; simp else le_nat_degree_of_ne_zero $ have hq0 : q ≠ 0, from λ hq0, hqd0 $ by rw [hq0, nat_degree_zero], calc coeff (p.comp q) (nat_degree p * nat_degree q) = leading_coeff p * leading_coeff q ^ nat_degree p : coeff_comp_degree_mul_degree hqd0 ... ≠ 0 : mul_ne_zero (mt leading_coeff_eq_zero.1 hp0) (pow_ne_zero _ (mt leading_coeff_eq_zero.1 hq0))) lemma leading_coeff_comp (hq : nat_degree q ≠ 0) : leading_coeff (p.comp q) = leading_coeff p * leading_coeff q ^ nat_degree p := by rw [← coeff_comp_degree_mul_degree hq, ← nat_degree_comp]; refl lemma degree_eq_zero_of_is_unit (h : is_unit p) : degree p = 0 := let ⟨q, hq⟩ := is_unit_iff_dvd_one.1 h in have hp0 : p ≠ 0, from λ hp0, by simpa [hp0] using hq, have hq0 : q ≠ 0, from λ hp0, by simpa [hp0] using hq, have nat_degree (1 : polynomial α) = nat_degree (p * q), from congr_arg _ hq, by rw [nat_degree_one, nat_degree_mul_eq hp0 hq0, eq_comm, _root_.add_eq_zero_iff, ← with_bot.coe_eq_coe, ← degree_eq_nat_degree hp0] at this; exact this.1 @[simp] lemma degree_coe_units (u : units (polynomial α)) : degree (u : polynomial α) = 0 := degree_eq_zero_of_is_unit ⟨u, rfl⟩ @[simp] lemma nat_degree_coe_units (u : units (polynomial α)) : nat_degree (u : polynomial α) = 0 := nat_degree_eq_of_degree_eq_some (degree_coe_units u) lemma coeff_coe_units_zero_ne_zero (u : units (polynomial α)) : coeff (u : polynomial α) 0 ≠ 0 := begin conv in (0) {rw [← nat_degree_coe_units u]}, rw [← leading_coeff, ne.def, leading_coeff_eq_zero], exact units.coe_ne_zero _ end lemma degree_eq_degree_of_associated (h : associated p q) : degree p = degree q := let ⟨u, hu⟩ := h in by simp [hu.symm] lemma degree_eq_one_of_irreducible_of_root (hi : irreducible p) {x : α} (hx : is_root p x) : degree p = 1 := let ⟨g, hg⟩ := dvd_iff_is_root.2 hx in have is_unit (X - C x) ∨ is_unit g, from hi.2 _ _ hg, this.elim (λ h, have h₁ : degree (X - C x) = 1, from degree_X_sub_C x, have h₂ : degree (X - C x) = 0, from degree_eq_zero_of_is_unit h, by rw h₁ at h₂; exact absurd h₂ dec_trivial) (λ hgu, by rw [hg, degree_mul_eq, degree_X_sub_C, degree_eq_zero_of_is_unit hgu, add_zero]) end integral_domain section field variables [field α] {p q : polynomial α} instance : vector_space α (polynomial α) := finsupp.vector_space _ _ lemma is_unit_iff_degree_eq_zero : is_unit p ↔ degree p = 0 := ⟨degree_eq_zero_of_is_unit, λ h, have degree p ≤ 0, by simp [*, le_refl], have hc : coeff p 0 ≠ 0, from λ hc, by rw [eq_C_of_degree_le_zero this, hc] at h; simpa using h, is_unit_iff_dvd_one.2 ⟨C (coeff p 0)⁻¹, begin conv in p { rw eq_C_of_degree_le_zero this }, rw [← C_mul, _root_.mul_inv_cancel hc, C_1] end⟩⟩ lemma degree_pos_of_ne_zero_of_nonunit (hp0 : p ≠ 0) (hp : ¬is_unit p) : 0 < degree p := lt_of_not_ge (λ h, by rw [eq_C_of_degree_le_zero h] at hp0 hp; exact (hp $ is_unit.map' C $ is_unit.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0)))) lemma irreducible_of_degree_eq_one (hp1 : degree p = 1) : irreducible p := ⟨mt is_unit_iff_dvd_one.1 (λ ⟨q, hq⟩, absurd (congr_arg degree hq) (λ h, have degree q = 0, by rw [degree_one, degree_mul_eq, hp1, eq_comm, nat.with_bot.add_eq_zero_iff] at h; exact h.2, by simp [degree_mul_eq, this, degree_one, hp1] at h; exact absurd h dec_trivial)), λ q r hpqr, begin have := congr_arg degree hpqr, rw [hp1, degree_mul_eq, eq_comm, nat.with_bot.add_eq_one_iff] at this, rw [is_unit_iff_degree_eq_zero, is_unit_iff_degree_eq_zero]; tautology end⟩ lemma monic_mul_leading_coeff_inv (h : p ≠ 0) : monic (p * C (leading_coeff p)⁻¹) := by rw [monic, leading_coeff_mul, leading_coeff_C, mul_inv_cancel (show leading_coeff p ≠ 0, from mt leading_coeff_eq_zero.1 h)] lemma degree_mul_leading_coeff_inv (p : polynomial α) (h : q ≠ 0) : degree (p * C (leading_coeff q)⁻¹) = degree p := have h₁ : (leading_coeff q)⁻¹ ≠ 0 := inv_ne_zero (mt leading_coeff_eq_zero.1 h), by rw [degree_mul_eq, degree_C h₁, add_zero] def div (p q : polynomial α) := C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹)) def mod (p q : polynomial α) := p %ₘ (q * C (leading_coeff q)⁻¹) private lemma quotient_mul_add_remainder_eq_aux (p q : polynomial α) : q * div p q + mod p q = p := if h : q = 0 then by simp only [h, zero_mul, mod, mod_by_monic_zero, zero_add] else begin conv {to_rhs, rw ← mod_by_monic_add_div p (monic_mul_leading_coeff_inv h)}, rw [div, mod, add_comm, mul_assoc] end private lemma remainder_lt_aux (p : polynomial α) (hq : q ≠ 0) : degree (mod p q) < degree q := by rw ← degree_mul_leading_coeff_inv q hq; exact degree_mod_by_monic_lt p (monic_mul_leading_coeff_inv hq) (mul_ne_zero hq (mt leading_coeff_eq_zero.2 (by rw leading_coeff_C; exact inv_ne_zero (mt leading_coeff_eq_zero.1 hq)))) instance : has_div (polynomial α) := ⟨div⟩ instance : has_mod (polynomial α) := ⟨mod⟩ lemma div_def : p / q = C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹)) := rfl lemma mod_def : p % q = p %ₘ (q * C (leading_coeff q)⁻¹) := rfl lemma mod_by_monic_eq_mod (p : polynomial α) (hq : monic q) : p %ₘ q = p % q := show p %ₘ q = p %ₘ (q * C (leading_coeff q)⁻¹), by simp only [monic.def.1 hq, inv_one, mul_one, C_1] lemma div_by_monic_eq_div (p : polynomial α) (hq : monic q) : p /ₘ q = p / q := show p /ₘ q = C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹)), by simp only [monic.def.1 hq, inv_one, C_1, one_mul, mul_one] lemma mod_X_sub_C_eq_C_eval (p : polynomial α) (a : α) : p % (X - C a) = C (p.eval a) := mod_by_monic_eq_mod p (monic_X_sub_C a) ▸ mod_by_monic_X_sub_C_eq_C_eval _ _ lemma mul_div_eq_iff_is_root : (X - C a) * (p / (X - C a)) = p ↔ is_root p a := div_by_monic_eq_div p (monic_X_sub_C a) ▸ mul_div_by_monic_eq_iff_is_root instance : euclidean_domain (polynomial α) := { quotient := (/), quotient_zero := by simp [div_def], remainder := (%), r := _, r_well_founded := degree_lt_wf, quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux, remainder_lt := λ p q hq, remainder_lt_aux _ hq, mul_left_not_lt := λ p q hq, not_lt_of_ge (degree_le_mul_left _ hq) } lemma mod_eq_self_iff (hq0 : q ≠ 0) : p % q = p ↔ degree p < degree q := ⟨λ h, h ▸ euclidean_domain.mod_lt _ hq0, λ h, have ¬degree (q * C (leading_coeff q)⁻¹) ≤ degree p := not_le_of_gt $ by rwa degree_mul_leading_coeff_inv q hq0, begin rw [mod_def, mod_by_monic, dif_pos (monic_mul_leading_coeff_inv hq0)], unfold div_mod_by_monic_aux, simp only [this, false_and, if_false] end⟩ lemma div_eq_zero_iff (hq0 : q ≠ 0) : p / q = 0 ↔ degree p < degree q := ⟨λ h, by have := euclidean_domain.div_add_mod p q; rwa [h, mul_zero, zero_add, mod_eq_self_iff hq0] at this, λ h, have hlt : degree p < degree (q * C (leading_coeff q)⁻¹), by rwa degree_mul_leading_coeff_inv q hq0, have hm : monic (q * C (leading_coeff q)⁻¹) := monic_mul_leading_coeff_inv hq0, by rw [div_def, (div_by_monic_eq_zero_iff hm (ne_zero_of_monic hm)).2 hlt, mul_zero]⟩ lemma degree_add_div (hq0 : q ≠ 0) (hpq : degree q ≤ degree p) : degree q + degree (p / q) = degree p := have degree (p % q) < degree (q * (p / q)) := calc degree (p % q) < degree q : euclidean_domain.mod_lt _ hq0 ... ≤ _ : degree_le_mul_left _ (mt (div_eq_zero_iff hq0).1 (not_lt_of_ge hpq)), by conv {to_rhs, rw [← euclidean_domain.div_add_mod p q, add_comm, degree_add_eq_of_degree_lt this, degree_mul_eq]} lemma degree_div_le (p q : polynomial α) : degree (p / q) ≤ degree p := if hq : q = 0 then by simp [hq] else by rw [div_def, mul_comm, degree_mul_leading_coeff_inv _ hq]; exact degree_div_by_monic_le _ _ lemma degree_div_lt (hp : p ≠ 0) (hq : 0 < degree q) : degree (p / q) < degree p := have hq0 : q ≠ 0, from λ hq0, by simpa [hq0] using hq, by rw [div_def, mul_comm, degree_mul_leading_coeff_inv _ hq0]; exact degree_div_by_monic_lt _ (monic_mul_leading_coeff_inv hq0) hp (by rw degree_mul_leading_coeff_inv _ hq0; exact hq) @[simp] lemma degree_map [field β] (p : polynomial α) (f : α → β) [is_ring_hom f] : degree (p.map f) = degree p := p.degree_map_eq_of_injective (is_ring_hom.injective f) @[simp] lemma nat_degree_map [field β] (f : α → β) [is_ring_hom f] : nat_degree (p.map f) = nat_degree p := nat_degree_eq_of_degree_eq (degree_map _ f) @[simp] lemma leading_coeff_map [field β] (f : α → β) [is_ring_hom f] : leading_coeff (p.map f) = f (leading_coeff p) := by simp [leading_coeff, coeff_map f] lemma map_div [field β] (f : α → β) [is_ring_hom f] : (p / q).map f = p.map f / q.map f := if hq0 : q = 0 then by simp [hq0] else by rw [div_def, div_def, map_mul, map_div_by_monic f (monic_mul_leading_coeff_inv hq0)]; simp [is_ring_hom.map_inv f, leading_coeff, coeff_map f] lemma map_mod [field β] (f : α → β) [is_ring_hom f] : (p % q).map f = p.map f % q.map f := if hq0 : q = 0 then by simp [hq0] else by rw [mod_def, mod_def, leading_coeff_map f, ← is_ring_hom.map_inv f, ← map_C f, ← map_mul f, map_mod_by_monic f (monic_mul_leading_coeff_inv hq0)] @[simp] lemma map_eq_zero [field β] (f : α → β) [is_ring_hom f] : p.map f = 0 ↔ p = 0 := by simp [polynomial.ext_iff, is_ring_hom.map_eq_zero f, coeff_map] lemma exists_root_of_degree_eq_one (h : degree p = 1) : ∃ x, is_root p x := ⟨-(p.coeff 0 / p.coeff 1), have p.coeff 1 ≠ 0, by rw ← nat_degree_eq_of_degree_eq_some h; exact mt leading_coeff_eq_zero.1 (λ h0, by simpa [h0] using h), by conv in p { rw [eq_X_add_C_of_degree_le_one (show degree p ≤ 1, by rw h; exact le_refl _)] }; simp [is_root, mul_div_cancel' _ this]⟩ lemma coeff_inv_units (u : units (polynomial α)) (n : ℕ) : ((↑u : polynomial α).coeff n)⁻¹ = ((↑u⁻¹ : polynomial α).coeff n) := begin rw [eq_C_of_degree_eq_zero (degree_coe_units u), eq_C_of_degree_eq_zero (degree_coe_units u⁻¹), coeff_C, coeff_C, inv_eq_one_div], split_ifs, { rw [div_eq_iff_mul_eq (coeff_coe_units_zero_ne_zero u), coeff_zero_eq_eval_zero, coeff_zero_eq_eval_zero, ← eval_mul, ← units.coe_mul, inv_mul_self]; simp }, { simp } end instance : normalization_domain (polynomial α) := { norm_unit := λ p, if hp0 : p = 0 then 1 else ⟨C p.leading_coeff⁻¹, C p.leading_coeff, by rw [← C_mul, inv_mul_cancel, C_1]; exact mt leading_coeff_eq_zero.1 hp0, by rw [← C_mul, mul_inv_cancel, C_1]; exact mt leading_coeff_eq_zero.1 hp0,⟩, norm_unit_zero := dif_pos rfl, norm_unit_mul := λ p q hp0 hq0, begin rw [dif_neg hp0, dif_neg hq0, dif_neg (mul_ne_zero hp0 hq0)], apply units.ext, show C (leading_coeff (p * q))⁻¹ = C (leading_coeff p)⁻¹ * C (leading_coeff q)⁻¹, rw [leading_coeff_mul, mul_inv', C_mul, mul_comm] end, norm_unit_coe_units := λ u, have hu : degree ↑u⁻¹ = 0, from degree_eq_zero_of_is_unit ⟨u⁻¹, rfl⟩, begin apply units.ext, rw [dif_neg (units.coe_ne_zero u)], conv_rhs {rw eq_C_of_degree_eq_zero hu}, refine C_inj.2 _, rw [← nat_degree_eq_of_degree_eq_some hu, leading_coeff, coeff_inv_units], simp end, ..polynomial.integral_domain } lemma monic_normalize (hp0 : p ≠ 0) : monic (normalize p) := show leading_coeff (p * ↑(dite _ _ _)) = 1, by rw dif_neg hp0; exact monic_mul_leading_coeff_inv hp0 lemma coe_norm_unit (hp : p ≠ 0) : (norm_unit p : polynomial α) = C p.leading_coeff⁻¹ := show ↑(dite _ _ _) = C p.leading_coeff⁻¹, by rw dif_neg hp; refl end field section derivative variables [comm_semiring α] /-- `derivative p` formal derivative of the polynomial `p` -/ def derivative (p : polynomial α) : polynomial α := p.sum (λn a, C (a * n) * X^(n - 1)) lemma coeff_derivative (p : polynomial α) (n : ℕ) : coeff (derivative p) n = coeff p (n + 1) * (n + 1) := begin rw [derivative], simp only [coeff_X_pow, coeff_sum, coeff_C_mul], rw [finsupp.sum, finset.sum_eq_single (n + 1), apply_eq_coeff], { rw [if_pos (nat.add_sub_cancel _ _).symm, mul_one, nat.cast_add, nat.cast_one] }, { assume b, cases b, { intros, rw [nat.cast_zero, mul_zero, zero_mul] }, { intros _ H, rw [nat.succ_sub_one b, if_neg (mt (congr_arg nat.succ) H.symm), mul_zero] } }, { intro H, rw [not_mem_support_iff.1 H, zero_mul, zero_mul] } end @[simp] lemma derivative_zero : derivative (0 : polynomial α) = 0 := finsupp.sum_zero_index lemma derivative_monomial (a : α) (n : ℕ) : derivative (C a * X ^ n) = C (a * n) * X^(n - 1) := by rw [← single_eq_C_mul_X, ← single_eq_C_mul_X, derivative, sum_single_index, single_eq_C_mul_X]; simp only [zero_mul, C_0]; refl @[simp] lemma derivative_C {a : α} : derivative (C a) = 0 := suffices derivative (C a * X^0) = C (a * 0:α) * X ^ 0, by simpa only [mul_one, zero_mul, C_0, mul_zero, pow_zero], derivative_monomial a 0 @[simp] lemma derivative_X : derivative (X : polynomial α) = 1 := suffices derivative (C (1:α) * X^1) = C (1 * (1:ℕ)) * X ^ 0, by simpa only [mul_one, one_mul, C_1, pow_one, nat.cast_one, pow_zero], derivative_monomial 1 1 @[simp] lemma derivative_one : derivative (1 : polynomial α) = 0 := derivative_C @[simp] lemma derivative_add {f g : polynomial α} : derivative (f + g) = derivative f + derivative g := by refine finsupp.sum_add_index _ _; intros; simp only [add_mul, zero_mul, C_0, C_add, C_mul] instance : is_add_monoid_hom (derivative : polynomial α → polynomial α) := { map_add := λ _ _, derivative_add, map_zero := derivative_zero } @[simp] lemma derivative_sum {s : finset β} {f : β → polynomial α} : derivative (s.sum f) = s.sum (λb, derivative (f b)) := (s.sum_hom derivative).symm @[simp] lemma derivative_mul {f g : polynomial α} : derivative (f * g) = derivative f * g + f * derivative g := calc derivative (f * g) = f.sum (λn a, g.sum (λm b, C ((a * b) * (n + m : ℕ)) * X^((n + m) - 1))) : begin transitivity, exact derivative_sum, transitivity, { apply finset.sum_congr rfl, assume x hx, exact derivative_sum }, apply finset.sum_congr rfl, assume n hn, apply finset.sum_congr rfl, assume m hm, transitivity, { apply congr_arg, exact single_eq_C_mul_X }, exact derivative_monomial _ _ end ... = f.sum (λn a, g.sum (λm b, (C (a * n) * X^(n - 1)) * (C b * X^m) + (C a * X^n) * (C (b * m) * X^(m - 1)))) : sum_congr rfl $ assume n hn, sum_congr rfl $ assume m hm, by simp only [nat.cast_add, mul_add, add_mul, C_add, C_mul]; cases n; simp only [nat.succ_sub_succ, pow_zero]; cases m; simp only [nat.cast_zero, C_0, nat.succ_sub_succ, zero_mul, mul_zero, nat.sub_zero, pow_zero, pow_add, one_mul, pow_succ, mul_comm, mul_left_comm] ... = derivative f * g + f * derivative g : begin conv { to_rhs, congr, { rw [← sum_C_mul_X_eq g] }, { rw [← sum_C_mul_X_eq f] } }, unfold derivative finsupp.sum, simp only [sum_add_distrib, finset.mul_sum, finset.sum_mul] end lemma derivative_eval (p : polynomial α) (x : α) : p.derivative.eval x = p.sum (λ n a, (a * n)*x^(n-1)) := by simp [derivative, eval_sum, eval_pow] end derivative section domain variables [integral_domain α] lemma mem_support_derivative [char_zero α] (p : polynomial α) (n : ℕ) : n ∈ (derivative p).support ↔ n + 1 ∈ p.support := suffices (¬(coeff p (n + 1) = 0 ∨ ((n + 1:ℕ) : α) = 0)) ↔ coeff p (n + 1) ≠ 0, by simpa only [coeff_derivative, apply_eq_coeff, mem_support_iff, ne.def, mul_eq_zero], by rw [nat.cast_eq_zero]; simp only [nat.succ_ne_zero, or_false] @[simp] lemma degree_derivative_eq [char_zero α] (p : polynomial α) (hp : 0 < nat_degree p) : degree (derivative p) = (nat_degree p - 1 : ℕ) := le_antisymm (le_trans (degree_sum_le _ _) $ sup_le $ assume n hn, have n ≤ nat_degree p, begin rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree], { refine le_degree_of_ne_zero _, simpa only [mem_support_iff] using hn }, { assume h, simpa only [h, support_zero] using hn } end, le_trans (degree_monomial_le _ _) $ with_bot.coe_le_coe.2 $ nat.sub_le_sub_right this _) begin refine le_sup _, rw [mem_support_derivative, nat.sub_add_cancel, mem_support_iff], { show ¬ leading_coeff p = 0, rw [leading_coeff_eq_zero], assume h, rw [h, nat_degree_zero] at hp, exact lt_irrefl 0 (lt_of_le_of_lt (zero_le _) hp), }, exact hp end end domain section identities /- @TODO: pow_add_expansion and pow_sub_pow_factor are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring Maybe use data.nat.choose to prove it. -/ def pow_add_expansion {α : Type*} [comm_semiring α] (x y : α) : ∀ (n : ℕ), {k // (x + y)^n = x^n + n*x^(n-1)*y + k * y^2} | 0 := ⟨0, by simp⟩ | 1 := ⟨0, by simp⟩ | (n+2) := begin cases pow_add_expansion (n+1) with z hz, existsi x*z + (n+1)*x^n+z*y, calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) : by ring_exp ... = (x + y) * (x ^ (n + 1) + ↑(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) : by rw hz ... = x ^ (n + 2) + ↑(n + 2) * x ^ (n + 1) * y + (x*z + (n+1)*x^n+z*y) * y ^ 2 : by { push_cast, ring_exp! } end variables [comm_ring α] private def poly_binom_aux1 (x y : α) (e : ℕ) (a : α) : {k : α // a * (x + y)^e = a * (x^e + e*x^(e-1)*y + k*y^2)} := begin existsi (pow_add_expansion x y e).val, congr, apply (pow_add_expansion _ _ _).property end private lemma poly_binom_aux2 (f : polynomial α) (x y : α) : f.eval (x + y) = f.sum (λ e a, a * (x^e + e*x^(e-1)*y + (poly_binom_aux1 x y e a).val*y^2)) := begin unfold eval eval₂, congr, ext, apply (poly_binom_aux1 x y _ _).property end private lemma poly_binom_aux3 (f : polynomial α) (x y : α) : f.eval (x + y) = f.sum (λ e a, a * x^e) + f.sum (λ e a, (a * e * x^(e-1)) * y) + f.sum (λ e a, (a *(poly_binom_aux1 x y e a).val)*y^2) := by rw poly_binom_aux2; simp [left_distrib, finsupp.sum_add, mul_assoc] def binom_expansion (f : polynomial α) (x y : α) : {k : α // f.eval (x + y) = f.eval x + (f.derivative.eval x) * y + k * y^2} := begin existsi f.sum (λ e a, a *((poly_binom_aux1 x y e a).val)), rw poly_binom_aux3, congr, { rw derivative_eval, symmetry, apply finsupp.sum_mul }, { symmetry, apply finsupp.sum_mul } end def pow_sub_pow_factor (x y : α) : Π {i : ℕ},{z : α // x^i - y^i = z*(x - y)} | 0 := ⟨0, by simp⟩ | 1 := ⟨1, by simp⟩ | (k+2) := begin cases @pow_sub_pow_factor (k+1) with z hz, existsi z*x + y^(k+1), calc x ^ (k + 2) - y ^ (k + 2) = x * (x ^ (k + 1) - y ^ (k + 1)) + (x * y ^ (k + 1) - y ^ (k + 2)) : by ring_exp ... = x * (z * (x - y)) + (x * y ^ (k + 1) - y ^ (k + 2)) : by rw hz ... = (z * x + y ^ (k + 1)) * (x - y) : by ring_exp end def eval_sub_factor (f : polynomial α) (x y : α) : {z : α // f.eval x - f.eval y = z*(x - y)} := begin existsi f.sum (λ a b, b * (pow_sub_pow_factor x y).val), unfold eval eval₂, rw [←finsupp.sum_sub], have : finsupp.sum f (λ (a : ℕ) (b : α), b * (pow_sub_pow_factor x y).val) * (x - y) = finsupp.sum f (λ (a : ℕ) (b : α), b * (pow_sub_pow_factor x y).val * (x - y)), { apply finsupp.sum_mul }, rw this, congr, ext e a, rw [mul_assoc, ←(pow_sub_pow_factor x y).property], simp [mul_sub] end end identities end polynomial namespace is_integral_domain variables {α : Type*} [comm_ring α] /-- Lift evidence that `is_integral_domain α` to `is_integral_domain (polynomial α)`. -/ lemma polynomial (h : is_integral_domain α) : is_integral_domain (polynomial α) := @integral_domain.to_is_integral_domain _ (@polynomial.integral_domain _ (h.to_integral_domain _)) end is_integral_domain
4c96e9e693cca0f0c05854ca7e1faaf18c12870d
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/simpperf/simp3000.lean
23be90708761d22b0e6036bec8beea7931bf606e
[ "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
262,598
lean
axiom f (x : Prop) : Prop axiom g0 (x : Prop) : Prop axiom g1 (x : Prop) : Prop axiom g2 (x : Prop) : Prop axiom g3 (x : Prop) : Prop axiom g4 (x : Prop) : Prop axiom g5 (x : Prop) : Prop axiom g6 (x : Prop) : Prop axiom g7 (x : Prop) : Prop axiom g8 (x : Prop) : Prop axiom g9 (x : Prop) : Prop axiom g10 (x : Prop) : Prop axiom g11 (x : Prop) : Prop axiom g12 (x : Prop) : Prop axiom g13 (x : Prop) : Prop axiom g14 (x : Prop) : Prop axiom g15 (x : Prop) : Prop axiom g16 (x : Prop) : Prop axiom g17 (x : Prop) : Prop axiom g18 (x : Prop) : Prop axiom g19 (x : Prop) : Prop axiom g20 (x : Prop) : Prop axiom g21 (x : Prop) : Prop axiom g22 (x : Prop) : Prop axiom g23 (x : Prop) : Prop axiom g24 (x : Prop) : Prop axiom g25 (x : Prop) : Prop axiom g26 (x : Prop) : Prop axiom g27 (x : Prop) : Prop axiom g28 (x : Prop) : Prop axiom g29 (x : Prop) : Prop axiom g30 (x : Prop) : Prop axiom g31 (x : Prop) : Prop axiom g32 (x : Prop) : Prop axiom g33 (x : Prop) : Prop axiom g34 (x : Prop) : Prop axiom g35 (x : Prop) : Prop axiom g36 (x : Prop) : Prop axiom g37 (x : Prop) : Prop axiom g38 (x : Prop) : Prop axiom g39 (x : Prop) : Prop axiom g40 (x : Prop) : Prop axiom g41 (x : Prop) : Prop axiom g42 (x : Prop) : Prop axiom g43 (x : Prop) : Prop axiom g44 (x : Prop) : Prop axiom g45 (x : Prop) : Prop axiom g46 (x : Prop) : Prop axiom g47 (x : Prop) : Prop axiom g48 (x : Prop) : Prop axiom g49 (x : Prop) : Prop axiom g50 (x : Prop) : Prop axiom g51 (x : Prop) : Prop axiom g52 (x : Prop) : Prop axiom g53 (x : Prop) : Prop axiom g54 (x : Prop) : Prop axiom g55 (x : Prop) : Prop axiom g56 (x : Prop) : Prop axiom g57 (x : Prop) : Prop axiom g58 (x : Prop) : Prop axiom g59 (x : Prop) : Prop axiom g60 (x : Prop) : Prop axiom g61 (x : Prop) : Prop axiom g62 (x : Prop) : Prop axiom g63 (x : Prop) : Prop axiom g64 (x : Prop) : Prop axiom g65 (x : Prop) : Prop axiom g66 (x : Prop) : Prop axiom g67 (x : Prop) : Prop axiom g68 (x : Prop) : Prop axiom g69 (x : Prop) : Prop axiom g70 (x : Prop) : Prop axiom g71 (x : Prop) : Prop axiom g72 (x : Prop) : Prop axiom g73 (x : Prop) : Prop axiom g74 (x : Prop) : Prop axiom g75 (x : Prop) : Prop axiom g76 (x : Prop) : Prop axiom g77 (x : Prop) : Prop axiom g78 (x : Prop) : Prop axiom g79 (x : Prop) : Prop axiom g80 (x : Prop) : Prop axiom g81 (x : Prop) : Prop axiom g82 (x : Prop) : Prop axiom g83 (x : Prop) : Prop axiom g84 (x : Prop) : Prop axiom g85 (x : Prop) : Prop axiom g86 (x : Prop) : Prop axiom g87 (x : Prop) : Prop axiom g88 (x : Prop) : Prop axiom g89 (x : Prop) : Prop axiom g90 (x : Prop) : Prop axiom g91 (x : Prop) : Prop axiom g92 (x : Prop) : Prop axiom g93 (x : Prop) : Prop axiom g94 (x : Prop) : Prop axiom g95 (x : Prop) : Prop axiom g96 (x : Prop) : Prop axiom g97 (x : Prop) : Prop axiom g98 (x : Prop) : Prop axiom g99 (x : Prop) : Prop axiom g100 (x : Prop) : Prop axiom g101 (x : Prop) : Prop axiom g102 (x : Prop) : Prop axiom g103 (x : Prop) : Prop axiom g104 (x : Prop) : Prop axiom g105 (x : Prop) : Prop axiom g106 (x : Prop) : Prop axiom g107 (x : Prop) : Prop axiom g108 (x : Prop) : Prop axiom g109 (x : Prop) : Prop axiom g110 (x : Prop) : Prop axiom g111 (x : Prop) : Prop axiom g112 (x : Prop) : Prop axiom g113 (x : Prop) : Prop axiom g114 (x : Prop) : Prop axiom g115 (x : Prop) : Prop axiom g116 (x : Prop) : Prop axiom g117 (x : Prop) : Prop axiom g118 (x : Prop) : Prop axiom g119 (x : Prop) : Prop axiom g120 (x : Prop) : Prop axiom g121 (x : Prop) : Prop axiom g122 (x : Prop) : Prop axiom g123 (x : Prop) : Prop axiom g124 (x : Prop) : Prop axiom g125 (x : Prop) : Prop axiom g126 (x : Prop) : Prop axiom g127 (x : Prop) : Prop axiom g128 (x : Prop) : Prop axiom g129 (x : Prop) : Prop axiom g130 (x : Prop) : Prop axiom g131 (x : Prop) : Prop axiom g132 (x : Prop) : Prop axiom g133 (x : Prop) : Prop axiom g134 (x : Prop) : Prop axiom g135 (x : Prop) : Prop axiom g136 (x : Prop) : Prop axiom g137 (x : Prop) : Prop axiom g138 (x : Prop) : Prop axiom g139 (x : Prop) : Prop axiom g140 (x : Prop) : Prop axiom g141 (x : Prop) : Prop axiom g142 (x : Prop) : Prop axiom g143 (x : Prop) : Prop axiom g144 (x : Prop) : Prop axiom g145 (x : Prop) : Prop axiom g146 (x : Prop) : Prop axiom g147 (x : Prop) : Prop axiom g148 (x : Prop) : Prop axiom g149 (x : Prop) : Prop axiom g150 (x : Prop) : Prop axiom g151 (x : Prop) : Prop axiom g152 (x : Prop) : Prop axiom g153 (x : Prop) : Prop axiom g154 (x : Prop) : Prop axiom g155 (x : Prop) : Prop axiom g156 (x : Prop) : Prop axiom g157 (x : Prop) : Prop axiom g158 (x : Prop) : Prop axiom g159 (x : Prop) : Prop axiom g160 (x : Prop) : Prop axiom g161 (x : Prop) : Prop axiom g162 (x : Prop) : Prop axiom g163 (x : Prop) : Prop axiom g164 (x : Prop) : Prop axiom g165 (x : Prop) : Prop axiom g166 (x : Prop) : Prop axiom g167 (x : Prop) : Prop axiom g168 (x : Prop) : Prop axiom g169 (x : Prop) : Prop axiom g170 (x : Prop) : Prop axiom g171 (x : Prop) : Prop axiom g172 (x : Prop) : Prop axiom g173 (x : Prop) : Prop axiom g174 (x : Prop) : Prop axiom g175 (x : Prop) : Prop axiom g176 (x : Prop) : Prop axiom g177 (x : Prop) : Prop axiom g178 (x : Prop) : Prop axiom g179 (x : Prop) : Prop axiom g180 (x : Prop) : Prop axiom g181 (x : Prop) : Prop axiom g182 (x : Prop) : Prop axiom g183 (x : Prop) : Prop axiom g184 (x : Prop) : Prop axiom g185 (x : Prop) : Prop axiom g186 (x : Prop) : Prop axiom g187 (x : Prop) : Prop axiom g188 (x : Prop) : Prop axiom g189 (x : Prop) : Prop axiom g190 (x : Prop) : Prop axiom g191 (x : Prop) : Prop axiom g192 (x : Prop) : Prop axiom g193 (x : Prop) : Prop axiom g194 (x : Prop) : Prop axiom g195 (x : Prop) : Prop axiom g196 (x : Prop) : Prop axiom g197 (x : Prop) : Prop axiom g198 (x : Prop) : Prop axiom g199 (x : Prop) : Prop axiom g200 (x : Prop) : Prop axiom g201 (x : Prop) : Prop axiom g202 (x : Prop) : Prop axiom g203 (x : Prop) : Prop axiom g204 (x : Prop) : Prop axiom g205 (x : Prop) : Prop axiom g206 (x : Prop) : Prop axiom g207 (x : Prop) : Prop axiom g208 (x : Prop) : Prop axiom g209 (x : Prop) : Prop axiom g210 (x : Prop) : Prop axiom g211 (x : Prop) : Prop axiom g212 (x : Prop) : Prop axiom g213 (x : Prop) : Prop axiom g214 (x : Prop) : Prop axiom g215 (x : Prop) : Prop axiom g216 (x : Prop) : Prop axiom g217 (x : Prop) : Prop axiom g218 (x : Prop) : Prop axiom g219 (x : Prop) : Prop axiom g220 (x : Prop) : Prop axiom g221 (x : Prop) : Prop axiom g222 (x : Prop) : Prop axiom g223 (x : Prop) : Prop axiom g224 (x : Prop) : Prop axiom g225 (x : Prop) : Prop axiom g226 (x : Prop) : Prop axiom g227 (x : Prop) : Prop axiom g228 (x : Prop) : Prop axiom g229 (x : Prop) : Prop axiom g230 (x : Prop) : Prop axiom g231 (x : Prop) : Prop axiom g232 (x : Prop) : Prop axiom g233 (x : Prop) : Prop axiom g234 (x : Prop) : Prop axiom g235 (x : Prop) : Prop axiom g236 (x : Prop) : Prop axiom g237 (x : Prop) : Prop axiom g238 (x : Prop) : Prop axiom g239 (x : Prop) : Prop axiom g240 (x : Prop) : Prop axiom g241 (x : Prop) : Prop axiom g242 (x : Prop) : Prop axiom g243 (x : Prop) : Prop axiom g244 (x : Prop) : Prop axiom g245 (x : Prop) : Prop axiom g246 (x : Prop) : Prop axiom g247 (x : Prop) : Prop axiom g248 (x : Prop) : Prop axiom g249 (x : Prop) : Prop axiom g250 (x : Prop) : Prop axiom g251 (x : Prop) : Prop axiom g252 (x : Prop) : Prop axiom g253 (x : Prop) : Prop axiom g254 (x : Prop) : Prop axiom g255 (x : Prop) : Prop axiom g256 (x : Prop) : Prop axiom g257 (x : Prop) : Prop axiom g258 (x : Prop) : Prop axiom g259 (x : Prop) : Prop axiom g260 (x : Prop) : Prop axiom g261 (x : Prop) : Prop axiom g262 (x : Prop) : Prop axiom g263 (x : Prop) : Prop axiom g264 (x : Prop) : Prop axiom g265 (x : Prop) : Prop axiom g266 (x : Prop) : Prop axiom g267 (x : Prop) : Prop axiom g268 (x : Prop) : Prop axiom g269 (x : Prop) : Prop axiom g270 (x : Prop) : Prop axiom g271 (x : Prop) : Prop axiom g272 (x : Prop) : Prop axiom g273 (x : Prop) : Prop axiom g274 (x : Prop) : Prop axiom g275 (x : Prop) : Prop axiom g276 (x : Prop) : Prop axiom g277 (x : Prop) : Prop axiom g278 (x : Prop) : Prop axiom g279 (x : Prop) : Prop axiom g280 (x : Prop) : Prop axiom g281 (x : Prop) : Prop axiom g282 (x : Prop) : Prop axiom g283 (x : Prop) : Prop axiom g284 (x : Prop) : Prop axiom g285 (x : Prop) : Prop axiom g286 (x : Prop) : Prop axiom g287 (x : Prop) : Prop axiom g288 (x : Prop) : Prop axiom g289 (x : Prop) : Prop axiom g290 (x : Prop) : Prop axiom g291 (x : Prop) : Prop axiom g292 (x : Prop) : Prop axiom g293 (x : Prop) : Prop axiom g294 (x : Prop) : Prop axiom g295 (x : Prop) : Prop axiom g296 (x : Prop) : Prop axiom g297 (x : Prop) : Prop axiom g298 (x : Prop) : Prop axiom g299 (x : Prop) : Prop axiom g300 (x : Prop) : Prop axiom g301 (x : Prop) : Prop axiom g302 (x : Prop) : Prop axiom g303 (x : Prop) : Prop axiom g304 (x : Prop) : Prop axiom g305 (x : Prop) : Prop axiom g306 (x : Prop) : Prop axiom g307 (x : Prop) : Prop axiom g308 (x : Prop) : Prop axiom g309 (x : Prop) : Prop axiom g310 (x : Prop) : Prop axiom g311 (x : Prop) : Prop axiom g312 (x : Prop) : Prop axiom g313 (x : Prop) : Prop axiom g314 (x : Prop) : Prop axiom g315 (x : Prop) : Prop axiom g316 (x : Prop) : Prop axiom g317 (x : Prop) : Prop axiom g318 (x : Prop) : Prop axiom g319 (x : Prop) : Prop axiom g320 (x : Prop) : Prop axiom g321 (x : Prop) : Prop axiom g322 (x : Prop) : Prop axiom g323 (x : Prop) : Prop axiom g324 (x : Prop) : Prop axiom g325 (x : Prop) : Prop axiom g326 (x : Prop) : Prop axiom g327 (x : Prop) : Prop axiom g328 (x : Prop) : Prop axiom g329 (x : Prop) : Prop axiom g330 (x : Prop) : Prop axiom g331 (x : Prop) : Prop axiom g332 (x : Prop) : Prop axiom g333 (x : Prop) : Prop axiom g334 (x : Prop) : Prop axiom g335 (x : Prop) : Prop axiom g336 (x : Prop) : Prop axiom g337 (x : Prop) : Prop axiom g338 (x : Prop) : Prop axiom g339 (x : Prop) : Prop axiom g340 (x : Prop) : Prop axiom g341 (x : Prop) : Prop axiom g342 (x : Prop) : Prop axiom g343 (x : Prop) : Prop axiom g344 (x : Prop) : Prop axiom g345 (x : Prop) : Prop axiom g346 (x : Prop) : Prop axiom g347 (x : Prop) : Prop axiom g348 (x : Prop) : Prop axiom g349 (x : Prop) : Prop axiom g350 (x : Prop) : Prop axiom g351 (x : Prop) : Prop axiom g352 (x : Prop) : Prop axiom g353 (x : Prop) : Prop axiom g354 (x : Prop) : Prop axiom g355 (x : Prop) : Prop axiom g356 (x : Prop) : Prop axiom g357 (x : Prop) : Prop axiom g358 (x : Prop) : Prop axiom g359 (x : Prop) : Prop axiom g360 (x : Prop) : Prop axiom g361 (x : Prop) : Prop axiom g362 (x : Prop) : Prop axiom g363 (x : Prop) : Prop axiom g364 (x : Prop) : Prop axiom g365 (x : Prop) : Prop axiom g366 (x : Prop) : Prop axiom g367 (x : Prop) : Prop axiom g368 (x : Prop) : Prop axiom g369 (x : Prop) : Prop axiom g370 (x : Prop) : Prop axiom g371 (x : Prop) : Prop axiom g372 (x : Prop) : Prop axiom g373 (x : Prop) : Prop axiom g374 (x : Prop) : Prop axiom g375 (x : Prop) : Prop axiom g376 (x : Prop) : Prop axiom g377 (x : Prop) : Prop axiom g378 (x : Prop) : Prop axiom g379 (x : Prop) : Prop axiom g380 (x : Prop) : Prop axiom g381 (x : Prop) : Prop axiom g382 (x : Prop) : Prop axiom g383 (x : Prop) : Prop axiom g384 (x : Prop) : Prop axiom g385 (x : Prop) : Prop axiom g386 (x : Prop) : Prop axiom g387 (x : Prop) : Prop axiom g388 (x : Prop) : Prop axiom g389 (x : Prop) : Prop axiom g390 (x : Prop) : Prop axiom g391 (x : Prop) : Prop axiom g392 (x : Prop) : Prop axiom g393 (x : Prop) : Prop axiom g394 (x : Prop) : Prop axiom g395 (x : Prop) : Prop axiom g396 (x : Prop) : Prop axiom g397 (x : Prop) : Prop axiom g398 (x : Prop) : Prop axiom g399 (x : Prop) : Prop axiom g400 (x : Prop) : Prop axiom g401 (x : Prop) : Prop axiom g402 (x : Prop) : Prop axiom g403 (x : Prop) : Prop axiom g404 (x : Prop) : Prop axiom g405 (x : Prop) : Prop axiom g406 (x : Prop) : Prop axiom g407 (x : Prop) : Prop axiom g408 (x : Prop) : Prop axiom g409 (x : Prop) : Prop axiom g410 (x : Prop) : Prop axiom g411 (x : Prop) : Prop axiom g412 (x : Prop) : Prop axiom g413 (x : Prop) : Prop axiom g414 (x : Prop) : Prop axiom g415 (x : Prop) : Prop axiom g416 (x : Prop) : Prop axiom g417 (x : Prop) : Prop axiom g418 (x : Prop) : Prop axiom g419 (x : Prop) : Prop axiom g420 (x : Prop) : Prop axiom g421 (x : Prop) : Prop axiom g422 (x : Prop) : Prop axiom g423 (x : Prop) : Prop axiom g424 (x : Prop) : Prop axiom g425 (x : Prop) : Prop axiom g426 (x : Prop) : Prop axiom g427 (x : Prop) : Prop axiom g428 (x : Prop) : Prop axiom g429 (x : Prop) : Prop axiom g430 (x : Prop) : Prop axiom g431 (x : Prop) : Prop axiom g432 (x : Prop) : Prop axiom g433 (x : Prop) : Prop axiom g434 (x : Prop) : Prop axiom g435 (x : Prop) : Prop axiom g436 (x : Prop) : Prop axiom g437 (x : Prop) : Prop axiom g438 (x : Prop) : Prop axiom g439 (x : Prop) : Prop axiom g440 (x : Prop) : Prop axiom g441 (x : Prop) : Prop axiom g442 (x : Prop) : Prop axiom g443 (x : Prop) : Prop axiom g444 (x : Prop) : Prop axiom g445 (x : Prop) : Prop axiom g446 (x : Prop) : Prop axiom g447 (x : Prop) : Prop axiom g448 (x : Prop) : Prop axiom g449 (x : Prop) : Prop axiom g450 (x : Prop) : Prop axiom g451 (x : Prop) : Prop axiom g452 (x : Prop) : Prop axiom g453 (x : Prop) : Prop axiom g454 (x : Prop) : Prop axiom g455 (x : Prop) : Prop axiom g456 (x : Prop) : Prop axiom g457 (x : Prop) : Prop axiom g458 (x : Prop) : Prop axiom g459 (x : Prop) : Prop axiom g460 (x : Prop) : Prop axiom g461 (x : Prop) : Prop axiom g462 (x : Prop) : Prop axiom g463 (x : Prop) : Prop axiom g464 (x : Prop) : Prop axiom g465 (x : Prop) : Prop axiom g466 (x : Prop) : Prop axiom g467 (x : Prop) : Prop axiom g468 (x : Prop) : Prop axiom g469 (x : Prop) : Prop axiom g470 (x : Prop) : Prop axiom g471 (x : Prop) : Prop axiom g472 (x : Prop) : Prop axiom g473 (x : Prop) : Prop axiom g474 (x : Prop) : Prop axiom g475 (x : Prop) : Prop axiom g476 (x : Prop) : Prop axiom g477 (x : Prop) : Prop axiom g478 (x : Prop) : Prop axiom g479 (x : Prop) : Prop axiom g480 (x : Prop) : Prop axiom g481 (x : Prop) : Prop axiom g482 (x : Prop) : Prop axiom g483 (x : Prop) : Prop axiom g484 (x : Prop) : Prop axiom g485 (x : Prop) : Prop axiom g486 (x : Prop) : Prop axiom g487 (x : Prop) : Prop axiom g488 (x : Prop) : Prop axiom g489 (x : Prop) : Prop axiom g490 (x : Prop) : Prop axiom g491 (x : Prop) : Prop axiom g492 (x : Prop) : Prop axiom g493 (x : Prop) : Prop axiom g494 (x : Prop) : Prop axiom g495 (x : Prop) : Prop axiom g496 (x : Prop) : Prop axiom g497 (x : Prop) : Prop axiom g498 (x : Prop) : Prop axiom g499 (x : Prop) : Prop axiom g500 (x : Prop) : Prop axiom g501 (x : Prop) : Prop axiom g502 (x : Prop) : Prop axiom g503 (x : Prop) : Prop axiom g504 (x : Prop) : Prop axiom g505 (x : Prop) : Prop axiom g506 (x : Prop) : Prop axiom g507 (x : Prop) : Prop axiom g508 (x : Prop) : Prop axiom g509 (x : Prop) : Prop axiom g510 (x : Prop) : Prop axiom g511 (x : Prop) : Prop axiom g512 (x : Prop) : Prop axiom g513 (x : Prop) : Prop axiom g514 (x : Prop) : Prop axiom g515 (x : Prop) : Prop axiom g516 (x : Prop) : Prop axiom g517 (x : Prop) : Prop axiom g518 (x : Prop) : Prop axiom g519 (x : Prop) : Prop axiom g520 (x : Prop) : Prop axiom g521 (x : Prop) : Prop axiom g522 (x : Prop) : Prop axiom g523 (x : Prop) : Prop axiom g524 (x : Prop) : Prop axiom g525 (x : Prop) : Prop axiom g526 (x : Prop) : Prop axiom g527 (x : Prop) : Prop axiom g528 (x : Prop) : Prop axiom g529 (x : Prop) : Prop axiom g530 (x : Prop) : Prop axiom g531 (x : Prop) : Prop axiom g532 (x : Prop) : Prop axiom g533 (x : Prop) : Prop axiom g534 (x : Prop) : Prop axiom g535 (x : Prop) : Prop axiom g536 (x : Prop) : Prop axiom g537 (x : Prop) : Prop axiom g538 (x : Prop) : Prop axiom g539 (x : Prop) : Prop axiom g540 (x : Prop) : Prop axiom g541 (x : Prop) : Prop axiom g542 (x : Prop) : Prop axiom g543 (x : Prop) : Prop axiom g544 (x : Prop) : Prop axiom g545 (x : Prop) : Prop axiom g546 (x : Prop) : Prop axiom g547 (x : Prop) : Prop axiom g548 (x : Prop) : Prop axiom g549 (x : Prop) : Prop axiom g550 (x : Prop) : Prop axiom g551 (x : Prop) : Prop axiom g552 (x : Prop) : Prop axiom g553 (x : Prop) : Prop axiom g554 (x : Prop) : Prop axiom g555 (x : Prop) : Prop axiom g556 (x : Prop) : Prop axiom g557 (x : Prop) : Prop axiom g558 (x : Prop) : Prop axiom g559 (x : Prop) : Prop axiom g560 (x : Prop) : Prop axiom g561 (x : Prop) : Prop axiom g562 (x : Prop) : Prop axiom g563 (x : Prop) : Prop axiom g564 (x : Prop) : Prop axiom g565 (x : Prop) : Prop axiom g566 (x : Prop) : Prop axiom g567 (x : Prop) : Prop axiom g568 (x : Prop) : Prop axiom g569 (x : Prop) : Prop axiom g570 (x : Prop) : Prop axiom g571 (x : Prop) : Prop axiom g572 (x : Prop) : Prop axiom g573 (x : Prop) : Prop axiom g574 (x : Prop) : Prop axiom g575 (x : Prop) : Prop axiom g576 (x : Prop) : Prop axiom g577 (x : Prop) : Prop axiom g578 (x : Prop) : Prop axiom g579 (x : Prop) : Prop axiom g580 (x : Prop) : Prop axiom g581 (x : Prop) : Prop axiom g582 (x : Prop) : Prop axiom g583 (x : Prop) : Prop axiom g584 (x : Prop) : Prop axiom g585 (x : Prop) : Prop axiom g586 (x : Prop) : Prop axiom g587 (x : Prop) : Prop axiom g588 (x : Prop) : Prop axiom g589 (x : Prop) : Prop axiom g590 (x : Prop) : Prop axiom g591 (x : Prop) : Prop axiom g592 (x : Prop) : Prop axiom g593 (x : Prop) : Prop axiom g594 (x : Prop) : Prop axiom g595 (x : Prop) : Prop axiom g596 (x : Prop) : Prop axiom g597 (x : Prop) : Prop axiom g598 (x : Prop) : Prop axiom g599 (x : Prop) : Prop axiom g600 (x : Prop) : Prop axiom g601 (x : Prop) : Prop axiom g602 (x : Prop) : Prop axiom g603 (x : Prop) : Prop axiom g604 (x : Prop) : Prop axiom g605 (x : Prop) : Prop axiom g606 (x : Prop) : Prop axiom g607 (x : Prop) : Prop axiom g608 (x : Prop) : Prop axiom g609 (x : Prop) : Prop axiom g610 (x : Prop) : Prop axiom g611 (x : Prop) : Prop axiom g612 (x : Prop) : Prop axiom g613 (x : Prop) : Prop axiom g614 (x : Prop) : Prop axiom g615 (x : Prop) : Prop axiom g616 (x : Prop) : Prop axiom g617 (x : Prop) : Prop axiom g618 (x : Prop) : Prop axiom g619 (x : Prop) : Prop axiom g620 (x : Prop) : Prop axiom g621 (x : Prop) : Prop axiom g622 (x : Prop) : Prop axiom g623 (x : Prop) : Prop axiom g624 (x : Prop) : Prop axiom g625 (x : Prop) : Prop axiom g626 (x : Prop) : Prop axiom g627 (x : Prop) : Prop axiom g628 (x : Prop) : Prop axiom g629 (x : Prop) : Prop axiom g630 (x : Prop) : Prop axiom g631 (x : Prop) : Prop axiom g632 (x : Prop) : Prop axiom g633 (x : Prop) : Prop axiom g634 (x : Prop) : Prop axiom g635 (x : Prop) : Prop axiom g636 (x : Prop) : Prop axiom g637 (x : Prop) : Prop axiom g638 (x : Prop) : Prop axiom g639 (x : Prop) : Prop axiom g640 (x : Prop) : Prop axiom g641 (x : Prop) : Prop axiom g642 (x : Prop) : Prop axiom g643 (x : Prop) : Prop axiom g644 (x : Prop) : Prop axiom g645 (x : Prop) : Prop axiom g646 (x : Prop) : Prop axiom g647 (x : Prop) : Prop axiom g648 (x : Prop) : Prop axiom g649 (x : Prop) : Prop axiom g650 (x : Prop) : Prop axiom g651 (x : Prop) : Prop axiom g652 (x : Prop) : Prop axiom g653 (x : Prop) : Prop axiom g654 (x : Prop) : Prop axiom g655 (x : Prop) : Prop axiom g656 (x : Prop) : Prop axiom g657 (x : Prop) : Prop axiom g658 (x : Prop) : Prop axiom g659 (x : Prop) : Prop axiom g660 (x : Prop) : Prop axiom g661 (x : Prop) : Prop axiom g662 (x : Prop) : Prop axiom g663 (x : Prop) : Prop axiom g664 (x : Prop) : Prop axiom g665 (x : Prop) : Prop axiom g666 (x : Prop) : Prop axiom g667 (x : Prop) : Prop axiom g668 (x : Prop) : Prop axiom g669 (x : Prop) : Prop axiom g670 (x : Prop) : Prop axiom g671 (x : Prop) : Prop axiom g672 (x : Prop) : Prop axiom g673 (x : Prop) : Prop axiom g674 (x : Prop) : Prop axiom g675 (x : Prop) : Prop axiom g676 (x : Prop) : Prop axiom g677 (x : Prop) : Prop axiom g678 (x : Prop) : Prop axiom g679 (x : Prop) : Prop axiom g680 (x : Prop) : Prop axiom g681 (x : Prop) : Prop axiom g682 (x : Prop) : Prop axiom g683 (x : Prop) : Prop axiom g684 (x : Prop) : Prop axiom g685 (x : Prop) : Prop axiom g686 (x : Prop) : Prop axiom g687 (x : Prop) : Prop axiom g688 (x : Prop) : Prop axiom g689 (x : Prop) : Prop axiom g690 (x : Prop) : Prop axiom g691 (x : Prop) : Prop axiom g692 (x : Prop) : Prop axiom g693 (x : Prop) : Prop axiom g694 (x : Prop) : Prop axiom g695 (x : Prop) : Prop axiom g696 (x : Prop) : Prop axiom g697 (x : Prop) : Prop axiom g698 (x : Prop) : Prop axiom g699 (x : Prop) : Prop axiom g700 (x : Prop) : Prop axiom g701 (x : Prop) : Prop axiom g702 (x : Prop) : Prop axiom g703 (x : Prop) : Prop axiom g704 (x : Prop) : Prop axiom g705 (x : Prop) : Prop axiom g706 (x : Prop) : Prop axiom g707 (x : Prop) : Prop axiom g708 (x : Prop) : Prop axiom g709 (x : Prop) : Prop axiom g710 (x : Prop) : Prop axiom g711 (x : Prop) : Prop axiom g712 (x : Prop) : Prop axiom g713 (x : Prop) : Prop axiom g714 (x : Prop) : Prop axiom g715 (x : Prop) : Prop axiom g716 (x : Prop) : Prop axiom g717 (x : Prop) : Prop axiom g718 (x : Prop) : Prop axiom g719 (x : Prop) : Prop axiom g720 (x : Prop) : Prop axiom g721 (x : Prop) : Prop axiom g722 (x : Prop) : Prop axiom g723 (x : Prop) : Prop axiom g724 (x : Prop) : Prop axiom g725 (x : Prop) : Prop axiom g726 (x : Prop) : Prop axiom g727 (x : Prop) : Prop axiom g728 (x : Prop) : Prop axiom g729 (x : Prop) : Prop axiom g730 (x : Prop) : Prop axiom g731 (x : Prop) : Prop axiom g732 (x : Prop) : Prop axiom g733 (x : Prop) : Prop axiom g734 (x : Prop) : Prop axiom g735 (x : Prop) : Prop axiom g736 (x : Prop) : Prop axiom g737 (x : Prop) : Prop axiom g738 (x : Prop) : Prop axiom g739 (x : Prop) : Prop axiom g740 (x : Prop) : Prop axiom g741 (x : Prop) : Prop axiom g742 (x : Prop) : Prop axiom g743 (x : Prop) : Prop axiom g744 (x : Prop) : Prop axiom g745 (x : Prop) : Prop axiom g746 (x : Prop) : Prop axiom g747 (x : Prop) : Prop axiom g748 (x : Prop) : Prop axiom g749 (x : Prop) : Prop axiom g750 (x : Prop) : Prop axiom g751 (x : Prop) : Prop axiom g752 (x : Prop) : Prop axiom g753 (x : Prop) : Prop axiom g754 (x : Prop) : Prop axiom g755 (x : Prop) : Prop axiom g756 (x : Prop) : Prop axiom g757 (x : Prop) : Prop axiom g758 (x : Prop) : Prop axiom g759 (x : Prop) : Prop axiom g760 (x : Prop) : Prop axiom g761 (x : Prop) : Prop axiom g762 (x : Prop) : Prop axiom g763 (x : Prop) : Prop axiom g764 (x : Prop) : Prop axiom g765 (x : Prop) : Prop axiom g766 (x : Prop) : Prop axiom g767 (x : Prop) : Prop axiom g768 (x : Prop) : Prop axiom g769 (x : Prop) : Prop axiom g770 (x : Prop) : Prop axiom g771 (x : Prop) : Prop axiom g772 (x : Prop) : Prop axiom g773 (x : Prop) : Prop axiom g774 (x : Prop) : Prop axiom g775 (x : Prop) : Prop axiom g776 (x : Prop) : Prop axiom g777 (x : Prop) : Prop axiom g778 (x : Prop) : Prop axiom g779 (x : Prop) : Prop axiom g780 (x : Prop) : Prop axiom g781 (x : Prop) : Prop axiom g782 (x : Prop) : Prop axiom g783 (x : Prop) : Prop axiom g784 (x : Prop) : Prop axiom g785 (x : Prop) : Prop axiom g786 (x : Prop) : Prop axiom g787 (x : Prop) : Prop axiom g788 (x : Prop) : Prop axiom g789 (x : Prop) : Prop axiom g790 (x : Prop) : Prop axiom g791 (x : Prop) : Prop axiom g792 (x : Prop) : Prop axiom g793 (x : Prop) : Prop axiom g794 (x : Prop) : Prop axiom g795 (x : Prop) : Prop axiom g796 (x : Prop) : Prop axiom g797 (x : Prop) : Prop axiom g798 (x : Prop) : Prop axiom g799 (x : Prop) : Prop axiom g800 (x : Prop) : Prop axiom g801 (x : Prop) : Prop axiom g802 (x : Prop) : Prop axiom g803 (x : Prop) : Prop axiom g804 (x : Prop) : Prop axiom g805 (x : Prop) : Prop axiom g806 (x : Prop) : Prop axiom g807 (x : Prop) : Prop axiom g808 (x : Prop) : Prop axiom g809 (x : Prop) : Prop axiom g810 (x : Prop) : Prop axiom g811 (x : Prop) : Prop axiom g812 (x : Prop) : Prop axiom g813 (x : Prop) : Prop axiom g814 (x : Prop) : Prop axiom g815 (x : Prop) : Prop axiom g816 (x : Prop) : Prop axiom g817 (x : Prop) : Prop axiom g818 (x : Prop) : Prop axiom g819 (x : Prop) : Prop axiom g820 (x : Prop) : Prop axiom g821 (x : Prop) : Prop axiom g822 (x : Prop) : Prop axiom g823 (x : Prop) : Prop axiom g824 (x : Prop) : Prop axiom g825 (x : Prop) : Prop axiom g826 (x : Prop) : Prop axiom g827 (x : Prop) : Prop axiom g828 (x : Prop) : Prop axiom g829 (x : Prop) : Prop axiom g830 (x : Prop) : Prop axiom g831 (x : Prop) : Prop axiom g832 (x : Prop) : Prop axiom g833 (x : Prop) : Prop axiom g834 (x : Prop) : Prop axiom g835 (x : Prop) : Prop axiom g836 (x : Prop) : Prop axiom g837 (x : Prop) : Prop axiom g838 (x : Prop) : Prop axiom g839 (x : Prop) : Prop axiom g840 (x : Prop) : Prop axiom g841 (x : Prop) : Prop axiom g842 (x : Prop) : Prop axiom g843 (x : Prop) : Prop axiom g844 (x : Prop) : Prop axiom g845 (x : Prop) : Prop axiom g846 (x : Prop) : Prop axiom g847 (x : Prop) : Prop axiom g848 (x : Prop) : Prop axiom g849 (x : Prop) : Prop axiom g850 (x : Prop) : Prop axiom g851 (x : Prop) : Prop axiom g852 (x : Prop) : Prop axiom g853 (x : Prop) : Prop axiom g854 (x : Prop) : Prop axiom g855 (x : Prop) : Prop axiom g856 (x : Prop) : Prop axiom g857 (x : Prop) : Prop axiom g858 (x : Prop) : Prop axiom g859 (x : Prop) : Prop axiom g860 (x : Prop) : Prop axiom g861 (x : Prop) : Prop axiom g862 (x : Prop) : Prop axiom g863 (x : Prop) : Prop axiom g864 (x : Prop) : Prop axiom g865 (x : Prop) : Prop axiom g866 (x : Prop) : Prop axiom g867 (x : Prop) : Prop axiom g868 (x : Prop) : Prop axiom g869 (x : Prop) : Prop axiom g870 (x : Prop) : Prop axiom g871 (x : Prop) : Prop axiom g872 (x : Prop) : Prop axiom g873 (x : Prop) : Prop axiom g874 (x : Prop) : Prop axiom g875 (x : Prop) : Prop axiom g876 (x : Prop) : Prop axiom g877 (x : Prop) : Prop axiom g878 (x : Prop) : Prop axiom g879 (x : Prop) : Prop axiom g880 (x : Prop) : Prop axiom g881 (x : Prop) : Prop axiom g882 (x : Prop) : Prop axiom g883 (x : Prop) : Prop axiom g884 (x : Prop) : Prop axiom g885 (x : Prop) : Prop axiom g886 (x : Prop) : Prop axiom g887 (x : Prop) : Prop axiom g888 (x : Prop) : Prop axiom g889 (x : Prop) : Prop axiom g890 (x : Prop) : Prop axiom g891 (x : Prop) : Prop axiom g892 (x : Prop) : Prop axiom g893 (x : Prop) : Prop axiom g894 (x : Prop) : Prop axiom g895 (x : Prop) : Prop axiom g896 (x : Prop) : Prop axiom g897 (x : Prop) : Prop axiom g898 (x : Prop) : Prop axiom g899 (x : Prop) : Prop axiom g900 (x : Prop) : Prop axiom g901 (x : Prop) : Prop axiom g902 (x : Prop) : Prop axiom g903 (x : Prop) : Prop axiom g904 (x : Prop) : Prop axiom g905 (x : Prop) : Prop axiom g906 (x : Prop) : Prop axiom g907 (x : Prop) : Prop axiom g908 (x : Prop) : Prop axiom g909 (x : Prop) : Prop axiom g910 (x : Prop) : Prop axiom g911 (x : Prop) : Prop axiom g912 (x : Prop) : Prop axiom g913 (x : Prop) : Prop axiom g914 (x : Prop) : Prop axiom g915 (x : Prop) : Prop axiom g916 (x : Prop) : Prop axiom g917 (x : Prop) : Prop axiom g918 (x : Prop) : Prop axiom g919 (x : Prop) : Prop axiom g920 (x : Prop) : Prop axiom g921 (x : Prop) : Prop axiom g922 (x : Prop) : Prop axiom g923 (x : Prop) : Prop axiom g924 (x : Prop) : Prop axiom g925 (x : Prop) : Prop axiom g926 (x : Prop) : Prop axiom g927 (x : Prop) : Prop axiom g928 (x : Prop) : Prop axiom g929 (x : Prop) : Prop axiom g930 (x : Prop) : Prop axiom g931 (x : Prop) : Prop axiom g932 (x : Prop) : Prop axiom g933 (x : Prop) : Prop axiom g934 (x : Prop) : Prop axiom g935 (x : Prop) : Prop axiom g936 (x : Prop) : Prop axiom g937 (x : Prop) : Prop axiom g938 (x : Prop) : Prop axiom g939 (x : Prop) : Prop axiom g940 (x : Prop) : Prop axiom g941 (x : Prop) : Prop axiom g942 (x : Prop) : Prop axiom g943 (x : Prop) : Prop axiom g944 (x : Prop) : Prop axiom g945 (x : Prop) : Prop axiom g946 (x : Prop) : Prop axiom g947 (x : Prop) : Prop axiom g948 (x : Prop) : Prop axiom g949 (x : Prop) : Prop axiom g950 (x : Prop) : Prop axiom g951 (x : Prop) : Prop axiom g952 (x : Prop) : Prop axiom g953 (x : Prop) : Prop axiom g954 (x : Prop) : Prop axiom g955 (x : Prop) : Prop axiom g956 (x : Prop) : Prop axiom g957 (x : Prop) : Prop axiom g958 (x : Prop) : Prop axiom g959 (x : Prop) : Prop axiom g960 (x : Prop) : Prop axiom g961 (x : Prop) : Prop axiom g962 (x : Prop) : Prop axiom g963 (x : Prop) : Prop axiom g964 (x : Prop) : Prop axiom g965 (x : Prop) : Prop axiom g966 (x : Prop) : Prop axiom g967 (x : Prop) : Prop axiom g968 (x : Prop) : Prop axiom g969 (x : Prop) : Prop axiom g970 (x : Prop) : Prop axiom g971 (x : Prop) : Prop axiom g972 (x : Prop) : Prop axiom g973 (x : Prop) : Prop axiom g974 (x : Prop) : Prop axiom g975 (x : Prop) : Prop axiom g976 (x : Prop) : Prop axiom g977 (x : Prop) : Prop axiom g978 (x : Prop) : Prop axiom g979 (x : Prop) : Prop axiom g980 (x : Prop) : Prop axiom g981 (x : Prop) : Prop axiom g982 (x : Prop) : Prop axiom g983 (x : Prop) : Prop axiom g984 (x : Prop) : Prop axiom g985 (x : Prop) : Prop axiom g986 (x : Prop) : Prop axiom g987 (x : Prop) : Prop axiom g988 (x : Prop) : Prop axiom g989 (x : Prop) : Prop axiom g990 (x : Prop) : Prop axiom g991 (x : Prop) : Prop axiom g992 (x : Prop) : Prop axiom g993 (x : Prop) : Prop axiom g994 (x : Prop) : Prop axiom g995 (x : Prop) : Prop axiom g996 (x : Prop) : Prop axiom g997 (x : Prop) : Prop axiom g998 (x : Prop) : Prop axiom g999 (x : Prop) : Prop axiom g1000 (x : Prop) : Prop axiom g1001 (x : Prop) : Prop axiom g1002 (x : Prop) : Prop axiom g1003 (x : Prop) : Prop axiom g1004 (x : Prop) : Prop axiom g1005 (x : Prop) : Prop axiom g1006 (x : Prop) : Prop axiom g1007 (x : Prop) : Prop axiom g1008 (x : Prop) : Prop axiom g1009 (x : Prop) : Prop axiom g1010 (x : Prop) : Prop axiom g1011 (x : Prop) : Prop axiom g1012 (x : Prop) : Prop axiom g1013 (x : Prop) : Prop axiom g1014 (x : Prop) : Prop axiom g1015 (x : Prop) : Prop axiom g1016 (x : Prop) : Prop axiom g1017 (x : Prop) : Prop axiom g1018 (x : Prop) : Prop axiom g1019 (x : Prop) : Prop axiom g1020 (x : Prop) : Prop axiom g1021 (x : Prop) : Prop axiom g1022 (x : Prop) : Prop axiom g1023 (x : Prop) : Prop axiom g1024 (x : Prop) : Prop axiom g1025 (x : Prop) : Prop axiom g1026 (x : Prop) : Prop axiom g1027 (x : Prop) : Prop axiom g1028 (x : Prop) : Prop axiom g1029 (x : Prop) : Prop axiom g1030 (x : Prop) : Prop axiom g1031 (x : Prop) : Prop axiom g1032 (x : Prop) : Prop axiom g1033 (x : Prop) : Prop axiom g1034 (x : Prop) : Prop axiom g1035 (x : Prop) : Prop axiom g1036 (x : Prop) : Prop axiom g1037 (x : Prop) : Prop axiom g1038 (x : Prop) : Prop axiom g1039 (x : Prop) : Prop axiom g1040 (x : Prop) : Prop axiom g1041 (x : Prop) : Prop axiom g1042 (x : Prop) : Prop axiom g1043 (x : Prop) : Prop axiom g1044 (x : Prop) : Prop axiom g1045 (x : Prop) : Prop axiom g1046 (x : Prop) : Prop axiom g1047 (x : Prop) : Prop axiom g1048 (x : Prop) : Prop axiom g1049 (x : Prop) : Prop axiom g1050 (x : Prop) : Prop axiom g1051 (x : Prop) : Prop axiom g1052 (x : Prop) : Prop axiom g1053 (x : Prop) : Prop axiom g1054 (x : Prop) : Prop axiom g1055 (x : Prop) : Prop axiom g1056 (x : Prop) : Prop axiom g1057 (x : Prop) : Prop axiom g1058 (x : Prop) : Prop axiom g1059 (x : Prop) : Prop axiom g1060 (x : Prop) : Prop axiom g1061 (x : Prop) : Prop axiom g1062 (x : Prop) : Prop axiom g1063 (x : Prop) : Prop axiom g1064 (x : Prop) : Prop axiom g1065 (x : Prop) : Prop axiom g1066 (x : Prop) : Prop axiom g1067 (x : Prop) : Prop axiom g1068 (x : Prop) : Prop axiom g1069 (x : Prop) : Prop axiom g1070 (x : Prop) : Prop axiom g1071 (x : Prop) : Prop axiom g1072 (x : Prop) : Prop axiom g1073 (x : Prop) : Prop axiom g1074 (x : Prop) : Prop axiom g1075 (x : Prop) : Prop axiom g1076 (x : Prop) : Prop axiom g1077 (x : Prop) : Prop axiom g1078 (x : Prop) : Prop axiom g1079 (x : Prop) : Prop axiom g1080 (x : Prop) : Prop axiom g1081 (x : Prop) : Prop axiom g1082 (x : Prop) : Prop axiom g1083 (x : Prop) : Prop axiom g1084 (x : Prop) : Prop axiom g1085 (x : Prop) : Prop axiom g1086 (x : Prop) : Prop axiom g1087 (x : Prop) : Prop axiom g1088 (x : Prop) : Prop axiom g1089 (x : Prop) : Prop axiom g1090 (x : Prop) : Prop axiom g1091 (x : Prop) : Prop axiom g1092 (x : Prop) : Prop axiom g1093 (x : Prop) : Prop axiom g1094 (x : Prop) : Prop axiom g1095 (x : Prop) : Prop axiom g1096 (x : Prop) : Prop axiom g1097 (x : Prop) : Prop axiom g1098 (x : Prop) : Prop axiom g1099 (x : Prop) : Prop axiom g1100 (x : Prop) : Prop axiom g1101 (x : Prop) : Prop axiom g1102 (x : Prop) : Prop axiom g1103 (x : Prop) : Prop axiom g1104 (x : Prop) : Prop axiom g1105 (x : Prop) : Prop axiom g1106 (x : Prop) : Prop axiom g1107 (x : Prop) : Prop axiom g1108 (x : Prop) : Prop axiom g1109 (x : Prop) : Prop axiom g1110 (x : Prop) : Prop axiom g1111 (x : Prop) : Prop axiom g1112 (x : Prop) : Prop axiom g1113 (x : Prop) : Prop axiom g1114 (x : Prop) : Prop axiom g1115 (x : Prop) : Prop axiom g1116 (x : Prop) : Prop axiom g1117 (x : Prop) : Prop axiom g1118 (x : Prop) : Prop axiom g1119 (x : Prop) : Prop axiom g1120 (x : Prop) : Prop axiom g1121 (x : Prop) : Prop axiom g1122 (x : Prop) : Prop axiom g1123 (x : Prop) : Prop axiom g1124 (x : Prop) : Prop axiom g1125 (x : Prop) : Prop axiom g1126 (x : Prop) : Prop axiom g1127 (x : Prop) : Prop axiom g1128 (x : Prop) : Prop axiom g1129 (x : Prop) : Prop axiom g1130 (x : Prop) : Prop axiom g1131 (x : Prop) : Prop axiom g1132 (x : Prop) : Prop axiom g1133 (x : Prop) : Prop axiom g1134 (x : Prop) : Prop axiom g1135 (x : Prop) : Prop axiom g1136 (x : Prop) : Prop axiom g1137 (x : Prop) : Prop axiom g1138 (x : Prop) : Prop axiom g1139 (x : Prop) : Prop axiom g1140 (x : Prop) : Prop axiom g1141 (x : Prop) : Prop axiom g1142 (x : Prop) : Prop axiom g1143 (x : Prop) : Prop axiom g1144 (x : Prop) : Prop axiom g1145 (x : Prop) : Prop axiom g1146 (x : Prop) : Prop axiom g1147 (x : Prop) : Prop axiom g1148 (x : Prop) : Prop axiom g1149 (x : Prop) : Prop axiom g1150 (x : Prop) : Prop axiom g1151 (x : Prop) : Prop axiom g1152 (x : Prop) : Prop axiom g1153 (x : Prop) : Prop axiom g1154 (x : Prop) : Prop axiom g1155 (x : Prop) : Prop axiom g1156 (x : Prop) : Prop axiom g1157 (x : Prop) : Prop axiom g1158 (x : Prop) : Prop axiom g1159 (x : Prop) : Prop axiom g1160 (x : Prop) : Prop axiom g1161 (x : Prop) : Prop axiom g1162 (x : Prop) : Prop axiom g1163 (x : Prop) : Prop axiom g1164 (x : Prop) : Prop axiom g1165 (x : Prop) : Prop axiom g1166 (x : Prop) : Prop axiom g1167 (x : Prop) : Prop axiom g1168 (x : Prop) : Prop axiom g1169 (x : Prop) : Prop axiom g1170 (x : Prop) : Prop axiom g1171 (x : Prop) : Prop axiom g1172 (x : Prop) : Prop axiom g1173 (x : Prop) : Prop axiom g1174 (x : Prop) : Prop axiom g1175 (x : Prop) : Prop axiom g1176 (x : Prop) : Prop axiom g1177 (x : Prop) : Prop axiom g1178 (x : Prop) : Prop axiom g1179 (x : Prop) : Prop axiom g1180 (x : Prop) : Prop axiom g1181 (x : Prop) : Prop axiom g1182 (x : Prop) : Prop axiom g1183 (x : Prop) : Prop axiom g1184 (x : Prop) : Prop axiom g1185 (x : Prop) : Prop axiom g1186 (x : Prop) : Prop axiom g1187 (x : Prop) : Prop axiom g1188 (x : Prop) : Prop axiom g1189 (x : Prop) : Prop axiom g1190 (x : Prop) : Prop axiom g1191 (x : Prop) : Prop axiom g1192 (x : Prop) : Prop axiom g1193 (x : Prop) : Prop axiom g1194 (x : Prop) : Prop axiom g1195 (x : Prop) : Prop axiom g1196 (x : Prop) : Prop axiom g1197 (x : Prop) : Prop axiom g1198 (x : Prop) : Prop axiom g1199 (x : Prop) : Prop axiom g1200 (x : Prop) : Prop axiom g1201 (x : Prop) : Prop axiom g1202 (x : Prop) : Prop axiom g1203 (x : Prop) : Prop axiom g1204 (x : Prop) : Prop axiom g1205 (x : Prop) : Prop axiom g1206 (x : Prop) : Prop axiom g1207 (x : Prop) : Prop axiom g1208 (x : Prop) : Prop axiom g1209 (x : Prop) : Prop axiom g1210 (x : Prop) : Prop axiom g1211 (x : Prop) : Prop axiom g1212 (x : Prop) : Prop axiom g1213 (x : Prop) : Prop axiom g1214 (x : Prop) : Prop axiom g1215 (x : Prop) : Prop axiom g1216 (x : Prop) : Prop axiom g1217 (x : Prop) : Prop axiom g1218 (x : Prop) : Prop axiom g1219 (x : Prop) : Prop axiom g1220 (x : Prop) : Prop axiom g1221 (x : Prop) : Prop axiom g1222 (x : Prop) : Prop axiom g1223 (x : Prop) : Prop axiom g1224 (x : Prop) : Prop axiom g1225 (x : Prop) : Prop axiom g1226 (x : Prop) : Prop axiom g1227 (x : Prop) : Prop axiom g1228 (x : Prop) : Prop axiom g1229 (x : Prop) : Prop axiom g1230 (x : Prop) : Prop axiom g1231 (x : Prop) : Prop axiom g1232 (x : Prop) : Prop axiom g1233 (x : Prop) : Prop axiom g1234 (x : Prop) : Prop axiom g1235 (x : Prop) : Prop axiom g1236 (x : Prop) : Prop axiom g1237 (x : Prop) : Prop axiom g1238 (x : Prop) : Prop axiom g1239 (x : Prop) : Prop axiom g1240 (x : Prop) : Prop axiom g1241 (x : Prop) : Prop axiom g1242 (x : Prop) : Prop axiom g1243 (x : Prop) : Prop axiom g1244 (x : Prop) : Prop axiom g1245 (x : Prop) : Prop axiom g1246 (x : Prop) : Prop axiom g1247 (x : Prop) : Prop axiom g1248 (x : Prop) : Prop axiom g1249 (x : Prop) : Prop axiom g1250 (x : Prop) : Prop axiom g1251 (x : Prop) : Prop axiom g1252 (x : Prop) : Prop axiom g1253 (x : Prop) : Prop axiom g1254 (x : Prop) : Prop axiom g1255 (x : Prop) : Prop axiom g1256 (x : Prop) : Prop axiom g1257 (x : Prop) : Prop axiom g1258 (x : Prop) : Prop axiom g1259 (x : Prop) : Prop axiom g1260 (x : Prop) : Prop axiom g1261 (x : Prop) : Prop axiom g1262 (x : Prop) : Prop axiom g1263 (x : Prop) : Prop axiom g1264 (x : Prop) : Prop axiom g1265 (x : Prop) : Prop axiom g1266 (x : Prop) : Prop axiom g1267 (x : Prop) : Prop axiom g1268 (x : Prop) : Prop axiom g1269 (x : Prop) : Prop axiom g1270 (x : Prop) : Prop axiom g1271 (x : Prop) : Prop axiom g1272 (x : Prop) : Prop axiom g1273 (x : Prop) : Prop axiom g1274 (x : Prop) : Prop axiom g1275 (x : Prop) : Prop axiom g1276 (x : Prop) : Prop axiom g1277 (x : Prop) : Prop axiom g1278 (x : Prop) : Prop axiom g1279 (x : Prop) : Prop axiom g1280 (x : Prop) : Prop axiom g1281 (x : Prop) : Prop axiom g1282 (x : Prop) : Prop axiom g1283 (x : Prop) : Prop axiom g1284 (x : Prop) : Prop axiom g1285 (x : Prop) : Prop axiom g1286 (x : Prop) : Prop axiom g1287 (x : Prop) : Prop axiom g1288 (x : Prop) : Prop axiom g1289 (x : Prop) : Prop axiom g1290 (x : Prop) : Prop axiom g1291 (x : Prop) : Prop axiom g1292 (x : Prop) : Prop axiom g1293 (x : Prop) : Prop axiom g1294 (x : Prop) : Prop axiom g1295 (x : Prop) : Prop axiom g1296 (x : Prop) : Prop axiom g1297 (x : Prop) : Prop axiom g1298 (x : Prop) : Prop axiom g1299 (x : Prop) : Prop axiom g1300 (x : Prop) : Prop axiom g1301 (x : Prop) : Prop axiom g1302 (x : Prop) : Prop axiom g1303 (x : Prop) : Prop axiom g1304 (x : Prop) : Prop axiom g1305 (x : Prop) : Prop axiom g1306 (x : Prop) : Prop axiom g1307 (x : Prop) : Prop axiom g1308 (x : Prop) : Prop axiom g1309 (x : Prop) : Prop axiom g1310 (x : Prop) : Prop axiom g1311 (x : Prop) : Prop axiom g1312 (x : Prop) : Prop axiom g1313 (x : Prop) : Prop axiom g1314 (x : Prop) : Prop axiom g1315 (x : Prop) : Prop axiom g1316 (x : Prop) : Prop axiom g1317 (x : Prop) : Prop axiom g1318 (x : Prop) : Prop axiom g1319 (x : Prop) : Prop axiom g1320 (x : Prop) : Prop axiom g1321 (x : Prop) : Prop axiom g1322 (x : Prop) : Prop axiom g1323 (x : Prop) : Prop axiom g1324 (x : Prop) : Prop axiom g1325 (x : Prop) : Prop axiom g1326 (x : Prop) : Prop axiom g1327 (x : Prop) : Prop axiom g1328 (x : Prop) : Prop axiom g1329 (x : Prop) : Prop axiom g1330 (x : Prop) : Prop axiom g1331 (x : Prop) : Prop axiom g1332 (x : Prop) : Prop axiom g1333 (x : Prop) : Prop axiom g1334 (x : Prop) : Prop axiom g1335 (x : Prop) : Prop axiom g1336 (x : Prop) : Prop axiom g1337 (x : Prop) : Prop axiom g1338 (x : Prop) : Prop axiom g1339 (x : Prop) : Prop axiom g1340 (x : Prop) : Prop axiom g1341 (x : Prop) : Prop axiom g1342 (x : Prop) : Prop axiom g1343 (x : Prop) : Prop axiom g1344 (x : Prop) : Prop axiom g1345 (x : Prop) : Prop axiom g1346 (x : Prop) : Prop axiom g1347 (x : Prop) : Prop axiom g1348 (x : Prop) : Prop axiom g1349 (x : Prop) : Prop axiom g1350 (x : Prop) : Prop axiom g1351 (x : Prop) : Prop axiom g1352 (x : Prop) : Prop axiom g1353 (x : Prop) : Prop axiom g1354 (x : Prop) : Prop axiom g1355 (x : Prop) : Prop axiom g1356 (x : Prop) : Prop axiom g1357 (x : Prop) : Prop axiom g1358 (x : Prop) : Prop axiom g1359 (x : Prop) : Prop axiom g1360 (x : Prop) : Prop axiom g1361 (x : Prop) : Prop axiom g1362 (x : Prop) : Prop axiom g1363 (x : Prop) : Prop axiom g1364 (x : Prop) : Prop axiom g1365 (x : Prop) : Prop axiom g1366 (x : Prop) : Prop axiom g1367 (x : Prop) : Prop axiom g1368 (x : Prop) : Prop axiom g1369 (x : Prop) : Prop axiom g1370 (x : Prop) : Prop axiom g1371 (x : Prop) : Prop axiom g1372 (x : Prop) : Prop axiom g1373 (x : Prop) : Prop axiom g1374 (x : Prop) : Prop axiom g1375 (x : Prop) : Prop axiom g1376 (x : Prop) : Prop axiom g1377 (x : Prop) : Prop axiom g1378 (x : Prop) : Prop axiom g1379 (x : Prop) : Prop axiom g1380 (x : Prop) : Prop axiom g1381 (x : Prop) : Prop axiom g1382 (x : Prop) : Prop axiom g1383 (x : Prop) : Prop axiom g1384 (x : Prop) : Prop axiom g1385 (x : Prop) : Prop axiom g1386 (x : Prop) : Prop axiom g1387 (x : Prop) : Prop axiom g1388 (x : Prop) : Prop axiom g1389 (x : Prop) : Prop axiom g1390 (x : Prop) : Prop axiom g1391 (x : Prop) : Prop axiom g1392 (x : Prop) : Prop axiom g1393 (x : Prop) : Prop axiom g1394 (x : Prop) : Prop axiom g1395 (x : Prop) : Prop axiom g1396 (x : Prop) : Prop axiom g1397 (x : Prop) : Prop axiom g1398 (x : Prop) : Prop axiom g1399 (x : Prop) : Prop axiom g1400 (x : Prop) : Prop axiom g1401 (x : Prop) : Prop axiom g1402 (x : Prop) : Prop axiom g1403 (x : Prop) : Prop axiom g1404 (x : Prop) : Prop axiom g1405 (x : Prop) : Prop axiom g1406 (x : Prop) : Prop axiom g1407 (x : Prop) : Prop axiom g1408 (x : Prop) : Prop axiom g1409 (x : Prop) : Prop axiom g1410 (x : Prop) : Prop axiom g1411 (x : Prop) : Prop axiom g1412 (x : Prop) : Prop axiom g1413 (x : Prop) : Prop axiom g1414 (x : Prop) : Prop axiom g1415 (x : Prop) : Prop axiom g1416 (x : Prop) : Prop axiom g1417 (x : Prop) : Prop axiom g1418 (x : Prop) : Prop axiom g1419 (x : Prop) : Prop axiom g1420 (x : Prop) : Prop axiom g1421 (x : Prop) : Prop axiom g1422 (x : Prop) : Prop axiom g1423 (x : Prop) : Prop axiom g1424 (x : Prop) : Prop axiom g1425 (x : Prop) : Prop axiom g1426 (x : Prop) : Prop axiom g1427 (x : Prop) : Prop axiom g1428 (x : Prop) : Prop axiom g1429 (x : Prop) : Prop axiom g1430 (x : Prop) : Prop axiom g1431 (x : Prop) : Prop axiom g1432 (x : Prop) : Prop axiom g1433 (x : Prop) : Prop axiom g1434 (x : Prop) : Prop axiom g1435 (x : Prop) : Prop axiom g1436 (x : Prop) : Prop axiom g1437 (x : Prop) : Prop axiom g1438 (x : Prop) : Prop axiom g1439 (x : Prop) : Prop axiom g1440 (x : Prop) : Prop axiom g1441 (x : Prop) : Prop axiom g1442 (x : Prop) : Prop axiom g1443 (x : Prop) : Prop axiom g1444 (x : Prop) : Prop axiom g1445 (x : Prop) : Prop axiom g1446 (x : Prop) : Prop axiom g1447 (x : Prop) : Prop axiom g1448 (x : Prop) : Prop axiom g1449 (x : Prop) : Prop axiom g1450 (x : Prop) : Prop axiom g1451 (x : Prop) : Prop axiom g1452 (x : Prop) : Prop axiom g1453 (x : Prop) : Prop axiom g1454 (x : Prop) : Prop axiom g1455 (x : Prop) : Prop axiom g1456 (x : Prop) : Prop axiom g1457 (x : Prop) : Prop axiom g1458 (x : Prop) : Prop axiom g1459 (x : Prop) : Prop axiom g1460 (x : Prop) : Prop axiom g1461 (x : Prop) : Prop axiom g1462 (x : Prop) : Prop axiom g1463 (x : Prop) : Prop axiom g1464 (x : Prop) : Prop axiom g1465 (x : Prop) : Prop axiom g1466 (x : Prop) : Prop axiom g1467 (x : Prop) : Prop axiom g1468 (x : Prop) : Prop axiom g1469 (x : Prop) : Prop axiom g1470 (x : Prop) : Prop axiom g1471 (x : Prop) : Prop axiom g1472 (x : Prop) : Prop axiom g1473 (x : Prop) : Prop axiom g1474 (x : Prop) : Prop axiom g1475 (x : Prop) : Prop axiom g1476 (x : Prop) : Prop axiom g1477 (x : Prop) : Prop axiom g1478 (x : Prop) : Prop axiom g1479 (x : Prop) : Prop axiom g1480 (x : Prop) : Prop axiom g1481 (x : Prop) : Prop axiom g1482 (x : Prop) : Prop axiom g1483 (x : Prop) : Prop axiom g1484 (x : Prop) : Prop axiom g1485 (x : Prop) : Prop axiom g1486 (x : Prop) : Prop axiom g1487 (x : Prop) : Prop axiom g1488 (x : Prop) : Prop axiom g1489 (x : Prop) : Prop axiom g1490 (x : Prop) : Prop axiom g1491 (x : Prop) : Prop axiom g1492 (x : Prop) : Prop axiom g1493 (x : Prop) : Prop axiom g1494 (x : Prop) : Prop axiom g1495 (x : Prop) : Prop axiom g1496 (x : Prop) : Prop axiom g1497 (x : Prop) : Prop axiom g1498 (x : Prop) : Prop axiom g1499 (x : Prop) : Prop axiom g1500 (x : Prop) : Prop axiom g1501 (x : Prop) : Prop axiom g1502 (x : Prop) : Prop axiom g1503 (x : Prop) : Prop axiom g1504 (x : Prop) : Prop axiom g1505 (x : Prop) : Prop axiom g1506 (x : Prop) : Prop axiom g1507 (x : Prop) : Prop axiom g1508 (x : Prop) : Prop axiom g1509 (x : Prop) : Prop axiom g1510 (x : Prop) : Prop axiom g1511 (x : Prop) : Prop axiom g1512 (x : Prop) : Prop axiom g1513 (x : Prop) : Prop axiom g1514 (x : Prop) : Prop axiom g1515 (x : Prop) : Prop axiom g1516 (x : Prop) : Prop axiom g1517 (x : Prop) : Prop axiom g1518 (x : Prop) : Prop axiom g1519 (x : Prop) : Prop axiom g1520 (x : Prop) : Prop axiom g1521 (x : Prop) : Prop axiom g1522 (x : Prop) : Prop axiom g1523 (x : Prop) : Prop axiom g1524 (x : Prop) : Prop axiom g1525 (x : Prop) : Prop axiom g1526 (x : Prop) : Prop axiom g1527 (x : Prop) : Prop axiom g1528 (x : Prop) : Prop axiom g1529 (x : Prop) : Prop axiom g1530 (x : Prop) : Prop axiom g1531 (x : Prop) : Prop axiom g1532 (x : Prop) : Prop axiom g1533 (x : Prop) : Prop axiom g1534 (x : Prop) : Prop axiom g1535 (x : Prop) : Prop axiom g1536 (x : Prop) : Prop axiom g1537 (x : Prop) : Prop axiom g1538 (x : Prop) : Prop axiom g1539 (x : Prop) : Prop axiom g1540 (x : Prop) : Prop axiom g1541 (x : Prop) : Prop axiom g1542 (x : Prop) : Prop axiom g1543 (x : Prop) : Prop axiom g1544 (x : Prop) : Prop axiom g1545 (x : Prop) : Prop axiom g1546 (x : Prop) : Prop axiom g1547 (x : Prop) : Prop axiom g1548 (x : Prop) : Prop axiom g1549 (x : Prop) : Prop axiom g1550 (x : Prop) : Prop axiom g1551 (x : Prop) : Prop axiom g1552 (x : Prop) : Prop axiom g1553 (x : Prop) : Prop axiom g1554 (x : Prop) : Prop axiom g1555 (x : Prop) : Prop axiom g1556 (x : Prop) : Prop axiom g1557 (x : Prop) : Prop axiom g1558 (x : Prop) : Prop axiom g1559 (x : Prop) : Prop axiom g1560 (x : Prop) : Prop axiom g1561 (x : Prop) : Prop axiom g1562 (x : Prop) : Prop axiom g1563 (x : Prop) : Prop axiom g1564 (x : Prop) : Prop axiom g1565 (x : Prop) : Prop axiom g1566 (x : Prop) : Prop axiom g1567 (x : Prop) : Prop axiom g1568 (x : Prop) : Prop axiom g1569 (x : Prop) : Prop axiom g1570 (x : Prop) : Prop axiom g1571 (x : Prop) : Prop axiom g1572 (x : Prop) : Prop axiom g1573 (x : Prop) : Prop axiom g1574 (x : Prop) : Prop axiom g1575 (x : Prop) : Prop axiom g1576 (x : Prop) : Prop axiom g1577 (x : Prop) : Prop axiom g1578 (x : Prop) : Prop axiom g1579 (x : Prop) : Prop axiom g1580 (x : Prop) : Prop axiom g1581 (x : Prop) : Prop axiom g1582 (x : Prop) : Prop axiom g1583 (x : Prop) : Prop axiom g1584 (x : Prop) : Prop axiom g1585 (x : Prop) : Prop axiom g1586 (x : Prop) : Prop axiom g1587 (x : Prop) : Prop axiom g1588 (x : Prop) : Prop axiom g1589 (x : Prop) : Prop axiom g1590 (x : Prop) : Prop axiom g1591 (x : Prop) : Prop axiom g1592 (x : Prop) : Prop axiom g1593 (x : Prop) : Prop axiom g1594 (x : Prop) : Prop axiom g1595 (x : Prop) : Prop axiom g1596 (x : Prop) : Prop axiom g1597 (x : Prop) : Prop axiom g1598 (x : Prop) : Prop axiom g1599 (x : Prop) : Prop axiom g1600 (x : Prop) : Prop axiom g1601 (x : Prop) : Prop axiom g1602 (x : Prop) : Prop axiom g1603 (x : Prop) : Prop axiom g1604 (x : Prop) : Prop axiom g1605 (x : Prop) : Prop axiom g1606 (x : Prop) : Prop axiom g1607 (x : Prop) : Prop axiom g1608 (x : Prop) : Prop axiom g1609 (x : Prop) : Prop axiom g1610 (x : Prop) : Prop axiom g1611 (x : Prop) : Prop axiom g1612 (x : Prop) : Prop axiom g1613 (x : Prop) : Prop axiom g1614 (x : Prop) : Prop axiom g1615 (x : Prop) : Prop axiom g1616 (x : Prop) : Prop axiom g1617 (x : Prop) : Prop axiom g1618 (x : Prop) : Prop axiom g1619 (x : Prop) : Prop axiom g1620 (x : Prop) : Prop axiom g1621 (x : Prop) : Prop axiom g1622 (x : Prop) : Prop axiom g1623 (x : Prop) : Prop axiom g1624 (x : Prop) : Prop axiom g1625 (x : Prop) : Prop axiom g1626 (x : Prop) : Prop axiom g1627 (x : Prop) : Prop axiom g1628 (x : Prop) : Prop axiom g1629 (x : Prop) : Prop axiom g1630 (x : Prop) : Prop axiom g1631 (x : Prop) : Prop axiom g1632 (x : Prop) : Prop axiom g1633 (x : Prop) : Prop axiom g1634 (x : Prop) : Prop axiom g1635 (x : Prop) : Prop axiom g1636 (x : Prop) : Prop axiom g1637 (x : Prop) : Prop axiom g1638 (x : Prop) : Prop axiom g1639 (x : Prop) : Prop axiom g1640 (x : Prop) : Prop axiom g1641 (x : Prop) : Prop axiom g1642 (x : Prop) : Prop axiom g1643 (x : Prop) : Prop axiom g1644 (x : Prop) : Prop axiom g1645 (x : Prop) : Prop axiom g1646 (x : Prop) : Prop axiom g1647 (x : Prop) : Prop axiom g1648 (x : Prop) : Prop axiom g1649 (x : Prop) : Prop axiom g1650 (x : Prop) : Prop axiom g1651 (x : Prop) : Prop axiom g1652 (x : Prop) : Prop axiom g1653 (x : Prop) : Prop axiom g1654 (x : Prop) : Prop axiom g1655 (x : Prop) : Prop axiom g1656 (x : Prop) : Prop axiom g1657 (x : Prop) : Prop axiom g1658 (x : Prop) : Prop axiom g1659 (x : Prop) : Prop axiom g1660 (x : Prop) : Prop axiom g1661 (x : Prop) : Prop axiom g1662 (x : Prop) : Prop axiom g1663 (x : Prop) : Prop axiom g1664 (x : Prop) : Prop axiom g1665 (x : Prop) : Prop axiom g1666 (x : Prop) : Prop axiom g1667 (x : Prop) : Prop axiom g1668 (x : Prop) : Prop axiom g1669 (x : Prop) : Prop axiom g1670 (x : Prop) : Prop axiom g1671 (x : Prop) : Prop axiom g1672 (x : Prop) : Prop axiom g1673 (x : Prop) : Prop axiom g1674 (x : Prop) : Prop axiom g1675 (x : Prop) : Prop axiom g1676 (x : Prop) : Prop axiom g1677 (x : Prop) : Prop axiom g1678 (x : Prop) : Prop axiom g1679 (x : Prop) : Prop axiom g1680 (x : Prop) : Prop axiom g1681 (x : Prop) : Prop axiom g1682 (x : Prop) : Prop axiom g1683 (x : Prop) : Prop axiom g1684 (x : Prop) : Prop axiom g1685 (x : Prop) : Prop axiom g1686 (x : Prop) : Prop axiom g1687 (x : Prop) : Prop axiom g1688 (x : Prop) : Prop axiom g1689 (x : Prop) : Prop axiom g1690 (x : Prop) : Prop axiom g1691 (x : Prop) : Prop axiom g1692 (x : Prop) : Prop axiom g1693 (x : Prop) : Prop axiom g1694 (x : Prop) : Prop axiom g1695 (x : Prop) : Prop axiom g1696 (x : Prop) : Prop axiom g1697 (x : Prop) : Prop axiom g1698 (x : Prop) : Prop axiom g1699 (x : Prop) : Prop axiom g1700 (x : Prop) : Prop axiom g1701 (x : Prop) : Prop axiom g1702 (x : Prop) : Prop axiom g1703 (x : Prop) : Prop axiom g1704 (x : Prop) : Prop axiom g1705 (x : Prop) : Prop axiom g1706 (x : Prop) : Prop axiom g1707 (x : Prop) : Prop axiom g1708 (x : Prop) : Prop axiom g1709 (x : Prop) : Prop axiom g1710 (x : Prop) : Prop axiom g1711 (x : Prop) : Prop axiom g1712 (x : Prop) : Prop axiom g1713 (x : Prop) : Prop axiom g1714 (x : Prop) : Prop axiom g1715 (x : Prop) : Prop axiom g1716 (x : Prop) : Prop axiom g1717 (x : Prop) : Prop axiom g1718 (x : Prop) : Prop axiom g1719 (x : Prop) : Prop axiom g1720 (x : Prop) : Prop axiom g1721 (x : Prop) : Prop axiom g1722 (x : Prop) : Prop axiom g1723 (x : Prop) : Prop axiom g1724 (x : Prop) : Prop axiom g1725 (x : Prop) : Prop axiom g1726 (x : Prop) : Prop axiom g1727 (x : Prop) : Prop axiom g1728 (x : Prop) : Prop axiom g1729 (x : Prop) : Prop axiom g1730 (x : Prop) : Prop axiom g1731 (x : Prop) : Prop axiom g1732 (x : Prop) : Prop axiom g1733 (x : Prop) : Prop axiom g1734 (x : Prop) : Prop axiom g1735 (x : Prop) : Prop axiom g1736 (x : Prop) : Prop axiom g1737 (x : Prop) : Prop axiom g1738 (x : Prop) : Prop axiom g1739 (x : Prop) : Prop axiom g1740 (x : Prop) : Prop axiom g1741 (x : Prop) : Prop axiom g1742 (x : Prop) : Prop axiom g1743 (x : Prop) : Prop axiom g1744 (x : Prop) : Prop axiom g1745 (x : Prop) : Prop axiom g1746 (x : Prop) : Prop axiom g1747 (x : Prop) : Prop axiom g1748 (x : Prop) : Prop axiom g1749 (x : Prop) : Prop axiom g1750 (x : Prop) : Prop axiom g1751 (x : Prop) : Prop axiom g1752 (x : Prop) : Prop axiom g1753 (x : Prop) : Prop axiom g1754 (x : Prop) : Prop axiom g1755 (x : Prop) : Prop axiom g1756 (x : Prop) : Prop axiom g1757 (x : Prop) : Prop axiom g1758 (x : Prop) : Prop axiom g1759 (x : Prop) : Prop axiom g1760 (x : Prop) : Prop axiom g1761 (x : Prop) : Prop axiom g1762 (x : Prop) : Prop axiom g1763 (x : Prop) : Prop axiom g1764 (x : Prop) : Prop axiom g1765 (x : Prop) : Prop axiom g1766 (x : Prop) : Prop axiom g1767 (x : Prop) : Prop axiom g1768 (x : Prop) : Prop axiom g1769 (x : Prop) : Prop axiom g1770 (x : Prop) : Prop axiom g1771 (x : Prop) : Prop axiom g1772 (x : Prop) : Prop axiom g1773 (x : Prop) : Prop axiom g1774 (x : Prop) : Prop axiom g1775 (x : Prop) : Prop axiom g1776 (x : Prop) : Prop axiom g1777 (x : Prop) : Prop axiom g1778 (x : Prop) : Prop axiom g1779 (x : Prop) : Prop axiom g1780 (x : Prop) : Prop axiom g1781 (x : Prop) : Prop axiom g1782 (x : Prop) : Prop axiom g1783 (x : Prop) : Prop axiom g1784 (x : Prop) : Prop axiom g1785 (x : Prop) : Prop axiom g1786 (x : Prop) : Prop axiom g1787 (x : Prop) : Prop axiom g1788 (x : Prop) : Prop axiom g1789 (x : Prop) : Prop axiom g1790 (x : Prop) : Prop axiom g1791 (x : Prop) : Prop axiom g1792 (x : Prop) : Prop axiom g1793 (x : Prop) : Prop axiom g1794 (x : Prop) : Prop axiom g1795 (x : Prop) : Prop axiom g1796 (x : Prop) : Prop axiom g1797 (x : Prop) : Prop axiom g1798 (x : Prop) : Prop axiom g1799 (x : Prop) : Prop axiom g1800 (x : Prop) : Prop axiom g1801 (x : Prop) : Prop axiom g1802 (x : Prop) : Prop axiom g1803 (x : Prop) : Prop axiom g1804 (x : Prop) : Prop axiom g1805 (x : Prop) : Prop axiom g1806 (x : Prop) : Prop axiom g1807 (x : Prop) : Prop axiom g1808 (x : Prop) : Prop axiom g1809 (x : Prop) : Prop axiom g1810 (x : Prop) : Prop axiom g1811 (x : Prop) : Prop axiom g1812 (x : Prop) : Prop axiom g1813 (x : Prop) : Prop axiom g1814 (x : Prop) : Prop axiom g1815 (x : Prop) : Prop axiom g1816 (x : Prop) : Prop axiom g1817 (x : Prop) : Prop axiom g1818 (x : Prop) : Prop axiom g1819 (x : Prop) : Prop axiom g1820 (x : Prop) : Prop axiom g1821 (x : Prop) : Prop axiom g1822 (x : Prop) : Prop axiom g1823 (x : Prop) : Prop axiom g1824 (x : Prop) : Prop axiom g1825 (x : Prop) : Prop axiom g1826 (x : Prop) : Prop axiom g1827 (x : Prop) : Prop axiom g1828 (x : Prop) : Prop axiom g1829 (x : Prop) : Prop axiom g1830 (x : Prop) : Prop axiom g1831 (x : Prop) : Prop axiom g1832 (x : Prop) : Prop axiom g1833 (x : Prop) : Prop axiom g1834 (x : Prop) : Prop axiom g1835 (x : Prop) : Prop axiom g1836 (x : Prop) : Prop axiom g1837 (x : Prop) : Prop axiom g1838 (x : Prop) : Prop axiom g1839 (x : Prop) : Prop axiom g1840 (x : Prop) : Prop axiom g1841 (x : Prop) : Prop axiom g1842 (x : Prop) : Prop axiom g1843 (x : Prop) : Prop axiom g1844 (x : Prop) : Prop axiom g1845 (x : Prop) : Prop axiom g1846 (x : Prop) : Prop axiom g1847 (x : Prop) : Prop axiom g1848 (x : Prop) : Prop axiom g1849 (x : Prop) : Prop axiom g1850 (x : Prop) : Prop axiom g1851 (x : Prop) : Prop axiom g1852 (x : Prop) : Prop axiom g1853 (x : Prop) : Prop axiom g1854 (x : Prop) : Prop axiom g1855 (x : Prop) : Prop axiom g1856 (x : Prop) : Prop axiom g1857 (x : Prop) : Prop axiom g1858 (x : Prop) : Prop axiom g1859 (x : Prop) : Prop axiom g1860 (x : Prop) : Prop axiom g1861 (x : Prop) : Prop axiom g1862 (x : Prop) : Prop axiom g1863 (x : Prop) : Prop axiom g1864 (x : Prop) : Prop axiom g1865 (x : Prop) : Prop axiom g1866 (x : Prop) : Prop axiom g1867 (x : Prop) : Prop axiom g1868 (x : Prop) : Prop axiom g1869 (x : Prop) : Prop axiom g1870 (x : Prop) : Prop axiom g1871 (x : Prop) : Prop axiom g1872 (x : Prop) : Prop axiom g1873 (x : Prop) : Prop axiom g1874 (x : Prop) : Prop axiom g1875 (x : Prop) : Prop axiom g1876 (x : Prop) : Prop axiom g1877 (x : Prop) : Prop axiom g1878 (x : Prop) : Prop axiom g1879 (x : Prop) : Prop axiom g1880 (x : Prop) : Prop axiom g1881 (x : Prop) : Prop axiom g1882 (x : Prop) : Prop axiom g1883 (x : Prop) : Prop axiom g1884 (x : Prop) : Prop axiom g1885 (x : Prop) : Prop axiom g1886 (x : Prop) : Prop axiom g1887 (x : Prop) : Prop axiom g1888 (x : Prop) : Prop axiom g1889 (x : Prop) : Prop axiom g1890 (x : Prop) : Prop axiom g1891 (x : Prop) : Prop axiom g1892 (x : Prop) : Prop axiom g1893 (x : Prop) : Prop axiom g1894 (x : Prop) : Prop axiom g1895 (x : Prop) : Prop axiom g1896 (x : Prop) : Prop axiom g1897 (x : Prop) : Prop axiom g1898 (x : Prop) : Prop axiom g1899 (x : Prop) : Prop axiom g1900 (x : Prop) : Prop axiom g1901 (x : Prop) : Prop axiom g1902 (x : Prop) : Prop axiom g1903 (x : Prop) : Prop axiom g1904 (x : Prop) : Prop axiom g1905 (x : Prop) : Prop axiom g1906 (x : Prop) : Prop axiom g1907 (x : Prop) : Prop axiom g1908 (x : Prop) : Prop axiom g1909 (x : Prop) : Prop axiom g1910 (x : Prop) : Prop axiom g1911 (x : Prop) : Prop axiom g1912 (x : Prop) : Prop axiom g1913 (x : Prop) : Prop axiom g1914 (x : Prop) : Prop axiom g1915 (x : Prop) : Prop axiom g1916 (x : Prop) : Prop axiom g1917 (x : Prop) : Prop axiom g1918 (x : Prop) : Prop axiom g1919 (x : Prop) : Prop axiom g1920 (x : Prop) : Prop axiom g1921 (x : Prop) : Prop axiom g1922 (x : Prop) : Prop axiom g1923 (x : Prop) : Prop axiom g1924 (x : Prop) : Prop axiom g1925 (x : Prop) : Prop axiom g1926 (x : Prop) : Prop axiom g1927 (x : Prop) : Prop axiom g1928 (x : Prop) : Prop axiom g1929 (x : Prop) : Prop axiom g1930 (x : Prop) : Prop axiom g1931 (x : Prop) : Prop axiom g1932 (x : Prop) : Prop axiom g1933 (x : Prop) : Prop axiom g1934 (x : Prop) : Prop axiom g1935 (x : Prop) : Prop axiom g1936 (x : Prop) : Prop axiom g1937 (x : Prop) : Prop axiom g1938 (x : Prop) : Prop axiom g1939 (x : Prop) : Prop axiom g1940 (x : Prop) : Prop axiom g1941 (x : Prop) : Prop axiom g1942 (x : Prop) : Prop axiom g1943 (x : Prop) : Prop axiom g1944 (x : Prop) : Prop axiom g1945 (x : Prop) : Prop axiom g1946 (x : Prop) : Prop axiom g1947 (x : Prop) : Prop axiom g1948 (x : Prop) : Prop axiom g1949 (x : Prop) : Prop axiom g1950 (x : Prop) : Prop axiom g1951 (x : Prop) : Prop axiom g1952 (x : Prop) : Prop axiom g1953 (x : Prop) : Prop axiom g1954 (x : Prop) : Prop axiom g1955 (x : Prop) : Prop axiom g1956 (x : Prop) : Prop axiom g1957 (x : Prop) : Prop axiom g1958 (x : Prop) : Prop axiom g1959 (x : Prop) : Prop axiom g1960 (x : Prop) : Prop axiom g1961 (x : Prop) : Prop axiom g1962 (x : Prop) : Prop axiom g1963 (x : Prop) : Prop axiom g1964 (x : Prop) : Prop axiom g1965 (x : Prop) : Prop axiom g1966 (x : Prop) : Prop axiom g1967 (x : Prop) : Prop axiom g1968 (x : Prop) : Prop axiom g1969 (x : Prop) : Prop axiom g1970 (x : Prop) : Prop axiom g1971 (x : Prop) : Prop axiom g1972 (x : Prop) : Prop axiom g1973 (x : Prop) : Prop axiom g1974 (x : Prop) : Prop axiom g1975 (x : Prop) : Prop axiom g1976 (x : Prop) : Prop axiom g1977 (x : Prop) : Prop axiom g1978 (x : Prop) : Prop axiom g1979 (x : Prop) : Prop axiom g1980 (x : Prop) : Prop axiom g1981 (x : Prop) : Prop axiom g1982 (x : Prop) : Prop axiom g1983 (x : Prop) : Prop axiom g1984 (x : Prop) : Prop axiom g1985 (x : Prop) : Prop axiom g1986 (x : Prop) : Prop axiom g1987 (x : Prop) : Prop axiom g1988 (x : Prop) : Prop axiom g1989 (x : Prop) : Prop axiom g1990 (x : Prop) : Prop axiom g1991 (x : Prop) : Prop axiom g1992 (x : Prop) : Prop axiom g1993 (x : Prop) : Prop axiom g1994 (x : Prop) : Prop axiom g1995 (x : Prop) : Prop axiom g1996 (x : Prop) : Prop axiom g1997 (x : Prop) : Prop axiom g1998 (x : Prop) : Prop axiom g1999 (x : Prop) : Prop axiom g2000 (x : Prop) : Prop axiom g2001 (x : Prop) : Prop axiom g2002 (x : Prop) : Prop axiom g2003 (x : Prop) : Prop axiom g2004 (x : Prop) : Prop axiom g2005 (x : Prop) : Prop axiom g2006 (x : Prop) : Prop axiom g2007 (x : Prop) : Prop axiom g2008 (x : Prop) : Prop axiom g2009 (x : Prop) : Prop axiom g2010 (x : Prop) : Prop axiom g2011 (x : Prop) : Prop axiom g2012 (x : Prop) : Prop axiom g2013 (x : Prop) : Prop axiom g2014 (x : Prop) : Prop axiom g2015 (x : Prop) : Prop axiom g2016 (x : Prop) : Prop axiom g2017 (x : Prop) : Prop axiom g2018 (x : Prop) : Prop axiom g2019 (x : Prop) : Prop axiom g2020 (x : Prop) : Prop axiom g2021 (x : Prop) : Prop axiom g2022 (x : Prop) : Prop axiom g2023 (x : Prop) : Prop axiom g2024 (x : Prop) : Prop axiom g2025 (x : Prop) : Prop axiom g2026 (x : Prop) : Prop axiom g2027 (x : Prop) : Prop axiom g2028 (x : Prop) : Prop axiom g2029 (x : Prop) : Prop axiom g2030 (x : Prop) : Prop axiom g2031 (x : Prop) : Prop axiom g2032 (x : Prop) : Prop axiom g2033 (x : Prop) : Prop axiom g2034 (x : Prop) : Prop axiom g2035 (x : Prop) : Prop axiom g2036 (x : Prop) : Prop axiom g2037 (x : Prop) : Prop axiom g2038 (x : Prop) : Prop axiom g2039 (x : Prop) : Prop axiom g2040 (x : Prop) : Prop axiom g2041 (x : Prop) : Prop axiom g2042 (x : Prop) : Prop axiom g2043 (x : Prop) : Prop axiom g2044 (x : Prop) : Prop axiom g2045 (x : Prop) : Prop axiom g2046 (x : Prop) : Prop axiom g2047 (x : Prop) : Prop axiom g2048 (x : Prop) : Prop axiom g2049 (x : Prop) : Prop axiom g2050 (x : Prop) : Prop axiom g2051 (x : Prop) : Prop axiom g2052 (x : Prop) : Prop axiom g2053 (x : Prop) : Prop axiom g2054 (x : Prop) : Prop axiom g2055 (x : Prop) : Prop axiom g2056 (x : Prop) : Prop axiom g2057 (x : Prop) : Prop axiom g2058 (x : Prop) : Prop axiom g2059 (x : Prop) : Prop axiom g2060 (x : Prop) : Prop axiom g2061 (x : Prop) : Prop axiom g2062 (x : Prop) : Prop axiom g2063 (x : Prop) : Prop axiom g2064 (x : Prop) : Prop axiom g2065 (x : Prop) : Prop axiom g2066 (x : Prop) : Prop axiom g2067 (x : Prop) : Prop axiom g2068 (x : Prop) : Prop axiom g2069 (x : Prop) : Prop axiom g2070 (x : Prop) : Prop axiom g2071 (x : Prop) : Prop axiom g2072 (x : Prop) : Prop axiom g2073 (x : Prop) : Prop axiom g2074 (x : Prop) : Prop axiom g2075 (x : Prop) : Prop axiom g2076 (x : Prop) : Prop axiom g2077 (x : Prop) : Prop axiom g2078 (x : Prop) : Prop axiom g2079 (x : Prop) : Prop axiom g2080 (x : Prop) : Prop axiom g2081 (x : Prop) : Prop axiom g2082 (x : Prop) : Prop axiom g2083 (x : Prop) : Prop axiom g2084 (x : Prop) : Prop axiom g2085 (x : Prop) : Prop axiom g2086 (x : Prop) : Prop axiom g2087 (x : Prop) : Prop axiom g2088 (x : Prop) : Prop axiom g2089 (x : Prop) : Prop axiom g2090 (x : Prop) : Prop axiom g2091 (x : Prop) : Prop axiom g2092 (x : Prop) : Prop axiom g2093 (x : Prop) : Prop axiom g2094 (x : Prop) : Prop axiom g2095 (x : Prop) : Prop axiom g2096 (x : Prop) : Prop axiom g2097 (x : Prop) : Prop axiom g2098 (x : Prop) : Prop axiom g2099 (x : Prop) : Prop axiom g2100 (x : Prop) : Prop axiom g2101 (x : Prop) : Prop axiom g2102 (x : Prop) : Prop axiom g2103 (x : Prop) : Prop axiom g2104 (x : Prop) : Prop axiom g2105 (x : Prop) : Prop axiom g2106 (x : Prop) : Prop axiom g2107 (x : Prop) : Prop axiom g2108 (x : Prop) : Prop axiom g2109 (x : Prop) : Prop axiom g2110 (x : Prop) : Prop axiom g2111 (x : Prop) : Prop axiom g2112 (x : Prop) : Prop axiom g2113 (x : Prop) : Prop axiom g2114 (x : Prop) : Prop axiom g2115 (x : Prop) : Prop axiom g2116 (x : Prop) : Prop axiom g2117 (x : Prop) : Prop axiom g2118 (x : Prop) : Prop axiom g2119 (x : Prop) : Prop axiom g2120 (x : Prop) : Prop axiom g2121 (x : Prop) : Prop axiom g2122 (x : Prop) : Prop axiom g2123 (x : Prop) : Prop axiom g2124 (x : Prop) : Prop axiom g2125 (x : Prop) : Prop axiom g2126 (x : Prop) : Prop axiom g2127 (x : Prop) : Prop axiom g2128 (x : Prop) : Prop axiom g2129 (x : Prop) : Prop axiom g2130 (x : Prop) : Prop axiom g2131 (x : Prop) : Prop axiom g2132 (x : Prop) : Prop axiom g2133 (x : Prop) : Prop axiom g2134 (x : Prop) : Prop axiom g2135 (x : Prop) : Prop axiom g2136 (x : Prop) : Prop axiom g2137 (x : Prop) : Prop axiom g2138 (x : Prop) : Prop axiom g2139 (x : Prop) : Prop axiom g2140 (x : Prop) : Prop axiom g2141 (x : Prop) : Prop axiom g2142 (x : Prop) : Prop axiom g2143 (x : Prop) : Prop axiom g2144 (x : Prop) : Prop axiom g2145 (x : Prop) : Prop axiom g2146 (x : Prop) : Prop axiom g2147 (x : Prop) : Prop axiom g2148 (x : Prop) : Prop axiom g2149 (x : Prop) : Prop axiom g2150 (x : Prop) : Prop axiom g2151 (x : Prop) : Prop axiom g2152 (x : Prop) : Prop axiom g2153 (x : Prop) : Prop axiom g2154 (x : Prop) : Prop axiom g2155 (x : Prop) : Prop axiom g2156 (x : Prop) : Prop axiom g2157 (x : Prop) : Prop axiom g2158 (x : Prop) : Prop axiom g2159 (x : Prop) : Prop axiom g2160 (x : Prop) : Prop axiom g2161 (x : Prop) : Prop axiom g2162 (x : Prop) : Prop axiom g2163 (x : Prop) : Prop axiom g2164 (x : Prop) : Prop axiom g2165 (x : Prop) : Prop axiom g2166 (x : Prop) : Prop axiom g2167 (x : Prop) : Prop axiom g2168 (x : Prop) : Prop axiom g2169 (x : Prop) : Prop axiom g2170 (x : Prop) : Prop axiom g2171 (x : Prop) : Prop axiom g2172 (x : Prop) : Prop axiom g2173 (x : Prop) : Prop axiom g2174 (x : Prop) : Prop axiom g2175 (x : Prop) : Prop axiom g2176 (x : Prop) : Prop axiom g2177 (x : Prop) : Prop axiom g2178 (x : Prop) : Prop axiom g2179 (x : Prop) : Prop axiom g2180 (x : Prop) : Prop axiom g2181 (x : Prop) : Prop axiom g2182 (x : Prop) : Prop axiom g2183 (x : Prop) : Prop axiom g2184 (x : Prop) : Prop axiom g2185 (x : Prop) : Prop axiom g2186 (x : Prop) : Prop axiom g2187 (x : Prop) : Prop axiom g2188 (x : Prop) : Prop axiom g2189 (x : Prop) : Prop axiom g2190 (x : Prop) : Prop axiom g2191 (x : Prop) : Prop axiom g2192 (x : Prop) : Prop axiom g2193 (x : Prop) : Prop axiom g2194 (x : Prop) : Prop axiom g2195 (x : Prop) : Prop axiom g2196 (x : Prop) : Prop axiom g2197 (x : Prop) : Prop axiom g2198 (x : Prop) : Prop axiom g2199 (x : Prop) : Prop axiom g2200 (x : Prop) : Prop axiom g2201 (x : Prop) : Prop axiom g2202 (x : Prop) : Prop axiom g2203 (x : Prop) : Prop axiom g2204 (x : Prop) : Prop axiom g2205 (x : Prop) : Prop axiom g2206 (x : Prop) : Prop axiom g2207 (x : Prop) : Prop axiom g2208 (x : Prop) : Prop axiom g2209 (x : Prop) : Prop axiom g2210 (x : Prop) : Prop axiom g2211 (x : Prop) : Prop axiom g2212 (x : Prop) : Prop axiom g2213 (x : Prop) : Prop axiom g2214 (x : Prop) : Prop axiom g2215 (x : Prop) : Prop axiom g2216 (x : Prop) : Prop axiom g2217 (x : Prop) : Prop axiom g2218 (x : Prop) : Prop axiom g2219 (x : Prop) : Prop axiom g2220 (x : Prop) : Prop axiom g2221 (x : Prop) : Prop axiom g2222 (x : Prop) : Prop axiom g2223 (x : Prop) : Prop axiom g2224 (x : Prop) : Prop axiom g2225 (x : Prop) : Prop axiom g2226 (x : Prop) : Prop axiom g2227 (x : Prop) : Prop axiom g2228 (x : Prop) : Prop axiom g2229 (x : Prop) : Prop axiom g2230 (x : Prop) : Prop axiom g2231 (x : Prop) : Prop axiom g2232 (x : Prop) : Prop axiom g2233 (x : Prop) : Prop axiom g2234 (x : Prop) : Prop axiom g2235 (x : Prop) : Prop axiom g2236 (x : Prop) : Prop axiom g2237 (x : Prop) : Prop axiom g2238 (x : Prop) : Prop axiom g2239 (x : Prop) : Prop axiom g2240 (x : Prop) : Prop axiom g2241 (x : Prop) : Prop axiom g2242 (x : Prop) : Prop axiom g2243 (x : Prop) : Prop axiom g2244 (x : Prop) : Prop axiom g2245 (x : Prop) : Prop axiom g2246 (x : Prop) : Prop axiom g2247 (x : Prop) : Prop axiom g2248 (x : Prop) : Prop axiom g2249 (x : Prop) : Prop axiom g2250 (x : Prop) : Prop axiom g2251 (x : Prop) : Prop axiom g2252 (x : Prop) : Prop axiom g2253 (x : Prop) : Prop axiom g2254 (x : Prop) : Prop axiom g2255 (x : Prop) : Prop axiom g2256 (x : Prop) : Prop axiom g2257 (x : Prop) : Prop axiom g2258 (x : Prop) : Prop axiom g2259 (x : Prop) : Prop axiom g2260 (x : Prop) : Prop axiom g2261 (x : Prop) : Prop axiom g2262 (x : Prop) : Prop axiom g2263 (x : Prop) : Prop axiom g2264 (x : Prop) : Prop axiom g2265 (x : Prop) : Prop axiom g2266 (x : Prop) : Prop axiom g2267 (x : Prop) : Prop axiom g2268 (x : Prop) : Prop axiom g2269 (x : Prop) : Prop axiom g2270 (x : Prop) : Prop axiom g2271 (x : Prop) : Prop axiom g2272 (x : Prop) : Prop axiom g2273 (x : Prop) : Prop axiom g2274 (x : Prop) : Prop axiom g2275 (x : Prop) : Prop axiom g2276 (x : Prop) : Prop axiom g2277 (x : Prop) : Prop axiom g2278 (x : Prop) : Prop axiom g2279 (x : Prop) : Prop axiom g2280 (x : Prop) : Prop axiom g2281 (x : Prop) : Prop axiom g2282 (x : Prop) : Prop axiom g2283 (x : Prop) : Prop axiom g2284 (x : Prop) : Prop axiom g2285 (x : Prop) : Prop axiom g2286 (x : Prop) : Prop axiom g2287 (x : Prop) : Prop axiom g2288 (x : Prop) : Prop axiom g2289 (x : Prop) : Prop axiom g2290 (x : Prop) : Prop axiom g2291 (x : Prop) : Prop axiom g2292 (x : Prop) : Prop axiom g2293 (x : Prop) : Prop axiom g2294 (x : Prop) : Prop axiom g2295 (x : Prop) : Prop axiom g2296 (x : Prop) : Prop axiom g2297 (x : Prop) : Prop axiom g2298 (x : Prop) : Prop axiom g2299 (x : Prop) : Prop axiom g2300 (x : Prop) : Prop axiom g2301 (x : Prop) : Prop axiom g2302 (x : Prop) : Prop axiom g2303 (x : Prop) : Prop axiom g2304 (x : Prop) : Prop axiom g2305 (x : Prop) : Prop axiom g2306 (x : Prop) : Prop axiom g2307 (x : Prop) : Prop axiom g2308 (x : Prop) : Prop axiom g2309 (x : Prop) : Prop axiom g2310 (x : Prop) : Prop axiom g2311 (x : Prop) : Prop axiom g2312 (x : Prop) : Prop axiom g2313 (x : Prop) : Prop axiom g2314 (x : Prop) : Prop axiom g2315 (x : Prop) : Prop axiom g2316 (x : Prop) : Prop axiom g2317 (x : Prop) : Prop axiom g2318 (x : Prop) : Prop axiom g2319 (x : Prop) : Prop axiom g2320 (x : Prop) : Prop axiom g2321 (x : Prop) : Prop axiom g2322 (x : Prop) : Prop axiom g2323 (x : Prop) : Prop axiom g2324 (x : Prop) : Prop axiom g2325 (x : Prop) : Prop axiom g2326 (x : Prop) : Prop axiom g2327 (x : Prop) : Prop axiom g2328 (x : Prop) : Prop axiom g2329 (x : Prop) : Prop axiom g2330 (x : Prop) : Prop axiom g2331 (x : Prop) : Prop axiom g2332 (x : Prop) : Prop axiom g2333 (x : Prop) : Prop axiom g2334 (x : Prop) : Prop axiom g2335 (x : Prop) : Prop axiom g2336 (x : Prop) : Prop axiom g2337 (x : Prop) : Prop axiom g2338 (x : Prop) : Prop axiom g2339 (x : Prop) : Prop axiom g2340 (x : Prop) : Prop axiom g2341 (x : Prop) : Prop axiom g2342 (x : Prop) : Prop axiom g2343 (x : Prop) : Prop axiom g2344 (x : Prop) : Prop axiom g2345 (x : Prop) : Prop axiom g2346 (x : Prop) : Prop axiom g2347 (x : Prop) : Prop axiom g2348 (x : Prop) : Prop axiom g2349 (x : Prop) : Prop axiom g2350 (x : Prop) : Prop axiom g2351 (x : Prop) : Prop axiom g2352 (x : Prop) : Prop axiom g2353 (x : Prop) : Prop axiom g2354 (x : Prop) : Prop axiom g2355 (x : Prop) : Prop axiom g2356 (x : Prop) : Prop axiom g2357 (x : Prop) : Prop axiom g2358 (x : Prop) : Prop axiom g2359 (x : Prop) : Prop axiom g2360 (x : Prop) : Prop axiom g2361 (x : Prop) : Prop axiom g2362 (x : Prop) : Prop axiom g2363 (x : Prop) : Prop axiom g2364 (x : Prop) : Prop axiom g2365 (x : Prop) : Prop axiom g2366 (x : Prop) : Prop axiom g2367 (x : Prop) : Prop axiom g2368 (x : Prop) : Prop axiom g2369 (x : Prop) : Prop axiom g2370 (x : Prop) : Prop axiom g2371 (x : Prop) : Prop axiom g2372 (x : Prop) : Prop axiom g2373 (x : Prop) : Prop axiom g2374 (x : Prop) : Prop axiom g2375 (x : Prop) : Prop axiom g2376 (x : Prop) : Prop axiom g2377 (x : Prop) : Prop axiom g2378 (x : Prop) : Prop axiom g2379 (x : Prop) : Prop axiom g2380 (x : Prop) : Prop axiom g2381 (x : Prop) : Prop axiom g2382 (x : Prop) : Prop axiom g2383 (x : Prop) : Prop axiom g2384 (x : Prop) : Prop axiom g2385 (x : Prop) : Prop axiom g2386 (x : Prop) : Prop axiom g2387 (x : Prop) : Prop axiom g2388 (x : Prop) : Prop axiom g2389 (x : Prop) : Prop axiom g2390 (x : Prop) : Prop axiom g2391 (x : Prop) : Prop axiom g2392 (x : Prop) : Prop axiom g2393 (x : Prop) : Prop axiom g2394 (x : Prop) : Prop axiom g2395 (x : Prop) : Prop axiom g2396 (x : Prop) : Prop axiom g2397 (x : Prop) : Prop axiom g2398 (x : Prop) : Prop axiom g2399 (x : Prop) : Prop axiom g2400 (x : Prop) : Prop axiom g2401 (x : Prop) : Prop axiom g2402 (x : Prop) : Prop axiom g2403 (x : Prop) : Prop axiom g2404 (x : Prop) : Prop axiom g2405 (x : Prop) : Prop axiom g2406 (x : Prop) : Prop axiom g2407 (x : Prop) : Prop axiom g2408 (x : Prop) : Prop axiom g2409 (x : Prop) : Prop axiom g2410 (x : Prop) : Prop axiom g2411 (x : Prop) : Prop axiom g2412 (x : Prop) : Prop axiom g2413 (x : Prop) : Prop axiom g2414 (x : Prop) : Prop axiom g2415 (x : Prop) : Prop axiom g2416 (x : Prop) : Prop axiom g2417 (x : Prop) : Prop axiom g2418 (x : Prop) : Prop axiom g2419 (x : Prop) : Prop axiom g2420 (x : Prop) : Prop axiom g2421 (x : Prop) : Prop axiom g2422 (x : Prop) : Prop axiom g2423 (x : Prop) : Prop axiom g2424 (x : Prop) : Prop axiom g2425 (x : Prop) : Prop axiom g2426 (x : Prop) : Prop axiom g2427 (x : Prop) : Prop axiom g2428 (x : Prop) : Prop axiom g2429 (x : Prop) : Prop axiom g2430 (x : Prop) : Prop axiom g2431 (x : Prop) : Prop axiom g2432 (x : Prop) : Prop axiom g2433 (x : Prop) : Prop axiom g2434 (x : Prop) : Prop axiom g2435 (x : Prop) : Prop axiom g2436 (x : Prop) : Prop axiom g2437 (x : Prop) : Prop axiom g2438 (x : Prop) : Prop axiom g2439 (x : Prop) : Prop axiom g2440 (x : Prop) : Prop axiom g2441 (x : Prop) : Prop axiom g2442 (x : Prop) : Prop axiom g2443 (x : Prop) : Prop axiom g2444 (x : Prop) : Prop axiom g2445 (x : Prop) : Prop axiom g2446 (x : Prop) : Prop axiom g2447 (x : Prop) : Prop axiom g2448 (x : Prop) : Prop axiom g2449 (x : Prop) : Prop axiom g2450 (x : Prop) : Prop axiom g2451 (x : Prop) : Prop axiom g2452 (x : Prop) : Prop axiom g2453 (x : Prop) : Prop axiom g2454 (x : Prop) : Prop axiom g2455 (x : Prop) : Prop axiom g2456 (x : Prop) : Prop axiom g2457 (x : Prop) : Prop axiom g2458 (x : Prop) : Prop axiom g2459 (x : Prop) : Prop axiom g2460 (x : Prop) : Prop axiom g2461 (x : Prop) : Prop axiom g2462 (x : Prop) : Prop axiom g2463 (x : Prop) : Prop axiom g2464 (x : Prop) : Prop axiom g2465 (x : Prop) : Prop axiom g2466 (x : Prop) : Prop axiom g2467 (x : Prop) : Prop axiom g2468 (x : Prop) : Prop axiom g2469 (x : Prop) : Prop axiom g2470 (x : Prop) : Prop axiom g2471 (x : Prop) : Prop axiom g2472 (x : Prop) : Prop axiom g2473 (x : Prop) : Prop axiom g2474 (x : Prop) : Prop axiom g2475 (x : Prop) : Prop axiom g2476 (x : Prop) : Prop axiom g2477 (x : Prop) : Prop axiom g2478 (x : Prop) : Prop axiom g2479 (x : Prop) : Prop axiom g2480 (x : Prop) : Prop axiom g2481 (x : Prop) : Prop axiom g2482 (x : Prop) : Prop axiom g2483 (x : Prop) : Prop axiom g2484 (x : Prop) : Prop axiom g2485 (x : Prop) : Prop axiom g2486 (x : Prop) : Prop axiom g2487 (x : Prop) : Prop axiom g2488 (x : Prop) : Prop axiom g2489 (x : Prop) : Prop axiom g2490 (x : Prop) : Prop axiom g2491 (x : Prop) : Prop axiom g2492 (x : Prop) : Prop axiom g2493 (x : Prop) : Prop axiom g2494 (x : Prop) : Prop axiom g2495 (x : Prop) : Prop axiom g2496 (x : Prop) : Prop axiom g2497 (x : Prop) : Prop axiom g2498 (x : Prop) : Prop axiom g2499 (x : Prop) : Prop axiom g2500 (x : Prop) : Prop axiom g2501 (x : Prop) : Prop axiom g2502 (x : Prop) : Prop axiom g2503 (x : Prop) : Prop axiom g2504 (x : Prop) : Prop axiom g2505 (x : Prop) : Prop axiom g2506 (x : Prop) : Prop axiom g2507 (x : Prop) : Prop axiom g2508 (x : Prop) : Prop axiom g2509 (x : Prop) : Prop axiom g2510 (x : Prop) : Prop axiom g2511 (x : Prop) : Prop axiom g2512 (x : Prop) : Prop axiom g2513 (x : Prop) : Prop axiom g2514 (x : Prop) : Prop axiom g2515 (x : Prop) : Prop axiom g2516 (x : Prop) : Prop axiom g2517 (x : Prop) : Prop axiom g2518 (x : Prop) : Prop axiom g2519 (x : Prop) : Prop axiom g2520 (x : Prop) : Prop axiom g2521 (x : Prop) : Prop axiom g2522 (x : Prop) : Prop axiom g2523 (x : Prop) : Prop axiom g2524 (x : Prop) : Prop axiom g2525 (x : Prop) : Prop axiom g2526 (x : Prop) : Prop axiom g2527 (x : Prop) : Prop axiom g2528 (x : Prop) : Prop axiom g2529 (x : Prop) : Prop axiom g2530 (x : Prop) : Prop axiom g2531 (x : Prop) : Prop axiom g2532 (x : Prop) : Prop axiom g2533 (x : Prop) : Prop axiom g2534 (x : Prop) : Prop axiom g2535 (x : Prop) : Prop axiom g2536 (x : Prop) : Prop axiom g2537 (x : Prop) : Prop axiom g2538 (x : Prop) : Prop axiom g2539 (x : Prop) : Prop axiom g2540 (x : Prop) : Prop axiom g2541 (x : Prop) : Prop axiom g2542 (x : Prop) : Prop axiom g2543 (x : Prop) : Prop axiom g2544 (x : Prop) : Prop axiom g2545 (x : Prop) : Prop axiom g2546 (x : Prop) : Prop axiom g2547 (x : Prop) : Prop axiom g2548 (x : Prop) : Prop axiom g2549 (x : Prop) : Prop axiom g2550 (x : Prop) : Prop axiom g2551 (x : Prop) : Prop axiom g2552 (x : Prop) : Prop axiom g2553 (x : Prop) : Prop axiom g2554 (x : Prop) : Prop axiom g2555 (x : Prop) : Prop axiom g2556 (x : Prop) : Prop axiom g2557 (x : Prop) : Prop axiom g2558 (x : Prop) : Prop axiom g2559 (x : Prop) : Prop axiom g2560 (x : Prop) : Prop axiom g2561 (x : Prop) : Prop axiom g2562 (x : Prop) : Prop axiom g2563 (x : Prop) : Prop axiom g2564 (x : Prop) : Prop axiom g2565 (x : Prop) : Prop axiom g2566 (x : Prop) : Prop axiom g2567 (x : Prop) : Prop axiom g2568 (x : Prop) : Prop axiom g2569 (x : Prop) : Prop axiom g2570 (x : Prop) : Prop axiom g2571 (x : Prop) : Prop axiom g2572 (x : Prop) : Prop axiom g2573 (x : Prop) : Prop axiom g2574 (x : Prop) : Prop axiom g2575 (x : Prop) : Prop axiom g2576 (x : Prop) : Prop axiom g2577 (x : Prop) : Prop axiom g2578 (x : Prop) : Prop axiom g2579 (x : Prop) : Prop axiom g2580 (x : Prop) : Prop axiom g2581 (x : Prop) : Prop axiom g2582 (x : Prop) : Prop axiom g2583 (x : Prop) : Prop axiom g2584 (x : Prop) : Prop axiom g2585 (x : Prop) : Prop axiom g2586 (x : Prop) : Prop axiom g2587 (x : Prop) : Prop axiom g2588 (x : Prop) : Prop axiom g2589 (x : Prop) : Prop axiom g2590 (x : Prop) : Prop axiom g2591 (x : Prop) : Prop axiom g2592 (x : Prop) : Prop axiom g2593 (x : Prop) : Prop axiom g2594 (x : Prop) : Prop axiom g2595 (x : Prop) : Prop axiom g2596 (x : Prop) : Prop axiom g2597 (x : Prop) : Prop axiom g2598 (x : Prop) : Prop axiom g2599 (x : Prop) : Prop axiom g2600 (x : Prop) : Prop axiom g2601 (x : Prop) : Prop axiom g2602 (x : Prop) : Prop axiom g2603 (x : Prop) : Prop axiom g2604 (x : Prop) : Prop axiom g2605 (x : Prop) : Prop axiom g2606 (x : Prop) : Prop axiom g2607 (x : Prop) : Prop axiom g2608 (x : Prop) : Prop axiom g2609 (x : Prop) : Prop axiom g2610 (x : Prop) : Prop axiom g2611 (x : Prop) : Prop axiom g2612 (x : Prop) : Prop axiom g2613 (x : Prop) : Prop axiom g2614 (x : Prop) : Prop axiom g2615 (x : Prop) : Prop axiom g2616 (x : Prop) : Prop axiom g2617 (x : Prop) : Prop axiom g2618 (x : Prop) : Prop axiom g2619 (x : Prop) : Prop axiom g2620 (x : Prop) : Prop axiom g2621 (x : Prop) : Prop axiom g2622 (x : Prop) : Prop axiom g2623 (x : Prop) : Prop axiom g2624 (x : Prop) : Prop axiom g2625 (x : Prop) : Prop axiom g2626 (x : Prop) : Prop axiom g2627 (x : Prop) : Prop axiom g2628 (x : Prop) : Prop axiom g2629 (x : Prop) : Prop axiom g2630 (x : Prop) : Prop axiom g2631 (x : Prop) : Prop axiom g2632 (x : Prop) : Prop axiom g2633 (x : Prop) : Prop axiom g2634 (x : Prop) : Prop axiom g2635 (x : Prop) : Prop axiom g2636 (x : Prop) : Prop axiom g2637 (x : Prop) : Prop axiom g2638 (x : Prop) : Prop axiom g2639 (x : Prop) : Prop axiom g2640 (x : Prop) : Prop axiom g2641 (x : Prop) : Prop axiom g2642 (x : Prop) : Prop axiom g2643 (x : Prop) : Prop axiom g2644 (x : Prop) : Prop axiom g2645 (x : Prop) : Prop axiom g2646 (x : Prop) : Prop axiom g2647 (x : Prop) : Prop axiom g2648 (x : Prop) : Prop axiom g2649 (x : Prop) : Prop axiom g2650 (x : Prop) : Prop axiom g2651 (x : Prop) : Prop axiom g2652 (x : Prop) : Prop axiom g2653 (x : Prop) : Prop axiom g2654 (x : Prop) : Prop axiom g2655 (x : Prop) : Prop axiom g2656 (x : Prop) : Prop axiom g2657 (x : Prop) : Prop axiom g2658 (x : Prop) : Prop axiom g2659 (x : Prop) : Prop axiom g2660 (x : Prop) : Prop axiom g2661 (x : Prop) : Prop axiom g2662 (x : Prop) : Prop axiom g2663 (x : Prop) : Prop axiom g2664 (x : Prop) : Prop axiom g2665 (x : Prop) : Prop axiom g2666 (x : Prop) : Prop axiom g2667 (x : Prop) : Prop axiom g2668 (x : Prop) : Prop axiom g2669 (x : Prop) : Prop axiom g2670 (x : Prop) : Prop axiom g2671 (x : Prop) : Prop axiom g2672 (x : Prop) : Prop axiom g2673 (x : Prop) : Prop axiom g2674 (x : Prop) : Prop axiom g2675 (x : Prop) : Prop axiom g2676 (x : Prop) : Prop axiom g2677 (x : Prop) : Prop axiom g2678 (x : Prop) : Prop axiom g2679 (x : Prop) : Prop axiom g2680 (x : Prop) : Prop axiom g2681 (x : Prop) : Prop axiom g2682 (x : Prop) : Prop axiom g2683 (x : Prop) : Prop axiom g2684 (x : Prop) : Prop axiom g2685 (x : Prop) : Prop axiom g2686 (x : Prop) : Prop axiom g2687 (x : Prop) : Prop axiom g2688 (x : Prop) : Prop axiom g2689 (x : Prop) : Prop axiom g2690 (x : Prop) : Prop axiom g2691 (x : Prop) : Prop axiom g2692 (x : Prop) : Prop axiom g2693 (x : Prop) : Prop axiom g2694 (x : Prop) : Prop axiom g2695 (x : Prop) : Prop axiom g2696 (x : Prop) : Prop axiom g2697 (x : Prop) : Prop axiom g2698 (x : Prop) : Prop axiom g2699 (x : Prop) : Prop axiom g2700 (x : Prop) : Prop axiom g2701 (x : Prop) : Prop axiom g2702 (x : Prop) : Prop axiom g2703 (x : Prop) : Prop axiom g2704 (x : Prop) : Prop axiom g2705 (x : Prop) : Prop axiom g2706 (x : Prop) : Prop axiom g2707 (x : Prop) : Prop axiom g2708 (x : Prop) : Prop axiom g2709 (x : Prop) : Prop axiom g2710 (x : Prop) : Prop axiom g2711 (x : Prop) : Prop axiom g2712 (x : Prop) : Prop axiom g2713 (x : Prop) : Prop axiom g2714 (x : Prop) : Prop axiom g2715 (x : Prop) : Prop axiom g2716 (x : Prop) : Prop axiom g2717 (x : Prop) : Prop axiom g2718 (x : Prop) : Prop axiom g2719 (x : Prop) : Prop axiom g2720 (x : Prop) : Prop axiom g2721 (x : Prop) : Prop axiom g2722 (x : Prop) : Prop axiom g2723 (x : Prop) : Prop axiom g2724 (x : Prop) : Prop axiom g2725 (x : Prop) : Prop axiom g2726 (x : Prop) : Prop axiom g2727 (x : Prop) : Prop axiom g2728 (x : Prop) : Prop axiom g2729 (x : Prop) : Prop axiom g2730 (x : Prop) : Prop axiom g2731 (x : Prop) : Prop axiom g2732 (x : Prop) : Prop axiom g2733 (x : Prop) : Prop axiom g2734 (x : Prop) : Prop axiom g2735 (x : Prop) : Prop axiom g2736 (x : Prop) : Prop axiom g2737 (x : Prop) : Prop axiom g2738 (x : Prop) : Prop axiom g2739 (x : Prop) : Prop axiom g2740 (x : Prop) : Prop axiom g2741 (x : Prop) : Prop axiom g2742 (x : Prop) : Prop axiom g2743 (x : Prop) : Prop axiom g2744 (x : Prop) : Prop axiom g2745 (x : Prop) : Prop axiom g2746 (x : Prop) : Prop axiom g2747 (x : Prop) : Prop axiom g2748 (x : Prop) : Prop axiom g2749 (x : Prop) : Prop axiom g2750 (x : Prop) : Prop axiom g2751 (x : Prop) : Prop axiom g2752 (x : Prop) : Prop axiom g2753 (x : Prop) : Prop axiom g2754 (x : Prop) : Prop axiom g2755 (x : Prop) : Prop axiom g2756 (x : Prop) : Prop axiom g2757 (x : Prop) : Prop axiom g2758 (x : Prop) : Prop axiom g2759 (x : Prop) : Prop axiom g2760 (x : Prop) : Prop axiom g2761 (x : Prop) : Prop axiom g2762 (x : Prop) : Prop axiom g2763 (x : Prop) : Prop axiom g2764 (x : Prop) : Prop axiom g2765 (x : Prop) : Prop axiom g2766 (x : Prop) : Prop axiom g2767 (x : Prop) : Prop axiom g2768 (x : Prop) : Prop axiom g2769 (x : Prop) : Prop axiom g2770 (x : Prop) : Prop axiom g2771 (x : Prop) : Prop axiom g2772 (x : Prop) : Prop axiom g2773 (x : Prop) : Prop axiom g2774 (x : Prop) : Prop axiom g2775 (x : Prop) : Prop axiom g2776 (x : Prop) : Prop axiom g2777 (x : Prop) : Prop axiom g2778 (x : Prop) : Prop axiom g2779 (x : Prop) : Prop axiom g2780 (x : Prop) : Prop axiom g2781 (x : Prop) : Prop axiom g2782 (x : Prop) : Prop axiom g2783 (x : Prop) : Prop axiom g2784 (x : Prop) : Prop axiom g2785 (x : Prop) : Prop axiom g2786 (x : Prop) : Prop axiom g2787 (x : Prop) : Prop axiom g2788 (x : Prop) : Prop axiom g2789 (x : Prop) : Prop axiom g2790 (x : Prop) : Prop axiom g2791 (x : Prop) : Prop axiom g2792 (x : Prop) : Prop axiom g2793 (x : Prop) : Prop axiom g2794 (x : Prop) : Prop axiom g2795 (x : Prop) : Prop axiom g2796 (x : Prop) : Prop axiom g2797 (x : Prop) : Prop axiom g2798 (x : Prop) : Prop axiom g2799 (x : Prop) : Prop axiom g2800 (x : Prop) : Prop axiom g2801 (x : Prop) : Prop axiom g2802 (x : Prop) : Prop axiom g2803 (x : Prop) : Prop axiom g2804 (x : Prop) : Prop axiom g2805 (x : Prop) : Prop axiom g2806 (x : Prop) : Prop axiom g2807 (x : Prop) : Prop axiom g2808 (x : Prop) : Prop axiom g2809 (x : Prop) : Prop axiom g2810 (x : Prop) : Prop axiom g2811 (x : Prop) : Prop axiom g2812 (x : Prop) : Prop axiom g2813 (x : Prop) : Prop axiom g2814 (x : Prop) : Prop axiom g2815 (x : Prop) : Prop axiom g2816 (x : Prop) : Prop axiom g2817 (x : Prop) : Prop axiom g2818 (x : Prop) : Prop axiom g2819 (x : Prop) : Prop axiom g2820 (x : Prop) : Prop axiom g2821 (x : Prop) : Prop axiom g2822 (x : Prop) : Prop axiom g2823 (x : Prop) : Prop axiom g2824 (x : Prop) : Prop axiom g2825 (x : Prop) : Prop axiom g2826 (x : Prop) : Prop axiom g2827 (x : Prop) : Prop axiom g2828 (x : Prop) : Prop axiom g2829 (x : Prop) : Prop axiom g2830 (x : Prop) : Prop axiom g2831 (x : Prop) : Prop axiom g2832 (x : Prop) : Prop axiom g2833 (x : Prop) : Prop axiom g2834 (x : Prop) : Prop axiom g2835 (x : Prop) : Prop axiom g2836 (x : Prop) : Prop axiom g2837 (x : Prop) : Prop axiom g2838 (x : Prop) : Prop axiom g2839 (x : Prop) : Prop axiom g2840 (x : Prop) : Prop axiom g2841 (x : Prop) : Prop axiom g2842 (x : Prop) : Prop axiom g2843 (x : Prop) : Prop axiom g2844 (x : Prop) : Prop axiom g2845 (x : Prop) : Prop axiom g2846 (x : Prop) : Prop axiom g2847 (x : Prop) : Prop axiom g2848 (x : Prop) : Prop axiom g2849 (x : Prop) : Prop axiom g2850 (x : Prop) : Prop axiom g2851 (x : Prop) : Prop axiom g2852 (x : Prop) : Prop axiom g2853 (x : Prop) : Prop axiom g2854 (x : Prop) : Prop axiom g2855 (x : Prop) : Prop axiom g2856 (x : Prop) : Prop axiom g2857 (x : Prop) : Prop axiom g2858 (x : Prop) : Prop axiom g2859 (x : Prop) : Prop axiom g2860 (x : Prop) : Prop axiom g2861 (x : Prop) : Prop axiom g2862 (x : Prop) : Prop axiom g2863 (x : Prop) : Prop axiom g2864 (x : Prop) : Prop axiom g2865 (x : Prop) : Prop axiom g2866 (x : Prop) : Prop axiom g2867 (x : Prop) : Prop axiom g2868 (x : Prop) : Prop axiom g2869 (x : Prop) : Prop axiom g2870 (x : Prop) : Prop axiom g2871 (x : Prop) : Prop axiom g2872 (x : Prop) : Prop axiom g2873 (x : Prop) : Prop axiom g2874 (x : Prop) : Prop axiom g2875 (x : Prop) : Prop axiom g2876 (x : Prop) : Prop axiom g2877 (x : Prop) : Prop axiom g2878 (x : Prop) : Prop axiom g2879 (x : Prop) : Prop axiom g2880 (x : Prop) : Prop axiom g2881 (x : Prop) : Prop axiom g2882 (x : Prop) : Prop axiom g2883 (x : Prop) : Prop axiom g2884 (x : Prop) : Prop axiom g2885 (x : Prop) : Prop axiom g2886 (x : Prop) : Prop axiom g2887 (x : Prop) : Prop axiom g2888 (x : Prop) : Prop axiom g2889 (x : Prop) : Prop axiom g2890 (x : Prop) : Prop axiom g2891 (x : Prop) : Prop axiom g2892 (x : Prop) : Prop axiom g2893 (x : Prop) : Prop axiom g2894 (x : Prop) : Prop axiom g2895 (x : Prop) : Prop axiom g2896 (x : Prop) : Prop axiom g2897 (x : Prop) : Prop axiom g2898 (x : Prop) : Prop axiom g2899 (x : Prop) : Prop axiom g2900 (x : Prop) : Prop axiom g2901 (x : Prop) : Prop axiom g2902 (x : Prop) : Prop axiom g2903 (x : Prop) : Prop axiom g2904 (x : Prop) : Prop axiom g2905 (x : Prop) : Prop axiom g2906 (x : Prop) : Prop axiom g2907 (x : Prop) : Prop axiom g2908 (x : Prop) : Prop axiom g2909 (x : Prop) : Prop axiom g2910 (x : Prop) : Prop axiom g2911 (x : Prop) : Prop axiom g2912 (x : Prop) : Prop axiom g2913 (x : Prop) : Prop axiom g2914 (x : Prop) : Prop axiom g2915 (x : Prop) : Prop axiom g2916 (x : Prop) : Prop axiom g2917 (x : Prop) : Prop axiom g2918 (x : Prop) : Prop axiom g2919 (x : Prop) : Prop axiom g2920 (x : Prop) : Prop axiom g2921 (x : Prop) : Prop axiom g2922 (x : Prop) : Prop axiom g2923 (x : Prop) : Prop axiom g2924 (x : Prop) : Prop axiom g2925 (x : Prop) : Prop axiom g2926 (x : Prop) : Prop axiom g2927 (x : Prop) : Prop axiom g2928 (x : Prop) : Prop axiom g2929 (x : Prop) : Prop axiom g2930 (x : Prop) : Prop axiom g2931 (x : Prop) : Prop axiom g2932 (x : Prop) : Prop axiom g2933 (x : Prop) : Prop axiom g2934 (x : Prop) : Prop axiom g2935 (x : Prop) : Prop axiom g2936 (x : Prop) : Prop axiom g2937 (x : Prop) : Prop axiom g2938 (x : Prop) : Prop axiom g2939 (x : Prop) : Prop axiom g2940 (x : Prop) : Prop axiom g2941 (x : Prop) : Prop axiom g2942 (x : Prop) : Prop axiom g2943 (x : Prop) : Prop axiom g2944 (x : Prop) : Prop axiom g2945 (x : Prop) : Prop axiom g2946 (x : Prop) : Prop axiom g2947 (x : Prop) : Prop axiom g2948 (x : Prop) : Prop axiom g2949 (x : Prop) : Prop axiom g2950 (x : Prop) : Prop axiom g2951 (x : Prop) : Prop axiom g2952 (x : Prop) : Prop axiom g2953 (x : Prop) : Prop axiom g2954 (x : Prop) : Prop axiom g2955 (x : Prop) : Prop axiom g2956 (x : Prop) : Prop axiom g2957 (x : Prop) : Prop axiom g2958 (x : Prop) : Prop axiom g2959 (x : Prop) : Prop axiom g2960 (x : Prop) : Prop axiom g2961 (x : Prop) : Prop axiom g2962 (x : Prop) : Prop axiom g2963 (x : Prop) : Prop axiom g2964 (x : Prop) : Prop axiom g2965 (x : Prop) : Prop axiom g2966 (x : Prop) : Prop axiom g2967 (x : Prop) : Prop axiom g2968 (x : Prop) : Prop axiom g2969 (x : Prop) : Prop axiom g2970 (x : Prop) : Prop axiom g2971 (x : Prop) : Prop axiom g2972 (x : Prop) : Prop axiom g2973 (x : Prop) : Prop axiom g2974 (x : Prop) : Prop axiom g2975 (x : Prop) : Prop axiom g2976 (x : Prop) : Prop axiom g2977 (x : Prop) : Prop axiom g2978 (x : Prop) : Prop axiom g2979 (x : Prop) : Prop axiom g2980 (x : Prop) : Prop axiom g2981 (x : Prop) : Prop axiom g2982 (x : Prop) : Prop axiom g2983 (x : Prop) : Prop axiom g2984 (x : Prop) : Prop axiom g2985 (x : Prop) : Prop axiom g2986 (x : Prop) : Prop axiom g2987 (x : Prop) : Prop axiom g2988 (x : Prop) : Prop axiom g2989 (x : Prop) : Prop axiom g2990 (x : Prop) : Prop axiom g2991 (x : Prop) : Prop axiom g2992 (x : Prop) : Prop axiom g2993 (x : Prop) : Prop axiom g2994 (x : Prop) : Prop axiom g2995 (x : Prop) : Prop axiom g2996 (x : Prop) : Prop axiom g2997 (x : Prop) : Prop axiom g2998 (x : Prop) : Prop axiom g2999 (x : Prop) : Prop @[simp] axiom s0 (x : Prop) : f (g1 x) = f (g0 x) @[simp] axiom s1 (x : Prop) : f (g2 x) = f (g1 x) @[simp] axiom s2 (x : Prop) : f (g3 x) = f (g2 x) @[simp] axiom s3 (x : Prop) : f (g4 x) = f (g3 x) @[simp] axiom s4 (x : Prop) : f (g5 x) = f (g4 x) @[simp] axiom s5 (x : Prop) : f (g6 x) = f (g5 x) @[simp] axiom s6 (x : Prop) : f (g7 x) = f (g6 x) @[simp] axiom s7 (x : Prop) : f (g8 x) = f (g7 x) @[simp] axiom s8 (x : Prop) : f (g9 x) = f (g8 x) @[simp] axiom s9 (x : Prop) : f (g10 x) = f (g9 x) @[simp] axiom s10 (x : Prop) : f (g11 x) = f (g10 x) @[simp] axiom s11 (x : Prop) : f (g12 x) = f (g11 x) @[simp] axiom s12 (x : Prop) : f (g13 x) = f (g12 x) @[simp] axiom s13 (x : Prop) : f (g14 x) = f (g13 x) @[simp] axiom s14 (x : Prop) : f (g15 x) = f (g14 x) @[simp] axiom s15 (x : Prop) : f (g16 x) = f (g15 x) @[simp] axiom s16 (x : Prop) : f (g17 x) = f (g16 x) @[simp] axiom s17 (x : Prop) : f (g18 x) = f (g17 x) @[simp] axiom s18 (x : Prop) : f (g19 x) = f (g18 x) @[simp] axiom s19 (x : Prop) : f (g20 x) = f (g19 x) @[simp] axiom s20 (x : Prop) : f (g21 x) = f (g20 x) @[simp] axiom s21 (x : Prop) : f (g22 x) = f (g21 x) @[simp] axiom s22 (x : Prop) : f (g23 x) = f (g22 x) @[simp] axiom s23 (x : Prop) : f (g24 x) = f (g23 x) @[simp] axiom s24 (x : Prop) : f (g25 x) = f (g24 x) @[simp] axiom s25 (x : Prop) : f (g26 x) = f (g25 x) @[simp] axiom s26 (x : Prop) : f (g27 x) = f (g26 x) @[simp] axiom s27 (x : Prop) : f (g28 x) = f (g27 x) @[simp] axiom s28 (x : Prop) : f (g29 x) = f (g28 x) @[simp] axiom s29 (x : Prop) : f (g30 x) = f (g29 x) @[simp] axiom s30 (x : Prop) : f (g31 x) = f (g30 x) @[simp] axiom s31 (x : Prop) : f (g32 x) = f (g31 x) @[simp] axiom s32 (x : Prop) : f (g33 x) = f (g32 x) @[simp] axiom s33 (x : Prop) : f (g34 x) = f (g33 x) @[simp] axiom s34 (x : Prop) : f (g35 x) = f (g34 x) @[simp] axiom s35 (x : Prop) : f (g36 x) = f (g35 x) @[simp] axiom s36 (x : Prop) : f (g37 x) = f (g36 x) @[simp] axiom s37 (x : Prop) : f (g38 x) = f (g37 x) @[simp] axiom s38 (x : Prop) : f (g39 x) = f (g38 x) @[simp] axiom s39 (x : Prop) : f (g40 x) = f (g39 x) @[simp] axiom s40 (x : Prop) : f (g41 x) = f (g40 x) @[simp] axiom s41 (x : Prop) : f (g42 x) = f (g41 x) @[simp] axiom s42 (x : Prop) : f (g43 x) = f (g42 x) @[simp] axiom s43 (x : Prop) : f (g44 x) = f (g43 x) @[simp] axiom s44 (x : Prop) : f (g45 x) = f (g44 x) @[simp] axiom s45 (x : Prop) : f (g46 x) = f (g45 x) @[simp] axiom s46 (x : Prop) : f (g47 x) = f (g46 x) @[simp] axiom s47 (x : Prop) : f (g48 x) = f (g47 x) @[simp] axiom s48 (x : Prop) : f (g49 x) = f (g48 x) @[simp] axiom s49 (x : Prop) : f (g50 x) = f (g49 x) @[simp] axiom s50 (x : Prop) : f (g51 x) = f (g50 x) @[simp] axiom s51 (x : Prop) : f (g52 x) = f (g51 x) @[simp] axiom s52 (x : Prop) : f (g53 x) = f (g52 x) @[simp] axiom s53 (x : Prop) : f (g54 x) = f (g53 x) @[simp] axiom s54 (x : Prop) : f (g55 x) = f (g54 x) @[simp] axiom s55 (x : Prop) : f (g56 x) = f (g55 x) @[simp] axiom s56 (x : Prop) : f (g57 x) = f (g56 x) @[simp] axiom s57 (x : Prop) : f (g58 x) = f (g57 x) @[simp] axiom s58 (x : Prop) : f (g59 x) = f (g58 x) @[simp] axiom s59 (x : Prop) : f (g60 x) = f (g59 x) @[simp] axiom s60 (x : Prop) : f (g61 x) = f (g60 x) @[simp] axiom s61 (x : Prop) : f (g62 x) = f (g61 x) @[simp] axiom s62 (x : Prop) : f (g63 x) = f (g62 x) @[simp] axiom s63 (x : Prop) : f (g64 x) = f (g63 x) @[simp] axiom s64 (x : Prop) : f (g65 x) = f (g64 x) @[simp] axiom s65 (x : Prop) : f (g66 x) = f (g65 x) @[simp] axiom s66 (x : Prop) : f (g67 x) = f (g66 x) @[simp] axiom s67 (x : Prop) : f (g68 x) = f (g67 x) @[simp] axiom s68 (x : Prop) : f (g69 x) = f (g68 x) @[simp] axiom s69 (x : Prop) : f (g70 x) = f (g69 x) @[simp] axiom s70 (x : Prop) : f (g71 x) = f (g70 x) @[simp] axiom s71 (x : Prop) : f (g72 x) = f (g71 x) @[simp] axiom s72 (x : Prop) : f (g73 x) = f (g72 x) @[simp] axiom s73 (x : Prop) : f (g74 x) = f (g73 x) @[simp] axiom s74 (x : Prop) : f (g75 x) = f (g74 x) @[simp] axiom s75 (x : Prop) : f (g76 x) = f (g75 x) @[simp] axiom s76 (x : Prop) : f (g77 x) = f (g76 x) @[simp] axiom s77 (x : Prop) : f (g78 x) = f (g77 x) @[simp] axiom s78 (x : Prop) : f (g79 x) = f (g78 x) @[simp] axiom s79 (x : Prop) : f (g80 x) = f (g79 x) @[simp] axiom s80 (x : Prop) : f (g81 x) = f (g80 x) @[simp] axiom s81 (x : Prop) : f (g82 x) = f (g81 x) @[simp] axiom s82 (x : Prop) : f (g83 x) = f (g82 x) @[simp] axiom s83 (x : Prop) : f (g84 x) = f (g83 x) @[simp] axiom s84 (x : Prop) : f (g85 x) = f (g84 x) @[simp] axiom s85 (x : Prop) : f (g86 x) = f (g85 x) @[simp] axiom s86 (x : Prop) : f (g87 x) = f (g86 x) @[simp] axiom s87 (x : Prop) : f (g88 x) = f (g87 x) @[simp] axiom s88 (x : Prop) : f (g89 x) = f (g88 x) @[simp] axiom s89 (x : Prop) : f (g90 x) = f (g89 x) @[simp] axiom s90 (x : Prop) : f (g91 x) = f (g90 x) @[simp] axiom s91 (x : Prop) : f (g92 x) = f (g91 x) @[simp] axiom s92 (x : Prop) : f (g93 x) = f (g92 x) @[simp] axiom s93 (x : Prop) : f (g94 x) = f (g93 x) @[simp] axiom s94 (x : Prop) : f (g95 x) = f (g94 x) @[simp] axiom s95 (x : Prop) : f (g96 x) = f (g95 x) @[simp] axiom s96 (x : Prop) : f (g97 x) = f (g96 x) @[simp] axiom s97 (x : Prop) : f (g98 x) = f (g97 x) @[simp] axiom s98 (x : Prop) : f (g99 x) = f (g98 x) @[simp] axiom s99 (x : Prop) : f (g100 x) = f (g99 x) @[simp] axiom s100 (x : Prop) : f (g101 x) = f (g100 x) @[simp] axiom s101 (x : Prop) : f (g102 x) = f (g101 x) @[simp] axiom s102 (x : Prop) : f (g103 x) = f (g102 x) @[simp] axiom s103 (x : Prop) : f (g104 x) = f (g103 x) @[simp] axiom s104 (x : Prop) : f (g105 x) = f (g104 x) @[simp] axiom s105 (x : Prop) : f (g106 x) = f (g105 x) @[simp] axiom s106 (x : Prop) : f (g107 x) = f (g106 x) @[simp] axiom s107 (x : Prop) : f (g108 x) = f (g107 x) @[simp] axiom s108 (x : Prop) : f (g109 x) = f (g108 x) @[simp] axiom s109 (x : Prop) : f (g110 x) = f (g109 x) @[simp] axiom s110 (x : Prop) : f (g111 x) = f (g110 x) @[simp] axiom s111 (x : Prop) : f (g112 x) = f (g111 x) @[simp] axiom s112 (x : Prop) : f (g113 x) = f (g112 x) @[simp] axiom s113 (x : Prop) : f (g114 x) = f (g113 x) @[simp] axiom s114 (x : Prop) : f (g115 x) = f (g114 x) @[simp] axiom s115 (x : Prop) : f (g116 x) = f (g115 x) @[simp] axiom s116 (x : Prop) : f (g117 x) = f (g116 x) @[simp] axiom s117 (x : Prop) : f (g118 x) = f (g117 x) @[simp] axiom s118 (x : Prop) : f (g119 x) = f (g118 x) @[simp] axiom s119 (x : Prop) : f (g120 x) = f (g119 x) @[simp] axiom s120 (x : Prop) : f (g121 x) = f (g120 x) @[simp] axiom s121 (x : Prop) : f (g122 x) = f (g121 x) @[simp] axiom s122 (x : Prop) : f (g123 x) = f (g122 x) @[simp] axiom s123 (x : Prop) : f (g124 x) = f (g123 x) @[simp] axiom s124 (x : Prop) : f (g125 x) = f (g124 x) @[simp] axiom s125 (x : Prop) : f (g126 x) = f (g125 x) @[simp] axiom s126 (x : Prop) : f (g127 x) = f (g126 x) @[simp] axiom s127 (x : Prop) : f (g128 x) = f (g127 x) @[simp] axiom s128 (x : Prop) : f (g129 x) = f (g128 x) @[simp] axiom s129 (x : Prop) : f (g130 x) = f (g129 x) @[simp] axiom s130 (x : Prop) : f (g131 x) = f (g130 x) @[simp] axiom s131 (x : Prop) : f (g132 x) = f (g131 x) @[simp] axiom s132 (x : Prop) : f (g133 x) = f (g132 x) @[simp] axiom s133 (x : Prop) : f (g134 x) = f (g133 x) @[simp] axiom s134 (x : Prop) : f (g135 x) = f (g134 x) @[simp] axiom s135 (x : Prop) : f (g136 x) = f (g135 x) @[simp] axiom s136 (x : Prop) : f (g137 x) = f (g136 x) @[simp] axiom s137 (x : Prop) : f (g138 x) = f (g137 x) @[simp] axiom s138 (x : Prop) : f (g139 x) = f (g138 x) @[simp] axiom s139 (x : Prop) : f (g140 x) = f (g139 x) @[simp] axiom s140 (x : Prop) : f (g141 x) = f (g140 x) @[simp] axiom s141 (x : Prop) : f (g142 x) = f (g141 x) @[simp] axiom s142 (x : Prop) : f (g143 x) = f (g142 x) @[simp] axiom s143 (x : Prop) : f (g144 x) = f (g143 x) @[simp] axiom s144 (x : Prop) : f (g145 x) = f (g144 x) @[simp] axiom s145 (x : Prop) : f (g146 x) = f (g145 x) @[simp] axiom s146 (x : Prop) : f (g147 x) = f (g146 x) @[simp] axiom s147 (x : Prop) : f (g148 x) = f (g147 x) @[simp] axiom s148 (x : Prop) : f (g149 x) = f (g148 x) @[simp] axiom s149 (x : Prop) : f (g150 x) = f (g149 x) @[simp] axiom s150 (x : Prop) : f (g151 x) = f (g150 x) @[simp] axiom s151 (x : Prop) : f (g152 x) = f (g151 x) @[simp] axiom s152 (x : Prop) : f (g153 x) = f (g152 x) @[simp] axiom s153 (x : Prop) : f (g154 x) = f (g153 x) @[simp] axiom s154 (x : Prop) : f (g155 x) = f (g154 x) @[simp] axiom s155 (x : Prop) : f (g156 x) = f (g155 x) @[simp] axiom s156 (x : Prop) : f (g157 x) = f (g156 x) @[simp] axiom s157 (x : Prop) : f (g158 x) = f (g157 x) @[simp] axiom s158 (x : Prop) : f (g159 x) = f (g158 x) @[simp] axiom s159 (x : Prop) : f (g160 x) = f (g159 x) @[simp] axiom s160 (x : Prop) : f (g161 x) = f (g160 x) @[simp] axiom s161 (x : Prop) : f (g162 x) = f (g161 x) @[simp] axiom s162 (x : Prop) : f (g163 x) = f (g162 x) @[simp] axiom s163 (x : Prop) : f (g164 x) = f (g163 x) @[simp] axiom s164 (x : Prop) : f (g165 x) = f (g164 x) @[simp] axiom s165 (x : Prop) : f (g166 x) = f (g165 x) @[simp] axiom s166 (x : Prop) : f (g167 x) = f (g166 x) @[simp] axiom s167 (x : Prop) : f (g168 x) = f (g167 x) @[simp] axiom s168 (x : Prop) : f (g169 x) = f (g168 x) @[simp] axiom s169 (x : Prop) : f (g170 x) = f (g169 x) @[simp] axiom s170 (x : Prop) : f (g171 x) = f (g170 x) @[simp] axiom s171 (x : Prop) : f (g172 x) = f (g171 x) @[simp] axiom s172 (x : Prop) : f (g173 x) = f (g172 x) @[simp] axiom s173 (x : Prop) : f (g174 x) = f (g173 x) @[simp] axiom s174 (x : Prop) : f (g175 x) = f (g174 x) @[simp] axiom s175 (x : Prop) : f (g176 x) = f (g175 x) @[simp] axiom s176 (x : Prop) : f (g177 x) = f (g176 x) @[simp] axiom s177 (x : Prop) : f (g178 x) = f (g177 x) @[simp] axiom s178 (x : Prop) : f (g179 x) = f (g178 x) @[simp] axiom s179 (x : Prop) : f (g180 x) = f (g179 x) @[simp] axiom s180 (x : Prop) : f (g181 x) = f (g180 x) @[simp] axiom s181 (x : Prop) : f (g182 x) = f (g181 x) @[simp] axiom s182 (x : Prop) : f (g183 x) = f (g182 x) @[simp] axiom s183 (x : Prop) : f (g184 x) = f (g183 x) @[simp] axiom s184 (x : Prop) : f (g185 x) = f (g184 x) @[simp] axiom s185 (x : Prop) : f (g186 x) = f (g185 x) @[simp] axiom s186 (x : Prop) : f (g187 x) = f (g186 x) @[simp] axiom s187 (x : Prop) : f (g188 x) = f (g187 x) @[simp] axiom s188 (x : Prop) : f (g189 x) = f (g188 x) @[simp] axiom s189 (x : Prop) : f (g190 x) = f (g189 x) @[simp] axiom s190 (x : Prop) : f (g191 x) = f (g190 x) @[simp] axiom s191 (x : Prop) : f (g192 x) = f (g191 x) @[simp] axiom s192 (x : Prop) : f (g193 x) = f (g192 x) @[simp] axiom s193 (x : Prop) : f (g194 x) = f (g193 x) @[simp] axiom s194 (x : Prop) : f (g195 x) = f (g194 x) @[simp] axiom s195 (x : Prop) : f (g196 x) = f (g195 x) @[simp] axiom s196 (x : Prop) : f (g197 x) = f (g196 x) @[simp] axiom s197 (x : Prop) : f (g198 x) = f (g197 x) @[simp] axiom s198 (x : Prop) : f (g199 x) = f (g198 x) @[simp] axiom s199 (x : Prop) : f (g200 x) = f (g199 x) @[simp] axiom s200 (x : Prop) : f (g201 x) = f (g200 x) @[simp] axiom s201 (x : Prop) : f (g202 x) = f (g201 x) @[simp] axiom s202 (x : Prop) : f (g203 x) = f (g202 x) @[simp] axiom s203 (x : Prop) : f (g204 x) = f (g203 x) @[simp] axiom s204 (x : Prop) : f (g205 x) = f (g204 x) @[simp] axiom s205 (x : Prop) : f (g206 x) = f (g205 x) @[simp] axiom s206 (x : Prop) : f (g207 x) = f (g206 x) @[simp] axiom s207 (x : Prop) : f (g208 x) = f (g207 x) @[simp] axiom s208 (x : Prop) : f (g209 x) = f (g208 x) @[simp] axiom s209 (x : Prop) : f (g210 x) = f (g209 x) @[simp] axiom s210 (x : Prop) : f (g211 x) = f (g210 x) @[simp] axiom s211 (x : Prop) : f (g212 x) = f (g211 x) @[simp] axiom s212 (x : Prop) : f (g213 x) = f (g212 x) @[simp] axiom s213 (x : Prop) : f (g214 x) = f (g213 x) @[simp] axiom s214 (x : Prop) : f (g215 x) = f (g214 x) @[simp] axiom s215 (x : Prop) : f (g216 x) = f (g215 x) @[simp] axiom s216 (x : Prop) : f (g217 x) = f (g216 x) @[simp] axiom s217 (x : Prop) : f (g218 x) = f (g217 x) @[simp] axiom s218 (x : Prop) : f (g219 x) = f (g218 x) @[simp] axiom s219 (x : Prop) : f (g220 x) = f (g219 x) @[simp] axiom s220 (x : Prop) : f (g221 x) = f (g220 x) @[simp] axiom s221 (x : Prop) : f (g222 x) = f (g221 x) @[simp] axiom s222 (x : Prop) : f (g223 x) = f (g222 x) @[simp] axiom s223 (x : Prop) : f (g224 x) = f (g223 x) @[simp] axiom s224 (x : Prop) : f (g225 x) = f (g224 x) @[simp] axiom s225 (x : Prop) : f (g226 x) = f (g225 x) @[simp] axiom s226 (x : Prop) : f (g227 x) = f (g226 x) @[simp] axiom s227 (x : Prop) : f (g228 x) = f (g227 x) @[simp] axiom s228 (x : Prop) : f (g229 x) = f (g228 x) @[simp] axiom s229 (x : Prop) : f (g230 x) = f (g229 x) @[simp] axiom s230 (x : Prop) : f (g231 x) = f (g230 x) @[simp] axiom s231 (x : Prop) : f (g232 x) = f (g231 x) @[simp] axiom s232 (x : Prop) : f (g233 x) = f (g232 x) @[simp] axiom s233 (x : Prop) : f (g234 x) = f (g233 x) @[simp] axiom s234 (x : Prop) : f (g235 x) = f (g234 x) @[simp] axiom s235 (x : Prop) : f (g236 x) = f (g235 x) @[simp] axiom s236 (x : Prop) : f (g237 x) = f (g236 x) @[simp] axiom s237 (x : Prop) : f (g238 x) = f (g237 x) @[simp] axiom s238 (x : Prop) : f (g239 x) = f (g238 x) @[simp] axiom s239 (x : Prop) : f (g240 x) = f (g239 x) @[simp] axiom s240 (x : Prop) : f (g241 x) = f (g240 x) @[simp] axiom s241 (x : Prop) : f (g242 x) = f (g241 x) @[simp] axiom s242 (x : Prop) : f (g243 x) = f (g242 x) @[simp] axiom s243 (x : Prop) : f (g244 x) = f (g243 x) @[simp] axiom s244 (x : Prop) : f (g245 x) = f (g244 x) @[simp] axiom s245 (x : Prop) : f (g246 x) = f (g245 x) @[simp] axiom s246 (x : Prop) : f (g247 x) = f (g246 x) @[simp] axiom s247 (x : Prop) : f (g248 x) = f (g247 x) @[simp] axiom s248 (x : Prop) : f (g249 x) = f (g248 x) @[simp] axiom s249 (x : Prop) : f (g250 x) = f (g249 x) @[simp] axiom s250 (x : Prop) : f (g251 x) = f (g250 x) @[simp] axiom s251 (x : Prop) : f (g252 x) = f (g251 x) @[simp] axiom s252 (x : Prop) : f (g253 x) = f (g252 x) @[simp] axiom s253 (x : Prop) : f (g254 x) = f (g253 x) @[simp] axiom s254 (x : Prop) : f (g255 x) = f (g254 x) @[simp] axiom s255 (x : Prop) : f (g256 x) = f (g255 x) @[simp] axiom s256 (x : Prop) : f (g257 x) = f (g256 x) @[simp] axiom s257 (x : Prop) : f (g258 x) = f (g257 x) @[simp] axiom s258 (x : Prop) : f (g259 x) = f (g258 x) @[simp] axiom s259 (x : Prop) : f (g260 x) = f (g259 x) @[simp] axiom s260 (x : Prop) : f (g261 x) = f (g260 x) @[simp] axiom s261 (x : Prop) : f (g262 x) = f (g261 x) @[simp] axiom s262 (x : Prop) : f (g263 x) = f (g262 x) @[simp] axiom s263 (x : Prop) : f (g264 x) = f (g263 x) @[simp] axiom s264 (x : Prop) : f (g265 x) = f (g264 x) @[simp] axiom s265 (x : Prop) : f (g266 x) = f (g265 x) @[simp] axiom s266 (x : Prop) : f (g267 x) = f (g266 x) @[simp] axiom s267 (x : Prop) : f (g268 x) = f (g267 x) @[simp] axiom s268 (x : Prop) : f (g269 x) = f (g268 x) @[simp] axiom s269 (x : Prop) : f (g270 x) = f (g269 x) @[simp] axiom s270 (x : Prop) : f (g271 x) = f (g270 x) @[simp] axiom s271 (x : Prop) : f (g272 x) = f (g271 x) @[simp] axiom s272 (x : Prop) : f (g273 x) = f (g272 x) @[simp] axiom s273 (x : Prop) : f (g274 x) = f (g273 x) @[simp] axiom s274 (x : Prop) : f (g275 x) = f (g274 x) @[simp] axiom s275 (x : Prop) : f (g276 x) = f (g275 x) @[simp] axiom s276 (x : Prop) : f (g277 x) = f (g276 x) @[simp] axiom s277 (x : Prop) : f (g278 x) = f (g277 x) @[simp] axiom s278 (x : Prop) : f (g279 x) = f (g278 x) @[simp] axiom s279 (x : Prop) : f (g280 x) = f (g279 x) @[simp] axiom s280 (x : Prop) : f (g281 x) = f (g280 x) @[simp] axiom s281 (x : Prop) : f (g282 x) = f (g281 x) @[simp] axiom s282 (x : Prop) : f (g283 x) = f (g282 x) @[simp] axiom s283 (x : Prop) : f (g284 x) = f (g283 x) @[simp] axiom s284 (x : Prop) : f (g285 x) = f (g284 x) @[simp] axiom s285 (x : Prop) : f (g286 x) = f (g285 x) @[simp] axiom s286 (x : Prop) : f (g287 x) = f (g286 x) @[simp] axiom s287 (x : Prop) : f (g288 x) = f (g287 x) @[simp] axiom s288 (x : Prop) : f (g289 x) = f (g288 x) @[simp] axiom s289 (x : Prop) : f (g290 x) = f (g289 x) @[simp] axiom s290 (x : Prop) : f (g291 x) = f (g290 x) @[simp] axiom s291 (x : Prop) : f (g292 x) = f (g291 x) @[simp] axiom s292 (x : Prop) : f (g293 x) = f (g292 x) @[simp] axiom s293 (x : Prop) : f (g294 x) = f (g293 x) @[simp] axiom s294 (x : Prop) : f (g295 x) = f (g294 x) @[simp] axiom s295 (x : Prop) : f (g296 x) = f (g295 x) @[simp] axiom s296 (x : Prop) : f (g297 x) = f (g296 x) @[simp] axiom s297 (x : Prop) : f (g298 x) = f (g297 x) @[simp] axiom s298 (x : Prop) : f (g299 x) = f (g298 x) @[simp] axiom s299 (x : Prop) : f (g300 x) = f (g299 x) @[simp] axiom s300 (x : Prop) : f (g301 x) = f (g300 x) @[simp] axiom s301 (x : Prop) : f (g302 x) = f (g301 x) @[simp] axiom s302 (x : Prop) : f (g303 x) = f (g302 x) @[simp] axiom s303 (x : Prop) : f (g304 x) = f (g303 x) @[simp] axiom s304 (x : Prop) : f (g305 x) = f (g304 x) @[simp] axiom s305 (x : Prop) : f (g306 x) = f (g305 x) @[simp] axiom s306 (x : Prop) : f (g307 x) = f (g306 x) @[simp] axiom s307 (x : Prop) : f (g308 x) = f (g307 x) @[simp] axiom s308 (x : Prop) : f (g309 x) = f (g308 x) @[simp] axiom s309 (x : Prop) : f (g310 x) = f (g309 x) @[simp] axiom s310 (x : Prop) : f (g311 x) = f (g310 x) @[simp] axiom s311 (x : Prop) : f (g312 x) = f (g311 x) @[simp] axiom s312 (x : Prop) : f (g313 x) = f (g312 x) @[simp] axiom s313 (x : Prop) : f (g314 x) = f (g313 x) @[simp] axiom s314 (x : Prop) : f (g315 x) = f (g314 x) @[simp] axiom s315 (x : Prop) : f (g316 x) = f (g315 x) @[simp] axiom s316 (x : Prop) : f (g317 x) = f (g316 x) @[simp] axiom s317 (x : Prop) : f (g318 x) = f (g317 x) @[simp] axiom s318 (x : Prop) : f (g319 x) = f (g318 x) @[simp] axiom s319 (x : Prop) : f (g320 x) = f (g319 x) @[simp] axiom s320 (x : Prop) : f (g321 x) = f (g320 x) @[simp] axiom s321 (x : Prop) : f (g322 x) = f (g321 x) @[simp] axiom s322 (x : Prop) : f (g323 x) = f (g322 x) @[simp] axiom s323 (x : Prop) : f (g324 x) = f (g323 x) @[simp] axiom s324 (x : Prop) : f (g325 x) = f (g324 x) @[simp] axiom s325 (x : Prop) : f (g326 x) = f (g325 x) @[simp] axiom s326 (x : Prop) : f (g327 x) = f (g326 x) @[simp] axiom s327 (x : Prop) : f (g328 x) = f (g327 x) @[simp] axiom s328 (x : Prop) : f (g329 x) = f (g328 x) @[simp] axiom s329 (x : Prop) : f (g330 x) = f (g329 x) @[simp] axiom s330 (x : Prop) : f (g331 x) = f (g330 x) @[simp] axiom s331 (x : Prop) : f (g332 x) = f (g331 x) @[simp] axiom s332 (x : Prop) : f (g333 x) = f (g332 x) @[simp] axiom s333 (x : Prop) : f (g334 x) = f (g333 x) @[simp] axiom s334 (x : Prop) : f (g335 x) = f (g334 x) @[simp] axiom s335 (x : Prop) : f (g336 x) = f (g335 x) @[simp] axiom s336 (x : Prop) : f (g337 x) = f (g336 x) @[simp] axiom s337 (x : Prop) : f (g338 x) = f (g337 x) @[simp] axiom s338 (x : Prop) : f (g339 x) = f (g338 x) @[simp] axiom s339 (x : Prop) : f (g340 x) = f (g339 x) @[simp] axiom s340 (x : Prop) : f (g341 x) = f (g340 x) @[simp] axiom s341 (x : Prop) : f (g342 x) = f (g341 x) @[simp] axiom s342 (x : Prop) : f (g343 x) = f (g342 x) @[simp] axiom s343 (x : Prop) : f (g344 x) = f (g343 x) @[simp] axiom s344 (x : Prop) : f (g345 x) = f (g344 x) @[simp] axiom s345 (x : Prop) : f (g346 x) = f (g345 x) @[simp] axiom s346 (x : Prop) : f (g347 x) = f (g346 x) @[simp] axiom s347 (x : Prop) : f (g348 x) = f (g347 x) @[simp] axiom s348 (x : Prop) : f (g349 x) = f (g348 x) @[simp] axiom s349 (x : Prop) : f (g350 x) = f (g349 x) @[simp] axiom s350 (x : Prop) : f (g351 x) = f (g350 x) @[simp] axiom s351 (x : Prop) : f (g352 x) = f (g351 x) @[simp] axiom s352 (x : Prop) : f (g353 x) = f (g352 x) @[simp] axiom s353 (x : Prop) : f (g354 x) = f (g353 x) @[simp] axiom s354 (x : Prop) : f (g355 x) = f (g354 x) @[simp] axiom s355 (x : Prop) : f (g356 x) = f (g355 x) @[simp] axiom s356 (x : Prop) : f (g357 x) = f (g356 x) @[simp] axiom s357 (x : Prop) : f (g358 x) = f (g357 x) @[simp] axiom s358 (x : Prop) : f (g359 x) = f (g358 x) @[simp] axiom s359 (x : Prop) : f (g360 x) = f (g359 x) @[simp] axiom s360 (x : Prop) : f (g361 x) = f (g360 x) @[simp] axiom s361 (x : Prop) : f (g362 x) = f (g361 x) @[simp] axiom s362 (x : Prop) : f (g363 x) = f (g362 x) @[simp] axiom s363 (x : Prop) : f (g364 x) = f (g363 x) @[simp] axiom s364 (x : Prop) : f (g365 x) = f (g364 x) @[simp] axiom s365 (x : Prop) : f (g366 x) = f (g365 x) @[simp] axiom s366 (x : Prop) : f (g367 x) = f (g366 x) @[simp] axiom s367 (x : Prop) : f (g368 x) = f (g367 x) @[simp] axiom s368 (x : Prop) : f (g369 x) = f (g368 x) @[simp] axiom s369 (x : Prop) : f (g370 x) = f (g369 x) @[simp] axiom s370 (x : Prop) : f (g371 x) = f (g370 x) @[simp] axiom s371 (x : Prop) : f (g372 x) = f (g371 x) @[simp] axiom s372 (x : Prop) : f (g373 x) = f (g372 x) @[simp] axiom s373 (x : Prop) : f (g374 x) = f (g373 x) @[simp] axiom s374 (x : Prop) : f (g375 x) = f (g374 x) @[simp] axiom s375 (x : Prop) : f (g376 x) = f (g375 x) @[simp] axiom s376 (x : Prop) : f (g377 x) = f (g376 x) @[simp] axiom s377 (x : Prop) : f (g378 x) = f (g377 x) @[simp] axiom s378 (x : Prop) : f (g379 x) = f (g378 x) @[simp] axiom s379 (x : Prop) : f (g380 x) = f (g379 x) @[simp] axiom s380 (x : Prop) : f (g381 x) = f (g380 x) @[simp] axiom s381 (x : Prop) : f (g382 x) = f (g381 x) @[simp] axiom s382 (x : Prop) : f (g383 x) = f (g382 x) @[simp] axiom s383 (x : Prop) : f (g384 x) = f (g383 x) @[simp] axiom s384 (x : Prop) : f (g385 x) = f (g384 x) @[simp] axiom s385 (x : Prop) : f (g386 x) = f (g385 x) @[simp] axiom s386 (x : Prop) : f (g387 x) = f (g386 x) @[simp] axiom s387 (x : Prop) : f (g388 x) = f (g387 x) @[simp] axiom s388 (x : Prop) : f (g389 x) = f (g388 x) @[simp] axiom s389 (x : Prop) : f (g390 x) = f (g389 x) @[simp] axiom s390 (x : Prop) : f (g391 x) = f (g390 x) @[simp] axiom s391 (x : Prop) : f (g392 x) = f (g391 x) @[simp] axiom s392 (x : Prop) : f (g393 x) = f (g392 x) @[simp] axiom s393 (x : Prop) : f (g394 x) = f (g393 x) @[simp] axiom s394 (x : Prop) : f (g395 x) = f (g394 x) @[simp] axiom s395 (x : Prop) : f (g396 x) = f (g395 x) @[simp] axiom s396 (x : Prop) : f (g397 x) = f (g396 x) @[simp] axiom s397 (x : Prop) : f (g398 x) = f (g397 x) @[simp] axiom s398 (x : Prop) : f (g399 x) = f (g398 x) @[simp] axiom s399 (x : Prop) : f (g400 x) = f (g399 x) @[simp] axiom s400 (x : Prop) : f (g401 x) = f (g400 x) @[simp] axiom s401 (x : Prop) : f (g402 x) = f (g401 x) @[simp] axiom s402 (x : Prop) : f (g403 x) = f (g402 x) @[simp] axiom s403 (x : Prop) : f (g404 x) = f (g403 x) @[simp] axiom s404 (x : Prop) : f (g405 x) = f (g404 x) @[simp] axiom s405 (x : Prop) : f (g406 x) = f (g405 x) @[simp] axiom s406 (x : Prop) : f (g407 x) = f (g406 x) @[simp] axiom s407 (x : Prop) : f (g408 x) = f (g407 x) @[simp] axiom s408 (x : Prop) : f (g409 x) = f (g408 x) @[simp] axiom s409 (x : Prop) : f (g410 x) = f (g409 x) @[simp] axiom s410 (x : Prop) : f (g411 x) = f (g410 x) @[simp] axiom s411 (x : Prop) : f (g412 x) = f (g411 x) @[simp] axiom s412 (x : Prop) : f (g413 x) = f (g412 x) @[simp] axiom s413 (x : Prop) : f (g414 x) = f (g413 x) @[simp] axiom s414 (x : Prop) : f (g415 x) = f (g414 x) @[simp] axiom s415 (x : Prop) : f (g416 x) = f (g415 x) @[simp] axiom s416 (x : Prop) : f (g417 x) = f (g416 x) @[simp] axiom s417 (x : Prop) : f (g418 x) = f (g417 x) @[simp] axiom s418 (x : Prop) : f (g419 x) = f (g418 x) @[simp] axiom s419 (x : Prop) : f (g420 x) = f (g419 x) @[simp] axiom s420 (x : Prop) : f (g421 x) = f (g420 x) @[simp] axiom s421 (x : Prop) : f (g422 x) = f (g421 x) @[simp] axiom s422 (x : Prop) : f (g423 x) = f (g422 x) @[simp] axiom s423 (x : Prop) : f (g424 x) = f (g423 x) @[simp] axiom s424 (x : Prop) : f (g425 x) = f (g424 x) @[simp] axiom s425 (x : Prop) : f (g426 x) = f (g425 x) @[simp] axiom s426 (x : Prop) : f (g427 x) = f (g426 x) @[simp] axiom s427 (x : Prop) : f (g428 x) = f (g427 x) @[simp] axiom s428 (x : Prop) : f (g429 x) = f (g428 x) @[simp] axiom s429 (x : Prop) : f (g430 x) = f (g429 x) @[simp] axiom s430 (x : Prop) : f (g431 x) = f (g430 x) @[simp] axiom s431 (x : Prop) : f (g432 x) = f (g431 x) @[simp] axiom s432 (x : Prop) : f (g433 x) = f (g432 x) @[simp] axiom s433 (x : Prop) : f (g434 x) = f (g433 x) @[simp] axiom s434 (x : Prop) : f (g435 x) = f (g434 x) @[simp] axiom s435 (x : Prop) : f (g436 x) = f (g435 x) @[simp] axiom s436 (x : Prop) : f (g437 x) = f (g436 x) @[simp] axiom s437 (x : Prop) : f (g438 x) = f (g437 x) @[simp] axiom s438 (x : Prop) : f (g439 x) = f (g438 x) @[simp] axiom s439 (x : Prop) : f (g440 x) = f (g439 x) @[simp] axiom s440 (x : Prop) : f (g441 x) = f (g440 x) @[simp] axiom s441 (x : Prop) : f (g442 x) = f (g441 x) @[simp] axiom s442 (x : Prop) : f (g443 x) = f (g442 x) @[simp] axiom s443 (x : Prop) : f (g444 x) = f (g443 x) @[simp] axiom s444 (x : Prop) : f (g445 x) = f (g444 x) @[simp] axiom s445 (x : Prop) : f (g446 x) = f (g445 x) @[simp] axiom s446 (x : Prop) : f (g447 x) = f (g446 x) @[simp] axiom s447 (x : Prop) : f (g448 x) = f (g447 x) @[simp] axiom s448 (x : Prop) : f (g449 x) = f (g448 x) @[simp] axiom s449 (x : Prop) : f (g450 x) = f (g449 x) @[simp] axiom s450 (x : Prop) : f (g451 x) = f (g450 x) @[simp] axiom s451 (x : Prop) : f (g452 x) = f (g451 x) @[simp] axiom s452 (x : Prop) : f (g453 x) = f (g452 x) @[simp] axiom s453 (x : Prop) : f (g454 x) = f (g453 x) @[simp] axiom s454 (x : Prop) : f (g455 x) = f (g454 x) @[simp] axiom s455 (x : Prop) : f (g456 x) = f (g455 x) @[simp] axiom s456 (x : Prop) : f (g457 x) = f (g456 x) @[simp] axiom s457 (x : Prop) : f (g458 x) = f (g457 x) @[simp] axiom s458 (x : Prop) : f (g459 x) = f (g458 x) @[simp] axiom s459 (x : Prop) : f (g460 x) = f (g459 x) @[simp] axiom s460 (x : Prop) : f (g461 x) = f (g460 x) @[simp] axiom s461 (x : Prop) : f (g462 x) = f (g461 x) @[simp] axiom s462 (x : Prop) : f (g463 x) = f (g462 x) @[simp] axiom s463 (x : Prop) : f (g464 x) = f (g463 x) @[simp] axiom s464 (x : Prop) : f (g465 x) = f (g464 x) @[simp] axiom s465 (x : Prop) : f (g466 x) = f (g465 x) @[simp] axiom s466 (x : Prop) : f (g467 x) = f (g466 x) @[simp] axiom s467 (x : Prop) : f (g468 x) = f (g467 x) @[simp] axiom s468 (x : Prop) : f (g469 x) = f (g468 x) @[simp] axiom s469 (x : Prop) : f (g470 x) = f (g469 x) @[simp] axiom s470 (x : Prop) : f (g471 x) = f (g470 x) @[simp] axiom s471 (x : Prop) : f (g472 x) = f (g471 x) @[simp] axiom s472 (x : Prop) : f (g473 x) = f (g472 x) @[simp] axiom s473 (x : Prop) : f (g474 x) = f (g473 x) @[simp] axiom s474 (x : Prop) : f (g475 x) = f (g474 x) @[simp] axiom s475 (x : Prop) : f (g476 x) = f (g475 x) @[simp] axiom s476 (x : Prop) : f (g477 x) = f (g476 x) @[simp] axiom s477 (x : Prop) : f (g478 x) = f (g477 x) @[simp] axiom s478 (x : Prop) : f (g479 x) = f (g478 x) @[simp] axiom s479 (x : Prop) : f (g480 x) = f (g479 x) @[simp] axiom s480 (x : Prop) : f (g481 x) = f (g480 x) @[simp] axiom s481 (x : Prop) : f (g482 x) = f (g481 x) @[simp] axiom s482 (x : Prop) : f (g483 x) = f (g482 x) @[simp] axiom s483 (x : Prop) : f (g484 x) = f (g483 x) @[simp] axiom s484 (x : Prop) : f (g485 x) = f (g484 x) @[simp] axiom s485 (x : Prop) : f (g486 x) = f (g485 x) @[simp] axiom s486 (x : Prop) : f (g487 x) = f (g486 x) @[simp] axiom s487 (x : Prop) : f (g488 x) = f (g487 x) @[simp] axiom s488 (x : Prop) : f (g489 x) = f (g488 x) @[simp] axiom s489 (x : Prop) : f (g490 x) = f (g489 x) @[simp] axiom s490 (x : Prop) : f (g491 x) = f (g490 x) @[simp] axiom s491 (x : Prop) : f (g492 x) = f (g491 x) @[simp] axiom s492 (x : Prop) : f (g493 x) = f (g492 x) @[simp] axiom s493 (x : Prop) : f (g494 x) = f (g493 x) @[simp] axiom s494 (x : Prop) : f (g495 x) = f (g494 x) @[simp] axiom s495 (x : Prop) : f (g496 x) = f (g495 x) @[simp] axiom s496 (x : Prop) : f (g497 x) = f (g496 x) @[simp] axiom s497 (x : Prop) : f (g498 x) = f (g497 x) @[simp] axiom s498 (x : Prop) : f (g499 x) = f (g498 x) @[simp] axiom s499 (x : Prop) : f (g500 x) = f (g499 x) @[simp] axiom s500 (x : Prop) : f (g501 x) = f (g500 x) @[simp] axiom s501 (x : Prop) : f (g502 x) = f (g501 x) @[simp] axiom s502 (x : Prop) : f (g503 x) = f (g502 x) @[simp] axiom s503 (x : Prop) : f (g504 x) = f (g503 x) @[simp] axiom s504 (x : Prop) : f (g505 x) = f (g504 x) @[simp] axiom s505 (x : Prop) : f (g506 x) = f (g505 x) @[simp] axiom s506 (x : Prop) : f (g507 x) = f (g506 x) @[simp] axiom s507 (x : Prop) : f (g508 x) = f (g507 x) @[simp] axiom s508 (x : Prop) : f (g509 x) = f (g508 x) @[simp] axiom s509 (x : Prop) : f (g510 x) = f (g509 x) @[simp] axiom s510 (x : Prop) : f (g511 x) = f (g510 x) @[simp] axiom s511 (x : Prop) : f (g512 x) = f (g511 x) @[simp] axiom s512 (x : Prop) : f (g513 x) = f (g512 x) @[simp] axiom s513 (x : Prop) : f (g514 x) = f (g513 x) @[simp] axiom s514 (x : Prop) : f (g515 x) = f (g514 x) @[simp] axiom s515 (x : Prop) : f (g516 x) = f (g515 x) @[simp] axiom s516 (x : Prop) : f (g517 x) = f (g516 x) @[simp] axiom s517 (x : Prop) : f (g518 x) = f (g517 x) @[simp] axiom s518 (x : Prop) : f (g519 x) = f (g518 x) @[simp] axiom s519 (x : Prop) : f (g520 x) = f (g519 x) @[simp] axiom s520 (x : Prop) : f (g521 x) = f (g520 x) @[simp] axiom s521 (x : Prop) : f (g522 x) = f (g521 x) @[simp] axiom s522 (x : Prop) : f (g523 x) = f (g522 x) @[simp] axiom s523 (x : Prop) : f (g524 x) = f (g523 x) @[simp] axiom s524 (x : Prop) : f (g525 x) = f (g524 x) @[simp] axiom s525 (x : Prop) : f (g526 x) = f (g525 x) @[simp] axiom s526 (x : Prop) : f (g527 x) = f (g526 x) @[simp] axiom s527 (x : Prop) : f (g528 x) = f (g527 x) @[simp] axiom s528 (x : Prop) : f (g529 x) = f (g528 x) @[simp] axiom s529 (x : Prop) : f (g530 x) = f (g529 x) @[simp] axiom s530 (x : Prop) : f (g531 x) = f (g530 x) @[simp] axiom s531 (x : Prop) : f (g532 x) = f (g531 x) @[simp] axiom s532 (x : Prop) : f (g533 x) = f (g532 x) @[simp] axiom s533 (x : Prop) : f (g534 x) = f (g533 x) @[simp] axiom s534 (x : Prop) : f (g535 x) = f (g534 x) @[simp] axiom s535 (x : Prop) : f (g536 x) = f (g535 x) @[simp] axiom s536 (x : Prop) : f (g537 x) = f (g536 x) @[simp] axiom s537 (x : Prop) : f (g538 x) = f (g537 x) @[simp] axiom s538 (x : Prop) : f (g539 x) = f (g538 x) @[simp] axiom s539 (x : Prop) : f (g540 x) = f (g539 x) @[simp] axiom s540 (x : Prop) : f (g541 x) = f (g540 x) @[simp] axiom s541 (x : Prop) : f (g542 x) = f (g541 x) @[simp] axiom s542 (x : Prop) : f (g543 x) = f (g542 x) @[simp] axiom s543 (x : Prop) : f (g544 x) = f (g543 x) @[simp] axiom s544 (x : Prop) : f (g545 x) = f (g544 x) @[simp] axiom s545 (x : Prop) : f (g546 x) = f (g545 x) @[simp] axiom s546 (x : Prop) : f (g547 x) = f (g546 x) @[simp] axiom s547 (x : Prop) : f (g548 x) = f (g547 x) @[simp] axiom s548 (x : Prop) : f (g549 x) = f (g548 x) @[simp] axiom s549 (x : Prop) : f (g550 x) = f (g549 x) @[simp] axiom s550 (x : Prop) : f (g551 x) = f (g550 x) @[simp] axiom s551 (x : Prop) : f (g552 x) = f (g551 x) @[simp] axiom s552 (x : Prop) : f (g553 x) = f (g552 x) @[simp] axiom s553 (x : Prop) : f (g554 x) = f (g553 x) @[simp] axiom s554 (x : Prop) : f (g555 x) = f (g554 x) @[simp] axiom s555 (x : Prop) : f (g556 x) = f (g555 x) @[simp] axiom s556 (x : Prop) : f (g557 x) = f (g556 x) @[simp] axiom s557 (x : Prop) : f (g558 x) = f (g557 x) @[simp] axiom s558 (x : Prop) : f (g559 x) = f (g558 x) @[simp] axiom s559 (x : Prop) : f (g560 x) = f (g559 x) @[simp] axiom s560 (x : Prop) : f (g561 x) = f (g560 x) @[simp] axiom s561 (x : Prop) : f (g562 x) = f (g561 x) @[simp] axiom s562 (x : Prop) : f (g563 x) = f (g562 x) @[simp] axiom s563 (x : Prop) : f (g564 x) = f (g563 x) @[simp] axiom s564 (x : Prop) : f (g565 x) = f (g564 x) @[simp] axiom s565 (x : Prop) : f (g566 x) = f (g565 x) @[simp] axiom s566 (x : Prop) : f (g567 x) = f (g566 x) @[simp] axiom s567 (x : Prop) : f (g568 x) = f (g567 x) @[simp] axiom s568 (x : Prop) : f (g569 x) = f (g568 x) @[simp] axiom s569 (x : Prop) : f (g570 x) = f (g569 x) @[simp] axiom s570 (x : Prop) : f (g571 x) = f (g570 x) @[simp] axiom s571 (x : Prop) : f (g572 x) = f (g571 x) @[simp] axiom s572 (x : Prop) : f (g573 x) = f (g572 x) @[simp] axiom s573 (x : Prop) : f (g574 x) = f (g573 x) @[simp] axiom s574 (x : Prop) : f (g575 x) = f (g574 x) @[simp] axiom s575 (x : Prop) : f (g576 x) = f (g575 x) @[simp] axiom s576 (x : Prop) : f (g577 x) = f (g576 x) @[simp] axiom s577 (x : Prop) : f (g578 x) = f (g577 x) @[simp] axiom s578 (x : Prop) : f (g579 x) = f (g578 x) @[simp] axiom s579 (x : Prop) : f (g580 x) = f (g579 x) @[simp] axiom s580 (x : Prop) : f (g581 x) = f (g580 x) @[simp] axiom s581 (x : Prop) : f (g582 x) = f (g581 x) @[simp] axiom s582 (x : Prop) : f (g583 x) = f (g582 x) @[simp] axiom s583 (x : Prop) : f (g584 x) = f (g583 x) @[simp] axiom s584 (x : Prop) : f (g585 x) = f (g584 x) @[simp] axiom s585 (x : Prop) : f (g586 x) = f (g585 x) @[simp] axiom s586 (x : Prop) : f (g587 x) = f (g586 x) @[simp] axiom s587 (x : Prop) : f (g588 x) = f (g587 x) @[simp] axiom s588 (x : Prop) : f (g589 x) = f (g588 x) @[simp] axiom s589 (x : Prop) : f (g590 x) = f (g589 x) @[simp] axiom s590 (x : Prop) : f (g591 x) = f (g590 x) @[simp] axiom s591 (x : Prop) : f (g592 x) = f (g591 x) @[simp] axiom s592 (x : Prop) : f (g593 x) = f (g592 x) @[simp] axiom s593 (x : Prop) : f (g594 x) = f (g593 x) @[simp] axiom s594 (x : Prop) : f (g595 x) = f (g594 x) @[simp] axiom s595 (x : Prop) : f (g596 x) = f (g595 x) @[simp] axiom s596 (x : Prop) : f (g597 x) = f (g596 x) @[simp] axiom s597 (x : Prop) : f (g598 x) = f (g597 x) @[simp] axiom s598 (x : Prop) : f (g599 x) = f (g598 x) @[simp] axiom s599 (x : Prop) : f (g600 x) = f (g599 x) @[simp] axiom s600 (x : Prop) : f (g601 x) = f (g600 x) @[simp] axiom s601 (x : Prop) : f (g602 x) = f (g601 x) @[simp] axiom s602 (x : Prop) : f (g603 x) = f (g602 x) @[simp] axiom s603 (x : Prop) : f (g604 x) = f (g603 x) @[simp] axiom s604 (x : Prop) : f (g605 x) = f (g604 x) @[simp] axiom s605 (x : Prop) : f (g606 x) = f (g605 x) @[simp] axiom s606 (x : Prop) : f (g607 x) = f (g606 x) @[simp] axiom s607 (x : Prop) : f (g608 x) = f (g607 x) @[simp] axiom s608 (x : Prop) : f (g609 x) = f (g608 x) @[simp] axiom s609 (x : Prop) : f (g610 x) = f (g609 x) @[simp] axiom s610 (x : Prop) : f (g611 x) = f (g610 x) @[simp] axiom s611 (x : Prop) : f (g612 x) = f (g611 x) @[simp] axiom s612 (x : Prop) : f (g613 x) = f (g612 x) @[simp] axiom s613 (x : Prop) : f (g614 x) = f (g613 x) @[simp] axiom s614 (x : Prop) : f (g615 x) = f (g614 x) @[simp] axiom s615 (x : Prop) : f (g616 x) = f (g615 x) @[simp] axiom s616 (x : Prop) : f (g617 x) = f (g616 x) @[simp] axiom s617 (x : Prop) : f (g618 x) = f (g617 x) @[simp] axiom s618 (x : Prop) : f (g619 x) = f (g618 x) @[simp] axiom s619 (x : Prop) : f (g620 x) = f (g619 x) @[simp] axiom s620 (x : Prop) : f (g621 x) = f (g620 x) @[simp] axiom s621 (x : Prop) : f (g622 x) = f (g621 x) @[simp] axiom s622 (x : Prop) : f (g623 x) = f (g622 x) @[simp] axiom s623 (x : Prop) : f (g624 x) = f (g623 x) @[simp] axiom s624 (x : Prop) : f (g625 x) = f (g624 x) @[simp] axiom s625 (x : Prop) : f (g626 x) = f (g625 x) @[simp] axiom s626 (x : Prop) : f (g627 x) = f (g626 x) @[simp] axiom s627 (x : Prop) : f (g628 x) = f (g627 x) @[simp] axiom s628 (x : Prop) : f (g629 x) = f (g628 x) @[simp] axiom s629 (x : Prop) : f (g630 x) = f (g629 x) @[simp] axiom s630 (x : Prop) : f (g631 x) = f (g630 x) @[simp] axiom s631 (x : Prop) : f (g632 x) = f (g631 x) @[simp] axiom s632 (x : Prop) : f (g633 x) = f (g632 x) @[simp] axiom s633 (x : Prop) : f (g634 x) = f (g633 x) @[simp] axiom s634 (x : Prop) : f (g635 x) = f (g634 x) @[simp] axiom s635 (x : Prop) : f (g636 x) = f (g635 x) @[simp] axiom s636 (x : Prop) : f (g637 x) = f (g636 x) @[simp] axiom s637 (x : Prop) : f (g638 x) = f (g637 x) @[simp] axiom s638 (x : Prop) : f (g639 x) = f (g638 x) @[simp] axiom s639 (x : Prop) : f (g640 x) = f (g639 x) @[simp] axiom s640 (x : Prop) : f (g641 x) = f (g640 x) @[simp] axiom s641 (x : Prop) : f (g642 x) = f (g641 x) @[simp] axiom s642 (x : Prop) : f (g643 x) = f (g642 x) @[simp] axiom s643 (x : Prop) : f (g644 x) = f (g643 x) @[simp] axiom s644 (x : Prop) : f (g645 x) = f (g644 x) @[simp] axiom s645 (x : Prop) : f (g646 x) = f (g645 x) @[simp] axiom s646 (x : Prop) : f (g647 x) = f (g646 x) @[simp] axiom s647 (x : Prop) : f (g648 x) = f (g647 x) @[simp] axiom s648 (x : Prop) : f (g649 x) = f (g648 x) @[simp] axiom s649 (x : Prop) : f (g650 x) = f (g649 x) @[simp] axiom s650 (x : Prop) : f (g651 x) = f (g650 x) @[simp] axiom s651 (x : Prop) : f (g652 x) = f (g651 x) @[simp] axiom s652 (x : Prop) : f (g653 x) = f (g652 x) @[simp] axiom s653 (x : Prop) : f (g654 x) = f (g653 x) @[simp] axiom s654 (x : Prop) : f (g655 x) = f (g654 x) @[simp] axiom s655 (x : Prop) : f (g656 x) = f (g655 x) @[simp] axiom s656 (x : Prop) : f (g657 x) = f (g656 x) @[simp] axiom s657 (x : Prop) : f (g658 x) = f (g657 x) @[simp] axiom s658 (x : Prop) : f (g659 x) = f (g658 x) @[simp] axiom s659 (x : Prop) : f (g660 x) = f (g659 x) @[simp] axiom s660 (x : Prop) : f (g661 x) = f (g660 x) @[simp] axiom s661 (x : Prop) : f (g662 x) = f (g661 x) @[simp] axiom s662 (x : Prop) : f (g663 x) = f (g662 x) @[simp] axiom s663 (x : Prop) : f (g664 x) = f (g663 x) @[simp] axiom s664 (x : Prop) : f (g665 x) = f (g664 x) @[simp] axiom s665 (x : Prop) : f (g666 x) = f (g665 x) @[simp] axiom s666 (x : Prop) : f (g667 x) = f (g666 x) @[simp] axiom s667 (x : Prop) : f (g668 x) = f (g667 x) @[simp] axiom s668 (x : Prop) : f (g669 x) = f (g668 x) @[simp] axiom s669 (x : Prop) : f (g670 x) = f (g669 x) @[simp] axiom s670 (x : Prop) : f (g671 x) = f (g670 x) @[simp] axiom s671 (x : Prop) : f (g672 x) = f (g671 x) @[simp] axiom s672 (x : Prop) : f (g673 x) = f (g672 x) @[simp] axiom s673 (x : Prop) : f (g674 x) = f (g673 x) @[simp] axiom s674 (x : Prop) : f (g675 x) = f (g674 x) @[simp] axiom s675 (x : Prop) : f (g676 x) = f (g675 x) @[simp] axiom s676 (x : Prop) : f (g677 x) = f (g676 x) @[simp] axiom s677 (x : Prop) : f (g678 x) = f (g677 x) @[simp] axiom s678 (x : Prop) : f (g679 x) = f (g678 x) @[simp] axiom s679 (x : Prop) : f (g680 x) = f (g679 x) @[simp] axiom s680 (x : Prop) : f (g681 x) = f (g680 x) @[simp] axiom s681 (x : Prop) : f (g682 x) = f (g681 x) @[simp] axiom s682 (x : Prop) : f (g683 x) = f (g682 x) @[simp] axiom s683 (x : Prop) : f (g684 x) = f (g683 x) @[simp] axiom s684 (x : Prop) : f (g685 x) = f (g684 x) @[simp] axiom s685 (x : Prop) : f (g686 x) = f (g685 x) @[simp] axiom s686 (x : Prop) : f (g687 x) = f (g686 x) @[simp] axiom s687 (x : Prop) : f (g688 x) = f (g687 x) @[simp] axiom s688 (x : Prop) : f (g689 x) = f (g688 x) @[simp] axiom s689 (x : Prop) : f (g690 x) = f (g689 x) @[simp] axiom s690 (x : Prop) : f (g691 x) = f (g690 x) @[simp] axiom s691 (x : Prop) : f (g692 x) = f (g691 x) @[simp] axiom s692 (x : Prop) : f (g693 x) = f (g692 x) @[simp] axiom s693 (x : Prop) : f (g694 x) = f (g693 x) @[simp] axiom s694 (x : Prop) : f (g695 x) = f (g694 x) @[simp] axiom s695 (x : Prop) : f (g696 x) = f (g695 x) @[simp] axiom s696 (x : Prop) : f (g697 x) = f (g696 x) @[simp] axiom s697 (x : Prop) : f (g698 x) = f (g697 x) @[simp] axiom s698 (x : Prop) : f (g699 x) = f (g698 x) @[simp] axiom s699 (x : Prop) : f (g700 x) = f (g699 x) @[simp] axiom s700 (x : Prop) : f (g701 x) = f (g700 x) @[simp] axiom s701 (x : Prop) : f (g702 x) = f (g701 x) @[simp] axiom s702 (x : Prop) : f (g703 x) = f (g702 x) @[simp] axiom s703 (x : Prop) : f (g704 x) = f (g703 x) @[simp] axiom s704 (x : Prop) : f (g705 x) = f (g704 x) @[simp] axiom s705 (x : Prop) : f (g706 x) = f (g705 x) @[simp] axiom s706 (x : Prop) : f (g707 x) = f (g706 x) @[simp] axiom s707 (x : Prop) : f (g708 x) = f (g707 x) @[simp] axiom s708 (x : Prop) : f (g709 x) = f (g708 x) @[simp] axiom s709 (x : Prop) : f (g710 x) = f (g709 x) @[simp] axiom s710 (x : Prop) : f (g711 x) = f (g710 x) @[simp] axiom s711 (x : Prop) : f (g712 x) = f (g711 x) @[simp] axiom s712 (x : Prop) : f (g713 x) = f (g712 x) @[simp] axiom s713 (x : Prop) : f (g714 x) = f (g713 x) @[simp] axiom s714 (x : Prop) : f (g715 x) = f (g714 x) @[simp] axiom s715 (x : Prop) : f (g716 x) = f (g715 x) @[simp] axiom s716 (x : Prop) : f (g717 x) = f (g716 x) @[simp] axiom s717 (x : Prop) : f (g718 x) = f (g717 x) @[simp] axiom s718 (x : Prop) : f (g719 x) = f (g718 x) @[simp] axiom s719 (x : Prop) : f (g720 x) = f (g719 x) @[simp] axiom s720 (x : Prop) : f (g721 x) = f (g720 x) @[simp] axiom s721 (x : Prop) : f (g722 x) = f (g721 x) @[simp] axiom s722 (x : Prop) : f (g723 x) = f (g722 x) @[simp] axiom s723 (x : Prop) : f (g724 x) = f (g723 x) @[simp] axiom s724 (x : Prop) : f (g725 x) = f (g724 x) @[simp] axiom s725 (x : Prop) : f (g726 x) = f (g725 x) @[simp] axiom s726 (x : Prop) : f (g727 x) = f (g726 x) @[simp] axiom s727 (x : Prop) : f (g728 x) = f (g727 x) @[simp] axiom s728 (x : Prop) : f (g729 x) = f (g728 x) @[simp] axiom s729 (x : Prop) : f (g730 x) = f (g729 x) @[simp] axiom s730 (x : Prop) : f (g731 x) = f (g730 x) @[simp] axiom s731 (x : Prop) : f (g732 x) = f (g731 x) @[simp] axiom s732 (x : Prop) : f (g733 x) = f (g732 x) @[simp] axiom s733 (x : Prop) : f (g734 x) = f (g733 x) @[simp] axiom s734 (x : Prop) : f (g735 x) = f (g734 x) @[simp] axiom s735 (x : Prop) : f (g736 x) = f (g735 x) @[simp] axiom s736 (x : Prop) : f (g737 x) = f (g736 x) @[simp] axiom s737 (x : Prop) : f (g738 x) = f (g737 x) @[simp] axiom s738 (x : Prop) : f (g739 x) = f (g738 x) @[simp] axiom s739 (x : Prop) : f (g740 x) = f (g739 x) @[simp] axiom s740 (x : Prop) : f (g741 x) = f (g740 x) @[simp] axiom s741 (x : Prop) : f (g742 x) = f (g741 x) @[simp] axiom s742 (x : Prop) : f (g743 x) = f (g742 x) @[simp] axiom s743 (x : Prop) : f (g744 x) = f (g743 x) @[simp] axiom s744 (x : Prop) : f (g745 x) = f (g744 x) @[simp] axiom s745 (x : Prop) : f (g746 x) = f (g745 x) @[simp] axiom s746 (x : Prop) : f (g747 x) = f (g746 x) @[simp] axiom s747 (x : Prop) : f (g748 x) = f (g747 x) @[simp] axiom s748 (x : Prop) : f (g749 x) = f (g748 x) @[simp] axiom s749 (x : Prop) : f (g750 x) = f (g749 x) @[simp] axiom s750 (x : Prop) : f (g751 x) = f (g750 x) @[simp] axiom s751 (x : Prop) : f (g752 x) = f (g751 x) @[simp] axiom s752 (x : Prop) : f (g753 x) = f (g752 x) @[simp] axiom s753 (x : Prop) : f (g754 x) = f (g753 x) @[simp] axiom s754 (x : Prop) : f (g755 x) = f (g754 x) @[simp] axiom s755 (x : Prop) : f (g756 x) = f (g755 x) @[simp] axiom s756 (x : Prop) : f (g757 x) = f (g756 x) @[simp] axiom s757 (x : Prop) : f (g758 x) = f (g757 x) @[simp] axiom s758 (x : Prop) : f (g759 x) = f (g758 x) @[simp] axiom s759 (x : Prop) : f (g760 x) = f (g759 x) @[simp] axiom s760 (x : Prop) : f (g761 x) = f (g760 x) @[simp] axiom s761 (x : Prop) : f (g762 x) = f (g761 x) @[simp] axiom s762 (x : Prop) : f (g763 x) = f (g762 x) @[simp] axiom s763 (x : Prop) : f (g764 x) = f (g763 x) @[simp] axiom s764 (x : Prop) : f (g765 x) = f (g764 x) @[simp] axiom s765 (x : Prop) : f (g766 x) = f (g765 x) @[simp] axiom s766 (x : Prop) : f (g767 x) = f (g766 x) @[simp] axiom s767 (x : Prop) : f (g768 x) = f (g767 x) @[simp] axiom s768 (x : Prop) : f (g769 x) = f (g768 x) @[simp] axiom s769 (x : Prop) : f (g770 x) = f (g769 x) @[simp] axiom s770 (x : Prop) : f (g771 x) = f (g770 x) @[simp] axiom s771 (x : Prop) : f (g772 x) = f (g771 x) @[simp] axiom s772 (x : Prop) : f (g773 x) = f (g772 x) @[simp] axiom s773 (x : Prop) : f (g774 x) = f (g773 x) @[simp] axiom s774 (x : Prop) : f (g775 x) = f (g774 x) @[simp] axiom s775 (x : Prop) : f (g776 x) = f (g775 x) @[simp] axiom s776 (x : Prop) : f (g777 x) = f (g776 x) @[simp] axiom s777 (x : Prop) : f (g778 x) = f (g777 x) @[simp] axiom s778 (x : Prop) : f (g779 x) = f (g778 x) @[simp] axiom s779 (x : Prop) : f (g780 x) = f (g779 x) @[simp] axiom s780 (x : Prop) : f (g781 x) = f (g780 x) @[simp] axiom s781 (x : Prop) : f (g782 x) = f (g781 x) @[simp] axiom s782 (x : Prop) : f (g783 x) = f (g782 x) @[simp] axiom s783 (x : Prop) : f (g784 x) = f (g783 x) @[simp] axiom s784 (x : Prop) : f (g785 x) = f (g784 x) @[simp] axiom s785 (x : Prop) : f (g786 x) = f (g785 x) @[simp] axiom s786 (x : Prop) : f (g787 x) = f (g786 x) @[simp] axiom s787 (x : Prop) : f (g788 x) = f (g787 x) @[simp] axiom s788 (x : Prop) : f (g789 x) = f (g788 x) @[simp] axiom s789 (x : Prop) : f (g790 x) = f (g789 x) @[simp] axiom s790 (x : Prop) : f (g791 x) = f (g790 x) @[simp] axiom s791 (x : Prop) : f (g792 x) = f (g791 x) @[simp] axiom s792 (x : Prop) : f (g793 x) = f (g792 x) @[simp] axiom s793 (x : Prop) : f (g794 x) = f (g793 x) @[simp] axiom s794 (x : Prop) : f (g795 x) = f (g794 x) @[simp] axiom s795 (x : Prop) : f (g796 x) = f (g795 x) @[simp] axiom s796 (x : Prop) : f (g797 x) = f (g796 x) @[simp] axiom s797 (x : Prop) : f (g798 x) = f (g797 x) @[simp] axiom s798 (x : Prop) : f (g799 x) = f (g798 x) @[simp] axiom s799 (x : Prop) : f (g800 x) = f (g799 x) @[simp] axiom s800 (x : Prop) : f (g801 x) = f (g800 x) @[simp] axiom s801 (x : Prop) : f (g802 x) = f (g801 x) @[simp] axiom s802 (x : Prop) : f (g803 x) = f (g802 x) @[simp] axiom s803 (x : Prop) : f (g804 x) = f (g803 x) @[simp] axiom s804 (x : Prop) : f (g805 x) = f (g804 x) @[simp] axiom s805 (x : Prop) : f (g806 x) = f (g805 x) @[simp] axiom s806 (x : Prop) : f (g807 x) = f (g806 x) @[simp] axiom s807 (x : Prop) : f (g808 x) = f (g807 x) @[simp] axiom s808 (x : Prop) : f (g809 x) = f (g808 x) @[simp] axiom s809 (x : Prop) : f (g810 x) = f (g809 x) @[simp] axiom s810 (x : Prop) : f (g811 x) = f (g810 x) @[simp] axiom s811 (x : Prop) : f (g812 x) = f (g811 x) @[simp] axiom s812 (x : Prop) : f (g813 x) = f (g812 x) @[simp] axiom s813 (x : Prop) : f (g814 x) = f (g813 x) @[simp] axiom s814 (x : Prop) : f (g815 x) = f (g814 x) @[simp] axiom s815 (x : Prop) : f (g816 x) = f (g815 x) @[simp] axiom s816 (x : Prop) : f (g817 x) = f (g816 x) @[simp] axiom s817 (x : Prop) : f (g818 x) = f (g817 x) @[simp] axiom s818 (x : Prop) : f (g819 x) = f (g818 x) @[simp] axiom s819 (x : Prop) : f (g820 x) = f (g819 x) @[simp] axiom s820 (x : Prop) : f (g821 x) = f (g820 x) @[simp] axiom s821 (x : Prop) : f (g822 x) = f (g821 x) @[simp] axiom s822 (x : Prop) : f (g823 x) = f (g822 x) @[simp] axiom s823 (x : Prop) : f (g824 x) = f (g823 x) @[simp] axiom s824 (x : Prop) : f (g825 x) = f (g824 x) @[simp] axiom s825 (x : Prop) : f (g826 x) = f (g825 x) @[simp] axiom s826 (x : Prop) : f (g827 x) = f (g826 x) @[simp] axiom s827 (x : Prop) : f (g828 x) = f (g827 x) @[simp] axiom s828 (x : Prop) : f (g829 x) = f (g828 x) @[simp] axiom s829 (x : Prop) : f (g830 x) = f (g829 x) @[simp] axiom s830 (x : Prop) : f (g831 x) = f (g830 x) @[simp] axiom s831 (x : Prop) : f (g832 x) = f (g831 x) @[simp] axiom s832 (x : Prop) : f (g833 x) = f (g832 x) @[simp] axiom s833 (x : Prop) : f (g834 x) = f (g833 x) @[simp] axiom s834 (x : Prop) : f (g835 x) = f (g834 x) @[simp] axiom s835 (x : Prop) : f (g836 x) = f (g835 x) @[simp] axiom s836 (x : Prop) : f (g837 x) = f (g836 x) @[simp] axiom s837 (x : Prop) : f (g838 x) = f (g837 x) @[simp] axiom s838 (x : Prop) : f (g839 x) = f (g838 x) @[simp] axiom s839 (x : Prop) : f (g840 x) = f (g839 x) @[simp] axiom s840 (x : Prop) : f (g841 x) = f (g840 x) @[simp] axiom s841 (x : Prop) : f (g842 x) = f (g841 x) @[simp] axiom s842 (x : Prop) : f (g843 x) = f (g842 x) @[simp] axiom s843 (x : Prop) : f (g844 x) = f (g843 x) @[simp] axiom s844 (x : Prop) : f (g845 x) = f (g844 x) @[simp] axiom s845 (x : Prop) : f (g846 x) = f (g845 x) @[simp] axiom s846 (x : Prop) : f (g847 x) = f (g846 x) @[simp] axiom s847 (x : Prop) : f (g848 x) = f (g847 x) @[simp] axiom s848 (x : Prop) : f (g849 x) = f (g848 x) @[simp] axiom s849 (x : Prop) : f (g850 x) = f (g849 x) @[simp] axiom s850 (x : Prop) : f (g851 x) = f (g850 x) @[simp] axiom s851 (x : Prop) : f (g852 x) = f (g851 x) @[simp] axiom s852 (x : Prop) : f (g853 x) = f (g852 x) @[simp] axiom s853 (x : Prop) : f (g854 x) = f (g853 x) @[simp] axiom s854 (x : Prop) : f (g855 x) = f (g854 x) @[simp] axiom s855 (x : Prop) : f (g856 x) = f (g855 x) @[simp] axiom s856 (x : Prop) : f (g857 x) = f (g856 x) @[simp] axiom s857 (x : Prop) : f (g858 x) = f (g857 x) @[simp] axiom s858 (x : Prop) : f (g859 x) = f (g858 x) @[simp] axiom s859 (x : Prop) : f (g860 x) = f (g859 x) @[simp] axiom s860 (x : Prop) : f (g861 x) = f (g860 x) @[simp] axiom s861 (x : Prop) : f (g862 x) = f (g861 x) @[simp] axiom s862 (x : Prop) : f (g863 x) = f (g862 x) @[simp] axiom s863 (x : Prop) : f (g864 x) = f (g863 x) @[simp] axiom s864 (x : Prop) : f (g865 x) = f (g864 x) @[simp] axiom s865 (x : Prop) : f (g866 x) = f (g865 x) @[simp] axiom s866 (x : Prop) : f (g867 x) = f (g866 x) @[simp] axiom s867 (x : Prop) : f (g868 x) = f (g867 x) @[simp] axiom s868 (x : Prop) : f (g869 x) = f (g868 x) @[simp] axiom s869 (x : Prop) : f (g870 x) = f (g869 x) @[simp] axiom s870 (x : Prop) : f (g871 x) = f (g870 x) @[simp] axiom s871 (x : Prop) : f (g872 x) = f (g871 x) @[simp] axiom s872 (x : Prop) : f (g873 x) = f (g872 x) @[simp] axiom s873 (x : Prop) : f (g874 x) = f (g873 x) @[simp] axiom s874 (x : Prop) : f (g875 x) = f (g874 x) @[simp] axiom s875 (x : Prop) : f (g876 x) = f (g875 x) @[simp] axiom s876 (x : Prop) : f (g877 x) = f (g876 x) @[simp] axiom s877 (x : Prop) : f (g878 x) = f (g877 x) @[simp] axiom s878 (x : Prop) : f (g879 x) = f (g878 x) @[simp] axiom s879 (x : Prop) : f (g880 x) = f (g879 x) @[simp] axiom s880 (x : Prop) : f (g881 x) = f (g880 x) @[simp] axiom s881 (x : Prop) : f (g882 x) = f (g881 x) @[simp] axiom s882 (x : Prop) : f (g883 x) = f (g882 x) @[simp] axiom s883 (x : Prop) : f (g884 x) = f (g883 x) @[simp] axiom s884 (x : Prop) : f (g885 x) = f (g884 x) @[simp] axiom s885 (x : Prop) : f (g886 x) = f (g885 x) @[simp] axiom s886 (x : Prop) : f (g887 x) = f (g886 x) @[simp] axiom s887 (x : Prop) : f (g888 x) = f (g887 x) @[simp] axiom s888 (x : Prop) : f (g889 x) = f (g888 x) @[simp] axiom s889 (x : Prop) : f (g890 x) = f (g889 x) @[simp] axiom s890 (x : Prop) : f (g891 x) = f (g890 x) @[simp] axiom s891 (x : Prop) : f (g892 x) = f (g891 x) @[simp] axiom s892 (x : Prop) : f (g893 x) = f (g892 x) @[simp] axiom s893 (x : Prop) : f (g894 x) = f (g893 x) @[simp] axiom s894 (x : Prop) : f (g895 x) = f (g894 x) @[simp] axiom s895 (x : Prop) : f (g896 x) = f (g895 x) @[simp] axiom s896 (x : Prop) : f (g897 x) = f (g896 x) @[simp] axiom s897 (x : Prop) : f (g898 x) = f (g897 x) @[simp] axiom s898 (x : Prop) : f (g899 x) = f (g898 x) @[simp] axiom s899 (x : Prop) : f (g900 x) = f (g899 x) @[simp] axiom s900 (x : Prop) : f (g901 x) = f (g900 x) @[simp] axiom s901 (x : Prop) : f (g902 x) = f (g901 x) @[simp] axiom s902 (x : Prop) : f (g903 x) = f (g902 x) @[simp] axiom s903 (x : Prop) : f (g904 x) = f (g903 x) @[simp] axiom s904 (x : Prop) : f (g905 x) = f (g904 x) @[simp] axiom s905 (x : Prop) : f (g906 x) = f (g905 x) @[simp] axiom s906 (x : Prop) : f (g907 x) = f (g906 x) @[simp] axiom s907 (x : Prop) : f (g908 x) = f (g907 x) @[simp] axiom s908 (x : Prop) : f (g909 x) = f (g908 x) @[simp] axiom s909 (x : Prop) : f (g910 x) = f (g909 x) @[simp] axiom s910 (x : Prop) : f (g911 x) = f (g910 x) @[simp] axiom s911 (x : Prop) : f (g912 x) = f (g911 x) @[simp] axiom s912 (x : Prop) : f (g913 x) = f (g912 x) @[simp] axiom s913 (x : Prop) : f (g914 x) = f (g913 x) @[simp] axiom s914 (x : Prop) : f (g915 x) = f (g914 x) @[simp] axiom s915 (x : Prop) : f (g916 x) = f (g915 x) @[simp] axiom s916 (x : Prop) : f (g917 x) = f (g916 x) @[simp] axiom s917 (x : Prop) : f (g918 x) = f (g917 x) @[simp] axiom s918 (x : Prop) : f (g919 x) = f (g918 x) @[simp] axiom s919 (x : Prop) : f (g920 x) = f (g919 x) @[simp] axiom s920 (x : Prop) : f (g921 x) = f (g920 x) @[simp] axiom s921 (x : Prop) : f (g922 x) = f (g921 x) @[simp] axiom s922 (x : Prop) : f (g923 x) = f (g922 x) @[simp] axiom s923 (x : Prop) : f (g924 x) = f (g923 x) @[simp] axiom s924 (x : Prop) : f (g925 x) = f (g924 x) @[simp] axiom s925 (x : Prop) : f (g926 x) = f (g925 x) @[simp] axiom s926 (x : Prop) : f (g927 x) = f (g926 x) @[simp] axiom s927 (x : Prop) : f (g928 x) = f (g927 x) @[simp] axiom s928 (x : Prop) : f (g929 x) = f (g928 x) @[simp] axiom s929 (x : Prop) : f (g930 x) = f (g929 x) @[simp] axiom s930 (x : Prop) : f (g931 x) = f (g930 x) @[simp] axiom s931 (x : Prop) : f (g932 x) = f (g931 x) @[simp] axiom s932 (x : Prop) : f (g933 x) = f (g932 x) @[simp] axiom s933 (x : Prop) : f (g934 x) = f (g933 x) @[simp] axiom s934 (x : Prop) : f (g935 x) = f (g934 x) @[simp] axiom s935 (x : Prop) : f (g936 x) = f (g935 x) @[simp] axiom s936 (x : Prop) : f (g937 x) = f (g936 x) @[simp] axiom s937 (x : Prop) : f (g938 x) = f (g937 x) @[simp] axiom s938 (x : Prop) : f (g939 x) = f (g938 x) @[simp] axiom s939 (x : Prop) : f (g940 x) = f (g939 x) @[simp] axiom s940 (x : Prop) : f (g941 x) = f (g940 x) @[simp] axiom s941 (x : Prop) : f (g942 x) = f (g941 x) @[simp] axiom s942 (x : Prop) : f (g943 x) = f (g942 x) @[simp] axiom s943 (x : Prop) : f (g944 x) = f (g943 x) @[simp] axiom s944 (x : Prop) : f (g945 x) = f (g944 x) @[simp] axiom s945 (x : Prop) : f (g946 x) = f (g945 x) @[simp] axiom s946 (x : Prop) : f (g947 x) = f (g946 x) @[simp] axiom s947 (x : Prop) : f (g948 x) = f (g947 x) @[simp] axiom s948 (x : Prop) : f (g949 x) = f (g948 x) @[simp] axiom s949 (x : Prop) : f (g950 x) = f (g949 x) @[simp] axiom s950 (x : Prop) : f (g951 x) = f (g950 x) @[simp] axiom s951 (x : Prop) : f (g952 x) = f (g951 x) @[simp] axiom s952 (x : Prop) : f (g953 x) = f (g952 x) @[simp] axiom s953 (x : Prop) : f (g954 x) = f (g953 x) @[simp] axiom s954 (x : Prop) : f (g955 x) = f (g954 x) @[simp] axiom s955 (x : Prop) : f (g956 x) = f (g955 x) @[simp] axiom s956 (x : Prop) : f (g957 x) = f (g956 x) @[simp] axiom s957 (x : Prop) : f (g958 x) = f (g957 x) @[simp] axiom s958 (x : Prop) : f (g959 x) = f (g958 x) @[simp] axiom s959 (x : Prop) : f (g960 x) = f (g959 x) @[simp] axiom s960 (x : Prop) : f (g961 x) = f (g960 x) @[simp] axiom s961 (x : Prop) : f (g962 x) = f (g961 x) @[simp] axiom s962 (x : Prop) : f (g963 x) = f (g962 x) @[simp] axiom s963 (x : Prop) : f (g964 x) = f (g963 x) @[simp] axiom s964 (x : Prop) : f (g965 x) = f (g964 x) @[simp] axiom s965 (x : Prop) : f (g966 x) = f (g965 x) @[simp] axiom s966 (x : Prop) : f (g967 x) = f (g966 x) @[simp] axiom s967 (x : Prop) : f (g968 x) = f (g967 x) @[simp] axiom s968 (x : Prop) : f (g969 x) = f (g968 x) @[simp] axiom s969 (x : Prop) : f (g970 x) = f (g969 x) @[simp] axiom s970 (x : Prop) : f (g971 x) = f (g970 x) @[simp] axiom s971 (x : Prop) : f (g972 x) = f (g971 x) @[simp] axiom s972 (x : Prop) : f (g973 x) = f (g972 x) @[simp] axiom s973 (x : Prop) : f (g974 x) = f (g973 x) @[simp] axiom s974 (x : Prop) : f (g975 x) = f (g974 x) @[simp] axiom s975 (x : Prop) : f (g976 x) = f (g975 x) @[simp] axiom s976 (x : Prop) : f (g977 x) = f (g976 x) @[simp] axiom s977 (x : Prop) : f (g978 x) = f (g977 x) @[simp] axiom s978 (x : Prop) : f (g979 x) = f (g978 x) @[simp] axiom s979 (x : Prop) : f (g980 x) = f (g979 x) @[simp] axiom s980 (x : Prop) : f (g981 x) = f (g980 x) @[simp] axiom s981 (x : Prop) : f (g982 x) = f (g981 x) @[simp] axiom s982 (x : Prop) : f (g983 x) = f (g982 x) @[simp] axiom s983 (x : Prop) : f (g984 x) = f (g983 x) @[simp] axiom s984 (x : Prop) : f (g985 x) = f (g984 x) @[simp] axiom s985 (x : Prop) : f (g986 x) = f (g985 x) @[simp] axiom s986 (x : Prop) : f (g987 x) = f (g986 x) @[simp] axiom s987 (x : Prop) : f (g988 x) = f (g987 x) @[simp] axiom s988 (x : Prop) : f (g989 x) = f (g988 x) @[simp] axiom s989 (x : Prop) : f (g990 x) = f (g989 x) @[simp] axiom s990 (x : Prop) : f (g991 x) = f (g990 x) @[simp] axiom s991 (x : Prop) : f (g992 x) = f (g991 x) @[simp] axiom s992 (x : Prop) : f (g993 x) = f (g992 x) @[simp] axiom s993 (x : Prop) : f (g994 x) = f (g993 x) @[simp] axiom s994 (x : Prop) : f (g995 x) = f (g994 x) @[simp] axiom s995 (x : Prop) : f (g996 x) = f (g995 x) @[simp] axiom s996 (x : Prop) : f (g997 x) = f (g996 x) @[simp] axiom s997 (x : Prop) : f (g998 x) = f (g997 x) @[simp] axiom s998 (x : Prop) : f (g999 x) = f (g998 x) @[simp] axiom s999 (x : Prop) : f (g1000 x) = f (g999 x) @[simp] axiom s1000 (x : Prop) : f (g1001 x) = f (g1000 x) @[simp] axiom s1001 (x : Prop) : f (g1002 x) = f (g1001 x) @[simp] axiom s1002 (x : Prop) : f (g1003 x) = f (g1002 x) @[simp] axiom s1003 (x : Prop) : f (g1004 x) = f (g1003 x) @[simp] axiom s1004 (x : Prop) : f (g1005 x) = f (g1004 x) @[simp] axiom s1005 (x : Prop) : f (g1006 x) = f (g1005 x) @[simp] axiom s1006 (x : Prop) : f (g1007 x) = f (g1006 x) @[simp] axiom s1007 (x : Prop) : f (g1008 x) = f (g1007 x) @[simp] axiom s1008 (x : Prop) : f (g1009 x) = f (g1008 x) @[simp] axiom s1009 (x : Prop) : f (g1010 x) = f (g1009 x) @[simp] axiom s1010 (x : Prop) : f (g1011 x) = f (g1010 x) @[simp] axiom s1011 (x : Prop) : f (g1012 x) = f (g1011 x) @[simp] axiom s1012 (x : Prop) : f (g1013 x) = f (g1012 x) @[simp] axiom s1013 (x : Prop) : f (g1014 x) = f (g1013 x) @[simp] axiom s1014 (x : Prop) : f (g1015 x) = f (g1014 x) @[simp] axiom s1015 (x : Prop) : f (g1016 x) = f (g1015 x) @[simp] axiom s1016 (x : Prop) : f (g1017 x) = f (g1016 x) @[simp] axiom s1017 (x : Prop) : f (g1018 x) = f (g1017 x) @[simp] axiom s1018 (x : Prop) : f (g1019 x) = f (g1018 x) @[simp] axiom s1019 (x : Prop) : f (g1020 x) = f (g1019 x) @[simp] axiom s1020 (x : Prop) : f (g1021 x) = f (g1020 x) @[simp] axiom s1021 (x : Prop) : f (g1022 x) = f (g1021 x) @[simp] axiom s1022 (x : Prop) : f (g1023 x) = f (g1022 x) @[simp] axiom s1023 (x : Prop) : f (g1024 x) = f (g1023 x) @[simp] axiom s1024 (x : Prop) : f (g1025 x) = f (g1024 x) @[simp] axiom s1025 (x : Prop) : f (g1026 x) = f (g1025 x) @[simp] axiom s1026 (x : Prop) : f (g1027 x) = f (g1026 x) @[simp] axiom s1027 (x : Prop) : f (g1028 x) = f (g1027 x) @[simp] axiom s1028 (x : Prop) : f (g1029 x) = f (g1028 x) @[simp] axiom s1029 (x : Prop) : f (g1030 x) = f (g1029 x) @[simp] axiom s1030 (x : Prop) : f (g1031 x) = f (g1030 x) @[simp] axiom s1031 (x : Prop) : f (g1032 x) = f (g1031 x) @[simp] axiom s1032 (x : Prop) : f (g1033 x) = f (g1032 x) @[simp] axiom s1033 (x : Prop) : f (g1034 x) = f (g1033 x) @[simp] axiom s1034 (x : Prop) : f (g1035 x) = f (g1034 x) @[simp] axiom s1035 (x : Prop) : f (g1036 x) = f (g1035 x) @[simp] axiom s1036 (x : Prop) : f (g1037 x) = f (g1036 x) @[simp] axiom s1037 (x : Prop) : f (g1038 x) = f (g1037 x) @[simp] axiom s1038 (x : Prop) : f (g1039 x) = f (g1038 x) @[simp] axiom s1039 (x : Prop) : f (g1040 x) = f (g1039 x) @[simp] axiom s1040 (x : Prop) : f (g1041 x) = f (g1040 x) @[simp] axiom s1041 (x : Prop) : f (g1042 x) = f (g1041 x) @[simp] axiom s1042 (x : Prop) : f (g1043 x) = f (g1042 x) @[simp] axiom s1043 (x : Prop) : f (g1044 x) = f (g1043 x) @[simp] axiom s1044 (x : Prop) : f (g1045 x) = f (g1044 x) @[simp] axiom s1045 (x : Prop) : f (g1046 x) = f (g1045 x) @[simp] axiom s1046 (x : Prop) : f (g1047 x) = f (g1046 x) @[simp] axiom s1047 (x : Prop) : f (g1048 x) = f (g1047 x) @[simp] axiom s1048 (x : Prop) : f (g1049 x) = f (g1048 x) @[simp] axiom s1049 (x : Prop) : f (g1050 x) = f (g1049 x) @[simp] axiom s1050 (x : Prop) : f (g1051 x) = f (g1050 x) @[simp] axiom s1051 (x : Prop) : f (g1052 x) = f (g1051 x) @[simp] axiom s1052 (x : Prop) : f (g1053 x) = f (g1052 x) @[simp] axiom s1053 (x : Prop) : f (g1054 x) = f (g1053 x) @[simp] axiom s1054 (x : Prop) : f (g1055 x) = f (g1054 x) @[simp] axiom s1055 (x : Prop) : f (g1056 x) = f (g1055 x) @[simp] axiom s1056 (x : Prop) : f (g1057 x) = f (g1056 x) @[simp] axiom s1057 (x : Prop) : f (g1058 x) = f (g1057 x) @[simp] axiom s1058 (x : Prop) : f (g1059 x) = f (g1058 x) @[simp] axiom s1059 (x : Prop) : f (g1060 x) = f (g1059 x) @[simp] axiom s1060 (x : Prop) : f (g1061 x) = f (g1060 x) @[simp] axiom s1061 (x : Prop) : f (g1062 x) = f (g1061 x) @[simp] axiom s1062 (x : Prop) : f (g1063 x) = f (g1062 x) @[simp] axiom s1063 (x : Prop) : f (g1064 x) = f (g1063 x) @[simp] axiom s1064 (x : Prop) : f (g1065 x) = f (g1064 x) @[simp] axiom s1065 (x : Prop) : f (g1066 x) = f (g1065 x) @[simp] axiom s1066 (x : Prop) : f (g1067 x) = f (g1066 x) @[simp] axiom s1067 (x : Prop) : f (g1068 x) = f (g1067 x) @[simp] axiom s1068 (x : Prop) : f (g1069 x) = f (g1068 x) @[simp] axiom s1069 (x : Prop) : f (g1070 x) = f (g1069 x) @[simp] axiom s1070 (x : Prop) : f (g1071 x) = f (g1070 x) @[simp] axiom s1071 (x : Prop) : f (g1072 x) = f (g1071 x) @[simp] axiom s1072 (x : Prop) : f (g1073 x) = f (g1072 x) @[simp] axiom s1073 (x : Prop) : f (g1074 x) = f (g1073 x) @[simp] axiom s1074 (x : Prop) : f (g1075 x) = f (g1074 x) @[simp] axiom s1075 (x : Prop) : f (g1076 x) = f (g1075 x) @[simp] axiom s1076 (x : Prop) : f (g1077 x) = f (g1076 x) @[simp] axiom s1077 (x : Prop) : f (g1078 x) = f (g1077 x) @[simp] axiom s1078 (x : Prop) : f (g1079 x) = f (g1078 x) @[simp] axiom s1079 (x : Prop) : f (g1080 x) = f (g1079 x) @[simp] axiom s1080 (x : Prop) : f (g1081 x) = f (g1080 x) @[simp] axiom s1081 (x : Prop) : f (g1082 x) = f (g1081 x) @[simp] axiom s1082 (x : Prop) : f (g1083 x) = f (g1082 x) @[simp] axiom s1083 (x : Prop) : f (g1084 x) = f (g1083 x) @[simp] axiom s1084 (x : Prop) : f (g1085 x) = f (g1084 x) @[simp] axiom s1085 (x : Prop) : f (g1086 x) = f (g1085 x) @[simp] axiom s1086 (x : Prop) : f (g1087 x) = f (g1086 x) @[simp] axiom s1087 (x : Prop) : f (g1088 x) = f (g1087 x) @[simp] axiom s1088 (x : Prop) : f (g1089 x) = f (g1088 x) @[simp] axiom s1089 (x : Prop) : f (g1090 x) = f (g1089 x) @[simp] axiom s1090 (x : Prop) : f (g1091 x) = f (g1090 x) @[simp] axiom s1091 (x : Prop) : f (g1092 x) = f (g1091 x) @[simp] axiom s1092 (x : Prop) : f (g1093 x) = f (g1092 x) @[simp] axiom s1093 (x : Prop) : f (g1094 x) = f (g1093 x) @[simp] axiom s1094 (x : Prop) : f (g1095 x) = f (g1094 x) @[simp] axiom s1095 (x : Prop) : f (g1096 x) = f (g1095 x) @[simp] axiom s1096 (x : Prop) : f (g1097 x) = f (g1096 x) @[simp] axiom s1097 (x : Prop) : f (g1098 x) = f (g1097 x) @[simp] axiom s1098 (x : Prop) : f (g1099 x) = f (g1098 x) @[simp] axiom s1099 (x : Prop) : f (g1100 x) = f (g1099 x) @[simp] axiom s1100 (x : Prop) : f (g1101 x) = f (g1100 x) @[simp] axiom s1101 (x : Prop) : f (g1102 x) = f (g1101 x) @[simp] axiom s1102 (x : Prop) : f (g1103 x) = f (g1102 x) @[simp] axiom s1103 (x : Prop) : f (g1104 x) = f (g1103 x) @[simp] axiom s1104 (x : Prop) : f (g1105 x) = f (g1104 x) @[simp] axiom s1105 (x : Prop) : f (g1106 x) = f (g1105 x) @[simp] axiom s1106 (x : Prop) : f (g1107 x) = f (g1106 x) @[simp] axiom s1107 (x : Prop) : f (g1108 x) = f (g1107 x) @[simp] axiom s1108 (x : Prop) : f (g1109 x) = f (g1108 x) @[simp] axiom s1109 (x : Prop) : f (g1110 x) = f (g1109 x) @[simp] axiom s1110 (x : Prop) : f (g1111 x) = f (g1110 x) @[simp] axiom s1111 (x : Prop) : f (g1112 x) = f (g1111 x) @[simp] axiom s1112 (x : Prop) : f (g1113 x) = f (g1112 x) @[simp] axiom s1113 (x : Prop) : f (g1114 x) = f (g1113 x) @[simp] axiom s1114 (x : Prop) : f (g1115 x) = f (g1114 x) @[simp] axiom s1115 (x : Prop) : f (g1116 x) = f (g1115 x) @[simp] axiom s1116 (x : Prop) : f (g1117 x) = f (g1116 x) @[simp] axiom s1117 (x : Prop) : f (g1118 x) = f (g1117 x) @[simp] axiom s1118 (x : Prop) : f (g1119 x) = f (g1118 x) @[simp] axiom s1119 (x : Prop) : f (g1120 x) = f (g1119 x) @[simp] axiom s1120 (x : Prop) : f (g1121 x) = f (g1120 x) @[simp] axiom s1121 (x : Prop) : f (g1122 x) = f (g1121 x) @[simp] axiom s1122 (x : Prop) : f (g1123 x) = f (g1122 x) @[simp] axiom s1123 (x : Prop) : f (g1124 x) = f (g1123 x) @[simp] axiom s1124 (x : Prop) : f (g1125 x) = f (g1124 x) @[simp] axiom s1125 (x : Prop) : f (g1126 x) = f (g1125 x) @[simp] axiom s1126 (x : Prop) : f (g1127 x) = f (g1126 x) @[simp] axiom s1127 (x : Prop) : f (g1128 x) = f (g1127 x) @[simp] axiom s1128 (x : Prop) : f (g1129 x) = f (g1128 x) @[simp] axiom s1129 (x : Prop) : f (g1130 x) = f (g1129 x) @[simp] axiom s1130 (x : Prop) : f (g1131 x) = f (g1130 x) @[simp] axiom s1131 (x : Prop) : f (g1132 x) = f (g1131 x) @[simp] axiom s1132 (x : Prop) : f (g1133 x) = f (g1132 x) @[simp] axiom s1133 (x : Prop) : f (g1134 x) = f (g1133 x) @[simp] axiom s1134 (x : Prop) : f (g1135 x) = f (g1134 x) @[simp] axiom s1135 (x : Prop) : f (g1136 x) = f (g1135 x) @[simp] axiom s1136 (x : Prop) : f (g1137 x) = f (g1136 x) @[simp] axiom s1137 (x : Prop) : f (g1138 x) = f (g1137 x) @[simp] axiom s1138 (x : Prop) : f (g1139 x) = f (g1138 x) @[simp] axiom s1139 (x : Prop) : f (g1140 x) = f (g1139 x) @[simp] axiom s1140 (x : Prop) : f (g1141 x) = f (g1140 x) @[simp] axiom s1141 (x : Prop) : f (g1142 x) = f (g1141 x) @[simp] axiom s1142 (x : Prop) : f (g1143 x) = f (g1142 x) @[simp] axiom s1143 (x : Prop) : f (g1144 x) = f (g1143 x) @[simp] axiom s1144 (x : Prop) : f (g1145 x) = f (g1144 x) @[simp] axiom s1145 (x : Prop) : f (g1146 x) = f (g1145 x) @[simp] axiom s1146 (x : Prop) : f (g1147 x) = f (g1146 x) @[simp] axiom s1147 (x : Prop) : f (g1148 x) = f (g1147 x) @[simp] axiom s1148 (x : Prop) : f (g1149 x) = f (g1148 x) @[simp] axiom s1149 (x : Prop) : f (g1150 x) = f (g1149 x) @[simp] axiom s1150 (x : Prop) : f (g1151 x) = f (g1150 x) @[simp] axiom s1151 (x : Prop) : f (g1152 x) = f (g1151 x) @[simp] axiom s1152 (x : Prop) : f (g1153 x) = f (g1152 x) @[simp] axiom s1153 (x : Prop) : f (g1154 x) = f (g1153 x) @[simp] axiom s1154 (x : Prop) : f (g1155 x) = f (g1154 x) @[simp] axiom s1155 (x : Prop) : f (g1156 x) = f (g1155 x) @[simp] axiom s1156 (x : Prop) : f (g1157 x) = f (g1156 x) @[simp] axiom s1157 (x : Prop) : f (g1158 x) = f (g1157 x) @[simp] axiom s1158 (x : Prop) : f (g1159 x) = f (g1158 x) @[simp] axiom s1159 (x : Prop) : f (g1160 x) = f (g1159 x) @[simp] axiom s1160 (x : Prop) : f (g1161 x) = f (g1160 x) @[simp] axiom s1161 (x : Prop) : f (g1162 x) = f (g1161 x) @[simp] axiom s1162 (x : Prop) : f (g1163 x) = f (g1162 x) @[simp] axiom s1163 (x : Prop) : f (g1164 x) = f (g1163 x) @[simp] axiom s1164 (x : Prop) : f (g1165 x) = f (g1164 x) @[simp] axiom s1165 (x : Prop) : f (g1166 x) = f (g1165 x) @[simp] axiom s1166 (x : Prop) : f (g1167 x) = f (g1166 x) @[simp] axiom s1167 (x : Prop) : f (g1168 x) = f (g1167 x) @[simp] axiom s1168 (x : Prop) : f (g1169 x) = f (g1168 x) @[simp] axiom s1169 (x : Prop) : f (g1170 x) = f (g1169 x) @[simp] axiom s1170 (x : Prop) : f (g1171 x) = f (g1170 x) @[simp] axiom s1171 (x : Prop) : f (g1172 x) = f (g1171 x) @[simp] axiom s1172 (x : Prop) : f (g1173 x) = f (g1172 x) @[simp] axiom s1173 (x : Prop) : f (g1174 x) = f (g1173 x) @[simp] axiom s1174 (x : Prop) : f (g1175 x) = f (g1174 x) @[simp] axiom s1175 (x : Prop) : f (g1176 x) = f (g1175 x) @[simp] axiom s1176 (x : Prop) : f (g1177 x) = f (g1176 x) @[simp] axiom s1177 (x : Prop) : f (g1178 x) = f (g1177 x) @[simp] axiom s1178 (x : Prop) : f (g1179 x) = f (g1178 x) @[simp] axiom s1179 (x : Prop) : f (g1180 x) = f (g1179 x) @[simp] axiom s1180 (x : Prop) : f (g1181 x) = f (g1180 x) @[simp] axiom s1181 (x : Prop) : f (g1182 x) = f (g1181 x) @[simp] axiom s1182 (x : Prop) : f (g1183 x) = f (g1182 x) @[simp] axiom s1183 (x : Prop) : f (g1184 x) = f (g1183 x) @[simp] axiom s1184 (x : Prop) : f (g1185 x) = f (g1184 x) @[simp] axiom s1185 (x : Prop) : f (g1186 x) = f (g1185 x) @[simp] axiom s1186 (x : Prop) : f (g1187 x) = f (g1186 x) @[simp] axiom s1187 (x : Prop) : f (g1188 x) = f (g1187 x) @[simp] axiom s1188 (x : Prop) : f (g1189 x) = f (g1188 x) @[simp] axiom s1189 (x : Prop) : f (g1190 x) = f (g1189 x) @[simp] axiom s1190 (x : Prop) : f (g1191 x) = f (g1190 x) @[simp] axiom s1191 (x : Prop) : f (g1192 x) = f (g1191 x) @[simp] axiom s1192 (x : Prop) : f (g1193 x) = f (g1192 x) @[simp] axiom s1193 (x : Prop) : f (g1194 x) = f (g1193 x) @[simp] axiom s1194 (x : Prop) : f (g1195 x) = f (g1194 x) @[simp] axiom s1195 (x : Prop) : f (g1196 x) = f (g1195 x) @[simp] axiom s1196 (x : Prop) : f (g1197 x) = f (g1196 x) @[simp] axiom s1197 (x : Prop) : f (g1198 x) = f (g1197 x) @[simp] axiom s1198 (x : Prop) : f (g1199 x) = f (g1198 x) @[simp] axiom s1199 (x : Prop) : f (g1200 x) = f (g1199 x) @[simp] axiom s1200 (x : Prop) : f (g1201 x) = f (g1200 x) @[simp] axiom s1201 (x : Prop) : f (g1202 x) = f (g1201 x) @[simp] axiom s1202 (x : Prop) : f (g1203 x) = f (g1202 x) @[simp] axiom s1203 (x : Prop) : f (g1204 x) = f (g1203 x) @[simp] axiom s1204 (x : Prop) : f (g1205 x) = f (g1204 x) @[simp] axiom s1205 (x : Prop) : f (g1206 x) = f (g1205 x) @[simp] axiom s1206 (x : Prop) : f (g1207 x) = f (g1206 x) @[simp] axiom s1207 (x : Prop) : f (g1208 x) = f (g1207 x) @[simp] axiom s1208 (x : Prop) : f (g1209 x) = f (g1208 x) @[simp] axiom s1209 (x : Prop) : f (g1210 x) = f (g1209 x) @[simp] axiom s1210 (x : Prop) : f (g1211 x) = f (g1210 x) @[simp] axiom s1211 (x : Prop) : f (g1212 x) = f (g1211 x) @[simp] axiom s1212 (x : Prop) : f (g1213 x) = f (g1212 x) @[simp] axiom s1213 (x : Prop) : f (g1214 x) = f (g1213 x) @[simp] axiom s1214 (x : Prop) : f (g1215 x) = f (g1214 x) @[simp] axiom s1215 (x : Prop) : f (g1216 x) = f (g1215 x) @[simp] axiom s1216 (x : Prop) : f (g1217 x) = f (g1216 x) @[simp] axiom s1217 (x : Prop) : f (g1218 x) = f (g1217 x) @[simp] axiom s1218 (x : Prop) : f (g1219 x) = f (g1218 x) @[simp] axiom s1219 (x : Prop) : f (g1220 x) = f (g1219 x) @[simp] axiom s1220 (x : Prop) : f (g1221 x) = f (g1220 x) @[simp] axiom s1221 (x : Prop) : f (g1222 x) = f (g1221 x) @[simp] axiom s1222 (x : Prop) : f (g1223 x) = f (g1222 x) @[simp] axiom s1223 (x : Prop) : f (g1224 x) = f (g1223 x) @[simp] axiom s1224 (x : Prop) : f (g1225 x) = f (g1224 x) @[simp] axiom s1225 (x : Prop) : f (g1226 x) = f (g1225 x) @[simp] axiom s1226 (x : Prop) : f (g1227 x) = f (g1226 x) @[simp] axiom s1227 (x : Prop) : f (g1228 x) = f (g1227 x) @[simp] axiom s1228 (x : Prop) : f (g1229 x) = f (g1228 x) @[simp] axiom s1229 (x : Prop) : f (g1230 x) = f (g1229 x) @[simp] axiom s1230 (x : Prop) : f (g1231 x) = f (g1230 x) @[simp] axiom s1231 (x : Prop) : f (g1232 x) = f (g1231 x) @[simp] axiom s1232 (x : Prop) : f (g1233 x) = f (g1232 x) @[simp] axiom s1233 (x : Prop) : f (g1234 x) = f (g1233 x) @[simp] axiom s1234 (x : Prop) : f (g1235 x) = f (g1234 x) @[simp] axiom s1235 (x : Prop) : f (g1236 x) = f (g1235 x) @[simp] axiom s1236 (x : Prop) : f (g1237 x) = f (g1236 x) @[simp] axiom s1237 (x : Prop) : f (g1238 x) = f (g1237 x) @[simp] axiom s1238 (x : Prop) : f (g1239 x) = f (g1238 x) @[simp] axiom s1239 (x : Prop) : f (g1240 x) = f (g1239 x) @[simp] axiom s1240 (x : Prop) : f (g1241 x) = f (g1240 x) @[simp] axiom s1241 (x : Prop) : f (g1242 x) = f (g1241 x) @[simp] axiom s1242 (x : Prop) : f (g1243 x) = f (g1242 x) @[simp] axiom s1243 (x : Prop) : f (g1244 x) = f (g1243 x) @[simp] axiom s1244 (x : Prop) : f (g1245 x) = f (g1244 x) @[simp] axiom s1245 (x : Prop) : f (g1246 x) = f (g1245 x) @[simp] axiom s1246 (x : Prop) : f (g1247 x) = f (g1246 x) @[simp] axiom s1247 (x : Prop) : f (g1248 x) = f (g1247 x) @[simp] axiom s1248 (x : Prop) : f (g1249 x) = f (g1248 x) @[simp] axiom s1249 (x : Prop) : f (g1250 x) = f (g1249 x) @[simp] axiom s1250 (x : Prop) : f (g1251 x) = f (g1250 x) @[simp] axiom s1251 (x : Prop) : f (g1252 x) = f (g1251 x) @[simp] axiom s1252 (x : Prop) : f (g1253 x) = f (g1252 x) @[simp] axiom s1253 (x : Prop) : f (g1254 x) = f (g1253 x) @[simp] axiom s1254 (x : Prop) : f (g1255 x) = f (g1254 x) @[simp] axiom s1255 (x : Prop) : f (g1256 x) = f (g1255 x) @[simp] axiom s1256 (x : Prop) : f (g1257 x) = f (g1256 x) @[simp] axiom s1257 (x : Prop) : f (g1258 x) = f (g1257 x) @[simp] axiom s1258 (x : Prop) : f (g1259 x) = f (g1258 x) @[simp] axiom s1259 (x : Prop) : f (g1260 x) = f (g1259 x) @[simp] axiom s1260 (x : Prop) : f (g1261 x) = f (g1260 x) @[simp] axiom s1261 (x : Prop) : f (g1262 x) = f (g1261 x) @[simp] axiom s1262 (x : Prop) : f (g1263 x) = f (g1262 x) @[simp] axiom s1263 (x : Prop) : f (g1264 x) = f (g1263 x) @[simp] axiom s1264 (x : Prop) : f (g1265 x) = f (g1264 x) @[simp] axiom s1265 (x : Prop) : f (g1266 x) = f (g1265 x) @[simp] axiom s1266 (x : Prop) : f (g1267 x) = f (g1266 x) @[simp] axiom s1267 (x : Prop) : f (g1268 x) = f (g1267 x) @[simp] axiom s1268 (x : Prop) : f (g1269 x) = f (g1268 x) @[simp] axiom s1269 (x : Prop) : f (g1270 x) = f (g1269 x) @[simp] axiom s1270 (x : Prop) : f (g1271 x) = f (g1270 x) @[simp] axiom s1271 (x : Prop) : f (g1272 x) = f (g1271 x) @[simp] axiom s1272 (x : Prop) : f (g1273 x) = f (g1272 x) @[simp] axiom s1273 (x : Prop) : f (g1274 x) = f (g1273 x) @[simp] axiom s1274 (x : Prop) : f (g1275 x) = f (g1274 x) @[simp] axiom s1275 (x : Prop) : f (g1276 x) = f (g1275 x) @[simp] axiom s1276 (x : Prop) : f (g1277 x) = f (g1276 x) @[simp] axiom s1277 (x : Prop) : f (g1278 x) = f (g1277 x) @[simp] axiom s1278 (x : Prop) : f (g1279 x) = f (g1278 x) @[simp] axiom s1279 (x : Prop) : f (g1280 x) = f (g1279 x) @[simp] axiom s1280 (x : Prop) : f (g1281 x) = f (g1280 x) @[simp] axiom s1281 (x : Prop) : f (g1282 x) = f (g1281 x) @[simp] axiom s1282 (x : Prop) : f (g1283 x) = f (g1282 x) @[simp] axiom s1283 (x : Prop) : f (g1284 x) = f (g1283 x) @[simp] axiom s1284 (x : Prop) : f (g1285 x) = f (g1284 x) @[simp] axiom s1285 (x : Prop) : f (g1286 x) = f (g1285 x) @[simp] axiom s1286 (x : Prop) : f (g1287 x) = f (g1286 x) @[simp] axiom s1287 (x : Prop) : f (g1288 x) = f (g1287 x) @[simp] axiom s1288 (x : Prop) : f (g1289 x) = f (g1288 x) @[simp] axiom s1289 (x : Prop) : f (g1290 x) = f (g1289 x) @[simp] axiom s1290 (x : Prop) : f (g1291 x) = f (g1290 x) @[simp] axiom s1291 (x : Prop) : f (g1292 x) = f (g1291 x) @[simp] axiom s1292 (x : Prop) : f (g1293 x) = f (g1292 x) @[simp] axiom s1293 (x : Prop) : f (g1294 x) = f (g1293 x) @[simp] axiom s1294 (x : Prop) : f (g1295 x) = f (g1294 x) @[simp] axiom s1295 (x : Prop) : f (g1296 x) = f (g1295 x) @[simp] axiom s1296 (x : Prop) : f (g1297 x) = f (g1296 x) @[simp] axiom s1297 (x : Prop) : f (g1298 x) = f (g1297 x) @[simp] axiom s1298 (x : Prop) : f (g1299 x) = f (g1298 x) @[simp] axiom s1299 (x : Prop) : f (g1300 x) = f (g1299 x) @[simp] axiom s1300 (x : Prop) : f (g1301 x) = f (g1300 x) @[simp] axiom s1301 (x : Prop) : f (g1302 x) = f (g1301 x) @[simp] axiom s1302 (x : Prop) : f (g1303 x) = f (g1302 x) @[simp] axiom s1303 (x : Prop) : f (g1304 x) = f (g1303 x) @[simp] axiom s1304 (x : Prop) : f (g1305 x) = f (g1304 x) @[simp] axiom s1305 (x : Prop) : f (g1306 x) = f (g1305 x) @[simp] axiom s1306 (x : Prop) : f (g1307 x) = f (g1306 x) @[simp] axiom s1307 (x : Prop) : f (g1308 x) = f (g1307 x) @[simp] axiom s1308 (x : Prop) : f (g1309 x) = f (g1308 x) @[simp] axiom s1309 (x : Prop) : f (g1310 x) = f (g1309 x) @[simp] axiom s1310 (x : Prop) : f (g1311 x) = f (g1310 x) @[simp] axiom s1311 (x : Prop) : f (g1312 x) = f (g1311 x) @[simp] axiom s1312 (x : Prop) : f (g1313 x) = f (g1312 x) @[simp] axiom s1313 (x : Prop) : f (g1314 x) = f (g1313 x) @[simp] axiom s1314 (x : Prop) : f (g1315 x) = f (g1314 x) @[simp] axiom s1315 (x : Prop) : f (g1316 x) = f (g1315 x) @[simp] axiom s1316 (x : Prop) : f (g1317 x) = f (g1316 x) @[simp] axiom s1317 (x : Prop) : f (g1318 x) = f (g1317 x) @[simp] axiom s1318 (x : Prop) : f (g1319 x) = f (g1318 x) @[simp] axiom s1319 (x : Prop) : f (g1320 x) = f (g1319 x) @[simp] axiom s1320 (x : Prop) : f (g1321 x) = f (g1320 x) @[simp] axiom s1321 (x : Prop) : f (g1322 x) = f (g1321 x) @[simp] axiom s1322 (x : Prop) : f (g1323 x) = f (g1322 x) @[simp] axiom s1323 (x : Prop) : f (g1324 x) = f (g1323 x) @[simp] axiom s1324 (x : Prop) : f (g1325 x) = f (g1324 x) @[simp] axiom s1325 (x : Prop) : f (g1326 x) = f (g1325 x) @[simp] axiom s1326 (x : Prop) : f (g1327 x) = f (g1326 x) @[simp] axiom s1327 (x : Prop) : f (g1328 x) = f (g1327 x) @[simp] axiom s1328 (x : Prop) : f (g1329 x) = f (g1328 x) @[simp] axiom s1329 (x : Prop) : f (g1330 x) = f (g1329 x) @[simp] axiom s1330 (x : Prop) : f (g1331 x) = f (g1330 x) @[simp] axiom s1331 (x : Prop) : f (g1332 x) = f (g1331 x) @[simp] axiom s1332 (x : Prop) : f (g1333 x) = f (g1332 x) @[simp] axiom s1333 (x : Prop) : f (g1334 x) = f (g1333 x) @[simp] axiom s1334 (x : Prop) : f (g1335 x) = f (g1334 x) @[simp] axiom s1335 (x : Prop) : f (g1336 x) = f (g1335 x) @[simp] axiom s1336 (x : Prop) : f (g1337 x) = f (g1336 x) @[simp] axiom s1337 (x : Prop) : f (g1338 x) = f (g1337 x) @[simp] axiom s1338 (x : Prop) : f (g1339 x) = f (g1338 x) @[simp] axiom s1339 (x : Prop) : f (g1340 x) = f (g1339 x) @[simp] axiom s1340 (x : Prop) : f (g1341 x) = f (g1340 x) @[simp] axiom s1341 (x : Prop) : f (g1342 x) = f (g1341 x) @[simp] axiom s1342 (x : Prop) : f (g1343 x) = f (g1342 x) @[simp] axiom s1343 (x : Prop) : f (g1344 x) = f (g1343 x) @[simp] axiom s1344 (x : Prop) : f (g1345 x) = f (g1344 x) @[simp] axiom s1345 (x : Prop) : f (g1346 x) = f (g1345 x) @[simp] axiom s1346 (x : Prop) : f (g1347 x) = f (g1346 x) @[simp] axiom s1347 (x : Prop) : f (g1348 x) = f (g1347 x) @[simp] axiom s1348 (x : Prop) : f (g1349 x) = f (g1348 x) @[simp] axiom s1349 (x : Prop) : f (g1350 x) = f (g1349 x) @[simp] axiom s1350 (x : Prop) : f (g1351 x) = f (g1350 x) @[simp] axiom s1351 (x : Prop) : f (g1352 x) = f (g1351 x) @[simp] axiom s1352 (x : Prop) : f (g1353 x) = f (g1352 x) @[simp] axiom s1353 (x : Prop) : f (g1354 x) = f (g1353 x) @[simp] axiom s1354 (x : Prop) : f (g1355 x) = f (g1354 x) @[simp] axiom s1355 (x : Prop) : f (g1356 x) = f (g1355 x) @[simp] axiom s1356 (x : Prop) : f (g1357 x) = f (g1356 x) @[simp] axiom s1357 (x : Prop) : f (g1358 x) = f (g1357 x) @[simp] axiom s1358 (x : Prop) : f (g1359 x) = f (g1358 x) @[simp] axiom s1359 (x : Prop) : f (g1360 x) = f (g1359 x) @[simp] axiom s1360 (x : Prop) : f (g1361 x) = f (g1360 x) @[simp] axiom s1361 (x : Prop) : f (g1362 x) = f (g1361 x) @[simp] axiom s1362 (x : Prop) : f (g1363 x) = f (g1362 x) @[simp] axiom s1363 (x : Prop) : f (g1364 x) = f (g1363 x) @[simp] axiom s1364 (x : Prop) : f (g1365 x) = f (g1364 x) @[simp] axiom s1365 (x : Prop) : f (g1366 x) = f (g1365 x) @[simp] axiom s1366 (x : Prop) : f (g1367 x) = f (g1366 x) @[simp] axiom s1367 (x : Prop) : f (g1368 x) = f (g1367 x) @[simp] axiom s1368 (x : Prop) : f (g1369 x) = f (g1368 x) @[simp] axiom s1369 (x : Prop) : f (g1370 x) = f (g1369 x) @[simp] axiom s1370 (x : Prop) : f (g1371 x) = f (g1370 x) @[simp] axiom s1371 (x : Prop) : f (g1372 x) = f (g1371 x) @[simp] axiom s1372 (x : Prop) : f (g1373 x) = f (g1372 x) @[simp] axiom s1373 (x : Prop) : f (g1374 x) = f (g1373 x) @[simp] axiom s1374 (x : Prop) : f (g1375 x) = f (g1374 x) @[simp] axiom s1375 (x : Prop) : f (g1376 x) = f (g1375 x) @[simp] axiom s1376 (x : Prop) : f (g1377 x) = f (g1376 x) @[simp] axiom s1377 (x : Prop) : f (g1378 x) = f (g1377 x) @[simp] axiom s1378 (x : Prop) : f (g1379 x) = f (g1378 x) @[simp] axiom s1379 (x : Prop) : f (g1380 x) = f (g1379 x) @[simp] axiom s1380 (x : Prop) : f (g1381 x) = f (g1380 x) @[simp] axiom s1381 (x : Prop) : f (g1382 x) = f (g1381 x) @[simp] axiom s1382 (x : Prop) : f (g1383 x) = f (g1382 x) @[simp] axiom s1383 (x : Prop) : f (g1384 x) = f (g1383 x) @[simp] axiom s1384 (x : Prop) : f (g1385 x) = f (g1384 x) @[simp] axiom s1385 (x : Prop) : f (g1386 x) = f (g1385 x) @[simp] axiom s1386 (x : Prop) : f (g1387 x) = f (g1386 x) @[simp] axiom s1387 (x : Prop) : f (g1388 x) = f (g1387 x) @[simp] axiom s1388 (x : Prop) : f (g1389 x) = f (g1388 x) @[simp] axiom s1389 (x : Prop) : f (g1390 x) = f (g1389 x) @[simp] axiom s1390 (x : Prop) : f (g1391 x) = f (g1390 x) @[simp] axiom s1391 (x : Prop) : f (g1392 x) = f (g1391 x) @[simp] axiom s1392 (x : Prop) : f (g1393 x) = f (g1392 x) @[simp] axiom s1393 (x : Prop) : f (g1394 x) = f (g1393 x) @[simp] axiom s1394 (x : Prop) : f (g1395 x) = f (g1394 x) @[simp] axiom s1395 (x : Prop) : f (g1396 x) = f (g1395 x) @[simp] axiom s1396 (x : Prop) : f (g1397 x) = f (g1396 x) @[simp] axiom s1397 (x : Prop) : f (g1398 x) = f (g1397 x) @[simp] axiom s1398 (x : Prop) : f (g1399 x) = f (g1398 x) @[simp] axiom s1399 (x : Prop) : f (g1400 x) = f (g1399 x) @[simp] axiom s1400 (x : Prop) : f (g1401 x) = f (g1400 x) @[simp] axiom s1401 (x : Prop) : f (g1402 x) = f (g1401 x) @[simp] axiom s1402 (x : Prop) : f (g1403 x) = f (g1402 x) @[simp] axiom s1403 (x : Prop) : f (g1404 x) = f (g1403 x) @[simp] axiom s1404 (x : Prop) : f (g1405 x) = f (g1404 x) @[simp] axiom s1405 (x : Prop) : f (g1406 x) = f (g1405 x) @[simp] axiom s1406 (x : Prop) : f (g1407 x) = f (g1406 x) @[simp] axiom s1407 (x : Prop) : f (g1408 x) = f (g1407 x) @[simp] axiom s1408 (x : Prop) : f (g1409 x) = f (g1408 x) @[simp] axiom s1409 (x : Prop) : f (g1410 x) = f (g1409 x) @[simp] axiom s1410 (x : Prop) : f (g1411 x) = f (g1410 x) @[simp] axiom s1411 (x : Prop) : f (g1412 x) = f (g1411 x) @[simp] axiom s1412 (x : Prop) : f (g1413 x) = f (g1412 x) @[simp] axiom s1413 (x : Prop) : f (g1414 x) = f (g1413 x) @[simp] axiom s1414 (x : Prop) : f (g1415 x) = f (g1414 x) @[simp] axiom s1415 (x : Prop) : f (g1416 x) = f (g1415 x) @[simp] axiom s1416 (x : Prop) : f (g1417 x) = f (g1416 x) @[simp] axiom s1417 (x : Prop) : f (g1418 x) = f (g1417 x) @[simp] axiom s1418 (x : Prop) : f (g1419 x) = f (g1418 x) @[simp] axiom s1419 (x : Prop) : f (g1420 x) = f (g1419 x) @[simp] axiom s1420 (x : Prop) : f (g1421 x) = f (g1420 x) @[simp] axiom s1421 (x : Prop) : f (g1422 x) = f (g1421 x) @[simp] axiom s1422 (x : Prop) : f (g1423 x) = f (g1422 x) @[simp] axiom s1423 (x : Prop) : f (g1424 x) = f (g1423 x) @[simp] axiom s1424 (x : Prop) : f (g1425 x) = f (g1424 x) @[simp] axiom s1425 (x : Prop) : f (g1426 x) = f (g1425 x) @[simp] axiom s1426 (x : Prop) : f (g1427 x) = f (g1426 x) @[simp] axiom s1427 (x : Prop) : f (g1428 x) = f (g1427 x) @[simp] axiom s1428 (x : Prop) : f (g1429 x) = f (g1428 x) @[simp] axiom s1429 (x : Prop) : f (g1430 x) = f (g1429 x) @[simp] axiom s1430 (x : Prop) : f (g1431 x) = f (g1430 x) @[simp] axiom s1431 (x : Prop) : f (g1432 x) = f (g1431 x) @[simp] axiom s1432 (x : Prop) : f (g1433 x) = f (g1432 x) @[simp] axiom s1433 (x : Prop) : f (g1434 x) = f (g1433 x) @[simp] axiom s1434 (x : Prop) : f (g1435 x) = f (g1434 x) @[simp] axiom s1435 (x : Prop) : f (g1436 x) = f (g1435 x) @[simp] axiom s1436 (x : Prop) : f (g1437 x) = f (g1436 x) @[simp] axiom s1437 (x : Prop) : f (g1438 x) = f (g1437 x) @[simp] axiom s1438 (x : Prop) : f (g1439 x) = f (g1438 x) @[simp] axiom s1439 (x : Prop) : f (g1440 x) = f (g1439 x) @[simp] axiom s1440 (x : Prop) : f (g1441 x) = f (g1440 x) @[simp] axiom s1441 (x : Prop) : f (g1442 x) = f (g1441 x) @[simp] axiom s1442 (x : Prop) : f (g1443 x) = f (g1442 x) @[simp] axiom s1443 (x : Prop) : f (g1444 x) = f (g1443 x) @[simp] axiom s1444 (x : Prop) : f (g1445 x) = f (g1444 x) @[simp] axiom s1445 (x : Prop) : f (g1446 x) = f (g1445 x) @[simp] axiom s1446 (x : Prop) : f (g1447 x) = f (g1446 x) @[simp] axiom s1447 (x : Prop) : f (g1448 x) = f (g1447 x) @[simp] axiom s1448 (x : Prop) : f (g1449 x) = f (g1448 x) @[simp] axiom s1449 (x : Prop) : f (g1450 x) = f (g1449 x) @[simp] axiom s1450 (x : Prop) : f (g1451 x) = f (g1450 x) @[simp] axiom s1451 (x : Prop) : f (g1452 x) = f (g1451 x) @[simp] axiom s1452 (x : Prop) : f (g1453 x) = f (g1452 x) @[simp] axiom s1453 (x : Prop) : f (g1454 x) = f (g1453 x) @[simp] axiom s1454 (x : Prop) : f (g1455 x) = f (g1454 x) @[simp] axiom s1455 (x : Prop) : f (g1456 x) = f (g1455 x) @[simp] axiom s1456 (x : Prop) : f (g1457 x) = f (g1456 x) @[simp] axiom s1457 (x : Prop) : f (g1458 x) = f (g1457 x) @[simp] axiom s1458 (x : Prop) : f (g1459 x) = f (g1458 x) @[simp] axiom s1459 (x : Prop) : f (g1460 x) = f (g1459 x) @[simp] axiom s1460 (x : Prop) : f (g1461 x) = f (g1460 x) @[simp] axiom s1461 (x : Prop) : f (g1462 x) = f (g1461 x) @[simp] axiom s1462 (x : Prop) : f (g1463 x) = f (g1462 x) @[simp] axiom s1463 (x : Prop) : f (g1464 x) = f (g1463 x) @[simp] axiom s1464 (x : Prop) : f (g1465 x) = f (g1464 x) @[simp] axiom s1465 (x : Prop) : f (g1466 x) = f (g1465 x) @[simp] axiom s1466 (x : Prop) : f (g1467 x) = f (g1466 x) @[simp] axiom s1467 (x : Prop) : f (g1468 x) = f (g1467 x) @[simp] axiom s1468 (x : Prop) : f (g1469 x) = f (g1468 x) @[simp] axiom s1469 (x : Prop) : f (g1470 x) = f (g1469 x) @[simp] axiom s1470 (x : Prop) : f (g1471 x) = f (g1470 x) @[simp] axiom s1471 (x : Prop) : f (g1472 x) = f (g1471 x) @[simp] axiom s1472 (x : Prop) : f (g1473 x) = f (g1472 x) @[simp] axiom s1473 (x : Prop) : f (g1474 x) = f (g1473 x) @[simp] axiom s1474 (x : Prop) : f (g1475 x) = f (g1474 x) @[simp] axiom s1475 (x : Prop) : f (g1476 x) = f (g1475 x) @[simp] axiom s1476 (x : Prop) : f (g1477 x) = f (g1476 x) @[simp] axiom s1477 (x : Prop) : f (g1478 x) = f (g1477 x) @[simp] axiom s1478 (x : Prop) : f (g1479 x) = f (g1478 x) @[simp] axiom s1479 (x : Prop) : f (g1480 x) = f (g1479 x) @[simp] axiom s1480 (x : Prop) : f (g1481 x) = f (g1480 x) @[simp] axiom s1481 (x : Prop) : f (g1482 x) = f (g1481 x) @[simp] axiom s1482 (x : Prop) : f (g1483 x) = f (g1482 x) @[simp] axiom s1483 (x : Prop) : f (g1484 x) = f (g1483 x) @[simp] axiom s1484 (x : Prop) : f (g1485 x) = f (g1484 x) @[simp] axiom s1485 (x : Prop) : f (g1486 x) = f (g1485 x) @[simp] axiom s1486 (x : Prop) : f (g1487 x) = f (g1486 x) @[simp] axiom s1487 (x : Prop) : f (g1488 x) = f (g1487 x) @[simp] axiom s1488 (x : Prop) : f (g1489 x) = f (g1488 x) @[simp] axiom s1489 (x : Prop) : f (g1490 x) = f (g1489 x) @[simp] axiom s1490 (x : Prop) : f (g1491 x) = f (g1490 x) @[simp] axiom s1491 (x : Prop) : f (g1492 x) = f (g1491 x) @[simp] axiom s1492 (x : Prop) : f (g1493 x) = f (g1492 x) @[simp] axiom s1493 (x : Prop) : f (g1494 x) = f (g1493 x) @[simp] axiom s1494 (x : Prop) : f (g1495 x) = f (g1494 x) @[simp] axiom s1495 (x : Prop) : f (g1496 x) = f (g1495 x) @[simp] axiom s1496 (x : Prop) : f (g1497 x) = f (g1496 x) @[simp] axiom s1497 (x : Prop) : f (g1498 x) = f (g1497 x) @[simp] axiom s1498 (x : Prop) : f (g1499 x) = f (g1498 x) @[simp] axiom s1499 (x : Prop) : f (g1500 x) = f (g1499 x) @[simp] axiom s1500 (x : Prop) : f (g1501 x) = f (g1500 x) @[simp] axiom s1501 (x : Prop) : f (g1502 x) = f (g1501 x) @[simp] axiom s1502 (x : Prop) : f (g1503 x) = f (g1502 x) @[simp] axiom s1503 (x : Prop) : f (g1504 x) = f (g1503 x) @[simp] axiom s1504 (x : Prop) : f (g1505 x) = f (g1504 x) @[simp] axiom s1505 (x : Prop) : f (g1506 x) = f (g1505 x) @[simp] axiom s1506 (x : Prop) : f (g1507 x) = f (g1506 x) @[simp] axiom s1507 (x : Prop) : f (g1508 x) = f (g1507 x) @[simp] axiom s1508 (x : Prop) : f (g1509 x) = f (g1508 x) @[simp] axiom s1509 (x : Prop) : f (g1510 x) = f (g1509 x) @[simp] axiom s1510 (x : Prop) : f (g1511 x) = f (g1510 x) @[simp] axiom s1511 (x : Prop) : f (g1512 x) = f (g1511 x) @[simp] axiom s1512 (x : Prop) : f (g1513 x) = f (g1512 x) @[simp] axiom s1513 (x : Prop) : f (g1514 x) = f (g1513 x) @[simp] axiom s1514 (x : Prop) : f (g1515 x) = f (g1514 x) @[simp] axiom s1515 (x : Prop) : f (g1516 x) = f (g1515 x) @[simp] axiom s1516 (x : Prop) : f (g1517 x) = f (g1516 x) @[simp] axiom s1517 (x : Prop) : f (g1518 x) = f (g1517 x) @[simp] axiom s1518 (x : Prop) : f (g1519 x) = f (g1518 x) @[simp] axiom s1519 (x : Prop) : f (g1520 x) = f (g1519 x) @[simp] axiom s1520 (x : Prop) : f (g1521 x) = f (g1520 x) @[simp] axiom s1521 (x : Prop) : f (g1522 x) = f (g1521 x) @[simp] axiom s1522 (x : Prop) : f (g1523 x) = f (g1522 x) @[simp] axiom s1523 (x : Prop) : f (g1524 x) = f (g1523 x) @[simp] axiom s1524 (x : Prop) : f (g1525 x) = f (g1524 x) @[simp] axiom s1525 (x : Prop) : f (g1526 x) = f (g1525 x) @[simp] axiom s1526 (x : Prop) : f (g1527 x) = f (g1526 x) @[simp] axiom s1527 (x : Prop) : f (g1528 x) = f (g1527 x) @[simp] axiom s1528 (x : Prop) : f (g1529 x) = f (g1528 x) @[simp] axiom s1529 (x : Prop) : f (g1530 x) = f (g1529 x) @[simp] axiom s1530 (x : Prop) : f (g1531 x) = f (g1530 x) @[simp] axiom s1531 (x : Prop) : f (g1532 x) = f (g1531 x) @[simp] axiom s1532 (x : Prop) : f (g1533 x) = f (g1532 x) @[simp] axiom s1533 (x : Prop) : f (g1534 x) = f (g1533 x) @[simp] axiom s1534 (x : Prop) : f (g1535 x) = f (g1534 x) @[simp] axiom s1535 (x : Prop) : f (g1536 x) = f (g1535 x) @[simp] axiom s1536 (x : Prop) : f (g1537 x) = f (g1536 x) @[simp] axiom s1537 (x : Prop) : f (g1538 x) = f (g1537 x) @[simp] axiom s1538 (x : Prop) : f (g1539 x) = f (g1538 x) @[simp] axiom s1539 (x : Prop) : f (g1540 x) = f (g1539 x) @[simp] axiom s1540 (x : Prop) : f (g1541 x) = f (g1540 x) @[simp] axiom s1541 (x : Prop) : f (g1542 x) = f (g1541 x) @[simp] axiom s1542 (x : Prop) : f (g1543 x) = f (g1542 x) @[simp] axiom s1543 (x : Prop) : f (g1544 x) = f (g1543 x) @[simp] axiom s1544 (x : Prop) : f (g1545 x) = f (g1544 x) @[simp] axiom s1545 (x : Prop) : f (g1546 x) = f (g1545 x) @[simp] axiom s1546 (x : Prop) : f (g1547 x) = f (g1546 x) @[simp] axiom s1547 (x : Prop) : f (g1548 x) = f (g1547 x) @[simp] axiom s1548 (x : Prop) : f (g1549 x) = f (g1548 x) @[simp] axiom s1549 (x : Prop) : f (g1550 x) = f (g1549 x) @[simp] axiom s1550 (x : Prop) : f (g1551 x) = f (g1550 x) @[simp] axiom s1551 (x : Prop) : f (g1552 x) = f (g1551 x) @[simp] axiom s1552 (x : Prop) : f (g1553 x) = f (g1552 x) @[simp] axiom s1553 (x : Prop) : f (g1554 x) = f (g1553 x) @[simp] axiom s1554 (x : Prop) : f (g1555 x) = f (g1554 x) @[simp] axiom s1555 (x : Prop) : f (g1556 x) = f (g1555 x) @[simp] axiom s1556 (x : Prop) : f (g1557 x) = f (g1556 x) @[simp] axiom s1557 (x : Prop) : f (g1558 x) = f (g1557 x) @[simp] axiom s1558 (x : Prop) : f (g1559 x) = f (g1558 x) @[simp] axiom s1559 (x : Prop) : f (g1560 x) = f (g1559 x) @[simp] axiom s1560 (x : Prop) : f (g1561 x) = f (g1560 x) @[simp] axiom s1561 (x : Prop) : f (g1562 x) = f (g1561 x) @[simp] axiom s1562 (x : Prop) : f (g1563 x) = f (g1562 x) @[simp] axiom s1563 (x : Prop) : f (g1564 x) = f (g1563 x) @[simp] axiom s1564 (x : Prop) : f (g1565 x) = f (g1564 x) @[simp] axiom s1565 (x : Prop) : f (g1566 x) = f (g1565 x) @[simp] axiom s1566 (x : Prop) : f (g1567 x) = f (g1566 x) @[simp] axiom s1567 (x : Prop) : f (g1568 x) = f (g1567 x) @[simp] axiom s1568 (x : Prop) : f (g1569 x) = f (g1568 x) @[simp] axiom s1569 (x : Prop) : f (g1570 x) = f (g1569 x) @[simp] axiom s1570 (x : Prop) : f (g1571 x) = f (g1570 x) @[simp] axiom s1571 (x : Prop) : f (g1572 x) = f (g1571 x) @[simp] axiom s1572 (x : Prop) : f (g1573 x) = f (g1572 x) @[simp] axiom s1573 (x : Prop) : f (g1574 x) = f (g1573 x) @[simp] axiom s1574 (x : Prop) : f (g1575 x) = f (g1574 x) @[simp] axiom s1575 (x : Prop) : f (g1576 x) = f (g1575 x) @[simp] axiom s1576 (x : Prop) : f (g1577 x) = f (g1576 x) @[simp] axiom s1577 (x : Prop) : f (g1578 x) = f (g1577 x) @[simp] axiom s1578 (x : Prop) : f (g1579 x) = f (g1578 x) @[simp] axiom s1579 (x : Prop) : f (g1580 x) = f (g1579 x) @[simp] axiom s1580 (x : Prop) : f (g1581 x) = f (g1580 x) @[simp] axiom s1581 (x : Prop) : f (g1582 x) = f (g1581 x) @[simp] axiom s1582 (x : Prop) : f (g1583 x) = f (g1582 x) @[simp] axiom s1583 (x : Prop) : f (g1584 x) = f (g1583 x) @[simp] axiom s1584 (x : Prop) : f (g1585 x) = f (g1584 x) @[simp] axiom s1585 (x : Prop) : f (g1586 x) = f (g1585 x) @[simp] axiom s1586 (x : Prop) : f (g1587 x) = f (g1586 x) @[simp] axiom s1587 (x : Prop) : f (g1588 x) = f (g1587 x) @[simp] axiom s1588 (x : Prop) : f (g1589 x) = f (g1588 x) @[simp] axiom s1589 (x : Prop) : f (g1590 x) = f (g1589 x) @[simp] axiom s1590 (x : Prop) : f (g1591 x) = f (g1590 x) @[simp] axiom s1591 (x : Prop) : f (g1592 x) = f (g1591 x) @[simp] axiom s1592 (x : Prop) : f (g1593 x) = f (g1592 x) @[simp] axiom s1593 (x : Prop) : f (g1594 x) = f (g1593 x) @[simp] axiom s1594 (x : Prop) : f (g1595 x) = f (g1594 x) @[simp] axiom s1595 (x : Prop) : f (g1596 x) = f (g1595 x) @[simp] axiom s1596 (x : Prop) : f (g1597 x) = f (g1596 x) @[simp] axiom s1597 (x : Prop) : f (g1598 x) = f (g1597 x) @[simp] axiom s1598 (x : Prop) : f (g1599 x) = f (g1598 x) @[simp] axiom s1599 (x : Prop) : f (g1600 x) = f (g1599 x) @[simp] axiom s1600 (x : Prop) : f (g1601 x) = f (g1600 x) @[simp] axiom s1601 (x : Prop) : f (g1602 x) = f (g1601 x) @[simp] axiom s1602 (x : Prop) : f (g1603 x) = f (g1602 x) @[simp] axiom s1603 (x : Prop) : f (g1604 x) = f (g1603 x) @[simp] axiom s1604 (x : Prop) : f (g1605 x) = f (g1604 x) @[simp] axiom s1605 (x : Prop) : f (g1606 x) = f (g1605 x) @[simp] axiom s1606 (x : Prop) : f (g1607 x) = f (g1606 x) @[simp] axiom s1607 (x : Prop) : f (g1608 x) = f (g1607 x) @[simp] axiom s1608 (x : Prop) : f (g1609 x) = f (g1608 x) @[simp] axiom s1609 (x : Prop) : f (g1610 x) = f (g1609 x) @[simp] axiom s1610 (x : Prop) : f (g1611 x) = f (g1610 x) @[simp] axiom s1611 (x : Prop) : f (g1612 x) = f (g1611 x) @[simp] axiom s1612 (x : Prop) : f (g1613 x) = f (g1612 x) @[simp] axiom s1613 (x : Prop) : f (g1614 x) = f (g1613 x) @[simp] axiom s1614 (x : Prop) : f (g1615 x) = f (g1614 x) @[simp] axiom s1615 (x : Prop) : f (g1616 x) = f (g1615 x) @[simp] axiom s1616 (x : Prop) : f (g1617 x) = f (g1616 x) @[simp] axiom s1617 (x : Prop) : f (g1618 x) = f (g1617 x) @[simp] axiom s1618 (x : Prop) : f (g1619 x) = f (g1618 x) @[simp] axiom s1619 (x : Prop) : f (g1620 x) = f (g1619 x) @[simp] axiom s1620 (x : Prop) : f (g1621 x) = f (g1620 x) @[simp] axiom s1621 (x : Prop) : f (g1622 x) = f (g1621 x) @[simp] axiom s1622 (x : Prop) : f (g1623 x) = f (g1622 x) @[simp] axiom s1623 (x : Prop) : f (g1624 x) = f (g1623 x) @[simp] axiom s1624 (x : Prop) : f (g1625 x) = f (g1624 x) @[simp] axiom s1625 (x : Prop) : f (g1626 x) = f (g1625 x) @[simp] axiom s1626 (x : Prop) : f (g1627 x) = f (g1626 x) @[simp] axiom s1627 (x : Prop) : f (g1628 x) = f (g1627 x) @[simp] axiom s1628 (x : Prop) : f (g1629 x) = f (g1628 x) @[simp] axiom s1629 (x : Prop) : f (g1630 x) = f (g1629 x) @[simp] axiom s1630 (x : Prop) : f (g1631 x) = f (g1630 x) @[simp] axiom s1631 (x : Prop) : f (g1632 x) = f (g1631 x) @[simp] axiom s1632 (x : Prop) : f (g1633 x) = f (g1632 x) @[simp] axiom s1633 (x : Prop) : f (g1634 x) = f (g1633 x) @[simp] axiom s1634 (x : Prop) : f (g1635 x) = f (g1634 x) @[simp] axiom s1635 (x : Prop) : f (g1636 x) = f (g1635 x) @[simp] axiom s1636 (x : Prop) : f (g1637 x) = f (g1636 x) @[simp] axiom s1637 (x : Prop) : f (g1638 x) = f (g1637 x) @[simp] axiom s1638 (x : Prop) : f (g1639 x) = f (g1638 x) @[simp] axiom s1639 (x : Prop) : f (g1640 x) = f (g1639 x) @[simp] axiom s1640 (x : Prop) : f (g1641 x) = f (g1640 x) @[simp] axiom s1641 (x : Prop) : f (g1642 x) = f (g1641 x) @[simp] axiom s1642 (x : Prop) : f (g1643 x) = f (g1642 x) @[simp] axiom s1643 (x : Prop) : f (g1644 x) = f (g1643 x) @[simp] axiom s1644 (x : Prop) : f (g1645 x) = f (g1644 x) @[simp] axiom s1645 (x : Prop) : f (g1646 x) = f (g1645 x) @[simp] axiom s1646 (x : Prop) : f (g1647 x) = f (g1646 x) @[simp] axiom s1647 (x : Prop) : f (g1648 x) = f (g1647 x) @[simp] axiom s1648 (x : Prop) : f (g1649 x) = f (g1648 x) @[simp] axiom s1649 (x : Prop) : f (g1650 x) = f (g1649 x) @[simp] axiom s1650 (x : Prop) : f (g1651 x) = f (g1650 x) @[simp] axiom s1651 (x : Prop) : f (g1652 x) = f (g1651 x) @[simp] axiom s1652 (x : Prop) : f (g1653 x) = f (g1652 x) @[simp] axiom s1653 (x : Prop) : f (g1654 x) = f (g1653 x) @[simp] axiom s1654 (x : Prop) : f (g1655 x) = f (g1654 x) @[simp] axiom s1655 (x : Prop) : f (g1656 x) = f (g1655 x) @[simp] axiom s1656 (x : Prop) : f (g1657 x) = f (g1656 x) @[simp] axiom s1657 (x : Prop) : f (g1658 x) = f (g1657 x) @[simp] axiom s1658 (x : Prop) : f (g1659 x) = f (g1658 x) @[simp] axiom s1659 (x : Prop) : f (g1660 x) = f (g1659 x) @[simp] axiom s1660 (x : Prop) : f (g1661 x) = f (g1660 x) @[simp] axiom s1661 (x : Prop) : f (g1662 x) = f (g1661 x) @[simp] axiom s1662 (x : Prop) : f (g1663 x) = f (g1662 x) @[simp] axiom s1663 (x : Prop) : f (g1664 x) = f (g1663 x) @[simp] axiom s1664 (x : Prop) : f (g1665 x) = f (g1664 x) @[simp] axiom s1665 (x : Prop) : f (g1666 x) = f (g1665 x) @[simp] axiom s1666 (x : Prop) : f (g1667 x) = f (g1666 x) @[simp] axiom s1667 (x : Prop) : f (g1668 x) = f (g1667 x) @[simp] axiom s1668 (x : Prop) : f (g1669 x) = f (g1668 x) @[simp] axiom s1669 (x : Prop) : f (g1670 x) = f (g1669 x) @[simp] axiom s1670 (x : Prop) : f (g1671 x) = f (g1670 x) @[simp] axiom s1671 (x : Prop) : f (g1672 x) = f (g1671 x) @[simp] axiom s1672 (x : Prop) : f (g1673 x) = f (g1672 x) @[simp] axiom s1673 (x : Prop) : f (g1674 x) = f (g1673 x) @[simp] axiom s1674 (x : Prop) : f (g1675 x) = f (g1674 x) @[simp] axiom s1675 (x : Prop) : f (g1676 x) = f (g1675 x) @[simp] axiom s1676 (x : Prop) : f (g1677 x) = f (g1676 x) @[simp] axiom s1677 (x : Prop) : f (g1678 x) = f (g1677 x) @[simp] axiom s1678 (x : Prop) : f (g1679 x) = f (g1678 x) @[simp] axiom s1679 (x : Prop) : f (g1680 x) = f (g1679 x) @[simp] axiom s1680 (x : Prop) : f (g1681 x) = f (g1680 x) @[simp] axiom s1681 (x : Prop) : f (g1682 x) = f (g1681 x) @[simp] axiom s1682 (x : Prop) : f (g1683 x) = f (g1682 x) @[simp] axiom s1683 (x : Prop) : f (g1684 x) = f (g1683 x) @[simp] axiom s1684 (x : Prop) : f (g1685 x) = f (g1684 x) @[simp] axiom s1685 (x : Prop) : f (g1686 x) = f (g1685 x) @[simp] axiom s1686 (x : Prop) : f (g1687 x) = f (g1686 x) @[simp] axiom s1687 (x : Prop) : f (g1688 x) = f (g1687 x) @[simp] axiom s1688 (x : Prop) : f (g1689 x) = f (g1688 x) @[simp] axiom s1689 (x : Prop) : f (g1690 x) = f (g1689 x) @[simp] axiom s1690 (x : Prop) : f (g1691 x) = f (g1690 x) @[simp] axiom s1691 (x : Prop) : f (g1692 x) = f (g1691 x) @[simp] axiom s1692 (x : Prop) : f (g1693 x) = f (g1692 x) @[simp] axiom s1693 (x : Prop) : f (g1694 x) = f (g1693 x) @[simp] axiom s1694 (x : Prop) : f (g1695 x) = f (g1694 x) @[simp] axiom s1695 (x : Prop) : f (g1696 x) = f (g1695 x) @[simp] axiom s1696 (x : Prop) : f (g1697 x) = f (g1696 x) @[simp] axiom s1697 (x : Prop) : f (g1698 x) = f (g1697 x) @[simp] axiom s1698 (x : Prop) : f (g1699 x) = f (g1698 x) @[simp] axiom s1699 (x : Prop) : f (g1700 x) = f (g1699 x) @[simp] axiom s1700 (x : Prop) : f (g1701 x) = f (g1700 x) @[simp] axiom s1701 (x : Prop) : f (g1702 x) = f (g1701 x) @[simp] axiom s1702 (x : Prop) : f (g1703 x) = f (g1702 x) @[simp] axiom s1703 (x : Prop) : f (g1704 x) = f (g1703 x) @[simp] axiom s1704 (x : Prop) : f (g1705 x) = f (g1704 x) @[simp] axiom s1705 (x : Prop) : f (g1706 x) = f (g1705 x) @[simp] axiom s1706 (x : Prop) : f (g1707 x) = f (g1706 x) @[simp] axiom s1707 (x : Prop) : f (g1708 x) = f (g1707 x) @[simp] axiom s1708 (x : Prop) : f (g1709 x) = f (g1708 x) @[simp] axiom s1709 (x : Prop) : f (g1710 x) = f (g1709 x) @[simp] axiom s1710 (x : Prop) : f (g1711 x) = f (g1710 x) @[simp] axiom s1711 (x : Prop) : f (g1712 x) = f (g1711 x) @[simp] axiom s1712 (x : Prop) : f (g1713 x) = f (g1712 x) @[simp] axiom s1713 (x : Prop) : f (g1714 x) = f (g1713 x) @[simp] axiom s1714 (x : Prop) : f (g1715 x) = f (g1714 x) @[simp] axiom s1715 (x : Prop) : f (g1716 x) = f (g1715 x) @[simp] axiom s1716 (x : Prop) : f (g1717 x) = f (g1716 x) @[simp] axiom s1717 (x : Prop) : f (g1718 x) = f (g1717 x) @[simp] axiom s1718 (x : Prop) : f (g1719 x) = f (g1718 x) @[simp] axiom s1719 (x : Prop) : f (g1720 x) = f (g1719 x) @[simp] axiom s1720 (x : Prop) : f (g1721 x) = f (g1720 x) @[simp] axiom s1721 (x : Prop) : f (g1722 x) = f (g1721 x) @[simp] axiom s1722 (x : Prop) : f (g1723 x) = f (g1722 x) @[simp] axiom s1723 (x : Prop) : f (g1724 x) = f (g1723 x) @[simp] axiom s1724 (x : Prop) : f (g1725 x) = f (g1724 x) @[simp] axiom s1725 (x : Prop) : f (g1726 x) = f (g1725 x) @[simp] axiom s1726 (x : Prop) : f (g1727 x) = f (g1726 x) @[simp] axiom s1727 (x : Prop) : f (g1728 x) = f (g1727 x) @[simp] axiom s1728 (x : Prop) : f (g1729 x) = f (g1728 x) @[simp] axiom s1729 (x : Prop) : f (g1730 x) = f (g1729 x) @[simp] axiom s1730 (x : Prop) : f (g1731 x) = f (g1730 x) @[simp] axiom s1731 (x : Prop) : f (g1732 x) = f (g1731 x) @[simp] axiom s1732 (x : Prop) : f (g1733 x) = f (g1732 x) @[simp] axiom s1733 (x : Prop) : f (g1734 x) = f (g1733 x) @[simp] axiom s1734 (x : Prop) : f (g1735 x) = f (g1734 x) @[simp] axiom s1735 (x : Prop) : f (g1736 x) = f (g1735 x) @[simp] axiom s1736 (x : Prop) : f (g1737 x) = f (g1736 x) @[simp] axiom s1737 (x : Prop) : f (g1738 x) = f (g1737 x) @[simp] axiom s1738 (x : Prop) : f (g1739 x) = f (g1738 x) @[simp] axiom s1739 (x : Prop) : f (g1740 x) = f (g1739 x) @[simp] axiom s1740 (x : Prop) : f (g1741 x) = f (g1740 x) @[simp] axiom s1741 (x : Prop) : f (g1742 x) = f (g1741 x) @[simp] axiom s1742 (x : Prop) : f (g1743 x) = f (g1742 x) @[simp] axiom s1743 (x : Prop) : f (g1744 x) = f (g1743 x) @[simp] axiom s1744 (x : Prop) : f (g1745 x) = f (g1744 x) @[simp] axiom s1745 (x : Prop) : f (g1746 x) = f (g1745 x) @[simp] axiom s1746 (x : Prop) : f (g1747 x) = f (g1746 x) @[simp] axiom s1747 (x : Prop) : f (g1748 x) = f (g1747 x) @[simp] axiom s1748 (x : Prop) : f (g1749 x) = f (g1748 x) @[simp] axiom s1749 (x : Prop) : f (g1750 x) = f (g1749 x) @[simp] axiom s1750 (x : Prop) : f (g1751 x) = f (g1750 x) @[simp] axiom s1751 (x : Prop) : f (g1752 x) = f (g1751 x) @[simp] axiom s1752 (x : Prop) : f (g1753 x) = f (g1752 x) @[simp] axiom s1753 (x : Prop) : f (g1754 x) = f (g1753 x) @[simp] axiom s1754 (x : Prop) : f (g1755 x) = f (g1754 x) @[simp] axiom s1755 (x : Prop) : f (g1756 x) = f (g1755 x) @[simp] axiom s1756 (x : Prop) : f (g1757 x) = f (g1756 x) @[simp] axiom s1757 (x : Prop) : f (g1758 x) = f (g1757 x) @[simp] axiom s1758 (x : Prop) : f (g1759 x) = f (g1758 x) @[simp] axiom s1759 (x : Prop) : f (g1760 x) = f (g1759 x) @[simp] axiom s1760 (x : Prop) : f (g1761 x) = f (g1760 x) @[simp] axiom s1761 (x : Prop) : f (g1762 x) = f (g1761 x) @[simp] axiom s1762 (x : Prop) : f (g1763 x) = f (g1762 x) @[simp] axiom s1763 (x : Prop) : f (g1764 x) = f (g1763 x) @[simp] axiom s1764 (x : Prop) : f (g1765 x) = f (g1764 x) @[simp] axiom s1765 (x : Prop) : f (g1766 x) = f (g1765 x) @[simp] axiom s1766 (x : Prop) : f (g1767 x) = f (g1766 x) @[simp] axiom s1767 (x : Prop) : f (g1768 x) = f (g1767 x) @[simp] axiom s1768 (x : Prop) : f (g1769 x) = f (g1768 x) @[simp] axiom s1769 (x : Prop) : f (g1770 x) = f (g1769 x) @[simp] axiom s1770 (x : Prop) : f (g1771 x) = f (g1770 x) @[simp] axiom s1771 (x : Prop) : f (g1772 x) = f (g1771 x) @[simp] axiom s1772 (x : Prop) : f (g1773 x) = f (g1772 x) @[simp] axiom s1773 (x : Prop) : f (g1774 x) = f (g1773 x) @[simp] axiom s1774 (x : Prop) : f (g1775 x) = f (g1774 x) @[simp] axiom s1775 (x : Prop) : f (g1776 x) = f (g1775 x) @[simp] axiom s1776 (x : Prop) : f (g1777 x) = f (g1776 x) @[simp] axiom s1777 (x : Prop) : f (g1778 x) = f (g1777 x) @[simp] axiom s1778 (x : Prop) : f (g1779 x) = f (g1778 x) @[simp] axiom s1779 (x : Prop) : f (g1780 x) = f (g1779 x) @[simp] axiom s1780 (x : Prop) : f (g1781 x) = f (g1780 x) @[simp] axiom s1781 (x : Prop) : f (g1782 x) = f (g1781 x) @[simp] axiom s1782 (x : Prop) : f (g1783 x) = f (g1782 x) @[simp] axiom s1783 (x : Prop) : f (g1784 x) = f (g1783 x) @[simp] axiom s1784 (x : Prop) : f (g1785 x) = f (g1784 x) @[simp] axiom s1785 (x : Prop) : f (g1786 x) = f (g1785 x) @[simp] axiom s1786 (x : Prop) : f (g1787 x) = f (g1786 x) @[simp] axiom s1787 (x : Prop) : f (g1788 x) = f (g1787 x) @[simp] axiom s1788 (x : Prop) : f (g1789 x) = f (g1788 x) @[simp] axiom s1789 (x : Prop) : f (g1790 x) = f (g1789 x) @[simp] axiom s1790 (x : Prop) : f (g1791 x) = f (g1790 x) @[simp] axiom s1791 (x : Prop) : f (g1792 x) = f (g1791 x) @[simp] axiom s1792 (x : Prop) : f (g1793 x) = f (g1792 x) @[simp] axiom s1793 (x : Prop) : f (g1794 x) = f (g1793 x) @[simp] axiom s1794 (x : Prop) : f (g1795 x) = f (g1794 x) @[simp] axiom s1795 (x : Prop) : f (g1796 x) = f (g1795 x) @[simp] axiom s1796 (x : Prop) : f (g1797 x) = f (g1796 x) @[simp] axiom s1797 (x : Prop) : f (g1798 x) = f (g1797 x) @[simp] axiom s1798 (x : Prop) : f (g1799 x) = f (g1798 x) @[simp] axiom s1799 (x : Prop) : f (g1800 x) = f (g1799 x) @[simp] axiom s1800 (x : Prop) : f (g1801 x) = f (g1800 x) @[simp] axiom s1801 (x : Prop) : f (g1802 x) = f (g1801 x) @[simp] axiom s1802 (x : Prop) : f (g1803 x) = f (g1802 x) @[simp] axiom s1803 (x : Prop) : f (g1804 x) = f (g1803 x) @[simp] axiom s1804 (x : Prop) : f (g1805 x) = f (g1804 x) @[simp] axiom s1805 (x : Prop) : f (g1806 x) = f (g1805 x) @[simp] axiom s1806 (x : Prop) : f (g1807 x) = f (g1806 x) @[simp] axiom s1807 (x : Prop) : f (g1808 x) = f (g1807 x) @[simp] axiom s1808 (x : Prop) : f (g1809 x) = f (g1808 x) @[simp] axiom s1809 (x : Prop) : f (g1810 x) = f (g1809 x) @[simp] axiom s1810 (x : Prop) : f (g1811 x) = f (g1810 x) @[simp] axiom s1811 (x : Prop) : f (g1812 x) = f (g1811 x) @[simp] axiom s1812 (x : Prop) : f (g1813 x) = f (g1812 x) @[simp] axiom s1813 (x : Prop) : f (g1814 x) = f (g1813 x) @[simp] axiom s1814 (x : Prop) : f (g1815 x) = f (g1814 x) @[simp] axiom s1815 (x : Prop) : f (g1816 x) = f (g1815 x) @[simp] axiom s1816 (x : Prop) : f (g1817 x) = f (g1816 x) @[simp] axiom s1817 (x : Prop) : f (g1818 x) = f (g1817 x) @[simp] axiom s1818 (x : Prop) : f (g1819 x) = f (g1818 x) @[simp] axiom s1819 (x : Prop) : f (g1820 x) = f (g1819 x) @[simp] axiom s1820 (x : Prop) : f (g1821 x) = f (g1820 x) @[simp] axiom s1821 (x : Prop) : f (g1822 x) = f (g1821 x) @[simp] axiom s1822 (x : Prop) : f (g1823 x) = f (g1822 x) @[simp] axiom s1823 (x : Prop) : f (g1824 x) = f (g1823 x) @[simp] axiom s1824 (x : Prop) : f (g1825 x) = f (g1824 x) @[simp] axiom s1825 (x : Prop) : f (g1826 x) = f (g1825 x) @[simp] axiom s1826 (x : Prop) : f (g1827 x) = f (g1826 x) @[simp] axiom s1827 (x : Prop) : f (g1828 x) = f (g1827 x) @[simp] axiom s1828 (x : Prop) : f (g1829 x) = f (g1828 x) @[simp] axiom s1829 (x : Prop) : f (g1830 x) = f (g1829 x) @[simp] axiom s1830 (x : Prop) : f (g1831 x) = f (g1830 x) @[simp] axiom s1831 (x : Prop) : f (g1832 x) = f (g1831 x) @[simp] axiom s1832 (x : Prop) : f (g1833 x) = f (g1832 x) @[simp] axiom s1833 (x : Prop) : f (g1834 x) = f (g1833 x) @[simp] axiom s1834 (x : Prop) : f (g1835 x) = f (g1834 x) @[simp] axiom s1835 (x : Prop) : f (g1836 x) = f (g1835 x) @[simp] axiom s1836 (x : Prop) : f (g1837 x) = f (g1836 x) @[simp] axiom s1837 (x : Prop) : f (g1838 x) = f (g1837 x) @[simp] axiom s1838 (x : Prop) : f (g1839 x) = f (g1838 x) @[simp] axiom s1839 (x : Prop) : f (g1840 x) = f (g1839 x) @[simp] axiom s1840 (x : Prop) : f (g1841 x) = f (g1840 x) @[simp] axiom s1841 (x : Prop) : f (g1842 x) = f (g1841 x) @[simp] axiom s1842 (x : Prop) : f (g1843 x) = f (g1842 x) @[simp] axiom s1843 (x : Prop) : f (g1844 x) = f (g1843 x) @[simp] axiom s1844 (x : Prop) : f (g1845 x) = f (g1844 x) @[simp] axiom s1845 (x : Prop) : f (g1846 x) = f (g1845 x) @[simp] axiom s1846 (x : Prop) : f (g1847 x) = f (g1846 x) @[simp] axiom s1847 (x : Prop) : f (g1848 x) = f (g1847 x) @[simp] axiom s1848 (x : Prop) : f (g1849 x) = f (g1848 x) @[simp] axiom s1849 (x : Prop) : f (g1850 x) = f (g1849 x) @[simp] axiom s1850 (x : Prop) : f (g1851 x) = f (g1850 x) @[simp] axiom s1851 (x : Prop) : f (g1852 x) = f (g1851 x) @[simp] axiom s1852 (x : Prop) : f (g1853 x) = f (g1852 x) @[simp] axiom s1853 (x : Prop) : f (g1854 x) = f (g1853 x) @[simp] axiom s1854 (x : Prop) : f (g1855 x) = f (g1854 x) @[simp] axiom s1855 (x : Prop) : f (g1856 x) = f (g1855 x) @[simp] axiom s1856 (x : Prop) : f (g1857 x) = f (g1856 x) @[simp] axiom s1857 (x : Prop) : f (g1858 x) = f (g1857 x) @[simp] axiom s1858 (x : Prop) : f (g1859 x) = f (g1858 x) @[simp] axiom s1859 (x : Prop) : f (g1860 x) = f (g1859 x) @[simp] axiom s1860 (x : Prop) : f (g1861 x) = f (g1860 x) @[simp] axiom s1861 (x : Prop) : f (g1862 x) = f (g1861 x) @[simp] axiom s1862 (x : Prop) : f (g1863 x) = f (g1862 x) @[simp] axiom s1863 (x : Prop) : f (g1864 x) = f (g1863 x) @[simp] axiom s1864 (x : Prop) : f (g1865 x) = f (g1864 x) @[simp] axiom s1865 (x : Prop) : f (g1866 x) = f (g1865 x) @[simp] axiom s1866 (x : Prop) : f (g1867 x) = f (g1866 x) @[simp] axiom s1867 (x : Prop) : f (g1868 x) = f (g1867 x) @[simp] axiom s1868 (x : Prop) : f (g1869 x) = f (g1868 x) @[simp] axiom s1869 (x : Prop) : f (g1870 x) = f (g1869 x) @[simp] axiom s1870 (x : Prop) : f (g1871 x) = f (g1870 x) @[simp] axiom s1871 (x : Prop) : f (g1872 x) = f (g1871 x) @[simp] axiom s1872 (x : Prop) : f (g1873 x) = f (g1872 x) @[simp] axiom s1873 (x : Prop) : f (g1874 x) = f (g1873 x) @[simp] axiom s1874 (x : Prop) : f (g1875 x) = f (g1874 x) @[simp] axiom s1875 (x : Prop) : f (g1876 x) = f (g1875 x) @[simp] axiom s1876 (x : Prop) : f (g1877 x) = f (g1876 x) @[simp] axiom s1877 (x : Prop) : f (g1878 x) = f (g1877 x) @[simp] axiom s1878 (x : Prop) : f (g1879 x) = f (g1878 x) @[simp] axiom s1879 (x : Prop) : f (g1880 x) = f (g1879 x) @[simp] axiom s1880 (x : Prop) : f (g1881 x) = f (g1880 x) @[simp] axiom s1881 (x : Prop) : f (g1882 x) = f (g1881 x) @[simp] axiom s1882 (x : Prop) : f (g1883 x) = f (g1882 x) @[simp] axiom s1883 (x : Prop) : f (g1884 x) = f (g1883 x) @[simp] axiom s1884 (x : Prop) : f (g1885 x) = f (g1884 x) @[simp] axiom s1885 (x : Prop) : f (g1886 x) = f (g1885 x) @[simp] axiom s1886 (x : Prop) : f (g1887 x) = f (g1886 x) @[simp] axiom s1887 (x : Prop) : f (g1888 x) = f (g1887 x) @[simp] axiom s1888 (x : Prop) : f (g1889 x) = f (g1888 x) @[simp] axiom s1889 (x : Prop) : f (g1890 x) = f (g1889 x) @[simp] axiom s1890 (x : Prop) : f (g1891 x) = f (g1890 x) @[simp] axiom s1891 (x : Prop) : f (g1892 x) = f (g1891 x) @[simp] axiom s1892 (x : Prop) : f (g1893 x) = f (g1892 x) @[simp] axiom s1893 (x : Prop) : f (g1894 x) = f (g1893 x) @[simp] axiom s1894 (x : Prop) : f (g1895 x) = f (g1894 x) @[simp] axiom s1895 (x : Prop) : f (g1896 x) = f (g1895 x) @[simp] axiom s1896 (x : Prop) : f (g1897 x) = f (g1896 x) @[simp] axiom s1897 (x : Prop) : f (g1898 x) = f (g1897 x) @[simp] axiom s1898 (x : Prop) : f (g1899 x) = f (g1898 x) @[simp] axiom s1899 (x : Prop) : f (g1900 x) = f (g1899 x) @[simp] axiom s1900 (x : Prop) : f (g1901 x) = f (g1900 x) @[simp] axiom s1901 (x : Prop) : f (g1902 x) = f (g1901 x) @[simp] axiom s1902 (x : Prop) : f (g1903 x) = f (g1902 x) @[simp] axiom s1903 (x : Prop) : f (g1904 x) = f (g1903 x) @[simp] axiom s1904 (x : Prop) : f (g1905 x) = f (g1904 x) @[simp] axiom s1905 (x : Prop) : f (g1906 x) = f (g1905 x) @[simp] axiom s1906 (x : Prop) : f (g1907 x) = f (g1906 x) @[simp] axiom s1907 (x : Prop) : f (g1908 x) = f (g1907 x) @[simp] axiom s1908 (x : Prop) : f (g1909 x) = f (g1908 x) @[simp] axiom s1909 (x : Prop) : f (g1910 x) = f (g1909 x) @[simp] axiom s1910 (x : Prop) : f (g1911 x) = f (g1910 x) @[simp] axiom s1911 (x : Prop) : f (g1912 x) = f (g1911 x) @[simp] axiom s1912 (x : Prop) : f (g1913 x) = f (g1912 x) @[simp] axiom s1913 (x : Prop) : f (g1914 x) = f (g1913 x) @[simp] axiom s1914 (x : Prop) : f (g1915 x) = f (g1914 x) @[simp] axiom s1915 (x : Prop) : f (g1916 x) = f (g1915 x) @[simp] axiom s1916 (x : Prop) : f (g1917 x) = f (g1916 x) @[simp] axiom s1917 (x : Prop) : f (g1918 x) = f (g1917 x) @[simp] axiom s1918 (x : Prop) : f (g1919 x) = f (g1918 x) @[simp] axiom s1919 (x : Prop) : f (g1920 x) = f (g1919 x) @[simp] axiom s1920 (x : Prop) : f (g1921 x) = f (g1920 x) @[simp] axiom s1921 (x : Prop) : f (g1922 x) = f (g1921 x) @[simp] axiom s1922 (x : Prop) : f (g1923 x) = f (g1922 x) @[simp] axiom s1923 (x : Prop) : f (g1924 x) = f (g1923 x) @[simp] axiom s1924 (x : Prop) : f (g1925 x) = f (g1924 x) @[simp] axiom s1925 (x : Prop) : f (g1926 x) = f (g1925 x) @[simp] axiom s1926 (x : Prop) : f (g1927 x) = f (g1926 x) @[simp] axiom s1927 (x : Prop) : f (g1928 x) = f (g1927 x) @[simp] axiom s1928 (x : Prop) : f (g1929 x) = f (g1928 x) @[simp] axiom s1929 (x : Prop) : f (g1930 x) = f (g1929 x) @[simp] axiom s1930 (x : Prop) : f (g1931 x) = f (g1930 x) @[simp] axiom s1931 (x : Prop) : f (g1932 x) = f (g1931 x) @[simp] axiom s1932 (x : Prop) : f (g1933 x) = f (g1932 x) @[simp] axiom s1933 (x : Prop) : f (g1934 x) = f (g1933 x) @[simp] axiom s1934 (x : Prop) : f (g1935 x) = f (g1934 x) @[simp] axiom s1935 (x : Prop) : f (g1936 x) = f (g1935 x) @[simp] axiom s1936 (x : Prop) : f (g1937 x) = f (g1936 x) @[simp] axiom s1937 (x : Prop) : f (g1938 x) = f (g1937 x) @[simp] axiom s1938 (x : Prop) : f (g1939 x) = f (g1938 x) @[simp] axiom s1939 (x : Prop) : f (g1940 x) = f (g1939 x) @[simp] axiom s1940 (x : Prop) : f (g1941 x) = f (g1940 x) @[simp] axiom s1941 (x : Prop) : f (g1942 x) = f (g1941 x) @[simp] axiom s1942 (x : Prop) : f (g1943 x) = f (g1942 x) @[simp] axiom s1943 (x : Prop) : f (g1944 x) = f (g1943 x) @[simp] axiom s1944 (x : Prop) : f (g1945 x) = f (g1944 x) @[simp] axiom s1945 (x : Prop) : f (g1946 x) = f (g1945 x) @[simp] axiom s1946 (x : Prop) : f (g1947 x) = f (g1946 x) @[simp] axiom s1947 (x : Prop) : f (g1948 x) = f (g1947 x) @[simp] axiom s1948 (x : Prop) : f (g1949 x) = f (g1948 x) @[simp] axiom s1949 (x : Prop) : f (g1950 x) = f (g1949 x) @[simp] axiom s1950 (x : Prop) : f (g1951 x) = f (g1950 x) @[simp] axiom s1951 (x : Prop) : f (g1952 x) = f (g1951 x) @[simp] axiom s1952 (x : Prop) : f (g1953 x) = f (g1952 x) @[simp] axiom s1953 (x : Prop) : f (g1954 x) = f (g1953 x) @[simp] axiom s1954 (x : Prop) : f (g1955 x) = f (g1954 x) @[simp] axiom s1955 (x : Prop) : f (g1956 x) = f (g1955 x) @[simp] axiom s1956 (x : Prop) : f (g1957 x) = f (g1956 x) @[simp] axiom s1957 (x : Prop) : f (g1958 x) = f (g1957 x) @[simp] axiom s1958 (x : Prop) : f (g1959 x) = f (g1958 x) @[simp] axiom s1959 (x : Prop) : f (g1960 x) = f (g1959 x) @[simp] axiom s1960 (x : Prop) : f (g1961 x) = f (g1960 x) @[simp] axiom s1961 (x : Prop) : f (g1962 x) = f (g1961 x) @[simp] axiom s1962 (x : Prop) : f (g1963 x) = f (g1962 x) @[simp] axiom s1963 (x : Prop) : f (g1964 x) = f (g1963 x) @[simp] axiom s1964 (x : Prop) : f (g1965 x) = f (g1964 x) @[simp] axiom s1965 (x : Prop) : f (g1966 x) = f (g1965 x) @[simp] axiom s1966 (x : Prop) : f (g1967 x) = f (g1966 x) @[simp] axiom s1967 (x : Prop) : f (g1968 x) = f (g1967 x) @[simp] axiom s1968 (x : Prop) : f (g1969 x) = f (g1968 x) @[simp] axiom s1969 (x : Prop) : f (g1970 x) = f (g1969 x) @[simp] axiom s1970 (x : Prop) : f (g1971 x) = f (g1970 x) @[simp] axiom s1971 (x : Prop) : f (g1972 x) = f (g1971 x) @[simp] axiom s1972 (x : Prop) : f (g1973 x) = f (g1972 x) @[simp] axiom s1973 (x : Prop) : f (g1974 x) = f (g1973 x) @[simp] axiom s1974 (x : Prop) : f (g1975 x) = f (g1974 x) @[simp] axiom s1975 (x : Prop) : f (g1976 x) = f (g1975 x) @[simp] axiom s1976 (x : Prop) : f (g1977 x) = f (g1976 x) @[simp] axiom s1977 (x : Prop) : f (g1978 x) = f (g1977 x) @[simp] axiom s1978 (x : Prop) : f (g1979 x) = f (g1978 x) @[simp] axiom s1979 (x : Prop) : f (g1980 x) = f (g1979 x) @[simp] axiom s1980 (x : Prop) : f (g1981 x) = f (g1980 x) @[simp] axiom s1981 (x : Prop) : f (g1982 x) = f (g1981 x) @[simp] axiom s1982 (x : Prop) : f (g1983 x) = f (g1982 x) @[simp] axiom s1983 (x : Prop) : f (g1984 x) = f (g1983 x) @[simp] axiom s1984 (x : Prop) : f (g1985 x) = f (g1984 x) @[simp] axiom s1985 (x : Prop) : f (g1986 x) = f (g1985 x) @[simp] axiom s1986 (x : Prop) : f (g1987 x) = f (g1986 x) @[simp] axiom s1987 (x : Prop) : f (g1988 x) = f (g1987 x) @[simp] axiom s1988 (x : Prop) : f (g1989 x) = f (g1988 x) @[simp] axiom s1989 (x : Prop) : f (g1990 x) = f (g1989 x) @[simp] axiom s1990 (x : Prop) : f (g1991 x) = f (g1990 x) @[simp] axiom s1991 (x : Prop) : f (g1992 x) = f (g1991 x) @[simp] axiom s1992 (x : Prop) : f (g1993 x) = f (g1992 x) @[simp] axiom s1993 (x : Prop) : f (g1994 x) = f (g1993 x) @[simp] axiom s1994 (x : Prop) : f (g1995 x) = f (g1994 x) @[simp] axiom s1995 (x : Prop) : f (g1996 x) = f (g1995 x) @[simp] axiom s1996 (x : Prop) : f (g1997 x) = f (g1996 x) @[simp] axiom s1997 (x : Prop) : f (g1998 x) = f (g1997 x) @[simp] axiom s1998 (x : Prop) : f (g1999 x) = f (g1998 x) @[simp] axiom s1999 (x : Prop) : f (g2000 x) = f (g1999 x) @[simp] axiom s2000 (x : Prop) : f (g2001 x) = f (g2000 x) @[simp] axiom s2001 (x : Prop) : f (g2002 x) = f (g2001 x) @[simp] axiom s2002 (x : Prop) : f (g2003 x) = f (g2002 x) @[simp] axiom s2003 (x : Prop) : f (g2004 x) = f (g2003 x) @[simp] axiom s2004 (x : Prop) : f (g2005 x) = f (g2004 x) @[simp] axiom s2005 (x : Prop) : f (g2006 x) = f (g2005 x) @[simp] axiom s2006 (x : Prop) : f (g2007 x) = f (g2006 x) @[simp] axiom s2007 (x : Prop) : f (g2008 x) = f (g2007 x) @[simp] axiom s2008 (x : Prop) : f (g2009 x) = f (g2008 x) @[simp] axiom s2009 (x : Prop) : f (g2010 x) = f (g2009 x) @[simp] axiom s2010 (x : Prop) : f (g2011 x) = f (g2010 x) @[simp] axiom s2011 (x : Prop) : f (g2012 x) = f (g2011 x) @[simp] axiom s2012 (x : Prop) : f (g2013 x) = f (g2012 x) @[simp] axiom s2013 (x : Prop) : f (g2014 x) = f (g2013 x) @[simp] axiom s2014 (x : Prop) : f (g2015 x) = f (g2014 x) @[simp] axiom s2015 (x : Prop) : f (g2016 x) = f (g2015 x) @[simp] axiom s2016 (x : Prop) : f (g2017 x) = f (g2016 x) @[simp] axiom s2017 (x : Prop) : f (g2018 x) = f (g2017 x) @[simp] axiom s2018 (x : Prop) : f (g2019 x) = f (g2018 x) @[simp] axiom s2019 (x : Prop) : f (g2020 x) = f (g2019 x) @[simp] axiom s2020 (x : Prop) : f (g2021 x) = f (g2020 x) @[simp] axiom s2021 (x : Prop) : f (g2022 x) = f (g2021 x) @[simp] axiom s2022 (x : Prop) : f (g2023 x) = f (g2022 x) @[simp] axiom s2023 (x : Prop) : f (g2024 x) = f (g2023 x) @[simp] axiom s2024 (x : Prop) : f (g2025 x) = f (g2024 x) @[simp] axiom s2025 (x : Prop) : f (g2026 x) = f (g2025 x) @[simp] axiom s2026 (x : Prop) : f (g2027 x) = f (g2026 x) @[simp] axiom s2027 (x : Prop) : f (g2028 x) = f (g2027 x) @[simp] axiom s2028 (x : Prop) : f (g2029 x) = f (g2028 x) @[simp] axiom s2029 (x : Prop) : f (g2030 x) = f (g2029 x) @[simp] axiom s2030 (x : Prop) : f (g2031 x) = f (g2030 x) @[simp] axiom s2031 (x : Prop) : f (g2032 x) = f (g2031 x) @[simp] axiom s2032 (x : Prop) : f (g2033 x) = f (g2032 x) @[simp] axiom s2033 (x : Prop) : f (g2034 x) = f (g2033 x) @[simp] axiom s2034 (x : Prop) : f (g2035 x) = f (g2034 x) @[simp] axiom s2035 (x : Prop) : f (g2036 x) = f (g2035 x) @[simp] axiom s2036 (x : Prop) : f (g2037 x) = f (g2036 x) @[simp] axiom s2037 (x : Prop) : f (g2038 x) = f (g2037 x) @[simp] axiom s2038 (x : Prop) : f (g2039 x) = f (g2038 x) @[simp] axiom s2039 (x : Prop) : f (g2040 x) = f (g2039 x) @[simp] axiom s2040 (x : Prop) : f (g2041 x) = f (g2040 x) @[simp] axiom s2041 (x : Prop) : f (g2042 x) = f (g2041 x) @[simp] axiom s2042 (x : Prop) : f (g2043 x) = f (g2042 x) @[simp] axiom s2043 (x : Prop) : f (g2044 x) = f (g2043 x) @[simp] axiom s2044 (x : Prop) : f (g2045 x) = f (g2044 x) @[simp] axiom s2045 (x : Prop) : f (g2046 x) = f (g2045 x) @[simp] axiom s2046 (x : Prop) : f (g2047 x) = f (g2046 x) @[simp] axiom s2047 (x : Prop) : f (g2048 x) = f (g2047 x) @[simp] axiom s2048 (x : Prop) : f (g2049 x) = f (g2048 x) @[simp] axiom s2049 (x : Prop) : f (g2050 x) = f (g2049 x) @[simp] axiom s2050 (x : Prop) : f (g2051 x) = f (g2050 x) @[simp] axiom s2051 (x : Prop) : f (g2052 x) = f (g2051 x) @[simp] axiom s2052 (x : Prop) : f (g2053 x) = f (g2052 x) @[simp] axiom s2053 (x : Prop) : f (g2054 x) = f (g2053 x) @[simp] axiom s2054 (x : Prop) : f (g2055 x) = f (g2054 x) @[simp] axiom s2055 (x : Prop) : f (g2056 x) = f (g2055 x) @[simp] axiom s2056 (x : Prop) : f (g2057 x) = f (g2056 x) @[simp] axiom s2057 (x : Prop) : f (g2058 x) = f (g2057 x) @[simp] axiom s2058 (x : Prop) : f (g2059 x) = f (g2058 x) @[simp] axiom s2059 (x : Prop) : f (g2060 x) = f (g2059 x) @[simp] axiom s2060 (x : Prop) : f (g2061 x) = f (g2060 x) @[simp] axiom s2061 (x : Prop) : f (g2062 x) = f (g2061 x) @[simp] axiom s2062 (x : Prop) : f (g2063 x) = f (g2062 x) @[simp] axiom s2063 (x : Prop) : f (g2064 x) = f (g2063 x) @[simp] axiom s2064 (x : Prop) : f (g2065 x) = f (g2064 x) @[simp] axiom s2065 (x : Prop) : f (g2066 x) = f (g2065 x) @[simp] axiom s2066 (x : Prop) : f (g2067 x) = f (g2066 x) @[simp] axiom s2067 (x : Prop) : f (g2068 x) = f (g2067 x) @[simp] axiom s2068 (x : Prop) : f (g2069 x) = f (g2068 x) @[simp] axiom s2069 (x : Prop) : f (g2070 x) = f (g2069 x) @[simp] axiom s2070 (x : Prop) : f (g2071 x) = f (g2070 x) @[simp] axiom s2071 (x : Prop) : f (g2072 x) = f (g2071 x) @[simp] axiom s2072 (x : Prop) : f (g2073 x) = f (g2072 x) @[simp] axiom s2073 (x : Prop) : f (g2074 x) = f (g2073 x) @[simp] axiom s2074 (x : Prop) : f (g2075 x) = f (g2074 x) @[simp] axiom s2075 (x : Prop) : f (g2076 x) = f (g2075 x) @[simp] axiom s2076 (x : Prop) : f (g2077 x) = f (g2076 x) @[simp] axiom s2077 (x : Prop) : f (g2078 x) = f (g2077 x) @[simp] axiom s2078 (x : Prop) : f (g2079 x) = f (g2078 x) @[simp] axiom s2079 (x : Prop) : f (g2080 x) = f (g2079 x) @[simp] axiom s2080 (x : Prop) : f (g2081 x) = f (g2080 x) @[simp] axiom s2081 (x : Prop) : f (g2082 x) = f (g2081 x) @[simp] axiom s2082 (x : Prop) : f (g2083 x) = f (g2082 x) @[simp] axiom s2083 (x : Prop) : f (g2084 x) = f (g2083 x) @[simp] axiom s2084 (x : Prop) : f (g2085 x) = f (g2084 x) @[simp] axiom s2085 (x : Prop) : f (g2086 x) = f (g2085 x) @[simp] axiom s2086 (x : Prop) : f (g2087 x) = f (g2086 x) @[simp] axiom s2087 (x : Prop) : f (g2088 x) = f (g2087 x) @[simp] axiom s2088 (x : Prop) : f (g2089 x) = f (g2088 x) @[simp] axiom s2089 (x : Prop) : f (g2090 x) = f (g2089 x) @[simp] axiom s2090 (x : Prop) : f (g2091 x) = f (g2090 x) @[simp] axiom s2091 (x : Prop) : f (g2092 x) = f (g2091 x) @[simp] axiom s2092 (x : Prop) : f (g2093 x) = f (g2092 x) @[simp] axiom s2093 (x : Prop) : f (g2094 x) = f (g2093 x) @[simp] axiom s2094 (x : Prop) : f (g2095 x) = f (g2094 x) @[simp] axiom s2095 (x : Prop) : f (g2096 x) = f (g2095 x) @[simp] axiom s2096 (x : Prop) : f (g2097 x) = f (g2096 x) @[simp] axiom s2097 (x : Prop) : f (g2098 x) = f (g2097 x) @[simp] axiom s2098 (x : Prop) : f (g2099 x) = f (g2098 x) @[simp] axiom s2099 (x : Prop) : f (g2100 x) = f (g2099 x) @[simp] axiom s2100 (x : Prop) : f (g2101 x) = f (g2100 x) @[simp] axiom s2101 (x : Prop) : f (g2102 x) = f (g2101 x) @[simp] axiom s2102 (x : Prop) : f (g2103 x) = f (g2102 x) @[simp] axiom s2103 (x : Prop) : f (g2104 x) = f (g2103 x) @[simp] axiom s2104 (x : Prop) : f (g2105 x) = f (g2104 x) @[simp] axiom s2105 (x : Prop) : f (g2106 x) = f (g2105 x) @[simp] axiom s2106 (x : Prop) : f (g2107 x) = f (g2106 x) @[simp] axiom s2107 (x : Prop) : f (g2108 x) = f (g2107 x) @[simp] axiom s2108 (x : Prop) : f (g2109 x) = f (g2108 x) @[simp] axiom s2109 (x : Prop) : f (g2110 x) = f (g2109 x) @[simp] axiom s2110 (x : Prop) : f (g2111 x) = f (g2110 x) @[simp] axiom s2111 (x : Prop) : f (g2112 x) = f (g2111 x) @[simp] axiom s2112 (x : Prop) : f (g2113 x) = f (g2112 x) @[simp] axiom s2113 (x : Prop) : f (g2114 x) = f (g2113 x) @[simp] axiom s2114 (x : Prop) : f (g2115 x) = f (g2114 x) @[simp] axiom s2115 (x : Prop) : f (g2116 x) = f (g2115 x) @[simp] axiom s2116 (x : Prop) : f (g2117 x) = f (g2116 x) @[simp] axiom s2117 (x : Prop) : f (g2118 x) = f (g2117 x) @[simp] axiom s2118 (x : Prop) : f (g2119 x) = f (g2118 x) @[simp] axiom s2119 (x : Prop) : f (g2120 x) = f (g2119 x) @[simp] axiom s2120 (x : Prop) : f (g2121 x) = f (g2120 x) @[simp] axiom s2121 (x : Prop) : f (g2122 x) = f (g2121 x) @[simp] axiom s2122 (x : Prop) : f (g2123 x) = f (g2122 x) @[simp] axiom s2123 (x : Prop) : f (g2124 x) = f (g2123 x) @[simp] axiom s2124 (x : Prop) : f (g2125 x) = f (g2124 x) @[simp] axiom s2125 (x : Prop) : f (g2126 x) = f (g2125 x) @[simp] axiom s2126 (x : Prop) : f (g2127 x) = f (g2126 x) @[simp] axiom s2127 (x : Prop) : f (g2128 x) = f (g2127 x) @[simp] axiom s2128 (x : Prop) : f (g2129 x) = f (g2128 x) @[simp] axiom s2129 (x : Prop) : f (g2130 x) = f (g2129 x) @[simp] axiom s2130 (x : Prop) : f (g2131 x) = f (g2130 x) @[simp] axiom s2131 (x : Prop) : f (g2132 x) = f (g2131 x) @[simp] axiom s2132 (x : Prop) : f (g2133 x) = f (g2132 x) @[simp] axiom s2133 (x : Prop) : f (g2134 x) = f (g2133 x) @[simp] axiom s2134 (x : Prop) : f (g2135 x) = f (g2134 x) @[simp] axiom s2135 (x : Prop) : f (g2136 x) = f (g2135 x) @[simp] axiom s2136 (x : Prop) : f (g2137 x) = f (g2136 x) @[simp] axiom s2137 (x : Prop) : f (g2138 x) = f (g2137 x) @[simp] axiom s2138 (x : Prop) : f (g2139 x) = f (g2138 x) @[simp] axiom s2139 (x : Prop) : f (g2140 x) = f (g2139 x) @[simp] axiom s2140 (x : Prop) : f (g2141 x) = f (g2140 x) @[simp] axiom s2141 (x : Prop) : f (g2142 x) = f (g2141 x) @[simp] axiom s2142 (x : Prop) : f (g2143 x) = f (g2142 x) @[simp] axiom s2143 (x : Prop) : f (g2144 x) = f (g2143 x) @[simp] axiom s2144 (x : Prop) : f (g2145 x) = f (g2144 x) @[simp] axiom s2145 (x : Prop) : f (g2146 x) = f (g2145 x) @[simp] axiom s2146 (x : Prop) : f (g2147 x) = f (g2146 x) @[simp] axiom s2147 (x : Prop) : f (g2148 x) = f (g2147 x) @[simp] axiom s2148 (x : Prop) : f (g2149 x) = f (g2148 x) @[simp] axiom s2149 (x : Prop) : f (g2150 x) = f (g2149 x) @[simp] axiom s2150 (x : Prop) : f (g2151 x) = f (g2150 x) @[simp] axiom s2151 (x : Prop) : f (g2152 x) = f (g2151 x) @[simp] axiom s2152 (x : Prop) : f (g2153 x) = f (g2152 x) @[simp] axiom s2153 (x : Prop) : f (g2154 x) = f (g2153 x) @[simp] axiom s2154 (x : Prop) : f (g2155 x) = f (g2154 x) @[simp] axiom s2155 (x : Prop) : f (g2156 x) = f (g2155 x) @[simp] axiom s2156 (x : Prop) : f (g2157 x) = f (g2156 x) @[simp] axiom s2157 (x : Prop) : f (g2158 x) = f (g2157 x) @[simp] axiom s2158 (x : Prop) : f (g2159 x) = f (g2158 x) @[simp] axiom s2159 (x : Prop) : f (g2160 x) = f (g2159 x) @[simp] axiom s2160 (x : Prop) : f (g2161 x) = f (g2160 x) @[simp] axiom s2161 (x : Prop) : f (g2162 x) = f (g2161 x) @[simp] axiom s2162 (x : Prop) : f (g2163 x) = f (g2162 x) @[simp] axiom s2163 (x : Prop) : f (g2164 x) = f (g2163 x) @[simp] axiom s2164 (x : Prop) : f (g2165 x) = f (g2164 x) @[simp] axiom s2165 (x : Prop) : f (g2166 x) = f (g2165 x) @[simp] axiom s2166 (x : Prop) : f (g2167 x) = f (g2166 x) @[simp] axiom s2167 (x : Prop) : f (g2168 x) = f (g2167 x) @[simp] axiom s2168 (x : Prop) : f (g2169 x) = f (g2168 x) @[simp] axiom s2169 (x : Prop) : f (g2170 x) = f (g2169 x) @[simp] axiom s2170 (x : Prop) : f (g2171 x) = f (g2170 x) @[simp] axiom s2171 (x : Prop) : f (g2172 x) = f (g2171 x) @[simp] axiom s2172 (x : Prop) : f (g2173 x) = f (g2172 x) @[simp] axiom s2173 (x : Prop) : f (g2174 x) = f (g2173 x) @[simp] axiom s2174 (x : Prop) : f (g2175 x) = f (g2174 x) @[simp] axiom s2175 (x : Prop) : f (g2176 x) = f (g2175 x) @[simp] axiom s2176 (x : Prop) : f (g2177 x) = f (g2176 x) @[simp] axiom s2177 (x : Prop) : f (g2178 x) = f (g2177 x) @[simp] axiom s2178 (x : Prop) : f (g2179 x) = f (g2178 x) @[simp] axiom s2179 (x : Prop) : f (g2180 x) = f (g2179 x) @[simp] axiom s2180 (x : Prop) : f (g2181 x) = f (g2180 x) @[simp] axiom s2181 (x : Prop) : f (g2182 x) = f (g2181 x) @[simp] axiom s2182 (x : Prop) : f (g2183 x) = f (g2182 x) @[simp] axiom s2183 (x : Prop) : f (g2184 x) = f (g2183 x) @[simp] axiom s2184 (x : Prop) : f (g2185 x) = f (g2184 x) @[simp] axiom s2185 (x : Prop) : f (g2186 x) = f (g2185 x) @[simp] axiom s2186 (x : Prop) : f (g2187 x) = f (g2186 x) @[simp] axiom s2187 (x : Prop) : f (g2188 x) = f (g2187 x) @[simp] axiom s2188 (x : Prop) : f (g2189 x) = f (g2188 x) @[simp] axiom s2189 (x : Prop) : f (g2190 x) = f (g2189 x) @[simp] axiom s2190 (x : Prop) : f (g2191 x) = f (g2190 x) @[simp] axiom s2191 (x : Prop) : f (g2192 x) = f (g2191 x) @[simp] axiom s2192 (x : Prop) : f (g2193 x) = f (g2192 x) @[simp] axiom s2193 (x : Prop) : f (g2194 x) = f (g2193 x) @[simp] axiom s2194 (x : Prop) : f (g2195 x) = f (g2194 x) @[simp] axiom s2195 (x : Prop) : f (g2196 x) = f (g2195 x) @[simp] axiom s2196 (x : Prop) : f (g2197 x) = f (g2196 x) @[simp] axiom s2197 (x : Prop) : f (g2198 x) = f (g2197 x) @[simp] axiom s2198 (x : Prop) : f (g2199 x) = f (g2198 x) @[simp] axiom s2199 (x : Prop) : f (g2200 x) = f (g2199 x) @[simp] axiom s2200 (x : Prop) : f (g2201 x) = f (g2200 x) @[simp] axiom s2201 (x : Prop) : f (g2202 x) = f (g2201 x) @[simp] axiom s2202 (x : Prop) : f (g2203 x) = f (g2202 x) @[simp] axiom s2203 (x : Prop) : f (g2204 x) = f (g2203 x) @[simp] axiom s2204 (x : Prop) : f (g2205 x) = f (g2204 x) @[simp] axiom s2205 (x : Prop) : f (g2206 x) = f (g2205 x) @[simp] axiom s2206 (x : Prop) : f (g2207 x) = f (g2206 x) @[simp] axiom s2207 (x : Prop) : f (g2208 x) = f (g2207 x) @[simp] axiom s2208 (x : Prop) : f (g2209 x) = f (g2208 x) @[simp] axiom s2209 (x : Prop) : f (g2210 x) = f (g2209 x) @[simp] axiom s2210 (x : Prop) : f (g2211 x) = f (g2210 x) @[simp] axiom s2211 (x : Prop) : f (g2212 x) = f (g2211 x) @[simp] axiom s2212 (x : Prop) : f (g2213 x) = f (g2212 x) @[simp] axiom s2213 (x : Prop) : f (g2214 x) = f (g2213 x) @[simp] axiom s2214 (x : Prop) : f (g2215 x) = f (g2214 x) @[simp] axiom s2215 (x : Prop) : f (g2216 x) = f (g2215 x) @[simp] axiom s2216 (x : Prop) : f (g2217 x) = f (g2216 x) @[simp] axiom s2217 (x : Prop) : f (g2218 x) = f (g2217 x) @[simp] axiom s2218 (x : Prop) : f (g2219 x) = f (g2218 x) @[simp] axiom s2219 (x : Prop) : f (g2220 x) = f (g2219 x) @[simp] axiom s2220 (x : Prop) : f (g2221 x) = f (g2220 x) @[simp] axiom s2221 (x : Prop) : f (g2222 x) = f (g2221 x) @[simp] axiom s2222 (x : Prop) : f (g2223 x) = f (g2222 x) @[simp] axiom s2223 (x : Prop) : f (g2224 x) = f (g2223 x) @[simp] axiom s2224 (x : Prop) : f (g2225 x) = f (g2224 x) @[simp] axiom s2225 (x : Prop) : f (g2226 x) = f (g2225 x) @[simp] axiom s2226 (x : Prop) : f (g2227 x) = f (g2226 x) @[simp] axiom s2227 (x : Prop) : f (g2228 x) = f (g2227 x) @[simp] axiom s2228 (x : Prop) : f (g2229 x) = f (g2228 x) @[simp] axiom s2229 (x : Prop) : f (g2230 x) = f (g2229 x) @[simp] axiom s2230 (x : Prop) : f (g2231 x) = f (g2230 x) @[simp] axiom s2231 (x : Prop) : f (g2232 x) = f (g2231 x) @[simp] axiom s2232 (x : Prop) : f (g2233 x) = f (g2232 x) @[simp] axiom s2233 (x : Prop) : f (g2234 x) = f (g2233 x) @[simp] axiom s2234 (x : Prop) : f (g2235 x) = f (g2234 x) @[simp] axiom s2235 (x : Prop) : f (g2236 x) = f (g2235 x) @[simp] axiom s2236 (x : Prop) : f (g2237 x) = f (g2236 x) @[simp] axiom s2237 (x : Prop) : f (g2238 x) = f (g2237 x) @[simp] axiom s2238 (x : Prop) : f (g2239 x) = f (g2238 x) @[simp] axiom s2239 (x : Prop) : f (g2240 x) = f (g2239 x) @[simp] axiom s2240 (x : Prop) : f (g2241 x) = f (g2240 x) @[simp] axiom s2241 (x : Prop) : f (g2242 x) = f (g2241 x) @[simp] axiom s2242 (x : Prop) : f (g2243 x) = f (g2242 x) @[simp] axiom s2243 (x : Prop) : f (g2244 x) = f (g2243 x) @[simp] axiom s2244 (x : Prop) : f (g2245 x) = f (g2244 x) @[simp] axiom s2245 (x : Prop) : f (g2246 x) = f (g2245 x) @[simp] axiom s2246 (x : Prop) : f (g2247 x) = f (g2246 x) @[simp] axiom s2247 (x : Prop) : f (g2248 x) = f (g2247 x) @[simp] axiom s2248 (x : Prop) : f (g2249 x) = f (g2248 x) @[simp] axiom s2249 (x : Prop) : f (g2250 x) = f (g2249 x) @[simp] axiom s2250 (x : Prop) : f (g2251 x) = f (g2250 x) @[simp] axiom s2251 (x : Prop) : f (g2252 x) = f (g2251 x) @[simp] axiom s2252 (x : Prop) : f (g2253 x) = f (g2252 x) @[simp] axiom s2253 (x : Prop) : f (g2254 x) = f (g2253 x) @[simp] axiom s2254 (x : Prop) : f (g2255 x) = f (g2254 x) @[simp] axiom s2255 (x : Prop) : f (g2256 x) = f (g2255 x) @[simp] axiom s2256 (x : Prop) : f (g2257 x) = f (g2256 x) @[simp] axiom s2257 (x : Prop) : f (g2258 x) = f (g2257 x) @[simp] axiom s2258 (x : Prop) : f (g2259 x) = f (g2258 x) @[simp] axiom s2259 (x : Prop) : f (g2260 x) = f (g2259 x) @[simp] axiom s2260 (x : Prop) : f (g2261 x) = f (g2260 x) @[simp] axiom s2261 (x : Prop) : f (g2262 x) = f (g2261 x) @[simp] axiom s2262 (x : Prop) : f (g2263 x) = f (g2262 x) @[simp] axiom s2263 (x : Prop) : f (g2264 x) = f (g2263 x) @[simp] axiom s2264 (x : Prop) : f (g2265 x) = f (g2264 x) @[simp] axiom s2265 (x : Prop) : f (g2266 x) = f (g2265 x) @[simp] axiom s2266 (x : Prop) : f (g2267 x) = f (g2266 x) @[simp] axiom s2267 (x : Prop) : f (g2268 x) = f (g2267 x) @[simp] axiom s2268 (x : Prop) : f (g2269 x) = f (g2268 x) @[simp] axiom s2269 (x : Prop) : f (g2270 x) = f (g2269 x) @[simp] axiom s2270 (x : Prop) : f (g2271 x) = f (g2270 x) @[simp] axiom s2271 (x : Prop) : f (g2272 x) = f (g2271 x) @[simp] axiom s2272 (x : Prop) : f (g2273 x) = f (g2272 x) @[simp] axiom s2273 (x : Prop) : f (g2274 x) = f (g2273 x) @[simp] axiom s2274 (x : Prop) : f (g2275 x) = f (g2274 x) @[simp] axiom s2275 (x : Prop) : f (g2276 x) = f (g2275 x) @[simp] axiom s2276 (x : Prop) : f (g2277 x) = f (g2276 x) @[simp] axiom s2277 (x : Prop) : f (g2278 x) = f (g2277 x) @[simp] axiom s2278 (x : Prop) : f (g2279 x) = f (g2278 x) @[simp] axiom s2279 (x : Prop) : f (g2280 x) = f (g2279 x) @[simp] axiom s2280 (x : Prop) : f (g2281 x) = f (g2280 x) @[simp] axiom s2281 (x : Prop) : f (g2282 x) = f (g2281 x) @[simp] axiom s2282 (x : Prop) : f (g2283 x) = f (g2282 x) @[simp] axiom s2283 (x : Prop) : f (g2284 x) = f (g2283 x) @[simp] axiom s2284 (x : Prop) : f (g2285 x) = f (g2284 x) @[simp] axiom s2285 (x : Prop) : f (g2286 x) = f (g2285 x) @[simp] axiom s2286 (x : Prop) : f (g2287 x) = f (g2286 x) @[simp] axiom s2287 (x : Prop) : f (g2288 x) = f (g2287 x) @[simp] axiom s2288 (x : Prop) : f (g2289 x) = f (g2288 x) @[simp] axiom s2289 (x : Prop) : f (g2290 x) = f (g2289 x) @[simp] axiom s2290 (x : Prop) : f (g2291 x) = f (g2290 x) @[simp] axiom s2291 (x : Prop) : f (g2292 x) = f (g2291 x) @[simp] axiom s2292 (x : Prop) : f (g2293 x) = f (g2292 x) @[simp] axiom s2293 (x : Prop) : f (g2294 x) = f (g2293 x) @[simp] axiom s2294 (x : Prop) : f (g2295 x) = f (g2294 x) @[simp] axiom s2295 (x : Prop) : f (g2296 x) = f (g2295 x) @[simp] axiom s2296 (x : Prop) : f (g2297 x) = f (g2296 x) @[simp] axiom s2297 (x : Prop) : f (g2298 x) = f (g2297 x) @[simp] axiom s2298 (x : Prop) : f (g2299 x) = f (g2298 x) @[simp] axiom s2299 (x : Prop) : f (g2300 x) = f (g2299 x) @[simp] axiom s2300 (x : Prop) : f (g2301 x) = f (g2300 x) @[simp] axiom s2301 (x : Prop) : f (g2302 x) = f (g2301 x) @[simp] axiom s2302 (x : Prop) : f (g2303 x) = f (g2302 x) @[simp] axiom s2303 (x : Prop) : f (g2304 x) = f (g2303 x) @[simp] axiom s2304 (x : Prop) : f (g2305 x) = f (g2304 x) @[simp] axiom s2305 (x : Prop) : f (g2306 x) = f (g2305 x) @[simp] axiom s2306 (x : Prop) : f (g2307 x) = f (g2306 x) @[simp] axiom s2307 (x : Prop) : f (g2308 x) = f (g2307 x) @[simp] axiom s2308 (x : Prop) : f (g2309 x) = f (g2308 x) @[simp] axiom s2309 (x : Prop) : f (g2310 x) = f (g2309 x) @[simp] axiom s2310 (x : Prop) : f (g2311 x) = f (g2310 x) @[simp] axiom s2311 (x : Prop) : f (g2312 x) = f (g2311 x) @[simp] axiom s2312 (x : Prop) : f (g2313 x) = f (g2312 x) @[simp] axiom s2313 (x : Prop) : f (g2314 x) = f (g2313 x) @[simp] axiom s2314 (x : Prop) : f (g2315 x) = f (g2314 x) @[simp] axiom s2315 (x : Prop) : f (g2316 x) = f (g2315 x) @[simp] axiom s2316 (x : Prop) : f (g2317 x) = f (g2316 x) @[simp] axiom s2317 (x : Prop) : f (g2318 x) = f (g2317 x) @[simp] axiom s2318 (x : Prop) : f (g2319 x) = f (g2318 x) @[simp] axiom s2319 (x : Prop) : f (g2320 x) = f (g2319 x) @[simp] axiom s2320 (x : Prop) : f (g2321 x) = f (g2320 x) @[simp] axiom s2321 (x : Prop) : f (g2322 x) = f (g2321 x) @[simp] axiom s2322 (x : Prop) : f (g2323 x) = f (g2322 x) @[simp] axiom s2323 (x : Prop) : f (g2324 x) = f (g2323 x) @[simp] axiom s2324 (x : Prop) : f (g2325 x) = f (g2324 x) @[simp] axiom s2325 (x : Prop) : f (g2326 x) = f (g2325 x) @[simp] axiom s2326 (x : Prop) : f (g2327 x) = f (g2326 x) @[simp] axiom s2327 (x : Prop) : f (g2328 x) = f (g2327 x) @[simp] axiom s2328 (x : Prop) : f (g2329 x) = f (g2328 x) @[simp] axiom s2329 (x : Prop) : f (g2330 x) = f (g2329 x) @[simp] axiom s2330 (x : Prop) : f (g2331 x) = f (g2330 x) @[simp] axiom s2331 (x : Prop) : f (g2332 x) = f (g2331 x) @[simp] axiom s2332 (x : Prop) : f (g2333 x) = f (g2332 x) @[simp] axiom s2333 (x : Prop) : f (g2334 x) = f (g2333 x) @[simp] axiom s2334 (x : Prop) : f (g2335 x) = f (g2334 x) @[simp] axiom s2335 (x : Prop) : f (g2336 x) = f (g2335 x) @[simp] axiom s2336 (x : Prop) : f (g2337 x) = f (g2336 x) @[simp] axiom s2337 (x : Prop) : f (g2338 x) = f (g2337 x) @[simp] axiom s2338 (x : Prop) : f (g2339 x) = f (g2338 x) @[simp] axiom s2339 (x : Prop) : f (g2340 x) = f (g2339 x) @[simp] axiom s2340 (x : Prop) : f (g2341 x) = f (g2340 x) @[simp] axiom s2341 (x : Prop) : f (g2342 x) = f (g2341 x) @[simp] axiom s2342 (x : Prop) : f (g2343 x) = f (g2342 x) @[simp] axiom s2343 (x : Prop) : f (g2344 x) = f (g2343 x) @[simp] axiom s2344 (x : Prop) : f (g2345 x) = f (g2344 x) @[simp] axiom s2345 (x : Prop) : f (g2346 x) = f (g2345 x) @[simp] axiom s2346 (x : Prop) : f (g2347 x) = f (g2346 x) @[simp] axiom s2347 (x : Prop) : f (g2348 x) = f (g2347 x) @[simp] axiom s2348 (x : Prop) : f (g2349 x) = f (g2348 x) @[simp] axiom s2349 (x : Prop) : f (g2350 x) = f (g2349 x) @[simp] axiom s2350 (x : Prop) : f (g2351 x) = f (g2350 x) @[simp] axiom s2351 (x : Prop) : f (g2352 x) = f (g2351 x) @[simp] axiom s2352 (x : Prop) : f (g2353 x) = f (g2352 x) @[simp] axiom s2353 (x : Prop) : f (g2354 x) = f (g2353 x) @[simp] axiom s2354 (x : Prop) : f (g2355 x) = f (g2354 x) @[simp] axiom s2355 (x : Prop) : f (g2356 x) = f (g2355 x) @[simp] axiom s2356 (x : Prop) : f (g2357 x) = f (g2356 x) @[simp] axiom s2357 (x : Prop) : f (g2358 x) = f (g2357 x) @[simp] axiom s2358 (x : Prop) : f (g2359 x) = f (g2358 x) @[simp] axiom s2359 (x : Prop) : f (g2360 x) = f (g2359 x) @[simp] axiom s2360 (x : Prop) : f (g2361 x) = f (g2360 x) @[simp] axiom s2361 (x : Prop) : f (g2362 x) = f (g2361 x) @[simp] axiom s2362 (x : Prop) : f (g2363 x) = f (g2362 x) @[simp] axiom s2363 (x : Prop) : f (g2364 x) = f (g2363 x) @[simp] axiom s2364 (x : Prop) : f (g2365 x) = f (g2364 x) @[simp] axiom s2365 (x : Prop) : f (g2366 x) = f (g2365 x) @[simp] axiom s2366 (x : Prop) : f (g2367 x) = f (g2366 x) @[simp] axiom s2367 (x : Prop) : f (g2368 x) = f (g2367 x) @[simp] axiom s2368 (x : Prop) : f (g2369 x) = f (g2368 x) @[simp] axiom s2369 (x : Prop) : f (g2370 x) = f (g2369 x) @[simp] axiom s2370 (x : Prop) : f (g2371 x) = f (g2370 x) @[simp] axiom s2371 (x : Prop) : f (g2372 x) = f (g2371 x) @[simp] axiom s2372 (x : Prop) : f (g2373 x) = f (g2372 x) @[simp] axiom s2373 (x : Prop) : f (g2374 x) = f (g2373 x) @[simp] axiom s2374 (x : Prop) : f (g2375 x) = f (g2374 x) @[simp] axiom s2375 (x : Prop) : f (g2376 x) = f (g2375 x) @[simp] axiom s2376 (x : Prop) : f (g2377 x) = f (g2376 x) @[simp] axiom s2377 (x : Prop) : f (g2378 x) = f (g2377 x) @[simp] axiom s2378 (x : Prop) : f (g2379 x) = f (g2378 x) @[simp] axiom s2379 (x : Prop) : f (g2380 x) = f (g2379 x) @[simp] axiom s2380 (x : Prop) : f (g2381 x) = f (g2380 x) @[simp] axiom s2381 (x : Prop) : f (g2382 x) = f (g2381 x) @[simp] axiom s2382 (x : Prop) : f (g2383 x) = f (g2382 x) @[simp] axiom s2383 (x : Prop) : f (g2384 x) = f (g2383 x) @[simp] axiom s2384 (x : Prop) : f (g2385 x) = f (g2384 x) @[simp] axiom s2385 (x : Prop) : f (g2386 x) = f (g2385 x) @[simp] axiom s2386 (x : Prop) : f (g2387 x) = f (g2386 x) @[simp] axiom s2387 (x : Prop) : f (g2388 x) = f (g2387 x) @[simp] axiom s2388 (x : Prop) : f (g2389 x) = f (g2388 x) @[simp] axiom s2389 (x : Prop) : f (g2390 x) = f (g2389 x) @[simp] axiom s2390 (x : Prop) : f (g2391 x) = f (g2390 x) @[simp] axiom s2391 (x : Prop) : f (g2392 x) = f (g2391 x) @[simp] axiom s2392 (x : Prop) : f (g2393 x) = f (g2392 x) @[simp] axiom s2393 (x : Prop) : f (g2394 x) = f (g2393 x) @[simp] axiom s2394 (x : Prop) : f (g2395 x) = f (g2394 x) @[simp] axiom s2395 (x : Prop) : f (g2396 x) = f (g2395 x) @[simp] axiom s2396 (x : Prop) : f (g2397 x) = f (g2396 x) @[simp] axiom s2397 (x : Prop) : f (g2398 x) = f (g2397 x) @[simp] axiom s2398 (x : Prop) : f (g2399 x) = f (g2398 x) @[simp] axiom s2399 (x : Prop) : f (g2400 x) = f (g2399 x) @[simp] axiom s2400 (x : Prop) : f (g2401 x) = f (g2400 x) @[simp] axiom s2401 (x : Prop) : f (g2402 x) = f (g2401 x) @[simp] axiom s2402 (x : Prop) : f (g2403 x) = f (g2402 x) @[simp] axiom s2403 (x : Prop) : f (g2404 x) = f (g2403 x) @[simp] axiom s2404 (x : Prop) : f (g2405 x) = f (g2404 x) @[simp] axiom s2405 (x : Prop) : f (g2406 x) = f (g2405 x) @[simp] axiom s2406 (x : Prop) : f (g2407 x) = f (g2406 x) @[simp] axiom s2407 (x : Prop) : f (g2408 x) = f (g2407 x) @[simp] axiom s2408 (x : Prop) : f (g2409 x) = f (g2408 x) @[simp] axiom s2409 (x : Prop) : f (g2410 x) = f (g2409 x) @[simp] axiom s2410 (x : Prop) : f (g2411 x) = f (g2410 x) @[simp] axiom s2411 (x : Prop) : f (g2412 x) = f (g2411 x) @[simp] axiom s2412 (x : Prop) : f (g2413 x) = f (g2412 x) @[simp] axiom s2413 (x : Prop) : f (g2414 x) = f (g2413 x) @[simp] axiom s2414 (x : Prop) : f (g2415 x) = f (g2414 x) @[simp] axiom s2415 (x : Prop) : f (g2416 x) = f (g2415 x) @[simp] axiom s2416 (x : Prop) : f (g2417 x) = f (g2416 x) @[simp] axiom s2417 (x : Prop) : f (g2418 x) = f (g2417 x) @[simp] axiom s2418 (x : Prop) : f (g2419 x) = f (g2418 x) @[simp] axiom s2419 (x : Prop) : f (g2420 x) = f (g2419 x) @[simp] axiom s2420 (x : Prop) : f (g2421 x) = f (g2420 x) @[simp] axiom s2421 (x : Prop) : f (g2422 x) = f (g2421 x) @[simp] axiom s2422 (x : Prop) : f (g2423 x) = f (g2422 x) @[simp] axiom s2423 (x : Prop) : f (g2424 x) = f (g2423 x) @[simp] axiom s2424 (x : Prop) : f (g2425 x) = f (g2424 x) @[simp] axiom s2425 (x : Prop) : f (g2426 x) = f (g2425 x) @[simp] axiom s2426 (x : Prop) : f (g2427 x) = f (g2426 x) @[simp] axiom s2427 (x : Prop) : f (g2428 x) = f (g2427 x) @[simp] axiom s2428 (x : Prop) : f (g2429 x) = f (g2428 x) @[simp] axiom s2429 (x : Prop) : f (g2430 x) = f (g2429 x) @[simp] axiom s2430 (x : Prop) : f (g2431 x) = f (g2430 x) @[simp] axiom s2431 (x : Prop) : f (g2432 x) = f (g2431 x) @[simp] axiom s2432 (x : Prop) : f (g2433 x) = f (g2432 x) @[simp] axiom s2433 (x : Prop) : f (g2434 x) = f (g2433 x) @[simp] axiom s2434 (x : Prop) : f (g2435 x) = f (g2434 x) @[simp] axiom s2435 (x : Prop) : f (g2436 x) = f (g2435 x) @[simp] axiom s2436 (x : Prop) : f (g2437 x) = f (g2436 x) @[simp] axiom s2437 (x : Prop) : f (g2438 x) = f (g2437 x) @[simp] axiom s2438 (x : Prop) : f (g2439 x) = f (g2438 x) @[simp] axiom s2439 (x : Prop) : f (g2440 x) = f (g2439 x) @[simp] axiom s2440 (x : Prop) : f (g2441 x) = f (g2440 x) @[simp] axiom s2441 (x : Prop) : f (g2442 x) = f (g2441 x) @[simp] axiom s2442 (x : Prop) : f (g2443 x) = f (g2442 x) @[simp] axiom s2443 (x : Prop) : f (g2444 x) = f (g2443 x) @[simp] axiom s2444 (x : Prop) : f (g2445 x) = f (g2444 x) @[simp] axiom s2445 (x : Prop) : f (g2446 x) = f (g2445 x) @[simp] axiom s2446 (x : Prop) : f (g2447 x) = f (g2446 x) @[simp] axiom s2447 (x : Prop) : f (g2448 x) = f (g2447 x) @[simp] axiom s2448 (x : Prop) : f (g2449 x) = f (g2448 x) @[simp] axiom s2449 (x : Prop) : f (g2450 x) = f (g2449 x) @[simp] axiom s2450 (x : Prop) : f (g2451 x) = f (g2450 x) @[simp] axiom s2451 (x : Prop) : f (g2452 x) = f (g2451 x) @[simp] axiom s2452 (x : Prop) : f (g2453 x) = f (g2452 x) @[simp] axiom s2453 (x : Prop) : f (g2454 x) = f (g2453 x) @[simp] axiom s2454 (x : Prop) : f (g2455 x) = f (g2454 x) @[simp] axiom s2455 (x : Prop) : f (g2456 x) = f (g2455 x) @[simp] axiom s2456 (x : Prop) : f (g2457 x) = f (g2456 x) @[simp] axiom s2457 (x : Prop) : f (g2458 x) = f (g2457 x) @[simp] axiom s2458 (x : Prop) : f (g2459 x) = f (g2458 x) @[simp] axiom s2459 (x : Prop) : f (g2460 x) = f (g2459 x) @[simp] axiom s2460 (x : Prop) : f (g2461 x) = f (g2460 x) @[simp] axiom s2461 (x : Prop) : f (g2462 x) = f (g2461 x) @[simp] axiom s2462 (x : Prop) : f (g2463 x) = f (g2462 x) @[simp] axiom s2463 (x : Prop) : f (g2464 x) = f (g2463 x) @[simp] axiom s2464 (x : Prop) : f (g2465 x) = f (g2464 x) @[simp] axiom s2465 (x : Prop) : f (g2466 x) = f (g2465 x) @[simp] axiom s2466 (x : Prop) : f (g2467 x) = f (g2466 x) @[simp] axiom s2467 (x : Prop) : f (g2468 x) = f (g2467 x) @[simp] axiom s2468 (x : Prop) : f (g2469 x) = f (g2468 x) @[simp] axiom s2469 (x : Prop) : f (g2470 x) = f (g2469 x) @[simp] axiom s2470 (x : Prop) : f (g2471 x) = f (g2470 x) @[simp] axiom s2471 (x : Prop) : f (g2472 x) = f (g2471 x) @[simp] axiom s2472 (x : Prop) : f (g2473 x) = f (g2472 x) @[simp] axiom s2473 (x : Prop) : f (g2474 x) = f (g2473 x) @[simp] axiom s2474 (x : Prop) : f (g2475 x) = f (g2474 x) @[simp] axiom s2475 (x : Prop) : f (g2476 x) = f (g2475 x) @[simp] axiom s2476 (x : Prop) : f (g2477 x) = f (g2476 x) @[simp] axiom s2477 (x : Prop) : f (g2478 x) = f (g2477 x) @[simp] axiom s2478 (x : Prop) : f (g2479 x) = f (g2478 x) @[simp] axiom s2479 (x : Prop) : f (g2480 x) = f (g2479 x) @[simp] axiom s2480 (x : Prop) : f (g2481 x) = f (g2480 x) @[simp] axiom s2481 (x : Prop) : f (g2482 x) = f (g2481 x) @[simp] axiom s2482 (x : Prop) : f (g2483 x) = f (g2482 x) @[simp] axiom s2483 (x : Prop) : f (g2484 x) = f (g2483 x) @[simp] axiom s2484 (x : Prop) : f (g2485 x) = f (g2484 x) @[simp] axiom s2485 (x : Prop) : f (g2486 x) = f (g2485 x) @[simp] axiom s2486 (x : Prop) : f (g2487 x) = f (g2486 x) @[simp] axiom s2487 (x : Prop) : f (g2488 x) = f (g2487 x) @[simp] axiom s2488 (x : Prop) : f (g2489 x) = f (g2488 x) @[simp] axiom s2489 (x : Prop) : f (g2490 x) = f (g2489 x) @[simp] axiom s2490 (x : Prop) : f (g2491 x) = f (g2490 x) @[simp] axiom s2491 (x : Prop) : f (g2492 x) = f (g2491 x) @[simp] axiom s2492 (x : Prop) : f (g2493 x) = f (g2492 x) @[simp] axiom s2493 (x : Prop) : f (g2494 x) = f (g2493 x) @[simp] axiom s2494 (x : Prop) : f (g2495 x) = f (g2494 x) @[simp] axiom s2495 (x : Prop) : f (g2496 x) = f (g2495 x) @[simp] axiom s2496 (x : Prop) : f (g2497 x) = f (g2496 x) @[simp] axiom s2497 (x : Prop) : f (g2498 x) = f (g2497 x) @[simp] axiom s2498 (x : Prop) : f (g2499 x) = f (g2498 x) @[simp] axiom s2499 (x : Prop) : f (g2500 x) = f (g2499 x) @[simp] axiom s2500 (x : Prop) : f (g2501 x) = f (g2500 x) @[simp] axiom s2501 (x : Prop) : f (g2502 x) = f (g2501 x) @[simp] axiom s2502 (x : Prop) : f (g2503 x) = f (g2502 x) @[simp] axiom s2503 (x : Prop) : f (g2504 x) = f (g2503 x) @[simp] axiom s2504 (x : Prop) : f (g2505 x) = f (g2504 x) @[simp] axiom s2505 (x : Prop) : f (g2506 x) = f (g2505 x) @[simp] axiom s2506 (x : Prop) : f (g2507 x) = f (g2506 x) @[simp] axiom s2507 (x : Prop) : f (g2508 x) = f (g2507 x) @[simp] axiom s2508 (x : Prop) : f (g2509 x) = f (g2508 x) @[simp] axiom s2509 (x : Prop) : f (g2510 x) = f (g2509 x) @[simp] axiom s2510 (x : Prop) : f (g2511 x) = f (g2510 x) @[simp] axiom s2511 (x : Prop) : f (g2512 x) = f (g2511 x) @[simp] axiom s2512 (x : Prop) : f (g2513 x) = f (g2512 x) @[simp] axiom s2513 (x : Prop) : f (g2514 x) = f (g2513 x) @[simp] axiom s2514 (x : Prop) : f (g2515 x) = f (g2514 x) @[simp] axiom s2515 (x : Prop) : f (g2516 x) = f (g2515 x) @[simp] axiom s2516 (x : Prop) : f (g2517 x) = f (g2516 x) @[simp] axiom s2517 (x : Prop) : f (g2518 x) = f (g2517 x) @[simp] axiom s2518 (x : Prop) : f (g2519 x) = f (g2518 x) @[simp] axiom s2519 (x : Prop) : f (g2520 x) = f (g2519 x) @[simp] axiom s2520 (x : Prop) : f (g2521 x) = f (g2520 x) @[simp] axiom s2521 (x : Prop) : f (g2522 x) = f (g2521 x) @[simp] axiom s2522 (x : Prop) : f (g2523 x) = f (g2522 x) @[simp] axiom s2523 (x : Prop) : f (g2524 x) = f (g2523 x) @[simp] axiom s2524 (x : Prop) : f (g2525 x) = f (g2524 x) @[simp] axiom s2525 (x : Prop) : f (g2526 x) = f (g2525 x) @[simp] axiom s2526 (x : Prop) : f (g2527 x) = f (g2526 x) @[simp] axiom s2527 (x : Prop) : f (g2528 x) = f (g2527 x) @[simp] axiom s2528 (x : Prop) : f (g2529 x) = f (g2528 x) @[simp] axiom s2529 (x : Prop) : f (g2530 x) = f (g2529 x) @[simp] axiom s2530 (x : Prop) : f (g2531 x) = f (g2530 x) @[simp] axiom s2531 (x : Prop) : f (g2532 x) = f (g2531 x) @[simp] axiom s2532 (x : Prop) : f (g2533 x) = f (g2532 x) @[simp] axiom s2533 (x : Prop) : f (g2534 x) = f (g2533 x) @[simp] axiom s2534 (x : Prop) : f (g2535 x) = f (g2534 x) @[simp] axiom s2535 (x : Prop) : f (g2536 x) = f (g2535 x) @[simp] axiom s2536 (x : Prop) : f (g2537 x) = f (g2536 x) @[simp] axiom s2537 (x : Prop) : f (g2538 x) = f (g2537 x) @[simp] axiom s2538 (x : Prop) : f (g2539 x) = f (g2538 x) @[simp] axiom s2539 (x : Prop) : f (g2540 x) = f (g2539 x) @[simp] axiom s2540 (x : Prop) : f (g2541 x) = f (g2540 x) @[simp] axiom s2541 (x : Prop) : f (g2542 x) = f (g2541 x) @[simp] axiom s2542 (x : Prop) : f (g2543 x) = f (g2542 x) @[simp] axiom s2543 (x : Prop) : f (g2544 x) = f (g2543 x) @[simp] axiom s2544 (x : Prop) : f (g2545 x) = f (g2544 x) @[simp] axiom s2545 (x : Prop) : f (g2546 x) = f (g2545 x) @[simp] axiom s2546 (x : Prop) : f (g2547 x) = f (g2546 x) @[simp] axiom s2547 (x : Prop) : f (g2548 x) = f (g2547 x) @[simp] axiom s2548 (x : Prop) : f (g2549 x) = f (g2548 x) @[simp] axiom s2549 (x : Prop) : f (g2550 x) = f (g2549 x) @[simp] axiom s2550 (x : Prop) : f (g2551 x) = f (g2550 x) @[simp] axiom s2551 (x : Prop) : f (g2552 x) = f (g2551 x) @[simp] axiom s2552 (x : Prop) : f (g2553 x) = f (g2552 x) @[simp] axiom s2553 (x : Prop) : f (g2554 x) = f (g2553 x) @[simp] axiom s2554 (x : Prop) : f (g2555 x) = f (g2554 x) @[simp] axiom s2555 (x : Prop) : f (g2556 x) = f (g2555 x) @[simp] axiom s2556 (x : Prop) : f (g2557 x) = f (g2556 x) @[simp] axiom s2557 (x : Prop) : f (g2558 x) = f (g2557 x) @[simp] axiom s2558 (x : Prop) : f (g2559 x) = f (g2558 x) @[simp] axiom s2559 (x : Prop) : f (g2560 x) = f (g2559 x) @[simp] axiom s2560 (x : Prop) : f (g2561 x) = f (g2560 x) @[simp] axiom s2561 (x : Prop) : f (g2562 x) = f (g2561 x) @[simp] axiom s2562 (x : Prop) : f (g2563 x) = f (g2562 x) @[simp] axiom s2563 (x : Prop) : f (g2564 x) = f (g2563 x) @[simp] axiom s2564 (x : Prop) : f (g2565 x) = f (g2564 x) @[simp] axiom s2565 (x : Prop) : f (g2566 x) = f (g2565 x) @[simp] axiom s2566 (x : Prop) : f (g2567 x) = f (g2566 x) @[simp] axiom s2567 (x : Prop) : f (g2568 x) = f (g2567 x) @[simp] axiom s2568 (x : Prop) : f (g2569 x) = f (g2568 x) @[simp] axiom s2569 (x : Prop) : f (g2570 x) = f (g2569 x) @[simp] axiom s2570 (x : Prop) : f (g2571 x) = f (g2570 x) @[simp] axiom s2571 (x : Prop) : f (g2572 x) = f (g2571 x) @[simp] axiom s2572 (x : Prop) : f (g2573 x) = f (g2572 x) @[simp] axiom s2573 (x : Prop) : f (g2574 x) = f (g2573 x) @[simp] axiom s2574 (x : Prop) : f (g2575 x) = f (g2574 x) @[simp] axiom s2575 (x : Prop) : f (g2576 x) = f (g2575 x) @[simp] axiom s2576 (x : Prop) : f (g2577 x) = f (g2576 x) @[simp] axiom s2577 (x : Prop) : f (g2578 x) = f (g2577 x) @[simp] axiom s2578 (x : Prop) : f (g2579 x) = f (g2578 x) @[simp] axiom s2579 (x : Prop) : f (g2580 x) = f (g2579 x) @[simp] axiom s2580 (x : Prop) : f (g2581 x) = f (g2580 x) @[simp] axiom s2581 (x : Prop) : f (g2582 x) = f (g2581 x) @[simp] axiom s2582 (x : Prop) : f (g2583 x) = f (g2582 x) @[simp] axiom s2583 (x : Prop) : f (g2584 x) = f (g2583 x) @[simp] axiom s2584 (x : Prop) : f (g2585 x) = f (g2584 x) @[simp] axiom s2585 (x : Prop) : f (g2586 x) = f (g2585 x) @[simp] axiom s2586 (x : Prop) : f (g2587 x) = f (g2586 x) @[simp] axiom s2587 (x : Prop) : f (g2588 x) = f (g2587 x) @[simp] axiom s2588 (x : Prop) : f (g2589 x) = f (g2588 x) @[simp] axiom s2589 (x : Prop) : f (g2590 x) = f (g2589 x) @[simp] axiom s2590 (x : Prop) : f (g2591 x) = f (g2590 x) @[simp] axiom s2591 (x : Prop) : f (g2592 x) = f (g2591 x) @[simp] axiom s2592 (x : Prop) : f (g2593 x) = f (g2592 x) @[simp] axiom s2593 (x : Prop) : f (g2594 x) = f (g2593 x) @[simp] axiom s2594 (x : Prop) : f (g2595 x) = f (g2594 x) @[simp] axiom s2595 (x : Prop) : f (g2596 x) = f (g2595 x) @[simp] axiom s2596 (x : Prop) : f (g2597 x) = f (g2596 x) @[simp] axiom s2597 (x : Prop) : f (g2598 x) = f (g2597 x) @[simp] axiom s2598 (x : Prop) : f (g2599 x) = f (g2598 x) @[simp] axiom s2599 (x : Prop) : f (g2600 x) = f (g2599 x) @[simp] axiom s2600 (x : Prop) : f (g2601 x) = f (g2600 x) @[simp] axiom s2601 (x : Prop) : f (g2602 x) = f (g2601 x) @[simp] axiom s2602 (x : Prop) : f (g2603 x) = f (g2602 x) @[simp] axiom s2603 (x : Prop) : f (g2604 x) = f (g2603 x) @[simp] axiom s2604 (x : Prop) : f (g2605 x) = f (g2604 x) @[simp] axiom s2605 (x : Prop) : f (g2606 x) = f (g2605 x) @[simp] axiom s2606 (x : Prop) : f (g2607 x) = f (g2606 x) @[simp] axiom s2607 (x : Prop) : f (g2608 x) = f (g2607 x) @[simp] axiom s2608 (x : Prop) : f (g2609 x) = f (g2608 x) @[simp] axiom s2609 (x : Prop) : f (g2610 x) = f (g2609 x) @[simp] axiom s2610 (x : Prop) : f (g2611 x) = f (g2610 x) @[simp] axiom s2611 (x : Prop) : f (g2612 x) = f (g2611 x) @[simp] axiom s2612 (x : Prop) : f (g2613 x) = f (g2612 x) @[simp] axiom s2613 (x : Prop) : f (g2614 x) = f (g2613 x) @[simp] axiom s2614 (x : Prop) : f (g2615 x) = f (g2614 x) @[simp] axiom s2615 (x : Prop) : f (g2616 x) = f (g2615 x) @[simp] axiom s2616 (x : Prop) : f (g2617 x) = f (g2616 x) @[simp] axiom s2617 (x : Prop) : f (g2618 x) = f (g2617 x) @[simp] axiom s2618 (x : Prop) : f (g2619 x) = f (g2618 x) @[simp] axiom s2619 (x : Prop) : f (g2620 x) = f (g2619 x) @[simp] axiom s2620 (x : Prop) : f (g2621 x) = f (g2620 x) @[simp] axiom s2621 (x : Prop) : f (g2622 x) = f (g2621 x) @[simp] axiom s2622 (x : Prop) : f (g2623 x) = f (g2622 x) @[simp] axiom s2623 (x : Prop) : f (g2624 x) = f (g2623 x) @[simp] axiom s2624 (x : Prop) : f (g2625 x) = f (g2624 x) @[simp] axiom s2625 (x : Prop) : f (g2626 x) = f (g2625 x) @[simp] axiom s2626 (x : Prop) : f (g2627 x) = f (g2626 x) @[simp] axiom s2627 (x : Prop) : f (g2628 x) = f (g2627 x) @[simp] axiom s2628 (x : Prop) : f (g2629 x) = f (g2628 x) @[simp] axiom s2629 (x : Prop) : f (g2630 x) = f (g2629 x) @[simp] axiom s2630 (x : Prop) : f (g2631 x) = f (g2630 x) @[simp] axiom s2631 (x : Prop) : f (g2632 x) = f (g2631 x) @[simp] axiom s2632 (x : Prop) : f (g2633 x) = f (g2632 x) @[simp] axiom s2633 (x : Prop) : f (g2634 x) = f (g2633 x) @[simp] axiom s2634 (x : Prop) : f (g2635 x) = f (g2634 x) @[simp] axiom s2635 (x : Prop) : f (g2636 x) = f (g2635 x) @[simp] axiom s2636 (x : Prop) : f (g2637 x) = f (g2636 x) @[simp] axiom s2637 (x : Prop) : f (g2638 x) = f (g2637 x) @[simp] axiom s2638 (x : Prop) : f (g2639 x) = f (g2638 x) @[simp] axiom s2639 (x : Prop) : f (g2640 x) = f (g2639 x) @[simp] axiom s2640 (x : Prop) : f (g2641 x) = f (g2640 x) @[simp] axiom s2641 (x : Prop) : f (g2642 x) = f (g2641 x) @[simp] axiom s2642 (x : Prop) : f (g2643 x) = f (g2642 x) @[simp] axiom s2643 (x : Prop) : f (g2644 x) = f (g2643 x) @[simp] axiom s2644 (x : Prop) : f (g2645 x) = f (g2644 x) @[simp] axiom s2645 (x : Prop) : f (g2646 x) = f (g2645 x) @[simp] axiom s2646 (x : Prop) : f (g2647 x) = f (g2646 x) @[simp] axiom s2647 (x : Prop) : f (g2648 x) = f (g2647 x) @[simp] axiom s2648 (x : Prop) : f (g2649 x) = f (g2648 x) @[simp] axiom s2649 (x : Prop) : f (g2650 x) = f (g2649 x) @[simp] axiom s2650 (x : Prop) : f (g2651 x) = f (g2650 x) @[simp] axiom s2651 (x : Prop) : f (g2652 x) = f (g2651 x) @[simp] axiom s2652 (x : Prop) : f (g2653 x) = f (g2652 x) @[simp] axiom s2653 (x : Prop) : f (g2654 x) = f (g2653 x) @[simp] axiom s2654 (x : Prop) : f (g2655 x) = f (g2654 x) @[simp] axiom s2655 (x : Prop) : f (g2656 x) = f (g2655 x) @[simp] axiom s2656 (x : Prop) : f (g2657 x) = f (g2656 x) @[simp] axiom s2657 (x : Prop) : f (g2658 x) = f (g2657 x) @[simp] axiom s2658 (x : Prop) : f (g2659 x) = f (g2658 x) @[simp] axiom s2659 (x : Prop) : f (g2660 x) = f (g2659 x) @[simp] axiom s2660 (x : Prop) : f (g2661 x) = f (g2660 x) @[simp] axiom s2661 (x : Prop) : f (g2662 x) = f (g2661 x) @[simp] axiom s2662 (x : Prop) : f (g2663 x) = f (g2662 x) @[simp] axiom s2663 (x : Prop) : f (g2664 x) = f (g2663 x) @[simp] axiom s2664 (x : Prop) : f (g2665 x) = f (g2664 x) @[simp] axiom s2665 (x : Prop) : f (g2666 x) = f (g2665 x) @[simp] axiom s2666 (x : Prop) : f (g2667 x) = f (g2666 x) @[simp] axiom s2667 (x : Prop) : f (g2668 x) = f (g2667 x) @[simp] axiom s2668 (x : Prop) : f (g2669 x) = f (g2668 x) @[simp] axiom s2669 (x : Prop) : f (g2670 x) = f (g2669 x) @[simp] axiom s2670 (x : Prop) : f (g2671 x) = f (g2670 x) @[simp] axiom s2671 (x : Prop) : f (g2672 x) = f (g2671 x) @[simp] axiom s2672 (x : Prop) : f (g2673 x) = f (g2672 x) @[simp] axiom s2673 (x : Prop) : f (g2674 x) = f (g2673 x) @[simp] axiom s2674 (x : Prop) : f (g2675 x) = f (g2674 x) @[simp] axiom s2675 (x : Prop) : f (g2676 x) = f (g2675 x) @[simp] axiom s2676 (x : Prop) : f (g2677 x) = f (g2676 x) @[simp] axiom s2677 (x : Prop) : f (g2678 x) = f (g2677 x) @[simp] axiom s2678 (x : Prop) : f (g2679 x) = f (g2678 x) @[simp] axiom s2679 (x : Prop) : f (g2680 x) = f (g2679 x) @[simp] axiom s2680 (x : Prop) : f (g2681 x) = f (g2680 x) @[simp] axiom s2681 (x : Prop) : f (g2682 x) = f (g2681 x) @[simp] axiom s2682 (x : Prop) : f (g2683 x) = f (g2682 x) @[simp] axiom s2683 (x : Prop) : f (g2684 x) = f (g2683 x) @[simp] axiom s2684 (x : Prop) : f (g2685 x) = f (g2684 x) @[simp] axiom s2685 (x : Prop) : f (g2686 x) = f (g2685 x) @[simp] axiom s2686 (x : Prop) : f (g2687 x) = f (g2686 x) @[simp] axiom s2687 (x : Prop) : f (g2688 x) = f (g2687 x) @[simp] axiom s2688 (x : Prop) : f (g2689 x) = f (g2688 x) @[simp] axiom s2689 (x : Prop) : f (g2690 x) = f (g2689 x) @[simp] axiom s2690 (x : Prop) : f (g2691 x) = f (g2690 x) @[simp] axiom s2691 (x : Prop) : f (g2692 x) = f (g2691 x) @[simp] axiom s2692 (x : Prop) : f (g2693 x) = f (g2692 x) @[simp] axiom s2693 (x : Prop) : f (g2694 x) = f (g2693 x) @[simp] axiom s2694 (x : Prop) : f (g2695 x) = f (g2694 x) @[simp] axiom s2695 (x : Prop) : f (g2696 x) = f (g2695 x) @[simp] axiom s2696 (x : Prop) : f (g2697 x) = f (g2696 x) @[simp] axiom s2697 (x : Prop) : f (g2698 x) = f (g2697 x) @[simp] axiom s2698 (x : Prop) : f (g2699 x) = f (g2698 x) @[simp] axiom s2699 (x : Prop) : f (g2700 x) = f (g2699 x) @[simp] axiom s2700 (x : Prop) : f (g2701 x) = f (g2700 x) @[simp] axiom s2701 (x : Prop) : f (g2702 x) = f (g2701 x) @[simp] axiom s2702 (x : Prop) : f (g2703 x) = f (g2702 x) @[simp] axiom s2703 (x : Prop) : f (g2704 x) = f (g2703 x) @[simp] axiom s2704 (x : Prop) : f (g2705 x) = f (g2704 x) @[simp] axiom s2705 (x : Prop) : f (g2706 x) = f (g2705 x) @[simp] axiom s2706 (x : Prop) : f (g2707 x) = f (g2706 x) @[simp] axiom s2707 (x : Prop) : f (g2708 x) = f (g2707 x) @[simp] axiom s2708 (x : Prop) : f (g2709 x) = f (g2708 x) @[simp] axiom s2709 (x : Prop) : f (g2710 x) = f (g2709 x) @[simp] axiom s2710 (x : Prop) : f (g2711 x) = f (g2710 x) @[simp] axiom s2711 (x : Prop) : f (g2712 x) = f (g2711 x) @[simp] axiom s2712 (x : Prop) : f (g2713 x) = f (g2712 x) @[simp] axiom s2713 (x : Prop) : f (g2714 x) = f (g2713 x) @[simp] axiom s2714 (x : Prop) : f (g2715 x) = f (g2714 x) @[simp] axiom s2715 (x : Prop) : f (g2716 x) = f (g2715 x) @[simp] axiom s2716 (x : Prop) : f (g2717 x) = f (g2716 x) @[simp] axiom s2717 (x : Prop) : f (g2718 x) = f (g2717 x) @[simp] axiom s2718 (x : Prop) : f (g2719 x) = f (g2718 x) @[simp] axiom s2719 (x : Prop) : f (g2720 x) = f (g2719 x) @[simp] axiom s2720 (x : Prop) : f (g2721 x) = f (g2720 x) @[simp] axiom s2721 (x : Prop) : f (g2722 x) = f (g2721 x) @[simp] axiom s2722 (x : Prop) : f (g2723 x) = f (g2722 x) @[simp] axiom s2723 (x : Prop) : f (g2724 x) = f (g2723 x) @[simp] axiom s2724 (x : Prop) : f (g2725 x) = f (g2724 x) @[simp] axiom s2725 (x : Prop) : f (g2726 x) = f (g2725 x) @[simp] axiom s2726 (x : Prop) : f (g2727 x) = f (g2726 x) @[simp] axiom s2727 (x : Prop) : f (g2728 x) = f (g2727 x) @[simp] axiom s2728 (x : Prop) : f (g2729 x) = f (g2728 x) @[simp] axiom s2729 (x : Prop) : f (g2730 x) = f (g2729 x) @[simp] axiom s2730 (x : Prop) : f (g2731 x) = f (g2730 x) @[simp] axiom s2731 (x : Prop) : f (g2732 x) = f (g2731 x) @[simp] axiom s2732 (x : Prop) : f (g2733 x) = f (g2732 x) @[simp] axiom s2733 (x : Prop) : f (g2734 x) = f (g2733 x) @[simp] axiom s2734 (x : Prop) : f (g2735 x) = f (g2734 x) @[simp] axiom s2735 (x : Prop) : f (g2736 x) = f (g2735 x) @[simp] axiom s2736 (x : Prop) : f (g2737 x) = f (g2736 x) @[simp] axiom s2737 (x : Prop) : f (g2738 x) = f (g2737 x) @[simp] axiom s2738 (x : Prop) : f (g2739 x) = f (g2738 x) @[simp] axiom s2739 (x : Prop) : f (g2740 x) = f (g2739 x) @[simp] axiom s2740 (x : Prop) : f (g2741 x) = f (g2740 x) @[simp] axiom s2741 (x : Prop) : f (g2742 x) = f (g2741 x) @[simp] axiom s2742 (x : Prop) : f (g2743 x) = f (g2742 x) @[simp] axiom s2743 (x : Prop) : f (g2744 x) = f (g2743 x) @[simp] axiom s2744 (x : Prop) : f (g2745 x) = f (g2744 x) @[simp] axiom s2745 (x : Prop) : f (g2746 x) = f (g2745 x) @[simp] axiom s2746 (x : Prop) : f (g2747 x) = f (g2746 x) @[simp] axiom s2747 (x : Prop) : f (g2748 x) = f (g2747 x) @[simp] axiom s2748 (x : Prop) : f (g2749 x) = f (g2748 x) @[simp] axiom s2749 (x : Prop) : f (g2750 x) = f (g2749 x) @[simp] axiom s2750 (x : Prop) : f (g2751 x) = f (g2750 x) @[simp] axiom s2751 (x : Prop) : f (g2752 x) = f (g2751 x) @[simp] axiom s2752 (x : Prop) : f (g2753 x) = f (g2752 x) @[simp] axiom s2753 (x : Prop) : f (g2754 x) = f (g2753 x) @[simp] axiom s2754 (x : Prop) : f (g2755 x) = f (g2754 x) @[simp] axiom s2755 (x : Prop) : f (g2756 x) = f (g2755 x) @[simp] axiom s2756 (x : Prop) : f (g2757 x) = f (g2756 x) @[simp] axiom s2757 (x : Prop) : f (g2758 x) = f (g2757 x) @[simp] axiom s2758 (x : Prop) : f (g2759 x) = f (g2758 x) @[simp] axiom s2759 (x : Prop) : f (g2760 x) = f (g2759 x) @[simp] axiom s2760 (x : Prop) : f (g2761 x) = f (g2760 x) @[simp] axiom s2761 (x : Prop) : f (g2762 x) = f (g2761 x) @[simp] axiom s2762 (x : Prop) : f (g2763 x) = f (g2762 x) @[simp] axiom s2763 (x : Prop) : f (g2764 x) = f (g2763 x) @[simp] axiom s2764 (x : Prop) : f (g2765 x) = f (g2764 x) @[simp] axiom s2765 (x : Prop) : f (g2766 x) = f (g2765 x) @[simp] axiom s2766 (x : Prop) : f (g2767 x) = f (g2766 x) @[simp] axiom s2767 (x : Prop) : f (g2768 x) = f (g2767 x) @[simp] axiom s2768 (x : Prop) : f (g2769 x) = f (g2768 x) @[simp] axiom s2769 (x : Prop) : f (g2770 x) = f (g2769 x) @[simp] axiom s2770 (x : Prop) : f (g2771 x) = f (g2770 x) @[simp] axiom s2771 (x : Prop) : f (g2772 x) = f (g2771 x) @[simp] axiom s2772 (x : Prop) : f (g2773 x) = f (g2772 x) @[simp] axiom s2773 (x : Prop) : f (g2774 x) = f (g2773 x) @[simp] axiom s2774 (x : Prop) : f (g2775 x) = f (g2774 x) @[simp] axiom s2775 (x : Prop) : f (g2776 x) = f (g2775 x) @[simp] axiom s2776 (x : Prop) : f (g2777 x) = f (g2776 x) @[simp] axiom s2777 (x : Prop) : f (g2778 x) = f (g2777 x) @[simp] axiom s2778 (x : Prop) : f (g2779 x) = f (g2778 x) @[simp] axiom s2779 (x : Prop) : f (g2780 x) = f (g2779 x) @[simp] axiom s2780 (x : Prop) : f (g2781 x) = f (g2780 x) @[simp] axiom s2781 (x : Prop) : f (g2782 x) = f (g2781 x) @[simp] axiom s2782 (x : Prop) : f (g2783 x) = f (g2782 x) @[simp] axiom s2783 (x : Prop) : f (g2784 x) = f (g2783 x) @[simp] axiom s2784 (x : Prop) : f (g2785 x) = f (g2784 x) @[simp] axiom s2785 (x : Prop) : f (g2786 x) = f (g2785 x) @[simp] axiom s2786 (x : Prop) : f (g2787 x) = f (g2786 x) @[simp] axiom s2787 (x : Prop) : f (g2788 x) = f (g2787 x) @[simp] axiom s2788 (x : Prop) : f (g2789 x) = f (g2788 x) @[simp] axiom s2789 (x : Prop) : f (g2790 x) = f (g2789 x) @[simp] axiom s2790 (x : Prop) : f (g2791 x) = f (g2790 x) @[simp] axiom s2791 (x : Prop) : f (g2792 x) = f (g2791 x) @[simp] axiom s2792 (x : Prop) : f (g2793 x) = f (g2792 x) @[simp] axiom s2793 (x : Prop) : f (g2794 x) = f (g2793 x) @[simp] axiom s2794 (x : Prop) : f (g2795 x) = f (g2794 x) @[simp] axiom s2795 (x : Prop) : f (g2796 x) = f (g2795 x) @[simp] axiom s2796 (x : Prop) : f (g2797 x) = f (g2796 x) @[simp] axiom s2797 (x : Prop) : f (g2798 x) = f (g2797 x) @[simp] axiom s2798 (x : Prop) : f (g2799 x) = f (g2798 x) @[simp] axiom s2799 (x : Prop) : f (g2800 x) = f (g2799 x) @[simp] axiom s2800 (x : Prop) : f (g2801 x) = f (g2800 x) @[simp] axiom s2801 (x : Prop) : f (g2802 x) = f (g2801 x) @[simp] axiom s2802 (x : Prop) : f (g2803 x) = f (g2802 x) @[simp] axiom s2803 (x : Prop) : f (g2804 x) = f (g2803 x) @[simp] axiom s2804 (x : Prop) : f (g2805 x) = f (g2804 x) @[simp] axiom s2805 (x : Prop) : f (g2806 x) = f (g2805 x) @[simp] axiom s2806 (x : Prop) : f (g2807 x) = f (g2806 x) @[simp] axiom s2807 (x : Prop) : f (g2808 x) = f (g2807 x) @[simp] axiom s2808 (x : Prop) : f (g2809 x) = f (g2808 x) @[simp] axiom s2809 (x : Prop) : f (g2810 x) = f (g2809 x) @[simp] axiom s2810 (x : Prop) : f (g2811 x) = f (g2810 x) @[simp] axiom s2811 (x : Prop) : f (g2812 x) = f (g2811 x) @[simp] axiom s2812 (x : Prop) : f (g2813 x) = f (g2812 x) @[simp] axiom s2813 (x : Prop) : f (g2814 x) = f (g2813 x) @[simp] axiom s2814 (x : Prop) : f (g2815 x) = f (g2814 x) @[simp] axiom s2815 (x : Prop) : f (g2816 x) = f (g2815 x) @[simp] axiom s2816 (x : Prop) : f (g2817 x) = f (g2816 x) @[simp] axiom s2817 (x : Prop) : f (g2818 x) = f (g2817 x) @[simp] axiom s2818 (x : Prop) : f (g2819 x) = f (g2818 x) @[simp] axiom s2819 (x : Prop) : f (g2820 x) = f (g2819 x) @[simp] axiom s2820 (x : Prop) : f (g2821 x) = f (g2820 x) @[simp] axiom s2821 (x : Prop) : f (g2822 x) = f (g2821 x) @[simp] axiom s2822 (x : Prop) : f (g2823 x) = f (g2822 x) @[simp] axiom s2823 (x : Prop) : f (g2824 x) = f (g2823 x) @[simp] axiom s2824 (x : Prop) : f (g2825 x) = f (g2824 x) @[simp] axiom s2825 (x : Prop) : f (g2826 x) = f (g2825 x) @[simp] axiom s2826 (x : Prop) : f (g2827 x) = f (g2826 x) @[simp] axiom s2827 (x : Prop) : f (g2828 x) = f (g2827 x) @[simp] axiom s2828 (x : Prop) : f (g2829 x) = f (g2828 x) @[simp] axiom s2829 (x : Prop) : f (g2830 x) = f (g2829 x) @[simp] axiom s2830 (x : Prop) : f (g2831 x) = f (g2830 x) @[simp] axiom s2831 (x : Prop) : f (g2832 x) = f (g2831 x) @[simp] axiom s2832 (x : Prop) : f (g2833 x) = f (g2832 x) @[simp] axiom s2833 (x : Prop) : f (g2834 x) = f (g2833 x) @[simp] axiom s2834 (x : Prop) : f (g2835 x) = f (g2834 x) @[simp] axiom s2835 (x : Prop) : f (g2836 x) = f (g2835 x) @[simp] axiom s2836 (x : Prop) : f (g2837 x) = f (g2836 x) @[simp] axiom s2837 (x : Prop) : f (g2838 x) = f (g2837 x) @[simp] axiom s2838 (x : Prop) : f (g2839 x) = f (g2838 x) @[simp] axiom s2839 (x : Prop) : f (g2840 x) = f (g2839 x) @[simp] axiom s2840 (x : Prop) : f (g2841 x) = f (g2840 x) @[simp] axiom s2841 (x : Prop) : f (g2842 x) = f (g2841 x) @[simp] axiom s2842 (x : Prop) : f (g2843 x) = f (g2842 x) @[simp] axiom s2843 (x : Prop) : f (g2844 x) = f (g2843 x) @[simp] axiom s2844 (x : Prop) : f (g2845 x) = f (g2844 x) @[simp] axiom s2845 (x : Prop) : f (g2846 x) = f (g2845 x) @[simp] axiom s2846 (x : Prop) : f (g2847 x) = f (g2846 x) @[simp] axiom s2847 (x : Prop) : f (g2848 x) = f (g2847 x) @[simp] axiom s2848 (x : Prop) : f (g2849 x) = f (g2848 x) @[simp] axiom s2849 (x : Prop) : f (g2850 x) = f (g2849 x) @[simp] axiom s2850 (x : Prop) : f (g2851 x) = f (g2850 x) @[simp] axiom s2851 (x : Prop) : f (g2852 x) = f (g2851 x) @[simp] axiom s2852 (x : Prop) : f (g2853 x) = f (g2852 x) @[simp] axiom s2853 (x : Prop) : f (g2854 x) = f (g2853 x) @[simp] axiom s2854 (x : Prop) : f (g2855 x) = f (g2854 x) @[simp] axiom s2855 (x : Prop) : f (g2856 x) = f (g2855 x) @[simp] axiom s2856 (x : Prop) : f (g2857 x) = f (g2856 x) @[simp] axiom s2857 (x : Prop) : f (g2858 x) = f (g2857 x) @[simp] axiom s2858 (x : Prop) : f (g2859 x) = f (g2858 x) @[simp] axiom s2859 (x : Prop) : f (g2860 x) = f (g2859 x) @[simp] axiom s2860 (x : Prop) : f (g2861 x) = f (g2860 x) @[simp] axiom s2861 (x : Prop) : f (g2862 x) = f (g2861 x) @[simp] axiom s2862 (x : Prop) : f (g2863 x) = f (g2862 x) @[simp] axiom s2863 (x : Prop) : f (g2864 x) = f (g2863 x) @[simp] axiom s2864 (x : Prop) : f (g2865 x) = f (g2864 x) @[simp] axiom s2865 (x : Prop) : f (g2866 x) = f (g2865 x) @[simp] axiom s2866 (x : Prop) : f (g2867 x) = f (g2866 x) @[simp] axiom s2867 (x : Prop) : f (g2868 x) = f (g2867 x) @[simp] axiom s2868 (x : Prop) : f (g2869 x) = f (g2868 x) @[simp] axiom s2869 (x : Prop) : f (g2870 x) = f (g2869 x) @[simp] axiom s2870 (x : Prop) : f (g2871 x) = f (g2870 x) @[simp] axiom s2871 (x : Prop) : f (g2872 x) = f (g2871 x) @[simp] axiom s2872 (x : Prop) : f (g2873 x) = f (g2872 x) @[simp] axiom s2873 (x : Prop) : f (g2874 x) = f (g2873 x) @[simp] axiom s2874 (x : Prop) : f (g2875 x) = f (g2874 x) @[simp] axiom s2875 (x : Prop) : f (g2876 x) = f (g2875 x) @[simp] axiom s2876 (x : Prop) : f (g2877 x) = f (g2876 x) @[simp] axiom s2877 (x : Prop) : f (g2878 x) = f (g2877 x) @[simp] axiom s2878 (x : Prop) : f (g2879 x) = f (g2878 x) @[simp] axiom s2879 (x : Prop) : f (g2880 x) = f (g2879 x) @[simp] axiom s2880 (x : Prop) : f (g2881 x) = f (g2880 x) @[simp] axiom s2881 (x : Prop) : f (g2882 x) = f (g2881 x) @[simp] axiom s2882 (x : Prop) : f (g2883 x) = f (g2882 x) @[simp] axiom s2883 (x : Prop) : f (g2884 x) = f (g2883 x) @[simp] axiom s2884 (x : Prop) : f (g2885 x) = f (g2884 x) @[simp] axiom s2885 (x : Prop) : f (g2886 x) = f (g2885 x) @[simp] axiom s2886 (x : Prop) : f (g2887 x) = f (g2886 x) @[simp] axiom s2887 (x : Prop) : f (g2888 x) = f (g2887 x) @[simp] axiom s2888 (x : Prop) : f (g2889 x) = f (g2888 x) @[simp] axiom s2889 (x : Prop) : f (g2890 x) = f (g2889 x) @[simp] axiom s2890 (x : Prop) : f (g2891 x) = f (g2890 x) @[simp] axiom s2891 (x : Prop) : f (g2892 x) = f (g2891 x) @[simp] axiom s2892 (x : Prop) : f (g2893 x) = f (g2892 x) @[simp] axiom s2893 (x : Prop) : f (g2894 x) = f (g2893 x) @[simp] axiom s2894 (x : Prop) : f (g2895 x) = f (g2894 x) @[simp] axiom s2895 (x : Prop) : f (g2896 x) = f (g2895 x) @[simp] axiom s2896 (x : Prop) : f (g2897 x) = f (g2896 x) @[simp] axiom s2897 (x : Prop) : f (g2898 x) = f (g2897 x) @[simp] axiom s2898 (x : Prop) : f (g2899 x) = f (g2898 x) @[simp] axiom s2899 (x : Prop) : f (g2900 x) = f (g2899 x) @[simp] axiom s2900 (x : Prop) : f (g2901 x) = f (g2900 x) @[simp] axiom s2901 (x : Prop) : f (g2902 x) = f (g2901 x) @[simp] axiom s2902 (x : Prop) : f (g2903 x) = f (g2902 x) @[simp] axiom s2903 (x : Prop) : f (g2904 x) = f (g2903 x) @[simp] axiom s2904 (x : Prop) : f (g2905 x) = f (g2904 x) @[simp] axiom s2905 (x : Prop) : f (g2906 x) = f (g2905 x) @[simp] axiom s2906 (x : Prop) : f (g2907 x) = f (g2906 x) @[simp] axiom s2907 (x : Prop) : f (g2908 x) = f (g2907 x) @[simp] axiom s2908 (x : Prop) : f (g2909 x) = f (g2908 x) @[simp] axiom s2909 (x : Prop) : f (g2910 x) = f (g2909 x) @[simp] axiom s2910 (x : Prop) : f (g2911 x) = f (g2910 x) @[simp] axiom s2911 (x : Prop) : f (g2912 x) = f (g2911 x) @[simp] axiom s2912 (x : Prop) : f (g2913 x) = f (g2912 x) @[simp] axiom s2913 (x : Prop) : f (g2914 x) = f (g2913 x) @[simp] axiom s2914 (x : Prop) : f (g2915 x) = f (g2914 x) @[simp] axiom s2915 (x : Prop) : f (g2916 x) = f (g2915 x) @[simp] axiom s2916 (x : Prop) : f (g2917 x) = f (g2916 x) @[simp] axiom s2917 (x : Prop) : f (g2918 x) = f (g2917 x) @[simp] axiom s2918 (x : Prop) : f (g2919 x) = f (g2918 x) @[simp] axiom s2919 (x : Prop) : f (g2920 x) = f (g2919 x) @[simp] axiom s2920 (x : Prop) : f (g2921 x) = f (g2920 x) @[simp] axiom s2921 (x : Prop) : f (g2922 x) = f (g2921 x) @[simp] axiom s2922 (x : Prop) : f (g2923 x) = f (g2922 x) @[simp] axiom s2923 (x : Prop) : f (g2924 x) = f (g2923 x) @[simp] axiom s2924 (x : Prop) : f (g2925 x) = f (g2924 x) @[simp] axiom s2925 (x : Prop) : f (g2926 x) = f (g2925 x) @[simp] axiom s2926 (x : Prop) : f (g2927 x) = f (g2926 x) @[simp] axiom s2927 (x : Prop) : f (g2928 x) = f (g2927 x) @[simp] axiom s2928 (x : Prop) : f (g2929 x) = f (g2928 x) @[simp] axiom s2929 (x : Prop) : f (g2930 x) = f (g2929 x) @[simp] axiom s2930 (x : Prop) : f (g2931 x) = f (g2930 x) @[simp] axiom s2931 (x : Prop) : f (g2932 x) = f (g2931 x) @[simp] axiom s2932 (x : Prop) : f (g2933 x) = f (g2932 x) @[simp] axiom s2933 (x : Prop) : f (g2934 x) = f (g2933 x) @[simp] axiom s2934 (x : Prop) : f (g2935 x) = f (g2934 x) @[simp] axiom s2935 (x : Prop) : f (g2936 x) = f (g2935 x) @[simp] axiom s2936 (x : Prop) : f (g2937 x) = f (g2936 x) @[simp] axiom s2937 (x : Prop) : f (g2938 x) = f (g2937 x) @[simp] axiom s2938 (x : Prop) : f (g2939 x) = f (g2938 x) @[simp] axiom s2939 (x : Prop) : f (g2940 x) = f (g2939 x) @[simp] axiom s2940 (x : Prop) : f (g2941 x) = f (g2940 x) @[simp] axiom s2941 (x : Prop) : f (g2942 x) = f (g2941 x) @[simp] axiom s2942 (x : Prop) : f (g2943 x) = f (g2942 x) @[simp] axiom s2943 (x : Prop) : f (g2944 x) = f (g2943 x) @[simp] axiom s2944 (x : Prop) : f (g2945 x) = f (g2944 x) @[simp] axiom s2945 (x : Prop) : f (g2946 x) = f (g2945 x) @[simp] axiom s2946 (x : Prop) : f (g2947 x) = f (g2946 x) @[simp] axiom s2947 (x : Prop) : f (g2948 x) = f (g2947 x) @[simp] axiom s2948 (x : Prop) : f (g2949 x) = f (g2948 x) @[simp] axiom s2949 (x : Prop) : f (g2950 x) = f (g2949 x) @[simp] axiom s2950 (x : Prop) : f (g2951 x) = f (g2950 x) @[simp] axiom s2951 (x : Prop) : f (g2952 x) = f (g2951 x) @[simp] axiom s2952 (x : Prop) : f (g2953 x) = f (g2952 x) @[simp] axiom s2953 (x : Prop) : f (g2954 x) = f (g2953 x) @[simp] axiom s2954 (x : Prop) : f (g2955 x) = f (g2954 x) @[simp] axiom s2955 (x : Prop) : f (g2956 x) = f (g2955 x) @[simp] axiom s2956 (x : Prop) : f (g2957 x) = f (g2956 x) @[simp] axiom s2957 (x : Prop) : f (g2958 x) = f (g2957 x) @[simp] axiom s2958 (x : Prop) : f (g2959 x) = f (g2958 x) @[simp] axiom s2959 (x : Prop) : f (g2960 x) = f (g2959 x) @[simp] axiom s2960 (x : Prop) : f (g2961 x) = f (g2960 x) @[simp] axiom s2961 (x : Prop) : f (g2962 x) = f (g2961 x) @[simp] axiom s2962 (x : Prop) : f (g2963 x) = f (g2962 x) @[simp] axiom s2963 (x : Prop) : f (g2964 x) = f (g2963 x) @[simp] axiom s2964 (x : Prop) : f (g2965 x) = f (g2964 x) @[simp] axiom s2965 (x : Prop) : f (g2966 x) = f (g2965 x) @[simp] axiom s2966 (x : Prop) : f (g2967 x) = f (g2966 x) @[simp] axiom s2967 (x : Prop) : f (g2968 x) = f (g2967 x) @[simp] axiom s2968 (x : Prop) : f (g2969 x) = f (g2968 x) @[simp] axiom s2969 (x : Prop) : f (g2970 x) = f (g2969 x) @[simp] axiom s2970 (x : Prop) : f (g2971 x) = f (g2970 x) @[simp] axiom s2971 (x : Prop) : f (g2972 x) = f (g2971 x) @[simp] axiom s2972 (x : Prop) : f (g2973 x) = f (g2972 x) @[simp] axiom s2973 (x : Prop) : f (g2974 x) = f (g2973 x) @[simp] axiom s2974 (x : Prop) : f (g2975 x) = f (g2974 x) @[simp] axiom s2975 (x : Prop) : f (g2976 x) = f (g2975 x) @[simp] axiom s2976 (x : Prop) : f (g2977 x) = f (g2976 x) @[simp] axiom s2977 (x : Prop) : f (g2978 x) = f (g2977 x) @[simp] axiom s2978 (x : Prop) : f (g2979 x) = f (g2978 x) @[simp] axiom s2979 (x : Prop) : f (g2980 x) = f (g2979 x) @[simp] axiom s2980 (x : Prop) : f (g2981 x) = f (g2980 x) @[simp] axiom s2981 (x : Prop) : f (g2982 x) = f (g2981 x) @[simp] axiom s2982 (x : Prop) : f (g2983 x) = f (g2982 x) @[simp] axiom s2983 (x : Prop) : f (g2984 x) = f (g2983 x) @[simp] axiom s2984 (x : Prop) : f (g2985 x) = f (g2984 x) @[simp] axiom s2985 (x : Prop) : f (g2986 x) = f (g2985 x) @[simp] axiom s2986 (x : Prop) : f (g2987 x) = f (g2986 x) @[simp] axiom s2987 (x : Prop) : f (g2988 x) = f (g2987 x) @[simp] axiom s2988 (x : Prop) : f (g2989 x) = f (g2988 x) @[simp] axiom s2989 (x : Prop) : f (g2990 x) = f (g2989 x) @[simp] axiom s2990 (x : Prop) : f (g2991 x) = f (g2990 x) @[simp] axiom s2991 (x : Prop) : f (g2992 x) = f (g2991 x) @[simp] axiom s2992 (x : Prop) : f (g2993 x) = f (g2992 x) @[simp] axiom s2993 (x : Prop) : f (g2994 x) = f (g2993 x) @[simp] axiom s2994 (x : Prop) : f (g2995 x) = f (g2994 x) @[simp] axiom s2995 (x : Prop) : f (g2996 x) = f (g2995 x) @[simp] axiom s2996 (x : Prop) : f (g2997 x) = f (g2996 x) @[simp] axiom s2997 (x : Prop) : f (g2998 x) = f (g2997 x) @[simp] axiom s2998 (x : Prop) : f (g2999 x) = f (g2998 x) def test (x : Prop) : f (g0 x) = f (g2999 x) := by simp #check test
88a2cca2688173853232897ed54964eb2fec86e1
9a0b1b3a653ea926b03d1495fef64da1d14b3174
/tidy/rewrite_search/core/types.lean
cd54805c0f60bef98796c23bab8da2671abd92be
[ "Apache-2.0" ]
permissive
khoek/mathlib-tidy
8623b27b4e04e7d598164e7eaf248610d58f768b
866afa6ab597c47f1b72e8fe2b82b97fff5b980f
refs/heads/master
1,585,598,975,772
1,538,659,544,000
1,538,659,544,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
8,373
lean
import tidy.lib import data.rat import tidy.rewrite_search.discovery.shared import .shared import .hook universe u namespace tidy.rewrite_search meta inductive search_result | success (proof : expr) (steps : list how) : search_result | failure (message : string) : search_result inductive bound_progress (β : Type u) | exactly : ℚ → β → bound_progress | at_least : ℚ → β → bound_progress open bound_progress def bound_progress.bound {β : Type u} : bound_progress β → ℚ | (exactly n _) := n | (at_least n _) := n def bound_progress.sure {β : Type u} : bound_progress β → bool | (exactly _ _) := tt | (at_least _ _) := ff def bound_progress.to_string {β : Type u} : bound_progress β → string | (exactly n _) := "= " ++ to_string n | (at_least n _) := "≥ " ++ to_string n meta structure edge := (f t : table_ref) (proof : tactic expr) (how : how) structure rewriterator := (orig : table_ref) (front : table_ref) meta structure vertex := (id : table_ref) (exp : expr) (pp : string) (tokens : list table_ref) (root : bool) (visited : bool) (s : side) (parent : option edge) (rw_prog : option rewrite_progress) (rws : table rewrite) (rw_front : table_ref) (adj : table edge) meta def vertex.same_side (a b : vertex) : bool := a.s = b.s meta def vertex.to_string (v : vertex) : string := v.s.to_string ++ v.pp meta def vertex.create (id : table_ref) (e : expr) (pp : string) (token_refs : list table_ref) (root : bool) (s : side) : vertex := ⟨ id, e, pp, token_refs, root, ff, s, none, none, table.create, table_ref.first, table.create ⟩ meta def null_expr : expr := default expr meta def null_vertex : vertex := vertex.create table_ref.null null_expr "__NULLEXPR" [] ff side.L meta instance vertex.inhabited : inhabited vertex := ⟨null_vertex⟩ meta instance vertex.indexed : indexed vertex := ⟨λ v, v.id⟩ meta instance vertex.keyed : keyed vertex string := ⟨λ v, v.pp⟩ meta instance vertex.has_to_format : has_to_format vertex := ⟨λ v, v.pp⟩ def pair := sided_pair table_ref def pair.null : pair := ⟨table_ref.null, table_ref.null⟩ instance pair.has_to_string : has_to_string pair := ⟨sided_pair.to_string⟩ structure dist_estimate (state_type : Type u) extends sided_pair table_ref := (id : table_ref) (bnd : bound_progress state_type) namespace dist_estimate variables {α : Type} (de : dist_estimate α) def to_pair : pair := de.to_sided_pair def side (s : side) : table_ref := de.to_pair.get s def set_bound (de : dist_estimate α) (bnd : bound_progress α) : dist_estimate α := { de with bnd := bnd } def to_string : string := de.to_pair.to_string ++ "Δ" ++ de.bnd.to_string instance {γ : Type} : has_to_string (dist_estimate γ) := ⟨λ v, v.to_string⟩ instance {γ : Type} : indexed (dist_estimate γ) := ⟨λ v, v.id⟩ instance {γ : Type} : keyed (dist_estimate γ) pair := ⟨λ v, v.to_pair⟩ end dist_estimate structure token := (id : table_ref) (str : string) (freq : sided_pair ℕ) def token.inc (t : token) (s : side) : token := {t with freq := t.freq.set s $ (t.freq.get s) + 1} def null_token : token := ⟨ table_ref.null, "__NULLTOKEN", 0, 0 ⟩ instance token.inhabited : inhabited token := ⟨null_token⟩ instance token.indexed : indexed token := ⟨λ t, t.id⟩ instance token.keyed : keyed token string := ⟨λ v, v.str⟩ meta def find_or_create_token (tokens : table token) (s : side) (tstr : string) : table token × token := match tokens.find_key tstr with | none := do let t : token := ⟨tokens.next_id, tstr, ⟨0, 0⟩⟩, let t := t.inc s in (tokens.alloc t, t) | (some t) := do let t := t.inc s in (tokens.update t, t) end meta inductive status | continue : status | repeat : status | done : edge → status | abort : string → status inductive init_result (ε : Type) | success : ε → init_result | failure : string → init_result meta def init_fn (ε : Type) := tactic (init_result ε) meta def init_result.pure {ε : Type} (v : ε) : tactic (init_result ε) := pure $ init_result.success v meta def init_result.fail {ε : Type} (reason : string) : tactic (init_result ε) := pure $ init_result.failure ε reason meta def init_result.cases {ε η : Type} (name : string) (fn : init_fn ε) (next_step : ε → tactic η) (fallback : string → tactic η) : tactic η := do val ← fn, match val with | init_result.failure _ reason := do fallback reason | init_result.success val := do next_step val end meta def init_result.chain {ε η : Type} (name : string) (fn : init_fn ε) (next_step : ε → init_fn η) : tactic (init_result η) := init_result.cases name fn next_step $ λ reason, return $ init_result.failure _ ("An error occurred while initialising " ++ name ++ ": " ++ reason) meta def init_result.try {ε η : Type} (name : string) (fn : init_fn ε) (next_step : ε → tactic (option η)) : tactic (option η) := init_result.cases name fn next_step $ λ reason, do tactic.trace ("\nWarning: failed to initialise " ++ name ++ "! Reason:\n\n" ++ reason), return none meta structure tracer (α β γ δ : Type) := (init : init_fn δ) (publish_vertex : δ → vertex → tactic unit) (publish_edge : δ → edge → tactic unit) (publish_visited : δ → vertex → tactic unit) (publish_finished : δ → list edge → tactic unit) (dump : δ → string → tactic unit) (pause : δ → tactic unit) structure statistics := (num_discovers : ℕ) def statistics.init : statistics := ⟨0⟩ meta structure search_state (α β γ δ : Type) := (tr : tracer α β γ δ) (conf : config) (strat_state : α) (metric_state : β) (tokens : table token) (vertices : table vertex) (estimates : table (dist_estimate γ)) (solving_edge : option edge) (tr_state : δ) (prog : discovery.progress) (stats : statistics) meta def update_fn (α β γ δ : Type) : Type := search_state α β γ δ → ℕ → tactic (search_state α β γ δ) meta def init_bound_fn (α β γ δ : Type) := search_state α β γ δ → vertex → vertex → bound_progress γ meta def improve_estimate_fn (α β γ δ : Type) := search_state α β γ δ → ℚ → vertex → vertex → bound_progress γ → bound_progress γ meta structure metric (α β γ δ : Type) := (init : init_fn β) (update : update_fn α β γ δ) (init_bound : init_bound_fn α β γ δ) (improve_estimate_over : improve_estimate_fn α β γ δ) meta def startup_fn (α β γ δ : Type) : Type := search_state α β γ δ → metric α β γ δ → vertex → vertex → tactic (search_state α β γ δ) meta def step_fn (α β γ δ : Type) : Type := search_state α β γ δ → metric α β γ δ → ℕ → tactic (search_state α β γ δ × status) meta structure strategy (α β γ δ : Type) := (init : init_fn α) (startup : startup_fn α β γ δ) (step : step_fn α β γ δ) meta structure inst (α β γ δ : Type) := (metric : metric α β γ δ) (strategy : strategy α β γ δ) (g : search_state α β γ δ) meta def strategy_constructor (α : Type) := Π (β γ δ : Type), strategy α β γ δ meta def metric_constructor (β γ : Type) := Π (α δ : Type), metric α β γ δ meta def tracer_constructor (δ : Type) := Π (α β γ : Type), tracer α β γ δ namespace search_state variables {α β γ δ : Type} (g : search_state α β γ δ) meta def mutate_strat (new_state : α) : search_state α β γ δ := { g with strat_state := new_state } meta def mutate_metric (new_state : β) : search_state α β γ δ := { g with metric_state := new_state } meta def mutate_stats (new_stats : statistics) : search_state α β γ δ := { g with stats := new_stats} meta def set_vertex (v : vertex) : (search_state α β γ δ × vertex) := ({ g with vertices := g.vertices.set v.id v }, v) meta def lookup_pair (p : pair) : tactic (vertex × vertex) := do vf ← g.vertices.get p.l, vt ← g.vertices.get p.r, return (vf, vt) meta def get_endpoints (e : edge) : tactic (vertex × vertex) := do vf ← g.vertices.get e.f, vt ← g.vertices.get e.t, return (vf, vt) meta def get_estimate_verts (de : dist_estimate γ) : tactic (vertex × vertex) := g.lookup_pair de.to_pair end search_state meta structure siterator (α : Type) end tidy.rewrite_search
b8a08c7f85101e34bc5463917edc847cd211728e
2eab05920d6eeb06665e1a6df77b3157354316ad
/src/group_theory/specific_groups/cyclic.lean
34b0ae2eec603e8fd66125b638c526e33cfea782
[ "Apache-2.0" ]
permissive
ayush1801/mathlib
78949b9f789f488148142221606bf15c02b960d2
ce164e28f262acbb3de6281b3b03660a9f744e3c
refs/heads/master
1,692,886,907,941
1,635,270,866,000
1,635,270,866,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
19,206
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 -/ import algebra.big_operators.order import data.nat.totient import group_theory.order_of_element import tactic.group /-! # Cyclic groups A group `G` is called cyclic if there exists an element `g : G` such that every element of `G` is of the form `g ^ n` for some `n : ℕ`. This file only deals with the predicate on a group to be cyclic. For the concrete cyclic group of order `n`, see `data.zmod.basic`. ## Main definitions * `is_cyclic` is a predicate on a group stating that the group is cyclic. ## Main statements * `is_cyclic_of_prime_card` proves that a finite group of prime order is cyclic. * `is_simple_group_of_prime_card`, `is_simple_group.is_cyclic`, and `is_simple_group.prime_card` classify finite simple abelian groups. ## Implementation details This file is currently only available for multiplicatively written groups. ## Tags cyclic group ## TODO * Add the attribute `@[to_additive]` to the declarations about `is_cyclic`, so that they work for additive groups. -/ universe u variables {α : Type u} {a : α} section cyclic open_locale big_operators local attribute [instance] set_fintype open subgroup /-- A group is called *cyclic* if it is generated by a single element. -/ class is_cyclic (α : Type u) [group α] : Prop := (exists_generator [] : ∃ g : α, ∀ x, x ∈ gpowers g) @[priority 100] instance is_cyclic_of_subsingleton [group α] [subsingleton α] : is_cyclic α := ⟨⟨1, λ x, by { rw subsingleton.elim x 1, exact mem_gpowers 1 }⟩⟩ /-- A cyclic group is always commutative. This is not an `instance` because often we have a better proof of `comm_group`. -/ def is_cyclic.comm_group [hg : group α] [is_cyclic α] : comm_group α := { mul_comm := λ x y, show x * y = y * x, from let ⟨g, hg⟩ := is_cyclic.exists_generator α in let ⟨n, hn⟩ := hg x in let ⟨m, hm⟩ := hg y in hm ▸ hn ▸ gpow_mul_comm _ _ _, ..hg } variables [group α] lemma monoid_hom.map_cyclic {G : Type*} [group G] [h : is_cyclic G] (σ : G →* G) : ∃ m : ℤ, ∀ g : G, σ g = g ^ m := begin obtain ⟨h, hG⟩ := is_cyclic.exists_generator G, obtain ⟨m, hm⟩ := hG (σ h), use m, intro g, obtain ⟨n, rfl⟩ := hG g, rw [monoid_hom.map_gpow, ←hm, ←gpow_mul, ←gpow_mul'], end lemma is_cyclic_of_order_of_eq_card [fintype α] (x : α) (hx : order_of x = fintype.card α) : is_cyclic α := begin classical, use x, simp_rw ← set_like.mem_coe, rw ← set.eq_univ_iff_forall, apply set.eq_of_subset_of_card_le (set.subset_univ _), rw [fintype.card_congr (equiv.set.univ α), ← hx, order_eq_card_gpowers], end /-- A finite group of prime order is cyclic. -/ lemma is_cyclic_of_prime_card {α : Type u} [group α] [fintype α] {p : ℕ} [hp : fact p.prime] (h : fintype.card α = p) : is_cyclic α := ⟨begin obtain ⟨g, hg⟩ : ∃ g : α, g ≠ 1, from fintype.exists_ne_of_one_lt_card (by { rw h, exact hp.1.one_lt }) 1, classical, -- for fintype (subgroup.gpowers g) have : fintype.card (subgroup.gpowers g) ∣ p, { rw ←h, apply card_subgroup_dvd_card }, rw nat.dvd_prime hp.1 at this, cases this, { rw fintype.card_eq_one_iff at this, cases this with t ht, suffices : g = 1, { contradiction }, have hgt := ht ⟨g, by { change g ∈ subgroup.gpowers g, exact subgroup.mem_gpowers g }⟩, rw [←ht 1] at hgt, change (⟨_, _⟩ : subgroup.gpowers g) = ⟨_, _⟩ at hgt, simpa using hgt }, { use g, intro x, rw [←h] at this, rw subgroup.eq_top_of_card_eq _ this, exact subgroup.mem_top _ } end⟩ lemma order_of_eq_card_of_forall_mem_gpowers [fintype α] {g : α} (hx : ∀ x, x ∈ gpowers g) : order_of g = fintype.card α := by { classical, rw [← fintype.card_congr (equiv.set.univ α), order_eq_card_gpowers], simp [hx], apply fintype.card_of_finset', simp, intro x, exact hx x} instance bot.is_cyclic {α : Type u} [group α] : is_cyclic (⊥ : subgroup α) := ⟨⟨1, λ x, ⟨0, subtype.eq $ eq.symm (subgroup.mem_bot.1 x.2)⟩⟩⟩ instance subgroup.is_cyclic {α : Type u} [group α] [is_cyclic α] (H : subgroup α) : is_cyclic H := by haveI := classical.prop_decidable; exact let ⟨g, hg⟩ := is_cyclic.exists_generator α in if hx : ∃ (x : α), x ∈ H ∧ x ≠ (1 : α) then let ⟨x, hx₁, hx₂⟩ := hx in let ⟨k, hk⟩ := hg x in have hex : ∃ n : ℕ, 0 < n ∧ g ^ n ∈ H, from ⟨k.nat_abs, nat.pos_of_ne_zero (λ h, hx₂ $ by rw [← hk, int.eq_zero_of_nat_abs_eq_zero h, gpow_zero]), match k, hk with | (k : ℕ), hk := by rw [int.nat_abs_of_nat, ← gpow_coe_nat, hk]; exact hx₁ | -[1+ k], hk := by rw [int.nat_abs_of_neg_succ_of_nat, ← subgroup.inv_mem_iff H]; simp * at * end⟩, ⟨⟨⟨g ^ nat.find hex, (nat.find_spec hex).2⟩, λ ⟨x, hx⟩, let ⟨k, hk⟩ := hg x in have hk₁ : g ^ ((nat.find hex : ℤ) * (k / nat.find hex)) ∈ gpowers (g ^ nat.find hex), from ⟨k / nat.find hex, by rw [← gpow_coe_nat, gpow_mul]⟩, have hk₂ : g ^ ((nat.find hex : ℤ) * (k / nat.find hex)) ∈ H, by { rw gpow_mul, apply H.gpow_mem, exact_mod_cast (nat.find_spec hex).2 }, have hk₃ : g ^ (k % nat.find hex) ∈ H, from (subgroup.mul_mem_cancel_right H hk₂).1 $ by rw [← gpow_add, int.mod_add_div, hk]; exact hx, have hk₄ : k % nat.find hex = (k % nat.find hex).nat_abs, by rw int.nat_abs_of_nonneg (int.mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2 (nat.find_spec hex).1)), have hk₅ : g ^ (k % nat.find hex ).nat_abs ∈ H, by rwa [← gpow_coe_nat, ← hk₄], have hk₆ : (k % (nat.find hex : ℤ)).nat_abs = 0, from by_contradiction (λ h, nat.find_min hex (int.coe_nat_lt.1 $ by rw [← hk₄]; exact int.mod_lt_of_pos _ (int.coe_nat_pos.2 (nat.find_spec hex).1)) ⟨nat.pos_of_ne_zero h, hk₅⟩), ⟨k / (nat.find hex : ℤ), subtype.ext_iff_val.2 begin suffices : g ^ ((nat.find hex : ℤ) * (k / nat.find hex)) = x, { simpa [gpow_mul] }, rw [int.mul_div_cancel' (int.dvd_of_mod_eq_zero (int.eq_zero_of_nat_abs_eq_zero hk₆)), hk] end⟩⟩⟩ else have H = (⊥ : subgroup α), from subgroup.ext $ λ x, ⟨λ h, by simp at *; tauto, λ h, by rw [subgroup.mem_bot.1 h]; exact H.one_mem⟩, by clear _let_match; substI this; apply_instance open finset nat section classical open_locale classical lemma is_cyclic.card_pow_eq_one_le [decidable_eq α] [fintype α] [is_cyclic α] {n : ℕ} (hn0 : 0 < n) : (univ.filter (λ a : α, a ^ n = 1)).card ≤ n := let ⟨g, hg⟩ := is_cyclic.exists_generator α in calc (univ.filter (λ a : α, a ^ n = 1)).card ≤ ((gpowers (g ^ (fintype.card α / (gcd n (fintype.card α))))) : set α).to_finset.card : card_le_of_subset (λ x hx, let ⟨m, hm⟩ := show x ∈ submonoid.powers g, from mem_powers_iff_mem_gpowers.2 $ hg x in set.mem_to_finset.2 ⟨(m / (fintype.card α / (gcd n (fintype.card α))) : ℕ), have hgmn : g ^ (m * gcd n (fintype.card α)) = 1, by rw [pow_mul, hm, ← pow_gcd_card_eq_one_iff]; exact (mem_filter.1 hx).2, begin rw [gpow_coe_nat, ← pow_mul, nat.mul_div_cancel_left', hm], refine dvd_of_mul_dvd_mul_right (gcd_pos_of_pos_left (fintype.card α) hn0) _, conv {to_lhs, rw [nat.div_mul_cancel (gcd_dvd_right _ _), ← order_of_eq_card_of_forall_mem_gpowers hg]}, exact order_of_dvd_of_pow_eq_one hgmn end⟩) ... ≤ n : let ⟨m, hm⟩ := gcd_dvd_right n (fintype.card α) in have hm0 : 0 < m, from nat.pos_of_ne_zero $ λ hm0, by { rw [hm0, mul_zero, fintype.card_eq_zero_iff] at hm, exact hm.elim' 1 }, begin rw [← fintype.card_of_finset' _ (λ _, set.mem_to_finset), ← order_eq_card_gpowers, order_of_pow g, order_of_eq_card_of_forall_mem_gpowers hg], rw [hm] {occs := occurrences.pos [2,3]}, rw [nat.mul_div_cancel_left _ (gcd_pos_of_pos_left _ hn0), gcd_mul_left_left, hm, nat.mul_div_cancel _ hm0], exact le_of_dvd hn0 (gcd_dvd_left _ _) end end classical lemma is_cyclic.exists_monoid_generator [fintype α] [is_cyclic α] : ∃ x : α, ∀ y : α, y ∈ submonoid.powers x := by { simp_rw [mem_powers_iff_mem_gpowers], exact is_cyclic.exists_generator α } section variables [decidable_eq α] [fintype α] lemma is_cyclic.image_range_order_of (ha : ∀ x : α, x ∈ gpowers a) : finset.image (λ i, a ^ i) (range (order_of a)) = univ := begin simp_rw [←set_like.mem_coe] at ha, simp only [image_range_order_of, set.eq_univ_iff_forall.mpr ha], convert set.to_finset_univ end lemma is_cyclic.image_range_card (ha : ∀ x : α, x ∈ gpowers a) : finset.image (λ i, a ^ i) (range (fintype.card α)) = univ := by rw [← order_of_eq_card_of_forall_mem_gpowers ha, is_cyclic.image_range_order_of ha] end section totient variables [decidable_eq α] [fintype α] (hn : ∀ n : ℕ, 0 < n → (univ.filter (λ a : α, a ^ n = 1)).card ≤ n) include hn lemma card_pow_eq_one_eq_order_of_aux (a : α) : (finset.univ.filter (λ b : α, b ^ order_of a = 1)).card = order_of a := le_antisymm (hn _ (order_of_pos a)) (calc order_of a = @fintype.card (gpowers a) (id _) : order_eq_card_gpowers ... ≤ @fintype.card (↑(univ.filter (λ b : α, b ^ order_of a = 1)) : set α) (fintype.of_finset _ (λ _, iff.rfl)) : @fintype.card_le_of_injective (gpowers a) (↑(univ.filter (λ b : α, b ^ order_of a = 1)) : set α) (id _) (id _) (λ b, ⟨b.1, mem_filter.2 ⟨mem_univ _, let ⟨i, hi⟩ := b.2 in by rw [← hi, ← gpow_coe_nat, ← gpow_mul, mul_comm, gpow_mul, gpow_coe_nat, pow_order_of_eq_one, one_gpow]⟩⟩) (λ _ _ h, subtype.eq (subtype.mk.inj h)) ... = (univ.filter (λ b : α, b ^ order_of a = 1)).card : fintype.card_of_finset _ _) open_locale nat -- use φ for nat.totient private lemma card_order_of_eq_totient_aux₁ : ∀ {d : ℕ}, d ∣ fintype.card α → 0 < (univ.filter (λ a : α, order_of a = d)).card → (univ.filter (λ a : α, order_of a = d)).card = φ d | 0 := λ hd hd0, let ⟨a, ha⟩ := card_pos.1 hd0 in absurd (mem_filter.1 ha).2 $ ne_of_gt $ order_of_pos a | (d+1) := λ hd hd0, let ⟨a, ha⟩ := card_pos.1 hd0 in have ha : order_of a = d.succ, from (mem_filter.1 ha).2, have h : ∑ m in (range d.succ).filter (∣ d.succ), (univ.filter (λ a : α, order_of a = m)).card = ∑ m in (range d.succ).filter (∣ d.succ), φ m, from finset.sum_congr rfl (λ m hm, have hmd : m < d.succ, from mem_range.1 (mem_filter.1 hm).1, have hm : m ∣ d.succ, from (mem_filter.1 hm).2, card_order_of_eq_totient_aux₁ (hm.trans hd) (finset.card_pos.2 ⟨a ^ (d.succ / m), mem_filter.2 ⟨mem_univ _, by { rw [order_of_pow a, ha, gcd_eq_right (div_dvd_of_dvd hm), nat.div_div_self hm (succ_pos _)] }⟩⟩)), have hinsert : insert d.succ ((range d.succ).filter (∣ d.succ)) = (range d.succ.succ).filter (∣ d.succ), from (finset.ext $ λ x, ⟨λ h, (mem_insert.1 h).elim (λ h, by simp [h, range_succ]) (by clear _let_match; simp [range_succ]; tauto), by clear _let_match; simp [range_succ] {contextual := tt}; tauto⟩), have hinsert₁ : d.succ ∉ (range d.succ).filter (∣ d.succ), by simp [mem_range, zero_le_one, le_succ], (add_left_inj (∑ m in (range d.succ).filter (∣ d.succ), (univ.filter (λ a : α, order_of a = m)).card)).1 (calc _ = ∑ m in insert d.succ (filter (∣ d.succ) (range d.succ)), (univ.filter (λ a : α, order_of a = m)).card : eq.symm (finset.sum_insert (by simp [mem_range, zero_le_one, le_succ])) ... = ∑ m in (range d.succ.succ).filter (∣ d.succ), (univ.filter (λ a : α, order_of a = m)).card : sum_congr hinsert (λ _ _, rfl) ... = (univ.filter (λ a : α, a ^ d.succ = 1)).card : sum_card_order_of_eq_card_pow_eq_one (succ_pos d) ... = ∑ m in (range d.succ.succ).filter (∣ d.succ), φ m : ha ▸ (card_pow_eq_one_eq_order_of_aux hn a).symm ▸ (sum_totient _).symm ... = _ : by rw [h, ← sum_insert hinsert₁]; exact finset.sum_congr hinsert.symm (λ _ _, rfl)) lemma card_order_of_eq_totient_aux₂ {d : ℕ} (hd : d ∣ fintype.card α) : (univ.filter (λ a : α, order_of a = d)).card = φ d := by_contradiction $ λ h, have h0 : (univ.filter (λ a : α , order_of a = d)).card = 0 := not_not.1 (mt pos_iff_ne_zero.2 (mt (card_order_of_eq_totient_aux₁ hn hd) h)), let c := fintype.card α in have hc0 : 0 < c, from fintype.card_pos_iff.2 ⟨1⟩, lt_irrefl c $ calc c = (univ.filter (λ a : α, a ^ c = 1)).card : congr_arg card $ by simp [finset.ext_iff, c] ... = ∑ m in (range c.succ).filter (∣ c), (univ.filter (λ a : α, order_of a = m)).card : (sum_card_order_of_eq_card_pow_eq_one hc0).symm ... = ∑ m in ((range c.succ).filter (∣ c)).erase d, (univ.filter (λ a : α, order_of a = m)).card : eq.symm (sum_subset (erase_subset _ _) (λ m hm₁ hm₂, have m = d, by simp at *; cc, by simp [*, finset.ext_iff] at *; exact h0)) ... ≤ ∑ m in ((range c.succ).filter (∣ c)).erase d, φ m : sum_le_sum (λ m hm, have hmc : m ∣ c, by simp at hm; tauto, (imp_iff_not_or.1 (card_order_of_eq_totient_aux₁ hn hmc)).elim (λ h, by simp [nat.le_zero_iff.1 (le_of_not_gt h), nat.zero_le]) (λ h, by rw h)) ... < φ d + ∑ m in ((range c.succ).filter (∣ c)).erase d, φ m : lt_add_of_pos_left _ (totient_pos (nat.pos_of_ne_zero (λ h, pos_iff_ne_zero.1 hc0 (eq_zero_of_zero_dvd $ h ▸ hd)))) ... = ∑ m in insert d (((range c.succ).filter (∣ c)).erase d), φ m : eq.symm (sum_insert (by simp)) ... = ∑ m in (range c.succ).filter (∣ c), φ m : finset.sum_congr (finset.insert_erase (mem_filter.2 ⟨mem_range.2 (lt_succ_of_le (le_of_dvd hc0 hd)), hd⟩)) (λ _ _, rfl) ... = c : sum_totient _ lemma is_cyclic_of_card_pow_eq_one_le : is_cyclic α := have (univ.filter (λ a : α, order_of a = fintype.card α)).nonempty, from (card_pos.1 $ by rw [card_order_of_eq_totient_aux₂ hn dvd_rfl]; exact totient_pos (fintype.card_pos_iff.2 ⟨1⟩)), let ⟨x, hx⟩ := this in is_cyclic_of_order_of_eq_card x (finset.mem_filter.1 hx).2 end totient lemma is_cyclic.card_order_of_eq_totient [is_cyclic α] [fintype α] {d : ℕ} (hd : d ∣ fintype.card α) : (univ.filter (λ a : α, order_of a = d)).card = totient d := begin classical, apply card_order_of_eq_totient_aux₂ (λ n, is_cyclic.card_pow_eq_one_le) hd end /-- A finite group of prime order is simple. -/ lemma is_simple_group_of_prime_card {α : Type u} [group α] [fintype α] {p : ℕ} [hp : fact p.prime] (h : fintype.card α = p) : is_simple_group α := ⟨begin have h' := nat.prime.one_lt (fact.out p.prime), rw ← h at h', haveI := fintype.one_lt_card_iff_nontrivial.1 h', apply exists_pair_ne α, end, λ H Hn, begin classical, have hcard := card_subgroup_dvd_card H, rw [h, dvd_prime (fact.out p.prime)] at hcard, refine hcard.imp (λ h1, _) (λ hp, _), { haveI := fintype.card_le_one_iff_subsingleton.1 (le_of_eq h1), apply eq_bot_of_subsingleton }, { exact eq_top_of_card_eq _ (hp.trans h.symm) } end⟩ end cyclic section quotient_center open subgroup variables {G : Type*} {H : Type*} [group G] [group H] /-- A group is commutative if the quotient by the center is cyclic. Also see `comm_group_of_cycle_center_quotient` for the `comm_group` instance -/ lemma commutative_of_cyclic_center_quotient [is_cyclic H] (f : G →* H) (hf : f.ker ≤ center G) (a b : G) : a * b = b * a := let ⟨⟨x, y, (hxy : f y = x)⟩, (hx : ∀ a : f.range, a ∈ gpowers _)⟩ := is_cyclic.exists_generator f.range in let ⟨m, hm⟩ := hx ⟨f a, a, rfl⟩ in let ⟨n, hn⟩ := hx ⟨f b, b, rfl⟩ in have hm : x ^ m = f a, by simpa [subtype.ext_iff] using hm, have hn : x ^ n = f b, by simpa [subtype.ext_iff] using hn, have ha : y ^ (-m) * a ∈ center G, from hf (by rw [f.mem_ker, f.map_mul, f.map_gpow, hxy, gpow_neg, hm, inv_mul_self]), have hb : y ^ (-n) * b ∈ center G, from hf (by rw [f.mem_ker, f.map_mul, f.map_gpow, hxy, gpow_neg, hn, inv_mul_self]), calc a * b = y ^ m * ((y ^ (-m) * a) * y ^ n) * (y ^ (-n) * b) : by simp [mul_assoc] ... = y ^ m * (y ^ n * (y ^ (-m) * a)) * (y ^ (-n) * b) : by rw [mem_center_iff.1 ha] ... = y ^ m * y ^ n * y ^ (-m) * (a * (y ^ (-n) * b)) : by simp [mul_assoc] ... = y ^ m * y ^ n * y ^ (-m) * ((y ^ (-n) * b) * a) : by rw [mem_center_iff.1 hb] ... = b * a : by group /-- A group is commutative if the quotient by the center is cyclic. -/ def comm_group_of_cycle_center_quotient [is_cyclic H] (f : G →* H) (hf : f.ker ≤ center G) : comm_group G := { mul_comm := commutative_of_cyclic_center_quotient f hf, ..show group G, by apply_instance } end quotient_center namespace is_simple_group section comm_group variables [comm_group α] [is_simple_group α] @[priority 100] instance : is_cyclic α := begin cases subsingleton_or_nontrivial α with hi hi; haveI := hi, { apply is_cyclic_of_subsingleton }, { obtain ⟨g, hg⟩ := exists_ne (1 : α), refine ⟨⟨g, λ x, _⟩⟩, cases is_simple_lattice.eq_bot_or_eq_top (subgroup.gpowers g) with hb ht, { exfalso, apply hg, rw [← subgroup.mem_bot, ← hb], apply subgroup.mem_gpowers }, { rw ht, apply subgroup.mem_top } } end theorem prime_card [fintype α] : (fintype.card α).prime := begin have h0 : 0 < fintype.card α := fintype.card_pos_iff.2 (by apply_instance), obtain ⟨g, hg⟩ := is_cyclic.exists_generator α, refine ⟨fintype.one_lt_card_iff_nontrivial.2 infer_instance, λ n hn, _⟩, refine (is_simple_lattice.eq_bot_or_eq_top (subgroup.gpowers (g ^ n))).symm.imp _ _, { intro h, have hgo := order_of_pow g, rw [order_of_eq_card_of_forall_mem_gpowers hg, nat.gcd_eq_right_iff_dvd.1 hn, order_of_eq_card_of_forall_mem_gpowers, eq_comm, nat.div_eq_iff_eq_mul_left (nat.pos_of_dvd_of_pos hn h0) hn] at hgo, { exact (mul_left_cancel₀ (ne_of_gt h0) ((mul_one (fintype.card α)).trans hgo)).symm }, { intro x, rw h, exact subgroup.mem_top _ } }, { intro h, apply le_antisymm (nat.le_of_dvd h0 hn), rw ← order_of_eq_card_of_forall_mem_gpowers hg, apply order_of_le_of_pow_eq_one (nat.pos_of_dvd_of_pos hn h0), rw [← subgroup.mem_bot, ← h], exact subgroup.mem_gpowers _ } end end comm_group end is_simple_group theorem comm_group.is_simple_iff_is_cyclic_and_prime_card [fintype α] [comm_group α] : is_simple_group α ↔ is_cyclic α ∧ (fintype.card α).prime := begin split, { introI h, exact ⟨is_simple_group.is_cyclic, is_simple_group.prime_card⟩ }, { rintro ⟨hc, hp⟩, haveI : fact (fintype.card α).prime := ⟨hp⟩, exact is_simple_group_of_prime_card rfl } end
8f26dc363be15f27b2a0f821bea2ed85230c270d
de44c57911f8f2292d4105ccefe4372f3880a7b7
/src/hol.lean
e45755d92f89c47058e7589e71002c746c1373f0
[]
no_license
nyuichi/LeanHOL
108b1df4daab61b60b0160a7f56cf6b7dd8f57fe
8190f2d4234f0f39c9e7b5612e552e72ab002798
refs/heads/master
1,587,207,990,491
1,569,724,629,000
1,569,724,629,000
167,488,678
22
0
null
null
null
null
UTF-8
Lean
false
false
9,062
lean
-- 3. higher order logic import moromoro import logic.basic namespace hol inductive type : Type | base : type | prop : type | arrow : type → type → type open type variable ν : type → Type inductive term : type → Type | var : Π {t}, ν t → term t | lam : Π {t₁ t₂}, (ν t₁ → term t₂) → term (arrow t₁ t₂) | app : Π {t₁ t₂}, term (arrow t₁ t₂) → term t₁ → term t₂ | eq : Π {t}, term t → term t → term prop open term def Term (t : type) : Type 1 := Π ν, term ν t def judgment : list type → type → Type := λ Γ t, list.foldr (λ t α, ν t → α) (term ν t) Γ def Judgment (Γ : list type) (t : type) : Type 1 := Π ν, judgment ν Γ t ---- universe u variables {α β : Type u} inductive mem : α → list α → Type u | here : Π {x l}, mem x (x :: l) | there : Π {x l y}, mem x l → mem x (y :: l) open mem local infix ` ∈' `:50 := mem variables {Γ Γ₁ Γ₂ : list type} {t t₁ t₂ t₃ : type} def subst' : Π {t : type}, term (term ν) t → term ν t | _ (var m) := m | _ (lam f) := lam (λ x, subst' (f (var x))) | _ (app m₁ m₂) := app (subst' m₁) (subst' m₂) | _ (eq m₁ m₂) := eq (subst' m₁) (subst' m₂) namespace judgment def weak : Judgment Γ t₂ → Judgment (t₁ :: Γ) t₂ := λ m ν x, m ν def var' : Π {Γ}, judgment ν (t :: Γ) t | [] := λ x, var x | (t :: Γ) := λ x y, var' x def var : Π {Γ}, t ∈' Γ → Judgment Γ t | _ here := λ ν, var' ν | _ (there h) := weak (var h) def lam' : Π {Γ}, judgment ν (t₁ :: Γ) t₂ → judgment ν Γ (arrow t₁ t₂) | [] m := lam (λ x, m x) | (t :: Γ) f := λ x, lam' (λ y, f y x) def lam : Judgment (t₁ :: Γ) t₂ → Judgment Γ (arrow t₁ t₂) := λ m ν, lam' ν (m ν) def app' : Π {Γ}, judgment ν Γ (arrow t₁ t₂) → judgment ν Γ t₁ → judgment ν Γ t₂ | [] m₁ m₂ := app m₁ m₂ | (t :: Γ) f m := λ x, app' (f x) (m x) def app : Judgment Γ (arrow t₁ t₂) → Judgment Γ t₁ → Judgment Γ t₂ := λ m₁ m₂ ν, app' ν (m₁ ν) (m₂ ν) def eq' : Π {Γ : list type}, judgment ν Γ t → judgment ν Γ t → judgment ν Γ prop | [] m₁ m₂ := eq m₁ m₂ | (t :: Γ) m₁ m₂ := λ x, eq' (m₁ x) (m₂ x) def eq : Judgment Γ t → Judgment Γ t → Judgment Γ prop := λ m₁ m₂ ν, eq' ν (m₁ ν) (m₂ ν) def subst'' : Π {Γ}, judgment (term ν) (t₁ :: Γ) t₂ → judgment ν Γ t₁ → judgment ν Γ t₂ | [] m₁ m₂ := subst' ν (m₁ m₂) | (t :: Γ) f m := λ x, subst'' (λ x', f x' (term.var x)) (m x) def subst : Judgment (t₁ :: Γ) t₂ → Judgment Γ t₁ → Judgment Γ t₂ := λ m₁ m₂ ν, subst'' ν (m₁ _) (m₂ ν) end judgment open judgment ---- def type.foldr : list type → type → type := λ Γ t, list.foldr arrow t Γ def judgment.to_term' : Π {Γ : list type}, judgment ν Γ t → term ν (type.foldr Γ t) | [] m := m | (t :: Γ) f := lam (λ x, judgment.to_term' (f x)) def judgment.to_term : Judgment Γ t → Term (type.foldr Γ t) := λ m ν, judgment.to_term' ν (m ν) def term.to_judgment' : Π {Γ : list type}, term (term ν) (type.foldr Γ t) → judgment ν Γ t | [] m := subst' ν m | (t :: Γ) m := match m with | (var x) := λ x, term.to_judgment' (app m (var (var x))) | (lam f) := λ x, term.to_judgment' (f (var x)) | (app m₁ m₂) := λ x, term.to_judgment' (app m (var (var x))) end def term.to_judgment : Term (type.foldr Γ t) → Judgment Γ t := λ m ν, term.to_judgment' ν (m _) ---- def domain : type → Type | base := term ν base | prop := term ν prop | (arrow t₁ t₂) := domain t₁ → domain t₂ def Domain (t : type) : Type 1 := Π ν, domain ν t def reify_reflect : Π (t : type), (domain ν t → term ν t) × (term ν t → domain ν t) | base := ⟨ id, id ⟩ | prop := ⟨ id, id ⟩ | (arrow t₁ t₂) := let r₁ := reify_reflect t₁ in let r₂ := reify_reflect t₂ in let reify (f : domain ν t₁ → domain ν t₂) := lam (λ x, r₂.1 (f (r₁.2 (var x)))) in let reflect (f : term ν (arrow t₁ t₂)) := λ x, r₂.2 (app f (r₁.1 x)) in ⟨reify, reflect⟩ def reify' : domain ν t → term ν t := λ x, (reify_reflect ν t).1 x def reify : Domain t → Term t := λ x ν, reify' ν (x ν) def eval' : Π {t : type}, term (domain ν) t → domain ν t | _ (var x) := x | _ (lam f) := λ x, eval' (f x) | _ (app m₁ m₂) := (eval' m₁) (eval' m₂) | _ (eq m₁ m₂) := eq (reify' ν (eval' m₁)) (reify' ν (eval' m₂)) def eval : Term t → Domain t := λ m ν, eval' ν (m _) def normalize : Term t → Term t := reify ∘ eval instance term_setoid : setoid (Term t) := ⟨inv_image eq normalize, inv_image.equivalence eq normalize eq_equivalence⟩ instance judgment_setoid [h : setoid (Term (type.foldr Γ t))] : setoid (Judgment Γ t) := ⟨inv_image h.r judgment.to_term, inv_image.equivalence h.r judgment.to_term h.iseqv⟩ meta def canonicity : tactic unit := `[ try { unfold has_equiv.equiv setoid.r inv_image }, try { reflexivity } ] ---- namespace term def top : Term prop := λ ν, eq (lam (λ x : ν prop, var x)) (lam (λ x, var x)) def and : Term (arrow prop (arrow prop prop)) := λ ν, lam (λ p₁, lam (λ p₂, eq (lam (λ f : ν (arrow _ (arrow _ prop)), app (app (var f) (top ν)) (top ν))) (lam (λ f, app (app (var f) (var p₁)) (var p₂))))) def Forall : Term (arrow (arrow t prop) prop) := λ ν, lam (λ f, eq (var f) (lam (λ x, (top ν)))) def bot : Term prop := λ ν, app (Forall ν) (lam (λ p, var p)) def implies : Term (arrow prop (arrow prop prop)) := λ ν, lam (λ p₁, lam (λ p₂, eq (app (app (and ν) (var p₁)) (var p₂)) (var p₁))) def not : Term (arrow prop prop) := λ ν, lam (λ p, app (app (implies ν) (var p)) (bot ν)) def iff : Term (arrow prop (arrow prop prop)) := λ ν, lam (λ p₁, lam (λ p₂, app (app (and ν) (app (app (implies ν) (var p₁)) (var p₂))) (app (app (implies ν) (var p₂)) (var p₁)))) def or : Term (arrow prop (arrow prop prop)) := λ ν, lam (λ p₁, lam (λ p₂, app (Forall ν) (lam (λ r, app (app (implies ν) (app (app (and ν) (app (app (implies ν) (var p₁)) (var r))) (app (app (implies ν) (var p₂)) (var r)))) (var r))))) def Exists : Term (arrow (arrow t prop) prop) := λ ν, lam (λ f, app (Forall ν) (lam (λ r, app (app (implies ν) (app (Forall ν) (lam (λ x, app (app (implies ν) (app (var f) (var x))) (var r))))) (var r)))) end term open term #reduce @id (Judgment [] prop) $ app (app and top) (app (app or bot) top) ---- inductive Theorem : Π {Γ}, list (Judgment Γ prop) → Judgment Γ prop → Prop | hyp : Π {Γ Φ} {φ : Judgment Γ prop}, φ ∈ Φ → Theorem Φ φ | refl : Π {Γ Φ t} {m₁ m₂ : Judgment Γ t}, m₁ ≈ m₂ → Theorem Φ (eq m₁ m₂) | subst : Π {Γ Φ t} (m : Judgment (t :: Γ) prop) (m₂ m₁ : Judgment Γ t), Theorem Φ (eq m₁ m₂) → Theorem Φ (subst m m₁) → Theorem Φ (subst m m₂) | prop_ext : Π {Γ Φ} {φ₁ φ₂ : Judgment Γ prop}, Theorem (φ₁ :: Φ) φ₂ → Theorem (φ₂ :: Φ) φ₁ → Theorem Φ (eq φ₁ φ₂) | fun_ext : Π {Γ Φ t₁ t₂} (m₁ m₂ : Judgment (t₁ :: Γ) t₂), Theorem (list.map weak Φ) (eq m₁ m₂) → Theorem Φ (eq (lam m₁) (lam m₂)) -- Let's prove! example : @Theorem [prop] [var here] (eq (weak top) (var here)) := begin apply Theorem.prop_ext, { apply Theorem.hyp, simp }, { apply Theorem.refl, canonicity } end example {φ₁ φ₂} {Φ : list (Judgment [] prop)} : Theorem Φ (app (app and φ₁) φ₂) → Theorem Φ φ₁ := begin intro p, apply Theorem.subst (var here) φ₁ (λ ν, app (lam (λ f, app (app (var f) (φ₁ ν)) (φ₂ ν))) (lam (λ p₁, lam (λ p₂, var p₁)))), { apply Theorem.refl, canonicity, }, { apply Theorem.subst (@id (Judgment [arrow _ prop] prop) $ λ ν f, app (var f) (lam (λ p₁, lam (λ p₂, var p₁)))) (λ ν, lam (λ f, app (app (var f) (φ₁ ν)) (φ₂ ν))) (@id (Judgment [] (arrow _ prop)) $ λ ν, lam (λ f, app (app (var f) (top ν)) (top ν))), { apply Theorem.subst (var here) (eq (@id (Judgment [] (arrow _ prop)) $ λ ν, lam (λ f, app (app (var f) (top ν)) (top ν))) (λ ν, lam (λ f, app (app (var f) (φ₁ ν)) (φ₂ ν)))) (λ ν, app (app (lam (λ p₁, lam (λ p₂, eq (lam (λ f : ν (arrow _ (arrow _ prop)), app (app (var f) (top ν)) (top ν))) (lam (λ f, app (app (var f) (var p₁)) (var p₂)))))) (φ₁ ν)) (φ₂ ν)), { apply Theorem.refl, canonicity }, { from p } }, { apply Theorem.subst (var here) (@id (Judgment [] _) $ λ ν, app (lam (λ f, app (app (var f) (top ν)) (top ν))) (lam (λ p₁, lam (λ p₂, var p₁)))) top, { apply Theorem.refl, canonicity }, { apply Theorem.refl, canonicity } } } end end hol
b3cc0f882e5496744f1e9185cfdbaa91ea0c6f5b
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/data/matrix/reflection.lean
690bed1a0d04abf12e7ae5b0a74d2d57ee71b5a7
[ "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,519
lean
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import data.matrix.notation import data.matrix.basic import data.fin.tuple.reflection /-! # Lemmas for concrete matrices `matrix (fin m) (fin n) α` > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file contains alternative definitions of common operators on matrices that expand definitionally to the expected expression when evaluated on `!![]` notation. This allows "proof by reflection", where we prove `A = !![A 0 0, A 0 1; A 1 0, A 1 1]` by defining `matrix.eta_expand A` to be equal to the RHS definitionally, and then prove that `A = eta_expand A`. The definitions in this file should normally not be used directly; the intent is for the corresponding `*_eq` lemmas to be used in a place where they are definitionally unfolded. ## Main definitionss * `matrix.transposeᵣ` * `matrix.dot_productᵣ` * `matrix.mulᵣ` * `matrix.mul_vecᵣ` * `matrix.vec_mulᵣ` * `matrix.eta_expand` -/ open_locale matrix namespace matrix variables {l m n : ℕ} {α β : Type*} /-- `∀` with better defeq for `∀ x : matrix (fin m) (fin n) α, P x`. -/ def «forall» : Π {m n} (P : (matrix (fin m) (fin n) α) → Prop), Prop | 0 n P := P (of ![]) | (m + 1) n P := fin_vec.forall $ λ r, «forall» (λ A, P (of (matrix.vec_cons r A))) /-- This can be use to prove ```lean example (P : matrix (fin 2) (fin 3) α → Prop) : (∀ x, P x) ↔ ∀ a b c d e f, P !![a, b, c; d, e, f] := (forall_iff _).symm ``` -/ lemma forall_iff : Π {m n} (P : (matrix (fin m) (fin n) α) → Prop), «forall» P ↔ ∀ x, P x | 0 n P := iff.symm fin.forall_fin_zero_pi | (m + 1) n P := begin simp only [«forall», fin_vec.forall_iff, forall_iff], exact iff.symm fin.forall_fin_succ_pi, end example (P : matrix (fin 2) (fin 3) α → Prop) : (∀ x, P x) ↔ ∀ a b c d e f, P !![a, b, c; d, e, f] := (forall_iff _).symm /--`∃` with better defeq for `∃ x : matrix (fin m) (fin n) α, P x`. -/ def «exists» : Π {m n} (P : (matrix (fin m) (fin n) α) → Prop), Prop | 0 n P := P (of ![]) | (m + 1) n P := fin_vec.exists $ λ r, «exists» (λ A, P (of (matrix.vec_cons r A))) /-- This can be use to prove ```lean example (P : matrix (fin 2) (fin 3) α → Prop) : (∃ x, P x) ↔ ∃ a b c d e f, P !![a, b, c; d, e, f] := (exists_iff _).symm ``` -/ lemma exists_iff : Π {m n} (P : (matrix (fin m) (fin n) α) → Prop), «exists» P ↔ ∃ x, P x | 0 n P := iff.symm fin.exists_fin_zero_pi | (m + 1) n P := begin simp only [«exists», fin_vec.exists_iff, exists_iff], exact iff.symm fin.exists_fin_succ_pi, end example (P : matrix (fin 2) (fin 3) α → Prop) : (∃ x, P x) ↔ ∃ a b c d e f, P !![a, b, c; d, e, f] := (exists_iff _).symm /-- `matrix.tranpose` with better defeq for `fin` -/ def transposeᵣ : Π {m n}, matrix (fin m) (fin n) α → matrix (fin n) (fin m) α | _ 0 A := of ![] | m (n + 1) A := of $ vec_cons (fin_vec.map (λ v : fin _ → α, v 0) A) (transposeᵣ (A.submatrix id fin.succ)) /-- This can be used to prove ```lean example (a b c d : α) : transpose !![a, b; c, d] = !![a, c; b, d] := (transposeᵣ_eq _).symm ``` -/ @[simp] lemma transposeᵣ_eq : Π {m n} (A : matrix (fin m) (fin n) α), transposeᵣ A = transpose A | _ 0 A := subsingleton.elim _ _ | m (n + 1) A := matrix.ext $ λ i j, begin simp_rw [transposeᵣ, transposeᵣ_eq], refine i.cases _ (λ i, _), { dsimp, rw fin_vec.map_eq }, { simp only [of_apply, matrix.cons_val_succ], refl }, end example (a b c d : α) : transpose !![a, b; c, d] = !![a, c; b, d] := (transposeᵣ_eq _).symm /-- `matrix.dot_product` with better defeq for `fin` -/ def dot_productᵣ [has_mul α] [has_add α] [has_zero α] {m} (a b : fin m → α) : α := fin_vec.sum $ fin_vec.seq (fin_vec.map (*) a) b /-- This can be used to prove ```lean example (a b c d : α) [has_mul α] [add_comm_monoid α] : dot_product ![a, b] ![c, d] = a * c + b * d := (dot_productᵣ_eq _ _).symm ``` -/ @[simp] lemma dot_productᵣ_eq [has_mul α] [add_comm_monoid α] {m} (a b : fin m → α) : dot_productᵣ a b = dot_product a b := by simp_rw [dot_productᵣ, dot_product, fin_vec.sum_eq, fin_vec.seq_eq, fin_vec.map_eq] example (a b c d : α) [has_mul α] [add_comm_monoid α] : dot_product ![a, b] ![c, d] = a * c + b * d := (dot_productᵣ_eq _ _).symm /-- `matrix.mul` with better defeq for `fin` -/ def mulᵣ [has_mul α] [has_add α] [has_zero α] (A : matrix (fin l) (fin m) α) (B : matrix (fin m) (fin n) α) : matrix (fin l) (fin n) α := of $ fin_vec.map (λ v₁, fin_vec.map (λ v₂, dot_productᵣ v₁ v₂) Bᵀ) A /-- This can be used to prove ```lean example [add_comm_monoid α] [has_mul α] (a₁₁ a₁₂ a₂₁ a₂₂ b₁₁ b₁₂ b₂₁ b₂₂ : α) : !![a₁₁, a₁₂; a₂₁, a₂₂] ⬝ !![b₁₁, b₁₂; b₂₁, b₂₂] = !![a₁₁*b₁₁ + a₁₂*b₂₁, a₁₁*b₁₂ + a₁₂*b₂₂; a₂₁*b₁₁ + a₂₂*b₂₁, a₂₁*b₁₂ + a₂₂*b₂₂] := (mulᵣ_eq _ _).symm ``` -/ @[simp] lemma mulᵣ_eq [has_mul α] [add_comm_monoid α] (A : matrix (fin l) (fin m) α) (B : matrix (fin m) (fin n) α) : mulᵣ A B = A.mul B := begin simp [mulᵣ, function.comp, matrix.mul, matrix.transpose], refl, end example [add_comm_monoid α] [has_mul α] (a₁₁ a₁₂ a₂₁ a₂₂ b₁₁ b₁₂ b₂₁ b₂₂ : α) : !![a₁₁, a₁₂; a₂₁, a₂₂].mul !![b₁₁, b₁₂; b₂₁, b₂₂] = !![a₁₁*b₁₁ + a₁₂*b₂₁, a₁₁*b₁₂ + a₁₂*b₂₂; a₂₁*b₁₁ + a₂₂*b₂₁, a₂₁*b₁₂ + a₂₂*b₂₂] := (mulᵣ_eq _ _).symm /-- `matrix.mul_vec` with better defeq for `fin` -/ def mul_vecᵣ [has_mul α] [has_add α] [has_zero α] (A : matrix (fin l) (fin m) α) (v : fin m → α) : fin l → α := fin_vec.map (λ a, dot_productᵣ a v) A /-- This can be used to prove ```lean example [non_unital_non_assoc_semiring α] (a₁₁ a₁₂ a₂₁ a₂₂ b₁ b₂ : α) : !![a₁₁, a₁₂; a₂₁, a₂₂].mul_vec ![b₁, b₂] = ![a₁₁*b₁ + a₁₂*b₂, a₂₁*b₁ + a₂₂*b₂] := (mul_vecᵣ_eq _ _).symm ``` -/ @[simp] lemma mul_vecᵣ_eq [non_unital_non_assoc_semiring α] (A : matrix (fin l) (fin m) α) (v : fin m → α) : mul_vecᵣ A v = A.mul_vec v := begin simp [mul_vecᵣ, function.comp], refl, end example [non_unital_non_assoc_semiring α] (a₁₁ a₁₂ a₂₁ a₂₂ b₁ b₂ : α) : !![a₁₁, a₁₂; a₂₁, a₂₂].mul_vec ![b₁, b₂] = ![a₁₁*b₁ + a₁₂*b₂, a₂₁*b₁ + a₂₂*b₂] := (mul_vecᵣ_eq _ _).symm /-- `matrix.vec_mul` with better defeq for `fin` -/ def vec_mulᵣ [has_mul α] [has_add α] [has_zero α] (v : fin l → α) (A : matrix (fin l) (fin m) α): fin m → α := fin_vec.map (λ a, dot_productᵣ v a) Aᵀ /-- This can be used to prove ```lean example [non_unital_non_assoc_semiring α] (a₁₁ a₁₂ a₂₁ a₂₂ b₁ b₂ : α) : vec_mul ![b₁, b₂] !![a₁₁, a₁₂; a₂₁, a₂₂] = ![b₁*a₁₁ + b₂*a₂₁, b₁*a₁₂ + b₂*a₂₂] := (vec_mulᵣ_eq _ _).symm ``` -/ @[simp] lemma vec_mulᵣ_eq [non_unital_non_assoc_semiring α] (v : fin l → α) (A : matrix (fin l) (fin m) α) : vec_mulᵣ v A = vec_mul v A := begin simp [vec_mulᵣ, function.comp], refl, end example [non_unital_non_assoc_semiring α] (a₁₁ a₁₂ a₂₁ a₂₂ b₁ b₂ : α) : vec_mul ![b₁, b₂] !![a₁₁, a₁₂; a₂₁, a₂₂] = ![b₁*a₁₁ + b₂*a₂₁, b₁*a₁₂ + b₂*a₂₂] := (vec_mulᵣ_eq _ _).symm /-- Expand `A` to `!![A 0 0, ...; ..., A m n]` -/ def eta_expand {m n} (A : matrix (fin m) (fin n) α) : matrix (fin m) (fin n) α := matrix.of (fin_vec.eta_expand (λ i, fin_vec.eta_expand (λ j, A i j))) /-- This can be used to prove ```lean example (A : matrix (fin 2) (fin 2) α) : A = !![A 0 0, A 0 1; A 1 0, A 1 1] := (eta_expand_eq _).symm ``` -/ lemma eta_expand_eq {m n} (A : matrix (fin m) (fin n) α) : eta_expand A = A := by simp_rw [eta_expand, fin_vec.eta_expand_eq, matrix.of, equiv.refl_apply] example (A : matrix (fin 2) (fin 2) α) : A = !![A 0 0, A 0 1; A 1 0, A 1 1] := (eta_expand_eq _).symm end matrix
01724525c0b5d7a6c15a7c689bd4000411e240e8
ff5230333a701471f46c57e8c115a073ebaaa448
/library/data/rbtree/min_max.lean
9077bbadee9bc74749a24ba6ca4c05ba8e453cb8
[ "Apache-2.0" ]
permissive
stanford-cs242/lean
f81721d2b5d00bc175f2e58c57b710d465e6c858
7bd861261f4a37326dcf8d7a17f1f1f330e4548c
refs/heads/master
1,600,957,431,849
1,576,465,093,000
1,576,465,093,000
225,779,423
0
3
Apache-2.0
1,575,433,936,000
1,575,433,935,000
null
UTF-8
Lean
false
false
3,668
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import data.rbtree.basic universe u namespace rbnode variables {α : Type u} {lt : α → α → Prop} lemma mem_of_min_eq (lt : α → α → Prop) [is_irrefl α lt] {a : α} {t : rbnode α} : t.min = some a → mem lt a t := begin induction t, { intros, contradiction }, all_goals { cases t_lchild; simp [rbnode.min]; intro h, { subst t_val, simp [mem, irrefl_of lt a] }, all_goals { rw [mem], simp [t_ih_lchild h] } } end lemma mem_of_max_eq (lt : α → α → Prop) [is_irrefl α lt] {a : α} {t : rbnode α} : t.max = some a → mem lt a t := begin induction t, { intros, contradiction }, all_goals { cases t_rchild; simp [rbnode.max]; intro h, { subst t_val, simp [mem, irrefl_of lt a] }, all_goals { rw [mem], simp [t_ih_rchild h] } } end variables [decidable_rel lt] [is_strict_weak_order α lt] lemma eq_leaf_of_min_eq_none {t : rbnode α} : t.min = none → t = leaf := begin induction t, { intros, refl }, all_goals { cases t_lchild; simp [rbnode.min]; intro h, all_goals { have := t_ih_lchild h, contradiction } } end lemma eq_leaf_of_max_eq_none {t : rbnode α} : t.max = none → t = leaf := begin induction t, { intros, refl }, all_goals { cases t_rchild; simp [rbnode.max]; intro h, all_goals { have := t_ih_rchild h, contradiction } } end lemma min_is_minimal {a : α} {t : rbnode α} : ∀ {lo hi}, is_searchable lt t lo hi → t.min = some a → ∀ {b}, mem lt b t → a ≈[lt] b ∨ lt a b := begin induction t, { simp [strict_weak_order.equiv], intros _ _ hs hmin b, contradiction }, all_goals { cases t_lchild; intros lo hi hs hmin b hmem, { simp [rbnode.min] at hmin, subst t_val, simp [mem] at hmem, cases hmem with heqv hmem, { left, exact heqv.swap }, { have := lt_of_mem_right hs (by constructor) hmem, right, assumption } }, all_goals { have hs' := hs, cases hs, simp [rbnode.min] at hmin, rw [mem] at hmem, blast_disjs, { exact t_ih_lchild hs_hs₁ hmin hmem }, { have hmm := mem_of_min_eq lt hmin, have a_lt_val := lt_of_mem_left hs' (by constructor) hmm, have a_lt_b := lt_of_lt_of_incomp a_lt_val hmem.swap, right, assumption }, { have hmm := mem_of_min_eq lt hmin, have a_lt_b := lt_of_mem_left_right hs' (by constructor) hmm hmem, right, assumption } } } end lemma max_is_maximal {a : α} {t : rbnode α} : ∀ {lo hi}, is_searchable lt t lo hi → t.max = some a → ∀ {b}, mem lt b t → a ≈[lt] b ∨ lt b a := begin induction t, { simp [strict_weak_order.equiv], intros _ _ hs hmax b, contradiction }, all_goals { cases t_rchild; intros lo hi hs hmax b hmem, { simp [rbnode.max] at hmax, subst t_val, simp [mem] at hmem, cases hmem with hmem heqv, { have := lt_of_mem_left hs (by constructor) hmem, right, assumption }, { left, exact heqv.swap } }, all_goals { have hs' := hs, cases hs, simp [rbnode.max] at hmax, rw [mem] at hmem, blast_disjs, { have hmm := mem_of_max_eq lt hmax, have a_lt_b := lt_of_mem_left_right hs' (by constructor) hmem hmm, right, assumption }, { have hmm := mem_of_max_eq lt hmax, have val_lt_a := lt_of_mem_right hs' (by constructor) hmm, have a_lt_b := lt_of_incomp_of_lt hmem val_lt_a, right, assumption }, { exact t_ih_rchild hs_hs₂ hmax hmem } } } end end rbnode
b86497a0f03a962071021475426257cd0214ffef
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/test/ext.lean
5b0779fe89d77e290f2775a4208832b876bb4607
[ "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
3,736
lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import tactic.ext import tactic.solve_by_elim import data.stream.basic import data.finset.basic import tactic.rcases section ext_trace_test setup_tactic_parser namespace tactic namespace interactive meta def ext_trace_test (patts : parse (rcases_patt_parse tt)*) (fuel : parse (tk ":" *> small_nat)?) (tgt_trace : string) : tactic unit := do ⟨_, σ⟩ ← state_t.run (ext_core {}) ⟨patts, [], fuel⟩, guard $ ", ".intercalate σ.trace_msg = tgt_trace end interactive end tactic end ext_trace_test example (α β γ : Type) (f g : α × β → γ) (H : ∀ a : α, ∀ b : β, f (a,b) = g (a,b)) : f = g := begin ext_trace_test ⟨a,b⟩ "apply funext, rintro ⟨a, b⟩", apply H end example : subsingleton unit := begin split, intros, ext end example (x y : ℕ) : true := begin have : x = y, { ext <|> admit }, have : x = y, { ext i <|> admit }, have : x = y, { ext : 1 <|> admit }, trivial end example (X Y : ℕ × ℕ) (h : X.1 = Y.1) (h : X.2 = Y.2) : X = Y := begin ext; assumption end example (X Y : (ℕ → ℕ) × ℕ) (h : ∀ i, X.1 i = Y.1 i) (h : X.2 = Y.2) : X = Y := begin ext x; solve_by_elim, end example (X Y : ℕ → ℕ × ℕ) (h : ∀ i, X i = Y i) : true := begin have : X = Y, { ext i : 1, guard_target X i = Y i, admit }, have : X = Y, { ext i, guard_target (X i).fst = (Y i).fst, admit, guard_target (X i).snd = (Y i).snd, admit, }, have : X = Y, { ext : 1, guard_target X x = Y x, admit }, trivial, end example (s₀ s₁ : set ℕ) (h : s₁ = s₀) : s₀ = s₁ := by { ext1, guard_target x ∈ s₀ ↔ x ∈ s₁, simp * } example (s₀ s₁ : stream ℕ) (h : s₁ = s₀) : s₀ = s₁ := by { ext1, guard_target s₀.nth n = s₁.nth n, simp * } example (s₀ s₁ : ℤ → set (ℕ × ℕ)) (h : ∀ i a b, (a,b) ∈ s₀ i ↔ (a,b) ∈ s₁ i) : s₀ = s₁ := begin ext i ⟨a,b⟩, apply h end example (s₀ s₁ : ℤ → set (ℕ × ℕ)) (h : ∀ i a b, (a,b) ∈ s₀ i ↔ (a,b) ∈ s₁ i) : s₀ = s₁ := begin ext_trace_test i ⟨a,b⟩ "apply funext, rintro i, apply set.ext, rintro ⟨a, b⟩", apply h end /- extensionality -/ example : true := begin have : ∀ (s₀ s₁ : set ℤ), s₀ = s₁, { intros, ext1, guard_target x ∈ s₀ ↔ x ∈ s₁, admit }, have : ∀ (s₀ s₁ : finset ℕ), s₀ = s₁, { intros, ext1, guard_target a ∈ s₀ ↔ a ∈ s₁, admit }, have : ∀ (s₀ s₁ : multiset ℕ), s₀ = s₁, { intros, ext1, guard_target multiset.count a s₀ = multiset.count a s₁, admit }, have : ∀ (s₀ s₁ : list ℕ), s₀ = s₁, { intros, ext1, guard_target list.nth s₀ n = list.nth s₁ n, admit }, have : ∀ (s₀ s₁ : stream ℕ), s₀ = s₁, { intros, ext1, guard_target stream.nth n s₀ = stream.nth n s₁, admit }, have : ∀ n (s₀ s₁ : array n ℕ), s₀ = s₁, { intros, ext1, guard_target array.read s₀ i = array.read s₁ i, admit }, trivial end structure dependent_fields := (a : bool) (v : if a then ℕ else ℤ) @[ext] lemma df.ext (s t : dependent_fields) (h : s.a = t.a) (w : (@eq.rec _ s.a (λ b, if b then ℕ else ℤ) s.v t.a h) = t.v) : s = t := begin cases s, cases t, dsimp at *, congr, exact h, subst h, simp, simp at w, exact w, end example (s : dependent_fields) : s = s := begin tactic.ext1 [] {tactic.apply_cfg . new_goals := tactic.new_goals.all}, guard_target s.a = s.a, refl, refl, end @[ext] structure dumb (V : Type) := (val : V)
755f0229a01775603f67351dde7b079ac8b9b2d3
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/group_theory/perm/fin.lean
a80671f99906bac1a7c1708d875d6be9d260bcbe
[ "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
10,757
lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import group_theory.perm.cycle.type import group_theory.perm.option import logic.equiv.fin import logic.equiv.fintype /-! # Permutations of `fin n` -/ open equiv /-- Permutations of `fin (n + 1)` are equivalent to fixing a single `fin (n + 1)` and permuting the remaining with a `perm (fin n)`. The fixed `fin (n + 1)` is swapped with `0`. -/ def equiv.perm.decompose_fin {n : ℕ} : perm (fin n.succ) ≃ fin n.succ × perm (fin n) := ((equiv.perm_congr $ fin_succ_equiv n).trans equiv.perm.decompose_option).trans (equiv.prod_congr (fin_succ_equiv n).symm (equiv.refl _)) @[simp] lemma equiv.perm.decompose_fin_symm_of_refl {n : ℕ} (p : fin (n + 1)) : equiv.perm.decompose_fin.symm (p, equiv.refl _) = swap 0 p := by simp [equiv.perm.decompose_fin, equiv.perm_congr_def] @[simp] lemma equiv.perm.decompose_fin_symm_of_one {n : ℕ} (p : fin (n + 1)) : equiv.perm.decompose_fin.symm (p, 1) = swap 0 p := equiv.perm.decompose_fin_symm_of_refl p @[simp] lemma equiv.perm.decompose_fin_symm_apply_zero {n : ℕ} (p : fin (n + 1)) (e : perm (fin n)) : equiv.perm.decompose_fin.symm (p, e) 0 = p := by simp [equiv.perm.decompose_fin] @[simp] lemma equiv.perm.decompose_fin_symm_apply_succ {n : ℕ} (e : perm (fin n)) (p : fin (n + 1)) (x : fin n) : equiv.perm.decompose_fin.symm (p, e) x.succ = swap 0 p (e x).succ := begin refine fin.cases _ _ p, { simp [equiv.perm.decompose_fin, equiv_functor.map] }, { intros i, by_cases h : i = e x, { simp [h, equiv.perm.decompose_fin, equiv_functor.map] }, { have h' : some (e x) ≠ some i := λ H, h (option.some_injective _ H).symm, have h'' : (e x).succ ≠ i.succ := λ H, h (fin.succ_injective _ H).symm, simp [h, h'', fin.succ_ne_zero, equiv.perm.decompose_fin, equiv_functor.map, swap_apply_of_ne_of_ne, swap_apply_of_ne_of_ne (option.some_ne_none (e x)) h'] } } end @[simp] lemma equiv.perm.decompose_fin_symm_apply_one {n : ℕ} (e : perm (fin (n + 1))) (p : fin (n + 2)) : equiv.perm.decompose_fin.symm (p, e) 1 = swap 0 p (e 0).succ := by rw [← fin.succ_zero_eq_one, equiv.perm.decompose_fin_symm_apply_succ e p 0] @[simp] lemma equiv.perm.decompose_fin.symm_sign {n : ℕ} (p : fin (n + 1)) (e : perm (fin n)) : perm.sign (equiv.perm.decompose_fin.symm (p, e)) = ite (p = 0) 1 (-1) * perm.sign e := by { refine fin.cases _ _ p; simp [equiv.perm.decompose_fin, fin.succ_ne_zero] } /-- The set of all permutations of `fin (n + 1)` can be constructed by augmenting the set of permutations of `fin n` by each element of `fin (n + 1)` in turn. -/ lemma finset.univ_perm_fin_succ {n : ℕ} : @finset.univ (perm $ fin n.succ) _ = (finset.univ : finset $ fin n.succ × perm (fin n)).map equiv.perm.decompose_fin.symm.to_embedding := (finset.univ_map_equiv_to_embedding _).symm section cycle_range /-! ### `cycle_range` section Define the permutations `fin.cycle_range i`, the cycle `(0 1 2 ... i)`. -/ open equiv.perm lemma fin_rotate_succ {n : ℕ} : fin_rotate n.succ = decompose_fin.symm (1, fin_rotate n) := begin ext i, cases n, { simp }, refine fin.cases _ (λ i, _) i, { simp }, rw [coe_fin_rotate, decompose_fin_symm_apply_succ, if_congr (i.succ_eq_last_succ) rfl rfl], split_ifs with h, { simp [h] }, { rw [fin.coe_succ, function.injective.map_swap fin.coe_injective, fin.coe_succ, coe_fin_rotate, if_neg h, fin.coe_zero, fin.coe_one, swap_apply_of_ne_of_ne (nat.succ_ne_zero _) (nat.succ_succ_ne_one _)] } end @[simp] lemma sign_fin_rotate (n : ℕ) : perm.sign (fin_rotate (n + 1)) = (-1) ^ n := begin induction n with n ih, { simp }, { rw fin_rotate_succ, simp [ih, pow_succ] }, end @[simp] lemma support_fin_rotate {n : ℕ} : support (fin_rotate (n + 2)) = finset.univ := by { ext, simp } lemma support_fin_rotate_of_le {n : ℕ} (h : 2 ≤ n) : support (fin_rotate n) = finset.univ := begin obtain ⟨m, rfl⟩ := exists_add_of_le h, rw [add_comm, support_fin_rotate], end lemma is_cycle_fin_rotate {n : ℕ} : is_cycle (fin_rotate (n + 2)) := begin refine ⟨0, dec_trivial, λ x hx', ⟨x, _⟩⟩, clear hx', cases x with x hx, rw [coe_coe, zpow_coe_nat, fin.ext_iff, fin.coe_mk], induction x with x ih, { refl }, rw [pow_succ, perm.mul_apply, coe_fin_rotate_of_ne_last, ih (lt_trans x.lt_succ_self hx)], rw [ne.def, fin.ext_iff, ih (lt_trans x.lt_succ_self hx), fin.coe_last], exact ne_of_lt (nat.lt_of_succ_lt_succ hx), end lemma is_cycle_fin_rotate_of_le {n : ℕ} (h : 2 ≤ n) : is_cycle (fin_rotate n) := begin obtain ⟨m, rfl⟩ := exists_add_of_le h, rw [add_comm], exact is_cycle_fin_rotate end @[simp] lemma cycle_type_fin_rotate {n : ℕ} : cycle_type (fin_rotate (n + 2)) = {n + 2} := begin rw [is_cycle_fin_rotate.cycle_type, support_fin_rotate, ← fintype.card, fintype.card_fin], refl, end lemma cycle_type_fin_rotate_of_le {n : ℕ} (h : 2 ≤ n) : cycle_type (fin_rotate n) = {n} := begin obtain ⟨m, rfl⟩ := exists_add_of_le h, rw [add_comm, cycle_type_fin_rotate] end namespace fin /-- `fin.cycle_range i` is the cycle `(0 1 2 ... i)` leaving `(i+1 ... (n-1))` unchanged. -/ def cycle_range {n : ℕ} (i : fin n) : perm (fin n) := (fin_rotate (i + 1)) .extend_domain (equiv.of_left_inverse' (fin.cast_le (nat.succ_le_of_lt i.is_lt)).to_embedding coe (by { intros x, ext, simp })) lemma cycle_range_of_gt {n : ℕ} {i j : fin n.succ} (h : i < j) : cycle_range i j = j := begin rw [cycle_range, of_left_inverse'_eq_of_injective, ←function.embedding.to_equiv_range_eq_of_injective, ←via_fintype_embedding, via_fintype_embedding_apply_not_mem_range], simpa end lemma cycle_range_of_le {n : ℕ} {i j : fin n.succ} (h : j ≤ i) : cycle_range i j = if j = i then 0 else j + 1 := begin cases n, { simp }, have : j = (fin.cast_le (nat.succ_le_of_lt i.is_lt)).to_embedding ⟨j, lt_of_le_of_lt h (nat.lt_succ_self i)⟩, { simp }, ext, rw [this, cycle_range, of_left_inverse'_eq_of_injective, ←function.embedding.to_equiv_range_eq_of_injective, ←via_fintype_embedding, via_fintype_embedding_apply_image, rel_embedding.coe_fn_to_embedding, coe_cast_le, coe_fin_rotate], simp only [fin.ext_iff, coe_last, coe_mk, coe_zero, fin.eta, apply_ite coe, cast_le_mk], split_ifs with heq, { refl }, { rw fin.coe_add_one_of_lt, exact lt_of_lt_of_le (lt_of_le_of_ne h (mt (congr_arg coe) heq)) (le_last i) } end lemma coe_cycle_range_of_le {n : ℕ} {i j : fin n.succ} (h : j ≤ i) : (cycle_range i j : ℕ) = if j = i then 0 else j + 1 := by { rw [cycle_range_of_le h], split_ifs with h', { refl }, exact coe_add_one_of_lt (calc (j : ℕ) < i : fin.lt_iff_coe_lt_coe.mp (lt_of_le_of_ne h h') ... ≤ n : nat.lt_succ_iff.mp i.2) } lemma cycle_range_of_lt {n : ℕ} {i j : fin n.succ} (h : j < i) : cycle_range i j = j + 1 := by rw [cycle_range_of_le h.le, if_neg h.ne] lemma coe_cycle_range_of_lt {n : ℕ} {i j : fin n.succ} (h : j < i) : (cycle_range i j : ℕ) = j + 1 := by rw [coe_cycle_range_of_le h.le, if_neg h.ne] lemma cycle_range_of_eq {n : ℕ} {i j : fin n.succ} (h : j = i) : cycle_range i j = 0 := by rw [cycle_range_of_le h.le, if_pos h] @[simp] lemma cycle_range_self {n : ℕ} (i : fin n.succ) : cycle_range i i = 0 := cycle_range_of_eq rfl lemma cycle_range_apply {n : ℕ} (i j : fin n.succ) : cycle_range i j = if j < i then j + 1 else if j = i then 0 else j := begin split_ifs with h₁ h₂, { exact cycle_range_of_lt h₁ }, { exact cycle_range_of_eq h₂ }, { exact cycle_range_of_gt (lt_of_le_of_ne (le_of_not_gt h₁) (ne.symm h₂)) }, end @[simp] lemma cycle_range_zero (n : ℕ) : cycle_range (0 : fin n.succ) = 1 := begin ext j, refine fin.cases _ (λ j, _) j, { simp }, { rw [cycle_range_of_gt (fin.succ_pos j), one_apply] }, end @[simp] lemma cycle_range_last (n : ℕ) : cycle_range (last n) = fin_rotate (n + 1) := by { ext i, rw [coe_cycle_range_of_le (le_last _), coe_fin_rotate] } @[simp] lemma cycle_range_zero' {n : ℕ} (h : 0 < n) : cycle_range ⟨0, h⟩ = 1 := begin cases n with n, { cases h }, exact cycle_range_zero n end @[simp] lemma sign_cycle_range {n : ℕ} (i : fin n) : perm.sign (cycle_range i) = (-1) ^ (i : ℕ) := by simp [cycle_range] @[simp] lemma succ_above_cycle_range {n : ℕ} (i j : fin n) : i.succ.succ_above (i.cycle_range j) = swap 0 i.succ j.succ := begin cases n, { rcases j with ⟨_, ⟨⟩⟩ }, rcases lt_trichotomy j i with hlt | heq | hgt, { have : (j + 1).cast_succ = j.succ, { ext, rw [coe_cast_succ, coe_succ, fin.coe_add_one_of_lt (lt_of_lt_of_le hlt i.le_last)] }, rw [fin.cycle_range_of_lt hlt, fin.succ_above_below, this, swap_apply_of_ne_of_ne], { apply fin.succ_ne_zero }, { exact (fin.succ_injective _).ne hlt.ne }, { rw fin.lt_iff_coe_lt_coe, simpa [this] using hlt } }, { rw [heq, fin.cycle_range_self, fin.succ_above_below, swap_apply_right, fin.cast_succ_zero], { rw fin.cast_succ_zero, apply fin.succ_pos } }, { rw [fin.cycle_range_of_gt hgt, fin.succ_above_above, swap_apply_of_ne_of_ne], { apply fin.succ_ne_zero }, { apply (fin.succ_injective _).ne hgt.ne.symm }, { simpa [fin.le_iff_coe_le_coe] using hgt } }, end @[simp] lemma cycle_range_succ_above {n : ℕ} (i : fin (n + 1)) (j : fin n) : i.cycle_range (i.succ_above j) = j.succ := begin cases lt_or_ge j.cast_succ i with h h, { rw [fin.succ_above_below _ _ h, fin.cycle_range_of_lt h, fin.coe_succ_eq_succ] }, { rw [fin.succ_above_above _ _ h, fin.cycle_range_of_gt (fin.le_cast_succ_iff.mp h)] } end @[simp] lemma cycle_range_symm_zero {n : ℕ} (i : fin (n + 1)) : i.cycle_range.symm 0 = i := i.cycle_range.injective (by simp) @[simp] lemma cycle_range_symm_succ {n : ℕ} (i : fin (n + 1)) (j : fin n) : i.cycle_range.symm j.succ = i.succ_above j := i.cycle_range.injective (by simp) lemma is_cycle_cycle_range {n : ℕ} {i : fin (n + 1)} (h0 : i ≠ 0) : is_cycle (cycle_range i) := begin cases i with i hi, cases i, { exact (h0 rfl).elim }, exact is_cycle_fin_rotate.extend_domain _, end @[simp] lemma cycle_type_cycle_range {n : ℕ} {i : fin (n + 1)} (h0 : i ≠ 0) : cycle_type (cycle_range i) = {i + 1} := begin cases i with i hi, cases i, { exact (h0 rfl).elim }, rw [cycle_range, cycle_type_extend_domain], exact cycle_type_fin_rotate, end lemma is_three_cycle_cycle_range_two {n : ℕ} : is_three_cycle (cycle_range 2 : perm (fin (n + 3))) := begin rw [is_three_cycle, cycle_type_cycle_range]; dec_trivial end end fin end cycle_range
2d279565d0878f51c7442cf879d7a78a47fbf194
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/category_theory/enriched/basic.lean
d7cd99921aebb62ed449496a7d85bcef7359c80f
[ "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,239
lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import category_theory.monoidal.types import category_theory.monoidal.center import tactic.apply_fun /-! # Enriched categories We set up the basic theory of `V`-enriched categories, for `V` an arbitrary monoidal category. We do not assume here that `V` is a concrete category, so there does not need to be a "honest" underlying category! Use `X ⟶[V] Y` to obtain the `V` object of morphisms from `X` to `Y`. This file contains the definitions of `V`-enriched categories and `V`-functors. We don't yet define the `V`-object of natural transformations between a pair of `V`-functors (this requires limits in `V`), but we do provide a presheaf isomorphic to the Yoneda embedding of this object. We verify that when `V = Type v`, all these notion reduce to the usual ones. -/ universes w v u₁ u₂ u₃ noncomputable theory namespace category_theory open opposite open monoidal_category variables (V : Type v) [category.{w} V] [monoidal_category V] /-- A `V`-category is a category enriched in a monoidal category `V`. Note that we do not assume that `V` is a concrete category, so there may not be an "honest" underlying category at all! -/ class enriched_category (C : Type u₁) := (hom : C → C → V) (notation X ` ⟶[] ` Y:10 := hom X Y) (id : Π X, 𝟙_ V ⟶ (X ⟶[] X)) (comp : Π X Y Z, (X ⟶[] Y) ⊗ (Y ⟶[] Z) ⟶ (X ⟶[] Z)) (id_comp : Π X Y, (λ_ (X ⟶[] Y)).inv ≫ (id X ⊗ 𝟙 _) ≫ comp X X Y = 𝟙 _ . obviously) (comp_id : Π X Y, (ρ_ (X ⟶[] Y)).inv ≫ (𝟙 _ ⊗ id Y) ≫ comp X Y Y = 𝟙 _ . obviously) (assoc : Π W X Y Z, (α_ _ _ _).inv ≫ (comp W X Y ⊗ 𝟙 _) ≫ comp W Y Z = (𝟙 _ ⊗ comp X Y Z) ≫ comp W X Z . obviously) notation (name := enriched_category.hom) X ` ⟶[`V`] ` Y:10 := (enriched_category.hom X Y : V) variables (V) {C : Type u₁} [enriched_category V C] /-- The `𝟙_ V`-shaped generalized element giving the identity in a `V`-enriched category. -/ def e_id (X : C) : 𝟙_ V ⟶ (X ⟶[V] X) := enriched_category.id X /-- The composition `V`-morphism for a `V`-enriched category. -/ def e_comp (X Y Z : C) : (X ⟶[V] Y) ⊗ (Y ⟶[V] Z) ⟶ (X ⟶[V] Z) := enriched_category.comp X Y Z -- We don't just use `restate_axiom` here; that would leave `V` as an implicit argument. @[simp, reassoc] lemma e_id_comp (X Y : C) : (λ_ (X ⟶[V] Y)).inv ≫ (e_id V X ⊗ 𝟙 _) ≫ e_comp V X X Y = 𝟙 (X ⟶[V] Y) := enriched_category.id_comp X Y @[simp, reassoc] lemma e_comp_id (X Y : C) : (ρ_ (X ⟶[V] Y)).inv ≫ (𝟙 _ ⊗ e_id V Y) ≫ e_comp V X Y Y = 𝟙 (X ⟶[V] Y) := enriched_category.comp_id X Y @[simp, reassoc] lemma e_assoc (W X Y Z : C) : (α_ _ _ _).inv ≫ (e_comp V W X Y ⊗ 𝟙 _) ≫ e_comp V W Y Z = (𝟙 _ ⊗ e_comp V X Y Z) ≫ e_comp V W X Z := enriched_category.assoc W X Y Z section variables {V} {W : Type v} [category.{w} W] [monoidal_category W] /-- A type synonym for `C`, which should come equipped with a `V`-enriched category structure. In a moment we will equip this with the `W`-enriched category structure obtained by applying the functor `F : lax_monoidal_functor V W` to each hom object. -/ @[nolint has_nonempty_instance unused_arguments] def transport_enrichment (F : lax_monoidal_functor V W) (C : Type u₁) := C instance (F : lax_monoidal_functor V W) : enriched_category W (transport_enrichment F C) := { hom := λ (X Y : C), F.obj (X ⟶[V] Y), id := λ (X : C), F.ε ≫ F.map (e_id V X), comp := λ (X Y Z : C), F.μ _ _ ≫ F.map (e_comp V X Y Z), id_comp := λ X Y, begin rw [comp_tensor_id, category.assoc, ←F.to_functor.map_id, F.μ_natural_assoc, F.to_functor.map_id, F.left_unitality_inv_assoc, ←F.to_functor.map_comp, ←F.to_functor.map_comp, e_id_comp, F.to_functor.map_id], end, comp_id := λ X Y, begin rw [id_tensor_comp, category.assoc, ←F.to_functor.map_id, F.μ_natural_assoc, F.to_functor.map_id, F.right_unitality_inv_assoc, ←F.to_functor.map_comp, ←F.to_functor.map_comp, e_comp_id, F.to_functor.map_id], end, assoc := λ P Q R S, begin rw [comp_tensor_id, category.assoc, ←F.to_functor.map_id, F.μ_natural_assoc, F.to_functor.map_id, ←F.associativity_inv_assoc, ←F.to_functor.map_comp, ←F.to_functor.map_comp, e_assoc, id_tensor_comp, category.assoc, ←F.to_functor.map_id, F.μ_natural_assoc, F.to_functor.map_comp], end, } end /-- Construct an honest category from a `Type v`-enriched category. -/ def category_of_enriched_category_Type (C : Type u₁) [𝒞 : enriched_category (Type v) C] : category.{v} C := { hom := 𝒞.hom, id := λ X, e_id (Type v) X punit.star, comp := λ X Y Z f g, e_comp (Type v) X Y Z ⟨f, g⟩, id_comp' := λ X Y f, congr_fun (e_id_comp (Type v) X Y) f, comp_id' := λ X Y f, congr_fun (e_comp_id (Type v) X Y) f, assoc' := λ W X Y Z f g h, (congr_fun (e_assoc (Type v) W X Y Z) ⟨f, g, h⟩ : _), } /-- Construct a `Type v`-enriched category from an honest category. -/ def enriched_category_Type_of_category (C : Type u₁) [𝒞 : category.{v} C] : enriched_category (Type v) C := { hom := 𝒞.hom, id := λ X p, 𝟙 X, comp := λ X Y Z p, p.1 ≫ p.2, id_comp := λ X Y, by { ext, simp, }, comp_id := λ X Y, by { ext, simp, }, assoc := λ W X Y Z, by { ext ⟨f, g, h⟩, simp, }, } /-- We verify that an enriched category in `Type u` is just the same thing as an honest category. -/ def enriched_category_Type_equiv_category (C : Type u₁) : (enriched_category (Type v) C) ≃ category.{v} C := { to_fun := λ 𝒞, by exactI category_of_enriched_category_Type C, inv_fun := λ 𝒞, by exactI enriched_category_Type_of_category C, left_inv := λ 𝒞, begin cases 𝒞, dsimp [enriched_category_Type_of_category], congr, { ext X ⟨⟩, refl, }, { ext X Y Z ⟨f, g⟩, refl, } end, right_inv := λ 𝒞, by { rcases 𝒞 with @⟨@⟨⟨⟩⟩⟩, dsimp, congr, }, }. section variables {W : Type (v+1)} [category.{v} W] [monoidal_category W] [enriched_category W C] /-- A type synonym for `C`, which should come equipped with a `V`-enriched category structure. In a moment we will equip this with the (honest) category structure so that `X ⟶ Y` is `(𝟙_ W) ⟶ (X ⟶[W] Y)`. We obtain this category by transporting the enrichment in `V` along the lax monoidal functor `coyoneda_tensor_unit`, then using the equivalence of `Type`-enriched categories with honest categories. This is sometimes called the "underlying" category of an enriched category, although some care is needed as the functor `coyoneda_tensor_unit`, which always exists, does not necessarily coincide with "the forgetful functor" from `V` to `Type`, if such exists. When `V` is any of `Type`, `Top`, `AddCommGroup`, or `Module R`, `coyoneda_tensor_unit` is just the usual forgetful functor, however. For `V = Algebra R`, the usual forgetful functor is coyoneda of `R[X]`, not of `R`. (Perhaps we should have a typeclass for this situation: `concrete_monoidal`?) -/ @[nolint has_nonempty_instance unused_arguments] def forget_enrichment (W : Type (v+1)) [category.{v} W] [monoidal_category W] (C : Type u₁) [enriched_category W C] := C variables (W) /-- Typecheck an object of `C` as an object of `forget_enrichment W C`. -/ def forget_enrichment.of (X : C) : forget_enrichment W C := X /-- Typecheck an object of `forget_enrichment W C` as an object of `C`. -/ def forget_enrichment.to (X : forget_enrichment W C) : C := X @[simp] lemma forget_enrichment.to_of (X : C) : forget_enrichment.to W (forget_enrichment.of W X) = X := rfl @[simp] lemma forget_enrichment.of_to (X : forget_enrichment W C) : forget_enrichment.of W (forget_enrichment.to W X) = X := rfl instance category_forget_enrichment : category (forget_enrichment W C) := begin let I : enriched_category (Type v) (transport_enrichment (coyoneda_tensor_unit W) C) := infer_instance, exact enriched_category_Type_equiv_category C I, end /-- We verify that the morphism types in `forget_enrichment W C` are `(𝟙_ W) ⟶ (X ⟶[W] Y)`. -/ example (X Y : forget_enrichment W C) : (X ⟶ Y) = ((𝟙_ W) ⟶ (forget_enrichment.to W X ⟶[W] forget_enrichment.to W Y)) := rfl /-- Typecheck a `(𝟙_ W)`-shaped `W`-morphism as a morphism in `forget_enrichment W C`. -/ def forget_enrichment.hom_of {X Y : C} (f : (𝟙_ W) ⟶ (X ⟶[W] Y)) : forget_enrichment.of W X ⟶ forget_enrichment.of W Y := f /-- Typecheck a morphism in `forget_enrichment W C` as a `(𝟙_ W)`-shaped `W`-morphism. -/ def forget_enrichment.hom_to {X Y : forget_enrichment W C} (f : X ⟶ Y) : (𝟙_ W) ⟶ (forget_enrichment.to W X ⟶[W] forget_enrichment.to W Y) := f @[simp] lemma forget_enrichment.hom_to_hom_of {X Y : C} (f : (𝟙_ W) ⟶ (X ⟶[W] Y)) : forget_enrichment.hom_to W (forget_enrichment.hom_of W f) = f := rfl @[simp] lemma forget_enrichment.hom_of_hom_to {X Y : forget_enrichment W C} (f : X ⟶ Y) : forget_enrichment.hom_of W (forget_enrichment.hom_to W f) = f := rfl /-- The identity in the "underlying" category of an enriched category. -/ @[simp] lemma forget_enrichment_id (X : forget_enrichment W C) : forget_enrichment.hom_to W (𝟙 X) = (e_id W (forget_enrichment.to W X : C)) := category.id_comp _ @[simp] lemma forget_enrichment_id' (X : C) : forget_enrichment.hom_of W (e_id W X) = (𝟙 (forget_enrichment.of W X : C)) := (forget_enrichment_id W (forget_enrichment.of W X)).symm /-- Composition in the "underlying" category of an enriched category. -/ @[simp] lemma forget_enrichment_comp {X Y Z : forget_enrichment W C} (f : X ⟶ Y) (g : Y ⟶ Z) : forget_enrichment.hom_to W (f ≫ g) = (((λ_ (𝟙_ W)).inv ≫ (forget_enrichment.hom_to W f ⊗ forget_enrichment.hom_to W g)) ≫ e_comp W _ _ _) := rfl end /-- A `V`-functor `F` between `V`-enriched categories has a `V`-morphism from `X ⟶[V] Y` to `F.obj X ⟶[V] F.obj Y`, satisfying the usual axioms. -/ structure enriched_functor (C : Type u₁) [enriched_category V C] (D : Type u₂) [enriched_category V D] := (obj : C → D) (map : Π X Y : C, (X ⟶[V] Y) ⟶ (obj X ⟶[V] obj Y)) (map_id' : ∀ X : C, e_id V X ≫ map X X = e_id V (obj X) . obviously) (map_comp' : ∀ X Y Z : C, e_comp V X Y Z ≫ map X Z = (map X Y ⊗ map Y Z) ≫ e_comp V (obj X) (obj Y) (obj Z) . obviously) restate_axiom enriched_functor.map_id' restate_axiom enriched_functor.map_comp' attribute [simp, reassoc] enriched_functor.map_id attribute [simp, reassoc] enriched_functor.map_comp /-- The identity enriched functor. -/ @[simps] def enriched_functor.id (C : Type u₁) [enriched_category V C] : enriched_functor V C C := { obj := λ X, X, map := λ X Y, 𝟙 _, } instance : inhabited (enriched_functor V C C) := ⟨enriched_functor.id V C⟩ /-- Composition of enriched functors. -/ @[simps] def enriched_functor.comp {C : Type u₁} {D : Type u₂} {E : Type u₃} [enriched_category V C] [enriched_category V D] [enriched_category V E] (F : enriched_functor V C D) (G : enriched_functor V D E) : enriched_functor V C E := { obj := λ X, G.obj (F.obj X), map := λ X Y, F.map _ _ ≫ G.map _ _, } section variables {W : Type (v+1)} [category.{v} W] [monoidal_category W] /-- An enriched functor induces an honest functor of the underlying categories, by mapping the `(𝟙_ W)`-shaped morphisms. -/ def enriched_functor.forget {C : Type u₁} {D : Type u₂} [enriched_category W C] [enriched_category W D] (F : enriched_functor W C D) : (forget_enrichment W C) ⥤ (forget_enrichment W D) := { obj := λ X, forget_enrichment.of W (F.obj (forget_enrichment.to W X)), map := λ X Y f, forget_enrichment.hom_of W (forget_enrichment.hom_to W f ≫ F.map (forget_enrichment.to W X) (forget_enrichment.to W Y)), map_comp' := λ X Y Z f g, begin dsimp, apply_fun forget_enrichment.hom_to W, { simp only [iso.cancel_iso_inv_left, category.assoc, tensor_comp, forget_enrichment.hom_to_hom_of, enriched_functor.map_comp, forget_enrichment_comp], refl, }, { intros f g w, apply_fun forget_enrichment.hom_of W at w, simpa using w, }, end, } end section variables {V} variables {D : Type u₂} [enriched_category V D] /-! We now turn to natural transformations between `V`-functors. The mostly commonly encountered definition of an enriched natural transformation is a collection of morphisms ``` (𝟙_ W) ⟶ (F.obj X ⟶[V] G.obj X) ``` satisfying an appropriate analogue of the naturality square. (c.f. https://ncatlab.org/nlab/show/enriched+natural+transformation) This is the same thing as a natural transformation `F.forget ⟶ G.forget`. We formalize this as `enriched_nat_trans F G`, which is a `Type`. However, there's also something much nicer: with appropriate additional hypotheses, there is a `V`-object `enriched_nat_trans_obj F G` which contains more information, and from which one can recover `enriched_nat_trans F G ≃ (𝟙_ V) ⟶ enriched_nat_trans_obj F G`. Using these as the hom-objects, we can build a `V`-enriched category with objects the `V`-functors. For `enriched_nat_trans_obj` to exist, it suffices to have `V` braided and complete. Before assuming `V` is complete, we assume it is braided and define a presheaf `enriched_nat_trans_yoneda F G` which is isomorphic to the Yoneda embedding of `enriched_nat_trans_obj F G` whether or not that object actually exists. This presheaf has components `(enriched_nat_trans_yoneda F G).obj A` what we call the `A`-graded enriched natural transformations, which are collections of morphisms ``` A ⟶ (F.obj X ⟶[V] G.obj X) ``` satisfying a similar analogue of the naturality square, this time incorporating a half-braiding on `A`. (We actually define `enriched_nat_trans F G` as the special case `A := 𝟙_ V` with the trivial half-braiding, and when defining `enriched_nat_trans_yoneda F G` we use the half-braidings coming from the ambient braiding on `V`.) -/ /-- The type of `A`-graded natural transformations between `V`-functors `F` and `G`. This is the type of morphisms in `V` from `A` to the `V`-object of natural transformations. -/ @[ext, nolint has_nonempty_instance] structure graded_nat_trans (A : center V) (F G : enriched_functor V C D) := (app : Π (X : C), A.1 ⟶ (F.obj X ⟶[V] G.obj X)) (naturality : ∀ (X Y : C), (A.2.β (X ⟶[V] Y)).hom ≫ (F.map X Y ⊗ app Y) ≫ e_comp V _ _ _ = (app X ⊗ G.map X Y) ≫ e_comp V _ _ _) variables [braided_category V] open braided_category /-- A presheaf isomorphic to the Yoneda embedding of the `V`-object of natural transformations from `F` to `G`. -/ @[simps] def enriched_nat_trans_yoneda (F G : enriched_functor V C D) : Vᵒᵖ ⥤ (Type (max u₁ w)) := { obj := λ A, graded_nat_trans ((center.of_braided V).obj (unop A)) F G, map := λ A A' f σ, { app := λ X, f.unop ≫ σ.app X, naturality := λ X Y, begin have p := σ.naturality X Y, dsimp at p ⊢, rw [←id_tensor_comp_tensor_id (f.unop ≫ σ.app Y) _, id_tensor_comp, category.assoc, category.assoc, ←braiding_naturality_assoc, id_tensor_comp_tensor_id_assoc, p, ←tensor_comp_assoc,category.id_comp], end }, } -- TODO assuming `[has_limits C]` construct the actual object of natural transformations -- and show that the functor category is `V`-enriched. end section local attribute [instance] category_of_enriched_category_Type /-- We verify that an enriched functor between `Type v` enriched categories is just the same thing as an honest functor. -/ @[simps] def enriched_functor_Type_equiv_functor {C : Type u₁} [𝒞 : enriched_category (Type v) C] {D : Type u₂} [𝒟 : enriched_category (Type v) D] : enriched_functor (Type v) C D ≃ (C ⥤ D) := { to_fun := λ F, { obj := λ X, F.obj X, map := λ X Y f, F.map X Y f, map_id' := λ X, congr_fun (F.map_id X) punit.star, map_comp' := λ X Y Z f g, congr_fun (F.map_comp X Y Z) ⟨f, g⟩, }, inv_fun := λ F, { obj := λ X, F.obj X, map := λ X Y f, F.map f, map_id' := λ X, by { ext ⟨⟩, exact F.map_id X, }, map_comp' := λ X Y Z, by { ext ⟨f, g⟩, exact F.map_comp f g, }, }, left_inv := λ F, by { cases F, simp, }, right_inv := λ F, by { cases F, simp, }, } /-- We verify that the presheaf representing natural transformations between `Type v`-enriched functors is actually represented by the usual type of natural transformations! -/ def enriched_nat_trans_yoneda_Type_iso_yoneda_nat_trans {C : Type v} [enriched_category (Type v) C] {D : Type v} [enriched_category (Type v) D] (F G : enriched_functor (Type v) C D) : enriched_nat_trans_yoneda F G ≅ yoneda.obj ((enriched_functor_Type_equiv_functor F) ⟶ (enriched_functor_Type_equiv_functor G)) := nat_iso.of_components (λ α, { hom := λ σ x, { app := λ X, σ.app X x, naturality' := λ X Y f, congr_fun (σ.naturality X Y) ⟨x, f⟩, }, inv := λ σ, { app := λ X x, (σ x).app X, naturality := λ X Y, by { ext ⟨x, f⟩, exact ((σ x).naturality f), }, }}) (by tidy) end end category_theory
3deff4216cf00dde1f3cb8839e4d92b40010ae4d
f083c4ed5d443659f3ed9b43b1ca5bb037ddeb58
/analysis/topology/uniform_space.lean
6fd88f0b6852b2ce98040183f9ea3feb44361efb
[ "Apache-2.0" ]
permissive
semorrison/mathlib
1be6f11086e0d24180fec4b9696d3ec58b439d10
20b4143976dad48e664c4847b75a85237dca0a89
refs/heads/master
1,583,799,212,170
1,535,634,130,000
1,535,730,505,000
129,076,205
0
0
Apache-2.0
1,551,697,998,000
1,523,442,265,000
Lean
UTF-8
Lean
false
false
83,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, Mario Carneiro, Patrick Massot Theory of uniform spaces. Uniform spaces are a generalization of metric spaces and topological groups. Many concepts directly generalize to uniform spaces, e.g. * completeness * completion (on Cauchy filters instead of Cauchy sequences) * extension of uniform continuous functions to complete spaces * uniform contiunuity & embedding * totally bounded * totally bounded ∧ complete → compact One reason to directly formalize uniform spaces is foundational: we define ℝ as a completion of ℚ. The central concept of uniform spaces is its uniformity: a filter relating two elements of the space. This filter is reflexive, symmetric and transitive. So a set (i.e. a relation) in this filter represents a 'distance': it is reflexive, symmetric and the uniformity contains a set for which the `triangular` rule holds. The formalization is mostly based on the books: N. Bourbaki: General Topology I. M. James: Topologies and Uniformities A major difference is that this formalization is heavily based on the filter library. -/ import order.filter data.quot analysis.topology.topological_space analysis.topology.continuity open set lattice filter classical local attribute [instance] prop_decidable set_option eqn_compiler.zeta true universes u section variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {ι : Sort*} /-- The identity relation, or the graph of the identity function -/ def id_rel {α : Type*} := {p : α × α | p.1 = p.2} @[simp] theorem mem_id_rel {a b : α} : (a, b) ∈ @id_rel α ↔ a = b := iff.rfl @[simp] theorem id_rel_subset {s : set (α × α)} : id_rel ⊆ s ↔ ∀ a, (a, a) ∈ s := by simp [subset_def]; exact forall_congr (λ a, by simp) /-- The composition of relations -/ def comp_rel {α : Type u} (r₁ r₂ : set (α×α)) := {p : α × α | ∃z:α, (p.1, z) ∈ r₁ ∧ (z, p.2) ∈ r₂} @[simp] theorem mem_comp_rel {r₁ r₂ : set (α×α)} {x y : α} : (x, y) ∈ comp_rel r₁ r₂ ↔ ∃ z, (x, z) ∈ r₁ ∧ (z, y) ∈ r₂ := iff.rfl @[simp] theorem swap_id_rel : prod.swap '' id_rel = @id_rel α := set.ext $ assume ⟨a, b⟩, by simp [image_swap_eq_preimage_swap]; exact eq_comm theorem monotone_comp_rel [preorder β] {f g : β → set (α×α)} (hf : monotone f) (hg : monotone g) : monotone (λx, comp_rel (f x) (g x)) := assume a b h p ⟨z, h₁, h₂⟩, ⟨z, hf h h₁, hg h h₂⟩ lemma prod_mk_mem_comp_rel {a b c : α} {s t : set (α×α)} (h₁ : (a, c) ∈ s) (h₂ : (c, b) ∈ t) : (a, b) ∈ comp_rel s t := ⟨c, h₁, h₂⟩ @[simp] lemma id_comp_rel {r : set (α×α)} : comp_rel id_rel r = r := set.ext $ assume ⟨a, b⟩, by simp lemma comp_rel_assoc {r s t : set (α×α)} : comp_rel (comp_rel r s) t = comp_rel r (comp_rel s t) := by ext p; cases p; simp only [mem_comp_rel]; tauto /-- This core description of a uniform space is outside of the type class hierarchy. It is useful for constructions of uniform spaces, when the topology is derived from the uniform space. -/ structure uniform_space.core (α : Type u) := (uniformity : filter (α × α)) (refl : principal id_rel ≤ uniformity) (symm : tendsto prod.swap uniformity uniformity) (comp : uniformity.lift' (λs, comp_rel s s) ≤ uniformity) def uniform_space.core.mk' {α : Type u} (U : filter (α × α)) (refl : ∀ (r ∈ U.sets) x, (x, x) ∈ r) (symm : ∀ r ∈ U.sets, {p | prod.swap p ∈ r} ∈ U.sets) (comp : ∀ r ∈ U.sets, ∃ t ∈ U.sets, comp_rel t t ⊆ r) : uniform_space.core α := ⟨U, λ r ru, id_rel_subset.2 (refl _ ru), symm, begin intros r ru, rw [mem_lift'_sets], exact comp _ ru, apply monotone_comp_rel; exact monotone_id, end⟩ /-- A uniform space generates a topological space -/ def uniform_space.core.to_topological_space {α : Type u} (u : uniform_space.core α) : topological_space α := { is_open := λs, ∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ u.uniformity.sets, is_open_univ := by simp; intro; exact univ_mem_sets, is_open_inter := assume s t hs ht x ⟨xs, xt⟩, by filter_upwards [hs x xs, ht x xt]; simp {contextual := tt}, is_open_sUnion := assume s hs x ⟨t, ts, xt⟩, by filter_upwards [hs t ts x xt] assume p ph h, ⟨t, ts, ph h⟩ } lemma uniform_space.core_eq : ∀{u₁ u₂ : uniform_space.core α}, u₁.uniformity = u₂.uniformity → u₁ = u₂ | ⟨u₁, _, _, _⟩ ⟨u₂, _, _, _⟩ h := have u₁ = u₂, from h, by simp [*] /-- A uniform space is a generalization of the "uniform" topological aspects of a metric space. It consists of a filter on `α × α` called the "uniformity", which satisfies properties analogous to the reflexivity, symmetry, and triangle properties of a metric. A metric space has a natural uniformity, and a uniform space has a natural topology. A topological group also has a natural uniformity, even when it is not metrizable. -/ class uniform_space (α : Type u) extends topological_space α, uniform_space.core α := (is_open_uniformity : ∀s, is_open s ↔ (∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ uniformity.sets)) @[pattern] def uniform_space.mk' {α} (t : topological_space α) (c : uniform_space.core α) (is_open_uniformity : ∀s:set α, t.is_open s ↔ (∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ c.uniformity.sets)) : uniform_space α := ⟨c, is_open_uniformity⟩ def uniform_space.of_core {α : Type u} (u : uniform_space.core α) : uniform_space α := { to_core := u, to_topological_space := u.to_topological_space, is_open_uniformity := assume a, iff.refl _ } def uniform_space.of_core_eq {α : Type u} (u : uniform_space.core α) (t : topological_space α) (h : t = u.to_topological_space) : uniform_space α := { to_core := u, to_topological_space := t, is_open_uniformity := assume a, h.symm ▸ iff.refl _ } lemma uniform_space.to_core_to_topological_space (u : uniform_space α) : u.to_core.to_topological_space = u.to_topological_space := topological_space_eq $ funext $ assume s, by rw [uniform_space.core.to_topological_space, uniform_space.is_open_uniformity] lemma uniform_space_eq : ∀{u₁ u₂ : uniform_space α}, u₁.uniformity = u₂.uniformity → u₁ = u₂ | (uniform_space.mk' t₁ u₁ o₁) (uniform_space.mk' t₂ u₂ o₂) h := have u₁ = u₂, from uniform_space.core_eq h, have t₁ = t₂, from topological_space_eq $ funext $ assume s, by rw [o₁, o₂]; simp [this], by simp [*] lemma uniform_space.of_core_eq_to_core (u : uniform_space α) (t : topological_space α) (h : t = u.to_core.to_topological_space) : uniform_space.of_core_eq u.to_core t h = u := uniform_space_eq rfl section uniform_space variables [uniform_space α] /-- The uniformity is a filter on α × α (inferred from an ambient uniform space structure on α). -/ def uniformity : filter (α × α) := (@uniform_space.to_core α _).uniformity lemma is_open_uniformity {s : set α} : is_open s ↔ (∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ (@uniformity α _).sets) := uniform_space.is_open_uniformity s lemma refl_le_uniformity : principal id_rel ≤ @uniformity α _ := (@uniform_space.to_core α _).refl lemma refl_mem_uniformity {x : α} {s : set (α × α)} (h : s ∈ (@uniformity α _).sets) : (x, x) ∈ s := refl_le_uniformity h rfl lemma symm_le_uniformity : map (@prod.swap α α) uniformity ≤ uniformity := (@uniform_space.to_core α _).symm lemma comp_le_uniformity : uniformity.lift' (λs:set (α×α), comp_rel s s) ≤ uniformity := (@uniform_space.to_core α _).comp lemma tendsto_swap_uniformity : tendsto prod.swap (@uniformity α _) uniformity := symm_le_uniformity lemma tendsto_const_uniformity {a : α} {f : filter β} : tendsto (λ_, (a, a)) f uniformity := assume s hs, show {x | (a, a) ∈ s} ∈ f.sets, from univ_mem_sets' $ assume b, refl_mem_uniformity hs lemma comp_mem_uniformity_sets {s : set (α × α)} (hs : s ∈ (@uniformity α _).sets) : ∃t∈(@uniformity α _).sets, comp_rel t t ⊆ s := have s ∈ (uniformity.lift' (λt:set (α×α), comp_rel t t)).sets, from comp_le_uniformity hs, (mem_lift'_sets $ monotone_comp_rel monotone_id monotone_id).mp this lemma symm_of_uniformity {s : set (α × α)} (hs : s ∈ (@uniformity α _).sets) : ∃t∈(@uniformity α _).sets, (∀a b, (a, b) ∈ t → (b, a) ∈ t) ∧ t ⊆ s := have preimage prod.swap s ∈ (@uniformity α _).sets, from symm_le_uniformity hs, ⟨s ∩ preimage prod.swap s, inter_mem_sets hs this, assume a b ⟨h₁, h₂⟩, ⟨h₂, h₁⟩, inter_subset_left _ _⟩ lemma comp_symm_of_uniformity {s : set (α × α)} (hs : s ∈ (@uniformity α _).sets) : ∃t∈(@uniformity α _).sets, (∀{a b}, (a, b) ∈ t → (b, a) ∈ t) ∧ comp_rel t t ⊆ s := let ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs in let ⟨t', ht', ht'₁, ht'₂⟩ := symm_of_uniformity ht₁ in ⟨t', ht', ht'₁, subset.trans (monotone_comp_rel monotone_id monotone_id ht'₂) ht₂⟩ lemma uniformity_le_symm : uniformity ≤ (@prod.swap α α) <$> uniformity := by rw [map_swap_eq_vmap_swap]; from map_le_iff_le_vmap.1 tendsto_swap_uniformity lemma uniformity_eq_symm : uniformity = (@prod.swap α α) <$> uniformity := le_antisymm uniformity_le_symm symm_le_uniformity theorem uniformity_lift_le_swap {g : set (α×α) → filter β} {f : filter β} (hg : monotone g) (h : uniformity.lift (λs, g (preimage prod.swap s)) ≤ f) : uniformity.lift g ≤ f := calc uniformity.lift g ≤ (filter.map prod.swap (@uniformity α _)).lift g : lift_mono uniformity_le_symm (le_refl _) ... ≤ _ : by rw [map_lift_eq2 hg, image_swap_eq_preimage_swap]; exact h lemma uniformity_lift_le_comp {f : set (α×α) → filter β} (h : monotone f): uniformity.lift (λs, f (comp_rel s s)) ≤ uniformity.lift f := calc uniformity.lift (λs, f (comp_rel s s)) = (uniformity.lift' (λs:set (α×α), comp_rel s s)).lift f : begin rw [lift_lift'_assoc], exact monotone_comp_rel monotone_id monotone_id, exact h end ... ≤ uniformity.lift f : lift_mono comp_le_uniformity (le_refl _) lemma comp_le_uniformity3 : uniformity.lift' (λs:set (α×α), comp_rel s (comp_rel s s)) ≤ uniformity := calc uniformity.lift' (λd, comp_rel d (comp_rel d d)) = uniformity.lift (λs, uniformity.lift' (λt:set(α×α), comp_rel s (comp_rel t t))) : begin rw [lift_lift'_same_eq_lift'], exact (assume x, monotone_comp_rel monotone_const $ monotone_comp_rel monotone_id monotone_id), exact (assume x, monotone_comp_rel monotone_id monotone_const), end ... ≤ uniformity.lift (λs, uniformity.lift' (λt:set(α×α), comp_rel s t)) : lift_mono' $ assume s hs, @uniformity_lift_le_comp α _ _ (principal ∘ comp_rel s) $ monotone_comp (monotone_comp_rel monotone_const monotone_id) monotone_principal ... = uniformity.lift' (λs:set(α×α), comp_rel s s) : lift_lift'_same_eq_lift' (assume s, monotone_comp_rel monotone_const monotone_id) (assume s, monotone_comp_rel monotone_id monotone_const) ... ≤ uniformity : comp_le_uniformity lemma mem_nhds_uniformity_iff {x : α} {s : set α} : (s ∈ (nhds x).sets) ↔ ({p : α × α | p.1 = x → p.2 ∈ s} ∈ (@uniformity α _).sets) := ⟨ begin simp [mem_nhds_sets_iff, is_open_uniformity], exact assume t ts ht xt, by filter_upwards [ht x xt] assume ⟨x', y⟩ h eq, ts $ h eq end, assume hs, mem_nhds_sets_iff.mpr ⟨{x | {p : α × α | p.1 = x → p.2 ∈ s} ∈ (@uniformity α _).sets}, assume x' hx', refl_mem_uniformity hx' rfl, is_open_uniformity.mpr $ assume x' hx', let ⟨t, ht, tr⟩ := comp_mem_uniformity_sets hx' in by filter_upwards [ht] assume ⟨a, b⟩ hp' (hax' : a = x'), by filter_upwards [ht] assume ⟨a, b'⟩ hp'' (hab : a = b), have hp : (x', b) ∈ t, from hax' ▸ hp', have (b, b') ∈ t, from hab ▸ hp'', have (x', b') ∈ comp_rel t t, from ⟨b, hp, this⟩, show b' ∈ s, from tr this rfl, hs⟩⟩ lemma nhds_eq_vmap_uniformity {x : α} : nhds x = uniformity.vmap (prod.mk x) := by ext s; rw [mem_nhds_uniformity_iff, mem_vmap_sets]; from iff.intro (assume hs, ⟨_, hs, assume x hx, hx rfl⟩) (assume ⟨t, h, ht⟩, uniformity.sets_of_superset h $ assume ⟨p₁, p₂⟩ hp (h : p₁ = x), ht $ by simp [h.symm, hp]) lemma nhds_eq_uniformity {x : α} : nhds x = uniformity.lift' (λs:set (α×α), {y | (x, y) ∈ s}) := begin ext s, rw [mem_lift'_sets], tactic.swap, apply monotone_preimage, simp [mem_nhds_uniformity_iff], exact ⟨assume h, ⟨_, h, assume y h, h rfl⟩, assume ⟨t, h₁, h₂⟩, uniformity.sets_of_superset h₁ $ assume ⟨x', y⟩ hp (eq : x' = x), h₂ $ show (x, y) ∈ t, from eq ▸ hp⟩ end lemma mem_nhds_left (x : α) {s : set (α×α)} (h : s ∈ (uniformity.sets : set (set (α×α)))) : {y : α | (x, y) ∈ s} ∈ (nhds x).sets := have nhds x ≤ principal {y : α | (x, y) ∈ s}, by rw [nhds_eq_uniformity]; exact infi_le_of_le s (infi_le _ h), by simp at this; assumption lemma mem_nhds_right (y : α) {s : set (α×α)} (h : s ∈ (uniformity.sets : set (set (α×α)))) : {x : α | (x, y) ∈ s} ∈ (nhds y).sets := mem_nhds_left _ (symm_le_uniformity h) lemma tendsto_right_nhds_uniformity {a : α} : tendsto (λa', (a', a)) (nhds a) uniformity := assume s, mem_nhds_right a lemma tendsto_left_nhds_uniformity {a : α} : tendsto (λa', (a, a')) (nhds a) uniformity := assume s, mem_nhds_left a lemma lift_nhds_left {x : α} {g : set α → filter β} (hg : monotone g) : (nhds x).lift g = uniformity.lift (λs:set (α×α), g {y | (x, y) ∈ s}) := eq.trans begin rw [nhds_eq_uniformity], exact (filter.lift_assoc $ monotone_comp monotone_preimage $ monotone_comp monotone_preimage monotone_principal) end (congr_arg _ $ funext $ assume s, filter.lift_principal hg) lemma lift_nhds_right {x : α} {g : set α → filter β} (hg : monotone g) : (nhds x).lift g = uniformity.lift (λs:set (α×α), g {y | (y, x) ∈ s}) := calc (nhds x).lift g = uniformity.lift (λs:set (α×α), g {y | (x, y) ∈ s}) : lift_nhds_left hg ... = ((@prod.swap α α) <$> uniformity).lift (λs:set (α×α), g {y | (x, y) ∈ s}) : by rw [←uniformity_eq_symm] ... = uniformity.lift (λs:set (α×α), g {y | (x, y) ∈ image prod.swap s}) : map_lift_eq2 $ monotone_comp monotone_preimage hg ... = _ : by simp [image_swap_eq_preimage_swap] lemma nhds_nhds_eq_uniformity_uniformity_prod {a b : α} : filter.prod (nhds a) (nhds b) = uniformity.lift (λs:set (α×α), uniformity.lift' (λt:set (α×α), set.prod {y : α | (y, a) ∈ s} {y : α | (b, y) ∈ t})) := begin rw [prod_def], show (nhds a).lift (λs:set α, (nhds b).lift (λt:set α, principal (set.prod s t))) = _, rw [lift_nhds_right], apply congr_arg, funext s, rw [lift_nhds_left], refl, exact monotone_comp (monotone_prod monotone_const monotone_id) monotone_principal, exact (monotone_lift' monotone_const $ monotone_lam $ assume x, monotone_prod monotone_id monotone_const) end lemma nhds_eq_uniformity_prod {a b : α} : nhds (a, b) = uniformity.lift' (λs:set (α×α), set.prod {y : α | (y, a) ∈ s} {y : α | (b, y) ∈ s}) := begin rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'], { intro s, exact monotone_prod monotone_const monotone_preimage }, { intro t, exact monotone_prod monotone_preimage monotone_const } end lemma nhdset_of_mem_uniformity {d : set (α×α)} (s : set (α×α)) (hd : d ∈ (@uniformity α _).sets) : ∃(t : set (α×α)), is_open t ∧ s ⊆ t ∧ t ⊆ {p | ∃x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d} := let cl_d := {p:α×α | ∃x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d} in have ∀p ∈ s, ∃t ⊆ cl_d, is_open t ∧ p ∈ t, from assume ⟨x, y⟩ hp, mem_nhds_sets_iff.mp $ show cl_d ∈ (nhds (x, y)).sets, begin rw [nhds_eq_uniformity_prod, mem_lift'_sets], exact ⟨d, hd, assume ⟨a, b⟩ ⟨ha, hb⟩, ⟨x, y, ha, hp, hb⟩⟩, exact monotone_prod monotone_preimage monotone_preimage end, have ∃t:(Π(p:α×α) (h:p ∈ s), set (α×α)), ∀p, ∀h:p ∈ s, t p h ⊆ cl_d ∧ is_open (t p h) ∧ p ∈ t p h, by simp [classical.skolem] at this; simp; assumption, match this with | ⟨t, ht⟩ := ⟨(⋃ p:α×α, ⋃ h : p ∈ s, t p h : set (α×α)), is_open_Union $ assume (p:α×α), is_open_Union $ assume hp, (ht p hp).right.left, assume ⟨a, b⟩ hp, begin simp; exact ⟨a, b, hp, (ht (a,b) hp).right.right⟩ end, Union_subset $ assume p, Union_subset $ assume hp, (ht p hp).left⟩ end lemma closure_eq_inter_uniformity {t : set (α×α)} : closure t = (⋂ d∈(@uniformity α _).sets, comp_rel d (comp_rel t d)) := set.ext $ assume ⟨a, b⟩, calc (a, b) ∈ closure t ↔ (nhds (a, b) ⊓ principal t ≠ ⊥) : by simp [closure_eq_nhds] ... ↔ (((@prod.swap α α) <$> uniformity).lift' (λ (s : set (α × α)), set.prod {x : α | (x, a) ∈ s} {y : α | (b, y) ∈ s}) ⊓ principal t ≠ ⊥) : by rw [←uniformity_eq_symm, nhds_eq_uniformity_prod] ... ↔ ((map (@prod.swap α α) uniformity).lift' (λ (s : set (α × α)), set.prod {x : α | (x, a) ∈ s} {y : α | (b, y) ∈ s}) ⊓ principal t ≠ ⊥) : by refl ... ↔ (uniformity.lift' (λ (s : set (α × α)), set.prod {y : α | (a, y) ∈ s} {x : α | (x, b) ∈ s}) ⊓ principal t ≠ ⊥) : begin rw [map_lift'_eq2], simp [image_swap_eq_preimage_swap, function.comp], exact monotone_prod monotone_preimage monotone_preimage end ... ↔ (∀s∈(@uniformity α _).sets, ∃x, x ∈ set.prod {y : α | (a, y) ∈ s} {x : α | (x, b) ∈ s} ∩ t) : begin rw [lift'_inf_principal_eq, lift'_neq_bot_iff], apply forall_congr, intro s, rw [ne_empty_iff_exists_mem], exact monotone_inter (monotone_prod monotone_preimage monotone_preimage) monotone_const end ... ↔ (∀s∈(@uniformity α _).sets, (a, b) ∈ comp_rel s (comp_rel t s)) : forall_congr $ assume s, forall_congr $ assume hs, ⟨assume ⟨⟨x, y⟩, ⟨⟨hx, hy⟩, hxyt⟩⟩, ⟨x, hx, y, hxyt, hy⟩, assume ⟨x, hx, y, hxyt, hy⟩, ⟨⟨x, y⟩, ⟨⟨hx, hy⟩, hxyt⟩⟩⟩ ... ↔ _ : by simp lemma uniformity_eq_uniformity_closure : (@uniformity α _) = uniformity.lift' closure := le_antisymm (le_infi $ assume s, le_infi $ assume hs, by simp; filter_upwards [hs] subset_closure) (calc uniformity.lift' closure ≤ uniformity.lift' (λd, comp_rel d (comp_rel d d)) : lift'_mono' (by intros s hs; rw [closure_eq_inter_uniformity]; exact bInter_subset_of_mem hs) ... ≤ uniformity : comp_le_uniformity3) lemma uniformity_eq_uniformity_interior : (@uniformity α _) = uniformity.lift' interior := le_antisymm (le_infi $ assume d, le_infi $ assume hd, let ⟨s, hs, hs_comp⟩ := (mem_lift'_sets $ monotone_comp_rel monotone_id $ monotone_comp_rel monotone_id monotone_id).mp (comp_le_uniformity3 hd) in let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs in have s ⊆ interior d, from calc s ⊆ t : hst ... ⊆ interior d : (subset_interior_iff_subset_of_open ht).mpr $ assume x, assume : x ∈ t, let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp this in hs_comp ⟨x, h₁, y, h₂, h₃⟩, have interior d ∈ (@uniformity α _).sets, by filter_upwards [hs] this, by simp [this]) (assume s hs, (uniformity.lift' interior).sets_of_superset (mem_lift' hs) interior_subset) lemma interior_mem_uniformity {s : set (α × α)} (hs : s ∈ (@uniformity α _).sets) : interior s ∈ (@uniformity α _).sets := by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs lemma mem_uniformity_is_closed [uniform_space α] {s : set (α×α)} (h : s ∈ (@uniformity α _).sets) : ∃t∈(@uniformity α _).sets, is_closed t ∧ t ⊆ s := have s ∈ ((@uniformity α _).lift' closure).sets, by rwa [uniformity_eq_uniformity_closure] at h, have ∃t∈(@uniformity α _).sets, closure t ⊆ s, by rwa [mem_lift'_sets] at this; apply closure_mono, let ⟨t, ht, hst⟩ := this in ⟨closure t, uniformity.sets_of_superset ht subset_closure, is_closed_closure, hst⟩ /- uniform continuity -/ def uniform_continuous [uniform_space β] (f : α → β) := tendsto (λx:α×α, (f x.1, f x.2)) uniformity uniformity theorem uniform_continuous_def [uniform_space β] {f : α → β} : uniform_continuous f ↔ ∀ r ∈ (@uniformity β _).sets, {x : α × α | (f x.1, f x.2) ∈ r} ∈ (@uniformity α _).sets := iff.rfl lemma uniform_continuous_id : uniform_continuous (@id α) := by simp [uniform_continuous]; exact tendsto_id lemma uniform_continuous_const [uniform_space β] {b : β} : uniform_continuous (λa:α, b) := @tendsto_const_uniformity _ _ _ b uniformity lemma uniform_continuous.comp [uniform_space β] [uniform_space γ] {f : α → β} {g : β → γ} (hf : uniform_continuous f) (hg : uniform_continuous g) : uniform_continuous (g ∘ f) := hf.comp hg def uniform_embedding [uniform_space β] (f : α → β) := function.injective f ∧ vmap (λx:α×α, (f x.1, f x.2)) uniformity = uniformity theorem uniform_embedding_def [uniform_space β] {f : α → β} : uniform_embedding f ↔ function.injective f ∧ ∀ s, s ∈ (@uniformity α _).sets ↔ ∃ t ∈ (@uniformity β _).sets, ∀ x y : α, (f x, f y) ∈ t → (x, y) ∈ s := by rw [uniform_embedding, eq_comm, filter.ext_iff]; simp [subset_def] theorem uniform_embedding_def' [uniform_space β] {f : α → β} : uniform_embedding f ↔ function.injective f ∧ uniform_continuous f ∧ ∀ s, s ∈ (@uniformity α _).sets → ∃ t ∈ (@uniformity β _).sets, ∀ x y : α, (f x, f y) ∈ t → (x, y) ∈ s := by simp [uniform_embedding_def, uniform_continuous_def]; exact ⟨λ ⟨I, H⟩, ⟨I, λ s su, (H _).2 ⟨s, su, λ x y, id⟩, λ s, (H s).1⟩, λ ⟨I, H₁, H₂⟩, ⟨I, λ s, ⟨H₂ s, λ ⟨t, tu, h⟩, sets_of_superset _ (H₁ t tu) (λ ⟨a, b⟩, h a b)⟩⟩⟩ lemma uniform_embedding.uniform_continuous [uniform_space β] {f : α → β} (hf : uniform_embedding f) : uniform_continuous f := (uniform_embedding_def'.1 hf).2.1 lemma uniform_embedding.uniform_continuous_iff [uniform_space β] [uniform_space γ] {f : α → β} {g : β → γ} (hg : uniform_embedding g) : uniform_continuous f ↔ uniform_continuous (g ∘ f) := by simp [uniform_continuous, tendsto]; rw [← hg.2, ← map_le_iff_le_vmap, filter.map_map] lemma uniform_embedding.dense_embedding [uniform_space β] {f : α → β} (h : uniform_embedding f) (hd : ∀x, x ∈ closure (range f)) : dense_embedding f := { dense := hd, inj := h.left, induced := begin intro a, simp [h.right.symm, nhds_eq_uniformity], rw [vmap_lift'_eq, vmap_lift'_eq2], refl, exact monotone_preimage, exact monotone_preimage end } lemma uniform_continuous.continuous [uniform_space β] {f : α → β} (hf : uniform_continuous f) : continuous f := continuous_iff_tendsto.mpr $ assume a, calc map f (nhds a) ≤ (map (λp:α×α, (f p.1, f p.2)) uniformity).lift' (λs:set (β×β), {y | (f a, y) ∈ s}) : begin rw [nhds_eq_uniformity, map_lift'_eq, map_lift'_eq2], exact (lift'_mono' $ assume s hs b ⟨a', (ha' : (_, a') ∈ s), a'_eq⟩, ⟨(a, a'), ha', show (f a, f a') = (f a, b), from a'_eq ▸ rfl⟩), exact monotone_preimage, exact monotone_preimage end ... ≤ nhds (f a) : by rw [nhds_eq_uniformity]; exact lift'_mono hf (le_refl _) lemma closure_image_mem_nhds_of_uniform_embedding [uniform_space α] [uniform_space β] {s : set (α×α)} {e : α → β} (b : β) (he₁ : uniform_embedding e) (he₂ : dense_embedding e) (hs : s ∈ (@uniformity α _).sets) : ∃a, closure (e '' {a' | (a, a') ∈ s}) ∈ (nhds b).sets := have s ∈ (vmap (λp:α×α, (e p.1, e p.2)) $ uniformity).sets, from he₁.right.symm ▸ hs, let ⟨t₁, ht₁u, ht₁⟩ := this in have ht₁ : ∀p:α×α, (e p.1, e p.2) ∈ t₁ → p ∈ s, from ht₁, let ⟨t₂, ht₂u, ht₂s, ht₂c⟩ := comp_symm_of_uniformity ht₁u in let ⟨t, htu, hts, htc⟩ := comp_symm_of_uniformity ht₂u in have preimage e {b' | (b, b') ∈ t₂} ∈ (vmap e $ nhds b).sets, from preimage_mem_vmap $ mem_nhds_left b ht₂u, let ⟨a, (ha : (b, e a) ∈ t₂)⟩ := inhabited_of_mem_sets (he₂.vmap_nhds_neq_bot) this in have ∀b' (s' : set (β × β)), (b, b') ∈ t → s' ∈ (@uniformity β _).sets → {y : β | (b', y) ∈ s'} ∩ e '' {a' : α | (a, a') ∈ s} ≠ ∅, from assume b' s' hb' hs', have preimage e {b'' | (b', b'') ∈ s' ∩ t} ∈ (vmap e $ nhds b').sets, from preimage_mem_vmap $ mem_nhds_left b' $ inter_mem_sets hs' htu, let ⟨a₂, ha₂s', ha₂t⟩ := inhabited_of_mem_sets (he₂.vmap_nhds_neq_bot) this in have (e a, e a₂) ∈ t₁, from ht₂c $ prod_mk_mem_comp_rel (ht₂s ha) $ htc $ prod_mk_mem_comp_rel hb' ha₂t, have e a₂ ∈ {b'':β | (b', b'') ∈ s'} ∩ e '' {a' | (a, a') ∈ s}, from ⟨ha₂s', mem_image_of_mem _ $ ht₁ (a, a₂) this⟩, ne_empty_of_mem this, have ∀b', (b, b') ∈ t → nhds b' ⊓ principal (e '' {a' | (a, a') ∈ s}) ≠ ⊥, begin intros b' hb', rw [nhds_eq_uniformity, lift'_inf_principal_eq, lift'_neq_bot_iff], exact assume s, this b' s hb', exact monotone_inter monotone_preimage monotone_const end, have ∀b', (b, b') ∈ t → b' ∈ closure (e '' {a' | (a, a') ∈ s}), from assume b' hb', by rw [closure_eq_nhds]; exact this b' hb', ⟨a, (nhds b).sets_of_superset (mem_nhds_left b htu) this⟩ /-- A filter `f` is Cauchy if for every entourage `r`, there exists an `s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy sequences, because if `a : ℕ → α` then the filter of sets containing cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/ def cauchy (f : filter α) := f ≠ ⊥ ∧ filter.prod f f ≤ uniformity lemma cauchy_iff [uniform_space α] {f : filter α} : cauchy f ↔ (f ≠ ⊥ ∧ (∀s∈(@uniformity α _).sets, ∃t∈f.sets, set.prod t t ⊆ s)) := and_congr (iff.refl _) $ forall_congr $ assume s, forall_congr $ assume hs, mem_prod_same_iff lemma cauchy_downwards {f g : filter α} (h_c : cauchy f) (hg : g ≠ ⊥) (h_le : g ≤ f) : cauchy g := ⟨hg, le_trans (filter.prod_mono h_le h_le) h_c.right⟩ lemma cauchy_nhds {a : α} : cauchy (nhds a) := ⟨nhds_neq_bot, calc filter.prod (nhds a) (nhds a) = uniformity.lift (λs:set (α×α), uniformity.lift' (λt:set(α×α), set.prod {y : α | (y, a) ∈ s} {y : α | (a, y) ∈ t})) : nhds_nhds_eq_uniformity_uniformity_prod ... ≤ uniformity.lift' (λs:set (α×α), comp_rel s s) : le_infi $ assume s, le_infi $ assume hs, infi_le_of_le s $ infi_le_of_le hs $ infi_le_of_le s $ infi_le_of_le hs $ principal_mono.mpr $ assume ⟨x, y⟩ ⟨(hx : (x, a) ∈ s), (hy : (a, y) ∈ s)⟩, ⟨a, hx, hy⟩ ... ≤ uniformity : comp_le_uniformity⟩ lemma cauchy_pure {a : α} : cauchy (pure a) := cauchy_downwards cauchy_nhds (show principal {a} ≠ ⊥, by simp) (pure_le_nhds a) lemma le_nhds_of_cauchy_adhp {f : filter α} {x : α} (hf : cauchy f) (adhs : f ⊓ nhds x ≠ ⊥) : f ≤ nhds x := have ∀s∈f.sets, x ∈ closure s, begin intros s hs, simp [closure_eq_nhds, inf_comm], exact assume h', adhs $ bot_unique $ h' ▸ inf_le_inf (by simp; exact hs) (le_refl _) end, calc f ≤ f.lift' (λs:set α, {y | x ∈ closure s ∧ y ∈ closure s}) : le_infi $ assume s, le_infi $ assume hs, begin rw [←forall_sets_neq_empty_iff_neq_bot] at adhs, simp [this s hs], exact mem_sets_of_superset hs subset_closure end ... ≤ f.lift' (λs:set α, {y | (x, y) ∈ closure (set.prod s s)}) : by simp [closure_prod_eq]; exact le_refl _ ... = (filter.prod f f).lift' (λs:set (α×α), {y | (x, y) ∈ closure s}) : begin rw [prod_same_eq], rw [lift'_lift'_assoc], exact monotone_prod monotone_id monotone_id, exact monotone_comp (assume s t h x h', closure_mono h h') monotone_preimage end ... ≤ uniformity.lift' (λs:set (α×α), {y | (x, y) ∈ closure s}) : lift'_mono hf.right (le_refl _) ... = (uniformity.lift' closure).lift' (λs:set (α×α), {y | (x, y) ∈ s}) : begin rw [lift'_lift'_assoc], exact assume s t h, closure_mono h, exact monotone_preimage end ... = uniformity.lift' (λs:set (α×α), {y | (x, y) ∈ s}) : by rw [←uniformity_eq_uniformity_closure] ... = nhds x : by rw [nhds_eq_uniformity] lemma le_nhds_iff_adhp_of_cauchy {f : filter α} {x : α} (hf : cauchy f) : f ≤ nhds x ↔ f ⊓ nhds x ≠ ⊥ := ⟨assume h, (inf_of_le_left h).symm ▸ hf.left, le_nhds_of_cauchy_adhp hf⟩ lemma cauchy_map [uniform_space β] {f : filter α} {m : α → β} (hm : uniform_continuous m) (hf : cauchy f) : cauchy (map m f) := ⟨have f ≠ ⊥, from hf.left, by simp; assumption, calc filter.prod (map m f) (map m f) = map (λp:α×α, (m p.1, m p.2)) (filter.prod f f) : filter.prod_map_map_eq ... ≤ map (λp:α×α, (m p.1, m p.2)) uniformity : map_mono hf.right ... ≤ uniformity : hm⟩ lemma cauchy_vmap [uniform_space β] {f : filter β} {m : α → β} (hm : vmap (λp:α×α, (m p.1, m p.2)) uniformity ≤ uniformity) (hf : cauchy f) (hb : vmap m f ≠ ⊥) : cauchy (vmap m f) := ⟨hb, calc filter.prod (vmap m f) (vmap m f) = vmap (λp:α×α, (m p.1, m p.2)) (filter.prod f f) : filter.prod_vmap_vmap_eq ... ≤ vmap (λp:α×α, (m p.1, m p.2)) uniformity : vmap_mono hf.right ... ≤ uniformity : hm⟩ /- separated uniformity -/ /-- The separation relation is the intersection of all entourages. Two points which are related by the separation relation are "indistinguishable" according to the uniform structure. -/ protected def separation_rel (α : Type u) [u : uniform_space α] := ⋂₀ (@uniformity α _).sets lemma separated_equiv : equivalence (λx y, (x, y) ∈ separation_rel α) := ⟨assume x, assume s, refl_mem_uniformity, assume x y, assume h (s : set (α×α)) hs, have preimage prod.swap s ∈ (@uniformity α _).sets, from symm_le_uniformity hs, h _ this, assume x y z (hxy : (x, y) ∈ separation_rel α) (hyz : (y, z) ∈ separation_rel α) s (hs : s ∈ (@uniformity α _).sets), let ⟨t, ht, (h_ts : comp_rel t t ⊆ s)⟩ := comp_mem_uniformity_sets hs in h_ts $ show (x, z) ∈ comp_rel t t, from ⟨y, hxy t ht, hyz t ht⟩⟩ protected def separation_setoid (α : Type u) [u : uniform_space α] : setoid α := ⟨λx y, (x, y) ∈ separation_rel α, separated_equiv⟩ @[class] def separated (α : Type u) [uniform_space α] := separation_rel α = id_rel theorem separated_def {α : Type u} [uniform_space α] : separated α ↔ ∀ x y, (∀ r ∈ (@uniformity α _).sets, (x, y) ∈ r) → x = y := by simp [separated, id_rel_subset.2 separated_equiv.1, subset.antisymm_iff]; simp [subset_def, separation_rel] theorem separated_def' {α : Type u} [uniform_space α] : separated α ↔ ∀ x y, x ≠ y → ∃ r ∈ (@uniformity α _).sets, (x, y) ∉ r := separated_def.trans $ forall_congr $ λ x, forall_congr $ λ y, by rw ← not_imp_not; simp [classical.not_forall] instance separated_t2 [s : separated α] : t2_space α := ⟨assume x y, assume h : x ≠ y, let ⟨d, hd, (hxy : (x, y) ∉ d)⟩ := separated_def'.1 s x y h in let ⟨d', hd', (hd'd' : comp_rel d' d' ⊆ d)⟩ := comp_mem_uniformity_sets hd in have {y | (x, y) ∈ d'} ∈ (nhds x).sets, from mem_nhds_left x hd', let ⟨u, hu₁, hu₂, hu₃⟩ := mem_nhds_sets_iff.mp this in have {x | (x, y) ∈ d'} ∈ (nhds y).sets, from mem_nhds_right y hd', let ⟨v, hv₁, hv₂, hv₃⟩ := mem_nhds_sets_iff.mp this in have u ∩ v = ∅, from eq_empty_of_subset_empty $ assume z ⟨(h₁ : z ∈ u), (h₂ : z ∈ v)⟩, have (x, y) ∈ comp_rel d' d', from ⟨z, hu₁ h₁, hv₁ h₂⟩, hxy $ hd'd' this, ⟨u, v, hu₂, hv₂, hu₃, hv₃, this⟩⟩ instance separated_regular [separated α] : regular_space α := { regular := λs a hs ha, have -s ∈ (nhds a).sets, from mem_nhds_sets hs ha, have {p : α × α | p.1 = a → p.2 ∈ -s} ∈ uniformity.sets, from mem_nhds_uniformity_iff.mp this, let ⟨d, hd, h⟩ := comp_mem_uniformity_sets this in let e := {y:α| (a, y) ∈ d} in have hae : a ∈ closure e, from subset_closure $ refl_mem_uniformity hd, have set.prod (closure e) (closure e) ⊆ comp_rel d (comp_rel (set.prod e e) d), begin rw [←closure_prod_eq, closure_eq_inter_uniformity], change (⨅d' ∈ uniformity.sets, _) ≤ comp_rel d (comp_rel _ d), exact (infi_le_of_le d $ infi_le_of_le hd $ le_refl _) end, have e_subset : closure e ⊆ -s, from assume a' ha', let ⟨x, (hx : (a, x) ∈ d), y, ⟨hx₁, hx₂⟩, (hy : (y, _) ∈ d)⟩ := @this ⟨a, a'⟩ ⟨hae, ha'⟩ in have (a, a') ∈ comp_rel d d, from ⟨y, hx₂, hy⟩, h this rfl, have closure e ∈ (nhds a).sets, from (nhds a).sets_of_superset (mem_nhds_left a hd) subset_closure, have nhds a ⊓ principal (-closure e) = ⊥, from (@inf_eq_bot_iff_le_compl _ _ _ (principal (- closure e)) (principal (closure e)) (by simp [principal_univ, union_comm]) (by simp)).mpr (by simp [this]), ⟨- closure e, is_closed_closure, assume x h₁ h₂, @e_subset x h₂ h₁, this⟩, ..separated_t2 } /-- A set `s` is totally bounded if for every entourage `d` there is a finite set of points `t` such that every element of `s` is `d`-near to some element of `t`. -/ def totally_bounded (s : set α) : Prop := ∀d ∈ (@uniformity α _).sets, ∃t : set α, finite t ∧ s ⊆ (⋃y∈t, {x | (x,y) ∈ d}) theorem totally_bounded_iff_subset {s : set α} : totally_bounded s ↔ ∀d ∈ (@uniformity α _).sets, ∃t ⊆ s, finite t ∧ s ⊆ (⋃y∈t, {x | (x,y) ∈ d}) := ⟨λ H d hd, begin rcases comp_symm_of_uniformity hd with ⟨r, hr, rs, rd⟩, rcases H r hr with ⟨k, fk, ks⟩, let u := {y ∈ k | ∃ x, x ∈ s ∧ (x, y) ∈ r}, let f : u → α := λ x, classical.some x.2.2, have : ∀ x : u, f x ∈ s ∧ (f x, x.1) ∈ r := λ x, classical.some_spec x.2.2, refine ⟨range f, _, _, _⟩, { exact range_subset_iff.2 (λ x, (this x).1) }, { have : finite u := finite_subset fk (λ x h, h.1), exact ⟨@set.fintype_range _ _ _ _ this.fintype⟩ }, { intros x xs, have := ks xs, simp at this, rcases this with ⟨y, hy, xy⟩, let z : coe_sort u := ⟨y, hy, x, xs, xy⟩, simp, exact ⟨_, ⟨_, z.2, rfl⟩, rd $ mem_comp_rel.2 ⟨_, xy, rs (this z).2⟩⟩ } end, λ H d hd, let ⟨t, _, ht⟩ := H d hd in ⟨t, ht⟩⟩ lemma totally_bounded_subset [uniform_space α] {s₁ s₂ : set α} (hs : s₁ ⊆ s₂) (h : totally_bounded s₂) : totally_bounded s₁ := assume d hd, let ⟨t, ht₁, ht₂⟩ := h d hd in ⟨t, ht₁, subset.trans hs ht₂⟩ lemma totally_bounded_closure [uniform_space α] {s : set α} (h : totally_bounded s) : totally_bounded (closure s) := assume t ht, let ⟨t', ht', hct', htt'⟩ := mem_uniformity_is_closed ht, ⟨c, hcf, hc⟩ := h t' ht' in ⟨c, hcf, calc closure s ⊆ closure (⋃ (y : α) (H : y ∈ c), {x : α | (x, y) ∈ t'}) : closure_mono hc ... = _ : closure_eq_of_is_closed $ is_closed_Union hcf $ assume i hi, continuous_iff_is_closed.mp (continuous_id.prod_mk continuous_const) _ hct' ... ⊆ _ : bUnion_subset $ assume i hi, subset.trans (assume x, @htt' (x, i)) (subset_bUnion_of_mem hi)⟩ lemma totally_bounded_image [uniform_space α] [uniform_space β] {f : α → β} {s : set α} (hf : uniform_continuous f) (hs : totally_bounded s) : totally_bounded (f '' s) := assume t ht, have {p:α×α | (f p.1, f p.2) ∈ t} ∈ (@uniformity α _).sets, from hf ht, let ⟨c, hfc, hct⟩ := hs _ this in ⟨f '' c, finite_image f hfc, begin simp [image_subset_iff], simp [subset_def] at hct, intros x hx, simp [-mem_image], exact let ⟨i, hi, ht⟩ := hct x hx in ⟨f i, mem_image_of_mem f hi, ht⟩ end⟩ lemma totally_bounded_preimage [uniform_space α] [uniform_space β] {f : α → β} {s : set β} (hf : uniform_embedding f) (hs : totally_bounded s) : totally_bounded (f ⁻¹' s) := λ t ht, begin rw ← hf.2 at ht, rcases mem_vmap_sets.2 ht with ⟨t', ht', ts⟩, rcases totally_bounded_iff_subset.1 (totally_bounded_subset (image_preimage_subset f s) hs) _ ht' with ⟨c, cs, hfc, hct⟩, refine ⟨f ⁻¹' c, finite_preimage hf.1 hfc, λ x h, _⟩, have := hct (mem_image_of_mem f h), simp at this ⊢, rcases this with ⟨z, zc, zt⟩, rcases cs zc with ⟨y, yc, rfl⟩, exact ⟨y, zc, ts (by exact zt)⟩ end lemma cauchy_of_totally_bounded_of_ultrafilter {s : set α} {f : filter α} (hs : totally_bounded s) (hf : ultrafilter f) (h : f ≤ principal s) : cauchy f := ⟨hf.left, assume t ht, let ⟨t', ht'₁, ht'_symm, ht'_t⟩ := comp_symm_of_uniformity ht in let ⟨i, hi, hs_union⟩ := hs t' ht'₁ in have (⋃y∈i, {x | (x,y) ∈ t'}) ∈ f.sets, from mem_sets_of_superset (le_principal_iff.mp h) hs_union, have ∃y∈i, {x | (x,y) ∈ t'} ∈ f.sets, from mem_of_finite_Union_ultrafilter hf hi this, let ⟨y, hy, hif⟩ := this in have set.prod {x | (x,y) ∈ t'} {x | (x,y) ∈ t'} ⊆ comp_rel t' t', from assume ⟨x₁, x₂⟩ ⟨(h₁ : (x₁, y) ∈ t'), (h₂ : (x₂, y) ∈ t')⟩, ⟨y, h₁, ht'_symm h₂⟩, (filter.prod f f).sets_of_superset (prod_mem_prod hif hif) (subset.trans this ht'_t)⟩ lemma totally_bounded_iff_filter {s : set α} : totally_bounded s ↔ (∀f, f ≠ ⊥ → f ≤ principal s → ∃c ≤ f, cauchy c) := ⟨assume : totally_bounded s, assume f hf hs, ⟨ultrafilter_of f, ultrafilter_of_le, cauchy_of_totally_bounded_of_ultrafilter this (ultrafilter_ultrafilter_of hf) (le_trans ultrafilter_of_le hs)⟩, assume h : ∀f, f ≠ ⊥ → f ≤ principal s → ∃c ≤ f, cauchy c, assume d hd, classical.by_contradiction $ assume hs, have hd_cover : ∀{t:set α}, finite t → ¬ s ⊆ (⋃y∈t, {x | (x,y) ∈ d}), by simpa using hs, let f := ⨅t:{t : set α // finite t}, principal (s \ (⋃y∈t.val, {x | (x,y) ∈ d})), ⟨a, ha⟩ := @exists_mem_of_ne_empty α s (assume h, hd_cover finite_empty $ h.symm ▸ empty_subset _) in have f ≠ ⊥, from infi_neq_bot_of_directed ⟨a⟩ (assume ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩, ⟨⟨t₁ ∪ t₂, finite_union ht₁ ht₂⟩, principal_mono.mpr $ diff_subset_diff_right $ Union_subset_Union $ assume t, Union_subset_Union_const or.inl, principal_mono.mpr $ diff_subset_diff_right $ Union_subset_Union $ assume t, Union_subset_Union_const or.inr⟩) (assume ⟨t, ht⟩, by simp [diff_eq_empty]; exact hd_cover ht), have f ≤ principal s, from infi_le_of_le ⟨∅, finite_empty⟩ $ by simp; exact subset.refl s, let ⟨c, (hc₁ : c ≤ f), (hc₂ : cauchy c)⟩ := h f ‹f ≠ ⊥› this, ⟨m, hm, (hmd : set.prod m m ⊆ d)⟩ := (@mem_prod_same_iff α c d).mp $ hc₂.right hd in have c ≤ principal s, from le_trans ‹c ≤ f› this, have m ∩ s ∈ c.sets, from inter_mem_sets hm $ le_principal_iff.mp this, let ⟨y, hym, hys⟩ := inhabited_of_mem_sets hc₂.left this in let ys := (⋃y'∈({y}:set α), {x | (x, y') ∈ d}) in have m ⊆ ys, from assume y' hy', show y' ∈ (⋃y'∈({y}:set α), {x | (x, y') ∈ d}), by simp; exact @hmd (y', y) ⟨hy', hym⟩, have c ≤ principal (s - ys), from le_trans hc₁ $ infi_le_of_le ⟨{y}, finite_singleton _⟩ $ le_refl _, have (s - ys) ∩ (m ∩ s) ∈ c.sets, from inter_mem_sets (le_principal_iff.mp this) ‹m ∩ s ∈ c.sets›, have ∅ ∈ c.sets, from c.sets_of_superset this $ assume x ⟨⟨hxs, hxys⟩, hxm, _⟩, hxys $ ‹m ⊆ ys› hxm, hc₂.left $ empty_in_sets_eq_bot.mp this⟩ lemma totally_bounded_iff_ultrafilter {s : set α} : totally_bounded s ↔ (∀f, ultrafilter f → f ≤ principal s → cauchy f) := ⟨assume hs f, cauchy_of_totally_bounded_of_ultrafilter hs, assume h, totally_bounded_iff_filter.mpr $ assume f hf hfs, have cauchy (ultrafilter_of f), from h (ultrafilter_of f) (ultrafilter_ultrafilter_of hf) (le_trans ultrafilter_of_le hfs), ⟨ultrafilter_of f, ultrafilter_of_le, this⟩⟩ lemma compact_of_totally_bounded_complete {s : set α} (ht : totally_bounded s) (hc : ∀{f:filter α}, cauchy f → f ≤ principal s → ∃x∈s, f ≤ nhds x) : compact s := begin rw [compact_iff_ultrafilter_le_nhds], rw [totally_bounded_iff_ultrafilter] at ht, exact assume f hf hfs, hc (ht _ hf hfs) hfs end /-- A complete space is defined here using uniformities. A uniform space is complete if every Cauchy filter converges. -/ class complete_space (α : Type u) [uniform_space α] : Prop := (complete : ∀{f:filter α}, cauchy f → ∃x, f ≤ nhds x) theorem le_nhds_lim_of_cauchy {α} [uniform_space α] [complete_space α] [inhabited α] {f : filter α} (hf : cauchy f) : f ≤ nhds (lim f) := lim_spec (complete_space.complete hf) lemma complete_of_is_closed [complete_space α] {s : set α} {f : filter α} (h : is_closed s) (hf : cauchy f) (hfs : f ≤ principal s) : ∃x∈s, f ≤ nhds x := let ⟨x, hx⟩ := complete_space.complete hf in have x ∈ s, from is_closed_iff_nhds.mp h x $ neq_bot_of_le_neq_bot hf.left $ le_inf hx hfs, ⟨x, this, hx⟩ lemma compact_of_totally_bounded_is_closed [complete_space α] {s : set α} (ht : totally_bounded s) (hc : is_closed s) : compact s := @compact_of_totally_bounded_complete α _ s ht $ assume f, complete_of_is_closed hc lemma complete_space_extension [uniform_space β] {m : β → α} (hm : uniform_embedding m) (dense : ∀x, x ∈ closure (range m)) (h : ∀f:filter β, cauchy f → ∃x:α, map m f ≤ nhds x) : complete_space α := ⟨assume (f : filter α), assume hf : cauchy f, let p : set (α × α) → set α → set α := λs t, {y : α| ∃x:α, x ∈ t ∧ (x, y) ∈ s}, g := uniformity.lift (λs, f.lift' (p s)) in have mp₀ : monotone p, from assume a b h t s ⟨x, xs, xa⟩, ⟨x, xs, h xa⟩, have mp₁ : ∀{s}, monotone (p s), from assume s a b h x ⟨y, ya, yxs⟩, ⟨y, h ya, yxs⟩, have f ≤ g, from le_infi $ assume s, le_infi $ assume hs, le_infi $ assume t, le_infi $ assume ht, le_principal_iff.mpr $ mem_sets_of_superset ht $ assume x hx, ⟨x, hx, refl_mem_uniformity hs⟩, have g ≠ ⊥, from neq_bot_of_le_neq_bot hf.left this, have vmap m g ≠ ⊥, from vmap_neq_bot $ assume t ht, let ⟨t', ht', ht_mem⟩ := (mem_lift_sets $ monotone_lift' monotone_const mp₀).mp ht in let ⟨t'', ht'', ht'_sub⟩ := (mem_lift'_sets mp₁).mp ht_mem in let ⟨x, (hx : x ∈ t'')⟩ := inhabited_of_mem_sets hf.left ht'' in have h₀ : nhds x ⊓ principal (range m) ≠ ⊥, by simp [closure_eq_nhds] at dense; exact dense x, have h₁ : {y | (x, y) ∈ t'} ∈ (nhds x ⊓ principal (range m)).sets, from @mem_inf_sets_of_left α (nhds x) (principal (range m)) _ $ mem_nhds_left x ht', have h₂ : range m ∈ (nhds x ⊓ principal (range m)).sets, from @mem_inf_sets_of_right α (nhds x) (principal (range m)) _ $ subset.refl _, have {y | (x, y) ∈ t'} ∩ range m ∈ (nhds x ⊓ principal (range m)).sets, from @inter_mem_sets α (nhds x ⊓ principal (range m)) _ _ h₁ h₂, let ⟨y, xyt', b, b_eq⟩ := inhabited_of_mem_sets h₀ this in ⟨b, b_eq.symm ▸ ht'_sub ⟨x, hx, xyt'⟩⟩, have cauchy g, from ⟨‹g ≠ ⊥›, assume s hs, let ⟨s₁, hs₁, (comp_s₁ : comp_rel s₁ s₁ ⊆ s)⟩ := comp_mem_uniformity_sets hs, ⟨s₂, hs₂, (comp_s₂ : comp_rel s₂ s₂ ⊆ s₁)⟩ := comp_mem_uniformity_sets hs₁, ⟨t, ht, (prod_t : set.prod t t ⊆ s₂)⟩ := mem_prod_same_iff.mp (hf.right hs₂) in have hg₁ : p (preimage prod.swap s₁) t ∈ g.sets, from mem_lift (symm_le_uniformity hs₁) $ @mem_lift' α α f _ t ht, have hg₂ : p s₂ t ∈ g.sets, from mem_lift hs₂ $ @mem_lift' α α f _ t ht, have hg : set.prod (p (preimage prod.swap s₁) t) (p s₂ t) ∈ (filter.prod g g).sets, from @prod_mem_prod α α _ _ g g hg₁ hg₂, (filter.prod g g).sets_of_superset hg (assume ⟨a, b⟩ ⟨⟨c₁, c₁t, hc₁⟩, ⟨c₂, c₂t, hc₂⟩⟩, have (c₁, c₂) ∈ set.prod t t, from ⟨c₁t, c₂t⟩, comp_s₁ $ prod_mk_mem_comp_rel hc₁ $ comp_s₂ $ prod_mk_mem_comp_rel (prod_t this) hc₂)⟩, have cauchy (filter.vmap m g), from cauchy_vmap (le_of_eq hm.right) ‹cauchy g› (by assumption), let ⟨x, (hx : map m (filter.vmap m g) ≤ nhds x)⟩ := h _ this in have map m (filter.vmap m g) ⊓ nhds x ≠ ⊥, from (le_nhds_iff_adhp_of_cauchy (cauchy_map hm.uniform_continuous this)).mp hx, have g ⊓ nhds x ≠ ⊥, from neq_bot_of_le_neq_bot this (inf_le_inf (assume s hs, ⟨s, hs, subset.refl _⟩) (le_refl _)), ⟨x, calc f ≤ g : by assumption ... ≤ nhds x : le_nhds_of_cauchy_adhp ‹cauchy g› this⟩⟩ /- separation space -/ section separation_space local attribute [instance] separation_setoid instance {α : Type u} [u : uniform_space α] : uniform_space (quotient (separation_setoid α)) := { to_topological_space := u.to_topological_space.coinduced (λx, ⟦x⟧), uniformity := map (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)) uniformity, refl := assume s hs ⟨a, b⟩ (h : a = b), have ∀a:α, (a, a) ∈ preimage (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧)) s, from assume a, refl_mem_uniformity hs, h ▸ quotient.induction_on a this, symm := tendsto_map' $ by simp [prod.swap, (∘)]; exact tendsto_swap_uniformity.comp tendsto_map, comp := calc (map (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧)) uniformity).lift' (λs, comp_rel s s) = uniformity.lift' ((λs, comp_rel s s) ∘ image (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧))) : map_lift'_eq2 $ monotone_comp_rel monotone_id monotone_id ... ≤ uniformity.lift' (image (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧)) ∘ (λs:set (α×α), comp_rel s (comp_rel s s))) : lift'_mono' $ assume s hs ⟨a, b⟩ ⟨c, ⟨⟨a₁, a₂⟩, ha, a_eq⟩, ⟨⟨b₁, b₂⟩, hb, b_eq⟩⟩, begin simp at a_eq, simp at b_eq, have h : ⟦a₂⟧ = ⟦b₁⟧, { rw [a_eq.right, b_eq.left] }, have h : (a₂, b₁) ∈ separation_rel α := quotient.exact h, simp [function.comp, set.image, comp_rel, and.comm, and.left_comm, and.assoc], exact ⟨a₁, a_eq.left, b₂, b_eq.right, a₂, ha, b₁, h s hs, hb⟩ end ... = map (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)) (uniformity.lift' (λs:set (α×α), comp_rel s (comp_rel s s))) : by rw [map_lift'_eq]; exact monotone_comp_rel monotone_id (monotone_comp_rel monotone_id monotone_id) ... ≤ map (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)) uniformity : map_mono comp_le_uniformity3, is_open_uniformity := assume s, have ∀a, ⟦a⟧ ∈ s → ({p:α×α | p.1 = a → ⟦p.2⟧ ∈ s} ∈ (@uniformity α _).sets ↔ {p:α×α | p.1 ≈ a → ⟦p.2⟧ ∈ s} ∈ (@uniformity α _).sets), from assume a ha, ⟨assume h, let ⟨t, ht, hts⟩ := comp_mem_uniformity_sets h in have hts : ∀{a₁ a₂}, (a, a₁) ∈ t → (a₁, a₂) ∈ t → ⟦a₂⟧ ∈ s, from assume a₁ a₂ ha₁ ha₂, @hts (a, a₂) ⟨a₁, ha₁, ha₂⟩ rfl, have ht' : ∀{a₁ a₂}, a₁ ≈ a₂ → (a₁, a₂) ∈ t, from assume a₁ a₂ h, sInter_subset_of_mem ht h, uniformity.sets_of_superset ht $ assume ⟨a₁, a₂⟩ h₁ h₂, hts (ht' $ setoid.symm h₂) h₁, assume h, uniformity.sets_of_superset h $ by simp {contextual := tt}⟩, begin simp [topological_space.coinduced, u.is_open_uniformity, uniformity, forall_quotient_iff], exact ⟨λh a ha, (this a ha).mp $ h a ha, λh a ha, (this a ha).mpr $ h a ha⟩ end } lemma uniform_continuous_quotient_mk : uniform_continuous (quotient.mk : α → quotient (separation_setoid α)) := le_refl _ lemma vmap_quotient_le_uniformity : vmap (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧)) uniformity ≤ uniformity := assume t' ht', let ⟨t, ht, tt_t'⟩ := comp_mem_uniformity_sets ht' in let ⟨s, hs, ss_t⟩ := comp_mem_uniformity_sets ht in ⟨(λp:α×α, (⟦p.1⟧, ⟦p.2⟧)) '' s, (@uniformity α _).sets_of_superset hs $ assume x hx, ⟨x, hx, rfl⟩, assume ⟨a₁, a₂⟩ ⟨⟨b₁, b₂⟩, hb, ab_eq⟩, have ⟦b₁⟧ = ⟦a₁⟧ ∧ ⟦b₂⟧ = ⟦a₂⟧, from prod.mk.inj ab_eq, have b₁ ≈ a₁ ∧ b₂ ≈ a₂, from and.imp quotient.exact quotient.exact this, have ab₁ : (a₁, b₁) ∈ t, from (setoid.symm this.left) t ht, have ba₂ : (b₂, a₂) ∈ s, from this.right s hs, tt_t' ⟨b₁, show ((a₁, a₂).1, b₁) ∈ t, from ab₁, ss_t ⟨b₂, show ((b₁, a₂).1, b₂) ∈ s, from hb, ba₂⟩⟩⟩ lemma vmap_quotient_eq_uniformity : vmap (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧)) uniformity = uniformity := le_antisymm vmap_quotient_le_uniformity le_vmap_map lemma complete_space_separation [h : complete_space α] : complete_space (quotient (separation_setoid α)) := ⟨assume f, assume hf : cauchy f, have cauchy (vmap (λx, ⟦x⟧) f), from cauchy_vmap vmap_quotient_le_uniformity hf $ vmap_neq_bot_of_surj hf.left $ assume b, quotient.exists_rep _, let ⟨x, (hx : vmap (λx, ⟦x⟧) f ≤ nhds x)⟩ := complete_space.complete this in ⟨⟦x⟧, calc f ≤ map (λx, ⟦x⟧) (vmap (λx, ⟦x⟧) f) : le_map_vmap $ assume b, quotient.exists_rep _ ... ≤ map (λx, ⟦x⟧) (nhds x) : map_mono hx ... ≤ _ : continuous_iff_tendsto.mp uniform_continuous_quotient_mk.continuous _⟩⟩ lemma separated_separation [h : complete_space α] : separated (quotient (separation_setoid α)) := set.ext $ assume ⟨a, b⟩, quotient.induction_on₂ a b $ assume a b, ⟨assume h, have a ≈ b, from assume s hs, have s ∈ (vmap (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)) uniformity).sets, from vmap_quotient_le_uniformity hs, let ⟨t, ht, hts⟩ := this in hts begin dsimp, exact h t ht end, show ⟦a⟧ = ⟦b⟧, from quotient.sound this, assume heq : ⟦a⟧ = ⟦b⟧, assume h hs, heq ▸ refl_mem_uniformity hs⟩ variables [uniform_space β] [uniform_space γ] lemma uniform_continuous_quotient {f : quotient (separation_setoid α) → β} (hf : uniform_continuous (λx, f ⟦x⟧)) : uniform_continuous f := hf lemma uniform_continuous_quotient_lift {f : α → β} {h : ∀a b, (a, b) ∈ separation_rel α → f a = f b} (hf : uniform_continuous f) : uniform_continuous (λa, quotient.lift f h a) := uniform_continuous_quotient hf lemma uniformity_quotient : @uniformity (quotient (separation_setoid α)) _ = uniformity.map (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)) := rfl lemma separated_of_uniform_continuous {f : α → β} (H : uniform_continuous f) {x y : α} (h : x ≈ y) : f x ≈ f y := assume _ h', h _ (H h') lemma eq_of_separated_of_uniform_continuous [separated β] {f : α → β} (H : uniform_continuous f) {x y : α} (h : x ≈ y) : f x = f y := separated_def.1 (by apply_instance) _ _ $ separated_of_uniform_continuous H h end separation_space section uniform_extension variables [uniform_space β] [uniform_space γ] {e : β → α} (h_e : uniform_embedding e) (h_dense : ∀x, x ∈ closure (range e)) {f : β → γ} (h_f : uniform_continuous f) local notation `ψ` := (h_e.dense_embedding h_dense).extend f lemma uniformly_extend_of_emb [cγ : complete_space γ] [sγ : separated γ] {b : β} : ψ (e b) = f b := dense_embedding.extend_e_eq _ $ continuous_iff_tendsto.mp h_f.continuous b lemma uniformly_extend_exists [complete_space γ] [sγ : separated γ] {a : α} : ∃c, tendsto f (vmap e (nhds a)) (nhds c) := let de := (h_e.dense_embedding h_dense) in have cauchy (nhds a), from cauchy_nhds, have cauchy (vmap e (nhds a)), from cauchy_vmap (le_of_eq h_e.right) this de.vmap_nhds_neq_bot, have cauchy (map f (vmap e (nhds a))), from cauchy_map h_f this, complete_space.complete this lemma uniformly_extend_spec [complete_space γ] [sγ : separated γ] {a : α} : tendsto f (vmap e (nhds a)) (nhds (ψ a)) := @lim_spec _ (id _) _ _ $ uniformly_extend_exists h_e h_dense h_f lemma uniform_continuous_uniformly_extend [cγ : complete_space γ] [sγ : separated γ] : uniform_continuous ψ := assume d hd, let ⟨s, hs, hs_comp⟩ := (mem_lift'_sets $ monotone_comp_rel monotone_id $ monotone_comp_rel monotone_id monotone_id).mp (comp_le_uniformity3 hd) in have h_pnt : ∀{a m}, m ∈ (nhds a).sets → ∃c, c ∈ f '' preimage e m ∧ (c, ψ a) ∈ s ∧ (ψ a, c) ∈ s, from assume a m hm, have nb : map f (vmap e (nhds a)) ≠ ⊥, from map_ne_bot (h_e.dense_embedding h_dense).vmap_nhds_neq_bot, have (f '' preimage e m) ∩ ({c | (c, ψ a) ∈ s } ∩ {c | (ψ a, c) ∈ s }) ∈ (map f (vmap e (nhds a))).sets, from inter_mem_sets (image_mem_map $ preimage_mem_vmap $ hm) (uniformly_extend_spec h_e h_dense h_f $ inter_mem_sets (mem_nhds_right _ hs) (mem_nhds_left _ hs)), inhabited_of_mem_sets nb this, have preimage (λp:β×β, (f p.1, f p.2)) s ∈ (@uniformity β _).sets, from h_f hs, have preimage (λp:β×β, (f p.1, f p.2)) s ∈ (vmap (λx:β×β, (e x.1, e x.2)) uniformity).sets, by rwa [h_e.right.symm] at this, let ⟨t, ht, ts⟩ := this in show preimage (λp:(α×α), (ψ p.1, ψ p.2)) d ∈ uniformity.sets, from (@uniformity α _).sets_of_superset (interior_mem_uniformity ht) $ assume ⟨x₁, x₂⟩ hx_t, have nhds (x₁, x₂) ≤ principal (interior t), from is_open_iff_nhds.mp is_open_interior (x₁, x₂) hx_t, have interior t ∈ (filter.prod (nhds x₁) (nhds x₂)).sets, by rwa [nhds_prod_eq, le_principal_iff] at this, let ⟨m₁, hm₁, m₂, hm₂, (hm : set.prod m₁ m₂ ⊆ interior t)⟩ := mem_prod_iff.mp this in let ⟨a, ha₁, _, ha₂⟩ := h_pnt hm₁ in let ⟨b, hb₁, hb₂, _⟩ := h_pnt hm₂ in have set.prod (preimage e m₁) (preimage e m₂) ⊆ preimage (λp:(β×β), (f p.1, f p.2)) s, from calc _ ⊆ preimage (λp:(β×β), (e p.1, e p.2)) (interior t) : preimage_mono hm ... ⊆ preimage (λp:(β×β), (e p.1, e p.2)) t : preimage_mono interior_subset ... ⊆ preimage (λp:(β×β), (f p.1, f p.2)) s : ts, have set.prod (f '' preimage e m₁) (f '' preimage e m₂) ⊆ s, from calc set.prod (f '' preimage e m₁) (f '' preimage e m₂) = (λp:(β×β), (f p.1, f p.2)) '' (set.prod (preimage e m₁) (preimage e m₂)) : prod_image_image_eq ... ⊆ (λp:(β×β), (f p.1, f p.2)) '' preimage (λp:(β×β), (f p.1, f p.2)) s : mono_image this ... ⊆ s : image_subset_iff.mpr $ subset.refl _, have (a, b) ∈ s, from @this (a, b) ⟨ha₁, hb₁⟩, hs_comp $ show (ψ x₁, ψ x₂) ∈ comp_rel s (comp_rel s s), from ⟨a, ha₂, ⟨b, this, hb₂⟩⟩ end uniform_extension end uniform_space end /-- 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 α] def gen (s : set (α × α)) : set (Cauchy α × Cauchy α) := {p | s ∈ (filter.prod (p.1.val) (p.2.val)).sets } lemma monotone_gen : monotone gen := monotone_set_of $ assume p, @monotone_mem_sets (α×α) (filter.prod (p.1.val) (p.2.val)) private lemma symm_gen : map prod.swap (uniformity.lift' gen) ≤ uniformity.lift' gen := calc map prod.swap (uniformity.lift' gen) = uniformity.lift' (λs:set (α×α), {p | s ∈ (filter.prod (p.2.val) (p.1.val)).sets }) : begin delta gen, simp [map_lift'_eq, monotone_set_of, monotone_mem_sets, function.comp, image_swap_eq_preimage_swap] end ... ≤ uniformity.lift' gen : uniformity_lift_le_swap (monotone_comp (monotone_set_of $ assume p, @monotone_mem_sets (α×α) ((filter.prod ((p.2).val) ((p.1).val)))) monotone_principal) begin have h := λ(p:Cauchy α×Cauchy α), @filter.prod_comm _ _ (p.2.val) (p.1.val), simp [function.comp, h], exact le_refl _ 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.sets), t₂, (ht₂ : t₂ ∈ h.val.sets), (h₁ : set.prod t₁ t₂ ⊆ s)⟩ := mem_prod_iff.mp h₁ in let ⟨t₃, (ht₃ : t₃ ∈ h.val.sets), t₄, (ht₄ : t₄ ∈ g.val.sets), (h₂ : set.prod t₃ t₄ ⊆ t)⟩ := mem_prod_iff.mp h₂ in have t₂ ∩ t₃ ∈ h.val.sets, from inter_mem_sets ht₂ ht₃, let ⟨x, xt₂, xt₃⟩ := inhabited_of_mem_sets (h.property.left) this in (filter.prod 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) ∈ set.prod t₁ t₂, from ⟨ha, xt₂⟩), h₂ (show (x, b) ∈ set.prod t₃ t₄, from ⟨xt₃, hb⟩)⟩) private lemma comp_gen : (uniformity.lift' gen).lift' (λs, comp_rel s s) ≤ uniformity.lift' gen := calc (uniformity.lift' gen).lift' (λs, comp_rel s s) = uniformity.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 ... ≤ uniformity.lift' (λs, gen $ comp_rel s s) : lift'_mono' $ assume s hs, comp_rel_gen_gen_subset_gen_comp_rel ... = (uniformity.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 ... ≤ uniformity.lift' gen : lift'_mono comp_le_uniformity (le_refl _) instance completion_space : uniform_space (Cauchy α) := uniform_space.of_core { uniformity := 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 ∈ (@uniformity (Cauchy α) _).sets ↔ ∃ t ∈ (@uniformity α _).sets, gen t ⊆ s := mem_lift'_sets monotone_gen theorem mem_uniformity' {s : set (Cauchy α × Cauchy α)} : s ∈ (@uniformity (Cauchy α) _).sets ↔ ∃ t ∈ (@uniformity α _).sets, ∀ f g : Cauchy α, t ∈ (filter.prod f.1 g.1).sets → (f, g) ∈ s := mem_uniformity.trans $ bex_congr $ λ t h, prod.forall /-- Embedding of `α` into its completion -/ def pure_cauchy (a : α) : Cauchy α := ⟨pure a, cauchy_pure⟩ lemma uniform_embedding_pure_cauchy : uniform_embedding (pure_cauchy : α → Cauchy α) := ⟨assume a₁ a₂ h, have (pure_cauchy a₁).val = (pure_cauchy a₂).val, from congr_arg _ h, have {a₁} = ({a₂} : set α), from principal_eq_iff_eq.mp this, by simp at this; assumption, 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 vmap (λ (x : α × α), (pure_cauchy (x.fst), pure_cauchy (x.snd))) (uniformity.lift' gen) = uniformity.lift' (preimage (λ (x : α × α), (pure_cauchy (x.fst), pure_cauchy (x.snd))) ∘ gen) : vmap_lift'_eq monotone_gen ... = uniformity : by simp [this]⟩ lemma pure_cauchy_dense : ∀x, x ∈ closure (range pure_cauchy) := assume f, have h_ex : ∀s∈(@uniformity (Cauchy α) _).sets, ∃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' ∈ (filter.prod (f.val) (f.val)).sets, from f.property.right ht'₁, let ⟨t, ht, (h : set.prod t t ⊆ t')⟩ := mem_prod_same_iff.mp this in let ⟨x, (hx : x ∈ t)⟩ := inhabited_of_mem_sets f.property.left ht in have t'' ∈ (filter.prod f.val (pure x)).sets, from mem_prod_iff.mpr ⟨t, ht, {y:α | (x, y) ∈ t'}, assume y, begin simp, intro h, simp [h], exact refl_mem_uniformity ht'₁ end, 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 [closure_eq_nhds, nhds_eq_uniformity, lift'_inf_principal_eq, set.inter_comm], exact (lift'_neq_bot_iff $ monotone_inter monotone_const 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⟩, ne_empty_of_mem this) end instance : complete_space (Cauchy α) := complete_space_extension uniform_embedding_pure_cauchy pure_cauchy_dense $ assume f hf, let f' : Cauchy α := ⟨f, hf⟩ in have map pure_cauchy f ≤ uniformity.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 : set.prod 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, (filter.prod f (pure x)).sets_of_superset (prod_mem_prod ht' $ mem_pure hx) h, f.sets_of_superset ht' $ subset.trans this (preimage_mono ht₂), ⟨f', by simp [nhds_eq_uniformity]; assumption⟩ end end Cauchy instance nonempty_Cauchy {α : Type u} [h : nonempty α] [uniform_space α] : nonempty (Cauchy α) := h.rec_on $ assume a, nonempty.intro $ Cauchy.pure_cauchy a instance inhabited_Cauchy {α : Type u} [inhabited α] [uniform_space α] : inhabited (Cauchy α) := ⟨Cauchy.pure_cauchy $ default α⟩ section constructions variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {ι : Sort*} instance : partial_order (uniform_space α) := { le := λt s, s.uniformity ≤ t.uniformity, le_antisymm := assume t s h₁ h₂, uniform_space_eq $ le_antisymm h₂ h₁, le_refl := assume t, le_refl _, le_trans := assume a b c h₁ h₂, @le_trans _ _ c.uniformity b.uniformity a.uniformity h₂ h₁ } instance : has_Sup (uniform_space α) := ⟨assume s, uniform_space.of_core { uniformity := (⨅u∈s, @uniformity α u), refl := le_infi $ assume u, le_infi $ assume hu, u.refl, symm := le_infi $ assume u, le_infi $ assume hu, le_trans (map_mono $ infi_le_of_le _ $ infi_le _ hu) u.symm, comp := le_infi $ assume u, le_infi $ assume hu, le_trans (lift'_mono (infi_le_of_le _ $ infi_le _ hu) $ le_refl _) u.comp }⟩ private lemma le_Sup {tt : set (uniform_space α)} {t : uniform_space α} (h : t ∈ tt) : t ≤ Sup tt := show (⨅u∈tt, @uniformity α u) ≤ t.uniformity, from infi_le_of_le t $ infi_le _ h private lemma Sup_le {tt : set (uniform_space α)} {t : uniform_space α} (h : ∀t'∈tt, t' ≤ t) : Sup tt ≤ t := show t.uniformity ≤ (⨅u∈tt, @uniformity α u), from le_infi $ assume t', le_infi $ assume ht', h t' ht' instance : has_bot (uniform_space α) := ⟨uniform_space.of_core { uniformity := ⊤, refl := le_top, symm := le_top, comp := le_top }⟩ instance : has_top (uniform_space α) := ⟨{ to_topological_space := ⊤, uniformity := principal id_rel, refl := le_refl _, symm := by simp [tendsto]; apply subset.refl, comp := begin rw [lift'_principal], {simp}, exact monotone_comp_rel monotone_id monotone_id end, is_open_uniformity := by simp [is_open_fold, subset_def, id_rel] {contextual := tt } } ⟩ instance : complete_lattice (uniform_space α) := { 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 h₁ h₂, Sup_le $ assume t', begin simp, intro h, cases h with h h, repeat { subst h; assumption } end, inf := λa b, Sup {x | x ≤ a ∧ x ≤ b}, le_inf := assume a b c h₁ h₂, le_Sup ⟨h₁, h₂⟩, inf_le_left := assume a b, Sup_le $ assume x ⟨ha, hb⟩, ha, inf_le_right := assume a b, Sup_le $ assume x ⟨ha, hb⟩, hb, top := ⊤, le_top := assume u, u.refl, bot := ⊥, bot_le := assume a, show a.uniformity ≤ ⊤, from le_top, Sup := Sup, le_Sup := assume s u, le_Sup, Sup_le := assume s u, Sup_le, Inf := λtt, Sup {t | ∀t'∈tt, t ≤ t'}, le_Inf := assume s a hs, le_Sup hs, Inf_le := assume s a ha, Sup_le $ assume u hs, hs _ ha, ..uniform_space.partial_order } lemma supr_uniformity {ι : Sort*} {u : ι → uniform_space α} : (supr u).uniformity = (⨅i, (u i).uniformity) := show (⨅a (h : ∃i:ι, a = u i), a.uniformity) = _, from le_antisymm (le_infi $ assume i, infi_le_of_le (u i) $ infi_le _ ⟨i, rfl⟩) (le_infi $ assume a, le_infi $ assume ⟨i, (ha : a = u i)⟩, ha.symm ▸ infi_le _ _) lemma sup_uniformity {u v : uniform_space α} : (u ⊔ v).uniformity = u.uniformity ⊓ v.uniformity := have (u ⊔ v) = (⨆i (h : i = u ∨ i = v), i), by simp [supr_or, supr_sup_eq], calc (u ⊔ v).uniformity = ((⨆i (h : i = u ∨ i = v), i) : uniform_space α).uniformity : by rw [this] ... = _ : by simp [supr_uniformity, infi_or, infi_inf_eq] instance inhabited_uniform_space : inhabited (uniform_space α) := ⟨⊤⟩ /-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f` is the inverse image in the filter sense of the induced function `α × α → β × β`. -/ def uniform_space.vmap (f : α → β) (u : uniform_space β) : uniform_space α := { uniformity := u.uniformity.vmap (λp:α×α, (f p.1, f p.2)), to_topological_space := u.to_topological_space.induced f, refl := le_trans (by simp; exact assume ⟨a, b⟩ (h : a = b), h ▸ rfl) (vmap_mono u.refl), symm := by simp [tendsto_vmap_iff, prod.swap, (∘)]; exact tendsto_vmap.comp tendsto_swap_uniformity, comp := le_trans begin rw [vmap_lift'_eq, vmap_lift'_eq2], exact (lift'_mono' $ assume s hs ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩, ⟨f x, h₁, h₂⟩), repeat { exact monotone_comp_rel monotone_id monotone_id } end (vmap_mono u.comp), is_open_uniformity := λ s, begin change (@is_open α (u.to_topological_space.induced f) s ↔ _), simp [is_open_iff_nhds, nhds_induced_eq_vmap, mem_nhds_uniformity_iff, filter.vmap, and_comm], refine ball_congr (λ x hx, ⟨_, _⟩), { rintro ⟨t, hts, ht⟩, refine ⟨_, ht, _⟩, rintro ⟨x₁, x₂⟩ h rfl, exact hts (h rfl) }, { rintro ⟨t, ht, hts⟩, exact ⟨{y | (f x, y) ∈ t}, λ y hy, @hts (x, y) hy rfl, mem_nhds_uniformity_iff.1 $ mem_nhds_left _ ht⟩ } end } lemma uniform_continuous_vmap {f : α → β} [u : uniform_space β] : @uniform_continuous α β (uniform_space.vmap f u) u f := tendsto_vmap theorem to_topological_space_vmap {f : α → β} {u : uniform_space β} : @uniform_space.to_topological_space _ (uniform_space.vmap f u) = topological_space.induced f (@uniform_space.to_topological_space β u) := eq_of_nhds_eq_nhds $ assume a, begin simp [nhds_induced_eq_vmap, nhds_eq_uniformity, nhds_eq_uniformity], change vmap f (uniformity.lift' (preimage (λb, (f a, b)))) = (u.uniformity.vmap (λp:α×α, (f p.1, f p.2))).lift' (preimage (λa', (a, a'))), rw [vmap_lift'_eq monotone_preimage, vmap_lift'_eq2 monotone_preimage], exact rfl end lemma uniform_continuous_vmap' {f : γ → β} {g : α → γ} [v : uniform_space β] [u : uniform_space α] (h : uniform_continuous (f ∘ g)) : @uniform_continuous α γ u (uniform_space.vmap f v) g := tendsto_vmap_iff.2 h lemma to_topological_space_mono {u₁ u₂ : uniform_space α} (h : u₁ ≤ u₂) : @uniform_space.to_topological_space _ u₁ ≤ @uniform_space.to_topological_space _ u₂ := le_of_nhds_le_nhds $ assume a, by rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact (lift'_mono h $ le_refl _) lemma to_topological_space_top : @uniform_space.to_topological_space α ⊤ = ⊤ := rfl lemma to_topological_space_bot : @uniform_space.to_topological_space α ⊥ = ⊥ := bot_unique $ assume s hs, classical.by_cases (assume : s = ∅, this.symm ▸ @is_open_empty _ ⊥) (assume : s ≠ ∅, let ⟨x, hx⟩ := exists_mem_of_ne_empty this in have s = univ, from top_unique $ assume y hy, hs x hx (x, y) rfl, this.symm ▸ @is_open_univ _ ⊥) lemma to_topological_space_supr {ι : Sort*} {u : ι → uniform_space α} : @uniform_space.to_topological_space α (supr u) = (⨆i, @uniform_space.to_topological_space α (u i)) := classical.by_cases (assume h : nonempty ι, eq_of_nhds_eq_nhds $ assume a, begin rw [nhds_supr, nhds_eq_uniformity], change _ = (supr u).uniformity.lift' (preimage $ prod.mk a), begin rw [supr_uniformity, lift'_infi], exact (congr_arg _ $ funext $ assume i, @nhds_eq_uniformity α (u i) a), exact h, exact assume a b, rfl end end) (assume : ¬ nonempty ι, le_antisymm (have supr u = ⊥, from bot_unique $ supr_le $ assume i, (this ⟨i⟩).elim, have @uniform_space.to_topological_space _ (supr u) = ⊥, from this.symm ▸ to_topological_space_bot, this.symm ▸ bot_le) (supr_le $ assume i, to_topological_space_mono $ le_supr _ _)) lemma to_topological_space_Sup {s : set (uniform_space α)} : @uniform_space.to_topological_space α (Sup s) = (⨆i∈s, @uniform_space.to_topological_space α i) := begin rw [Sup_eq_supr, to_topological_space_supr], apply congr rfl, funext x, exact to_topological_space_supr end lemma to_topological_space_sup {u v : uniform_space α} : @uniform_space.to_topological_space α (u ⊔ v) = @uniform_space.to_topological_space α u ⊔ @uniform_space.to_topological_space α v := ord_continuous_sup $ assume s, to_topological_space_Sup instance : uniform_space empty := ⊤ instance : uniform_space unit := ⊤ instance : uniform_space bool := ⊤ instance : uniform_space ℕ := ⊤ instance : uniform_space ℤ := ⊤ instance {p : α → Prop} [t : uniform_space α] : uniform_space (subtype p) := uniform_space.vmap subtype.val t lemma uniformity_subtype {p : α → Prop} [t : uniform_space α] : (@uniformity (subtype p) _) = vmap (λq:subtype p × subtype p, (q.1.1, q.2.1)) uniformity := rfl lemma uniform_continuous_subtype_val {p : α → Prop} [uniform_space α] : uniform_continuous (subtype.val : {a : α // p a} → α) := uniform_continuous_vmap lemma uniform_continuous_subtype_mk {p : α → Prop} [uniform_space α] [uniform_space β] {f : β → α} (hf : uniform_continuous f) (h : ∀x, p (f x)) : uniform_continuous (λx, ⟨f x, h x⟩ : β → subtype p) := uniform_continuous_vmap' hf lemma tendsto_of_uniform_continuous_subtype [uniform_space α] [uniform_space β] {f : α → β} {s : set α} {a : α} (hf : uniform_continuous (λx:s, f x.val)) (ha : s ∈ (nhds a).sets) : tendsto f (nhds a) (nhds (f a)) := by rw [(@map_nhds_subtype_val_eq α _ s a (mem_of_nhds ha) ha).symm]; exact tendsto_map' (continuous_iff_tendsto.mp hf.continuous _) instance [u₁ : uniform_space α] [u₂ : uniform_space β] : uniform_space (α × β) := uniform_space.of_core_eq (u₁.vmap prod.fst ⊔ u₂.vmap prod.snd).to_core prod.topological_space (calc prod.topological_space = (u₁.vmap prod.fst ⊔ u₂.vmap prod.snd).to_topological_space : by rw [to_topological_space_sup, to_topological_space_vmap, to_topological_space_vmap]; refl ... = _ : by rw [uniform_space.to_core_to_topological_space]) theorem uniformity_prod [uniform_space α] [uniform_space β] : @uniformity (α × β) _ = uniformity.vmap (λp:(α × β) × α × β, (p.1.1, p.2.1)) ⊓ uniformity.vmap (λp:(α × β) × α × β, (p.1.2, p.2.2)) := sup_uniformity lemma uniform_embedding_subtype_emb {α : Type*} {β : Type*} [uniform_space α] [uniform_space β] (p : α → Prop) {e : α → β} (ue : uniform_embedding e) (de : dense_embedding e) : uniform_embedding (de.subtype_emb p) := ⟨(de.subtype p).inj, by simp [vmap_vmap_comp, (∘), dense_embedding.subtype_emb, uniformity_subtype, ue.right.symm]⟩ lemma uniform_extend_subtype {α : Type*} {β : Type*} {γ : Type*} [uniform_space α] [uniform_space β] [uniform_space γ] [complete_space γ] [inhabited γ] [separated γ] {p : α → Prop} {e : α → β} {f : α → γ} {b : β} {s : set α} (hf : uniform_continuous (λx:subtype p, f x.val)) (he : uniform_embedding e) (hd : ∀x:β, x ∈ closure (range e)) (hb : closure (e '' s) ∈ (nhds b).sets) (hs : is_closed s) (hp : ∀x∈s, p x) : ∃c, tendsto f (vmap e (nhds b)) (nhds c) := have de : dense_embedding e, from he.dense_embedding hd, have de' : dense_embedding (de.subtype_emb p), by exact de.subtype p, have ue' : uniform_embedding (de.subtype_emb p), from uniform_embedding_subtype_emb _ he de, have b ∈ closure (e '' {x | p x}), from (closure_mono $ mono_image $ hp) (mem_of_nhds hb), let ⟨c, (hc : tendsto (f ∘ subtype.val) (vmap (de.subtype_emb p) (nhds ⟨b, this⟩)) (nhds c))⟩ := uniformly_extend_exists ue' de'.dense hf in begin rw [nhds_subtype_eq_vmap] at hc, simp [vmap_vmap_comp] at hc, change (tendsto (f ∘ @subtype.val α p) (vmap (e ∘ @subtype.val α p) (nhds b)) (nhds c)) at hc, rw [←vmap_vmap_comp] at hc, existsi c, apply tendsto_vmap'' s _ _ hc, exact ⟨_, hb, assume x, begin change e x ∈ (closure (e '' s)) → x ∈ s, rw [←closure_induced, closure_eq_nhds], dsimp, rw [nhds_induced_eq_vmap, de.induced], change x ∈ {x | nhds x ⊓ principal s ≠ ⊥} → x ∈ s, rw [←closure_eq_nhds, closure_eq_of_is_closed hs], exact id, exact de.inj end⟩, exact (assume x hx, ⟨⟨x, hp x hx⟩, rfl⟩) end /- a similar product space is possible on the function space (uniformity of pointwise convergence), but we want to have the uniformity of uniform convergence on function spaces -/ lemma uniformity_prod_eq_prod [uniform_space α] [uniform_space β] : @uniformity (α×β) _ = map (λp:(α×α)×(β×β), ((p.1.1, p.2.1), (p.1.2, p.2.2))) (filter.prod uniformity uniformity) := have map (λp:(α×α)×(β×β), ((p.1.1, p.2.1), (p.1.2, p.2.2))) = vmap (λp:(α×β)×(α×β), ((p.1.1, p.2.1), (p.1.2, p.2.2))), from funext $ assume f, map_eq_vmap_of_inverse (funext $ assume ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl) (funext $ assume ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl), by rw [this, uniformity_prod, filter.prod, vmap_inf, vmap_vmap_comp, vmap_vmap_comp] lemma mem_uniform_prod [t₁ : uniform_space α] [t₂ : uniform_space β] {a : set (α × α)} {b : set (β × β)} (ha : a ∈ (@uniformity α _).sets) (hb : b ∈ (@uniformity β _).sets) : {p:(α×β)×(α×β) | (p.1.1, p.2.1) ∈ a ∧ (p.1.2, p.2.2) ∈ b } ∈ (@uniformity (α × β) _).sets := by rw [uniformity_prod]; exact inter_mem_inf_sets (preimage_mem_vmap ha) (preimage_mem_vmap hb) lemma tendsto_prod_uniformity_fst [uniform_space α] [uniform_space β] : tendsto (λp:(α×β)×(α×β), (p.1.1, p.2.1)) uniformity uniformity := le_trans (map_mono (@le_sup_left (uniform_space (α×β)) _ _ _)) map_vmap_le lemma tendsto_prod_uniformity_snd [uniform_space α] [uniform_space β] : tendsto (λp:(α×β)×(α×β), (p.1.2, p.2.2)) uniformity uniformity := le_trans (map_mono (@le_sup_right (uniform_space (α×β)) _ _ _)) map_vmap_le lemma uniform_continuous_fst [uniform_space α] [uniform_space β] : uniform_continuous (λp:α×β, p.1) := tendsto_prod_uniformity_fst lemma uniform_continuous_snd [uniform_space α] [uniform_space β] : uniform_continuous (λp:α×β, p.2) := tendsto_prod_uniformity_snd variables [uniform_space α] [uniform_space β] [uniform_space γ] lemma uniform_continuous.prod_mk {f₁ : α → β} {f₂ : α → γ} (h₁ : uniform_continuous f₁) (h₂ : uniform_continuous f₂) : uniform_continuous (λa, (f₁ a, f₂ a)) := by rw [uniform_continuous, uniformity_prod]; exact tendsto_inf.2 ⟨tendsto_vmap_iff.2 h₁, tendsto_vmap_iff.2 h₂⟩ lemma uniform_continuous.prod_mk_left {f : α × β → γ} (h : uniform_continuous f) (b) : uniform_continuous (λ a, f (a,b)) := uniform_continuous.comp (uniform_continuous.prod_mk uniform_continuous_id uniform_continuous_const) h lemma uniform_continuous.prod_mk_right {f : α × β → γ} (h : uniform_continuous f) (a) : uniform_continuous (λ b, f (a,b)) := uniform_continuous.comp (uniform_continuous.prod_mk uniform_continuous_const uniform_continuous_id) h instance complete_space.prod [complete_space α] [complete_space β] : complete_space (α × β) := { complete := λ f hf, let ⟨x1, hx1⟩ := complete_space.complete $ cauchy_map uniform_continuous_fst hf in let ⟨x2, hx2⟩ := complete_space.complete $ cauchy_map uniform_continuous_snd hf in ⟨(x1, x2), by rw [nhds_prod_eq, filter.prod_def]; from filter.le_lift (λ s hs, filter.le_lift' $ λ t ht, have H1 : prod.fst ⁻¹' s ∈ f.sets := hx1 hs, have H2 : prod.snd ⁻¹' t ∈ f.sets := hx2 ht, filter.inter_mem_sets H1 H2)⟩ } lemma uniform_embedding.prod {α' : Type*} {β' : Type*} [uniform_space α] [uniform_space β] [uniform_space α'] [uniform_space β'] {e₁ : α → α'} {e₂ : β → β'} (h₁ : uniform_embedding e₁) (h₂ : uniform_embedding e₂) : uniform_embedding (λp:α×β, (e₁ p.1, e₂ p.2)) := ⟨assume ⟨a₁, b₁⟩ ⟨a₂, b₂⟩, by simp [prod.mk.inj_iff]; exact assume eq₁ eq₂, ⟨h₁.left eq₁, h₂.left eq₂⟩, by simp [(∘), uniformity_prod, h₁.right.symm, h₂.right.symm, vmap_inf, vmap_vmap_comp]⟩ lemma to_topological_space_prod [u : uniform_space α] [v : uniform_space β] : @uniform_space.to_topological_space (α × β) prod.uniform_space = @prod.topological_space α β u.to_topological_space v.to_topological_space := rfl lemma to_topological_space_subtype [u : uniform_space α] {p : α → Prop} : @uniform_space.to_topological_space (subtype p) subtype.uniform_space = @subtype.topological_space α p u.to_topological_space := rfl section separation_space local attribute [instance] separation_setoid lemma uniform_continuous_quotient_lift₂ [uniform_space γ] {f : α → β → γ} {h : ∀a c b d, (a, b) ∈ separation_rel α → (c, d) ∈ separation_rel β → f a c = f b d} (hf : uniform_continuous (λp:α×β, f p.1 p.2)) : uniform_continuous (λp:_×_, quotient.lift₂ f h p.1 p.2) := begin rw [uniform_continuous, uniformity_prod_eq_prod, uniformity_quotient, uniformity_quotient, filter.prod_map_map_eq, filter.tendsto_map'_iff, filter.tendsto_map'_iff], rwa [uniform_continuous, uniformity_prod_eq_prod, filter.tendsto_map'_iff] at hf end lemma separation_prod {a₁ a₂ : α} {b₁ b₂ : β} : (a₁, b₁) ≈ (a₂, b₂) ↔ a₁ ≈ a₂ ∧ b₁ ≈ b₂ := begin split ; intro h, { exact ⟨separated_of_uniform_continuous uniform_continuous_fst h, separated_of_uniform_continuous uniform_continuous_snd h⟩ }, { rcases h with ⟨eqv_α, eqv_β⟩, intros r r_in, rw uniformity_prod at r_in, rcases r_in with ⟨t_α, ⟨r_α, r_α_in, h_α⟩, t_β, ⟨r_β, r_β_in, h_β⟩, H⟩, let p_α := λ (p : (α × β) × α × β), ((p.fst).fst, (p.snd).fst), let p_β := λ (p : (α × β) × α × β), ((p.fst).snd, (p.snd).snd), have key_α : p_α ((a₁, b₁), (a₂, b₂)) ∈ r_α, by simp[p_α, eqv_α r_α r_α_in], have key_β : p_β ((a₁, b₁), (a₂, b₂)) ∈ r_β, by simp[p_β, eqv_β r_β r_β_in], exact H ⟨h_α key_α, h_β key_β⟩ }, end instance separated.prod [separated α] [separated β] : separated (α × β) := separated_def.2 $ assume x y H, prod.ext (eq_of_separated_of_uniform_continuous uniform_continuous_fst H) (eq_of_separated_of_uniform_continuous uniform_continuous_snd H) end separation_space end constructions lemma lebesgue_number_lemma {α : Type u} [uniform_space α] {s : set α} {ι} {c : ι → set α} (hs : compact s) (hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) : ∃ n ∈ (@uniformity α _).sets, ∀ x ∈ s, ∃ i, {y | (x, y) ∈ n} ⊆ c i := begin let u := λ n, {x | ∃ i (m ∈ (@uniformity α _).sets), {y | (x, y) ∈ comp_rel m n} ⊆ c i}, have hu₁ : ∀ n ∈ (@uniformity α _).sets, is_open (u n), { refine λ n hn, is_open_uniformity.2 _, rintro x ⟨i, m, hm, h⟩, rcases comp_mem_uniformity_sets hm with ⟨m', hm', mm'⟩, apply uniformity.sets_of_superset hm', rintros ⟨x, y⟩ hp rfl, refine ⟨i, m', hm', λ z hz, h (monotone_comp_rel monotone_id monotone_const mm' _)⟩, dsimp at hz ⊢, rw comp_rel_assoc, exact ⟨y, hp, hz⟩ }, have hu₂ : s ⊆ ⋃ n ∈ (@uniformity α _).sets, u n, { intros x hx, rcases mem_Union.1 (hc₂ hx) with ⟨i, h⟩, rcases comp_mem_uniformity_sets (is_open_uniformity.1 (hc₁ i) x h) with ⟨m', hm', mm'⟩, exact mem_bUnion hm' ⟨i, _, hm', λ y hy, mm' hy rfl⟩ }, rcases compact_elim_finite_subcover_image hs hu₁ hu₂ with ⟨b, bu, b_fin, b_cover⟩, refine ⟨_, Inter_mem_sets b_fin bu, λ x hx, _⟩, rcases mem_bUnion_iff.1 (b_cover hx) with ⟨n, bn, i, m, hm, h⟩, refine ⟨i, λ y hy, h _⟩, exact prod_mk_mem_comp_rel (refl_mem_uniformity hm) (bInter_subset_of_mem bn hy) end lemma lebesgue_number_lemma_sUnion {α : Type u} [uniform_space α] {s : set α} {c : set (set α)} (hs : compact s) (hc₁ : ∀ t ∈ c, is_open t) (hc₂ : s ⊆ ⋃₀ c) : ∃ n ∈ (@uniformity α _).sets, ∀ x ∈ s, ∃ t ∈ c, ∀ y, (x, y) ∈ n → y ∈ t := by rw sUnion_eq_Union at hc₂; simpa using lebesgue_number_lemma hs (by simpa) hc₂
2375d0f17251dd29a64bb66c8e2eb40d75789199
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/control/uliftable.lean
6b96c5ccae147118ff0f9470450abff397bfd0d7
[ "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
5,580
lean
/- Copyright (c) 2020 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import control.monad.basic import control.monad.cont import control.monad.writer import data.equiv.basic import tactic.interactive /-! # Universe lifting for type families Some functors such as `option` and `list` are universe polymorphic. Unlike type polymorphism where `option α` is a function application and reasoning and generalizations that apply to functions can be used, `option.{u}` and `option.{v}` are not one function applied to two universe names but one polymorphic definition instantiated twice. This means that whatever works on `option.{u}` is hard to transport over to `option.{v}`. `uliftable` is an attempt at improving the situation. `uliftable option.{u} option.{v}` gives us a generic and composable way to use `option.{u}` in a context that requires `option.{v}`. It is often used in tandem with `ulift` but the two are purposefully decoupled. ## Main definitions * `uliftable` class ## Tags universe polymorphism functor -/ universes u₀ u₁ v₀ v₁ v₂ w w₀ w₁ variables {s : Type u₀} {s' : Type u₁} {r r' w w' : Type*} /-- Given a universe polymorphic type family `M.{u} : Type u₁ → Type u₂`, this class convert between instantiations, from `M.{u} : Type u₁ → Type u₂` to `M.{v} : Type v₁ → Type v₂` and back -/ class uliftable (f : Type u₀ → Type u₁) (g : Type v₀ → Type v₁) := (congr [] {α β} : α ≃ β → f α ≃ g β) namespace uliftable /-- The most common practical use `uliftable` (together with `up`), this function takes `x : M.{u} α` and lifts it to M.{max u v} (ulift.{v} α) -/ @[reducible] def up {f : Type u₀ → Type u₁} {g : Type (max u₀ v₀) → Type v₁} [uliftable f g] {α} : f α → g (ulift α) := (uliftable.congr f g equiv.ulift.symm).to_fun /-- The most common practical use of `uliftable` (together with `up`), this function takes `x : M.{max u v} (ulift.{v} α)` and lowers it to `M.{u} α` -/ @[reducible] def down {f : Type u₀ → Type u₁} {g : Type (max u₀ v₀) → Type v₁} [uliftable f g] {α} : g (ulift α) → f α := (uliftable.congr f g equiv.ulift.symm).inv_fun /-- convenient shortcut to avoid manipulating `ulift` -/ def adapt_up (F : Type v₀ → Type v₁) (G : Type (max v₀ u₀) → Type u₁) [uliftable F G] [monad G] {α β} (x : F α) (f : α → G β) : G β := up x >>= f ∘ ulift.down /-- convenient shortcut to avoid manipulating `ulift` -/ def adapt_down {F : Type (max u₀ v₀) → Type u₁} {G : Type v₀ → Type v₁} [L : uliftable G F] [monad F] {α β} (x : F α) (f : α → G β) : G β := @down.{v₀ v₁ (max u₀ v₀)} G F L β $ x >>= @up.{v₀ v₁ (max u₀ v₀)} G F L β ∘ f /-- map function that moves up universes -/ def up_map {F : Type u₀ → Type u₁} {G : Type.{max u₀ v₀} → Type v₁} [inst : uliftable F G] [functor G] {α β} (f : α → β) (x : F α) : G β := functor.map (f ∘ ulift.down) (up x) /-- map function that moves down universes -/ def down_map {F : Type.{max u₀ v₀} → Type u₁} {G : Type u₀ → Type v₁} [inst : uliftable G F] [functor F] {α β} (f : α → β) (x : F α) : G β := down (functor.map (ulift.up ∘ f) x : F (ulift β)) @[simp] lemma up_down {f : Type u₀ → Type u₁} {g : Type (max u₀ v₀) → Type v₁} [uliftable f g] {α} (x : g (ulift α)) : up (down x : f α) = x := (uliftable.congr f g equiv.ulift.symm).right_inv _ @[simp] lemma down_up {f : Type u₀ → Type u₁} {g : Type (max u₀ v₀) → Type v₁} [uliftable f g] {α} (x : f α) : down (up x : g _) = x := (uliftable.congr f g equiv.ulift.symm).left_inv _ end uliftable open ulift instance : uliftable id id := { congr := λ α β F, F } /-- for specific state types, this function helps to create a uliftable instance -/ def state_t.uliftable' {m : Type u₀ → Type v₀} {m' : Type u₁ → Type v₁} [uliftable m m'] (F : s ≃ s') : uliftable (state_t s m) (state_t s' m') := { congr := λ α β G, state_t.equiv $ equiv.Pi_congr F $ λ _, uliftable.congr _ _ $ equiv.prod_congr G F } instance {m m'} [uliftable m m'] : uliftable (state_t s m) (state_t (ulift s) m') := state_t.uliftable' equiv.ulift.symm /-- for specific reader monads, this function helps to create a uliftable instance -/ def reader_t.uliftable' {m m'} [uliftable m m'] (F : s ≃ s') : uliftable (reader_t s m) (reader_t s' m') := { congr := λ α β G, reader_t.equiv $ equiv.Pi_congr F $ λ _, uliftable.congr _ _ G } instance {m m'} [uliftable m m'] : uliftable (reader_t s m) (reader_t (ulift s) m') := reader_t.uliftable' equiv.ulift.symm /-- for specific continuation passing monads, this function helps to create a uliftable instance -/ def cont_t.uliftable' {m m'} [uliftable m m'] (F : r ≃ r') : uliftable (cont_t r m) (cont_t r' m') := { congr := λ α β, cont_t.equiv (uliftable.congr _ _ F) } instance {s m m'} [uliftable m m'] : uliftable (cont_t s m) (cont_t (ulift s) m') := cont_t.uliftable' equiv.ulift.symm /-- for specific writer monads, this function helps to create a uliftable instance -/ def writer_t.uliftable' {m m'} [uliftable m m'] (F : w ≃ w') : uliftable (writer_t w m) (writer_t w' m') := { congr := λ α β G, writer_t.equiv $ uliftable.congr _ _ $ equiv.prod_congr G F } instance {m m'} [uliftable m m'] : uliftable (writer_t s m) (writer_t (ulift s) m') := writer_t.uliftable' equiv.ulift.symm
a6cf2d1de06ce472111d5ba2127c69e05dd15aac
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/src/Init/Lean/Elab/DeclModifiers.lean
6c102acb791546a9e73eae604da3143281bd27ce
[ "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
4,631
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Sebastian Ullrich -/ prelude import Init.Lean.Elab.Command namespace Lean namespace Elab namespace Command structure Attribute := (name : Name) (args : Syntax := Syntax.missing) instance Attribute.hasFormat : HasFormat Attribute := ⟨fun attr => Format.bracket "@[" (toString attr.name ++ (if attr.args.isMissing then "" else toString attr.args)) "]"⟩ inductive Visibility | regular | «protected» | «private» instance Visibility.hasToString : HasToString Visibility := ⟨fun v => match v with | Visibility.regular => "regular" | Visibility.private => "private" | Visibility.protected => "protected"⟩ structure Modifiers := (docString : Option String := none) (visibility : Visibility := Visibility.regular) (isNoncomputable : Bool := false) (isPartial : Bool := false) (isUnsafe : Bool := false) (attrs : Array Attribute := #[]) def Modifiers.addAttribute (modifiers : Modifiers) (attr : Attribute) : Modifiers := { attrs := modifiers.attrs.push attr, .. modifiers } instance Modifiers.hasFormat : HasFormat Modifiers := ⟨fun m => let components : List Format := (match m.docString with | some str => ["/--" ++ str ++ "-/"] | none => []) ++ (match m.visibility with | Visibility.regular => [] | Visibility.protected => ["protected"] | Visibility.private => ["private"]) ++ (if m.isNoncomputable then ["noncomputable"] else []) ++ (if m.isPartial then ["partial"] else []) ++ (if m.isUnsafe then ["unsafe"] else []) ++ m.attrs.toList.map (fun attr => fmt attr); Format.bracket "{" (Format.joinSep components ("," ++ Format.line)) "}"⟩ instance Modifiers.hasToString : HasToString Modifiers := ⟨toString ∘ format⟩ def elabAttr (stx : Syntax) : CommandElabM Attribute := do -- rawIdent >> many attrArg let nameStx := stx.getArg 0; attrName ← match nameStx.isIdOrAtom? with | none => throwError nameStx "identifier expected" | some str => pure $ mkNameSimple str; env ← getEnv; unless (isAttribute env attrName) $ throwError stx ("unknown attribute [" ++ attrName ++ "]"); let args := stx.getArg 1; pure { name := attrName, args := args } def elabAttrs (stx : Syntax) : CommandElabM (Array Attribute) := (stx.getArg 1).foldSepArgsM (fun stx attrs => do attr ← elabAttr stx; pure $ attrs.push attr) #[] def elabModifiers (stx : Syntax) : CommandElabM Modifiers := do let docCommentStx := stx.getArg 0; let attrsStx := stx.getArg 1; let visibilityStx := stx.getArg 2; let noncompStx := stx.getArg 3; let unsafeStx := stx.getArg 4; let partialStx := stx.getArg 5; docString ← match docCommentStx.getOptional? with | none => pure none | some s => match s.getArg 1 with | Syntax.atom _ val => pure (some (val.extract 0 (val.bsize - 2))) | _ => throwError s ("unexpected doc string " ++ toString (s.getArg 1)); visibility ← match visibilityStx.getOptional? with | none => pure Visibility.regular | some v => let kind := v.getKind; if kind == `Lean.Parser.Command.private then pure Visibility.private else if kind == `Lean.Parser.Command.protected then pure Visibility.protected else throwError v "unexpected visibility modifier"; attrs ← match attrsStx.getOptional? with | none => pure #[] | some attrs => elabAttrs attrs; pure { docString := docString, visibility := visibility, isPartial := !partialStx.isNone, isUnsafe := !unsafeStx.isNone, isNoncomputable := !noncompStx.isNone, attrs := attrs } def mkDeclName (modifiers : Modifiers) (atomicName : Name) : CommandElabM Name := do currNamespace ← getCurrNamespace; let declName := currNamespace ++ atomicName; match modifiers.visibility with | Visibility.private => do env ← getEnv; let (env, declName) := mkPrivateName env declName; setEnv env; -- TODO: alias? pure declName | _ => pure declName def applyAttributes (ref : Syntax) (declName : Name) (attrs : Array Attribute) (applicationTime : AttributeApplicationTime) : CommandElabM Unit := attrs.forM $ fun attr => do env ← getEnv; match getAttributeImpl env attr.name with | Except.error errMsg => throwError ref errMsg | Except.ok attrImpl => when (attrImpl.applicationTime == applicationTime) $ do env ← getEnv; env ← liftIO ref $ attrImpl.add env declName attr.args true; setEnv env end Command end Elab end Lean
3741d275576cec4d5b0d194a8652f914ee38ddc9
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
/src/algebra/category/Module/adjunctions.lean
3b7e874686270ac1b5e7cd6807d9c68d7146b111
[ "Apache-2.0" ]
permissive
waynemunro/mathlib
e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552
065a70810b5480d584033f7bbf8e0409480c2118
refs/heads/master
1,693,417,182,397
1,634,644,781,000
1,634,644,781,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
10,234
lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Johan Commelin -/ import algebra.category.Module.monoidal import category_theory.monoidal.functorial import category_theory.monoidal.types import linear_algebra.direct_sum.finsupp import category_theory.linear.linear_functor /-! The functor of forming finitely supported functions on a type with values in a `[ring R]` is the left adjoint of the forgetful functor from `R`-modules to types. -/ noncomputable theory open category_theory namespace Module universe u open_locale classical variables (R : Type u) section variables [ring R] /-- The free functor `Type u ⥤ Module R` sending a type `X` to the free `R`-module with generators `x : X`, implemented as the type `X →₀ R`. -/ @[simps] def free : Type u ⥤ Module R := { obj := λ X, Module.of R (X →₀ R), map := λ X Y f, finsupp.lmap_domain _ _ f, map_id' := by { intros, exact finsupp.lmap_domain_id _ _ }, map_comp' := by { intros, exact finsupp.lmap_domain_comp _ _ _ _, } } /-- The free-forgetful adjunction for R-modules. -/ def adj : free R ⊣ forget (Module.{u} R) := adjunction.mk_of_hom_equiv { hom_equiv := λ X M, (finsupp.lift M R X).to_equiv.symm, hom_equiv_naturality_left_symm' := λ _ _ M f g, finsupp.lhom_ext' (λ x, linear_map.ext_ring (finsupp.sum_map_domain_index_add_monoid_hom (λ y, ((smul_add_hom R ↥M).flip) (g y))).symm) } instance : is_right_adjoint (forget (Module.{u} R)) := ⟨_, adj R⟩ end namespace free variables [comm_ring R] local attribute [ext] tensor_product.ext /-- The free R-module functor is lax monoidal. -/ -- In fact, it's strong monoidal, but we don't yet have a typeclass for that. instance : lax_monoidal.{u} (free R).obj := { -- Send `R` to `punit →₀ R` ε := finsupp.lsingle punit.star, -- Send `(α →₀ R) ⊗ (β →₀ R)` to `α × β →₀ R` μ := λ α β, (finsupp_tensor_finsupp' R α β).to_linear_map, μ_natural' := begin intros, ext x x' ⟨y, y'⟩, -- This is rather tedious: it's a terminal simp, with no arguments, -- but between the four of them it is too slow. simp only [tensor_product.mk_apply, mul_one, tensor_apply, monoidal_category.hom_apply, Module.free_map, Module.coe_comp, map_functorial_obj, linear_map.compr₂_apply, linear_equiv.coe_to_linear_map, linear_map.comp_apply, function.comp_app, finsupp.lmap_domain_apply, finsupp.map_domain_single, finsupp_tensor_finsupp'_single_tmul_single, finsupp.lsingle_apply], end, left_unitality' := begin intros, ext, simp only [tensor_product.mk_apply, mul_one, Module.id_apply, Module.free_map, Module.coe_comp, map_functorial_obj, Module.monoidal_category.hom_apply, left_unitor_hom_apply, Module.monoidal_category.left_unitor_hom_apply, linear_map.compr₂_apply, linear_equiv.coe_to_linear_map, linear_map.comp_apply, function.comp_app, finsupp.lmap_domain_apply, finsupp.smul_single', finsupp.map_domain_single, finsupp_tensor_finsupp'_single_tmul_single, finsupp.lsingle_apply], end, right_unitality' := begin intros, ext, simp only [tensor_product.mk_apply, mul_one, Module.id_apply, Module.free_map, Module.coe_comp, map_functorial_obj, Module.monoidal_category.hom_apply, right_unitor_hom_apply, Module.monoidal_category.right_unitor_hom_apply, linear_map.compr₂_apply, linear_equiv.coe_to_linear_map, linear_map.comp_apply, function.comp_app, finsupp.lmap_domain_apply, finsupp.smul_single', finsupp.map_domain_single, finsupp_tensor_finsupp'_single_tmul_single, finsupp.lsingle_apply], end, associativity' := begin intros, ext, simp only [tensor_product.mk_apply, mul_one, Module.id_apply, Module.free_map, Module.coe_comp, map_functorial_obj, Module.monoidal_category.hom_apply, associator_hom_apply, Module.monoidal_category.associator_hom_apply, linear_map.compr₂_apply, linear_equiv.coe_to_linear_map, linear_map.comp_apply, function.comp_app, finsupp.lmap_domain_apply, finsupp.smul_single', finsupp.map_domain_single, finsupp_tensor_finsupp'_single_tmul_single, finsupp.lsingle_apply], end, } end free end Module namespace category_theory universes v u /-- `Free R C` is a type synonym for `C`, which, given `[comm_ring R]` and `[category C]`, we will equip with a category structure where the morphisms are formal `R`-linear combinations of the morphisms in `C`. -/ @[nolint unused_arguments has_inhabited_instance] def Free (R : Type*) (C : Type u) := C /-- Consider an object of `C` as an object of the `R`-linear completion. -/ def Free.of (R : Type*) {C : Type u} (X : C) : Free R C := X variables (R : Type*) [comm_ring R] (C : Type u) [category.{v} C] open finsupp -- Conceptually, it would be nice to construct this via "transport of enrichment", -- using the fact that `Module.free R : Type ⥤ Module R` and `Module.forget` are both lax monoidal. -- This still seems difficult, so we just do it by hand. instance category_Free : category (Free R C) := { hom := λ (X Y : C), (X ⟶ Y) →₀ R, id := λ (X : C), finsupp.single (𝟙 X) 1, comp := λ (X Y Z : C) f g, f.sum (λ f' s, g.sum (λ g' t, finsupp.single (f' ≫ g') (s * t))), assoc' := λ W X Y Z f g h, begin dsimp, -- This imitates the proof of associativity for `monoid_algebra`. simp only [sum_sum_index, sum_single_index, single_zero, single_add, eq_self_iff_true, forall_true_iff, forall_3_true_iff, add_mul, mul_add, category.assoc, mul_assoc, zero_mul, mul_zero, sum_zero, sum_add], end }. namespace Free section local attribute [simp] category_theory.category_Free @[simp] lemma single_comp_single {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (r s : R) : (single f r ≫ single g s : (Free.of R X) ⟶ (Free.of R Z)) = single (f ≫ g) (r * s) := by { dsimp, simp, } instance : preadditive (Free R C) := { hom_group := λ X Y, finsupp.add_comm_group, add_comp' := λ X Y Z f f' g, begin dsimp, rw [finsupp.sum_add_index]; { simp [add_mul], } end, comp_add' := λ X Y Z f g g', begin dsimp, rw ← finsupp.sum_add, congr, ext r h, rw [finsupp.sum_add_index]; { simp [mul_add], }, end, } instance : linear R (Free R C) := { hom_module := λ X Y, finsupp.module (X ⟶ Y) R, smul_comp' := λ X Y Z r f g, begin dsimp, rw [finsupp.sum_smul_index]; simp [finsupp.smul_sum, mul_assoc], end, comp_smul' := λ X Y Z f r g, begin dsimp, simp_rw [finsupp.smul_sum], congr, ext h s, rw [finsupp.sum_smul_index]; simp [finsupp.smul_sum, mul_left_comm], end, } end /-- A category embeds into its `R`-linear completion. -/ @[simps] def embedding : C ⥤ Free R C := { obj := λ X, X, map := λ X Y f, finsupp.single f 1, map_id' := λ X, rfl, map_comp' := λ X Y Z f g, by simp, } variables (R) {C} {D : Type u} [category.{v} D] [preadditive D] [linear R D] open preadditive linear /-- A functor to a preadditive category lifts to a functor from its `R`-linear completion. -/ @[simps] def lift (F : C ⥤ D) : Free R C ⥤ D := { obj := λ X, F.obj X, map := λ X Y f, f.sum (λ f' r, r • (F.map f')), map_id' := by { dsimp [category_theory.category_Free], simp }, map_comp' := λ X Y Z f g, begin apply finsupp.induction_linear f, { simp, }, { intros f₁ f₂ w₁ w₂, rw add_comp, rw [finsupp.sum_add_index, finsupp.sum_add_index], { simp [w₁, w₂, add_comp], }, { simp, }, { intros, simp only [add_smul], }, { simp, }, { intros, simp only [add_smul], }, }, { intros f' r, apply finsupp.induction_linear g, { simp, }, { intros f₁ f₂ w₁ w₂, rw comp_add, rw [finsupp.sum_add_index, finsupp.sum_add_index], { simp [w₁, w₂, add_comp], }, { simp, }, { intros, simp only [add_smul], }, { simp, }, { intros, simp only [add_smul], }, }, { intros g' s, erw single_comp_single, simp [mul_comm r s, mul_smul], } } end, } @[simp] lemma lift_map_single (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) (r : R) : (lift R F).map (single f r) = r • F.map f := by simp instance lift_additive (F : C ⥤ D) : (lift R F).additive := { map_zero' := by simp, map_add' := λ X Y f g, begin dsimp, rw finsupp.sum_add_index; simp [add_smul] end, } instance lift_linear (F : C ⥤ D) : (lift R F).linear R := { map_smul' := λ X Y f r, begin dsimp, rw finsupp.sum_smul_index; simp [finsupp.smul_sum, mul_smul], end, } /-- The embedding into the `R`-linear completion, followed by the lift, is isomorphic to the original functor. -/ def embedding_lift_iso (F : C ⥤ D) : embedding R C ⋙ lift R F ≅ F := nat_iso.of_components (λ X, iso.refl _) (by tidy) /-- Two `R`-linear functors out of the `R`-linear completion are isomorphic iff their compositions with the embedding functor are isomorphic. -/ @[ext] def ext {F G : Free R C ⥤ D} [F.additive] [F.linear R] [G.additive] [G.linear R] (α : embedding R C ⋙ F ≅ embedding R C ⋙ G) : F ≅ G := nat_iso.of_components (λ X, α.app X) begin intros X Y f, apply finsupp.induction_linear f, { simp, }, { intros f₁ f₂ w₁ w₂, simp only [F.map_add, G.map_add, add_comp, comp_add, w₁, w₂], }, { intros f' r, rw [iso.app_hom, iso.app_hom, ←smul_single_one, F.map_smul, G.map_smul, smul_comp, comp_smul], change r • (embedding R C ⋙ F).map f' ≫ _ = r • _ ≫ (embedding R C ⋙ G).map f', rw α.hom.naturality f', apply_instance, -- Why are these not picked up automatically when we rewrite? apply_instance, } end /-- `Free.lift` is unique amongst `R`-linear functors `Free R C ⥤ D` which compose with `embedding ℤ C` to give the original functor. -/ def lift_unique (F : C ⥤ D) (L : Free R C ⥤ D) [L.additive] [L.linear R] (α : embedding R C ⋙ L ≅ F) : L ≅ lift R F := ext R (α.trans (embedding_lift_iso R F).symm) end Free end category_theory
93df5bf8754922506b7f6217174b7c10ebc7a0af
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
/library/standard/logic/axioms/hilbert.lean
f45e15c0005f4fa708ce84ee2f223ecbd24c3d75
[ "Apache-2.0" ]
permissive
codyroux/lean
7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3
0cca265db19f7296531e339192e9b9bae4a31f8b
refs/heads/master
1,610,909,964,159
1,407,084,399,000
1,416,857,075,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,322
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 ---------------------------------------------------------------------------------------------------- import logic.classes.inhabited variable epsilon {A : Type} {H : inhabited A} (P : A → Prop) : A axiom epsilon_ax {A : Type} {P : A → Prop} (Hex : ∃ a, P a) : P (@epsilon A (inhabited_exists Hex) P) theorem epsilon_singleton {A : Type} (a : A) : @epsilon A (inhabited_intro a) (λ x, x = a) = a := epsilon_ax (exists_intro a (refl a)) theorem axiom_of_choice {A : Type} {B : A → Type} {R : Π x, B x → Prop} (H : ∀ x, ∃ y, R x y) : ∃ f, ∀ x, R x (f x) := let f [inline] := λ x, @epsilon _ (inhabited_exists (H x)) (λ y, R x y), H [inline] := take x, epsilon_ax (H x) in exists_intro f H theorem skolem {A : Type} {B : A → Type} {P : Π x, B x → Prop} : (∀ x, ∃ y, P x y) ↔ ∃ f, (∀ x, P x (f x)) := iff_intro (assume H : (∀ x, ∃ y, P x y), axiom_of_choice H) (assume H : (∃ f, (∀ x, P x (f x))), take x, obtain (fw : ∀ x, B x) (Hw : ∀ x, P x (fw x)), from H, exists_intro (fw x) (Hw x))
8dbb1d349909946eb973f1b3c7e90af674ba0fb2
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
/library/logic/eq.lean
75d0942766c1099ece5727ea791d273be65e1046
[ "Apache-2.0" ]
permissive
codyroux/lean
7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3
0cca265db19f7296531e339192e9b9bae4a31f8b
refs/heads/master
1,610,909,964,159
1,407,084,399,000
1,416,857,075,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
8,153
lean
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Leonardo de Moura, Jeremy Avigad, Floris van Doorn import general_notation logic.prop data.unit.decl -- logic.eq -- ==================== -- Equality. -- eq -- -- inductive eq {A : Type} (a : A) : A → Prop := refl : eq a a notation a = b := eq a b definition rfl {A : Type} {a : A} := eq.refl a -- proof irrelevance is built in theorem proof_irrel {a : Prop} (H₁ H₂ : a) : H₁ = H₂ := rfl namespace eq variables {A : Type} variables {a b c : A} theorem id_refl (H₁ : a = a) : H₁ = (eq.refl a) := rfl theorem irrel (H₁ H₂ : a = b) : H₁ = H₂ := !proof_irrel theorem subst {P : A → Prop} (H₁ : a = b) (H₂ : P a) : P b := rec H₂ H₁ theorem trans (H₁ : a = b) (H₂ : b = c) : a = c := subst H₂ H₁ theorem symm (H : a = b) : b = a := subst H (refl a) namespace ops notation H `⁻¹` := symm H --input with \sy or \-1 or \inv notation H1 ⬝ H2 := trans H1 H2 notation H1 ▸ H2 := subst H1 H2 end ops end eq calc_subst eq.subst calc_refl eq.refl calc_trans eq.trans calc_symm eq.symm open eq.ops namespace eq variables {A B : Type} {a a' a₁ a₂ a₃ a₄ : A} definition drec_on {B : Πa' : A, a = a' → Type} (H₁ : a = a') (H₂ : B a (refl a)) : B a' H₁ := eq.rec (λH₁ : a = a, show B a H₁, from H₂) H₁ H₁ --can we remove the theorems about drec_on and only have the rec_on versions? -- theorem drec_on_id {B : Πa' : A, a = a' → Type} (H : a = a) (b : B a H) : drec_on H b = b := -- rfl -- theorem drec_on_constant (H : a = a') {B : Type} (b : B) : drec_on H b = b := -- drec_on H rfl -- theorem drec_on_constant2 (H₁ : a₁ = a₂) (H₂ : a₃ = a₄) (b : B) : drec_on H₁ b = drec_on H₂ b := -- drec_on_constant H₁ b ⬝ (drec_on_constant H₂ b)⁻¹ -- theorem drec_on_irrel_arg {f : A → B} {D : B → Type} (H : a = a') (H' : f a = f a') -- (b : D (f a)) : drec_on H b = drec_on H' b := -- drec_on H (λ(H' : f a = f a), !drec_on_id⁻¹) H' -- theorem drec_on_irrel {D : A → Type} (H H' : a = a') (b : D a) : -- drec_on H b = drec_on H' b := -- !drec_on_irrel_arg -- theorem drec_on_compose {a b c : A} {P : A → Type} (H₁ : a = b) (H₂ : b = c) -- (u : P a) : drec_on H₂ (drec_on H₁ u) = drec_on (trans H₁ H₂) u := -- (show ∀ H₂ : b = c, drec_on H₂ (drec_on H₁ u) = drec_on (trans H₁ H₂) u, -- from drec_on H₂ (take (H₂ : b = b), drec_on_id H₂ _)) -- H₂ theorem rec_on_id {B : A → Type} (H : a = a) (b : B a) : rec_on H b = b := rfl theorem rec_on_constant (H : a = a') {B : Type} (b : B) : rec_on H b = b := drec_on H rfl theorem rec_on_constant2 (H₁ : a₁ = a₂) (H₂ : a₃ = a₄) (b : B) : rec_on H₁ b = rec_on H₂ b := rec_on_constant H₁ b ⬝ rec_on_constant H₂ b⁻¹ theorem rec_on_irrel_arg {f : A → B} {D : B → Type} (H : a = a') (H' : f a = f a') (b : D (f a)) : rec_on H b = rec_on H' b := drec_on H (λ(H' : f a = f a), !rec_on_id⁻¹) H' theorem rec_on_irrel {a a' : A} {D : A → Type} (H H' : a = a') (b : D a) : drec_on H b = drec_on H' b := !rec_on_irrel_arg --do we need the following? -- theorem rec_on_irrel_fun {B : A → Type} {a : A} {f f' : Π x, B x} {D : Π a, B a → Type} (H : f = f') (H' : f a = f' a) (b : D a (f a)) : -- rec_on H b = rec_on H' b := -- sorry -- the -- theorem rec_on_comm_ap {B : A → Type} {C : Πa, B a → Type} {a a' : A} {f : Π x, C a x} -- (H : a = a') (H' : a = a') (b : B a) : rec_on H f b = rec_on H' (f b) := -- sorry theorem rec_on_compose {a b c : A} {P : A → Type} (H₁ : a = b) (H₂ : b = c) (u : P a) : rec_on H₂ (rec_on H₁ u) = rec_on (trans H₁ H₂) u := (show ∀ H₂ : b = c, rec_on H₂ (rec_on H₁ u) = rec_on (trans H₁ H₂) u, from drec_on H₂ (take (H₂ : b = b), rec_on_id H₂ _)) H₂ end eq open eq section variables {A B C D E F : Type} variables {a a' : A} {b b' : B} {c c' : C} {d d' : D} {e e' : E} theorem congr_fun {B : A → Type} {f g : Π x, B x} (H : f = g) (a : A) : f a = g a := H ▸ rfl theorem congr_arg (f : A → B) (H : a = a') : f a = f a' := H ▸ rfl theorem congr {f g : A → B} (H₁ : f = g) (H₂ : a = a') : f a = g a' := H₁ ▸ H₂ ▸ rfl theorem congr_arg2 (f : A → B → C) (Ha : a = a') (Hb : b = b') : f a b = f a' b' := congr (congr_arg f Ha) Hb theorem congr_arg3 (f : A → B → C → D) (Ha : a = a') (Hb : b = b') (Hc : c = c') : f a b c = f a' b' c' := congr (congr_arg2 f Ha Hb) Hc theorem congr_arg4 (f : A → B → C → D → E) (Ha : a = a') (Hb : b = b') (Hc : c = c') (Hd : d = d') : f a b c d = f a' b' c' d' := congr (congr_arg3 f Ha Hb Hc) Hd theorem congr_arg5 (f : A → B → C → D → E → F) (Ha : a = a') (Hb : b = b') (Hc : c = c') (Hd : d = d') (He : e = e') : f a b c d e = f a' b' c' d' e' := congr (congr_arg4 f Ha Hb Hc Hd) He theorem congr2 (f f' : A → B → C) (Hf : f = f') (Ha : a = a') (Hb : b = b') : f a b = f' a' b' := Hf ▸ congr_arg2 f Ha Hb theorem congr3 (f f' : A → B → C → D) (Hf : f = f') (Ha : a = a') (Hb : b = b') (Hc : c = c') : f a b c = f' a' b' c' := Hf ▸ congr_arg3 f Ha Hb Hc theorem congr4 (f f' : A → B → C → D → E) (Hf : f = f') (Ha : a = a') (Hb : b = b') (Hc : c = c') (Hd : d = d') : f a b c d = f' a' b' c' d' := Hf ▸ congr_arg4 f Ha Hb Hc Hd theorem congr5 (f f' : A → B → C → D → E → F) (Hf : f = f') (Ha : a = a') (Hb : b = b') (Hc : c = c') (Hd : d = d') (He : e = e') : f a b c d e = f' a' b' c' d' e' := Hf ▸ congr_arg5 f Ha Hb Hc Hd He end theorem equal_f {A : Type} {B : A → Type} {f g : Π x, B x} (H : f = g) : ∀x, f x = g x := take x, congr_fun H x section variables {a b c : Prop} theorem eqmp (H₁ : a = b) (H₂ : a) : b := H₁ ▸ H₂ theorem eqmpr (H₁ : a = b) (H₂ : b) : a := H₁⁻¹ ▸ H₂ theorem eq_true_elim (H : a = true) : a := H⁻¹ ▸ trivial theorem eq_false_elim (H : a = false) : ¬a := assume Ha : a, H ▸ Ha theorem imp_trans (H₁ : a → b) (H₂ : b → c) : a → c := assume Ha, H₂ (H₁ Ha) theorem imp_eq_trans (H₁ : a → b) (H₂ : b = c) : a → c := assume Ha, H₂ ▸ (H₁ Ha) theorem eq_imp_trans (H₁ : a = b) (H₂ : b → c) : a → c := assume Ha, H₂ (H₁ ▸ Ha) end -- ne -- -- definition ne {A : Type} (a b : A) := ¬(a = b) notation a ≠ b := ne a b namespace ne variable {A : Type} variables {a b : A} theorem intro : (a = b → false) → a ≠ b := assume H, H theorem elim : a ≠ b → a = b → false := assume H₁ H₂, H₁ H₂ theorem irrefl : a ≠ a → false := assume H, H rfl theorem symm : a ≠ b → b ≠ a := assume (H : a ≠ b) (H₁ : b = a), H (H₁⁻¹) end ne section variables {A : Type} {a b c : A} theorem a_neq_a_elim : a ≠ a → false := assume H, H rfl theorem eq_ne_trans : a = b → b ≠ c → a ≠ c := assume H₁ H₂, H₁⁻¹ ▸ H₂ theorem ne_eq_trans : a ≠ b → b = c → a ≠ c := assume H₁ H₂, H₂ ▸ H₁ end calc_trans eq_ne_trans calc_trans ne_eq_trans section variables {p : Prop} theorem p_ne_false : p → p ≠ false := assume (Hp : p) (Heq : p = false), Heq ▸ Hp theorem p_ne_true : ¬p → p ≠ true := assume (Hnp : ¬p) (Heq : p = true), absurd trivial (Heq ▸ Hnp) end theorem true_ne_false : ¬true = false := assume H : true = false, H ▸ trivial inductive subsingleton [class] (A : Type) : Prop := intro : (∀ a b : A, a = b) -> subsingleton A namespace subsingleton definition elim {A : Type} {H : subsingleton A} : ∀(a b : A), a = b := rec (fun p, p) H end subsingleton protected definition prop.subsingleton [instance] (P : Prop) : subsingleton P := subsingleton.intro (λa b, !proof_irrel)
32d798cd0f422cd057f8853022ab03b3440787e5
d1a52c3f208fa42c41df8278c3d280f075eb020c
/stage0/src/Lean/Elab/Declaration.lean
fc17f88ef98d65bb7c8ed202dc0c84677f7ffd6f
[ "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
14,231
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Sebastian Ullrich -/ import Lean.Util.CollectLevelParams import Lean.Elab.DeclUtil import Lean.Elab.DefView import Lean.Elab.Inductive import Lean.Elab.Structure import Lean.Elab.MutualDef import Lean.Elab.DeclarationRange namespace Lean.Elab.Command open Meta /- Auxiliary function for `expandDeclNamespace?` -/ def expandDeclIdNamespace? (declId : Syntax) : Option (Name × Syntax) := let (id, optUnivDeclStx) := expandDeclIdCore declId let scpView := extractMacroScopes id match scpView.name with | Name.str Name.anonymous s _ => none | Name.str pre s _ => let nameNew := { scpView with name := Name.mkSimple s }.review if declId.isIdent then some (pre, mkIdentFrom declId nameNew) else some (pre, declId.setArg 0 (mkIdentFrom declId nameNew)) | _ => none /- given declarations such as `@[...] def Foo.Bla.f ...` return `some (Foo.Bla, @[...] def f ...)` -/ def expandDeclNamespace? (stx : Syntax) : Option (Name × Syntax) := if !stx.isOfKind `Lean.Parser.Command.declaration then none else let decl := stx[1] let k := decl.getKind if k == ``Lean.Parser.Command.abbrev || k == ``Lean.Parser.Command.def || k == ``Lean.Parser.Command.theorem || k == ``Lean.Parser.Command.constant || k == ``Lean.Parser.Command.axiom || k == ``Lean.Parser.Command.inductive || k == ``Lean.Parser.Command.classInductive || k == ``Lean.Parser.Command.structure then match expandDeclIdNamespace? decl[1] with | some (ns, declId) => some (ns, stx.setArg 1 (decl.setArg 1 declId)) | none => none else if k == ``Lean.Parser.Command.instance then let optDeclId := decl[3] if optDeclId.isNone then none else match expandDeclIdNamespace? optDeclId[0] with | some (ns, declId) => some (ns, stx.setArg 1 (decl.setArg 3 (optDeclId.setArg 0 declId))) | none => none else none def elabAxiom (modifiers : Modifiers) (stx : Syntax) : CommandElabM Unit := do -- leading_parser "axiom " >> declId >> declSig let declId := stx[1] let (binders, typeStx) := expandDeclSig stx[2] let scopeLevelNames ← getLevelNames let ⟨name, declName, allUserLevelNames⟩ ← expandDeclId declId modifiers addDeclarationRanges declName stx runTermElabM declName fun vars => Term.withLevelNames allUserLevelNames $ Term.elabBinders binders.getArgs fun xs => do Term.applyAttributesAt declName modifiers.attrs AttributeApplicationTime.beforeElaboration let type ← Term.elabType typeStx Term.synthesizeSyntheticMVarsNoPostponing let type ← instantiateMVars type let type ← mkForallFVars xs type let type ← mkForallFVars vars type (usedOnly := true) let (type, _) ← Term.levelMVarToParam type let usedParams := collectLevelParams {} type |>.params match sortDeclLevelParams scopeLevelNames allUserLevelNames usedParams with | Except.error msg => throwErrorAt stx msg | Except.ok levelParams => let decl := Declaration.axiomDecl { name := declName, levelParams := levelParams, type := type, isUnsafe := modifiers.isUnsafe } Term.ensureNoUnassignedMVars decl addDecl decl withSaveInfoContext do -- save new env Term.addTermInfo declId (← mkConstWithLevelParams declName) (isBinder := true) Term.applyAttributesAt declName modifiers.attrs AttributeApplicationTime.afterTypeChecking if isExtern (← getEnv) declName then compileDecl decl Term.applyAttributesAt declName modifiers.attrs AttributeApplicationTime.afterCompilation /- leading_parser "inductive " >> declId >> optDeclSig >> optional ":=" >> many ctor leading_parser atomic (group ("class " >> "inductive ")) >> declId >> optDeclSig >> optional ":=" >> many ctor >> optDeriving -/ private def inductiveSyntaxToView (modifiers : Modifiers) (decl : Syntax) : CommandElabM InductiveView := do checkValidInductiveModifier modifiers let (binders, type?) := expandOptDeclSig decl[2] let declId := decl[1] let ⟨name, declName, levelNames⟩ ← expandDeclId declId modifiers addDeclarationRanges declName decl let ctors ← decl[4].getArgs.mapM fun ctor => withRef ctor do -- def ctor := leading_parser " | " >> declModifiers >> ident >> optional inferMod >> optDeclSig let ctorModifiers ← elabModifiers ctor[1] if ctorModifiers.isPrivate && modifiers.isPrivate then throwError "invalid 'private' constructor in a 'private' inductive datatype" if ctorModifiers.isProtected && modifiers.isPrivate then throwError "invalid 'protected' constructor in a 'private' inductive datatype" checkValidCtorModifier ctorModifiers let ctorName := ctor.getIdAt 2 let ctorName := declName ++ ctorName let ctorName ← withRef ctor[2] $ applyVisibility ctorModifiers.visibility ctorName let inferMod := !ctor[3].isNone let (binders, type?) := expandOptDeclSig ctor[4] addDocString' ctorName ctorModifiers.docString? addAuxDeclarationRanges ctorName ctor ctor[2] pure { ref := ctor, modifiers := ctorModifiers, declName := ctorName, inferMod := inferMod, binders := binders, type? := type? : CtorView } let classes ← getOptDerivingClasses decl[5] pure { ref := decl modifiers := modifiers shortDeclName := name declName := declName levelNames := levelNames binders := binders type? := type? ctors := ctors derivingClasses := classes } private def classInductiveSyntaxToView (modifiers : Modifiers) (decl : Syntax) : CommandElabM InductiveView := inductiveSyntaxToView modifiers decl def elabInductive (modifiers : Modifiers) (stx : Syntax) : CommandElabM Unit := do let v ← inductiveSyntaxToView modifiers stx elabInductiveViews #[v] def elabClassInductive (modifiers : Modifiers) (stx : Syntax) : CommandElabM Unit := do let modifiers := modifiers.addAttribute { name := `class } let v ← classInductiveSyntaxToView modifiers stx elabInductiveViews #[v] def getTerminationHints (stx : Syntax) : TerminationHints := let decl := stx[1] let k := decl.getKind if k == ``Parser.Command.def || k == ``Parser.Command.theorem || k == ``Parser.Command.instance then let args := decl.getArgs { terminationBy? := args[args.size - 2].getOptional?, decreasingBy? := args[args.size - 1].getOptional? } else {} @[builtinCommandElab declaration] def elabDeclaration : CommandElab := fun stx => match expandDeclNamespace? stx with | some (ns, newStx) => do let ns := mkIdentFrom stx ns let newStx ← `(namespace $ns:ident $newStx end $ns:ident) withMacroExpansion stx newStx $ elabCommand newStx | none => do let modifiers ← elabModifiers stx[0] let decl := stx[1] let declKind := decl.getKind if declKind == ``Lean.Parser.Command.«axiom» then elabAxiom modifiers decl else if declKind == ``Lean.Parser.Command.«inductive» then elabInductive modifiers decl else if declKind == ``Lean.Parser.Command.classInductive then elabClassInductive modifiers decl else if declKind == ``Lean.Parser.Command.«structure» then elabStructure modifiers decl else if isDefLike decl then elabMutualDef #[stx] (getTerminationHints stx) else throwError "unexpected declaration" /- Return true if all elements of the mutual-block are inductive declarations. -/ private def isMutualInductive (stx : Syntax) : Bool := stx[1].getArgs.all fun elem => let decl := elem[1] let declKind := decl.getKind declKind == `Lean.Parser.Command.inductive private def elabMutualInductive (elems : Array Syntax) : CommandElabM Unit := do let views ← elems.mapM fun stx => do let modifiers ← elabModifiers stx[0] inductiveSyntaxToView modifiers stx[1] elabInductiveViews views /- Return true if all elements of the mutual-block are definitions/theorems/abbrevs. -/ private def isMutualDef (stx : Syntax) : Bool := stx[1].getArgs.all fun elem => let decl := elem[1] isDefLike decl private def isMutualPreambleCommand (stx : Syntax) : Bool := let k := stx.getKind k == ``Lean.Parser.Command.variable || k == ``Lean.Parser.Command.universe || k == ``Lean.Parser.Command.check || k == ``Lean.Parser.Command.set_option || k == ``Lean.Parser.Command.open private partial def splitMutualPreamble (elems : Array Syntax) : Option (Array Syntax × Array Syntax) := let rec loop (i : Nat) : Option (Array Syntax × Array Syntax) := if h : i < elems.size then let elem := elems.get ⟨i, h⟩ if isMutualPreambleCommand elem then loop (i+1) else if i == 0 then none -- `mutual` block does not contain any preamble commands else some (elems[0:i], elems[i:elems.size]) else none -- a `mutual` block containing only preamble commands is not a valid `mutual` block loop 0 @[builtinMacro Lean.Parser.Command.mutual] def expandMutualNamespace : Macro := fun stx => do let mut ns? := none let mut elemsNew := #[] for elem in stx[1].getArgs do match ns?, expandDeclNamespace? elem with | _, none => elemsNew := elemsNew.push elem | none, some (ns, elem) => ns? := some ns; elemsNew := elemsNew.push elem | some nsCurr, some (nsNew, elem) => if nsCurr == nsNew then elemsNew := elemsNew.push elem else Macro.throwErrorAt elem s!"conflicting namespaces in mutual declaration, using namespace '{nsNew}', but used '{nsCurr}' in previous declaration" match ns? with | some ns => let ns := mkIdentFrom stx ns let stxNew := stx.setArg 1 (mkNullNode elemsNew) `(namespace $ns:ident $stxNew end $ns:ident) | none => Macro.throwUnsupported @[builtinMacro Lean.Parser.Command.mutual] def expandMutualElement : Macro := fun stx => do let mut elemsNew := #[] let mut modified := false for elem in stx[1].getArgs do match (← expandMacro? elem) with | some elemNew => elemsNew := elemsNew.push elemNew; modified := true | none => elemsNew := elemsNew.push elem if modified then pure $ stx.setArg 1 (mkNullNode elemsNew) else Macro.throwUnsupported @[builtinMacro Lean.Parser.Command.mutual] def expandMutualPreamble : Macro := fun stx => match splitMutualPreamble stx[1].getArgs with | none => Macro.throwUnsupported | some (preamble, rest) => do let secCmd ← `(section) let newMutual := stx.setArg 1 (mkNullNode rest) let endCmd ← `(end) pure $ mkNullNode (#[secCmd] ++ preamble ++ #[newMutual] ++ #[endCmd]) @[builtinCommandElab «mutual»] def elabMutual : CommandElab := fun stx => do let hints := { terminationBy? := stx[3].getOptional?, decreasingBy? := stx[4].getOptional? } if isMutualInductive stx then if let some bad := hints.terminationBy? then throwErrorAt bad "invalid 'termination_by' in mutually inductive datatype declaration" if let some bad := hints.decreasingBy? then throwErrorAt bad "invalid 'decreasing_by' in mutually inductive datatype declaration" elabMutualInductive stx[1].getArgs else if isMutualDef stx then for arg in stx[1].getArgs do let argHints := getTerminationHints arg if let some bad := argHints.terminationBy? then throwErrorAt bad "invalid 'termination_by' in 'mutual' block, it must be used after the 'end' keyword" if let some bad := argHints.decreasingBy? then throwErrorAt bad "invalid 'decreasing_by' in 'mutual' block, it must be used after the 'end' keyword" elabMutualDef stx[1].getArgs hints else throwError "invalid mutual block" /- leading_parser "attribute " >> "[" >> sepBy1 (eraseAttr <|> Term.attrInstance) ", " >> "]" >> many1 ident -/ @[builtinCommandElab «attribute»] def elabAttr : CommandElab := fun stx => do let mut attrInsts := #[] let mut toErase := #[] for attrKindStx in stx[2].getSepArgs do if attrKindStx.getKind == ``Lean.Parser.Command.eraseAttr then let attrName := attrKindStx[1].getId.eraseMacroScopes unless isAttribute (← getEnv) attrName do throwError "unknown attribute [{attrName}]" toErase := toErase.push attrName else attrInsts := attrInsts.push attrKindStx let attrs ← elabAttrs attrInsts let idents := stx[4].getArgs for ident in idents do withRef ident <| liftTermElabM none do let declName ← resolveGlobalConstNoOverloadWithInfo ident Term.applyAttributes declName attrs for attrName in toErase do Attribute.erase declName attrName def expandInitCmd (builtin : Bool) : Macro := fun stx => do let optVisibility := stx[0] let optHeader := stx[2] let doSeq := stx[3] let attrId := mkIdentFrom stx $ if builtin then `builtinInit else `init if optHeader.isNone then unless optVisibility.isNone do Macro.throwError "invalid initialization command, 'visibility' modifer is not allowed" `(@[$attrId:ident]def initFn : IO Unit := do $doSeq) else let id := optHeader[0] let type := optHeader[1][1] if optVisibility.isNone then `(def initFn : IO $type := do $doSeq @[$attrId:ident initFn] constant $id : $type) else if optVisibility[0].getKind == ``Parser.Command.private then `(def initFn : IO $type := do $doSeq @[$attrId:ident initFn] private constant $id : $type) else if optVisibility[0].getKind == ``Parser.Command.protected then `(def initFn : IO $type := do $doSeq @[$attrId:ident initFn] protected constant $id : $type) else Macro.throwError "unexpected visibility annotation" @[builtinMacro Lean.Parser.Command.«initialize»] def expandInitialize : Macro := expandInitCmd (builtin := false) @[builtinMacro Lean.Parser.Command.«builtin_initialize»] def expandBuiltinInitialize : Macro := expandInitCmd (builtin := true) end Lean.Elab.Command
7c95f6d718456d16d576d42ab71726a8361df7fa
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/data/set_like/fintype.lean
d1bb48f11a7834c72d8f4d8badf5e98d4202bfed
[ "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
1,024
lean
/- Copyright (c) 2021 . All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import data.set_like.basic import data.fintype.powerset /-! # Set-like fintype > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file contains a fintype instance for set-like objects such as subgroups. If `set_like A B` and `fintype B` then `fintype A`. -/ namespace set_like /-- TODO: It should be possible to obtain a computable version of this for most set_like objects. If we add those instances, we should remove this one. -/ @[nolint dangerous_instance, instance, priority 100] noncomputable instance {A B : Type*} [fintype B] [set_like A B] : fintype A := fintype.of_injective coe set_like.coe_injective @[nolint dangerous_instance, priority 100] -- See note [lower instance priority] instance {A B : Type*} [finite B] [set_like A B] : finite A := finite.of_injective coe set_like.coe_injective end set_like
f75a5a16ae0052ff8e3860af264420932150318d
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
/src/data/complex/module.lean
de44dd1a81360b80f995c4c281fbff1c51a448b6
[ "Apache-2.0" ]
permissive
waynemunro/mathlib
e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552
065a70810b5480d584033f7bbf8e0409480c2118
refs/heads/master
1,693,417,182,397
1,634,644,781,000
1,634,644,781,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
10,480
lean
/- Copyright (c) 2020 Alexander Bentkamp, Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Sébastien Gouëzel, Eric Wieser -/ import algebra.module.ordered import data.complex.basic import data.matrix.notation import field_theory.tower /-! # Complex number as a vector space over `ℝ` This file contains the following instances: * Any `•`-structure (`has_scalar`, `mul_action`, `distrib_mul_action`, `module`, `algebra`) on `ℝ` imbues a corresponding structure on `ℂ`. This includes the statement that `ℂ` is an `ℝ` algebra. * any complex vector space is a real vector space; * any finite dimensional complex vector space is a finite dimensional real vector space; * the space of `ℝ`-linear maps from a real vector space to a complex vector space is a complex vector space. It also defines bundled versions of four standard maps (respectively, the real part, the imaginary part, the embedding of `ℝ` in `ℂ`, and the complex conjugate): * `complex.re_lm` (`ℝ`-linear map); * `complex.im_lm` (`ℝ`-linear map); * `complex.of_real_am` (`ℝ`-algebra (homo)morphism); * `complex.conj_ae` (`ℝ`-algebra equivalence). It also provides a universal property of the complex numbers `complex.lift`, which constructs a `ℂ →ₐ[ℝ] A` into any `ℝ`-algebra `A` given a square root of `-1`. -/ namespace complex variables {R : Type*} {S : Type*} section variables [has_scalar R ℝ] /- The useless `0` multiplication in `smul` is to make sure that `restrict_scalars.module ℝ ℂ ℂ = complex.module` definitionally. -/ instance : has_scalar R ℂ := { smul := λ r x, ⟨r • x.re - 0 * x.im, r • x.im + 0 * x.re⟩ } lemma smul_re (r : R) (z : ℂ) : (r • z).re = r • z.re := by simp [(•)] lemma smul_im (r : R) (z : ℂ) : (r • z).im = r • z.im := by simp [(•)] @[simp] lemma real_smul {x : ℝ} {z : ℂ} : x • z = x * z := rfl end instance [has_scalar R ℝ] [has_scalar S ℝ] [smul_comm_class R S ℝ] : smul_comm_class R S ℂ := { smul_comm := λ r s x, by ext; simp [smul_re, smul_im, smul_comm] } instance [has_scalar R S] [has_scalar R ℝ] [has_scalar S ℝ] [is_scalar_tower R S ℝ] : is_scalar_tower R S ℂ := { smul_assoc := λ r s x, by ext; simp [smul_re, smul_im, smul_assoc] } instance [monoid R] [mul_action R ℝ] : mul_action R ℂ := { one_smul := λ x, by ext; simp [smul_re, smul_im, one_smul], mul_smul := λ r s x, by ext; simp [smul_re, smul_im, mul_smul] } instance [semiring R] [distrib_mul_action R ℝ] : distrib_mul_action R ℂ := { smul_add := λ r x y, by ext; simp [smul_re, smul_im, smul_add], smul_zero := λ r, by ext; simp [smul_re, smul_im, smul_zero] } instance [semiring R] [module R ℝ] : module R ℂ := { add_smul := λ r s x, by ext; simp [smul_re, smul_im, add_smul], zero_smul := λ r, by ext; simp [smul_re, smul_im, zero_smul] } instance [comm_semiring R] [algebra R ℝ] : algebra R ℂ := { smul := (•), smul_def' := λ r x, by ext; simp [smul_re, smul_im, algebra.smul_def], commutes' := λ r ⟨xr, xi⟩, by ext; simp [smul_re, smul_im, algebra.commutes], ..complex.of_real.comp (algebra_map R ℝ) } @[simp] lemma coe_algebra_map : (algebra_map ℝ ℂ : ℝ → ℂ) = coe := rfl section variables {A : Type*} [semiring A] [algebra ℝ A] /-- We need this lemma since `complex.coe_algebra_map` diverts the simp-normal form away from `alg_hom.commutes`. -/ @[simp] lemma _root_.alg_hom.map_coe_real_complex (f : ℂ →ₐ[ℝ] A) (x : ℝ) : f x = algebra_map ℝ A x := f.commutes x /-- Two `ℝ`-algebra homomorphisms from ℂ are equal if they agree on `complex.I`. -/ @[ext] lemma alg_hom_ext ⦃f g : ℂ →ₐ[ℝ] A⦄ (h : f I = g I) : f = g := begin ext ⟨x, y⟩, simp only [mk_eq_add_mul_I, alg_hom.map_add, alg_hom.map_coe_real_complex, alg_hom.map_mul, h] end end section open_locale complex_order protected lemma ordered_smul : ordered_smul ℝ ℂ := ordered_smul.mk' $ λ a b r hab hr, ⟨by simp [hr, hab.1.le], by simp [hab.2]⟩ localized "attribute [instance] complex.ordered_smul" in complex_order end open submodule finite_dimensional /-- `ℂ` has a basis over `ℝ` given by `1` and `I`. -/ noncomputable def basis_one_I : basis (fin 2) ℝ ℂ := basis.of_equiv_fun { to_fun := λ z, ![z.re, z.im], inv_fun := λ c, c 0 + c 1 • I, left_inv := λ z, by simp, right_inv := λ c, by { ext i, fin_cases i; simp }, map_add' := λ z z', by simp, map_smul' := λ c z, by simp } @[simp] lemma coe_basis_one_I_repr (z : ℂ) : ⇑(basis_one_I.repr z) = ![z.re, z.im] := rfl @[simp] lemma coe_basis_one_I : ⇑basis_one_I = ![1, I] := funext $ λ i, basis.apply_eq_iff.mpr $ finsupp.ext $ λ j, by fin_cases i; fin_cases j; simp only [coe_basis_one_I_repr, finsupp.single_eq_same, finsupp.single_eq_of_ne, matrix.cons_val_zero, matrix.cons_val_one, matrix.head_cons, nat.one_ne_zero, fin.one_eq_zero_iff, fin.zero_eq_one_iff, ne.def, not_false_iff, one_re, one_im, I_re, I_im] instance : finite_dimensional ℝ ℂ := of_fintype_basis basis_one_I @[simp] lemma finrank_real_complex : finite_dimensional.finrank ℝ ℂ = 2 := by rw [finrank_eq_card_basis basis_one_I, fintype.card_fin] @[simp] lemma dim_real_complex : module.rank ℝ ℂ = 2 := by simp [← finrank_eq_dim, finrank_real_complex] lemma {u} dim_real_complex' : cardinal.lift.{u} (module.rank ℝ ℂ) = 2 := by simp [← finrank_eq_dim, finrank_real_complex, bit0] /-- `fact` version of the dimension of `ℂ` over `ℝ`, locally useful in the definition of the circle. -/ lemma finrank_real_complex_fact : fact (finrank ℝ ℂ = 2) := ⟨finrank_real_complex⟩ end complex /- Register as an instance (with low priority) the fact that a complex vector space is also a real vector space. -/ @[priority 900] instance module.complex_to_real (E : Type*) [add_comm_group E] [module ℂ E] : module ℝ E := restrict_scalars.module ℝ ℂ E instance module.real_complex_tower (E : Type*) [add_comm_group E] [module ℂ E] : is_scalar_tower ℝ ℂ E := restrict_scalars.is_scalar_tower ℝ ℂ E @[simp, norm_cast] lemma complex.coe_smul {E : Type*} [add_comm_group E] [module ℂ E] (x : ℝ) (y : E) : (x : ℂ) • y = x • y := rfl @[priority 100] instance finite_dimensional.complex_to_real (E : Type*) [add_comm_group E] [module ℂ E] [finite_dimensional ℂ E] : finite_dimensional ℝ E := finite_dimensional.trans ℝ ℂ E lemma dim_real_of_complex (E : Type*) [add_comm_group E] [module ℂ E] : module.rank ℝ E = 2 * module.rank ℂ E := cardinal.lift_inj.1 $ by { rw [← dim_mul_dim' ℝ ℂ E, complex.dim_real_complex], simp [bit0] } lemma finrank_real_of_complex (E : Type*) [add_comm_group E] [module ℂ E] : finite_dimensional.finrank ℝ E = 2 * finite_dimensional.finrank ℂ E := by rw [← finite_dimensional.finrank_mul_finrank ℝ ℂ E, complex.finrank_real_complex] namespace complex /-- Linear map version of the real part function, from `ℂ` to `ℝ`. -/ def re_lm : ℂ →ₗ[ℝ] ℝ := { to_fun := λx, x.re, map_add' := add_re, map_smul' := by simp, } @[simp] lemma re_lm_coe : ⇑re_lm = re := rfl /-- Linear map version of the imaginary part function, from `ℂ` to `ℝ`. -/ def im_lm : ℂ →ₗ[ℝ] ℝ := { to_fun := λx, x.im, map_add' := add_im, map_smul' := by simp, } @[simp] lemma im_lm_coe : ⇑im_lm = im := rfl /-- `ℝ`-algebra morphism version of the canonical embedding of `ℝ` in `ℂ`. -/ def of_real_am : ℝ →ₐ[ℝ] ℂ := algebra.of_id ℝ ℂ @[simp] lemma of_real_am_coe : ⇑of_real_am = coe := rfl /-- `ℝ`-algebra isomorphism version of the complex conjugation function from `ℂ` to `ℂ` -/ def conj_ae : ℂ ≃ₐ[ℝ] ℂ := { inv_fun := conj, left_inv := conj_conj, right_inv := conj_conj, commutes' := conj_of_real, .. conj } @[simp] lemma conj_ae_coe : ⇑conj_ae = conj := rfl section lift variables {A : Type*} [ring A] [algebra ℝ A] /-- There is an alg_hom from `ℂ` to any `ℝ`-algebra with an element that squares to `-1`. See `complex.lift` for this as an equiv. -/ def lift_aux (I' : A) (hf : I' * I' = -1) : ℂ →ₐ[ℝ] A := alg_hom.of_linear_map ((algebra.of_id ℝ A).to_linear_map.comp re_lm + (linear_map.to_span_singleton _ _ I').comp im_lm) (show algebra_map ℝ A 1 + (0 : ℝ) • I' = 1, by rw [ring_hom.map_one, zero_smul, add_zero]) (λ ⟨x₁, y₁⟩ ⟨x₂, y₂⟩, show algebra_map ℝ A (x₁ * x₂ - y₁ * y₂) + (x₁ * y₂ + y₁ * x₂) • I' = (algebra_map ℝ A x₁ + y₁ • I') * (algebra_map ℝ A x₂ + y₂ • I'), begin rw [add_mul, mul_add, mul_add, add_comm _ (y₁ • I' * y₂ • I'), add_add_add_comm], congr' 1, -- equate "real" and "imaginary" parts { rw [smul_mul_smul, hf, smul_neg, ←algebra.algebra_map_eq_smul_one, ←sub_eq_add_neg, ←ring_hom.map_mul, ←ring_hom.map_sub], }, { rw [algebra.smul_def, algebra.smul_def, algebra.smul_def, ←algebra.right_comm _ x₂, ←mul_assoc, ←add_mul, ←ring_hom.map_mul, ←ring_hom.map_mul, ←ring_hom.map_add] } end) @[simp] lemma lift_aux_apply (I' : A) (hI') (z : ℂ) : lift_aux I' hI' z = algebra_map ℝ A z.re + z.im • I' := rfl lemma lift_aux_apply_I (I' : A) (hI') : lift_aux I' hI' I = I' := by simp /-- A universal property of the complex numbers, providing a unique `ℂ →ₐ[ℝ] A` for every element of `A` which squares to `-1`. This can be used to embed the complex numbers in the `quaternion`s. This isomorphism is named to match the very similar `zsqrtd.lift`. -/ @[simps {simp_rhs := tt}] def lift : {I' : A // I' * I' = -1} ≃ (ℂ →ₐ[ℝ] A) := { to_fun := λ I', lift_aux I' I'.prop, inv_fun := λ F, ⟨F I, by rw [←F.map_mul, I_mul_I, alg_hom.map_neg, alg_hom.map_one]⟩, left_inv := λ I', subtype.ext $ lift_aux_apply_I I' I'.prop, right_inv := λ F, alg_hom_ext $ lift_aux_apply_I _ _, } /- When applied to `complex.I` itself, `lift` is the identity. -/ @[simp] lemma lift_aux_I : lift_aux I I_mul_I = alg_hom.id ℝ ℂ := alg_hom_ext $ lift_aux_apply_I _ _ /- When applied to `-complex.I`, `lift` is conjugation, `conj`. -/ @[simp] lemma lift_aux_neg_I : lift_aux (-I) ((neg_mul_neg _ _).trans I_mul_I) = conj_ae := alg_hom_ext $ (lift_aux_apply_I _ _).trans conj_I.symm end lift end complex
606e8f204dccccf45accf5acdb8902928d788d04
94e33a31faa76775069b071adea97e86e218a8ee
/src/analysis/calculus/fderiv.lean
f254914e4ec078160301fb73afb84d019d014f94
[ "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
135,587
lean
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import analysis.asymptotics.asymptotic_equivalent import analysis.calculus.tangent_cone import analysis.normed_space.bounded_linear_maps import analysis.normed_space.units /-! # The Fréchet derivative Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then `has_fderiv_within_at f f' s x` says that `f` has derivative `f'` at `x`, where the domain of interest is restricted to `s`. We also have `has_fderiv_at f f' x := has_fderiv_within_at f f' x univ` Finally, `has_strict_fderiv_at f f' x` means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability, i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse function theorem, and is defined here only to avoid proving theorems like `is_bounded_bilinear_map.has_fderiv_at` twice: first for `has_fderiv_at`, then for `has_strict_fderiv_at`. ## Main results In addition to the definition and basic properties of the derivative, this file contains the usual formulas (and existence assertions) for the derivative of * constants * the identity * bounded linear maps * bounded bilinear maps * sum of two functions * sum of finitely many functions * multiplication of a function by a scalar constant * negative of a function * subtraction of two functions * multiplication of a function by a scalar function * multiplication of two scalar functions * composition of functions (the chain rule) * inverse function (assuming that it exists; the inverse function theorem is in `inverse.lean`) For most binary operations we also define `const_op` and `op_const` theorems for the cases when the first or second argument is a constant. This makes writing chains of `has_deriv_at`'s easier, and they more frequently lead to the desired result. One can also interpret the derivative of a function `f : 𝕜 → E` as an element of `E` (by identifying a linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet derivative are translated to this more elementary point of view on the derivative in the file `deriv.lean`. The derivative of polynomials is handled there, as it is naturally one-dimensional. The simplifier is set up to prove automatically that some functions are differentiable, or differentiable at a point (but not differentiable on a set or within a set at a point, as checking automatically that the good domains are mapped one to the other when using composition is not something the simplifier can easily do). This means that one can write `example (x : ℝ) : differentiable ℝ (λ x, sin (exp (3 + x^2)) - 5 * cos x) := by simp`. If there are divisions, one needs to supply to the simplifier proofs that the denominators do not vanish, as in ```lean example (x : ℝ) (h : 1 + sin x ≠ 0) : differentiable_at ℝ (λ x, exp x / (1 + sin x)) x := by simp [h] ``` Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be differentiable, in `analysis.special_functions.trigonometric`. The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general complicated multidimensional linear maps), but it will compute one-dimensional derivatives, see `deriv.lean`. ## Implementation details The derivative is defined in terms of the `is_o` relation, but also characterized in terms of the `tendsto` relation. We also introduce predicates `differentiable_within_at 𝕜 f s x` (where `𝕜` is the base field, `f` the function to be differentiated, `x` the point at which the derivative is asserted to exist, and `s` the set along which the derivative is defined), as well as `differentiable_at 𝕜 f x`, `differentiable_on 𝕜 f s` and `differentiable 𝕜 f` to express the existence of a derivative. To be able to compute with derivatives, we write `fderiv_within 𝕜 f s x` and `fderiv 𝕜 f x` for some choice of a derivative if it exists, and the zero function otherwise. This choice only behaves well along sets for which the derivative is unique, i.e., those for which the tangent directions span a dense subset of the whole space. The predicates `unique_diff_within_at s x` and `unique_diff_on s`, defined in `tangent_cone.lean` express this property. We prove that indeed they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever. To make sure that the simplifier can prove automatically that functions are differentiable, we tag many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable functions is differentiable, as well as their product, their cartesian product, and so on. A notable exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are differentiable, then their composition also is: `simp` would always be able to match this lemma, by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`), we add a lemma that if `f` is differentiable then so is `(λ x, exp (f x))`. This means adding some boilerplate lemmas, but these can also be useful in their own right. Tests for this ability of the simplifier (with more examples) are provided in `tests/differentiable.lean`. ## Tags derivative, differentiable, Fréchet, calculus -/ open filter asymptotics continuous_linear_map set metric open_locale topological_space classical nnreal filter asymptotics ennreal noncomputable theory section variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] variables {E : Type*} [normed_group E] [normed_space 𝕜 E] variables {F : Type*} [normed_group F] [normed_space 𝕜 F] variables {G : Type*} [normed_group G] [normed_space 𝕜 G] variables {G' : Type*} [normed_group G'] [normed_space 𝕜 G'] /-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition is designed to be specialized for `L = 𝓝 x` (in `has_fderiv_at`), giving rise to the usual notion of Fréchet derivative, and for `L = 𝓝[s] x` (in `has_fderiv_within_at`), giving rise to the notion of Fréchet derivative along the set `s`. -/ def has_fderiv_at_filter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : filter E) := (λ x', f x' - f x - f' (x' - x)) =o[L] (λ x', x' - x) /-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/ def has_fderiv_within_at (f : E → F) (f' : E →L[𝕜] F) (s : set E) (x : E) := has_fderiv_at_filter f f' x (𝓝[s] x) /-- A function `f` has the continuous linear map `f'` as derivative at `x` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/ def has_fderiv_at (f : E → F) (f' : E →L[𝕜] F) (x : E) := has_fderiv_at_filter f f' x (𝓝 x) /-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability* if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required, e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/ def has_strict_fderiv_at (f : E → F) (f' : E →L[𝕜] F) (x : E) := (λ p : E × E, f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝓝 (x, x)] (λ p : E × E, p.1 - p.2) variables (𝕜) /-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative there (possibly non-unique). -/ def differentiable_within_at (f : E → F) (s : set E) (x : E) := ∃f' : E →L[𝕜] F, has_fderiv_within_at f f' s x /-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly non-unique). -/ def differentiable_at (f : E → F) (x : E) := ∃f' : E →L[𝕜] F, has_fderiv_at f f' x /-- If `f` has a derivative at `x` within `s`, then `fderiv_within 𝕜 f s x` is such a derivative. Otherwise, it is set to `0`. -/ def fderiv_within (f : E → F) (s : set E) (x : E) : E →L[𝕜] F := if h : ∃f', has_fderiv_within_at f f' s x then classical.some h else 0 /-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is set to `0`. -/ def fderiv (f : E → F) (x : E) : E →L[𝕜] F := if h : ∃f', has_fderiv_at f f' x then classical.some h else 0 /-- `differentiable_on 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/ def differentiable_on (f : E → F) (s : set E) := ∀x ∈ s, differentiable_within_at 𝕜 f s x /-- `differentiable 𝕜 f` means that `f` is differentiable at any point. -/ def differentiable (f : E → F) := ∀x, differentiable_at 𝕜 f x variables {𝕜} variables {f f₀ f₁ g : E → F} variables {f' f₀' f₁' g' : E →L[𝕜] F} variables (e : E →L[𝕜] F) variables {x : E} variables {s t : set E} variables {L L₁ L₂ : filter E} lemma fderiv_within_zero_of_not_differentiable_within_at (h : ¬ differentiable_within_at 𝕜 f s x) : fderiv_within 𝕜 f s x = 0 := have ¬ ∃ f', has_fderiv_within_at f f' s x, from h, by simp [fderiv_within, this] lemma fderiv_zero_of_not_differentiable_at (h : ¬ differentiable_at 𝕜 f x) : fderiv 𝕜 f x = 0 := have ¬ ∃ f', has_fderiv_at f f' x, from h, by simp [fderiv, this] section derivative_uniqueness /- In this section, we discuss the uniqueness of the derivative. We prove that the definitions `unique_diff_within_at` and `unique_diff_on` indeed imply the uniqueness of the derivative. -/ /-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f', i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses this fact, for functions having a derivative within a set. Its specific formulation is useful for tangent cone related discussions. -/ theorem has_fderiv_within_at.lim (h : has_fderiv_within_at f f' s x) {α : Type*} (l : filter α) {c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s) (clim : tendsto (λ n, ∥c n∥) l at_top) (cdlim : tendsto (λ n, c n • d n) l (𝓝 v)) : tendsto (λn, c n • (f (x + d n) - f x)) l (𝓝 (f' v)) := begin have tendsto_arg : tendsto (λ n, x + d n) l (𝓝[s] x), { conv in (𝓝[s] x) { rw ← add_zero x }, rw [nhds_within, tendsto_inf], split, { apply tendsto_const_nhds.add (tangent_cone_at.lim_zero l clim cdlim) }, { rwa tendsto_principal } }, have : (λ y, f y - f x - f' (y - x)) =o[𝓝[s] x] (λ y, y - x) := h, have : (λ n, f (x + d n) - f x - f' ((x + d n) - x)) =o[l] (λ n, (x + d n) - x) := this.comp_tendsto tendsto_arg, have : (λ n, f (x + d n) - f x - f' (d n)) =o[l] d := by simpa only [add_sub_cancel'], have : (λ n, c n • (f (x + d n) - f x - f' (d n))) =o[l] (λ n, c n • d n) := (is_O_refl c l).smul_is_o this, have : (λ n, c n • (f (x + d n) - f x - f' (d n))) =o[l] (λ n, (1:ℝ)) := this.trans_is_O (cdlim.is_O_one ℝ), have L1 : tendsto (λn, c n • (f (x + d n) - f x - f' (d n))) l (𝓝 0) := (is_o_one_iff ℝ).1 this, have L2 : tendsto (λn, f' (c n • d n)) l (𝓝 (f' v)) := tendsto.comp f'.cont.continuous_at cdlim, have L3 : tendsto (λn, (c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n))) l (𝓝 (0 + f' v)) := L1.add L2, have : (λn, (c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n))) = (λn, c n • (f (x + d n) - f x)), by { ext n, simp [smul_add, smul_sub] }, rwa [this, zero_add] at L3 end /-- If `f'` and `f₁'` are two derivatives of `f` within `s` at `x`, then they are equal on the tangent cone to `s` at `x` -/ theorem has_fderiv_within_at.unique_on (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at f f₁' s x) : eq_on f' f₁' (tangent_cone_at 𝕜 s x) := λ y ⟨c, d, dtop, clim, cdlim⟩, tendsto_nhds_unique (hf.lim at_top dtop clim cdlim) (hg.lim at_top dtop clim cdlim) /-- `unique_diff_within_at` achieves its goal: it implies the uniqueness of the derivative. -/ theorem unique_diff_within_at.eq (H : unique_diff_within_at 𝕜 s x) (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at f f₁' s x) : f' = f₁' := continuous_linear_map.ext_on H.1 (hf.unique_on hg) theorem unique_diff_on.eq (H : unique_diff_on 𝕜 s) (hx : x ∈ s) (h : has_fderiv_within_at f f' s x) (h₁ : has_fderiv_within_at f f₁' s x) : f' = f₁' := (H x hx).eq h h₁ end derivative_uniqueness section fderiv_properties /-! ### Basic properties of the derivative -/ theorem has_fderiv_at_filter_iff_tendsto : has_fderiv_at_filter f f' x L ↔ tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) L (𝓝 0) := have h : ∀ x', ∥x' - x∥ = 0 → ∥f x' - f x - f' (x' - x)∥ = 0, from λ x' hx', by { rw [sub_eq_zero.1 (norm_eq_zero.1 hx')], simp }, begin unfold has_fderiv_at_filter, rw [←is_o_norm_left, ←is_o_norm_right, is_o_iff_tendsto h], exact tendsto_congr (λ _, div_eq_inv_mul _ _), end theorem has_fderiv_within_at_iff_tendsto : has_fderiv_within_at f f' s x ↔ tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) (𝓝[s] x) (𝓝 0) := has_fderiv_at_filter_iff_tendsto theorem has_fderiv_at_iff_tendsto : has_fderiv_at f f' x ↔ tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) (𝓝 x) (𝓝 0) := has_fderiv_at_filter_iff_tendsto theorem has_fderiv_at_iff_is_o_nhds_zero : has_fderiv_at f f' x ↔ (λ h : E, f (x + h) - f x - f' h) =o[𝓝 0] (λh, h) := begin rw [has_fderiv_at, has_fderiv_at_filter, ← map_add_left_nhds_zero x, is_o_map], simp [(∘)] end /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`. This version only assumes that `∥f x - f x₀∥ ≤ C * ∥x - x₀∥` in a neighborhood of `x`. -/ lemma has_fderiv_at.le_of_lip' {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : has_fderiv_at f f' x₀) {C : ℝ} (hC₀ : 0 ≤ C) (hlip : ∀ᶠ x in 𝓝 x₀, ∥f x - f x₀∥ ≤ C * ∥x - x₀∥) : ∥f'∥ ≤ C := begin refine le_of_forall_pos_le_add (λ ε ε0, op_norm_le_of_nhds_zero _ _), exact add_nonneg hC₀ ε0.le, rw [← map_add_left_nhds_zero x₀, eventually_map] at hlip, filter_upwards [is_o_iff.1 (has_fderiv_at_iff_is_o_nhds_zero.1 hf) ε0, hlip] with y hy hyC, rw add_sub_cancel' at hyC, calc ∥f' y∥ ≤ ∥f (x₀ + y) - f x₀∥ + ∥f (x₀ + y) - f x₀ - f' y∥ : norm_le_insert _ _ ... ≤ C * ∥y∥ + ε * ∥y∥ : add_le_add hyC hy ... = (C + ε) * ∥y∥ : (add_mul _ _ _).symm end /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`. -/ lemma has_fderiv_at.le_of_lip {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : has_fderiv_at f f' x₀) {s : set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : lipschitz_on_with C f s) : ∥f'∥ ≤ C := begin refine hf.le_of_lip' C.coe_nonneg _, filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs), end theorem has_fderiv_at_filter.mono (h : has_fderiv_at_filter f f' x L₂) (hst : L₁ ≤ L₂) : has_fderiv_at_filter f f' x L₁ := h.mono hst theorem has_fderiv_within_at.mono_of_mem (h : has_fderiv_within_at f f' t x) (hst : t ∈ 𝓝[s] x) : has_fderiv_within_at f f' s x := h.mono $ nhds_within_le_iff.mpr hst theorem has_fderiv_within_at.mono (h : has_fderiv_within_at f f' t x) (hst : s ⊆ t) : has_fderiv_within_at f f' s x := h.mono $ nhds_within_mono _ hst theorem has_fderiv_at.has_fderiv_at_filter (h : has_fderiv_at f f' x) (hL : L ≤ 𝓝 x) : has_fderiv_at_filter f f' x L := h.mono hL theorem has_fderiv_at.has_fderiv_within_at (h : has_fderiv_at f f' x) : has_fderiv_within_at f f' s x := h.has_fderiv_at_filter inf_le_left lemma has_fderiv_within_at.differentiable_within_at (h : has_fderiv_within_at f f' s x) : differentiable_within_at 𝕜 f s x := ⟨f', h⟩ lemma has_fderiv_at.differentiable_at (h : has_fderiv_at f f' x) : differentiable_at 𝕜 f x := ⟨f', h⟩ @[simp] lemma has_fderiv_within_at_univ : has_fderiv_within_at f f' univ x ↔ has_fderiv_at f f' x := by { simp only [has_fderiv_within_at, nhds_within_univ], refl } lemma has_strict_fderiv_at.is_O_sub (hf : has_strict_fderiv_at f f' x) : (λ p : E × E, f p.1 - f p.2) =O[𝓝 (x, x)] (λ p : E × E, p.1 - p.2) := hf.is_O.congr_of_sub.2 (f'.is_O_comp _ _) lemma has_fderiv_at_filter.is_O_sub (h : has_fderiv_at_filter f f' x L) : (λ x', f x' - f x) =O[L] (λ x', x' - x) := h.is_O.congr_of_sub.2 (f'.is_O_sub _ _) protected lemma has_strict_fderiv_at.has_fderiv_at (hf : has_strict_fderiv_at f f' x) : has_fderiv_at f f' x := begin rw [has_fderiv_at, has_fderiv_at_filter, is_o_iff], exact (λ c hc, tendsto_id.prod_mk_nhds tendsto_const_nhds (is_o_iff.1 hf hc)) end protected lemma has_strict_fderiv_at.differentiable_at (hf : has_strict_fderiv_at f f' x) : differentiable_at 𝕜 f x := hf.has_fderiv_at.differentiable_at /-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ∥f'∥₊`, then `f` is `K`-Lipschitz in a neighborhood of `x`. -/ lemma has_strict_fderiv_at.exists_lipschitz_on_with_of_nnnorm_lt (hf : has_strict_fderiv_at f f' x) (K : ℝ≥0) (hK : ∥f'∥₊ < K) : ∃ s ∈ 𝓝 x, lipschitz_on_with K f s := begin have := hf.add_is_O_with (f'.is_O_with_comp _ _) hK, simp only [sub_add_cancel, is_O_with] at this, rcases exists_nhds_square this with ⟨U, Uo, xU, hU⟩, exact ⟨U, Uo.mem_nhds xU, lipschitz_on_with_iff_norm_sub_le.2 $ λ x hx y hy, hU (mk_mem_prod hx hy)⟩ end /-- If `f` is strictly differentiable at `x` with derivative `f'`, then `f` is Lipschitz in a neighborhood of `x`. See also `has_strict_fderiv_at.exists_lipschitz_on_with_of_nnnorm_lt` for a more precise statement. -/ lemma has_strict_fderiv_at.exists_lipschitz_on_with (hf : has_strict_fderiv_at f f' x) : ∃ K (s ∈ 𝓝 x), lipschitz_on_with K f s := (exists_gt _).imp hf.exists_lipschitz_on_with_of_nnnorm_lt /-- Directional derivative agrees with `has_fderiv`. -/ lemma has_fderiv_at.lim (hf : has_fderiv_at f f' x) (v : E) {α : Type*} {c : α → 𝕜} {l : filter α} (hc : tendsto (λ n, ∥c n∥) l at_top) : tendsto (λ n, (c n) • (f (x + (c n)⁻¹ • v) - f x)) l (𝓝 (f' v)) := begin refine (has_fderiv_within_at_univ.2 hf).lim _ (univ_mem' (λ _, trivial)) hc _, assume U hU, refine (eventually_ne_of_tendsto_norm_at_top hc (0:𝕜)).mono (λ y hy, _), convert mem_of_mem_nhds hU, dsimp only, rw [← mul_smul, mul_inv_cancel hy, one_smul] end theorem has_fderiv_at.unique (h₀ : has_fderiv_at f f₀' x) (h₁ : has_fderiv_at f f₁' x) : f₀' = f₁' := begin rw ← has_fderiv_within_at_univ at h₀ h₁, exact unique_diff_within_at_univ.eq h₀ h₁ end lemma has_fderiv_within_at_inter' (h : t ∈ 𝓝[s] x) : has_fderiv_within_at f f' (s ∩ t) x ↔ has_fderiv_within_at f f' s x := by simp [has_fderiv_within_at, nhds_within_restrict'' s h] lemma has_fderiv_within_at_inter (h : t ∈ 𝓝 x) : has_fderiv_within_at f f' (s ∩ t) x ↔ has_fderiv_within_at f f' s x := by simp [has_fderiv_within_at, nhds_within_restrict' s h] lemma has_fderiv_within_at.union (hs : has_fderiv_within_at f f' s x) (ht : has_fderiv_within_at f f' t x) : has_fderiv_within_at f f' (s ∪ t) x := begin simp only [has_fderiv_within_at, nhds_within_union], exact hs.sup ht, end lemma has_fderiv_within_at.nhds_within (h : has_fderiv_within_at f f' s x) (ht : s ∈ 𝓝[t] x) : has_fderiv_within_at f f' t x := (has_fderiv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _)) lemma has_fderiv_within_at.has_fderiv_at (h : has_fderiv_within_at f f' s x) (hs : s ∈ 𝓝 x) : has_fderiv_at f f' x := by rwa [← univ_inter s, has_fderiv_within_at_inter hs, has_fderiv_within_at_univ] at h lemma differentiable_within_at.differentiable_at (h : differentiable_within_at 𝕜 f s x) (hs : s ∈ 𝓝 x) : differentiable_at 𝕜 f x := h.imp (λ f' hf', hf'.has_fderiv_at hs) lemma differentiable_within_at.has_fderiv_within_at (h : differentiable_within_at 𝕜 f s x) : has_fderiv_within_at f (fderiv_within 𝕜 f s x) s x := begin dunfold fderiv_within, dunfold differentiable_within_at at h, rw dif_pos h, exact classical.some_spec h end lemma differentiable_at.has_fderiv_at (h : differentiable_at 𝕜 f x) : has_fderiv_at f (fderiv 𝕜 f x) x := begin dunfold fderiv, dunfold differentiable_at at h, rw dif_pos h, exact classical.some_spec h end lemma differentiable_on.has_fderiv_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) : has_fderiv_at f (fderiv 𝕜 f x) x := ((h x (mem_of_mem_nhds hs)).differentiable_at hs).has_fderiv_at lemma differentiable_on.differentiable_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) : differentiable_at 𝕜 f x := (h.has_fderiv_at hs).differentiable_at lemma differentiable_on.eventually_differentiable_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) : ∀ᶠ y in 𝓝 x, differentiable_at 𝕜 f y := (eventually_eventually_nhds.2 hs).mono $ λ y, h.differentiable_at lemma has_fderiv_at.fderiv (h : has_fderiv_at f f' x) : fderiv 𝕜 f x = f' := by { ext, rw h.unique h.differentiable_at.has_fderiv_at } lemma fderiv_eq {f' : E → E →L[𝕜] F} (h : ∀ x, has_fderiv_at f (f' x) x) : fderiv 𝕜 f = f' := funext $ λ x, (h x).fderiv /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`. Version using `fderiv`. -/ lemma fderiv_at.le_of_lip {f : E → F} {x₀ : E} (hf : differentiable_at 𝕜 f x₀) {s : set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : lipschitz_on_with C f s) : ∥fderiv 𝕜 f x₀∥ ≤ C := hf.has_fderiv_at.le_of_lip hs hlip lemma has_fderiv_within_at.fderiv_within (h : has_fderiv_within_at f f' s x) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f s x = f' := (hxs.eq h h.differentiable_within_at.has_fderiv_within_at).symm /-- If `x` is not in the closure of `s`, then `f` has any derivative at `x` within `s`, as this statement is empty. -/ lemma has_fderiv_within_at_of_not_mem_closure (h : x ∉ closure s) : has_fderiv_within_at f f' s x := begin simp only [mem_closure_iff_nhds_within_ne_bot, ne_bot_iff, ne.def, not_not] at h, simp [has_fderiv_within_at, has_fderiv_at_filter, h, is_o, is_O_with], end lemma differentiable_within_at.mono (h : differentiable_within_at 𝕜 f t x) (st : s ⊆ t) : differentiable_within_at 𝕜 f s x := begin rcases h with ⟨f', hf'⟩, exact ⟨f', hf'.mono st⟩ end lemma differentiable_within_at_univ : differentiable_within_at 𝕜 f univ x ↔ differentiable_at 𝕜 f x := by simp only [differentiable_within_at, has_fderiv_within_at_univ, differentiable_at] lemma differentiable_within_at_inter (ht : t ∈ 𝓝 x) : differentiable_within_at 𝕜 f (s ∩ t) x ↔ differentiable_within_at 𝕜 f s x := by simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter, nhds_within_restrict' s ht] lemma differentiable_within_at_inter' (ht : t ∈ 𝓝[s] x) : differentiable_within_at 𝕜 f (s ∩ t) x ↔ differentiable_within_at 𝕜 f s x := by simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter, nhds_within_restrict'' s ht] lemma differentiable_within_at.antimono (h : differentiable_within_at 𝕜 f s x) (hst : s ⊆ t) (hx : s ∈ 𝓝[t] x) : differentiable_within_at 𝕜 f t x := by rwa [← differentiable_within_at_inter' hx, inter_eq_self_of_subset_right hst] lemma has_fderiv_within_at.antimono (h : has_fderiv_within_at f f' s x) (hst : s ⊆ t) (hs : unique_diff_within_at 𝕜 s x) (hx : s ∈ 𝓝[t] x) : has_fderiv_within_at f f' t x := begin have h' : has_fderiv_within_at f _ t x := (h.differentiable_within_at.antimono hst hx).has_fderiv_within_at, rwa hs.eq h (h'.mono hst), end lemma differentiable_at.differentiable_within_at (h : differentiable_at 𝕜 f x) : differentiable_within_at 𝕜 f s x := (differentiable_within_at_univ.2 h).mono (subset_univ _) lemma differentiable.differentiable_at (h : differentiable 𝕜 f) : differentiable_at 𝕜 f x := h x lemma differentiable_at.fderiv_within (h : differentiable_at 𝕜 f x) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f s x = fderiv 𝕜 f x := begin apply has_fderiv_within_at.fderiv_within _ hxs, exact h.has_fderiv_at.has_fderiv_within_at end lemma differentiable_on.mono (h : differentiable_on 𝕜 f t) (st : s ⊆ t) : differentiable_on 𝕜 f s := λx hx, (h x (st hx)).mono st lemma differentiable_on_univ : differentiable_on 𝕜 f univ ↔ differentiable 𝕜 f := by { simp [differentiable_on, differentiable_within_at_univ], refl } lemma differentiable.differentiable_on (h : differentiable 𝕜 f) : differentiable_on 𝕜 f s := (differentiable_on_univ.2 h).mono (subset_univ _) lemma differentiable_on_of_locally_differentiable_on (h : ∀x∈s, ∃u, is_open u ∧ x ∈ u ∧ differentiable_on 𝕜 f (s ∩ u)) : differentiable_on 𝕜 f s := begin assume x xs, rcases h x xs with ⟨t, t_open, xt, ht⟩, exact (differentiable_within_at_inter (is_open.mem_nhds t_open xt)).1 (ht x ⟨xs, xt⟩) end lemma fderiv_within_subset (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f t x) : fderiv_within 𝕜 f s x = fderiv_within 𝕜 f t x := ((differentiable_within_at.has_fderiv_within_at h).mono st).fderiv_within ht lemma fderiv_within_subset' (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x) (hx : s ∈ 𝓝[t] x) (h : differentiable_within_at 𝕜 f s x) : fderiv_within 𝕜 f s x = fderiv_within 𝕜 f t x := fderiv_within_subset st ht (h.antimono st hx) @[simp] lemma fderiv_within_univ : fderiv_within 𝕜 f univ = fderiv 𝕜 f := begin ext x : 1, by_cases h : differentiable_at 𝕜 f x, { apply has_fderiv_within_at.fderiv_within _ unique_diff_within_at_univ, rw has_fderiv_within_at_univ, apply h.has_fderiv_at }, { have : ¬ differentiable_within_at 𝕜 f univ x, by contrapose! h; rwa ← differentiable_within_at_univ, rw [fderiv_zero_of_not_differentiable_at h, fderiv_within_zero_of_not_differentiable_within_at this] } end lemma fderiv_within_inter (ht : t ∈ 𝓝 x) (hs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f (s ∩ t) x = fderiv_within 𝕜 f s x := begin by_cases h : differentiable_within_at 𝕜 f (s ∩ t) x, { apply fderiv_within_subset (inter_subset_left _ _) _ ((differentiable_within_at_inter ht).1 h), apply hs.inter ht }, { have : ¬ differentiable_within_at 𝕜 f s x, by contrapose! h; rw differentiable_within_at_inter; assumption, rw [fderiv_within_zero_of_not_differentiable_within_at h, fderiv_within_zero_of_not_differentiable_within_at this] } end lemma fderiv_within_of_mem_nhds (h : s ∈ 𝓝 x) : fderiv_within 𝕜 f s x = fderiv 𝕜 f x := begin have : s = univ ∩ s, by simp only [univ_inter], rw [this, ← fderiv_within_univ], exact fderiv_within_inter h (unique_diff_on_univ _ (mem_univ _)) end lemma fderiv_within_of_open (hs : is_open s) (hx : x ∈ s) : fderiv_within 𝕜 f s x = fderiv 𝕜 f x := fderiv_within_of_mem_nhds (is_open.mem_nhds hs hx) lemma fderiv_within_eq_fderiv (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_at 𝕜 f x) : fderiv_within 𝕜 f s x = fderiv 𝕜 f x := begin rw ← fderiv_within_univ, exact fderiv_within_subset (subset_univ _) hs h.differentiable_within_at end lemma fderiv_mem_iff {f : E → F} {s : set (E →L[𝕜] F)} {x : E} : fderiv 𝕜 f x ∈ s ↔ (differentiable_at 𝕜 f x ∧ fderiv 𝕜 f x ∈ s) ∨ (¬differentiable_at 𝕜 f x ∧ (0 : E →L[𝕜] F) ∈ s) := by by_cases hx : differentiable_at 𝕜 f x; simp [fderiv_zero_of_not_differentiable_at, *] lemma fderiv_within_mem_iff {f : E → F} {t : set E} {s : set (E →L[𝕜] F)} {x : E} : fderiv_within 𝕜 f t x ∈ s ↔ (differentiable_within_at 𝕜 f t x ∧ fderiv_within 𝕜 f t x ∈ s) ∨ (¬differentiable_within_at 𝕜 f t x ∧ (0 : E →L[𝕜] F) ∈ s) := by by_cases hx : differentiable_within_at 𝕜 f t x; simp [fderiv_within_zero_of_not_differentiable_within_at, *] end fderiv_properties section continuous /-! ### Deducing continuity from differentiability -/ theorem has_fderiv_at_filter.tendsto_nhds (hL : L ≤ 𝓝 x) (h : has_fderiv_at_filter f f' x L) : tendsto f L (𝓝 (f x)) := begin have : tendsto (λ x', f x' - f x) L (𝓝 0), { refine h.is_O_sub.trans_tendsto (tendsto.mono_left _ hL), rw ← sub_self x, exact tendsto_id.sub tendsto_const_nhds }, have := tendsto.add this tendsto_const_nhds, rw zero_add (f x) at this, exact this.congr (by simp) end theorem has_fderiv_within_at.continuous_within_at (h : has_fderiv_within_at f f' s x) : continuous_within_at f s x := has_fderiv_at_filter.tendsto_nhds inf_le_left h theorem has_fderiv_at.continuous_at (h : has_fderiv_at f f' x) : continuous_at f x := has_fderiv_at_filter.tendsto_nhds le_rfl h lemma differentiable_within_at.continuous_within_at (h : differentiable_within_at 𝕜 f s x) : continuous_within_at f s x := let ⟨f', hf'⟩ := h in hf'.continuous_within_at lemma differentiable_at.continuous_at (h : differentiable_at 𝕜 f x) : continuous_at f x := let ⟨f', hf'⟩ := h in hf'.continuous_at lemma differentiable_on.continuous_on (h : differentiable_on 𝕜 f s) : continuous_on f s := λx hx, (h x hx).continuous_within_at lemma differentiable.continuous (h : differentiable 𝕜 f) : continuous f := continuous_iff_continuous_at.2 $ λx, (h x).continuous_at protected lemma has_strict_fderiv_at.continuous_at (hf : has_strict_fderiv_at f f' x) : continuous_at f x := hf.has_fderiv_at.continuous_at lemma has_strict_fderiv_at.is_O_sub_rev {f' : E ≃L[𝕜] F} (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) x) : (λ p : E × E, p.1 - p.2) =O[𝓝 (x, x)](λ p : E × E, f p.1 - f p.2) := ((f'.is_O_comp_rev _ _).trans (hf.trans_is_O (f'.is_O_comp_rev _ _)).right_is_O_add).congr (λ _, rfl) (λ _, sub_add_cancel _ _) lemma has_fderiv_at_filter.is_O_sub_rev (hf : has_fderiv_at_filter f f' x L) {C} (hf' : antilipschitz_with C f') : (λ x', x' - x) =O[L] (λ x', f x' - f x) := have (λ x', x' - x) =O[L] (λ x', f' (x' - x)), from is_O_iff.2 ⟨C, eventually_of_forall $ λ x', add_monoid_hom_class.bound_of_antilipschitz f' hf' _⟩, (this.trans (hf.trans_is_O this).right_is_O_add).congr (λ _, rfl) (λ _, sub_add_cancel _ _) end continuous section congr /-! ### congr properties of the derivative -/ theorem filter.eventually_eq.has_strict_fderiv_at_iff (h : f₀ =ᶠ[𝓝 x] f₁) (h' : ∀ y, f₀' y = f₁' y) : has_strict_fderiv_at f₀ f₀' x ↔ has_strict_fderiv_at f₁ f₁' x := begin refine is_o_congr ((h.prod_mk_nhds h).mono _) (eventually_of_forall $ λ _, rfl), rintros p ⟨hp₁, hp₂⟩, simp only [*] end theorem has_strict_fderiv_at.congr_of_eventually_eq (h : has_strict_fderiv_at f f' x) (h₁ : f =ᶠ[𝓝 x] f₁) : has_strict_fderiv_at f₁ f' x := (h₁.has_strict_fderiv_at_iff (λ _, rfl)).1 h theorem filter.eventually_eq.has_fderiv_at_filter_iff (h₀ : f₀ =ᶠ[L] f₁) (hx : f₀ x = f₁ x) (h₁ : ∀ x, f₀' x = f₁' x) : has_fderiv_at_filter f₀ f₀' x L ↔ has_fderiv_at_filter f₁ f₁' x L := is_o_congr (h₀.mono $ λ y hy, by simp only [hy, h₁, hx]) (eventually_of_forall $ λ _, rfl) lemma has_fderiv_at_filter.congr_of_eventually_eq (h : has_fderiv_at_filter f f' x L) (hL : f₁ =ᶠ[L] f) (hx : f₁ x = f x) : has_fderiv_at_filter f₁ f' x L := (hL.has_fderiv_at_filter_iff hx $ λ _, rfl).2 h theorem filter.eventually_eq.has_fderiv_at_iff (h : f₀ =ᶠ[𝓝 x] f₁) : has_fderiv_at f₀ f' x ↔ has_fderiv_at f₁ f' x := h.has_fderiv_at_filter_iff h.eq_of_nhds (λ _, rfl) theorem filter.eventually_eq.differentiable_at_iff (h : f₀ =ᶠ[𝓝 x] f₁) : differentiable_at 𝕜 f₀ x ↔ differentiable_at 𝕜 f₁ x := exists_congr $ λ f', h.has_fderiv_at_iff theorem filter.eventually_eq.has_fderiv_within_at_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) : has_fderiv_within_at f₀ f' s x ↔ has_fderiv_within_at f₁ f' s x := h.has_fderiv_at_filter_iff hx (λ _, rfl) theorem filter.eventually_eq.has_fderiv_within_at_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) : has_fderiv_within_at f₀ f' s x ↔ has_fderiv_within_at f₁ f' s x := h.has_fderiv_within_at_iff (h.eq_of_nhds_within hx) theorem filter.eventually_eq.differentiable_within_at_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) : differentiable_within_at 𝕜 f₀ s x ↔ differentiable_within_at 𝕜 f₁ s x := exists_congr $ λ f', h.has_fderiv_within_at_iff hx theorem filter.eventually_eq.differentiable_within_at_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) : differentiable_within_at 𝕜 f₀ s x ↔ differentiable_within_at 𝕜 f₁ s x := h.differentiable_within_at_iff (h.eq_of_nhds_within hx) lemma has_fderiv_within_at.congr_mono (h : has_fderiv_within_at f f' s x) (ht : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : has_fderiv_within_at f₁ f' t x := has_fderiv_at_filter.congr_of_eventually_eq (h.mono h₁) (filter.mem_inf_of_right ht) hx lemma has_fderiv_within_at.congr (h : has_fderiv_within_at f f' s x) (hs : ∀x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : has_fderiv_within_at f₁ f' s x := h.congr_mono hs hx (subset.refl _) lemma has_fderiv_within_at.congr' (h : has_fderiv_within_at f f' s x) (hs : ∀x ∈ s, f₁ x = f x) (hx : x ∈ s) : has_fderiv_within_at f₁ f' s x := h.congr hs (hs x hx) lemma has_fderiv_within_at.congr_of_eventually_eq (h : has_fderiv_within_at f f' s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : has_fderiv_within_at f₁ f' s x := has_fderiv_at_filter.congr_of_eventually_eq h h₁ hx lemma has_fderiv_at.congr_of_eventually_eq (h : has_fderiv_at f f' x) (h₁ : f₁ =ᶠ[𝓝 x] f) : has_fderiv_at f₁ f' x := has_fderiv_at_filter.congr_of_eventually_eq h h₁ (mem_of_mem_nhds h₁ : _) lemma differentiable_within_at.congr_mono (h : differentiable_within_at 𝕜 f s x) (ht : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : differentiable_within_at 𝕜 f₁ t x := (has_fderiv_within_at.congr_mono h.has_fderiv_within_at ht hx h₁).differentiable_within_at lemma differentiable_within_at.congr (h : differentiable_within_at 𝕜 f s x) (ht : ∀x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : differentiable_within_at 𝕜 f₁ s x := differentiable_within_at.congr_mono h ht hx (subset.refl _) lemma differentiable_within_at.congr_of_eventually_eq (h : differentiable_within_at 𝕜 f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : differentiable_within_at 𝕜 f₁ s x := (h.has_fderiv_within_at.congr_of_eventually_eq h₁ hx).differentiable_within_at lemma differentiable_on.congr_mono (h : differentiable_on 𝕜 f s) (h' : ∀x ∈ t, f₁ x = f x) (h₁ : t ⊆ s) : differentiable_on 𝕜 f₁ t := λ x hx, (h x (h₁ hx)).congr_mono h' (h' x hx) h₁ lemma differentiable_on.congr (h : differentiable_on 𝕜 f s) (h' : ∀x ∈ s, f₁ x = f x) : differentiable_on 𝕜 f₁ s := λ x hx, (h x hx).congr h' (h' x hx) lemma differentiable_on_congr (h' : ∀x ∈ s, f₁ x = f x) : differentiable_on 𝕜 f₁ s ↔ differentiable_on 𝕜 f s := ⟨λ h, differentiable_on.congr h (λy hy, (h' y hy).symm), λ h, differentiable_on.congr h h'⟩ lemma differentiable_at.congr_of_eventually_eq (h : differentiable_at 𝕜 f x) (hL : f₁ =ᶠ[𝓝 x] f) : differentiable_at 𝕜 f₁ x := hL.differentiable_at_iff.2 h lemma differentiable_within_at.fderiv_within_congr_mono (h : differentiable_within_at 𝕜 f s x) (hs : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (hxt : unique_diff_within_at 𝕜 t x) (h₁ : t ⊆ s) : fderiv_within 𝕜 f₁ t x = fderiv_within 𝕜 f s x := (has_fderiv_within_at.congr_mono h.has_fderiv_within_at hs hx h₁).fderiv_within hxt lemma filter.eventually_eq.fderiv_within_eq (hs : unique_diff_within_at 𝕜 s x) (hL : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x := if h : differentiable_within_at 𝕜 f s x then has_fderiv_within_at.fderiv_within (h.has_fderiv_within_at.congr_of_eventually_eq hL hx) hs else have h' : ¬ differentiable_within_at 𝕜 f₁ s x, from mt (λ h, h.congr_of_eventually_eq (hL.mono $ λ x, eq.symm) hx.symm) h, by rw [fderiv_within_zero_of_not_differentiable_within_at h, fderiv_within_zero_of_not_differentiable_within_at h'] lemma filter.eventually_eq.fderiv_within_eq_nhds (hs : unique_diff_within_at 𝕜 s x) (hL : f₁ =ᶠ[𝓝 x] f) : fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x := (show f₁ =ᶠ[𝓝[s] x] f, from nhds_within_le_nhds hL).fderiv_within_eq hs (mem_of_mem_nhds hL : _) lemma fderiv_within_congr (hs : unique_diff_within_at 𝕜 s x) (hL : ∀y∈s, f₁ y = f y) (hx : f₁ x = f x) : fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x := begin apply filter.eventually_eq.fderiv_within_eq hs _ hx, apply mem_of_superset self_mem_nhds_within, exact hL end lemma filter.eventually_eq.fderiv_eq (hL : f₁ =ᶠ[𝓝 x] f) : fderiv 𝕜 f₁ x = fderiv 𝕜 f x := begin have A : f₁ x = f x := hL.eq_of_nhds, rw [← fderiv_within_univ, ← fderiv_within_univ], rw ← nhds_within_univ at hL, exact hL.fderiv_within_eq unique_diff_within_at_univ A end protected lemma filter.eventually_eq.fderiv (h : f₁ =ᶠ[𝓝 x] f) : fderiv 𝕜 f₁ =ᶠ[𝓝 x] fderiv 𝕜 f := h.eventually_eq_nhds.mono $ λ x h, h.fderiv_eq end congr section id /-! ### Derivative of the identity -/ theorem has_strict_fderiv_at_id (x : E) : has_strict_fderiv_at id (id 𝕜 E) x := (is_o_zero _ _).congr_left $ by simp theorem has_fderiv_at_filter_id (x : E) (L : filter E) : has_fderiv_at_filter id (id 𝕜 E) x L := (is_o_zero _ _).congr_left $ by simp theorem has_fderiv_within_at_id (x : E) (s : set E) : has_fderiv_within_at id (id 𝕜 E) s x := has_fderiv_at_filter_id _ _ theorem has_fderiv_at_id (x : E) : has_fderiv_at id (id 𝕜 E) x := has_fderiv_at_filter_id _ _ @[simp] lemma differentiable_at_id : differentiable_at 𝕜 id x := (has_fderiv_at_id x).differentiable_at @[simp] lemma differentiable_at_id' : differentiable_at 𝕜 (λ x, x) x := (has_fderiv_at_id x).differentiable_at lemma differentiable_within_at_id : differentiable_within_at 𝕜 id s x := differentiable_at_id.differentiable_within_at @[simp] lemma differentiable_id : differentiable 𝕜 (id : E → E) := λx, differentiable_at_id @[simp] lemma differentiable_id' : differentiable 𝕜 (λ (x : E), x) := λx, differentiable_at_id lemma differentiable_on_id : differentiable_on 𝕜 id s := differentiable_id.differentiable_on lemma fderiv_id : fderiv 𝕜 id x = id 𝕜 E := has_fderiv_at.fderiv (has_fderiv_at_id x) @[simp] lemma fderiv_id' : fderiv 𝕜 (λ (x : E), x) x = continuous_linear_map.id 𝕜 E := fderiv_id lemma fderiv_within_id (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 id s x = id 𝕜 E := begin rw differentiable_at.fderiv_within (differentiable_at_id) hxs, exact fderiv_id end lemma fderiv_within_id' (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (λ (x : E), x) s x = continuous_linear_map.id 𝕜 E := fderiv_within_id hxs end id section const /-! ### derivative of a constant function -/ theorem has_strict_fderiv_at_const (c : F) (x : E) : has_strict_fderiv_at (λ _, c) (0 : E →L[𝕜] F) x := (is_o_zero _ _).congr_left $ λ _, by simp only [zero_apply, sub_self] theorem has_fderiv_at_filter_const (c : F) (x : E) (L : filter E) : has_fderiv_at_filter (λ x, c) (0 : E →L[𝕜] F) x L := (is_o_zero _ _).congr_left $ λ _, by simp only [zero_apply, sub_self] theorem has_fderiv_within_at_const (c : F) (x : E) (s : set E) : has_fderiv_within_at (λ x, c) (0 : E →L[𝕜] F) s x := has_fderiv_at_filter_const _ _ _ theorem has_fderiv_at_const (c : F) (x : E) : has_fderiv_at (λ x, c) (0 : E →L[𝕜] F) x := has_fderiv_at_filter_const _ _ _ @[simp] lemma differentiable_at_const (c : F) : differentiable_at 𝕜 (λx, c) x := ⟨0, has_fderiv_at_const c x⟩ lemma differentiable_within_at_const (c : F) : differentiable_within_at 𝕜 (λx, c) s x := differentiable_at.differentiable_within_at (differentiable_at_const _) lemma fderiv_const_apply (c : F) : fderiv 𝕜 (λy, c) x = 0 := has_fderiv_at.fderiv (has_fderiv_at_const c x) @[simp] lemma fderiv_const (c : F) : fderiv 𝕜 (λ (y : E), c) = 0 := by { ext m, rw fderiv_const_apply, refl } lemma fderiv_within_const_apply (c : F) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (λy, c) s x = 0 := begin rw differentiable_at.fderiv_within (differentiable_at_const _) hxs, exact fderiv_const_apply _ end @[simp] lemma differentiable_const (c : F) : differentiable 𝕜 (λx : E, c) := λx, differentiable_at_const _ lemma differentiable_on_const (c : F) : differentiable_on 𝕜 (λx, c) s := (differentiable_const _).differentiable_on lemma has_fderiv_within_at_singleton (f : E → F) (x : E) : has_fderiv_within_at f (0 : E →L[𝕜] F) {x} x := by simp only [has_fderiv_within_at, nhds_within_singleton, has_fderiv_at_filter, is_o_pure, continuous_linear_map.zero_apply, sub_self] lemma has_fderiv_at_of_subsingleton [h : subsingleton E] (f : E → F) (x : E) : has_fderiv_at f (0 : E →L[𝕜] F) x := begin rw [← has_fderiv_within_at_univ, subsingleton_univ.eq_singleton_of_mem (mem_univ x)], exact has_fderiv_within_at_singleton f x end lemma differentiable_on_empty : differentiable_on 𝕜 f ∅ := λ x, false.elim lemma differentiable_on_singleton : differentiable_on 𝕜 f {x} := forall_eq.2 (has_fderiv_within_at_singleton f x).differentiable_within_at lemma set.subsingleton.differentiable_on (hs : s.subsingleton) : differentiable_on 𝕜 f s := hs.induction_on differentiable_on_empty (λ x, differentiable_on_singleton) end const section continuous_linear_map /-! ### Continuous linear maps There are currently two variants of these in mathlib, the bundled version (named `continuous_linear_map`, and denoted `E →L[𝕜] F`), and the unbundled version (with a predicate `is_bounded_linear_map`). We give statements for both versions. -/ protected theorem continuous_linear_map.has_strict_fderiv_at {x : E} : has_strict_fderiv_at e e x := (is_o_zero _ _).congr_left $ λ x, by simp only [e.map_sub, sub_self] protected lemma continuous_linear_map.has_fderiv_at_filter : has_fderiv_at_filter e e x L := (is_o_zero _ _).congr_left $ λ x, by simp only [e.map_sub, sub_self] protected lemma continuous_linear_map.has_fderiv_within_at : has_fderiv_within_at e e s x := e.has_fderiv_at_filter protected lemma continuous_linear_map.has_fderiv_at : has_fderiv_at e e x := e.has_fderiv_at_filter @[simp] protected lemma continuous_linear_map.differentiable_at : differentiable_at 𝕜 e x := e.has_fderiv_at.differentiable_at protected lemma continuous_linear_map.differentiable_within_at : differentiable_within_at 𝕜 e s x := e.differentiable_at.differentiable_within_at @[simp] protected lemma continuous_linear_map.fderiv : fderiv 𝕜 e x = e := e.has_fderiv_at.fderiv protected lemma continuous_linear_map.fderiv_within (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 e s x = e := begin rw differentiable_at.fderiv_within e.differentiable_at hxs, exact e.fderiv end @[simp] protected lemma continuous_linear_map.differentiable : differentiable 𝕜 e := λx, e.differentiable_at protected lemma continuous_linear_map.differentiable_on : differentiable_on 𝕜 e s := e.differentiable.differentiable_on lemma is_bounded_linear_map.has_fderiv_at_filter (h : is_bounded_linear_map 𝕜 f) : has_fderiv_at_filter f h.to_continuous_linear_map x L := h.to_continuous_linear_map.has_fderiv_at_filter lemma is_bounded_linear_map.has_fderiv_within_at (h : is_bounded_linear_map 𝕜 f) : has_fderiv_within_at f h.to_continuous_linear_map s x := h.has_fderiv_at_filter lemma is_bounded_linear_map.has_fderiv_at (h : is_bounded_linear_map 𝕜 f) : has_fderiv_at f h.to_continuous_linear_map x := h.has_fderiv_at_filter lemma is_bounded_linear_map.differentiable_at (h : is_bounded_linear_map 𝕜 f) : differentiable_at 𝕜 f x := h.has_fderiv_at.differentiable_at lemma is_bounded_linear_map.differentiable_within_at (h : is_bounded_linear_map 𝕜 f) : differentiable_within_at 𝕜 f s x := h.differentiable_at.differentiable_within_at lemma is_bounded_linear_map.fderiv (h : is_bounded_linear_map 𝕜 f) : fderiv 𝕜 f x = h.to_continuous_linear_map := has_fderiv_at.fderiv (h.has_fderiv_at) lemma is_bounded_linear_map.fderiv_within (h : is_bounded_linear_map 𝕜 f) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f s x = h.to_continuous_linear_map := begin rw differentiable_at.fderiv_within h.differentiable_at hxs, exact h.fderiv end lemma is_bounded_linear_map.differentiable (h : is_bounded_linear_map 𝕜 f) : differentiable 𝕜 f := λx, h.differentiable_at lemma is_bounded_linear_map.differentiable_on (h : is_bounded_linear_map 𝕜 f) : differentiable_on 𝕜 f s := h.differentiable.differentiable_on end continuous_linear_map section composition /-! ### Derivative of the composition of two functions For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to get confused since there are too many possibilities for composition -/ variable (x) theorem has_fderiv_at_filter.comp {g : F → G} {g' : F →L[𝕜] G} {L' : filter F} (hg : has_fderiv_at_filter g g' (f x) L') (hf : has_fderiv_at_filter f f' x L) (hL : tendsto f L L') : has_fderiv_at_filter (g ∘ f) (g'.comp f') x L := let eq₁ := (g'.is_O_comp _ _).trans_is_o hf in let eq₂ := (hg.comp_tendsto hL).trans_is_O hf.is_O_sub in by { refine eq₂.triangle (eq₁.congr_left (λ x', _)), simp } /- A readable version of the previous theorem, a general form of the chain rule. -/ example {g : F → G} {g' : F →L[𝕜] G} (hg : has_fderiv_at_filter g g' (f x) (L.map f)) (hf : has_fderiv_at_filter f f' x L) : has_fderiv_at_filter (g ∘ f) (g'.comp f') x L := begin unfold has_fderiv_at_filter at hg, have := calc (λ x', g (f x') - g (f x) - g' (f x' - f x)) =o[L] (λ x', f x' - f x) : hg.comp_tendsto le_rfl ... =O[L] (λ x', x' - x) : hf.is_O_sub, refine this.triangle _, calc (λ x' : E, g' (f x' - f x) - g'.comp f' (x' - x)) =ᶠ[L] λ x', g' (f x' - f x - f' (x' - x)) : eventually_of_forall (λ x', by simp) ... =O[L] λ x', f x' - f x - f' (x' - x) : g'.is_O_comp _ _ ... =o[L] λ x', x' - x : hf end theorem has_fderiv_within_at.comp {g : F → G} {g' : F →L[𝕜] G} {t : set F} (hg : has_fderiv_within_at g g' t (f x)) (hf : has_fderiv_within_at f f' s x) (hst : maps_to f s t) : has_fderiv_within_at (g ∘ f) (g'.comp f') s x := hg.comp x hf $ hf.continuous_within_at.tendsto_nhds_within hst theorem has_fderiv_at.comp_has_fderiv_within_at {g : F → G} {g' : F →L[𝕜] G} (hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (g ∘ f) (g'.comp f') s x := hg.comp x hf hf.continuous_within_at /-- The chain rule. -/ theorem has_fderiv_at.comp {g : F → G} {g' : F →L[𝕜] G} (hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_at f f' x) : has_fderiv_at (g ∘ f) (g'.comp f') x := hg.comp x hf hf.continuous_at lemma differentiable_within_at.comp {g : F → G} {t : set F} (hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x) (h : maps_to f s t) : differentiable_within_at 𝕜 (g ∘ f) s x := (hg.has_fderiv_within_at.comp x hf.has_fderiv_within_at h).differentiable_within_at lemma differentiable_within_at.comp' {g : F → G} {t : set F} (hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x) : differentiable_within_at 𝕜 (g ∘ f) (s ∩ f⁻¹' t) x := hg.comp x (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _) lemma differentiable_at.comp {g : F → G} (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_at 𝕜 f x) : differentiable_at 𝕜 (g ∘ f) x := (hg.has_fderiv_at.comp x hf.has_fderiv_at).differentiable_at lemma differentiable_at.comp_differentiable_within_at {g : F → G} (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_within_at 𝕜 f s x) : differentiable_within_at 𝕜 (g ∘ f) s x := hg.differentiable_within_at.comp x hf (maps_to_univ _ _) lemma fderiv_within.comp {g : F → G} {t : set F} (hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x) (h : maps_to f s t) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (g ∘ f) s x = (fderiv_within 𝕜 g t (f x)).comp (fderiv_within 𝕜 f s x) := (hg.has_fderiv_within_at.comp x (hf.has_fderiv_within_at) h).fderiv_within hxs /-- Ternary version of `fderiv_within.comp`, with equality assumptions of basepoints added, in order to apply more easily as a rewrite from right-to-left. -/ lemma fderiv_within.comp₃ {g' : G → G'} {g : F → G} {t : set F} {u : set G} {y : F} {y' : G} (hg' : differentiable_within_at 𝕜 g' u y') (hg : differentiable_within_at 𝕜 g t y) (hf : differentiable_within_at 𝕜 f s x) (h2g : maps_to g t u) (h2f : maps_to f s t) (h3g : g y = y') (h3f : f x = y) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (g' ∘ g ∘ f) s x = (fderiv_within 𝕜 g' u y').comp ((fderiv_within 𝕜 g t y).comp (fderiv_within 𝕜 f s x)) := begin substs h3g h3f, exact (hg'.has_fderiv_within_at.comp x (hg.has_fderiv_within_at.comp x (hf.has_fderiv_within_at) h2f) $ h2g.comp h2f).fderiv_within hxs end lemma fderiv.comp {g : F → G} (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_at 𝕜 f x) : fderiv 𝕜 (g ∘ f) x = (fderiv 𝕜 g (f x)).comp (fderiv 𝕜 f x) := (hg.has_fderiv_at.comp x hf.has_fderiv_at).fderiv lemma fderiv.comp_fderiv_within {g : F → G} (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_within_at 𝕜 f s x) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (g ∘ f) s x = (fderiv 𝕜 g (f x)).comp (fderiv_within 𝕜 f s x) := (hg.has_fderiv_at.comp_has_fderiv_within_at x hf.has_fderiv_within_at).fderiv_within hxs lemma differentiable_on.comp {g : F → G} {t : set F} (hg : differentiable_on 𝕜 g t) (hf : differentiable_on 𝕜 f s) (st : maps_to f s t) : differentiable_on 𝕜 (g ∘ f) s := λx hx, differentiable_within_at.comp x (hg (f x) (st hx)) (hf x hx) st lemma differentiable.comp {g : F → G} (hg : differentiable 𝕜 g) (hf : differentiable 𝕜 f) : differentiable 𝕜 (g ∘ f) := λx, differentiable_at.comp x (hg (f x)) (hf x) lemma differentiable.comp_differentiable_on {g : F → G} (hg : differentiable 𝕜 g) (hf : differentiable_on 𝕜 f s) : differentiable_on 𝕜 (g ∘ f) s := hg.differentiable_on.comp hf (maps_to_univ _ _) /-- The chain rule for derivatives in the sense of strict differentiability. -/ protected lemma has_strict_fderiv_at.comp {g : F → G} {g' : F →L[𝕜] G} (hg : has_strict_fderiv_at g g' (f x)) (hf : has_strict_fderiv_at f f' x) : has_strict_fderiv_at (λ x, g (f x)) (g'.comp f') x := ((hg.comp_tendsto (hf.continuous_at.prod_map' hf.continuous_at)).trans_is_O hf.is_O_sub).triangle $ by simpa only [g'.map_sub, f'.coe_comp'] using (g'.is_O_comp _ _).trans_is_o hf protected lemma differentiable.iterate {f : E → E} (hf : differentiable 𝕜 f) (n : ℕ) : differentiable 𝕜 (f^[n]) := nat.rec_on n differentiable_id (λ n ihn, ihn.comp hf) protected lemma differentiable_on.iterate {f : E → E} (hf : differentiable_on 𝕜 f s) (hs : maps_to f s s) (n : ℕ) : differentiable_on 𝕜 (f^[n]) s := nat.rec_on n differentiable_on_id (λ n ihn, ihn.comp hf hs) variable {x} protected lemma has_fderiv_at_filter.iterate {f : E → E} {f' : E →L[𝕜] E} (hf : has_fderiv_at_filter f f' x L) (hL : tendsto f L L) (hx : f x = x) (n : ℕ) : has_fderiv_at_filter (f^[n]) (f'^n) x L := begin induction n with n ihn, { exact has_fderiv_at_filter_id x L }, { rw [function.iterate_succ, pow_succ'], rw ← hx at ihn, exact ihn.comp x hf hL } end protected lemma has_fderiv_at.iterate {f : E → E} {f' : E →L[𝕜] E} (hf : has_fderiv_at f f' x) (hx : f x = x) (n : ℕ) : has_fderiv_at (f^[n]) (f'^n) x := begin refine hf.iterate _ hx n, convert hf.continuous_at, exact hx.symm end protected lemma has_fderiv_within_at.iterate {f : E → E} {f' : E →L[𝕜] E} (hf : has_fderiv_within_at f f' s x) (hx : f x = x) (hs : maps_to f s s) (n : ℕ) : has_fderiv_within_at (f^[n]) (f'^n) s x := begin refine hf.iterate _ hx n, convert tendsto_inf.2 ⟨hf.continuous_within_at, _⟩, exacts [hx.symm, (tendsto_principal_principal.2 hs).mono_left inf_le_right] end protected lemma has_strict_fderiv_at.iterate {f : E → E} {f' : E →L[𝕜] E} (hf : has_strict_fderiv_at f f' x) (hx : f x = x) (n : ℕ) : has_strict_fderiv_at (f^[n]) (f'^n) x := begin induction n with n ihn, { exact has_strict_fderiv_at_id x }, { rw [function.iterate_succ, pow_succ'], rw ← hx at ihn, exact ihn.comp x hf } end protected lemma differentiable_at.iterate {f : E → E} (hf : differentiable_at 𝕜 f x) (hx : f x = x) (n : ℕ) : differentiable_at 𝕜 (f^[n]) x := (hf.has_fderiv_at.iterate hx n).differentiable_at protected lemma differentiable_within_at.iterate {f : E → E} (hf : differentiable_within_at 𝕜 f s x) (hx : f x = x) (hs : maps_to f s s) (n : ℕ) : differentiable_within_at 𝕜 (f^[n]) s x := (hf.has_fderiv_within_at.iterate hx hs n).differentiable_within_at end composition section cartesian_product /-! ### Derivative of the cartesian product of two functions -/ section prod variables {f₂ : E → G} {f₂' : E →L[𝕜] G} protected lemma has_strict_fderiv_at.prod (hf₁ : has_strict_fderiv_at f₁ f₁' x) (hf₂ : has_strict_fderiv_at f₂ f₂' x) : has_strict_fderiv_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x := hf₁.prod_left hf₂ lemma has_fderiv_at_filter.prod (hf₁ : has_fderiv_at_filter f₁ f₁' x L) (hf₂ : has_fderiv_at_filter f₂ f₂' x L) : has_fderiv_at_filter (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x L := hf₁.prod_left hf₂ lemma has_fderiv_within_at.prod (hf₁ : has_fderiv_within_at f₁ f₁' s x) (hf₂ : has_fderiv_within_at f₂ f₂' s x) : has_fderiv_within_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') s x := hf₁.prod hf₂ lemma has_fderiv_at.prod (hf₁ : has_fderiv_at f₁ f₁' x) (hf₂ : has_fderiv_at f₂ f₂' x) : has_fderiv_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x := hf₁.prod hf₂ lemma has_fderiv_at_prod_mk_left (e₀ : E) (f₀ : F) : has_fderiv_at (λ e : E, (e, f₀)) (inl 𝕜 E F) e₀ := (has_fderiv_at_id e₀).prod (has_fderiv_at_const f₀ e₀) lemma has_fderiv_at_prod_mk_right (e₀ : E) (f₀ : F) : has_fderiv_at (λ f : F, (e₀, f)) (inr 𝕜 E F) f₀ := (has_fderiv_at_const e₀ f₀).prod (has_fderiv_at_id f₀) lemma differentiable_within_at.prod (hf₁ : differentiable_within_at 𝕜 f₁ s x) (hf₂ : differentiable_within_at 𝕜 f₂ s x) : differentiable_within_at 𝕜 (λx:E, (f₁ x, f₂ x)) s x := (hf₁.has_fderiv_within_at.prod hf₂.has_fderiv_within_at).differentiable_within_at @[simp] lemma differentiable_at.prod (hf₁ : differentiable_at 𝕜 f₁ x) (hf₂ : differentiable_at 𝕜 f₂ x) : differentiable_at 𝕜 (λx:E, (f₁ x, f₂ x)) x := (hf₁.has_fderiv_at.prod hf₂.has_fderiv_at).differentiable_at lemma differentiable_on.prod (hf₁ : differentiable_on 𝕜 f₁ s) (hf₂ : differentiable_on 𝕜 f₂ s) : differentiable_on 𝕜 (λx:E, (f₁ x, f₂ x)) s := λx hx, differentiable_within_at.prod (hf₁ x hx) (hf₂ x hx) @[simp] lemma differentiable.prod (hf₁ : differentiable 𝕜 f₁) (hf₂ : differentiable 𝕜 f₂) : differentiable 𝕜 (λx:E, (f₁ x, f₂ x)) := λ x, differentiable_at.prod (hf₁ x) (hf₂ x) lemma differentiable_at.fderiv_prod (hf₁ : differentiable_at 𝕜 f₁ x) (hf₂ : differentiable_at 𝕜 f₂ x) : fderiv 𝕜 (λx:E, (f₁ x, f₂ x)) x = (fderiv 𝕜 f₁ x).prod (fderiv 𝕜 f₂ x) := (hf₁.has_fderiv_at.prod hf₂.has_fderiv_at).fderiv lemma differentiable_at.fderiv_within_prod (hf₁ : differentiable_within_at 𝕜 f₁ s x) (hf₂ : differentiable_within_at 𝕜 f₂ s x) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (λx:E, (f₁ x, f₂ x)) s x = (fderiv_within 𝕜 f₁ s x).prod (fderiv_within 𝕜 f₂ s x) := (hf₁.has_fderiv_within_at.prod hf₂.has_fderiv_within_at).fderiv_within hxs end prod section fst variables {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F} lemma has_strict_fderiv_at_fst : has_strict_fderiv_at (@prod.fst E F) (fst 𝕜 E F) p := (fst 𝕜 E F).has_strict_fderiv_at protected lemma has_strict_fderiv_at.fst (h : has_strict_fderiv_at f₂ f₂' x) : has_strict_fderiv_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x := has_strict_fderiv_at_fst.comp x h lemma has_fderiv_at_filter_fst {L : filter (E × F)} : has_fderiv_at_filter (@prod.fst E F) (fst 𝕜 E F) p L := (fst 𝕜 E F).has_fderiv_at_filter protected lemma has_fderiv_at_filter.fst (h : has_fderiv_at_filter f₂ f₂' x L) : has_fderiv_at_filter (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x L := has_fderiv_at_filter_fst.comp x h tendsto_map lemma has_fderiv_at_fst : has_fderiv_at (@prod.fst E F) (fst 𝕜 E F) p := has_fderiv_at_filter_fst protected lemma has_fderiv_at.fst (h : has_fderiv_at f₂ f₂' x) : has_fderiv_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x := h.fst lemma has_fderiv_within_at_fst {s : set (E × F)} : has_fderiv_within_at (@prod.fst E F) (fst 𝕜 E F) s p := has_fderiv_at_filter_fst protected lemma has_fderiv_within_at.fst (h : has_fderiv_within_at f₂ f₂' s x) : has_fderiv_within_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') s x := h.fst lemma differentiable_at_fst : differentiable_at 𝕜 prod.fst p := has_fderiv_at_fst.differentiable_at @[simp] protected lemma differentiable_at.fst (h : differentiable_at 𝕜 f₂ x) : differentiable_at 𝕜 (λ x, (f₂ x).1) x := differentiable_at_fst.comp x h lemma differentiable_fst : differentiable 𝕜 (prod.fst : E × F → E) := λ x, differentiable_at_fst @[simp] protected lemma differentiable.fst (h : differentiable 𝕜 f₂) : differentiable 𝕜 (λ x, (f₂ x).1) := differentiable_fst.comp h lemma differentiable_within_at_fst {s : set (E × F)} : differentiable_within_at 𝕜 prod.fst s p := differentiable_at_fst.differentiable_within_at protected lemma differentiable_within_at.fst (h : differentiable_within_at 𝕜 f₂ s x) : differentiable_within_at 𝕜 (λ x, (f₂ x).1) s x := differentiable_at_fst.comp_differentiable_within_at x h lemma differentiable_on_fst {s : set (E × F)} : differentiable_on 𝕜 prod.fst s := differentiable_fst.differentiable_on protected lemma differentiable_on.fst (h : differentiable_on 𝕜 f₂ s) : differentiable_on 𝕜 (λ x, (f₂ x).1) s := differentiable_fst.comp_differentiable_on h lemma fderiv_fst : fderiv 𝕜 prod.fst p = fst 𝕜 E F := has_fderiv_at_fst.fderiv lemma fderiv.fst (h : differentiable_at 𝕜 f₂ x) : fderiv 𝕜 (λ x, (f₂ x).1) x = (fst 𝕜 F G).comp (fderiv 𝕜 f₂ x) := h.has_fderiv_at.fst.fderiv lemma fderiv_within_fst {s : set (E × F)} (hs : unique_diff_within_at 𝕜 s p) : fderiv_within 𝕜 prod.fst s p = fst 𝕜 E F := has_fderiv_within_at_fst.fderiv_within hs lemma fderiv_within.fst (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f₂ s x) : fderiv_within 𝕜 (λ x, (f₂ x).1) s x = (fst 𝕜 F G).comp (fderiv_within 𝕜 f₂ s x) := h.has_fderiv_within_at.fst.fderiv_within hs end fst section snd variables {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F} lemma has_strict_fderiv_at_snd : has_strict_fderiv_at (@prod.snd E F) (snd 𝕜 E F) p := (snd 𝕜 E F).has_strict_fderiv_at protected lemma has_strict_fderiv_at.snd (h : has_strict_fderiv_at f₂ f₂' x) : has_strict_fderiv_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x := has_strict_fderiv_at_snd.comp x h lemma has_fderiv_at_filter_snd {L : filter (E × F)} : has_fderiv_at_filter (@prod.snd E F) (snd 𝕜 E F) p L := (snd 𝕜 E F).has_fderiv_at_filter protected lemma has_fderiv_at_filter.snd (h : has_fderiv_at_filter f₂ f₂' x L) : has_fderiv_at_filter (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x L := has_fderiv_at_filter_snd.comp x h tendsto_map lemma has_fderiv_at_snd : has_fderiv_at (@prod.snd E F) (snd 𝕜 E F) p := has_fderiv_at_filter_snd protected lemma has_fderiv_at.snd (h : has_fderiv_at f₂ f₂' x) : has_fderiv_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x := h.snd lemma has_fderiv_within_at_snd {s : set (E × F)} : has_fderiv_within_at (@prod.snd E F) (snd 𝕜 E F) s p := has_fderiv_at_filter_snd protected lemma has_fderiv_within_at.snd (h : has_fderiv_within_at f₂ f₂' s x) : has_fderiv_within_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') s x := h.snd lemma differentiable_at_snd : differentiable_at 𝕜 prod.snd p := has_fderiv_at_snd.differentiable_at @[simp] protected lemma differentiable_at.snd (h : differentiable_at 𝕜 f₂ x) : differentiable_at 𝕜 (λ x, (f₂ x).2) x := differentiable_at_snd.comp x h lemma differentiable_snd : differentiable 𝕜 (prod.snd : E × F → F) := λ x, differentiable_at_snd @[simp] protected lemma differentiable.snd (h : differentiable 𝕜 f₂) : differentiable 𝕜 (λ x, (f₂ x).2) := differentiable_snd.comp h lemma differentiable_within_at_snd {s : set (E × F)} : differentiable_within_at 𝕜 prod.snd s p := differentiable_at_snd.differentiable_within_at protected lemma differentiable_within_at.snd (h : differentiable_within_at 𝕜 f₂ s x) : differentiable_within_at 𝕜 (λ x, (f₂ x).2) s x := differentiable_at_snd.comp_differentiable_within_at x h lemma differentiable_on_snd {s : set (E × F)} : differentiable_on 𝕜 prod.snd s := differentiable_snd.differentiable_on protected lemma differentiable_on.snd (h : differentiable_on 𝕜 f₂ s) : differentiable_on 𝕜 (λ x, (f₂ x).2) s := differentiable_snd.comp_differentiable_on h lemma fderiv_snd : fderiv 𝕜 prod.snd p = snd 𝕜 E F := has_fderiv_at_snd.fderiv lemma fderiv.snd (h : differentiable_at 𝕜 f₂ x) : fderiv 𝕜 (λ x, (f₂ x).2) x = (snd 𝕜 F G).comp (fderiv 𝕜 f₂ x) := h.has_fderiv_at.snd.fderiv lemma fderiv_within_snd {s : set (E × F)} (hs : unique_diff_within_at 𝕜 s p) : fderiv_within 𝕜 prod.snd s p = snd 𝕜 E F := has_fderiv_within_at_snd.fderiv_within hs lemma fderiv_within.snd (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f₂ s x) : fderiv_within 𝕜 (λ x, (f₂ x).2) s x = (snd 𝕜 F G).comp (fderiv_within 𝕜 f₂ s x) := h.has_fderiv_within_at.snd.fderiv_within hs end snd section prod_map variables {f₂ : G → G'} {f₂' : G →L[𝕜] G'} {y : G} (p : E × G) protected theorem has_strict_fderiv_at.prod_map (hf : has_strict_fderiv_at f f' p.1) (hf₂ : has_strict_fderiv_at f₂ f₂' p.2) : has_strict_fderiv_at (prod.map f f₂) (f'.prod_map f₂') p := (hf.comp p has_strict_fderiv_at_fst).prod (hf₂.comp p has_strict_fderiv_at_snd) protected theorem has_fderiv_at.prod_map (hf : has_fderiv_at f f' p.1) (hf₂ : has_fderiv_at f₂ f₂' p.2) : has_fderiv_at (prod.map f f₂) (f'.prod_map f₂') p := (hf.comp p has_fderiv_at_fst).prod (hf₂.comp p has_fderiv_at_snd) @[simp] protected theorem differentiable_at.prod_map (hf : differentiable_at 𝕜 f p.1) (hf₂ : differentiable_at 𝕜 f₂ p.2) : differentiable_at 𝕜 (λ p : E × G, (f p.1, f₂ p.2)) p := (hf.comp p differentiable_at_fst).prod (hf₂.comp p differentiable_at_snd) end prod_map end cartesian_product section const_smul variables {R : Type*} [semiring R] [module R F] [smul_comm_class 𝕜 R F] [has_continuous_const_smul R F] /-! ### Derivative of a function multiplied by a constant -/ theorem has_strict_fderiv_at.const_smul (h : has_strict_fderiv_at f f' x) (c : R) : has_strict_fderiv_at (λ x, c • f x) (c • f') x := (c • (1 : F →L[𝕜] F)).has_strict_fderiv_at.comp x h theorem has_fderiv_at_filter.const_smul (h : has_fderiv_at_filter f f' x L) (c : R) : has_fderiv_at_filter (λ x, c • f x) (c • f') x L := (c • (1 : F →L[𝕜] F)).has_fderiv_at_filter.comp x h tendsto_map theorem has_fderiv_within_at.const_smul (h : has_fderiv_within_at f f' s x) (c : R) : has_fderiv_within_at (λ x, c • f x) (c • f') s x := h.const_smul c theorem has_fderiv_at.const_smul (h : has_fderiv_at f f' x) (c : R) : has_fderiv_at (λ x, c • f x) (c • f') x := h.const_smul c lemma differentiable_within_at.const_smul (h : differentiable_within_at 𝕜 f s x) (c : R) : differentiable_within_at 𝕜 (λy, c • f y) s x := (h.has_fderiv_within_at.const_smul c).differentiable_within_at lemma differentiable_at.const_smul (h : differentiable_at 𝕜 f x) (c : R) : differentiable_at 𝕜 (λy, c • f y) x := (h.has_fderiv_at.const_smul c).differentiable_at lemma differentiable_on.const_smul (h : differentiable_on 𝕜 f s) (c : R) : differentiable_on 𝕜 (λy, c • f y) s := λx hx, (h x hx).const_smul c lemma differentiable.const_smul (h : differentiable 𝕜 f) (c : R) : differentiable 𝕜 (λy, c • f y) := λx, (h x).const_smul c lemma fderiv_within_const_smul (hxs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f s x) (c : R) : fderiv_within 𝕜 (λy, c • f y) s x = c • fderiv_within 𝕜 f s x := (h.has_fderiv_within_at.const_smul c).fderiv_within hxs lemma fderiv_const_smul (h : differentiable_at 𝕜 f x) (c : R) : fderiv 𝕜 (λy, c • f y) x = c • fderiv 𝕜 f x := (h.has_fderiv_at.const_smul c).fderiv end const_smul section add /-! ### Derivative of the sum of two functions -/ theorem has_strict_fderiv_at.add (hf : has_strict_fderiv_at f f' x) (hg : has_strict_fderiv_at g g' x) : has_strict_fderiv_at (λ y, f y + g y) (f' + g') x := (hf.add hg).congr_left $ λ y, by simp; abel theorem has_fderiv_at_filter.add (hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) : has_fderiv_at_filter (λ y, f y + g y) (f' + g') x L := (hf.add hg).congr_left $ λ _, by simp; abel theorem has_fderiv_within_at.add (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) : has_fderiv_within_at (λ y, f y + g y) (f' + g') s x := hf.add hg theorem has_fderiv_at.add (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) : has_fderiv_at (λ x, f x + g x) (f' + g') x := hf.add hg lemma differentiable_within_at.add (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : differentiable_within_at 𝕜 (λ y, f y + g y) s x := (hf.has_fderiv_within_at.add hg.has_fderiv_within_at).differentiable_within_at @[simp] lemma differentiable_at.add (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : differentiable_at 𝕜 (λ y, f y + g y) x := (hf.has_fderiv_at.add hg.has_fderiv_at).differentiable_at lemma differentiable_on.add (hf : differentiable_on 𝕜 f s) (hg : differentiable_on 𝕜 g s) : differentiable_on 𝕜 (λy, f y + g y) s := λx hx, (hf x hx).add (hg x hx) @[simp] lemma differentiable.add (hf : differentiable 𝕜 f) (hg : differentiable 𝕜 g) : differentiable 𝕜 (λy, f y + g y) := λx, (hf x).add (hg x) lemma fderiv_within_add (hxs : unique_diff_within_at 𝕜 s x) (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : fderiv_within 𝕜 (λy, f y + g y) s x = fderiv_within 𝕜 f s x + fderiv_within 𝕜 g s x := (hf.has_fderiv_within_at.add hg.has_fderiv_within_at).fderiv_within hxs lemma fderiv_add (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : fderiv 𝕜 (λy, f y + g y) x = fderiv 𝕜 f x + fderiv 𝕜 g x := (hf.has_fderiv_at.add hg.has_fderiv_at).fderiv theorem has_strict_fderiv_at.add_const (hf : has_strict_fderiv_at f f' x) (c : F) : has_strict_fderiv_at (λ y, f y + c) f' x := add_zero f' ▸ hf.add (has_strict_fderiv_at_const _ _) theorem has_fderiv_at_filter.add_const (hf : has_fderiv_at_filter f f' x L) (c : F) : has_fderiv_at_filter (λ y, f y + c) f' x L := add_zero f' ▸ hf.add (has_fderiv_at_filter_const _ _ _) theorem has_fderiv_within_at.add_const (hf : has_fderiv_within_at f f' s x) (c : F) : has_fderiv_within_at (λ y, f y + c) f' s x := hf.add_const c theorem has_fderiv_at.add_const (hf : has_fderiv_at f f' x) (c : F): has_fderiv_at (λ x, f x + c) f' x := hf.add_const c lemma differentiable_within_at.add_const (hf : differentiable_within_at 𝕜 f s x) (c : F) : differentiable_within_at 𝕜 (λ y, f y + c) s x := (hf.has_fderiv_within_at.add_const c).differentiable_within_at @[simp] lemma differentiable_within_at_add_const_iff (c : F) : differentiable_within_at 𝕜 (λ y, f y + c) s x ↔ differentiable_within_at 𝕜 f s x := ⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩ lemma differentiable_at.add_const (hf : differentiable_at 𝕜 f x) (c : F) : differentiable_at 𝕜 (λ y, f y + c) x := (hf.has_fderiv_at.add_const c).differentiable_at @[simp] lemma differentiable_at_add_const_iff (c : F) : differentiable_at 𝕜 (λ y, f y + c) x ↔ differentiable_at 𝕜 f x := ⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩ lemma differentiable_on.add_const (hf : differentiable_on 𝕜 f s) (c : F) : differentiable_on 𝕜 (λy, f y + c) s := λx hx, (hf x hx).add_const c @[simp] lemma differentiable_on_add_const_iff (c : F) : differentiable_on 𝕜 (λ y, f y + c) s ↔ differentiable_on 𝕜 f s := ⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩ lemma differentiable.add_const (hf : differentiable 𝕜 f) (c : F) : differentiable 𝕜 (λy, f y + c) := λx, (hf x).add_const c @[simp] lemma differentiable_add_const_iff (c : F) : differentiable 𝕜 (λ y, f y + c) ↔ differentiable 𝕜 f := ⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩ lemma fderiv_within_add_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) : fderiv_within 𝕜 (λy, f y + c) s x = fderiv_within 𝕜 f s x := if hf : differentiable_within_at 𝕜 f s x then (hf.has_fderiv_within_at.add_const c).fderiv_within hxs else by { rw [fderiv_within_zero_of_not_differentiable_within_at hf, fderiv_within_zero_of_not_differentiable_within_at], simpa } lemma fderiv_add_const (c : F) : fderiv 𝕜 (λy, f y + c) x = fderiv 𝕜 f x := by simp only [← fderiv_within_univ, fderiv_within_add_const unique_diff_within_at_univ] theorem has_strict_fderiv_at.const_add (hf : has_strict_fderiv_at f f' x) (c : F) : has_strict_fderiv_at (λ y, c + f y) f' x := zero_add f' ▸ (has_strict_fderiv_at_const _ _).add hf theorem has_fderiv_at_filter.const_add (hf : has_fderiv_at_filter f f' x L) (c : F) : has_fderiv_at_filter (λ y, c + f y) f' x L := zero_add f' ▸ (has_fderiv_at_filter_const _ _ _).add hf theorem has_fderiv_within_at.const_add (hf : has_fderiv_within_at f f' s x) (c : F) : has_fderiv_within_at (λ y, c + f y) f' s x := hf.const_add c theorem has_fderiv_at.const_add (hf : has_fderiv_at f f' x) (c : F): has_fderiv_at (λ x, c + f x) f' x := hf.const_add c lemma differentiable_within_at.const_add (hf : differentiable_within_at 𝕜 f s x) (c : F) : differentiable_within_at 𝕜 (λ y, c + f y) s x := (hf.has_fderiv_within_at.const_add c).differentiable_within_at @[simp] lemma differentiable_within_at_const_add_iff (c : F) : differentiable_within_at 𝕜 (λ y, c + f y) s x ↔ differentiable_within_at 𝕜 f s x := ⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩ lemma differentiable_at.const_add (hf : differentiable_at 𝕜 f x) (c : F) : differentiable_at 𝕜 (λ y, c + f y) x := (hf.has_fderiv_at.const_add c).differentiable_at @[simp] lemma differentiable_at_const_add_iff (c : F) : differentiable_at 𝕜 (λ y, c + f y) x ↔ differentiable_at 𝕜 f x := ⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩ lemma differentiable_on.const_add (hf : differentiable_on 𝕜 f s) (c : F) : differentiable_on 𝕜 (λy, c + f y) s := λx hx, (hf x hx).const_add c @[simp] lemma differentiable_on_const_add_iff (c : F) : differentiable_on 𝕜 (λ y, c + f y) s ↔ differentiable_on 𝕜 f s := ⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩ lemma differentiable.const_add (hf : differentiable 𝕜 f) (c : F) : differentiable 𝕜 (λy, c + f y) := λx, (hf x).const_add c @[simp] lemma differentiable_const_add_iff (c : F) : differentiable 𝕜 (λ y, c + f y) ↔ differentiable 𝕜 f := ⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩ lemma fderiv_within_const_add (hxs : unique_diff_within_at 𝕜 s x) (c : F) : fderiv_within 𝕜 (λy, c + f y) s x = fderiv_within 𝕜 f s x := by simpa only [add_comm] using fderiv_within_add_const hxs c lemma fderiv_const_add (c : F) : fderiv 𝕜 (λy, c + f y) x = fderiv 𝕜 f x := by simp only [add_comm c, fderiv_add_const] end add section sum /-! ### Derivative of a finite sum of functions -/ open_locale big_operators variables {ι : Type*} {u : finset ι} {A : ι → (E → F)} {A' : ι → (E →L[𝕜] F)} theorem has_strict_fderiv_at.sum (h : ∀ i ∈ u, has_strict_fderiv_at (A i) (A' i) x) : has_strict_fderiv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x := begin dsimp [has_strict_fderiv_at] at *, convert is_o.sum h, simp [finset.sum_sub_distrib, continuous_linear_map.sum_apply] end theorem has_fderiv_at_filter.sum (h : ∀ i ∈ u, has_fderiv_at_filter (A i) (A' i) x L) : has_fderiv_at_filter (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x L := begin dsimp [has_fderiv_at_filter] at *, convert is_o.sum h, simp [continuous_linear_map.sum_apply] end theorem has_fderiv_within_at.sum (h : ∀ i ∈ u, has_fderiv_within_at (A i) (A' i) s x) : has_fderiv_within_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) s x := has_fderiv_at_filter.sum h theorem has_fderiv_at.sum (h : ∀ i ∈ u, has_fderiv_at (A i) (A' i) x) : has_fderiv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x := has_fderiv_at_filter.sum h theorem differentiable_within_at.sum (h : ∀ i ∈ u, differentiable_within_at 𝕜 (A i) s x) : differentiable_within_at 𝕜 (λ y, ∑ i in u, A i y) s x := has_fderiv_within_at.differentiable_within_at $ has_fderiv_within_at.sum $ λ i hi, (h i hi).has_fderiv_within_at @[simp] theorem differentiable_at.sum (h : ∀ i ∈ u, differentiable_at 𝕜 (A i) x) : differentiable_at 𝕜 (λ y, ∑ i in u, A i y) x := has_fderiv_at.differentiable_at $ has_fderiv_at.sum $ λ i hi, (h i hi).has_fderiv_at theorem differentiable_on.sum (h : ∀ i ∈ u, differentiable_on 𝕜 (A i) s) : differentiable_on 𝕜 (λ y, ∑ i in u, A i y) s := λ x hx, differentiable_within_at.sum $ λ i hi, h i hi x hx @[simp] theorem differentiable.sum (h : ∀ i ∈ u, differentiable 𝕜 (A i)) : differentiable 𝕜 (λ y, ∑ i in u, A i y) := λ x, differentiable_at.sum $ λ i hi, h i hi x theorem fderiv_within_sum (hxs : unique_diff_within_at 𝕜 s x) (h : ∀ i ∈ u, differentiable_within_at 𝕜 (A i) s x) : fderiv_within 𝕜 (λ y, ∑ i in u, A i y) s x = (∑ i in u, fderiv_within 𝕜 (A i) s x) := (has_fderiv_within_at.sum (λ i hi, (h i hi).has_fderiv_within_at)).fderiv_within hxs theorem fderiv_sum (h : ∀ i ∈ u, differentiable_at 𝕜 (A i) x) : fderiv 𝕜 (λ y, ∑ i in u, A i y) x = (∑ i in u, fderiv 𝕜 (A i) x) := (has_fderiv_at.sum (λ i hi, (h i hi).has_fderiv_at)).fderiv end sum section pi /-! ### Derivatives of functions `f : E → Π i, F' i` In this section we formulate `has_*fderiv*_pi` theorems as `iff`s, and provide two versions of each theorem: * the version without `'` deals with `φ : Π i, E → F' i` and `φ' : Π i, E →L[𝕜] F' i` and is designed to deduce differentiability of `λ x i, φ i x` from differentiability of each `φ i`; * the version with `'` deals with `Φ : E → Π i, F' i` and `Φ' : E →L[𝕜] Π i, F' i` and is designed to deduce differentiability of the components `λ x, Φ x i` from differentiability of `Φ`. -/ variables {ι : Type*} [fintype ι] {F' : ι → Type*} [Π i, normed_group (F' i)] [Π i, normed_space 𝕜 (F' i)] {φ : Π i, E → F' i} {φ' : Π i, E →L[𝕜] F' i} {Φ : E → Π i, F' i} {Φ' : E →L[𝕜] Π i, F' i} @[simp] lemma has_strict_fderiv_at_pi' : has_strict_fderiv_at Φ Φ' x ↔ ∀ i, has_strict_fderiv_at (λ x, Φ x i) ((proj i).comp Φ') x := begin simp only [has_strict_fderiv_at, continuous_linear_map.coe_pi], exact is_o_pi end @[simp] lemma has_strict_fderiv_at_pi : has_strict_fderiv_at (λ x i, φ i x) (continuous_linear_map.pi φ') x ↔ ∀ i, has_strict_fderiv_at (φ i) (φ' i) x := has_strict_fderiv_at_pi' @[simp] lemma has_fderiv_at_filter_pi' : has_fderiv_at_filter Φ Φ' x L ↔ ∀ i, has_fderiv_at_filter (λ x, Φ x i) ((proj i).comp Φ') x L := begin simp only [has_fderiv_at_filter, continuous_linear_map.coe_pi], exact is_o_pi end lemma has_fderiv_at_filter_pi : has_fderiv_at_filter (λ x i, φ i x) (continuous_linear_map.pi φ') x L ↔ ∀ i, has_fderiv_at_filter (φ i) (φ' i) x L := has_fderiv_at_filter_pi' @[simp] lemma has_fderiv_at_pi' : has_fderiv_at Φ Φ' x ↔ ∀ i, has_fderiv_at (λ x, Φ x i) ((proj i).comp Φ') x := has_fderiv_at_filter_pi' lemma has_fderiv_at_pi : has_fderiv_at (λ x i, φ i x) (continuous_linear_map.pi φ') x ↔ ∀ i, has_fderiv_at (φ i) (φ' i) x := has_fderiv_at_filter_pi @[simp] lemma has_fderiv_within_at_pi' : has_fderiv_within_at Φ Φ' s x ↔ ∀ i, has_fderiv_within_at (λ x, Φ x i) ((proj i).comp Φ') s x := has_fderiv_at_filter_pi' lemma has_fderiv_within_at_pi : has_fderiv_within_at (λ x i, φ i x) (continuous_linear_map.pi φ') s x ↔ ∀ i, has_fderiv_within_at (φ i) (φ' i) s x := has_fderiv_at_filter_pi @[simp] lemma differentiable_within_at_pi : differentiable_within_at 𝕜 Φ s x ↔ ∀ i, differentiable_within_at 𝕜 (λ x, Φ x i) s x := ⟨λ h i, (has_fderiv_within_at_pi'.1 h.has_fderiv_within_at i).differentiable_within_at, λ h, (has_fderiv_within_at_pi.2 (λ i, (h i).has_fderiv_within_at)).differentiable_within_at⟩ @[simp] lemma differentiable_at_pi : differentiable_at 𝕜 Φ x ↔ ∀ i, differentiable_at 𝕜 (λ x, Φ x i) x := ⟨λ h i, (has_fderiv_at_pi'.1 h.has_fderiv_at i).differentiable_at, λ h, (has_fderiv_at_pi.2 (λ i, (h i).has_fderiv_at)).differentiable_at⟩ lemma differentiable_on_pi : differentiable_on 𝕜 Φ s ↔ ∀ i, differentiable_on 𝕜 (λ x, Φ x i) s := ⟨λ h i x hx, differentiable_within_at_pi.1 (h x hx) i, λ h x hx, differentiable_within_at_pi.2 (λ i, h i x hx)⟩ lemma differentiable_pi : differentiable 𝕜 Φ ↔ ∀ i, differentiable 𝕜 (λ x, Φ x i) := ⟨λ h i x, differentiable_at_pi.1 (h x) i, λ h x, differentiable_at_pi.2 (λ i, h i x)⟩ -- TODO: find out which version (`φ` or `Φ`) works better with `rw`/`simp` lemma fderiv_within_pi (h : ∀ i, differentiable_within_at 𝕜 (φ i) s x) (hs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (λ x i, φ i x) s x = pi (λ i, fderiv_within 𝕜 (φ i) s x) := (has_fderiv_within_at_pi.2 (λ i, (h i).has_fderiv_within_at)).fderiv_within hs lemma fderiv_pi (h : ∀ i, differentiable_at 𝕜 (φ i) x) : fderiv 𝕜 (λ x i, φ i x) x = pi (λ i, fderiv 𝕜 (φ i) x) := (has_fderiv_at_pi.2 (λ i, (h i).has_fderiv_at)).fderiv end pi section neg /-! ### Derivative of the negative of a function -/ theorem has_strict_fderiv_at.neg (h : has_strict_fderiv_at f f' x) : has_strict_fderiv_at (λ x, -f x) (-f') x := (-1 : F →L[𝕜] F).has_strict_fderiv_at.comp x h theorem has_fderiv_at_filter.neg (h : has_fderiv_at_filter f f' x L) : has_fderiv_at_filter (λ x, -f x) (-f') x L := (-1 : F →L[𝕜] F).has_fderiv_at_filter.comp x h tendsto_map theorem has_fderiv_within_at.neg (h : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, -f x) (-f') s x := h.neg theorem has_fderiv_at.neg (h : has_fderiv_at f f' x) : has_fderiv_at (λ x, -f x) (-f') x := h.neg lemma differentiable_within_at.neg (h : differentiable_within_at 𝕜 f s x) : differentiable_within_at 𝕜 (λy, -f y) s x := h.has_fderiv_within_at.neg.differentiable_within_at @[simp] lemma differentiable_within_at_neg_iff : differentiable_within_at 𝕜 (λy, -f y) s x ↔ differentiable_within_at 𝕜 f s x := ⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩ lemma differentiable_at.neg (h : differentiable_at 𝕜 f x) : differentiable_at 𝕜 (λy, -f y) x := h.has_fderiv_at.neg.differentiable_at @[simp] lemma differentiable_at_neg_iff : differentiable_at 𝕜 (λy, -f y) x ↔ differentiable_at 𝕜 f x := ⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩ lemma differentiable_on.neg (h : differentiable_on 𝕜 f s) : differentiable_on 𝕜 (λy, -f y) s := λx hx, (h x hx).neg @[simp] lemma differentiable_on_neg_iff : differentiable_on 𝕜 (λy, -f y) s ↔ differentiable_on 𝕜 f s := ⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩ lemma differentiable.neg (h : differentiable 𝕜 f) : differentiable 𝕜 (λy, -f y) := λx, (h x).neg @[simp] lemma differentiable_neg_iff : differentiable 𝕜 (λy, -f y) ↔ differentiable 𝕜 f := ⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩ lemma fderiv_within_neg (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (λy, -f y) s x = - fderiv_within 𝕜 f s x := if h : differentiable_within_at 𝕜 f s x then h.has_fderiv_within_at.neg.fderiv_within hxs else by { rw [fderiv_within_zero_of_not_differentiable_within_at h, fderiv_within_zero_of_not_differentiable_within_at, neg_zero], simpa } @[simp] lemma fderiv_neg : fderiv 𝕜 (λy, -f y) x = - fderiv 𝕜 f x := by simp only [← fderiv_within_univ, fderiv_within_neg unique_diff_within_at_univ] end neg section sub /-! ### Derivative of the difference of two functions -/ theorem has_strict_fderiv_at.sub (hf : has_strict_fderiv_at f f' x) (hg : has_strict_fderiv_at g g' x) : has_strict_fderiv_at (λ x, f x - g x) (f' - g') x := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem has_fderiv_at_filter.sub (hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) : has_fderiv_at_filter (λ x, f x - g x) (f' - g') x L := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem has_fderiv_within_at.sub (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) : has_fderiv_within_at (λ x, f x - g x) (f' - g') s x := hf.sub hg theorem has_fderiv_at.sub (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) : has_fderiv_at (λ x, f x - g x) (f' - g') x := hf.sub hg lemma differentiable_within_at.sub (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : differentiable_within_at 𝕜 (λ y, f y - g y) s x := (hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).differentiable_within_at @[simp] lemma differentiable_at.sub (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : differentiable_at 𝕜 (λ y, f y - g y) x := (hf.has_fderiv_at.sub hg.has_fderiv_at).differentiable_at lemma differentiable_on.sub (hf : differentiable_on 𝕜 f s) (hg : differentiable_on 𝕜 g s) : differentiable_on 𝕜 (λy, f y - g y) s := λx hx, (hf x hx).sub (hg x hx) @[simp] lemma differentiable.sub (hf : differentiable 𝕜 f) (hg : differentiable 𝕜 g) : differentiable 𝕜 (λy, f y - g y) := λx, (hf x).sub (hg x) lemma fderiv_within_sub (hxs : unique_diff_within_at 𝕜 s x) (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : fderiv_within 𝕜 (λy, f y - g y) s x = fderiv_within 𝕜 f s x - fderiv_within 𝕜 g s x := (hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).fderiv_within hxs lemma fderiv_sub (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : fderiv 𝕜 (λy, f y - g y) x = fderiv 𝕜 f x - fderiv 𝕜 g x := (hf.has_fderiv_at.sub hg.has_fderiv_at).fderiv theorem has_strict_fderiv_at.sub_const (hf : has_strict_fderiv_at f f' x) (c : F) : has_strict_fderiv_at (λ x, f x - c) f' x := by simpa only [sub_eq_add_neg] using hf.add_const (-c) theorem has_fderiv_at_filter.sub_const (hf : has_fderiv_at_filter f f' x L) (c : F) : has_fderiv_at_filter (λ x, f x - c) f' x L := by simpa only [sub_eq_add_neg] using hf.add_const (-c) theorem has_fderiv_within_at.sub_const (hf : has_fderiv_within_at f f' s x) (c : F) : has_fderiv_within_at (λ x, f x - c) f' s x := hf.sub_const c theorem has_fderiv_at.sub_const (hf : has_fderiv_at f f' x) (c : F) : has_fderiv_at (λ x, f x - c) f' x := hf.sub_const c lemma differentiable_within_at.sub_const (hf : differentiable_within_at 𝕜 f s x) (c : F) : differentiable_within_at 𝕜 (λ y, f y - c) s x := (hf.has_fderiv_within_at.sub_const c).differentiable_within_at @[simp] lemma differentiable_within_at_sub_const_iff (c : F) : differentiable_within_at 𝕜 (λ y, f y - c) s x ↔ differentiable_within_at 𝕜 f s x := by simp only [sub_eq_add_neg, differentiable_within_at_add_const_iff] lemma differentiable_at.sub_const (hf : differentiable_at 𝕜 f x) (c : F) : differentiable_at 𝕜 (λ y, f y - c) x := (hf.has_fderiv_at.sub_const c).differentiable_at @[simp] lemma differentiable_at_sub_const_iff (c : F) : differentiable_at 𝕜 (λ y, f y - c) x ↔ differentiable_at 𝕜 f x := by simp only [sub_eq_add_neg, differentiable_at_add_const_iff] lemma differentiable_on.sub_const (hf : differentiable_on 𝕜 f s) (c : F) : differentiable_on 𝕜 (λy, f y - c) s := λx hx, (hf x hx).sub_const c @[simp] lemma differentiable_on_sub_const_iff (c : F) : differentiable_on 𝕜 (λ y, f y - c) s ↔ differentiable_on 𝕜 f s := by simp only [sub_eq_add_neg, differentiable_on_add_const_iff] lemma differentiable.sub_const (hf : differentiable 𝕜 f) (c : F) : differentiable 𝕜 (λy, f y - c) := λx, (hf x).sub_const c @[simp] lemma differentiable_sub_const_iff (c : F) : differentiable 𝕜 (λ y, f y - c) ↔ differentiable 𝕜 f := by simp only [sub_eq_add_neg, differentiable_add_const_iff] lemma fderiv_within_sub_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) : fderiv_within 𝕜 (λy, f y - c) s x = fderiv_within 𝕜 f s x := by simp only [sub_eq_add_neg, fderiv_within_add_const hxs] lemma fderiv_sub_const (c : F) : fderiv 𝕜 (λy, f y - c) x = fderiv 𝕜 f x := by simp only [sub_eq_add_neg, fderiv_add_const] theorem has_strict_fderiv_at.const_sub (hf : has_strict_fderiv_at f f' x) (c : F) : has_strict_fderiv_at (λ x, c - f x) (-f') x := by simpa only [sub_eq_add_neg] using hf.neg.const_add c theorem has_fderiv_at_filter.const_sub (hf : has_fderiv_at_filter f f' x L) (c : F) : has_fderiv_at_filter (λ x, c - f x) (-f') x L := by simpa only [sub_eq_add_neg] using hf.neg.const_add c theorem has_fderiv_within_at.const_sub (hf : has_fderiv_within_at f f' s x) (c : F) : has_fderiv_within_at (λ x, c - f x) (-f') s x := hf.const_sub c theorem has_fderiv_at.const_sub (hf : has_fderiv_at f f' x) (c : F) : has_fderiv_at (λ x, c - f x) (-f') x := hf.const_sub c lemma differentiable_within_at.const_sub (hf : differentiable_within_at 𝕜 f s x) (c : F) : differentiable_within_at 𝕜 (λ y, c - f y) s x := (hf.has_fderiv_within_at.const_sub c).differentiable_within_at @[simp] lemma differentiable_within_at_const_sub_iff (c : F) : differentiable_within_at 𝕜 (λ y, c - f y) s x ↔ differentiable_within_at 𝕜 f s x := by simp [sub_eq_add_neg] lemma differentiable_at.const_sub (hf : differentiable_at 𝕜 f x) (c : F) : differentiable_at 𝕜 (λ y, c - f y) x := (hf.has_fderiv_at.const_sub c).differentiable_at @[simp] lemma differentiable_at_const_sub_iff (c : F) : differentiable_at 𝕜 (λ y, c - f y) x ↔ differentiable_at 𝕜 f x := by simp [sub_eq_add_neg] lemma differentiable_on.const_sub (hf : differentiable_on 𝕜 f s) (c : F) : differentiable_on 𝕜 (λy, c - f y) s := λx hx, (hf x hx).const_sub c @[simp] lemma differentiable_on_const_sub_iff (c : F) : differentiable_on 𝕜 (λ y, c - f y) s ↔ differentiable_on 𝕜 f s := by simp [sub_eq_add_neg] lemma differentiable.const_sub (hf : differentiable 𝕜 f) (c : F) : differentiable 𝕜 (λy, c - f y) := λx, (hf x).const_sub c @[simp] lemma differentiable_const_sub_iff (c : F) : differentiable 𝕜 (λ y, c - f y) ↔ differentiable 𝕜 f := by simp [sub_eq_add_neg] lemma fderiv_within_const_sub (hxs : unique_diff_within_at 𝕜 s x) (c : F) : fderiv_within 𝕜 (λy, c - f y) s x = -fderiv_within 𝕜 f s x := by simp only [sub_eq_add_neg, fderiv_within_const_add, fderiv_within_neg, hxs] lemma fderiv_const_sub (c : F) : fderiv 𝕜 (λy, c - f y) x = -fderiv 𝕜 f x := by simp only [← fderiv_within_univ, fderiv_within_const_sub unique_diff_within_at_univ] end sub section bilinear_map /-! ### Derivative of a bounded bilinear map -/ variables {b : E × F → G} {u : set (E × F) } open normed_field lemma is_bounded_bilinear_map.has_strict_fderiv_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : has_strict_fderiv_at b (h.deriv p) p := begin rw has_strict_fderiv_at, set T := (E × F) × (E × F), have : (λ q : T, b (q.1 - q.2)) =o[𝓝 (p, p)] (λ q : T, ∥q.1 - q.2∥ * 1), { refine (h.is_O'.comp_tendsto le_top).trans_is_o _, simp only [(∘)], refine (is_O_refl (λ q : T, ∥q.1 - q.2∥) _).mul_is_o (is_o.norm_left $ (is_o_one_iff _).2 _), rw [← sub_self p], exact continuous_at_fst.sub continuous_at_snd }, simp only [mul_one, is_o_norm_right] at this, refine (is_o.congr_of_sub _).1 this, clear this, convert_to (λ q : T, h.deriv (p - q.2) (q.1 - q.2)) =o[𝓝 (p, p)] (λ q : T, q.1 - q.2), { ext ⟨⟨x₁, y₁⟩, ⟨x₂, y₂⟩⟩, rcases p with ⟨x, y⟩, simp only [is_bounded_bilinear_map_deriv_coe, prod.mk_sub_mk, h.map_sub_left, h.map_sub_right], abel }, have : (λ q : T, p - q.2) =o[𝓝 (p, p)] (λ q, (1:ℝ)), from (is_o_one_iff _).2 (sub_self p ▸ tendsto_const_nhds.sub continuous_at_snd), apply is_bounded_bilinear_map_apply.is_O_comp.trans_is_o, refine is_o.trans_is_O _ (is_O_const_mul_self 1 _ _).of_norm_right, refine is_o.mul_is_O _ (is_O_refl _ _), exact (((h.is_bounded_linear_map_deriv.is_O_id ⊤).comp_tendsto le_top : _).trans_is_o this).norm_left end lemma is_bounded_bilinear_map.has_fderiv_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : has_fderiv_at b (h.deriv p) p := (h.has_strict_fderiv_at p).has_fderiv_at lemma is_bounded_bilinear_map.has_fderiv_within_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : has_fderiv_within_at b (h.deriv p) u p := (h.has_fderiv_at p).has_fderiv_within_at lemma is_bounded_bilinear_map.differentiable_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : differentiable_at 𝕜 b p := (h.has_fderiv_at p).differentiable_at lemma is_bounded_bilinear_map.differentiable_within_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : differentiable_within_at 𝕜 b u p := (h.differentiable_at p).differentiable_within_at lemma is_bounded_bilinear_map.fderiv (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : fderiv 𝕜 b p = h.deriv p := has_fderiv_at.fderiv (h.has_fderiv_at p) lemma is_bounded_bilinear_map.fderiv_within (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) (hxs : unique_diff_within_at 𝕜 u p) : fderiv_within 𝕜 b u p = h.deriv p := begin rw differentiable_at.fderiv_within (h.differentiable_at p) hxs, exact h.fderiv p end lemma is_bounded_bilinear_map.differentiable (h : is_bounded_bilinear_map 𝕜 b) : differentiable 𝕜 b := λx, h.differentiable_at x lemma is_bounded_bilinear_map.differentiable_on (h : is_bounded_bilinear_map 𝕜 b) : differentiable_on 𝕜 b u := h.differentiable.differentiable_on end bilinear_map section clm_comp_apply /-! ### Derivative of the pointwise composition/application of continuous linear maps -/ variables {H : Type*} [normed_group H] [normed_space 𝕜 H] {c : E → G →L[𝕜] H} {c' : E →L[𝕜] G →L[𝕜] H} {d : E → F →L[𝕜] G} {d' : E →L[𝕜] F →L[𝕜] G} {u : E → G} {u' : E →L[𝕜] G} lemma has_strict_fderiv_at.clm_comp (hc : has_strict_fderiv_at c c' x) (hd : has_strict_fderiv_at d d' x) : has_strict_fderiv_at (λ y, (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x := (is_bounded_bilinear_map_comp.has_strict_fderiv_at (c x, d x)).comp x $ hc.prod hd lemma has_fderiv_within_at.clm_comp (hc : has_fderiv_within_at c c' s x) (hd : has_fderiv_within_at d d' s x) : has_fderiv_within_at (λ y, (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') s x := (is_bounded_bilinear_map_comp.has_fderiv_at (c x, d x)).comp_has_fderiv_within_at x $ hc.prod hd lemma has_fderiv_at.clm_comp (hc : has_fderiv_at c c' x) (hd : has_fderiv_at d d' x) : has_fderiv_at (λ y, (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x := (is_bounded_bilinear_map_comp.has_fderiv_at (c x, d x)).comp x $ hc.prod hd lemma differentiable_within_at.clm_comp (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) : differentiable_within_at 𝕜 (λ y, (c y).comp (d y)) s x := (hc.has_fderiv_within_at.clm_comp hd.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.clm_comp (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) : differentiable_at 𝕜 (λ y, (c y).comp (d y)) x := (hc.has_fderiv_at.clm_comp hd.has_fderiv_at).differentiable_at lemma differentiable_on.clm_comp (hc : differentiable_on 𝕜 c s) (hd : differentiable_on 𝕜 d s) : differentiable_on 𝕜 (λ y, (c y).comp (d y)) s := λx hx, (hc x hx).clm_comp (hd x hx) lemma differentiable.clm_comp (hc : differentiable 𝕜 c) (hd : differentiable 𝕜 d) : differentiable 𝕜 (λ y, (c y).comp (d y)) := λx, (hc x).clm_comp (hd x) lemma fderiv_within_clm_comp (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) : fderiv_within 𝕜 (λ y, (c y).comp (d y)) s x = (compL 𝕜 F G H (c x)).comp (fderiv_within 𝕜 d s x) + ((compL 𝕜 F G H).flip (d x)).comp (fderiv_within 𝕜 c s x) := (hc.has_fderiv_within_at.clm_comp hd.has_fderiv_within_at).fderiv_within hxs lemma fderiv_clm_comp (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) : fderiv 𝕜 (λ y, (c y).comp (d y)) x = (compL 𝕜 F G H (c x)).comp (fderiv 𝕜 d x) + ((compL 𝕜 F G H).flip (d x)).comp (fderiv 𝕜 c x) := (hc.has_fderiv_at.clm_comp hd.has_fderiv_at).fderiv lemma has_strict_fderiv_at.clm_apply (hc : has_strict_fderiv_at c c' x) (hu : has_strict_fderiv_at u u' x) : has_strict_fderiv_at (λ y, (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x := (is_bounded_bilinear_map_apply.has_strict_fderiv_at (c x, u x)).comp x (hc.prod hu) lemma has_fderiv_within_at.clm_apply (hc : has_fderiv_within_at c c' s x) (hu : has_fderiv_within_at u u' s x) : has_fderiv_within_at (λ y, (c y) (u y)) ((c x).comp u' + c'.flip (u x)) s x := (is_bounded_bilinear_map_apply.has_fderiv_at (c x, u x)).comp_has_fderiv_within_at x (hc.prod hu) lemma has_fderiv_at.clm_apply (hc : has_fderiv_at c c' x) (hu : has_fderiv_at u u' x) : has_fderiv_at (λ y, (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x := (is_bounded_bilinear_map_apply.has_fderiv_at (c x, u x)).comp x (hc.prod hu) lemma differentiable_within_at.clm_apply (hc : differentiable_within_at 𝕜 c s x) (hu : differentiable_within_at 𝕜 u s x) : differentiable_within_at 𝕜 (λ y, (c y) (u y)) s x := (hc.has_fderiv_within_at.clm_apply hu.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.clm_apply (hc : differentiable_at 𝕜 c x) (hu : differentiable_at 𝕜 u x) : differentiable_at 𝕜 (λ y, (c y) (u y)) x := (hc.has_fderiv_at.clm_apply hu.has_fderiv_at).differentiable_at lemma differentiable_on.clm_apply (hc : differentiable_on 𝕜 c s) (hu : differentiable_on 𝕜 u s) : differentiable_on 𝕜 (λ y, (c y) (u y)) s := λx hx, (hc x hx).clm_apply (hu x hx) lemma differentiable.clm_apply (hc : differentiable 𝕜 c) (hu : differentiable 𝕜 u) : differentiable 𝕜 (λ y, (c y) (u y)) := λx, (hc x).clm_apply (hu x) lemma fderiv_within_clm_apply (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (hu : differentiable_within_at 𝕜 u s x) : fderiv_within 𝕜 (λ y, (c y) (u y)) s x = ((c x).comp (fderiv_within 𝕜 u s x) + (fderiv_within 𝕜 c s x).flip (u x)) := (hc.has_fderiv_within_at.clm_apply hu.has_fderiv_within_at).fderiv_within hxs lemma fderiv_clm_apply (hc : differentiable_at 𝕜 c x) (hu : differentiable_at 𝕜 u x) : fderiv 𝕜 (λ y, (c y) (u y)) x = ((c x).comp (fderiv 𝕜 u x) + (fderiv 𝕜 c x).flip (u x)) := (hc.has_fderiv_at.clm_apply hu.has_fderiv_at).fderiv end clm_comp_apply section smul /-! ### Derivative of the product of a scalar-valued function and a vector-valued function If `c` is a differentiable scalar-valued function and `f` is a differentiable vector-valued function, then `λ x, c x • f x` is differentiable as well. Lemmas in this section works for function `c` taking values in the base field, as well as in a normed algebra over the base field: e.g., they work for `c : E → ℂ` and `f : E → F` provided that `F` is a complex normed vector space. -/ variables {𝕜' : Type*} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜 𝕜'] [normed_space 𝕜' F] [is_scalar_tower 𝕜 𝕜' F] variables {c : E → 𝕜'} {c' : E →L[𝕜] 𝕜'} theorem has_strict_fderiv_at.smul (hc : has_strict_fderiv_at c c' x) (hf : has_strict_fderiv_at f f' x) : has_strict_fderiv_at (λ y, c y • f y) (c x • f' + c'.smul_right (f x)) x := (is_bounded_bilinear_map_smul.has_strict_fderiv_at (c x, f x)).comp x $ hc.prod hf theorem has_fderiv_within_at.smul (hc : has_fderiv_within_at c c' s x) (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ y, c y • f y) (c x • f' + c'.smul_right (f x)) s x := (is_bounded_bilinear_map_smul.has_fderiv_at (c x, f x)).comp_has_fderiv_within_at x $ hc.prod hf theorem has_fderiv_at.smul (hc : has_fderiv_at c c' x) (hf : has_fderiv_at f f' x) : has_fderiv_at (λ y, c y • f y) (c x • f' + c'.smul_right (f x)) x := (is_bounded_bilinear_map_smul.has_fderiv_at (c x, f x)).comp x $ hc.prod hf lemma differentiable_within_at.smul (hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) : differentiable_within_at 𝕜 (λ y, c y • f y) s x := (hc.has_fderiv_within_at.smul hf.has_fderiv_within_at).differentiable_within_at @[simp] lemma differentiable_at.smul (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) : differentiable_at 𝕜 (λ y, c y • f y) x := (hc.has_fderiv_at.smul hf.has_fderiv_at).differentiable_at lemma differentiable_on.smul (hc : differentiable_on 𝕜 c s) (hf : differentiable_on 𝕜 f s) : differentiable_on 𝕜 (λ y, c y • f y) s := λx hx, (hc x hx).smul (hf x hx) @[simp] lemma differentiable.smul (hc : differentiable 𝕜 c) (hf : differentiable 𝕜 f) : differentiable 𝕜 (λ y, c y • f y) := λx, (hc x).smul (hf x) lemma fderiv_within_smul (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) : fderiv_within 𝕜 (λ y, c y • f y) s x = c x • fderiv_within 𝕜 f s x + (fderiv_within 𝕜 c s x).smul_right (f x) := (hc.has_fderiv_within_at.smul hf.has_fderiv_within_at).fderiv_within hxs lemma fderiv_smul (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) : fderiv 𝕜 (λ y, c y • f y) x = c x • fderiv 𝕜 f x + (fderiv 𝕜 c x).smul_right (f x) := (hc.has_fderiv_at.smul hf.has_fderiv_at).fderiv theorem has_strict_fderiv_at.smul_const (hc : has_strict_fderiv_at c c' x) (f : F) : has_strict_fderiv_at (λ y, c y • f) (c'.smul_right f) x := by simpa only [smul_zero, zero_add] using hc.smul (has_strict_fderiv_at_const f x) theorem has_fderiv_within_at.smul_const (hc : has_fderiv_within_at c c' s x) (f : F) : has_fderiv_within_at (λ y, c y • f) (c'.smul_right f) s x := by simpa only [smul_zero, zero_add] using hc.smul (has_fderiv_within_at_const f x s) theorem has_fderiv_at.smul_const (hc : has_fderiv_at c c' x) (f : F) : has_fderiv_at (λ y, c y • f) (c'.smul_right f) x := by simpa only [smul_zero, zero_add] using hc.smul (has_fderiv_at_const f x) lemma differentiable_within_at.smul_const (hc : differentiable_within_at 𝕜 c s x) (f : F) : differentiable_within_at 𝕜 (λ y, c y • f) s x := (hc.has_fderiv_within_at.smul_const f).differentiable_within_at lemma differentiable_at.smul_const (hc : differentiable_at 𝕜 c x) (f : F) : differentiable_at 𝕜 (λ y, c y • f) x := (hc.has_fderiv_at.smul_const f).differentiable_at lemma differentiable_on.smul_const (hc : differentiable_on 𝕜 c s) (f : F) : differentiable_on 𝕜 (λ y, c y • f) s := λx hx, (hc x hx).smul_const f lemma differentiable.smul_const (hc : differentiable 𝕜 c) (f : F) : differentiable 𝕜 (λ y, c y • f) := λx, (hc x).smul_const f lemma fderiv_within_smul_const (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (f : F) : fderiv_within 𝕜 (λ y, c y • f) s x = (fderiv_within 𝕜 c s x).smul_right f := (hc.has_fderiv_within_at.smul_const f).fderiv_within hxs lemma fderiv_smul_const (hc : differentiable_at 𝕜 c x) (f : F) : fderiv 𝕜 (λ y, c y • f) x = (fderiv 𝕜 c x).smul_right f := (hc.has_fderiv_at.smul_const f).fderiv end smul section mul /-! ### Derivative of the product of two functions -/ variables {𝔸 𝔸' : Type*} [normed_ring 𝔸] [normed_comm_ring 𝔸'] [normed_algebra 𝕜 𝔸] [normed_algebra 𝕜 𝔸'] {a b : E → 𝔸} {a' b' : E →L[𝕜] 𝔸} {c d : E → 𝔸'} {c' d' : E →L[𝕜] 𝔸'} theorem has_strict_fderiv_at.mul' {x : E} (ha : has_strict_fderiv_at a a' x) (hb : has_strict_fderiv_at b b' x) : has_strict_fderiv_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) x := ((continuous_linear_map.lmul 𝕜 𝔸).is_bounded_bilinear_map.has_strict_fderiv_at (a x, b x)).comp x (ha.prod hb) theorem has_strict_fderiv_at.mul (hc : has_strict_fderiv_at c c' x) (hd : has_strict_fderiv_at d d' x) : has_strict_fderiv_at (λ y, c y * d y) (c x • d' + d x • c') x := by { convert hc.mul' hd, ext z, apply mul_comm } theorem has_fderiv_within_at.mul' (ha : has_fderiv_within_at a a' s x) (hb : has_fderiv_within_at b b' s x) : has_fderiv_within_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) s x := ((continuous_linear_map.lmul 𝕜 𝔸).is_bounded_bilinear_map.has_fderiv_at (a x, b x)).comp_has_fderiv_within_at x (ha.prod hb) theorem has_fderiv_within_at.mul (hc : has_fderiv_within_at c c' s x) (hd : has_fderiv_within_at d d' s x) : has_fderiv_within_at (λ y, c y * d y) (c x • d' + d x • c') s x := by { convert hc.mul' hd, ext z, apply mul_comm } theorem has_fderiv_at.mul' (ha : has_fderiv_at a a' x) (hb : has_fderiv_at b b' x) : has_fderiv_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) x := ((continuous_linear_map.lmul 𝕜 𝔸).is_bounded_bilinear_map.has_fderiv_at (a x, b x)).comp x (ha.prod hb) theorem has_fderiv_at.mul (hc : has_fderiv_at c c' x) (hd : has_fderiv_at d d' x) : has_fderiv_at (λ y, c y * d y) (c x • d' + d x • c') x := by { convert hc.mul' hd, ext z, apply mul_comm } lemma differentiable_within_at.mul (ha : differentiable_within_at 𝕜 a s x) (hb : differentiable_within_at 𝕜 b s x) : differentiable_within_at 𝕜 (λ y, a y * b y) s x := (ha.has_fderiv_within_at.mul' hb.has_fderiv_within_at).differentiable_within_at @[simp] lemma differentiable_at.mul (ha : differentiable_at 𝕜 a x) (hb : differentiable_at 𝕜 b x) : differentiable_at 𝕜 (λ y, a y * b y) x := (ha.has_fderiv_at.mul' hb.has_fderiv_at).differentiable_at lemma differentiable_on.mul (ha : differentiable_on 𝕜 a s) (hb : differentiable_on 𝕜 b s) : differentiable_on 𝕜 (λ y, a y * b y) s := λx hx, (ha x hx).mul (hb x hx) @[simp] lemma differentiable.mul (ha : differentiable 𝕜 a) (hb : differentiable 𝕜 b) : differentiable 𝕜 (λ y, a y * b y) := λx, (ha x).mul (hb x) lemma fderiv_within_mul' (hxs : unique_diff_within_at 𝕜 s x) (ha : differentiable_within_at 𝕜 a s x) (hb : differentiable_within_at 𝕜 b s x) : fderiv_within 𝕜 (λ y, a y * b y) s x = a x • fderiv_within 𝕜 b s x + (fderiv_within 𝕜 a s x).smul_right (b x) := (ha.has_fderiv_within_at.mul' hb.has_fderiv_within_at).fderiv_within hxs lemma fderiv_within_mul (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) : fderiv_within 𝕜 (λ y, c y * d y) s x = c x • fderiv_within 𝕜 d s x + d x • fderiv_within 𝕜 c s x := (hc.has_fderiv_within_at.mul hd.has_fderiv_within_at).fderiv_within hxs lemma fderiv_mul' (ha : differentiable_at 𝕜 a x) (hb : differentiable_at 𝕜 b x) : fderiv 𝕜 (λ y, a y * b y) x = a x • fderiv 𝕜 b x + (fderiv 𝕜 a x).smul_right (b x) := (ha.has_fderiv_at.mul' hb.has_fderiv_at).fderiv lemma fderiv_mul (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) : fderiv 𝕜 (λ y, c y * d y) x = c x • fderiv 𝕜 d x + d x • fderiv 𝕜 c x := (hc.has_fderiv_at.mul hd.has_fderiv_at).fderiv theorem has_strict_fderiv_at.mul_const' (ha : has_strict_fderiv_at a a' x) (b : 𝔸) : has_strict_fderiv_at (λ y, a y * b) (a'.smul_right b) x := (((continuous_linear_map.lmul 𝕜 𝔸).flip b).has_strict_fderiv_at).comp x ha theorem has_strict_fderiv_at.mul_const (hc : has_strict_fderiv_at c c' x) (d : 𝔸') : has_strict_fderiv_at (λ y, c y * d) (d • c') x := by { convert hc.mul_const' d, ext z, apply mul_comm } theorem has_fderiv_within_at.mul_const' (ha : has_fderiv_within_at a a' s x) (b : 𝔸) : has_fderiv_within_at (λ y, a y * b) (a'.smul_right b) s x := (((continuous_linear_map.lmul 𝕜 𝔸).flip b).has_fderiv_at).comp_has_fderiv_within_at x ha theorem has_fderiv_within_at.mul_const (hc : has_fderiv_within_at c c' s x) (d : 𝔸') : has_fderiv_within_at (λ y, c y * d) (d • c') s x := by { convert hc.mul_const' d, ext z, apply mul_comm } theorem has_fderiv_at.mul_const' (ha : has_fderiv_at a a' x) (b : 𝔸) : has_fderiv_at (λ y, a y * b) (a'.smul_right b) x := (((continuous_linear_map.lmul 𝕜 𝔸).flip b).has_fderiv_at).comp x ha theorem has_fderiv_at.mul_const (hc : has_fderiv_at c c' x) (d : 𝔸') : has_fderiv_at (λ y, c y * d) (d • c') x := by { convert hc.mul_const' d, ext z, apply mul_comm } lemma differentiable_within_at.mul_const (ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) : differentiable_within_at 𝕜 (λ y, a y * b) s x := (ha.has_fderiv_within_at.mul_const' b).differentiable_within_at lemma differentiable_at.mul_const (ha : differentiable_at 𝕜 a x) (b : 𝔸) : differentiable_at 𝕜 (λ y, a y * b) x := (ha.has_fderiv_at.mul_const' b).differentiable_at lemma differentiable_on.mul_const (ha : differentiable_on 𝕜 a s) (b : 𝔸) : differentiable_on 𝕜 (λ y, a y * b) s := λx hx, (ha x hx).mul_const b lemma differentiable.mul_const (ha : differentiable 𝕜 a) (b : 𝔸) : differentiable 𝕜 (λ y, a y * b) := λx, (ha x).mul_const b lemma fderiv_within_mul_const' (hxs : unique_diff_within_at 𝕜 s x) (ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) : fderiv_within 𝕜 (λ y, a y * b) s x = (fderiv_within 𝕜 a s x).smul_right b := (ha.has_fderiv_within_at.mul_const' b).fderiv_within hxs lemma fderiv_within_mul_const (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (d : 𝔸') : fderiv_within 𝕜 (λ y, c y * d) s x = d • fderiv_within 𝕜 c s x := (hc.has_fderiv_within_at.mul_const d).fderiv_within hxs lemma fderiv_mul_const' (ha : differentiable_at 𝕜 a x) (b : 𝔸) : fderiv 𝕜 (λ y, a y * b) x = (fderiv 𝕜 a x).smul_right b := (ha.has_fderiv_at.mul_const' b).fderiv lemma fderiv_mul_const (hc : differentiable_at 𝕜 c x) (d : 𝔸') : fderiv 𝕜 (λ y, c y * d) x = d • fderiv 𝕜 c x := (hc.has_fderiv_at.mul_const d).fderiv theorem has_strict_fderiv_at.const_mul (ha : has_strict_fderiv_at a a' x) (b : 𝔸) : has_strict_fderiv_at (λ y, b * a y) (b • a') x := (((continuous_linear_map.lmul 𝕜 𝔸) b).has_strict_fderiv_at).comp x ha theorem has_fderiv_within_at.const_mul (ha : has_fderiv_within_at a a' s x) (b : 𝔸) : has_fderiv_within_at (λ y, b * a y) (b • a') s x := (((continuous_linear_map.lmul 𝕜 𝔸) b).has_fderiv_at).comp_has_fderiv_within_at x ha theorem has_fderiv_at.const_mul (ha : has_fderiv_at a a' x) (b : 𝔸) : has_fderiv_at (λ y, b * a y) (b • a') x := (((continuous_linear_map.lmul 𝕜 𝔸) b).has_fderiv_at).comp x ha lemma differentiable_within_at.const_mul (ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) : differentiable_within_at 𝕜 (λ y, b * a y) s x := (ha.has_fderiv_within_at.const_mul b).differentiable_within_at lemma differentiable_at.const_mul (ha : differentiable_at 𝕜 a x) (b : 𝔸) : differentiable_at 𝕜 (λ y, b * a y) x := (ha.has_fderiv_at.const_mul b).differentiable_at lemma differentiable_on.const_mul (ha : differentiable_on 𝕜 a s) (b : 𝔸) : differentiable_on 𝕜 (λ y, b * a y) s := λx hx, (ha x hx).const_mul b lemma differentiable.const_mul (ha : differentiable 𝕜 a) (b : 𝔸) : differentiable 𝕜 (λ y, b * a y) := λx, (ha x).const_mul b lemma fderiv_within_const_mul (hxs : unique_diff_within_at 𝕜 s x) (ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) : fderiv_within 𝕜 (λ y, b * a y) s x = b • fderiv_within 𝕜 a s x := (ha.has_fderiv_within_at.const_mul b).fderiv_within hxs lemma fderiv_const_mul (ha : differentiable_at 𝕜 a x) (b : 𝔸) : fderiv 𝕜 (λ y, b * a y) x = b • fderiv 𝕜 a x := (ha.has_fderiv_at.const_mul b).fderiv end mul section algebra_inverse variables {R : Type*} [normed_ring R] [normed_algebra 𝕜 R] [complete_space R] open normed_ring continuous_linear_map ring /-- At an invertible element `x` of a normed algebra `R`, the Fréchet derivative of the inversion operation is the linear map `λ t, - x⁻¹ * t * x⁻¹`. -/ lemma has_fderiv_at_ring_inverse (x : Rˣ) : has_fderiv_at ring.inverse (-lmul_left_right 𝕜 R ↑x⁻¹ ↑x⁻¹) x := begin have h_is_o : (λ (t : R), inverse (↑x + t) - ↑x⁻¹ + ↑x⁻¹ * t * ↑x⁻¹) =o[𝓝 0] (λ (t : R), t), { refine (inverse_add_norm_diff_second_order x).trans_is_o ((is_o_norm_norm).mp _), simp only [norm_pow, norm_norm], have h12 : 1 < 2 := by norm_num, convert (asymptotics.is_o_pow_pow h12).comp_tendsto tendsto_norm_zero, ext, simp }, have h_lim : tendsto (λ (y:R), y - x) (𝓝 x) (𝓝 0), { refine tendsto_zero_iff_norm_tendsto_zero.mpr _, exact tendsto_iff_norm_tendsto_zero.mp tendsto_id }, simp only [has_fderiv_at, has_fderiv_at_filter], convert h_is_o.comp_tendsto h_lim, ext y, simp only [coe_comp', function.comp_app, lmul_left_right_apply, neg_apply, inverse_unit x, units.inv_mul, add_sub_cancel'_right, mul_sub, sub_mul, one_mul, sub_neg_eq_add] end lemma differentiable_at_inverse (x : Rˣ) : differentiable_at 𝕜 (@ring.inverse R _) x := (has_fderiv_at_ring_inverse x).differentiable_at lemma fderiv_inverse (x : Rˣ) : fderiv 𝕜 (@ring.inverse R _) x = - lmul_left_right 𝕜 R ↑x⁻¹ ↑x⁻¹ := (has_fderiv_at_ring_inverse x).fderiv end algebra_inverse namespace continuous_linear_equiv /-! ### Differentiability of linear equivs, and invariance of differentiability -/ variable (iso : E ≃L[𝕜] F) protected lemma has_strict_fderiv_at : has_strict_fderiv_at iso (iso : E →L[𝕜] F) x := iso.to_continuous_linear_map.has_strict_fderiv_at protected lemma has_fderiv_within_at : has_fderiv_within_at iso (iso : E →L[𝕜] F) s x := iso.to_continuous_linear_map.has_fderiv_within_at protected lemma has_fderiv_at : has_fderiv_at iso (iso : E →L[𝕜] F) x := iso.to_continuous_linear_map.has_fderiv_at_filter protected lemma differentiable_at : differentiable_at 𝕜 iso x := iso.has_fderiv_at.differentiable_at protected lemma differentiable_within_at : differentiable_within_at 𝕜 iso s x := iso.differentiable_at.differentiable_within_at protected lemma fderiv : fderiv 𝕜 iso x = iso := iso.has_fderiv_at.fderiv protected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 iso s x = iso := iso.to_continuous_linear_map.fderiv_within hxs protected lemma differentiable : differentiable 𝕜 iso := λx, iso.differentiable_at protected lemma differentiable_on : differentiable_on 𝕜 iso s := iso.differentiable.differentiable_on lemma comp_differentiable_within_at_iff {f : G → E} {s : set G} {x : G} : differentiable_within_at 𝕜 (iso ∘ f) s x ↔ differentiable_within_at 𝕜 f s x := begin refine ⟨λ H, _, λ H, iso.differentiable.differentiable_at.comp_differentiable_within_at x H⟩, have : differentiable_within_at 𝕜 (iso.symm ∘ (iso ∘ f)) s x := iso.symm.differentiable.differentiable_at.comp_differentiable_within_at x H, rwa [← function.comp.assoc iso.symm iso f, iso.symm_comp_self] at this, end lemma comp_differentiable_at_iff {f : G → E} {x : G} : differentiable_at 𝕜 (iso ∘ f) x ↔ differentiable_at 𝕜 f x := by rw [← differentiable_within_at_univ, ← differentiable_within_at_univ, iso.comp_differentiable_within_at_iff] lemma comp_differentiable_on_iff {f : G → E} {s : set G} : differentiable_on 𝕜 (iso ∘ f) s ↔ differentiable_on 𝕜 f s := begin rw [differentiable_on, differentiable_on], simp only [iso.comp_differentiable_within_at_iff], end lemma comp_differentiable_iff {f : G → E} : differentiable 𝕜 (iso ∘ f) ↔ differentiable 𝕜 f := begin rw [← differentiable_on_univ, ← differentiable_on_univ], exact iso.comp_differentiable_on_iff end lemma comp_has_fderiv_within_at_iff {f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] E} : has_fderiv_within_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ has_fderiv_within_at f f' s x := begin refine ⟨λ H, _, λ H, iso.has_fderiv_at.comp_has_fderiv_within_at x H⟩, have A : f = iso.symm ∘ (iso ∘ f), by { rw [← function.comp.assoc, iso.symm_comp_self], refl }, have B : f' = (iso.symm : F →L[𝕜] E).comp ((iso : E →L[𝕜] F).comp f'), by rw [← continuous_linear_map.comp_assoc, iso.coe_symm_comp_coe, continuous_linear_map.id_comp], rw [A, B], exact iso.symm.has_fderiv_at.comp_has_fderiv_within_at x H end lemma comp_has_strict_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : has_strict_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_strict_fderiv_at f f' x := begin refine ⟨λ H, _, λ H, iso.has_strict_fderiv_at.comp x H⟩, convert iso.symm.has_strict_fderiv_at.comp x H; ext z; apply (iso.symm_apply_apply _).symm end lemma comp_has_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : has_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_fderiv_at f f' x := by rw [← has_fderiv_within_at_univ, ← has_fderiv_within_at_univ, iso.comp_has_fderiv_within_at_iff] lemma comp_has_fderiv_within_at_iff' {f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] F} : has_fderiv_within_at (iso ∘ f) f' s x ↔ has_fderiv_within_at f ((iso.symm : F →L[𝕜] E).comp f') s x := by rw [← iso.comp_has_fderiv_within_at_iff, ← continuous_linear_map.comp_assoc, iso.coe_comp_coe_symm, continuous_linear_map.id_comp] lemma comp_has_fderiv_at_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} : has_fderiv_at (iso ∘ f) f' x ↔ has_fderiv_at f ((iso.symm : F →L[𝕜] E).comp f') x := by rw [← has_fderiv_within_at_univ, ← has_fderiv_within_at_univ, iso.comp_has_fderiv_within_at_iff'] lemma comp_fderiv_within {f : G → E} {s : set G} {x : G} (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderiv_within 𝕜 f s x) := begin by_cases h : differentiable_within_at 𝕜 f s x, { rw [fderiv.comp_fderiv_within x iso.differentiable_at h hxs, iso.fderiv] }, { have : ¬differentiable_within_at 𝕜 (iso ∘ f) s x, from mt iso.comp_differentiable_within_at_iff.1 h, rw [fderiv_within_zero_of_not_differentiable_within_at h, fderiv_within_zero_of_not_differentiable_within_at this, continuous_linear_map.comp_zero] } end lemma comp_fderiv {f : G → E} {x : G} : fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) := begin rw [← fderiv_within_univ, ← fderiv_within_univ], exact iso.comp_fderiv_within unique_diff_within_at_univ, end end continuous_linear_equiv namespace linear_isometry_equiv /-! ### Differentiability of linear isometry equivs, and invariance of differentiability -/ variable (iso : E ≃ₗᵢ[𝕜] F) protected lemma has_strict_fderiv_at : has_strict_fderiv_at iso (iso : E →L[𝕜] F) x := (iso : E ≃L[𝕜] F).has_strict_fderiv_at protected lemma has_fderiv_within_at : has_fderiv_within_at iso (iso : E →L[𝕜] F) s x := (iso : E ≃L[𝕜] F).has_fderiv_within_at protected lemma has_fderiv_at : has_fderiv_at iso (iso : E →L[𝕜] F) x := (iso : E ≃L[𝕜] F).has_fderiv_at protected lemma differentiable_at : differentiable_at 𝕜 iso x := iso.has_fderiv_at.differentiable_at protected lemma differentiable_within_at : differentiable_within_at 𝕜 iso s x := iso.differentiable_at.differentiable_within_at protected lemma fderiv : fderiv 𝕜 iso x = iso := iso.has_fderiv_at.fderiv protected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 iso s x = iso := (iso : E ≃L[𝕜] F).fderiv_within hxs protected lemma differentiable : differentiable 𝕜 iso := λx, iso.differentiable_at protected lemma differentiable_on : differentiable_on 𝕜 iso s := iso.differentiable.differentiable_on lemma comp_differentiable_within_at_iff {f : G → E} {s : set G} {x : G} : differentiable_within_at 𝕜 (iso ∘ f) s x ↔ differentiable_within_at 𝕜 f s x := (iso : E ≃L[𝕜] F).comp_differentiable_within_at_iff lemma comp_differentiable_at_iff {f : G → E} {x : G} : differentiable_at 𝕜 (iso ∘ f) x ↔ differentiable_at 𝕜 f x := (iso : E ≃L[𝕜] F).comp_differentiable_at_iff lemma comp_differentiable_on_iff {f : G → E} {s : set G} : differentiable_on 𝕜 (iso ∘ f) s ↔ differentiable_on 𝕜 f s := (iso : E ≃L[𝕜] F).comp_differentiable_on_iff lemma comp_differentiable_iff {f : G → E} : differentiable 𝕜 (iso ∘ f) ↔ differentiable 𝕜 f := (iso : E ≃L[𝕜] F).comp_differentiable_iff lemma comp_has_fderiv_within_at_iff {f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] E} : has_fderiv_within_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ has_fderiv_within_at f f' s x := (iso : E ≃L[𝕜] F).comp_has_fderiv_within_at_iff lemma comp_has_strict_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : has_strict_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_strict_fderiv_at f f' x := (iso : E ≃L[𝕜] F).comp_has_strict_fderiv_at_iff lemma comp_has_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : has_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_fderiv_at f f' x := (iso : E ≃L[𝕜] F).comp_has_fderiv_at_iff lemma comp_has_fderiv_within_at_iff' {f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] F} : has_fderiv_within_at (iso ∘ f) f' s x ↔ has_fderiv_within_at f ((iso.symm : F →L[𝕜] E).comp f') s x := (iso : E ≃L[𝕜] F).comp_has_fderiv_within_at_iff' lemma comp_has_fderiv_at_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} : has_fderiv_at (iso ∘ f) f' x ↔ has_fderiv_at f ((iso.symm : F →L[𝕜] E).comp f') x := (iso : E ≃L[𝕜] F).comp_has_fderiv_at_iff' lemma comp_fderiv_within {f : G → E} {s : set G} {x : G} (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderiv_within 𝕜 f s x) := (iso : E ≃L[𝕜] F).comp_fderiv_within hxs lemma comp_fderiv {f : G → E} {x : G} : fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) := (iso : E ≃L[𝕜] F).comp_fderiv end linear_isometry_equiv /-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an invertible derivative `f'` at `g a` in the strict sense, then `g` has the derivative `f'⁻¹` at `a` in the strict sense. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem has_strict_fderiv_at.of_local_left_inverse {f : E → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F} (hg : continuous_at g a) (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) (g a)) (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : has_strict_fderiv_at g (f'.symm : F →L[𝕜] E) a := begin replace hg := hg.prod_map' hg, replace hfg := hfg.prod_mk_nhds hfg, have : (λ p : F × F, g p.1 - g p.2 - f'.symm (p.1 - p.2)) =O[𝓝 (a, a)] (λ p : F × F, f' (g p.1 - g p.2) - (p.1 - p.2)), { refine ((f'.symm : F →L[𝕜] E).is_O_comp _ _).congr (λ x, _) (λ _, rfl), simp }, refine this.trans_is_o _, clear this, refine ((hf.comp_tendsto hg).symm.congr' (hfg.mono _) (eventually_of_forall $ λ _, rfl)).trans_is_O _, { rintros p ⟨hp1, hp2⟩, simp [hp1, hp2] }, { refine (hf.is_O_sub_rev.comp_tendsto hg).congr' (eventually_of_forall $ λ _, rfl) (hfg.mono _), rintros p ⟨hp1, hp2⟩, simp only [(∘), hp1, hp2] } end /-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an invertible derivative `f'` at `g a`, then `g` has the derivative `f'⁻¹` at `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem has_fderiv_at.of_local_left_inverse {f : E → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F} (hg : continuous_at g a) (hf : has_fderiv_at f (f' : E →L[𝕜] F) (g a)) (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : has_fderiv_at g (f'.symm : F →L[𝕜] E) a := begin have : (λ x : F, g x - g a - f'.symm (x - a)) =O[𝓝 a] (λ x : F, f' (g x - g a) - (x - a)), { refine ((f'.symm : F →L[𝕜] E).is_O_comp _ _).congr (λ x, _) (λ _, rfl), simp }, refine this.trans_is_o _, clear this, refine ((hf.comp_tendsto hg).symm.congr' (hfg.mono _) (eventually_of_forall $ λ _, rfl)).trans_is_O _, { rintros p hp, simp [hp, hfg.self_of_nhds] }, { refine ((hf.is_O_sub_rev f'.antilipschitz).comp_tendsto hg).congr' (eventually_of_forall $ λ _, rfl) (hfg.mono _), rintros p hp, simp only [(∘), hp, hfg.self_of_nhds] } end /-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an invertible derivative `f'` in the sense of strict differentiability at `f.symm a`, then `f.symm` has the derivative `f'⁻¹` at `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ lemma local_homeomorph.has_strict_fderiv_at_symm (f : local_homeomorph E F) {f' : E ≃L[𝕜] F} {a : F} (ha : a ∈ f.target) (htff' : has_strict_fderiv_at f (f' : E →L[𝕜] F) (f.symm a)) : has_strict_fderiv_at f.symm (f'.symm : F →L[𝕜] E) a := htff'.of_local_left_inverse (f.symm.continuous_at ha) (f.eventually_right_inverse ha) /-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an invertible derivative `f'` at `f.symm a`, then `f.symm` has the derivative `f'⁻¹` at `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ lemma local_homeomorph.has_fderiv_at_symm (f : local_homeomorph E F) {f' : E ≃L[𝕜] F} {a : F} (ha : a ∈ f.target) (htff' : has_fderiv_at f (f' : E →L[𝕜] F) (f.symm a)) : has_fderiv_at f.symm (f'.symm : F →L[𝕜] E) a := htff'.of_local_left_inverse (f.symm.continuous_at ha) (f.eventually_right_inverse ha) lemma has_fderiv_within_at.eventually_ne (h : has_fderiv_within_at f f' s x) (hf' : ∃ C, ∀ z, ∥z∥ ≤ C * ∥f' z∥) : ∀ᶠ z in 𝓝[s \ {x}] x, f z ≠ f x := begin rw [nhds_within, diff_eq, ← inf_principal, ← inf_assoc, eventually_inf_principal], have A : (λ z, z - x) =O[𝓝[s] x] (λ z, f' (z - x)) := (is_O_iff.2 $ hf'.imp $ λ C hC, eventually_of_forall $ λ z, hC _), have : (λ z, f z - f x) ~[𝓝[s] x] (λ z, f' (z - x)) := h.trans_is_O A, simpa [not_imp_not, sub_eq_zero] using (A.trans this.is_O_symm).eq_zero_imp end lemma has_fderiv_at.eventually_ne (h : has_fderiv_at f f' x) (hf' : ∃ C, ∀ z, ∥z∥ ≤ C * ∥f' z∥) : ∀ᶠ z in 𝓝[≠] x, f z ≠ f x := by simpa only [compl_eq_univ_diff] using (has_fderiv_within_at_univ.2 h).eventually_ne hf' end section /- In the special case of a normed space over the reals, we can use scalar multiplication in the `tendsto` characterization of the Fréchet derivative. -/ variables {E : Type*} [normed_group E] [normed_space ℝ E] variables {F : Type*} [normed_group F] [normed_space ℝ F] variables {f : E → F} {f' : E →L[ℝ] F} {x : E} theorem has_fderiv_at_filter_real_equiv {L : filter E} : tendsto (λ x' : E, ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) L (𝓝 0) ↔ tendsto (λ x' : E, ∥x' - x∥⁻¹ • (f x' - f x - f' (x' - x))) L (𝓝 0) := begin symmetry, rw [tendsto_iff_norm_tendsto_zero], refine tendsto_congr (λ x', _), have : ∥x' - x∥⁻¹ ≥ 0, from inv_nonneg.mpr (norm_nonneg _), simp [norm_smul, abs_of_nonneg this] end lemma has_fderiv_at.lim_real (hf : has_fderiv_at f f' x) (v : E) : tendsto (λ (c:ℝ), c • (f (x + c⁻¹ • v) - f x)) at_top (𝓝 (f' v)) := begin apply hf.lim v, rw tendsto_at_top_at_top, exact λ b, ⟨b, λ a ha, le_trans ha (le_abs_self _)⟩ end end section tangent_cone variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E] {F : Type*} [normed_group F] [normed_space 𝕜 F] {f : E → F} {s : set E} {f' : E →L[𝕜] F} /-- The image of a tangent cone under the differential of a map is included in the tangent cone to the image. -/ lemma has_fderiv_within_at.maps_to_tangent_cone {x : E} (h : has_fderiv_within_at f f' s x) : maps_to f' (tangent_cone_at 𝕜 s x) (tangent_cone_at 𝕜 (f '' s) (f x)) := begin rintros v ⟨c, d, dtop, clim, cdlim⟩, refine ⟨c, (λn, f (x + d n) - f x), mem_of_superset dtop _, clim, h.lim at_top dtop clim cdlim⟩, simp [-mem_image, mem_image_of_mem] {contextual := tt} end /-- If a set has the unique differentiability property at a point x, then the image of this set under a map with onto derivative has also the unique differentiability property at the image point. -/ lemma has_fderiv_within_at.unique_diff_within_at {x : E} (h : has_fderiv_within_at f f' s x) (hs : unique_diff_within_at 𝕜 s x) (h' : dense_range f') : unique_diff_within_at 𝕜 (f '' s) (f x) := begin refine ⟨h'.dense_of_maps_to f'.continuous hs.1 _, h.continuous_within_at.mem_closure_image hs.2⟩, show submodule.span 𝕜 (tangent_cone_at 𝕜 s x) ≤ (submodule.span 𝕜 (tangent_cone_at 𝕜 (f '' s) (f x))).comap ↑f', rw [submodule.span_le], exact h.maps_to_tangent_cone.mono (subset.refl _) submodule.subset_span end lemma unique_diff_on.image {f' : E → E →L[𝕜] F} (hs : unique_diff_on 𝕜 s) (hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hd : ∀ x ∈ s, dense_range (f' x)) : unique_diff_on 𝕜 (f '' s) := ball_image_iff.2 $ λ x hx, (hf' x hx).unique_diff_within_at (hs x hx) (hd x hx) lemma has_fderiv_within_at.unique_diff_within_at_of_continuous_linear_equiv {x : E} (e' : E ≃L[𝕜] F) (h : has_fderiv_within_at f (e' : E →L[𝕜] F) s x) (hs : unique_diff_within_at 𝕜 s x) : unique_diff_within_at 𝕜 (f '' s) (f x) := h.unique_diff_within_at hs e'.surjective.dense_range lemma continuous_linear_equiv.unique_diff_on_image (e : E ≃L[𝕜] F) (h : unique_diff_on 𝕜 s) : unique_diff_on 𝕜 (e '' s) := h.image (λ x _, e.has_fderiv_within_at) (λ x hx, e.surjective.dense_range) @[simp] lemma continuous_linear_equiv.unique_diff_on_image_iff (e : E ≃L[𝕜] F) : unique_diff_on 𝕜 (e '' s) ↔ unique_diff_on 𝕜 s := ⟨λ h, e.symm_image_image s ▸ e.symm.unique_diff_on_image h, e.unique_diff_on_image⟩ @[simp] lemma continuous_linear_equiv.unique_diff_on_preimage_iff (e : F ≃L[𝕜] E) : unique_diff_on 𝕜 (e ⁻¹' s) ↔ unique_diff_on 𝕜 s := by rw [← e.image_symm_eq_preimage, e.symm.unique_diff_on_image_iff] end tangent_cone section restrict_scalars /-! ### Restricting from `ℂ` to `ℝ`, or generally from `𝕜'` to `𝕜` If a function is differentiable over `ℂ`, then it is differentiable over `ℝ`. In this paragraph, we give variants of this statement, in the general situation where `ℂ` and `ℝ` are replaced respectively by `𝕜'` and `𝕜` where `𝕜'` is a normed algebra over `𝕜`. -/ variables (𝕜 : Type*) [nondiscrete_normed_field 𝕜] variables {𝕜' : Type*} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜 𝕜'] variables {E : Type*} [normed_group E] [normed_space 𝕜 E] [normed_space 𝕜' E] variables [is_scalar_tower 𝕜 𝕜' E] variables {F : Type*} [normed_group F] [normed_space 𝕜 F] [normed_space 𝕜' F] variables [is_scalar_tower 𝕜 𝕜' F] variables {f : E → F} {f' : E →L[𝕜'] F} {s : set E} {x : E} lemma has_strict_fderiv_at.restrict_scalars (h : has_strict_fderiv_at f f' x) : has_strict_fderiv_at f (f'.restrict_scalars 𝕜) x := h lemma has_fderiv_at_filter.restrict_scalars {L} (h : has_fderiv_at_filter f f' x L) : has_fderiv_at_filter f (f'.restrict_scalars 𝕜) x L := h lemma has_fderiv_at.restrict_scalars (h : has_fderiv_at f f' x) : has_fderiv_at f (f'.restrict_scalars 𝕜) x := h lemma has_fderiv_within_at.restrict_scalars (h : has_fderiv_within_at f f' s x) : has_fderiv_within_at f (f'.restrict_scalars 𝕜) s x := h lemma differentiable_at.restrict_scalars (h : differentiable_at 𝕜' f x) : differentiable_at 𝕜 f x := (h.has_fderiv_at.restrict_scalars 𝕜).differentiable_at lemma differentiable_within_at.restrict_scalars (h : differentiable_within_at 𝕜' f s x) : differentiable_within_at 𝕜 f s x := (h.has_fderiv_within_at.restrict_scalars 𝕜).differentiable_within_at lemma differentiable_on.restrict_scalars (h : differentiable_on 𝕜' f s) : differentiable_on 𝕜 f s := λx hx, (h x hx).restrict_scalars 𝕜 lemma differentiable.restrict_scalars (h : differentiable 𝕜' f) : differentiable 𝕜 f := λx, (h x).restrict_scalars 𝕜 lemma has_fderiv_within_at_of_restrict_scalars {g' : E →L[𝕜] F} (h : has_fderiv_within_at f g' s x) (H : f'.restrict_scalars 𝕜 = g') : has_fderiv_within_at f f' s x := by { rw ← H at h, exact h } lemma has_fderiv_at_of_restrict_scalars {g' : E →L[𝕜] F} (h : has_fderiv_at f g' x) (H : f'.restrict_scalars 𝕜 = g') : has_fderiv_at f f' x := by { rw ← H at h, exact h } lemma differentiable_at.fderiv_restrict_scalars (h : differentiable_at 𝕜' f x) : fderiv 𝕜 f x = (fderiv 𝕜' f x).restrict_scalars 𝕜 := (h.has_fderiv_at.restrict_scalars 𝕜).fderiv lemma differentiable_within_at_iff_restrict_scalars (hf : differentiable_within_at 𝕜 f s x) (hs : unique_diff_within_at 𝕜 s x) : differentiable_within_at 𝕜' f s x ↔ ∃ (g' : E →L[𝕜'] F), g'.restrict_scalars 𝕜 = fderiv_within 𝕜 f s x := begin split, { rintros ⟨g', hg'⟩, exact ⟨g', hs.eq (hg'.restrict_scalars 𝕜) hf.has_fderiv_within_at⟩, }, { rintros ⟨f', hf'⟩, exact ⟨f', has_fderiv_within_at_of_restrict_scalars 𝕜 hf.has_fderiv_within_at hf'⟩, }, end lemma differentiable_at_iff_restrict_scalars (hf : differentiable_at 𝕜 f x) : differentiable_at 𝕜' f x ↔ ∃ (g' : E →L[𝕜'] F), g'.restrict_scalars 𝕜 = fderiv 𝕜 f x := begin rw [← differentiable_within_at_univ, ← fderiv_within_univ], exact differentiable_within_at_iff_restrict_scalars 𝕜 hf.differentiable_within_at unique_diff_within_at_univ, end end restrict_scalars /-! ### Support of derivatives -/ section support open function variables (𝕜 : Type*) {E F : Type*} [nondiscrete_normed_field 𝕜] variables [normed_group E] [normed_space 𝕜 E] [normed_group F] [normed_space 𝕜 F] {f : E → F} lemma support_fderiv_subset : support (fderiv 𝕜 f) ⊆ tsupport f := begin intros x, rw [← not_imp_not], intro h2x, rw [not_mem_closure_support_iff_eventually_eq] at h2x, exact nmem_support.mpr (h2x.fderiv_eq.trans $ fderiv_const_apply 0), end lemma has_compact_support.fderiv (hf : has_compact_support f) : has_compact_support (fderiv 𝕜 f) := hf.mono' $ support_fderiv_subset 𝕜 end support
6e565def64d67f3a354f2cd963d012580a9d8f0c
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/category_theory/adjunction/limits.lean
1820e2cc84d6670276fdc20bfdd5946833cd55cc
[ "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
13,269
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.adjunction.basic import category_theory.limits.creates /-! # Adjunctions and limits > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. A left adjoint preserves colimits (`category_theory.adjunction.left_adjoint_preserves_colimits`), and a right adjoint preserves limits (`category_theory.adjunction.right_adjoint_preserves_limits`). Equivalences create and reflect (co)limits. (`category_theory.adjunction.is_equivalence_creates_limits`, `category_theory.adjunction.is_equivalence_creates_colimits`, `category_theory.adjunction.is_equivalence_reflects_limits`, `category_theory.adjunction.is_equivalence_reflects_colimits`,) In `category_theory.adjunction.cocones_iso` we show that when `F ⊣ G`, the functor associating to each `Y` the cocones over `K ⋙ F` with cone point `Y` is naturally isomorphic to the functor associating to each `Y` the cocones over `K` with cone point `G.obj Y`. -/ open opposite namespace category_theory.adjunction open category_theory open category_theory.functor open category_theory.limits universes v u v₁ v₂ v₀ u₁ u₂ section arbitrary_universe variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D] variables {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) include adj section preservation_colimits variables {J : Type u} [category.{v} J] (K : J ⥤ C) /-- The right adjoint of `cocones.functoriality K F : cocone K ⥤ cocone (K ⋙ F)`. Auxiliary definition for `functoriality_is_left_adjoint`. -/ def functoriality_right_adjoint : cocone (K ⋙ F) ⥤ cocone K := (cocones.functoriality _ G) ⋙ (cocones.precompose (K.right_unitor.inv ≫ (whisker_left K adj.unit) ≫ (associator _ _ _).inv)) local attribute [reducible] functoriality_right_adjoint /-- The unit for the adjunction for `cocones.functoriality K F : cocone K ⥤ cocone (K ⋙ F)`. Auxiliary definition for `functoriality_is_left_adjoint`. -/ @[simps] def functoriality_unit : 𝟭 (cocone K) ⟶ cocones.functoriality _ F ⋙ functoriality_right_adjoint adj K := { app := λ c, { hom := adj.unit.app c.X } } /-- The counit for the adjunction for `cocones.functoriality K F : cocone K ⥤ cocone (K ⋙ F)`. Auxiliary definition for `functoriality_is_left_adjoint`. -/ @[simps] def functoriality_counit : functoriality_right_adjoint adj K ⋙ cocones.functoriality _ F ⟶ 𝟭 (cocone (K ⋙ F)) := { app := λ c, { hom := adj.counit.app c.X } } /-- The functor `cocones.functoriality K F : cocone K ⥤ cocone (K ⋙ F)` is a left adjoint. -/ def functoriality_is_left_adjoint : is_left_adjoint (cocones.functoriality K F) := { right := functoriality_right_adjoint adj K, adj := mk_of_unit_counit { unit := functoriality_unit adj K, counit := functoriality_counit adj K } } /-- A left adjoint preserves colimits. See <https://stacks.math.columbia.edu/tag/0038>. -/ def left_adjoint_preserves_colimits : preserves_colimits_of_size.{v u} F := { preserves_colimits_of_shape := λ J 𝒥, { preserves_colimit := λ F, by exactI { preserves := λ c hc, is_colimit.iso_unique_cocone_morphism.inv (λ s, @equiv.unique _ _ (is_colimit.iso_unique_cocone_morphism.hom hc _) (((adj.functoriality_is_left_adjoint _).adj).hom_equiv _ _)) } } }. omit adj @[priority 100] -- see Note [lower instance priority] instance is_equivalence_preserves_colimits (E : C ⥤ D) [is_equivalence E] : preserves_colimits_of_size.{v u} E := left_adjoint_preserves_colimits E.adjunction @[priority 100] -- see Note [lower instance priority] instance is_equivalence_reflects_colimits (E : D ⥤ C) [is_equivalence E] : reflects_colimits_of_size.{v u} E := { reflects_colimits_of_shape := λ J 𝒥, by exactI { reflects_colimit := λ K, { reflects := λ c t, begin have l := (is_colimit_of_preserves E.inv t).map_cocone_equiv E.as_equivalence.unit_iso.symm, refine (((is_colimit.precompose_inv_equiv K.right_unitor _).symm) l).of_iso_colimit _, tidy, end } } } @[priority 100] -- see Note [lower instance priority] instance is_equivalence_creates_colimits (H : D ⥤ C) [is_equivalence H] : creates_colimits_of_size.{v u} H := { creates_colimits_of_shape := λ J 𝒥, by exactI { creates_colimit := λ F, { lifts := λ c t, { lifted_cocone := H.map_cocone_inv c, valid_lift := H.map_cocone_map_cocone_inv c } } } } -- verify the preserve_colimits instance works as expected: example (E : C ⥤ D) [is_equivalence E] (c : cocone K) (h : is_colimit c) : is_colimit (E.map_cocone c) := preserves_colimit.preserves h lemma has_colimit_comp_equivalence (E : C ⥤ D) [is_equivalence E] [has_colimit K] : has_colimit (K ⋙ E) := has_colimit.mk { cocone := E.map_cocone (colimit.cocone K), is_colimit := preserves_colimit.preserves (colimit.is_colimit K) } lemma has_colimit_of_comp_equivalence (E : C ⥤ D) [is_equivalence E] [has_colimit (K ⋙ E)] : has_colimit K := @has_colimit_of_iso _ _ _ _ (K ⋙ E ⋙ inv E) K (@has_colimit_comp_equivalence _ _ _ _ _ _ (K ⋙ E) (inv E) _ _) ((functor.right_unitor _).symm ≪≫ iso_whisker_left K (E.as_equivalence.unit_iso)) /-- Transport a `has_colimits_of_shape` instance across an equivalence. -/ lemma has_colimits_of_shape_of_equivalence (E : C ⥤ D) [is_equivalence E] [has_colimits_of_shape J D] : has_colimits_of_shape J C := ⟨λ F, by exactI has_colimit_of_comp_equivalence F E⟩ /-- Transport a `has_colimits` instance across an equivalence. -/ lemma has_colimits_of_equivalence (E : C ⥤ D) [is_equivalence E] [has_colimits_of_size.{v u} D] : has_colimits_of_size.{v u} C := ⟨λ J hJ, by { exactI has_colimits_of_shape_of_equivalence E }⟩ end preservation_colimits section preservation_limits variables {J : Type u} [category.{v} J] (K : J ⥤ D) /-- The left adjoint of `cones.functoriality K G : cone K ⥤ cone (K ⋙ G)`. Auxiliary definition for `functoriality_is_right_adjoint`. -/ def functoriality_left_adjoint : cone (K ⋙ G) ⥤ cone K := (cones.functoriality _ F) ⋙ (cones.postcompose ((associator _ _ _).hom ≫ (whisker_left K adj.counit) ≫ K.right_unitor.hom)) local attribute [reducible] functoriality_left_adjoint /-- The unit for the adjunction for`cones.functoriality K G : cone K ⥤ cone (K ⋙ G)`. Auxiliary definition for `functoriality_is_right_adjoint`. -/ @[simps] def functoriality_unit' : 𝟭 (cone (K ⋙ G)) ⟶ functoriality_left_adjoint adj K ⋙ cones.functoriality _ G := { app := λ c, { hom := adj.unit.app c.X, } } /-- The counit for the adjunction for`cones.functoriality K G : cone K ⥤ cone (K ⋙ G)`. Auxiliary definition for `functoriality_is_right_adjoint`. -/ @[simps] def functoriality_counit' : cones.functoriality _ G ⋙ functoriality_left_adjoint adj K ⟶ 𝟭 (cone K) := { app := λ c, { hom := adj.counit.app c.X, } } /-- The functor `cones.functoriality K G : cone K ⥤ cone (K ⋙ G)` is a right adjoint. -/ def functoriality_is_right_adjoint : is_right_adjoint (cones.functoriality K G) := { left := functoriality_left_adjoint adj K, adj := mk_of_unit_counit { unit := functoriality_unit' adj K, counit := functoriality_counit' adj K } } /-- A right adjoint preserves limits. See <https://stacks.math.columbia.edu/tag/0038>. -/ def right_adjoint_preserves_limits : preserves_limits_of_size.{v u} G := { preserves_limits_of_shape := λ J 𝒥, { preserves_limit := λ K, by exactI { preserves := λ c hc, is_limit.iso_unique_cone_morphism.inv (λ s, @equiv.unique _ _ (is_limit.iso_unique_cone_morphism.hom hc _) (((adj.functoriality_is_right_adjoint _).adj).hom_equiv _ _).symm) } } }. omit adj @[priority 100] -- see Note [lower instance priority] instance is_equivalence_preserves_limits (E : D ⥤ C) [is_equivalence E] : preserves_limits_of_size.{v u} E := right_adjoint_preserves_limits E.inv.adjunction @[priority 100] -- see Note [lower instance priority] instance is_equivalence_reflects_limits (E : D ⥤ C) [is_equivalence E] : reflects_limits_of_size.{v u} E := { reflects_limits_of_shape := λ J 𝒥, by exactI { reflects_limit := λ K, { reflects := λ c t, begin have := (is_limit_of_preserves E.inv t).map_cone_equiv E.as_equivalence.unit_iso.symm, refine (((is_limit.postcompose_hom_equiv K.left_unitor _).symm) this).of_iso_limit _, tidy, end } } } @[priority 100] -- see Note [lower instance priority] instance is_equivalence_creates_limits (H : D ⥤ C) [is_equivalence H] : creates_limits_of_size.{v u} H := { creates_limits_of_shape := λ J 𝒥, by exactI { creates_limit := λ F, { lifts := λ c t, { lifted_cone := H.map_cone_inv c, valid_lift := H.map_cone_map_cone_inv c } } } } -- verify the preserve_limits instance works as expected: example (E : D ⥤ C) [is_equivalence E] (c : cone K) [h : is_limit c] : is_limit (E.map_cone c) := preserves_limit.preserves h lemma has_limit_comp_equivalence (E : D ⥤ C) [is_equivalence E] [has_limit K] : has_limit (K ⋙ E) := has_limit.mk { cone := E.map_cone (limit.cone K), is_limit := preserves_limit.preserves (limit.is_limit K) } lemma has_limit_of_comp_equivalence (E : D ⥤ C) [is_equivalence E] [has_limit (K ⋙ E)] : has_limit K := @has_limit_of_iso _ _ _ _ (K ⋙ E ⋙ inv E) K (@has_limit_comp_equivalence _ _ _ _ _ _ (K ⋙ E) (inv E) _ _) ((iso_whisker_left K E.as_equivalence.unit_iso.symm) ≪≫ (functor.right_unitor _)) /-- Transport a `has_limits_of_shape` instance across an equivalence. -/ lemma has_limits_of_shape_of_equivalence (E : D ⥤ C) [is_equivalence E] [has_limits_of_shape J C] : has_limits_of_shape J D := ⟨λ F, by exactI has_limit_of_comp_equivalence F E⟩ /-- Transport a `has_limits` instance across an equivalence. -/ lemma has_limits_of_equivalence (E : D ⥤ C) [is_equivalence E] [has_limits_of_size.{v u} C] : has_limits_of_size.{v u} D := ⟨λ J hJ, by exactI has_limits_of_shape_of_equivalence E⟩ end preservation_limits /-- auxiliary construction for `cocones_iso` -/ @[simps] def cocones_iso_component_hom {J : Type u} [category.{v} J] {K : J ⥤ C} (Y : D) (t : ((cocones J D).obj (op (K ⋙ F))).obj Y) : (G ⋙ (cocones J C).obj (op K)).obj Y := { app := λ j, (adj.hom_equiv (K.obj j) Y) (t.app j), naturality' := λ j j' f, by { erw [← adj.hom_equiv_naturality_left, t.naturality], dsimp, simp } } /-- auxiliary construction for `cocones_iso` -/ @[simps] def cocones_iso_component_inv {J : Type u} [category.{v} J] {K : J ⥤ C} (Y : D) (t : (G ⋙ (cocones J C).obj (op K)).obj Y) : ((cocones J D).obj (op (K ⋙ F))).obj Y := { app := λ j, (adj.hom_equiv (K.obj j) Y).symm (t.app j), naturality' := λ j j' f, begin erw [← adj.hom_equiv_naturality_left_symm, ← adj.hom_equiv_naturality_right_symm, t.naturality], dsimp, simp end } /-- auxiliary construction for `cones_iso` -/ @[simps] def cones_iso_component_hom {J : Type u} [category.{v} J] {K : J ⥤ D} (X : Cᵒᵖ) (t : (functor.op F ⋙ (cones J D).obj K).obj X) : ((cones J C).obj (K ⋙ G)).obj X := { app := λ j, (adj.hom_equiv (unop X) (K.obj j)) (t.app j), naturality' := λ j j' f, begin erw [← adj.hom_equiv_naturality_right, ← t.naturality, category.id_comp, category.id_comp], refl end } /-- auxiliary construction for `cones_iso` -/ @[simps] def cones_iso_component_inv {J : Type u} [category.{v} J] {K : J ⥤ D} (X : Cᵒᵖ) (t : ((cones J C).obj (K ⋙ G)).obj X) : (functor.op F ⋙ (cones J D).obj K).obj X := { app := λ j, (adj.hom_equiv (unop X) (K.obj j)).symm (t.app j), naturality' := λ j j' f, begin erw [← adj.hom_equiv_naturality_right_symm, ← t.naturality, category.id_comp, category.id_comp] end } end arbitrary_universe variables {C : Type u₁} [category.{v₀} C] {D : Type u₂} [category.{v₀} D] {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) /-- When `F ⊣ G`, the functor associating to each `Y` the cocones over `K ⋙ F` with cone point `Y` is naturally isomorphic to the functor associating to each `Y` the cocones over `K` with cone point `G.obj Y`. -/ -- Note: this is natural in K, but we do not yet have the tools to formulate that. def cocones_iso {J : Type u} [category.{v} J] {K : J ⥤ C} : (cocones J D).obj (op (K ⋙ F)) ≅ G ⋙ (cocones J C).obj (op K) := nat_iso.of_components (λ Y, { hom := cocones_iso_component_hom adj Y, inv := cocones_iso_component_inv adj Y, }) (by tidy) -- Note: this is natural in K, but we do not yet have the tools to formulate that. /-- When `F ⊣ G`, the functor associating to each `X` the cones over `K` with cone point `F.op.obj X` is naturally isomorphic to the functor associating to each `X` the cones over `K ⋙ G` with cone point `X`. -/ def cones_iso {J : Type u} [category.{v} J] {K : J ⥤ D} : F.op ⋙ (cones J D).obj K ≅ (cones J C).obj (K ⋙ G) := nat_iso.of_components (λ X, { hom := cones_iso_component_hom adj X, inv := cones_iso_component_inv adj X, } ) (by tidy) end category_theory.adjunction
f01e9fec0a0bcf04952e3667681bfbe1f6548dbf
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/tc_out_param_deps.lean
974ac53b1b4697e7904493d3afc8ee45f8e2f977
[ "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
817
lean
prelude import init.core class semiring (G : Type*) := (one : G) instance : semiring nat := ⟨1⟩ class add_monoid_hom_class (F : Type*) (H : out_param Type*) [semiring H] := (coe : F → nat → H) (ext_nat : ∀ (f g : F), coe f 1 = coe g 1 → f = g) open add_monoid_hom_class class semiring_hom_class (F : Type*) (H : out_param Type*) [semiring H] extends add_monoid_hom_class F H := (map_one : ∀ (f : F), coe f 1 = semiring.one) -- Ensure `H` can be inferred through the `out_param` of `semiring_hom_class`, -- even though `semiring H` is a non-out_param depending on it. lemma semiring_hom_class.ext_nat {F : Type*} {H : Type*} [semiring H] [semiring_hom_class F H] (f g : F) : f = g := add_monoid_hom_class.ext_nat f g $ (semiring_hom_class.map_one f).trans (semiring_hom_class.map_one g).symm
90e4d3fbc38135b221c3d91113504431adffa0b2
c777c32c8e484e195053731103c5e52af26a25d1
/src/data/real/pi/leibniz.lean
be7ce817b362d890e4a14b9f9971356910eec26c
[ "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
7,647
lean
/- Copyright (c) 2020 Benjamin Davidson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Benjamin Davidson -/ import analysis.special_functions.trigonometric.arctan_deriv /-! ### Leibniz's Series for Pi -/ namespace real open filter set open_locale classical big_operators topology real local notation (name := abs) `|`x`|` := abs x /-- This theorem establishes **Leibniz's series for `π`**: The alternating sum of the reciprocals of the odd numbers is `π/4`. Note that this is a conditionally rather than absolutely convergent series. The main tool that this proof uses is the Mean Value Theorem (specifically avoiding the Fundamental Theorem of Calculus). Intuitively, the theorem holds because Leibniz's series is the Taylor series of `arctan x` centered about `0` and evaluated at the value `x = 1`. Therefore, much of this proof consists of reasoning about a function `f := arctan x - ∑ i in finset.range k, (-(1:ℝ))^i * x^(2*i+1) / (2*i+1)`, the difference between `arctan` and the `k`-th partial sum of its Taylor series. Some ingenuity is required due to the fact that the Taylor series is not absolutely convergent at `x = 1`. This proof requires a bound on `f 1`, the key idea being that `f 1` can be split as the sum of `f 1 - f u` and `f u`, where `u` is a sequence of values in [0,1], carefully chosen such that each of these two terms can be controlled (in different ways). We begin the proof by (1) introducing that sequence `u` and then proving that another sequence constructed from `u` tends to `0` at `+∞`. After (2) converting the limit in our goal to an inequality, we (3) introduce the auxiliary function `f` defined above. Next, we (4) compute the derivative of `f`, denoted by `f'`, first generally and then on each of two subintervals of [0,1]. We then (5) prove a bound for `f'`, again both generally as well as on each of the two subintervals. Finally, we (6) apply the Mean Value Theorem twice, obtaining bounds on `f 1 - f u` and `f u - f 0` from the bounds on `f'` (note that `f 0 = 0`). -/ theorem tendsto_sum_pi_div_four : tendsto (λ k, ∑ i in finset.range k, ((-(1:ℝ))^i / (2*i+1))) at_top (𝓝 (π/4)) := begin rw [tendsto_iff_norm_tendsto_zero, ← tendsto_zero_iff_norm_tendsto_zero], -- (1) We introduce a useful sequence `u` of values in [0,1], then prove that another sequence -- constructed from `u` tends to `0` at `+∞` let u := λ k : ℕ, (k:nnreal) ^ (-1 / (2 * (k:ℝ) + 1)), have H : tendsto (λ k : ℕ, (1:ℝ) - (u k) + (u k) ^ (2 * (k:ℝ) + 1)) at_top (𝓝 0), { convert (((tendsto_rpow_div_mul_add (-1) 2 1 two_ne_zero.symm).neg.const_add 1).add tendsto_inv_at_top_zero).comp tendsto_coe_nat_at_top_at_top, { ext k, simp only [nnreal.coe_nat_cast, function.comp_app, nnreal.coe_rpow], rw [← rpow_mul (nat.cast_nonneg k) ((-1)/(2*(k:ℝ)+1)) (2*(k:ℝ)+1), @div_mul_cancel _ _ (2*(k:ℝ)+1) _ (by { norm_cast, simp only [nat.succ_ne_zero, not_false_iff] }), rpow_neg_one k, sub_eq_add_neg] }, { simp only [add_zero, add_right_neg] } }, -- (2) We convert the limit in our goal to an inequality refine squeeze_zero_norm _ H, intro k, -- Since `k` is now fixed, we henceforth denote `u k` as `U` let U := u k, -- (3) We introduce an auxiliary function `f` let b := λ (i:ℕ) x, (-(1:ℝ))^i * x^(2*i+1) / (2*i+1), let f := λ x, arctan x - (∑ i in finset.range k, b i x), suffices f_bound : |f 1 - f 0| ≤ (1:ℝ) - U + U ^ (2 * (k:ℝ) + 1), { rw ← norm_neg, convert f_bound, simp only [f], simp [b] }, -- We show that `U` is indeed in [0,1] have hU1 : (U:ℝ) ≤ 1, { by_cases hk : k = 0, { simp [u, U, hk] }, { exact rpow_le_one_of_one_le_of_nonpos (by { norm_cast, exact nat.succ_le_iff.mpr (nat.pos_of_ne_zero hk) }) (le_of_lt (@div_neg_of_neg_of_pos _ _ (-(1:ℝ)) (2*k+1) (neg_neg_iff_pos.mpr zero_lt_one) (by { norm_cast, exact nat.succ_pos' }))) } }, have hU2 := nnreal.coe_nonneg U, -- (4) We compute the derivative of `f`, denoted by `f'` let f' := λ x : ℝ, (-x^2) ^ k / (1 + x^2), have has_deriv_at_f : ∀ x, has_deriv_at f (f' x) x, { intro x, have has_deriv_at_b : ∀ i ∈ finset.range k, (has_deriv_at (b i) ((-x^2)^i) x), { intros i hi, convert has_deriv_at.const_mul ((-1:ℝ)^i / (2*i+1)) (@has_deriv_at.pow _ _ _ _ _ (2*i+1) (has_deriv_at_id x)), { ext y, simp only [b, id.def], ring }, { simp only [nat.add_succ_sub_one, add_zero, mul_one, id.def, nat.cast_bit0, nat.cast_add, nat.cast_one, nat.cast_mul], rw [← mul_assoc, @div_mul_cancel _ _ (2*(i:ℝ)+1) _ (by { norm_cast, linarith }), pow_mul x 2 i, ← mul_pow (-1) (x^2) i], ring_nf } }, convert (has_deriv_at_arctan x).sub (has_deriv_at.sum has_deriv_at_b), have g_sum := @geom_sum_eq _ _ (-x^2) ((neg_nonpos.mpr (sq_nonneg x)).trans_lt zero_lt_one).ne k, simp only [f'] at g_sum ⊢, rw [g_sum, ← neg_add' (x^2) 1, add_comm (x^2) 1, sub_eq_add_neg, neg_div', neg_div_neg_eq], ring }, have hderiv1 : ∀ x ∈ Icc (U:ℝ) 1, has_deriv_within_at f (f' x) (Icc (U:ℝ) 1) x := λ x hx, (has_deriv_at_f x).has_deriv_within_at, have hderiv2 : ∀ x ∈ Icc 0 (U:ℝ), has_deriv_within_at f (f' x) (Icc 0 (U:ℝ)) x := λ x hx, (has_deriv_at_f x).has_deriv_within_at, -- (5) We prove a general bound for `f'` and then more precise bounds on each of two subintervals have f'_bound : ∀ x ∈ Icc (-1:ℝ) 1, |f' x| ≤ |x|^(2*k), { intros x hx, rw [abs_div, is_absolute_value.abv_pow abs (-x^2) k, abs_neg, is_absolute_value.abv_pow abs x 2, ← pow_mul], refine div_le_of_nonneg_of_le_mul (abs_nonneg _) (pow_nonneg (abs_nonneg _) _) _, refine le_mul_of_one_le_right (pow_nonneg (abs_nonneg _) _) _, rw abs_of_nonneg ((add_nonneg zero_le_one (sq_nonneg x)) : (0 : ℝ) ≤ _), exact (le_add_of_nonneg_right (sq_nonneg x) : (1 : ℝ) ≤ _) }, have hbound1 : ∀ x ∈ Ico (U:ℝ) 1, |f' x| ≤ 1, { rintros x ⟨hx_left, hx_right⟩, have hincr := pow_le_pow_of_le_left (le_trans hU2 hx_left) (le_of_lt hx_right) (2*k), rw [one_pow (2*k), ← abs_of_nonneg (le_trans hU2 hx_left)] at hincr, rw ← abs_of_nonneg (le_trans hU2 hx_left) at hx_right, linarith [f'_bound x (mem_Icc.mpr (abs_le.mp (le_of_lt hx_right)))] }, have hbound2 : ∀ x ∈ Ico 0 (U:ℝ), |f' x| ≤ U ^ (2*k), { rintros x ⟨hx_left, hx_right⟩, have hincr := pow_le_pow_of_le_left hx_left (le_of_lt hx_right) (2*k), rw ← abs_of_nonneg hx_left at hincr hx_right, rw ← abs_of_nonneg hU2 at hU1 hx_right, linarith [f'_bound x (mem_Icc.mpr (abs_le.mp (le_trans (le_of_lt hx_right) hU1)))] }, -- (6) We twice apply the Mean Value Theorem to obtain bounds on `f` from the bounds on `f'` have mvt1 := norm_image_sub_le_of_norm_deriv_le_segment' hderiv1 hbound1 _ (right_mem_Icc.mpr hU1), have mvt2 := norm_image_sub_le_of_norm_deriv_le_segment' hderiv2 hbound2 _ (right_mem_Icc.mpr hU2), -- The following algebra is enough to complete the proof calc |f 1 - f 0| = |(f 1 - f U) + (f U - f 0)| : by ring_nf ... ≤ 1 * (1-U) + U^(2*k) * (U - 0) : le_trans (abs_add (f 1 - f U) (f U - f 0)) (add_le_add mvt1 mvt2) ... = 1 - U + U^(2*k) * U : by ring ... = 1 - (u k) + (u k)^(2*(k:ℝ)+1) : by { rw [← pow_succ' (U:ℝ) (2*k)], norm_cast }, end end real
9ba63da085c22428d738e64939a265c9616e9f01
43390109ab88557e6090f3245c47479c123ee500
/src/classical_logic/proposional_lemmas.lean
55c136f9e4529cb430783da84c193098488cf97f
[ "Apache-2.0" ]
permissive
Ja1941/xena-UROP-2018
41f0956519f94d56b8bf6834a8d39473f4923200
b111fb87f343cf79eca3b886f99ee15c1dd9884b
refs/heads/master
1,662,355,955,139
1,590,577,325,000
1,590,577,325,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
952
lean
open classical variables { p q r : Prop } theorem not_not_iff : ¬¬p ↔ p := ⟨by_contradiction ∘ flip absurd, not_not_intro⟩ theorem imp_classical : p → q ↔ ¬ p ∨ q := ⟨λh, by_cases (or.inr ∘ h) or.inl, λh h1, h.elim (absurd h1) id⟩ theorem not_and_iff_neg_or : ¬ (p ∧ q) ↔ (¬ p ∨ ¬ q) := by { split; intro h, { apply @by_cases p; intro h1, { apply @by_cases q; intro h2, { apply false.elim, apply h, split, exact h1, exact h2 }, { right, exact h2 } }, { left, exact h1 } }, { intro h1, cases h1 with h2 h3, cases h with h h; apply h, exact h2, exact h3 } } theorem not_or_iff_neg_and : ¬ (p ∨ q) ↔ (¬ p ∧ ¬ q) := by { split; intro h, { split; intro h1; apply h, { left, exact h1 }, { right, exact h1 } }, { cases h with h h1, intro h2, cases h2 with h2 h2, { apply h, exact h2 }, { apply h1, exact h2 } } }
1d39fcf5243b7bdcb99f25dffdf950ce7cceba3f
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/tactic/omega/clause.lean
96e6f9469eae793b8ab8afa0835f04e2e8d147dd
[ "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,028
lean
/- Copyright (c) 2019 Seul Baek. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Seul Baek -/ /- Definition of linear constrain clauses. -/ import data.list.basic import tactic.omega.term namespace omega /-- (([t₁,...tₘ],[s₁,...,sₙ]) : clause) encodes the constraints 0 = ⟦t₁⟧ ∧ ... ∧ 0 = ⟦tₘ⟧ ∧ 0 ≤ ⟦s₁⟧ ∧ ... ∧ 0 ≤ ⟦sₙ⟧, where ⟦t⟧ is the value of (t : term). -/ @[reducible] def clause := (list term) × (list term) namespace clause /-- holds v c := clause c holds under valuation v -/ def holds (v : nat → int) : clause → Prop | (eqs,les) := ( (∀ t : term, t ∈ eqs → 0 = term.val v t) ∧ (∀ t : term, t ∈ les → 0 ≤ term.val v t) ) /-- sat c := there exists a valuation v under which c holds -/ def sat (c : clause) : Prop := ∃ v : nat → int, holds v c /-- unsat c := there is no valuation v under which c holds -/ def unsat (c : clause) : Prop := ¬ c.sat /-- append two clauses by elementwise appending -/ def append (c1 c2 : clause) : clause := (c1.fst ++ c2.fst, c1.snd ++ c2.snd) lemma holds_append {v : nat → int} {c1 c2 : clause} : holds v c1 → holds v c2 → holds v (append c1 c2) := begin intros h1 h2, cases c1 with eqs1 les1, cases c2 with eqs2 les2, cases h1, cases h2, constructor; rw list.forall_mem_append; constructor; assumption, end end clause /-- There exists a satisfiable clause c in argument -/ def clauses.sat (cs : list clause) : Prop := ∃ c ∈ cs, clause.sat c /-- There is no satisfiable clause c in argument -/ def clauses.unsat (cs : list clause) : Prop := ¬ clauses.sat cs lemma clauses.unsat_nil : clauses.unsat [] := begin intro h1, rcases h1 with ⟨c,h1,h2⟩, cases h1 end lemma clauses.unsat_cons (c : clause) (cs : list clause) : clause.unsat c → clauses.unsat cs → clauses.unsat (c::cs) | h1 h2 h3 := begin unfold clauses.sat at h3, rw list.exists_mem_cons_iff at h3, cases h3; contradiction, end end omega
f0713b47250182b1179581fff64e56ef1f4d94f5
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/src/Lean/Elab/Deriving/Repr.lean
461d21036acf27d82bc6472ad018a02681834b46
[ "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
5,207
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Meta.Transform import Lean.Meta.Inductive import Lean.Elab.Deriving.Basic import Lean.Elab.Deriving.Util namespace Lean.Elab.Deriving.Repr open Lean.Parser.Term open Meta open Std def mkReprHeader (indVal : InductiveVal) : TermElabM Header := do let header ← mkHeader `Repr 1 indVal return { header with binders := header.binders.push (← `(bracketedBinderF| (prec : Nat))) } def mkBodyForStruct (header : Header) (indVal : InductiveVal) : TermElabM Term := do let ctorVal ← getConstInfoCtor indVal.ctors.head! let fieldNames := getStructureFields (← getEnv) indVal.name let numParams := indVal.numParams let target := mkIdent header.targetNames[0]! forallTelescopeReducing ctorVal.type fun xs _ => do let mut fields ← `(Format.nil) if xs.size != numParams + fieldNames.size then throwError "'deriving Repr' failed, unexpected number of fields in structure" for i in [:fieldNames.size] do let fieldName := fieldNames[i]! let fieldNameLit := Syntax.mkStrLit (toString fieldName) let x := xs[numParams + i]! if i != 0 then fields ← `($fields ++ "," ++ Format.line) if (← isType x <||> isProof x) then fields ← `($fields ++ $fieldNameLit ++ " := " ++ "_") else let indent := Syntax.mkNumLit <| toString ((toString fieldName |>.length) + " := ".length) fields ← `($fields ++ $fieldNameLit ++ " := " ++ (Format.group (Format.nest $indent (repr ($target.$(mkIdent fieldName):ident))))) `(Format.bracket "{ " $fields:term " }") def mkBodyForInduct (header : Header) (indVal : InductiveVal) (auxFunName : Name) : TermElabM Term := do let discrs ← mkDiscrs header indVal let alts ← mkAlts `(match $[$discrs],* with $alts:matchAlt*) where mkAlts : TermElabM (Array (TSyntax ``matchAlt)) := do let mut alts := #[] for ctorName in indVal.ctors do let ctorInfo ← getConstInfoCtor ctorName let alt ← forallTelescopeReducing ctorInfo.type fun xs _ => do let mut patterns := #[] -- add `_` pattern for indices for _ in [:indVal.numIndices] do patterns := patterns.push (← `(_)) let mut ctorArgs := #[] let mut rhs : Term := Syntax.mkStrLit (toString ctorInfo.name) rhs ← `(Format.text $rhs) -- add `_` for inductive parameters, they are inaccessible for _ in [:indVal.numParams] do ctorArgs := ctorArgs.push (← `(_)) for i in [:ctorInfo.numFields] do let x := xs[indVal.numParams + i]! let a := mkIdent (← mkFreshUserName `a) ctorArgs := ctorArgs.push a let localDecl ← x.fvarId!.getDecl if localDecl.binderInfo.isExplicit then if (← inferType x).isAppOf indVal.name then rhs ← `($rhs ++ Format.line ++ $(mkIdent auxFunName):ident $a:ident max_prec) else rhs ← `($rhs ++ Format.line ++ reprArg $a) patterns := patterns.push (← `(@$(mkIdent ctorName):ident $ctorArgs:term*)) `(matchAltExpr| | $[$patterns:term],* => Repr.addAppParen (Format.group (Format.nest (if prec >= max_prec then 1 else 2) ($rhs:term))) prec) alts := alts.push alt return alts def mkBody (header : Header) (indVal : InductiveVal) (auxFunName : Name) : TermElabM Term := do if isStructure (← getEnv) indVal.name then mkBodyForStruct header indVal else mkBodyForInduct header indVal auxFunName def mkAuxFunction (ctx : Context) (i : Nat) : TermElabM Command := do let auxFunName := ctx.auxFunNames[i]! let indVal := ctx.typeInfos[i]! let header ← mkReprHeader indVal let mut body ← mkBody header indVal auxFunName if ctx.usePartial then let letDecls ← mkLocalInstanceLetDecls ctx `Repr header.argNames body ← mkLet letDecls body let binders := header.binders if ctx.usePartial then `(private partial def $(mkIdent auxFunName):ident $binders:bracketedBinder* : Format := $body:term) else `(private def $(mkIdent auxFunName):ident $binders:bracketedBinder* : Format := $body:term) def mkMutualBlock (ctx : Context) : TermElabM Syntax := do let mut auxDefs := #[] for i in [:ctx.typeInfos.size] do auxDefs := auxDefs.push (← mkAuxFunction ctx i) `(mutual $auxDefs:command* end) private def mkReprInstanceCmds (declNames : Array Name) : TermElabM (Array Syntax) := do let ctx ← mkContext "repr" declNames[0]! let cmds := #[← mkMutualBlock ctx] ++ (← mkInstanceCmds ctx `Repr declNames) trace[Elab.Deriving.repr] "\n{cmds}" return cmds open Command def mkReprInstanceHandler (declNames : Array Name) : CommandElabM Bool := do if (← declNames.allM isInductive) && declNames.size > 0 then let cmds ← liftTermElabM <| mkReprInstanceCmds declNames cmds.forM elabCommand return true else return false builtin_initialize registerDerivingHandler `Repr mkReprInstanceHandler registerTraceClass `Elab.Deriving.repr end Lean.Elab.Deriving.Repr
1e084f1425a99c9da48d079030fdbb6755140b7e
e514e8b939af519a1d5e9b30a850769d058df4e9
/src/tactic/rewrite_search/command/suggestion.lean
b3283ac847a316a9001815829ed6c001496be8cb
[]
no_license
semorrison/lean-rewrite-search
dca317c5a52e170fb6ffc87c5ab767afb5e3e51a
e804b8f2753366b8957be839908230ee73f9e89f
refs/heads/master
1,624,051,754,485
1,614,160,817,000
1,614,160,817,000
162,660,605
0
1
null
null
null
null
UTF-8
Lean
false
false
676
lean
import tactic.where -- Import the `@[suggest]` attribute definition, since we emit code which uses it. import tactic.rewrite_search.discovery.suggest open lean.parser interactive open tactic.rewrite_search.discovery @[user_command] meta def suggestion_cmd (d : decl_meta_info) (_ : parse $ tk "suggestion") : lean.parser unit := do bn ← opt_single_or_list ident, -- Implement option parsing here, e.g: -- tgt ← optional (tk "at" *> ident), pfx ← get_namespace, of_tactic' $ do sfx ← tactic.mk_user_fresh_name, let n := pfx ++ sfx, tactic.add_meta_definition n [] `(list name) (reflect bn).to_expr, user_attribute.set suggest_attr n [] tt
53a622d78dd87f6592fde159e2aefe73087e11d8
5749d8999a76f3a8fddceca1f6941981e33aaa96
/src/linear_algebra/tensor_product.lean
39b4d34db06cd202031128bc768a418544e43f5b
[ "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
15,953
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro Tensor product of modules over commutative rings. -/ import group_theory.free_abelian_group import linear_algebra.direct_sum_module variables {R : Type*} [comm_ring R] variables {M : Type*} {N : Type*} {P : Type*} {Q : Type*} variables [add_comm_group M] [add_comm_group N] [add_comm_group P] [add_comm_group Q] variables [module R M] [module R N] [module R P] [module R Q] include R set_option class.instance_max_depth 100 namespace linear_map variables (R) def mk₂ (f : M → N → P) (H1 : ∀ m₁ m₂ n, f (m₁ + m₂) n = f m₁ n + f m₂ n) (H2 : ∀ (c:R) m n, f (c • m) n = c • f m n) (H3 : ∀ m n₁ n₂, f m (n₁ + n₂) = f m n₁ + f m n₂) (H4 : ∀ (c:R) m n, f m (c • n) = c • f m n) : M →ₗ N →ₗ P := ⟨λ m, ⟨f m, H3 m, λ c, H4 c m⟩, λ m₁ m₂, linear_map.ext $ H1 m₁ m₂, λ c m, linear_map.ext $ H2 c m⟩ variables {R} @[simp] theorem mk₂_apply (f : M → N → P) {H1 H2 H3 H4} (m : M) (n : N) : (mk₂ R f H1 H2 H3 H4 : M →ₗ[R] N →ₗ P) m n = f m n := rfl variables (f : M →ₗ[R] N →ₗ[R] P) theorem ext₂ {f g : M →ₗ[R] N →ₗ[R] P} (H : ∀ m n, f m n = g m n) : f = g := linear_map.ext (λ m, linear_map.ext $ λ n, H m n) def flip : N →ₗ M →ₗ P := mk₂ R (λ n m, f m n) (λ n₁ n₂ m, (f m).map_add _ _) (λ c n m, (f m).map_smul _ _) (λ n m₁ m₂, by rw f.map_add; refl) (λ c n m, by rw f.map_smul; refl) @[simp] theorem flip_apply (m : M) (n : N) : flip f n m = f m n := rfl variables {R} theorem flip_inj {f g : M →ₗ[R] N →ₗ P} (H : flip f = flip g) : f = g := ext₂ $ λ m n, show flip f n m = flip g n m, by rw H variables (R M N P) def lflip : (M →ₗ[R] N →ₗ P) →ₗ[R] N →ₗ M →ₗ P := ⟨flip, λ _ _, rfl, λ _ _, rfl⟩ variables {R M N P} @[simp] theorem lflip_apply (m : M) (n : N) : lflip R M N P f n m = f m n := rfl theorem map_zero₂ (y) : f 0 y = 0 := (flip f y).map_zero theorem map_neg₂ (x y) : f (-x) y = -f x y := (flip f y).map_neg _ theorem map_add₂ (x₁ x₂ y) : f (x₁ + x₂) y = f x₁ y + f x₂ y := (flip f y).map_add _ _ theorem map_smul₂ (r:R) (x y) : f (r • x) y = r • f x y := (flip f y).map_smul _ _ variables (R P) def lcomp (f : M →ₗ[R] N) : (N →ₗ P) →ₗ M →ₗ P := flip $ (flip id).comp f variables {R P} @[simp] theorem lcomp_apply (f : M →ₗ[R] N) (g : N →ₗ P) (x : M) : lcomp R P f g x = g (f x) := rfl variables (R M N P) def llcomp : (N →ₗ[R] P) →ₗ[R] (M →ₗ[R] N) →ₗ M →ₗ P := flip ⟨lcomp R P, λ f f', ext₂ $ λ g x, g.map_add _ _, λ c f, ext₂ $ λ g x, g.map_smul _ _⟩ variables {R M N P} section @[simp] theorem llcomp_apply (f : N →ₗ[R] P) (g : M →ₗ[R] N) (x : M) : llcomp R M N P f g x = f (g x) := rfl end def compl₂ (g : Q →ₗ N) : M →ₗ Q →ₗ P := (lcomp R _ g).comp f @[simp] theorem compl₂_apply (g : Q →ₗ[R] N) (m : M) (q : Q) : f.compl₂ g m q = f m (g q) := rfl def compr₂ (g : P →ₗ Q) : M →ₗ N →ₗ Q := linear_map.comp (llcomp R N P Q g) f @[simp] theorem compr₂_apply (g : P →ₗ[R] Q) (m : M) (n : N) : f.compr₂ g m n = g (f m n) := rfl variables (R M) def lsmul : R →ₗ M →ₗ M := mk₂ R (•) add_smul (λ _ _ _, mul_smul _ _ _) smul_add (λ r s m, by simp only [smul_smul, smul_eq_mul, mul_comm]) variables {R M} @[simp] theorem lsmul_apply (r : R) (m : M) : lsmul R M r m = r • m := rfl end linear_map variables (M N) namespace tensor_product section open free_abelian_group variables (R) def relators : set (free_abelian_group (M × N)) := add_group.closure { x : free_abelian_group (M × N) | (∃ (m₁ m₂ : M) (n : N), x = of (m₁, n) + of (m₂, n) - of (m₁ + m₂, n)) ∨ (∃ (m : M) (n₁ n₂ : N), x = of (m, n₁) + of (m, n₂) - of (m, n₁ + n₂)) ∨ (∃ (r : R) (m : M) (n : N), x = of (r • m, n) - of (m, r • n)) } end namespace relators instance : normal_add_subgroup (relators R M N) := by unfold relators; apply normal_add_subgroup_of_add_comm_group end relators end tensor_product variables (R) def tensor_product : Type* := quotient_add_group.quotient (tensor_product.relators R M N) variables {R} localized "infix ` ⊗ `:100 := tensor_product _" in tensor_product localized "notation M ` ⊗[`:100 R `] ` N:100 := tensor_product R M N" in tensor_product namespace tensor_product section module local attribute [instance] quotient_add_group.left_rel normal_add_subgroup.to_is_add_subgroup instance : add_comm_group (M ⊗[R] N) := quotient_add_group.add_comm_group _ instance quotient.mk.is_add_group_hom : is_add_group_hom (quotient.mk : free_abelian_group (M × N) → M ⊗ N) := quotient_add_group.is_add_group_hom _ variables (R) {M N} def tmul (m : M) (n : N) : M ⊗[R] N := quotient_add_group.mk $ free_abelian_group.of (m, n) variables {R} infix ` ⊗ₜ `:100 := tmul _ notation x ` ⊗ₜ[`:100 R `] ` y := tmul R x y lemma add_tmul (m₁ m₂ : M) (n : N) : (m₁ + m₂) ⊗ₜ n = m₁ ⊗ₜ n + m₂ ⊗ₜ[R] n := eq.symm $ sub_eq_zero.1 $ eq.symm $ quotient.sound $ add_group.in_closure.basic $ or.inl $ ⟨m₁, m₂, n, rfl⟩ lemma tmul_add (m : M) (n₁ n₂ : N) : m ⊗ₜ (n₁ + n₂) = m ⊗ₜ n₁ + m ⊗ₜ[R] n₂ := eq.symm $ sub_eq_zero.1 $ eq.symm $ quotient.sound $ add_group.in_closure.basic $ or.inr $ or.inl $ ⟨m, n₁, n₂, rfl⟩ lemma smul_tmul (r : R) (m : M) (n : N) : (r • m) ⊗ₜ n = m ⊗ₜ[R] (r • n) := sub_eq_zero.1 $ eq.symm $ quotient.sound $ add_group.in_closure.basic $ or.inr $ or.inr $ ⟨r, m, n, rfl⟩ local attribute [instance] quotient_add_group.is_add_group_hom_quotient_lift def smul.aux (r : R) : free_abelian_group (M × N) → M ⊗[R] N := free_abelian_group.lift (λ (y : M × N), (r • y.1) ⊗ₜ y.2) instance (r : R) : is_add_group_hom (smul.aux r : _ → M ⊗ N) := by unfold smul.aux; apply_instance instance : has_scalar R (M ⊗ N) := ⟨λ r, quotient_add_group.lift _ (smul.aux r) $ λ x hx, begin refine (is_add_group_hom.mem_ker (smul.aux r : _ → M ⊗ N)).1 (add_group.closure_subset _ hx), clear hx x, rintro x (⟨m₁, m₂, n, rfl⟩ | ⟨m, n₁, n₂, rfl⟩ | ⟨q, m, n, rfl⟩); simp only [smul.aux, is_add_group_hom.mem_ker, -sub_eq_add_neg, sub_self, add_tmul, tmul_add, smul_tmul, smul_add, smul_smul, mul_comm, free_abelian_group.lift.of, free_abelian_group.lift.add, free_abelian_group.lift.sub] end⟩ instance smul.is_add_group_hom (r : R) : is_add_group_hom ((•) r : M ⊗[R] N → M ⊗[R] N) := by unfold has_scalar.smul; apply_instance protected theorem smul_add (r : R) (x y : M ⊗[R] N) : r • (x + y) = r • x + r • y := is_add_hom.map_add _ _ _ instance : module R (M ⊗ N) := module.of_core { smul := (•), smul_add := tensor_product.smul_add, add_smul := begin intros r s x, apply quotient_add_group.induction_on' x, intro z, symmetry, refine @free_abelian_group.lift.unique _ _ _ _ _ (is_add_group_hom.mk' $ λ p q, _) _ z, { simp [tensor_product.smul_add] }, rintro ⟨m, n⟩, change (r • m) ⊗ₜ n + (s • m) ⊗ₜ n = ((r + s) • m) ⊗ₜ n, rw [add_smul, add_tmul] end, mul_smul := begin intros r s x, apply quotient_add_group.induction_on' x, intro z, symmetry, refine @free_abelian_group.lift.unique _ _ _ _ _ (is_add_group_hom.mk' $ λ p q, _) _ z, { simp [tensor_product.smul_add] }, rintro ⟨m, n⟩, change r • s • (m ⊗ₜ n) = ((r * s) • m) ⊗ₜ n, rw mul_smul, refl end, one_smul := λ x, quotient.induction_on x $ λ _, eq.symm $ free_abelian_group.lift.unique _ _ $ λ ⟨p, q⟩, by rw one_smul; refl } @[simp] lemma tmul_smul (r : R) (x : M) (y : N) : x ⊗ₜ (r • y) = r • (x ⊗ₜ[R] y) := (smul_tmul _ _ _).symm variables (R M N) def mk : M →ₗ N →ₗ M ⊗ N := linear_map.mk₂ R (⊗ₜ) add_tmul (λ c m n, by rw [smul_tmul, tmul_smul]) tmul_add tmul_smul variables {R M N} @[simp] lemma mk_apply (m : M) (n : N) : mk R M N m n = m ⊗ₜ n := rfl lemma zero_tmul (n : N) : (0 ⊗ₜ[R] n : M ⊗ N) = 0 := (mk R M N).map_zero₂ _ lemma tmul_zero (m : M) : (m ⊗ₜ[R] 0 : M ⊗ N) = 0 := (mk R M N _).map_zero lemma neg_tmul (m : M) (n : N) : (-m) ⊗ₜ n = -(m ⊗ₜ[R] n) := (mk R M N).map_neg₂ _ _ lemma tmul_neg (m : M) (n : N) : m ⊗ₜ (-n) = -(m ⊗ₜ[R] n) := (mk R M N _).map_neg _ end module local attribute [instance] quotient_add_group.left_rel normal_add_subgroup.to_is_add_subgroup @[elab_as_eliminator] protected theorem induction_on {C : (M ⊗[R] N) → Prop} (z : M ⊗[R] N) (C0 : C 0) (C1 : ∀ x y, C $ x ⊗ₜ[R] y) (Cp : ∀ x y, C x → C y → C (x + y)) : C z := quotient.induction_on z $ λ x, free_abelian_group.induction_on x C0 (λ ⟨p, q⟩, C1 p q) (λ ⟨p, q⟩ _, show C (-(p ⊗ₜ q)), by rw ← neg_tmul; from C1 (-p) q) (λ _ _, Cp _ _) section UMP variables {M N P Q} variables (f : M →ₗ[R] N →ₗ[R] P) local attribute [instance] free_abelian_group.lift.is_add_group_hom def lift_aux : (M ⊗[R] N) → P := quotient_add_group.lift _ (free_abelian_group.lift $ λ z, f z.1 z.2) $ λ x hx, begin refine (is_add_group_hom.mem_ker _).1 (add_group.closure_subset _ hx), clear hx x, rintro x (⟨m₁, m₂, n, rfl⟩ | ⟨m, n₁, n₂, rfl⟩ | ⟨q, m, n, rfl⟩); simp [is_add_group_hom.mem_ker, -sub_eq_add_neg, f.map_add, f.map_add₂, f.map_smul, f.map_smul₂, sub_self], end variable {f} local attribute [instance] quotient_add_group.left_rel normal_add_subgroup.to_is_add_subgroup @[simp] lemma lift_aux.add (x y) : lift_aux f (x + y) = lift_aux f x + lift_aux f y := quotient.induction_on₂ x y $ λ m n, free_abelian_group.lift.add _ _ _ @[simp] lemma lift_aux.smul (r:R) (x) : lift_aux f (r • x) = r • lift_aux f x := tensor_product.induction_on _ _ x (smul_zero _).symm (λ p q, by rw [← tmul_smul]; simp [lift_aux, tmul]) (λ p q ih1 ih2, by simp [@smul_add _ _ _ _ _ _ p _, lift_aux.add, ih1, ih2, smul_add]) variable (f) def lift : M ⊗ N →ₗ P := { to_fun := lift_aux f, add := lift_aux.add, smul := lift_aux.smul } variable {f} @[simp] lemma lift.tmul (x y) : lift f (x ⊗ₜ y) = f x y := zero_add _ @[simp] lemma lift.tmul' (x y) : (lift f).1 (x ⊗ₜ y) = f x y := lift.tmul _ _ theorem lift.unique {g : (M ⊗[R] N) →ₗ[R] P} (H : ∀ x y, g (x ⊗ₜ y) = f x y) : g = lift f := linear_map.ext $ λ z, begin apply quotient_add_group.induction_on' z, intro z, refine @free_abelian_group.lift.unique _ _ _ _ _ (is_add_group_hom.mk' $ λ p q, _) _ z, { simp [g.2] }, exact λ ⟨m, n⟩, H m n end theorem lift_mk : lift (mk R M N) = linear_map.id := eq.symm $ lift.unique $ λ x y, rfl theorem lift_compr₂ (g : P →ₗ Q) : lift (f.compr₂ g) = g.comp (lift f) := eq.symm $ lift.unique $ λ x y, by simp theorem lift_mk_compr₂ (f : M ⊗ N →ₗ P) : lift ((mk R M N).compr₂ f) = f := by rw [lift_compr₂, lift_mk, linear_map.comp_id] theorem ext {g h : (M ⊗[R] N) →ₗ[R] P} (H : ∀ x y, g (x ⊗ₜ y) = h (x ⊗ₜ y)) : g = h := by rw ← lift_mk_compr₂ h; exact lift.unique H theorem mk_compr₂_inj {g h : M ⊗ N →ₗ P} (H : (mk R M N).compr₂ g = (mk R M N).compr₂ h) : g = h := by rw [← lift_mk_compr₂ g, H, lift_mk_compr₂] example : M → N → (M → N → P) → P := λ m, flip $ λ f, f m variables (R M N P) def uncurry : (M →ₗ N →ₗ[R] P) →ₗ M ⊗ N →ₗ P := linear_map.flip $ lift $ (linear_map.lflip _ _ _ _).comp linear_map.id.flip variables {R M N P} @[simp] theorem uncurry_apply (f : M →ₗ[R] N →ₗ[R] P) (m : M) (n : N) : uncurry R M N P f (m ⊗ₜ n) = f m n := by rw [uncurry, linear_map.flip_apply, lift.tmul]; refl variables (R M N P) def lift.equiv : (M →ₗ N →ₗ P) ≃ₗ (M ⊗ N →ₗ P) := { inv_fun := λ f, (mk R M N).compr₂ f, left_inv := λ f, linear_map.ext₂ $ λ m n, lift.tmul _ _, right_inv := λ f, ext $ λ m n, lift.tmul _ _, .. uncurry R M N P } def lcurry : (M ⊗[R] N →ₗ[R] P) →ₗ[R] M →ₗ[R] N →ₗ[R] P := (lift.equiv R M N P).symm variables {R M N P} @[simp] theorem lcurry_apply (f : M ⊗[R] N →ₗ[R] P) (m : M) (n : N) : lcurry R M N P f m n = f (m ⊗ₜ n) := rfl def curry (f : M ⊗ N →ₗ P) : M →ₗ N →ₗ P := lcurry R M N P f @[simp] theorem curry_apply (f : M ⊗ N →ₗ[R] P) (m : M) (n : N) : curry f m n = f (m ⊗ₜ n) := rfl end UMP variables {M N} /-- The base ring is a left identity for the tensor product of modules, up to linear equivalence. -/ protected def lid : R ⊗ M ≃ₗ M := linear_equiv.of_linear (lift $ linear_map.lsmul R M) (mk R R M 1) (linear_map.ext $ λ _, by simp) (ext $ λ r m, by simp; rw [← tmul_smul, ← smul_tmul, smul_eq_mul, mul_one]) /-- The tensor product of modules is commutative, up to linear equivalence. -/ protected def comm : M ⊗ N ≃ₗ N ⊗ M := linear_equiv.of_linear (lift (mk R N M).flip) (lift (mk R M N).flip) (ext $ λ m n, rfl) (ext $ λ m n, rfl) /-- The base ring is a right identity for the tensor product of modules, up to linear equivalence. -/ protected def rid : M ⊗ R ≃ₗ M := linear_equiv.trans tensor_product.comm tensor_product.lid open linear_map protected def assoc : (M ⊗[R] N) ⊗[R] P ≃ₗ[R] M ⊗[R] (N ⊗[R] P) := begin refine linear_equiv.of_linear (lift $ lift $ comp (lcurry R _ _ _) $ mk _ _ _) (lift $ comp (uncurry R _ _ _) $ curry $ mk _ _ _) (mk_compr₂_inj $ linear_map.ext $ λ m, ext $ λ n p, _) (mk_compr₂_inj $ flip_inj $ linear_map.ext $ λ p, ext $ λ m n, _); repeat { rw lift.tmul <|> rw compr₂_apply <|> rw comp_apply <|> rw mk_apply <|> rw flip_apply <|> rw lcurry_apply <|> rw uncurry_apply <|> rw curry_apply <|> rw id_apply } end def map (f : M →ₗ[R] P) (g : N →ₗ Q) : M ⊗ N →ₗ P ⊗ Q := lift $ comp (compl₂ (mk _ _ _) g) f @[simp] theorem map_tmul (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (m : M) (n : N) : map f g (m ⊗ₜ n) = f m ⊗ₜ g n := rfl def congr (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) : M ⊗ N ≃ₗ[R] P ⊗ Q := linear_equiv.of_linear (map f g) (map f.symm g.symm) (ext $ λ m n, by simp; simp only [linear_equiv.apply_symm_apply]) (ext $ λ m n, by simp; simp only [linear_equiv.symm_apply_apply]) variables (ι₁ : Type*) (ι₂ : Type*) variables [decidable_eq ι₁] [decidable_eq ι₂] variables (M₁ : ι₁ → Type*) (M₂ : ι₂ → Type*) variables [Π i₁, add_comm_group (M₁ i₁)] [Π i₂, add_comm_group (M₂ i₂)] variables [Π i₁, module R (M₁ i₁)] [Π i₂, module R (M₂ i₂)] def direct_sum : direct_sum ι₁ M₁ ⊗[R] direct_sum ι₂ M₂ ≃ₗ[R] direct_sum (ι₁ × ι₂) (λ i, M₁ i.1 ⊗[R] M₂ i.2) := begin refine linear_equiv.of_linear (lift $ direct_sum.to_module R _ _ $ λ i₁, flip $ direct_sum.to_module R _ _ $ λ i₂, flip $ curry $ direct_sum.lof R (ι₁ × ι₂) (λ i, M₁ i.1 ⊗[R] M₂ i.2) (i₁, i₂)) (direct_sum.to_module R _ _ $ λ i, map (direct_sum.lof R _ _ _) (direct_sum.lof R _ _ _)) (linear_map.ext $ direct_sum.to_module.ext _ $ λ i, mk_compr₂_inj $ linear_map.ext $ λ x₁, linear_map.ext $ λ x₂, _) (mk_compr₂_inj $ linear_map.ext $ direct_sum.to_module.ext _ $ λ i₁, linear_map.ext $ λ x₁, linear_map.ext $ direct_sum.to_module.ext _ $ λ i₂, linear_map.ext $ λ x₂, _); repeat { rw compr₂_apply <|> rw comp_apply <|> rw id_apply <|> rw mk_apply <|> rw direct_sum.to_module_lof <|> rw map_tmul <|> rw lift.tmul <|> rw flip_apply <|> rw curry_apply }, cases i; refl end end tensor_product
633db1161456cabffc9c7bdef732f3d2a8c87451
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/algebra/big_operators/finprod.lean
4e54d6ce17006b8362f141f0217c1aa9a65a134b
[ "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
35,604
lean
/- Copyright (c) 2020 Kexing Ying and Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Kevin Buzzard, Yury Kudryashov -/ import data.set.finite import data.set.disjointed import algebra.big_operators import algebra.indicator_function /-! # Finite products and sums over types and sets We define products and sums over types and subsets of types, with no finiteness hypotheses. All infinite products and sums are defined to be junk values (i.e. one or zero). This approach is sometimes easier to use than `finset.sum`, when issues arise with `finset` and `fintype` being data. ## Main definitions We use the following variables: * `α`, `β` - types with no structure; * `s`, `t` - sets * `M`, `N` - additive or multiplicative commutative monoids * `f`, `g` - functions Definitions in this file: * `finsum f : M` : the sum of `f x` as `x` ranges over the support of `f`, if it's finite. Zero otherwise. * `finprod f : M` : the product of `f x` as `x` ranges over the multiplicative support of `f`, if it's finite. One otherwise. ## Notation * `∑ᶠ i, f i` and `∑ᶠ i : α, f i` for `finsum f` * `∏ᶠ i, f i` and `∏ᶠ i : α, f i` for `finprod f` This notation works for functions `f : p → M`, where `p : Prop`, so the following works: * `∑ᶠ i ∈ s, f i`, where `f : α → M`, `s : set α` : sum over the set `s`; * `∑ᶠ n < 5, f n`, where `f : ℕ → M` : same as `f 0 + f 1 + f 2 + f 3 + f 4`; * `∏ᶠ (n >= -2) (hn : n < 3), f n`, where `f : ℤ → M` : same as `f (-2) * f (-1) * f 0 * f 1 * f 2`. ## Implementation notes `finsum` and `finprod` is "yet another way of doing finite sums and products in Lean". However experiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings where the user is not interested in computability and wants to do reasoning without running into typeclass diamonds caused by the constructive finiteness used in definitions such as `finset` and `fintype`. By sticking solely to `set.finite` we avoid these problems. We are aware that there are other solutions but for beginner mathematicians this approach is easier in practice. Another application is the construction of a partition of unity from a collection of “bump” function. In this case the finite set depends on the point and it's convenient to have a definition that does not mention the set explicitly. 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. ## Todo We did not add `is_finite (X : Type) : Prop`, because it is simply `nonempty (fintype X)`. There is work on `fincard` in the pipeline, which returns the cardinality of `X` if it is finite, and 0 otherwise. ## Tags finsum, finprod, finite sum, finite product -/ open function set /-! ### Definition and relation to `finset.sum` and `finset.prod` -/ section sort variables {M N : Type*} {α β ι : Sort*} [comm_monoid M] [comm_monoid N] open_locale big_operators section /- Note: we use classical logic only for these definitions, to ensure that we do not write lemmas with `classical.dec` in their statement. -/ open_locale classical /-- Sum of `f x` as `x` ranges over the elements of the support of `f`, if it's finite. Zero otherwise. -/ @[irreducible] noncomputable def finsum {M α} [add_comm_monoid M] (f : α → M) : M := if h : finite (support (f ∘ plift.down)) then ∑ i in h.to_finset, f i.down else 0 /-- Product of `f x` as `x` ranges over the elements of the multiplicative support of `f`, if it's finite. One otherwise. -/ @[irreducible, to_additive] noncomputable def finprod (f : α → M) : M := if h : finite (mul_support (f ∘ plift.down)) then ∏ i in h.to_finset, f i.down else 1 end localized "notation `∑ᶠ` binders `, ` r:(scoped:67 f, finsum f) := r" in big_operators localized "notation `∏ᶠ` binders `, ` r:(scoped:67 f, finprod f) := r" in big_operators @[to_additive] lemma finprod_eq_prod_plift_of_mul_support_to_finset_subset {f : α → M} (hf : finite (mul_support (f ∘ plift.down))) {s : finset (plift α)} (hs : hf.to_finset ⊆ s) : ∏ᶠ i, f i = ∏ i in s, f i.down := begin rw [finprod, dif_pos], refine finset.prod_subset hs (λ x hx hxf, _), rwa [hf.mem_to_finset, nmem_mul_support] at hxf end @[to_additive] lemma finprod_eq_prod_plift_of_mul_support_subset {f : α → M} {s : finset (plift α)} (hs : mul_support (f ∘ plift.down) ⊆ s) : ∏ᶠ i, f i = ∏ i in s, f i.down := finprod_eq_prod_plift_of_mul_support_to_finset_subset (s.finite_to_set.subset hs) $ λ x hx, by { rw finite.mem_to_finset at hx, exact hs hx } @[simp, to_additive] lemma finprod_one : ∏ᶠ i : α, (1 : M) = 1 := begin have : mul_support (λ x : plift α, (λ _, 1 : α → M) x.down) ⊆ (∅ : finset (plift α)), from λ x h, h rfl, rw [finprod_eq_prod_plift_of_mul_support_subset this, finset.prod_empty] end @[to_additive] lemma finprod_of_is_empty [is_empty α] (f : α → M) : ∏ᶠ i, f i = 1 := by { rw ← finprod_one, congr } @[simp, to_additive] lemma finprod_false (f : false → M) : ∏ᶠ i, f i = 1 := finprod_of_is_empty _ @[to_additive] lemma finprod_unique [unique α] (f : α → M) : ∏ᶠ i, f i = f (default α) := begin have : mul_support (f ∘ plift.down) ⊆ (finset.univ : finset (plift α)), from λ x _, finset.mem_univ x, rw [finprod_eq_prod_plift_of_mul_support_subset this, univ_unique, finset.prod_singleton], exact congr_arg f (plift.down_up _) end @[simp, to_additive] lemma finprod_true (f : true → M) : ∏ᶠ i, f i = f trivial := @finprod_unique M true _ ⟨⟨trivial⟩, λ _, rfl⟩ f @[to_additive] lemma finprod_eq_dif {p : Prop} [decidable p] (f : p → M) : ∏ᶠ i, f i = if h : p then f h else 1 := begin split_ifs, { haveI : unique p := ⟨⟨h⟩, λ _, rfl⟩, exact finprod_unique f }, { haveI : is_empty p := ⟨h⟩, exact finprod_of_is_empty f } end @[to_additive] lemma finprod_eq_if {p : Prop} [decidable p] {x : M} : ∏ᶠ i : p, x = if p then x else 1 := finprod_eq_dif (λ _, x) @[to_additive] lemma finprod_congr {f g : α → M} (h : ∀ x, f x = g x) : finprod f = finprod g := congr_arg _ $ funext h @[congr, to_additive] lemma finprod_congr_Prop {p q : Prop} {f : p → M} {g : q → M} (hpq : p = q) (hfg : ∀ h : q, f (hpq.mpr h) = g h) : finprod f = finprod g := by { subst q, exact finprod_congr hfg } attribute [congr] finsum_congr_Prop lemma finprod_nonneg {R : Type*} [ordered_comm_semiring R] {f : α → R} (hf : ∀ x, 0 ≤ f x) : 0 ≤ ∏ᶠ x, f x := begin rw finprod, split_ifs, { exact finset.prod_nonneg (λ x _, hf _) }, { exact zero_le_one } end @[to_additive] lemma monoid_hom.map_finprod_plift (f : M →* N) (g : α → M) (h : finite (mul_support $ g ∘ plift.down)) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := begin rw [finprod_eq_prod_plift_of_mul_support_subset h.coe_to_finset.ge, finprod_eq_prod_plift_of_mul_support_subset, f.map_prod], rw [h.coe_to_finset], exact mul_support_comp_subset f.map_one (g ∘ plift.down) end @[to_additive] lemma monoid_hom.map_finprod_Prop {p : Prop} (f : M →* N) (g : p → M) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := f.map_finprod_plift g (finite.of_fintype _) end sort section type variables {α β ι M N : Type*} [comm_monoid M] [comm_monoid N] open_locale big_operators @[to_additive] lemma finprod_eq_mul_indicator_apply (s : set α) (f : α → M) (a : α) : ∏ᶠ (h : a ∈ s), f a = mul_indicator s f a := by convert finprod_eq_if @[simp, to_additive] lemma finprod_mem_mul_support (f : α → M) (a : α) : ∏ᶠ (h : f a ≠ 1), f a = f a := by rw [← mem_mul_support, finprod_eq_mul_indicator_apply, mul_indicator_mul_support] @[to_additive] lemma finprod_mem_def (s : set α) (f : α → M) : ∏ᶠ a ∈ s, f a = ∏ᶠ a, mul_indicator s f a := finprod_congr $ finprod_eq_mul_indicator_apply s f @[to_additive] lemma finprod_eq_prod_of_mul_support_subset (f : α → M) {s : finset α} (h : mul_support f ⊆ s) : ∏ᶠ i, f i = ∏ i in s, f i := begin have A : mul_support (f ∘ plift.down) = equiv.plift.symm '' mul_support f, { rw mul_support_comp_eq_preimage, exact (equiv.plift.symm.image_eq_preimage _).symm }, have : mul_support (f ∘ plift.down) ⊆ s.map equiv.plift.symm.to_embedding, { rw [A, finset.coe_map], exact image_subset _ h }, rw [finprod_eq_prod_plift_of_mul_support_subset this], simp end @[to_additive] lemma finprod_eq_prod_of_mul_support_to_finset_subset (f : α → M) (hf : finite (mul_support f)) {s : finset α} (h : hf.to_finset ⊆ s) : ∏ᶠ i, f i = ∏ i in s, f i := finprod_eq_prod_of_mul_support_subset _ $ λ x hx, h $ hf.mem_to_finset.2 hx @[to_additive] lemma finprod_def (f : α → M) [decidable (mul_support f).finite] : ∏ᶠ i : α, f i = if h : (mul_support f).finite then ∏ i in h.to_finset, f i else 1 := begin split_ifs, { exact finprod_eq_prod_of_mul_support_to_finset_subset _ h (finset.subset.refl _) }, { rw [finprod, dif_neg], rw [mul_support_comp_eq_preimage], exact mt (λ hf, hf.of_preimage equiv.plift.surjective) h} end @[to_additive] lemma finprod_of_infinite_mul_support {f : α → M} (hf : (mul_support f).infinite) : ∏ᶠ i, f i = 1 := by { classical, rw [finprod_def, dif_neg hf] } @[to_additive] lemma finprod_eq_prod (f : α → M) (hf : (mul_support f).finite) : ∏ᶠ i : α, f i = ∏ i in hf.to_finset, f i := by { classical, rw [finprod_def, dif_pos hf] } @[to_additive] lemma finprod_eq_prod_of_fintype [fintype α] (f : α → M) : ∏ᶠ i : α, f i = ∏ i, f i := finprod_eq_prod_of_mul_support_to_finset_subset _ (finite.of_fintype _) $ finset.subset_univ _ @[to_additive] lemma finprod_cond_eq_prod_of_cond_iff (f : α → M) {p : α → Prop} {t : finset α} (h : ∀ {x}, f x ≠ 1 → (p x ↔ x ∈ t)) : ∏ᶠ i (hi : p i), f i = ∏ i in t, f i := begin set s := {x | p x}, have : mul_support (s.mul_indicator f) ⊆ t, { rw [set.mul_support_mul_indicator], intros x hx, exact (h hx.2).1 hx.1 }, erw [finprod_mem_def, finprod_eq_prod_of_mul_support_subset _ this], refine finset.prod_congr rfl (λ x hx, mul_indicator_apply_eq_self.2 $ λ hxs, _), contrapose! hxs, exact (h hxs).2 hx end @[to_additive] lemma finprod_mem_eq_prod_of_inter_mul_support_eq (f : α → M) {s : set α} {t : finset α} (h : s ∩ mul_support f = t ∩ mul_support f) : ∏ᶠ i ∈ s, f i = ∏ i in t, f i := finprod_cond_eq_prod_of_cond_iff _ $ by simpa [set.ext_iff] using h @[to_additive] lemma finprod_mem_eq_prod_of_subset (f : α → M) {s : set α} {t : finset α} (h₁ : s ∩ mul_support f ⊆ t) (h₂ : ↑t ⊆ s) : ∏ᶠ i ∈ s, f i = ∏ i in t, f i := finprod_cond_eq_prod_of_cond_iff _ $ λ x hx, ⟨λ h, h₁ ⟨h, hx⟩, λ h, h₂ h⟩ @[to_additive] lemma finprod_mem_eq_prod (f : α → M) {s : set α} (hf : (s ∩ mul_support f).finite) : ∏ᶠ i ∈ s, f i = ∏ i in hf.to_finset, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by simp [inter_assoc] @[to_additive] lemma finprod_mem_eq_prod_filter (f : α → M) (s : set α) [decidable_pred (∈ s)] (hf : (mul_support f).finite) : ∏ᶠ i ∈ s, f i = ∏ i in finset.filter (∈ s) hf.to_finset, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by simp [inter_comm, inter_left_comm] @[to_additive] lemma finprod_mem_eq_to_finset_prod (f : α → M) (s : set α) [fintype s] : ∏ᶠ i ∈ s, f i = ∏ i in s.to_finset, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by rw [coe_to_finset] @[to_additive] lemma finprod_mem_eq_finite_to_finset_prod (f : α → M) {s : set α} (hs : s.finite) : ∏ᶠ i ∈ s, f i = ∏ i in hs.to_finset, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by rw [hs.coe_to_finset] @[to_additive] lemma finprod_mem_finset_eq_prod (f : α → M) (s : finset α) : ∏ᶠ i ∈ s, f i = ∏ i in s, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ rfl @[to_additive] lemma finprod_mem_coe_finset (f : α → M) (s : finset α) : ∏ᶠ i ∈ (s : set α), f i = ∏ i in s, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ rfl @[to_additive] lemma finprod_mem_eq_one_of_infinite {f : α → M} {s : set α} (hs : (s ∩ mul_support f).infinite) : ∏ᶠ i ∈ s, f i = 1 := begin rw finprod_mem_def, apply finprod_of_infinite_mul_support, rwa [← mul_support_mul_indicator] at hs end @[to_additive] lemma finprod_mem_inter_mul_support (f : α → M) (s : set α) : ∏ᶠ i ∈ (s ∩ mul_support f), f i = ∏ᶠ i ∈ s, f i := by rw [finprod_mem_def, finprod_mem_def, mul_indicator_inter_mul_support] @[to_additive] lemma finprod_mem_inter_mul_support_eq (f : α → M) (s t : set α) (h : s ∩ mul_support f = t ∩ mul_support f) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mul_support, h, finprod_mem_inter_mul_support] @[to_additive] lemma finprod_mem_inter_mul_support_eq' (f : α → M) (s t : set α) (h : ∀ x ∈ mul_support f, x ∈ s ↔ x ∈ t) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := begin apply finprod_mem_inter_mul_support_eq, ext x, exact and_congr_left (h x) end @[to_additive] lemma finprod_mem_univ (f : α → M) : ∏ᶠ i ∈ @set.univ α, f i = ∏ᶠ i : α, f i := finprod_congr $ λ i, finprod_true _ variables {f g : α → M} {a b : α} {s t : set α} @[to_additive] lemma finprod_mem_congr (h₀ : s = t) (h₁ : ∀ x ∈ t, f x = g x) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, g i := h₀.symm ▸ (finprod_congr $ λ i, finprod_congr_Prop rfl (h₁ i)) /-! ### Distributivity w.r.t. addition, subtraction, and (scalar) multiplication -/ /-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i * g i` equals the product of `f i` multiplied by the product over `g i`. -/ @[to_additive] lemma finprod_mul_distrib (hf : (mul_support f).finite) (hg : (mul_support g).finite) : ∏ᶠ i, (f i * g i) = (∏ᶠ i, f i) * ∏ᶠ i, g i := begin classical, rw [finprod_eq_prod_of_mul_support_to_finset_subset _ hf (finset.subset_union_left _ _), finprod_eq_prod_of_mul_support_to_finset_subset _ hg (finset.subset_union_right _ _), ← finset.prod_mul_distrib], refine finprod_eq_prod_of_mul_support_subset _ _, simp [mul_support_mul] end /-- A more general version of `finprod_mem_mul_distrib` that requires `s ∩ mul_support f` and `s ∩ mul_support g` instead of `s` to be finite. -/ @[to_additive] lemma finprod_mem_mul_distrib' (hf : (s ∩ mul_support f).finite) (hg : (s ∩ mul_support g).finite) : ∏ᶠ i ∈ s, (f i * g i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i := begin rw [← mul_support_mul_indicator] at hf hg, simp only [finprod_mem_def, mul_indicator_mul, finprod_mul_distrib hf hg] end /-- The product of constant one over any set equals one. -/ @[to_additive] lemma finprod_mem_one (s : set α) : ∏ᶠ i ∈ s, (1 : M) = 1 := by simp /-- If a function `f` equals one on a set `s`, then the product of `f i` over `i ∈ s` equals one. -/ @[to_additive] lemma finprod_mem_of_eq_on_one (hf : eq_on f 1 s) : ∏ᶠ i ∈ s, f i = 1 := by { rw ← finprod_mem_one s, exact finprod_mem_congr rfl hf } /-- If the product of `f i` over `i ∈ s` is not equal to one, then there is some `x ∈ s` such that `f x ≠ 1`. -/ @[to_additive] lemma exists_ne_one_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) : ∃ x ∈ s, f x ≠ 1 := begin by_contra h', push_neg at h', exact h (finprod_mem_of_eq_on_one h') end /-- Given a finite set `s`, the product of `f i * g i` over `i ∈ s` equals the product of `f i` over `i ∈ s` times the product of `g i` over `i ∈ s`. -/ @[to_additive] lemma finprod_mem_mul_distrib (hs : s.finite) : ∏ᶠ i ∈ s, (f i * g i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i := finprod_mem_mul_distrib' (hs.inter_of_left _) (hs.inter_of_left _) @[to_additive] lemma monoid_hom.map_finprod {f : α → M} (g : M →* N) (hf : (mul_support f).finite) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.map_finprod_plift f $ hf.preimage $ equiv.plift.injective.inj_on _ /-- A more general version of `monoid_hom.map_finprod_mem` that requires `s ∩ mul_support f` and instead of `s` to be finite. -/ @[to_additive] lemma monoid_hom.map_finprod_mem' {f : α → M} (g : M →* N) (h₀ : (s ∩ mul_support f).finite) : g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, (g (f i)) := begin rw [g.map_finprod], { simp only [g.map_finprod_Prop] }, { simpa only [finprod_eq_mul_indicator_apply, mul_support_mul_indicator] } end /-- Given a monoid homomorphism `g : M →* N`, and a function `f : α → M`, the value of `g` at the product of `f i` over `i ∈ s` equals the product of `(g ∘ f) i` over `s`. -/ @[to_additive] lemma monoid_hom.map_finprod_mem (f : α → M) (g : M →* N) (hs : s.finite) : g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, g (f i) := g.map_finprod_mem' (hs.inter_of_left _) /-! ### `∏ᶠ x ∈ s, f x` and set operations -/ /-- The product of any function over an empty set is one. -/ @[to_additive] lemma finprod_mem_empty : ∏ᶠ i ∈ (∅ : set α), f i = 1 := by simp /-- A set `s` is not empty if the product of some function over `s` is not equal to one. -/ @[to_additive] lemma nonempty_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) : s.nonempty := ne_empty_iff_nonempty.1 $ λ h', h $ h'.symm ▸ finprod_mem_empty /-- Given finite sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` times the product of `f i` over `i ∈ s ∩ t` equals the product of `f i` over `i ∈ s` times the product of `f i` over `i ∈ t`. -/ @[to_additive] lemma finprod_mem_union_inter (hs : s.finite) (ht : t.finite) : (∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := begin unfreezingI { lift s to finset α using hs, lift t to finset α using ht }, classical, rw [← finset.coe_union, ← finset.coe_inter], simp only [finprod_mem_coe_finset, finset.prod_union_inter] end /-- A more general version of `finprod_mem_union_inter` that requires `s ∩ mul_support f` and `t ∩ mul_support f` instead of `s` and `t` to be finite. -/ @[to_additive] lemma finprod_mem_union_inter' (hs : (s ∩ mul_support f).finite) (ht : (t ∩ mul_support f).finite) : (∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := begin rw [← finprod_mem_inter_mul_support f s, ← finprod_mem_inter_mul_support f t, ← finprod_mem_union_inter hs ht, ← union_inter_distrib_right, finprod_mem_inter_mul_support, ← finprod_mem_inter_mul_support f (s ∩ t)], congr' 2, rw [inter_left_comm, inter_assoc, inter_assoc, inter_self, inter_left_comm] end /-- A more general version of `finprod_mem_union` that requires `s ∩ mul_support f` and `t ∩ mul_support f` instead of `s` and `t` to be finite. -/ @[to_additive] lemma finprod_mem_union' (hst : disjoint s t) (hs : (s ∩ mul_support f).finite) (ht : (t ∩ mul_support f).finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_union_inter' hs ht, disjoint_iff_inter_eq_empty.1 hst, finprod_mem_empty, mul_one] /-- Given two finite disjoint sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` equals the product of `f i` over `i ∈ s` times the product of `f i` over `i ∈ t`. -/ @[to_additive] lemma finprod_mem_union (hst : disjoint s t) (hs : s.finite) (ht : t.finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := finprod_mem_union' hst (hs.inter_of_left _) (ht.inter_of_left _) /-- A more general version of `finprod_mem_union'` that requires `s ∩ mul_support f` and `t ∩ mul_support f` instead of `s` and `t` to be disjoint -/ @[to_additive] lemma finprod_mem_union'' (hst : disjoint (s ∩ mul_support f) (t ∩ mul_support f)) (hs : (s ∩ mul_support f).finite) (ht : (t ∩ mul_support f).finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mul_support f s, ← finprod_mem_inter_mul_support f t, ← finprod_mem_union hst hs ht, ← union_inter_distrib_right, finprod_mem_inter_mul_support] /-- The product of `f i` over `i ∈ {a}` equals `f a`. -/ @[to_additive] lemma finprod_mem_singleton : ∏ᶠ i ∈ ({a} : set α), f i = f a := by rw [← finset.coe_singleton, finprod_mem_coe_finset, finset.prod_singleton] @[simp, to_additive] lemma finprod_cond_eq_left : ∏ᶠ i = a, f i = f a := finprod_mem_singleton @[simp, to_additive] lemma finprod_cond_eq_right : ∏ᶠ i (hi : a = i), f i = f a := by simp [@eq_comm _ a] /-- A more general version of `finprod_mem_insert` that requires `s ∩ mul_support f` instead of `s` to be finite. -/ @[to_additive] lemma finprod_mem_insert' (f : α → M) (h : a ∉ s) (hs : (s ∩ mul_support f).finite) : ∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i := begin rw [insert_eq, finprod_mem_union' _ _ hs, finprod_mem_singleton], { rwa disjoint_singleton_left }, { exact (finite_singleton a).inter_of_left _ } end /-- Given a finite set `s` and an element `a ∉ s`, the product of `f i` over `i ∈ insert a s` equals `f a` times the product of `f i` over `i ∈ s`. -/ @[to_additive] lemma finprod_mem_insert (f : α → M) (h : a ∉ s) (hs : s.finite) : ∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i := finprod_mem_insert' f h $ hs.inter_of_left _ /-- If `f a = 1` for all `a ∉ s`, then the product of `f i` over `i ∈ insert a s` equals the product of `f i` over `i ∈ s`. -/ @[to_additive] lemma finprod_mem_insert_of_eq_one_if_not_mem (h : a ∉ s → f a = 1) : ∏ᶠ i ∈ (insert a s), f i = ∏ᶠ i ∈ s, f i := begin refine finprod_mem_inter_mul_support_eq' _ _ _ (λ x hx, ⟨_, or.inr⟩), rintro (rfl|hxs), exacts [not_imp_comm.1 h hx, hxs] end /-- If `f a = 1`, then the product of `f i` over `i ∈ insert a s` equals the product of `f i` over `i ∈ s`. -/ @[to_additive] lemma finprod_mem_insert_one (h : f a = 1) : ∏ᶠ i ∈ (insert a s), f i = ∏ᶠ i ∈ s, f i := finprod_mem_insert_of_eq_one_if_not_mem (λ _, h) /-- The product of `f i` over `i ∈ {a, b}`, `a ≠ b`, is equal to `f a * f b`. -/ @[to_additive] lemma finprod_mem_pair (h : a ≠ b) : ∏ᶠ i ∈ ({a, b} : set α), f i = f a * f b := by { rw [finprod_mem_insert, finprod_mem_singleton], exacts [h, finite_singleton b] } /-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s` provided that `g` is injective on `s ∩ mul_support (f ∘ g)`. -/ @[to_additive] lemma finprod_mem_image' {s : set β} {g : β → α} (hg : set.inj_on g (s ∩ mul_support (f ∘ g))) : ∏ᶠ i ∈ (g '' s), f i = ∏ᶠ j ∈ s, f (g j) := begin classical, by_cases hs : finite (s ∩ mul_support (f ∘ g)), { have hg : ∀ (x ∈ hs.to_finset) (y ∈ hs.to_finset), g x = g y → x = y, by simpa only [hs.mem_to_finset], rw [finprod_mem_eq_prod _ hs, ← finset.prod_image hg], refine finprod_mem_eq_prod_of_inter_mul_support_eq f _, rw [finset.coe_image, hs.coe_to_finset, ← image_inter_mul_support_eq, inter_assoc, inter_self] }, { rw [finprod_mem_eq_one_of_infinite hs, finprod_mem_eq_one_of_infinite], rwa [image_inter_mul_support_eq, infinite_image_iff hg] } end /-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s` provided that `g` is injective on `s`. -/ @[to_additive] lemma finprod_mem_image {β} {s : set β} {g : β → α} (hg : set.inj_on g s) : ∏ᶠ i ∈ (g '' s), f i = ∏ᶠ j ∈ s, f (g j) := finprod_mem_image' $ hg.mono $ inter_subset_left _ _ /-- The product of `f y` over `y ∈ set.range g` equals the product of `f (g i)` over all `i` provided that `g` is injective on `mul_support (f ∘ g)`. -/ @[to_additive] lemma finprod_mem_range' {g : β → α} (hg : set.inj_on g (mul_support (f ∘ g))) : ∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) := begin rw [← image_univ, finprod_mem_image', finprod_mem_univ], rwa univ_inter end /-- The product of `f y` over `y ∈ set.range g` equals the product of `f (g i)` over all `i` provided that `g` is injective. -/ @[to_additive] lemma finprod_mem_range {g : β → α} (hg : injective g) : ∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) := finprod_mem_range' (hg.inj_on _) /-- The product of `f i` over `s : set α` is equal to the product of `g j` over `t : set β` if there exists a function `e : α → β` such that `e` is bijective from `s` to `t` and for all `x` in `s` we have `f x = g (e x)`. -/ @[to_additive] lemma finprod_mem_eq_of_bij_on {s : set α} {t : set β} {f : α → M} {g : β → M} (e : α → β) (he₀ : set.bij_on e s t) (he₁ : ∀ x ∈ s, f x = g (e x)) : ∏ᶠ i ∈ s, f i = ∏ᶠ j ∈ t, g j := begin rw [← set.bij_on.image_eq he₀, finprod_mem_image he₀.2.1], exact finprod_mem_congr rfl he₁ end @[to_additive] lemma finprod_set_coe_eq_finprod_mem (s : set α) : ∏ᶠ j : s, f j = ∏ᶠ i ∈ s, f i := begin rw [← finprod_mem_range, subtype.range_coe], exact subtype.coe_injective end @[to_additive] lemma finprod_subtype_eq_finprod_cond (p : α → Prop) : ∏ᶠ j : subtype p, f j = ∏ᶠ i (hi : p i), f i := finprod_set_coe_eq_finprod_mem {i | p i} @[to_additive] lemma finprod_mem_inter_mul_diff' (t : set α) (h : (s ∩ mul_support f).finite) : (∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i = ∏ᶠ i ∈ s, f i := begin rw [← finprod_mem_union', inter_union_diff], exacts [λ x hx, hx.2.2 hx.1.2, h.subset (λ x hx, ⟨hx.1.1, hx.2⟩), h.subset (λ x hx, ⟨hx.1.1, hx.2⟩)], end @[to_additive] lemma finprod_mem_inter_mul_diff (t : set α) (h : s.finite) : (∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i = ∏ᶠ i ∈ s, f i := finprod_mem_inter_mul_diff' _ $ h.inter_of_left _ /-- A more general version of `finprod_mem_mul_diff` that requires `t ∩ mul_support f` instead of `t` to be finite. -/ @[to_additive] lemma finprod_mem_mul_diff' (hst : s ⊆ t) (ht : (t ∩ mul_support f).finite) : (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i = ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mul_diff' _ ht, inter_eq_self_of_subset_right hst] /-- Given a finite set `t` and a subset `s` of `t`, the product of `f i` over `i ∈ s` times the product of `f i` over `t \ s` equals the product of `f i` over `i ∈ t`. -/ @[to_additive] lemma finprod_mem_mul_diff (hst : s ⊆ t) (ht : t.finite) : (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i = ∏ᶠ i ∈ t, f i := finprod_mem_mul_diff' hst (ht.inter_of_left _) /-- Given a family of pairwise disjoint finite sets `t i` indexed by a finite type, the product of `f a` over the union `⋃ i, t i` is equal to the product over all indexes `i` of the products of `f a` over `a ∈ t i`. -/ @[to_additive] lemma finprod_mem_Union [fintype ι] {t : ι → set α} (h : pairwise (disjoint on t)) (ht : ∀ i, (t i).finite) : ∏ᶠ a ∈ (⋃ i : ι, t i), f a = ∏ᶠ i, (∏ᶠ a ∈ t i, f a) := begin unfreezingI { lift t to ι → finset α using ht }, classical, rw [← bUnion_univ, ← finset.coe_univ, ← finset.coe_bUnion, finprod_mem_coe_finset, finset.prod_bUnion], { simp only [finprod_mem_coe_finset, finprod_eq_prod_of_fintype] }, { exact λ x _ y _ hxy, finset.disjoint_iff_disjoint_coe.2 (h x y hxy) } end /-- Given a family of sets `t : ι → set α`, a finite set `I` in the index type such that all sets `t i`, `i ∈ I`, are finite, if all `t i`, `i ∈ I`, are pairwise disjoint, then the product of `f a` over `a ∈ ⋃ i ∈ I, t i` is equal to the product over `i ∈ I` of the products of `f a` over `a ∈ t i`. -/ @[to_additive] lemma finprod_mem_bUnion {I : set ι} {t : ι → set α} (h : pairwise_on I (disjoint on t)) (hI : I.finite) (ht : ∀ i ∈ I, (t i).finite) : ∏ᶠ a ∈ ⋃ x ∈ I, t x, f a = ∏ᶠ i ∈ I, ∏ᶠ j ∈ t i, f j := begin haveI := hI.fintype, rw [← Union_subtype, finprod_mem_Union, ← finprod_set_coe_eq_finprod_mem], exacts [λ x y hxy, h x x.2 y y.2 (subtype.coe_injective.ne hxy), λ b, ht b b.2] end /-- If `t` is a finite set of pairwise disjoint finite sets, then the product of `f a` over `a ∈ ⋃₀ t` is the product over `s ∈ t` of the products of `f a` over `a ∈ s`. -/ @[to_additive] lemma finprod_mem_sUnion {t : set (set α)} (h : pairwise_on t disjoint) (ht₀ : t.finite) (ht₁ : ∀ x ∈ t, set.finite x): ∏ᶠ a ∈ ⋃₀ t, f a = ∏ᶠ s ∈ t, ∏ᶠ a ∈ s, f a := by rw [set.sUnion_eq_bUnion, finprod_mem_bUnion h ht₀ ht₁] /-- If `s : set α` and `t : set β` are finite sets, then the product over `s` commutes with the product over `t`. -/ @[to_additive] lemma finprod_mem_comm {s : set α} {t : set β} (f : α → β → M) (hs : s.finite) (ht : t.finite) : ∏ᶠ i ∈ s, ∏ᶠ j ∈ t, f i j = ∏ᶠ j ∈ t, ∏ᶠ i ∈ s, f i j := begin unfreezingI { lift s to finset α using hs, lift t to finset β using ht }, simp only [finprod_mem_coe_finset], exact finset.prod_comm end /-- To prove a property of a finite product, it suffices to prove that the property is multiplicative and holds on multipliers. -/ @[to_additive] lemma finprod_mem_induction (p : M → Prop) (hp₀ : p 1) (hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ x ∈ s, p $ f x) : p (∏ᶠ i ∈ s, f i) := begin by_cases hs : (s ∩ mul_support f).finite, { rw [finprod_mem_eq_prod _ hs], refine finset.prod_induction _ p hp₁ hp₀ (λ x hx, hp₂ x _), rw hs.mem_to_finset at hx, exact hx.1 }, { exact (finprod_mem_eq_one_of_infinite hs).symm ▸ hp₀ } end lemma finprod_cond_nonneg {R : Type*} [ordered_comm_semiring R] {p : α → Prop} {f : α → R} (hf : ∀ x, p x → 0 ≤ f x) : 0 ≤ ∏ᶠ x (h : p x), f x := finprod_nonneg $ λ x, finprod_nonneg $ hf x lemma finprod_eq_zero {M₀ : Type*} [comm_monoid_with_zero M₀] (f : α → M₀) (x : α) (hx : f x = 0) (hf : finite (mul_support f)) : ∏ᶠ x, f x = 0 := begin nontriviality, rw [finprod_eq_prod f hf], refine finset.prod_eq_zero (hf.mem_to_finset.2 _) hx, simp [hx] end @[to_additive] lemma finprod_prod_comm (s : finset β) (f : α → β → M) (h : ∀ b ∈ s, (mul_support (λ a, f a b)).finite) : ∏ᶠ a : α, ∏ b in s, f a b = ∏ b in s, ∏ᶠ a : α, f a b := begin have hU : mul_support (λ a, ∏ b in s, f a b) ⊆ (s.finite_to_set.bUnion (λ b hb, h b (finset.mem_coe.1 hb))).to_finset, { rw finite.coe_to_finset, intros x hx, simp only [exists_prop, mem_Union, ne.def, mem_mul_support, finset.mem_coe], contrapose! hx, rw [mem_mul_support, not_not, finset.prod_congr rfl hx, finset.prod_const_one] }, rw [finprod_eq_prod_of_mul_support_subset _ hU, finset.prod_comm], refine finset.prod_congr rfl (λ b hb, (finprod_eq_prod_of_mul_support_subset _ _).symm), intros a ha, simp only [finite.coe_to_finset, mem_Union], exact ⟨b, hb, ha⟩ end @[to_additive] lemma prod_finprod_comm (s : finset α) (f : α → β → M) (h : ∀ a ∈ s, (mul_support (f a)).finite) : ∏ a in s, ∏ᶠ b : β, f a b = ∏ᶠ b : β, ∏ a in s, f a b := (finprod_prod_comm s (λ b a, f a b) h).symm lemma mul_finsum {R : Type*} [semiring R] (f : α → R) (r : R) (h : (function.support f).finite) : r * ∑ᶠ a : α, f a = ∑ᶠ a : α, r * f a := (add_monoid_hom.mul_left r).map_finsum h lemma finsum_mul {R : Type*} [semiring R] (f : α → R) (r : R) (h : (function.support f).finite) : (∑ᶠ a : α, f a) * r = ∑ᶠ a : α, f a * r := (add_monoid_hom.mul_right r).map_finsum h @[to_additive] lemma finset.mul_support_of_fiberwise_prod_subset_image [decidable_eq β] (s : finset α) (f : α → M) (g : α → β) : mul_support (λ b, (s.filter (λ a, g a = b)).prod f) ⊆ s.image g := begin simp only [finset.coe_image, set.mem_image, finset.mem_coe, function.support_subset_iff], intros b h, suffices : (s.filter (λ (a : α), g a = b)).nonempty, { simpa only [s.fiber_nonempty_iff_mem_image g b, finset.mem_image, exists_prop], }, exact finset.nonempty_of_prod_ne_one h, end /-- Note that `b ∈ (s.filter (λ ab, prod.fst ab = a)).image prod.snd` iff `(a, b) ∈ s` so we can simplify the right hand side of this lemma. However the form stated here is more useful for iterating this lemma, e.g., if we have `f : α × β × γ → M`. -/ @[to_additive] lemma finprod_mem_finset_product' [decidable_eq α] [decidable_eq β] (s : finset (α × β)) (f : α × β → M) : ∏ᶠ ab (h : ab ∈ s), f ab = ∏ᶠ a b (h : b ∈ (s.filter (λ ab, prod.fst ab = a)).image prod.snd), f (a, b) := begin have : ∀ a, ∏ (i : β) in (s.filter (λ ab, prod.fst ab = a)).image prod.snd, f (a, i) = (finset.filter (λ ab, prod.fst ab = a) s).prod f, { intros a, apply finset.prod_bij (λ b _, (a, b)); finish, }, rw finprod_mem_finset_eq_prod, simp_rw [finprod_mem_finset_eq_prod, this], rw [finprod_eq_prod_of_mul_support_subset _ (s.mul_support_of_fiberwise_prod_subset_image f prod.fst), ← finset.prod_fiberwise_of_maps_to _ f], finish, end /-- See also `finprod_mem_finset_product'`. -/ @[to_additive] lemma finprod_mem_finset_product (s : finset (α × β)) (f : α × β → M) : ∏ᶠ ab (h : ab ∈ s), f ab = ∏ᶠ a b (h : (a, b) ∈ s), f (a, b) := by { classical, rw finprod_mem_finset_product', simp, } @[to_additive] lemma finprod_mem_finset_product₃ {γ : Type*} (s : finset (α × β × γ)) (f : α × β × γ → M) : ∏ᶠ abc (h : abc ∈ s), f abc = ∏ᶠ a b c (h : (a, b, c) ∈ s), f (a, b, c) := by { classical, rw finprod_mem_finset_product', simp_rw finprod_mem_finset_product', simp, } @[to_additive] lemma finprod_curry (f : α × β → M) (hf : (mul_support f).finite) : ∏ᶠ ab, f ab = ∏ᶠ a b, f (a, b) := begin have h₁ : ∀ a, ∏ᶠ (h : a ∈ hf.to_finset), f a = f a, { simp, }, have h₂ : ∏ᶠ a, f a = ∏ᶠ a (h : a ∈ hf.to_finset), f a, { simp, }, simp_rw [h₂, finprod_mem_finset_product, h₁], end @[to_additive] lemma finprod_curry₃ {γ : Type*} (f : α × β × γ → M) (h : (mul_support f).finite) : ∏ᶠ abc, f abc = ∏ᶠ a b c, f (a, b, c) := by { rw finprod_curry f h, congr, ext a, rw finprod_curry, simp [h], } @[to_additive] lemma finprod_dmem {s : set α} [decidable_pred (∈ s)] (f : (Π (a : α), a ∈ s → M)) : ∏ᶠ (a : α) (h : a ∈ s), f a h = ∏ᶠ (a : α) (h : a ∈ s), if h' : a ∈ s then f a h' else 1 := finprod_congr (λ a, finprod_congr (λ ha, (dif_pos ha).symm)) @[to_additive] lemma finprod_emb_domain' {f : α → β} (hf : function.injective f) [decidable_pred (∈ set.range f)] (g : α → M) : ∏ᶠ (b : β), (if h : b ∈ set.range f then g (classical.some h) else 1) = ∏ᶠ (a : α), g a := begin simp_rw [← finprod_eq_dif], rw [finprod_dmem, finprod_mem_range hf, finprod_congr (λ a, _)], rw [dif_pos (set.mem_range_self a), hf (classical.some_spec (set.mem_range_self a))] end @[to_additive] lemma finprod_emb_domain (f : α ↪ β) [decidable_pred (∈ set.range f)] (g : α → M) : ∏ᶠ (b : β), (if h : b ∈ set.range f then g (classical.some h) else 1) = ∏ᶠ (a : α), g a := finprod_emb_domain' f.injective g end type
fd141d97d88d4479a82ff3257330d9b1ccb3344f
2eab05920d6eeb06665e1a6df77b3157354316ad
/src/group_theory/free_group.lean
49bb030f01cbd46cc2d52eefe6a62bd28ed3adb3
[ "Apache-2.0" ]
permissive
ayush1801/mathlib
78949b9f789f488148142221606bf15c02b960d2
ce164e28f262acbb3de6281b3b03660a9f744e3c
refs/heads/master
1,692,886,907,941
1,635,270,866,000
1,635,270,866,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
32,613
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import data.fintype.basic import group_theory.subgroup.basic /-! # Free groups This file defines free groups over a type. Furthermore, it is shown that the free group construction is an instance of a monad. For the result that `free_group` is the left adjoint to the forgetful functor from groups to types, see `algebra/category/Group/adjunctions`. ## Main definitions * `free_group`: the free group associated to a type `α` defined as the words over `a : α × bool ` modulo the relation `a * x * x⁻¹ * b = a * b`. * `mk`: the canonical quotient map `list (α × bool) → free_group α`. * `of`: the canoical injection `α → free_group α`. * `lift f`: the canonical group homomorphism `free_group α →* G` given a group `G` and a function `f : α → G`. ## Main statements * `church_rosser`: The Church-Rosser theorem for word reduction (also known as Newman's diamond lemma). * `free_group_unit_equiv_int`: The free group over the one-point type is isomorphic to the integers. * The free group construction is an instance of a monad. ## Implementation details First we introduce the one step reduction relation `free_group.red.step`: `w * x * x⁻¹ * v ~> w * v`, its reflexive transitive closure `free_group.red.trans` and prove that its join is an equivalence relation. Then we introduce `free_group α` as a quotient over `free_group.red.step`. ## Tags free group, Newman's diamond lemma, Church-Rosser theorem -/ open relation universes u v w variables {α : Type u} local attribute [simp] list.append_eq_has_append namespace free_group variables {L L₁ L₂ L₃ L₄ : list (α × bool)} /-- Reduction step: `w * x * x⁻¹ * v ~> w * v` -/ inductive red.step : list (α × bool) → list (α × bool) → Prop | bnot {L₁ L₂ x b} : red.step (L₁ ++ (x, b) :: (x, bnot b) :: L₂) (L₁ ++ L₂) attribute [simp] red.step.bnot /-- Reflexive-transitive closure of red.step -/ def red : list (α × bool) → list (α × bool) → Prop := refl_trans_gen red.step @[refl] lemma red.refl : red L L := refl_trans_gen.refl @[trans] lemma red.trans : red L₁ L₂ → red L₂ L₃ → red L₁ L₃ := refl_trans_gen.trans namespace red /-- Predicate asserting that word `w₁` can be reduced to `w₂` in one step, i.e. there are words `w₃ w₄` and letter `x` such that `w₁ = w₃xx⁻¹w₄` and `w₂ = w₃w₄` -/ theorem step.length : ∀ {L₁ L₂ : list (α × bool)}, step L₁ L₂ → L₂.length + 2 = L₁.length | _ _ (@red.step.bnot _ L1 L2 x b) := by rw [list.length_append, list.length_append]; refl @[simp] lemma step.bnot_rev {x b} : step (L₁ ++ (x, bnot b) :: (x, b) :: L₂) (L₁ ++ L₂) := by cases b; from step.bnot @[simp] lemma step.cons_bnot {x b} : red.step ((x, b) :: (x, bnot b) :: L) L := @step.bnot _ [] _ _ _ @[simp] lemma step.cons_bnot_rev {x b} : red.step ((x, bnot b) :: (x, b) :: L) L := @red.step.bnot_rev _ [] _ _ _ theorem step.append_left : ∀ {L₁ L₂ L₃ : list (α × bool)}, step L₂ L₃ → step (L₁ ++ L₂) (L₁ ++ L₃) | _ _ _ red.step.bnot := by rw [← list.append_assoc, ← list.append_assoc]; constructor theorem step.cons {x} (H : red.step L₁ L₂) : red.step (x :: L₁) (x :: L₂) := @step.append_left _ [x] _ _ H theorem step.append_right : ∀ {L₁ L₂ L₃ : list (α × bool)}, step L₁ L₂ → step (L₁ ++ L₃) (L₂ ++ L₃) | _ _ _ red.step.bnot := by simp lemma not_step_nil : ¬ step [] L := begin generalize h' : [] = L', assume h, cases h with L₁ L₂, simp [list.nil_eq_append_iff] at h', contradiction end lemma step.cons_left_iff {a : α} {b : bool} : step ((a, b) :: L₁) L₂ ↔ (∃L, step L₁ L ∧ L₂ = (a, b) :: L) ∨ (L₁ = (a, bnot b)::L₂) := begin split, { generalize hL : ((a, b) :: L₁ : list _) = L, assume h, rcases h with ⟨_ | ⟨p, s'⟩, e, a', b'⟩, { simp at hL, simp [*] }, { simp at hL, rcases hL with ⟨rfl, rfl⟩, refine or.inl ⟨s' ++ e, step.bnot, _⟩, simp } }, { assume h, rcases h with ⟨L, h, rfl⟩ | rfl, { exact step.cons h }, { exact step.cons_bnot } } end lemma not_step_singleton : ∀ {p : α × bool}, ¬ step [p] L | (a, b) := by simp [step.cons_left_iff, not_step_nil] lemma step.cons_cons_iff : ∀{p : α × bool}, step (p :: L₁) (p :: L₂) ↔ step L₁ L₂ := by simp [step.cons_left_iff, iff_def, or_imp_distrib] {contextual := tt} lemma step.append_left_iff : ∀L, step (L ++ L₁) (L ++ L₂) ↔ step L₁ L₂ | [] := by simp | (p :: l) := by simp [step.append_left_iff l, step.cons_cons_iff] private theorem step.diamond_aux : ∀ {L₁ L₂ L₃ L₄ : list (α × bool)} {x1 b1 x2 b2}, L₁ ++ (x1, b1) :: (x1, bnot b1) :: L₂ = L₃ ++ (x2, b2) :: (x2, bnot b2) :: L₄ → L₁ ++ L₂ = L₃ ++ L₄ ∨ ∃ L₅, red.step (L₁ ++ L₂) L₅ ∧ red.step (L₃ ++ L₄) L₅ | [] _ [] _ _ _ _ _ H := by injections; subst_vars; simp | [] _ [(x3,b3)] _ _ _ _ _ H := by injections; subst_vars; simp | [(x3,b3)] _ [] _ _ _ _ _ H := by injections; subst_vars; simp | [] _ ((x3,b3)::(x4,b4)::tl) _ _ _ _ _ H := by injections; subst_vars; simp; right; exact ⟨_, red.step.bnot, red.step.cons_bnot⟩ | ((x3,b3)::(x4,b4)::tl) _ [] _ _ _ _ _ H := by injections; subst_vars; simp; right; exact ⟨_, red.step.cons_bnot, red.step.bnot⟩ | ((x3,b3)::tl) _ ((x4,b4)::tl2) _ _ _ _ _ H := let ⟨H1, H2⟩ := list.cons.inj H in match step.diamond_aux H2 with | or.inl H3 := or.inl $ by simp [H1, H3] | or.inr ⟨L₅, H3, H4⟩ := or.inr ⟨_, step.cons H3, by simpa [H1] using step.cons H4⟩ end theorem step.diamond : ∀ {L₁ L₂ L₃ L₄ : list (α × bool)}, red.step L₁ L₃ → red.step L₂ L₄ → L₁ = L₂ → L₃ = L₄ ∨ ∃ L₅, red.step L₃ L₅ ∧ red.step L₄ L₅ | _ _ _ _ red.step.bnot red.step.bnot H := step.diamond_aux H lemma step.to_red : step L₁ L₂ → red L₁ L₂ := refl_trans_gen.single /-- **Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4` respectively. This is also known as Newman's diamond lemma. -/ theorem church_rosser : red L₁ L₂ → red L₁ L₃ → join red L₂ L₃ := relation.church_rosser (assume a b c hab hac, match b, c, red.step.diamond hab hac rfl with | b, _, or.inl rfl := ⟨b, by refl, by refl⟩ | b, c, or.inr ⟨d, hbd, hcd⟩ := ⟨d, refl_gen.single hbd, hcd.to_red⟩ end) lemma cons_cons {p} : red L₁ L₂ → red (p :: L₁) (p :: L₂) := refl_trans_gen_lift (list.cons p) (assume a b, step.cons) lemma cons_cons_iff (p) : red (p :: L₁) (p :: L₂) ↔ red L₁ L₂ := iff.intro begin generalize eq₁ : (p :: L₁ : list _) = LL₁, generalize eq₂ : (p :: L₂ : list _) = LL₂, assume h, induction h using relation.refl_trans_gen.head_induction_on with L₁ L₂ h₁₂ h ih generalizing L₁ L₂, { subst_vars, cases eq₂, constructor }, { subst_vars, cases p with a b, rw [step.cons_left_iff] at h₁₂, rcases h₁₂ with ⟨L, h₁₂, rfl⟩ | rfl, { exact (ih rfl rfl).head h₁₂ }, { exact (cons_cons h).tail step.cons_bnot_rev } } end cons_cons lemma append_append_left_iff : ∀L, red (L ++ L₁) (L ++ L₂) ↔ red L₁ L₂ | [] := iff.rfl | (p :: L) := by simp [append_append_left_iff L, cons_cons_iff] lemma append_append (h₁ : red L₁ L₃) (h₂ : red L₂ L₄) : red (L₁ ++ L₂) (L₃ ++ L₄) := (refl_trans_gen_lift (λL, L ++ L₂) (assume a b, step.append_right) h₁).trans ((append_append_left_iff _).2 h₂) lemma to_append_iff : red L (L₁ ++ L₂) ↔ (∃L₃ L₄, L = L₃ ++ L₄ ∧ red L₃ L₁ ∧ red L₄ L₂) := iff.intro begin generalize eq : L₁ ++ L₂ = L₁₂, assume h, induction h with L' L₁₂ hLL' h ih generalizing L₁ L₂, { exact ⟨_, _, eq.symm, by refl, by refl⟩ }, { cases h with s e a b, rcases list.append_eq_append_iff.1 eq with ⟨s', rfl, rfl⟩ | ⟨e', rfl, rfl⟩, { have : L₁ ++ (s' ++ ((a, b) :: (a, bnot b) :: e)) = (L₁ ++ s') ++ ((a, b) :: (a, bnot b) :: e), { simp }, rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩, exact ⟨w₁, w₂, rfl, h₁, h₂.tail step.bnot⟩ }, { have : (s ++ ((a, b) :: (a, bnot b) :: e')) ++ L₂ = s ++ ((a, b) :: (a, bnot b) :: (e' ++ L₂)), { simp }, rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩, exact ⟨w₁, w₂, rfl, h₁.tail step.bnot, h₂⟩ }, } end (assume ⟨L₃, L₄, eq, h₃, h₄⟩, eq.symm ▸ append_append h₃ h₄) /-- The empty word `[]` only reduces to itself. -/ theorem nil_iff : red [] L ↔ L = [] := refl_trans_gen_iff_eq (assume l, red.not_step_nil) /-- A letter only reduces to itself. -/ theorem singleton_iff {x} : red [x] L₁ ↔ L₁ = [x] := refl_trans_gen_iff_eq (assume l, not_step_singleton) /-- If `x` is a letter and `w` is a word such that `xw` reduces to the empty word, then `w` reduces to `x⁻¹` -/ theorem cons_nil_iff_singleton {x b} : red ((x, b) :: L) [] ↔ red L [(x, bnot b)] := iff.intro (assume h, have h₁ : red ((x, bnot b) :: (x, b) :: L) [(x, bnot b)], from cons_cons h, have h₂ : red ((x, bnot b) :: (x, b) :: L) L, from refl_trans_gen.single step.cons_bnot_rev, let ⟨L', h₁, h₂⟩ := church_rosser h₁ h₂ in by rw [singleton_iff] at h₁; subst L'; assumption) (assume h, (cons_cons h).tail step.cons_bnot) theorem red_iff_irreducible {x1 b1 x2 b2} (h : (x1, b1) ≠ (x2, b2)) : red [(x1, bnot b1), (x2, b2)] L ↔ L = [(x1, bnot b1), (x2, b2)] := begin apply refl_trans_gen_iff_eq, generalize eq : [(x1, bnot b1), (x2, b2)] = L', assume L h', cases h', simp [list.cons_eq_append_iff, list.nil_eq_append_iff] at eq, rcases eq with ⟨rfl, ⟨rfl, rfl⟩, ⟨rfl, rfl⟩, rfl⟩, subst_vars, simp at h, contradiction end /-- If `x` and `y` are distinct letters and `w₁ w₂` are words such that `xw₁` reduces to `yw₂`, then `w₁` reduces to `x⁻¹yw₂`. -/ theorem inv_of_red_of_ne {x1 b1 x2 b2} (H1 : (x1, b1) ≠ (x2, b2)) (H2 : red ((x1, b1) :: L₁) ((x2, b2) :: L₂)) : red L₁ ((x1, bnot b1) :: (x2, b2) :: L₂) := begin have : red ((x1, b1) :: L₁) ([(x2, b2)] ++ L₂), from H2, rcases to_append_iff.1 this with ⟨_ | ⟨p, L₃⟩, L₄, eq, h₁, h₂⟩, { simp [nil_iff] at h₁, contradiction }, { cases eq, show red (L₃ ++ L₄) ([(x1, bnot b1), (x2, b2)] ++ L₂), apply append_append _ h₂, have h₁ : red ((x1, bnot b1) :: (x1, b1) :: L₃) [(x1, bnot b1), (x2, b2)], { exact cons_cons h₁ }, have h₂ : red ((x1, bnot b1) :: (x1, b1) :: L₃) L₃, { exact step.cons_bnot_rev.to_red }, rcases church_rosser h₁ h₂ with ⟨L', h₁, h₂⟩, rw [red_iff_irreducible H1] at h₁, rwa [h₁] at h₂ } end theorem step.sublist (H : red.step L₁ L₂) : L₂ <+ L₁ := by cases H; simp; constructor; constructor; refl /-- If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of `w₁`. -/ theorem sublist : red L₁ L₂ → L₂ <+ L₁ := refl_trans_gen_of_transitive_reflexive (λl, list.sublist.refl l) (λa b c hab hbc, list.sublist.trans hbc hab) (λa b, red.step.sublist) theorem sizeof_of_step : ∀ {L₁ L₂ : list (α × bool)}, step L₁ L₂ → L₂.sizeof < L₁.sizeof | _ _ (@step.bnot _ L1 L2 x b) := begin induction L1 with hd tl ih, case list.nil { dsimp [list.sizeof], have H : 1 + sizeof (x, b) + (1 + sizeof (x, bnot b) + list.sizeof L2) = (list.sizeof L2 + 1) + (sizeof (x, b) + sizeof (x, bnot b) + 1), { ac_refl }, rw H, exact nat.le_add_right _ _ }, case list.cons { dsimp [list.sizeof], exact nat.add_lt_add_left ih _ } end theorem length (h : red L₁ L₂) : ∃ n, L₁.length = L₂.length + 2 * n := begin induction h with L₂ L₃ h₁₂ h₂₃ ih, { exact ⟨0, rfl⟩ }, { rcases ih with ⟨n, eq⟩, existsi (1 + n), simp [mul_add, eq, (step.length h₂₃).symm, add_assoc] } end theorem antisymm (h₁₂ : red L₁ L₂) : red L₂ L₁ → L₁ = L₂ := match L₁, h₁₂.cases_head with | _, or.inl rfl := assume h, rfl | L₁, or.inr ⟨L₃, h₁₃, h₃₂⟩ := assume h₂₁, let ⟨n, eq⟩ := length (h₃₂.trans h₂₁) in have list.length L₃ + 0 = list.length L₃ + (2 * n + 2), by simpa [(step.length h₁₃).symm, add_comm, add_assoc] using eq, (nat.no_confusion $ nat.add_left_cancel this) end end red theorem equivalence_join_red : equivalence (join (@red α)) := equivalence_join_refl_trans_gen $ assume a b c hab hac, (match b, c, red.step.diamond hab hac rfl with | b, _, or.inl rfl := ⟨b, by refl, by refl⟩ | b, c, or.inr ⟨d, hbd, hcd⟩ := ⟨d, refl_gen.single hbd, refl_trans_gen.single hcd⟩ end) theorem join_red_of_step (h : red.step L₁ L₂) : join red L₁ L₂ := join_of_single reflexive_refl_trans_gen h.to_red theorem eqv_gen_step_iff_join_red : eqv_gen red.step L₁ L₂ ↔ join red L₁ L₂ := iff.intro (assume h, have eqv_gen (join red) L₁ L₂ := eqv_gen_mono (assume a b, join_red_of_step) h, (eqv_gen_iff_of_equivalence $ equivalence_join_red).1 this) (join_of_equivalence (eqv_gen.is_equivalence _) $ assume a b, refl_trans_gen_of_equivalence (eqv_gen.is_equivalence _) eqv_gen.rel) end free_group /-- The free group over a type, i.e. the words formed by the elements of the type and their formal inverses, quotient by one step reduction. -/ def free_group (α : Type u) : Type u := quot $ @free_group.red.step α namespace free_group variables {α} {L L₁ L₂ L₃ L₄ : list (α × bool)} /-- The canonical map from `list (α × bool)` to the free group on `α`. -/ def mk (L) : free_group α := quot.mk red.step L @[simp] lemma quot_mk_eq_mk : quot.mk red.step L = mk L := rfl @[simp] lemma quot_lift_mk (β : Type v) (f : list (α × bool) → β) (H : ∀ L₁ L₂, red.step L₁ L₂ → f L₁ = f L₂) : quot.lift f H (mk L) = f L := rfl @[simp] lemma quot_lift_on_mk (β : Type v) (f : list (α × bool) → β) (H : ∀ L₁ L₂, red.step L₁ L₂ → f L₁ = f L₂) : quot.lift_on (mk L) f H = f L := rfl instance : has_one (free_group α) := ⟨mk []⟩ lemma one_eq_mk : (1 : free_group α) = mk [] := rfl instance : inhabited (free_group α) := ⟨1⟩ instance : has_mul (free_group α) := ⟨λ x y, quot.lift_on x (λ L₁, quot.lift_on y (λ L₂, mk $ L₁ ++ L₂) (λ L₂ L₃ H, quot.sound $ red.step.append_left H)) (λ L₁ L₂ H, quot.induction_on y $ λ L₃, quot.sound $ red.step.append_right H)⟩ @[simp] lemma mul_mk : mk L₁ * mk L₂ = mk (L₁ ++ L₂) := rfl instance : has_inv (free_group α) := ⟨λx, quot.lift_on x (λ L, mk (L.map $ λ x : α × bool, (x.1, bnot x.2)).reverse) (assume a b h, quot.sound $ by cases h; simp)⟩ @[simp] lemma inv_mk : (mk L)⁻¹ = mk (L.map $ λ x : α × bool, (x.1, bnot x.2)).reverse := rfl instance : group (free_group α) := { mul := (*), one := 1, inv := has_inv.inv, mul_assoc := by rintros ⟨L₁⟩ ⟨L₂⟩ ⟨L₃⟩; simp, one_mul := by rintros ⟨L⟩; refl, mul_one := by rintros ⟨L⟩; simp [one_eq_mk], mul_left_inv := by rintros ⟨L⟩; exact (list.rec_on L rfl $ λ ⟨x, b⟩ tl ih, eq.trans (quot.sound $ by simp [one_eq_mk]) ih) } /-- `of` is the canonical injection from the type to the free group over that type by sending each element to the equivalence class of the letter that is the element. -/ def of (x : α) : free_group α := mk [(x, tt)] theorem red.exact : mk L₁ = mk L₂ ↔ join red L₁ L₂ := calc (mk L₁ = mk L₂) ↔ eqv_gen red.step L₁ L₂ : iff.intro (quot.exact _) quot.eqv_gen_sound ... ↔ join red L₁ L₂ : eqv_gen_step_iff_join_red /-- The canonical injection from the type to the free group is an injection. -/ theorem of_injective : function.injective (@of α) := λ _ _ H, let ⟨L₁, hx, hy⟩ := red.exact.1 H in by simp [red.singleton_iff] at hx hy; cc section lift variables {β : Type v} [group β] (f : α → β) {x y : free_group α} /-- Given `f : α → β` with `β` a group, the canonical map `list (α × bool) → β` -/ def lift.aux : list (α × bool) → β := λ L, list.prod $ L.map $ λ x, cond x.2 (f x.1) (f x.1)⁻¹ theorem red.step.lift {f : α → β} (H : red.step L₁ L₂) : lift.aux f L₁ = lift.aux f L₂ := by cases H with _ _ _ b; cases b; simp [lift.aux] /-- If `β` is a group, then any function from `α` to `β` extends uniquely to a group homomorphism from the free group over `α` to `β` -/ @[simps symm_apply] def lift : (α → β) ≃ (free_group α →* β) := { to_fun := λ f, monoid_hom.mk' (quot.lift (lift.aux f) $ λ L₁ L₂, red.step.lift) $ begin rintros ⟨L₁⟩ ⟨L₂⟩, simp [lift.aux], end, inv_fun := λ g, g ∘ of, left_inv := λ f, one_mul _, right_inv := λ g, monoid_hom.ext $ begin rintros ⟨L⟩, apply list.rec_on L, { exact g.map_one.symm, }, { rintros ⟨x, _ | _⟩ t (ih : _ = g (mk t)), { show _ = g ((of x)⁻¹ * mk t), simpa [lift.aux] using ih }, { show _ = g (of x * mk t), simpa [lift.aux] using ih }, }, end } variable {f} @[simp] lemma lift.mk : lift f (mk L) = list.prod (L.map $ λ x, cond x.2 (f x.1) (f x.1)⁻¹) := rfl @[simp] lemma lift.of {x} : lift f (of x) = f x := one_mul _ theorem lift.unique (g : free_group α →* β) (hg : ∀ x, g (of x) = f x) : ∀{x}, g x = lift f x := monoid_hom.congr_fun $ (lift.symm_apply_eq).mp (funext hg : g ∘ of = f) /-- Two homomorphisms out of a free group are equal if they are equal on generators. See note [partially-applied ext lemmas]. -/ @[ext] lemma ext_hom {G : Type*} [group G] (f g : free_group α →* G) (h : ∀ a, f (of a) = g (of a)) : f = g := lift.symm.injective $ funext h theorem lift.of_eq (x : free_group α) : lift of x = x := monoid_hom.congr_fun (lift.apply_symm_apply (monoid_hom.id _)) x theorem lift.range_subset {s : subgroup β} (H : set.range f ⊆ s) : set.range (lift f) ⊆ s := by rintros _ ⟨⟨L⟩, rfl⟩; exact list.rec_on L s.one_mem (λ ⟨x, b⟩ tl ih, bool.rec_on b (by simp at ih ⊢; from s.mul_mem (s.inv_mem $ H ⟨x, rfl⟩) ih) (by simp at ih ⊢; from s.mul_mem (H ⟨x, rfl⟩) ih)) theorem closure_subset {G : Type*} [group G] {s : set G} {t : subgroup G} (h : s ⊆ t) : subgroup.closure s ≤ t := begin simp only [h, subgroup.closure_le], end theorem lift.range_eq_closure : set.range (lift f) = subgroup.closure (set.range f) := set.subset.antisymm (lift.range_subset subgroup.subset_closure) begin suffices : (subgroup.closure (set.range f)) ≤ monoid_hom.range (lift f), simpa, rw subgroup.closure_le, rintros y ⟨x, hx⟩, exact ⟨of x, by simpa⟩ end end lift section map variables {β : Type v} (f : α → β) {x y : free_group α} /-- Given `f : α → β`, the canonical map `list (α × bool) → list (β × bool)`. -/ def map.aux (L : list (α × bool)) : list (β × bool) := L.map $ λ x, (f x.1, x.2) /-- Any function from `α` to `β` extends uniquely to a group homomorphism from the free group over `α` to the free group over `β`. Note that this is the bare function; for the group homomorphism use `map`. -/ def map.to_fun (x : free_group α) : free_group β := x.lift_on (λ L, mk $ map.aux f L) $ λ L₁ L₂ H, quot.sound $ by cases H; simp [map.aux] /-- Any function from `α` to `β` extends uniquely to a group homomorphism from the free group ver `α` to the free group over `β`. -/ def map : free_group α →* free_group β := monoid_hom.mk' (map.to_fun f) begin rintros ⟨L₁⟩ ⟨L₂⟩, simp [map.to_fun, map.aux] end --by rintros ⟨L₁⟩ ⟨L₂⟩; simp [map, map.aux] variable {f} @[simp] lemma map.mk : map f (mk L) = mk (L.map (λ x, (f x.1, x.2))) := rfl @[simp] lemma map.id : map id x = x := have H1 : (λ (x : α × bool), x) = id := rfl, by rcases x with ⟨L⟩; simp [H1] @[simp] lemma map.id' : map (λ z, z) x = x := map.id theorem map.comp {γ : Type w} {f : α → β} {g : β → γ} {x} : map g (map f x) = map (g ∘ f) x := by rcases x with ⟨L⟩; simp @[simp] lemma map.of {x} : map f (of x) = of (f x) := rfl theorem map.unique (g : free_group α →* free_group β) (hg : ∀ x, g (of x) = of (f x)) : ∀{x}, g x = map f x := by rintros ⟨L⟩; exact list.rec_on L g.map_one (λ ⟨x, b⟩ t (ih : g (mk t) = map f (mk t)), bool.rec_on b (show g ((of x)⁻¹ * mk t) = map f ((of x)⁻¹ * mk t), by simp [g.map_mul, g.map_inv, hg, ih]) (show g (of x * mk t) = map f (of x * mk t), by simp [g.map_mul, hg, ih])) /-- Equivalent types give rise to equivalent free groups. -/ def free_group_congr {α β} (e : α ≃ β) : free_group α ≃ free_group β := ⟨map e, map e.symm, λ x, by simp [function.comp, map.comp], λ x, by simp [function.comp, map.comp]⟩ theorem map_eq_lift : map f x = lift (of ∘ f) x := eq.symm $ map.unique _ $ λ x, by simp end map section prod variables [group α] (x y : free_group α) /-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the free group over `α` to `α`. This is the multiplicative version of `sum`. -/ def prod : free_group α →* α := lift id variables {x y} @[simp] lemma prod_mk : prod (mk L) = list.prod (L.map $ λ x, cond x.2 x.1 x.1⁻¹) := rfl @[simp] lemma prod.of {x : α} : prod (of x) = x := lift.of lemma prod.unique (g : free_group α →* α) (hg : ∀ x, g (of x) = x) {x} : g x = prod x := lift.unique g hg end prod theorem lift_eq_prod_map {β : Type v} [group β] {f : α → β} {x} : lift f x = prod (map f x) := begin rw ←lift.unique (prod.comp (map f)), { refl }, { simp } end section sum variables [add_group α] (x y : free_group α) /-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the free group over `α` to `α`. This is the additive version of `prod`. -/ def sum : α := @prod (multiplicative _) _ x variables {x y} @[simp] lemma sum_mk : sum (mk L) = list.sum (L.map $ λ x, cond x.2 x.1 (-x.1)) := rfl @[simp] lemma sum.of {x : α} : sum (of x) = x := prod.of -- note: there are no bundled homs with different notation in the domain and codomain, so we copy -- these manually @[simp] lemma sum.map_mul : sum (x * y) = sum x + sum y := (@prod (multiplicative _) _).map_mul _ _ @[simp] lemma sum.map_one : sum (1:free_group α) = 0 := (@prod (multiplicative _) _).map_one @[simp] lemma sum.map_inv : sum x⁻¹ = -sum x := (@prod (multiplicative _) _).map_inv _ end sum /-- The bijection between the free group on the empty type, and a type with one element. -/ def free_group_empty_equiv_unit : free_group empty ≃ unit := { to_fun := λ _, (), inv_fun := λ _, 1, left_inv := by rintros ⟨_ | ⟨⟨⟨⟩, _⟩, _⟩⟩; refl, right_inv := λ ⟨⟩, rfl } /-- The bijection between the free group on a singleton, and the integers. -/ def free_group_unit_equiv_int : free_group unit ≃ ℤ := { to_fun := λ x, sum begin revert x, apply monoid_hom.to_fun, apply map (λ _, (1 : ℤ)), end, inv_fun := λ x, of () ^ x, left_inv := begin rintros ⟨L⟩, refine list.rec_on L rfl _, exact (λ ⟨⟨⟩, b⟩ tl ih, by cases b; simp [gpow_add] at ih ⊢; rw ih; refl), end, right_inv := λ x, int.induction_on x (by simp) (λ i ih, by simp at ih; simp [gpow_add, ih]) (λ i ih, by simp at ih; simp [gpow_add, ih, sub_eq_add_neg, -int.add_neg_one]) } section category variables {β : Type u} instance : monad free_group.{u} := { pure := λ α, of, map := λ α β f, (map f), bind := λ α β x f, lift f x } @[elab_as_eliminator] protected theorem induction_on {C : free_group α → Prop} (z : free_group α) (C1 : C 1) (Cp : ∀ x, C $ pure x) (Ci : ∀ x, C (pure x) → C (pure x)⁻¹) (Cm : ∀ x y, C x → C y → C (x * y)) : C z := quot.induction_on z $ λ L, list.rec_on L C1 $ λ ⟨x, b⟩ tl ih, bool.rec_on b (Cm _ _ (Ci _ $ Cp x) ih) (Cm _ _ (Cp x) ih) @[simp] lemma map_pure (f : α → β) (x : α) : f <$> (pure x : free_group α) = pure (f x) := map.of @[simp] lemma map_one (f : α → β) : f <$> (1 : free_group α) = 1 := (map f).map_one @[simp] lemma map_mul (f : α → β) (x y : free_group α) : f <$> (x * y) = f <$> x * f <$> y := (map f).map_mul x y @[simp] lemma map_inv (f : α → β) (x : free_group α) : f <$> (x⁻¹) = (f <$> x)⁻¹ := (map f).map_inv x @[simp] lemma pure_bind (f : α → free_group β) (x) : pure x >>= f = f x := lift.of @[simp] lemma one_bind (f : α → free_group β) : 1 >>= f = 1 := (lift f).map_one @[simp] lemma mul_bind (f : α → free_group β) (x y : free_group α) : x * y >>= f = (x >>= f) * (y >>= f) := (lift f).map_mul _ _ @[simp] lemma inv_bind (f : α → free_group β) (x : free_group α) : x⁻¹ >>= f = (x >>= f)⁻¹ := (lift f).map_inv _ instance : is_lawful_monad free_group.{u} := { id_map := λ α x, free_group.induction_on x (map_one id) (λ x, map_pure id x) (λ x ih, by rw [map_inv, ih]) (λ x y ihx ihy, by rw [map_mul, ihx, ihy]), pure_bind := λ α β x f, pure_bind f x, bind_assoc := λ α β γ x f g, free_group.induction_on x (by iterate 3 { rw one_bind }) (λ x, by iterate 2 { rw pure_bind }) (λ x ih, by iterate 3 { rw inv_bind }; rw ih) (λ x y ihx ihy, by iterate 3 { rw mul_bind }; rw [ihx, ihy]), bind_pure_comp_eq_map := λ α β f x, free_group.induction_on x (by rw [one_bind, map_one]) (λ x, by rw [pure_bind, map_pure]) (λ x ih, by rw [inv_bind, map_inv, ih]) (λ x y ihx ihy, by rw [mul_bind, map_mul, ihx, ihy]) } end category section reduce variable [decidable_eq α] /-- The maximal reduction of a word. It is computable iff `α` has decidable equality. -/ def reduce (L : list (α × bool)) : list (α × bool) := list.rec_on L [] $ λ hd1 tl1 ih, list.cases_on ih [hd1] $ λ hd2 tl2, if hd1.1 = hd2.1 ∧ hd1.2 = bnot hd2.2 then tl2 else hd1 :: hd2 :: tl2 @[simp] lemma reduce.cons (x) : reduce (x :: L) = list.cases_on (reduce L) [x] (λ hd tl, if x.1 = hd.1 ∧ x.2 = bnot hd.2 then tl else x :: hd :: tl) := rfl /-- The first theorem that characterises the function `reduce`: a word reduces to its maximal reduction. -/ theorem reduce.red : red L (reduce L) := begin induction L with hd1 tl1 ih, case list.nil { constructor }, case list.cons { dsimp, revert ih, generalize htl : reduce tl1 = TL, intro ih, cases TL with hd2 tl2, case list.nil { exact red.cons_cons ih }, case list.cons { dsimp, by_cases h : hd1.fst = hd2.fst ∧ hd1.snd = bnot (hd2.snd), { rw [if_pos h], transitivity, { exact red.cons_cons ih }, { cases hd1, cases hd2, cases h, dsimp at *, subst_vars, exact red.step.cons_bnot_rev.to_red } }, { rw [if_neg h], exact red.cons_cons ih } } } end theorem reduce.not {p : Prop} : ∀ {L₁ L₂ L₃ : list (α × bool)} {x b}, reduce L₁ = L₂ ++ (x, b) :: (x, bnot b) :: L₃ → p | [] L2 L3 _ _ := λ h, by cases L2; injections | ((x,b)::L1) L2 L3 x' b' := begin dsimp, cases r : reduce L1, { dsimp, intro h, have := congr_arg list.length h, simp [-add_comm] at this, exact absurd this dec_trivial }, cases hd with y c, by_cases x = y ∧ b = bnot c; simp [h]; intro H, { rw H at r, exact @reduce.not L1 ((y,c)::L2) L3 x' b' r }, rcases L2 with _|⟨a, L2⟩, { injections, subst_vars, simp at h, cc }, { refine @reduce.not L1 L2 L3 x' b' _, injection H with _ H, rw [r, H], refl } end /-- The second theorem that characterises the function `reduce`: the maximal reduction of a word only reduces to itself. -/ theorem reduce.min (H : red (reduce L₁) L₂) : reduce L₁ = L₂ := begin induction H with L1 L' L2 H1 H2 ih, { refl }, { cases H1 with L4 L5 x b, exact reduce.not H2 } end /-- `reduce` is idempotent, i.e. the maximal reduction of the maximal reduction of a word is the maximal reduction of the word. -/ theorem reduce.idem : reduce (reduce L) = reduce L := eq.symm $ reduce.min reduce.red theorem reduce.step.eq (H : red.step L₁ L₂) : reduce L₁ = reduce L₂ := let ⟨L₃, HR13, HR23⟩ := red.church_rosser reduce.red (reduce.red.head H) in (reduce.min HR13).trans (reduce.min HR23).symm /-- If a word reduces to another word, then they have a common maximal reduction. -/ theorem reduce.eq_of_red (H : red L₁ L₂) : reduce L₁ = reduce L₂ := let ⟨L₃, HR13, HR23⟩ := red.church_rosser reduce.red (red.trans H reduce.red) in (reduce.min HR13).trans (reduce.min HR23).symm /-- If two words correspond to the same element in the free group, then they have a common maximal reduction. This is the proof that the function that sends an element of the free group to its maximal reduction is well-defined. -/ theorem reduce.sound (H : mk L₁ = mk L₂) : reduce L₁ = reduce L₂ := let ⟨L₃, H13, H23⟩ := red.exact.1 H in (reduce.eq_of_red H13).trans (reduce.eq_of_red H23).symm /-- If two words have a common maximal reduction, then they correspond to the same element in the free group. -/ theorem reduce.exact (H : reduce L₁ = reduce L₂) : mk L₁ = mk L₂ := red.exact.2 ⟨reduce L₂, H ▸ reduce.red, reduce.red⟩ /-- A word and its maximal reduction correspond to the same element of the free group. -/ theorem reduce.self : mk (reduce L) = mk L := reduce.exact reduce.idem /-- If words `w₁ w₂` are such that `w₁` reduces to `w₂`, then `w₂` reduces to the maximal reduction of `w₁`. -/ theorem reduce.rev (H : red L₁ L₂) : red L₂ (reduce L₁) := (reduce.eq_of_red H).symm ▸ reduce.red /-- The function that sends an element of the free group to its maximal reduction. -/ def to_word : free_group α → list (α × bool) := quot.lift reduce $ λ L₁ L₂ H, reduce.step.eq H lemma to_word.mk : ∀{x : free_group α}, mk (to_word x) = x := by rintros ⟨L⟩; exact reduce.self lemma to_word.inj : ∀(x y : free_group α), to_word x = to_word y → x = y := by rintros ⟨L₁⟩ ⟨L₂⟩; exact reduce.exact /-- Constructive Church-Rosser theorem (compare `church_rosser`). -/ def reduce.church_rosser (H12 : red L₁ L₂) (H13 : red L₁ L₃) : { L₄ // red L₂ L₄ ∧ red L₃ L₄ } := ⟨reduce L₁, reduce.rev H12, reduce.rev H13⟩ instance : decidable_eq (free_group α) := function.injective.decidable_eq to_word.inj instance red.decidable_rel : decidable_rel (@red α) | [] [] := is_true red.refl | [] (hd2::tl2) := is_false $ λ H, list.no_confusion (red.nil_iff.1 H) | ((x,b)::tl) [] := match red.decidable_rel tl [(x, bnot b)] with | is_true H := is_true $ red.trans (red.cons_cons H) $ (@red.step.bnot _ [] [] _ _).to_red | is_false H := is_false $ λ H2, H $ red.cons_nil_iff_singleton.1 H2 end | ((x1,b1)::tl1) ((x2,b2)::tl2) := if h : (x1, b1) = (x2, b2) then match red.decidable_rel tl1 tl2 with | is_true H := is_true $ h ▸ red.cons_cons H | is_false H := is_false $ λ H2, H $ h ▸ (red.cons_cons_iff _).1 $ H2 end else match red.decidable_rel tl1 ((x1,bnot b1)::(x2,b2)::tl2) with | is_true H := is_true $ (red.cons_cons H).tail red.step.cons_bnot | is_false H := is_false $ λ H2, H $ red.inv_of_red_of_ne h H2 end /-- A list containing every word that `w₁` reduces to. -/ def red.enum (L₁ : list (α × bool)) : list (list (α × bool)) := list.filter (λ L₂, red L₁ L₂) (list.sublists L₁) theorem red.enum.sound (H : L₂ ∈ red.enum L₁) : red L₁ L₂ := list.of_mem_filter H theorem red.enum.complete (H : red L₁ L₂) : L₂ ∈ red.enum L₁ := list.mem_filter_of_mem (list.mem_sublists.2 $ red.sublist H) H instance : fintype { L₂ // red L₁ L₂ } := fintype.subtype (list.to_finset $ red.enum L₁) $ λ L₂, ⟨λ H, red.enum.sound $ list.mem_to_finset.1 H, λ H, list.mem_to_finset.2 $ red.enum.complete H⟩ end reduce end free_group
881cb6f16d1756f64d360c52783e8a81995d0f94
54deab7025df5d2df4573383df7e1e5497b7a2c2
/topology/continuity.lean
5f0d6e5699b3b6ebfad5cf91e7a27475c5e927e7
[ "Apache-2.0" ]
permissive
HGldJ1966/mathlib
f8daac93a5b4ae805cfb0ecebac21a9ce9469009
c5c5b504b918a6c5e91e372ee29ed754b0513e85
refs/heads/master
1,611,340,395,683
1,503,040,489,000
1,503,040,489,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
32,860
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 Continuous functions. Parts of the formalization is based on the books: N. Bourbaki: General Topology I. M. James: Topologies and Uniformities A major difference is that this formalization is heavily based on the filter library. -/ import topology.topological_space noncomputable theory open set filter lattice universes u v w x y variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type y} {ι : Sort x} lemma image_preimage_eq_inter_rng {f : α → β} {t : set β} : f '' preimage f t = t ∩ f '' univ := set.ext $ assume x, ⟨assume ⟨x, hx, heq⟩, heq ▸ ⟨hx, mem_image_of_mem f trivial⟩, assume ⟨hx, ⟨y, hy, h_eq⟩⟩, h_eq ▸ mem_image_of_mem f $ show y ∈ preimage f t, by simp [preimage, h_eq, hx]⟩ lemma subtype.val_image {p : α → Prop} {s : set (subtype p)} : subtype.val '' s = {x | ∃h : p x, (⟨x, h⟩ : subtype p) ∈ s} := set.ext $ assume a, ⟨assume ⟨⟨a', ha'⟩, in_s, (h_eq : a' = a)⟩, h_eq ▸ ⟨ha', in_s⟩, assume ⟨ha, in_s⟩, ⟨⟨a, ha⟩, in_s, rfl⟩⟩ @[simp] lemma univ_prod_univ : set.prod univ univ = (univ : set (α×β)) := set.ext $ assume ⟨a, b⟩, by simp section variables [topological_space α] [topological_space β] [topological_space γ] def continuous (f : α → β) := ∀s, is_open s → is_open (preimage f s) lemma continuous_id : continuous (id : α → α) := assume s h, h lemma continuous_compose {f : α → β} {g : β → γ} (hf : continuous f) (hg : continuous g): continuous (g ∘ f) := assume s h, hf _ (hg s h) lemma continuous_iff_tendsto {f : α → β} : continuous f ↔ (∀x, tendsto f (nhds x) (nhds (f x))) := ⟨assume hf : continuous f, assume x s, show s ∈ (nhds (f x)).sets → s ∈ (map f (nhds x)).sets, by simp [nhds_sets]; exact assume ⟨t, t_open, t_subset, fx_in_t⟩, ⟨preimage f t, hf t t_open, fx_in_t, preimage_mono t_subset⟩, assume hf : ∀x, tendsto f (nhds x) (nhds (f x)), assume s, assume hs : is_open s, have ∀a, f a ∈ s → s ∈ (nhds (f a)).sets, by simp [nhds_sets]; exact assume a ha, ⟨s, hs, subset.refl s, ha⟩, show is_open (preimage f s), by simp [is_open_iff_nhds]; exact assume a ha, hf a (this a ha)⟩ lemma continuous_const [topological_space α] [topological_space β] {b : β} : continuous (λa:α, b) := continuous_iff_tendsto.mpr $ assume a, tendsto_const_nhds lemma continuous_iff_is_closed {f : α → β} : continuous f ↔ (∀s, is_closed s → is_closed (preimage f s)) := ⟨assume hf s hs, hf (-s) hs, assume hf s, by rw [←is_closed_compl_iff, ←is_closed_compl_iff]; exact hf _⟩ lemma image_closure_subset_closure_image {f : α → β} {s : set α} (h : continuous f) : f '' closure s ⊆ closure (f '' s) := have ∀ (a : α), nhds a ⊓ principal s ≠ ⊥ → nhds (f a) ⊓ principal (f '' s) ≠ ⊥, from assume a ha, have h₁ : ¬ map f (nhds a ⊓ principal s) = ⊥, by rwa[map_eq_bot_iff], have h₂ : map f (nhds a ⊓ principal s) ≤ nhds (f a) ⊓ principal (f '' s), from le_inf (le_trans (map_mono inf_le_left) $ by rw [continuous_iff_tendsto] at h; exact h a) (le_trans (map_mono inf_le_right) $ by simp; exact subset.refl _), neq_bot_of_le_neq_bot h₁ h₂, by simp [image_subset_iff_subset_preimage, closure_eq_nhds]; assumption lemma compact_image {s : set α} {f : α → β} (hs : compact s) (hf : continuous f) : compact (f '' s) := compact_of_finite_subcover $ assume c hco hcs, have hdo : ∀t∈c, is_open (preimage f t), from assume t' ht, hf _ $ hco _ ht, have hds : s ⊆ ⋃i∈c, preimage f i, by simp [subset_def]; simp [subset_def] at hcs; exact assume x hx, hcs _ (mem_image_of_mem f hx), let ⟨d', hcd', hfd', hd'⟩ := compact_elim_finite_subcover_image hs hdo hds in ⟨d', hcd', hfd', by simp [subset_def] at hd'; simp [image_subset_iff_subset_preimage]; assumption⟩ end section constructions local notation `cont` := @continuous _ _ local notation `tspace` := topological_space open topological_space variable {f : α → β} lemma continuous_iff_induced_le {t₁ : tspace α} {t₂ : tspace β} : cont t₁ t₂ f ↔ (induced f t₂ ≤ t₁) := ⟨assume hc s ⟨t, ht, s_eq⟩, s_eq.symm ▸ hc t ht, assume hle s h, hle _ ⟨_, h, rfl⟩⟩ lemma continuous_eq_le_coinduced {t₁ : tspace α} {t₂ : tspace β} : cont t₁ t₂ f = (t₂ ≤ coinduced f t₁) := rfl theorem continuous_generated_from {t : tspace α} {b : set (set β)} (h : ∀s∈b, is_open (preimage f s)) : cont t (generate_from b) f := assume s hs, generate_open.rec_on hs h is_open_univ (assume s t _ _, is_open_inter) (assume t _ h, by rw [preimage_sUnion]; exact (is_open_Union $ assume s, is_open_Union $ assume hs, h s hs)) lemma continuous_induced_dom {t : tspace β} : cont (induced f t) t f := assume s h, ⟨_, h, rfl⟩ lemma continuous_induced_rng {g : γ → α} {t₂ : tspace β} {t₁ : tspace γ} (h : cont t₁ t₂ (f ∘ g)) : cont t₁ (induced f t₂) g := assume s ⟨t, ht, s_eq⟩, s_eq.symm ▸ h t ht lemma continuous_coinduced_rng {t : tspace α} : cont t (coinduced f t) f := assume s h, h lemma continuous_coinduced_dom {g : β → γ} {t₁ : tspace α} {t₂ : tspace γ} (h : cont t₁ t₂ (g ∘ f)) : cont (coinduced f t₁) t₂ g := assume s hs, h s hs lemma continuous_inf_dom {t₁ t₂ : tspace α} {t₃ : tspace β} (h₁ : cont t₁ t₃ f) (h₂ : cont t₂ t₃ f) : cont (t₁ ⊓ t₂) t₃ f := assume s h, ⟨h₁ s h, h₂ s h⟩ lemma continuous_inf_rng_left {t₁ : tspace α} {t₃ t₂ : tspace β} (h : cont t₁ t₂ f) : cont t₁ (t₂ ⊓ t₃) f := assume s hs, h s hs.left lemma continuous_inf_rng_right {t₁ : tspace α} {t₃ t₂ : tspace β} (h : cont t₁ t₃ f) : cont t₁ (t₂ ⊓ t₃) f := assume s hs, h s hs.right lemma continuous_Inf_dom {t₁ : set (tspace α)} {t₂ : tspace β} (h : ∀t∈t₁, cont t t₂ f) : cont (Inf t₁) t₂ f := assume s hs t ht, h t ht s hs lemma continuous_Inf_rng {t₁ : tspace α} {t₂ : set (tspace β)} {t : tspace β} (h₁ : t ∈ t₂) (hf : cont t₁ t f) : cont t₁ (Inf t₂) f := assume s hs, hf s $ hs t h₁ lemma continuous_infi_dom {t₁ : ι → tspace α} {t₂ : tspace β} (h : ∀i, cont (t₁ i) t₂ f) : cont (infi t₁) t₂ f := continuous_Inf_dom $ assume t ⟨i, (t_eq : t = t₁ i)⟩, t_eq.symm ▸ h i lemma continuous_infi_rng {t₁ : tspace α} {t₂ : ι → tspace β} {i : ι} (h : cont t₁ (t₂ i) f) : cont t₁ (infi t₂) f := continuous_Inf_rng ⟨i, rfl⟩ h lemma continuous_top {t : tspace β} : cont ⊤ t f := assume s h, trivial lemma continuous_bot {t : tspace α} : cont t ⊥ f := continuous_Inf_rng (mem_univ $ coinduced f t) continuous_coinduced_rng lemma continuous_sup_rng {t₁ : tspace α} {t₂ t₃ : tspace β} (h₁ : cont t₁ t₂ f) (h₂ : cont t₁ t₃ f) : cont t₁ (t₂ ⊔ t₃) f := continuous_Inf_rng (show t₂ ≤ coinduced f t₁ ∧ t₃ ≤ coinduced f t₁, from ⟨h₁, h₂⟩) continuous_coinduced_rng lemma continuous_sup_dom_left {t₁ t₂ : tspace α} {t₃ : tspace β} (h : cont t₁ t₃ f) : cont (t₁ ⊔ t₂) t₃ f := continuous_Inf_dom $ assume t ⟨h₁, h₂⟩ s hs, h₁ _ $ h s hs lemma continuous_sup_dom_right {t₁ t₂ : tspace α} {t₃ : tspace β} (h : cont t₂ t₃ f) : cont (t₁ ⊔ t₂) t₃ f := continuous_Inf_dom $ assume t ⟨h₁, h₂⟩ s hs, h₂ _ $ h s hs end constructions section embedding lemma induced_mono {t₁ t₂ : topological_space α} {f : β → α} (h : t₁ ≤ t₂) : t₁.induced f ≤ t₂.induced f := continuous_iff_induced_le.mp $ show @continuous β α (@topological_space.induced β α f t₂) t₁ (id ∘ f), begin apply continuous_compose, exact continuous_induced_dom, exact assume s hs, h _ hs end lemma induced_id [t : topological_space α] : t.induced id = t := topological_space_eq $ funext $ assume s, propext $ ⟨assume ⟨s', hs, h⟩, h.symm ▸ hs, assume hs, ⟨s, hs, rfl⟩⟩ lemma induced_compose [tβ : topological_space β] [tγ : topological_space γ] {f : α → β} {g : β → γ} : (tγ.induced g).induced f = tγ.induced (g ∘ f) := topological_space_eq $ funext $ assume s, propext $ ⟨assume ⟨s', ⟨s, hs, h₂⟩, h₁⟩, h₁.symm ▸ h₂.symm ▸ ⟨s, hs, rfl⟩, assume ⟨s, hs, h⟩, ⟨preimage g s, ⟨s, hs, rfl⟩, h ▸ rfl⟩⟩ lemma induced_sup (t₁ : topological_space β) (t₂ : topological_space β) {f : α → β} : (t₁ ⊔ t₂).induced f = t₁.induced f ⊔ t₂.induced f := le_antisymm (continuous_iff_induced_le.mp $ continuous_sup_rng (continuous_sup_dom_left continuous_induced_dom) (continuous_sup_dom_right continuous_induced_dom)) (sup_le (induced_mono le_sup_left) (induced_mono le_sup_right)) def embedding [tα : topological_space α] [tβ : topological_space β] (f : α → β) : Prop := (∀a₁ a₂, f a₁ = f a₂ → a₁ = a₂) ∧ tα = tβ.induced f variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ] lemma embedding_id : embedding (@id α) := ⟨assume a₁ a₂ h, h, induced_id.symm⟩ lemma embedding_compose {f : α → β} {g : β → γ} (hf : embedding f) (hg : embedding g) : embedding (g ∘ f) := ⟨assume a₁ a₂ h, hf.left _ _ $ hg.left _ _ $ h, by rw [hf.right, hg.right, induced_compose]⟩ lemma embedding_prod_mk {f : α → β} {g : γ → δ} (hf : embedding f) (hg : embedding g) : embedding (λx:α×γ, (f x.1, g x.2)) := ⟨assume ⟨x₁, x₂⟩ ⟨y₁, y₂⟩, by simp; exact assume ⟨h₁, h₂⟩, ⟨hf.left _ _ h₁, hg.left _ _ h₂⟩, by rw [prod.topological_space, prod.topological_space, hf.right, hg.right, induced_compose, induced_compose, induced_sup, induced_compose, induced_compose]⟩ lemma embedding_of_embedding_compose {f : α → β} {g : β → γ} (hf : continuous f) (hg : continuous g) (hgf : embedding (g ∘ f)) : embedding f := ⟨assume a₁ a₂ h, hgf.left a₁ a₂ $ by simp [h, (∘)], le_antisymm (by rw [hgf.right, ←continuous_iff_induced_le]; apply continuous_compose continuous_induced_dom hg) (by rwa [←continuous_iff_induced_le])⟩ lemma embedding_open {f : α → β} {s : set α} (hf : embedding f) (h : is_open (f '' univ)) (hs : is_open s) : is_open (f '' s) := let ⟨t, ht, h_eq⟩ := by rw [hf.right] at hs; exact hs in have is_open (t ∩ f '' univ), from is_open_inter ht h, h_eq.symm ▸ by rwa [image_preimage_eq_inter_rng] lemma embedding_is_closed {f : α → β} {s : set α} (hf : embedding f) (h : is_closed (f '' univ)) (hs : is_closed s) : is_closed (f '' s) := let ⟨t, ht, h_eq⟩ := by rw [hf.right, is_closed_induced_iff] at hs; exact hs in have is_closed (t ∩ f '' univ), from is_closed_inter ht h, h_eq.symm ▸ by rwa [image_preimage_eq_inter_rng] end embedding section sierpinski variables [topological_space α] @[simp] lemma is_open_singleton_true : is_open ({true} : set Prop) := topological_space.generate_open.basic _ (by simp) lemma continuous_Prop {p : α → Prop} : continuous p ↔ is_open {x | p x} := ⟨assume h : continuous p, have is_open (preimage p {true}), from h _ is_open_singleton_true, by simp [preimage, eq_true] at this; assumption, assume h : is_open {x | p x}, continuous_generated_from $ assume s (hs : s ∈ {{true}}), by simp at hs; simp [hs, preimage, eq_true, h]⟩ end sierpinski section induced open topological_space variables [t : topological_space β] {f : α → β} theorem is_open_induced {s : set β} (h : is_open s) : (induced f t).is_open (preimage f s) := ⟨s, h, rfl⟩ lemma nhds_induced_eq_vmap {a : α} : @nhds α (induced f t) a = vmap f (nhds (f a)) := le_antisymm (assume s ⟨s', hs', (h_s : preimage f s' ⊆ s)⟩, have ∃t':set β, is_open t' ∧ t' ⊆ s' ∧ f a ∈ t', by simp [mem_nhds_sets_iff] at hs'; assumption, let ⟨t', ht', hsub, hin⟩ := this in (@nhds α (induced f t) a).upwards_sets begin simp [mem_nhds_sets_iff], exact ⟨preimage f t', is_open_induced ht', hin, preimage_mono hsub⟩ end h_s) (le_infi $ assume s, le_infi $ assume ⟨as, ⟨s', is_open_s', s_eq⟩⟩, begin simp [vmap, mem_nhds_sets_iff, s_eq], exact ⟨s', subset.refl _, s', is_open_s', subset.refl _, by rw [s_eq] at as; assumption⟩ end) lemma map_nhds_induced_eq {a : α} (h : image f univ ∈ (nhds (f a)).sets) : map f (@nhds α (induced f t) a) = nhds (f a) := le_antisymm ((@continuous_iff_tendsto α β (induced f t) _ _).mp continuous_induced_dom a) (assume s, assume hs : preimage f s ∈ (@nhds α (induced f t) a).sets, let ⟨t', t_subset, is_open_t, a_in_t⟩ := mem_nhds_sets_iff.mp h in let ⟨s', s'_subset, ⟨s'', is_open_s'', s'_eq⟩, a_in_s'⟩ := (@mem_nhds_sets_iff _ (induced f t) _ _).mp hs in by subst s'_eq; exact (mem_nhds_sets_iff.mpr $ ⟨t' ∩ s'', assume x ⟨h₁, h₂⟩, match x, h₂, t_subset h₁ with | x, h₂, ⟨y, _, y_eq⟩ := begin subst y_eq, exact s'_subset h₂ end end, is_open_inter is_open_t is_open_s'', ⟨a_in_t, a_in_s'⟩⟩)) lemma closure_induced [t : topological_space β] {f : α → β} {a : α} {s : set α} (hf : ∀x y, f x = f y → x = y) : a ∈ @closure α (topological_space.induced f t) s ↔ f a ∈ closure (f '' s) := have vmap f (nhds (f a) ⊓ principal (f '' s)) ≠ ⊥ ↔ nhds (f a) ⊓ principal (f '' s) ≠ ⊥, from ⟨assume h₁ h₂, h₁ $ h₂.symm ▸ vmap_bot, assume h, forall_sets_neq_empty_iff_neq_bot.mp $ assume s₁ ⟨s₂, hs₂, (hs : preimage f s₂ ⊆ s₁)⟩, have f '' s ∈ (nhds (f a) ⊓ principal (f '' s)).sets, from mem_inf_sets_of_right $ by simp [subset.refl], have s₂ ∩ f '' s ∈ (nhds (f a) ⊓ principal (f '' s)).sets, from inter_mem_sets hs₂ this, let ⟨b, hb₁, ⟨a, ha, ha₂⟩⟩ := inhabited_of_mem_sets h this in ne_empty_of_mem $ hs $ by rwa [←ha₂] at hb₁⟩, calc a ∈ @closure α (topological_space.induced f t) s ↔ (@nhds α (topological_space.induced f t) a) ⊓ principal s ≠ ⊥ : by rw [closure_eq_nhds]; refl ... ↔ vmap f (nhds (f a)) ⊓ principal (preimage f (f '' s)) ≠ ⊥ : by rw [nhds_induced_eq_vmap, preimage_image_eq hf] ... ↔ vmap f (nhds (f a) ⊓ principal (f '' s)) ≠ ⊥ : by rw [vmap_inf, ←vmap_principal] ... ↔ _ : by rwa [closure_eq_nhds] end induced section prod open topological_space variables [topological_space α] [topological_space β] [topological_space γ] lemma continuous_fst : continuous (@prod.fst α β) := continuous_sup_dom_left continuous_induced_dom lemma continuous_snd : continuous (@prod.snd α β) := continuous_sup_dom_right continuous_induced_dom lemma continuous_prod_mk {f : γ → α} {g : γ → β} (hf : continuous f) (hg : continuous g) : continuous (λx, prod.mk (f x) (g x)) := continuous_sup_rng (continuous_induced_rng hf) (continuous_induced_rng hg) lemma is_open_set_prod {s : set α} {t : set β} (hs : is_open s) (ht: is_open t) : is_open (set.prod s t) := is_open_inter (continuous_fst s hs) (continuous_snd t ht) lemma prod_eq_generate_from [tα : topological_space α] [tβ : topological_space β] : prod.topological_space = generate_from {g | ∃(s:set α) (t:set β), is_open s ∧ is_open t ∧ g = set.prod s t} := le_antisymm (sup_le (assume s ⟨t, ht, s_eq⟩, have set.prod t univ = s, by simp [s_eq, preimage, set.prod], this ▸ (generate_open.basic _ ⟨t, univ, ht, is_open_univ, rfl⟩)) (assume s ⟨t, ht, s_eq⟩, have set.prod univ t = s, by simp [s_eq, preimage, set.prod], this ▸ (generate_open.basic _ ⟨univ, t, is_open_univ, ht, rfl⟩))) (generate_from_le $ assume g ⟨s, t, hs, ht, g_eq⟩, g_eq.symm ▸ is_open_set_prod hs ht) lemma nhds_prod_eq {a : α} {b : β} : nhds (a, b) = filter.prod (nhds a) (nhds b) := by rw [prod_eq_generate_from, nhds_generate_from]; exact le_antisymm (le_infi $ assume s, le_infi $ assume hs, le_infi $ assume t, le_infi $ assume ht, begin simp [mem_nhds_sets_iff] at hs, simp [mem_nhds_sets_iff] at ht, revert hs ht, exact (assume ⟨s', hs', hs_sub, as'⟩ ⟨t', ht', ht_sub, at'⟩, infi_le_of_le (set.prod s' t') $ infi_le_of_le ⟨⟨as', at'⟩, s', t', hs', ht', rfl⟩ $ principal_mono.mpr $ set.prod_mono hs_sub ht_sub) end) (le_infi $ assume s, le_infi $ assume ⟨hab, s', t', hs', ht', s_eq⟩, begin revert hab, simp [s_eq], exact assume ⟨ha, hb⟩, @prod_mem_prod α β s' t' (nhds a) (nhds b) (mem_nhds_sets_iff.mpr ⟨s', subset.refl s', hs', ha⟩) (mem_nhds_sets_iff.mpr ⟨t', subset.refl t', ht', hb⟩) end) lemma closure_prod_eq {s : set α} {t : set β} : closure (set.prod s t) = set.prod (closure s) (closure t) := set.ext $ assume ⟨a, b⟩, have filter.prod (nhds a) (nhds b) ⊓ principal (set.prod s t) = filter.prod (nhds a ⊓ principal s) (nhds b ⊓ principal t), by rw [←prod_inf_prod, prod_principal_principal], by simp [closure_eq_nhds, nhds_prod_eq, this]; exact prod_neq_bot lemma is_closed_prod [topological_space α] [topological_space β] {s₁ : set α} {s₂ : set β} (h₁ : is_closed s₁) (h₂ : is_closed s₂) : is_closed (set.prod s₁ s₂) := closure_eq_iff_is_closed.mp $ by simp [h₁, h₂, closure_prod_eq, closure_eq_of_is_closed] lemma is_closed_diagonal [topological_space α] [t2_space α] : is_closed {p:α×α | p.1 = p.2} := is_closed_iff_nhds.mpr $ assume ⟨a₁, a₂⟩ h, eq_of_nhds_neq_bot $ assume : nhds a₁ ⊓ nhds a₂ = ⊥, h $ let ⟨t₁, ht₁, t₂, ht₂, (h' : t₁ ∩ t₂ ⊆ ∅)⟩ := by rw [←empty_in_sets_eq_bot, mem_inf_sets] at this; exact this in begin rw [nhds_prod_eq, ←empty_in_sets_eq_bot], apply filter.upwards_sets, apply inter_mem_inf_sets (prod_mem_prod ht₁ ht₂) (mem_principal_sets.mpr (subset.refl _)), exact assume ⟨x₁, x₂⟩ ⟨⟨hx₁, hx₂⟩, (heq : x₁ = x₂)⟩, show false, from @h' x₁ ⟨hx₁, heq.symm ▸ hx₂⟩ end lemma is_closed_eq [topological_space α] [t2_space α] [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : is_closed {x:β | f x = g x} := continuous_iff_is_closed.mp (continuous_prod_mk hf hg) _ is_closed_diagonal end prod section sum variables [topological_space α] [topological_space β] [topological_space γ] lemma continuous_inl : continuous (@sum.inl α β) := continuous_inf_rng_left continuous_coinduced_rng lemma continuous_inr : continuous (@sum.inr α β) := continuous_inf_rng_right continuous_coinduced_rng lemma continuous_sum_rec {f : α → γ} {g : β → γ} (hf : continuous f) (hg : continuous g) : @continuous (α ⊕ β) γ _ _ (@sum.rec α β (λ_, γ) f g) := continuous_inf_dom hf hg end sum section subtype variables [topological_space α] [topological_space β] [topological_space γ] {p : α → Prop} lemma tendsto_nhds_iff_of_embedding {f : α → β} {g : β → γ} {a : filter α} {b : β} (hg : embedding g) : tendsto f a (nhds b) ↔ tendsto (g ∘ f) a (nhds (g b)) := by rw [tendsto, tendsto, hg.right, nhds_induced_eq_vmap, le_vmap_iff_map_le, map_map] lemma continuous_iff_of_embedding {f : α → β} {g : β → γ} (hg : embedding g) : continuous f ↔ continuous (g ∘ f) := by simp [continuous_iff_tendsto, @tendsto_nhds_iff_of_embedding α β γ _ _ _ f g _ _ hg] lemma embedding_graph {f : α → β} (hf : continuous f) : embedding (λx, (x, f x)) := embedding_of_embedding_compose (continuous_prod_mk continuous_id hf) continuous_fst embedding_id lemma embedding_subtype_val : embedding (@subtype.val α p) := ⟨assume a₁ a₂, subtype.eq, rfl⟩ lemma continuous_subtype_val : continuous (@subtype.val α p) := continuous_induced_dom lemma continuous_subtype_mk {f : β → α} (hp : ∀x, p (f x)) (h : continuous f) : continuous (λx, (⟨f x, hp x⟩ : subtype p)) := continuous_induced_rng h lemma map_nhds_subtype_val_eq {a : α} (ha : p a) (h : {a | p a} ∈ (nhds a).sets) : map (@subtype.val α p) (nhds ⟨a, ha⟩) = nhds a := map_nhds_induced_eq (by simp [subtype.val_image, h]) lemma nhds_subtype_eq_vmap {a : α} {h : p a} : nhds (⟨a, h⟩ : subtype p) = vmap subtype.val (nhds a) := nhds_induced_eq_vmap lemma continuous_subtype_nhds_cover {f : α → β} {c : ι → α → Prop} (c_cover : ∀x:α, ∃i, {x | c i x} ∈ (nhds x).sets) (f_cont : ∀i, continuous (λ(x : subtype (c i)), f x.val)) : continuous f := continuous_iff_tendsto.mpr $ assume x, let ⟨i, (c_sets : {x | c i x} ∈ (nhds x).sets)⟩ := c_cover x in let x' : subtype (c i) := ⟨x, mem_of_nhds c_sets⟩ in calc map f (nhds x) = map f (map subtype.val (nhds x')) : congr_arg (map f) (map_nhds_subtype_val_eq _ $ c_sets).symm ... = map (λx:subtype (c i), f x.val) (nhds x') : rfl ... ≤ nhds (f x) : continuous_iff_tendsto.mp (f_cont i) x' lemma continuous_subtype_is_closed_cover {f : α → β} (c : γ → α → Prop) (h_lf : locally_finite (λi, {x | c i x})) (h_is_closed : ∀i, is_closed {x | c i x}) (h_cover : ∀x, ∃i, c i x) (f_cont : ∀i, continuous (λ(x : subtype (c i)), f x.val)) : continuous f := continuous_iff_is_closed.mpr $ assume s hs, have ∀i, is_closed (@subtype.val α {x | c i x} '' (preimage (f ∘ subtype.val) s)), from assume i, embedding_is_closed embedding_subtype_val (by simp [subtype.val_image]; exact h_is_closed i) (continuous_iff_is_closed.mp (f_cont i) _ hs), have is_closed (⋃i, @subtype.val α {x | c i x} '' (preimage (f ∘ subtype.val) s)), from is_closed_Union_of_locally_finite (locally_finite_subset h_lf $ assume i x ⟨⟨x', hx'⟩, _, heq⟩, heq ▸ hx') this, have preimage f s = (⋃i, @subtype.val α {x | c i x} '' (preimage (f ∘ subtype.val) s)), begin apply set.ext, simp, exact assume x, ⟨assume hx, let ⟨i, hi⟩ := h_cover x in ⟨i, ⟨x, hi⟩, hx, rfl⟩, assume ⟨i, ⟨x', hx'⟩, hx₁, hx₂⟩, hx₂ ▸ hx₁⟩ end, by rwa [this] lemma closure_subtype {p : α → Prop} {x : {a // p a}} {s : set {a // p a}}: x ∈ closure s ↔ x.val ∈ closure (subtype.val '' s) := closure_induced $ assume x y, subtype.eq end subtype section pi lemma nhds_pi {ι : Type u} {α : ι → Type v} [t : ∀i, topological_space (α i)] {a : Πi, α i} : nhds a = (⨅i, vmap (λx, x i) (nhds (a i))) := calc nhds a = (⨅i, @nhds _ (@topological_space.induced _ _ (λx:Πi, α i, x i) (t i)) a) : nhds_supr ... = (⨅i, vmap (λx, x i) (nhds (a i))) : by simp [nhds_induced_eq_vmap] /-- Tychonoff's theorem -/ lemma compact_pi_infinite {ι : Type v} {α : ι → Type u} [∀i:ι, topological_space (α i)] {s : Πi:ι, set (α i)} : (∀i, compact (s i)) → compact {x : Πi:ι, α i | ∀i, x i ∈ s i} := begin simp [compact_iff_ultrafilter_le_nhds, nhds_pi], exact assume h f hf hfs, let p : Πi:ι, filter (α i) := λi, map (λx:Πi:ι, α i, x i) f in have ∀i:ι, ∃a, a∈s i ∧ p i ≤ nhds a, from assume i, h i (p i) (ultrafilter_map hf) $ show preimage (λx:Πi:ι, α i, x i) (s i) ∈ f.sets, from f.upwards_sets hfs $ assume x (hx : ∀i, x i ∈ s i), hx i, let ⟨a, ha⟩ := classical.axiom_of_choice this in ⟨a, assume i, (ha i).left, assume i, le_vmap_iff_map_le.mpr $ (ha i).right⟩ end end pi -- TODO: use embeddings from above! structure dense_embedding [topological_space α] [topological_space β] (e : α → β) := (dense : ∀x, x ∈ closure (e '' univ)) (inj : ∀x y, e x = e y → x = y) (induced : ∀a, vmap e (nhds (e a)) = nhds a) namespace dense_embedding variables [topological_space α] [topological_space β] variables {e : α → β} (de : dense_embedding e) protected lemma embedding (de : dense_embedding e) : embedding e := ⟨de.inj, eq_of_nhds_eq_nhds begin intro a, rw [← de.induced a, nhds_induced_eq_vmap] end⟩ protected lemma tendsto (de : dense_embedding e) {a : α} : tendsto e (nhds a) (nhds (e a)) := by rw [←de.induced a]; exact tendsto_vmap protected lemma continuous (de : dense_embedding e) {a : α} : continuous e := by rw [continuous_iff_tendsto]; exact assume a, de.tendsto lemma inj_iff (de : dense_embedding e) {x y} : e x = e y ↔ x = y := ⟨de.inj _ _, assume h, h ▸ rfl⟩ lemma closure_image_univ : closure (e '' univ) = univ := let h := de.dense in set.ext $ assume x, ⟨assume _, trivial, assume _, @h x⟩ protected lemma nhds_inf_neq_bot (de : dense_embedding e) {b : β} : nhds b ⊓ principal (e '' univ) ≠ ⊥ := begin have h := de.dense, simp [closure_eq_nhds] at h, exact h _ end lemma vmap_nhds_neq_bot (de : dense_embedding e) {b : β} : vmap e (nhds b) ≠ ⊥ := forall_sets_neq_empty_iff_neq_bot.mp $ assume s ⟨t, ht, (hs : preimage e t ⊆ s)⟩, have t ∩ e '' univ ∈ (nhds b ⊓ principal (e '' univ)).sets, from inter_mem_inf_sets ht (subset.refl _), let ⟨x, ⟨hx₁, y, hy, y_eq⟩⟩ := inhabited_of_mem_sets de.nhds_inf_neq_bot this in ne_empty_of_mem $ hs $ show e y ∈ t, from y_eq.symm ▸ hx₁ variables [topological_space γ] [inhabited γ] [regular_space γ] def ext (de : dense_embedding e) (f : α → γ) : β → γ := lim ∘ map f ∘ vmap e ∘ nhds lemma ext_eq {b : β} {c : γ} {f : α → γ} (hf : map f (vmap e (nhds b)) ≤ nhds c) : de.ext f b = c := lim_eq begin simp; exact vmap_nhds_neq_bot de end hf lemma ext_e_eq {a : α} {f : α → γ} (de : dense_embedding e) (hf : map f (nhds a) ≤ nhds (f a)) : de.ext f (e a) = f a := de.ext_eq begin rw de.induced; exact hf end lemma tendsto_ext {b : β} {f : α → γ} (de : dense_embedding e) (hf : {b | ∃c, tendsto f (vmap e $ nhds b) (nhds c)} ∈ (nhds b).sets) : tendsto (de.ext f) (nhds b) (nhds (de.ext f b)) := let φ := {b | tendsto f (vmap e $ nhds b) (nhds $ de.ext f b)} in have hφ : φ ∈ (nhds b).sets, from (nhds b).upwards_sets hf $ assume b ⟨c, hc⟩, show tendsto f (vmap e (nhds b)) (nhds (de.ext f b)), from (de.ext_eq hc).symm ▸ hc, assume s hs, let ⟨s'', hs''₁, hs''₂, hs''₃⟩ := nhds_is_closed hs in let ⟨s', hs'₁, (hs'₂ : preimage e s' ⊆ preimage f s'')⟩ := mem_of_nhds hφ hs''₁ in let ⟨t, (ht₁ : t ⊆ φ ∩ s'), ht₂, ht₃⟩ := mem_nhds_sets_iff.mp $ inter_mem_sets hφ hs'₁ in have h₁ : closure (f '' preimage e s') ⊆ s'', by rw [closure_subset_iff_subset_of_is_closed hs''₃, image_subset_iff_subset_preimage]; exact hs'₂, have h₂ : t ⊆ preimage (de.ext f) (closure (f '' preimage e t)), from assume b' hb', have nhds b' ≤ principal t, by simp; exact mem_nhds_sets ht₂ hb', have map f (vmap e (nhds b')) ≤ nhds (de.ext f b') ⊓ principal (f '' preimage e t), from calc _ ≤ map f (vmap e (nhds b' ⊓ principal t)) : map_mono $ vmap_mono $ le_inf (le_refl _) this ... ≤ map f (vmap e (nhds b')) ⊓ map f (vmap e (principal t)) : le_inf (map_mono $ vmap_mono $ inf_le_left) (map_mono $ vmap_mono $ inf_le_right) ... ≤ map f (vmap e (nhds b')) ⊓ principal (f '' preimage e t) : by simp [le_refl] ... ≤ _ : inf_le_inf ((ht₁ hb').left) (le_refl _), show de.ext f b' ∈ closure (f '' preimage e t), begin rw [closure_eq_nhds], apply neq_bot_of_le_neq_bot _ this, simp, exact de.vmap_nhds_neq_bot end, (nhds b).upwards_sets (show t ∈ (nhds b).sets, from mem_nhds_sets ht₂ ht₃) (calc t ⊆ preimage (de.ext f) (closure (f '' preimage e t)) : h₂ ... ⊆ preimage (de.ext f) (closure (f '' preimage e s')) : preimage_mono $ closure_mono $ image_subset f $ preimage_mono $ subset.trans ht₁ $ inter_subset_right _ _ ... ⊆ preimage (de.ext f) s'' : preimage_mono h₁ ... ⊆ preimage (de.ext f) s : preimage_mono hs''₂) lemma continuous_ext {f : α → γ} (de : dense_embedding e) (hf : ∀b, ∃c, tendsto f (vmap e (nhds b)) (nhds c)) : continuous (de.ext f) := continuous_iff_tendsto.mpr $ assume b, de.tendsto_ext $ univ_mem_sets' hf end dense_embedding namespace dense_embedding variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ] protected def prod {e₁ : α → β} {e₂ : γ → δ} (de₁ : dense_embedding e₁) (de₂ : dense_embedding e₂) : dense_embedding (λ(p : α × γ), (e₁ p.1, e₂ p.2)) := { dense_embedding . dense := have closure ((λ(p : α × γ), (e₁ p.1, e₂ p.2)) '' univ) = set.prod (closure (e₁ '' univ)) (closure (e₂ '' univ)), by rw [←closure_prod_eq, prod_image_image_eq, univ_prod_univ], assume ⟨b, d⟩, begin rw [this], simp, constructor, apply de₁.dense, apply de₂.dense end, inj := assume ⟨x₁, x₂⟩ ⟨y₁, y₂⟩, by simp; exact assume ⟨h₁, h₂⟩, ⟨de₁.inj _ _ h₁, de₂.inj _ _ h₂⟩, induced := assume ⟨a, b⟩, by rw [nhds_prod_eq, nhds_prod_eq, ←prod_vmap_vmap_eq, de₁.induced, de₂.induced] } def subtype_emb (p : α → Prop) {e : α → β} (de : dense_embedding e) (x : {x // p x}) : {x // x ∈ closure (e '' {x | p x})} := ⟨e x.1, subset_closure $ mem_image_of_mem e x.2⟩ protected def subtype (p : α → Prop) {e : α → β} (de : dense_embedding e) : dense_embedding (de.subtype_emb p) := { dense_embedding . dense := assume ⟨x, hx⟩, closure_subtype.mpr $ have (λ (x : {x // p x}), e (x.val)) = e ∘ subtype.val, from rfl, begin simp [(image_comp _ _ _).symm, (∘), subtype_emb], rw [this, image_comp, subtype.val_image], simp, assumption end, inj := assume ⟨x, hx⟩ ⟨y, hy⟩ h, subtype.eq $ de.inj x y $ @@congr_arg subtype.val h, induced := assume ⟨x, hx⟩, by simp [subtype_emb, nhds_subtype_eq_vmap, vmap_vmap_comp, (∘), (de.induced x).symm] } end dense_embedding lemma is_closed_property [topological_space α] [topological_space β] {e : α → β} {p : β → Prop} (he : closure (e '' univ) = univ) (hp : is_closed {x | p x}) (h : ∀a, p (e a)) : ∀b, p b := have univ ⊆ {b | p b}, from calc univ = closure (e '' univ) : he.symm ... ⊆ closure {b | p b} : closure_mono $ image_subset_iff_subset_preimage.mpr $ assume a _, h a ... = _ : closure_eq_of_is_closed hp, assume b, this trivial lemma is_closed_property2 [topological_space α] [topological_space β] {e : α → β} {p : β → β → Prop} (he : dense_embedding e) (hp : is_closed {q:β×β | p q.1 q.2}) (h : ∀a₁ a₂, p (e a₁) (e a₂)) : ∀b₁ b₂, p b₁ b₂ := have ∀q:β×β, p q.1 q.2, from is_closed_property ((he.prod he).closure_image_univ) hp $ assume ⟨a₁, a₂⟩, h _ _, assume b₁ b₂, this ⟨b₁, b₂⟩ lemma is_closed_property3 [topological_space α] [topological_space β] {e : α → β} {p : β → β → β → Prop} (he : dense_embedding e) (hp : is_closed {q:β×β×β | p q.1 q.2.1 q.2.2}) (h : ∀a₁ a₂ a₃, p (e a₁) (e a₂) (e a₃)) : ∀b₁ b₂ b₃, p b₁ b₂ b₃ := have ∀q:β×β×β, p q.1 q.2.1 q.2.2, from is_closed_property ((he.prod $ he.prod he).closure_image_univ) hp $ assume ⟨a₁, a₂, a₃⟩, h _ _ _, assume b₁ b₂ b₃, this ⟨b₁, b₂, b₃⟩ lemma mem_closure_of_continuous [topological_space α] [topological_space β] {f : α → β} {a : α} {s : set α} {t : set β} (hf : continuous f) (ha : a ∈ closure s) (h : ∀a∈s, f a ∈ closure t) : f a ∈ closure t := calc f a ∈ f '' closure s : mem_image_of_mem _ ha ... ⊆ closure (f '' s) : image_closure_subset_closure_image hf ... ⊆ closure (closure t) : closure_mono $ image_subset_iff_subset_preimage.mpr $ h ... ⊆ closure t : begin rw [closure_eq_of_is_closed], exact subset.refl _, exact is_closed_closure end lemma mem_closure_of_continuous2 [topological_space α] [topological_space β] [topological_space γ] {f : α → β → γ} {a : α} {b : β} {s : set α} {t : set β} {u : set γ} (hf : continuous (λp:α×β, f p.1 p.2)) (ha : a ∈ closure s) (hb : b ∈ closure t) (h : ∀a∈s, ∀b∈t, f a b ∈ closure u) : f a b ∈ closure u := have (a,b) ∈ closure (set.prod s t), by simp [closure_prod_eq, ha, hb], show f (a, b).1 (a, b).2 ∈ closure u, from @mem_closure_of_continuous (α×β) _ _ _ (λp:α×β, f p.1 p.2) (a,b) _ u hf this $ assume ⟨p₁, p₂⟩ ⟨h₁, h₂⟩, h p₁ h₁ p₂ h₂