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
8a001f5af0575c6e5790486beffe807a4f41e351
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/polynomial/eval_auto.lean
1a0b84b3a01b9ea17e260b1b98abbb2b926095c3
[]
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
25,723
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 -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.polynomial.induction import Mathlib.data.polynomial.degree.definitions import Mathlib.deprecated.ring import Mathlib.PostPort universes u v u_1 u_2 w y namespace Mathlib /-! # Theory of univariate polynomials The main defs here are `eval₂`, `eval`, and `map`. We give several lemmas about their interaction with each other and with module operations. -/ namespace polynomial /-- 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₂ {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (x : S) (p : polynomial R) : S := finsupp.sum p fun (e : ℕ) (a : R) => coe_fn f a * x ^ e theorem eval₂_eq_sum {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] {f : R →+* S} {x : S} : eval₂ f x p = finsupp.sum p fun (e : ℕ) (a : R) => coe_fn f a * x ^ e := rfl theorem eval₂_eq_lift_nc {R : Type u} {S : Type v} [semiring R] [semiring S] {f : R →+* S} {x : S} : eval₂ f x = ⇑(add_monoid_algebra.lift_nc (↑f) (coe_fn (powers_hom S) x)) := rfl theorem eval₂_congr {R : Type u_1} {S : Type u_2} [semiring R] [semiring S] {f : R →+* S} {g : R →+* S} {s : S} {t : S} {φ : polynomial R} {ψ : polynomial R} : f = g → s = t → φ = ψ → eval₂ f s φ = eval₂ g t ψ := fun (ᾰ : f = g) (ᾰ_1 : s = t) (ᾰ_2 : φ = ψ) => Eq._oldrec (Eq._oldrec (Eq._oldrec (Eq.refl (eval₂ f s φ)) ᾰ_2) ᾰ_1) ᾰ @[simp] theorem eval₂_zero {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (x : S) : eval₂ f x 0 = 0 := finsupp.sum_zero_index @[simp] theorem eval₂_C {R : Type u} {S : Type v} {a : R} [semiring R] [semiring S] (f : R →+* S) (x : S) : eval₂ f x (coe_fn C a) = coe_fn f a := sorry @[simp] theorem eval₂_X {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (x : S) : eval₂ f x X = x := sorry @[simp] theorem eval₂_monomial {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (x : S) {n : ℕ} {r : R} : eval₂ f x (coe_fn (monomial n) r) = coe_fn f r * x ^ n := sorry @[simp] theorem eval₂_X_pow {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (x : S) {n : ℕ} : eval₂ f x (X ^ n) = x ^ n := sorry @[simp] theorem eval₂_add {R : Type u} {S : Type v} [semiring R] {p : polynomial R} {q : polynomial R} [semiring S] (f : R →+* S) (x : S) : eval₂ f x (p + q) = eval₂ f x p + eval₂ f x q := sorry @[simp] theorem eval₂_one {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (x : S) : eval₂ f x 1 = 1 := eq.mpr (id (Eq._oldrec (Eq.refl (eval₂ f x 1 = 1)) (Eq.symm C_1))) (eq.mpr (id (Eq._oldrec (Eq.refl (eval₂ f x (coe_fn C 1) = 1)) (eval₂_C f x))) (eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn f 1 = 1)) (ring_hom.map_one f))) (Eq.refl 1))) @[simp] theorem eval₂_bit0 {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) (x : S) : eval₂ f x (bit0 p) = bit0 (eval₂ f x p) := sorry @[simp] theorem eval₂_bit1 {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) (x : S) : eval₂ f x (bit1 p) = bit1 (eval₂ f x p) := sorry @[simp] theorem eval₂_smul {R : Type u} {S : Type v} [semiring R] [semiring S] (g : R →+* S) (p : polynomial R) (x : S) {s : R} : eval₂ g x (s • p) = coe_fn g s • eval₂ g x p := sorry @[simp] theorem eval₂_C_X {R : Type u} [semiring R] {p : polynomial R} : eval₂ C X p = p := sorry protected instance eval₂.is_add_monoid_hom {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (x : S) : is_add_monoid_hom (eval₂ f x) := is_add_monoid_hom.mk (eval₂_zero f x) @[simp] theorem eval₂_nat_cast {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (x : S) (n : ℕ) : eval₂ f x ↑n = ↑n := sorry theorem eval₂_sum {R : Type u} {S : Type v} {T : Type w} [semiring R] [semiring S] (f : R →+* S) [semiring T] (p : polynomial T) (g : ℕ → T → polynomial R) (x : S) : eval₂ f x (finsupp.sum p g) = finsupp.sum p fun (n : ℕ) (a : T) => eval₂ f x (g n a) := sorry theorem eval₂_finset_sum {R : Type u} {S : Type v} {ι : Type y} [semiring R] [semiring S] (f : R →+* S) (s : finset ι) (g : ι → polynomial R) (x : S) : eval₂ f x (finset.sum s fun (i : ι) => g i) = finset.sum s fun (i : ι) => eval₂ f x (g i) := sorry theorem eval₂_mul_noncomm {R : Type u} {S : Type v} [semiring R] {p : polynomial R} {q : polynomial R} [semiring S] (f : R →+* S) (x : S) (hf : ∀ (k : ℕ), commute (coe_fn f (coeff q k)) x) : eval₂ f x (p * q) = eval₂ f x p * eval₂ f x q := sorry @[simp] theorem eval₂_mul_X {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) (x : S) : eval₂ f x (p * X) = eval₂ f x p * x := sorry @[simp] theorem eval₂_X_mul {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) (x : S) : eval₂ f x (X * p) = eval₂ f x p * x := eq.mpr (id (Eq._oldrec (Eq.refl (eval₂ f x (X * p) = eval₂ f x p * x)) X_mul)) (eq.mpr (id (Eq._oldrec (Eq.refl (eval₂ f x (p * X) = eval₂ f x p * x)) (eval₂_mul_X f x))) (Eq.refl (eval₂ f x p * x))) theorem eval₂_mul_C' {R : Type u} {S : Type v} {a : R} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) (x : S) (h : commute (coe_fn f a) x) : eval₂ f x (p * coe_fn C a) = eval₂ f x p * coe_fn f a := sorry theorem eval₂_list_prod_noncomm {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (x : S) (ps : List (polynomial R)) (hf : ∀ (p : polynomial R), p ∈ ps → ∀ (k : ℕ), commute (coe_fn f (coeff p k)) x) : eval₂ f x (list.prod ps) = list.prod (list.map (eval₂ f x) ps) := sorry /-- `eval₂` as a `ring_hom` for noncommutative rings -/ def eval₂_ring_hom' {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (x : S) (hf : ∀ (a : R), commute (coe_fn f a) x) : polynomial R →+* S := ring_hom.mk (eval₂ f x) (eval₂_one f x) sorry (eval₂_zero f x) sorry /-! We next prove that eval₂ is multiplicative as long as target ring is commutative (even if the source ring is not). -/ @[simp] theorem eval₂_mul {R : Type u} {S : Type v} [semiring R] {p : polynomial R} {q : polynomial R} [comm_semiring S] (f : R →+* S) (x : S) : eval₂ f x (p * q) = eval₂ f x p * eval₂ f x q := eval₂_mul_noncomm f x fun (k : ℕ) => commute.all (coe_fn f (coeff q k)) x theorem eval₂_mul_eq_zero_of_left {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [comm_semiring S] (f : R →+* S) (x : S) (q : polynomial R) (hp : eval₂ f x p = 0) : eval₂ f x (p * q) = 0 := eq.mpr (id (Eq._oldrec (Eq.refl (eval₂ f x (p * q) = 0)) (eval₂_mul f x))) (mul_eq_zero_of_left hp (eval₂ f x q)) theorem eval₂_mul_eq_zero_of_right {R : Type u} {S : Type v} [semiring R] {q : polynomial R} [comm_semiring S] (f : R →+* S) (x : S) (p : polynomial R) (hq : eval₂ f x q = 0) : eval₂ f x (p * q) = 0 := eq.mpr (id (Eq._oldrec (Eq.refl (eval₂ f x (p * q) = 0)) (eval₂_mul f x))) (mul_eq_zero_of_right (eval₂ f x p) hq) protected instance eval₂.is_semiring_hom {R : Type u} {S : Type v} [semiring R] [comm_semiring S] (f : R →+* S) (x : S) : is_semiring_hom (eval₂ f x) := is_semiring_hom.mk (eval₂_zero f x) (eval₂_one f x) (fun (_x _x_1 : polynomial R) => eval₂_add f x) fun (_x _x_1 : polynomial R) => eval₂_mul f x /-- `eval₂` as a `ring_hom` -/ def eval₂_ring_hom {R : Type u} {S : Type v} [semiring R] [comm_semiring S] (f : R →+* S) (x : S) : polynomial R →+* S := ring_hom.of (eval₂ f x) @[simp] theorem coe_eval₂_ring_hom {R : Type u} {S : Type v} [semiring R] [comm_semiring S] (f : R →+* S) (x : S) : ⇑(eval₂_ring_hom f x) = eval₂ f x := rfl theorem eval₂_pow {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [comm_semiring S] (f : R →+* S) (x : S) (n : ℕ) : eval₂ f x (p ^ n) = eval₂ f x p ^ n := ring_hom.map_pow (eval₂_ring_hom f x) p n theorem eval₂_eq_sum_range {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [comm_semiring S] (f : R →+* S) (x : S) : eval₂ f x p = finset.sum (finset.range (nat_degree p + 1)) fun (i : ℕ) => coe_fn f (coeff p i) * x ^ i := sorry theorem eval₂_eq_sum_range' {R : Type u} {S : Type v} [semiring R] [comm_semiring S] (f : R →+* S) {p : polynomial R} {n : ℕ} (hn : nat_degree p < n) (x : S) : eval₂ f x p = finset.sum (finset.range n) fun (i : ℕ) => coe_fn f (coeff p i) * x ^ i := sorry /-- `eval x p` is the evaluation of the polynomial `p` at `x` -/ def eval {R : Type u} [semiring R] : R → polynomial R → R := eval₂ (ring_hom.id R) theorem eval_eq_sum {R : Type u} [semiring R] {p : polynomial R} {x : R} : eval x p = finsupp.sum p fun (e : ℕ) (a : R) => a * x ^ e := rfl @[simp] theorem eval_C {R : Type u} {a : R} [semiring R] {x : R} : eval x (coe_fn C a) = a := eval₂_C (ring_hom.id R) x @[simp] theorem eval_nat_cast {R : Type u} [semiring R] {x : R} {n : ℕ} : eval x ↑n = ↑n := sorry @[simp] theorem eval_X {R : Type u} [semiring R] {x : R} : eval x X = x := eval₂_X (ring_hom.id R) x @[simp] theorem eval_monomial {R : Type u} [semiring R] {x : R} {n : ℕ} {a : R} : eval x (coe_fn (monomial n) a) = a * x ^ n := eval₂_monomial (ring_hom.id R) x @[simp] theorem eval_zero {R : Type u} [semiring R] {x : R} : eval x 0 = 0 := eval₂_zero (ring_hom.id R) x @[simp] theorem eval_add {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} {x : R} : eval x (p + q) = eval x p + eval x q := eval₂_add (ring_hom.id R) x @[simp] theorem eval_one {R : Type u} [semiring R] {x : R} : eval x 1 = 1 := eval₂_one (ring_hom.id R) x @[simp] theorem eval_bit0 {R : Type u} [semiring R] {p : polynomial R} {x : R} : eval x (bit0 p) = bit0 (eval x p) := eval₂_bit0 (ring_hom.id R) x @[simp] theorem eval_bit1 {R : Type u} [semiring R] {p : polynomial R} {x : R} : eval x (bit1 p) = bit1 (eval x p) := eval₂_bit1 (ring_hom.id R) x @[simp] theorem eval_smul {R : Type u} [semiring R] (p : polynomial R) (x : R) {s : R} : eval x (s • p) = s • eval x p := eval₂_smul (ring_hom.id R) p x theorem eval_sum {R : Type u} [semiring R] (p : polynomial R) (f : ℕ → R → polynomial R) (x : R) : eval x (finsupp.sum p f) = finsupp.sum p fun (n : ℕ) (a : R) => eval x (f n a) := eval₂_sum (ring_hom.id R) p f x theorem eval_finset_sum {R : Type u} {ι : Type y} [semiring R] (s : finset ι) (g : ι → polynomial R) (x : R) : eval x (finset.sum s fun (i : ι) => g i) = finset.sum s fun (i : ι) => eval x (g i) := eval₂_finset_sum (ring_hom.id R) s (fun (i : ι) => g i) x /-- `is_root p x` implies `x` is a root of `p`. The evaluation of `p` at `x` is zero -/ def is_root {R : Type u} [semiring R] (p : polynomial R) (a : R) := eval a p = 0 protected instance is_root.decidable {R : Type u} {a : R} [semiring R] {p : polynomial R} [DecidableEq R] : Decidable (is_root p a) := eq.mpr sorry (_inst_2 (eval a p) 0) @[simp] theorem is_root.def {R : Type u} {a : R} [semiring R] {p : polynomial R} : is_root p a ↔ eval a p = 0 := iff.rfl theorem coeff_zero_eq_eval_zero {R : Type u} [semiring R] (p : polynomial R) : coeff p 0 = eval 0 p := sorry theorem zero_is_root_of_coeff_zero_eq_zero {R : Type u} [semiring R] {p : polynomial R} (hp : coeff p 0 = 0) : is_root p 0 := eq.mp (Eq._oldrec (Eq.refl (coeff p 0 = 0)) (coeff_zero_eq_eval_zero p)) hp /-- The composition of polynomials as a polynomial. -/ def comp {R : Type u} [semiring R] (p : polynomial R) (q : polynomial R) : polynomial R := eval₂ C q p theorem comp_eq_sum_left {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} : comp p q = finsupp.sum p fun (e : ℕ) (a : R) => coe_fn C a * q ^ e := rfl @[simp] theorem comp_X {R : Type u} [semiring R] {p : polynomial R} : comp p X = p := sorry @[simp] theorem X_comp {R : Type u} [semiring R] {p : polynomial R} : comp X p = p := eval₂_X C p @[simp] theorem comp_C {R : Type u} {a : R} [semiring R] {p : polynomial R} : comp p (coe_fn C a) = coe_fn C (eval a p) := sorry @[simp] theorem C_comp {R : Type u} {a : R} [semiring R] {p : polynomial R} : comp (coe_fn C a) p = coe_fn C a := eval₂_C C p @[simp] theorem comp_zero {R : Type u} [semiring R] {p : polynomial R} : comp p 0 = coe_fn C (eval 0 p) := eq.mpr (id (Eq._oldrec (Eq.refl (comp p 0 = coe_fn C (eval 0 p))) (Eq.symm C_0))) (eq.mpr (id (Eq._oldrec (Eq.refl (comp p (coe_fn C 0) = coe_fn C (eval 0 p))) comp_C)) (Eq.refl (coe_fn C (eval 0 p)))) @[simp] theorem zero_comp {R : Type u} [semiring R] {p : polynomial R} : comp 0 p = 0 := eq.mpr (id (Eq._oldrec (Eq.refl (comp 0 p = 0)) (Eq.symm C_0))) (eq.mpr (id (Eq._oldrec (Eq.refl (comp (coe_fn C 0) p = coe_fn C 0)) C_comp)) (Eq.refl (coe_fn C 0))) @[simp] theorem comp_one {R : Type u} [semiring R] {p : polynomial R} : comp p 1 = coe_fn C (eval 1 p) := eq.mpr (id (Eq._oldrec (Eq.refl (comp p 1 = coe_fn C (eval 1 p))) (Eq.symm C_1))) (eq.mpr (id (Eq._oldrec (Eq.refl (comp p (coe_fn C 1) = coe_fn C (eval 1 p))) comp_C)) (Eq.refl (coe_fn C (eval 1 p)))) @[simp] theorem one_comp {R : Type u} [semiring R] {p : polynomial R} : comp 1 p = 1 := eq.mpr (id (Eq._oldrec (Eq.refl (comp 1 p = 1)) (Eq.symm C_1))) (eq.mpr (id (Eq._oldrec (Eq.refl (comp (coe_fn C 1) p = coe_fn C 1)) C_comp)) (Eq.refl (coe_fn C 1))) @[simp] theorem add_comp {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} {r : polynomial R} : comp (p + q) r = comp p r + comp q r := eval₂_add C r @[simp] theorem mul_comp {R : Type u_1} [comm_semiring R] (p : polynomial R) (q : polynomial R) (r : polynomial R) : comp (p * q) r = comp p r * comp q r := eval₂_mul C r @[simp] theorem bit0_comp {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} : comp (bit0 p) q = bit0 (comp p q) := sorry @[simp] theorem bit1_comp {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} : comp (bit1 p) q = bit1 (comp p q) := sorry theorem comp_assoc {R : Type u_1} [comm_semiring R] (φ : polynomial R) (ψ : polynomial R) (χ : polynomial R) : comp (comp φ ψ) χ = comp φ (comp ψ χ) := sorry /-- `map f p` maps a polynomial `p` across a ring hom `f` -/ def map {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) : polynomial R → polynomial S := eval₂ (ring_hom.comp C f) X protected instance is_semiring_hom_C_f {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) : is_semiring_hom (⇑C ∘ ⇑f) := is_semiring_hom.comp ⇑f ⇑C @[simp] theorem map_C {R : Type u} {S : Type v} {a : R} [semiring R] [semiring S] (f : R →+* S) : map f (coe_fn C a) = coe_fn C (coe_fn f a) := eval₂_C (ring_hom.comp C f) X @[simp] theorem map_X {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) : map f X = X := eval₂_X (ring_hom.comp C f) X @[simp] theorem map_monomial {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) {n : ℕ} {a : R} : map f (coe_fn (monomial n) a) = coe_fn (monomial n) (coe_fn f a) := sorry @[simp] theorem map_zero {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) : map f 0 = 0 := eval₂_zero (ring_hom.comp C f) X @[simp] theorem map_add {R : Type u} {S : Type v} [semiring R] {p : polynomial R} {q : polynomial R} [semiring S] (f : R →+* S) : map f (p + q) = map f p + map f q := eval₂_add (ring_hom.comp C f) X @[simp] theorem map_one {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) : map f 1 = 1 := eval₂_one (ring_hom.comp C f) X @[simp] theorem map_nat_cast {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (n : ℕ) : map f ↑n = ↑n := sorry @[simp] theorem coeff_map {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) (n : ℕ) : coeff (map f p) n = coe_fn f (coeff p n) := sorry theorem map_map {R : Type u} {S : Type v} {T : Type w} [semiring R] [semiring S] (f : R →+* S) [semiring T] (g : S →+* T) (p : polynomial R) : map g (map f p) = map (ring_hom.comp g f) p := sorry @[simp] theorem map_id {R : Type u} [semiring R] {p : polynomial R} : map (ring_hom.id R) p = p := sorry theorem eval₂_eq_eval_map {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) {x : S} : eval₂ f x p = eval x (map f p) := sorry theorem map_injective {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (hf : function.injective ⇑f) : function.injective (map f) := sorry theorem map_surjective {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (hf : function.surjective ⇑f) : function.surjective (map f) := sorry theorem map_monic_eq_zero_iff {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] {f : R →+* S} (hp : monic p) : map f p = 0 ↔ ∀ (x : R), coe_fn f x = 0 := sorry theorem map_monic_ne_zero {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] {f : R →+* S} (hp : monic p) [nontrivial S] : map f p ≠ 0 := fun (h : map f p = 0) => ring_hom.map_one_ne_zero f (iff.mp (map_monic_eq_zero_iff hp) h 1) -- If the rings were commutative, we could prove this just using `eval₂_mul`. -- TODO this proof is just a hack job on the proof of `eval₂_mul`, -- using that `X` is central. It should probably be golfed! @[simp] theorem map_mul {R : Type u} {S : Type v} [semiring R] {p : polynomial R} {q : polynomial R} [semiring S] (f : R →+* S) : map f (p * q) = map f p * map f q := sorry protected instance map.is_semiring_hom {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) : is_semiring_hom (map f) := is_semiring_hom.mk (eval₂_zero (ring_hom.comp C f) X) (eval₂_one (ring_hom.comp C f) X) (fun (_x _x_1 : polynomial R) => eval₂_add (ring_hom.comp C f) X) fun (_x _x_1 : polynomial R) => map_mul f /-- `polynomial.map` as a `ring_hom` -/ def map_ring_hom {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) : polynomial R →+* polynomial S := ring_hom.mk (map f) sorry sorry sorry sorry @[simp] theorem coe_map_ring_hom {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) : ⇑(map_ring_hom f) = map f := rfl theorem map_list_prod {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) (L : List (polynomial R)) : map f (list.prod L) = list.prod (list.map (map f) L) := Eq.symm (list.prod_hom L (monoid_hom.of (map f))) @[simp] theorem map_pow {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) (n : ℕ) : map f (p ^ n) = map f p ^ n := is_monoid_hom.map_pow (map f) p n theorem mem_map_range {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) {p : polynomial S} : p ∈ set.range (map f) ↔ ∀ (n : ℕ), coeff p n ∈ set.range ⇑f := sorry theorem eval₂_map {R : Type u} {S : Type v} {T : Type w} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) [semiring T] (g : S →+* T) (x : T) : eval₂ g x (map f p) = eval₂ (ring_hom.comp g f) x p := sorry theorem eval_map {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) (x : S) : eval x (map f p) = eval₂ f x p := eval₂_map f (ring_hom.id S) x theorem map_sum {R : Type u} {S : Type v} [semiring R] [semiring S] (f : R →+* S) {ι : Type u_1} (g : ι → polynomial R) (s : finset ι) : map f (finset.sum s fun (i : ι) => g i) = finset.sum s fun (i : ι) => map f (g i) := Eq.symm (finset.sum_hom s (map f)) /-! After having set up the basic theory of `eval₂`, `eval`, `comp`, and `map`, we make `eval₂` irreducible. Perhaps we can make the others irreducible too? -/ -- TODO: Here we need commutativity in both `S` and `T`? theorem hom_eval₂ {R : Type u} {S : Type v} {T : Type w} [semiring R] (p : polynomial R) [comm_semiring S] [comm_semiring T] (f : R →+* S) (g : S →+* T) (x : S) : coe_fn g (eval₂ f x p) = eval₂ (ring_hom.comp g f) (coe_fn g x) p := sorry @[simp] theorem eval_mul {R : Type u} [comm_semiring R] {p : polynomial R} {q : polynomial R} {x : R} : eval x (p * q) = eval x p * eval x q := eval₂_mul (ring_hom.id R) x protected instance eval.is_semiring_hom {R : Type u} [comm_semiring R] {x : R} : is_semiring_hom (eval x) := eval₂.is_semiring_hom (ring_hom.id R) x @[simp] theorem eval_pow {R : Type u} [comm_semiring R] {p : polynomial R} {x : R} (n : ℕ) : eval x (p ^ n) = eval x p ^ n := eval₂_pow (ring_hom.id R) x n theorem eval₂_hom {R : Type u} {S : Type v} [comm_semiring R] {p : polynomial R} [comm_semiring S] (f : R →+* S) (x : R) : eval₂ f (coe_fn f x) p = coe_fn f (eval x p) := ring_hom.comp_id f ▸ Eq.symm (hom_eval₂ p (ring_hom.id R) f x) theorem root_mul_left_of_is_root {R : Type u} {a : R} [comm_semiring R] (p : polynomial R) {q : polynomial R} : is_root q a → is_root (p * q) a := sorry theorem root_mul_right_of_is_root {R : Type u} {a : R} [comm_semiring R] {p : polynomial R} (q : polynomial R) : is_root p a → is_root (p * q) a := sorry /-- Polynomial evaluation commutes with finset.prod -/ theorem eval_prod {R : Type u} [comm_semiring R] {ι : Type u_1} (s : finset ι) (p : ι → polynomial R) (x : R) : eval x (finset.prod s fun (j : ι) => p j) = finset.prod s fun (j : ι) => eval x (p j) := sorry theorem map_multiset_prod {R : Type u} {S : Type v} [comm_semiring R] [comm_semiring S] (f : R →+* S) (m : multiset (polynomial R)) : map f (multiset.prod m) = multiset.prod (multiset.map (map f) m) := Eq.symm (multiset.prod_hom m (monoid_hom.of (map f))) theorem map_prod {R : Type u} {S : Type v} [comm_semiring R] [comm_semiring S] (f : R →+* S) {ι : Type u_1} (g : ι → polynomial R) (s : finset ι) : map f (finset.prod s fun (i : ι) => g i) = finset.prod s fun (i : ι) => map f (g i) := Eq.symm (finset.prod_hom s (map f)) theorem support_map_subset {R : Type u} {S : Type v} [comm_semiring R] [comm_semiring S] (f : R →+* S) (p : polynomial R) : finsupp.support (map f p) ⊆ finsupp.support p := sorry theorem map_comp {R : Type u} {S : Type v} [comm_semiring R] [comm_semiring S] (f : R →+* S) (p : polynomial R) (q : polynomial R) : map f (comp p q) = comp (map f p) (map f q) := sorry -- @[simp] -- lemma C_eq_int_cast (n : ℤ) : C ↑n = (n : polynomial R) := -- (C : R →+* _).map_int_cast n theorem C_neg {R : Type u} {a : R} [ring R] : coe_fn C (-a) = -coe_fn C a := ring_hom.map_neg C a theorem C_sub {R : Type u} {a : R} {b : R} [ring R] : coe_fn C (a - b) = coe_fn C a - coe_fn C b := ring_hom.map_sub C a b protected instance map.is_ring_hom {R : Type u} [ring R] {S : Type u_1} [ring S] (f : R →+* S) : is_ring_hom (map f) := is_ring_hom.of_semiring (map f) @[simp] theorem map_sub {R : Type u} [ring R] {p : polynomial R} {q : polynomial R} {S : Type u_1} [ring S] (f : R →+* S) : map f (p - q) = map f p - map f q := is_ring_hom.map_sub (map f) @[simp] theorem map_neg {R : Type u} [ring R] {p : polynomial R} {S : Type u_1} [ring S] (f : R →+* S) : map f (-p) = -map f p := is_ring_hom.map_neg (map f) @[simp] theorem map_int_cast {R : Type u} [ring R] {S : Type u_1} [ring S] (f : R →+* S) (n : ℤ) : map f ↑n = ↑n := ring_hom.map_int_cast (ring_hom.of (map f)) n @[simp] theorem eval_int_cast {R : Type u} [ring R] {n : ℤ} {x : R} : eval x ↑n = ↑n := sorry @[simp] theorem eval₂_neg {R : Type u} [ring R] {p : polynomial R} {S : Type u_1} [ring S] (f : R →+* S) {x : S} : eval₂ f x (-p) = -eval₂ f x p := sorry @[simp] theorem eval₂_sub {R : Type u} [ring R] {p : polynomial R} {q : polynomial R} {S : Type u_1} [ring S] (f : R →+* S) {x : S} : eval₂ f x (p - q) = eval₂ f x p - eval₂ f x q := sorry @[simp] theorem eval_neg {R : Type u} [ring R] (p : polynomial R) (x : R) : eval x (-p) = -eval x p := eval₂_neg (ring_hom.id R) @[simp] theorem eval_sub {R : Type u} [ring R] (p : polynomial R) (q : polynomial R) (x : R) : eval x (p - q) = eval x p - eval x q := eval₂_sub (ring_hom.id R) theorem root_X_sub_C {R : Type u} {a : R} {b : R} [ring R] : is_root (X - coe_fn C a) b ↔ a = b := sorry @[simp] theorem neg_comp {R : Type u} [ring R] {p : polynomial R} {q : polynomial R} : comp (-p) q = -comp p q := eval₂_neg C @[simp] theorem sub_comp {R : Type u} [ring R] {p : polynomial R} {q : polynomial R} {r : polynomial R} : comp (p - q) r = comp p r - comp q r := eval₂_sub C protected instance eval₂.is_ring_hom {R : Type u} [comm_ring R] {S : Type u_1} [comm_ring S] (f : R →+* S) {x : S} : is_ring_hom (eval₂ f x) := is_ring_hom.of_semiring (eval₂ f x) protected instance eval.is_ring_hom {R : Type u} [comm_ring R] {x : R} : is_ring_hom (eval x) := eval₂.is_ring_hom (ring_hom.id R) end Mathlib
dcd0c48395f3942ad041a687a7663a7677f0d46d
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/control/equiv_functor.lean
210dcf001636ec9deec882fa409f78282f93c657
[]
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
3,973
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Scott Morrison -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.category_theory.category.default import Mathlib.data.equiv.functor import Mathlib.PostPort universes u₀ u₁ l namespace Mathlib /-! # Functions functorial with respect to equivalences An `equiv_functor` is a function from `Type → Type` equipped with the additional data of coherently mapping equivalences to equivalences. In categorical language, it is an endofunctor of the "core" of the category `Type`. -/ /-- An `equiv_functor` is only functorial with respect to equivalences. To construct an `equiv_functor`, it suffices to supply just the function `f α → f β` from an equivalence `α ≃ β`, and then prove the functor laws. It's then a consequence that this function is part of an equivalence, provided by `equiv_functor.map_equiv`. -/ class equiv_functor (f : Type u₀ → Type u₁) where map : {α β : Type u₀} → α ≃ β → f α → f β map_refl' : autoParam (∀ (α : Type u₀), map (equiv.refl α) = id) (Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.obviously") (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "obviously") []) map_trans' : autoParam (∀ {α β γ : Type u₀} (k : α ≃ β) (h : β ≃ γ), map (equiv.trans k h) = map h ∘ map k) (Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.obviously") (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "obviously") []) @[simp] theorem equiv_functor.map_refl {f : Type u₀ → Type u₁} [c : equiv_functor f] (α : Type u₀) : equiv_functor.map (equiv.refl α) = id := sorry theorem equiv_functor.map_trans {f : Type u₀ → Type u₁} [c : equiv_functor f] {α : Type u₀} {β : Type u₀} {γ : Type u₀} (k : α ≃ β) (h : β ≃ γ) : equiv_functor.map (equiv.trans k h) = equiv_functor.map h ∘ equiv_functor.map k := sorry namespace equiv_functor /-- An `equiv_functor` in fact takes every equiv to an equiv. -/ def map_equiv (f : Type u₀ → Type u₁) [equiv_functor f] {α : Type u₀} {β : Type u₀} (e : α ≃ β) : f α ≃ f β := equiv.mk (map e) (map (equiv.symm e)) sorry sorry @[simp] theorem map_equiv_apply (f : Type u₀ → Type u₁) [equiv_functor f] {α : Type u₀} {β : Type u₀} (e : α ≃ β) (x : f α) : coe_fn (map_equiv f e) x = map e x := rfl theorem map_equiv_symm_apply (f : Type u₀ → Type u₁) [equiv_functor f] {α : Type u₀} {β : Type u₀} (e : α ≃ β) (y : f β) : coe_fn (equiv.symm (map_equiv f e)) y = map (equiv.symm e) y := rfl @[simp] theorem map_equiv_refl (f : Type u₀ → Type u₁) [equiv_functor f] (α : Type u₀) : map_equiv f (equiv.refl α) = equiv.refl (f α) := sorry @[simp] theorem map_equiv_symm (f : Type u₀ → Type u₁) [equiv_functor f] {α : Type u₀} {β : Type u₀} (e : α ≃ β) : equiv.symm (map_equiv f e) = map_equiv f (equiv.symm e) := equiv.ext (map_equiv_symm_apply f e) /-- The composition of `map_equiv`s is carried over the `equiv_functor`. For plain `functor`s, this lemma is named `map_map` when applied or `map_comp_map` when not applied. -/ @[simp] theorem map_equiv_trans (f : Type u₀ → Type u₁) [equiv_functor f] {α : Type u₀} {β : Type u₀} {γ : Type u₀} (ab : α ≃ β) (bc : β ≃ γ) : equiv.trans (map_equiv f ab) (map_equiv f bc) = map_equiv f (equiv.trans ab bc) := sorry protected instance of_is_lawful_functor (f : Type u₀ → Type u₁) [Functor f] [is_lawful_functor f] : equiv_functor f := mk fun (α β : Type u₀) (e : α ≃ β) => Functor.map ⇑e theorem map_equiv.injective (f : Type u₀ → Type u₁) [Applicative f] [is_lawful_applicative f] {α : Type u₀} {β : Type u₀} (h : Type u₀ → function.injective pure) : function.injective (map_equiv f) := sorry
12f4344fc76053872fedeaab291cf5ef32805119
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/order/bounded_lattice.lean
aec38f433cb30c85dc03737931f9ff07da6f11f0
[ "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
27,257
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 Defines bounded lattice type class hierarchy. Includes the Prop and fun instances. -/ import order.lattice data.option.basic tactic.pi_instances set_option old_structure_cmd true universes u v namespace lattice variable {α : Type u} /-- Typeclass for the `⊤` (`\top`) notation -/ class has_top (α : Type u) := (top : α) /-- Typeclass for the `⊥` (`\bot`) notation -/ class has_bot (α : Type u) := (bot : α) notation `⊤` := has_top.top _ notation `⊥` := has_bot.bot _ /-- An `order_top` is a partial order with a maximal element. (We could state this on preorders, but then it wouldn't be unique so distinguishing one would seem odd.) -/ class order_top (α : Type u) extends has_top α, partial_order α := (le_top : ∀ a : α, a ≤ ⊤) section order_top variables [order_top α] {a b : α} @[simp] theorem le_top : a ≤ ⊤ := order_top.le_top a theorem top_unique (h : ⊤ ≤ a) : a = ⊤ := le_antisymm le_top h -- TODO: delete in favor of the next? theorem eq_top_iff : a = ⊤ ↔ ⊤ ≤ a := ⟨assume eq, eq.symm ▸ le_refl ⊤, top_unique⟩ @[simp] theorem top_le_iff : ⊤ ≤ a ↔ a = ⊤ := ⟨top_unique, λ h, h.symm ▸ le_refl ⊤⟩ @[simp] theorem not_top_lt : ¬ ⊤ < a := assume h, lt_irrefl a (lt_of_le_of_lt le_top h) theorem eq_top_mono (h : a ≤ b) (h₂ : a = ⊤) : b = ⊤ := top_le_iff.1 $ h₂ ▸ h lemma lt_top_iff_ne_top : a < ⊤ ↔ a ≠ ⊤ := begin haveI := classical.dec_eq α, haveI : decidable (⊤ ≤ a) := decidable_of_iff' _ top_le_iff, by simp [-top_le_iff, lt_iff_le_not_le, not_iff_not.2 (@top_le_iff _ _ a)] end lemma ne_top_of_lt (h : a < b) : a ≠ ⊤ := lt_top_iff_ne_top.1 $ lt_of_lt_of_le h le_top end order_top theorem order_top.ext_top {α} {A B : order_top α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : (by haveI := A; exact ⊤ : α) = ⊤ := top_unique $ by rw ← H; apply le_top theorem order_top.ext {α} {A B : order_top α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin haveI this := partial_order.ext H, have tt := order_top.ext_top H, cases A; cases B; injection this; congr' end /-- An `order_bot` is a partial order with a minimal element. (We could state this on preorders, but then it wouldn't be unique so distinguishing one would seem odd.) -/ class order_bot (α : Type u) extends has_bot α, partial_order α := (bot_le : ∀ a : α, ⊥ ≤ a) section order_bot variables [order_bot α] {a b : α} @[simp] theorem bot_le : ⊥ ≤ a := order_bot.bot_le a theorem bot_unique (h : a ≤ ⊥) : a = ⊥ := le_antisymm h bot_le -- TODO: delete? theorem eq_bot_iff : a = ⊥ ↔ a ≤ ⊥ := ⟨assume eq, eq.symm ▸ le_refl ⊥, bot_unique⟩ @[simp] theorem le_bot_iff : a ≤ ⊥ ↔ a = ⊥ := ⟨bot_unique, assume h, h.symm ▸ le_refl ⊥⟩ @[simp] theorem not_lt_bot : ¬ a < ⊥ := assume h, lt_irrefl a (lt_of_lt_of_le h bot_le) theorem neq_bot_of_le_neq_bot {a b : α} (hb : b ≠ ⊥) (hab : b ≤ a) : a ≠ ⊥ := assume ha, hb $ bot_unique $ ha ▸ hab theorem eq_bot_mono (h : a ≤ b) (h₂ : b = ⊥) : a = ⊥ := le_bot_iff.1 $ h₂ ▸ h lemma bot_lt_iff_ne_bot : ⊥ < a ↔ a ≠ ⊥ := begin haveI := classical.dec_eq α, haveI : decidable (a ≤ ⊥) := decidable_of_iff' _ le_bot_iff, simp [-le_bot_iff, lt_iff_le_not_le, not_iff_not.2 (@le_bot_iff _ _ a)] end lemma ne_bot_of_gt (h : a < b) : b ≠ ⊥ := bot_lt_iff_ne_bot.1 $ lt_of_le_of_lt bot_le h end order_bot theorem order_bot.ext_bot {α} {A B : order_bot α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : (by haveI := A; exact ⊥ : α) = ⊥ := bot_unique $ by rw ← H; apply bot_le theorem order_bot.ext {α} {A B : order_bot α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin haveI this := partial_order.ext H, have tt := order_bot.ext_bot H, cases A; cases B; injection this; congr' end /-- A `semilattice_sup_top` is a semilattice with top and join. -/ class semilattice_sup_top (α : Type u) extends order_top α, semilattice_sup α section semilattice_sup_top variables [semilattice_sup_top α] {a : α} @[simp] theorem top_sup_eq : ⊤ ⊔ a = ⊤ := sup_of_le_left le_top @[simp] theorem sup_top_eq : a ⊔ ⊤ = ⊤ := sup_of_le_right le_top end semilattice_sup_top /-- A `semilattice_sup_bot` is a semilattice with bottom and join. -/ class semilattice_sup_bot (α : Type u) extends order_bot α, semilattice_sup α section semilattice_sup_bot variables [semilattice_sup_bot α] {a b : α} @[simp] theorem bot_sup_eq : ⊥ ⊔ a = a := sup_of_le_right bot_le @[simp] theorem sup_bot_eq : a ⊔ ⊥ = a := sup_of_le_left bot_le @[simp] theorem sup_eq_bot_iff : a ⊔ b = ⊥ ↔ (a = ⊥ ∧ b = ⊥) := by rw [eq_bot_iff, sup_le_iff]; simp end semilattice_sup_bot instance nat.semilattice_sup_bot : semilattice_sup_bot ℕ := { bot := 0, bot_le := nat.zero_le, .. nat.distrib_lattice } /-- A `semilattice_inf_top` is a semilattice with top and meet. -/ class semilattice_inf_top (α : Type u) extends order_top α, semilattice_inf α section semilattice_inf_top variables [semilattice_inf_top α] {a b : α} @[simp] theorem top_inf_eq : ⊤ ⊓ a = a := inf_of_le_right le_top @[simp] theorem inf_top_eq : a ⊓ ⊤ = a := inf_of_le_left le_top @[simp] theorem inf_eq_top_iff : a ⊓ b = ⊤ ↔ (a = ⊤ ∧ b = ⊤) := by rw [eq_top_iff, le_inf_iff]; simp end semilattice_inf_top /-- A `semilattice_inf_bot` is a semilattice with bottom and meet. -/ class semilattice_inf_bot (α : Type u) extends order_bot α, semilattice_inf α section semilattice_inf_bot variables [semilattice_inf_bot α] {a : α} @[simp] theorem bot_inf_eq : ⊥ ⊓ a = ⊥ := inf_of_le_left bot_le @[simp] theorem inf_bot_eq : a ⊓ ⊥ = ⊥ := inf_of_le_right bot_le end semilattice_inf_bot /- Bounded lattices -/ /-- A bounded lattice is a lattice with a top and bottom element, denoted `⊤` and `⊥` respectively. This allows for the interpretation of all finite suprema and infima, taking `inf ∅ = ⊤` and `sup ∅ = ⊥`. -/ class bounded_lattice (α : Type u) extends lattice α, order_top α, order_bot α instance semilattice_inf_top_of_bounded_lattice (α : Type u) [bl : bounded_lattice α] : semilattice_inf_top α := { le_top := assume x, @le_top α _ x, ..bl } instance semilattice_inf_bot_of_bounded_lattice (α : Type u) [bl : bounded_lattice α] : semilattice_inf_bot α := { bot_le := assume x, @bot_le α _ x, ..bl } instance semilattice_sup_top_of_bounded_lattice (α : Type u) [bl : bounded_lattice α] : semilattice_sup_top α := { le_top := assume x, @le_top α _ x, ..bl } instance semilattice_sup_bot_of_bounded_lattice (α : Type u) [bl : bounded_lattice α] : semilattice_sup_bot α := { bot_le := assume x, @bot_le α _ x, ..bl } theorem bounded_lattice.ext {α} {A B : bounded_lattice α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin haveI H1 : @bounded_lattice.to_lattice α A = @bounded_lattice.to_lattice α B := lattice.ext H, haveI H2 := order_bot.ext H, haveI H3 : @bounded_lattice.to_order_top α A = @bounded_lattice.to_order_top α B := order_top.ext H, have tt := order_bot.ext_bot H, cases A; cases B; injection H1; injection H2; injection H3; congr' end /-- A bounded distributive lattice is exactly what it sounds like. -/ class bounded_distrib_lattice α extends distrib_lattice α, bounded_lattice α lemma inf_eq_bot_iff_le_compl {α : Type u} [bounded_distrib_lattice α] {a b c : α} (h₁ : b ⊔ c = ⊤) (h₂ : b ⊓ c = ⊥) : a ⊓ b = ⊥ ↔ a ≤ c := ⟨assume : a ⊓ b = ⊥, calc a ≤ a ⊓ (b ⊔ c) : by simp [h₁] ... = (a ⊓ b) ⊔ (a ⊓ c) : by simp [inf_sup_left] ... ≤ c : by simp [this, inf_le_right], assume : a ≤ c, bot_unique $ calc a ⊓ b ≤ b ⊓ c : by rw [inf_comm]; exact inf_le_inf (le_refl _) this ... = ⊥ : h₂⟩ /- Prop instance -/ instance bounded_lattice_Prop : bounded_lattice Prop := { lattice.bounded_lattice . le := λa b, a → b, le_refl := assume _, id, le_trans := assume a b c f g, g ∘ f, le_antisymm := assume a b Hab Hba, propext ⟨Hab, Hba⟩, sup := or, le_sup_left := @or.inl, le_sup_right := @or.inr, sup_le := assume a b c, or.rec, inf := and, inf_le_left := @and.left, inf_le_right := @and.right, le_inf := assume a b c Hab Hac Ha, and.intro (Hab Ha) (Hac Ha), top := true, le_top := assume a Ha, true.intro, bot := false, bot_le := @false.elim } section logic variable [preorder α] theorem monotone_and {p q : α → Prop} (m_p : monotone p) (m_q : monotone q) : monotone (λx, p x ∧ q x) := assume a b h, and.imp (m_p h) (m_q h) -- Note: by finish [monotone] doesn't work theorem monotone_or {p q : α → Prop} (m_p : monotone p) (m_q : monotone q) : monotone (λx, p x ∨ q x) := assume a b h, or.imp (m_p h) (m_q h) end logic /- Function lattices -/ /- TODO: * build up the lattice hierarchy for `fun`-functor piecewise. semilattic_*, bounded_lattice, lattice ... * can this be generalized to the dependent function space? -/ instance pi.bounded_lattice {α : Type u} {β : Type v} [bounded_lattice β] : bounded_lattice (α → β) := by pi_instance end lattice def with_bot (α : Type*) := option α namespace with_bot variable {α : Type u} open lattice meta instance {α} [has_to_format α] : has_to_format (with_bot α) := { to_format := λ x, match x with | none := "⊥" | (some x) := to_fmt x end } instance : has_coe_t α (with_bot α) := ⟨some⟩ instance has_bot : has_bot (with_bot α) := ⟨none⟩ lemma none_eq_bot : (none : with_bot α) = (⊥ : with_bot α) := rfl lemma some_eq_coe (a : α) : (some a : with_bot α) = (↑a : with_bot α) := rfl theorem coe_eq_coe {a b : α} : (a : with_bot α) = b ↔ a = b := by rw [← option.some.inj_eq a b]; refl @[priority 0] instance has_lt [has_lt α] : has_lt (with_bot α) := { lt := λ o₁ o₂ : option α, ∃ b ∈ o₂, ∀ a ∈ o₁, a < b } @[simp] theorem some_lt_some [has_lt α] {a b : α} : @has_lt.lt (with_bot α) _ (some a) (some b) ↔ a < b := by simp [(<)] instance partial_order [partial_order α] : partial_order (with_bot α) := { le := λ o₁ o₂ : option α, ∀ a ∈ o₁, ∃ b ∈ o₂, a ≤ b, lt := (<), lt_iff_le_not_le := by intros; cases a; cases b; simp [lt_iff_le_not_le]; simp [(<)]; split; refl, le_refl := λ o a ha, ⟨a, ha, le_refl _⟩, le_trans := λ o₁ o₂ o₃ h₁ h₂ a ha, let ⟨b, hb, ab⟩ := h₁ a ha, ⟨c, hc, bc⟩ := h₂ b hb in ⟨c, hc, le_trans ab bc⟩, le_antisymm := λ o₁ o₂ h₁ h₂, begin cases o₁ with a, { cases o₂ with b, {refl}, rcases h₂ b rfl with ⟨_, ⟨⟩, _⟩ }, { rcases h₁ a rfl with ⟨b, ⟨⟩, h₁'⟩, rcases h₂ b rfl with ⟨_, ⟨⟩, h₂'⟩, rw le_antisymm h₁' h₂' } end } instance order_bot [partial_order α] : order_bot (with_bot α) := { bot_le := λ a a' h, option.no_confusion h, ..with_bot.partial_order, ..with_bot.has_bot } @[simp] theorem coe_le_coe [partial_order α] {a b : α} : (a : with_bot α) ≤ b ↔ a ≤ b := ⟨λ h, by rcases h a rfl with ⟨_, ⟨⟩, h⟩; exact h, λ h a' e, option.some_inj.1 e ▸ ⟨b, rfl, h⟩⟩ @[simp] theorem some_le_some [partial_order α] {a b : α} : @has_le.le (with_bot α) _ (some a) (some b) ↔ a ≤ b := coe_le_coe theorem coe_le [partial_order α] {a b : α} : ∀ {o : option α}, b ∈ o → ((a : with_bot α) ≤ o ↔ a ≤ b) | _ rfl := coe_le_coe lemma coe_lt_coe [partial_order α] {a b : α} : (a : with_bot α) < b ↔ a < b := some_lt_some lemma bot_lt_some [partial_order α] (a : α) : (⊥ : with_bot α) < some a := lt_of_le_of_ne bot_le (λ h, option.no_confusion h) lemma bot_lt_coe [partial_order α] (a : α) : (⊥ : with_bot α) < a := bot_lt_some a instance linear_order [linear_order α] : linear_order (with_bot α) := { le_total := λ o₁ o₂, begin cases o₁ with a, {exact or.inl bot_le}, cases o₂ with b, {exact or.inr bot_le}, simp [le_total] end, ..with_bot.partial_order } instance decidable_lt [has_lt α] [@decidable_rel α (<)] : @decidable_rel (with_bot α) (<) | none (some x) := is_true $ by existsi [x,rfl]; rintros _ ⟨⟩ | (some x) (some y) := if h : x < y then is_true $ by simp * else is_false $ by simp * | x none := is_false $ by rintro ⟨a,⟨⟨⟩⟩⟩ instance decidable_linear_order [decidable_linear_order α] : decidable_linear_order (with_bot α) := { decidable_le := λ a b, begin cases a with a, { exact is_true bot_le }, cases b with b, { exact is_false (mt (le_antisymm bot_le) (by simp)) }, { exact decidable_of_iff _ some_le_some } end, ..with_bot.linear_order } instance semilattice_sup [semilattice_sup α] : semilattice_sup_bot (with_bot α) := { sup := option.lift_or_get (⊔), le_sup_left := λ o₁ o₂ a ha, by cases ha; cases o₂; simp [option.lift_or_get], le_sup_right := λ o₁ o₂ a ha, by cases ha; cases o₁; simp [option.lift_or_get], sup_le := λ o₁ o₂ o₃ h₁ h₂ a ha, begin cases o₁ with b; cases o₂ with c; cases ha, { exact h₂ a rfl }, { exact h₁ a rfl }, { rcases h₁ b rfl with ⟨d, ⟨⟩, h₁'⟩, simp at h₂, exact ⟨d, rfl, sup_le h₁' h₂⟩ } end, ..with_bot.order_bot } instance semilattice_inf [semilattice_inf α] : semilattice_inf_bot (with_bot α) := { inf := λ o₁ o₂, o₁.bind (λ a, o₂.map (λ b, a ⊓ b)), inf_le_left := λ o₁ o₂ a ha, begin simp at ha, rcases ha with ⟨b, rfl, c, rfl, rfl⟩, exact ⟨_, rfl, inf_le_left⟩ end, inf_le_right := λ o₁ o₂ a ha, begin simp at ha, rcases ha with ⟨b, rfl, c, rfl, rfl⟩, exact ⟨_, rfl, inf_le_right⟩ end, le_inf := λ o₁ o₂ o₃ h₁ h₂ a ha, begin cases ha, rcases h₁ a rfl with ⟨b, ⟨⟩, ab⟩, rcases h₂ a rfl with ⟨c, ⟨⟩, ac⟩, exact ⟨_, rfl, le_inf ab ac⟩ end, ..with_bot.order_bot } instance lattice [lattice α] : lattice (with_bot α) := { ..with_bot.semilattice_sup, ..with_bot.semilattice_inf } theorem lattice_eq_DLO [decidable_linear_order α] : lattice.lattice_of_decidable_linear_order = @with_bot.lattice α _ := lattice.ext $ λ x y, iff.rfl theorem sup_eq_max [decidable_linear_order α] (x y : with_bot α) : x ⊔ y = max x y := by rw [← sup_eq_max, lattice_eq_DLO] theorem inf_eq_min [decidable_linear_order α] (x y : with_bot α) : x ⊓ y = min x y := by rw [← inf_eq_min, lattice_eq_DLO] instance order_top [order_top α] : order_top (with_bot α) := { top := some ⊤, le_top := λ o a ha, by cases ha; exact ⟨_, rfl, le_top⟩, ..with_bot.partial_order } instance bounded_lattice [bounded_lattice α] : bounded_lattice (with_bot α) := { ..with_bot.lattice, ..with_bot.order_top, ..with_bot.order_bot } lemma well_founded_lt [partial_order α] (h : well_founded ((<) : α → α → Prop)) : well_founded ((<) : with_bot α → with_bot α → Prop) := have acc_bot : acc ((<) : with_bot α → with_bot α → Prop) ⊥ := acc.intro _ (λ a ha, (not_le_of_gt ha bot_le).elim), ⟨λ a, option.rec_on a acc_bot (λ a, acc.intro _ (λ b, option.rec_on b (λ _, acc_bot) (λ b, well_founded.induction h b (show ∀ b : α, (∀ c, c < b → (c : with_bot α) < a → acc ((<) : with_bot α → with_bot α → Prop) c) → (b : with_bot α) < a → acc ((<) : with_bot α → with_bot α → Prop) b, from λ b ih hba, acc.intro _ (λ c, option.rec_on c (λ _, acc_bot) (λ c hc, ih _ (some_lt_some.1 hc) (lt_trans hc hba)))))))⟩ instance densely_ordered [partial_order α] [densely_ordered α] [no_bot_order α] : densely_ordered (with_bot α) := ⟨ assume a b, match a, b with | a, none := assume h : a < ⊥, (not_lt_bot h).elim | none, some b := assume h, let ⟨a, ha⟩ := no_bot b in ⟨a, bot_lt_coe a, coe_lt_coe.2 ha⟩ | some a, some b := assume h, let ⟨a, ha₁, ha₂⟩ := dense (coe_lt_coe.1 h) in ⟨a, coe_lt_coe.2 ha₁, coe_lt_coe.2 ha₂⟩ end⟩ end with_bot --TODO(Mario): Construct using order dual on with_bot def with_top (α : Type*) := option α namespace with_top variable {α : Type u} open lattice meta instance {α} [has_to_format α] : has_to_format (with_top α) := { to_format := λ x, match x with | none := "⊤" | (some x) := to_fmt x end } instance : has_coe_t α (with_top α) := ⟨some⟩ instance has_top : has_top (with_top α) := ⟨none⟩ lemma none_eq_top : (none : with_top α) = (⊤ : with_top α) := rfl lemma some_eq_coe (a : α) : (some a : with_top α) = (↑a : with_top α) := rfl theorem coe_eq_coe {a b : α} : (a : with_top α) = b ↔ a = b := by rw [← option.some.inj_eq a b]; refl @[simp] theorem top_ne_coe [partial_order α] {a : α} : ⊤ ≠ (a : with_top α) . @[simp] theorem coe_ne_top [partial_order α] {a : α} : (a : with_top α) ≠ ⊤ . instance partial_order [partial_order α] : partial_order (with_top α) := { le := λ o₁ o₂ : option α, ∀ b ∈ o₂, ∃ a ∈ o₁, a ≤ b, le_refl := λ o a ha, ⟨a, ha, le_refl _⟩, le_trans := λ o₁ o₂ o₃ h₁ h₂ c hc, let ⟨b, hb, bc⟩ := h₂ c hc, ⟨a, ha, ab⟩ := h₁ b hb in ⟨a, ha, le_trans ab bc⟩, le_antisymm := λ o₁ o₂ h₁ h₂, begin cases o₂ with b, { cases o₁ with a, {refl}, rcases h₂ a rfl with ⟨_, ⟨⟩, _⟩ }, { rcases h₁ b rfl with ⟨a, ⟨⟩, h₁'⟩, rcases h₂ a rfl with ⟨_, ⟨⟩, h₂'⟩, rw le_antisymm h₁' h₂' } end } instance order_top [partial_order α] : order_top (with_top α) := { le_top := λ a a' h, option.no_confusion h, ..with_top.partial_order, .. with_top.has_top } @[simp] theorem coe_le_coe [partial_order α] {a b : α} : (a : with_top α) ≤ b ↔ a ≤ b := ⟨λ h, by rcases h b rfl with ⟨_, ⟨⟩, h⟩; exact h, λ h a' e, option.some_inj.1 e ▸ ⟨a, rfl, h⟩⟩ @[simp] theorem some_le_some [partial_order α] {a b : α} : @has_le.le (with_top α) _ (some a) (some b) ↔ a ≤ b := coe_le_coe theorem le_coe [partial_order α] {a b : α} : ∀ {o : option α}, a ∈ o → (@has_le.le (with_top α) _ o b ↔ a ≤ b) | _ rfl := coe_le_coe theorem le_coe_iff [partial_order α] (b : α) : ∀(x : with_top α), x ≤ b ↔ (∃a:α, x = a ∧ a ≤ b) | (some a) := by simp [some_eq_coe, coe_eq_coe] | none := by simp [none_eq_top] theorem coe_le_iff [partial_order α] (a : α) : ∀(x : with_top α), ↑a ≤ x ↔ (∀b:α, x = ↑b → a ≤ b) | (some b) := by simp [some_eq_coe, coe_eq_coe] | none := by simp [none_eq_top] theorem lt_iff_exists_coe [partial_order α] : ∀(a b : with_top α), a < b ↔ (∃p:α, a = p ∧ ↑p < b) | (some a) b := by simp [some_eq_coe, coe_eq_coe] | none b := by simp [none_eq_top] @[simp] theorem some_lt_some [partial_order α] {a b : α} : @has_lt.lt (with_top α) _ (some a) (some b) ↔ a < b := (and_congr some_le_some (not_congr some_le_some)) .trans lt_iff_le_not_le.symm lemma coe_lt_coe [partial_order α] {a b : α} : (a : with_top α) < b ↔ a < b := some_lt_some lemma coe_lt_top [partial_order α] (a : α) : (a : with_top α) < ⊤ := lt_of_le_of_ne le_top (λ h, option.no_confusion h) lemma not_top_le_coe [partial_order α] (a : α) : ¬ (⊤:with_top α) ≤ ↑a := assume h, (lt_irrefl ⊤ (lt_of_le_of_lt h (coe_lt_top a))).elim instance linear_order [linear_order α] : linear_order (with_top α) := { le_total := λ o₁ o₂, begin cases o₁ with a, {exact or.inr le_top}, cases o₂ with b, {exact or.inl le_top}, simp [le_total] end, ..with_top.partial_order } instance decidable_linear_order [decidable_linear_order α] : decidable_linear_order (with_top α) := { decidable_le := λ a b, begin cases b with b, { exact is_true le_top }, cases a with a, { exact is_false (mt (le_antisymm le_top) (by simp)) }, { exact decidable_of_iff _ some_le_some } end, ..with_top.linear_order } instance semilattice_inf [semilattice_inf α] : semilattice_inf_top (with_top α) := { inf := option.lift_or_get (⊓), inf_le_left := λ o₁ o₂ a ha, by cases ha; cases o₂; simp [option.lift_or_get], inf_le_right := λ o₁ o₂ a ha, by cases ha; cases o₁; simp [option.lift_or_get], le_inf := λ o₁ o₂ o₃ h₁ h₂ a ha, begin cases o₂ with b; cases o₃ with c; cases ha, { exact h₂ a rfl }, { exact h₁ a rfl }, { rcases h₁ b rfl with ⟨d, ⟨⟩, h₁'⟩, simp at h₂, exact ⟨d, rfl, le_inf h₁' h₂⟩ } end, ..with_top.order_top } lemma coe_inf [semilattice_inf α] (a b : α) : ((a ⊓ b : α) : with_top α) = a ⊓ b := rfl instance semilattice_sup [semilattice_sup α] : semilattice_sup_top (with_top α) := { sup := λ o₁ o₂, o₁.bind (λ a, o₂.map (λ b, a ⊔ b)), le_sup_left := λ o₁ o₂ a ha, begin simp at ha, rcases ha with ⟨b, rfl, c, rfl, rfl⟩, exact ⟨_, rfl, le_sup_left⟩ end, le_sup_right := λ o₁ o₂ a ha, begin simp at ha, rcases ha with ⟨b, rfl, c, rfl, rfl⟩, exact ⟨_, rfl, le_sup_right⟩ end, sup_le := λ o₁ o₂ o₃ h₁ h₂ a ha, begin cases ha, rcases h₁ a rfl with ⟨b, ⟨⟩, ab⟩, rcases h₂ a rfl with ⟨c, ⟨⟩, ac⟩, exact ⟨_, rfl, sup_le ab ac⟩ end, ..with_top.order_top } lemma coe_sup [semilattice_sup α] (a b : α) : ((a ⊔ b : α) : with_top α) = a ⊔ b := rfl instance lattice [lattice α] : lattice (with_top α) := { ..with_top.semilattice_sup, ..with_top.semilattice_inf } theorem lattice_eq_DLO [decidable_linear_order α] : lattice.lattice_of_decidable_linear_order = @with_top.lattice α _ := lattice.ext $ λ x y, iff.rfl theorem sup_eq_max [decidable_linear_order α] (x y : with_top α) : x ⊔ y = max x y := by rw [← sup_eq_max, lattice_eq_DLO] theorem inf_eq_min [decidable_linear_order α] (x y : with_top α) : x ⊓ y = min x y := by rw [← inf_eq_min, lattice_eq_DLO] instance order_bot [order_bot α] : order_bot (with_top α) := { bot := some ⊥, bot_le := λ o a ha, by cases ha; exact ⟨_, rfl, bot_le⟩, ..with_top.partial_order } instance bounded_lattice [bounded_lattice α] : bounded_lattice (with_top α) := { ..with_top.lattice, ..with_top.order_top, ..with_top.order_bot } lemma well_founded_lt {α : Type*} [partial_order α] (h : well_founded ((<) : α → α → Prop)) : well_founded ((<) : with_top α → with_top α → Prop) := have acc_some : ∀ a : α, acc ((<) : with_top α → with_top α → Prop) (some a) := λ a, acc.intro _ (well_founded.induction h a (show ∀ b, (∀ c, c < b → ∀ d : with_top α, d < some c → acc (<) d) → ∀ y : with_top α, y < some b → acc (<) y, from λ b ih c, option.rec_on c (λ hc, (not_lt_of_ge lattice.le_top hc).elim) (λ c hc, acc.intro _ (ih _ (some_lt_some.1 hc))))), ⟨λ a, option.rec_on a (acc.intro _ (λ y, option.rec_on y (λ h, (lt_irrefl _ h).elim) (λ _ _, acc_some _))) acc_some⟩ instance densely_ordered [partial_order α] [densely_ordered α] [no_top_order α] : densely_ordered (with_top α) := ⟨ assume a b, match a, b with | none, a := assume h : ⊤ < a, (not_top_lt h).elim | some a, none := assume h, let ⟨b, hb⟩ := no_top a in ⟨b, coe_lt_coe.2 hb, coe_lt_top b⟩ | some a, some b := assume h, let ⟨a, ha₁, ha₂⟩ := dense (coe_lt_coe.1 h) in ⟨a, coe_lt_coe.2 ha₁, coe_lt_coe.2 ha₂⟩ end⟩ end with_top namespace order_dual open lattice variable (α : Type*) instance [has_bot α] : has_top (order_dual α) := ⟨(⊥ : α)⟩ instance [has_top α] : has_bot (order_dual α) := ⟨(⊤ : α)⟩ instance [order_bot α] : order_top (order_dual α) := { le_top := @bot_le α _, .. order_dual.partial_order α, .. order_dual.lattice.has_top α } instance [order_top α] : order_bot (order_dual α) := { bot_le := @le_top α _, .. order_dual.partial_order α, .. order_dual.lattice.has_bot α } instance [semilattice_inf_bot α] : semilattice_sup_top (order_dual α) := { .. order_dual.lattice.semilattice_sup α, .. order_dual.lattice.order_top α } instance [semilattice_inf_top α] : semilattice_sup_bot (order_dual α) := { .. order_dual.lattice.semilattice_sup α, .. order_dual.lattice.order_bot α } instance [semilattice_sup_bot α] : semilattice_inf_top (order_dual α) := { .. order_dual.lattice.semilattice_inf α, .. order_dual.lattice.order_top α } instance [semilattice_sup_top α] : semilattice_inf_bot (order_dual α) := { .. order_dual.lattice.semilattice_inf α, .. order_dual.lattice.order_bot α } instance [bounded_lattice α] : bounded_lattice (order_dual α) := { .. order_dual.lattice.lattice α, .. order_dual.lattice.order_top α, .. order_dual.lattice.order_bot α } instance [bounded_distrib_lattice α] : bounded_distrib_lattice (order_dual α) := { .. order_dual.lattice.bounded_lattice α, .. order_dual.lattice.distrib_lattice α } end order_dual namespace prod open lattice variables (α : Type u) (β : Type v) instance [has_top α] [has_top β] : has_top (α × β) := ⟨⟨⊤, ⊤⟩⟩ instance [has_bot α] [has_bot β] : has_bot (α × β) := ⟨⟨⊥, ⊥⟩⟩ instance [order_top α] [order_top β] : order_top (α × β) := { le_top := assume a, ⟨le_top, le_top⟩, .. prod.partial_order α β, .. prod.lattice.has_top α β } instance [order_bot α] [order_bot β] : order_bot (α × β) := { bot_le := assume a, ⟨bot_le, bot_le⟩, .. prod.partial_order α β, .. prod.lattice.has_bot α β } instance [semilattice_sup_top α] [semilattice_sup_top β] : semilattice_sup_top (α × β) := { .. prod.lattice.semilattice_sup α β, .. prod.lattice.order_top α β } instance [semilattice_inf_top α] [semilattice_inf_top β] : semilattice_inf_top (α × β) := { .. prod.lattice.semilattice_inf α β, .. prod.lattice.order_top α β } instance [semilattice_sup_bot α] [semilattice_sup_bot β] : semilattice_sup_bot (α × β) := { .. prod.lattice.semilattice_sup α β, .. prod.lattice.order_bot α β } instance [semilattice_inf_bot α] [semilattice_inf_bot β] : semilattice_inf_bot (α × β) := { .. prod.lattice.semilattice_inf α β, .. prod.lattice.order_bot α β } instance [bounded_lattice α] [bounded_lattice β] : bounded_lattice (α × β) := { .. prod.lattice.lattice α β, .. prod.lattice.order_top α β, .. prod.lattice.order_bot α β } instance [bounded_distrib_lattice α] [bounded_distrib_lattice β] : bounded_distrib_lattice (α × β) := { .. prod.lattice.bounded_lattice α β, .. prod.lattice.distrib_lattice α β } end prod
f252f7a076d0500f1e69ce4918ba55c18ff30a9d
fe84e287c662151bb313504482b218a503b972f3
/src/algebra/power_series.lean
8a5843d33cd5b65809bf63d38875235e972714b1
[]
no_license
NeilStrickland/lean_lib
91e163f514b829c42fe75636407138b5c75cba83
6a9563de93748ace509d9db4302db6cd77d8f92c
refs/heads/master
1,653,408,198,261
1,652,996,419,000
1,652,996,419,000
181,006,067
4
1
null
null
null
null
UTF-8
Lean
false
false
17,613
lean
/- Copyright (c) 2019 Neil Strickland. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Neil Strickland Given a semiring `R`, this file defines the power series semiring `R[[x]]` -/ import data.fintype.basic data.finsupp algebra.big_operators data.pi.algebra import data.list_extra algebra.biadditive algebra.prod_equiv algebra.convolution import algebra.order.sub import tactic.squeeze tactic.pi_instances def power_series (R : Type*) := convolution.map ℕ R namespace power_series open finset variable {R : Type*} def coeff₀ : ℕ → (power_series R) → R := λ n f, f n instance [has_zero R] : has_zero (power_series R) := by {dsimp[power_series], apply_instance} instance [add_comm_monoid R] : add_comm_monoid (power_series R) := by {dsimp[power_series], apply_instance} instance [semiring R] : semiring (power_series R) := by {dsimp[power_series], apply_instance} instance [comm_semiring R] : comm_semiring (power_series R) := by {dsimp[power_series], apply_instance} instance [ring R] : ring (power_series R) := by {dsimp[power_series], apply_instance} instance [comm_ring R] : comm_ring (power_series R) := by {dsimp[power_series], apply_instance} /- `C a` is the constant power series with value `a`, so the zeroth coefficient is `a` and the other coefficients are zero. -/ def C [semiring R] : R →+* power_series R := { to_fun := convolution.map.delta, map_zero' := convolution.map.delta_zero, map_one' := by {dsimp[power_series,has_one.one,monoid.one,semiring.one],refl}, map_add' := λ x y, by {apply convolution.map.delta_add}, map_mul' := λ x y, by {symmetry,apply convolution.delta_convolve_delta} } /- `X` denotes the standard generator of the power series semiring `R[[X]]`. -/ def X [semiring R] : power_series R := convolution.map.single (1 : ℕ) (1 : R) def coeff [add_comm_monoid R] (n : ℕ) : (power_series R →+ R) := { to_fun := λ f, f n, map_zero' := rfl, map_add' := λ f g, rfl, } @[ext] lemma ext [add_comm_monoid R] : ∀ {f g : power_series R}, (∀ n, coeff n f = coeff n g) → f = g := @funext _ _ lemma coeff_n_one [semiring R] (n : ℕ) : coeff n (1 : power_series R) = ite (0 = n) 1 0 := rfl lemma coeff_zero_one [semiring R] : coeff 0 (1 : power_series R) = 1 := rfl lemma coeff_succ_one [semiring R] (n : ℕ) : coeff (n + 1) (1 : power_series R) = 0 := rfl lemma coeff_n_C [semiring R] (n : ℕ) (a : R) : coeff n (C a) = ite (0 = n) a 0 := rfl lemma coeff_zero_C [semiring R] (a : R) : coeff 0 (C a) = a := rfl lemma coeff_succ_C [semiring R] (n : ℕ) (a : R) : coeff (n + 1) (C a) = 0 := rfl lemma coeff_n_X [semiring R] (n : ℕ) : coeff n (X : power_series R) = ite (1 = n) 1 0 := rfl lemma coeff_zero_X [semiring R] : coeff 0 (X : power_series R) = 0 := rfl lemma coeff_one_X [semiring R] : coeff 1 (X : power_series R) = 1 := rfl lemma coeff_ss_X [semiring R] (n : ℕ) : coeff (n + 2) (X : power_series R) = 0 := rfl lemma coeff_mul [semiring R] (n : ℕ) (f g : power_series R) : coeff n (f * g) = (range n.succ).sum (λ i, (coeff i f) * (coeff (n - i) g)) := begin change convolution.convolve ((*) : R → R → R) f g n = (range n.succ).sum (λ i, (coeff i f) * (coeff (n - i) g)), dsimp[convolution.convolve,convolution.sum_set.els,coeff], let h_inj : ∀ (i₁ : ℕ) (h₁ : i₁ ∈ range n.succ) (i₂ : ℕ) (h₂ : i₂ ∈ range n.succ) (e : prod.mk i₁ (n - i₁) = prod.mk i₂ (n - i₂)), i₁ = i₂ := by { intros,injection e, }, have := @sum_image R (ℕ × ℕ) ℕ (λ x, (f x.1) * (g x.2)) _ _ (range n.succ) (λ i, prod.mk i (n - i)) h_inj, simp only [] at this ⊢, rw[← this] end /- Left multiplication by `C a` is termwise left multiplication by `a` -/ lemma coeff_C_mul [semiring R] (n : ℕ) (a : R) (f : power_series R) : coeff n ((C a) * f) = a * coeff n f := begin rw[coeff_mul], let h := @sum_eq_single R ℕ _ (range (n + 1)) (λ i, coeff i (C a) * coeff (n - i) f) 0 (λ i _ h, by { simp only[], rw[coeff_n_C i a,if_neg h.symm,zero_mul], }) (λ h, by { exfalso, exact h (mem_range_succ.mpr (nat.zero_le n)) }), rw[h],simp only[],rw[coeff_n_C,if_pos rfl,nat.sub_zero], end /- Right multiplication by `C a` is termwise right multiplication by `a` -/ lemma coeff_mul_C [semiring R] (n : ℕ) (f : power_series R) (a : R) : coeff n (f * (C a)) = (coeff n f) * a := begin rw[coeff_mul], let h := @sum_eq_single R ℕ _ (range (n + 1)) (λ i, coeff i f * coeff (n - i) (C a)) n (λ i h_le h_ne, by { replace h_le : i ≤ n := mem_range_succ.mp h_le, have h_lt : i < n := lt_of_le_of_ne h_le h_ne, have : n - i ≠ 0 := λ e, not_lt_of_ge (nat.sub_eq_zero_iff_le.mp e) h_lt, simp only[], rw[coeff_n_C (n - i),if_neg this.symm,mul_zero], }) (λ h, by { exfalso, exact h (mem_range_succ.mpr (le_refl n)),}), rw[h],simp only[],rw[nat.sub_self,coeff_n_C,if_pos rfl], end lemma coeff_X_mul_zero [semiring R] (f : power_series R) : coeff 0 (X * f) = 0 := begin rw[coeff_mul,sum_range_one,coeff_n_X,if_neg (dec_trivial : 1 ≠ 0),zero_mul], end lemma coeff_X_mul_succ [semiring R] (n : ℕ) (f : power_series R) : coeff (n + 1) (X * f) = coeff n f := begin rw[coeff_mul], let h₀ := @sum_eq_single R ℕ _ (range (n + 2)) (λ i, coeff i X * coeff (n + 1 - i) f) 1 (λ i _ h, by { simp only[], rw[coeff_n_X i,if_neg h.symm,zero_mul], }) (λ h, by { have : 1 < n + 2 := nat.succ_lt_succ (nat.zero_lt_succ n), have : 1 ∈ range (n + 2) := mem_range.mpr this, exact (h this).elim}), rw[h₀],simp only[coeff_one_X],rw[one_mul],refl, end /- `E` is the homomorphism sending a power series to its constant term. -/ def E [semiring R] : (power_series R) →+* R := { to_fun := λ f, coeff 0 f, map_zero' := rfl, map_one' := rfl, map_add' := λ f g, rfl, map_mul' := λ f g, by { rw[coeff_mul,sum_range_one] } } lemma E_C [semiring R] (a : R) : E (C a) = a := rfl /- `val_ge n f` means that `f` has valuation at least `n`, or in other words that `f` is divisible by `X ^ n`. -/ @[irreducible] def val_ge [add_comm_monoid R] (n : ℕ) (f : power_series R) : Prop := ∀ {i : ℕ} (hi : i < n), coeff i f = 0 lemma val_ge_zero_all [add_comm_monoid R] (f : power_series R) : val_ge 0 f := begin dsimp[val_ge],intros i hi, exact (nat.not_lt_zero i hi).elim end lemma val_ge_all_zero [add_comm_monoid R] (n : ℕ) : val_ge n (0 : power_series R) := by {dsimp[val_ge], intros i hi, refl} lemma val_ge_one_iff [add_comm_monoid R] (f : power_series R) : val_ge 1 f ↔ coeff 0 f = 0 := by { dsimp[val_ge], split, {intro h,exact h (nat.lt_succ_self 0)}, {intros h i i_lt,cases i with i,{exact h}, {exact (nat.not_lt_zero i (nat.lt_of_succ_lt_succ i_lt)).elim,}} } lemma val_ge_add [add_comm_monoid R] {n : ℕ} {f g : power_series R} : val_ge n f → val_ge n g → val_ge n (f + g) := by {dsimp[val_ge], intros hf hg i i_is_lt, show coeff i f + coeff i g = 0,rw[hf i_is_lt,hg i_is_lt,zero_add],} lemma val_ge_mul [semiring R] {n m : ℕ} {f g : power_series R} : val_ge n f → val_ge m g → val_ge (n + m) (f * g) := λ hf hg, begin dsimp[val_ge] at hf hg ⊢, intros k k_is_lt, change (convolution.sum_set.els k).sum (λ ij, (f ij.1) * (g ij.2)) = 0, have : (convolution.sum_set.els k).sum (λ ij, (0 : R)) = (0 : R) := sum_const_zero, rw[← this],apply sum_congr rfl, rintros ⟨i,j⟩ ij_sum, replace ij_sum : i + j = k := (convolution.sum_set.mem_els _ _).mp ij_sum, change (coeff i f) * (coeff j g) = 0, by_cases hi : i < n, {rw[hf hi,zero_mul],}, by_cases hj : j < m, {rw[hg hj,mul_zero],}, let hk : n + m ≤ k := ij_sum ▸ (add_le_add (le_of_not_gt hi) (le_of_not_gt hj)), exact (not_le_of_gt k_is_lt hk).elim, end lemma val_ge_pow [semiring R] {n : ℕ} {f : power_series R} (hf : val_ge n f) (k : ℕ) : val_ge (k * n) (f ^ k) := begin induction k with k ih, {rw[zero_mul],apply val_ge_zero_all}, {rw[nat.succ_eq_add_one,pow_add,pow_one,add_mul,one_mul], exact val_ge_mul ih hf, } end lemma val_ge_pow' [semiring R] {f : power_series R} (hf : coeff 0 f = 0) (k : ℕ) : val_ge k (f ^ k) := by {have := val_ge_pow ((val_ge_one_iff f).mpr hf) k, rw[mul_one] at this, exact this,} lemma val_ge_X [semiring R] : val_ge 1 (X : power_series R) := by {dsimp[val_ge,X,coeff],intros i hi, apply convolution.map.single_eq_of_ne (ne_of_lt hi).symm,} lemma coeff_X_pow [semiring R] (n i : ℕ) : coeff i ((X : power_series R) ^ n) = ite (n = i) 1 0 := begin induction n with n ih generalizing i, {rw[pow_zero,coeff_n_one]}, {rw[pow_succ],cases i with i, {rw[coeff_X_mul_zero],rw[if_neg (nat.succ_ne_zero n)],}, {rw[coeff_X_mul_succ,ih i],by_cases h : n = i, {rw[if_pos h,if_pos (congr_arg nat.succ h)]}, {have : n.succ ≠ i.succ := λ e, h (nat.succ_inj'.mp e), rw[if_neg h,if_neg this]}}} end section compose variable [comm_semiring R] /- Note: this definition is only sensible with the side condition `coeff 0 g = 0` -/ def compose (f g : power_series R) : power_series R := λ n, ((range n.succ).sum (λ j, C (coeff j f) * (g ^ j))) n lemma coeff_compose (n : ℕ) (f g : power_series R) : coeff n (compose f g) = (range n.succ).sum (λ j, (coeff j f) * (coeff n (g ^ j))) := begin let hh := (coeff n : power_series R →+ R).map_sum, have := calc coeff n (compose f g) = coeff n ((range n.succ).sum (λ j, C (coeff j f) * (g ^ j))) : rfl ... = (range n.succ).sum (λ j, coeff n (C (coeff j f) * (g ^ j))) : by {rw[← hh]}, rw[this],congr,funext j,rw[coeff_C_mul], end lemma coeff_compose_extra {n m : ℕ} (f g : power_series R) (hg : coeff 0 g = 0) (hnm : n ≤ m) : coeff n (compose f g) = (range m.succ).sum (λ j, (coeff j f) * (coeff n (g ^ j))) := begin rw[coeff_compose], have : range n.succ = (range m.succ).filter (λ i, i ≤ n) := by {ext i,rw[mem_filter,mem_range_succ,mem_range_succ],split, {intro hn,exact ⟨le_trans hn hnm,hn⟩,},{exact λ h,h.2}}, rw[this,sum_filter],congr,ext j,split_ifs with h,refl, replace h : n < j := lt_of_not_ge h, have hv := val_ge_pow' hg j, dsimp[val_ge] at hv, rw[hv h,mul_zero], end lemma zero_compose (g : power_series R) : compose 0 g = 0 := begin ext n,rw[coeff_compose], apply sum_eq_zero_of_terms_eq_zero, intros i _,rw[(coeff i).map_zero,zero_mul], end /- `f ∘ g` is an additive function of `f`. -/ lemma add_compose (f₁ f₂ g : power_series R) : compose (f₁ + f₂) g = compose f₁ g + compose f₂ g := begin ext n,rw[(coeff n).map_add,coeff_compose,coeff_compose,coeff_compose], rw[← sum_add_distrib],congr,ext j, rw[(coeff _).map_add,add_mul], end /- `f ∘ g` is a multiplicative function of `f`. -/ lemma mul_compose (f₁ f₂ g : power_series R) (hg : coeff 0 g = 0): compose (f₁ * f₂) g = compose f₁ g * compose f₂ g := begin ext n, let r := range n.succ, let r2 := r.product r, let r3 := r.product r2, let r3' := r2.product r, let t₁ : (ℕ × ℕ × ℕ) → R := λ jpq, coeff jpq.2.1 f₁ * coeff jpq.2.2 f₂ * coeff jpq.1 (g ^ jpq.2.1) * coeff (n - jpq.1) (g ^ jpq.2.2), let t'₁ := λ pqj : ((ℕ × ℕ) × ℕ), t₁ ⟨pqj.2,pqj.1⟩, let inc₁ : ∀ (k : ℕ), ℕ ↪ (ℕ × ℕ) := λ k, { to_fun := λ p, ⟨p,k - p⟩, inj' := λ p₁ p₂ e, congr_arg prod.fst e, }, let r2' := r.bUnion (λ k, (range k.succ).map (inc₁ k)), have r2_filter : r2' = r2.filter (λ pq, pq.1 + pq.2 ≤ n) := by { ext ⟨p,q⟩,rw[mem_bUnion,mem_filter,mem_product,mem_range_succ,mem_range_succ], simp only [],split, {rintro ⟨k,k_le,hk⟩,rcases mem_map.mp hk with ⟨p',p_le,hpq⟩, injection hpq with hp hq,rw[hp] at p_le hq, replace k_le := mem_range_succ.mp k_le, replace p_le := mem_range_succ.mp p_le, repeat {split}; apply le_trans _ k_le, {exact p_le}, {rw[← hq],apply tsub_le_self}, {rw[← hq,nat.add_sub_of_le p_le]} }, {rintro ⟨⟨p_le,q_le⟩,k_le⟩, use p + q,use mem_range_succ.mpr k_le, apply mem_map.mpr,use p,use mem_range_succ.mpr (nat.le_add_right p q), show prod.mk p ((p + q) - p) = prod.mk p q, congr,rw[add_comm,nat.add_sub_cancel], } }, let e₁ := calc coeff n (compose (f₁ * f₂) g) = r.sum (λ k, coeff k (f₁ * f₂) * (coeff n (g ^ k))) : by rw[coeff_compose] ... = r.sum (λ k, (range k.succ).sum (λ p, coeff p f₁ * coeff (k - p) f₂ * coeff n (g ^ k))) : by {apply sum_congr rfl,intros k k_le,rw[coeff_mul,sum_mul],} ... = r2'.sum (λ pq, coeff pq.1 f₁ * coeff pq.2 f₂ * coeff n (g ^ (pq.1 + pq.2))) : by {rw[sum_bUnion],apply sum_congr rfl,intros k k_le, rw[sum_map],{ apply sum_congr rfl,intros p p_le,dsimp[inc₁], replace p_le : p ≤ k := mem_range_succ.mp p_le, rw[nat.add_sub_of_le p_le], },{-- side condition for sum_map intros k₁ k₁_le k₂ k₂_le k_ne, change disjoint _ _, simp only [], rw [disjoint, le_bot_iff], apply eq_empty_iff_forall_not_mem.mpr,rintros ⟨p,q⟩ hpq, change _ ∈ _ ∩ _ at hpq, rw[mem_inter] at hpq, rcases mem_map.mp hpq.1 with ⟨p₁,p₁_le,hpq₁⟩,injection hpq₁ with hp₁ hq₁, rcases mem_map.mp hpq.2 with ⟨p₂,p₂_le,hpq₂⟩,injection hpq₂ with hp₂ hq₂, replace p₁_le := mem_range_succ.mp p₁_le, replace p₂_le := mem_range_succ.mp p₂_le, rw[← nat.add_sub_of_le p₁_le,← nat.add_sub_of_le p₂_le,hq₁,hq₂,hp₁,hp₂] at k_ne, exact k_ne rfl, } } ... = r2.sum (λ pq, coeff pq.1 f₁ * coeff pq.2 f₂ * coeff n (g ^ (pq.1 + pq.2))) : by { rw[r2_filter,sum_filter],apply sum_congr rfl,rintros ⟨p,q⟩ hpq, split_ifs,refl, replace h : n < p + q := lt_of_not_ge h, have := val_ge_pow' hg (p + q),dsimp[val_ge] at this,rw[this h,mul_zero], } ... = r2.sum (λ pq,r.sum (λ j, t₁ ⟨j,pq⟩)) : by {dsimp[t₁], apply finset.sum_congr rfl,rintros ⟨p,q⟩ hpq,rw[pow_add,coeff_mul,mul_sum], apply finset.sum_congr rfl,rintros j hj,repeat {rw[mul_assoc]},} ... = r3'.sum t'₁ : by {dsimp[r3'],rw[@sum_product _ _ _ _ r2 r],} ,rw[e₁],clear e₁, let e₂ := calc coeff n (compose f₁ g * compose f₂ g) = r.sum (λ j, coeff j (compose f₁ g) * coeff (n - j) (compose f₂ g)) : by rw[coeff_mul] ... = r.sum (λ j, r.sum (λ p, coeff p f₁ * coeff j (g ^ p)) * r.sum (λ q, coeff q f₂ * coeff (n - j) (g ^ q))) : by {apply sum_congr rfl,intros j j_le, replace j_le := mem_range_succ.mp j_le, rw[coeff_compose_extra f₁ g hg j_le], have : n - j ≤ n := tsub_le_self, rw[coeff_compose_extra f₂ g hg this], } ... = r.sum (λ j, r.sum (λ p, coeff p f₁ * coeff j (g ^ p) * r.sum (λ q, coeff q f₂ * coeff (n - j) (g ^ q)))) : by {apply sum_congr rfl,intros j j_le,rw[sum_mul]} ... = r.sum (λ j, r.sum (λ p, r.sum (λ q, coeff p f₁ * coeff j (g ^ p) * (coeff q f₂ * coeff (n - j) (g ^ q))))) : by {apply sum_congr rfl,intros j j_le, apply sum_congr rfl,intros k k_le,rw[mul_sum]} ... = r.sum (λ j, r.sum (λ p, r.sum (λ q, t₁ ⟨j,p,q⟩))) : by {apply sum_congr rfl,intros j j_le, apply sum_congr rfl,intros k k_le, apply sum_congr rfl,intros p p_le, rw[mul_assoc,← mul_assoc (coeff j (g ^ k)),mul_comm (coeff j (g ^ k))], rw[← mul_assoc,← mul_assoc],} ... = r.sum (λ j, r2.sum (λ pq, t₁ ⟨j,pq⟩)) : by {apply sum_congr rfl,intros j j_le,rw[sum_product],} ... = r3.sum t₁ : by rw[← sum_product], rw[e₂], clear e₂, let s := λ (jpq : ℕ × ℕ × ℕ) (h : jpq ∈ r3), prod.mk jpq.2 jpq.1, let e := @sum_bij _ _ _ _ r3 r3' t₁ t'₁ s (λ ⟨j,p,q⟩ h, by {dsimp[s],repeat {rw[mem_product] at h ⊢}, rcases h with ⟨hj,hp,hq⟩,repeat {split}; assumption,}) (λ ⟨j,p,q⟩ h, rfl) (λ ⟨j₁,p₁,q₁⟩ ⟨j₂,p₂,q₂⟩ h₁ h₂ e, by {dsimp[s] at e,injection e with epq ej,injection epq with ep eq, rw[ej,ep,eq],}) (λ ⟨⟨p,q⟩,j⟩ h, by {use ⟨j,p,q⟩,have : (⟨j,p,q⟩ : ℕ × ℕ × ℕ) ∈ r3, {repeat {rw[mem_product] at h ⊢}, rcases h with ⟨⟨hp,hq⟩,hj⟩,repeat {split}; assumption,}, use this}), exact e.symm, end lemma C_compose (a : R) (g : power_series R) : compose (C a) g = C a := begin ext n,rw[coeff_compose], let f := λ (j : ℕ), coeff j (C a) * coeff n (g ^ j), change (range n.succ).sum f = coeff n (C a), have : f 0 = coeff n (C a) := by {dsimp[f],rw[pow_zero,coeff_zero_C,coeff_n_one,coeff_n_C], split_ifs,rw[mul_one],rw[mul_zero]}, rw[← this],apply sum_eq_single, {intros j h_le h_ne,rw[coeff_n_C,if_neg h_ne.symm,zero_mul]}, {intro h,exfalso,exact h (mem_range_succ.mpr (nat.zero_le n))} end lemma X_compose (a : R) (g : power_series R) (hg : coeff 0 g = 0) : compose X g = g := begin ext n,rw[coeff_compose], let f := λ (j : ℕ), coeff j X * coeff n (g ^ j), change (range n.succ).sum f = coeff n g, have : f 1 = coeff n g := by {dsimp[f],rw[coeff_one_X,pow_one,one_mul]}, rw[← this],apply sum_eq_single, {intros j h_le h_ne,rw[coeff_n_X,if_neg h_ne.symm,zero_mul]}, {cases n with n, {intro h,rw[pow_one,hg,mul_zero]}, {intro h,exfalso, exact h (mem_range_succ.mpr (nat.succ_le_succ (nat.zero_le n))), }} end end compose end power_series
a7b52e3bbc2038b9da0f5d2ace9313b1e7030eae
d406927ab5617694ec9ea7001f101b7c9e3d9702
/test/free_algebra.lean
b570e397a309cc47b3302dd7de514181312a80f3
[ "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
1,180
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import linear_algebra.exterior_algebra.basic import linear_algebra.clifford_algebra /-! Tests that the ring instances for `free_algebra` and derived quotient types actually work. There is some discussion about this in https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241 In essence, the use of `attribute [irreducible] the_type` was breaking instance resolution on that type. -/ variables {S : Type*} {M : Type*} section free variables [comm_ring S] example : (1 : free_algebra S M) - (1 : free_algebra S M) = 0 := by rw sub_self end free section exterior variables [comm_ring S] [add_comm_group M] [module S M] example : (1 : exterior_algebra S M) - (1 : exterior_algebra S M) = 0 := by rw sub_self end exterior section clifford variables [comm_ring S] [add_comm_group M] [module S M] (Q : quadratic_form S M) example : (1 : clifford_algebra Q) - (1 : clifford_algebra Q) = 0 := by rw sub_self end clifford
720a73d557b220162d8265babbeb570ae1082115
7bf54883c04ff2856c37f76a79599ceb380c1996
/non-mathlib/cubic.lean
d43ad13db264f35ae9febe488e388b458e7c5af4
[]
no_license
anonymousLeanDocsHosting/lean-polynomials
4094466bf19acc0d1a47b4cabb60d8c21ddb2b00
361ef4cb7b68ef47d43b85cfa2d13f2ea0a47613
refs/heads/main
1,691,112,899,935
1,631,819,522,000
1,631,819,522,000
405,448,439
0
2
null
null
null
null
UTF-8
Lean
false
false
92,838
lean
import field_definition import field_results import numbers import roots import quadratic lemma multiply_out_cubed (f : Type) [myfld f] (x a : f) : (cubed f (x .+ a)) = ((cubed f x) .+ (((three f) .* ((square f x) .* a)) .+ (((three f) .* ((x .* a) .* a)) .+ (cubed f a)))) := begin unfold cubed, unfold three, unfold square, repeat {rw distrib_simp f _ _ _}, repeat {rw distrib_simp_alt f _ _ _}, rw one_mul_simp f _, rw myfld.mul_assoc _ _ _, rw myfld.mul_comm a x, rw myfld.mul_assoc a x a, rw myfld.mul_comm a x, rw myfld.mul_assoc _ _ _, rw myfld.mul_assoc a x x, rw myfld.mul_comm a x, rw <- myfld.mul_assoc x a x, rw myfld.mul_comm a x, repeat {rw myfld.mul_assoc _ _ _}, repeat {rw <- myfld.add_assoc _ _ _}, rw myfld.add_assoc ((x .* a) .* a) ((x .* x) .* a) _, rw myfld.add_comm ((x .* a) .* a) ((x .* x) .* a), repeat {rw <- myfld.add_assoc _ _ _}, rw one_mul_simp f _, end def cardano_intermediate_val (f : Type) [myfld f] [fld_with_sqrt f] [fld_not_char_two f] [fld_not_char_three f] (c d : f) : f := sqroot (((square f d) .* (myfld.reciprocal (four f) (four_ne_zero f))) .+ ((cubed f c) .* (myfld.reciprocal (twenty_seven f) (twenty_seven_ne_zero f)))) def cardano_other_int_val (f : Type) [myfld f] [fld_not_char_two f] (d : f) : f := .- (d .* (myfld.reciprocal (two f) fld_not_char_two.not_char_two)) /- Prove that (if c ≠ 0) the fraction in the Cardano formula is a legal fraction. We do actually need a couple of versions of this for different purposes, so the formula is split over a few different lemmae.-/ lemma cardano_den_not_zero_general (f : Type) [myfld f] [fld_with_sqrt f] [fld_not_char_two f] [fld_not_char_three f] (c d : f) (c_ne_zero : c ≠ myfld.zero) : (square f (cardano_intermediate_val f c d)) .+ (.- (square f (cardano_other_int_val f d))) ≠ myfld.zero := begin intro h, unfold square at h, unfold cardano_other_int_val at h, unfold cardano_intermediate_val at h, rw fld_with_sqrt.sqrt_mul_sqrt _ at h, rw mul_negate f _ at h, rw <- mul_negate_alt f _ at h, rw double_negative f _ at h, rw <- myfld.mul_assoc d _ _ at h, rw myfld.mul_comm d (myfld.reciprocal (two f) _) at h, rw myfld.mul_assoc (myfld.reciprocal (two f) _) (myfld.reciprocal (two f) _) _ at h, rw mul_two_reciprocals f (two f) (two f) _ _ at h, rw myfld.mul_comm _ d at h, rw myfld.mul_assoc d d _ at h, unfold square at h, unfold four at h, rw reciprocal_rewrite f ((two f) .+ (two f)) ((two f) .* (two f)) (two_plus_two f) _ at h, rw myfld.add_comm (_ .* _) _ at h, rw <- myfld.add_assoc _ _ _ at h, rw only_one_reciprocal f ((two f) .* (two f)) _ (mul_nonzero f (two f) (two f) fld_not_char_two.not_char_two fld_not_char_two.not_char_two) at h, rw myfld.add_negate _ at h, rw zero_simp at h, have h1 : (cubed f c) ≠ myfld.zero, unfold cubed, exact mul_nonzero f c (c .* c) c_ne_zero (mul_nonzero f c c c_ne_zero c_ne_zero), exact (mul_nonzero f (cubed f c) (myfld.reciprocal (twenty_seven f) _) h1 (reciprocal_ne_zero f (twenty_seven f) _)) h, end lemma cardano_den_not_zero_int (f : Type) [myfld f] [fld_with_sqrt f] [fld_not_char_two f] [fld_not_char_three f] (c d : f) (c_ne_zero : c ≠ myfld.zero) : (cardano_intermediate_val f c d) .+ (cardano_other_int_val f d) ≠ myfld.zero := begin intro h, have h1 : (((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d)) .* ((cardano_intermediate_val f c d) .+ (.- (cardano_other_int_val f d)))) = myfld.zero, rw h, rw mul_zero f _, clear h, rename h1 h, rw difference_of_squares f _ _ at h, exact cardano_den_not_zero_general f c d c_ne_zero h, end lemma cardano_den_not_zero_int_alt (f : Type) [myfld f] [fld_with_sqrt f] [fld_not_char_two f] [fld_not_char_three f] (c d : f) (c_ne_zero : c ≠ myfld.zero) : (cardano_intermediate_val f c d) .+ (.- (cardano_other_int_val f d)) ≠ myfld.zero := begin intro h, have h1 : (((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d)) .* ((cardano_intermediate_val f c d) .+ (.- (cardano_other_int_val f d)))) = myfld.zero, rw h, rw zero_mul f _, clear h, rename h1 h, rw difference_of_squares f _ _ at h, exact cardano_den_not_zero_general f c d c_ne_zero h, end lemma cardano_denominator_not_zero (f : Type) [myfld f] [fld_with_sqrt f] [fld_not_char_two f] [fld_not_char_three f] [fld_with_cube_root f] (c d : f) (c_ne_zero : c ≠ myfld.zero) (cubrt_func : f -> f) (cubrt_func_nonzero : ∀ (x : f), x ≠ myfld.zero -> (cubrt_func x ≠ myfld.zero)) : (cubrt_func ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))) .* (three f) ≠ myfld.zero := begin exact mul_nonzero f _ (three f) (cubrt_func_nonzero _ (cardano_den_not_zero_int f c d c_ne_zero)) fld_not_char_three.not_char_three, end /- This is the formula, finally. Note that we are intentionally vague about the cube root - any function that gives a cube root can be provided. This is so that we can easily create a proof that covers all three cube roots at the same time.-/ def cardano_formula (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (c d : f) (c_ne_zero : c ≠ myfld.zero) (cubrt_func : f -> f) (cubrt_func_nonzero : ∀ (x : f), x ≠ myfld.zero -> (cubrt_func x ≠ myfld.zero)) (cubrt_func_correct : ∀ (x : f), (cubed f (cubrt_func x)) = x) : f := ((cubrt_func ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))) .+ (.- (c .* (myfld.reciprocal ((cubrt_func ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))) .* (three f)) (cardano_denominator_not_zero f c d c_ne_zero cubrt_func cubrt_func_nonzero))))) def depressed_cubic_subst (f : Type) [myfld f] (c d x : f) : f := (cubed f x) .+ ((c .* x) .+ d) /- This is now the proof that all depressed cubics can be solved by the above formula. We're not doing uniqueness yet.-/ lemma cardano_works (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (c d : f) (c_ne_zero : c ≠ myfld.zero) (cubrt_func : f -> f) (cubrt_func_nonzero : ∀ (x : f), x ≠ myfld.zero -> (cubrt_func x ≠ myfld.zero)) (cubrt_func_correct : ∀ (x : f), (cubed f (cubrt_func x)) = x) : depressed_cubic_subst f c d (cardano_formula f c d c_ne_zero cubrt_func cubrt_func_nonzero cubrt_func_correct) = myfld.zero := begin /- First multiply out the brackets.-/ unfold depressed_cubic_subst, unfold cardano_formula, rw distrib_simp_alt f c _ _, rw multiply_out_cubed f _ _, unfold square, rw cubrt_func_correct _, rw cube_of_negative f _, simp only [mul_negate, mul_negate_alt_simp, double_negative], /- Now simplify two terms where we have 3 * 1/3.-/ rw split_reciprocal f _ (three f) _, rw myfld.mul_comm (myfld.reciprocal _ _) (myfld.reciprocal (three f) _), rw myfld.mul_assoc c (myfld.reciprocal (three f) _) _, rw myfld.mul_comm c (myfld.reciprocal (three f) _), rw myfld.mul_comm _ (((myfld.reciprocal (three f) _) .* c) .* (myfld.reciprocal _ _)), rw myfld.mul_comm _ (((myfld.reciprocal (three f) _) .* c) .* (myfld.reciprocal _ _)), repeat {rw myfld.mul_assoc _ _ _}, rw myfld.mul_reciprocal (three f) _, rw one_mul_simp f _, /- There are also some points where we have cubrt (stuff) * reciprocal (cubrt (stuff)) . So these also simplify.-/ rw <- myfld.mul_assoc c (myfld.reciprocal (cubrt_func _) _) (cubrt_func _), rw myfld.mul_comm (myfld.reciprocal (cubrt_func _) _) (cubrt_func _), rw myfld.mul_reciprocal _ _, rw simp_mul_one f _, /- We can now cancel some of the terms by moving them next to their negations. -/ rw myfld.add_comm (c .* _) (.- _), rw myfld.add_comm (((c .* _) .* c) .* _) (.- (cubed f _)), repeat {rw <- myfld.add_assoc _ _ _}, rw myfld.add_assoc (((c .* _) .* c) .* _) (.- _) _, rw myfld.add_negate _, rw simp_zero f _, rw myfld.add_comm (.- _) _, rw myfld.add_comm _ d, repeat {rw <- myfld.add_assoc _ _ _}, rw myfld.add_negate _, rw zero_simp f _, /- One of our remaining terms has two reciprocals multiplied together. Also, it is the cube of some stuff multiplied by a cube root, so we can remove the cube root from the expression.-/ rw myfld.mul_comm (myfld.reciprocal _ _) c, rw <- myfld.mul_assoc c (myfld.reciprocal _ _) (myfld.reciprocal _ _), repeat {rw cube_of_product f _ _}, rw cube_of_reciprocal f (cubrt_func _), rw reciprocal_rewrite f (cubed f (cubrt_func _)) _ (cubrt_func_correct _) _, rw cube_of_reciprocal f _, /- We now have the reciprocal of (cardano_intermediate_val + cardano_other_int_val) . cardano_intermediate_val is a square root, so in the interest of rationalising denominators we can multiply this by (int_val - other_int_val) / (int_val - other_int_val) . -/ rw only_one_reciprocal f ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d)) _ (cardano_den_not_zero_int f c d c_ne_zero), have tmp : (((cardano_intermediate_val f c d) .+ (.- (cardano_other_int_val f d))) .* (myfld.reciprocal ((cardano_intermediate_val f c d) .+ (.- (cardano_other_int_val f d))) (cardano_den_not_zero_int_alt f c d c_ne_zero))) = myfld.one, rw myfld.mul_reciprocal _ _, have tmp2 : (myfld.reciprocal ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d)) (cardano_den_not_zero_int f c d c_ne_zero)) = ((myfld.reciprocal ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d)) (cardano_den_not_zero_int f c d c_ne_zero)) .* myfld.one), exact myfld.mul_one _, rw <- tmp at tmp2, clear tmp, rename tmp2 tmp, rw myfld.mul_comm _ (myfld.reciprocal _ _) at tmp, rw myfld.mul_assoc (myfld.reciprocal _ _) (myfld.reciprocal _ _) _ at tmp, rw mul_two_reciprocals f _ _ _ _ at tmp, rw reciprocal_rewrite f _ _ (difference_of_squares f _ _) _ at tmp, rw tmp, clear tmp, /- Now that we've pre-rationalized the denominator, it's finally time to unfold these intermediate values.-/ unfold cardano_intermediate_val, unfold cardano_other_int_val, /- Our fraction now has an expression on the bottom that simplifies to p^3/27. Because reciprocals need to have a proof that the denominator isn't zero, it's easier to do this in a sub-proof so that the reciprocal only needs to be rewritten once.-/ have denominator_sub_proof : ((square f (sqroot (((square f d) .* (myfld.reciprocal (four f) _)) .+ ((cubed f c) .* (myfld.reciprocal (twenty_seven f) _))))) .+ (.- (square f (.- (d .* (myfld.reciprocal (two f) fld_not_char_two.not_char_two)))))) = ((cubed f c) .* (myfld.reciprocal (twenty_seven f) (twenty_seven_ne_zero f))), rw sqrt_squared f _, unfold square, rw mul_negate f _ _, rw double_negative f _, rw mul_negate_alt_simp f _ _, rw <- myfld.mul_assoc d (myfld.reciprocal _ _) (_ .* _), rw myfld.mul_comm d (myfld.reciprocal _ _), rw myfld.mul_assoc (myfld.reciprocal _ _) (myfld.reciprocal _ _) d, rw mul_two_reciprocals f (two f) (two f) _ _, rw myfld.mul_comm (myfld.reciprocal _ _) d, rw myfld.mul_assoc d d _, rw myfld.add_comm _ (.- _), rw myfld.add_assoc _ _ _, unfold four, rw reciprocal_rewrite f ((two f) .+ (two f)) ((two f) .* (two f)) (two_plus_two _) _, rw only_one_reciprocal f ((two f) .* (two f)) _ (mul_nonzero f (two f) (two f) fld_not_char_two.not_char_two fld_not_char_two.not_char_two), rw myfld.add_comm (.- _) _, rw myfld.add_negate _, rw simp_zero f _, /- And now we can do the rewrite in the main proof.-/ rw reciprocal_rewrite f _ _ denominator_sub_proof _, /- The big fraction is now reduced to p^3 (stuff) / (27 (p^3/27)) . A bit of cancellation will reduce that to the part abbreviated "stuff" in that equation.-/ rw myfld.mul_assoc (myfld.reciprocal _ _) (myfld.reciprocal _ _) (_ .+ _), rw myfld.mul_comm (myfld.reciprocal (cubed f (three f)) _) (myfld.reciprocal (_ .* _) _), repeat {rw <- myfld.mul_assoc _ _ _}, repeat {rw myfld.mul_assoc _ _ _}, rw split_reciprocal f (cubed f c) _ _, rw myfld.mul_assoc (cubed f c) (myfld.reciprocal (cubed f c) _) _, rw myfld.mul_reciprocal (cubed f c), rw one_mul_simp f _, rw double_reciprocal f _, rw reciprocal_rewrite f (cubed f (three f)) (twenty_seven f) (three_cubed f) _, rw myfld.mul_reciprocal (twenty_seven f) _, rw one_mul_simp f _, /- And now one of the big square roots is positive and one is negative, so they cancel.-/ clear denominator_sub_proof, repeat {rw add_negate f _ _}, rw double_negative f _, rw <- myfld.add_assoc (.- (sqroot _)) _ _, rw myfld.add_assoc _ (.- (sqroot _)) _, rw myfld.add_comm _ (.- (sqroot _)), repeat {rw <- myfld.add_assoc _ _ _}, repeat {rw myfld.add_assoc _ _ _}, /- TODO: improve this line-/ rw myfld.add_negate _, rw simp_zero f _, /- And finally we have (-d/2) + (-d/2) + d, which is obviously zero.-/ rw <- add_negate f (d .* _) (d .* _), rw <- distrib_simp_alt f d _ _, rw only_one_reciprocal f (two f) _ (two_ne_zero f), rw add_two_halves f, rw <- myfld.mul_one d, rw myfld.add_comm (.- d) d, exact myfld.add_negate d, end def cardano_formula_a (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (c d : f) (c_ne_zero : c ≠ myfld.zero) : f := cardano_formula f c d c_ne_zero fld_with_cube_root.cubrt (cubrt_nonzero f) (cubrt_cubed f) def cardano_formula_b (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (c d : f) (c_ne_zero : c ≠ myfld.zero) : f := cardano_formula f c d c_ne_zero (alt_cubrt_a f) (alt_cubrt_a_nonzero f) (alt_cubrt_a_correct f) def cardano_formula_c (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (c d : f) (c_ne_zero : c ≠ myfld.zero) : f := cardano_formula f c d c_ne_zero (alt_cubrt_b f) (alt_cubrt_b_nonzero f) (alt_cubrt_b_correct f) /- And as we have proven that all versions of the cardano_formula are correct when substituted into the equation, all three of the above formulae are solutions to a depressed cubic equation.-/ def depressed_cubic_solution_c_zero (f : Type) [myfld f] (c d : f) (c_eq_zero : c = myfld.zero) (cubrt_func : f -> f) (cubrt_func_correct : ∀ (x : f), (cubed f (cubrt_func x)) = x) : f := .- (cubrt_func (d)) lemma depressed_cubic_solution_c_zero_correct (f : Type) [myfld f] (c d : f) (c_eq_zero : c = myfld.zero) (cubrt_func : f -> f) (cubrt_func_correct : ∀ (x : f), (cubed f (cubrt_func x)) = x) : depressed_cubic_subst f c d (depressed_cubic_solution_c_zero f c d c_eq_zero cubrt_func cubrt_func_correct) = myfld.zero := begin unfold depressed_cubic_solution_c_zero, unfold depressed_cubic_subst, rw c_eq_zero, rw mul_zero f _, rw simp_zero f _, unfold cubed, repeat {rw mul_negate f _ _}, repeat {rw mul_negate_alt_simp f _ _}, rw double_negative f _, rw myfld.mul_assoc _ _ _, unfold cubed at cubrt_func_correct, rw <- myfld.mul_assoc, rw cubrt_func_correct _, rw myfld.add_comm, rw myfld.add_negate d, end def depressed_cubic_solution_c_zero_a (f : Type) [myfld f] [fld_with_cube_root f] (c d : f) (c_eq_zero : c = myfld.zero) : f := depressed_cubic_solution_c_zero f c d c_eq_zero fld_with_cube_root.cubrt (cubrt_cubed f) def depressed_cubic_solution_c_zero_b (f : Type) [myfld f] [fld_with_cube_root f] [fld_with_sqrt f] [fld_not_char_two f] (c d : f) (c_eq_zero : c = myfld.zero) : f := depressed_cubic_solution_c_zero f c d c_eq_zero (alt_cubrt_a f) (alt_cubrt_a_correct f) def depressed_cubic_solution_c_zero_c (f : Type) [myfld f] [fld_with_cube_root f] [fld_with_sqrt f] [fld_not_char_two f] (c d : f) (c_eq_zero : c = myfld.zero) : f := depressed_cubic_solution_c_zero f c d c_eq_zero (alt_cubrt_b f) (alt_cubrt_b_correct f) /- This is a bit lame, I will admit. We have a formula that is proven to be correct when c is zero, and a formula that is proven to be correct when c is not zero. I don't right now see that we can merge them into one formula, however, because while Lean does have a "cond" operator that functions like the ternary operator in most languages, it doesn't seem to allow for accessing a proof of the proposition that has been evaluated. Ergo, we can't use it here because calling the "c is not zero" version of the formula requires that we have a proof that c is not zero.-/ def cubic_subst (f : Type) [myfld f] (a b c d x : f) : f := (a .* (cubed f x)) .+ ((b .* (square f x)) .+ ((c .* x) .+ d)) /- This is a fairly trivial result, but it enables us to create a simplified version of the formula with no x^3 coefficient.-/ lemma divide_cubic_through (f : Type) [myfld f] (a b c d x : f) (a_ne_zero : a ≠ myfld.zero) : (cubic_subst f a b c d x) = myfld.zero <-> (cubic_subst f myfld.one (b .* (myfld.reciprocal a a_ne_zero)) (c .* (myfld.reciprocal a a_ne_zero)) (d .* (myfld.reciprocal a a_ne_zero)) x) = myfld.zero := begin unfold cubic_subst, split, intros h, have h1 : (((a .* (cubed f x)) .+ ((b .* (square f x)) .+ ((c .* x) .+ d))) .* (myfld.reciprocal a a_ne_zero)) = myfld.zero, rw h, exact mul_zero f _, clear h, rename h1 h, repeat {rw distrib_simp f _ _ _ at h}, repeat {rw <- myfld.mul_assoc _ _ (myfld.reciprocal a a_ne_zero) at h}, repeat {rw myfld.mul_comm _ (myfld.reciprocal a a_ne_zero) at h}, rw myfld.mul_assoc a (myfld.reciprocal a a_ne_zero) _ at h, rw myfld.mul_reciprocal a a_ne_zero at h, rw myfld.mul_comm d (myfld.reciprocal a a_ne_zero), repeat {rw myfld.mul_assoc _ _ _ at h}, repeat {rw myfld.mul_assoc _ _ _}, exact h, intros h, have h1 : (((myfld.one .* (cubed f x)) .+ (((b .* (myfld.reciprocal a a_ne_zero)) .* (square f x)) .+ (((c .* (myfld.reciprocal a a_ne_zero)) .* x) .+ (d .* (myfld.reciprocal a a_ne_zero))))) .* a) = myfld.zero, rw h, exact mul_zero f _, clear h, rename h1 h, repeat {rw distrib_simp f _ _ _ at h}, rw <- myfld.mul_assoc _ (myfld.reciprocal a a_ne_zero) a at h, rw myfld.mul_comm (myfld.reciprocal a a_ne_zero) a at h, rw myfld.mul_reciprocal a a_ne_zero at h, rw simp_mul_one at h, repeat {rw <- myfld.mul_assoc _ _ a at h}, repeat {rw myfld.mul_comm _ a at h}, repeat {rw myfld.mul_assoc _ a _ at h}, repeat {rw <- myfld.mul_assoc _ _ a at h}, repeat {rw myfld.mul_comm (myfld.reciprocal a a_ne_zero) a at h}, rw myfld.mul_reciprocal a a_ne_zero at h, repeat {rw simp_mul_one at h}, rw one_mul_simp at h, exact h, end def third (f : Type) [myfld f] [fld_not_char_three f] : f := (myfld.reciprocal (three f) fld_not_char_three.not_char_three) def twenty_seventh (f : Type) [myfld f] [fld_not_char_three f] : f := (myfld.reciprocal (twenty_seven f) (twenty_seven_ne_zero f)) /- This looks weird and pointless but it simplifies a proof later.-/ lemma depressed_cubic_equal_split (f : Type) [myfld f] (c1 d1 c2 d2 x : f) : (c1 = c2) /\ (d1 = d2) -> (depressed_cubic_subst f c1 d1 x) = (depressed_cubic_subst f c2 d2 x) := begin intros h, cases h with h1 h2, rw h1, rw h2, end /- This is used in the next proof (reduce_cubic_to_depressed) . It could have been done with a "have", but the next proof is long enough that my computer was struggling with it, so it seemed worth moving this bit out.-/ lemma helper_bcubed (f : Type) [myfld f] [fld_not_char_three f] (b : f) : (b .* ((third f) .* (b .* ((third f) .* b)))) = ((three f) .* ((myfld.reciprocal (twenty_seven f) (twenty_seven_ne_zero f)) .* ((b .* b) .* b))) := begin unfold third, unfold twenty_seven, unfold nine, rw split_reciprocal f _ _ _, rw <- myfld.mul_assoc (myfld.reciprocal (three f) _), rw myfld.mul_assoc (three f) (myfld.reciprocal (three f) _) _, rw myfld.mul_reciprocal (three f) _, rw one_mul_simp f _, repeat {rw myfld.mul_comm b (_ .* _) }, repeat {rw myfld.mul_assoc _ _ _}, rw mul_two_reciprocals f _ _ _ _, end /- Ditto.-/ lemma helper_twothirds (f : Type) [myfld f] [fld_not_char_three f] : ((.- (third f)) .+ myfld.one) = (third f) .+ (third f) := begin have h : myfld.one = (third f) .* (three f) , unfold third, rw myfld.mul_comm, symmetry, exact myfld.mul_reciprocal (three f) _, rw h, clear h, have h : (.- (third f)) = (third f) .* (.- myfld.one) , rw <- mul_negate_alt f _ _, rw simp_mul_one f _, rw h, clear h, rw <- distrib_simp_alt f _ _ _, unfold third, unfold three, rw myfld.add_assoc (.- myfld.one) myfld.one _, rw myfld.add_comm (.- myfld.one) myfld.one, rw myfld.add_negate myfld.one, rw simp_zero f _, rw distrib_simp_alt f _ _ _, rw simp_mul_one f _, end lemma reduce_cubic_to_depressed (f : Type) [myfld f] [fld_not_char_three f] (b c d x y : f) : x = y .+ (.- (b .* (third f))) -> (cubic_subst f myfld.one b c d x) = (depressed_cubic_subst f (((square f b) .* (.- (third f))) .+ c) ((twenty_seventh f) .* ((((two f) .* (cubed f b)) .+ (.- ((nine f) .* (b .* c)))) .+ ((twenty_seven f) .* d))) y) := begin intros h, rw h, clear h, unfold cubic_subst, rw multiply_out_cubed f y _, rw multiply_out_squared f _ _, rw one_mul_simp f _, repeat {rw distrib_simp_alt f _ _ _}, rw mul_negate f _ _, repeat {rw mul_negate_alt_simp f _ _}, repeat {rw mul_negate f _ _}, rw mul_negate_alt_simp f _ _, rw double_negative f _, /- First job is to cancel the terms that have 3 * (1/3) in them.-/ have third_three : (three f) .* (third f) = myfld.one, unfold third, rw myfld.mul_reciprocal (three f) _, rw myfld.mul_comm b (third f), rw myfld.mul_assoc _ (third f) _, rw myfld.mul_comm _ (third f), rw <- myfld.mul_assoc (third f) _ _, rw myfld.mul_assoc y (third f) b, rw myfld.mul_comm y (third f), rw <- myfld.mul_assoc (third f) y b, rw <- myfld.mul_assoc (third f) (y .* b) _, repeat {rw myfld.mul_assoc (three f) (third f) _}, rw third_three, clear third_three, repeat {rw one_mul_simp f _}, /- Now we have a term for by^2 and -by^2, so these cancel.-/ unfold square, rw myfld.mul_comm b (y .* y), rw myfld.add_comm (.- ((y .* y) .* b)) _, repeat {rw <- myfld.add_assoc}, rw myfld.add_assoc (.- ((y .* y) .* b)) ((y .* y) .* b) _, rw myfld.add_comm (.- ((y .* y) .* b)) ((y .* y) .* b), rw myfld.add_negate ((y .* y) .* b), rw simp_zero, /- This ultimately needs to be made equivalent to the depressed cubic formula, so we gather all the terms that are multiplied by y together.-/ rw myfld.mul_comm _ y, repeat {rw myfld.mul_assoc _ y _, rw myfld.mul_comm _ y}, rw <- myfld.mul_assoc y (two f) _, rw myfld.mul_assoc _ y _, rw myfld.mul_comm b y, repeat {rw <- myfld.mul_assoc y b _}, rw mul_negate_alt f y _, rw myfld.mul_comm c y, rw myfld.add_assoc (cubed f (.- ((third f) .* b))) (y .* _) _, rw myfld.add_comm _ (y .* (.- (b .* ((two f) .* ((third f) .* b))))), rw <- myfld.add_assoc (y .* (.- (b .* ((two f) .* ((third f) .* b))))) _ _, rw myfld.add_assoc (y .* _) (y .* _), rw <- distrib_simp_alt f y _ _, rw myfld.add_assoc _ (y .* c) _, rw myfld.add_comm _ (y .* c), rw <- myfld.add_assoc (y .* c) _ _, rw myfld.add_assoc _ (y .* c) _, rw myfld.add_comm _ (y .* c), rw <- myfld.add_assoc (y .* c) _ _, rw myfld.add_assoc _ (y .* c) _, rw <- distrib_simp_alt f y _ c, /- We can now fold this back into the depressed cubic formula, which will make the remaining algebra slightly easier to follow.-/ rw myfld.mul_comm y _, /- The following line is ugly, but it's just a copy-paste of the algebra in the sidebar.-/ have tmp : (cubed f y) .+ (((((b .* ((third f) .* b)) .+ (.- (b .* ((two f) .* ((third f) .* b))))) .+ c) .* y) .+ ((cubed f (.- ((third f) .* b))) .+ ((b .* ((.- ((third f) .* b)) .* (.- ((third f) .* b)))) .+ ((.- (c .* ((third f) .* b))) .+ d)))) = depressed_cubic_subst f (((b .* ((third f) .* b)) .+ (.- (b .* ((two f) .* ((third f) .* b))))) .+ c) ((cubed f (.- ((third f) .* b))) .+ ((b .* ((.- ((third f) .* b)) .* (.- ((third f) .* b)))) .+ ((.- (c .* ((third f) .* b))) .+ d))) y, unfold depressed_cubic_subst, rw tmp, clear tmp, /- This enables us to break down into two goals (one for the y term and one for the constant.) -/ apply depressed_cubic_equal_split f _ _ _ _ y, split, /- (b^2) /3 - 2 (b/^2) 3 = - (b^2) /3, which solves the y term goal.-/ rw myfld.mul_comm _ b, rw myfld.mul_comm _ (b .* _), rw myfld.mul_assoc _ b _, rw myfld.mul_comm (two f) b, rw <- myfld.mul_assoc b (two f) _, rw myfld.mul_comm (b .* (third f)) b, repeat {rw myfld.mul_assoc b b _}, rw mul_negate_alt f (b .* b) _, rw <- distrib_simp_alt f (b .* b) _ _, rw myfld.mul_comm (two f) (third f), have tmp : (third f) = ((third f) .* myfld.one), exact myfld.mul_one (third f), rewrite [tmp] {occs := occurrences.pos [1]}, clear tmp, rw mul_negate_alt f (third f) (two f), rw <- distrib_simp_alt f (third f) _ _, have tmp : myfld.one .+ (.- (two f)) = .- (myfld.one), unfold two, rw add_negate f myfld.one myfld.one, rw myfld.add_assoc myfld.one (.- myfld.one) (.- myfld.one), rw myfld.add_negate myfld.one, rw <- zero_add f (.- myfld.one), rw tmp, clear tmp, rw <- mul_negate_alt f (third f) myfld.one, rw simp_mul_one f _, rw <- mul_negate_alt f (b .* b) (third f), /- The constant goal is a bit more complicated, but all it really involves is collecting together the b^3 terms and reducing the coefficient of each term to a single power of three.-/ unfold cubed, repeat {rw mul_negate f _ _}, repeat {rw mul_negate_alt_simp f _ _}, repeat {rw double_negative f _}, rw myfld.mul_assoc (twenty_seventh f) (twenty_seven f) _, rw myfld.mul_comm (twenty_seventh f) (twenty_seven f), unfold twenty_seventh, rw myfld.mul_reciprocal (twenty_seven f) _, rw one_mul_simp f _, rw myfld.mul_assoc (myfld.reciprocal (twenty_seven f) _) (nine f), rw only_one_reciprocal f (twenty_seven f) _ (twenty_seven_ne_zero f), have tmp : ((myfld.reciprocal (twenty_seven f) (twenty_seven_ne_zero f)) .* (nine f)) = (myfld.reciprocal (three f) fld_not_char_three.not_char_three), unfold twenty_seven, unfold nine, rw split_reciprocal f _ _ _, rw split_reciprocal f _ _ _, repeat {rw <- myfld.mul_assoc _ _ _}, rw myfld.mul_assoc (myfld.reciprocal _ _) (three f) _, rw myfld.mul_comm (myfld.reciprocal (three f) _) (three f), rw myfld.mul_reciprocal (three f) _, rw one_mul_simp f _, rw myfld.mul_comm (myfld.reciprocal (three f) _) (three f), rw myfld.mul_reciprocal (three f) _, rw simp_mul_one f _, rw myfld.mul_assoc (myfld.reciprocal (twenty_seven f) _) (nine f) _, rw tmp, clear tmp, rw myfld.mul_assoc _ (two f) _, rw myfld.mul_comm _ (two f), rw <- myfld.mul_assoc (two f) _ _, unfold two, rw distrib_simp f myfld.one myfld.one _, rw one_mul_simp f _, rw myfld.add_assoc _ (b .* ((third f) .* (b .* ((third f) .* b)))) _, rw helper_bcubed f b, have tmp : ((three f) .* ((myfld.reciprocal (twenty_seven f) _) .* ((b .* b) .* b))) = (myfld.one .* ((three f) .* ((myfld.reciprocal (twenty_seven f) _) .* ((b .* b) .* b)))), rw one_mul_simp f _, rewrite [tmp] {occs := occurrences.pos [2]}, clear tmp, rw <- mul_negate f (third f) _, rw <- distrib_simp f _ _ _, rw helper_twothirds f, rw distrib_simp f (third f) (third f) _, rw myfld.mul_assoc (third f) (three f) _, have tmp : (third f) .* (three f) = myfld.one, unfold third, rw myfld.mul_comm _ _, rw myfld.mul_reciprocal (three f) _, rw tmp, rw one_mul_simp f _, clear tmp, rw myfld.mul_assoc c (third f) b, rw myfld.mul_comm c (third f), rw <- myfld.mul_assoc (third f) c b, rw myfld.mul_comm c b, rw myfld.mul_assoc b b b, unfold third, end /- We have now proven that every cubic equation can be reduced to a cubic equation where the x^3 coefficient is 1, that every such cubic can be reduced to a depressed cubic, and that every depressed cubic can be solved with Cardano's formula. This is therefore enough for a solution to any general cubic. The one wrinkle in this is that the Cardano formula only works if the x term is not equal to zero. If the x term is equal to zero then the solution is trivial (x just equals zero minus the cube root of the constant), but this cannot be represented as part of the same formula using our notion of reciprocals. Ergo, to get a general cubic formula we need to assume that it is always decidable whether a value is zero or not.-/ lemma int_quantity_ne_zero_simp (f : Type) [myfld f] [fld_not_char_three f] (a1 b c : f) (a_ne_zero : a1 ≠ myfld.zero) : ((three f) .* (a1 .* c)) .+ (.- (square f b)) ≠ myfld.zero -> (((square f (b .* (myfld.reciprocal a1 a_ne_zero))) .* (.- (third f))) .+ (c .* (myfld.reciprocal a1 a_ne_zero))) ≠ myfld.zero := begin intros h1 h2, unfold square at h2, rw myfld.mul_comm _ (.- _) at h2, repeat {rw myfld.mul_assoc _ _ (myfld.reciprocal a1 a_ne_zero) at h2}, rw <- distrib_simp f _ _ _ at h2, rw <- mul_zero_by_reciprocal f a1 _ _ at h2, rw mul_both_sides f _ _ (three f) at h2, rw mul_zero at h2, rw distrib_simp at h2, repeat {rw mul_negate at h2}, rw myfld.mul_comm (_ .* _) (three f) at h2, rw myfld.mul_assoc (three f) (third f) _ at h2, unfold third at h2, rw myfld.mul_reciprocal (three f) _ at h2, rw one_mul_simp at h2, rw mul_both_sides f _ _ a1 at h2, rw distrib_simp at h2, rw mul_zero at h2, rw mul_negate at h2, rw myfld.mul_comm _ b at h2, repeat {rw <- myfld.mul_assoc at h2}, rw myfld.mul_comm _ a1 at h2, rw myfld.mul_reciprocal a1 _ at h2, rw simp_mul_one at h2, unfold square at h1, rw myfld.mul_comm c _ at h2, rw myfld.mul_assoc at h1, rw myfld.add_comm at h1, cc, cc, exact fld_not_char_three.not_char_three, end def cubic_formula_a (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (a b c d : f) (a_ne_zero : a ≠ myfld.zero) (int_quantity_ne_zero : ((three f) .* (a .* c)) .+ (.- (square f b)) ≠ myfld.zero) : f := ((cardano_formula_a f (((square f (b .* (myfld.reciprocal a a_ne_zero))) .* (.- (third f))) .+ (c .* (myfld.reciprocal a a_ne_zero))) ((twenty_seventh f) .* ((((two f) .* (cubed f (b .* (myfld.reciprocal a a_ne_zero)))) .+ (.- ((nine f) .* ((b .* (myfld.reciprocal a a_ne_zero)) .* (c .* (myfld.reciprocal a a_ne_zero)))))) .+ ((twenty_seven f) .* (d .* (myfld.reciprocal a a_ne_zero))))) (int_quantity_ne_zero_simp f a b c a_ne_zero int_quantity_ne_zero)) .+ (.- ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f)))) lemma cubic_formula_a_correct (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (a b c d : f) (a_ne_zero : a ≠ myfld.zero) (int_quantity_ne_zero : ((three f) .* (a .* c)) .+ (.- (square f b)) ≠ myfld.zero) : cubic_subst f a b c d (cubic_formula_a f a b c d a_ne_zero int_quantity_ne_zero) = myfld.zero := begin rw divide_cubic_through f a b c d _ a_ne_zero, have tmp : (cubic_formula_a f a b c d a_ne_zero int_quantity_ne_zero) = (((cubic_formula_a f a b c d a_ne_zero int_quantity_ne_zero) .+ ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f))) .+ (.- ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f)))), simp, rw reduce_cubic_to_depressed f (b .* (myfld.reciprocal a a_ne_zero)) (c .* (myfld.reciprocal a a_ne_zero)) (d .* (myfld.reciprocal a a_ne_zero)) (cubic_formula_a f a b c d a_ne_zero int_quantity_ne_zero) ((cubic_formula_a f a b c d a_ne_zero int_quantity_ne_zero) .+ ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f))) tmp, clear tmp, unfold cubic_formula_a, unfold cardano_formula_a, rw <- myfld.add_assoc (cardano_formula f _ _ _ _ _ _) (.- _) _, rw myfld.add_comm (.- _) _, rw myfld.add_negate _, rw zero_simp f _, exact cardano_works f _ _ _ _ _ _, end def cubic_formula_b (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (a b c d : f) (a_ne_zero : a ≠ myfld.zero) (int_quantity_ne_zero : ((three f) .* (a .* c)) .+ (.- (square f b)) ≠ myfld.zero) : f := ((cardano_formula_b f (((square f (b .* (myfld.reciprocal a a_ne_zero))) .* (.- (third f))) .+ (c .* (myfld.reciprocal a a_ne_zero))) ((twenty_seventh f) .* ((((two f) .* (cubed f (b .* (myfld.reciprocal a a_ne_zero)))) .+ (.- ((nine f) .* ((b .* (myfld.reciprocal a a_ne_zero)) .* (c .* (myfld.reciprocal a a_ne_zero)))))) .+ ((twenty_seven f) .* (d .* (myfld.reciprocal a a_ne_zero))))) (int_quantity_ne_zero_simp f a b c a_ne_zero int_quantity_ne_zero)) .+ (.- ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f)))) lemma cubic_formula_b_correct (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (a b c d : f) (a_ne_zero : a ≠ myfld.zero) (int_quantity_ne_zero : ((three f) .* (a .* c)) .+ (.- (square f b)) ≠ myfld.zero) : cubic_subst f a b c d (cubic_formula_b f a b c d a_ne_zero int_quantity_ne_zero) = myfld.zero := begin rw divide_cubic_through f a b c d _ a_ne_zero, have tmp : (cubic_formula_b f a b c d a_ne_zero int_quantity_ne_zero) = (((cubic_formula_b f a b c d a_ne_zero int_quantity_ne_zero) .+ ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f))) .+ (.- ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f)))), simp, rw reduce_cubic_to_depressed f (b .* (myfld.reciprocal a a_ne_zero)) (c .* (myfld.reciprocal a a_ne_zero)) (d .* (myfld.reciprocal a a_ne_zero)) (cubic_formula_b f a b c d a_ne_zero int_quantity_ne_zero) ((cubic_formula_b f a b c d a_ne_zero int_quantity_ne_zero) .+ ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f))) tmp, clear tmp, unfold cubic_formula_b, unfold cardano_formula_b, rw <- myfld.add_assoc (cardano_formula f _ _ _ _ _ _) (.- _) _, rw myfld.add_comm (.- _) _, rw myfld.add_negate _, rw zero_simp f _, exact cardano_works f _ _ _ _ _ _, end def cubic_formula_c (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (a b c d : f) (a_ne_zero : a ≠ myfld.zero) (int_quantity_ne_zero : ((three f) .* (a .* c)) .+ (.- (square f b)) ≠ myfld.zero) : f := ((cardano_formula_c f (((square f (b .* (myfld.reciprocal a a_ne_zero))) .* (.- (third f))) .+ (c .* (myfld.reciprocal a a_ne_zero))) ((twenty_seventh f) .* ((((two f) .* (cubed f (b .* (myfld.reciprocal a a_ne_zero)))) .+ (.- ((nine f) .* ((b .* (myfld.reciprocal a a_ne_zero)) .* (c .* (myfld.reciprocal a a_ne_zero)))))) .+ ((twenty_seven f) .* (d .* (myfld.reciprocal a a_ne_zero))))) (int_quantity_ne_zero_simp f a b c a_ne_zero int_quantity_ne_zero)) .+ (.- ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f)))) lemma cubic_formula_c_correct (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (a b c d : f) (a_ne_zero : a ≠ myfld.zero) (int_quantity_ne_zero : ((three f) .* (a .* c)) .+ (.- (square f b)) ≠ myfld.zero) : cubic_subst f a b c d (cubic_formula_c f a b c d a_ne_zero int_quantity_ne_zero) = myfld.zero := begin rw divide_cubic_through f a b c d _ a_ne_zero, have tmp : (cubic_formula_c f a b c d a_ne_zero int_quantity_ne_zero) = (((cubic_formula_c f a b c d a_ne_zero int_quantity_ne_zero) .+ ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f))) .+ (.- ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f)))), simp, rw reduce_cubic_to_depressed f (b .* (myfld.reciprocal a a_ne_zero)) (c .* (myfld.reciprocal a a_ne_zero)) (d .* (myfld.reciprocal a a_ne_zero)) (cubic_formula_c f a b c d a_ne_zero int_quantity_ne_zero) ((cubic_formula_c f a b c d a_ne_zero int_quantity_ne_zero) .+ ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f))) tmp, clear tmp, unfold cubic_formula_c, unfold cardano_formula_c, rw <- myfld.add_assoc (cardano_formula f _ _ _ _ _ _) (.- _) _, rw myfld.add_comm (.- _) _, rw myfld.add_negate _, rw zero_simp f _, exact cardano_works f _ _ _ _ _ _, end lemma int_quantity_eq_zero_simp (f : Type) [myfld f] [fld_not_char_three f] (a1 b c : f) (a_ne_zero : a1 ≠ myfld.zero) : ((three f) .* (a1 .* c)) .+ (.- (square f b)) = myfld.zero -> (((square f (b .* (myfld.reciprocal a1 a_ne_zero))) .* (.- (third f))) .+ (c .* (myfld.reciprocal a1 a_ne_zero))) = myfld.zero := begin intros h, unfold square, rw myfld.mul_comm _ (.- _), repeat {rw myfld.mul_assoc _ _ (myfld.reciprocal a1 a_ne_zero) }, rw <- distrib_simp f _ _ _, rw <- mul_zero_by_reciprocal f a1 _ _, rw mul_both_sides f _ _ (three f), rw mul_zero, rw distrib_simp, repeat {rw mul_negate}, rw myfld.mul_comm (_ .* _) (three f), rw myfld.mul_assoc (three f) (third f) _, unfold third, rw myfld.mul_reciprocal (three f) _, rw one_mul_simp, rw mul_both_sides f _ _ a1, rw distrib_simp, rw mul_zero, rw mul_negate, rw myfld.mul_comm _ b, repeat {rw <- myfld.mul_assoc}, rw myfld.mul_comm _ a1, rw myfld.mul_reciprocal a1 _, rw simp_mul_one, unfold square at h, rw myfld.mul_comm c _, rw myfld.mul_assoc at h, rw myfld.add_comm at h, cc, cc, exact fld_not_char_three.not_char_three, end def cubic_formula_a_alt (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (a b c d : f) (a_ne_zero : a ≠ myfld.zero) (int_quantity_eq_zero : ((three f) .* (a .* c)) .+ (.- (square f b)) = myfld.zero) : f := ((depressed_cubic_solution_c_zero_a f (((square f (b .* (myfld.reciprocal a a_ne_zero))) .* (.- (third f))) .+ (c .* (myfld.reciprocal a a_ne_zero))) ((twenty_seventh f) .* ((((two f) .* (cubed f (b .* (myfld.reciprocal a a_ne_zero)))) .+ (.- ((nine f) .* ((b .* (myfld.reciprocal a a_ne_zero)) .* (c .* (myfld.reciprocal a a_ne_zero)))))) .+ ((twenty_seven f) .* (d .* (myfld.reciprocal a a_ne_zero))))) (int_quantity_eq_zero_simp f a b c a_ne_zero int_quantity_eq_zero)) .+ (.- ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f)))) lemma cubic_formula_a_alt_correct (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (a b c d : f) (a_ne_zero : a ≠ myfld.zero) (int_quantity_eq_zero : ((three f) .* (a .* c)) .+ (.- (square f b)) = myfld.zero) : cubic_subst f a b c d (cubic_formula_a_alt f a b c d a_ne_zero int_quantity_eq_zero) = myfld.zero := begin rw divide_cubic_through f a b c d _ a_ne_zero, have tmp : (cubic_formula_a_alt f a b c d a_ne_zero int_quantity_eq_zero) = (((cubic_formula_a_alt f a b c d a_ne_zero int_quantity_eq_zero) .+ ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f))) .+ (.- ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f)))), simp, rw reduce_cubic_to_depressed f (b .* (myfld.reciprocal a a_ne_zero)) (c .* (myfld.reciprocal a a_ne_zero)) (d .* (myfld.reciprocal a a_ne_zero)) (cubic_formula_a_alt f a b c d a_ne_zero int_quantity_eq_zero) ((cubic_formula_a_alt f a b c d a_ne_zero int_quantity_eq_zero) .+ ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f))) tmp, clear tmp, unfold cubic_formula_a_alt, unfold depressed_cubic_solution_c_zero_a, rw <- myfld.add_assoc (depressed_cubic_solution_c_zero f _ _ _ _ _) (.- _) _, rw myfld.add_comm (.- _) _, rw myfld.add_negate _, rw zero_simp f _, exact depressed_cubic_solution_c_zero_correct f _ _ _ fld_with_cube_root.cubrt (cubrt_cubed f), end def cubic_formula_b_alt (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (a b c d : f) (a_ne_zero : a ≠ myfld.zero) (int_quantity_eq_zero : ((three f) .* (a .* c)) .+ (.- (square f b)) = myfld.zero) : f := ((depressed_cubic_solution_c_zero_b f (((square f (b .* (myfld.reciprocal a a_ne_zero))) .* (.- (third f))) .+ (c .* (myfld.reciprocal a a_ne_zero))) ((twenty_seventh f) .* ((((two f) .* (cubed f (b .* (myfld.reciprocal a a_ne_zero)))) .+ (.- ((nine f) .* ((b .* (myfld.reciprocal a a_ne_zero)) .* (c .* (myfld.reciprocal a a_ne_zero)))))) .+ ((twenty_seven f) .* (d .* (myfld.reciprocal a a_ne_zero))))) (int_quantity_eq_zero_simp f a b c a_ne_zero int_quantity_eq_zero)) .+ (.- ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f)))) def cubic_formula_c_alt (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (a b c d : f) (a_ne_zero : a ≠ myfld.zero) (int_quantity_eq_zero : ((three f) .* (a .* c)) .+ (.- (square f b)) = myfld.zero) : f := ((depressed_cubic_solution_c_zero_c f (((square f (b .* (myfld.reciprocal a a_ne_zero))) .* (.- (third f))) .+ (c .* (myfld.reciprocal a a_ne_zero))) ((twenty_seventh f) .* ((((two f) .* (cubed f (b .* (myfld.reciprocal a a_ne_zero)))) .+ (.- ((nine f) .* ((b .* (myfld.reciprocal a a_ne_zero)) .* (c .* (myfld.reciprocal a a_ne_zero)))))) .+ ((twenty_seven f) .* (d .* (myfld.reciprocal a a_ne_zero))))) (int_quantity_eq_zero_simp f a b c a_ne_zero int_quantity_eq_zero)) .+ (.- ((b .* (myfld.reciprocal a a_ne_zero)) .* (third f)))) /- And so, as long as it is decidable whether a quantity is equal to zero or not, we have a viable solution to any cubic.-/ /- The next goal is to prove uniqueness of those solutions. As thie is going to involve the cardano formula and the cube roots of unity, we can start with some intermediate lemmae.-/ lemma cube_roots_sum_zero (f : Type) [myfld f] [fld_with_sqrt f] [fld_not_char_two f] [fld_with_cube_root f] (x : f) : (fld_with_cube_root.cubrt x) .+ ((alt_cubrt_a f x) .+ (alt_cubrt_b f x)) = myfld.zero := begin unfold alt_cubrt_a, unfold alt_cubrt_b, unfold cube_root_of_unity, rw <- distrib_simp f _ _ (fld_with_cube_root.cubrt x), have tmp : (fld_with_cube_root.cubrt x) = myfld.one .* (fld_with_cube_root.cubrt x) , rw myfld.mul_comm, exact myfld.mul_one (fld_with_cube_root.cubrt x), rw [tmp] {occs := occurrences.pos [1]}, clear tmp, rw <- distrib_simp f _ _ (fld_with_cube_root.cubrt x), have h : (myfld.one .+ (( .- myfld.one .+ sqroot .- (three f)) .* (myfld.reciprocal (two f) _) .+ ( .- myfld.one .+ .- sqroot .- (three f)) .* (myfld.reciprocal (two f) _))) = myfld.zero, rw myfld.add_comm _ (.- (sqroot _)), rw distrib_simp f _ _ _, rw distrib_simp f _ _ _, repeat {rw mul_negate f _ _}, rw one_mul_simp f _, repeat {rw <- myfld.add_assoc _ _ _}, rw myfld.add_assoc (_ .* _) (.- _) _, rw myfld.add_negate _, rw simp_zero f _, rw <- add_negate f _ _, rw only_one_reciprocal f (two f) _ (two_ne_zero f), rw add_two_halves f, exact myfld.add_negate myfld.one, rw h, exact mul_zero f _, end /- Proving uniqueness will involve expalnding the cubic (x - solution_a) (x - solution_b) (x - solution_c) . This is the x^2 term (0) in the resulting cubic.-/ lemma cardano_formulae_sum_zero (f : Type) [myfld f] [fld_with_sqrt f] [fld_not_char_two f] [fld_with_cube_root f] [fld_not_char_three f] (c d : f) (c_ne_zero : c ≠ myfld.zero) : (cardano_formula_a f c d c_ne_zero) .+ ((cardano_formula_b f c d c_ne_zero) .+ (cardano_formula_c f c d c_ne_zero)) = myfld.zero := begin have mul_zero_by_anything : ∀(x y : f), (x = myfld.zero) -> x .* y = myfld.zero, intros x y hx, rw hx, rw mul_zero, unfold cardano_formula_a, unfold cardano_formula_b, unfold cardano_formula_c, unfold cardano_formula, /- First move all the cube root terms to the start - they must sum to zero by the previous lemma.-/ rw <- myfld.add_assoc (alt_cubrt_a f _) _ _, rw myfld.add_assoc _ (alt_cubrt_b f _) _, rw myfld.add_comm _ (alt_cubrt_b f _), rw <- myfld.add_assoc (alt_cubrt_b f _) _ _, rw myfld.add_assoc (alt_cubrt_a f _) (alt_cubrt_b f _) _, rw myfld.add_assoc (_ .+ _) (_ .+ _) (_ .+ _), rw <- myfld.add_assoc (fld_with_cube_root.cubrt _) (.- _) (_ .+ _), rw myfld.add_comm (.- _) ((alt_cubrt_a f _) .+ (alt_cubrt_b f _)), rw myfld.add_assoc (fld_with_cube_root.cubrt _) (_ .+ _) (.- _), rw cube_roots_sum_zero f _, rw simp_zero f _, /- The three remaining terms are all -c/3x, where x is one of the three cube roots. We can first use distributivity to make this into the sum of the reciprocals of the cube roots.-/ rw <- add_negate f _ _, rw <- add_negate f _ _, apply negate_zero_a f _, rw <- distrib_simp_alt f c _ _, rw <- distrib_simp_alt f c _ _, rw myfld.mul_comm c _, apply mul_zero_by_anything _ c, repeat {rw <- mul_two_reciprocals f _ (three f) _ _}, rw only_one_reciprocal f (three f) _ fld_not_char_three.not_char_three, rw <- distrib_simp f _ _ (myfld.reciprocal (three f) fld_not_char_three.not_char_three), rw <- distrib_simp f _ _ (myfld.reciprocal (three f) fld_not_char_three.not_char_three), apply mul_zero_by_anything _ (myfld.reciprocal (three f) fld_not_char_three.not_char_three), unfold alt_cubrt_a, unfold alt_cubrt_b, rw split_reciprocal f _ (fld_with_cube_root.cubrt ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))), rw split_reciprocal f _ (fld_with_cube_root.cubrt ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))), rw only_one_reciprocal f _ _ (cubrt_nonzero f _ (cardano_den_not_zero_int f c d c_ne_zero)), rw <- distrib_simp f _ _ _, have tmp : (myfld.reciprocal (fld_with_cube_root.cubrt ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))) _) = myfld.one .* (myfld.reciprocal (fld_with_cube_root.cubrt ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))) _) , rw myfld.mul_comm myfld.one _, exact myfld.mul_one _, exact cubrt_nonzero f _ (cardano_den_not_zero_int f c d c_ne_zero), rw [tmp] {occs := occurrences.pos [1]}, clear tmp, rw only_one_reciprocal f _ _ (cubrt_nonzero f _ (cardano_den_not_zero_int f c d c_ne_zero)), rw <- distrib_simp f _ _ _, apply mul_zero_by_anything _ _, /- And now we just prove that the reciprocals of the cube roots of unity add to zero. -/ unfold cube_root_of_unity, repeat {rw split_reciprocal f _ _ _}, rw double_reciprocal f _ _, rw <- distrib_simp f _ _ (two f), rw add_two_reciprocals f _ _ _ _, rw <- myfld.add_assoc (.- myfld.one) _ (_ .+ _), have tmp : (.- myfld.one) .+ (.- (sqroot (.- (three f)))) = (.- (sqroot (.- (three f)))) .+ (.- myfld.one) , exact myfld.add_comm (.- myfld.one) (.- (sqroot (.- (three f)))), rw [tmp] {occs := occurrences.pos [1]}, clear tmp, rw myfld.add_assoc (sqroot _) (.- (sqroot _)) _, rw myfld.add_negate (sqroot (.- (three f))), rw simp_zero f _, rw <- add_negate f myfld.one myfld.one, rw reciprocal_rewrite f _ _ (difference_of_squares f (.- myfld.one) (sqroot (.- (three f)))) _, have simp_den : ((square f (.- myfld.one)) .+ (.- (square f (sqroot (.- (three f)))))) = (two f) .* (two f) , unfold square, rw mul_negate f _ _, rw <- mul_negate_alt f _ _, rw double_negative f _, rw simp_mul_one f _, rw fld_with_sqrt.sqrt_mul_sqrt _, rw double_negative f _, unfold three, unfold two, simp, rw reciprocal_rewrite f _ ((two f) .* (two f)) simp_den _, rw <- myfld.mul_assoc _ _ _, rw split_reciprocal f (two f) (two f) _, rw <- myfld.mul_assoc (myfld.reciprocal (two f) _) (myfld.reciprocal (two f) _) (two f), rw myfld.mul_comm (myfld.reciprocal (two f) _) (two f), rw myfld.mul_reciprocal (two f) _, rw simp_mul_one f _, rw mul_negate f _ _, unfold two, rw myfld.mul_reciprocal (myfld.one .+ myfld.one) _, exact myfld.add_negate myfld.one, /- And now we just do some of the leftover detritus from the "applies" earlier.-/ apply alt_cubrt_b_nonzero f _, exact cardano_den_not_zero_int f c d c_ne_zero, exact fld_not_char_three.not_char_three, apply alt_cubrt_a_nonzero f _, exact cardano_den_not_zero_int f c d c_ne_zero, end lemma cardano_products (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (c d x : f) (c_ne_zero : c ≠ myfld.zero) : ((((cardano_formula_a f c d c_ne_zero) .* (cardano_formula_b f c d c_ne_zero)) .+ ((cardano_formula_a f c d c_ne_zero) .* (cardano_formula_c f c d c_ne_zero))) .+ ((cardano_formula_b f c d c_ne_zero) .* (cardano_formula_c f c d c_ne_zero))) = c := begin /- I'm so sorry about this line. What it does is simplify the proof by reducing it to solving the same goal where some of the more complex recurring expressions have been folded down. However, the only nice way to do that is with mathlib, and there are reasons why I *really* didn't want to use that.-/ have folded_version : ∀ (cubrt root_unity_a root_unity_b : f), ∀ (cubrt_ne_zero : cubrt ≠ myfld.zero), ∀ (root_unity_a_ne_zero : root_unity_a ≠ myfld.zero), ∀ (root_unity_b_ne_zero : root_unity_b ≠ myfld.zero), (cubrt = (fld_with_cube_root.cubrt ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))) -> root_unity_a = (cube_root_of_unity f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))) -> root_unity_b = (cube_root_of_unity f (.- (sqroot (.- (three f)))) (negative_sqrt f (.- (three f)))) -> (((cubrt .+ (.- (c .* (myfld.reciprocal (cubrt .* (three f)) (mul_nonzero f cubrt (three f) cubrt_ne_zero fld_not_char_three.not_char_three))))) .* ((root_unity_a .* cubrt) .+ (.- (c .* (myfld.reciprocal ((root_unity_a .* cubrt) .* (three f)) (mul_nonzero f (root_unity_a .* cubrt) (three f) (mul_nonzero f root_unity_a cubrt root_unity_a_ne_zero cubrt_ne_zero) fld_not_char_three.not_char_three)))))) .+ ((cubrt .+ (.- (c .* (myfld.reciprocal (cubrt .* (three f)) (mul_nonzero f cubrt (three f) cubrt_ne_zero fld_not_char_three.not_char_three))))) .* ((root_unity_b .* cubrt) .+ (.- (c .* (myfld.reciprocal ((root_unity_b .* cubrt) .* (three f)) (mul_nonzero f (root_unity_b .* cubrt) (three f) (mul_nonzero f root_unity_b cubrt root_unity_b_ne_zero cubrt_ne_zero) fld_not_char_three.not_char_three))))))) .+ (((root_unity_a .* cubrt) .+ (.- (c .* (myfld.reciprocal ((root_unity_a .* cubrt) .* (three f)) (mul_nonzero f (root_unity_a .* cubrt) (three f) (mul_nonzero f root_unity_a cubrt root_unity_a_ne_zero cubrt_ne_zero) fld_not_char_three.not_char_three))))) .* ((root_unity_b .* cubrt) .+ (.- (c .* (myfld.reciprocal ((root_unity_b .* cubrt) .* (three f)) (mul_nonzero f (root_unity_b .* cubrt) (three f) (mul_nonzero f root_unity_b cubrt root_unity_b_ne_zero cubrt_ne_zero) fld_not_char_three.not_char_three)))))) = c), intros cubrt root_unity_a root_unity_b cubrt_n_zero rta_n_zero rtb_n_zero cubrt_h root_unity_a_h root_unity_b_h, /- OK, so that hideous line means that the proof in the sidebar looks much less hideous, but we can still use it to solve the main proof once we finish.-/ /- First take a moment to restate some of the properties of roots.-/ have sum_roots_zero : myfld.one .+ (root_unity_a .+ root_unity_b) = myfld.zero, rw root_unity_a_h, rw root_unity_b_h, have tmp : myfld.one .+ ((cubrt_unity_a f) .+ (cubrt_unity_b f)) = myfld.zero, exact cubrts_unity_sum_zero f, unfold cubrt_unity_a at tmp, unfold cubrt_unity_b at tmp, unfold cube_root_of_unity, exact tmp, have product_roots_one : root_unity_a .* root_unity_b = myfld.one, rw root_unity_a_h, rw root_unity_b_h, unfold cube_root_of_unity, rw <- myfld.mul_assoc _ (myfld.reciprocal (two f) _) _, rw myfld.mul_comm (myfld.reciprocal (two f) _) _, rw <- myfld.mul_assoc _ (myfld.reciprocal (two f) _) (myfld.reciprocal (two f) _), rw mul_two_reciprocals f (two f) (two f) _ _, rw myfld.mul_assoc _ _ (myfld.reciprocal _ _), rw difference_of_squares f (.- (myfld.one)) _, rw sqrt_squared f _, unfold square, rw mul_negate f _ _, rw mul_negate_alt_simp f _ _, repeat {rw double_negative f _}, rw one_mul_simp f _, unfold two, unfold three, simp, have root_a_reciprocal : ∀ (rta_prf : root_unity_a ≠ myfld.zero), myfld.reciprocal root_unity_a rta_prf = root_unity_b, intros prf, symmetry, exact only_one_reciprocal_alt f root_unity_a root_unity_b _ product_roots_one, have root_b_reciprocal : ∀ (rtb_prf : root_unity_b ≠ myfld.zero), myfld.reciprocal root_unity_b rtb_prf = root_unity_a, intros prf, symmetry, rw myfld.mul_comm at product_roots_one, exact only_one_reciprocal_alt f root_unity_b root_unity_a _ product_roots_one, have sum_alt_roots_minusone : root_unity_a .+ root_unity_b = .- myfld.one, have tmp : (myfld.one .+ (root_unity_a .+ root_unity_b)) .+ (.- myfld.one) = .- myfld.one, rw sum_roots_zero, rw simp_zero f _, rw <- myfld.add_assoc myfld.one (_ .+ _) (.- _) at tmp, rw myfld.add_comm (_ .+ _) (.- myfld.one) at tmp, rw myfld.add_assoc myfld.one (.- myfld.one) _ at tmp, rw myfld.add_negate myfld.one at tmp, rw simp_zero f _ at tmp, exact tmp, have root_a_squ : root_unity_a .* root_unity_a = root_unity_b, have tmp : root_unity_a .+ (myfld.reciprocal root_unity_a rta_n_zero) = .- (myfld.one), rw root_a_reciprocal rta_n_zero, exact sum_alt_roots_minusone, have tmp2 : (root_unity_a .+ (myfld.reciprocal root_unity_a rta_n_zero)) .* root_unity_a = .- root_unity_a, rw tmp, rw mul_negate f _ _, rw one_mul_simp f root_unity_a, clear tmp, rw distrib_simp f _ _ _ at tmp2, rw carry_term_across f (root_unity_a .* root_unity_a) (.- root_unity_a) ((myfld.reciprocal root_unity_a rta_n_zero) .* root_unity_a) at tmp2, rw myfld.mul_comm (myfld.reciprocal _ _) root_unity_a at tmp2, rw myfld.mul_reciprocal root_unity_a _ at tmp2, rw myfld.add_assoc at sum_roots_zero, rw myfld.add_comm (_ .+ _) root_unity_b at sum_roots_zero, rw carry_term_across f _ _ _ at sum_roots_zero, rw <- add_negate _ _ at tmp2, rw simp_zero _ at sum_roots_zero, rw myfld.add_comm root_unity_a myfld.one at tmp2, rw <- sum_roots_zero at tmp2, exact tmp2, have root_b_squ : root_unity_b .* root_unity_b = root_unity_a, rw <- root_a_squ, rw [root_a_squ] {occs := occurrences.pos [2]}, rw <- myfld.mul_assoc, rw product_roots_one, rw <- myfld.mul_one root_unity_a, /-have a_squared_b : root_unity_a .* root_unity_a = root_unity_b, rw root_unity_a_h, rw root_unity_b_h, -/ /- Start by multiplying out all the brackets and cancelling in terms with cubrt * reciprocal (cubrt) .-/ repeat {rw distrib_simp f _ _ _}, repeat {rw distrib_simp_alt f _ _ _}, repeat {rw mul_negate f _ _}, repeat {rw mul_negate_alt_simp f _ _}, repeat {rw double_negative f _}, have tmp : ∀ (x : f), ((x .* cubrt) .* (three f)) = cubrt .* (x .* (three f)) , intro x, simp, rw reciprocal_rewrite f _ _ (tmp root_unity_a) _, rw reciprocal_rewrite f _ _ (tmp root_unity_b) _, /- Some sensible-looking stuff now doesn't work because it's rewriting inside the proofs that are keeping the reciprocals legal. -/ /- To make it work we're gonna need to do a massive only_one_reciprocal.-/ rw only_one_reciprocal f (cubrt .* (root_unity_a .* (three f))) _ (mul_nonzero f cubrt (root_unity_a .* (three f)) cubrt_n_zero (mul_nonzero f root_unity_a (three f) rta_n_zero fld_not_char_three.not_char_three)), rw only_one_reciprocal f (cubrt .* (root_unity_b .* (three f))) _ (mul_nonzero f cubrt (root_unity_b .* (three f)) cubrt_n_zero (mul_nonzero f root_unity_b (three f) rtb_n_zero fld_not_char_three.not_char_three)), repeat {rw myfld.mul_comm _ cubrt}, repeat {rw myfld.mul_assoc cubrt c (myfld.reciprocal _ _) }, repeat {rw myfld.mul_comm cubrt c}, repeat {rw <- myfld.mul_assoc c cubrt (myfld.reciprocal _ _) }, repeat {rw cancel_from_reciprocal_alt f cubrt _ _}, repeat {rw myfld.mul_assoc (c .* _) cubrt _}, repeat {rw <- myfld.mul_assoc c (myfld.reciprocal _ _) cubrt}, repeat {rw cancel_from_reciprocal f cubrt _ _}, /- Now we gather all of the (cubrt^2) terms together, and they cancel out as there is one for each of the cube roots of unity.-/ rw myfld.mul_assoc (cubrt .* root_unity_a) cubrt root_unity_b, rw myfld.mul_comm (cubrt .* root_unity_a) cubrt, repeat {rw myfld.mul_assoc cubrt cubrt _}, repeat {rw <- myfld.mul_assoc (cubrt .* cubrt) _ _}, repeat {rw <- myfld.add_assoc ((cubrt .* cubrt) .* _) _ _}, repeat {rw myfld.add_assoc _ ((cubrt .* cubrt) .* _) _}, repeat {rw myfld.add_comm _ ((cubrt .* cubrt) .* _) }, repeat {rw <- myfld.add_assoc ((cubrt .* cubrt) .* _) _ _}, rw myfld.add_assoc ((cubrt .* cubrt) .* _) ((cubrt .* cubrt) .* _) _, rw <- distrib_simp_alt f (cubrt .* cubrt) _ _, rw myfld.add_assoc ((cubrt .* cubrt) .* _) ((cubrt .* cubrt) .* _) _, rw <- distrib_simp_alt f (cubrt .* cubrt) _ _, rw product_roots_one, rw myfld.add_comm root_unity_a myfld.one, rw <- myfld.add_assoc myfld.one root_unity_a root_unity_b, rw sum_roots_zero, rw zero_mul f _, rw simp_zero f _, /- Now we can do the same with the terms containing a factor of c^2/cubrt^2-/ have tmp2 : ∀ (x y : f), (c .* x) .* (c .* y) = (c .* c) .* (x .* y) , intros x y, rw myfld.mul_assoc (c .* x) c y, rw <- myfld.mul_assoc c x c, rw myfld.mul_comm x c, rw myfld.mul_assoc _ _ _, rw myfld.mul_assoc _ _ _, repeat {rw tmp2 _ _}, clear tmp2, clear tmp, repeat {rw mul_two_reciprocals f _ _ _ _}, /- We now have some convoluted reciprocals that need to be simplified. This needs to be done in sub-proofs so that it can be done in a single step with reciprocal_rewrite.-/ have reciprocal_1 : ((cubrt .* (three f)) .* (cubrt .* (root_unity_a .* (three f)))) = (square f (cubrt .* (three f))) .* root_unity_a, unfold square, simp, rw reciprocal_rewrite f _ _ reciprocal_1 _, have reciprocal_2 : ((cubrt .* (three f)) .* (cubrt .* (root_unity_b .* (three f)))) = (square f (cubrt .* (three f))) .* root_unity_b, unfold square, simp, rw reciprocal_rewrite f _ _ reciprocal_2 _, have reciprocal_3 : ((cubrt .* (root_unity_a .* (three f))) .* (cubrt .* (root_unity_b .* (three f)))) = (square f (cubrt .* (three f))) .* (root_unity_a .* root_unity_b) , unfold square, exact mul_complex f _ _ _ _, rw product_roots_one at reciprocal_3, rw reciprocal_rewrite f _ _ reciprocal_3 _, repeat {rw split_reciprocal f (square f (cubrt .* (three f))) _ _}, repeat {rw myfld.mul_assoc (c .* c) (myfld.reciprocal (square f _) _) (myfld.reciprocal _ _) }, repeat {rw myfld.add_comm _ (((c .* c) .* (myfld.reciprocal _ _)) .* (myfld.reciprocal _ _)) }, repeat {rw myfld.add_assoc _ (((c .* c) .* (myfld.reciprocal _ _)) .* (myfld.reciprocal _ _)) _}, repeat {rw myfld.add_comm _ (((c .* c) .* (myfld.reciprocal _ _)) .* (myfld.reciprocal _ _)) }, repeat {rw <- myfld.add_assoc (((c .* c) .* (myfld.reciprocal _ _)) .* (myfld.reciprocal _ _)) _ _}, repeat {rw myfld.add_assoc _ (((c .* c) .* (myfld.reciprocal _ _)) .* (myfld.reciprocal _ _)) _}, repeat {rw myfld.add_comm _ (((c .* c) .* (myfld.reciprocal _ _)) .* (myfld.reciprocal _ _)) }, rw <- myfld.add_assoc (((c .* c) .* (myfld.reciprocal _ _)) .* (myfld.reciprocal _ _)) _ _, rw myfld.add_assoc (((c .* c) .* (myfld.reciprocal _ _)) .* (myfld.reciprocal _ _)) (((c .* c) .* (myfld.reciprocal _ _)) .* (myfld.reciprocal _ _)) _, rw <- distrib_simp_alt f ((c .* c) .* (myfld.reciprocal _ _)) _ _, repeat {rw <- myfld.add_assoc (((c .* c) .* (myfld.reciprocal _ _)) .* (myfld.reciprocal _ _)) _ _}, rw myfld.add_assoc (((c .* c) .* (myfld.reciprocal _ _)) .* _) (((c .* c) .* (myfld.reciprocal _ _)) .* _) _, rw <- distrib_simp_alt f ((c .* c) .* (myfld.reciprocal _ _)) _ _, rw root_a_reciprocal _, rw root_b_reciprocal _, rw recip_one_one f _, rw myfld.add_comm root_unity_b myfld.one, rw <- myfld.add_assoc myfld.one root_unity_b root_unity_a, rw myfld.add_comm root_unity_b root_unity_a, rw sum_roots_zero, rw zero_mul f _, rw simp_zero f _, clear reciprocal_1, clear reciprocal_2, clear reciprocal_3, /- Some minor cancellation that should maybe have been done earlier but wasn't...-/ rw myfld.mul_comm cubrt root_unity_a, repeat {rw <- myfld.mul_assoc root_unity_a cubrt (_ .* _) }, rw myfld.mul_assoc cubrt c (myfld.reciprocal _ _), rw myfld.mul_comm cubrt c, rw <- myfld.mul_assoc c cubrt (myfld.reciprocal _ _), rw cancel_from_reciprocal_alt f cubrt _ _, clear cubrt_h, /- This also lets us get rid of the cubrt variable entirely, which is nice.-/ repeat {rw split_reciprocal f _ _ _}, rw only_one_reciprocal f root_unity_a _ rta_n_zero, rw only_one_reciprocal f root_unity_b _ rtb_n_zero, rw only_one_reciprocal f (three f) _ fld_not_char_three.not_char_three, clear cubrt_n_zero, clear cubrt, repeat {rw <- add_negate f _ _}, repeat {rw root_a_reciprocal _}, repeat {rw root_b_reciprocal _}, clear root_a_reciprocal, clear root_b_reciprocal, clear rta_n_zero, clear rtb_n_zero, clear root_unity_a_h, clear root_unity_b_h, /- Every remainining term is a factor of c/3, so we can pull that out.-/ rw myfld.mul_assoc root_unity_a c (_ .* _), rw myfld.mul_comm root_unity_a c, repeat {rw <- myfld.mul_assoc c _ _}, repeat {rw <- distrib_simp_alt f c _ _}, rw myfld.mul_assoc root_unity_a root_unity_a _, rw root_a_squ, clear root_a_squ, rw myfld.mul_comm (root_unity_b .* _) root_unity_b, rw myfld.mul_assoc root_unity_b root_unity_b _, rw root_b_squ, clear root_b_squ, repeat {rw myfld.mul_comm _ (myfld.reciprocal (three f) _) }, repeat {rw <- distrib_simp_alt f (myfld.reciprocal (three f) _) _ _}, /- And now we have -c * 1/3 * -3, so c.-/ rw myfld.add_comm root_unity_b root_unity_a, rw sum_alt_roots_minusone, repeat {rw <- add_negate f _ _}, rw <- mul_negate_alt f (myfld.reciprocal (three f) _) (_ .+ _), rw <- mul_negate_alt f _ _, rw double_negative f _, rw myfld.mul_comm (myfld.reciprocal _ _) (_ .+ _), unfold three, rw <- myfld.add_assoc myfld.one myfld.one myfld.one, rw myfld.mul_reciprocal (myfld.one .+ (myfld.one .+ myfld.one)) _, symmetry, exact myfld.mul_one c, unfold cardano_formula_a, unfold cardano_formula_b, unfold cardano_formula_c, unfold cardano_formula, unfold alt_cubrt_a, unfold alt_cubrt_b, have tmp1 : (fld_with_cube_root.cubrt ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))) = (fld_with_cube_root.cubrt ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))), refl, have tmp2 : (cube_root_of_unity f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))) = (cube_root_of_unity f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))), refl, have tmp3 : (cube_root_of_unity f (.- (sqroot (.- (three f)))) (negative_sqrt f (.- (three f)))) = (cube_root_of_unity f (.- (sqroot (.- (three f)))) (negative_sqrt f (.- (three f)))), refl, exact folded_version (fld_with_cube_root.cubrt ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))) (cube_root_of_unity f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))) (cube_root_of_unity f (.- (sqroot (.- (three f)))) (negative_sqrt f (.- (three f)))) (cubrt_nonzero f ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d)) (cardano_den_not_zero_int f c d c_ne_zero)) (cubrt_unity_nonzero f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))) (cubrt_unity_nonzero f (.- (sqroot (.- (three f)))) (negative_sqrt f (.- (three f)))) tmp1 tmp2 tmp3, /- You tried to do this bit with mathlib, which would have made it prettier. However, the display bugs and over-aggressive rewriter made it impractical.-/ /-set cubrt := (fld_with_cube_root.cubrt ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))), set root_unity_a := (cube_root_of_unity f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))) with rt_unity_a_h, repeat {rw split_reciprocal f _ _ _}, have tmp : (cube_root_of_unity f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))) = root_unity_a, rw rt_unity_a_h, rw reciprocal_rewrite f (cube_root_of_unity f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))) root_unity_a tmp _, rw reciprocal_rewrite f (cube_root_of_unity f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))) root_unity_a tmp _, -/ end /- This is used to end the next proof, because that's long enough that it's starting to lag visual studio, so moving part of it out to somewhere else seems smart.-/ lemma cardano_product_helper (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (c d : f) (c_ne_zero : c ≠ myfld.zero) : (((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d)) .+ (.- ((((myfld.reciprocal ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d)) (cardano_den_not_zero_int f c d c_ne_zero)) .* (myfld.reciprocal ((three f) .* ((three f) .* (three f))) (mul_nonzero f (three f) ((three f) .* (three f)) fld_not_char_three.not_char_three (mul_nonzero f (three f) (three f) fld_not_char_three.not_char_three fld_not_char_three.not_char_three)))) .* (c .* c)) .* c))) = .- d := begin /- Start by rationalising the denominator.-/ have tmp_rat_den : (myfld.reciprocal ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d)) (cardano_den_not_zero_int f c d c_ne_zero)) = ((myfld.reciprocal ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d)) (cardano_den_not_zero_int f c d c_ne_zero)) .* ((myfld.reciprocal ((cardano_intermediate_val f c d) .+ (.- (cardano_other_int_val f d))) (cardano_den_not_zero_int_alt f c d c_ne_zero)) .* ((cardano_intermediate_val f c d) .+ (.- (cardano_other_int_val f d))))), rw myfld.mul_comm (myfld.reciprocal _ _) (_ .+ _), rw myfld.mul_reciprocal _ _, rw simp_mul_one f _, rw tmp_rat_den, clear tmp_rat_den, rw myfld.mul_assoc (myfld.reciprocal _ _) (myfld.reciprocal _ _) _, rw mul_two_reciprocals f _ _ _ _, rw reciprocal_rewrite f _ _ (difference_of_squares f _ _) _, /- Now we can simplify the denominator.-/ rw myfld.mul_comm _ (myfld.reciprocal (_ .* _) _), rw myfld.mul_assoc (myfld.reciprocal _ _) (myfld.reciprocal _ _) _, rw mul_two_reciprocals f _ _ _ _, have denom_simp : (((three f) .* ((three f) .* (three f))) .* ((square f (cardano_intermediate_val f c d)) .+ (.- (square f (cardano_other_int_val f d))))) = c .* (c .* c) , unfold cardano_intermediate_val, unfold cardano_other_int_val, rw sqrt_squared f _, unfold square, repeat {rw mul_negate_alt_simp f _ _}, rw double_negative f _, rw [ (myfld.mul_comm d (myfld.reciprocal _ _)) ] {occs := occurrences.pos [2]}, rw mul_negate f _ _, rw myfld.mul_assoc (d .* _) _ d, rw <- myfld.mul_assoc d (myfld.reciprocal _ _) (myfld.reciprocal _ _), rw mul_two_reciprocals f (two f) (two f) _ _, rw myfld.mul_comm (_ .* _) d, rw myfld.mul_assoc d d _, rw myfld.add_comm _ (.- (_ .* _)), rw myfld.add_assoc (.- _) (_ .* _), unfold four, rw myfld.add_comm (.- _) _, rw reciprocal_rewrite f _ _ (two_plus_two f) _, rw only_one_reciprocal f ((two f) .* (two f)) _ (mul_nonzero f (two f) (two f) fld_not_char_two.not_char_two fld_not_char_two.not_char_two), rw myfld.add_negate _, rw simp_zero f _, rw myfld.mul_assoc ((three f) .* _) (cubed f c) _, rw myfld.mul_comm _ (cubed f c), unfold twenty_seven, unfold nine, rw <- myfld.mul_assoc (cubed f c) ((three f) .* _) (myfld.reciprocal _ _), rw myfld.mul_reciprocal _ _, unfold cubed, simp, rw reciprocal_rewrite f _ _ denom_simp _, /- The c^3 on the numerator now cancels with the denominator.-/ repeat {rw <- myfld.mul_assoc}, rw myfld.mul_comm _ ((c .* c) .* c), rw myfld.mul_assoc (myfld.reciprocal _ _) ((c .* c) .* c) _, rw <- myfld.mul_assoc c c c, rw myfld.mul_comm (myfld.reciprocal _ _) (c .* (c .* c)), rw myfld.mul_reciprocal (c .* (c .* c)) _, rw one_mul_simp f _, clear denom_simp, /- The positive intermediate_val cancels with the negative...-/ rw add_negate f _ _, rw double_negative f _, rw myfld.add_assoc (_ .+ _) (.- _) _, rw <- myfld.add_assoc _ _ (.- _), rw myfld.add_comm _ (.- _), rw myfld.add_assoc _ (.- _) _, rw myfld.add_negate _, rw simp_zero f _, /- And ifnally we have to copies of other_int_value added to each other. Each of these is just -d/2, so they add to -d.-/ unfold cardano_other_int_val, rw <- add_negate f _ _, rw <- distrib_simp_alt f d _ _, rw only_one_reciprocal f (two f) _ (two_ne_zero f), rw add_two_halves f, rw simp_mul_one f _, end lemma cardano_product (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (c d : f) (c_ne_zero : c ≠ myfld.zero) : ((cardano_formula_a f c d c_ne_zero) .* ((cardano_formula_b f c d c_ne_zero) .* (cardano_formula_c f c d c_ne_zero))) = .- (d) := begin /- Again, this line is hideous but actually makes the proof easier to follow in the long run.-/ have folded_version : ∀ (cubrt root_unity_a root_unity_b : f), ∀ (cubrt_ne_zero : cubrt ≠ myfld.zero), ∀ (root_unity_a_ne_zero : root_unity_a ≠ myfld.zero), ∀ (root_unity_b_ne_zero : root_unity_b ≠ myfld.zero), (cubrt = (fld_with_cube_root.cubrt ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))) -> root_unity_a = (cube_root_of_unity f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))) -> root_unity_b = (cube_root_of_unity f (.- (sqroot (.- (three f)))) (negative_sqrt f (.- (three f)))) -> (cubrt .+ (.- (c .* (myfld.reciprocal (cubrt .* (three f)) (mul_nonzero f cubrt (three f) cubrt_ne_zero fld_not_char_three.not_char_three))))) .* (((root_unity_a .* cubrt) .+ (.- (c .* (myfld.reciprocal ((root_unity_a .* cubrt) .* (three f)) (mul_nonzero f (root_unity_a .* cubrt) (three f) (mul_nonzero f root_unity_a cubrt root_unity_a_ne_zero cubrt_ne_zero) fld_not_char_three.not_char_three))))) .* ((root_unity_b .* cubrt) .+ (.- (c .* (myfld.reciprocal ((root_unity_b .* cubrt) .* (three f)) (mul_nonzero f (root_unity_b .* cubrt) (three f) (mul_nonzero f root_unity_b cubrt root_unity_b_ne_zero cubrt_ne_zero) fld_not_char_three.not_char_three)))))) = (.- d)), intros cubrt root_unity_a root_unity_b cubrt_ne_zero rta_n_zero rtb_n_zero cubrt_h root_unity_a_h root_unity_b_h, /- TODO: Move all of this crap to somewhere where both sub-proofs can refer to it rather than having all this duplication.-/ have product_roots_one : root_unity_a .* root_unity_b = myfld.one, rw root_unity_a_h, rw root_unity_b_h, unfold cube_root_of_unity, rw <- myfld.mul_assoc _ (myfld.reciprocal (two f) _) _, rw myfld.mul_comm (myfld.reciprocal (two f) _) _, rw <- myfld.mul_assoc _ (myfld.reciprocal (two f) _) (myfld.reciprocal (two f) _), rw mul_two_reciprocals f (two f) (two f) _ _, rw myfld.mul_assoc _ _ (myfld.reciprocal _ _), rw difference_of_squares f (.- (myfld.one)) _, rw sqrt_squared f _, unfold square, rw mul_negate f _ _, rw mul_negate_alt_simp f _ _, repeat {rw double_negative f _}, rw one_mul_simp f _, unfold two, unfold three, simp, have sum_roots_zero : myfld.one .+ (root_unity_a .+ root_unity_b) = myfld.zero, rw root_unity_a_h, rw root_unity_b_h, have tmp : myfld.one .+ ((cubrt_unity_a f) .+ (cubrt_unity_b f)) = myfld.zero, exact cubrts_unity_sum_zero f, unfold cubrt_unity_a at tmp, unfold cubrt_unity_b at tmp, unfold cube_root_of_unity, exact tmp, have root_a_reciprocal : ∀ (rta_prf : root_unity_a ≠ myfld.zero), myfld.reciprocal root_unity_a rta_prf = root_unity_b, intros prf, symmetry, exact only_one_reciprocal_alt f root_unity_a root_unity_b _ product_roots_one, have root_b_reciprocal : ∀ (rtb_prf : root_unity_b ≠ myfld.zero), myfld.reciprocal root_unity_b rtb_prf = root_unity_a, intros prf, symmetry, rw myfld.mul_comm at product_roots_one, exact only_one_reciprocal_alt f root_unity_b root_unity_a _ product_roots_one, have sum_alt_roots_minusone : root_unity_a .+ root_unity_b = .- myfld.one, have tmp : (myfld.one .+ (root_unity_a .+ root_unity_b)) .+ (.- myfld.one) = .- myfld.one, rw sum_roots_zero, rw simp_zero f _, rw <- myfld.add_assoc myfld.one (_ .+ _) (.- _) at tmp, rw myfld.add_comm (_ .+ _) (.- myfld.one) at tmp, rw myfld.add_assoc myfld.one (.- myfld.one) _ at tmp, rw myfld.add_negate myfld.one at tmp, rw simp_zero f _ at tmp, exact tmp, have root_a_squ : root_unity_a .* root_unity_a = root_unity_b, have tmp : root_unity_a .+ (myfld.reciprocal root_unity_a rta_n_zero) = .- (myfld.one), rw root_a_reciprocal rta_n_zero, exact sum_alt_roots_minusone, have tmp2 : (root_unity_a .+ (myfld.reciprocal root_unity_a rta_n_zero)) .* root_unity_a = .- root_unity_a, rw tmp, rw mul_negate f _ _, rw one_mul_simp f root_unity_a, clear tmp, rw distrib_simp f _ _ _ at tmp2, rw carry_term_across f (root_unity_a .* root_unity_a) (.- root_unity_a) ((myfld.reciprocal root_unity_a rta_n_zero) .* root_unity_a) at tmp2, rw myfld.mul_comm (myfld.reciprocal _ _) root_unity_a at tmp2, rw myfld.mul_reciprocal root_unity_a _ at tmp2, rw myfld.add_assoc at sum_roots_zero, rw myfld.add_comm (_ .+ _) root_unity_b at sum_roots_zero, rw carry_term_across f _ _ _ at sum_roots_zero, rw <- add_negate _ _ at tmp2, rw simp_zero _ at sum_roots_zero, rw myfld.add_comm root_unity_a myfld.one at tmp2, rw <- sum_roots_zero at tmp2, exact tmp2, have root_b_squ : root_unity_b .* root_unity_b = root_unity_a, rw <- root_a_squ, rw [root_a_squ] {occs := occurrences.pos [2]}, rw <- myfld.mul_assoc, rw product_roots_one, rw <- myfld.mul_one root_unity_a, repeat {rw distrib_simp f _ _ _}, repeat {rw distrib_simp_alt f _ _ _}, /- First cancel cubrt and 1/cubrt in some terms.-/ repeat {rw mul_negate f _ _}, repeat {rw mul_negate_alt_simp f _ _}, repeat {rw double_negative f _}, repeat {rw myfld.mul_comm c (myfld.reciprocal _ _) }, repeat {rw <- myfld.mul_assoc (myfld.reciprocal _ _) c _}, repeat {rw myfld.mul_assoc cubrt (myfld.reciprocal _ _) _}, rw myfld.mul_assoc (_ .* cubrt) (myfld.reciprocal _ _) _, rw <- myfld.mul_assoc _ cubrt (myfld.reciprocal _ _), have tmp : ∀ (rt : f), ((rt .* cubrt) .* (three f)) = cubrt .* (rt .* (three f)) , simp, repeat {rw reciprocal_rewrite f _ _ (tmp _) _}, repeat {rw cancel_from_reciprocal_alt f cubrt _ _}, /- Some of this bit is slightly more convoluted than you'd expect so as to avoid making the result type-incorrect by rewriting in a reciprocal as collateral damage.-/ rw myfld.mul_assoc c (root_unity_a .* cubrt) (root_unity_b .* cubrt), rw myfld.mul_assoc c root_unity_a cubrt, rw myfld.mul_comm (c .* root_unity_a) cubrt, rw <- myfld.mul_assoc cubrt (c .* root_unity_a) _, rw myfld.mul_assoc (myfld.reciprocal _ _) cubrt _, rw myfld.mul_assoc c root_unity_b cubrt, rw myfld.mul_comm (c .* root_unity_b) cubrt, repeat {rw myfld.mul_assoc (myfld.reciprocal _ _) cubrt _}, repeat {rw cancel_from_reciprocal f cubrt _ _}, /- We can now collect like terms together, as three terms have a factor of cubrt and three terms have a factor of 1/cubrt.-/ repeat {rw myfld.mul_comm (myfld.reciprocal _ _) cubrt}, rw <- myfld.add_assoc (.- _) _ _, rw myfld.add_assoc _ (.- _) _, repeat {rw myfld.add_comm _ (.- _) }, rw <- myfld.add_assoc (.- _) _ _, rw myfld.add_assoc _ (.- _) _, repeat {rw myfld.add_comm _ (.- _) }, rw myfld.add_assoc (.- _) (.- _) _, rw <- add_negate f _ _, repeat {rw <- myfld.add_assoc (.- _) _ _}, rw myfld.add_assoc (.- _) (.- _) _, rw <- add_negate f _ _, rw myfld.mul_assoc (c .* root_unity_a) root_unity_b cubrt, rw myfld.mul_assoc (myfld.reciprocal (three f) _) (_ .* _) cubrt, rw myfld.mul_comm (_ .* _) cubrt, rw <- myfld.mul_assoc cubrt _ _, rw <- distrib_simp_alt f cubrt _ _, rw <- distrib_simp_alt f cubrt _ _, /- cubrt term done, now 1/cubrt term-/ have tmp2 : (cubrt .* (root_unity_b .* (three f))) = ((cubrt .* (three f)) .* root_unity_b), simp, rw reciprocal_rewrite f _ _ tmp2 _, rw split_reciprocal f (cubrt .* (three f)) _ _, rw <- myfld.mul_assoc (myfld.reciprocal (cubrt .* (three f)) _) _ _, rw myfld.mul_assoc _ (myfld.reciprocal (cubrt .* (three f)) _) _, rw myfld.mul_comm _ (myfld.reciprocal (cubrt .* (three f)) _), rw <- myfld.mul_assoc (myfld.reciprocal (cubrt .* (three f)) _) _ _, rw myfld.mul_assoc _ (myfld.reciprocal (cubrt .* (three f)) _) _, rw myfld.mul_comm _ (myfld.reciprocal (cubrt .* (three f)) _), rw <- myfld.mul_assoc (myfld.reciprocal (cubrt .* (three f)) _) _ _, rw only_one_reciprocal f (cubrt .* (three f)) _ (mul_nonzero f cubrt (three f) cubrt_ne_zero fld_not_char_three.not_char_three), rw myfld.add_comm (.- _) ((myfld.reciprocal (cubrt .* (three f)) _) .* _), rw myfld.add_assoc ((myfld.reciprocal (cubrt .* (three f)) _) .* _) ((myfld.reciprocal (cubrt .* (three f)) _) .* _) (.- _), rw <- distrib_simp_alt f (myfld.reciprocal (cubrt .* (three f)) _) _ _, repeat {rw <- myfld.add_assoc _ _ _}, rw myfld.add_assoc ((myfld.reciprocal (cubrt .* (three f)) _) .* _) ((myfld.reciprocal (cubrt .* (three f)) _) .* _) (.- _), rw <- distrib_simp_alt f (myfld.reciprocal (cubrt .* (three f)) _) _ _, /- The cubrt terms do in fact sum to zero.-/ repeat {rw myfld.mul_comm _ c}, repeat {rw myfld.mul_assoc _ c _}, repeat {rw <- myfld.mul_assoc c _ _}, repeat {rw myfld.mul_assoc _ c _}, repeat {rw myfld.mul_comm (myfld.reciprocal _ _) c}, repeat {rw <- myfld.mul_assoc c _ _}, rw <- distrib_simp_alt f c _ _, rw <- distrib_simp_alt f c _ _, repeat {rw reciprocal_rewrite f (_ .* (three f)) ((three f) .* _) (myfld.mul_comm _ (three f)) }, rw myfld.mul_comm root_unity_a (myfld.reciprocal _ _), rw split_reciprocal f (three f) _ _, rw split_reciprocal f (three f) _ _, repeat {rw <- myfld.mul_assoc (myfld.reciprocal (three f) _) _ _}, rw only_one_reciprocal f (three f) _ fld_not_char_three.not_char_three, rw <- distrib_simp_alt f (myfld.reciprocal (three f) _) _ _, rw <- distrib_simp_alt f (myfld.reciprocal (three f) _) _ _, rw product_roots_one, rw root_a_reciprocal _, rw root_b_reciprocal _, rw root_a_squ, rw root_b_squ, rw sum_roots_zero, repeat {rw zero_mul f _}, rw negate_zero_zero f, rw simp_zero f _, /- And so do the 1/cubrt terms.-/ rw myfld.mul_comm root_unity_b c, rw <- myfld.mul_assoc c root_unity_b root_unity_a, rw myfld.mul_assoc (myfld.reciprocal _ _) c (root_unity_b .* root_unity_a), rw myfld.mul_comm (myfld.reciprocal (three f) _) c, rw <- myfld.mul_assoc c (myfld.reciprocal (three f) _) (root_unity_b .* root_unity_a), repeat {rw myfld.mul_assoc c c _}, repeat {rw myfld.mul_assoc (c .* c) (myfld.reciprocal (three f) _) _}, rw <- distrib_simp_alt f ((c .* c) .* (myfld.reciprocal (three f) _)) _ _, rw <- distrib_simp_alt f ((c .* c) .* (myfld.reciprocal (three f) _)) _ _, rw myfld.mul_comm root_unity_b root_unity_a, rw product_roots_one, rw myfld.add_comm root_unity_b root_unity_a, rw sum_roots_zero, repeat {rw zero_mul f _}, rw simp_zero f _, /- Minor simplifications that should maybe have been done earlier.-/ rw myfld.mul_assoc (root_unity_a .* cubrt) root_unity_b cubrt, rw [ (myfld.mul_comm root_unity_a cubrt) ] {occs := occurrences.pos [1]}, rw <- myfld.mul_assoc cubrt root_unity_a root_unity_b, rw product_roots_one, rw simp_mul_one f _, rw myfld.mul_comm c ((_ .* _) .* _), repeat {rw myfld.mul_assoc _ _ _}, repeat {rw <- myfld.mul_assoc _ _ _}, rw myfld.mul_assoc (myfld.reciprocal _ _) (myfld.reciprocal _ _), rw mul_two_reciprocals f _ _ _ _, rw myfld.mul_assoc (myfld.reciprocal _ _) (myfld.reciprocal _ _), rw mul_two_reciprocals f _ _ _ _, have den_reorder : ((((three f) .* cubrt) .* (cubrt .* (root_unity_a .* (three f)))) .* ((three f) .* cubrt)) = (((cubrt .* (cubrt .* cubrt)) .* ((three f) .* ((three f) .* (three f)))) .* root_unity_a), rw myfld.mul_comm root_unity_a (three f), rw myfld.mul_assoc cubrt (three f) root_unity_a, repeat {rw myfld.mul_comm (three f) cubrt}, rw <- myfld.mul_assoc (cubrt .* (three f)) _ (cubrt .* (three f)), rw myfld.mul_comm (_ .* root_unity_a) _, repeat {rw <- myfld.mul_assoc cubrt _ _}, repeat {rw myfld.mul_assoc _ cubrt _}, rw myfld.mul_comm (three f) cubrt, repeat {rw <- myfld.mul_assoc cubrt _ _}, repeat {rw myfld.mul_assoc _ cubrt _}, rw myfld.mul_comm (three f) cubrt, repeat {rw myfld.mul_assoc}, rw reciprocal_rewrite f _ _ den_reorder _, rw split_reciprocal f _ root_unity_a _, rw root_a_reciprocal _, repeat {rw <- myfld.mul_assoc}, rw myfld.mul_comm c (root_unity_a .* c), rw myfld.mul_assoc root_unity_b (_ .* _) c, rw myfld.mul_assoc root_unity_b root_unity_a c, rw myfld.mul_comm root_unity_b root_unity_a, rw product_roots_one, rw one_mul f c, /- Now that we only have two fractions left, simplifying the proofs that enable those reciprocals to exist will allow us to throw away all the lemmae about roots, as they are no longer relevant.-/ rw split_reciprocal f (_ .* (_ .* _)) (_ .* (_ .* _)) _, rw only_one_reciprocal f (cubrt .* (cubrt .* cubrt)) _ (mul_nonzero f cubrt (cubrt .* cubrt) cubrt_ne_zero (mul_nonzero f cubrt cubrt cubrt_ne_zero cubrt_ne_zero)), rw only_one_reciprocal f ((three f) .* ((three f) .* (three f))) _ (mul_nonzero f (three f) ((three f) .* (three f)) fld_not_char_three.not_char_three (mul_nonzero f (three f) (three f) fld_not_char_three.not_char_three fld_not_char_three.not_char_three)), clear tmp tmp2 den_reorder root_a_squ root_b_squ sum_alt_roots_minusone root_a_reciprocal root_b_reciprocal sum_roots_zero product_roots_one root_unity_a_h root_unity_b_h rta_n_zero rtb_n_zero root_unity_a root_unity_b, rw myfld.mul_comm c (_ .* _), /- We now have cubrt * (cubrt * cubrt) in some places. As cubrt is a cube root this can be rewritten according to the definition of the cube root.-/ have cubrt_cubed : (cubrt .* (cubrt .* cubrt)) = (cardano_intermediate_val f c d) .+ (cardano_other_int_val f d) , rw myfld.mul_assoc, rw cubrt_h, rw fld_with_cube_root.cubrt_cubed, rw reciprocal_rewrite f _ _ cubrt_cubed _, rw [cubrt_cubed] {occs := occurrences.pos [1]}, rw only_one_reciprocal f _ _ (cardano_den_not_zero_int f c d c_ne_zero), clear cubrt_cubed cubrt_h cubrt_ne_zero cubrt, /- The remaining simplification is outsourced to a separate lemma, as this one is already large enough to lag VS.-/ exact cardano_product_helper f c d c_ne_zero, unfold cardano_formula_a, unfold cardano_formula_b, unfold cardano_formula_c, unfold cardano_formula, unfold alt_cubrt_a, unfold alt_cubrt_b, have tmp1 : (fld_with_cube_root.cubrt ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))) = (fld_with_cube_root.cubrt ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))), refl, have tmp2 : (cube_root_of_unity f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))) = (cube_root_of_unity f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))), refl, have tmp3 : (cube_root_of_unity f (.- (sqroot (.- (three f)))) (negative_sqrt f (.- (three f)))) = (cube_root_of_unity f (.- (sqroot (.- (three f)))) (negative_sqrt f (.- (three f)))), refl, exact folded_version (fld_with_cube_root.cubrt ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d))) (cube_root_of_unity f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))) (cube_root_of_unity f (.- (sqroot (.- (three f)))) (negative_sqrt f (.- (three f)))) (cubrt_nonzero f ((cardano_intermediate_val f c d) .+ (cardano_other_int_val f d)) (cardano_den_not_zero_int f c d c_ne_zero)) (cubrt_unity_nonzero f (sqroot (.- (three f))) (fld_with_sqrt.sqrt_mul_sqrt (.- (three f)))) (cubrt_unity_nonzero f (.- (sqroot (.- (three f)))) (negative_sqrt f (.- (three f)))) tmp1 tmp2 tmp3, end /- Now we do uniqueness. As every cubic is equivalent to a depressed cubic, it is sufficient to prove this for the general depressed cubic.-/ lemma depressed_cubic_factorize (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (c d x : f) (c_ne_zero : c ≠ myfld.zero) : (depressed_cubic_subst f c d x) = (factorized_cubic_expression f x (cardano_formula_a f c d c_ne_zero) (cardano_formula_b f c d c_ne_zero) (cardano_formula_c f c d c_ne_zero)) := begin rw multiply_out_cubic f x _ _ _, rw cardano_formulae_sum_zero f, rw mul_zero f (x .* x), rw negate_zero_zero f, rw simp_zero f, rw cardano_products f c d x c_ne_zero, rw cardano_product f, rw double_negative f d, unfold depressed_cubic_subst, rw myfld.mul_comm x c, end lemma cardano_formula_uniqueness (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (c d x : f) (c_ne_zero : c ≠ myfld.zero) : (x ≠ (cardano_formula_a f c d c_ne_zero)) -> (x ≠ (cardano_formula_b f c d c_ne_zero)) -> (x ≠ (cardano_formula_c f c d c_ne_zero)) -> ((depressed_cubic_subst f c d x) ≠ myfld.zero) := begin have h : factorized_cubic_expression f x (cardano_formula_a f c d c_ne_zero) (cardano_formula_b f c d c_ne_zero) (cardano_formula_c f c d c_ne_zero) = depressed_cubic_subst f c d x, symmetry, exact depressed_cubic_factorize f c d x c_ne_zero, intros not_formula_a not_formula_b not_formula_c solution, unfold factorized_cubic_expression at h, rw solution at h, have ne_zero_a : (x .+ (.- (cardano_formula_a f c d c_ne_zero))) ≠ myfld.zero, exact subtract_ne f x (cardano_formula_a f c d c_ne_zero) not_formula_a, have ne_zero_b : (x .+ (.- (cardano_formula_b f c d c_ne_zero))) ≠ myfld.zero, exact subtract_ne f x (cardano_formula_b f c d c_ne_zero) not_formula_b, have ne_zero_c : (x .+ (.- (cardano_formula_c f c d c_ne_zero))) ≠ myfld.zero, exact subtract_ne f x (cardano_formula_c f c d c_ne_zero) not_formula_c, exact (mul_nonzero f ((x .+ (.- (cardano_formula_a f c d c_ne_zero))) .* (x .+ (.- (cardano_formula_b f c d c_ne_zero)))) (x .+ (.- (cardano_formula_c f c d c_ne_zero))) (mul_nonzero f (x .+ (.- (cardano_formula_a f c d c_ne_zero))) (x .+ (.- (cardano_formula_b f c d c_ne_zero))) ne_zero_a ne_zero_b) ne_zero_c) h, end lemma cubic_formula_uniqueness (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (a1 b c d x : f) (a_ne_zero : a1 ≠ myfld.zero) (int_quantity_ne_zero : ((three f) .* (a1 .* c)) .+ (.- (square f b)) ≠ myfld.zero) : (x ≠ (cubic_formula_a f a1 b c d a_ne_zero int_quantity_ne_zero)) -> (x ≠ (cubic_formula_b f a1 b c d a_ne_zero int_quantity_ne_zero)) -> (x ≠ (cubic_formula_c f a1 b c d a_ne_zero int_quantity_ne_zero)) -> ((cubic_subst f a1 b c d x) ≠ myfld.zero) := begin intros ha hb hc, have move_term : ∀ (q : f), x ≠ q .+ (.- ((b .* (myfld.reciprocal a1 a_ne_zero)) .* (third f))) <-> (x .+ ((b .* (myfld.reciprocal a1 a_ne_zero)) .* (third f))) ≠ q, intros q, split, intros h1 h2, rw <- h2 at h1, clear h2, rw <- myfld.add_assoc at h1, rw myfld.add_negate at h1, rw zero_simp f x at h1, cc, intros h1 h2, rw h2 at h1, clear h2, rw <- myfld.add_assoc at h1, rw myfld.add_comm (.- _) _ at h1, rw myfld.add_negate at h1, rw zero_simp f q at h1, cc, unfold cubic_formula_a at ha, rw move_term _ at ha, unfold cubic_formula_b at hb, rw move_term _ at hb, unfold cubic_formula_c at hc, rw move_term _ at hc, intros is_solution, rw divide_cubic_through f a1 b c d _ a_ne_zero at is_solution, have tmp : x = (x .+ ((b .* (myfld.reciprocal a1 a_ne_zero)) .* (third f))) .+ (.- ((b .* (myfld.reciprocal a1 a_ne_zero)) .* (third f))) , rw <- myfld.add_assoc, rw myfld.add_negate, exact myfld.add_zero x, rw (reduce_cubic_to_depressed f (b .* (myfld.reciprocal a1 a_ne_zero)) (c .* (myfld.reciprocal a1 a_ne_zero)) (d .* (myfld.reciprocal a1 a_ne_zero)) x (x .+ ((b .* (myfld.reciprocal a1 a_ne_zero)) .* (third f))) tmp) at is_solution, exact cardano_formula_uniqueness f _ _ _ (int_quantity_ne_zero_simp f a1 b c a_ne_zero int_quantity_ne_zero) ha hb hc is_solution, end lemma cubic_formula_alt_uniqueness (f : Type) [myfld f] [fld_with_sqrt f] [fld_with_cube_root f] [fld_not_char_two f] [fld_not_char_three f] (a1 b c d x : f) (a_ne_zero : a1 ≠ myfld.zero) (int_quantity_eq_zero : ((three f) .* (a1 .* c)) .+ (.- (square f b)) = myfld.zero) : (x ≠ (cubic_formula_a_alt f a1 b c d a_ne_zero int_quantity_eq_zero)) -> (x ≠ (cubic_formula_b_alt f a1 b c d a_ne_zero int_quantity_eq_zero)) -> (x ≠ (cubic_formula_c_alt f a1 b c d a_ne_zero int_quantity_eq_zero)) -> ((cubic_subst f a1 b c d x) ≠ myfld.zero) := begin intros ha hb hc is_solution, rw divide_cubic_through f a1 b c d _ a_ne_zero at is_solution, have tmp : x = (x .+ ((b .* (myfld.reciprocal a1 a_ne_zero)) .* (third f))) .+ (.- ((b .* (myfld.reciprocal a1 a_ne_zero)) .* (third f))) , rw <- myfld.add_assoc, rw myfld.add_negate, exact myfld.add_zero x, rw (reduce_cubic_to_depressed f (b .* (myfld.reciprocal a1 a_ne_zero)) (c .* (myfld.reciprocal a1 a_ne_zero)) (d .* (myfld.reciprocal a1 a_ne_zero)) x (x .+ ((b .* (myfld.reciprocal a1 a_ne_zero)) .* (third f))) tmp) at is_solution, rw (int_quantity_eq_zero_simp f a1 b c a_ne_zero int_quantity_eq_zero) at is_solution, unfold depressed_cubic_subst at is_solution, rw mul_zero at is_solution, rw simp_zero at is_solution, have move_term : ∀ (q : f), x ≠ q .+ (.- ((b .* (myfld.reciprocal a1 a_ne_zero)) .* (third f))) <-> (x .+ ((b .* (myfld.reciprocal a1 a_ne_zero)) .* (third f))) ≠ q, intros q, split, intros h1 h2, rw <- h2 at h1, clear h2, rw <- myfld.add_assoc at h1, rw myfld.add_negate at h1, rw zero_simp f x at h1, cc, intros h1 h2, rw h2 at h1, clear h2, rw <- myfld.add_assoc at h1, rw myfld.add_comm (.- _) _ at h1, rw myfld.add_negate at h1, rw zero_simp f q at h1, cc, unfold cubic_formula_a_alt at ha, rw move_term _ at ha, unfold depressed_cubic_solution_c_zero_a at ha, unfold depressed_cubic_solution_c_zero at ha, rw move_negation_ne f _ _ at ha, unfold cubic_formula_b_alt at hb, rw move_term _ at hb, unfold depressed_cubic_solution_c_zero_b at hb, unfold depressed_cubic_solution_c_zero at hb, rw move_negation_ne f _ _ at hb, unfold cubic_formula_c_alt at hc, rw move_term _ at hc, unfold depressed_cubic_solution_c_zero_c at hc, unfold depressed_cubic_solution_c_zero at hc, rw move_negation_ne f _ _ at hc, clear move_term, clear tmp, rw move_across at is_solution, have tmp : ∀ (x : f), .- (cubed f x) = cubed f (.- x), intros q, unfold cubed, simp, rw tmp _ at is_solution, exact (no_other_cubrts_simple f _ _ ha hb hc) is_solution, end
477000a75596edffbc09222c048ec845474a348e
aa5a655c05e5359a70646b7154e7cac59f0b4132
/src/Std/Data/PersistentArray.lean
af60db2b58e58fcd7a4a0fa311659c324759dc41
[ "Apache-2.0" ]
permissive
lambdaxymox/lean4
ae943c960a42247e06eff25c35338268d07454cb
278d47c77270664ef29715faab467feac8a0f446
refs/heads/master
1,677,891,867,340
1,612,500,005,000
1,612,500,005,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
13,823
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 -/ universes u v w namespace Std inductive PersistentArrayNode (α : Type u) where | node (cs : Array (PersistentArrayNode α)) : PersistentArrayNode α | leaf (vs : Array α) : PersistentArrayNode α deriving Inhabited namespace PersistentArrayNode def isNode {α} : PersistentArrayNode α → Bool | node _ => true | leaf _ => false end PersistentArrayNode abbrev PersistentArray.initShift : USize := 5 abbrev PersistentArray.branching : USize := USize.ofNat (2 ^ PersistentArray.initShift.toNat) structure PersistentArray (α : Type u) where /- Recall that we run out of memory if we have more than `usizeSz/8` elements. So, we can stop adding elements at `root` after `size > usizeSz`, and keep growing the `tail`. This modification allow us to use `USize` instead of `Nat` when traversing `root`. -/ root : PersistentArrayNode α := PersistentArrayNode.node (Array.mkEmpty PersistentArray.branching.toNat) tail : Array α := Array.mkEmpty PersistentArray.branching.toNat size : Nat := 0 shift : USize := PersistentArray.initShift tailOff : Nat := 0 deriving Inhabited abbrev PArray (α : Type u) := PersistentArray α namespace PersistentArray /- TODO: use proofs for showing that array accesses are not out of bounds. We can do it after we reimplement the tactic framework. -/ variable {α : Type u} open Std.PersistentArrayNode def empty : PersistentArray α := {} def isEmpty (a : PersistentArray α) : Bool := a.size == 0 def mkEmptyArray : Array α := Array.mkEmpty branching.toNat abbrev mul2Shift (i : USize) (shift : USize) : USize := i.shiftLeft shift abbrev div2Shift (i : USize) (shift : USize) : USize := i.shiftRight shift abbrev mod2Shift (i : USize) (shift : USize) : USize := USize.land i ((USize.shiftLeft 1 shift) - 1) partial def getAux [Inhabited α] : PersistentArrayNode α → USize → USize → α | node cs, i, shift => getAux (cs.get! (div2Shift i shift).toNat) (mod2Shift i shift) (shift - initShift) | leaf cs, i, _ => cs.get! i.toNat def get! [Inhabited α] (t : PersistentArray α) (i : Nat) : α := if i >= t.tailOff then t.tail.get! (i - t.tailOff) else getAux t.root (USize.ofNat i) t.shift def getOp [Inhabited α] (self : PersistentArray α) (idx : Nat) : α := self.get! idx partial def setAux : PersistentArrayNode α → USize → USize → α → PersistentArrayNode α | node cs, i, shift, a => let j := div2Shift i shift let i := mod2Shift i shift let shift := shift - initShift node $ cs.modify j.toNat $ fun c => setAux c i shift a | leaf cs, i, _, a => leaf (cs.set! i.toNat a) def set (t : PersistentArray α) (i : Nat) (a : α) : PersistentArray α := if i >= t.tailOff then { t with tail := t.tail.set! (i - t.tailOff) a } else { t with root := setAux t.root (USize.ofNat i) t.shift a } @[specialize] partial def modifyAux [Inhabited α] (f : α → α) : PersistentArrayNode α → USize → USize → PersistentArrayNode α | node cs, i, shift => let j := div2Shift i shift let i := mod2Shift i shift let shift := shift - initShift node $ cs.modify j.toNat $ fun c => modifyAux f c i shift | leaf cs, i, _ => leaf (cs.modify i.toNat f) @[specialize] def modify [Inhabited α] (t : PersistentArray α) (i : Nat) (f : α → α) : PersistentArray α := if i >= t.tailOff then { t with tail := t.tail.modify (i - t.tailOff) f } else { t with root := modifyAux f t.root (USize.ofNat i) t.shift } partial def mkNewPath (shift : USize) (a : Array α) : PersistentArrayNode α := if shift == 0 then leaf a else node (mkEmptyArray.push (mkNewPath (shift - initShift) a)) partial def insertNewLeaf : PersistentArrayNode α → USize → USize → Array α → PersistentArrayNode α | node cs, i, shift, a => if i < branching then node (cs.push (leaf a)) else let j := div2Shift i shift let i := mod2Shift i shift let shift := shift - initShift if j.toNat < cs.size then node $ cs.modify j.toNat fun c => insertNewLeaf c i shift a else node $ cs.push $ mkNewPath shift a | n, _, _, _ => n -- unreachable def mkNewTail (t : PersistentArray α) : PersistentArray α := if t.size <= (mul2Shift 1 (t.shift + initShift)).toNat then { t with tail := mkEmptyArray, root := insertNewLeaf t.root (USize.ofNat (t.size - 1)) t.shift t.tail, tailOff := t.size } else { t with tail := #[], root := let n := mkEmptyArray.push t.root; node (n.push (mkNewPath t.shift t.tail)), shift := t.shift + initShift, tailOff := t.size } def tooBig : Nat := USize.size / 8 def push (t : PersistentArray α) (a : α) : PersistentArray α := let r := { t with tail := t.tail.push a, size := t.size + 1 } if r.tail.size < branching.toNat || t.size >= tooBig then r else mkNewTail r private def emptyArray {α : Type u} : Array (PersistentArrayNode α) := Array.mkEmpty PersistentArray.branching.toNat partial def popLeaf : PersistentArrayNode α → Option (Array α) × Array (PersistentArrayNode α) | n@(node cs) => if h : cs.size ≠ 0 then let idx : Fin cs.size := ⟨cs.size - 1, by exact Nat.predLt h⟩ let last := cs.get idx let cs' := cs.set idx arbitrary match popLeaf last with | (none, _) => (none, emptyArray) | (some l, newLast) => if newLast.size == 0 then let cs' := cs'.pop if cs'.isEmpty then (some l, emptyArray) else (some l, cs') else (some l, cs'.set (Array.sizeSetEq cs idx _ ▸ idx) (node newLast)) else (none, emptyArray) | leaf vs => (some vs, emptyArray) def pop (t : PersistentArray α) : PersistentArray α := if t.tail.size > 0 then { t with tail := t.tail.pop, size := t.size - 1 } else match popLeaf t.root with | (none, _) => t | (some last, newRoots) => let last := last.pop let newSize := t.size - 1 let newTailOff := newSize - last.size if newRoots.size == 1 && (newRoots.get! 0).isNode then { root := newRoots.get! 0, shift := t.shift - initShift, size := newSize, tail := last, tailOff := newTailOff } else { t with root := node newRoots, size := newSize, tail := last, tailOff := newTailOff } section variable {m : Type v → Type w} [Monad m] variable {β : Type v} @[specialize] private partial def foldlMAux (f : β → α → m β) : PersistentArrayNode α → β → m β | node cs, b => cs.foldlM (fun b c => foldlMAux f c b) b | leaf vs, b => vs.foldlM f b @[specialize] private partial def foldlFromMAux (f : β → α → m β) : PersistentArrayNode α → USize → USize → β → m β | node cs, i, shift, b => do let j := (div2Shift i shift).toNat let b ← foldlFromMAux f (cs.get! j) (mod2Shift i shift) (shift - initShift) b cs.foldlM (init := b) (start := j+1) fun b c => foldlMAux f c b | leaf vs, i, _, b => vs.foldlM (init := b) (start := i.toNat) f @[specialize] def foldlM (t : PersistentArray α) (f : β → α → m β) (init : β) (start : Nat := 0) : m β := do if start == 0 then let b ← foldlMAux f t.root init t.tail.foldlM f b else if start >= t.tailOff then t.tail.foldlM (init := init) (start := start - t.tailOff) f else do let b ← foldlFromMAux f t.root (USize.ofNat start) t.shift init; t.tail.foldlM f b @[specialize] partial def forInAux {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] [inh : Inhabited β] (f : α → β → m (ForInStep β)) (n : PersistentArrayNode α) (b : β) : m (ForInStep β) := do let mut b := b match n with | leaf vs => for v in vs do match (← f v b) with | r@(ForInStep.done b) => return r | ForInStep.yield bNew => b := bNew return ForInStep.yield b | node cs => for c in cs do match (← forInAux f c b) with | r@(ForInStep.done b) => return r | ForInStep.yield bNew => b := bNew return ForInStep.yield b @[specialize] protected def forIn (t : PersistentArray α) (init : β) (f : α → β → m (ForInStep β)) : m β := do match (← forInAux (inh := ⟨init⟩) f t.root init) with | ForInStep.done b => pure b | ForInStep.yield b => let mut b := b for v in t.tail do match (← f v b) with | ForInStep.done b => return b | ForInStep.yield bNew => b := bNew return b instance : ForIn m (PersistentArray α) α where forIn := PersistentArray.forIn @[specialize] partial def findSomeMAux (f : α → m (Option β)) : PersistentArrayNode α → m (Option β) | node cs => cs.findSomeM? (fun c => findSomeMAux f c) | leaf vs => vs.findSomeM? f @[specialize] def findSomeM? (t : PersistentArray α) (f : α → m (Option β)) : m (Option β) := do match (← findSomeMAux f t.root) with | none => t.tail.findSomeM? f | some b => pure (some b) @[specialize] partial def findSomeRevMAux (f : α → m (Option β)) : PersistentArrayNode α → m (Option β) | node cs => cs.findSomeRevM? (fun c => findSomeRevMAux f c) | leaf vs => vs.findSomeRevM? f @[specialize] def findSomeRevM? (t : PersistentArray α) (f : α → m (Option β)) : m (Option β) := do match (← t.tail.findSomeRevM? f) with | none => findSomeRevMAux f t.root | some b => pure (some b) @[specialize] partial def forMAux (f : α → m PUnit) : PersistentArrayNode α → m PUnit | node cs => cs.forM (fun c => forMAux f c) | leaf vs => vs.forM f @[specialize] def forM (t : PersistentArray α) (f : α → m PUnit) : m PUnit := forMAux f t.root *> t.tail.forM f end @[inline] def foldl {β} (t : PersistentArray α) (f : β → α → β) (init : β) (start : Nat := 0) : β := Id.run $ t.foldlM f init start @[inline] def filter (as : PersistentArray α) (p : α → Bool) : PersistentArray α := as.foldl (init := {}) fun asNew a => if p a then asNew.push a else asNew def toArray (t : PersistentArray α) : Array α := t.foldl Array.push #[] def append (t₁ t₂ : PersistentArray α) : PersistentArray α := if t₁.isEmpty then t₂ else t₂.foldl PersistentArray.push t₁ instance : Append (PersistentArray α) := ⟨append⟩ @[inline] def findSome? {β} (t : PersistentArray α) (f : α → (Option β)) : Option β := Id.run $ t.findSomeM? f @[inline] def findSomeRev? {β} (t : PersistentArray α) (f : α → (Option β)) : Option β := Id.run $ t.findSomeRevM? f def toList (t : PersistentArray α) : List α := (t.foldl (init := []) fun xs x => x :: xs).reverse section variable {m : Type → Type w} [Monad m] @[specialize] partial def anyMAux (p : α → m Bool) : PersistentArrayNode α → m Bool | node cs => cs.anyM fun c => anyMAux p c | leaf vs => vs.anyM p @[specialize] def anyM (t : PersistentArray α) (p : α → m Bool) : m Bool := anyMAux p t.root <||> t.tail.anyM p @[inline] def allM (a : PersistentArray α) (p : α → m Bool) : m Bool := do let b ← anyM a (fun v => do let b ← p v; pure (not b)) pure (not b) end @[inline] def any (a : PersistentArray α) (p : α → Bool) : Bool := Id.run $ anyM a p @[inline] def all (a : PersistentArray α) (p : α → Bool) : Bool := !any a fun v => !p v section variable {m : Type u → Type v} [Monad m] variable {β : Type u} @[specialize] partial def mapMAux (f : α → m β) : PersistentArrayNode α → m (PersistentArrayNode β) | node cs => node <$> cs.mapM (fun c => mapMAux f c) | leaf vs => leaf <$> vs.mapM f @[specialize] def mapM (f : α → m β) (t : PersistentArray α) : m (PersistentArray β) := do let root ← mapMAux f t.root let tail ← t.tail.mapM f pure { t with tail := tail, root := root } end @[inline] def map {β} (f : α → β) (t : PersistentArray α) : PersistentArray β := Id.run $ t.mapM f structure Stats where numNodes : Nat depth : Nat tailSize : Nat partial def collectStats : PersistentArrayNode α → Stats → Nat → Stats | node cs, s, d => cs.foldl (fun s c => collectStats c s (d+1)) { s with numNodes := s.numNodes + 1, depth := Nat.max d s.depth } | leaf vs, s, d => { s with numNodes := s.numNodes + 1, depth := Nat.max d s.depth } def stats (r : PersistentArray α) : Stats := collectStats r.root { numNodes := 0, depth := 0, tailSize := r.tail.size } 0 def Stats.toString (s : Stats) : String := s!"\{nodes := {s.numNodes}, depth := {s.depth}, tail size := {s.tailSize}}" instance : ToString Stats := ⟨Stats.toString⟩ end PersistentArray def mkPersistentArray {α : Type u} (n : Nat) (v : α) : PArray α := n.fold (init := PersistentArray.empty) fun i p => p.push v @[inline] def mkPArray {α : Type u} (n : Nat) (v : α) : PArray α := mkPersistentArray n v end Std open Std (PersistentArray PersistentArray.empty) def List.toPersistentArrayAux {α : Type u} : List α → PersistentArray α → PersistentArray α | [], t => t | x::xs, t => toPersistentArrayAux xs (t.push x) def List.toPersistentArray {α : Type u} (xs : List α) : PersistentArray α := xs.toPersistentArrayAux {} def Array.toPersistentArray {α : Type u} (xs : Array α) : PersistentArray α := xs.foldl (init := PersistentArray.empty) fun p x => p.push x @[inline] def Array.toPArray {α : Type u} (xs : Array α) : PersistentArray α := xs.toPersistentArray
d6b153b5a4d2062f7efb04a037171cdf71eab62a
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/measure_theory/ess_sup.lean
0d38bf20596ee8c10e52dc9f608bdb6fbfe59934
[]
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
6,405
lean
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.measure_theory.measure_space import Mathlib.order.filter.ennreal import Mathlib.PostPort universes u_1 u_2 u_3 namespace Mathlib /-! # Essential supremum and infimum We define the essential supremum and infimum of a function `f : α → β` with respect to a measure `μ` on `α`. The essential supremum is the infimum of the constants `c : β` such that `f x ≤ c` almost everywhere. TODO: The essential supremum of functions `α → ennreal` is used in particular to define the norm in the `L∞` space (see measure_theory/lp_space.lean). There is a different quantity which is sometimes also called essential supremum: the least upper-bound among measurable functions of a family of measurable functions (in an almost-everywhere sense). We do not define that quantity here, which is simply the supremum of a map with values in `α →ₘ[μ] β` (see measure_theory/ae_eq_fun.lean). ## Main definitions * `ess_sup f μ := μ.ae.limsup f` * `ess_inf f μ := μ.ae.liminf f` -/ /-- Essential supremum of `f` with respect to measure `μ`: the smallest `c : β` such that `f x ≤ c` a.e. -/ def ess_sup {α : Type u_1} {β : Type u_2} [measurable_space α] [conditionally_complete_lattice β] (f : α → β) (μ : measure_theory.measure α) : β := filter.limsup (measure_theory.measure.ae μ) f /-- Essential infimum of `f` with respect to measure `μ`: the greatest `c : β` such that `c ≤ f x` a.e. -/ def ess_inf {α : Type u_1} {β : Type u_2} [measurable_space α] [conditionally_complete_lattice β] (f : α → β) (μ : measure_theory.measure α) : β := filter.liminf (measure_theory.measure.ae μ) f theorem ess_sup_congr_ae {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure_theory.measure α} [conditionally_complete_lattice β] {f : α → β} {g : α → β} (hfg : filter.eventually_eq (measure_theory.measure.ae μ) f g) : ess_sup f μ = ess_sup g μ := filter.limsup_congr hfg theorem ess_inf_congr_ae {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure_theory.measure α} [conditionally_complete_lattice β] {f : α → β} {g : α → β} (hfg : filter.eventually_eq (measure_theory.measure.ae μ) f g) : ess_inf f μ = ess_inf g μ := ess_sup_congr_ae hfg @[simp] theorem ess_sup_measure_zero {α : Type u_1} {β : Type u_2} [measurable_space α] [complete_lattice β] {f : α → β} : ess_sup f 0 = ⊥ := sorry @[simp] theorem ess_inf_measure_zero {α : Type u_1} {β : Type u_2} [measurable_space α] [complete_lattice β] {f : α → β} : ess_inf f 0 = ⊤ := ess_sup_measure_zero theorem ess_sup_mono_ae {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure_theory.measure α} [complete_lattice β] {f : α → β} {g : α → β} (hfg : filter.eventually_le (measure_theory.measure.ae μ) f g) : ess_sup f μ ≤ ess_sup g μ := filter.limsup_le_limsup hfg theorem ess_inf_mono_ae {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure_theory.measure α} [complete_lattice β] {f : α → β} {g : α → β} (hfg : filter.eventually_le (measure_theory.measure.ae μ) f g) : ess_inf f μ ≤ ess_inf g μ := filter.liminf_le_liminf hfg theorem ess_sup_const {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure_theory.measure α} [complete_lattice β] (c : β) (hμ : μ ≠ 0) : ess_sup (fun (x : α) => c) μ = c := filter.limsup_const c theorem ess_inf_const {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure_theory.measure α} [complete_lattice β] (c : β) (hμ : μ ≠ 0) : ess_inf (fun (x : α) => c) μ = c := ess_sup_const c hμ theorem ess_sup_const_bot {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure_theory.measure α} [complete_lattice β] : ess_sup (fun (x : α) => ⊥) μ = ⊥ := filter.limsup_const_bot theorem ess_inf_const_top {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure_theory.measure α} [complete_lattice β] : ess_inf (fun (x : α) => ⊤) μ = ⊤ := filter.liminf_const_top theorem order_iso.ess_sup_apply {α : Type u_1} {β : Type u_2} [measurable_space α] [complete_lattice β] {γ : Type u_3} [complete_lattice γ] (f : α → β) (μ : measure_theory.measure α) (g : β ≃o γ) : coe_fn g (ess_sup f μ) = ess_sup (fun (x : α) => coe_fn g (f x)) μ := order_iso.limsup_apply g theorem order_iso.ess_inf_apply {α : Type u_1} {β : Type u_2} [measurable_space α] [complete_lattice β] {γ : Type u_3} [complete_lattice γ] (f : α → β) (μ : measure_theory.measure α) (g : β ≃o γ) : coe_fn g (ess_inf f μ) = ess_inf (fun (x : α) => coe_fn g (f x)) μ := order_iso.ess_sup_apply f μ (order_iso.dual g) theorem ae_lt_of_ess_sup_lt {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure_theory.measure α} [complete_linear_order β] {f : α → β} {x : β} (hf : ess_sup f μ < x) : filter.eventually (fun (y : α) => f y < x) (measure_theory.measure.ae μ) := filter.eventually_lt_of_limsup_lt hf theorem ae_lt_of_lt_ess_inf {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure_theory.measure α} [complete_linear_order β] {f : α → β} {x : β} (hf : x < ess_inf f μ) : filter.eventually (fun (y : α) => x < f y) (measure_theory.measure.ae μ) := ae_lt_of_ess_sup_lt hf namespace ennreal theorem ae_le_ess_sup {α : Type u_1} [measurable_space α] {μ : measure_theory.measure α} (f : α → ennreal) : filter.eventually (fun (y : α) => f y ≤ ess_sup f μ) (measure_theory.measure.ae μ) := eventually_le_limsup f theorem ess_sup_eq_zero_iff {α : Type u_1} [measurable_space α] {μ : measure_theory.measure α} {f : α → ennreal} : ess_sup f μ = 0 ↔ filter.eventually_eq (measure_theory.measure.ae μ) f 0 := limsup_eq_zero_iff theorem ess_sup_const_mul {α : Type u_1} [measurable_space α] {μ : measure_theory.measure α} {f : α → ennreal} {a : ennreal} : ess_sup (fun (x : α) => a * f x) μ = a * ess_sup f μ := limsup_const_mul theorem ess_sup_add_le {α : Type u_1} [measurable_space α] {μ : measure_theory.measure α} (f : α → ennreal) (g : α → ennreal) : ess_sup (f + g) μ ≤ ess_sup f μ + ess_sup g μ := limsup_add_le f g
a87b29b1a506b2eaf9a2116680d01dc32f0467e7
1e3a43e8ba59c6fe1c66775b6e833e721eaf1675
/src/algebra/module.lean
67ecc51050c616bb96379f744c395d467078cc08
[ "Apache-2.0" ]
permissive
Sterrs/mathlib
ea6910847b8dfd18500486de9ab0ee35704a3f52
d9327e433804004aa1dc65091bbe0de1e5a08c5e
refs/heads/master
1,650,769,884,257
1,587,808,694,000
1,587,808,694,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
26,189
lean
/- Copyright (c) 2015 Nathaniel Thomas. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro -/ import group_theory.group_action /-! # Modules over a ring In this file we define * `semimodule R M` : an additive commutative monoid `M` is a `semimodule` over a `semiring` `R` if for `r : R` and `x : M` their "scalar multiplication `r • x : M` is defined, and the operation `•` satisfies some natural associativity and distributivity axioms similar to those on a ring. * `module R M` : same as `semimodule R M` but assumes that `R` is a `ring` and `M` is an additive commutative group. * `vector_space k M` : same as `semimodule k M` and `module k M` but assumes that `k` is a `field` and `M` is an additive commutative group. * `linear_map R M M₂`, `M →ₗ[R] M₂` : a linear map between two R-`module`s. * `is_linear_map R f` : predicate saying that `f : M → M₂` is a linear map. * `submodule R M` : a subset of `M` that contains zero and is closed with respect to addition and scalar multiplication. * `subspace k M` : an abbreviation for `submodule` assuming that `k` is a `field`. ## Implementation notes * `vector_space` is an abbreviation for `module R M` while the latter `extends semimodule R M`. There were several attempts to make `module` an abbreviation of `semimodule` but this makes class instance search too hard for Lean 3. ## TODO * `submodule R M` was written before bundled `submonoid`s, so it does not extend it. ## Tags semimodule, module, vector space, submodule, subspace, linear map -/ open function universes u u' v w x y z variables {R : Type u} {k : Type u'} {S : Type v} {M : Type w} {M₂ : Type x} {M₃ : Type y} {ι : Type z} section prio set_option default_priority 100 -- see Note [default priority] /-- A semimodule is a generalization of vector spaces to a scalar semiring. It consists of a scalar semiring `R` and an additive monoid of "vectors" `M`, connected by a "scalar multiplication" operation `r • x : M` (where `r : R` and `x : M`) with some natural associativity and distributivity axioms similar to those on a ring. -/ class semimodule (R : Type u) (M : Type v) [semiring R] [add_comm_monoid M] extends distrib_mul_action R M := (add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x) (zero_smul : ∀x : M, (0 : R) • x = 0) end prio section semimodule variables [semiring R] [add_comm_monoid M] [semimodule R M] (r s : R) (x y : M) theorem add_smul : (r + s) • x = r • x + s • x := semimodule.add_smul r s x variables (R) @[simp] theorem zero_smul : (0 : R) • x = 0 := semimodule.zero_smul x variable {R} lemma semimodule.eq_zero_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : x = 0 := by rw [←one_smul R x, ←zero_eq_one, zero_smul] instance smul.is_add_monoid_hom (x : M) : is_add_monoid_hom (λ r:R, r • x) := { map_zero := zero_smul _ x, map_add := λ r₁ r₂, add_smul r₁ r₂ x } lemma list.sum_smul {l : list R} {x : M} : l.sum • x = (l.map (λ r, r • x)).sum := show (λ r, r • x) l.sum = (l.map (λ r, r • x)).sum, from (list.sum_hom _ _).symm lemma multiset.sum_smul {l : multiset R} {x : M} : l.sum • x = (l.map (λ r, r • x)).sum := show (λ r, r • x) l.sum = (l.map (λ r, r • x)).sum, from (multiset.sum_hom _ _).symm lemma finset.sum_smul {f : ι → R} {s : finset ι} {x : M} : s.sum f • x = s.sum (λ r, (f r) • x) := show (λ r, r • x) (s.sum f) = s.sum (λ r, (f r) • x), from (finset.sum_hom _ _).symm end semimodule section prio set_option default_priority 100 -- see Note [default priority] /-- A module is a generalization of vector spaces to a scalar ring. It consists of a scalar ring `R` and an additive group of "vectors" `M`, connected by a "scalar multiplication" operation `r • x : M` (where `r : R` and `x : M`) with some natural associativity and distributivity axioms similar to those on a ring. -/ class module (R : Type u) (M : Type v) [ring R] [add_comm_group M] extends semimodule R M end prio /-- To prove two module structures on a fixed `add_comm_group` agree, it suffices to check the scalar multiplications agree. -/ -- We'll later use this to show `module ℤ M` is a subsingleton. @[ext] lemma module_ext {R : Type*} [ring R] {M : Type*} [add_comm_group M] (P Q : module R M) (w : ∀ (r : R) (m : M), by { haveI := P, exact r • m } = by { haveI := Q, exact r • m }) : P = Q := begin resetI, rcases P with ⟨⟨⟨⟨⟨P⟩⟩⟩⟩⟩, rcases Q with ⟨⟨⟨⟨⟨Q⟩⟩⟩⟩⟩, congr, funext r m, exact w r m, all_goals { apply proof_irrel_heq }, end /-- An auxiliary `structure` that is used to define `module`s without verifying `zero_smul` and `smul_zero`. -/ structure module.core (R M) [ring R] [add_comm_group M] extends has_scalar R M := (smul_add : ∀(r : R) (x y : M), r • (x + y) = r • x + r • y) (add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x) (mul_smul : ∀(r s : R) (x : M), (r * s) • x = r • s • x) (one_smul : ∀x : M, (1 : R) • x = x) /-- Define `module` without proving `zero_smul` and `smul_zero` by using an auxiliary structure `module.core`. -/ def module.of_core [ring R] [add_comm_group M] (Mc : module.core R M) : module R M := by letI := Mc.to_has_scalar; exact { zero_smul := λ x, (add_monoid_hom.mk' (λ r : R, r • x) (λ r s, Mc.add_smul r s x)).map_zero, smul_zero := λ r, (add_monoid_hom.mk' ((•) r) (Mc.smul_add r)).map_zero, ..Mc } section module variables [ring R] [add_comm_group M] [module R M] (r s : R) (x y : M) @[simp] theorem neg_smul : -r • x = - (r • x) := eq_neg_of_add_eq_zero (by rw [← add_smul, add_left_neg, zero_smul]) variables (R) theorem neg_one_smul (x : M) : (-1 : R) • x = -x := by simp variables {R} @[simp] theorem smul_neg : r • (-x) = -(r • x) := by rw [← neg_one_smul R, ← mul_smul, mul_neg_one, neg_smul] theorem smul_sub (r : R) (x y : M) : r • (x - y) = r • x - r • y := by simp [smul_add, sub_eq_add_neg]; rw smul_neg theorem sub_smul (r s : R) (y : M) : (r - s) • y = r • y - s • y := by simp [add_smul, sub_eq_add_neg] theorem smul_eq_zero {R E : Type*} [division_ring R] [add_comm_group E] [module R E] {c : R} {x : E} : c • x = 0 ↔ c = 0 ∨ x = 0 := ⟨λ h, classical.by_cases or.inl (λ hc, or.inr $ by rw [← one_smul R x, ← inv_mul_cancel hc, mul_smul, h, smul_zero]), λ h, h.elim (λ hc, hc.symm ▸ zero_smul R x) (λ hx, hx.symm ▸ smul_zero c)⟩ end module instance semiring.to_semimodule [semiring R] : semimodule R R := { smul := (*), smul_add := mul_add, add_smul := add_mul, mul_smul := mul_assoc, one_smul := one_mul, zero_smul := zero_mul, smul_zero := mul_zero } @[simp] lemma smul_eq_mul [semiring R] {a a' : R} : a • a' = a * a' := rfl instance ring.to_module [ring R] : module R R := { to_semimodule := semiring.to_semimodule } /-- A ring homomorphism `f : R →+* S` defines a semimodule structure by `r • x = f r * x`. -/ def ring_hom.to_semimodule [semiring R] [semiring S] (f : R →+* S) : semimodule R S := { smul := λ r x, f r * x, smul_add := λ r x y, by unfold has_scalar.smul; rw [mul_add], add_smul := λ r s x, by unfold has_scalar.smul; rw [f.map_add, add_mul], mul_smul := λ r s x, by unfold has_scalar.smul; rw [f.map_mul, mul_assoc], one_smul := λ x, show f 1 * x = _, by rw [f.map_one, one_mul], zero_smul := λ x, show f 0 * x = 0, by rw [f.map_zero, zero_mul], smul_zero := λ r, mul_zero (f r) } /-- A ring homomorphism `f : R →+* S` defines a module structure by `r • x = f r * x`. -/ def ring_hom.to_module [ring R] [ring S] (f : R →+* S) : module R S := { to_semimodule := f.to_semimodule } /-- A class saying that `f` is an `R` linear map. Though it is a class, it is used as an explicit argument in most lemmas. -/ class is_linear_map (R : Type u) {M : Type v} {M₂ : Type w} [ring R] [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂] (f : M → M₂) : Prop := (add [] : ∀ x y, f (x + y) = f x + f y) (smul [] : ∀ (c : R) x, f (c • x) = c • f x) /-- A bundled `R`-linear map from `M` to `M₂`. -/ structure linear_map (R : Type u) (M : Type v) (M₂ : Type w) [ring R] [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂] := (to_fun : M → M₂) (add : ∀x y, to_fun (x + y) = to_fun x + to_fun y) (smul : ∀(c : R) x, to_fun (c • x) = c • to_fun x) infixr ` →ₗ `:25 := linear_map _ notation β ` →ₗ[`:25 α:25 `] `:0 γ:0 := linear_map α β γ namespace linear_map variables [ring R] [add_comm_group M] [add_comm_group M₂] section variables [module R M] [module R M₂] variables (f g : M →ₗ[R] M₂) instance : has_coe_to_fun (M →ₗ[R] M₂) := ⟨_, to_fun⟩ @[simp] lemma coe_mk (f : M → M₂) (h₁ h₂) : ((linear_map.mk f h₁ h₂ : M →ₗ[R] M₂) : M → M₂) = f := rfl end -- We can infer the module structure implicitly from the linear maps, -- rather than via typeclass resolution. variables {module_M : module R M} {module_M₂ : module R M₂} variables (f g : M →ₗ[R] M₂) @[simp] lemma to_fun_eq_coe : f.to_fun = ⇑f := rfl theorem is_linear : is_linear_map R f := {..f} variables {f g} @[ext] theorem ext (H : ∀ x, f x = g x) : f = g := by cases f; cases g; congr'; exact funext H lemma coe_fn_congr : Π {x x' : M}, x = x' → f x = f x' | _ _ rfl := rfl theorem ext_iff : f = g ↔ ∀ x, f x = g x := ⟨by { rintro rfl x, refl } , ext⟩ variables (f g) @[simp] lemma map_add (x y : M) : f (x + y) = f x + f y := f.add x y @[simp] lemma map_smul (c : R) (x : M) : f (c • x) = c • f x := f.smul c x @[simp] lemma map_zero : f 0 = 0 := by rw [← zero_smul R, map_smul f 0 0, zero_smul] instance : is_add_group_hom f := { map_add := map_add f } /-- convert a linear map to an additive map -/ def to_add_monoid_hom : M →+ M₂ := { to_fun := f, map_zero' := f.map_zero, map_add' := f.map_add } @[simp] lemma to_add_monoid_hom_coe : ((f.to_add_monoid_hom) : M → M₂) = f := rfl @[simp] lemma map_neg (x : M) : f (- x) = - f x := f.to_add_monoid_hom.map_neg x @[simp] lemma map_sub (x y : M) : f (x - y) = f x - f y := f.to_add_monoid_hom.map_sub x y @[simp] lemma map_sum {t : finset ι} {g : ι → M} : f (t.sum g) = t.sum (λi, f (g i)) := f.to_add_monoid_hom.map_sum _ _ end linear_map namespace linear_map variables [ring R] [add_comm_group M] [add_comm_group M₂] variables [add_comm_group M₃] variables {module_M : module R M} {module_M₂ : module R M₂} {module_M₃ : module R M₃} variables (f : M₂ →ₗ[R] M₃) (g : M →ₗ[R] M₂) /-- Composition of two linear maps is a linear map -/ def comp : M →ₗ[R] M₃ := ⟨f ∘ g, by simp, by simp⟩ @[simp] lemma comp_apply (x : M) : f.comp g x = f (g x) := rfl /-- Identity map as a `linear_map` -/ def id {R} {M} [ring R] [add_comm_group M] [module R M] : M →ₗ[R] M := ⟨id, λ _ _, rfl, λ _ _, rfl⟩ @[simp] lemma id_apply {R} {M} [ring R] [add_comm_group M] [module R M] (x : M) : @id R M _ _ _ x = x := rfl end linear_map namespace is_linear_map variables [ring R] [add_comm_group M] [add_comm_group M₂] variables [module R M] [module R M₂] /-- Convert an `is_linear_map` predicate to a `linear_map` -/ def mk' (f : M → M₂) (H : is_linear_map R f) : M →ₗ M₂ := {to_fun := f, ..H} @[simp] theorem mk'_apply {f : M → M₂} (H : is_linear_map R f) (x : M) : mk' f H x = f x := rfl lemma is_linear_map_neg : is_linear_map R (λ (z : M), -z) := is_linear_map.mk neg_add (λ x y, (smul_neg x y).symm) lemma is_linear_map_smul {R M : Type*} [comm_ring R] [add_comm_group M] [module R M] (c : R) : is_linear_map R (λ (z : M), c • z) := begin refine is_linear_map.mk (smul_add c) _, intros _ _, simp only [smul_smul, mul_comm] end --TODO: move lemma is_linear_map_smul' (a : M) : is_linear_map R (λ (c : R), c • a) := is_linear_map.mk (λ x y, add_smul x y a) (λ x y, mul_smul x y a) variables {f : M → M₂} (lin : is_linear_map R f) include M M₂ lin lemma map_zero : f (0 : M) = (0 : M₂) := (lin.mk' f).map_zero lemma map_add : ∀ x y, f (x + y) = f x + f y := lin.add lemma map_neg (x) : f (- x) = - f x := (lin.mk' f).map_neg x lemma map_sub (x y) : f (x - y) = f x - f y := (lin.mk' f).map_sub x y lemma map_smul (c : R) (x : M) : f (c • x) = c • f x := (lin.mk' f).map_smul c x end is_linear_map /-- Ring of linear endomorphismsms of a module. -/ abbreviation module.End (R : Type u) (M : Type v) [comm_ring R] [add_comm_group M] [module R M] := M →ₗ[R] M /-- A submodule of a module is one which is closed under vector operations. This is a sufficient condition for the subset of vectors in the submodule to themselves form a module. -/ structure submodule (R : Type u) (M : Type v) [ring R] [add_comm_group M] [module R M] : Type v := (carrier : set M) (zero : (0:M) ∈ carrier) (add : ∀ {x y}, x ∈ carrier → y ∈ carrier → x + y ∈ carrier) (smul : ∀ (c:R) {x}, x ∈ carrier → c • x ∈ carrier) namespace submodule variables [ring R] [add_comm_group M] [add_comm_group M₂] section variables [module R M] instance : has_coe (submodule R M) (set M) := ⟨submodule.carrier⟩ instance : has_mem M (submodule R M) := ⟨λ x p, x ∈ (p : set M)⟩ end -- We can infer the module structure implicitly from the bundled submodule, -- rather than via typeclass resolution. variables {module_M : module R M} variables {p q : submodule R M} variables {r : R} {x y : M} theorem ext' (h : (p : set M) = q) : p = q := by cases p; cases q; congr' protected theorem ext'_iff : (p : set M) = q ↔ p = q := ⟨ext', λ h, h ▸ rfl⟩ @[ext] theorem ext (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := ext' $ set.ext h variables (p) @[simp] theorem mem_coe : x ∈ (p : set M) ↔ x ∈ p := iff.rfl @[simp] lemma zero_mem : (0 : M) ∈ p := p.zero lemma add_mem (h₁ : x ∈ p) (h₂ : y ∈ p) : x + y ∈ p := p.add h₁ h₂ lemma smul_mem (r : R) (h : x ∈ p) : r • x ∈ p := p.smul r h lemma neg_mem (hx : x ∈ p) : -x ∈ p := by rw ← neg_one_smul R; exact p.smul_mem _ hx lemma sub_mem (hx : x ∈ p) (hy : y ∈ p) : x - y ∈ p := p.add_mem hx (p.neg_mem hy) lemma neg_mem_iff : -x ∈ p ↔ x ∈ p := ⟨λ h, by simpa using neg_mem p h, neg_mem p⟩ lemma add_mem_iff_left (h₁ : y ∈ p) : x + y ∈ p ↔ x ∈ p := ⟨λ h₂, by simpa using sub_mem _ h₂ h₁, λ h₂, add_mem _ h₂ h₁⟩ lemma add_mem_iff_right (h₁ : x ∈ p) : x + y ∈ p ↔ y ∈ p := ⟨λ h₂, by simpa using sub_mem _ h₂ h₁, add_mem _ h₁⟩ lemma sum_mem {t : finset ι} {f : ι → M} : (∀c∈t, f c ∈ p) → t.sum f ∈ p := begin classical, exact finset.induction_on t (by simp [p.zero_mem]) (by simp [p.add_mem] {contextual := tt}) end lemma smul_mem_iff' (u : units R) : (u:R) • x ∈ p ↔ x ∈ p := ⟨λ h, by simpa only [smul_smul, u.inv_mul, one_smul] using p.smul_mem ↑u⁻¹ h, p.smul_mem u⟩ instance : has_add p := ⟨λx y, ⟨x.1 + y.1, add_mem _ x.2 y.2⟩⟩ instance : has_zero p := ⟨⟨0, zero_mem _⟩⟩ instance : inhabited p := ⟨0⟩ instance : has_neg p := ⟨λx, ⟨-x.1, neg_mem _ x.2⟩⟩ instance : has_scalar R p := ⟨λ c x, ⟨c • x.1, smul_mem _ c x.2⟩⟩ variables {p} @[simp, norm_cast] lemma coe_add (x y : p) : (↑(x + y) : M) = ↑x + ↑y := rfl @[simp, norm_cast] lemma coe_zero : ((0 : p) : M) = 0 := rfl @[simp, norm_cast] lemma coe_neg (x : p) : ((-x : p) : M) = -x := rfl @[simp, norm_cast] lemma coe_smul (r : R) (x : p) : ((r • x : p) : M) = r • ↑x := rfl @[simp, norm_cast] lemma coe_mk (x : M) (hx : x ∈ p) : ((⟨x, hx⟩ : p) : M) = x := rfl @[simp] protected lemma eta (x : p) (hx : (x : M) ∈ p) : (⟨x, hx⟩ : p) = x := subtype.eta x hx instance : add_comm_group p := by refine {add := (+), zero := 0, neg := has_neg.neg, ..}; { intros, apply set_coe.ext, simp [add_comm, add_left_comm] } instance submodule_is_add_subgroup : is_add_subgroup (p : set M) := { zero_mem := p.zero, add_mem := p.add, neg_mem := λ _, p.neg_mem } @[simp, norm_cast] lemma coe_sub (x y : p) : (↑(x - y) : M) = ↑x - ↑y := rfl variables (p) instance : module R p := by refine {smul := (•), ..}; { intros, apply set_coe.ext, simp [smul_add, add_smul, mul_smul] } /-- Embedding of a submodule `p` to the ambient space `M`. -/ protected def subtype : p →ₗ[R] M := by refine {to_fun := coe, ..}; simp [coe_smul] @[simp] theorem subtype_apply (x : p) : p.subtype x = x := rfl lemma subtype_eq_val : ((submodule.subtype p) : p → M) = subtype.val := rfl end submodule -- TODO: Do we want one-sided ideals? /-- Ideal in a commutative ring is an additive subgroup `s` such that `a * b ∈ s` whenever `b ∈ s`. We define `ideal R` as `submodule R R`. -/ @[reducible] def ideal (R : Type u) [comm_ring R] := submodule R R namespace ideal variables [comm_ring R] (I : ideal R) {a b : R} protected lemma zero_mem : (0 : R) ∈ I := I.zero_mem protected lemma add_mem : a ∈ I → b ∈ I → a + b ∈ I := I.add_mem lemma neg_mem_iff : -a ∈ I ↔ a ∈ I := I.neg_mem_iff lemma add_mem_iff_left : b ∈ I → (a + b ∈ I ↔ a ∈ I) := I.add_mem_iff_left lemma add_mem_iff_right : a ∈ I → (a + b ∈ I ↔ b ∈ I) := I.add_mem_iff_right protected lemma sub_mem : a ∈ I → b ∈ I → a - b ∈ I := I.sub_mem lemma mul_mem_left : b ∈ I → a * b ∈ I := I.smul_mem _ lemma mul_mem_right (h : a ∈ I) : a * b ∈ I := mul_comm b a ▸ I.mul_mem_left h end ideal /-- Vector spaces are defined as an `abbreviation` for modules, if the base ring is a field. (A previous definition made `vector_space` a structure defined to be `module`.) This has as advantage that vector spaces are completely transparent for type class inference, which means that all instances for modules are immediately picked up for vector spaces as well. A cosmetic disadvantage is that one can not extend vector spaces an sich, in definitions such as `normed_space`. The solution is to extend `module` instead. -/ library_note "vector space definition" /-- A vector space is the same as a module, except the scalar ring is actually a field. (This adds commutativity of the multiplication and existence of inverses.) This is the traditional generalization of spaces like `ℝ^n`, which have a natural addition operation and a way to multiply them by real numbers, but no multiplication operation between vectors. -/ abbreviation vector_space (k : Type u) (M : Type v) [field k] [add_comm_group M] := module k M instance field.to_vector_space {k : Type*} [field k] : vector_space k k := ring.to_module /-- Subspace of a vector space. Defined to equal `submodule`. -/ @[reducible] def subspace (k : Type u) (M : Type v) [field k] [add_comm_group M] [vector_space k M] : Type v := submodule k M instance subspace.vector_space {k M} {f : field k} [add_comm_group M] [vector_space k M] (p : subspace k M) : vector_space k p := p.module namespace submodule variables [division_ring R] [add_comm_group M] [module R M] variables (p : submodule R M) {r : R} {x y : M} theorem smul_mem_iff (r0 : r ≠ 0) : r • x ∈ p ↔ x ∈ p := p.smul_mem_iff' (units.mk0 r r0) end submodule namespace add_comm_monoid open add_monoid variables [add_comm_monoid M] /-- The natural ℕ-semimodule structure on any `add_comm_monoid`. -/ -- We don't make this a global instance, as it results in too many instances, -- and confusing ambiguity in the notation `n • x` when `n : ℕ`. def nat_semimodule : semimodule ℕ M := { smul := smul, smul_add := λ _ _ _, smul_add _ _ _, add_smul := λ _ _ _, add_smul _ _ _, mul_smul := λ _ _ _, mul_smul _ _ _, one_smul := one_smul, zero_smul := zero_smul, smul_zero := smul_zero } end add_comm_monoid namespace add_comm_group variables [add_comm_group M] /-- The natural ℤ-module structure on any `add_comm_group`. -/ -- We don't immediately make this a global instance, as it results in too many instances, -- and confusing ambiguity in the notation `n • x` when `n : ℤ`. -- We do turn it into a global instance, but only at the end of this file, -- and I remain dubious whether this is a good idea. def int_module : module ℤ M := { smul := gsmul, smul_add := λ _ _ _, gsmul_add _ _ _, add_smul := λ _ _ _, add_gsmul _ _ _, mul_smul := λ _ _ _, gsmul_mul _ _ _, one_smul := one_gsmul, zero_smul := zero_gsmul, smul_zero := gsmul_zero } instance : subsingleton (module ℤ M) := begin split, intros P Q, ext, -- isn't that lovely: `r • m = r • m` have one_smul : by { haveI := P, exact (1 : ℤ) • m } = by { haveI := Q, exact (1 : ℤ) • m }, begin rw [@one_smul ℤ _ _ (by { haveI := P, apply_instance, }) m], rw [@one_smul ℤ _ _ (by { haveI := Q, apply_instance, }) m], end, have nat_smul : ∀ n : ℕ, by { haveI := P, exact (n : ℤ) • m } = by { haveI := Q, exact (n : ℤ) • m }, begin intro n, induction n with n ih, { erw [zero_smul, zero_smul], }, { rw [int.coe_nat_succ, add_smul, add_smul], erw ih, rw [one_smul], } end, cases r, { rw [int.of_nat_eq_coe, nat_smul], }, { rw [int.neg_succ_of_nat_coe, neg_smul, neg_smul, nat_smul], } end end add_comm_group section local attribute [instance] add_comm_monoid.nat_semimodule lemma semimodule.smul_eq_smul (R : Type*) [semiring R] {M : Type*} [add_comm_monoid M] [semimodule R M] (n : ℕ) (b : M) : n • b = (n : R) • b := begin induction n with n ih, { rw [nat.cast_zero, zero_smul, zero_smul] }, { change (n + 1) • b = (n + 1 : R) • b, rw [add_smul, add_smul, one_smul, ih, one_smul] } end lemma semimodule.add_monoid_smul_eq_smul (R : Type*) [semiring R] {M : Type*} [add_comm_monoid M] [semimodule R M] (n : ℕ) (b : M) : add_monoid.smul n b = (n : R) • b := semimodule.smul_eq_smul R n b lemma nat.smul_def {M : Type*} [add_comm_monoid M] (n : ℕ) (x : M) : n • x = add_monoid.smul n x := rfl end section local attribute [instance] add_comm_group.int_module lemma gsmul_eq_smul {M : Type*} [add_comm_group M] (n : ℤ) (x : M) : gsmul n x = n • x := rfl lemma module.gsmul_eq_smul_cast (R : Type*) [ring R] {β : Type*} [add_comm_group β] [module R β] (n : ℤ) (b : β) : gsmul n b = (n : R) • b := begin cases n, { apply semimodule.add_monoid_smul_eq_smul, }, { dsimp, rw semimodule.add_monoid_smul_eq_smul R, push_cast, rw neg_smul, } end lemma module.gsmul_eq_smul {M : Type*} [add_comm_group M] [module ℤ M] (n : ℤ) (b : M) : gsmul n b = n • b := by rw [module.gsmul_eq_smul_cast ℤ, int.cast_id] end -- We prove this without using the `add_comm_group.int_module` instance, so the `•`s here -- come from whatever the local `module ℤ` structure actually is. lemma add_monoid_hom.map_int_module_smul [add_comm_group M] [add_comm_group M₂] [module ℤ M] [module ℤ M₂] (f : M →+ M₂) (x : ℤ) (a : M) : f (x • a) = x • f a := by simp only [← module.gsmul_eq_smul, f.map_gsmul] lemma add_monoid_hom.map_int_cast_smul [ring R] [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂] (f : M →+ M₂) (x : ℤ) (a : M) : f ((x : R) • a) = (x : R) • f a := by simp only [← module.gsmul_eq_smul_cast, f.map_gsmul] lemma add_monoid_hom.map_nat_cast_smul [semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [semimodule R M] [semimodule R M₂] (f : M →+ M₂) (x : ℕ) (a : M) : f ((x : R) • a) = (x : R) • f a := by simp only [← semimodule.add_monoid_smul_eq_smul, f.map_smul] lemma add_monoid_hom.map_rat_cast_smul {R : Type*} [division_ring R] [char_zero R] {E : Type*} [add_comm_group E] [module R E] {F : Type*} [add_comm_group F] [module R F] (f : E →+ F) (c : ℚ) (x : E) : f ((c : R) • x) = (c : R) • f x := begin have : ∀ (x : E) (n : ℕ), 0 < n → f (((n⁻¹ : ℚ) : R) • x) = ((n⁻¹ : ℚ) : R) • f x, { intros x n hn, replace hn : (n : R) ≠ 0 := nat.cast_ne_zero.2 (ne_of_gt hn), conv_rhs { congr, skip, rw [← one_smul R x, ← mul_inv_cancel hn, mul_smul] }, rw [f.map_nat_cast_smul, smul_smul, rat.cast_inv, rat.cast_coe_nat, inv_mul_cancel hn, one_smul] }, refine c.num_denom_cases_on (λ m n hn hmn, _), rw [rat.mk_eq_div, div_eq_mul_inv, rat.cast_mul, int.cast_coe_nat, mul_smul, mul_smul, rat.cast_coe_int, f.map_int_cast_smul, this _ n hn] end lemma add_monoid_hom.map_rat_module_smul {E : Type*} [add_comm_group E] [vector_space ℚ E] {F : Type*} [add_comm_group F] [module ℚ F] (f : E →+ F) (c : ℚ) (x : E) : f (c • x) = c • f x := rat.cast_id c ▸ f.map_rat_cast_smul c x -- We finally turn on these instances globally: attribute [instance] add_comm_monoid.nat_semimodule add_comm_group.int_module /-- Reinterpret an additive homomorphism as a `ℤ`-linear map. -/ def add_monoid_hom.to_int_linear_map [add_comm_group M] [add_comm_group M₂] (f : M →+ M₂) : M →ₗ[ℤ] M₂ := ⟨f, f.map_add, f.map_int_module_smul⟩ /-- Reinterpret an additive homomorphism as a `ℚ`-linear map. -/ def add_monoid_hom.to_rat_linear_map [add_comm_group M] [vector_space ℚ M] [add_comm_group M₂] [vector_space ℚ M₂] (f : M →+ M₂) : M →ₗ[ℚ] M₂ := ⟨f, f.map_add, f.map_rat_module_smul⟩ namespace finset variable (R) lemma sum_const' [semiring R] [add_comm_monoid M] [semimodule R M] {s : finset ι} (b : M) : finset.sum s (λ (i : ι), b) = (finset.card s : R) • b := by rw [finset.sum_const, ← semimodule.smul_eq_smul]; refl variables {R} [decidable_linear_ordered_cancel_add_comm_monoid M] {s : finset ι} (f : ι → M) theorem exists_card_smul_le_sum (hs : s.nonempty) : ∃ i ∈ s, s.card • f i ≤ s.sum f := exists_le_of_sum_le hs $ by rw [sum_const, ← nat.smul_def, smul_sum] theorem exists_card_smul_ge_sum (hs : s.nonempty) : ∃ i ∈ s, s.sum f ≤ s.card • f i := exists_le_of_sum_le hs $ by rw [sum_const, ← nat.smul_def, smul_sum] end finset
39e31ef2e2e1984a13b31cb7279e71a7470600a5
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/combinatorics/set_family/shadow.lean
f02c1165296ea9701c6562d3eba71de0af03b691
[ "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
11,150
lean
/- Copyright (c) 2021 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Alena Gusakov, Yaël Dillies -/ import data.finset.slice import logic.function.iterate /-! # Shadows > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines shadows of a set family. The shadow of a set family is the set family of sets we get by removing any element from any set of the original family. If one pictures `finset α` as a big hypercube (each dimension being membership of a given element), then taking the shadow corresponds to projecting each finset down once in all available directions. ## Main definitions * `finset.shadow`: The shadow of a set family. Everything we can get by removing a new element from some set. * `finset.up_shadow`: The upper shadow of a set family. Everything we can get by adding an element to some set. ## Notation We define notation in locale `finset_family`: * `∂ 𝒜`: Shadow of `𝒜`. * `∂⁺ 𝒜`: Upper shadow of `𝒜`. We also maintain the convention that `a, b : α` are elements of the ground type, `s, t : finset α` are finsets, and `𝒜, ℬ : finset (finset α)` are finset families. ## References * https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf * http://discretemath.imp.fu-berlin.de/DMII-2015-16/kruskal.pdf ## Tags shadow, set family -/ open finset nat variables {α : Type*} namespace finset section shadow variables [decidable_eq α] {𝒜 : finset (finset α)} {s t : finset α} {a : α} {k r : ℕ} /-- The shadow of a set family `𝒜` is all sets we can get by removing one element from any set in `𝒜`, and the (`k` times) iterated shadow (`shadow^[k]`) is all sets we can get by removing `k` elements from any set in `𝒜`. -/ def shadow (𝒜 : finset (finset α)) : finset (finset α) := 𝒜.sup (λ s, s.image (erase s)) localized "notation (name := finset.shadow) `∂ `:90 := finset.shadow" in finset_family /-- The shadow of the empty set is empty. -/ @[simp] lemma shadow_empty : ∂ (∅ : finset (finset α)) = ∅ := rfl @[simp] lemma shadow_singleton_empty : ∂ ({∅} : finset (finset α)) = ∅ := rfl --TODO: Prove `∂ {{a}} = {∅}` quickly using `covers` and `grade_order` /-- The shadow is monotone. -/ @[mono] lemma shadow_monotone : monotone (shadow : finset (finset α) → finset (finset α)) := λ 𝒜 ℬ, sup_mono /-- `s` is in the shadow of `𝒜` iff there is an `t ∈ 𝒜` from which we can remove one element to get `s`. -/ lemma mem_shadow_iff : s ∈ ∂ 𝒜 ↔ ∃ t ∈ 𝒜, ∃ a ∈ t, erase t a = s := by simp only [shadow, mem_sup, mem_image] lemma erase_mem_shadow (hs : s ∈ 𝒜) (ha : a ∈ s) : erase s a ∈ ∂ 𝒜 := mem_shadow_iff.2 ⟨s, hs, a, ha, rfl⟩ /-- `t` is in the shadow of `𝒜` iff we can add an element to it so that the resulting finset is in `𝒜`. -/ lemma mem_shadow_iff_insert_mem : s ∈ ∂ 𝒜 ↔ ∃ a ∉ s, insert a s ∈ 𝒜 := begin refine mem_shadow_iff.trans ⟨_, _⟩, { rintro ⟨s, hs, a, ha, rfl⟩, refine ⟨a, not_mem_erase a s, _⟩, rwa insert_erase ha }, { rintro ⟨a, ha, hs⟩, exact ⟨insert a s, hs, a, mem_insert_self _ _, erase_insert ha⟩ } end /-- The shadow of a family of `r`-sets is a family of `r - 1`-sets. -/ protected lemma _root_.set.sized.shadow (h𝒜 : (𝒜 : set (finset α)).sized r) : (∂ 𝒜 : set (finset α)).sized (r - 1) := begin intros A h, obtain ⟨A, hA, i, hi, rfl⟩ := mem_shadow_iff.1 h, rw [card_erase_of_mem hi, h𝒜 hA], end lemma sized_shadow_iff (h : ∅ ∉ 𝒜) : (∂ 𝒜 : set (finset α)).sized r ↔ (𝒜 : set (finset α)).sized (r + 1) := begin refine ⟨λ h𝒜 s hs, _, set.sized.shadow⟩, obtain ⟨a, ha⟩ := nonempty_iff_ne_empty.2 (ne_of_mem_of_not_mem hs h), rw [←h𝒜 (erase_mem_shadow hs ha), card_erase_add_one ha], end /-- `s ∈ ∂ 𝒜` iff `s` is exactly one element less than something from `𝒜` -/ lemma mem_shadow_iff_exists_mem_card_add_one : s ∈ ∂ 𝒜 ↔ ∃ t ∈ 𝒜, s ⊆ t ∧ t.card = s.card + 1 := begin refine mem_shadow_iff_insert_mem.trans ⟨_, _⟩, { rintro ⟨a, ha, hs⟩, exact ⟨insert a s, hs, subset_insert _ _, card_insert_of_not_mem ha⟩ }, { rintro ⟨t, ht, hst, h⟩, obtain ⟨a, ha⟩ : ∃ a, t \ s = {a} := card_eq_one.1 (by rw [card_sdiff hst, h, add_tsub_cancel_left]), exact ⟨a, λ hat, not_mem_sdiff_of_mem_right hat ((ha.ge : _ ⊆ _) $ mem_singleton_self a), by rwa [insert_eq a s, ←ha, sdiff_union_of_subset hst]⟩ } end /-- Being in the shadow of `𝒜` means we have a superset in `𝒜`. -/ lemma exists_subset_of_mem_shadow (hs : s ∈ ∂ 𝒜) : ∃ t ∈ 𝒜, s ⊆ t := let ⟨t, ht, hst⟩ := mem_shadow_iff_exists_mem_card_add_one.1 hs in ⟨t, ht, hst.1⟩ /-- `t ∈ ∂^k 𝒜` iff `t` is exactly `k` elements less than something in `𝒜`. -/ lemma mem_shadow_iff_exists_mem_card_add : s ∈ (∂^[k]) 𝒜 ↔ ∃ t ∈ 𝒜, s ⊆ t ∧ t.card = s.card + k := begin induction k with k ih generalizing 𝒜 s, { refine ⟨λ hs, ⟨s, hs, subset.refl _, rfl⟩, _⟩, rintro ⟨t, ht, hst, hcard⟩, rwa eq_of_subset_of_card_le hst hcard.le }, simp only [exists_prop, function.comp_app, function.iterate_succ], refine ih.trans _, clear ih, split, { rintro ⟨t, ht, hst, hcardst⟩, obtain ⟨u, hu, htu, hcardtu⟩ := mem_shadow_iff_exists_mem_card_add_one.1 ht, refine ⟨u, hu, hst.trans htu, _⟩, rw [hcardtu, hcardst], refl }, { rintro ⟨t, ht, hst, hcard⟩, obtain ⟨u, hsu, hut, hu⟩ := finset.exists_intermediate_set k (by { rw [add_comm, hcard], exact le_succ _ }) hst, rw add_comm at hu, refine ⟨u, mem_shadow_iff_exists_mem_card_add_one.2 ⟨t, ht, hut, _⟩, hsu, hu⟩, rw [hcard, hu], refl } end end shadow open_locale finset_family section up_shadow variables [decidable_eq α] [fintype α] {𝒜 : finset (finset α)} {s t : finset α} {a : α} {k r : ℕ} /-- The upper shadow of a set family `𝒜` is all sets we can get by adding one element to any set in `𝒜`, and the (`k` times) iterated upper shadow (`up_shadow^[k]`) is all sets we can get by adding `k` elements from any set in `𝒜`. -/ def up_shadow (𝒜 : finset (finset α)) : finset (finset α) := 𝒜.sup $ λ s, sᶜ.image $ λ a, insert a s localized "notation (name := finset.up_shadow) `∂⁺ `:90 := finset.up_shadow" in finset_family /-- The upper shadow of the empty set is empty. -/ @[simp] lemma up_shadow_empty : ∂⁺ (∅ : finset (finset α)) = ∅ := rfl /-- The upper shadow is monotone. -/ @[mono] lemma up_shadow_monotone : monotone (up_shadow : finset (finset α) → finset (finset α)) := λ 𝒜 ℬ, sup_mono /-- `s` is in the upper shadow of `𝒜` iff there is an `t ∈ 𝒜` from which we can remove one element to get `s`. -/ lemma mem_up_shadow_iff : s ∈ ∂⁺ 𝒜 ↔ ∃ t ∈ 𝒜, ∃ a ∉ t, insert a t = s := by simp_rw [up_shadow, mem_sup, mem_image, exists_prop, mem_compl] lemma insert_mem_up_shadow (hs : s ∈ 𝒜) (ha : a ∉ s) : insert a s ∈ ∂⁺ 𝒜 := mem_up_shadow_iff.2 ⟨s, hs, a, ha, rfl⟩ /-- The upper shadow of a family of `r`-sets is a family of `r + 1`-sets. -/ protected lemma _root_.set.sized.up_shadow (h𝒜 : (𝒜 : set (finset α)).sized r) : (∂⁺ 𝒜 : set (finset α)).sized (r + 1) := begin intros A h, obtain ⟨A, hA, i, hi, rfl⟩ := mem_up_shadow_iff.1 h, rw [card_insert_of_not_mem hi, h𝒜 hA], end /-- `t` is in the upper shadow of `𝒜` iff we can remove an element from it so that the resulting finset is in `𝒜`. -/ lemma mem_up_shadow_iff_erase_mem : s ∈ ∂⁺ 𝒜 ↔ ∃ a ∈ s, s.erase a ∈ 𝒜 := begin refine mem_up_shadow_iff.trans ⟨_, _⟩, { rintro ⟨s, hs, a, ha, rfl⟩, refine ⟨a, mem_insert_self a s, _⟩, rwa erase_insert ha }, { rintro ⟨a, ha, hs⟩, exact ⟨s.erase a, hs, a, not_mem_erase _ _, insert_erase ha⟩ } end /-- `s ∈ ∂⁺ 𝒜` iff `s` is exactly one element less than something from `𝒜`. -/ lemma mem_up_shadow_iff_exists_mem_card_add_one : s ∈ ∂⁺ 𝒜 ↔ ∃ t ∈ 𝒜, t ⊆ s ∧ t.card + 1 = s.card := begin refine mem_up_shadow_iff_erase_mem.trans ⟨_, _⟩, { rintro ⟨a, ha, hs⟩, exact ⟨s.erase a, hs, erase_subset _ _, card_erase_add_one ha⟩ }, { rintro ⟨t, ht, hts, h⟩, obtain ⟨a, ha⟩ : ∃ a, s \ t = {a} := card_eq_one.1 (by rw [card_sdiff hts, ←h, add_tsub_cancel_left]), refine ⟨a, sdiff_subset _ _ ((ha.ge : _ ⊆ _) $ mem_singleton_self a), _⟩, rwa [←sdiff_singleton_eq_erase, ←ha, sdiff_sdiff_eq_self hts] } end /-- Being in the upper shadow of `𝒜` means we have a superset in `𝒜`. -/ lemma exists_subset_of_mem_up_shadow (hs : s ∈ ∂⁺ 𝒜) : ∃ t ∈ 𝒜, t ⊆ s := let ⟨t, ht, hts, _⟩ := mem_up_shadow_iff_exists_mem_card_add_one.1 hs in ⟨t, ht, hts⟩ /-- `t ∈ ∂^k 𝒜` iff `t` is exactly `k` elements more than something in `𝒜`. -/ lemma mem_up_shadow_iff_exists_mem_card_add : s ∈ (∂⁺^[k]) 𝒜 ↔ ∃ t ∈ 𝒜, t ⊆ s ∧ t.card + k = s.card := begin induction k with k ih generalizing 𝒜 s, { refine ⟨λ hs, ⟨s, hs, subset.refl _, rfl⟩, _⟩, rintro ⟨t, ht, hst, hcard⟩, rwa ←eq_of_subset_of_card_le hst hcard.ge }, simp only [exists_prop, function.comp_app, function.iterate_succ], refine ih.trans _, clear ih, split, { rintro ⟨t, ht, hts, hcardst⟩, obtain ⟨u, hu, hut, hcardtu⟩ := mem_up_shadow_iff_exists_mem_card_add_one.1 ht, refine ⟨u, hu, hut.trans hts, _⟩, rw [←hcardst, ←hcardtu, add_right_comm], refl }, { rintro ⟨t, ht, hts, hcard⟩, obtain ⟨u, htu, hus, hu⟩ := finset.exists_intermediate_set 1 (by { rw [add_comm, ←hcard], exact add_le_add_left (zero_lt_succ _) _ }) hts, rw add_comm at hu, refine ⟨u, mem_up_shadow_iff_exists_mem_card_add_one.2 ⟨t, ht, htu, hu.symm⟩, hus, _⟩, rw [hu, ←hcard, add_right_comm], refl } end @[simp] lemma shadow_image_compl : (∂ 𝒜).image compl = ∂⁺ (𝒜.image compl) := begin ext s, simp only [mem_image, exists_prop, mem_shadow_iff, mem_up_shadow_iff], split, { rintro ⟨_, ⟨s, hs, a, ha, rfl⟩, rfl⟩, exact ⟨sᶜ, ⟨s, hs, rfl⟩, a, not_mem_compl.2 ha, compl_erase.symm⟩ }, { rintro ⟨_, ⟨s, hs, rfl⟩, a, ha, rfl⟩, exact ⟨s.erase a, ⟨s, hs, a, not_mem_compl.1 ha, rfl⟩, compl_erase⟩ } end @[simp] lemma up_shadow_image_compl : (∂⁺ 𝒜).image compl = ∂ (𝒜.image compl) := begin ext s, simp only [mem_image, exists_prop, mem_shadow_iff, mem_up_shadow_iff], split, { rintro ⟨_, ⟨s, hs, a, ha, rfl⟩, rfl⟩, exact ⟨sᶜ, ⟨s, hs, rfl⟩, a, mem_compl.2 ha, compl_insert.symm⟩ }, { rintro ⟨_, ⟨s, hs, rfl⟩, a, ha, rfl⟩, exact ⟨insert a s, ⟨s, hs, a, mem_compl.1 ha, rfl⟩, compl_insert⟩ } end end up_shadow end finset
dfaa6a78b8b55a9a35b2761539c19e431b10e771
6e9cd8d58e550c481a3b45806bd34a3514c6b3e0
/src/algebra/ordered_group.lean
e33420a72091f4e7f44297cdfba8e3f5cf7ba6a6
[ "Apache-2.0" ]
permissive
sflicht/mathlib
220fd16e463928110e7b0a50bbed7b731979407f
1b2048d7195314a7e34e06770948ee00f0ac3545
refs/heads/master
1,665,934,056,043
1,591,373,803,000
1,591,373,803,000
269,815,267
0
0
Apache-2.0
1,591,402,068,000
1,591,402,067,000
null
UTF-8
Lean
false
false
55,974
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.units import algebra.group.with_one import algebra.group.type_tags import order.bounded_lattice set_option old_structure_cmd true set_option default_priority 100 -- see Note [default priority] /-! # Ordered monoids and groups -/ universe u variable {α : Type u} /-- An ordered (additive) commutative monoid is a commutative monoid with a partial order such that addition is an order embedding, i.e. `a + b ≤ a + c ↔ b ≤ c`. These monoids are automatically cancellative. -/ @[protect_proj] 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) section ordered_add_comm_monoid variables [ordered_add_comm_monoid α] {a b c d : α} lemma add_le_add_left' (h : a ≤ b) : c + a ≤ c + b := ordered_add_comm_monoid.add_le_add_left a b h c lemma add_le_add_right' (h : a ≤ b) : a + c ≤ b + c := add_comm c a ▸ add_comm c b ▸ add_le_add_left' h lemma lt_of_add_lt_add_left' : a + b < a + c → b < c := ordered_add_comm_monoid.lt_of_add_lt_add_left a b c lemma add_le_add' (h₁ : a ≤ b) (h₂ : c ≤ d) : a + c ≤ b + d := le_trans (add_le_add_right' h₁) (add_le_add_left' h₂) lemma le_add_of_nonneg_right' (h : 0 ≤ b) : a ≤ a + b := have a + 0 ≤ a + b, from add_le_add_left' h, by rwa add_zero at this lemma le_add_of_nonneg_left' (h : 0 ≤ b) : a ≤ b + a := have 0 + a ≤ b + a, from add_le_add_right' h, by rwa zero_add at this lemma lt_of_add_lt_add_right' (h : a + b < c + b) : a < c := lt_of_add_lt_add_left' (show b + a < b + c, begin rw [add_comm b a, add_comm b c], assumption end) -- here we start using properties of zero. lemma le_add_of_nonneg_of_le' (ha : 0 ≤ a) (hbc : b ≤ c) : b ≤ a + c := zero_add b ▸ add_le_add' ha hbc lemma le_add_of_le_of_nonneg' (hbc : b ≤ c) (ha : 0 ≤ a) : b ≤ c + a := add_zero b ▸ add_le_add' hbc ha lemma add_nonneg' (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a + b := le_add_of_nonneg_of_le' ha hb lemma add_pos_of_pos_of_nonneg' (ha : 0 < a) (hb : 0 ≤ b) : 0 < a + b := lt_of_lt_of_le ha $ le_add_of_nonneg_right' hb lemma add_pos' (ha : 0 < a) (hb : 0 < b) : 0 < a + b := add_pos_of_pos_of_nonneg' ha $ le_of_lt hb lemma add_pos_of_nonneg_of_pos' (ha : 0 ≤ a) (hb : 0 < b) : 0 < a + b := lt_of_lt_of_le hb $ le_add_of_nonneg_left' ha lemma add_nonpos' (ha : a ≤ 0) (hb : b ≤ 0) : a + b ≤ 0 := zero_add (0:α) ▸ (add_le_add' ha hb) lemma add_le_of_nonpos_of_le' (ha : a ≤ 0) (hbc : b ≤ c) : a + b ≤ c := zero_add c ▸ add_le_add' ha hbc lemma add_le_of_le_of_nonpos' (hbc : b ≤ c) (ha : a ≤ 0) : b + a ≤ c := add_zero c ▸ add_le_add' hbc ha lemma add_neg_of_neg_of_nonpos' (ha : a < 0) (hb : b ≤ 0) : a + b < 0 := lt_of_le_of_lt (add_le_of_le_of_nonpos' (le_refl _) hb) ha lemma add_neg_of_nonpos_of_neg' (ha : a ≤ 0) (hb : b < 0) : a + b < 0 := lt_of_le_of_lt (add_le_of_nonpos_of_le' ha (le_refl _)) hb lemma add_neg' (ha : a < 0) (hb : b < 0) : a + b < 0 := add_neg_of_nonpos_of_neg' (le_of_lt ha) hb lemma lt_add_of_nonneg_of_lt' (ha : 0 ≤ a) (hbc : b < c) : b < a + c := lt_of_lt_of_le hbc $ le_add_of_nonneg_left' ha lemma lt_add_of_lt_of_nonneg' (hbc : b < c) (ha : 0 ≤ a) : b < c + a := lt_of_lt_of_le hbc $ le_add_of_nonneg_right' ha lemma lt_add_of_pos_of_lt' (ha : 0 < a) (hbc : b < c) : b < a + c := lt_add_of_nonneg_of_lt' (le_of_lt ha) hbc lemma lt_add_of_lt_of_pos' (hbc : b < c) (ha : 0 < a) : b < c + a := lt_add_of_lt_of_nonneg' hbc (le_of_lt ha) lemma add_lt_of_nonpos_of_lt' (ha : a ≤ 0) (hbc : b < c) : a + b < c := lt_of_le_of_lt (add_le_of_nonpos_of_le' ha (le_refl _)) hbc lemma add_lt_of_lt_of_nonpos' (hbc : b < c) (ha : a ≤ 0) : b + a < c := lt_of_le_of_lt (add_le_of_le_of_nonpos' (le_refl _) ha) hbc lemma add_lt_of_neg_of_lt' (ha : a < 0) (hbc : b < c) : a + b < c := add_lt_of_nonpos_of_lt' (le_of_lt ha) hbc lemma add_lt_of_lt_of_neg' (hbc : b < c) (ha : a < 0) : b + a < c := add_lt_of_lt_of_nonpos' hbc (le_of_lt ha) lemma add_eq_zero_iff' (ha : 0 ≤ a) (hb : 0 ≤ b) : a + b = 0 ↔ a = 0 ∧ b = 0 := iff.intro (assume hab : a + b = 0, have a ≤ 0, from hab ▸ le_add_of_le_of_nonneg' (le_refl _) hb, have a = 0, from le_antisymm this ha, have b ≤ 0, from hab ▸ le_add_of_nonneg_of_le' ha (le_refl _), have b = 0, from le_antisymm this hb, and.intro ‹a = 0› ‹b = 0›) (assume ⟨ha', hb'⟩, by rw [ha', hb', add_zero]) lemma bit0_pos {a : α} (h : 0 < a) : 0 < bit0 a := add_pos' h h section mono variables {β : Type*} [preorder β] {f g : β → α} lemma monotone.add (hf : monotone f) (hg : monotone g) : monotone (λ x, f x + g x) := λ x y h, add_le_add' (hf h) (hg h) lemma monotone.add_const (hf : monotone f) (a : α) : monotone (λ x, f x + a) := hf.add monotone_const lemma monotone.const_add (hf : monotone f) (a : α) : monotone (λ x, a + f x) := monotone_const.add hf end mono end ordered_add_comm_monoid namespace units instance [monoid α] [i : preorder α] : preorder (units α) := preorder.lift (coe : units α → α) i @[simp] theorem coe_le_coe [monoid α] [preorder α] {a b : units α} : (a : α) ≤ b ↔ a ≤ b := iff.rfl @[simp] theorem coe_lt_coe [monoid α] [preorder α] {a b : units α} : (a : α) < b ↔ a < b := iff.rfl instance [monoid α] [i : partial_order α] : partial_order (units α) := partial_order.lift (coe : units α → α) (by ext) i instance [monoid α] [i : linear_order α] : linear_order (units α) := linear_order.lift (coe : units α → α) (by ext) i instance [monoid α] [i : decidable_linear_order α] : decidable_linear_order (units α) := decidable_linear_order.lift (coe : units α → α) (by ext) i theorem max_coe [monoid α] [decidable_linear_order α] {a b : units α} : (↑(max a b) : α) = max a b := by by_cases a ≤ b; simp [max, h] theorem min_coe [monoid α] [decidable_linear_order α] {a b : units α} : (↑(min a b) : α) = min a b := by by_cases a ≤ b; simp [min, h] end units namespace 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 instance [lattice α] : lattice (with_zero α) := with_bot.lattice instance [linear_order α] : linear_order (with_zero α) := with_bot.linear_order instance [decidable_linear_order α] : decidable_linear_order (with_zero α) := with_bot.decidable_linear_order /-- 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 instance [add_semigroup α] : add_semigroup (with_top α) := { add := λ o₁ o₂, o₁.bind (λ a, o₂.map (λ b, a + b)), ..@additive.add_semigroup _ $ @with_zero.semigroup (multiplicative α) _ } lemma coe_add [add_semigroup α] {a b : α} : ((a + b : α) : with_top α) = a + b := rfl 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 _ $ @with_zero.monoid (multiplicative α) _ } instance [add_comm_monoid α] : add_comm_monoid (with_top α) := { zero := 0, add := (+), ..@additive.add_comm_monoid _ $ @with_zero.comm_monoid (multiplicative α) _ } instance [ordered_add_comm_monoid α] : ordered_add_comm_monoid (with_top α) := begin suffices, refine { add_le_add_left := this, ..with_top.partial_order, ..with_top.add_comm_monoid, ..}, { intros a b c h, have h' := h, rw lt_iff_le_not_le at h' ⊢, refine ⟨λ c h₂, _, λ h₂, h'.2 $ this _ _ h₂ _⟩, cases h₂, cases a with a, { exact (not_le_of_lt h).elim le_top }, cases b with b, { exact (not_le_of_lt h).elim le_top }, { exact ⟨_, rfl, le_of_lt (lt_of_add_lt_add_left' $ with_top.some_lt_some.1 h)⟩ } }, { intros a b h c ca h₂, cases c with c, {cases h₂}, cases b with b; cases h₂, cases a with a, {cases le_antisymm h le_top }, simp at h, exact ⟨_, rfl, add_le_add_left' h⟩, } end @[simp] lemma zero_lt_top [ordered_add_comm_monoid α] : (0 : with_top α) < ⊤ := coe_lt_top 0 @[simp] lemma zero_lt_coe [ordered_add_comm_monoid α] (a : α) : (0 : with_top α) < a ↔ 0 < a := coe_lt_coe @[simp] lemma add_top [ordered_add_comm_monoid α] : ∀{a : with_top α}, a + ⊤ = ⊤ | none := rfl | (some a) := rfl @[simp] lemma top_add [ordered_add_comm_monoid α] {a : with_top α} : ⊤ + a = ⊤ := rfl lemma add_eq_top [ordered_add_comm_monoid α] (a b : with_top α) : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := by cases a; cases b; simp [none_eq_top, some_eq_coe, coe_add.symm] lemma add_lt_top [ordered_add_comm_monoid α] (a b : with_top α) : a + b < ⊤ ↔ a < ⊤ ∧ b < ⊤ := begin apply not_iff_not.1, simp [lt_top_iff_ne_top, add_eq_top], finish, apply classical.dec _, apply classical.dec _, end end with_top namespace with_bot 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 @[simp] lemma coe_zero [add_monoid α] : ((0 : α) : with_bot α) = 0 := rfl @[simp] lemma coe_add [add_semigroup α] (a b : α) : ((a + b : α) : with_bot α) = a + b := rfl @[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 instance has_one [has_one α] : has_one (with_bot α) := ⟨(1 : α)⟩ @[simp] lemma coe_one [has_one α] : ((1 : α) : with_bot α) = 1 := rfl end with_bot /-- 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`. This is satisfied by the natural numbers, for example, but not the integers or other ordered groups. -/ @[protect_proj] 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) section canonically_ordered_add_monoid variables [canonically_ordered_add_monoid α] {a b c d : α} lemma le_iff_exists_add : a ≤ b ↔ ∃c, b = a + c := canonically_ordered_add_monoid.le_iff_exists_add a b @[simp] lemma zero_le (a : α) : 0 ≤ a := le_iff_exists_add.mpr ⟨a, by simp⟩ @[simp] lemma bot_eq_zero : (⊥ : α) = 0 := le_antisymm bot_le (zero_le ⊥) @[simp] lemma add_eq_zero_iff : a + b = 0 ↔ a = 0 ∧ b = 0 := add_eq_zero_iff' (zero_le _) (zero_le _) @[simp] lemma le_zero_iff_eq : a ≤ 0 ↔ a = 0 := iff.intro (assume h, le_antisymm h (zero_le a)) (assume h, h ▸ le_refl a) protected lemma zero_lt_iff_ne_zero : 0 < a ↔ a ≠ 0 := iff.intro ne_of_gt $ assume hne, lt_of_le_of_ne (zero_le _) hne.symm lemma le_add_left (h : a ≤ c) : a ≤ b + c := calc a = 0 + a : by simp ... ≤ b + c : add_le_add' (zero_le _) h lemma le_add_right (h : a ≤ b) : a ≤ b + c := calc a = a + 0 : by simp ... ≤ b + c : add_le_add' h (zero_le _) instance with_zero.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 : 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, _⟩, simp [with_top.coe_add] }, { 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_add_monoid @[protect_proj] class ordered_cancel_add_comm_monoid (α : Type u) extends add_comm_monoid α, add_left_cancel_semigroup α, add_right_cancel_semigroup α, 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) section ordered_cancel_add_comm_monoid variables [ordered_cancel_add_comm_monoid α] {a b c d : α} lemma add_le_add_left : ∀ {a b : α} (h : a ≤ b) (c : α), c + a ≤ c + b := ordered_cancel_add_comm_monoid.add_le_add_left lemma le_of_add_le_add_left : ∀ {a b c : α}, a + b ≤ a + c → b ≤ c := ordered_cancel_add_comm_monoid.le_of_add_le_add_left lemma add_lt_add_left (h : a < b) (c : α) : c + a < c + b := lt_of_le_not_le (add_le_add_left (le_of_lt h) _) $ mt le_of_add_le_add_left (not_le_of_gt h) lemma lt_of_add_lt_add_left (h : a + b < a + c) : b < c := lt_of_le_not_le (le_of_add_le_add_left (le_of_lt h)) $ mt (λ h, add_le_add_left h _) (not_le_of_gt h) lemma add_le_add_right (h : a ≤ b) (c : α) : a + c ≤ b + c := add_comm c a ▸ add_comm c b ▸ add_le_add_left h c theorem add_lt_add_right (h : a < b) (c : α) : a + c < b + c := begin rw [add_comm a c, add_comm b c], exact (add_lt_add_left h c) end lemma add_le_add {a b c d : α} (h₁ : a ≤ b) (h₂ : c ≤ d) : a + c ≤ b + d := le_trans (add_le_add_right h₁ c) (add_le_add_left h₂ b) lemma le_add_of_nonneg_right (h : 0 ≤ b) : a ≤ a + b := have a + 0 ≤ a + b, from add_le_add_left h a, by rwa add_zero at this lemma le_add_of_nonneg_left (h : 0 ≤ b) : a ≤ b + a := have 0 + a ≤ b + a, from add_le_add_right h a, by rwa zero_add at this lemma add_lt_add (h₁ : a < b) (h₂ : c < d) : a + c < b + d := lt_trans (add_lt_add_right h₁ c) (add_lt_add_left h₂ b) lemma add_lt_add_of_le_of_lt (h₁ : a ≤ b) (h₂ : c < d) : a + c < b + d := lt_of_le_of_lt (add_le_add_right h₁ c) (add_lt_add_left h₂ b) lemma add_lt_add_of_lt_of_le (h₁ : a < b) (h₂ : c ≤ d) : a + c < b + d := lt_of_lt_of_le (add_lt_add_right h₁ c) (add_le_add_left h₂ b) lemma lt_add_of_pos_right (a : α) {b : α} (h : 0 < b) : a < a + b := have a + 0 < a + b, from add_lt_add_left h a, by rwa [add_zero] at this lemma lt_add_of_pos_left (a : α) {b : α} (h : 0 < b) : a < b + a := have 0 + a < b + a, from add_lt_add_right h a, by rwa [zero_add] at this lemma le_of_add_le_add_right (h : a + b ≤ c + b) : a ≤ c := le_of_add_le_add_left (show b + a ≤ b + c, begin rw [add_comm b a, add_comm b c], assumption end) lemma lt_of_add_lt_add_right (h : a + b < c + b) : a < c := lt_of_add_lt_add_left (show b + a < b + c, begin rw [add_comm b a, add_comm b c], assumption end) -- here we start using properties of zero. lemma add_nonneg (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a + b := zero_add (0:α) ▸ (add_le_add ha hb) lemma add_pos (ha : 0 < a) (hb : 0 < b) : 0 < a + b := zero_add (0:α) ▸ (add_lt_add ha hb) lemma add_pos_of_pos_of_nonneg (ha : 0 < a) (hb : 0 ≤ b) : 0 < a + b := zero_add (0:α) ▸ (add_lt_add_of_lt_of_le ha hb) lemma add_pos_of_nonneg_of_pos (ha : 0 ≤ a) (hb : 0 < b) : 0 < a + b := zero_add (0:α) ▸ (add_lt_add_of_le_of_lt ha hb) lemma add_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : a + b ≤ 0 := zero_add (0:α) ▸ (add_le_add ha hb) lemma add_neg (ha : a < 0) (hb : b < 0) : a + b < 0 := zero_add (0:α) ▸ (add_lt_add ha hb) lemma add_neg_of_neg_of_nonpos (ha : a < 0) (hb : b ≤ 0) : a + b < 0 := zero_add (0:α) ▸ (add_lt_add_of_lt_of_le ha hb) lemma add_neg_of_nonpos_of_neg (ha : a ≤ 0) (hb : b < 0) : a + b < 0 := zero_add (0:α) ▸ (add_lt_add_of_le_of_lt ha hb) lemma add_eq_zero_iff_eq_zero_and_eq_zero_of_nonneg_of_nonneg (ha : 0 ≤ a) (hb : 0 ≤ b) : a + b = 0 ↔ a = 0 ∧ b = 0 := iff.intro (assume hab : a + b = 0, have ha' : a ≤ 0, from calc a = a + 0 : by rw add_zero ... ≤ a + b : add_le_add_left hb _ ... = 0 : hab, have haz : a = 0, from le_antisymm ha' ha, have hb' : b ≤ 0, from calc b = 0 + b : by rw zero_add ... ≤ a + b : by exact add_le_add_right ha _ ... = 0 : hab, have hbz : b = 0, from le_antisymm hb' hb, and.intro haz hbz) (assume ⟨ha', hb'⟩, by rw [ha', hb', add_zero]) lemma le_add_of_nonneg_of_le (ha : 0 ≤ a) (hbc : b ≤ c) : b ≤ a + c := zero_add b ▸ add_le_add ha hbc lemma le_add_of_le_of_nonneg (hbc : b ≤ c) (ha : 0 ≤ a) : b ≤ c + a := add_zero b ▸ add_le_add hbc ha lemma lt_add_of_pos_of_le (ha : 0 < a) (hbc : b ≤ c) : b < a + c := zero_add b ▸ add_lt_add_of_lt_of_le ha hbc lemma lt_add_of_le_of_pos (hbc : b ≤ c) (ha : 0 < a) : b < c + a := add_zero b ▸ add_lt_add_of_le_of_lt hbc ha lemma add_le_of_nonpos_of_le (ha : a ≤ 0) (hbc : b ≤ c) : a + b ≤ c := zero_add c ▸ add_le_add ha hbc lemma add_le_of_le_of_nonpos (hbc : b ≤ c) (ha : a ≤ 0) : b + a ≤ c := add_zero c ▸ add_le_add hbc ha lemma add_lt_of_neg_of_le (ha : a < 0) (hbc : b ≤ c) : a + b < c := zero_add c ▸ add_lt_add_of_lt_of_le ha hbc lemma add_lt_of_le_of_neg (hbc : b ≤ c) (ha : a < 0) : b + a < c := add_zero c ▸ add_lt_add_of_le_of_lt hbc ha lemma lt_add_of_nonneg_of_lt (ha : 0 ≤ a) (hbc : b < c) : b < a + c := zero_add b ▸ add_lt_add_of_le_of_lt ha hbc lemma lt_add_of_lt_of_nonneg (hbc : b < c) (ha : 0 ≤ a) : b < c + a := add_zero b ▸ add_lt_add_of_lt_of_le hbc ha lemma lt_add_of_pos_of_lt (ha : 0 < a) (hbc : b < c) : b < a + c := zero_add b ▸ add_lt_add ha hbc lemma lt_add_of_lt_of_pos (hbc : b < c) (ha : 0 < a) : b < c + a := add_zero b ▸ add_lt_add hbc ha lemma add_lt_of_nonpos_of_lt (ha : a ≤ 0) (hbc : b < c) : a + b < c := zero_add c ▸ add_lt_add_of_le_of_lt ha hbc lemma add_lt_of_lt_of_nonpos (hbc : b < c) (ha : a ≤ 0) : b + a < c := add_zero c ▸ add_lt_add_of_lt_of_le hbc ha lemma add_lt_of_neg_of_lt (ha : a < 0) (hbc : b < c) : a + b < c := zero_add c ▸ add_lt_add ha hbc lemma add_lt_of_lt_of_neg (hbc : b < c) (ha : a < 0) : b + a < c := add_zero c ▸ add_lt_add hbc ha instance ordered_cancel_add_comm_monoid.to_ordered_add_comm_monoid : ordered_add_comm_monoid α := { lt_of_add_lt_add_left := @lt_of_add_lt_add_left _ _, ..‹ordered_cancel_add_comm_monoid α› } instance ordered_cancel_add_comm_monoid.to_add_left_cancel_monoid : add_left_cancel_monoid α := { ..‹ordered_cancel_add_comm_monoid α› } @[simp] lemma add_le_add_iff_left (a : α) {b c : α} : a + b ≤ a + c ↔ b ≤ c := ⟨le_of_add_le_add_left, λ h, add_le_add_left h _⟩ @[simp] lemma add_le_add_iff_right (c : α) : a + c ≤ b + c ↔ a ≤ b := add_comm c a ▸ add_comm c b ▸ add_le_add_iff_left c @[simp] lemma add_lt_add_iff_left (a : α) {b c : α} : a + b < a + c ↔ b < c := ⟨lt_of_add_lt_add_left, λ h, add_lt_add_left h _⟩ @[simp] lemma add_lt_add_iff_right (c : α) : a + c < b + c ↔ a < b := add_comm c a ▸ add_comm c b ▸ add_lt_add_iff_left c @[simp] lemma le_add_iff_nonneg_right (a : α) {b : α} : a ≤ a + b ↔ 0 ≤ b := have a + 0 ≤ a + b ↔ 0 ≤ b, from add_le_add_iff_left a, by rwa add_zero at this @[simp] lemma le_add_iff_nonneg_left (a : α) {b : α} : a ≤ b + a ↔ 0 ≤ b := by rw [add_comm, le_add_iff_nonneg_right] @[simp] lemma lt_add_iff_pos_right (a : α) {b : α} : a < a + b ↔ 0 < b := have a + 0 < a + b ↔ 0 < b, from add_lt_add_iff_left a, by rwa add_zero at this @[simp] lemma lt_add_iff_pos_left (a : α) {b : α} : a < b + a ↔ 0 < b := by rw [add_comm, lt_add_iff_pos_right] @[simp] lemma add_le_iff_nonpos_left : a + b ≤ b ↔ a ≤ 0 := by { convert add_le_add_iff_right b, rw [zero_add] } @[simp] lemma add_le_iff_nonpos_right : a + b ≤ a ↔ b ≤ 0 := by { convert add_le_add_iff_left a, rw [add_zero] } @[simp] lemma add_lt_iff_neg_right : a + b < b ↔ a < 0 := by { convert add_lt_add_iff_right b, rw [zero_add] } @[simp] lemma add_lt_iff_neg_left : a + b < a ↔ b < 0 := by { convert add_lt_add_iff_left a, rw [add_zero] } lemma add_eq_zero_iff_eq_zero_of_nonneg (ha : 0 ≤ a) (hb : 0 ≤ b) : a + b = 0 ↔ a = 0 ∧ b = 0 := ⟨λ hab : a + b = 0, by split; apply le_antisymm; try {assumption}; rw ← hab; simp [ha, hb], λ ⟨ha', hb'⟩, by rw [ha', hb', add_zero]⟩ 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], { rw [← with_top.coe_add], exact with_top.coe_lt_top _ }, { rw [← with_top.coe_add, ← with_top.coe_add, with_top.coe_lt_coe], exact add_lt_add_iff_left _ } end 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 section mono variables {β : Type*} [preorder β] {f g : β → α} lemma monotone.add_strict_mono (hf : monotone f) (hg : strict_mono g) : strict_mono (λ x, f x + g x) := λ x y h, add_lt_add_of_le_of_lt (hf $ le_of_lt h) (hg h) lemma strict_mono.add_monotone (hf : strict_mono f) (hg : monotone g) : strict_mono (λ x, f x + g x) := λ x y h, add_lt_add_of_lt_of_le (hf h) (hg $ le_of_lt h) lemma strict_mono.add_const (hf : strict_mono f) (c : α) : strict_mono (λ x, f x + c) := hf.add_monotone monotone_const lemma strict_mono.const_add (hf : strict_mono f) (c : α) : strict_mono (λ x, c + f x) := monotone_const.add_strict_mono hf end mono end ordered_cancel_add_comm_monoid @[protect_proj] class ordered_add_comm_group (α : Type u) extends add_comm_group α, partial_order α := (add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b) section ordered_add_comm_group variables [ordered_add_comm_group α] {a b c d : α} lemma ordered_add_comm_group.add_lt_add_left (a b : α) (h : a < b) (c : α) : c + a < c + b := begin rw lt_iff_le_not_le at h ⊢, split, { apply ordered_add_comm_group.add_le_add_left _ _ h.1 }, { intro w, have w : -c + (c + b) ≤ -c + (c + a) := ordered_add_comm_group.add_le_add_left _ _ w _, simp only [add_zero, add_comm, add_left_neg, add_left_comm] at w, exact h.2 w }, end lemma ordered_add_comm_group.le_of_add_le_add_left (h : a + b ≤ a + c) : b ≤ c := have -a + (a + b) ≤ -a + (a + c), from ordered_add_comm_group.add_le_add_left _ _ h _, begin simp [neg_add_cancel_left] at this, assumption end lemma ordered_add_comm_group.lt_of_add_lt_add_left (h : a + b < a + c) : b < c := have -a + (a + b) < -a + (a + c), from ordered_add_comm_group.add_lt_add_left _ _ h _, begin simp [neg_add_cancel_left] at this, assumption end instance ordered_add_comm_group.to_ordered_cancel_add_comm_monoid (α : Type u) [s : ordered_add_comm_group α] : ordered_cancel_add_comm_monoid α := { add_left_cancel := @add_left_cancel α _, add_right_cancel := @add_right_cancel α _, le_of_add_le_add_left := @ordered_add_comm_group.le_of_add_le_add_left α _, ..s } lemma neg_le_neg (h : a ≤ b) : -b ≤ -a := have 0 ≤ -a + b, from add_left_neg a ▸ add_le_add_left h (-a), have 0 + -b ≤ -a + b + -b, from add_le_add_right this (-b), by rwa [add_neg_cancel_right, zero_add] at this lemma le_of_neg_le_neg (h : -b ≤ -a) : a ≤ b := suffices -(-a) ≤ -(-b), from begin simp [neg_neg] at this, assumption end, neg_le_neg h lemma nonneg_of_neg_nonpos (h : -a ≤ 0) : 0 ≤ a := have -a ≤ -0, by rwa neg_zero, le_of_neg_le_neg this lemma neg_nonpos_of_nonneg (h : 0 ≤ a) : -a ≤ 0 := have -a ≤ -0, from neg_le_neg h, by rwa neg_zero at this lemma nonpos_of_neg_nonneg (h : 0 ≤ -a) : a ≤ 0 := have -0 ≤ -a, by rwa neg_zero, le_of_neg_le_neg this lemma neg_nonneg_of_nonpos (h : a ≤ 0) : 0 ≤ -a := have -0 ≤ -a, from neg_le_neg h, by rwa neg_zero at this lemma neg_lt_neg (h : a < b) : -b < -a := have 0 < -a + b, from add_left_neg a ▸ add_lt_add_left h (-a), have 0 + -b < -a + b + -b, from add_lt_add_right this (-b), by rwa [add_neg_cancel_right, zero_add] at this lemma lt_of_neg_lt_neg (h : -b < -a) : a < b := neg_neg a ▸ neg_neg b ▸ neg_lt_neg h lemma pos_of_neg_neg (h : -a < 0) : 0 < a := have -a < -0, by rwa neg_zero, lt_of_neg_lt_neg this lemma neg_neg_of_pos (h : 0 < a) : -a < 0 := have -a < -0, from neg_lt_neg h, by rwa neg_zero at this lemma neg_of_neg_pos (h : 0 < -a) : a < 0 := have -0 < -a, by rwa neg_zero, lt_of_neg_lt_neg this lemma neg_pos_of_neg (h : a < 0) : 0 < -a := have -0 < -a, from neg_lt_neg h, by rwa neg_zero at this lemma le_neg_of_le_neg (h : a ≤ -b) : b ≤ -a := begin have h := neg_le_neg h, rwa neg_neg at h end lemma neg_le_of_neg_le (h : -a ≤ b) : -b ≤ a := begin have h := neg_le_neg h, rwa neg_neg at h end lemma lt_neg_of_lt_neg (h : a < -b) : b < -a := begin have h := neg_lt_neg h, rwa neg_neg at h end lemma neg_lt_of_neg_lt (h : -a < b) : -b < a := begin have h := neg_lt_neg h, rwa neg_neg at h end lemma sub_nonneg_of_le (h : b ≤ a) : 0 ≤ a - b := begin have h := add_le_add_right h (-b), rwa add_right_neg at h end lemma le_of_sub_nonneg (h : 0 ≤ a - b) : b ≤ a := begin have h := add_le_add_right h b, rwa [sub_add_cancel, zero_add] at h end lemma sub_nonpos_of_le (h : a ≤ b) : a - b ≤ 0 := begin have h := add_le_add_right h (-b), rwa add_right_neg at h end lemma le_of_sub_nonpos (h : a - b ≤ 0) : a ≤ b := begin have h := add_le_add_right h b, rwa [sub_add_cancel, zero_add] at h end lemma sub_pos_of_lt (h : b < a) : 0 < a - b := begin have h := add_lt_add_right h (-b), rwa add_right_neg at h end lemma lt_of_sub_pos (h : 0 < a - b) : b < a := begin have h := add_lt_add_right h b, rwa [sub_add_cancel, zero_add] at h end lemma sub_neg_of_lt (h : a < b) : a - b < 0 := begin have h := add_lt_add_right h (-b), rwa add_right_neg at h end lemma lt_of_sub_neg (h : a - b < 0) : a < b := begin have h := add_lt_add_right h b, rwa [sub_add_cancel, zero_add] at h end lemma add_le_of_le_neg_add (h : b ≤ -a + c) : a + b ≤ c := begin have h := add_le_add_left h a, rwa add_neg_cancel_left at h end lemma le_neg_add_of_add_le (h : a + b ≤ c) : b ≤ -a + c := begin have h := add_le_add_left h (-a), rwa neg_add_cancel_left at h end lemma add_le_of_le_sub_left (h : b ≤ c - a) : a + b ≤ c := begin have h := add_le_add_left h a, rwa [← add_sub_assoc, add_comm a c, add_sub_cancel] at h end lemma le_sub_left_of_add_le (h : a + b ≤ c) : b ≤ c - a := begin have h := add_le_add_right h (-a), rwa [add_comm a b, add_neg_cancel_right] at h end lemma add_le_of_le_sub_right (h : a ≤ c - b) : a + b ≤ c := begin have h := add_le_add_right h b, rwa sub_add_cancel at h end lemma le_sub_right_of_add_le (h : a + b ≤ c) : a ≤ c - b := begin have h := add_le_add_right h (-b), rwa add_neg_cancel_right at h end lemma le_add_of_neg_add_le (h : -b + a ≤ c) : a ≤ b + c := begin have h := add_le_add_left h b, rwa add_neg_cancel_left at h end lemma neg_add_le_of_le_add (h : a ≤ b + c) : -b + a ≤ c := begin have h := add_le_add_left h (-b), rwa neg_add_cancel_left at h end lemma le_add_of_sub_left_le (h : a - b ≤ c) : a ≤ b + c := begin have h := add_le_add_right h b, rwa [sub_add_cancel, add_comm] at h end lemma sub_left_le_of_le_add (h : a ≤ b + c) : a - b ≤ c := begin have h := add_le_add_right h (-b), rwa [add_comm b c, add_neg_cancel_right] at h end lemma le_add_of_sub_right_le (h : a - c ≤ b) : a ≤ b + c := begin have h := add_le_add_right h c, rwa sub_add_cancel at h end lemma sub_right_le_of_le_add (h : a ≤ b + c) : a - c ≤ b := begin have h := add_le_add_right h (-c), rwa add_neg_cancel_right at h end lemma le_add_of_neg_add_le_left (h : -b + a ≤ c) : a ≤ b + c := begin rw add_comm at h, exact le_add_of_sub_left_le h end lemma neg_add_le_left_of_le_add (h : a ≤ b + c) : -b + a ≤ c := begin rw add_comm, exact sub_left_le_of_le_add h end lemma le_add_of_neg_add_le_right (h : -c + a ≤ b) : a ≤ b + c := begin rw add_comm at h, exact le_add_of_sub_right_le h end lemma neg_add_le_right_of_le_add (h : a ≤ b + c) : -c + a ≤ b := begin rw add_comm at h, apply neg_add_le_left_of_le_add h end lemma le_add_of_neg_le_sub_left (h : -a ≤ b - c) : c ≤ a + b := le_add_of_neg_add_le_left (add_le_of_le_sub_right h) lemma neg_le_sub_left_of_le_add (h : c ≤ a + b) : -a ≤ b - c := begin have h := le_neg_add_of_add_le (sub_left_le_of_le_add h), rwa add_comm at h end lemma le_add_of_neg_le_sub_right (h : -b ≤ a - c) : c ≤ a + b := le_add_of_sub_right_le (add_le_of_le_sub_left h) lemma neg_le_sub_right_of_le_add (h : c ≤ a + b) : -b ≤ a - c := le_sub_left_of_add_le (sub_right_le_of_le_add h) lemma sub_le_of_sub_le (h : a - b ≤ c) : a - c ≤ b := sub_left_le_of_le_add (le_add_of_sub_right_le h) lemma sub_le_sub_left (h : a ≤ b) (c : α) : c - b ≤ c - a := add_le_add_left (neg_le_neg h) c lemma sub_le_sub_right (h : a ≤ b) (c : α) : a - c ≤ b - c := add_le_add_right h (-c) lemma sub_le_sub (hab : a ≤ b) (hcd : c ≤ d) : a - d ≤ b - c := add_le_add hab (neg_le_neg hcd) lemma add_lt_of_lt_neg_add (h : b < -a + c) : a + b < c := begin have h := add_lt_add_left h a, rwa add_neg_cancel_left at h end lemma lt_neg_add_of_add_lt (h : a + b < c) : b < -a + c := begin have h := add_lt_add_left h (-a), rwa neg_add_cancel_left at h end lemma add_lt_of_lt_sub_left (h : b < c - a) : a + b < c := begin have h := add_lt_add_left h a, rwa [← add_sub_assoc, add_comm a c, add_sub_cancel] at h end lemma lt_sub_left_of_add_lt (h : a + b < c) : b < c - a := begin have h := add_lt_add_right h (-a), rwa [add_comm a b, add_neg_cancel_right] at h end lemma add_lt_of_lt_sub_right (h : a < c - b) : a + b < c := begin have h := add_lt_add_right h b, rwa sub_add_cancel at h end lemma lt_sub_right_of_add_lt (h : a + b < c) : a < c - b := begin have h := add_lt_add_right h (-b), rwa add_neg_cancel_right at h end lemma lt_add_of_neg_add_lt (h : -b + a < c) : a < b + c := begin have h := add_lt_add_left h b, rwa add_neg_cancel_left at h end lemma neg_add_lt_of_lt_add (h : a < b + c) : -b + a < c := begin have h := add_lt_add_left h (-b), rwa neg_add_cancel_left at h end lemma lt_add_of_sub_left_lt (h : a - b < c) : a < b + c := begin have h := add_lt_add_right h b, rwa [sub_add_cancel, add_comm] at h end lemma sub_left_lt_of_lt_add (h : a < b + c) : a - b < c := begin have h := add_lt_add_right h (-b), rwa [add_comm b c, add_neg_cancel_right] at h end lemma lt_add_of_sub_right_lt (h : a - c < b) : a < b + c := begin have h := add_lt_add_right h c, rwa sub_add_cancel at h end lemma sub_right_lt_of_lt_add (h : a < b + c) : a - c < b := begin have h := add_lt_add_right h (-c), rwa add_neg_cancel_right at h end lemma lt_add_of_neg_add_lt_left (h : -b + a < c) : a < b + c := begin rw add_comm at h, exact lt_add_of_sub_left_lt h end lemma neg_add_lt_left_of_lt_add (h : a < b + c) : -b + a < c := begin rw add_comm, exact sub_left_lt_of_lt_add h end lemma lt_add_of_neg_add_lt_right (h : -c + a < b) : a < b + c := begin rw add_comm at h, exact lt_add_of_sub_right_lt h end lemma neg_add_lt_right_of_lt_add (h : a < b + c) : -c + a < b := begin rw add_comm at h, apply neg_add_lt_left_of_lt_add h end lemma lt_add_of_neg_lt_sub_left (h : -a < b - c) : c < a + b := lt_add_of_neg_add_lt_left (add_lt_of_lt_sub_right h) lemma neg_lt_sub_left_of_lt_add (h : c < a + b) : -a < b - c := begin have h := lt_neg_add_of_add_lt (sub_left_lt_of_lt_add h), rwa add_comm at h end lemma lt_add_of_neg_lt_sub_right (h : -b < a - c) : c < a + b := lt_add_of_sub_right_lt (add_lt_of_lt_sub_left h) lemma neg_lt_sub_right_of_lt_add (h : c < a + b) : -b < a - c := lt_sub_left_of_add_lt (sub_right_lt_of_lt_add h) lemma sub_lt_of_sub_lt (h : a - b < c) : a - c < b := sub_left_lt_of_lt_add (lt_add_of_sub_right_lt h) lemma sub_lt_sub_left (h : a < b) (c : α) : c - b < c - a := add_lt_add_left (neg_lt_neg h) c lemma sub_lt_sub_right (h : a < b) (c : α) : a - c < b - c := add_lt_add_right h (-c) lemma sub_lt_sub (hab : a < b) (hcd : c < d) : a - d < b - c := add_lt_add hab (neg_lt_neg hcd) lemma sub_lt_sub_of_le_of_lt (hab : a ≤ b) (hcd : c < d) : a - d < b - c := add_lt_add_of_le_of_lt hab (neg_lt_neg hcd) lemma sub_lt_sub_of_lt_of_le (hab : a < b) (hcd : c ≤ d) : a - d < b - c := add_lt_add_of_lt_of_le hab (neg_le_neg hcd) lemma sub_le_self (a : α) {b : α} (h : 0 ≤ b) : a - b ≤ a := calc a - b = a + -b : rfl ... ≤ a + 0 : add_le_add_left (neg_nonpos_of_nonneg h) _ ... = a : by rw add_zero lemma sub_lt_self (a : α) {b : α} (h : 0 < b) : a - b < a := calc a - b = a + -b : rfl ... < a + 0 : add_lt_add_left (neg_neg_of_pos h) _ ... = a : by rw add_zero lemma add_le_add_three {a b c d e f : α} (h₁ : a ≤ d) (h₂ : b ≤ e) (h₃ : c ≤ f) : a + b + c ≤ d + e + f := begin apply le_trans, apply add_le_add, apply add_le_add, assumption', apply le_refl end @[simp] lemma neg_neg_iff_pos : -a < 0 ↔ 0 < a := ⟨ pos_of_neg_neg, neg_neg_of_pos ⟩ @[simp] lemma neg_le_neg_iff : -a ≤ -b ↔ b ≤ a := have a + b - a ≤ a + b - b ↔ -a ≤ -b, from add_le_add_iff_left _, by simp at this; simp [this] lemma neg_le : -a ≤ b ↔ -b ≤ a := have -a ≤ -(-b) ↔ -b ≤ a, from neg_le_neg_iff, by rwa neg_neg at this lemma le_neg : a ≤ -b ↔ b ≤ -a := have -(-a) ≤ -b ↔ b ≤ -a, from neg_le_neg_iff, by rwa neg_neg at this lemma neg_le_iff_add_nonneg : -a ≤ b ↔ 0 ≤ a + b := (add_le_add_iff_left a).symm.trans $ by rw add_neg_self lemma le_neg_iff_add_nonpos : a ≤ -b ↔ a + b ≤ 0 := (add_le_add_iff_right b).symm.trans $ by rw neg_add_self @[simp] lemma neg_nonpos : -a ≤ 0 ↔ 0 ≤ a := have -a ≤ -0 ↔ 0 ≤ a, from neg_le_neg_iff, by rwa neg_zero at this @[simp] lemma neg_nonneg : 0 ≤ -a ↔ a ≤ 0 := have -0 ≤ -a ↔ a ≤ 0, from neg_le_neg_iff, by rwa neg_zero at this lemma neg_le_self (h : 0 ≤ a) : -a ≤ a := le_trans (neg_nonpos.2 h) h lemma self_le_neg (h : a ≤ 0) : a ≤ -a := le_trans h (neg_nonneg.2 h) @[simp] lemma neg_lt_neg_iff : -a < -b ↔ b < a := have a + b - a < a + b - b ↔ -a < -b, from add_lt_add_iff_left _, by simp at this; simp [this] lemma neg_lt_zero : -a < 0 ↔ 0 < a := have -a < -0 ↔ 0 < a, from neg_lt_neg_iff, by rwa neg_zero at this lemma neg_pos : 0 < -a ↔ a < 0 := have -0 < -a ↔ a < 0, from neg_lt_neg_iff, by rwa neg_zero at this lemma neg_lt : -a < b ↔ -b < a := have -a < -(-b) ↔ -b < a, from neg_lt_neg_iff, by rwa neg_neg at this lemma lt_neg : a < -b ↔ b < -a := have -(-a) < -b ↔ b < -a, from neg_lt_neg_iff, by rwa neg_neg at this @[simp] lemma sub_le_sub_iff_left (a : α) {b c : α} : a - b ≤ a - c ↔ c ≤ b := (add_le_add_iff_left _).trans neg_le_neg_iff @[simp] lemma sub_le_sub_iff_right (c : α) : a - c ≤ b - c ↔ a ≤ b := add_le_add_iff_right _ @[simp] lemma sub_lt_sub_iff_left (a : α) {b c : α} : a - b < a - c ↔ c < b := (add_lt_add_iff_left _).trans neg_lt_neg_iff @[simp] lemma sub_lt_sub_iff_right (c : α) : a - c < b - c ↔ a < b := add_lt_add_iff_right _ @[simp] lemma sub_nonneg : 0 ≤ a - b ↔ b ≤ a := have a - a ≤ a - b ↔ b ≤ a, from sub_le_sub_iff_left a, by rwa sub_self at this @[simp] lemma sub_nonpos : a - b ≤ 0 ↔ a ≤ b := have a - b ≤ b - b ↔ a ≤ b, from sub_le_sub_iff_right b, by rwa sub_self at this @[simp] lemma sub_pos : 0 < a - b ↔ b < a := have a - a < a - b ↔ b < a, from sub_lt_sub_iff_left a, by rwa sub_self at this @[simp] lemma sub_lt_zero : a - b < 0 ↔ a < b := have a - b < b - b ↔ a < b, from sub_lt_sub_iff_right b, by rwa sub_self at this lemma le_neg_add_iff_add_le : b ≤ -a + c ↔ a + b ≤ c := have -a + (a + b) ≤ -a + c ↔ a + b ≤ c, from add_le_add_iff_left _, by rwa neg_add_cancel_left at this lemma le_sub_iff_add_le' : b ≤ c - a ↔ a + b ≤ c := by rw [sub_eq_add_neg, add_comm, le_neg_add_iff_add_le] lemma le_sub_iff_add_le : a ≤ c - b ↔ a + b ≤ c := by rw [le_sub_iff_add_le', add_comm] @[simp] lemma neg_add_le_iff_le_add : -b + a ≤ c ↔ a ≤ b + c := have -b + a ≤ -b + (b + c) ↔ a ≤ b + c, from add_le_add_iff_left _, by rwa neg_add_cancel_left at this lemma sub_le_iff_le_add' : a - b ≤ c ↔ a ≤ b + c := by rw [sub_eq_add_neg, add_comm, neg_add_le_iff_le_add] lemma sub_le_iff_le_add : a - c ≤ b ↔ a ≤ b + c := by rw [sub_le_iff_le_add', add_comm] lemma add_neg_le_iff_le_add : a + -c ≤ b ↔ a ≤ b + c := sub_le_iff_le_add @[simp] lemma add_neg_le_iff_le_add' : a + -b ≤ c ↔ a ≤ b + c := sub_le_iff_le_add' lemma neg_add_le_iff_le_add' : -c + a ≤ b ↔ a ≤ b + c := by rw [neg_add_le_iff_le_add, add_comm] @[simp] lemma neg_le_sub_iff_le_add : -b ≤ a - c ↔ c ≤ a + b := le_sub_iff_add_le.trans neg_add_le_iff_le_add' lemma neg_le_sub_iff_le_add' : -a ≤ b - c ↔ c ≤ a + b := by rw [neg_le_sub_iff_le_add, add_comm] lemma sub_le : a - b ≤ c ↔ a - c ≤ b := sub_le_iff_le_add'.trans sub_le_iff_le_add.symm theorem le_sub : a ≤ b - c ↔ c ≤ b - a := le_sub_iff_add_le'.trans le_sub_iff_add_le.symm @[simp] lemma lt_neg_add_iff_add_lt : b < -a + c ↔ a + b < c := have -a + (a + b) < -a + c ↔ a + b < c, from add_lt_add_iff_left _, by rwa neg_add_cancel_left at this lemma lt_sub_iff_add_lt' : b < c - a ↔ a + b < c := by rw [sub_eq_add_neg, add_comm, lt_neg_add_iff_add_lt] lemma lt_sub_iff_add_lt : a < c - b ↔ a + b < c := by rw [lt_sub_iff_add_lt', add_comm] @[simp] lemma neg_add_lt_iff_lt_add : -b + a < c ↔ a < b + c := have -b + a < -b + (b + c) ↔ a < b + c, from add_lt_add_iff_left _, by rwa neg_add_cancel_left at this lemma sub_lt_iff_lt_add' : a - b < c ↔ a < b + c := by rw [sub_eq_add_neg, add_comm, neg_add_lt_iff_lt_add] lemma sub_lt_iff_lt_add : a - c < b ↔ a < b + c := by rw [sub_lt_iff_lt_add', add_comm] lemma neg_add_lt_iff_lt_add_right : -c + a < b ↔ a < b + c := by rw [neg_add_lt_iff_lt_add, add_comm] @[simp] lemma neg_lt_sub_iff_lt_add : -b < a - c ↔ c < a + b := lt_sub_iff_add_lt.trans neg_add_lt_iff_lt_add_right lemma neg_lt_sub_iff_lt_add' : -a < b - c ↔ c < a + b := by rw [neg_lt_sub_iff_lt_add, add_comm] lemma sub_lt : a - b < c ↔ a - c < b := sub_lt_iff_lt_add'.trans sub_lt_iff_lt_add.symm theorem lt_sub : a < b - c ↔ c < b - a := lt_sub_iff_add_lt'.trans lt_sub_iff_add_lt.symm lemma sub_le_self_iff (a : α) {b : α} : a - b ≤ a ↔ 0 ≤ b := sub_le_iff_le_add'.trans (le_add_iff_nonneg_left _) lemma sub_lt_self_iff (a : α) {b : α} : a - b < a ↔ 0 < b := sub_lt_iff_lt_add'.trans (lt_add_iff_pos_left _) end ordered_add_comm_group /-- The `add_lt_add_left` field of `ordered_add_comm_group` is redundant, but it is in core so we can't remove it for now. This alternative constructor is the best we can do. -/ def ordered_add_comm_group.mk' {α : Type u} [add_comm_group α] [partial_order α] (add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b) : ordered_add_comm_group α := { add_le_add_left := add_le_add_left, ..(by apply_instance : add_comm_group α), ..(by apply_instance : partial_order α) } @[protect_proj] class decidable_linear_ordered_cancel_add_comm_monoid (α : Type u) extends ordered_cancel_add_comm_monoid α, decidable_linear_order α section decidable_linear_ordered_cancel_add_comm_monoid variables [decidable_linear_ordered_cancel_add_comm_monoid α] lemma min_add_add_left (a b c : α) : min (a + b) (a + c) = a + min b c := eq.symm (eq_min (show a + min b c ≤ a + b, from add_le_add_left (min_le_left _ _) _) (show a + min b c ≤ a + c, from add_le_add_left (min_le_right _ _) _) (assume d, assume : d ≤ a + b, assume : d ≤ a + c, decidable.by_cases (assume : b ≤ c, by rwa [min_eq_left this]) (assume : ¬ b ≤ c, by rwa [min_eq_right (le_of_lt (lt_of_not_ge this))]))) lemma min_add_add_right (a b c : α) : min (a + c) (b + c) = min a b + c := begin rw [add_comm a c, add_comm b c, add_comm _ c], apply min_add_add_left end lemma max_add_add_left (a b c : α) : max (a + b) (a + c) = a + max b c := eq.symm (eq_max (add_le_add_left (le_max_left _ _) _) (add_le_add_left (le_max_right _ _) _) (assume d, assume : a + b ≤ d, assume : a + c ≤ d, decidable.by_cases (assume : b ≤ c, by rwa [max_eq_right this]) (assume : ¬ b ≤ c, by rwa [max_eq_left (le_of_lt (lt_of_not_ge this))]))) lemma max_add_add_right (a b c : α) : max (a + c) (b + c) = max a b + c := begin rw [add_comm a c, add_comm b c, add_comm _ c], apply max_add_add_left end end decidable_linear_ordered_cancel_add_comm_monoid @[protect_proj] class decidable_linear_ordered_add_comm_group (α : Type u) extends add_comm_group α, decidable_linear_order α := (add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b) instance decidable_linear_ordered_comm_group.to_ordered_add_comm_group (α : Type u) [s : decidable_linear_ordered_add_comm_group α] : ordered_add_comm_group α := { add := s.add, ..s } section decidable_linear_ordered_add_comm_group variables [decidable_linear_ordered_add_comm_group α] @[priority 100] -- see Note [lower instance priority] instance decidable_linear_ordered_add_comm_group.to_decidable_linear_ordered_cancel_add_comm_monoid : decidable_linear_ordered_cancel_add_comm_monoid α := { le_of_add_le_add_left := λ x y z, le_of_add_le_add_left, add_left_cancel := λ x y z, add_left_cancel, add_right_cancel := λ x y z, add_right_cancel, ..‹decidable_linear_ordered_add_comm_group α› } lemma decidable_linear_ordered_add_comm_group.add_lt_add_left (a b : α) (h : a < b) (c : α) : c + a < c + b := ordered_add_comm_group.add_lt_add_left a b h c lemma max_neg_neg (a b : α) : max (-a) (-b) = - min a b := eq.symm (eq_max (show -a ≤ -(min a b), from neg_le_neg $ min_le_left a b) (show -b ≤ -(min a b), from neg_le_neg $ min_le_right a b) (assume d, assume H₁ : -a ≤ d, assume H₂ : -b ≤ d, have H : -d ≤ min a b, from le_min (neg_le_of_neg_le H₁) (neg_le_of_neg_le H₂), show -(min a b) ≤ d, from neg_le_of_neg_le H)) lemma min_eq_neg_max_neg_neg (a b : α) : min a b = - max (-a) (-b) := by rw [max_neg_neg, neg_neg] lemma min_neg_neg (a b : α) : min (-a) (-b) = - max a b := by rw [min_eq_neg_max_neg_neg, neg_neg, neg_neg] lemma max_eq_neg_min_neg_neg (a b : α) : max a b = - min (-a) (-b) := by rw [min_neg_neg, neg_neg] def abs (a : α) : α := max a (-a) lemma abs_of_nonneg {a : α} (h : 0 ≤ a) : abs a = a := have h' : -a ≤ a, from le_trans (neg_nonpos_of_nonneg h) h, max_eq_left h' lemma abs_of_pos {a : α} (h : 0 < a) : abs a = a := abs_of_nonneg (le_of_lt h) lemma abs_of_nonpos {a : α} (h : a ≤ 0) : abs a = -a := have h' : a ≤ -a, from le_trans h (neg_nonneg_of_nonpos h), max_eq_right h' lemma abs_of_neg {a : α} (h : a < 0) : abs a = -a := abs_of_nonpos (le_of_lt h) lemma abs_zero : abs 0 = (0:α) := abs_of_nonneg (le_refl _) lemma abs_neg (a : α) : abs (-a) = abs a := begin unfold abs, rw [max_comm, neg_neg] end lemma abs_pos_of_pos {a : α} (h : 0 < a) : 0 < abs a := by rwa (abs_of_pos h) lemma abs_pos_of_neg {a : α} (h : a < 0) : 0 < abs a := abs_neg a ▸ abs_pos_of_pos (neg_pos_of_neg h) lemma abs_sub (a b : α) : abs (a - b) = abs (b - a) := by rw [← neg_sub, abs_neg] lemma ne_zero_of_abs_ne_zero {a : α} (h : abs a ≠ 0) : a ≠ 0 := assume ha, h (eq.symm ha ▸ abs_zero) /- these assume a linear order -/ lemma eq_zero_of_neg_eq {a : α} (h : -a = a) : a = 0 := match lt_trichotomy a 0 with | or.inl h₁ := have 0 < a, from h ▸ neg_pos_of_neg h₁, absurd h₁ (lt_asymm this) | or.inr (or.inl h₁) := h₁ | or.inr (or.inr h₁) := have a < 0, from h ▸ neg_neg_of_pos h₁, absurd h₁ (lt_asymm this) end lemma abs_nonneg (a : α) : 0 ≤ abs a := or.elim (le_total 0 a) (assume h : 0 ≤ a, by rwa (abs_of_nonneg h)) (assume h : a ≤ 0, calc 0 ≤ -a : neg_nonneg_of_nonpos h ... = abs a : eq.symm (abs_of_nonpos h)) lemma abs_abs (a : α) : abs (abs a) = abs a := abs_of_nonneg $ abs_nonneg a lemma le_abs_self (a : α) : a ≤ abs a := or.elim (le_total 0 a) (assume h : 0 ≤ a, begin rw [abs_of_nonneg h] end) (assume h : a ≤ 0, le_trans h $ abs_nonneg a) lemma neg_le_abs_self (a : α) : -a ≤ abs a := abs_neg a ▸ le_abs_self (-a) lemma eq_zero_of_abs_eq_zero {a : α} (h : abs a = 0) : a = 0 := have h₁ : a ≤ 0, from h ▸ le_abs_self a, have h₂ : -a ≤ 0, from h ▸ abs_neg a ▸ le_abs_self (-a), le_antisymm h₁ (nonneg_of_neg_nonpos h₂) lemma eq_of_abs_sub_eq_zero {a b : α} (h : abs (a - b) = 0) : a = b := have a - b = 0, from eq_zero_of_abs_eq_zero h, show a = b, from eq_of_sub_eq_zero this lemma abs_pos_of_ne_zero {a : α} (h : a ≠ 0) : 0 < abs a := or.elim (lt_or_gt_of_ne h) abs_pos_of_neg abs_pos_of_pos lemma abs_by_cases (P : α → Prop) {a : α} (h1 : P a) (h2 : P (-a)) : P (abs a) := or.elim (le_total 0 a) (assume h : 0 ≤ a, eq.symm (abs_of_nonneg h) ▸ h1) (assume h : a ≤ 0, eq.symm (abs_of_nonpos h) ▸ h2) lemma abs_le_of_le_of_neg_le {a b : α} (h1 : a ≤ b) (h2 : -a ≤ b) : abs a ≤ b := abs_by_cases (λ x : α, x ≤ b) h1 h2 lemma abs_lt_of_lt_of_neg_lt {a b : α} (h1 : a < b) (h2 : -a < b) : abs a < b := abs_by_cases (λ x : α, x < b) h1 h2 private lemma aux1 {a b : α} (h1 : 0 ≤ a + b) (h2 : 0 ≤ a) : abs (a + b) ≤ abs a + abs b := decidable.by_cases (assume h3 : 0 ≤ b, calc abs (a + b) ≤ abs (a + b) : by apply le_refl ... = a + b : by rw (abs_of_nonneg h1) ... = abs a + b : by rw (abs_of_nonneg h2) ... = abs a + abs b : by rw (abs_of_nonneg h3)) (assume h3 : ¬ 0 ≤ b, have h4 : b ≤ 0, from le_of_lt (lt_of_not_ge h3), calc abs (a + b) = a + b : by rw (abs_of_nonneg h1) ... = abs a + b : by rw (abs_of_nonneg h2) ... ≤ abs a + 0 : add_le_add_left h4 _ ... ≤ abs a + -b : add_le_add_left (neg_nonneg_of_nonpos h4) _ ... = abs a + abs b : by rw (abs_of_nonpos h4)) private lemma aux2 {a b : α} (h1 : 0 ≤ a + b) : abs (a + b) ≤ abs a + abs b := or.elim (le_total b 0) (assume h2 : b ≤ 0, have h3 : ¬ a < 0, from assume h4 : a < 0, have h5 : a + b < 0, begin have aux := add_lt_add_of_lt_of_le h4 h2, rwa [add_zero] at aux end, not_lt_of_ge h1 h5, aux1 h1 (le_of_not_gt h3)) (assume h2 : 0 ≤ b, begin have h3 : abs (b + a) ≤ abs b + abs a, begin rw add_comm at h1, exact aux1 h1 h2 end, rw [add_comm, add_comm (abs a)], exact h3 end) lemma abs_add_le_abs_add_abs (a b : α) : abs (a + b) ≤ abs a + abs b := or.elim (le_total 0 (a + b)) (assume h2 : 0 ≤ a + b, aux2 h2) (assume h2 : a + b ≤ 0, have h3 : -a + -b = -(a + b), by rw neg_add, have h4 : 0 ≤ -(a + b), from neg_nonneg_of_nonpos h2, have h5 : 0 ≤ -a + -b, begin rw [← h3] at h4, exact h4 end, calc abs (a + b) = abs (-a + -b) : by rw [← abs_neg, neg_add] ... ≤ abs (-a) + abs (-b) : aux2 h5 ... = abs a + abs b : by rw [abs_neg, abs_neg]) lemma abs_sub_abs_le_abs_sub (a b : α) : abs a - abs b ≤ abs (a - b) := have h1 : abs a - abs b + abs b ≤ abs (a - b) + abs b, from calc abs a - abs b + abs b = abs a : by rw sub_add_cancel ... = abs (a - b + b) : by rw sub_add_cancel ... ≤ abs (a - b) + abs b : by apply abs_add_le_abs_add_abs, le_of_add_le_add_right h1 lemma abs_sub_le (a b c : α) : abs (a - c) ≤ abs (a - b) + abs (b - c) := calc abs (a - c) = abs (a - b + (b - c)) : by rw [sub_eq_add_neg, sub_eq_add_neg, sub_eq_add_neg, add_assoc, neg_add_cancel_left] ... ≤ abs (a - b) + abs (b - c) : by apply abs_add_le_abs_add_abs lemma abs_add_three (a b c : α) : abs (a + b + c) ≤ abs a + abs b + abs c := begin apply le_trans, apply abs_add_le_abs_add_abs, apply le_trans, apply add_le_add_right, apply abs_add_le_abs_add_abs, apply le_refl end lemma dist_bdd_within_interval {a b lb ub : α} (h : lb < ub) (hal : lb ≤ a) (hau : a ≤ ub) (hbl : lb ≤ b) (hbu : b ≤ ub) : abs (a - b) ≤ ub - lb := begin cases (decidable.em (b ≤ a)) with hba hba, rw (abs_of_nonneg (sub_nonneg_of_le hba)), apply sub_le_sub, apply hau, apply hbl, rw [abs_of_neg (sub_neg_of_lt (lt_of_not_ge hba)), neg_sub], apply sub_le_sub, apply hbu, apply hal end lemma decidable_linear_ordered_add_comm_group.eq_of_abs_sub_nonpos {a b : α} (h : abs (a - b) ≤ 0) : a = b := eq_of_abs_sub_eq_zero (le_antisymm h (abs_nonneg (a - b))) end decidable_linear_ordered_add_comm_group set_option old_structure_cmd true section prio set_option default_priority 100 -- see Note [default priority] /-- This is not so much a new structure as a construction mechanism for ordered groups, by specifying only the "positive cone" of the group. -/ class nonneg_add_comm_group (α : Type*) extends add_comm_group α := (nonneg : α → Prop) (pos : α → Prop := λ a, nonneg a ∧ ¬ nonneg (neg a)) (pos_iff : ∀ a, pos a ↔ nonneg a ∧ ¬ nonneg (-a) . order_laws_tac) (zero_nonneg : nonneg 0) (add_nonneg : ∀ {a b}, nonneg a → nonneg b → nonneg (a + b)) (nonneg_antisymm : ∀ {a}, nonneg a → nonneg (-a) → a = 0) end prio namespace nonneg_add_comm_group variable [s : nonneg_add_comm_group α] include s @[reducible, priority 100] -- see Note [lower instance priority] instance to_ordered_add_comm_group : ordered_add_comm_group α := { le := λ a b, nonneg (b - a), lt := λ a b, pos (b - a), lt_iff_le_not_le := λ a b, by simp; rw [pos_iff]; simp, le_refl := λ a, by simp [zero_nonneg], le_trans := λ a b c nab nbc, by simp [-sub_eq_add_neg]; rw ← sub_add_sub_cancel; exact add_nonneg nbc nab, le_antisymm := λ a b nab nba, eq_of_sub_eq_zero $ nonneg_antisymm nba (by rw neg_sub; exact nab), add_le_add_left := λ a b nab c, by simpa [(≤), preorder.le] using nab, ..s } theorem nonneg_def {a : α} : nonneg a ↔ 0 ≤ a := show _ ↔ nonneg _, by simp theorem pos_def {a : α} : pos a ↔ 0 < a := show _ ↔ pos _, by simp theorem not_zero_pos : ¬ pos (0 : α) := mt pos_def.1 (lt_irrefl _) theorem zero_lt_iff_nonneg_nonneg {a : α} : 0 < a ↔ nonneg a ∧ ¬ nonneg (-a) := pos_def.symm.trans (pos_iff _) theorem nonneg_total_iff : (∀ a : α, nonneg a ∨ nonneg (-a)) ↔ (∀ a b : α, a ≤ b ∨ b ≤ a) := ⟨λ h a b, by have := h (b - a); rwa [neg_sub] at this, λ h a, by rw [nonneg_def, nonneg_def, neg_nonneg]; apply h⟩ /-- A `nonneg_add_comm_group` is a `decidable_linear_ordered_add_comm_group` if `nonneg` is total and decidable. -/ def to_decidable_linear_ordered_add_comm_group [decidable_pred (@nonneg α _)] (nonneg_total : ∀ a : α, nonneg a ∨ nonneg (-a)) : decidable_linear_ordered_add_comm_group α := { le := (≤), lt := (<), lt_iff_le_not_le := @lt_iff_le_not_le _ _, le_refl := @le_refl _ _, le_trans := @le_trans _ _, le_antisymm := @le_antisymm _ _, le_total := nonneg_total_iff.1 nonneg_total, decidable_le := by apply_instance, decidable_lt := by apply_instance, ..@nonneg_add_comm_group.to_ordered_add_comm_group _ s } end nonneg_add_comm_group namespace order_dual instance [ordered_add_comm_monoid α] : ordered_add_comm_monoid (order_dual α) := { add_le_add_left := λ a b h c, @add_le_add_left' α _ b a c h, lt_of_add_lt_add_left := λ a b c h, @lt_of_add_lt_add_left' α _ a c b h, ..order_dual.partial_order α, ..show add_comm_monoid α, by apply_instance } instance [ordered_cancel_add_comm_monoid α] : ordered_cancel_add_comm_monoid (order_dual α) := { le_of_add_le_add_left := λ a b c : α, le_of_add_le_add_left, add_left_cancel := @add_left_cancel α _, add_right_cancel := @add_right_cancel α _, ..order_dual.ordered_add_comm_monoid } instance [ordered_add_comm_group α] : ordered_add_comm_group (order_dual α) := { add_left_neg := λ a : α, add_left_neg a, ..order_dual.ordered_add_comm_monoid, ..show add_comm_group α, by apply_instance } end order_dual
1c72b59563d4a4f69dfefa0679653f9ff6ff5b41
35677d2df3f081738fa6b08138e03ee36bc33cad
/src/data/nat/gcd.lean
a69126858568ba36ce5b390ae41b4e53e45f112a
[ "Apache-2.0" ]
permissive
gebner/mathlib
eab0150cc4f79ec45d2016a8c21750244a2e7ff0
cc6a6edc397c55118df62831e23bfbd6e6c6b4ab
refs/heads/master
1,625,574,853,976
1,586,712,827,000
1,586,712,827,000
99,101,412
1
0
Apache-2.0
1,586,716,389,000
1,501,667,958,000
Lean
UTF-8
Lean
false
false
15,710
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura Definitions and properties of gcd, lcm, and coprime. -/ import data.nat.basic namespace nat /- gcd -/ theorem gcd_dvd (m n : ℕ) : (gcd m n ∣ m) ∧ (gcd m n ∣ n) := gcd.induction m n (λn, by rw gcd_zero_left; exact ⟨dvd_zero n, dvd_refl n⟩) (λm n npos, by rw ←gcd_rec; exact λ ⟨IH₁, IH₂⟩, ⟨IH₂, (dvd_mod_iff IH₂).1 IH₁⟩) theorem gcd_dvd_left (m n : ℕ) : gcd m n ∣ m := (gcd_dvd m n).left theorem gcd_dvd_right (m n : ℕ) : gcd m n ∣ n := (gcd_dvd m n).right theorem gcd_le_left {m} (n) (h : 0 < m) : gcd m n ≤ m := le_of_dvd h $ gcd_dvd_left m n theorem gcd_le_right (m) {n} (h : 0 < n) : gcd m n ≤ n := le_of_dvd h $ gcd_dvd_right m n theorem dvd_gcd {m n k : ℕ} : k ∣ m → k ∣ n → k ∣ gcd m n := gcd.induction m n (λn _ kn, by rw gcd_zero_left; exact kn) (λn m mpos IH H1 H2, by rw gcd_rec; exact IH ((dvd_mod_iff H1).2 H2) H1) theorem dvd_gcd_iff {m n k : ℕ} : k ∣ gcd m n ↔ k ∣ m ∧ k ∣ n := iff.intro (λ h, ⟨dvd_trans h (gcd_dvd m n).left, dvd_trans h (gcd_dvd m n).right⟩) (λ h, dvd_gcd h.left h.right) theorem gcd_comm (m n : ℕ) : gcd m n = gcd n m := dvd_antisymm (dvd_gcd (gcd_dvd_right m n) (gcd_dvd_left m n)) (dvd_gcd (gcd_dvd_right n m) (gcd_dvd_left n m)) theorem gcd_eq_left_iff_dvd {m n : ℕ} : m ∣ n ↔ gcd m n = m := ⟨λ h, by rw [gcd_rec, mod_eq_zero_of_dvd h, gcd_zero_left], λ h, h ▸ gcd_dvd_right m n⟩ theorem gcd_eq_right_iff_dvd {m n : ℕ} : m ∣ n ↔ gcd n m = m := by rw gcd_comm; apply gcd_eq_left_iff_dvd theorem gcd_assoc (m n k : ℕ) : gcd (gcd m n) k = gcd m (gcd n k) := dvd_antisymm (dvd_gcd (dvd.trans (gcd_dvd_left (gcd m n) k) (gcd_dvd_left m n)) (dvd_gcd (dvd.trans (gcd_dvd_left (gcd m n) k) (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k))) (dvd_gcd (dvd_gcd (gcd_dvd_left m (gcd n k)) (dvd.trans (gcd_dvd_right m (gcd n k)) (gcd_dvd_left n k))) (dvd.trans (gcd_dvd_right m (gcd n k)) (gcd_dvd_right n k))) @[simp] theorem gcd_one_right (n : ℕ) : gcd n 1 = 1 := eq.trans (gcd_comm n 1) $ gcd_one_left n theorem gcd_mul_left (m n k : ℕ) : gcd (m * n) (m * k) = m * gcd n k := gcd.induction n k (λk, by repeat {rw mul_zero <|> rw gcd_zero_left}) (λk n H IH, by rwa [←mul_mod_mul_left, ←gcd_rec, ←gcd_rec] at IH) theorem gcd_mul_right (m n k : ℕ) : gcd (m * n) (k * n) = gcd m k * n := by rw [mul_comm m n, mul_comm k n, mul_comm (gcd m k) n, gcd_mul_left] theorem gcd_pos_of_pos_left {m : ℕ} (n : ℕ) (mpos : 0 < m) : 0 < gcd m n := pos_of_dvd_of_pos (gcd_dvd_left m n) mpos theorem gcd_pos_of_pos_right (m : ℕ) {n : ℕ} (npos : 0 < n) : 0 < gcd m n := pos_of_dvd_of_pos (gcd_dvd_right m n) npos theorem eq_zero_of_gcd_eq_zero_left {m n : ℕ} (H : gcd m n = 0) : m = 0 := or.elim (eq_zero_or_pos m) id (assume H1 : 0 < m, absurd (eq.symm H) (ne_of_lt (gcd_pos_of_pos_left _ H1))) theorem eq_zero_of_gcd_eq_zero_right {m n : ℕ} (H : gcd m n = 0) : n = 0 := by rw gcd_comm at H; exact eq_zero_of_gcd_eq_zero_left H theorem gcd_div {m n k : ℕ} (H1 : k ∣ m) (H2 : k ∣ n) : gcd (m / k) (n / k) = gcd m n / k := or.elim (eq_zero_or_pos k) (λk0, by rw [k0, nat.div_zero, nat.div_zero, nat.div_zero, gcd_zero_right]) (λH3, nat.eq_of_mul_eq_mul_right H3 $ by rw [ nat.div_mul_cancel (dvd_gcd H1 H2), ←gcd_mul_right, nat.div_mul_cancel H1, nat.div_mul_cancel H2]) theorem gcd_dvd_gcd_of_dvd_left {m k : ℕ} (n : ℕ) (H : m ∣ k) : gcd m n ∣ gcd k n := dvd_gcd (dvd.trans (gcd_dvd_left m n) H) (gcd_dvd_right m n) theorem gcd_dvd_gcd_of_dvd_right {m k : ℕ} (n : ℕ) (H : m ∣ k) : gcd n m ∣ gcd n k := dvd_gcd (gcd_dvd_left n m) (dvd.trans (gcd_dvd_right n m) H) theorem gcd_dvd_gcd_mul_left (m n k : ℕ) : gcd m n ∣ gcd (k * m) n := gcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _) theorem gcd_dvd_gcd_mul_right (m n k : ℕ) : gcd m n ∣ gcd (m * k) n := gcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _) theorem gcd_dvd_gcd_mul_left_right (m n k : ℕ) : gcd m n ∣ gcd m (k * n) := gcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _) theorem gcd_dvd_gcd_mul_right_right (m n k : ℕ) : gcd m n ∣ gcd m (n * k) := gcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _) theorem gcd_eq_left {m n : ℕ} (H : m ∣ n) : gcd m n = m := dvd_antisymm (gcd_dvd_left _ _) (dvd_gcd (dvd_refl _) H) theorem gcd_eq_right {m n : ℕ} (H : n ∣ m) : gcd m n = n := by rw [gcd_comm, gcd_eq_left H] @[simp] lemma gcd_mul_left_left (m n : ℕ) : gcd (m * n) n = n := dvd_antisymm (gcd_dvd_right _ _) (dvd_gcd (dvd_mul_left _ _) (dvd_refl _)) @[simp] lemma gcd_mul_left_right (m n : ℕ) : gcd n (m * n) = n := by rw [gcd_comm, gcd_mul_left_left] @[simp] lemma gcd_mul_right_left (m n : ℕ) : gcd (n * m) n = n := by rw [mul_comm, gcd_mul_left_left] @[simp] lemma gcd_mul_right_right (m n : ℕ) : gcd n (n * m) = n := by rw [gcd_comm, gcd_mul_right_left] @[simp] lemma gcd_gcd_self_right_left (m n : ℕ) : gcd m (gcd m n) = gcd m n := dvd_antisymm (gcd_dvd_right _ _) (dvd_gcd (gcd_dvd_left _ _) (dvd_refl _)) @[simp] lemma gcd_gcd_self_right_right (m n : ℕ) : gcd m (gcd n m) = gcd n m := by rw [gcd_comm n m, gcd_gcd_self_right_left] @[simp] lemma gcd_gcd_self_left_right (m n : ℕ) : gcd (gcd n m) m = gcd n m := by rw [gcd_comm, gcd_gcd_self_right_right] @[simp] lemma gcd_gcd_self_left_left (m n : ℕ) : gcd (gcd m n) m = gcd m n := by rw [gcd_comm m n, gcd_gcd_self_left_right] /- lcm -/ theorem lcm_comm (m n : ℕ) : lcm m n = lcm n m := by delta lcm; rw [mul_comm, gcd_comm] theorem lcm_zero_left (m : ℕ) : lcm 0 m = 0 := by delta lcm; rw [zero_mul, nat.zero_div] theorem lcm_zero_right (m : ℕ) : lcm m 0 = 0 := lcm_comm 0 m ▸ lcm_zero_left m theorem lcm_one_left (m : ℕ) : lcm 1 m = m := by delta lcm; rw [one_mul, gcd_one_left, nat.div_one] theorem lcm_one_right (m : ℕ) : lcm m 1 = m := lcm_comm 1 m ▸ lcm_one_left m theorem lcm_self (m : ℕ) : lcm m m = m := or.elim (eq_zero_or_pos m) (λh, by rw [h, lcm_zero_left]) (λh, by delta lcm; rw [gcd_self, nat.mul_div_cancel _ h]) theorem dvd_lcm_left (m n : ℕ) : m ∣ lcm m n := dvd.intro (n / gcd m n) (nat.mul_div_assoc _ $ gcd_dvd_right m n).symm theorem dvd_lcm_right (m n : ℕ) : n ∣ lcm m n := lcm_comm n m ▸ dvd_lcm_left n m theorem gcd_mul_lcm (m n : ℕ) : gcd m n * lcm m n = m * n := by delta lcm; rw [nat.mul_div_cancel' (dvd.trans (gcd_dvd_left m n) (dvd_mul_right m n))] theorem lcm_dvd {m n k : ℕ} (H1 : m ∣ k) (H2 : n ∣ k) : lcm m n ∣ k := or.elim (eq_zero_or_pos k) (λh, by rw h; exact dvd_zero _) (λkpos, dvd_of_mul_dvd_mul_left (gcd_pos_of_pos_left n (pos_of_dvd_of_pos H1 kpos)) $ by rw [gcd_mul_lcm, ←gcd_mul_right, mul_comm n k]; exact dvd_gcd (mul_dvd_mul_left _ H2) (mul_dvd_mul_right H1 _)) theorem lcm_assoc (m n k : ℕ) : lcm (lcm m n) k = lcm m (lcm n k) := dvd_antisymm (lcm_dvd (lcm_dvd (dvd_lcm_left m (lcm n k)) (dvd.trans (dvd_lcm_left n k) (dvd_lcm_right m (lcm n k)))) (dvd.trans (dvd_lcm_right n k) (dvd_lcm_right m (lcm n k)))) (lcm_dvd (dvd.trans (dvd_lcm_left m n) (dvd_lcm_left (lcm m n) k)) (lcm_dvd (dvd.trans (dvd_lcm_right m n) (dvd_lcm_left (lcm m n) k)) (dvd_lcm_right (lcm m n) k))) /- coprime -/ instance (m n : ℕ) : decidable (coprime m n) := by unfold coprime; apply_instance theorem coprime.gcd_eq_one {m n : ℕ} : coprime m n → gcd m n = 1 := id theorem coprime.symm {m n : ℕ} : coprime n m → coprime m n := (gcd_comm m n).trans theorem coprime_of_dvd {m n : ℕ} (H : ∀ k, 1 < k → k ∣ m → ¬ k ∣ n) : coprime m n := or.elim (eq_zero_or_pos (gcd m n)) (λg0, by rw [eq_zero_of_gcd_eq_zero_left g0, eq_zero_of_gcd_eq_zero_right g0] at H; exact false.elim (H 2 dec_trivial (dvd_zero _) (dvd_zero _))) (λ(g1 : 1 ≤ _), eq.symm $ (lt_or_eq_of_le g1).resolve_left $ λg2, H _ g2 (gcd_dvd_left _ _) (gcd_dvd_right _ _)) theorem coprime_of_dvd' {m n : ℕ} (H : ∀ k, k ∣ m → k ∣ n → k ∣ 1) : coprime m n := coprime_of_dvd $ λk kl km kn, not_le_of_gt kl $ le_of_dvd zero_lt_one (H k km kn) theorem coprime.dvd_of_dvd_mul_right {m n k : ℕ} (H1 : coprime k n) (H2 : k ∣ m * n) : k ∣ m := let t := dvd_gcd (dvd_mul_left k m) H2 in by rwa [gcd_mul_left, H1.gcd_eq_one, mul_one] at t theorem coprime.dvd_of_dvd_mul_left {m n k : ℕ} (H1 : coprime k m) (H2 : k ∣ m * n) : k ∣ n := by rw mul_comm at H2; exact H1.dvd_of_dvd_mul_right H2 theorem coprime.gcd_mul_left_cancel {k : ℕ} (m : ℕ) {n : ℕ} (H : coprime k n) : gcd (k * m) n = gcd m n := have H1 : coprime (gcd (k * m) n) k, by rw [coprime, gcd_assoc, H.symm.gcd_eq_one, gcd_one_right], dvd_antisymm (dvd_gcd (H1.dvd_of_dvd_mul_left (gcd_dvd_left _ _)) (gcd_dvd_right _ _)) (gcd_dvd_gcd_mul_left _ _ _) theorem coprime.gcd_mul_right_cancel (m : ℕ) {k n : ℕ} (H : coprime k n) : gcd (m * k) n = gcd m n := by rw [mul_comm m k, H.gcd_mul_left_cancel m] theorem coprime.gcd_mul_left_cancel_right {k m : ℕ} (n : ℕ) (H : coprime k m) : gcd m (k * n) = gcd m n := by rw [gcd_comm m n, gcd_comm m (k * n), H.gcd_mul_left_cancel n] theorem coprime.gcd_mul_right_cancel_right {k m : ℕ} (n : ℕ) (H : coprime k m) : gcd m (n * k) = gcd m n := by rw [mul_comm n k, H.gcd_mul_left_cancel_right n] theorem coprime_div_gcd_div_gcd {m n : ℕ} (H : 0 < gcd m n) : coprime (m / gcd m n) (n / gcd m n) := by delta coprime; rw [gcd_div (gcd_dvd_left m n) (gcd_dvd_right m n), nat.div_self H] theorem not_coprime_of_dvd_of_dvd {m n d : ℕ} (dgt1 : 1 < d) (Hm : d ∣ m) (Hn : d ∣ n) : ¬ coprime m n := λ (co : gcd m n = 1), not_lt_of_ge (le_of_dvd zero_lt_one $ by rw ←co; exact dvd_gcd Hm Hn) dgt1 theorem exists_coprime {m n : ℕ} (H : 0 < gcd m n) : ∃ m' n', coprime m' n' ∧ m = m' * gcd m n ∧ n = n' * gcd m n := ⟨_, _, coprime_div_gcd_div_gcd H, (nat.div_mul_cancel (gcd_dvd_left m n)).symm, (nat.div_mul_cancel (gcd_dvd_right m n)).symm⟩ theorem exists_coprime' {m n : ℕ} (H : 0 < gcd m n) : ∃ g m' n', 0 < g ∧ coprime m' n' ∧ m = m' * g ∧ n = n' * g := let ⟨m', n', h⟩ := exists_coprime H in ⟨_, m', n', H, h⟩ theorem coprime.mul {m n k : ℕ} (H1 : coprime m k) (H2 : coprime n k) : coprime (m * n) k := (H1.gcd_mul_left_cancel n).trans H2 theorem coprime.mul_right {k m n : ℕ} (H1 : coprime k m) (H2 : coprime k n) : coprime k (m * n) := (H1.symm.mul H2.symm).symm theorem coprime.coprime_dvd_left {m k n : ℕ} (H1 : m ∣ k) (H2 : coprime k n) : coprime m n := eq_one_of_dvd_one (by delta coprime at H2; rw ← H2; exact gcd_dvd_gcd_of_dvd_left _ H1) theorem coprime.coprime_dvd_right {m k n : ℕ} (H1 : n ∣ m) (H2 : coprime k m) : coprime k n := (H2.symm.coprime_dvd_left H1).symm theorem coprime.coprime_mul_left {k m n : ℕ} (H : coprime (k * m) n) : coprime m n := H.coprime_dvd_left (dvd_mul_left _ _) theorem coprime.coprime_mul_right {k m n : ℕ} (H : coprime (m * k) n) : coprime m n := H.coprime_dvd_left (dvd_mul_right _ _) theorem coprime.coprime_mul_left_right {k m n : ℕ} (H : coprime m (k * n)) : coprime m n := H.coprime_dvd_right (dvd_mul_left _ _) theorem coprime.coprime_mul_right_right {k m n : ℕ} (H : coprime m (n * k)) : coprime m n := H.coprime_dvd_right (dvd_mul_right _ _) lemma coprime_mul_iff_left {k m n : ℕ} : coprime (m * n) k ↔ coprime m k ∧ coprime n k := ⟨λ h, ⟨coprime.coprime_mul_right h, coprime.coprime_mul_left h⟩, λ ⟨h, _⟩, by rwa [coprime, coprime.gcd_mul_left_cancel n h]⟩ lemma coprime_mul_iff_right {k m n : ℕ} : coprime k (m * n) ↔ coprime k m ∧ coprime k n := by { repeat { rw [coprime, nat.gcd_comm k] }, exact coprime_mul_iff_left } lemma coprime.gcd_left (k : ℕ) {m n : ℕ} (hmn : coprime m n) : coprime (gcd k m) n := hmn.coprime_dvd_left $ gcd_dvd_right k m lemma coprime.gcd_right (k : ℕ) {m n : ℕ} (hmn : coprime m n) : coprime m (gcd k n) := hmn.coprime_dvd_right $ gcd_dvd_right k n lemma coprime.gcd_both (k l : ℕ) {m n : ℕ} (hmn : coprime m n) : coprime (gcd k m) (gcd l n) := (hmn.gcd_left k).gcd_right l lemma coprime.mul_dvd_of_dvd_of_dvd {a n m : ℕ} (hmn : coprime m n) (hm : m ∣ a) (hn : n ∣ a) : m * n ∣ a := let ⟨k, hk⟩ := hm in hk.symm ▸ mul_dvd_mul_left _ (hmn.symm.dvd_of_dvd_mul_left (hk ▸ hn)) theorem coprime_one_left : ∀ n, coprime 1 n := gcd_one_left theorem coprime_one_right : ∀ n, coprime n 1 := gcd_one_right theorem coprime.pow_left {m k : ℕ} (n : ℕ) (H1 : coprime m k) : coprime (m ^ n) k := nat.rec_on n (coprime_one_left _) (λn IH, IH.mul H1) theorem coprime.pow_right {m k : ℕ} (n : ℕ) (H1 : coprime k m) : coprime k (m ^ n) := (H1.symm.pow_left n).symm theorem coprime.pow {k l : ℕ} (m n : ℕ) (H1 : coprime k l) : coprime (k ^ m) (l ^ n) := (H1.pow_left _).pow_right _ theorem coprime.eq_one_of_dvd {k m : ℕ} (H : coprime k m) (d : k ∣ m) : k = 1 := by rw [← H.gcd_eq_one, gcd_eq_left d] @[simp] theorem coprime_zero_left (n : ℕ) : coprime 0 n ↔ n = 1 := by simp [coprime] @[simp] theorem coprime_zero_right (n : ℕ) : coprime n 0 ↔ n = 1 := by simp [coprime] @[simp] theorem coprime_one_left_iff (n : ℕ) : coprime 1 n ↔ true := by simp [coprime] @[simp] theorem coprime_one_right_iff (n : ℕ) : coprime n 1 ↔ true := by simp [coprime] @[simp] theorem coprime_self (n : ℕ) : coprime n n ↔ n = 1 := by simp [coprime] /-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`. -/ def prod_dvd_and_dvd_of_dvd_prod {m n k : ℕ} (H : k ∣ m * n) : { d : {m' // m' ∣ m} × {n' // n' ∣ n} // k = d.1 * d.2 } := begin cases h0 : (gcd k m), case nat.zero { have : k = 0 := eq_zero_of_gcd_eq_zero_left h0, subst this, have : m = 0 := eq_zero_of_gcd_eq_zero_right h0, subst this, exact ⟨⟨⟨0, dvd_refl 0⟩, ⟨n, dvd_refl n⟩⟩, (zero_mul n).symm⟩ }, case nat.succ : tmp hpos { replace hpos : 0 < gcd k m := hpos.symm ▸ nat.zero_lt_succ _; clear tmp, have hd : gcd k m * (k / gcd k m) = k := (nat.mul_div_cancel' (gcd_dvd_left k m)), refine ⟨⟨⟨gcd k m, gcd_dvd_right k m⟩, ⟨k / gcd k m, _⟩⟩, hd.symm⟩, apply dvd_of_mul_dvd_mul_left hpos, rw [hd, ← gcd_mul_right], exact dvd_gcd (dvd_mul_right _ _) H } end theorem gcd_mul_dvd_mul_gcd (k m n : ℕ) : gcd k (m * n) ∣ gcd k m * gcd k n := begin rcases (prod_dvd_and_dvd_of_dvd_prod $ gcd_dvd_right k (m * n)) with ⟨⟨⟨m', hm'⟩, ⟨n', hn'⟩⟩, h⟩, replace h : gcd k (m * n) = m' * n' := h, rw h, have hm'n' : m' * n' ∣ k := h ▸ gcd_dvd_left _ _, apply mul_dvd_mul, { have hm'k : m' ∣ k := dvd_trans (dvd_mul_right m' n') hm'n', exact dvd_gcd hm'k hm' }, { have hn'k : n' ∣ k := dvd_trans (dvd_mul_left n' m') hm'n', exact dvd_gcd hn'k hn' } end theorem coprime.gcd_mul (k : ℕ) {m n : ℕ} (h : coprime m n) : gcd k (m * n) = gcd k m * gcd k n := dvd_antisymm (gcd_mul_dvd_mul_gcd k m n) ((h.gcd_both k k).mul_dvd_of_dvd_of_dvd (gcd_dvd_gcd_mul_right_right _ _ _) (gcd_dvd_gcd_mul_left_right _ _ _)) theorem pow_dvd_pow_iff {a b n : ℕ} (n0 : 0 < n) : a ^ n ∣ b ^ n ↔ a ∣ b := begin refine ⟨λ h, _, λ h, pow_dvd_pow_of_dvd h _⟩, cases eq_zero_or_pos (gcd a b) with g0 g0, { simp [eq_zero_of_gcd_eq_zero_right g0] }, rcases exists_coprime' g0 with ⟨g, a', b', g0', co, rfl, rfl⟩, rw [mul_pow, mul_pow] at h, replace h := dvd_of_mul_dvd_mul_right (pos_pow_of_pos _ g0') h, have := pow_dvd_pow a' n0, rw [pow_one, (co.pow n n).eq_one_of_dvd h] at this, simp [eq_one_of_dvd_one this] end end nat
f02c8470709e71bab4fedeb4816d724692a5c0af
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/set/disjointed.lean
6edee41927d89d0ff7f4fb3e441279f8bb74d644
[]
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
4,049
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 Disjointed sets -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.set.lattice import Mathlib.tactic.wlog import Mathlib.PostPort universes u_1 u v namespace Mathlib /-- A relation `p` holds pairwise if `p i j` for all `i ≠ j`. -/ def pairwise {α : Type u_1} (p : α → α → Prop) := ∀ (i j : α), i ≠ j → p i j theorem set.pairwise_on_univ {α : Type u} {r : α → α → Prop} : set.pairwise_on set.univ r ↔ pairwise r := sorry theorem set.pairwise_on.on_injective {α : Type u} {β : Type v} {s : set α} {r : α → α → Prop} (hs : set.pairwise_on s r) {f : β → α} (hf : function.injective f) (hfs : ∀ (x : β), f x ∈ s) : pairwise (r on f) := fun (i j : β) (hij : i ≠ j) => hs (f i) (hfs i) (f j) (hfs j) (function.injective.ne hf hij) theorem pairwise.mono {α : Type u} {p : α → α → Prop} {q : α → α → Prop} (h : ∀ {i j : α}, p i j → q i j) (hp : pairwise p) : pairwise q := fun (i j : α) (hij : i ≠ j) => h (hp i j hij) theorem pairwise_on_bool {α : Type u} {r : α → α → Prop} (hr : symmetric r) {a : α} {b : α} : pairwise (r on fun (c : Bool) => cond c a b) ↔ r a b := sorry theorem pairwise_disjoint_on_bool {α : Type u} [semilattice_inf_bot α] {a : α} {b : α} : pairwise (disjoint on fun (c : Bool) => cond c a b) ↔ disjoint a b := pairwise_on_bool disjoint.symm theorem pairwise.pairwise_on {α : Type u} {p : α → α → Prop} (h : pairwise p) (s : set α) : set.pairwise_on s p := fun (x : α) (hx : x ∈ s) (y : α) (hy : y ∈ s) => h x y theorem pairwise_disjoint_fiber {α : Type u} {β : Type v} (f : α → β) : pairwise (disjoint on fun (y : β) => f ⁻¹' singleton y) := iff.mp set.pairwise_on_univ (set.pairwise_on_disjoint_fiber f set.univ) namespace set /-- If `f : ℕ → set α` is a sequence of sets, then `disjointed f` is the sequence formed with each set subtracted from the later ones in the sequence, to form a disjoint sequence. -/ def disjointed {α : Type u} (f : ℕ → set α) (n : ℕ) : set α := f n ∩ Inter fun (i : ℕ) => Inter fun (H : i < n) => f iᶜ theorem disjoint_disjointed {α : Type u} {f : ℕ → set α} : pairwise (disjoint on disjointed f) := sorry theorem disjoint_disjointed' {α : Type u} {f : ℕ → set α} (i : ℕ) (j : ℕ) : i ≠ j → disjointed f i ∩ disjointed f j = ∅ := fun (hij : i ≠ j) => iff.mp disjoint_iff (disjoint_disjointed i j hij) theorem disjointed_subset {α : Type u} {f : ℕ → set α} {n : ℕ} : disjointed f n ⊆ f n := inter_subset_left (f n) (Inter fun (i : ℕ) => Inter fun (H : i < n) => f iᶜ) theorem Union_lt_succ {α : Type u} {f : ℕ → set α} {n : ℕ} : (Union fun (i : ℕ) => Union fun (H : i < Nat.succ n) => f i) = f n ∪ Union fun (i : ℕ) => Union fun (H : i < n) => f i := sorry theorem Inter_lt_succ {α : Type u} {f : ℕ → set α} {n : ℕ} : (Inter fun (i : ℕ) => Inter fun (H : i < Nat.succ n) => f i) = f n ∩ Inter fun (i : ℕ) => Inter fun (H : i < n) => f i := sorry theorem subset_Union_disjointed {α : Type u} {f : ℕ → set α} {n : ℕ} : f n ⊆ Union fun (i : ℕ) => Union fun (H : i < Nat.succ n) => disjointed f i := sorry theorem Union_disjointed {α : Type u} {f : ℕ → set α} : (Union fun (n : ℕ) => disjointed f n) = Union fun (n : ℕ) => f n := sorry theorem disjointed_induct {α : Type u} {f : ℕ → set α} {n : ℕ} {p : set α → Prop} (h₁ : p (f n)) (h₂ : ∀ (t : set α) (i : ℕ), p t → p (t \ f i)) : p (disjointed f n) := sorry theorem disjointed_of_mono {α : Type u} {f : ℕ → set α} {n : ℕ} (hf : monotone f) : disjointed f (n + 1) = f (n + 1) \ f n := sorry theorem Union_disjointed_of_mono {α : Type u} {f : ℕ → set α} (hf : monotone f) (n : ℕ) : (Union fun (i : ℕ) => Union fun (H : i < Nat.succ n) => disjointed f i) = f n := sorry
10a6dac123f52c6700f4e957ba16be75d9de9fd4
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/stage0/src/Init/Data/RBMap/BasicAux.lean
920a1258f9b873b7f15402eefea2d384a0b9121f
[ "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
782
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.Data.RBMap.Basic import Init.Util universes u v w w' namespace RBMap variables {α : Type u} {β : Type v} {lt : α → α → Bool} @[inline] def min! [Inhabited α] [Inhabited β] (t : RBMap α β lt) : α × β := match t.min with | some p => p | none => panic! "map is empty" @[inline] def max! [Inhabited α] [Inhabited β] (t : RBMap α β lt) : α × β := match t.max with | some p => p | none => panic! "map is empty" @[inline] def find! [Inhabited β] (t : RBMap α β lt) (k : α) : β := match t.find? k with | some b => b | none => panic! "key is not in the map" end RBMap
8b91a6841065407288049c68f515a44278ff16cd
36c7a18fd72e5b57229bd8ba36493daf536a19ce
/tests/lean/run/blast17.lean
fc9325f9da37ca9eaff3dcb647d81ae6a2418ab0
[ "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
88
lean
example (p q r : Prop) (a b : nat) : true → a = a → q → q → p → p := by blast
d9e975c347541ca0ea6252255514d8890eed69e2
32da3d0f92cab08875472ef6cacc1931c2b3eafa
/src/analysis/special_functions/trigonometric.lean
98e03e0e8880c1994b6c635f6cd24ced4ee8b4d7
[ "Apache-2.0" ]
permissive
karthiknadig/mathlib
b6073c3748860bfc9a3e55da86afcddba62dc913
33a86cfff12d7f200d0010cd03b95e9b69a6c1a5
refs/heads/master
1,676,389,371,851
1,610,061,127,000
1,610,061,127,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
118,800
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import analysis.special_functions.exp_log import data.set.intervals.infinite import algebra.quadratic_discriminant import ring_theory.polynomial.chebyshev.defs /-! # Trigonometric functions ## Main definitions This file contains the following definitions: * π, arcsin, arccos, arctan * argument of a complex number * logarithm on complex numbers ## Main statements Many basic inequalities on trigonometric functions are established. The continuity and differentiability of the usual trigonometric functions are proved, and their derivatives are computed. * `polynomial.chebyshev₁_complex_cos`: the `n`-th Chebyshev polynomial evaluates on `complex.cos θ` to the value `n * complex.cos θ`. ## Tags log, sin, cos, tan, arcsin, arccos, arctan, angle, argument -/ noncomputable theory open_locale classical topological_space filter open set filter namespace complex /-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/ lemma has_deriv_at_sin (x : ℂ) : has_deriv_at sin (cos x) x := begin simp only [cos, div_eq_mul_inv], convert ((((has_deriv_at_id x).neg.mul_const I).cexp.sub ((has_deriv_at_id x).mul_const I).cexp).mul_const I).mul_const (2:ℂ)⁻¹, simp only [function.comp, id], rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc, I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm] end lemma times_cont_diff_sin {n} : times_cont_diff ℂ n sin := (((times_cont_diff_neg.mul times_cont_diff_const).cexp.sub (times_cont_diff_id.mul times_cont_diff_const).cexp).mul times_cont_diff_const).div_const lemma differentiable_sin : differentiable ℂ sin := λx, (has_deriv_at_sin x).differentiable_at lemma differentiable_at_sin {x : ℂ} : differentiable_at ℂ sin x := differentiable_sin x @[simp] lemma deriv_sin : deriv sin = cos := funext $ λ x, (has_deriv_at_sin x).deriv lemma continuous_sin : continuous sin := differentiable_sin.continuous lemma continuous_on_sin {s : set ℂ} : continuous_on sin s := continuous_sin.continuous_on lemma measurable_sin : measurable sin := continuous_sin.measurable /-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/ lemma has_deriv_at_cos (x : ℂ) : has_deriv_at cos (-sin x) x := begin simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul], convert (((has_deriv_at_id x).mul_const I).cexp.add ((has_deriv_at_id x).neg.mul_const I).cexp).mul_const (2:ℂ)⁻¹, simp only [function.comp, id], ring end lemma times_cont_diff_cos {n} : times_cont_diff ℂ n cos := ((times_cont_diff_id.mul times_cont_diff_const).cexp.add (times_cont_diff_neg.mul times_cont_diff_const).cexp).div_const lemma differentiable_cos : differentiable ℂ cos := λx, (has_deriv_at_cos x).differentiable_at lemma differentiable_at_cos {x : ℂ} : differentiable_at ℂ cos x := differentiable_cos x lemma deriv_cos {x : ℂ} : deriv cos x = -sin x := (has_deriv_at_cos x).deriv @[simp] lemma deriv_cos' : deriv cos = (λ x, -sin x) := funext $ λ x, deriv_cos lemma continuous_cos : continuous cos := differentiable_cos.continuous lemma continuous_on_cos {s : set ℂ} : continuous_on cos s := continuous_cos.continuous_on lemma measurable_cos : measurable cos := continuous_cos.measurable /-- The complex hyperbolic sine function is everywhere differentiable, with the derivative `cosh x`. -/ lemma has_deriv_at_sinh (x : ℂ) : has_deriv_at sinh (cosh x) x := begin simp only [cosh, div_eq_mul_inv], convert ((has_deriv_at_exp x).sub (has_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹, rw [id, mul_neg_one, sub_eq_add_neg, neg_neg] end lemma times_cont_diff_sinh {n} : times_cont_diff ℂ n sinh := (times_cont_diff_exp.sub times_cont_diff_neg.cexp).div_const lemma differentiable_sinh : differentiable ℂ sinh := λx, (has_deriv_at_sinh x).differentiable_at lemma differentiable_at_sinh {x : ℂ} : differentiable_at ℂ sinh x := differentiable_sinh x @[simp] lemma deriv_sinh : deriv sinh = cosh := funext $ λ x, (has_deriv_at_sinh x).deriv lemma continuous_sinh : continuous sinh := differentiable_sinh.continuous lemma measurable_sinh : measurable sinh := continuous_sinh.measurable /-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative `sinh x`. -/ lemma has_deriv_at_cosh (x : ℂ) : has_deriv_at cosh (sinh x) x := begin simp only [sinh, div_eq_mul_inv], convert ((has_deriv_at_exp x).add (has_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹, rw [id, mul_neg_one, sub_eq_add_neg] end lemma times_cont_diff_cosh {n} : times_cont_diff ℂ n cosh := (times_cont_diff_exp.add times_cont_diff_neg.cexp).div_const lemma differentiable_cosh : differentiable ℂ cosh := λx, (has_deriv_at_cosh x).differentiable_at lemma differentiable_at_cosh {x : ℂ} : differentiable_at ℂ cos x := differentiable_cos x @[simp] lemma deriv_cosh : deriv cosh = sinh := funext $ λ x, (has_deriv_at_cosh x).deriv lemma continuous_cosh : continuous cosh := differentiable_cosh.continuous lemma measurable_cosh : measurable cosh := continuous_cosh.measurable end complex section /-! ### Simp lemmas for derivatives of `λ x, complex.cos (f x)` etc., `f : ℂ → ℂ` -/ variables {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ} /-! #### `complex.cos` -/ lemma measurable.ccos {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) : measurable (λ x, complex.cos (f x)) := complex.measurable_cos.comp hf lemma has_deriv_at.ccos (hf : has_deriv_at f f' x) : has_deriv_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') x := (complex.has_deriv_at_cos (f x)).comp x hf lemma has_deriv_within_at.ccos (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') s x := (complex.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf lemma deriv_within_ccos (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : deriv_within (λx, complex.cos (f x)) s x = - complex.sin (f x) * (deriv_within f s x) := hf.has_deriv_within_at.ccos.deriv_within hxs @[simp] lemma deriv_ccos (hc : differentiable_at ℂ f x) : deriv (λx, complex.cos (f x)) x = - complex.sin (f x) * (deriv f x) := hc.has_deriv_at.ccos.deriv /-! #### `complex.sin` -/ lemma measurable.csin {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) : measurable (λ x, complex.sin (f x)) := complex.measurable_sin.comp hf lemma has_deriv_at.csin (hf : has_deriv_at f f' x) : has_deriv_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') x := (complex.has_deriv_at_sin (f x)).comp x hf lemma has_deriv_within_at.csin (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') s x := (complex.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf lemma deriv_within_csin (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : deriv_within (λx, complex.sin (f x)) s x = complex.cos (f x) * (deriv_within f s x) := hf.has_deriv_within_at.csin.deriv_within hxs @[simp] lemma deriv_csin (hc : differentiable_at ℂ f x) : deriv (λx, complex.sin (f x)) x = complex.cos (f x) * (deriv f x) := hc.has_deriv_at.csin.deriv /-! #### `complex.cosh` -/ lemma measurable.ccosh {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) : measurable (λ x, complex.cosh (f x)) := complex.measurable_cosh.comp hf lemma has_deriv_at.ccosh (hf : has_deriv_at f f' x) : has_deriv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') x := (complex.has_deriv_at_cosh (f x)).comp x hf lemma has_deriv_within_at.ccosh (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') s x := (complex.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf lemma deriv_within_ccosh (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : deriv_within (λx, complex.cosh (f x)) s x = complex.sinh (f x) * (deriv_within f s x) := hf.has_deriv_within_at.ccosh.deriv_within hxs @[simp] lemma deriv_ccosh (hc : differentiable_at ℂ f x) : deriv (λx, complex.cosh (f x)) x = complex.sinh (f x) * (deriv f x) := hc.has_deriv_at.ccosh.deriv /-! #### `complex.sinh` -/ lemma measurable.csinh {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) : measurable (λ x, complex.sinh (f x)) := complex.measurable_sinh.comp hf lemma has_deriv_at.csinh (hf : has_deriv_at f f' x) : has_deriv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') x := (complex.has_deriv_at_sinh (f x)).comp x hf lemma has_deriv_within_at.csinh (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') s x := (complex.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf lemma deriv_within_csinh (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : deriv_within (λx, complex.sinh (f x)) s x = complex.cosh (f x) * (deriv_within f s x) := hf.has_deriv_within_at.csinh.deriv_within hxs @[simp] lemma deriv_csinh (hc : differentiable_at ℂ f x) : deriv (λx, complex.sinh (f x)) x = complex.cosh (f x) * (deriv f x) := hc.has_deriv_at.csinh.deriv end section /-! ### Simp lemmas for derivatives of `λ x, complex.cos (f x)` etc., `f : E → ℂ` -/ variables {E : Type*} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {f' : E →L[ℂ] ℂ} {x : E} {s : set E} /-! #### `complex.cos` -/ lemma has_fderiv_at.ccos (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, complex.cos (f x)) (- complex.sin (f x) • f') x := (complex.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.ccos (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, complex.cos (f x)) (- complex.sin (f x) • f') s x := (complex.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.ccos (hf : differentiable_within_at ℂ f s x) : differentiable_within_at ℂ (λ x, complex.cos (f x)) s x := hf.has_fderiv_within_at.ccos.differentiable_within_at @[simp] lemma differentiable_at.ccos (hc : differentiable_at ℂ f x) : differentiable_at ℂ (λx, complex.cos (f x)) x := hc.has_fderiv_at.ccos.differentiable_at lemma differentiable_on.ccos (hc : differentiable_on ℂ f s) : differentiable_on ℂ (λx, complex.cos (f x)) s := λx h, (hc x h).ccos @[simp] lemma differentiable.ccos (hc : differentiable ℂ f) : differentiable ℂ (λx, complex.cos (f x)) := λx, (hc x).ccos lemma fderiv_within_ccos (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : fderiv_within ℂ (λx, complex.cos (f x)) s x = - complex.sin (f x) • (fderiv_within ℂ f s x) := hf.has_fderiv_within_at.ccos.fderiv_within hxs @[simp] lemma fderiv_ccos (hc : differentiable_at ℂ f x) : fderiv ℂ (λx, complex.cos (f x)) x = - complex.sin (f x) • (fderiv ℂ f x) := hc.has_fderiv_at.ccos.fderiv lemma times_cont_diff.ccos {n} (h : times_cont_diff ℂ n f) : times_cont_diff ℂ n (λ x, complex.cos (f x)) := complex.times_cont_diff_cos.comp h lemma times_cont_diff_at.ccos {n} (hf : times_cont_diff_at ℂ n f x) : times_cont_diff_at ℂ n (λ x, complex.cos (f x)) x := complex.times_cont_diff_cos.times_cont_diff_at.comp x hf lemma times_cont_diff_on.ccos {n} (hf : times_cont_diff_on ℂ n f s) : times_cont_diff_on ℂ n (λ x, complex.cos (f x)) s := complex.times_cont_diff_cos.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.ccos {n} (hf : times_cont_diff_within_at ℂ n f s x) : times_cont_diff_within_at ℂ n (λ x, complex.cos (f x)) s x := complex.times_cont_diff_cos.times_cont_diff_at.comp_times_cont_diff_within_at x hf /-! #### `complex.sin` -/ lemma has_fderiv_at.csin (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, complex.sin (f x)) (complex.cos (f x) • f') x := (complex.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.csin (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, complex.sin (f x)) (complex.cos (f x) • f') s x := (complex.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.csin (hf : differentiable_within_at ℂ f s x) : differentiable_within_at ℂ (λ x, complex.sin (f x)) s x := hf.has_fderiv_within_at.csin.differentiable_within_at @[simp] lemma differentiable_at.csin (hc : differentiable_at ℂ f x) : differentiable_at ℂ (λx, complex.sin (f x)) x := hc.has_fderiv_at.csin.differentiable_at lemma differentiable_on.csin (hc : differentiable_on ℂ f s) : differentiable_on ℂ (λx, complex.sin (f x)) s := λx h, (hc x h).csin @[simp] lemma differentiable.csin (hc : differentiable ℂ f) : differentiable ℂ (λx, complex.sin (f x)) := λx, (hc x).csin lemma fderiv_within_csin (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : fderiv_within ℂ (λx, complex.sin (f x)) s x = complex.cos (f x) • (fderiv_within ℂ f s x) := hf.has_fderiv_within_at.csin.fderiv_within hxs @[simp] lemma fderiv_csin (hc : differentiable_at ℂ f x) : fderiv ℂ (λx, complex.sin (f x)) x = complex.cos (f x) • (fderiv ℂ f x) := hc.has_fderiv_at.csin.fderiv lemma times_cont_diff.csin {n} (h : times_cont_diff ℂ n f) : times_cont_diff ℂ n (λ x, complex.sin (f x)) := complex.times_cont_diff_sin.comp h lemma times_cont_diff_at.csin {n} (hf : times_cont_diff_at ℂ n f x) : times_cont_diff_at ℂ n (λ x, complex.sin (f x)) x := complex.times_cont_diff_sin.times_cont_diff_at.comp x hf lemma times_cont_diff_on.csin {n} (hf : times_cont_diff_on ℂ n f s) : times_cont_diff_on ℂ n (λ x, complex.sin (f x)) s := complex.times_cont_diff_sin.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.csin {n} (hf : times_cont_diff_within_at ℂ n f s x) : times_cont_diff_within_at ℂ n (λ x, complex.sin (f x)) s x := complex.times_cont_diff_sin.times_cont_diff_at.comp_times_cont_diff_within_at x hf /-! #### `complex.cosh` -/ lemma has_fderiv_at.ccosh (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) • f') x := (complex.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.ccosh (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, complex.cosh (f x)) (complex.sinh (f x) • f') s x := (complex.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.ccosh (hf : differentiable_within_at ℂ f s x) : differentiable_within_at ℂ (λ x, complex.cosh (f x)) s x := hf.has_fderiv_within_at.ccosh.differentiable_within_at @[simp] lemma differentiable_at.ccosh (hc : differentiable_at ℂ f x) : differentiable_at ℂ (λx, complex.cosh (f x)) x := hc.has_fderiv_at.ccosh.differentiable_at lemma differentiable_on.ccosh (hc : differentiable_on ℂ f s) : differentiable_on ℂ (λx, complex.cosh (f x)) s := λx h, (hc x h).ccosh @[simp] lemma differentiable.ccosh (hc : differentiable ℂ f) : differentiable ℂ (λx, complex.cosh (f x)) := λx, (hc x).ccosh lemma fderiv_within_ccosh (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : fderiv_within ℂ (λx, complex.cosh (f x)) s x = complex.sinh (f x) • (fderiv_within ℂ f s x) := hf.has_fderiv_within_at.ccosh.fderiv_within hxs @[simp] lemma fderiv_ccosh (hc : differentiable_at ℂ f x) : fderiv ℂ (λx, complex.cosh (f x)) x = complex.sinh (f x) • (fderiv ℂ f x) := hc.has_fderiv_at.ccosh.fderiv lemma times_cont_diff.ccosh {n} (h : times_cont_diff ℂ n f) : times_cont_diff ℂ n (λ x, complex.cosh (f x)) := complex.times_cont_diff_cosh.comp h lemma times_cont_diff_at.ccosh {n} (hf : times_cont_diff_at ℂ n f x) : times_cont_diff_at ℂ n (λ x, complex.cosh (f x)) x := complex.times_cont_diff_cosh.times_cont_diff_at.comp x hf lemma times_cont_diff_on.ccosh {n} (hf : times_cont_diff_on ℂ n f s) : times_cont_diff_on ℂ n (λ x, complex.cosh (f x)) s := complex.times_cont_diff_cosh.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.ccosh {n} (hf : times_cont_diff_within_at ℂ n f s x) : times_cont_diff_within_at ℂ n (λ x, complex.cosh (f x)) s x := complex.times_cont_diff_cosh.times_cont_diff_at.comp_times_cont_diff_within_at x hf /-! #### `complex.sinh` -/ lemma has_fderiv_at.csinh (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) • f') x := (complex.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.csinh (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, complex.sinh (f x)) (complex.cosh (f x) • f') s x := (complex.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.csinh (hf : differentiable_within_at ℂ f s x) : differentiable_within_at ℂ (λ x, complex.sinh (f x)) s x := hf.has_fderiv_within_at.csinh.differentiable_within_at @[simp] lemma differentiable_at.csinh (hc : differentiable_at ℂ f x) : differentiable_at ℂ (λx, complex.sinh (f x)) x := hc.has_fderiv_at.csinh.differentiable_at lemma differentiable_on.csinh (hc : differentiable_on ℂ f s) : differentiable_on ℂ (λx, complex.sinh (f x)) s := λx h, (hc x h).csinh @[simp] lemma differentiable.csinh (hc : differentiable ℂ f) : differentiable ℂ (λx, complex.sinh (f x)) := λx, (hc x).csinh lemma fderiv_within_csinh (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : fderiv_within ℂ (λx, complex.sinh (f x)) s x = complex.cosh (f x) • (fderiv_within ℂ f s x) := hf.has_fderiv_within_at.csinh.fderiv_within hxs @[simp] lemma fderiv_csinh (hc : differentiable_at ℂ f x) : fderiv ℂ (λx, complex.sinh (f x)) x = complex.cosh (f x) • (fderiv ℂ f x) := hc.has_fderiv_at.csinh.fderiv lemma times_cont_diff.csinh {n} (h : times_cont_diff ℂ n f) : times_cont_diff ℂ n (λ x, complex.sinh (f x)) := complex.times_cont_diff_sinh.comp h lemma times_cont_diff_at.csinh {n} (hf : times_cont_diff_at ℂ n f x) : times_cont_diff_at ℂ n (λ x, complex.sinh (f x)) x := complex.times_cont_diff_sinh.times_cont_diff_at.comp x hf lemma times_cont_diff_on.csinh {n} (hf : times_cont_diff_on ℂ n f s) : times_cont_diff_on ℂ n (λ x, complex.sinh (f x)) s := complex.times_cont_diff_sinh.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.csinh {n} (hf : times_cont_diff_within_at ℂ n f s x) : times_cont_diff_within_at ℂ n (λ x, complex.sinh (f x)) s x := complex.times_cont_diff_sinh.times_cont_diff_at.comp_times_cont_diff_within_at x hf end namespace real variables {x y z : ℝ} lemma has_deriv_at_sin (x : ℝ) : has_deriv_at sin (cos x) x := (complex.has_deriv_at_sin x).real_of_complex lemma times_cont_diff_sin {n} : times_cont_diff ℝ n sin := complex.times_cont_diff_sin.real_of_complex lemma differentiable_sin : differentiable ℝ sin := λx, (has_deriv_at_sin x).differentiable_at lemma differentiable_at_sin : differentiable_at ℝ sin x := differentiable_sin x @[simp] lemma deriv_sin : deriv sin = cos := funext $ λ x, (has_deriv_at_sin x).deriv lemma continuous_sin : continuous sin := differentiable_sin.continuous lemma measurable_sin : measurable sin := continuous_sin.measurable lemma has_deriv_at_cos (x : ℝ) : has_deriv_at cos (-sin x) x := (complex.has_deriv_at_cos x).real_of_complex lemma times_cont_diff_cos {n} : times_cont_diff ℝ n cos := complex.times_cont_diff_cos.real_of_complex lemma differentiable_cos : differentiable ℝ cos := λx, (has_deriv_at_cos x).differentiable_at lemma differentiable_at_cos : differentiable_at ℝ cos x := differentiable_cos x lemma deriv_cos : deriv cos x = - sin x := (has_deriv_at_cos x).deriv @[simp] lemma deriv_cos' : deriv cos = (λ x, - sin x) := funext $ λ _, deriv_cos lemma continuous_cos : continuous cos := differentiable_cos.continuous lemma continuous_on_cos {s} : continuous_on cos s := continuous_cos.continuous_on lemma measurable_cos : measurable cos := continuous_cos.measurable lemma has_deriv_at_sinh (x : ℝ) : has_deriv_at sinh (cosh x) x := (complex.has_deriv_at_sinh x).real_of_complex lemma times_cont_diff_sinh {n} : times_cont_diff ℝ n sinh := complex.times_cont_diff_sinh.real_of_complex lemma differentiable_sinh : differentiable ℝ sinh := λx, (has_deriv_at_sinh x).differentiable_at lemma differentiable_at_sinh : differentiable_at ℝ sinh x := differentiable_sinh x @[simp] lemma deriv_sinh : deriv sinh = cosh := funext $ λ x, (has_deriv_at_sinh x).deriv lemma continuous_sinh : continuous sinh := differentiable_sinh.continuous lemma measurable_sinh : measurable sinh := continuous_sinh.measurable lemma has_deriv_at_cosh (x : ℝ) : has_deriv_at cosh (sinh x) x := (complex.has_deriv_at_cosh x).real_of_complex lemma times_cont_diff_cosh {n} : times_cont_diff ℝ n cosh := complex.times_cont_diff_cosh.real_of_complex lemma differentiable_cosh : differentiable ℝ cosh := λx, (has_deriv_at_cosh x).differentiable_at lemma differentiable_at_cosh : differentiable_at ℝ cosh x := differentiable_cosh x @[simp] lemma deriv_cosh : deriv cosh = sinh := funext $ λ x, (has_deriv_at_cosh x).deriv lemma continuous_cosh : continuous cosh := differentiable_cosh.continuous lemma measurable_cosh : measurable cosh := continuous_cosh.measurable /-- `sinh` is strictly monotone. -/ lemma sinh_strict_mono : strict_mono sinh := strict_mono_of_deriv_pos differentiable_sinh (by { rw [real.deriv_sinh], exact cosh_pos }) end real section /-! ### Simp lemmas for derivatives of `λ x, real.cos (f x)` etc., `f : ℝ → ℝ` -/ variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ} /-! #### `real.cos` -/ lemma measurable.cos {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) : measurable (λ x, real.cos (f x)) := real.measurable_cos.comp hf lemma has_deriv_at.cos (hf : has_deriv_at f f' x) : has_deriv_at (λ x, real.cos (f x)) (- real.sin (f x) * f') x := (real.has_deriv_at_cos (f x)).comp x hf lemma has_deriv_within_at.cos (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, real.cos (f x)) (- real.sin (f x) * f') s x := (real.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf lemma deriv_within_cos (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λx, real.cos (f x)) s x = - real.sin (f x) * (deriv_within f s x) := hf.has_deriv_within_at.cos.deriv_within hxs @[simp] lemma deriv_cos (hc : differentiable_at ℝ f x) : deriv (λx, real.cos (f x)) x = - real.sin (f x) * (deriv f x) := hc.has_deriv_at.cos.deriv /-! #### `real.sin` -/ lemma measurable.sin {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) : measurable (λ x, real.sin (f x)) := real.measurable_sin.comp hf lemma has_deriv_at.sin (hf : has_deriv_at f f' x) : has_deriv_at (λ x, real.sin (f x)) (real.cos (f x) * f') x := (real.has_deriv_at_sin (f x)).comp x hf lemma has_deriv_within_at.sin (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, real.sin (f x)) (real.cos (f x) * f') s x := (real.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf lemma deriv_within_sin (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λx, real.sin (f x)) s x = real.cos (f x) * (deriv_within f s x) := hf.has_deriv_within_at.sin.deriv_within hxs @[simp] lemma deriv_sin (hc : differentiable_at ℝ f x) : deriv (λx, real.sin (f x)) x = real.cos (f x) * (deriv f x) := hc.has_deriv_at.sin.deriv /-! #### `real.cosh` -/ lemma measurable.cosh {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) : measurable (λ x, real.cosh (f x)) := real.measurable_cosh.comp hf lemma has_deriv_at.cosh (hf : has_deriv_at f f' x) : has_deriv_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') x := (real.has_deriv_at_cosh (f x)).comp x hf lemma has_deriv_within_at.cosh (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') s x := (real.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf lemma deriv_within_cosh (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λx, real.cosh (f x)) s x = real.sinh (f x) * (deriv_within f s x) := hf.has_deriv_within_at.cosh.deriv_within hxs @[simp] lemma deriv_cosh (hc : differentiable_at ℝ f x) : deriv (λx, real.cosh (f x)) x = real.sinh (f x) * (deriv f x) := hc.has_deriv_at.cosh.deriv /-! #### `real.sinh` -/ lemma measurable.sinh {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) : measurable (λ x, real.sinh (f x)) := real.measurable_sinh.comp hf lemma has_deriv_at.sinh (hf : has_deriv_at f f' x) : has_deriv_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') x := (real.has_deriv_at_sinh (f x)).comp x hf lemma has_deriv_within_at.sinh (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') s x := (real.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf lemma deriv_within_sinh (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λx, real.sinh (f x)) s x = real.cosh (f x) * (deriv_within f s x) := hf.has_deriv_within_at.sinh.deriv_within hxs @[simp] lemma deriv_sinh (hc : differentiable_at ℝ f x) : deriv (λx, real.sinh (f x)) x = real.cosh (f x) * (deriv f x) := hc.has_deriv_at.sinh.deriv end section /-! ### Simp lemmas for derivatives of `λ x, real.cos (f x)` etc., `f : E → ℝ` -/ variables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ} {x : E} {s : set E} /-! #### `real.cos` -/ lemma has_fderiv_at.cos (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, real.cos (f x)) (- real.sin (f x) • f') x := (real.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.cos (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, real.cos (f x)) (- real.sin (f x) • f') s x := (real.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.cos (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.cos (f x)) s x := hf.has_fderiv_within_at.cos.differentiable_within_at @[simp] lemma differentiable_at.cos (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λx, real.cos (f x)) x := hc.has_fderiv_at.cos.differentiable_at lemma differentiable_on.cos (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λx, real.cos (f x)) s := λx h, (hc x h).cos @[simp] lemma differentiable.cos (hc : differentiable ℝ f) : differentiable ℝ (λx, real.cos (f x)) := λx, (hc x).cos lemma fderiv_within_cos (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : fderiv_within ℝ (λx, real.cos (f x)) s x = - real.sin (f x) • (fderiv_within ℝ f s x) := hf.has_fderiv_within_at.cos.fderiv_within hxs @[simp] lemma fderiv_cos (hc : differentiable_at ℝ f x) : fderiv ℝ (λx, real.cos (f x)) x = - real.sin (f x) • (fderiv ℝ f x) := hc.has_fderiv_at.cos.fderiv lemma times_cont_diff.cos {n} (h : times_cont_diff ℝ n f) : times_cont_diff ℝ n (λ x, real.cos (f x)) := real.times_cont_diff_cos.comp h lemma times_cont_diff_at.cos {n} (hf : times_cont_diff_at ℝ n f x) : times_cont_diff_at ℝ n (λ x, real.cos (f x)) x := real.times_cont_diff_cos.times_cont_diff_at.comp x hf lemma times_cont_diff_on.cos {n} (hf : times_cont_diff_on ℝ n f s) : times_cont_diff_on ℝ n (λ x, real.cos (f x)) s := real.times_cont_diff_cos.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.cos {n} (hf : times_cont_diff_within_at ℝ n f s x) : times_cont_diff_within_at ℝ n (λ x, real.cos (f x)) s x := real.times_cont_diff_cos.times_cont_diff_at.comp_times_cont_diff_within_at x hf /-! #### `real.sin` -/ lemma has_fderiv_at.sin (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, real.sin (f x)) (real.cos (f x) • f') x := (real.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.sin (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, real.sin (f x)) (real.cos (f x) • f') s x := (real.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.sin (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.sin (f x)) s x := hf.has_fderiv_within_at.sin.differentiable_within_at @[simp] lemma differentiable_at.sin (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λx, real.sin (f x)) x := hc.has_fderiv_at.sin.differentiable_at lemma differentiable_on.sin (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λx, real.sin (f x)) s := λx h, (hc x h).sin @[simp] lemma differentiable.sin (hc : differentiable ℝ f) : differentiable ℝ (λx, real.sin (f x)) := λx, (hc x).sin lemma fderiv_within_sin (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : fderiv_within ℝ (λx, real.sin (f x)) s x = real.cos (f x) • (fderiv_within ℝ f s x) := hf.has_fderiv_within_at.sin.fderiv_within hxs @[simp] lemma fderiv_sin (hc : differentiable_at ℝ f x) : fderiv ℝ (λx, real.sin (f x)) x = real.cos (f x) • (fderiv ℝ f x) := hc.has_fderiv_at.sin.fderiv lemma times_cont_diff.sin {n} (h : times_cont_diff ℝ n f) : times_cont_diff ℝ n (λ x, real.sin (f x)) := real.times_cont_diff_sin.comp h lemma times_cont_diff_at.sin {n} (hf : times_cont_diff_at ℝ n f x) : times_cont_diff_at ℝ n (λ x, real.sin (f x)) x := real.times_cont_diff_sin.times_cont_diff_at.comp x hf lemma times_cont_diff_on.sin {n} (hf : times_cont_diff_on ℝ n f s) : times_cont_diff_on ℝ n (λ x, real.sin (f x)) s := real.times_cont_diff_sin.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.sin {n} (hf : times_cont_diff_within_at ℝ n f s x) : times_cont_diff_within_at ℝ n (λ x, real.sin (f x)) s x := real.times_cont_diff_sin.times_cont_diff_at.comp_times_cont_diff_within_at x hf /-! #### `real.cosh` -/ lemma has_fderiv_at.cosh (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, real.cosh (f x)) (real.sinh (f x) • f') x := (real.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.cosh (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, real.cosh (f x)) (real.sinh (f x) • f') s x := (real.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.cosh (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.cosh (f x)) s x := hf.has_fderiv_within_at.cosh.differentiable_within_at @[simp] lemma differentiable_at.cosh (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λx, real.cosh (f x)) x := hc.has_fderiv_at.cosh.differentiable_at lemma differentiable_on.cosh (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λx, real.cosh (f x)) s := λx h, (hc x h).cosh @[simp] lemma differentiable.cosh (hc : differentiable ℝ f) : differentiable ℝ (λx, real.cosh (f x)) := λx, (hc x).cosh lemma fderiv_within_cosh (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : fderiv_within ℝ (λx, real.cosh (f x)) s x = real.sinh (f x) • (fderiv_within ℝ f s x) := hf.has_fderiv_within_at.cosh.fderiv_within hxs @[simp] lemma fderiv_cosh (hc : differentiable_at ℝ f x) : fderiv ℝ (λx, real.cosh (f x)) x = real.sinh (f x) • (fderiv ℝ f x) := hc.has_fderiv_at.cosh.fderiv lemma times_cont_diff.cosh {n} (h : times_cont_diff ℝ n f) : times_cont_diff ℝ n (λ x, real.cosh (f x)) := real.times_cont_diff_cosh.comp h lemma times_cont_diff_at.cosh {n} (hf : times_cont_diff_at ℝ n f x) : times_cont_diff_at ℝ n (λ x, real.cosh (f x)) x := real.times_cont_diff_cosh.times_cont_diff_at.comp x hf lemma times_cont_diff_on.cosh {n} (hf : times_cont_diff_on ℝ n f s) : times_cont_diff_on ℝ n (λ x, real.cosh (f x)) s := real.times_cont_diff_cosh.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.cosh {n} (hf : times_cont_diff_within_at ℝ n f s x) : times_cont_diff_within_at ℝ n (λ x, real.cosh (f x)) s x := real.times_cont_diff_cosh.times_cont_diff_at.comp_times_cont_diff_within_at x hf /-! #### `real.sinh` -/ lemma has_fderiv_at.sinh (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, real.sinh (f x)) (real.cosh (f x) • f') x := (real.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.sinh (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, real.sinh (f x)) (real.cosh (f x) • f') s x := (real.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.sinh (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.sinh (f x)) s x := hf.has_fderiv_within_at.sinh.differentiable_within_at @[simp] lemma differentiable_at.sinh (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λx, real.sinh (f x)) x := hc.has_fderiv_at.sinh.differentiable_at lemma differentiable_on.sinh (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λx, real.sinh (f x)) s := λx h, (hc x h).sinh @[simp] lemma differentiable.sinh (hc : differentiable ℝ f) : differentiable ℝ (λx, real.sinh (f x)) := λx, (hc x).sinh lemma fderiv_within_sinh (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : fderiv_within ℝ (λx, real.sinh (f x)) s x = real.cosh (f x) • (fderiv_within ℝ f s x) := hf.has_fderiv_within_at.sinh.fderiv_within hxs @[simp] lemma fderiv_sinh (hc : differentiable_at ℝ f x) : fderiv ℝ (λx, real.sinh (f x)) x = real.cosh (f x) • (fderiv ℝ f x) := hc.has_fderiv_at.sinh.fderiv lemma times_cont_diff.sinh {n} (h : times_cont_diff ℝ n f) : times_cont_diff ℝ n (λ x, real.sinh (f x)) := real.times_cont_diff_sinh.comp h lemma times_cont_diff_at.sinh {n} (hf : times_cont_diff_at ℝ n f x) : times_cont_diff_at ℝ n (λ x, real.sinh (f x)) x := real.times_cont_diff_sinh.times_cont_diff_at.comp x hf lemma times_cont_diff_on.sinh {n} (hf : times_cont_diff_on ℝ n f s) : times_cont_diff_on ℝ n (λ x, real.sinh (f x)) s := real.times_cont_diff_sinh.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.sinh {n} (hf : times_cont_diff_within_at ℝ n f s x) : times_cont_diff_within_at ℝ n (λ x, real.sinh (f x)) s x := real.times_cont_diff_sinh.times_cont_diff_at.comp_times_cont_diff_within_at x hf end namespace real lemma exists_cos_eq_zero : 0 ∈ cos '' Icc (1:ℝ) 2 := intermediate_value_Icc' (by norm_num) continuous_on_cos ⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩ /-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from which one can derive all its properties. For explicit bounds on π, see `data.real.pi`. -/ noncomputable def pi : ℝ := 2 * classical.some exists_cos_eq_zero localized "notation `π` := real.pi" in real @[simp] lemma cos_pi_div_two : cos (π / 2) = 0 := by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)]; exact (classical.some_spec exists_cos_eq_zero).2 lemma one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)]; exact (classical.some_spec exists_cos_eq_zero).1.1 lemma pi_div_two_le_two : π / 2 ≤ 2 := by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)]; exact (classical.some_spec exists_cos_eq_zero).1.2 lemma two_le_pi : (2 : ℝ) ≤ π := (div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1 (by rw div_self (@two_ne_zero' ℝ _ _ _); exact one_le_pi_div_two) lemma pi_le_four : π ≤ 4 := (div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1 (calc π / 2 ≤ 2 : pi_div_two_le_two ... = 4 / 2 : by norm_num) lemma pi_pos : 0 < π := lt_of_lt_of_le (by norm_num) two_le_pi lemma pi_ne_zero : pi ≠ 0 := ne_of_gt pi_pos lemma pi_div_two_pos : 0 < π / 2 := half_pos pi_pos lemma two_pi_pos : 0 < 2 * π := by linarith [pi_pos] @[simp] lemma sin_pi : sin π = 0 := by rw [← mul_div_cancel_left pi (@two_ne_zero ℝ _ _), two_mul, add_div, sin_add, cos_pi_div_two]; simp @[simp] lemma cos_pi : cos π = -1 := by rw [← mul_div_cancel_left pi (@two_ne_zero ℝ _ _), mul_div_assoc, cos_two_mul, cos_pi_div_two]; simp [bit0, pow_add] @[simp] lemma sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] lemma cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] lemma sin_add_pi (x : ℝ) : sin (x + π) = -sin x := by simp [sin_add] lemma sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x := by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi] lemma cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x := by simp [cos_add, cos_two_pi, sin_two_pi] lemma sin_pi_sub (x : ℝ) : sin (π - x) = sin x := by simp [sub_eq_add_neg, sin_add] lemma cos_add_pi (x : ℝ) : cos (x + π) = -cos x := by simp [cos_add] lemma cos_pi_sub (x : ℝ) : cos (π - x) = -cos x := by simp [sub_eq_add_neg, cos_add] lemma sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x := if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2 else have (2 : ℝ) + 2 = 4, from rfl, have π - x ≤ 2, from sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)), sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this lemma sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x := sin_pos_of_pos_of_lt_pi hx.1 hx.2 lemma sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x := begin rw ← closure_Ioo pi_pos at hx, exact closure_lt_subset_le continuous_const continuous_sin (closure_mono (λ y, sin_pos_of_mem_Ioo) hx) end lemma sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x := sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩ lemma sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 := neg_pos.1 $ sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx) lemma sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 := neg_nonneg.1 $ sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx) @[simp] lemma sin_pi_div_two : sin (π / 2) = 1 := have sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by simpa [pow_two, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2), this.resolve_right (λ h, (show ¬(0 : ℝ) < -1, by norm_num) $ h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos)) lemma sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add] lemma sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] lemma sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] lemma cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add] lemma cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] lemma cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] lemma cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x := sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩ lemma cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x := sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩ lemma cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 := neg_pos.1 $ cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩ lemma cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) : cos x ≤ 0 := neg_nonneg.1 $ cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩ lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := by induction n; simp [add_mul, sin_add, *] lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi] lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi] lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe, int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg, (neg_mul_eq_neg_mul _ _).symm, cos_neg] lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by simp [cos_add, sin_add, cos_int_mul_two_pi] lemma sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) : sin x = 0 ↔ x = 0 := ⟨λ h, le_antisymm (le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $ calc 0 < sin x : sin_pos_of_pos_of_lt_pi h0 hx₂ ... = 0 : h)) (le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $ calc 0 = sin x : h.symm ... < 0 : sin_neg_of_neg_of_neg_pi_lt h0 hx₁)), λ h, by simp [h]⟩ lemma sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x := ⟨λ h, ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (sub_floor_div_mul_nonneg _ pi_pos)) (sub_nonpos.1 $ le_of_not_gt $ λ h₃, ne_of_lt (sin_pos_of_pos_of_lt_pi h₃ (sub_floor_div_mul_lt _ pi_pos)) (by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩, λ ⟨n, hn⟩, hn ▸ sin_int_mul_pi _⟩ lemma sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, pow_two, pow_two, ← sub_eq_iff_eq_add, sub_self]; exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩ lemma cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x := ⟨λ h, let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (or.inl h)) in ⟨n / 2, (int.mod_two_eq_zero_or_one n).elim (λ hn0, by rwa [← mul_assoc, ← @int.cast_two ℝ, ← int.cast_mul, int.div_mul_cancel ((int.dvd_iff_mod_eq_zero _ _).2 hn0)]) (λ hn1, by rw [← int.mod_add_div n 2, hn1, int.cast_add, int.cast_one, add_mul, one_mul, add_comm, mul_comm (2 : ℤ), int.cast_mul, mul_assoc, int.cast_two] at hn; rw [← hn, cos_int_mul_two_pi_add_pi] at h; exact absurd h (by norm_num))⟩, λ ⟨n, hn⟩, hn ▸ cos_int_mul_two_pi _⟩ lemma cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) : cos x = 1 ↔ x = 0 := ⟨λ h, begin rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩, rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂, rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁, norm_cast at hx₁ hx₂, obtain rfl : n = 0, by omega, simp end, λ h, by simp [h]⟩ lemma cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : cos y < cos x := begin rw [← sub_lt_zero, cos_sub_cos], have : 0 < sin ((y + x) / 2), { refine sin_pos_of_pos_of_lt_pi _ _; linarith }, have : 0 < sin ((y - x) / 2), { refine sin_pos_of_pos_of_lt_pi _ _; linarith }, nlinarith, end lemma cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) : cos y < cos x := match (le_total x (π / 2) : x ≤ π / 2 ∨ π / 2 ≤ x), le_total y (π / 2) with | or.inl hx, or.inl hy := cos_lt_cos_of_nonneg_of_le_pi_div_two hx₁ hy hxy | or.inl hx, or.inr hy := (lt_or_eq_of_le hx).elim (λ hx, calc cos y ≤ 0 : cos_nonpos_of_pi_div_two_le_of_le hy (by linarith [pi_pos]) ... < cos x : cos_pos_of_mem_Ioo ⟨by linarith, hx⟩) (λ hx, calc cos y < 0 : cos_neg_of_pi_div_two_lt_of_lt (by linarith) (by linarith [pi_pos]) ... = cos x : by rw [hx, cos_pi_div_two]) | or.inr hx, or.inl hy := by linarith | or.inr hx, or.inr hy := neg_lt_neg_iff.1 (by rw [← cos_pi_sub, ← cos_pi_sub]; apply cos_lt_cos_of_nonneg_of_le_pi_div_two; linarith) end lemma strict_mono_decr_on_cos : strict_mono_decr_on cos (Icc 0 π) := λ x hx y hy hxy, cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy lemma cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) : cos y ≤ cos x := (strict_mono_decr_on_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy lemma sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y := by rw [← cos_sub_pi_div_two, ← cos_sub_pi_div_two, ← cos_neg (x - _), ← cos_neg (y - _)]; apply cos_lt_cos_of_nonneg_of_le_pi; linarith lemma strict_mono_incr_on_sin : strict_mono_incr_on sin (Icc (-(π / 2)) (π / 2)) := λ x hx y hy hxy, sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy lemma sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y := (strict_mono_incr_on_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy lemma inj_on_sin : inj_on sin (Icc (-(π / 2)) (π / 2)) := strict_mono_incr_on_sin.inj_on lemma inj_on_cos : inj_on cos (Icc 0 π) := strict_mono_decr_on_cos.inj_on lemma surj_on_sin : surj_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := by simpa only [sin_neg, sin_pi_div_two] using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuous_on lemma surj_on_cos : surj_on cos (Icc 0 π) (Icc (-1) 1) := by simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuous_on lemma sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩ lemma cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩ lemma maps_to_sin (s : set ℝ) : maps_to sin s (Icc (-1 : ℝ) 1) := λ x _, sin_mem_Icc x lemma maps_to_cos (s : set ℝ) : maps_to cos s (Icc (-1 : ℝ) 1) := λ x _, cos_mem_Icc x lemma bij_on_sin : bij_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := ⟨maps_to_sin _, inj_on_sin, surj_on_sin⟩ lemma bij_on_cos : bij_on cos (Icc 0 π) (Icc (-1) 1) := ⟨maps_to_cos _, inj_on_cos, surj_on_cos⟩ @[simp] lemma range_cos : range cos = (Icc (-1) 1 : set ℝ) := subset.antisymm (range_subset_iff.2 cos_mem_Icc) surj_on_cos.subset_range @[simp] lemma range_sin : range sin = (Icc (-1) 1 : set ℝ) := subset.antisymm (range_subset_iff.2 sin_mem_Icc) surj_on_sin.subset_range lemma range_cos_infinite : (range real.cos).infinite := by { rw real.range_cos, exact Icc.infinite (by norm_num) } lemma range_sin_infinite : (range real.sin).infinite := by { rw real.range_sin, exact Icc.infinite (by norm_num) } lemma sin_lt {x : ℝ} (h : 0 < x) : sin x < x := begin cases le_or_gt x 1 with h' h', { have hx : abs x = x := abs_of_nonneg (le_of_lt h), have : abs x ≤ 1, rwa [hx], have := sin_bound this, rw [abs_le] at this, have := this.2, rw [sub_le_iff_le_add', hx] at this, apply lt_of_le_of_lt this, rw [sub_add], apply lt_of_lt_of_le _ (le_of_eq (sub_zero x)), apply sub_lt_sub_left, rw [sub_pos, div_eq_mul_inv (x ^ 3)], apply mul_lt_mul', { rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)), rw mul_le_mul_right, exact h', apply pow_pos h }, norm_num, norm_num, apply pow_pos h }, exact lt_of_le_of_lt (sin_le_one x) h' end /- note 1: this inequality is not tight, the tighter inequality is sin x > x - x ^ 3 / 6. note 2: this is also true for x > 1, but it's nontrivial for x just above 1. -/ lemma sin_gt_sub_cube {x : ℝ} (h : 0 < x) (h' : x ≤ 1) : x - x ^ 3 / 4 < sin x := begin have hx : abs x = x := abs_of_nonneg (le_of_lt h), have : abs x ≤ 1, rwa [hx], have := sin_bound this, rw [abs_le] at this, have := this.1, rw [le_sub_iff_add_le, hx] at this, refine lt_of_lt_of_le _ this, rw [add_comm, sub_add, sub_neg_eq_add], apply sub_lt_sub_left, apply add_lt_of_lt_sub_left, rw (show x ^ 3 / 4 - x ^ 3 / 6 = x ^ 3 * 12⁻¹, by simp [div_eq_mul_inv, ← mul_sub]; norm_num), apply mul_lt_mul', { rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)), rw mul_le_mul_right, exact h', apply pow_pos h }, norm_num, norm_num, apply pow_pos h end section cos_div_pow_two variable (x : ℝ) /-- the series `sqrt_two_add_series x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots, starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2` -/ @[simp, pp_nodot] noncomputable def sqrt_two_add_series (x : ℝ) : ℕ → ℝ | 0 := x | (n+1) := sqrt (2 + sqrt_two_add_series n) lemma sqrt_two_add_series_zero : sqrt_two_add_series x 0 = x := by simp lemma sqrt_two_add_series_one : sqrt_two_add_series 0 1 = sqrt 2 := by simp lemma sqrt_two_add_series_two : sqrt_two_add_series 0 2 = sqrt (2 + sqrt 2) := by simp lemma sqrt_two_add_series_zero_nonneg : ∀(n : ℕ), 0 ≤ sqrt_two_add_series 0 n | 0 := le_refl 0 | (n+1) := sqrt_nonneg _ lemma sqrt_two_add_series_nonneg {x : ℝ} (h : 0 ≤ x) : ∀(n : ℕ), 0 ≤ sqrt_two_add_series x n | 0 := h | (n+1) := sqrt_nonneg _ lemma sqrt_two_add_series_lt_two : ∀(n : ℕ), sqrt_two_add_series 0 n < 2 | 0 := by norm_num | (n+1) := begin refine lt_of_lt_of_le _ (le_of_eq $ sqrt_sqr $ le_of_lt zero_lt_two), rw [sqrt_two_add_series, sqrt_lt, ← lt_sub_iff_add_lt'], { refine (sqrt_two_add_series_lt_two n).trans_le _, norm_num }, { exact add_nonneg zero_le_two (sqrt_two_add_series_zero_nonneg n) } end lemma sqrt_two_add_series_succ (x : ℝ) : ∀(n : ℕ), sqrt_two_add_series x (n+1) = sqrt_two_add_series (sqrt (2 + x)) n | 0 := rfl | (n+1) := by rw [sqrt_two_add_series, sqrt_two_add_series_succ, sqrt_two_add_series] lemma sqrt_two_add_series_monotone_left {x y : ℝ} (h : x ≤ y) : ∀(n : ℕ), sqrt_two_add_series x n ≤ sqrt_two_add_series y n | 0 := h | (n+1) := begin rw [sqrt_two_add_series, sqrt_two_add_series], exact sqrt_le_sqrt (add_le_add_left (sqrt_two_add_series_monotone_left _) _) end @[simp] lemma cos_pi_over_two_pow : ∀(n : ℕ), cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2 | 0 := by simp | (n+1) := begin have : (2 : ℝ) ≠ 0 := two_ne_zero, symmetry, rw [div_eq_iff_mul_eq this], symmetry, rw [sqrt_two_add_series, sqrt_eq_iff_sqr_eq, mul_pow, cos_square, ←mul_div_assoc, nat.add_succ, pow_succ, mul_div_mul_left _ _ this, cos_pi_over_two_pow, add_mul], congr, { norm_num }, rw [mul_comm, pow_two, mul_assoc, ←mul_div_assoc, mul_div_cancel_left, ←mul_div_assoc, mul_div_cancel_left]; try { exact this }, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, norm_num, apply le_of_lt, apply cos_pos_of_mem_Ioo ⟨_, _⟩, { transitivity (0 : ℝ), rw neg_lt_zero, apply pi_div_two_pos, apply div_pos pi_pos, apply pow_pos, norm_num }, apply div_lt_div' (le_refl pi) _ pi_pos _, refine lt_of_le_of_lt (le_of_eq (pow_one _).symm) _, apply pow_lt_pow, norm_num, apply nat.succ_lt_succ, apply nat.succ_pos, all_goals {norm_num} end lemma sin_square_pi_over_two_pow (n : ℕ) : sin (pi / 2 ^ (n+1)) ^ 2 = 1 - (sqrt_two_add_series 0 n / 2) ^ 2 := by rw [sin_square, cos_pi_over_two_pow] lemma sin_square_pi_over_two_pow_succ (n : ℕ) : sin (pi / 2 ^ (n+2)) ^ 2 = 1 / 2 - sqrt_two_add_series 0 n / 4 := begin rw [sin_square_pi_over_two_pow, sqrt_two_add_series, div_pow, sqr_sqrt, add_div, ←sub_sub], congr, norm_num, norm_num, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, end @[simp] lemma sin_pi_over_two_pow_succ (n : ℕ) : sin (pi / 2 ^ (n+2)) = sqrt (2 - sqrt_two_add_series 0 n) / 2 := begin symmetry, rw [div_eq_iff_mul_eq], symmetry, rw [sqrt_eq_iff_sqr_eq, mul_pow, sin_square_pi_over_two_pow_succ, sub_mul], { congr, norm_num, rw [mul_comm], convert mul_div_cancel' _ _, norm_num, norm_num }, { rw [sub_nonneg], apply le_of_lt, apply sqrt_two_add_series_lt_two }, apply le_of_lt, apply mul_pos, apply sin_pos_of_pos_of_lt_pi, { apply div_pos pi_pos, apply pow_pos, norm_num }, refine lt_of_lt_of_le _ (le_of_eq (div_one _)), rw [div_lt_div_left], refine lt_of_le_of_lt (le_of_eq (pow_zero 2).symm) _, apply pow_lt_pow, norm_num, apply nat.succ_pos, apply pi_pos, apply pow_pos, all_goals {norm_num} end @[simp] lemma cos_pi_div_four : cos (pi / 4) = sqrt 2 / 2 := by { transitivity cos (pi / 2 ^ 2), congr, norm_num, simp } @[simp] lemma sin_pi_div_four : sin (pi / 4) = sqrt 2 / 2 := by { transitivity sin (pi / 2 ^ 2), congr, norm_num, simp } @[simp] lemma cos_pi_div_eight : cos (pi / 8) = sqrt (2 + sqrt 2) / 2 := by { transitivity cos (pi / 2 ^ 3), congr, norm_num, simp } @[simp] lemma sin_pi_div_eight : sin (pi / 8) = sqrt (2 - sqrt 2) / 2 := by { transitivity sin (pi / 2 ^ 3), congr, norm_num, simp } @[simp] lemma cos_pi_div_sixteen : cos (pi / 16) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 := by { transitivity cos (pi / 2 ^ 4), congr, norm_num, simp } @[simp] lemma sin_pi_div_sixteen : sin (pi / 16) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 := by { transitivity sin (pi / 2 ^ 4), congr, norm_num, simp } @[simp] lemma cos_pi_div_thirty_two : cos (pi / 32) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 := by { transitivity cos (pi / 2 ^ 5), congr, norm_num, simp } @[simp] lemma sin_pi_div_thirty_two : sin (pi / 32) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 := by { transitivity sin (pi / 2 ^ 5), congr, norm_num, simp } -- This section is also a convenient location for other explicit values of `sin` and `cos`. /-- The cosine of `π / 3` is `1 / 2`. -/ @[simp] lemma cos_pi_div_three : cos (π / 3) = 1 / 2 := begin have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0, { have : cos (3 * (π / 3)) = cos π := by { congr' 1, ring }, linarith [cos_pi, cos_three_mul (π / 3)] }, cases mul_eq_zero.mp h₁ with h h, { linarith [pow_eq_zero h] }, { have : cos π < cos (π / 3), { refine cos_lt_cos_of_nonneg_of_le_pi _ rfl.ge _; linarith [pi_pos] }, linarith [cos_pi] } end /-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ lemma square_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 := begin have h1 : cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2, { convert cos_square (π / 6), have h2 : 2 * (π / 6) = π / 3 := by cancel_denoms, rw [h2, cos_pi_div_three] }, rw ← sub_eq_zero at h1 ⊢, convert h1 using 1, ring end /-- The cosine of `π / 6` is `√3 / 2`. -/ @[simp] lemma cos_pi_div_six : cos (π / 6) = (sqrt 3) / 2 := begin suffices : sqrt 3 = cos (π / 6) * 2, { field_simp [(by norm_num : 0 ≠ 2)], exact this.symm }, rw sqrt_eq_iff_sqr_eq, { have h1 := (mul_right_inj' (by norm_num : (4:ℝ) ≠ 0)).mpr square_cos_pi_div_six, rw ← sub_eq_zero at h1 ⊢, convert h1 using 1, ring }, { norm_num }, { have : 0 < cos (π / 6) := by { apply cos_pos_of_mem_Ioo; split; linarith [pi_pos] }, linarith }, end /-- The sine of `π / 6` is `1 / 2`. -/ @[simp] lemma sin_pi_div_six : sin (π / 6) = 1 / 2 := begin rw [← cos_pi_div_two_sub, ← cos_pi_div_three], congr, ring end /-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ lemma square_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 := begin rw [← cos_pi_div_two_sub, ← square_cos_pi_div_six], congr, ring end /-- The sine of `π / 3` is `√3 / 2`. -/ @[simp] lemma sin_pi_div_three : sin (π / 3) = (sqrt 3) / 2 := begin rw [← cos_pi_div_two_sub, ← cos_pi_div_six], congr, ring end end cos_div_pow_two /-- The type of angles -/ def angle : Type := quotient_add_group.quotient (add_subgroup.gmultiples (2 * π)) namespace angle instance angle.add_comm_group : add_comm_group angle := quotient_add_group.add_comm_group _ instance : inhabited angle := ⟨0⟩ instance angle.has_coe : has_coe ℝ angle := ⟨quotient.mk'⟩ @[simp] lemma coe_zero : ↑(0 : ℝ) = (0 : angle) := rfl @[simp] lemma coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : angle) := rfl @[simp] lemma coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : angle) := rfl @[simp] lemma coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : angle) := by rw [sub_eq_add_neg, sub_eq_add_neg, coe_add, coe_neg] @[simp, norm_cast] lemma coe_nat_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n •ℕ (↑x : angle) := by simpa using add_monoid_hom.map_nsmul ⟨coe, coe_zero, coe_add⟩ _ _ @[simp, norm_cast] lemma coe_int_mul_eq_gsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n •ℤ (↑x : angle) := by simpa using add_monoid_hom.map_gsmul ⟨coe, coe_zero, coe_add⟩ _ _ @[simp] lemma coe_two_pi : ↑(2 * π : ℝ) = (0 : angle) := quotient.sound' ⟨-1, show (-1 : ℤ) •ℤ (2 * π) = _, by rw [neg_one_gsmul, add_zero]⟩ lemma angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by simp only [quotient_add_group.eq, add_subgroup.gmultiples_eq_closure, add_subgroup.mem_closure_singleton, gsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] theorem cos_eq_iff_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : angle) = ψ ∨ (θ : angle) = -ψ := begin split, { intro Hcos, rw [←sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false_intro two_ne_zero, false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos, rcases Hcos with ⟨n, hn⟩ | ⟨n, hn⟩, { right, rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _ _), ← sub_eq_iff_eq_add] at hn, rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero] }, { left, rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _ _), eq_sub_iff_add_eq] at hn, rw [← hn, coe_add, mul_assoc, coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero, zero_add] }, apply_instance, }, { rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub], rintro (⟨k, H⟩ | ⟨k, H⟩), rw [← sub_eq_zero_iff_eq, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero], rw [←sub_eq_zero_iff_eq, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k, mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] } end theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : ℝ} : sin θ = sin ψ ↔ (θ : angle) = ψ ∨ (θ : angle) + ψ = π := begin split, { intro Hsin, rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin, cases cos_eq_iff_eq_or_eq_neg.mp Hsin with h h, { left, rw [coe_sub, coe_sub] at h, exact sub_right_inj.1 h }, right, rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h, exact h.symm }, { rw [angle_eq_iff_two_pi_dvd_sub, ←eq_sub_iff_add_eq, ←coe_sub, angle_eq_iff_two_pi_dvd_sub], rintro (⟨k, H⟩ | ⟨k, H⟩), rw [← sub_eq_zero_iff_eq, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul], have H' : θ + ψ = (2 * k) * π + π := by rwa [←sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ←mul_assoc] at H, rw [← sub_eq_zero_iff_eq, sin_sub_sin, H', add_div, mul_assoc 2 _ π, mul_div_cancel_left _ (@two_ne_zero ℝ _ _), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] } end theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : angle) = ψ := begin cases cos_eq_iff_eq_or_eq_neg.mp Hcos with hc hc, { exact hc }, cases sin_eq_iff_eq_or_add_eq_pi.mp Hsin with hs hs, { exact hs }, rw [eq_neg_iff_add_eq_zero, hs] at hc, cases quotient.exact' hc with n hn, change n •ℤ _ = _ at hn, rw [← neg_one_mul, add_zero, ← sub_eq_zero_iff_eq, gsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero, eq_false_intro (ne_of_gt pi_pos), or_false, sub_neg_eq_add, ← int.cast_zero, ← int.cast_one, ← int.cast_bit0, ← int.cast_mul, ← int.cast_add, int.cast_inj] at hn, have : (n * 2 + 1) % (2:ℤ) = 0 % (2:ℤ) := congr_arg (%(2:ℤ)) hn, rw [add_comm, int.add_mul_mod_self] at this, exact absurd this one_ne_zero end end angle /-- `real.sin` as an `order_iso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/ def sin_order_iso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1:ℝ) 1 := (strict_mono_incr_on_sin.order_iso _ _).trans $ order_iso.set_congr _ _ bij_on_sin.image_eq @[simp] lemma coe_sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) : (sin_order_iso x : ℝ) = sin x := rfl lemma sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) : sin_order_iso x = ⟨sin x, sin_mem_Icc x⟩ := rfl /-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`. It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/ @[pp_nodot] noncomputable def arcsin : ℝ → ℝ := coe ∘ Icc_extend (neg_le_self zero_le_one) sin_order_iso.symm lemma arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := subtype.coe_prop _ @[simp] lemma range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) := by { rw [arcsin, range_comp coe], simp [Icc] } lemma arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2 lemma neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1 lemma arcsin_proj_Icc (x : ℝ) : arcsin (proj_Icc (-1) 1 (neg_le_self $ @zero_le_one ℝ _) x) = arcsin x := by rw [arcsin, function.comp_app, Icc_extend_coe, function.comp_app, Icc_extend] lemma sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x := by simpa [arcsin, Icc_extend_of_mem _ _ hx, -order_iso.apply_symm_apply] using subtype.ext_iff.1 (sin_order_iso.apply_symm_apply ⟨x, hx⟩) lemma sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x := sin_arcsin' ⟨hx₁, hx₂⟩ lemma arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x := inj_on_sin (arcsin_mem_Icc _) hx $ by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)] lemma arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x := arcsin_sin' ⟨hx₁, hx₂⟩ lemma strict_mono_incr_on_arcsin : strict_mono_incr_on arcsin (Icc (-1) 1) := (subtype.strict_mono_coe _).comp_strict_mono_incr_on $ sin_order_iso.symm.strict_mono.strict_mono_incr_on_Icc_extend _ lemma monotone_arcsin : monotone arcsin := (subtype.mono_coe _).comp $ sin_order_iso.symm.monotone.Icc_extend _ lemma inj_on_arcsin : inj_on arcsin (Icc (-1) 1) := strict_mono_incr_on_arcsin.inj_on lemma arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) : arcsin x = arcsin y ↔ x = y := inj_on_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ lemma continuous_arcsin : continuous arcsin := continuous_subtype_coe.comp sin_order_iso.symm.continuous.Icc_extend lemma continuous_at_arcsin {x : ℝ} : continuous_at arcsin x := continuous_arcsin.continuous_at lemma arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin y = x := begin subst y, exact inj_on_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x)) end @[simp] lemma arcsin_zero : arcsin 0 = 0 := arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩ @[simp] lemma arcsin_one : arcsin 1 = π / 2 := arcsin_eq_of_sin_eq sin_pi_div_two $ right_mem_Icc.2 (neg_le_self pi_div_two_pos.le) lemma arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 := by rw [← arcsin_proj_Icc, proj_Icc_of_right_le _ hx, subtype.coe_mk, arcsin_one] lemma arcsin_neg_one : arcsin (-1) = -(π / 2) := arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) $ left_mem_Icc.2 (neg_le_self pi_div_two_pos.le) lemma arcsin_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) := by rw [← arcsin_proj_Icc, proj_Icc_of_le_left _ hx, subtype.coe_mk, arcsin_neg_one] @[simp] lemma arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x := begin cases le_total x (-1) with hx₁ hx₁, { rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] }, cases le_total 1 x with hx₂ hx₂, { rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)] }, refine arcsin_eq_of_sin_eq _ _, { rw [sin_neg, sin_arcsin hx₁ hx₂] }, { exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ } end lemma arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := by rw [← arcsin_sin' hy, strict_mono_incr_on_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy] lemma arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := begin cases le_total x (-1) with hx₁ hx₁, { simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] }, cases lt_or_le 1 x with hx₂ hx₂, { simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂] }, exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy) end lemma le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x ≤ arcsin y ↔ sin x ≤ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩, sin_neg, neg_le_neg_iff] lemma le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) : x ≤ arcsin y ↔ sin x ≤ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩, sin_neg, neg_le_neg_iff] lemma arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans $ (not_congr $ le_arcsin_iff_sin_le hy hx).trans not_le lemma arcsin_lt_iff_lt_sin' {x y : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans $ (not_congr $ le_arcsin_iff_sin_le' hy).trans not_le lemma lt_arcsin_iff_sin_lt {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x < arcsin y ↔ sin x < y := not_le.symm.trans $ (not_congr $ arcsin_le_iff_le_sin hy hx).trans not_le lemma lt_arcsin_iff_sin_lt' {x y : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) : x < arcsin y ↔ sin x < y := not_le.symm.trans $ (not_congr $ arcsin_le_iff_le_sin' hx).trans not_le lemma arcsin_eq_iff_eq_sin {x y : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) : arcsin x = y ↔ x = sin y := by simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy), le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)] @[simp] lemma arcsin_nonneg {x : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x := (le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans $ by rw [sin_zero] @[simp] lemma arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 := neg_nonneg.symm.trans $ arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg @[simp] lemma arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 := by simp [le_antisymm_iff] @[simp] lemma zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 := eq_comm.trans arcsin_eq_zero_iff @[simp] lemma arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x := lt_iff_lt_of_le_iff_le arcsin_nonpos @[simp] lemma arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 := lt_iff_lt_of_le_iff_le arcsin_nonneg @[simp] lemma arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ x < 1 := (arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 $ neg_lt_self pi_div_two_pos)).trans $ by rw sin_pi_div_two @[simp] lemma neg_pi_div_two_lt_arcsin {x : ℝ} : -(π / 2) < arcsin x ↔ -1 < x := (lt_arcsin_iff_sin_lt' $ left_mem_Ico.2 $ neg_lt_self pi_div_two_pos).trans $ by rw [sin_neg, sin_pi_div_two] @[simp] lemma arcsin_eq_pi_div_two {x : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x := ⟨λ h, not_lt.1 $ λ h', (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩ @[simp] lemma pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x := eq_comm.trans arcsin_eq_pi_div_two @[simp] lemma pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ x := (arcsin_le_pi_div_two x).le_iff_eq.trans pi_div_two_eq_arcsin @[simp] lemma arcsin_eq_neg_pi_div_two {x : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 := ⟨λ h, not_lt.1 $ λ h', (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩ @[simp] lemma neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 := eq_comm.trans arcsin_eq_neg_pi_div_two @[simp] lemma arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -1 := (neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two lemma maps_to_sin_Ioo : maps_to sin (Ioo (-(π / 2)) (π / 2)) (Ioo (-1) 1) := λ x h, by rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin, arcsin_sin h.1.le h.2.le] /-- `real.sin` as a `local_homeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/ @[simp] def sin_local_homeomorph : local_homeomorph ℝ ℝ := { to_fun := sin, inv_fun := arcsin, source := Ioo (-(π / 2)) (π / 2), target := Ioo (-1) 1, map_source' := maps_to_sin_Ioo, map_target' := λ y hy, ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩, left_inv' := λ x hx, arcsin_sin hx.1.le hx.2.le, right_inv' := λ y hy, sin_arcsin hy.1.le hy.2.le, open_source := is_open_Ioo, open_target := is_open_Ioo, continuous_to_fun := continuous_sin.continuous_on, continuous_inv_fun := continuous_arcsin.continuous_on } lemma cos_arcsin_nonneg (x : ℝ) : 0 ≤ cos (arcsin x) := cos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩ lemma cos_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arcsin x) = sqrt (1 - x ^ 2) := have sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x), begin rw [← eq_sub_iff_add_eq', ← sqrt_inj (pow_two_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))), pow_two, sqrt_mul_self (cos_arcsin_nonneg _)] at this, rw [this, sin_arcsin hx₁ hx₂], end lemma deriv_arcsin_aux {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) : has_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x ∧ times_cont_diff_at ℝ ⊤ arcsin x := begin cases h₁.lt_or_lt with h₁ h₁, { have : 1 - x ^ 2 < 0, by nlinarith [h₁], rw [sqrt_eq_zero'.2 this.le, div_zero], have : arcsin =ᶠ[𝓝 x] λ _, -(π / 2) := (gt_mem_nhds h₁).mono (λ y hy, arcsin_of_le_neg_one hy.le), exact ⟨(has_deriv_at_const _ _).congr_of_eventually_eq this, times_cont_diff_at_const.congr_of_eventually_eq this⟩ }, cases h₂.lt_or_lt with h₂ h₂, { have : 0 < sqrt (1 - x ^ 2) := sqrt_pos.2 (by nlinarith [h₁, h₂]), simp only [← cos_arcsin h₁.le h₂.le, one_div] at this ⊢, exact ⟨sin_local_homeomorph.has_deriv_at_symm ⟨h₁, h₂⟩ this.ne' (has_deriv_at_sin _), sin_local_homeomorph.times_cont_diff_at_symm_deriv this.ne' ⟨h₁, h₂⟩ (has_deriv_at_sin _) times_cont_diff_sin.times_cont_diff_at⟩ }, { have : 1 - x ^ 2 < 0, by nlinarith [h₂], rw [sqrt_eq_zero'.2 this.le, div_zero], have : arcsin =ᶠ[𝓝 x] λ _, π / 2 := (lt_mem_nhds h₂).mono (λ y hy, arcsin_of_one_le hy.le), exact ⟨(has_deriv_at_const _ _).congr_of_eventually_eq this, times_cont_diff_at_const.congr_of_eventually_eq this⟩ } end lemma has_deriv_at_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) : has_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x := (deriv_arcsin_aux h₁ h₂).1 lemma times_cont_diff_at_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) {n : with_top ℕ} : times_cont_diff_at ℝ n arcsin x := (deriv_arcsin_aux h₁ h₂).2.of_le le_top lemma has_deriv_within_at_arcsin_Ici {x : ℝ} (h : x ≠ -1) : has_deriv_within_at arcsin (1 / sqrt (1 - x ^ 2)) (Ici x) x := begin rcases em (x = 1) with (rfl|h'), { convert (has_deriv_within_at_const _ _ (π / 2)).congr _ _; simp [arcsin_of_one_le] { contextual := tt } }, { exact (has_deriv_at_arcsin h h').has_deriv_within_at } end lemma has_deriv_within_at_arcsin_Iic {x : ℝ} (h : x ≠ 1) : has_deriv_within_at arcsin (1 / sqrt (1 - x ^ 2)) (Iic x) x := begin rcases em (x = -1) with (rfl|h'), { convert (has_deriv_within_at_const _ _ (-(π / 2))).congr _ _; simp [arcsin_of_le_neg_one] { contextual := tt } }, { exact (has_deriv_at_arcsin h' h).has_deriv_within_at } end lemma differentiable_within_at_arcsin_Ici {x : ℝ} : differentiable_within_at ℝ arcsin (Ici x) x ↔ x ≠ -1 := begin refine ⟨_, λ h, (has_deriv_within_at_arcsin_Ici h).differentiable_within_at⟩, rintro h rfl, have : sin ∘ arcsin =ᶠ[𝓝[Ici (-1:ℝ)] (-1)] id, { filter_upwards [Icc_mem_nhds_within_Ici ⟨le_rfl, neg_lt_self (@zero_lt_one ℝ _ _)⟩], exact λ x, sin_arcsin' }, have := h.has_deriv_within_at.sin.congr_of_eventually_eq this.symm (by simp), simpa using (unique_diff_on_Ici _ _ left_mem_Ici).eq_deriv _ this (has_deriv_within_at_id _ _) end lemma differentiable_within_at_arcsin_Iic {x : ℝ} : differentiable_within_at ℝ arcsin (Iic x) x ↔ x ≠ 1 := begin refine ⟨λ h, _, λ h, (has_deriv_within_at_arcsin_Iic h).differentiable_within_at⟩, rw [← neg_neg x, ← image_neg_Ici] at h, have := (h.comp (-x) differentiable_within_at_id.neg (maps_to_image _ _)).neg, simpa [(∘), differentiable_within_at_arcsin_Ici] using this end lemma differentiable_at_arcsin {x : ℝ} : differentiable_at ℝ arcsin x ↔ x ≠ -1 ∧ x ≠ 1 := ⟨λ h, ⟨differentiable_within_at_arcsin_Ici.1 h.differentiable_within_at, differentiable_within_at_arcsin_Iic.1 h.differentiable_within_at⟩, λ h, (has_deriv_at_arcsin h.1 h.2).differentiable_at⟩ @[simp] lemma deriv_arcsin : deriv arcsin = λ x, 1 / sqrt (1 - x ^ 2) := begin funext x, by_cases h : x ≠ -1 ∧ x ≠ 1, { exact (has_deriv_at_arcsin h.1 h.2).deriv }, { rw [deriv_zero_of_not_differentiable_at (mt differentiable_at_arcsin.1 h)], simp only [not_and_distrib, ne.def, not_not] at h, rcases h with (rfl|rfl); simp } end lemma differentiable_on_arcsin : differentiable_on ℝ arcsin {-1, 1}ᶜ := λ x hx, (differentiable_at_arcsin.2 ⟨λ h, hx (or.inl h), λ h, hx (or.inr h)⟩).differentiable_within_at lemma times_cont_diff_on_arcsin {n : with_top ℕ} : times_cont_diff_on ℝ n arcsin {-1, 1}ᶜ := λ x hx, (times_cont_diff_at_arcsin (mt or.inl hx) (mt or.inr hx)).times_cont_diff_within_at lemma times_cont_diff_at_arcsin_iff {x : ℝ} {n : with_top ℕ} : times_cont_diff_at ℝ n arcsin x ↔ n = 0 ∨ (x ≠ -1 ∧ x ≠ 1) := ⟨λ h, or_iff_not_imp_left.2 $ λ hn, differentiable_at_arcsin.1 $ h.differentiable_at $ with_top.one_le_iff_pos.2 (zero_lt_iff_ne_zero.2 hn), λ h, h.elim (λ hn, hn.symm ▸ (times_cont_diff_zero.2 continuous_arcsin).times_cont_diff_at) $ λ hx, times_cont_diff_at_arcsin hx.1 hx.2⟩ lemma measurable_arcsin : measurable arcsin := continuous_arcsin.measurable /-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`. If the argument is not between `-1` and `1` it defaults to `π / 2` -/ @[pp_nodot] noncomputable def arccos (x : ℝ) : ℝ := π / 2 - arcsin x lemma arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x := rfl lemma arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x := by simp [arccos] lemma arccos_le_pi (x : ℝ) : arccos x ≤ π := by unfold arccos; linarith [neg_pi_div_two_le_arcsin x] lemma arccos_nonneg (x : ℝ) : 0 ≤ arccos x := by unfold arccos; linarith [arcsin_le_pi_div_two x] lemma cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x := by rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂] lemma arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x := by rw [arccos, ← sin_pi_div_two_sub, arcsin_sin]; simp [sub_eq_add_neg]; linarith lemma strict_mono_decr_on_arccos : strict_mono_decr_on arccos (Icc (-1) 1) := λ x hx y hy h, sub_lt_sub_left (strict_mono_incr_on_arcsin hx hy h) _ lemma arccos_inj_on : inj_on arccos (Icc (-1) 1) := strict_mono_decr_on_arccos.inj_on lemma arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) : arccos x = arccos y ↔ x = y := arccos_inj_on.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ @[simp] lemma arccos_zero : arccos 0 = π / 2 := by simp [arccos] @[simp] lemma arccos_one : arccos 1 = 0 := by simp [arccos] @[simp] lemma arccos_neg_one : arccos (-1) = π := by simp [arccos, add_halves] @[simp] lemma arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≤ x := by simp [arccos, sub_eq_zero] @[simp] lemma arccos_eq_pi_div_two {x} : arccos x = π / 2 ↔ x = 0 := by simp [arccos, sub_eq_iff_eq_add] @[simp] lemma arccos_eq_pi {x} : arccos x = π ↔ x ≤ -1 := by rw [arccos, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin] lemma arccos_neg (x : ℝ) : arccos (-x) = π - arccos x := by rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add] lemma sin_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arccos x) = sqrt (1 - x ^ 2) := by rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin hx₁ hx₂] lemma continuous_arccos : continuous arccos := continuous_const.sub continuous_arcsin lemma has_deriv_at_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) : has_deriv_at arccos (-(1 / sqrt (1 - x ^ 2))) x := (has_deriv_at_arcsin h₁ h₂).const_sub (π / 2) lemma times_cont_diff_at_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) {n : with_top ℕ} : times_cont_diff_at ℝ n arccos x := times_cont_diff_at_const.sub (times_cont_diff_at_arcsin h₁ h₂) lemma has_deriv_within_at_arccos_Ici {x : ℝ} (h : x ≠ -1) : has_deriv_within_at arccos (-(1 / sqrt (1 - x ^ 2))) (Ici x) x := (has_deriv_within_at_arcsin_Ici h).const_sub _ lemma has_deriv_within_at_arccos_Iic {x : ℝ} (h : x ≠ 1) : has_deriv_within_at arccos (-(1 / sqrt (1 - x ^ 2))) (Iic x) x := (has_deriv_within_at_arcsin_Iic h).const_sub _ lemma differentiable_within_at_arccos_Ici {x : ℝ} : differentiable_within_at ℝ arccos (Ici x) x ↔ x ≠ -1 := (differentiable_within_at_const_sub_iff _).trans differentiable_within_at_arcsin_Ici lemma differentiable_within_at_arccos_Iic {x : ℝ} : differentiable_within_at ℝ arccos (Iic x) x ↔ x ≠ 1 := (differentiable_within_at_const_sub_iff _).trans differentiable_within_at_arcsin_Iic lemma differentiable_at_arccos {x : ℝ} : differentiable_at ℝ arccos x ↔ x ≠ -1 ∧ x ≠ 1 := (differentiable_at_const_sub_iff _).trans differentiable_at_arcsin @[simp] lemma deriv_arccos : deriv arccos = λ x, -(1 / sqrt (1 - x ^ 2)) := funext $ λ x, (deriv_const_sub _).trans $ by simp only [deriv_arcsin] lemma differentiable_on_arccos : differentiable_on ℝ arccos {-1, 1}ᶜ := differentiable_on_arcsin.const_sub _ lemma times_cont_diff_on_arccos {n : with_top ℕ} : times_cont_diff_on ℝ n arccos {-1, 1}ᶜ := times_cont_diff_on_const.sub times_cont_diff_on_arcsin lemma times_cont_diff_at_arccos_iff {x : ℝ} {n : with_top ℕ} : times_cont_diff_at ℝ n arccos x ↔ n = 0 ∨ (x ≠ -1 ∧ x ≠ 1) := by refine iff.trans ⟨λ h, _, λ h, _⟩ times_cont_diff_at_arcsin_iff; simpa [arccos] using (@times_cont_diff_at_const _ _ _ _ _ _ _ _ _ _ (π / 2)).sub h lemma measurable_arccos : measurable arccos := continuous_arccos.measurable @[simp] lemma tan_pi_div_four : tan (π / 4) = 1 := begin rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four], have h : (sqrt 2) / 2 > 0 := by cancel_denoms, exact div_self (ne_of_gt h), end @[simp] lemma tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos] lemma tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x := by rw tan_eq_sin_div_cos; exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith)) (cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩) lemma tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x := match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with | or.inl hx0, or.inl hxp := le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp) | or.inl hx0, or.inr hxp := by simp [hxp, tan_eq_sin_div_cos] | or.inr hx0, _ := by simp [hx0.symm] end lemma tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 := neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos])) lemma tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) : tan x ≤ 0 := neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith)) lemma tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := begin rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos], exact div_lt_div (sin_lt_sin_of_lt_of_le_pi_div_two (by linarith) (le_of_lt hy₂) hxy) (cos_le_cos_of_nonneg_of_le_pi hx₁ (by linarith) (le_of_lt hxy)) (sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith)) (cos_pos_of_mem_Ioo ⟨by linarith, hy₂⟩) end lemma tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := match le_total x 0, le_total y 0 with | or.inl hx0, or.inl hy0 := neg_lt_neg_iff.1 $ by rw [← tan_neg, ← tan_neg]; exact tan_lt_tan_of_nonneg_of_lt_pi_div_two (neg_nonneg.2 hy0) (neg_lt.2 hx₁) (neg_lt_neg hxy) | or.inl hx0, or.inr hy0 := (lt_or_eq_of_le hy0).elim (λ hy0, calc tan x ≤ 0 : tan_nonpos_of_nonpos_of_neg_pi_div_two_le hx0 (le_of_lt hx₁) ... < tan y : tan_pos_of_pos_of_lt_pi_div_two hy0 hy₂) (λ hy0, by rw [← hy0, tan_zero]; exact tan_neg_of_neg_of_pi_div_two_lt (hy0.symm ▸ hxy) hx₁) | or.inr hx0, or.inl hy0 := by linarith | or.inr hx0, or.inr hy0 := tan_lt_tan_of_nonneg_of_lt_pi_div_two hx0 hy₂ hxy end lemma strict_mono_incr_on_tan : strict_mono_incr_on tan (Ioo (-(π / 2)) (π / 2)) := λ x hx y hy, tan_lt_tan_of_lt_of_lt_pi_div_two hx.1 hy.2 lemma inj_on_tan : inj_on tan (Ioo (-(π / 2)) (π / 2)) := strict_mono_incr_on_tan.inj_on lemma tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) (hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y := inj_on_tan ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ hxy end real namespace complex open_locale real /-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, `arg 0` defaults to `0` -/ noncomputable def arg (x : ℂ) : ℝ := if 0 ≤ x.re then real.arcsin (x.im / x.abs) else if 0 ≤ x.im then real.arcsin ((-x).im / x.abs) + π else real.arcsin ((-x).im / x.abs) - π lemma arg_le_pi (x : ℂ) : arg x ≤ π := if hx₁ : 0 ≤ x.re then by rw [arg, if_pos hx₁]; exact le_trans (real.arcsin_le_pi_div_two _) (le_of_lt (half_lt_self real.pi_pos)) else if hx₂ : 0 ≤ x.im then by rw [arg, if_neg hx₁, if_pos hx₂, ← le_sub_iff_add_le, sub_self, real.arcsin_nonpos, neg_im, neg_div, neg_nonpos]; exact div_nonneg hx₂ (abs_nonneg _) else by rw [arg, if_neg hx₁, if_neg hx₂]; exact sub_le_iff_le_add.2 (le_trans (real.arcsin_le_pi_div_two _) (by linarith [real.pi_pos])) lemma neg_pi_lt_arg (x : ℂ) : -π < arg x := if hx₁ : 0 ≤ x.re then by rw [arg, if_pos hx₁]; exact lt_of_lt_of_le (neg_lt_neg (half_lt_self real.pi_pos)) (real.neg_pi_div_two_le_arcsin _) else have hx : x ≠ 0, from λ h, by simpa [h, lt_irrefl] using hx₁, if hx₂ : 0 ≤ x.im then by rw [arg, if_neg hx₁, if_pos hx₂, ← sub_lt_iff_lt_add]; exact (lt_of_lt_of_le (by linarith [real.pi_pos]) (real.neg_pi_div_two_le_arcsin _)) else by rw [arg, if_neg hx₁, if_neg hx₂, lt_sub_iff_add_lt, neg_add_self, real.arcsin_pos, neg_im]; exact div_pos (neg_pos.2 (lt_of_not_ge hx₂)) (abs_pos.2 hx) lemma arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : 0 ≤ x.im) : arg x = arg (-x) + π := have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos], by rw [arg, arg, if_neg (not_le.2 hxr), if_pos this, if_pos hxi, abs_neg] lemma arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : x.im < 0) : arg x = arg (-x) - π := have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos], by rw [arg, arg, if_neg (not_le.2 hxr), if_neg (not_le.2 hxi), if_pos this, abs_neg] @[simp] lemma arg_zero : arg 0 = 0 := by simp [arg, le_refl] @[simp] lemma arg_one : arg 1 = 0 := by simp [arg, zero_le_one] @[simp] lemma arg_neg_one : arg (-1) = π := by simp [arg, le_refl, not_le.2 (@zero_lt_one ℝ _ _)] @[simp] lemma arg_I : arg I = π / 2 := by simp [arg, le_refl] @[simp] lemma arg_neg_I : arg (-I) = -(π / 2) := by simp [arg, le_refl] lemma sin_arg (x : ℂ) : real.sin (arg x) = x.im / x.abs := by unfold arg; split_ifs; simp [sub_eq_add_neg, arg, real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1 (abs_le.1 (abs_im_div_abs_le_one x)).2, real.sin_add, neg_div, real.arcsin_neg, real.sin_neg] private lemma cos_arg_of_re_nonneg {x : ℂ} (hx : x ≠ 0) (hxr : 0 ≤ x.re) : real.cos (arg x) = x.re / x.abs := have 0 ≤ 1 - (x.im / abs x) ^ 2, from sub_nonneg.2 $ by rw [pow_two, ← _root_.abs_mul_self, _root_.abs_mul, ← pow_two]; exact pow_le_one _ (_root_.abs_nonneg _) (abs_im_div_abs_le_one _), by rw [eq_div_iff_mul_eq (mt abs_eq_zero.1 hx), ← real.mul_self_sqrt (abs_nonneg x), arg, if_pos hxr, real.cos_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1 (abs_le.1 (abs_im_div_abs_le_one x)).2, ← real.sqrt_mul (abs_nonneg _), ← real.sqrt_mul this, sub_mul, div_pow, ← pow_two, div_mul_cancel _ (pow_ne_zero 2 (mt abs_eq_zero.1 hx)), one_mul, pow_two, mul_self_abs, norm_sq_apply, pow_two, add_sub_cancel, real.sqrt_mul_self hxr] lemma cos_arg {x : ℂ} (hx : x ≠ 0) : real.cos (arg x) = x.re / x.abs := if hxr : 0 ≤ x.re then cos_arg_of_re_nonneg hx hxr else have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr, if hxi : 0 ≤ x.im then have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr, by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg (not_le.1 hxr) hxi, real.cos_add_pi, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this]; simp [neg_div] else by rw [arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg (not_le.1 hxr) (not_le.1 hxi)]; simp [sub_eq_add_neg, real.cos_add, neg_div, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this] lemma tan_arg {x : ℂ} : real.tan (arg x) = x.im / x.re := begin by_cases h : x = 0, { simp only [h, zero_div, complex.zero_im, complex.arg_zero, real.tan_zero, complex.zero_re] }, rw [real.tan_eq_sin_div_cos, sin_arg, cos_arg h, div_div_div_cancel_right _ (mt abs_eq_zero.1 h)] end lemma arg_cos_add_sin_mul_I {x : ℝ} (hx₁ : -π < x) (hx₂ : x ≤ π) : arg (cos x + sin x * I) = x := if hx₃ : -(π / 2) ≤ x ∧ x ≤ π / 2 then have hx₄ : 0 ≤ (cos x + sin x * I).re, by simp; exact real.cos_nonneg_of_mem_Icc hx₃, by rw [arg, if_pos hx₄]; simp [abs_cos_add_sin_mul_I, sin_of_real_re, real.arcsin_sin hx₃.1 hx₃.2] else if hx₄ : x < -(π / 2) then have hx₅ : ¬0 ≤ (cos x + sin x * I).re := suffices ¬ 0 ≤ real.cos x, by simpa, not_le.2 $ by rw ← real.cos_neg; apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith, have hx₆ : ¬0 ≤ (cos ↑x + sin ↑x * I).im := suffices real.sin x < 0, by simpa, by apply real.sin_neg_of_neg_of_neg_pi_lt; linarith, suffices -π + -real.arcsin (real.sin x) = x, by rw [arg, if_neg hx₅, if_neg hx₆]; simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re], by rw [← real.arcsin_neg, ← real.sin_add_pi, real.arcsin_sin]; try {simp [add_left_comm]}; linarith else have hx₅ : π / 2 < x, by cases not_and_distrib.1 hx₃; linarith, have hx₆ : ¬0 ≤ (cos x + sin x * I).re := suffices ¬0 ≤ real.cos x, by simpa, not_le.2 $ by apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith, have hx₇ : 0 ≤ (cos x + sin x * I).im := suffices 0 ≤ real.sin x, by simpa, by apply real.sin_nonneg_of_nonneg_of_le_pi; linarith, suffices π - real.arcsin (real.sin x) = x, by rw [arg, if_neg hx₆, if_pos hx₇]; simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re], by rw [← real.sin_pi_sub, real.arcsin_sin]; simp [sub_eq_add_neg]; linarith lemma arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) : arg x = arg y ↔ (abs y / abs x : ℂ) * x = y := have hax : abs x ≠ 0, from (mt abs_eq_zero.1 hx), have hay : abs y ≠ 0, from (mt abs_eq_zero.1 hy), ⟨λ h, begin have hcos := congr_arg real.cos h, rw [cos_arg hx, cos_arg hy, div_eq_div_iff hax hay] at hcos, have hsin := congr_arg real.sin h, rw [sin_arg, sin_arg, div_eq_div_iff hax hay] at hsin, apply complex.ext, { rw [mul_re, ← of_real_div, of_real_re, of_real_im, zero_mul, sub_zero, mul_comm, ← mul_div_assoc, hcos, mul_div_cancel _ hax] }, { rw [mul_im, ← of_real_div, of_real_re, of_real_im, zero_mul, add_zero, mul_comm, ← mul_div_assoc, hsin, mul_div_cancel _ hax] } end, λ h, have hre : abs (y / x) * x.re = y.re, by rw ← of_real_div at h; simpa [-of_real_div] using congr_arg re h, have hre' : abs (x / y) * y.re = x.re, by rw [← hre, abs_div, abs_div, ← mul_assoc, div_mul_div, mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul], have him : abs (y / x) * x.im = y.im, by rw ← of_real_div at h; simpa [-of_real_div] using congr_arg im h, have him' : abs (x / y) * y.im = x.im, by rw [← him, abs_div, abs_div, ← mul_assoc, div_mul_div, mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul], have hxya : x.im / abs x = y.im / abs y, by rw [← him, abs_div, mul_comm, ← mul_div_comm, mul_div_cancel_left _ hay], have hnxya : (-x).im / abs x = (-y).im / abs y, by rw [neg_im, neg_im, neg_div, neg_div, hxya], if hxr : 0 ≤ x.re then have hyr : 0 ≤ y.re, from hre ▸ mul_nonneg (abs_nonneg _) hxr, by simp [arg, *] at * else have hyr : ¬ 0 ≤ y.re, from λ hyr, hxr $ hre' ▸ mul_nonneg (abs_nonneg _) hyr, if hxi : 0 ≤ x.im then have hyi : 0 ≤ y.im, from him ▸ mul_nonneg (abs_nonneg _) hxi, by simp [arg, *] at * else have hyi : ¬ 0 ≤ y.im, from λ hyi, hxi $ him' ▸ mul_nonneg (abs_nonneg _) hyi, by simp [arg, *] at *⟩ lemma arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x := if hx : x = 0 then by simp [hx] else (arg_eq_arg_iff (mul_ne_zero (of_real_ne_zero.2 (ne_of_lt hr).symm) hx) hx).2 $ by rw [abs_mul, abs_of_nonneg (le_of_lt hr), ← mul_assoc, of_real_mul, mul_comm (r : ℂ), ← div_div_eq_div_mul, div_mul_cancel _ (of_real_ne_zero.2 (ne_of_lt hr).symm), div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), one_mul] lemma ext_abs_arg {x y : ℂ} (h₁ : x.abs = y.abs) (h₂ : x.arg = y.arg) : x = y := if hy : y = 0 then by simp * at * else have hx : x ≠ 0, from λ hx, by simp [*, eq_comm] at *, by rwa [arg_eq_arg_iff hx hy, h₁, div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hy)), one_mul] at h₂ lemma arg_of_real_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 := by simp [arg, hx] lemma arg_of_real_of_neg {x : ℝ} (hx : x < 0) : arg x = π := by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg, ← of_real_neg, arg_of_real_of_nonneg]; simp [*, le_iff_eq_or_lt, lt_neg] /-- Inverse of the `exp` function. Returns values such that `(log x).im > - π` and `(log x).im ≤ π`. `log 0 = 0`-/ noncomputable def log (x : ℂ) : ℂ := x.abs.log + arg x * I lemma log_re (x : ℂ) : x.log.re = x.abs.log := by simp [log] lemma log_im (x : ℂ) : x.log.im = x.arg := by simp [log] lemma exp_log {x : ℂ} (hx : x ≠ 0) : exp (log x) = x := by rw [log, exp_add_mul_I, ← of_real_sin, sin_arg, ← of_real_cos, cos_arg hx, ← of_real_exp, real.exp_log (abs_pos.2 hx), mul_add, of_real_div, of_real_div, mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), ← mul_assoc, mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), re_add_im] lemma range_exp : range exp = {x | x ≠ 0} := set.ext $ λ x, ⟨by { rintro ⟨x, rfl⟩, exact exp_ne_zero x }, λ hx, ⟨log x, exp_log hx⟩⟩ lemma exp_inj_of_neg_pi_lt_of_le_pi {x y : ℂ} (hx₁ : -π < x.im) (hx₂ : x.im ≤ π) (hy₁ : - π < y.im) (hy₂ : y.im ≤ π) (hxy : exp x = exp y) : x = y := by rw [exp_eq_exp_re_mul_sin_add_cos, exp_eq_exp_re_mul_sin_add_cos y] at hxy; exact complex.ext (real.exp_injective $ by simpa [abs_mul, abs_cos_add_sin_mul_I] using congr_arg complex.abs hxy) (by simpa [(of_real_exp _).symm, - of_real_exp, arg_real_mul _ (real.exp_pos _), arg_cos_add_sin_mul_I hx₁ hx₂, arg_cos_add_sin_mul_I hy₁ hy₂] using congr_arg arg hxy) lemma log_exp {x : ℂ} (hx₁ : -π < x.im) (hx₂: x.im ≤ π) : log (exp x) = x := exp_inj_of_neg_pi_lt_of_le_pi (by rw log_im; exact neg_pi_lt_arg _) (by rw log_im; exact arg_le_pi _) hx₁ hx₂ (by rw [exp_log (exp_ne_zero _)]) lemma of_real_log {x : ℝ} (hx : 0 ≤ x) : (x.log : ℂ) = log x := complex.ext (by rw [log_re, of_real_re, abs_of_nonneg hx]) (by rw [of_real_im, log_im, arg_of_real_of_nonneg hx]) lemma log_of_real_re (x : ℝ) : (log (x : ℂ)).re = real.log x := by simp [log_re] @[simp] lemma log_zero : log 0 = 0 := by simp [log] @[simp] lemma log_one : log 1 = 0 := by simp [log] lemma log_neg_one : log (-1) = π * I := by simp [log] lemma log_I : log I = π / 2 * I := by simp [log] lemma log_neg_I : log (-I) = -(π / 2) * I := by simp [log] lemma exists_pow_nat_eq (x : ℂ) {n : ℕ} (hn : 0 < n) : ∃ z, z ^ n = x := begin by_cases hx : x = 0, { use 0, simp only [hx, zero_pow_eq_zero, hn] }, { use exp (log x / n), rw [← exp_nat_mul, mul_div_cancel', exp_log hx], exact_mod_cast (nat.pos_iff_ne_zero.mp hn) } end lemma exists_eq_mul_self (x : ℂ) : ∃ z, x = z * z := begin obtain ⟨z, rfl⟩ := exists_pow_nat_eq x zero_lt_two, exact ⟨z, pow_two z⟩ end lemma two_pi_I_ne_zero : (2 * π * I : ℂ) ≠ 0 := by norm_num [real.pi_ne_zero, I_ne_zero] lemma exp_eq_one_iff {x : ℂ} : exp x = 1 ↔ ∃ n : ℤ, x = n * ((2 * π) * I) := have real.exp (x.re) * real.cos (x.im) = 1 → real.cos x.im ≠ -1, from λ h₁ h₂, begin rw [h₂, mul_neg_eq_neg_mul_symm, mul_one, neg_eq_iff_neg_eq] at h₁, have := real.exp_pos x.re, rw ← h₁ at this, exact absurd this (by norm_num) end, calc exp x = 1 ↔ (exp x).re = 1 ∧ (exp x).im = 0 : by simp [complex.ext_iff] ... ↔ real.cos x.im = 1 ∧ real.sin x.im = 0 ∧ x.re = 0 : begin rw exp_eq_exp_re_mul_sin_add_cos, simp [complex.ext_iff, cos_of_real_re, sin_of_real_re, exp_of_real_re, real.exp_ne_zero], split; finish [real.sin_eq_zero_iff_cos_eq] end ... ↔ (∃ n : ℤ, ↑n * (2 * π) = x.im) ∧ (∃ n : ℤ, ↑n * π = x.im) ∧ x.re = 0 : by rw [real.sin_eq_zero_iff, real.cos_eq_one_iff] ... ↔ ∃ n : ℤ, x = n * ((2 * π) * I) : ⟨λ ⟨⟨n, hn⟩, ⟨m, hm⟩, h⟩, ⟨n, by simp [complex.ext_iff, hn.symm, h]⟩, λ ⟨n, hn⟩, ⟨⟨n, by simp [hn]⟩, ⟨2 * n, by simp [hn, mul_comm, mul_assoc, mul_left_comm]⟩, by simp [hn]⟩⟩ lemma exp_eq_exp_iff_exp_sub_eq_one {x y : ℂ} : exp x = exp y ↔ exp (x - y) = 1 := by rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)] lemma exp_eq_exp_iff_exists_int {x y : ℂ} : exp x = exp y ↔ ∃ n : ℤ, x = y + n * ((2 * π) * I) := by simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add'] @[simp] lemma cos_pi_div_two : cos (π / 2) = 0 := calc cos (π / 2) = real.cos (π / 2) : by rw [of_real_cos]; simp ... = 0 : by simp @[simp] lemma sin_pi_div_two : sin (π / 2) = 1 := calc sin (π / 2) = real.sin (π / 2) : by rw [of_real_sin]; simp ... = 1 : by simp @[simp] lemma sin_pi : sin π = 0 := by rw [← of_real_sin, real.sin_pi]; simp @[simp] lemma cos_pi : cos π = -1 := by rw [← of_real_cos, real.cos_pi]; simp @[simp] lemma sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] lemma cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] lemma sin_add_pi (x : ℂ) : sin (x + π) = -sin x := by simp [sin_add] lemma sin_add_two_pi (x : ℂ) : sin (x + 2 * π) = sin x := by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi] lemma cos_add_two_pi (x : ℂ) : cos (x + 2 * π) = cos x := by simp [cos_add, cos_two_pi, sin_two_pi] lemma sin_pi_sub (x : ℂ) : sin (π - x) = sin x := by simp [sub_eq_add_neg, sin_add] lemma cos_add_pi (x : ℂ) : cos (x + π) = -cos x := by simp [cos_add] lemma cos_pi_sub (x : ℂ) : cos (π - x) = -cos x := by simp [sub_eq_add_neg, cos_add] lemma sin_add_pi_div_two (x : ℂ) : sin (x + π / 2) = cos x := by simp [sin_add] lemma sin_sub_pi_div_two (x : ℂ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] lemma sin_pi_div_two_sub (x : ℂ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] lemma cos_add_pi_div_two (x : ℂ) : cos (x + π / 2) = -sin x := by simp [cos_add] lemma cos_sub_pi_div_two (x : ℂ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] lemma cos_pi_div_two_sub (x : ℂ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := by induction n; simp [add_mul, sin_add, *] lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi] lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi] lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe, int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg, (neg_mul_eq_neg_mul _ _).symm, cos_neg] lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by simp [cos_add, sin_add, cos_int_mul_two_pi] lemma exp_pi_mul_I : exp (π * I) = -1 := by { rw exp_mul_I, simp, } theorem cos_eq_zero_iff {θ : ℂ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 := begin have h : (exp (θ * I) + exp (-θ * I)) / 2 = 0 ↔ exp (2 * θ * I) = -1, { rw [@div_eq_iff _ _ (exp (θ * I) + exp (-θ * I)) 2 0 (by norm_num), zero_mul, add_eq_zero_iff_eq_neg, neg_eq_neg_one_mul (exp (-θ * I)), ← div_eq_iff (exp_ne_zero (-θ * I)), ← exp_sub], field_simp, ring }, rw [cos, h, ← exp_pi_mul_I, exp_eq_exp_iff_exists_int], split; simp; intros x h2; use x, { field_simp, ring at h2, rwa [mul_right_comm 2 I θ, mul_right_comm (2*(x:ℂ)+1) I (π:ℂ), mul_left_inj' I_ne_zero, mul_comm 2 θ] at h2}, { field_simp at h2, ring, rw [mul_right_comm 2 I θ, mul_right_comm (2*(x:ℂ)+1) I (π:ℂ), mul_left_inj' I_ne_zero, mul_comm 2 θ, h2] }, end theorem cos_ne_zero_iff {θ : ℂ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 := by rw [← not_exists, not_iff_not, cos_eq_zero_iff] theorem sin_eq_zero_iff {θ : ℂ} : sin θ = 0 ↔ ∃ k : ℤ, θ = k * π := begin rw [← complex.cos_sub_pi_div_two, cos_eq_zero_iff], split, { rintros ⟨k, hk⟩, use k + 1, field_simp [eq_add_of_sub_eq hk], ring }, { rintros ⟨k, rfl⟩, use k - 1, field_simp, ring } end theorem sin_ne_zero_iff {θ : ℂ} : sin θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π := by rw [← not_exists, not_iff_not, sin_eq_zero_iff] lemma cos_eq_cos_iff {x y : ℂ} : cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x := calc cos x = cos y ↔ cos x - cos y = 0 : sub_eq_zero.symm ... ↔ -2 * sin((x + y)/2) * sin((x - y)/2) = 0 : by rw cos_sub_cos ... ↔ sin((x + y)/2) = 0 ∨ sin((x - y)/2) = 0 : by simp [(by norm_num : (2:ℂ) ≠ 0)] ... ↔ sin((x - y)/2) = 0 ∨ sin((x + y)/2) = 0 : or.comm ... ↔ (∃ k : ℤ, y = 2 * k * π + x) ∨ (∃ k :ℤ, y = 2 * k * π - x) : begin apply or_congr; field_simp [sin_eq_zero_iff, (by norm_num : -(2:ℂ) ≠ 0), eq_sub_iff_add_eq', sub_eq_iff_eq_add, mul_comm (2:ℂ), mul_right_comm _ (2:ℂ)], split; { rintros ⟨k, rfl⟩, use -k, simp, }, end ... ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x : exists_or_distrib.symm lemma sin_eq_sin_iff {x y : ℂ} : sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x := begin simp only [← complex.cos_sub_pi_div_two, cos_eq_cos_iff, sub_eq_iff_eq_add], refine exists_congr (λ k, or_congr _ _); refine eq.congr rfl _; field_simp; ring end lemma has_deriv_at_tan {x : ℂ} (h : cos x ≠ 0) : has_deriv_at tan (1 / (cos x)^2) x := begin convert has_deriv_at.div (has_deriv_at_sin x) (has_deriv_at_cos x) h, rw ← sin_sq_add_cos_sq x, ring, end lemma tendsto_abs_tan_of_cos_eq_zero {x : ℂ} (hx : cos x = 0) : tendsto (λ x, abs (tan x)) (𝓝[{x}ᶜ] x) at_top := begin simp only [tan_eq_sin_div_cos, ← norm_eq_abs, normed_field.norm_div], have A : sin x ≠ 0 := λ h, by simpa [*, pow_two] using sin_sq_add_cos_sq x, have B : tendsto cos (𝓝[{x}ᶜ] (x)) (𝓝[{0}ᶜ] 0), { refine tendsto_inf.2 ⟨tendsto.mono_left _ inf_le_left, tendsto_principal.2 _⟩, exacts [continuous_cos.tendsto' x 0 hx, hx ▸ (has_deriv_at_cos _).eventually_ne (neg_ne_zero.2 A)] }, exact tendsto.mul_at_top (norm_pos_iff.2 A) continuous_sin.continuous_within_at.norm (tendsto.inv_tendsto_zero $ tendsto_norm_nhds_within_zero.comp B), end lemma tendsto_abs_tan_at_top (k : ℤ) : tendsto (λ x, abs (tan x)) (𝓝[{(2 * k + 1) * π / 2}ᶜ] ((2 * k + 1) * π / 2)) at_top := tendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 ⟨k, rfl⟩ @[simp] lemma continuous_at_tan {x : ℂ} : continuous_at tan x ↔ cos x ≠ 0 := begin refine ⟨λ hc h₀, _, λ h, (has_deriv_at_tan h).continuous_at⟩, exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h₀) _ (hc.norm.tendsto.mono_left inf_le_left) end @[simp] lemma differentiable_at_tan {x : ℂ} : differentiable_at ℂ tan x ↔ cos x ≠ 0:= ⟨λ h, continuous_at_tan.1 h.continuous_at, λ h, (has_deriv_at_tan h).differentiable_at⟩ @[simp] lemma deriv_tan (x : ℂ) : deriv tan x = 1 / (cos x)^2 := if h : cos x = 0 then have ¬differentiable_at ℂ tan x := mt differentiable_at_tan.1 (not_not.2 h), by simp [deriv_zero_of_not_differentiable_at this, h, pow_two] else (has_deriv_at_tan h).deriv lemma continuous_on_tan : continuous_on tan {x | cos x ≠ 0} := continuous_on_sin.div continuous_on_cos $ λ x, id lemma continuous_tan : continuous (λ x : {x | cos x ≠ 0}, tan x) := continuous_on_iff_continuous_restrict.1 continuous_on_tan @[simp] lemma times_cont_diff_at_tan {x : ℂ} {n : with_top ℕ} : times_cont_diff_at ℂ n tan x ↔ cos x ≠ 0 := ⟨λ h, continuous_at_tan.1 h.continuous_at, times_cont_diff_sin.times_cont_diff_at.div times_cont_diff_cos.times_cont_diff_at⟩ lemma cos_eq_iff_quadratic {z w : ℂ} : cos z = w ↔ (exp (z * I)) ^ 2 - 2 * w * exp (z * I) + 1 = 0 := begin rw ← sub_eq_zero, field_simp [cos, exp_neg, exp_ne_zero], refine eq.congr _ rfl, ring end lemma cos_surjective : function.surjective cos := begin intro x, obtain ⟨w, w₀, hw⟩ : ∃ w ≠ 0, 1 * w * w + (-2 * x) * w + 1 = 0, { rcases exists_quadratic_eq_zero one_ne_zero (exists_eq_mul_self _) with ⟨w, hw⟩, refine ⟨w, _, hw⟩, rintro rfl, simpa only [zero_add, one_ne_zero, mul_zero] using hw }, refine ⟨log w / I, cos_eq_iff_quadratic.2 _⟩, rw [div_mul_cancel _ I_ne_zero, exp_log w₀], convert hw, ring end @[simp] lemma range_cos : range cos = set.univ := cos_surjective.range_eq lemma sin_surjective : function.surjective sin := begin intro x, rcases cos_surjective x with ⟨z, rfl⟩, exact ⟨z + π / 2, sin_add_pi_div_two z⟩ end @[simp] lemma range_sin : range sin = set.univ := sin_surjective.range_eq end complex section chebyshev₁ open polynomial complex /-- the `n`-th Chebyshev polynomial evaluates on `cos θ` to the value `cos (n * θ)`. -/ lemma chebyshev₁_complex_cos (θ : ℂ) : ∀ n, (chebyshev₁ ℂ n).eval (cos θ) = cos (n * θ) | 0 := by simp only [chebyshev₁_zero, eval_one, nat.cast_zero, zero_mul, cos_zero] | 1 := by simp only [eval_X, one_mul, chebyshev₁_one, nat.cast_one] | (n + 2) := begin simp only [eval_X, eval_one, chebyshev₁_add_two, eval_sub, eval_bit0, nat.cast_succ, eval_mul], rw [chebyshev₁_complex_cos (n + 1), chebyshev₁_complex_cos n], have aux : sin θ * sin θ = 1 - cos θ * cos θ, { rw ← sin_sq_add_cos_sq θ, ring, }, simp only [nat.cast_add, nat.cast_one, add_mul, cos_add, one_mul, sin_add, mul_assoc, aux], ring, end /-- `cos (n * θ)` is equal to the `n`-th Chebyshev polynomial evaluated on `cos θ`. -/ lemma cos_nat_mul (n : ℕ) (θ : ℂ) : cos (n * θ) = (chebyshev₁ ℂ n).eval (cos θ) := (chebyshev₁_complex_cos θ n).symm end chebyshev₁ namespace real open_locale real theorem cos_eq_zero_iff {θ : ℝ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 := by exact_mod_cast @complex.cos_eq_zero_iff θ theorem cos_ne_zero_iff {θ : ℝ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 := by rw [← not_exists, not_iff_not, cos_eq_zero_iff] lemma cos_eq_cos_iff {x y : ℝ} : cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x := by exact_mod_cast @complex.cos_eq_cos_iff x y lemma sin_eq_sin_iff {x y : ℝ} : sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x := by exact_mod_cast @complex.sin_eq_sin_iff x y lemma has_deriv_at_tan {x : ℝ} (h : cos x ≠ 0) : has_deriv_at tan (1 / (cos x)^2) x := by exact_mod_cast (complex.has_deriv_at_tan (by exact_mod_cast h)).real_of_complex lemma tendsto_abs_tan_of_cos_eq_zero {x : ℝ} (hx : cos x = 0) : tendsto (λ x, abs (tan x)) (𝓝[{x}ᶜ] x) at_top := begin have hx : complex.cos x = 0, by exact_mod_cast hx, simp only [← complex.abs_of_real, complex.of_real_tan], refine (complex.tendsto_abs_tan_of_cos_eq_zero hx).comp _, refine tendsto.inf complex.continuous_of_real.continuous_at _, exact tendsto_principal_principal.2 (λ y, mt complex.of_real_inj.1) end lemma tendsto_abs_tan_at_top (k : ℤ) : tendsto (λ x, abs (tan x)) (𝓝[{(2 * k + 1) * π / 2}ᶜ] ((2 * k + 1) * π / 2)) at_top := tendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 ⟨k, rfl⟩ lemma continuous_at_tan {x : ℝ} : continuous_at tan x ↔ cos x ≠ 0 := begin refine ⟨λ hc h₀, _, λ h, (has_deriv_at_tan h).continuous_at⟩, exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h₀) _ (hc.norm.tendsto.mono_left inf_le_left) end lemma differentiable_at_tan {x : ℝ} : differentiable_at ℝ tan x ↔ cos x ≠ 0 := ⟨λ h, continuous_at_tan.1 h.continuous_at, λ h, (has_deriv_at_tan h).differentiable_at⟩ @[simp] lemma deriv_tan (x : ℝ) : deriv tan x = 1 / (cos x)^2 := if h : cos x = 0 then have ¬differentiable_at ℝ tan x := mt differentiable_at_tan.1 (not_not.2 h), by simp [deriv_zero_of_not_differentiable_at this, h, pow_two] else (has_deriv_at_tan h).deriv @[simp] lemma times_cont_diff_at_tan {n x} : times_cont_diff_at ℝ n tan x ↔ cos x ≠ 0 := ⟨λ h, continuous_at_tan.1 h.continuous_at, λ h, (complex.times_cont_diff_at_tan.2 $ by exact_mod_cast h).real_of_complex⟩ lemma continuous_on_tan : continuous_on tan {x | cos x ≠ 0} := λ x hx, (continuous_at_tan.2 hx).continuous_within_at lemma has_deriv_at_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(π/2):ℝ) (π/2)) : has_deriv_at tan (1 / (cos x)^2) x := has_deriv_at_tan (cos_pos_of_mem_Ioo h).ne' lemma differentiable_at_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(π/2):ℝ) (π/2)) : differentiable_at ℝ tan x := (has_deriv_at_tan_of_mem_Ioo h).differentiable_at lemma continuous_on_tan_Ioo : continuous_on tan (Ioo (-(π/2)) (π/2)) := λ x hx, (differentiable_at_tan_of_mem_Ioo hx).continuous_at.continuous_within_at lemma tendsto_sin_pi_div_two : tendsto sin (𝓝[Iio (π/2)] (π/2)) (𝓝 1) := by { convert continuous_sin.continuous_within_at, simp } lemma tendsto_cos_pi_div_two : tendsto cos (𝓝[Iio (π/2)] (π/2)) (𝓝[Ioi 0] 0) := begin apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within, { convert continuous_cos.continuous_within_at, simp }, { filter_upwards [Ioo_mem_nhds_within_Iio (right_mem_Ioc.mpr (norm_num.lt_neg_pos _ _ pi_div_two_pos pi_div_two_pos))] λ x hx, cos_pos_of_mem_Ioo hx }, end lemma tendsto_tan_pi_div_two : tendsto tan (𝓝[Iio (π/2)] (π/2)) at_top := begin convert (tendsto.inv_tendsto_zero tendsto_cos_pi_div_two).at_top_mul (by norm_num) tendsto_sin_pi_div_two, simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] end lemma tendsto_sin_neg_pi_div_two : tendsto sin (𝓝[Ioi (-(π/2))] (-(π/2))) (𝓝 (-1)) := by { convert continuous_sin.continuous_within_at, simp } lemma tendsto_cos_neg_pi_div_two : tendsto cos (𝓝[Ioi (-(π/2))] (-(π/2))) (𝓝[Ioi 0] 0) := begin apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within, { convert continuous_cos.continuous_within_at, simp }, { filter_upwards [Ioo_mem_nhds_within_Ioi (set.left_mem_Ico.mpr (norm_num.lt_neg_pos _ _ pi_div_two_pos pi_div_two_pos))] λ x hx, cos_pos_of_mem_Ioo hx }, end lemma tendsto_tan_neg_pi_div_two : tendsto tan (𝓝[Ioi (-(π/2))] (-(π/2))) at_bot := begin convert (tendsto.inv_tendsto_zero tendsto_cos_neg_pi_div_two).at_top_mul_neg (by norm_num) tendsto_sin_neg_pi_div_two, simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] end lemma surj_on_tan : surj_on tan (Ioo (-(π / 2)) (π / 2)) univ := have _ := neg_lt_self pi_div_two_pos, continuous_on_tan_Ioo.surj_on_of_tendsto (nonempty_Ioo.2 this) (by simp [tendsto_tan_neg_pi_div_two, this]) (by simp [tendsto_tan_pi_div_two, this]) lemma tan_surjective : function.surjective tan := λ x, surj_on_tan.subset_range trivial lemma image_tan_Ioo : tan '' (Ioo (-(π / 2)) (π / 2)) = univ := univ_subset_iff.1 surj_on_tan /-- `real.tan` as an `order_iso` between `(-(π / 2), π / 2)` and `ℝ`. -/ def tan_order_iso : Ioo (-(π / 2)) (π / 2) ≃o ℝ := (strict_mono_incr_on_tan.order_iso _ _).trans $ (order_iso.set_congr _ _ image_tan_Ioo).trans order_iso.set.univ /-- Inverse of the `tan` function, returns values in the range `-π / 2 < arctan x` and `arctan x < π / 2` -/ @[pp_nodot] noncomputable def arctan (x : ℝ) : ℝ := tan_order_iso.symm x @[simp] lemma tan_arctan (x : ℝ) : tan (arctan x) = x := tan_order_iso.apply_symm_apply x lemma arctan_mem_Ioo (x : ℝ) : arctan x ∈ Ioo (-(π / 2)) (π / 2) := subtype.coe_prop _ lemma arctan_tan {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : arctan (tan x) = x := subtype.ext_iff.1 $ tan_order_iso.symm_apply_apply ⟨x, hx₁, hx₂⟩ lemma cos_arctan_pos (x : ℝ) : 0 < cos (arctan x) := cos_pos_of_mem_Ioo $ arctan_mem_Ioo x lemma cos_sq_arctan (x : ℝ) : cos (arctan x) ^ 2 = 1 / (1 + x ^ 2) := by rw [one_div, ← inv_one_add_tan_sq (cos_arctan_pos x).ne', tan_arctan] lemma sin_arctan (x : ℝ) : sin (arctan x) = x / sqrt (1 + x ^ 2) := by rw [← tan_div_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan] lemma cos_arctan (x : ℝ) : cos (arctan x) = 1 / sqrt (1 + x ^ 2) := by rw [one_div, ← inv_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan] lemma arctan_lt_pi_div_two (x : ℝ) : arctan x < π / 2 := (arctan_mem_Ioo x).2 lemma neg_pi_div_two_lt_arctan (x : ℝ) : -(π / 2) < arctan x := (arctan_mem_Ioo x).1 lemma arctan_eq_arcsin (x : ℝ) : arctan x = arcsin (x / sqrt (1 + x ^ 2)) := eq.symm $ arcsin_eq_of_sin_eq (sin_arctan x) (mem_Icc_of_Ioo $ arctan_mem_Ioo x) @[simp] lemma arctan_zero : arctan 0 = 0 := by simp [arctan_eq_arcsin] lemma arctan_eq_of_tan_eq {x y : ℝ} (h : tan x = y) (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : arctan y = x := inj_on_tan (arctan_mem_Ioo _) hx (by rw [tan_arctan, h]) @[simp] lemma arctan_one : arctan 1 = π / 4 := arctan_eq_of_tan_eq tan_pi_div_four $ by split; linarith [pi_pos] @[simp] lemma arctan_neg (x : ℝ) : arctan (-x) = - arctan x := by simp [arctan_eq_arcsin, neg_div] lemma continuous_arctan : continuous arctan := continuous_subtype_coe.comp tan_order_iso.to_homeomorph.continuous_inv_fun lemma continuous_at_arctan {x : ℝ} : continuous_at arctan x := continuous_arctan.continuous_at /-- `real.tan` as a `local_homeomorph` between `(-(π / 2), π / 2)` and the whole line. -/ def tan_local_homeomorph : local_homeomorph ℝ ℝ := { to_fun := tan, inv_fun := arctan, source := Ioo (-(π / 2)) (π / 2), target := univ, map_source' := maps_to_univ _ _, map_target' := λ y hy, arctan_mem_Ioo y, left_inv' := λ x hx, arctan_tan hx.1 hx.2, right_inv' := λ y hy, tan_arctan y, open_source := is_open_Ioo, open_target := is_open_univ, continuous_to_fun := continuous_on_tan_Ioo, continuous_inv_fun := continuous_arctan.continuous_on } @[simp] lemma coe_tan_local_homeomorph : ⇑tan_local_homeomorph = tan := rfl @[simp] lemma coe_tan_local_homeomorph_symm : ⇑tan_local_homeomorph.symm = arctan := rfl lemma has_deriv_at_arctan (x : ℝ) : has_deriv_at arctan (1 / (1 + x^2)) x := have A : cos (arctan x) ≠ 0 := (cos_arctan_pos x).ne', by simpa [cos_sq_arctan] using tan_local_homeomorph.has_deriv_at_symm trivial (by simpa) (has_deriv_at_tan A) lemma differentiable_at_arctan (x : ℝ) : differentiable_at ℝ arctan x := (has_deriv_at_arctan x).differentiable_at lemma differentiable_arctan : differentiable ℝ arctan := differentiable_at_arctan @[simp] lemma deriv_arctan : deriv arctan = (λ x, 1 / (1 + x^2)) := funext $ λ x, (has_deriv_at_arctan x).deriv lemma times_cont_diff_arctan {n : with_top ℕ} : times_cont_diff ℝ n arctan := times_cont_diff_iff_times_cont_diff_at.2 $ λ x, have cos (arctan x) ≠ 0 := (cos_arctan_pos x).ne', tan_local_homeomorph.times_cont_diff_at_symm_deriv (by simpa) trivial (has_deriv_at_tan this) (times_cont_diff_at_tan.2 this) lemma measurable_arctan : measurable arctan := continuous_arctan.measurable end real section /-! ### Lemmas for derivatives of the composition of `real.arctan` with a differentiable function In this section we register lemmas for the derivatives of the composition of `real.arctan` with a differentiable function, for standalone use and use with `simp`. -/ open real lemma measurable.arctan {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) : measurable (λ x, arctan (f x)) := measurable_arctan.comp hf section deriv variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ} lemma has_deriv_at.arctan (hf : has_deriv_at f f' x) : has_deriv_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) * f') x := (real.has_deriv_at_arctan (f x)).comp x hf lemma has_deriv_within_at.arctan (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) * f') s x := (real.has_deriv_at_arctan (f x)).comp_has_deriv_within_at x hf lemma deriv_within_arctan (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λ x, arctan (f x)) s x = (1 / (1 + (f x)^2)) * (deriv_within f s x) := hf.has_deriv_within_at.arctan.deriv_within hxs @[simp] lemma deriv_arctan (hc : differentiable_at ℝ f x) : deriv (λ x, arctan (f x)) x = (1 / (1 + (f x)^2)) * (deriv f x) := hc.has_deriv_at.arctan.deriv end deriv section fderiv variables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ} {x : E} {s : set E} {n : with_top ℕ} lemma has_fderiv_at.arctan (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) • f') x := (has_deriv_at_arctan (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.arctan (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) • f') s x := (has_deriv_at_arctan (f x)).comp_has_fderiv_within_at x hf lemma fderiv_within_arctan (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : fderiv_within ℝ (λ x, arctan (f x)) s x = (1 / (1 + (f x)^2)) • (fderiv_within ℝ f s x) := hf.has_fderiv_within_at.arctan.fderiv_within hxs @[simp] lemma fderiv_arctan (hc : differentiable_at ℝ f x) : fderiv ℝ (λ x, arctan (f x)) x = (1 / (1 + (f x)^2)) • (fderiv ℝ f x) := hc.has_fderiv_at.arctan.fderiv lemma differentiable_within_at.arctan (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.arctan (f x)) s x := hf.has_fderiv_within_at.arctan.differentiable_within_at @[simp] lemma differentiable_at.arctan (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λ x, arctan (f x)) x := hc.has_fderiv_at.arctan.differentiable_at lemma differentiable_on.arctan (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λ x, arctan (f x)) s := λ x h, (hc x h).arctan @[simp] lemma differentiable.arctan (hc : differentiable ℝ f) : differentiable ℝ (λ x, arctan (f x)) := λ x, (hc x).arctan lemma times_cont_diff_at.arctan (h : times_cont_diff_at ℝ n f x) : times_cont_diff_at ℝ n (λ x, arctan (f x)) x := times_cont_diff_arctan.times_cont_diff_at.comp x h lemma times_cont_diff.arctan (h : times_cont_diff ℝ n f) : times_cont_diff ℝ n (λ x, arctan (f x)) := times_cont_diff_arctan.comp h lemma times_cont_diff_within_at.arctan (h : times_cont_diff_within_at ℝ n f s x) : times_cont_diff_within_at ℝ n (λ x, arctan (f x)) s x := times_cont_diff_arctan.comp_times_cont_diff_within_at h lemma times_cont_diff_on.arctan (h : times_cont_diff_on ℝ n f s) : times_cont_diff_on ℝ n (λ x, arctan (f x)) s := times_cont_diff_arctan.comp_times_cont_diff_on h end fderiv end
f64d6d8cb5bf46cc2581f57cfb9c87cb351e6cda
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/analysis/convex/topology_auto.lean
f2bd2f92e28ac6c1c0747b26a16512bc47b14292
[]
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
6,830
lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudriashov -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.analysis.convex.basic import Mathlib.analysis.normed_space.finite_dimension import Mathlib.topology.path_connected import Mathlib.PostPort universes u_1 u_2 namespace Mathlib /-! # Topological and metric properties of convex sets We prove the following facts: * `convex.interior` : interior of a convex set is convex; * `convex.closure` : closure of a convex set is convex; * `set.finite.compact_convex_hull` : convex hull of a finite set is compact; * `set.finite.is_closed_convex_hull` : convex hull of a finite set is closed; * `convex_on_dist` : distance to a fixed point is convex on any convex set; * `convex_hull_ediam`, `convex_hull_diam` : convex hull of a set has the same (e)metric diameter as the original set; * `bounded_convex_hull` : convex hull of a set is bounded if and only if the original set is bounded. * `bounded_std_simplex`, `is_closed_std_simplex`, `compact_std_simplex`: topological properties of the standard simplex; -/ theorem real.convex_iff_is_preconnected {s : set ℝ} : convex s ↔ is_preconnected s := iff.trans real.convex_iff_ord_connected (iff.symm is_preconnected_iff_ord_connected) theorem is_preconnected.convex {s : set ℝ} : is_preconnected s → convex s := iff.mpr real.convex_iff_is_preconnected /-! ### Standard simplex -/ /-- Every vector in `std_simplex ι` has `max`-norm at most `1`. -/ theorem std_simplex_subset_closed_ball {ι : Type u_1} [fintype ι] : std_simplex ι ⊆ metric.closed_ball 0 1 := sorry /-- `std_simplex ι` is bounded. -/ theorem bounded_std_simplex (ι : Type u_1) [fintype ι] : metric.bounded (std_simplex ι) := iff.mpr (metric.bounded_iff_subset_ball 0) (Exists.intro 1 std_simplex_subset_closed_ball) /-- `std_simplex ι` is closed. -/ theorem is_closed_std_simplex (ι : Type u_1) [fintype ι] : is_closed (std_simplex ι) := sorry /-- `std_simplex ι` is compact. -/ theorem compact_std_simplex (ι : Type u_1) [fintype ι] : is_compact (std_simplex ι) := iff.mpr metric.compact_iff_closed_bounded { left := is_closed_std_simplex ι, right := bounded_std_simplex ι } /-! ### Topological vector space -/ /-- In a topological vector space, the interior of a convex set is convex. -/ theorem convex.interior {E : Type u_2} [add_comm_group E] [vector_space ℝ E] [topological_space E] [topological_add_group E] [topological_vector_space ℝ E] {s : set E} (hs : convex s) : convex (interior s) := sorry /-- In a topological vector space, the closure of a convex set is convex. -/ theorem convex.closure {E : Type u_2} [add_comm_group E] [vector_space ℝ E] [topological_space E] [topological_add_group E] [topological_vector_space ℝ E] {s : set E} (hs : convex s) : convex (closure s) := sorry /-- Convex hull of a finite set is compact. -/ theorem set.finite.compact_convex_hull {E : Type u_2} [add_comm_group E] [vector_space ℝ E] [topological_space E] [topological_add_group E] [topological_vector_space ℝ E] {s : set E} (hs : set.finite s) : is_compact (convex_hull s) := sorry /-- Convex hull of a finite set is closed. -/ theorem set.finite.is_closed_convex_hull {E : Type u_2} [add_comm_group E] [vector_space ℝ E] [topological_space E] [topological_add_group E] [topological_vector_space ℝ E] [t2_space E] {s : set E} (hs : set.finite s) : is_closed (convex_hull s) := is_compact.is_closed (set.finite.compact_convex_hull hs) /-! ### Normed vector space -/ theorem convex_on_dist {E : Type u_2} [normed_group E] [normed_space ℝ E] (z : E) (s : set E) (hs : convex s) : convex_on s fun (z' : E) => dist z' z := sorry theorem convex_ball {E : Type u_2} [normed_group E] [normed_space ℝ E] (a : E) (r : ℝ) : convex (metric.ball a r) := sorry theorem convex_closed_ball {E : Type u_2} [normed_group E] [normed_space ℝ E] (a : E) (r : ℝ) : convex (metric.closed_ball a r) := sorry /-- Given a point `x` in the convex hull of `s` and a point `y`, there exists a point of `s` at distance at least `dist x y` from `y`. -/ theorem convex_hull_exists_dist_ge {E : Type u_2} [normed_group E] [normed_space ℝ E] {s : set E} {x : E} (hx : x ∈ convex_hull s) (y : E) : ∃ (x' : E), ∃ (H : x' ∈ s), dist x y ≤ dist x' y := convex_on.exists_ge_of_mem_convex_hull (convex_on_dist y (convex_hull s) (convex_convex_hull s)) hx /-- Given a point `x` in the convex hull of `s` and a point `y` in the convex hull of `t`, there exist points `x' ∈ s` and `y' ∈ t` at distance at least `dist x y`. -/ theorem convex_hull_exists_dist_ge2 {E : Type u_2} [normed_group E] [normed_space ℝ E] {s : set E} {t : set E} {x : E} {y : E} (hx : x ∈ convex_hull s) (hy : y ∈ convex_hull t) : ∃ (x' : E), ∃ (H : x' ∈ s), ∃ (y' : E), ∃ (H : y' ∈ t), dist x y ≤ dist x' y' := sorry /-- Emetric diameter of the convex hull of a set `s` equals the emetric diameter of `s. -/ @[simp] theorem convex_hull_ediam {E : Type u_2} [normed_group E] [normed_space ℝ E] (s : set E) : emetric.diam (convex_hull s) = emetric.diam s := sorry /-- Diameter of the convex hull of a set `s` equals the emetric diameter of `s. -/ @[simp] theorem convex_hull_diam {E : Type u_2} [normed_group E] [normed_space ℝ E] (s : set E) : metric.diam (convex_hull s) = metric.diam s := sorry /-- Convex hull of `s` is bounded if and only if `s` is bounded. -/ @[simp] theorem bounded_convex_hull {E : Type u_2} [normed_group E] [normed_space ℝ E] {s : set E} : metric.bounded (convex_hull s) ↔ metric.bounded s := sorry theorem convex.is_path_connected {E : Type u_2} [normed_group E] [normed_space ℝ E] {s : set E} (hconv : convex s) (hne : set.nonempty s) : is_path_connected s := sorry protected instance normed_space.path_connected {E : Type u_2} [normed_group E] [normed_space ℝ E] : path_connected_space E := iff.mpr path_connected_space_iff_univ (convex.is_path_connected convex_univ (Exists.intro 0 trivial)) protected instance normed_space.loc_path_connected {E : Type u_2} [normed_group E] [normed_space ℝ E] : loc_path_connected_space E := loc_path_connected_of_bases (fun (x : E) => metric.nhds_basis_ball) fun (x : E) (r : ℝ) (r_pos : 0 < r) => convex.is_path_connected (convex_ball x r) (eq.mpr (id (propext ((fun {α : Type u_2} [_inst_1 : metric_space α] {x : α} {ε : ℝ} (h : 0 < ε) => iff_true_intro (metric.nonempty_ball h)) (iff.mpr (iff_true_intro r_pos) True.intro)))) trivial) end Mathlib
a6ebf06afba0ef1c87d701d0afdf7c0b624270bc
94e33a31faa76775069b071adea97e86e218a8ee
/src/group_theory/finite_abelian.lean
04c269575ab3d649af431adc38bcf58ac087bf79
[ "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,524
lean
/- Copyright (c) 2022 Pierre-Alexandre Bazin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Pierre-Alexandre Bazin -/ import data.zmod.quotient import algebra.module.pid /-! # Structure of finite(ly generated) abelian groups * `add_comm_group.equiv_free_prod_direct_sum_zmod` : Any finitely generated abelian group is the product of a power of `ℤ` and a direct sum of some `zmod (p i ^ e i)` for some prime powers `p i ^ e i`. * `add_comm_group.equiv_direct_sum_zmod_of_fintype` : Any finite abelian group is a direct sum of some `zmod (p i ^ e i)` for some prime powers `p i ^ e i`. -/ open_locale direct_sum namespace add_comm_group /-- **Structure theorem of finitely generated abelian groups** : Any finitely generated abelian group is the product of a power of `ℤ` and a direct sum of some `zmod (p i ^ e i)` for some prime powers `p i ^ e i`.-/ theorem equiv_free_prod_direct_sum_zmod (G : Type*) [add_comm_group G] [hG : add_group.fg G] : ∃ (n : ℕ) (ι : Type) [fintype ι] (p : ι → ℕ) [∀ i, nat.prime $ p i] (e : ι → ℕ), nonempty $ G ≃+ (fin n →₀ ℤ) × ⨁ (i : ι), zmod (p i ^ e i) := begin obtain ⟨n, ι, fι, p, hp, e, ⟨f⟩⟩ := @module.equiv_free_prod_direct_sum _ _ _ _ _ _ _ (module.finite.iff_add_group_fg.mpr hG), refine ⟨n, ι, fι, λ i, (p i).nat_abs, λ i, _, e, ⟨_⟩⟩, { rw [← int.prime_iff_nat_abs_prime, ← gcd_monoid.irreducible_iff_prime], exact hp i }, exact f.to_add_equiv.trans ((add_equiv.refl _).prod_congr $ dfinsupp.map_range.add_equiv $ λ i, ((int.quotient_span_equiv_zmod _).trans $ zmod.ring_equiv_congr $ (p i).nat_abs_pow _).to_add_equiv) end /-- **Structure theorem of finite abelian groups** : Any finite abelian group is a direct sum of some `zmod (p i ^ e i)` for some prime powers `p i ^ e i`.-/ theorem equiv_direct_sum_zmod_of_fintype (G : Type*) [add_comm_group G] [fintype G] : ∃ (ι : Type) [fintype ι] (p : ι → ℕ) [∀ i, nat.prime $ p i] (e : ι → ℕ), nonempty $ G ≃+ ⨁ (i : ι), zmod (p i ^ e i) := begin obtain ⟨n, ι, fι, p, hp, e, ⟨f⟩⟩ := equiv_free_prod_direct_sum_zmod G, cases n, { exact ⟨ι, fι, p, hp, e, ⟨f.trans add_equiv.unique_prod⟩⟩ }, { haveI := @fintype.prod_left _ _ _ (fintype.of_equiv G f.to_equiv) _, exact (fintype.of_surjective (λ f : fin n.succ →₀ ℤ, f 0) $ λ a, ⟨finsupp.single 0 a, finsupp.single_eq_same⟩).false.elim } end end add_comm_group
4916c4ceb62306e649c436f6563eb77c88117175
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/geometry/euclidean/sphere/ptolemy.lean
bb988789b77876cf18d520afb85f9511a8478f12
[ "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,531
lean
/- Copyright (c) 2021 Manuel Candales. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Manuel Candales, Benjamin Davidson -/ import geometry.euclidean.sphere.power import geometry.euclidean.triangle /-! # Ptolemy's theorem > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file proves Ptolemy's theorem on the lengths of the diagonals and sides of a cyclic quadrilateral. ## Main theorems * `mul_dist_add_mul_dist_eq_mul_dist_of_cospherical`: Ptolemy’s Theorem (Freek No. 95). TODO: The current statement of Ptolemy’s theorem works around the lack of a "cyclic polygon" concept in mathlib, which is what the theorem statement would naturally use (or two such concepts, since both a strict version, where all vertices must be distinct, and a weak version, where consecutive vertices may be equal, would be useful; Ptolemy's theorem should then use the weak one). An API needs to be built around that concept, which would include: - strict cyclic implies weak cyclic, - weak cyclic and consecutive points distinct implies strict cyclic, - weak/strict cyclic implies weak/strict cyclic for any subsequence, - any three points on a sphere are weakly or strictly cyclic according to whether they are distinct, - any number of points on a sphere intersected with a two-dimensional affine subspace are cyclic in some order, - a list of points is cyclic if and only if its reversal is, - a list of points is cyclic if and only if any cyclic permutation is, while other permutations are not when the points are distinct, - a point P where the diagonals of a cyclic polygon cross exists (and is unique) with weak/strict betweenness depending on weak/strict cyclicity, - four points on a sphere with such a point P are cyclic in the appropriate order, and so on. -/ open real open_locale euclidean_geometry real_inner_product_space real namespace euclidean_geometry variables {V : Type*} [normed_add_comm_group V] [inner_product_space ℝ V] variables {P : Type*} [metric_space P] [normed_add_torsor V P] include V /-- **Ptolemy’s Theorem**. -/ theorem mul_dist_add_mul_dist_eq_mul_dist_of_cospherical {a b c d p : P} (h : cospherical ({a, b, c, d} : set P)) (hapc : ∠ a p c = π) (hbpd : ∠ b p d = π) : dist a b * dist c d + dist b c * dist d a = dist a c * dist b d := begin have h' : cospherical ({a, c, b, d} : set P), { rwa set.insert_comm c b {d} }, have hmul := mul_dist_eq_mul_dist_of_cospherical_of_angle_eq_pi h' hapc hbpd, have hbp := left_dist_ne_zero_of_angle_eq_pi hbpd, have h₁ : dist c d = dist c p / dist b p * dist a b, { rw [dist_mul_of_eq_angle_of_dist_mul b p a c p d, dist_comm a b], { rw [angle_eq_angle_of_angle_eq_pi_of_angle_eq_pi hbpd hapc, angle_comm] }, all_goals { field_simp [mul_comm, hmul] } }, have h₂ : dist d a = dist a p / dist b p * dist b c, { rw [dist_mul_of_eq_angle_of_dist_mul c p b d p a, dist_comm c b], { rwa [angle_comm, angle_eq_angle_of_angle_eq_pi_of_angle_eq_pi], rwa angle_comm }, all_goals { field_simp [mul_comm, hmul] } }, have h₃ : dist d p = dist a p * dist c p / dist b p, { field_simp [mul_comm, hmul] }, have h₄ : ∀ x y : ℝ, x * (y * x) = x * x * y := λ x y, by rw [mul_left_comm, mul_comm], field_simp [h₁, h₂, dist_eq_add_dist_of_angle_eq_pi hbpd, h₃, hbp, dist_comm a b, h₄, ← sq, dist_sq_mul_dist_add_dist_sq_mul_dist b, hapc], end end euclidean_geometry
bebec321f0508c32a5493896e88a2b0fd64e1d64
b7f22e51856f4989b970961f794f1c435f9b8f78
/hott/algebra/category/nat_trans.hlean
4c631bf9b30761c54db5025dcff326fe48cd747d
[ "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
7,870
hlean
/- Copyright (c) 2015 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Floris van Doorn, Jakob von Raumer -/ import .functor.basic open eq category functor is_trunc equiv sigma.ops sigma is_equiv function pi funext iso structure nat_trans {C : Precategory} {D : Precategory} (F G : C ⇒ D) : Type := (natural_map : Π (a : C), hom (F a) (G a)) (naturality : Π {a b : C} (f : hom a b), G f ∘ natural_map a = natural_map b ∘ F f) namespace nat_trans infixl ` ⟹ `:25 := nat_trans -- \==> variables {B C D E : Precategory} {F G H I : C ⇒ D} {F' G' : D ⇒ E} {F'' G'' : E ⇒ B} {J : C ⇒ C} attribute natural_map [coercion] protected definition compose [constructor] (η : G ⟹ H) (θ : F ⟹ G) : F ⟹ H := nat_trans.mk (λ a, η a ∘ θ a) (λ a b f, abstract calc H f ∘ (η a ∘ θ a) = (H f ∘ η a) ∘ θ a : by rewrite assoc ... = (η b ∘ G f) ∘ θ a : by rewrite naturality ... = η b ∘ (G f ∘ θ a) : by rewrite assoc ... = η b ∘ (θ b ∘ F f) : by rewrite naturality ... = (η b ∘ θ b) ∘ F f : by rewrite assoc end) infixr ` ∘n `:60 := nat_trans.compose definition compose_def (η : G ⟹ H) (θ : F ⟹ G) (c : C) : (η ∘n θ) c = η c ∘ θ c := idp protected definition id [reducible] [constructor] {F : C ⇒ D} : nat_trans F F := mk (λa, id) (λa b f, !id_right ⬝ !id_left⁻¹) protected definition ID [reducible] [constructor] (F : C ⇒ D) : nat_trans F F := (@nat_trans.id C D F) notation 1 := nat_trans.id definition constant_nat_trans [constructor] (C : Precategory) {D : Precategory} {d d' : D} (g : d ⟶ d') : constant_functor C d ⟹ constant_functor C d' := mk (λc, g) (λc c' f, !id_comp_eq_comp_id) open iso definition naturality_iso_left (η : F ⟹ G) {a b : C} (f : a ≅ b) : η a = (G f)⁻¹ ∘ η b ∘ F f := by apply eq_inverse_comp_of_comp_eq; apply naturality definition naturality_iso_right (η : F ⟹ G) {a b : C} (f : a ≅ b) : η b = G f ∘ η a ∘ (F f)⁻¹ := by refine _⁻¹ ⬝ !assoc⁻¹; apply comp_inverse_eq_of_eq_comp; apply naturality definition nat_trans_mk_eq {η₁ η₂ : Π (a : C), hom (F a) (G a)} (nat₁ : Π (a b : C) (f : hom a b), G f ∘ η₁ a = η₁ b ∘ F f) (nat₂ : Π (a b : C) (f : hom a b), G f ∘ η₂ a = η₂ b ∘ F f) (p : η₁ ~ η₂) : nat_trans.mk η₁ nat₁ = nat_trans.mk η₂ nat₂ := apd011 nat_trans.mk (eq_of_homotopy p) !is_prop.elimo definition nat_trans_eq {η₁ η₂ : F ⟹ G} : natural_map η₁ ~ natural_map η₂ → η₁ = η₂ := by induction η₁; induction η₂; apply nat_trans_mk_eq protected definition assoc (η₃ : H ⟹ I) (η₂ : G ⟹ H) (η₁ : F ⟹ G) : η₃ ∘n (η₂ ∘n η₁) = (η₃ ∘n η₂) ∘n η₁ := nat_trans_eq (λa, !assoc) protected definition id_left (η : F ⟹ G) : 1 ∘n η = η := nat_trans_eq (λa, !id_left) protected definition id_right (η : F ⟹ G) : η ∘n 1 = η := nat_trans_eq (λa, !id_right) protected definition sigma_char (F G : C ⇒ D) : (Σ (η : Π (a : C), hom (F a) (G a)), Π (a b : C) (f : hom a b), G f ∘ η a = η b ∘ F f) ≃ (F ⟹ G) := begin fapply equiv.mk, -- TODO(Leo): investigate why we need to use rexact in the following line {intro S, apply nat_trans.mk, rexact (S.2)}, fapply adjointify, intro H, fapply sigma.mk, intro a, exact (H a), intro a b f, exact (naturality H f), intro η, apply nat_trans_eq, intro a, apply idp, intro S, fapply sigma_eq, { apply eq_of_homotopy, intro a, apply idp}, { apply is_prop.elimo} end definition is_set_nat_trans [instance] : is_set (F ⟹ G) := by apply is_trunc_is_equiv_closed; apply (equiv.to_is_equiv !nat_trans.sigma_char) definition change_natural_map [constructor] (η : F ⟹ G) (f : Π (a : C), F a ⟶ G a) (p : Πa, η a = f a) : F ⟹ G := nat_trans.mk f (λa b g, p a ▸ p b ▸ naturality η g) definition nat_trans_functor_compose [constructor] (η : G ⟹ H) (F : E ⇒ C) : G ∘f F ⟹ H ∘f F := nat_trans.mk (λ a, η (F a)) (λ a b f, naturality η (F f)) definition functor_nat_trans_compose [constructor] (F : D ⇒ E) (η : G ⟹ H) : F ∘f G ⟹ F ∘f H := nat_trans.mk (λ a, F (η a)) (λ a b f, calc F (H f) ∘ F (η a) = F (H f ∘ η a) : by rewrite respect_comp ... = F (η b ∘ G f) : by rewrite (naturality η f) ... = F (η b) ∘ F (G f) : by rewrite respect_comp) definition nat_trans_id_functor_compose [constructor] (η : J ⟹ 1) (F : E ⇒ C) : J ∘f F ⟹ F := nat_trans.mk (λ a, η (F a)) (λ a b f, naturality η (F f)) definition id_nat_trans_functor_compose [constructor] (η : 1 ⟹ J) (F : E ⇒ C) : F ⟹ J ∘f F := nat_trans.mk (λ a, η (F a)) (λ a b f, naturality η (F f)) definition functor_nat_trans_id_compose [constructor] (F : C ⇒ D) (η : J ⟹ 1) : F ∘f J ⟹ F := nat_trans.mk (λ a, F (η a)) (λ a b f, calc F f ∘ F (η a) = F (f ∘ η a) : by rewrite respect_comp ... = F (η b ∘ J f) : by rewrite (naturality η f) ... = F (η b) ∘ F (J f) : by rewrite respect_comp) definition functor_id_nat_trans_compose [constructor] (F : C ⇒ D) (η : 1 ⟹ J) : F ⟹ F ∘f J := nat_trans.mk (λ a, F (η a)) (λ a b f, calc F (J f) ∘ F (η a) = F (J f ∘ η a) : by rewrite respect_comp ... = F (η b ∘ f) : by rewrite (naturality η f) ... = F (η b) ∘ F f : by rewrite respect_comp) infixr ` ∘nf ` :62 := nat_trans_functor_compose infixr ` ∘fn ` :62 := functor_nat_trans_compose infixr ` ∘n1f `:62 := nat_trans_id_functor_compose infixr ` ∘1nf `:62 := id_nat_trans_functor_compose infixr ` ∘f1n `:62 := functor_id_nat_trans_compose infixr ` ∘fn1 `:62 := functor_nat_trans_id_compose definition nf_fn_eq_fn_nf_pt (η : F ⟹ G) (θ : F' ⟹ G') (c : C) : (θ (G c)) ∘ (F' (η c)) = (G' (η c)) ∘ (θ (F c)) := (naturality θ (η c))⁻¹ variable (F') definition nf_fn_eq_fn_nf_pt' (η : F ⟹ G) (θ : F'' ⟹ G'') (c : C) : (θ (F' (G c))) ∘ (F'' (F' (η c))) = (G'' (F' (η c))) ∘ (θ (F' (F c))) := (naturality θ (F' (η c)))⁻¹ variable {F'} definition nf_fn_eq_fn_nf (η : F ⟹ G) (θ : F' ⟹ G') : (θ ∘nf G) ∘n (F' ∘fn η) = (G' ∘fn η) ∘n (θ ∘nf F) := nat_trans_eq (λ c, nf_fn_eq_fn_nf_pt η θ c) definition fn_n_distrib (F' : D ⇒ E) (η : G ⟹ H) (θ : F ⟹ G) : F' ∘fn (η ∘n θ) = (F' ∘fn η) ∘n (F' ∘fn θ) := nat_trans_eq (λc, by apply respect_comp) definition n_nf_distrib (η : G ⟹ H) (θ : F ⟹ G) (F' : B ⇒ C) : (η ∘n θ) ∘nf F' = (η ∘nf F') ∘n (θ ∘nf F') := nat_trans_eq (λc, idp) definition fn_id (F' : D ⇒ E) : F' ∘fn nat_trans.ID F = 1 := nat_trans_eq (λc, by apply respect_id) definition id_nf (F' : B ⇒ C) : nat_trans.ID F ∘nf F' = 1 := nat_trans_eq (λc, idp) definition id_fn (η : G ⟹ H) (c : C) : (1 ∘fn η) c = η c := idp definition nf_id (η : G ⟹ H) (c : C) : (η ∘nf 1) c = η c := idp definition nat_trans_of_eq [reducible] [constructor] (p : F = G) : F ⟹ G := nat_trans.mk (λc, hom_of_eq (ap010 to_fun_ob p c)) (λa b f, eq.rec_on p (!id_right ⬝ !id_left⁻¹)) definition compose_rev [unfold_full] (θ : F ⟹ G) (η : G ⟹ H) : F ⟹ H := η ∘n θ end nat_trans attribute nat_trans.compose_rev [trans] attribute nat_trans.id [refl]
d4e72c78a97bfdeeca3322df3d229ac53b021c3d
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/geometry/euclidean/angle/oriented/right_angle.lean
b38ec3b422bf26559d9525e79b248afdabd1b10b
[ "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
45,701
lean
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import geometry.euclidean.angle.oriented.affine import geometry.euclidean.angle.unoriented.right_angle /-! # Oriented angles in right-angled triangles. > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file proves basic geometrical results about distances and oriented angles in (possibly degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces. -/ noncomputable theory open_locale euclidean_geometry open_locale real open_locale real_inner_product_space namespace orientation open finite_dimensional variables {V : Type*} [normed_add_comm_group V] [inner_product_space ℝ V] variables [hd2 : fact (finrank ℝ V = 2)] (o : orientation ℝ V (fin 2)) include hd2 o /-- An angle in a right-angled triangle expressed using `arccos`. -/ lemma oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = real.arccos (‖x‖ / ‖x + y‖) := begin have hs : (o.oangle x (x + y)).sign = 1, { rw [oangle_sign_add_right, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, inner_product_geometry.angle_add_eq_arccos_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] end /-- An angle in a right-angled triangle expressed using `arccos`. -/ lemma oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = real.arccos (‖y‖ / ‖x + y‖) := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, rw add_comm, exact (-o).oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two h end /-- An angle in a right-angled triangle expressed using `arcsin`. -/ lemma oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = real.arcsin (‖y‖ / ‖x + y‖) := begin have hs : (o.oangle x (x + y)).sign = 1, { rw [oangle_sign_add_right, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, inner_product_geometry.angle_add_eq_arcsin_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] end /-- An angle in a right-angled triangle expressed using `arcsin`. -/ lemma oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = real.arcsin (‖x‖ / ‖x + y‖) := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, rw add_comm, exact (-o).oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two h end /-- An angle in a right-angled triangle expressed using `arctan`. -/ lemma oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = real.arctan (‖y‖ / ‖x‖) := begin have hs : (o.oangle x (x + y)).sign = 1, { rw [oangle_sign_add_right, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, inner_product_geometry.angle_add_eq_arctan_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (o.left_ne_zero_of_oangle_eq_pi_div_two h)] end /-- An angle in a right-angled triangle expressed using `arctan`. -/ lemma oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = real.arctan (‖x‖ / ‖y‖) := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, rw add_comm, exact (-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two h end /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ lemma cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.cos (o.oangle x (x + y)) = ‖x‖ / ‖x + y‖ := begin have hs : (o.oangle x (x + y)).sign = 1, { rw [oangle_sign_add_right, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.cos_coe, inner_product_geometry.cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] end /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ lemma cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.cos (o.oangle (x + y) y) = ‖y‖ / ‖x + y‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, rw add_comm, exact (-o).cos_oangle_add_right_of_oangle_eq_pi_div_two h end /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ lemma sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.sin (o.oangle x (x + y)) = ‖y‖ / ‖x + y‖ := begin have hs : (o.oangle x (x + y)).sign = 1, { rw [oangle_sign_add_right, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.sin_coe, inner_product_geometry.sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] end /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ lemma sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.sin (o.oangle (x + y) y) = ‖x‖ / ‖x + y‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, rw add_comm, exact (-o).sin_oangle_add_right_of_oangle_eq_pi_div_two h end /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ lemma tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.tan (o.oangle x (x + y)) = ‖y‖ / ‖x‖ := begin have hs : (o.oangle x (x + y)).sign = 1, { rw [oangle_sign_add_right, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.tan_coe, inner_product_geometry.tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] end /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ lemma tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.tan (o.oangle (x + y) y) = ‖x‖ / ‖y‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, rw add_comm, exact (-o).tan_oangle_add_right_of_oangle_eq_pi_div_two h end /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ lemma cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.cos (o.oangle x (x + y)) * ‖x + y‖ = ‖x‖ := begin have hs : (o.oangle x (x + y)).sign = 1, { rw [oangle_sign_add_right, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.cos_coe, inner_product_geometry.cos_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] end /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ lemma cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.cos (o.oangle (x + y) y) * ‖x + y‖ = ‖y‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, rw add_comm, exact (-o).cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h end /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ lemma sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.sin (o.oangle x (x + y)) * ‖x + y‖ = ‖y‖ := begin have hs : (o.oangle x (x + y)).sign = 1, { rw [oangle_sign_add_right, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.sin_coe, inner_product_geometry.sin_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] end /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ lemma sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.sin (o.oangle (x + y) y) * ‖x + y‖ = ‖x‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, rw add_comm, exact (-o).sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h end /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ lemma tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.tan (o.oangle x (x + y)) * ‖x‖ = ‖y‖ := begin have hs : (o.oangle x (x + y)).sign = 1, { rw [oangle_sign_add_right, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.tan_coe, inner_product_geometry.tan_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] end /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ lemma tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.tan (o.oangle (x + y) y) * ‖y‖ = ‖x‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, rw add_comm, exact (-o).tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h end /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ lemma norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / real.angle.cos (o.oangle x (x + y)) = ‖x + y‖ := begin have hs : (o.oangle x (x + y)).sign = 1, { rw [oangle_sign_add_right, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.cos_coe, inner_product_geometry.norm_div_cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] end /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ lemma norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / real.angle.cos (o.oangle (x + y) y) = ‖x + y‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, rw add_comm, exact (-o).norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two h end /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ lemma norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / real.angle.sin (o.oangle x (x + y)) = ‖x + y‖ := begin have hs : (o.oangle x (x + y)).sign = 1, { rw [oangle_sign_add_right, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.sin_coe, inner_product_geometry.norm_div_sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))] end /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ lemma norm_div_sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / real.angle.sin (o.oangle (x + y) y) = ‖x + y‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, rw add_comm, exact (-o).norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two h end /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ lemma norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / real.angle.tan (o.oangle x (x + y)) = ‖x‖ := begin have hs : (o.oangle x (x + y)).sign = 1, { rw [oangle_sign_add_right, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.tan_coe, inner_product_geometry.norm_div_tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))] end /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ lemma norm_div_tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / real.angle.tan (o.oangle (x + y) y) = ‖y‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, rw add_comm, exact (-o).norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two h end /-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/ lemma oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle y (y - x) = real.arccos (‖y‖ / ‖y - x‖) := begin have hs : (o.oangle y (y - x)).sign = 1, { rw [oangle_sign_sub_right_swap, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, inner_product_geometry.angle_sub_eq_arccos_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] end /-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/ lemma oangle_sub_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x - y) x = real.arccos (‖x‖ / ‖x - y‖) := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, exact (-o).oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two h end /-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/ lemma oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle y (y - x) = real.arcsin (‖x‖ / ‖y - x‖) := begin have hs : (o.oangle y (y - x)).sign = 1, { rw [oangle_sign_sub_right_swap, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, inner_product_geometry.angle_sub_eq_arcsin_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))] end /-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/ lemma oangle_sub_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x - y) x = real.arcsin (‖y‖ / ‖x - y‖) := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, exact (-o).oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two h end /-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/ lemma oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle y (y - x) = real.arctan (‖x‖ / ‖y‖) := begin have hs : (o.oangle y (y - x)).sign = 1, { rw [oangle_sign_sub_right_swap, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, inner_product_geometry.angle_sub_eq_arctan_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (o.right_ne_zero_of_oangle_eq_pi_div_two h)] end /-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/ lemma oangle_sub_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x - y) x = real.arctan (‖y‖ / ‖x‖) := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, exact (-o).oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two h end /-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ lemma cos_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.cos (o.oangle y (y - x)) = ‖y‖ / ‖y - x‖ := begin have hs : (o.oangle y (y - x)).sign = 1, { rw [oangle_sign_sub_right_swap, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.cos_coe, inner_product_geometry.cos_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] end /-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ lemma cos_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.cos (o.oangle (x - y) x) = ‖x‖ / ‖x - y‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, exact (-o).cos_oangle_sub_right_of_oangle_eq_pi_div_two h end /-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ lemma sin_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.sin (o.oangle y (y - x)) = ‖x‖ / ‖y - x‖ := begin have hs : (o.oangle y (y - x)).sign = 1, { rw [oangle_sign_sub_right_swap, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.sin_coe, inner_product_geometry.sin_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))] end /-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ lemma sin_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.sin (o.oangle (x - y) x) = ‖y‖ / ‖x - y‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, exact (-o).sin_oangle_sub_right_of_oangle_eq_pi_div_two h end /-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ lemma tan_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.tan (o.oangle y (y - x)) = ‖x‖ / ‖y‖ := begin have hs : (o.oangle y (y - x)).sign = 1, { rw [oangle_sign_sub_right_swap, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.tan_coe, inner_product_geometry.tan_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] end /-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ lemma tan_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.tan (o.oangle (x - y) x) = ‖y‖ / ‖x‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, exact (-o).tan_oangle_sub_right_of_oangle_eq_pi_div_two h end /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side, version subtracting vectors. -/ lemma cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.cos (o.oangle y (y - x)) * ‖y - x‖ = ‖y‖ := begin have hs : (o.oangle y (y - x)).sign = 1, { rw [oangle_sign_sub_right_swap, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.cos_coe, inner_product_geometry.cos_angle_sub_mul_norm_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] end /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side, version subtracting vectors. -/ lemma cos_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.cos (o.oangle (x - y) x) * ‖x - y‖ = ‖x‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, exact (-o).cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h end /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side, version subtracting vectors. -/ lemma sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.sin (o.oangle y (y - x)) * ‖y - x‖ = ‖x‖ := begin have hs : (o.oangle y (y - x)).sign = 1, { rw [oangle_sign_sub_right_swap, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.sin_coe, inner_product_geometry.sin_angle_sub_mul_norm_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] end /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side, version subtracting vectors. -/ lemma sin_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.sin (o.oangle (x - y) x) * ‖x - y‖ = ‖y‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, exact (-o).sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h end /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side, version subtracting vectors. -/ lemma tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.tan (o.oangle y (y - x)) * ‖y‖ = ‖x‖ := begin have hs : (o.oangle y (y - x)).sign = 1, { rw [oangle_sign_sub_right_swap, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.tan_coe, inner_product_geometry.tan_angle_sub_mul_norm_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))] end /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side, version subtracting vectors. -/ lemma tan_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : real.angle.tan (o.oangle (x - y) x) * ‖x‖ = ‖y‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, exact (-o).tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h end /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse, version subtracting vectors. -/ lemma norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / real.angle.cos (o.oangle y (y - x)) = ‖y - x‖ := begin have hs : (o.oangle y (y - x)).sign = 1, { rw [oangle_sign_sub_right_swap, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.cos_coe, inner_product_geometry.norm_div_cos_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))] end /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse, version subtracting vectors. -/ lemma norm_div_cos_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / real.angle.cos (o.oangle (x - y) x) = ‖x - y‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, exact (-o).norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two h end /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse, version subtracting vectors. -/ lemma norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / real.angle.sin (o.oangle y (y - x)) = ‖y - x‖ := begin have hs : (o.oangle y (y - x)).sign = 1, { rw [oangle_sign_sub_right_swap, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.sin_coe, inner_product_geometry.norm_div_sin_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (or.inr (o.left_ne_zero_of_oangle_eq_pi_div_two h))] end /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse, version subtracting vectors. -/ lemma norm_div_sin_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / real.angle.sin (o.oangle (x - y) x) = ‖x - y‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, exact (-o).norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two h end /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side, version subtracting vectors. -/ lemma norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / real.angle.tan (o.oangle y (y - x)) = ‖y‖ := begin have hs : (o.oangle y (y - x)).sign = 1, { rw [oangle_sign_sub_right_swap, h, real.angle.sign_coe_pi_div_two] }, rw [o.oangle_eq_angle_of_sign_eq_one hs, real.angle.tan_coe, inner_product_geometry.norm_div_tan_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (or.inr (o.left_ne_zero_of_oangle_eq_pi_div_two h))] end /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side, version subtracting vectors. -/ lemma norm_div_tan_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / real.angle.tan (o.oangle (x - y) x) = ‖x‖ := begin rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj] at h ⊢, exact (-o).norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two h end /-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple of a rotation of another by `π / 2`. -/ lemma oangle_add_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : o.oangle x (x + r • o.rotation (π / 2 : ℝ) x) = real.arctan r := begin rcases lt_trichotomy r 0 with hr | rfl | hr, { have ha : o.oangle x (r • o.rotation (π / 2 : ℝ) x) = -(π / 2 : ℝ), { rw [o.oangle_smul_right_of_neg _ _ hr, o.oangle_neg_right h, o.oangle_rotation_self_right h, ←sub_eq_zero, add_comm, sub_neg_eq_add, ←real.angle.coe_add, ←real.angle.coe_add, add_assoc, add_halves, ←two_mul, real.angle.coe_two_pi], simpa using h }, rw [←neg_inj, ←oangle_neg_orientation_eq_neg, neg_neg] at ha, rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj, oangle_rev, (-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two ha, norm_smul, linear_isometry_equiv.norm_map, mul_div_assoc, div_self (norm_ne_zero_iff.2 h), mul_one, real.norm_eq_abs, abs_of_neg hr, real.arctan_neg, real.angle.coe_neg, neg_neg] }, { rw [zero_smul, add_zero, oangle_self, real.arctan_zero, real.angle.coe_zero] }, { have ha : o.oangle x (r • o.rotation (π / 2 : ℝ) x) = (π / 2 : ℝ), { rw [o.oangle_smul_right_of_pos _ _ hr, o.oangle_rotation_self_right h] }, rw [o.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two ha, norm_smul, linear_isometry_equiv.norm_map, mul_div_assoc, div_self (norm_ne_zero_iff.2 h), mul_one, real.norm_eq_abs, abs_of_pos hr] } end /-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple of a rotation of another by `π / 2`. -/ lemma oangle_add_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : o.oangle (x + r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x) = real.arctan r⁻¹ := begin by_cases hr : r = 0, { simp [hr] }, rw [←neg_inj, oangle_rev, ←oangle_neg_orientation_eq_neg, neg_inj, ←neg_neg ((π / 2 : ℝ) : real.angle), ←rotation_neg_orientation_eq_neg, add_comm], have hx : x = r⁻¹ • ((-o).rotation (π / 2 : ℝ) (r • ((-o).rotation (-(π / 2 : ℝ)) x))), { simp [hr] }, nth_rewrite 2 hx, refine (-o).oangle_add_right_smul_rotation_pi_div_two _ _, simp [hr, h] end /-- The tangent of an angle in a right-angled triangle, where one side is a multiple of a rotation of another by `π / 2`. -/ lemma tan_oangle_add_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : real.angle.tan (o.oangle x (x + r • o.rotation (π / 2 : ℝ) x)) = r := by rw [o.oangle_add_right_smul_rotation_pi_div_two h, real.angle.tan_coe, real.tan_arctan] /-- The tangent of an angle in a right-angled triangle, where one side is a multiple of a rotation of another by `π / 2`. -/ lemma tan_oangle_add_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : real.angle.tan (o.oangle (x + r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x)) = r⁻¹ := by rw [o.oangle_add_left_smul_rotation_pi_div_two h, real.angle.tan_coe, real.tan_arctan] /-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple of a rotation of another by `π / 2`, version subtracting vectors. -/ lemma oangle_sub_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : o.oangle (r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x - x) = real.arctan r⁻¹ := begin by_cases hr : r = 0, { simp [hr] }, have hx : -x = r⁻¹ • (o.rotation (π / 2 : ℝ) (r • (o.rotation (π / 2 : ℝ) x))), { simp [hr, ←real.angle.coe_add] }, rw [sub_eq_add_neg, hx, o.oangle_add_right_smul_rotation_pi_div_two], simpa [hr] using h end /-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple of a rotation of another by `π / 2`, version subtracting vectors. -/ lemma oangle_sub_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : o.oangle (x - r • o.rotation (π / 2 : ℝ) x) x = real.arctan r := begin by_cases hr : r = 0, { simp [hr] }, have hx : x = r⁻¹ • (o.rotation (π / 2 : ℝ) (-(r • (o.rotation (π / 2 : ℝ) x)))), { simp [hr, ←real.angle.coe_add] }, rw [sub_eq_add_neg, add_comm], nth_rewrite 2 hx, nth_rewrite 1 hx, rw [o.oangle_add_left_smul_rotation_pi_div_two, inv_inv], simpa [hr] using h end end orientation namespace euclidean_geometry open finite_dimensional variables {V : Type*} {P : Type*} [normed_add_comm_group V] [inner_product_space ℝ V] [metric_space P] [normed_add_torsor V P] [hd2 : fact (finrank ℝ V = 2)] [module.oriented ℝ V (fin 2)] include hd2 /-- An angle in a right-angled triangle expressed using `arccos`. -/ lemma oangle_right_eq_arccos_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₂ p₃ p₁ = real.arccos (dist p₃ p₂ / dist p₁ p₃) := begin have hs : (∡ p₂ p₃ p₁).sign = 1, { rw [oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_eq_arccos_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] end /-- An angle in a right-angled triangle expressed using `arccos`. -/ lemma oangle_left_eq_arccos_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₃ p₁ p₂ = real.arccos (dist p₁ p₂ / dist p₁ p₃) := begin have hs : (∡ p₃ p₁ p₂).sign = 1, { rw [←oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, angle_eq_arccos_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h), dist_comm p₁ p₃] end /-- An angle in a right-angled triangle expressed using `arcsin`. -/ lemma oangle_right_eq_arcsin_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₂ p₃ p₁ = real.arcsin (dist p₁ p₂ / dist p₁ p₃) := begin have hs : (∡ p₂ p₃ p₁).sign = 1, { rw [oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_eq_arcsin_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (or.inl (left_ne_of_oangle_eq_pi_div_two h))] end /-- An angle in a right-angled triangle expressed using `arcsin`. -/ lemma oangle_left_eq_arcsin_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₃ p₁ p₂ = real.arcsin (dist p₃ p₂ / dist p₁ p₃) := begin have hs : (∡ p₃ p₁ p₂).sign = 1, { rw [←oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, angle_eq_arcsin_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (or.inr (left_ne_of_oangle_eq_pi_div_two h)), dist_comm p₁ p₃] end /-- An angle in a right-angled triangle expressed using `arctan`. -/ lemma oangle_right_eq_arctan_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₂ p₃ p₁ = real.arctan (dist p₁ p₂ / dist p₃ p₂) := begin have hs : (∡ p₂ p₃ p₁).sign = 1, { rw [oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_eq_arctan_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (right_ne_of_oangle_eq_pi_div_two h)] end /-- An angle in a right-angled triangle expressed using `arctan`. -/ lemma oangle_left_eq_arctan_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₃ p₁ p₂ = real.arctan (dist p₃ p₂ / dist p₁ p₂) := begin have hs : (∡ p₃ p₁ p₂).sign = 1, { rw [←oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, angle_eq_arctan_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (left_ne_of_oangle_eq_pi_div_two h)] end /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ lemma cos_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : real.angle.cos (∡ p₂ p₃ p₁) = dist p₃ p₂ / dist p₁ p₃ := begin have hs : (∡ p₂ p₃ p₁).sign = 1, { rw [oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, real.angle.cos_coe, cos_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] end /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ lemma cos_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : real.angle.cos (∡ p₃ p₁ p₂) = dist p₁ p₂ / dist p₁ p₃ := begin have hs : (∡ p₃ p₁ p₂).sign = 1, { rw [←oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, real.angle.cos_coe, cos_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h), dist_comm p₁ p₃] end /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ lemma sin_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : real.angle.sin (∡ p₂ p₃ p₁) = dist p₁ p₂ / dist p₁ p₃ := begin have hs : (∡ p₂ p₃ p₁).sign = 1, { rw [oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, real.angle.sin_coe, sin_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (or.inl (left_ne_of_oangle_eq_pi_div_two h))] end /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ lemma sin_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : real.angle.sin (∡ p₃ p₁ p₂) = dist p₃ p₂ / dist p₁ p₃ := begin have hs : (∡ p₃ p₁ p₂).sign = 1, { rw [←oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, real.angle.sin_coe, sin_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (or.inr (left_ne_of_oangle_eq_pi_div_two h)), dist_comm p₁ p₃] end /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ lemma tan_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : real.angle.tan (∡ p₂ p₃ p₁) = dist p₁ p₂ / dist p₃ p₂ := begin have hs : (∡ p₂ p₃ p₁).sign = 1, { rw [oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, real.angle.tan_coe, tan_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] end /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ lemma tan_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : real.angle.tan (∡ p₃ p₁ p₂) = dist p₃ p₂ / dist p₁ p₂ := begin have hs : (∡ p₃ p₁ p₂).sign = 1, { rw [←oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, real.angle.tan_coe, tan_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)] end /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ lemma cos_oangle_right_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : real.angle.cos (∡ p₂ p₃ p₁) * dist p₁ p₃ = dist p₃ p₂ := begin have hs : (∡ p₂ p₃ p₁).sign = 1, { rw [oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, real.angle.cos_coe, cos_angle_mul_dist_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] end /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ lemma cos_oangle_left_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : real.angle.cos (∡ p₃ p₁ p₂) * dist p₁ p₃ = dist p₁ p₂ := begin have hs : (∡ p₃ p₁ p₂).sign = 1, { rw [←oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, real.angle.cos_coe, dist_comm p₁ p₃, cos_angle_mul_dist_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)] end /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ lemma sin_oangle_right_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : real.angle.sin (∡ p₂ p₃ p₁) * dist p₁ p₃ = dist p₁ p₂ := begin have hs : (∡ p₂ p₃ p₁).sign = 1, { rw [oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, real.angle.sin_coe, sin_angle_mul_dist_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] end /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ lemma sin_oangle_left_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : real.angle.sin (∡ p₃ p₁ p₂) * dist p₁ p₃ = dist p₃ p₂ := begin have hs : (∡ p₃ p₁ p₂).sign = 1, { rw [←oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, real.angle.sin_coe, dist_comm p₁ p₃, sin_angle_mul_dist_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)] end /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ lemma tan_oangle_right_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : real.angle.tan (∡ p₂ p₃ p₁) * dist p₃ p₂ = dist p₁ p₂ := begin have hs : (∡ p₂ p₃ p₁).sign = 1, { rw [oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, real.angle.tan_coe, tan_angle_mul_dist_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (or.inr (right_ne_of_oangle_eq_pi_div_two h))] end /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ lemma tan_oangle_left_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : real.angle.tan (∡ p₃ p₁ p₂) * dist p₁ p₂ = dist p₃ p₂ := begin have hs : (∡ p₃ p₁ p₂).sign = 1, { rw [←oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, real.angle.tan_coe, tan_angle_mul_dist_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (or.inr (left_ne_of_oangle_eq_pi_div_two h))] end /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ lemma dist_div_cos_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₃ p₂ / real.angle.cos (∡ p₂ p₃ p₁) = dist p₁ p₃ := begin have hs : (∡ p₂ p₃ p₁).sign = 1, { rw [oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, real.angle.cos_coe, dist_div_cos_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (or.inr (right_ne_of_oangle_eq_pi_div_two h))] end /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ lemma dist_div_cos_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₁ p₂ / real.angle.cos (∡ p₃ p₁ p₂) = dist p₁ p₃ := begin have hs : (∡ p₃ p₁ p₂).sign = 1, { rw [←oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, real.angle.cos_coe, dist_comm p₁ p₃, dist_div_cos_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (or.inr (left_ne_of_oangle_eq_pi_div_two h))] end /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ lemma dist_div_sin_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₁ p₂ / real.angle.sin (∡ p₂ p₃ p₁) = dist p₁ p₃ := begin have hs : (∡ p₂ p₃ p₁).sign = 1, { rw [oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, real.angle.sin_coe, dist_div_sin_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (or.inl (left_ne_of_oangle_eq_pi_div_two h))] end /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ lemma dist_div_sin_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₃ p₂ / real.angle.sin (∡ p₃ p₁ p₂) = dist p₁ p₃ := begin have hs : (∡ p₃ p₁ p₂).sign = 1, { rw [←oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, real.angle.sin_coe, dist_comm p₁ p₃, dist_div_sin_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (or.inl (right_ne_of_oangle_eq_pi_div_two h))] end /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ lemma dist_div_tan_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₁ p₂ / real.angle.tan (∡ p₂ p₃ p₁) = dist p₃ p₂ := begin have hs : (∡ p₂ p₃ p₁).sign = 1, { rw [oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, real.angle.tan_coe, dist_div_tan_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (or.inl (left_ne_of_oangle_eq_pi_div_two h))] end /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ lemma dist_div_tan_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₃ p₂ / real.angle.tan (∡ p₃ p₁ p₂) = dist p₁ p₂ := begin have hs : (∡ p₃ p₁ p₂).sign = 1, { rw [←oangle_rotate_sign, h, real.angle.sign_coe_pi_div_two] }, rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, real.angle.tan_coe, dist_div_tan_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (or.inl (right_ne_of_oangle_eq_pi_div_two h))] end end euclidean_geometry
3a55f320f998217246ffbb2ea20cee3cda0814ff
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/linear_algebra/affine_space/independent.lean
5b95b702e2f6ae735ff50ea6e26b4201b65ac631
[ "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
24,631
lean
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import data.finset.sort import data.matrix.notation import linear_algebra.affine_space.combination import linear_algebra.basis /-! # Affine independence This file defines affinely independent families of points. ## Main definitions * `affine_independent` defines affinely independent families of points as those where no nontrivial weighted subtraction is 0. This is proved equivalent to two other formulations: linear independence of the results of subtracting a base point in the family from the other points in the family, or any equal affine combinations having the same weights. A bundled type `simplex` is provided for finite affinely independent families of points, with an abbreviation `triangle` for the case of three points. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable theory open_locale big_operators classical affine open function section affine_independent variables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V] variables [affine_space V P] {ι : Type*} include V /-- An indexed family is said to be affinely independent if no nontrivial weighted subtractions (where the sum of weights is 0) are 0. -/ def affine_independent (p : ι → P) : Prop := ∀ (s : finset ι) (w : ι → k), ∑ i in s, w i = 0 → s.weighted_vsub p w = (0:V) → ∀ i ∈ s, w i = 0 /-- The definition of `affine_independent`. -/ lemma affine_independent_def (p : ι → P) : affine_independent k p ↔ ∀ (s : finset ι) (w : ι → k), ∑ i in s, w i = 0 → s.weighted_vsub p w = (0 : V) → ∀ i ∈ s, w i = 0 := iff.rfl /-- A family with at most one point is affinely independent. -/ lemma affine_independent_of_subsingleton [subsingleton ι] (p : ι → P) : affine_independent k p := λ s w h hs i hi, fintype.eq_of_subsingleton_of_sum_eq h i hi /-- A family indexed by a `fintype` is affinely independent if and only if no nontrivial weighted subtractions over `finset.univ` (where the sum of the weights is 0) are 0. -/ lemma affine_independent_iff_of_fintype [fintype ι] (p : ι → P) : affine_independent k p ↔ ∀ w : ι → k, ∑ i, w i = 0 → finset.univ.weighted_vsub p w = (0 : V) → ∀ i, w i = 0 := begin split, { exact λ h w hw hs i, h finset.univ w hw hs i (finset.mem_univ _) }, { intros h s w hw hs i hi, rw finset.weighted_vsub_indicator_subset _ _ (finset.subset_univ s) at hs, rw set.sum_indicator_subset _ (finset.subset_univ s) at hw, replace h := h ((↑s : set ι).indicator w) hw hs i, simpa [hi] using h } end /-- A family is affinely independent if and only if the differences from a base point in that family are linearly independent. -/ lemma affine_independent_iff_linear_independent_vsub (p : ι → P) (i1 : ι) : affine_independent k p ↔ linear_independent k (λ i : {x // x ≠ i1}, (p i -ᵥ p i1 : V)) := begin split, { intro h, rw linear_independent_iff', intros s g hg i hi, set f : ι → k := λ x, if hx : x = i1 then -∑ y in s, g y else g ⟨x, hx⟩ with hfdef, let s2 : finset ι := insert i1 (s.map (embedding.subtype _)), have hfg : ∀ x : {x // x ≠ i1}, g x = f x, { intro x, rw hfdef, dsimp only [], erw [dif_neg x.property, subtype.coe_eta] }, rw hfg, have hf : ∑ ι in s2, f ι = 0, { rw [finset.sum_insert (finset.not_mem_map_subtype_of_not_property s (not_not.2 rfl)), finset.sum_subtype_map_embedding (λ x hx, (hfg x).symm)], rw hfdef, dsimp only [], rw dif_pos rfl, exact neg_add_self _ }, have hs2 : s2.weighted_vsub p f = (0:V), { set f2 : ι → V := λ x, f x • (p x -ᵥ p i1) with hf2def, set g2 : {x // x ≠ i1} → V := λ x, g x • (p x -ᵥ p i1) with hg2def, have hf2g2 : ∀ x : {x // x ≠ i1}, f2 x = g2 x, { simp_rw [hf2def, hg2def, hfg], exact λ x, rfl }, rw [finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero s2 f p hf (p i1), finset.weighted_vsub_of_point_insert, finset.weighted_vsub_of_point_apply, finset.sum_subtype_map_embedding (λ x hx, hf2g2 x)], exact hg }, exact h s2 f hf hs2 i (finset.mem_insert_of_mem (finset.mem_map.2 ⟨i, hi, rfl⟩)) }, { intro h, rw linear_independent_iff' at h, intros s w hw hs i hi, rw [finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero s w p hw (p i1), ←s.weighted_vsub_of_point_erase w p i1, finset.weighted_vsub_of_point_apply] at hs, let f : ι → V := λ i, w i • (p i -ᵥ p i1), have hs2 : ∑ i in (s.erase i1).subtype (λ i, i ≠ i1), f i = 0, { rw [←hs], convert finset.sum_subtype_of_mem f (λ x, finset.ne_of_mem_erase) }, have h2 := h ((s.erase i1).subtype (λ i, i ≠ i1)) (λ x, w x) hs2, simp_rw [finset.mem_subtype] at h2, have h2b : ∀ i ∈ s, i ≠ i1 → w i = 0 := λ i his hi, h2 ⟨i, hi⟩ (finset.mem_erase_of_ne_of_mem hi his), exact finset.eq_zero_of_sum_eq_zero hw h2b i hi } end /-- A set is affinely independent if and only if the differences from a base point in that set are linearly independent. -/ lemma affine_independent_set_iff_linear_independent_vsub {s : set P} {p₁ : P} (hp₁ : p₁ ∈ s) : affine_independent k (λ p, p : s → P) ↔ linear_independent k (λ v, v : (λ p, (p -ᵥ p₁ : V)) '' (s \ {p₁}) → V) := begin rw affine_independent_iff_linear_independent_vsub k (λ p, p : s → P) ⟨p₁, hp₁⟩, split, { intro h, have hv : ∀ v : (λ p, (p -ᵥ p₁ : V)) '' (s \ {p₁}), (v : V) +ᵥ p₁ ∈ s \ {p₁} := λ v, (set.mem_image_of_injective (vsub_left_injective p₁)).1 ((vadd_vsub (v : V) p₁).symm ▸ v.property), let f : (λ p : P, (p -ᵥ p₁ : V)) '' (s \ {p₁}) → {x : s // x ≠ ⟨p₁, hp₁⟩} := λ x, ⟨⟨(x : V) +ᵥ p₁, set.mem_of_mem_diff (hv x)⟩, λ hx, set.not_mem_of_mem_diff (hv x) (subtype.ext_iff.1 hx)⟩, convert h.comp f (λ x1 x2 hx, (subtype.ext (vadd_right_cancel p₁ (subtype.ext_iff.1 (subtype.ext_iff.1 hx))))), ext v, exact (vadd_vsub (v : V) p₁).symm }, { intro h, let f : {x : s // x ≠ ⟨p₁, hp₁⟩} → (λ p : P, (p -ᵥ p₁ : V)) '' (s \ {p₁}) := λ x, ⟨((x : s) : P) -ᵥ p₁, ⟨x, ⟨⟨(x : s).property, λ hx, x.property (subtype.ext hx)⟩, rfl⟩⟩⟩, convert h.comp f (λ x1 x2 hx, subtype.ext (subtype.ext (vsub_left_cancel (subtype.ext_iff.1 hx)))) } end /-- A set of nonzero vectors is linearly independent if and only if, given a point `p₁`, the vectors added to `p₁` and `p₁` itself are affinely independent. -/ lemma linear_independent_set_iff_affine_independent_vadd_union_singleton {s : set V} (hs : ∀ v ∈ s, v ≠ (0 : V)) (p₁ : P) : linear_independent k (λ v, v : s → V) ↔ affine_independent k (λ p, p : {p₁} ∪ ((λ v, v +ᵥ p₁) '' s) → P) := begin rw affine_independent_set_iff_linear_independent_vsub k (set.mem_union_left _ (set.mem_singleton p₁)), have h : (λ p, (p -ᵥ p₁ : V)) '' (({p₁} ∪ (λ v, v +ᵥ p₁) '' s) \ {p₁}) = s, { simp_rw [set.union_diff_left, set.image_diff (vsub_left_injective p₁), set.image_image, set.image_singleton, vsub_self, vadd_vsub, set.image_id'], exact set.diff_singleton_eq_self (λ h, hs 0 h rfl) }, rw h end /-- A family is affinely independent if and only if any affine combinations (with sum of weights 1) that evaluate to the same point have equal `set.indicator`. -/ lemma affine_independent_iff_indicator_eq_of_affine_combination_eq (p : ι → P) : affine_independent k p ↔ ∀ (s1 s2 : finset ι) (w1 w2 : ι → k), ∑ i in s1, w1 i = 1 → ∑ i in s2, w2 i = 1 → s1.affine_combination p w1 = s2.affine_combination p w2 → set.indicator ↑s1 w1 = set.indicator ↑s2 w2 := begin split, { intros ha s1 s2 w1 w2 hw1 hw2 heq, ext i, by_cases hi : i ∈ (s1 ∪ s2), { rw ←sub_eq_zero, rw set.sum_indicator_subset _ (finset.subset_union_left s1 s2) at hw1, rw set.sum_indicator_subset _ (finset.subset_union_right s1 s2) at hw2, have hws : ∑ i in s1 ∪ s2, (set.indicator ↑s1 w1 - set.indicator ↑s2 w2) i = 0, { simp [hw1, hw2] }, rw [finset.affine_combination_indicator_subset _ _ (finset.subset_union_left s1 s2), finset.affine_combination_indicator_subset _ _ (finset.subset_union_right s1 s2), ←@vsub_eq_zero_iff_eq V, finset.affine_combination_vsub] at heq, exact ha (s1 ∪ s2) (set.indicator ↑s1 w1 - set.indicator ↑s2 w2) hws heq i hi }, { rw [←finset.mem_coe, finset.coe_union] at hi, simp [mt (set.mem_union_left ↑s2) hi, mt (set.mem_union_right ↑s1) hi] } }, { intros ha s w hw hs i0 hi0, let w1 : ι → k := function.update (function.const ι 0) i0 1, have hw1 : ∑ i in s, w1 i = 1, { rw [finset.sum_update_of_mem hi0, finset.sum_const_zero, add_zero] }, have hw1s : s.affine_combination p w1 = p i0 := s.affine_combination_of_eq_one_of_eq_zero w1 p hi0 (function.update_same _ _ _) (λ _ _ hne, function.update_noteq hne _ _), let w2 := w + w1, have hw2 : ∑ i in s, w2 i = 1, { simp [w2, finset.sum_add_distrib, hw, hw1] }, have hw2s : s.affine_combination p w2 = p i0, { simp [w2, ←finset.weighted_vsub_vadd_affine_combination, hs, hw1s] }, replace ha := ha s s w2 w1 hw2 hw1 (hw1s.symm ▸ hw2s), have hws : w2 i0 - w1 i0 = 0, { rw ←finset.mem_coe at hi0, rw [←set.indicator_of_mem hi0 w2, ←set.indicator_of_mem hi0 w1, ha, sub_self] }, simpa [w2] using hws } end variables {k} /-- An affinely independent family is injective, if the underlying ring is nontrivial. -/ lemma injective_of_affine_independent [nontrivial k] {p : ι → P} (ha : affine_independent k p) : function.injective p := begin intros i j hij, rw affine_independent_iff_linear_independent_vsub _ _ j at ha, by_contra hij', exact ha.ne_zero ⟨i, hij'⟩ (vsub_eq_zero_iff_eq.mpr hij) end /-- If a family is affinely independent, so is any subfamily given by composition of an embedding into index type with the original family. -/ lemma affine_independent_embedding_of_affine_independent {ι2 : Type*} (f : ι2 ↪ ι) {p : ι → P} (ha : affine_independent k p) : affine_independent k (p ∘ f) := begin intros fs w hw hs i0 hi0, let fs' := fs.map f, let w' := λ i, if h : ∃ i2, f i2 = i then w h.some else 0, have hw' : ∀ i2 : ι2, w' (f i2) = w i2, { intro i2, have h : ∃ i : ι2, f i = f i2 := ⟨i2, rfl⟩, have hs : h.some = i2 := f.injective h.some_spec, simp_rw [w', dif_pos h, hs] }, have hw's : ∑ i in fs', w' i = 0, { rw [←hw, finset.sum_map], simp [hw'] }, have hs' : fs'.weighted_vsub p w' = (0:V), { rw [←hs, finset.weighted_vsub_map], congr' with i, simp [hw'] }, rw [←ha fs' w' hw's hs' (f i0) ((finset.mem_map' _).2 hi0), hw'] end /-- If a family is affinely independent, so is any subfamily indexed by a subtype of the index type. -/ lemma affine_independent_subtype_of_affine_independent {p : ι → P} (ha : affine_independent k p) (s : set ι) : affine_independent k (λ i : s, p i) := affine_independent_embedding_of_affine_independent (embedding.subtype _) ha /-- If an indexed family of points is affinely independent, so is the corresponding set of points. -/ lemma affine_independent_set_of_affine_independent {p : ι → P} (ha : affine_independent k p) : affine_independent k (λ x, x : set.range p → P) := begin let f : set.range p → ι := λ x, x.property.some, have hf : ∀ x, p (f x) = x := λ x, x.property.some_spec, let fe : set.range p ↪ ι := ⟨f, λ x₁ x₂ he, subtype.ext (hf x₁ ▸ hf x₂ ▸ he ▸ rfl)⟩, convert affine_independent_embedding_of_affine_independent fe ha, ext, simp [hf] end /-- If a set of points is affinely independent, so is any subset. -/ lemma affine_independent_of_subset_affine_independent {s t : set P} (ha : affine_independent k (λ x, x : t → P)) (hs : s ⊆ t) : affine_independent k (λ x, x : s → P) := affine_independent_embedding_of_affine_independent (set.embedding_of_subset s t hs) ha /-- If the range of an injective indexed family of points is affinely independent, so is that family. -/ lemma affine_independent_of_affine_independent_set_of_injective {p : ι → P} (ha : affine_independent k (λ x, x : set.range p → P)) (hi : function.injective p) : affine_independent k p := affine_independent_embedding_of_affine_independent (⟨λ i, ⟨p i, set.mem_range_self _⟩, λ x y h, hi (subtype.mk_eq_mk.1 h)⟩ : ι ↪ set.range p) ha /-- If a family is affinely independent, and the spans of points indexed by two subsets of the index type have a point in common, those subsets of the index type have an element in common, if the underlying ring is nontrivial. -/ lemma exists_mem_inter_of_exists_mem_inter_affine_span_of_affine_independent [nontrivial k] {p : ι → P} (ha : affine_independent k p) {s1 s2 : set ι} {p0 : P} (hp0s1 : p0 ∈ affine_span k (p '' s1)) (hp0s2 : p0 ∈ affine_span k (p '' s2)): ∃ (i : ι), i ∈ s1 ∩ s2 := begin rw set.image_eq_range at hp0s1 hp0s2, rw [mem_affine_span_iff_eq_affine_combination, ←finset.eq_affine_combination_subset_iff_eq_affine_combination_subtype] at hp0s1 hp0s2, rcases hp0s1 with ⟨fs1, hfs1, w1, hw1, hp0s1⟩, rcases hp0s2 with ⟨fs2, hfs2, w2, hw2, hp0s2⟩, rw affine_independent_iff_indicator_eq_of_affine_combination_eq at ha, replace ha := ha fs1 fs2 w1 w2 hw1 hw2 (hp0s1 ▸ hp0s2), have hnz : ∑ i in fs1, w1 i ≠ 0 := hw1.symm ▸ one_ne_zero, rcases finset.exists_ne_zero_of_sum_ne_zero hnz with ⟨i, hifs1, hinz⟩, simp_rw [←set.indicator_of_mem (finset.mem_coe.2 hifs1) w1, ha] at hinz, use [i, hfs1 hifs1, hfs2 (set.mem_of_indicator_ne_zero hinz)] end /-- If a family is affinely independent, the spans of points indexed by disjoint subsets of the index type are disjoint, if the underlying ring is nontrivial. -/ lemma affine_span_disjoint_of_disjoint_of_affine_independent [nontrivial k] {p : ι → P} (ha : affine_independent k p) {s1 s2 : set ι} (hd : s1 ∩ s2 = ∅) : (affine_span k (p '' s1) : set P) ∩ affine_span k (p '' s2) = ∅ := begin by_contradiction hne, change (affine_span k (p '' s1) : set P) ∩ affine_span k (p '' s2) ≠ ∅ at hne, rw set.ne_empty_iff_nonempty at hne, rcases hne with ⟨p0, hp0s1, hp0s2⟩, cases exists_mem_inter_of_exists_mem_inter_affine_span_of_affine_independent ha hp0s1 hp0s2 with i hi, exact set.not_mem_empty i (hd ▸ hi) end /-- If a family is affinely independent, a point in the family is in the span of some of the points given by a subset of the index type if and only if that point's index is in the subset, if the underlying ring is nontrivial. -/ @[simp] lemma mem_affine_span_iff_mem_of_affine_independent [nontrivial k] {p : ι → P} (ha : affine_independent k p) (i : ι) (s : set ι) : p i ∈ affine_span k (p '' s) ↔ i ∈ s := begin split, { intro hs, have h := exists_mem_inter_of_exists_mem_inter_affine_span_of_affine_independent ha hs (mem_affine_span k (set.mem_image_of_mem _ (set.mem_singleton _))), rwa [←set.nonempty_def, set.inter_singleton_nonempty] at h }, { exact λ h, mem_affine_span k (set.mem_image_of_mem p h) } end /-- If a family is affinely independent, a point in the family is not in the affine span of the other points, if the underlying ring is nontrivial. -/ lemma not_mem_affine_span_diff_of_affine_independent [nontrivial k] {p : ι → P} (ha : affine_independent k p) (i : ι) (s : set ι) : p i ∉ affine_span k (p '' (s \ {i})) := by simp [ha] end affine_independent section field variables {k : Type*} {V : Type*} {P : Type*} [field k] [add_comm_group V] [module k V] variables [affine_space V P] {ι : Type*} include V /-- An affinely independent set of points can be extended to such a set that spans the whole space. -/ lemma exists_subset_affine_independent_affine_span_eq_top {s : set P} (h : affine_independent k (λ p, p : s → P)) : ∃ t : set P, s ⊆ t ∧ affine_independent k (λ p, p : t → P) ∧ affine_span k t = ⊤ := begin rcases s.eq_empty_or_nonempty with rfl | ⟨p₁, hp₁⟩, { have p₁ : P := add_torsor.nonempty.some, let hsv := basis.of_vector_space k V, have hsvi := hsv.linear_independent, have hsvt := hsv.span_eq, rw basis.coe_of_vector_space at hsvi hsvt, have h0 : ∀ v : V, v ∈ (basis.of_vector_space_index _ _) → v ≠ 0, { intros v hv, simpa using hsv.ne_zero ⟨v, hv⟩ }, rw linear_independent_set_iff_affine_independent_vadd_union_singleton k h0 p₁ at hsvi, exact ⟨{p₁} ∪ (λ v, v +ᵥ p₁) '' _, set.empty_subset _, hsvi, affine_span_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt⟩ }, { rw affine_independent_set_iff_linear_independent_vsub k hp₁ at h, let bsv := basis.extend h, have hsvi := bsv.linear_independent, have hsvt := bsv.span_eq, rw basis.coe_extend at hsvi hsvt, have hsv := h.subset_extend (set.subset_univ _), have h0 : ∀ v : V, v ∈ (h.extend _) → v ≠ 0, { intros v hv, simpa using bsv.ne_zero ⟨v, hv⟩ }, rw linear_independent_set_iff_affine_independent_vadd_union_singleton k h0 p₁ at hsvi, refine ⟨{p₁} ∪ (λ v, v +ᵥ p₁) '' h.extend (set.subset_univ _), _, _⟩, { refine set.subset.trans _ (set.union_subset_union_right _ (set.image_subset _ hsv)), simp [set.image_image] }, { use [hsvi, affine_span_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt] } } end variables (k) /-- Two different points are affinely independent. -/ lemma affine_independent_of_ne {p₁ p₂ : P} (h : p₁ ≠ p₂) : affine_independent k ![p₁, p₂] := begin rw affine_independent_iff_linear_independent_vsub k ![p₁, p₂] 0, let i₁ : {x // x ≠ (0 : fin 2)} := ⟨1, by norm_num⟩, have he' : ∀ i, i = i₁, { rintro ⟨i, hi⟩, ext, fin_cases i, { simpa using hi } }, haveI : unique {x // x ≠ (0 : fin 2)} := ⟨⟨i₁⟩, he'⟩, have hz : (![p₁, p₂] ↑(default {x // x ≠ (0 : fin 2)}) -ᵥ ![p₁, p₂] 0 : V) ≠ 0, { rw he' (default _), simp, cc }, exact linear_independent_unique _ hz end end field namespace affine variables (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V] [module k V] variables [affine_space V P] include V /-- A `simplex k P n` is a collection of `n + 1` affinely independent points. -/ structure simplex (n : ℕ) := (points : fin (n + 1) → P) (independent : affine_independent k points) /-- A `triangle k P` is a collection of three affinely independent points. -/ abbreviation triangle := simplex k P 2 namespace simplex variables {P} /-- Construct a 0-simplex from a point. -/ def mk_of_point (p : P) : simplex k P 0 := ⟨λ _, p, affine_independent_of_subsingleton k _⟩ /-- The point in a simplex constructed with `mk_of_point`. -/ @[simp] lemma mk_of_point_points (p : P) (i : fin 1) : (mk_of_point k p).points i = p := rfl instance [inhabited P] : inhabited (simplex k P 0) := ⟨mk_of_point k $ default P⟩ instance nonempty : nonempty (simplex k P 0) := ⟨mk_of_point k $ add_torsor.nonempty.some⟩ variables {k V} /-- Two simplices are equal if they have the same points. -/ @[ext] lemma ext {n : ℕ} {s1 s2 : simplex k P n} (h : ∀ i, s1.points i = s2.points i) : s1 = s2 := begin cases s1, cases s2, congr' with i, exact h i end /-- Two simplices are equal if and only if they have the same points. -/ lemma ext_iff {n : ℕ} (s1 s2 : simplex k P n): s1 = s2 ↔ ∀ i, s1.points i = s2.points i := ⟨λ h _, h ▸ rfl, ext⟩ /-- A face of a simplex is a simplex with the given subset of points. -/ def face {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : simplex k P m := ⟨s.points ∘ fs.order_emb_of_fin h, affine_independent_embedding_of_affine_independent (fs.order_emb_of_fin h).to_embedding s.independent⟩ /-- The points of a face of a simplex are given by `mono_of_fin`. -/ lemma face_points {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) (i : fin (m + 1)) : (s.face h).points i = s.points (fs.order_emb_of_fin h i) := rfl /-- The points of a face of a simplex are given by `mono_of_fin`. -/ lemma face_points' {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : (s.face h).points = s.points ∘ (fs.order_emb_of_fin h) := rfl /-- A single-point face equals the 0-simplex constructed with `mk_of_point`. -/ @[simp] lemma face_eq_mk_of_point {n : ℕ} (s : simplex k P n) (i : fin (n + 1)) : s.face (finset.card_singleton i) = mk_of_point k (s.points i) := by { ext, simp [face_points] } /-- The set of points of a face. -/ @[simp] lemma range_face_points {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : set.range (s.face h).points = s.points '' ↑fs := by rw [face_points', set.range_comp, finset.range_order_emb_of_fin] end simplex end affine namespace affine namespace simplex variables {k : Type*} {V : Type*} {P : Type*} [division_ring k] [add_comm_group V] [module k V] [affine_space V P] include V /-- The centroid of a face of a simplex as the centroid of a subset of the points. -/ @[simp] lemma face_centroid_eq_centroid {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : finset.univ.centroid k (s.face h).points = fs.centroid k s.points := begin convert (finset.univ.centroid_map k (fs.order_emb_of_fin h).to_embedding s.points).symm, rw [← finset.coe_inj, finset.coe_map, finset.coe_univ, set.image_univ], simp end /-- Over a characteristic-zero division ring, the centroids given by two subsets of the points of a simplex are equal if and only if those faces are given by the same subset of points. -/ @[simp] lemma centroid_eq_iff [char_zero k] {n : ℕ} (s : simplex k P n) {fs₁ fs₂ : finset (fin (n + 1))} {m₁ m₂ : ℕ} (h₁ : fs₁.card = m₁ + 1) (h₂ : fs₂.card = m₂ + 1) : fs₁.centroid k s.points = fs₂.centroid k s.points ↔ fs₁ = fs₂ := begin split, { intro h, rw [finset.centroid_eq_affine_combination_fintype, finset.centroid_eq_affine_combination_fintype] at h, have ha := (affine_independent_iff_indicator_eq_of_affine_combination_eq k s.points).1 s.independent _ _ _ _ (fs₁.sum_centroid_weights_indicator_eq_one_of_card_eq_add_one k h₁) (fs₂.sum_centroid_weights_indicator_eq_one_of_card_eq_add_one k h₂) h, simp_rw [finset.coe_univ, set.indicator_univ, function.funext_iff, finset.centroid_weights_indicator_def, finset.centroid_weights, h₁, h₂] at ha, ext i, replace ha := ha i, split, all_goals { intro hi, by_contradiction hni, simp [hi, hni] at ha, norm_cast at ha } }, { intro h, have hm : m₁ = m₂, { subst h, simpa [h₁] using h₂ }, subst hm, congr, exact h } end /-- Over a characteristic-zero division ring, the centroids of two faces of a simplex are equal if and only if those faces are given by the same subset of points. -/ lemma face_centroid_eq_iff [char_zero k] {n : ℕ} (s : simplex k P n) {fs₁ fs₂ : finset (fin (n + 1))} {m₁ m₂ : ℕ} (h₁ : fs₁.card = m₁ + 1) (h₂ : fs₂.card = m₂ + 1) : finset.univ.centroid k (s.face h₁).points = finset.univ.centroid k (s.face h₂).points ↔ fs₁ = fs₂ := begin rw [face_centroid_eq_centroid, face_centroid_eq_centroid], exact s.centroid_eq_iff h₁ h₂ end /-- Two simplices with the same points have the same centroid. -/ lemma centroid_eq_of_range_eq {n : ℕ} {s₁ s₂ : simplex k P n} (h : set.range s₁.points = set.range s₂.points) : finset.univ.centroid k s₁.points = finset.univ.centroid k s₂.points := begin rw [←set.image_univ, ←set.image_univ, ←finset.coe_univ] at h, exact finset.univ.centroid_eq_of_inj_on_of_image_eq k _ (λ _ _ _ _ he, injective_of_affine_independent s₁.independent he) (λ _ _ _ _ he, injective_of_affine_independent s₂.independent he) h end end simplex end affine
16d942249bd10a703398a4fd1cee07beb0840d9e
137c667471a40116a7afd7261f030b30180468c2
/src/category_theory/limits/shapes/zero.lean
1dccd2226a8563baeaa11dd6bc911286e1bd23c0
[ "Apache-2.0" ]
permissive
bragadeesh153/mathlib
46bf814cfb1eecb34b5d1549b9117dc60f657792
b577bb2cd1f96eb47031878256856020b76f73cd
refs/heads/master
1,687,435,188,334
1,626,384,207,000
1,626,384,207,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
17,976
lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import category_theory.limits.shapes.terminal import category_theory.limits.shapes.binary_products import category_theory.limits.shapes.products import category_theory.limits.shapes.images import category_theory.isomorphism_classes /-! # Zero morphisms and zero objects A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space, and compositions of zero morphisms with anything give the zero morphism. (Notice this is extra structure, not merely a property.) A category "has a zero object" if it has an object which is both initial and terminal. Having a zero object provides zero morphisms, as the unique morphisms factoring through the zero object. ## References * https://en.wikipedia.org/wiki/Zero_morphism * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable theory universes v u open category_theory open category_theory.category namespace category_theory.limits variables (C : Type u) [category.{v} C] /-- A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space, and compositions of zero morphisms with anything give the zero morphism. -/ class has_zero_morphisms := [has_zero : Π X Y : C, has_zero (X ⟶ Y)] (comp_zero' : ∀ {X Y : C} (f : X ⟶ Y) (Z : C), f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) . obviously) (zero_comp' : ∀ (X : C) {Y Z : C} (f : Y ⟶ Z), (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) . obviously) attribute [instance] has_zero_morphisms.has_zero restate_axiom has_zero_morphisms.comp_zero' restate_axiom has_zero_morphisms.zero_comp' variables {C} @[simp] lemma comp_zero [has_zero_morphisms C] {X Y : C} {f : X ⟶ Y} {Z : C} : f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) := has_zero_morphisms.comp_zero f Z @[simp] lemma zero_comp [has_zero_morphisms C] {X : C} {Y Z : C} {f : Y ⟶ Z} : (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) := has_zero_morphisms.zero_comp X f instance has_zero_morphisms_pempty : has_zero_morphisms (discrete pempty) := { has_zero := by tidy } instance has_zero_morphisms_punit : has_zero_morphisms (discrete punit) := { has_zero := by tidy } namespace has_zero_morphisms variables {C} /-- This lemma will be immediately superseded by `ext`, below. -/ private lemma ext_aux (I J : has_zero_morphisms C) (w : ∀ X Y : C, (@has_zero_morphisms.has_zero _ _ I X Y).zero = (@has_zero_morphisms.has_zero _ _ J X Y).zero) : I = J := begin casesI I, casesI J, congr, { ext X Y, exact w X Y }, { apply proof_irrel_heq, }, { apply proof_irrel_heq, } end /-- If you're tempted to use this lemma "in the wild", you should probably carefully consider whether you've made a mistake in allowing two instances of `has_zero_morphisms` to exist at all. See, particularly, the note on `zero_morphisms_of_zero_object` below. -/ lemma ext (I J : has_zero_morphisms C) : I = J := begin apply ext_aux, intros X Y, rw ←@has_zero_morphisms.comp_zero _ _ I X X (@has_zero_morphisms.has_zero _ _ J X X).zero, rw @has_zero_morphisms.zero_comp _ _ J, end instance : subsingleton (has_zero_morphisms C) := ⟨ext⟩ end has_zero_morphisms open opposite has_zero_morphisms instance has_zero_morphisms_opposite [has_zero_morphisms C] : has_zero_morphisms Cᵒᵖ := { has_zero := λ X Y, ⟨(0 : unop Y ⟶ unop X).op⟩, comp_zero' := λ X Y f Z, congr_arg quiver.hom.op (has_zero_morphisms.zero_comp (unop Z) f.unop), zero_comp' := λ X Y Z f, congr_arg quiver.hom.op (has_zero_morphisms.comp_zero f.unop (unop X)), } section variables {C} [has_zero_morphisms C] lemma zero_of_comp_mono {X Y Z : C} {f : X ⟶ Y} (g : Y ⟶ Z) [mono g] (h : f ≫ g = 0) : f = 0 := by { rw [←zero_comp, cancel_mono] at h, exact h } lemma zero_of_epi_comp {X Y Z : C} (f : X ⟶ Y) {g : Y ⟶ Z} [epi f] (h : f ≫ g = 0) : g = 0 := by { rw [←comp_zero, cancel_epi] at h, exact h } lemma eq_zero_of_image_eq_zero {X Y : C} {f : X ⟶ Y} [has_image f] (w : image.ι f = 0) : f = 0 := by rw [←image.fac f, w, has_zero_morphisms.comp_zero] lemma nonzero_image_of_nonzero {X Y : C} {f : X ⟶ Y} [has_image f] (w : f ≠ 0) : image.ι f ≠ 0 := λ h, w (eq_zero_of_image_eq_zero h) end section universes v' u' variables (D : Type u') [category.{v'} D] variables [has_zero_morphisms D] instance : has_zero_morphisms (C ⥤ D) := { has_zero := λ F G, ⟨{ app := λ X, 0, }⟩ } @[simp] lemma zero_app (F G : C ⥤ D) (j : C) : (0 : F ⟶ G).app j = 0 := rfl variables [has_zero_morphisms C] lemma equivalence_preserves_zero_morphisms (F : C ≌ D) (X Y : C) : F.functor.map (0 : X ⟶ Y) = (0 : F.functor.obj X ⟶ F.functor.obj Y) := begin have t : F.functor.map (0 : X ⟶ Y) = F.functor.map (0 : X ⟶ Y) ≫ (0 : F.functor.obj Y ⟶ F.functor.obj Y), { apply faithful.map_injective (F.inverse), rw [functor.map_comp, equivalence.inv_fun_map], dsimp, rw [zero_comp, comp_zero, zero_comp], }, exact t.trans (by simp) end @[simp] lemma is_equivalence_preserves_zero_morphisms (F : C ⥤ D) [is_equivalence F] (X Y : C) : F.map (0 : X ⟶ Y) = 0 := by rw [←functor.as_equivalence_functor F, equivalence_preserves_zero_morphisms] end variables (C) /-- A category "has a zero object" if it has an object which is both initial and terminal. -/ class has_zero_object := (zero : C) (unique_to : Π X : C, unique (zero ⟶ X)) (unique_from : Π X : C, unique (X ⟶ zero)) instance has_zero_object_punit : has_zero_object (discrete punit) := { zero := punit.star, unique_to := by tidy, unique_from := by tidy, } variables {C} namespace has_zero_object variables [has_zero_object C] /-- Construct a `has_zero C` for a category with a zero object. This can not be a global instance as it will trigger for every `has_zero C` typeclass search. -/ protected def has_zero : has_zero C := { zero := has_zero_object.zero } localized "attribute [instance] category_theory.limits.has_zero_object.has_zero" in zero_object localized "attribute [instance] category_theory.limits.has_zero_object.unique_to" in zero_object localized "attribute [instance] category_theory.limits.has_zero_object.unique_from" in zero_object @[ext] lemma to_zero_ext {X : C} (f g : X ⟶ 0) : f = g := by rw [(has_zero_object.unique_from X).uniq f, (has_zero_object.unique_from X).uniq g] @[ext] lemma from_zero_ext {X : C} (f g : 0 ⟶ X) : f = g := by rw [(has_zero_object.unique_to X).uniq f, (has_zero_object.unique_to X).uniq g] instance (X : C) : subsingleton (X ≅ 0) := by tidy instance {X : C} (f : 0 ⟶ X) : mono f := { right_cancellation := λ Z g h w, by ext, } instance {X : C} (f : X ⟶ 0) : epi f := { left_cancellation := λ Z g h w, by ext, } /-- A category with a zero object has zero morphisms. It is rarely a good idea to use this. Many categories that have a zero object have zero morphisms for some other reason, for example from additivity. Library code that uses `zero_morphisms_of_zero_object` will then be incompatible with these categories because the `has_zero_morphisms` instances will not be definitionally equal. For this reason library code should generally ask for an instance of `has_zero_morphisms` separately, even if it already asks for an instance of `has_zero_objects`. -/ def zero_morphisms_of_zero_object : has_zero_morphisms C := { has_zero := λ X Y, { zero := inhabited.default (X ⟶ 0) ≫ inhabited.default (0 ⟶ Y) }, zero_comp' := λ X Y Z f, by { dunfold has_zero.zero, rw category.assoc, congr, }, comp_zero' := λ X Y Z f, by { dunfold has_zero.zero, rw ←category.assoc, congr, }} /-- A zero object is in particular initial. -/ lemma has_initial : has_initial C := has_initial_of_unique 0 /-- A zero object is in particular terminal. -/ lemma has_terminal : has_terminal C := has_terminal_of_unique 0 open_locale zero_object instance {B : Type*} [category B] [has_zero_morphisms C] : has_zero_object (B ⥤ C) := { zero := { obj := λ X, 0, map := λ X Y f, 0, }, unique_to := λ F, ⟨⟨{ app := λ X, 0, }⟩, by tidy⟩, unique_from := λ F, ⟨⟨{ app := λ X, 0, }⟩, by tidy⟩ } @[simp] lemma functor.zero_obj {B : Type*} [category B] [has_zero_morphisms C] (X : B) : (0 : B ⥤ C).obj X = 0 := rfl @[simp] lemma functor.zero_map {B : Type*} [category B] [has_zero_morphisms C] {X Y : B} (f : X ⟶ Y) : (0 : B ⥤ C).map f = 0 := rfl end has_zero_object section variables [has_zero_object C] [has_zero_morphisms C] open_locale zero_object @[simp] lemma id_zero : 𝟙 (0 : C) = (0 : 0 ⟶ 0) := by ext /-- An arrow ending in the zero object is zero -/ -- This can't be a `simp` lemma because the left hand side would be a metavariable. lemma zero_of_to_zero {X : C} (f : X ⟶ 0) : f = 0 := by ext lemma zero_of_target_iso_zero {X Y : C} (f : X ⟶ Y) (i : Y ≅ 0) : f = 0 := begin have h : f = f ≫ i.hom ≫ 𝟙 0 ≫ i.inv := by simp only [iso.hom_inv_id, id_comp, comp_id], simpa using h, end /-- An arrow starting at the zero object is zero -/ lemma zero_of_from_zero {X : C} (f : 0 ⟶ X) : f = 0 := by ext lemma zero_of_source_iso_zero {X Y : C} (f : X ⟶ Y) (i : X ≅ 0) : f = 0 := begin have h : f = i.hom ≫ 𝟙 0 ≫ i.inv ≫ f := by simp only [iso.hom_inv_id_assoc, id_comp, comp_id], simpa using h, end lemma zero_of_source_iso_zero' {X Y : C} (f : X ⟶ Y) (i : is_isomorphic X 0) : f = 0 := zero_of_source_iso_zero f (nonempty.some i) lemma zero_of_target_iso_zero' {X Y : C} (f : X ⟶ Y) (i : is_isomorphic Y 0) : f = 0 := zero_of_target_iso_zero f (nonempty.some i) lemma mono_of_source_iso_zero {X Y : C} (f : X ⟶ Y) (i : X ≅ 0) : mono f := ⟨λ Z g h w, by rw [zero_of_target_iso_zero g i, zero_of_target_iso_zero h i]⟩ lemma epi_of_target_iso_zero {X Y : C} (f : X ⟶ Y) (i : Y ≅ 0) : epi f := ⟨λ Z g h w, by rw [zero_of_source_iso_zero g i, zero_of_source_iso_zero h i]⟩ /-- An object `X` has `𝟙 X = 0` if and only if it is isomorphic to the zero object. Because `X ≅ 0` contains data (even if a subsingleton), we express this `↔` as an `≃`. -/ def id_zero_equiv_iso_zero (X : C) : (𝟙 X = 0) ≃ (X ≅ 0) := { to_fun := λ h, { hom := 0, inv := 0, }, inv_fun := λ i, zero_of_target_iso_zero (𝟙 X) i, left_inv := by tidy, right_inv := by tidy, } @[simp] lemma id_zero_equiv_iso_zero_apply_hom (X : C) (h : 𝟙 X = 0) : ((id_zero_equiv_iso_zero X) h).hom = 0 := rfl @[simp] lemma id_zero_equiv_iso_zero_apply_inv (X : C) (h : 𝟙 X = 0) : ((id_zero_equiv_iso_zero X) h).inv = 0 := rfl /-- If `0 : X ⟶ Y` is an monomorphism, then `X ≅ 0`. -/ @[simps] def iso_zero_of_mono_zero {X Y : C} (h : mono (0 : X ⟶ Y)) : X ≅ 0 := { hom := 0, inv := 0, hom_inv_id' := (cancel_mono (0 : X ⟶ Y)).mp (by simp) } /-- If `0 : X ⟶ Y` is an epimorphism, then `Y ≅ 0`. -/ @[simps] def iso_zero_of_epi_zero {X Y : C} (h : epi (0 : X ⟶ Y)) : Y ≅ 0 := { hom := 0, inv := 0, hom_inv_id' := (cancel_epi (0 : X ⟶ Y)).mp (by simp) } /-- If an object `X` is isomorphic to 0, there's no need to use choice to construct an explicit isomorphism: the zero morphism suffices. -/ def iso_of_is_isomorphic_zero {X : C} (P : is_isomorphic X 0) : X ≅ 0 := { hom := 0, inv := 0, hom_inv_id' := begin casesI P, rw ←P.hom_inv_id, rw ←category.id_comp P.inv, simp, end, inv_hom_id' := by simp, } end section is_iso variables [has_zero_morphisms C] /-- A zero morphism `0 : X ⟶ Y` is an isomorphism if and only if the identities on both `X` and `Y` are zero. -/ @[simps] def is_iso_zero_equiv (X Y : C) : is_iso (0 : X ⟶ Y) ≃ (𝟙 X = 0 ∧ 𝟙 Y = 0) := { to_fun := by { introsI i, rw ←is_iso.hom_inv_id (0 : X ⟶ Y), rw ←is_iso.inv_hom_id (0 : X ⟶ Y), simp }, inv_fun := λ h, ⟨⟨(0 : Y ⟶ X), by tidy⟩⟩, left_inv := by tidy, right_inv := by tidy, } /-- A zero morphism `0 : X ⟶ X` is an isomorphism if and only if the identity on `X` is zero. -/ def is_iso_zero_self_equiv (X : C) : is_iso (0 : X ⟶ X) ≃ (𝟙 X = 0) := by simpa using is_iso_zero_equiv X X variables [has_zero_object C] open_locale zero_object /-- A zero morphism `0 : X ⟶ Y` is an isomorphism if and only if `X` and `Y` are isomorphic to the zero object. -/ def is_iso_zero_equiv_iso_zero (X Y : C) : is_iso (0 : X ⟶ Y) ≃ (X ≅ 0) × (Y ≅ 0) := begin -- This is lame, because `prod` can't cope with `Prop`, so we can't use `equiv.prod_congr`. refine (is_iso_zero_equiv X Y).trans _, symmetry, fsplit, { rintros ⟨eX, eY⟩, fsplit, exact (id_zero_equiv_iso_zero X).symm eX, exact (id_zero_equiv_iso_zero Y).symm eY, }, { rintros ⟨hX, hY⟩, fsplit, exact (id_zero_equiv_iso_zero X) hX, exact (id_zero_equiv_iso_zero Y) hY, }, { tidy, }, { tidy, }, end lemma is_iso_of_source_target_iso_zero {X Y : C} (f : X ⟶ Y) (i : X ≅ 0) (j : Y ≅ 0) : is_iso f := begin rw zero_of_source_iso_zero f i, exact (is_iso_zero_equiv_iso_zero _ _).inv_fun ⟨i, j⟩, end /-- A zero morphism `0 : X ⟶ X` is an isomorphism if and only if `X` is isomorphic to the zero object. -/ def is_iso_zero_self_equiv_iso_zero (X : C) : is_iso (0 : X ⟶ X) ≃ (X ≅ 0) := (is_iso_zero_equiv_iso_zero X X).trans subsingleton_prod_self_equiv end is_iso /-- If there are zero morphisms, any initial object is a zero object. -/ @[priority 50] instance has_zero_object_of_has_initial_object [has_zero_morphisms C] [has_initial C] : has_zero_object C := { zero := ⊥_ C, unique_to := λ X, ⟨⟨0⟩, by tidy⟩, unique_from := λ X, ⟨⟨0⟩, λ f, calc f = f ≫ 𝟙 _ : (category.comp_id _).symm ... = f ≫ 0 : by congr ... = 0 : has_zero_morphisms.comp_zero _ _ ⟩ } /-- If there are zero morphisms, any terminal object is a zero object. -/ @[priority 50] instance has_zero_object_of_has_terminal_object [has_zero_morphisms C] [has_terminal C] : has_zero_object C := { zero := ⊤_ C, unique_from := λ X, ⟨⟨0⟩, by tidy⟩, unique_to := λ X, ⟨⟨0⟩, λ f, calc f = 𝟙 _ ≫ f : (category.id_comp _).symm ... = 0 ≫ f : by congr ... = 0 : zero_comp ⟩ } section image variable [has_zero_morphisms C] lemma image_ι_comp_eq_zero {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} [has_image f] [epi (factor_thru_image f)] (h : f ≫ g = 0) : image.ι f ≫ g = 0 := zero_of_epi_comp (factor_thru_image f) $ by simp [h] lemma comp_factor_thru_image_eq_zero {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} [has_image g] (h : f ≫ g = 0) : f ≫ factor_thru_image g = 0 := zero_of_comp_mono (image.ι g) $ by simp [h] variables [has_zero_object C] open_locale zero_object /-- The zero morphism has a `mono_factorisation` through the zero object. -/ @[simps] def mono_factorisation_zero (X Y : C) : mono_factorisation (0 : X ⟶ Y) := { I := 0, m := 0, e := 0, } /-- The factorisation through the zero object is an image factorisation. -/ def image_factorisation_zero (X Y : C) : image_factorisation (0 : X ⟶ Y) := { F := mono_factorisation_zero X Y, is_image := { lift := λ F', 0 } } instance has_image_zero {X Y : C} : has_image (0 : X ⟶ Y) := has_image.mk $ image_factorisation_zero _ _ /-- The image of a zero morphism is the zero object. -/ def image_zero {X Y : C} : image (0 : X ⟶ Y) ≅ 0 := is_image.iso_ext (image.is_image (0 : X ⟶ Y)) (image_factorisation_zero X Y).is_image /-- The image of a morphism which is equal to zero is the zero object. -/ def image_zero' {X Y : C} {f : X ⟶ Y} (h : f = 0) [has_image f] : image f ≅ 0 := image.eq_to_iso h ≪≫ image_zero @[simp] lemma image.ι_zero {X Y : C} [has_image (0 : X ⟶ Y)] : image.ι (0 : X ⟶ Y) = 0 := begin rw ←image.lift_fac (mono_factorisation_zero X Y), simp, end /-- If we know `f = 0`, it requires a little work to conclude `image.ι f = 0`, because `f = g` only implies `image f ≅ image g`. -/ @[simp] lemma image.ι_zero' [has_equalizers C] {X Y : C} {f : X ⟶ Y} (h : f = 0) [has_image f] : image.ι f = 0 := by { rw image.eq_fac h, simp } end image /-- In the presence of zero morphisms, coprojections into a coproduct are (split) monomorphisms. -/ instance split_mono_sigma_ι {β : Type v} [decidable_eq β] [has_zero_morphisms C] (f : β → C) [has_colimit (discrete.functor f)] (b : β) : split_mono (sigma.ι f b) := { retraction := sigma.desc (λ b', if h : b' = b then eq_to_hom (congr_arg f h) else 0), } /-- In the presence of zero morphisms, projections into a product are (split) epimorphisms. -/ instance split_epi_pi_π {β : Type v} [decidable_eq β] [has_zero_morphisms C] (f : β → C) [has_limit (discrete.functor f)] (b : β) : split_epi (pi.π f b) := { section_ := pi.lift (λ b', if h : b = b' then eq_to_hom (congr_arg f h) else 0), } /-- In the presence of zero morphisms, coprojections into a coproduct are (split) monomorphisms. -/ instance split_mono_coprod_inl [has_zero_morphisms C] {X Y : C} [has_colimit (pair X Y)] : split_mono (coprod.inl : X ⟶ X ⨿ Y) := { retraction := coprod.desc (𝟙 X) 0, } /-- In the presence of zero morphisms, coprojections into a coproduct are (split) monomorphisms. -/ instance split_mono_coprod_inr [has_zero_morphisms C] {X Y : C} [has_colimit (pair X Y)] : split_mono (coprod.inr : Y ⟶ X ⨿ Y) := { retraction := coprod.desc 0 (𝟙 Y), } /-- In the presence of zero morphisms, projections into a product are (split) epimorphisms. -/ instance split_epi_prod_fst [has_zero_morphisms C] {X Y : C} [has_limit (pair X Y)] : split_epi (prod.fst : X ⨯ Y ⟶ X) := { section_ := prod.lift (𝟙 X) 0, } /-- In the presence of zero morphisms, projections into a product are (split) epimorphisms. -/ instance split_epi_prod_snd [has_zero_morphisms C] {X Y : C} [has_limit (pair X Y)] : split_epi (prod.snd : X ⨯ Y ⟶ Y) := { section_ := prod.lift 0 (𝟙 Y), } end category_theory.limits
42e87f40b7d441a785c0772cf030d43711afe1d1
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/representation_theory/maschke_auto.lean
39476ba3f7e33651e907f2e97e61201d4698a323
[]
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
6,325
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Scott Morrison -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.algebra.monoid_algebra import Mathlib.algebra.invertible import Mathlib.algebra.char_p.basic import Mathlib.linear_algebra.basis import Mathlib.PostPort universes u namespace Mathlib /-! # Maschke's theorem We prove Maschke's theorem for finite groups, in the formulation that every submodule of a `k[G]` module has a complement, when `k` is a field with `¬(ring_char k ∣ fintype.card G)`. We do the core computation in greater generality. For any `[comm_ring k]` in which `[invertible (fintype.card G : k)]`, and a `k[G]`-linear map `i : V → W` which admits a `k`-linear retraction `π`, we produce a `k[G]`-linear retraction by taking the average over `G` of the conjugates of `π`. ## Future work It's not so far to give the usual statement, that every finite dimensional representation of a finite group is semisimple (i.e. a direct sum of irreducibles). -/ -- At first we work with any `[comm_ring k]`, and add the assumption that -- `[invertible (fintype.card G : k)]` when it is required. /-! We now do the key calculation in Maschke's theorem. Given `V → W`, an inclusion of `k[G]` modules,, assume we have some retraction `π` (i.e. `∀ v, π (i v) = v`), just as a `k`-linear map. (When `k` is a field, this will be available cheaply, by choosing a basis.) We now construct a retraction of the inclusion as a `k[G]`-linear map, by the formula $$ \frac{1}{|G|} \sum_{g \in G} g⁻¹ • π(g • -). $$ -/ namespace linear_map /-- We define the conjugate of `π` by `g`, as a `k`-linear map. -/ def conjugate {k : Type u} [comm_ring k] {G : Type u} [group G] {V : Type u} [add_comm_group V] [module k V] [module (monoid_algebra k G) V] [is_scalar_tower k (monoid_algebra k G) V] {W : Type u} [add_comm_group W] [module k W] [module (monoid_algebra k G) W] [is_scalar_tower k (monoid_algebra k G) W] (π : linear_map k W V) (g : G) : linear_map k W V := comp (comp (monoid_algebra.group_smul.linear_map k V (g⁻¹)) π) (monoid_algebra.group_smul.linear_map k W g) theorem conjugate_i {k : Type u} [comm_ring k] {G : Type u} [group G] {V : Type u} [add_comm_group V] [module k V] [module (monoid_algebra k G) V] [is_scalar_tower k (monoid_algebra k G) V] {W : Type u} [add_comm_group W] [module k W] [module (monoid_algebra k G) W] [is_scalar_tower k (monoid_algebra k G) W] (π : linear_map k W V) (i : linear_map (monoid_algebra k G) V W) (h : ∀ (v : V), coe_fn π (coe_fn i v) = v) (g : G) (v : V) : coe_fn (conjugate π g) (coe_fn i v) = v := sorry /-- The sum of the conjugates of `π` by each element `g : G`, as a `k`-linear map. (We postpone dividing by the size of the group as long as possible.) -/ def sum_of_conjugates {k : Type u} [comm_ring k] (G : Type u) [group G] {V : Type u} [add_comm_group V] [module k V] [module (monoid_algebra k G) V] [is_scalar_tower k (monoid_algebra k G) V] {W : Type u} [add_comm_group W] [module k W] [module (monoid_algebra k G) W] [is_scalar_tower k (monoid_algebra k G) W] (π : linear_map k W V) [fintype G] : linear_map k W V := finset.sum finset.univ fun (g : G) => conjugate π g /-- In fact, the sum over `g : G` of the conjugate of `π` by `g` is a `k[G]`-linear map. -/ def sum_of_conjugates_equivariant {k : Type u} [comm_ring k] (G : Type u) [group G] {V : Type u} [add_comm_group V] [module k V] [module (monoid_algebra k G) V] [is_scalar_tower k (monoid_algebra k G) V] {W : Type u} [add_comm_group W] [module k W] [module (monoid_algebra k G) W] [is_scalar_tower k (monoid_algebra k G) W] (π : linear_map k W V) [fintype G] : linear_map (monoid_algebra k G) W V := monoid_algebra.equivariant_of_linear_of_comm (sum_of_conjugates G π) sorry /-- We construct our `k[G]`-linear retraction of `i` as $$ \frac{1}{|G|} \sum_{g \in G} g⁻¹ • π(g • -). $$ -/ def equivariant_projection {k : Type u} [comm_ring k] (G : Type u) [group G] {V : Type u} [add_comm_group V] [module k V] [module (monoid_algebra k G) V] [is_scalar_tower k (monoid_algebra k G) V] {W : Type u} [add_comm_group W] [module k W] [module (monoid_algebra k G) W] [is_scalar_tower k (monoid_algebra k G) W] (π : linear_map k W V) [fintype G] [inv : invertible ↑(fintype.card G)] : linear_map (monoid_algebra k G) W V := ⅟ • sum_of_conjugates_equivariant G π theorem equivariant_projection_condition {k : Type u} [comm_ring k] (G : Type u) [group G] {V : Type u} [add_comm_group V] [module k V] [module (monoid_algebra k G) V] [is_scalar_tower k (monoid_algebra k G) V] {W : Type u} [add_comm_group W] [module k W] [module (monoid_algebra k G) W] [is_scalar_tower k (monoid_algebra k G) W] (π : linear_map k W V) (i : linear_map (monoid_algebra k G) V W) (h : ∀ (v : V), coe_fn π (coe_fn i v) = v) [fintype G] [inv : invertible ↑(fintype.card G)] (v : V) : coe_fn (equivariant_projection G π) (coe_fn i v) = v := sorry end linear_map -- Now we work over a `[field k]`, and replace the assumption `[invertible (fintype.card G : k)]` -- with `¬(ring_char k ∣ fintype.card G)`. theorem monoid_algebra.exists_left_inverse_of_injective {k : Type u} [field k] {G : Type u} [fintype G] [group G] {V : Type u} [add_comm_group V] [module k V] [module (monoid_algebra k G) V] [is_scalar_tower k (monoid_algebra k G) V] {W : Type u} [add_comm_group W] [module k W] [module (monoid_algebra k G) W] [is_scalar_tower k (monoid_algebra k G) W] (not_dvd : ¬ring_char k ∣ fintype.card G) (f : linear_map (monoid_algebra k G) V W) (hf : linear_map.ker f = ⊥) : ∃ (g : linear_map (monoid_algebra k G) W V), linear_map.comp g f = linear_map.id := sorry theorem monoid_algebra.submodule.exists_is_compl {k : Type u} [field k] {G : Type u} [fintype G] [group G] {V : Type u} [add_comm_group V] [module k V] [module (monoid_algebra k G) V] [is_scalar_tower k (monoid_algebra k G) V] (not_dvd : ¬ring_char k ∣ fintype.card G) (p : submodule (monoid_algebra k G) V) : ∃ (q : submodule (monoid_algebra k G) V), is_compl p q := sorry end Mathlib
d0f800fcf19e086c73f4a730921e8f75b2795ccc
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/scopedParsers2.lean
d9faa02fb6f6a8931abadea46ad7ff3ab4be0c33
[ "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
366
lean
namespace Foo def x := 10 end Foo #check Foo.x open Foo #check x theorem ex1 : x = Foo.x := rfl namespace Foo def f x y := x + y + 1 scoped infix:70 "^^" => f #check 1 ^^ 2 theorem ex1 : x ^^ y = f x y := rfl end Foo #check 1 ^^ 2 -- works because we have an `open Foo` above theorem ex2 : x ^^ y = f x y := rfl theorem ex3 : x ^^ y = Foo.f x y := rfl
1be9a4d98bab4f42c8f84cf6567569c399e8ce1e
cc060cf567f81c404a13ee79bf21f2e720fa6db0
/lean/natural-transformation-equality.lean
3f918fdaff0029fdc4bc2d9ac15cb6980e026c14
[ "Apache-2.0" ]
permissive
semorrison/proof
cf0a8c6957153bdb206fd5d5a762a75958a82bca
5ee398aa239a379a431190edbb6022b1a0aa2c70
refs/heads/master
1,610,414,502,842
1,518,696,851,000
1,518,696,851,000
78,375,937
2
1
null
null
null
null
UTF-8
Lean
false
false
2,280
lean
import standard meta def blast : tactic unit := using_smt $ return () structure Category := (Obj : Type) (Hom : Obj -> Obj -> Type) (identity : Π A : Obj, Hom A A) (compose : Π ⦃A B C : Obj⦄, Hom A B → Hom B C → Hom A C) (left_identity : Π ⦃A B : Obj⦄ (f : Hom A B), compose (identity _) f = f) (right_identity : Π ⦃A B : Obj⦄ (f : Hom A B), compose f (identity _) = f) (associativity : Π ⦃A B C D : Obj⦄ (f : Hom A B) (g : Hom B C) (h : Hom C D), compose (compose f g) h = compose f (compose g h)) attribute [class] Category structure Functor (C : Category) (D : Category) := (onObjects : C^.Obj → D^.Obj) (onMorphisms : Π ⦃A B : C^.Obj⦄, C^.Hom A B → D^.Hom (onObjects A) (onObjects B)) (identities : Π (A : C^.Obj), onMorphisms (C^.identity A) = D^.identity (onObjects A)) (functoriality : Π ⦃X Y Z : C^.Obj⦄ (f : C^.Hom X Y) (g : C^.Hom Y Z), onMorphisms (C^.compose f g) = D^.compose (onMorphisms f) (onMorphisms g)) attribute [class] Functor instance Functor_to_onObjects { C D : Category }: has_coe_to_fun (Functor C D) := { F := λ f, C^.Obj -> D^.Obj, coe := Functor.onObjects } namespace Functor infix `<$>`:50 := λ {C : Category} {D : Category} (F : Functor C D) {A B : C^.Obj} (f : C^.Hom A B), onMorphisms F f end Functor structure NaturalTransformation { C D : Category } ( F G : Functor C D ) := (components: Π A : C^.Obj, D^.Hom (F A) (G A)) (naturality: Π { A B : C^.Obj }, Π f : C^.Hom A B, D^.compose (F <$> f) (components B) = D^.compose (components A) (G <$> f)) instance NaturalTransformation_to_components { C D : Category } { F G : Functor C D } : has_coe_to_fun (NaturalTransformation F G) := { F := λ f, Π A : C^.Obj, D^.Hom (F A) (G A), coe := NaturalTransformation.components } -- We'll want to be able to prove that two natural transformations are equal if they are componentwise equal. lemma NaturalTransformations_componentwise_equal { C D : Category } { F G : Functor C D } ( α β : NaturalTransformation F G ) ( w: Π X : C^.Obj, α X = β X ) : α = β := begin induction α, induction β, -- Argh, how to complete this proof? exact sorry end
803cca72d1e058b20c56c1bcba1fde4687573a74
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/src/lake/Lake/Util/Binder.lean
21adec6e6a0fd8c9b93172c50c779ba67c80ce0e
[ "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,054
lean
/- Copyright (c) 2021 Mac Malone. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mac Malone -/ import Lean.Parser.Term import Lean.Elab.Term import Lean.Expr namespace Lake open Lean Parser abbrev Ellipsis := TSyntax ``Term.ellipsis abbrev NamedArgument := TSyntax ``Term.namedArgument abbrev Argument := TSyntax ``Term.argument instance : Coe Term Argument where coe s := ⟨s.raw⟩ instance : Coe Ellipsis Argument where coe s := ⟨s.raw⟩ instance : Coe NamedArgument Argument where coe s := ⟨s.raw⟩ abbrev Hole := TSyntax ``Term.hole abbrev BinderIdent := TSyntax ``Term.binderIdent abbrev TypeSpec := TSyntax ``Term.typeSpec def mkHoleFrom (ref : Syntax) : Hole := mkNode ``Term.hole #[mkAtomFrom ref "_"] instance : Coe Hole Term where coe s := ⟨s.raw⟩ instance : Coe Hole BinderIdent where coe s := ⟨s.raw⟩ instance : Coe Ident BinderIdent where coe s := ⟨s.raw⟩ abbrev BracketedBinder := TSyntax ``Term.bracketedBinder abbrev FunBinder := TSyntax ``Term.funBinder instance : Coe BinderIdent FunBinder where coe s := ⟨s.raw⟩ @[run_parser_attribute_hooks] def binder := Term.binderIdent <|> Term.bracketedBinder abbrev Binder := TSyntax ``binder instance : Coe Binder (TSyntax [identKind, ``Term.hole, ``Term.bracketedBinder]) where coe stx := ⟨stx.raw⟩ abbrev BinderModifier := TSyntax [``Term.binderTactic, ``Term.binderDefault] -------------------------------------------------------------------------------- -- Adapted from the private utilities in `Lean.Elab.Binders` structure BinderSyntaxView where id : Ident type : Term info : BinderInfo modifier? : Option BinderModifier := none def expandOptType (ref : Syntax) (optType : Syntax) : Term := if optType.isNone then mkHoleFrom ref else ⟨optType[0][1]⟩ def getBinderIds (ids : Syntax) : MacroM (Array BinderIdent) := ids.getArgs.mapM fun id => let k := id.getKind if k == identKind || k == `Lean.Parser.Term.hole then return ⟨id⟩ else Macro.throwErrorAt id "identifier or `_` expected" def expandBinderIdent (stx : Syntax) : MacroM Ident := match stx with | `(_) => (⟨·⟩) <$> Elab.Term.mkFreshIdent stx | _ => pure ⟨stx⟩ def expandOptIdent (stx : Syntax) : BinderIdent := if stx.isNone then mkHoleFrom stx else ⟨stx[0]⟩ def expandBinderType (ref : Syntax) (stx : Syntax) : Term := if stx.getNumArgs == 0 then mkHoleFrom ref else ⟨stx[1]⟩ def expandBinderModifier (optBinderModifier : Syntax) : Option BinderModifier := if optBinderModifier.isNone then none else some ⟨optBinderModifier[0]⟩ def matchBinder (stx : Syntax) : MacroM (Array BinderSyntaxView) := do let k := stx.getKind if stx.isIdent || k == ``Term.hole then -- binderIdent return #[{ id := (← expandBinderIdent stx), type := mkHoleFrom stx, info := .default }] else if k == ``Lean.Parser.Term.explicitBinder then -- `(` binderIdent+ binderType (binderDefault <|> binderTactic)? `)` let ids ← getBinderIds stx[1] let type := stx[2] let modifier? := expandBinderModifier stx[3] ids.mapM fun id => return { id := ← expandBinderIdent id, type := expandBinderType id type, info := .default, modifier? } else if k == ``Lean.Parser.Term.implicitBinder then -- `{` binderIdent+ binderType `}` let ids ← getBinderIds stx[1] let type := stx[2] ids.mapM fun id => return { id := ← expandBinderIdent id, type := expandBinderType id type, info := .implicit } else if k == ``Lean.Parser.Term.strictImplicitBinder then -- `⦃` binderIdent+ binderType `⦄` let ids ← getBinderIds stx[1] let type := stx[2] ids.mapM fun id => do pure { id := ← expandBinderIdent id, type := expandBinderType id type, info := .strictImplicit } else if k == ``Lean.Parser.Term.instBinder then -- `[` optIdent type `]` let id := expandOptIdent stx[1] let type := stx[2] return #[{id := ← expandBinderIdent id, type := ⟨type⟩, info := .instImplicit}] else Macro.throwUnsupported -------------------------------------------------------------------------------- def BinderSyntaxView.mkBinder : BinderSyntaxView → MacroM Binder | {id, type, info, modifier?} => do match info with | .default => `(binder| ($id : $type $[$modifier?]?)) | .implicit => `(binder| {$id : $type}) | .strictImplicit => `(binder| ⦃$id : $type⦄) | .instImplicit => `(binder| [$id : $type]) def BinderSyntaxView.mkArgument : BinderSyntaxView → MacroM NamedArgument | {id, ..} => `(Term.namedArgument| ($id := $id)) def expandBinders (dbs : Array Binder) : MacroM (Array Binder × Array Term) := do let mut bs := #[] let mut args : Array Term := #[] for db in dbs do let views ← matchBinder db.raw for view in views do bs := bs.push (← view.mkBinder) args := args.push ⟨(← view.mkArgument).raw⟩ return (bs, args)
a2e8684c4789aac0ca0d294a7fe59f951b7dfd07
63abd62053d479eae5abf4951554e1064a4c45b4
/src/ring_theory/polynomial_algebra.lean
b7dc62c466c3a819f3185e01ff7cf29763203466
[ "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
12,010
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import ring_theory.matrix_algebra import data.polynomial.algebra_map /-! # Algebra isomorphism between matrices of polynomials and polynomials of matrices Given `[comm_ring R] [ring A] [algebra R A]` we show `polynomial A ≃ₐ[R] (A ⊗[R] polynomial R)`. Combining this with the isomorphism `matrix n n A ≃ₐ[R] (A ⊗[R] matrix n n R)` proved earlier in `ring_theory.matrix_algebra`, we obtain the algebra isomorphism ``` def mat_poly_equiv : matrix n n (polynomial R) ≃ₐ[R] polynomial (matrix n n R) ``` which is characterized by ``` coeff (mat_poly_equiv m) k i j = coeff (m i j) k ``` We will use this algebra isomorphism to prove the Cayley-Hamilton theorem. -/ universes u v w open_locale tensor_product open polynomial open tensor_product open algebra.tensor_product (alg_hom_of_linear_map_tensor_product include_left) noncomputable theory variables (R A : Type*) variables [comm_semiring R] variables [semiring A] [algebra R A] namespace poly_equiv_tensor /-- (Implementation detail). The bare function underlying `A ⊗[R] polynomial R →ₐ[R] polynomial A`, on pure tensors. -/ def to_fun (a : A) (p : polynomial R) : polynomial A := p.sum (λ n r, monomial n (a * algebra_map R A r)) /-- (Implementation detail). The function underlying `A ⊗[R] polynomial R →ₐ[R] polynomial A`, as a linear map in the second factor. -/ def to_fun_linear_right (a : A) : polynomial R →ₗ[R] polynomial A := { to_fun := to_fun R A a, map_smul' := λ r p, begin dsimp [to_fun], rw finsupp.sum_smul_index, { dsimp [finsupp.sum], rw finset.smul_sum, apply finset.sum_congr rfl, intros k hk, rw [monomial_eq_smul_X, monomial_eq_smul_X, algebra.smul_def, ← C_mul', ← C_mul', ← mul_assoc], congr' 1, rw [← algebra.commutes, ← algebra.commutes], simp only [ring_hom.map_mul, polynomial.algebra_map_apply, mul_assoc], }, { intro i, simp only [ring_hom.map_zero, mul_zero, monomial_zero_right] }, end, map_add' := λ p q, begin simp only [to_fun], rw finsupp.sum_add_index, { simp only [monomial_zero_right, forall_const, ring_hom.map_zero, mul_zero], }, { intros i r s, simp only [ring_hom.map_add, mul_add, monomial_add], }, end, } /-- (Implementation detail). The function underlying `A ⊗[R] polynomial R →ₐ[R] polynomial A`, as a bilinear function of two arguments. -/ def to_fun_bilinear : A →ₗ[R] polynomial R →ₗ[R] polynomial A := { to_fun := to_fun_linear_right R A, map_smul' := by { intros, unfold to_fun_linear_right, congr, simp only [linear_map.coe_mk], unfold to_fun finsupp.sum, simp_rw [finset.smul_sum, smul_monomial, ← algebra.smul_mul_assoc], refl }, map_add' := by { intros, unfold to_fun_linear_right, congr, simp only [linear_map.coe_mk], unfold to_fun finsupp.sum, simp_rw [← finset.sum_add_distrib, ← monomial_add, ← add_mul], refl } } /-- (Implementation detail). The function underlying `A ⊗[R] polynomial R →ₐ[R] polynomial A`, as a linear map. -/ def to_fun_linear : A ⊗[R] polynomial R →ₗ[R] polynomial A := tensor_product.lift (to_fun_bilinear R A) -- We apparently need to provide the decidable instance here -- in order to successfully rewrite by this lemma. lemma to_fun_linear_mul_tmul_mul_aux_1 (p : polynomial R) (k : ℕ) (h : decidable (¬p.coeff k = 0)) (a : A) : ite (¬coeff p k = 0) (a * (algebra_map R A) (coeff p k)) 0 = a * (algebra_map R A) (coeff p k) := by { classical, split_ifs; simp *, } lemma to_fun_linear_mul_tmul_mul_aux_2 (k : ℕ) (a₁ a₂ : A) (p₁ p₂ : polynomial R) : a₁ * a₂ * (algebra_map R A) ((p₁ * p₂).coeff k) = (finset.nat.antidiagonal k).sum (λ x, a₁ * (algebra_map R A) (coeff p₁ x.1) * (a₂ * (algebra_map R A) (coeff p₂ x.2))) := begin simp_rw [mul_assoc, algebra.commutes, ←finset.mul_sum, mul_assoc, ←finset.mul_sum], congr, simp_rw [algebra.commutes (coeff p₂ _), coeff_mul, ring_hom.map_sum, ring_hom.map_mul], end lemma to_fun_linear_mul_tmul_mul (a₁ a₂ : A) (p₁ p₂ : polynomial R) : (to_fun_linear R A) ((a₁ * a₂) ⊗ₜ[R] p₁ * p₂) = (to_fun_linear R A) (a₁ ⊗ₜ[R] p₁) * (to_fun_linear R A) (a₂ ⊗ₜ[R] p₂) := begin dsimp [to_fun_linear], simp only [lift.tmul], dsimp [to_fun_bilinear, to_fun_linear_right, to_fun], ext k, -- TODO This is a bit annoying: the polynomial API is breaking down. have apply_eq_coeff : ∀ {p : ℕ →₀ R} {n : ℕ}, p n = coeff p n := by { intros, refl }, simp_rw [coeff_sum, coeff_monomial, finsupp.sum, finset.sum_ite_eq', finsupp.mem_support_iff, ne.def, coeff_mul, finset_sum_coeff, coeff_monomial, finset.sum_ite_eq', finsupp.mem_support_iff, ne.def, mul_ite, mul_zero, ite_mul, zero_mul, apply_eq_coeff], simp_rw [ite_mul_zero_left (¬coeff p₁ _ = 0) (a₁ * (algebra_map R A) (coeff p₁ _))], simp_rw [ite_mul_zero_right (¬coeff p₂ _ = 0) _ (_ * _)], simp_rw [to_fun_linear_mul_tmul_mul_aux_1, to_fun_linear_mul_tmul_mul_aux_2], end lemma to_fun_linear_algebra_map_tmul_one (r : R) : (to_fun_linear R A) ((algebra_map R A) r ⊗ₜ[R] 1) = (algebra_map R (polynomial A)) r := begin dsimp [to_fun_linear], simp only [lift.tmul], dsimp [to_fun_bilinear, to_fun_linear_right, to_fun], rw [← C_1, ←monomial_zero_left], refine (finsupp.sum_single_index _).trans _; simp [algebra_map_apply] end /-- (Implementation detail). The algebra homomorphism `A ⊗[R] polynomial R →ₐ[R] polynomial A`. -/ def to_fun_alg_hom : A ⊗[R] polynomial R →ₐ[R] polynomial A := alg_hom_of_linear_map_tensor_product (to_fun_linear R A) (to_fun_linear_mul_tmul_mul R A) (to_fun_linear_algebra_map_tmul_one R A) @[simp] lemma to_fun_alg_hom_apply_tmul (a : A) (p : polynomial R) : to_fun_alg_hom R A (a ⊗ₜ[R] p) = p.sum (λ n r, monomial n (a * (algebra_map R A) r)) := by simp [to_fun_alg_hom, to_fun_linear, to_fun_bilinear, to_fun_linear_right, to_fun] /-- (Implementation detail.) The bare function `polynomial A → A ⊗[R] polynomial R`. (We don't need to show that it's an algebra map, thankfully --- just that it's an inverse.) -/ def inv_fun (p : polynomial A) : A ⊗[R] polynomial R := p.eval₂ (include_left : A →ₐ[R] A ⊗[R] polynomial R) ((1 : A) ⊗ₜ[R] (X : polynomial R)) @[simp] lemma inv_fun_add {p q} : inv_fun R A (p + q) = inv_fun R A p + inv_fun R A q := by simp only [inv_fun, eval₂_add] lemma inv_fun_monomial (n : ℕ) (a : A) : inv_fun R A (monomial n a) = include_left a * ((1 : A) ⊗ₜ[R] (X : polynomial R)) ^ n := eval₂_monomial _ _ lemma left_inv (x : A ⊗ polynomial R) : inv_fun R A ((to_fun_alg_hom R A) x) = x := begin apply tensor_product.induction_on x, { simp [inv_fun], }, { intros a p, dsimp only [inv_fun], rw [to_fun_alg_hom_apply_tmul, eval₂_sum], simp_rw [eval₂_monomial, alg_hom.coe_to_ring_hom, algebra.tensor_product.tmul_pow, one_pow, algebra.tensor_product.include_left_apply, algebra.tensor_product.tmul_mul_tmul, mul_one, one_mul, ←algebra.commutes, ←algebra.smul_def'', smul_tmul], rw [finsupp.sum, ←tmul_sum], conv_rhs { rw [←sum_C_mul_X_eq p], }, simp only [algebra.smul_def''], refl, }, { intros p q hp hq, simp only [alg_hom.map_add, inv_fun_add, hp, hq], }, end lemma right_inv (x : polynomial A) : (to_fun_alg_hom R A) (inv_fun R A x) = x := begin apply polynomial.induction_on' x, { intros p q hp hq, simp only [inv_fun_add, alg_hom.map_add, hp, hq], }, { intros n a, rw [inv_fun_monomial, algebra.tensor_product.include_left_apply, algebra.tensor_product.tmul_pow, one_pow, algebra.tensor_product.tmul_mul_tmul, mul_one, one_mul, to_fun_alg_hom_apply_tmul, X_pow_eq_monomial], dsimp [monomial], rw [finsupp.sum_single_index]; simp, } end /-- (Implementation detail) The equivalence, ignoring the algebra structure, `(A ⊗[R] polynomial R) ≃ polynomial A`. -/ def equiv : (A ⊗[R] polynomial R) ≃ polynomial A := { to_fun := to_fun_alg_hom R A, inv_fun := inv_fun R A, left_inv := left_inv R A, right_inv := right_inv R A, } end poly_equiv_tensor open poly_equiv_tensor /-- The `R`-algebra isomorphism `polynomial A ≃ₐ[R] (A ⊗[R] polynomial R)`. -/ def poly_equiv_tensor : polynomial A ≃ₐ[R] (A ⊗[R] polynomial R) := alg_equiv.symm { ..(poly_equiv_tensor.to_fun_alg_hom R A), ..(poly_equiv_tensor.equiv R A) } @[simp] lemma poly_equiv_tensor_apply (p : polynomial A) : poly_equiv_tensor R A p = p.eval₂ (include_left : A →ₐ[R] A ⊗[R] polynomial R) ((1 : A) ⊗ₜ[R] (X : polynomial R)) := rfl @[simp] lemma poly_equiv_tensor_symm_apply_tmul (a : A) (p : polynomial R) : (poly_equiv_tensor R A).symm (a ⊗ₜ p) = p.sum (λ n r, monomial n (a * algebra_map R A r)) := begin simp [poly_equiv_tensor, to_fun_alg_hom, alg_hom_of_linear_map_tensor_product, to_fun_linear], refl, end open matrix open_locale big_operators variables {R} variables {n : Type w} [decidable_eq n] [fintype n] /-- The algebra isomorphism stating "matrices of polynomials are the same as polynomials of matrices". (You probably shouldn't attempt to use this underlying definition --- it's an algebra equivalence, and characterised extensionally by the lemma `mat_poly_equiv_coeff_apply` below.) -/ noncomputable def mat_poly_equiv : matrix n n (polynomial R) ≃ₐ[R] polynomial (matrix n n R) := (((matrix_equiv_tensor R (polynomial R) n)).trans (algebra.tensor_product.comm R _ _)).trans (poly_equiv_tensor R (matrix n n R)).symm open finset lemma mat_poly_equiv_coeff_apply_aux_1 (i j : n) (k : ℕ) (x : R) : mat_poly_equiv (std_basis_matrix i j $ monomial k x) = monomial k (std_basis_matrix i j x) := begin simp only [mat_poly_equiv, alg_equiv.trans_apply, matrix_equiv_tensor_apply_std_basis], apply (poly_equiv_tensor R (matrix n n R)).injective, simp only [alg_equiv.apply_symm_apply], convert algebra.tensor_product.comm_tmul _ _ _ _ _, simp only [poly_equiv_tensor_apply], convert eval₂_monomial _ _, simp only [algebra.tensor_product.tmul_mul_tmul, one_pow, one_mul, matrix.mul_one, algebra.tensor_product.tmul_pow, algebra.tensor_product.include_left_apply, mul_eq_mul], rw [monomial_eq_smul_X, ← tensor_product.smul_tmul], congr' with i' j'; simp end lemma mat_poly_equiv_coeff_apply_aux_2 (i j : n) (p : polynomial R) (k : ℕ) : coeff (mat_poly_equiv (std_basis_matrix i j p)) k = std_basis_matrix i j (coeff p k) := begin apply polynomial.induction_on' p, { intros p q hp hq, ext, simp [hp, hq, coeff_add, add_apply, std_basis_matrix_add], }, { intros k x, simp only [mat_poly_equiv_coeff_apply_aux_1, coeff_monomial], split_ifs; { funext, simp, }, } end @[simp] lemma mat_poly_equiv_coeff_apply (m : matrix n n (polynomial R)) (k : ℕ) (i j : n) : coeff (mat_poly_equiv m) k i j = coeff (m i j) k := begin apply matrix.induction_on' m, { simp, }, { intros p q hp hq, simp [hp, hq], }, { intros i' j' x, erw mat_poly_equiv_coeff_apply_aux_2, dsimp [std_basis_matrix], split_ifs, { rcases h with ⟨rfl, rfl⟩, simp [std_basis_matrix], }, { simp [std_basis_matrix, h], }, }, end @[simp] lemma mat_poly_equiv_symm_apply_coeff (p : polynomial (matrix n n R)) (i j : n) (k : ℕ) : coeff (mat_poly_equiv.symm p i j) k = coeff p k i j := begin have t : p = mat_poly_equiv (mat_poly_equiv.symm p) := by simp, conv_rhs { rw t, }, simp only [mat_poly_equiv_coeff_apply], end lemma mat_poly_equiv_smul_one (p : polynomial R) : mat_poly_equiv (p • 1) = p.map (algebra_map R (matrix n n R)) := begin ext m i j, simp only [coeff_map, one_apply, algebra_map_matrix_apply, mul_boole, smul_apply, mat_poly_equiv_coeff_apply], split_ifs; simp, end
583dab4af71f9d7b3cdf35a07d7a73aded758f26
2c096fdfecf64e46ea7bc6ce5521f142b5926864
/src/Lean/Elab/Tactic/Simp.lean
df13416168e902a7e074382c53a0e861d2a20f40
[ "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
Kha/lean4
1005785d2c8797ae266a303968848e5f6ce2fe87
b99e11346948023cd6c29d248cd8f3e3fb3474cf
refs/heads/master
1,693,355,498,027
1,669,080,461,000
1,669,113,138,000
184,748,176
0
0
Apache-2.0
1,665,995,520,000
1,556,884,930,000
Lean
UTF-8
Lean
false
false
14,731
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.Tactic.Simp import Lean.Meta.Tactic.Replace import Lean.Elab.BuiltinNotation import Lean.Elab.Tactic.Basic import Lean.Elab.Tactic.ElabTerm import Lean.Elab.Tactic.Location import Lean.Elab.Tactic.Config namespace Lean.Elab.Tactic open Meta open TSyntax.Compat open Simp (UsedSimps) declare_config_elab elabSimpConfigCore Meta.Simp.Config declare_config_elab elabSimpConfigCtxCore Meta.Simp.ConfigCtx declare_config_elab elabDSimpConfigCore Meta.DSimp.Config inductive SimpKind where | simp | simpAll | dsimp deriving Inhabited, BEq /-- Implement a `simp` discharge function using the given tactic syntax code. Recall that `simp` dischargers are in `SimpM` which does not have access to `Term.State`. We need access to `Term.State` to store messages and update the info tree. Thus, we create an `IO.ref` to track these changes at `Term.State` when we execute `tacticCode`. We must set this reference with the current `Term.State` before we execute `simp` using the generated `Simp.Discharge`. -/ def tacticToDischarge (tacticCode : Syntax) : TacticM (IO.Ref Term.State × Simp.Discharge) := do let tacticCode ← `(tactic| try ($tacticCode:tacticSeq)) let ref ← IO.mkRef (← getThe Term.State) let ctx ← readThe Term.Context let disch : Simp.Discharge := fun e => do let mvar ← mkFreshExprSyntheticOpaqueMVar e `simp.discharger let s ← ref.get let runTac? : TermElabM (Option Expr) := try /- We must only save messages and info tree changes. Recall that `simp` uses temporary metavariables (`withNewMCtxDepth`). So, we must not save references to them at `Term.State`. -/ withoutModifyingStateWithInfoAndMessages do Term.withSynthesize (mayPostpone := false) <| Term.runTactic mvar.mvarId! tacticCode let result ← instantiateMVars mvar if result.hasExprMVar then return none else return some result catch _ => return none let (result?, s) ← liftM (m := MetaM) <| Term.TermElabM.run runTac? ctx s ref.set s return result? return (ref, disch) inductive Simp.DischargeWrapper where | default | custom (ref : IO.Ref Term.State) (discharge : Simp.Discharge) def Simp.DischargeWrapper.with (w : Simp.DischargeWrapper) (x : Option Simp.Discharge → TacticM α) : TacticM α := do match w with | default => x none | custom ref d => ref.set (← getThe Term.State) try x d finally set (← ref.get) private def mkDischargeWrapper (optDischargeSyntax : Syntax) : TacticM Simp.DischargeWrapper := do if optDischargeSyntax.isNone then return Simp.DischargeWrapper.default else let (ref, d) ← tacticToDischarge optDischargeSyntax[0][3] return Simp.DischargeWrapper.custom ref d /- `optConfig` is of the form `("(" "config" ":=" term ")")?` -/ def elabSimpConfig (optConfig : Syntax) (kind : SimpKind) : TermElabM Meta.Simp.Config := do match kind with | .simp => elabSimpConfigCore optConfig | .simpAll => return (← elabSimpConfigCtxCore optConfig).toConfig | .dsimp => return { (← elabDSimpConfigCore optConfig) with } private def addDeclToUnfoldOrTheorem (thms : Meta.SimpTheorems) (id : Origin) (e : Expr) (post : Bool) (inv : Bool) (kind : SimpKind) : MetaM Meta.SimpTheorems := do if e.isConst then let declName := e.constName! let info ← getConstInfo declName if (← isProp info.type) then thms.addConst declName (post := post) (inv := inv) else if inv then throwError "invalid '←' modifier, '{declName}' is a declaration name to be unfolded" if kind == .dsimp then return thms.addDeclToUnfoldCore declName else thms.addDeclToUnfold declName else thms.add id #[] e (post := post) (inv := inv) private def addSimpTheorem (thms : Meta.SimpTheorems) (id : Origin) (stx : Syntax) (post : Bool) (inv : Bool) : TermElabM Meta.SimpTheorems := do let (levelParams, proof) ← Term.withoutModifyingElabMetaStateWithInfo <| withRef stx <| Term.withoutErrToSorry do let e ← Term.elabTerm stx none Term.synthesizeSyntheticMVars (mayPostpone := false) (ignoreStuckTC := true) let e ← instantiateMVars e let e := e.eta if e.hasMVar then let r ← abstractMVars e return (r.paramNames, r.expr) else return (#[], e) thms.add id levelParams proof (post := post) (inv := inv) structure ElabSimpArgsResult where ctx : Simp.Context starArg : Bool := false inductive ResolveSimpIdResult where | none | expr (e : Expr) | ext (ext : SimpExtension) /-- Elaborate extra simp theorems provided to `simp`. `stx` is of the form `"[" simpTheorem,* "]"` If `eraseLocal == true`, then we consider local declarations when resolving names for erased theorems (`- id`), this option only makes sense for `simp_all` or `*` is used. -/ def elabSimpArgs (stx : Syntax) (ctx : Simp.Context) (eraseLocal : Bool) (kind : SimpKind) : TacticM ElabSimpArgsResult := do if stx.isNone then return { ctx } else /- syntax simpPre := "↓" syntax simpPost := "↑" syntax simpLemma := (simpPre <|> simpPost)? term syntax simpErase := "-" ident -/ withMainContext do let mut thmsArray := ctx.simpTheorems let mut thms := thmsArray[0]! let mut starArg := false for arg in stx[1].getSepArgs do if arg.getKind == ``Lean.Parser.Tactic.simpErase then let fvar ← if eraseLocal || starArg then Term.isLocalIdent? arg[1] else pure none if let some fvar := fvar then -- We use `eraseCore` because the simp theorem for the hypothesis was not added yet thms := thms.eraseCore (.fvar fvar.fvarId!) else let declName ← resolveGlobalConstNoOverloadWithInfo arg[1] if ctx.config.autoUnfold then thms := thms.eraseCore (.decl declName) else thms ← thms.erase (.decl declName) else if arg.getKind == ``Lean.Parser.Tactic.simpLemma then let post := if arg[0].isNone then true else arg[0][0].getKind == ``Parser.Tactic.simpPost let inv := !arg[1].isNone let term := arg[2] match (← resolveSimpIdTheorem? term) with | .expr e => let name ← mkFreshId thms ← addDeclToUnfoldOrTheorem thms (.stx name arg) e post inv kind | .ext ext => thmsArray := thmsArray.push (← ext.getTheorems) | .none => let name ← mkFreshId thms ← addSimpTheorem thms (.stx name arg) term post inv else if arg.getKind == ``Lean.Parser.Tactic.simpStar then starArg := true else throwUnsupportedSyntax return { ctx := { ctx with simpTheorems := thmsArray.set! 0 thms }, starArg } where resolveSimpIdTheorem? (simpArgTerm : Term) : TacticM ResolveSimpIdResult := do let resolveExt (n : Name) : TacticM ResolveSimpIdResult := do if let some ext ← getSimpExtension? n then return .ext ext else return .none match simpArgTerm with | `($id:ident) => try if let some e ← Term.resolveId? simpArgTerm (withInfo := true) then return .expr e else resolveExt id.getId.eraseMacroScopes catch _ => resolveExt id.getId.eraseMacroScopes | _ => if let some e ← Term.elabCDotFunctionAlias? simpArgTerm then return .expr e else return .none @[inline] def simpOnlyBuiltins : List Name := [``eq_self] structure MkSimpContextResult where ctx : Simp.Context dischargeWrapper : Simp.DischargeWrapper /-- Create the `Simp.Context` for the `simp`, `dsimp`, and `simp_all` tactics. If `kind != SimpKind.simp`, the `discharge` option must be `none` TODO: generate error message if non `rfl` theorems are provided as arguments to `dsimp`. -/ def mkSimpContext (stx : Syntax) (eraseLocal : Bool) (kind := SimpKind.simp) (ignoreStarArg : Bool := false) : TacticM MkSimpContextResult := do if !stx[2].isNone then if kind == SimpKind.simpAll then throwError "'simp_all' tactic does not support 'discharger' option" if kind == SimpKind.dsimp then throwError "'dsimp' tactic does not support 'discharger' option" let dischargeWrapper ← mkDischargeWrapper stx[2] let simpOnly := !stx[3].isNone let simpTheorems ← if simpOnly then simpOnlyBuiltins.foldlM (·.addConst ·) ({} : SimpTheorems) else getSimpTheorems let congrTheorems ← getSimpCongrTheorems let r ← elabSimpArgs stx[4] (eraseLocal := eraseLocal) (kind := kind) { config := (← elabSimpConfig stx[1] (kind := kind)) simpTheorems := #[simpTheorems], congrTheorems } if !r.starArg || ignoreStarArg then return { r with dischargeWrapper } else let ctx := r.ctx let mut simpTheorems := ctx.simpTheorems let hs ← getPropHyps for h in hs do unless simpTheorems.isErased (.fvar h) do simpTheorems ← simpTheorems.addTheorem (.fvar h) (← h.getDecl).toExpr let ctx := { ctx with simpTheorems } return { ctx, dischargeWrapper } register_builtin_option tactic.simp.trace : Bool := { defValue := false descr := "When tracing is enabled, calls to `simp` or `dsimp` will print an equivalent `simp only` call." } def traceSimpCall (stx : Syntax) (usedSimps : UsedSimps) : MetaM Unit := do let mut stx := stx if stx[3].isNone then stx := stx.setArg 3 (mkNullNode #[mkAtom "only"]) let mut args := #[] let mut localsOrStar := some #[] let lctx ← getLCtx let env ← getEnv for (thm, _) in usedSimps.toArray.qsort (·.2 < ·.2) do match thm with | .decl declName => -- global definitions in the environment if env.contains declName && !simpOnlyBuiltins.contains declName then args := args.push (← `(Parser.Tactic.simpLemma| $(mkIdent (← unresolveNameGlobal declName)):ident)) | .fvar fvarId => -- local hypotheses in the context if let some ldecl := lctx.find? fvarId then localsOrStar := localsOrStar.bind fun locals => if !ldecl.userName.isInaccessibleUserName && (lctx.findFromUserName? ldecl.userName).get!.fvarId == ldecl.fvarId then some (locals.push ldecl.userName) else none -- Note: the `if let` can fail for `simp (config := {contextual := true})` when -- rewriting with a variable that was introduced in a scope. In that case we just ignore. | .stx _ thmStx => -- simp theorems provided in the local invocation args := args.push thmStx | .other _ => -- Ignore "special" simp lemmas such as constructed by `simp_all`. pure () -- We can't display them anyway. if let some locals := localsOrStar then args := args ++ (← locals.mapM fun id => `(Parser.Tactic.simpLemma| $(mkIdent id):ident)) else args := args.push (← `(Parser.Tactic.simpStar| *)) let argsStx := if args.isEmpty then #[] else #[mkAtom "[", (mkAtom ",").mkSep args, mkAtom "]"] stx := stx.setArg 4 (mkNullNode argsStx) logInfoAt stx[0] m!"Try this: {stx}" /-- `simpLocation ctx discharge? varIdToLemmaId loc` runs the simplifier at locations specified by `loc`, using the simp theorems collected in `ctx` optionally running a discharger specified in `discharge?` on generated subgoals. Its primary use is as the implementation of the `simp [...] at ...` and `simp only [...] at ...` syntaxes, but can also be used by other tactics when a `Syntax` is not available. For many tactics other than the simplifier, one should use the `withLocation` tactic combinator when working with a `location`. -/ def simpLocation (ctx : Simp.Context) (discharge? : Option Simp.Discharge := none) (loc : Location) : TacticM UsedSimps := do match loc with | Location.targets hyps simplifyTarget => withMainContext do let fvarIds ← getFVarIds hyps go fvarIds simplifyTarget | Location.wildcard => withMainContext do go (← (← getMainGoal).getNondepPropHyps) (simplifyTarget := true) where go (fvarIdsToSimp : Array FVarId) (simplifyTarget : Bool) : TacticM UsedSimps := do let mvarId ← getMainGoal let (result?, usedSimps) ← simpGoal mvarId ctx (simplifyTarget := simplifyTarget) (discharge? := discharge?) (fvarIdsToSimp := fvarIdsToSimp) match result? with | none => replaceMainGoal [] | some (_, mvarId) => replaceMainGoal [mvarId] return usedSimps /- "simp " (config)? (discharger)? ("only ")? ("[" simpLemma,* "]")? (location)? -/ @[builtin_tactic Lean.Parser.Tactic.simp] def evalSimp : Tactic := fun stx => do let { ctx, dischargeWrapper } ← withMainContext <| mkSimpContext stx (eraseLocal := false) let usedSimps ← dischargeWrapper.with fun discharge? => simpLocation ctx discharge? (expandOptLocation stx[5]) if tactic.simp.trace.get (← getOptions) then traceSimpCall stx usedSimps @[builtin_tactic Lean.Parser.Tactic.simpAll] def evalSimpAll : Tactic := fun stx => do let { ctx, .. } ← mkSimpContext stx (eraseLocal := true) (kind := .simpAll) (ignoreStarArg := true) let (result?, usedSimps) ← simpAll (← getMainGoal) ctx match result? with | none => replaceMainGoal [] | some mvarId => replaceMainGoal [mvarId] if tactic.simp.trace.get (← getOptions) then traceSimpCall stx usedSimps def dsimpLocation (ctx : Simp.Context) (loc : Location) : TacticM Unit := do match loc with | Location.targets hyps simplifyTarget => withMainContext do let fvarIds ← getFVarIds hyps go fvarIds simplifyTarget | Location.wildcard => withMainContext do go (← (← getMainGoal).getNondepPropHyps) (simplifyTarget := true) where go (fvarIdsToSimp : Array FVarId) (simplifyTarget : Bool) : TacticM Unit := do let mvarId ← getMainGoal let (result?, usedSimps) ← dsimpGoal mvarId ctx (simplifyTarget := simplifyTarget) (fvarIdsToSimp := fvarIdsToSimp) match result? with | none => replaceMainGoal [] | some mvarId => replaceMainGoal [mvarId] if tactic.simp.trace.get (← getOptions) then traceSimpCall (← getRef) usedSimps @[builtin_tactic Lean.Parser.Tactic.dsimp] def evalDSimp : Tactic := fun stx => do let { ctx, .. } ← withMainContext <| mkSimpContext stx (eraseLocal := false) (kind := .dsimp) dsimpLocation ctx (expandOptLocation stx[5]) end Lean.Elab.Tactic
6a891f779f1f30ee1b0733c489cf2884578284a7
4727251e0cd73359b15b664c3170e5d754078599
/src/linear_algebra/vandermonde.lean
4e4575cfe459e01613ce3f09c3dbd3ceb8585079
[ "Apache-2.0" ]
permissive
Vierkantor/mathlib
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
refs/heads/master
1,658,323,012,449
1,652,256,003,000
1,652,256,003,000
209,296,341
0
1
Apache-2.0
1,568,807,655,000
1,568,807,655,000
null
UTF-8
Lean
false
false
4,788
lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import algebra.big_operators.fin import algebra.geom_sum import group_theory.perm.fin import linear_algebra.matrix.determinant import tactic.ring_exp /-! # Vandermonde matrix This file defines the `vandermonde` matrix and gives its determinant. ## Main definitions - `vandermonde v`: a square matrix with the `i, j`th entry equal to `v i ^ j`. ## Main results - `det_vandermonde`: `det (vandermonde v)` is the product of `v i - v j`, where `(i, j)` ranges over the unordered pairs. -/ variables {R : Type*} [comm_ring R] open_locale big_operators open_locale matrix open equiv namespace matrix /-- `vandermonde v` is the square matrix with `i`th row equal to `1, v i, v i ^ 2, v i ^ 3, ...`. -/ def vandermonde {n : ℕ} (v : fin n → R) : matrix (fin n) (fin n) R := λ i j, v i ^ (j : ℕ) @[simp] lemma vandermonde_apply {n : ℕ} (v : fin n → R) (i j) : vandermonde v i j = v i ^ (j : ℕ) := rfl @[simp] lemma vandermonde_cons {n : ℕ} (v0 : R) (v : fin n → R) : vandermonde (fin.cons v0 v : fin n.succ → R) = fin.cons (λ j, v0 ^ (j : ℕ)) (λ i, fin.cons 1 (λ j, v i * vandermonde v i j)) := begin ext i j, refine fin.cases (by simp) (λ i, _) i, refine fin.cases (by simp) (λ j, _) j, simp [pow_succ] end lemma vandermonde_succ {n : ℕ} (v : fin n.succ → R) : vandermonde v = fin.cons (λ j, v 0 ^ (j : ℕ)) (λ i, fin.cons 1 (λ j, v i.succ * vandermonde (fin.tail v) i j)) := begin conv_lhs { rw [← fin.cons_self_tail v, vandermonde_cons] }, simp only [fin.tail] end lemma vandermonde_mul_vandermonde_transpose {n : ℕ} (v w : fin n → R) (i j) : (vandermonde v ⬝ (vandermonde w)ᵀ) i j = ∑ (k : fin n), (v i * w j) ^ (k : ℕ) := by simp only [vandermonde_apply, matrix.mul_apply, matrix.transpose_apply, mul_pow] lemma vandermonde_transpose_mul_vandermonde {n : ℕ} (v : fin n → R) (i j) : ((vandermonde v)ᵀ ⬝ vandermonde v) i j = ∑ (k : fin n), v k ^ (i + j : ℕ) := by simp only [vandermonde_apply, matrix.mul_apply, matrix.transpose_apply, pow_add] lemma det_vandermonde {n : ℕ} (v : fin n → R) : det (vandermonde v) = ∏ i : fin n, ∏ j in finset.univ.filter (λ j, i < j), (v j - v i) := begin unfold vandermonde, induction n with n ih, { exact det_eq_one_of_card_eq_zero (fintype.card_fin 0) }, calc det (λ (i j : fin n.succ), v i ^ (j : ℕ)) = det (λ (i j : fin n.succ), @fin.cons _ (λ _, R) (v 0 ^ (j : ℕ)) (λ i, v (fin.succ i) ^ (j : ℕ) - v 0 ^ (j : ℕ)) i) : det_eq_of_forall_row_eq_smul_add_const (fin.cons 0 1) 0 (fin.cons_zero _ _) _ ... = det (λ (i j : fin n), @fin.cons _ (λ _, R) (v 0 ^ (j.succ : ℕ)) (λ (i : fin n), v (fin.succ i) ^ (j.succ : ℕ) - v 0 ^ (j.succ : ℕ)) (fin.succ_above 0 i)) : by simp_rw [det_succ_column_zero, fin.sum_univ_succ, fin.cons_zero, minor, fin.cons_succ, fin.coe_zero, pow_zero, one_mul, sub_self, mul_zero, zero_mul, finset.sum_const_zero, add_zero] ... = det (λ (i j : fin n), (v (fin.succ i) - v 0) * (∑ k in finset.range (j + 1 : ℕ), v i.succ ^ k * v 0 ^ (j - k : ℕ))) : by { congr, ext i j, rw [fin.succ_above_zero, fin.cons_succ, fin.coe_succ, mul_comm], exact (geom_sum₂_mul (v i.succ) (v 0) (j + 1 : ℕ)).symm } ... = (∏ (i : fin n), (v (fin.succ i) - v 0)) * det (λ (i j : fin n), (∑ k in finset.range (j + 1 : ℕ), v i.succ ^ k * v 0 ^ (j - k : ℕ))) : det_mul_column (λ i, v (fin.succ i) - v 0) _ ... = (∏ (i : fin n), (v (fin.succ i) - v 0)) * det (λ (i j : fin n), v (fin.succ i) ^ (j : ℕ)) : congr_arg ((*) _) _ ... = ∏ i : fin n.succ, ∏ j in finset.univ.filter (λ j, i < j), (v j - v i) : by { simp_rw [ih (v ∘ fin.succ), fin.prod_univ_succ, fin.prod_filter_zero_lt, fin.prod_filter_succ_lt] }, { intros i j, rw fin.cons_zero, refine fin.cases _ (λ i, _) i, { simp }, rw [fin.cons_succ, fin.cons_succ, pi.one_apply], ring }, { cases n, { simp only [det_eq_one_of_card_eq_zero (fintype.card_fin 0)] }, apply det_eq_of_forall_col_eq_smul_add_pred (λ i, v 0), { intro j, simp }, { intros i j, simp only [smul_eq_mul, pi.add_apply, fin.coe_succ, fin.coe_cast_succ, pi.smul_apply], rw [finset.sum_range_succ, add_comm, tsub_self, pow_zero, mul_one, finset.mul_sum], congr' 1, refine finset.sum_congr rfl (λ i' hi', _), rw [mul_left_comm (v 0), nat.succ_sub, pow_succ], exact nat.lt_succ_iff.mp (finset.mem_range.mp hi') } } end end matrix
74dbec131e38ca6293fb608761f1bef597ece1b1
a11f4536efad51bc2b648123619720f3b9318c0f
/src/google_tree_interview.lean
bee9d89de315c7e5516bab947cb40c21638c91dc
[]
no_license
ezrasitorus/codewars_lean
909471d43f5130669a90b8e11afc37aec2f21d8f
6d1abcc1253403511f4cfd767c645596175e4fd3
refs/heads/master
1,672,659,589,352
1,603,281,507,000
1,603,281,507,000
288,579,451
0
0
null
null
null
null
UTF-8
Lean
false
false
519
lean
universes u inductive mytree (A : Type u) : Type u | leaf : A → mytree | branch : A → mytree → mytree → mytree def flip_mytree {A : Type u} : mytree A → mytree A | t@(mytree.leaf _) := t | (mytree.branch a l r) := mytree.branch a (flip_mytree r) (flip_mytree l) theorem flip_flip {A : Type u} {t : mytree A} : flip_mytree (flip_mytree t) = t := begin induction t with t a l r hl hr, { rw [flip_mytree, flip_mytree], }, { rw [flip_mytree, flip_mytree, hr, hl], }, end
c2e879f9b4e9d36bd331d1e8afa9c57506ae6902
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/ring_theory/euclidean_domain_auto.lean
ce732ffd9fb2056c55458b84d8981df4aa18568d
[]
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
1,525
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Chris Hughes -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.ring_theory.coprime import Mathlib.ring_theory.ideal.basic import Mathlib.PostPort universes u_1 namespace Mathlib /-! # Lemmas about Euclidean domains Various about Euclidean domains are proved; all of them seem to be true more generally for principal ideal domains, so these lemmas should probably be reproved in more generality and this file perhaps removed? ## Tags euclidean domain -/ -- TODO -- this should surely be proved for PIDs instead? theorem span_gcd {α : Type u_1} [euclidean_domain α] (x : α) (y : α) : ideal.span (singleton (euclidean_domain.gcd x y)) = ideal.span (insert x (singleton y)) := sorry -- this should be proved for PIDs? theorem gcd_is_unit_iff {α : Type u_1} [euclidean_domain α] {x : α} {y : α} : is_unit (euclidean_domain.gcd x y) ↔ is_coprime x y := sorry -- this should be proved for UFDs surely? theorem is_coprime_of_dvd {α : Type u_1} [euclidean_domain α] {x : α} {y : α} (z : ¬(x = 0 ∧ y = 0)) (H : ∀ (z : α), z ∈ nonunits α → z ≠ 0 → z ∣ x → ¬z ∣ y) : is_coprime x y := sorry -- this should be proved for UFDs surely? theorem dvd_or_coprime {α : Type u_1} [euclidean_domain α] (x : α) (y : α) (h : irreducible x) : x ∣ y ∨ is_coprime x y := sorry end Mathlib
f17eaf087c9f376c5b686a03283c8ff0e29498d7
dcf093fda1f51c094394c50e182cfb9dec39635a
/cardinality.lean
6383b4d76f0ba4354433c4691da96719fe490d77
[]
no_license
dselsam/cs103
7ac496d0293befca95d3045add91c5270a5d291f
31ab9784a6f65f226efb702a0da52f907c616a71
refs/heads/master
1,611,092,644,140
1,492,571,015,000
1,492,571,015,000
88,693,969
1
0
null
null
null
null
UTF-8
Lean
false
false
1,328
lean
import data.nat data.set algebra.binary open nat set quot binary function definition injective [reducible] {T U : Type} (f : T → U) := ∀ (x y : T), f x = f y → x = y private definition equiv (T1 T2 : Type) := ∃ (f : T1 → T2), bijective f local infix ~ := equiv private definition equiv.refl (T : Type) : T ~ T := sorry private definition equiv.symm ⦃T1 T2 : Type⦄ : T1 ~ T2 → T2 ~ T1 := sorry private definition equiv.trans ⦃T1 T2 T3 : Type⦄ : T1 ~ T2 → T2 ~ T3 → T1 ~ T3 := sorry definition cardinality.bij_setoid [instance] : setoid Type := setoid.mk equiv (mk_equivalence equiv equiv.refl equiv.symm equiv.trans) definition cardinality : Type := quot cardinality.bij_setoid namespace cardinality definition aleph_zero := ⟦ ℕ ⟧ definition le [reducible] (C1 C2 : cardinality) : Prop := quot.lift_on₂ C1 C2 (λ T1 T2, ∃ (f : T1 → T2), injective f) sorry infix `≤` := le definition lt [reducible] (C1 C2 : cardinality) : Prop := C1 ≤ C2 ∧ C1 ≠ C2 infix `<` := lt theorem cantor (T : Type) : ⟦T⟧ < ⟦T → bool⟧ := assume (C : ⟦T⟧), quot.rec₂ -- proof that there is an injection from T to T → bool -- proof that it doesn't matter which representatives you choose (rep1 → T → (T → bool) → rep2) using the given bijections end cardinality
05418c882486cd6b42f164f4cf54cfe39305e808
a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940
/tests/lean/run/newfrontend5.lean
271391dbf792ed6ee4a543f4e8bf59395f94bb7d
[ "Apache-2.0" ]
permissive
WojciechKarpiel/lean4
7f89706b8e3c1f942b83a2c91a3a00b05da0e65b
f6e1314fa08293dea66a329e05b6c196a0189163
refs/heads/master
1,686,633,402,214
1,625,821,189,000
1,625,821,258,000
384,640,886
0
0
Apache-2.0
1,625,903,617,000
1,625,903,026,000
null
UTF-8
Lean
false
false
1,953
lean
def foo {α} (f : {β : Type _} → β → β) (a : α) : α := f a #check_failure let g := id; foo g true -- fails /- Expands to ``` let g : ?γ → ?γ := @id ?γ; @foo ?α (fun (β : Sort ?u) => g) true ``` Unification constraint ``` ?γ → ?γ =?= β → β ``` fails because `β` is not in the scope of `?γ` Error message can be improved because it doesn't make it clear the issue is the scope of the metavariable. Not sure yet how to improve it. -/ #check_failure (fun g => foo g 2) id -- fails for the same reason the previous one fail. #check let g := @id; foo @g true -- works /- Expands into ``` let g : {γ : Sort ?v} → γ → γ := @id; @foo ?α @g true ``` Note that `@g` also disables implicit lambdas. The unification constraint is easily solved ``` {γ : Sort ?v} → γ → γ =?= {β : Sort ?u} → β → β ``` -/ #check foo id true -- works #check foo @id true -- works #check foo (fun b => b) true -- works #check foo @(fun β b => b) true -- works #check_failure foo @(fun b => b) true -- fails as expected, and error message is clear #check foo @(fun β b => b) true -- works (implicit lambdas were disabled) set_option pp.all true #check let x := (fun f => (f, f)) @id; (x.1 (), x.2 true) -- works #check_failure let x := (fun f => (f, f)) id; (x.1 (), x.2 true) -- fails as expected -- #check let x := (fun (f : {α : Type} → α → α) => (f, f)) @id; (x.1 (), x.2 true) -- we need constApprox := true for this one -- #check let x := (fun (f : {α : Type} → α → α) => (f, f)) @id; (x.1 [], x.2 true) -- we need constApprox := true for this one set_option pp.all false set_option pp.explicit true def h (x := 10) (y := 20) : Nat := x + y #check h -- h 10 20 : Nat #check let f := @h; f -- (let f : optParam Nat 10 → optParam Nat 20 → Nat := @h; f 10 20) : Nat #check let f := fun (x : optParam Nat 10) => x + 1; f + f 1 #check (fun (x : optParam Nat 10) => x) #check let_fun x := 10; x + 1
93a628ebe22630da25a821836d737995d345eb86
fcf3ffa92a3847189ca669cb18b34ef6b2ec2859
/src/world5/level4.lean
a1a7aea3c0edc3f400a7069833ae05e862c44587
[ "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
169
lean
example (P Q R S T U: Type) (p: P) (h: P → Q) (i: Q → R) (j: Q → T) (k: S → T) (l: T → U) : U := begin apply l, apply j, apply h, exact p, end
3f4f5284f9bd9f2e67012b263cfed91caecbfa9d
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/ring_theory/graded_algebra/basic.lean
fae06aaac6fc8a669fbd2aba2a1e6413a3fadf54
[ "Apache-2.0" ]
permissive
robertylewis/mathlib
3d16e3e6daf5ddde182473e03a1b601d2810952c
1d13f5b932f5e40a8308e3840f96fc882fae01f0
refs/heads/master
1,651,379,945,369
1,644,276,960,000
1,644,276,960,000
98,875,504
0
0
Apache-2.0
1,644,253,514,000
1,501,495,700,000
Lean
UTF-8
Lean
false
false
7,127
lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Kevin Buzzard, Jujian Zhang -/ import algebra.direct_sum.algebra import algebra.direct_sum.internal import algebra.direct_sum.ring import group_theory.subgroup.basic /-! # Internally-graded algebras This file defines the typeclass `graded_algebra 𝒜`, for working with an algebra `A` that is internally graded by a collection of submodules `𝒜 : ι → submodule R A`. See the docstring of that typeclass for more information. ## Main definitions * `graded_algebra 𝒜`: the typeclass, which is a combination of `set_like.graded_monoid`, and a constructive version of `direct_sum.submodule_is_internal 𝒜`. * `graded_algebra.decompose : A ≃ₐ[R] ⨁ i, 𝒜 i`, which breaks apart an element of the algebra into its constituent pieces. * `graded_algebra.proj 𝒜 i` is the linear map from `A` to its degree `i : ι` component, such that `proj 𝒜 i x = decompose 𝒜 x i`. * `graded_algebra.support 𝒜 r` is the `finset ι` containing the `i : ι` such that the degree `i` component of `r` is not zero. ## Implementation notes For now, we do not have internally-graded semirings and internally-graded rings; these can be represented with `𝒜 : ι → submodule ℕ A` and `𝒜 : ι → submodule ℤ A` respectively, since all `semiring`s are ℕ-algebras via `algebra_nat`, and all `ring`s are `ℤ`-algebras via `algebra_int`. ## Tags graded algebra, graded ring, graded semiring, decomposition -/ open_locale direct_sum big_operators section graded_algebra variables {ι R A : Type*} variables [decidable_eq ι] [add_comm_monoid ι] [comm_semiring R] [semiring A] [algebra R A] variables (𝒜 : ι → submodule R A) /-- An internally-graded `R`-algebra `A` is one that can be decomposed into a collection of `submodule R A`s indexed by `ι` such that the canonical map `A → ⨁ i, 𝒜 i` is bijective and respects multiplication, i.e. the product of an element of degree `i` and an element of degree `j` is an element of degree `i + j`. Note that the fact that `A` is internally-graded, `graded_algebra 𝒜`, implies an externally-graded algebra structure `direct_sum.galgebra R (λ i, ↥(𝒜 i))`, which in turn makes available an `algebra R (⨁ i, 𝒜 i)` instance. -/ class graded_algebra extends set_like.graded_monoid 𝒜 := (decompose' : A → ⨁ i, 𝒜 i) (left_inv : function.left_inverse decompose' (direct_sum.submodule_coe 𝒜)) (right_inv : function.right_inverse decompose' (direct_sum.submodule_coe 𝒜)) lemma graded_algebra.is_internal [graded_algebra 𝒜] : direct_sum.submodule_is_internal 𝒜 := ⟨graded_algebra.left_inv.injective, graded_algebra.right_inv.surjective⟩ /-- A helper to construct a `graded_algebra` when the `set_like.graded_monoid` structure is already available. This makes the `left_inv` condition easier to prove, and phrases the `right_inv` condition in a way that allows custom `@[ext]` lemmas to apply. See note [reducible non-instances]. -/ @[reducible] def graded_algebra.of_alg_hom [set_like.graded_monoid 𝒜] (decompose : A →ₐ[R] ⨁ i, 𝒜 i) (right_inv : (direct_sum.submodule_coe_alg_hom 𝒜).comp decompose = alg_hom.id R A) (left_inv : ∀ i (x : 𝒜 i), decompose (x : A) = direct_sum.of (λ i, ↥(𝒜 i)) i x) : graded_algebra 𝒜 := { decompose' := decompose, right_inv := alg_hom.congr_fun right_inv, left_inv := begin suffices : decompose.comp (direct_sum.submodule_coe_alg_hom 𝒜) = alg_hom.id _ _, from alg_hom.congr_fun this, ext i x : 2, exact (decompose.congr_arg $ direct_sum.submodule_coe_alg_hom_of _ _ _).trans (left_inv i x), end} variable [graded_algebra 𝒜] /-- If `A` is graded by `ι` with degree `i` component `𝒜 i`, then it is isomorphic as an algebra to a direct sum of components. -/ def graded_algebra.decompose : A ≃ₐ[R] ⨁ i, 𝒜 i := alg_equiv.symm { to_fun := direct_sum.submodule_coe_alg_hom 𝒜, inv_fun := graded_algebra.decompose', left_inv := graded_algebra.left_inv, right_inv := graded_algebra.right_inv, map_mul' := alg_hom.map_mul _, map_add' := alg_hom.map_add _, commutes' := alg_hom.commutes _ } @[simp] lemma graded_algebra.decompose'_def : graded_algebra.decompose' = graded_algebra.decompose 𝒜 := rfl @[simp] lemma graded_algebra.decompose_symm_of {i : ι} (x : 𝒜 i) : (graded_algebra.decompose 𝒜).symm (direct_sum.of _ i x) = x := direct_sum.submodule_coe_alg_hom_of 𝒜 _ _ /-- The projection maps of graded algebra-/ def graded_algebra.proj (𝒜 : ι → submodule R A) [graded_algebra 𝒜] (i : ι) : A →ₗ[R] A := (𝒜 i).subtype.comp $ (dfinsupp.lapply i).comp $ (graded_algebra.decompose 𝒜).to_alg_hom.to_linear_map @[simp] lemma graded_algebra.proj_apply (i : ι) (r : A) : graded_algebra.proj 𝒜 i r = (graded_algebra.decompose 𝒜 r : ⨁ i, 𝒜 i) i := rfl /-- The support of `r` is the `finset` where `proj R A i r ≠ 0 ↔ i ∈ r.support`-/ def graded_algebra.support [Π (i : ι) (x : 𝒜 i), decidable (x ≠ 0)] (r : A) : finset ι := (graded_algebra.decompose 𝒜 r).support lemma graded_algebra.proj_recompose (a : ⨁ i, 𝒜 i) (i : ι) : graded_algebra.proj 𝒜 i ((graded_algebra.decompose 𝒜).symm a) = (graded_algebra.decompose 𝒜).symm (direct_sum.of _ i (a i)) := by rw [graded_algebra.proj_apply, graded_algebra.decompose_symm_of, alg_equiv.apply_symm_apply] @[simp] lemma graded_algebra.decompose_coe {i : ι} (x : 𝒜 i) : graded_algebra.decompose 𝒜 x = direct_sum.of _ i x := by rw [←graded_algebra.decompose_symm_of, alg_equiv.apply_symm_apply] lemma graded_algebra.decompose_of_mem {x : A} {i : ι} (hx : x ∈ 𝒜 i) : graded_algebra.decompose 𝒜 x = direct_sum.of _ i (⟨x, hx⟩ : 𝒜 i) := graded_algebra.decompose_coe _ ⟨x, hx⟩ lemma graded_algebra.decompose_of_mem_same {x : A} {i : ι} (hx : x ∈ 𝒜 i) : (graded_algebra.decompose 𝒜 x i : A) = x := by rw [graded_algebra.decompose_of_mem _ hx, direct_sum.of_eq_same, subtype.coe_mk] lemma graded_algebra.decompose_of_mem_ne {x : A} {i j : ι} (hx : x ∈ 𝒜 i) (hij : i ≠ j): (graded_algebra.decompose 𝒜 x j : A) = 0 := by rw [graded_algebra.decompose_of_mem _ hx, direct_sum.of_eq_of_ne _ _ _ _ hij, submodule.coe_zero] variable [Π (i : ι) (x : 𝒜 i), decidable (x ≠ 0)] lemma graded_algebra.mem_support_iff (r : A) (i : ι) : i ∈ graded_algebra.support 𝒜 r ↔ graded_algebra.proj 𝒜 i r ≠ 0 := begin rw [graded_algebra.support, dfinsupp.mem_support_iff, graded_algebra.proj_apply], simp only [ne.def, submodule.coe_eq_zero], end lemma graded_algebra.sum_support_decompose (r : A) : ∑ i in graded_algebra.support 𝒜 r, (graded_algebra.decompose 𝒜 r i : A) = r := begin conv_rhs { rw [←(graded_algebra.decompose 𝒜).symm_apply_apply r, ←direct_sum.sum_support_of _ (graded_algebra.decompose 𝒜 r)] }, rw [alg_equiv.map_sum, graded_algebra.support], simp_rw graded_algebra.decompose_symm_of, end end graded_algebra
da449996706ae12c12076470c59b830411daf4a0
5ae26df177f810c5006841e9c73dc56e01b978d7
/src/data/pequiv.lean
4f878b5788a24def05a56ce2192f36821c659c02
[ "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
11,599
lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import data.equiv.basic data.set.lattice tactic.tauto universes u v w x /-- A `pequiv` is a partial equivalence, a representation of a bijection between a subset of `α` and a subset of `β` -/ structure pequiv (α : Type u) (β : Type v) := (to_fun : α → option β) (inv_fun : β → option α) (inv : ∀ (a : α) (b : β), a ∈ inv_fun b ↔ b ∈ to_fun a) infixr ` ≃. `:25 := pequiv namespace pequiv variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} open function option instance : has_coe_to_fun (α ≃. β) := ⟨_, to_fun⟩ @[simp] lemma coe_mk_apply (f₁ : α → option β) (f₂ : β → option α) (h) (x : α) : (pequiv.mk f₁ f₂ h : α → option β) x = f₁ x := rfl @[extensionality] lemma ext : ∀ {f g : α ≃. β} (h : ∀ x, f x = g x), f = g | ⟨f₁, f₂, hf⟩ ⟨g₁, g₂, hg⟩ h := have h : f₁ = g₁, from funext h, have ∀ b, f₂ b = g₂ b, begin subst h, assume b, have hf := λ a, hf a b, have hg := λ a, hg a b, cases h : g₂ b with a, { simp only [h, option.not_mem_none, false_iff] at hg, simp only [hg, iff_false] at hf, rwa [option.eq_none_iff_forall_not_mem] }, { rw [← option.mem_def, hf, ← hg, h, option.mem_def] } end, by simp [*, funext_iff] lemma ext_iff {f g : α ≃. β} : f = g ↔ ∀ x, f x = g x := ⟨congr_fun ∘ congr_arg _, ext⟩ @[refl] protected def refl (α : Type*) : α ≃. α := { to_fun := some, inv_fun := some, inv := λ _ _, eq_comm } @[symm] protected def symm (f : α ≃. β) : β ≃. α := { to_fun := f.2, inv_fun := f.1, inv := λ _ _, (f.inv _ _).symm } lemma mem_iff_mem (f : α ≃. β) : ∀ {a : α} {b : β}, a ∈ f.symm b ↔ b ∈ f a := f.3 lemma eq_some_iff (f : α ≃. β) : ∀ {a : α} {b : β}, f.symm b = some a ↔ f a = some b := f.3 @[trans] protected def trans (f : α ≃. β) (g : β ≃. γ) : pequiv α γ := { to_fun := λ a, (f a).bind g, inv_fun := λ a, (g.symm a).bind f.symm, inv := λ a b, by simp [*, and.comm, eq_some_iff f, eq_some_iff g] at * } @[simp] lemma refl_apply (a : α) : pequiv.refl α a = some a := rfl @[simp] lemma symm_refl : (pequiv.refl α).symm = pequiv.refl α := rfl @[simp] lemma symm_refl_apply (a : α) : (pequiv.refl α).symm a = some a := rfl @[simp] lemma symm_symm (f : α ≃. β) : f.symm.symm = f := by cases f; refl @[simp] lemma symm_symm_apply (f : α ≃. β) (a : α) : f.symm.symm a = f a := by rw symm_symm lemma symm_injective : function.injective (@pequiv.symm α β) := injective_of_has_left_inverse ⟨_, symm_symm⟩ lemma trans_assoc (f : α ≃. β) (g : β ≃. γ) (h : γ ≃. δ) : (f.trans g).trans h = f.trans (g.trans h) := ext (λ _, option.bind_assoc _ _ _) lemma mem_trans (f : α ≃. β) (g : β ≃. γ) (a : α) (c : γ) : c ∈ f.trans g a ↔ ∃ b, b ∈ f a ∧ c ∈ g b := option.bind_eq_some' lemma trans_eq_some (f : α ≃. β) (g : β ≃. γ) (a : α) (c : γ) : f.trans g a = some c ↔ ∃ b, f a = some b ∧ g b = some c := option.bind_eq_some' lemma trans_eq_none (f : α ≃. β) (g : β ≃. γ) (a : α) : f.trans g a = none ↔ (∀ b c, b ∉ f a ∨ c ∉ g b) := by simp only [eq_none_iff_forall_not_mem, mem_trans]; push_neg; tauto @[simp] lemma refl_trans (f : α ≃. β) : (pequiv.refl α).trans f = f := by ext; dsimp [pequiv.trans]; refl @[simp] lemma trans_refl (f : α ≃. β) : f.trans (pequiv.refl β) = f := by ext; dsimp [pequiv.trans]; simp @[simp] lemma refl_trans_apply (f : α ≃. β) (a : α) : (pequiv.refl α).trans f a = f a := by rw refl_trans @[simp] lemma trans_refl_apply (f : α ≃. β) (a : α) : f.trans (pequiv.refl β) a = f a := by rw trans_refl protected lemma inj (f : α ≃. β) {a₁ a₂ : α} {b : β} (h₁ : b ∈ f a₁) (h₂ : b ∈ f a₂) : a₁ = a₂ := by rw ← mem_iff_mem at *; cases h : f.symm b; simp * at * lemma injective_of_forall_ne_is_some (f : α ≃. β) (a₂ : α) (h : ∀ (a₁ : α), a₁ ≠ a₂ → is_some (f a₁)) : injective f := injective_of_has_left_inverse ⟨λ b, option.rec_on b a₂ (λ b', option.rec_on (f.symm b') a₂ id), λ x, begin classical, cases hfx : f x, { have : x = a₂, from not_imp_comm.1 (h x) (hfx.symm ▸ by simp), simp [this] }, { simp only [hfx], rw [(eq_some_iff f).2 hfx], refl } end⟩ lemma injective_of_forall_is_some {f : α ≃. β} (h : ∀ (a : α), is_some (f a)) : injective f := (classical.em (nonempty α)).elim (λ hn, injective_of_forall_ne_is_some f (classical.choice hn) (λ a _, h a)) (λ hn x, (hn ⟨x⟩).elim) section of_set variables (s : set α) [decidable_pred s] def of_set (s : set α) [decidable_pred s] : α ≃. α := { to_fun := λ a, if a ∈ s then some a else none, inv_fun := λ a, if a ∈ s then some a else none, inv := λ a b, by split_ifs; finish [eq_comm] } lemma mem_of_set_self_iff {s : set α} [decidable_pred s] {a : α} : a ∈ of_set s a ↔ a ∈ s := by dsimp [of_set]; split_ifs; simp * lemma mem_of_set_iff {s : set α} [decidable_pred s] {a b : α} : a ∈ of_set s b ↔ a = b ∧ a ∈ s := by dsimp [of_set]; split_ifs; split; finish @[simp] lemma of_set_eq_some_self_iff {s : set α} {h : decidable_pred s} {a : α} : of_set s a = some a ↔ a ∈ s := mem_of_set_self_iff @[simp] lemma of_set_eq_some_iff {s : set α} {h : decidable_pred s} {a b : α} : of_set s b = some a ↔ a = b ∧ a ∈ s := mem_of_set_iff @[simp] lemma of_set_symm : (of_set s).symm = of_set s := rfl @[simp] lemma of_set_univ : of_set set.univ = pequiv.refl α := by ext; dsimp [of_set]; simp [eq_comm] @[simp] lemma of_set_eq_refl {s : set α} [decidable_pred s] : of_set s = pequiv.refl α ↔ s = set.univ := ⟨λ h, begin rw [set.eq_univ_iff_forall], intro, rw [← mem_of_set_self_iff, h], exact rfl end, λ h, by simp only [of_set_univ.symm, h]; congr⟩ end of_set lemma symm_trans_rev (f : α ≃. β) (g : β ≃. γ) : (f.trans g).symm = g.symm.trans f.symm := rfl lemma trans_symm (f : α ≃. β) : f.trans f.symm = of_set {a | (f a).is_some} := begin ext, dsimp [pequiv.trans], simp only [eq_some_iff f, option.is_some_iff_exists, option.mem_def, bind_eq_some', of_set_eq_some_iff], split, { rintros ⟨b, hb₁, hb₂⟩, exact ⟨pequiv.inj _ hb₂ hb₁, b, hb₂⟩ }, { simp {contextual := tt} } end lemma symm_trans (f : α ≃. β) : f.symm.trans f = of_set {b | (f.symm b).is_some} := symm_injective $ by simp [symm_trans_rev, trans_symm, -symm_symm] lemma trans_symm_eq_iff_forall_is_some {f : α ≃. β} : f.trans f.symm = pequiv.refl α ↔ ∀ a, is_some (f a) := by rw [trans_symm, of_set_eq_refl, set.eq_univ_iff_forall]; refl instance : lattice.has_bot (α ≃. β) := ⟨{ to_fun := λ _, none, inv_fun := λ _, none, inv := by simp }⟩ @[simp] lemma bot_apply (a : α) : (⊥ : α ≃. β) a = none := rfl @[simp] lemma symm_bot : (⊥ : α ≃. β).symm = ⊥ := rfl @[simp] lemma trans_bot (f : α ≃. β) : f.trans (⊥ : β ≃. γ) = ⊥ := by ext; dsimp [pequiv.trans]; simp @[simp] lemma bot_trans (f : β ≃. γ) : (⊥ : α ≃. β).trans f = ⊥ := by ext; dsimp [pequiv.trans]; simp lemma is_some_symm_get (f : α ≃. β) {a : α} (h : is_some (f a)) : is_some (f.symm (option.get h)) := is_some_iff_exists.2 ⟨a, by rw [f.eq_some_iff, some_get]⟩ section single variables [decidable_eq α] [decidable_eq β] [decidable_eq γ] def single (a : α) (b : β) : α ≃. β := { to_fun := λ x, if x = a then some b else none, inv_fun := λ x, if x = b then some a else none, inv := λ _ _, by simp; split_ifs; cc } lemma mem_single (a : α) (b : β) : b ∈ single a b a := if_pos rfl lemma mem_single_iff (a₁ a₂ : α) (b₁ b₂ : β) : b₁ ∈ single a₂ b₂ a₁ ↔ a₁ = a₂ ∧ b₁ = b₂ := by dsimp [single]; split_ifs; simp [*, eq_comm] @[simp] lemma symm_single (a : α) (b : β) : (single a b).symm = single b a := rfl @[simp] lemma single_apply (a : α) (b : β) : single a b a = some b := if_pos rfl lemma single_apply_of_ne {a₁ a₂ : α} (h : a₁ ≠ a₂) (b : β) : single a₁ b a₂ = none := if_neg h.symm lemma single_trans_of_mem (a : α) {b : β} {c : γ} {f : β ≃. γ} (h : c ∈ f b) : (single a b).trans f = single a c := begin ext, dsimp [single, pequiv.trans], split_ifs; simp * at * end lemma trans_single_of_mem {a : α} {b : β} (c : γ) {f : α ≃. β} (h : b ∈ f a) : f.trans (single b c) = single a c := symm_injective $ single_trans_of_mem _ ((mem_iff_mem f).2 h) @[simp] lemma single_trans_single (a : α) (b : β) (c : γ) : (single a b).trans (single b c) = single a c := single_trans_of_mem _ (mem_single _ _) @[simp] lemma single_subsingleton_eq_refl [subsingleton α] (a b : α) : single a b = pequiv.refl α := begin ext i j, dsimp [single], rw [if_pos (subsingleton.elim i a), subsingleton.elim i j, subsingleton.elim b j] end lemma trans_single_of_eq_none {b : β} (c : γ) {f : α ≃. β} (h : f.symm b = none) : f.trans (single b c) = ⊥ := begin ext, simp only [eq_none_iff_forall_not_mem, option.mem_def, f.eq_some_iff] at h, dsimp [pequiv.trans, single], simp, intros, split_ifs; simp * at * end lemma single_trans_of_eq_none (a : α) {b : β} {f : β ≃. γ} (h : f b = none) : (single a b).trans f = ⊥ := symm_injective $ trans_single_of_eq_none _ h lemma single_trans_single_of_ne {b₁ b₂ : β} (h : b₁ ≠ b₂) (a : α) (c : γ) : (single a b₁).trans (single b₂ c) = ⊥ := single_trans_of_eq_none _ (single_apply_of_ne h.symm _) end single section order open lattice instance : partial_order (α ≃. β) := { le := λ f g, ∀ (a : α) (b : β), b ∈ f a → b ∈ g a, le_refl := λ _ _ _, id, le_trans := λ f g h fg gh a b, (gh a b) ∘ (fg a b), le_antisymm := λ f g fg gf, ext begin assume a, cases h : g a with b, { exact eq_none_iff_forall_not_mem.2 (λ b hb, option.not_mem_none b $ h ▸ fg a b hb) }, { exact gf _ _ h } end } lemma le_def {f g : α ≃. β} : f ≤ g ↔ (∀ (a : α) (b : β), b ∈ f a → b ∈ g a) := iff.rfl instance : order_bot (α ≃. β) := { bot_le := λ _ _ _ h, (not_mem_none _ h).elim, ..pequiv.partial_order, ..pequiv.lattice.has_bot } instance [decidable_eq α] [decidable_eq β] : semilattice_inf_bot (α ≃. β) := { inf := λ f g, { to_fun := λ a, if f a = g a then f a else none, inv_fun := λ b, if f.symm b = g.symm b then f.symm b else none, inv := λ a b, begin have := @mem_iff_mem _ _ f a b, have := @mem_iff_mem _ _ g a b, split_ifs; finish end }, inf_le_left := λ _ _ _ _, by simp; split_ifs; cc, inf_le_right := λ _ _ _ _, by simp; split_ifs; cc, le_inf := λ f g h fg gh a b, begin have := fg a b, have := gh a b, simp [le_def], split_ifs; finish end, ..pequiv.lattice.order_bot } end order end pequiv namespace equiv variables {α : Type*} {β : Type*} {γ : Type*} def to_pequiv (f : α ≃ β) : α ≃. β := { to_fun := some ∘ f, inv_fun := some ∘ f.symm, inv := by simp [equiv.eq_symm_apply, eq_comm] } @[simp] lemma to_pequiv_refl : (equiv.refl α).to_pequiv = pequiv.refl α := rfl lemma to_pequiv_trans (f : α ≃ β) (g : β ≃ γ) : (f.trans g).to_pequiv = f.to_pequiv.trans g.to_pequiv := rfl lemma to_pequiv_symm (f : α ≃ β) : f.symm.to_pequiv = f.to_pequiv.symm := rfl end equiv
51111dc19c33a21978defc7ca9f39d6d736b8f66
6db8061629f55e774dd3d03be5bf005ffb485e48
/BetterNumLits/Nat.lean
7a73fc85726139d7f743880b51496ed533ef5c41
[]
no_license
tydeu/lean4-betterNumLits
21fd5717d1b62ecb021c73e8cfaa0e3d19005690
45e3b79214b3e1f81f8e034dd12257e993ddc578
refs/heads/master
1,683,103,070,685
1,621,717,131,000
1,621,717,131,000
369,368,844
0
0
null
null
null
null
UTF-8
Lean
false
false
1,590
lean
import BetterNumLits.Numerals namespace Nat abbrev one := nat_lit 1 abbrev two := nat_lit 2 abbrev three := nat_lit 3 abbrev four := nat_lit 4 abbrev five := nat_lit 5 abbrev six := nat_lit 6 abbrev seven := nat_lit 7 abbrev eight := nat_lit 8 abbrev nine := nat_lit 9 abbrev ten := nat_lit 10 abbrev eleven := nat_lit 11 abbrev twelve := nat_lit 12 abbrev thirteen := nat_lit 13 abbrev fourteen := nat_lit 14 abbrev fifteen := nat_lit 15 abbrev sixteen := nat_lit 16 @[defaultInstance low] instance : Zero Nat := ⟨zero⟩ @[defaultInstance low] instance : One Nat := ⟨one⟩ @[defaultInstance low] instance : Two Nat := ⟨two⟩ @[defaultInstance low] instance : Three Nat := ⟨three⟩ @[defaultInstance low] instance : Four Nat := ⟨four⟩ @[defaultInstance low] instance : Five Nat := ⟨five⟩ @[defaultInstance low] instance : Six Nat := ⟨six⟩ @[defaultInstance low] instance : Seven Nat := ⟨seven⟩ @[defaultInstance low] instance : Eight Nat := ⟨eight⟩ @[defaultInstance low] instance : Nine Nat := ⟨nine⟩ @[defaultInstance low] instance : Ten Nat := ⟨ten⟩ @[defaultInstance low] instance : Eleven Nat := ⟨eleven⟩ @[defaultInstance low] instance : Twelve Nat := ⟨twelve⟩ @[defaultInstance low] instance : Thirteen Nat := ⟨thirteen⟩ @[defaultInstance low] instance : Fourteen Nat := ⟨fourteen⟩ @[defaultInstance low] instance : Fifteen Nat := ⟨fifteen⟩ @[defaultInstance low] instance : Sixteen Nat := ⟨sixteen⟩
f737155ce257f4fc894f54cf9a4a5cc8eb399460
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/data/multiset/erase_dup.lean
9b55a4218c7835e41f49fa12eb1737a35c71ce01
[ "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,605
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.multiset.nodup /-! # Erasing duplicates in a multiset. -/ namespace multiset open list variables {α β : Type*} [decidable_eq α] /-! ### erase_dup -/ /-- `erase_dup s` removes duplicates from `s`, yielding a `nodup` multiset. -/ def erase_dup (s : multiset α) : multiset α := quot.lift_on s (λ l, (l.erase_dup : multiset α)) (λ s t p, quot.sound p.erase_dup) @[simp] theorem coe_erase_dup (l : list α) : @erase_dup α _ l = l.erase_dup := rfl @[simp] theorem erase_dup_zero : @erase_dup α _ 0 = 0 := rfl @[simp] theorem mem_erase_dup {a : α} {s : multiset α} : a ∈ erase_dup s ↔ a ∈ s := quot.induction_on s $ λ l, mem_erase_dup @[simp] theorem erase_dup_cons_of_mem {a : α} {s : multiset α} : a ∈ s → erase_dup (a ::ₘ s) = erase_dup s := quot.induction_on s $ λ l m, @congr_arg _ _ _ _ coe $ erase_dup_cons_of_mem m @[simp] theorem erase_dup_cons_of_not_mem {a : α} {s : multiset α} : a ∉ s → erase_dup (a ::ₘ s) = a ::ₘ erase_dup s := quot.induction_on s $ λ l m, congr_arg coe $ erase_dup_cons_of_not_mem m theorem erase_dup_le (s : multiset α) : erase_dup s ≤ s := quot.induction_on s $ λ l, (erase_dup_sublist _).subperm theorem erase_dup_subset (s : multiset α) : erase_dup s ⊆ s := subset_of_le $ erase_dup_le _ theorem subset_erase_dup (s : multiset α) : s ⊆ erase_dup s := λ a, mem_erase_dup.2 @[simp] theorem erase_dup_subset' {s t : multiset α} : erase_dup s ⊆ t ↔ s ⊆ t := ⟨subset.trans (subset_erase_dup _), subset.trans (erase_dup_subset _)⟩ @[simp] theorem subset_erase_dup' {s t : multiset α} : s ⊆ erase_dup t ↔ s ⊆ t := ⟨λ h, subset.trans h (erase_dup_subset _), λ h, subset.trans h (subset_erase_dup _)⟩ @[simp] theorem nodup_erase_dup (s : multiset α) : nodup (erase_dup s) := quot.induction_on s nodup_erase_dup theorem erase_dup_eq_self {s : multiset α} : erase_dup s = s ↔ nodup s := ⟨λ e, e ▸ nodup_erase_dup s, quot.induction_on s $ λ l h, congr_arg coe $ erase_dup_eq_self.2 h⟩ theorem erase_dup_eq_zero {s : multiset α} : erase_dup s = 0 ↔ s = 0 := ⟨λ h, eq_zero_of_subset_zero $ h ▸ subset_erase_dup _, λ h, h.symm ▸ erase_dup_zero⟩ @[simp] theorem erase_dup_singleton {a : α} : erase_dup (a ::ₘ 0) = a ::ₘ 0 := erase_dup_eq_self.2 $ nodup_singleton _ theorem le_erase_dup {s t : multiset α} : s ≤ erase_dup t ↔ s ≤ t ∧ nodup s := ⟨λ h, ⟨le_trans h (erase_dup_le _), nodup_of_le h (nodup_erase_dup _)⟩, λ ⟨l, d⟩, (le_iff_subset d).2 $ subset.trans (subset_of_le l) (subset_erase_dup _)⟩ theorem erase_dup_ext {s t : multiset α} : erase_dup s = erase_dup t ↔ ∀ a, a ∈ s ↔ a ∈ t := by simp [nodup_ext] theorem erase_dup_map_erase_dup_eq [decidable_eq β] (f : α → β) (s : multiset α) : erase_dup (map f (erase_dup s)) = erase_dup (map f s) := by simp [erase_dup_ext] @[simp] lemma erase_dup_nsmul {s : multiset α} {n : ℕ} (h0 : n ≠ 0) : (n • s).erase_dup = s.erase_dup := begin ext a, by_cases h : a ∈ s; simp [h,h0] end lemma nodup.le_erase_dup_iff_le {s t : multiset α} (hno : s.nodup) : s ≤ t.erase_dup ↔ s ≤ t := by simp [le_erase_dup, hno] end multiset lemma multiset.nodup.le_nsmul_iff_le {α : Type*} {s t : multiset α} {n : ℕ} (h : s.nodup) (hn : n ≠ 0) : s ≤ n • t ↔ s ≤ t := begin classical, rw [← h.le_erase_dup_iff_le, iff.comm, ← h.le_erase_dup_iff_le], simp [hn] end
0c9c3a6a5fd9f3935a04ed5ad888663709046074
41e069072396dcd54bd9fdadb27cfd35fd07016a
/src/K/ops.lean
2337f4e94a835c5dca327dfe2343f40e8dae0974
[ "MIT" ]
permissive
semorrison/ModalTab
438ad601bd2631ab9cfe1e61f0d1337a36e2367e
cc94099194a2b69f84eb7a770b7aac711825179f
refs/heads/master
1,585,939,884,891
1,540,961,947,000
1,540,961,947,000
155,500,181
0
0
MIT
1,540,961,175,000
1,540,961,175,000
null
UTF-8
Lean
false
false
12,662
lean
import .size open nnf list namespace list universes u v w variables {α : Type u} {β : Type v} {γ : Type w} theorem mapp {p : β → Prop} (f : α → β) : Π (l : list α) (h : ∀ x∈l, p (f x)) x, x ∈ list.map f l → p x | [] h x := by simp | (hd::tl) h x := begin intro hmem, cases hmem, {rw hmem, apply h, simp}, {apply mapp tl, intros a ha, apply h, simp [ha], exact hmem} end @[simp] def ne_empty_head : Π l : list α, l ≠ [] → α | [] h := by contradiction | (a :: l) h := a end list @[simp] def unbox : list nnf → list nnf | [] := [] | ((box φ) :: l) := φ :: unbox l | (e :: l) := unbox l theorem unbox_iff : Π {Γ φ}, box φ ∈ Γ ↔ φ ∈ unbox Γ | [] φ := begin split, repeat {intro h, simpa using h} end | (hd::tl) φ := begin split, { intro h, cases h₁ : hd, case nnf.box : ψ { dsimp [unbox], cases h, {left, rw h₁ at h, injection h}, {right, exact (@unbox_iff tl φ).1 h} }, all_goals { dsimp [unbox], cases h, {rw h₁ at h, contradiction}, {exact (@unbox_iff tl φ).1 h} } }, { intro h, cases h₁ : hd, case nnf.box : ψ { rw h₁ at h, dsimp [unbox] at h, cases h, {simp [h]}, {right, exact (@unbox_iff tl φ).2 h} }, all_goals { rw h₁ at h, dsimp [unbox] at h, right, exact (@unbox_iff tl φ).2 h } } end theorem unbox_size_aux : Π {Γ}, node_size (unbox Γ) ≤ node_size Γ | [] := by simp | (hd::tl) := begin cases h : hd, case nnf.box : ψ { dsimp, apply add_le_add, { dsimp [sizeof, has_sizeof.sizeof, nnf.sizeof], rw add_comm, apply nat.le_succ }, { apply unbox_size_aux } }, all_goals { dsimp, apply le_add_of_nonneg_of_le, { dsimp [sizeof, has_sizeof.sizeof, nnf.sizeof], rw add_comm, apply nat.zero_le }, { apply unbox_size_aux } } end theorem unbox_size : Π {Γ φ}, dia φ ∈ Γ → node_size (unbox Γ) + sizeof φ < node_size Γ | [] := by simp | (hd::tl) := begin intros φ h, cases h₁ : hd, case nnf.box : ψ {dsimp, cases h, {rw h₁ at h, contradiction}, {rw add_assoc, apply add_lt_add, {dsimp [sizeof, has_sizeof.sizeof, nnf.sizeof], rw add_comm, apply nat.lt_succ_self}, {apply unbox_size, exact h} } }, case nnf.dia : ψ {dsimp, rw add_comm, cases h, {rw h₁ at h, have : φ = ψ, injection h, rw this, apply add_lt_add_of_lt_of_le, {dsimp [sizeof, has_sizeof.sizeof, nnf.sizeof], rw add_comm, apply nat.lt_succ_self}, {apply unbox_size_aux} }, {apply lt_add_of_pos_of_lt, {dsimp [sizeof, has_sizeof.sizeof, nnf.sizeof], rw add_comm, apply nat.succ_pos}, {rw add_comm, apply unbox_size, exact h} } }, all_goals {dsimp, apply nat.lt_add_left, apply unbox_size, cases h, rw h₁ at h, contradiction, exact h} end @[simp] def rebox : list nnf → list nnf | [] := [] | (hd::tl) := box hd :: rebox tl theorem rebox_unbox_of_mem : Π {Γ} (h : ∀ {φ}, φ ∈ unbox Γ → box φ ∈ Γ), rebox (unbox Γ) ⊆ Γ | [] h := by simp | (hd::tl) h := begin cases hψ : hd, case nnf.box : φ {dsimp, simp [cons_subset_cons], apply subset_cons_of_subset, apply rebox_unbox_of_mem, simp [unbox_iff]}, all_goals {dsimp, apply subset_cons_of_subset, apply rebox_unbox_of_mem, simp [unbox_iff]} end theorem unbox_rebox : Π {Γ}, unbox (rebox Γ) = Γ | [] := by simp | (hd::tl) := by simp [unbox_rebox] -- Just that I don't want to say ∃ φ s.t. ... def box_only_rebox : Π {Γ}, box_only (rebox Γ) | [] := {no_var := by simp, no_neg := by simp, no_and := by simp, no_or := by simp, no_dia := by simp} | (hd::tl) := begin cases h : hd, all_goals { exact { no_var := begin intros n h, cases h, contradiction, apply (@box_only_rebox tl).no_var, assumption end, no_neg := begin intros n h, cases h, contradiction, apply (@box_only_rebox tl).no_neg, assumption end, no_and := begin intros φ ψ h, cases h, contradiction, apply (@box_only_rebox tl).no_and, assumption end, no_or := begin intros φ ψ h, cases h, contradiction, apply (@box_only_rebox tl).no_or, assumption end, no_dia := begin intros φ h, cases h, contradiction, apply (@box_only_rebox tl).no_dia, assumption end} } end theorem rebox_iff : Π {φ Γ}, box φ ∈ rebox Γ ↔ φ ∈ Γ | φ [] := by simp | φ (hd::tl) := begin split, {intro h, cases h₁ : hd, all_goals { cases h, {left, rw ←h₁, injection h}, {right, have := (@rebox_iff φ tl).1, exact this h } }}, {intro h, cases h₁ : hd, all_goals { dsimp, cases h, {left, rw ←h₁, rw h}, {right, have := (@rebox_iff φ tl).2, exact this h } } } end @[simp] def undia : list nnf → list nnf | [] := [] | ((dia φ) :: l) := φ :: undia l | (e :: l) := undia l theorem undia_iff : Π {Γ φ}, dia φ ∈ Γ ↔ φ ∈ undia Γ | [] φ := begin split, repeat {intro h, simpa using h} end | (hd::tl) φ := begin split, { intro h, cases h₁ : hd, case nnf.dia : ψ { dsimp [undia], cases h, {left, rw h₁ at h, injection h}, {right, exact (@undia_iff tl φ).1 h} }, all_goals { dsimp [undia], cases h, {rw h₁ at h, contradiction}, {exact (@undia_iff tl φ).1 h} } }, { intro h, cases h₁ : hd, case nnf.dia : ψ { rw h₁ at h, dsimp [undia] at h, cases h, {simp [h]}, {right, exact (@undia_iff tl φ).2 h} }, all_goals { rw h₁ at h, dsimp [undia] at h, right, exact (@undia_iff tl φ).2 h } } end theorem undia_size : Π {Γ φ}, φ ∈ undia Γ → sizeof φ + node_size (unbox Γ) < node_size Γ := begin intros Γ φ h, rw add_comm, apply unbox_size, rw undia_iff, exact h end @[simp] def get_modal : list nnf → list nnf | [] := [] | (φ@(dia ψ) :: l) := φ :: get_modal l | (φ@(box ψ) :: l) := φ :: get_modal l | (e :: l) := get_modal l theorem get_modal_iff_dia : Π {Γ} {φ : nnf}, dia φ ∈ get_modal Γ ↔ dia φ ∈ Γ | [] φ := by simp | (hd::tl) φ := begin split, {intro h, cases heq : hd, case nnf.dia : ψ {rw heq at h, dsimp at h, cases h, left, exact h, right, have := (@get_modal_iff_dia tl φ), have := this.1 h, exact this}, case nnf.box : ψ {rw heq at h, dsimp at h, cases h, contradiction, right, have := (@get_modal_iff_dia tl φ), have := this.1 h, exact this}, all_goals {rw heq at h, dsimp at h, right, have := (@get_modal_iff_dia tl φ), have := this.1 h, exact this}}, {intro h, cases heq : hd, case nnf.dia : ψ {dsimp, rw heq at h, cases h, left, exact h, right, have := (@get_modal_iff_dia tl φ), have := this.2 h, exact this}, case nnf.box : ψ {dsimp, rw heq at h, cases h, contradiction, right, have := (@get_modal_iff_dia tl φ), have := this.2 h, exact this}, all_goals {dsimp, rw heq at h, cases h, contradiction, have := (@get_modal_iff_dia tl φ), have := this.2 h, exact this} } end theorem get_modal_iff_box : Π {Γ} {φ : nnf}, box φ ∈ get_modal Γ ↔ box φ ∈ Γ | [] φ := by simp | (hd::tl) φ := begin split, {intro h, cases heq : hd, case nnf.box : ψ {rw heq at h, dsimp at h, cases h, left, exact h, right, have := (@get_modal_iff_box tl φ), have := this.1 h, exact this}, case nnf.dia : ψ {rw heq at h, dsimp at h, cases h, contradiction, right, have := (@get_modal_iff_box tl φ), have := this.1 h, exact this}, all_goals {rw heq at h, dsimp at h, right, have := (@get_modal_iff_box tl φ), have := this.1 h, exact this}}, {intro h, cases heq : hd, case nnf.box : ψ {dsimp, rw heq at h, cases h, left, exact h, right, have := (@get_modal_iff_box tl φ), have := this.2 h, exact this}, case nnf.dia : ψ {dsimp, rw heq at h, cases h, contradiction, right, have := (@get_modal_iff_box tl φ), have := this.2 h, exact this}, all_goals {dsimp, rw heq at h, cases h, contradiction, have := (@get_modal_iff_box tl φ), have := this.2 h, exact this}} end def get_contra : Π Γ : list nnf, psum {p : nat // var p ∈ Γ ∧ neg p ∈ Γ} (∀ n, var n ∈ Γ → neg n ∉ Γ) | [] := psum.inr $ λ _ h, absurd h $ not_mem_nil _ | (hd :: tl) := begin cases h : hd, case nnf.var : n {apply dite (neg n ∈ tl), {intro t, exact psum.inl ⟨n, ⟨mem_cons_self _ _, mem_cons_of_mem _ t⟩⟩}, {intro e, cases (get_contra tl), {left, constructor, constructor, apply mem_cons_of_mem, exact val.2.1, apply mem_cons_of_mem, exact val.2.2}, {right, intros m hm hin, by_cases eq : m=n, {apply e, cases hin, contradiction, rw ←eq, assumption}, {cases hm, apply eq, injection hm, apply val, exact hm, cases hin, contradiction, assumption} } } }, case nnf.neg : n { apply dite (var n ∈ tl), { intro t, exact psum.inl ⟨n, ⟨mem_cons_of_mem _ t, mem_cons_self _ _⟩⟩ }, { intro e, cases (get_contra tl), {left, constructor, constructor, apply mem_cons_of_mem, exact val.2.1, apply mem_cons_of_mem, exact val.2.2 }, { right, intros m hm hin, by_cases eq : m=n, { apply e, cases hm, contradiction, rw ←eq, assumption }, { cases hin, apply eq, injection hin, apply val, swap, exact hin, cases hm, contradiction, assumption } } } }, all_goals { cases (get_contra tl), { left, constructor, constructor, apply mem_cons_of_mem, exact val.2.1, apply mem_cons_of_mem, exact val.2.2 }, { right, intros m hm hin, {apply val, swap 3, exact m, cases hm, contradiction, assumption, cases hin, contradiction, assumption} } } end def get_and : Π Γ : list nnf, psum {p : nnf × nnf // and p.1 p.2 ∈ Γ} (∀ φ ψ, nnf.and φ ψ ∉ Γ) | [] := psum.inr $ λ _ _, not_mem_nil _ | (hd :: tl) := begin cases h : hd, case nnf.and : φ ψ { left, constructor,swap, constructor, exact φ, exact ψ, simp }, all_goals { cases (get_and tl), {left, constructor, apply mem_cons_of_mem, exact val.2}, {right, intros γ ψ h, cases h, contradiction, apply val, assumption } } end def get_or : Π Γ : list nnf, psum {p : nnf × nnf // or p.1 p.2 ∈ Γ} (∀ φ ψ, nnf.or φ ψ ∉ Γ) | [] := psum.inr $ λ _ _, not_mem_nil _ | (hd :: tl) := begin cases h : hd, case nnf.or : φ ψ { left, constructor,swap, constructor, exact φ, exact ψ, simp }, all_goals { cases (get_or tl), {left, constructor, apply mem_cons_of_mem, exact val.2}, {right, intros γ ψ h, cases h, contradiction, apply val, assumption} } end def get_dia : Π Γ : list nnf, psum {p : nnf // dia p ∈ Γ} (∀ φ, nnf.dia φ ∉ Γ) | [] := psum.inr $ λ _, not_mem_nil _ | (hd :: tl) := begin cases h : hd, case nnf.dia : φ { left, constructor, swap, exact φ, simp }, all_goals { cases (get_dia tl), {left, constructor, apply mem_cons_of_mem, exact val.2}, {right, intros γ h, cases h, contradiction, apply val, assumption } } end @[simp] def get_var : list nnf → list ℕ | [] := [] | ((var n) :: l) := n :: get_var l | (e :: l) := get_var l theorem get_var_iff : Π {Γ n}, var n ∈ Γ ↔ n ∈ get_var Γ | [] φ := begin split, repeat {intro h, simpa using h} end | (hd::tl) φ := begin split, { intro h, cases h₁ : hd, case nnf.var : n { dsimp, cases h, {left, rw h₁ at h, injection h}, {right, exact (@get_var_iff tl φ).1 h} }, all_goals { dsimp, cases h, {rw h₁ at h, contradiction}, {exact (@get_var_iff tl φ).1 h} } }, { intro h, cases h₁ : hd, case nnf.var : n { rw h₁ at h, dsimp at h, cases h, {simp [h]}, {right, exact (@get_var_iff tl φ).2 h} }, all_goals { rw h₁ at h, dsimp [undia] at h, right, exact (@get_var_iff tl φ).2 h } } end
ad3d64b8227474d90acd31052ce77239cc58778c
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/sigma/default_auto.lean
6e829c1630f247cd45e815aec1984328dc5adbf4
[]
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
147
lean
import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.sigma.basic import Mathlib.PostPort namespace Mathlib end Mathlib
e006a066fd50fd040d8b0c88cc099e1cbb9f1bfe
76df16d6c3760cb415f1294caee997cc4736e09b
/lean/src/cs/rsc.lean
57f6f12125e972fca4932201b2e854f216c3f539
[ "MIT" ]
permissive
uw-unsat/leanette-popl22-artifact
70409d9cbd8921d794d27b7992bf1d9a4087e9fe
80fea2519e61b45a283fbf7903acdf6d5528dbe7
refs/heads/master
1,681,592,449,670
1,637,037,431,000
1,637,037,431,000
414,331,908
6
1
null
null
null
null
UTF-8
Lean
false
false
28,200
lean
import tactic.basic import tactic.split_ifs import tactic.linarith import tactic.apply_fun import .svm import .lib import .hp import .mrg import .lgl import .detc namespace sym open lang section rsc variables {Model SymB SymV D O : Type} [inhabited Model] [inhabited SymV] (f : factory Model SymB SymV D O) {m : Model} lemma factory.normal_ans_rc {σ' : state SymB} (v : SymV) (hn' : (state.normal f.to_has_eval m σ')) : ∃ w, f.evalV m v = w ∧ (result.ans σ' v).eval f.to_has_eval m = (lang.result.ans w) := begin apply exists.intro (f.to_has_eval.evalV m v), simp only [result.eval, true_and, eq_ff_eq_not_eq_tt, eq_self_iff_true, ite_eq_left_iff], intro hnn, simp only [hnn, coe_sort_ff] at hn', contradiction, end lemma factory.var_rc {ε : env SymV} {σ : state SymB} {y : ℕ} {e : lang.env D O} {r : lang.result D O} (hy : y < ε.length) (hn : (state.normal f.to_has_eval m σ)) (hε : env.eval f.to_has_eval m ε = e) (hr : result.eval f.to_has_eval m (result.ans σ (ε.nth_le y hy)) = r) : evalC f.opC (exp.var y) e r := begin rcases (env.eval_nth_le f.to_has_eval hy hε) with ⟨hy', he⟩, simp only [result.eval, he, hn, if_true] at hr, rewrite ←hr, apply evalC.var, end lemma factory.compose_normal_any (σ σ' : state SymB) : σ.normal f.to_has_eval m → (f.compose σ σ').eqv f.to_has_eval m σ' := begin simp only [state.normal, factory.compose, state.eqv, and_imp, bool.to_bool_and, bool.to_bool_coe, band_coe_iff], intros h1 h2, simp only [f.and_sound, f.imp_sound, h1, h2, true_and, eq_self_iff_true, bool.to_bool_coe, forall_true_left], end lemma factory.halted_is_abnormal {σ : state SymB} : f.halted σ → ¬ σ.normal f.to_has_eval m := begin simp only [factory.halted, state.normal, eq_ff_eq_not_eq_tt, bor_coe_iff, not_and, bool.to_bool_and, bool.to_bool_coe, band_coe_iff], intros h1 h2, cases h1; rewrite f.is_ff_sound at h1; apply_fun (f.evalB m) at h1; simp only [f.mk_ff_sound] at h1, { simp only [h1, coe_sort_ff] at h2, contradiction,}, { exact h1, } end lemma factory.eval_strengthen_normal {σ : state SymB} {ρ : result SymB SymV} (hn : (state.normal f.to_has_eval m σ)) : result.eval f.to_has_eval m (f.strengthen σ ρ) = result.eval f.to_has_eval m ρ := begin cases ρ with σ' v' σ', { rcases (f.compose_normal_any σ σ' hn) with hc, simp only [factory.strengthen, factory.halt_or_ans], split_ifs, { simp only [result.eval], rcases (@factory.halted_is_abnormal Model SymB SymV D O _ _ f m (f.compose σ σ') h) with hnc, rcases (state.eqv_abnormal f.to_has_eval hnc hc) with hn', simp only [hn', if_false], apply state.eqv_aborted f.to_has_eval hc, }, { simp only [result.eval], cases hnc : (state.normal f.to_has_eval m (f.compose σ σ')), { rewrite ←bool_iff_false at hnc, rcases (state.eqv_abnormal f.to_has_eval hnc hc) with hn', simp only [hn', if_false, coe_sort_ff], apply state.eqv_aborted f.to_has_eval hc, }, { rcases (state.eqv_normal f.to_has_eval hnc hc) with hn', simp only [hn', if_true, coe_sort_tt], } } }, { rcases (f.compose_normal_any σ σ' hn) with hc, simp only [factory.strengthen, result.eval, state.aborted, eq_ff_eq_not_eq_tt, bool.to_bool_eq], simp only [state.eqv] at hc, simp only [hc, iff_self], } end lemma factory.app_rc {ε : env SymV} {σ : state SymB} {o : O} {xs : list ℕ} {vs : list SymV} {e : lang.env D O} {r : lang.result D O} (h1 : xs.length = vs.length) (h2 : ∀ (i : ℕ) (hx : i < xs.length) (hv : i < vs.length), evalS f (exp.var (xs.nth_le i hx)) ε σ (result.ans σ (vs.nth_le i hv))) (ih: ∀ (i : ℕ) (hx : i < xs.length) (hv : i < vs.length), (λ {x : exp D O} {ε : env SymV} {σ : state SymB} {ρ : result SymB SymV} (hs : evalS f x ε σ ρ), (state.normal f.to_has_eval m σ) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m ρ = r → evalC f.opC x e r) (h2 i hx hv)) (hn : (state.normal f.to_has_eval m σ)) (hε : env.eval f.to_has_eval m ε = e) (hr : result.eval f.to_has_eval m (f.strengthen σ (f.opS o vs)) = r) : evalC f.opC (exp.app o xs) e r := begin rewrite f.eval_strengthen_normal hn at hr, rcases (f.opS_sound m o vs) with ⟨hos, _⟩, rewrite [←hr, hos], apply evalC.app, { simp only [h1, list.length_map], }, { intros i hx hw, specialize @ih i hx (by { rewrite ←h1, exact hx, }) hn e (lang.result.ans ((list.map (f.to_has_eval.evalV m) vs).nth_le i hw)) hε, apply ih, apply result.eval_ans f.to_has_eval hn, simp only [list.nth_le_map'], } end lemma factory.not_some_cast_not_clos {c : SymV} {w : lang.val D O} (hf : f.to_has_eval.evalB m (f.some choice.guard (f.cast c)) = ff) (hw : f.to_has_eval.evalV m c = w): ¬(w.is_clos) := begin rcases (f.cast_sound m c) with ⟨hcs1, _⟩, rewrite hw at hcs1, by_contradiction, specialize hcs1 h, cases hcs1 with hcs1 _, simp only [f.some_eq_any] at hf, rewrite ← bool_iff_false at hf, rcases (choices.not_some_is_none (has_eval_clos f.to_has_eval) hf) with hf', simp only [choices.one, choices.none] at hf' hcs1, simp only [hcs1, nat.one_ne_zero] at hf', contradiction end lemma factory.call_sym_cast {c : SymV} {w : lang.val D O} {i : ℕ} (hi : i < (f.cast c).length) : f.evalV m c = w → (f.cast c).filter (λ (gv : choice SymB (clos D O SymV)), f.evalB m gv.guard) = [(f.cast c).nth_le i hi] → ∃ e, ((f.cast c).nth_le i hi).value.env.eval f.to_has_eval m = e ∧ w = lang.val.clos ((f.cast c).nth_le i hi).value.var ((f.cast c).nth_le i hi).value.exp e := begin intros hw hf, have h1 : ((f.cast c).one f.to_has_eval m) := by { apply choices.filter_implies_one (has_eval_clos f.to_has_eval), apply exists.intro i, apply exists.intro hi, exact hf, }, rcases (f.cast_sound m c) with ⟨hsc1, hsc2⟩, rewrite ←hw, apply exists.intro (env.eval f.to_has_eval m (list.nth_le (f.cast c) i hi).value.env), simp only [true_and, eq_self_iff_true], cases (f.to_has_eval.evalV m c).is_clos, { simp only [choices.none, choices.true, has_eval_clos, forall_true_left, not_false_iff, coe_sort_ff] at hsc2, simp only [choices.one, choices.true, hsc2, nat.zero_ne_one] at h1, contradiction, }, { simp only [coe_sort_tt, forall_true_left] at hsc1, rcases hsc1 with ⟨_, hsc1⟩, rewrite ←hsc1, rcases (choices.filter_one_eval (has_eval_clos f.to_has_eval) (f.to_has_eval.evalV m c) hf) with hfc, rewrite hfc, simp only [has_eval_clos, clos.eval, eq_self_iff_true, and_self], } end lemma factory.call_sym_same_idx {gvs : choices SymB (clos D O SymV)} {grs : choices SymB (result SymB SymV)} {i : ℕ} (hv : i < gvs.length) (hr : i < grs.length) : gvs.map choice.guard = grs.map choice.guard → gvs.filter (λ gv, f.evalB m gv.guard) = [gvs.nth_le i hv] → grs.filter (λ gv, f.evalB m gv.guard) = [grs.nth_le i hr] := begin intros heq hfv, have hv1 : (gvs.one f.to_has_eval m) := by { apply choices.filter_implies_one (has_eval_clos f.to_has_eval), apply exists.intro i, apply exists.intro hv, exact hfv, }, rcases (choices.eq_one (has_eval_result f.to_has_eval) heq hv1) with hfr, rewrite choices.one_iff_filter at hfr, rcases hfr with ⟨j, hj, hfr⟩, simp only [has_eval_result] at hfr, rewrite hfr, congr, by_contradiction, rewrite ←ne.def at h, rcases (choices.filter_one_guard (has_eval_clos f.to_has_eval) hfv) with hi, simp only [has_eval_clos] at hi, rcases (choices.filter_one_rest (has_eval_result f.to_has_eval) hj hr hfr h) with hi', simp only [has_eval_result, eq_ff_eq_not_eq_tt] at hi', have hh : i < (list.map choice.guard gvs).length := by { simp only [hv, list.length_map], }, rcases (list.nth_le_of_eq heq hh) with heq_i, simp only [list.nth_le_map'] at heq_i, simp only [heq_i, hi', coe_sort_ff] at hi, contradiction, end lemma factory.call_sym_rc {ε : env SymV} {σ σ' : state SymB} {x1 x2 : ℕ} {c v: SymV} {grs : choices SymB (result SymB SymV)} {e : lang.env D O} {r : lang.result D O} (h1 : evalS f (exp.var x1) ε σ (result.ans σ c)) (h2 : evalS f (exp.var x2) ε σ (result.ans σ v)) (h3 : σ' = f.assert σ (f.some choice.guard (f.cast c))) (h4 : ¬↥(f.is_ff (f.some choice.guard (f.cast c))) ∧ ¬↥(f.halted σ')) (h5 : list.map choice.guard (f.cast c) = list.map choice.guard grs) (h6 : ∀ (i : ℕ) (hc : i < list.length (f.cast c)) (hr : i < list.length grs), evalS f (list.nth_le (f.cast c) i hc).value.exp (list.update_nth (list.nth_le (f.cast c) i hc).value.env (list.nth_le (f.cast c) i hc).value.var v) (f.assume σ' (list.nth_le (f.cast c) i hc).guard) (list.nth_le grs i hr).value) (ih1: (state.normal f.to_has_eval m σ) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m (result.ans σ c) = r → evalC f.opC (exp.var x1) e r) (ih2: (state.normal f.to_has_eval m σ) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m (result.ans σ v) = r → evalC f.opC (exp.var x2) e r) (ih6: ∀ (i : ℕ) (hc : i < list.length (f.cast c)) (hr : i < list.length grs), (λ {x : exp D O} {ε : env SymV} {σ : state SymB} {ρ : result SymB SymV} (hs : evalS f x ε σ ρ), (state.normal f.to_has_eval m σ) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m ρ = r → evalC f.opC x e r) (h6 i hc hr)) (hn : (state.normal f.to_has_eval m σ)) (hε : env.eval f.to_has_eval m ε = e) (hr : result.eval f.to_has_eval m (f.merge_ρ σ' grs) = r) : evalC f.opC (exp.call x1 x2) e r := begin rcases (f.normal_ans_rc c hn) with ⟨w1, hw1, h1e⟩, rcases (f.normal_ans_rc v hn) with ⟨w2, hw2, h2e⟩, specialize ih1 hn hε h1e, specialize ih2 hn hε h2e, have hlen : (f.cast c).length = grs.length := by { apply_fun list.length at h5, simp only [list.length_map] at h5, exact h5, }, cases hgc : (f.evalB m (f.some choice.guard (f.cast c))), { have hf : ↥(state.errored f.to_has_eval m σ') := by { simp only [state.normal, bool.to_bool_and, bool.to_bool_coe, band_coe_iff] at hn, simp only [h3, factory.assert, state.errored, hn, f.and_sound, f.imp_sound, hgc, true_and, eq_ff_eq_not_eq_tt, bool.of_to_bool_iff, forall_true_left, not_false_iff], }, rcases (state.errored_not_normal f.to_has_eval hf) with hn', rewrite ←bool_iff_false at hn', have hh : state.eqv f.to_has_eval m (f.merge_ρ σ' grs).state σ' := by { apply f.merge_ρ_eqp, intros i hi, have hic : i < (f.cast c).length := by { simp only [hlen, hi], }, specialize h6 i hic hi, have heq : state.eqv f.to_has_eval m (f.assume σ' (list.nth_le (f.cast c) i hic).guard) σ' := by {apply f.assume_hp hn',}, transitivity (f.assume σ' (list.nth_le (f.cast c) i hic).guard), { apply svm_hp f _ h6, apply state.eqv_abnormal f.to_has_eval hn', symmetry, exact heq, }, { exact heq, } }, rcases (state.eqv_abnormal f.to_has_eval hn' (state.eqv.symm f.to_has_eval m hh)) with hnm, rewrite ←hr, rewrite result.eval_halt f.to_has_eval hnm, rewrite state.eqv_aborted f.to_has_eval hh, rewrite state.errored_not_aborted f.to_has_eval hf, rewrite ←lang.err, apply evalC.call_halt ih1 ih2, apply f.not_some_cast_not_clos hgc hw1, }, { rewrite bool.tt_eq_true at hgc, rcases (f.assert_normal_true hn hgc) with hn', rewrite ←h3 at hn', rcases (f.assert_some_cast_one hn hn' h3) with h_one, rcases (choices.one_implies_filter (has_eval_clos f.to_has_eval) h_one) with ⟨i, hic, hfc⟩, simp only [has_eval_clos] at hfc, have hig : i < list.length grs := by { rewrite ←hlen, exact hic, }, rcases (f.call_sym_same_idx hic hig h5 hfc) with hfg, have hl : ↥(result.legal f.to_has_eval m (list.nth_le grs i hig).value) := by { specialize h6 i hic hig, apply svm_lgl f _ h6, apply f.assume_lgl, apply state.normal_is_legal f.to_has_eval hn', }, rcases (f.merge_ρ_normal_eval hn' hfg hl) with hm, rewrite [←hr, hm], rcases (f.call_sym_cast hic hw1 hfc) with ⟨ce, hce, hcw1⟩, simp only [hcw1] at ih1, apply evalC.call ih1 ih2, apply ih6 i hic hig _ _ rfl, { apply f.assume_normal_true hn', apply choices.filter_one_guard (has_eval_clos f.to_has_eval) hfc, }, { apply env.eval_update f.to_has_eval, exact hce, exact hw2, }, } end lemma factory.call_halt_rc {ε : env SymV} {σ σ' : state SymB} {x1 x2 : ℕ} {c v: SymV} {e : lang.env D O} {r : lang.result D O} (h1 : evalS f (exp.var x1) ε σ (result.ans σ c)) (h2 : evalS f (exp.var x2) ε σ (result.ans σ v)) (h3 : σ' = f.assert σ (f.some choice.guard (f.cast c))) (h4 : ↥(f.is_ff (f.some choice.guard (f.cast c))) ∨ ↥(f.halted σ')) (ih1: (state.normal f.to_has_eval m σ) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m (result.ans σ c) = r → evalC f.opC (exp.var x1) e r) (ih2: (state.normal f.to_has_eval m σ) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m (result.ans σ v) = r → evalC f.opC (exp.var x2) e r) (hn : (state.normal f.to_has_eval m σ)) (hε : env.eval f.to_has_eval m ε = e) (hr : result.eval f.to_has_eval m (result.halt σ') = r) : evalC f.opC (exp.call x1 x2) e r := begin rcases (f.normal_ans_rc c hn) with ⟨w1, hw1, h1e⟩, rcases (f.normal_ans_rc v hn) with ⟨w2, hw2, h2e⟩, specialize ih1 hn hε h1e, specialize ih2 hn hε h2e, rewrite ←hr, simp only [result.eval], simp only [state.normal, bool.to_bool_and, bool.to_bool_coe, band_coe_iff] at hn, have hf : f.to_has_eval.evalB m (f.some choice.guard (f.cast c)) = ff := by { cases h4, { simp only [f.is_ff_sound] at h4, simp only [h4, f.mk_ff_sound], }, { simp only [factory.halted, h3, factory.assert, bor_coe_iff] at h4, cases h4; simp only [f.is_ff_sound] at h4; apply_fun (f.evalB m) at h4, { simp only [f.mk_ff_sound] at h4, simp only [h4, coe_sort_ff, false_and] at hn, contradiction, }, { simp only [f.and_sound, hn, f.imp_sound, f.mk_ff_sound, true_and, bool.to_bool_coe, forall_true_left] at h4, exact h4, } } }, have hh : ↥(state.errored f.to_has_eval m σ') := by { simp only [h3, factory.assert, state.errored, hn, f.and_sound, f.imp_sound, hf, true_and, eq_ff_eq_not_eq_tt, bool.of_to_bool_iff, forall_true_left], }, rcases (state.errored_not_aborted f.to_has_eval hh) with hh', simp only [hh'], rewrite ←lang.err, apply evalC.call_halt ih1 ih2, apply f.not_some_cast_not_clos hf hw1, end lemma factory.let0_rc {ε : env SymV} {σ σ' : state SymB} {y : ℕ} {x1 x2 : exp D O} {v : SymV} {ρ : result SymB SymV} {e : lang.env D O} {r : lang.result D O} (h1 : evalS f x1 ε σ (result.ans σ' v)) (h2 : evalS f x2 (list.update_nth ε y v) σ' ρ) (ih1: (state.normal f.to_has_eval m σ) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m (result.ans σ' v) = r → evalC f.opC x1 e r) (ih2: (state.normal f.to_has_eval m σ') → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m (list.update_nth ε y v) = e → result.eval f.to_has_eval m ρ = r → evalC f.opC x2 e r) (hn : (state.normal f.to_has_eval m σ)) (hε : env.eval f.to_has_eval m ε = e) (hr : result.eval f.to_has_eval m ρ = r) : evalC f.opC (exp.let0 y x1 x2) e r := begin cases hn' : (σ'.normal f.to_has_eval m), { rewrite ←bool_iff_false at hn', have hnv : ¬ (result.ans σ' v).state.normal f.to_has_eval m := by { simp only [result.state, hn', not_false_iff], }, rcases (result.eval_halt f.to_has_eval hnv) with hrv, rcases (svm_hp f hn' h2) with hρ, have hnρ : ¬ ρ.state.normal f.to_has_eval m := by { apply state.eqv_abnormal f.to_has_eval hn', symmetry, exact hρ, }, rcases (result.eval_halt f.to_has_eval hnρ) with hρv, rcases (state.eqv_aborted f.to_has_eval hρ) with heq, specialize ih1 hn hε hrv, simp only [result.state] at ih1, rewrite ←hr, simp only [hρv, heq], apply evalC.let0_halt ih1, }, { rewrite bool.tt_eq_true at hn', rcases (f.normal_ans_rc v hn') with ⟨w, hw, h1r⟩, rcases (env.eval_update f.to_has_eval y hε hw) with hup, specialize @ih1 hn e (lang.result.ans w) hε h1r, specialize @ih2 hn' (list.update_nth e y w) r hup hr, apply evalC.let0 ih1 ih2, } end lemma factory.let0_halt_rc {ε : env SymV} {σ σ' : state SymB} {y : ℕ} {x1 x2 : exp D O} {e : lang.env D O} {r : lang.result D O} (h1 : evalS f x1 ε σ (result.halt σ')) (ih : (state.normal f.to_has_eval m σ) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m (result.halt σ') = r → evalC f.opC x1 e r) (hn : (state.normal f.to_has_eval m σ)) (hε : env.eval f.to_has_eval m ε = e) (hr : result.eval f.to_has_eval m (result.halt σ') = r) : evalC f.opC (exp.let0 y x1 x2) e r := begin specialize @ih hn e r hε hr, simp only [result.eval] at hr, rewrite ←hr, rewrite ←hr at ih, apply evalC.let0_halt ih, end lemma factory.if0_sym_rc {ε : env SymV} {σ : state SymB} {xc : ℕ} {xt xf : exp D O} {v : SymV} {rt rf : result SymB SymV} {e : lang.env D O} {r : lang.result D O} (hc : evalS f (exp.var xc) ε σ (result.ans σ v)) (hv : ¬↥(f.is_tt (f.truth v)) ∧ ¬↥(f.is_ff (f.truth v))) (ht : evalS f xt ε (f.assume σ (f.truth v)) rt) (hf : evalS f xf ε (f.assume σ (f.not (f.truth v))) rf) (ihc: (state.normal f.to_has_eval m σ) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m (result.ans σ v) = r → evalC f.opC (exp.var xc) e r) (iht: (state.normal f.to_has_eval m (f.assume σ (f.truth v))) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m rt = r → evalC f.opC xt e r) (ihf: (state.normal f.to_has_eval m (f.assume σ (f.not (f.truth v)))) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m rf = r → evalC f.opC xf e r) (hn : (state.normal f.to_has_eval m σ)) (hε : env.eval f.to_has_eval m ε = e) (hr : result.eval f.to_has_eval m (f.merge_ρ σ [{guard := f.truth v, value := rt}, {guard := f.not (f.truth v), value := rf}]) = r) : evalC f.opC (exp.if0 xc xt xf) e r := begin rcases (f.normal_ans_rc v hn) with ⟨w, hw, hce⟩, specialize (@ihc hn e (lang.result.ans w) hε hce), rcases (f.truth_sound m v) with hbv, rewrite ←hr, cases hb : (f.evalB m (f.truth v)), { rewrite ←bool_iff_false at hb, rcases (f.not_sound m (f.truth v)) with hb', simp only [hb, to_bool_true_eq_tt, coe_sort_tt, iff_true, not_false_iff] at hb', rcases (f.assume_normal_true hn hb') with hn', have h : list.filter (λ (gv : choice SymB (result SymB SymV)), f.evalB m gv.guard) [choice.mk (f.truth v) rt, choice.mk (f.not (f.truth v)) rf] = [⟨f.not (f.truth v), rf⟩] := by { simp only [list.filter, hb, hb', if_true, eq_self_iff_true, if_false, and_self, coe_sort_tt], }, have hl : ↥((choice.mk (f.not (f.truth v)) rf).value.legal f.to_has_eval m) := by { simp only, apply svm_lgl f (state.normal_is_legal f.to_has_eval hn') hf, }, rcases (f.merge_ρ_normal_eval hn h hl) with hrf, simp only at hrf, specialize ihf hn' hε (eq.symm hrf), apply evalC.if0_false ihc _ ihf, simp only [hbv, hw, not_not] at hb, exact hb, }, { rewrite bool.tt_eq_true at hb, rcases (f.assume_normal_true hn hb) with hn', have h : list.filter (λ (gv : choice SymB (result SymB SymV)), f.evalB m gv.guard) [choice.mk (f.truth v) rt, choice.mk (f.not (f.truth v)) rf] = [⟨f.truth v, rt⟩] := by { simp only [list.filter, hb, f.not_sound, to_bool_false_eq_ff, if_true, eq_self_iff_true, not_true, if_false, and_self, coe_sort_ff], }, have hl : ↥((choice.mk (f.truth v) rt).value.legal f.to_has_eval m) := by { simp only, apply svm_lgl f (state.normal_is_legal f.to_has_eval hn') ht, }, rcases (f.merge_ρ_normal_eval hn h hl) with hrt, simp only at hrt, specialize iht hn' hε (eq.symm hrt), apply evalC.if0_true ihc _ iht, rewrite [hbv, hw] at hb, exact hb, } end lemma factory.if0_true_rc {ε : env SymV} {σ : state SymB} {xc : ℕ} {xt xf : exp D O} {v : SymV} {ρ : result SymB SymV} {e : lang.env D O} {r : lang.result D O} (hc : evalS f (exp.var xc) ε σ (result.ans σ v)) (hv : (f.is_tt (f.truth v))) (hr : evalS f xt ε σ ρ) (ihc: (state.normal f.to_has_eval m σ) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m (result.ans σ v) = r → evalC f.opC (exp.var xc) e r) (ihr: (state.normal f.to_has_eval m σ) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m ρ = r → evalC f.opC xt e r) (hn : (state.normal f.to_has_eval m σ)) (hε : env.eval f.to_has_eval m ε = e) (hr : result.eval f.to_has_eval m ρ = r) : evalC f.opC (exp.if0 xc xt xf) e r := begin rcases (f.normal_ans_rc v hn) with ⟨w, hw, hce⟩, specialize (@ihc hn e (lang.result.ans w) hε hce), specialize (@ihr hn e r hε hr), apply evalC.if0_true ihc _ ihr, rcases (f.truth_sound m v) with ht, rewrite [←hw, ←ht], rewrite [f.is_tt_sound] at hv, apply_fun (f.evalB m) at hv, simp only [f.mk_tt_sound] at hv, simp only [hv, coe_sort_tt], end lemma factory.if0_false_rc {ε : env SymV} {σ : state SymB} {xc : ℕ} {xt xf : exp D O} {v : SymV} {ρ : result SymB SymV} {e : lang.env D O} {r : lang.result D O} (hc : evalS f (exp.var xc) ε σ (result.ans σ v)) (hv : (f.is_ff (f.truth v))) (hr : evalS f xf ε σ ρ) (ihc: (state.normal f.to_has_eval m σ) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m (result.ans σ v) = r → evalC f.opC (exp.var xc) e r) (ihr: (state.normal f.to_has_eval m σ) → ∀ {e : lang.env D O} {r : lang.result D O}, env.eval f.to_has_eval m ε = e → result.eval f.to_has_eval m ρ = r → evalC f.opC xf e r) (hn : (state.normal f.to_has_eval m σ)) (hε : env.eval f.to_has_eval m ε = e) (hr : result.eval f.to_has_eval m ρ = r) : evalC f.opC (exp.if0 xc xt xf) e r := begin rcases (f.normal_ans_rc v hn) with ⟨w, hw, hce⟩, specialize (@ihc hn e (lang.result.ans w) hε hce), specialize (@ihr hn e r hε hr), apply evalC.if0_false ihc _ ihr, rcases (f.truth_sound m v) with ht, rewrite [f.is_ff_sound] at hv, apply_fun (f.evalB m) at hv, simp only [f.mk_ff_sound] at hv, simp only [hw, hv, false_iff, not_not, coe_sort_ff] at ht, exact ht, end lemma factory.error_rc {ε : env SymV} {σ : state SymB} {e : lang.env D O} {r : lang.result D O} (hn : (state.normal f.to_has_eval m σ)) (hε : env.eval f.to_has_eval m ε = e) (hr : result.eval f.to_has_eval m (result.halt (f.assert σ f.mk_ff)) = r) : evalC f.opC exp.error e r := begin simp only [state.normal, bool.to_bool_and, bool.to_bool_coe, band_coe_iff] at hn, simp only [result.eval, state.aborted, factory.assert, hn, to_bool_false_eq_ff, not_true, false_and] at hr, rewrite ←hr, apply evalC.error, end lemma factory.abort_rc {ε : env SymV} {σ : state SymB} {e : lang.env D O} {r : lang.result D O} (hn : (state.normal f.to_has_eval m σ)) (hε : env.eval f.to_has_eval m ε = e) (hr : result.eval f.to_has_eval m (result.halt (f.assume σ f.mk_ff)) = r) : evalC f.opC exp.abort e r := begin simp only [state.normal, bool.to_bool_and, bool.to_bool_coe, band_coe_iff] at hn, simp only [result.eval, state.aborted, factory.assume, hn, f.and_sound, f.imp_sound, f.mk_ff_sound, to_bool_false_eq_ff, to_bool_true_eq_tt, forall_true_left, not_false_iff, and_self, and_false, coe_sort_ff] at hr, rewrite ←hr, apply evalC.abort, end -- The SVM rules are relatively complete with respect to the concrete -- semantics: if the SVM terminates on a well-formed input state σ -- and well-formed symbolic environment ε to produce a result ρ, -- then for any model m under which σ is normal and ε evaluates to -- the concrete environment e = ε.eval m, executing the concrete semantics on -- e terminates and leads to a result r if r = ρ.eval m. theorem svm_rc {x : exp D O} {ε : env SymV} {e : lang.env D O} {σ : state SymB} {ρ : result SymB SymV} {r : lang.result D O} : σ.normal f.to_has_eval m → ε.eval f.to_has_eval m = e → evalS f x ε σ ρ → ρ.eval f.to_has_eval m = r → evalC f.opC x e r := begin intros hn hε hs hr, induction hs generalizing e r, case sym.evalS.bool { simp only [result.eval, f.bval_sound, hn, if_true] at hr, rewrite ←hr, apply evalC.bool, }, case sym.evalS.datum { simp only [result.eval, f.dval_sound, hn, if_true] at hr, rewrite ←hr, apply evalC.datum, }, case sym.evalS.lam { simp only [result.eval, f.cval_sound, hn, clos.eval, hε, coe, lift_t, has_lift_t.lift, coe_t, has_coe_t.coe, if_true] at hr, rewrite ←hr, apply evalC.lam, }, case sym.evalS.var { apply f.var_rc hs_hy hn hε hr, }, case sym.evalS.app { apply f.app_rc hs_h1 hs_h2 hs_ih hn hε hr, }, case sym.evalS.call_sym { apply f.call_sym_rc hs_h1 hs_h2 hs_h3 hs_h4 hs_h5 hs_h6 hs_ih_h1 hs_ih_h2 hs_ih_h6 hn hε hr, }, case sym.evalS.call_halt { apply f.call_halt_rc hs_h1 hs_h2 hs_h3 hs_h4 hs_ih_h1 hs_ih_h2 hn hε hr, }, case sym.evalS.let0 { apply f.let0_rc hs_h1 hs_h2 hs_ih_h1 hs_ih_h2 hn hε hr, }, case sym.evalS.let0_halt { apply f.let0_halt_rc hs_h1 hs_ih hn hε hr, }, case sym.evalS.if0_true { apply f.if0_true_rc hs_hc hs_hv hs_hr hs_ih_hc hs_ih_hr hn hε hr, }, case sym.evalS.if0_false { apply f.if0_false_rc hs_hc hs_hv hs_hr hs_ih_hc hs_ih_hr hn hε hr, }, case sym.evalS.if0_sym { apply f.if0_sym_rc hs_hc hs_hv hs_ht hs_hf hs_ih_hc hs_ih_ht hs_ih_hf hn hε hr, }, case sym.evalS.error { apply f.error_rc hn hε hr }, case sym.evalS.abort { apply f.abort_rc hn hε hr }, end -- The SVM rules are relatively sound and complete with respect to the concrete -- semantics: if the SVM terminates on a well-formed input state σ -- and symbolic environment ε to produce a result ρ, -- then for any model m under which σ is normal and ε evaluates to -- the concrete environment e = ε.eval m, executing the concrete semantics on -- e terminates and leads to a result r if and only if r = ρ.eval m. theorem svm_rsc {x : exp D O} {ε : env SymV} {e : lang.env D O} {σ : state SymB} {ρ : result SymB SymV} {r : lang.result D O} : σ.normal f.to_has_eval m → ε.eval f.to_has_eval m = e → evalS f x ε σ ρ → (evalC f.opC x e r ↔ ρ.eval f.to_has_eval m = r) := begin intros hn hε hs, constructor, { intro hrc, rcases (svm_rc f hn hε hs rfl) with hr, apply evalC_det hr hrc, }, { apply svm_rc f hn hε hs, } end end rsc end sym
31385be930e27309205549ee0fbe08916f0a107f
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/ring_theory/free_ring_auto.lean
5df4035bde318b69ea452420c84acbfb7994a5b5
[]
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
2,747
lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Johan Commelin -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.group_theory.free_abelian_group import Mathlib.ring_theory.subring import Mathlib.PostPort universes u v namespace Mathlib /-! # Free rings The theory of the free ring over a type. ## Main definitions * `free_ring α` : the free (not commutative in general) ring over a type. * `lift (f : α → R)` : the ring hom `free_ring α →+* R` induced by `f`. * `map (f : α → β)` : the ring hom `free_ring α →+* free_ring β` induced by `f`. ## Implementation details `free_ring α` is implemented as the free abelian group over the free monoid on `α`. ## Tags free ring -/ /-- The free ring over a type `α`. -/ def free_ring (α : Type u) := free_abelian_group (free_monoid α) namespace free_ring protected instance ring (α : Type u) : ring (free_ring α) := free_abelian_group.ring (free_monoid α) protected instance inhabited (α : Type u) : Inhabited (free_ring α) := { default := 0 } /-- The canonical map from α to `free_ring α`. -/ def of {α : Type u} (x : α) : free_ring α := free_abelian_group.of [x] theorem of_injective {α : Type u} : function.injective of := function.injective.comp free_abelian_group.of_injective free_monoid.of_injective protected theorem induction_on {α : Type u} {C : free_ring α → Prop} (z : free_ring α) (hn1 : C (-1)) (hb : ∀ (b : α), C (of b)) (ha : ∀ (x y : free_ring α), C x → C y → C (x + y)) (hm : ∀ (x y : free_ring α), C x → C y → C (x * y)) : C z := sorry /-- The ring homomorphism `free_ring α →+* R` induced from a map `α → R`. -/ def lift {α : Type u} {R : Type v} [ring R] (f : α → R) : free_ring α →+* R := ring_hom.mk (add_monoid_hom.to_fun (free_abelian_group.lift fun (L : List α) => list.prod (list.map f L))) sorry sorry sorry sorry @[simp] theorem lift_of {α : Type u} {R : Type v} [ring R] (f : α → R) (x : α) : coe_fn (lift f) (of x) = f x := Eq.trans (free_abelian_group.lift.of (fun (L : List α) => list.prod (list.map f L)) [x]) (one_mul (f x)) @[simp] theorem lift_comp_of {α : Type u} {R : Type v} [ring R] (f : free_ring α →+* R) : lift (⇑f ∘ of) = f := sorry /-- The canonical ring homomorphism `free_ring α →+* free_ring β` generated by a map `α → β`. -/ def map {α : Type u} {β : Type v} (f : α → β) : free_ring α →+* free_ring β := lift (of ∘ f) @[simp] theorem map_of {α : Type u} {β : Type v} (f : α → β) (x : α) : coe_fn (map f) (of x) = of (f x) := lift_of (of ∘ f) x end Mathlib
446b1ad129f61949d36131fcb48d9024914bb7d3
36c7a18fd72e5b57229bd8ba36493daf536a19ce
/hott/homotopy/circle.hlean
03fc4df632717009b742a381fa55ebfa095279e7
[ "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
9,787
hlean
/- Copyright (c) 2015 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn Declaration of the circle -/ import .sphere import types.bool types.int.hott types.equiv import algebra.homotopy_group algebra.hott open eq susp bool sphere_index is_equiv equiv equiv.ops is_trunc pi definition circle : Type₀ := sphere 1 namespace circle notation `S¹` := circle definition base1 : circle := !north definition base2 : circle := !south definition seg1 : base1 = base2 := merid !north definition seg2 : base1 = base2 := merid !south definition base : circle := base1 definition loop : base = base := seg2 ⬝ seg1⁻¹ definition rec2 {P : circle → Type} (Pb1 : P base1) (Pb2 : P base2) (Ps1 : Pb1 =[seg1] Pb2) (Ps2 : Pb1 =[seg2] Pb2) (x : circle) : P x := begin induction x with b, { exact Pb1}, { exact Pb2}, { esimp at *, induction b with y, { exact Ps1}, { exact Ps2}, { cases y}}, end definition rec2_on [reducible] {P : circle → Type} (x : circle) (Pb1 : P base1) (Pb2 : P base2) (Ps1 : Pb1 =[seg1] Pb2) (Ps2 : Pb1 =[seg2] Pb2) : P x := circle.rec2 Pb1 Pb2 Ps1 Ps2 x theorem rec2_seg1 {P : circle → Type} (Pb1 : P base1) (Pb2 : P base2) (Ps1 : Pb1 =[seg1] Pb2) (Ps2 : Pb1 =[seg2] Pb2) : apdo (rec2 Pb1 Pb2 Ps1 Ps2) seg1 = Ps1 := !rec_merid theorem rec2_seg2 {P : circle → Type} (Pb1 : P base1) (Pb2 : P base2) (Ps1 : Pb1 =[seg1] Pb2) (Ps2 : Pb1 =[seg2] Pb2) : apdo (rec2 Pb1 Pb2 Ps1 Ps2) seg2 = Ps2 := !rec_merid definition elim2 {P : Type} (Pb1 Pb2 : P) (Ps1 Ps2 : Pb1 = Pb2) (x : circle) : P := rec2 Pb1 Pb2 (pathover_of_eq Ps1) (pathover_of_eq Ps2) x definition elim2_on [reducible] {P : Type} (x : circle) (Pb1 Pb2 : P) (Ps1 : Pb1 = Pb2) (Ps2 : Pb1 = Pb2) : P := elim2 Pb1 Pb2 Ps1 Ps2 x theorem elim2_seg1 {P : Type} (Pb1 Pb2 : P) (Ps1 : Pb1 = Pb2) (Ps2 : Pb1 = Pb2) : ap (elim2 Pb1 Pb2 Ps1 Ps2) seg1 = Ps1 := begin apply eq_of_fn_eq_fn_inv !(pathover_constant seg1), rewrite [▸*,-apdo_eq_pathover_of_eq_ap,↑elim2,rec2_seg1], end theorem elim2_seg2 {P : Type} (Pb1 Pb2 : P) (Ps1 : Pb1 = Pb2) (Ps2 : Pb1 = Pb2) : ap (elim2 Pb1 Pb2 Ps1 Ps2) seg2 = Ps2 := begin apply eq_of_fn_eq_fn_inv !(pathover_constant seg2), rewrite [▸*,-apdo_eq_pathover_of_eq_ap,↑elim2,rec2_seg2], end definition elim2_type (Pb1 Pb2 : Type) (Ps1 Ps2 : Pb1 ≃ Pb2) (x : circle) : Type := elim2 Pb1 Pb2 (ua Ps1) (ua Ps2) x definition elim2_type_on [reducible] (x : circle) (Pb1 Pb2 : Type) (Ps1 Ps2 : Pb1 ≃ Pb2) : Type := elim2_type Pb1 Pb2 Ps1 Ps2 x theorem elim2_type_seg1 (Pb1 Pb2 : Type) (Ps1 Ps2 : Pb1 ≃ Pb2) : transport (elim2_type Pb1 Pb2 Ps1 Ps2) seg1 = Ps1 := by rewrite [tr_eq_cast_ap_fn,↑elim2_type,elim2_seg1];apply cast_ua_fn theorem elim2_type_seg2 (Pb1 Pb2 : Type) (Ps1 Ps2 : Pb1 ≃ Pb2) : transport (elim2_type Pb1 Pb2 Ps1 Ps2) seg2 = Ps2 := by rewrite [tr_eq_cast_ap_fn,↑elim2_type,elim2_seg2];apply cast_ua_fn protected definition rec {P : circle → Type} (Pbase : P base) (Ploop : Pbase =[loop] Pbase) (x : circle) : P x := begin fapply (rec2_on x), { exact Pbase}, { exact (transport P seg1 Pbase)}, { apply pathover_tr}, { apply pathover_tr_of_pathover, exact Ploop} end protected definition rec_on [reducible] {P : circle → Type} (x : circle) (Pbase : P base) (Ploop : Pbase =[loop] Pbase) : P x := circle.rec Pbase Ploop x theorem rec_loop_helper {A : Type} (P : A → Type) {x y z : A} {p : x = y} {p' : z = y} {u : P x} {v : P z} (q : u =[p ⬝ p'⁻¹] v) : pathover_tr_of_pathover q ⬝o !pathover_tr⁻¹ᵒ = q := by cases p'; cases q; exact idp definition con_refl {A : Type} {x y : A} (p : x = y) : p ⬝ refl _ = p := eq.rec_on p idp theorem rec_loop {P : circle → Type} (Pbase : P base) (Ploop : Pbase =[loop] Pbase) : apdo (circle.rec Pbase Ploop) loop = Ploop := begin rewrite [↑loop,apdo_con,↑circle.rec,↑circle.rec2_on,↑base,rec2_seg2,apdo_inv,rec2_seg1], apply rec_loop_helper end protected definition elim {P : Type} (Pbase : P) (Ploop : Pbase = Pbase) (x : circle) : P := circle.rec Pbase (pathover_of_eq Ploop) x protected definition elim_on [reducible] {P : Type} (x : circle) (Pbase : P) (Ploop : Pbase = Pbase) : P := circle.elim Pbase Ploop x theorem elim_loop {P : Type} (Pbase : P) (Ploop : Pbase = Pbase) : ap (circle.elim Pbase Ploop) loop = Ploop := begin apply eq_of_fn_eq_fn_inv !(pathover_constant loop), rewrite [▸*,-apdo_eq_pathover_of_eq_ap,↑circle.elim,rec_loop], end protected definition elim_type (Pbase : Type) (Ploop : Pbase ≃ Pbase) (x : circle) : Type := circle.elim Pbase (ua Ploop) x protected definition elim_type_on [reducible] (x : circle) (Pbase : Type) (Ploop : Pbase ≃ Pbase) : Type := circle.elim_type Pbase Ploop x theorem elim_type_loop (Pbase : Type) (Ploop : Pbase ≃ Pbase) : transport (circle.elim_type Pbase Ploop) loop = Ploop := by rewrite [tr_eq_cast_ap_fn,↑circle.elim_type,circle.elim_loop];apply cast_ua_fn theorem elim_type_loop_inv (Pbase : Type) (Ploop : Pbase ≃ Pbase) : transport (circle.elim_type Pbase Ploop) loop⁻¹ = to_inv Ploop := by rewrite [tr_inv_fn]; apply inv_eq_inv; apply elim_type_loop end circle attribute circle.base1 circle.base2 circle.base [constructor] attribute circle.rec2 circle.elim2 [unfold 6] [recursor 6] attribute circle.elim2_type [unfold 5] attribute circle.rec2_on circle.elim2_on [unfold 2] attribute circle.elim2_type [unfold 1] attribute circle.rec circle.elim [unfold 4] [recursor 4] attribute circle.elim_type [unfold 3] attribute circle.rec_on circle.elim_on [unfold 2] attribute circle.elim_type_on [unfold 1] namespace circle definition pointed_circle [instance] [constructor] : pointed circle := pointed.mk base definition Circle [constructor] : Type* := pointed.mk' circle notation `S¹.` := Circle definition loop_neq_idp : loop ≠ idp := assume H : loop = idp, have H2 : Π{A : Type₁} {a : A} {p : a = a}, p = idp, from λA a p, calc p = ap (circle.elim a p) loop : elim_loop ... = ap (circle.elim a p) (refl base) : by rewrite H, eq_bnot_ne_idp H2 definition nonidp (x : circle) : x = x := begin induction x, { exact loop}, { apply concato_eq, apply pathover_eq_lr, rewrite [con.left_inv,idp_con]} end definition nonidp_neq_idp : nonidp ≠ (λx, idp) := assume H : nonidp = λx, idp, have H2 : loop = idp, from apd10 H base, absurd H2 loop_neq_idp open int protected definition code [unfold 1] (x : circle) : Type₀ := circle.elim_type_on x ℤ equiv_succ definition transport_code_loop (a : ℤ) : transport circle.code loop a = succ a := ap10 !elim_type_loop a definition transport_code_loop_inv (a : ℤ) : transport circle.code loop⁻¹ a = pred a := ap10 !elim_type_loop_inv a protected definition encode [unfold 2] {x : circle} (p : base = x) : circle.code x := transport circle.code p (of_num 0) protected definition decode [unfold 1] {x : circle} : circle.code x → base = x := begin induction x, { exact power loop}, { apply arrow_pathover_left, intro b, apply concato_eq, apply pathover_eq_r, rewrite [power_con,transport_code_loop]} end definition circle_eq_equiv [constructor] (x : circle) : (base = x) ≃ circle.code x := begin fapply equiv.MK, { exact circle.encode}, { exact circle.decode}, { exact abstract [irreducible] begin induction x, { intro a, esimp, apply rec_nat_on a, { exact idp}, { intros n p, rewrite [↑circle.encode, -power_con, con_tr, transport_code_loop], exact ap succ p}, { intros n p, rewrite [↑circle.encode, nat_succ_eq_int_succ, neg_succ, -power_con_inv, @con_tr _ circle.code, transport_code_loop_inv, ↑[circle.encode] at p, p, -neg_succ] }}, { apply pathover_of_tr_eq, apply eq_of_homotopy, intro a, apply @is_hset.elim, esimp, exact _} end end}, { intro p, cases p, exact idp}, end definition base_eq_base_equiv [constructor] : base = base ≃ ℤ := circle_eq_equiv base definition decode_add (a b : ℤ) : circle.decode a ⬝ circle.decode b = circle.decode (a + b) := !power_con_power definition encode_con (p q : base = base) : circle.encode (p ⬝ q) = circle.encode p + circle.encode q := preserve_binary_of_inv_preserve base_eq_base_equiv concat add decode_add p q --the carrier of π₁(S¹) is the set-truncation of base = base. open algebra trunc equiv.ops definition fg_carrier_equiv_int : π[1](S¹.) ≃ ℤ := trunc_equiv_trunc 0 base_eq_base_equiv ⬝e !trunc_equiv definition con_comm_base (p q : base = base) : p ⬝ q = q ⬝ p := eq_of_fn_eq_fn base_eq_base_equiv (by esimp;rewrite [+encode_con,add.comm]) definition fundamental_group_of_circle : π₁(S¹.) = group_integers := begin apply (Group_eq fg_carrier_equiv_int), intros g h, induction g with g', induction h with h', apply encode_con, end open nat definition homotopy_group_of_circle (n : ℕ) : πG[n+1 +1] S¹. = G0 := begin refine @trivial_homotopy_of_is_hset_loop_space S¹. 1 n _, apply is_trunc_equiv_closed_rev, apply base_eq_base_equiv end definition eq_equiv_Z (x : S¹) : x = x ≃ ℤ := begin induction x, { apply base_eq_base_equiv}, { apply equiv_pathover, intro p p' q, apply pathover_of_eq, let H := eq_of_square (square_of_pathover q), rewrite con_comm_base at H, let H' := cancel_left H, induction H', reflexivity} end end circle
832a4999e098b787c2a26094094b39c7b97d9539
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/extmacro.lean
a8ba0c7b821c8c5006d0984236a1dcac26621bbb
[ "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
481
lean
macro "ext_tactic" t:tactic "=>" newT:tactic : command => `(macro_rules | `(tactic| $t) => `(tactic| $newT)) syntax "trivial'" : tactic ext_tactic trivial' => apply Eq.refl theorem tst1 (x : Nat) : x = x := by trivial' -- theorem tst2 (x y : Nat) (h : x = y) : x = y := -- by trivial' -- fail as expected ext_tactic trivial' => assumption theorem tst1b (x : Nat) : x = x := by trivial' -- still works theorem tst2 (x y : Nat) (h : x = y) : x = y := by trivial' -- works too
540b30f539840877f915204fb76881b5ad1404e2
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/analysis/analytic/basic.lean
d8f3bfea0cfebb606fe57903b016ad97edbe7f9e
[ "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
66,305
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, Yury Kudryashov -/ import analysis.calculus.formal_multilinear_series import analysis.specific_limits.normed import logic.equiv.fin /-! # Analytic functions A function is analytic in one dimension around `0` if it can be written as a converging power series `Σ pₙ zⁿ`. This definition can be extended to any dimension (even in infinite dimension) by requiring that `pₙ` is a continuous `n`-multilinear map. In general, `pₙ` is not unique (in two dimensions, taking `p₂ (x, y) (x', y') = x y'` or `y x'` gives the same map when applied to a vector `(x, y) (x, y)`). A way to guarantee uniqueness is to take a symmetric `pₙ`, but this is not always possible in nonzero characteristic (in characteristic 2, the previous example has no symmetric representative). Therefore, we do not insist on symmetry or uniqueness in the definition, and we only require the existence of a converging series. The general framework is important to say that the exponential map on bounded operators on a Banach space is analytic, as well as the inverse on invertible operators. ## Main definitions Let `p` be a formal multilinear series from `E` to `F`, i.e., `p n` is a multilinear map on `E^n` for `n : ℕ`. * `p.radius`: the largest `r : ℝ≥0∞` such that `‖p n‖ * r^n` grows subexponentially. * `p.le_radius_of_bound`, `p.le_radius_of_bound_nnreal`, `p.le_radius_of_is_O`: if `‖p n‖ * r ^ n` is bounded above, then `r ≤ p.radius`; * `p.is_o_of_lt_radius`, `p.norm_mul_pow_le_mul_pow_of_lt_radius`, `p.is_o_one_of_lt_radius`, `p.norm_mul_pow_le_of_lt_radius`, `p.nnnorm_mul_pow_le_of_lt_radius`: if `r < p.radius`, then `‖p n‖ * r ^ n` tends to zero exponentially; * `p.lt_radius_of_is_O`: if `r ≠ 0` and `‖p n‖ * r ^ n = O(a ^ n)` for some `-1 < a < 1`, then `r < p.radius`; * `p.partial_sum n x`: the sum `∑_{i = 0}^{n-1} pᵢ xⁱ`. * `p.sum x`: the sum `∑'_{i = 0}^{∞} pᵢ xⁱ`. Additionally, let `f` be a function from `E` to `F`. * `has_fpower_series_on_ball f p x r`: on the ball of center `x` with radius `r`, `f (x + y) = ∑'_n pₙ yⁿ`. * `has_fpower_series_at f p x`: on some ball of center `x` with positive radius, holds `has_fpower_series_on_ball f p x r`. * `analytic_at 𝕜 f x`: there exists a power series `p` such that holds `has_fpower_series_at f p x`. * `analytic_on 𝕜 f s`: the function `f` is analytic at every point of `s`. We develop the basic properties of these notions, notably: * If a function admits a power series, it is continuous (see `has_fpower_series_on_ball.continuous_on` and `has_fpower_series_at.continuous_at` and `analytic_at.continuous_at`). * In a complete space, the sum of a formal power series with positive radius is well defined on the disk of convergence, see `formal_multilinear_series.has_fpower_series_on_ball`. * If a function admits a power series in a ball, then it is analytic at any point `y` of this ball, and the power series there can be expressed in terms of the initial power series `p` as `p.change_origin y`. See `has_fpower_series_on_ball.change_origin`. It follows in particular that the set of points at which a given function is analytic is open, see `is_open_analytic_at`. ## Implementation details We only introduce the radius of convergence of a power series, as `p.radius`. For a power series in finitely many dimensions, there is a finer (directional, coordinate-dependent) notion, describing the polydisk of convergence. This notion is more specific, and not necessary to build the general theory. We do not define it here. -/ noncomputable theory variables {𝕜 E F G : Type*} open_locale topological_space classical big_operators nnreal filter ennreal open set filter asymptotics namespace formal_multilinear_series variables [ring 𝕜] [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F] variables [topological_space E] [topological_space F] variables [topological_add_group E] [topological_add_group F] variables [has_continuous_const_smul 𝕜 E] [has_continuous_const_smul 𝕜 F] /-- Given a formal multilinear series `p` and a vector `x`, then `p.sum x` is the sum `Σ pₙ xⁿ`. A priori, it only behaves well when `‖x‖ < p.radius`. -/ protected def sum (p : formal_multilinear_series 𝕜 E F) (x : E) : F := ∑' n : ℕ , p n (λ i, x) /-- Given a formal multilinear series `p` and a vector `x`, then `p.partial_sum n x` is the sum `Σ pₖ xᵏ` for `k ∈ {0,..., n-1}`. -/ def partial_sum (p : formal_multilinear_series 𝕜 E F) (n : ℕ) (x : E) : F := ∑ k in finset.range n, p k (λ(i : fin k), x) /-- The partial sums of a formal multilinear series are continuous. -/ lemma partial_sum_continuous (p : formal_multilinear_series 𝕜 E F) (n : ℕ) : continuous (p.partial_sum n) := by continuity end formal_multilinear_series /-! ### The radius of a formal multilinear series -/ variables [nontrivially_normed_field 𝕜] [normed_add_comm_group E] [normed_space 𝕜 E] [normed_add_comm_group F] [normed_space 𝕜 F] [normed_add_comm_group G] [normed_space 𝕜 G] namespace formal_multilinear_series variables (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0} /-- The radius of a formal multilinear series is the largest `r` such that the sum `Σ ‖pₙ‖ ‖y‖ⁿ` converges for all `‖y‖ < r`. This implies that `Σ pₙ yⁿ` converges for all `‖y‖ < r`, but these definitions are *not* equivalent in general. -/ def radius (p : formal_multilinear_series 𝕜 E F) : ℝ≥0∞ := ⨆ (r : ℝ≥0) (C : ℝ) (hr : ∀ n, ‖p n‖ * r ^ n ≤ C), (r : ℝ≥0∞) /-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/ lemma le_radius_of_bound (C : ℝ) {r : ℝ≥0} (h : ∀ (n : ℕ), ‖p n‖ * r^n ≤ C) : (r : ℝ≥0∞) ≤ p.radius := le_supr_of_le r $ le_supr_of_le C $ (le_supr (λ _, (r : ℝ≥0∞)) h) /-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/ lemma le_radius_of_bound_nnreal (C : ℝ≥0) {r : ℝ≥0} (h : ∀ (n : ℕ), ‖p n‖₊ * r^n ≤ C) : (r : ℝ≥0∞) ≤ p.radius := p.le_radius_of_bound C $ λ n, by exact_mod_cast (h n) /-- If `‖pₙ‖ rⁿ = O(1)`, as `n → ∞`, then the radius of `p` is at least `r`. -/ lemma le_radius_of_is_O (h : (λ n, ‖p n‖ * r^n) =O[at_top] (λ n, (1 : ℝ))) : ↑r ≤ p.radius := exists.elim (is_O_one_nat_at_top_iff.1 h) $ λ C hC, p.le_radius_of_bound C $ λ n, (le_abs_self _).trans (hC n) lemma le_radius_of_eventually_le (C) (h : ∀ᶠ n in at_top, ‖p n‖ * r ^ n ≤ C) : ↑r ≤ p.radius := p.le_radius_of_is_O $ is_O.of_bound C $ h.mono $ λ n hn, by simpa lemma le_radius_of_summable_nnnorm (h : summable (λ n, ‖p n‖₊ * r ^ n)) : ↑r ≤ p.radius := p.le_radius_of_bound_nnreal (∑' n, ‖p n‖₊ * r ^ n) $ λ n, le_tsum' h _ lemma le_radius_of_summable (h : summable (λ n, ‖p n‖ * r ^ n)) : ↑r ≤ p.radius := p.le_radius_of_summable_nnnorm $ by { simp only [← coe_nnnorm] at h, exact_mod_cast h } lemma radius_eq_top_of_forall_nnreal_is_O (h : ∀ r : ℝ≥0, (λ n, ‖p n‖ * r^n) =O[at_top] (λ n, (1 : ℝ))) : p.radius = ∞ := ennreal.eq_top_of_forall_nnreal_le $ λ r, p.le_radius_of_is_O (h r) lemma radius_eq_top_of_eventually_eq_zero (h : ∀ᶠ n in at_top, p n = 0) : p.radius = ∞ := p.radius_eq_top_of_forall_nnreal_is_O $ λ r, (is_O_zero _ _).congr' (h.mono $ λ n hn, by simp [hn]) eventually_eq.rfl lemma radius_eq_top_of_forall_image_add_eq_zero (n : ℕ) (hn : ∀ m, p (m + n) = 0) : p.radius = ∞ := p.radius_eq_top_of_eventually_eq_zero $ mem_at_top_sets.2 ⟨n, λ k hk, tsub_add_cancel_of_le hk ▸ hn _⟩ @[simp] lemma const_formal_multilinear_series_radius {v : F} : (const_formal_multilinear_series 𝕜 E v).radius = ⊤ := (const_formal_multilinear_series 𝕜 E v).radius_eq_top_of_forall_image_add_eq_zero 1 (by simp [const_formal_multilinear_series]) /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially: for some `0 < a < 1`, `‖p n‖ rⁿ = o(aⁿ)`. -/ lemma is_o_of_lt_radius (h : ↑r < p.radius) : ∃ a ∈ Ioo (0 : ℝ) 1, (λ n, ‖p n‖ * r ^ n) =o[at_top] (pow a) := begin rw (tfae_exists_lt_is_o_pow (λ n, ‖p n‖ * r ^ n) 1).out 1 4, simp only [radius, lt_supr_iff] at h, rcases h with ⟨t, C, hC, rt⟩, rw [ennreal.coe_lt_coe, ← nnreal.coe_lt_coe] at rt, have : 0 < (t : ℝ), from r.coe_nonneg.trans_lt rt, rw [← div_lt_one this] at rt, refine ⟨_, rt, C, or.inr zero_lt_one, λ n, _⟩, calc |‖p n‖ * r ^ n| = (‖p n‖ * t ^ n) * (r / t) ^ n : by field_simp [mul_right_comm, abs_mul, this.ne'] ... ≤ C * (r / t) ^ n : mul_le_mul_of_nonneg_right (hC n) (pow_nonneg (div_nonneg r.2 t.2) _) end /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ = o(1)`. -/ lemma is_o_one_of_lt_radius (h : ↑r < p.radius) : (λ n, ‖p n‖ * r ^ n) =o[at_top] (λ _, 1 : ℕ → ℝ) := let ⟨a, ha, hp⟩ := p.is_o_of_lt_radius h in hp.trans $ (is_o_pow_pow_of_lt_left ha.1.le ha.2).congr (λ n, rfl) one_pow /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially: for some `0 < a < 1` and `C > 0`, `‖p n‖ * r ^ n ≤ C * a ^ n`. -/ lemma norm_mul_pow_le_mul_pow_of_lt_radius (h : ↑r < p.radius) : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ n, ‖p n‖ * r^n ≤ C * a^n := begin rcases ((tfae_exists_lt_is_o_pow (λ n, ‖p n‖ * r ^ n) 1).out 1 5).mp (p.is_o_of_lt_radius h) with ⟨a, ha, C, hC, H⟩, exact ⟨a, ha, C, hC, λ n, (le_abs_self _).trans (H n)⟩ end /-- If `r ≠ 0` and `‖pₙ‖ rⁿ = O(aⁿ)` for some `-1 < a < 1`, then `r < p.radius`. -/ lemma lt_radius_of_is_O (h₀ : r ≠ 0) {a : ℝ} (ha : a ∈ Ioo (-1 : ℝ) 1) (hp : (λ n, ‖p n‖ * r ^ n) =O[at_top] (pow a)) : ↑r < p.radius := begin rcases ((tfae_exists_lt_is_o_pow (λ n, ‖p n‖ * r ^ n) 1).out 2 5).mp ⟨a, ha, hp⟩ with ⟨a, ha, C, hC, hp⟩, rw [← pos_iff_ne_zero, ← nnreal.coe_pos] at h₀, lift a to ℝ≥0 using ha.1.le, have : (r : ℝ) < r / a := by simpa only [div_one] using (div_lt_div_left h₀ zero_lt_one ha.1).2 ha.2, norm_cast at this, rw [← ennreal.coe_lt_coe] at this, refine this.trans_le (p.le_radius_of_bound C $ λ n, _), rw [nnreal.coe_div, div_pow, ← mul_div_assoc, div_le_iff (pow_pos ha.1 n)], exact (le_abs_self _).trans (hp n) end /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/ lemma norm_mul_pow_le_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0} (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ * r^n ≤ C := let ⟨a, ha, C, hC, h⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h in ⟨C, hC, λ n, (h n).trans $ mul_le_of_le_one_right hC.lt.le (pow_le_one _ ha.1.le ha.2.le)⟩ /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/ lemma norm_le_div_pow_of_pos_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0} (h0 : 0 < r) (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ ≤ C / r ^ n := let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h in ⟨C, hC, λ n, iff.mpr (le_div_iff (pow_pos h0 _)) (hp n)⟩ /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/ lemma nnnorm_mul_pow_le_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0} (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖₊ * r^n ≤ C := let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h in ⟨⟨C, hC.lt.le⟩, hC, by exact_mod_cast hp⟩ lemma le_radius_of_tendsto (p : formal_multilinear_series 𝕜 E F) {l : ℝ} (h : tendsto (λ n, ‖p n‖ * r^n) at_top (𝓝 l)) : ↑r ≤ p.radius := p.le_radius_of_is_O (h.is_O_one _) lemma le_radius_of_summable_norm (p : formal_multilinear_series 𝕜 E F) (hs : summable (λ n, ‖p n‖ * r^n)) : ↑r ≤ p.radius := p.le_radius_of_tendsto hs.tendsto_at_top_zero lemma not_summable_norm_of_radius_lt_nnnorm (p : formal_multilinear_series 𝕜 E F) {x : E} (h : p.radius < ‖x‖₊) : ¬ summable (λ n, ‖p n‖ * ‖x‖^n) := λ hs, not_le_of_lt h (p.le_radius_of_summable_norm hs) lemma summable_norm_mul_pow (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0} (h : ↑r < p.radius) : summable (λ n : ℕ, ‖p n‖ * r ^ n) := begin obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, hC : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h, exact summable_of_nonneg_of_le (λ n, mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg _)) hp ((summable_geometric_of_lt_1 ha.1.le ha.2).mul_left _), end lemma summable_norm_apply (p : formal_multilinear_series 𝕜 E F) {x : E} (hx : x ∈ emetric.ball (0 : E) p.radius) : summable (λ n : ℕ, ‖p n (λ _, x)‖) := begin rw mem_emetric_ball_zero_iff at hx, refine summable_of_nonneg_of_le (λ _, norm_nonneg _) (λ n, ((p n).le_op_norm _).trans_eq _) (p.summable_norm_mul_pow hx), simp end lemma summable_nnnorm_mul_pow (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0} (h : ↑r < p.radius) : summable (λ n : ℕ, ‖p n‖₊ * r ^ n) := by { rw ← nnreal.summable_coe, push_cast, exact p.summable_norm_mul_pow h } protected lemma summable [complete_space F] (p : formal_multilinear_series 𝕜 E F) {x : E} (hx : x ∈ emetric.ball (0 : E) p.radius) : summable (λ n : ℕ, p n (λ _, x)) := summable_of_summable_norm (p.summable_norm_apply hx) lemma radius_eq_top_of_summable_norm (p : formal_multilinear_series 𝕜 E F) (hs : ∀ r : ℝ≥0, summable (λ n, ‖p n‖ * r^n)) : p.radius = ∞ := ennreal.eq_top_of_forall_nnreal_le (λ r, p.le_radius_of_summable_norm (hs r)) lemma radius_eq_top_iff_summable_norm (p : formal_multilinear_series 𝕜 E F) : p.radius = ∞ ↔ ∀ r : ℝ≥0, summable (λ n, ‖p n‖ * r^n) := begin split, { intros h r, obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, hC : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius (show (r:ℝ≥0∞) < p.radius, from h.symm ▸ ennreal.coe_lt_top), refine (summable_of_norm_bounded (λ n, (C : ℝ) * a ^ n) ((summable_geometric_of_lt_1 ha.1.le ha.2).mul_left _) (λ n, _)), specialize hp n, rwa real.norm_of_nonneg (mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg n)) }, { exact p.radius_eq_top_of_summable_norm } end /-- If the radius of `p` is positive, then `‖pₙ‖` grows at most geometrically. -/ lemma le_mul_pow_of_radius_pos (p : formal_multilinear_series 𝕜 E F) (h : 0 < p.radius) : ∃ C r (hC : 0 < C) (hr : 0 < r), ∀ n, ‖p n‖ ≤ C * r ^ n := begin rcases ennreal.lt_iff_exists_nnreal_btwn.1 h with ⟨r, r0, rlt⟩, have rpos : 0 < (r : ℝ), by simp [ennreal.coe_pos.1 r0], rcases norm_le_div_pow_of_pos_of_lt_radius p rpos rlt with ⟨C, Cpos, hCp⟩, refine ⟨C, r ⁻¹, Cpos, by simp [rpos], λ n, _⟩, convert hCp n, exact inv_pow _ _, end /-- The radius of the sum of two formal series is at least the minimum of their two radii. -/ lemma min_radius_le_radius_add (p q : formal_multilinear_series 𝕜 E F) : min p.radius q.radius ≤ (p + q).radius := begin refine ennreal.le_of_forall_nnreal_lt (λ r hr, _), rw lt_min_iff at hr, have := ((p.is_o_one_of_lt_radius hr.1).add (q.is_o_one_of_lt_radius hr.2)).is_O, refine (p + q).le_radius_of_is_O ((is_O_of_le _ $ λ n, _).trans this), rw [← add_mul, norm_mul, norm_mul, norm_norm], exact mul_le_mul_of_nonneg_right ((norm_add_le _ _).trans (le_abs_self _)) (norm_nonneg _) end @[simp] lemma radius_neg (p : formal_multilinear_series 𝕜 E F) : (-p).radius = p.radius := by simp [radius] protected lemma has_sum [complete_space F] (p : formal_multilinear_series 𝕜 E F) {x : E} (hx : x ∈ emetric.ball (0 : E) p.radius) : has_sum (λ n : ℕ, p n (λ _, x)) (p.sum x) := (p.summable hx).has_sum lemma radius_le_radius_continuous_linear_map_comp (p : formal_multilinear_series 𝕜 E F) (f : F →L[𝕜] G) : p.radius ≤ (f.comp_formal_multilinear_series p).radius := begin refine ennreal.le_of_forall_nnreal_lt (λ r hr, _), apply le_radius_of_is_O, apply (is_O.trans_is_o _ (p.is_o_one_of_lt_radius hr)).is_O, refine is_O.mul (@is_O_with.is_O _ _ _ _ _ (‖f‖) _ _ _ _) (is_O_refl _ _), apply is_O_with.of_bound (eventually_of_forall (λ n, _)), simpa only [norm_norm] using f.norm_comp_continuous_multilinear_map_le (p n) end end formal_multilinear_series /-! ### Expanding a function as a power series -/ section variables {f g : E → F} {p pf pg : formal_multilinear_series 𝕜 E F} {x : E} {r r' : ℝ≥0∞} /-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as a power series on the ball of radius `r > 0` around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `‖y‖ < r`. -/ structure has_fpower_series_on_ball (f : E → F) (p : formal_multilinear_series 𝕜 E F) (x : E) (r : ℝ≥0∞) : Prop := (r_le : r ≤ p.radius) (r_pos : 0 < r) (has_sum : ∀ {y}, y ∈ emetric.ball (0 : E) r → has_sum (λn:ℕ, p n (λ(i : fin n), y)) (f (x + y))) /-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as a power series around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `y` in a neighborhood of `0`. -/ def has_fpower_series_at (f : E → F) (p : formal_multilinear_series 𝕜 E F) (x : E) := ∃ r, has_fpower_series_on_ball f p x r variable (𝕜) /-- Given a function `f : E → F`, we say that `f` is analytic at `x` if it admits a convergent power series expansion around `x`. -/ def analytic_at (f : E → F) (x : E) := ∃ (p : formal_multilinear_series 𝕜 E F), has_fpower_series_at f p x /-- Given a function `f : E → F`, we say that `f` is analytic on a set `s` if it is analytic around every point of `s`. -/ def analytic_on (f : E → F) (s : set E) := ∀ x, x ∈ s → analytic_at 𝕜 f x variable {𝕜} lemma has_fpower_series_on_ball.has_fpower_series_at (hf : has_fpower_series_on_ball f p x r) : has_fpower_series_at f p x := ⟨r, hf⟩ lemma has_fpower_series_at.analytic_at (hf : has_fpower_series_at f p x) : analytic_at 𝕜 f x := ⟨p, hf⟩ lemma has_fpower_series_on_ball.analytic_at (hf : has_fpower_series_on_ball f p x r) : analytic_at 𝕜 f x := hf.has_fpower_series_at.analytic_at lemma has_fpower_series_on_ball.congr (hf : has_fpower_series_on_ball f p x r) (hg : eq_on f g (emetric.ball x r)) : has_fpower_series_on_ball g p x r := { r_le := hf.r_le, r_pos := hf.r_pos, has_sum := λ y hy, begin convert hf.has_sum hy, apply hg.symm, simpa [edist_eq_coe_nnnorm_sub] using hy, end } /-- If a function `f` has a power series `p` around `x`, then the function `z ↦ f (z - y)` has the same power series around `x + y`. -/ lemma has_fpower_series_on_ball.comp_sub (hf : has_fpower_series_on_ball f p x r) (y : E) : has_fpower_series_on_ball (λ z, f (z - y)) p (x + y) r := { r_le := hf.r_le, r_pos := hf.r_pos, has_sum := λ z hz, by { convert hf.has_sum hz, abel } } lemma has_fpower_series_on_ball.has_sum_sub (hf : has_fpower_series_on_ball f p x r) {y : E} (hy : y ∈ emetric.ball x r) : has_sum (λ n : ℕ, p n (λ i, y - x)) (f y) := have y - x ∈ emetric.ball (0 : E) r, by simpa [edist_eq_coe_nnnorm_sub] using hy, by simpa only [add_sub_cancel'_right] using hf.has_sum this lemma has_fpower_series_on_ball.radius_pos (hf : has_fpower_series_on_ball f p x r) : 0 < p.radius := lt_of_lt_of_le hf.r_pos hf.r_le lemma has_fpower_series_at.radius_pos (hf : has_fpower_series_at f p x) : 0 < p.radius := let ⟨r, hr⟩ := hf in hr.radius_pos lemma has_fpower_series_on_ball.mono (hf : has_fpower_series_on_ball f p x r) (r'_pos : 0 < r') (hr : r' ≤ r) : has_fpower_series_on_ball f p x r' := ⟨le_trans hr hf.1, r'_pos, λ y hy, hf.has_sum (emetric.ball_subset_ball hr hy)⟩ lemma has_fpower_series_at.congr (hf : has_fpower_series_at f p x) (hg : f =ᶠ[𝓝 x] g) : has_fpower_series_at g p x := begin rcases hf with ⟨r₁, h₁⟩, rcases emetric.mem_nhds_iff.mp hg with ⟨r₂, h₂pos, h₂⟩, exact ⟨min r₁ r₂, (h₁.mono (lt_min h₁.r_pos h₂pos) inf_le_left).congr (λ y hy, h₂ (emetric.ball_subset_ball inf_le_right hy))⟩ end protected lemma has_fpower_series_at.eventually (hf : has_fpower_series_at f p x) : ∀ᶠ r : ℝ≥0∞ in 𝓝[>] 0, has_fpower_series_on_ball f p x r := let ⟨r, hr⟩ := hf in mem_of_superset (Ioo_mem_nhds_within_Ioi (left_mem_Ico.2 hr.r_pos)) $ λ r' hr', hr.mono hr'.1 hr'.2.le lemma has_fpower_series_on_ball.eventually_has_sum (hf : has_fpower_series_on_ball f p x r) : ∀ᶠ y in 𝓝 0, has_sum (λn:ℕ, p n (λ(i : fin n), y)) (f (x + y)) := by filter_upwards [emetric.ball_mem_nhds (0 : E) hf.r_pos] using λ _, hf.has_sum lemma has_fpower_series_at.eventually_has_sum (hf : has_fpower_series_at f p x) : ∀ᶠ y in 𝓝 0, has_sum (λn:ℕ, p n (λ(i : fin n), y)) (f (x + y)) := let ⟨r, hr⟩ := hf in hr.eventually_has_sum lemma has_fpower_series_on_ball.eventually_has_sum_sub (hf : has_fpower_series_on_ball f p x r) : ∀ᶠ y in 𝓝 x, has_sum (λn:ℕ, p n (λ(i : fin n), y - x)) (f y) := by filter_upwards [emetric.ball_mem_nhds x hf.r_pos] with y using hf.has_sum_sub lemma has_fpower_series_at.eventually_has_sum_sub (hf : has_fpower_series_at f p x) : ∀ᶠ y in 𝓝 x, has_sum (λn:ℕ, p n (λ(i : fin n), y - x)) (f y) := let ⟨r, hr⟩ := hf in hr.eventually_has_sum_sub lemma has_fpower_series_on_ball.eventually_eq_zero (hf : has_fpower_series_on_ball f (0 : formal_multilinear_series 𝕜 E F) x r) : ∀ᶠ z in 𝓝 x, f z = 0 := by filter_upwards [hf.eventually_has_sum_sub] with z hz using hz.unique has_sum_zero lemma has_fpower_series_at.eventually_eq_zero (hf : has_fpower_series_at f (0 : formal_multilinear_series 𝕜 E F) x) : ∀ᶠ z in 𝓝 x, f z = 0 := let ⟨r, hr⟩ := hf in hr.eventually_eq_zero lemma has_fpower_series_on_ball_const {c : F} {e : E} : has_fpower_series_on_ball (λ _, c) (const_formal_multilinear_series 𝕜 E c) e ⊤ := begin refine ⟨by simp, with_top.zero_lt_top, λ y hy, has_sum_single 0 (λ n hn, _)⟩, simp [const_formal_multilinear_series_apply hn] end lemma has_fpower_series_at_const {c : F} {e : E} : has_fpower_series_at (λ _, c) (const_formal_multilinear_series 𝕜 E c) e := ⟨⊤, has_fpower_series_on_ball_const⟩ lemma analytic_at_const {v : F} : analytic_at 𝕜 (λ _, v) x := ⟨const_formal_multilinear_series 𝕜 E v, has_fpower_series_at_const⟩ lemma analytic_on_const {v : F} {s : set E} : analytic_on 𝕜 (λ _, v) s := λ z _, analytic_at_const lemma has_fpower_series_on_ball.add (hf : has_fpower_series_on_ball f pf x r) (hg : has_fpower_series_on_ball g pg x r) : has_fpower_series_on_ball (f + g) (pf + pg) x r := { r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg), r_pos := hf.r_pos, has_sum := λ y hy, (hf.has_sum hy).add (hg.has_sum hy) } lemma has_fpower_series_at.add (hf : has_fpower_series_at f pf x) (hg : has_fpower_series_at g pg x) : has_fpower_series_at (f + g) (pf + pg) x := begin rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩, exact ⟨r, hr.1.add hr.2⟩ end lemma analytic_at.add (hf : analytic_at 𝕜 f x) (hg : analytic_at 𝕜 g x) : analytic_at 𝕜 (f + g) x := let ⟨pf, hpf⟩ := hf, ⟨qf, hqf⟩ := hg in (hpf.add hqf).analytic_at lemma has_fpower_series_on_ball.neg (hf : has_fpower_series_on_ball f pf x r) : has_fpower_series_on_ball (-f) (-pf) x r := { r_le := by { rw pf.radius_neg, exact hf.r_le }, r_pos := hf.r_pos, has_sum := λ y hy, (hf.has_sum hy).neg } lemma has_fpower_series_at.neg (hf : has_fpower_series_at f pf x) : has_fpower_series_at (-f) (-pf) x := let ⟨rf, hrf⟩ := hf in hrf.neg.has_fpower_series_at lemma analytic_at.neg (hf : analytic_at 𝕜 f x) : analytic_at 𝕜 (-f) x := let ⟨pf, hpf⟩ := hf in hpf.neg.analytic_at lemma has_fpower_series_on_ball.sub (hf : has_fpower_series_on_ball f pf x r) (hg : has_fpower_series_on_ball g pg x r) : has_fpower_series_on_ball (f - g) (pf - pg) x r := by simpa only [sub_eq_add_neg] using hf.add hg.neg lemma has_fpower_series_at.sub (hf : has_fpower_series_at f pf x) (hg : has_fpower_series_at g pg x) : has_fpower_series_at (f - g) (pf - pg) x := by simpa only [sub_eq_add_neg] using hf.add hg.neg lemma analytic_at.sub (hf : analytic_at 𝕜 f x) (hg : analytic_at 𝕜 g x) : analytic_at 𝕜 (f - g) x := by simpa only [sub_eq_add_neg] using hf.add hg.neg lemma analytic_on.mono {s t : set E} (hf : analytic_on 𝕜 f t) (hst : s ⊆ t) : analytic_on 𝕜 f s := λ z hz, hf z (hst hz) lemma analytic_on.add {s : set E} (hf : analytic_on 𝕜 f s) (hg : analytic_on 𝕜 g s) : analytic_on 𝕜 (f + g) s := λ z hz, (hf z hz).add (hg z hz) lemma analytic_on.sub {s : set E} (hf : analytic_on 𝕜 f s) (hg : analytic_on 𝕜 g s) : analytic_on 𝕜 (f - g) s := λ z hz, (hf z hz).sub (hg z hz) lemma has_fpower_series_on_ball.coeff_zero (hf : has_fpower_series_on_ball f pf x r) (v : fin 0 → E) : pf 0 v = f x := begin have v_eq : v = (λ i, 0) := subsingleton.elim _ _, have zero_mem : (0 : E) ∈ emetric.ball (0 : E) r, by simp [hf.r_pos], have : ∀ i ≠ 0, pf i (λ j, 0) = 0, { assume i hi, have : 0 < i := pos_iff_ne_zero.2 hi, exact continuous_multilinear_map.map_coord_zero _ (⟨0, this⟩ : fin i) rfl }, have A := (hf.has_sum zero_mem).unique (has_sum_single _ this), simpa [v_eq] using A.symm, end lemma has_fpower_series_at.coeff_zero (hf : has_fpower_series_at f pf x) (v : fin 0 → E) : pf 0 v = f x := let ⟨rf, hrf⟩ := hf in hrf.coeff_zero v /-- If a function `f` has a power series `p` on a ball and `g` is linear, then `g ∘ f` has the power series `g ∘ p` on the same ball. -/ lemma _root_.continuous_linear_map.comp_has_fpower_series_on_ball (g : F →L[𝕜] G) (h : has_fpower_series_on_ball f p x r) : has_fpower_series_on_ball (g ∘ f) (g.comp_formal_multilinear_series p) x r := { r_le := h.r_le.trans (p.radius_le_radius_continuous_linear_map_comp _), r_pos := h.r_pos, has_sum := λ y hy, by simpa only [continuous_linear_map.comp_formal_multilinear_series_apply, continuous_linear_map.comp_continuous_multilinear_map_coe, function.comp_app] using g.has_sum (h.has_sum hy) } /-- If a function `f` is analytic on a set `s` and `g` is linear, then `g ∘ f` is analytic on `s`. -/ lemma _root_.continuous_linear_map.comp_analytic_on {s : set E} (g : F →L[𝕜] G) (h : analytic_on 𝕜 f s) : analytic_on 𝕜 (g ∘ f) s := begin rintros x hx, rcases h x hx with ⟨p, r, hp⟩, exact ⟨g.comp_formal_multilinear_series p, r, g.comp_has_fpower_series_on_ball hp⟩, end /-- If a function admits a power series expansion, then it is exponentially close to the partial sums of this power series on strict subdisks of the disk of convergence. This version provides an upper estimate that decreases both in `‖y‖` and `n`. See also `has_fpower_series_on_ball.uniform_geometric_approx` for a weaker version. -/ lemma has_fpower_series_on_ball.uniform_geometric_approx' {r' : ℝ≥0} (hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), (∀ y ∈ metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partial_sum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n) := begin obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ n, ‖p n‖ * r' ^n ≤ C * a^n := p.norm_mul_pow_le_mul_pow_of_lt_radius (h.trans_le hf.r_le), refine ⟨a, ha, C / (1 - a), div_pos hC (sub_pos.2 ha.2), λ y hy n, _⟩, have yr' : ‖y‖ < r', by { rw ball_zero_eq at hy, exact hy }, have hr'0 : 0 < (r' : ℝ), from (norm_nonneg _).trans_lt yr', have : y ∈ emetric.ball (0 : E) r, { refine mem_emetric_ball_zero_iff.2 (lt_trans _ h), exact_mod_cast yr' }, rw [norm_sub_rev, ← mul_div_right_comm], have ya : a * (‖y‖ / ↑r') ≤ a, from mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg), suffices : ‖p.partial_sum n y - f (x + y)‖ ≤ C * (a * (‖y‖ / r')) ^ n / (1 - a * (‖y‖ / r')), { refine this.trans _, apply_rules [div_le_div_of_le_left, sub_pos.2, div_nonneg, mul_nonneg, pow_nonneg, hC.lt.le, ha.1.le, norm_nonneg, nnreal.coe_nonneg, ha.2, (sub_le_sub_iff_left _).2]; apply_instance }, apply norm_sub_le_of_geometric_bound_of_has_sum (ya.trans_lt ha.2) _ (hf.has_sum this), assume n, calc ‖(p n) (λ (i : fin n), y)‖ ≤ ‖p n‖ * (∏ i : fin n, ‖y‖) : continuous_multilinear_map.le_op_norm _ _ ... = (‖p n‖ * r' ^ n) * (‖y‖ / r') ^ n : by field_simp [hr'0.ne', mul_right_comm] ... ≤ (C * a ^ n) * (‖y‖ / r') ^ n : mul_le_mul_of_nonneg_right (hp n) (pow_nonneg (div_nonneg (norm_nonneg _) r'.coe_nonneg) _) ... ≤ C * (a * (‖y‖ / r')) ^ n : by rw [mul_pow, mul_assoc] end /-- If a function admits a power series expansion, then it is exponentially close to the partial sums of this power series on strict subdisks of the disk of convergence. -/ lemma has_fpower_series_on_ball.uniform_geometric_approx {r' : ℝ≥0} (hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), (∀ y ∈ metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partial_sum n y‖ ≤ C * a ^ n) := begin obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), (∀ y ∈ metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partial_sum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n), from hf.uniform_geometric_approx' h, refine ⟨a, ha, C, hC, λ y hy n, (hp y hy n).trans _⟩, have yr' : ‖y‖ < r', by rwa ball_zero_eq at hy, refine mul_le_mul_of_nonneg_left (pow_le_pow_of_le_left _ _ _) hC.lt.le, exacts [mul_nonneg ha.1.le (div_nonneg (norm_nonneg y) r'.coe_nonneg), mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg)] end /-- Taylor formula for an analytic function, `is_O` version. -/ lemma has_fpower_series_at.is_O_sub_partial_sum_pow (hf : has_fpower_series_at f p x) (n : ℕ) : (λ y : E, f (x + y) - p.partial_sum n y) =O[𝓝 0] (λ y, ‖y‖ ^ n) := begin rcases hf with ⟨r, hf⟩, rcases ennreal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩, obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), (∀ y ∈ metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partial_sum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n), from hf.uniform_geometric_approx' h, refine is_O_iff.2 ⟨C * (a / r') ^ n, _⟩, replace r'0 : 0 < (r' : ℝ), by exact_mod_cast r'0, filter_upwards [metric.ball_mem_nhds (0 : E) r'0] with y hy, simpa [mul_pow, mul_div_assoc, mul_assoc, div_mul_eq_mul_div] using hp y hy n, end /-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller ball, the norm of the difference `f y - f z - p 1 (λ _, y - z)` is bounded above by `C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. This lemma formulates this property using `is_O` and `filter.principal` on `E × E`. -/ lemma has_fpower_series_on_ball.is_O_image_sub_image_sub_deriv_principal (hf : has_fpower_series_on_ball f p x r) (hr : r' < r) : (λ y : E × E, f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))) =O[𝓟 (emetric.ball (x, x) r')] (λ y, ‖y - (x, x)‖ * ‖y.1 - y.2‖) := begin lift r' to ℝ≥0 using ne_top_of_lt hr, rcases (zero_le r').eq_or_lt with rfl|hr'0, { simp only [is_O_bot, emetric.ball_zero, principal_empty, ennreal.coe_zero] }, obtain ⟨a, ha, C, hC : 0 < C, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ (n : ℕ), ‖p n‖ * ↑r' ^ n ≤ C * a ^ n, from p.norm_mul_pow_le_mul_pow_of_lt_radius (hr.trans_le hf.r_le), simp only [← le_div_iff (pow_pos (nnreal.coe_pos.2 hr'0) _)] at hp, set L : E × E → ℝ := λ y, (C * (a / r') ^ 2) * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * (a / (1 - a) ^ 2 + 2 / (1 - a)), have hL : ∀ y ∈ emetric.ball (x, x) r', ‖f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))‖ ≤ L y, { intros y hy', have hy : y ∈ emetric.ball x r ×ˢ emetric.ball x r, { rw [emetric.ball_prod_same], exact emetric.ball_subset_ball hr.le hy' }, set A : ℕ → F := λ n, p n (λ _, y.1 - x) - p n (λ _, y.2 - x), have hA : has_sum (λ n, A (n + 2)) (f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))), { convert (has_sum_nat_add_iff' 2).2 ((hf.has_sum_sub hy.1).sub (hf.has_sum_sub hy.2)) using 1, rw [finset.sum_range_succ, finset.sum_range_one, hf.coeff_zero, hf.coeff_zero, sub_self, zero_add, ← subsingleton.pi_single_eq (0 : fin 1) (y.1 - x), pi.single, ← subsingleton.pi_single_eq (0 : fin 1) (y.2 - x), pi.single, ← (p 1).map_sub, ← pi.single, subsingleton.pi_single_eq, sub_sub_sub_cancel_right] }, rw [emetric.mem_ball, edist_eq_coe_nnnorm_sub, ennreal.coe_lt_coe] at hy', set B : ℕ → ℝ := λ n, (C * (a / r') ^ 2) * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * ((n + 2) * a ^ n), have hAB : ∀ n, ‖A (n + 2)‖ ≤ B n := λ n, calc ‖A (n + 2)‖ ≤ ‖p (n + 2)‖ * ↑(n + 2) * ‖y - (x, x)‖ ^ (n + 1) * ‖y.1 - y.2‖ : by simpa only [fintype.card_fin, pi_norm_const (_ : E), prod.norm_def, pi.sub_def, prod.fst_sub, prod.snd_sub, sub_sub_sub_cancel_right] using (p $ n + 2).norm_image_sub_le (λ _, y.1 - x) (λ _, y.2 - x) ... = ‖p (n + 2)‖ * ‖y - (x, x)‖ ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) : by { rw [pow_succ ‖y - (x, x)‖], ring } ... ≤ (C * a ^ (n + 2) / r' ^ (n + 2)) * r' ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) : by apply_rules [mul_le_mul_of_nonneg_right, mul_le_mul, hp, pow_le_pow_of_le_left, hy'.le, norm_nonneg, pow_nonneg, div_nonneg, mul_nonneg, nat.cast_nonneg, hC.le, r'.coe_nonneg, ha.1.le] ... = B n : by { field_simp [B, pow_succ, hr'0.ne'], simp only [mul_assoc, mul_comm, mul_left_comm] }, have hBL : has_sum B (L y), { apply has_sum.mul_left, simp only [add_mul], have : ‖a‖ < 1, by simp only [real.norm_eq_abs, abs_of_pos ha.1, ha.2], convert (has_sum_coe_mul_geometric_of_norm_lt_1 this).add ((has_sum_geometric_of_norm_lt_1 this).mul_left 2) }, exact hA.norm_le_of_bounded hBL hAB }, suffices : L =O[𝓟 (emetric.ball (x, x) r')] (λ y, ‖y - (x, x)‖ * ‖y.1 - y.2‖), { refine (is_O.of_bound 1 (eventually_principal.2 $ λ y hy, _)).trans this, rw one_mul, exact (hL y hy).trans (le_abs_self _) }, simp_rw [L, mul_right_comm _ (_ * _)], exact (is_O_refl _ _).const_mul_left _, end /-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller ball, the norm of the difference `f y - f z - p 1 (λ _, y - z)` is bounded above by `C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. -/ lemma has_fpower_series_on_ball.image_sub_sub_deriv_le (hf : has_fpower_series_on_ball f p x r) (hr : r' < r) : ∃ C, ∀ (y z ∈ emetric.ball x r'), ‖f y - f z - (p 1 (λ _, y - z))‖ ≤ C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖ := by simpa only [is_O_principal, mul_assoc, norm_mul, norm_norm, prod.forall, emetric.mem_ball, prod.edist_eq, max_lt_iff, and_imp, @forall_swap (_ < _) E] using hf.is_O_image_sub_image_sub_deriv_principal hr /-- If `f` has formal power series `∑ n, pₙ` at `x`, then `f y - f z - p 1 (λ _, y - z) = O(‖(y, z) - (x, x)‖ * ‖y - z‖)` as `(y, z) → (x, x)`. In particular, `f` is strictly differentiable at `x`. -/ lemma has_fpower_series_at.is_O_image_sub_norm_mul_norm_sub (hf : has_fpower_series_at f p x) : (λ y : E × E, f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))) =O[𝓝 (x, x)] (λ y, ‖y - (x, x)‖ * ‖y.1 - y.2‖) := begin rcases hf with ⟨r, hf⟩, rcases ennreal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩, refine (hf.is_O_image_sub_image_sub_deriv_principal h).mono _, exact le_principal_iff.2 (emetric.ball_mem_nhds _ r'0) end /-- If a function admits a power series expansion at `x`, then it is the uniform limit of the partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f (x + y)` is the uniform limit of `p.partial_sum n y` there. -/ lemma has_fpower_series_on_ball.tendsto_uniformly_on {r' : ℝ≥0} (hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) : tendsto_uniformly_on (λ n y, p.partial_sum n y) (λ y, f (x + y)) at_top (metric.ball (0 : E) r') := begin obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), (∀ y ∈ metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partial_sum n y‖ ≤ C * a ^ n), from hf.uniform_geometric_approx h, refine metric.tendsto_uniformly_on_iff.2 (λ ε εpos, _), have L : tendsto (λ n, (C : ℝ) * a^n) at_top (𝓝 ((C : ℝ) * 0)) := tendsto_const_nhds.mul (tendsto_pow_at_top_nhds_0_of_lt_1 ha.1.le ha.2), rw mul_zero at L, refine (L.eventually (gt_mem_nhds εpos)).mono (λ n hn y hy, _), rw dist_eq_norm, exact (hp y hy n).trans_lt hn end /-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of the partial sums of this power series on the disk of convergence, i.e., `f (x + y)` is the locally uniform limit of `p.partial_sum n y` there. -/ lemma has_fpower_series_on_ball.tendsto_locally_uniformly_on (hf : has_fpower_series_on_ball f p x r) : tendsto_locally_uniformly_on (λ n y, p.partial_sum n y) (λ y, f (x + y)) at_top (emetric.ball (0 : E) r) := begin assume u hu x hx, rcases ennreal.lt_iff_exists_nnreal_btwn.1 hx with ⟨r', xr', hr'⟩, have : emetric.ball (0 : E) r' ∈ 𝓝 x := is_open.mem_nhds emetric.is_open_ball xr', refine ⟨emetric.ball (0 : E) r', mem_nhds_within_of_mem_nhds this, _⟩, simpa [metric.emetric_ball_nnreal] using hf.tendsto_uniformly_on hr' u hu end /-- If a function admits a power series expansion at `x`, then it is the uniform limit of the partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f y` is the uniform limit of `p.partial_sum n (y - x)` there. -/ lemma has_fpower_series_on_ball.tendsto_uniformly_on' {r' : ℝ≥0} (hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) : tendsto_uniformly_on (λ n y, p.partial_sum n (y - x)) f at_top (metric.ball (x : E) r') := begin convert (hf.tendsto_uniformly_on h).comp (λ y, y - x), { simp [(∘)] }, { ext z, simp [dist_eq_norm] } end /-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of the partial sums of this power series on the disk of convergence, i.e., `f y` is the locally uniform limit of `p.partial_sum n (y - x)` there. -/ lemma has_fpower_series_on_ball.tendsto_locally_uniformly_on' (hf : has_fpower_series_on_ball f p x r) : tendsto_locally_uniformly_on (λ n y, p.partial_sum n (y - x)) f at_top (emetric.ball (x : E) r) := begin have A : continuous_on (λ (y : E), y - x) (emetric.ball (x : E) r) := (continuous_id.sub continuous_const).continuous_on, convert (hf.tendsto_locally_uniformly_on).comp (λ (y : E), y - x) _ A, { ext z, simp }, { assume z, simp [edist_eq_coe_nnnorm, edist_eq_coe_nnnorm_sub] } end /-- If a function admits a power series expansion on a disk, then it is continuous there. -/ protected lemma has_fpower_series_on_ball.continuous_on (hf : has_fpower_series_on_ball f p x r) : continuous_on f (emetric.ball x r) := hf.tendsto_locally_uniformly_on'.continuous_on $ eventually_of_forall $ λ n, ((p.partial_sum_continuous n).comp (continuous_id.sub continuous_const)).continuous_on protected lemma has_fpower_series_at.continuous_at (hf : has_fpower_series_at f p x) : continuous_at f x := let ⟨r, hr⟩ := hf in hr.continuous_on.continuous_at (emetric.ball_mem_nhds x (hr.r_pos)) protected lemma analytic_at.continuous_at (hf : analytic_at 𝕜 f x) : continuous_at f x := let ⟨p, hp⟩ := hf in hp.continuous_at protected lemma analytic_on.continuous_on {s : set E} (hf : analytic_on 𝕜 f s) : continuous_on f s := λ x hx, (hf x hx).continuous_at.continuous_within_at /-- In a complete space, the sum of a converging power series `p` admits `p` as a power series. This is not totally obvious as we need to check the convergence of the series. -/ protected lemma formal_multilinear_series.has_fpower_series_on_ball [complete_space F] (p : formal_multilinear_series 𝕜 E F) (h : 0 < p.radius) : has_fpower_series_on_ball p.sum p 0 p.radius := { r_le := le_rfl, r_pos := h, has_sum := λ y hy, by { rw zero_add, exact p.has_sum hy } } lemma has_fpower_series_on_ball.sum (h : has_fpower_series_on_ball f p x r) {y : E} (hy : y ∈ emetric.ball (0 : E) r) : f (x + y) = p.sum y := (h.has_sum hy).tsum_eq.symm /-- The sum of a converging power series is continuous in its disk of convergence. -/ protected lemma formal_multilinear_series.continuous_on [complete_space F] : continuous_on p.sum (emetric.ball 0 p.radius) := begin cases (zero_le p.radius).eq_or_lt with h h, { simp [← h, continuous_on_empty] }, { exact (p.has_fpower_series_on_ball h).continuous_on } end end /-! ### Uniqueness of power series If a function `f : E → F` has two representations as power series at a point `x : E`, corresponding to formal multilinear series `p₁` and `p₂`, then these representations agree term-by-term. That is, for any `n : ℕ` and `y : E`, `p₁ n (λ i, y) = p₂ n (λ i, y)`. In the one-dimensional case, when `f : 𝕜 → E`, the continuous multilinear maps `p₁ n` and `p₂ n` are given by `formal_multilinear_series.mk_pi_field`, and hence are determined completely by the value of `p₁ n (λ i, 1)`, so `p₁ = p₂`. Consequently, the radius of convergence for one series can be transferred to the other. -/ section uniqueness open continuous_multilinear_map lemma asymptotics.is_O.continuous_multilinear_map_apply_eq_zero {n : ℕ} {p : E [×n]→L[𝕜] F} (h : (λ y, p (λ i, y)) =O[𝓝 0] (λ y, ‖y‖ ^ (n + 1))) (y : E) : p (λ i, y) = 0 := begin obtain ⟨c, c_pos, hc⟩ := h.exists_pos, obtain ⟨t, ht, t_open, z_mem⟩ := eventually_nhds_iff.mp (is_O_with_iff.mp hc), obtain ⟨δ, δ_pos, δε⟩ := (metric.is_open_iff.mp t_open) 0 z_mem, clear h hc z_mem, cases n, { exact norm_eq_zero.mp (by simpa only [fin0_apply_norm, norm_eq_zero, norm_zero, zero_pow', ne.def, nat.one_ne_zero, not_false_iff, mul_zero, norm_le_zero_iff] using ht 0 (δε (metric.mem_ball_self δ_pos))), }, { refine or.elim (em (y = 0)) (λ hy, by simpa only [hy] using p.map_zero) (λ hy, _), replace hy := norm_pos_iff.mpr hy, refine norm_eq_zero.mp (le_antisymm (le_of_forall_pos_le_add (λ ε ε_pos, _)) (norm_nonneg _)), have h₀ := mul_pos c_pos (pow_pos hy (n.succ + 1)), obtain ⟨k, k_pos, k_norm⟩ := normed_field.exists_norm_lt 𝕜 (lt_min (mul_pos δ_pos (inv_pos.mpr hy)) (mul_pos ε_pos (inv_pos.mpr h₀))), have h₁ : ‖k • y‖ < δ, { rw norm_smul, exact inv_mul_cancel_right₀ hy.ne.symm δ ▸ mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_left _ _)) hy }, have h₂ := calc ‖p (λ i, k • y)‖ ≤ c * ‖k • y‖ ^ (n.succ + 1) : by simpa only [norm_pow, norm_norm] using ht (k • y) (δε (mem_ball_zero_iff.mpr h₁)) ... = ‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))) : by { simp only [norm_smul, mul_pow], rw pow_succ, ring }, have h₃ : ‖k‖ * (c * ‖y‖ ^ (n.succ + 1)) < ε, from inv_mul_cancel_right₀ h₀.ne.symm ε ▸ mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_right _ _)) h₀, calc ‖p (λ i, y)‖ = ‖(k⁻¹) ^ n.succ‖ * ‖p (λ i, k • y)‖ : by simpa only [inv_smul_smul₀ (norm_pos_iff.mp k_pos), norm_smul, finset.prod_const, finset.card_fin] using congr_arg norm (p.map_smul_univ (λ (i : fin n.succ), k⁻¹) (λ (i : fin n.succ), k • y)) ... ≤ ‖(k⁻¹) ^ n.succ‖ * (‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1)))) : mul_le_mul_of_nonneg_left h₂ (norm_nonneg _) ... = ‖(k⁻¹ * k) ^ n.succ‖ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))) : by { rw ←mul_assoc, simp [norm_mul, mul_pow] } ... ≤ 0 + ε : by { rw inv_mul_cancel (norm_pos_iff.mp k_pos), simpa using h₃.le }, }, end /-- If a formal multilinear series `p` represents the zero function at `x : E`, then the terms `p n (λ i, y)` appearing the in sum are zero for any `n : ℕ`, `y : E`. -/ lemma has_fpower_series_at.apply_eq_zero {p : formal_multilinear_series 𝕜 E F} {x : E} (h : has_fpower_series_at 0 p x) (n : ℕ) : ∀ y : E, p n (λ i, y) = 0 := begin refine nat.strong_rec_on n (λ k hk, _), have psum_eq : p.partial_sum (k + 1) = (λ y, p k (λ i, y)), { funext z, refine finset.sum_eq_single _ (λ b hb hnb, _) (λ hn, _), { have := finset.mem_range_succ_iff.mp hb, simp only [hk b (this.lt_of_ne hnb), pi.zero_apply, zero_apply] }, { exact false.elim (hn (finset.mem_range.mpr (lt_add_one k))) } }, replace h := h.is_O_sub_partial_sum_pow k.succ, simp only [psum_eq, zero_sub, pi.zero_apply, asymptotics.is_O_neg_left] at h, exact h.continuous_multilinear_map_apply_eq_zero, end /-- A one-dimensional formal multilinear series representing the zero function is zero. -/ lemma has_fpower_series_at.eq_zero {p : formal_multilinear_series 𝕜 𝕜 E} {x : 𝕜} (h : has_fpower_series_at 0 p x) : p = 0 := by { ext n x, rw ←mk_pi_field_apply_one_eq_self (p n), simp [h.apply_eq_zero n 1] } /-- One-dimensional formal multilinear series representing the same function are equal. -/ theorem has_fpower_series_at.eq_formal_multilinear_series {p₁ p₂ : formal_multilinear_series 𝕜 𝕜 E} {f : 𝕜 → E} {x : 𝕜} (h₁ : has_fpower_series_at f p₁ x) (h₂ : has_fpower_series_at f p₂ x) : p₁ = p₂ := sub_eq_zero.mp (has_fpower_series_at.eq_zero (by simpa only [sub_self] using h₁.sub h₂)) lemma has_fpower_series_at.eq_formal_multilinear_series_of_eventually {p q : formal_multilinear_series 𝕜 𝕜 E} {f g : 𝕜 → E} {x : 𝕜} (hp : has_fpower_series_at f p x) (hq : has_fpower_series_at g q x) (heq : ∀ᶠ z in 𝓝 x, f z = g z) : p = q := (hp.congr heq).eq_formal_multilinear_series hq /-- A one-dimensional formal multilinear series representing a locally zero function is zero. -/ lemma has_fpower_series_at.eq_zero_of_eventually {p : formal_multilinear_series 𝕜 𝕜 E} {f : 𝕜 → E} {x : 𝕜} (hp : has_fpower_series_at f p x) (hf : f =ᶠ[𝓝 x] 0) : p = 0 := (hp.congr hf).eq_zero /-- If a function `f : 𝕜 → E` has two power series representations at `x`, then the given radii in which convergence is guaranteed may be interchanged. This can be useful when the formal multilinear series in one representation has a particularly nice form, but the other has a larger radius. -/ theorem has_fpower_series_on_ball.exchange_radius {p₁ p₂ : formal_multilinear_series 𝕜 𝕜 E} {f : 𝕜 → E} {r₁ r₂ : ℝ≥0∞} {x : 𝕜} (h₁ : has_fpower_series_on_ball f p₁ x r₁) (h₂ : has_fpower_series_on_ball f p₂ x r₂) : has_fpower_series_on_ball f p₁ x r₂ := h₂.has_fpower_series_at.eq_formal_multilinear_series h₁.has_fpower_series_at ▸ h₂ /-- If a function `f : 𝕜 → E` has power series representation `p` on a ball of some radius and for each positive radius it has some power series representation, then `p` converges to `f` on the whole `𝕜`. -/ theorem has_fpower_series_on_ball.r_eq_top_of_exists {f : 𝕜 → E} {r : ℝ≥0∞} {x : 𝕜} {p : formal_multilinear_series 𝕜 𝕜 E} (h : has_fpower_series_on_ball f p x r) (h' : ∀ (r' : ℝ≥0) (hr : 0 < r'), ∃ p' : formal_multilinear_series 𝕜 𝕜 E, has_fpower_series_on_ball f p' x r') : has_fpower_series_on_ball f p x ∞ := { r_le := ennreal.le_of_forall_pos_nnreal_lt $ λ r hr hr', let ⟨p', hp'⟩ := h' r hr in (h.exchange_radius hp').r_le, r_pos := ennreal.coe_lt_top, has_sum := λ y hy, let ⟨r', hr'⟩ := exists_gt ‖y‖₊, ⟨p', hp'⟩ := h' r' hr'.ne_bot.bot_lt in (h.exchange_radius hp').has_sum $ mem_emetric_ball_zero_iff.mpr (ennreal.coe_lt_coe.2 hr') } end uniqueness /-! ### Changing origin in a power series If a function is analytic in a disk `D(x, R)`, then it is analytic in any disk contained in that one. Indeed, one can write $$ f (x + y + z) = \sum_{n} p_n (y + z)^n = \sum_{n, k} \binom{n}{k} p_n y^{n-k} z^k = \sum_{k} \Bigl(\sum_{n} \binom{n}{k} p_n y^{n-k}\Bigr) z^k. $$ The corresponding power series has thus a `k`-th coefficient equal to $\sum_{n} \binom{n}{k} p_n y^{n-k}$. In the general case where `pₙ` is a multilinear map, this has to be interpreted suitably: instead of having a binomial coefficient, one should sum over all possible subsets `s` of `fin n` of cardinal `k`, and attribute `z` to the indices in `s` and `y` to the indices outside of `s`. In this paragraph, we implement this. The new power series is called `p.change_origin y`. Then, we check its convergence and the fact that its sum coincides with the original sum. The outcome of this discussion is that the set of points where a function is analytic is open. -/ namespace formal_multilinear_series section variables (p : formal_multilinear_series 𝕜 E F) {x y : E} {r R : ℝ≥0} /-- A term of `formal_multilinear_series.change_origin_series`. Given a formal multilinear series `p` and a point `x` in its ball of convergence, `p.change_origin x` is a formal multilinear series such that `p.sum (x+y) = (p.change_origin x).sum y` when this makes sense. Each term of `p.change_origin x` is itself an analytic function of `x` given by the series `p.change_origin_series`. Each term in `change_origin_series` is the sum of `change_origin_series_term`'s over all `s` of cardinality `l`. The definition is such that `p.change_origin_series_term k l s hs (λ _, x) (λ _, y) = p (k + l) (s.piecewise (λ _, x) (λ _, y))` -/ def change_origin_series_term (k l : ℕ) (s : finset (fin (k + l))) (hs : s.card = l) : E [×l]→L[𝕜] E [×k]→L[𝕜] F := continuous_multilinear_map.curry_fin_finset 𝕜 E F hs (by erw [finset.card_compl, fintype.card_fin, hs, add_tsub_cancel_right]) (p $ k + l) lemma change_origin_series_term_apply (k l : ℕ) (s : finset (fin (k + l))) (hs : s.card = l) (x y : E) : p.change_origin_series_term k l s hs (λ _, x) (λ _, y) = p (k + l) (s.piecewise (λ _, x) (λ _, y)) := continuous_multilinear_map.curry_fin_finset_apply_const _ _ _ _ _ @[simp] lemma norm_change_origin_series_term (k l : ℕ) (s : finset (fin (k + l))) (hs : s.card = l) : ‖p.change_origin_series_term k l s hs‖ = ‖p (k + l)‖ := by simp only [change_origin_series_term, linear_isometry_equiv.norm_map] @[simp] lemma nnnorm_change_origin_series_term (k l : ℕ) (s : finset (fin (k + l))) (hs : s.card = l) : ‖p.change_origin_series_term k l s hs‖₊ = ‖p (k + l)‖₊ := by simp only [change_origin_series_term, linear_isometry_equiv.nnnorm_map] lemma nnnorm_change_origin_series_term_apply_le (k l : ℕ) (s : finset (fin (k + l))) (hs : s.card = l) (x y : E) : ‖p.change_origin_series_term k l s hs (λ _, x) (λ _, y)‖₊ ≤ ‖p (k + l)‖₊ * ‖x‖₊ ^ l * ‖y‖₊ ^ k := begin rw [← p.nnnorm_change_origin_series_term k l s hs, ← fin.prod_const, ← fin.prod_const], apply continuous_multilinear_map.le_of_op_nnnorm_le, apply continuous_multilinear_map.le_op_nnnorm end /-- The power series for `f.change_origin k`. Given a formal multilinear series `p` and a point `x` in its ball of convergence, `p.change_origin x` is a formal multilinear series such that `p.sum (x+y) = (p.change_origin x).sum y` when this makes sense. Its `k`-th term is the sum of the series `p.change_origin_series k`. -/ def change_origin_series (k : ℕ) : formal_multilinear_series 𝕜 E (E [×k]→L[𝕜] F) := λ l, ∑ s : {s : finset (fin (k + l)) // finset.card s = l}, p.change_origin_series_term k l s s.2 lemma nnnorm_change_origin_series_le_tsum (k l : ℕ) : ‖p.change_origin_series k l‖₊ ≤ ∑' (x : {s : finset (fin (k + l)) // s.card = l}), ‖p (k + l)‖₊ := (nnnorm_sum_le _ _).trans_eq $ by simp only [tsum_fintype, nnnorm_change_origin_series_term] lemma nnnorm_change_origin_series_apply_le_tsum (k l : ℕ) (x : E) : ‖p.change_origin_series k l (λ _, x)‖₊ ≤ ∑' s : {s : finset (fin (k + l)) // s.card = l}, ‖p (k + l)‖₊ * ‖x‖₊ ^ l := begin rw [nnreal.tsum_mul_right, ← fin.prod_const], exact (p.change_origin_series k l).le_of_op_nnnorm_le _ (p.nnnorm_change_origin_series_le_tsum _ _) end /-- Changing the origin of a formal multilinear series `p`, so that `p.sum (x+y) = (p.change_origin x).sum y` when this makes sense. -/ def change_origin (x : E) : formal_multilinear_series 𝕜 E F := λ k, (p.change_origin_series k).sum x /-- An auxiliary equivalence useful in the proofs about `formal_multilinear_series.change_origin_series`: the set of triples `(k, l, s)`, where `s` is a `finset (fin (k + l))` of cardinality `l` is equivalent to the set of pairs `(n, s)`, where `s` is a `finset (fin n)`. The forward map sends `(k, l, s)` to `(k + l, s)` and the inverse map sends `(n, s)` to `(n - finset.card s, finset.card s, s)`. The actual definition is less readable because of problems with non-definitional equalities. -/ @[simps] def change_origin_index_equiv : (Σ k l : ℕ, {s : finset (fin (k + l)) // s.card = l}) ≃ Σ n : ℕ, finset (fin n) := { to_fun := λ s, ⟨s.1 + s.2.1, s.2.2⟩, inv_fun := λ s, ⟨s.1 - s.2.card, s.2.card, ⟨s.2.map (fin.cast $ (tsub_add_cancel_of_le $ card_finset_fin_le s.2).symm).to_equiv.to_embedding, finset.card_map _⟩⟩, left_inv := begin rintro ⟨k, l, ⟨s : finset (fin $ k + l), hs : s.card = l⟩⟩, dsimp only [subtype.coe_mk], -- Lean can't automatically generalize `k' = k + l - s.card`, `l' = s.card`, so we explicitly -- formulate the generalized goal suffices : ∀ k' l', k' = k → l' = l → ∀ (hkl : k + l = k' + l') hs', (⟨k', l', ⟨finset.map (fin.cast hkl).to_equiv.to_embedding s, hs'⟩⟩ : (Σ k l : ℕ, {s : finset (fin (k + l)) // s.card = l})) = ⟨k, l, ⟨s, hs⟩⟩, { apply this; simp only [hs, add_tsub_cancel_right] }, rintro _ _ rfl rfl hkl hs', simp only [equiv.refl_to_embedding, fin.cast_refl, finset.map_refl, eq_self_iff_true, order_iso.refl_to_equiv, and_self, heq_iff_eq] end, right_inv := begin rintro ⟨n, s⟩, simp [tsub_add_cancel_of_le (card_finset_fin_le s), fin.cast_to_equiv] end } lemma change_origin_series_summable_aux₁ {r r' : ℝ≥0} (hr : (r + r' : ℝ≥0∞) < p.radius) : summable (λ s : Σ k l : ℕ, {s : finset (fin (k + l)) // s.card = l}, ‖p (s.1 + s.2.1)‖₊ * r ^ s.2.1 * r' ^ s.1) := begin rw ← change_origin_index_equiv.symm.summable_iff, dsimp only [(∘), change_origin_index_equiv_symm_apply_fst, change_origin_index_equiv_symm_apply_snd_fst], have : ∀ n : ℕ, has_sum (λ s : finset (fin n), ‖p (n - s.card + s.card)‖₊ * r ^ s.card * r' ^ (n - s.card)) (‖p n‖₊ * (r + r') ^ n), { intro n, -- TODO: why `simp only [tsub_add_cancel_of_le (card_finset_fin_le _)]` fails? convert_to has_sum (λ s : finset (fin n), ‖p n‖₊ * (r ^ s.card * r' ^ (n - s.card))) _, { ext1 s, rw [tsub_add_cancel_of_le (card_finset_fin_le _), mul_assoc] }, rw ← fin.sum_pow_mul_eq_add_pow, exact (has_sum_fintype _).mul_left _ }, refine nnreal.summable_sigma.2 ⟨λ n, (this n).summable, _⟩, simp only [(this _).tsum_eq], exact p.summable_nnnorm_mul_pow hr end lemma change_origin_series_summable_aux₂ (hr : (r : ℝ≥0∞) < p.radius) (k : ℕ) : summable (λ s : Σ l : ℕ, {s : finset (fin (k + l)) // s.card = l}, ‖p (k + s.1)‖₊ * r ^ s.1) := begin rcases ennreal.lt_iff_exists_add_pos_lt.1 hr with ⟨r', h0, hr'⟩, simpa only [mul_inv_cancel_right₀ (pow_pos h0 _).ne'] using ((nnreal.summable_sigma.1 (p.change_origin_series_summable_aux₁ hr')).1 k).mul_right (r' ^ k)⁻¹ end lemma change_origin_series_summable_aux₃ {r : ℝ≥0} (hr : ↑r < p.radius) (k : ℕ) : summable (λ l : ℕ, ‖p.change_origin_series k l‖₊ * r ^ l) := begin refine nnreal.summable_of_le (λ n, _) (nnreal.summable_sigma.1 $ p.change_origin_series_summable_aux₂ hr k).2, simp only [nnreal.tsum_mul_right], exact mul_le_mul' (p.nnnorm_change_origin_series_le_tsum _ _) le_rfl end lemma le_change_origin_series_radius (k : ℕ) : p.radius ≤ (p.change_origin_series k).radius := ennreal.le_of_forall_nnreal_lt $ λ r hr, le_radius_of_summable_nnnorm _ (p.change_origin_series_summable_aux₃ hr k) lemma nnnorm_change_origin_le (k : ℕ) (h : (‖x‖₊ : ℝ≥0∞) < p.radius) : ‖p.change_origin x k‖₊ ≤ ∑' s : Σ l : ℕ, {s : finset (fin (k + l)) // s.card = l}, ‖p (k + s.1)‖₊ * ‖x‖₊ ^ s.1 := begin refine tsum_of_nnnorm_bounded _ (λ l, p.nnnorm_change_origin_series_apply_le_tsum k l x), have := p.change_origin_series_summable_aux₂ h k, refine has_sum.sigma this.has_sum (λ l, _), exact ((nnreal.summable_sigma.1 this).1 l).has_sum end /-- The radius of convergence of `p.change_origin x` is at least `p.radius - ‖x‖`. In other words, `p.change_origin x` is well defined on the largest ball contained in the original ball of convergence.-/ lemma change_origin_radius : p.radius - ‖x‖₊ ≤ (p.change_origin x).radius := begin refine ennreal.le_of_forall_pos_nnreal_lt (λ r h0 hr, _), rw [lt_tsub_iff_right, add_comm] at hr, have hr' : (‖x‖₊ : ℝ≥0∞) < p.radius, from (le_add_right le_rfl).trans_lt hr, apply le_radius_of_summable_nnnorm, have : ∀ k : ℕ, ‖p.change_origin x k‖₊ * r ^ k ≤ (∑' s : Σ l : ℕ, {s : finset (fin (k + l)) // s.card = l}, ‖p (k + s.1)‖₊ * ‖x‖₊ ^ s.1) * r ^ k, from λ k, mul_le_mul_right' (p.nnnorm_change_origin_le k hr') (r ^ k), refine nnreal.summable_of_le this _, simpa only [← nnreal.tsum_mul_right] using (nnreal.summable_sigma.1 (p.change_origin_series_summable_aux₁ hr)).2 end end -- From this point on, assume that the space is complete, to make sure that series that converge -- in norm also converge in `F`. variables [complete_space F] (p : formal_multilinear_series 𝕜 E F) {x y : E} {r R : ℝ≥0} lemma has_fpower_series_on_ball_change_origin (k : ℕ) (hr : 0 < p.radius) : has_fpower_series_on_ball (λ x, p.change_origin x k) (p.change_origin_series k) 0 p.radius := have _ := p.le_change_origin_series_radius k, ((p.change_origin_series k).has_fpower_series_on_ball (hr.trans_le this)).mono hr this /-- Summing the series `p.change_origin x` at a point `y` gives back `p (x + y)`-/ theorem change_origin_eval (h : (‖x‖₊ + ‖y‖₊ : ℝ≥0∞) < p.radius) : (p.change_origin x).sum y = (p.sum (x + y)) := begin have radius_pos : 0 < p.radius := lt_of_le_of_lt (zero_le _) h, have x_mem_ball : x ∈ emetric.ball (0 : E) p.radius, from mem_emetric_ball_zero_iff.2 ((le_add_right le_rfl).trans_lt h), have y_mem_ball : y ∈ emetric.ball (0 : E) (p.change_origin x).radius, { refine mem_emetric_ball_zero_iff.2 (lt_of_lt_of_le _ p.change_origin_radius), rwa [lt_tsub_iff_right, add_comm] }, have x_add_y_mem_ball : x + y ∈ emetric.ball (0 : E) p.radius, { refine mem_emetric_ball_zero_iff.2 (lt_of_le_of_lt _ h), exact_mod_cast nnnorm_add_le x y }, set f : (Σ (k l : ℕ), {s : finset (fin (k + l)) // s.card = l}) → F := λ s, p.change_origin_series_term s.1 s.2.1 s.2.2 s.2.2.2 (λ _, x) (λ _, y), have hsf : summable f, { refine summable_of_nnnorm_bounded _ (p.change_origin_series_summable_aux₁ h) _, rintro ⟨k, l, s, hs⟩, dsimp only [subtype.coe_mk], exact p.nnnorm_change_origin_series_term_apply_le _ _ _ _ _ _ }, have hf : has_sum f ((p.change_origin x).sum y), { refine has_sum.sigma_of_has_sum ((p.change_origin x).summable y_mem_ball).has_sum (λ k, _) hsf, { dsimp only [f], refine continuous_multilinear_map.has_sum_eval _ _, have := (p.has_fpower_series_on_ball_change_origin k radius_pos).has_sum x_mem_ball, rw zero_add at this, refine has_sum.sigma_of_has_sum this (λ l, _) _, { simp only [change_origin_series, continuous_multilinear_map.sum_apply], apply has_sum_fintype }, { refine summable_of_nnnorm_bounded _ (p.change_origin_series_summable_aux₂ (mem_emetric_ball_zero_iff.1 x_mem_ball) k) (λ s, _), refine (continuous_multilinear_map.le_op_nnnorm _ _).trans_eq _, simp } } }, refine hf.unique (change_origin_index_equiv.symm.has_sum_iff.1 _), refine has_sum.sigma_of_has_sum (p.has_sum x_add_y_mem_ball) (λ n, _) (change_origin_index_equiv.symm.summable_iff.2 hsf), erw [(p n).map_add_univ (λ _, x) (λ _, y)], convert has_sum_fintype _, ext1 s, dsimp only [f, change_origin_series_term, (∘), change_origin_index_equiv_symm_apply_fst, change_origin_index_equiv_symm_apply_snd_fst, change_origin_index_equiv_symm_apply_snd_snd_coe], rw continuous_multilinear_map.curry_fin_finset_apply_const, have : ∀ m (hm : n = m), p n (s.piecewise (λ _, x) (λ _, y)) = p m ((s.map (fin.cast hm).to_equiv.to_embedding).piecewise (λ _, x) (λ _, y)), { rintro m rfl, simp }, apply this end end formal_multilinear_series section variables [complete_space F] {f : E → F} {p : formal_multilinear_series 𝕜 E F} {x y : E} {r : ℝ≥0∞} /-- If a function admits a power series expansion `p` on a ball `B (x, r)`, then it also admits a power series on any subball of this ball (even with a different center), given by `p.change_origin`. -/ theorem has_fpower_series_on_ball.change_origin (hf : has_fpower_series_on_ball f p x r) (h : (‖y‖₊ : ℝ≥0∞) < r) : has_fpower_series_on_ball f (p.change_origin y) (x + y) (r - ‖y‖₊) := { r_le := begin apply le_trans _ p.change_origin_radius, exact tsub_le_tsub hf.r_le le_rfl end, r_pos := by simp [h], has_sum := λ z hz, begin convert (p.change_origin y).has_sum _, { rw [mem_emetric_ball_zero_iff, lt_tsub_iff_right, add_comm] at hz, rw [p.change_origin_eval (hz.trans_le hf.r_le), add_assoc, hf.sum], refine mem_emetric_ball_zero_iff.2 (lt_of_le_of_lt _ hz), exact_mod_cast nnnorm_add_le y z }, { refine emetric.ball_subset_ball (le_trans _ p.change_origin_radius) hz, exact tsub_le_tsub hf.r_le le_rfl } end } /-- If a function admits a power series expansion `p` on an open ball `B (x, r)`, then it is analytic at every point of this ball. -/ lemma has_fpower_series_on_ball.analytic_at_of_mem (hf : has_fpower_series_on_ball f p x r) (h : y ∈ emetric.ball x r) : analytic_at 𝕜 f y := begin have : (‖y - x‖₊ : ℝ≥0∞) < r, by simpa [edist_eq_coe_nnnorm_sub] using h, have := hf.change_origin this, rw [add_sub_cancel'_right] at this, exact this.analytic_at end lemma has_fpower_series_on_ball.analytic_on (hf : has_fpower_series_on_ball f p x r) : analytic_on 𝕜 f (emetric.ball x r) := λ y hy, hf.analytic_at_of_mem hy variables (𝕜 f) /-- For any function `f` from a normed vector space to a Banach space, the set of points `x` such that `f` is analytic at `x` is open. -/ lemma is_open_analytic_at : is_open {x | analytic_at 𝕜 f x} := begin rw is_open_iff_mem_nhds, rintro x ⟨p, r, hr⟩, exact mem_of_superset (emetric.ball_mem_nhds _ hr.r_pos) (λ y hy, hr.analytic_at_of_mem hy) end end section open formal_multilinear_series variables {p : formal_multilinear_series 𝕜 𝕜 E} {f : 𝕜 → E} {z₀ : 𝕜} /-- A function `f : 𝕜 → E` has `p` as power series expansion at a point `z₀` iff it is the sum of `p` in a neighborhood of `z₀`. This makes some proofs easier by hiding the fact that `has_fpower_series_at` depends on `p.radius`. -/ lemma has_fpower_series_at_iff : has_fpower_series_at f p z₀ ↔ ∀ᶠ z in 𝓝 0, has_sum (λ n, z ^ n • p.coeff n) (f (z₀ + z)) := begin refine ⟨λ ⟨r, r_le, r_pos, h⟩, eventually_of_mem (emetric.ball_mem_nhds 0 r_pos) (λ _, by simpa using h), _⟩, simp only [metric.eventually_nhds_iff], rintro ⟨r, r_pos, h⟩, refine ⟨p.radius ⊓ r.to_nnreal, by simp, _, _⟩, { simp only [r_pos.lt, lt_inf_iff, ennreal.coe_pos, real.to_nnreal_pos, and_true], obtain ⟨z, z_pos, le_z⟩ := normed_field.exists_norm_lt 𝕜 r_pos.lt, have : (‖z‖₊ : ennreal) ≤ p.radius, by { simp only [dist_zero_right] at h, apply formal_multilinear_series.le_radius_of_tendsto, convert tendsto_norm.comp (h le_z).summable.tendsto_at_top_zero, funext; simp [norm_smul, mul_comm] }, refine lt_of_lt_of_le _ this, simp only [ennreal.coe_pos], exact zero_lt_iff.mpr (nnnorm_ne_zero_iff.mpr (norm_pos_iff.mp z_pos)) }, { simp only [emetric.mem_ball, lt_inf_iff, edist_lt_coe, apply_eq_pow_smul_coeff, and_imp, dist_zero_right] at h ⊢, refine λ y hyp hyr, h _, simpa [nndist_eq_nnnorm, real.lt_to_nnreal_iff_coe_lt] using hyr } end lemma has_fpower_series_at_iff' : has_fpower_series_at f p z₀ ↔ ∀ᶠ z in 𝓝 z₀, has_sum (λ n, (z - z₀) ^ n • p.coeff n) (f z) := begin rw [← map_add_left_nhds_zero, eventually_map, has_fpower_series_at_iff], congrm ∀ᶠ z in (𝓝 0 : filter 𝕜), has_sum (λ n, _) (f (z₀ + z)), rw add_sub_cancel' end end
4c8e9c24a586efea4c65718368c4e19b6a73ff1f
d7189ea2ef694124821b033e533f18905b5e87ef
/galois/sequent/ltl_lemmas.lean
f34e882d7ffecd93f1c7ddf40e7b945646590fa4
[ "Apache-2.0" ]
permissive
digama0/lean-protocol-support
eaa7e6f8b8e0d5bbfff1f7f52bfb79a3b11b0f59
cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda
refs/heads/master
1,625,421,450,627
1,506,035,462,000
1,506,035,462,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,070
lean
import .ltl galois.temporal.fixpoint universes u v open temporal lattice namespace sequent lemma eventually_cut {T : Type u} {P Q : tProp T} : rlist.nil & ◇ P & □ (P => ◇ Q) ⊢ ◇ Q := begin repeat {sequent.revert}, rw tautology_iff, apply temporal.eventually_cut, end lemma now_until_eventually {T : Type u} {P Q : tProp T} : rlist.nil & P & ((◯ P) 𝓤 Q) ⊢ ◇ (P ∩ Q) := begin repeat {sequent.revert}, rw tautology_iff, apply temporal.now_until_eventually, end lemma eventually_strengthen_until {T : Type u} {P Q : tProp T} [decidable_pred Q] : rlist.nil & ◇ Q & (P 𝓦 Q) ⊢ (P 𝓤 Q) := begin repeat {sequent.revert}, rw tautology_iff, apply temporal.eventually_strengthen_until, end --notation a `&\n` b `]` := a & b lemma well_founded_LTL_template (A : Type v) (P Q X : tProp A) [decidable_pred Q] : rlist.nil & ◇ Q & P & ((◯ P) 𝓦 Q) & (□ ((P ∩ Q) => ◇ X)) ⊢ ◇ X := begin sequent.apply eventually_cut, tactic.swap, sequent.assumption, sequent.apply now_until_eventually, sequent.assumption, sequent.apply eventually_strengthen_until; sequent.assumption, end lemma until_always_mono {T : Type u} {A B P : tProp T} : rlist.nil & (□ (A ⇒ B)) & (A 𝓤 P) ⊢ (B 𝓤 P) := begin repeat { sequent.revert }, rw tautology_iff, apply until_always_mono, end lemma example1 {A B P X : tProp ℕ} : rlist.nil & (□ (A ⇒ B)) & X & (A 𝓤 P) ⊢ (B 𝓤 P) := begin sequent.revert, sequent.intros, sequent.apply until_always_mono; sequent.assumption, end lemma example2 {A B C D : tProp ℕ} (H : rlist.nil & A & B & A & C ⊢ D) : rlist.nil & A & B & C ⊢ D := begin sequent.apply H; sequent.assumption end lemma example3 {P Q R : tProp ℕ} : rlist.nil & P & Q ⊢ (R ⊓ P) ⊔ (Q ⊓ P) := begin sequent.right, sequent.split, sequent.assumption, sequent.assumption, end --lemma example4 {P Q R : tProp ℕ} : -- rlist.nil & P & Q ⊢ (R ⊓ P) ⊔ (Q ⊓ P) --:= begin --sequent.reify_goal, sequent.entails_tactic formula_entails_auto, --end end sequent
56e01d1f2b1f0552e96d103033e8bf771d6b7843
367134ba5a65885e863bdc4507601606690974c1
/src/tactic/find_unused.lean
a85bd0d985efc1585309e2a5d9ee637788999d7c
[ "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
4,381
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 tactic.core /-! # list_unused_decls `#list_unused_decls` is a command used for theory development. When writing a new theory one often tries multiple variations of the same definitions: `foo`, `foo'`, `foo₂`, `foo₃`, etc. Once the main definition or theorem has been written, it's time to clean up and the file can contain a lot of dead code. Mark the main declarations with `@[main_declaration]` and `#list_unused_decls` will show the declarations in the file that are not needed to define the main declarations. Some of the so-called "unused" declarations may turn out to be useful after all. The oversight can be corrected by marking those as `@[main_declaration]`. `#list_unused_decls` will revise the list of unused declarations. By default, the list of unused declarations will not include any dependency of the main declarations. The `@[main_declaration]` attribute should be removed before submitting code to mathlib as it is merely a tool for cleaning up a module. -/ namespace tactic /-- Attribute `main_declaration` is used to mark declarations that are featured in the current file. Then, the `#list_unused_decls` command can be used to list the declaration present in the file that are not used by the main declarations of the file. -/ @[user_attribute] meta def main_declaration_attr : user_attribute := { name := `main_declaration, descr := "tag essential declarations to help identify unused definitions" } /-- `update_unsed_decls_list n m` removes from the map of unneeded declarations those referenced by declaration named `n` which is considerred to be a main declaration -/ private meta def update_unsed_decls_list : name → name_map declaration → tactic (name_map declaration) | n m := do d ← get_decl n, if m.contains n then do let m := m.erase n, let ns := d.value.list_constant.union d.type.list_constant, ns.mfold m update_unsed_decls_list else pure m /-- In the current file, list all the declaration that are not marked as `@[main_declaration]` and that are not referenced by such declarations -/ meta def all_unused (fs : list (option string)) : tactic (name_map declaration) := do ds ← get_decls_from fs, ls ← ds.keys.mfilter (succeeds ∘ user_attribute.get_param_untyped main_declaration_attr), ds ← ls.mfoldl (flip update_unsed_decls_list) ds, ds.mfilter $ λ n d, do e ← get_env, return $ !d.is_auto_or_internal e /-- expecting a string literal (e.g. `"src/tactic/find_unused.lean"`) -/ meta def parse_file_name (fn : pexpr) : tactic (option string) := some <$> (to_expr fn >>= eval_expr string) <|> fail "expecting: \"src/dir/file-name\"" setup_tactic_parser /-- The command `#list_unused_decls` lists the declarations that that are not used the main features of the present file. The main features of a file are taken as the declaration tagged with `@[main_declaration]`. A list of files can be given to `#list_unused_decls` as follows: ```lean #list_unused_decls ["src/tactic/core.lean","src/tactic/interactive.lean"] ``` They are given in a list that contains file names written as Lean strings. With a list of files, the declarations from all those files in addition to the declarations above `#list_unused_decls` in the current file will be considered and their interdependencies will be analyzed to see which declarations are unused by declarations marked as `@[main_declaration]`. The files listed must be imported by the current file. The path of the file names is expected to be relative to the root of the project (i.e. the location of `leanpkg.toml` when it is present). Neither `#list_unused_decls` nor `@[main_declaration]` should appear in a finished mathlib development. -/ @[user_command] meta def unused_decls_cmd (_ : parse $ tk "#list_unused_decls") : lean.parser unit := do fs ← pexpr_list, show tactic unit, from do fs ← fs.mmap parse_file_name, ds ← all_unused $ none :: fs, ds.to_list.mmap' $ λ ⟨n,_⟩, trace!"#print {n}" add_tactic_doc { name := "#list_unused_decls", category := doc_category.cmd, decl_names := [`tactic.unused_decls_cmd], tags := ["debugging"] } end tactic
7ad24ab7341fbc2a15080f9367097f7eba66b9b7
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/elabissues/issues6.lean
6772110e480dad4608fe2c2ec47014b64ce49552
[ "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
426
lean
def f1 (n : Nat) (i : Int) := i + n -- works def f2 (n : Nat) (i : Int) := n + i -- fails can't coerce Int to Nat def f3 (n : Nat) (i : Int) := n + (n + (n + (n + i))) -- nested version of the previous issue def f4 (n : Nat) (i : Int) := n + (n + (n * (n * i))) -- nested version of the previous issue with mixed operators def f5 (n : Nat) (i : Int) := n + (n + (n * (i, i).1)) -- mixed operators and different structures
b63097f116f0768cd47454b39dc32fad5adabfca
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/ring_theory/chain_of_divisors.lean
3ae3837b0be6737d9d5ece3fc44ae590e5aa8576
[ "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
21,280
lean
/- Copyright (c) 2021 Paul Lezeau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Paul Lezeau -/ import algebra.is_prime_pow import algebra.squarefree import order.hom.bounded import algebra.gcd_monoid.basic /-! # Chains of divisors The results in this file show that in the monoid `associates M` of a `unique_factorization_monoid` `M`, an element `a` is an n-th prime power iff its set of divisors is a strictly increasing chain of length `n + 1`, meaning that we can find a strictly increasing bijection between `fin (n + 1)` and the set of factors of `a`. ## Main results - `divisor_chain.exists_chain_of_prime_pow` : existence of a chain for prime powers. - `divisor_chain.is_prime_pow_of_has_chain` : elements that have a chain are prime powers. - `multiplicity_prime_eq_multiplicity_image_by_factor_order_iso` : if there is a monotone bijection `d` between the set of factors of `a : associates M` and the set of factors of `b : associates N` then for any prime `p ∣ a`, `multiplicity p a = multiplicity (d p) b`. - `multiplicity_eq_multiplicity_factor_dvd_iso_of_mem_normalized_factor` : if there is a bijection between the set of factors of `a : M` and `b : N` then for any prime `p ∣ a`, `multiplicity p a = multiplicity (d p) b` ## Todo - Create a structure for chains of divisors. - Simplify proof of `mem_normalized_factors_factor_dvd_iso_of_mem_normalized_factors` using `mem_normalized_factors_factor_order_iso_of_mem_normalized_factors` or vice versa. -/ variables {M : Type*} [cancel_comm_monoid_with_zero M] open unique_factorization_monoid multiplicity irreducible associates namespace divisor_chain lemma exists_chain_of_prime_pow {p : associates M} {n : ℕ} (hn : n ≠ 0) (hp : prime p) : ∃ c : fin (n + 1) → associates M, c 1 = p ∧ strict_mono c ∧ ∀ {r : associates M}, r ≤ p^n ↔ ∃ i, r = c i := begin refine ⟨λ i, p^(i : ℕ), _, λ n m h, _, λ y, ⟨λ h, _, _⟩⟩, { rw [fin.coe_one', nat.mod_eq_of_lt, pow_one], exact nat.lt_succ_of_le (nat.one_le_iff_ne_zero.mpr hn) }, { exact associates.dvd_not_unit_iff_lt.mp ⟨pow_ne_zero n hp.ne_zero, p^(m - n : ℕ), not_is_unit_of_not_is_unit_dvd hp.not_unit (dvd_pow dvd_rfl (nat.sub_pos_of_lt h).ne'), (pow_mul_pow_sub p h.le).symm⟩ }, { obtain ⟨i, i_le, hi⟩ := (dvd_prime_pow hp n).1 h, rw associated_iff_eq at hi, exact ⟨⟨i, nat.lt_succ_of_le i_le⟩, hi⟩ }, { rintro ⟨i, rfl⟩, exact ⟨p^(n - i : ℕ), (pow_mul_pow_sub p (nat.succ_le_succ_iff.mp i.2)).symm⟩ } end lemma element_of_chain_not_is_unit_of_index_ne_zero {n : ℕ} {i : fin (n + 1)} (i_pos : i ≠ 0) {c : fin (n + 1) → associates M} (h₁ : strict_mono c) : ¬ is_unit (c i) := dvd_not_unit.not_unit (associates.dvd_not_unit_iff_lt.2 (h₁ $ show (0 : fin (n + 1)) < i, from i.pos_iff_ne_zero.mpr i_pos)) lemma first_of_chain_is_unit {q : associates M} {n : ℕ} {c : fin (n + 1) → associates M} (h₁ : strict_mono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) : is_unit (c 0) := begin obtain ⟨i, hr⟩ := h₂.mp associates.one_le, rw [associates.is_unit_iff_eq_one, ← associates.le_one_iff, hr], exact h₁.monotone (fin.zero_le i) end /-- The second element of a chain is irreducible. -/ lemma second_of_chain_is_irreducible {q : associates M} {n : ℕ} (hn : n ≠ 0) {c : fin (n + 1) → associates M} (h₁ : strict_mono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) (hq : q ≠ 0) : irreducible (c 1) := begin cases n, { contradiction }, refine (associates.is_atom_iff (ne_zero_of_dvd_ne_zero hq (h₂.2 ⟨1, rfl⟩))).mp ⟨_, λ b hb, _⟩, { exact ne_bot_of_gt (h₁ (show (0 : fin (n + 2)) < 1, from fin.one_pos)) }, obtain ⟨⟨i, hi⟩, rfl⟩ := h₂.1 (hb.le.trans (h₂.2 ⟨1, rfl⟩)), cases i, { exact (associates.is_unit_iff_eq_one _).mp (first_of_chain_is_unit h₁ @h₂) }, { simpa [fin.lt_iff_coe_lt_coe] using h₁.lt_iff_lt.mp hb }, end lemma eq_second_of_chain_of_prime_dvd {p q r : associates M} {n : ℕ} (hn : n ≠ 0) {c : fin (n + 1) → associates M} (h₁ : strict_mono c) (h₂ : ∀ {r : associates M}, r ≤ q ↔ ∃ i, r = c i) (hp : prime p) (hr : r ∣ q) (hp' : p ∣ r) : p = c 1 := begin cases n, { contradiction }, obtain ⟨i, rfl⟩ := h₂.1 (dvd_trans hp' hr), refine congr_arg c (eq_of_ge_of_not_gt _ $ λ hi, _), { rw [fin.le_iff_coe_le_coe, fin.coe_one, nat.succ_le_iff, ← fin.coe_zero, ← fin.lt_iff_coe_lt_coe, fin.pos_iff_ne_zero], rintro rfl, exact hp.not_unit (first_of_chain_is_unit h₁ @h₂) }, obtain (rfl | ⟨j, rfl⟩) := i.eq_zero_or_eq_succ, { cases hi }, refine not_irreducible_of_not_unit_dvd_not_unit (dvd_not_unit.not_unit (associates.dvd_not_unit_iff_lt.2 (h₁ (show (0 : fin (n + 2)) < j, from _)) )) _ hp.irreducible, { simpa [← fin.succ_zero_eq_one, fin.succ_lt_succ_iff] using hi }, { refine associates.dvd_not_unit_iff_lt.2 (h₁ _), simpa only [fin.coe_eq_cast_succ] using fin.lt_succ } end lemma card_subset_divisors_le_length_of_chain {q : associates M} {n : ℕ} {c : fin (n + 1) → associates M} (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) {m : finset (associates M)} (hm : ∀ r, r ∈ m → r ≤ q) : m.card ≤ n + 1 := begin classical, have mem_image : ∀ (r : associates M), r ≤ q → r ∈ finset.univ.image c, { intros r hr, obtain ⟨i, hi⟩ := h₂.1 hr, exact finset.mem_image.2 ⟨i, finset.mem_univ _, hi.symm⟩ }, rw ←finset.card_fin (n + 1), exact (finset.card_le_of_subset $ λ x hx, mem_image x $ hm x hx).trans finset.card_image_le, end variables [unique_factorization_monoid M] lemma element_of_chain_eq_pow_second_of_chain {q r : associates M} {n : ℕ} (hn : n ≠ 0) {c : fin (n + 1) → associates M} (h₁ : strict_mono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) (hr : r ∣ q) (hq : q ≠ 0) : ∃ (i : fin (n + 1)), r = (c 1) ^ (i : ℕ) := begin classical, let i := (normalized_factors r).card, have hi : normalized_factors r = multiset.repeat (c 1) i, { apply multiset.eq_repeat_of_mem, intros b hb, refine eq_second_of_chain_of_prime_dvd hn h₁ (λ r', h₂) (prime_of_normalized_factor b hb) hr (dvd_of_mem_normalized_factors hb) }, have H : r = (c 1)^i, { have := unique_factorization_monoid.normalized_factors_prod (ne_zero_of_dvd_ne_zero hq hr), rw [associated_iff_eq, hi, multiset.prod_repeat] at this, rw this }, refine ⟨⟨i, _⟩, H⟩, have : (finset.univ.image (λ (m : fin (i + 1)), (c 1) ^ (m : ℕ))).card = i + 1, { conv_rhs { rw [← finset.card_fin (i+1)] }, cases n, { contradiction }, rw finset.card_image_iff, refine set.inj_on_of_injective (λ m m' h, fin.ext _) _, refine pow_injective_of_not_unit (element_of_chain_not_is_unit_of_index_ne_zero (by simp) h₁) _ h, exact irreducible.ne_zero (second_of_chain_is_irreducible hn h₁ @h₂ hq) }, suffices H' : ∀ r ∈ (finset.univ.image (λ (m : fin (i + 1)), (c 1) ^ (m : ℕ))), r ≤ q, { simp only [← nat.succ_le_iff, nat.succ_eq_add_one, ← this], apply card_subset_divisors_le_length_of_chain @h₂ H' }, simp only [finset.mem_image], rintros r ⟨a, ha, rfl⟩, refine dvd_trans _ hr, use (c 1)^(i - a), rw pow_mul_pow_sub (c 1), { exact H }, { exact nat.succ_le_succ_iff.mp a.2 } end lemma eq_pow_second_of_chain_of_has_chain {q : associates M} {n : ℕ} (hn : n ≠ 0) {c : fin (n + 1) → associates M} (h₁ : strict_mono c) (h₂ : ∀ {r : associates M}, r ≤ q ↔ ∃ i, r = c i) (hq : q ≠ 0) : q = (c 1)^n := begin classical, obtain ⟨i, hi'⟩ := element_of_chain_eq_pow_second_of_chain hn h₁ (λ r, h₂) (dvd_refl q) hq, convert hi', refine (nat.lt_succ_iff.1 i.prop).antisymm' (nat.le_of_succ_le_succ _), calc n + 1 = (finset.univ : finset (fin (n + 1))).card : (finset.card_fin _).symm ... = (finset.univ.image c).card : (finset.card_image_iff.mpr (h₁.injective.inj_on _)).symm ... ≤ (finset.univ.image (λ (m : fin (i + 1)), (c 1)^(m : ℕ))).card : finset.card_le_of_subset _ ... ≤ (finset.univ : finset (fin (i + 1))).card : finset.card_image_le ... = i + 1 : finset.card_fin _, intros r hr, obtain ⟨j, -, rfl⟩ := finset.mem_image.1 hr, have := h₂.2 ⟨j, rfl⟩, rw hi' at this, obtain ⟨u, hu, hu'⟩ := (dvd_prime_pow (show prime (c 1), from _) i).1 this, refine finset.mem_image.mpr ⟨u, finset.mem_univ _, _⟩, { rw associated_iff_eq at hu', rw [fin.coe_coe_of_lt (nat.lt_succ_of_le hu), hu'] }, { rw ← irreducible_iff_prime, exact second_of_chain_is_irreducible hn h₁ @h₂ hq, } end lemma is_prime_pow_of_has_chain {q : associates M} {n : ℕ} (hn : n ≠ 0) {c : fin (n + 1) → associates M} (h₁ : strict_mono c) (h₂ : ∀ {r : associates M}, r ≤ q ↔ ∃ i, r = c i) (hq : q ≠ 0) : is_prime_pow q := ⟨c 1, n, irreducible_iff_prime.mp (second_of_chain_is_irreducible hn h₁ @h₂ hq), zero_lt_iff.mpr hn, (eq_pow_second_of_chain_of_has_chain hn h₁ @h₂ hq).symm⟩ end divisor_chain variables {N : Type*} [cancel_comm_monoid_with_zero N] lemma factor_order_iso_map_one_eq_bot {m : associates M} {n : associates N} (d : {l : associates M // l ≤ m} ≃o {l : associates N // l ≤ n}) : (d ⟨1, one_dvd m⟩ : associates N) = 1 := begin letI : order_bot {l : associates M // l ≤ m} := subtype.order_bot bot_le, letI : order_bot {l : associates N // l ≤ n} := subtype.order_bot bot_le, simp [←associates.bot_eq_one] end lemma coe_factor_order_iso_map_eq_one_iff {m u : associates M} {n : associates N} (hu' : u ≤ m) (d : set.Iic m ≃o set.Iic n) : (d ⟨u, hu'⟩ : associates N) = 1 ↔ u = 1 := ⟨λ hu, by { rw (show u = ↑(d.symm ⟨↑(d ⟨u, hu'⟩), (d ⟨u, hu'⟩).prop⟩), by simp only [subtype.coe_eta, order_iso.symm_apply_apply, subtype.coe_mk]), convert factor_order_iso_map_one_eq_bot d.symm }, λ hu, by {simp_rw hu, convert factor_order_iso_map_one_eq_bot d } ⟩ section variables [unique_factorization_monoid N] [unique_factorization_monoid M] open divisor_chain lemma pow_image_of_prime_by_factor_order_iso_dvd [decidable_eq (associates M)] {m p : associates M} {n : associates N} (hn : n ≠ 0) (hp : p ∈ normalized_factors m) (d : set.Iic m ≃o set.Iic n) {s : ℕ} (hs' : p^s ≤ m) : (d ⟨p, dvd_of_mem_normalized_factors hp⟩ : associates N)^s ≤ n := begin by_cases hs : s = 0, { simp [hs], }, suffices : (d ⟨p, dvd_of_mem_normalized_factors hp⟩ : associates N)^s = ↑(d ⟨p^s, hs'⟩), { rw this, apply subtype.prop (d ⟨p^s, hs'⟩) }, obtain ⟨c₁, rfl, hc₁', hc₁''⟩ := exists_chain_of_prime_pow hs (prime_of_normalized_factor p hp), set c₂ : fin (s + 1) → associates N := λ t, d ⟨c₁ t, le_trans (hc₁''.2 ⟨t, by simp⟩) hs'⟩, have c₂.def : ∀ (t), c₂ t = d ⟨c₁ t, _⟩ := λ t, rfl, refine (congr_arg (^s) (c₂.def 1).symm).trans _, refine (eq_pow_second_of_chain_of_has_chain hs (λ t u h, _) (λ r, ⟨λ hr, _, _⟩) _).symm, { rw [c₂.def, c₂.def, subtype.coe_lt_coe, d.lt_iff_lt, subtype.mk_lt_mk, (hc₁').lt_iff_lt], exact h }, { have : r ≤ n := hr.trans (d ⟨c₁ 1 ^ s, _⟩).2, suffices : d.symm ⟨r, this⟩ ≤ ⟨c₁ 1 ^ s, hs'⟩, { obtain ⟨i, hi⟩ := hc₁''.1 this, use i, simp only [c₂.def, ← hi, d.apply_symm_apply, subtype.coe_eta, subtype.coe_mk] }, conv_rhs { rw ← d.symm_apply_apply ⟨c₁ 1 ^ s, hs'⟩ }, rw d.symm.le_iff_le, simpa only [← subtype.coe_le_coe, subtype.coe_mk] using hr }, { rintros ⟨i, hr⟩, rw [hr, c₂.def, subtype.coe_le_coe, d.le_iff_le], simpa [subtype.mk_le_mk] using hc₁''.2 ⟨i, rfl⟩ }, exact ne_zero_of_dvd_ne_zero hn (subtype.prop (d ⟨c₁ 1 ^ s, _⟩)) end lemma map_prime_of_factor_order_iso [decidable_eq (associates M)] {m p : associates M} {n : associates N} (hn : n ≠ 0) (hp : p ∈ normalized_factors m) (d : set.Iic m ≃o set.Iic n) : prime (d ⟨p, dvd_of_mem_normalized_factors hp⟩ : associates N) := begin rw ← irreducible_iff_prime, refine (associates.is_atom_iff $ ne_zero_of_dvd_ne_zero hn (d ⟨p, _⟩).prop).mp ⟨_, λ b hb, _⟩, { rw [ne.def, ← associates.is_unit_iff_eq_bot, associates.is_unit_iff_eq_one, coe_factor_order_iso_map_eq_one_iff _ d], rintro rfl, exact (prime_of_normalized_factor 1 hp).not_unit is_unit_one }, { obtain ⟨x, hx⟩ := d.surjective ⟨b, le_trans (le_of_lt hb) (d ⟨p, dvd_of_mem_normalized_factors hp⟩).prop⟩, rw [← subtype.coe_mk b _ , subtype.coe_lt_coe, ← hx] at hb, letI : order_bot {l : associates M // l ≤ m} := subtype.order_bot bot_le, letI : order_bot {l : associates N // l ≤ n} := subtype.order_bot bot_le, suffices : x = ⊥, { rw [this, order_iso.map_bot d] at hx, refine (subtype.mk_eq_bot_iff _ _).mp hx.symm, exact bot_le }, obtain ⟨a, ha⟩ := x, rw subtype.mk_eq_bot_iff, { exact ((associates.is_atom_iff $ prime.ne_zero $ prime_of_normalized_factor p hp).mpr $ irreducible_of_normalized_factor p hp).right a (subtype.mk_lt_mk.mp $ d.lt_iff_lt.mp hb) }, exact bot_le } end lemma mem_normalized_factors_factor_order_iso_of_mem_normalized_factors [decidable_eq (associates M)] [decidable_eq (associates N)] {m p : associates M} {n : associates N} (hn : n ≠ 0) (hp : p ∈ normalized_factors m) (d : set.Iic m ≃o set.Iic n) : ↑(d ⟨p, dvd_of_mem_normalized_factors hp⟩) ∈ normalized_factors n := begin obtain ⟨q, hq, hq'⟩ := exists_mem_normalized_factors_of_dvd hn (map_prime_of_factor_order_iso hn hp d).irreducible (d ⟨p, dvd_of_mem_normalized_factors hp⟩).prop, rw associated_iff_eq at hq', rwa hq' end variables [decidable_rel ((∣) : M → M → Prop)] [decidable_rel ((∣) : N → N → Prop)] lemma multiplicity_prime_le_multiplicity_image_by_factor_order_iso [decidable_eq (associates M)] {m p : associates M} {n : associates N} (hp : p ∈ normalized_factors m) (d : set.Iic m ≃o set.Iic n) : multiplicity p m ≤ multiplicity ↑(d ⟨p, dvd_of_mem_normalized_factors hp⟩) n := begin by_cases hn : n = 0, { simp [hn], }, by_cases hm : m = 0, { simpa [hm] using hp, }, rw [← part_enat.coe_get (finite_iff_dom.1 $ finite_prime_left (prime_of_normalized_factor p hp) hm), ← pow_dvd_iff_le_multiplicity], exact pow_image_of_prime_by_factor_order_iso_dvd hn hp d (pow_multiplicity_dvd _), end lemma multiplicity_prime_eq_multiplicity_image_by_factor_order_iso [decidable_eq (associates M)] {m p : associates M} {n : associates N} (hn : n ≠ 0) (hp : p ∈ normalized_factors m) (d : set.Iic m ≃o set.Iic n) : multiplicity p m = multiplicity ↑(d ⟨p, dvd_of_mem_normalized_factors hp⟩) n := begin refine le_antisymm (multiplicity_prime_le_multiplicity_image_by_factor_order_iso hp d) _, suffices : multiplicity ↑(d ⟨p, dvd_of_mem_normalized_factors hp⟩) n ≤ multiplicity ↑(d.symm (d ⟨p, dvd_of_mem_normalized_factors hp⟩)) m, { rw [d.symm_apply_apply ⟨p, dvd_of_mem_normalized_factors hp⟩, subtype.coe_mk] at this, exact this }, letI := classical.dec_eq (associates N), simpa only [subtype.coe_eta] using (multiplicity_prime_le_multiplicity_image_by_factor_order_iso (mem_normalized_factors_factor_order_iso_of_mem_normalized_factors hn hp d) d.symm), end end variables [unique (Mˣ)] [unique (Nˣ)] /-- The order isomorphism between the factors of `mk m` and the factors of `mk n` induced by a bijection between the factors of `m` and the factors of `n` that preserves `∣`. -/ @[simps] def mk_factor_order_iso_of_factor_dvd_equiv {m : M} {n : N} {d : {l : M // l ∣ m} ≃ {l : N // l ∣ n}} (hd : ∀ l l', ((d l) : N) ∣ (d l') ↔ (l : M) ∣ (l' : M)) : set.Iic (associates.mk m) ≃o set.Iic (associates.mk n) := { to_fun := λ l, ⟨associates.mk (d ⟨associates_equiv_of_unique_units ↑l, by { obtain ⟨x, hx⟩ := l, rw [subtype.coe_mk, associates_equiv_of_unique_units_apply, out_dvd_iff], exact hx } ⟩), mk_le_mk_iff_dvd_iff.mpr (subtype.prop (d ⟨associates_equiv_of_unique_units ↑l, _ ⟩)) ⟩, inv_fun := λ l, ⟨associates.mk (d.symm (⟨(associates_equiv_of_unique_units ↑l), by obtain ⟨x, hx⟩ := l ; rw [subtype.coe_mk, associates_equiv_of_unique_units_apply, out_dvd_iff] ; exact hx ⟩)), mk_le_mk_iff_dvd_iff.mpr (subtype.prop (d.symm ⟨associates_equiv_of_unique_units ↑l, _ ⟩)) ⟩, left_inv := λ ⟨l, hl⟩, by simp only [subtype.coe_eta, equiv.symm_apply_apply, subtype.coe_mk, associates_equiv_of_unique_units_apply, mk_out, out_mk, normalize_eq], right_inv := λ ⟨l, hl⟩, by simp only [subtype.coe_eta, equiv.apply_symm_apply, subtype.coe_mk, associates_equiv_of_unique_units_apply, out_mk, normalize_eq, mk_out], map_rel_iff' := by rintros ⟨a, ha⟩ ⟨b, hb⟩ ; simp only [equiv.coe_fn_mk, subtype.mk_le_mk, associates.mk_le_mk_iff_dvd_iff, hd, subtype.coe_mk, associates_equiv_of_unique_units_apply, out_dvd_iff, mk_out] } variables [unique_factorization_monoid M] [unique_factorization_monoid N] [decidable_eq M] lemma mem_normalized_factors_factor_dvd_iso_of_mem_normalized_factors [decidable_eq N] {m p : M} {n : N} (hm : m ≠ 0) (hn : n ≠ 0) (hp : p ∈ normalized_factors m) {d : {l : M // l ∣ m} ≃ {l : N // l ∣ n}} (hd : ∀ l l', ((d l) : N) ∣ (d l') ↔ (l : M) ∣ (l' : M)) : ↑(d ⟨p, dvd_of_mem_normalized_factors hp⟩) ∈ normalized_factors n := begin suffices : prime ↑(d ⟨associates_equiv_of_unique_units (associates_equiv_of_unique_units.symm p), by simp [dvd_of_mem_normalized_factors hp]⟩), { simp only [associates_equiv_of_unique_units_apply, out_mk, normalize_eq, associates_equiv_of_unique_units_symm_apply] at this, obtain ⟨q, hq, hq'⟩ := exists_mem_normalized_factors_of_dvd hn (this.irreducible) (d ⟨p, by apply dvd_of_mem_normalized_factors ; convert hp⟩).prop, rwa associated_iff_eq.mp hq' }, have : associates.mk ↑(d ⟨associates_equiv_of_unique_units (associates_equiv_of_unique_units.symm p), by simp only [dvd_of_mem_normalized_factors hp, associates_equiv_of_unique_units_apply, out_mk, normalize_eq, associates_equiv_of_unique_units_symm_apply] ⟩) = ↑(mk_factor_order_iso_of_factor_dvd_equiv hd ⟨( associates_equiv_of_unique_units.symm p), by simp only [associates_equiv_of_unique_units_symm_apply] ; exact mk_dvd_mk.mpr (dvd_of_mem_normalized_factors hp) ⟩), { rw mk_factor_order_iso_of_factor_dvd_equiv_apply_coe, simp only [subtype.coe_mk] }, rw [ ← associates.prime_mk, this], letI := classical.dec_eq (associates M), refine map_prime_of_factor_order_iso (mk_ne_zero.mpr hn) _ _, obtain ⟨q, hq, hq'⟩ := exists_mem_normalized_factors_of_dvd (mk_ne_zero.mpr hm) ((prime_mk p).mpr (prime_of_normalized_factor p (by convert hp))).irreducible (mk_le_mk_of_dvd (dvd_of_mem_normalized_factors hp)), simpa only [associated_iff_eq.mp hq', associates_equiv_of_unique_units_symm_apply] using hq, end variables [decidable_rel ((∣) : M → M → Prop)] [decidable_rel ((∣) : N → N → Prop)] lemma multiplicity_factor_dvd_iso_eq_multiplicity_of_mem_normalized_factor {m p : M} {n : N} (hm : m ≠ 0) (hn : n ≠ 0) (hp : p ∈ normalized_factors m) {d : {l : M // l ∣ m} ≃ {l : N // l ∣ n}} (hd : ∀ l l', ((d l) : N) ∣ (d l') ↔ (l : M) ∣ l') : multiplicity ((d ⟨p, dvd_of_mem_normalized_factors hp⟩) : N) n = multiplicity p m := begin apply eq.symm, suffices : multiplicity (associates.mk p) (associates.mk m) = multiplicity (associates.mk ↑(d ⟨associates_equiv_of_unique_units (associates_equiv_of_unique_units.symm p), by simp [dvd_of_mem_normalized_factors hp]⟩)) (associates.mk n), { simpa only [multiplicity_mk_eq_multiplicity, associates_equiv_of_unique_units_symm_apply, associates_equiv_of_unique_units_apply, out_mk, normalize_eq] using this }, have : associates.mk ↑(d ⟨associates_equiv_of_unique_units (associates_equiv_of_unique_units.symm p), by simp only [dvd_of_mem_normalized_factors hp, associates_equiv_of_unique_units_symm_apply, associates_equiv_of_unique_units_apply, out_mk, normalize_eq] ⟩) = ↑(mk_factor_order_iso_of_factor_dvd_equiv hd ⟨(associates_equiv_of_unique_units.symm p), by rw [associates_equiv_of_unique_units_symm_apply] ; exact mk_le_mk_of_dvd (dvd_of_mem_normalized_factors hp) ⟩), { rw mk_factor_order_iso_of_factor_dvd_equiv_apply_coe, refl }, rw this, letI := classical.dec_eq (associates M), refine multiplicity_prime_eq_multiplicity_image_by_factor_order_iso (mk_ne_zero.mpr hn) _ (mk_factor_order_iso_of_factor_dvd_equiv hd), obtain ⟨q, hq, hq'⟩ := exists_mem_normalized_factors_of_dvd (mk_ne_zero.mpr hm) ((prime_mk p).mpr (prime_of_normalized_factor p hp)).irreducible (mk_le_mk_of_dvd (dvd_of_mem_normalized_factors hp)), rwa associated_iff_eq.mp hq', end
cc9f4471ec30b43c4e9507df374b443583d6cf51
94e33a31faa76775069b071adea97e86e218a8ee
/src/geometry/euclidean/circumcenter.lean
95a77aa6e6ce3760510109e25c0c7633373432e3
[ "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
40,597
lean
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import geometry.euclidean.basic import linear_algebra.affine_space.finite_dimensional import tactic.derive_fintype /-! # Circumcenter and circumradius This file proves some lemmas on points equidistant from a set of points, and defines the circumradius and circumcenter of a simplex. There are also some definitions for use in calculations where it is convenient to work with affine combinations of vertices together with the circumcenter. ## Main definitions * `circumcenter` and `circumradius` are the circumcenter and circumradius of a simplex. ## References * https://en.wikipedia.org/wiki/Circumscribed_circle -/ noncomputable theory open_locale big_operators open_locale classical open_locale real open_locale real_inner_product_space namespace euclidean_geometry open inner_product_geometry variables {V : Type*} {P : Type*} [inner_product_space ℝ V] [metric_space P] [normed_add_torsor V P] include V open affine_subspace /-- `p` is equidistant from two points in `s` if and only if its `orthogonal_projection` is. -/ lemma dist_eq_iff_dist_orthogonal_projection_eq {s : affine_subspace ℝ P} [nonempty s] [complete_space s.direction] {p1 p2 : P} (p3 : P) (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : dist p1 p3 = dist p2 p3 ↔ dist p1 (orthogonal_projection s p3) = dist p2 (orthogonal_projection s p3) := begin rw [←mul_self_inj_of_nonneg dist_nonneg dist_nonneg, ←mul_self_inj_of_nonneg dist_nonneg dist_nonneg, dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq p3 hp1, dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq p3 hp2], simp end /-- `p` is equidistant from a set of points in `s` if and only if its `orthogonal_projection` is. -/ lemma dist_set_eq_iff_dist_orthogonal_projection_eq {s : affine_subspace ℝ P} [nonempty s] [complete_space s.direction] {ps : set P} (hps : ps ⊆ s) (p : P) : set.pairwise ps (λ p1 p2, dist p1 p = dist p2 p) ↔ (set.pairwise ps (λ p1 p2, dist p1 (orthogonal_projection s p) = dist p2 (orthogonal_projection s p))) := ⟨λ h p1 hp1 p2 hp2 hne, (dist_eq_iff_dist_orthogonal_projection_eq p (hps hp1) (hps hp2)).1 (h hp1 hp2 hne), λ h p1 hp1 p2 hp2 hne, (dist_eq_iff_dist_orthogonal_projection_eq p (hps hp1) (hps hp2)).2 (h hp1 hp2 hne)⟩ /-- There exists `r` such that `p` has distance `r` from all the points of a set of points in `s` if and only if there exists (possibly different) `r` such that its `orthogonal_projection` has that distance from all the points in that set. -/ lemma exists_dist_eq_iff_exists_dist_orthogonal_projection_eq {s : affine_subspace ℝ P} [nonempty s] [complete_space s.direction] {ps : set P} (hps : ps ⊆ s) (p : P) : (∃ r, ∀ p1 ∈ ps, dist p1 p = r) ↔ ∃ r, ∀ p1 ∈ ps, dist p1 ↑(orthogonal_projection s p) = r := begin have h := dist_set_eq_iff_dist_orthogonal_projection_eq hps p, simp_rw set.pairwise_eq_iff_exists_eq at h, exact h end /-- The induction step for the existence and uniqueness of the circumcenter. Given a nonempty set of points in a nonempty affine subspace whose direction is complete, such that there is a unique (circumcenter, circumradius) pair for those points in that subspace, and a point `p` not in that subspace, there is a unique (circumcenter, circumradius) pair for the set with `p` added, in the span of the subspace with `p` added. -/ lemma exists_unique_dist_eq_of_insert {s : affine_subspace ℝ P} [complete_space s.direction] {ps : set P} (hnps : ps.nonempty) {p : P} (hps : ps ⊆ s) (hp : p ∉ s) (hu : ∃! cccr : (P × ℝ), cccr.fst ∈ s ∧ ∀ p1 ∈ ps, dist p1 cccr.fst = cccr.snd) : ∃! cccr₂ : (P × ℝ), cccr₂.fst ∈ affine_span ℝ (insert p (s : set P)) ∧ ∀ p1 ∈ insert p ps, dist p1 cccr₂.fst = cccr₂.snd := begin haveI : nonempty s := set.nonempty.to_subtype (hnps.mono hps), rcases hu with ⟨⟨cc, cr⟩, ⟨hcc, hcr⟩, hcccru⟩, simp only [prod.fst, prod.snd] at hcc hcr hcccru, let x := dist cc (orthogonal_projection s p), let y := dist p (orthogonal_projection s p), have hy0 : y ≠ 0 := dist_orthogonal_projection_ne_zero_of_not_mem hp, let ycc₂ := (x * x + y * y - cr * cr) / (2 * y), let cc₂ := (ycc₂ / y) • (p -ᵥ orthogonal_projection s p : V) +ᵥ cc, let cr₂ := real.sqrt (cr * cr + ycc₂ * ycc₂), use (cc₂, cr₂), simp only [prod.fst, prod.snd], have hpo : p = (1 : ℝ) • (p -ᵥ orthogonal_projection s p : V) +ᵥ orthogonal_projection s p, { simp }, split, { split, { refine vadd_mem_of_mem_direction _ (mem_affine_span ℝ (set.mem_insert_of_mem _ hcc)), rw direction_affine_span, exact submodule.smul_mem _ _ (vsub_mem_vector_span ℝ (set.mem_insert _ _) (set.mem_insert_of_mem _ (orthogonal_projection_mem _))) }, { intros p1 hp1, rw [←mul_self_inj_of_nonneg dist_nonneg (real.sqrt_nonneg _), real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))], cases hp1, { rw hp1, rw [hpo, dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonal_projection_mem p) hcc _ _ (vsub_orthogonal_projection_mem_direction_orthogonal s p), ←dist_eq_norm_vsub V p, dist_comm _ cc], field_simp [hy0], ring }, { rw [dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq _ (hps hp1), orthogonal_projection_vadd_smul_vsub_orthogonal_projection _ _ hcc, subtype.coe_mk, hcr _ hp1, dist_eq_norm_vsub V cc₂ cc, vadd_vsub, norm_smul, ←dist_eq_norm_vsub V, real.norm_eq_abs, abs_div, abs_of_nonneg dist_nonneg, div_mul_cancel _ hy0, abs_mul_abs_self] } } }, { rintros ⟨cc₃, cr₃⟩ ⟨hcc₃, hcr₃⟩, simp only [prod.fst, prod.snd] at hcc₃ hcr₃, obtain ⟨t₃, cc₃', hcc₃', hcc₃''⟩ : ∃ (r : ℝ) (p0 : P) (hp0 : p0 ∈ s), cc₃ = r • (p -ᵥ ↑((orthogonal_projection s) p)) +ᵥ p0, { rwa mem_affine_span_insert_iff (orthogonal_projection_mem p) at hcc₃ }, have hcr₃' : ∃ r, ∀ p1 ∈ ps, dist p1 cc₃ = r := ⟨cr₃, λ p1 hp1, hcr₃ p1 (set.mem_insert_of_mem _ hp1)⟩, rw [exists_dist_eq_iff_exists_dist_orthogonal_projection_eq hps cc₃, hcc₃'', orthogonal_projection_vadd_smul_vsub_orthogonal_projection _ _ hcc₃'] at hcr₃', cases hcr₃' with cr₃' hcr₃', have hu := hcccru (cc₃', cr₃'), simp only [prod.fst, prod.snd] at hu, replace hu := hu ⟨hcc₃', hcr₃'⟩, rw prod.ext_iff at hu, simp only [prod.fst, prod.snd] at hu, cases hu with hucc hucr, substs hucc hucr, have hcr₃val : cr₃ = real.sqrt (cr₃' * cr₃' + (t₃ * y) * (t₃ * y)), { cases hnps with p0 hp0, have h' : ↑(⟨cc₃', hcc₃'⟩ : s) = cc₃' := rfl, rw [←hcr₃ p0 (set.mem_insert_of_mem _ hp0), hcc₃'', ←mul_self_inj_of_nonneg dist_nonneg (real.sqrt_nonneg _), real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)), dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq _ (hps hp0), orthogonal_projection_vadd_smul_vsub_orthogonal_projection _ _ hcc₃', h', hcr p0 hp0, dist_eq_norm_vsub V _ cc₃', vadd_vsub, norm_smul, ←dist_eq_norm_vsub V p, real.norm_eq_abs, ←mul_assoc, mul_comm _ (|t₃|), ←mul_assoc, abs_mul_abs_self], ring }, replace hcr₃ := hcr₃ p (set.mem_insert _ _), rw [hpo, hcc₃'', hcr₃val, ←mul_self_inj_of_nonneg dist_nonneg (real.sqrt_nonneg _), dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonal_projection_mem p) hcc₃' _ _ (vsub_orthogonal_projection_mem_direction_orthogonal s p), dist_comm, ←dist_eq_norm_vsub V p, real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] at hcr₃, change x * x + _ * (y * y) = _ at hcr₃, rw [(show x * x + (1 - t₃) * (1 - t₃) * (y * y) = x * x + y * y - 2 * y * (t₃ * y) + t₃ * y * (t₃ * y), by ring), add_left_inj] at hcr₃, have ht₃ : t₃ = ycc₂ / y, { field_simp [←hcr₃, hy0], ring }, subst ht₃, change cc₃ = cc₂ at hcc₃'', congr', rw hcr₃val, congr' 2, field_simp [hy0], ring } end /-- Given a finite nonempty affinely independent family of points, there is a unique (circumcenter, circumradius) pair for those points in the affine subspace they span. -/ lemma _root_.affine_independent.exists_unique_dist_eq {ι : Type*} [hne : nonempty ι] [fintype ι] {p : ι → P} (ha : affine_independent ℝ p) : ∃! cccr : (P × ℝ), cccr.fst ∈ affine_span ℝ (set.range p) ∧ ∀ i, dist (p i) cccr.fst = cccr.snd := begin unfreezingI { induction hn : fintype.card ι with m hm generalizing ι }, { exfalso, have h := fintype.card_pos_iff.2 hne, rw hn at h, exact lt_irrefl 0 h }, { cases m, { rw fintype.card_eq_one_iff at hn, cases hn with i hi, haveI : unique ι := ⟨⟨i⟩, hi⟩, use (p i, 0), simp only [prod.fst, prod.snd, set.range_unique, affine_subspace.mem_affine_span_singleton], split, { simp_rw [hi default], use rfl, intro i1, rw hi i1, exact dist_self _ }, { rintros ⟨cc, cr⟩, simp only [prod.fst, prod.snd], rintros ⟨rfl, hdist⟩, rw hi default, congr', rw ←hdist default, exact dist_self _ } }, { have i := hne.some, let ι2 := {x // x ≠ i}, have hc : fintype.card ι2 = m + 1, { rw fintype.card_of_subtype (finset.univ.filter (λ x, x ≠ i)), { rw finset.filter_not, simp_rw eq_comm, rw [finset.filter_eq, if_pos (finset.mem_univ _), finset.card_sdiff (finset.subset_univ _), finset.card_singleton, finset.card_univ, hn], simp }, { simp } }, haveI : nonempty ι2 := fintype.card_pos_iff.1 (hc.symm ▸ nat.zero_lt_succ _), have ha2 : affine_independent ℝ (λ i2 : ι2, p i2) := ha.subtype _, replace hm := hm ha2 hc, have hr : set.range p = insert (p i) (set.range (λ i2 : ι2, p i2)), { change _ = insert _ (set.range (λ i2 : {x | x ≠ i}, p i2)), rw [←set.image_eq_range, ←set.image_univ, ←set.image_insert_eq], congr' with j, simp [classical.em] }, change ∃! (cccr : P × ℝ), (_ ∧ ∀ i2, (λ q, dist q cccr.fst = cccr.snd) (p i2)), conv { congr, funext, conv { congr, skip, rw ←set.forall_range_iff } }, dsimp only, rw hr, change ∃! (cccr : P × ℝ), (_ ∧ ∀ (i2 : ι2), (λ q, dist q cccr.fst = cccr.snd) (p i2)) at hm, conv at hm { congr, funext, conv { congr, skip, rw ←set.forall_range_iff } }, rw ←affine_span_insert_affine_span, refine exists_unique_dist_eq_of_insert (set.range_nonempty _) (subset_span_points ℝ _) _ hm, convert ha.not_mem_affine_span_diff i set.univ, change set.range (λ i2 : {x | x ≠ i}, p i2) = _, rw ←set.image_eq_range, congr' with j, simp, refl } } end end euclidean_geometry namespace affine namespace simplex open finset affine_subspace euclidean_geometry variables {V : Type*} {P : Type*} [inner_product_space ℝ V] [metric_space P] [normed_add_torsor V P] include V /-- The pair (circumcenter, circumradius) of a simplex. -/ def circumcenter_circumradius {n : ℕ} (s : simplex ℝ P n) : (P × ℝ) := s.independent.exists_unique_dist_eq.some /-- The property satisfied by the (circumcenter, circumradius) pair. -/ lemma circumcenter_circumradius_unique_dist_eq {n : ℕ} (s : simplex ℝ P n) : (s.circumcenter_circumradius.fst ∈ affine_span ℝ (set.range s.points) ∧ ∀ i, dist (s.points i) s.circumcenter_circumradius.fst = s.circumcenter_circumradius.snd) ∧ (∀ cccr : (P × ℝ), (cccr.fst ∈ affine_span ℝ (set.range s.points) ∧ ∀ i, dist (s.points i) cccr.fst = cccr.snd) → cccr = s.circumcenter_circumradius) := s.independent.exists_unique_dist_eq.some_spec /-- The circumcenter of a simplex. -/ def circumcenter {n : ℕ} (s : simplex ℝ P n) : P := s.circumcenter_circumradius.fst /-- The circumradius of a simplex. -/ def circumradius {n : ℕ} (s : simplex ℝ P n) : ℝ := s.circumcenter_circumradius.snd /-- The circumcenter lies in the affine span. -/ lemma circumcenter_mem_affine_span {n : ℕ} (s : simplex ℝ P n) : s.circumcenter ∈ affine_span ℝ (set.range s.points) := s.circumcenter_circumradius_unique_dist_eq.1.1 /-- All points have distance from the circumcenter equal to the circumradius. -/ @[simp] lemma dist_circumcenter_eq_circumradius {n : ℕ} (s : simplex ℝ P n) : ∀ i, dist (s.points i) s.circumcenter = s.circumradius := s.circumcenter_circumradius_unique_dist_eq.1.2 /-- All points have distance to the circumcenter equal to the circumradius. -/ @[simp] lemma dist_circumcenter_eq_circumradius' {n : ℕ} (s : simplex ℝ P n) : ∀ i, dist s.circumcenter (s.points i) = s.circumradius := begin intro i, rw dist_comm, exact dist_circumcenter_eq_circumradius _ _ end /-- Given a point in the affine span from which all the points are equidistant, that point is the circumcenter. -/ lemma eq_circumcenter_of_dist_eq {n : ℕ} (s : simplex ℝ P n) {p : P} (hp : p ∈ affine_span ℝ (set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : p = s.circumcenter := begin have h := s.circumcenter_circumradius_unique_dist_eq.2 (p, r), simp only [hp, hr, forall_const, eq_self_iff_true, and_self, prod.ext_iff] at h, exact h.1 end /-- Given a point in the affine span from which all the points are equidistant, that distance is the circumradius. -/ lemma eq_circumradius_of_dist_eq {n : ℕ} (s : simplex ℝ P n) {p : P} (hp : p ∈ affine_span ℝ (set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : r = s.circumradius := begin have h := s.circumcenter_circumradius_unique_dist_eq.2 (p, r), simp only [hp, hr, forall_const, eq_self_iff_true, and_self, prod.ext_iff] at h, exact h.2 end /-- The circumradius is non-negative. -/ lemma circumradius_nonneg {n : ℕ} (s : simplex ℝ P n) : 0 ≤ s.circumradius := s.dist_circumcenter_eq_circumradius 0 ▸ dist_nonneg /-- The circumradius of a simplex with at least two points is positive. -/ lemma circumradius_pos {n : ℕ} (s : simplex ℝ P (n + 1)) : 0 < s.circumradius := begin refine lt_of_le_of_ne s.circumradius_nonneg _, intro h, have hr := s.dist_circumcenter_eq_circumradius, simp_rw [←h, dist_eq_zero] at hr, have h01 := s.independent.injective.ne (dec_trivial : (0 : fin (n + 2)) ≠ 1), simpa [hr] using h01 end /-- The circumcenter of a 0-simplex equals its unique point. -/ lemma circumcenter_eq_point (s : simplex ℝ P 0) (i : fin 1) : s.circumcenter = s.points i := begin have h := s.circumcenter_mem_affine_span, rw [set.range_unique, mem_affine_span_singleton] at h, rw h, congr end /-- The circumcenter of a 1-simplex equals its centroid. -/ lemma circumcenter_eq_centroid (s : simplex ℝ P 1) : s.circumcenter = finset.univ.centroid ℝ s.points := begin have hr : set.pairwise set.univ (λ i j : fin 2, dist (s.points i) (finset.univ.centroid ℝ s.points) = dist (s.points j) (finset.univ.centroid ℝ s.points)), { intros i hi j hj hij, rw [finset.centroid_pair_fin, dist_eq_norm_vsub V (s.points i), dist_eq_norm_vsub V (s.points j), vsub_vadd_eq_vsub_sub, vsub_vadd_eq_vsub_sub, ←one_smul ℝ (s.points i -ᵥ s.points 0), ←one_smul ℝ (s.points j -ᵥ s.points 0)], fin_cases i; fin_cases j; simp [-one_smul, ←sub_smul]; norm_num }, rw set.pairwise_eq_iff_exists_eq at hr, cases hr with r hr, exact (s.eq_circumcenter_of_dist_eq (centroid_mem_affine_span_of_card_eq_add_one ℝ _ (finset.card_fin 2)) (λ i, hr i (set.mem_univ _))).symm end /-- The orthogonal projection of a point `p` onto the hyperplane spanned by the simplex's points. -/ def orthogonal_projection_span {n : ℕ} (s : simplex ℝ P n) : P →ᵃ[ℝ] affine_span ℝ (set.range s.points) := orthogonal_projection (affine_span ℝ (set.range s.points)) /-- Adding a vector to a point in the given subspace, then taking the orthogonal projection, produces the original point if the vector is a multiple of the result of subtracting a point's orthogonal projection from that point. -/ lemma orthogonal_projection_vadd_smul_vsub_orthogonal_projection {n : ℕ} (s : simplex ℝ P n) {p1 : P} (p2 : P) (r : ℝ) (hp : p1 ∈ affine_span ℝ (set.range s.points)) : s.orthogonal_projection_span (r • (p2 -ᵥ s.orthogonal_projection_span p2 : V) +ᵥ p1) = ⟨p1, hp⟩ := orthogonal_projection_vadd_smul_vsub_orthogonal_projection _ _ _ lemma coe_orthogonal_projection_vadd_smul_vsub_orthogonal_projection {n : ℕ} {r₁ : ℝ} (s : simplex ℝ P n) {p p₁o : P} (hp₁o : p₁o ∈ affine_span ℝ (set.range s.points)) : ↑(s.orthogonal_projection_span (r₁ • (p -ᵥ ↑(s.orthogonal_projection_span p)) +ᵥ p₁o)) = p₁o := congr_arg coe (orthogonal_projection_vadd_smul_vsub_orthogonal_projection _ _ _ hp₁o) lemma dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq {n : ℕ} (s : simplex ℝ P n) {p1 : P} (p2 : P) (hp1 : p1 ∈ affine_span ℝ (set.range s.points)) : dist p1 p2 * dist p1 p2 = dist p1 (s.orthogonal_projection_span p2) * dist p1 (s.orthogonal_projection_span p2) + dist p2 (s.orthogonal_projection_span p2) * dist p2 (s.orthogonal_projection_span p2) := begin rw [pseudo_metric_space.dist_comm p2 _, dist_eq_norm_vsub V p1 _, dist_eq_norm_vsub V p1 _, dist_eq_norm_vsub V _ p2, ← vsub_add_vsub_cancel p1 (s.orthogonal_projection_span p2) p2, norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero], exact submodule.inner_right_of_mem_orthogonal (vsub_orthogonal_projection_mem_direction p2 hp1) (orthogonal_projection_vsub_mem_direction_orthogonal _ p2), end lemma dist_circumcenter_sq_eq_sq_sub_circumradius {n : ℕ} {r : ℝ} (s : simplex ℝ P n) {p₁ : P} (h₁ : ∀ (i : fin (n + 1)), dist (s.points i) p₁ = r) (h₁' : ↑((s.orthogonal_projection_span) p₁) = s.circumcenter) (h : s.points 0 ∈ affine_span ℝ (set.range s.points)) : dist p₁ s.circumcenter * dist p₁ s.circumcenter = r * r - s.circumradius * s.circumradius := begin rw [dist_comm, ←h₁ 0, s.dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq p₁ h], simp only [h₁', dist_comm p₁, add_sub_cancel', simplex.dist_circumcenter_eq_circumradius], end /-- If there exists a distance that a point has from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ lemma orthogonal_projection_eq_circumcenter_of_exists_dist_eq {n : ℕ} (s : simplex ℝ P n) {p : P} (hr : ∃ r, ∀ i, dist (s.points i) p = r) : ↑(s.orthogonal_projection_span p) = s.circumcenter := begin change ∃ r : ℝ, ∀ i, (λ x, dist x p = r) (s.points i) at hr, conv at hr { congr, funext, rw ←set.forall_range_iff }, rw exists_dist_eq_iff_exists_dist_orthogonal_projection_eq (subset_affine_span ℝ _) p at hr, cases hr with r hr, exact s.eq_circumcenter_of_dist_eq (orthogonal_projection_mem p) (λ i, hr _ (set.mem_range_self i)), end /-- If a point has the same distance from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ lemma orthogonal_projection_eq_circumcenter_of_dist_eq {n : ℕ} (s : simplex ℝ P n) {p : P} {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : ↑(s.orthogonal_projection_span p) = s.circumcenter := s.orthogonal_projection_eq_circumcenter_of_exists_dist_eq ⟨r, hr⟩ /-- The orthogonal projection of the circumcenter onto a face is the circumcenter of that face. -/ lemma orthogonal_projection_circumcenter {n : ℕ} (s : simplex ℝ P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : ↑((s.face h).orthogonal_projection_span s.circumcenter) = (s.face h).circumcenter := begin have hr : ∃ r, ∀ i, dist ((s.face h).points i) s.circumcenter = r, { use s.circumradius, simp [face_points] }, exact orthogonal_projection_eq_circumcenter_of_exists_dist_eq _ hr end /-- Two simplices with the same points have the same circumcenter. -/ lemma circumcenter_eq_of_range_eq {n : ℕ} {s₁ s₂ : simplex ℝ P n} (h : set.range s₁.points = set.range s₂.points) : s₁.circumcenter = s₂.circumcenter := begin have hs : s₁.circumcenter ∈ affine_span ℝ (set.range s₂.points) := h ▸ s₁.circumcenter_mem_affine_span, have hr : ∀ i, dist (s₂.points i) s₁.circumcenter = s₁.circumradius, { intro i, have hi : s₂.points i ∈ set.range s₂.points := set.mem_range_self _, rw [←h, set.mem_range] at hi, rcases hi with ⟨j, hj⟩, rw [←hj, s₁.dist_circumcenter_eq_circumradius j] }, exact s₂.eq_circumcenter_of_dist_eq hs hr end omit V /-- An index type for the vertices of a simplex plus its circumcenter. This is for use in calculations where it is convenient to work with affine combinations of vertices together with the circumcenter. (An equivalent form sometimes used in the literature is placing the circumcenter at the origin and working with vectors for the vertices.) -/ @[derive fintype] inductive points_with_circumcenter_index (n : ℕ) | point_index : fin (n + 1) → points_with_circumcenter_index | circumcenter_index : points_with_circumcenter_index open points_with_circumcenter_index instance points_with_circumcenter_index_inhabited (n : ℕ) : inhabited (points_with_circumcenter_index n) := ⟨circumcenter_index⟩ /-- `point_index` as an embedding. -/ def point_index_embedding (n : ℕ) : fin (n + 1) ↪ points_with_circumcenter_index n := ⟨λ i, point_index i, λ _ _ h, by injection h⟩ /-- The sum of a function over `points_with_circumcenter_index`. -/ lemma sum_points_with_circumcenter {α : Type*} [add_comm_monoid α] {n : ℕ} (f : points_with_circumcenter_index n → α) : ∑ i, f i = (∑ (i : fin (n + 1)), f (point_index i)) + f circumcenter_index := begin have h : univ = insert circumcenter_index (univ.map (point_index_embedding n)), { ext x, refine ⟨λ h, _, λ _, mem_univ _⟩, cases x with i, { exact mem_insert_of_mem (mem_map_of_mem _ (mem_univ i)) }, { exact mem_insert_self _ _ } }, change _ = ∑ i, f (point_index_embedding n i) + _, rw [add_comm, h, ←sum_map, sum_insert], simp_rw [finset.mem_map, not_exists], intros x hx h, injection h end include V /-- The vertices of a simplex plus its circumcenter. -/ def points_with_circumcenter {n : ℕ} (s : simplex ℝ P n) : points_with_circumcenter_index n → P | (point_index i) := s.points i | circumcenter_index := s.circumcenter /-- `points_with_circumcenter`, applied to a `point_index` value, equals `points` applied to that value. -/ @[simp] lemma points_with_circumcenter_point {n : ℕ} (s : simplex ℝ P n) (i : fin (n + 1)) : s.points_with_circumcenter (point_index i) = s.points i := rfl /-- `points_with_circumcenter`, applied to `circumcenter_index`, equals the circumcenter. -/ @[simp] lemma points_with_circumcenter_eq_circumcenter {n : ℕ} (s : simplex ℝ P n) : s.points_with_circumcenter circumcenter_index = s.circumcenter := rfl omit V /-- The weights for a single vertex of a simplex, in terms of `points_with_circumcenter`. -/ def point_weights_with_circumcenter {n : ℕ} (i : fin (n + 1)) : points_with_circumcenter_index n → ℝ | (point_index j) := if j = i then 1 else 0 | circumcenter_index := 0 /-- `point_weights_with_circumcenter` sums to 1. -/ @[simp] lemma sum_point_weights_with_circumcenter {n : ℕ} (i : fin (n + 1)) : ∑ j, point_weights_with_circumcenter i j = 1 := begin convert sum_ite_eq' univ (point_index i) (function.const _ (1 : ℝ)), { ext j, cases j ; simp [point_weights_with_circumcenter] }, { simp } end include V /-- A single vertex, in terms of `points_with_circumcenter`. -/ lemma point_eq_affine_combination_of_points_with_circumcenter {n : ℕ} (s : simplex ℝ P n) (i : fin (n + 1)) : s.points i = (univ : finset (points_with_circumcenter_index n)).affine_combination s.points_with_circumcenter (point_weights_with_circumcenter i) := begin rw ←points_with_circumcenter_point, symmetry, refine affine_combination_of_eq_one_of_eq_zero _ _ _ (mem_univ _) (by simp [point_weights_with_circumcenter]) _, intros i hi hn, cases i, { have h : i_1 ≠ i := λ h, hn (h ▸ rfl), simp [point_weights_with_circumcenter, h] }, { refl } end omit V /-- The weights for the centroid of some vertices of a simplex, in terms of `points_with_circumcenter`. -/ def centroid_weights_with_circumcenter {n : ℕ} (fs : finset (fin (n + 1))) : points_with_circumcenter_index n → ℝ | (point_index i) := if i ∈ fs then ((card fs : ℝ) ⁻¹) else 0 | circumcenter_index := 0 /-- `centroid_weights_with_circumcenter` sums to 1, if the `finset` is nonempty. -/ @[simp] lemma sum_centroid_weights_with_circumcenter {n : ℕ} {fs : finset (fin (n + 1))} (h : fs.nonempty) : ∑ i, centroid_weights_with_circumcenter fs i = 1 := begin simp_rw [sum_points_with_circumcenter, centroid_weights_with_circumcenter, add_zero, ←fs.sum_centroid_weights_eq_one_of_nonempty ℝ h, set.sum_indicator_subset _ fs.subset_univ], rcongr end include V /-- The centroid of some vertices of a simplex, in terms of `points_with_circumcenter`. -/ lemma centroid_eq_affine_combination_of_points_with_circumcenter {n : ℕ} (s : simplex ℝ P n) (fs : finset (fin (n + 1))) : fs.centroid ℝ s.points = (univ : finset (points_with_circumcenter_index n)).affine_combination s.points_with_circumcenter (centroid_weights_with_circumcenter fs) := begin simp_rw [centroid_def, affine_combination_apply, weighted_vsub_of_point_apply, sum_points_with_circumcenter, centroid_weights_with_circumcenter, points_with_circumcenter_point, zero_smul, add_zero, centroid_weights, set.sum_indicator_subset_of_eq_zero (function.const (fin (n + 1)) ((card fs : ℝ)⁻¹)) (λ i wi, wi • (s.points i -ᵥ classical.choice add_torsor.nonempty)) fs.subset_univ (λ i, zero_smul ℝ _), set.indicator_apply], congr, end omit V /-- The weights for the circumcenter of a simplex, in terms of `points_with_circumcenter`. -/ def circumcenter_weights_with_circumcenter (n : ℕ) : points_with_circumcenter_index n → ℝ | (point_index i) := 0 | circumcenter_index := 1 /-- `circumcenter_weights_with_circumcenter` sums to 1. -/ @[simp] lemma sum_circumcenter_weights_with_circumcenter (n : ℕ) : ∑ i, circumcenter_weights_with_circumcenter n i = 1 := begin convert sum_ite_eq' univ circumcenter_index (function.const _ (1 : ℝ)), { ext ⟨j⟩ ; simp [circumcenter_weights_with_circumcenter] }, { simp } end include V /-- The circumcenter of a simplex, in terms of `points_with_circumcenter`. -/ lemma circumcenter_eq_affine_combination_of_points_with_circumcenter {n : ℕ} (s : simplex ℝ P n) : s.circumcenter = (univ : finset (points_with_circumcenter_index n)).affine_combination s.points_with_circumcenter (circumcenter_weights_with_circumcenter n) := begin rw ←points_with_circumcenter_eq_circumcenter, symmetry, refine affine_combination_of_eq_one_of_eq_zero _ _ _ (mem_univ _) rfl _, rintros ⟨i⟩ hi hn ; tauto end omit V /-- The weights for the reflection of the circumcenter in an edge of a simplex. This definition is only valid with `i₁ ≠ i₂`. -/ def reflection_circumcenter_weights_with_circumcenter {n : ℕ} (i₁ i₂ : fin (n + 1)) : points_with_circumcenter_index n → ℝ | (point_index i) := if i = i₁ ∨ i = i₂ then 1 else 0 | circumcenter_index := -1 /-- `reflection_circumcenter_weights_with_circumcenter` sums to 1. -/ @[simp] lemma sum_reflection_circumcenter_weights_with_circumcenter {n : ℕ} {i₁ i₂ : fin (n + 1)} (h : i₁ ≠ i₂) : ∑ i, reflection_circumcenter_weights_with_circumcenter i₁ i₂ i = 1 := begin simp_rw [sum_points_with_circumcenter, reflection_circumcenter_weights_with_circumcenter, sum_ite, sum_const, filter_or, filter_eq'], rw card_union_eq, { simp }, { simpa only [if_true, mem_univ, disjoint_singleton] using h } end include V /-- The reflection of the circumcenter of a simplex in an edge, in terms of `points_with_circumcenter`. -/ lemma reflection_circumcenter_eq_affine_combination_of_points_with_circumcenter {n : ℕ} (s : simplex ℝ P n) {i₁ i₂ : fin (n + 1)} (h : i₁ ≠ i₂) : reflection (affine_span ℝ (s.points '' {i₁, i₂})) s.circumcenter = (univ : finset (points_with_circumcenter_index n)).affine_combination s.points_with_circumcenter (reflection_circumcenter_weights_with_circumcenter i₁ i₂) := begin have hc : card ({i₁, i₂} : finset (fin (n + 1))) = 2, { simp [h] }, -- Making the next line a separate definition helps the elaborator: set W : affine_subspace ℝ P := affine_span ℝ (s.points '' {i₁, i₂}) with W_def, have h_faces : ↑(orthogonal_projection W s.circumcenter) = ↑((s.face hc).orthogonal_projection_span s.circumcenter), { apply eq_orthogonal_projection_of_eq_subspace, simp }, rw [euclidean_geometry.reflection_apply, h_faces, s.orthogonal_projection_circumcenter hc, circumcenter_eq_centroid, s.face_centroid_eq_centroid hc, centroid_eq_affine_combination_of_points_with_circumcenter, circumcenter_eq_affine_combination_of_points_with_circumcenter, ←@vsub_eq_zero_iff_eq V, affine_combination_vsub, weighted_vsub_vadd_affine_combination, affine_combination_vsub, weighted_vsub_apply, sum_points_with_circumcenter], simp_rw [pi.sub_apply, pi.add_apply, pi.sub_apply, sub_smul, add_smul, sub_smul, centroid_weights_with_circumcenter, circumcenter_weights_with_circumcenter, reflection_circumcenter_weights_with_circumcenter, ite_smul, zero_smul, sub_zero, apply_ite2 (+), add_zero, ←add_smul, hc, zero_sub, neg_smul, sub_self, add_zero], convert sum_const_zero, norm_num end end simplex end affine namespace euclidean_geometry open affine affine_subspace finite_dimensional variables {V : Type*} {P : Type*} [inner_product_space ℝ V] [metric_space P] [normed_add_torsor V P] include V /-- Given a nonempty affine subspace, whose direction is complete, that contains a set of points, those points are cospherical if and only if they are equidistant from some point in that subspace. -/ lemma cospherical_iff_exists_mem_of_complete {s : affine_subspace ℝ P} {ps : set P} (h : ps ⊆ s) [nonempty s] [complete_space s.direction] : cospherical ps ↔ ∃ (center ∈ s) (radius : ℝ), ∀ p ∈ ps, dist p center = radius := begin split, { rintro ⟨c, hcr⟩, rw exists_dist_eq_iff_exists_dist_orthogonal_projection_eq h c at hcr, exact ⟨orthogonal_projection s c, orthogonal_projection_mem _, hcr⟩ }, { exact λ ⟨c, hc, hd⟩, ⟨c, hd⟩ } end /-- Given a nonempty affine subspace, whose direction is finite-dimensional, that contains a set of points, those points are cospherical if and only if they are equidistant from some point in that subspace. -/ lemma cospherical_iff_exists_mem_of_finite_dimensional {s : affine_subspace ℝ P} {ps : set P} (h : ps ⊆ s) [nonempty s] [finite_dimensional ℝ s.direction] : cospherical ps ↔ ∃ (center ∈ s) (radius : ℝ), ∀ p ∈ ps, dist p center = radius := cospherical_iff_exists_mem_of_complete h /-- All n-simplices among cospherical points in an n-dimensional subspace have the same circumradius. -/ lemma exists_circumradius_eq_of_cospherical_subset {s : affine_subspace ℝ P} {ps : set P} (h : ps ⊆ s) [nonempty s] {n : ℕ} [finite_dimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : cospherical ps) : ∃ r : ℝ, ∀ sx : simplex ℝ P n, set.range sx.points ⊆ ps → sx.circumradius = r := begin rw cospherical_iff_exists_mem_of_finite_dimensional h at hc, rcases hc with ⟨c, hc, r, hcr⟩, use r, intros sx hsxps, have hsx : affine_span ℝ (set.range sx.points) = s, { refine sx.independent.affine_span_eq_of_le_of_card_eq_finrank_add_one (span_points_subset_coe_of_subset_coe (hsxps.trans h)) _, simp [hd] }, have hc : c ∈ affine_span ℝ (set.range sx.points) := hsx.symm ▸ hc, exact (sx.eq_circumradius_of_dist_eq hc (λ i, hcr (sx.points i) (hsxps (set.mem_range_self i)))).symm end /-- Two n-simplices among cospherical points in an n-dimensional subspace have the same circumradius. -/ lemma circumradius_eq_of_cospherical_subset {s : affine_subspace ℝ P} {ps : set P} (h : ps ⊆ s) [nonempty s] {n : ℕ} [finite_dimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : cospherical ps) {sx₁ sx₂ : simplex ℝ P n} (hsx₁ : set.range sx₁.points ⊆ ps) (hsx₂ : set.range sx₂.points ⊆ ps) : sx₁.circumradius = sx₂.circumradius := begin rcases exists_circumradius_eq_of_cospherical_subset h hd hc with ⟨r, hr⟩, rw [hr sx₁ hsx₁, hr sx₂ hsx₂] end /-- All n-simplices among cospherical points in n-space have the same circumradius. -/ lemma exists_circumradius_eq_of_cospherical {ps : set P} {n : ℕ} [finite_dimensional ℝ V] (hd : finrank ℝ V = n) (hc : cospherical ps) : ∃ r : ℝ, ∀ sx : simplex ℝ P n, set.range sx.points ⊆ ps → sx.circumradius = r := begin haveI : nonempty (⊤ : affine_subspace ℝ P) := set.univ.nonempty, rw [←finrank_top, ←direction_top ℝ V P] at hd, refine exists_circumradius_eq_of_cospherical_subset _ hd hc, exact set.subset_univ _ end /-- Two n-simplices among cospherical points in n-space have the same circumradius. -/ lemma circumradius_eq_of_cospherical {ps : set P} {n : ℕ} [finite_dimensional ℝ V] (hd : finrank ℝ V = n) (hc : cospherical ps) {sx₁ sx₂ : simplex ℝ P n} (hsx₁ : set.range sx₁.points ⊆ ps) (hsx₂ : set.range sx₂.points ⊆ ps) : sx₁.circumradius = sx₂.circumradius := begin rcases exists_circumradius_eq_of_cospherical hd hc with ⟨r, hr⟩, rw [hr sx₁ hsx₁, hr sx₂ hsx₂] end /-- All n-simplices among cospherical points in an n-dimensional subspace have the same circumcenter. -/ lemma exists_circumcenter_eq_of_cospherical_subset {s : affine_subspace ℝ P} {ps : set P} (h : ps ⊆ s) [nonempty s] {n : ℕ} [finite_dimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : cospherical ps) : ∃ c : P, ∀ sx : simplex ℝ P n, set.range sx.points ⊆ ps → sx.circumcenter = c := begin rw cospherical_iff_exists_mem_of_finite_dimensional h at hc, rcases hc with ⟨c, hc, r, hcr⟩, use c, intros sx hsxps, have hsx : affine_span ℝ (set.range sx.points) = s, { refine sx.independent.affine_span_eq_of_le_of_card_eq_finrank_add_one (span_points_subset_coe_of_subset_coe (hsxps.trans h)) _, simp [hd] }, have hc : c ∈ affine_span ℝ (set.range sx.points) := hsx.symm ▸ hc, exact (sx.eq_circumcenter_of_dist_eq hc (λ i, hcr (sx.points i) (hsxps (set.mem_range_self i)))).symm end /-- Two n-simplices among cospherical points in an n-dimensional subspace have the same circumcenter. -/ lemma circumcenter_eq_of_cospherical_subset {s : affine_subspace ℝ P} {ps : set P} (h : ps ⊆ s) [nonempty s] {n : ℕ} [finite_dimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : cospherical ps) {sx₁ sx₂ : simplex ℝ P n} (hsx₁ : set.range sx₁.points ⊆ ps) (hsx₂ : set.range sx₂.points ⊆ ps) : sx₁.circumcenter = sx₂.circumcenter := begin rcases exists_circumcenter_eq_of_cospherical_subset h hd hc with ⟨r, hr⟩, rw [hr sx₁ hsx₁, hr sx₂ hsx₂] end /-- All n-simplices among cospherical points in n-space have the same circumcenter. -/ lemma exists_circumcenter_eq_of_cospherical {ps : set P} {n : ℕ} [finite_dimensional ℝ V] (hd : finrank ℝ V = n) (hc : cospherical ps) : ∃ c : P, ∀ sx : simplex ℝ P n, set.range sx.points ⊆ ps → sx.circumcenter = c := begin haveI : nonempty (⊤ : affine_subspace ℝ P) := set.univ.nonempty, rw [←finrank_top, ←direction_top ℝ V P] at hd, refine exists_circumcenter_eq_of_cospherical_subset _ hd hc, exact set.subset_univ _ end /-- Two n-simplices among cospherical points in n-space have the same circumcenter. -/ lemma circumcenter_eq_of_cospherical {ps : set P} {n : ℕ} [finite_dimensional ℝ V] (hd : finrank ℝ V = n) (hc : cospherical ps) {sx₁ sx₂ : simplex ℝ P n} (hsx₁ : set.range sx₁.points ⊆ ps) (hsx₂ : set.range sx₂.points ⊆ ps) : sx₁.circumcenter = sx₂.circumcenter := begin rcases exists_circumcenter_eq_of_cospherical hd hc with ⟨r, hr⟩, rw [hr sx₁ hsx₁, hr sx₂ hsx₂] end /-- Suppose all distances from `p₁` and `p₂` to the points of a simplex are equal, and that `p₁` and `p₂` lie in the affine span of `p` with the vertices of that simplex. Then `p₁` and `p₂` are equal or reflections of each other in the affine span of the vertices of the simplex. -/ lemma eq_or_eq_reflection_of_dist_eq {n : ℕ} {s : simplex ℝ P n} {p p₁ p₂ : P} {r : ℝ} (hp₁ : p₁ ∈ affine_span ℝ (insert p (set.range s.points))) (hp₂ : p₂ ∈ affine_span ℝ (insert p (set.range s.points))) (h₁ : ∀ i, dist (s.points i) p₁ = r) (h₂ : ∀ i, dist (s.points i) p₂ = r) : p₁ = p₂ ∨ p₁ = reflection (affine_span ℝ (set.range s.points)) p₂ := begin let span_s := affine_span ℝ (set.range s.points), have h₁' := s.orthogonal_projection_eq_circumcenter_of_dist_eq h₁, have h₂' := s.orthogonal_projection_eq_circumcenter_of_dist_eq h₂, rw [←affine_span_insert_affine_span, mem_affine_span_insert_iff (orthogonal_projection_mem p)] at hp₁ hp₂, obtain ⟨r₁, p₁o, hp₁o, hp₁⟩ := hp₁, obtain ⟨r₂, p₂o, hp₂o, hp₂⟩ := hp₂, obtain rfl : ↑(s.orthogonal_projection_span p₁) = p₁o, { subst hp₁, exact s.coe_orthogonal_projection_vadd_smul_vsub_orthogonal_projection hp₁o }, rw h₁' at hp₁, obtain rfl : ↑(s.orthogonal_projection_span p₂) = p₂o, { subst hp₂, exact s.coe_orthogonal_projection_vadd_smul_vsub_orthogonal_projection hp₂o }, rw h₂' at hp₂, have h : s.points 0 ∈ span_s := mem_affine_span ℝ (set.mem_range_self _), have hd₁ : dist p₁ s.circumcenter * dist p₁ s.circumcenter = r * r - s.circumradius * s.circumradius := s.dist_circumcenter_sq_eq_sq_sub_circumradius h₁ h₁' h, have hd₂ : dist p₂ s.circumcenter * dist p₂ s.circumcenter = r * r - s.circumradius * s.circumradius := s.dist_circumcenter_sq_eq_sq_sub_circumradius h₂ h₂' h, rw [←hd₂, hp₁, hp₂, dist_eq_norm_vsub V _ s.circumcenter, dist_eq_norm_vsub V _ s.circumcenter, vadd_vsub, vadd_vsub, ←real_inner_self_eq_norm_mul_norm, ←real_inner_self_eq_norm_mul_norm, real_inner_smul_left, real_inner_smul_left, real_inner_smul_right, real_inner_smul_right, ←mul_assoc, ←mul_assoc] at hd₁, by_cases hp : p = s.orthogonal_projection_span p, { rw simplex.orthogonal_projection_span at hp, rw [hp₁, hp₂, ←hp], simp only [true_or, eq_self_iff_true, smul_zero, vsub_self] }, { have hz : ⟪p -ᵥ orthogonal_projection span_s p, p -ᵥ orthogonal_projection span_s p⟫ ≠ 0, by simpa only [ne.def, vsub_eq_zero_iff_eq, inner_self_eq_zero] using hp, rw [mul_left_inj' hz, mul_self_eq_mul_self_iff] at hd₁, rw [hp₁, hp₂], cases hd₁, { left, rw hd₁ }, { right, rw [hd₁, reflection_vadd_smul_vsub_orthogonal_projection p r₂ s.circumcenter_mem_affine_span, neg_smul] } } end end euclidean_geometry
3830f552c85f10eee3e7febc8611e2c035cb1a0f
4f9ca1935adf84f1bae9c5740ec1f2ad406716fa
/src/linear_algebra/basic.lean
55b0fdfd1da58dd2aef2a37fbe61a8d0fb7c8736
[ "Apache-2.0" ]
permissive
matthew-hilty/mathlib
36fd7db866365e9ee4a0ba1d6f8ad34d068cec6c
585e107f9811719832c6656f49e1263a8eef5380
refs/heads/master
1,607,100,509,178
1,578,151,707,000
1,578,151,707,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
71,966
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, Kevin Buzzard -/ import algebra.pi_instances data.finsupp data.equiv.algebra order.order_iso /-! # Linear algebra This file defines the basics of linear algebra. It sets up the "categorical/lattice structure" of modules over a ring, submodules, and linear maps. If `p` and `q` are submodules of a module, `p ≤ q` means that `p ⊆ q`. Many of the relevant definitions, including `module`, `submodule`, and `linear_map`, are found in `src/algebra/module.lean`. ## Main definitions * Many constructors for linear maps, including `pair` and `copair` * `submodule.span s` is defined to be the smallest submodule containing the set `s`. * If `p` is a submodule of `M`, `submodule.quotient p` is the quotient of `M` with respect to `p`: that is, elements of `M` are identified if their difference is in `p`. This is itself a module. * The kernel `ker` and range `range` of a linear map are submodules of the domain and codomain respectively. * `linear_equiv M M₂`, the type of linear equivalences between `M` and `M₂`, is a structure that extends `linear_map` and `equiv`. * The general linear group is defined to be the group of invertible linear maps from `M` to itself. ## Main statements * The first and second isomorphism laws for modules are proved as `quot_ker_equiv_range` and `sup_quotient_equiv_quotient_inf`. ## Notations * We continue to use the notation `M →ₗ[R] M₂` for the type of linear maps from `M` to `M₂` over the ring `R`. * We introduce the notations `M ≃ₗ M₂` and `M ≃ₗ[R] M₂` for `linear_equiv M M₂`. In the first, the ring `R` is implicit. ## Implementation notes We note that, when constructing linear maps, it is convenient to use operations defined on bundled maps (`pair`, `copair`, arithmetic operations like `+`) instead of defining a function and proving it is linear. ## Tags linear algebra, vector space, module -/ open function lattice reserve infix ` ≃ₗ `:25 universes u v w x y z u' v' w' y' variables {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'} variables {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x} namespace finset lemma smul_sum {α : Type u} {M : Type v} {R : Type w} [ring R] [add_comm_group M] [module R M] {s : finset α} {a : R} {f : α → M} : a • (s.sum f) = s.sum (λc, a • f c) := (s.sum_hom ((•) a)).symm lemma smul_sum' {α : Type u} {M : Type v} {R : Type w} [ring R] [add_comm_group M] [module R M] {s : finset α} {f : α → R} {x : M} : (s.sum f) • x = s.sum (λa, (f a) • x) := begin -- TODO : where should I put this instance? haveI : is_add_monoid_hom (λ (r : R), r • x) := { map_add := λ a b, add_smul _ _ _, map_zero := zero_smul _ _ }, exact (s.sum_hom (λ (r : R), r • x)).symm end end finset namespace finsupp lemma smul_sum {α : Type u} {β : Type v} {R : Type w} {M : Type y} [has_zero β] [ring R] [add_comm_group M] [module R M] {v : α →₀ β} {c : R} {h : α → β → M} : c • (v.sum h) = v.sum (λa b, c • h a b) := finset.smul_sum end finsupp section open_locale classical /-- decomposing `x : ι → R` as a sum along the canonical basis -/ lemma pi_eq_sum_univ {ι : Type u} [fintype ι] {R : Type v} [semiring R] (x : ι → R) : x = finset.sum finset.univ (λi:ι, x i • (λj, if i = j then 1 else 0)) := begin ext k, rw pi.finset_sum_apply, have : finset.sum finset.univ (λ (x_1 : ι), x x_1 * ite (k = x_1) 1 0) = x k, by { have := finset.sum_mul_boole finset.univ x k, rwa if_pos (finset.mem_univ _) at this }, rw ← this, apply finset.sum_congr rfl (λl hl, _), simp only [smul_eq_mul, mul_ite, pi.smul_apply], conv_lhs { rw eq_comm } end end namespace linear_map section variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] [add_comm_group M₄] variables [module R M] [module R M₂] [module R M₃] [module R M₄] variables (f g : M →ₗ[R] M₂) include R @[simp] theorem comp_id : f.comp id = f := linear_map.ext $ λ x, rfl @[simp] theorem id_comp : id.comp f = f := linear_map.ext $ λ x, rfl theorem comp_assoc (g : M₂ →ₗ[R] M₃) (h : M₃ →ₗ[R] M₄) : (h.comp g).comp f = h.comp (g.comp f) := rfl /-- A linear map `f : M₂ → M` whose values lie in a submodule `p ⊆ M` can be restricted to a linear map M₂ → p. -/ def cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (h : ∀c, f c ∈ p) : M₂ →ₗ[R] p := by refine {to_fun := λc, ⟨f c, h c⟩, ..}; intros; apply set_coe.ext; simp @[simp] theorem cod_restrict_apply (p : submodule R M) (f : M₂ →ₗ[R] M) {h} (x : M₂) : (cod_restrict p f h x : M) = f x := rfl @[simp] lemma comp_cod_restrict (p : submodule R M₂) (h : ∀b, f b ∈ p) (g : M₃ →ₗ[R] M) : (cod_restrict p f h).comp g = cod_restrict p (f.comp g) (assume b, h _) := ext $ assume b, rfl @[simp] lemma subtype_comp_cod_restrict (p : submodule R M₂) (h : ∀b, f b ∈ p) : p.subtype.comp (cod_restrict p f h) = f := ext $ assume b, rfl /-- If a function `g` is a left and right inverse of a linear map `f`, then `g` is linear itself. -/ def inverse (g : M₂ → M) (h₁ : left_inverse g f) (h₂ : right_inverse g f) : M₂ →ₗ[R] M := by dsimp [left_inverse, function.right_inverse] at h₁ h₂; exact ⟨g, λ x y, by rw [← h₁ (g (x + y)), ← h₁ (g x + g y)]; simp [h₂], λ a b, by rw [← h₁ (g (a • b)), ← h₁ (a • g b)]; simp [h₂]⟩ /-- The constant 0 map is linear. -/ instance : has_zero (M →ₗ[R] M₂) := ⟨⟨λ _, 0, by simp, by simp⟩⟩ @[simp] lemma zero_apply (x : M) : (0 : M →ₗ[R] M₂) x = 0 := rfl /-- The negation of a linear map is linear. -/ instance : has_neg (M →ₗ[R] M₂) := ⟨λ f, ⟨λ b, - f b, by simp, by simp⟩⟩ @[simp] lemma neg_apply (x : M) : (- f) x = - f x := rfl /-- The sum of two linear maps is linear. -/ instance : has_add (M →ₗ[R] M₂) := ⟨λ f g, ⟨λ b, f b + g b, by simp, by simp [smul_add]⟩⟩ @[simp] lemma add_apply (x : M) : (f + g) x = f x + g x := rfl /-- The type of linear maps is an additive group. -/ instance : add_comm_group (M →ₗ[R] M₂) := by refine {zero := 0, add := (+), neg := has_neg.neg, ..}; intros; ext; simp instance linear_map.is_add_group_hom : is_add_group_hom f := { map_add := f.add } instance linear_map_apply_is_add_group_hom (a : M) : is_add_group_hom (λ f : M →ₗ[R] M₂, f a) := { map_add := λ f g, linear_map.add_apply f g a } lemma sum_apply (t : finset ι) (f : ι → M →ₗ[R] M₂) (b : M) : t.sum f b = t.sum (λd, f d b) := (t.sum_hom (λ g : M →ₗ[R] M₂, g b)).symm @[simp] lemma sub_apply (x : M) : (f - g) x = f x - g x := rfl /-- `λb, f b • x` is a linear map. -/ def smul_right (f : M₂ →ₗ[R] R) (x : M) : M₂ →ₗ[R] M := ⟨λb, f b • x, by simp [add_smul], by simp [smul_smul]⟩. @[simp] theorem smul_right_apply (f : M₂ →ₗ[R] R) (x : M) (c : M₂) : (smul_right f x : M₂ → M) c = f c • x := rfl instance : has_one (M →ₗ[R] M) := ⟨linear_map.id⟩ instance : has_mul (M →ₗ[R] M) := ⟨linear_map.comp⟩ @[simp] lemma one_app (x : M) : (1 : M →ₗ[R] M) x = x := rfl @[simp] lemma mul_app (A B : M →ₗ[R] M) (x : M) : (A * B) x = A (B x) := rfl @[simp] theorem comp_zero : f.comp (0 : M₃ →ₗ[R] M) = 0 := ext $ assume c, by rw [comp_apply, zero_apply, zero_apply, f.map_zero] @[simp] theorem zero_comp : (0 : M₂ →ₗ[R] M₃).comp f = 0 := rfl section variables (R M) include M instance endomorphism_ring : ring (M →ₗ[R] M) := by refine {mul := (*), one := 1, ..linear_map.add_comm_group, ..}; { intros, apply linear_map.ext, simp } end section open_locale classical /-- A linear map `f` applied to `x : ι → R` can be computed using the image under `f` of elements of the canonical basis. -/ lemma pi_apply_eq_sum_univ [fintype ι] (f : (ι → R) →ₗ[R] M) (x : ι → R) : f x = finset.sum finset.univ (λi:ι, x i • (f (λj, if i = j then 1 else 0))) := begin conv_lhs { rw [pi_eq_sum_univ x, f.map_sum] }, apply finset.sum_congr rfl (λl hl, _), rw f.map_smul end end section variables (R M M₂) /-- The first projection of a product is a linear map. -/ def fst : M × M₂ →ₗ[R] M := ⟨prod.fst, λ x y, rfl, λ x y, rfl⟩ /-- The second projection of a product is a linear map. -/ def snd : M × M₂ →ₗ[R] M₂ := ⟨prod.snd, λ x y, rfl, λ x y, rfl⟩ end @[simp] theorem fst_apply (x : M × M₂) : fst R M M₂ x = x.1 := rfl @[simp] theorem snd_apply (x : M × M₂) : snd R M M₂ x = x.2 := rfl /-- The pair of two linear maps is a linear map. -/ def pair (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : M →ₗ[R] M₂ × M₃ := ⟨λ x, (f x, g x), λ x y, by simp, λ x y, by simp⟩ @[simp] theorem pair_apply (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) (x : M) : pair f g x = (f x, g x) := rfl @[simp] theorem fst_pair (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (fst R M₂ M₃).comp (pair f g) = f := by ext; refl @[simp] theorem snd_pair (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (snd R M₂ M₃).comp (pair f g) = g := by ext; refl @[simp] theorem pair_fst_snd : pair (fst R M M₂) (snd R M M₂) = linear_map.id := by ext; refl section variables (R M M₂) /-- The left injection into a product is a linear map. -/ def inl : M →ₗ[R] M × M₂ := by refine ⟨prod.inl, _, _⟩; intros; simp [prod.inl] /-- The right injection into a product is a linear map. -/ def inr : M₂ →ₗ[R] M × M₂ := by refine ⟨prod.inr, _, _⟩; intros; simp [prod.inr] end @[simp] theorem inl_apply (x : M) : inl R M M₂ x = (x, 0) := rfl @[simp] theorem inr_apply (x : M₂) : inr R M M₂ x = (0, x) := rfl /-- The copair function `λ x : M × M₂, f x.1 + g x.2` is a linear map. -/ def copair (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : M × M₂ →ₗ[R] M₃ := ⟨λ x, f x.1 + g x.2, λ x y, by simp, λ x y, by simp [smul_add]⟩ @[simp] theorem copair_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (x : M) (y : M₂) : copair f g (x, y) = f x + g y := rfl @[simp] theorem copair_inl (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (copair f g).comp (inl R M M₂) = f := by ext; simp @[simp] theorem copair_inr (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (copair f g).comp (inr R M M₂) = g := by ext; simp @[simp] theorem copair_inl_inr : copair (inl R M M₂) (inr R M M₂) = linear_map.id := by ext ⟨x, y⟩; simp theorem fst_eq_copair : fst R M M₂ = copair linear_map.id 0 := by ext ⟨x, y⟩; simp theorem snd_eq_copair : snd R M M₂ = copair 0 linear_map.id := by ext ⟨x, y⟩; simp theorem inl_eq_pair : inl R M M₂ = pair linear_map.id 0 := rfl theorem inr_eq_pair : inr R M M₂ = pair 0 linear_map.id := rfl end section comm_ring variables [comm_ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [module R M] [module R M₂] [module R M₃] variables (f g : M →ₗ[R] M₂) include R instance : has_scalar R (M →ₗ[R] M₂) := ⟨λ a f, ⟨λ b, a • f b, by simp [smul_add], by simp [smul_smul, mul_comm]⟩⟩ @[simp] lemma smul_apply (a : R) (x : M) : (a • f) x = a • f x := rfl instance : module R (M →ₗ[R] M₂) := module.of_core $ by refine { smul := (•), ..}; intros; ext; simp [smul_add, add_smul, smul_smul] /-- Composition by `f : M₂ → M₃` is a linear map from the space of linear maps `M → M₂` to the space of linear maps `M₂ → M₃`. -/ def congr_right (f : M₂ →ₗ[R] M₃) : (M →ₗ[R] M₂) →ₗ[R] (M →ₗ[R] M₃) := ⟨linear_map.comp f, λ _ _, linear_map.ext $ λ _, f.2 _ _, λ _ _, linear_map.ext $ λ _, f.3 _ _⟩ theorem smul_comp (g : M₂ →ₗ[R] M₃) (a : R) : (a • g).comp f = a • (g.comp f) := rfl theorem comp_smul (g : M₂ →ₗ[R] M₃) (a : R) : g.comp (a • f) = a • (g.comp f) := ext $ assume b, by rw [comp_apply, smul_apply, g.map_smul]; refl end comm_ring end linear_map namespace submodule variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [module R M] [module R M₂] [module R M₃] variables (p p' : submodule R M) (q q' : submodule R M₂) variables {r : R} {x y : M} open set lattice instance : partial_order (submodule R M) := partial_order.lift (coe : submodule R M → set M) (λ a b, ext') (by apply_instance) lemma le_def {p p' : submodule R M} : p ≤ p' ↔ (p : set M) ⊆ p' := iff.rfl lemma le_def' {p p' : submodule R M} : p ≤ p' ↔ ∀ x ∈ p, x ∈ p' := iff.rfl /-- If two submodules p and p' satisfy p ⊆ p', then `of_le p p'` is the linear map version of this inclusion. -/ def of_le {p p' : submodule R M} (h : p ≤ p') : p →ₗ[R] p' := linear_map.cod_restrict _ p.subtype $ λ ⟨x, hx⟩, h hx @[simp] theorem of_le_apply {p p' : submodule R M} (h : p ≤ p') (x : p) : (of_le h x : M) = x := rfl lemma subtype_comp_of_le (p q : submodule R M) (h : p ≤ q) : (submodule.subtype q).comp (of_le h) = submodule.subtype p := by ext ⟨b, hb⟩; simp /-- The set `{0}` is the bottom element of the lattice of submodules. -/ instance : has_bot (submodule R M) := ⟨by split; try {exact {0}}; simp {contextual := tt}⟩ @[simp] lemma bot_coe : ((⊥ : submodule R M) : set M) = {0} := rfl section variables (R) @[simp] lemma mem_bot : x ∈ (⊥ : submodule R M) ↔ x = 0 := mem_singleton_iff end instance : order_bot (submodule R M) := { bot := ⊥, bot_le := λ p x, by simp {contextual := tt}, ..submodule.partial_order } /-- The universal set is the top element of the lattice of submodules. -/ instance : has_top (submodule R M) := ⟨by split; try {exact set.univ}; simp⟩ @[simp] lemma top_coe : ((⊤ : submodule R M) : set M) = univ := rfl @[simp] lemma mem_top : x ∈ (⊤ : submodule R M) := trivial lemma eq_bot_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : p = ⊥ := by ext x; simp [semimodule.eq_zero_of_zero_eq_one _ x zero_eq_one] instance : order_top (submodule R M) := { top := ⊤, le_top := λ p x _, trivial, ..submodule.partial_order } instance : has_Inf (submodule R M) := ⟨λ S, { carrier := ⋂ s ∈ S, ↑s, zero := by simp, add := by simp [add_mem] {contextual := tt}, smul := by simp [smul_mem] {contextual := tt} }⟩ private lemma Inf_le' {S : set (submodule R M)} {p} : p ∈ S → Inf S ≤ p := bInter_subset_of_mem private lemma le_Inf' {S : set (submodule R M)} {p} : (∀p' ∈ S, p ≤ p') → p ≤ Inf S := subset_bInter instance : has_inf (submodule R M) := ⟨λ p p', { carrier := p ∩ p', zero := by simp, add := by simp [add_mem] {contextual := tt}, smul := by simp [smul_mem] {contextual := tt} }⟩ instance : complete_lattice (submodule R M) := { sup := λ a b, Inf {x | a ≤ x ∧ b ≤ x}, le_sup_left := λ a b, le_Inf' $ λ x ⟨ha, hb⟩, ha, le_sup_right := λ a b, le_Inf' $ λ x ⟨ha, hb⟩, hb, sup_le := λ a b c h₁ h₂, Inf_le' ⟨h₁, h₂⟩, inf := (⊓), le_inf := λ a b c, subset_inter, inf_le_left := λ a b, inter_subset_left _ _, inf_le_right := λ a b, inter_subset_right _ _, Sup := λtt, Inf {t | ∀t'∈tt, t' ≤ t}, le_Sup := λ s p hs, le_Inf' $ λ p' hp', hp' _ hs, Sup_le := λ s p hs, Inf_le' hs, Inf := Inf, le_Inf := λ s a, le_Inf', Inf_le := λ s a, Inf_le', ..submodule.lattice.order_top, ..submodule.lattice.order_bot } instance : add_comm_monoid (submodule R M) := { add := (⊔), add_assoc := λ _ _ _, sup_assoc, zero := ⊥, zero_add := λ _, bot_sup_eq, add_zero := λ _, sup_bot_eq, add_comm := λ _ _, sup_comm } @[simp] lemma add_eq_sup (p q : submodule R M) : p + q = p ⊔ q := rfl @[simp] lemma zero_eq_bot : (0 : submodule R M) = ⊥ := rfl lemma eq_top_iff' {p : submodule R M} : p = ⊤ ↔ ∀ x, x ∈ p := eq_top_iff.trans ⟨λ h x, @h x trivial, λ h x _, h x⟩ @[simp] theorem inf_coe : (p ⊓ p' : set M) = p ∩ p' := rfl @[simp] theorem mem_inf {p p' : submodule R M} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := iff.rfl @[simp] theorem Inf_coe (P : set (submodule R M)) : (↑(Inf P) : set M) = ⋂ p ∈ P, ↑p := rfl @[simp] theorem infi_coe {ι} (p : ι → submodule R M) : (↑⨅ i, p i : set M) = ⋂ i, ↑(p i) := by rw [infi, Inf_coe]; ext a; simp; exact ⟨λ h i, h _ i rfl, λ h i x e, e ▸ h _⟩ @[simp] theorem mem_infi {ι} (p : ι → submodule R M) : x ∈ (⨅ i, p i) ↔ ∀ i, x ∈ p i := by rw [← mem_coe, infi_coe, mem_Inter]; refl theorem disjoint_def {p p' : submodule R M} : disjoint p p' ↔ ∀ x ∈ p, x ∈ p' → x = (0:M) := show (∀ x, x ∈ p ∧ x ∈ p' → x ∈ ({0} : set M)) ↔ _, by simp /-- The pushforward of a submodule `p ⊆ M` by `f : M → M₂` -/ def map (f : M →ₗ[R] M₂) (p : submodule R M) : submodule R M₂ := { carrier := f '' p, zero := ⟨0, p.zero_mem, f.map_zero⟩, add := by rintro _ _ ⟨b₁, hb₁, rfl⟩ ⟨b₂, hb₂, rfl⟩; exact ⟨_, p.add_mem hb₁ hb₂, f.map_add _ _⟩, smul := by rintro a _ ⟨b, hb, rfl⟩; exact ⟨_, p.smul_mem _ hb, f.map_smul _ _⟩ } lemma map_coe (f : M →ₗ[R] M₂) (p : submodule R M) : (map f p : set M₂) = f '' p := rfl @[simp] lemma mem_map {f : M →ₗ[R] M₂} {p : submodule R M} {x : M₂} : x ∈ map f p ↔ ∃ y, y ∈ p ∧ f y = x := iff.rfl theorem mem_map_of_mem {f : M →ₗ[R] M₂} {p : submodule R M} {r} (h : r ∈ p) : f r ∈ map f p := set.mem_image_of_mem _ h lemma map_id : map linear_map.id p = p := submodule.ext $ λ a, by simp lemma map_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) (p : submodule R M) : map (g.comp f) p = map g (map f p) := submodule.ext' $ by simp [map_coe]; rw ← image_comp lemma map_mono {f : M →ₗ[R] M₂} {p p' : submodule R M} : p ≤ p' → map f p ≤ map f p' := image_subset _ @[simp] lemma map_zero : map (0 : M →ₗ[R] M₂) p = ⊥ := have ∃ (x : M), x ∈ p := ⟨0, p.zero_mem⟩, ext $ by simp [this, eq_comm] /-- The pullback of a submodule `p ⊆ M₂` along `f : M → M₂` -/ def comap (f : M →ₗ[R] M₂) (p : submodule R M₂) : submodule R M := { carrier := f ⁻¹' p, zero := by simp, add := λ x y h₁ h₂, by simp [p.add_mem h₁ h₂], smul := λ a x h, by simp [p.smul_mem _ h] } @[simp] lemma comap_coe (f : M →ₗ[R] M₂) (p : submodule R M₂) : (comap f p : set M) = f ⁻¹' p := rfl @[simp] lemma mem_comap {f : M →ₗ[R] M₂} {p : submodule R M₂} : x ∈ comap f p ↔ f x ∈ p := iff.rfl lemma comap_id : comap linear_map.id p = p := submodule.ext' rfl lemma comap_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) (p : submodule R M₃) : comap (g.comp f) p = comap f (comap g p) := rfl lemma comap_mono {f : M →ₗ[R] M₂} {q q' : submodule R M₂} : q ≤ q' → comap f q ≤ comap f q' := preimage_mono lemma map_le_iff_le_comap {f : M →ₗ[R] M₂} {p : submodule R M} {q : submodule R M₂} : map f p ≤ q ↔ p ≤ comap f q := image_subset_iff lemma gc_map_comap (f : M →ₗ[R] M₂) : galois_connection (map f) (comap f) | p q := map_le_iff_le_comap @[simp] lemma map_bot (f : M →ₗ[R] M₂) : map f ⊥ = ⊥ := (gc_map_comap f).l_bot @[simp] lemma map_sup (f : M →ₗ[R] M₂) : map f (p ⊔ p') = map f p ⊔ map f p' := (gc_map_comap f).l_sup @[simp] lemma map_supr {ι : Sort*} (f : M →ₗ[R] M₂) (p : ι → submodule R M) : map f (⨆i, p i) = (⨆i, map f (p i)) := (gc_map_comap f).l_supr @[simp] lemma comap_top (f : M →ₗ[R] M₂) : comap f ⊤ = ⊤ := rfl @[simp] lemma comap_inf (f : M →ₗ[R] M₂) : comap f (q ⊓ q') = comap f q ⊓ comap f q' := rfl @[simp] lemma comap_infi {ι : Sort*} (f : M →ₗ[R] M₂) (p : ι → submodule R M₂) : comap f (⨅i, p i) = (⨅i, comap f (p i)) := (gc_map_comap f).u_infi @[simp] lemma comap_zero : comap (0 : M →ₗ[R] M₂) q = ⊤ := ext $ by simp lemma map_comap_le (f : M →ₗ[R] M₂) (q : submodule R M₂) : map f (comap f q) ≤ q := (gc_map_comap f).l_u_le _ lemma le_comap_map (f : M →ₗ[R] M₂) (p : submodule R M) : p ≤ comap f (map f p) := (gc_map_comap f).le_u_l _ --TODO(Mario): is there a way to prove this from order properties? lemma map_inf_eq_map_inf_comap {f : M →ₗ[R] M₂} {p : submodule R M} {p' : submodule R M₂} : map f p ⊓ p' = map f (p ⊓ comap f p') := le_antisymm (by rintro _ ⟨⟨x, h₁, rfl⟩, h₂⟩; exact ⟨_, ⟨h₁, h₂⟩, rfl⟩) (le_inf (map_mono inf_le_left) (map_le_iff_le_comap.2 inf_le_right)) lemma map_comap_subtype : map p.subtype (comap p.subtype p') = p ⊓ p' := ext $ λ x, ⟨by rintro ⟨⟨_, h₁⟩, h₂, rfl⟩; exact ⟨h₁, h₂⟩, λ ⟨h₁, h₂⟩, ⟨⟨_, h₁⟩, h₂, rfl⟩⟩ lemma eq_zero_of_bot_submodule : ∀(b : (⊥ : submodule R M)), b = 0 | ⟨b', hb⟩ := subtype.eq $ show b' = 0, from (mem_bot R).1 hb section variables (R) /-- The span of a set `s ⊆ M` is the smallest submodule of M that contains `s`. -/ def span (s : set M) : submodule R M := Inf {p | s ⊆ p} end variables {s t : set M} lemma mem_span : x ∈ span R s ↔ ∀ p : submodule R M, s ⊆ p → x ∈ p := mem_bInter_iff lemma subset_span : s ⊆ span R s := λ x h, mem_span.2 $ λ p hp, hp h lemma span_le {p} : span R s ≤ p ↔ s ⊆ p := ⟨subset.trans subset_span, λ ss x h, mem_span.1 h _ ss⟩ lemma span_mono (h : s ⊆ t) : span R s ≤ span R t := span_le.2 $ subset.trans h subset_span lemma span_eq_of_le (h₁ : s ⊆ p) (h₂ : p ≤ span R s) : span R s = p := le_antisymm (span_le.2 h₁) h₂ @[simp] lemma span_eq : span R (p : set M) = p := span_eq_of_le _ (subset.refl _) subset_span /-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is preserved under addition and scalar multiplication, then `p` holds for all elements of the span of `s`. -/ @[elab_as_eliminator] lemma span_induction {p : M → Prop} (h : x ∈ span R s) (Hs : ∀ x ∈ s, p x) (H0 : p 0) (H1 : ∀ x y, p x → p y → p (x + y)) (H2 : ∀ (a:R) x, p x → p (a • x)) : p x := (@span_le _ _ _ _ _ _ ⟨p, H0, H1, H2⟩).2 Hs h section variables (R M) /-- `span` forms a Galois insertion with the coercion from submodule to set. -/ protected def gi : galois_insertion (@span R M _ _ _) coe := { choice := λ s _, span R s, gc := λ s t, span_le, le_l_u := λ s, subset_span, choice_eq := λ s h, rfl } end @[simp] lemma span_empty : span R (∅ : set M) = ⊥ := (submodule.gi R M).gc.l_bot @[simp] lemma span_univ : span R (univ : set M) = ⊤ := eq_top_iff.2 $ le_def.2 $ subset_span lemma span_union (s t : set M) : span R (s ∪ t) = span R s ⊔ span R t := (submodule.gi R M).gc.l_sup lemma span_Union {ι} (s : ι → set M) : span R (⋃ i, s i) = ⨆ i, span R (s i) := (submodule.gi R M).gc.l_supr @[simp] theorem Union_coe_of_directed {ι} (hι : nonempty ι) (S : ι → submodule R M) (H : ∀ i j, ∃ k, S i ≤ S k ∧ S j ≤ S k) : ((supr S : submodule R M) : set M) = ⋃ i, S i := begin refine subset.antisymm _ (Union_subset $ le_supr S), rw [show supr S = ⨆ i, span R (S i), by simp, ← span_Union], unfreezeI, refine λ x hx, span_induction hx (λ _, id) _ _ _, { cases hι with i, exact mem_Union.2 ⟨i, by simp⟩ }, { simp, intros x y i hi j hj, rcases H i j with ⟨k, ik, jk⟩, exact ⟨k, add_mem _ (ik hi) (jk hj)⟩ }, { simp [-mem_coe]; exact λ a x i hi, ⟨i, smul_mem _ a hi⟩ }, end lemma mem_supr_of_mem {ι : Sort*} {b : M} (p : ι → submodule R M) (i : ι) (h : b ∈ p i) : b ∈ (⨆i, p i) := have p i ≤ (⨆i, p i) := le_supr p i, @this b h @[simp] theorem mem_supr_of_directed {ι} (hι : nonempty ι) (S : ι → submodule R M) (H : ∀ i j, ∃ k, S i ≤ S k ∧ S j ≤ S k) {x} : x ∈ supr S ↔ ∃ i, x ∈ S i := by rw [← mem_coe, Union_coe_of_directed hι S H, mem_Union]; refl theorem mem_Sup_of_directed {s : set (submodule R M)} {z} (hzs : z ∈ Sup s) (x ∈ s) (hdir : ∀ i ∈ s, ∀ j ∈ s, ∃ k ∈ s, i ≤ k ∧ j ≤ k) : ∃ y ∈ s, z ∈ y := begin haveI := classical.dec, rw Sup_eq_supr at hzs, have : ∃ (i : submodule R M), z ∈ ⨆ (H : i ∈ s), i, { refine (mem_supr_of_directed ⟨⊥⟩ _ (λ i j, _)).1 hzs, by_cases his : i ∈ s; by_cases hjs : j ∈ s, { rcases hdir i his j hjs with ⟨k, hks, hik, hjk⟩, exact ⟨k, le_supr_of_le hks (supr_le $ λ _, hik), le_supr_of_le hks (supr_le $ λ _, hjk)⟩ }, { exact ⟨i, le_refl _, supr_le $ hjs.elim⟩ }, { exact ⟨j, supr_le $ his.elim, le_refl _⟩ }, { exact ⟨⊥, supr_le $ his.elim, supr_le $ hjs.elim⟩ } }, cases this with N hzn, by_cases hns : N ∈ s, { have : (⨆ (H : N ∈ s), N) ≤ N := supr_le (λ _, le_refl _), exact ⟨N, hns, this hzn⟩ }, { have : (⨆ (H : N ∈ s), N) ≤ ⊥ := supr_le hns.elim, cases (mem_bot R).1 (this hzn), exact ⟨x, H, x.zero_mem⟩ } end section variables {p p'} lemma mem_sup : x ∈ p ⊔ p' ↔ ∃ (y ∈ p) (z ∈ p'), y + z = x := ⟨λ h, begin rw [← span_eq p, ← span_eq p', ← span_union] at h, apply span_induction h, { rintro y (h | h), { exact ⟨y, h, 0, by simp, by simp⟩ }, { exact ⟨0, by simp, y, h, by simp⟩ } }, { exact ⟨0, by simp, 0, by simp⟩ }, { rintro _ _ ⟨y₁, hy₁, z₁, hz₁, rfl⟩ ⟨y₂, hy₂, z₂, hz₂, rfl⟩, exact ⟨_, add_mem _ hy₁ hy₂, _, add_mem _ hz₁ hz₂, by simp⟩ }, { rintro a _ ⟨y, hy, z, hz, rfl⟩, exact ⟨_, smul_mem _ a hy, _, smul_mem _ a hz, by simp [smul_add]⟩ } end, by rintro ⟨y, hy, z, hz, rfl⟩; exact add_mem _ ((le_sup_left : p ≤ p ⊔ p') hy) ((le_sup_right : p' ≤ p ⊔ p') hz)⟩ end lemma mem_span_singleton {y : M} : x ∈ span R ({y} : set M) ↔ ∃ a:R, a • y = x := ⟨λ h, begin apply span_induction h, { rintro y (rfl|⟨⟨⟩⟩), exact ⟨1, by simp⟩ }, { exact ⟨0, by simp⟩ }, { rintro _ _ ⟨a, rfl⟩ ⟨b, rfl⟩, exact ⟨a + b, by simp [add_smul]⟩ }, { rintro a _ ⟨b, rfl⟩, exact ⟨a * b, by simp [smul_smul]⟩ } end, by rintro ⟨a, y, rfl⟩; exact smul_mem _ _ (subset_span $ by simp)⟩ lemma span_singleton_eq_range (y : M) : (span R ({y} : set M) : set M) = range ((• y) : R → M) := set.ext $ λ x, mem_span_singleton lemma mem_span_insert {y} : x ∈ span R (insert y s) ↔ ∃ (a:R) (z ∈ span R s), x = a • y + z := begin rw [← union_singleton, span_union, mem_sup], simp [mem_span_singleton], split, { rintro ⟨z, hz, _, ⟨a, rfl⟩, rfl⟩, exact ⟨a, z, hz, rfl⟩ }, { rintro ⟨a, z, hz, rfl⟩, exact ⟨z, hz, _, ⟨a, rfl⟩, rfl⟩ } end lemma mem_span_insert' {y} : x ∈ span R (insert y s) ↔ ∃(a:R), x + a • y ∈ span R s := begin rw mem_span_insert, split, { rintro ⟨a, z, hz, rfl⟩, exact ⟨-a, by simp [hz]⟩ }, { rintro ⟨a, h⟩, exact ⟨-a, _, h, by simp⟩ } end lemma span_insert_eq_span (h : x ∈ span R s) : span R (insert x s) = span R s := span_eq_of_le _ (set.insert_subset.mpr ⟨h, subset_span⟩) (span_mono $ subset_insert _ _) lemma span_span : span R (span R s : set M) = span R s := span_eq _ lemma span_eq_bot : span R (s : set M) = ⊥ ↔ ∀ x ∈ s, (x:M) = 0 := eq_bot_iff.trans ⟨ λ H x h, (mem_bot R).1 $ H $ subset_span h, λ H, span_le.2 (λ x h, (mem_bot R).2 $ H x h)⟩ lemma span_singleton_eq_bot : span R ({x} : set M) = ⊥ ↔ x = 0 := span_eq_bot.trans $ by simp @[simp] lemma span_image (f : M →ₗ[R] M₂) : span R (f '' s) = map f (span R s) := span_eq_of_le _ (image_subset _ subset_span) $ map_le_iff_le_comap.2 $ span_le.2 $ image_subset_iff.1 subset_span lemma linear_eq_on (s : set M) {f g : M →ₗ[R] M₂} (H : ∀x∈s, f x = g x) {x} (h : x ∈ span R s) : f x = g x := by apply span_induction h H; simp {contextual := tt} /-- The product of two submodules is a submodule. -/ def prod : submodule R (M × M₂) := { carrier := set.prod p q, zero := ⟨zero_mem _, zero_mem _⟩, add := by rintro ⟨x₁, y₁⟩ ⟨x₂, y₂⟩ ⟨hx₁, hy₁⟩ ⟨hx₂, hy₂⟩; exact ⟨add_mem _ hx₁ hx₂, add_mem _ hy₁ hy₂⟩, smul := by rintro a ⟨x, y⟩ ⟨hx, hy⟩; exact ⟨smul_mem _ a hx, smul_mem _ a hy⟩ } @[simp] lemma prod_coe : (prod p q : set (M × M₂)) = set.prod p q := rfl @[simp] lemma mem_prod {p : submodule R M} {q : submodule R M₂} {x : M × M₂} : x ∈ prod p q ↔ x.1 ∈ p ∧ x.2 ∈ q := set.mem_prod lemma span_prod_le (s : set M) (t : set M₂) : span R (set.prod s t) ≤ prod (span R s) (span R t) := span_le.2 $ set.prod_mono subset_span subset_span @[simp] lemma prod_top : (prod ⊤ ⊤ : submodule R (M × M₂)) = ⊤ := by ext; simp @[simp] lemma prod_bot : (prod ⊥ ⊥ : submodule R (M × M₂)) = ⊥ := by ext ⟨x, y⟩; simp [prod.zero_eq_mk] lemma prod_mono {p p' : submodule R M} {q q' : submodule R M₂} : p ≤ p' → q ≤ q' → prod p q ≤ prod p' q' := prod_mono @[simp] lemma prod_inf_prod : prod p q ⊓ prod p' q' = prod (p ⊓ p') (q ⊓ q') := ext' set.prod_inter_prod @[simp] lemma prod_sup_prod : prod p q ⊔ prod p' q' = prod (p ⊔ p') (q ⊔ q') := begin refine le_antisymm (sup_le (prod_mono le_sup_left le_sup_left) (prod_mono le_sup_right le_sup_right)) _, simp [le_def'], intros xx yy hxx hyy, rcases mem_sup.1 hxx with ⟨x, hx, x', hx', rfl⟩, rcases mem_sup.1 hyy with ⟨y, hy, y', hy', rfl⟩, refine mem_sup.2 ⟨(x, y), ⟨hx, hy⟩, (x', y'), ⟨hx', hy'⟩, rfl⟩ end -- TODO(Mario): Factor through add_subgroup /-- The equivalence relation associated to a submodule `p`, defined by `x ≈ y` iff `y - x ∈ p`. -/ def quotient_rel : setoid M := ⟨λ x y, x - y ∈ p, λ x, by simp, λ x y h, by simpa using neg_mem _ h, λ x y z h₁ h₂, by simpa using add_mem _ h₁ h₂⟩ /-- The quotient of a module `M` by a submodule `p ⊆ M`. -/ def quotient : Type* := quotient (quotient_rel p) namespace quotient /-- Map associating to an element of `M` the corresponding element of `M/p`, when `p` is a submodule of `M`. -/ def mk {p : submodule R M} : M → quotient p := quotient.mk' @[simp] theorem mk_eq_mk {p : submodule R M} (x : M) : (quotient.mk x : quotient p) = mk x := rfl @[simp] theorem mk'_eq_mk {p : submodule R M} (x : M) : (quotient.mk' x : quotient p) = mk x := rfl @[simp] theorem quot_mk_eq_mk {p : submodule R M} (x : M) : (quot.mk _ x : quotient p) = mk x := rfl protected theorem eq {x y : M} : (mk x : quotient p) = mk y ↔ x - y ∈ p := quotient.eq' instance : has_zero (quotient p) := ⟨mk 0⟩ @[simp] theorem mk_zero : mk 0 = (0 : quotient p) := rfl @[simp] theorem mk_eq_zero : (mk x : quotient p) = 0 ↔ x ∈ p := by simpa using (quotient.eq p : mk x = 0 ↔ _) instance : has_add (quotient p) := ⟨λ a b, quotient.lift_on₂' a b (λ a b, mk (a + b)) $ λ a₁ a₂ b₁ b₂ h₁ h₂, (quotient.eq p).2 $ by simpa using add_mem p h₁ h₂⟩ @[simp] theorem mk_add : (mk (x + y) : quotient p) = mk x + mk y := rfl instance : has_neg (quotient p) := ⟨λ a, quotient.lift_on' a (λ a, mk (-a)) $ λ a b h, (quotient.eq p).2 $ by simpa using neg_mem p h⟩ @[simp] theorem mk_neg : (mk (-x) : quotient p) = -mk x := rfl instance : add_comm_group (quotient p) := by refine {zero := 0, add := (+), neg := has_neg.neg, ..}; repeat {rintro ⟨⟩}; simp [-mk_zero, (mk_zero p).symm, -mk_add, (mk_add p).symm, -mk_neg, (mk_neg p).symm] instance : has_scalar R (quotient p) := ⟨λ a x, quotient.lift_on' x (λ x, mk (a • x)) $ λ x y h, (quotient.eq p).2 $ by simpa [smul_add] using smul_mem p a h⟩ @[simp] theorem mk_smul : (mk (r • x) : quotient p) = r • mk x := rfl instance : module R (quotient p) := module.of_core $ by refine {smul := (•), ..}; repeat {rintro ⟨⟩ <|> intro}; simp [smul_add, add_smul, smul_smul, -mk_add, (mk_add p).symm, -mk_smul, (mk_smul p).symm] end quotient end submodule namespace submodule variables [discrete_field K] variables [add_comm_group V] [vector_space K V] variables [add_comm_group V₂] [vector_space K V₂] lemma comap_smul (f : V →ₗ[K] V₂) (p : submodule K V₂) (a : K) (h : a ≠ 0) : p.comap (a • f) = p.comap f := by ext b; simp only [submodule.mem_comap, p.smul_mem_iff h, linear_map.smul_apply] lemma map_smul (f : V →ₗ[K] V₂) (p : submodule K V) (a : K) (h : a ≠ 0) : p.map (a • f) = p.map f := le_antisymm begin rw [map_le_iff_le_comap, comap_smul f _ a h, ← map_le_iff_le_comap], exact le_refl _ end begin rw [map_le_iff_le_comap, ← comap_smul f _ a h, ← map_le_iff_le_comap], exact le_refl _ end set_option class.instance_max_depth 40 lemma comap_smul' (f : V →ₗ[K] V₂) (p : submodule K V₂) (a : K) : p.comap (a • f) = (⨅ h : a ≠ 0, p.comap f) := by by_cases a = 0; simp [h, comap_smul] lemma map_smul' (f : V →ₗ[K] V₂) (p : submodule K V) (a : K) : p.map (a • f) = (⨆ h : a ≠ 0, p.map f) := by by_cases a = 0; simp [h, map_smul] end submodule namespace linear_map variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [module R M] [module R M₂] [module R M₃] include R open submodule @[simp] lemma finsupp_sum {R M M₂ γ} [ring R] [add_comm_group M] [module R M] [add_comm_group M₂] [module R M₂] [has_zero γ] (f : M →ₗ[R] M₂) {t : ι →₀ γ} {g : ι → γ → M} : f (t.sum g) = t.sum (λi d, f (g i d)) := f.map_sum theorem map_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (h p') : submodule.map (cod_restrict p f h) p' = comap p.subtype (p'.map f) := submodule.ext $ λ ⟨x, hx⟩, by simp [subtype.coe_ext] theorem comap_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (hf p') : submodule.comap (cod_restrict p f hf) p' = submodule.comap f (map p.subtype p') := submodule.ext $ λ x, ⟨λ h, ⟨⟨_, hf x⟩, h, rfl⟩, by rintro ⟨⟨_, _⟩, h, ⟨⟩⟩; exact h⟩ /-- The range of a linear map `f : M → M₂` is a submodule of `M₂`. -/ def range (f : M →ₗ[R] M₂) : submodule R M₂ := map f ⊤ theorem range_coe (f : M →ₗ[R] M₂) : (range f : set M₂) = set.range f := set.image_univ @[simp] theorem mem_range {f : M →ₗ[R] M₂} : ∀ {x}, x ∈ range f ↔ ∃ y, f y = x := (set.ext_iff _ _).1 (range_coe f). @[simp] theorem range_id : range (linear_map.id : M →ₗ[R] M) = ⊤ := map_id _ theorem range_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : range (g.comp f) = map g (range f) := map_comp _ _ _ theorem range_comp_le_range (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : range (g.comp f) ≤ range g := by rw range_comp; exact map_mono le_top theorem range_eq_top {f : M →ₗ[R] M₂} : range f = ⊤ ↔ surjective f := by rw [← submodule.ext'_iff, range_coe, top_coe, set.range_iff_surjective] lemma range_le_iff_comap {f : M →ₗ[R] M₂} {p : submodule R M₂} : range f ≤ p ↔ comap f p = ⊤ := by rw [range, map_le_iff_le_comap, eq_top_iff] lemma map_le_range {f : M →ₗ[R] M₂} {p : submodule R M} : map f p ≤ range f := map_mono le_top lemma sup_range_inl_inr : (inl R M M₂).range ⊔ (inr R M M₂).range = ⊤ := begin refine eq_top_iff'.2 (λ x, mem_sup.2 _), rcases x with ⟨x₁, x₂⟩ , have h₁ : prod.mk x₁ (0 : M₂) ∈ (inl R M M₂).range, by simp, have h₂ : prod.mk (0 : M) x₂ ∈ (inr R M M₂).range, by simp, use [⟨x₁, 0⟩, h₁, ⟨0, x₂⟩, h₂], simp end /-- The kernel of a linear map `f : M → M₂` is defined to be `comap f ⊥`. This is equivalent to the set of `x : M` such that `f x = 0`. The kernel is a submodule of `M`. -/ def ker (f : M →ₗ[R] M₂) : submodule R M := comap f ⊥ @[simp] theorem mem_ker {f : M →ₗ[R] M₂} {y} : y ∈ ker f ↔ f y = 0 := mem_bot R @[simp] theorem ker_id : ker (linear_map.id : M →ₗ[R] M) = ⊥ := rfl theorem ker_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : ker (g.comp f) = comap f (ker g) := rfl theorem ker_le_ker_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : ker f ≤ ker (g.comp f) := by rw ker_comp; exact comap_mono bot_le theorem sub_mem_ker_iff {f : M →ₗ[R] M₂} {x y} : x - y ∈ f.ker ↔ f x = f y := by rw [mem_ker, map_sub, sub_eq_zero] theorem disjoint_ker {f : M →ₗ[R] M₂} {p : submodule R M} : disjoint p (ker f) ↔ ∀ x ∈ p, f x = 0 → x = 0 := by simp [disjoint_def] theorem disjoint_ker' {f : M →ₗ[R] M₂} {p : submodule R M} : disjoint p (ker f) ↔ ∀ x y ∈ p, f x = f y → x = y := disjoint_ker.trans ⟨λ H x y hx hy h, eq_of_sub_eq_zero $ H _ (sub_mem _ hx hy) (by simp [h]), λ H x h₁ h₂, H x 0 h₁ (zero_mem _) (by simpa using h₂)⟩ theorem inj_of_disjoint_ker {f : M →ₗ[R] M₂} {p : submodule R M} {s : set M} (h : s ⊆ p) (hd : disjoint p (ker f)) : ∀ x y ∈ s, f x = f y → x = y := λ x y hx hy, disjoint_ker'.1 hd _ _ (h hx) (h hy) lemma disjoint_inl_inr : disjoint (inl R M M₂).range (inr R M M₂).range := by simp [disjoint_def, @eq_comm M 0, @eq_comm M₂ 0] {contextual := tt}; intros; refl theorem ker_eq_bot {f : M →ₗ[R] M₂} : ker f = ⊥ ↔ injective f := by simpa [disjoint] using @disjoint_ker' _ _ _ _ _ _ _ _ f ⊤ theorem ker_eq_bot' {f : M →ₗ[R] M₂} : ker f = ⊥ ↔ (∀ m, f m = 0 → m = 0) := have h : (∀ m ∈ (⊤ : submodule R M), f m = 0 → m = 0) ↔ (∀ m, f m = 0 → m = 0), from ⟨λ h m, h m mem_top, λ h m _, h m⟩, by simpa [h, disjoint] using @disjoint_ker _ _ _ _ _ _ _ _ f ⊤ lemma le_ker_iff_map {f : M →ₗ[R] M₂} {p : submodule R M} : p ≤ ker f ↔ map f p = ⊥ := by rw [ker, eq_bot_iff, map_le_iff_le_comap] lemma ker_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (hf) : ker (cod_restrict p f hf) = ker f := by rw [ker, comap_cod_restrict, map_bot]; refl lemma range_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (hf) : range (cod_restrict p f hf) = comap p.subtype f.range := map_cod_restrict _ _ _ _ lemma map_comap_eq (f : M →ₗ[R] M₂) (q : submodule R M₂) : map f (comap f q) = range f ⊓ q := le_antisymm (le_inf (map_mono le_top) (map_comap_le _ _)) $ by rintro _ ⟨⟨x, _, rfl⟩, hx⟩; exact ⟨x, hx, rfl⟩ lemma map_comap_eq_self {f : M →ₗ[R] M₂} {q : submodule R M₂} (h : q ≤ range f) : map f (comap f q) = q := by rw [map_comap_eq, inf_of_le_right h] lemma comap_map_eq (f : M →ₗ[R] M₂) (p : submodule R M) : comap f (map f p) = p ⊔ ker f := begin refine le_antisymm _ (sup_le (le_comap_map _ _) (comap_mono bot_le)), rintro x ⟨y, hy, e⟩, exact mem_sup.2 ⟨y, hy, x - y, by simpa using sub_eq_zero.2 e.symm, by simp⟩ end lemma comap_map_eq_self {f : M →ₗ[R] M₂} {p : submodule R M} (h : ker f ≤ p) : comap f (map f p) = p := by rw [comap_map_eq, sup_of_le_left h] @[simp] theorem ker_zero : ker (0 : M →ₗ[R] M₂) = ⊤ := eq_top_iff'.2 $ λ x, by simp @[simp] theorem range_zero : range (0 : M →ₗ[R] M₂) = ⊥ := submodule.map_zero _ theorem ker_eq_top {f : M →ₗ[R] M₂} : ker f = ⊤ ↔ f = 0 := ⟨λ h, ext $ λ x, mem_ker.1 $ h.symm ▸ trivial, λ h, h.symm ▸ ker_zero⟩ lemma range_le_bot_iff (f : M →ₗ[R] M₂) : range f ≤ ⊥ ↔ f = 0 := by rw [range_le_iff_comap]; exact ker_eq_top theorem map_le_map_iff {f : M →ₗ[R] M₂} (hf : ker f = ⊥) {p p'} : map f p ≤ map f p' ↔ p ≤ p' := ⟨λ H x hx, let ⟨y, hy, e⟩ := H ⟨x, hx, rfl⟩ in ker_eq_bot.1 hf e ▸ hy, map_mono⟩ theorem map_injective {f : M →ₗ[R] M₂} (hf : ker f = ⊥) : injective (map f) := λ p p' h, le_antisymm ((map_le_map_iff hf).1 (le_of_eq h)) ((map_le_map_iff hf).1 (ge_of_eq h)) theorem comap_le_comap_iff {f : M →ₗ[R] M₂} (hf : range f = ⊤) {p p'} : comap f p ≤ comap f p' ↔ p ≤ p' := ⟨λ H x hx, by rcases range_eq_top.1 hf x with ⟨y, hy, rfl⟩; exact H hx, comap_mono⟩ theorem comap_injective {f : M →ₗ[R] M₂} (hf : range f = ⊤) : injective (comap f) := λ p p' h, le_antisymm ((comap_le_comap_iff hf).1 (le_of_eq h)) ((comap_le_comap_iff hf).1 (ge_of_eq h)) theorem map_copair_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (p : submodule R M) (q : submodule R M₂) : map (copair f g) (p.prod q) = map f p ⊔ map g q := begin refine le_antisymm _ (sup_le (map_le_iff_le_comap.2 _) (map_le_iff_le_comap.2 _)), { rw le_def', rintro _ ⟨x, ⟨h₁, h₂⟩, rfl⟩, exact mem_sup.2 ⟨_, ⟨_, h₁, rfl⟩, _, ⟨_, h₂, rfl⟩, rfl⟩ }, { exact λ x hx, ⟨(x, 0), by simp [hx]⟩ }, { exact λ x hx, ⟨(0, x), by simp [hx]⟩ } end theorem comap_pair_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) (p : submodule R M₂) (q : submodule R M₃) : comap (pair f g) (p.prod q) = comap f p ⊓ comap g q := submodule.ext $ λ x, iff.rfl theorem prod_eq_inf_comap (p : submodule R M) (q : submodule R M₂) : p.prod q = p.comap (linear_map.fst R M M₂) ⊓ q.comap (linear_map.snd R M M₂) := submodule.ext $ λ x, iff.rfl theorem prod_eq_sup_map (p : submodule R M) (q : submodule R M₂) : p.prod q = p.map (linear_map.inl R M M₂) ⊔ q.map (linear_map.inr R M M₂) := by rw [← map_copair_prod, copair_inl_inr, map_id] lemma span_inl_union_inr {s : set M} {t : set M₂} : span R (prod.inl '' s ∪ prod.inr '' t) = (span R s).prod (span R t) := by rw [span_union, prod_eq_sup_map, ← span_image, ← span_image]; refl lemma ker_pair (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : ker (pair f g) = ker f ⊓ ker g := by rw [ker, ← prod_bot, comap_pair_prod]; refl end linear_map namespace linear_map variables [discrete_field K] variables [add_comm_group V] [vector_space K V] variables [add_comm_group V₂] [vector_space K V₂] lemma ker_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : ker (a • f) = ker f := submodule.comap_smul f _ a h lemma ker_smul' (f : V →ₗ[K] V₂) (a : K) : ker (a • f) = ⨅(h : a ≠ 0), ker f := submodule.comap_smul' f _ a lemma range_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : range (a • f) = range f := submodule.map_smul f _ a h lemma range_smul' (f : V →ₗ[K] V₂) (a : K) : range (a • f) = ⨆(h : a ≠ 0), range f := submodule.map_smul' f _ a end linear_map namespace is_linear_map lemma is_linear_map_add {R M : Type*} [ring R] [add_comm_group M] [module R M]: is_linear_map R (λ (x : M × M), x.1 + x.2) := begin apply is_linear_map.mk, { intros x y, simp }, { intros x y, simp [smul_add] } end lemma is_linear_map_sub {R M : Type*} [ring R] [add_comm_group M] [module R M]: is_linear_map R (λ (x : M × M), x.1 - x.2) := begin apply is_linear_map.mk, { intros x y, simp }, { intros x y, simp [smul_add] } end end is_linear_map namespace submodule variables {T : ring R} [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂] variables (p p' : submodule R M) (q : submodule R M₂) include T open linear_map @[simp] theorem map_top (f : M →ₗ[R] M₂) : map f ⊤ = range f := rfl @[simp] theorem comap_bot (f : M →ₗ[R] M₂) : comap f ⊥ = ker f := rfl @[simp] theorem ker_subtype : p.subtype.ker = ⊥ := ker_eq_bot.2 $ λ x y, subtype.eq' @[simp] theorem range_subtype : p.subtype.range = p := by simpa using map_comap_subtype p ⊤ lemma map_subtype_le (p' : submodule R p) : map p.subtype p' ≤ p := by simpa using (map_mono le_top : map p.subtype p' ≤ p.subtype.range) /-- Under the canonical linear map from a submodule `p` to the ambient space `M`, the image of the maximal submodule of `p` is just `p `. -/ @[simp] lemma map_subtype_top : map p.subtype (⊤ : submodule R p) = p := by simp @[simp] theorem ker_of_le (p p' : submodule R M) (h : p ≤ p') : (of_le h).ker = ⊥ := by rw [of_le, ker_cod_restrict, ker_subtype] lemma range_of_le (p q : submodule R M) (h : p ≤ q) : (of_le h).range = comap q.subtype p := by rw [← map_top, of_le, linear_map.map_cod_restrict, map_top, range_subtype] lemma disjoint_iff_comap_eq_bot (p q : submodule R M) : disjoint p q ↔ comap p.subtype q = ⊥ := by rw [eq_bot_iff, ← map_le_map_iff p.ker_subtype, map_bot, map_comap_subtype]; refl /-- If N ⊆ M then submodules of N are the same as submodules of M contained in N -/ def map_subtype.order_iso : ((≤) : submodule R p → submodule R p → Prop) ≃o ((≤) : {p' : submodule R M // p' ≤ p} → {p' : submodule R M // p' ≤ p} → Prop) := { to_fun := λ p', ⟨map p.subtype p', map_subtype_le p _⟩, inv_fun := λ q, comap p.subtype q, left_inv := λ p', comap_map_eq_self $ by simp, right_inv := λ ⟨q, hq⟩, subtype.eq' $ by simp [map_comap_subtype p, inf_of_le_right hq], ord := λ p₁ p₂, (map_le_map_iff $ ker_subtype _).symm } /-- If `p ⊆ M` is a submodule, the ordering of submodules of `p` is embedded in the ordering of submodules of M. -/ def map_subtype.le_order_embedding : ((≤) : submodule R p → submodule R p → Prop) ≼o ((≤) : submodule R M → submodule R M → Prop) := (order_iso.to_order_embedding $ map_subtype.order_iso p).trans (subtype.order_embedding _ _) @[simp] lemma map_subtype_embedding_eq (p' : submodule R p) : map_subtype.le_order_embedding p p' = map p.subtype p' := rfl /-- If `p ⊆ M` is a submodule, the ordering of submodules of `p` is embedded in the ordering of submodules of M. -/ def map_subtype.lt_order_embedding : ((<) : submodule R p → submodule R p → Prop) ≼o ((<) : submodule R M → submodule R M → Prop) := (map_subtype.le_order_embedding p).lt_embedding_of_le_embedding @[simp] theorem map_inl : p.map (inl R M M₂) = prod p ⊥ := by ext ⟨x, y⟩; simp [and.left_comm, eq_comm] @[simp] theorem map_inr : q.map (inr R M M₂) = prod ⊥ q := by ext ⟨x, y⟩; simp [and.left_comm, eq_comm] @[simp] theorem comap_fst : p.comap (fst R M M₂) = prod p ⊤ := by ext ⟨x, y⟩; simp @[simp] theorem comap_snd : q.comap (snd R M M₂) = prod ⊤ q := by ext ⟨x, y⟩; simp @[simp] theorem prod_comap_inl : (prod p q).comap (inl R M M₂) = p := by ext; simp @[simp] theorem prod_comap_inr : (prod p q).comap (inr R M M₂) = q := by ext; simp @[simp] theorem prod_map_fst : (prod p q).map (fst R M M₂) = p := by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ q)] @[simp] theorem prod_map_snd : (prod p q).map (snd R M M₂) = q := by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ p)] @[simp] theorem ker_inl : (inl R M M₂).ker = ⊥ := by rw [ker, ← prod_bot, prod_comap_inl] @[simp] theorem ker_inr : (inr R M M₂).ker = ⊥ := by rw [ker, ← prod_bot, prod_comap_inr] @[simp] theorem range_fst : (fst R M M₂).range = ⊤ := by rw [range, ← prod_top, prod_map_fst] @[simp] theorem range_snd : (snd R M M₂).range = ⊤ := by rw [range, ← prod_top, prod_map_snd] /-- The map from a module `M` to the quotient of `M` by a submodule `p` as a linear map. -/ def mkq : M →ₗ[R] p.quotient := ⟨quotient.mk, by simp, by simp⟩ @[simp] theorem mkq_apply (x : M) : p.mkq x = quotient.mk x := rfl /-- The map from the quotient of `M` by a submodule `p` to `M₂` induced by a linear map `f : M → M₂` vanishing on `p`, as a linear map. -/ def liftq (f : M →ₗ[R] M₂) (h : p ≤ f.ker) : p.quotient →ₗ[R] M₂ := ⟨λ x, _root_.quotient.lift_on' x f $ λ a b (ab : a - b ∈ p), eq_of_sub_eq_zero $ by simpa using h ab, by rintro ⟨x⟩ ⟨y⟩; exact f.map_add x y, by rintro a ⟨x⟩; exact f.map_smul a x⟩ @[simp] theorem liftq_apply (f : M →ₗ[R] M₂) {h} (x : M) : p.liftq f h (quotient.mk x) = f x := rfl @[simp] theorem liftq_mkq (f : M →ₗ[R] M₂) (h) : (p.liftq f h).comp p.mkq = f := by ext; refl @[simp] theorem range_mkq : p.mkq.range = ⊤ := eq_top_iff'.2 $ by rintro ⟨x⟩; exact ⟨x, trivial, rfl⟩ @[simp] theorem ker_mkq : p.mkq.ker = p := by ext; simp lemma le_comap_mkq (p' : submodule R p.quotient) : p ≤ comap p.mkq p' := by simpa using (comap_mono bot_le : p.mkq.ker ≤ comap p.mkq p') @[simp] theorem mkq_map_self : map p.mkq p = ⊥ := by rw [eq_bot_iff, map_le_iff_le_comap, comap_bot, ker_mkq]; exact le_refl _ @[simp] theorem comap_map_mkq : comap p.mkq (map p.mkq p') = p ⊔ p' := by simp [comap_map_eq, sup_comm] /-- The map from the quotient of `M` by submodule `p` to the quotient of `M₂` by submodule `q` along `f : M → M₂` is linear. -/ def mapq (f : M →ₗ[R] M₂) (h : p ≤ comap f q) : p.quotient →ₗ[R] q.quotient := p.liftq (q.mkq.comp f) $ by simpa [ker_comp] using h @[simp] theorem mapq_apply (f : M →ₗ[R] M₂) {h} (x : M) : mapq p q f h (quotient.mk x) = quotient.mk (f x) := rfl theorem mapq_mkq (f : M →ₗ[R] M₂) {h} : (mapq p q f h).comp p.mkq = q.mkq.comp f := by ext x; refl theorem comap_liftq (f : M →ₗ[R] M₂) (h) : q.comap (p.liftq f h) = (q.comap f).map (mkq p) := le_antisymm (by rintro ⟨x⟩ hx; exact ⟨_, hx, rfl⟩) (by rw [map_le_iff_le_comap, ← comap_comp, liftq_mkq]; exact le_refl _) theorem map_liftq (f : M →ₗ[R] M₂) (h) (q : submodule R (quotient p)) : q.map (p.liftq f h) = (q.comap p.mkq).map f := le_antisymm (by rintro _ ⟨⟨x⟩, hxq, rfl⟩; exact ⟨x, hxq, rfl⟩) (by rintro _ ⟨x, hxq, rfl⟩; exact ⟨quotient.mk x, hxq, rfl⟩) theorem ker_liftq (f : M →ₗ[R] M₂) (h) : ker (p.liftq f h) = (ker f).map (mkq p) := comap_liftq _ _ _ _ theorem range_liftq (f : M →ₗ[R] M₂) (h) : range (p.liftq f h) = range f := map_liftq _ _ _ _ theorem ker_liftq_eq_bot (f : M →ₗ[R] M₂) (h) (h' : ker f ≤ p) : ker (p.liftq f h) = ⊥ := by rw [ker_liftq, le_antisymm h h', mkq_map_self] /-- The correspondence theorem for modules: there is an order isomorphism between submodules of the quotient of `M` by `p`, and submodules of `M` larger than `p`. -/ def comap_mkq.order_iso : ((≤) : submodule R p.quotient → submodule R p.quotient → Prop) ≃o ((≤) : {p' : submodule R M // p ≤ p'} → {p' : submodule R M // p ≤ p'} → Prop) := { to_fun := λ p', ⟨comap p.mkq p', le_comap_mkq p _⟩, inv_fun := λ q, map p.mkq q, left_inv := λ p', map_comap_eq_self $ by simp, right_inv := λ ⟨q, hq⟩, subtype.eq' $ by simp [comap_map_mkq p, sup_of_le_right hq], ord := λ p₁ p₂, (comap_le_comap_iff $ range_mkq _).symm } /-- The ordering on submodules of the quotient of `M` by `p` embeds into the ordering on submodules of `M`. -/ def comap_mkq.le_order_embedding : ((≤) : submodule R p.quotient → submodule R p.quotient → Prop) ≼o ((≤) : submodule R M → submodule R M → Prop) := (order_iso.to_order_embedding $ comap_mkq.order_iso p).trans (subtype.order_embedding _ _) @[simp] lemma comap_mkq_embedding_eq (p' : submodule R p.quotient) : comap_mkq.le_order_embedding p p' = comap p.mkq p' := rfl /-- The ordering on submodules of the quotient of `M` by `p` embeds into the ordering on submodules of `M`. -/ def comap_mkq.lt_order_embedding : ((<) : submodule R p.quotient → submodule R p.quotient → Prop) ≼o ((<) : submodule R M → submodule R M → Prop) := (comap_mkq.le_order_embedding p).lt_embedding_of_le_embedding end submodule section set_option old_structure_cmd true /-- A linear equivalence is an invertible linear map. -/ structure linear_equiv (R : Type u) (M : Type v) (M₂ : Type w) [ring R] [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂] extends M →ₗ[R] M₂, M ≃ M₂ end infix ` ≃ₗ ` := linear_equiv _ notation M ` ≃ₗ[`:50 R `] ` M₂ := linear_equiv R M M₂ namespace linear_equiv section ring variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [module R M] [module R M₂] [module R M₃] include R instance : has_coe (M ≃ₗ[R] M₂) (M →ₗ[R] M₂) := ⟨to_linear_map⟩ @[simp] theorem coe_apply (e : M ≃ₗ[R] M₂) (b : M) : (e : M →ₗ[R] M₂) b = e b := rfl lemma to_equiv_injective : function.injective (to_equiv : (M ≃ₗ[R] M₂) → M ≃ M₂) := λ ⟨_, _, _, _, _, _⟩ ⟨_, _, _, _, _, _⟩ h, linear_equiv.mk.inj_eq.mpr (equiv.mk.inj h) @[ext] lemma ext {f g : M ≃ₗ[R] M₂} (h : (f : M → M₂) = g) : f = g := to_equiv_injective (equiv.eq_of_to_fun_eq h) section variable (M) /-- The identity map is a linear equivalence. -/ def refl : M ≃ₗ[R] M := { .. linear_map.id, .. equiv.refl M } end /-- Linear equivalences are symmetric. -/ def symm (e : M ≃ₗ[R] M₂) : M₂ ≃ₗ[R] M := { .. e.to_linear_map.inverse e.inv_fun e.left_inv e.right_inv, .. e.to_equiv.symm } /-- Linear equivalences are transitive. -/ def trans (e₁ : M ≃ₗ[R] M₂) (e₂ : M₂ ≃ₗ[R] M₃) : M ≃ₗ[R] M₃ := { .. e₂.to_linear_map.comp e₁.to_linear_map, .. e₁.to_equiv.trans e₂.to_equiv } @[simp] theorem apply_symm_apply (e : M ≃ₗ[R] M₂) (c : M₂) : e (e.symm c) = c := e.6 c @[simp] theorem symm_apply_apply (e : M ≃ₗ[R] M₂) (b : M) : e.symm (e b) = b := e.5 b /-- A bijective linear map is a linear equivalence. Here, bijectivity is described by saying that the kernel of `f` is `{0}` and the range is the universal set. -/ noncomputable def of_bijective (f : M →ₗ[R] M₂) (hf₁ : f.ker = ⊥) (hf₂ : f.range = ⊤) : M ≃ₗ[R] M₂ := { ..f, ..@equiv.of_bijective _ _ f ⟨linear_map.ker_eq_bot.1 hf₁, linear_map.range_eq_top.1 hf₂⟩ } @[simp] theorem of_bijective_apply (f : M →ₗ[R] M₂) {hf₁ hf₂} (x : M) : of_bijective f hf₁ hf₂ x = f x := rfl /-- If a linear map has an inverse, it is a linear equivalence. -/ def of_linear (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M) (h₁ : f.comp g = linear_map.id) (h₂ : g.comp f = linear_map.id) : M ≃ₗ[R] M₂ := { inv_fun := g, left_inv := linear_map.ext_iff.1 h₂, right_inv := linear_map.ext_iff.1 h₁, ..f } @[simp] theorem of_linear_apply (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M) {h₁ h₂} (x : M) : of_linear f g h₁ h₂ x = f x := rfl @[simp] theorem of_linear_symm_apply (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M) {h₁ h₂} (x : M₂) : (of_linear f g h₁ h₂).symm x = g x := rfl @[simp] protected theorem ker (f : M ≃ₗ[R] M₂) : (f : M →ₗ[R] M₂).ker = ⊥ := linear_map.ker_eq_bot.2 f.to_equiv.injective @[simp] protected theorem range (f : M ≃ₗ[R] M₂) : (f : M →ₗ[R] M₂).range = ⊤ := linear_map.range_eq_top.2 f.to_equiv.surjective /-- The top submodule of `M` is linearly equivalent to `M`. -/ def of_top (p : submodule R M) (h : p = ⊤) : p ≃ₗ[R] M := { inv_fun := λ x, ⟨x, h.symm ▸ trivial⟩, left_inv := λ ⟨x, h⟩, rfl, right_inv := λ x, rfl, .. p.subtype } @[simp] theorem of_top_apply (p : submodule R M) {h} (x : p) : of_top p h x = x := rfl @[simp] theorem of_top_symm_apply (p : submodule R M) {h} (x : M) : ↑((of_top p h).symm x) = x := rfl lemma eq_bot_of_equiv (p : submodule R M) (e : p ≃ₗ[R] (⊥ : submodule R M₂)) : p = ⊥ := begin refine bot_unique (submodule.le_def'.2 $ assume b hb, (submodule.mem_bot R).2 _), have := e.symm_apply_apply ⟨b, hb⟩, rw [← e.coe_apply, submodule.eq_zero_of_bot_submodule ((e : p →ₗ[R] (⊥ : submodule R M₂)) ⟨b, hb⟩), ← e.symm.coe_apply, linear_map.map_zero] at this, exact congr_arg (coe : p → M) this.symm end end ring section comm_ring variables [comm_ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [module R M] [module R M₂] [module R M₃] include R open linear_map set_option class.instance_max_depth 39 /-- Multiplying by a unit `a` of the ring `R` is a linear equivalence. -/ def smul_of_unit (a : units R) : M ≃ₗ[R] M := of_linear ((a:R) • 1 : M →ₗ M) (((a⁻¹ : units R) : R) • 1 : M →ₗ M) (by rw [smul_comp, comp_smul, smul_smul, units.mul_inv, one_smul]; refl) (by rw [smul_comp, comp_smul, smul_smul, units.inv_mul, one_smul]; refl) /-- A linear isomorphism between the domains and codomains of two spaces of linear maps gives a linear isomorphism between the two function spaces. -/ def arrow_congr {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_ring R] [add_comm_group M₁] [add_comm_group M₂] [add_comm_group M₂₁] [add_comm_group M₂₂] [module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂] (e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) : (M₁ →ₗ[R] M₂₁) ≃ₗ[R] (M₂ →ₗ[R] M₂₂) := { to_fun := λ f, e₂.to_linear_map.comp $ f.comp e₁.symm.to_linear_map, inv_fun := λ f, e₂.symm.to_linear_map.comp $ f.comp e₁.to_linear_map, left_inv := λ f, by { ext x, unfold_coes, change e₂.inv_fun (e₂.to_fun $ f.to_fun $ e₁.inv_fun $ e₁.to_fun x) = _, rw [e₁.left_inv, e₂.left_inv] }, right_inv := λ f, by { ext x, unfold_coes, change e₂.to_fun (e₂.inv_fun $ f.to_fun $ e₁.to_fun $ e₁.inv_fun x) = _, rw [e₁.right_inv, e₂.right_inv] }, add := λ f g, by { ext x, change e₂.to_fun ((f + g) (e₁.inv_fun x)) = _, rw [linear_map.add_apply, e₂.add], refl }, smul := λ c f, by { ext x, change e₂.to_fun ((c • f) (e₁.inv_fun x)) = _, rw [linear_map.smul_apply, e₂.smul], refl } } /-- If M₂ and M₃ are linearly isomorphic then the two spaces of linear maps from M into M₂ and M into M₃ are linearly isomorphic. -/ def congr_right (f : M₂ ≃ₗ[R] M₃) : (M →ₗ[R] M₂) ≃ₗ (M →ₗ M₃) := arrow_congr (linear_equiv.refl M) f /-- If M and M₂ are linearly isomorphic then the two spaces of linear maps from M and M₂ to themselves are linearly isomorphic. -/ def conj (e : M ≃ₗ[R] M₂) : (M →ₗ[R] M) ≃ₗ[R] (M₂ →ₗ[R] M₂) := arrow_congr e e end comm_ring section field variables [field K] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [module K M] [module K M₂] [module K M₃] variable (M) open linear_map /-- Multiplying by a nonzero element `a` of the field `K` is a linear equivalence. -/ def smul_of_ne_zero (a : K) (ha : a ≠ 0) : M ≃ₗ[K] M := smul_of_unit $ units.mk0 a ha end field end linear_equiv namespace equiv variables [ring R] [add_comm_group M] [module R M] [add_comm_group M₂] [module R M₂] /-- An equivalence whose underlying function is linear is a linear equivalence. -/ def to_linear_equiv (e : M ≃ M₂) (h : is_linear_map R (e : M → M₂)) : M ≃ₗ[R] M₂ := { add := h.add, smul := h.smul, .. e} end equiv namespace linear_map variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [module R M] [module R M₂] [module R M₃] variables (f : M →ₗ[R] M₂) /-- The first isomorphism law for modules. The quotient of `M` by the kernel of `f` is linearly equivalent to the range of `f`. -/ noncomputable def quot_ker_equiv_range : f.ker.quotient ≃ₗ[R] f.range := have hr : ∀ x : f.range, ∃ y, f y = ↑x := λ x, x.2.imp $ λ _, and.right, let F : f.ker.quotient →ₗ[R] f.range := f.ker.liftq (cod_restrict f.range f $ λ x, ⟨x, trivial, rfl⟩) (λ x hx, by simp; apply subtype.coe_ext.2; simpa using hx) in { inv_fun := λx, submodule.quotient.mk (classical.some (hr x)), left_inv := by rintro ⟨x⟩; exact (submodule.quotient.eq _).2 (sub_mem_ker_iff.2 $ classical.some_spec $ hr $ F $ submodule.quotient.mk x), right_inv := λ x : range f, subtype.eq $ classical.some_spec (hr x), .. F } open submodule /-- Canonical linear map from the quotient p/(p ∩ p') to (p+p')/p', mapping x + (p ∩ p') to x + p', where p and p' are submodules of an ambient module. -/ def sup_quotient_to_quotient_inf (p p' : submodule R M) : (comap p.subtype (p ⊓ p')).quotient →ₗ[R] (comap (p ⊔ p').subtype p').quotient := (comap p.subtype (p ⊓ p')).liftq ((comap (p ⊔ p').subtype p').mkq.comp (of_le le_sup_left)) begin rw [ker_comp, of_le, comap_cod_restrict, ker_mkq, map_comap_subtype], exact comap_mono (inf_le_inf le_sup_left (le_refl _)) end set_option class.instance_max_depth 41 /-- Second Isomorphism Law : the canonical map from p/(p ∩ p') to (p+p')/p' as a linear isomorphism. -/ noncomputable def sup_quotient_equiv_quotient_inf (p p' : submodule R M) : (comap p.subtype (p ⊓ p')).quotient ≃ₗ[R] (comap (p ⊔ p').subtype p').quotient := { .. sup_quotient_to_quotient_inf p p', .. show (comap p.subtype (p ⊓ p')).quotient ≃ (comap (p ⊔ p').subtype p').quotient, from @equiv.of_bijective _ _ (sup_quotient_to_quotient_inf p p') begin constructor, { rw [← ker_eq_bot, sup_quotient_to_quotient_inf, ker_liftq_eq_bot], rw [ker_comp, ker_mkq], rintros ⟨x, hx1⟩ hx2, exact ⟨hx1, hx2⟩ }, rw [← range_eq_top, sup_quotient_to_quotient_inf, range_liftq, eq_top_iff'], rintros ⟨x, hx⟩, rcases mem_sup.1 hx with ⟨y, hy, z, hz, rfl⟩, use [⟨y, hy⟩, trivial], apply (submodule.quotient.eq _).2, change y - (y + z) ∈ p', rwa [sub_add_eq_sub_sub, sub_self, zero_sub, neg_mem_iff] end } section prod /-- The cartesian product of two linear maps as a linear map. -/ def prod {R M M₂ M₃ : Type*} [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] [module R M] [module R M₂] [module R M₃] (f₁ : M →ₗ[R] M₂) (f₂ : M →ₗ[R] M₃) : M →ₗ[R] (M₂ × M₃) := { to_fun := λx, (f₁ x, f₂ x), add := λx y, begin change (f₁ (x + y), f₂ (x+y)) = (f₁ x, f₂ x) + (f₁ y, f₂ y), simp only [linear_map.map_add], refl end, smul := λc x, by simp only [linear_map.map_smul] } lemma is_linear_map_prod_iso {R M M₂ M₃ : Type*} [comm_ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] [module R M] [module R M₂] [module R M₃] : is_linear_map R (λ(p : (M →ₗ[R] M₂) × (M →ₗ[R] M₃)), (linear_map.prod p.1 p.2 : (M →ₗ[R] (M₂ × M₃)))) := ⟨λu v, rfl, λc u, rfl⟩ end prod section pi universe i variables {φ : ι → Type i} variables [∀i, add_comm_group (φ i)] [∀i, module R (φ i)] /-- `pi` construction for linear functions. From a family of linear functions it produces a linear function into a family of modules. -/ def pi (f : Πi, M₂ →ₗ[R] φ i) : M₂ →ₗ[R] (Πi, φ i) := ⟨λc i, f i c, assume c d, funext $ assume i, (f i).add _ _, assume c d, funext $ assume i, (f i).smul _ _⟩ @[simp] lemma pi_apply (f : Πi, M₂ →ₗ[R] φ i) (c : M₂) (i : ι) : pi f c i = f i c := rfl lemma ker_pi (f : Πi, M₂ →ₗ[R] φ i) : ker (pi f) = (⨅i:ι, ker (f i)) := by ext c; simp [funext_iff]; refl lemma pi_eq_zero (f : Πi, M₂ →ₗ[R] φ i) : pi f = 0 ↔ (∀i, f i = 0) := by simp only [linear_map.ext_iff, pi_apply, funext_iff]; exact ⟨λh a b, h b a, λh a b, h b a⟩ lemma pi_zero : pi (λi, 0 : Πi, M₂ →ₗ[R] φ i) = 0 := by ext; refl lemma pi_comp (f : Πi, M₂ →ₗ[R] φ i) (g : M₃ →ₗ[R] M₂) : (pi f).comp g = pi (λi, (f i).comp g) := rfl /-- The projections from a family of modules are linear maps. -/ def proj (i : ι) : (Πi, φ i) →ₗ[R] φ i := ⟨ λa, a i, assume f g, rfl, assume c f, rfl ⟩ @[simp] lemma proj_apply (i : ι) (b : Πi, φ i) : (proj i : (Πi, φ i) →ₗ[R] φ i) b = b i := rfl lemma proj_pi (f : Πi, M₂ →ₗ[R] φ i) (i : ι) : (proj i).comp (pi f) = f i := ext $ assume c, rfl lemma infi_ker_proj : (⨅i, ker (proj i) : submodule R (Πi, φ i)) = ⊥ := bot_unique $ submodule.le_def'.2 $ assume a h, begin simp only [mem_infi, mem_ker, proj_apply] at h, exact (mem_bot _).2 (funext $ assume i, h i) end section variables (R φ) /-- If `I` and `J` are disjoint index sets, the product of the kernels of the `J`th projections of `φ` is linearly equivalent to the product over `I`. -/ def infi_ker_proj_equiv {I J : set ι} [decidable_pred (λi, i ∈ I)] (hd : disjoint I J) (hu : set.univ ⊆ I ∪ J) : (⨅i ∈ J, ker (proj i) : submodule R (Πi, φ i)) ≃ₗ[R] (Πi:I, φ i) := begin refine linear_equiv.of_linear (pi $ λi, (proj (i:ι)).comp (submodule.subtype _)) (cod_restrict _ (pi $ λi, if h : i ∈ I then proj (⟨i, h⟩ : I) else 0) _) _ _, { assume b, simp only [mem_infi, mem_ker, funext_iff, proj_apply, pi_apply], assume j hjJ, have : j ∉ I := assume hjI, hd ⟨hjI, hjJ⟩, rw [dif_neg this, zero_apply] }, { simp only [pi_comp, comp_assoc, subtype_comp_cod_restrict, proj_pi, dif_pos, subtype.val_prop'], ext b ⟨j, hj⟩, refl }, { ext ⟨b, hb⟩, apply subtype.coe_ext.2, ext j, have hb : ∀i ∈ J, b i = 0, { simpa only [mem_infi, mem_ker, proj_apply] using (mem_infi _).1 hb }, simp only [comp_apply, pi_apply, id_apply, proj_apply, subtype_apply, cod_restrict_apply], split_ifs, { rw [dif_pos h], refl }, { rw [dif_neg h], exact (hb _ $ (hu trivial).resolve_left h).symm } } end end section variable [decidable_eq ι] /-- `diag i j` is the identity map if `i = j`. Otherwise it is the constant 0 map. -/ def diag (i j : ι) : φ i →ₗ[R] φ j := @function.update ι (λj, φ i →ₗ[R] φ j) _ 0 i id j lemma update_apply (f : Πi, M₂ →ₗ[R] φ i) (c : M₂) (i j : ι) (b : M₂ →ₗ[R] φ i) : (update f i b j) c = update (λi, f i c) i (b c) j := begin by_cases j = i, { rw [h, update_same, update_same] }, { rw [update_noteq h, update_noteq h] } end end section variable [decidable_eq ι] variables (R φ) /-- The standard basis of the product of `φ`. -/ def std_basis (i : ι) : φ i →ₗ[R] (Πi, φ i) := pi (diag i) lemma std_basis_apply (i : ι) (b : φ i) : std_basis R φ i b = update 0 i b := by ext j; rw [std_basis, pi_apply, diag, update_apply]; refl @[simp] lemma std_basis_same (i : ι) (b : φ i) : std_basis R φ i b i = b := by rw [std_basis_apply, update_same] lemma std_basis_ne (i j : ι) (h : j ≠ i) (b : φ i) : std_basis R φ i b j = 0 := by rw [std_basis_apply, update_noteq h]; refl lemma ker_std_basis (i : ι) : ker (std_basis R φ i) = ⊥ := ker_eq_bot.2 $ assume f g hfg, have std_basis R φ i f i = std_basis R φ i g i := hfg ▸ rfl, by simpa only [std_basis_same] lemma proj_comp_std_basis (i j : ι) : (proj i).comp (std_basis R φ j) = diag j i := by rw [std_basis, proj_pi] lemma proj_std_basis_same (i : ι) : (proj i).comp (std_basis R φ i) = id := by ext b; simp lemma proj_std_basis_ne (i j : ι) (h : i ≠ j) : (proj i).comp (std_basis R φ j) = 0 := by ext b; simp [std_basis_ne R φ _ _ h] lemma supr_range_std_basis_le_infi_ker_proj (I J : set ι) (h : disjoint I J) : (⨆i∈I, range (std_basis R φ i)) ≤ (⨅i∈J, ker (proj i)) := begin refine (supr_le $ assume i, supr_le $ assume hi, range_le_iff_comap.2 _), simp only [(ker_comp _ _).symm, eq_top_iff, le_def', mem_ker, comap_infi, mem_infi], assume b hb j hj, have : i ≠ j := assume eq, h ⟨hi, eq.symm ▸ hj⟩, rw [proj_std_basis_ne R φ j i this.symm, zero_apply] end lemma infi_ker_proj_le_supr_range_std_basis {I : finset ι} {J : set ι} (hu : set.univ ⊆ ↑I ∪ J) : (⨅ i∈J, ker (proj i)) ≤ (⨆i∈I, range (std_basis R φ i)) := submodule.le_def'.2 begin assume b hb, simp only [mem_infi, mem_ker, proj_apply] at hb, rw ← show I.sum (λi, std_basis R φ i (b i)) = b, { ext i, rw [pi.finset_sum_apply, ← std_basis_same R φ i (b i)], refine finset.sum_eq_single i (assume j hjI ne, std_basis_ne _ _ _ _ ne.symm _) _, assume hiI, rw [std_basis_same], exact hb _ ((hu trivial).resolve_left hiI) }, exact sum_mem _ (assume i hiI, mem_supr_of_mem _ i $ mem_supr_of_mem _ hiI $ linear_map.mem_range.2 ⟨_, rfl⟩) end lemma supr_range_std_basis_eq_infi_ker_proj {I J : set ι} (hd : disjoint I J) (hu : set.univ ⊆ I ∪ J) (hI : set.finite I) : (⨆i∈I, range (std_basis R φ i)) = (⨅i∈J, ker (proj i)) := begin refine le_antisymm (supr_range_std_basis_le_infi_ker_proj _ _ _ _ hd) _, have : set.univ ⊆ ↑hI.to_finset ∪ J, { rwa [finset.coe_to_finset] }, refine le_trans (infi_ker_proj_le_supr_range_std_basis R φ this) (supr_le_supr $ assume i, _), rw [← finset.mem_coe, finset.coe_to_finset], exact le_refl _ end lemma supr_range_std_basis [fintype ι] : (⨆i:ι, range (std_basis R φ i)) = ⊤ := have (set.univ : set ι) ⊆ ↑(finset.univ : finset ι) ∪ ∅ := by rw [finset.coe_univ, set.union_empty], begin apply top_unique, convert (infi_ker_proj_le_supr_range_std_basis R φ this), exact infi_emptyset.symm, exact (funext $ λi, (@supr_pos _ _ _ (λh, range (std_basis R φ i)) $ finset.mem_univ i).symm) end lemma disjoint_std_basis_std_basis (I J : set ι) (h : disjoint I J) : disjoint (⨆i∈I, range (std_basis R φ i)) (⨆i∈J, range (std_basis R φ i)) := begin refine disjoint_mono (supr_range_std_basis_le_infi_ker_proj _ _ _ _ $ set.disjoint_compl I) (supr_range_std_basis_le_infi_ker_proj _ _ _ _ $ set.disjoint_compl J) _, simp only [disjoint, submodule.le_def', mem_infi, mem_inf, mem_ker, mem_bot, proj_apply, funext_iff], rintros b ⟨hI, hJ⟩ i, classical, by_cases hiI : i ∈ I, { by_cases hiJ : i ∈ J, { exact (h ⟨hiI, hiJ⟩).elim }, { exact hJ i hiJ } }, { exact hI i hiI } end lemma std_basis_eq_single {a : R} : (λ (i : ι), (std_basis R (λ _ : ι, R) i) a) = λ (i : ι), (finsupp.single i a) := begin ext i j, rw [std_basis_apply, finsupp.single_apply], split_ifs, { rw [h, function.update_same] }, { rw [function.update_noteq (ne.symm h)], refl }, end end end pi variables (R M) instance automorphism_group : group (M ≃ₗ[R] M) := { mul := λ f g, g.trans f, one := linear_equiv.refl M, inv := λ f, f.symm, mul_assoc := λ f g h, by {ext, refl}, mul_one := λ f, by {ext, refl}, one_mul := λ f, by {ext, refl}, mul_left_inv := λ f, by {ext, exact f.left_inv x} } instance automorphism_group.to_linear_map_is_monoid_hom : is_monoid_hom (linear_equiv.to_linear_map : (M ≃ₗ[R] M) → (M →ₗ[R] M)) := { map_one := rfl, map_mul := λ f g, rfl } /-- The group of invertible linear maps from `M` to itself -/ def general_linear_group := units (M →ₗ[R] M) namespace general_linear_group variables {R M} instance : group (general_linear_group R M) := by delta general_linear_group; apply_instance /-- An invertible linear map `f` determines an equivalence from `M` to itself. -/ def to_linear_equiv (f : general_linear_group R M) : (M ≃ₗ[R] M) := { inv_fun := f.inv.to_fun, left_inv := λ m, show (f.inv * f.val) m = m, by erw f.inv_val; simp, right_inv := λ m, show (f.val * f.inv) m = m, by erw f.val_inv; simp, ..f.val } /-- An equivalence from `M` to itself determines an invertible linear map. -/ def of_linear_equiv (f : (M ≃ₗ[R] M)) : general_linear_group R M := { val := f, inv := f.symm, val_inv := linear_map.ext $ λ _, f.apply_symm_apply _, inv_val := linear_map.ext $ λ _, f.symm_apply_apply _ } variables (R M) /-- The general linear group on `R` and `M` is multiplicatively equivalent to the type of linear equivalences between `M` and itself. -/ def general_linear_equiv : general_linear_group R M ≃* (M ≃ₗ[R] M) := { to_fun := to_linear_equiv, inv_fun := of_linear_equiv, left_inv := λ f, begin delta to_linear_equiv of_linear_equiv, cases f with f f_inv, cases f, cases f_inv, congr end, right_inv := λ f, begin delta to_linear_equiv of_linear_equiv, cases f, congr end, map_mul' := λ x y, by {ext, refl} } @[simp] lemma general_linear_equiv_to_linear_map (f : general_linear_group R M) : ((general_linear_equiv R M).to_equiv f).to_linear_map = f.val := by {ext, refl} end general_linear_group end linear_map
208eedb26cfaf3ec741b4c7b03ca934ea72d5913
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/control/applicative.lean
84ce23162a5fb98775b38a68fbc65481d963ef87
[ "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
4,882
lean
/- Copyright (c) 2017 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import algebra.group.defs import control.functor /-! # `applicative` instances This file provides `applicative` instances for concrete functors: * `id` * `functor.comp` * `functor.const` * `functor.add_const` -/ universes u v w section lemmas open function variables {F : Type u → Type v} variables [applicative F] [is_lawful_applicative F] variables {α β γ σ : Type u} lemma applicative.map_seq_map (f : α → β → γ) (g : σ → β) (x : F α) (y : F σ) : (f <$> x) <*> (g <$> y) = (flip (∘) g ∘ f) <$> x <*> y := by simp [flip] with functor_norm lemma applicative.pure_seq_eq_map' (f : α → β) : (<*>) (pure f : F (α → β)) = (<$>) f := by ext; simp with functor_norm theorem applicative.ext {F} : ∀ {A1 : applicative F} {A2 : applicative F} [@is_lawful_applicative F A1] [@is_lawful_applicative F A2] (H1 : ∀ {α : Type u} (x : α), @has_pure.pure _ A1.to_has_pure _ x = @has_pure.pure _ A2.to_has_pure _ x) (H2 : ∀ {α β : Type u} (f : F (α → β)) (x : F α), @has_seq.seq _ A1.to_has_seq _ _ f x = @has_seq.seq _ A2.to_has_seq _ _ f x), A1 = A2 | {to_functor := F1, seq := s1, pure := p1, seq_left := sl1, seq_right := sr1} {to_functor := F2, seq := s2, pure := p2, seq_left := sl2, seq_right := sr2} L1 L2 H1 H2 := begin have : @p1 = @p2, {funext α x, apply H1}, subst this, have : @s1 = @s2, {funext α β f x, apply H2}, subst this, cases L1, cases L2, have : F1 = F2, { resetI, apply functor.ext, intros, exact (L1_pure_seq_eq_map _ _).symm.trans (L2_pure_seq_eq_map _ _) }, subst this, congr; funext α β x y, { exact (L1_seq_left_eq _ _).trans (L2_seq_left_eq _ _).symm }, { exact (L1_seq_right_eq _ _).trans (L2_seq_right_eq _ _).symm } end end lemmas instance : is_comm_applicative id := by refine { .. }; intros; refl namespace functor namespace comp open function (hiding comp) open functor variables {F : Type u → Type w} {G : Type v → Type u} variables [applicative F] [applicative G] variables [is_lawful_applicative F] [is_lawful_applicative G] variables {α β γ : Type v} lemma map_pure (f : α → β) (x : α) : (f <$> pure x : comp F G β) = pure (f x) := comp.ext $ by simp lemma seq_pure (f : comp F G (α → β)) (x : α) : f <*> pure x = (λ g : α → β, g x) <$> f := comp.ext $ by simp [(∘)] with functor_norm lemma seq_assoc (x : comp F G α) (f : comp F G (α → β)) (g : comp F G (β → γ)) : g <*> (f <*> x) = (@function.comp α β γ <$> g) <*> f <*> x := comp.ext $ by simp [(∘)] with functor_norm lemma pure_seq_eq_map (f : α → β) (x : comp F G α) : pure f <*> x = f <$> x := comp.ext $ by simp [applicative.pure_seq_eq_map'] with functor_norm instance : is_lawful_applicative (comp F G) := { pure_seq_eq_map := @comp.pure_seq_eq_map F G _ _ _ _, map_pure := @comp.map_pure F G _ _ _ _, seq_pure := @comp.seq_pure F G _ _ _ _, seq_assoc := @comp.seq_assoc F G _ _ _ _ } theorem applicative_id_comp {F} [AF : applicative F] [LF : is_lawful_applicative F] : @comp.applicative id F _ _ = AF := @applicative.ext F _ _ (@comp.is_lawful_applicative id F _ _ _ _) _ (λ α x, rfl) (λ α β f x, rfl) theorem applicative_comp_id {F} [AF : applicative F] [LF : is_lawful_applicative F] : @comp.applicative F id _ _ = AF := @applicative.ext F _ _ (@comp.is_lawful_applicative F id _ _ _ _) _ (λ α x, rfl) (λ α β f x, show id <$> f <*> x = f <*> x, by rw id_map) open is_comm_applicative instance {f : Type u → Type w} {g : Type v → Type u} [applicative f] [applicative g] [is_comm_applicative f] [is_comm_applicative g] : is_comm_applicative (comp f g) := by { refine { .. @comp.is_lawful_applicative f g _ _ _ _, .. }, intros, casesm* comp _ _ _, simp! [map,has_seq.seq] with functor_norm, rw [commutative_map], simp [comp.mk,flip,(∘)] with functor_norm, congr, funext, rw [commutative_map], congr } end comp end functor open functor @[functor_norm] lemma comp.seq_mk {α β : Type w} {f : Type u → Type v} {g : Type w → Type u} [applicative f] [applicative g] (h : f (g (α → β))) (x : f (g α)) : comp.mk h <*> comp.mk x = comp.mk (has_seq.seq <$> h <*> x) := rfl instance {α} [has_one α] [has_mul α] : applicative (const α) := { pure := λ β x, (1 : α), seq := λ β γ f x, (f * x : α) } instance {α} [monoid α] : is_lawful_applicative (const α) := by refine { .. }; intros; simp [mul_assoc, (<$>), (<*>), pure] instance {α} [has_zero α] [has_add α] : applicative (add_const α) := { pure := λ β x, (0 : α), seq := λ β γ f x, (f + x : α) } instance {α} [add_monoid α] : is_lawful_applicative (add_const α) := by refine { .. }; intros; simp [add_assoc, (<$>), (<*>), pure]
5685027af7241ee403528d8a8bc8b4ea8c7dc5c5
c31182a012eec69da0a1f6c05f42b0f0717d212d
/src/for_mathlib/Cech/split.lean
6dd51eaee0060f0111bb975667525cdf54f1497e
[]
no_license
Ja1941/lean-liquid
fbec3ffc7fc67df1b5ca95b7ee225685ab9ffbdc
8e80ed0cbdf5145d6814e833a674eaf05a1495c1
refs/heads/master
1,689,437,983,362
1,628,362,719,000
1,628,362,719,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
7,353
lean
import category_theory.preadditive import algebraic_topology.cech_nerve import for_mathlib.simplicial.complex import for_mathlib.arrow.split namespace category_theory universes v u namespace arrow noncomputable theory open_locale simplicial open category_theory.limits variables {C : Type u} [category.{v} C] (f : arrow C) variables [∀ n : ℕ, has_wide_pullback f.right (λ i : ulift (fin (n+1)), f.left) (λ i, f.hom)] /-- The splittings of the Cech nerve associated to a split arrow. -/ def cech_splitting [split f] (n : ℕ) : f.cech_nerve _[n] ⟶ f.cech_nerve _[n+1] := wide_pullback.lift (wide_pullback.base _) (λ i, if h : i.down = 0 then wide_pullback.base _ ≫ split.σ else wide_pullback.π _ ⟨i.down.pred h⟩) begin rintro ⟨j⟩, split_ifs, tidy, end lemma cech_splitting_face_zero [split f] (n : ℕ) : f.cech_splitting n ≫ f.cech_nerve.δ 0 = 𝟙 _ := begin ext ⟨j⟩, dsimp [cech_splitting, simplicial_object.δ], simp only [category.id_comp, category.assoc, wide_pullback.lift_π], split_ifs, { exfalso, exact fin.succ_ne_zero _ h }, { congr, dsimp [simplicial_object.δ, simplex_category.δ], simp }, { dsimp [simplicial_object.δ, cech_splitting], simp }, end lemma face_π (n : ℕ) (i : fin (n+1)) (j : fin (n+2)) : (f.cech_nerve.δ j : f.cech_nerve _[n+1] ⟶ _) ≫ wide_pullback.π _ ⟨i⟩ = wide_pullback.π _ ⟨j.succ_above i⟩ := begin change wide_pullback.lift _ _ _ ≫ _ = _, simpa, end lemma cech_splitting_face [split f] (n : ℕ) (j : fin (n+3)) (hj : j ≠ 0) : f.cech_splitting (n+1) ≫ f.cech_nerve.δ j = f.cech_nerve.δ (j.pred hj) ≫ f.cech_splitting n := begin ext ⟨k⟩, swap, { dsimp [cech_splitting, simplicial_object.δ], simp }, { dsimp [cech_splitting, simplicial_object.δ], simp only [category.assoc, limits.wide_pullback.lift_π], split_ifs with h1 h2, { simp }, { refine false.elim (h2 _), change j.succ_above k = 0 at h1, change k = 0, rwa ← fin.succ_above_eq_zero_iff hj }, { refine false.elim (h1 _), erw h, change j.succ_above 0 = 0, rw fin.succ_above_eq_zero_iff hj }, { simp only [category_theory.limits.wide_pullback.lift_π], congr, change (j.succ_above k).pred h1 = (j.pred hj).succ_above (k.pred h), rw fin.pred_succ_above_pred, refl } } end end arrow namespace arrow section contracting_homotopy open category_theory.limits opposite -- Note: Universe restrictions! I hope this doesn't pose any issues later... variables {P N : Type u} [category.{v} P] [category.{v} N] (M : Pᵒᵖ ⥤ N) variables (f : arrow P) variables [∀ n : ℕ, has_wide_pullback f.right (λ i : ulift (fin (n+1)), f.left) (λ i, f.hom)] /-- The augmented Cech conerve induced by applying M to `f.augmented_cech_nerve`. -/ abbreviation conerve : cosimplicial_object.augmented N := ((cosimplicial_object.augmented.whiskering _ _).obj M).obj f.augmented_cech_nerve.right_op variables [arrow.split f] [preadditive N] /-- The morphisms yielding the contracting homotopy. -/ def contracting_homotopy : Π (n : ℕ), (f.conerve M).to_cocomplex.X (n+1) ⟶ (f.conerve M).to_cocomplex.X n | 0 := M.map (wide_pullback.lift (𝟙 _) (λ i, (split.σ : f.right ⟶ _)) (by simp)).op | (n+1) := M.map (f.cech_splitting n).op open cosimplicial_object.augmented open_locale big_operators lemma is_contracting_homotopy_zero : (f.conerve M).to_cocomplex.d 0 1 ≫ f.contracting_homotopy M 0 = 𝟙 _ := begin dsimp, rw if_pos, swap, { simp }, delta conerve, dsimp [to_cocomplex_d, to_cocomplex_obj, contracting_homotopy ], simp only [category.id_comp, category.comp_id], simp_rw [← M.map_comp, ← op_comp, ← M.map_id, ← op_id], congr' 2, simp, end lemma is_contracting_homotopy_one : (f.conerve M).to_cocomplex.d 1 2 ≫ f.contracting_homotopy M 1 + f.contracting_homotopy M 0 ≫ (f.conerve M).to_cocomplex.d 0 1 = 𝟙 _ := begin rw ← add_zero (𝟙 ((conerve M f).to_cocomplex.X 1)), dsimp only [to_cocomplex, cochain_complex.of], rw dif_pos, swap, { dec_trivial }, rw dif_pos, swap, { dec_trivial }, dsimp, delta conerve, dsimp only [to_cocomplex_d, cosimplicial_object.coboundary, whiskering, whiskering_obj, drop, to_cocomplex_obj, comma.snd, cosimplicial_object.whiskering, whiskering_right, contracting_homotopy], simp_rw fin.sum_univ_succ, simp only [fin.coe_zero, fin.sum_univ_zero, fin.coe_one, one_gsmul, preadditive.add_comp, pow_one, fin.succ_zero_eq_one, category.id_comp, neg_smul, category.comp_id, preadditive.neg_comp, pow_zero ], rw [add_assoc], congr' 1, { dsimp [cosimplicial_object.δ], simp_rw [← M.map_comp, ← M.map_id, ← op_id, ← op_comp], congr' 2, dsimp [cech_splitting], ext ⟨j⟩, { simp only [wide_pullback.lift_π, category.id_comp, category.assoc], split_ifs, { cases j, dsimp at h, injection h with hh, simp only [nat.succ_ne_zero] at hh, cases hh }, { congr, } }, { simp only [wide_pullback.lift_base, category.assoc, category.id_comp] } }, { dsimp [cosimplicial_object.δ], rw [add_assoc, neg_add_eq_zero, ← M.map_comp], simp only [zero_comp, category.id_comp, zero_add, functor.map_comp, ← M.map_comp, ← op_comp], congr' 2, dsimp [cech_splitting], ext ⟨j⟩, { simp only [wide_pullback.lift_π, category.assoc], split_ifs, { refl }, { refine false.elim (h _), change (1 : fin 2).succ_above j = 0, rw fin.succ_above_eq_zero_iff, { simp }, { exact top_ne_bot } } }, { simp only [wide_pullback.lift_base, category.assoc, category.comp_id] } } end lemma is_contracting_homotopy (n : ℕ) : (f.conerve M).to_cocomplex.d (n+2) (n+3) ≫ f.contracting_homotopy M (n+2) + f.contracting_homotopy M (n+1) ≫ (f.conerve M).to_cocomplex.d (n+1) (n+2) = 𝟙 _ := begin dsimp, erw if_pos, swap, refl, dsimp only [to_cocomplex_d], rw if_pos, swap, refl, dsimp only [cosimplicial_object.coboundary], simp only [preadditive.sum_comp, preadditive.comp_sum], erw [fin.sum_univ_succ, add_assoc, ← finset.sum_add_distrib], rw ← add_zero (𝟙 ((conerve M f).to_cocomplex_obj (n + 2))), dsimp only [cosimplicial_object.δ], congr' 1, { delta conerve, dsimp [to_cocomplex_obj, contracting_homotopy], simp only [category_theory.category.comp_id, one_gsmul, pow_zero], simp_rw [← M.map_id, ← M.map_comp, ← op_comp, ← op_id], congr' 2, apply cech_splitting_face_zero }, { apply fintype.sum_eq_zero, intros i, simp only [ category.comp_id, add_zero, functor.comp_map, fin.coe_succ, preadditive.comp_gsmul, preadditive.gsmul_comp], suffices : (drop.obj (conerve M f)).map (simplex_category.δ i.succ) ≫ contracting_homotopy M f (n+2) = contracting_homotopy M f (n+1) ≫ (drop.obj (conerve M f)).map (simplex_category.δ i), { rw [this, pow_succ], simp }, delta conerve, dsimp [contracting_homotopy], simp_rw [← M.map_comp, ← op_comp], congr' 2, convert cech_splitting_face _ _ _ (fin.succ_ne_zero _), funext, congr, simp } end end contracting_homotopy end arrow end category_theory
b37ecc42ae8fd10adf53c6a5ab0908682e95f327
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/data/int/basic.lean
f83bb630be5bd1859f91a6b4790ad15821664806
[ "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
19,560
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import data.nat.basic import order.monotone.basic /-! # Basic instances on the integers > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file contains: * instances on `ℤ`. The stronger one is `int.comm_ring`. See `data/int/defs/order` for `int.linear_ordered_comm_ring`. * basic lemmas about the integers, but which do not use the ordered algebra hierarchy. -/ open nat namespace int instance : inhabited ℤ := ⟨int.zero⟩ instance : nontrivial ℤ := ⟨⟨0, 1, int.zero_ne_one⟩⟩ instance : comm_ring ℤ := { add := int.add, add_assoc := int.add_assoc, zero := int.zero, zero_add := int.zero_add, add_zero := int.add_zero, neg := int.neg, add_left_neg := int.add_left_neg, add_comm := int.add_comm, mul := int.mul, mul_assoc := int.mul_assoc, one := int.one, one_mul := int.one_mul, mul_one := int.mul_one, sub := int.sub, left_distrib := int.distrib_left, right_distrib := int.distrib_right, mul_comm := int.mul_comm, nat_cast := int.of_nat, nat_cast_zero := rfl, nat_cast_succ := λ n, rfl, int_cast := λ n, n, int_cast_of_nat := λ n, rfl, int_cast_neg_succ_of_nat := λ n, rfl, zsmul := (*), zsmul_zero' := int.zero_mul, zsmul_succ' := λ n x, by rw [nat.succ_eq_add_one, nat.add_comm, of_nat_add, int.distrib_right, of_nat_one, int.one_mul], zsmul_neg' := λ n x, int.neg_mul_eq_neg_mul_symm (n.succ : ℤ) x } /-! ### Extra instances to short-circuit type class resolution These also prevent non-computable instances like `int.normed_comm_ring` being used to construct these instances non-computably. -/ -- instance : has_sub int := by apply_instance -- This is in core instance : add_comm_monoid ℤ := by apply_instance instance : add_monoid ℤ := by apply_instance instance : monoid ℤ := by apply_instance instance : comm_monoid ℤ := by apply_instance instance : comm_semigroup ℤ := by apply_instance instance : semigroup ℤ := by apply_instance instance : add_comm_group ℤ := by apply_instance instance : add_group ℤ := by apply_instance instance : add_comm_semigroup ℤ := by apply_instance instance : add_semigroup ℤ := by apply_instance instance : comm_semiring ℤ := by apply_instance instance : semiring ℤ := by apply_instance instance : ring ℤ := by apply_instance instance : distrib ℤ := by apply_instance end int namespace int @[simp] lemma add_neg_one (i : ℤ) : i + -1 = i - 1 := rfl @[simp] theorem sign_coe_add_one (n : ℕ) : int.sign (n + 1) = 1 := rfl @[simp] theorem sign_neg_succ_of_nat (n : ℕ) : int.sign -[1+ n] = -1 := rfl @[simp] lemma default_eq_zero : default = (0 : ℤ) := rfl meta instance : has_to_format ℤ := ⟨λ z, to_string z⟩ section -- Note that here we are disabling the "safety" of reflected, to allow us to reuse `int.mk_numeral`. -- The usual way to provide the required `reflected` instance would be via rewriting to prove that -- the expression we use here is equivalent. local attribute [semireducible] reflected meta instance reflect : has_reflect ℤ := int.mk_numeral `(ℤ) `(by apply_instance : has_zero ℤ) `(by apply_instance : has_one ℤ) `(by apply_instance : has_add ℤ) `(by apply_instance : has_neg ℤ) end attribute [simp] int.bodd @[simp] theorem add_def {a b : ℤ} : int.add a b = a + b := rfl @[simp] theorem mul_def {a b : ℤ} : int.mul a b = a * b := rfl @[simp] lemma neg_succ_not_nonneg (n : ℕ) : 0 ≤ -[1+ n] ↔ false := by { simp only [not_le, iff_false], exact int.neg_succ_lt_zero n, } @[simp] lemma neg_succ_not_pos (n : ℕ) : 0 < -[1+ n] ↔ false := by simp only [not_lt, iff_false] @[simp] lemma neg_succ_sub_one (n : ℕ) : -[1+ n] - 1 = -[1+ (n+1)] := rfl @[simp] theorem coe_nat_mul_neg_succ (m n : ℕ) : (m : ℤ) * -[1+ n] = -(m * succ n) := rfl @[simp] theorem neg_succ_mul_coe_nat (m n : ℕ) : -[1+ m] * n = -(succ m * n) := rfl @[simp] theorem neg_succ_mul_neg_succ (m n : ℕ) : -[1+ m] * -[1+ n] = succ m * succ n := rfl theorem coe_nat_le {m n : ℕ} : (↑m : ℤ) ≤ ↑n ↔ m ≤ n := coe_nat_le_coe_nat_iff m n theorem coe_nat_lt {m n : ℕ} : (↑m : ℤ) < ↑n ↔ m < n := coe_nat_lt_coe_nat_iff m n theorem coe_nat_inj' {m n : ℕ} : (↑m : ℤ) = ↑n ↔ m = n := int.coe_nat_eq_coe_nat_iff m n lemma coe_nat_strict_mono : strict_mono (coe : ℕ → ℤ) := λ _ _, int.coe_nat_lt.2 lemma coe_nat_nonneg (n : ℕ) : 0 ≤ (n : ℤ) := coe_nat_le.2 (nat.zero_le _) @[simp] lemma neg_of_nat_ne_zero (n : ℕ) : -[1+ n] ≠ 0 := λ h, int.no_confusion h @[simp] lemma zero_ne_neg_of_nat (n : ℕ) : 0 ≠ -[1+ n] := λ h, int.no_confusion h /-! ### succ and pred -/ /-- Immediate successor of an integer: `succ n = n + 1` -/ def succ (a : ℤ) := a + 1 /-- Immediate predecessor of an integer: `pred n = n - 1` -/ def pred (a : ℤ) := a - 1 theorem nat_succ_eq_int_succ (n : ℕ) : (nat.succ n : ℤ) = int.succ n := rfl theorem pred_succ (a : ℤ) : pred (succ a) = a := add_sub_cancel _ _ theorem succ_pred (a : ℤ) : succ (pred a) = a := sub_add_cancel _ _ theorem neg_succ (a : ℤ) : -succ a = pred (-a) := neg_add _ _ theorem succ_neg_succ (a : ℤ) : succ (-succ a) = -a := by rw [neg_succ, succ_pred] theorem neg_pred (a : ℤ) : -pred a = succ (-a) := by rw [neg_eq_iff_eq_neg.mp (neg_succ (-a)), neg_neg] theorem pred_neg_pred (a : ℤ) : pred (-pred a) = -a := by rw [neg_pred, pred_succ] theorem pred_nat_succ (n : ℕ) : pred (nat.succ n) = n := pred_succ n theorem neg_nat_succ (n : ℕ) : -(nat.succ n : ℤ) = pred (-n) := neg_succ n theorem succ_neg_nat_succ (n : ℕ) : succ (-nat.succ n) = -n := succ_neg_succ n theorem add_one_le_iff {a b : ℤ} : a + 1 ≤ b ↔ a < b := iff.rfl @[norm_cast] lemma coe_pred_of_pos {n : ℕ} (h : 0 < n) : ((n - 1 : ℕ) : ℤ) = (n : ℤ) - 1 := by { cases n, cases h, simp, } @[elab_as_eliminator] protected lemma induction_on {p : ℤ → Prop} (i : ℤ) (hz : p 0) (hp : ∀ i : ℕ, p i → p (i + 1)) (hn : ∀ i : ℕ, p (-i) → p (-i - 1)) : p i := begin induction i, { induction i, { exact hz }, { exact hp _ i_ih } }, { have : ∀ n:ℕ, p (- n), { intro n, induction n, { simp [hz] }, { convert hn _ n_ih using 1, simp [sub_eq_neg_add] } }, exact this (i + 1) } end /-! ### nat abs -/ variables {a b : ℤ} {n : ℕ} attribute [simp] nat_abs_of_nat nat_abs_zero nat_abs_one lemma nat_abs_surjective : nat_abs.surjective := λ n, ⟨n, nat_abs_of_nat n⟩ theorem nat_abs_add_le (a b : ℤ) : nat_abs (a + b) ≤ nat_abs a + nat_abs b := begin have : ∀ (a b : ℕ), nat_abs (sub_nat_nat a (nat.succ b)) ≤ nat.succ (a + b), { refine (λ a b : ℕ, sub_nat_nat_elim a b.succ (λ m n i, n = b.succ → nat_abs i ≤ (m + b).succ) _ (λ i n e, _) rfl), { rintro i n rfl, rw [add_comm _ i, add_assoc], exact nat.le_add_right i (b.succ + b).succ }, { apply succ_le_succ, rw [← succ.inj e, ← add_assoc, add_comm], apply nat.le_add_right } }, cases a; cases b with b b; simp [nat_abs, nat.succ_add]; try {refl}; [skip, rw add_comm a b]; apply this end lemma nat_abs_sub_le (a b : ℤ) : nat_abs (a - b) ≤ nat_abs a + nat_abs b := by { rw [sub_eq_add_neg, ← int.nat_abs_neg b], apply nat_abs_add_le } theorem nat_abs_neg_of_nat (n : ℕ) : nat_abs (neg_of_nat n) = n := by cases n; refl theorem nat_abs_mul (a b : ℤ) : nat_abs (a * b) = (nat_abs a) * (nat_abs b) := by cases a; cases b; simp only [← int.mul_def, int.mul, nat_abs_neg_of_nat, eq_self_iff_true, int.nat_abs] lemma nat_abs_mul_nat_abs_eq {a b : ℤ} {c : ℕ} (h : a * b = (c : ℤ)) : a.nat_abs * b.nat_abs = c := by rw [← nat_abs_mul, h, nat_abs_of_nat] lemma nat_abs_mul_self' (a : ℤ) : (nat_abs a * nat_abs a : ℤ) = a * a := by rw [← int.coe_nat_mul, nat_abs_mul_self] theorem neg_succ_of_nat_eq' (m : ℕ) : -[1+ m] = -m - 1 := by simp [neg_succ_of_nat_eq, sub_eq_neg_add] lemma nat_abs_ne_zero_of_ne_zero {z : ℤ} (hz : z ≠ 0) : z.nat_abs ≠ 0 := λ h, hz $ int.eq_zero_of_nat_abs_eq_zero h @[simp] lemma nat_abs_eq_zero {a : ℤ} : a.nat_abs = 0 ↔ a = 0 := ⟨int.eq_zero_of_nat_abs_eq_zero, λ h, h.symm ▸ rfl⟩ lemma nat_abs_ne_zero {a : ℤ} : a.nat_abs ≠ 0 ↔ a ≠ 0 := not_congr int.nat_abs_eq_zero lemma nat_abs_lt_nat_abs_of_nonneg_of_lt {a b : ℤ} (w₁ : 0 ≤ a) (w₂ : a < b) : a.nat_abs < b.nat_abs := begin lift b to ℕ using le_trans w₁ (le_of_lt w₂), lift a to ℕ using w₁, simpa [coe_nat_lt] using w₂, end lemma nat_abs_eq_nat_abs_iff {a b : ℤ} : a.nat_abs = b.nat_abs ↔ a = b ∨ a = -b := begin split; intro h, { cases int.nat_abs_eq a with h₁ h₁; cases int.nat_abs_eq b with h₂ h₂; rw [h₁, h₂]; simp [h], }, { cases h; rw h, rw int.nat_abs_neg, }, end lemma nat_abs_eq_iff {a : ℤ} {n : ℕ} : a.nat_abs = n ↔ a = n ∨ a = -n := by rw [←int.nat_abs_eq_nat_abs_iff, int.nat_abs_of_nat] /-! ### `/` -/ @[simp] theorem of_nat_div (m n : ℕ) : of_nat (m / n) = (of_nat m) / (of_nat n) := rfl @[simp, norm_cast] theorem coe_nat_div (m n : ℕ) : ((m / n : ℕ) : ℤ) = m / n := rfl theorem neg_succ_of_nat_div (m : ℕ) {b : ℤ} (H : 0 < b) : -[1+m] / b = -(m / b + 1) := match b, eq_succ_of_zero_lt H with ._, ⟨n, rfl⟩ := rfl end -- Will be generalized to Euclidean domains. local attribute [simp] protected theorem zero_div : ∀ (b : ℤ), 0 / b = 0 | (n:ℕ) := show of_nat _ = _, by simp | -[1+ n] := show -of_nat _ = _, by simp local attribute [simp] -- Will be generalized to Euclidean domains. protected theorem div_zero : ∀ (a : ℤ), a / 0 = 0 | (n:ℕ) := show of_nat _ = _, by simp | -[1+ n] := rfl @[simp] protected theorem div_neg : ∀ (a b : ℤ), a / -b = -(a / b) | (m : ℕ) 0 := show of_nat (m / 0) = -(m / 0 : ℕ), by rw nat.div_zero; refl | (m : ℕ) (n+1:ℕ) := rfl | (m : ℕ) -[1+ n] := (neg_neg _).symm | -[1+ m] 0 := rfl | -[1+ m] (n+1:ℕ) := rfl | -[1+ m] -[1+ n] := rfl theorem div_of_neg_of_pos {a b : ℤ} (Ha : a < 0) (Hb : 0 < b) : a / b = -((-a - 1) / b + 1) := match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := by change (- -[1+ m] : ℤ) with (m+1 : ℤ); rw add_sub_cancel; refl end protected theorem div_nonneg {a b : ℤ} (Ha : 0 ≤ a) (Hb : 0 ≤ b) : 0 ≤ a / b := match a, b, eq_coe_of_zero_le Ha, eq_coe_of_zero_le Hb with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := coe_zero_le _ end theorem div_neg' {a b : ℤ} (Ha : a < 0) (Hb : 0 < b) : a / b < 0 := match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := neg_succ_lt_zero _ end @[simp] protected theorem div_one : ∀ (a : ℤ), a / 1 = a | (n:ℕ) := congr_arg of_nat (nat.div_one _) | -[1+ n] := congr_arg neg_succ_of_nat (nat.div_one _) theorem div_eq_zero_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a / b = 0 := match a, b, eq_coe_of_zero_le H1, eq_succ_of_zero_lt (lt_of_le_of_lt H1 H2), H2 with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 := congr_arg of_nat $ nat.div_eq_of_lt $ lt_of_coe_nat_lt_coe_nat H2 end /-! ### mod -/ theorem of_nat_mod (m n : nat) : (m % n : ℤ) = of_nat (m % n) := rfl @[simp, norm_cast] theorem coe_nat_mod (m n : ℕ) : (↑(m % n) : ℤ) = ↑m % ↑n := rfl theorem neg_succ_of_nat_mod (m : ℕ) {b : ℤ} (bpos : 0 < b) : -[1+m] % b = b - 1 - m % b := by rw [sub_sub, add_comm]; exact match b, eq_succ_of_zero_lt bpos with ._, ⟨n, rfl⟩ := rfl end @[simp] theorem mod_neg : ∀ (a b : ℤ), a % -b = a % b | (m : ℕ) n := @congr_arg ℕ ℤ _ _ (λ i, ↑(m % i)) (nat_abs_neg _) | -[1+ m] n := @congr_arg ℕ ℤ _ _ (λ i, sub_nat_nat i (nat.succ (m % i))) (nat_abs_neg _) local attribute [simp] -- Will be generalized to Euclidean domains. theorem zero_mod (b : ℤ) : 0 % b = 0 := rfl local attribute [simp] -- Will be generalized to Euclidean domains. theorem mod_zero : ∀ (a : ℤ), a % 0 = a | (m : ℕ) := congr_arg of_nat $ nat.mod_zero _ | -[1+ m] := congr_arg neg_succ_of_nat $ nat.mod_zero _ local attribute [simp] -- Will be generalized to Euclidean domains. theorem mod_one : ∀ (a : ℤ), a % 1 = 0 | (m : ℕ) := congr_arg of_nat $ nat.mod_one _ | -[1+ m] := show (1 - (m % 1).succ : ℤ) = 0, by rw nat.mod_one; refl theorem mod_eq_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a % b = a := match a, b, eq_coe_of_zero_le H1, eq_coe_of_zero_le (le_trans H1 (le_of_lt H2)), H2 with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 := congr_arg of_nat $ nat.mod_eq_of_lt (lt_of_coe_nat_lt_coe_nat H2) end theorem mod_add_div_aux (m n : ℕ) : (n - (m % n + 1) - (n * (m / n) + n) : ℤ) = -[1+ m] := begin rw [← sub_sub, neg_succ_of_nat_coe, sub_sub (n:ℤ), eq_comm, neg_eq_iff_eq_neg, neg_sub, sub_sub_self, add_right_comm], exact @congr_arg ℕ ℤ _ _ (λi, (i + 1 : ℤ)) (nat.mod_add_div _ _).symm end theorem mod_add_div : ∀ (a b : ℤ), a % b + b * (a / b) = a | (m : ℕ) (n : ℕ) := congr_arg of_nat (nat.mod_add_div _ _) | (m : ℕ) -[1+ n] := show (_ + -(n+1) * -((m) / (n + 1) : ℕ) : ℤ) = _, by rw [neg_mul_neg]; exact congr_arg of_nat (nat.mod_add_div _ _) | -[1+ m] 0 := by rw [mod_zero, int.div_zero]; refl | -[1+ m] (n+1:ℕ) := mod_add_div_aux m n.succ | -[1+ m] -[1+ n] := mod_add_div_aux m n.succ theorem div_add_mod (a b : ℤ) : b * (a / b) + a % b = a := (add_comm _ _).trans (mod_add_div _ _) lemma mod_add_div' (m k : ℤ) : m % k + (m / k) * k = m := by { rw mul_comm, exact mod_add_div _ _ } lemma div_add_mod' (m k : ℤ) : (m / k) * k + m % k = m := by { rw mul_comm, exact div_add_mod _ _ } theorem mod_def (a b : ℤ) : a % b = a - b * (a / b) := eq_sub_of_add_eq (mod_add_div _ _) /-! ### properties of `/` and `%` -/ @[simp] theorem mul_div_mul_of_pos {a : ℤ} (b c : ℤ) (H : 0 < a) : a * b / (a * c) = b / c := suffices ∀ (m k : ℕ) (b : ℤ), (m.succ * b / (m.succ * k) : ℤ) = b / k, from match a, eq_succ_of_zero_lt H, c, eq_coe_or_neg c with | ._, ⟨m, rfl⟩, ._, ⟨k, or.inl rfl⟩ := this _ _ _ | ._, ⟨m, rfl⟩, ._, ⟨k, or.inr rfl⟩ := by rw [mul_neg, int.div_neg, int.div_neg]; apply congr_arg has_neg.neg; apply this end, λ m k b, match b, k with | (n : ℕ), k := congr_arg of_nat (nat.mul_div_mul _ _ m.succ_pos) | -[1+ n], 0 := by rw [int.coe_nat_zero, mul_zero, int.div_zero, int.div_zero] | -[1+ n], k+1 := congr_arg neg_succ_of_nat $ show (m.succ * n + m) / (m.succ * k.succ) = n / k.succ, begin apply nat.div_eq_of_lt_le, { refine le_trans _ (nat.le_add_right _ _), rw [← nat.mul_div_mul _ _ m.succ_pos], apply nat.div_mul_le_self }, { change m.succ * n.succ ≤ _, rw [mul_left_comm], apply nat.mul_le_mul_left, apply (nat.div_lt_iff_lt_mul k.succ_pos).1, apply nat.lt_succ_self } end end @[simp] theorem mul_div_mul_of_pos_left (a : ℤ) {b : ℤ} (H : 0 < b) (c : ℤ) : a * b / (c * b) = a / c := by rw [mul_comm, mul_comm c, mul_div_mul_of_pos _ _ H] @[simp] theorem mul_mod_mul_of_pos {a : ℤ} (H : 0 < a) (b c : ℤ) : a * b % (a * c) = a * (b % c) := by rw [mod_def, mod_def, mul_div_mul_of_pos _ _ H, mul_sub_left_distrib, mul_assoc] theorem mul_div_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : b * (a / b) = a := by have := mod_add_div a b; rwa [H, zero_add] at this theorem div_mul_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : a / b * b = a := by rw [mul_comm, mul_div_cancel_of_mod_eq_zero H] lemma nat_abs_sign (z : ℤ) : z.sign.nat_abs = if z = 0 then 0 else 1 := by rcases z with (_ | _) | _; refl lemma nat_abs_sign_of_nonzero {z : ℤ} (hz : z ≠ 0) : z.sign.nat_abs = 1 := by rw [int.nat_abs_sign, if_neg hz] lemma sign_coe_nat_of_nonzero {n : ℕ} (hn : n ≠ 0) : int.sign n = 1 := begin obtain ⟨n, rfl⟩ := nat.exists_eq_succ_of_ne_zero hn, exact int.sign_of_succ n end @[simp] lemma sign_neg (z : ℤ) : int.sign (-z) = -int.sign z := by rcases z with (_ | _)| _; refl theorem div_sign : ∀ a b, a / sign b = a * sign b | a (n+1:ℕ) := by unfold sign; simp | a 0 := by simp [sign] | a -[1+ n] := by simp [sign] @[simp] theorem sign_mul : ∀ a b, sign (a * b) = sign a * sign b | a 0 := by simp | 0 b := by simp | (m+1:ℕ) (n+1:ℕ) := rfl | (m+1:ℕ) -[1+ n] := rfl | -[1+ m] (n+1:ℕ) := rfl | -[1+ m] -[1+ n] := rfl theorem mul_sign : ∀ (i : ℤ), i * sign i = nat_abs i | (n+1:ℕ) := mul_one _ | 0 := mul_zero _ | -[1+ n] := mul_neg_one _ theorem of_nat_add_neg_succ_of_nat_of_lt {m n : ℕ} (h : m < n.succ) : of_nat m + -[1+n] = -[1+ n - m] := begin change sub_nat_nat _ _ = _, have h' : n.succ - m = (n - m).succ, apply succ_sub, apply le_of_lt_succ h, simp [*, sub_nat_nat] end @[simp] theorem neg_add_neg (m n : ℕ) : -[1+m] + -[1+n] = -[1+nat.succ(m+n)] := rfl /-! ### to_nat -/ theorem to_nat_eq_max : ∀ (a : ℤ), (to_nat a : ℤ) = max a 0 | (n : ℕ) := (max_eq_left (coe_zero_le n)).symm | -[1+ n] := (max_eq_right (le_of_lt (neg_succ_lt_zero n))).symm @[simp] lemma to_nat_zero : (0 : ℤ).to_nat = 0 := rfl @[simp] lemma to_nat_one : (1 : ℤ).to_nat = 1 := rfl @[simp] theorem to_nat_of_nonneg {a : ℤ} (h : 0 ≤ a) : (to_nat a : ℤ) = a := by rw [to_nat_eq_max, max_eq_left h] @[simp] theorem to_nat_coe_nat (n : ℕ) : to_nat ↑n = n := rfl @[simp] lemma to_nat_coe_nat_add_one {n : ℕ} : ((n : ℤ) + 1).to_nat = n + 1 := rfl theorem le_to_nat (a : ℤ) : a ≤ to_nat a := by rw [to_nat_eq_max]; apply le_max_left @[simp]lemma le_to_nat_iff {n : ℕ} {z : ℤ} (h : 0 ≤ z) : n ≤ z.to_nat ↔ (n : ℤ) ≤ z := by rw [←int.coe_nat_le_coe_nat_iff, int.to_nat_of_nonneg h] lemma to_nat_add {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : (a + b).to_nat = a.to_nat + b.to_nat := begin lift a to ℕ using ha, lift b to ℕ using hb, norm_cast, end lemma to_nat_add_nat {a : ℤ} (ha : 0 ≤ a) (n : ℕ) : (a + n).to_nat = a.to_nat + n := begin lift a to ℕ using ha, norm_cast, end @[simp] lemma pred_to_nat : ∀ (i : ℤ), (i - 1).to_nat = i.to_nat - 1 | (0:ℕ) := rfl | (n+1:ℕ) := by simp | -[1+ n] := rfl @[simp] lemma to_nat_sub_to_nat_neg : ∀ (n : ℤ), ↑n.to_nat - ↑((-n).to_nat) = n | (0 : ℕ) := rfl | (n+1 : ℕ) := show ↑(n+1) - (0:ℤ) = n+1, from sub_zero _ | -[1+ n] := show 0 - (n+1 : ℤ) = _, from zero_sub _ @[simp] lemma to_nat_add_to_nat_neg_eq_nat_abs : ∀ (n : ℤ), (n.to_nat) + ((-n).to_nat) = n.nat_abs | (0 : ℕ) := rfl | (n+1 : ℕ) := show (n+1) + 0 = n+1, from add_zero _ | -[1+ n] := show 0 + (n+1) = n+1, from zero_add _ /-- If `n : ℕ`, then `int.to_nat' n = some n`, if `n : ℤ` is negative, then `int.to_nat' n = none`. -/ def to_nat' : ℤ → option ℕ | (n : ℕ) := some n | -[1+ n] := none theorem mem_to_nat' : ∀ (a : ℤ) (n : ℕ), n ∈ to_nat' a ↔ a = n | (m : ℕ) n := option.some_inj.trans coe_nat_inj'.symm | -[1+ m] n := by split; intro h; cases h @[simp] lemma to_nat_neg_nat : ∀ (n : ℕ), (-(n : ℤ)).to_nat = 0 | 0 := rfl | (n + 1) := rfl end int attribute [irreducible] int.nonneg
e66c5b5303737d583eb25e3f8368f0d4801a40d9
4727251e0cd73359b15b664c3170e5d754078599
/src/topology/maps.lean
3dcbb381db24871d25ebbd8ca1d4880db722664a
[ "Apache-2.0" ]
permissive
Vierkantor/mathlib
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
refs/heads/master
1,658,323,012,449
1,652,256,003,000
1,652,256,003,000
209,296,341
0
1
Apache-2.0
1,568,807,655,000
1,568,807,655,000
null
UTF-8
Lean
false
false
23,771
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 -/ import topology.order /-! # Specific classes of maps between topological spaces This file introduces the following properties of a map `f : X → Y` between topological spaces: * `is_open_map f` means the image of an open set under `f` is open. * `is_closed_map f` means the image of a closed set under `f` is closed. (Open and closed maps need not be continuous.) * `inducing f` means the topology on `X` is the one induced via `f` from the topology on `Y`. These behave like embeddings except they need not be injective. Instead, points of `X` which are identified by `f` are also indistinguishable in the topology on `X`. * `embedding f` means `f` is inducing and also injective. Equivalently, `f` identifies `X` with a subspace of `Y`. * `open_embedding f` means `f` is an embedding with open image, so it identifies `X` with an open subspace of `Y`. Equivalently, `f` is an embedding and an open map. * `closed_embedding f` similarly means `f` is an embedding with closed image, so it identifies `X` with a closed subspace of `Y`. Equivalently, `f` is an embedding and a closed map. * `quotient_map f` is the dual condition to `embedding f`: `f` is surjective and the topology on `Y` is the one coinduced via `f` from the topology on `X`. Equivalently, `f` identifies `Y` with a quotient of `X`. Quotient maps are also sometimes known as identification maps. ## References * <https://en.wikipedia.org/wiki/Open_and_closed_maps> * <https://en.wikipedia.org/wiki/Embedding#General_topology> * <https://en.wikipedia.org/wiki/Quotient_space_(topology)#Quotient_map> ## Tags open map, closed map, embedding, quotient map, identification map -/ open set filter open_locale topological_space filter variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} section inducing /-- A function `f : α → β` between topological spaces is inducing if the topology on `α` is induced by the topology on `β` through `f`, meaning that a set `s : set α` is open iff it is the preimage under `f` of some open set `t : set β`. -/ structure inducing [tα : topological_space α] [tβ : topological_space β] (f : α → β) : Prop := (induced : tα = tβ.induced f) variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ] lemma inducing_id : inducing (@id α) := ⟨induced_id.symm⟩ protected lemma inducing.comp {g : β → γ} {f : α → β} (hg : inducing g) (hf : inducing f) : inducing (g ∘ f) := ⟨by rw [hf.induced, hg.induced, induced_compose]⟩ lemma inducing_of_inducing_compose {f : α → β} {g : β → γ} (hf : continuous f) (hg : continuous g) (hgf : inducing (g ∘ f)) : inducing f := ⟨le_antisymm (by rwa ← continuous_iff_le_induced) (by { rw [hgf.induced, ← continuous_iff_le_induced], apply hg.comp continuous_induced_dom })⟩ lemma inducing.nhds_eq_comap {f : α → β} (hf : inducing f) : ∀ (a : α), 𝓝 a = comap f (𝓝 $ f a) := (induced_iff_nhds_eq f).1 hf.induced lemma inducing.map_nhds_eq {f : α → β} (hf : inducing f) (a : α) : (𝓝 a).map f = 𝓝[range f] (f a) := hf.induced.symm ▸ map_nhds_induced_eq a lemma inducing.map_nhds_of_mem {f : α → β} (hf : inducing f) (a : α) (h : range f ∈ 𝓝 (f a)) : (𝓝 a).map f = 𝓝 (f a) := hf.induced.symm ▸ map_nhds_induced_of_mem h lemma inducing.image_mem_nhds_within {f : α → β} (hf : inducing f) {a : α} {s : set α} (hs : s ∈ 𝓝 a) : f '' s ∈ 𝓝[range f] (f a) := hf.map_nhds_eq a ▸ image_mem_map hs lemma inducing.tendsto_nhds_iff {ι : Type*} {f : ι → β} {g : β → γ} {a : filter ι} {b : β} (hg : inducing g) : tendsto f a (𝓝 b) ↔ tendsto (g ∘ f) a (𝓝 (g b)) := by rw [hg.nhds_eq_comap, tendsto_comap_iff] lemma inducing.continuous_at_iff {f : α → β} {g : β → γ} (hg : inducing g) {x : α} : continuous_at f x ↔ continuous_at (g ∘ f) x := by simp_rw [continuous_at, inducing.tendsto_nhds_iff hg] lemma inducing.continuous_iff {f : α → β} {g : β → γ} (hg : inducing g) : continuous f ↔ continuous (g ∘ f) := by simp_rw [continuous_iff_continuous_at, hg.continuous_at_iff] lemma inducing.continuous_at_iff' {f : α → β} {g : β → γ} (hf : inducing f) {x : α} (h : range f ∈ 𝓝 (f x)) : continuous_at (g ∘ f) x ↔ continuous_at g (f x) := by { simp_rw [continuous_at, filter.tendsto, ← hf.map_nhds_of_mem _ h, filter.map_map] } protected lemma inducing.continuous {f : α → β} (hf : inducing f) : continuous f := hf.continuous_iff.mp continuous_id protected lemma inducing.inducing_iff {f : α → β} {g : β → γ} (hg : inducing g) : inducing f ↔ inducing (g ∘ f) := begin refine ⟨λ h, hg.comp h, λ hgf, inducing_of_inducing_compose _ hg.continuous hgf⟩, rw hg.continuous_iff, exact hgf.continuous end lemma inducing.closure_eq_preimage_closure_image {f : α → β} (hf : inducing f) (s : set α) : closure s = f ⁻¹' closure (f '' s) := by { ext x, rw [set.mem_preimage, ← closure_induced, hf.induced] } lemma inducing.is_closed_iff {f : α → β} (hf : inducing f) {s : set α} : is_closed s ↔ ∃ t, is_closed t ∧ f ⁻¹' t = s := by rw [hf.induced, is_closed_induced_iff] lemma inducing.is_closed_iff' {f : α → β} (hf : inducing f) {s : set α} : is_closed s ↔ ∀ x, f x ∈ closure (f '' s) → x ∈ s := by rw [hf.induced, is_closed_induced_iff'] lemma inducing.is_open_iff {f : α → β} (hf : inducing f) {s : set α} : is_open s ↔ ∃ t, is_open t ∧ f ⁻¹' t = s := by rw [hf.induced, is_open_induced_iff] end inducing section embedding /-- A function between topological spaces is an embedding if it is injective, and for all `s : set α`, `s` is open iff it is the preimage of an open set. -/ structure embedding [tα : topological_space α] [tβ : topological_space β] (f : α → β) extends inducing f : Prop := (inj : function.injective f) lemma function.injective.embedding_induced [t : topological_space β] {f : α → β} (hf : function.injective f) : @embedding α β (t.induced f) t f := { induced := rfl, inj := hf } variables [topological_space α] [topological_space β] [topological_space γ] lemma embedding.mk' (f : α → β) (inj : function.injective f) (induced : ∀a, comap f (𝓝 (f a)) = 𝓝 a) : embedding f := ⟨⟨(induced_iff_nhds_eq f).2 (λ a, (induced a).symm)⟩, inj⟩ lemma embedding_id : embedding (@id α) := ⟨inducing_id, assume a₁ a₂ h, h⟩ lemma embedding.comp {g : β → γ} {f : α → β} (hg : embedding g) (hf : embedding f) : embedding (g ∘ f) := { inj:= assume a₁ a₂ h, hf.inj $ hg.inj h, ..hg.to_inducing.comp hf.to_inducing } lemma embedding_of_embedding_compose {f : α → β} {g : β → γ} (hf : continuous f) (hg : continuous g) (hgf : embedding (g ∘ f)) : embedding f := { induced := (inducing_of_inducing_compose hf hg hgf.to_inducing).induced, inj := assume a₁ a₂ h, hgf.inj $ by simp [h, (∘)] } protected lemma function.left_inverse.embedding {f : α → β} {g : β → α} (h : function.left_inverse f g) (hf : continuous f) (hg : continuous g) : embedding g := embedding_of_embedding_compose hg hf $ h.comp_eq_id.symm ▸ embedding_id lemma embedding.map_nhds_eq {f : α → β} (hf : embedding f) (a : α) : (𝓝 a).map f = 𝓝[range f] (f a) := hf.1.map_nhds_eq a lemma embedding.map_nhds_of_mem {f : α → β} (hf : embedding f) (a : α) (h : range f ∈ 𝓝 (f a)) : (𝓝 a).map f = 𝓝 (f a) := hf.1.map_nhds_of_mem a h lemma embedding.tendsto_nhds_iff {ι : Type*} {f : ι → β} {g : β → γ} {a : filter ι} {b : β} (hg : embedding g) : tendsto f a (𝓝 b) ↔ tendsto (g ∘ f) a (𝓝 (g b)) := hg.to_inducing.tendsto_nhds_iff lemma embedding.continuous_iff {f : α → β} {g : β → γ} (hg : embedding g) : continuous f ↔ continuous (g ∘ f) := inducing.continuous_iff hg.1 lemma embedding.continuous {f : α → β} (hf : embedding f) : continuous f := inducing.continuous hf.1 lemma embedding.closure_eq_preimage_closure_image {e : α → β} (he : embedding e) (s : set α) : closure s = e ⁻¹' closure (e '' s) := he.1.closure_eq_preimage_closure_image s end embedding /-- A function between topological spaces is a quotient map if it is surjective, and for all `s : set β`, `s` is open iff its preimage is an open set. -/ def quotient_map {α : Type*} {β : Type*} [tα : topological_space α] [tβ : topological_space β] (f : α → β) : Prop := function.surjective f ∧ tβ = tα.coinduced f lemma quotient_map_iff {α β : Type*} [topological_space α] [topological_space β] {f : α → β} : quotient_map f ↔ function.surjective f ∧ ∀ s : set β, is_open s ↔ is_open (f ⁻¹' s) := and_congr iff.rfl topological_space_eq_iff namespace quotient_map variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ] {g : β → γ} {f : α → β} protected lemma id : quotient_map (@id α) := ⟨assume a, ⟨a, rfl⟩, coinduced_id.symm⟩ protected lemma comp (hg : quotient_map g) (hf : quotient_map f) : quotient_map (g ∘ f) := ⟨hg.left.comp hf.left, by rw [hg.right, hf.right, coinduced_compose]⟩ protected lemma of_quotient_map_compose (hf : continuous f) (hg : continuous g) (hgf : quotient_map (g ∘ f)) : quotient_map g := ⟨hgf.1.of_comp, le_antisymm (by { rw [hgf.right, ← continuous_iff_coinduced_le], apply continuous_coinduced_rng.comp hf }) (by rwa ← continuous_iff_coinduced_le)⟩ protected lemma continuous_iff (hf : quotient_map f) : continuous g ↔ continuous (g ∘ f) := by rw [continuous_iff_coinduced_le, continuous_iff_coinduced_le, hf.right, coinduced_compose] protected lemma continuous (hf : quotient_map f) : continuous f := hf.continuous_iff.mp continuous_id protected lemma surjective (hf : quotient_map f) : function.surjective f := hf.1 protected lemma is_open_preimage (hf : quotient_map f) {s : set β} : is_open (f ⁻¹' s) ↔ is_open s := ((quotient_map_iff.1 hf).2 s).symm protected lemma is_closed_preimage (hf : quotient_map f) {s : set β} : is_closed (f ⁻¹' s) ↔ is_closed s := by simp only [← is_open_compl_iff, ← preimage_compl, hf.is_open_preimage] end quotient_map /-- A map `f : α → β` is said to be an *open map*, if the image of any open `U : set α` is open in `β`. -/ def is_open_map [topological_space α] [topological_space β] (f : α → β) := ∀ U : set α, is_open U → is_open (f '' U) namespace is_open_map variables [topological_space α] [topological_space β] [topological_space γ] {f : α → β} open function protected lemma id : is_open_map (@id α) := assume s hs, by rwa [image_id] protected lemma comp {g : β → γ} {f : α → β} (hg : is_open_map g) (hf : is_open_map f) : is_open_map (g ∘ f) := by intros s hs; rw [image_comp]; exact hg _ (hf _ hs) lemma is_open_range (hf : is_open_map f) : is_open (range f) := by { rw ← image_univ, exact hf _ is_open_univ } lemma image_mem_nhds (hf : is_open_map f) {x : α} {s : set α} (hx : s ∈ 𝓝 x) : f '' s ∈ 𝓝 (f x) := let ⟨t, hts, ht, hxt⟩ := mem_nhds_iff.1 hx in mem_of_superset (is_open.mem_nhds (hf t ht) (mem_image_of_mem _ hxt)) (image_subset _ hts) lemma maps_to_interior (hf : is_open_map f) {s : set α} {t : set β} (h : maps_to f s t) : maps_to f (interior s) (interior t) := maps_to'.2 $ interior_maximal (h.mono interior_subset subset.rfl).image_subset (hf _ is_open_interior) lemma image_interior_subset (hf : is_open_map f) (s : set α) : f '' interior s ⊆ interior (f '' s) := (hf.maps_to_interior (maps_to_image f s)).image_subset lemma nhds_le (hf : is_open_map f) (a : α) : 𝓝 (f a) ≤ (𝓝 a).map f := le_map $ λ s, hf.image_mem_nhds lemma of_nhds_le (hf : ∀ a, 𝓝 (f a) ≤ map f (𝓝 a)) : is_open_map f := λ s hs, is_open_iff_mem_nhds.2 $ λ b ⟨a, has, hab⟩, hab ▸ hf _ (image_mem_map $ is_open.mem_nhds hs has) lemma of_sections {f : α → β} (h : ∀ x, ∃ g : β → α, continuous_at g (f x) ∧ g (f x) = x ∧ right_inverse g f) : is_open_map f := of_nhds_le $ λ x, let ⟨g, hgc, hgx, hgf⟩ := h x in calc 𝓝 (f x) = map f (map g (𝓝 (f x))) : by rw [map_map, hgf.comp_eq_id, map_id] ... ≤ map f (𝓝 (g (f x))) : map_mono hgc ... = map f (𝓝 x) : by rw hgx lemma of_inverse {f : α → β} {f' : β → α} (h : continuous f') (l_inv : left_inverse f f') (r_inv : right_inverse f f') : is_open_map f := of_sections $ λ x, ⟨f', h.continuous_at, r_inv _, l_inv⟩ /-- A continuous surjective open map is a quotient map. -/ lemma to_quotient_map {f : α → β} (open_map : is_open_map f) (cont : continuous f) (surj : surjective f) : quotient_map f := quotient_map_iff.2 ⟨surj, λ s, ⟨λ h, h.preimage cont, λ h, surj.image_preimage s ▸ open_map _ h⟩⟩ lemma interior_preimage_subset_preimage_interior (hf : is_open_map f) {s : set β} : interior (f⁻¹' s) ⊆ f⁻¹' (interior s) := hf.maps_to_interior (maps_to_preimage _ _) lemma preimage_interior_eq_interior_preimage (hf₁ : is_open_map f) (hf₂ : continuous f) (s : set β) : f⁻¹' (interior s) = interior (f⁻¹' s) := subset.antisymm (preimage_interior_subset_interior_preimage hf₂) (interior_preimage_subset_preimage_interior hf₁) lemma preimage_closure_subset_closure_preimage (hf : is_open_map f) {s : set β} : f ⁻¹' (closure s) ⊆ closure (f ⁻¹' s) := begin rw ← compl_subset_compl, simp only [← interior_compl, ← preimage_compl, hf.interior_preimage_subset_preimage_interior] end lemma preimage_closure_eq_closure_preimage (hf : is_open_map f) (hfc : continuous f) (s : set β) : f ⁻¹' (closure s) = closure (f ⁻¹' s) := hf.preimage_closure_subset_closure_preimage.antisymm (hfc.closure_preimage_subset s) lemma preimage_frontier_subset_frontier_preimage (hf : is_open_map f) {s : set β} : f ⁻¹' (frontier s) ⊆ frontier (f ⁻¹' s) := by simpa only [frontier_eq_closure_inter_closure, preimage_inter] using inter_subset_inter hf.preimage_closure_subset_closure_preimage hf.preimage_closure_subset_closure_preimage lemma preimage_frontier_eq_frontier_preimage (hf : is_open_map f) (hfc : continuous f) (s : set β) : f ⁻¹' (frontier s) = frontier (f ⁻¹' s) := by simp only [frontier_eq_closure_inter_closure, preimage_inter, preimage_compl, hf.preimage_closure_eq_closure_preimage hfc] end is_open_map lemma is_open_map_iff_nhds_le [topological_space α] [topological_space β] {f : α → β} : is_open_map f ↔ ∀(a:α), 𝓝 (f a) ≤ (𝓝 a).map f := ⟨λ hf, hf.nhds_le, is_open_map.of_nhds_le⟩ lemma is_open_map_iff_interior [topological_space α] [topological_space β] {f : α → β} : is_open_map f ↔ ∀ s, f '' (interior s) ⊆ interior (f '' s) := ⟨is_open_map.image_interior_subset, λ hs u hu, subset_interior_iff_open.mp $ calc f '' u = f '' (interior u) : by rw hu.interior_eq ... ⊆ interior (f '' u) : hs u⟩ /-- An inducing map with an open range is an open map. -/ protected lemma inducing.is_open_map [topological_space α] [topological_space β] {f : α → β} (hi : inducing f) (ho : is_open (range f)) : is_open_map f := is_open_map.of_nhds_le $ λ x, (hi.map_nhds_of_mem _ $ is_open.mem_nhds ho $ mem_range_self _).ge section is_closed_map variables [topological_space α] [topological_space β] /-- A map `f : α → β` is said to be a *closed map*, if the image of any closed `U : set α` is closed in `β`. -/ def is_closed_map (f : α → β) := ∀ U : set α, is_closed U → is_closed (f '' U) end is_closed_map namespace is_closed_map variables [topological_space α] [topological_space β] [topological_space γ] open function protected lemma id : is_closed_map (@id α) := assume s hs, by rwa image_id protected lemma comp {g : β → γ} {f : α → β} (hg : is_closed_map g) (hf : is_closed_map f) : is_closed_map (g ∘ f) := by { intros s hs, rw image_comp, exact hg _ (hf _ hs) } lemma closure_image_subset {f : α → β} (hf : is_closed_map f) (s : set α) : closure (f '' s) ⊆ f '' closure s := closure_minimal (image_subset _ subset_closure) (hf _ is_closed_closure) lemma of_inverse {f : α → β} {f' : β → α} (h : continuous f') (l_inv : left_inverse f f') (r_inv : right_inverse f f') : is_closed_map f := assume s hs, have f' ⁻¹' s = f '' s, by ext x; simp [mem_image_iff_of_inverse r_inv l_inv], this ▸ hs.preimage h lemma of_nonempty {f : α → β} (h : ∀ s, is_closed s → s.nonempty → is_closed (f '' s)) : is_closed_map f := begin intros s hs, cases eq_empty_or_nonempty s with h2s h2s, { simp_rw [h2s, image_empty, is_closed_empty] }, { exact h s hs h2s } end lemma closed_range {f : α → β} (hf : is_closed_map f) : is_closed (range f) := @image_univ _ _ f ▸ hf _ is_closed_univ end is_closed_map lemma inducing.is_closed_map [topological_space α] [topological_space β] {f : α → β} (hf : inducing f) (h : is_closed (range f)) : is_closed_map f := begin intros s hs, rcases hf.is_closed_iff.1 hs with ⟨t, ht, rfl⟩, rw image_preimage_eq_inter_range, exact ht.inter h end lemma is_closed_map_iff_closure_image [topological_space α] [topological_space β] {f : α → β} : is_closed_map f ↔ ∀ s, closure (f '' s) ⊆ f '' closure s := ⟨is_closed_map.closure_image_subset, λ hs c hc, is_closed_of_closure_subset $ calc closure (f '' c) ⊆ f '' (closure c) : hs c ... = f '' c : by rw hc.closure_eq⟩ section open_embedding variables [topological_space α] [topological_space β] [topological_space γ] /-- An open embedding is an embedding with open image. -/ structure open_embedding (f : α → β) extends embedding f : Prop := (open_range : is_open $ range f) lemma open_embedding.is_open_map {f : α → β} (hf : open_embedding f) : is_open_map f := hf.to_embedding.to_inducing.is_open_map hf.open_range lemma open_embedding.map_nhds_eq {f : α → β} (hf : open_embedding f) (a : α) : map f (𝓝 a) = 𝓝 (f a) := hf.to_embedding.map_nhds_of_mem _ $ hf.open_range.mem_nhds $ mem_range_self _ lemma open_embedding.open_iff_image_open {f : α → β} (hf : open_embedding f) {s : set α} : is_open s ↔ is_open (f '' s) := ⟨hf.is_open_map s, λ h, begin convert ← h.preimage hf.to_embedding.continuous, apply preimage_image_eq _ hf.inj end⟩ lemma open_embedding.tendsto_nhds_iff {ι : Type*} {f : ι → β} {g : β → γ} {a : filter ι} {b : β} (hg : open_embedding g) : tendsto f a (𝓝 b) ↔ tendsto (g ∘ f) a (𝓝 (g b)) := hg.to_embedding.tendsto_nhds_iff lemma open_embedding.continuous {f : α → β} (hf : open_embedding f) : continuous f := hf.to_embedding.continuous lemma open_embedding.open_iff_preimage_open {f : α → β} (hf : open_embedding f) {s : set β} (hs : s ⊆ range f) : is_open s ↔ is_open (f ⁻¹' s) := begin convert ←hf.open_iff_image_open.symm, rwa [image_preimage_eq_inter_range, inter_eq_self_of_subset_left] end lemma open_embedding_of_embedding_open {f : α → β} (h₁ : embedding f) (h₂ : is_open_map f) : open_embedding f := ⟨h₁, h₂.is_open_range⟩ lemma open_embedding_of_continuous_injective_open {f : α → β} (h₁ : continuous f) (h₂ : function.injective f) (h₃ : is_open_map f) : open_embedding f := begin refine open_embedding_of_embedding_open ⟨⟨_⟩, h₂⟩ h₃, apply le_antisymm (continuous_iff_le_induced.mp h₁) _, intro s, change is_open _ → is_open _, rw is_open_induced_iff, refine λ hs, ⟨f '' s, h₃ s hs, _⟩, rw preimage_image_eq _ h₂ end lemma open_embedding_id : open_embedding (@id α) := ⟨embedding_id, is_open_map.id.is_open_range⟩ lemma open_embedding.comp {g : β → γ} {f : α → β} (hg : open_embedding g) (hf : open_embedding f) : open_embedding (g ∘ f) := ⟨hg.1.comp hf.1, (hg.is_open_map.comp hf.is_open_map).is_open_range⟩ lemma open_embedding_of_open_embedding_compose {α β γ : Type*} [topological_space α] [topological_space β] [topological_space γ] (f : α → β) {g : β → γ} (hg : open_embedding g) (h : open_embedding (g ∘ f)) : open_embedding f := begin have hf := hg.to_embedding.continuous_iff.mpr h.continuous, split, { exact embedding_of_embedding_compose hf hg.continuous h.to_embedding }, { rw [hg.open_iff_image_open, ← set.image_univ, ← set.image_comp, ← h.open_iff_image_open], exact is_open_univ } end lemma open_embedding_iff_open_embedding_compose {α β γ : Type*} [topological_space α] [topological_space β] [topological_space γ] (f : α → β) {g : β → γ} (hg : open_embedding g) : open_embedding (g ∘ f) ↔ open_embedding f := ⟨open_embedding_of_open_embedding_compose f hg, hg.comp⟩ end open_embedding section closed_embedding variables [topological_space α] [topological_space β] [topological_space γ] /-- A closed embedding is an embedding with closed image. -/ structure closed_embedding (f : α → β) extends embedding f : Prop := (closed_range : is_closed $ range f) variables {f : α → β} lemma closed_embedding.tendsto_nhds_iff {ι : Type*} {g : ι → α} {a : filter ι} {b : α} (hf : closed_embedding f) : tendsto g a (𝓝 b) ↔ tendsto (f ∘ g) a (𝓝 (f b)) := hf.to_embedding.tendsto_nhds_iff lemma closed_embedding.continuous (hf : closed_embedding f) : continuous f := hf.to_embedding.continuous lemma closed_embedding.is_closed_map (hf : closed_embedding f) : is_closed_map f := hf.to_embedding.to_inducing.is_closed_map hf.closed_range lemma closed_embedding.closed_iff_image_closed (hf : closed_embedding f) {s : set α} : is_closed s ↔ is_closed (f '' s) := ⟨hf.is_closed_map s, λ h, begin convert ←continuous_iff_is_closed.mp hf.continuous _ h, apply preimage_image_eq _ hf.inj end⟩ lemma closed_embedding.closed_iff_preimage_closed (hf : closed_embedding f) {s : set β} (hs : s ⊆ range f) : is_closed s ↔ is_closed (f ⁻¹' s) := begin convert ←hf.closed_iff_image_closed.symm, rwa [image_preimage_eq_inter_range, inter_eq_self_of_subset_left] end lemma closed_embedding_of_embedding_closed (h₁ : embedding f) (h₂ : is_closed_map f) : closed_embedding f := ⟨h₁, by convert h₂ univ is_closed_univ; simp⟩ lemma closed_embedding_of_continuous_injective_closed (h₁ : continuous f) (h₂ : function.injective f) (h₃ : is_closed_map f) : closed_embedding f := begin refine closed_embedding_of_embedding_closed ⟨⟨_⟩, h₂⟩ h₃, apply le_antisymm (continuous_iff_le_induced.mp h₁) _, intro s', change is_open _ ≤ is_open _, rw [←is_closed_compl_iff, ←is_closed_compl_iff], generalize : s'ᶜ = s, rw is_closed_induced_iff, refine λ hs, ⟨f '' s, h₃ s hs, _⟩, rw preimage_image_eq _ h₂ end lemma closed_embedding_id : closed_embedding (@id α) := ⟨embedding_id, by convert is_closed_univ; apply range_id⟩ lemma closed_embedding.comp {g : β → γ} {f : α → β} (hg : closed_embedding g) (hf : closed_embedding f) : closed_embedding (g ∘ f) := ⟨hg.to_embedding.comp hf.to_embedding, show is_closed (range (g ∘ f)), by rw [range_comp, ←hg.closed_iff_image_closed]; exact hf.closed_range⟩ lemma closed_embedding.closure_image_eq {f : α → β} (hf : closed_embedding f) (s : set α) : closure (f '' s) = f '' closure s := le_antisymm (is_closed_map_iff_closure_image.mp hf.is_closed_map _) (image_closure_subset_closure_image hf.continuous) end closed_embedding
8190c31772f59e2ee594668441f81d010ed1370e
7b89826c26634aa18c0110f1634f73027851edfe
/natural-number-game/src/world01/level03.lean
ec4fc3fc5324f5a94a0b3b796f2221b929a54377
[ "MIT" ]
permissive
marcofavorito/leanings
b7642344d8c9012a1cec74a804c5884297880c4d
581b83be66ff4f8dd946fb6a1bb045d2ddf91076
refs/heads/master
1,672,310,991,244
1,603,031,766,000
1,603,031,766,000
279,163,004
1
0
null
null
null
null
UTF-8
Lean
false
false
237
lean
import mynat.definition -- import Peano's definition of the natural numbers {0,1,2,3,4,...} namespace mynat lemma example3 (a b : mynat) (h : succ a = b) : succ(succ(a)) = succ(b) := begin [nat_num_game] rw h, refl, end end mynat
f650cff3bfba66849d6697c0bd476c6b5cbd78aa
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/linear_algebra/eigenspace/is_alg_closed.lean
1b896aa946d8259db8898f40ed18dbe6039f916f
[ "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
5,454
lean
/- Copyright (c) 2020 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp -/ import linear_algebra.eigenspace.basic import field_theory.is_alg_closed.spectrum /-! # Eigenvectors and eigenvalues over algebraically closed fields. > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. * Every linear operator on a vector space over an algebraically closed field has an eigenvalue. * The generalized eigenvectors span the entire vector space. ## References * [Sheldon Axler, *Linear Algebra Done Right*][axler2015] * https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors ## Tags eigenspace, eigenvector, eigenvalue, eigen -/ universes u v w namespace module namespace End open finite_dimensional variables {K : Type v} {V : Type w} [field K] [add_comm_group V] [module K V] /-- Every linear operator on a vector space over an algebraically closed field has an eigenvalue. -/ -- This is Lemma 5.21 of [axler2015], although we are no longer following that proof. lemma exists_eigenvalue [is_alg_closed K] [finite_dimensional K V] [nontrivial V] (f : End K V) : ∃ (c : K), f.has_eigenvalue c := by { simp_rw has_eigenvalue_iff_mem_spectrum, exact spectrum.nonempty_of_is_alg_closed_of_finite_dimensional K f } noncomputable instance [is_alg_closed K] [finite_dimensional K V] [nontrivial V] (f : End K V) : inhabited f.eigenvalues := ⟨⟨f.exists_eigenvalue.some, f.exists_eigenvalue.some_spec⟩⟩ /-- The generalized eigenvectors span the entire vector space (Lemma 8.21 of [axler2015]). -/ lemma supr_generalized_eigenspace_eq_top [is_alg_closed K] [finite_dimensional K V] (f : End K V) : (⨆ (μ : K) (k : ℕ), f.generalized_eigenspace μ k) = ⊤ := begin -- We prove the claim by strong induction on the dimension of the vector space. unfreezingI { induction h_dim : finrank K V using nat.strong_induction_on with n ih generalizing V }, cases n, -- If the vector space is 0-dimensional, the result is trivial. { rw ←top_le_iff, simp only [finrank_eq_zero.1 (eq.trans (finrank_top _ _) h_dim), bot_le] }, -- Otherwise the vector space is nontrivial. { haveI : nontrivial V := finrank_pos_iff.1 (by { rw h_dim, apply nat.zero_lt_succ }), -- Hence, `f` has an eigenvalue `μ₀`. obtain ⟨μ₀, hμ₀⟩ : ∃ μ₀, f.has_eigenvalue μ₀ := exists_eigenvalue f, -- We define `ES` to be the generalized eigenspace let ES := f.generalized_eigenspace μ₀ (finrank K V), -- and `ER` to be the generalized eigenrange. let ER := f.generalized_eigenrange μ₀ (finrank K V), -- `f` maps `ER` into itself. have h_f_ER : ∀ (x : V), x ∈ ER → f x ∈ ER, from λ x hx, map_generalized_eigenrange_le (submodule.mem_map_of_mem hx), -- Therefore, we can define the restriction `f'` of `f` to `ER`. let f' : End K ER := f.restrict h_f_ER, -- The dimension of `ES` is positive have h_dim_ES_pos : 0 < finrank K ES, { dsimp only [ES], rw h_dim, apply pos_finrank_generalized_eigenspace_of_has_eigenvalue hμ₀ (nat.zero_lt_succ n) }, -- and the dimensions of `ES` and `ER` add up to `finrank K V`. have h_dim_add : finrank K ER + finrank K ES = finrank K V, { apply linear_map.finrank_range_add_finrank_ker }, -- Therefore the dimension `ER` mus be smaller than `finrank K V`. have h_dim_ER : finrank K ER < n.succ, by linarith, -- This allows us to apply the induction hypothesis on `ER`: have ih_ER : (⨆ (μ : K) (k : ℕ), f'.generalized_eigenspace μ k) = ⊤, from ih (finrank K ER) h_dim_ER f' rfl, -- The induction hypothesis gives us a statement about subspaces of `ER`. We can transfer this -- to a statement about subspaces of `V` via `submodule.subtype`: have ih_ER' : (⨆ (μ : K) (k : ℕ), (f'.generalized_eigenspace μ k).map ER.subtype) = ER, by simp only [(submodule.map_supr _ _).symm, ih_ER, submodule.map_subtype_top ER], -- Moreover, every generalized eigenspace of `f'` is contained in the corresponding generalized -- eigenspace of `f`. have hff' : ∀ μ k, (f'.generalized_eigenspace μ k).map ER.subtype ≤ f.generalized_eigenspace μ k, { intros, rw generalized_eigenspace_restrict, apply submodule.map_comap_le }, -- It follows that `ER` is contained in the span of all generalized eigenvectors. have hER : ER ≤ ⨆ (μ : K) (k : ℕ), f.generalized_eigenspace μ k, { rw ← ih_ER', exact supr₂_mono hff' }, -- `ES` is contained in this span by definition. have hES : ES ≤ ⨆ (μ : K) (k : ℕ), f.generalized_eigenspace μ k, from le_trans (le_supr (λ k, f.generalized_eigenspace μ₀ k) (finrank K V)) (le_supr (λ (μ : K), ⨆ (k : ℕ), f.generalized_eigenspace μ k) μ₀), -- Moreover, we know that `ER` and `ES` are disjoint. have h_disjoint : disjoint ER ES, from generalized_eigenvec_disjoint_range_ker f μ₀, -- Since the dimensions of `ER` and `ES` add up to the dimension of `V`, it follows that the -- span of all generalized eigenvectors is all of `V`. show (⨆ (μ : K) (k : ℕ), f.generalized_eigenspace μ k) = ⊤, { rw [←top_le_iff, ←submodule.eq_top_of_disjoint ER ES h_dim_add h_disjoint], apply sup_le hER hES } } end end End end module
26342747287c626ad89143a58a92a645987bd495
30b012bb72d640ec30c8fdd4c45fdfa67beb012c
/analysis/topology/continuous_map.lean
c07694f9a16c8e862146a51e1ef27b5288a11d7b
[ "Apache-2.0" ]
permissive
kckennylau/mathlib
21fb810b701b10d6606d9002a4004f7672262e83
47b3477e20ffb5a06588dd3abb01fe0fe3205646
refs/heads/master
1,634,976,409,281
1,542,042,832,000
1,542,319,733,000
109,560,458
0
0
Apache-2.0
1,542,369,208,000
1,509,867,494,000
Lean
UTF-8
Lean
false
false
4,083
lean
/- Copyright (c) 2018 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton Type of continuous maps and the compact-open topology on them. -/ import analysis.topology.continuity tactic.tidy open set universes u v w def continuous_map (α : Type u) (β : Type v) [topological_space α] [topological_space β] : Type (max u v) := subtype (continuous : (α → β) → Prop) local notation `C(` α `, ` β `)` := continuous_map α β namespace continuous_map section compact_open variables {α : Type u} {β : Type v} {γ : Type w} variables [topological_space α] [topological_space β] [topological_space γ] instance : has_coe_to_fun C(α, β) := ⟨λ_, α → β, λf, f.1⟩ def compact_open.gen (s : set α) (u : set β) : set C(α,β) := {f | f '' s ⊆ u} -- The compact-open topology on the space of continuous maps α → β. instance compact_open : topological_space C(α, β) := topological_space.generate_from {m | ∃ (s : set α) (hs : compact s) (u : set β) (hu : is_open u), m = compact_open.gen s u} private lemma is_open_gen {s : set α} (hs : compact s) {u : set β} (hu : is_open u) : is_open (compact_open.gen s u) := topological_space.generate_open.basic _ (by dsimp [mem_set_of_eq]; tauto) section functorial variables {g : β → γ} (hg : continuous g) def induced (f : C(α, β)) : C(α, γ) := ⟨g ∘ f, f.property.comp hg⟩ private lemma preimage_gen {s : set α} (hs : compact s) {u : set γ} (hu : is_open u) : continuous_map.induced hg ⁻¹' (compact_open.gen s u) = compact_open.gen s (g ⁻¹' u) := begin ext ⟨f, _⟩, change g ∘ f '' s ⊆ u ↔ f '' s ⊆ g ⁻¹' u, rw [image_comp, image_subset_iff] end /-- C(α, -) is a functor. -/ lemma continuous_induced : continuous (continuous_map.induced hg : C(α, β) → C(α, γ)) := continuous_generated_from $ assume m ⟨s, hs, u, hu, hm⟩, by rw [hm, preimage_gen hg hs hu]; exact is_open_gen hs (hg _ hu) end functorial section ev variables (α β) def ev (p : C(α, β) × α) : β := p.1 p.2 variables {α β} -- The evaluation map C(α, β) × α → β is continuous if α is locally compact. lemma continuous_ev [locally_compact_space α] : continuous (ev α β) := continuous_iff_tendsto.mpr $ assume ⟨f, x⟩ n hn, let ⟨v, vn, vo, fxv⟩ := mem_nhds_sets_iff.mp hn in have v ∈ (nhds (f.val x)).sets, from mem_nhds_sets vo fxv, let ⟨s, hs, sv, sc⟩ := locally_compact_space.local_compact_nhds x (f.val ⁻¹' v) (f.property.tendsto x this) in let ⟨u, us, uo, xu⟩ := mem_nhds_sets_iff.mp hs in show (ev α β) ⁻¹' n ∈ (nhds (f, x)).sets, from let w := set.prod (compact_open.gen s v) u in have w ⊆ ev α β ⁻¹' n, from assume ⟨f', x'⟩ ⟨hf', hx'⟩, calc f'.val x' ∈ f'.val '' s : mem_image_of_mem f'.val (us hx') ... ⊆ v : hf' ... ⊆ n : vn, have is_open w, from is_open_prod (is_open_gen sc vo) uo, have (f, x) ∈ w, from ⟨image_subset_iff.mpr sv, xu⟩, mem_nhds_sets_iff.mpr ⟨w, by assumption, by assumption, by assumption⟩ end ev section coev variables (α β) def coev (b : β) : C(α, β × α) := ⟨λ a, (b, a), continuous.prod_mk continuous_const continuous_id⟩ variables {α β} lemma image_coev {y : β} (s : set α) : (coev α β y).val '' s = set.prod {y} s := by tidy -- The coevaluation map β → C(α, β × α) is continuous (always). lemma continuous_coev : continuous (coev α β) := continuous_generated_from $ begin rintros _ ⟨s, sc, u, uo, rfl⟩, rw is_open_iff_forall_mem_open, intros y hy, change (coev α β y).val '' s ⊆ u at hy, rw image_coev s at hy, rcases generalized_tube_lemma compact_singleton sc uo hy with ⟨v, w, vo, wo, yv, sw, vwu⟩, refine ⟨v, _, vo, singleton_subset_iff.mp yv⟩, intros y' hy', change (coev α β y').val '' s ⊆ u, rw image_coev s, exact subset.trans (prod_mono (singleton_subset_iff.mpr hy') sw) vwu end end coev end compact_open end continuous_map
6e815d9ad6f4f1d153e8b084c87c20994e3761c6
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
/src/analysis/box_integral/partition/measure.lean
3d538050cce306ef16c730fb38c6cdbbb929ad63
[ "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
3,752
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.partition.additive import measure_theory.measure.lebesgue /-! # Box-additive functions defined by measures In this file we prove a few simple facts about rectangular boxes, partitions, and measures: - given a box `I : box ι`, its coercion to `set (ι → ℝ)` and `I.Icc` are measurable sets; - if `μ` is a locally finite measure, then `(I : set (ι → ℝ))` and `I.Icc` have finite measure; - if `μ` is a locally finite measure, then `λ J, (μ J).to_real` is a box additive function. For the last statement, we both prove it as a proposition and define a bundled `box_integral.box_additive` function. ### Tags rectangular box, measure -/ open set noncomputable theory open_locale ennreal big_operators classical box_integral variables {ι : Type*} namespace box_integral open measure_theory namespace box variables (I : box ι) lemma measurable_set_coe [fintype ι] (I : box ι) : measurable_set (I : set (ι → ℝ)) := begin rw [coe_eq_pi], haveI := fintype.encodable ι, exact measurable_set.univ_pi (λ i, measurable_set_Ioc) end lemma measurable_set_Icc [fintype ι] (I : box ι) : measurable_set I.Icc := measurable_set_Icc lemma measure_Icc_lt_top (μ : measure (ι → ℝ)) [is_locally_finite_measure μ] : μ I.Icc < ∞ := show μ (Icc I.lower I.upper) < ∞, from (is_compact_pi_Icc I.lower I.upper).measure_lt_top lemma measure_coe_lt_top (μ : measure (ι → ℝ)) [is_locally_finite_measure μ] : μ I < ∞ := (measure_mono $ coe_subset_Icc).trans_lt (I.measure_Icc_lt_top μ) end box lemma prepartition.measure_Union_to_real [fintype ι] {I : box ι} (π : prepartition I) (μ : measure (ι → ℝ)) [is_locally_finite_measure μ] : (μ π.Union).to_real = ∑ J in π.boxes, (μ J).to_real := begin erw [← ennreal.to_real_sum, π.Union_def, measure_bUnion_finset π.pairwise_disjoint], exacts [λ J hJ, J.measurable_set_coe, λ J hJ, (J.measure_coe_lt_top μ).ne] end end box_integral open box_integral box_integral.box variables [fintype ι] namespace measure_theory namespace measure /-- If `μ` is a locally finite measure on `ℝⁿ`, then `λ J, (μ J).to_real` is a box-additive function. -/ @[simps] def to_box_additive (μ : measure (ι → ℝ)) [is_locally_finite_measure μ] : ι →ᵇᵃ[⊤] ℝ := { to_fun := λ J, (μ J).to_real, sum_partition_boxes' := λ J hJ π hπ, by rw [← π.measure_Union_to_real, hπ.Union_eq] } end measure end measure_theory namespace box_integral open measure_theory namespace box @[simp] lemma volume_apply (I : box ι) : (volume : measure (ι → ℝ)).to_box_additive I = ∏ i, (I.upper i - I.lower i) := by rw [measure.to_box_additive_apply, coe_eq_pi, real.volume_pi_Ioc_to_real I.lower_le_upper] lemma volume_face_mul {n} (i : fin (n + 1)) (I : box (fin (n + 1))) : (∏ j, ((I.face i).upper j - (I.face i).lower j)) * (I.upper i - I.lower i) = ∏ j, (I.upper j - I.lower j) := by simp only [face_lower, face_upper, (∘), fin.prod_univ_succ_above _ i, mul_comm] end box namespace box_additive_map /-- Box-additive map sending each box `I` to the continuous linear endomorphism `x ↦ (volume I).to_real • x`. -/ protected def volume {E : Type*} [normed_group E] [normed_space ℝ E] : ι →ᵇᵃ (E →L[ℝ] E) := (volume : measure (ι → ℝ)).to_box_additive.to_smul lemma volume_apply {E : Type*} [normed_group E] [normed_space ℝ E] (I : box ι) (x : E) : box_additive_map.volume I x = (∏ j, (I.upper j - I.lower j)) • x := congr_arg2 (•) I.volume_apply rfl end box_additive_map end box_integral
bd03ecea08d386d47501d48fbf7c87020c3d7d92
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/Lean3Lib/init/control/functor_auto.lean
d1e63d54d28c75c066bf00549cd63879bba94871
[]
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
706
lean
/- Copyright (c) Luke Nelson and Jared Roesch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Luke Nelson, Jared Roesch, Sebastian Ullrich, Leonardo de Moura -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.core import Mathlib.Lean3Lib.init.function import Mathlib.Lean3Lib.init.meta.name universes u v l namespace Mathlib not found infixr:100 " <$> " => Mathlib.functor.map infixr:100 " <$ " => Mathlib.functor.map_const def functor.map_const_rev {f : Type u → Type v} [Functor f] {α : Type u} {β : Type u} : f β → α → f α := fun (a : f β) (b : α) => b <$ a infixr:100 " $> " => Mathlib.functor.map_const_rev end Mathlib
873485263a7bf6d56c92589f935b9ad64b052a21
206422fb9edabf63def0ed2aa3f489150fb09ccb
/src/ring_theory/perfection.lean
d94d2db45bd3d5c33d9ce8091f2a2c60dfaa98c7
[ "Apache-2.0" ]
permissive
hamdysalah1/mathlib
b915f86b2503feeae268de369f1b16932321f097
95454452f6b3569bf967d35aab8d852b1ddf8017
refs/heads/master
1,677,154,116,545
1,611,797,994,000
1,611,797,994,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
24,181
lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import algebra.char_p import algebra.ring.pi import analysis.special_functions.pow import field_theory.perfect_closure import ring_theory.localization import ring_theory.subring import ring_theory.valuation.integers /-! # Ring Perfection and Tilt In this file we define the perfection of a ring of characteristic p, and the tilt of a field given a valuation to `ℝ≥0`. ## TODO Define the valuation on the tilt, and define a characteristic predicate for the tilt. -/ universes u₁ u₂ u₃ u₄ open_locale nnreal /-- The perfection of a monoid `M`, defined to be the projective limit of `M` using the `p`-th power maps `M → M` indexed by the natural numbers, implemented as `{ f : ℕ → M | ∀ n, f (n + 1) ^ p = f n }`. -/ def monoid.perfection (M : Type u₁) [comm_monoid M] (p : ℕ) : submonoid (ℕ → M) := { carrier := { f | ∀ n, f (n + 1) ^ p = f n }, one_mem' := λ n, one_pow _, mul_mem' := λ f g hf hg n, (mul_pow _ _ _).trans $ congr_arg2 _ (hf n) (hg n) } /-- The perfection of a ring `R` with characteristic `p`, defined to be the projective limit of `R` using the Frobenius maps `R → R` indexed by the natural numbers, implemented as `{ f : ℕ → R | ∀ n, f (n + 1) ^ p = f n }`. -/ def ring.perfection (R : Type u₁) [comm_semiring R] (p : ℕ) [hp : fact p.prime] [char_p R p] : subsemiring (ℕ → R) := { zero_mem' := λ n, zero_pow $ hp.pos, add_mem' := λ f g hf hg n, (frobenius_add R p _ _).trans $ congr_arg2 _ (hf n) (hg n), .. monoid.perfection R p } namespace perfection variables (R : Type u₁) [comm_semiring R] (p : ℕ) [hp : fact p.prime] [char_p R p] include hp /-- The `n`-th coefficient of an element of the perfection. -/ def coeff (n : ℕ) : ring.perfection R p →+* R := { to_fun := λ f, f.1 n, map_one' := rfl, map_mul' := λ f g, rfl, map_zero' := rfl, map_add' := λ f g, rfl } variables {R p} @[ext] lemma ext {f g : ring.perfection R p} (h : ∀ n, coeff R p n f = coeff R p n g) : f = g := subtype.eq $ funext h variables (R p) /-- The `p`-th root of an element of the perfection. -/ def pth_root : ring.perfection R p →+* ring.perfection R p := { to_fun := λ f, ⟨λ n, coeff R p (n + 1) f, λ n, f.2 _⟩, map_one' := rfl, map_mul' := λ f g, rfl, map_zero' := rfl, map_add' := λ f g, rfl } variables {R p} @[simp] lemma coeff_mk (f : ℕ → R) (hf) (n : ℕ) : coeff R p n ⟨f, hf⟩ = f n := rfl lemma coeff_pth_root (f : ring.perfection R p) (n : ℕ) : coeff R p n (pth_root R p f) = coeff R p (n + 1) f := rfl lemma coeff_pow_p (f : ring.perfection R p) (n : ℕ) : coeff R p (n + 1) (f ^ p) = coeff R p n f := by { rw ring_hom.map_pow, exact f.2 n } lemma coeff_pow_p' (f : ring.perfection R p) (n : ℕ) : coeff R p (n + 1) f ^ p = coeff R p n f := f.2 n lemma coeff_frobenius (f : ring.perfection R p) (n : ℕ) : coeff R p (n + 1) (frobenius _ p f) = coeff R p n f := by convert coeff_pow_p f n lemma coeff_iterate_frobenius (f : ring.perfection R p) (n m : ℕ) : coeff R p (n + m) (frobenius _ p ^[m] f) = coeff R p n f := nat.rec_on m rfl $ λ m ih, by erw [function.iterate_succ_apply', coeff_frobenius, ih] lemma coeff_iterate_frobenius' (f : ring.perfection R p) (n m : ℕ) (hmn : m ≤ n) : coeff R p n (frobenius _ p ^[m] f) = coeff R p (n - m) f := eq.symm $ (coeff_iterate_frobenius _ _ m).symm.trans $ (nat.sub_add_cancel hmn).symm ▸ rfl lemma pth_root_frobenius : (pth_root R p).comp (frobenius _ p) = ring_hom.id _ := ring_hom.ext $ λ x, ext $ λ n, by rw [ring_hom.comp_apply, ring_hom.id_apply, coeff_pth_root, coeff_frobenius] lemma frobenius_pth_root : (frobenius _ p).comp (pth_root R p) = ring_hom.id _ := ring_hom.ext $ λ x, ext $ λ n, by rw [ring_hom.comp_apply, ring_hom.id_apply, ring_hom.map_frobenius, coeff_pth_root, ← ring_hom.map_frobenius, coeff_frobenius] lemma coeff_add_ne_zero {f : ring.perfection R p} {n : ℕ} (hfn : coeff R p n f ≠ 0) (k : ℕ) : coeff R p (n + k) f ≠ 0 := nat.rec_on k hfn $ λ k ih h, ih $ by erw [← coeff_pow_p, ring_hom.map_pow, h, zero_pow hp.pos] lemma coeff_ne_zero_of_le {f : ring.perfection R p} {m n : ℕ} (hfm : coeff R p m f ≠ 0) (hmn : m ≤ n) : coeff R p n f ≠ 0 := let ⟨k, hk⟩ := nat.exists_eq_add_of_le hmn in hk.symm ▸ coeff_add_ne_zero hfm k variables (R p) instance perfect_ring : perfect_ring (ring.perfection R p) p := { pth_root' := pth_root R p, frobenius_pth_root' := congr_fun $ congr_arg ring_hom.to_fun $ @frobenius_pth_root R _ p _ _, pth_root_frobenius' := congr_fun $ congr_arg ring_hom.to_fun $ @pth_root_frobenius R _ p _ _ } instance ring (R : Type u₁) [comm_ring R] [char_p R p] : ring (ring.perfection R p) := ((ring.perfection R p).to_subring $ λ n, by simp_rw [← frobenius_def, pi.neg_apply, pi.one_apply, ring_hom.map_neg, ring_hom.map_one]).to_ring instance comm_ring (R : Type u₁) [comm_ring R] [char_p R p] : comm_ring (ring.perfection R p) := ((ring.perfection R p).to_subring $ λ n, by simp_rw [← frobenius_def, pi.neg_apply, pi.one_apply, ring_hom.map_neg, ring_hom.map_one]).to_comm_ring /-- Given rings `R` and `S` of characteristic `p`, with `R` being perfect, any homomorphism `R →+* S` can be lifted to a homomorphism `R →+* perfection S p`. -/ @[simps] def lift (R : Type u₁) [comm_semiring R] [char_p R p] [perfect_ring R p] (S : Type u₂) [comm_semiring S] [char_p S p] : (R →+* S) ≃ (R →+* ring.perfection S p) := { to_fun := λ f, { to_fun := λ r, ⟨λ n, f $ _root_.pth_root R p ^[n] r, λ n, by rw [← f.map_pow, function.iterate_succ_apply', pth_root_pow_p]⟩, map_one' := ext $ λ n, (congr_arg f $ ring_hom.iterate_map_one _ _).trans f.map_one, map_mul' := λ x y, ext $ λ n, (congr_arg f $ ring_hom.iterate_map_mul _ _ _ _).trans $ f.map_mul _ _, map_zero' := ext $ λ n, (congr_arg f $ ring_hom.iterate_map_zero _ _).trans f.map_zero, map_add' := λ x y, ext $ λ n, (congr_arg f $ ring_hom.iterate_map_add _ _ _ _).trans $ f.map_add _ _ }, inv_fun := ring_hom.comp $ coeff S p 0, left_inv := λ f, ring_hom.ext $ λ r, rfl, right_inv := λ f, ring_hom.ext $ λ r, ext $ λ n, show coeff S p 0 (f (_root_.pth_root R p ^[n] r)) = coeff S p n (f r), by rw [← coeff_iterate_frobenius _ 0 n, zero_add, ← ring_hom.map_iterate_frobenius, right_inverse_pth_root_frobenius.iterate] } lemma hom_ext {R : Type u₁} [comm_semiring R] [char_p R p] [perfect_ring R p] {S : Type u₂} [comm_semiring S] [char_p S p] {f g : R →+* ring.perfection S p} (hfg : ∀ x, coeff S p 0 (f x) = coeff S p 0 (g x)) : f = g := (lift p R S).symm.injective $ ring_hom.ext hfg variables {R} {S : Type u₂} [comm_semiring S] [char_p S p] /-- A ring homomorphism `R →+* S` induces `perfection R p →+* perfection S p` -/ @[simps] def map (φ : R →+* S) : ring.perfection R p →+* ring.perfection S p := { to_fun := λ f, ⟨λ n, φ (coeff R p n f), λ n, by rw [← φ.map_pow, coeff_pow_p']⟩, map_one' := subtype.eq $ funext $ λ n, φ.map_one, map_mul' := λ f g, subtype.eq $ funext $ λ n, φ.map_mul _ _, map_zero' := subtype.eq $ funext $ λ n, φ.map_zero, map_add' := λ f g, subtype.eq $ funext $ λ n, φ.map_add _ _ } lemma coeff_map (φ : R →+* S) (f : ring.perfection R p) (n : ℕ) : coeff S p n (map p φ f) = φ (coeff R p n f) := rfl end perfection /-- A perfection map to a ring of characteristic `p` is a map that is isomorphic to its perfection. -/ @[nolint has_inhabited_instance] structure perfection_map (p : ℕ) [fact p.prime] {R : Type u₁} [comm_semiring R] [char_p R p] {P : Type u₂} [comm_semiring P] [char_p P p] [perfect_ring P p] (π : P →+* R) : Prop := (injective : ∀ ⦃x y : P⦄, (∀ n, π (pth_root P p ^[n] x) = π (pth_root P p ^[n] y)) → x = y) (surjective : ∀ f : ℕ → R, (∀ n, f (n + 1) ^ p = f n) → ∃ x : P, ∀ n, π (pth_root P p ^[n] x) = f n) namespace perfection_map variables {p : ℕ} [fact p.prime] variables {R : Type u₁} [comm_semiring R] [char_p R p] variables {P : Type u₃} [comm_semiring P] [char_p P p] [perfect_ring P p] /-- Create a `perfection_map` from an isomorphism to the perfection. -/ @[simps] lemma mk' {f : P →+* R} (g : P ≃+* ring.perfection R p) (hfg : perfection.lift p P R f = g) : perfection_map p f := { injective := λ x y hxy, g.injective $ (ring_hom.ext_iff.1 hfg x).symm.trans $ eq.symm $ (ring_hom.ext_iff.1 hfg y).symm.trans $ perfection.ext $ λ n, (hxy n).symm, surjective := λ y hy, let ⟨x, hx⟩ := g.surjective ⟨y, hy⟩ in ⟨x, λ n, show perfection.coeff R p n (perfection.lift p P R f x) = perfection.coeff R p n ⟨y, hy⟩, by rw [hfg, ← coe_fn_coe_base, hx]⟩ } variables (p R P) /-- The canonical perfection map from the perfection of a ring. -/ lemma of : perfection_map p (perfection.coeff R p 0) := mk' (ring_equiv.refl _) $ (equiv.apply_eq_iff_eq_symm_apply _).2 rfl /-- For a perfect ring, it itself is the perfection. -/ lemma id [perfect_ring R p] : perfection_map p (ring_hom.id R) := { injective := λ x y hxy, hxy 0, surjective := λ f hf, ⟨f 0, λ n, show pth_root R p ^[n] (f 0) = f n, from nat.rec_on n rfl $ λ n ih, injective_pow_p p $ by rw [function.iterate_succ_apply', pth_root_pow_p _, ih, hf]⟩ } variables {p R P} /-- A perfection map induces an isomorphism to the prefection. -/ noncomputable def equiv {π : P →+* R} (m : perfection_map p π) : P ≃+* ring.perfection R p := ring_equiv.of_bijective (perfection.lift p P R π) ⟨λ x y hxy, m.injective $ λ n, (congr_arg (perfection.coeff R p n) hxy : _), λ f, let ⟨x, hx⟩ := m.surjective f.1 f.2 in ⟨x, perfection.ext $ hx⟩⟩ lemma equiv_apply {π : P →+* R} (m : perfection_map p π) (x : P) : m.equiv x = perfection.lift p P R π x := rfl lemma comp_equiv {π : P →+* R} (m : perfection_map p π) (x : P) : perfection.coeff R p 0 (m.equiv x) = π x := rfl lemma comp_equiv' {π : P →+* R} (m : perfection_map p π) : (perfection.coeff R p 0).comp ↑m.equiv = π := ring_hom.ext $ λ x, rfl lemma comp_symm_equiv {π : P →+* R} (m : perfection_map p π) (f : ring.perfection R p) : π (m.equiv.symm f) = perfection.coeff R p 0 f := (m.comp_equiv _).symm.trans $ congr_arg _ $ m.equiv.apply_symm_apply f lemma comp_symm_equiv' {π : P →+* R} (m : perfection_map p π) : π.comp ↑m.equiv.symm = perfection.coeff R p 0 := ring_hom.ext m.comp_symm_equiv variables (p R P) /-- Given rings `R` and `S` of characteristic `p`, with `R` being perfect, any homomorphism `R →+* S` can be lifted to a homomorphism `R →+* P`, where `P` is any perfection of `S`. -/ @[simps] noncomputable def lift [perfect_ring R p] (S : Type u₂) [comm_semiring S] [char_p S p] (P : Type u₃) [comm_semiring P] [char_p P p] [perfect_ring P p] (π : P →+* S) (m : perfection_map p π) : (R →+* S) ≃ (R →+* P) := { to_fun := λ f, ring_hom.comp ↑m.equiv.symm $ perfection.lift p R S f, inv_fun := λ f, π.comp f, left_inv := λ f, by { simp_rw [← ring_hom.comp_assoc, comp_symm_equiv'], exact (perfection.lift p R S).symm_apply_apply f }, right_inv := λ f, ring_hom.ext $ λ x, m.equiv.injective $ (m.equiv.apply_symm_apply _).trans $ show perfection.lift p R S (π.comp f) x = ring_hom.comp ↑m.equiv f x, from ring_hom.ext_iff.1 ((perfection.lift p R S).apply_eq_iff_eq_symm_apply.2 rfl) _ } variables {R p} lemma hom_ext [perfect_ring R p] {S : Type u₂} [comm_semiring S] [char_p S p] {P : Type u₃} [comm_semiring P] [char_p P p] [perfect_ring P p] (π : P →+* S) (m : perfection_map p π) {f g : R →+* P} (hfg : ∀ x, π (f x) = π (g x)) : f = g := (lift p R S P π m).symm.injective $ ring_hom.ext hfg variables {R P} (p) {S : Type u₂} [comm_semiring S] [char_p S p] variables {Q : Type u₄} [comm_semiring Q] [char_p Q p] [perfect_ring Q p] /-- A ring homomorphism `R →+* S` induces `P →+* Q`, a map of the respective perfections -/ @[nolint unused_arguments] noncomputable def map {π : P →+* R} (m : perfection_map p π) {σ : Q →+* S} (n : perfection_map p σ) (φ : R →+* S) : P →+* Q := lift p P S Q σ n $ φ.comp π lemma comp_map {π : P →+* R} (m : perfection_map p π) {σ : Q →+* S} (n : perfection_map p σ) (φ : R →+* S) : σ.comp (map p m n φ) = φ.comp π := (lift p P S Q σ n).symm_apply_apply _ lemma map_map {π : P →+* R} (m : perfection_map p π) {σ : Q →+* S} (n : perfection_map p σ) (φ : R →+* S) (x : P) : σ (map p m n φ x) = φ (π x) := ring_hom.ext_iff.1 (comp_map p m n φ) x -- Why is this slow? lemma map_eq_map (φ : R →+* S) : map p (of p R) (of p S) φ = perfection.map p φ := hom_ext _ (of p S) $ λ f, by rw [map_map, perfection.coeff_map] end perfection_map section perfectoid variables (K : Type u₁) [field K] (v : valuation K ℝ≥0) variables (O : Type u₂) [comm_ring O] [algebra O K] (hv : v.integers O) variables (p : ℕ) include hv /-- `O/(p)` for `O`, ring of integers of `K`. -/ @[nolint unused_arguments has_inhabited_instance] def mod_p := (ideal.span {p} : ideal O).quotient variables [hp : fact p.prime] [hvp : fact (v p ≠ 1)] namespace mod_p instance : comm_ring (mod_p K v O hv p) := ideal.quotient.comm_ring _ include hp hvp instance : char_p (mod_p K v O hv p) p := char_p.quotient O p $ mt hv.one_of_is_unit $ ((algebra_map O K).map_nat_cast p).symm ▸ hvp instance : nontrivial (mod_p K v O hv p) := char_p.nontrivial_of_char_ne_one hp.ne_one section classical local attribute [instance] classical.dec omit hp hvp /-- For a field `K` with valuation `v : K → ℝ≥0` and ring of integers `O`, a function `O/(p) → ℝ≥0` that sends `0` to `0` and `x + (p)` to `v(x)` as long as `x ∉ (p)`. -/ noncomputable def pre_val (x : mod_p K v O hv p) : ℝ≥0 := if x = 0 then 0 else v (algebra_map O K x.out') variables {K v O hv p} lemma pre_val_mk {x : O} (hx : (ideal.quotient.mk _ x : mod_p K v O hv p) ≠ 0) : pre_val K v O hv p (ideal.quotient.mk _ x) = v (algebra_map O K x) := begin obtain ⟨r, hr⟩ := ideal.mem_span_singleton'.1 (ideal.quotient.eq.1 $ quotient.sound' $ @quotient.mk_out' O (ideal.span {p} : ideal O).quotient_rel x), refine (if_neg hx).trans (v.map_eq_of_sub_lt $ lt_of_not_ge' _), erw [← ring_hom.map_sub, ← hr, hv.le_iff_dvd], exact λ hprx, hx (ideal.quotient.eq_zero_iff_mem.2 $ ideal.mem_span_singleton.2 $ dvd_of_mul_left_dvd hprx), end lemma pre_val_zero : pre_val K v O hv p 0 = 0 := if_pos rfl lemma pre_val_mul {x y : mod_p K v O hv p} (hxy0 : x * y ≠ 0) : pre_val K v O hv p (x * y) = pre_val K v O hv p x * pre_val K v O hv p y := begin have hx0 : x ≠ 0 := mt (by { rintro rfl, rw zero_mul }) hxy0, have hy0 : y ≠ 0 := mt (by { rintro rfl, rw mul_zero }) hxy0, obtain ⟨r, rfl⟩ := ideal.quotient.mk_surjective x, obtain ⟨s, rfl⟩ := ideal.quotient.mk_surjective y, rw ← ring_hom.map_mul at hxy0 ⊢, rw [pre_val_mk hx0, pre_val_mk hy0, pre_val_mk hxy0, ring_hom.map_mul, v.map_mul] end lemma pre_val_add (x y : mod_p K v O hv p) : pre_val K v O hv p (x + y) ≤ max (pre_val K v O hv p x) (pre_val K v O hv p y) := begin by_cases hx0 : x = 0, { rw [hx0, zero_add], exact le_max_right _ _ }, by_cases hy0 : y = 0, { rw [hy0, add_zero], exact le_max_left _ _ }, by_cases hxy0 : x + y = 0, { rw [hxy0, pre_val_zero], exact zero_le _ }, obtain ⟨r, rfl⟩ := ideal.quotient.mk_surjective x, obtain ⟨s, rfl⟩ := ideal.quotient.mk_surjective y, rw ← ring_hom.map_add at hxy0 ⊢, rw [pre_val_mk hx0, pre_val_mk hy0, pre_val_mk hxy0, ring_hom.map_add], exact v.map_add _ _ end lemma v_p_lt_pre_val {x : mod_p K v O hv p} : v p < pre_val K v O hv p x ↔ x ≠ 0 := begin refine ⟨λ h hx, by { rw [hx, pre_val_zero] at h, exact not_lt_zero' h }, λ h, lt_of_not_ge' $ λ hp, h _⟩, obtain ⟨r, rfl⟩ := ideal.quotient.mk_surjective x, rw [pre_val_mk h, ← (algebra_map O K).map_nat_cast p, hv.le_iff_dvd] at hp, rw [ideal.quotient.eq_zero_iff_mem, ideal.mem_span_singleton], exact hp end lemma pre_val_eq_zero {x : mod_p K v O hv p} : pre_val K v O hv p x = 0 ↔ x = 0 := ⟨λ hvx, classical.by_contradiction $ λ hx0 : x ≠ 0, by { rw [← v_p_lt_pre_val, hvx] at hx0, exact not_lt_zero' hx0 }, λ hx, hx.symm ▸ pre_val_zero⟩ variables (hv hvp) lemma v_p_lt_val {x : O} : v p < v (algebra_map O K x) ↔ (ideal.quotient.mk _ x : mod_p K v O hv p) ≠ 0 := by rw [lt_iff_not_ge', not_iff_not, ← (algebra_map O K).map_nat_cast p, hv.le_iff_dvd, ideal.quotient.eq_zero_iff_mem, ideal.mem_span_singleton] open nnreal variables {hv} [hvp] include hp lemma mul_ne_zero_of_pow_p_ne_zero {x y : mod_p K v O hv p} (hx : x ^ p ≠ 0) (hy : y ^ p ≠ 0) : x * y ≠ 0 := begin obtain ⟨r, rfl⟩ := ideal.quotient.mk_surjective x, obtain ⟨s, rfl⟩ := ideal.quotient.mk_surjective y, have h1p : (0 : ℝ) < 1 / p := one_div_pos.2 (nat.cast_pos.2 hp.pos), rw ← ring_hom.map_mul, rw ← ring_hom.map_pow at hx hy, rw ← v_p_lt_val hv at hx hy ⊢, rw [ring_hom.map_pow, v.map_pow, ← rpow_lt_rpow_iff h1p, ← rpow_nat_cast, ← rpow_mul, mul_one_div_cancel (nat.cast_ne_zero.2 hp.ne_zero : (p : ℝ) ≠ 0), rpow_one] at hx hy, rw [ring_hom.map_mul, v.map_mul], refine lt_of_le_of_lt _ (mul_lt_mul'''' hx hy), by_cases hvp : v p = 0, { rw hvp, exact zero_le _ }, replace hvp := zero_lt_iff.2 hvp, conv_lhs { rw ← rpow_one (v p) }, rw ← rpow_add (ne_of_gt hvp), refine rpow_le_rpow_of_exponent_ge hvp ((algebra_map O K).map_nat_cast p ▸ hv.2 _) _, rw [← add_div, div_le_one (nat.cast_pos.2 hp.pos : 0 < (p : ℝ))], exact_mod_cast hp.two_le end end classical end mod_p include hp hvp /-- Perfection of `O/(p)` where `O` is the ring of integers of `K`. -/ @[nolint has_inhabited_instance] def pre_tilt := ring.perfection (mod_p K v O hv p) p namespace pre_tilt instance : comm_ring (pre_tilt K v O hv p) := perfection.comm_ring p _ section classical local attribute [instance] classical.dec open perfection /-- The valuation `Perfection(O/(p)) → ℝ≥0` as a function. Given `f ∈ Perfection(O/(p))`, if `f = 0` then output `0`; otherwise output `pre_val(f(n))^(p^n)` for any `n` such that `f(n) ≠ 0`. -/ noncomputable def val_aux (f : pre_tilt K v O hv p) : ℝ≥0 := if h : ∃ n, coeff _ _ n f ≠ 0 then mod_p.pre_val K v O hv p (coeff _ _ (nat.find h) f) ^ (p ^ nat.find h) else 0 variables {K v O hv p} lemma coeff_nat_find_add_ne_zero {f : pre_tilt K v O hv p} {h : ∃ n, coeff _ _ n f ≠ 0} (k : ℕ) : coeff _ _ (nat.find h + k) f ≠ 0 := coeff_add_ne_zero (nat.find_spec h) k lemma val_aux_eq {f : pre_tilt K v O hv p} {n : ℕ} (hfn : coeff _ _ n f ≠ 0) : val_aux K v O hv p f = mod_p.pre_val K v O hv p (coeff _ _ n f) ^ (p ^ n) := begin have h : ∃ n, coeff _ _ n f ≠ 0 := ⟨n, hfn⟩, rw [val_aux, dif_pos h], obtain ⟨k, rfl⟩ := nat.exists_eq_add_of_le (nat.find_min' h hfn), induction k with k ih, { refl }, obtain ⟨x, hx⟩ := ideal.quotient.mk_surjective (coeff _ _ (nat.find h + k + 1) f), have h1 : (ideal.quotient.mk _ x : mod_p K v O hv p) ≠ 0 := hx.symm ▸ hfn, have h2 : (ideal.quotient.mk _ (x ^ p) : mod_p K v O hv p) ≠ 0, by { erw [ring_hom.map_pow, hx, ← ring_hom.map_pow, coeff_pow_p], exact coeff_nat_find_add_ne_zero k }, erw [ih (coeff_nat_find_add_ne_zero k), ← hx, ← coeff_pow_p, ring_hom.map_pow, ← hx, ← ring_hom.map_pow, mod_p.pre_val_mk h1, mod_p.pre_val_mk h2, ring_hom.map_pow, v.map_pow, ← pow_mul, pow_succ], refl end lemma val_aux_zero : val_aux K v O hv p 0 = 0 := dif_neg $ λ ⟨n, hn⟩, hn rfl lemma val_aux_one : val_aux K v O hv p 1 = 1 := (val_aux_eq $ by exact one_ne_zero).trans $ by { rw [pow_zero, pow_one, ring_hom.map_one, ← (ideal.quotient.mk _).map_one, mod_p.pre_val_mk, ring_hom.map_one, v.map_one], exact @one_ne_zero (mod_p K v O hv p) _ _ } lemma val_aux_mul (f g : pre_tilt K v O hv p) : val_aux K v O hv p (f * g) = val_aux K v O hv p f * val_aux K v O hv p g := begin by_cases hf : f = 0, { rw [hf, zero_mul, val_aux_zero, zero_mul] }, by_cases hg : g = 0, { rw [hg, mul_zero, val_aux_zero, mul_zero] }, replace hf : ∃ n, coeff _ _ n f ≠ 0 := not_forall.1 (λ h, hf $ perfection.ext h), replace hg : ∃ n, coeff _ _ n g ≠ 0 := not_forall.1 (λ h, hg $ perfection.ext h), obtain ⟨m, hm⟩ := hf, obtain ⟨n, hn⟩ := hg, replace hm := coeff_ne_zero_of_le hm (le_max_left m n), replace hn := coeff_ne_zero_of_le hn (le_max_right m n), have hfg : coeff _ _ (max m n + 1) (f * g) ≠ 0, { rw ring_hom.map_mul, refine mod_p.mul_ne_zero_of_pow_p_ne_zero _ _; rw [← ring_hom.map_pow, coeff_pow_p]; assumption }, rw [val_aux_eq (coeff_add_ne_zero hm 1), val_aux_eq (coeff_add_ne_zero hn 1), val_aux_eq hfg], rw ring_hom.map_mul at hfg ⊢, rw [mod_p.pre_val_mul hfg, mul_pow] end lemma val_aux_add (f g : pre_tilt K v O hv p) : val_aux K v O hv p (f + g) ≤ max (val_aux K v O hv p f) (val_aux K v O hv p g) := begin by_cases hf : f = 0, { rw [hf, zero_add, val_aux_zero, max_eq_right], exact zero_le _ }, by_cases hg : g = 0, { rw [hg, add_zero, val_aux_zero, max_eq_left], exact zero_le _ }, by_cases hfg : f + g = 0, { rw [hfg, val_aux_zero], exact zero_le _ }, replace hf : ∃ n, coeff _ _ n f ≠ 0 := not_forall.1 (λ h, hf $ perfection.ext h), replace hg : ∃ n, coeff _ _ n g ≠ 0 := not_forall.1 (λ h, hg $ perfection.ext h), replace hfg : ∃ n, coeff _ _ n (f + g) ≠ 0 := not_forall.1 (λ h, hfg $ perfection.ext h), obtain ⟨m, hm⟩ := hf, obtain ⟨n, hn⟩ := hg, obtain ⟨k, hk⟩ := hfg, replace hm := coeff_ne_zero_of_le hm (le_trans (le_max_left m n) (le_max_left _ k)), replace hn := coeff_ne_zero_of_le hn (le_trans (le_max_right m n) (le_max_left _ k)), replace hk := coeff_ne_zero_of_le hk (le_max_right (max m n) k), rw [val_aux_eq hm, val_aux_eq hn, val_aux_eq hk, ring_hom.map_add], cases le_max_iff.1 (mod_p.pre_val_add (coeff _ _ (max (max m n) k) f) (coeff _ _ (max (max m n) k) g)) with h h, { exact le_max_left_of_le (canonically_ordered_semiring.pow_le_pow_of_le_left h _) }, { exact le_max_right_of_le (canonically_ordered_semiring.pow_le_pow_of_le_left h _) } end variables (K v O hv p) /-- The valuation `Perfection(O/(p)) → ℝ≥0`. Given `f ∈ Perfection(O/(p))`, if `f = 0` then output `0`; otherwise output `pre_val(f(n))^(p^n)` for any `n` such that `f(n) ≠ 0`. -/ noncomputable def val : valuation (pre_tilt K v O hv p) ℝ≥0 := { to_fun := val_aux K v O hv p, map_one' := val_aux_one, map_mul' := val_aux_mul, map_zero' := val_aux_zero, map_add' := val_aux_add } variables {K v O hv p} lemma map_eq_zero {f : pre_tilt K v O hv p} : val K v O hv p f = 0 ↔ f = 0 := begin by_cases hf0 : f = 0, { rw hf0, exact iff_of_true (valuation.map_zero _) rfl }, obtain ⟨n, hn⟩ : ∃ n, coeff _ _ n f ≠ 0 := not_forall.1 (λ h, hf0 $ perfection.ext h), show val_aux K v O hv p f = 0 ↔ f = 0, refine iff_of_false (λ hvf, hn _) hf0, rw val_aux_eq hn at hvf, replace hvf := pow_eq_zero hvf, rwa mod_p.pre_val_eq_zero at hvf end end classical instance : integral_domain (pre_tilt K v O hv p) := { exists_pair_ne := (char_p.nontrivial_of_char_ne_one hp.ne_one).1, eq_zero_or_eq_zero_of_mul_eq_zero := λ f g hfg, by { simp_rw ← map_eq_zero at hfg ⊢, contrapose! hfg, rw valuation.map_mul, exact mul_ne_zero hfg.1 hfg.2 }, .. (infer_instance : comm_ring (pre_tilt K v O hv p)) } end pre_tilt /-- The tilt of a field, as defined in Perfectoid Spaces by Peter Scholze, as in [scholze2011perfectoid]. Given a field `K` with valuation `K → ℝ≥0` and ring of integers `O`, this is implemented as the fraction field of the perfection of `O/(p)`. -/ @[nolint has_inhabited_instance] def tilt := fraction_ring (pre_tilt K v O hv p) namespace tilt noncomputable instance : field (tilt K v O hv p) := fraction_ring.field end tilt end perfectoid
5354485ef07570fec9a995edc2ede0bc777d0bd7
efce24474b28579aba3272fdb77177dc2b11d7aa
/src/homotopy_theory/formal/cylinder/homotopy.lean
c598b0ffe0bafb0644a63a0b48f8f6b218a0f3d2
[ "Apache-2.0" ]
permissive
rwbarton/lean-homotopy-theory
cff499f24268d60e1c546e7c86c33f58c62888ed
39e1b4ea1ed1b0eca2f68bc64162dde6a6396dee
refs/heads/lean-3.4.2
1,622,711,883,224
1,598,550,958,000
1,598,550,958,000
136,023,667
12
6
Apache-2.0
1,573,187,573,000
1,528,116,262,000
Lean
UTF-8
Lean
false
false
6,669
lean
import category_theory.category import category_theory.colimit_lemmas import .definitions open category_theory open category_theory.category local notation f ` ∘ `:80 g:80 := g ≫ f local notation t ` @> `:90 X:90 := t.app X universes v u namespace homotopy_theory.cylinder variables {C : Type u} [category.{v} C] [has_cylinder C] -- Homotopy with respect to a given cylinder functor. structure homotopy {x y : C} (f₀ f₁ : x ⟶ y) := (H : I.obj x ⟶ y) (Hi₀ : H ∘ i 0 @> x = f₀) (Hi₁ : H ∘ i 1 @> x = f₁) -- The constant homotopy on a map. def homotopy.refl {x y : C} (f : x ⟶ y) : homotopy f f := by refine { H := f ∘ p @> x, Hi₀ := _, Hi₁ := _ }; rw [←assoc]; dsimp; simp -- The image of a homotopy under a map. def homotopy.congr_left {x y y' : C} (g : y ⟶ y') {f₀ f₁ : x ⟶ y} (H : homotopy f₀ f₁) : homotopy (g ∘ f₀) (g ∘ f₁) := { H := g ∘ H.H, Hi₀ := by rw [←assoc, H.Hi₀], Hi₁ := by rw [←assoc, H.Hi₁] } -- The precomposition of a homotopy by a map. def homotopy.congr_right {x' x y : C} (g : x' ⟶ x) {f₀ f₁ : x ⟶ y} (H : homotopy f₀ f₁) : homotopy (f₀ ∘ g) (f₁ ∘ g) := { H := H.H ∘ I &> g, Hi₀ := by erw [←assoc, ←(i _).naturality]; simp; erw H.Hi₀, Hi₁ := by erw [←assoc, ←(i _).naturality]; simp; erw H.Hi₁ } -- Annoying equality stuff. -- If we rewrite the starting point of the homotopy by an equality, it doesn't change H. lemma homotopy.eq_rec_on_left {x y : C} {f₀ f₀' f₁ : x ⟶ y} (H : homotopy f₀ f₁) (e : f₀ = f₀') : (eq.rec_on e H : homotopy f₀' f₁).H = H.H := by cases e; refl section rel variables {a x y : C} (j : a ⟶ x) {f₀ f₁ : x ⟶ y} -- The property of a homotopy leaving fixed a subspace, or more -- generally the "image" of any map j : A → X. In order for the -- homotopy to be rel u, we must first have f₀ ∘ j = f₁ ∘ j. This -- condition is not encoded in the type. def homotopy.is_rel (H : homotopy f₀ f₁) : Prop := H.H ∘ I &> j = f₀ ∘ j ∘ p @> a variables {j} lemma agree_of_is_rel {H : homotopy f₀ f₁} (h : H.is_rel j) : f₀ ∘ j = f₁ ∘ j := calc f₀ ∘ j = (f₀ ∘ j) ∘ (p @> a ∘ i 1 @> a) : by simp ... = f₀ ∘ j ∘ p @> a ∘ i 1 @> a : by rw assoc ... = H.H ∘ I &> j ∘ i 1 @> a : by unfold homotopy.is_rel at h; simp [h] ... = H.H ∘ (I &> j ∘ i 1 @> a) : by simp ... = H.H ∘ (i 1 @> x ∘ j) : by erw ←(i 1).naturality; refl ... = f₁ ∘ j : by simp; erw H.Hi₁ lemma homotopy.refl_is_rel {f : x ⟶ y} : (homotopy.refl f).is_rel j := show f ∘ p @> x ∘ I &> j = f ∘ j ∘ p @> a, by erw [←assoc, ←assoc, p.naturality]; refl lemma homotopy.congr_left_is_rel {f₀ f₁ : x ⟶ y} {H : homotopy f₀ f₁} {z} (g : y ⟶ z) (h : H.is_rel j) : (H.congr_left g).is_rel j := begin unfold homotopy.is_rel at ⊢ h, dsimp [homotopy.congr_left] { iota := tt }, rw [←assoc, h], simp end lemma homotopy.congr_right_is_rel {f₀ f₁ : x ⟶ y} {H : homotopy f₀ f₁} {x'} {j' : a ⟶ x'} (g : x' ⟶ x) (h : H.is_rel (g ∘ j')) : (H.congr_right g).is_rel j' := begin unfold homotopy.is_rel at ⊢ h, dsimp [homotopy.congr_right] { iota := tt }, rw [←assoc, ←I.map_comp, h], simp end -- In practice, `a` is initial and `I` preserves initial objects. lemma homotopy.is_rel_initial (Iai : Is_initial_object.{v} (I.obj a)) (H : homotopy f₀ f₁) : H.is_rel j := Iai.uniqueness _ _ end rel section dir -- A technical contrivance to let us abstract over the direction of a -- homotopy. def homotopy_dir (ε : endpoint) {x y : C} (fε fεv : x ⟶ y) : Type v := match ε with | 0 := homotopy fε fεv | 1 := homotopy fεv fε end def homotopy_dir.H {ε} {x y : C} {fε fεv : x ⟶ y} (H : homotopy_dir ε fε fεv) : I.obj x ⟶ y := match ε, H with | 0, H := homotopy.H H | 1, H := homotopy.H H end lemma homotopy_dir.Hiε {ε} {x y : C} {fε fεv : x ⟶ y} (H : homotopy_dir ε fε fεv) : H.H ∘ i ε @> x = fε := match ε, H with | 0, H := homotopy.Hi₀ H | 1, H := homotopy.Hi₁ H end lemma homotopy_dir.Hiεv {ε} {x y : C} {fε fεv : x ⟶ y} (H : homotopy_dir ε fε fεv) : H.H ∘ i ε.v @> x = fεv := match ε, H with | 0, H := homotopy.Hi₁ H | 1, H := homotopy.Hi₀ H end def homotopy_dir.mk (ε : endpoint) {x y : C} {fε fεv : x ⟶ y} (H : I.obj x ⟶ y) (Hiε : H ∘ i ε @> x = fε) (Hiεv : H ∘ i ε.v @> x = fεv) : homotopy_dir ε fε fεv := match ε, H, Hiε, Hiεv with | 0, H, Hiε, Hiεv := { H := H, Hi₀ := Hiε, Hi₁ := Hiεv } | 1, H, Hiε, Hiεv := { H := H, Hi₀ := Hiεv, Hi₁ := Hiε } end end dir -- The homotopy relation with respect to the given cylinder functor. def homotopic {x y : C} (f₀ f₁ : x ⟶ y) : Prop := nonempty (homotopy f₀ f₁) notation f₀ ` ≃ `:50 f₁:50 := homotopic f₀ f₁ @[refl] lemma homotopic.refl {x y : C} (f : x ⟶ y) : f ≃ f := ⟨homotopy.refl f⟩ lemma homotopic.congr_left {x y y' : C} (g : y ⟶ y') {f₀ f₁ : x ⟶ y} (h : f₀ ≃ f₁) : g ∘ f₀ ≃ g ∘ f₁ := let ⟨H⟩ := h in ⟨H.congr_left g⟩ lemma homotopic.congr_right {x' x y : C} (g : x' ⟶ x) {f₀ f₁ : x ⟶ y} (h : f₀ ≃ f₁) : f₀ ∘ g ≃ f₁ ∘ g := let ⟨H⟩ := h in ⟨H.congr_right g⟩ -- The relation of being homotopic rel a fixed map j : A → X. def homotopic_rel {a x y : C} (j : a ⟶ x) (f₀ f₁ : x ⟶ y) : Prop := ∃ H : homotopy f₀ f₁, H.is_rel j notation f₀ ` ≃ `:50 f₁:50 ` rel `:50 j:50 := homotopic_rel j f₀ f₁ @[refl] lemma homotopic_rel.refl {a x y : C} {j : a ⟶ x} (f : x ⟶ y) : f ≃ f rel j := ⟨homotopy.refl f, homotopy.refl_is_rel⟩ lemma homotopic_rel.congr_left {a x y y' : C} {j : a ⟶ x} (g : y ⟶ y') {f₀ f₁ : x ⟶ y} : f₀ ≃ f₁ rel j → g ∘ f₀ ≃ g ∘ f₁ rel j := assume ⟨H, h⟩, ⟨H.congr_left g, homotopy.congr_left_is_rel g h⟩ lemma homotopic_rel.congr_right {a x' x y : C} {j' : a ⟶ x'} (g : x' ⟶ x) {f₀ f₁ : x ⟶ y} : f₀ ≃ f₁ rel (g ∘ j') → f₀ ∘ g ≃ f₁ ∘ g rel j' := assume ⟨H, h⟩, ⟨H.congr_right g, homotopy.congr_right_is_rel g h⟩ lemma homotopic_rel.forget_rel {a x y : C} {j : a ⟶ x} {f₀ f₁ : x ⟶ y} : f₀ ≃ f₁ rel j → f₀ ≃ f₁ := assume ⟨H, h⟩, ⟨H⟩ lemma homotopic_rel_initial {a x y : C} (Iai : Is_initial_object.{v} (I.obj a)) (j : a ⟶ x) (f₀ f₁ : x ⟶ y) : (f₀ ≃ f₁ rel j) = (f₀ ≃ f₁) := propext $ iff.intro (assume ⟨H, _⟩, ⟨H⟩) (assume ⟨H⟩, ⟨H, H.is_rel_initial Iai⟩) end homotopy_theory.cylinder
05ec9d92bbabf54311fcac3907c7f5b5e6a5d612
ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5
/tests/plugin/SnakeLinter.lean
0cd958d8aed5510ec8be83df1c36ac4920929e58
[ "Apache-2.0" ]
permissive
dupuisf/lean4
d082d13b01243e1de29ae680eefb476961221eef
6a39c65bd28eb0e28c3870188f348c8914502718
refs/heads/master
1,676,948,755,391
1,610,665,114,000
1,610,665,114,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
540
lean
#lang lean4 import Lean open Lean def oh_no : Nat := 0 def snakeLinter : Linter := fun stx => do if stx.getKind == `Lean.Parser.Command.declaration then let decl := stx[1] if decl.getKind == `Lean.Parser.Command.def then let declId := decl[1] withRef declId do let declName := declId[0].getId if declName.eraseMacroScopes.toString.contains '_' then -- TODO(Sebastian): return actual message with position from syntax tree throwError "SNAKES!!" initialize addLinter snakeLinter
a162fb2c56efd4fd26dd8075828e35ba4efd92bd
4727251e0cd73359b15b664c3170e5d754078599
/src/algebra/category/Module/limits.lean
51386835a918b1514c07995868234781750562a1
[ "Apache-2.0" ]
permissive
Vierkantor/mathlib
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
refs/heads/master
1,658,323,012,449
1,652,256,003,000
1,652,256,003,000
209,296,341
0
1
Apache-2.0
1,568,807,655,000
1,568,807,655,000
null
UTF-8
Lean
false
false
7,500
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import algebra.category.Module.basic import algebra.category.Group.limits import algebra.direct_limit /-! # The category of R-modules has all limits Further, these limits are preserved by the forgetful functor --- that is, the underlying types are just the limits in the category of types. -/ open category_theory open category_theory.limits universes v w u -- `u` is determined by the ring, so can come last noncomputable theory namespace Module variables {R : Type u} [ring R] variables {J : Type v} [small_category J] instance add_comm_group_obj (F : J ⥤ Module.{max v w} R) (j) : add_comm_group ((F ⋙ forget (Module R)).obj j) := by { change add_comm_group (F.obj j), apply_instance } instance module_obj (F : J ⥤ Module.{max v w} R) (j) : module R ((F ⋙ forget (Module R)).obj j) := by { change module R (F.obj j), apply_instance } /-- The flat sections of a functor into `Module R` form a submodule of all sections. -/ def sections_submodule (F : J ⥤ Module.{max v w} R) : submodule R (Π j, F.obj j) := { carrier := (F ⋙ forget (Module R)).sections, smul_mem' := λ r s sh j j' f, begin simp only [forget_map_eq_coe, functor.comp_map, pi.smul_apply, linear_map.map_smul], dsimp [functor.sections] at sh, rw sh f, end, ..(AddGroup.sections_add_subgroup (F ⋙ forget₂ (Module R) AddCommGroup.{max v w} ⋙ forget₂ AddCommGroup AddGroup.{max v w})) } -- Adding the following instance speeds up `limit_module` noticeably, -- by preventing a bad unfold of `limit_add_comm_group`. instance limit_add_comm_monoid (F : J ⥤ Module R) : add_comm_monoid (types.limit_cone (F ⋙ forget (Module.{max v w} R))).X := show add_comm_monoid (sections_submodule F), by apply_instance instance limit_add_comm_group (F : J ⥤ Module R) : add_comm_group (types.limit_cone (F ⋙ forget (Module.{max v w} R))).X := show add_comm_group (sections_submodule F), by apply_instance instance limit_module (F : J ⥤ Module R) : module R (types.limit_cone (F ⋙ forget (Module.{max v w} R))).X := show module R (sections_submodule F), by apply_instance /-- `limit.π (F ⋙ forget Ring) j` as a `ring_hom`. -/ def limit_π_linear_map (F : J ⥤ Module R) (j) : (types.limit_cone (F ⋙ forget (Module.{max v w} R))).X →ₗ[R] (F ⋙ forget (Module R)).obj j := { to_fun := (types.limit_cone (F ⋙ forget (Module R))).π.app j, map_smul' := λ x y, rfl, map_add' := λ x y, rfl } namespace has_limits -- The next two definitions are used in the construction of `has_limits (Module R)`. -- After that, the limits should be constructed using the generic limits API, -- e.g. `limit F`, `limit.cone F`, and `limit.is_limit F`. /-- Construction of a limit cone in `Module R`. (Internal use only; use the limits API.) -/ def limit_cone (F : J ⥤ Module.{max v w} R) : cone F := { X := Module.of R (types.limit_cone (F ⋙ forget _)).X, π := { app := limit_π_linear_map F, naturality' := λ j j' f, linear_map.coe_injective ((types.limit_cone (F ⋙ forget _)).π.naturality f) } } /-- Witness that the limit cone in `Module R` is a limit cone. (Internal use only; use the limits API.) -/ def limit_cone_is_limit (F : J ⥤ Module.{max v w} R) : is_limit (limit_cone F) := by refine is_limit.of_faithful (forget (Module R)) (types.limit_cone_is_limit _) (λ s, ⟨_, _, _⟩) (λ s, rfl); intros; ext j; simp only [subtype.coe_mk, functor.map_cone_π_app, forget_map_eq_coe, linear_map.map_add, linear_map.map_smul]; refl end has_limits open has_limits /-- The category of R-modules has all limits. -/ @[irreducible] instance has_limits_of_size : has_limits_of_size.{v v} (Module.{max v w} R) := { has_limits_of_shape := λ J 𝒥, by exactI { has_limit := λ F, has_limit.mk { cone := limit_cone F, is_limit := limit_cone_is_limit F } } } instance has_limits : has_limits (Module.{w} R) := Module.has_limits_of_size.{w w u} /-- An auxiliary declaration to speed up typechecking. -/ def forget₂_AddCommGroup_preserves_limits_aux (F : J ⥤ Module.{max v w} R) : is_limit ((forget₂ (Module R) AddCommGroup).map_cone (limit_cone F)) := AddCommGroup.limit_cone_is_limit (F ⋙ forget₂ (Module R) AddCommGroup.{max v w}) /-- The forgetful functor from R-modules to abelian groups preserves all limits. -/ instance forget₂_AddCommGroup_preserves_limits_of_size : preserves_limits_of_size.{v v} (forget₂ (Module R) AddCommGroup.{max v w}) := { preserves_limits_of_shape := λ J 𝒥, by exactI { preserves_limit := λ F, preserves_limit_of_preserves_limit_cone (limit_cone_is_limit F) (forget₂_AddCommGroup_preserves_limits_aux F) } } instance forget₂_AddCommGroup_preserves_limits : preserves_limits (forget₂ (Module R) AddCommGroup.{w}) := Module.forget₂_AddCommGroup_preserves_limits_of_size.{w w} /-- The forgetful functor from R-modules to types preserves all limits. -/ instance forget_preserves_limits_of_size : preserves_limits_of_size.{v v} (forget (Module.{max v w} R)) := { preserves_limits_of_shape := λ J 𝒥, by exactI { preserves_limit := λ F, preserves_limit_of_preserves_limit_cone (limit_cone_is_limit F) (types.limit_cone_is_limit (F ⋙ forget _)) } } instance forget_preserves_limits : preserves_limits (forget (Module.{w} R)) := Module.forget_preserves_limits_of_size.{w w} section direct_limit open module variables {ι : Type v} variables [dec_ι : decidable_eq ι] [preorder ι] variables (G : ι → Type v) variables [Π i, add_comm_group (G i)] [Π i, module R (G i)] variables (f : Π i j, i ≤ j → G i →ₗ[R] G j) [directed_system G (λ i j h, f i j h)] /-- The diagram (in the sense of `category_theory`) of an unbundled `direct_limit` of modules. -/ @[simps] def direct_limit_diagram : ι ⥤ Module R := { obj := λ i, Module.of R (G i), map := λ i j hij, f i j hij.le, map_id' := λ i, by { apply linear_map.ext, intro x, apply module.directed_system.map_self }, map_comp' := λ i j k hij hjk, begin apply linear_map.ext, intro x, symmetry, apply module.directed_system.map_map end } variables [decidable_eq ι] /-- The `cocone` on `direct_limit_diagram` corresponding to the unbundled `direct_limit` of modules. In `direct_limit_is_colimit` we show that it is a colimit cocone. -/ @[simps] def direct_limit_cocone : cocone (direct_limit_diagram G f) := { X := Module.of R $ direct_limit G f, ι := { app := module.direct_limit.of R ι G f, naturality' := λ i j hij, by { apply linear_map.ext, intro x, exact direct_limit.of_f } } } /-- The unbundled `direct_limit` of modules is a colimit in the sense of `category_theory`. -/ @[simps] def direct_limit_is_colimit [nonempty ι] [is_directed ι (≤)] : is_colimit (direct_limit_cocone G f) := { desc := λ s, direct_limit.lift R ι G f s.ι.app $ λ i j h x, by { rw [←s.w (hom_of_le h)], refl }, fac' := λ s i, begin apply linear_map.ext, intro x, dsimp, exact direct_limit.lift_of s.ι.app _ x, end, uniq' := λ s m h, begin have : s.ι.app = λ i, linear_map.comp m (direct_limit.of R ι (λ i, G i) (λ i j H, f i j H) i), { funext i, rw ← h, refl }, apply linear_map.ext, intro x, simp only [this], apply module.direct_limit.lift_unique end } end direct_limit end Module
bb31b4bf860ec0eb371380427f92f7cae4519e39
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/tactic/generalize_proofs.lean
4ad2ea32425a7f6d5978d39b5ee692f3a3710896
[]
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
842
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.tactic.doc_commands import Mathlib.PostPort namespace Mathlib /-! # `generalize_proofs` A simple tactic to find and replace all occurrences of proof terms in the context and goal with new variables. -/ namespace tactic /-- Generalize proofs in the goal, naming them with the provided list. -/ namespace interactive /-- Generalize proofs in the goal, naming them with the provided list. For example: ```lean example : list.nth_le [1, 2] 1 dec_trivial = 2 := begin -- ⊢ [1, 2].nth_le 1 _ = 2 generalize_proofs h, -- h : 1 < [1, 2].length -- ⊢ [1, 2].nth_le 1 h = 2 end ``` -/ end interactive
93ca60b815feb7265d6db02acbdd75c1a2799f38
75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2
/tests/lean/run/have1.lean
9fd2e17d1d5000183f90d3c6bbbe0658fea542ad
[ "Apache-2.0" ]
permissive
jroesch/lean
30ef0860fa905d35b9ad6f76de1a4f65c9af6871
3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2
refs/heads/master
1,586,090,835,348
1,455,142,203,000
1,455,142,277,000
51,536,958
1
0
null
1,455,215,811,000
1,455,215,811,000
null
UTF-8
Lean
false
false
184
lean
prelude definition Prop : Type.{1} := Type.{0} constants a b c : Prop axiom Ha : a axiom Hb : b axiom Hc : c check have H1 : a, from Ha, have H2 : a, using H1, from H1, H2
fc71171f1567f526dd7ef8451cb906f81d74c546
94e33a31faa76775069b071adea97e86e218a8ee
/src/analysis/special_functions/polar_coord.lean
03a219bbc35155c2b202a08ff40d29b2b87fa5ec
[ "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
6,760
lean
/- Copyright (c) 2022 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 measure_theory.function.jacobian /-! # Polar coordinates We define polar coordinates, as a local homeomorphism in `ℝ^2` between `ℝ^2 - (-∞, 0]` and `(0, +∞) × (-π, π)`. Its inverse is given by `(r, θ) ↦ (r cos θ, r sin θ)`. It satisfies the following change of variables formula (see `integral_comp_polar_coord_symm`): `∫ p in polar_coord.target, p.1 • f (polar_coord.symm p) = ∫ p, f p` -/ noncomputable theory open real set measure_theory open_locale real topological_space /-- The polar coordinates local homeomorphism in `ℝ^2`, mapping `(r cos θ, r sin θ)` to `(r, θ)`. It is a homeomorphism between `ℝ^2 - (-∞, 0]` and `(0, +∞) × (-π, π)`. -/ @[simps] def polar_coord : local_homeomorph (ℝ × ℝ) (ℝ × ℝ) := { to_fun := λ q, (real.sqrt (q.1^2 + q.2^2), complex.arg (complex.equiv_real_prod.symm q)), inv_fun := λ p, (p.1 * cos p.2, p.1 * sin p.2), source := {q | 0 < q.1} ∪ {q | q.2 ≠ 0}, target := Ioi (0 : ℝ) ×ˢ Ioo (-π) π, map_target' := begin rintros ⟨r, θ⟩ ⟨hr, hθ⟩, dsimp at hr hθ, rcases eq_or_ne θ 0 with rfl|h'θ, { simpa using hr }, { right, simpa only [ne_of_gt hr, ne.def, mem_set_of_eq, mul_eq_zero, false_or, sin_eq_zero_iff_of_lt_of_lt hθ.1 hθ.2] using h'θ } end, map_source' := begin rintros ⟨x, y⟩ hxy, simp only [prod_mk_mem_set_prod_eq, mem_Ioi, sqrt_pos, mem_Ioo, complex.neg_pi_lt_arg, true_and, complex.arg_lt_pi_iff], split, { cases hxy, { dsimp at hxy, linarith [sq_pos_of_ne_zero _ (hxy.ne'), sq_nonneg y] }, { linarith [sq_nonneg x, sq_pos_of_ne_zero _ hxy] } }, { cases hxy, { exact or.inl (le_of_lt hxy) }, { exact or.inr hxy } } end, right_inv' := begin rintros ⟨r, θ⟩ ⟨hr, hθ⟩, dsimp at hr hθ, simp only [prod.mk.inj_iff], split, { conv_rhs { rw [← sqrt_sq (le_of_lt hr), ← one_mul (r^2), ← sin_sq_add_cos_sq θ], }, congr' 1, ring_exp }, { convert complex.arg_mul_cos_add_sin_mul_I hr ⟨hθ.1, hθ.2.le⟩, simp only [complex.equiv_real_prod_symm_apply, complex.of_real_mul, complex.of_real_cos, complex.of_real_sin], ring } end, left_inv' := begin rintros ⟨x, y⟩ hxy, have A : sqrt (x ^ 2 + y ^ 2) = complex.abs (x + y * complex.I), by simp only [complex.abs, complex.norm_sq, pow_two, monoid_with_zero_hom.coe_mk, complex.add_re, complex.of_real_re, complex.mul_re, complex.I_re, mul_zero, complex.of_real_im, complex.I_im, sub_self, add_zero, complex.add_im, complex.mul_im, mul_one, zero_add], have Z := complex.abs_mul_cos_add_sin_mul_I (x + y * complex.I), simp only [← complex.of_real_cos, ← complex.of_real_sin, mul_add, ← complex.of_real_mul, ← mul_assoc] at Z, simpa [A, -complex.of_real_cos, -complex.of_real_sin] using complex.ext_iff.1 Z, end, open_target := is_open_Ioi.prod is_open_Ioo, open_source := (is_open_lt continuous_const continuous_fst).union (is_open_ne_fun continuous_snd continuous_const), continuous_inv_fun := ((continuous_fst.mul (continuous_cos.comp continuous_snd)).prod_mk (continuous_fst.mul (continuous_sin.comp continuous_snd))).continuous_on, continuous_to_fun := begin apply ((continuous_fst.pow 2).add (continuous_snd.pow 2)).sqrt.continuous_on.prod, have A : maps_to complex.equiv_real_prod.symm ({q : ℝ × ℝ | 0 < q.1} ∪ {q : ℝ × ℝ | q.2 ≠ 0}) {z | 0 < z.re ∨ z.im ≠ 0}, { rintros ⟨x, y⟩ hxy, simpa only using hxy }, apply continuous_on.comp (λ z hz, _) _ A, { exact (complex.continuous_at_arg hz).continuous_within_at }, { exact complex.equiv_real_prodₗ.symm.continuous.continuous_on } end } lemma has_fderiv_at_polar_coord_symm (p : ℝ × ℝ) : has_fderiv_at polar_coord.symm (matrix.to_lin (basis.fin_two_prod ℝ) (basis.fin_two_prod ℝ) (![![cos p.2, -p.1 * sin p.2], ![sin p.2, p.1 * cos p.2]])).to_continuous_linear_map p := begin rw matrix.to_lin_fin_two_prod_to_continuous_linear_map, convert has_fderiv_at.prod (has_fderiv_at_fst.mul ((has_deriv_at_cos p.2).comp_has_fderiv_at p has_fderiv_at_snd)) (has_fderiv_at_fst.mul ((has_deriv_at_sin p.2).comp_has_fderiv_at p has_fderiv_at_snd)) using 2; simp only [smul_smul, add_comm, neg_mul, neg_smul, smul_neg], end lemma polar_coord_source_ae_eq_univ : polar_coord.source =ᵐ[volume] univ := begin have A : polar_coord.sourceᶜ ⊆ (linear_map.snd ℝ ℝ ℝ).ker, { assume x hx, simp only [polar_coord_source, compl_union, mem_inter_eq, mem_compl_eq, mem_set_of_eq, not_lt, not_not] at hx, exact hx.2 }, have B : volume ((linear_map.snd ℝ ℝ ℝ).ker : set (ℝ × ℝ)) = 0, { apply measure.add_haar_submodule, rw [ne.def, linear_map.ker_eq_top], assume h, have : (linear_map.snd ℝ ℝ ℝ) (0, 1) = (0 : (ℝ × ℝ →ₗ[ℝ] ℝ)) (0, 1), by rw h, simpa using this }, simp only [ae_eq_univ], exact le_antisymm ((measure_mono A).trans (le_of_eq B)) bot_le, end theorem integral_comp_polar_coord_symm {E : Type*} [normed_group E] [normed_space ℝ E] [complete_space E] (f : ℝ × ℝ → E) : ∫ p in polar_coord.target, p.1 • f (polar_coord.symm p) = ∫ p, f p := begin set B : (ℝ × ℝ) → ((ℝ × ℝ) →L[ℝ] (ℝ × ℝ)) := λ p, (matrix.to_lin (basis.fin_two_prod ℝ) (basis.fin_two_prod ℝ) ![![cos p.2, -p.1 * sin p.2], ![sin p.2, p.1 * cos p.2]]).to_continuous_linear_map with hB, have A : ∀ p ∈ polar_coord.symm.source, has_fderiv_at polar_coord.symm (B p) p := λ p hp, has_fderiv_at_polar_coord_symm p, have B_det : ∀ p, (B p).det = p.1, { assume p, conv_rhs {rw [← one_mul p.1, ← cos_sq_add_sin_sq p.2] }, simp only [neg_mul, linear_map.det_to_continuous_linear_map, linear_map.det_to_lin, matrix.det_fin_two, sub_neg_eq_add, matrix.cons_val_zero, matrix.cons_val_one, matrix.head_cons], ring_exp }, symmetry, calc ∫ p, f p = ∫ p in polar_coord.source, f p : begin rw ← integral_univ, apply set_integral_congr_set_ae, exact polar_coord_source_ae_eq_univ.symm end ... = ∫ p in polar_coord.target, abs ((B p).det) • f (polar_coord.symm p) : by apply integral_target_eq_integral_abs_det_fderiv_smul volume A ... = ∫ p in polar_coord.target, p.1 • f (polar_coord.symm p) : begin apply set_integral_congr (polar_coord.open_target.measurable_set) (λ x hx, _), rw [B_det, abs_of_pos], exact hx.1, end end
002717642aff08fc8f34e5eb004a8b2ec4dd32e9
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/algebra/category/Semigroup/basic.lean
7ebbd336f04977ab755b9391e9253af73133e215
[ "Apache-2.0" ]
permissive
jjgarzella/mathlib
96a345378c4e0bf26cf604aed84f90329e4896a2
395d8716c3ad03747059d482090e2bb97db612c8
refs/heads/master
1,686,480,124,379
1,625,163,323,000
1,625,163,323,000
281,190,421
2
0
Apache-2.0
1,595,268,170,000
1,595,268,169,000
null
UTF-8
Lean
false
false
6,521
lean
/- Copyright (c) 2021 Julian Kuelshammer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Julian Kuelshammer -/ import category_theory.concrete_category.bundled_hom import category_theory.concrete_category.reflects_isomorphisms import algebra.pempty_instances /-! # Category instances for has_mul, has_add, semigroup and add_semigroup We introduce the bundled categories: * `Magma` * `AddMagma` * `Semigroup` * `AddSemigroup` along with the relevant forgetful functors between them. This closely follows `algebra.category.Mon.basic`. ## TODO * Limits in these categories * free/forgetful adjunctions -/ universes u v open category_theory /-- The category of magmas and magma morphisms. -/ @[to_additive AddMagma] def Magma : Type (u+1) := bundled has_mul /-- The category of additive magmas and additive magma morphisms. -/ add_decl_doc AddMagma namespace Magma @[to_additive] instance bundled_hom : bundled_hom @mul_hom := ⟨@mul_hom.to_fun, @mul_hom.id, @mul_hom.comp, @mul_hom.coe_inj⟩ attribute [derive [has_coe_to_sort, large_category, concrete_category]] Magma attribute [to_additive] Magma.has_coe_to_sort Magma.large_category Magma.concrete_category /-- Construct a bundled `Magma` from the underlying type and typeclass. -/ @[to_additive] def of (M : Type u) [has_mul M] : Magma := bundled.of M /-- Construct a bundled `Magma` from the underlying type and typeclass. -/ add_decl_doc AddMagma.of @[to_additive] instance : inhabited Magma := ⟨Magma.of pempty⟩ @[to_additive] instance (M : Magma) : has_mul M := M.str @[simp, to_additive] lemma coe_of (R : Type u) [has_mul R] : (Magma.of R : Type u) = R := rfl end Magma /-- The category of semigroups and semigroup morphisms. -/ @[to_additive AddSemigroup] def Semigroup : Type (u+1) := bundled semigroup /-- The category of additive semigroups and semigroup morphisms. -/ add_decl_doc AddSemigroup namespace Semigroup @[to_additive] instance : bundled_hom.parent_projection semigroup.to_has_mul := ⟨⟩ attribute [derive [has_coe_to_sort, large_category, concrete_category]] Semigroup attribute [to_additive] Semigroup.has_coe_to_sort Semigroup.large_category Semigroup.concrete_category /-- Construct a bundled `Semigroup` from the underlying type and typeclass. -/ @[to_additive] def of (M : Type u) [semigroup M] : Semigroup := bundled.of M /-- Construct a bundled `AddSemigroup` from the underlying type and typeclass. -/ add_decl_doc AddSemigroup.of @[to_additive] instance : inhabited Semigroup := ⟨Semigroup.of pempty⟩ @[to_additive] instance (M : Semigroup) : semigroup M := M.str @[simp, to_additive] lemma coe_of (R : Type u) [semigroup R] : (Semigroup.of R : Type u) = R := rfl @[to_additive has_forget_to_AddMagma] instance has_forget_to_Magma : has_forget₂ Semigroup Magma := bundled_hom.forget₂ _ _ end Semigroup variables {X Y : Type u} section variables [has_mul X] [has_mul Y] /-- Build an isomorphism in the category `Magma` from a `mul_equiv` between `has_mul`s. -/ @[to_additive add_equiv.to_AddMagma_iso "Build an isomorphism in the category `AddMagma` from an `add_equiv` between `has_add`s.", simps] def mul_equiv.to_Magma_iso (e : X ≃* Y) : Magma.of X ≅ Magma.of Y := { hom := e.to_mul_hom, inv := e.symm.to_mul_hom } end section variables [semigroup X] [semigroup Y] /-- Build an isomorphism in the category `Semigroup` from a `mul_equiv` between `semigroup`s. -/ @[to_additive add_equiv.to_AddSemigroup_iso "Build an isomorphism in the category `AddSemigroup` from an `add_equiv` between `add_semigroup`s.", simps] def mul_equiv.to_Semigroup_iso (e : X ≃* Y) : Semigroup.of X ≅ Semigroup.of Y := { hom := e.to_mul_hom, inv := e.symm.to_mul_hom } end namespace category_theory.iso /-- Build a `mul_equiv` from an isomorphism in the category `Magma`. -/ @[to_additive AddMagma_iso_to_add_equiv "Build an `add_equiv` from an isomorphism in the category `AddMagma`."] def Magma_iso_to_mul_equiv {X Y : Magma} (i : X ≅ Y) : X ≃* Y := { to_fun := i.hom, inv_fun := i.inv, left_inv := begin rw function.left_inverse, simp end, right_inv := begin rw function.right_inverse, rw function.left_inverse, simp end, map_mul' := by simp } /-- Build a `mul_equiv` from an isomorphism in the category `Semigroup`. -/ @[to_additive "Build an `add_equiv` from an isomorphism in the category `AddSemigroup`."] def Semigroup_iso_to_mul_equiv {X Y : Semigroup} (i : X ≅ Y) : X ≃* Y := { to_fun := i.hom, inv_fun := i.inv, left_inv := begin rw function.left_inverse, simp end, right_inv := begin rw function.right_inverse, rw function.left_inverse, simp end, map_mul' := by simp } end category_theory.iso /-- multiplicative equivalences between `has_mul`s are the same as (isomorphic to) isomorphisms in `Magma` -/ @[to_additive add_equiv_iso_AddMagma_iso "additive equivalences between `has_add`s are the same as (isomorphic to) isomorphisms in `AddMagma`"] def mul_equiv_iso_Magma_iso {X Y : Type u} [has_mul X] [has_mul Y] : (X ≃* Y) ≅ (Magma.of X ≅ Magma.of Y) := { hom := λ e, e.to_Magma_iso, inv := λ i, i.Magma_iso_to_mul_equiv } /-- multiplicative equivalences between `semigroup`s are the same as (isomorphic to) isomorphisms in `Semigroup` -/ @[to_additive add_equiv_iso_AddSemigroup_iso "additive equivalences between `add_semigroup`s are the same as (isomorphic to) isomorphisms in `AddSemigroup`"] def mul_equiv_iso_Semigroup_iso {X Y : Type u} [semigroup X] [semigroup Y] : (X ≃* Y) ≅ (Semigroup.of X ≅ Semigroup.of Y) := { hom := λ e, e.to_Semigroup_iso, inv := λ i, i.Semigroup_iso_to_mul_equiv } @[to_additive] instance Magma.forget_reflects_isos : reflects_isomorphisms (forget Magma.{u}) := { reflects := λ X Y f _, begin resetI, let i := as_iso ((forget Magma).map f), let e : X ≃* Y := { ..f, ..i.to_equiv }, exact ⟨(is_iso.of_iso e.to_Magma_iso).1⟩, end } @[to_additive] instance Semigroup.forget_reflects_isos : reflects_isomorphisms (forget Semigroup.{u}) := { reflects := λ X Y f _, begin resetI, let i := as_iso ((forget Semigroup).map f), let e : X ≃* Y := { ..f, ..i.to_equiv }, exact ⟨(is_iso.of_iso e.to_Semigroup_iso).1⟩, end } /-! Once we've shown that the forgetful functors to type reflect isomorphisms, we automatically obtain that the `forget₂` functors between our concrete categories reflect isomorphisms. -/ example : reflects_isomorphisms (forget₂ Semigroup Magma) := by apply_instance
5ecf0e3e5f3068552003ba28e7769e6638bf6c5b
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
/src/data/polynomial/basic.lean
526273349bdf92a6c7a2b5446fa117b758224f43
[ "Apache-2.0" ]
permissive
dupuisf/mathlib
62de4ec6544bf3b79086afd27b6529acfaf2c1bb
8582b06b0a5d06c33ee07d0bdf7c646cae22cf36
refs/heads/master
1,669,494,854,016
1,595,692,409,000
1,595,692,409,000
272,046,630
0
0
Apache-2.0
1,592,066,143,000
1,592,066,142,000
null
UTF-8
Lean
false
false
5,310
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 -/ import tactic.ring_exp import tactic.chain import data.monoid_algebra import data.finset.sort /-! # Theory of univariate polynomials Polynomials are represented as `add_monoid_algebra R ℕ`, where `R` is a commutative semiring. In this file, we define `polynomial`, provide basic instances, and prove an `ext` lemma. -/ noncomputable theory /-- `polynomial R` is the type of univariate polynomials over `R`. Polynomials should be seen as (semi-)rings with the additional constructor `X`. The embedding from `R` is called `C`. -/ def polynomial (R : Type*) [semiring R] := add_monoid_algebra R ℕ open finsupp add_monoid_algebra open_locale big_operators namespace polynomial universes u variables {R : Type u} {a : R} {m n : ℕ} section semiring variables [semiring R] {p q : polynomial R} instance : inhabited (polynomial R) := finsupp.inhabited instance : semiring (polynomial R) := add_monoid_algebra.semiring instance : has_scalar R (polynomial R) := add_monoid_algebra.has_scalar instance : semimodule R (polynomial R) := add_monoid_algebra.semimodule instance subsingleton [subsingleton R] : subsingleton (polynomial R) := ⟨λ _ _, ext (λ _, subsingleton.elim _ _)⟩ @[simp] lemma support_zero : (0 : polynomial R).support = ∅ := rfl /-- `monomial s a` is the monomial `a * X^s` -/ def monomial (n : ℕ) (a : R) : polynomial R := finsupp.single n a @[simp] lemma monomial_zero_right (n : ℕ) : monomial n (0 : R) = 0 := by simp [monomial] lemma monomial_add (n : ℕ) (r s : R) : monomial n (r + s) = monomial n r + monomial n s := by simp [monomial] lemma monomial_mul_monomial (n m : ℕ) (r s : R) : monomial n r * monomial m s = monomial (n + m) (r * s) := by simp only [monomial, single_mul_single] /-- `X` is the polynomial variable (aka indeterminant). -/ def X : polynomial R := monomial 1 1 /-- `X` commutes with everything, even when the coefficients are noncommutative. -/ lemma X_mul : X * p = p * X := begin ext, simp [X, monomial, add_monoid_algebra.mul_apply, sum_single_index, add_comm], end lemma X_pow_mul {n : ℕ} : X^n * p = p * X^n := begin induction n with n ih, { simp, }, { conv_lhs { rw pow_succ', }, rw [mul_assoc, X_mul, ←mul_assoc, ih, mul_assoc, ←pow_succ'], } end lemma X_pow_mul_assoc {n : ℕ} : (p * X^n) * q = (p * q) * X^n := by rw [mul_assoc, X_pow_mul, ←mul_assoc] /-- coeff p n is the coefficient of X^n in p -/ def coeff (p : polynomial R) := p.to_fun @[simp] lemma coeff_mk (s) (f) (h) : coeff (finsupp.mk s f h : polynomial R) = f := rfl lemma coeff_monomial : coeff (monomial n a) m = if n = m then a else 0 := by { dsimp [monomial, single, finsupp.single], congr, } /-- This lemma is needed for occasions when we break through the abstraction from `polynomial` to `finsupp`; ideally it wouldn't be necessary at all. -/ lemma coeff_single : coeff (single n a) m = if n = m then a else 0 := coeff_monomial @[simp] lemma coeff_zero (n : ℕ) : coeff (0 : polynomial R) n = 0 := rfl @[simp] lemma coeff_one_zero : coeff (1 : polynomial R) 0 = 1 := coeff_monomial @[simp] lemma coeff_X_one : coeff (X : polynomial R) 1 = 1 := coeff_monomial @[simp] lemma coeff_X_zero : coeff (X : polynomial R) 0 = 0 := coeff_monomial lemma coeff_X : coeff (X : polynomial R) n = if 1 = n then 1 else 0 := coeff_monomial theorem ext_iff {p q : polynomial R} : p = q ↔ ∀ n, coeff p n = coeff q n := ⟨λ h n, h ▸ rfl, finsupp.ext⟩ @[ext] lemma ext {p q : polynomial R} : (∀ n, coeff p n = coeff q n) → p = q := (@ext_iff _ _ p q).2 -- this has the same content as the subsingleton lemma eq_zero_of_eq_zero (h : (0 : R) = (1 : R)) (p : polynomial R) : p = 0 := by rw [←one_smul R p, ←h, zero_smul] end semiring section ring variables [ring R] instance : ring (polynomial R) := add_monoid_algebra.ring @[simp] lemma coeff_neg (p : polynomial R) (n : ℕ) : coeff (-p) n = -coeff p n := rfl @[simp] lemma coeff_sub (p q : polynomial R) (n : ℕ) : coeff (p - q) n = coeff p n - coeff q n := rfl end ring instance [comm_semiring R] : comm_semiring (polynomial R) := add_monoid_algebra.comm_semiring instance [comm_ring R] : comm_ring (polynomial R) := add_monoid_algebra.comm_ring section nonzero_semiring variables [semiring R] [nontrivial R] instance : nontrivial (polynomial R) := begin refine nontrivial_of_ne 0 1 _, intro h, have := coeff_zero 0, revert this, rw h, simp, end lemma X_ne_zero : (X : polynomial R) ≠ 0 := mt (congr_arg (λ p, coeff p 1)) (by simp) end nonzero_semiring section repr variables [semiring R] local attribute [instance, priority 100] classical.prop_decidable instance [has_repr R] : has_repr (polynomial R) := ⟨λ 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) ""⟩ end repr end polynomial
db460149e34f1f51a4d527f4ab844895daa1ba93
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
/src/category_theory/limits/shapes/finite_products.lean
b5e567c05424127b47e830be919ccda7296144e5
[ "Apache-2.0" ]
permissive
dupuisf/mathlib
62de4ec6544bf3b79086afd27b6529acfaf2c1bb
8582b06b0a5d06c33ee07d0bdf7c646cae22cf36
refs/heads/master
1,669,494,854,016
1,595,692,409,000
1,595,692,409,000
272,046,630
0
0
Apache-2.0
1,592,066,143,000
1,592,066,142,000
null
UTF-8
Lean
false
false
2,321
lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import category_theory.limits.shapes.finite_limits import category_theory.limits.shapes.binary_products import category_theory.limits.shapes.terminal universes v u open category_theory namespace category_theory.limits variables (C : Type u) [category.{v} C] class has_finite_products := (has_limits_of_shape : Π (J : Type v) [fintype J] [decidable_eq J], has_limits_of_shape (discrete J) C) class has_finite_coproducts := (has_colimits_of_shape : Π (J : Type v) [fintype J] [decidable_eq J], has_colimits_of_shape (discrete J) C) attribute [instance] has_finite_products.has_limits_of_shape has_finite_coproducts.has_colimits_of_shape @[priority 100] -- see Note [lower instance priority] instance has_finite_products_of_has_products [has_products C] : has_finite_products C := { has_limits_of_shape := λ J _, by apply_instance } @[priority 100] -- see Note [lower instance priority] instance has_finite_coproducts_of_has_coproducts [has_coproducts C] : has_finite_coproducts C := { has_colimits_of_shape := λ J _, by apply_instance } @[priority 100] -- see Note [lower instance priority] instance has_finite_products_of_has_finite_limits [has_finite_limits C] : has_finite_products C := { has_limits_of_shape := λ J _ _, by { resetI, apply_instance } } @[priority 100] -- see Note [lower instance priority] instance has_finite_coproducts_of_has_finite_colimits [has_finite_colimits C] : has_finite_coproducts C := { has_colimits_of_shape := λ J _ _, by { resetI, apply_instance } } @[priority 200] -- see Note [lower instance priority] instance [has_finite_products C] : has_binary_products.{v} C := { has_limits_of_shape := by apply_instance } @[priority 200] -- see Note [lower instance priority] instance [has_finite_coproducts C] : has_binary_coproducts.{v} C := { has_colimits_of_shape := by apply_instance } @[priority 100] -- see Note [lower instance priority] instance [has_finite_products C] : has_terminal C := { has_limits_of_shape := by apply_instance } @[priority 100] -- see Note [lower instance priority] instance [has_finite_coproducts C] : has_initial C := { has_colimits_of_shape := by apply_instance } end category_theory.limits
d6659333c8dc0a5dedebd6bd97d78ebc2b0a55f7
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/data/nat/mul_ind.lean
681c91d861fdbaf37913333a07c61f60c088189c
[ "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
4,239
lean
/- Copyright (c) 2021 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez -/ import number_theory.padics.padic_norm /-! # Multiplicative induction principles for ℕ This file provides three (closely linked) induction principles for ℕ, commonly used for proofs about multiplicative functions, such as the totient function and the Möbius function. ## Main definitions * `nat.rec_on_prime_pow`: Given `P 0, P 1` and a way to extend `P a` to `P (p ^ k * a)`, you can define `P` for all natural numbers. * `nat.rec_on_prime_coprime`: Given `P 0`, `P (p ^ k)` for all `p` prime, and a way to extend `P a` and `P b` to `P (a * b)` when `a, b` are coprime, you can define `P` for all natural numbers. * `nat.rec_on_pos_prime_coprime`: Given `P 0`, `P 1`, and `P (p ^ k)` for positive prime powers, and a way to extend `P a` and `P b` to `P (a * b)` when `a, b` are coprime, you can define `P` for all natural numbers. * `nat.rec_on_mul`: Given `P 0`, `P 1`, `P p` for all primes, and a proof that you can extend `P a` and `P b` to `P (a * b)`, you can define `P` for all natural numbers. ## Implementation notes The proofs use `padic_val_nat`; however, we have `padic_val_nat p = nat.log p $ nat.gcd k (p ^ k)` for any `p ∣ k`, which requires far less imports - the API isn't there though; however, this is why it's in `data` even though we import `number_theory`; it's not a particularly deep theorem. ## TODO: Extend these results to any `normalization_monoid` with unique factorization. -/ namespace nat /-- Given `P 0, P 1` and a way to extend `P a` to `P (p ^ k * a)`, you can define `P` for all natural numbers. -/ @[elab_as_eliminator] def rec_on_prime_pow {P : ℕ → Sort*} (h0 : P 0) (h1 : P 1) (h : ∀ a p n : ℕ, p.prime → ¬ p ∣ a → P a → P (p ^ n * a)) : ∀ (a : ℕ), P a := λ a, nat.strong_rec_on a $ λ n, match n with | 0 := λ _, h0 | 1 := λ _, h1 | (k+2) := λ hk, begin let p := (k + 2).min_fac, haveI : fact (prime p) := ⟨min_fac_prime (succ_succ_ne_one k)⟩, let t := padic_val_nat p (k+2), have hpt : p ^ t ∣ k + 2 := pow_padic_val_nat_dvd, have ht : 0 < t := one_le_padic_val_nat_of_dvd (nat.succ_ne_zero (k + 1)) (min_fac_dvd _), convert h ((k + 2) / p ^ t) p t (fact.out _) _ _, { rw nat.mul_div_cancel' hpt }, { rw [nat.dvd_div_iff hpt, ←pow_succ'], exact pow_succ_padic_val_nat_not_dvd nat.succ_pos' }, apply hk _ (nat.div_lt_of_lt_mul _), rw [lt_mul_iff_one_lt_left nat.succ_pos', one_lt_pow_iff ht.ne], exact (prime.one_lt' p).out end end /-- Given `P 0`, `P 1`, and `P (p ^ k)` for positive prime powers, and a way to extend `P a` and `P b` to `P (a * b)` when `a, b` are coprime, you can define `P` for all natural numbers. -/ @[elab_as_eliminator] def rec_on_pos_prime_coprime {P : ℕ → Sort*} (hp : ∀ p n : ℕ, prime p → 0 < n → P (p ^ n)) (h0 : P 0) (h1 : P 1) (h : ∀ a b, coprime a b → P a → P b → P (a * b)) : ∀ a, P a := rec_on_prime_pow h0 h1 $ λ a p n hp' hpa ha, h (p ^ n) a ((prime.coprime_pow_of_not_dvd hp' hpa).symm) (if h : n = 0 then eq.rec h1 h.symm else hp p n hp' $ nat.pos_of_ne_zero h) ha /-- Given `P 0`, `P (p ^ k)` for all prime powers, and a way to extend `P a` and `P b` to `P (a * b)` when `a, b` are coprime, you can define `P` for all natural numbers. -/ @[elab_as_eliminator] def rec_on_prime_coprime {P : ℕ → Sort*} (h0 : P 0) (hp : ∀ p n : ℕ, prime p → P (p ^ n)) (h : ∀ a b, coprime a b → P a → P b → P (a * b)) : ∀ a, P a := rec_on_pos_prime_coprime (λ p n h _, hp p n h) h0 (hp 2 0 prime_two) h /-- Given `P 0`, `P 1`, `P p` for all primes, and a proof that you can extend `P a` and `P b` to `P (a * b)`, you can define `P` for all natural numbers. -/ @[elab_as_eliminator] def rec_on_mul {P : ℕ → Sort*} (h0 : P 0) (h1 : P 1) (hp : ∀ p, prime p → P p) (h : ∀ a b, P a → P b → P (a * b)) : ∀ a, P a := let hp : ∀ p n : ℕ, prime p → P (p ^ n) := λ p n hp', match n with | 0 := h1 | (n+1) := by exact h _ _ (hp p hp') (_match _) end in rec_on_prime_coprime h0 hp $ λ a b _, h a b end nat
655b49bc48fe1ece93f1e8fbe5763921df296aff
4727251e0cd73359b15b664c3170e5d754078599
/src/topology/metric_space/hausdorff_dimension.lean
59f7d7ff3dadf301eaa44d7d40668093ef25fb70
[ "Apache-2.0" ]
permissive
Vierkantor/mathlib
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
refs/heads/master
1,658,323,012,449
1,652,256,003,000
1,652,256,003,000
209,296,341
0
1
Apache-2.0
1,568,807,655,000
1,568,807,655,000
null
UTF-8
Lean
false
false
22,787
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 measure_theory.measure.hausdorff /-! # Hausdorff dimension The Hausdorff dimension of a set `X` in an (extended) metric space is the unique number `dimH s : ℝ≥0∞` such that for any `d : ℝ≥0` we have - `μH[d] s = 0` if `dimH s < d`, and - `μH[d] s = ∞` if `d < dimH s`. In this file we define `dimH s` to be the Hausdorff dimension of `s`, then prove some basic properties of Hausdorff dimension. ## Main definitions * `measure_theory.dimH`: the Hausdorff dimension of a set. For the Hausdorff dimension of the whole space we use `measure_theory.dimH (set.univ : set X)`. ## Main results ### Basic properties of Hausdorff dimension * `hausdorff_measure_of_lt_dimH`, `dimH_le_of_hausdorff_measure_ne_top`, `le_dimH_of_hausdorff_measure_eq_top`, `hausdorff_measure_of_dimH_lt`, `measure_zero_of_dimH_lt`, `le_dimH_of_hausdorff_measure_ne_zero`, `dimH_of_hausdorff_measure_ne_zero_ne_top`: various forms of the characteristic property of the Hausdorff dimension; * `dimH_union`: the Hausdorff dimension of the union of two sets is the maximum of their Hausdorff dimensions. * `dimH_Union`, `dimH_bUnion`, `dimH_sUnion`: the Hausdorff dimension of a countable union of sets is the supremum of their Hausdorff dimensions; * `dimH_empty`, `dimH_singleton`, `set.subsingleton.dimH_zero`, `set.countable.dimH_zero` : `dimH s = 0` whenever `s` is countable; ### (Pre)images under (anti)lipschitz and Hölder continuous maps * `holder_with.dimH_image_le` etc: if `f : X → Y` is Hölder continuous with exponent `r > 0`, then for any `s`, `dimH (f '' s) ≤ dimH s / r`. We prove versions of this statement for `holder_with`, `holder_on_with`, and locally Hölder maps, as well as for `set.image` and `set.range`. * `lipschitz_with.dimH_image_le` etc: Lipschitz continuous maps do not increase the Hausdorff dimension of sets. * for a map that is known to be both Lipschitz and antilipschitz (e.g., for an `isometry` or a `continuous_linear_equiv`) we also prove `dimH (f '' s) = dimH s`. ### Hausdorff measure in `ℝⁿ` * `real.dimH_of_nonempty_interior`: if `s` is a set in a finite dimensional real vector space `E` with nonempty interior, then the Hausdorff dimension of `s` is equal to the dimension of `E`. * `dense_compl_of_dimH_lt_finrank`: if `s` is a set in a finite dimensional real vector space `E` with Hausdorff dimension strictly less than the dimension of `E`, the `s` has a dense complement. * `cont_diff.dense_compl_range_of_finrank_lt_finrank`: the complement to the range of a `C¹` smooth map is dense provided that the dimension of the domain is strictly less than the dimension of the codomain. ## Notations We use the following notation localized in `measure_theory`. It is defined in `measure_theory.measure.hausdorff`. - `μH[d]` : `measure_theory.measure.hausdorff_measure d` ## Implementation notes * The definition of `dimH` explicitly uses `borel X` as a measurable space structure. This way we can formulate lemmas about Hausdorff dimension without assuming that the environment has a `[measurable_space X]` instance that is equal but possibly not defeq to `borel X`. Lemma `dimH_def` unfolds this definition using whatever `[measurable_space X]` instance we have in the environment (as long as it is equal to `borel X`). * The definition `dimH` is irreducible; use API lemmas or `dimH_def` instead. ## Tags Hausdorff measure, Hausdorff dimension, dimension -/ open_locale measure_theory ennreal nnreal topological_space open measure_theory measure_theory.measure set topological_space finite_dimensional filter variables {ι X Y : Type*} [emetric_space X] [emetric_space Y] /-- Hausdorff dimension of a set in an (e)metric space. -/ @[irreducible] noncomputable def dimH (s : set X) : ℝ≥0∞ := by { borelize X, exact ⨆ (d : ℝ≥0) (hd : @hausdorff_measure X _ _ ⟨rfl⟩ d s = ∞), d } /-! ### Basic properties -/ section measurable variables [measurable_space X] [borel_space X] /-- Unfold the definition of `dimH` using `[measurable_space X] [borel_space X]` from the environment. -/ lemma dimH_def (s : set X) : dimH s = ⨆ (d : ℝ≥0) (hd : μH[d] s = ∞), d := by { borelize X, rw dimH } lemma hausdorff_measure_of_lt_dimH {s : set X} {d : ℝ≥0} (h : ↑d < dimH s) : μH[d] s = ∞ := begin simp only [dimH_def, lt_supr_iff] at h, rcases h with ⟨d', hsd', hdd'⟩, rw [ennreal.coe_lt_coe, ← nnreal.coe_lt_coe] at hdd', exact top_unique (hsd' ▸ hausdorff_measure_mono hdd'.le _) end lemma dimH_le {s : set X} {d : ℝ≥0∞} (H : ∀ d' : ℝ≥0, μH[d'] s = ∞ → ↑d' ≤ d) : dimH s ≤ d := (dimH_def s).trans_le $ supr₂_le H lemma dimH_le_of_hausdorff_measure_ne_top {s : set X} {d : ℝ≥0} (h : μH[d] s ≠ ∞) : dimH s ≤ d := le_of_not_lt $ mt hausdorff_measure_of_lt_dimH h lemma le_dimH_of_hausdorff_measure_eq_top {s : set X} {d : ℝ≥0} (h : μH[d] s = ∞) : ↑d ≤ dimH s := by { rw dimH_def, exact le_supr₂ d h } lemma hausdorff_measure_of_dimH_lt {s : set X} {d : ℝ≥0} (h : dimH s < d) : μH[d] s = 0 := begin rw dimH_def at h, rcases ennreal.lt_iff_exists_nnreal_btwn.1 h with ⟨d', hsd', hd'd⟩, rw [ennreal.coe_lt_coe, ← nnreal.coe_lt_coe] at hd'd, exact (hausdorff_measure_zero_or_top hd'd s).resolve_right (λ h, hsd'.not_le $ le_supr₂ d' h) end lemma measure_zero_of_dimH_lt {μ : measure X} {d : ℝ≥0} (h : μ ≪ μH[d]) {s : set X} (hd : dimH s < d) : μ s = 0 := h $ hausdorff_measure_of_dimH_lt hd lemma le_dimH_of_hausdorff_measure_ne_zero {s : set X} {d : ℝ≥0} (h : μH[d] s ≠ 0) : ↑d ≤ dimH s := le_of_not_lt $ mt hausdorff_measure_of_dimH_lt h lemma dimH_of_hausdorff_measure_ne_zero_ne_top {d : ℝ≥0} {s : set X} (h : μH[d] s ≠ 0) (h' : μH[d] s ≠ ∞) : dimH s = d := le_antisymm (dimH_le_of_hausdorff_measure_ne_top h') (le_dimH_of_hausdorff_measure_ne_zero h) end measurable @[mono] lemma dimH_mono {s t : set X} (h : s ⊆ t) : dimH s ≤ dimH t := begin borelize X, exact dimH_le (λ d hd, le_dimH_of_hausdorff_measure_eq_top $ top_unique $ hd ▸ measure_mono h) end lemma dimH_subsingleton {s : set X} (h : s.subsingleton) : dimH s = 0 := begin borelize X, apply le_antisymm _ (zero_le _), refine dimH_le_of_hausdorff_measure_ne_top _, exact ((hausdorff_measure_le_one_of_subsingleton h le_rfl).trans_lt ennreal.one_lt_top).ne, end alias dimH_subsingleton ← set.subsingleton.dimH_zero @[simp] lemma dimH_empty : dimH (∅ : set X) = 0 := subsingleton_empty.dimH_zero @[simp] lemma dimH_singleton (x : X) : dimH ({x} : set X) = 0 := subsingleton_singleton.dimH_zero @[simp] lemma dimH_Union [encodable ι] (s : ι → set X) : dimH (⋃ i, s i) = ⨆ i, dimH (s i) := begin borelize X, refine le_antisymm (dimH_le $ λ d hd, _) (supr_le $ λ i, dimH_mono $ subset_Union _ _), contrapose! hd, have : ∀ i, μH[d] (s i) = 0, from λ i, hausdorff_measure_of_dimH_lt ((le_supr (λ i, dimH (s i)) i).trans_lt hd), rw measure_Union_null this, exact ennreal.zero_ne_top end @[simp] lemma dimH_bUnion {s : set ι} (hs : countable s) (t : ι → set X) : dimH (⋃ i ∈ s, t i) = ⨆ i ∈ s, dimH (t i) := begin haveI := hs.to_encodable, rw [bUnion_eq_Union, dimH_Union, ← supr_subtype''] end @[simp] lemma dimH_sUnion {S : set (set X)} (hS : countable S) : dimH (⋃₀ S) = ⨆ s ∈ S, dimH s := by rw [sUnion_eq_bUnion, dimH_bUnion hS] @[simp] lemma dimH_union (s t : set X) : dimH (s ∪ t) = max (dimH s) (dimH t) := by rw [union_eq_Union, dimH_Union, supr_bool_eq, cond, cond, ennreal.sup_eq_max] lemma dimH_countable {s : set X} (hs : countable s) : dimH s = 0 := bUnion_of_singleton s ▸ by simp only [dimH_bUnion hs, dimH_singleton, ennreal.supr_zero_eq_zero] alias dimH_countable ← set.countable.dimH_zero lemma dimH_finite {s : set X} (hs : finite s) : dimH s = 0 := hs.countable.dimH_zero alias dimH_finite ← set.finite.dimH_zero @[simp] lemma dimH_coe_finset (s : finset X) : dimH (s : set X) = 0 := s.finite_to_set.dimH_zero alias dimH_coe_finset ← finset.dimH_zero /-! ### Hausdorff dimension as the supremum of local Hausdorff dimensions -/ section variables [second_countable_topology X] /-- If `r` is less than the Hausdorff dimension of a set `s` in an (extended) metric space with second countable topology, then there exists a point `x ∈ s` such that every neighborhood `t` of `x` within `s` has Hausdorff dimension greater than `r`. -/ lemma exists_mem_nhds_within_lt_dimH_of_lt_dimH {s : set X} {r : ℝ≥0∞} (h : r < dimH s) : ∃ x ∈ s, ∀ t ∈ 𝓝[s] x, r < dimH t := begin contrapose! h, choose! t htx htr using h, rcases countable_cover_nhds_within htx with ⟨S, hSs, hSc, hSU⟩, calc dimH s ≤ dimH (⋃ x ∈ S, t x) : dimH_mono hSU ... = ⨆ x ∈ S, dimH (t x) : dimH_bUnion hSc _ ... ≤ r : supr₂_le (λ x hx, htr x $ hSs hx) end /-- In an (extended) metric space with second countable topology, the Hausdorff dimension of a set `s` is the supremum over `x ∈ s` of the limit superiors of `dimH t` along `(𝓝[s] x).small_sets`. -/ lemma bsupr_limsup_dimH (s : set X) : (⨆ x ∈ s, limsup (𝓝[s] x).small_sets dimH) = dimH s := begin refine le_antisymm (supr₂_le $ λ x hx, _) _, { refine Limsup_le_of_le (by apply_auto_param) (eventually_map.2 _), exact eventually_small_sets.2 ⟨s, self_mem_nhds_within, λ t, dimH_mono⟩ }, { refine le_of_forall_ge_of_dense (λ r hr, _), rcases exists_mem_nhds_within_lt_dimH_of_lt_dimH hr with ⟨x, hxs, hxr⟩, refine le_supr₂_of_le x hxs _, rw limsup_eq, refine le_Inf (λ b hb, _), rcases eventually_small_sets.1 hb with ⟨t, htx, ht⟩, exact (hxr t htx).le.trans (ht t subset.rfl) } end /-- In an (extended) metric space with second countable topology, the Hausdorff dimension of a set `s` is the supremum over all `x` of the limit superiors of `dimH t` along `(𝓝[s] x).small_sets`. -/ lemma supr_limsup_dimH (s : set X) : (⨆ x, limsup (𝓝[s] x).small_sets dimH) = dimH s := begin refine le_antisymm (supr_le $ λ x, _) _, { refine Limsup_le_of_le (by apply_auto_param) (eventually_map.2 _), exact eventually_small_sets.2 ⟨s, self_mem_nhds_within, λ t, dimH_mono⟩ }, { rw ← bsupr_limsup_dimH, exact supr₂_le_supr _ _ } end end /-! ### Hausdorff dimension and Hölder continuity -/ variables {C K r : ℝ≥0} {f : X → Y} {s t : set X} /-- If `f` is a Hölder continuous map with exponent `r > 0`, then `dimH (f '' s) ≤ dimH s / r`. -/ lemma holder_on_with.dimH_image_le (h : holder_on_with C r f s) (hr : 0 < r) : dimH (f '' s) ≤ dimH s / r := begin borelize [X, Y], refine dimH_le (λ d hd, _), have := h.hausdorff_measure_image_le hr d.coe_nonneg, rw [hd, ennreal.coe_rpow_of_nonneg _ d.coe_nonneg, top_le_iff] at this, have Hrd : μH[(r * d : ℝ≥0)] s = ⊤, { contrapose this, exact ennreal.mul_ne_top ennreal.coe_ne_top this }, rw [ennreal.le_div_iff_mul_le, mul_comm, ← ennreal.coe_mul], exacts [le_dimH_of_hausdorff_measure_eq_top Hrd, or.inl (mt ennreal.coe_eq_zero.1 hr.ne'), or.inl ennreal.coe_ne_top] end namespace holder_with /-- If `f : X → Y` is Hölder continuous with a positive exponent `r`, then the Hausdorff dimension of the image of a set `s` is at most `dimH s / r`. -/ lemma dimH_image_le (h : holder_with C r f) (hr : 0 < r) (s : set X) : dimH (f '' s) ≤ dimH s / r := (h.holder_on_with s).dimH_image_le hr /-- If `f` is a Hölder continuous map with exponent `r > 0`, then the Hausdorff dimension of its range is at most the Hausdorff dimension of its domain divided by `r`. -/ lemma dimH_range_le (h : holder_with C r f) (hr : 0 < r) : dimH (range f) ≤ dimH (univ : set X) / r := @image_univ _ _ f ▸ h.dimH_image_le hr univ end holder_with /-- If `s` is a set in a space `X` with second countable topology and `f : X → Y` is Hölder continuous in a neighborhood within `s` of every point `x ∈ s` with the same positive exponent `r` but possibly different coefficients, then the Hausdorff dimension of the image `f '' s` is at most the Hausdorff dimension of `s` divided by `r`. -/ lemma dimH_image_le_of_locally_holder_on [second_countable_topology X] {r : ℝ≥0} {f : X → Y} (hr : 0 < r) {s : set X} (hf : ∀ x ∈ s, ∃ (C : ℝ≥0) (t ∈ 𝓝[s] x), holder_on_with C r f t) : dimH (f '' s) ≤ dimH s / r := begin choose! C t htn hC using hf, rcases countable_cover_nhds_within htn with ⟨u, hus, huc, huU⟩, replace huU := inter_eq_self_of_subset_left huU, rw inter_Union₂ at huU, rw [← huU, image_Union₂, dimH_bUnion huc, dimH_bUnion huc], simp only [ennreal.supr_div], exact supr₂_mono (λ x hx, ((hC x (hus hx)).mono (inter_subset_right _ _)).dimH_image_le hr) end /-- If `f : X → Y` is Hölder continuous in a neighborhood of every point `x : X` with the same positive exponent `r` but possibly different coefficients, then the Hausdorff dimension of the range of `f` is at most the Hausdorff dimension of `X` divided by `r`. -/ lemma dimH_range_le_of_locally_holder_on [second_countable_topology X] {r : ℝ≥0} {f : X → Y} (hr : 0 < r) (hf : ∀ x : X, ∃ (C : ℝ≥0) (s ∈ 𝓝 x), holder_on_with C r f s) : dimH (range f) ≤ dimH (univ : set X) / r := begin rw ← image_univ, refine dimH_image_le_of_locally_holder_on hr (λ x _, _), simpa only [exists_prop, nhds_within_univ] using hf x end /-! ### Hausdorff dimension and Lipschitz continuity -/ /-- If `f : X → Y` is Lipschitz continuous on `s`, then `dimH (f '' s) ≤ dimH s`. -/ lemma lipschitz_on_with.dimH_image_le (h : lipschitz_on_with K f s) : dimH (f '' s) ≤ dimH s := by simpa using h.holder_on_with.dimH_image_le zero_lt_one namespace lipschitz_with /-- If `f` is a Lipschitz continuous map, then `dimH (f '' s) ≤ dimH s`. -/ lemma dimH_image_le (h : lipschitz_with K f) (s : set X) : dimH (f '' s) ≤ dimH s := (h.lipschitz_on_with s).dimH_image_le /-- If `f` is a Lipschitz continuous map, then the Hausdorff dimension of its range is at most the Hausdorff dimension of its domain. -/ lemma dimH_range_le (h : lipschitz_with K f) : dimH (range f) ≤ dimH (univ : set X) := @image_univ _ _ f ▸ h.dimH_image_le univ end lipschitz_with /-- If `s` is a set in an extended metric space `X` with second countable topology and `f : X → Y` is Lipschitz in a neighborhood within `s` of every point `x ∈ s`, then the Hausdorff dimension of the image `f '' s` is at most the Hausdorff dimension of `s`. -/ lemma dimH_image_le_of_locally_lipschitz_on [second_countable_topology X] {f : X → Y} {s : set X} (hf : ∀ x ∈ s, ∃ (C : ℝ≥0) (t ∈ 𝓝[s] x), lipschitz_on_with C f t) : dimH (f '' s) ≤ dimH s := begin have : ∀ x ∈ s, ∃ (C : ℝ≥0) (t ∈ 𝓝[s] x), holder_on_with C 1 f t, by simpa only [holder_on_with_one] using hf, simpa only [ennreal.coe_one, ennreal.div_one] using dimH_image_le_of_locally_holder_on zero_lt_one this end /-- If `f : X → Y` is Lipschitz in a neighborhood of each point `x : X`, then the Hausdorff dimension of `range f` is at most the Hausdorff dimension of `X`. -/ lemma dimH_range_le_of_locally_lipschitz_on [second_countable_topology X] {f : X → Y} (hf : ∀ x : X, ∃ (C : ℝ≥0) (s ∈ 𝓝 x), lipschitz_on_with C f s) : dimH (range f) ≤ dimH (univ : set X) := begin rw ← image_univ, refine dimH_image_le_of_locally_lipschitz_on (λ x _, _), simpa only [exists_prop, nhds_within_univ] using hf x end namespace antilipschitz_with lemma dimH_preimage_le (hf : antilipschitz_with K f) (s : set Y) : dimH (f ⁻¹' s) ≤ dimH s := begin borelize [X, Y], refine dimH_le (λ d hd, le_dimH_of_hausdorff_measure_eq_top _), have := hf.hausdorff_measure_preimage_le d.coe_nonneg s, rw [hd, top_le_iff] at this, contrapose! this, exact ennreal.mul_ne_top (by simp) this end lemma le_dimH_image (hf : antilipschitz_with K f) (s : set X) : dimH s ≤ dimH (f '' s) := calc dimH s ≤ dimH (f ⁻¹' (f '' s)) : dimH_mono (subset_preimage_image _ _) ... ≤ dimH (f '' s) : hf.dimH_preimage_le _ end antilipschitz_with /-! ### Isometries preserve Hausdorff dimension -/ lemma isometry.dimH_image (hf : isometry f) (s : set X) : dimH (f '' s) = dimH s := le_antisymm (hf.lipschitz.dimH_image_le _) (hf.antilipschitz.le_dimH_image _) namespace isometric @[simp] lemma dimH_image (e : X ≃ᵢ Y) (s : set X) : dimH (e '' s) = dimH s := e.isometry.dimH_image s @[simp] lemma dimH_preimage (e : X ≃ᵢ Y) (s : set Y) : dimH (e ⁻¹' s) = dimH s := by rw [← e.image_symm, e.symm.dimH_image] lemma dimH_univ (e : X ≃ᵢ Y) : dimH (univ : set X) = dimH (univ : set Y) := by rw [← e.dimH_preimage univ, preimage_univ] end isometric namespace continuous_linear_equiv variables {𝕜 E F : Type*} [nondiscrete_normed_field 𝕜] [normed_group E] [normed_space 𝕜 E] [normed_group F] [normed_space 𝕜 F] @[simp] lemma dimH_image (e : E ≃L[𝕜] F) (s : set E) : dimH (e '' s) = dimH s := le_antisymm (e.lipschitz.dimH_image_le s) $ by simpa only [e.symm_image_image] using e.symm.lipschitz.dimH_image_le (e '' s) @[simp] lemma dimH_preimage (e : E ≃L[𝕜] F) (s : set F) : dimH (e ⁻¹' s) = dimH s := by rw [← e.image_symm_eq_preimage, e.symm.dimH_image] lemma dimH_univ (e : E ≃L[𝕜] F) : dimH (univ : set E) = dimH (univ : set F) := by rw [← e.dimH_preimage, preimage_univ] end continuous_linear_equiv /-! ### Hausdorff dimension in a real vector space -/ namespace real variables {E : Type*} [fintype ι] [normed_group E] [normed_space ℝ E] [finite_dimensional ℝ E] theorem dimH_ball_pi (x : ι → ℝ) {r : ℝ} (hr : 0 < r) : dimH (metric.ball x r) = fintype.card ι := begin casesI is_empty_or_nonempty ι, { rwa [dimH_subsingleton, eq_comm, nat.cast_eq_zero, fintype.card_eq_zero_iff], exact λ x _ y _, subsingleton.elim x y }, { rw ← ennreal.coe_nat, have : μH[fintype.card ι] (metric.ball x r) = ennreal.of_real ((2 * r) ^ fintype.card ι), by rw [hausdorff_measure_pi_real, real.volume_pi_ball _ hr], refine dimH_of_hausdorff_measure_ne_zero_ne_top _ _; rw [nnreal.coe_nat_cast, this], { simp [pow_pos (mul_pos zero_lt_two hr)] }, { exact ennreal.of_real_ne_top } } end theorem dimH_ball_pi_fin {n : ℕ} (x : fin n → ℝ) {r : ℝ} (hr : 0 < r) : dimH (metric.ball x r) = n := by rw [dimH_ball_pi x hr, fintype.card_fin] theorem dimH_univ_pi (ι : Type*) [fintype ι] : dimH (univ : set (ι → ℝ)) = fintype.card ι := by simp only [← metric.Union_ball_nat_succ (0 : ι → ℝ), dimH_Union, dimH_ball_pi _ (nat.cast_add_one_pos _), supr_const] theorem dimH_univ_pi_fin (n : ℕ) : dimH (univ : set (fin n → ℝ)) = n := by rw [dimH_univ_pi, fintype.card_fin] theorem dimH_of_mem_nhds {x : E} {s : set E} (h : s ∈ 𝓝 x) : dimH s = finrank ℝ E := begin have e : E ≃L[ℝ] (fin (finrank ℝ E) → ℝ), from continuous_linear_equiv.of_finrank_eq (finite_dimensional.finrank_fin_fun ℝ).symm, rw ← e.dimH_image, refine le_antisymm _ _, { exact (dimH_mono (subset_univ _)).trans_eq (dimH_univ_pi_fin _) }, { have : e '' s ∈ 𝓝 (e x), by { rw ← e.map_nhds_eq, exact image_mem_map h }, rcases metric.nhds_basis_ball.mem_iff.1 this with ⟨r, hr0, hr⟩, simpa only [dimH_ball_pi_fin (e x) hr0] using dimH_mono hr } end theorem dimH_of_nonempty_interior {s : set E} (h : (interior s).nonempty) : dimH s = finrank ℝ E := let ⟨x, hx⟩ := h in dimH_of_mem_nhds (mem_interior_iff_mem_nhds.1 hx) variable (E) theorem dimH_univ_eq_finrank : dimH (univ : set E) = finrank ℝ E := dimH_of_mem_nhds (@univ_mem _ (𝓝 0)) theorem dimH_univ : dimH (univ : set ℝ) = 1 := by rw [dimH_univ_eq_finrank ℝ, finite_dimensional.finrank_self, nat.cast_one] end real variables {E F : Type*} [normed_group E] [normed_space ℝ E] [finite_dimensional ℝ E] [normed_group F] [normed_space ℝ F] theorem dense_compl_of_dimH_lt_finrank {s : set E} (hs : dimH s < finrank ℝ E) : dense sᶜ := begin refine λ x, mem_closure_iff_nhds.2 (λ t ht, ne_empty_iff_nonempty.1 $ λ he, hs.not_le _), rw [← diff_eq, diff_eq_empty] at he, rw [← real.dimH_of_mem_nhds ht], exact dimH_mono he end /-! ### Hausdorff dimension and `C¹`-smooth maps `C¹`-smooth maps are locally Lipschitz continuous, hence they do not increase the Hausdorff dimension of sets. -/ /-- Let `f` be a function defined on a finite dimensional real normed space. If `f` is `C¹`-smooth on a convex set `s`, then the Hausdorff dimension of `f '' s` is less than or equal to the Hausdorff dimension of `s`. TODO: do we actually need `convex ℝ s`? -/ lemma cont_diff_on.dimH_image_le {f : E → F} {s t : set E} (hf : cont_diff_on ℝ 1 f s) (hc : convex ℝ s) (ht : t ⊆ s) : dimH (f '' t) ≤ dimH t := dimH_image_le_of_locally_lipschitz_on $ λ x hx, let ⟨C, u, hu, hf⟩ := (hf x (ht hx)).exists_lipschitz_on_with hc in ⟨C, u, nhds_within_mono _ ht hu, hf⟩ /-- The Hausdorff dimension of the range of a `C¹`-smooth function defined on a finite dimensional real normed space is at most the dimension of its domain as a vector space over `ℝ`. -/ lemma cont_diff.dimH_range_le {f : E → F} (h : cont_diff ℝ 1 f) : dimH (range f) ≤ finrank ℝ E := calc dimH (range f) = dimH (f '' univ) : by rw image_univ ... ≤ dimH (univ : set E) : h.cont_diff_on.dimH_image_le convex_univ subset.rfl ... = finrank ℝ E : real.dimH_univ_eq_finrank E /-- A particular case of Sard's Theorem. Let `f : E → F` be a map between finite dimensional real vector spaces. Suppose that `f` is `C¹` smooth on a convex set `s` of Hausdorff dimension strictly less than the dimension of `F`. Then the complement of the image `f '' s` is dense in `F`. -/ lemma cont_diff_on.dense_compl_image_of_dimH_lt_finrank [finite_dimensional ℝ F] {f : E → F} {s t : set E} (h : cont_diff_on ℝ 1 f s) (hc : convex ℝ s) (ht : t ⊆ s) (htF : dimH t < finrank ℝ F) : dense (f '' t)ᶜ := dense_compl_of_dimH_lt_finrank $ (h.dimH_image_le hc ht).trans_lt htF /-- A particular case of Sard's Theorem. If `f` is a `C¹` smooth map from a real vector space to a real vector space `F` of strictly larger dimension, then the complement of the range of `f` is dense in `F`. -/ lemma cont_diff.dense_compl_range_of_finrank_lt_finrank [finite_dimensional ℝ F] {f : E → F} (h : cont_diff ℝ 1 f) (hEF : finrank ℝ E < finrank ℝ F) : dense (range f)ᶜ := dense_compl_of_dimH_lt_finrank $ h.dimH_range_le.trans_lt $ ennreal.coe_nat_lt_coe_nat.2 hEF
a1fb727d5ef9ab08cf16279a7fbd4f7494d1996e
ac49064e8a9a038e07cf5574b4fccd8a70d115c8
/hott/types/fiber.hlean
e369549e4517176e6973b5b0fda5784e7fedafb1
[ "Apache-2.0" ]
permissive
Bolt64/lean2
7c75016729569e04a3f403c7a4fc7c1de4377c9d
75fd8162488214a959dbe3303a185cbbb83f60f9
refs/heads/master
1,611,290,445,156
1,493,763,922,000
1,493,763,922,000
81,566,307
0
0
null
1,486,732,167,000
1,486,732,167,000
null
UTF-8
Lean
false
false
10,823
hlean
/- Copyright (c) 2015 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Mike Shulman Ported from Coq HoTT Theorems about fibers -/ import .sigma .eq .pi cubical.squareover .pointed .eq open equiv sigma sigma.ops eq pi pointed structure fiber {A B : Type} (f : A → B) (b : B) := (point : A) (point_eq : f point = b) namespace fiber variables {A B : Type} {f : A → B} {b : B} protected definition sigma_char [constructor] (f : A → B) (b : B) : fiber f b ≃ (Σ(a : A), f a = b) := begin fapply equiv.MK, {intro x, exact ⟨point x, point_eq x⟩}, {intro x, exact (fiber.mk x.1 x.2)}, {intro x, exact abstract begin cases x, apply idp end end}, {intro x, exact abstract begin cases x, apply idp end end}, end definition fiber_eq_equiv [constructor] (x y : fiber f b) : (x = y) ≃ (Σ(p : point x = point y), point_eq x = ap f p ⬝ point_eq y) := begin apply equiv.trans, apply eq_equiv_fn_eq_of_equiv, apply fiber.sigma_char, apply equiv.trans, apply sigma_eq_equiv, apply sigma_equiv_sigma_right, intro p, apply eq_pathover_equiv_Fl, end definition fiber_eq {x y : fiber f b} (p : point x = point y) (q : point_eq x = ap f p ⬝ point_eq y) : x = y := to_inv !fiber_eq_equiv ⟨p, q⟩ definition fiber_pathover {X : Type} {A B : X → Type} {x₁ x₂ : X} {p : x₁ = x₂} {f : Πx, A x → B x} {b : Πx, B x} {v₁ : fiber (f x₁) (b x₁)} {v₂ : fiber (f x₂) (b x₂)} (q : point v₁ =[p] point v₂) (r : squareover B hrfl (pathover_idp_of_eq (point_eq v₁)) (pathover_idp_of_eq (point_eq v₂)) (apo f q) (apd b p)) : v₁ =[p] v₂ := begin apply pathover_of_fn_pathover_fn (λa, !fiber.sigma_char), esimp, fapply sigma_pathover: esimp, { exact q}, { induction v₁ with a₁ p₁, induction v₂ with a₂ p₂, esimp at *, induction q, esimp at *, apply pathover_idp_of_eq, apply eq_of_vdeg_square, apply square_of_squareover_ids r} end open is_trunc definition fiber_pr1 (B : A → Type) (a : A) : fiber (pr1 : (Σa, B a) → A) a ≃ B a := calc fiber pr1 a ≃ Σu, u.1 = a : fiber.sigma_char ... ≃ Σa' (b : B a'), a' = a : sigma_assoc_equiv ... ≃ Σa' (p : a' = a), B a' : sigma_equiv_sigma_right (λa', !comm_equiv_nondep) ... ≃ Σu, B u.1 : sigma_assoc_equiv ... ≃ B a : !sigma_equiv_of_is_contr_left definition sigma_fiber_equiv (f : A → B) : (Σb, fiber f b) ≃ A := calc (Σb, fiber f b) ≃ Σb a, f a = b : sigma_equiv_sigma_right (λb, !fiber.sigma_char) ... ≃ Σa b, f a = b : sigma_comm_equiv ... ≃ A : sigma_equiv_of_is_contr_right definition is_pointed_fiber [instance] [constructor] (f : A → B) (a : A) : pointed (fiber f (f a)) := pointed.mk (fiber.mk a idp) definition pointed_fiber [constructor] (f : A → B) (a : A) : Type* := pointed.Mk (fiber.mk a (idpath (f a))) definition is_trunc_fun [reducible] (n : ℕ₋₂) (f : A → B) := Π(b : B), is_trunc n (fiber f b) definition is_contr_fun [reducible] (f : A → B) := is_trunc_fun -2 f -- pre and post composition with equivalences open function variable (f) protected definition equiv_postcompose [constructor] {B' : Type} (g : B ≃ B') --[H : is_equiv g] (b : B) : fiber (g ∘ f) (g b) ≃ fiber f b := calc fiber (g ∘ f) (g b) ≃ Σa : A, g (f a) = g b : fiber.sigma_char ... ≃ Σa : A, f a = b : begin apply sigma_equiv_sigma_right, intro a, apply equiv.symm, apply eq_equiv_fn_eq end ... ≃ fiber f b : fiber.sigma_char protected definition equiv_precompose [constructor] {A' : Type} (g : A' ≃ A) --[H : is_equiv g] (b : B) : fiber (f ∘ g) b ≃ fiber f b := calc fiber (f ∘ g) b ≃ Σa' : A', f (g a') = b : fiber.sigma_char ... ≃ Σa : A, f a = b : begin apply sigma_equiv_sigma g, intro a', apply erfl end ... ≃ fiber f b : fiber.sigma_char end fiber open unit is_trunc pointed namespace fiber definition fiber_star_equiv [constructor] (A : Type) : fiber (λx : A, star) star ≃ A := begin fapply equiv.MK, { intro f, cases f with a H, exact a }, { intro a, apply fiber.mk a, reflexivity }, { intro a, reflexivity }, { intro f, cases f with a H, change fiber.mk a (refl star) = fiber.mk a H, rewrite [is_set.elim H (refl star)] } end definition fiber_const_equiv [constructor] (A : Type) (a₀ : A) (a : A) : fiber (λz : unit, a₀) a ≃ a₀ = a := calc fiber (λz : unit, a₀) a ≃ Σz : unit, a₀ = a : fiber.sigma_char ... ≃ a₀ = a : sigma_unit_left -- the pointed fiber of a pointed map, which is the fiber over the basepoint open pointed definition pfiber [constructor] {X Y : Type*} (f : X →* Y) : Type* := pointed.MK (fiber f pt) (fiber.mk pt !respect_pt) definition ppoint [constructor] {X Y : Type*} (f : X →* Y) : pfiber f →* X := pmap.mk point idp definition pfiber.sigma_char [constructor] {A B : Type*} (f : A →* B) : pfiber f ≃* pointed.MK (Σa, f a = pt) ⟨pt, respect_pt f⟩ := pequiv_of_equiv (fiber.sigma_char f pt) idp definition ppoint_sigma_char [constructor] {A B : Type*} (f : A →* B) : ppoint f ~* pmap.mk pr1 idp ∘* pfiber.sigma_char f := !phomotopy.refl definition pfiber_loop_space {A B : Type*} (f : A →* B) : pfiber (Ω→ f) ≃* Ω (pfiber f) := pequiv_of_equiv (calc pfiber (Ω→ f) ≃ Σ(p : Point A = Point A), ap1 f p = rfl : (fiber.sigma_char (ap1 f) (Point (Ω B))) ... ≃ Σ(p : Point A = Point A), (respect_pt f) = ap f p ⬝ (respect_pt f) : (sigma_equiv_sigma_right (λp, calc (ap1 f p = rfl) ≃ !respect_pt⁻¹ ⬝ (ap f p ⬝ !respect_pt) = rfl : equiv_eq_closed_left _ (con.assoc _ _ _) ... ≃ ap f p ⬝ (respect_pt f) = (respect_pt f) : eq_equiv_inv_con_eq_idp ... ≃ (respect_pt f) = ap f p ⬝ (respect_pt f) : eq_equiv_eq_symm)) ... ≃ fiber.mk (Point A) (respect_pt f) = fiber.mk pt (respect_pt f) : fiber_eq_equiv ... ≃ Ω (pfiber f) : erfl) (begin cases f with f p, cases A with A a, cases B with B b, esimp at p, esimp at f, induction p, reflexivity end) definition pfiber_equiv_of_phomotopy {A B : Type*} {f g : A →* B} (h : f ~* g) : pfiber f ≃* pfiber g := begin fapply pequiv_of_equiv, { refine (fiber.sigma_char f pt ⬝e _ ⬝e (fiber.sigma_char g pt)⁻¹ᵉ), apply sigma_equiv_sigma_right, intros a, apply equiv_eq_closed_left, apply (to_homotopy h) }, { refine (fiber_eq rfl _), change (h pt)⁻¹ ⬝ respect_pt f = idp ⬝ respect_pt g, rewrite idp_con, apply inv_con_eq_of_eq_con, symmetry, exact (to_homotopy_pt h) } end definition transport_fiber_equiv [constructor] {A B : Type} (f : A → B) {b1 b2 : B} (p : b1 = b2) : fiber f b1 ≃ fiber f b2 := calc fiber f b1 ≃ Σa, f a = b1 : fiber.sigma_char ... ≃ Σa, f a = b2 : sigma_equiv_sigma_right (λa, equiv_eq_closed_right (f a) p) ... ≃ fiber f b2 : fiber.sigma_char definition pequiv_postcompose {A B B' : Type*} (f : A →* B) (g : B ≃* B') : pfiber (g ∘* f) ≃* pfiber f := begin fapply pequiv_of_equiv, esimp, refine transport_fiber_equiv (g ∘* f) (respect_pt g)⁻¹ ⬝e fiber.equiv_postcompose f g (Point B), esimp, apply (ap (fiber.mk (Point A))), refine !con.assoc ⬝ _, apply inv_con_eq_of_eq_con, rewrite [con.assoc, con.right_inv, con_idp, -ap_compose'], apply ap_con_eq_con end definition pequiv_precompose {A A' B : Type*} (f : A →* B) (g : A' ≃* A) : pfiber (f ∘* g) ≃* pfiber f := begin fapply pequiv_of_equiv, esimp, refine fiber.equiv_precompose f g (Point B), esimp, apply (eq_of_fn_eq_fn (fiber.sigma_char _ _)), fapply sigma_eq: esimp, { apply respect_pt g }, { apply eq_pathover_Fl' } end definition pfiber_equiv_of_square {A B C D : Type*} {f : A →* B} {g : C →* D} (h : A ≃* C) (k : B ≃* D) (s : k ∘* f ~* g ∘* h) : pfiber f ≃* pfiber g := calc pfiber f ≃* pfiber (k ∘* f) : pequiv_postcompose ... ≃* pfiber (g ∘* h) : pfiber_equiv_of_phomotopy s ... ≃* pfiber g : pequiv_precompose end fiber open function is_equiv namespace fiber /- Theorem 4.7.6 -/ variables {A : Type} {P Q : A → Type} variable (f : Πa, P a → Q a) definition fiber_total_equiv [constructor] {a : A} (q : Q a) : fiber (total f) ⟨a , q⟩ ≃ fiber (f a) q := calc fiber (total f) ⟨a , q⟩ ≃ Σ(w : Σx, P x), ⟨w.1 , f w.1 w.2 ⟩ = ⟨a , q⟩ : fiber.sigma_char ... ≃ Σ(x : A), Σ(p : P x), ⟨x , f x p⟩ = ⟨a , q⟩ : sigma_assoc_equiv ... ≃ Σ(x : A), Σ(p : P x), Σ(H : x = a), f x p =[H] q : begin apply sigma_equiv_sigma_right, intro x, apply sigma_equiv_sigma_right, intro p, apply sigma_eq_equiv end ... ≃ Σ(x : A), Σ(H : x = a), Σ(p : P x), f x p =[H] q : begin apply sigma_equiv_sigma_right, intro x, apply sigma_comm_equiv end ... ≃ Σ(w : Σx, x = a), Σ(p : P w.1), f w.1 p =[w.2] q : sigma_assoc_equiv ... ≃ Σ(p : P (center (Σx, x=a)).1), f (center (Σx, x=a)).1 p =[(center (Σx, x=a)).2] q : sigma_equiv_of_is_contr_left ... ≃ Σ(p : P a), f a p =[idpath a] q : equiv_of_eq idp ... ≃ Σ(p : P a), f a p = q : begin apply sigma_equiv_sigma_right, intro p, apply pathover_idp end ... ≃ fiber (f a) q : fiber.sigma_char end fiber
8ce42f48b97e9cee6ae7477f15ceb6a53a67b5ca
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/tactic/split_ifs.lean
e96604ceea6a0d030a74e06c136e970c0c31b924
[ "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,106
lean
/- Copyright (c) 2018 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner Tactic to split if-then-else-expressions. -/ import tactic.hint open expr tactic namespace tactic setup_tactic_parser meta def find_if_cond : expr → option expr | e := e.fold none $ λ e _ acc, acc <|> do c ← match e with | `(@ite _ %%c %%_ _ _) := some c | `(@dite _ %%c %%_ _ _) := some c | _ := none end, guard ¬c.has_var, find_if_cond c <|> return c meta def find_if_cond_at (at_ : loc) : tactic (option expr) := do lctx ← at_.get_locals, lctx ← lctx.mmap infer_type, tgt ← target, let es := if at_.include_goal then tgt::lctx else lctx, return $ find_if_cond $ es.foldr app default meta def reduce_ifs_at (at_ : loc) : tactic unit := do sls ← get_user_simp_lemmas `split_if_reduction, let cfg : simp_config := { fail_if_unchanged := ff }, let discharger := assumption <|> (applyc `not_not_intro >> assumption), hs ← at_.get_locals, hs.mmap' (λ h, simp_hyp sls [] h cfg discharger >> skip), when at_.include_goal (simp_target sls [] cfg discharger >> skip) meta def split_if1 (c : expr) (n : name) (at_ : loc) : tactic unit := by_cases c n; reduce_ifs_at at_ private meta def get_next_name (names : ref (list name)) : tactic name := do ns ← read_ref names, match ns with | [] := get_unused_name `h | n::ns := do write_ref names ns, return n end private meta def value_known (c : expr) : tactic bool := do lctx ← local_context, lctx ← lctx.mmap infer_type, return $ c ∈ lctx ∨ `(¬%%c) ∈ lctx private meta def split_ifs_core (at_ : loc) (names : ref (list name)) : list expr → tactic unit | done := do some cond ← find_if_cond_at at_ | fail "no if-then-else expressions to split", let cond := match cond with `(¬%%p) := p | p := p end, if cond ∈ done then skip else do no_split ← value_known cond, if no_split then reduce_ifs_at at_; try (split_ifs_core (cond :: done)) else do n ← get_next_name names, split_if1 cond n at_; try (split_ifs_core (cond :: done)) meta def split_ifs (names : list name) (at_ : loc := loc.ns [none]) := using_new_ref names $ λ names, split_ifs_core at_ names [] namespace interactive open interactive interactive.types expr lean.parser /-- Splits all if-then-else-expressions into multiple goals. Given a goal of the form `g (if p then x else y)`, `split_ifs` will produce two goals: `p ⊢ g x` and `¬p ⊢ g y`. If there are multiple ite-expressions, then `split_ifs` will split them all, starting with a top-most one whose condition does not contain another ite-expression. `split_ifs at *` splits all ite-expressions in all hypotheses as well as the goal. `split_ifs with h₁ h₂ h₃` overrides the default names for the hypotheses. -/ meta def split_ifs (at_ : parse location) (names : parse with_ident_list) : tactic unit := tactic.split_ifs names at_ add_hint_tactic "split_ifs" add_tactic_doc { name := "split_ifs", category := doc_category.tactic, decl_names := [``split_ifs], tags := ["case bashing"] } end interactive end tactic
cce4fdc77cf4054afc77c08b8bec8e65bc57c850
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
/src/algebraic_topology/simplex_category.lean
9282e4f230ac015396714f163781a038d7a0a707
[ "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
17,704
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Scott Morrison, Adam Topaz -/ import order.category.NonemptyFinLinOrd import category_theory.skeletal import data.finset.sort import tactic.linarith /-! # The simplex category We construct a skeletal model of the simplex category, with objects `ℕ` and the morphism `n ⟶ m` being the monotone maps from `fin (n+1)` to `fin (m+1)`. We show that this category is equivalent to `NonemptyFinLinOrd`. ## Remarks The definitions `simplex_category` and `simplex_category.hom` are marked as irreducible. We provide the following functions to work with these objects: 1. `simplex_category.mk` creates an object of `simplex_category` out of a natural number. Use the notation `[n]` in the `simplicial` locale. 2. `simplex_category.len` gives the "length" of an object of `simplex_category`, as a natural. 3. `simplex_category.hom.mk` makes a morphism out of a monotone map between `fin`'s. 4. `simplex_category.hom.to_preorder_hom` gives the underlying monotone map associated to a term of `simplex_category.hom`. -/ universe variables u v open category_theory /-- The simplex category: * objects are natural numbers `n : ℕ` * morphisms from `n` to `m` are monotone functions `fin (n+1) → fin (m+1)` -/ @[derive inhabited, irreducible] def simplex_category := ulift.{u} ℕ namespace simplex_category section local attribute [semireducible] simplex_category -- TODO: Make `mk` irreducible. /-- Interpet a natural number as an object of the simplex category. -/ def mk (n : ℕ) : simplex_category.{u} := ulift.up n localized "notation `[`n`]` := simplex_category.mk n" in simplicial -- TODO: Make `len` irreducible. /-- The length of an object of `simplex_category`. -/ def len (n : simplex_category.{u}) : ℕ := n.down @[ext] lemma ext (a b : simplex_category.{u}) : a.len = b.len → a = b := ulift.ext a b @[simp] lemma len_mk (n : ℕ) : [n].len = n := rfl @[simp] lemma mk_len (n : simplex_category.{u}) : [n.len] = n := by {cases n, refl} /-- Morphisms in the simplex_category. -/ @[irreducible, nolint has_inhabited_instance] protected def hom (a b : simplex_category.{u}) : Type u := ulift (fin (a.len + 1) →ₘ fin (b.len + 1)) namespace hom local attribute [semireducible] simplex_category.hom /-- Make a moprhism in `simplex_category` from a monotone map of fin's. -/ def mk {a b : simplex_category.{u}} (f : fin (a.len + 1) →ₘ fin (b.len + 1)) : simplex_category.hom a b := ulift.up f /-- Recover the monotone map from a morphism in the simplex category. -/ def to_preorder_hom {a b : simplex_category.{u}} (f : simplex_category.hom a b) : fin (a.len + 1) →ₘ fin (b.len + 1) := ulift.down f @[ext] lemma ext {a b : simplex_category.{u}} (f g : simplex_category.hom a b) : f.to_preorder_hom = g.to_preorder_hom → f = g := ulift.ext _ _ @[simp] lemma mk_to_preorder_hom {a b : simplex_category.{u}} (f : simplex_category.hom a b) : mk (f.to_preorder_hom) = f := by {cases f, refl} @[simp] lemma to_preorder_hom_mk {a b : simplex_category.{u}} (f : fin (a.len + 1) →ₘ fin (b.len + 1)) : (mk f).to_preorder_hom = f := by simp [to_preorder_hom, mk] lemma mk_to_preorder_hom_apply {a b : simplex_category.{u}} (f : fin (a.len + 1) →ₘ fin (b.len + 1)) (i : fin (a.len + 1)) : (mk f).to_preorder_hom i = f i := rfl /-- Identity morphisms of `simplex_category`. -/ @[simp] def id (a : simplex_category.{u}) : simplex_category.hom a a := mk preorder_hom.id /-- Composition of morphisms of `simplex_category`. -/ @[simp] def comp {a b c : simplex_category.{u}} (f : simplex_category.hom b c) (g : simplex_category.hom a b) : simplex_category.hom a c := mk $ f.to_preorder_hom.comp g.to_preorder_hom end hom @[simps] instance small_category : small_category.{u} simplex_category := { hom := λ n m, simplex_category.hom n m, id := λ m, simplex_category.hom.id _, comp := λ _ _ _ f g, simplex_category.hom.comp g f, } /-- The constant morphism from [0]. -/ def const (x : simplex_category.{u}) (i : fin (x.len+1)) : [0] ⟶ x := hom.mk $ ⟨λ _, i, by tauto⟩ @[simp] lemma const_comp (x y : simplex_category.{u}) (i : fin (x.len + 1)) (f : x ⟶ y) : const x i ≫ f = const y (f.to_preorder_hom i) := rfl /-- Make a morphism `[n] ⟶ [m]` from a monotone map between fin's. This is useful for constructing morphisms beetween `[n]` directly without identifying `n` with `[n].len`. -/ @[simp] def mk_hom {n m : ℕ} (f : (fin (n+1)) →ₘ (fin (m+1))) : [n] ⟶ [m] := simplex_category.hom.mk f lemma hom_zero_zero (f : [0] ⟶ [0]) : f = 𝟙 _ := by { ext : 2, dsimp, apply subsingleton.elim } end open_locale simplicial section generators /-! ## Generating maps for the simplex category TODO: prove that the simplex category is equivalent to one given by the following generators and relations. -/ /-- The `i`-th face map from `[n]` to `[n+1]` -/ def δ {n} (i : fin (n+2)) : [n] ⟶ [n+1] := mk_hom (fin.succ_above i).to_preorder_hom /-- The `i`-th degeneracy map from `[n+1]` to `[n]` -/ def σ {n} (i : fin (n+1)) : [n+1] ⟶ [n] := mk_hom { to_fun := fin.pred_above i, monotone' := fin.pred_above_right_monotone i } /-- The generic case of the first simplicial identity -/ lemma δ_comp_δ {n} {i j : fin (n+2)} (H : i ≤ j) : δ i ≫ δ j.succ = δ j ≫ δ i.cast_succ := begin ext k, dsimp [δ, fin.succ_above], simp only [order_embedding.to_preorder_hom_coe, order_embedding.coe_of_strict_mono, function.comp_app, simplex_category.hom.to_preorder_hom_mk, preorder_hom.comp_coe], rcases i with ⟨i, _⟩, rcases j with ⟨j, _⟩, rcases k with ⟨k, _⟩, split_ifs; { simp at *; linarith }, end /-- The special case of the first simplicial identity -/ lemma δ_comp_δ_self {n} {i : fin (n+2)} : δ i ≫ δ i.cast_succ = δ i ≫ δ i.succ := (δ_comp_δ (le_refl i)).symm /-- The second simplicial identity -/ lemma δ_comp_σ_of_le {n} {i : fin (n+2)} {j : fin (n+1)} (H : i ≤ j.cast_succ) : δ i.cast_succ ≫ σ j.succ = σ j ≫ δ i := begin ext k, suffices : ite (j.succ.cast_succ < ite (k < i) k.cast_succ k.succ) (ite (k < i) (k:ℕ) (k + 1) - 1) (ite (k < i) k (k + 1)) = ite ((if h : (j:ℕ) < k then k.pred (by { rintro rfl, exact nat.not_lt_zero _ h }) else k.cast_lt (by { cases j, cases k, simp only [len_mk], linarith })).cast_succ < i) (ite (j.cast_succ < k) (k - 1) k) (ite (j.cast_succ < k) (k - 1) k + 1), { dsimp [δ, σ, fin.succ_above, fin.pred_above], simpa [fin.pred_above] with push_cast }, rcases i with ⟨i, _⟩, rcases j with ⟨j, _⟩, rcases k with ⟨k, _⟩, simp only [subtype.mk_le_mk, fin.cast_succ_mk] at H, dsimp, simp only [if_congr, subtype.mk_lt_mk, dif_ctx_congr], split_ifs, -- Most of the goals can now be handled by `linarith`, -- but we have to deal with two of them by hand. swap 8, { exact (nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) ‹_›)).symm, }, swap 7, { have : k ≤ i := nat.le_of_pred_lt ‹_›, linarith, }, -- Hope for the best from `linarith`: all_goals { try { refl <|> simp at * }; linarith, }, end /-- The first part of the third simplicial identity -/ lemma δ_comp_σ_self {n} {i : fin (n+1)} : δ i.cast_succ ≫ σ i = 𝟙 [n] := begin ext j, suffices : ite (fin.cast_succ i < ite (j < i) (fin.cast_succ j) j.succ) (ite (j < i) (j:ℕ) (j + 1) - 1) (ite (j < i) j (j + 1)) = j, { dsimp [δ, σ, fin.succ_above, fin.pred_above], simpa [fin.pred_above] with push_cast }, rcases i with ⟨i, _⟩, rcases j with ⟨j, _⟩, dsimp, simp only [if_congr, subtype.mk_lt_mk], split_ifs; { simp at *; linarith, }, end /-- The second part of the third simplicial identity -/ lemma δ_comp_σ_succ {n} {i : fin (n+1)} : δ i.succ ≫ σ i = 𝟙 [n] := begin ext j, rcases i with ⟨i, _⟩, rcases j with ⟨j, _⟩, dsimp [δ, σ, fin.succ_above, fin.pred_above], simp [fin.pred_above] with push_cast, split_ifs; { simp at *; linarith, }, end /-- The fourth simplicial identity -/ lemma δ_comp_σ_of_gt {n} {i : fin (n+2)} {j : fin (n+1)} (H : j.cast_succ < i) : δ i.succ ≫ σ j.cast_succ = σ j ≫ δ i := begin ext k, dsimp [δ, σ, fin.succ_above, fin.pred_above], rcases i with ⟨i, _⟩, rcases j with ⟨j, _⟩, rcases k with ⟨k, _⟩, simp only [subtype.mk_lt_mk, fin.cast_succ_mk] at H, suffices : ite (_ < ite (k < i + 1) _ _) _ _ = ite _ (ite (j < k) (k - 1) k) (ite (j < k) (k - 1) k + 1), { simpa [apply_dite fin.cast_succ, fin.pred_above] with push_cast, }, split_ifs, -- Most of the goals can now be handled by `linarith`, -- but we have to deal with three of them by hand. swap 2, { simp only [subtype.mk_lt_mk] at h_1, simp only [not_lt] at h_2, simp only [self_eq_add_right, one_ne_zero], exact lt_irrefl (k - 1) (lt_of_lt_of_le (nat.pred_lt (ne_of_lt (lt_of_le_of_lt (zero_le _) h_1)).symm) (le_trans (nat.le_of_lt_succ h) h_2)) }, swap 4, { simp only [subtype.mk_lt_mk] at h_1, simp only [not_lt] at h, simp only [nat.add_succ_sub_one, add_zero], exfalso, exact lt_irrefl _ (lt_of_le_of_lt (nat.le_pred_of_lt (nat.lt_of_succ_le h)) h_3), }, swap 4, { simp only [subtype.mk_lt_mk] at h_1, simp only [not_lt] at h_3, simp only [nat.add_succ_sub_one, add_zero], exact (nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) h_2)).symm, }, -- Hope for the best from `linarith`: all_goals { simp at h_1 h_2 ⊢; linarith, }, end local attribute [simp] fin.pred_mk /-- The fifth simplicial identity -/ lemma σ_comp_σ {n} {i j : fin (n+1)} (H : i ≤ j) : σ i.cast_succ ≫ σ j = σ j.succ ≫ σ i := begin ext k, dsimp [σ, fin.pred_above], rcases i with ⟨i, _⟩, rcases j with ⟨j, _⟩, rcases k with ⟨k, _⟩, simp only [subtype.mk_le_mk] at H, -- At this point `simp with push_cast` makes good progress, but neither `simp?` nor `squeeze_simp` -- return usable sets of lemmas. -- To avoid using a non-terminal simp, we make a `suffices` statement indicating the shape -- of the goal we're looking for, and then use `simpa with push_cast`. -- I'm not sure this is actually much more robust that a non-terminal simp. suffices : ite (_ < dite (i < k) _ _) _ _ = ite (_ < dite (j + 1 < k) _ _) _ _, { simpa [fin.pred_above] with push_cast, }, split_ifs, -- `split_ifs` created 12 goals. -- Most of them are dealt with `by simp at *; linarith`, -- but we pull out two harder ones to do by hand. swap 3, { simp only [not_lt] at h_2, exact false.elim (lt_irrefl (k - 1) (lt_of_lt_of_le (nat.pred_lt (id (ne_of_lt (lt_of_le_of_lt (zero_le i) h)).symm)) (le_trans h_2 (nat.succ_le_of_lt h_1)))) }, swap 3, { simp only [subtype.mk_lt_mk, not_lt] at h_1, exact false.elim (lt_irrefl j (lt_of_lt_of_le (nat.pred_lt_pred (nat.succ_ne_zero j) h_2) h_1)) }, -- Deal with the rest automatically. all_goals { simp at *; linarith, }, end end generators section skeleton /-- The functor that exhibits `simplex_category` as skeleton of `NonemptyFinLinOrd` -/ @[simps obj map] def skeletal_functor : simplex_category.{u} ⥤ NonemptyFinLinOrd.{v} := { obj := λ a, NonemptyFinLinOrd.of $ ulift (fin (a.len + 1)), map := λ a b f, ⟨λ i, ulift.up (f.to_preorder_hom i.down), λ i j h, f.to_preorder_hom.monotone h⟩, map_id' := λ a, by { ext, simp, }, map_comp' := λ a b c f g, by { ext, simp, }, } lemma skeletal : skeletal simplex_category.{u} := λ X Y ⟨I⟩, begin suffices : fintype.card (fin (X.len+1)) = fintype.card (fin (Y.len+1)), { ext, simpa }, { apply fintype.card_congr, refine equiv.ulift.symm.trans (((skeletal_functor ⋙ forget _).map_iso I).to_equiv.trans _), apply equiv.ulift } end namespace skeletal_functor instance : full skeletal_functor.{u v} := { preimage := λ a b f, simplex_category.hom.mk ⟨λ i, (f (ulift.up i)).down, λ i j h, f.monotone h⟩, witness' := by { intros m n f, dsimp at *, ext1 ⟨i⟩, ext1, ext1, cases x, simp, } } instance : faithful skeletal_functor.{u v} := { map_injective' := λ m n f g h, begin ext1, ext1, ext1 i, apply ulift.up.inj, change (skeletal_functor.map f) ⟨i⟩ = (skeletal_functor.map g) ⟨i⟩, rw h, end } instance : ess_surj skeletal_functor.{u v} := { mem_ess_image := λ X, ⟨mk (fintype.card X - 1 : ℕ), ⟨begin have aux : fintype.card X = fintype.card X - 1 + 1, { exact (nat.succ_pred_eq_of_pos $ fintype.card_pos_iff.mpr ⟨⊥⟩).symm, }, let f := mono_equiv_of_fin X aux, have hf := (finset.univ.order_emb_of_fin aux).strict_mono, refine { hom := ⟨λ i, f i.down, _⟩, inv := ⟨λ i, ⟨f.symm i⟩, _⟩, hom_inv_id' := _, inv_hom_id' := _ }, { rintro ⟨i⟩ ⟨j⟩ h, show f i ≤ f j, exact hf.monotone h, }, { intros i j h, show f.symm i ≤ f.symm j, rw ← hf.le_iff_le, show f (f.symm i) ≤ f (f.symm j), simpa only [order_iso.apply_symm_apply], }, { ext1, ext1 ⟨i⟩, ext1, exact f.symm_apply_apply i }, { ext1, ext1 i, exact f.apply_symm_apply i }, end⟩⟩, } noncomputable instance is_equivalence : is_equivalence skeletal_functor.{u v} := equivalence.of_fully_faithfully_ess_surj skeletal_functor end skeletal_functor /-- The equivalence that exhibits `simplex_category` as skeleton of `NonemptyFinLinOrd` -/ noncomputable def skeletal_equivalence : simplex_category.{u} ≌ NonemptyFinLinOrd.{v} := functor.as_equivalence skeletal_functor end skeleton /-- `simplex_category` is a skeleton of `NonemptyFinLinOrd`. -/ noncomputable def is_skeleton_of : is_skeleton_of NonemptyFinLinOrd simplex_category skeletal_functor.{u v} := { skel := skeletal, eqv := skeletal_functor.is_equivalence } /-- The truncated simplex category. -/ @[derive small_category] def truncated (n : ℕ) := {a : simplex_category.{u} // a.len ≤ n} namespace truncated instance {n} : inhabited (truncated n) := ⟨⟨[0],by simp⟩⟩ /-- The fully faithful inclusion of the truncated simplex category into the usual simplex category. -/ @[derive [full, faithful]] def inclusion {n : ℕ} : simplex_category.truncated.{u} n ⥤ simplex_category.{u} := full_subcategory_inclusion _ end truncated section concrete instance : concrete_category.{0} simplex_category.{u} := { forget := { obj := λ i, fin (i.len + 1), map := λ i j f, f.to_preorder_hom }, forget_faithful := {} } end concrete section epi_mono /-- A morphism in `simplex_category` is a monomorphism precisely when it is an injective function -/ theorem mono_iff_injective {n m : simplex_category.{u}} {f : n ⟶ m} : mono f ↔ function.injective f.to_preorder_hom := begin split, { introsI m x y h, have H : const n x ≫ f = const n y ≫ f, { dsimp, rw h }, change (n.const x).to_preorder_hom 0 = (n.const y).to_preorder_hom 0, rw cancel_mono f at H, rw H }, { exact concrete_category.mono_of_injective f } end /-- A morphism in `simplex_category` is an epimorphism if and only if it is a surjective function -/ lemma epi_iff_surjective {n m : simplex_category.{u}} {f: n ⟶ m} : epi f ↔ function.surjective f.to_preorder_hom := begin split, { introsI hyp_f_epi x, by_contradiction h_ab, rw not_exists at h_ab, -- The proof is by contradiction: assume f is not surjective, -- then introduce two non-equal auxiliary functions equalizing f, and get a contradiction. -- First we define the two auxiliary functions. set chi_1 : m ⟶ [1] := hom.mk ⟨λ u, if u ≤ x then 0 else 1, begin intros a b h, dsimp only [], split_ifs with h1 h2 h3, any_goals { exact le_refl _ }, { exact bot_le }, { exact false.elim (h1 (le_trans h h3)) } end ⟩, set chi_2 : m ⟶ [1] := hom.mk ⟨λ u, if u < x then 0 else 1, begin intros a b h, dsimp only [], split_ifs with h1 h2 h3, any_goals { exact le_refl _ }, { exact bot_le }, { exact false.elim (h1 (lt_of_le_of_lt h h3)) } end ⟩, -- The two auxiliary functions equalize f have f_comp_chi_i : f ≫ chi_1 = f ≫ chi_2, { dsimp, ext, simp [le_iff_lt_or_eq, h_ab x_1] }, -- We now just have to show the two auxiliary functions are not equal. rw category_theory.cancel_epi f at f_comp_chi_i, rename f_comp_chi_i eq_chi_i, apply_fun (λ e, e.to_preorder_hom x) at eq_chi_i, suffices : (0 : fin 2) = 1, by exact bot_ne_top this, simpa using eq_chi_i }, { exact concrete_category.epi_of_surjective f } end /-- A monomorphism in `simplex_category` must increase lengths-/ lemma len_le_of_mono {x y : simplex_category.{u}} {f : x ⟶ y} : mono f → (x.len ≤ y.len) := begin intro hyp_f_mono, have f_inj : function.injective f.to_preorder_hom.to_fun, { exact mono_iff_injective.elim_left (hyp_f_mono) }, simpa using fintype.card_le_of_injective f.to_preorder_hom.to_fun f_inj, end lemma le_of_mono {n m : ℕ} {f : [n] ⟶ [m]} : (category_theory.mono f) → (n ≤ m) := len_le_of_mono /-- An epimorphism in `simplex_category` must decrease lengths-/ lemma len_le_of_epi {x y : simplex_category.{u}} {f : x ⟶ y} : epi f → y.len ≤ x.len := begin intro hyp_f_epi, have f_surj : function.surjective f.to_preorder_hom.to_fun, { exact epi_iff_surjective.elim_left (hyp_f_epi) }, simpa using fintype.card_le_of_surjective f.to_preorder_hom.to_fun f_surj, end lemma le_of_epi {n m : ℕ} {f : [n] ⟶ [m]} : epi f → (m ≤ n) := len_le_of_epi end epi_mono end simplex_category
13290c064009f51f747cb544e6e564b4f032c9d9
bb31430994044506fa42fd667e2d556327e18dfe
/src/measure_theory/integral/set_to_l1.lean
97479a4bb2cfb9c89f255a6c38388d1e82a392f7
[ "Apache-2.0" ]
permissive
sgouezel/mathlib
0cb4e5335a2ba189fa7af96d83a377f83270e503
00638177efd1b2534fc5269363ebf42a7871df9a
refs/heads/master
1,674,527,483,042
1,673,665,568,000
1,673,665,568,000
119,598,202
0
0
null
1,517,348,647,000
1,517,348,646,000
null
UTF-8
Lean
false
false
88,227
lean
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import measure_theory.function.simple_func_dense_lp /-! # Extension of a linear function from indicators to L1 Let `T : set α → E →L[ℝ] F` be additive for measurable sets with finite measure, in the sense that for `s, t` two such sets, `s ∩ t = ∅ → T (s ∪ t) = T s + T t`. `T` is akin to a bilinear map on `set α × E`, or a linear map on indicator functions. This file constructs an extension of `T` to integrable simple functions, which are finite sums of indicators of measurable sets with finite measure, then to integrable functions, which are limits of integrable simple functions. The main result is a continuous linear map `(α →₁[μ] E) →L[ℝ] F`. This extension process is used to define the Bochner integral in the `measure_theory.integral.bochner` file and the conditional expectation of an integrable function in `measure_theory.function.conditional_expectation`. ## Main Definitions - `fin_meas_additive μ T`: the property that `T` is additive on measurable sets with finite measure. For two such sets, `s ∩ t = ∅ → T (s ∪ t) = T s + T t`. - `dominated_fin_meas_additive μ T C`: `fin_meas_additive μ T ∧ ∀ s, ‖T s‖ ≤ C * (μ s).to_real`. This is the property needed to perform the extension from indicators to L1. - `set_to_L1 (hT : dominated_fin_meas_additive μ T C) : (α →₁[μ] E) →L[ℝ] F`: the extension of `T` from indicators to L1. - `set_to_fun μ T (hT : dominated_fin_meas_additive μ T C) (f : α → E) : F`: a version of the extension which applies to functions (with value 0 if the function is not integrable). ## Properties For most properties of `set_to_fun`, we provide two lemmas. One version uses hypotheses valid on all sets, like `T = T'`, and a second version which uses a primed name uses hypotheses on measurable sets with finite measure, like `∀ s, measurable_set s → μ s < ∞ → T s = T' s`. The lemmas listed here don't show all hypotheses. Refer to the actual lemmas for details. Linearity: - `set_to_fun_zero_left : set_to_fun μ 0 hT f = 0` - `set_to_fun_add_left : set_to_fun μ (T + T') _ f = set_to_fun μ T hT f + set_to_fun μ T' hT' f` - `set_to_fun_smul_left : set_to_fun μ (λ s, c • (T s)) (hT.smul c) f = c • set_to_fun μ T hT f` - `set_to_fun_zero : set_to_fun μ T hT (0 : α → E) = 0` - `set_to_fun_neg : set_to_fun μ T hT (-f) = - set_to_fun μ T hT f` If `f` and `g` are integrable: - `set_to_fun_add : set_to_fun μ T hT (f + g) = set_to_fun μ T hT f + set_to_fun μ T hT g` - `set_to_fun_sub : set_to_fun μ T hT (f - g) = set_to_fun μ T hT f - set_to_fun μ T hT g` If `T` is verifies `∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x`: - `set_to_fun_smul : set_to_fun μ T hT (c • f) = c • set_to_fun μ T hT f` Other: - `set_to_fun_congr_ae (h : f =ᵐ[μ] g) : set_to_fun μ T hT f = set_to_fun μ T hT g` - `set_to_fun_measure_zero (h : μ = 0) : set_to_fun μ T hT f = 0` If the space is a `normed_lattice_add_comm_group` and `T` is such that `0 ≤ T s x` for `0 ≤ x`, we also prove order-related properties: - `set_to_fun_mono_left (h : ∀ s x, T s x ≤ T' s x) : set_to_fun μ T hT f ≤ set_to_fun μ T' hT' f` - `set_to_fun_nonneg (hf : 0 ≤ᵐ[μ] f) : 0 ≤ set_to_fun μ T hT f` - `set_to_fun_mono (hfg : f ≤ᵐ[μ] g) : set_to_fun μ T hT f ≤ set_to_fun μ T hT g` ## Implementation notes The starting object `T : set α → E →L[ℝ] F` matters only through its restriction on measurable sets with finite measure. Its value on other sets is ignored. -/ noncomputable theory open_locale classical topological_space big_operators nnreal ennreal measure_theory pointwise open set filter topological_space ennreal emetric namespace measure_theory variables {α E F F' G 𝕜 : Type*} {p : ℝ≥0∞} [normed_add_comm_group E] [normed_space ℝ E] [normed_add_comm_group F] [normed_space ℝ F] [normed_add_comm_group F'] [normed_space ℝ F'] [normed_add_comm_group G] {m : measurable_space α} {μ : measure α} local infixr ` →ₛ `:25 := simple_func open finset section fin_meas_additive /-- A set function is `fin_meas_additive` if its value on the union of two disjoint measurable sets with finite measure is the sum of its values on each set. -/ def fin_meas_additive {β} [add_monoid β] {m : measurable_space α} (μ : measure α) (T : set α → β) : Prop := ∀ s t, measurable_set s → measurable_set t → μ s ≠ ∞ → μ t ≠ ∞ → s ∩ t = ∅ → T (s ∪ t) = T s + T t namespace fin_meas_additive variables {β : Type*} [add_comm_monoid β] {T T' : set α → β} lemma zero : fin_meas_additive μ (0 : set α → β) := λ s t hs ht hμs hμt hst, by simp lemma add (hT : fin_meas_additive μ T) (hT' : fin_meas_additive μ T') : fin_meas_additive μ (T + T') := begin intros s t hs ht hμs hμt hst, simp only [hT s t hs ht hμs hμt hst, hT' s t hs ht hμs hμt hst, pi.add_apply], abel, end lemma smul [monoid 𝕜] [distrib_mul_action 𝕜 β] (hT : fin_meas_additive μ T) (c : 𝕜) : fin_meas_additive μ (λ s, c • (T s)) := λ s t hs ht hμs hμt hst, by simp [hT s t hs ht hμs hμt hst] lemma of_eq_top_imp_eq_top {μ' : measure α} (h : ∀ s, measurable_set s → μ s = ∞ → μ' s = ∞) (hT : fin_meas_additive μ T) : fin_meas_additive μ' T := λ s t hs ht hμ's hμ't hst, hT s t hs ht (mt (h s hs) hμ's) (mt (h t ht) hμ't) hst lemma of_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞) (hT : fin_meas_additive (c • μ) T) : fin_meas_additive μ T := begin refine of_eq_top_imp_eq_top (λ s hs hμs, _) hT, rw [measure.smul_apply, smul_eq_mul, with_top.mul_eq_top_iff] at hμs, simp only [hc_ne_top, or_false, ne.def, false_and] at hμs, exact hμs.2, end lemma smul_measure (c : ℝ≥0∞) (hc_ne_zero : c ≠ 0) (hT : fin_meas_additive μ T) : fin_meas_additive (c • μ) T := begin refine of_eq_top_imp_eq_top (λ s hs hμs, _) hT, rw [measure.smul_apply, smul_eq_mul, with_top.mul_eq_top_iff], simp only [hc_ne_zero, true_and, ne.def, not_false_iff], exact or.inl hμs, end lemma smul_measure_iff (c : ℝ≥0∞) (hc_ne_zero : c ≠ 0) (hc_ne_top : c ≠ ∞) : fin_meas_additive (c • μ) T ↔ fin_meas_additive μ T := ⟨λ hT, of_smul_measure c hc_ne_top hT, λ hT, smul_measure c hc_ne_zero hT⟩ lemma map_empty_eq_zero {β} [add_cancel_monoid β] {T : set α → β} (hT : fin_meas_additive μ T) : T ∅ = 0 := begin have h_empty : μ ∅ ≠ ∞, from (measure_empty.le.trans_lt ennreal.coe_lt_top).ne, specialize hT ∅ ∅ measurable_set.empty measurable_set.empty h_empty h_empty (set.inter_empty ∅), rw set.union_empty at hT, nth_rewrite 0 ← add_zero (T ∅) at hT, exact (add_left_cancel hT).symm, end lemma map_Union_fin_meas_set_eq_sum (T : set α → β) (T_empty : T ∅ = 0) (h_add : fin_meas_additive μ T) {ι} (S : ι → set α) (sι : finset ι) (hS_meas : ∀ i, measurable_set (S i)) (hSp : ∀ i ∈ sι, μ (S i) ≠ ∞) (h_disj : ∀ i j ∈ sι, i ≠ j → disjoint (S i) (S j)) : T (⋃ i ∈ sι, S i) = ∑ i in sι, T (S i) := begin revert hSp h_disj, refine finset.induction_on sι _ _, { simp only [finset.not_mem_empty, is_empty.forall_iff, Union_false, Union_empty, sum_empty, forall_2_true_iff, implies_true_iff, forall_true_left, not_false_iff, T_empty], }, intros a s has h hps h_disj, rw [finset.sum_insert has, ← h], swap, { exact λ i hi, hps i (finset.mem_insert_of_mem hi), }, swap, { exact λ i hi j hj hij, h_disj i (finset.mem_insert_of_mem hi) j (finset.mem_insert_of_mem hj) hij, }, rw ← h_add (S a) (⋃ i ∈ s, S i) (hS_meas a) (measurable_set_bUnion _ (λ i _, hS_meas i)) (hps a (finset.mem_insert_self a s)), { congr, convert finset.supr_insert a s S, }, { exact ((measure_bUnion_finset_le _ _).trans_lt $ ennreal.sum_lt_top $ λ i hi, hps i $ finset.mem_insert_of_mem hi).ne, }, { simp_rw set.inter_Union, refine Union_eq_empty.mpr (λ i, Union_eq_empty.mpr (λ hi, _)), rw ← set.disjoint_iff_inter_eq_empty, refine h_disj a (finset.mem_insert_self a s) i (finset.mem_insert_of_mem hi) (λ hai, _), rw ← hai at hi, exact has hi, }, end end fin_meas_additive /-- A `fin_meas_additive` set function whose norm on every set is less than the measure of the set (up to a multiplicative constant). -/ def dominated_fin_meas_additive {β} [seminormed_add_comm_group β] {m : measurable_space α} (μ : measure α) (T : set α → β) (C : ℝ) : Prop := fin_meas_additive μ T ∧ ∀ s, measurable_set s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).to_real namespace dominated_fin_meas_additive variables {β : Type*} [seminormed_add_comm_group β] {T T' : set α → β} {C C' : ℝ} lemma zero {m : measurable_space α} (μ : measure α) (hC : 0 ≤ C) : dominated_fin_meas_additive μ (0 : set α → β) C := begin refine ⟨fin_meas_additive.zero, λ s hs hμs, _⟩, rw [pi.zero_apply, norm_zero], exact mul_nonneg hC to_real_nonneg, end lemma eq_zero_of_measure_zero {β : Type*} [normed_add_comm_group β] {T : set α → β} {C : ℝ} (hT : dominated_fin_meas_additive μ T C) {s : set α} (hs : measurable_set s) (hs_zero : μ s = 0) : T s = 0 := begin refine norm_eq_zero.mp _, refine ((hT.2 s hs (by simp [hs_zero])).trans (le_of_eq _)).antisymm (norm_nonneg _), rw [hs_zero, ennreal.zero_to_real, mul_zero], end lemma eq_zero {β : Type*} [normed_add_comm_group β] {T : set α → β} {C : ℝ} {m : measurable_space α} (hT : dominated_fin_meas_additive (0 : measure α) T C) {s : set α} (hs : measurable_set s) : T s = 0 := eq_zero_of_measure_zero hT hs (by simp only [measure.coe_zero, pi.zero_apply]) lemma add (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') : dominated_fin_meas_additive μ (T + T') (C + C') := begin refine ⟨hT.1.add hT'.1, λ s hs hμs, _⟩, rw [pi.add_apply, add_mul], exact (norm_add_le _ _).trans (add_le_add (hT.2 s hs hμs) (hT'.2 s hs hμs)), end lemma smul [normed_field 𝕜] [normed_space 𝕜 β] (hT : dominated_fin_meas_additive μ T C) (c : 𝕜) : dominated_fin_meas_additive μ (λ s, c • (T s)) (‖c‖ * C) := begin refine ⟨hT.1.smul c, λ s hs hμs, _⟩, dsimp only, rw [norm_smul, mul_assoc], exact mul_le_mul le_rfl (hT.2 s hs hμs) (norm_nonneg _) (norm_nonneg _), end lemma of_measure_le {μ' : measure α} (h : μ ≤ μ') (hT : dominated_fin_meas_additive μ T C) (hC : 0 ≤ C) : dominated_fin_meas_additive μ' T C := begin have h' : ∀ s, measurable_set s → μ s = ∞ → μ' s = ∞, { intros s hs hμs, rw [eq_top_iff, ← hμs], exact h s hs, }, refine ⟨hT.1.of_eq_top_imp_eq_top h', λ s hs hμ's, _⟩, have hμs : μ s < ∞, from (h s hs).trans_lt hμ's, refine (hT.2 s hs hμs).trans (mul_le_mul le_rfl _ ennreal.to_real_nonneg hC), rw to_real_le_to_real hμs.ne hμ's.ne, exact h s hs, end lemma add_measure_right {m : measurable_space α} (μ ν : measure α) (hT : dominated_fin_meas_additive μ T C) (hC : 0 ≤ C) : dominated_fin_meas_additive (μ + ν) T C := of_measure_le (measure.le_add_right le_rfl) hT hC lemma add_measure_left {m : measurable_space α} (μ ν : measure α) (hT : dominated_fin_meas_additive ν T C) (hC : 0 ≤ C) : dominated_fin_meas_additive (μ + ν) T C := of_measure_le (measure.le_add_left le_rfl) hT hC lemma of_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞) (hT : dominated_fin_meas_additive (c • μ) T C) : dominated_fin_meas_additive μ T (c.to_real * C) := begin have h : ∀ s, measurable_set s → c • μ s = ∞ → μ s = ∞, { intros s hs hcμs, simp only [hc_ne_top, algebra.id.smul_eq_mul, with_top.mul_eq_top_iff, or_false, ne.def, false_and] at hcμs, exact hcμs.2, }, refine ⟨hT.1.of_eq_top_imp_eq_top h, λ s hs hμs, _⟩, have hcμs : c • μ s ≠ ∞, from mt (h s hs) hμs.ne, rw smul_eq_mul at hcμs, simp_rw [dominated_fin_meas_additive, measure.smul_apply, smul_eq_mul, to_real_mul] at hT, refine (hT.2 s hs hcμs.lt_top).trans (le_of_eq _), ring, end lemma of_measure_le_smul {μ' : measure α} (c : ℝ≥0∞) (hc : c ≠ ∞) (h : μ ≤ c • μ') (hT : dominated_fin_meas_additive μ T C) (hC : 0 ≤ C) : dominated_fin_meas_additive μ' T (c.to_real * C) := (hT.of_measure_le h hC).of_smul_measure c hc end dominated_fin_meas_additive end fin_meas_additive namespace simple_func /-- Extend `set α → (F →L[ℝ] F')` to `(α →ₛ F) → F'`. -/ def set_to_simple_func {m : measurable_space α} (T : set α → F →L[ℝ] F') (f : α →ₛ F) : F' := ∑ x in f.range, T (f ⁻¹' {x}) x @[simp] lemma set_to_simple_func_zero {m : measurable_space α} (f : α →ₛ F) : set_to_simple_func (0 : set α → F →L[ℝ] F') f = 0 := by simp [set_to_simple_func] lemma set_to_simple_func_zero' {T : set α → E →L[ℝ] F'} (h_zero : ∀ s, measurable_set s → μ s < ∞ → T s = 0) (f : α →ₛ E) (hf : integrable f μ) : set_to_simple_func T f = 0 := begin simp_rw set_to_simple_func, refine sum_eq_zero (λ x hx, _), by_cases hx0 : x = 0, { simp [hx0], }, rw [h_zero (f ⁻¹' ({x} : set E)) (measurable_set_fiber _ _) (measure_preimage_lt_top_of_integrable f hf hx0), continuous_linear_map.zero_apply], end @[simp] lemma set_to_simple_func_zero_apply {m : measurable_space α} (T : set α → F →L[ℝ] F') : set_to_simple_func T (0 : α →ₛ F) = 0 := by casesI is_empty_or_nonempty α; simp [set_to_simple_func] lemma set_to_simple_func_eq_sum_filter {m : measurable_space α} (T : set α → F →L[ℝ] F') (f : α →ₛ F) : set_to_simple_func T f = ∑ x in f.range.filter (λ x, x ≠ 0), (T (f ⁻¹' {x})) x := begin symmetry, refine sum_filter_of_ne (λ x hx, mt (λ hx0, _)), rw hx0, exact continuous_linear_map.map_zero _, end lemma map_set_to_simple_func (T : set α → F →L[ℝ] F') (h_add : fin_meas_additive μ T) {f : α →ₛ G} (hf : integrable f μ) {g : G → F} (hg : g 0 = 0) : (f.map g).set_to_simple_func T = ∑ x in f.range, T (f ⁻¹' {x}) (g x) := begin have T_empty : T ∅ = 0, from h_add.map_empty_eq_zero, have hfp : ∀ x ∈ f.range, x ≠ 0 → μ (f ⁻¹' {x}) ≠ ∞, from λ x hx hx0, (measure_preimage_lt_top_of_integrable f hf hx0).ne, simp only [set_to_simple_func, range_map], refine finset.sum_image' _ (assume b hb, _), rcases mem_range.1 hb with ⟨a, rfl⟩, by_cases h0 : g (f a) = 0, { simp_rw h0, rw [continuous_linear_map.map_zero, finset.sum_eq_zero (λ x hx, _)], rw mem_filter at hx, rw [hx.2, continuous_linear_map.map_zero], }, have h_left_eq : T ((map g f) ⁻¹' {g (f a)}) (g (f a)) = T (f ⁻¹' ↑(f.range.filter (λ b, g b = g (f a)))) (g (f a)), { congr, rw map_preimage_singleton, }, rw h_left_eq, have h_left_eq' : T (f ⁻¹' ↑(filter (λ (b : G), g b = g (f a)) f.range)) (g (f a)) = T (⋃ y ∈ (filter (λ (b : G), g b = g (f a)) f.range), f ⁻¹' {y}) (g (f a)), { congr, rw ← finset.set_bUnion_preimage_singleton, }, rw h_left_eq', rw h_add.map_Union_fin_meas_set_eq_sum T T_empty, { simp only [filter_congr_decidable, sum_apply, continuous_linear_map.coe_sum'], refine finset.sum_congr rfl (λ x hx, _), rw mem_filter at hx, rw hx.2, }, { exact λ i, measurable_set_fiber _ _, }, { intros i hi, rw mem_filter at hi, refine hfp i hi.1 (λ hi0, _), rw [hi0, hg] at hi, exact h0 hi.2.symm, }, { intros i j hi hj hij, rw set.disjoint_iff, intros x hx, rw [set.mem_inter_iff, set.mem_preimage, set.mem_preimage, set.mem_singleton_iff, set.mem_singleton_iff] at hx, rw [← hx.1, ← hx.2] at hij, exact absurd rfl hij, }, end lemma set_to_simple_func_congr' (T : set α → E →L[ℝ] F) (h_add : fin_meas_additive μ T) {f g : α →ₛ E} (hf : integrable f μ) (hg : integrable g μ) (h : ∀ x y, x ≠ y → T ((f ⁻¹' {x}) ∩ (g ⁻¹' {y})) = 0) : f.set_to_simple_func T = g.set_to_simple_func T := show ((pair f g).map prod.fst).set_to_simple_func T = ((pair f g).map prod.snd).set_to_simple_func T, from begin have h_pair : integrable (f.pair g) μ, from integrable_pair hf hg, rw map_set_to_simple_func T h_add h_pair prod.fst_zero, rw map_set_to_simple_func T h_add h_pair prod.snd_zero, refine finset.sum_congr rfl (λ p hp, _), rcases mem_range.1 hp with ⟨a, rfl⟩, by_cases eq : f a = g a, { dsimp only [pair_apply], rw eq }, { have : T ((pair f g) ⁻¹' {(f a, g a)}) = 0, { have h_eq : T (⇑(f.pair g) ⁻¹' {(f a, g a)}) = T ((f ⁻¹' {f a}) ∩ (g ⁻¹' {g a})), { congr, rw pair_preimage_singleton f g, }, rw h_eq, exact h (f a) (g a) eq, }, simp only [this, continuous_linear_map.zero_apply, pair_apply], }, end lemma set_to_simple_func_congr (T : set α → (E →L[ℝ] F)) (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T) {f g : α →ₛ E} (hf : integrable f μ) (h : f =ᵐ[μ] g) : f.set_to_simple_func T = g.set_to_simple_func T := begin refine set_to_simple_func_congr' T h_add hf ((integrable_congr h).mp hf) _, refine λ x y hxy, h_zero _ ((measurable_set_fiber f x).inter (measurable_set_fiber g y)) _, rw [eventually_eq, ae_iff] at h, refine measure_mono_null (λ z, _) h, simp_rw [set.mem_inter_iff, set.mem_set_of_eq, set.mem_preimage, set.mem_singleton_iff], intro h, rwa [h.1, h.2], end lemma set_to_simple_func_congr_left (T T' : set α → E →L[ℝ] F) (h : ∀ s, measurable_set s → μ s < ∞ → T s = T' s) (f : α →ₛ E) (hf : integrable f μ) : set_to_simple_func T f = set_to_simple_func T' f := begin simp_rw set_to_simple_func, refine sum_congr rfl (λ x hx, _), by_cases hx0 : x = 0, { simp [hx0], }, { rw h (f ⁻¹' {x}) (simple_func.measurable_set_fiber _ _) (simple_func.measure_preimage_lt_top_of_integrable _ hf hx0), }, end lemma set_to_simple_func_add_left {m : measurable_space α} (T T' : set α → F →L[ℝ] F') {f : α →ₛ F} : set_to_simple_func (T + T') f = set_to_simple_func T f + set_to_simple_func T' f := begin simp_rw [set_to_simple_func, pi.add_apply], push_cast, simp_rw [pi.add_apply, sum_add_distrib], end lemma set_to_simple_func_add_left' (T T' T'' : set α → E →L[ℝ] F) (h_add : ∀ s, measurable_set s → μ s < ∞ → T'' s = T s + T' s) {f : α →ₛ E} (hf : integrable f μ) : set_to_simple_func (T'') f = set_to_simple_func T f + set_to_simple_func T' f := begin simp_rw [set_to_simple_func_eq_sum_filter], suffices : ∀ x ∈ filter (λ (x : E), x ≠ 0) f.range, T'' (f ⁻¹' {x}) = T (f ⁻¹' {x}) + T' (f ⁻¹' {x}), { rw ← sum_add_distrib, refine finset.sum_congr rfl (λ x hx, _), rw this x hx, push_cast, rw pi.add_apply, }, intros x hx, refine h_add (f ⁻¹' {x}) (measurable_set_preimage _ _) (measure_preimage_lt_top_of_integrable _ hf _), rw mem_filter at hx, exact hx.2, end lemma set_to_simple_func_smul_left {m : measurable_space α} (T : set α → F →L[ℝ] F') (c : ℝ) (f : α →ₛ F) : set_to_simple_func (λ s, c • (T s)) f = c • set_to_simple_func T f := by simp_rw [set_to_simple_func, continuous_linear_map.smul_apply, smul_sum] lemma set_to_simple_func_smul_left' (T T' : set α → E →L[ℝ] F') (c : ℝ) (h_smul : ∀ s, measurable_set s → μ s < ∞ → T' s = c • (T s)) {f : α →ₛ E} (hf : integrable f μ) : set_to_simple_func T' f = c • set_to_simple_func T f := begin simp_rw [set_to_simple_func_eq_sum_filter], suffices : ∀ x ∈ filter (λ (x : E), x ≠ 0) f.range, T' (f ⁻¹' {x}) = c • (T (f ⁻¹' {x})), { rw smul_sum, refine finset.sum_congr rfl (λ x hx, _), rw this x hx, refl, }, intros x hx, refine h_smul (f ⁻¹' {x}) (measurable_set_preimage _ _) (measure_preimage_lt_top_of_integrable _ hf _), rw mem_filter at hx, exact hx.2, end lemma set_to_simple_func_add (T : set α → E →L[ℝ] F) (h_add : fin_meas_additive μ T) {f g : α →ₛ E} (hf : integrable f μ) (hg : integrable g μ) : set_to_simple_func T (f + g) = set_to_simple_func T f + set_to_simple_func T g := have hp_pair : integrable (f.pair g) μ, from integrable_pair hf hg, calc set_to_simple_func T (f + g) = ∑ x in (pair f g).range, T ((pair f g) ⁻¹' {x}) (x.fst + x.snd) : by { rw [add_eq_map₂, map_set_to_simple_func T h_add hp_pair], simp, } ... = ∑ x in (pair f g).range, (T ((pair f g) ⁻¹' {x}) x.fst + T ((pair f g) ⁻¹' {x}) x.snd) : finset.sum_congr rfl $ assume a ha, continuous_linear_map.map_add _ _ _ ... = ∑ x in (pair f g).range, T ((pair f g) ⁻¹' {x}) x.fst + ∑ x in (pair f g).range, T ((pair f g) ⁻¹' {x}) x.snd : by rw finset.sum_add_distrib ... = ((pair f g).map prod.fst).set_to_simple_func T + ((pair f g).map prod.snd).set_to_simple_func T : by rw [map_set_to_simple_func T h_add hp_pair prod.snd_zero, map_set_to_simple_func T h_add hp_pair prod.fst_zero] lemma set_to_simple_func_neg (T : set α → E →L[ℝ] F) (h_add : fin_meas_additive μ T) {f : α →ₛ E} (hf : integrable f μ) : set_to_simple_func T (-f) = - set_to_simple_func T f := calc set_to_simple_func T (-f) = set_to_simple_func T (f.map (has_neg.neg)) : rfl ... = - set_to_simple_func T f : begin rw [map_set_to_simple_func T h_add hf neg_zero, set_to_simple_func, ← sum_neg_distrib], exact finset.sum_congr rfl (λ x h, continuous_linear_map.map_neg _ _), end lemma set_to_simple_func_sub (T : set α → E →L[ℝ] F) (h_add : fin_meas_additive μ T) {f g : α →ₛ E} (hf : integrable f μ) (hg : integrable g μ) : set_to_simple_func T (f - g) = set_to_simple_func T f - set_to_simple_func T g := begin rw [sub_eq_add_neg, set_to_simple_func_add T h_add hf, set_to_simple_func_neg T h_add hg, sub_eq_add_neg], rw integrable_iff at hg ⊢, intros x hx_ne, change μ ((has_neg.neg ∘ g) ⁻¹' {x}) < ∞, rw [preimage_comp, neg_preimage, set.neg_singleton], refine hg (-x) _, simp [hx_ne], end lemma set_to_simple_func_smul_real (T : set α → E →L[ℝ] F) (h_add : fin_meas_additive μ T) (c : ℝ) {f : α →ₛ E} (hf : integrable f μ) : set_to_simple_func T (c • f) = c • set_to_simple_func T f := calc set_to_simple_func T (c • f) = ∑ x in f.range, T (f ⁻¹' {x}) (c • x) : by { rw [smul_eq_map c f, map_set_to_simple_func T h_add hf], rw smul_zero, } ... = ∑ x in f.range, c • (T (f ⁻¹' {x}) x) : finset.sum_congr rfl $ λ b hb, by { rw continuous_linear_map.map_smul (T (f ⁻¹' {b})) c b, } ... = c • set_to_simple_func T f : by simp only [set_to_simple_func, smul_sum, smul_smul, mul_comm] lemma set_to_simple_func_smul {E} [normed_add_comm_group E] [normed_field 𝕜] [normed_space 𝕜 E] [normed_space ℝ E] [normed_space 𝕜 F] (T : set α → E →L[ℝ] F) (h_add : fin_meas_additive μ T) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) {f : α →ₛ E} (hf : integrable f μ) : set_to_simple_func T (c • f) = c • set_to_simple_func T f := calc set_to_simple_func T (c • f) = ∑ x in f.range, T (f ⁻¹' {x}) (c • x) : by { rw [smul_eq_map c f, map_set_to_simple_func T h_add hf], rw smul_zero, } ... = ∑ x in f.range, c • (T (f ⁻¹' {x}) x) : finset.sum_congr rfl $ λ b hb, by { rw h_smul, } ... = c • set_to_simple_func T f : by simp only [set_to_simple_func, smul_sum, smul_smul, mul_comm] section order variables {G' G'' : Type*} [normed_lattice_add_comm_group G''] [normed_space ℝ G''] [normed_lattice_add_comm_group G'] [normed_space ℝ G'] lemma set_to_simple_func_mono_left {m : measurable_space α} (T T' : set α → F →L[ℝ] G'') (hTT' : ∀ s x, T s x ≤ T' s x) (f : α →ₛ F) : set_to_simple_func T f ≤ set_to_simple_func T' f := by { simp_rw set_to_simple_func, exact sum_le_sum (λ i hi, hTT' _ i), } lemma set_to_simple_func_mono_left' (T T' : set α → E →L[ℝ] G'') (hTT' : ∀ s, measurable_set s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →ₛ E) (hf : integrable f μ) : set_to_simple_func T f ≤ set_to_simple_func T' f := begin refine sum_le_sum (λ i hi, _), by_cases h0 : i = 0, { simp [h0], }, { exact hTT' _ (measurable_set_fiber _ _) (measure_preimage_lt_top_of_integrable _ hf h0) i, } end lemma set_to_simple_func_nonneg {m : measurable_space α} (T : set α → G' →L[ℝ] G'') (hT_nonneg : ∀ s x, 0 ≤ x → 0 ≤ T s x) (f : α →ₛ G') (hf : 0 ≤ f) : 0 ≤ set_to_simple_func T f := begin refine sum_nonneg (λ i hi, hT_nonneg _ i _), rw mem_range at hi, obtain ⟨y, hy⟩ := set.mem_range.mp hi, rw ← hy, refine le_trans _ (hf y), simp, end lemma set_to_simple_func_nonneg' (T : set α → G' →L[ℝ] G'') (hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) (f : α →ₛ G') (hf : 0 ≤ f) (hfi : integrable f μ) : 0 ≤ set_to_simple_func T f := begin refine sum_nonneg (λ i hi, _), by_cases h0 : i = 0, { simp [h0], }, refine hT_nonneg _ (measurable_set_fiber _ _) (measure_preimage_lt_top_of_integrable _ hfi h0) i _, rw mem_range at hi, obtain ⟨y, hy⟩ := set.mem_range.mp hi, rw ← hy, convert (hf y), end lemma set_to_simple_func_mono {T : set α → G' →L[ℝ] G''} (h_add : fin_meas_additive μ T) (hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →ₛ G'} (hfi : integrable f μ) (hgi : integrable g μ) (hfg : f ≤ g) : set_to_simple_func T f ≤ set_to_simple_func T g := begin rw [← sub_nonneg, ← set_to_simple_func_sub T h_add hgi hfi], refine set_to_simple_func_nonneg' T hT_nonneg _ _ (hgi.sub hfi), intro x, simp only [coe_sub, sub_nonneg, coe_zero, pi.zero_apply, pi.sub_apply], exact hfg x, end end order lemma norm_set_to_simple_func_le_sum_op_norm {m : measurable_space α} (T : set α → F' →L[ℝ] F) (f : α →ₛ F') : ‖f.set_to_simple_func T‖ ≤ ∑ x in f.range, ‖T (f ⁻¹' {x})‖ * ‖x‖ := calc ‖∑ x in f.range, T (f ⁻¹' {x}) x‖ ≤ ∑ x in f.range, ‖T (f ⁻¹' {x}) x‖ : norm_sum_le _ _ ... ≤ ∑ x in f.range, ‖T (f ⁻¹' {x})‖ * ‖x‖ : by { refine finset.sum_le_sum (λb hb, _), simp_rw continuous_linear_map.le_op_norm, } lemma norm_set_to_simple_func_le_sum_mul_norm (T : set α → F →L[ℝ] F') {C : ℝ} (hT_norm : ∀ s, measurable_set s → ‖T s‖ ≤ C * (μ s).to_real) (f : α →ₛ F) : ‖f.set_to_simple_func T‖ ≤ C * ∑ x in f.range, (μ (f ⁻¹' {x})).to_real * ‖x‖ := calc ‖f.set_to_simple_func T‖ ≤ ∑ x in f.range, ‖T (f ⁻¹' {x})‖ * ‖x‖ : norm_set_to_simple_func_le_sum_op_norm T f ... ≤ ∑ x in f.range, C * (μ (f ⁻¹' {x})).to_real * ‖x‖ : sum_le_sum $ λ b hb, mul_le_mul_of_nonneg_right (hT_norm _ $ simple_func.measurable_set_fiber _ _) $ norm_nonneg _ ... ≤ C * ∑ x in f.range, (μ (f ⁻¹' {x})).to_real * ‖x‖ : by simp_rw [mul_sum, ← mul_assoc] lemma norm_set_to_simple_func_le_sum_mul_norm_of_integrable (T : set α → E →L[ℝ] F') {C : ℝ} (hT_norm : ∀ s, measurable_set s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).to_real) (f : α →ₛ E) (hf : integrable f μ) : ‖f.set_to_simple_func T‖ ≤ C * ∑ x in f.range, (μ (f ⁻¹' {x})).to_real * ‖x‖ := calc ‖f.set_to_simple_func T‖ ≤ ∑ x in f.range, ‖T (f ⁻¹' {x})‖ * ‖x‖ : norm_set_to_simple_func_le_sum_op_norm T f ... ≤ ∑ x in f.range, C * (μ (f ⁻¹' {x})).to_real * ‖x‖ : begin refine finset.sum_le_sum (λ b hb, _), obtain rfl | hb := eq_or_ne b 0, { simp }, exact mul_le_mul_of_nonneg_right (hT_norm _ (simple_func.measurable_set_fiber _ _) $ simple_func.measure_preimage_lt_top_of_integrable _ hf hb) (norm_nonneg _), end ... ≤ C * ∑ x in f.range, (μ (f ⁻¹' {x})).to_real * ‖x‖ : by simp_rw [mul_sum, ← mul_assoc] lemma set_to_simple_func_indicator (T : set α → F →L[ℝ] F') (hT_empty : T ∅ = 0) {m : measurable_space α} {s : set α} (hs : measurable_set s) (x : F) : simple_func.set_to_simple_func T (simple_func.piecewise s hs (simple_func.const α x) (simple_func.const α 0)) = T s x := begin obtain rfl | hs_empty := s.eq_empty_or_nonempty, { simp only [hT_empty, continuous_linear_map.zero_apply, piecewise_empty, const_zero, set_to_simple_func_zero_apply], }, simp_rw set_to_simple_func, obtain rfl | hs_univ := eq_or_ne s univ, { haveI hα := hs_empty.to_type, simp }, rw range_indicator hs hs_empty hs_univ, by_cases hx0 : x = 0, { simp_rw hx0, simp, }, rw sum_insert, swap, { rw finset.mem_singleton, exact hx0, }, rw [sum_singleton, (T _).map_zero, add_zero], congr, simp only [coe_piecewise, piecewise_eq_indicator, coe_const, pi.const_zero, piecewise_eq_indicator], rw [indicator_preimage, preimage_const_of_mem], swap, { exact set.mem_singleton x, }, rw [← pi.const_zero, preimage_const_of_not_mem], swap, { rw set.mem_singleton_iff, exact ne.symm hx0, }, simp, end lemma set_to_simple_func_const' [nonempty α] (T : set α → F →L[ℝ] F') (x : F) {m : measurable_space α} : simple_func.set_to_simple_func T (simple_func.const α x) = T univ x := by simp only [set_to_simple_func, range_const, set.mem_singleton, preimage_const_of_mem, sum_singleton, coe_const] lemma set_to_simple_func_const (T : set α → F →L[ℝ] F') (hT_empty : T ∅ = 0) (x : F) {m : measurable_space α} : simple_func.set_to_simple_func T (simple_func.const α x) = T univ x := begin casesI hα : is_empty_or_nonempty α, { have h_univ_empty : (univ : set α) = ∅, from subsingleton.elim _ _, rw [h_univ_empty, hT_empty], simp only [set_to_simple_func, continuous_linear_map.zero_apply, sum_empty, range_eq_empty_of_is_empty], }, { exact set_to_simple_func_const' T x, }, end end simple_func namespace L1 open ae_eq_fun Lp.simple_func Lp variables {α E μ} namespace simple_func lemma norm_eq_sum_mul (f : α →₁ₛ[μ] G) : ‖f‖ = ∑ x in (to_simple_func f).range, (μ ((to_simple_func f) ⁻¹' {x})).to_real * ‖x‖ := begin rw [norm_to_simple_func, snorm_one_eq_lintegral_nnnorm], have h_eq := simple_func.map_apply (λ x, (‖x‖₊ : ℝ≥0∞)) (to_simple_func f), dsimp only at h_eq, simp_rw ← h_eq, rw [simple_func.lintegral_eq_lintegral, simple_func.map_lintegral, ennreal.to_real_sum], { congr, ext1 x, rw [ennreal.to_real_mul, mul_comm, ← of_real_norm_eq_coe_nnnorm, ennreal.to_real_of_real (norm_nonneg _)], }, { intros x hx, by_cases hx0 : x = 0, { rw hx0, simp, }, { exact ennreal.mul_ne_top ennreal.coe_ne_top (simple_func.measure_preimage_lt_top_of_integrable _ (simple_func.integrable f) hx0).ne } } end section set_to_L1s variables [normed_field 𝕜] [normed_space 𝕜 E] local attribute [instance] Lp.simple_func.module local attribute [instance] Lp.simple_func.normed_space /-- Extend `set α → (E →L[ℝ] F')` to `(α →₁ₛ[μ] E) → F'`. -/ def set_to_L1s (T : set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) : F := (to_simple_func f).set_to_simple_func T lemma set_to_L1s_eq_set_to_simple_func (T : set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) : set_to_L1s T f = (to_simple_func f).set_to_simple_func T := rfl @[simp] lemma set_to_L1s_zero_left (f : α →₁ₛ[μ] E) : set_to_L1s (0 : set α → E →L[ℝ] F) f = 0 := simple_func.set_to_simple_func_zero _ lemma set_to_L1s_zero_left' {T : set α → E →L[ℝ] F} (h_zero : ∀ s, measurable_set s → μ s < ∞ → T s = 0) (f : α →₁ₛ[μ] E) : set_to_L1s T f = 0 := simple_func.set_to_simple_func_zero' h_zero _ (simple_func.integrable f) lemma set_to_L1s_congr (T : set α → E →L[ℝ] F) (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T) {f g : α →₁ₛ[μ] E} (h : to_simple_func f =ᵐ[μ] to_simple_func g) : set_to_L1s T f = set_to_L1s T g := simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable f) h lemma set_to_L1s_congr_left (T T' : set α → E →L[ℝ] F) (h : ∀ s, measurable_set s → μ s < ∞ → T s = T' s) (f : α →₁ₛ[μ] E) : set_to_L1s T f = set_to_L1s T' f := simple_func.set_to_simple_func_congr_left T T' h (simple_func.to_simple_func f) (simple_func.integrable f) /-- `set_to_L1s` does not change if we replace the measure `μ` by `μ'` with `μ ≪ μ'`. The statement uses two functions `f` and `f'` because they have to belong to different types, but morally these are the same function (we have `f =ᵐ[μ] f'`). -/ lemma set_to_L1s_congr_measure {μ' : measure α} (T : set α → E →L[ℝ] F) (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T) (hμ : μ ≪ μ') (f : α →₁ₛ[μ] E) (f' : α →₁ₛ[μ'] E) (h : f =ᵐ[μ] f') : set_to_L1s T f = set_to_L1s T f' := begin refine simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable f) _, refine (to_simple_func_eq_to_fun f).trans _, suffices : f' =ᵐ[μ] ⇑(simple_func.to_simple_func f'), from h.trans this, have goal' : f' =ᵐ[μ'] simple_func.to_simple_func f', from (to_simple_func_eq_to_fun f').symm, exact hμ.ae_eq goal', end lemma set_to_L1s_add_left (T T' : set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) : set_to_L1s (T + T') f = set_to_L1s T f + set_to_L1s T' f := simple_func.set_to_simple_func_add_left T T' lemma set_to_L1s_add_left' (T T' T'' : set α → E →L[ℝ] F) (h_add : ∀ s, measurable_set s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[μ] E) : set_to_L1s T'' f = set_to_L1s T f + set_to_L1s T' f := simple_func.set_to_simple_func_add_left' T T' T'' h_add (simple_func.integrable f) lemma set_to_L1s_smul_left (T : set α → E →L[ℝ] F) (c : ℝ) (f : α →₁ₛ[μ] E) : set_to_L1s (λ s, c • (T s)) f = c • set_to_L1s T f := simple_func.set_to_simple_func_smul_left T c _ lemma set_to_L1s_smul_left' (T T' : set α → E →L[ℝ] F) (c : ℝ) (h_smul : ∀ s, measurable_set s → μ s < ∞ → T' s = c • (T s)) (f : α →₁ₛ[μ] E) : set_to_L1s T' f = c • set_to_L1s T f := simple_func.set_to_simple_func_smul_left' T T' c h_smul (simple_func.integrable f) lemma set_to_L1s_add (T : set α → E →L[ℝ] F) (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T) (f g : α →₁ₛ[μ] E) : set_to_L1s T (f + g) = set_to_L1s T f + set_to_L1s T g := begin simp_rw set_to_L1s, rw ← simple_func.set_to_simple_func_add T h_add (simple_func.integrable f) (simple_func.integrable g), exact simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable _) (add_to_simple_func f g), end lemma set_to_L1s_neg {T : set α → E →L[ℝ] F} (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T) (f : α →₁ₛ[μ] E) : set_to_L1s T (-f) = - set_to_L1s T f := begin simp_rw set_to_L1s, have : simple_func.to_simple_func (-f) =ᵐ[μ] ⇑(-simple_func.to_simple_func f), from neg_to_simple_func f, rw simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable _) this, exact simple_func.set_to_simple_func_neg T h_add (simple_func.integrable f), end lemma set_to_L1s_sub {T : set α → E →L[ℝ] F} (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T) (f g : α →₁ₛ[μ] E) : set_to_L1s T (f - g) = set_to_L1s T f - set_to_L1s T g := by rw [sub_eq_add_neg, set_to_L1s_add T h_zero h_add, set_to_L1s_neg h_zero h_add, sub_eq_add_neg] lemma set_to_L1s_smul_real (T : set α → E →L[ℝ] F) (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T) (c : ℝ) (f : α →₁ₛ[μ] E) : set_to_L1s T (c • f) = c • set_to_L1s T f := begin simp_rw set_to_L1s, rw ← simple_func.set_to_simple_func_smul_real T h_add c (simple_func.integrable f), refine simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable _) _, exact smul_to_simple_func c f, end lemma set_to_L1s_smul {E} [normed_add_comm_group E] [normed_space ℝ E] [normed_space 𝕜 E] [normed_space 𝕜 F] (T : set α → E →L[ℝ] F) (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α →₁ₛ[μ] E) : set_to_L1s T (c • f) = c • set_to_L1s T f := begin simp_rw set_to_L1s, rw ← simple_func.set_to_simple_func_smul T h_add h_smul c (simple_func.integrable f), refine simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable _) _, exact smul_to_simple_func c f, end lemma norm_set_to_L1s_le (T : set α → E →L[ℝ] F) {C : ℝ} (hT_norm : ∀ s, measurable_set s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).to_real) (f : α →₁ₛ[μ] E) : ‖set_to_L1s T f‖ ≤ C * ‖f‖ := begin rw [set_to_L1s, norm_eq_sum_mul f], exact simple_func.norm_set_to_simple_func_le_sum_mul_norm_of_integrable T hT_norm _ (simple_func.integrable f), end lemma set_to_L1s_indicator_const {T : set α → E →L[ℝ] F} {s : set α} (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T) (hs : measurable_set s) (hμs : μ s < ∞) (x : E) : set_to_L1s T (simple_func.indicator_const 1 hs hμs.ne x) = T s x := begin have h_empty : T ∅ = 0, from h_zero _ measurable_set.empty measure_empty, rw set_to_L1s_eq_set_to_simple_func, refine eq.trans _ (simple_func.set_to_simple_func_indicator T h_empty hs x), refine simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable _) _, exact to_simple_func_indicator_const hs hμs.ne x, end lemma set_to_L1s_const [is_finite_measure μ] {T : set α → E →L[ℝ] F} (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T) (x : E) : set_to_L1s T (simple_func.indicator_const 1 measurable_set.univ (measure_ne_top μ _) x) = T univ x := set_to_L1s_indicator_const h_zero h_add measurable_set.univ (measure_lt_top _ _) x section order variables {G'' G' : Type*} [normed_lattice_add_comm_group G'] [normed_space ℝ G'] [normed_lattice_add_comm_group G''] [normed_space ℝ G''] {T : set α → G'' →L[ℝ] G'} lemma set_to_L1s_mono_left {T T' : set α → E →L[ℝ] G''} (hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) : set_to_L1s T f ≤ set_to_L1s T' f := simple_func.set_to_simple_func_mono_left T T' hTT' _ lemma set_to_L1s_mono_left' {T T' : set α → E →L[ℝ] G''} (hTT' : ∀ s, measurable_set s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) : set_to_L1s T f ≤ set_to_L1s T' f := simple_func.set_to_simple_func_mono_left' T T' hTT' _ (simple_func.integrable f) lemma set_to_L1s_nonneg (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T) (hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁ₛ[μ] G''} (hf : 0 ≤ f) : 0 ≤ set_to_L1s T f := begin simp_rw set_to_L1s, obtain ⟨f', hf', hff'⟩ : ∃ f' : α →ₛ G'', 0 ≤ f' ∧ simple_func.to_simple_func f =ᵐ[μ] f', { obtain ⟨f'', hf'', hff''⟩ := exists_simple_func_nonneg_ae_eq hf, exact ⟨f'', hf'', (Lp.simple_func.to_simple_func_eq_to_fun f).trans hff''⟩, }, rw simple_func.set_to_simple_func_congr _ h_zero h_add (simple_func.integrable _) hff', exact simple_func.set_to_simple_func_nonneg' T hT_nonneg _ hf' ((simple_func.integrable f).congr hff'), end lemma set_to_L1s_mono (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T) (hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁ₛ[μ] G''} (hfg : f ≤ g) : set_to_L1s T f ≤ set_to_L1s T g := begin rw ← sub_nonneg at ⊢ hfg, rw ← set_to_L1s_sub h_zero h_add, exact set_to_L1s_nonneg h_zero h_add hT_nonneg hfg, end end order variables [normed_space 𝕜 F] variables (α E μ 𝕜) /-- Extend `set α → E →L[ℝ] F` to `(α →₁ₛ[μ] E) →L[𝕜] F`. -/ def set_to_L1s_clm' {T : set α → E →L[ℝ] F} {C : ℝ} (hT : dominated_fin_meas_additive μ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) : (α →₁ₛ[μ] E) →L[𝕜] F := linear_map.mk_continuous ⟨set_to_L1s T, set_to_L1s_add T (λ _, hT.eq_zero_of_measure_zero) hT.1, set_to_L1s_smul T (λ _, hT.eq_zero_of_measure_zero) hT.1 h_smul⟩ C (λ f, norm_set_to_L1s_le T hT.2 f) /-- Extend `set α → E →L[ℝ] F` to `(α →₁ₛ[μ] E) →L[ℝ] F`. -/ def set_to_L1s_clm {T : set α → E →L[ℝ] F} {C : ℝ} (hT : dominated_fin_meas_additive μ T C) : (α →₁ₛ[μ] E) →L[ℝ] F := linear_map.mk_continuous ⟨set_to_L1s T, set_to_L1s_add T (λ _, hT.eq_zero_of_measure_zero) hT.1, set_to_L1s_smul_real T (λ _, hT.eq_zero_of_measure_zero) hT.1⟩ C (λ f, norm_set_to_L1s_le T hT.2 f) variables {α E μ 𝕜} variables {T T' T'' : set α → E →L[ℝ] F} {C C' C'' : ℝ} @[simp] lemma set_to_L1s_clm_zero_left (hT : dominated_fin_meas_additive μ (0 : set α → E →L[ℝ] F) C) (f : α →₁ₛ[μ] E) : set_to_L1s_clm α E μ hT f = 0 := set_to_L1s_zero_left _ lemma set_to_L1s_clm_zero_left' (hT : dominated_fin_meas_additive μ T C) (h_zero : ∀ s, measurable_set s → μ s < ∞ → T s = 0) (f : α →₁ₛ[μ] E) : set_to_L1s_clm α E μ hT f = 0 := set_to_L1s_zero_left' h_zero f lemma set_to_L1s_clm_congr_left (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (h : T = T') (f : α →₁ₛ[μ] E) : set_to_L1s_clm α E μ hT f = set_to_L1s_clm α E μ hT' f := set_to_L1s_congr_left T T' (λ _ _ _, by rw h) f lemma set_to_L1s_clm_congr_left' (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (h : ∀ s, measurable_set s → μ s < ∞ → T s = T' s) (f : α →₁ₛ[μ] E) : set_to_L1s_clm α E μ hT f = set_to_L1s_clm α E μ hT' f := set_to_L1s_congr_left T T' h f lemma set_to_L1s_clm_congr_measure {μ' : measure α} (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ' T C') (hμ : μ ≪ μ') (f : α →₁ₛ[μ] E) (f' : α →₁ₛ[μ'] E) (h : f =ᵐ[μ] f') : set_to_L1s_clm α E μ hT f = set_to_L1s_clm α E μ' hT' f' := set_to_L1s_congr_measure T (λ s, hT.eq_zero_of_measure_zero) hT.1 hμ _ _ h lemma set_to_L1s_clm_add_left (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (f : α →₁ₛ[μ] E) : set_to_L1s_clm α E μ (hT.add hT') f = set_to_L1s_clm α E μ hT f + set_to_L1s_clm α E μ hT' f := set_to_L1s_add_left T T' f lemma set_to_L1s_clm_add_left' (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (hT'' : dominated_fin_meas_additive μ T'' C'') (h_add : ∀ s, measurable_set s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[μ] E) : set_to_L1s_clm α E μ hT'' f = set_to_L1s_clm α E μ hT f + set_to_L1s_clm α E μ hT' f := set_to_L1s_add_left' T T' T'' h_add f lemma set_to_L1s_clm_smul_left (c : ℝ) (hT : dominated_fin_meas_additive μ T C) (f : α →₁ₛ[μ] E) : set_to_L1s_clm α E μ (hT.smul c) f = c • set_to_L1s_clm α E μ hT f := set_to_L1s_smul_left T c f lemma set_to_L1s_clm_smul_left' (c : ℝ) (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (h_smul : ∀ s, measurable_set s → μ s < ∞ → T' s = c • (T s)) (f : α →₁ₛ[μ] E) : set_to_L1s_clm α E μ hT' f = c • set_to_L1s_clm α E μ hT f := set_to_L1s_smul_left' T T' c h_smul f lemma norm_set_to_L1s_clm_le {T : set α → E →L[ℝ] F} {C : ℝ} (hT : dominated_fin_meas_additive μ T C) (hC : 0 ≤ C) : ‖set_to_L1s_clm α E μ hT‖ ≤ C := linear_map.mk_continuous_norm_le _ hC _ lemma norm_set_to_L1s_clm_le' {T : set α → E →L[ℝ] F} {C : ℝ} (hT : dominated_fin_meas_additive μ T C) : ‖set_to_L1s_clm α E μ hT‖ ≤ max C 0 := linear_map.mk_continuous_norm_le' _ _ lemma set_to_L1s_clm_const [is_finite_measure μ] {T : set α → E →L[ℝ] F} {C : ℝ} (hT : dominated_fin_meas_additive μ T C) (x : E) : set_to_L1s_clm α E μ hT (simple_func.indicator_const 1 measurable_set.univ (measure_ne_top μ _) x) = T univ x := set_to_L1s_const (λ s, hT.eq_zero_of_measure_zero) hT.1 x section order variables {G' G'' : Type*} [normed_lattice_add_comm_group G''] [normed_space ℝ G''] [normed_lattice_add_comm_group G'] [normed_space ℝ G'] lemma set_to_L1s_clm_mono_left {T T' : set α → E →L[ℝ] G''} {C C' : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) : set_to_L1s_clm α E μ hT f ≤ set_to_L1s_clm α E μ hT' f := simple_func.set_to_simple_func_mono_left T T' hTT' _ lemma set_to_L1s_clm_mono_left' {T T' : set α → E →L[ℝ] G''} {C C' : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (hTT' : ∀ s, measurable_set s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) : set_to_L1s_clm α E μ hT f ≤ set_to_L1s_clm α E μ hT' f := simple_func.set_to_simple_func_mono_left' T T' hTT' _ (simple_func.integrable f) lemma set_to_L1s_clm_nonneg {T : set α → G' →L[ℝ] G''} {C : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁ₛ[μ] G'} (hf : 0 ≤ f) : 0 ≤ set_to_L1s_clm α G' μ hT f := set_to_L1s_nonneg (λ s, hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hf lemma set_to_L1s_clm_mono {T : set α → G' →L[ℝ] G''} {C : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁ₛ[μ] G'} (hfg : f ≤ g) : set_to_L1s_clm α G' μ hT f ≤ set_to_L1s_clm α G' μ hT g := set_to_L1s_mono (λ s, hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hfg end order end set_to_L1s end simple_func open simple_func section set_to_L1 local attribute [instance] Lp.simple_func.module local attribute [instance] Lp.simple_func.normed_space variables (𝕜) [nontrivially_normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F] [complete_space F] {T T' T'' : set α → E →L[ℝ] F} {C C' C'' : ℝ} /-- Extend `set α → (E →L[ℝ] F)` to `(α →₁[μ] E) →L[𝕜] F`. -/ def set_to_L1' (hT : dominated_fin_meas_additive μ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) : (α →₁[μ] E) →L[𝕜] F := (set_to_L1s_clm' α E 𝕜 μ hT h_smul).extend (coe_to_Lp α E 𝕜) (simple_func.dense_range one_ne_top) simple_func.uniform_inducing variables {𝕜} /-- Extend `set α → E →L[ℝ] F` to `(α →₁[μ] E) →L[ℝ] F`. -/ def set_to_L1 (hT : dominated_fin_meas_additive μ T C) : (α →₁[μ] E) →L[ℝ] F := (set_to_L1s_clm α E μ hT).extend (coe_to_Lp α E ℝ) (simple_func.dense_range one_ne_top) simple_func.uniform_inducing lemma set_to_L1_eq_set_to_L1s_clm (hT : dominated_fin_meas_additive μ T C) (f : α →₁ₛ[μ] E) : set_to_L1 hT f = set_to_L1s_clm α E μ hT f := uniformly_extend_of_ind simple_func.uniform_inducing (simple_func.dense_range one_ne_top) (set_to_L1s_clm α E μ hT).uniform_continuous _ lemma set_to_L1_eq_set_to_L1' (hT : dominated_fin_meas_additive μ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (f : α →₁[μ] E) : set_to_L1 hT f = set_to_L1' 𝕜 hT h_smul f := rfl @[simp] lemma set_to_L1_zero_left (hT : dominated_fin_meas_additive μ (0 : set α → E →L[ℝ] F) C) (f : α →₁[μ] E) : set_to_L1 hT f = 0 := begin suffices : set_to_L1 hT = 0, by { rw this, simp, }, refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ hT) _ _ _ _ _, ext1 f, rw [set_to_L1s_clm_zero_left hT f, continuous_linear_map.zero_comp, continuous_linear_map.zero_apply], end lemma set_to_L1_zero_left' (hT : dominated_fin_meas_additive μ T C) (h_zero : ∀ s, measurable_set s → μ s < ∞ → T s = 0) (f : α →₁[μ] E) : set_to_L1 hT f = 0 := begin suffices : set_to_L1 hT = 0, by { rw this, simp, }, refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ hT) _ _ _ _ _, ext1 f, rw [set_to_L1s_clm_zero_left' hT h_zero f, continuous_linear_map.zero_comp, continuous_linear_map.zero_apply], end lemma set_to_L1_congr_left (T T' : set α → E →L[ℝ] F) {C C' : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (h : T = T') (f : α →₁[μ] E) : set_to_L1 hT f = set_to_L1 hT' f := begin suffices : set_to_L1 hT = set_to_L1 hT', by rw this, refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ hT) _ _ _ _ _, ext1 f, suffices : set_to_L1 hT' f = set_to_L1s_clm α E μ hT f, by { rw ← this, congr' 1, }, rw set_to_L1_eq_set_to_L1s_clm, exact set_to_L1s_clm_congr_left hT' hT h.symm f, end lemma set_to_L1_congr_left' (T T' : set α → E →L[ℝ] F) {C C' : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (h : ∀ s, measurable_set s → μ s < ∞ → T s = T' s) (f : α →₁[μ] E) : set_to_L1 hT f = set_to_L1 hT' f := begin suffices : set_to_L1 hT = set_to_L1 hT', by rw this, refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ hT) _ _ _ _ _, ext1 f, suffices : set_to_L1 hT' f = set_to_L1s_clm α E μ hT f, by { rw ← this, congr' 1, }, rw set_to_L1_eq_set_to_L1s_clm, exact (set_to_L1s_clm_congr_left' hT hT' h f).symm, end lemma set_to_L1_add_left (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (f : α →₁[μ] E) : set_to_L1 (hT.add hT') f = set_to_L1 hT f + set_to_L1 hT' f := begin suffices : set_to_L1 (hT.add hT') = set_to_L1 hT + set_to_L1 hT', by { rw [this, continuous_linear_map.add_apply], }, refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ (hT.add hT')) _ _ _ _ _, ext1 f, simp only [continuous_linear_map.add_comp, continuous_linear_map.coe_comp', function.comp_app, continuous_linear_map.add_apply], suffices : set_to_L1 hT f + set_to_L1 hT' f = set_to_L1s_clm α E μ (hT.add hT') f, by { rw ← this, congr, }, rw [set_to_L1_eq_set_to_L1s_clm, set_to_L1_eq_set_to_L1s_clm, set_to_L1s_clm_add_left hT hT'], end lemma set_to_L1_add_left' (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (hT'' : dominated_fin_meas_additive μ T'' C'') (h_add : ∀ s, measurable_set s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁[μ] E) : set_to_L1 hT'' f = set_to_L1 hT f + set_to_L1 hT' f := begin suffices : set_to_L1 hT'' = set_to_L1 hT + set_to_L1 hT', by { rw [this, continuous_linear_map.add_apply], }, refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ hT'') _ _ _ _ _, ext1 f, simp only [continuous_linear_map.add_comp, continuous_linear_map.coe_comp', function.comp_app, continuous_linear_map.add_apply], suffices : set_to_L1 hT f + set_to_L1 hT' f = set_to_L1s_clm α E μ hT'' f, by { rw ← this, congr, }, rw [set_to_L1_eq_set_to_L1s_clm, set_to_L1_eq_set_to_L1s_clm, set_to_L1s_clm_add_left' hT hT' hT'' h_add], end lemma set_to_L1_smul_left (hT : dominated_fin_meas_additive μ T C) (c : ℝ) (f : α →₁[μ] E) : set_to_L1 (hT.smul c) f = c • set_to_L1 hT f := begin suffices : set_to_L1 (hT.smul c) = c • set_to_L1 hT, by { rw [this, continuous_linear_map.smul_apply], }, refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ (hT.smul c)) _ _ _ _ _, ext1 f, simp only [continuous_linear_map.coe_comp', function.comp_app, continuous_linear_map.smul_comp, pi.smul_apply, continuous_linear_map.coe_smul'], suffices : c • set_to_L1 hT f = set_to_L1s_clm α E μ (hT.smul c) f, by { rw ← this, congr, }, rw [set_to_L1_eq_set_to_L1s_clm, set_to_L1s_clm_smul_left c hT], end lemma set_to_L1_smul_left' (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (c : ℝ) (h_smul : ∀ s, measurable_set s → μ s < ∞ → T' s = c • (T s)) (f : α →₁[μ] E) : set_to_L1 hT' f = c • set_to_L1 hT f := begin suffices : set_to_L1 hT' = c • set_to_L1 hT, by { rw [this, continuous_linear_map.smul_apply], }, refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ hT') _ _ _ _ _, ext1 f, simp only [continuous_linear_map.coe_comp', function.comp_app, continuous_linear_map.smul_comp, pi.smul_apply, continuous_linear_map.coe_smul'], suffices : c • set_to_L1 hT f = set_to_L1s_clm α E μ hT' f, by { rw ← this, congr, }, rw [set_to_L1_eq_set_to_L1s_clm, set_to_L1s_clm_smul_left' c hT hT' h_smul], end lemma set_to_L1_smul (hT : dominated_fin_meas_additive μ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α →₁[μ] E) : set_to_L1 hT (c • f) = c • set_to_L1 hT f := begin rw [set_to_L1_eq_set_to_L1' hT h_smul, set_to_L1_eq_set_to_L1' hT h_smul], exact continuous_linear_map.map_smul _ _ _, end lemma set_to_L1_simple_func_indicator_const (hT : dominated_fin_meas_additive μ T C) {s : set α} (hs : measurable_set s) (hμs : μ s < ∞) (x : E) : set_to_L1 hT (simple_func.indicator_const 1 hs hμs.ne x) = T s x := begin rw set_to_L1_eq_set_to_L1s_clm, exact set_to_L1s_indicator_const (λ s, hT.eq_zero_of_measure_zero) hT.1 hs hμs x, end lemma set_to_L1_indicator_const_Lp (hT : dominated_fin_meas_additive μ T C) {s : set α} (hs : measurable_set s) (hμs : μ s ≠ ∞) (x : E) : set_to_L1 hT (indicator_const_Lp 1 hs hμs x) = T s x := begin rw ← Lp.simple_func.coe_indicator_const hs hμs x, exact set_to_L1_simple_func_indicator_const hT hs hμs.lt_top x, end lemma set_to_L1_const [is_finite_measure μ] (hT : dominated_fin_meas_additive μ T C) (x : E) : set_to_L1 hT (indicator_const_Lp 1 measurable_set.univ (measure_ne_top _ _) x) = T univ x := set_to_L1_indicator_const_Lp hT measurable_set.univ (measure_ne_top _ _) x section order variables {G' G'' : Type*} [normed_lattice_add_comm_group G''] [normed_space ℝ G''] [complete_space G''] [normed_lattice_add_comm_group G'] [normed_space ℝ G'] lemma set_to_L1_mono_left' {T T' : set α → E →L[ℝ] G''} {C C' : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (hTT' : ∀ s, measurable_set s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁[μ] E) : set_to_L1 hT f ≤ set_to_L1 hT' f := begin refine Lp.induction one_ne_top _ _ _ _ f, { intros c s hs hμs, rw [set_to_L1_simple_func_indicator_const hT hs hμs, set_to_L1_simple_func_indicator_const hT' hs hμs], exact hTT' s hs hμs c, }, { intros f g hf hg hfg_disj hf_le hg_le, rw [(set_to_L1 hT).map_add, (set_to_L1 hT').map_add], exact add_le_add hf_le hg_le, }, { exact is_closed_le (set_to_L1 hT).continuous (set_to_L1 hT').continuous, }, end lemma set_to_L1_mono_left {T T' : set α → E →L[ℝ] G''} {C C' : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁[μ] E) : set_to_L1 hT f ≤ set_to_L1 hT' f := set_to_L1_mono_left' hT hT' (λ s _ _ x, hTT' s x) f lemma set_to_L1_nonneg {T : set α → G' →L[ℝ] G''} {C : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁[μ] G'} (hf : 0 ≤ f) : 0 ≤ set_to_L1 hT f := begin suffices : ∀ f : {g : α →₁[μ] G' // 0 ≤ g}, 0 ≤ set_to_L1 hT f, from this (⟨f, hf⟩ : {g : α →₁[μ] G' // 0 ≤ g}), refine λ g, @is_closed_property {g : α →₁ₛ[μ] G' // 0 ≤ g} {g : α →₁[μ] G' // 0 ≤ g} _ _ _ (dense_range_coe_simple_func_nonneg_to_Lp_nonneg 1 μ G' one_ne_top) _ _ g, { exact is_closed_le continuous_zero ((set_to_L1 hT).continuous.comp continuous_induced_dom), }, { intros g, have : (coe_simple_func_nonneg_to_Lp_nonneg 1 μ G' g : α →₁[μ] G') = (g : α →₁ₛ[μ] G') := rfl, rw [this, set_to_L1_eq_set_to_L1s_clm], exact set_to_L1s_nonneg (λ s, hT.eq_zero_of_measure_zero) hT.1 hT_nonneg g.2, }, end lemma set_to_L1_mono {T : set α → G' →L[ℝ] G''} {C : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁[μ] G'} (hfg : f ≤ g) : set_to_L1 hT f ≤ set_to_L1 hT g := begin rw ← sub_nonneg at hfg ⊢, rw ← (set_to_L1 hT).map_sub, exact set_to_L1_nonneg hT hT_nonneg hfg, end end order lemma norm_set_to_L1_le_norm_set_to_L1s_clm (hT : dominated_fin_meas_additive μ T C) : ‖set_to_L1 hT‖ ≤ ‖set_to_L1s_clm α E μ hT‖ := calc ‖set_to_L1 hT‖ ≤ (1 : ℝ≥0) * ‖set_to_L1s_clm α E μ hT‖ : begin refine continuous_linear_map.op_norm_extend_le (set_to_L1s_clm α E μ hT) (coe_to_Lp α E ℝ) (simple_func.dense_range one_ne_top) (λ x, le_of_eq _), rw [nnreal.coe_one, one_mul], refl, end ... = ‖set_to_L1s_clm α E μ hT‖ : by rw [nnreal.coe_one, one_mul] lemma norm_set_to_L1_le_mul_norm (hT : dominated_fin_meas_additive μ T C) (hC : 0 ≤ C) (f : α →₁[μ] E) : ‖set_to_L1 hT f‖ ≤ C * ‖f‖ := calc ‖set_to_L1 hT f‖ ≤ ‖set_to_L1s_clm α E μ hT‖ * ‖f‖ : continuous_linear_map.le_of_op_norm_le _ (norm_set_to_L1_le_norm_set_to_L1s_clm hT) _ ... ≤ C * ‖f‖ : mul_le_mul (norm_set_to_L1s_clm_le hT hC) le_rfl (norm_nonneg _) hC lemma norm_set_to_L1_le_mul_norm' (hT : dominated_fin_meas_additive μ T C) (f : α →₁[μ] E) : ‖set_to_L1 hT f‖ ≤ max C 0 * ‖f‖ := calc ‖set_to_L1 hT f‖ ≤ ‖set_to_L1s_clm α E μ hT‖ * ‖f‖ : continuous_linear_map.le_of_op_norm_le _ (norm_set_to_L1_le_norm_set_to_L1s_clm hT) _ ... ≤ max C 0 * ‖f‖ : mul_le_mul (norm_set_to_L1s_clm_le' hT) le_rfl (norm_nonneg _) (le_max_right _ _) lemma norm_set_to_L1_le (hT : dominated_fin_meas_additive μ T C) (hC : 0 ≤ C) : ‖set_to_L1 hT‖ ≤ C := continuous_linear_map.op_norm_le_bound _ hC (norm_set_to_L1_le_mul_norm hT hC) lemma norm_set_to_L1_le' (hT : dominated_fin_meas_additive μ T C) : ‖set_to_L1 hT‖ ≤ max C 0 := continuous_linear_map.op_norm_le_bound _ (le_max_right _ _) (norm_set_to_L1_le_mul_norm' hT) lemma set_to_L1_lipschitz (hT : dominated_fin_meas_additive μ T C) : lipschitz_with (real.to_nnreal C) (set_to_L1 hT) := (set_to_L1 hT).lipschitz.weaken (norm_set_to_L1_le' hT) /-- If `fs i → f` in `L1`, then `set_to_L1 hT (fs i) → set_to_L1 hT f`. -/ lemma tendsto_set_to_L1 (hT : dominated_fin_meas_additive μ T C) (f : α →₁[μ] E) {ι} (fs : ι → α →₁[μ] E) {l : filter ι} (hfs : tendsto fs l (𝓝 f)) : tendsto (λ i, set_to_L1 hT (fs i)) l (𝓝 $ set_to_L1 hT f) := ((set_to_L1 hT).continuous.tendsto _).comp hfs end set_to_L1 end L1 section function variables [complete_space F] {T T' T'': set α → E →L[ℝ] F} {C C' C'' : ℝ} {f g : α → E} variables (μ T) /-- Extend `T : set α → E →L[ℝ] F` to `(α → E) → F` (for integrable functions `α → E`). We set it to 0 if the function is not integrable. -/ def set_to_fun (hT : dominated_fin_meas_additive μ T C) (f : α → E) : F := if hf : integrable f μ then L1.set_to_L1 hT (hf.to_L1 f) else 0 variables {μ T} lemma set_to_fun_eq (hT : dominated_fin_meas_additive μ T C) (hf : integrable f μ) : set_to_fun μ T hT f = L1.set_to_L1 hT (hf.to_L1 f) := dif_pos hf lemma L1.set_to_fun_eq_set_to_L1 (hT : dominated_fin_meas_additive μ T C) (f : α →₁[μ] E) : set_to_fun μ T hT f = L1.set_to_L1 hT f := by rw [set_to_fun_eq hT (L1.integrable_coe_fn f), integrable.to_L1_coe_fn] lemma set_to_fun_undef (hT : dominated_fin_meas_additive μ T C) (hf : ¬ integrable f μ) : set_to_fun μ T hT f = 0 := dif_neg hf lemma set_to_fun_non_ae_strongly_measurable (hT : dominated_fin_meas_additive μ T C) (hf : ¬ ae_strongly_measurable f μ) : set_to_fun μ T hT f = 0 := set_to_fun_undef hT (not_and_of_not_left _ hf) lemma set_to_fun_congr_left (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (h : T = T') (f : α → E) : set_to_fun μ T hT f = set_to_fun μ T' hT' f := begin by_cases hf : integrable f μ, { simp_rw [set_to_fun_eq _ hf, L1.set_to_L1_congr_left T T' hT hT' h], }, { simp_rw [set_to_fun_undef _ hf], }, end lemma set_to_fun_congr_left' (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (h : ∀ s, measurable_set s → μ s < ∞ → T s = T' s) (f : α → E) : set_to_fun μ T hT f = set_to_fun μ T' hT' f := begin by_cases hf : integrable f μ, { simp_rw [set_to_fun_eq _ hf, L1.set_to_L1_congr_left' T T' hT hT' h], }, { simp_rw [set_to_fun_undef _ hf], }, end lemma set_to_fun_add_left (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (f : α → E) : set_to_fun μ (T + T') (hT.add hT') f = set_to_fun μ T hT f + set_to_fun μ T' hT' f := begin by_cases hf : integrable f μ, { simp_rw [set_to_fun_eq _ hf, L1.set_to_L1_add_left hT hT'], }, { simp_rw [set_to_fun_undef _ hf, add_zero], }, end lemma set_to_fun_add_left' (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (hT'' : dominated_fin_meas_additive μ T'' C'') (h_add : ∀ s, measurable_set s → μ s < ∞ → T'' s = T s + T' s) (f : α → E) : set_to_fun μ T'' hT'' f = set_to_fun μ T hT f + set_to_fun μ T' hT' f := begin by_cases hf : integrable f μ, { simp_rw [set_to_fun_eq _ hf, L1.set_to_L1_add_left' hT hT' hT'' h_add], }, { simp_rw [set_to_fun_undef _ hf, add_zero], }, end lemma set_to_fun_smul_left (hT : dominated_fin_meas_additive μ T C) (c : ℝ) (f : α → E) : set_to_fun μ (λ s, c • (T s)) (hT.smul c) f = c • set_to_fun μ T hT f := begin by_cases hf : integrable f μ, { simp_rw [set_to_fun_eq _ hf, L1.set_to_L1_smul_left hT c], }, { simp_rw [set_to_fun_undef _ hf, smul_zero], }, end lemma set_to_fun_smul_left' (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (c : ℝ) (h_smul : ∀ s, measurable_set s → μ s < ∞ → T' s = c • (T s)) (f : α → E) : set_to_fun μ T' hT' f = c • set_to_fun μ T hT f := begin by_cases hf : integrable f μ, { simp_rw [set_to_fun_eq _ hf, L1.set_to_L1_smul_left' hT hT' c h_smul], }, { simp_rw [set_to_fun_undef _ hf, smul_zero], }, end @[simp] lemma set_to_fun_zero (hT : dominated_fin_meas_additive μ T C) : set_to_fun μ T hT (0 : α → E) = 0 := begin rw set_to_fun_eq hT, { simp only [integrable.to_L1_zero, continuous_linear_map.map_zero], }, { exact integrable_zero _ _ _, }, end @[simp] lemma set_to_fun_zero_left {hT : dominated_fin_meas_additive μ (0 : set α → E →L[ℝ] F) C} : set_to_fun μ 0 hT f = 0 := begin by_cases hf : integrable f μ, { rw set_to_fun_eq hT hf, exact L1.set_to_L1_zero_left hT _, }, { exact set_to_fun_undef hT hf, }, end lemma set_to_fun_zero_left' (hT : dominated_fin_meas_additive μ T C) (h_zero : ∀ s, measurable_set s → μ s < ∞ → T s = 0) : set_to_fun μ T hT f = 0 := begin by_cases hf : integrable f μ, { rw set_to_fun_eq hT hf, exact L1.set_to_L1_zero_left' hT h_zero _, }, { exact set_to_fun_undef hT hf, }, end lemma set_to_fun_add (hT : dominated_fin_meas_additive μ T C) (hf : integrable f μ) (hg : integrable g μ) : set_to_fun μ T hT (f + g) = set_to_fun μ T hT f + set_to_fun μ T hT g := by rw [set_to_fun_eq hT (hf.add hg), set_to_fun_eq hT hf, set_to_fun_eq hT hg, integrable.to_L1_add, (L1.set_to_L1 hT).map_add] lemma set_to_fun_finset_sum' (hT : dominated_fin_meas_additive μ T C) {ι} (s : finset ι) {f : ι → α → E} (hf : ∀ i ∈ s, integrable (f i) μ) : set_to_fun μ T hT (∑ i in s, f i) = ∑ i in s, set_to_fun μ T hT (f i) := begin revert hf, refine finset.induction_on s _ _, { intro h, simp only [set_to_fun_zero, finset.sum_empty] }, { assume i s his ih hf, simp only [his, finset.sum_insert, not_false_iff], rw set_to_fun_add hT (hf i (finset.mem_insert_self i s)) _, { rw ih (λ i hi, hf i (finset.mem_insert_of_mem hi)), }, { convert (integrable_finset_sum s (λ i hi, hf i (finset.mem_insert_of_mem hi))), ext1 x, simp, }, } end lemma set_to_fun_finset_sum (hT : dominated_fin_meas_additive μ T C) {ι} (s : finset ι) {f : ι → α → E} (hf : ∀ i ∈ s, integrable (f i) μ) : set_to_fun μ T hT (λ a, ∑ i in s, f i a) = ∑ i in s, set_to_fun μ T hT (f i) := by { convert set_to_fun_finset_sum' hT s hf, ext1 a, simp, } lemma set_to_fun_neg (hT : dominated_fin_meas_additive μ T C) (f : α → E) : set_to_fun μ T hT (-f) = - set_to_fun μ T hT f := begin by_cases hf : integrable f μ, { rw [set_to_fun_eq hT hf, set_to_fun_eq hT hf.neg, integrable.to_L1_neg, (L1.set_to_L1 hT).map_neg], }, { rw [set_to_fun_undef hT hf, set_to_fun_undef hT, neg_zero], rwa [← integrable_neg_iff] at hf, } end lemma set_to_fun_sub (hT : dominated_fin_meas_additive μ T C) (hf : integrable f μ) (hg : integrable g μ) : set_to_fun μ T hT (f - g) = set_to_fun μ T hT f - set_to_fun μ T hT g := by rw [sub_eq_add_neg, sub_eq_add_neg, set_to_fun_add hT hf hg.neg, set_to_fun_neg hT g] lemma set_to_fun_smul [nontrivially_normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F] (hT : dominated_fin_meas_additive μ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α → E) : set_to_fun μ T hT (c • f) = c • set_to_fun μ T hT f := begin by_cases hf : integrable f μ, { rw [set_to_fun_eq hT hf, set_to_fun_eq hT, integrable.to_L1_smul', L1.set_to_L1_smul hT h_smul c _], }, { by_cases hr : c = 0, { rw hr, simp, }, { have hf' : ¬ integrable (c • f) μ, by rwa [integrable_smul_iff hr f], rw [set_to_fun_undef hT hf, set_to_fun_undef hT hf', smul_zero], }, }, end lemma set_to_fun_congr_ae (hT : dominated_fin_meas_additive μ T C) (h : f =ᵐ[μ] g) : set_to_fun μ T hT f = set_to_fun μ T hT g := begin by_cases hfi : integrable f μ, { have hgi : integrable g μ := hfi.congr h, rw [set_to_fun_eq hT hfi, set_to_fun_eq hT hgi, (integrable.to_L1_eq_to_L1_iff f g hfi hgi).2 h] }, { have hgi : ¬ integrable g μ, { rw integrable_congr h at hfi, exact hfi }, rw [set_to_fun_undef hT hfi, set_to_fun_undef hT hgi] }, end lemma set_to_fun_measure_zero (hT : dominated_fin_meas_additive μ T C) (h : μ = 0) : set_to_fun μ T hT f = 0 := by { have : f =ᵐ[μ] 0, by simp [h], rw [set_to_fun_congr_ae hT this, set_to_fun_zero], } lemma set_to_fun_measure_zero' (hT : dominated_fin_meas_additive μ T C) (h : ∀ s, measurable_set s → μ s < ∞ → μ s = 0) : set_to_fun μ T hT f = 0 := set_to_fun_zero_left' hT (λ s hs hμs, hT.eq_zero_of_measure_zero hs (h s hs hμs)) lemma set_to_fun_to_L1 (hT : dominated_fin_meas_additive μ T C) (hf : integrable f μ) : set_to_fun μ T hT (hf.to_L1 f) = set_to_fun μ T hT f := set_to_fun_congr_ae hT hf.coe_fn_to_L1 lemma set_to_fun_indicator_const (hT : dominated_fin_meas_additive μ T C) {s : set α} (hs : measurable_set s) (hμs : μ s ≠ ∞) (x : E) : set_to_fun μ T hT (s.indicator (λ _, x)) = T s x := begin rw set_to_fun_congr_ae hT (@indicator_const_Lp_coe_fn _ _ _ 1 _ _ _ hs hμs x).symm, rw L1.set_to_fun_eq_set_to_L1 hT, exact L1.set_to_L1_indicator_const_Lp hT hs hμs x, end lemma set_to_fun_const [is_finite_measure μ] (hT : dominated_fin_meas_additive μ T C) (x : E) : set_to_fun μ T hT (λ _, x) = T univ x := begin have : (λ (_ : α) , x) = set.indicator univ (λ _, x), from (indicator_univ _).symm, rw this, exact set_to_fun_indicator_const hT measurable_set.univ (measure_ne_top _ _) x, end section order variables {G' G'' : Type*} [normed_lattice_add_comm_group G''] [normed_space ℝ G''] [complete_space G''] [normed_lattice_add_comm_group G'] [normed_space ℝ G'] lemma set_to_fun_mono_left' {T T' : set α → E →L[ℝ] G''} {C C' : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (hTT' : ∀ s, measurable_set s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α → E) : set_to_fun μ T hT f ≤ set_to_fun μ T' hT' f := begin by_cases hf : integrable f μ, { simp_rw set_to_fun_eq _ hf, exact L1.set_to_L1_mono_left' hT hT' hTT' _, }, { simp_rw set_to_fun_undef _ hf, }, end lemma set_to_fun_mono_left {T T' : set α → E →L[ℝ] G''} {C C' : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') (hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁[μ] E) : set_to_fun μ T hT f ≤ set_to_fun μ T' hT' f := set_to_fun_mono_left' hT hT' (λ s _ _ x, hTT' s x) f lemma set_to_fun_nonneg {T : set α → G' →L[ℝ] G''} {C : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α → G'} (hf : 0 ≤ᵐ[μ] f) : 0 ≤ set_to_fun μ T hT f := begin by_cases hfi : integrable f μ, { simp_rw set_to_fun_eq _ hfi, refine L1.set_to_L1_nonneg hT hT_nonneg _, rw ← Lp.coe_fn_le, have h0 := Lp.coe_fn_zero G' 1 μ, have h := integrable.coe_fn_to_L1 hfi, filter_upwards [h0, h, hf] with _ h0a ha hfa, rw [h0a, ha], exact hfa, }, { simp_rw set_to_fun_undef _ hfi, }, end lemma set_to_fun_mono {T : set α → G' →L[ℝ] G''} {C : ℝ} (hT : dominated_fin_meas_additive μ T C) (hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α → G'} (hf : integrable f μ) (hg : integrable g μ) (hfg : f ≤ᵐ[μ] g) : set_to_fun μ T hT f ≤ set_to_fun μ T hT g := begin rw [← sub_nonneg, ← set_to_fun_sub hT hg hf], refine set_to_fun_nonneg hT hT_nonneg (hfg.mono (λ a ha, _)), rw [pi.sub_apply, pi.zero_apply, sub_nonneg], exact ha, end end order @[continuity] lemma continuous_set_to_fun (hT : dominated_fin_meas_additive μ T C) : continuous (λ (f : α →₁[μ] E), set_to_fun μ T hT f) := by { simp_rw L1.set_to_fun_eq_set_to_L1 hT, exact continuous_linear_map.continuous _, } /-- If `F i → f` in `L1`, then `set_to_fun μ T hT (F i) → set_to_fun μ T hT f`. -/ lemma tendsto_set_to_fun_of_L1 (hT : dominated_fin_meas_additive μ T C) {ι} (f : α → E) (hfi : integrable f μ) {fs : ι → α → E} {l : filter ι} (hfsi : ∀ᶠ i in l, integrable (fs i) μ) (hfs : tendsto (λ i, ∫⁻ x, ‖fs i x - f x‖₊ ∂μ) l (𝓝 0)) : tendsto (λ i, set_to_fun μ T hT (fs i)) l (𝓝 $ set_to_fun μ T hT f) := begin classical, let f_lp := hfi.to_L1 f, let F_lp := λ i, if hFi : integrable (fs i) μ then hFi.to_L1 (fs i) else 0, have tendsto_L1 : tendsto F_lp l (𝓝 f_lp), { rw Lp.tendsto_Lp_iff_tendsto_ℒp', simp_rw [snorm_one_eq_lintegral_nnnorm, pi.sub_apply], refine (tendsto_congr' _).mp hfs, filter_upwards [hfsi] with i hi, refine lintegral_congr_ae _, filter_upwards [hi.coe_fn_to_L1, hfi.coe_fn_to_L1] with x hxi hxf, simp_rw [F_lp, dif_pos hi, hxi, hxf], }, suffices : tendsto (λ i, set_to_fun μ T hT (F_lp i)) l (𝓝 (set_to_fun μ T hT f)), { refine (tendsto_congr' _).mp this, filter_upwards [hfsi] with i hi, suffices h_ae_eq : F_lp i =ᵐ[μ] fs i, from set_to_fun_congr_ae hT h_ae_eq, simp_rw [F_lp, dif_pos hi], exact hi.coe_fn_to_L1, }, rw set_to_fun_congr_ae hT (hfi.coe_fn_to_L1).symm, exact ((continuous_set_to_fun hT).tendsto f_lp).comp tendsto_L1, end lemma tendsto_set_to_fun_approx_on_of_measurable (hT : dominated_fin_meas_additive μ T C) [measurable_space E] [borel_space E] {f : α → E} {s : set E} [separable_space s] (hfi : integrable f μ) (hfm : measurable f) (hs : ∀ᵐ x ∂μ, f x ∈ closure s) {y₀ : E} (h₀ : y₀ ∈ s) (h₀i : integrable (λ x, y₀) μ) : tendsto (λ n, set_to_fun μ T hT (simple_func.approx_on f hfm s y₀ h₀ n)) at_top (𝓝 $ set_to_fun μ T hT f) := tendsto_set_to_fun_of_L1 hT _ hfi (eventually_of_forall (simple_func.integrable_approx_on hfm hfi h₀ h₀i)) (simple_func.tendsto_approx_on_L1_nnnorm hfm _ hs (hfi.sub h₀i).2) lemma tendsto_set_to_fun_approx_on_of_measurable_of_range_subset (hT : dominated_fin_meas_additive μ T C) [measurable_space E] [borel_space E] {f : α → E} (fmeas : measurable f) (hf : integrable f μ) (s : set E) [separable_space s] (hs : range f ∪ {0} ⊆ s) : tendsto (λ n, set_to_fun μ T hT (simple_func.approx_on f fmeas s 0 (hs $ by simp) n)) at_top (𝓝 $ set_to_fun μ T hT f) := begin refine tendsto_set_to_fun_approx_on_of_measurable hT hf fmeas _ _ (integrable_zero _ _ _), exact eventually_of_forall (λ x, subset_closure (hs (set.mem_union_left _ (mem_range_self _)))), end /-- Auxiliary lemma for `set_to_fun_congr_measure`: the function sending `f : α →₁[μ] G` to `f : α →₁[μ'] G` is continuous when `μ' ≤ c' • μ` for `c' ≠ ∞`. -/ lemma continuous_L1_to_L1 {μ' : measure α} (c' : ℝ≥0∞) (hc' : c' ≠ ∞) (hμ'_le : μ' ≤ c' • μ) : continuous (λ f : α →₁[μ] G, (integrable.of_measure_le_smul c' hc' hμ'_le (L1.integrable_coe_fn f)).to_L1 f) := begin by_cases hc'0 : c' = 0, { have hμ'0 : μ' = 0, { rw ← measure.nonpos_iff_eq_zero', refine hμ'_le.trans _, simp [hc'0], }, have h_im_zero : (λ f : α →₁[μ] G, (integrable.of_measure_le_smul c' hc' hμ'_le (L1.integrable_coe_fn f)).to_L1 f) = 0, by { ext1 f, ext1, simp_rw hμ'0, simp only [ae_zero], }, rw h_im_zero, exact continuous_zero, }, rw metric.continuous_iff, intros f ε hε_pos, use (ε / 2) / c'.to_real, refine ⟨div_pos (half_pos hε_pos) (to_real_pos hc'0 hc'), _⟩, intros g hfg, rw Lp.dist_def at hfg ⊢, let h_int := λ f' : α →₁[μ] G, (L1.integrable_coe_fn f').of_measure_le_smul c' hc' hμ'_le, have : snorm (integrable.to_L1 g (h_int g) - integrable.to_L1 f (h_int f)) 1 μ' = snorm (g - f) 1 μ', from snorm_congr_ae ((integrable.coe_fn_to_L1 _).sub (integrable.coe_fn_to_L1 _)), rw this, have h_snorm_ne_top : snorm (g - f) 1 μ ≠ ∞, by { rw ← snorm_congr_ae (Lp.coe_fn_sub _ _), exact Lp.snorm_ne_top _, }, have h_snorm_ne_top' : snorm (g - f) 1 μ' ≠ ∞, { refine ((snorm_mono_measure _ hμ'_le).trans_lt _).ne, rw [snorm_smul_measure_of_ne_zero hc'0, smul_eq_mul], refine ennreal.mul_lt_top _ h_snorm_ne_top, simp [hc', hc'0], }, calc (snorm (g - f) 1 μ').to_real ≤ (c' * snorm (g - f) 1 μ).to_real : by { rw to_real_le_to_real h_snorm_ne_top' (ennreal.mul_ne_top hc' h_snorm_ne_top), refine (snorm_mono_measure (⇑g - ⇑f) hμ'_le).trans _, rw [snorm_smul_measure_of_ne_zero hc'0, smul_eq_mul], simp, } ... = c'.to_real * (snorm (⇑g - ⇑f) 1 μ).to_real : to_real_mul ... ≤ c'.to_real * ((ε / 2) / c'.to_real) : mul_le_mul le_rfl hfg.le to_real_nonneg to_real_nonneg ... = ε / 2 : by { refine mul_div_cancel' (ε / 2) _, rw [ne.def, to_real_eq_zero_iff], simp [hc', hc'0], } ... < ε : half_lt_self hε_pos, end lemma set_to_fun_congr_measure_of_integrable {μ' : measure α} (c' : ℝ≥0∞) (hc' : c' ≠ ∞) (hμ'_le : μ' ≤ c' • μ) (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ' T C') (f : α → E) (hfμ : integrable f μ) : set_to_fun μ T hT f = set_to_fun μ' T hT' f := begin /- integrability for `μ` implies integrability for `μ'`. -/ have h_int : ∀ g : α → E, integrable g μ → integrable g μ', from λ g hg, integrable.of_measure_le_smul c' hc' hμ'_le hg, /- We use `integrable.induction` -/ refine hfμ.induction _ _ _ _ _, { intros c s hs hμs, have hμ's : μ' s ≠ ∞, { refine ((hμ'_le s hs).trans_lt _).ne, rw [measure.smul_apply, smul_eq_mul], exact ennreal.mul_lt_top hc' hμs.ne, }, rw [set_to_fun_indicator_const hT hs hμs.ne, set_to_fun_indicator_const hT' hs hμ's], }, { intros f₂ g₂ h_dish hf₂ hg₂ h_eq_f h_eq_g, rw [set_to_fun_add hT hf₂ hg₂, set_to_fun_add hT' (h_int f₂ hf₂) (h_int g₂ hg₂), h_eq_f, h_eq_g], }, { refine is_closed_eq (continuous_set_to_fun hT) _, have : (λ f : α →₁[μ] E, set_to_fun μ' T hT' f) = (λ f : α →₁[μ] E, set_to_fun μ' T hT' ((h_int f (L1.integrable_coe_fn f)).to_L1 f)), { ext1 f, exact set_to_fun_congr_ae hT' (integrable.coe_fn_to_L1 _).symm, }, rw this, exact (continuous_set_to_fun hT').comp (continuous_L1_to_L1 c' hc' hμ'_le), }, { intros f₂ g₂ hfg hf₂ hf_eq, have hfg' : f₂ =ᵐ[μ'] g₂, from (measure.absolutely_continuous_of_le_smul hμ'_le).ae_eq hfg, rw [← set_to_fun_congr_ae hT hfg, hf_eq, set_to_fun_congr_ae hT' hfg'], }, end lemma set_to_fun_congr_measure {μ' : measure α} (c c' : ℝ≥0∞) (hc : c ≠ ∞) (hc' : c' ≠ ∞) (hμ_le : μ ≤ c • μ') (hμ'_le : μ' ≤ c' • μ) (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ' T C') (f : α → E) : set_to_fun μ T hT f = set_to_fun μ' T hT' f := begin by_cases hf : integrable f μ, { exact set_to_fun_congr_measure_of_integrable c' hc' hμ'_le hT hT' f hf, }, { /- if `f` is not integrable, both `set_to_fun` are 0. -/ have h_int : ∀ g : α → E, ¬ integrable g μ → ¬ integrable g μ', from λ g, mt (λ h, h.of_measure_le_smul _ hc hμ_le), simp_rw [set_to_fun_undef _ hf, set_to_fun_undef _ (h_int f hf)], }, end lemma set_to_fun_congr_measure_of_add_right {μ' : measure α} (hT_add : dominated_fin_meas_additive (μ + μ') T C') (hT : dominated_fin_meas_additive μ T C) (f : α → E) (hf : integrable f (μ + μ')) : set_to_fun (μ + μ') T hT_add f = set_to_fun μ T hT f := begin refine set_to_fun_congr_measure_of_integrable 1 one_ne_top _ hT_add hT f hf, rw one_smul, nth_rewrite 0 ← add_zero μ, exact add_le_add le_rfl bot_le, end lemma set_to_fun_congr_measure_of_add_left {μ' : measure α} (hT_add : dominated_fin_meas_additive (μ + μ') T C') (hT : dominated_fin_meas_additive μ' T C) (f : α → E) (hf : integrable f (μ + μ')) : set_to_fun (μ + μ') T hT_add f = set_to_fun μ' T hT f := begin refine set_to_fun_congr_measure_of_integrable 1 one_ne_top _ hT_add hT f hf, rw one_smul, nth_rewrite 0 ← zero_add μ', exact add_le_add bot_le le_rfl, end lemma set_to_fun_top_smul_measure (hT : dominated_fin_meas_additive (∞ • μ) T C) (f : α → E) : set_to_fun (∞ • μ) T hT f = 0 := begin refine set_to_fun_measure_zero' hT (λ s hs hμs, _), rw lt_top_iff_ne_top at hμs, simp only [true_and, measure.smul_apply, with_top.mul_eq_top_iff, eq_self_iff_true, top_ne_zero, ne.def, not_false_iff, not_or_distrib, not_not, smul_eq_mul] at hμs, simp only [hμs.right, measure.smul_apply, mul_zero, smul_eq_mul], end lemma set_to_fun_congr_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞) (hT : dominated_fin_meas_additive μ T C) (hT_smul : dominated_fin_meas_additive (c • μ) T C') (f : α → E) : set_to_fun μ T hT f = set_to_fun (c • μ) T hT_smul f := begin by_cases hc0 : c = 0, { simp [hc0] at hT_smul, have h : ∀ s, measurable_set s → μ s < ∞ → T s = 0, from λ s hs hμs, hT_smul.eq_zero hs, rw [set_to_fun_zero_left' _ h, set_to_fun_measure_zero], simp [hc0], }, refine set_to_fun_congr_measure c⁻¹ c _ hc_ne_top (le_of_eq _) le_rfl hT hT_smul f, { simp [hc0], }, { rw [smul_smul, ennreal.inv_mul_cancel hc0 hc_ne_top, one_smul], }, end lemma norm_set_to_fun_le_mul_norm (hT : dominated_fin_meas_additive μ T C) (f : α →₁[μ] E) (hC : 0 ≤ C) : ‖set_to_fun μ T hT f‖ ≤ C * ‖f‖ := by { rw L1.set_to_fun_eq_set_to_L1, exact L1.norm_set_to_L1_le_mul_norm hT hC f, } lemma norm_set_to_fun_le_mul_norm' (hT : dominated_fin_meas_additive μ T C) (f : α →₁[μ] E) : ‖set_to_fun μ T hT f‖ ≤ max C 0 * ‖f‖ := by { rw L1.set_to_fun_eq_set_to_L1, exact L1.norm_set_to_L1_le_mul_norm' hT f, } lemma norm_set_to_fun_le (hT : dominated_fin_meas_additive μ T C) (hf : integrable f μ) (hC : 0 ≤ C) : ‖set_to_fun μ T hT f‖ ≤ C * ‖hf.to_L1 f‖ := by { rw set_to_fun_eq hT hf, exact L1.norm_set_to_L1_le_mul_norm hT hC _, } lemma norm_set_to_fun_le' (hT : dominated_fin_meas_additive μ T C) (hf : integrable f μ) : ‖set_to_fun μ T hT f‖ ≤ max C 0 * ‖hf.to_L1 f‖ := by { rw set_to_fun_eq hT hf, exact L1.norm_set_to_L1_le_mul_norm' hT _, } /-- Lebesgue dominated convergence theorem provides sufficient conditions under which almost everywhere convergence of a sequence of functions implies the convergence of their image by `set_to_fun`. We could weaken the condition `bound_integrable` to require `has_finite_integral bound μ` instead (i.e. not requiring that `bound` is measurable), but in all applications proving integrability is easier. -/ theorem tendsto_set_to_fun_of_dominated_convergence (hT : dominated_fin_meas_additive μ T C) {fs : ℕ → α → E} {f : α → E} (bound : α → ℝ) (fs_measurable : ∀ n, ae_strongly_measurable (fs n) μ) (bound_integrable : integrable bound μ) (h_bound : ∀ n, ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a) (h_lim : ∀ᵐ a ∂μ, tendsto (λ n, fs n a) at_top (𝓝 (f a))) : tendsto (λ n, set_to_fun μ T hT (fs n)) at_top (𝓝 $ set_to_fun μ T hT f) := begin /- `f` is a.e.-measurable, since it is the a.e.-pointwise limit of a.e.-measurable functions. -/ have f_measurable : ae_strongly_measurable f μ := ae_strongly_measurable_of_tendsto_ae _ fs_measurable h_lim, /- all functions we consider are integrable -/ have fs_int : ∀ n, integrable (fs n) μ := λ n, bound_integrable.mono' (fs_measurable n) (h_bound _), have f_int : integrable f μ := ⟨f_measurable, has_finite_integral_of_dominated_convergence bound_integrable.has_finite_integral h_bound h_lim⟩, /- it suffices to prove the result for the corresponding L1 functions -/ suffices : tendsto (λ n, L1.set_to_L1 hT ((fs_int n).to_L1 (fs n))) at_top (𝓝 (L1.set_to_L1 hT (f_int.to_L1 f))), { convert this, { ext1 n, exact set_to_fun_eq hT (fs_int n), }, { exact set_to_fun_eq hT f_int, }, }, /- the convergence of set_to_L1 follows from the convergence of the L1 functions -/ refine L1.tendsto_set_to_L1 hT _ _ _, /- up to some rewriting, what we need to prove is `h_lim` -/ rw tendsto_iff_norm_tendsto_zero, have lintegral_norm_tendsto_zero : tendsto (λn, ennreal.to_real $ ∫⁻ a, (ennreal.of_real ‖fs n a - f a‖) ∂μ) at_top (𝓝 0) := (tendsto_to_real zero_ne_top).comp (tendsto_lintegral_norm_of_dominated_convergence fs_measurable bound_integrable.has_finite_integral h_bound h_lim), convert lintegral_norm_tendsto_zero, ext1 n, rw L1.norm_def, congr' 1, refine lintegral_congr_ae _, rw ← integrable.to_L1_sub, refine ((fs_int n).sub f_int).coe_fn_to_L1.mono (λ x hx, _), dsimp only, rw [hx, of_real_norm_eq_coe_nnnorm, pi.sub_apply], end /-- Lebesgue dominated convergence theorem for filters with a countable basis -/ lemma tendsto_set_to_fun_filter_of_dominated_convergence (hT : dominated_fin_meas_additive μ T C) {ι} {l : _root_.filter ι} [l.is_countably_generated] {fs : ι → α → E} {f : α → E} (bound : α → ℝ) (hfs_meas : ∀ᶠ n in l, ae_strongly_measurable (fs n) μ) (h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a) (bound_integrable : integrable bound μ) (h_lim : ∀ᵐ a ∂μ, tendsto (λ n, fs n a) l (𝓝 (f a))) : tendsto (λ n, set_to_fun μ T hT (fs n)) l (𝓝 $ set_to_fun μ T hT f) := begin rw tendsto_iff_seq_tendsto, intros x xl, have hxl : ∀ s ∈ l, ∃ a, ∀ b ≥ a, x b ∈ s, by { rwa tendsto_at_top' at xl, }, have h : {x : ι | (λ n, ae_strongly_measurable (fs n) μ) x} ∩ {x : ι | (λ n, ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a) x} ∈ l, from inter_mem hfs_meas h_bound, obtain ⟨k, h⟩ := hxl _ h, rw ← tendsto_add_at_top_iff_nat k, refine tendsto_set_to_fun_of_dominated_convergence hT bound _ bound_integrable _ _, { exact λ n, (h _ (self_le_add_left _ _)).1, }, { exact λ n, (h _ (self_le_add_left _ _)).2, }, { filter_upwards [h_lim], refine λ a h_lin, @tendsto.comp _ _ _ (λ n, x (n + k)) (λ n, fs n a) _ _ _ h_lin _, rw tendsto_add_at_top_iff_nat, assumption } end variables {X : Type*} [topological_space X] [first_countable_topology X] lemma continuous_within_at_set_to_fun_of_dominated (hT : dominated_fin_meas_additive μ T C) {fs : X → α → E} {x₀ : X} {bound : α → ℝ} {s : set X} (hfs_meas : ∀ᶠ x in 𝓝[s] x₀, ae_strongly_measurable (fs x) μ) (h_bound : ∀ᶠ x in 𝓝[s] x₀, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous_within_at (λ x, fs x a) s x₀) : continuous_within_at (λ x, set_to_fun μ T hT (fs x)) s x₀ := tendsto_set_to_fun_filter_of_dominated_convergence hT bound ‹_› ‹_› ‹_› ‹_› lemma continuous_at_set_to_fun_of_dominated (hT : dominated_fin_meas_additive μ T C) {fs : X → α → E} {x₀ : X} {bound : α → ℝ} (hfs_meas : ∀ᶠ x in 𝓝 x₀, ae_strongly_measurable (fs x) μ) (h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous_at (λ x, fs x a) x₀) : continuous_at (λ x, set_to_fun μ T hT (fs x)) x₀ := tendsto_set_to_fun_filter_of_dominated_convergence hT bound ‹_› ‹_› ‹_› ‹_› lemma continuous_on_set_to_fun_of_dominated (hT : dominated_fin_meas_additive μ T C) {fs : X → α → E} {bound : α → ℝ} {s : set X} (hfs_meas : ∀ x ∈ s, ae_strongly_measurable (fs x) μ) (h_bound : ∀ x ∈ s, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous_on (λ x, fs x a) s) : continuous_on (λ x, set_to_fun μ T hT (fs x)) s := begin assume x hx, refine continuous_within_at_set_to_fun_of_dominated hT _ _ bound_integrable _, { filter_upwards [self_mem_nhds_within] with x hx using hfs_meas x hx }, { filter_upwards [self_mem_nhds_within] with x hx using h_bound x hx }, { filter_upwards [h_cont] with a ha using ha x hx } end lemma continuous_set_to_fun_of_dominated (hT : dominated_fin_meas_additive μ T C) {fs : X → α → E} {bound : α → ℝ} (hfs_meas : ∀ x, ae_strongly_measurable (fs x) μ) (h_bound : ∀ x, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous (λ x, fs x a)) : continuous (λ x, set_to_fun μ T hT (fs x)) := continuous_iff_continuous_at.mpr (λ x₀, continuous_at_set_to_fun_of_dominated hT (eventually_of_forall hfs_meas) (eventually_of_forall h_bound) ‹_› $ h_cont.mono $ λ _, continuous.continuous_at) end function end measure_theory
94f567d1710102850b88be22a1bed38cb9216af5
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/algebra/bounds.lean
24454207ab5d63bb7c3d7a9b2004260f4242cf72
[ "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
3,826
lean
/- Copyright (c) 2021 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import order.conditionally_complete_lattice import algebra.pointwise /-! # Upper/lower bounds in ordered monoids and groups In this file we prove a few facts like “`-s` is bounded above iff `s` is bounded below” (`bdd_above_neg`). -/ open function set open_locale pointwise section inv_neg variables {G : Type*} [group G] [preorder G] [covariant_class G G (*) (≤)] [covariant_class G G (swap (*)) (≤)] {s : set G} {a : G} @[simp, to_additive] lemma bdd_above_inv : bdd_above s⁻¹ ↔ bdd_below s := (order_iso.inv G).bdd_above_preimage @[simp, to_additive] lemma bdd_below_inv : bdd_below s⁻¹ ↔ bdd_above s := (order_iso.inv G).bdd_below_preimage @[to_additive] lemma bdd_above.inv (h : bdd_above s) : bdd_below s⁻¹ := bdd_below_inv.2 h @[to_additive] lemma bdd_below.inv (h : bdd_below s) : bdd_above s⁻¹ := bdd_above_inv.2 h @[simp, to_additive] lemma is_lub_inv : is_lub s⁻¹ a ↔ is_glb s a⁻¹ := (order_iso.inv G).is_lub_preimage @[to_additive] lemma is_lub_inv' : is_lub s⁻¹ a⁻¹ ↔ is_glb s a := (order_iso.inv G).is_lub_preimage' @[to_additive] lemma is_glb.inv (h : is_glb s a) : is_lub s⁻¹ a⁻¹ := is_lub_inv'.2 h @[simp, to_additive] lemma is_glb_inv : is_glb s⁻¹ a ↔ is_lub s a⁻¹ := (order_iso.inv G).is_glb_preimage @[to_additive] lemma is_glb_inv' : is_glb s⁻¹ a⁻¹ ↔ is_lub s a := (order_iso.inv G).is_glb_preimage' @[to_additive] lemma is_lub.inv (h : is_lub s a) : is_glb s⁻¹ a⁻¹ := is_glb_inv'.2 h end inv_neg section mul_add variables {M : Type*} [has_mul M] [preorder M] [covariant_class M M (*) (≤)] [covariant_class M M (swap (*)) (≤)] @[to_additive] lemma mul_mem_upper_bounds_mul {s t : set M} {a b : M} (ha : a ∈ upper_bounds s) (hb : b ∈ upper_bounds t) : a * b ∈ upper_bounds (s * t) := forall_image2_iff.2 $ λ x hx y hy, mul_le_mul' (ha hx) (hb hy) @[to_additive] lemma subset_upper_bounds_mul (s t : set M) : upper_bounds s * upper_bounds t ⊆ upper_bounds (s * t) := image2_subset_iff.2 $ λ x hx y hy, mul_mem_upper_bounds_mul hx hy @[to_additive] lemma mul_mem_lower_bounds_mul {s t : set M} {a b : M} (ha : a ∈ lower_bounds s) (hb : b ∈ lower_bounds t) : a * b ∈ lower_bounds (s * t) := @mul_mem_upper_bounds_mul (order_dual M) _ _ _ _ _ _ _ _ ha hb @[to_additive] lemma subset_lower_bounds_mul (s t : set M) : lower_bounds s * lower_bounds t ⊆ lower_bounds (s * t) := @subset_upper_bounds_mul (order_dual M) _ _ _ _ _ _ @[to_additive] lemma bdd_above.mul {s t : set M} (hs : bdd_above s) (ht : bdd_above t) : bdd_above (s * t) := (hs.mul ht).mono (subset_upper_bounds_mul s t) @[to_additive] lemma bdd_below.mul {s t : set M} (hs : bdd_below s) (ht : bdd_below t) : bdd_below (s * t) := (hs.mul ht).mono (subset_lower_bounds_mul s t) end mul_add section conditionally_complete_lattice section right variables {ι G : Type*} [group G] [conditionally_complete_lattice G] [covariant_class G G (function.swap (*)) (≤)] [nonempty ι] {f : ι → G} @[to_additive] lemma csupr_mul (hf : bdd_above (set.range f)) (a : G) : (⨆ i, f i) * a = ⨆ i, f i * a := (order_iso.mul_right a).map_csupr hf @[to_additive] lemma csupr_div (hf : bdd_above (set.range f)) (a : G) : (⨆ i, f i) / a = ⨆ i, f i / a := by simp only [div_eq_mul_inv, csupr_mul hf] end right section left variables {ι G : Type*} [group G] [conditionally_complete_lattice G] [covariant_class G G (*) (≤)] [nonempty ι] {f : ι → G} @[to_additive] lemma mul_csupr (hf : bdd_above (set.range f)) (a : G) : a * (⨆ i, f i) = ⨆ i, a * f i := (order_iso.mul_left a).map_csupr hf end left end conditionally_complete_lattice
ede467ce478270f17d74238b305e8eafd75ea369
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/control/traversable/basic.lean
6f297f03b087bd3ab02d736b6484a58732a165a7
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
9,671
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 control.functor import tactic.ext /-! # Traversable type class > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. Type classes for traversing collections. The concepts and laws are taken from <http://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Traversable.html> Traversable collections are a generalization of functors. Whereas functors (such as `list`) allow us to apply a function to every element, it does not allow functions which external effects encoded in a monad. Consider for instance a functor `invite : email → io response` that takes an email address, sends an email and waits for a response. If we have a list `guests : list email`, using calling `invite` using `map` gives us the following: `map invite guests : list (io response)`. It is not what we need. We need something of type `io (list response)`. Instead of using `map`, we can use `traverse` to send all the invites: `traverse invite guests : io (list response)`. `traverse` applies `invite` to every element of `guests` and combines all the resulting effects. In the example, the effect is encoded in the monad `io` but any applicative functor is accepted by `traverse`. For more on how to use traversable, consider the Haskell tutorial: <https://en.wikibooks.org/wiki/Haskell/Traversable> ## Main definitions * `traversable` type class - exposes the `traverse` function * `sequence` - based on `traverse`, turns a collection of effects into an effect returning a collection * `is_lawful_traversable` - laws for a traversable functor * `applicative_transformation` - the notion of a natural transformation for applicative functors ## Tags traversable iterator functor applicative ## References * "Applicative Programming with Effects", by Conor McBride and Ross Paterson, Journal of Functional Programming 18:1 (2008) 1-13, online at <http://www.soi.city.ac.uk/~ross/papers/Applicative.html> * "The Essence of the Iterator Pattern", by Jeremy Gibbons and Bruno Oliveira, in Mathematically-Structured Functional Programming, 2006, online at <http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/#iterator> * "An Investigation of the Laws of Traversals", by Mauro Jaskelioff and Ondrej Rypacek, in Mathematically-Structured Functional Programming, 2012, online at <http://arxiv.org/pdf/1202.2919> -/ open function (hiding comp) universes u v w section applicative_transformation variables (F : Type u → Type v) [applicative F] [is_lawful_applicative F] variables (G : Type u → Type w) [applicative G] [is_lawful_applicative G] /-- A transformation between applicative functors. It is a natural transformation such that `app` preserves the `has_pure.pure` and `functor.map` (`<*>`) operations. See `applicative_transformation.preserves_map` for naturality. -/ structure applicative_transformation : Type (max (u+1) v w) := (app : Π α : Type u, F α → G α) (preserves_pure' : ∀ {α : Type u} (x : α), app _ (pure x) = pure x) (preserves_seq' : ∀ {α β : Type u} (x : F (α → β)) (y : F α), app _ (x <*> y) = app _ x <*> app _ y) end applicative_transformation namespace applicative_transformation variables (F : Type u → Type v) [applicative F] [is_lawful_applicative F] variables (G : Type u → Type w) [applicative G] [is_lawful_applicative G] instance : has_coe_to_fun (applicative_transformation F G) (λ _, Π {α}, F α → G α) := ⟨applicative_transformation.app⟩ variables {F G} @[simp] lemma app_eq_coe (η : applicative_transformation F G) : η.app = η := rfl @[simp] lemma coe_mk (f : Π (α : Type u), F α → G α) (pp ps) : ⇑(applicative_transformation.mk f pp ps) = f := rfl protected lemma congr_fun (η η' : applicative_transformation F G) (h : η = η') {α : Type u} (x : F α) : η x = η' x := congr_arg (λ η'' : applicative_transformation F G, η'' x) h protected lemma congr_arg (η : applicative_transformation F G) {α : Type u} {x y : F α} (h : x = y) : η x = η y := congr_arg (λ z : F α, η z) h lemma coe_inj ⦃η η' : applicative_transformation F G⦄ (h : (η : Π α, F α → G α) = η') : η = η' := by { cases η, cases η', congr, exact h } @[ext] lemma ext ⦃η η' : applicative_transformation F G⦄ (h : ∀ (α : Type u) (x : F α), η x = η' x) : η = η' := by { apply coe_inj, ext1 α, exact funext (h α) } lemma ext_iff {η η' : applicative_transformation F G} : η = η' ↔ ∀ (α : Type u) (x : F α), η x = η' x := ⟨λ h α x, h ▸ rfl, λ h, ext h⟩ section preserves variables (η : applicative_transformation F G) @[functor_norm] lemma preserves_pure {α} : ∀ (x : α), η (pure x) = pure x := η.preserves_pure' @[functor_norm] lemma preserves_seq {α β : Type u} : ∀ (x : F (α → β)) (y : F α), η (x <*> y) = η x <*> η y := η.preserves_seq' @[functor_norm] lemma preserves_map {α β} (x : α → β) (y : F α) : η (x <$> y) = x <$> η y := by rw [← pure_seq_eq_map, η.preserves_seq]; simp with functor_norm lemma preserves_map' {α β} (x : α → β) : @η _ ∘ functor.map x = functor.map x ∘ @η _ := by { ext y, exact preserves_map η x y } end preserves /-- The identity applicative transformation from an applicative functor to itself. -/ def id_transformation : applicative_transformation F F := { app := λ α, id, preserves_pure' := by simp, preserves_seq' := λ α β x y, by simp } instance : inhabited (applicative_transformation F F) := ⟨id_transformation⟩ universes s t variables {H : Type u → Type s} [applicative H] [is_lawful_applicative H] /-- The composition of applicative transformations. -/ def comp (η' : applicative_transformation G H) (η : applicative_transformation F G) : applicative_transformation F H := { app := λ α x, η' (η x), preserves_pure' := λ α x, by simp with functor_norm, preserves_seq' := λ α β x y, by simp with functor_norm } @[simp] lemma comp_apply (η' : applicative_transformation G H) (η : applicative_transformation F G) {α : Type u} (x : F α) : η'.comp η x = η' (η x) := rfl lemma comp_assoc {I : Type u → Type t} [applicative I] [is_lawful_applicative I] (η'' : applicative_transformation H I) (η' : applicative_transformation G H) (η : applicative_transformation F G) : (η''.comp η').comp η = η''.comp (η'.comp η) := rfl @[simp] lemma comp_id (η : applicative_transformation F G) : η.comp id_transformation = η := ext $ λ α x, rfl @[simp] lemma id_comp (η : applicative_transformation F G) : id_transformation.comp η = η := ext $ λ α x, rfl end applicative_transformation open applicative_transformation /-- A traversable functor is a functor along with a way to commute with all applicative functors (see `sequence`). For example, if `t` is the traversable functor `list` and `m` is the applicative functor `io`, then given a function `f : α → io β`, the function `functor.map f` is `list α → list (io β)`, but `traverse f` is `list α → io (list β)`. -/ class traversable (t : Type u → Type u) extends functor t := (traverse : Π {m : Type u → Type u} [applicative m] {α β}, (α → m β) → t α → m (t β)) open functor export traversable (traverse) section functions variables {t : Type u → Type u} variables {m : Type u → Type v} [applicative m] variables {α β : Type u} variables {f : Type u → Type u} [applicative f] /-- A traversable functor commutes with all applicative functors. -/ def sequence [traversable t] : t (f α) → f (t α) := traverse id end functions /-- A traversable functor is lawful if its `traverse` satisfies a number of additional properties. It must send `id.mk` to `id.mk`, send the composition of applicative functors to the composition of the `traverse` of each, send each function `f` to `λ x, f <$> x`, and satisfy a naturality condition with respect to applicative transformations. -/ class is_lawful_traversable (t : Type u → Type u) [traversable t] extends is_lawful_functor t : Type (u+1) := (id_traverse : ∀ {α} (x : t α), traverse id.mk x = x ) (comp_traverse : ∀ {F G} [applicative F] [applicative G] [is_lawful_applicative F] [is_lawful_applicative G] {α β γ} (f : β → F γ) (g : α → G β) (x : t α), traverse (comp.mk ∘ map f ∘ g) x = comp.mk (map (traverse f) (traverse g x))) (traverse_eq_map_id : ∀ {α β} (f : α → β) (x : t α), traverse (id.mk ∘ f) x = id.mk (f <$> x)) (naturality : ∀ {F G} [applicative F] [applicative G] [is_lawful_applicative F] [is_lawful_applicative G] (η : applicative_transformation F G) {α β} (f : α → F β) (x : t α), η (traverse f x) = traverse (@η _ ∘ f) x) instance : traversable id := ⟨λ _ _ _ _, id⟩ instance : is_lawful_traversable id := by refine {..}; intros; refl section variables {F : Type u → Type v} [applicative F] instance : traversable option := ⟨@option.traverse⟩ instance : traversable list := ⟨@list.traverse⟩ end namespace sum variables {σ : Type u} variables {F : Type u → Type u} variables [applicative F] /-- Defines a `traverse` function on the second component of a sum type. This is used to give a `traversable` instance for the functor `σ ⊕ -`. -/ protected def traverse {α β} (f : α → F β) : σ ⊕ α → F (σ ⊕ β) | (sum.inl x) := pure (sum.inl x) | (sum.inr x) := sum.inr <$> f x end sum instance {σ : Type u} : traversable.{u} (sum σ) := ⟨@sum.traverse _⟩
2385dcecb1db5beffc4da321be856a97ab29ae05
ce6917c5bacabee346655160b74a307b4a5ab620
/src/ch3/ex0101.lean
d7784d48f8c6f50d083e14c770a0c50a18686a5a
[]
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
264
lean
-- constant and : Prop → Prop → Prop -- constant or : Prop → Prop → Prop -- constant not : Prop → Prop → Prop -- constant implies : Prop → Prop → Prop variables p q r : Prop #check and p q #check or (and p q) r #check implies (and p q) (and q p)
3d94b570226572907ee6f5168ae377ee5a3779b7
35677d2df3f081738fa6b08138e03ee36bc33cad
/src/topology/uniform_space/completion.lean
d119492ab07006fc257dc12ff6d5daec41d802e3
[ "Apache-2.0" ]
permissive
gebner/mathlib
eab0150cc4f79ec45d2016a8c21750244a2e7ff0
cc6a6edc397c55118df62831e23bfbd6e6c6b4ab
refs/heads/master
1,625,574,853,976
1,586,712,827,000
1,586,712,827,000
99,101,412
1
0
Apache-2.0
1,586,716,389,000
1,501,667,958,000
Lean
UTF-8
Lean
false
false
23,306
lean
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl Hausdorff completions of uniform spaces. The goal is to construct a left-adjoint to the inclusion of complete Hausdorff uniform spaces into all uniform spaces. Any uniform space `α` gets a completion `completion α` and a morphism (ie. uniformly continuous map) `completion : α → completion α` which solves the universal mapping problem of factorizing morphisms from `α` to any complete Hausdorff uniform space `β`. It means any uniformly continuous `f : α → β` gives rise to a unique morphism `completion.extension f : completion α → β` such that `f = completion.extension f ∘ completion α`. Actually `completion.extension f` is defined for all maps from `α` to `β` but it has the desired properties only if `f` is uniformly continuous. Beware that `completion α` is not injective if `α` is not Hausdorff. But its image is always dense. The adjoint functor acting on morphisms is then constructed by the usual abstract nonsense. For every uniform spaces `α` and `β`, it turns `f : α → β` into a morphism `completion.map f : completion α → completion β` such that `coe ∘ f = (completion.map f) ∘ coe` provided `f` is uniformly continuous. This construction is compatible with composition. In this file we introduce the following concepts: * `Cauchy α` the uniform completion of the uniform space `α` (using Cauchy filters). These are not minimal filters. * `completion α := quotient (separation_setoid (Cauchy α))` the Hausdorff completion. This formalization is mostly based on N. Bourbaki: General Topology I. M. James: Topologies and Uniformities From a slightly different perspective in order to reuse material in topology.uniform_space.basic. -/ import data.set.basic import topology.uniform_space.abstract_completion topology.uniform_space.separation noncomputable theory open filter set universes u v w x open_locale uniformity classical topological_space /-- Space of Cauchy filters This is essentially the completion of a uniform space. The embeddings are the neighbourhood filters. This space is not minimal, the separated uniform space (i.e. quotiented on the intersection of all entourages) is necessary for this. -/ def Cauchy (α : Type u) [uniform_space α] : Type u := { f : filter α // cauchy f } namespace Cauchy section parameters {α : Type u} [uniform_space α] variables {β : Type v} {γ : Type w} variables [uniform_space β] [uniform_space γ] def gen (s : set (α × α)) : set (Cauchy α × Cauchy α) := {p | s ∈ filter.prod (p.1.val) (p.2.val) } 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 ((𝓤 α).lift' gen) ≤ (𝓤 α).lift' gen := calc map prod.swap ((𝓤 α).lift' gen) = (𝓤 α).lift' (λs:set (α×α), {p | s ∈ filter.prod (p.2.val) (p.1.val) }) : begin delta gen, simp [map_lift'_eq, monotone_set_of, monotone_mem_sets, function.comp, image_swap_eq_preimage_swap] end ... ≤ (𝓤 α).lift' gen : uniformity_lift_le_swap (monotone_principal.comp (monotone_set_of $ assume p, @monotone_mem_sets (α×α) ((filter.prod ((p.2).val) ((p.1).val))))) begin have h := λ(p:Cauchy α×Cauchy α), @filter.prod_comm _ _ (p.2.val) (p.1.val), simp [function.comp, h], 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), t₂, (ht₂ : t₂ ∈ h.val), (h₁ : set.prod t₁ t₂ ⊆ s)⟩ := mem_prod_iff.mp h₁ in let ⟨t₃, (ht₃ : t₃ ∈ h.val), t₄, (ht₄ : t₄ ∈ g.val), (h₂ : set.prod t₃ t₄ ⊆ t)⟩ := mem_prod_iff.mp h₂ in have t₂ ∩ t₃ ∈ h.val, from inter_mem_sets ht₂ ht₃, let ⟨x, xt₂, xt₃⟩ := nonempty_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 : ((𝓤 α).lift' gen).lift' (λs, comp_rel s s) ≤ (𝓤 α).lift' gen := calc ((𝓤 α).lift' gen).lift' (λs, comp_rel s s) = (𝓤 α).lift' (λs, comp_rel (gen s) (gen s)) : begin rw [lift'_lift'_assoc], exact monotone_gen, exact (monotone_comp_rel monotone_id monotone_id) end ... ≤ (𝓤 α).lift' (λs, gen $ comp_rel s s) : lift'_mono' $ assume s hs, comp_rel_gen_gen_subset_gen_comp_rel ... = ((𝓤 α).lift' $ λs:set(α×α), comp_rel s s).lift' gen : begin rw [lift'_lift'_assoc], exact (monotone_comp_rel monotone_id monotone_id), exact monotone_gen end ... ≤ (𝓤 α).lift' gen : lift'_mono comp_le_uniformity (le_refl _) instance : uniform_space (Cauchy α) := uniform_space.of_core { uniformity := (𝓤 α).lift' gen, refl := principal_le_lift' $ assume s hs ⟨a, b⟩ (a_eq_b : a = b), a_eq_b ▸ a.property.right hs, symm := symm_gen, comp := comp_gen } theorem mem_uniformity {s : set (Cauchy α × Cauchy α)} : s ∈ 𝓤 (Cauchy α) ↔ ∃ t ∈ 𝓤 α, gen t ⊆ s := mem_lift'_sets monotone_gen theorem mem_uniformity' {s : set (Cauchy α × Cauchy α)} : s ∈ 𝓤 (Cauchy α) ↔ ∃ t ∈ 𝓤 α, ∀ f g : Cauchy α, t ∈ filter.prod f.1 g.1 → (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_inducing_pure_cauchy : uniform_inducing (pure_cauchy : α → Cauchy α) := ⟨have (preimage (λ (x : α × α), (pure_cauchy (x.fst), pure_cauchy (x.snd))) ∘ gen) = id, from funext $ assume s, set.ext $ assume ⟨a₁, a₂⟩, by simp [preimage, gen, pure_cauchy, prod_principal_principal], calc comap (λ (x : α × α), (pure_cauchy (x.fst), pure_cauchy (x.snd))) ((𝓤 α).lift' gen) = (𝓤 α).lift' (preimage (λ (x : α × α), (pure_cauchy (x.fst), pure_cauchy (x.snd))) ∘ gen) : comap_lift'_eq monotone_gen ... = 𝓤 α : by simp [this]⟩ lemma uniform_embedding_pure_cauchy : uniform_embedding (pure_cauchy : α → Cauchy α) := { inj := assume a₁ a₂ h, pure_inj $ subtype.ext.1 h, ..uniform_inducing_pure_cauchy } lemma pure_cauchy_dense : ∀x, x ∈ closure (range pure_cauchy) := assume f, have h_ex : ∀ s ∈ 𝓤 (Cauchy α), ∃y:α, (f, pure_cauchy y) ∈ s, from assume s hs, let ⟨t'', ht''₁, (ht''₂ : gen t'' ⊆ s)⟩ := (mem_lift'_sets monotone_gen).mp hs in let ⟨t', ht'₁, ht'₂⟩ := comp_mem_uniformity_sets ht''₁ in have t' ∈ filter.prod (f.val) (f.val), 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)⟩ := nonempty_of_mem_sets f.property.left ht in have t'' ∈ filter.prod f.val (pure x), from mem_prod_iff.mpr ⟨t, ht, {y:α | (x, y) ∈ t'}, h $ mk_mem_prod hx hx, assume ⟨a, b⟩ ⟨(h₁ : a ∈ t), (h₂ : (x, b) ∈ t')⟩, ht'₂ $ prod_mk_mem_comp_rel (@h (a, x) ⟨h₁, hx⟩) h₂⟩, ⟨x, ht''₂ $ by dsimp [gen]; exact this⟩, begin simp [closure_eq_nhds, nhds_eq_uniformity, lift'_inf_principal_eq, set.inter_comm], exact (lift'_ne_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⟩, ⟨_, this⟩) end lemma dense_inducing_pure_cauchy : dense_inducing pure_cauchy := uniform_inducing_pure_cauchy.dense_inducing pure_cauchy_dense lemma dense_embedding_pure_cauchy : dense_embedding pure_cauchy := uniform_embedding_pure_cauchy.dense_embedding pure_cauchy_dense lemma nonempty_Cauchy_iff : nonempty (Cauchy α) ↔ nonempty α := begin split ; rintro ⟨c⟩, { have := eq_univ_iff_forall.1 dense_embedding_pure_cauchy.to_dense_inducing.closure_range c, obtain ⟨_, ⟨_, a, _⟩⟩ := mem_closure_iff.1 this _ is_open_univ trivial, exact ⟨a⟩ }, { exact ⟨pure_cauchy c⟩ } end section set_option eqn_compiler.zeta true instance : complete_space (Cauchy α) := complete_space_extension uniform_inducing_pure_cauchy pure_cauchy_dense $ assume f hf, let f' : Cauchy α := ⟨f, hf⟩ in have map pure_cauchy f ≤ (𝓤 $ Cauchy α).lift' (preimage (prod.mk f')), from le_lift' $ assume s hs, let ⟨t, ht₁, (ht₂ : gen t ⊆ s)⟩ := (mem_lift'_sets monotone_gen).mp hs in let ⟨t', ht', (h : 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' hx) h, f.sets_of_superset ht' $ subset.trans this (preimage_mono ht₂), ⟨f', by simp [nhds_eq_uniformity]; assumption⟩ end instance [inhabited α] : inhabited (Cauchy α) := ⟨pure_cauchy $ default α⟩ instance [h : nonempty α] : nonempty (Cauchy α) := h.rec_on $ assume a, nonempty.intro $ Cauchy.pure_cauchy a section extend def extend (f : α → β) : (Cauchy α → β) := if uniform_continuous f then dense_inducing_pure_cauchy.extend f else λ x, f (classical.inhabited_of_nonempty $ nonempty_Cauchy_iff.1 ⟨x⟩).default variables [separated β] lemma extend_pure_cauchy {f : α → β} (hf : uniform_continuous f) (a : α) : extend f (pure_cauchy a) = f a := begin rw [extend, if_pos hf], exact uniformly_extend_of_ind uniform_inducing_pure_cauchy pure_cauchy_dense hf _ end variables [_root_.complete_space β] lemma uniform_continuous_extend {f : α → β} : uniform_continuous (extend f) := begin by_cases hf : uniform_continuous f, { rw [extend, if_pos hf], exact uniform_continuous_uniformly_extend uniform_inducing_pure_cauchy pure_cauchy_dense hf }, { rw [extend, if_neg hf], exact uniform_continuous_of_const (assume a b, by congr) } end end extend end theorem Cauchy_eq {α : Type*} [inhabited α] [uniform_space α] [complete_space α] [separated α] {f g : Cauchy α} : lim f.1 = lim g.1 ↔ (f, g) ∈ separation_rel (Cauchy α) := begin split, { intros e s hs, rcases Cauchy.mem_uniformity'.1 hs with ⟨t, tu, ts⟩, apply ts, rcases comp_mem_uniformity_sets tu with ⟨d, du, dt⟩, refine mem_prod_iff.2 ⟨_, le_nhds_lim_of_cauchy f.2 (mem_nhds_right (lim f.1) du), _, le_nhds_lim_of_cauchy g.2 (mem_nhds_left (lim g.1) du), λ x h, _⟩, cases x with a b, cases h with h₁ h₂, rw ← e at h₂, exact dt ⟨_, h₁, h₂⟩ }, { intros H, refine separated_def.1 (by apply_instance) _ _ (λ t tu, _), rcases mem_uniformity_is_closed tu with ⟨d, du, dc, dt⟩, refine H {p | (lim p.1.1, lim p.2.1) ∈ t} (Cauchy.mem_uniformity'.2 ⟨d, du, λ f g h, _⟩), rcases mem_prod_iff.1 h with ⟨x, xf, y, yg, h⟩, have limc : ∀ (f : Cauchy α) (x ∈ f.1), lim f.1 ∈ closure x, { intros f x xf, rw closure_eq_nhds, exact ne_bot_of_le_ne_bot f.2.1 (le_inf (le_nhds_lim_of_cauchy f.2) (le_principal_iff.2 xf)) }, have := (closure_subset_iff_subset_of_is_closed dc).2 h, rw closure_prod_eq at this, refine dt (this ⟨_, _⟩); dsimp; apply limc; assumption } end section local attribute [instance] uniform_space.separation_setoid lemma injective_separated_pure_cauchy {α : Type*} [uniform_space α] [s : separated α] : function.injective (λa:α, ⟦pure_cauchy a⟧) | a b h := separated_def.1 s _ _ $ assume s hs, let ⟨t, ht, hts⟩ := by rw [← (@uniform_embedding_pure_cauchy α _).comap_uniformity, filter.mem_comap_sets] at hs; exact hs in have (pure_cauchy a, pure_cauchy b) ∈ t, from quotient.exact h t ht, @hts (a, b) this end end Cauchy local attribute [instance] uniform_space.separation_setoid open Cauchy set namespace uniform_space variables (α : Type*) [uniform_space α] variables {β : Type*} [uniform_space β] variables {γ : Type*} [uniform_space γ] instance complete_space_separation [h : complete_space α] : complete_space (quotient (separation_setoid α)) := ⟨assume f, assume hf : cauchy f, have cauchy (f.comap (λx, ⟦x⟧)), from cauchy_comap comap_quotient_le_uniformity hf $ comap_ne_bot_of_surj hf.left $ assume b, quotient.exists_rep _, let ⟨x, (hx : f.comap (λx, ⟦x⟧) ≤ 𝓝 x)⟩ := complete_space.complete this in ⟨⟦x⟧, calc f = map (λx, ⟦x⟧) (f.comap (λx, ⟦x⟧)) : (map_comap $ univ_mem_sets' $ assume b, quotient.exists_rep _).symm ... ≤ map (λx, ⟦x⟧) (𝓝 x) : map_mono hx ... ≤ _ : continuous_iff_continuous_at.mp uniform_continuous_quotient_mk.continuous _⟩⟩ /-- Hausdorff completion of `α` -/ def completion := quotient (separation_setoid $ Cauchy α) namespace completion instance [inhabited α] : inhabited (completion α) := by unfold completion; apply_instance @[priority 50] instance : uniform_space (completion α) := by dunfold completion ; apply_instance instance : complete_space (completion α) := by dunfold completion ; apply_instance instance : separated (completion α) := by dunfold completion ; apply_instance instance : t2_space (completion α) := separated_t2 instance : regular_space (completion α) := separated_regular /-- Automatic coercion from `α` to its completion. Not always injective. -/ instance : has_coe_t α (completion α) := ⟨quotient.mk ∘ pure_cauchy⟩ -- note [use has_coe_t] protected lemma coe_eq : (coe : α → completion α) = quotient.mk ∘ pure_cauchy := rfl lemma comap_coe_eq_uniformity : (𝓤 _).comap (λ(p:α×α), ((p.1 : completion α), (p.2 : completion α))) = 𝓤 α := begin have : (λx:α×α, ((x.1 : completion α), (x.2 : completion α))) = (λx:(Cauchy α)×(Cauchy α), (⟦x.1⟧, ⟦x.2⟧)) ∘ (λx:α×α, (pure_cauchy x.1, pure_cauchy x.2)), { ext ⟨a, b⟩; simp; refl }, rw [this, ← filter.comap_comap_comp], change filter.comap _ (filter.comap _ (𝓤 $ quotient $ separation_setoid $ Cauchy α)) = 𝓤 α, rw [comap_quotient_eq_uniformity, uniform_embedding_pure_cauchy.comap_uniformity] end lemma uniform_inducing_coe : uniform_inducing (coe : α → completion α) := ⟨comap_coe_eq_uniformity α⟩ variables {α} lemma dense : dense_range (coe : α → completion α) := begin rw [dense_range_iff_closure_range, completion.coe_eq, range_comp], exact quotient_dense_of_dense pure_cauchy_dense end variables (α) def cpkg {α : Type*} [uniform_space α] : abstract_completion α := { space := completion α, coe := coe, uniform_struct := by apply_instance, complete := by apply_instance, separation := by apply_instance, uniform_inducing := completion.uniform_inducing_coe α, dense := completion.dense } instance abstract_completion.inhabited : inhabited (abstract_completion α) := ⟨cpkg⟩ local attribute [instance] abstract_completion.uniform_struct abstract_completion.complete abstract_completion.separation lemma nonempty_completion_iff : nonempty (completion α) ↔ nonempty α := (dense_range.nonempty (cpkg.dense)).symm lemma uniform_continuous_coe : uniform_continuous (coe : α → completion α) := cpkg.uniform_continuous_coe lemma continuous_coe : continuous (coe : α → completion α) := cpkg.continuous_coe lemma uniform_embedding_coe [separated α] : uniform_embedding (coe : α → completion α) := { comap_uniformity := comap_coe_eq_uniformity α, inj := injective_separated_pure_cauchy } variable {α} lemma dense_inducing_coe : dense_inducing (coe : α → completion α) := { dense := dense, ..(uniform_inducing_coe α).inducing } lemma dense_embedding_coe [separated α]: dense_embedding (coe : α → completion α) := { inj := injective_separated_pure_cauchy, ..dense_inducing_coe } lemma dense₂ : dense_range (λx:α × β, ((x.1 : completion α), (x.2 : completion β))) := dense.prod dense lemma dense₃ : dense_range (λx:α × (β × γ), ((x.1 : completion α), ((x.2.1 : completion β), (x.2.2 : completion γ)))) := dense.prod dense₂ @[elab_as_eliminator] lemma induction_on {p : completion α → Prop} (a : completion α) (hp : is_closed {a | p a}) (ih : ∀a:α, p a) : p a := is_closed_property dense hp ih a @[elab_as_eliminator] lemma induction_on₂ {p : completion α → completion β → Prop} (a : completion α) (b : completion β) (hp : is_closed {x : completion α × completion β | p x.1 x.2}) (ih : ∀(a:α) (b:β), p a b) : p a b := have ∀x : completion α × completion β, p x.1 x.2, from is_closed_property dense₂ hp $ assume ⟨a, b⟩, ih a b, this (a, b) @[elab_as_eliminator] lemma induction_on₃ {p : completion α → completion β → completion γ → Prop} (a : completion α) (b : completion β) (c : completion γ) (hp : is_closed {x : completion α × completion β × completion γ | p x.1 x.2.1 x.2.2}) (ih : ∀(a:α) (b:β) (c:γ), p a b c) : p a b c := have ∀x : completion α × completion β × completion γ, p x.1 x.2.1 x.2.2, from is_closed_property dense₃ hp $ assume ⟨a, b, c⟩, ih a b c, this (a, b, c) lemma ext [t2_space β] {f g : completion α → β} (hf : continuous f) (hg : continuous g) (h : ∀a:α, f a = g a) : f = g := cpkg.funext hf hg h section extension variables {f : α → β} /-- "Extension" to the completion. It is defined for any map `f` but returns an arbitrary constant value if `f` is not uniformly continuous -/ protected def extension (f : α → β) : completion α → β := cpkg.extend f variables [separated β] @[simp] lemma extension_coe (hf : uniform_continuous f) (a : α) : (completion.extension f) a = f a := cpkg.extend_coe hf a variables [complete_space β] lemma uniform_continuous_extension : uniform_continuous (completion.extension f) := cpkg.uniform_continuous_extend lemma continuous_extension : continuous (completion.extension f) := cpkg.continuous_extend lemma extension_unique (hf : uniform_continuous f) {g : completion α → β} (hg : uniform_continuous g) (h : ∀ a : α, f a = g (a : completion α)) : completion.extension f = g := cpkg.extend_unique hf hg h @[simp] lemma extension_comp_coe {f : completion α → β} (hf : uniform_continuous f) : completion.extension (f ∘ coe) = f := cpkg.extend_comp_coe hf end extension section map variables {f : α → β} /-- Completion functor acting on morphisms -/ protected def map (f : α → β) : completion α → completion β := cpkg.map cpkg f lemma uniform_continuous_map : uniform_continuous (completion.map f) := cpkg.uniform_continuous_map cpkg f lemma continuous_map : continuous (completion.map f) := cpkg.continuous_map cpkg f @[simp] lemma map_coe (hf : uniform_continuous f) (a : α) : (completion.map f) a = f a := cpkg.map_coe cpkg hf a lemma map_unique {f : α → β} {g : completion α → completion β} (hg : uniform_continuous g) (h : ∀a:α, ↑(f a) = g a) : completion.map f = g := cpkg.map_unique cpkg hg h @[simp] lemma map_id : completion.map (@id α) = id := cpkg.map_id lemma extension_map [complete_space γ] [separated γ] {f : β → γ} {g : α → β} (hf : uniform_continuous f) (hg : uniform_continuous g) : completion.extension f ∘ completion.map g = completion.extension (f ∘ g) := completion.ext (continuous_extension.comp continuous_map) continuous_extension $ by intro a; simp only [hg, hf, hf.comp hg, (∘), map_coe, extension_coe] lemma map_comp {g : β → γ} {f : α → β} (hg : uniform_continuous g) (hf : uniform_continuous f) : completion.map g ∘ completion.map f = completion.map (g ∘ f) := extension_map ((uniform_continuous_coe _).comp hg) hf end map /- In this section we construct isomorphisms between the completion of a uniform space and the completion of its separation quotient -/ section separation_quotient_completion def completion_separation_quotient_equiv (α : Type u) [uniform_space α] : completion (separation_quotient α) ≃ completion α := begin refine ⟨completion.extension (separation_quotient.lift (coe : α → completion α)), completion.map quotient.mk, _, _⟩, { assume a, refine induction_on a (is_closed_eq (continuous_map.comp continuous_extension) continuous_id) _, rintros ⟨a⟩, show completion.map quotient.mk (completion.extension (separation_quotient.lift coe) ↑⟦a⟧) = ↑⟦a⟧, rw [extension_coe (separation_quotient.uniform_continuous_lift _), separation_quotient.lift_mk (uniform_continuous_coe α), completion.map_coe uniform_continuous_quotient_mk] ; apply_instance }, { assume a, refine completion.induction_on a (is_closed_eq (continuous_extension.comp continuous_map) continuous_id) _, assume a, rw [map_coe uniform_continuous_quotient_mk, extension_coe (separation_quotient.uniform_continuous_lift _), separation_quotient.lift_mk (uniform_continuous_coe α) _] ; apply_instance } end lemma uniform_continuous_completion_separation_quotient_equiv : uniform_continuous ⇑(completion_separation_quotient_equiv α) := uniform_continuous_extension lemma uniform_continuous_completion_separation_quotient_equiv_symm : uniform_continuous ⇑(completion_separation_quotient_equiv α).symm := uniform_continuous_map end separation_quotient_completion section extension₂ variables (f : α → β → γ) open function protected def extension₂ (f : α → β → γ) : completion α → completion β → γ := cpkg.extend₂ cpkg f variables [separated γ] {f} @[simp] lemma extension₂_coe_coe (hf : uniform_continuous $ uncurry' f) (a : α) (b : β) : completion.extension₂ f a b = f a b := cpkg.extension₂_coe_coe cpkg hf a b variables [complete_space γ] (f) lemma uniform_continuous_extension₂ : uniform_continuous₂ (completion.extension₂ f) := cpkg.uniform_continuous_extension₂ cpkg f end extension₂ section map₂ open function protected def map₂ (f : α → β → γ) : completion α → completion β → completion γ := cpkg.map₂ cpkg cpkg f lemma uniform_continuous_map₂ (f : α → β → γ) : uniform_continuous (uncurry' $ completion.map₂ f) := cpkg.uniform_continuous_map₂ cpkg cpkg f lemma continuous_map₂ {δ} [topological_space δ] {f : α → β → γ} {a : δ → completion α} {b : δ → completion β} (ha : continuous a) (hb : continuous b) : continuous (λd:δ, completion.map₂ f (a d) (b d)) := cpkg.continuous_map₂ cpkg cpkg ha hb lemma map₂_coe_coe (a : α) (b : β) (f : α → β → γ) (hf : uniform_continuous $ uncurry' f) : completion.map₂ f (a : completion α) (b : completion β) = f a b := cpkg.map₂_coe_coe cpkg cpkg a b f hf end map₂ end completion end uniform_space
f9b3af0ef9e7768e7d337bb37f078ab8f377963b
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/analysis/special_functions/compare_exp.lean
653f01558aa337e61d3c29d2f716d7e61cc8324d
[ "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
9,107
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 analysis.special_functions.pow import analysis.asymptotics.specific_asymptotics /-! # Growth estimates on `x ^ y` for complex `x`, `y` Let `l` be a filter on `ℂ` such that `complex.re` tends to infinity along `l` and `complex.im z` grows at a subexponential rate compared to `complex.re z`. Then - `complex.is_o_log_abs_re_of_subexponential_im_re`: `real.log ∘ complex.abs` is `o`-small of `complex.re` along `l`; - `complex.is_o_cpow_mul_exp`: $z^{a_1}e^{b_1 * z} = o\left(z^{a_1}e^{b_1 * z}\right)$ along `l` for any complex `a₁`, `a₂` and real `b₁ < b₂`. We use these assumptions on `l` for two reasons. First, these are the assumptions that naturally appear in the proof. Second, in some applications (e.g., in Ilyashenko's proof of the individual finiteness theorem for limit cycles of polynomial ODEs with hyperbolic singularities only) natural stronger assumptions (e.g., `im z` is bounded from below and from above) are not available. -/ open asymptotics filter function open_locale topological_space namespace complex /-- We say that `l : filter ℂ` is an *exponential comparison filter* if the real part tends to infinity along `l` and the imaginary part grows subexponentially compared to the real part. These properties guarantee that `(λ z, z ^ a₁ * exp (b₁ * z)) =o[l] (λ z, z ^ a₂ * exp (b₂ * z))` for any complex `a₁`, `a₂` and real `b₁ < b₂`. In particular, the second property is automatically satisfied if the imaginary part is bounded along `l`. -/ structure is_exp_cmp_filter (l : filter ℂ) : Prop := (tendsto_re : tendsto re l at_top) (is_O_im_pow_re : ∀ n : ℕ, (λ z : ℂ, z.im ^ n) =O[l] (λ z, real.exp z.re)) namespace is_exp_cmp_filter variables {l : filter ℂ} /-! ### Alternative constructors -/ lemma of_is_O_im_re_rpow (hre : tendsto re l at_top) (r : ℝ) (hr : im =O[l] (λ z, z.re ^ r)) : is_exp_cmp_filter l := ⟨hre, λ n, is_o.is_O $ calc (λ z : ℂ, z.im ^ n) =O[l] (λ z, (z.re ^ r) ^ n) : hr.pow n ... =ᶠ[l] (λ z, z.re ^ (r * n)) : (hre.eventually_ge_at_top 0).mono $ λ z hz, by simp only [real.rpow_mul hz r n, real.rpow_nat_cast] ... =o[l] (λ z, real.exp z.re) : (is_o_rpow_exp_at_top _).comp_tendsto hre⟩ lemma of_is_O_im_re_pow (hre : tendsto re l at_top) (n : ℕ) (hr : im =O[l] (λ z, z.re ^ n)) : is_exp_cmp_filter l := of_is_O_im_re_rpow hre n $ by simpa only [real.rpow_nat_cast] lemma of_bounded_under_abs_im (hre : tendsto re l at_top) (him : is_bounded_under (≤) l (λ z, |z.im|)) : is_exp_cmp_filter l := of_is_O_im_re_pow hre 0 $ by simpa only [pow_zero] using @is_bounded_under.is_O_const ℂ ℝ ℝ _ _ _ l him 1 one_ne_zero lemma of_bounded_under_im (hre : tendsto re l at_top) (him_le : is_bounded_under (≤) l im) (him_ge : is_bounded_under (≥) l im) : is_exp_cmp_filter l := of_bounded_under_abs_im hre $ is_bounded_under_le_abs.2 ⟨him_le, him_ge⟩ /-! ### Preliminary lemmas -/ lemma eventually_ne (hl : is_exp_cmp_filter l) : ∀ᶠ w : ℂ in l, w ≠ 0 := hl.tendsto_re.eventually_ne_at_top' _ lemma tendsto_abs_re (hl : is_exp_cmp_filter l) : tendsto (λ z : ℂ, |z.re|) l at_top := tendsto_abs_at_top_at_top.comp hl.tendsto_re lemma tendsto_abs (hl : is_exp_cmp_filter l) : tendsto abs l at_top := tendsto_at_top_mono abs_re_le_abs hl.tendsto_abs_re lemma is_o_log_re_re (hl : is_exp_cmp_filter l) : (λ z, real.log z.re) =o[l] re := real.is_o_log_id_at_top.comp_tendsto hl.tendsto_re lemma is_o_im_pow_exp_re (hl : is_exp_cmp_filter l) (n : ℕ) : (λ z : ℂ, z.im ^ n) =o[l] (λ z, real.exp z.re) := flip is_o.of_pow two_ne_zero $ calc (λ z : ℂ, (z.im ^ n) ^ 2) = (λ z, z.im ^ (2 * n)) : by simp only [pow_mul'] ... =O[l] (λ z, real.exp z.re) : hl.is_O_im_pow_re _ ... = (λ z, (real.exp z.re) ^ 1) : by simp only [pow_one] ... =o[l] (λ z, (real.exp z.re) ^ 2) : (is_o_pow_pow_at_top_of_lt one_lt_two).comp_tendsto $ real.tendsto_exp_at_top.comp hl.tendsto_re lemma abs_im_pow_eventually_le_exp_re (hl : is_exp_cmp_filter l) (n : ℕ) : (λ z : ℂ, |z.im| ^ n) ≤ᶠ[l] (λ z, real.exp z.re) := by simpa using (hl.is_o_im_pow_exp_re n).bound zero_lt_one /-- If `l : filter ℂ` is an "exponential comparison filter", then $\log |z| =o(ℜ z)$ along `l`. This is the main lemma in the proof of `complex.is_exp_cmp_filter.is_o_cpow_exp` below. -/ lemma is_o_log_abs_re (hl : is_exp_cmp_filter l) : (λ z, real.log (abs z)) =o[l] re := calc (λ z, real.log (abs z)) =O[l] (λ z, real.log (real.sqrt 2) + real.log (max z.re (|z.im|))) : is_O.of_bound 1 $ (hl.tendsto_re.eventually_ge_at_top 1).mono $ λ z hz, begin have h2 : 0 < real.sqrt 2, by simp, have hz' : 1 ≤ abs z, from hz.trans (re_le_abs z), have hz₀ : 0 < abs z, from one_pos.trans_le hz', have hm₀ : 0 < max z.re (|z.im|), from lt_max_iff.2 (or.inl $ one_pos.trans_le hz), rw [one_mul, real.norm_eq_abs, _root_.abs_of_nonneg (real.log_nonneg hz')], refine le_trans _ (le_abs_self _), rw [← real.log_mul, real.log_le_log, ← _root_.abs_of_nonneg (le_trans zero_le_one hz)], exacts [abs_le_sqrt_two_mul_max z, one_pos.trans_le hz', (mul_pos h2 hm₀), h2.ne', hm₀.ne'] end ... =o[l] re : is_o.add (is_o_const_left.2 $ or.inr $ hl.tendsto_abs_re) $ is_o_iff_nat_mul_le.2 $ λ n, begin filter_upwards [is_o_iff_nat_mul_le.1 hl.is_o_log_re_re n, hl.abs_im_pow_eventually_le_exp_re n, hl.tendsto_re.eventually_gt_at_top 1] with z hre him h₁, cases le_total (|z.im|) z.re with hle hle, { rwa [max_eq_left hle] }, { have H : 1 < |z.im|, from h₁.trans_le hle, rwa [max_eq_right hle, real.norm_eq_abs, real.norm_eq_abs, abs_of_pos (real.log_pos H), ← real.log_pow, real.log_le_iff_le_exp (pow_pos (one_pos.trans H) _), abs_of_pos (one_pos.trans h₁)] } end /-! ### Main results -/ /-- If `l : filter ℂ` is an "exponential comparison filter", then for any complex `a` and any positive real `b`, we have `(λ z, z ^ a) =o[l] (λ z, exp (b * z))`. -/ lemma is_o_cpow_exp (hl : is_exp_cmp_filter l) (a : ℂ) {b : ℝ} (hb : 0 < b) : (λ z, z ^ a) =o[l] (λ z, exp (b * z)) := calc (λ z, z ^ a) =Θ[l] λ z, abs z ^ re a : is_Theta_cpow_const_rpow $ λ _ _, hl.eventually_ne ... =ᶠ[l] λ z, real.exp (re a * real.log (abs z)) : hl.eventually_ne.mono $ λ z hz, by simp only [real.rpow_def_of_pos, abs.pos hz, mul_comm] ... =o[l] λ z, exp (b * z) : is_o.of_norm_right $ begin simp only [norm_eq_abs, abs_exp, of_real_mul_re, real.is_o_exp_comp_exp_comp], refine (is_equivalent.refl.sub_is_o _).symm.tendsto_at_top (hl.tendsto_re.const_mul_at_top hb), exact (hl.is_o_log_abs_re.const_mul_left _).const_mul_right hb.ne' end /-- If `l : filter ℂ` is an "exponential comparison filter", then for any complex `a₁`, `a₂` and any real `b₁ < b₂`, we have `(λ z, z ^ a₁ * exp (b₁ * z)) =o[l] (λ z, z ^ a₂ * exp (b₂ * z))`. -/ lemma is_o_cpow_mul_exp {b₁ b₂ : ℝ} (hl : is_exp_cmp_filter l) (hb : b₁ < b₂) (a₁ a₂ : ℂ) : (λ z, z ^ a₁ * exp (b₁ * z)) =o[l] (λ z, z ^ a₂ * exp (b₂ * z)) := calc (λ z, z ^ a₁ * exp (b₁ * z)) =ᶠ[l] (λ z, z ^ a₂ * exp (b₁ * z) * z ^ (a₁ - a₂)) : hl.eventually_ne.mono $ λ z hz, by { simp only, rw [mul_right_comm, ← cpow_add _ _ hz, add_sub_cancel'_right] } ... =o[l] λ z, z ^ a₂ * exp (b₁ * z) * exp (↑(b₂ - b₁) * z) : (is_O_refl (λ z, z ^ a₂ * exp (b₁ * z)) l).mul_is_o $ hl.is_o_cpow_exp _ (sub_pos.2 hb) ... =ᶠ[l] λ z, z ^ a₂ * exp (b₂ * z) : by simp only [of_real_sub, sub_mul, mul_assoc, ← exp_add, add_sub_cancel'_right] /-- If `l : filter ℂ` is an "exponential comparison filter", then for any complex `a` and any negative real `b`, we have `(λ z, exp (b * z)) =o[l] (λ z, z ^ a)`. -/ lemma is_o_exp_cpow (hl : is_exp_cmp_filter l) (a : ℂ) {b : ℝ} (hb : b < 0) : (λ z, exp (b * z)) =o[l] (λ z, z ^ a) := by simpa using hl.is_o_cpow_mul_exp hb 0 a /-- If `l : filter ℂ` is an "exponential comparison filter", then for any complex `a₁`, `a₂` and any natural `b₁ < b₂`, we have `(λ z, z ^ a₁ * exp (b₁ * z)) =o[l] (λ z, z ^ a₂ * exp (b₂ * z))`. -/ lemma is_o_pow_mul_exp {b₁ b₂ : ℝ} (hl : is_exp_cmp_filter l) (hb : b₁ < b₂) (m n : ℕ) : (λ z, z ^ m * exp (b₁ * z)) =o[l] (λ z, z ^ n * exp (b₂ * z)) := by simpa only [cpow_nat_cast] using hl.is_o_cpow_mul_exp hb m n /-- If `l : filter ℂ` is an "exponential comparison filter", then for any complex `a₁`, `a₂` and any integer `b₁ < b₂`, we have `(λ z, z ^ a₁ * exp (b₁ * z)) =o[l] (λ z, z ^ a₂ * exp (b₂ * z))`. -/ lemma is_o_zpow_mul_exp {b₁ b₂ : ℝ} (hl : is_exp_cmp_filter l) (hb : b₁ < b₂) (m n : ℤ) : (λ z, z ^ m * exp (b₁ * z)) =o[l] (λ z, z ^ n * exp (b₂ * z)) := by simpa only [cpow_int_cast] using hl.is_o_cpow_mul_exp hb m n end is_exp_cmp_filter end complex
9dcdd2e600fb448794e0d601d0658c5e80d98735
856e2e1615a12f95b551ed48fa5b03b245abba44
/src/computability/is_odd.lean
043780d5dc802dd55da7482ad177b1b4d9242f02
[ "Apache-2.0" ]
permissive
pimsp/mathlib
8b77e1ccfab21703ba8fbe65988c7de7765aa0e5
913318ca9d6979686996e8d9b5ebf7e74aae1c63
refs/heads/master
1,669,812,465,182
1,597,133,610,000
1,597,133,610,000
281,890,685
1
0
null
1,595,491,577,000
1,595,491,576,000
null
UTF-8
Lean
false
false
13,666
lean
import tactic import data.list import data.list.basic import .problem namespace tm2program open turing.TM2 open turing.TM2.stmt open problem section inductive K₀ | t1 | t2 parameters {K : Type*} [decidable_eq K] -- Index type of stacks parameters (lK : K₀ → K) parameters (k₀ : K) -- input stack parameters (k₁ : K) -- output stack parameters (k₂ : K) -- call stack parameters (h₀₂: k₀ ≠ k₂) -- input stack is not the call stack @[derive decidable_eq] inductive vars₀ | temp open vars₀ parameters {vars : Type} [decidable_eq vars] parameters (lv : vars₀ → vars) inductive Λ₀ | copy_rec ( f : K ) ( t : K ) ( n : fin 2 ) | copy_rec₂ ( f : K ) ( t : K ) ( n : fin 1 ) | pop_rec ( t : K ) ( n : fin 1 ) | list_head ( f : K ) ( t : K ) ( n : fin 2 ) | nat_to_list₂ ( f : K ) ( t : K ) ( n : fin 1 ) open Λ₀ parameters (Λ : Type) -- Type of function labels parameters (lΛ : Λ₀ → Λ) def σ := (vars → option Γ') × Λ /- inductive stmt | push : ∀ k, (σ → Γ k) → stmt → stmt | peek : ∀ k, (σ → option (Γ k) → σ) → stmt → stmt | pop : ∀ k, (σ → option (Γ k) → σ) → stmt → stmt | load : (σ → σ) → stmt → stmt | branch : (σ → bool) → stmt → stmt → stmt | goto : (σ → Λ) → stmt | halt : stmt open stmt -/ -- inductive Γ' | blank | bit0 | bit1 | left | right | comma def Γ: K → Type := λ k, if k = k₂ then Λ else Γ' def stmt' := turing.TM2.stmt Γ Λ σ --inductive Γ' | blank | bit0 | bit1 | bra | ket | comma /-def set_var : vars₀ → σ → option Γ' → σ := λ v f s x, if lv v = x then s else f x def get_var : vars₀ → Γ' → σ → Γ' := λ v d f, option.cases_on (f(lv v)) d (λ x, x) def get_var' : vars₀ → σ → Γ' := λ v, get_var v Γ'.blank def ignore : σ → option Γ' → σ := λ f _, f def goto' : Λ₀ → stmt' := λ l, goto (λ _, lΛ (l) ) def var_eq : vars₀ → Γ' → σ → bool := λ v x f, f (lv v) = x def var_undef : vars₀ → σ → bool := λ v f, f (lv v) = none-/ --attribute [class] ne /-lemma ne_call_stack {k:K} (h:k≠k₂): Γ k = Γ' := begin change (if k = k₂ then Λ else Γ') = Γ', simp [h], end def push_const {k:K} (h:k≠k₂) : Γ' → stmt' → stmt' := λ g e, push k ( λ σ, begin rw ne_call_stack k₂ Λ h, exact g, end ) e def pop' {k:K} (h:k≠k₂) : (σ → option Γ' → σ) → stmt' → stmt' := λ f e, pop k begin rw ne_call_stack k₂ Λ h, exact f, end e -/ -- rec_list namespace rec_list @[derive inhabited] inductive rec_list | empty : rec_list | string : list(bool) → rec_list → rec_list | sublist : rec_list → rec_list → rec_list def string_to_bits : list bool → list Γ' := list.map (λ b:bool, ite b Γ'.bit1 Γ'.bit0 ) def bits_to_string : list Γ' → list bool := list.map (λ c:Γ', c = Γ'.bit1 ) @[simp] lemma string_to_bits_to_string (l:list bool): bits_to_string ( string_to_bits l) = l := begin let f : bool → Γ' := (λ b:bool, ite b Γ'.bit1 Γ'.bit0 ), let g : Γ' → bool := (λ c:Γ', c = Γ'.bit1 ), have h : g ∘ f = id, ext, induction x, repeat {refl}, change list.map g ( list.map f l ) = l, simp [h], end def symbol_sign : Γ' → ℤ | Γ'.bra := 1 | Γ'.ket := -1 | _ := 0 def stack_depth : list Γ' → list ℤ := list.scanl (λ d g, d + symbol_sign g) 0 def index_of_comma₁ : list Γ' → ℕ := λ l, (l.zip (stack_depth l)).index_of (Γ'.comma,0) def pop_ends : list Γ' → list Γ' := λ l, l.tail.reverse.tail.reverse def split_stack₁ : list Γ' → list Γ' × list Γ' := λ l, if index_of_comma₁ l ≥ l.length then ⟨[],[]⟩ else l.split_at $ index_of_comma₁ l def split_stackₐ' : list Γ' → list(list(Γ'×ℤ)) := λ l, (l.zip (stack_depth l)).split_on (Γ'.comma,0) def split_stackₐ : list Γ' → list(list(Γ')) := λ l₁, list.map ( λ l₂, list.map ( λ x:Γ'×ℤ, x.1 ) l₂ ) $ split_stackₐ' l₁ lemma pop_ends_size (l: list Γ'): (pop_ends l).length + 2 = l.length ∨ (pop_ends l).length = 0 := begin change l.tail.reverse.tail.reverse.length + 2 = l.length ∨ l.tail.reverse.tail.reverse.length = 0, cases l with hd l2, { right, trivial, }, change l2.reverse.tail.reverse.length + 2 = l2.length+1 ∨ l2.reverse.tail.reverse.length = 0, suffices h: l2.reverse.tail.reverse.length + 2 = l2.reverse.length+1 ∨ l2.reverse.tail.reverse.length = 0, { cases h, left, repeat { rw list.length_reverse at h }, rw list.length_reverse, exact h, right, rw list.length_reverse, exact h, }, cases l2.reverse with tl l3, right, trivial, left, simp, end lemma take_sublist {α} (l:list α): ∀ n, l.take n <+ l := begin induction l with x xs xh, { simp, }, intro n, induction n with n nh, { simp, }, change x :: (xs.take n) <+ x :: xs, apply list.sublist.cons2, exact xh n, end lemma split_sublist₁ {α} (l:list α) (n:ℕ): (l.split_at n).1 <+ l := begin rw list.split_at_eq_take_drop, change l.take n <+ l, exact take_sublist l n, end lemma split_sublist₂ {α} (l:list α): ∀ n, (l.split_at n).2 <+ l := begin induction l with x xs xh, { simp, }, intro n, induction n with n nh, { simp, }, have q: (list.split_at n.succ (x :: xs)).2 = (list.split_at n xs).2, simp, rw q, apply list.sublist.cons, exact xh n, end lemma sizeof_sublist {α} [has_sizeof α] (l l':list α): l <+ l' → l.sizeof ≤ l'.sizeof := begin intro h, induction h, { trivial, }, { apply le_trans h_ih, change h_l₂.sizeof ≤ 1 + (sizeof h_a) + h_l₂.sizeof, linarith, }, change 1 + (sizeof h_a) + h_l₁.sizeof ≤ 1 + (sizeof h_a) + h_l₂.sizeof, linarith, end lemma sizeof_sublist_eq {α} [has_sizeof α]: ∀ (l' l:list α), l <+ l' → l.sizeof = l'.sizeof → l=l' := begin have hl: ∀ li : list α, li.sizeof > 0, { intro li, induction li with x xs hx, { change 1 > 0, linarith, }, change 1 + (sizeof x) + xs.sizeof ≥ 1, linarith, }, sorry, end lemma asj {α} (l l':list α): l <+ l' → l.length = l'.length → l=l' := begin intros h h', exact list.eq_of_sublist_of_length_eq h h', end lemma take_oob {α} (l:list α): ∀ n : ℕ, (l.take n) = l → n ≥ l.length := begin induction l with x xs xh, simp, intro n, cases n, simp, intro h, change n+1≥ xs.length+1, refine add_le_add _ (le_refl 1), apply xh, apply (list.cons_inj x).mp, exact h, end lemma split_oob {α} (l:list α): ∀ n : ℕ, (l.split_at n).1 = l → n ≥ l.length := begin intros n h, apply take_oob, simp only [list.split_at_eq_take_drop] at h, exact h, end lemma split_stack_dec₁ (l:list Γ') (hl:l≠[]): (split_stack₁ l).1.sizeof < l.sizeof := begin have ss: (split_stack₁ l).1 <+ l, { change (if index_of_comma₁ l ≥ l.length then ([],[]) else l.split_at $ index_of_comma₁ l).1 <+ l, by_cases c : index_of_comma₁ l ≥ l.length, { rw if_pos c, simp, }, { rw if_neg c, exact split_sublist₁ l (index_of_comma₁ l), } }, refine lt_iff_le_and_ne.mpr _, split, { refine sizeof_sublist _ _ ss, }, change (if index_of_comma₁ l ≥ l.length then ([],[]) else l.split_at $ index_of_comma₁ l).1.sizeof ≠ l.sizeof, by_cases c : index_of_comma₁ l ≥ l.length, { rw if_pos c, change list.nil.sizeof ≠ l.sizeof, intro e, apply hl, symmetry, refine sizeof_sublist_eq _ _ _ e, simp, }, { rw if_neg c, intro e, apply c, clear c, apply split_oob, apply sizeof_sublist_eq, exact split_sublist₁ _ _, exact e, } end lemma split_stack_dec₂ (l:list Γ') (h:l≠[]): (split_stack₁ l).2.sizeof < l.sizeof := begin sorry, end def rec_list_to_stack : rec_list → list Γ' | (rec_list.empty) := [] | (rec_list.sublist l' l) := ([Γ'.bra]++rec_list_to_stack l'++[Γ'.ket])++(Γ'.comma::rec_list_to_stack l) | (rec_list.string b l) := (string_to_bits b)++(Γ'.comma::rec_list_to_stack l) def stack_to_rec_list' : list Γ' → rec_list | [] := rec_list.empty | (Γ'.bra::l) := have (pop_ends (split_stack₁ l).fst).sizeof < 1 + 1 + l.sizeof, { suffices h: (split_stack₁ l).fst.sizeof < l.sizeof, { } }, have (split_stack₁ l).snd.sizeof < 1 + 1 + l.sizeof, { cases l, { change list.nil.sizeof < 1 + 1 + list.nil.sizeof, linarith, }, let h := split_stack_dec₂ (l_hd::l_tl) _, linarith, simp, }, rec_list.sublist (stack_to_rec_list' $ pop_ends (split_stack₁ l).1) $ stack_to_rec_list' (split_stack₁ l).2 | (list.cons a l) := have (split_stack₁ (a :: l)).snd.sizeof < 1 + a.sizeof + l.sizeof, { let l' := (list.cons a l), have h: l' ≠ [], simp [l'], have hs: l'.sizeof = 1+ a.sizeof + l.sizeof, trivial, rw ← hs, exact split_stack_dec₂ l' h, }, rec_list.string (bits_to_string (split_stack₁ (a::l)).1) $ stack_to_rec_list' (split_stack₁ (a::l)).2 -- edge case elimination def no_call_stack: K → K := λ k, if k=k₂ then k₀ else k include h₀₂ lemma no_call_stack_elim (k:K): Γ ( no_call_stack k ) = Γ' := begin change (if (if k=k₂ then k₀ else k) = k₂ then Λ else Γ') = Γ', cases _inst_1 k k₂ with h h, simp [h], exact if_neg h₀₂, end def no_option: option Γ' → Γ' := λ l, option.cases_on l Γ'.blank id -- syntactic sugar def push_const: K → Γ' → stmt' → stmt' := λ k g e, push (no_call_stack k) (λ f,by{ rw no_call_stack_elim _ _ h₀₂, use g,}) e def push_var: K → vars → stmt' → stmt' := λ k v e, push (no_call_stack k) (λ f,by{ rw no_call_stack_elim _ _ h₀₂, use no_option _ _ h₀₂ (f.1 v),}) e def discard: K → stmt' → stmt' := λ k e, pop k (λ f g, f) e def pop_var: K → vars → stmt' → stmt' := λ k v e, pop (no_call_stack k) (λ f g, (λ w, if v = w then by{ rw ← no_call_stack_elim _ _ h₀₂, use g, } else f.1 w, f.2)) e def goto' : Λ₀ → stmt' := λ l, goto (λ _, lΛ (l) ) def var_eq_const : vars → Γ' → σ → bool := λ v x f, f.1 v = x def var_undef : vars → σ → bool := λ v f, f.1 v = none def call : Λ → Λ → stmt' := λ a b, push k₂ (λ f, begin change (if k₂ = k₂ then Λ else Γ'), simp, use b, end) $ goto (λ _, a) def return : stmt' := pop k₂ begin intros f g, change option (if k₂ = k₂ then Λ else Γ') at g, simp at g, cases g, use f, use (f.1,g), end $ goto (λ f, f.2) -- programs def func_nat_to_list₂ (f:K) (t:K): ℕ → stmt Γ Λ σ | 0 := push_const t Γ'.comma $ push_const t Γ'.ket $ goto' $ nat_to_list₂ f t 1 | _ := pop_var f (lv temp) $ branch (var_eq_const (lv temp) Γ'.comma) ( push_const t Γ'.bra $ return ) ( push_const t Γ'.comma $ push_var t (lv temp) $ goto' $ nat_to_list₂ f t 1 ) /-def func_nat_to_list₂ (f:K) (t:K) (t₂:t≠k₂) (f₂:f≠k₂): ℕ → stmt Γ Λ σ | 0 := push_const t₂ Γ'.comma $ push_const t₂ Γ'.ket $ goto' $ nat_to_list₂ f t 1 | _ := pop' f₂ (set_var temp) $ branch (var_eq temp Γ'.comma) ( push_const t₂ Γ'.bra $ halt ) ( push_const t₂ Γ'.comma $ push_var t₂ temp $ goto' $ nat_to_list₂ f t 1 ) -/ -- f = t is not allowed, reverses def func_copy_rec₂ (f : K) (t : K): ℕ → stmt Γ Λ σ | 0 := push_const (lK K₀.t1) Γ'.comma $ goto' $ copy_rec₂ f t 1 | _ := pop_var f (lv temp) $ branch (var_eq_const (lv temp) Γ'.bra) ( push_const t Γ'.ket $ push_const t Γ'.comma $ push_const (lK K₀.t1) Γ'.bit1 $ goto' $ copy_rec₂ f t 1 ) $ branch (var_eq_const (lv temp) Γ'.ket) ( discard t $ push_const t Γ'.bra $ discard (lK K₀.t1) $ goto' $ copy_rec₂ f t 1 ) $ branch (var_eq_const (lv temp) Γ'.comma) ( push_const t Γ'.comma $ pop_var (lK K₀.t1) (lv temp) $ branch (var_eq_const (lv temp) Γ'.bit1) ( goto' $ copy_rec₂ f t 1 ) $ return ) $ push_var t (lv temp) $ goto' $ copy_rec₂ f t 1 -- f = t is allowed, does not reverse def func_copy_rec (f : K) (t : K): ℕ → stmt Γ Λ σ | 0 := call (lΛ (copy_rec₂ f (lK K₀.t2) 0) ) (lΛ (copy_rec f t 1) ) | 1 := call (lΛ (copy_rec₂ (lK K₀.t2) t 0) ) (lΛ (copy_rec f t 2) ) | _ := return def func_pop_rec (f : K): ℕ → stmt Γ Λ σ | 0 := push_const (lK K₀.t1) Γ'.comma $ goto' $ pop_rec f 1 | _ := pop_var f (lv temp) $ branch (var_eq_const (lv temp) Γ'.bra) ( push_const (lK K₀.t1) Γ'.bit1 $ goto' $ pop_rec f 1 ) $ branch (var_eq_const (lv temp) Γ'.ket) ( discard (lK K₀.t1) $ goto' $ pop_rec f 1 ) $ branch (var_eq_const (lv temp) Γ'.comma) ( pop_var (lK K₀.t1) (lv temp) $ branch (var_eq_const (lv temp) Γ'.bit1) ( goto' $ pop_rec f 1 ) $ return ) $ goto' $ pop_rec f 1 /-def func_clear_stack (t : K): ℕ → stmt Γ Λ σ | _ := pop_var t (lv temp) $ branch (var_undef (lv temp)) return $ goto' $ clear_stack t 0-/ def func_list_head (f : K) (t : K): ℕ → stmt Γ Λ σ | 0 := discard f $ call (lΛ (copy_rec f t 0)) (lΛ (list_head f t 1)) | 1 := push_const f Γ'.bra $ call (lΛ (pop_rec f 0)) (lΛ (list_head f t 2)) | _ := return end end tm2program
5c5bc730dabba9c83f53aa62d7f8096a6e8c7239
35677d2df3f081738fa6b08138e03ee36bc33cad
/src/algebra/order_functions.lean
45afaad045ee5cd7471ecff3a6aafb1bede54582
[ "Apache-2.0" ]
permissive
gebner/mathlib
eab0150cc4f79ec45d2016a8c21750244a2e7ff0
cc6a6edc397c55118df62831e23bfbd6e6c6b4ab
refs/heads/master
1,625,574,853,976
1,586,712,827,000
1,586,712,827,000
99,101,412
1
0
Apache-2.0
1,586,716,389,000
1,501,667,958,000
Lean
UTF-8
Lean
false
false
13,223
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 algebra.ordered_group order.lattice universes u v variables {α : Type u} {β : Type v} attribute [simp] max_eq_left max_eq_right min_eq_left min_eq_right /-- A function `f` is strictly monotone if `a < b` implies `f a < f b`. -/ def strict_mono [has_lt α] [has_lt β] (f : α → β) : Prop := ∀ ⦃a b⦄, a < b → f a < f b namespace strict_mono open ordering function section variables [linear_order α] [preorder β] {f : α → β} lemma lt_iff_lt (H : strict_mono f) {a b} : f a < f b ↔ a < b := ⟨λ h, ((lt_trichotomy b a) .resolve_left $ λ h', lt_asymm h $ H h') .resolve_left $ λ e, ne_of_gt h $ congr_arg _ e, @H _ _⟩ lemma injective (H : strict_mono f) : injective f | a b e := ((lt_trichotomy a b) .resolve_left $ λ h, ne_of_lt (H h) e) .resolve_right $ λ h, ne_of_gt (H h) e theorem compares (H : strict_mono f) {a b} : ∀ {o}, compares o (f a) (f b) ↔ compares o a b | lt := H.lt_iff_lt | eq := ⟨λ h, H.injective h, congr_arg _⟩ | gt := H.lt_iff_lt lemma le_iff_le (H : strict_mono f) {a b} : f a ≤ f b ↔ a ≤ b := ⟨λ h, le_of_not_gt $ λ h', not_le_of_lt (H h') h, λ h, (lt_or_eq_of_le h).elim (λ h', le_of_lt (H h')) (λ h', h' ▸ le_refl _)⟩ end protected lemma nat {β} [preorder β] {f : ℕ → β} (h : ∀n, f n < f (n+1)) : strict_mono f := by { intros n m hnm, induction hnm with m' hnm' ih, apply h, exact lt.trans ih (h _) } -- `preorder α` isn't strong enough: if the preorder on α is an equivalence relation, -- then `strict_mono f` is vacuously true. lemma monotone [partial_order α] [preorder β] {f : α → β} (H : strict_mono f) : monotone f := λ a b h, (lt_or_eq_of_le h).rec (le_of_lt ∘ (@H _ _)) (by rintro rfl; refl) end strict_mono section open function variables [partial_order α] [partial_order β] {f : α → β} lemma strict_mono_of_monotone_of_injective (h₁ : monotone f) (h₂ : injective f) : strict_mono f := λ a b h, begin rw lt_iff_le_and_ne at ⊢ h, exact ⟨h₁ h.1, λ e, h.2 (h₂ e)⟩ end end section variables [decidable_linear_order α] [decidable_linear_order β] {f : α → β} {a b c d : α} -- translate from lattices to linear orders (sup → max, inf → min) @[simp] lemma le_min_iff : c ≤ min a b ↔ c ≤ a ∧ c ≤ b := le_inf_iff @[simp] lemma max_le_iff : max a b ≤ c ↔ a ≤ c ∧ b ≤ c := sup_le_iff lemma max_le_max : a ≤ c → b ≤ d → max a b ≤ max c d := sup_le_sup lemma min_le_min : a ≤ c → b ≤ d → min a b ≤ min c d := inf_le_inf lemma le_max_left_of_le : a ≤ b → a ≤ max b c := le_sup_left_of_le lemma le_max_right_of_le : a ≤ c → a ≤ max b c := le_sup_right_of_le lemma min_le_left_of_le : a ≤ c → min a b ≤ c := inf_le_left_of_le lemma min_le_right_of_le : b ≤ c → min a b ≤ c := inf_le_right_of_le lemma max_min_distrib_left : max a (min b c) = min (max a b) (max a c) := sup_inf_left lemma max_min_distrib_right : max (min a b) c = min (max a c) (max b c) := sup_inf_right lemma min_max_distrib_left : min a (max b c) = max (min a b) (min a c) := inf_sup_left lemma min_max_distrib_right : min (max a b) c = max (min a c) (min b c) := inf_sup_right lemma min_le_max : min a b ≤ max a b := le_trans (min_le_left a b) (le_max_left a b) instance max_idem : is_idempotent α max := by apply_instance -- short-circuit type class inference instance min_idem : is_idempotent α min := by apply_instance -- short-circuit type class inference @[simp] lemma min_le_iff : min a b ≤ c ↔ a ≤ c ∨ b ≤ c := have a ≤ b → (a ≤ c ∨ b ≤ c ↔ a ≤ c), from assume h, or_iff_left_of_imp $ le_trans h, have b ≤ a → (a ≤ c ∨ b ≤ c ↔ b ≤ c), from assume h, or_iff_right_of_imp $ le_trans h, by cases le_total a b; simp * @[simp] lemma le_max_iff : a ≤ max b c ↔ a ≤ b ∨ a ≤ c := have b ≤ c → (a ≤ b ∨ a ≤ c ↔ a ≤ c), from assume h, or_iff_right_of_imp $ assume h', le_trans h' h, have c ≤ b → (a ≤ b ∨ a ≤ c ↔ a ≤ b), from assume h, or_iff_left_of_imp $ assume h', le_trans h' h, by cases le_total b c; simp * @[simp] lemma max_lt_iff : max a b < c ↔ (a < c ∧ b < c) := by rw [lt_iff_not_ge]; simp [(≥), le_max_iff, not_or_distrib] @[simp] lemma lt_min_iff : a < min b c ↔ (a < b ∧ a < c) := by rw [lt_iff_not_ge]; simp [(≥), min_le_iff, not_or_distrib] @[simp] lemma lt_max_iff : a < max b c ↔ a < b ∨ a < c := by rw [lt_iff_not_ge]; simp [(≥), max_le_iff, not_and_distrib] @[simp] lemma min_lt_iff : min a b < c ↔ a < c ∨ b < c := by rw [lt_iff_not_ge]; simp [(≥), le_min_iff, not_and_distrib] lemma max_lt_max (h₁ : a < c) (h₂ : b < d) : max a b < max c d := by apply max_lt; simp [lt_max_iff, h₁, h₂] lemma min_lt_min (h₁ : a < c) (h₂ : b < d) : min a b < min c d := by apply lt_min; simp [min_lt_iff, h₁, h₂] theorem min_right_comm (a b c : α) : min (min a b) c = min (min a c) b := right_comm min min_comm min_assoc a b c theorem max.left_comm (a b c : α) : max a (max b c) = max b (max a c) := left_comm max max_comm max_assoc a b c theorem max.right_comm (a b c : α) : max (max a b) c = max (max a c) b := right_comm max max_comm max_assoc a b c lemma monotone.map_max (hf : monotone f) : f (max a b) = max (f a) (f b) := by cases le_total a b; simp [h, hf h] lemma monotone.map_min (hf : monotone f) : f (min a b) = min (f a) (f b) := by cases le_total a b; simp [h, hf h] theorem min_choice (a b : α) : min a b = a ∨ min a b = b := by by_cases h : a ≤ b; simp [min, h] theorem max_choice (a b : α) : max a b = a ∨ max a b = b := by by_cases h : a ≤ b; simp [max, h] lemma le_of_max_le_left {a b c : α} (h : max a b ≤ c) : a ≤ c := le_trans (le_max_left _ _) h lemma le_of_max_le_right {a b c : α} (h : max a b ≤ c) : b ≤ c := le_trans (le_max_right _ _) h end lemma min_add {α : Type u} [decidable_linear_ordered_add_comm_group α] (a b c : α) : min a b + c = min (a + c) (b + c) := if hle : a ≤ b then have a - c ≤ b - c, from sub_le_sub hle (le_refl _), by simp * at * else have b - c ≤ a - c, from sub_le_sub (le_of_lt (lt_of_not_ge hle)) (le_refl _), by simp * at * lemma min_sub {α : Type u} [decidable_linear_ordered_add_comm_group α] (a b c : α) : min a b - c = min (a - c) (b - c) := by simp [min_add, sub_eq_add_neg] /- Some lemmas about types that have an ordering and a binary operation, with no rules relating them. -/ lemma fn_min_add_fn_max [decidable_linear_order α] [add_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, add_comm] } lemma min_add_max [decidable_linear_order α] [add_comm_semigroup α] (n m : α) : min n m + max n m = n + m := fn_min_add_fn_max id n m lemma fn_min_mul_fn_max [decidable_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] } lemma min_mul_max [decidable_linear_order α] [comm_semigroup α] (n m : α) : min n m * max n m = n * m := fn_min_mul_fn_max id n m section decidable_linear_ordered_add_comm_group variables [decidable_linear_ordered_add_comm_group α] {a b c : α} attribute [simp] abs_zero abs_neg lemma abs_add (a b : α) : abs (a + b) ≤ abs a + abs b := abs_add_le_abs_add_abs a b theorem abs_le : abs a ≤ b ↔ - b ≤ a ∧ a ≤ b := ⟨assume h, ⟨neg_le_of_neg_le $ le_trans (neg_le_abs_self _) h, le_trans (le_abs_self _) h⟩, assume ⟨h₁, h₂⟩, abs_le_of_le_of_neg_le h₂ $ neg_le_of_neg_le h₁⟩ lemma abs_lt : abs a < b ↔ - b < a ∧ a < b := ⟨assume h, ⟨neg_lt_of_neg_lt $ lt_of_le_of_lt (neg_le_abs_self _) h, lt_of_le_of_lt (le_abs_self _) h⟩, assume ⟨h₁, h₂⟩, abs_lt_of_lt_of_neg_lt h₂ $ neg_lt_of_neg_lt h₁⟩ lemma abs_sub_le_iff : abs (a - b) ≤ c ↔ a - b ≤ c ∧ b - a ≤ c := by rw [abs_le, neg_le_sub_iff_le_add, @sub_le_iff_le_add' _ _ b, and_comm] lemma abs_sub_lt_iff : abs (a - b) < c ↔ a - b < c ∧ b - a < c := by rw [abs_lt, neg_lt_sub_iff_lt_add, @sub_lt_iff_lt_add' _ _ b, and_comm] lemma sub_abs_le_abs_sub (a b : α) : abs a - abs b ≤ abs (a - b) := abs_sub_abs_le_abs_sub a b lemma abs_abs_sub_le_abs_sub (a b : α) : abs (abs a - abs b) ≤ abs (a - b) := abs_sub_le_iff.2 ⟨sub_abs_le_abs_sub _ _, by rw abs_sub; apply sub_abs_le_abs_sub⟩ lemma abs_eq (hb : 0 ≤ b) : abs a = b ↔ a = b ∨ a = -b := iff.intro begin cases le_total a 0 with a_nonpos a_nonneg, { rw [abs_of_nonpos a_nonpos, neg_eq_iff_neg_eq, eq_comm], exact or.inr }, { rw [abs_of_nonneg a_nonneg, eq_comm], exact or.inl } end (by intro h; cases h; subst h; try { rw abs_neg }; exact abs_of_nonneg hb) @[simp] lemma abs_eq_zero : abs a = 0 ↔ a = 0 := ⟨eq_zero_of_abs_eq_zero, λ e, e.symm ▸ abs_zero⟩ lemma abs_pos_iff {a : α} : 0 < abs a ↔ a ≠ 0 := ⟨λ h, mt abs_eq_zero.2 (ne_of_gt h), abs_pos_of_ne_zero⟩ @[simp] lemma abs_nonpos_iff {a : α} : abs a ≤ 0 ↔ a = 0 := by rw [← not_lt, abs_pos_iff, not_not] lemma abs_le_max_abs_abs (hab : a ≤ b) (hbc : b ≤ c) : abs b ≤ max (abs a) (abs c) := abs_le_of_le_of_neg_le (by simp [le_max_iff, le_trans hbc (le_abs_self c)]) (by simp [le_max_iff, le_trans (neg_le_neg hab) (neg_le_abs_self a)]) theorem abs_le_abs {α : Type*} [decidable_linear_ordered_add_comm_group α] {a b : α} (h₀ : a ≤ b) (h₁ : -a ≤ b) : abs a ≤ abs b := calc abs a ≤ b : by { apply abs_le_of_le_of_neg_le; assumption } ... ≤ abs b : le_abs_self _ lemma min_le_add_of_nonneg_right {a b : α} (hb : b ≥ 0) : min a b ≤ a + b := calc min a b ≤ a : by apply min_le_left ... ≤ a + b : le_add_of_nonneg_right hb lemma min_le_add_of_nonneg_left {a b : α} (ha : a ≥ 0) : min a b ≤ a + b := calc min a b ≤ b : by apply min_le_right ... ≤ a + b : le_add_of_nonneg_left ha lemma max_le_add_of_nonneg {a b : α} (ha : a ≥ 0) (hb : b ≥ 0) : max a b ≤ a + b := max_le_iff.2 (by split; simpa) lemma max_zero_sub_eq_self (a : α) : max a 0 - max (-a) 0 = a := begin rcases le_total a 0, { rw [max_eq_right h, max_eq_left, zero_sub, neg_neg], { rwa [le_neg, neg_zero] } }, { rw [max_eq_left, max_eq_right, sub_zero], { rwa [neg_le, neg_zero] }, exact h } end lemma abs_max_sub_max_le_abs (a b c : α) : abs (max a c - max b c) ≤ abs (a - b) := begin simp only [max], split_ifs, { rw [sub_self, abs_zero], exact abs_nonneg _ }, { calc abs (c - b) = - (c - b) : abs_of_neg (sub_neg_of_lt (lt_of_not_ge h_1)) ... = b - c : neg_sub _ _ ... ≤ b - a : by { rw sub_le_sub_iff_left, exact h } ... = - (a - b) : by rw neg_sub ... ≤ abs (a - b) : neg_le_abs_self _ }, { calc abs (a - c) = a - c : abs_of_pos (sub_pos_of_lt (lt_of_not_ge h)) ... ≤ a - b : by { rw sub_le_sub_iff_left, exact h_1 } ... ≤ abs (a - b) : le_abs_self _ }, { refl } end lemma max_sub_min_eq_abs' (a b : α) : max a b - min a b = abs (a - b) := begin cases le_total a b with ab ba, { rw [max_eq_right ab, min_eq_left ab, abs_of_nonpos, neg_sub], rwa sub_nonpos }, { rw [max_eq_left ba, min_eq_right ba, abs_of_nonneg], exact sub_nonneg_of_le ba } end lemma max_sub_min_eq_abs (a b : α) : max a b - min a b = abs (b - a) := by { rw [abs_sub], exact max_sub_min_eq_abs' _ _ } end decidable_linear_ordered_add_comm_group section decidable_linear_ordered_semiring variables [decidable_linear_ordered_semiring α] {a b c d : α} lemma monotone_mul_left_of_nonneg (ha : 0 ≤ a) : monotone (λ x, a*x) := assume b c b_le_c, mul_le_mul_of_nonneg_left b_le_c ha lemma monotone_mul_right_of_nonneg (ha : 0 ≤ a) : monotone (λ x, x*a) := assume b c b_le_c, mul_le_mul_of_nonneg_right b_le_c ha lemma mul_max_of_nonneg (b c : α) (ha : 0 ≤ a) : a * max b c = max (a * b) (a * c) := (monotone_mul_left_of_nonneg ha).map_max lemma mul_min_of_nonneg (b c : α) (ha : 0 ≤ a) : a * min b c = min (a * b) (a * c) := (monotone_mul_left_of_nonneg ha).map_min lemma max_mul_of_nonneg (a b : α) (hc : 0 ≤ c) : max a b * c = max (a * c) (b * c) := (monotone_mul_right_of_nonneg hc).map_max lemma min_mul_of_nonneg (a b : α) (hc : 0 ≤ c) : min a b * c = min (a * c) (b * c) := (monotone_mul_right_of_nonneg hc).map_min end decidable_linear_ordered_semiring section decidable_linear_ordered_comm_ring variables [decidable_linear_ordered_comm_ring α] {a b c d : α} @[simp] lemma abs_one : abs (1 : α) = 1 := abs_of_pos zero_lt_one lemma max_mul_mul_le_max_mul_max (b c : α) (ha : 0 ≤ a) (hd: 0 ≤ d) : max (a * b) (d * c) ≤ max a c * max d b := have ba : b * a ≤ max d b * max c a, from mul_le_mul (le_max_right d b) (le_max_right c a) ha (le_trans hd (le_max_left d b)), have cd : c * d ≤ max a c * max b d, from mul_le_mul (le_max_right a c) (le_max_right b d) hd (le_trans ha (le_max_left a c)), max_le (by simpa [mul_comm, max_comm] using ba) (by simpa [mul_comm, max_comm] using cd) end decidable_linear_ordered_comm_ring
90ae9e14f4b0785272b3edacdc9a765e393eff68
bb31430994044506fa42fd667e2d556327e18dfe
/src/data/polynomial/derivative.lean
170c4700a4fbaf0cf56b0f5e3edd8fbb86131b66
[ "Apache-2.0" ]
permissive
sgouezel/mathlib
0cb4e5335a2ba189fa7af96d83a377f83270e503
00638177efd1b2534fc5269363ebf42a7871df9a
refs/heads/master
1,674,527,483,042
1,673,665,568,000
1,673,665,568,000
119,598,202
0
0
null
1,517,348,647,000
1,517,348,646,000
null
UTF-8
Lean
false
false
23,824
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 -/ import algebra.hom.iterate import data.polynomial.eval /-! # The derivative map on polynomials ## Main definitions * `polynomial.derivative`: The formal derivative of polynomials, expressed as a linear map. -/ noncomputable theory open finset open_locale big_operators classical polynomial namespace polynomial universes u v w y z variables {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {A : Type z} {a b : R} {n : ℕ} section derivative section semiring variables [semiring R] /-- `derivative p` is the formal derivative of the polynomial `p` -/ def derivative : R[X] →ₗ[R] R[X] := { to_fun := λ p, p.sum (λ n a, C (a * n) * X^(n-1)), map_add' := λ p q, by rw sum_add_index; simp only [add_mul, forall_const, ring_hom.map_add, eq_self_iff_true, zero_mul, ring_hom.map_zero], map_smul' := λ a p, by dsimp; rw sum_smul_index; simp only [mul_sum, ← C_mul', mul_assoc, coeff_C_mul, ring_hom.map_mul, forall_const, zero_mul, ring_hom.map_zero, sum] } lemma derivative_apply (p : R[X]) : derivative p = p.sum (λn a, C (a * n) * X^(n - 1)) := rfl lemma coeff_derivative (p : R[X]) (n : ℕ) : coeff (derivative p) n = coeff p (n + 1) * (n + 1) := begin rw [derivative_apply], simp only [coeff_X_pow, coeff_sum, coeff_C_mul], rw [sum, finset.sum_eq_single (n + 1)], simp only [nat.add_succ_sub_one, add_zero, mul_one, if_true, eq_self_iff_true], norm_cast, { 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] } }, { rw [if_pos (add_tsub_cancel_right n 1).symm, mul_one, nat.cast_add, nat.cast_one, mem_support_iff], intro h, push_neg at h, simp [h], }, end @[simp] lemma derivative_zero : derivative (0 : R[X]) = 0 := derivative.map_zero @[simp] lemma iterate_derivative_zero {k : ℕ} : derivative^[k] (0 : R[X]) = 0 := begin induction k with k ih, { simp, }, { simp [ih], }, end @[simp] lemma derivative_monomial (a : R) (n : ℕ) : derivative (monomial n a) = monomial (n - 1) (a * n) := by { rw [derivative_apply, sum_monomial_index, C_mul_X_pow_eq_monomial], simp } lemma derivative_C_mul_X (a : R) : derivative (C a * X) = C a := by simpa only [C_mul_X_eq_monomial, derivative_monomial, nat.cast_one, mul_one] lemma derivative_C_mul_X_pow (a : R) (n : ℕ) : derivative (C a * X ^ n) = C (a * n) * X ^ (n - 1) := by rw [C_mul_X_pow_eq_monomial, C_mul_X_pow_eq_monomial, derivative_monomial] lemma derivative_C_mul_X_sq (a : R) : derivative (C a * X ^ 2) = C (a * 2) * X := by rw [derivative_C_mul_X_pow, nat.cast_two, pow_one] @[simp] lemma derivative_X_pow (n : ℕ) : derivative (X ^ n : R[X]) = C ↑n * X ^ (n - 1) := by convert derivative_C_mul_X_pow (1 : R) n; simp @[simp] lemma derivative_X_sq : derivative (X ^ 2 : R[X]) = C 2 * X := by rw [derivative_X_pow, nat.cast_two, pow_one] @[simp] lemma derivative_C {a : R} : derivative (C a) = 0 := by simp [derivative_apply] lemma derivative_of_nat_degree_zero {p : R[X]} (hp : p.nat_degree = 0) : p.derivative = 0 := by rw [eq_C_of_nat_degree_eq_zero hp, derivative_C] @[simp] lemma derivative_X : derivative (X : R[X]) = 1 := (derivative_monomial _ _).trans $ by simp @[simp] lemma derivative_one : derivative (1 : R[X]) = 0 := derivative_C @[simp] lemma derivative_bit0 {a : R[X]} : derivative (bit0 a) = bit0 (derivative a) := by simp [bit0] @[simp] lemma derivative_bit1 {a : R[X]} : derivative (bit1 a) = bit0 (derivative a) := by simp [bit1] @[simp] lemma derivative_add {f g : R[X]} : derivative (f + g) = derivative f + derivative g := derivative.map_add f g @[simp] lemma derivative_X_add_C (c : R) : (X + C c).derivative = 1 := by rw [derivative_add, derivative_X, derivative_C, add_zero] @[simp] lemma iterate_derivative_add {f g : R[X]} {k : ℕ} : derivative^[k] (f + g) = (derivative^[k] f) + (derivative^[k] g) := derivative.to_add_monoid_hom.iterate_map_add _ _ _ @[simp] lemma derivative_sum {s : finset ι} {f : ι → R[X]} : derivative (∑ b in s, f b) = ∑ b in s, derivative (f b) := derivative.map_sum @[simp] lemma derivative_smul {S : Type*} [monoid S] [distrib_mul_action S R] [is_scalar_tower S R R] (s : S) (p : R[X]) : derivative (s • p) = s • derivative p := derivative.map_smul_of_tower s p @[simp] lemma iterate_derivative_smul {S : Type*} [monoid S] [distrib_mul_action S R] [is_scalar_tower S R R] (s : S) (p : R[X]) (k : ℕ) : derivative^[k] (s • p) = s • (derivative^[k] p) := begin induction k with k ih generalizing p, { simp, }, { simp [ih], }, end @[simp] lemma iterate_derivative_C_mul (a : R) (p : R[X]) (k : ℕ) : derivative^[k] (C a * p) = C a * (derivative^[k] p) := by simp_rw [← smul_eq_C_mul, iterate_derivative_smul] theorem of_mem_support_derivative {p : R[X]} {n : ℕ} (h : n ∈ p.derivative.support) : n + 1 ∈ p.support := mem_support_iff.2 $ λ (h1 : p.coeff (n+1) = 0), mem_support_iff.1 h $ show p.derivative.coeff n = 0, by rw [coeff_derivative, h1, zero_mul] theorem degree_derivative_lt {p : R[X]} (hp : p ≠ 0) : p.derivative.degree < p.degree := (finset.sup_lt_iff $ bot_lt_iff_ne_bot.2 $ mt degree_eq_bot.1 hp).2 $ λ n hp, lt_of_lt_of_le (with_bot.some_lt_some.2 n.lt_succ_self) $ finset.le_sup $ of_mem_support_derivative hp theorem degree_derivative_le {p : R[X]} : p.derivative.degree ≤ p.degree := if H : p = 0 then le_of_eq $ by rw [H, derivative_zero] else (degree_derivative_lt H).le theorem nat_degree_derivative_lt {p : R[X]} (hp : p.nat_degree ≠ 0) : p.derivative.nat_degree < p.nat_degree := begin cases eq_or_ne p.derivative 0 with hp' hp', { rw [hp', polynomial.nat_degree_zero], exact hp.bot_lt }, { rw nat_degree_lt_nat_degree_iff hp', exact degree_derivative_lt (λ h, hp (h.symm ▸ nat_degree_zero)) } end lemma nat_degree_derivative_le (p : R[X]) : p.derivative.nat_degree ≤ p.nat_degree - 1 := begin by_cases p0 : p.nat_degree = 0, { simp [p0, derivative_of_nat_degree_zero] }, { exact nat.le_pred_of_lt (nat_degree_derivative_lt p0) } end @[simp] lemma derivative_nat_cast {n : ℕ} : derivative (n : R[X]) = 0 := begin rw ← map_nat_cast C n, exact derivative_C, end lemma iterate_derivative_eq_zero {p : R[X]} {x : ℕ} (hx : p.nat_degree < x) : polynomial.derivative^[x] p = 0 := begin induction h : p.nat_degree using nat.strong_induction_on with _ ih generalizing p x, subst h, obtain ⟨t, rfl⟩ := nat.exists_eq_succ_of_ne_zero (pos_of_gt hx).ne', rw [function.iterate_succ_apply], by_cases hp : p.nat_degree = 0, { rw [derivative_of_nat_degree_zero hp, iterate_derivative_zero] }, have := nat_degree_derivative_lt hp, exact ih _ this (this.trans_le $ nat.le_of_lt_succ hx) rfl end @[simp] lemma iterate_derivative_C {k} (h : 0 < k) : (derivative^[k] (C a : R[X])) = 0 := iterate_derivative_eq_zero $ (nat_degree_C _).trans_lt h @[simp] lemma iterate_derivative_one {k} (h : 0 < k) : (derivative^[k] (1 : R[X])) = 0 := iterate_derivative_C h @[simp] lemma iterate_derivative_X {k} (h : 1 < k) : (derivative^[k] (X : R[X])) = 0 := iterate_derivative_eq_zero $ nat_degree_X_le.trans_lt h theorem nat_degree_eq_zero_of_derivative_eq_zero [no_zero_smul_divisors ℕ R] {f : R[X]} (h : f.derivative = 0) : f.nat_degree = 0 := begin rcases eq_or_ne f 0 with rfl | hf, { exact nat_degree_zero }, rw nat_degree_eq_zero_iff_degree_le_zero, by_contra' f_nat_degree_pos, rw [←nat_degree_pos_iff_degree_pos] at f_nat_degree_pos, let m := f.nat_degree - 1, have hm : m + 1 = f.nat_degree := tsub_add_cancel_of_le f_nat_degree_pos, have h2 := coeff_derivative f m, rw polynomial.ext_iff at h, rw [h m, coeff_zero, ← nat.cast_add_one, ← nsmul_eq_mul', eq_comm, smul_eq_zero] at h2, replace h2 := h2.resolve_left m.succ_ne_zero, rw [hm, ←leading_coeff, leading_coeff_eq_zero] at h2, exact hf h2 end theorem eq_C_of_derivative_eq_zero [no_zero_smul_divisors ℕ R] {f : R[X]} (h : f.derivative = 0) : f = C (f.coeff 0) := eq_C_of_nat_degree_eq_zero $ nat_degree_eq_zero_of_derivative_eq_zero h @[simp] lemma derivative_mul {f g : R[X]} : derivative (f * g) = derivative f * g + f * derivative g := calc derivative (f * g) = f.sum (λ n a, g.sum (λ m b, (n + m) • (C (a * b) * X ^ ((n + m) - 1)))) : begin rw mul_eq_sum_sum, 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, { exact congr_arg _ C_mul_X_pow_eq_monomial.symm }, dsimp, rw [← smul_mul_assoc, smul_C, nsmul_eq_mul'], exact derivative_C_mul_X_pow _ _ end ... = f.sum (λn a, g.sum (λm b, (n • (C a * X^(n - 1))) * (C b * X^m) + (C a * X^n) * (m • (C b * X^(m - 1))))) : sum_congr rfl $ assume n hn, sum_congr rfl $ assume m hm, by cases n; cases m; simp_rw [add_smul, mul_smul_comm, smul_mul_assoc, X_pow_mul_assoc, ← mul_assoc, ← C_mul, mul_assoc, ← pow_add]; simp only [nat.add_succ, nat.succ_add, nat.succ_sub_one, zero_smul, add_comm] ... = derivative f * g + f * derivative g : begin conv { to_rhs, congr, { rw [← sum_C_mul_X_pow_eq g] }, { rw [← sum_C_mul_X_pow_eq f] } }, simp only [sum, sum_add_distrib, finset.mul_sum, finset.sum_mul, derivative_apply], simp_rw [← smul_mul_assoc, smul_C, nsmul_eq_mul'], end lemma derivative_eval (p : R[X]) (x : R) : p.derivative.eval x = p.sum (λ n a, (a * n) * x ^ (n-1)) := by simp_rw [derivative_apply, eval_sum, eval_mul_X_pow, eval_C] @[simp] theorem derivative_map [semiring S] (p : R[X]) (f : R →+* S) : (p.map f).derivative = p.derivative.map f := begin let n := max p.nat_degree ((map f p).nat_degree), rw [derivative_apply, derivative_apply], rw [sum_over_range' _ _ (n + 1) ((le_max_left _ _).trans_lt (lt_add_one _))], rw [sum_over_range' _ _ (n + 1) ((le_max_right _ _).trans_lt (lt_add_one _))], simp only [polynomial.map_sum, polynomial.map_mul, polynomial.map_C, map_mul, coeff_map, map_nat_cast, polynomial.map_nat_cast, polynomial.map_pow, map_X], all_goals { intro n, rw [zero_mul, C_0, zero_mul], } end @[simp] theorem iterate_derivative_map [semiring S] (p : R[X]) (f : R →+* S) (k : ℕ): polynomial.derivative^[k] (p.map f) = (polynomial.derivative^[k] p).map f := begin induction k with k ih generalizing p, { simp, }, { simp only [ih, function.iterate_succ, polynomial.derivative_map, function.comp_app], }, end lemma derivative_nat_cast_mul {n : ℕ} {f : R[X]} : (↑n * f).derivative = n * f.derivative := by simp @[simp] lemma iterate_derivative_nat_cast_mul {n k : ℕ} {f : R[X]} : derivative^[k] (n * f) = n * (derivative^[k] f) := by induction k with k ih generalizing f; simp* lemma mem_support_derivative [no_zero_smul_divisors ℕ R] (p : R[X]) (n : ℕ) : n ∈ (derivative p).support ↔ n + 1 ∈ p.support := suffices ¬p.coeff (n + 1) * (n + 1 : ℕ) = 0 ↔ coeff p (n + 1) ≠ 0, by simpa only [mem_support_iff, coeff_derivative, ne.def, nat.cast_succ], by { rw [← nsmul_eq_mul', smul_eq_zero], simp only [nat.succ_ne_zero, false_or] } @[simp] lemma degree_derivative_eq [no_zero_smul_divisors ℕ R] (p : R[X]) (hp : 0 < nat_degree p) : degree (derivative p) = (nat_degree p - 1 : ℕ) := begin have h0 : p ≠ 0, { contrapose! hp, simp [hp] }, apply le_antisymm, { rw derivative_apply, apply le_trans (degree_sum_le _ _) (finset.sup_le (λ n hn, _)), apply le_trans (degree_C_mul_X_pow_le _ _) (with_bot.coe_le_coe.2 (tsub_le_tsub_right _ _)), apply le_nat_degree_of_mem_supp _ hn }, { refine le_sup _, rw [mem_support_derivative, tsub_add_cancel_of_le, 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 lemma coeff_iterate_derivative_as_prod_Ico {k} (p : R[X]) : ∀ m : ℕ, (derivative^[k] p).coeff m = (∏ i in Ico m.succ (m + k.succ), i) • (p.coeff (m + k)) := begin induction k with k ih, { simp only [add_zero, forall_const, one_smul, Ico_self, eq_self_iff_true, function.iterate_zero_apply, prod_empty] }, { intro m, rw [function.iterate_succ_apply', coeff_derivative, ih (m+1), ← nat.cast_add_one, ← nsmul_eq_mul', smul_smul, mul_comm], apply congr_arg2, { have set_eq : (Ico m.succ (m + k.succ.succ)) = (Ico (m + 1).succ (m + 1 + k.succ)) ∪ {m+1}, { simp_rw [← nat.Ico_succ_singleton, union_comm, nat.succ_eq_add_one, add_comm (k + 1), add_assoc], rw [Ico_union_Ico_eq_Ico]; simp_rw [add_le_add_iff_left, le_add_self], }, rw [set_eq, prod_union, prod_singleton], { rw [disjoint_singleton_right, mem_Ico], exact λ h, (nat.lt_succ_self _).not_le h.1 } }, { exact congr_arg _ (nat.succ_add m k) } }, end lemma coeff_iterate_derivative_as_prod_range {k} (p : R[X]) : ∀ m : ℕ, (derivative^[k] p).coeff m = (∏ i in range k, (m + k - i)) • p.coeff (m + k) := begin induction k with k ih, { simp }, intro m, calc (derivative^[k + 1] p).coeff m = (∏ i in range k, (m + k.succ - i)) • p.coeff (m + k.succ) * (m + 1) : by rw [function.iterate_succ_apply', coeff_derivative, ih m.succ, nat.succ_add, nat.add_succ] ... = ((∏ i in range k, (m + k.succ - i)) * (m + 1)) • p.coeff (m + k.succ) : by rw [← nat.cast_add_one, ← nsmul_eq_mul', smul_smul, mul_comm] ... = (∏ i in range k.succ, (m + k.succ - i)) • p.coeff (m + k.succ) : by rw [prod_range_succ, add_tsub_assoc_of_le k.le_succ, nat.succ_sub le_rfl, tsub_self] end lemma iterate_derivative_mul {n} (p q : R[X]) : derivative^[n] (p * q) = ∑ k in range n.succ, n.choose k • ((derivative^[n - k] p) * (derivative^[k] q)) := begin induction n with n IH, { simp }, calc derivative^[n + 1] (p * q) = (∑ (k : ℕ) in range n.succ, (n.choose k) • ((derivative^[n - k] p) * (derivative^[k] q))).derivative : by rw [function.iterate_succ_apply', IH] ... = ∑ (k : ℕ) in range n.succ, (n.choose k) • ((derivative^[n - k + 1] p) * (derivative^[k] q)) + ∑ (k : ℕ) in range n.succ, (n.choose k) • ((derivative^[n - k] p) * (derivative^[k + 1] q)) : by simp_rw [derivative_sum, derivative_smul, derivative_mul, function.iterate_succ_apply', smul_add, sum_add_distrib] ... = (∑ (k : ℕ) in range n.succ, (n.choose k.succ) • ((derivative^[n - k] p) * (derivative^[k + 1] q)) + 1 • ((derivative^[n + 1] p) * (derivative^[0] q))) + ∑ (k : ℕ) in range n.succ, (n.choose k) • ((derivative^[n - k] p) * (derivative^[k + 1] q)) : _ ... = ∑ (k : ℕ) in range n.succ, (n.choose k) • ((derivative^[n - k] p) * (derivative^[k + 1] q)) + ∑ (k : ℕ) in range n.succ, (n.choose k.succ) • ((derivative^[n - k] p) * (derivative^[k + 1] q)) + 1 • ((derivative^[n + 1] p) * (derivative^[0] q)) : by rw [add_comm, add_assoc] ... = ∑ (i : ℕ) in range n.succ, ((n+1).choose (i+1)) • ((derivative^[n + 1 - (i + 1)] p) * (derivative^[i + 1] q)) + 1 • ((derivative^[n + 1] p) * (derivative^[0] q)) : by simp_rw [nat.choose_succ_succ, nat.succ_sub_succ, add_smul, sum_add_distrib] ... = ∑ (k : ℕ) in range n.succ.succ, (n.succ.choose k) • (derivative^[n.succ - k] p * (derivative^[k] q)) : by rw [sum_range_succ' _ n.succ, nat.choose_zero_right, tsub_zero], congr, refine (sum_range_succ' _ _).trans (congr_arg2 (+) _ _), { rw [sum_range_succ, nat.choose_succ_self, zero_smul, add_zero], refine sum_congr rfl (λ k hk, _), rw mem_range at hk, congr, rw [tsub_add_eq_add_tsub (nat.succ_le_of_lt hk), nat.succ_sub_succ] }, { rw [nat.choose_zero_right, tsub_zero] }, end end semiring section comm_semiring variables [comm_semiring R] theorem derivative_pow_succ (p : R[X]) (n : ℕ) : (p ^ (n + 1)).derivative = C ↑(n + 1) * (p ^ n) * p.derivative := nat.rec_on n (by rw [pow_one, nat.cast_one, C_1, one_mul, pow_zero, one_mul]) $ λ n ih, by rw [pow_succ', derivative_mul, ih, nat.add_one, mul_right_comm, nat.cast_add n.succ, C_add, add_mul, add_mul, pow_succ', ← mul_assoc, nat.cast_one, C_1, one_mul] theorem derivative_pow (p : R[X]) (n : ℕ) : (p ^ n).derivative = C ↑n * (p ^ (n - 1)) * p.derivative := nat.cases_on n (by rw [pow_zero, derivative_one, nat.cast_zero, C_0, zero_mul, zero_mul]) $ λ n, by rw [p.derivative_pow_succ n, n.succ_sub_one, n.cast_succ] theorem derivative_sq (p : R[X]) : (p ^ 2).derivative = C 2 * p * p.derivative := by rw [derivative_pow_succ, nat.cast_two, pow_one] theorem dvd_iterate_derivative_pow (f : R[X]) (n : ℕ) {m : ℕ} (c : R) (hm : m ≠ 0) : (n : R) ∣ eval c (derivative^[m] (f ^ n)) := begin obtain ⟨m, rfl⟩ := nat.exists_eq_succ_of_ne_zero hm, rw [function.iterate_succ_apply, derivative_pow, mul_assoc, C_eq_nat_cast, iterate_derivative_nat_cast_mul, eval_mul, eval_nat_cast], exact dvd_mul_right _ _, end lemma iterate_derivative_X_pow_eq_nat_cast_mul (n k : ℕ) : (derivative^[k] (X ^ n : R[X])) = ↑(nat.desc_factorial n k) * X ^ (n - k) := begin induction k with k ih, { rw [function.iterate_zero_apply, tsub_zero, nat.desc_factorial_zero, nat.cast_one, one_mul] }, { rw [function.iterate_succ_apply', ih, derivative_nat_cast_mul, derivative_X_pow, C_eq_nat_cast, nat.succ_eq_add_one, nat.desc_factorial_succ, nat.sub_sub, nat.cast_mul, ←mul_assoc, mul_comm ↑(nat.desc_factorial _ _)] }, end lemma iterate_derivative_X_pow_eq_C_mul (n k : ℕ) : (derivative^[k] (X ^ n : R[X])) = C ↑(nat.desc_factorial n k) * X ^ (n - k) := by rw [iterate_derivative_X_pow_eq_nat_cast_mul n k, C_eq_nat_cast] lemma iterate_derivative_X_pow_eq_smul (n : ℕ) (k : ℕ) : (derivative^[k] (X ^ n : R[X])) = (nat.desc_factorial n k : R) • X ^ (n - k) := by rw [iterate_derivative_X_pow_eq_C_mul n k, smul_eq_C_mul] lemma derivative_X_add_C_pow (c : R) (m : ℕ) : ((X + C c) ^ m).derivative = C ↑m * (X + C c) ^ (m - 1) := by rw [derivative_pow, derivative_X_add_C, mul_one] lemma derivative_X_add_C_sq (c : R) : ((X + C c) ^ 2).derivative = C 2 * (X + C c) := by rw [derivative_sq, derivative_X_add_C, mul_one] lemma iterate_derivative_X_add_pow (n k : ℕ) (c : R) : derivative^[k] ((X + C c) ^ n) = ↑(∏ i in finset.range k, (n - i)) * (X + C c) ^ (n - k) := begin induction k with k IH, { rw [function.iterate_zero_apply, finset.range_zero, finset.prod_empty, nat.cast_one, one_mul, tsub_zero] }, { simp only [function.iterate_succ_apply', IH, derivative_mul, zero_mul, derivative_nat_cast, zero_add, finset.prod_range_succ, C_eq_nat_cast, nat.sub_sub, ←mul_assoc, derivative_X_add_C_pow, nat.succ_eq_add_one, nat.cast_mul] }, end lemma derivative_comp (p q : R[X]) : (p.comp q).derivative = q.derivative * p.derivative.comp q := begin apply polynomial.induction_on' p, { intros p₁ p₂ h₁ h₂, simp [h₁, h₂, mul_add], }, { intros n r, simp only [derivative_pow, derivative_mul, monomial_comp, derivative_monomial, derivative_C, zero_mul, C_eq_nat_cast, zero_add, ring_hom.map_mul], -- is there a tactic for this? (a multiplicative `abel`): rw [mul_comm (derivative q)], simp only [mul_assoc], } end /-- Chain rule for formal derivative of polynomials. -/ theorem derivative_eval₂_C (p q : R[X]) : (p.eval₂ C q).derivative = p.derivative.eval₂ C q * q.derivative := polynomial.induction_on p (λ r, by rw [eval₂_C, derivative_C, eval₂_zero, zero_mul]) (λ p₁ p₂ ih₁ ih₂, by rw [eval₂_add, derivative_add, ih₁, ih₂, derivative_add, eval₂_add, add_mul]) (λ n r ih, by rw [pow_succ', ← mul_assoc, eval₂_mul, eval₂_X, derivative_mul, ih, @derivative_mul _ _ _ X, derivative_X, mul_one, eval₂_add, @eval₂_mul _ _ _ _ X, eval₂_X, add_mul, mul_right_comm]) theorem derivative_prod {s : multiset ι} {f : ι → R[X]} : (multiset.map f s).prod.derivative = (multiset.map (λ i, (multiset.map f (s.erase i)).prod * (f i).derivative) s).sum := begin refine multiset.induction_on s (by simp) (λ i s h, _), rw [multiset.map_cons, multiset.prod_cons, derivative_mul, multiset.map_cons _ i s, multiset.sum_cons, multiset.erase_cons_head, mul_comm (f i).derivative], congr, rw [h, ← add_monoid_hom.coe_mul_left, (add_monoid_hom.mul_left (f i)).map_multiset_sum _, add_monoid_hom.coe_mul_left], simp only [function.comp_app, multiset.map_map], refine congr_arg _ (multiset.map_congr rfl (λ j hj, _)), rw [← mul_assoc, ← multiset.prod_cons, ← multiset.map_cons], by_cases hij : i = j, { simp [hij, ← multiset.prod_cons, ← multiset.map_cons, multiset.cons_erase hj] }, { simp [hij] } end end comm_semiring section ring variables [ring R] @[simp] lemma derivative_neg (f : R[X]) : derivative (-f) = - derivative f := linear_map.map_neg derivative f @[simp] lemma iterate_derivative_neg {f : R[X]} {k : ℕ} : derivative^[k] (-f) = - (derivative^[k] f) := (@derivative R _).to_add_monoid_hom.iterate_map_neg _ _ @[simp] lemma derivative_sub {f g : R[X]} : derivative (f - g) = derivative f - derivative g := linear_map.map_sub derivative f g @[simp] lemma derivative_X_sub_C (c : R) : (X - C c).derivative = 1 := by rw [derivative_sub, derivative_X, derivative_C, sub_zero] @[simp] lemma iterate_derivative_sub {k : ℕ} {f g : R[X]} : derivative^[k] (f - g) = (derivative^[k] f) - (derivative^[k] g) := by induction k with k ih generalizing f g; simp* @[simp] lemma derivative_int_cast {n : ℤ} : derivative (n : R[X]) = 0 := begin rw ← C_eq_int_cast n, exact derivative_C, end lemma derivative_int_cast_mul {n : ℤ} {f : R[X]} : (↑n * f).derivative = n * f.derivative := by simp @[simp] lemma iterate_derivative_int_cast_mul {n : ℤ} {k : ℕ} {f : R[X]} : derivative^[k] (↑n * f) = n * (derivative^[k] f) := by induction k with k ih generalizing f; simp* end ring section comm_ring variables [comm_ring R] lemma derivative_comp_one_sub_X (p : R[X]) : (p.comp (1 - X)).derivative = -p.derivative.comp (1 - X) := by simp [derivative_comp] @[simp] lemma iterate_derivative_comp_one_sub_X (p : R[X]) (k : ℕ) : derivative^[k] (p.comp (1 - X)) = (-1) ^ k * (derivative^[k] p).comp (1 - X) := begin induction k with k ih generalizing p, { simp, }, { simp [ih p.derivative, iterate_derivative_neg, derivative_comp, pow_succ], }, end lemma eval_multiset_prod_X_sub_C_derivative {S : multiset R} {r : R} (hr : r ∈ S) : eval r (multiset.map (λ a, X - C a) S).prod.derivative = (multiset.map (λ a, r - a) (S.erase r)).prod := begin nth_rewrite 0 [← multiset.cons_erase hr], simpa using (eval_ring_hom r).map_multiset_prod (multiset.map (λ a, X - C a) (S.erase r)), end lemma derivative_X_sub_C_pow (c : R) (m : ℕ) : ((X - C c) ^ m).derivative = C ↑m * (X - C c) ^ (m - 1) := by rw [derivative_pow, derivative_X_sub_C, mul_one] lemma derivative_X_sub_C_sq (c : R) : ((X - C c) ^ 2).derivative = C 2 * (X - C c) := by rw [derivative_sq, derivative_X_sub_C, mul_one] lemma iterate_derivative_X_sub_pow (n k : ℕ) (c : R) : (derivative^[k] ((X - C c) ^ n)) = (↑(∏ i in finset.range k, (n - i))) * (X - C c) ^ (n - k) := by simp_rw [sub_eq_add_neg, ←C_neg, iterate_derivative_X_add_pow] end comm_ring end derivative end polynomial
368541ba019d023c5dccd3aedb35f47b8d4fb8e3
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/import_invalid_tk.lean
d9b2730ab1c918ab68b63ace26147e7f22753211
[ "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
40
lean
import data.buffer 0b311 #print buffer
f0897a541ba68ab8be4d2f5f178ff2feb6efa3e2
302c785c90d40ad3d6be43d33bc6a558354cc2cf
/src/linear_algebra/tensor_algebra.lean
765c967cbd1622977905953f806d01644061fb15
[ "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
7,206
lean
/- Copyright (c) 2020 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz -/ import algebra.free_algebra import algebra.ring_quot import algebra.triv_sq_zero_ext /-! # Tensor Algebras Given a commutative semiring `R`, and an `R`-module `M`, we construct the tensor algebra of `M`. This is the free `R`-algebra generated (`R`-linearly) by the module `M`. ## Notation 1. `tensor_algebra R M` is the tensor algebra itself. It is endowed with an R-algebra structure. 2. `tensor_algebra.ι R` is the canonical R-linear map `M → tensor_algebra R M`. 3. Given a linear map `f : M → A` to an R-algebra `A`, `lift R f` is the lift of `f` to an `R`-algebra morphism `tensor_algebra R M → A`. ## Theorems 1. `ι_comp_lift` states that the composition `(lift R f) ∘ (ι R)` is identical to `f`. 2. `lift_unique` states that whenever an R-algebra morphism `g : tensor_algebra R M → A` is given whose composition with `ι R` is `f`, then one has `g = lift R f`. 3. `hom_ext` is a variant of `lift_unique` in the form of an extensionality theorem. 4. `lift_comp_ι` is a combination of `ι_comp_lift` and `lift_unique`. It states that the lift of the composition of an algebra morphism with `ι` is the algebra morphism itself. ## Implementation details As noted above, the tensor algebra of `M` is constructed as the free `R`-algebra generated by `M`, modulo the additional relations making the inclusion of `M` into an `R`-linear map. -/ variables (R : Type*) [comm_semiring R] variables (M : Type*) [add_comm_monoid M] [semimodule R M] namespace tensor_algebra /-- An inductively defined relation on `pre R M` used to force the initial algebra structure on the associated quotient. -/ inductive rel : free_algebra R M → free_algebra R M → Prop -- force `ι` to be linear | add {a b : M} : rel (free_algebra.ι R (a+b)) (free_algebra.ι R a + free_algebra.ι R b) | smul {r : R} {a : M} : rel (free_algebra.ι R (r • a)) (algebra_map R (free_algebra R M) r * free_algebra.ι R a) end tensor_algebra /-- The tensor algebra of the module `M` over the commutative semiring `R`. -/ @[derive [inhabited, semiring, algebra R]] def tensor_algebra := ring_quot (tensor_algebra.rel R M) namespace tensor_algebra instance {S : Type*} [comm_ring S] [semimodule S M] : ring (tensor_algebra S M) := ring_quot.ring (rel S M) variables {M} /-- The canonical linear map `M →ₗ[R] tensor_algebra R M`. -/ def ι : M →ₗ[R] (tensor_algebra R M) := { to_fun := λ m, (ring_quot.mk_alg_hom R _ (free_algebra.ι R m)), map_add' := λ x y, by { rw [←alg_hom.map_add], exact ring_quot.mk_alg_hom_rel R rel.add, }, map_smul' := λ r x, by { rw [←alg_hom.map_smul], exact ring_quot.mk_alg_hom_rel R rel.smul, } } lemma ring_quot_mk_alg_hom_free_algebra_ι_eq_ι (m : M) : ring_quot.mk_alg_hom R (rel R M) (free_algebra.ι R m) = ι R m := rfl /-- Given a linear map `f : M → A` where `A` is an `R`-algebra, `lift R f` is the unique lift of `f` to a morphism of `R`-algebras `tensor_algebra R M → A`. -/ @[simps symm_apply] def lift {A : Type*} [semiring A] [algebra R A] : (M →ₗ[R] A) ≃ (tensor_algebra R M →ₐ[R] A) := { to_fun := ring_quot.lift_alg_hom R ∘ λ f, ⟨free_algebra.lift R ⇑f, λ x y (h : rel R M x y), by induction h; simp [algebra.smul_def]⟩, inv_fun := λ F, F.to_linear_map.comp (ι R), left_inv := λ f, by { ext, simp [ι], }, right_inv := λ F, by { ext, simp [ι], } } variables {R} @[simp] theorem ι_comp_lift {A : Type*} [semiring A] [algebra R A] (f : M →ₗ[R] A) : (lift R f).to_linear_map.comp (ι R) = f := (lift R).symm_apply_apply f @[simp] theorem lift_ι_apply {A : Type*} [semiring A] [algebra R A] (f : M →ₗ[R] A) (x) : lift R f (ι R x) = f x := by { dsimp [lift, ι], refl, } @[simp] theorem lift_unique {A : Type*} [semiring A] [algebra R A] (f : M →ₗ[R] A) (g : tensor_algebra R M →ₐ[R] A) : g.to_linear_map.comp (ι R) = f ↔ g = lift R f := (lift R).symm_apply_eq -- Marking `tensor_algebra` irreducible makes `ring` instances inaccessible on quotients. -- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241 -- For now, we avoid this by not marking it irreducible. attribute [irreducible] ι lift @[simp] theorem lift_comp_ι {A : Type*} [semiring A] [algebra R A] (g : tensor_algebra R M →ₐ[R] A) : lift R (g.to_linear_map.comp (ι R)) = g := by { rw ←lift_symm_apply, exact (lift R).apply_symm_apply g } /-- See note [partially-applied ext lemmas]. -/ @[ext] theorem hom_ext {A : Type*} [semiring A] [algebra R A] {f g : tensor_algebra R M →ₐ[R] A} (w : f.to_linear_map.comp (ι R) = g.to_linear_map.comp (ι R)) : f = g := begin rw [←lift_symm_apply, ←lift_symm_apply] at w, exact (lift R).symm.injective w, end /-- If `C` holds for the `algebra_map` of `r : R` into `tensor_algebra R M`, the `ι` of `x : M`, and is preserved under addition and muliplication, then it holds for all of `tensor_algebra R M`. -/ -- This proof closely follows `free_algebra.induction` @[elab_as_eliminator] lemma induction {C : tensor_algebra R M → Prop} (h_grade0 : ∀ r, C (algebra_map R (tensor_algebra R M) r)) (h_grade1 : ∀ x, C (ι R x)) (h_mul : ∀ a b, C a → C b → C (a * b)) (h_add : ∀ a b, C a → C b → C (a + b)) (a : tensor_algebra R M) : C a := begin -- the arguments are enough to construct a subalgebra, and a mapping into it from M let s : subalgebra R (tensor_algebra R M) := { carrier := C, mul_mem' := h_mul, add_mem' := h_add, algebra_map_mem' := h_grade0, }, let of : M →ₗ[R] s := (ι R).cod_restrict s.to_submodule h_grade1, -- the mapping through the subalgebra is the identity have of_id : alg_hom.id R (tensor_algebra R M) = s.val.comp (lift R of), { ext, simp [of], }, -- finding a proof is finding an element of the subalgebra convert subtype.prop (lift R of a), exact alg_hom.congr_fun of_id a, end /-- The left-inverse of `algebra_map`. -/ def algebra_map_inv : tensor_algebra R M →ₐ[R] R := lift R (0 : M →ₗ[R] R) lemma algebra_map_left_inverse : function.left_inverse algebra_map_inv (algebra_map R $ tensor_algebra R M) := λ x, by simp [algebra_map_inv] /-- The left-inverse of `ι`. As an implementation detail, we implement this using `triv_sq_zero_ext` which has a suitable algebra structure. -/ def ι_inv : tensor_algebra R M →ₗ[R] M := (triv_sq_zero_ext.snd_hom R M).comp (lift R (triv_sq_zero_ext.inr_hom R M)).to_linear_map lemma ι_left_inverse : function.left_inverse ι_inv (ι R : M → tensor_algebra R M) := λ x, by simp [ι_inv] end tensor_algebra namespace free_algebra variables {R M} /-- The canonical image of the `free_algebra` in the `tensor_algebra`, which maps `free_algebra.ι R x` to `tensor_algebra.ι R x`. -/ def to_tensor : free_algebra R M →ₐ[R] tensor_algebra R M := free_algebra.lift R (tensor_algebra.ι R) @[simp] lemma to_tensor_ι (m : M) : (free_algebra.ι R m).to_tensor = tensor_algebra.ι R m := by simp [to_tensor] end free_algebra
f799490de8999e3cc8367a30a3f7e4b2b4ea5e3d
1446f520c1db37e157b631385707cc28a17a595e
/src/Init/Lean/Meta/WHNF.lean
84ce45baec0aaaabae29e915316b2df0688d21eb
[ "Apache-2.0" ]
permissive
bdbabiak/lean4
cab06b8a2606d99a168dd279efdd404edb4e825a
3f4d0d78b2ce3ef541cb643bbe21496bd6b057ac
refs/heads/master
1,615,045,275,530
1,583,793,696,000
1,583,793,696,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,195
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.Lean.AuxRecursor import Init.Lean.Util.WHNF import Init.Lean.Meta.Basic import Init.Lean.Meta.LevelDefEq namespace Lean namespace Meta def isAuxDef? (constName : Name) : MetaM Bool := do env ← getEnv; pure (isAuxRecursor env constName || isNoConfusion env constName) def unfoldDefinition? (e : Expr) : MetaM (Option Expr) := Lean.WHNF.unfoldDefinitionAux getConstNoEx isAuxDef? whnf inferType isExprDefEq synthPending getLocalDecl getExprMVarAssignment? e def whnfCore (e : Expr) : MetaM Expr := Lean.WHNF.whnfCore getConstNoEx isAuxDef? whnf inferType isExprDefEqAux getLocalDecl getExprMVarAssignment? e partial def whnfImpl : Expr → MetaM Expr | e => Lean.WHNF.whnfEasyCases getLocalDecl getExprMVarAssignment? e $ fun e => do e ← whnfCore e; e? ← unfoldDefinition? e; match e? with | some e => whnfImpl e | none => pure e @[init] def setWHNFRef : IO Unit := whnfRef.set whnfImpl /- Given an expression `e`, compute its WHNF and if the result is a constructor, return field #i. -/ def reduceProj? (e : Expr) (i : Nat) : MetaM (Option Expr) := do env ← getEnv; e ← whnf e; match e.getAppFn with | Expr.const name _ _ => match env.find? name with | some (ConstantInfo.ctorInfo ctorVal) => let numArgs := e.getAppNumArgs; let idx := ctorVal.nparams + i; if idx < numArgs then pure (some (e.getArg! idx)) else pure none | _ => pure none | _ => pure none @[specialize] private partial def whnfHeadPredAux (pred : Expr → MetaM Bool) : Expr → MetaM Expr | e => Lean.WHNF.whnfEasyCases getLocalDecl getExprMVarAssignment? e $ fun e => do e ← whnfCore e; condM (pred e) (do e? ← unfoldDefinition? e; match e? with | some e => whnfHeadPredAux e | none => pure e) (pure e) def whnfHeadPred (e : Expr) (pred : Expr → MetaM Bool) : MetaM Expr := whnfHeadPredAux pred e def whnfUntil (e : Expr) (declName : Name) : MetaM Expr := whnfHeadPredAux (fun e => pure $ e.isAppOf declName) e end Meta end Lean
472bf667763ec194f81e98b1a526ae53e73dc1e4
947fa6c38e48771ae886239b4edce6db6e18d0fb
/src/linear_algebra/clifford_algebra/basic.lean
725d054f473658300bd440efdae35ce6f2b378b0
[ "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
12,505
lean
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Utensil Song -/ import algebra.ring_quot import linear_algebra.tensor_algebra.basic import linear_algebra.quadratic_form.isometry /-! # Clifford Algebras We construct the Clifford algebra of a module `M` over a commutative ring `R`, equipped with a quadratic_form `Q`. ## Notation The Clifford algebra of the `R`-module `M` equipped with a quadratic_form `Q` is an `R`-algebra denoted `clifford_algebra Q`. Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that `cond : ∀ m, f m * f m = algebra_map _ _ (Q m)`, there is a (unique) lift of `f` to an `R`-algebra morphism from `clifford_algebra Q` to `A`, which is denoted `clifford_algebra.lift Q f cond`. The canonical linear map `M → clifford_algebra Q` is denoted `clifford_algebra.ι Q`. ## Theorems The main theorems proved ensure that `clifford_algebra Q` satisfies the universal property of the Clifford algebra. 1. `ι_comp_lift` is the fact that the composition of `ι Q` with `lift Q f cond` agrees with `f`. 2. `lift_unique` ensures the uniqueness of `lift Q f cond` with respect to 1. Additionally, when `Q = 0` an `alg_equiv` to the `exterior_algebra` is provided as `as_exterior`. ## Implementation details The Clifford algebra of `M` is constructed as a quotient of the tensor algebra, as follows. 1. We define a relation `clifford_algebra.rel Q` on `tensor_algebra R M`. This is the smallest relation which identifies squares of elements of `M` with `Q m`. 2. The Clifford algebra is the quotient of the tensor algebra by this relation. This file is almost identical to `linear_algebra/exterior_algebra.lean`. -/ variables {R : Type*} [comm_ring R] variables {M : Type*} [add_comm_group M] [module R M] variables (Q : quadratic_form R M) variable {n : ℕ} namespace clifford_algebra open tensor_algebra /-- `rel` relates each `ι m * ι m`, for `m : M`, with `Q m`. The Clifford algebra of `M` is defined as the quotient modulo this relation. -/ inductive rel : tensor_algebra R M → tensor_algebra R M → Prop | of (m : M) : rel (ι R m * ι R m) (algebra_map R _ (Q m)) end clifford_algebra /-- The Clifford algebra of an `R`-module `M` equipped with a quadratic_form `Q`. -/ @[derive [inhabited, ring, algebra R]] def clifford_algebra := ring_quot (clifford_algebra.rel Q) namespace clifford_algebra /-- The canonical linear map `M →ₗ[R] clifford_algebra Q`. -/ def ι : M →ₗ[R] clifford_algebra Q := (ring_quot.mk_alg_hom R _).to_linear_map.comp (tensor_algebra.ι R) /-- As well as being linear, `ι Q` squares to the quadratic form -/ @[simp] theorem ι_sq_scalar (m : M) : ι Q m * ι Q m = algebra_map R _ (Q m) := begin erw [←alg_hom.map_mul, ring_quot.mk_alg_hom_rel R (rel.of m), alg_hom.commutes], refl, end variables {Q} {A : Type*} [semiring A] [algebra R A] @[simp] theorem comp_ι_sq_scalar (g : clifford_algebra Q →ₐ[R] A) (m : M) : g (ι Q m) * g (ι Q m) = algebra_map _ _ (Q m) := by rw [←alg_hom.map_mul, ι_sq_scalar, alg_hom.commutes] variables (Q) /-- Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition: `cond : ∀ m : M, f m * f m = Q(m)`, this is the canonical lift of `f` to a morphism of `R`-algebras from `clifford_algebra Q` to `A`. -/ @[simps symm_apply] def lift : {f : M →ₗ[R] A // ∀ m, f m * f m = algebra_map _ _ (Q m)} ≃ (clifford_algebra Q →ₐ[R] A) := { to_fun := λ f, ring_quot.lift_alg_hom R ⟨tensor_algebra.lift R (f : M →ₗ[R] A), (λ x y (h : rel Q x y), by { induction h, rw [alg_hom.commutes, alg_hom.map_mul, tensor_algebra.lift_ι_apply, f.prop], })⟩, inv_fun := λ F, ⟨F.to_linear_map.comp (ι Q), λ m, by rw [ linear_map.comp_apply, alg_hom.to_linear_map_apply, comp_ι_sq_scalar]⟩, left_inv := λ f, by { ext, simp only [ι, alg_hom.to_linear_map_apply, function.comp_app, linear_map.coe_comp, subtype.coe_mk, ring_quot.lift_alg_hom_mk_alg_hom_apply, tensor_algebra.lift_ι_apply] }, right_inv := λ F, by { ext, simp only [ι, alg_hom.comp_to_linear_map, alg_hom.to_linear_map_apply, function.comp_app, linear_map.coe_comp, subtype.coe_mk, ring_quot.lift_alg_hom_mk_alg_hom_apply, tensor_algebra.lift_ι_apply] } } variables {Q} @[simp] theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebra_map _ _ (Q m)) : (lift Q ⟨f, cond⟩).to_linear_map.comp (ι Q) = f := (subtype.mk_eq_mk.mp $ (lift Q).symm_apply_apply ⟨f, cond⟩) @[simp] theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebra_map _ _ (Q m)) (x) : lift Q ⟨f, cond⟩ (ι Q x) = f x := (linear_map.ext_iff.mp $ ι_comp_lift f cond) x @[simp] theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m : M, f m * f m = algebra_map _ _ (Q m)) (g : clifford_algebra Q →ₐ[R] A) : g.to_linear_map.comp (ι Q) = f ↔ g = lift Q ⟨f, cond⟩ := begin convert (lift Q).symm_apply_eq, rw lift_symm_apply, simp only, end attribute [irreducible] clifford_algebra ι lift @[simp] theorem lift_comp_ι (g : clifford_algebra Q →ₐ[R] A) : lift Q ⟨g.to_linear_map.comp (ι Q), comp_ι_sq_scalar _⟩ = g := begin convert (lift Q).apply_symm_apply g, rw lift_symm_apply, refl, end /-- See note [partially-applied ext lemmas]. -/ @[ext] theorem hom_ext {A : Type*} [semiring A] [algebra R A] {f g : clifford_algebra Q →ₐ[R] A} : f.to_linear_map.comp (ι Q) = g.to_linear_map.comp (ι Q) → f = g := begin intro h, apply (lift Q).symm.injective, rw [lift_symm_apply, lift_symm_apply], simp only [h], end /-- If `C` holds for the `algebra_map` of `r : R` into `clifford_algebra Q`, the `ι` of `x : M`, and is preserved under addition and muliplication, then it holds for all of `clifford_algebra Q`. See also the stronger `clifford_algebra.left_induction` and `clifford_algebra.right_induction`. -/ -- This proof closely follows `tensor_algebra.induction` @[elab_as_eliminator] lemma induction {C : clifford_algebra Q → Prop} (h_grade0 : ∀ r, C (algebra_map R (clifford_algebra Q) r)) (h_grade1 : ∀ x, C (ι Q x)) (h_mul : ∀ a b, C a → C b → C (a * b)) (h_add : ∀ a b, C a → C b → C (a + b)) (a : clifford_algebra Q) : C a := begin -- the arguments are enough to construct a subalgebra, and a mapping into it from M let s : subalgebra R (clifford_algebra Q) := { carrier := C, mul_mem' := h_mul, add_mem' := h_add, algebra_map_mem' := h_grade0, }, let of : { f : M →ₗ[R] s // ∀ m, f m * f m = algebra_map _ _ (Q m) } := ⟨(ι Q).cod_restrict s.to_submodule h_grade1, λ m, subtype.eq $ ι_sq_scalar Q m ⟩, -- the mapping through the subalgebra is the identity have of_id : alg_hom.id R (clifford_algebra Q) = s.val.comp (lift Q of), { ext, simp [of], }, -- finding a proof is finding an element of the subalgebra convert subtype.prop (lift Q of a), exact alg_hom.congr_fun of_id a, end /-- The symmetric product of vectors is a scalar -/ lemma ι_mul_ι_add_swap (a b : M) : ι Q a * ι Q b + ι Q b * ι Q a = algebra_map R _ (quadratic_form.polar Q a b) := calc ι Q a * ι Q b + ι Q b * ι Q a = ι Q (a + b) * ι Q (a + b) - ι Q a * ι Q a - ι Q b * ι Q b : by { rw [(ι Q).map_add, mul_add, add_mul, add_mul], abel, } ... = algebra_map R _ (Q (a + b)) - algebra_map R _ (Q a) - algebra_map R _ (Q b) : by rw [ι_sq_scalar, ι_sq_scalar, ι_sq_scalar] ... = algebra_map R _ (Q (a + b) - Q a - Q b) : by rw [←ring_hom.map_sub, ←ring_hom.map_sub] ... = algebra_map R _ (quadratic_form.polar Q a b) : rfl @[simp] lemma ι_range_map_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebra_map _ _ (Q m)) : (ι Q).range.map (lift Q ⟨f, cond⟩).to_linear_map = f.range := by rw [←linear_map.range_comp, ι_comp_lift] section map variables {M₁ M₂ M₃ : Type*} variables [add_comm_group M₁] [add_comm_group M₂] [add_comm_group M₃] variables [module R M₁] [module R M₂] [module R M₃] variables (Q₁ : quadratic_form R M₁) (Q₂ : quadratic_form R M₂) (Q₃ : quadratic_form R M₃) /-- Any linear map that preserves the quadratic form lifts to an `alg_hom` between algebras. See `clifford_algebra.equiv_of_isometry` for the case when `f` is a `quadratic_form.isometry`. -/ def map (f : M₁ →ₗ[R] M₂) (hf : ∀ m, Q₂ (f m) = Q₁ m) : clifford_algebra Q₁ →ₐ[R] clifford_algebra Q₂ := clifford_algebra.lift Q₁ ⟨(clifford_algebra.ι Q₂).comp f, λ m, (ι_sq_scalar _ _).trans $ ring_hom.congr_arg _ $ hf m⟩ @[simp] lemma map_comp_ι (f : M₁ →ₗ[R] M₂) (hf) : (map Q₁ Q₂ f hf).to_linear_map.comp (ι Q₁) = (ι Q₂).comp f := ι_comp_lift _ _ @[simp] lemma map_apply_ι (f : M₁ →ₗ[R] M₂) (hf) (m : M₁): map Q₁ Q₂ f hf (ι Q₁ m) = ι Q₂ (f m) := lift_ι_apply _ _ m @[simp] lemma map_id : map Q₁ Q₁ (linear_map.id : M₁ →ₗ[R] M₁) (λ m, rfl) = alg_hom.id R (clifford_algebra Q₁) := by { ext m, exact map_apply_ι _ _ _ _ m } @[simp] lemma map_comp_map (f : M₂ →ₗ[R] M₃) (hf) (g : M₁ →ₗ[R] M₂) (hg) : (map Q₂ Q₃ f hf).comp (map Q₁ Q₂ g hg) = map Q₁ Q₃ (f.comp g) (λ m, (hf _).trans $ hg m) := begin ext m, dsimp only [linear_map.comp_apply, alg_hom.comp_apply, alg_hom.to_linear_map_apply, alg_hom.id_apply], rw [map_apply_ι, map_apply_ι, map_apply_ι, linear_map.comp_apply], end @[simp] lemma ι_range_map_map (f : M₁ →ₗ[R] M₂) (hf : ∀ m, Q₂ (f m) = Q₁ m) : (ι Q₁).range.map (map Q₁ Q₂ f hf).to_linear_map = f.range.map (ι Q₂) := (ι_range_map_lift _ _).trans (linear_map.range_comp _ _) variables {Q₁ Q₂ Q₃} /-- Two `clifford_algebra`s are equivalent as algebras if their quadratic forms are equivalent. -/ @[simps apply] def equiv_of_isometry (e : Q₁.isometry Q₂) : clifford_algebra Q₁ ≃ₐ[R] clifford_algebra Q₂ := alg_equiv.of_alg_hom (map Q₁ Q₂ e e.map_app) (map Q₂ Q₁ e.symm e.symm.map_app) ((map_comp_map _ _ _ _ _ _ _).trans $ begin convert map_id _ using 2, ext m, exact e.to_linear_equiv.apply_symm_apply m, end) ((map_comp_map _ _ _ _ _ _ _).trans $ begin convert map_id _ using 2, ext m, exact e.to_linear_equiv.symm_apply_apply m, end) @[simp] lemma equiv_of_isometry_symm (e : Q₁.isometry Q₂) : (equiv_of_isometry e).symm = equiv_of_isometry e.symm := rfl @[simp] lemma equiv_of_isometry_trans (e₁₂ : Q₁.isometry Q₂) (e₂₃ : Q₂.isometry Q₃) : (equiv_of_isometry e₁₂).trans (equiv_of_isometry e₂₃) = equiv_of_isometry (e₁₂.trans e₂₃) := by { ext x, exact alg_hom.congr_fun (map_comp_map Q₁ Q₂ Q₃ _ _ _ _) x } @[simp] lemma equiv_of_isometry_refl : (equiv_of_isometry $ quadratic_form.isometry.refl Q₁) = alg_equiv.refl := by { ext x, exact alg_hom.congr_fun (map_id Q₁) x } end map variables (Q) /-- If the quadratic form of a vector is invertible, then so is that vector. -/ def invertible_ι_of_invertible (m : M) [invertible (Q m)] : invertible (ι Q m) := { inv_of := ι Q (⅟(Q m) • m), inv_of_mul_self := by rw [map_smul, smul_mul_assoc, ι_sq_scalar, algebra.smul_def, ←map_mul, inv_of_mul_self, map_one], mul_inv_of_self := by rw [map_smul, mul_smul_comm, ι_sq_scalar, algebra.smul_def, ←map_mul, inv_of_mul_self, map_one] } /-- For a vector with invertible quadratic form, $v^{-1} = \frac{v}{Q(v)}$ -/ lemma inv_of_ι (m : M) [invertible (Q m)] [invertible (ι Q m)] : ⅟(ι Q m) = ι Q (⅟(Q m) • m) := begin letI := invertible_ι_of_invertible Q m, convert (rfl : ⅟(ι Q m) = _), end lemma is_unit_ι_of_is_unit {m : M} (h : is_unit (Q m)) : is_unit (ι Q m) := begin casesI h.nonempty_invertible, letI := invertible_ι_of_invertible Q m, exactI is_unit_of_invertible (ι Q m), end end clifford_algebra namespace tensor_algebra variables {Q} /-- The canonical image of the `tensor_algebra` in the `clifford_algebra`, which maps `tensor_algebra.ι R x` to `clifford_algebra.ι Q x`. -/ def to_clifford : tensor_algebra R M →ₐ[R] clifford_algebra Q := tensor_algebra.lift R (clifford_algebra.ι Q) @[simp] lemma to_clifford_ι (m : M) : (tensor_algebra.ι R m).to_clifford = clifford_algebra.ι Q m := by simp [to_clifford] end tensor_algebra
30d1775be6468a8210aa2e6f6e18adb803316233
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/list/alist.lean
7948dd8b1f9324088e4b26cee5a3e037106acc89
[]
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
14,065
lean
/- Copyright (c) 2018 Sean Leather. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sean Leather, Mario Carneiro -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.list.sigma import Mathlib.PostPort universes u v l w namespace Mathlib /-! # Association lists -/ /-- `alist β` is a key-value map stored as a `list` (i.e. a linked list). It is a wrapper around certain `list` functions with the added constraint that the list have unique keys. -/ structure alist {α : Type u} (β : α → Type v) where entries : List (sigma β) nodupkeys : list.nodupkeys entries /-- Given `l : list (sigma β)`, create a term of type `alist β` by removing entries with duplicate keys. -/ def list.to_alist {α : Type u} [DecidableEq α] {β : α → Type v} (l : List (sigma β)) : alist β := alist.mk (list.erase_dupkeys l) sorry namespace alist theorem ext {α : Type u} {β : α → Type v} {s : alist β} {t : alist β} : entries s = entries t → s = t := sorry theorem ext_iff {α : Type u} {β : α → Type v} {s : alist β} {t : alist β} : s = t ↔ entries s = entries t := { mp := congr_arg fun {s : alist β} => entries s, mpr := ext } protected instance decidable_eq {α : Type u} {β : α → Type v} [DecidableEq α] [(a : α) → DecidableEq (β a)] : DecidableEq (alist β) := fun (xs ys : alist β) => eq.mpr sorry (list.decidable_eq (entries xs) (entries ys)) /-! ### keys -/ /-- The list of keys of an association list. -/ def keys {α : Type u} {β : α → Type v} (s : alist β) : List α := list.keys (entries s) theorem keys_nodup {α : Type u} {β : α → Type v} (s : alist β) : list.nodup (keys s) := nodupkeys s /-! ### mem -/ /-- The predicate `a ∈ s` means that `s` has a value associated to the key `a`. -/ protected instance has_mem {α : Type u} {β : α → Type v} : has_mem α (alist β) := has_mem.mk fun (a : α) (s : alist β) => a ∈ keys s theorem mem_keys {α : Type u} {β : α → Type v} {a : α} {s : alist β} : a ∈ s ↔ a ∈ keys s := iff.rfl theorem mem_of_perm {α : Type u} {β : α → Type v} {a : α} {s₁ : alist β} {s₂ : alist β} (p : entries s₁ ~ entries s₂) : a ∈ s₁ ↔ a ∈ s₂ := list.perm.mem_iff (list.perm.map sigma.fst p) /-! ### empty -/ /-- The empty association list. -/ protected instance has_emptyc {α : Type u} {β : α → Type v} : has_emptyc (alist β) := has_emptyc.mk (mk [] list.nodupkeys_nil) protected instance inhabited {α : Type u} {β : α → Type v} : Inhabited (alist β) := { default := ∅ } theorem not_mem_empty {α : Type u} {β : α → Type v} (a : α) : ¬a ∈ ∅ := list.not_mem_nil a @[simp] theorem empty_entries {α : Type u} {β : α → Type v} : entries ∅ = [] := rfl @[simp] theorem keys_empty {α : Type u} {β : α → Type v} : keys ∅ = [] := rfl /-! ### singleton -/ /-- The singleton association list. -/ def singleton {α : Type u} {β : α → Type v} (a : α) (b : β a) : alist β := mk [sigma.mk a b] sorry @[simp] theorem singleton_entries {α : Type u} {β : α → Type v} (a : α) (b : β a) : entries (singleton a b) = [sigma.mk a b] := rfl @[simp] theorem keys_singleton {α : Type u} {β : α → Type v} (a : α) (b : β a) : keys (singleton a b) = [a] := rfl /-! ### lookup -/ /-- Look up the value associated to a key in an association list. -/ def lookup {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) (s : alist β) : Option (β a) := list.lookup a (entries s) @[simp] theorem lookup_empty {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) : lookup a ∅ = none := rfl theorem lookup_is_some {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {s : alist β} : ↥(option.is_some (lookup a s)) ↔ a ∈ s := list.lookup_is_some theorem lookup_eq_none {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {s : alist β} : lookup a s = none ↔ ¬a ∈ s := list.lookup_eq_none theorem perm_lookup {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {s₁ : alist β} {s₂ : alist β} (p : entries s₁ ~ entries s₂) : lookup a s₁ = lookup a s₂ := list.perm_lookup a (nodupkeys s₁) (nodupkeys s₂) p protected instance has_mem.mem.decidable {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) (s : alist β) : Decidable (a ∈ s) := decidable_of_iff ↥(option.is_some (lookup a s)) sorry /-! ### replace -/ /-- Replace a key with a given value in an association list. If the key is not present it does nothing. -/ def replace {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) (b : β a) (s : alist β) : alist β := mk (list.kreplace a b (entries s)) sorry @[simp] theorem keys_replace {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) (b : β a) (s : alist β) : keys (replace a b s) = keys s := list.keys_kreplace a b (entries s) @[simp] theorem mem_replace {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {a' : α} {b : β a} {s : alist β} : a' ∈ replace a b s ↔ a' ∈ s := eq.mpr (id (Eq._oldrec (Eq.refl (a' ∈ replace a b s ↔ a' ∈ s)) (propext mem_keys))) (eq.mpr (id (Eq._oldrec (Eq.refl (a' ∈ keys (replace a b s) ↔ a' ∈ s)) (keys_replace a b s))) (eq.mpr (id (Eq._oldrec (Eq.refl (a' ∈ keys s ↔ a' ∈ s)) (Eq.symm (propext mem_keys)))) (iff.refl (a' ∈ s)))) theorem perm_replace {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {b : β a} {s₁ : alist β} {s₂ : alist β} : entries s₁ ~ entries s₂ → entries (replace a b s₁) ~ entries (replace a b s₂) := list.perm.kreplace (nodupkeys s₁) /-- Fold a function over the key-value pairs in the map. -/ def foldl {α : Type u} {β : α → Type v} {δ : Type w} (f : δ → (a : α) → β a → δ) (d : δ) (m : alist β) : δ := list.foldl (fun (r : δ) (a : sigma β) => f r (sigma.fst a) (sigma.snd a)) d (entries m) /-! ### erase -/ /-- Erase a key from the map. If the key is not present, do nothing. -/ def erase {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) (s : alist β) : alist β := mk (list.kerase a (entries s)) sorry @[simp] theorem keys_erase {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) (s : alist β) : keys (erase a s) = list.erase (keys s) a := sorry @[simp] theorem mem_erase {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {a' : α} {s : alist β} : a' ∈ erase a s ↔ a' ≠ a ∧ a' ∈ s := sorry theorem perm_erase {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {s₁ : alist β} {s₂ : alist β} : entries s₁ ~ entries s₂ → entries (erase a s₁) ~ entries (erase a s₂) := list.perm.kerase (nodupkeys s₁) @[simp] theorem lookup_erase {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) (s : alist β) : lookup a (erase a s) = none := list.lookup_kerase a (nodupkeys s) @[simp] theorem lookup_erase_ne {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {a' : α} {s : alist β} (h : a ≠ a') : lookup a (erase a' s) = lookup a s := list.lookup_kerase_ne h theorem erase_erase {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) (a' : α) (s : alist β) : erase a' (erase a s) = erase a (erase a' s) := ext list.kerase_kerase /-! ### insert -/ /-- Insert a key-value pair into an association list and erase any existing pair with the same key. -/ def insert {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) (b : β a) (s : alist β) : alist β := mk (list.kinsert a b (entries s)) sorry @[simp] theorem insert_entries {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {b : β a} {s : alist β} : entries (insert a b s) = sigma.mk a b :: list.kerase a (entries s) := rfl theorem insert_entries_of_neg {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {b : β a} {s : alist β} (h : ¬a ∈ s) : entries (insert a b s) = sigma.mk a b :: entries s := sorry @[simp] theorem mem_insert {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {a' : α} {b' : β a'} (s : alist β) : a ∈ insert a' b' s ↔ a = a' ∨ a ∈ s := list.mem_keys_kinsert @[simp] theorem keys_insert {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {b : β a} (s : alist β) : keys (insert a b s) = a :: list.erase (keys s) a := sorry theorem perm_insert {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {b : β a} {s₁ : alist β} {s₂ : alist β} (p : entries s₁ ~ entries s₂) : entries (insert a b s₁) ~ entries (insert a b s₂) := sorry @[simp] theorem lookup_insert {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {b : β a} (s : alist β) : lookup a (insert a b s) = some b := sorry @[simp] theorem lookup_insert_ne {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {a' : α} {b' : β a'} {s : alist β} (h : a ≠ a') : lookup a (insert a' b' s) = lookup a s := list.lookup_kinsert_ne h @[simp] theorem lookup_to_alist {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} (s : List (sigma β)) : lookup a (list.to_alist s) = list.lookup a s := sorry @[simp] theorem insert_insert {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {b : β a} {b' : β a} (s : alist β) : insert a b' (insert a b s) = insert a b' s := sorry theorem insert_insert_of_ne {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {a' : α} {b : β a} {b' : β a'} (s : alist β) (h : a ≠ a') : entries (insert a' b' (insert a b s)) ~ entries (insert a b (insert a' b' s)) := sorry @[simp] theorem insert_singleton_eq {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {b : β a} {b' : β a} : insert a b (singleton a b') = singleton a b := sorry @[simp] theorem entries_to_alist {α : Type u} {β : α → Type v} [DecidableEq α] (xs : List (sigma β)) : entries (list.to_alist xs) = list.erase_dupkeys xs := rfl theorem to_alist_cons {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) (b : β a) (xs : List (sigma β)) : list.to_alist (sigma.mk a b :: xs) = insert a b (list.to_alist xs) := rfl /-! ### extract -/ /-- Erase a key from the map, and return the corresponding value, if found. -/ def extract {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) (s : alist β) : Option (β a) × alist β := (fun (this : list.nodupkeys (prod.snd (list.kextract a (entries s)))) => sorry) sorry @[simp] theorem extract_eq_lookup_erase {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) (s : alist β) : extract a s = (lookup a s, erase a s) := sorry /-! ### union -/ /-- `s₁ ∪ s₂` is the key-based union of two association lists. It is left-biased: if there exists an `a ∈ s₁`, `lookup a (s₁ ∪ s₂) = lookup a s₁`. -/ def union {α : Type u} {β : α → Type v} [DecidableEq α] (s₁ : alist β) (s₂ : alist β) : alist β := mk (list.kunion (entries s₁) (entries s₂)) sorry protected instance has_union {α : Type u} {β : α → Type v} [DecidableEq α] : has_union (alist β) := has_union.mk union @[simp] theorem union_entries {α : Type u} {β : α → Type v} [DecidableEq α] {s₁ : alist β} {s₂ : alist β} : entries (s₁ ∪ s₂) = list.kunion (entries s₁) (entries s₂) := rfl @[simp] theorem empty_union {α : Type u} {β : α → Type v} [DecidableEq α] {s : alist β} : ∅ ∪ s = s := ext rfl @[simp] theorem union_empty {α : Type u} {β : α → Type v} [DecidableEq α] {s : alist β} : s ∪ ∅ = s := sorry @[simp] theorem mem_union {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {s₁ : alist β} {s₂ : alist β} : a ∈ s₁ ∪ s₂ ↔ a ∈ s₁ ∨ a ∈ s₂ := list.mem_keys_kunion theorem perm_union {α : Type u} {β : α → Type v} [DecidableEq α] {s₁ : alist β} {s₂ : alist β} {s₃ : alist β} {s₄ : alist β} (p₁₂ : entries s₁ ~ entries s₂) (p₃₄ : entries s₃ ~ entries s₄) : entries (s₁ ∪ s₃) ~ entries (s₂ ∪ s₄) := sorry theorem union_erase {α : Type u} {β : α → Type v} [DecidableEq α] (a : α) (s₁ : alist β) (s₂ : alist β) : erase a (s₁ ∪ s₂) = erase a s₁ ∪ erase a s₂ := ext (Eq.symm list.kunion_kerase) @[simp] theorem lookup_union_left {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {s₁ : alist β} {s₂ : alist β} : a ∈ s₁ → lookup a (s₁ ∪ s₂) = lookup a s₁ := list.lookup_kunion_left @[simp] theorem lookup_union_right {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {s₁ : alist β} {s₂ : alist β} : ¬a ∈ s₁ → lookup a (s₁ ∪ s₂) = lookup a s₂ := list.lookup_kunion_right @[simp] theorem mem_lookup_union {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {b : β a} {s₁ : alist β} {s₂ : alist β} : b ∈ lookup a (s₁ ∪ s₂) ↔ b ∈ lookup a s₁ ∨ ¬a ∈ s₁ ∧ b ∈ lookup a s₂ := list.mem_lookup_kunion theorem mem_lookup_union_middle {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {b : β a} {s₁ : alist β} {s₂ : alist β} {s₃ : alist β} : b ∈ lookup a (s₁ ∪ s₃) → ¬a ∈ s₂ → b ∈ lookup a (s₁ ∪ s₂ ∪ s₃) := list.mem_lookup_kunion_middle theorem insert_union {α : Type u} {β : α → Type v} [DecidableEq α] {a : α} {b : β a} {s₁ : alist β} {s₂ : alist β} : insert a b (s₁ ∪ s₂) = insert a b s₁ ∪ s₂ := sorry theorem union_assoc {α : Type u} {β : α → Type v} [DecidableEq α] {s₁ : alist β} {s₂ : alist β} {s₃ : alist β} : entries (s₁ ∪ s₂ ∪ s₃) ~ entries (s₁ ∪ (s₂ ∪ s₃)) := sorry /-! ### disjoint -/ /-- Two associative lists are disjoint if they have no common keys. -/ def disjoint {α : Type u} {β : α → Type v} (s₁ : alist β) (s₂ : alist β) := ∀ (k : α), k ∈ keys s₁ → ¬k ∈ keys s₂ theorem union_comm_of_disjoint {α : Type u} {β : α → Type v} [DecidableEq α] {s₁ : alist β} {s₂ : alist β} (h : disjoint s₁ s₂) : entries (s₁ ∪ s₂) ~ entries (s₂ ∪ s₁) := sorry
ad5b95ec32326da0c5b2f28fe508a7ca16368148
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/data/erased.lean
b98121ec35ca8c94e3f84950202651bc8f8a4327
[ "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
2,124
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro A type for VM-erased data. -/ import data.equiv.basic /-- `erased α` is the same as `α`, except that the elements of `erased α` are erased in the VM in the same way as types and proofs. This can be used to track data without storing it literally. -/ def erased (α : Sort*) : Sort* := Σ' s : α → Prop, ∃ a, (λ b, a = b) = s namespace erased @[inline] def mk {α} (a : α) : erased α := ⟨λ b, a = b, a, rfl⟩ noncomputable def out {α} : erased α → α | ⟨s, h⟩ := classical.some h @[reducible] def out_type (a : erased Sort*) : Sort* := out a theorem out_proof {p : Prop} (a : erased p) : p := out a @[simp] theorem out_mk {α} (a : α) : (mk a).out = a := begin let h, show classical.some h = a, have := classical.some_spec h, exact cast (congr_fun this a).symm rfl end @[simp] theorem mk_out {α} : ∀ (a : erased α), mk (out a) = a | ⟨s, h⟩ := by simp [mk]; congr; exact classical.some_spec h noncomputable def equiv (α) : erased α ≃ α := ⟨out, mk, mk_out, out_mk⟩ instance (α : Type*) : has_repr (erased α) := ⟨λ _, "erased"⟩ def choice {α} (h : nonempty α) : erased α := mk (classical.choice h) theorem nonempty_iff {α} : nonempty (erased α) ↔ nonempty α := ⟨λ ⟨a⟩, ⟨a.out⟩, λ ⟨a⟩, ⟨mk a⟩⟩ instance {α} [h : nonempty α] : nonempty (erased α) := erased.nonempty_iff.2 h instance {α} [h : inhabited α] : inhabited (erased α) := ⟨mk (default _)⟩ def bind {α β} (a : erased α) (f : α → erased β) : erased β := ⟨λ b, (f a.out).1 b, (f a.out).2⟩ @[simp] theorem bind_eq_out {α β} (a f) : @bind α β a f = f a.out := by delta bind bind._proof_1; cases f a.out; refl def join {α} (a : erased (erased α)) : erased α := bind a id @[simp] theorem join_eq_out {α} (a) : @join α a = a.out := bind_eq_out _ _ instance : monad erased := { pure := @mk, bind := @bind } instance : is_lawful_monad erased := by refine {..}; intros; simp end erased
d33dd74621c93db83e026fff78830f9d48929035
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/order/galois_connection.lean
ac42735154f25c76ba22375cc73405fdaa61bf90
[ "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
10,481
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Johannes Hölzl Galois connections - order theoretic adjoints. -/ import order.bounds open function set lattice universes u v w x variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {a a₁ a₂ : α} {b b₁ b₂ : β} /-- A Galois connection is a pair of functions `l` and `u` satisfying `l a ≤ b ↔ a ≤ u b`. They are closely connected to adjoint functors in category theory. -/ def galois_connection [preorder α] [preorder β] (l : α → β) (u : β → α) := ∀a b, l a ≤ b ↔ a ≤ u b namespace galois_connection section variables [preorder α] [preorder β] {l : α → β} {u : β → α} (gc : galois_connection l u) lemma monotone_intro (hu : monotone u) (hl : monotone l) (hul : ∀ a, a ≤ u (l a)) (hlu : ∀ a, l (u a) ≤ a) : galois_connection l u := assume a b, ⟨assume h, le_trans (hul _) (hu h), assume h, le_trans (hl h) (hlu _)⟩ include gc lemma l_le {a : α} {b : β} : a ≤ u b → l a ≤ b := (gc _ _).mpr lemma le_u {a : α} {b : β} : l a ≤ b → a ≤ u b := (gc _ _).mp lemma le_u_l (a) : a ≤ u (l a) := gc.le_u $ le_refl _ lemma l_u_le (a) : l (u a) ≤ a := gc.l_le $ le_refl _ lemma monotone_u : monotone u := assume a b H, gc.le_u (le_trans (gc.l_u_le a) H) lemma monotone_l : monotone l := assume a b H, gc.l_le (le_trans H (gc.le_u_l b)) lemma upper_bounds_l_image_subset {s : set α} : upper_bounds (l '' s) ⊆ u ⁻¹' upper_bounds s := assume b hb c, assume : c ∈ s, gc.le_u (hb _ (mem_image_of_mem _ ‹c ∈ s›)) lemma lower_bounds_u_image_subset {s : set β} : lower_bounds (u '' s) ⊆ l ⁻¹' lower_bounds s := assume a ha c, assume : c ∈ s, gc.l_le (ha _ (mem_image_of_mem _ ‹c ∈ s›)) lemma is_lub_l_image {s : set α} {a : α} (h : is_lub s a) : is_lub (l '' s) (l a) := ⟨mem_upper_bounds_image gc.monotone_l $ and.elim_left ‹is_lub s a›, assume b hb, gc.l_le $ and.elim_right ‹is_lub s a› _ $ gc.upper_bounds_l_image_subset hb⟩ lemma is_glb_u_image {s : set β} {b : β} (h : is_glb s b) : is_glb (u '' s) (u b) := ⟨mem_lower_bounds_image gc.monotone_u $ and.elim_left ‹is_glb s b›, assume a ha, gc.le_u $ and.elim_right ‹is_glb s b› _ $ gc.lower_bounds_u_image_subset ha⟩ lemma is_glb_l {a : α} : is_glb { b | a ≤ u b } (l a) := ⟨assume b, gc.l_le, assume b h, h _ $ gc.le_u_l _⟩ lemma is_lub_u {b : β} : is_lub { a | l a ≤ b } (u b) := ⟨assume b, gc.le_u, assume b h, h _ $ gc.l_u_le _⟩ end section partial_order variables [partial_order α] [partial_order β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma u_l_u_eq_u : u ∘ l ∘ u = u := funext (assume x, le_antisymm (gc.monotone_u (gc.l_u_le _)) (gc.le_u_l _)) lemma l_u_l_eq_l : l ∘ u ∘ l = l := funext (assume x, le_antisymm (gc.l_u_le _) (gc.monotone_l (gc.le_u_l _))) end partial_order section order_top variables [order_top α] [order_top β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma u_top : u ⊤ = ⊤ := eq_of_is_glb_of_is_glb (gc.is_glb_u_image is_glb_empty) $ by simp [is_glb_empty, image_empty] end order_top section order_bot variables [order_bot α] [order_bot β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma l_bot : l ⊥ = ⊥ := eq_of_is_lub_of_is_lub (gc.is_lub_l_image is_lub_empty) $ by simp [is_lub_empty, image_empty] end order_bot section semilattice_sup variables [semilattice_sup α] [semilattice_sup β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma l_sup : l (a₁ ⊔ a₂) = l a₁ ⊔ l a₂ := have {l a₂, l a₁} = l '' {a₂, a₁}, by simp [image_insert_eq, image_singleton], eq.symm $ is_lub_iff_sup_eq.mp $ by rw [this]; exact gc.is_lub_l_image (is_lub_insert_sup is_lub_singleton) end semilattice_sup section semilattice_inf variables [semilattice_inf α] [semilattice_inf β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma u_inf : u (b₁ ⊓ b₂) = u b₁ ⊓ u b₂ := have {u b₂, u b₁} = u '' {b₂, b₁}, by simp [image_insert_eq, image_singleton], eq.symm $ is_glb_iff_inf_eq.mp $ by rw [this]; exact gc.is_glb_u_image (is_glb_insert_inf is_glb_singleton) end semilattice_inf section complete_lattice variables [complete_lattice α] [complete_lattice β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma l_supr {f : ι → α} : l (supr f) = (⨆i, l (f i)) := eq.symm $ is_lub_iff_supr_eq.mp $ show is_lub (range (l ∘ f)) (l (supr f)), by rw [range_comp, ← Sup_range]; exact gc.is_lub_l_image is_lub_Sup lemma u_infi {f : ι → β} : u (infi f) = (⨅i, u (f i)) := eq.symm $ is_glb_iff_infi_eq.mp $ show is_glb (range (u ∘ f)) (u (infi f)), by rw [range_comp, ← Inf_range]; exact gc.is_glb_u_image is_glb_Inf end complete_lattice section complete_lattice variables [complete_lattice α] [complete_lattice β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma l_Sup {s : set α} : l (Sup s) = (⨆a∈s, l a) := by simp [Sup_eq_supr, gc.l_supr] lemma u_Inf {s : set β} : u (Inf s) = (⨅a∈s, u a) := by simp [Inf_eq_infi, gc.u_infi] end complete_lattice /- Constructing Galois connections -/ section constructions protected lemma id [pα : preorder α] : @galois_connection α α pα pα id id := assume a b, iff.intro (λx, x) (λx, x) protected lemma compose [preorder α] [preorder β] [preorder γ] (l1 : α → β) (u1 : β → α) (l2 : β → γ) (u2 : γ → β) (gc1 : galois_connection l1 u1) (gc2 : galois_connection l2 u2) : galois_connection (l2 ∘ l1) (u1 ∘ u2) := by intros a b; rw [gc2, gc1] protected lemma dual [pα : preorder α] [pβ : preorder β] {l : α → β} {u : β → α} (gc : galois_connection l u) : @galois_connection (order_dual β) (order_dual α) _ _ u l := assume a b, (gc _ _).symm protected lemma dfun {ι : Type u} {α : ι → Type v} {β : ι → Type w} [∀i, preorder (α i)] [∀i, preorder (β i)] (l : Πi, α i → β i) (u : Πi, β i → α i) (gc : ∀i, galois_connection (l i) (u i)) : @galois_connection (Π i, α i) (Π i, β i) _ _ (λa i, l i (a i)) (λb i, u i (b i)) := assume a b, forall_congr $ assume i, gc i (a i) (b i) end constructions end galois_connection namespace nat lemma galois_connection_mul_div {k : ℕ} (h : k > 0) : galois_connection (λn, n * k) (λn, n / k) := assume x y, (le_div_iff_mul_le x y h).symm end nat /-- A Galois insertion is a Galois connection where `l ∘ u = id`. It also contains a constructive choice function, to give better definitional equalities when lifting order structures. -/ structure galois_insertion {α β : Type*} [preorder α] [preorder β] (l : α → β) (u : β → α) := (choice : Πx:α, u (l x) ≤ x → β) (gc : galois_connection l u) (le_l_u : ∀x, x ≤ l (u x)) (choice_eq : ∀a h, choice a h = l a) /-- Lift the bottom along a Galois connection -/ def galois_connection.lift_order_bot {α β : Type*} [order_bot α] [partial_order β] {l : α → β} {u : β → α} (gc : galois_connection l u) : order_bot β := { bot := l ⊥, bot_le := assume b, gc.l_le $ bot_le, .. ‹partial_order β› } namespace galois_insertion open lattice variables [partial_order β] {l : α → β} {u : β → α} lemma l_u_eq [preorder α] (gi : galois_insertion l u) (b : β) : l (u b) = b := le_antisymm (gi.gc.l_u_le _) (gi.le_l_u _) /-- Lift the suprema along a Galois insertion -/ def lift_semilattice_sup [semilattice_sup α] (gi : galois_insertion l u) : semilattice_sup β := { sup := λa b, l (u a ⊔ u b), le_sup_left := assume a b, le_trans (gi.le_l_u a) $ gi.gc.monotone_l $ le_sup_left, le_sup_right := assume a b, le_trans (gi.le_l_u b) $ gi.gc.monotone_l $ le_sup_right, sup_le := assume a b c hac hbc, gi.gc.l_le $ sup_le (gi.gc.monotone_u hac) (gi.gc.monotone_u hbc), .. ‹partial_order β› } /-- Lift the infima along a Galois insertion -/ def lift_semilattice_inf [semilattice_inf α] (gi : galois_insertion l u) : semilattice_inf β := { inf := λa b, gi.choice (u a ⊓ u b) $ (le_inf (gi.gc.monotone_u $ gi.gc.l_le $ inf_le_left) (gi.gc.monotone_u $ gi.gc.l_le $ inf_le_right)), inf_le_left := by simp only [gi.choice_eq]; exact assume a b, gi.gc.l_le inf_le_left, inf_le_right := by simp only [gi.choice_eq]; exact assume a b, gi.gc.l_le inf_le_right, le_inf := by simp only [gi.choice_eq]; exact assume a b c hac hbc, le_trans (gi.le_l_u a) $ gi.gc.monotone_l $ le_inf (gi.gc.monotone_u hac) (gi.gc.monotone_u hbc), .. ‹partial_order β› } /-- Lift the suprema and infima along a Galois insertion -/ def lift_lattice [lattice α] (gi : galois_insertion l u) : lattice β := { .. gi.lift_semilattice_sup, .. gi.lift_semilattice_inf } /-- Lift the top along a Galois insertion -/ def lift_order_top [order_top α] (gi : galois_insertion l u) : order_top β := { top := gi.choice ⊤ $ le_top, le_top := by simp only [gi.choice_eq]; exact assume b, le_trans (gi.le_l_u b) (gi.gc.monotone_l le_top), .. ‹partial_order β› } /-- Lift the top, bottom, suprema, and infima along a Galois insertion -/ def lift_bounded_lattice [bounded_lattice α] (gi : galois_insertion l u) : bounded_lattice β := { .. gi.lift_lattice, .. gi.lift_order_top, .. gi.gc.lift_order_bot } /-- Lift all suprema and infima along a Galois insertion -/ def lift_complete_lattice [complete_lattice α] (gi : galois_insertion l u) : complete_lattice β := { Sup := λs, l (⨆ b∈s, u b), Sup_le := assume s a hs, gi.gc.l_le $ supr_le $ assume b, supr_le $ assume hb, gi.gc.monotone_u $ hs _ hb, le_Sup := assume s a ha, le_trans (gi.le_l_u a) $ gi.gc.monotone_l $ le_supr_of_le a $ le_supr_of_le ha $ le_refl _, Inf := λs, gi.choice (⨅ b∈s, u b) $ le_infi $ assume b, le_infi $ assume hb, gi.gc.monotone_u $ gi.gc.l_le $ infi_le_of_le b $ infi_le_of_le hb $ le_refl _, Inf_le := by simp only [gi.choice_eq]; exact assume s a ha, gi.gc.l_le $ infi_le_of_le a $ infi_le_of_le ha $ le_refl _, le_Inf := by simp only [gi.choice_eq]; exact assume s a hs, le_trans (gi.le_l_u a) $ gi.gc.monotone_l $ le_infi $ assume b, show u a ≤ ⨅ (H : b ∈ s), u b, from le_infi $ assume hb, gi.gc.monotone_u $ hs _ hb, .. gi.lift_bounded_lattice } end galois_insertion
d1e21191ba56211ab1075c44b0150b43655458e9
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/tests/lean/run/meta4.lean
9219811936a9237c966ff3955b6c4cc9a010b063
[ "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
1,324
lean
import Init.Lean.Meta open Lean open Lean.Meta def print (msg : MessageData) : MetaM Unit := trace! `Meta.debug msg def check (x : MetaM Bool) : MetaM Unit := unlessM x $ throw $ Exception.other "check failed" axiom Ax : forall (α β : Type), α → β → DecidableEq β set_option trace.Meta true def tst1 : MetaM Unit := do cinfo ← getConstInfo `Ax; (_, _, e) ← forallMetaTelescopeReducing cinfo.type (some 0); check (pure (!e.hasMVar)); print e; (_, _, e) ← forallMetaTelescopeReducing cinfo.type (some 1); check (pure e.hasMVar); check (pure e.isForall); print e; (_, _, e) ← forallMetaTelescopeReducing cinfo.type (some 5); check (pure e.hasMVar); check (pure e.isForall); print e; (_, _, e) ← forallMetaTelescopeReducing cinfo.type (some 6); check (pure e.hasMVar); check (pure (!e.isForall)); print e; (_, _, e') ← forallMetaTelescopeReducing cinfo.type; print e'; check (isDefEq e e'); forallBoundedTelescope cinfo.type (some 0) $ fun xs body => check (pure (xs.size == 0)); forallBoundedTelescope cinfo.type (some 1) $ fun xs body => check (pure (xs.size == 1)); forallBoundedTelescope cinfo.type (some 6) $ fun xs body => do { print xs; check (pure (xs.size == 6)) }; forallBoundedTelescope cinfo.type (some 10) $ fun xs body => do { print xs; check (pure (xs.size == 6)) }; pure () #eval tst1
7a645f6b5adb451ecb0153615813adae1ed3b01e
b3c7090f393c11bd47c82d2f8bb4edf8213173f5
/src/subgroup.lean
92637a138d07547d497fb2de25915bc688b0541a
[]
no_license
ImperialCollegeLondon/lean-groups
964b197478f0313d826073576a3e0ae8b166a584
9a82d2a66ef7f549107fcb4e1504d734c43ebb33
refs/heads/master
1,592,371,184,330
1,567,197,270,000
1,567,197,270,000
195,810,480
4
0
null
null
null
null
UTF-8
Lean
false
false
1,474
lean
-- bundled subgroups -- We're going to make one object which is all the subgroups of G. -- first let's do some tests import group_theory.subgroup import algebra.group.hom --#print notation ↥ --coe_sort #0 --#print notation ↑ --coe example (G1 G2 : Type*) [group G1] [group G2] (f : G1 → G2) [is_group_hom f] (H1 : set G1) [is_subgroup H1] (a b : H1) : is_subgroup (f '' H1) := { one_mem := begin show (1:G2) ∈ f '' H1, unfold set.image, use (1), split, {exact is_submonoid.one_mem H1}, {exact is_group_hom.map_one f} end, mul_mem := begin -- intro j, -- intro k, -- intro n, -- change j ∈ f '' H1 at n, -- intro m, -- change k ∈ f '' H1 at m, -- show j*k ∈ f '' H1, -- cases n with j' hj', -- cases m with k' hk', rintro j k ⟨j', hj', rfl⟩ ⟨k', hk', rfl⟩, show (f j') * (f k') ∈ f '' H1, rw [← is_mul_hom.map_mul f j' k'], unfold set.image, dsimp, use j'*k', split, apply is_submonoid.mul_mem, assumption, assumption, refl, -- need to get rid of the fs --apply is_submonoid.mul_mem, end, inv_mem := begin --intro j, --intro n, --change j ∈ f '' H1 at n, --show j⁻¹ ∈ f '' H1, rintro j ⟨j', hj', rfl⟩, show (f j')⁻¹ ∈ f '' H1, rw [← is_group_hom.map_inv f j'], unfold set.image, dsimp, use j'⁻¹, split, rw [is_subgroup.inv_mem_iff H1], assumption, refl, -- need to get rid of the fs --rw [is_subgroup.inv_mem_iff H1], end }
f5250f710f07d02a1e757eedd959b5e4d4335eaa
e0f9ba56b7fedc16ef8697f6caeef5898b435143
/src/ring_theory/fractional_ideal.lean
c6674e28d83b9240ff1a05c0087c389256c101ad
[ "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
14,243
lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen Fractional ideals of an integral domain. -/ import ring_theory.localization /-! # Fractional ideals This file defines fractional ideals of an integral domain and proves basic facts about them. ## Main definitions * `is_fractional` defines which `R`-submodules of `localization R S` are fractional ideals * `fractional_ideal R S` is the type of fractional ideals in `localization R S` * `has_coe (ideal R) (fractional_ideal R S)` instance * `comm_semiring (fractional_ideal R S)` instance: the typical ideal operations generalized to fractional ideals * `lattice (fractional_ideal R S)` instance * `has_div (fractional_ideal R (non_zero_divisors R))` instance: the ideal quotient `I / J` (typically written $I : J$, but a `:` operator cannot be defined) ## Main statements * `mul_left_mono` and `mul_right_mono` state that ideal multiplication is monotone * `right_inverse_eq` states that `1 / I` is the inverse of `I` if one exists ## Implementation notes Fractional ideals are considered equal when they contain the same elements, independent of the denominator `a : R` such that `a I ⊆ R`. Thus, we define `fractional_ideal` to be the subtype of the predicate `is_fractional`, instead of having `fractional_ideal` be a structure of which `a` is a field. Most definitions in this file specialize operations from submodules to fractional ideals, proving that the result of this operation is fractional if the input is fractional. Exceptions to this rule are defining `(+) := (⊔)` and `⊥ := 0`, in order to re-use their respective proof terms. We can still use `simp` to show `I.1 + J.1 = (I + J).1` and `⊥.1 = 0.1`. We don't assume that `localization R S` is a field until we need it to define ideal quotients. When this assumption is needed, we replace `S` with `non_zero_divisors R`, making `localization R (non_zero_divisors R) = fraction_ring R` into a field since `R` is a domain. ## References * https://en.wikipedia.org/wiki/Fractional_ideal ## Tags fractional ideal, fractional ideals, invertible ideal -/ open localization universes u v w namespace ring section defs variables (R : Type u) [integral_domain R] (S : set R) [is_submonoid S] /-- A submodule `I` is a fractional ideal if `a I ⊆ R` for some `a ≠ 0`. -/ def is_fractional (I : submodule R (localization R S)) := ∃ a ≠ (0 : R), ∀ b ∈ I, is_integer R S (a • b) /-- The fractional ideals of a domain `R` are ideals of `R` divided by some `a ∈ R`. More precisely, let `R'` be a localization of `R` at some submonoid `S`, then a fractional ideal `I ⊆ R'` is an `R`-submodule of `R'`, such that there is a nonzero `a : R` with `a I ⊆ R`. -/ def fractional_ideal := {I : submodule R (localization R S) // is_fractional R S I} end defs namespace fractional_ideal open set open submodule variables {R : Type u} [integral_domain R] {S : set R} [is_submonoid S] instance : has_mem (localization R S) (fractional_ideal R S) := ⟨λ x I, x ∈ I.1⟩ /-- Fractional ideals are equal if their submodules are equal. Combined with `submodule.ext` this gives that fractional ideals are equal if they have the same elements. -/ @[ext] lemma ext {I J : fractional_ideal R S} : I.1 = J.1 → I = J := subtype.ext.mpr lemma fractional_of_subset_one (I : submodule R (localization R S)) (h : I ≤ 1) : is_fractional R S I := begin use 1, use one_ne_zero, intros b hb, obtain ⟨b', b'_mem, b'_eq_b⟩ := h hb, convert is_integer_coe R b', simp [b'_eq_b.symm] end instance coe_to_fractional_ideal : has_coe (ideal R) (fractional_ideal R S) := ⟨ λ I, ⟨ ↑I, fractional_of_subset_one _ (image_subset _ (subset_univ _)) ⟩ ⟩ instance : has_zero (fractional_ideal R S) := ⟨(0 : ideal R)⟩ @[simp] lemma mem_zero_iff {x : localization R S} : x ∈ (0 : fractional_ideal R S) ↔ x = 0 := ⟨ (λ ⟨x', x'_mem_zero, x'_eq_x⟩, have x'_eq_zero : x' = 0 := (or_false _).mp x'_mem_zero, by simp [x'_eq_x.symm, x'_eq_zero]), (λ hx, ⟨0, or.inl rfl, by simp [hx]⟩) ⟩ @[simp] lemma val_zero : (0 : fractional_ideal R S).1 = 0 := begin ext, split; intro h; convert submodule.zero _, { rw [mem_zero_iff.mp h] }, { exact (or_false _).mp h } end lemma nonzero_iff_val_nonzero {I : fractional_ideal R S} : I.1 ≠ 0 ↔ I ≠ 0 := ⟨ λ h h', h (by simp [h']), λ h h', h (ext (by simp [h'])) ⟩ instance : inhabited (fractional_ideal R S) := ⟨0⟩ instance : has_one (fractional_ideal R S) := ⟨(1 : ideal R)⟩ lemma mem_one_iff {x : localization R S} : x ∈ (1 : fractional_ideal R S) ↔ ∃ x' : R, ↑x' = x := iff.intro (λ ⟨x', _, h⟩, ⟨x', h⟩) (λ ⟨x', h⟩, ⟨x', ⟨x', set.mem_univ _, rfl⟩, h⟩) lemma coe_mem_one (x : R) : (x : localization R S) ∈ (1 : fractional_ideal R S) := mem_one_iff.mpr ⟨x, rfl⟩ section lattice /-! ### `lattice` section Defines the order on fractional ideals as inclusion of their underlying sets, and ports the lattice structure on submodules to fractional ideals. -/ instance : partial_order (fractional_ideal R S) := { le := λ I J, I.1 ≤ J.1, le_refl := λ I, le_refl I.1, le_antisymm := λ ⟨I, hI⟩ ⟨J, hJ⟩ hIJ hJI, by { congr, exact le_antisymm hIJ hJI }, le_trans := λ _ _ _ hIJ hJK, le_trans hIJ hJK } lemma le_iff {I J : fractional_ideal R S} : I ≤ J ↔ (∀ x ∈ I, x ∈ J) := iff.refl _ lemma zero_le (I : fractional_ideal R S) : 0 ≤ I := begin intros x hx, convert submodule.zero _, simpa using hx end instance order_bot : order_bot (fractional_ideal R S) := { bot := 0, bot_le := zero_le, ..fractional_ideal.partial_order } @[simp] lemma bot_eq_zero : (⊥ : fractional_ideal R S) = 0 := rfl lemma eq_zero_iff {I : fractional_ideal R S} : I = 0 ↔ (∀ x ∈ I, x = (0 : localization R S)) := ⟨ (λ h x hx, by simpa [h, mem_zero_iff] using hx), (λ h, le_bot_iff.mp (λ x hx, mem_zero_iff.mpr (h x hx))) ⟩ lemma fractional_sup (I J : fractional_ideal R S) : is_fractional R S (I.1 ⊔ J.1) := begin rcases I.2 with ⟨aI, haI, hI⟩, rcases J.2 with ⟨aJ, haJ, hJ⟩, use aI * aJ, use mul_ne_zero haI haJ, intros b hb, rcases mem_sup.mp hb with ⟨bI, hbI, bJ, hbJ, hbIJ⟩, rw [←hbIJ, smul_add], apply is_integer_add, { rw [mul_comm, mul_smul], apply is_integer_smul _ (hI bI hbI) }, { rw [mul_smul], apply is_integer_smul _ (hJ bJ hbJ) } end lemma fractional_inf (I J : fractional_ideal R S) : is_fractional R S (I.1 ⊓ J.1) := begin rcases I.2 with ⟨aI, haI, hI⟩, use aI, use haI, intros b hb, rcases mem_inf.mp hb with ⟨hbI, hbJ⟩, exact (hI b hbI) end instance lattice : lattice (fractional_ideal R S) := { inf := λ I J, ⟨I.1 ⊓ J.1, fractional_inf I J⟩, sup := λ I J, ⟨I.1 ⊔ J.1, fractional_sup I J⟩, inf_le_left := λ I J, show I.1 ⊓ J.1 ≤ I.1, from inf_le_left, inf_le_right := λ I J, show I.1 ⊓ J.1 ≤ J.1, from inf_le_right, le_inf := λ I J K hIJ hIK, show I.1 ≤ (J.1 ⊓ K.1), from le_inf hIJ hIK, le_sup_left := λ I J, show I.1 ≤ I.1 ⊔ J.1, from le_sup_left, le_sup_right := λ I J, show J.1 ≤ I.1 ⊔ J.1, from le_sup_right, sup_le := λ I J K hIK hJK, show (I.1 ⊔ J.1) ≤ K.1, from sup_le hIK hJK, ..fractional_ideal.partial_order } instance : semilattice_sup_bot (fractional_ideal R S) := { ..fractional_ideal.order_bot, ..fractional_ideal.lattice } end lattice section semiring instance : has_add (fractional_ideal R S) := ⟨(⊔)⟩ @[simp] lemma sup_eq_add (I J : fractional_ideal R S) : I ⊔ J = I + J := rfl @[simp] lemma val_add (I J : fractional_ideal R S) : (I + J).1 = I.1 + J.1 := rfl lemma fractional_mul (I J : fractional_ideal R S) : is_fractional R S (I.1 * J.1) := begin rcases I with ⟨I, aI, haI, hI⟩, rcases J with ⟨I, aJ, haJ, hJ⟩, use aI * aJ, use mul_ne_zero haI haJ, intros b hb, apply submodule.mul_induction_on hb, { intros m hm n hn, obtain ⟨n', hn'⟩ := hJ n hn, rw [mul_smul, ←algebra.mul_smul_comm, ←hn', mul_comm], apply hI, exact submodule.smul _ _ hm }, { rw [smul_zero], apply is_integer_coe }, { intros x y hx hy, rw [smul_add], apply is_integer_add _ hx hy }, { intros r x hx, rw [←mul_smul, mul_comm, mul_smul], apply is_integer_smul _ hx }, end instance : has_mul (fractional_ideal R S) := ⟨λ I J, ⟨I.1 * J.1, fractional_mul I J⟩⟩ @[simp] lemma val_mul (I J : fractional_ideal R S) : (I * J).1 = I.1 * J.1 := rfl lemma mul_left_mono (I : fractional_ideal R S) : monotone ((*) I) := λ J J' h, mul_le.mpr (λ x hx y hy, mul_mem_mul hx (h hy)) lemma mul_right_mono (I : fractional_ideal R S) : monotone (λ J, J * I) := λ J J' h, mul_le.mpr (λ x hx y hy, mul_mem_mul (h hx) hy) instance add_comm_monoid : add_comm_monoid (fractional_ideal R S) := { add_assoc := λ I J K, sup_assoc, add_comm := λ I J, sup_comm, add_zero := λ I, sup_bot_eq, zero_add := λ I, bot_sup_eq, ..fractional_ideal.has_zero, ..fractional_ideal.has_add } instance comm_monoid : comm_monoid (fractional_ideal R S) := { mul_assoc := λ I J K, ext (submodule.mul_assoc _ _ _), mul_comm := λ I J, ext (mul_comm _ _), mul_one := λ I, begin ext, split; intro h, { apply mul_le.mpr _ h, rintros x hx y ⟨y', y'_mem_R, y'_eq_y⟩, erw [←y'_eq_y, mul_comm, coe_mul_eq_smul], exact submodule.smul _ _ hx }, { have : x * 1 ∈ (I * 1) := mul_mem_mul h (coe_mem_one _), simpa } end, one_mul := λ I, begin ext, split; intro h, { apply mul_le.mpr _ h, rintros x ⟨x', x'_mem_R, x'_eq_x⟩ y hy, erw [←x'_eq_x, coe_mul_eq_smul], exact submodule.smul _ _ hy }, { have : 1 * x ∈ (1 * I) := mul_mem_mul (coe_mem_one _) h, simpa } end, ..fractional_ideal.has_mul, ..fractional_ideal.has_one } instance comm_semiring : comm_semiring (fractional_ideal R S) := { mul_zero := λ I, eq_zero_iff.mpr (λ x hx, submodule.mul_induction_on hx (λ x hx y hy, by simp [mem_zero_iff.mp hy]) rfl (λ x y hx hy, by simp [hx, hy]) (λ r x hx, by simp [hx])), zero_mul := λ I, eq_zero_iff.mpr (λ x hx, submodule.mul_induction_on hx (λ x hx y hy, by simp [mem_zero_iff.mp hx]) rfl (λ x y hx hy, by simp [hx, hy]) (λ r x hx, by simp [hx])), left_distrib := λ I J K, ext (mul_add _ _ _), right_distrib := λ I J K, ext (add_mul _ _ _), ..fractional_ideal.add_comm_monoid, ..fractional_ideal.comm_monoid } end semiring section quotient /-! ### `quotient` section This section defines the ideal quotient of fractional ideals. In this section we need that each non-zero `y : R` has an inverse in `localization R S`, i.e. that `localization R S` is a field. We satisfy this assumption by taking `S = non_zero_divisors R`, so that `localization R (non_zero_divisors R) = fraction_ring R`, which is a field because `R` is a domain. -/ open_locale classical instance : zero_ne_one_class (fractional_ideal R (non_zero_divisors R)) := { zero_ne_one := λ h, have this : (1 : localization _ _) ∈ (0 : fractional_ideal R (non_zero_divisors R)) := by convert coe_mem_one _, one_ne_zero (mem_zero_iff.mp this), ..fractional_ideal.has_one, ..fractional_ideal.has_zero } lemma fractional_div_of_nonzero {I J : fractional_ideal R (non_zero_divisors R)} (h : J ≠ 0) : is_fractional R (non_zero_divisors R) (I.1 / J.1) := begin rcases I with ⟨I, aI, haI, hI⟩, rcases J with ⟨J, aJ, haJ, hJ⟩, obtain ⟨y, mem_J, not_mem_zero⟩ := exists_of_lt (bot_lt_iff_ne_bot.mpr h), obtain ⟨y', hy'⟩ := hJ y mem_J, use (aI * y'), split, { apply mul_ne_zero haI, intro y'_eq_zero, have : ↑aJ * y = 0 := by rw [coe_mul_eq_smul, ←hy', y'_eq_zero, localization.coe_zero], obtain aJ_zero | y_zero := mul_eq_zero.mp this, { have : aJ = 0 := fraction_ring.of.injective (trans aJ_zero (of_zero _ _).symm), contradiction }, { exact not_mem_zero (mem_zero_iff.mpr y_zero) } }, intros b hb, rw [mul_smul], convert hI _ (hb _ (submodule.smul_mem _ aJ mem_J)), rw [←hy', mul_coe_eq_smul] end noncomputable instance fractional_ideal_has_div : has_div (fractional_ideal R (non_zero_divisors R)) := ⟨ λ I J, if h : J = 0 then 0 else ⟨I.1 / J.1, fractional_div_of_nonzero h⟩ ⟩ noncomputable instance : has_inv (fractional_ideal R (non_zero_divisors R)) := ⟨λ I, 1 / I⟩ lemma div_nonzero {I J : fractional_ideal R (non_zero_divisors R)} (h : J ≠ 0) : (I / J) = ⟨I.1 / J.1, fractional_div_of_nonzero h⟩ := dif_neg h lemma inv_nonzero {I : fractional_ideal R (non_zero_divisors R)} (h : I ≠ 0) : I⁻¹ = ⟨(1 : fractional_ideal R _).val / I.1, fractional_div_of_nonzero h⟩ := div_nonzero h @[simp] lemma div_one {I : fractional_ideal R (non_zero_divisors R)} : I / 1 = I := begin rw [div_nonzero (@one_ne_zero (fractional_ideal R _) _)], ext, split; intro h, { convert mem_div_iff_forall_mul_mem.mp h 1 (coe_mem_one 1), simp }, { apply mem_div_iff_forall_mul_mem.mpr, rintros y ⟨y', _, y_eq_y'⟩, rw [mul_comm], convert submodule.smul _ y' h, simp [y_eq_y'.symm] } end lemma ne_zero_of_mul_eq_one (I J : fractional_ideal R (non_zero_divisors R)) (h : I * J = 1) : I ≠ 0 := λ hI, @zero_ne_one (fractional_ideal R (non_zero_divisors R)) _ (by { convert h, simp [hI], }) /-- `I⁻¹` is the inverse of `I` if `I` has an inverse. -/ theorem right_inverse_eq (I J : fractional_ideal R (non_zero_divisors R)) (h : I * J = 1) : J = I⁻¹ := begin have hI : I ≠ 0 := ne_zero_of_mul_eq_one I J h, suffices h' : I * (1 / I) = 1, { exact (congr_arg units.inv $ @units.ext _ _ (units.mk_of_mul_eq_one _ _ h) (units.mk_of_mul_eq_one _ _ h') rfl) }, rw [div_nonzero hI], apply le_antisymm, { apply submodule.mul_le.mpr _, intros x hx y hy, rw [mul_comm], exact mem_div_iff_forall_mul_mem.mp hy x hx }, rw [←h], apply mul_left_mono I, apply submodule.le_div_iff.mpr _, intros y hy x hx, rw [mul_comm], exact submodule.mul_mem_mul hx hy end end quotient end fractional_ideal end ring
dfb15e3878f72efa79ee8041659950ae754b86e6
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/analysis/convex/stone_separation.lean
903563a4ec4c8c7a1a984e6cf399ba60dc9fcb8a
[ "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
5,227
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 analysis.convex.join /-! # Stone's separation theorem > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file prove Stone's separation theorem. This tells us that any two disjoint convex sets can be separated by a convex set whose complement is also convex. In locally convex real topological vector spaces, the Hahn-Banach separation theorems provide stronger statements: one may find a separating hyperplane, instead of merely a convex set whose complement is convex. -/ open set open_locale big_operators variables {𝕜 E ι : Type*} [linear_ordered_field 𝕜] [add_comm_group E] [module 𝕜 E] {s t : set E} /-- In a tetrahedron with vertices `x`, `y`, `p`, `q`, any segment `[u, v]` joining the opposite edges `[x, p]` and `[y, q]` passes through any triangle of vertices `p`, `q`, `z` where `z ∈ [x, y]`. -/ lemma not_disjoint_segment_convex_hull_triple {p q u v x y z : E} (hz : z ∈ segment 𝕜 x y) (hu : u ∈ segment 𝕜 x p) (hv : v ∈ segment 𝕜 y q) : ¬ disjoint (segment 𝕜 u v) (convex_hull 𝕜 {p, q, z}) := begin rw not_disjoint_iff, obtain ⟨az, bz, haz, hbz, habz, rfl⟩ := hz, obtain rfl | haz' := haz.eq_or_lt, { rw zero_add at habz, rw [zero_smul, zero_add, habz, one_smul], refine ⟨v, right_mem_segment _ _ _, segment_subset_convex_hull _ _ hv⟩; simp }, obtain ⟨av, bv, hav, hbv, habv, rfl⟩ := hv, obtain rfl | hav' := hav.eq_or_lt, { rw zero_add at habv, rw [zero_smul, zero_add, habv, one_smul], exact ⟨q, right_mem_segment _ _ _, subset_convex_hull _ _ $ by simp⟩ }, obtain ⟨au, bu, hau, hbu, habu, rfl⟩ := hu, have hab : 0 < az * av + bz * au := add_pos_of_pos_of_nonneg (mul_pos haz' hav') (mul_nonneg hbz hau), refine ⟨(az * av / (az * av + bz * au)) • (au • x + bu • p) + (bz * au / (az * av + bz * au)) • (av • y + bv • q), ⟨_, _, _, _, _, rfl⟩, _⟩, { exact div_nonneg (mul_nonneg haz hav) hab.le }, { exact div_nonneg (mul_nonneg hbz hau) hab.le }, { rw [←add_div, div_self hab.ne'] }, rw [smul_add, smul_add, add_add_add_comm, add_comm, ←mul_smul, ←mul_smul], classical, let w : fin 3 → 𝕜 := ![az * av * bu, bz * au * bv, au * av], let z : fin 3 → E := ![p, q, az • x + bz • y], have hw₀ : ∀ i, 0 ≤ w i, { rintro i, fin_cases i, { exact mul_nonneg (mul_nonneg haz hav) hbu }, { exact mul_nonneg (mul_nonneg hbz hau) hbv }, { exact mul_nonneg hau hav } }, have hw : ∑ i, w i = az * av + bz * au, { transitivity az * av * bu + (bz * au * bv + au * av), { simp [w, fin.sum_univ_succ, fin.sum_univ_zero] }, rw [←one_mul (au * av), ←habz, add_mul, ←add_assoc, add_add_add_comm, mul_assoc, ←mul_add, mul_assoc, ←mul_add, mul_comm av, ←add_mul, ←mul_add, add_comm bu, add_comm bv, habu, habv, one_mul, mul_one] }, have hz : ∀ i, z i ∈ ({p, q, az • x + bz • y} : set E), { rintro i, fin_cases i; simp [z] }, convert finset.center_mass_mem_convex_hull (finset.univ : finset (fin 3)) (λ i _, hw₀ i) (by rwa hw) (λ i _, hz i), rw finset.center_mass, simp_rw [div_eq_inv_mul, hw, mul_assoc, mul_smul (az * av + bz * au)⁻¹, ←smul_add, add_assoc, ←mul_assoc], congr' 3, rw [←mul_smul, ←mul_rotate, mul_right_comm, mul_smul, ←mul_smul _ av, mul_rotate, mul_smul _ bz, ←smul_add], simp only [list.map, list.pmap, nat.add_def, add_zero, fin.mk_bit0, fin.mk_one, list.foldr_cons, list.foldr_nil], refl, end /-- **Stone's Separation Theorem** -/ lemma exists_convex_convex_compl_subset (hs : convex 𝕜 s) (ht : convex 𝕜 t) (hst : disjoint s t) : ∃ C : set E, convex 𝕜 C ∧ convex 𝕜 Cᶜ ∧ s ⊆ C ∧ t ⊆ Cᶜ := begin let S : set (set E) := {C | convex 𝕜 C ∧ disjoint C t}, obtain ⟨C, hC, hsC, hCmax⟩ := zorn_subset_nonempty S (λ c hcS hc ⟨t, ht⟩, ⟨⋃₀ c, ⟨hc.directed_on.convex_sUnion (λ s hs, (hcS hs).1), disjoint_sUnion_left.2 $ λ c hc, (hcS hc).2⟩, λ s, subset_sUnion_of_mem⟩) s ⟨hs, hst⟩, refine ⟨C, hC.1, convex_iff_segment_subset.2 $ λ x hx y hy z hz hzC, _, hsC, hC.2.subset_compl_left⟩, suffices h : ∀ c ∈ Cᶜ, ∃ a ∈ C, (segment 𝕜 c a ∩ t).nonempty, { obtain ⟨p, hp, u, hu, hut⟩ := h x hx, obtain ⟨q, hq, v, hv, hvt⟩ := h y hy, refine not_disjoint_segment_convex_hull_triple hz hu hv (hC.2.symm.mono (ht.segment_subset hut hvt) $ convex_hull_min _ hC.1), simp [insert_subset, hp, hq, singleton_subset_iff.2 hzC] }, rintro c hc, by_contra' h, suffices h : disjoint (convex_hull 𝕜 (insert c C)) t, { rw ←hCmax _ ⟨convex_convex_hull _ _, h⟩ ((subset_insert _ _).trans $ subset_convex_hull _ _) at hc, exact hc (subset_convex_hull _ _ $ mem_insert _ _) }, rw [convex_hull_insert ⟨z, hzC⟩, convex_join_singleton_left], refine disjoint_Union₂_left.2 (λ a ha, disjoint_iff_inf_le.mpr $ λ b hb, h a _ ⟨b, hb⟩), rwa ←hC.1.convex_hull_eq, end
f198e413712af975db45ecb9e5853c16420aaf6a
82e44445c70db0f03e30d7be725775f122d72f3e
/src/topology/algebra/ordered/basic.lean
57a8139615a71d1a58cc808a849c53c1db491145
[ "Apache-2.0" ]
permissive
stjordanis/mathlib
51e286d19140e3788ef2c470bc7b953e4991f0c9
2568d41bca08f5d6bf39d915434c8447e21f42ee
refs/heads/master
1,631,748,053,501
1,627,938,886,000
1,627,938,886,000
228,728,358
0
0
Apache-2.0
1,576,630,588,000
1,576,630,587,000
null
UTF-8
Lean
false
false
176,250
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, Yury Kudryashov -/ import algebra.group_with_zero.power import data.set.intervals.pi import order.filter.interval import topology.algebra.group import tactic.linarith import tactic.tfae /-! # Theory of topology on ordered spaces ## Main definitions The order topology on an ordered space is the topology generated by all open intervals (or equivalently by those of the form `(-∞, a)` and `(b, +∞)`). We define it as `preorder.topology α`. However, we do *not* register it as an instance (as many existing ordered types already have topologies, which would be equal but not definitionally equal to `preorder.topology α`). Instead, we introduce a class `order_topology α` (which is a `Prop`, also known as a mixin) saying that on the type `α` having already a topological space structure and a preorder structure, the topological structure is equal to the order topology. We also introduce another (mixin) class `order_closed_topology α` saying that the set of points `(x, y)` with `x ≤ y` is closed in the product space. This is automatically satisfied on a linear order with the order topology. We prove many basic properties of such topologies. ## Main statements This file contains the proofs of the following facts. For exact requirements (`order_closed_topology` vs `order_topology`, `preorder` vs `partial_order` vs `linear_order` etc) see their statements. ### Open / closed sets * `is_open_lt` : if `f` and `g` are continuous functions, then `{x | f x < g x}` is open; * `is_open_Iio`, `is_open_Ioi`, `is_open_Ioo` : open intervals are open; * `is_closed_le` : if `f` and `g` are continuous functions, then `{x | f x ≤ g x}` is closed; * `is_closed_Iic`, `is_closed_Ici`, `is_closed_Icc` : closed intervals are closed; * `frontier_le_subset_eq`, `frontier_lt_subset_eq` : frontiers of both `{x | f x ≤ g x}` and `{x | f x < g x}` are included by `{x | f x = g x}`; * `exists_Ioc_subset_of_mem_nhds`, `exists_Ico_subset_of_mem_nhds` : if `x < y`, then any neighborhood of `x` includes an interval `[x, z)` for some `z ∈ (x, y]`, and any neighborhood of `y` includes an interval `(z, y]` for some `z ∈ [x, y)`. ### Convergence and inequalities * `le_of_tendsto_of_tendsto` : if `f` converges to `a`, `g` converges to `b`, and eventually `f x ≤ g x`, then `a ≤ b` * `le_of_tendsto`, `ge_of_tendsto` : if `f` converges to `a` and eventually `f x ≤ b` (resp., `b ≤ f x`), then `a ≤ b` (resp., `b ≤ a); we also provide primed versions that assume the inequalities to hold for all `x`. ### Min, max, `Sup` and `Inf` * `continuous.min`, `continuous.max`: pointwise `min`/`max` of two continuous functions is continuous. * `tendsto.min`, `tendsto.max` : if `f` tends to `a` and `g` tends to `b`, then their pointwise `min`/`max` tend to `min a b` and `max a b`, respectively. * `tendsto_of_tendsto_of_tendsto_of_le_of_le` : theorem known as squeeze theorem, sandwich theorem, theorem of Carabinieri, and two policemen (and a drunk) theorem; if `g` and `h` both converge to `a`, and eventually `g x ≤ f x ≤ h x`, then `f` converges to `a`. ### Connected sets and Intermediate Value Theorem * `is_preconnected_I??` : all intervals `I??` are preconnected, * `is_preconnected.intermediate_value`, `intermediate_value_univ` : Intermediate Value Theorem for connected sets and connected spaces, respectively; * `intermediate_value_Icc`, `intermediate_value_Icc'`: Intermediate Value Theorem for functions on closed intervals. ### Miscellaneous facts * `is_compact.exists_forall_le`, `is_compact.exists_forall_ge` : extreme value theorem, a continuous function on a compact set takes its minimum and maximum values. * `is_closed.Icc_subset_of_forall_mem_nhds_within` : “Continuous induction” principle; if `s ∩ [a, b]` is closed, `a ∈ s`, and for each `x ∈ [a, b) ∩ s` some of its right neighborhoods is included `s`, then `[a, b] ⊆ s`. * `is_closed.Icc_subset_of_forall_exists_gt`, `is_closed.mem_of_ge_of_forall_exists_gt` : two other versions of the “continuous induction” principle. ## Implementation We do _not_ register the order topology as an instance on a preorder (or even on a linear order). Indeed, on many such spaces, a topology has already been constructed in a different way (think of the discrete spaces `ℕ` or `ℤ`, or `ℝ` that could inherit a topology as the completion of `ℚ`), and is in general not defeq to the one generated by the intervals. We make it available as a definition `preorder.topology α` though, that can be registered as an instance when necessary, or for specific types. -/ open classical set filter topological_space open function open_locale topological_space classical filter universes u v w variables {α : Type u} {β : Type v} {γ : Type w} /-- A topology on a set which is both a topological space and a preorder is _order-closed_ if the set of points `(x, y)` with `x ≤ y` is closed in the product space. We introduce this as a mixin. This property is satisfied for the order topology on a linear order, but it can be satisfied more generally, and suffices to derive many interesting properties relating order and topology. -/ class order_closed_topology (α : Type*) [topological_space α] [preorder α] : Prop := (is_closed_le' : is_closed {p:α×α | p.1 ≤ p.2}) instance : Π [topological_space α], topological_space (order_dual α) := id @[to_additive] instance [topological_space α] [has_mul α] [h : has_continuous_mul α] : has_continuous_mul (order_dual α) := h section order_closed_topology section preorder variables [topological_space α] [preorder α] [t : order_closed_topology α] include t namespace subtype instance {p : α → Prop} : order_closed_topology (subtype p) := have this : continuous (λ (p : (subtype p) × (subtype p)), ((p.fst : α), (p.snd : α))) := (continuous_subtype_coe.comp continuous_fst).prod_mk (continuous_subtype_coe.comp continuous_snd), order_closed_topology.mk (t.is_closed_le'.preimage this) end subtype lemma is_closed_le_prod : is_closed {p : α × α | p.1 ≤ p.2} := t.is_closed_le' lemma is_closed_le [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : is_closed {b | f b ≤ g b} := continuous_iff_is_closed.mp (hf.prod_mk hg) _ is_closed_le_prod lemma is_closed_le' (a : α) : is_closed {b | b ≤ a} := is_closed_le continuous_id continuous_const lemma is_closed_Iic {a : α} : is_closed (Iic a) := is_closed_le' a lemma is_closed_ge' (a : α) : is_closed {b | a ≤ b} := is_closed_le continuous_const continuous_id lemma is_closed_Ici {a : α} : is_closed (Ici a) := is_closed_ge' a instance : order_closed_topology (order_dual α) := ⟨(@order_closed_topology.is_closed_le' α _ _ _).preimage continuous_swap⟩ lemma is_closed_Icc {a b : α} : is_closed (Icc a b) := is_closed.inter is_closed_Ici is_closed_Iic @[simp] lemma closure_Icc (a b : α) : closure (Icc a b) = Icc a b := is_closed_Icc.closure_eq @[simp] lemma closure_Iic (a : α) : closure (Iic a) = Iic a := is_closed_Iic.closure_eq @[simp] lemma closure_Ici (a : α) : closure (Ici a) = Ici a := is_closed_Ici.closure_eq lemma le_of_tendsto_of_tendsto {f g : β → α} {b : filter β} {a₁ a₂ : α} [ne_bot b] (hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) (h : f ≤ᶠ[b] g) : a₁ ≤ a₂ := have tendsto (λb, (f b, g b)) b (𝓝 (a₁, a₂)), by rw [nhds_prod_eq]; exact hf.prod_mk hg, show (a₁, a₂) ∈ {p:α×α | p.1 ≤ p.2}, from t.is_closed_le'.mem_of_tendsto this h lemma le_of_tendsto_of_tendsto' {f g : β → α} {b : filter β} {a₁ a₂ : α} [ne_bot b] (hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) (h : ∀ x, f x ≤ g x) : a₁ ≤ a₂ := le_of_tendsto_of_tendsto hf hg (eventually_of_forall h) lemma le_of_tendsto {f : β → α} {a b : α} {x : filter β} [ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ᶠ c in x, f c ≤ b) : a ≤ b := le_of_tendsto_of_tendsto lim tendsto_const_nhds h lemma le_of_tendsto' {f : β → α} {a b : α} {x : filter β} [ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ c, f c ≤ b) : a ≤ b := le_of_tendsto lim (eventually_of_forall h) lemma ge_of_tendsto {f : β → α} {a b : α} {x : filter β} [ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ᶠ c in x, b ≤ f c) : b ≤ a := le_of_tendsto_of_tendsto tendsto_const_nhds lim h lemma ge_of_tendsto' {f : β → α} {a b : α} {x : filter β} [ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ c, b ≤ f c) : b ≤ a := ge_of_tendsto lim (eventually_of_forall h) @[simp] lemma closure_le_eq [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : closure {b | f b ≤ g b} = {b | f b ≤ g b} := (is_closed_le hf hg).closure_eq lemma closure_lt_subset_le [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : closure {b | f b < g b} ⊆ {b | f b ≤ g b} := by { rw [←closure_le_eq hf hg], exact closure_mono (λ b, le_of_lt) } lemma continuous_within_at.closure_le [topological_space β] {f g : β → α} {s : set β} {x : β} (hx : x ∈ closure s) (hf : continuous_within_at f s x) (hg : continuous_within_at g s x) (h : ∀ y ∈ s, f y ≤ g y) : f x ≤ g x := show (f x, g x) ∈ {p : α × α | p.1 ≤ p.2}, from order_closed_topology.is_closed_le'.closure_subset ((hf.prod hg).mem_closure hx h) /-- If `s` is a closed set and two functions `f` and `g` are continuous on `s`, then the set `{x ∈ s | f x ≤ g x}` is a closed set. -/ lemma is_closed.is_closed_le [topological_space β] {f g : β → α} {s : set β} (hs : is_closed s) (hf : continuous_on f s) (hg : continuous_on g s) : is_closed {x ∈ s | f x ≤ g x} := (hf.prod hg).preimage_closed_of_closed hs order_closed_topology.is_closed_le' omit t lemma nhds_within_Ici_ne_bot {a b : α} (H₂ : a ≤ b) : ne_bot (𝓝[Ici a] b) := nhds_within_ne_bot_of_mem H₂ @[instance] lemma nhds_within_Ici_self_ne_bot (a : α) : ne_bot (𝓝[Ici a] a) := nhds_within_Ici_ne_bot (le_refl a) lemma nhds_within_Iic_ne_bot {a b : α} (H : a ≤ b) : ne_bot (𝓝[Iic b] a) := nhds_within_ne_bot_of_mem H @[instance] lemma nhds_within_Iic_self_ne_bot (a : α) : ne_bot (𝓝[Iic a] a) := nhds_within_Iic_ne_bot (le_refl a) end preorder section partial_order variables [topological_space α] [partial_order α] [t : order_closed_topology α] include t private lemma is_closed_eq_aux : is_closed {p : α × α | p.1 = p.2} := by simp only [le_antisymm_iff]; exact is_closed.inter t.is_closed_le' (is_closed_le continuous_snd continuous_fst) @[priority 90] -- see Note [lower instance priority] instance order_closed_topology.to_t2_space : t2_space α := { t2 := have is_open {p : α × α | p.1 ≠ p.2} := is_closed_eq_aux.is_open_compl, assume a b h, let ⟨u, v, hu, hv, ha, hb, h⟩ := is_open_prod_iff.mp this a b h in ⟨u, v, hu, hv, ha, hb, set.eq_empty_iff_forall_not_mem.2 $ assume a ⟨h₁, h₂⟩, have a ≠ a, from @h (a, a) ⟨h₁, h₂⟩, this rfl⟩ } end partial_order section linear_order variables [topological_space α] [linear_order α] [order_closed_topology α] lemma is_open_lt_prod : is_open {p : α × α | p.1 < p.2} := by { simp_rw [← is_closed_compl_iff, compl_set_of, not_lt], exact is_closed_le continuous_snd continuous_fst } lemma is_open_lt [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : is_open {b | f b < g b} := by simp [lt_iff_not_ge, -not_le]; exact (is_closed_le hg hf).is_open_compl variables {a b : α} lemma is_open_Iio : is_open (Iio a) := is_open_lt continuous_id continuous_const lemma is_open_Ioi : is_open (Ioi a) := is_open_lt continuous_const continuous_id lemma is_open_Ioo : is_open (Ioo a b) := is_open.inter is_open_Ioi is_open_Iio @[simp] lemma interior_Ioi : interior (Ioi a) = Ioi a := is_open_Ioi.interior_eq @[simp] lemma interior_Iio : interior (Iio a) = Iio a := is_open_Iio.interior_eq @[simp] lemma interior_Ioo : interior (Ioo a b) = Ioo a b := is_open_Ioo.interior_eq lemma eventually_le_of_tendsto_lt {l : filter γ} {f : γ → α} {u v : α} (hv : v < u) (h : tendsto f l (𝓝 v)) : ∀ᶠ a in l, f a ≤ u := eventually.mono (tendsto_nhds.1 h (< u) is_open_Iio hv) (λ v, le_of_lt) lemma eventually_ge_of_tendsto_gt {l : filter γ} {f : γ → α} {u v : α} (hv : u < v) (h : tendsto f l (𝓝 v)) : ∀ᶠ a in l, u ≤ f a := eventually.mono (tendsto_nhds.1 h (> u) is_open_Ioi hv) (λ v, le_of_lt) variables [topological_space γ] /-- Intermediate value theorem for two functions: if `f` and `g` are two continuous functions on a preconnected space and `f a ≤ g a` and `g b ≤ f b`, then for some `x` we have `f x = g x`. -/ lemma intermediate_value_univ₂ [preconnected_space γ] {a b : γ} {f g : γ → α} (hf : continuous f) (hg : continuous g) (ha : f a ≤ g a) (hb : g b ≤ f b) : ∃ x, f x = g x := begin obtain ⟨x, h, hfg, hgf⟩ : (univ ∩ {x | f x ≤ g x ∧ g x ≤ f x}).nonempty, from is_preconnected_closed_iff.1 preconnected_space.is_preconnected_univ _ _ (is_closed_le hf hg) (is_closed_le hg hf) (λ x hx, le_total _ _) ⟨a, trivial, ha⟩ ⟨b, trivial, hb⟩, exact ⟨x, le_antisymm hfg hgf⟩ end lemma intermediate_value_univ₂_eventually₁ [preconnected_space γ] {a : γ} {l : filter γ} [ne_bot l] {f g : γ → α} (hf : continuous f) (hg : continuous g) (ha : f a ≤ g a) (he : g ≤ᶠ[l] f) : ∃ x, f x = g x := let ⟨c, hc⟩ := he.frequently.exists in intermediate_value_univ₂ hf hg ha hc lemma intermediate_value_univ₂_eventually₂ [preconnected_space γ] {l₁ l₂ : filter γ} [ne_bot l₁] [ne_bot l₂] {f g : γ → α} (hf : continuous f) (hg : continuous g) (he₁ : f ≤ᶠ[l₁] g ) (he₂ : g ≤ᶠ[l₂] f) : ∃ x, f x = g x := let ⟨c₁, hc₁⟩ := he₁.frequently.exists, ⟨c₂, hc₂⟩ := he₂.frequently.exists in intermediate_value_univ₂ hf hg hc₁ hc₂ /-- Intermediate value theorem for two functions: if `f` and `g` are two functions continuous on a preconnected set `s` and for some `a b ∈ s` we have `f a ≤ g a` and `g b ≤ f b`, then for some `x ∈ s` we have `f x = g x`. -/ lemma is_preconnected.intermediate_value₂ {s : set γ} (hs : is_preconnected s) {a b : γ} (ha : a ∈ s) (hb : b ∈ s) {f g : γ → α} (hf : continuous_on f s) (hg : continuous_on g s) (ha' : f a ≤ g a) (hb' : g b ≤ f b) : ∃ x ∈ s, f x = g x := let ⟨x, hx⟩ := @intermediate_value_univ₂ α s _ _ _ _ (subtype.preconnected_space hs) ⟨a, ha⟩ ⟨b, hb⟩ _ _ (continuous_on_iff_continuous_restrict.1 hf) (continuous_on_iff_continuous_restrict.1 hg) ha' hb' in ⟨x, x.2, hx⟩ lemma is_preconnected.intermediate_value₂_eventually₁ {s : set γ} (hs : is_preconnected s) {a : γ} {l : filter γ} (ha : a ∈ s) [ne_bot l] (hl : l ≤ 𝓟 s) {f g : γ → α} (hf : continuous_on f s) (hg : continuous_on g s) (ha' : f a ≤ g a) (he : g ≤ᶠ[l] f) : ∃ x ∈ s, f x = g x := begin rw continuous_on_iff_continuous_restrict at hf hg, obtain ⟨b, h⟩ := @intermediate_value_univ₂_eventually₁ _ _ _ _ _ _ (subtype.preconnected_space hs) ⟨a, ha⟩ _ (comap_coe_ne_bot_of_le_principal hl) _ _ hf hg ha' (eventually_comap' he), exact ⟨b, b.prop, h⟩, end lemma is_preconnected.intermediate_value₂_eventually₂ {s : set γ} (hs : is_preconnected s) {l₁ l₂ : filter γ} [ne_bot l₁] [ne_bot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f g : γ → α} (hf : continuous_on f s) (hg : continuous_on g s) (he₁ : f ≤ᶠ[l₁] g) (he₂ : g ≤ᶠ[l₂] f) : ∃ x ∈ s, f x = g x := begin rw continuous_on_iff_continuous_restrict at hf hg, obtain ⟨b, h⟩ := @intermediate_value_univ₂_eventually₂ _ _ _ _ _ _ (subtype.preconnected_space hs) _ _ (comap_coe_ne_bot_of_le_principal hl₁) (comap_coe_ne_bot_of_le_principal hl₂) _ _ hf hg (eventually_comap' he₁) (eventually_comap' he₂), exact ⟨b, b.prop, h⟩, end /-- **Intermediate Value Theorem** for continuous functions on connected sets. -/ lemma is_preconnected.intermediate_value {s : set γ} (hs : is_preconnected s) {a b : γ} (ha : a ∈ s) (hb : b ∈ s) {f : γ → α} (hf : continuous_on f s) : Icc (f a) (f b) ⊆ f '' s := λ x hx, mem_image_iff_bex.2 $ hs.intermediate_value₂ ha hb hf continuous_on_const hx.1 hx.2 lemma is_preconnected.intermediate_value_Ico {s : set γ} (hs : is_preconnected s) {a : γ} {l : filter γ} (ha : a ∈ s) [ne_bot l] (hl : l ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) {v : α} (ht : tendsto f l (𝓝 v)) : Ico (f a) v ⊆ f '' s := λ y h, bex_def.1 $ hs.intermediate_value₂_eventually₁ ha hl hf continuous_on_const h.1 (eventually_ge_of_tendsto_gt h.2 ht) lemma is_preconnected.intermediate_value_Ioc {s : set γ} (hs : is_preconnected s) {a : γ} {l : filter γ} (ha : a ∈ s) [ne_bot l] (hl : l ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) {v : α} (ht : tendsto f l (𝓝 v)) : Ioc v (f a) ⊆ f '' s := λ y h, bex_def.1 $ bex.imp_right (λ x _, eq.symm) $ hs.intermediate_value₂_eventually₁ ha hl continuous_on_const hf h.2 (eventually_le_of_tendsto_lt h.1 ht) lemma is_preconnected.intermediate_value_Ioo {s : set γ} (hs : is_preconnected s) {l₁ l₂ : filter γ} [ne_bot l₁] [ne_bot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) {v₁ v₂ : α} (ht₁ : tendsto f l₁ (𝓝 v₁)) (ht₂ : tendsto f l₂ (𝓝 v₂)) : Ioo v₁ v₂ ⊆ f '' s := λ y h, bex_def.1 $ hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuous_on_const (eventually_le_of_tendsto_lt h.1 ht₁) (eventually_ge_of_tendsto_gt h.2 ht₂) lemma is_preconnected.intermediate_value_Ici {s : set γ} (hs : is_preconnected s) {a : γ} {l : filter γ} (ha : a ∈ s) [ne_bot l] (hl : l ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) (ht : tendsto f l at_top) : Ici (f a) ⊆ f '' s := λ y h, bex_def.1 $ hs.intermediate_value₂_eventually₁ ha hl hf continuous_on_const h (tendsto_at_top.1 ht y) lemma is_preconnected.intermediate_value_Iic {s : set γ} (hs : is_preconnected s) {a : γ} {l : filter γ} (ha : a ∈ s) [ne_bot l] (hl : l ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) (ht : tendsto f l at_bot) : Iic (f a) ⊆ f '' s := λ y h, bex_def.1 $ bex.imp_right (λ x _, eq.symm) $ hs.intermediate_value₂_eventually₁ ha hl continuous_on_const hf h (tendsto_at_bot.1 ht y) lemma is_preconnected.intermediate_value_Ioi {s : set γ} (hs : is_preconnected s) {l₁ l₂ : filter γ} [ne_bot l₁] [ne_bot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) {v : α} (ht₁ : tendsto f l₁ (𝓝 v)) (ht₂ : tendsto f l₂ at_top) : Ioi v ⊆ f '' s := λ y h, bex_def.1 $ hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuous_on_const (eventually_le_of_tendsto_lt h ht₁) (tendsto_at_top.1 ht₂ y) lemma is_preconnected.intermediate_value_Iio {s : set γ} (hs : is_preconnected s) {l₁ l₂ : filter γ} [ne_bot l₁] [ne_bot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) {v : α} (ht₁ : tendsto f l₁ at_bot) (ht₂ : tendsto f l₂ (𝓝 v)) : Iio v ⊆ f '' s := λ y h, bex_def.1 $ hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuous_on_const (tendsto_at_bot.1 ht₁ y) (eventually_ge_of_tendsto_gt h ht₂) lemma is_preconnected.intermediate_value_Iii {s : set γ} (hs : is_preconnected s) {l₁ l₂ : filter γ} [ne_bot l₁] [ne_bot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) (ht₁ : tendsto f l₁ at_bot) (ht₂ : tendsto f l₂ at_top) : univ ⊆ f '' s := λ y h, bex_def.1 $ hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuous_on_const (tendsto_at_bot.1 ht₁ y) (tendsto_at_top.1 ht₂ y) /-- **Intermediate Value Theorem** for continuous functions on connected spaces. -/ lemma intermediate_value_univ [preconnected_space γ] (a b : γ) {f : γ → α} (hf : continuous f) : Icc (f a) (f b) ⊆ range f := λ x hx, intermediate_value_univ₂ hf continuous_const hx.1 hx.2 /-- **Intermediate Value Theorem** for continuous functions on connected spaces. -/ lemma mem_range_of_exists_le_of_exists_ge [preconnected_space γ] {c : α} {f : γ → α} (hf : continuous f) (h₁ : ∃ a, f a ≤ c) (h₂ : ∃ b, c ≤ f b) : c ∈ range f := let ⟨a, ha⟩ := h₁, ⟨b, hb⟩ := h₂ in intermediate_value_univ a b hf ⟨ha, hb⟩ /-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/ lemma is_preconnected.Icc_subset {s : set α} (hs : is_preconnected s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : Icc a b ⊆ s := by simpa only [image_id] using hs.intermediate_value ha hb continuous_on_id /-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/ lemma is_connected.Icc_subset {s : set α} (hs : is_connected s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : Icc a b ⊆ s := hs.2.Icc_subset ha hb /-- If preconnected set in a linear order space is unbounded below and above, then it is the whole space. -/ lemma is_preconnected.eq_univ_of_unbounded {s : set α} (hs : is_preconnected s) (hb : ¬bdd_below s) (ha : ¬bdd_above s) : s = univ := begin refine eq_univ_of_forall (λ x, _), obtain ⟨y, ys, hy⟩ : ∃ y ∈ s, y < x := not_bdd_below_iff.1 hb x, obtain ⟨z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bdd_above_iff.1 ha x, exact hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩ end /-! ### Neighborhoods to the left and to the right on an `order_closed_topology` Limits to the left and to the right of real functions are defined in terms of neighborhoods to the left and to the right, either open or closed, i.e., members of `𝓝[Ioi a] a` and `𝓝[Ici a] a` on the right, and similarly on the left. Here we simply prove that all right-neighborhoods of a point are equal, and we'll prove later other useful characterizations which require the stronger hypothesis `order_topology α` -/ /-! #### Right neighborhoods, point excluded -/ lemma Ioo_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) : Ioo a c ∈ 𝓝[Ioi b] b := mem_nhds_within.2 ⟨Iio c, is_open_Iio, H.2, by rw [inter_comm, Ioi_inter_Iio]; exact Ioo_subset_Ioo_left H.1⟩ lemma Ioc_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) : Ioc a c ∈ 𝓝[Ioi b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Ioc_self lemma Ico_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) : Ico a c ∈ 𝓝[Ioi b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Ico_self lemma Icc_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) : Icc a c ∈ 𝓝[Ioi b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Icc_self @[simp] lemma nhds_within_Ioc_eq_nhds_within_Ioi {a b : α} (h : a < b) : 𝓝[Ioc a b] a = 𝓝[Ioi a] a := le_antisymm (nhds_within_mono _ Ioc_subset_Ioi_self) $ nhds_within_le_of_mem $ Ioc_mem_nhds_within_Ioi $ left_mem_Ico.2 h @[simp] lemma nhds_within_Ioo_eq_nhds_within_Ioi {a b : α} (h : a < b) : 𝓝[Ioo a b] a = 𝓝[Ioi a] a := le_antisymm (nhds_within_mono _ Ioo_subset_Ioi_self) $ nhds_within_le_of_mem $ Ioo_mem_nhds_within_Ioi $ left_mem_Ico.2 h @[simp] lemma continuous_within_at_Ioc_iff_Ioi [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Ioc a b) a ↔ continuous_within_at f (Ioi a) a := by simp only [continuous_within_at, nhds_within_Ioc_eq_nhds_within_Ioi h] @[simp] lemma continuous_within_at_Ioo_iff_Ioi [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Ioo a b) a ↔ continuous_within_at f (Ioi a) a := by simp only [continuous_within_at, nhds_within_Ioo_eq_nhds_within_Ioi h] /-! #### Left neighborhoods, point excluded -/ lemma Ioo_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) : Ioo a c ∈ 𝓝[Iio b] b := by simpa only [dual_Ioo] using @Ioo_mem_nhds_within_Ioi (order_dual α) _ _ _ _ _ _ ⟨H.2, H.1⟩ lemma Ico_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) : Ico a c ∈ 𝓝[Iio b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Iio H) Ioo_subset_Ico_self lemma Ioc_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) : Ioc a c ∈ 𝓝[Iio b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Iio H) Ioo_subset_Ioc_self lemma Icc_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) : Icc a c ∈ 𝓝[Iio b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Iio H) Ioo_subset_Icc_self @[simp] lemma nhds_within_Ico_eq_nhds_within_Iio {a b : α} (h : a < b) : 𝓝[Ico a b] b = 𝓝[Iio b] b := by simpa only [dual_Ioc] using @nhds_within_Ioc_eq_nhds_within_Ioi (order_dual α) _ _ _ _ _ h @[simp] lemma nhds_within_Ioo_eq_nhds_within_Iio {a b : α} (h : a < b) : 𝓝[Ioo a b] b = 𝓝[Iio b] b := by simpa only [dual_Ioo] using @nhds_within_Ioo_eq_nhds_within_Ioi (order_dual α) _ _ _ _ _ h @[simp] lemma continuous_within_at_Ico_iff_Iio {a b : α} {f : α → γ} (h : a < b) : continuous_within_at f (Ico a b) b ↔ continuous_within_at f (Iio b) b := by simp only [continuous_within_at, nhds_within_Ico_eq_nhds_within_Iio h] @[simp] lemma continuous_within_at_Ioo_iff_Iio {a b : α} {f : α → γ} (h : a < b) : continuous_within_at f (Ioo a b) b ↔ continuous_within_at f (Iio b) b := by simp only [continuous_within_at, nhds_within_Ioo_eq_nhds_within_Iio h] /-! #### Right neighborhoods, point included -/ lemma Ioo_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ioo a c) : Ioo a c ∈ 𝓝[Ici b] b := mem_nhds_within_of_mem_nhds $ is_open.mem_nhds is_open_Ioo H lemma Ioc_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ioo a c) : Ioc a c ∈ 𝓝[Ici b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Ici H) Ioo_subset_Ioc_self lemma Ico_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ico a c) : Ico a c ∈ 𝓝[Ici b] b := mem_nhds_within.2 ⟨Iio c, is_open_Iio, H.2, by simp only [inter_comm, Ici_inter_Iio, Ico_subset_Ico_left H.1]⟩ lemma Icc_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ico a c) : Icc a c ∈ 𝓝[Ici b] b := mem_sets_of_superset (Ico_mem_nhds_within_Ici H) Ico_subset_Icc_self @[simp] lemma nhds_within_Icc_eq_nhds_within_Ici {a b : α} (h : a < b) : 𝓝[Icc a b] a = 𝓝[Ici a] a := le_antisymm (nhds_within_mono _ Icc_subset_Ici_self) $ nhds_within_le_of_mem $ Icc_mem_nhds_within_Ici $ left_mem_Ico.2 h @[simp] lemma nhds_within_Ico_eq_nhds_within_Ici {a b : α} (h : a < b) : 𝓝[Ico a b] a = 𝓝[Ici a] a := le_antisymm (nhds_within_mono _ (λ x, and.left)) $ nhds_within_le_of_mem $ Ico_mem_nhds_within_Ici $ left_mem_Ico.2 h @[simp] lemma continuous_within_at_Icc_iff_Ici [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Icc a b) a ↔ continuous_within_at f (Ici a) a := by simp only [continuous_within_at, nhds_within_Icc_eq_nhds_within_Ici h] @[simp] lemma continuous_within_at_Ico_iff_Ici [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Ico a b) a ↔ continuous_within_at f (Ici a) a := by simp only [continuous_within_at, nhds_within_Ico_eq_nhds_within_Ici h] /-! #### Left neighborhoods, point included -/ lemma Ioo_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioo a c) : Ioo a c ∈ 𝓝[Iic b] b := mem_nhds_within_of_mem_nhds $ is_open.mem_nhds is_open_Ioo H lemma Ico_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioo a c) : Ico a c ∈ 𝓝[Iic b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Iic H) Ioo_subset_Ico_self lemma Ioc_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioc a c) : Ioc a c ∈ 𝓝[Iic b] b := by simpa only [dual_Ico] using @Ico_mem_nhds_within_Ici (order_dual α) _ _ _ _ _ _ ⟨H.2, H.1⟩ lemma Icc_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioc a c) : Icc a c ∈ 𝓝[Iic b] b := mem_sets_of_superset (Ioc_mem_nhds_within_Iic H) Ioc_subset_Icc_self @[simp] lemma nhds_within_Icc_eq_nhds_within_Iic {a b : α} (h : a < b) : 𝓝[Icc a b] b = 𝓝[Iic b] b := by simpa only [dual_Icc] using @nhds_within_Icc_eq_nhds_within_Ici (order_dual α) _ _ _ _ _ h @[simp] lemma nhds_within_Ioc_eq_nhds_within_Iic {a b : α} (h : a < b) : 𝓝[Ioc a b] b = 𝓝[Iic b] b := by simpa only [dual_Ico] using @nhds_within_Ico_eq_nhds_within_Ici (order_dual α) _ _ _ _ _ h @[simp] lemma continuous_within_at_Icc_iff_Iic [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Icc a b) b ↔ continuous_within_at f (Iic b) b := by simp only [continuous_within_at, nhds_within_Icc_eq_nhds_within_Iic h] @[simp] lemma continuous_within_at_Ioc_iff_Iic [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Ioc a b) b ↔ continuous_within_at f (Iic b) b := by simp only [continuous_within_at, nhds_within_Ioc_eq_nhds_within_Iic h] end linear_order section linear_order variables [topological_space α] [linear_order α] [order_closed_topology α] {f g : β → α} section variables [topological_space β] lemma frontier_le_subset_eq (hf : continuous f) (hg : continuous g) : frontier {b | f b ≤ g b} ⊆ {b | f b = g b} := begin rw [frontier_eq_closure_inter_closure, closure_le_eq hf hg], rintros b ⟨hb₁, hb₂⟩, refine le_antisymm hb₁ (closure_lt_subset_le hg hf _), convert hb₂ using 2, simp only [not_le.symm], refl end lemma frontier_Iic_subset (a : α) : frontier (Iic a) ⊆ {a} := frontier_le_subset_eq (@continuous_id α _) continuous_const lemma frontier_Ici_subset (a : α) : frontier (Ici a) ⊆ {a} := @frontier_Iic_subset (order_dual α) _ _ _ _ lemma frontier_lt_subset_eq (hf : continuous f) (hg : continuous g) : frontier {b | f b < g b} ⊆ {b | f b = g b} := by rw ← frontier_compl; convert frontier_le_subset_eq hg hf; simp [ext_iff, eq_comm] lemma continuous_if_le [topological_space γ] [Π x, decidable (f x ≤ g x)] {f' g' : β → γ} (hf : continuous f) (hg : continuous g) (hf' : continuous_on f' {x | f x ≤ g x}) (hg' : continuous_on g' {x | g x ≤ f x}) (hfg : ∀ x, f x = g x → f' x = g' x) : continuous (λ x, if f x ≤ g x then f' x else g' x) := begin refine continuous_if (λ a ha, hfg _ (frontier_le_subset_eq hf hg ha)) _ (hg'.mono _), { rwa [(is_closed_le hf hg).closure_eq] }, { simp only [not_le], exact closure_lt_subset_le hg hf } end lemma continuous.if_le [topological_space γ] [Π x, decidable (f x ≤ g x)] {f' g' : β → γ} (hf' : continuous f') (hg' : continuous g') (hf : continuous f) (hg : continuous g) (hfg : ∀ x, f x = g x → f' x = g' x) : continuous (λ x, if f x ≤ g x then f' x else g' x) := continuous_if_le hf hg hf'.continuous_on hg'.continuous_on hfg @[continuity] lemma continuous.min (hf : continuous f) (hg : continuous g) : continuous (λb, min (f b) (g b)) := hf.if_le hg hf hg (λ x, id) @[continuity] lemma continuous.max (hf : continuous f) (hg : continuous g) : continuous (λb, max (f b) (g b)) := @continuous.min (order_dual α) _ _ _ _ _ _ _ hf hg end lemma continuous_min : continuous (λ p : α × α, min p.1 p.2) := continuous_fst.min continuous_snd lemma continuous_max : continuous (λ p : α × α, max p.1 p.2) := continuous_fst.max continuous_snd lemma filter.tendsto.max {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) : tendsto (λb, max (f b) (g b)) b (𝓝 (max a₁ a₂)) := (continuous_max.tendsto (a₁, a₂)).comp (hf.prod_mk_nhds hg) lemma filter.tendsto.min {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) : tendsto (λb, min (f b) (g b)) b (𝓝 (min a₁ a₂)) := (continuous_min.tendsto (a₁, a₂)).comp (hf.prod_mk_nhds hg) lemma is_preconnected.ord_connected {s : set α} (h : is_preconnected s) : ord_connected s := ⟨λ x hx y hy, h.Icc_subset hx hy⟩ end linear_order end order_closed_topology /-- The order topology on an ordered type is the topology generated by open intervals. We register it on a preorder, but it is mostly interesting in linear orders, where it is also order-closed. We define it as a mixin. If you want to introduce the order topology on a preorder, use `preorder.topology`. -/ class order_topology (α : Type*) [t : topological_space α] [preorder α] : Prop := (topology_eq_generate_intervals : t = generate_from {s | ∃a, s = Ioi a ∨ s = Iio a}) /-- (Order) topology on a partial order `α` generated by the subbase of open intervals `(a, ∞) = { x ∣ a < x }, (-∞ , b) = {x ∣ x < b}` for all `a, b` in `α`. We do not register it as an instance as many ordered sets are already endowed with the same topology, most often in a non-defeq way though. Register as a local instance when necessary. -/ def preorder.topology (α : Type*) [preorder α] : topological_space α := generate_from {s : set α | ∃ (a : α), s = {b : α | a < b} ∨ s = {b : α | b < a}} section order_topology instance {α : Type*} [topological_space α] [partial_order α] [order_topology α] : order_topology (order_dual α) := ⟨by convert @order_topology.topology_eq_generate_intervals α _ _ _; conv in (_ ∨ _) { rw or.comm }; refl⟩ section partial_order variables [topological_space α] [partial_order α] [t : order_topology α] include t lemma is_open_iff_generate_intervals {s : set α} : is_open s ↔ generate_open {s | ∃a, s = Ioi a ∨ s = Iio a} s := by rw [t.topology_eq_generate_intervals]; refl lemma is_open_lt' (a : α) : is_open {b:α | a < b} := by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inl rfl⟩ lemma is_open_gt' (a : α) : is_open {b:α | b < a} := by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inr rfl⟩ lemma lt_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a < x := is_open.mem_nhds (is_open_lt' _) h lemma le_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a ≤ x := (𝓝 b).sets_of_superset (lt_mem_nhds h) $ assume b hb, le_of_lt hb lemma gt_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x < b := is_open.mem_nhds (is_open_gt' _) h lemma ge_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x ≤ b := (𝓝 a).sets_of_superset (gt_mem_nhds h) $ assume b hb, le_of_lt hb lemma nhds_eq_order (a : α) : 𝓝 a = (⨅b ∈ Iio a, 𝓟 (Ioi b)) ⊓ (⨅b ∈ Ioi a, 𝓟 (Iio b)) := by rw [t.topology_eq_generate_intervals, nhds_generate_from]; from le_antisymm (le_inf (le_binfi $ assume b hb, infi_le_of_le {c : α | b < c} $ infi_le _ ⟨hb, b, or.inl rfl⟩) (le_binfi $ assume b hb, infi_le_of_le {c : α | c < b} $ infi_le _ ⟨hb, b, or.inr rfl⟩)) (le_infi $ assume s, le_infi $ assume ⟨ha, b, hs⟩, match s, ha, hs with | _, h, (or.inl rfl) := inf_le_of_left_le $ infi_le_of_le b $ infi_le _ h | _, h, (or.inr rfl) := inf_le_of_right_le $ infi_le_of_le b $ infi_le _ h end) lemma tendsto_order {f : β → α} {a : α} {x : filter β} : tendsto f x (𝓝 a) ↔ (∀ a' < a, ∀ᶠ b in x, a' < f b) ∧ (∀ a' > a, ∀ᶠ b in x, f b < a') := by simp [nhds_eq_order a, tendsto_inf, tendsto_infi, tendsto_principal] instance tendsto_Icc_class_nhds (a : α) : tendsto_Ixx_class Icc (𝓝 a) (𝓝 a) := begin simp only [nhds_eq_order, infi_subtype'], refine ((has_basis_infi_principal_finite _).inf (has_basis_infi_principal_finite _)).tendsto_Ixx_class (λ s hs, _), refine ((ord_connected_bInter _).inter (ord_connected_bInter _)).out; intros _ _, exacts [ord_connected_Ioi, ord_connected_Iio] end instance tendsto_Ico_class_nhds (a : α) : tendsto_Ixx_class Ico (𝓝 a) (𝓝 a) := tendsto_Ixx_class_of_subset (λ _ _, Ico_subset_Icc_self) instance tendsto_Ioc_class_nhds (a : α) : tendsto_Ixx_class Ioc (𝓝 a) (𝓝 a) := tendsto_Ixx_class_of_subset (λ _ _, Ioc_subset_Icc_self) instance tendsto_Ioo_class_nhds (a : α) : tendsto_Ixx_class Ioo (𝓝 a) (𝓝 a) := tendsto_Ixx_class_of_subset (λ _ _, Ioo_subset_Icc_self) /-- Also known as squeeze or sandwich theorem. This version assumes that inequalities hold eventually for the filter. -/ lemma tendsto_of_tendsto_of_tendsto_of_le_of_le' {f g h : β → α} {b : filter β} {a : α} (hg : tendsto g b (𝓝 a)) (hh : tendsto h b (𝓝 a)) (hgf : ∀ᶠ b in b, g b ≤ f b) (hfh : ∀ᶠ b in b, f b ≤ h b) : tendsto f b (𝓝 a) := tendsto_order.2 ⟨assume a' h', have ∀ᶠ b in b, a' < g b, from (tendsto_order.1 hg).left a' h', by filter_upwards [this, hgf] assume a, lt_of_lt_of_le, assume a' h', have ∀ᶠ b in b, h b < a', from (tendsto_order.1 hh).right a' h', by filter_upwards [this, hfh] assume a h₁ h₂, lt_of_le_of_lt h₂ h₁⟩ /-- Also known as squeeze or sandwich theorem. This version assumes that inequalities hold everywhere. -/ lemma tendsto_of_tendsto_of_tendsto_of_le_of_le {f g h : β → α} {b : filter β} {a : α} (hg : tendsto g b (𝓝 a)) (hh : tendsto h b (𝓝 a)) (hgf : g ≤ f) (hfh : f ≤ h) : tendsto f b (𝓝 a) := tendsto_of_tendsto_of_tendsto_of_le_of_le' hg hh (eventually_of_forall hgf) (eventually_of_forall hfh) lemma nhds_order_unbounded {a : α} (hu : ∃u, a < u) (hl : ∃l, l < a) : 𝓝 a = (⨅l (h₂ : l < a) u (h₂ : a < u), 𝓟 (Ioo l u)) := have ∃ u, u ∈ Ioi a, from hu, have ∃ l, l ∈ Iio a, from hl, by { simp only [nhds_eq_order, inf_binfi, binfi_inf, *, inf_principal, Ioi_inter_Iio], refl } lemma tendsto_order_unbounded {f : β → α} {a : α} {x : filter β} (hu : ∃u, a < u) (hl : ∃l, l < a) (h : ∀l u, l < a → a < u → ∀ᶠ b in x, l < f b ∧ f b < u) : tendsto f x (𝓝 a) := by rw [nhds_order_unbounded hu hl]; from (tendsto_infi.2 $ assume l, tendsto_infi.2 $ assume hl, tendsto_infi.2 $ assume u, tendsto_infi.2 $ assume hu, tendsto_principal.2 $ h l u hl hu) end partial_order instance tendsto_Ixx_nhds_within {α : Type*} [preorder α] [topological_space α] (a : α) {s t : set α} {Ixx} [tendsto_Ixx_class Ixx (𝓝 a) (𝓝 a)] [tendsto_Ixx_class Ixx (𝓟 s) (𝓟 t)]: tendsto_Ixx_class Ixx (𝓝[s] a) (𝓝[t] a) := filter.tendsto_Ixx_class_inf instance tendsto_Icc_class_nhds_pi {ι : Type*} {α : ι → Type*} [Π i, partial_order (α i)] [Π i, topological_space (α i)] [∀ i, order_topology (α i)] (f : Π i, α i) : tendsto_Ixx_class Icc (𝓝 f) (𝓝 f) := begin constructor, conv in ((𝓝 f).lift' powerset) { rw [nhds_pi] }, simp only [lift'_infi_powerset, comap_lift'_eq2 monotone_powerset, tendsto_infi, tendsto_lift', mem_powerset_iff, subset_def, mem_preimage], intros i s hs, have : tendsto (λ g : Π i, α i, g i) (𝓝 f) (𝓝 (f i)) := ((continuous_apply i).tendsto f), refine (tendsto_lift'.1 ((this.comp tendsto_fst).Icc (this.comp tendsto_snd)) s hs).mono _, exact λ p hp g hg, hp ⟨hg.1 _, hg.2 _⟩ end theorem induced_order_topology' {α : Type u} {β : Type v} [partial_order α] [ta : topological_space β] [partial_order β] [order_topology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H₁ : ∀ {a x}, x < f a → ∃ b < a, x ≤ f b) (H₂ : ∀ {a x}, f a < x → ∃ b > a, f b ≤ x) : @order_topology _ (induced f ta) _ := begin letI := induced f ta, refine ⟨eq_of_nhds_eq_nhds (λ a, _)⟩, rw [nhds_induced, nhds_generate_from, nhds_eq_order (f a)], apply le_antisymm, { refine le_infi (λ s, le_infi $ λ hs, le_principal_iff.2 _), rcases hs with ⟨ab, b, rfl|rfl⟩, { exact mem_comap_sets.2 ⟨{x | f b < x}, mem_inf_sets_of_left $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _, λ x, hf.1⟩ }, { exact mem_comap_sets.2 ⟨{x | x < f b}, mem_inf_sets_of_right $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _, λ x, hf.1⟩ } }, { rw [← map_le_iff_le_comap], refine le_inf _ _; refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _); simp, { rcases H₁ h with ⟨b, ab, xb⟩, refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inl rfl⟩ (mem_principal_sets.2 _)), exact λ c hc, lt_of_le_of_lt xb (hf.2 hc) }, { rcases H₂ h with ⟨b, ab, xb⟩, refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inr rfl⟩ (mem_principal_sets.2 _)), exact λ c hc, lt_of_lt_of_le (hf.2 hc) xb } }, end theorem induced_order_topology {α : Type u} {β : Type v} [partial_order α] [ta : topological_space β] [partial_order β] [order_topology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H : ∀ {x y}, x < y → ∃ a, x < f a ∧ f a < y) : @order_topology _ (induced f ta) _ := induced_order_topology' f @hf (λ a x xa, let ⟨b, xb, ba⟩ := H xa in ⟨b, hf.1 ba, le_of_lt xb⟩) (λ a x ax, let ⟨b, ab, bx⟩ := H ax in ⟨b, hf.1 ab, le_of_lt bx⟩) /-- On an `ord_connected` subset of a linear order, the order topology for the restriction of the order is the same as the restriction to the subset of the order topology. -/ instance order_topology_of_ord_connected {α : Type u} [ta : topological_space α] [linear_order α] [order_topology α] {t : set α} [ht : ord_connected t] : order_topology t := begin letI := induced (coe : t → α) ta, refine ⟨eq_of_nhds_eq_nhds (λ a, _)⟩, rw [nhds_induced, nhds_generate_from, nhds_eq_order (a : α)], apply le_antisymm, { refine le_infi (λ s, le_infi $ λ hs, le_principal_iff.2 _), rcases hs with ⟨ab, b, rfl|rfl⟩, { refine ⟨Ioi b, _, λ _, id⟩, refine mem_inf_sets_of_left (mem_infi_sets b _), exact mem_infi_sets ab (mem_principal_self (Ioi ↑b)) }, { refine ⟨Iio b, _, λ _, id⟩, refine mem_inf_sets_of_right (mem_infi_sets b _), exact mem_infi_sets ab (mem_principal_self (Iio b)) } }, { rw [← map_le_iff_le_comap], refine le_inf _ _, { refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _), by_cases hx : x ∈ t, { refine mem_infi_sets (Ioi ⟨x, hx⟩) (mem_infi_sets ⟨h, ⟨⟨x, hx⟩, or.inl rfl⟩⟩ _), exact λ _, id }, simp only [set_coe.exists, mem_set_of_eq, mem_map], convert univ_sets _, suffices hx' : ∀ (y : t), ↑y ∈ Ioi x, { simp [hx'] }, intros y, revert hx, contrapose!, -- here we use the `ord_connected` hypothesis exact λ hx, ht.out y.2 a.2 ⟨le_of_not_gt hx, le_of_lt h⟩ }, { refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _), by_cases hx : x ∈ t, { refine mem_infi_sets (Iio ⟨x, hx⟩) (mem_infi_sets ⟨h, ⟨⟨x, hx⟩, or.inr rfl⟩⟩ _), exact λ _, id }, simp only [set_coe.exists, mem_set_of_eq, mem_map], convert univ_sets _, suffices hx' : ∀ (y : t), ↑y ∈ Iio x, { simp [hx'] }, intros y, revert hx, contrapose!, -- here we use the `ord_connected` hypothesis exact λ hx, ht.out a.2 y.2 ⟨le_of_lt h, le_of_not_gt hx⟩ } } end lemma nhds_top_order [topological_space α] [order_top α] [order_topology α] : 𝓝 (⊤:α) = (⨅l (h₂ : l < ⊤), 𝓟 (Ioi l)) := by simp [nhds_eq_order (⊤:α)] lemma nhds_bot_order [topological_space α] [order_bot α] [order_topology α] : 𝓝 (⊥:α) = (⨅l (h₂ : ⊥ < l), 𝓟 (Iio l)) := by simp [nhds_eq_order (⊥:α)] lemma nhds_top_basis [topological_space α] [semilattice_sup_top α] [is_total α has_le.le] [order_topology α] [nontrivial α] : (𝓝 ⊤).has_basis (λ a : α, a < ⊤) (λ a : α, Ioi a) := ⟨ begin simp only [nhds_top_order], refine @filter.mem_binfi α α (λ a, 𝓟 (Ioi a)) (λ a, a < ⊤) _ _, { rintros a (ha : a < ⊤) b (hb : b < ⊤), use a ⊔ b, simp only [filter.le_principal_iff, ge_iff_le, order.preimage], exact ⟨sup_lt_iff.mpr ⟨ha, hb⟩, Ioi_subset_Ioi le_sup_left, Ioi_subset_Ioi le_sup_right⟩ }, { obtain ⟨a, ha⟩ : ∃ a : α, a ≠ ⊤ := exists_ne ⊤, exact ⟨a, lt_top_iff_ne_top.mpr ha⟩ } end ⟩ lemma nhds_bot_basis [topological_space α] [semilattice_inf_bot α] [is_total α has_le.le] [order_topology α] [nontrivial α] : (𝓝 ⊥).has_basis (λ a : α, ⊥ < a) (λ a : α, Iio a) := @nhds_top_basis (order_dual α) _ _ _ _ _ lemma nhds_top_basis_Ici [topological_space α] [semilattice_sup_top α] [is_total α has_le.le] [order_topology α] [nontrivial α] [densely_ordered α] : (𝓝 ⊤).has_basis (λ a : α, a < ⊤) Ici := nhds_top_basis.to_has_basis (λ a ha, let ⟨b, hab, hb⟩ := exists_between ha in ⟨b, hb, Ici_subset_Ioi.mpr hab⟩) (λ a ha, ⟨a, ha, Ioi_subset_Ici_self⟩) lemma nhds_bot_basis_Iic [topological_space α] [semilattice_inf_bot α] [is_total α has_le.le] [order_topology α] [nontrivial α] [densely_ordered α] : (𝓝 ⊥).has_basis (λ a : α, ⊥ < a) Iic := @nhds_top_basis_Ici (order_dual α) _ _ _ _ _ _ lemma tendsto_nhds_top_mono [topological_space β] [order_top β] [order_topology β] {l : filter α} {f g : α → β} (hf : tendsto f l (𝓝 ⊤)) (hg : f ≤ᶠ[l] g) : tendsto g l (𝓝 ⊤) := begin simp only [nhds_top_order, tendsto_infi, tendsto_principal] at hf ⊢, intros x hx, filter_upwards [hf x hx, hg], exact λ x, lt_of_lt_of_le end lemma tendsto_nhds_bot_mono [topological_space β] [order_bot β] [order_topology β] {l : filter α} {f g : α → β} (hf : tendsto f l (𝓝 ⊥)) (hg : g ≤ᶠ[l] f) : tendsto g l (𝓝 ⊥) := @tendsto_nhds_top_mono α (order_dual β) _ _ _ _ _ _ hf hg lemma tendsto_nhds_top_mono' [topological_space β] [order_top β] [order_topology β] {l : filter α} {f g : α → β} (hf : tendsto f l (𝓝 ⊤)) (hg : f ≤ g) : tendsto g l (𝓝 ⊤) := tendsto_nhds_top_mono hf (eventually_of_forall hg) lemma tendsto_nhds_bot_mono' [topological_space β] [order_bot β] [order_topology β] {l : filter α} {f g : α → β} (hf : tendsto f l (𝓝 ⊥)) (hg : g ≤ f) : tendsto g l (𝓝 ⊥) := tendsto_nhds_bot_mono hf (eventually_of_forall hg) section linear_order variables [topological_space α] [linear_order α] [order_topology α] lemma exists_Ioc_subset_of_mem_nhds' {a : α} {s : set α} (hs : s ∈ 𝓝 a) {l : α} (hl : l < a) : ∃ l' ∈ Ico l a, Ioc l' a ⊆ s := begin rw [nhds_eq_order a] at hs, rcases hs with ⟨t₁, ht₁, t₂, ht₂, hts⟩, -- First we show that `t₂` includes `(-∞, a]`, so it suffices to show `(l', ∞) ⊆ t₁` suffices : ∃ l' ∈ Ico l a, Ioi l' ⊆ t₁, { have A : 𝓟 (Iic a) ≤ ⨅ b ∈ Ioi a, 𝓟 (Iio b), from (le_infi $ λ b, le_infi $ λ hb, principal_mono.2 $ Iic_subset_Iio.2 hb), have B : t₁ ∩ Iic a ⊆ s, from subset.trans (inter_subset_inter_right _ (A ht₂)) hts, from this.imp (λ l', Exists.imp $ λ hl' hl x hx, B ⟨hl hx.1, hx.2⟩) }, clear hts ht₂ t₂, -- Now we find `l` such that `(l', ∞) ⊆ t₁` rw [mem_binfi] at ht₁, { rcases ht₁ with ⟨b, hb, hb'⟩, exact ⟨max b l, ⟨le_max_right _ _, max_lt hb hl⟩, λ x hx, hb' $ Ioi_subset_Ioi (le_max_left _ _) hx⟩ }, { intros b hb b' hb', simp only [mem_Iio] at hb hb', use [max b b', max_lt hb hb'], simp [le_refl] }, exact ⟨l, hl⟩ end lemma exists_Ico_subset_of_mem_nhds' {a : α} {s : set α} (hs : s ∈ 𝓝 a) {u : α} (hu : a < u) : ∃ u' ∈ Ioc a u, Ico a u' ⊆ s := begin convert @exists_Ioc_subset_of_mem_nhds' (order_dual α) _ _ _ _ _ hs _ hu, ext, rw [dual_Ico, dual_Ioc] end lemma exists_Ioc_subset_of_mem_nhds {a : α} {s : set α} (hs : s ∈ 𝓝 a) (h : ∃ l, l < a) : ∃ l < a, Ioc l a ⊆ s := let ⟨l', hl'⟩ := h in let ⟨l, hl⟩ := exists_Ioc_subset_of_mem_nhds' hs hl' in ⟨l, hl.fst.2, hl.snd⟩ lemma exists_Ico_subset_of_mem_nhds {a : α} {s : set α} (hs : s ∈ 𝓝 a) (h : ∃ u, a < u) : ∃ u (_ : a < u), Ico a u ⊆ s := let ⟨l', hl'⟩ := h in let ⟨l, hl⟩ := exists_Ico_subset_of_mem_nhds' hs hl' in ⟨l, hl.fst.1, hl.snd⟩ lemma order_separated {a₁ a₂ : α} (h : a₁ < a₂) : ∃u v : set α, is_open u ∧ is_open v ∧ a₁ ∈ u ∧ a₂ ∈ v ∧ (∀b₁∈u, ∀b₂∈v, b₁ < b₂) := match dense_or_discrete a₁ a₂ with | or.inl ⟨a, ha₁, ha₂⟩ := ⟨{a' | a' < a}, {a' | a < a'}, is_open_gt' a, is_open_lt' a, ha₁, ha₂, assume b₁ h₁ b₂ h₂, lt_trans h₁ h₂⟩ | or.inr ⟨h₁, h₂⟩ := ⟨{a | a < a₂}, {a | a₁ < a}, is_open_gt' a₂, is_open_lt' a₁, h, h, assume b₁ hb₁ b₂ hb₂, calc b₁ ≤ a₁ : h₂ _ hb₁ ... < a₂ : h ... ≤ b₂ : h₁ _ hb₂⟩ end @[priority 100] -- see Note [lower instance priority] instance order_topology.to_order_closed_topology : order_closed_topology α := { is_closed_le' := is_open_compl_iff.1 $ is_open_prod_iff.mpr $ assume a₁ a₂ (h : ¬ a₁ ≤ a₂), have h : a₂ < a₁, from lt_of_not_ge h, let ⟨u, v, hu, hv, ha₁, ha₂, h⟩ := order_separated h in ⟨v, u, hv, hu, ha₂, ha₁, assume ⟨b₁, b₂⟩ ⟨h₁, h₂⟩, not_le_of_gt $ h b₂ h₂ b₁ h₁⟩ } lemma order_topology.t2_space : t2_space α := by apply_instance @[priority 100] -- see Note [lower instance priority] instance order_topology.regular_space : regular_space α := { regular := assume s a hs ha, have hs' : sᶜ ∈ 𝓝 a, from is_open.mem_nhds hs.is_open_compl ha, have ∃t:set α, is_open t ∧ (∀l∈ s, l < a → l ∈ t) ∧ 𝓝[t] a = ⊥, from by_cases (assume h : ∃l, l < a, let ⟨l, hl, h⟩ := exists_Ioc_subset_of_mem_nhds hs' h in match dense_or_discrete l a with | or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | a < b}, is_open_gt' _, assume c hcs hca, show c < b, from lt_of_not_ge $ assume hbc, h ⟨lt_of_lt_of_le hb₁ hbc, le_of_lt hca⟩ hcs, inf_principal_eq_bot.2 $ (𝓝 a).sets_of_superset ((is_open_lt' _).mem_nhds hb₂) $ assume x (hx : b < x), show ¬ x < b, from not_lt.2 $ le_of_lt hx⟩ | or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' < a}, is_open_gt' _, assume b hbs hba, hba, inf_principal_eq_bot.2 $ (𝓝 a).sets_of_superset ((is_open_lt' _).mem_nhds hl) $ assume x (hx : l < x), show ¬ x < a, from not_lt.2 $ h₁ _ hx⟩ end) (assume : ¬ ∃l, l < a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim, nhds_within_empty _⟩), let ⟨t₁, ht₁o, ht₁s, ht₁a⟩ := this in have ∃t:set α, is_open t ∧ (∀u∈ s, u>a → u ∈ t) ∧ 𝓝[t] a = ⊥, from by_cases (assume h : ∃u, u > a, let ⟨u, hu, h⟩ := exists_Ico_subset_of_mem_nhds hs' h in match dense_or_discrete a u with | or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | b < a}, is_open_lt' _, assume c hcs hca, show c > b, from lt_of_not_ge $ assume hbc, h ⟨le_of_lt hca, lt_of_le_of_lt hbc hb₂⟩ hcs, inf_principal_eq_bot.2 $ (𝓝 a).sets_of_superset ((is_open_gt' _).mem_nhds hb₁) $ assume x (hx : b > x), show ¬ x > b, from not_lt.2 $ le_of_lt hx⟩ | or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' > a}, is_open_lt' _, assume b hbs hba, hba, inf_principal_eq_bot.2 $ (𝓝 a).sets_of_superset ((is_open_gt' _).mem_nhds hu) $ assume x (hx : u > x), show ¬ x > a, from not_lt.2 $ h₂ _ hx⟩ end) (assume : ¬ ∃u, u > a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim, nhds_within_empty _⟩), let ⟨t₂, ht₂o, ht₂s, ht₂a⟩ := this in ⟨t₁ ∪ t₂, is_open.union ht₁o ht₂o, assume x hx, have x ≠ a, from assume eq, ha $ eq ▸ hx, (ne_iff_lt_or_gt.mp this).imp (ht₁s _ hx) (ht₂s _ hx), by rw [nhds_within_union, ht₁a, ht₂a, bot_sup_eq]⟩, ..order_topology.t2_space } /-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`, provided `a` is neither a bottom element nor a top element. -/ lemma mem_nhds_iff_exists_Ioo_subset' {a : α} {s : set α} (hl : ∃ l, l < a) (hu : ∃ u, a < u) : s ∈ 𝓝 a ↔ ∃l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s := begin split, { assume h, rcases exists_Ico_subset_of_mem_nhds h hu with ⟨u, au, hu⟩, rcases exists_Ioc_subset_of_mem_nhds h hl with ⟨l, la, hl⟩, refine ⟨l, u, ⟨la, au⟩, λx hx, _⟩, cases le_total a x with hax hax, { exact hu ⟨hax, hx.2⟩ }, { exact hl ⟨hx.1, hax⟩ } }, { rintros ⟨l, u, ha, h⟩, apply mem_sets_of_superset (is_open.mem_nhds is_open_Ioo ha) h } end /-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`. -/ lemma mem_nhds_iff_exists_Ioo_subset [no_top_order α] [no_bot_order α] {a : α} {s : set α} : s ∈ 𝓝 a ↔ ∃l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s := mem_nhds_iff_exists_Ioo_subset' (no_bot a) (no_top a) lemma nhds_basis_Ioo' {a : α} (hl : ∃ l, l < a) (hu : ∃ u, a < u) : (𝓝 a).has_basis (λ b : α × α, b.1 < a ∧ a < b.2) (λ b, Ioo b.1 b.2) := ⟨λ s, (mem_nhds_iff_exists_Ioo_subset' hl hu).trans $ by simp⟩ lemma nhds_basis_Ioo [no_top_order α] [no_bot_order α] (a : α) : (𝓝 a).has_basis (λ b : α × α, b.1 < a ∧ a < b.2) (λ b, Ioo b.1 b.2) := nhds_basis_Ioo' (no_bot a) (no_top a) lemma filter.eventually.exists_Ioo_subset [no_top_order α] [no_bot_order α] {a : α} {p : α → Prop} (hp : ∀ᶠ x in 𝓝 a, p x) : ∃ l u, a ∈ Ioo l u ∧ Ioo l u ⊆ {x | p x} := mem_nhds_iff_exists_Ioo_subset.1 hp lemma Iio_mem_nhds {a b : α} (h : a < b) : Iio b ∈ 𝓝 a := is_open.mem_nhds is_open_Iio h lemma Ioi_mem_nhds {a b : α} (h : a < b) : Ioi a ∈ 𝓝 b := is_open.mem_nhds is_open_Ioi h lemma Iic_mem_nhds {a b : α} (h : a < b) : Iic b ∈ 𝓝 a := mem_sets_of_superset (Iio_mem_nhds h) Iio_subset_Iic_self lemma Ici_mem_nhds {a b : α} (h : a < b) : Ici a ∈ 𝓝 b := mem_sets_of_superset (Ioi_mem_nhds h) Ioi_subset_Ici_self lemma Ioo_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ioo a b ∈ 𝓝 x := is_open.mem_nhds is_open_Ioo ⟨ha, hb⟩ lemma Ioc_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ioc a b ∈ 𝓝 x := mem_sets_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Ioc_self lemma Ico_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ico a b ∈ 𝓝 x := mem_sets_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Ico_self lemma Icc_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Icc a b ∈ 𝓝 x := mem_sets_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Icc_self section pi /-! ### Intervals in `Π i, π i` belong to `𝓝 x` For each lemma `pi_Ixx_mem_nhds` we add a non-dependent version `pi_Ixx_mem_nhds'` because sometimes Lean fails to unify different instances while trying to apply the dependent version to, e.g., `ι → ℝ`. -/ variables {ι : Type*} {π : ι → Type*} [fintype ι] [Π i, linear_order (π i)] [Π i, topological_space (π i)] [∀ i, order_topology (π i)] {a b x : Π i, π i} {a' b' x' : ι → α} lemma pi_Iic_mem_nhds (ha : ∀ i, x i < a i) : Iic a ∈ 𝓝 x := pi_univ_Iic a ▸ set_pi_mem_nhds (finite.of_fintype _) (λ i _, Iic_mem_nhds (ha _)) lemma pi_Iic_mem_nhds' (ha : ∀ i, x' i < a' i) : Iic a' ∈ 𝓝 x' := pi_Iic_mem_nhds ha lemma pi_Ici_mem_nhds (ha : ∀ i, a i < x i) : Ici a ∈ 𝓝 x := pi_univ_Ici a ▸ set_pi_mem_nhds (finite.of_fintype _) (λ i _, Ici_mem_nhds (ha _)) lemma pi_Ici_mem_nhds' (ha : ∀ i, a' i < x' i) : Ici a' ∈ 𝓝 x' := pi_Ici_mem_nhds ha lemma pi_Icc_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Icc a b ∈ 𝓝 x := pi_univ_Icc a b ▸ set_pi_mem_nhds (finite.of_fintype _) (λ i _, Icc_mem_nhds (ha _) (hb _)) lemma pi_Icc_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Icc a' b' ∈ 𝓝 x' := pi_Icc_mem_nhds ha hb variables [nonempty ι] lemma pi_Iio_mem_nhds (ha : ∀ i, x i < a i) : Iio a ∈ 𝓝 x := begin refine mem_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ i _, _)) (pi_univ_Iio_subset a), exact Iio_mem_nhds (ha i) end lemma pi_Iio_mem_nhds' (ha : ∀ i, x' i < a' i) : Iio a' ∈ 𝓝 x' := pi_Iio_mem_nhds ha lemma pi_Ioi_mem_nhds (ha : ∀ i, a i < x i) : Ioi a ∈ 𝓝 x := @pi_Iio_mem_nhds ι (λ i, order_dual (π i)) _ _ _ _ _ _ _ ha lemma pi_Ioi_mem_nhds' (ha : ∀ i, a' i < x' i) : Ioi a' ∈ 𝓝 x' := pi_Ioi_mem_nhds ha lemma pi_Ioc_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Ioc a b ∈ 𝓝 x := begin refine mem_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ i _, _)) (pi_univ_Ioc_subset a b), exact Ioc_mem_nhds (ha i) (hb i) end lemma pi_Ioc_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Ioc a' b' ∈ 𝓝 x' := pi_Ioc_mem_nhds ha hb lemma pi_Ico_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Ico a b ∈ 𝓝 x := begin refine mem_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ i _, _)) (pi_univ_Ico_subset a b), exact Ico_mem_nhds (ha i) (hb i) end lemma pi_Ico_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Ico a' b' ∈ 𝓝 x' := pi_Ico_mem_nhds ha hb lemma pi_Ioo_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Ioo a b ∈ 𝓝 x := begin refine mem_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ i _, _)) (pi_univ_Ioo_subset a b), exact Ioo_mem_nhds (ha i) (hb i) end lemma pi_Ioo_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Ioo a' b' ∈ 𝓝 x' := pi_Ioo_mem_nhds ha hb end pi lemma disjoint_nhds_at_top [no_top_order α] (x : α) : disjoint (𝓝 x) at_top := begin rw filter.disjoint_iff, cases no_top x with a ha, use [Iio a, Iio_mem_nhds ha, Ici a, mem_at_top a], rw [inter_comm, Ici_inter_Iio, Ico_self] end @[simp] lemma inf_nhds_at_top [no_top_order α] (x : α) : 𝓝 x ⊓ at_top = ⊥ := disjoint_iff.1 (disjoint_nhds_at_top x) lemma disjoint_nhds_at_bot [no_bot_order α] (x : α) : disjoint (𝓝 x) at_bot := @disjoint_nhds_at_top (order_dual α) _ _ _ _ x @[simp] lemma inf_nhds_at_bot [no_bot_order α] (x : α) : 𝓝 x ⊓ at_bot = ⊥ := @inf_nhds_at_top (order_dual α) _ _ _ _ x lemma not_tendsto_nhds_of_tendsto_at_top [no_top_order α] {F : filter β} [ne_bot F] {f : β → α} (hf : tendsto f F at_top) (x : α) : ¬ tendsto f F (𝓝 x) := hf.not_tendsto (disjoint_nhds_at_top x).symm lemma not_tendsto_at_top_of_tendsto_nhds [no_top_order α] {F : filter β} [ne_bot F] {f : β → α} {x : α} (hf : tendsto f F (𝓝 x)) : ¬ tendsto f F at_top := hf.not_tendsto (disjoint_nhds_at_top x) lemma not_tendsto_nhds_of_tendsto_at_bot [no_bot_order α] {F : filter β} [ne_bot F] {f : β → α} (hf : tendsto f F at_bot) (x : α) : ¬ tendsto f F (𝓝 x) := hf.not_tendsto (disjoint_nhds_at_bot x).symm lemma not_tendsto_at_bot_of_tendsto_nhds [no_bot_order α] {F : filter β} [ne_bot F] {f : β → α} {x : α} (hf : tendsto f F (𝓝 x)) : ¬ tendsto f F at_bot := hf.not_tendsto (disjoint_nhds_at_bot x) /-! ### Neighborhoods to the left and to the right on an `order_topology` We've seen some properties of left and right neighborhood of a point in an `order_closed_topology`. In an `order_topology`, such neighborhoods can be characterized as the sets containing suitable intervals to the right or to the left of `a`. We give now these characterizations. -/ -- NB: If you extend the list, append to the end please to avoid breaking the API /-- The following statements are equivalent: 0. `s` is a neighborhood of `a` within `(a, +∞)` 1. `s` is a neighborhood of `a` within `(a, b]` 2. `s` is a neighborhood of `a` within `(a, b)` 3. `s` includes `(a, u)` for some `u ∈ (a, b]` 4. `s` includes `(a, u)` for some `u > a` -/ lemma tfae_mem_nhds_within_Ioi {a b : α} (hab : a < b) (s : set α) : tfae [s ∈ 𝓝[Ioi a] a, -- 0 : `s` is a neighborhood of `a` within `(a, +∞)` s ∈ 𝓝[Ioc a b] a, -- 1 : `s` is a neighborhood of `a` within `(a, b]` s ∈ 𝓝[Ioo a b] a, -- 2 : `s` is a neighborhood of `a` within `(a, b)` ∃ u ∈ Ioc a b, Ioo a u ⊆ s, -- 3 : `s` includes `(a, u)` for some `u ∈ (a, b]` ∃ u ∈ Ioi a, Ioo a u ⊆ s] := -- 4 : `s` includes `(a, u)` for some `u > a` begin tfae_have : 1 ↔ 2, by rw [nhds_within_Ioc_eq_nhds_within_Ioi hab], tfae_have : 1 ↔ 3, by rw [nhds_within_Ioo_eq_nhds_within_Ioi hab], tfae_have : 4 → 5, from λ ⟨u, umem, hu⟩, ⟨u, umem.1, hu⟩, tfae_have : 5 → 1, { rintros ⟨u, hau, hu⟩, exact mem_sets_of_superset (Ioo_mem_nhds_within_Ioi ⟨le_refl a, hau⟩) hu }, tfae_have : 1 → 4, { assume h, rcases mem_nhds_within_iff_exists_mem_nhds_inter.1 h with ⟨v, va, hv⟩, rcases exists_Ico_subset_of_mem_nhds' va hab with ⟨u, au, hu⟩, refine ⟨u, au, λx hx, _⟩, refine hv ⟨hu ⟨le_of_lt hx.1, hx.2⟩, _⟩, exact hx.1 }, tfae_finish end lemma mem_nhds_within_Ioi_iff_exists_mem_Ioc_Ioo_subset {a u' : α} {s : set α} (hu' : a < u') : s ∈ 𝓝[Ioi a] a ↔ ∃u ∈ Ioc a u', Ioo a u ⊆ s := (tfae_mem_nhds_within_Ioi hu' s).out 0 3 /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u)` with `a < u < u'`, provided `a` is not a top element. -/ lemma mem_nhds_within_Ioi_iff_exists_Ioo_subset' {a u' : α} {s : set α} (hu' : a < u') : s ∈ 𝓝[Ioi a] a ↔ ∃u ∈ Ioi a, Ioo a u ⊆ s := (tfae_mem_nhds_within_Ioi hu' s).out 0 4 /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u)` with `a < u`. -/ lemma mem_nhds_within_Ioi_iff_exists_Ioo_subset [no_top_order α] {a : α} {s : set α} : s ∈ 𝓝[Ioi a] a ↔ ∃u ∈ Ioi a, Ioo a u ⊆ s := let ⟨u', hu'⟩ := no_top a in mem_nhds_within_Ioi_iff_exists_Ioo_subset' hu' /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u]` with `a < u`. -/ lemma mem_nhds_within_Ioi_iff_exists_Ioc_subset [no_top_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[Ioi a] a ↔ ∃u ∈ Ioi a, Ioc a u ⊆ s := begin rw mem_nhds_within_Ioi_iff_exists_Ioo_subset, split, { rintros ⟨u, au, as⟩, rcases exists_between au with ⟨v, hv⟩, exact ⟨v, hv.1, λx hx, as ⟨hx.1, lt_of_le_of_lt hx.2 hv.2⟩⟩ }, { rintros ⟨u, au, as⟩, exact ⟨u, au, subset.trans Ioo_subset_Ioc_self as⟩ } end /-- The following statements are equivalent: 0. `s` is a neighborhood of `b` within `(-∞, b)` 1. `s` is a neighborhood of `b` within `[a, b)` 2. `s` is a neighborhood of `b` within `(a, b)` 3. `s` includes `(l, b)` for some `l ∈ [a, b)` 4. `s` includes `(l, b)` for some `l < b` -/ lemma tfae_mem_nhds_within_Iio {a b : α} (h : a < b) (s : set α) : tfae [s ∈ 𝓝[Iio b] b, -- 0 : `s` is a neighborhood of `b` within `(-∞, b)` s ∈ 𝓝[Ico a b] b, -- 1 : `s` is a neighborhood of `b` within `[a, b)` s ∈ 𝓝[Ioo a b] b, -- 2 : `s` is a neighborhood of `b` within `(a, b)` ∃ l ∈ Ico a b, Ioo l b ⊆ s, -- 3 : `s` includes `(l, b)` for some `l ∈ [a, b)` ∃ l ∈ Iio b, Ioo l b ⊆ s] := -- 4 : `s` includes `(l, b)` for some `l < b` begin have := @tfae_mem_nhds_within_Ioi (order_dual α) _ _ _ _ _ h s, -- If we call `convert` here, it generates wrong equations, so we need to simplify first simp only [exists_prop] at this ⊢, rw [dual_Ioi, dual_Ioc, dual_Ioo] at this, convert this; ext l; rw [dual_Ioo] end lemma mem_nhds_within_Iio_iff_exists_mem_Ico_Ioo_subset {a l' : α} {s : set α} (hl' : l' < a) : s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Ico l' a, Ioo l a ⊆ s := (tfae_mem_nhds_within_Iio hl' s).out 0 3 /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `(l, a)` with `l < a`, provided `a` is not a bottom element. -/ lemma mem_nhds_within_Iio_iff_exists_Ioo_subset' {a l' : α} {s : set α} (hl' : l' < a) : s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Iio a, Ioo l a ⊆ s := (tfae_mem_nhds_within_Iio hl' s).out 0 4 /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `(l, a)` with `l < a`. -/ lemma mem_nhds_within_Iio_iff_exists_Ioo_subset [no_bot_order α] {a : α} {s : set α} : s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Iio a, Ioo l a ⊆ s := let ⟨l', hl'⟩ := no_bot a in mem_nhds_within_Iio_iff_exists_Ioo_subset' hl' /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `[l, a)` with `l < a`. -/ lemma mem_nhds_within_Iio_iff_exists_Ico_subset [no_bot_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Iio a, Ico l a ⊆ s := begin convert @mem_nhds_within_Ioi_iff_exists_Ioc_subset (order_dual α) _ _ _ _ _ _ _, simp only [dual_Ioc], refl end /-- The following statements are equivalent: 0. `s` is a neighborhood of `a` within `[a, +∞)` 1. `s` is a neighborhood of `a` within `[a, b]` 2. `s` is a neighborhood of `a` within `[a, b)` 3. `s` includes `[a, u)` for some `u ∈ (a, b]` 4. `s` includes `[a, u)` for some `u > a` -/ lemma tfae_mem_nhds_within_Ici {a b : α} (hab : a < b) (s : set α) : tfae [s ∈ 𝓝[Ici a] a, -- 0 : `s` is a neighborhood of `a` within `[a, +∞)` s ∈ 𝓝[Icc a b] a, -- 1 : `s` is a neighborhood of `a` within `[a, b]` s ∈ 𝓝[Ico a b] a, -- 2 : `s` is a neighborhood of `a` within `[a, b)` ∃ u ∈ Ioc a b, Ico a u ⊆ s, -- 3 : `s` includes `[a, u)` for some `u ∈ (a, b]` ∃ u ∈ Ioi a, Ico a u ⊆ s] := -- 4 : `s` includes `[a, u)` for some `u > a` begin tfae_have : 1 ↔ 2, by rw [nhds_within_Icc_eq_nhds_within_Ici hab], tfae_have : 1 ↔ 3, by rw [nhds_within_Ico_eq_nhds_within_Ici hab], tfae_have : 4 → 5, from λ ⟨u, umem, hu⟩, ⟨u, umem.1, hu⟩, tfae_have : 5 → 1, { rintros ⟨u, hau, hu⟩, exact mem_sets_of_superset (Ico_mem_nhds_within_Ici ⟨le_refl a, hau⟩) hu }, tfae_have : 1 → 4, { assume h, rcases mem_nhds_within_iff_exists_mem_nhds_inter.1 h with ⟨v, va, hv⟩, rcases exists_Ico_subset_of_mem_nhds' va hab with ⟨u, au, hu⟩, refine ⟨u, au, λx hx, _⟩, refine hv ⟨hu ⟨hx.1, hx.2⟩, _⟩, exact hx.1 }, tfae_finish end lemma mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset {a u' : α} {s : set α} (hu' : a < u') : s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioc a u', Ico a u ⊆ s := (tfae_mem_nhds_within_Ici hu' s).out 0 3 (by norm_num) (by norm_num) /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u)` with `a < u < u'`, provided `a` is not a top element. -/ lemma mem_nhds_within_Ici_iff_exists_Ico_subset' {a u' : α} {s : set α} (hu' : a < u') : s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioi a, Ico a u ⊆ s := (tfae_mem_nhds_within_Ici hu' s).out 0 4 (by norm_num) (by norm_num) /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u)` with `a < u`. -/ lemma mem_nhds_within_Ici_iff_exists_Ico_subset [no_top_order α] {a : α} {s : set α} : s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioi a, Ico a u ⊆ s := let ⟨u', hu'⟩ := no_top a in mem_nhds_within_Ici_iff_exists_Ico_subset' hu' /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u]` with `a < u`. -/ lemma mem_nhds_within_Ici_iff_exists_Icc_subset' [no_top_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioi a, Icc a u ⊆ s := begin rw mem_nhds_within_Ici_iff_exists_Ico_subset, split, { rintros ⟨u, au, as⟩, rcases exists_between au with ⟨v, hv⟩, exact ⟨v, hv.1, λx hx, as ⟨hx.1, lt_of_le_of_lt hx.2 hv.2⟩⟩ }, { rintros ⟨u, au, as⟩, exact ⟨u, au, subset.trans Ico_subset_Icc_self as⟩ } end /-- The following statements are equivalent: 0. `s` is a neighborhood of `b` within `(-∞, b]` 1. `s` is a neighborhood of `b` within `[a, b]` 2. `s` is a neighborhood of `b` within `(a, b]` 3. `s` includes `(l, b]` for some `l ∈ [a, b)` 4. `s` includes `(l, b]` for some `l < b` -/ lemma tfae_mem_nhds_within_Iic {a b : α} (h : a < b) (s : set α) : tfae [s ∈ 𝓝[Iic b] b, -- 0 : `s` is a neighborhood of `b` within `(-∞, b]` s ∈ 𝓝[Icc a b] b, -- 1 : `s` is a neighborhood of `b` within `[a, b]` s ∈ 𝓝[Ioc a b] b, -- 2 : `s` is a neighborhood of `b` within `(a, b]` ∃ l ∈ Ico a b, Ioc l b ⊆ s, -- 3 : `s` includes `(l, b]` for some `l ∈ [a, b)` ∃ l ∈ Iio b, Ioc l b ⊆ s] := -- 4 : `s` includes `(l, b]` for some `l < b` begin have := @tfae_mem_nhds_within_Ici (order_dual α) _ _ _ _ _ h s, -- If we call `convert` here, it generates wrong equations, so we need to simplify first simp only [exists_prop] at this ⊢, rw [dual_Icc, dual_Ioc, dual_Ioi] at this, convert this; ext l; rw [dual_Ico] end lemma mem_nhds_within_Iic_iff_exists_mem_Ico_Ioc_subset {a l' : α} {s : set α} (hl' : l' < a) : s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Ico l' a, Ioc l a ⊆ s := (tfae_mem_nhds_within_Iic hl' s).out 0 3 (by norm_num) (by norm_num) /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `(l, a]` with `l < a`, provided `a` is not a bottom element. -/ lemma mem_nhds_within_Iic_iff_exists_Ioc_subset' {a l' : α} {s : set α} (hl' : l' < a) : s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Iio a, Ioc l a ⊆ s := (tfae_mem_nhds_within_Iic hl' s).out 0 4 (by norm_num) (by norm_num) /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `(l, a]` with `l < a`. -/ lemma mem_nhds_within_Iic_iff_exists_Ioc_subset [no_bot_order α] {a : α} {s : set α} : s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Iio a, Ioc l a ⊆ s := let ⟨l', hl'⟩ := no_bot a in mem_nhds_within_Iic_iff_exists_Ioc_subset' hl' /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `[l, a]` with `l < a`. -/ lemma mem_nhds_within_Iic_iff_exists_Icc_subset' [no_bot_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Iio a, Icc l a ⊆ s := begin convert @mem_nhds_within_Ici_iff_exists_Icc_subset' (order_dual α) _ _ _ _ _ _ _, simp_rw (show ∀ u : order_dual α, @Icc (order_dual α) _ a u = @Icc α _ u a, from λ u, dual_Icc), refl, end /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u]` with `a < u`. -/ lemma mem_nhds_within_Ici_iff_exists_Icc_subset [no_top_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[Ici a] a ↔ ∃u, a < u ∧ Icc a u ⊆ s := begin rw mem_nhds_within_Ici_iff_exists_Ico_subset, split, { rintros ⟨u, au, as⟩, rcases exists_between au with ⟨v, hv⟩, exact ⟨v, hv.1, λx hx, as ⟨hx.1, lt_of_le_of_lt hx.2 hv.2⟩⟩ }, { rintros ⟨u, au, as⟩, exact ⟨u, au, subset.trans Ico_subset_Icc_self as⟩ } end /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `[l, a]` with `l < a`. -/ lemma mem_nhds_within_Iic_iff_exists_Icc_subset [no_bot_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[Iic a] a ↔ ∃l, l < a ∧ Icc l a ⊆ s := begin rw mem_nhds_within_Iic_iff_exists_Ioc_subset, split, { rintros ⟨l, la, as⟩, rcases exists_between la with ⟨v, hv⟩, refine ⟨v, hv.2, λx hx, as ⟨lt_of_lt_of_le hv.1 hx.1, hx.2⟩⟩, }, { rintros ⟨l, la, as⟩, exact ⟨l, la, subset.trans Ioc_subset_Icc_self as⟩ } end end linear_order section linear_ordered_add_comm_group variables [topological_space α] [linear_ordered_add_comm_group α] [order_topology α] variables {l : filter β} {f g : β → α} local notation `|` x `|` := abs x lemma nhds_eq_infi_abs_sub (a : α) : 𝓝 a = (⨅r>0, 𝓟 {b | |a - b| < r}) := begin simp only [le_antisymm_iff, nhds_eq_order, le_inf_iff, le_infi_iff, le_principal_iff, mem_Ioi, mem_Iio, abs_sub_lt_iff, @sub_lt_iff_lt_add _ _ _ _ _ _ a, @sub_lt _ _ _ _ a, set_of_and], refine ⟨_, _, _⟩, { intros ε ε0, exact inter_mem_inf_sets (mem_infi_sets (a - ε) $ mem_infi_sets (sub_lt_self a ε0) (mem_principal_self _)) (mem_infi_sets (ε + a) $ mem_infi_sets (by simpa) (mem_principal_self _)) }, { intros b hb, exact mem_infi_sets (a - b) (mem_infi_sets (sub_pos.2 hb) (by simp [Ioi])) }, { intros b hb, exact mem_infi_sets (b - a) (mem_infi_sets (sub_pos.2 hb) (by simp [Iio])) } end lemma order_topology_of_nhds_abs {α : Type*} [topological_space α] [linear_ordered_add_comm_group α] (h_nhds : ∀a:α, 𝓝 a = (⨅r>0, 𝓟 {b | |a - b| < r})) : order_topology α := begin refine ⟨eq_of_nhds_eq_nhds $ λ a, _⟩, rw [h_nhds], letI := preorder.topology α, letI : order_topology α := ⟨rfl⟩, exact (nhds_eq_infi_abs_sub a).symm end lemma linear_ordered_add_comm_group.tendsto_nhds {x : filter β} {a : α} : tendsto f x (𝓝 a) ↔ ∀ ε > (0 : α), ∀ᶠ b in x, |f b - a| < ε := by simp [nhds_eq_infi_abs_sub, abs_sub_comm a] lemma eventually_abs_sub_lt (a : α) {ε : α} (hε : 0 < ε) : ∀ᶠ x in 𝓝 a, |x - a| < ε := (nhds_eq_infi_abs_sub a).symm ▸ mem_infi_sets ε (mem_infi_sets hε $ by simp only [abs_sub_comm, mem_principal_self]) @[priority 100] -- see Note [lower instance priority] instance linear_ordered_add_comm_group.topological_add_group : topological_add_group α := { continuous_add := begin refine continuous_iff_continuous_at.2 _, rintro ⟨a, b⟩, refine linear_ordered_add_comm_group.tendsto_nhds.2 (λ ε ε0, _), rcases dense_or_discrete 0 ε with (⟨δ, δ0, δε⟩|⟨h₁, h₂⟩), { -- If there exists `δ ∈ (0, ε)`, then we choose `δ`-nhd of `a` and `(ε-δ)`-nhd of `b` filter_upwards [prod_is_open.mem_nhds (eventually_abs_sub_lt a δ0) (eventually_abs_sub_lt b (sub_pos.2 δε))], rintros ⟨x, y⟩ ⟨hx : |x - a| < δ, hy : |y - b| < ε - δ⟩, rw [add_sub_comm], calc |x - a + (y - b)| ≤ |x - a| + |y - b| : abs_add _ _ ... < δ + (ε - δ) : add_lt_add hx hy ... = ε : add_sub_cancel'_right _ _ }, { -- Otherewise `ε`-nhd of each point `a` is `{a}` have hε : ∀ {x y}, abs (x - y) < ε → x = y, { intros x y h, simpa [sub_eq_zero] using h₂ _ h }, filter_upwards [prod_is_open.mem_nhds (eventually_abs_sub_lt a ε0) (eventually_abs_sub_lt b ε0)], rintros ⟨x, y⟩ ⟨hx : |x - a| < ε, hy : |y - b| < ε⟩, simpa [hε hx, hε hy] } end, continuous_neg := continuous_iff_continuous_at.2 $ λ a, linear_ordered_add_comm_group.tendsto_nhds.2 $ λ ε ε0, (eventually_abs_sub_lt a ε0).mono $ λ x hx, by rwa [neg_sub_neg, abs_sub_comm] } @[continuity] lemma continuous_abs : continuous (abs : α → α) := continuous_id.max continuous_neg lemma filter.tendsto.abs {f : β → α} {a : α} {l : filter β} (h : tendsto f l (𝓝 a)) : tendsto (λ x, |f x|) l (𝓝 (|a|)) := (continuous_abs.tendsto _).comp h lemma nhds_basis_Ioo_pos [no_bot_order α] [no_top_order α] (a : α) : (𝓝 a).has_basis (λ ε : α, (0 : α) < ε) (λ ε, Ioo (a-ε) (a+ε)) := ⟨begin refine λ t, (nhds_basis_Ioo a).mem_iff.trans ⟨_, _⟩, { rintros ⟨⟨l, u⟩, ⟨hl : l < a, hu : a < u⟩, h' : Ioo l u ⊆ t⟩, refine ⟨min (a-l) (u-a), by apply lt_min; rwa sub_pos, _⟩, rintros x ⟨hx, hx'⟩, apply h', rw [sub_lt, lt_min_iff, sub_lt_sub_iff_left] at hx, rw [← sub_lt_iff_lt_add', lt_min_iff, sub_lt_sub_iff_right] at hx', exact ⟨hx.1, hx'.2⟩ }, { rintros ⟨ε, ε_pos, h⟩, exact ⟨(a-ε, a+ε), by simp [ε_pos], h⟩ }, end⟩ lemma nhds_basis_abs_sub_lt [no_bot_order α] [no_top_order α] (a : α) : (𝓝 a).has_basis (λ ε : α, (0 : α) < ε) (λ ε, {b | abs (b - a) < ε}) := begin convert nhds_basis_Ioo_pos a, { ext ε, change abs (x - a) < ε ↔ a - ε < x ∧ x < a + ε, simp [abs_lt, sub_lt_iff_lt_add, add_comm ε a, add_comm x ε] } end variable (α) lemma nhds_basis_zero_abs_sub_lt [no_bot_order α] [no_top_order α] : (𝓝 (0 : α)).has_basis (λ ε : α, (0 : α) < ε) (λ ε, {b | abs b < ε}) := by simpa using nhds_basis_abs_sub_lt (0 : α) variable {α} /-- If `a` is positive we can form a basis from only nonnegative `Ioo` intervals -/ lemma nhds_basis_Ioo_pos_of_pos [no_bot_order α] [no_top_order α] {a : α} (ha : 0 < a) : (𝓝 a).has_basis (λ ε : α, (0 : α) < ε ∧ ε ≤ a) (λ ε, Ioo (a-ε) (a+ε)) := ⟨ λ t, (nhds_basis_Ioo_pos a).mem_iff.trans ⟨λ h, let ⟨i, hi, hit⟩ := h in ⟨min i a, ⟨lt_min hi ha, min_le_right i a⟩, trans (Ioo_subset_Ioo (sub_le_sub_left (min_le_left i a) a) (add_le_add_left (min_le_left i a) a)) hit⟩, λ h, let ⟨i, hi, hit⟩ := h in ⟨i, hi.1, hit⟩ ⟩ ⟩ section variables [topological_space β] {b : β} {a : α} {s : set β} lemma continuous.abs (h : continuous f) : continuous (λ x, |f x|) := continuous_abs.comp h lemma continuous_at.abs (h : continuous_at f b) : continuous_at (λ x, |f x|) b := h.abs lemma continuous_within_at.abs (h : continuous_within_at f s b) : continuous_within_at (λ x, |f x|) s b := h.abs lemma continuous_on.abs (h : continuous_on f s) : continuous_on (λ x, |f x|) s := λ x hx, (h x hx).abs lemma tendsto_abs_nhds_within_zero : tendsto (abs : α → α) (𝓝[{0}ᶜ] 0) (𝓝[Ioi 0] 0) := (continuous_abs.tendsto' (0 : α) 0 abs_zero).inf $ tendsto_principal_principal.2 $ λ x, abs_pos.2 end /-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `C` and `g` tends to `at_top` then `f + g` tends to `at_top`. -/ lemma filter.tendsto.add_at_top {C : α} (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_top) : tendsto (λ x, f x + g x) l at_top := begin nontriviality α, obtain ⟨C', hC'⟩ : ∃ C', C' < C := no_bot C, refine tendsto_at_top_add_left_of_le' _ C' _ hg, exact (hf.eventually (lt_mem_nhds hC')).mono (λ x, le_of_lt) end /-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `C` and `g` tends to `at_bot` then `f + g` tends to `at_bot`. -/ lemma filter.tendsto.add_at_bot {C : α} (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_bot) : tendsto (λ x, f x + g x) l at_bot := @filter.tendsto.add_at_top (order_dual α) _ _ _ _ _ _ _ _ hf hg /-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `at_top` and `g` tends to `C` then `f + g` tends to `at_top`. -/ lemma filter.tendsto.at_top_add {C : α} (hf : tendsto f l at_top) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, f x + g x) l at_top := by { conv in (_ + _) { rw add_comm }, exact hg.add_at_top hf } /-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `at_bot` and `g` tends to `C` then `f + g` tends to `at_bot`. -/ lemma filter.tendsto.at_bot_add {C : α} (hf : tendsto f l at_bot) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, f x + g x) l at_bot := by { conv in (_ + _) { rw add_comm }, exact hg.add_at_bot hf } end linear_ordered_add_comm_group section linear_ordered_field variables [linear_ordered_field α] [topological_space α] [order_topology α] variables {l : filter β} {f g : β → α} section continuous_mul lemma mul_tendsto_nhds_zero_right (x : α) : tendsto (uncurry ((*) : α → α → α)) (𝓝 0 ×ᶠ 𝓝 x) $ 𝓝 0 := begin have hx : 0 < 2 * (1 + abs x) := (mul_pos (zero_lt_two) $ lt_of_lt_of_le zero_lt_one $ le_add_of_le_of_nonneg le_rfl (abs_nonneg x)), rw ((nhds_basis_zero_abs_sub_lt α).prod $ nhds_basis_abs_sub_lt x).tendsto_iff (nhds_basis_zero_abs_sub_lt α), refine λ ε ε_pos, ⟨(ε/(2 * (1 + abs x)), 1), ⟨div_pos ε_pos hx, zero_lt_one⟩, _⟩, suffices : ∀ (a b : α), abs a < ε / (2 * (1 + abs x)) → abs (b - x) < 1 → (abs a) * (abs b) < ε, by simpa only [and_imp, prod.forall, mem_prod, ← abs_mul], intros a b h h', refine lt_of_le_of_lt (mul_le_mul_of_nonneg_left _ (abs_nonneg a)) ((lt_div_iff hx).1 h), calc abs b = abs ((b - x) + x) : by rw sub_add_cancel b x ... ≤ abs (b - x) + abs x : abs_add (b - x) x ... ≤ 1 + abs x : add_le_add_right (le_of_lt h') (abs x) ... ≤ 2 * (1 + abs x) : by linarith, end lemma mul_tendsto_nhds_zero_left (x : α) : tendsto (uncurry ((*) : α → α → α)) (𝓝 x ×ᶠ 𝓝 0) $ 𝓝 0 := begin intros s hs, have := mul_tendsto_nhds_zero_right x hs, rw [filter.mem_map, mem_prod_iff] at this ⊢, obtain ⟨U, hU, V, hV, h⟩ := this, exact ⟨V, hV, U, hU, λ y hy, ((mul_comm y.2 y.1) ▸ h (⟨hy.2, hy.1⟩ : (prod.mk y.2 y.1) ∈ (U.prod V)) : y.1 * y.2 ∈ s)⟩, end lemma nhds_eq_map_mul_left_nhds_one {x₀ : α} (hx₀ : x₀ ≠ 0) : 𝓝 x₀ = map (λ x, x₀*x) (𝓝 1) := begin have hx₀' : 0 < abs x₀ := abs_pos.2 hx₀, refine filter.ext (λ t, _), simp only [exists_prop, set_of_subset_set_of, (nhds_basis_abs_sub_lt x₀).mem_iff, (nhds_basis_abs_sub_lt (1 : α)).mem_iff, filter.mem_map], refine ⟨λ h, _, λ h, _⟩, { obtain ⟨i, hi, hit⟩ := h, refine ⟨i / (abs x₀), div_pos hi (abs_pos.2 hx₀), λ x hx, hit _⟩, calc abs (x₀ * x - x₀) = abs (x₀ * (x - 1)) : congr_arg abs (by ring_nf) ... = abs x₀ * abs (x - 1) : abs_mul x₀ (x - 1) ... < abs x₀ * (i / abs x₀) : mul_lt_mul' le_rfl hx (abs_nonneg (x - 1)) (abs_pos.2 hx₀) ... = abs x₀ * i / abs x₀ : by ring ... = i : mul_div_cancel_left i (λ h, hx₀ (abs_eq_zero.1 h)) }, { obtain ⟨i, hi, hit⟩ := h, refine ⟨i * (abs x₀), mul_pos hi (abs_pos.2 hx₀), λ x hx, _⟩, have : abs (x / x₀ - 1) < i, calc abs (x / x₀ - 1) = abs (x / x₀ - x₀ / x₀) : (by rw div_self hx₀) ... = abs ((x - x₀) / x₀) : congr_arg abs (sub_div x x₀ x₀).symm ... = abs (x - x₀) / abs x₀ : abs_div (x - x₀) x₀ ... < i * abs x₀ / abs x₀ : div_lt_div hx le_rfl (mul_nonneg (le_of_lt hi) (abs_nonneg x₀)) (abs_pos.2 hx₀) ... = i : by rw [← mul_div_assoc', div_self (ne_of_lt $ abs_pos.2 hx₀).symm, mul_one], specialize hit (x / x₀) this, rwa [mul_div_assoc', mul_div_cancel_left x hx₀] at hit } end lemma nhds_eq_map_mul_right_nhds_one {x₀ : α} (hx₀ : x₀ ≠ 0) : 𝓝 x₀ = map (λ x, x*x₀) (𝓝 1) := by simp_rw [mul_comm _ x₀, nhds_eq_map_mul_left_nhds_one hx₀] lemma mul_tendsto_nhds_one_nhds_one : tendsto (uncurry ((*) : α → α → α)) (𝓝 1 ×ᶠ 𝓝 1) $ 𝓝 1 := begin rw ((nhds_basis_Ioo_pos (1 : α)).prod $ nhds_basis_Ioo_pos (1 : α)).tendsto_iff (nhds_basis_Ioo_pos_of_pos (zero_lt_one : (0 : α) < 1)), intros ε hε, have hε' : 0 ≤ 1 - ε / 4 := by linarith, have ε_pos : 0 < ε / 4 := by linarith, have ε_pos' : 0 < ε / 2 := by linarith, simp only [and_imp, prod.forall, mem_Ioo, function.uncurry_apply_pair, mem_prod, prod.exists], refine ⟨ε/4, ε/4, ⟨ε_pos, ε_pos⟩, λ a b ha ha' hb hb', _⟩, have ha0 : 0 ≤ a := le_trans hε' (le_of_lt ha), have hb0 : 0 ≤ b := le_trans hε' (le_of_lt hb), refine ⟨lt_of_le_of_lt _ (mul_lt_mul'' ha hb hε' hε'), lt_of_lt_of_le (mul_lt_mul'' ha' hb' ha0 hb0) _⟩, { calc 1 - ε = 1 - ε / 2 - ε/2 : by ring_nf ... ≤ 1 - ε/2 - ε/2 + (ε/2)*(ε/2) : le_add_of_nonneg_right (le_of_lt (mul_pos ε_pos' ε_pos')) ... = (1 - ε/2) * (1 - ε/2) : by ring_nf ... ≤ (1 - ε/4) * (1 - ε/4) : mul_le_mul (by linarith) (by linarith) (by linarith) hε' }, { calc (1 + ε/4) * (1 + ε/4) = 1 + ε/2 + (ε/4)*(ε/4) : by ring_nf ... = 1 + ε/2 + (ε * ε) / 16 : by ring_nf ... ≤ 1 + ε/2 + ε/2 : add_le_add_left (div_le_div (le_of_lt hε.1) (le_trans ((mul_le_mul_left hε.1).2 hε.2) (le_of_eq $ mul_one ε)) zero_lt_two (by linarith)) (1 + ε/2) ... ≤ 1 + ε : by ring_nf } end @[priority 100] instance linear_ordered_field.has_continuous_mul : has_continuous_mul α := ⟨begin rw continuous_iff_continuous_at, rintro ⟨x₀, y₀⟩, by_cases hx₀ : x₀ = 0, { rw [hx₀, continuous_at, zero_mul, nhds_prod_eq], exact mul_tendsto_nhds_zero_right y₀ }, by_cases hy₀ : y₀ = 0, { rw [hy₀, continuous_at, mul_zero, nhds_prod_eq], exact mul_tendsto_nhds_zero_left x₀ }, have hxy : x₀ * y₀ ≠ 0 := mul_ne_zero hx₀ hy₀, have key : (λ p : α × α, x₀ * p.1 * (p.2 * y₀)) = ((λ x, x₀*x) ∘ (λ x, x*y₀)) ∘ (uncurry (*)), { ext p, simp [uncurry, mul_assoc] }, have key₂ : (λ x, x₀*x) ∘ (λ x, y₀*x) = λ x, (x₀ *y₀)*x, { ext x, simp }, calc map (uncurry (*)) (𝓝 (x₀, y₀)) = map (uncurry (*)) (𝓝 x₀ ×ᶠ 𝓝 y₀) : by rw nhds_prod_eq ... = map (λ (p : α × α), x₀ * p.1 * (p.2 * y₀)) ((𝓝 1) ×ᶠ (𝓝 1)) : by rw [uncurry, nhds_eq_map_mul_left_nhds_one hx₀, nhds_eq_map_mul_right_nhds_one hy₀, prod_map_map_eq, filter.map_map] ... = map ((λ x, x₀ * x) ∘ λ x, x * y₀) (map (uncurry (*)) (𝓝 1 ×ᶠ 𝓝 1)) : by rw [key, ← filter.map_map] ... ≤ map ((λ (x : α), x₀ * x) ∘ λ x, x * y₀) (𝓝 1) : map_mono (mul_tendsto_nhds_one_nhds_one) ... = 𝓝 (x₀*y₀) : by rw [← filter.map_map, ← nhds_eq_map_mul_right_nhds_one hy₀, nhds_eq_map_mul_left_nhds_one hy₀, filter.map_map, key₂, ← nhds_eq_map_mul_left_nhds_one hxy], end⟩ end continuous_mul /-- In a linearly ordered field with the order topology, if `f` tends to `at_top` and `g` tends to a positive constant `C` then `f * g` tends to `at_top`. -/ lemma filter.tendsto.at_top_mul {C : α} (hC : 0 < C) (hf : tendsto f l at_top) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, (f x * g x)) l at_top := begin refine tendsto_at_top_mono' _ _ (hf.at_top_mul_const (half_pos hC)), filter_upwards [hg.eventually (lt_mem_nhds (half_lt_self hC)), hf.eventually (eventually_ge_at_top 0)], exact λ x hg hf, mul_le_mul_of_nonneg_left hg.le hf end /-- In a linearly ordered field with the order topology, if `f` tends to a positive constant `C` and `g` tends to `at_top` then `f * g` tends to `at_top`. -/ lemma filter.tendsto.mul_at_top {C : α} (hC : 0 < C) (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_top) : tendsto (λ x, (f x * g x)) l at_top := by simpa only [mul_comm] using hg.at_top_mul hC hf /-- In a linearly ordered field with the order topology, if `f` tends to `at_top` and `g` tends to a negative constant `C` then `f * g` tends to `at_bot`. -/ lemma filter.tendsto.at_top_mul_neg {C : α} (hC : C < 0) (hf : tendsto f l at_top) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, (f x * g x)) l at_bot := by simpa only [(∘), neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_at_top_at_bot.comp (hf.at_top_mul (neg_pos.2 hC) hg.neg) /-- In a linearly ordered field with the order topology, if `f` tends to a negative constant `C` and `g` tends to `at_top` then `f * g` tends to `at_bot`. -/ lemma filter.tendsto.neg_mul_at_top {C : α} (hC : C < 0) (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_top) : tendsto (λ x, (f x * g x)) l at_bot := by simpa only [mul_comm] using hg.at_top_mul_neg hC hf /-- In a linearly ordered field with the order topology, if `f` tends to `at_bot` and `g` tends to a positive constant `C` then `f * g` tends to `at_bot`. -/ lemma filter.tendsto.at_bot_mul {C : α} (hC : 0 < C) (hf : tendsto f l at_bot) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, (f x * g x)) l at_bot := by simpa [(∘)] using tendsto_neg_at_top_at_bot.comp ((tendsto_neg_at_bot_at_top.comp hf).at_top_mul hC hg) /-- In a linearly ordered field with the order topology, if `f` tends to `at_bot` and `g` tends to a negative constant `C` then `f * g` tends to `at_top`. -/ lemma filter.tendsto.at_bot_mul_neg {C : α} (hC : C < 0) (hf : tendsto f l at_bot) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, (f x * g x)) l at_top := by simpa [(∘)] using tendsto_neg_at_bot_at_top.comp ((tendsto_neg_at_bot_at_top.comp hf).at_top_mul_neg hC hg) /-- In a linearly ordered field with the order topology, if `f` tends to a positive constant `C` and `g` tends to `at_bot` then `f * g` tends to `at_bot`. -/ lemma filter.tendsto.mul_at_bot {C : α} (hC : 0 < C) (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_bot) : tendsto (λ x, (f x * g x)) l at_bot := by simpa only [mul_comm] using hg.at_bot_mul hC hf /-- In a linearly ordered field with the order topology, if `f` tends to a negative constant `C` and `g` tends to `at_bot` then `f * g` tends to `at_top`. -/ lemma filter.tendsto.neg_mul_at_bot {C : α} (hC : C < 0) (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_bot) : tendsto (λ x, (f x * g x)) l at_top := by simpa only [mul_comm] using hg.at_bot_mul_neg hC hf /-- The function `x ↦ x⁻¹` tends to `+∞` on the right of `0`. -/ lemma tendsto_inv_zero_at_top : tendsto (λx:α, x⁻¹) (𝓝[set.Ioi (0:α)] 0) at_top := begin refine (at_top_basis' 1).tendsto_right_iff.2 (λ b hb, _), have hb' : 0 < b := zero_lt_one.trans_le hb, filter_upwards [Ioc_mem_nhds_within_Ioi ⟨le_rfl, inv_pos.2 hb'⟩], exact λ x hx, (le_inv hx.1 hb').1 hx.2 end /-- The function `r ↦ r⁻¹` tends to `0` on the right as `r → +∞`. -/ lemma tendsto_inv_at_top_zero' : tendsto (λr:α, r⁻¹) at_top (𝓝[set.Ioi (0:α)] 0) := begin refine (has_basis.tendsto_iff at_top_basis ⟨λ s, mem_nhds_within_Ioi_iff_exists_Ioc_subset⟩).2 _, refine λ b hb, ⟨b⁻¹, trivial, λ x hx, _⟩, have : 0 < x := lt_of_lt_of_le (inv_pos.2 hb) hx, exact ⟨inv_pos.2 this, (inv_le this hb).2 hx⟩ end lemma tendsto_inv_at_top_zero : tendsto (λr:α, r⁻¹) at_top (𝓝 0) := tendsto_inv_at_top_zero'.mono_right inf_le_left lemma filter.tendsto.div_at_top [has_continuous_mul α] {f g : β → α} {l : filter β} {a : α} (h : tendsto f l (𝓝 a)) (hg : tendsto g l at_top) : tendsto (λ x, f x / g x) l (𝓝 0) := by { simp only [div_eq_mul_inv], exact mul_zero a ▸ h.mul (tendsto_inv_at_top_zero.comp hg) } lemma filter.tendsto.inv_tendsto_at_top (h : tendsto f l at_top) : tendsto (f⁻¹) l (𝓝 0) := tendsto_inv_at_top_zero.comp h lemma filter.tendsto.inv_tendsto_zero (h : tendsto f l (𝓝[set.Ioi 0] 0)) : tendsto (f⁻¹) l at_top := tendsto_inv_zero_at_top.comp h /-- The function `x^(-n)` tends to `0` at `+∞` for any positive natural `n`. A version for positive real powers exists as `tendsto_rpow_neg_at_top`. -/ lemma tendsto_pow_neg_at_top {n : ℕ} (hn : 1 ≤ n) : tendsto (λ x : α, x ^ (-(n:ℤ))) at_top (𝓝 0) := tendsto.congr (λ x, (fpow_neg x n).symm) (filter.tendsto.inv_tendsto_at_top (by simpa [gpow_coe_nat] using tendsto_pow_at_top hn)) lemma tendsto_fpow_at_top_zero {n : ℤ} (hn : n < 0) : tendsto (λ x : α, x^n) at_top (𝓝 0) := begin have : 1 ≤ -n := le_neg.mp (int.le_of_lt_add_one (hn.trans_le (neg_add_self 1).symm.le)), apply tendsto.congr (show ∀ x : α, x^-(-n) = x^n, by simp), lift -n to ℕ using le_of_lt (neg_pos.mpr hn) with N, exact tendsto_pow_neg_at_top (by exact_mod_cast this) end lemma tendsto_const_mul_fpow_at_top_zero {n : ℤ} {c : α} (hn : n < 0) : tendsto (λ x, c * x ^ n) at_top (𝓝 0) := (mul_zero c) ▸ (filter.tendsto.const_mul c (tendsto_fpow_at_top_zero hn)) lemma tendsto_const_mul_pow_nhds_iff {n : ℕ} {c d : α} (hc : c ≠ 0) : tendsto (λ x : α, c * x ^ n) at_top (𝓝 d) ↔ n = 0 ∧ c = d := begin refine ⟨λ h, _, λ h, _⟩, { have hn : n = 0, { by_contradiction hn, have hn : 1 ≤ n := nat.succ_le_iff.2 (lt_of_le_of_ne (zero_le _) (ne.symm hn)), by_cases hc' : 0 < c, { have := (tendsto_const_mul_pow_at_top_iff c n).2 ⟨hn, hc'⟩, exact not_tendsto_nhds_of_tendsto_at_top this d h }, { have := (tendsto_neg_const_mul_pow_at_top_iff c n).2 ⟨hn, lt_of_le_of_ne (not_lt.1 hc') hc⟩, exact not_tendsto_nhds_of_tendsto_at_bot this d h } }, have : (λ x : α, c * x ^ n) = (λ x : α, c), by simp [hn], rw [this, tendsto_const_nhds_iff] at h, exact ⟨hn, h⟩ }, { obtain ⟨hn, hcd⟩ := h, simpa [hn, hcd] using tendsto_const_nhds } end lemma tendsto_const_mul_fpow_at_top_zero_iff {n : ℤ} {c d : α} (hc : c ≠ 0) : tendsto (λ x : α, c * x ^ n) at_top (𝓝 d) ↔ (n = 0 ∧ c = d) ∨ (n < 0 ∧ d = 0) := begin refine ⟨λ h, _, λ h, _⟩, { by_cases hn : 0 ≤ n, { lift n to ℕ using hn, simp only [gpow_coe_nat] at h, rw [tendsto_const_mul_pow_nhds_iff hc, ← int.coe_nat_eq_zero] at h, exact or.inl h }, { rw not_le at hn, refine or.inr ⟨hn, tendsto_nhds_unique h (tendsto_const_mul_fpow_at_top_zero hn)⟩ } }, { cases h, { simp only [h.left, h.right, gpow_zero, mul_one], exact tendsto_const_nhds }, { exact h.2.symm ▸ tendsto_const_mul_fpow_at_top_zero h.1} } end end linear_ordered_field lemma preimage_neg [add_group α] : preimage (has_neg.neg : α → α) = image (has_neg.neg : α → α) := (image_eq_preimage_of_inverse neg_neg neg_neg).symm lemma filter.map_neg [add_group α] : map (has_neg.neg : α → α) = comap (has_neg.neg : α → α) := funext $ assume f, map_eq_comap_of_inverse (funext neg_neg) (funext neg_neg) section order_topology variables [topological_space α] [topological_space β] [linear_order α] [linear_order β] [order_topology α] [order_topology β] lemma is_lub.frequently_mem {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) : ∃ᶠ x in 𝓝[Iic a] a, x ∈ s := begin rcases hs with ⟨a', ha'⟩, intro h, rcases (ha.1 ha').eq_or_lt with (rfl|ha'a), { exact h.self_of_nhds_within le_rfl ha' }, { rcases (mem_nhds_within_Iic_iff_exists_Ioc_subset' ha'a).1 h with ⟨b, hba, hb⟩, rcases ha.exists_between hba with ⟨b', hb's, hb'⟩, exact hb hb' hb's }, end lemma is_lub.frequently_nhds_mem {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) : ∃ᶠ x in 𝓝 a, x ∈ s := (ha.frequently_mem hs).filter_mono inf_le_left lemma is_glb.frequently_mem {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) : ∃ᶠ x in 𝓝[Ici a] a, x ∈ s := @is_lub.frequently_mem (order_dual α) _ _ _ _ _ ha hs lemma is_glb.frequently_nhds_mem {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) : ∃ᶠ x in 𝓝 a, x ∈ s := (ha.frequently_mem hs).filter_mono inf_le_left lemma is_lub.mem_closure {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) : a ∈ closure s := (ha.frequently_nhds_mem hs).mem_closure lemma is_glb.mem_closure {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) : a ∈ closure s := (ha.frequently_nhds_mem hs).mem_closure lemma is_lub.nhds_within_ne_bot {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) : ne_bot (𝓝[s] a) := mem_closure_iff_nhds_within_ne_bot.1 (ha.mem_closure hs) lemma is_glb.nhds_within_ne_bot : ∀ {a : α} {s : set α}, is_glb s a → s.nonempty → ne_bot (𝓝[s] a) := @is_lub.nhds_within_ne_bot (order_dual α) _ _ _ lemma is_lub_of_mem_nhds {s : set α} {a : α} {f : filter α} (hsa : a ∈ upper_bounds s) (hsf : s ∈ f) [ne_bot (f ⊓ 𝓝 a)] : is_lub s a := ⟨hsa, assume b hb, not_lt.1 $ assume hba, have s ∩ {a | b < a} ∈ f ⊓ 𝓝 a, from inter_mem_inf_sets hsf (is_open.mem_nhds (is_open_lt' _) hba), let ⟨x, ⟨hxs, hxb⟩⟩ := nonempty_of_mem_sets this in have b < b, from lt_of_lt_of_le hxb $ hb hxs, lt_irrefl b this⟩ lemma is_glb_of_mem_nhds : ∀ {s : set α} {a : α} {f : filter α}, a ∈ lower_bounds s → s ∈ f → ne_bot (f ⊓ 𝓝 a) → is_glb s a := @is_lub_of_mem_nhds (order_dual α) _ _ _ lemma is_lub.mem_upper_bounds_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_lub s a) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ upper_bounds (f '' s) := begin rintro _ ⟨x, hx, rfl⟩, replace ha := ha.inter_Ici_of_mem hx, haveI := ha.nhds_within_ne_bot ⟨x, hx, le_rfl⟩, refine ge_of_tendsto (hb.mono_left (nhds_within_mono _ (inter_subset_left s (Ici x)))) _, exact mem_sets_of_superset self_mem_nhds_within (λ y hy, hf _ hx _ hy.1 hy.2) end -- For a version of this theorem in which the convergence considered on the domain `α` is as -- `x : α` tends to infinity, rather than tending to a point `x` in `α`, see `is_lub_of_tendsto`, -- below lemma is_lub.is_lub_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_lub s a) (hs : s.nonempty) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : is_lub (f '' s) b := begin haveI := ha.nhds_within_ne_bot hs, exact ⟨ha.mem_upper_bounds_of_tendsto hf hb, λ b' hb', le_of_tendsto hb (mem_sets_of_superset self_mem_nhds_within $ λ x hx, hb' $ mem_image_of_mem _ hx)⟩ end lemma is_glb.mem_lower_bounds_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_glb s a) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ lower_bounds (f '' s) := @is_lub.mem_upper_bounds_of_tendsto (order_dual α) (order_dual γ) _ _ _ _ _ _ _ _ _ _ (λ x hx y hy, hf y hy x hx) ha hb -- For a version of this theorem in which the convergence considered on the domain `α` is as -- `x : α` tends to negative infinity, rather than tending to a point `x` in `α`, see -- `is_glb_of_tendsto`, below lemma is_glb.is_glb_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) : is_glb s a → s.nonempty → tendsto f (𝓝[s] a) (𝓝 b) → is_glb (f '' s) b := @is_lub.is_lub_of_tendsto (order_dual α) (order_dual γ) _ _ _ _ _ _ f s a b (λ x hx y hy, hf y hy x hx) lemma is_lub.mem_lower_bounds_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : ∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) (ha : is_lub s a) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ lower_bounds (f '' s) := @is_lub.mem_upper_bounds_of_tendsto α (order_dual γ) _ _ _ _ _ _ _ _ _ _ hf ha hb lemma is_lub.is_glb_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] : ∀ {f : α → γ} {s : set α} {a : α} {b : γ}, (∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) → is_lub s a → s.nonempty → tendsto f (𝓝[s] a) (𝓝 b) → is_glb (f '' s) b := @is_lub.is_lub_of_tendsto α (order_dual γ) _ _ _ _ _ _ lemma is_glb.mem_upper_bounds_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : ∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) (ha : is_glb s a) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ upper_bounds (f '' s) := @is_glb.mem_lower_bounds_of_tendsto α (order_dual γ) _ _ _ _ _ _ _ _ _ _ hf ha hb lemma is_glb.is_lub_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] : ∀ {f : α → γ} {s : set α} {a : α} {b : γ}, (∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) → is_glb s a → s.nonempty → tendsto f (𝓝[s] a) (𝓝 b) → is_lub (f '' s) b := @is_glb.is_glb_of_tendsto α (order_dual γ) _ _ _ _ _ _ lemma is_lub.mem_of_is_closed {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) (sc : is_closed s) : a ∈ s := sc.closure_subset $ ha.mem_closure hs alias is_lub.mem_of_is_closed ← is_closed.is_lub_mem lemma is_glb.mem_of_is_closed {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) (sc : is_closed s) : a ∈ s := sc.closure_subset $ ha.mem_closure hs alias is_glb.mem_of_is_closed ← is_closed.is_glb_mem /-- A compact set is bounded below -/ lemma is_compact.bdd_below {α : Type u} [topological_space α] [linear_order α] [order_closed_topology α] [nonempty α] {s : set α} (hs : is_compact s) : bdd_below s := begin by_contra H, rcases hs.elim_finite_subcover_image (λ x (_ : x ∈ s), @is_open_Ioi _ _ _ _ x) _ with ⟨t, st, ft, ht⟩, { refine H (ft.bdd_below.imp $ λ C hC y hy, _), rcases mem_bUnion_iff.1 (ht hy) with ⟨x, hx, xy⟩, exact le_trans (hC hx) (le_of_lt xy) }, { refine λ x hx, mem_bUnion_iff.2 (not_imp_comm.1 _ H), exact λ h, ⟨x, λ y hy, le_of_not_lt (h.imp $ λ ys, ⟨_, hy, ys⟩)⟩ } end /-- A compact set is bounded above -/ lemma is_compact.bdd_above {α : Type u} [topological_space α] [linear_order α] [order_topology α] : Π [nonempty α] {s : set α}, is_compact s → bdd_above s := @is_compact.bdd_below (order_dual α) _ _ _ end order_topology section linear_order variables [topological_space α] [linear_order α] [order_topology α] [densely_ordered α] /-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`, unless `a` is a top element. -/ lemma closure_Ioi' {a b : α} (hab : a < b) : closure (Ioi a) = Ici a := begin apply subset.antisymm, { exact closure_minimal Ioi_subset_Ici_self is_closed_Ici }, { rw [← diff_subset_closure_iff, Ici_diff_Ioi_same, singleton_subset_iff], exact is_glb_Ioi.mem_closure ⟨_, hab⟩ } end /-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`. -/ @[simp] lemma closure_Ioi (a : α) [no_top_order α] : closure (Ioi a) = Ici a := let ⟨b, hb⟩ := no_top a in closure_Ioi' hb /-- The closure of the interval `(-∞, a)` is the closed interval `(-∞, a]`, unless `a` is a bottom element. -/ lemma closure_Iio' {a b : α} (hab : b < a) : closure (Iio a) = Iic a := @closure_Ioi' (order_dual α) _ _ _ _ _ _ hab /-- The closure of the interval `(-∞, a)` is the interval `(-∞, a]`. -/ @[simp] lemma closure_Iio (a : α) [no_bot_order α] : closure (Iio a) = Iic a := let ⟨b, hb⟩ := no_bot a in closure_Iio' hb /-- The closure of the open interval `(a, b)` is the closed interval `[a, b]`. -/ @[simp] lemma closure_Ioo {a b : α} (hab : a < b) : closure (Ioo a b) = Icc a b := begin apply subset.antisymm, { exact closure_minimal Ioo_subset_Icc_self is_closed_Icc }, { rw [← diff_subset_closure_iff, Icc_diff_Ioo_same hab.le], have hab' : (Ioo a b).nonempty, from nonempty_Ioo.2 hab, simp only [insert_subset, singleton_subset_iff], exact ⟨(is_glb_Ioo hab).mem_closure hab', (is_lub_Ioo hab).mem_closure hab'⟩ } end /-- The closure of the interval `(a, b]` is the closed interval `[a, b]`. -/ @[simp] lemma closure_Ioc {a b : α} (hab : a < b) : closure (Ioc a b) = Icc a b := begin apply subset.antisymm, { exact closure_minimal Ioc_subset_Icc_self is_closed_Icc }, { apply subset.trans _ (closure_mono Ioo_subset_Ioc_self), rw closure_Ioo hab } end /-- The closure of the interval `[a, b)` is the closed interval `[a, b]`. -/ @[simp] lemma closure_Ico {a b : α} (hab : a < b) : closure (Ico a b) = Icc a b := begin apply subset.antisymm, { exact closure_minimal Ico_subset_Icc_self is_closed_Icc }, { apply subset.trans _ (closure_mono Ioo_subset_Ico_self), rw closure_Ioo hab } end @[simp] lemma interior_Ici [no_bot_order α] {a : α} : interior (Ici a) = Ioi a := by rw [← compl_Iio, interior_compl, closure_Iio, compl_Iic] @[simp] lemma interior_Iic [no_top_order α] {a : α} : interior (Iic a) = Iio a := by rw [← compl_Ioi, interior_compl, closure_Ioi, compl_Ici] @[simp] lemma interior_Icc [no_bot_order α] [no_top_order α] {a b : α}: interior (Icc a b) = Ioo a b := by rw [← Ici_inter_Iic, interior_inter, interior_Ici, interior_Iic, Ioi_inter_Iio] @[simp] lemma interior_Ico [no_bot_order α] {a b : α} : interior (Ico a b) = Ioo a b := by rw [← Ici_inter_Iio, interior_inter, interior_Ici, interior_Iio, Ioi_inter_Iio] @[simp] lemma interior_Ioc [no_top_order α] {a b : α} : interior (Ioc a b) = Ioo a b := by rw [← Ioi_inter_Iic, interior_inter, interior_Ioi, interior_Iic, Ioi_inter_Iio] @[simp] lemma frontier_Ici [no_bot_order α] {a : α} : frontier (Ici a) = {a} := by simp [frontier] @[simp] lemma frontier_Iic [no_top_order α] {a : α} : frontier (Iic a) = {a} := by simp [frontier] @[simp] lemma frontier_Ioi [no_top_order α] {a : α} : frontier (Ioi a) = {a} := by simp [frontier] @[simp] lemma frontier_Iio [no_bot_order α] {a : α} : frontier (Iio a) = {a} := by simp [frontier] @[simp] lemma frontier_Icc [no_bot_order α] [no_top_order α] {a b : α} (h : a < b) : frontier (Icc a b) = {a, b} := by simp [frontier, le_of_lt h, Icc_diff_Ioo_same] @[simp] lemma frontier_Ioo {a b : α} (h : a < b) : frontier (Ioo a b) = {a, b} := by simp [frontier, h, le_of_lt h, Icc_diff_Ioo_same] @[simp] lemma frontier_Ico [no_bot_order α] {a b : α} (h : a < b) : frontier (Ico a b) = {a, b} := by simp [frontier, h, le_of_lt h, Icc_diff_Ioo_same] @[simp] lemma frontier_Ioc [no_top_order α] {a b : α} (h : a < b) : frontier (Ioc a b) = {a, b} := by simp [frontier, h, le_of_lt h, Icc_diff_Ioo_same] lemma nhds_within_Ioi_ne_bot' {a b c : α} (H₁ : a < c) (H₂ : a ≤ b) : ne_bot (𝓝[Ioi a] b) := mem_closure_iff_nhds_within_ne_bot.1 $ by { rw [closure_Ioi' H₁], exact H₂ } lemma nhds_within_Ioi_ne_bot [no_top_order α] {a b : α} (H : a ≤ b) : ne_bot (𝓝[Ioi a] b) := let ⟨c, hc⟩ := no_top a in nhds_within_Ioi_ne_bot' hc H lemma nhds_within_Ioi_self_ne_bot' {a b : α} (H : a < b) : ne_bot (𝓝[Ioi a] a) := nhds_within_Ioi_ne_bot' H (le_refl a) @[instance] lemma nhds_within_Ioi_self_ne_bot [no_top_order α] (a : α) : ne_bot (𝓝[Ioi a] a) := nhds_within_Ioi_ne_bot (le_refl a) lemma nhds_within_Iio_ne_bot' {a b c : α} (H₁ : a < c) (H₂ : b ≤ c) : ne_bot (𝓝[Iio c] b) := mem_closure_iff_nhds_within_ne_bot.1 $ by { rw [closure_Iio' H₁], exact H₂ } lemma nhds_within_Iio_ne_bot [no_bot_order α] {a b : α} (H : a ≤ b) : ne_bot (𝓝[Iio b] a) := let ⟨c, hc⟩ := no_bot b in nhds_within_Iio_ne_bot' hc H lemma nhds_within_Iio_self_ne_bot' {a b : α} (H : a < b) : ne_bot (𝓝[Iio b] b) := nhds_within_Iio_ne_bot' H (le_refl b) @[instance] lemma nhds_within_Iio_self_ne_bot [no_bot_order α] (a : α) : ne_bot (𝓝[Iio a] a) := nhds_within_Iio_ne_bot (le_refl a) lemma right_nhds_within_Ico_ne_bot {a b : α} (H : a < b) : ne_bot (𝓝[Ico a b] b) := (is_lub_Ico H).nhds_within_ne_bot (nonempty_Ico.2 H) lemma left_nhds_within_Ioc_ne_bot {a b : α} (H : a < b) : ne_bot (𝓝[Ioc a b] a) := (is_glb_Ioc H).nhds_within_ne_bot (nonempty_Ioc.2 H) lemma left_nhds_within_Ioo_ne_bot {a b : α} (H : a < b) : ne_bot (𝓝[Ioo a b] a) := (is_glb_Ioo H).nhds_within_ne_bot (nonempty_Ioo.2 H) lemma right_nhds_within_Ioo_ne_bot {a b : α} (H : a < b) : ne_bot (𝓝[Ioo a b] b) := (is_lub_Ioo H).nhds_within_ne_bot (nonempty_Ioo.2 H) end linear_order section linear_order variables [topological_space α] [linear_order α] [order_topology α] [densely_ordered α] {a b : α} {s : set α} lemma comap_coe_nhds_within_Iio_of_Ioo_subset (hb : s ⊆ Iio b) (hs : s.nonempty → ∃ a < b, Ioo a b ⊆ s) : comap (coe : s → α) (𝓝[Iio b] b) = at_top := begin nontriviality, haveI : nonempty s := nontrivial_iff_nonempty.1 ‹_›, rcases hs (nonempty_subtype.1 ‹_›) with ⟨a, h, hs⟩, ext u, split, { rintros ⟨t, ht, hts⟩, obtain ⟨x, ⟨hxa : a ≤ x, hxb : x < b⟩, hxt : Ioo x b ⊆ t⟩ := (mem_nhds_within_Iio_iff_exists_mem_Ico_Ioo_subset h).mp ht, obtain ⟨y, hxy, hyb⟩ := exists_between hxb, refine mem_sets_of_superset (mem_at_top ⟨y, hs ⟨hxa.trans_lt hxy, hyb⟩⟩) _, rintros ⟨z, hzs⟩ (hyz : y ≤ z), refine hts (hxt ⟨hxy.trans_le _, hb _⟩); assumption }, { intros hu, obtain ⟨x : s, hx : ∀ z, x ≤ z → z ∈ u⟩ := mem_at_top_sets.1 hu, exact ⟨Ioo x b, Ioo_mem_nhds_within_Iio (right_mem_Ioc.2 $ hb x.2), λ z hz, hx _ hz.1.le⟩ } end lemma comap_coe_nhds_within_Ioi_of_Ioo_subset (ha : s ⊆ Ioi a) (hs : s.nonempty → ∃ b > a, Ioo a b ⊆ s) : comap (coe : s → α) (𝓝[Ioi a] a) = at_bot := begin refine @comap_coe_nhds_within_Iio_of_Ioo_subset (order_dual α) _ _ _ _ _ _ ha (λ h, _), rcases hs h with ⟨b, hab, h⟩, use [b, hab], rwa dual_Ioo end lemma map_coe_at_top_of_Ioo_subset (hb : s ⊆ Iio b) (hs : ∀ a' < b, ∃ a < b, Ioo a b ⊆ s) : map (coe : s → α) at_top = 𝓝[Iio b] b := begin rcases eq_empty_or_nonempty (Iio b) with (hb'|⟨a, ha⟩), { rw [filter_eq_bot_of_not_nonempty at_top, map_bot, hb', nhds_within_empty], exact λ ⟨⟨x, hx⟩⟩, not_nonempty_iff_eq_empty.2 hb' ⟨x, hb hx⟩ }, { rw [← comap_coe_nhds_within_Iio_of_Ioo_subset hb (λ _, hs a ha), map_comap_of_mem], rw subtype.range_coe, exact (mem_nhds_within_Iio_iff_exists_Ioo_subset' ha).2 (hs a ha) }, end lemma map_coe_at_bot_of_Ioo_subset (ha : s ⊆ Ioi a) (hs : ∀ b' > a, ∃ b > a, Ioo a b ⊆ s) : map (coe : s → α) at_bot = (𝓝[Ioi a] a) := begin refine @map_coe_at_top_of_Ioo_subset (order_dual α) _ _ _ _ a s ha (λ b' hb', _), rcases hs b' hb' with ⟨b, hab, hbs⟩, use [b, hab], rwa dual_Ioo end /-- The `at_top` filter for an open interval `Ioo a b` comes from the left-neighbourhoods filter at the right endpoint in the ambient order. -/ lemma comap_coe_Ioo_nhds_within_Iio (a b : α) : comap (coe : Ioo a b → α) (𝓝[Iio b] b) = at_top := comap_coe_nhds_within_Iio_of_Ioo_subset Ioo_subset_Iio_self $ λ h, ⟨a, nonempty_Ioo.1 h, subset.refl _⟩ /-- The `at_bot` filter for an open interval `Ioo a b` comes from the right-neighbourhoods filter at the left endpoint in the ambient order. -/ lemma comap_coe_Ioo_nhds_within_Ioi (a b : α) : comap (coe : Ioo a b → α) (𝓝[Ioi a] a) = at_bot := comap_coe_nhds_within_Ioi_of_Ioo_subset Ioo_subset_Ioi_self $ λ h, ⟨b, nonempty_Ioo.1 h, subset.refl _⟩ lemma comap_coe_Ioi_nhds_within_Ioi (a : α) : comap (coe : Ioi a → α) (𝓝[Ioi a] a) = at_bot := comap_coe_nhds_within_Ioi_of_Ioo_subset (subset.refl _) $ λ ⟨x, hx⟩, ⟨x, hx, Ioo_subset_Ioi_self⟩ lemma comap_coe_Iio_nhds_within_Iio (a : α) : comap (coe : Iio a → α) (𝓝[Iio a] a) = at_top := @comap_coe_Ioi_nhds_within_Ioi (order_dual α) _ _ _ _ a @[simp] lemma map_coe_Ioo_at_top {a b : α} (h : a < b) : map (coe : Ioo a b → α) at_top = 𝓝[Iio b] b := map_coe_at_top_of_Ioo_subset Ioo_subset_Iio_self $ λ _ _, ⟨_, h, subset.refl _⟩ @[simp] lemma map_coe_Ioo_at_bot {a b : α} (h : a < b) : map (coe : Ioo a b → α) at_bot = 𝓝[Ioi a] a := map_coe_at_bot_of_Ioo_subset Ioo_subset_Ioi_self $ λ _ _, ⟨_, h, subset.refl _⟩ @[simp] lemma map_coe_Ioi_at_bot (a : α) : map (coe : Ioi a → α) at_bot = 𝓝[Ioi a] a := map_coe_at_bot_of_Ioo_subset (subset.refl _) $ λ b hb, ⟨b, hb, Ioo_subset_Ioi_self⟩ @[simp] lemma map_coe_Iio_at_top (a : α) : map (coe : Iio a → α) at_top = 𝓝[Iio a] a := @map_coe_Ioi_at_bot (order_dual α) _ _ _ _ _ variables {l : filter β} {f : α → β} @[simp] lemma tendsto_comp_coe_Ioo_at_top (h : a < b) : tendsto (λ x : Ioo a b, f x) at_top l ↔ tendsto f (𝓝[Iio b] b) l := by rw [← map_coe_Ioo_at_top h, tendsto_map'_iff] @[simp] lemma tendsto_comp_coe_Ioo_at_bot (h : a < b) : tendsto (λ x : Ioo a b, f x) at_bot l ↔ tendsto f (𝓝[Ioi a] a) l := by rw [← map_coe_Ioo_at_bot h, tendsto_map'_iff] @[simp] lemma tendsto_comp_coe_Ioi_at_bot : tendsto (λ x : Ioi a, f x) at_bot l ↔ tendsto f (𝓝[Ioi a] a) l := by rw [← map_coe_Ioi_at_bot, tendsto_map'_iff] @[simp] lemma tendsto_comp_coe_Iio_at_top : tendsto (λ x : Iio a, f x) at_top l ↔ tendsto f (𝓝[Iio a] a) l := by rw [← map_coe_Iio_at_top, tendsto_map'_iff] @[simp] lemma tendsto_Ioo_at_top {f : β → Ioo a b} : tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l (𝓝[Iio b] b) := by rw [← comap_coe_Ioo_nhds_within_Iio, tendsto_comap_iff] @[simp] lemma tendsto_Ioo_at_bot {f : β → Ioo a b} : tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l (𝓝[Ioi a] a) := by rw [← comap_coe_Ioo_nhds_within_Ioi, tendsto_comap_iff] @[simp] lemma tendsto_Ioi_at_bot {f : β → Ioi a} : tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l (𝓝[Ioi a] a) := by rw [← comap_coe_Ioi_nhds_within_Ioi, tendsto_comap_iff] @[simp] lemma tendsto_Iio_at_top {f : β → Iio a} : tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l (𝓝[Iio a] a) := by rw [← comap_coe_Iio_nhds_within_Iio, tendsto_comap_iff] end linear_order section complete_linear_order variables [complete_linear_order α] [topological_space α] [order_topology α] [complete_linear_order β] [topological_space β] [order_topology β] [nonempty γ] lemma Sup_mem_closure {α : Type u} [topological_space α] [complete_linear_order α] [order_topology α] {s : set α} (hs : s.nonempty) : Sup s ∈ closure s := (is_lub_Sup s).mem_closure hs lemma Inf_mem_closure {α : Type u} [topological_space α] [complete_linear_order α] [order_topology α] {s : set α} (hs : s.nonempty) : Inf s ∈ closure s := (is_glb_Inf s).mem_closure hs lemma is_closed.Sup_mem {α : Type u} [topological_space α] [complete_linear_order α] [order_topology α] {s : set α} (hs : s.nonempty) (hc : is_closed s) : Sup s ∈ s := (is_lub_Sup s).mem_of_is_closed hs hc lemma is_closed.Inf_mem {α : Type u} [topological_space α] [complete_linear_order α] [order_topology α] {s : set α} (hs : s.nonempty) (hc : is_closed s) : Inf s ∈ s := (is_glb_Inf s).mem_of_is_closed hs hc /-- A monotone function continuous at the supremum of a nonempty set sends this supremum to the supremum of the image of this set. -/ lemma map_Sup_of_continuous_at_of_monotone' {f : α → β} {s : set α} (Cf : continuous_at f (Sup s)) (Mf : monotone f) (hs : s.nonempty) : f (Sup s) = Sup (f '' s) := --This is a particular case of the more general is_lub.is_lub_of_tendsto ((is_lub_Sup _).is_lub_of_tendsto (λ x hx y hy xy, Mf xy) hs $ Cf.mono_left inf_le_left).Sup_eq.symm /-- A monotone function `s` sending `bot` to `bot` and continuous at the supremum of a set sends this supremum to the supremum of the image of this set. -/ lemma map_Sup_of_continuous_at_of_monotone {f : α → β} {s : set α} (Cf : continuous_at f (Sup s)) (Mf : monotone f) (fbot : f ⊥ = ⊥) : f (Sup s) = Sup (f '' s) := begin cases s.eq_empty_or_nonempty with h h, { simp [h, fbot] }, { exact map_Sup_of_continuous_at_of_monotone' Cf Mf h } end /-- A monotone function continuous at the indexed supremum over a nonempty `Sort` sends this indexed supremum to the indexed supremum of the composition. -/ lemma map_supr_of_continuous_at_of_monotone' {ι : Sort*} [nonempty ι] {f : α → β} {g : ι → α} (Cf : continuous_at f (supr g)) (Mf : monotone f) : f (⨆ i, g i) = ⨆ i, f (g i) := by rw [supr, map_Sup_of_continuous_at_of_monotone' Cf Mf (range_nonempty g), ← range_comp, supr] /-- If a monotone function sending `bot` to `bot` is continuous at the indexed supremum over a `Sort`, then it sends this indexed supremum to the indexed supremum of the composition. -/ lemma map_supr_of_continuous_at_of_monotone {ι : Sort*} {f : α → β} {g : ι → α} (Cf : continuous_at f (supr g)) (Mf : monotone f) (fbot : f ⊥ = ⊥) : f (⨆ i, g i) = ⨆ i, f (g i) := by rw [supr, map_Sup_of_continuous_at_of_monotone Cf Mf fbot, ← range_comp, supr] /-- A monotone function continuous at the infimum of a nonempty set sends this infimum to the infimum of the image of this set. -/ lemma map_Inf_of_continuous_at_of_monotone' {f : α → β} {s : set α} (Cf : continuous_at f (Inf s)) (Mf : monotone f) (hs : s.nonempty) : f (Inf s) = Inf (f '' s) := @map_Sup_of_continuous_at_of_monotone' (order_dual α) (order_dual β) _ _ _ _ _ _ f s Cf Mf.order_dual hs /-- A monotone function `s` sending `top` to `top` and continuous at the infimum of a set sends this infimum to the infimum of the image of this set. -/ lemma map_Inf_of_continuous_at_of_monotone {f : α → β} {s : set α} (Cf : continuous_at f (Inf s)) (Mf : monotone f) (ftop : f ⊤ = ⊤) : f (Inf s) = Inf (f '' s) := @map_Sup_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ f s Cf Mf.order_dual ftop /-- A monotone function continuous at the indexed infimum over a nonempty `Sort` sends this indexed infimum to the indexed infimum of the composition. -/ lemma map_infi_of_continuous_at_of_monotone' {ι : Sort*} [nonempty ι] {f : α → β} {g : ι → α} (Cf : continuous_at f (infi g)) (Mf : monotone f) : f (⨅ i, g i) = ⨅ i, f (g i) := @map_supr_of_continuous_at_of_monotone' (order_dual α) (order_dual β) _ _ _ _ _ _ ι _ f g Cf Mf.order_dual /-- If a monotone function sending `top` to `top` is continuous at the indexed infimum over a `Sort`, then it sends this indexed infimum to the indexed infimum of the composition. -/ lemma map_infi_of_continuous_at_of_monotone {ι : Sort*} {f : α → β} {g : ι → α} (Cf : continuous_at f (infi g)) (Mf : monotone f) (ftop : f ⊤ = ⊤) : f (infi g) = infi (f ∘ g) := @map_supr_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ ι f g Cf Mf.order_dual ftop end complete_linear_order section conditionally_complete_linear_order variables [conditionally_complete_linear_order α] [topological_space α] [order_topology α] [conditionally_complete_linear_order β] [topological_space β] [order_topology β] [nonempty γ] lemma cSup_mem_closure {s : set α} (hs : s.nonempty) (B : bdd_above s) : Sup s ∈ closure s := (is_lub_cSup hs B).mem_closure hs lemma cInf_mem_closure {s : set α} (hs : s.nonempty) (B : bdd_below s) : Inf s ∈ closure s := (is_glb_cInf hs B).mem_closure hs lemma is_closed.cSup_mem {s : set α} (hc : is_closed s) (hs : s.nonempty) (B : bdd_above s) : Sup s ∈ s := (is_lub_cSup hs B).mem_of_is_closed hs hc lemma is_closed.cInf_mem {s : set α} (hc : is_closed s) (hs : s.nonempty) (B : bdd_below s) : Inf s ∈ s := (is_glb_cInf hs B).mem_of_is_closed hs hc /-- If a monotone function is continuous at the supremum of a nonempty bounded above set `s`, then it sends this supremum to the supremum of the image of `s`. -/ lemma map_cSup_of_continuous_at_of_monotone {f : α → β} {s : set α} (Cf : continuous_at f (Sup s)) (Mf : monotone f) (ne : s.nonempty) (H : bdd_above s) : f (Sup s) = Sup (f '' s) := begin refine ((is_lub_cSup (ne.image f) (Mf.map_bdd_above H)).unique _).symm, refine (is_lub_cSup ne H).is_lub_of_tendsto (λx hx y hy xy, Mf xy) ne _, exact Cf.mono_left inf_le_left end /-- If a monotone function is continuous at the indexed supremum of a bounded function on a nonempty `Sort`, then it sends this supremum to the supremum of the composition. -/ lemma map_csupr_of_continuous_at_of_monotone {f : α → β} {g : γ → α} (Cf : continuous_at f (⨆ i, g i)) (Mf : monotone f) (H : bdd_above (range g)) : f (⨆ i, g i) = ⨆ i, f (g i) := by rw [supr, map_cSup_of_continuous_at_of_monotone Cf Mf (range_nonempty _) H, ← range_comp, supr] /-- If a monotone function is continuous at the infimum of a nonempty bounded below set `s`, then it sends this infimum to the infimum of the image of `s`. -/ lemma map_cInf_of_continuous_at_of_monotone {f : α → β} {s : set α} (Cf : continuous_at f (Inf s)) (Mf : monotone f) (ne : s.nonempty) (H : bdd_below s) : f (Inf s) = Inf (f '' s) := @map_cSup_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ f s Cf Mf.order_dual ne H /-- A continuous monotone function sends indexed infimum to indexed infimum in conditionally complete linear order, under a boundedness assumption. -/ lemma map_cinfi_of_continuous_at_of_monotone {f : α → β} {g : γ → α} (Cf : continuous_at f (⨅ i, g i)) (Mf : monotone f) (H : bdd_below (range g)) : f (⨅ i, g i) = ⨅ i, f (g i) := @map_csupr_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ _ _ _ _ Cf Mf.order_dual H /-- A bounded connected subset of a conditionally complete linear order includes the open interval `(Inf s, Sup s)`. -/ lemma is_connected.Ioo_cInf_cSup_subset {s : set α} (hs : is_connected s) (hb : bdd_below s) (ha : bdd_above s) : Ioo (Inf s) (Sup s) ⊆ s := λ x hx, let ⟨y, ys, hy⟩ := (is_glb_lt_iff (is_glb_cInf hs.nonempty hb)).1 hx.1 in let ⟨z, zs, hz⟩ := (lt_is_lub_iff (is_lub_cSup hs.nonempty ha)).1 hx.2 in hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩ lemma eq_Icc_cInf_cSup_of_connected_bdd_closed {s : set α} (hc : is_connected s) (hb : bdd_below s) (ha : bdd_above s) (hcl : is_closed s) : s = Icc (Inf s) (Sup s) := subset.antisymm (subset_Icc_cInf_cSup hb ha) $ hc.Icc_subset (hcl.cInf_mem hc.nonempty hb) (hcl.cSup_mem hc.nonempty ha) lemma is_preconnected.Ioi_cInf_subset {s : set α} (hs : is_preconnected s) (hb : bdd_below s) (ha : ¬bdd_above s) : Ioi (Inf s) ⊆ s := begin have sne : s.nonempty := @nonempty_of_not_bdd_above α _ s ⟨Inf ∅⟩ ha, intros x hx, obtain ⟨y, ys, hy⟩ : ∃ y ∈ s, y < x := (is_glb_lt_iff (is_glb_cInf sne hb)).1 hx, obtain ⟨z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bdd_above_iff.1 ha x, exact hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩ end lemma is_preconnected.Iio_cSup_subset {s : set α} (hs : is_preconnected s) (hb : ¬bdd_below s) (ha : bdd_above s) : Iio (Sup s) ⊆ s := @is_preconnected.Ioi_cInf_subset (order_dual α) _ _ _ s hs ha hb /-- A preconnected set in a conditionally complete linear order is either one of the intervals `[Inf s, Sup s]`, `[Inf s, Sup s)`, `(Inf s, Sup s]`, `(Inf s, Sup s)`, `[Inf s, +∞)`, `(Inf s, +∞)`, `(-∞, Sup s]`, `(-∞, Sup s)`, `(-∞, +∞)`, or `∅`. The converse statement requires `α` to be densely ordererd. -/ lemma is_preconnected.mem_intervals {s : set α} (hs : is_preconnected s) : s ∈ ({Icc (Inf s) (Sup s), Ico (Inf s) (Sup s), Ioc (Inf s) (Sup s), Ioo (Inf s) (Sup s), Ici (Inf s), Ioi (Inf s), Iic (Sup s), Iio (Sup s), univ, ∅} : set (set α)) := begin rcases s.eq_empty_or_nonempty with rfl|hne, { apply_rules [or.inr, mem_singleton] }, have hs' : is_connected s := ⟨hne, hs⟩, by_cases hb : bdd_below s; by_cases ha : bdd_above s, { rcases mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset (hs'.Ioo_cInf_cSup_subset hb ha) (subset_Icc_cInf_cSup hb ha) with hs|hs|hs|hs, { exact (or.inl hs) }, { exact (or.inr $ or.inl hs) }, { exact (or.inr $ or.inr $ or.inl hs) }, { exact (or.inr $ or.inr $ or.inr $ or.inl hs) } }, { refine (or.inr $ or.inr $ or.inr $ or.inr _), cases mem_Ici_Ioi_of_subset_of_subset (hs.Ioi_cInf_subset hb ha) (λ x hx, cInf_le hb hx) with hs hs, { exact or.inl hs }, { exact or.inr (or.inl hs) } }, { iterate 6 { apply or.inr }, cases mem_Iic_Iio_of_subset_of_subset (hs.Iio_cSup_subset hb ha) (λ x hx, le_cSup ha hx) with hs hs, { exact or.inl hs }, { exact or.inr (or.inl hs) } }, { iterate 8 { apply or.inr }, exact or.inl (hs.eq_univ_of_unbounded hb ha) } end /-- A preconnected set is either one of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`, `Iic`, `Iio`, or `univ`, or `∅`. The converse statement requires `α` to be densely ordererd. Though one can represent `∅` as `(Inf s, Inf s)`, we include it into the list of possible cases to improve readability. -/ lemma set_of_is_preconnected_subset_of_ordered : {s : set α | is_preconnected s} ⊆ -- bounded intervals (range (uncurry Icc) ∪ range (uncurry Ico) ∪ range (uncurry Ioc) ∪ range (uncurry Ioo)) ∪ -- unbounded intervals and `univ` (range Ici ∪ range Ioi ∪ range Iic ∪ range Iio ∪ {univ, ∅}) := begin intros s hs, rcases hs.mem_intervals with hs|hs|hs|hs|hs|hs|hs|hs|hs|hs, { exact (or.inl $ or.inl $ or.inl $ or.inl ⟨(Inf s, Sup s), hs.symm⟩) }, { exact (or.inl $ or.inl $ or.inl $ or.inr ⟨(Inf s, Sup s), hs.symm⟩) }, { exact (or.inl $ or.inl $ or.inr ⟨(Inf s, Sup s), hs.symm⟩) }, { exact (or.inl $ or.inr ⟨(Inf s, Sup s), hs.symm⟩) }, { exact (or.inr $ or.inl $ or.inl $ or.inl $ or.inl ⟨Inf s, hs.symm⟩) }, { exact (or.inr $ or.inl $ or.inl $ or.inl $ or.inr ⟨Inf s, hs.symm⟩) }, { exact (or.inr $ or.inl $ or.inl $ or.inr ⟨Sup s, hs.symm⟩) }, { exact (or.inr $ or.inl $ or.inr ⟨Sup s, hs.symm⟩) }, { exact (or.inr $ or.inr $ or.inl hs) }, { exact (or.inr $ or.inr $ or.inr hs) } end /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and the set `s ∩ [a, b)` has no maximal point, then `b ∈ s`. -/ lemma is_closed.mem_of_ge_of_forall_exists_gt {a b : α} {s : set α} (hs : is_closed (s ∩ Icc a b)) (ha : a ∈ s) (hab : a ≤ b) (hgt : ∀ x ∈ s ∩ Ico a b, (s ∩ Ioc x b).nonempty) : b ∈ s := begin let S := s ∩ Icc a b, replace ha : a ∈ S, from ⟨ha, left_mem_Icc.2 hab⟩, have Sbd : bdd_above S, from ⟨b, λ z hz, hz.2.2⟩, let c := Sup (s ∩ Icc a b), have c_mem : c ∈ S, from hs.cSup_mem ⟨_, ha⟩ Sbd, have c_le : c ≤ b, from cSup_le ⟨_, ha⟩ (λ x hx, hx.2.2), cases eq_or_lt_of_le c_le with hc hc, from hc ▸ c_mem.1, exfalso, rcases hgt c ⟨c_mem.1, c_mem.2.1, hc⟩ with ⟨x, xs, cx, xb⟩, exact not_lt_of_le (le_cSup Sbd ⟨xs, le_trans (le_cSup Sbd ha) (le_of_lt cx), xb⟩) cx end /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and for any `a ≤ x < y ≤ b`, `x ∈ s`, the set `s ∩ (x, y]` is not empty, then `[a, b] ⊆ s`. -/ lemma is_closed.Icc_subset_of_forall_exists_gt {a b : α} {s : set α} (hs : is_closed (s ∩ Icc a b)) (ha : a ∈ s) (hgt : ∀ x ∈ s ∩ Ico a b, ∀ y ∈ Ioi x, (s ∩ Ioc x y).nonempty) : Icc a b ⊆ s := begin assume y hy, have : is_closed (s ∩ Icc a y), { suffices : s ∩ Icc a y = s ∩ Icc a b ∩ Icc a y, { rw this, exact is_closed.inter hs is_closed_Icc }, rw [inter_assoc], congr, exact (inter_eq_self_of_subset_right $ Icc_subset_Icc_right hy.2).symm }, exact is_closed.mem_of_ge_of_forall_exists_gt this ha hy.1 (λ x hx, hgt x ⟨hx.1, Ico_subset_Ico_right hy.2 hx.2⟩ y hx.2.2) end section densely_ordered variables [densely_ordered α] {a b : α} /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and for any `x ∈ s ∩ [a, b)` the set `s` includes some open neighborhood of `x` within `(x, +∞)`, then `[a, b] ⊆ s`. -/ lemma is_closed.Icc_subset_of_forall_mem_nhds_within {a b : α} {s : set α} (hs : is_closed (s ∩ Icc a b)) (ha : a ∈ s) (hgt : ∀ x ∈ s ∩ Ico a b, s ∈ 𝓝[Ioi x] x) : Icc a b ⊆ s := begin apply hs.Icc_subset_of_forall_exists_gt ha, rintros x ⟨hxs, hxab⟩ y hyxb, have : s ∩ Ioc x y ∈ 𝓝[Ioi x] x, from inter_mem_sets (hgt x ⟨hxs, hxab⟩) (Ioc_mem_nhds_within_Ioi ⟨le_refl _, hyxb⟩), exact (nhds_within_Ioi_self_ne_bot' hxab.2).nonempty_of_mem this end /-- A closed interval in a densely ordered conditionally complete linear order is preconnected. -/ lemma is_preconnected_Icc : is_preconnected (Icc a b) := is_preconnected_closed_iff.2 begin rintros s t hs ht hab ⟨x, hx⟩ ⟨y, hy⟩, wlog hxy : x ≤ y := le_total x y using [x y s t, y x t s], have xyab : Icc x y ⊆ Icc a b := Icc_subset_Icc hx.1.1 hy.1.2, by_contradiction hst, suffices : Icc x y ⊆ s, from hst ⟨y, xyab $ right_mem_Icc.2 hxy, this $ right_mem_Icc.2 hxy, hy.2⟩, apply (is_closed.inter hs is_closed_Icc).Icc_subset_of_forall_mem_nhds_within hx.2, rintros z ⟨zs, hz⟩, have zt : z ∈ tᶜ, from λ zt, hst ⟨z, xyab $ Ico_subset_Icc_self hz, zs, zt⟩, have : tᶜ ∩ Ioc z y ∈ 𝓝[Ioi z] z, { rw [← nhds_within_Ioc_eq_nhds_within_Ioi hz.2], exact mem_nhds_within.2 ⟨tᶜ, ht.is_open_compl, zt, subset.refl _⟩}, apply mem_sets_of_superset this, have : Ioc z y ⊆ s ∪ t, from λ w hw, hab (xyab ⟨le_trans hz.1 (le_of_lt hw.1), hw.2⟩), exact λ w ⟨wt, wzy⟩, (this wzy).elim id (λ h, (wt h).elim) end lemma is_preconnected_interval : is_preconnected (interval a b) := is_preconnected_Icc lemma set.ord_connected.is_preconnected {s : set α} (h : s.ord_connected) : is_preconnected s := is_preconnected_of_forall_pair $ λ x y hx hy, ⟨interval x y, h.interval_subset hx hy, left_mem_interval, right_mem_interval, is_preconnected_interval⟩ lemma is_preconnected_iff_ord_connected {s : set α} : is_preconnected s ↔ ord_connected s := ⟨is_preconnected.ord_connected, set.ord_connected.is_preconnected⟩ lemma is_preconnected_Ici : is_preconnected (Ici a) := ord_connected_Ici.is_preconnected lemma is_preconnected_Iic : is_preconnected (Iic a) := ord_connected_Iic.is_preconnected lemma is_preconnected_Iio : is_preconnected (Iio a) := ord_connected_Iio.is_preconnected lemma is_preconnected_Ioi : is_preconnected (Ioi a) := ord_connected_Ioi.is_preconnected lemma is_preconnected_Ioo : is_preconnected (Ioo a b) := ord_connected_Ioo.is_preconnected lemma is_preconnected_Ioc : is_preconnected (Ioc a b) := ord_connected_Ioc.is_preconnected lemma is_preconnected_Ico : is_preconnected (Ico a b) := ord_connected_Ico.is_preconnected @[priority 100] instance ordered_connected_space : preconnected_space α := ⟨ord_connected_univ.is_preconnected⟩ /-- In a dense conditionally complete linear order, the set of preconnected sets is exactly the set of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`, `Iic`, `Iio`, `(-∞, +∞)`, or `∅`. Though one can represent `∅` as `(Inf s, Inf s)`, we include it into the list of possible cases to improve readability. -/ lemma set_of_is_preconnected_eq_of_ordered : {s : set α | is_preconnected s} = -- bounded intervals (range (uncurry Icc) ∪ range (uncurry Ico) ∪ range (uncurry Ioc) ∪ range (uncurry Ioo)) ∪ -- unbounded intervals and `univ` (range Ici ∪ range Ioi ∪ range Iic ∪ range Iio ∪ {univ, ∅}) := begin refine subset.antisymm set_of_is_preconnected_subset_of_ordered _, simp only [subset_def, -mem_range, forall_range_iff, uncurry, or_imp_distrib, forall_and_distrib, mem_union, mem_set_of_eq, insert_eq, mem_singleton_iff, forall_eq, forall_true_iff, and_true, is_preconnected_Icc, is_preconnected_Ico, is_preconnected_Ioc, is_preconnected_Ioo, is_preconnected_Ioi, is_preconnected_Iio, is_preconnected_Ici, is_preconnected_Iic, is_preconnected_univ, is_preconnected_empty], end variables {δ : Type*} [linear_order δ] [topological_space δ] [order_closed_topology δ] /-- **Intermediate Value Theorem** for continuous functions on closed intervals, case `f a ≤ t ≤ f b`.-/ lemma intermediate_value_Icc {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Icc (f a) (f b) ⊆ f '' (Icc a b) := is_preconnected_Icc.intermediate_value (left_mem_Icc.2 hab) (right_mem_Icc.2 hab) hf /-- **Intermediate Value Theorem** for continuous functions on closed intervals, case `f a ≥ t ≥ f b`.-/ lemma intermediate_value_Icc' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Icc (f b) (f a) ⊆ f '' (Icc a b) := is_preconnected_Icc.intermediate_value (right_mem_Icc.2 hab) (left_mem_Icc.2 hab) hf /-- **Intermediate Value Theorem** for continuous functions on closed intervals, unordered case. -/ lemma intermediate_value_interval {a b : α} {f : α → δ} (hf : continuous_on f (interval a b)) : interval (f a) (f b) ⊆ f '' interval a b := by cases le_total (f a) (f b); simp [*, is_preconnected_interval.intermediate_value] lemma intermediate_value_Ico {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Ico (f a) (f b) ⊆ f '' (Ico a b) := or.elim (eq_or_lt_of_le hab) (λ he y h, absurd h.2 (not_lt_of_le (he ▸ h.1))) (λ hlt, @is_preconnected.intermediate_value_Ico _ _ _ _ _ _ _ (is_preconnected_Ico) _ _ ⟨refl a, hlt⟩ (right_nhds_within_Ico_ne_bot hlt) inf_le_right _ (hf.mono Ico_subset_Icc_self) _ ((hf.continuous_within_at ⟨hab, refl b⟩).mono Ico_subset_Icc_self)) lemma intermediate_value_Ico' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Ioc (f b) (f a) ⊆ f '' (Ico a b) := or.elim (eq_or_lt_of_le hab) (λ he y h, absurd h.1 (not_lt_of_le (he ▸ h.2))) (λ hlt, @is_preconnected.intermediate_value_Ioc _ _ _ _ _ _ _ (is_preconnected_Ico) _ _ ⟨refl a, hlt⟩ (right_nhds_within_Ico_ne_bot hlt) inf_le_right _ (hf.mono Ico_subset_Icc_self) _ ((hf.continuous_within_at ⟨hab, refl b⟩).mono Ico_subset_Icc_self)) lemma intermediate_value_Ioc {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Ioc (f a) (f b) ⊆ f '' (Ioc a b) := or.elim (eq_or_lt_of_le hab) (λ he y h, absurd h.2 (not_le_of_lt (he ▸ h.1))) (λ hlt, @is_preconnected.intermediate_value_Ioc _ _ _ _ _ _ _ (is_preconnected_Ioc) _ _ ⟨hlt, refl b⟩ (left_nhds_within_Ioc_ne_bot hlt) inf_le_right _ (hf.mono Ioc_subset_Icc_self) _ ((hf.continuous_within_at ⟨refl a, hab⟩).mono Ioc_subset_Icc_self)) lemma intermediate_value_Ioc' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Ico (f b) (f a) ⊆ f '' (Ioc a b) := or.elim (eq_or_lt_of_le hab) (λ he y h, absurd h.1 (not_le_of_lt (he ▸ h.2))) (λ hlt, @is_preconnected.intermediate_value_Ico _ _ _ _ _ _ _ (is_preconnected_Ioc) _ _ ⟨hlt, refl b⟩ (left_nhds_within_Ioc_ne_bot hlt) inf_le_right _ (hf.mono Ioc_subset_Icc_self) _ ((hf.continuous_within_at ⟨refl a, hab⟩).mono Ioc_subset_Icc_self)) lemma intermediate_value_Ioo {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Ioo (f a) (f b) ⊆ f '' (Ioo a b) := or.elim (eq_or_lt_of_le hab) (λ he y h, absurd h.2 (not_lt_of_lt (he ▸ h.1))) (λ hlt, @is_preconnected.intermediate_value_Ioo _ _ _ _ _ _ _ (is_preconnected_Ioo) _ _ (left_nhds_within_Ioo_ne_bot hlt) (right_nhds_within_Ioo_ne_bot hlt) inf_le_right inf_le_right _ (hf.mono Ioo_subset_Icc_self) _ _ ((hf.continuous_within_at ⟨refl a, hab⟩).mono Ioo_subset_Icc_self) ((hf.continuous_within_at ⟨hab, refl b⟩).mono Ioo_subset_Icc_self)) lemma intermediate_value_Ioo' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Ioo (f b) (f a) ⊆ f '' (Ioo a b) := or.elim (eq_or_lt_of_le hab) (λ he y h, absurd h.1 (not_lt_of_lt (he ▸ h.2))) (λ hlt, @is_preconnected.intermediate_value_Ioo _ _ _ _ _ _ _ (is_preconnected_Ioo) _ _ (right_nhds_within_Ioo_ne_bot hlt) (left_nhds_within_Ioo_ne_bot hlt) inf_le_right inf_le_right _ (hf.mono Ioo_subset_Icc_self) _ _ ((hf.continuous_within_at ⟨hab, refl b⟩).mono Ioo_subset_Icc_self) ((hf.continuous_within_at ⟨refl a, hab⟩).mono Ioo_subset_Icc_self)) /-- A continuous function which tendsto `at_top` `at_top` and to `at_bot` `at_bot` is surjective. -/ lemma continuous.surjective {f : α → δ} (hf : continuous f) (h_top : tendsto f at_top at_top) (h_bot : tendsto f at_bot at_bot) : function.surjective f := λ p, mem_range_of_exists_le_of_exists_ge hf (h_bot.eventually (eventually_le_at_bot p)).exists (h_top.eventually (eventually_ge_at_top p)).exists /-- A continuous function which tendsto `at_bot` `at_top` and to `at_top` `at_bot` is surjective. -/ lemma continuous.surjective' {f : α → δ} (hf : continuous f) (h_top : tendsto f at_bot at_top) (h_bot : tendsto f at_top at_bot) : function.surjective f := @continuous.surjective (order_dual α) _ _ _ _ _ _ _ _ _ hf h_top h_bot /-- If a function `f : α → β` is continuous on a nonempty interval `s`, its restriction to `s` tends to `at_bot : filter β` along `at_bot : filter ↥s` and tends to `at_top : filter β` along `at_top : filter ↥s`, then the restriction of `f` to `s` is surjective. We formulate the conclusion as `surj_on f s univ`. -/ lemma continuous_on.surj_on_of_tendsto {f : α → β} {s : set α} [ord_connected s] (hs : s.nonempty) (hf : continuous_on f s) (hbot : tendsto (λ x : s, f x) at_bot at_bot) (htop : tendsto (λ x : s, f x) at_top at_top) : surj_on f s univ := by haveI := inhabited_of_nonempty hs.to_subtype; exact (surj_on_iff_surjective.2 $ (continuous_on_iff_continuous_restrict.1 hf).surjective htop hbot) /-- If a function `f : α → β` is continuous on a nonempty interval `s`, its restriction to `s` tends to `at_top : filter β` along `at_bot : filter ↥s` and tends to `at_bot : filter β` along `at_top : filter ↥s`, then the restriction of `f` to `s` is surjective. We formulate the conclusion as `surj_on f s univ`. -/ lemma continuous_on.surj_on_of_tendsto' {f : α → β} {s : set α} [ord_connected s] (hs : s.nonempty) (hf : continuous_on f s) (hbot : tendsto (λ x : s, f x) at_bot at_top) (htop : tendsto (λ x : s, f x) at_top at_bot) : surj_on f s univ := @continuous_on.surj_on_of_tendsto α (order_dual β) _ _ _ _ _ _ _ _ _ _ hs hf hbot htop end densely_ordered /-- A closed interval in a conditionally complete linear order is compact. -/ lemma is_compact_Icc {a b : α} : is_compact (Icc a b) := begin cases le_or_lt a b with hab hab, swap, { simp [hab] }, refine is_compact_iff_ultrafilter_le_nhds.2 (λ f hf, _), contrapose! hf, rw [le_principal_iff], have hpt : ∀ x ∈ Icc a b, {x} ∉ f, from λ x hx hxf, hf x hx ((le_pure_iff.2 hxf).trans (pure_le_nhds x)), set s := {x ∈ Icc a b | Icc a x ∉ f}, have hsb : b ∈ upper_bounds s, from λ x hx, hx.1.2, have sbd : bdd_above s, from ⟨b, hsb⟩, have ha : a ∈ s, by simp [hpt, hab], rcases hab.eq_or_lt with rfl|hlt, { exact ha.2 }, set c := Sup s, have hsc : is_lub s c, from is_lub_cSup ⟨a, ha⟩ sbd, have hc : c ∈ Icc a b, from ⟨hsc.1 ha, hsc.2 hsb⟩, specialize hf c hc, have hcs : c ∈ s, { cases hc.1.eq_or_lt with heq hlt, { rwa ← heq }, refine ⟨hc, λ hcf, hf (λ U hU, _)⟩, rcases (mem_nhds_within_Iic_iff_exists_Ioc_subset' hlt).1 (mem_nhds_within_of_mem_nhds hU) with ⟨x, hxc, hxU⟩, rcases ((hsc.frequently_mem ⟨a, ha⟩).and_eventually (Ioc_mem_nhds_within_Iic ⟨hxc, le_rfl⟩)).exists with ⟨y, ⟨hyab, hyf⟩, hy⟩, refine mem_sets_of_superset(f.diff_mem_iff.2 ⟨hcf, hyf⟩) (subset.trans _ hxU), rw diff_subset_iff, exact subset.trans Icc_subset_Icc_union_Ioc (union_subset_union subset.rfl $ Ioc_subset_Ioc_left hy.1.le) }, cases hc.2.eq_or_lt with heq hlt, { rw ← heq, exact hcs.2 }, contrapose! hf, intros U hU, rcases (mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset hlt).1 (mem_nhds_within_of_mem_nhds hU) with ⟨y, hxy, hyU⟩, refine mem_sets_of_superset _ hyU, clear_dependent U, have hy : y ∈ Icc a b, from ⟨hc.1.trans hxy.1.le, hxy.2⟩, by_cases hay : Icc a y ∈ f, { refine mem_sets_of_superset (f.diff_mem_iff.2 ⟨f.diff_mem_iff.2 ⟨hay, hcs.2⟩, hpt y hy⟩) _, rw [diff_subset_iff, union_comm, Ico_union_right hxy.1.le, diff_subset_iff], exact Icc_subset_Icc_union_Icc }, { exact ((hsc.1 ⟨hy, hay⟩).not_lt hxy.1).elim }, end /-- An unordered closed interval in a conditionally complete linear order is compact. -/ lemma is_compact_interval {a b : α} : is_compact (interval a b) := is_compact_Icc lemma is_compact_pi_Icc {ι : Type*} {α : ι → Type*} [Π i, conditionally_complete_linear_order (α i)] [Π i, topological_space (α i)] [Π i, order_topology (α i)] (a b : Π i, α i) : is_compact (Icc a b) := pi_univ_Icc a b ▸ is_compact_univ_pi $ λ i, is_compact_Icc instance compact_space_Icc (a b : α) : compact_space (Icc a b) := is_compact_iff_compact_space.mp is_compact_Icc instance compact_space_pi_Icc {ι : Type*} {α : ι → Type*} [Π i, conditionally_complete_linear_order (α i)] [Π i, topological_space (α i)] [Π i, order_topology (α i)] (a b : Π i, α i) : compact_space (Icc a b) := is_compact_iff_compact_space.mp (is_compact_pi_Icc a b) @[priority 100] -- See note [lower instance priority] instance compact_space_of_complete_linear_order {α : Type*} [complete_linear_order α] [topological_space α] [order_topology α] : compact_space α := ⟨by simp only [← Icc_bot_top, is_compact_Icc]⟩ lemma is_compact.Inf_mem {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : Inf s ∈ s := hs.is_closed.cInf_mem ne_s hs.bdd_below lemma is_compact.Sup_mem {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : Sup s ∈ s := @is_compact.Inf_mem (order_dual α) _ _ _ _ hs ne_s lemma is_compact.is_glb_Inf {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : is_glb s (Inf s) := is_glb_cInf ne_s hs.bdd_below lemma is_compact.is_lub_Sup {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : is_lub s (Sup s) := @is_compact.is_glb_Inf (order_dual α) _ _ _ _ hs ne_s lemma is_compact.is_least_Inf {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : is_least s (Inf s) := ⟨hs.Inf_mem ne_s, (hs.is_glb_Inf ne_s).1⟩ lemma is_compact.is_greatest_Sup {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : is_greatest s (Sup s) := @is_compact.is_least_Inf (order_dual α) _ _ _ _ hs ne_s lemma is_compact.exists_is_least {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : ∃ x, is_least s x := ⟨_, hs.is_least_Inf ne_s⟩ lemma is_compact.exists_is_greatest {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : ∃ x, is_greatest s x := ⟨_, hs.is_greatest_Sup ne_s⟩ lemma is_compact.exists_is_glb {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : ∃ x ∈ s, is_glb s x := ⟨_, hs.Inf_mem ne_s, hs.is_glb_Inf ne_s⟩ lemma is_compact.exists_is_lub {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : ∃ x ∈ s, is_lub s x := ⟨_, hs.Sup_mem ne_s, hs.is_lub_Sup ne_s⟩ lemma is_compact.exists_Inf_image_eq {α : Type u} [topological_space α] {s : set α} (hs : is_compact s) (ne_s : s.nonempty) {f : α → β} (hf : continuous_on f s) : ∃ x ∈ s, Inf (f '' s) = f x := let ⟨x, hxs, hx⟩ := (hs.image_of_continuous_on hf).Inf_mem (ne_s.image f) in ⟨x, hxs, hx.symm⟩ lemma is_compact.exists_Sup_image_eq {α : Type u} [topological_space α]: ∀ {s : set α}, is_compact s → s.nonempty → ∀ {f : α → β}, continuous_on f s → ∃ x ∈ s, Sup (f '' s) = f x := @is_compact.exists_Inf_image_eq (order_dual β) _ _ _ _ _ lemma eq_Icc_of_connected_compact {s : set α} (h₁ : is_connected s) (h₂ : is_compact s) : s = Icc (Inf s) (Sup s) := eq_Icc_cInf_cSup_of_connected_bdd_closed h₁ h₂.bdd_below h₂.bdd_above h₂.is_closed /-- The extreme value theorem: a continuous function realizes its minimum on a compact set -/ lemma is_compact.exists_forall_le {α : Type u} [topological_space α] {s : set α} (hs : is_compact s) (ne_s : s.nonempty) {f : α → β} (hf : continuous_on f s) : ∃x∈s, ∀y∈s, f x ≤ f y := begin rcases hs.exists_Inf_image_eq ne_s hf with ⟨x, hxs, hx⟩, refine ⟨x, hxs, λ y hy, _⟩, rw ← hx, exact ((hs.image_of_continuous_on hf).is_glb_Inf (ne_s.image f)).1 (mem_image_of_mem _ hy) end /-- The extreme value theorem: a continuous function realizes its maximum on a compact set -/ lemma is_compact.exists_forall_ge {α : Type u} [topological_space α]: ∀ {s : set α}, is_compact s → s.nonempty → ∀ {f : α → β}, continuous_on f s → ∃x∈s, ∀y∈s, f y ≤ f x := @is_compact.exists_forall_le (order_dual β) _ _ _ _ _ /-- The extreme value theorem: if a continuous function `f` tends to infinity away from compact sets, then it has a global minimum. -/ lemma continuous.exists_forall_le {α : Type*} [topological_space α] [nonempty α] {f : α → β} (hf : continuous f) (hlim : tendsto f (cocompact α) at_top) : ∃ x, ∀ y, f x ≤ f y := begin inhabit α, obtain ⟨s : set α, hsc : is_compact s, hsf : ∀ x ∉ s, f (default α) ≤ f x⟩ := (has_basis_cocompact.tendsto_iff at_top_basis).1 hlim (f $ default α) trivial, obtain ⟨x, -, hx⟩ := (hsc.insert (default α)).exists_forall_le (nonempty_insert _ _) hf.continuous_on, refine ⟨x, λ y, _⟩, by_cases hy : y ∈ s, exacts [hx y (or.inr hy), (hx _ (or.inl rfl)).trans (hsf y hy)] end /-- The extreme value theorem: if a continuous function `f` tends to negative infinity away from compactx sets, then it has a global maximum. -/ lemma continuous.exists_forall_ge {α : Type*} [topological_space α] [nonempty α] {f : α → β} (hf : continuous f) (hlim : tendsto f (cocompact α) at_bot) : ∃ x, ∀ y, f y ≤ f x := @continuous.exists_forall_le (order_dual β) _ _ _ _ _ _ _ hf hlim end conditionally_complete_linear_order end order_topology /-! ### Bounded monotone sequences converge The first result in this section is that in a linear order `α`, if the range of a monotone function `f : α → ι` admits a least upper bound `a`, then `f` converges to `a`. Later results specialize this to the case of (conditionally) complete linear orders, where the existence of a least upper bound `α` is automatic. In these settings the result is that `f` converges to its supremum, `⨆ i, f i`. Here is a counter-example to show that the order must be a linear (i.e., total) order. Take `α = [0, 1) → ℝ` with the natural lattice structure; this is a `conditionally_complete_lattice`. Take `ι = ℕ` and `f n x = -x^n`. Then `⨆ n, f n = 0` while none of `f n` is strictly greater than the constant function `-0.5`. -/ lemma tendsto_at_top_is_lub {ι α : Type*} [preorder ι] [topological_space α] [linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) {a : α} (ha : is_lub (set.range f) a) : tendsto f at_top (𝓝 a) := begin by_cases hi : nonempty ι, { resetI, rw tendsto_order, split, { intros a' ha', obtain ⟨_, ⟨N, rfl⟩, hN⟩ : ∃ x ∈ set.range f, a' < x := (lt_is_lub_iff ha).mp ha', have := ha.2, apply eventually.mono (mem_at_top N), exact λ i hi, lt_of_lt_of_le hN (h_mono hi) }, { intros a' ha', exact eventually_of_forall (λ i, lt_of_le_of_lt (ha.1 (set.mem_range_self i)) ha') } }, { exact tendsto_of_not_nonempty hi } end lemma tendsto_at_bot_is_glb {ι α : Type*} [preorder ι] [topological_space α] [linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) {a : α} (ha : is_glb (set.range f) a) : tendsto f at_bot (𝓝 a) := @tendsto_at_top_is_lub (order_dual ι) (order_dual α) _ _ _ _ _ h_mono.order_dual _ ha lemma tendsto_at_top_csupr {ι α : Type*} [preorder ι] [topological_space α] [conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) (hbdd : bdd_above $ range f) : tendsto f at_top (𝓝 (⨆i, f i)) := begin by_cases hi : nonempty ι, { resetI, exact tendsto_at_top_is_lub h_mono (is_lub_cSup (range_nonempty f) hbdd) }, { exact tendsto_of_not_nonempty hi } end lemma tendsto_at_bot_cinfi {ι α : Type*} [preorder ι] [topological_space α] [conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) (hbdd : bdd_below $ range f) : tendsto f at_bot (𝓝 (⨅i, f i)) := @tendsto_at_top_csupr (order_dual ι) (order_dual α) _ _ _ _ _ h_mono.order_dual hbdd lemma tendsto_at_top_cinfi {ι α : Type*} [preorder ι] [topological_space α] [conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) (hbdd : bdd_below $ range f) : tendsto f at_top (𝓝 (⨅i, f i)) := @tendsto_at_top_csupr _ (order_dual α) _ _ _ _ _ @h_mono hbdd lemma tendsto_at_bot_csupr {ι α : Type*} [preorder ι] [topological_space α] [conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) (hbdd : bdd_above $ range f) : tendsto f at_bot (𝓝 (⨆i, f i)) := @tendsto_at_bot_cinfi ι (order_dual α) _ _ _ _ _ h_mono hbdd lemma tendsto_at_top_supr {ι α : Type*} [preorder ι] [topological_space α] [complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) : tendsto f at_top (𝓝 (⨆i, f i)) := tendsto_at_top_csupr h_mono (order_top.bdd_above _) lemma tendsto_at_bot_infi {ι α : Type*} [preorder ι] [topological_space α] [complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) : tendsto f at_bot (𝓝 (⨅i, f i)) := tendsto_at_bot_cinfi h_mono (order_bot.bdd_below _) lemma tendsto_at_top_infi {ι α : Type*} [preorder ι] [topological_space α] [complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) : tendsto f at_top (𝓝 (⨅i, f i)) := tendsto_at_top_cinfi @h_mono (order_bot.bdd_below _) lemma tendsto_at_bot_supr {ι α : Type*} [preorder ι] [topological_space α] [complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) : tendsto f at_bot (𝓝 (⨆i, f i)) := tendsto_at_bot_csupr h_mono (order_top.bdd_above _) lemma tendsto_of_monotone {ι α : Type*} [preorder ι] [topological_space α] [conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) : tendsto f at_top at_top ∨ (∃ l, tendsto f at_top (𝓝 l)) := if H : bdd_above (range f) then or.inr ⟨_, tendsto_at_top_csupr h_mono H⟩ else or.inl $ tendsto_at_top_at_top_of_monotone' h_mono H lemma tendsto_iff_tendsto_subseq_of_monotone {ι₁ ι₂ α : Type*} [semilattice_sup ι₁] [preorder ι₂] [nonempty ι₁] [topological_space α] [conditionally_complete_linear_order α] [order_topology α] [no_top_order α] {f : ι₂ → α} {φ : ι₁ → ι₂} {l : α} (hf : monotone f) (hg : tendsto φ at_top at_top) : tendsto f at_top (𝓝 l) ↔ tendsto (f ∘ φ) at_top (𝓝 l) := begin split; intro h, { exact h.comp hg }, { rcases tendsto_of_monotone hf with h' | ⟨l', hl'⟩, { exact (not_tendsto_at_top_of_tendsto_nhds h (h'.comp hg)).elim }, { rwa tendsto_nhds_unique h (hl'.comp hg) } } end /-! The next family of results, such as `is_lub_of_tendsto` and `supr_eq_of_tendsto`, are converses to the standard fact that bounded monotone functions converge. They state, that if a monotone function `f` tends to `a` along `at_top`, then that value `a` is a least upper bound for the range of `f`. Related theorems above (`is_lub.is_lub_of_tendsto`, `is_glb.is_glb_of_tendsto` etc) cover the case when `f x` tends to `a` as `x` tends to some point `b` in the domain. -/ lemma monotone.ge_of_tendsto {α β : Type*} [topological_space α] [preorder α] [order_closed_topology α] [semilattice_sup β] {f : β → α} {a : α} (hf : monotone f) (ha : tendsto f at_top (𝓝 a)) (b : β) : f b ≤ a := begin haveI : nonempty β := nonempty.intro b, exact ge_of_tendsto ha ((eventually_ge_at_top b).mono (λ _ hxy, hf hxy)) end lemma monotone.le_of_tendsto {α β : Type*} [topological_space α] [preorder α] [order_closed_topology α] [semilattice_inf β] {f : β → α} {a : α} (hf : monotone f) (ha : tendsto f at_bot (𝓝 a)) (b : β) : a ≤ f b := @monotone.ge_of_tendsto (order_dual α) (order_dual β) _ _ _ _ f _ hf.order_dual ha b lemma is_lub_of_tendsto {α β : Type*} [topological_space α] [preorder α] [order_closed_topology α] [nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : monotone f) (ha : tendsto f at_top (𝓝 a)) : is_lub (set.range f) a := begin split, { rintros _ ⟨b, rfl⟩, exact hf.ge_of_tendsto ha b }, { exact λ _ hb, le_of_tendsto' ha (λ x, hb (set.mem_range_self x)) } end lemma is_glb_of_tendsto {α β : Type*} [topological_space α] [preorder α] [order_closed_topology α] [nonempty β] [semilattice_inf β] {f : β → α} {a : α} (hf : monotone f) (ha : tendsto f at_bot (𝓝 a)) : is_glb (set.range f) a := @is_lub_of_tendsto (order_dual α) (order_dual β) _ _ _ _ _ _ _ hf.order_dual ha lemma supr_eq_of_tendsto {α β} [topological_space α] [complete_linear_order α] [order_topology α] [nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : monotone f) : tendsto f at_top (𝓝 a) → supr f = a := tendsto_nhds_unique (tendsto_at_top_supr hf) lemma infi_eq_of_tendsto {α} [topological_space α] [complete_linear_order α] [order_topology α] [nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : ∀n m, n ≤ m → f m ≤ f n) : tendsto f at_top (𝓝 a) → infi f = a := tendsto_nhds_unique (tendsto_at_top_infi hf) lemma supr_eq_supr_subseq_of_monotone {ι₁ ι₂ α : Type*} [preorder ι₂] [complete_lattice α] {l : filter ι₁} [l.ne_bot] {f : ι₂ → α} {φ : ι₁ → ι₂} (hf : monotone f) (hφ : tendsto φ l at_top) : (⨆ i, f i) = (⨆ i, f (φ i)) := le_antisymm (supr_le_supr2 $ λ i, exists_imp_exists (λ j (hj : i ≤ φ j), hf hj) (hφ.eventually $ eventually_ge_at_top i).exists) (supr_le_supr2 $ λ i, ⟨φ i, le_refl _⟩) lemma infi_eq_infi_subseq_of_monotone {ι₁ ι₂ α : Type*} [preorder ι₂] [complete_lattice α] {l : filter ι₁} [l.ne_bot] {f : ι₂ → α} {φ : ι₁ → ι₂} (hf : monotone f) (hφ : tendsto φ l at_bot) : (⨅ i, f i) = (⨅ i, f (φ i)) := le_antisymm (infi_le_infi2 $ λ i, ⟨φ i, le_refl _⟩) (infi_le_infi2 $ λ i, exists_imp_exists (λ j (hj : φ j ≤ i), hf hj) (hφ.eventually $ eventually_le_at_bot i).exists) @[to_additive] lemma tendsto_inv_nhds_within_Ioi [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Ioi a] a) (𝓝[Iio (a⁻¹)] (a⁻¹)) := (continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal] @[to_additive] lemma tendsto_inv_nhds_within_Iio [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Iio a] a) (𝓝[Ioi (a⁻¹)] (a⁻¹)) := (continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal] @[to_additive] lemma tendsto_inv_nhds_within_Ioi_inv [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Ioi (a⁻¹)] (a⁻¹)) (𝓝[Iio a] a) := by simpa only [inv_inv] using @tendsto_inv_nhds_within_Ioi _ _ _ _ (a⁻¹) @[to_additive] lemma tendsto_inv_nhds_within_Iio_inv [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Iio (a⁻¹)] (a⁻¹)) (𝓝[Ioi a] a) := by simpa only [inv_inv] using @tendsto_inv_nhds_within_Iio _ _ _ _ (a⁻¹) @[to_additive] lemma tendsto_inv_nhds_within_Ici [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Ici a] a) (𝓝[Iic (a⁻¹)] (a⁻¹)) := (continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal] @[to_additive] lemma tendsto_inv_nhds_within_Iic [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Iic a] a) (𝓝[Ici (a⁻¹)] (a⁻¹)) := (continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal] @[to_additive] lemma tendsto_inv_nhds_within_Ici_inv [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Ici (a⁻¹)] (a⁻¹)) (𝓝[Iic a] a) := by simpa only [inv_inv] using @tendsto_inv_nhds_within_Ici _ _ _ _ (a⁻¹) @[to_additive] lemma tendsto_inv_nhds_within_Iic_inv [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Iic (a⁻¹)] (a⁻¹)) (𝓝[Ici a] a) := by simpa only [inv_inv] using @tendsto_inv_nhds_within_Iic _ _ _ _ (a⁻¹) lemma nhds_left_sup_nhds_right (a : α) [topological_space α] [linear_order α] : 𝓝[Iic a] a ⊔ 𝓝[Ici a] a = 𝓝 a := by rw [← nhds_within_union, Iic_union_Ici, nhds_within_univ] lemma nhds_left'_sup_nhds_right (a : α) [topological_space α] [linear_order α] : 𝓝[Iio a] a ⊔ 𝓝[Ici a] a = 𝓝 a := by rw [← nhds_within_union, Iio_union_Ici, nhds_within_univ] lemma nhds_left_sup_nhds_right' (a : α) [topological_space α] [linear_order α] : 𝓝[Iic a] a ⊔ 𝓝[Ioi a] a = 𝓝 a := by rw [← nhds_within_union, Iic_union_Ioi, nhds_within_univ] lemma continuous_at_iff_continuous_left_right [topological_space α] [linear_order α] [topological_space β] {a : α} {f : α → β} : continuous_at f a ↔ continuous_within_at f (Iic a) a ∧ continuous_within_at f (Ici a) a := by simp only [continuous_within_at, continuous_at, ← tendsto_sup, nhds_left_sup_nhds_right] lemma continuous_within_at_Ioi_iff_Ici {α β : Type*} [topological_space α] [partial_order α] [topological_space β] {a : α} {f : α → β} : continuous_within_at f (Ioi a) a ↔ continuous_within_at f (Ici a) a := by simp only [← Ici_diff_left, continuous_within_at_diff_self] lemma continuous_within_at_Iio_iff_Iic {α β : Type*} [topological_space α] [linear_order α] [topological_space β] {a : α} {f : α → β} : continuous_within_at f (Iio a) a ↔ continuous_within_at f (Iic a) a := begin have := @continuous_within_at_Ioi_iff_Ici (order_dual α) _ _ _ _ _ f, erw [dual_Ici, dual_Ioi] at this, exact this, end lemma continuous_at_iff_continuous_left'_right' [topological_space α] [linear_order α] [topological_space β] {a : α} {f : α → β} : continuous_at f a ↔ continuous_within_at f (Iio a) a ∧ continuous_within_at f (Ioi a) a := by rw [continuous_within_at_Ioi_iff_Ici, continuous_within_at_Iio_iff_Iic, continuous_at_iff_continuous_left_right] /-! ### Continuity of monotone functions In this section we prove the following fact: if `f` is a monotone function on a neighborhood of `a` and the image of this neighborhood is a neighborhood of `f a`, then `f` is continuous at `a`, see `continuous_at_of_mono_incr_on_of_image_mem_nhds`, as well as several similar facts. -/ section linear_order variables [linear_order α] [topological_space α] [order_topology α] variables [linear_order β] [topological_space β] [order_topology β] /-- If `f` is a function strictly monotonically increasing on a right neighborhood of `a` and the image of this neighborhood under `f` meets every interval `(f a, b]`, `b > f a`, then `f` is continuous at `a` from the right. The assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b` is required because otherwise the function `f : ℝ → ℝ` given by `f x = if x ≤ 0 then x else x + 1` would be a counter-example at `a = 0`. -/ lemma strict_mono_incr_on.continuous_at_right_of_exists_between {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a) (hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b) : continuous_within_at f (Ici a) a := begin have ha : a ∈ Ici a := left_mem_Ici, have has : a ∈ s := mem_of_mem_nhds_within ha hs, refine tendsto_order.2 ⟨λ b hb, _, λ b hb, _⟩, { filter_upwards [hs, self_mem_nhds_within], intros x hxs hxa, exact hb.trans_le ((h_mono.le_iff_le has hxs).2 hxa) }, { rcases hfs b hb with ⟨c, hcs, hac, hcb⟩, rw [h_mono.lt_iff_lt has hcs] at hac, filter_upwards [hs, Ico_mem_nhds_within_Ici (left_mem_Ico.2 hac)], rintros x hx ⟨hax, hxc⟩, exact ((h_mono.lt_iff_lt hx hcs).2 hxc).trans_le hcb } end /-- If `f` is a function monotonically increasing function on a right neighborhood of `a` and the image of this neighborhood under `f` meets every interval `(f a, b)`, `b > f a`, then `f` is continuous at `a` from the right. The assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b` cannot be replaced by the weaker assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b` we use for strictly monotone functions because otherwise the function `ceil : ℝ → ℤ` would be a counter-example at `a = 0`. -/ lemma continuous_at_right_of_mono_incr_on_of_exists_between {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Ici a] a) (hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b) : continuous_within_at f (Ici a) a := begin have ha : a ∈ Ici a := left_mem_Ici, have has : a ∈ s := mem_of_mem_nhds_within ha hs, refine tendsto_order.2 ⟨λ b hb, _, λ b hb, _⟩, { filter_upwards [hs, self_mem_nhds_within], intros x hxs hxa, exact hb.trans_le (h_mono _ has _ hxs hxa) }, { rcases hfs b hb with ⟨c, hcs, hac, hcb⟩, have : a < c, from not_le.1 (λ h, hac.not_le $ h_mono _ hcs _ has h), filter_upwards [hs, Ico_mem_nhds_within_Ici (left_mem_Ico.2 this)], rintros x hx ⟨hax, hxc⟩, exact (h_mono _ hx _ hcs hxc.le).trans_lt hcb } end /-- If a function `f` with a densely ordered codomain is monotonically increasing on a right neighborhood of `a` and the closure of the image of this neighborhood under `f` is a right neighborhood of `f a`, then `f` is continuous at `a` from the right. -/ lemma continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Ici a] a) (hfs : closure (f '' s) ∈ 𝓝[Ici (f a)] (f a)) : continuous_within_at f (Ici a) a := begin refine continuous_at_right_of_mono_incr_on_of_exists_between h_mono hs (λ b hb, _), rcases (mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset hb).1 hfs with ⟨b', ⟨hab', hbb'⟩, hb'⟩, rcases exists_between hab' with ⟨c', hc'⟩, rcases mem_closure_iff.1 (hb' ⟨hc'.1.le, hc'.2⟩) (Ioo (f a) b') is_open_Ioo hc' with ⟨_, hc, ⟨c, hcs, rfl⟩⟩, exact ⟨c, hcs, hc.1, hc.2.trans_le hbb'⟩ end /-- If a function `f` with a densely ordered codomain is monotonically increasing on a right neighborhood of `a` and the image of this neighborhood under `f` is a right neighborhood of `f a`, then `f` is continuous at `a` from the right. -/ lemma continuous_at_right_of_mono_incr_on_of_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Ici a] a) (hfs : f '' s ∈ 𝓝[Ici (f a)] (f a)) : continuous_within_at f (Ici a) a := continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono hs $ mem_sets_of_superset hfs subset_closure /-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a right neighborhood of `a` and the closure of the image of this neighborhood under `f` is a right neighborhood of `f a`, then `f` is continuous at `a` from the right. -/ lemma strict_mono_incr_on.continuous_at_right_of_closure_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a) (hfs : closure (f '' s) ∈ 𝓝[Ici (f a)] (f a)) : continuous_within_at f (Ici a) a := continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within (λ x hx y hy, (h_mono.le_iff_le hx hy).2) hs hfs /-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a right neighborhood of `a` and the image of this neighborhood under `f` is a right neighborhood of `f a`, then `f` is continuous at `a` from the right. -/ lemma strict_mono_incr_on.continuous_at_right_of_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a) (hfs : f '' s ∈ 𝓝[Ici (f a)] (f a)) : continuous_within_at f (Ici a) a := h_mono.continuous_at_right_of_closure_image_mem_nhds_within hs (mem_sets_of_superset hfs subset_closure) /-- If a function `f` is strictly monotonically increasing on a right neighborhood of `a` and the image of this neighborhood under `f` includes `Ioi (f a)`, then `f` is continuous at `a` from the right. -/ lemma strict_mono_incr_on.continuous_at_right_of_surj_on {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a) (hfs : surj_on f s (Ioi (f a))) : continuous_within_at f (Ici a) a := h_mono.continuous_at_right_of_exists_between hs $ λ b hb, let ⟨c, hcs, hcb⟩ := hfs hb in ⟨c, hcs, hcb.symm ▸ hb, hcb.le⟩ /-- If `f` is a function strictly monotonically increasing on a left neighborhood of `a` and the image of this neighborhood under `f` meets every interval `[b, f a)`, `b < f a`, then `f` is continuous at `a` from the left. The assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)` is required because otherwise the function `f : ℝ → ℝ` given by `f x = if x < 0 then x else x + 1` would be a counter-example at `a = 0`. -/ lemma strict_mono_incr_on.continuous_at_left_of_exists_between {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a) (hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)) : continuous_within_at f (Iic a) a := h_mono.dual.continuous_at_right_of_exists_between hs $ λ b hb, let ⟨c, hcs, hcb, hca⟩ := hfs b hb in ⟨c, hcs, hca, hcb⟩ /-- If `f` is a function monotonically increasing function on a left neighborhood of `a` and the image of this neighborhood under `f` meets every interval `(b, f a)`, `b < f a`, then `f` is continuous at `a` from the left. The assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)` cannot be replaced by the weaker assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)` we use for strictly monotone functions because otherwise the function `floor : ℝ → ℤ` would be a counter-example at `a = 0`. -/ lemma continuous_at_left_of_mono_incr_on_of_exists_between {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Iic a] a) (hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)) : continuous_within_at f (Iic a) a := @continuous_at_right_of_mono_incr_on_of_exists_between (order_dual α) (order_dual β) _ _ _ _ _ _ f s a (λ x hx y hy, h_mono y hy x hx) hs $ λ b hb, let ⟨c, hcs, hcb, hca⟩ := hfs b hb in ⟨c, hcs, hca, hcb⟩ /-- If a function `f` with a densely ordered codomain is monotonically increasing on a left neighborhood of `a` and the closure of the image of this neighborhood under `f` is a left neighborhood of `f a`, then `f` is continuous at `a` from the left -/ lemma continuous_at_left_of_mono_incr_on_of_closure_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Iic a] a) (hfs : closure (f '' s) ∈ 𝓝[Iic (f a)] (f a)) : continuous_within_at f (Iic a) a := @continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within (order_dual α) (order_dual β) _ _ _ _ _ _ _ f s a (λ x hx y hy, h_mono y hy x hx) hs hfs /-- If a function `f` with a densely ordered codomain is monotonically increasing on a left neighborhood of `a` and the image of this neighborhood under `f` is a left neighborhood of `f a`, then `f` is continuous at `a` from the left. -/ lemma continuous_at_left_of_mono_incr_on_of_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Iic a] a) (hfs : f '' s ∈ 𝓝[Iic (f a)] (f a)) : continuous_within_at f (Iic a) a := continuous_at_left_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono hs (mem_sets_of_superset hfs subset_closure) /-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a left neighborhood of `a` and the closure of the image of this neighborhood under `f` is a left neighborhood of `f a`, then `f` is continuous at `a` from the left. -/ lemma strict_mono_incr_on.continuous_at_left_of_closure_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a) (hfs : closure (f '' s) ∈ 𝓝[Iic (f a)] (f a)) : continuous_within_at f (Iic a) a := h_mono.dual.continuous_at_right_of_closure_image_mem_nhds_within hs hfs /-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a left neighborhood of `a` and the image of this neighborhood under `f` is a left neighborhood of `f a`, then `f` is continuous at `a` from the left. -/ lemma strict_mono_incr_on.continuous_at_left_of_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a) (hfs : f '' s ∈ 𝓝[Iic (f a)] (f a)) : continuous_within_at f (Iic a) a := h_mono.dual.continuous_at_right_of_image_mem_nhds_within hs hfs /-- If a function `f` is strictly monotonically increasing on a left neighborhood of `a` and the image of this neighborhood under `f` includes `Iio (f a)`, then `f` is continuous at `a` from the left. -/ lemma strict_mono_incr_on.continuous_at_left_of_surj_on {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a) (hfs : surj_on f s (Iio (f a))) : continuous_within_at f (Iic a) a := h_mono.dual.continuous_at_right_of_surj_on hs hfs /-- If a function `f` is strictly monotonically increasing on a neighborhood of `a` and the image of this neighborhood under `f` meets every interval `[b, f a)`, `b < f a`, and every interval `(f a, b]`, `b > f a`, then `f` is continuous at `a`. -/ lemma strict_mono_incr_on.continuous_at_of_exists_between {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝 a) (hfs_l : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)) (hfs_r : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b) : continuous_at f a := continuous_at_iff_continuous_left_right.2 ⟨h_mono.continuous_at_left_of_exists_between (mem_nhds_within_of_mem_nhds hs) hfs_l, h_mono.continuous_at_right_of_exists_between (mem_nhds_within_of_mem_nhds hs) hfs_r⟩ /-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a neighborhood of `a` and the closure of the image of this neighborhood under `f` is a neighborhood of `f a`, then `f` is continuous at `a`. -/ lemma strict_mono_incr_on.continuous_at_of_closure_image_mem_nhds [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝 a) (hfs : closure (f '' s) ∈ 𝓝 (f a)) : continuous_at f a := continuous_at_iff_continuous_left_right.2 ⟨h_mono.continuous_at_left_of_closure_image_mem_nhds_within (mem_nhds_within_of_mem_nhds hs) (mem_nhds_within_of_mem_nhds hfs), h_mono.continuous_at_right_of_closure_image_mem_nhds_within (mem_nhds_within_of_mem_nhds hs) (mem_nhds_within_of_mem_nhds hfs)⟩ /-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a neighborhood of `a` and the image of this set under `f` is a neighborhood of `f a`, then `f` is continuous at `a`. -/ lemma strict_mono_incr_on.continuous_at_of_image_mem_nhds [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝 a) (hfs : f '' s ∈ 𝓝 (f a)) : continuous_at f a := h_mono.continuous_at_of_closure_image_mem_nhds hs (mem_sets_of_superset hfs subset_closure) /-- If `f` is a function monotonically increasing function on a neighborhood of `a` and the image of this neighborhood under `f` meets every interval `(b, f a)`, `b < f a`, and every interval `(f a, b)`, `b > f a`, then `f` is continuous at `a`. -/ lemma continuous_at_of_mono_incr_on_of_exists_between {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝 a) (hfs_l : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)) (hfs_r : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b) : continuous_at f a := continuous_at_iff_continuous_left_right.2 ⟨continuous_at_left_of_mono_incr_on_of_exists_between h_mono (mem_nhds_within_of_mem_nhds hs) hfs_l, continuous_at_right_of_mono_incr_on_of_exists_between h_mono (mem_nhds_within_of_mem_nhds hs) hfs_r⟩ /-- If a function `f` with a densely ordered codomain is monotonically increasing on a neighborhood of `a` and the closure of the image of this neighborhood under `f` is a neighborhood of `f a`, then `f` is continuous at `a`. -/ lemma continuous_at_of_mono_incr_on_of_closure_image_mem_nhds [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝 a) (hfs : closure (f '' s) ∈ 𝓝 (f a)) : continuous_at f a := continuous_at_iff_continuous_left_right.2 ⟨continuous_at_left_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono (mem_nhds_within_of_mem_nhds hs) (mem_nhds_within_of_mem_nhds hfs), continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono (mem_nhds_within_of_mem_nhds hs) (mem_nhds_within_of_mem_nhds hfs)⟩ /-- If a function `f` with a densely ordered codomain is monotonically increasing on a neighborhood of `a` and the image of this neighborhood under `f` is a neighborhood of `f a`, then `f` is continuous at `a`. -/ lemma continuous_at_of_mono_incr_on_of_image_mem_nhds [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝 a) (hfs : f '' s ∈ 𝓝 (f a)) : continuous_at f a := continuous_at_of_mono_incr_on_of_closure_image_mem_nhds h_mono hs (mem_sets_of_superset hfs subset_closure) /-- A monotone function with densely ordered codomain and a dense range is continuous. -/ lemma monotone.continuous_of_dense_range [densely_ordered β] {f : α → β} (h_mono : monotone f) (h_dense : dense_range f) : continuous f := continuous_iff_continuous_at.mpr $ λ a, continuous_at_of_mono_incr_on_of_closure_image_mem_nhds (λ x hx y hy hxy, h_mono hxy) univ_mem_sets $ by simp only [image_univ, h_dense.closure_eq, univ_mem_sets] /-- A monotone surjective function with a densely ordered codomain is surjective. -/ lemma monotone.continuous_of_surjective [densely_ordered β] {f : α → β} (h_mono : monotone f) (h_surj : function.surjective f) : continuous f := h_mono.continuous_of_dense_range h_surj.dense_range end linear_order /-! ### Continuity of order isomorphisms In this section we prove that an `order_iso` is continuous, hence it is a `homeomorph`. We prove this for an `order_iso` between to partial orders with order topology. -/ namespace order_iso variables [partial_order α] [partial_order β] [topological_space α] [topological_space β] [order_topology α] [order_topology β] protected lemma continuous (e : α ≃o β) : continuous e := begin rw [‹order_topology β›.topology_eq_generate_intervals], refine continuous_generated_from (λ s hs, _), rcases hs with ⟨a, rfl|rfl⟩, { rw e.preimage_Ioi, apply is_open_lt' }, { rw e.preimage_Iio, apply is_open_gt' } end /-- An order isomorphism between two linear order `order_topology` spaces is a homeomorphism. -/ def to_homeomorph (e : α ≃o β) : α ≃ₜ β := { continuous_to_fun := e.continuous, continuous_inv_fun := e.symm.continuous, .. e } @[simp] lemma coe_to_homeomorph (e : α ≃o β) : ⇑e.to_homeomorph = e := rfl @[simp] lemma coe_to_homeomorph_symm (e : α ≃o β) : ⇑e.to_homeomorph.symm = e.symm := rfl end order_iso
47d105fcf51ccf0c1104a7d49287c9c452a40b5d
6dc0c8ce7a76229dd81e73ed4474f15f88a9e294
/stage0/src/Lean/Parser/Attr.lean
4a8fb75d83a59b6ab137660e22b743a0cc5bc1cc
[ "Apache-2.0" ]
permissive
williamdemeo/lean4
72161c58fe65c3ad955d6a3050bb7d37c04c0d54
6d00fcf1d6d873e195f9220c668ef9c58e9c4a35
refs/heads/master
1,678,305,356,877
1,614,708,995,000
1,614,708,995,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,985
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.Parser.Basic import Lean.Parser.Extra namespace Lean.Parser builtin_initialize registerBuiltinParserAttribute `builtinPrioParser `prio LeadingIdentBehavior.both registerBuiltinDynamicParserAttribute `prioParser `prio builtin_initialize registerBuiltinParserAttribute `builtinAttrParser `attr LeadingIdentBehavior.symbol registerBuiltinDynamicParserAttribute `attrParser `attr @[inline] def priorityParser (rbp : Nat := 0) : Parser := categoryParser `prio rbp @[inline] def attrParser (rbp : Nat := 0) : Parser := categoryParser `attr rbp attribute [runBuiltinParserAttributeHooks] priorityParser attrParser namespace Priority @[builtinPrioParser] def numPrio := checkPrec maxPrec >> numLit attribute [runBuiltinParserAttributeHooks] numPrio end Priority namespace Attr @[builtinAttrParser] def simple := parser! ident >> optional (priorityParser <|> ident) /- Remark, We can't use `simple` for `class`, `instance`, `export`, and `macro` because they are keywords. -/ @[builtinAttrParser] def «macro» := parser! "macro " >> ident @[builtinAttrParser] def «export» := parser! "export " >> ident /- We don't use `simple` for recursor because the argument is not a priority-/ @[builtinAttrParser] def recursor := parser! nonReservedSymbol "recursor " >> numLit @[builtinAttrParser] def «class» := parser! "class" @[builtinAttrParser] def «instance» := parser! "instance" >> optional priorityParser @[builtinAttrParser] def defaultInstance := parser! nonReservedSymbol "defaultInstance " >> optional priorityParser def externEntry := parser! optional ident >> optional (nonReservedSymbol "inline ") >> strLit @[builtinAttrParser] def extern := parser! nonReservedSymbol "extern " >> optional numLit >> many externEntry end Attr end Lean.Parser
e5188ab9f6b6858d35add9ac60cc4618ab053020
5f83eb0c32f15aeed5993a3ad5ededb6f31fe7aa
/lean/attic/jit-concrete.lean
e44621caabc309442eeb39a26c7cafaec3ed9675
[]
no_license
uw-unsat/jitterbug
45b54979b156c0f5330012313052f8594abd6f14
78d1e75ad506498b585fbac66985ff9d9d05952d
refs/heads/master
1,689,066,921,433
1,687,061,448,000
1,688,415,161,000
244,440,882
46
5
null
null
null
null
UTF-8
Lean
false
false
3,679
lean
-- import .jit -- import bv.basic -- @[reducible] def Event : Type := unit -- @[reducible] def Nondet : Type := unit -- @[reducible] def Result : Type := bv 64 -- def Trace : Type := @machine.TRACE Event -- namespace BPF -- @[derive decidable_eq] -- inductive Reg : Type -- | R0 : Reg -- | R1 : Reg -- -- etc. -- @[derive decidable_eq] -- inductive Insn : Type -- | MOV64_Reg : Reg → Reg → Insn -- | EXIT : Insn -- @[reducible] def PC : Type := bv 64 -- def Regs : Type := Reg → bv 64 -- def update (regs : Regs) (r : Reg) (val : bv 64) : Regs := -- λ x, -- ite (x = r) val (regs x) -- structure State : Type := -- mk :: (pc : PC) (regs : Regs) (result : option (bv 64)) -- def init_state : State := -- State.mk 0 (λ _, 0) option.none -- @[reducible] def pc_of : State → PC := State.pc -- @[reducible] def result_of : State → option Result := State.result -- def Code : Type := @machine.CODE PC Insn -- -- Lift a list of instructions to an abstract CODE map -- def liftCode (c: list Insn) : Code := -- λ (p : PC), -- let n : ℕ := bv.to_nat p in -- list.nth c n -- def step_insn (n : Nondet) (i : Insn) (s : State) : State × Trace := -- let (State.mk pc regs _) := s in -- match i with -- | Insn.MOV64_Reg dst src := -- ({regs := update regs dst (regs src), pc := pc + 1, ..s}, []) -- | Insn.EXIT := -- ({result := regs Reg.R0, ..s}, []) -- end -- def step := machine.step pc_of step_insn -- def star := machine.step pc_of step_insn -- end BPF -- namespace rv32 -- @[derive decidable_eq] -- inductive Reg : Type -- | S1 -- | S2 -- | A0 -- | A1 -- @[derive decidable_eq] -- inductive Insn : Type -- | addi : Reg → Reg → bv 12 → Insn -- @[reducible] def PC : Type := bv 32 -- def Regs : Type := Reg → bv 32 -- def Code : Type := @machine.CODE PC Insn -- structure State : Type := -- mk :: (pc : PC) (regs : Regs) -- @[reducible] def pc_of : State → PC := State.pc -- def result_of (s : State) : option Result := -- let regs := State.regs s in -- option.some (bv.concat (regs Reg.A1) (regs Reg.A0)) -- def step_insn (n : Nondet) (i : Insn) (s : State) : State × Trace := -- let (State.mk pc regs) := s in -- match i with -- | Insn.addi dst src imm := -- ({pc := pc + 4, ..s}, []) -- end -- def step := machine.step pc_of step_insn -- def star := machine.step pc_of step_insn -- end rv32 -- namespace rv32_jit -- def Context : Type := unit -- def regmap (r : BPF.Reg) : rv32.Reg × rv32.Reg := -- match r with -- | BPF.Reg.R0 := (rv32.Reg.S2, rv32.Reg.S1) -- | BPF.Reg.R1 := (rv32.Reg.A1, rv32.Reg.A0) -- end -- def phi_reg (s : rv32.State) (r : BPF.Reg) : bv 64 := -- let (hi, lo) := regmap r in -- let regs := (rv32.State.regs s) in -- bv.concat (regs hi) (regs lo) -- def phi_pc (c : Context) (r : BPF.PC) : rv32.PC := -- bv.take 32 (4 * r) -- def emit_insn (c : Context) (src : BPF.Code) (idx : BPF.PC) : option rv32.Code := -- match src idx with -- | option.some (BPF.Insn.MOV64_Reg dst src) := option.none -- | option.some (BPF.Insn.EXIT) := option.none -- | option.none := option.none -- end -- def emit_prologue (c : Context) : rv32.Code := λ x, option.none -- def emit_epilogue (c : Context) : rv32.Code := λ x, option.none -- def related (c : Context) (s : BPF.State) (t : rv32.State) : Prop := -- (∀ (r : BPF.Reg), -- (BPF.State.regs s) r = phi_reg t r) ∧ -- phi_pc c (BPF.State.pc s) = (rv32.State.pc t) -- end rv32_jit
412722883318b396c9b5929a176c3ee449ebd4a9
9dc8cecdf3c4634764a18254e94d43da07142918
/src/topology/metric_space/lipschitz.lean
b0279dedeb874ea850a8a96025a511c7dc8fd7d3
[ "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
29,100
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, Yury Kudryashov -/ import logic.function.iterate import data.set.intervals.proj_Icc import topology.metric_space.basic import topology.bornology.hom /-! # Lipschitz continuous functions A map `f : α → β` between two (extended) metric spaces is called *Lipschitz continuous* with constant `K ≥ 0` if for all `x, y` we have `edist (f x) (f y) ≤ K * edist x y`. For a metric space, the latter inequality is equivalent to `dist (f x) (f y) ≤ K * dist x y`. There is also a version asserting this inequality only for `x` and `y` in some set `s`. In this file we provide various ways to prove that various combinations of Lipschitz continuous functions are Lipschitz continuous. We also prove that Lipschitz continuous functions are uniformly continuous. ## Main definitions and lemmas * `lipschitz_with K f`: states that `f` is Lipschitz with constant `K : ℝ≥0` * `lipschitz_on_with K f`: states that `f` is Lipschitz with constant `K : ℝ≥0` on a set `s` * `lipschitz_with.uniform_continuous`: a Lipschitz function is uniformly continuous * `lipschitz_on_with.uniform_continuous_on`: a function which is Lipschitz on a set is uniformly continuous on that set. ## Implementation notes The parameter `K` has type `ℝ≥0`. This way we avoid conjuction in the definition and have coercions both to `ℝ` and `ℝ≥0∞`. Constructors whose names end with `'` take `K : ℝ` as an argument, and return `lipschitz_with (real.to_nnreal K) f`. -/ universes u v w x open filter function set open_locale topological_space nnreal ennreal variables {α : Type u} {β : Type v} {γ : Type w} {ι : Type x} /-- A function `f` is Lipschitz continuous with constant `K ≥ 0` if for all `x, y` we have `dist (f x) (f y) ≤ K * dist x y` -/ def lipschitz_with [pseudo_emetric_space α] [pseudo_emetric_space β] (K : ℝ≥0) (f : α → β) := ∀x y, edist (f x) (f y) ≤ K * edist x y lemma lipschitz_with_iff_dist_le_mul [pseudo_metric_space α] [pseudo_metric_space β] {K : ℝ≥0} {f : α → β} : lipschitz_with K f ↔ ∀ x y, dist (f x) (f y) ≤ K * dist x y := by { simp only [lipschitz_with, edist_nndist, dist_nndist], norm_cast } alias lipschitz_with_iff_dist_le_mul ↔ lipschitz_with.dist_le_mul lipschitz_with.of_dist_le_mul /-- A function `f` is Lipschitz continuous with constant `K ≥ 0` on `s` if for all `x, y` in `s` we have `dist (f x) (f y) ≤ K * dist x y` -/ def lipschitz_on_with [pseudo_emetric_space α] [pseudo_emetric_space β] (K : ℝ≥0) (f : α → β) (s : set α) := ∀ ⦃x⦄ (hx : x ∈ s) ⦃y⦄ (hy : y ∈ s), edist (f x) (f y) ≤ K * edist x y @[simp] lemma lipschitz_on_with_empty [pseudo_emetric_space α] [pseudo_emetric_space β] (K : ℝ≥0) (f : α → β) : lipschitz_on_with K f ∅ := λ x x_in y y_in, false.elim x_in lemma lipschitz_on_with.mono [pseudo_emetric_space α] [pseudo_emetric_space β] {K : ℝ≥0} {s t : set α} {f : α → β} (hf : lipschitz_on_with K f t) (h : s ⊆ t) : lipschitz_on_with K f s := λ x x_in y y_in, hf (h x_in) (h y_in) lemma lipschitz_on_with_iff_dist_le_mul [pseudo_metric_space α] [pseudo_metric_space β] {K : ℝ≥0} {s : set α} {f : α → β} : lipschitz_on_with K f s ↔ ∀ (x ∈ s) (y ∈ s), dist (f x) (f y) ≤ K * dist x y := by { simp only [lipschitz_on_with, edist_nndist, dist_nndist], norm_cast } alias lipschitz_on_with_iff_dist_le_mul ↔ lipschitz_on_with.dist_le_mul lipschitz_on_with.of_dist_le_mul @[simp] lemma lipschitz_on_univ [pseudo_emetric_space α] [pseudo_emetric_space β] {K : ℝ≥0} {f : α → β} : lipschitz_on_with K f univ ↔ lipschitz_with K f := by simp [lipschitz_on_with, lipschitz_with] lemma lipschitz_on_with_iff_restrict [pseudo_emetric_space α] [pseudo_emetric_space β] {K : ℝ≥0} {f : α → β} {s : set α} : lipschitz_on_with K f s ↔ lipschitz_with K (s.restrict f) := by simp only [lipschitz_on_with, lipschitz_with, set_coe.forall', restrict, subtype.edist_eq] alias lipschitz_on_with_iff_restrict ↔ lipschitz_on_with.to_restrict _ lemma maps_to.lipschitz_on_with_iff_restrict [pseudo_emetric_space α] [pseudo_emetric_space β] {K : ℝ≥0} {f : α → β} {s : set α} {t : set β} (h : maps_to f s t) : lipschitz_on_with K f s ↔ lipschitz_with K (h.restrict f s t) := lipschitz_on_with_iff_restrict alias maps_to.lipschitz_on_with_iff_restrict ↔ lipschitz_on_with.to_restrict_maps_to _ namespace lipschitz_with section emetric open emetric variables [pseudo_emetric_space α] [pseudo_emetric_space β] [pseudo_emetric_space γ] variables {K : ℝ≥0} {f : α → β} {x y : α} {r : ℝ≥0∞} protected lemma lipschitz_on_with (h : lipschitz_with K f) (s : set α) : lipschitz_on_with K f s := λ x _ y _, h x y lemma edist_le_mul (h : lipschitz_with K f) (x y : α) : edist (f x) (f y) ≤ K * edist x y := h x y lemma edist_le_mul_of_le (h : lipschitz_with K f) (hr : edist x y ≤ r) : edist (f x) (f y) ≤ K * r := (h x y).trans $ ennreal.mul_left_mono hr lemma edist_lt_mul_of_lt (h : lipschitz_with K f) (hK : K ≠ 0) (hr : edist x y < r) : edist (f x) (f y) < K * r := (h x y).trans_lt $ (ennreal.mul_lt_mul_left (ennreal.coe_ne_zero.2 hK) ennreal.coe_ne_top).2 hr lemma maps_to_emetric_closed_ball (h : lipschitz_with K f) (x : α) (r : ℝ≥0∞) : maps_to f (closed_ball x r) (closed_ball (f x) (K * r)) := λ y hy, h.edist_le_mul_of_le hy lemma maps_to_emetric_ball (h : lipschitz_with K f) (hK : K ≠ 0) (x : α) (r : ℝ≥0∞) : maps_to f (ball x r) (ball (f x) (K * r)) := λ y hy, h.edist_lt_mul_of_lt hK hy lemma edist_lt_top (hf : lipschitz_with K f) {x y : α} (h : edist x y ≠ ⊤) : edist (f x) (f y) < ⊤ := (hf x y).trans_lt $ ennreal.mul_lt_top ennreal.coe_ne_top h lemma mul_edist_le (h : lipschitz_with K f) (x y : α) : (K⁻¹ : ℝ≥0∞) * edist (f x) (f y) ≤ edist x y := begin rw [mul_comm, ← div_eq_mul_inv], exact ennreal.div_le_of_le_mul' (h x y) end protected lemma of_edist_le (h : ∀ x y, edist (f x) (f y) ≤ edist x y) : lipschitz_with 1 f := λ x y, by simp only [ennreal.coe_one, one_mul, h] protected lemma weaken (hf : lipschitz_with K f) {K' : ℝ≥0} (h : K ≤ K') : lipschitz_with K' f := assume x y, le_trans (hf x y) $ ennreal.mul_right_mono (ennreal.coe_le_coe.2 h) lemma ediam_image_le (hf : lipschitz_with K f) (s : set α) : emetric.diam (f '' s) ≤ K * emetric.diam s := begin apply emetric.diam_le, rintros _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩, exact hf.edist_le_mul_of_le (emetric.edist_le_diam_of_mem hx hy) end lemma edist_lt_of_edist_lt_div (hf : lipschitz_with K f) {x y : α} {d : ℝ≥0∞} (h : edist x y < d / K) : edist (f x) (f y) < d := calc edist (f x) (f y) ≤ K * edist x y : hf x y ... < d : ennreal.mul_lt_of_lt_div' h /-- A Lipschitz function is uniformly continuous -/ protected lemma uniform_continuous (hf : lipschitz_with K f) : uniform_continuous f := begin refine emetric.uniform_continuous_iff.2 (λε εpos, _), use [ε / K, ennreal.div_pos_iff.2 ⟨ne_of_gt εpos, ennreal.coe_ne_top⟩], exact λ x y, hf.edist_lt_of_edist_lt_div end /-- A Lipschitz function is continuous -/ protected lemma continuous (hf : lipschitz_with K f) : continuous f := hf.uniform_continuous.continuous protected lemma const (b : β) : lipschitz_with 0 (λa:α, b) := assume x y, by simp only [edist_self, zero_le] protected lemma id : lipschitz_with 1 (@id α) := lipschitz_with.of_edist_le $ assume x y, le_rfl protected lemma subtype_val (s : set α) : lipschitz_with 1 (subtype.val : s → α) := lipschitz_with.of_edist_le $ assume x y, le_rfl protected lemma subtype_coe (s : set α) : lipschitz_with 1 (coe : s → α) := lipschitz_with.subtype_val s lemma subtype_mk (hf : lipschitz_with K f) {p : β → Prop} (hp : ∀ x, p (f x)) : lipschitz_with K (λ x, ⟨f x, hp x⟩ : α → {y // p y}) := hf protected lemma eval {α : ι → Type u} [Π i, pseudo_emetric_space (α i)] [fintype ι] (i : ι) : lipschitz_with 1 (function.eval i : (Π i, α i) → α i) := lipschitz_with.of_edist_le $ λ f g, by convert edist_le_pi_edist f g i protected lemma restrict (hf : lipschitz_with K f) (s : set α) : lipschitz_with K (s.restrict f) := λ x y, hf x y protected lemma comp {Kf Kg : ℝ≥0} {f : β → γ} {g : α → β} (hf : lipschitz_with Kf f) (hg : lipschitz_with Kg g) : lipschitz_with (Kf * Kg) (f ∘ g) := assume x y, calc edist (f (g x)) (f (g y)) ≤ Kf * edist (g x) (g y) : hf _ _ ... ≤ Kf * (Kg * edist x y) : ennreal.mul_left_mono (hg _ _) ... = (Kf * Kg : ℝ≥0) * edist x y : by rw [← mul_assoc, ennreal.coe_mul] lemma comp_lipschitz_on_with {Kf Kg : ℝ≥0} {f : β → γ} {g : α → β} {s : set α} (hf : lipschitz_with Kf f) (hg : lipschitz_on_with Kg g s) : lipschitz_on_with (Kf * Kg) (f ∘ g) s := lipschitz_on_with_iff_restrict.mpr $ hf.comp hg.to_restrict protected lemma prod_fst : lipschitz_with 1 (@prod.fst α β) := lipschitz_with.of_edist_le $ assume x y, le_max_left _ _ protected lemma prod_snd : lipschitz_with 1 (@prod.snd α β) := lipschitz_with.of_edist_le $ assume x y, le_max_right _ _ protected lemma prod {f : α → β} {Kf : ℝ≥0} (hf : lipschitz_with Kf f) {g : α → γ} {Kg : ℝ≥0} (hg : lipschitz_with Kg g) : lipschitz_with (max Kf Kg) (λ x, (f x, g x)) := begin assume x y, rw [ennreal.coe_mono.map_max, prod.edist_eq, ennreal.max_mul], exact max_le_max (hf x y) (hg x y) end protected lemma prod_mk_left (a : α) : lipschitz_with 1 (prod.mk a : β → α × β) := by simpa only [max_eq_right zero_le_one] using (lipschitz_with.const a).prod lipschitz_with.id protected lemma prod_mk_right (b : α) : lipschitz_with 1 (λ a : α, (a, b)) := by simpa only [max_eq_left zero_le_one] using lipschitz_with.id.prod (lipschitz_with.const b) protected lemma uncurry {f : α → β → γ} {Kα Kβ : ℝ≥0} (hα : ∀ b, lipschitz_with Kα (λ a, f a b)) (hβ : ∀ a, lipschitz_with Kβ (f a)) : lipschitz_with (Kα + Kβ) (function.uncurry f) := begin rintros ⟨a₁, b₁⟩ ⟨a₂, b₂⟩, simp only [function.uncurry, ennreal.coe_add, add_mul], apply le_trans (edist_triangle _ (f a₂ b₁) _), exact add_le_add (le_trans (hα _ _ _) $ ennreal.mul_left_mono $ le_max_left _ _) (le_trans (hβ _ _ _) $ ennreal.mul_left_mono $ le_max_right _ _) end protected lemma iterate {f : α → α} (hf : lipschitz_with K f) : ∀n, lipschitz_with (K ^ n) (f^[n]) | 0 := lipschitz_with.id | (n + 1) := by rw [pow_succ']; exact (iterate n).comp hf lemma edist_iterate_succ_le_geometric {f : α → α} (hf : lipschitz_with K f) (x n) : edist (f^[n] x) (f^[n + 1] x) ≤ edist x (f x) * K ^ n := begin rw [iterate_succ, mul_comm], simpa only [ennreal.coe_pow] using (hf.iterate n) x (f x) end protected lemma mul {f g : function.End α} {Kf Kg} (hf : lipschitz_with Kf f) (hg : lipschitz_with Kg g) : lipschitz_with (Kf * Kg) (f * g : function.End α) := hf.comp hg /-- The product of a list of Lipschitz continuous endomorphisms is a Lipschitz continuous endomorphism. -/ protected lemma list_prod (f : ι → function.End α) (K : ι → ℝ≥0) (h : ∀ i, lipschitz_with (K i) (f i)) : ∀ l : list ι, lipschitz_with (l.map K).prod (l.map f).prod | [] := by simpa using lipschitz_with.id | (i :: l) := by { simp only [list.map_cons, list.prod_cons], exact (h i).mul (list_prod l) } protected lemma pow {f : function.End α} {K} (h : lipschitz_with K f) : ∀ n : ℕ, lipschitz_with (K^n) (f^n : function.End α) | 0 := lipschitz_with.id | (n + 1) := by { rw [pow_succ, pow_succ], exact h.mul (pow n) } end emetric section metric variables [pseudo_metric_space α] [pseudo_metric_space β] [pseudo_metric_space γ] {K : ℝ≥0} {f : α → β} {x y : α} {r : ℝ} protected lemma of_dist_le' {K : ℝ} (h : ∀ x y, dist (f x) (f y) ≤ K * dist x y) : lipschitz_with (real.to_nnreal K) f := of_dist_le_mul $ λ x y, le_trans (h x y) $ mul_le_mul_of_nonneg_right (real.le_coe_to_nnreal K) dist_nonneg protected lemma mk_one (h : ∀ x y, dist (f x) (f y) ≤ dist x y) : lipschitz_with 1 f := of_dist_le_mul $ by simpa only [nnreal.coe_one, one_mul] using h /-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version doesn't assume `0≤K`. -/ protected lemma of_le_add_mul' {f : α → ℝ} (K : ℝ) (h : ∀x y, f x ≤ f y + K * dist x y) : lipschitz_with (real.to_nnreal K) f := have I : ∀ x y, f x - f y ≤ K * dist x y, from assume x y, sub_le_iff_le_add'.2 (h x y), lipschitz_with.of_dist_le' $ assume x y, abs_sub_le_iff.2 ⟨I x y, dist_comm y x ▸ I y x⟩ /-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version assumes `0≤K`. -/ protected lemma of_le_add_mul {f : α → ℝ} (K : ℝ≥0) (h : ∀x y, f x ≤ f y + K * dist x y) : lipschitz_with K f := by simpa only [real.to_nnreal_coe] using lipschitz_with.of_le_add_mul' K h protected lemma of_le_add {f : α → ℝ} (h : ∀ x y, f x ≤ f y + dist x y) : lipschitz_with 1 f := lipschitz_with.of_le_add_mul 1 $ by simpa only [nnreal.coe_one, one_mul] protected lemma le_add_mul {f : α → ℝ} {K : ℝ≥0} (h : lipschitz_with K f) (x y) : f x ≤ f y + K * dist x y := sub_le_iff_le_add'.1 $ le_trans (le_abs_self _) $ h.dist_le_mul x y protected lemma iff_le_add_mul {f : α → ℝ} {K : ℝ≥0} : lipschitz_with K f ↔ ∀ x y, f x ≤ f y + K * dist x y := ⟨lipschitz_with.le_add_mul, lipschitz_with.of_le_add_mul K⟩ lemma nndist_le (hf : lipschitz_with K f) (x y : α) : nndist (f x) (f y) ≤ K * nndist x y := hf.dist_le_mul x y lemma dist_le_mul_of_le (hf : lipschitz_with K f) (hr : dist x y ≤ r) : dist (f x) (f y) ≤ K * r := (hf.dist_le_mul x y).trans $ mul_le_mul_of_nonneg_left hr K.coe_nonneg lemma maps_to_closed_ball (hf : lipschitz_with K f) (x : α) (r : ℝ) : maps_to f (metric.closed_ball x r) (metric.closed_ball (f x) (K * r)) := λ y hy, hf.dist_le_mul_of_le hy lemma dist_lt_mul_of_lt (hf : lipschitz_with K f) (hK : K ≠ 0) (hr : dist x y < r) : dist (f x) (f y) < K * r := (hf.dist_le_mul x y).trans_lt $ (mul_lt_mul_left $ nnreal.coe_pos.2 hK.bot_lt).2 hr lemma maps_to_ball (hf : lipschitz_with K f) (hK : K ≠ 0) (x : α) (r : ℝ) : maps_to f (metric.ball x r) (metric.ball (f x) (K * r)) := λ y hy, hf.dist_lt_mul_of_lt hK hy /-- A Lipschitz continuous map is a locally bounded map. -/ def to_locally_bounded_map (f : α → β) (hf : lipschitz_with K f) : locally_bounded_map α β := locally_bounded_map.of_map_bounded f $ λ s hs, let ⟨C, hC⟩ := metric.is_bounded_iff.1 hs in metric.is_bounded_iff.2 ⟨K * C, ball_image_iff.2 $ λ x hx, ball_image_iff.2 $ λ y hy, hf.dist_le_mul_of_le (hC hx hy)⟩ @[simp] lemma coe_to_locally_bounded_map (hf : lipschitz_with K f) : ⇑(hf.to_locally_bounded_map f) = f := rfl lemma comap_cobounded_le (hf : lipschitz_with K f) : comap f (bornology.cobounded β) ≤ bornology.cobounded α := (hf.to_locally_bounded_map f).2 lemma bounded_image (hf : lipschitz_with K f) {s : set α} (hs : metric.bounded s) : metric.bounded (f '' s) := metric.bounded_iff_ediam_ne_top.2 $ ne_top_of_le_ne_top (ennreal.mul_ne_top ennreal.coe_ne_top hs.ediam_ne_top) (hf.ediam_image_le s) lemma diam_image_le (hf : lipschitz_with K f) (s : set α) (hs : metric.bounded s) : metric.diam (f '' s) ≤ K * metric.diam s := metric.diam_le_of_forall_dist_le (mul_nonneg K.coe_nonneg metric.diam_nonneg) $ ball_image_iff.2 $ λ x hx, ball_image_iff.2 $ λ y hy, hf.dist_le_mul_of_le $ metric.dist_le_diam_of_mem hs hx hy protected lemma dist_left (y : α) : lipschitz_with 1 (λ x, dist x y) := lipschitz_with.of_le_add $ assume x z, by { rw [add_comm], apply dist_triangle } protected lemma dist_right (x : α) : lipschitz_with 1 (dist x) := lipschitz_with.of_le_add $ assume y z, dist_triangle_right _ _ _ protected lemma dist : lipschitz_with 2 (function.uncurry $ @dist α _) := lipschitz_with.uncurry lipschitz_with.dist_left lipschitz_with.dist_right lemma dist_iterate_succ_le_geometric {f : α → α} (hf : lipschitz_with K f) (x n) : dist (f^[n] x) (f^[n + 1] x) ≤ dist x (f x) * K ^ n := begin rw [iterate_succ, mul_comm], simpa only [nnreal.coe_pow] using (hf.iterate n).dist_le_mul x (f x) end lemma _root_.lipschitz_with_max : lipschitz_with 1 (λ p : ℝ × ℝ, max p.1 p.2) := lipschitz_with.of_le_add $ λ p₁ p₂, sub_le_iff_le_add'.1 $ (le_abs_self _).trans (abs_max_sub_max_le_max _ _ _ _) lemma _root_.lipschitz_with_min : lipschitz_with 1 (λ p : ℝ × ℝ, min p.1 p.2) := lipschitz_with.of_le_add $ λ p₁ p₂, sub_le_iff_le_add'.1 $ (le_abs_self _).trans (abs_min_sub_min_le_max _ _ _ _) end metric section emetric variables {α} [pseudo_emetric_space α] {f g : α → ℝ} {Kf Kg : ℝ≥0} protected lemma max (hf : lipschitz_with Kf f) (hg : lipschitz_with Kg g) : lipschitz_with (max Kf Kg) (λ x, max (f x) (g x)) := by simpa only [(∘), one_mul] using lipschitz_with_max.comp (hf.prod hg) protected lemma min (hf : lipschitz_with Kf f) (hg : lipschitz_with Kg g) : lipschitz_with (max Kf Kg) (λ x, min (f x) (g x)) := by simpa only [(∘), one_mul] using lipschitz_with_min.comp (hf.prod hg) lemma max_const (hf : lipschitz_with Kf f) (a : ℝ) : lipschitz_with Kf (λ x, max (f x) a) := by simpa only [max_eq_left (zero_le Kf)] using hf.max (lipschitz_with.const a) lemma const_max (hf : lipschitz_with Kf f) (a : ℝ) : lipschitz_with Kf (λ x, max a (f x)) := by simpa only [max_comm] using hf.max_const a lemma min_const (hf : lipschitz_with Kf f) (a : ℝ) : lipschitz_with Kf (λ x, min (f x) a) := by simpa only [max_eq_left (zero_le Kf)] using hf.min (lipschitz_with.const a) lemma const_min (hf : lipschitz_with Kf f) (a : ℝ) : lipschitz_with Kf (λ x, min a (f x)) := by simpa only [min_comm] using hf.min_const a end emetric protected lemma proj_Icc {a b : ℝ} (h : a ≤ b) : lipschitz_with 1 (proj_Icc a b h) := ((lipschitz_with.id.const_min _).const_max _).subtype_mk _ end lipschitz_with namespace metric variables [pseudo_metric_space α] [pseudo_metric_space β] {s : set α} {t : set β} lemma bounded.left_of_prod (h : bounded (s ×ˢ t)) (ht : t.nonempty) : bounded s := by simpa only [fst_image_prod s ht] using (@lipschitz_with.prod_fst α β _ _).bounded_image h lemma bounded.right_of_prod (h : bounded (s ×ˢ t)) (hs : s.nonempty) : bounded t := by simpa only [snd_image_prod hs t] using (@lipschitz_with.prod_snd α β _ _).bounded_image h lemma bounded_prod_of_nonempty (hs : s.nonempty) (ht : t.nonempty) : bounded (s ×ˢ t) ↔ bounded s ∧ bounded t := ⟨λ h, ⟨h.left_of_prod ht, h.right_of_prod hs⟩, λ h, h.1.prod h.2⟩ lemma bounded_prod : bounded (s ×ˢ t) ↔ s = ∅ ∨ t = ∅ ∨ bounded s ∧ bounded t := begin rcases s.eq_empty_or_nonempty with rfl|hs, { simp }, rcases t.eq_empty_or_nonempty with rfl|ht, { simp }, simp only [bounded_prod_of_nonempty hs ht, hs.ne_empty, ht.ne_empty, false_or] end end metric namespace lipschitz_on_with section emetric variables [pseudo_emetric_space α] [pseudo_emetric_space β] [pseudo_emetric_space γ] variables {K : ℝ≥0} {s : set α} {f : α → β} protected lemma uniform_continuous_on (hf : lipschitz_on_with K f s) : uniform_continuous_on f s := uniform_continuous_on_iff_restrict.mpr (lipschitz_on_with_iff_restrict.mp hf).uniform_continuous protected lemma continuous_on (hf : lipschitz_on_with K f s) : continuous_on f s := hf.uniform_continuous_on.continuous_on lemma edist_lt_of_edist_lt_div (hf : lipschitz_on_with K f s) {x y : α} (hx : x ∈ s) (hy : y ∈ s) {d : ℝ≥0∞} (hd : edist x y < d / K) : edist (f x) (f y) < d := (lipschitz_on_with_iff_restrict.mp hf).edist_lt_of_edist_lt_div $ show edist (⟨x, hx⟩ : s) ⟨y, hy⟩ < d / K, from hd protected lemma comp {g : β → γ} {t : set β} {Kg : ℝ≥0} (hg : lipschitz_on_with Kg g t) (hf : lipschitz_on_with K f s) (hmaps : maps_to f s t) : lipschitz_on_with (Kg * K) (g ∘ f) s := lipschitz_on_with_iff_restrict.mpr $ hg.to_restrict.comp (hf.to_restrict_maps_to hmaps) end emetric section metric variables [pseudo_metric_space α] [pseudo_metric_space β] [pseudo_metric_space γ] variables {K : ℝ≥0} {s : set α} {f : α → β} protected lemma of_dist_le' {K : ℝ} (h : ∀ (x ∈ s) (y ∈ s), dist (f x) (f y) ≤ K * dist x y) : lipschitz_on_with (real.to_nnreal K) f s := of_dist_le_mul $ λ x hx y hy, le_trans (h x hx y hy) $ mul_le_mul_of_nonneg_right (real.le_coe_to_nnreal K) dist_nonneg protected lemma mk_one (h : ∀ (x ∈ s) (y ∈ s), dist (f x) (f y) ≤ dist x y) : lipschitz_on_with 1 f s := of_dist_le_mul $ by simpa only [nnreal.coe_one, one_mul] using h /-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version doesn't assume `0≤K`. -/ protected lemma of_le_add_mul' {f : α → ℝ} (K : ℝ) (h : ∀ (x ∈ s) (y ∈ s), f x ≤ f y + K * dist x y) : lipschitz_on_with (real.to_nnreal K) f s := have I : ∀ (x ∈ s) (y ∈ s), f x - f y ≤ K * dist x y, from assume x hx y hy, sub_le_iff_le_add'.2 (h x hx y hy), lipschitz_on_with.of_dist_le' $ assume x hx y hy, abs_sub_le_iff.2 ⟨I x hx y hy, dist_comm y x ▸ I y hy x hx⟩ /-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version assumes `0≤K`. -/ protected lemma of_le_add_mul {f : α → ℝ} (K : ℝ≥0) (h : ∀ (x ∈ s) (y ∈ s), f x ≤ f y + K * dist x y) : lipschitz_on_with K f s := by simpa only [real.to_nnreal_coe] using lipschitz_on_with.of_le_add_mul' K h protected lemma of_le_add {f : α → ℝ} (h : ∀ (x ∈ s) (y ∈ s), f x ≤ f y + dist x y) : lipschitz_on_with 1 f s := lipschitz_on_with.of_le_add_mul 1 $ by simpa only [nnreal.coe_one, one_mul] protected lemma le_add_mul {f : α → ℝ} {K : ℝ≥0} (h : lipschitz_on_with K f s) {x : α} (hx : x ∈ s) {y : α} (hy : y ∈ s) : f x ≤ f y + K * dist x y := sub_le_iff_le_add'.1 $ le_trans (le_abs_self _) $ h.dist_le_mul x hx y hy protected lemma iff_le_add_mul {f : α → ℝ} {K : ℝ≥0} : lipschitz_on_with K f s ↔ ∀ (x ∈ s) (y ∈ s), f x ≤ f y + K * dist x y := ⟨lipschitz_on_with.le_add_mul, lipschitz_on_with.of_le_add_mul K⟩ end metric end lipschitz_on_with /-- Consider a function `f : α × β → γ`. Suppose that it is continuous on each “vertical fiber” `{a} × t`, `a ∈ s`, and is Lipschitz continuous on each “horizontal fiber” `s × {b}`, `b ∈ t` with the same Lipschitz constant `K`. Then it is continuous on `s × t`. The actual statement uses (Lipschitz) continuity of `λ y, f (a, y)` and `λ x, f (x, b)` instead of continuity of `f` on subsets of the product space. -/ lemma continuous_on_prod_of_continuous_on_lipschitz_on [pseudo_emetric_space α] [topological_space β] [pseudo_emetric_space γ] (f : α × β → γ) {s : set α} {t : set β} (K : ℝ≥0) (ha : ∀ a ∈ s, continuous_on (λ y, f (a, y)) t) (hb : ∀ b ∈ t, lipschitz_on_with K (λ x, f (x, b)) s) : continuous_on f (s ×ˢ t) := begin rintro ⟨x, y⟩ ⟨hx : x ∈ s, hy : y ∈ t⟩, refine emetric.tendsto_nhds.2 (λ ε (ε0 : 0 < ε), _), replace ε0 : 0 < ε / 2 := ennreal.half_pos (ne_of_gt ε0), have εK : 0 < ε / 2 / K := ennreal.div_pos_iff.2 ⟨ε0.ne', ennreal.coe_ne_top⟩, have A : s ∩ emetric.ball x (ε / 2 / K) ∈ 𝓝[s] x := inter_mem_nhds_within _ (emetric.ball_mem_nhds _ εK), have B : {b : β | b ∈ t ∧ edist (f (x, b)) (f (x, y)) < ε / 2} ∈ 𝓝[t] y := inter_mem self_mem_nhds_within (ha x hx y hy (emetric.ball_mem_nhds _ ε0)), filter_upwards [nhds_within_prod A B], rintro ⟨a, b⟩ ⟨⟨has : a ∈ s, hax : edist a x < ε / 2 / K⟩, hbt : b ∈ t, hby : edist (f (x, b)) (f (x, y)) < ε / 2⟩, calc edist (f (a, b)) (f (x, y)) ≤ edist (f (a, b)) (f (x, b)) + edist (f (x, b)) (f (x, y)) : edist_triangle _ _ _ ... < ε / 2 + ε / 2 : ennreal.add_lt_add ((hb _ hbt).edist_lt_of_edist_lt_div has hx hax) hby ... = ε : ennreal.add_halves ε end /-- Consider a function `f : α × β → γ`. Suppose that it is continuous on each “vertical section” `{a} × univ`, `a : α`, and is Lipschitz continuous on each “horizontal section” `univ × {b}`, `b : β` with the same Lipschitz constant `K`. Then it is continuous. The actual statement uses (Lipschitz) continuity of `λ y, f (a, y)` and `λ x, f (x, b)` instead of continuity of `f` on subsets of the product space. -/ lemma continuous_prod_of_continuous_lipschitz [pseudo_emetric_space α] [topological_space β] [pseudo_emetric_space γ] (f : α × β → γ) (K : ℝ≥0) (ha : ∀ a, continuous (λ y, f (a, y))) (hb : ∀ b, lipschitz_with K (λ x, f (x, b))) : continuous f := begin simp only [continuous_iff_continuous_on_univ, ← univ_prod_univ, ← lipschitz_on_univ] at *, exact continuous_on_prod_of_continuous_on_lipschitz_on f K (λ a _, ha a) (λ b _, hb b) end open metric /-- If a function is locally Lipschitz around a point, then it is continuous at this point. -/ lemma continuous_at_of_locally_lipschitz [pseudo_metric_space α] [pseudo_metric_space β] {f : α → β} {x : α} {r : ℝ} (hr : 0 < r) (K : ℝ) (h : ∀ y, dist y x < r → dist (f y) (f x) ≤ K * dist y x) : continuous_at f x := begin -- We use `h` to squeeze `dist (f y) (f x)` between `0` and `K * dist y x` refine tendsto_iff_dist_tendsto_zero.2 (squeeze_zero' (eventually_of_forall $ λ _, dist_nonneg) (mem_of_superset (ball_mem_nhds _ hr) h) _), -- Then show that `K * dist y x` tends to zero as `y → x` refine (continuous_const.mul (continuous_id.dist continuous_const)).tendsto' _ _ _, simp end /-- A function `f : α → ℝ` which is `K`-Lipschitz on a subset `s` admits a `K`-Lipschitz extension to the whole space. -/ lemma lipschitz_on_with.extend_real [pseudo_metric_space α] {f : α → ℝ} {s : set α} {K : ℝ≥0} (hf : lipschitz_on_with K f s) : ∃ g : α → ℝ, lipschitz_with K g ∧ eq_on f g s := begin /- An extension is given by `g y = Inf {f x + K * dist y x | x ∈ s}`. Taking `x = y`, one has `g y ≤ f y` for `y ∈ s`, and the other inequality holds because `f` is `K`-Lipschitz, so that it can not counterbalance the growth of `K * dist y x`. One readily checks from the formula that the extended function is also `K`-Lipschitz. -/ rcases eq_empty_or_nonempty s with rfl|hs, { exact ⟨λ x, 0, (lipschitz_with.const _).weaken (zero_le _), eq_on_empty _ _⟩ }, haveI : nonempty s, by simp only [hs, nonempty_coe_sort], let g := λ (y : α), infi (λ (x : s), f x + K * dist y x), have B : ∀ (y : α), bdd_below (range (λ (x : s), f x + K * dist y x)), { assume y, rcases hs with ⟨z, hz⟩, refine ⟨f z - K * dist y z, _⟩, rintros w ⟨t, rfl⟩, dsimp, rw [sub_le_iff_le_add, add_assoc, ← mul_add, add_comm (dist y t)], calc f z ≤ f t + K * dist z t : hf.le_add_mul hz t.2 ... ≤ f t + K * (dist y z + dist y t) : add_le_add_left (mul_le_mul_of_nonneg_left (dist_triangle_left _ _ _) K.2) _ }, have E : eq_on f g s, { assume x hx, refine le_antisymm (le_cinfi (λ y, hf.le_add_mul hx y.2)) _, simpa only [add_zero, subtype.coe_mk, mul_zero, dist_self] using cinfi_le (B x) ⟨x, hx⟩ }, refine ⟨g, lipschitz_with.of_le_add_mul K (λ x y, _), E⟩, rw ← sub_le_iff_le_add, refine le_cinfi (λ z, _), rw sub_le_iff_le_add, calc g x ≤ f z + K * dist x z : cinfi_le (B x) _ ... ≤ f z + K * dist y z + K * dist x y : begin rw [add_assoc, ← mul_add, add_comm (dist y z)], exact add_le_add_left (mul_le_mul_of_nonneg_left (dist_triangle _ _ _) K.2) _, end end /-- A function `f : α → (ι → ℝ)` which is `K`-Lipschitz on a subset `s` admits a `K`-Lipschitz extension to the whole space. TODO: state the same result (with the same proof) for the space `ℓ^∞ (ι, ℝ)` over a possibly infinite type `ι`. -/ lemma lipschitz_on_with.extend_pi [pseudo_metric_space α] [fintype ι] {f : α → (ι → ℝ)} {s : set α} {K : ℝ≥0} (hf : lipschitz_on_with K f s) : ∃ g : α → (ι → ℝ), lipschitz_with K g ∧ eq_on f g s := begin have : ∀ i, ∃ g : α → ℝ, lipschitz_with K g ∧ eq_on (λ x, f x i) g s, { assume i, have : lipschitz_on_with K (λ (x : α), f x i) s, { apply lipschitz_on_with.of_dist_le_mul (λ x hx y hy, _), exact (dist_le_pi_dist _ _ i).trans (hf.dist_le_mul x hx y hy) }, exact this.extend_real }, choose g hg using this, refine ⟨λ x i, g i x, lipschitz_with.of_dist_le_mul (λ x y, _), _⟩, { exact (dist_pi_le_iff (mul_nonneg K.2 dist_nonneg)).2 (λ i, (hg i).1.dist_le_mul x y) }, { assume x hx, ext1 i, exact (hg i).2 hx } end