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
4acb361018aa6ab9953411bd93098834d939048b
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/test/continuity.lean
83db43cae46f78c3cf27216f1359fcea56eea65d
[ "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
1,855
lean
import topology.tactic import topology.algebra.monoid import topology.instances.real import analysis.special_functions.trigonometric example {X Y : Type*} [topological_space X] [topological_space Y] (f₁ fβ‚‚ : X β†’ Y) (hf₁ : continuous f₁) (hfβ‚‚ : continuous fβ‚‚) (g : Y β†’ ℝ) (hg : continuous g) : continuous (Ξ» x, (max (g (f₁ x)) (g (fβ‚‚ x))) + 1) := by guard_proof_term { continuity } ((hg.comp hf₁).max (hg.comp hfβ‚‚)).add continuous_const example {ΞΊ ΞΉ : Type} (K : ΞΊ β†’ Type) [βˆ€ k, topological_space (K k)] (I : ΞΉ β†’ Type) [βˆ€ i, topological_space (I i)] (e : ΞΊ ≃ ΞΉ) (F : Ξ  k, homeomorph (K k) (I (e k))) : continuous (Ξ» (f : Ξ  k, K k) (i : ΞΉ), F (e.symm i) (f (e.symm i))) := by guard_proof_term { continuity } @continuous_pi _ _ _ _ _ (Ξ» (f : Ξ  k, K k) i, (F (e.symm i)) (f (e.symm i))) (Ξ» (i : ΞΉ), ((F (e.symm i)).continuous).comp (continuous_apply (e.symm i))) open real local attribute [continuity] continuous_exp continuous_sin continuous_cos example : continuous (Ξ» x : ℝ, exp ((max x (-x)) + sin x)^2) := by guard_proof_term { continuity } (continuous_exp.comp ((continuous_id.max continuous_id.neg).add continuous_sin)).pow 2 example : continuous (Ξ» x : ℝ, exp ((max x (-x)) + sin (cos x))^2) := by guard_proof_term { continuity } (continuous_exp.comp ((continuous_id'.max continuous_id'.neg).add (continuous_sin.comp continuous_cos))).pow 2 -- Without `md := semireducible` in the call to `apply_rules` in `continuity`, -- this last example would have run off the rails: -- ``` -- example : continuous (Ξ» x : ℝ, exp ((max x (-x)) + sin (cos x))^2) := -- by show_term { continuity! } -- ``` -- produces lots of subgoals, including many copies of -- ⊒ continuous complex.re -- ⊒ continuous complex.exp -- ⊒ continuous coe -- ⊒ continuous (Ξ» (x : ℝ), ↑x)
da1de3ccc503d15b47eda8f373d6134ea8f8bdc9
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
/src/analysis/complex/basic.lean
1b7f3331db0ee7220121933b6523a24feb671e3c
[ "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
8,435
lean
/- Copyright (c) SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel -/ import analysis.calculus.deriv import analysis.normed_space.finite_dimension /-! # Normed space structure on `β„‚`. This file gathers basic facts on complex numbers of an analytic nature. ## Main results This file registers `β„‚` as a normed field, expresses basic properties of the norm, and gives tools on the real vector space structure of `β„‚`. Notably, in the namespace `complex`, it defines functions: * `linear_map.re` * `continuous_linear_map.re` * `linear_map.im` * `continuous_linear_map.im` * `linear_map.of_real` * `continuous_linear_map.of_real` They are bundled versions of the real part, the imaginary part, and the embedding of `ℝ` in `β„‚`, as `ℝ`-linear maps. `has_deriv_at_real_of_complex` expresses that, if a function on `β„‚` is differentiable (over `β„‚`), then its restriction to `ℝ` is differentiable over `ℝ`, with derivative the real part of the complex derivative. -/ noncomputable theory namespace complex instance : normed_field β„‚ := { norm := abs, dist_eq := Ξ» _ _, rfl, norm_mul' := abs_mul, .. complex.field } instance : nondiscrete_normed_field β„‚ := { non_trivial := ⟨2, by simp [norm]; norm_num⟩ } instance normed_algebra_over_reals : normed_algebra ℝ β„‚ := { norm_algebra_map_eq := abs_of_real, ..complex.algebra_over_reals } @[simp] lemma norm_eq_abs (z : β„‚) : βˆ₯zβˆ₯ = abs z := rfl @[simp] lemma norm_real (r : ℝ) : βˆ₯(r : β„‚)βˆ₯ = βˆ₯rβˆ₯ := abs_of_real _ @[simp] lemma norm_rat (r : β„š) : βˆ₯(r : β„‚)βˆ₯ = _root_.abs (r : ℝ) := suffices βˆ₯((r : ℝ) : β„‚)βˆ₯ = _root_.abs r, by simpa, by rw [norm_real, real.norm_eq_abs] @[simp] lemma norm_nat (n : β„•) : βˆ₯(n : β„‚)βˆ₯ = n := abs_of_nat _ @[simp] lemma norm_int {n : β„€} : βˆ₯(n : β„‚)βˆ₯ = _root_.abs n := suffices βˆ₯((n : ℝ) : β„‚)βˆ₯ = _root_.abs n, by simpa, by rw [norm_real, real.norm_eq_abs] lemma norm_int_of_nonneg {n : β„€} (hn : 0 ≀ n) : βˆ₯(n : β„‚)βˆ₯ = n := by rw [norm_int, _root_.abs_of_nonneg]; exact int.cast_nonneg.2 hn /-- Over the complex numbers, any finite-dimensional spaces is proper (and therefore complete). We can register this as an instance, as it will not cause problems in instance resolution since the properness of `β„‚` is already known and there is no metavariable. -/ instance finite_dimensional.proper (E : Type) [normed_group E] [normed_space β„‚ E] [finite_dimensional β„‚ E] : proper_space E := finite_dimensional.proper β„‚ E attribute [instance, priority 900] complex.finite_dimensional.proper /-- A complex normed vector space is also a real normed vector space. -/ instance normed_space.restrict_scalars_real (E : Type*) [normed_group E] [normed_space β„‚ E] : normed_space ℝ E := normed_space.restrict_scalars ℝ β„‚ attribute [instance, priority 900] complex.normed_space.restrict_scalars_real /-- Linear map version of the real part function, from `β„‚` to `ℝ`. -/ def linear_map.re : β„‚ β†’β‚—[ℝ] ℝ := { to_fun := Ξ»x, x.re, map_add' := by simp, map_smul' := Ξ»c x, by { change ((c : β„‚) * x).re = c * x.re, simp } } @[simp] lemma linear_map.re_apply (z : β„‚) : linear_map.re z = z.re := rfl /-- Continuous linear map version of the real part function, from `β„‚` to `ℝ`. -/ def continuous_linear_map.re : β„‚ β†’L[ℝ] ℝ := linear_map.re.mk_continuous 1 $ Ξ»x, begin change _root_.abs (x.re) ≀ 1 * abs x, rw one_mul, exact abs_re_le_abs x end @[simp] lemma continuous_linear_map.re_coe : (coe (continuous_linear_map.re) : β„‚ β†’β‚—[ℝ] ℝ) = linear_map.re := rfl @[simp] lemma continuous_linear_map.re_apply (z : β„‚) : (continuous_linear_map.re : β„‚ β†’ ℝ) z = z.re := rfl @[simp] lemma continuous_linear_map.re_norm : βˆ₯continuous_linear_map.reβˆ₯ = 1 := begin apply le_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _), calc 1 = βˆ₯continuous_linear_map.re (1 : β„‚)βˆ₯ : by simp ... ≀ βˆ₯continuous_linear_map.reβˆ₯ : by { apply continuous_linear_map.unit_le_op_norm, simp } end /-- Linear map version of the imaginary part function, from `β„‚` to `ℝ`. -/ def linear_map.im : β„‚ β†’β‚—[ℝ] ℝ := { to_fun := Ξ»x, x.im, map_add' := by simp, map_smul' := Ξ»c x, by { change ((c : β„‚) * x).im = c * x.im, simp } } @[simp] lemma linear_map.im_apply (z : β„‚) : linear_map.im z = z.im := rfl /-- Continuous linear map version of the real part function, from `β„‚` to `ℝ`. -/ def continuous_linear_map.im : β„‚ β†’L[ℝ] ℝ := linear_map.im.mk_continuous 1 $ Ξ»x, begin change _root_.abs (x.im) ≀ 1 * abs x, rw one_mul, exact complex.abs_im_le_abs x end @[simp] lemma continuous_linear_map.im_coe : (coe (continuous_linear_map.im) : β„‚ β†’β‚—[ℝ] ℝ) = linear_map.im := rfl @[simp] lemma continuous_linear_map.im_apply (z : β„‚) : (continuous_linear_map.im : β„‚ β†’ ℝ) z = z.im := rfl @[simp] lemma continuous_linear_map.im_norm : βˆ₯continuous_linear_map.imβˆ₯ = 1 := begin apply le_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _), calc 1 = βˆ₯continuous_linear_map.im (I : β„‚)βˆ₯ : by simp ... ≀ βˆ₯continuous_linear_map.imβˆ₯ : by { apply continuous_linear_map.unit_le_op_norm, rw ← abs_I, exact le_refl _ } end /-- Linear map version of the canonical embedding of `ℝ` in `β„‚`. -/ def linear_map.of_real : ℝ β†’β‚—[ℝ] β„‚ := { to_fun := Ξ»x, of_real x, map_add' := by simp, map_smul' := Ξ»c x, by { simp, refl } } @[simp] lemma linear_map.of_real_apply (x : ℝ) : linear_map.of_real x = x := rfl /-- Continuous linear map version of the canonical embedding of `ℝ` in `β„‚`. -/ def continuous_linear_map.of_real : ℝ β†’L[ℝ] β„‚ := linear_map.of_real.mk_continuous 1 $ Ξ»x, by simp @[simp] lemma continuous_linear_map.of_real_coe : (coe (continuous_linear_map.of_real) : ℝ β†’β‚—[ℝ] β„‚) = linear_map.of_real := rfl @[simp] lemma continuous_linear_map.of_real_apply (x : ℝ) : (continuous_linear_map.of_real : ℝ β†’ β„‚) x = x := rfl @[simp] lemma continuous_linear_map.of_real_norm : βˆ₯continuous_linear_map.of_realβˆ₯ = 1 := begin apply le_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _), calc 1 = βˆ₯continuous_linear_map.of_real (1 : ℝ)βˆ₯ : by simp ... ≀ βˆ₯continuous_linear_map.of_realβˆ₯ : by { apply continuous_linear_map.unit_le_op_norm, simp } end lemma continuous_linear_map.of_real_isometry : isometry continuous_linear_map.of_real := continuous_linear_map.isometry_iff_norm_image_eq_norm.2 (Ξ»x, by simp) end complex section real_deriv_of_complex /-! ### Differentiability of the restriction to `ℝ` of complex functions -/ open complex variables {e : β„‚ β†’ β„‚} {e' : β„‚} {z : ℝ} /-- A preliminary lemma for `has_deriv_at_real_of_complex`, which we only separate out to keep the maximum compile time per declaration low. -/ lemma has_deriv_at_real_of_complex_aux (h : has_deriv_at e e' z) : has_deriv_at (⇑continuous_linear_map.re ∘ Ξ» {z : ℝ}, e (continuous_linear_map.of_real z)) (((continuous_linear_map.re.comp ((continuous_linear_map.smul_right (1 : β„‚ β†’L[β„‚] β„‚) e').restrict_scalars ℝ)).comp continuous_linear_map.of_real) (1 : ℝ)) z := begin have A : has_fderiv_at continuous_linear_map.of_real continuous_linear_map.of_real z := continuous_linear_map.of_real.has_fderiv_at, have B : has_fderiv_at e ((continuous_linear_map.smul_right 1 e' : β„‚ β†’L[β„‚] β„‚).restrict_scalars ℝ) (continuous_linear_map.of_real z) := (has_deriv_at_iff_has_fderiv_at.1 h).restrict_scalars ℝ, have C : has_fderiv_at continuous_linear_map.re continuous_linear_map.re (e (continuous_linear_map.of_real z)) := continuous_linear_map.re.has_fderiv_at, exact has_fderiv_at_iff_has_deriv_at.1 (C.comp z (B.comp z A)), end /-- If a complex function is differentiable at a real point, then the induced real function is also differentiable at this point, with a derivative equal to the real part of the complex derivative. -/ theorem has_deriv_at_real_of_complex (h : has_deriv_at e e' z) : has_deriv_at (Ξ»x:ℝ, (e x).re) e'.re z := begin rw (show (Ξ»x:ℝ, (e x).re) = (continuous_linear_map.re : β„‚ β†’ ℝ) ∘ e ∘ (continuous_linear_map.of_real : ℝ β†’ β„‚), by { ext x, refl }), simpa using has_deriv_at_real_of_complex_aux h, end end real_deriv_of_complex
33828c3d7a3494073f464118ef55d789d1d050ce
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/analysis/special_functions/log/deriv.lean
434ae117622d454dc14d88e30944d5fac94df430
[ "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
12,635
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 -/ import analysis.special_functions.log.basic import analysis.special_functions.exp_deriv /-! # Derivative and series expansion of real logarithm In this file we prove that `real.log` is infinitely smooth at all nonzero `x : ℝ`. We also prove that the series `βˆ‘' n : β„•, x ^ (n + 1) / (n + 1)` converges to `(-real.log (1 - x))` for all `x : ℝ`, `|x| < 1`. ## Tags logarithm, derivative -/ open filter finset set open_locale topological_space big_operators namespace real variables {x : ℝ} lemma has_strict_deriv_at_log_of_pos (hx : 0 < x) : has_strict_deriv_at log x⁻¹ x := have has_strict_deriv_at log (exp $ log x)⁻¹ x, from (has_strict_deriv_at_exp $ log x).of_local_left_inverse (continuous_at_log hx.ne') (ne_of_gt $ exp_pos _) $ eventually.mono (lt_mem_nhds hx) @exp_log, by rwa [exp_log hx] at this lemma has_strict_deriv_at_log (hx : x β‰  0) : has_strict_deriv_at log x⁻¹ x := begin cases hx.lt_or_lt with hx hx, { convert (has_strict_deriv_at_log_of_pos (neg_pos.mpr hx)).comp x (has_strict_deriv_at_neg x), { ext y, exact (log_neg_eq_log y).symm }, { field_simp [hx.ne] } }, { exact has_strict_deriv_at_log_of_pos hx } end lemma has_deriv_at_log (hx : x β‰  0) : has_deriv_at log x⁻¹ x := (has_strict_deriv_at_log hx).has_deriv_at lemma differentiable_at_log (hx : x β‰  0) : differentiable_at ℝ log x := (has_deriv_at_log hx).differentiable_at lemma differentiable_on_log : differentiable_on ℝ log {0}ᢜ := Ξ» x hx, (differentiable_at_log hx).differentiable_within_at @[simp] lemma differentiable_at_log_iff : differentiable_at ℝ log x ↔ x β‰  0 := ⟨λ h, continuous_at_log_iff.1 h.continuous_at, differentiable_at_log⟩ lemma deriv_log (x : ℝ) : deriv log x = x⁻¹ := if hx : x = 0 then by rw [deriv_zero_of_not_differentiable_at (mt differentiable_at_log_iff.1 (not_not.2 hx)), hx, inv_zero] else (has_deriv_at_log hx).deriv @[simp] lemma deriv_log' : deriv log = has_inv.inv := funext deriv_log lemma cont_diff_on_log {n : β„•βˆž} : cont_diff_on ℝ n log {0}ᢜ := begin suffices : cont_diff_on ℝ ⊀ log {0}ᢜ, from this.of_le le_top, refine (cont_diff_on_top_iff_deriv_of_open is_open_compl_singleton).2 _, simp [differentiable_on_log, cont_diff_on_inv] end lemma cont_diff_at_log {n : β„•βˆž} : cont_diff_at ℝ n log x ↔ x β‰  0 := ⟨λ h, continuous_at_log_iff.1 h.continuous_at, Ξ» hx, (cont_diff_on_log x hx).cont_diff_at $ is_open.mem_nhds is_open_compl_singleton hx⟩ end real section log_differentiable open real section deriv variables {f : ℝ β†’ ℝ} {x f' : ℝ} {s : set ℝ} lemma has_deriv_within_at.log (hf : has_deriv_within_at f f' s x) (hx : f x β‰  0) : has_deriv_within_at (Ξ» y, log (f y)) (f' / (f x)) s x := begin rw div_eq_inv_mul, exact (has_deriv_at_log hx).comp_has_deriv_within_at x hf end lemma has_deriv_at.log (hf : has_deriv_at f f' x) (hx : f x β‰  0) : has_deriv_at (Ξ» y, log (f y)) (f' / f x) x := begin rw ← has_deriv_within_at_univ at *, exact hf.log hx end lemma has_strict_deriv_at.log (hf : has_strict_deriv_at f f' x) (hx : f x β‰  0) : has_strict_deriv_at (Ξ» y, log (f y)) (f' / f x) x := begin rw div_eq_inv_mul, exact (has_strict_deriv_at_log hx).comp x hf end lemma deriv_within.log (hf : differentiable_within_at ℝ f s x) (hx : f x β‰  0) (hxs : unique_diff_within_at ℝ s x) : deriv_within (Ξ»x, log (f x)) s x = (deriv_within f s x) / (f x) := (hf.has_deriv_within_at.log hx).deriv_within hxs @[simp] lemma deriv.log (hf : differentiable_at ℝ f x) (hx : f x β‰  0) : deriv (Ξ»x, log (f x)) x = (deriv f x) / (f x) := (hf.has_deriv_at.log hx).deriv end deriv section fderiv variables {E : Type*} [normed_add_comm_group E] [normed_space ℝ E] {f : E β†’ ℝ} {x : E} {f' : E β†’L[ℝ] ℝ} {s : set E} lemma has_fderiv_within_at.log (hf : has_fderiv_within_at f f' s x) (hx : f x β‰  0) : has_fderiv_within_at (Ξ» x, log (f x)) ((f x)⁻¹ β€’ f') s x := (has_deriv_at_log hx).comp_has_fderiv_within_at x hf lemma has_fderiv_at.log (hf : has_fderiv_at f f' x) (hx : f x β‰  0) : has_fderiv_at (Ξ» x, log (f x)) ((f x)⁻¹ β€’ f') x := (has_deriv_at_log hx).comp_has_fderiv_at x hf lemma has_strict_fderiv_at.log (hf : has_strict_fderiv_at f f' x) (hx : f x β‰  0) : has_strict_fderiv_at (Ξ» x, log (f x)) ((f x)⁻¹ β€’ f') x := (has_strict_deriv_at_log hx).comp_has_strict_fderiv_at x hf lemma differentiable_within_at.log (hf : differentiable_within_at ℝ f s x) (hx : f x β‰  0) : differentiable_within_at ℝ (Ξ»x, log (f x)) s x := (hf.has_fderiv_within_at.log hx).differentiable_within_at @[simp] lemma differentiable_at.log (hf : differentiable_at ℝ f x) (hx : f x β‰  0) : differentiable_at ℝ (Ξ»x, log (f x)) x := (hf.has_fderiv_at.log hx).differentiable_at lemma cont_diff_at.log {n} (hf : cont_diff_at ℝ n f x) (hx : f x β‰  0) : cont_diff_at ℝ n (Ξ» x, log (f x)) x := (cont_diff_at_log.2 hx).comp x hf lemma cont_diff_within_at.log {n} (hf : cont_diff_within_at ℝ n f s x) (hx : f x β‰  0) : cont_diff_within_at ℝ n (Ξ» x, log (f x)) s x := (cont_diff_at_log.2 hx).comp_cont_diff_within_at x hf lemma cont_diff_on.log {n} (hf : cont_diff_on ℝ n f s) (hs : βˆ€ x ∈ s, f x β‰  0) : cont_diff_on ℝ n (Ξ» x, log (f x)) s := Ξ» x hx, (hf x hx).log (hs x hx) lemma cont_diff.log {n} (hf : cont_diff ℝ n f) (h : βˆ€ x, f x β‰  0) : cont_diff ℝ n (Ξ» x, log (f x)) := cont_diff_iff_cont_diff_at.2 $ Ξ» x, hf.cont_diff_at.log (h x) lemma differentiable_on.log (hf : differentiable_on ℝ f s) (hx : βˆ€ x ∈ s, f x β‰  0) : differentiable_on ℝ (Ξ»x, log (f x)) s := Ξ»x h, (hf x h).log (hx x h) @[simp] lemma differentiable.log (hf : differentiable ℝ f) (hx : βˆ€ x, f x β‰  0) : differentiable ℝ (Ξ»x, log (f x)) := Ξ»x, (hf x).log (hx x) lemma fderiv_within.log (hf : differentiable_within_at ℝ f s x) (hx : f x β‰  0) (hxs : unique_diff_within_at ℝ s x) : fderiv_within ℝ (Ξ»x, log (f x)) s x = (f x)⁻¹ β€’ fderiv_within ℝ f s x := (hf.has_fderiv_within_at.log hx).fderiv_within hxs @[simp] lemma fderiv.log (hf : differentiable_at ℝ f x) (hx : f x β‰  0) : fderiv ℝ (Ξ»x, log (f x)) x = (f x)⁻¹ β€’ fderiv ℝ f x := (hf.has_fderiv_at.log hx).fderiv end fderiv end log_differentiable namespace real /-- The function `x * log (1 + t / x)` tends to `t` at `+∞`. -/ lemma tendsto_mul_log_one_plus_div_at_top (t : ℝ) : tendsto (Ξ» x, x * log (1 + t / x)) at_top (𝓝 t) := begin have h₁ : tendsto (Ξ» h, h⁻¹ * log (1 + t * h)) (𝓝[β‰ ] 0) (𝓝 t), { simpa [has_deriv_at_iff_tendsto_slope, slope_fun_def] using (((has_deriv_at_id (0 : ℝ)).const_mul t).const_add 1).log (by simp) }, have hβ‚‚ : tendsto (Ξ» x : ℝ, x⁻¹) at_top (𝓝[β‰ ] 0) := tendsto_inv_at_top_zero'.mono_right (nhds_within_mono _ (Ξ» x hx, (set.mem_Ioi.mp hx).ne')), simpa only [(∘), inv_inv] using h₁.comp hβ‚‚ end open_locale big_operators /-- A crude lemma estimating the difference between `log (1-x)` and its Taylor series at `0`, where the main point of the bound is that it tends to `0`. The goal is to deduce the series expansion of the logarithm, in `has_sum_pow_div_log_of_abs_lt_1`. -/ lemma abs_log_sub_add_sum_range_le {x : ℝ} (h : |x| < 1) (n : β„•) : |((βˆ‘ i in range n, x^(i+1)/(i+1)) + log (1-x))| ≀ (|x|)^(n+1) / (1 - |x|) := begin /- For the proof, we show that the derivative of the function to be estimated is small, and then apply the mean value inequality. -/ let F : ℝ β†’ ℝ := Ξ» x, βˆ‘ i in range n, x^(i+1)/(i+1) + log (1-x), -- First step: compute the derivative of `F` have A : βˆ€ y ∈ Ioo (-1 : ℝ) 1, deriv F y = - (y^n) / (1 - y), { assume y hy, have : (βˆ‘ i in range n, (↑i + 1) * y ^ i / (↑i + 1)) = (βˆ‘ i in range n, y ^ i), { congr' with i, exact mul_div_cancel_left _ (nat.cast_add_one_pos i).ne' }, field_simp [F, this, geom_sum_eq (ne_of_lt hy.2), sub_ne_zero_of_ne (ne_of_gt hy.2), sub_ne_zero_of_ne (ne_of_lt hy.2)], ring }, -- second step: show that the derivative of `F` is small have B : βˆ€ y ∈ Icc (-|x|) (|x|), |deriv F y| ≀ |x|^n / (1 - |x|), { assume y hy, have : y ∈ Ioo (-(1 : ℝ)) 1 := ⟨lt_of_lt_of_le (neg_lt_neg h) hy.1, lt_of_le_of_lt hy.2 h⟩, calc |deriv F y| = | -(y^n) / (1 - y)| : by rw [A y this] ... ≀ |x|^n / (1 - |x|) : begin have : |y| ≀ |x| := abs_le.2 hy, have : 0 < 1 - |x|, by linarith, have : 1 - |x| ≀ |1 - y| := le_trans (by linarith [hy.2]) (le_abs_self _), simp only [← pow_abs, abs_div, abs_neg], apply_rules [div_le_div, pow_nonneg, abs_nonneg, pow_le_pow_of_le_left] end }, -- third step: apply the mean value inequality have C : β€–F x - F 0β€– ≀ (|x|^n / (1 - |x|)) * β€–x - 0β€–, { have : βˆ€ y ∈ Icc (- |x|) (|x|), differentiable_at ℝ F y, { assume y hy, have : 1 - y β‰  0 := sub_ne_zero_of_ne (ne_of_gt (lt_of_le_of_lt hy.2 h)), simp [F, this] }, apply convex.norm_image_sub_le_of_norm_deriv_le this B (convex_Icc _ _) _ _, { simp }, { simp [le_abs_self x, neg_le.mp (neg_le_abs_self x)] } }, -- fourth step: conclude by massaging the inequality of the third step simpa [F, norm_eq_abs, div_mul_eq_mul_div, pow_succ'] using C end /-- Power series expansion of the logarithm around `1`. -/ theorem has_sum_pow_div_log_of_abs_lt_1 {x : ℝ} (h : |x| < 1) : has_sum (Ξ» (n : β„•), x ^ (n + 1) / (n + 1)) (-log (1 - x)) := begin rw summable.has_sum_iff_tendsto_nat, show tendsto (Ξ» (n : β„•), βˆ‘ (i : β„•) in range n, x ^ (i + 1) / (i + 1)) at_top (𝓝 (-log (1 - x))), { rw [tendsto_iff_norm_tendsto_zero], simp only [norm_eq_abs, sub_neg_eq_add], refine squeeze_zero (Ξ» n, abs_nonneg _) (abs_log_sub_add_sum_range_le h) _, suffices : tendsto (Ξ» (t : β„•), |x| ^ (t + 1) / (1 - |x|)) at_top (𝓝 (|x| * 0 / (1 - |x|))), by simpa, simp only [pow_succ], refine (tendsto_const_nhds.mul _).div_const, exact tendsto_pow_at_top_nhds_0_of_lt_1 (abs_nonneg _) h }, show summable (Ξ» (n : β„•), x ^ (n + 1) / (n + 1)), { refine summable_of_norm_bounded _ (summable_geometric_of_lt_1 (abs_nonneg _) h) (Ξ» i, _), calc β€–x ^ (i + 1) / (i + 1)β€– = |x| ^ (i + 1) / (i + 1) : begin have : (0 : ℝ) ≀ i + 1 := le_of_lt (nat.cast_add_one_pos i), rw [norm_eq_abs, abs_div, ← pow_abs, abs_of_nonneg this], end ... ≀ |x| ^ (i + 1) / (0 + 1) : begin apply_rules [div_le_div_of_le_left, pow_nonneg, abs_nonneg, add_le_add_right, i.cast_nonneg], norm_num, end ... ≀ |x| ^ i : by simpa [pow_succ'] using mul_le_of_le_one_right (pow_nonneg (abs_nonneg x) i) (le_of_lt h) } end /-- Power series expansion of `log(1 + x) - log(1 - x)` for `|x| < 1`. -/ lemma has_sum_log_sub_log_of_abs_lt_1 {x : ℝ} (h : |x| < 1) : has_sum (Ξ» k : β„•, (2 : ℝ) * (1 / (2 * k + 1)) * x ^ (2 * k + 1)) (log (1 + x) - log(1 - x)) := begin let term := Ξ» n : β„•, (-1) * ((-x) ^ (n + 1) / ((n : ℝ) + 1)) + x ^ (n + 1) / (n + 1), have h_term_eq_goal : term ∘ (*) 2 = Ξ» k : β„•, 2 * (1 / (2 * k + 1)) * x ^ (2 * k + 1), { ext n, dsimp [term], rw [odd.neg_pow (⟨n, rfl⟩ : odd (2 * n + 1)) x], push_cast, ring_nf, }, rw [← h_term_eq_goal, (mul_right_injectiveβ‚€ (two_ne_zero' β„•)).has_sum_iff], { have h₁ := (has_sum_pow_div_log_of_abs_lt_1 (eq.trans_lt (abs_neg x) h)).mul_left (-1), convert h₁.add (has_sum_pow_div_log_of_abs_lt_1 h), ring_nf }, { intros m hm, rw [range_two_mul, set.mem_set_of_eq, ← nat.even_add_one] at hm, dsimp [term], rw [even.neg_pow hm, neg_one_mul, neg_add_self] }, end /-- Expansion of `log (1 + a⁻¹)` as a series in powers of `1 / (2 * a + 1)`. -/ theorem has_sum_log_one_add_inv {a : ℝ} (h : 0 < a) : has_sum (Ξ» k : β„•, (2 : ℝ) * (1 / (2 * k + 1)) * (1 / (2 * a + 1)) ^ (2 * k + 1)) (log (1 + a⁻¹)) := begin have h₁ : |1 / (2 * a + 1)| < 1, { rw [abs_of_pos, div_lt_one], { linarith, }, { linarith, }, { exact div_pos one_pos (by linarith), }, }, convert has_sum_log_sub_log_of_abs_lt_1 h₁, have hβ‚‚ : (2 : ℝ) * a + 1 β‰  0 := by linarith, have h₃ := h.ne', rw ← log_div, { congr, field_simp, linarith, }, { field_simp, linarith } , { field_simp }, end end real
54fe4a82b1b27e3cb98b8d5d9b5a5990228eebfb
367134ba5a65885e863bdc4507601606690974c1
/src/data/finset/powerset.lean
fd82863ec563498f6010ad810ebd386bbdfbf9ed
[ "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,349
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro -/ import data.finset.basic /-! # The powerset of a finset -/ namespace finset open multiset variables {Ξ± : Type*} /-! ### powerset -/ section powerset /-- When `s` is a finset, `s.powerset` is the finset of all subsets of `s` (seen as finsets). -/ def powerset (s : finset Ξ±) : finset (finset Ξ±) := ⟨s.1.powerset.pmap finset.mk (Ξ» t h, nodup_of_le (mem_powerset.1 h) s.2), nodup_pmap (Ξ» a ha b hb, congr_arg finset.val) (nodup_powerset.2 s.2)⟩ @[simp] theorem mem_powerset {s t : finset Ξ±} : s ∈ powerset t ↔ s βŠ† t := by cases s; simp only [powerset, mem_mk, mem_pmap, mem_powerset, exists_prop, exists_eq_right]; rw ← val_le_iff @[simp] theorem empty_mem_powerset (s : finset Ξ±) : βˆ… ∈ powerset s := mem_powerset.2 (empty_subset _) @[simp] theorem mem_powerset_self (s : finset Ξ±) : s ∈ powerset s := mem_powerset.2 (subset.refl _) @[simp] lemma powerset_empty : finset.powerset (βˆ… : finset Ξ±) = {βˆ…} := rfl @[simp] theorem powerset_mono {s t : finset Ξ±} : powerset s βŠ† powerset t ↔ s βŠ† t := ⟨λ h, (mem_powerset.1 $ h $ mem_powerset_self _), Ξ» st u h, mem_powerset.2 $ subset.trans (mem_powerset.1 h) st⟩ @[simp] theorem card_powerset (s : finset Ξ±) : card (powerset s) = 2 ^ card s := (card_pmap _ _ _).trans (card_powerset s.1) lemma not_mem_of_mem_powerset_of_not_mem {s t : finset Ξ±} {a : Ξ±} (ht : t ∈ s.powerset) (h : a βˆ‰ s) : a βˆ‰ t := by { apply mt _ h, apply mem_powerset.1 ht } lemma powerset_insert [decidable_eq Ξ±] (s : finset Ξ±) (a : Ξ±) : powerset (insert a s) = s.powerset βˆͺ s.powerset.image (insert a) := begin ext t, simp only [exists_prop, mem_powerset, mem_image, mem_union, subset_insert_iff], by_cases h : a ∈ t, { split, { exact Ξ»H, or.inr ⟨_, H, insert_erase h⟩ }, { intros H, cases H, { exact subset.trans (erase_subset a t) H }, { rcases H with ⟨u, hu⟩, rw ← hu.2, exact subset.trans (erase_insert_subset a u) hu.1 } } }, { have : Β¬ βˆƒ (u : finset Ξ±), u βŠ† s ∧ insert a u = t, by simp [ne.symm (ne_insert_of_not_mem _ _ h)], simp [finset.erase_eq_of_not_mem h, this] } end end powerset section powerset_len /-- Given an integer `n` and a finset `s`, then `powerset_len n s` is the finset of subsets of `s` of cardinality `n`. -/ def powerset_len (n : β„•) (s : finset Ξ±) : finset (finset Ξ±) := ⟨(s.1.powerset_len n).pmap finset.mk (Ξ» t h, nodup_of_le (mem_powerset_len.1 h).1 s.2), nodup_pmap (Ξ» a ha b hb, congr_arg finset.val) (nodup_powerset_len s.2)⟩ theorem mem_powerset_len {n} {s t : finset Ξ±} : s ∈ powerset_len n t ↔ s βŠ† t ∧ card s = n := by cases s; simp [powerset_len, val_le_iff.symm]; refl @[simp] theorem powerset_len_mono {n} {s t : finset Ξ±} (h : s βŠ† t) : powerset_len n s βŠ† powerset_len n t := Ξ» u h', mem_powerset_len.2 $ and.imp (Ξ» hβ‚‚, subset.trans hβ‚‚ h) id (mem_powerset_len.1 h') @[simp] theorem card_powerset_len (n : β„•) (s : finset Ξ±) : card (powerset_len n s) = nat.choose (card s) n := (card_pmap _ _ _).trans (card_powerset_len n s.1) @[simp] lemma powerset_len_zero (s : finset Ξ±) : finset.powerset_len 0 s = {βˆ…} := begin ext, rw [mem_powerset_len, mem_singleton, card_eq_zero], refine ⟨λ h, h.2, Ξ» h, by { rw h, exact ⟨empty_subset s, rfl⟩ }⟩, end @[simp] theorem powerset_len_empty (n : β„•) {s : finset Ξ±} (h : s.card < n) : powerset_len n s = βˆ… := finset.card_eq_zero.mp (by rw [card_powerset_len, nat.choose_eq_zero_of_lt h]) theorem powerset_len_eq_filter {n} {s : finset Ξ±} : powerset_len n s = (powerset s).filter (Ξ» x, x.card = n) := by { ext, simp [mem_powerset_len] } lemma powerset_card_bUnion [decidable_eq (finset Ξ±)] (s : finset Ξ±) : finset.powerset s = (range (s.card + 1)).bUnion (Ξ» i, powerset_len i s) := begin refine ext (Ξ» a, ⟨λ ha, _, Ξ» ha, _ ⟩), { rw mem_bUnion, exact ⟨a.card, mem_range.mpr (nat.lt_succ_of_le (card_le_of_subset (mem_powerset.mp ha))), mem_powerset_len.mpr ⟨mem_powerset.mp ha, rfl⟩⟩ }, { rcases mem_bUnion.mp ha with ⟨i, hi, ha⟩, exact mem_powerset.mpr (mem_powerset_len.mp ha).1, } end end powerset_len end finset
879228d48ac509fdfd0e8f9635518345ae3c7068
2731214ea32f2a1a985300e281fb3117640a16c3
/portmanteau_limsup_lemmas.lean
fdb8aeb1938a2aee1832f8e756f3e7948742f808
[ "Apache-2.0" ]
permissive
kkytola/lean_portmanteau
5d6a156db959974ebc4f5bed9118a7a2438a33fa
ac55eb4e24be43032cbc082e2b68d8fb8bd63f22
refs/heads/main
1,686,107,117,334
1,625,177,052,000
1,625,177,052,000
381,514,032
1
0
null
null
null
null
UTF-8
Lean
false
false
17,478
lean
/- Copyright (c) 2021 Kalle KytΓΆlΓ€. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle KytΓΆlΓ€ -/ import topology.instances.real import topology.instances.ennreal import portmanteau_comeonlean_lemmas noncomputable theory open set open filter open_locale topological_space namespace portmanteau abbreviation liminf_R (s : β„• β†’ ℝ) : ℝ := liminf at_top s abbreviation limsup_R (s : β„• β†’ ℝ) : ℝ := limsup at_top s abbreviation liminf_enn (s : β„• β†’ ennreal) : ennreal := liminf at_top s abbreviation limsup_enn (s : β„• β†’ ennreal) : ennreal := limsup at_top s abbreviation lim_R (s : β„• β†’ ℝ) (l : ℝ) : Prop := tendsto s at_top (𝓝 l) abbreviation lim_enn (s : β„• β†’ ennreal) (l : ennreal) : Prop := tendsto s at_top (𝓝 l) lemma lim_R_rw (s : β„• β†’ ℝ) (l : ℝ) : lim_R s l = tendsto s at_top (𝓝 l) := by refl lemma liminf_enn_rw {s : β„• β†’ ennreal} : liminf_enn s = liminf at_top s := by refl lemma limsup_enn_rw {s : β„• β†’ ennreal} : limsup_enn s = limsup at_top s := by refl section portmanteau_limsup_liminf_lemmas lemma liminf_le_limsup_enn (s : β„• β†’ ennreal) : (liminf_enn s) ≀ (limsup_enn s) := begin apply @liminf_le_limsup ennreal _ _ _ _ s , exact at_top_ne_bot , end lemma lim_eq_liminf_of_limsup_le_liminf_ennreal {s : β„• β†’ ennreal} (hle : limsup_enn s ≀ liminf_enn s ) : lim_enn (s) (liminf_enn s) := begin have heq : limsup_enn s = liminf_enn s := le_antisymm hle (liminf_le_limsup_enn s) , set l := liminf_enn s with hl, exact tendsto_of_liminf_eq_limsup hl heq , end lemma lim_eq_limsup_of_limsup_le_liminf_ennreal {s : β„• β†’ ennreal} (hle : limsup_enn s ≀ liminf_enn s ) : lim_enn s (limsup_enn s) := begin rw le_antisymm hle (liminf_le_limsup_enn s) , exact lim_eq_liminf_of_limsup_le_liminf_ennreal hle , end lemma lim_eq_limsup_ennreal {s : β„• β†’ ennreal} {l : ennreal} (hlim : lim_enn s l ) : limsup_enn s = l := tendsto.limsup_eq hlim lemma lim_eq_liminf_ennreal {s : β„• β†’ ennreal} {l : ennreal} (hlim : lim_enn s l ) : liminf_enn s = l := tendsto.liminf_eq hlim lemma limsup_le_of_le_ennreal {s : β„• β†’ ennreal} {b : ennreal} (hb : βˆ€ n , s(n) ≀ b ) : limsup_enn s ≀ b := begin have key : s ≀ᢠ[at_top] (Ξ» n , b) := eventually_of_forall hb , have le := limsup_le_limsup key , have lim : tendsto (Ξ» (n:β„•) , b) at_top (𝓝 b) := tendsto_const_nhds , have eq : at_top.limsup (Ξ» n , b) = b := lim_eq_limsup_ennreal lim , rwa eq at le , end lemma liminf_le_of_le_ennreal {s : β„• β†’ ennreal} {b : ennreal} (hb : βˆ€ n , s(n) ≀ b ) : liminf_enn s ≀ b := begin have key : s ≀ᢠ[at_top] (Ξ» n , b) := eventually_of_forall hb , have le := liminf_le_liminf key , have lim : tendsto (Ξ» (n:β„•) , b) at_top (𝓝 b) := tendsto_const_nhds , have eq : at_top.liminf (Ξ» n , b) = b := lim_eq_liminf_ennreal lim , rwa eq at le , end -- TODO: Why does Limsup_le_Limsup_of_le not work? lemma limsup_enn_mono {s t : β„• β†’ ennreal} (hst : βˆ€ (n : β„•) , s(n) ≀ t(n)) : limsup_enn s ≀ limsup_enn t := begin have relax : s ≀ᢠ[at_top] t , { apply eventually_of_mem (@univ_mem_sets β„• at_top) , intros n hn , exact hst n , } , exact limsup_le_limsup relax , end -- TODO: Why does Liminf_le_Liminf_of_le not work? lemma liminf_enn_mono {s t : β„• β†’ ennreal} (hst : βˆ€ (n : β„•) , s(n) ≀ t(n)) : liminf_enn s ≀ liminf_enn t := begin have relax : s ≀ᢠ[at_top] t , { apply eventually_of_mem (@univ_mem_sets β„• at_top) , intros n hn , exact hst n , } , exact liminf_le_liminf relax , end lemma Sup_neg (A : set ℝ) : Sup {x : ℝ | -x ∈ A} = - Inf A := begin set mA := {x : ℝ | -x ∈ A} with hmA , set z := Sup mA with hz , have key := real.Inf_def A , rw key , simp , end lemma Inf_neg (A : set ℝ) : Inf {x : ℝ | -x ∈ A} = - Sup A := begin set mA := {x : ℝ | -x ∈ A} with hmA , have key := Sup_neg mA , set mmA := {x : ℝ | -x ∈ mA} with hmmA , have AmmA : A = mmA := by simp [hmA , hmmA], rw [AmmA, key] , simp , end lemma liminf_neg {s : β„• β†’ ℝ} : liminf_R (-s) = - limsup_R s := begin set A := { a : ℝ | βˆƒ (a_1 : β„•) , βˆ€ (b : β„•) , a_1 ≀ b β†’ s b ≀ a } with hA , set mA := { a : ℝ | -a ∈ A } with hmA , have mA_rw : mA = { a : ℝ | βˆƒ (a_1 : β„•) , βˆ€ (b : β„•) , a_1 ≀ b β†’ a ≀ - s b } , { ext a , rw mem_set_of_eq , split ; -- hide in corners { intro h , cases h with k hk , use k , intros l hl , specialize hk l hl , linarith , } , } , have ls_eq : limsup_R s = Inf A , { change limsup at_top s = Inf A , rw limsup_eq , simp only [eventually_at_top] , } , have li_eq : liminf_R (-s) = Sup mA , { change liminf at_top (-s) = Sup mA , rw liminf_eq , simp only [mA_rw, pi.neg_apply, eventually_at_top] , } , rw [li_eq, ls_eq] , exact Sup_neg A , end lemma limsup_neg {s : β„• β†’ ℝ} : limsup_R (-s) = - liminf_R s := begin set t := -s with ht , have nt_rw : s = -t := by tidy , have key := @liminf_neg t , rw nt_rw , linarith , end -- TODO: should the following couple of lemmas be done in more generality? -- Probably `complete_semilattice_Sup` and `order_topology` etc. -- would be good general assumptions. lemma f_Sup_eq_Sup_f_ennreal (f : ennreal β†’ ennreal) (f_mono : monotone f) (f_cont : continuous f) (T : set ennreal) (nonemp_T : T.nonempty) : Sup (f '' T) = f(Sup T) := begin have ub : βˆ€ y ∈ f '' T , y ≀ f (Sup T) , { intros y hy , rcases hy with ⟨ x , hxT , fx_eq_y ⟩ , rw ← fx_eq_y , exact f_mono (le_Sup hxT) , } , have lub : βˆ€ (b : ennreal) , (βˆ€ y ∈ f '' T , y ≀ b) β†’ f (Sup T) ≀ b , { have tends : tendsto f (𝓝 (Sup T)) (𝓝 (f (Sup T))) := continuous.tendsto f_cont (Sup T) , have tends' : tendsto f (𝓝[T] (Sup T)) (𝓝 (f (Sup T))) := tendsto_nhds_within_of_tendsto_nhds tends , have tada : is_lub T (Sup T) := is_lub_Sup T , have key := is_lub.is_lub_of_tendsto _ tada nonemp_T tends' , { intros b hb , exact key.2 hb , } , { intros a haT b hbT hab , exact f_mono hab , } , } , apply le_antisymm , { apply Sup_le ub , } , { apply le_Sup_iff.mpr lub , } , end lemma f_Inf_eq_Inf_f_ennreal (f : ennreal β†’ ennreal) (f_mono : monotone f) (f_cont : continuous f) (T : set ennreal) (nonemp_T : T.nonempty) : Inf (f '' T) = f(Inf T) := begin have lb : βˆ€ y ∈ f '' T , f (Inf T) ≀ y , { intros y hy , rcases hy with ⟨ x , hxT , fx_eq_y ⟩ , rw ← fx_eq_y , exact f_mono (Inf_le hxT) , } , have glb : βˆ€ (b : ennreal) , (βˆ€ y ∈ f '' T , b ≀ y) β†’ b ≀ f (Inf T) , { have tends : tendsto f (𝓝 (Inf T)) (𝓝 (f (Inf T))) := continuous.tendsto f_cont (Inf T) , have tends' : tendsto f (𝓝[T] (Inf T)) (𝓝 (f (Inf T))) := tendsto_nhds_within_of_tendsto_nhds tends , have inf_is_glb : is_glb T (Inf T) := is_glb_Inf T , have key := is_glb.is_glb_of_tendsto _ inf_is_glb nonemp_T tends' , { intros b hb , exact key.2 hb , } , { intros a haT b hbT hab , exact f_mono hab , } , } , apply le_antisymm , { apply Inf_le_iff.mpr glb , } , { apply le_Inf lb , } , end lemma f_Sup_eq_Inf_f_ennreal (f : ennreal β†’ ennreal) (f_antimono : @monotone ennreal (order_dual(ennreal)) _ _ f) (f_cont : continuous f) (T : set ennreal) (nonemp_T : T.nonempty) : Inf (f '' T) = f(Sup T) := begin have lb : βˆ€ y ∈ f '' T , f (Sup T) ≀ y, { intros y hy , rcases hy with ⟨ x , hxT , fx_eq_y ⟩ , rw ← fx_eq_y , exact f_antimono (le_Sup hxT) , } , have glb : βˆ€ (b : ennreal) , (βˆ€ y ∈ f '' T , b ≀ y ) β†’ b ≀ f (Sup T) , { have tends : tendsto f (𝓝 (Sup T)) (𝓝 (f (Sup T))) := continuous.tendsto f_cont (Sup T) , have tends' : tendsto f (𝓝[T] (Sup T)) (𝓝 (f (Sup T))) := tendsto_nhds_within_of_tendsto_nhds tends , have sup_is_lub : is_lub T (Sup T) := is_lub_Sup T , have key := is_lub.is_glb_of_tendsto _ sup_is_lub nonemp_T tends' , { intros b hb , exact key.2 hb , } , { intros a haT b hbT hab , exact f_antimono hab , } , } , apply le_antisymm , { exact Inf_le_iff.mpr glb , } , { exact le_Inf lb , } , end lemma f_Inf_eq_Sup_f_ennreal (f : ennreal β†’ ennreal) (f_antimono : @monotone ennreal (order_dual(ennreal)) _ _ f) (f_cont : continuous f) (T : set ennreal) (nonemp_T : T.nonempty) : Sup (f '' T) = f(Inf T) := begin have ub : βˆ€ y ∈ f '' T , y ≀ f (Inf T) , { intros y hy , rcases hy with ⟨ x , hxT , fx_eq_y ⟩ , rw ← fx_eq_y , exact f_antimono (Inf_le hxT) , } , have lub : βˆ€ (b : ennreal) , (βˆ€ y ∈ f '' T , y ≀ b) β†’ f (Inf T) ≀ b , { have tends : tendsto f (𝓝 (Inf T)) (𝓝 (f (Inf T))) := continuous.tendsto f_cont (Inf T) , have tends' : tendsto f (𝓝[T] (Inf T)) (𝓝 (f (Inf T))) := tendsto_nhds_within_of_tendsto_nhds tends , have inf_is_glb : is_glb T (Inf T) := is_glb_Inf T , have key := is_glb.is_lub_of_tendsto _ inf_is_glb nonemp_T tends' , { intros b hb , exact key.2 hb , } , { intros a haT b hbT hab , exact f_antimono hab , } , } , apply le_antisymm , { apply Sup_le ub , } , { apply le_Sup_iff.mpr lub , } , end lemma image_range {Ξ± Ξ² Ξ³ : Type*} (g : Ξ² β†’ Ξ³) (f : Ξ± β†’ Ξ²) : g '' (range f) = range (g ∘ f) := begin ext w , simp only [mem_image, mem_range, exists_exists_eq_and] , end lemma inf_tails_mono_ennreal (s : β„• β†’ ennreal) : monotone (Ξ» (m : β„•) , Inf (s '' (Ici m))) := begin intros n m hnm , exact Inf_le_Inf (image_subset s (Ici_subset_Ici.mpr hnm)) , end -- I did not manage to state this result correctly -- using `@monotone` and `order_dual`... lemma sup_tails_antimono_ennreal (s : β„• β†’ ennreal) : βˆ€ (k l : β„•) , k ≀ l β†’ (Ξ» (m : β„•) , Sup (s '' (Ici m))) l ≀ (Ξ» (m : β„•) , Sup (s '' (Ici m))) k := begin intros k l hkl , exact Sup_le_Sup (image_subset s (Ici_subset_Ici.mpr hkl)) , end lemma Sup_eq_Inf_upper_bounds (Ξ³ : Type) [complete_lattice Ξ³] (A : set Ξ³) : Sup A = Inf (upper_bounds(A)) := begin have key := is_lub_Sup A , apply le_antisymm , { cases key , simp only [le_Inf_iff, Sup_le_iff] , intros b hbub b' hb' , solve_by_elim , } , { cases key, exact Inf_le key_left , } , end lemma Inf_eq_Sup_lower_bounds (Ξ³ : Type) [complete_lattice Ξ³] (A : set Ξ³) : Inf A = Sup (lower_bounds(A)) := begin have key := is_glb_Inf A , apply le_antisymm , { cases key, exact le_Sup key_left , } , { cases key , simp only [le_Inf_iff, Sup_le_iff] , intros b hblb b' hb' , solve_by_elim , } , end lemma liminf_eq_Sup_Inf_ennreal (s : β„• β†’ ennreal) : liminf_enn s = Sup ( range( Ξ» (m : β„•) , Inf (s '' (Ici m))) ) := begin have mono := inf_tails_mono_ennreal s , set s_inf_tail := Ξ» (m : β„•) , Inf (s '' (Ici m)) with h_s_inf_tail , set A := { a : ennreal | βˆƒ (m : β„•) , βˆ€ (n : β„•) , m ≀ n β†’ a ≀ s(n) } with hA , have ls_eq : liminf_enn s = Sup A , { change liminf at_top s = Sup A , rw liminf_eq , simp , } , rw ls_eq , have A_eq : A = { a : ennreal | βˆƒ (m : β„•) , a ≀ s_inf_tail m} , { simp only [mem_image, and_imp, mem_Ici, le_Inf_iff, forall_apply_eq_imp_iffβ‚‚, exists_imp_distrib] , } , have ss : range(s_inf_tail) βŠ† { a : ennreal | βˆƒ (m : β„•) , a ≀ s_inf_tail m } , { intros x hx , cases hx with n hn , -- corners use n , rw hn , exact le_refl x , } , have key : upper_bounds { a : ennreal | βˆƒ (m : β„•) , a ≀ s_inf_tail m } = upper_bounds (range(s_inf_tail)) , { apply le_antisymm , { intros b h_bub x hxran , -- more corners, safe place exact h_bub (ss hxran) , } , { intros b h_bub x hx , cases hx with m hm , exact le_trans hm (h_bub (mem_range_self m)) , } , } , rw ← A_eq at key , rw Sup_eq_Inf_upper_bounds , rw Sup_eq_Inf_upper_bounds , exact congr_arg Inf key , end lemma limsup_eq_Inf_Sup_ennreal (s : β„• β†’ ennreal) : limsup_enn s = Inf ( range( Ξ» (m : β„•) , Sup (s '' (Ici m))) ) := begin have antimono := sup_tails_antimono_ennreal s , set s_sup_tail := Ξ» (m : β„•) , Sup (s '' (Ici m)) with h_s_sup_tail , set A := { a : ennreal | βˆƒ (m : β„•) , βˆ€ (n : β„•) , m ≀ n β†’ s(n) ≀ a } with hA , have ls_eq : limsup_enn s = Inf A , { change limsup at_top s = Inf A , rw limsup_eq , simp , } , rw ls_eq , have A_eq : A = { a : ennreal | βˆƒ (m : β„•) , s_sup_tail m ≀ a } , { simp only [mem_image, and_imp, mem_Ici, Sup_le_iff, forall_apply_eq_imp_iffβ‚‚, exists_imp_distrib] , } , have ss : range(s_sup_tail) βŠ† { a : ennreal | βˆƒ (m : β„•) , s_sup_tail m ≀ a} , { intros x hx , cases hx with n hn , use n , rw hn , -- hide exact le_refl x , } , have key : lower_bounds { a : ennreal | βˆƒ (m : β„•) , s_sup_tail m ≀ a} = lower_bounds (range(s_sup_tail)) , { apply le_antisymm , { intros b h_blb x hxran , exact h_blb (ss hxran) , } , { intros b h_blb x hx , -- keep quiet cases hx with m hm , exact le_trans (h_blb (mem_range_self m)) hm , } , } , rw ← A_eq at key , rw Inf_eq_Sup_lower_bounds , rw Inf_eq_Sup_lower_bounds , exact congr_arg Sup key , end lemma liminf_eq_supr_Inf_ennreal (s : β„• β†’ ennreal) : liminf_enn s = supr ( Ξ» (m : β„•) , Inf (s '' (Ici m))) := begin have eq : supr ( Ξ» (m : β„•) , Inf (s '' (Ici m))) = Sup ( range( Ξ» (m : β„•) , Inf (s '' (Ici m))) ) := by refl , rw eq , apply liminf_eq_Sup_Inf_ennreal , end lemma liminf_apply_cont_mono_ennreal {s : β„• β†’ ennreal} (f : ennreal β†’ ennreal) (f_cont : continuous f) (f_mono : monotone f) : liminf_enn (f ∘ s) = f ( liminf_enn s) := begin nth_rewrite 1 liminf_eq_Sup_Inf_ennreal , rw ← f_Sup_eq_Sup_f_ennreal f f_mono f_cont (range (Ξ» (m : β„•) , Inf (s '' (Ici m)))) (range_nonempty _) , rw image_range _ _ , have eq : (f ∘ Ξ» (m : β„•), Inf (s '' Ici m)) = (Ξ» (m : β„•), Inf ((f ∘ s) '' Ici m)) , { funext m , dsimp , rw ← f_Inf_eq_Inf_f_ennreal f f_mono f_cont (s '' Ici m) nonempty_of_nonempty_subtype , have eq_im : (f '' (s '' (Ici m))) = ((f ∘ s) '' (Ici m)) , { ext , simp only [mem_image, exists_exists_and_eq_and] , } , simp only [eq_im] , } , rw [eq , liminf_eq_Sup_Inf_ennreal] , end lemma liminf_apply_cont_antimono_ennreal {s : β„• β†’ ennreal} (f : ennreal β†’ ennreal) (f_cont : continuous f) (f_antimono : @monotone ennreal (order_dual(ennreal)) _ _ f) : liminf_enn (f ∘ s) = f ( limsup_enn s) := begin rw limsup_eq_Inf_Sup_ennreal , rw ← f_Inf_eq_Sup_f_ennreal f f_antimono f_cont (range (Ξ» (m : β„•) , Sup (s '' (Ici m)))) (range_nonempty _) , rw image_range _ _ , have eq : (f ∘ Ξ» (m : β„•), Sup (s '' Ici m)) = (Ξ» (m : β„•), Inf ((f ∘ s) '' Ici m)) , { funext m , dsimp , rw ← f_Sup_eq_Inf_f_ennreal f f_antimono f_cont (s '' Ici m) nonempty_of_nonempty_subtype , have eq_im : (f '' (s '' (Ici m))) = ((f ∘ s) '' (Ici m)) , { ext , simp only [mem_image, exists_exists_and_eq_and] , } , simp only [eq_im] , } , rw [eq , liminf_eq_Sup_Inf_ennreal] , end lemma limsup_apply_cont_antimono_ennreal {s : β„• β†’ ennreal} (f : ennreal β†’ ennreal) (f_cont : continuous f) (f_antimono : @monotone ennreal (order_dual(ennreal)) _ _ f) : limsup_enn (f ∘ s) = f ( liminf_enn s) := begin rw liminf_eq_Sup_Inf_ennreal , rw ← f_Sup_eq_Inf_f_ennreal f f_antimono f_cont (range (Ξ» (m : β„•) , Inf (s '' (Ici m)))) (range_nonempty _) , rw image_range _ _ , have eq : (f ∘ Ξ» (m : β„•), Inf (s '' Ici m)) = (Ξ» (m : β„•), Sup ((f ∘ s) '' Ici m)) , { funext m , dsimp , rw ← f_Inf_eq_Sup_f_ennreal f f_antimono f_cont (s '' Ici m) nonempty_of_nonempty_subtype , have eq_im : (f '' (s '' (Ici m))) = ((f ∘ s) '' (Ici m)) , { ext , simp only [mem_image, exists_exists_and_eq_and] , } , simp only [eq_im] , } , rw [eq , limsup_eq_Inf_Sup_ennreal] , end lemma liminf_const_sub (a : ennreal) (a_ne_top : a β‰  ⊀) (s : β„• β†’ ennreal) : liminf at_top (Ξ» n , (a - s(n))) = a - limsup at_top s := begin have cont : continuous (Ξ» (x : ennreal) , a-x ) := continuous_const_sub_ennreal a a_ne_top , set f := Ξ» (x : ennreal) , a-x with hf , -- TODO: the following is repeated many times, but stating it as lemma -- gets messed up, because Lean doesn't know that in `order_dual(ennreal)` -- I want to use the same `-` (`sub`) as in `ennreal`... have antimono : @monotone ennreal (order_dual(ennreal)) _ _ f , { intros x y hxy , exact self_sub_le_self_sub_ennreal a y x hxy , } , apply liminf_apply_cont_antimono_ennreal _ cont antimono , end lemma limsup_const_sub (a : ennreal) (a_ne_top : a β‰  ⊀) (s : β„• β†’ ennreal) : limsup at_top (Ξ» n , (a - s(n))) = a - liminf at_top s := begin have cont : continuous (Ξ» (x : ennreal) , a-x ) := continuous_const_sub_ennreal a a_ne_top , set f := Ξ» (x : ennreal) , a-x with hf , have antimono : @monotone ennreal (order_dual(ennreal)) _ _ f , { intros x y hxy , exact self_sub_le_self_sub_ennreal a y x hxy , } , apply limsup_apply_cont_antimono_ennreal _ cont antimono , end end portmanteau_limsup_liminf_lemmas end portmanteau
9aba1a9c37bccbd2a0e04a371f39c8c2fb401aa2
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/number_theory/class_number/admissible_card_pow_degree.lean
c056f5e20432a02ccfe50926894a21ffe9897b71
[ "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
13,869
lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import data.polynomial.degree.card_pow_degree import field_theory.finite.basic import number_theory.class_number.admissible_absolute_value /-! # Admissible absolute values on polynomials This file defines an admissible absolute value `polynomial.card_pow_degree_is_admissible` which we use to show the class number of the ring of integers of a function field is finite. ## Main results * `polynomial.card_pow_degree_is_admissible` shows `card_pow_degree`, mapping `p : polynomial 𝔽_q` to `q ^ degree p`, is admissible -/ namespace polynomial open absolute_value real variables {Fq : Type*} [field Fq] [fintype Fq] /-- If `A` is a family of enough low-degree polynomials over a finite field, there is a pair of equal elements in `A`. -/ lemma exists_eq_polynomial {d : β„•} {m : β„•} (hm : fintype.card Fq ^ d ≀ m) (b : polynomial Fq) (hb : nat_degree b ≀ d) (A : fin m.succ β†’ polynomial Fq) (hA : βˆ€ i, degree (A i) < degree b) : βˆƒ iβ‚€ i₁, iβ‚€ β‰  i₁ ∧ A i₁ = A iβ‚€ := begin -- Since there are > q^d elements of A, and only q^d choices for the highest `d` coefficients, -- there must be two elements of A with the same coefficients at -- `0`, ... `degree b - 1` ≀ `d - 1`. -- In other words, the following map is not injective: set f : fin m.succ β†’ (fin d β†’ Fq) := Ξ» i j, (A i).coeff j, have : fintype.card (fin d β†’ Fq) < fintype.card (fin m.succ), { simpa using lt_of_le_of_lt hm (nat.lt_succ_self m) }, -- Therefore, the differences have all coefficients higher than `deg b - d` equal. obtain ⟨iβ‚€, i₁, i_ne, i_eq⟩ := fintype.exists_ne_map_eq_of_card_lt f this, use [iβ‚€, i₁, i_ne], ext j, -- The coefficients higher than `deg b` are the same because they are equal to 0. by_cases hbj : degree b ≀ j, { rw [coeff_eq_zero_of_degree_lt (lt_of_lt_of_le (hA _) hbj), coeff_eq_zero_of_degree_lt (lt_of_lt_of_le (hA _) hbj)] }, -- So we only need to look for the coefficients between `0` and `deg b`. rw not_le at hbj, apply congr_fun i_eq.symm ⟨j, _⟩, exact lt_of_lt_of_le (coe_lt_degree.mp hbj) hb end /-- If `A` is a family of enough low-degree polynomials over a finite field, there is a pair of elements in `A` (with different indices but not necessarily distinct), such that their difference has small degree. -/ lemma exists_approx_polynomial_aux {d : β„•} {m : β„•} (hm : fintype.card Fq ^ d ≀ m) (b : polynomial Fq) (A : fin m.succ β†’ polynomial Fq) (hA : βˆ€ i, degree (A i) < degree b) : βˆƒ iβ‚€ i₁, iβ‚€ β‰  i₁ ∧ degree (A i₁ - A iβ‚€) < ↑(nat_degree b - d) := begin have hb : b β‰  0, { rintro rfl, specialize hA 0, rw degree_zero at hA, exact not_lt_of_le bot_le hA }, -- Since there are > q^d elements of A, and only q^d choices for the highest `d` coefficients, -- there must be two elements of A with the same coefficients at -- `degree b - 1`, ... `degree b - d`. -- In other words, the following map is not injective: set f : fin m.succ β†’ (fin d β†’ Fq) := Ξ» i j, (A i).coeff (nat_degree b - j.succ), have : fintype.card (fin d β†’ Fq) < fintype.card (fin m.succ), { simpa using lt_of_le_of_lt hm (nat.lt_succ_self m) }, -- Therefore, the differences have all coefficients higher than `deg b - d` equal. obtain ⟨iβ‚€, i₁, i_ne, i_eq⟩ := fintype.exists_ne_map_eq_of_card_lt f this, use [iβ‚€, i₁, i_ne], refine (degree_lt_iff_coeff_zero _ _).mpr (Ξ» j hj, _), -- The coefficients higher than `deg b` are the same because they are equal to 0. by_cases hbj : degree b ≀ j, { refine coeff_eq_zero_of_degree_lt (lt_of_lt_of_le _ hbj), exact lt_of_le_of_lt (degree_sub_le _ _) (max_lt (hA _) (hA _)) }, -- So we only need to look for the coefficients between `deg b - d` and `deg b`. rw [coeff_sub, sub_eq_zero], rw [not_le, degree_eq_nat_degree hb, with_bot.coe_lt_coe] at hbj, have hj : nat_degree b - j.succ < d, { by_cases hd : nat_degree b < d, { exact lt_of_le_of_lt tsub_le_self hd }, { rw not_lt at hd, have := lt_of_le_of_lt hj (nat.lt_succ_self j), rwa [tsub_lt_iff_tsub_lt hd hbj] at this } }, have : j = b.nat_degree - (nat_degree b - j.succ).succ, { rw [← nat.succ_sub hbj, nat.succ_sub_succ, tsub_tsub_cancel_of_le hbj.le] }, convert congr_fun i_eq.symm ⟨nat_degree b - j.succ, hj⟩ end /-- If `A` is a family of enough low-degree polynomials over a finite field, there is a pair of elements in `A` (with different indices but not necessarily distinct), such that the difference of their remainders is close together. -/ lemma exists_approx_polynomial {b : polynomial Fq} (hb : b β‰  0) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) (A : fin (fintype.card Fq ^ ⌈- log Ξ΅ / log (fintype.card Fq)βŒ‰β‚Š).succ β†’ polynomial Fq) : βˆƒ iβ‚€ i₁, iβ‚€ β‰  i₁ ∧ (card_pow_degree (A i₁ % b - A iβ‚€ % b) : ℝ) < card_pow_degree b β€’ Ξ΅ := begin have hbΞ΅ : 0 < card_pow_degree b β€’ Ξ΅, { rw [algebra.smul_def, ring_hom.eq_int_cast], exact mul_pos (int.cast_pos.mpr (absolute_value.pos _ hb)) hΞ΅ }, have one_lt_q : 1 < fintype.card Fq := fintype.one_lt_card, have one_lt_q' : (1 : ℝ) < fintype.card Fq, { assumption_mod_cast }, have q_pos : 0 < fintype.card Fq, { linarith }, have q_pos' : (0 : ℝ) < fintype.card Fq, { assumption_mod_cast }, -- If `b` is already small enough, then the remainders are equal and we are done. by_cases le_b : b.nat_degree ≀ ⌈- log Ξ΅ / log (fintype.card Fq)βŒ‰β‚Š, { obtain ⟨iβ‚€, i₁, i_ne, mod_eq⟩ := exists_eq_polynomial le_rfl b le_b (Ξ» i, A i % b) (Ξ» i, euclidean_domain.mod_lt (A i) hb), refine ⟨iβ‚€, i₁, i_ne, _⟩, simp only at mod_eq, rwa [mod_eq, sub_self, absolute_value.map_zero, int.cast_zero] }, -- Otherwise, it suffices to choose two elements whose difference is of small enough degree. rw not_le at le_b, obtain ⟨iβ‚€, i₁, i_ne, deg_lt⟩ := exists_approx_polynomial_aux le_rfl b (Ξ» i, A i % b) (Ξ» i, euclidean_domain.mod_lt (A i) hb), simp only at deg_lt, use [iβ‚€, i₁, i_ne], -- Again, if the remainders are equal we are done. by_cases h : A i₁ % b = A iβ‚€ % b, { rwa [h, sub_self, absolute_value.map_zero, int.cast_zero] }, have h' : A i₁ % b - A iβ‚€ % b β‰  0 := mt sub_eq_zero.mp h, -- If the remainders are not equal, we'll show their difference is of small degree. -- In particular, we'll show the degree is less than the following: suffices : (nat_degree (A i₁ % b - A iβ‚€ % b) : ℝ) < b.nat_degree + log Ξ΅ / log (fintype.card Fq), { rwa [← real.log_lt_log_iff (int.cast_pos.mpr (card_pow_degree.pos h')) hbΞ΅, card_pow_degree_nonzero _ h', card_pow_degree_nonzero _ hb, algebra.smul_def, ring_hom.eq_int_cast, int.cast_pow, int.cast_coe_nat, int.cast_pow, int.cast_coe_nat, log_mul (pow_ne_zero _ q_pos'.ne') hΞ΅.ne', ← rpow_nat_cast, ← rpow_nat_cast, log_rpow q_pos', log_rpow q_pos', ← lt_div_iff (log_pos one_lt_q'), add_div, mul_div_cancel _ (log_pos one_lt_q').ne'] }, -- And that result follows from manipulating the result from `exists_approx_polynomial_aux` -- to turn the `-⌈-stuffβŒ‰β‚Š` into `+ stuff`. refine lt_of_lt_of_le (nat.cast_lt.mpr (with_bot.coe_lt_coe.mp _)) _, swap, { convert deg_lt, rw degree_eq_nat_degree h' }, rw [← sub_neg_eq_add, neg_div], refine le_trans _ (sub_le_sub_left (nat.le_ceil _) (b.nat_degree : ℝ)), rw ← neg_div, exact le_of_eq (nat.cast_sub le_b.le) end /-- If `x` is close to `y` and `y` is close to `z`, then `x` and `z` are at least as close. -/ lemma card_pow_degree_anti_archimedean {x y z : polynomial Fq} {a : β„€} (hxy : card_pow_degree (x - y) < a) (hyz : card_pow_degree (y - z) < a) : card_pow_degree (x - z) < a := begin have ha : 0 < a := lt_of_le_of_lt (absolute_value.nonneg _ _) hxy, by_cases hxy' : x = y, { rwa hxy' }, by_cases hyz' : y = z, { rwa ← hyz' }, by_cases hxz' : x = z, { rwa [hxz', sub_self, absolute_value.map_zero] }, rw [← ne.def, ← sub_ne_zero] at hxy' hyz' hxz', refine lt_of_le_of_lt _ (max_lt hxy hyz), rw [card_pow_degree_nonzero _ hxz', card_pow_degree_nonzero _ hxy', card_pow_degree_nonzero _ hyz'], have : (1 : β„€) ≀ fintype.card Fq, { exact_mod_cast (@fintype.one_lt_card Fq _ _).le }, simp only [int.cast_pow, int.cast_coe_nat, le_max_iff], refine or.imp (pow_le_pow this) (pow_le_pow this) _, rw [nat_degree_le_iff_degree_le, nat_degree_le_iff_degree_le, ← le_max_iff, ← degree_eq_nat_degree hxy', ← degree_eq_nat_degree hyz'], convert degree_add_le (x - y) (y - z) using 2, exact (sub_add_sub_cancel _ _ _).symm end /-- A slightly stronger version of `exists_partition` on which we perform induction on `n`: for all `Ξ΅ > 0`, we can partition the remainders of any family of polynomials `A` into equivalence classes, where the equivalence(!) relation is "closer than `Ξ΅`". -/ lemma exists_partition_polynomial_aux (n : β„•) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) {b : polynomial Fq} (hb : b β‰  0) (A : fin n β†’ polynomial Fq) : βˆƒ (t : fin n β†’ fin (fintype.card Fq ^ ⌈- log Ξ΅ / log (fintype.card Fq)βŒ‰β‚Š)), βˆ€ (iβ‚€ i₁ : fin n), t iβ‚€ = t i₁ ↔ (card_pow_degree (A i₁ % b - A iβ‚€ % b) : ℝ) < card_pow_degree b β€’ Ξ΅ := begin have hbΞ΅ : 0 < card_pow_degree b β€’ Ξ΅, { rw [algebra.smul_def, ring_hom.eq_int_cast], exact mul_pos (int.cast_pos.mpr (absolute_value.pos _ hb)) hΞ΅ }, -- We go by induction on the size `A`. induction n with n ih, { refine ⟨fin_zero_elim, fin_zero_elim⟩ }, -- Show `anti_archimedean` also holds for real distances. have anti_archim' : βˆ€ {i j k} {Ξ΅ : ℝ}, (card_pow_degree (A i % b - A j % b) : ℝ) < Ξ΅ β†’ (card_pow_degree (A j % b - A k % b) : ℝ) < Ξ΅ β†’ (card_pow_degree (A i % b - A k % b) : ℝ) < Ξ΅, { intros i j k Ξ΅, simp_rw [← int.lt_ceil], exact card_pow_degree_anti_archimedean }, obtain ⟨t', ht'⟩ := ih (fin.tail A), -- We got rid of `A 0`, so determine the index `j` of the partition we'll re-add it to. suffices : βˆƒ j, βˆ€ i, t' i = j ↔ (card_pow_degree (A 0 % b - A i.succ % b) : ℝ) < card_pow_degree b β€’ Ξ΅, { obtain ⟨j, hj⟩ := this, refine ⟨fin.cons j t', Ξ» iβ‚€ i₁, _⟩, refine fin.cases _ (Ξ» iβ‚€, _) iβ‚€; refine fin.cases _ (Ξ» i₁, _) i₁, { simpa using hbΞ΅ }, { rw [fin.cons_succ, fin.cons_zero, eq_comm, absolute_value.map_sub], exact hj i₁ }, { rw [fin.cons_succ, fin.cons_zero], exact hj iβ‚€ }, { rw [fin.cons_succ, fin.cons_succ], exact ht' iβ‚€ i₁ } }, -- `exists_approx_polynomial` guarantees that we can insert `A 0` into some partition `j`, -- but not that `j` is uniquely defined (which is needed to keep the induction going). obtain ⟨j, hj⟩ : βˆƒ j, βˆ€ (i : fin n), t' i = j β†’ (card_pow_degree (A 0 % b - A i.succ % b) : ℝ) < card_pow_degree b β€’ Ξ΅, { by_contra this, push_neg at this, obtain ⟨jβ‚€, j₁, j_ne, approx⟩ := exists_approx_polynomial hb hΞ΅ (fin.cons (A 0) (Ξ» j, A (fin.succ (classical.some (this j))))), revert j_ne approx, refine fin.cases _ (Ξ» jβ‚€, _) jβ‚€; refine fin.cases (Ξ» j_ne approx, _) (Ξ» j₁ j_ne approx, _) j₁, { exact absurd rfl j_ne }, { rw [fin.cons_succ, fin.cons_zero, ← not_le, absolute_value.map_sub] at approx, have := (classical.some_spec (this j₁)).2, contradiction }, { rw [fin.cons_succ, fin.cons_zero, ← not_le] at approx, have := (classical.some_spec (this jβ‚€)).2, contradiction }, { rw [fin.cons_succ, fin.cons_succ] at approx, rw [ne.def, fin.succ_inj] at j_ne, have : jβ‚€ = j₁ := (classical.some_spec (this jβ‚€)).1.symm.trans (((ht' (classical.some (this jβ‚€)) (classical.some (this j₁))).mpr approx).trans (classical.some_spec (this j₁)).1), contradiction } }, -- However, if one of those partitions `j` is inhabited by some `i`, then this `j` works. by_cases exists_nonempty_j : βˆƒ j, (βˆƒ i, t' i = j) ∧ βˆ€ i, t' i = j β†’ (card_pow_degree (A 0 % b - A i.succ % b) : ℝ) < card_pow_degree b β€’ Ξ΅, { obtain ⟨j, ⟨i, hi⟩, hj⟩ := exists_nonempty_j, refine ⟨j, Ξ» i', ⟨hj i', Ξ» hi', trans ((ht' _ _).mpr _) hi⟩⟩, apply anti_archim' _ hi', rw absolute_value.map_sub, exact hj _ hi }, -- And otherwise, we can just take any `j`, since those are empty. refine ⟨j, Ξ» i, ⟨hj i, Ξ» hi, _⟩⟩, have := exists_nonempty_j ⟨t' i, ⟨i, rfl⟩, Ξ» i' hi', anti_archim' hi ((ht' _ _).mp hi')⟩, contradiction end /-- For all `Ξ΅ > 0`, we can partition the remainders of any family of polynomials `A` into classes, where all remainders in a class are close together. -/ lemma exists_partition_polynomial (n : β„•) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) {b : polynomial Fq} (hb : b β‰  0) (A : fin n β†’ polynomial Fq) : βˆƒ (t : fin n β†’ fin (fintype.card Fq ^ ⌈- log Ξ΅ / log (fintype.card Fq)βŒ‰β‚Š)), βˆ€ (iβ‚€ i₁ : fin n), t iβ‚€ = t i₁ β†’ (card_pow_degree (A i₁ % b - A iβ‚€ % b) : ℝ) < card_pow_degree b β€’ Ξ΅ := begin obtain ⟨t, ht⟩ := exists_partition_polynomial_aux n hΞ΅ hb A, exact ⟨t, Ξ» iβ‚€ i₁ hi, (ht iβ‚€ i₁).mp hi⟩ end /-- `Ξ» p, fintype.card Fq ^ degree p` is an admissible absolute value. We set `q ^ degree 0 = 0`. -/ noncomputable def card_pow_degree_is_admissible : is_admissible (card_pow_degree : absolute_value (polynomial Fq) β„€) := { card := Ξ» Ξ΅, fintype.card Fq ^ ⌈- log Ξ΅ / log (fintype.card Fq)βŒ‰β‚Š, exists_partition' := Ξ» n Ξ΅ hΞ΅ b hb, exists_partition_polynomial n hΞ΅ hb, .. @card_pow_degree_is_euclidean Fq _ _ } end polynomial
3efd528b0cefa4b280f24b5cd66e1f8b1bf2ea24
9dc8cecdf3c4634764a18254e94d43da07142918
/src/category_theory/preadditive/default.lean
878e29a2ddcc6f6076c33d887cf4783a74f550c8
[ "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
13,584
lean
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Jakob von Raumer -/ import algebra.big_operators.basic import algebra.hom.group import algebra.module.basic import category_theory.endomorphism import category_theory.limits.shapes.kernels /-! # Preadditive categories A preadditive category is a category in which `X ⟢ Y` is an abelian group in such a way that composition of morphisms is linear in both variables. This file contains a definition of preadditive category that directly encodes the definition given above. The definition could also be phrased as follows: A preadditive category is a category enriched over the category of Abelian groups. Once the general framework to state this in Lean is available, the contents of this file should become obsolete. ## Main results * Definition of preadditive categories and basic properties * In a preadditive category, `f : Q ⟢ R` is mono if and only if `g ≫ f = 0 β†’ g = 0` for all composable `g`. * A preadditive category with kernels has equalizers. ## Implementation notes The simp normal form for negation and composition is to push negations as far as possible to the outside. For example, `f ≫ (-g)` and `(-f) ≫ g` both become `-(f ≫ g)`, and `(-f) ≫ (-g)` is simplified to `f ≫ g`. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] ## Tags additive, preadditive, Hom group, Ab-category, Ab-enriched -/ universes v u open category_theory.limits open_locale big_operators namespace category_theory variables (C : Type u) [category.{v} C] /-- A category is called preadditive if `P ⟢ Q` is an abelian group such that composition is linear in both variables. -/ class preadditive := (hom_group : Ξ  P Q : C, add_comm_group (P ⟢ Q) . tactic.apply_instance) (add_comp' : βˆ€ (P Q R : C) (f f' : P ⟢ Q) (g : Q ⟢ R), (f + f') ≫ g = f ≫ g + f' ≫ g . obviously) (comp_add' : βˆ€ (P Q R : C) (f : P ⟢ Q) (g g' : Q ⟢ R), f ≫ (g + g') = f ≫ g + f ≫ g' . obviously) attribute [instance] preadditive.hom_group restate_axiom preadditive.add_comp' restate_axiom preadditive.comp_add' attribute [simp,reassoc] preadditive.add_comp attribute [reassoc] preadditive.comp_add -- (the linter doesn't like `simp` on this lemma) attribute [simp] preadditive.comp_add end category_theory open category_theory namespace category_theory namespace preadditive section preadditive open add_monoid_hom variables {C : Type u} [category.{v} C] [preadditive C] section induced_category universes u' variables {C} {D : Type u'} (F : D β†’ C) instance induced_category.category : preadditive.{v} (induced_category C F) := { hom_group := Ξ» P Q, @preadditive.hom_group C _ _ (F P) (F Q), add_comp' := Ξ» P Q R f f' g, add_comp' _ _ _ _ _ _, comp_add' := Ξ» P Q R f g g', comp_add' _ _ _ _ _ _, } end induced_category instance (X : C) : add_comm_group (End X) := by { dsimp [End], apply_instance, } instance (X : C) : ring (End X) := { left_distrib := Ξ» f g h, preadditive.add_comp X X X g h f, right_distrib := Ξ» f g h, preadditive.comp_add X X X h f g, ..(infer_instance : add_comm_group (End X)), ..(infer_instance : monoid (End X)) } /-- Composition by a fixed left argument as a group homomorphism -/ def left_comp {P Q : C} (R : C) (f : P ⟢ Q) : (Q ⟢ R) β†’+ (P ⟢ R) := mk' (Ξ» g, f ≫ g) $ Ξ» g g', by simp /-- Composition by a fixed right argument as a group homomorphism -/ def right_comp (P : C) {Q R : C} (g : Q ⟢ R) : (P ⟢ Q) β†’+ (P ⟢ R) := mk' (Ξ» f, f ≫ g) $ Ξ» f f', by simp variables {P Q R : C} (f f' : P ⟢ Q) (g g' : Q ⟢ R) /-- Composition as a bilinear group homomorphism -/ def comp_hom : (P ⟢ Q) β†’+ (Q ⟢ R) β†’+ (P ⟢ R) := add_monoid_hom.mk' (Ξ» f, left_comp _ f) $ Ξ» f₁ fβ‚‚, add_monoid_hom.ext $ Ξ» g, (right_comp _ g).map_add f₁ fβ‚‚ @[simp, reassoc] lemma sub_comp : (f - f') ≫ g = f ≫ g - f' ≫ g := map_sub (right_comp P g) f f' -- The redundant simp lemma linter says that simp can prove the reassoc version of this lemma. @[reassoc, simp] lemma comp_sub : f ≫ (g - g') = f ≫ g - f ≫ g' := map_sub (left_comp R f) g g' @[simp, reassoc] lemma neg_comp : (-f) ≫ g = -(f ≫ g) := map_neg (right_comp P g) f /- The redundant simp lemma linter says that simp can prove the reassoc version of this lemma. -/ @[reassoc, simp] lemma comp_neg : f ≫ (-g) = -(f ≫ g) := map_neg (left_comp R f) g @[reassoc] lemma neg_comp_neg : (-f) ≫ (-g) = f ≫ g := by simp lemma nsmul_comp (n : β„•) : (n β€’ f) ≫ g = n β€’ (f ≫ g) := map_nsmul (right_comp P g) n f lemma comp_nsmul (n : β„•) : f ≫ (n β€’ g) = n β€’ (f ≫ g) := map_nsmul (left_comp R f) n g lemma zsmul_comp (n : β„€) : (n β€’ f) ≫ g = n β€’ (f ≫ g) := map_zsmul (right_comp P g) n f lemma comp_zsmul (n : β„€) : f ≫ (n β€’ g) = n β€’ (f ≫ g) := map_zsmul (left_comp R f) n g @[reassoc] lemma comp_sum {P Q R : C} {J : Type*} (s : finset J) (f : P ⟢ Q) (g : J β†’ (Q ⟢ R)) : f ≫ βˆ‘ j in s, g j = βˆ‘ j in s, f ≫ g j := map_sum (left_comp R f) _ _ @[reassoc] lemma sum_comp {P Q R : C} {J : Type*} (s : finset J) (f : J β†’ (P ⟢ Q)) (g : Q ⟢ R) : (βˆ‘ j in s, f j) ≫ g = βˆ‘ j in s, f j ≫ g := map_sum (right_comp P g) _ _ instance {P Q : C} {f : P ⟢ Q} [epi f] : epi (-f) := ⟨λ R g g' H, by rwa [neg_comp, neg_comp, ←comp_neg, ←comp_neg, cancel_epi, neg_inj] at H⟩ instance {P Q : C} {f : P ⟢ Q} [mono f] : mono (-f) := ⟨λ R g g' H, by rwa [comp_neg, comp_neg, ←neg_comp, ←neg_comp, cancel_mono, neg_inj] at H⟩ @[priority 100] instance preadditive_has_zero_morphisms : has_zero_morphisms C := { has_zero := infer_instance, comp_zero' := Ξ» P Q f R, show left_comp R f 0 = 0, from map_zero _, zero_comp' := Ξ» P Q R f, show right_comp P f 0 = 0, from map_zero _ } instance module_End_right {X Y : C} : module (End Y) (X ⟢ Y) := { smul_add := Ξ» r f g, add_comp _ _ _ _ _ _, smul_zero := Ξ» r, zero_comp, add_smul := Ξ» r s f, comp_add _ _ _ _ _ _, zero_smul := Ξ» r, comp_zero } lemma mono_of_cancel_zero {Q R : C} (f : Q ⟢ R) (h : βˆ€ {P : C} (g : P ⟢ Q), g ≫ f = 0 β†’ g = 0) : mono f := ⟨λ P g g' hg, sub_eq_zero.1 $ h _ $ (map_sub (right_comp P f) g g').trans $ sub_eq_zero.2 hg⟩ lemma mono_iff_cancel_zero {Q R : C} (f : Q ⟢ R) : mono f ↔ βˆ€ (P : C) (g : P ⟢ Q), g ≫ f = 0 β†’ g = 0 := ⟨λ m P g, by exactI zero_of_comp_mono _, mono_of_cancel_zero f⟩ lemma mono_of_kernel_zero {X Y : C} {f : X ⟢ Y} [has_limit (parallel_pair f 0)] (w : kernel.ΞΉ f = 0) : mono f := mono_of_cancel_zero f (Ξ» P g h, by rw [←kernel.lift_ΞΉ f g h, w, limits.comp_zero]) lemma epi_of_cancel_zero {P Q : C} (f : P ⟢ Q) (h : βˆ€ {R : C} (g : Q ⟢ R), f ≫ g = 0 β†’ g = 0) : epi f := ⟨λ R g g' hg, sub_eq_zero.1 $ h _ $ (map_sub (left_comp R f) g g').trans $ sub_eq_zero.2 hg⟩ lemma epi_iff_cancel_zero {P Q : C} (f : P ⟢ Q) : epi f ↔ βˆ€ (R : C) (g : Q ⟢ R), f ≫ g = 0 β†’ g = 0 := ⟨λ e R g, by exactI zero_of_epi_comp _, epi_of_cancel_zero f⟩ lemma epi_of_cokernel_zero {X Y : C} {f : X ⟢ Y} [has_colimit (parallel_pair f 0 )] (w : cokernel.Ο€ f = 0) : epi f := epi_of_cancel_zero f (Ξ» P g h, by rw [←cokernel.Ο€_desc f g h, w, limits.zero_comp]) namespace is_iso @[simp] lemma comp_left_eq_zero [is_iso f] : f ≫ g = 0 ↔ g = 0 := by rw [← is_iso.eq_inv_comp, limits.comp_zero] @[simp] lemma comp_right_eq_zero [is_iso g] : f ≫ g = 0 ↔ f = 0 := by rw [← is_iso.eq_comp_inv, limits.zero_comp] end is_iso open_locale zero_object variables [has_zero_object C] lemma mono_of_kernel_iso_zero {X Y : C} {f : X ⟢ Y} [has_limit (parallel_pair f 0)] (w : kernel f β‰… 0) : mono f := mono_of_kernel_zero (zero_of_source_iso_zero _ w) lemma epi_of_cokernel_iso_zero {X Y : C} {f : X ⟢ Y} [has_colimit (parallel_pair f 0)] (w : cokernel f β‰… 0) : epi f := epi_of_cokernel_zero (zero_of_target_iso_zero _ w) end preadditive section equalizers variables {C : Type u} [category.{v} C] [preadditive C] section variables {X Y : C} {f : X ⟢ Y} {g : X ⟢ Y} /-- Map a kernel cone on the difference of two morphisms to the equalizer fork. -/ @[simps X] def fork_of_kernel_fork (c : kernel_fork (f - g)) : fork f g := fork.of_ΞΉ c.ΞΉ $ by rw [← sub_eq_zero, ← comp_sub, c.condition] @[simp] lemma fork_of_kernel_fork_ΞΉ (c : kernel_fork (f - g)) : (fork_of_kernel_fork c).ΞΉ = c.ΞΉ := rfl /-- Map any equalizer fork to a cone on the difference of the two morphisms. -/ def kernel_fork_of_fork (c : fork f g) : kernel_fork (f - g) := fork.of_ΞΉ c.ΞΉ $ by rw [comp_sub, comp_zero, sub_eq_zero, c.condition] @[simp] lemma kernel_fork_of_fork_ΞΉ (c : fork f g) : (kernel_fork_of_fork c).ΞΉ = c.ΞΉ := rfl @[simp] lemma kernel_fork_of_fork_of_ΞΉ {P : C} (ΞΉ : P ⟢ X) (w : ΞΉ ≫ f = ΞΉ ≫ g) : (kernel_fork_of_fork (fork.of_ΞΉ ΞΉ w)) = kernel_fork.of_ΞΉ ΞΉ (by simp [w]) := rfl /-- A kernel of `f - g` is an equalizer of `f` and `g`. -/ def is_limit_fork_of_kernel_fork {c : kernel_fork (f - g)} (i : is_limit c) : is_limit (fork_of_kernel_fork c) := fork.is_limit.mk' _ $ Ξ» s, ⟨i.lift (kernel_fork_of_fork s), i.fac _ _, Ξ» m h, by apply fork.is_limit.hom_ext i; tidy⟩ @[simp] lemma is_limit_fork_of_kernel_fork_lift {c : kernel_fork (f - g)} (i : is_limit c) (s : fork f g) : (is_limit_fork_of_kernel_fork i).lift s = i.lift (kernel_fork_of_fork s) := rfl /-- An equalizer of `f` and `g` is a kernel of `f - g`. -/ def is_limit_kernel_fork_of_fork {c : fork f g} (i : is_limit c) : is_limit (kernel_fork_of_fork c) := fork.is_limit.mk' _ $ Ξ» s, ⟨i.lift (fork_of_kernel_fork s), i.fac _ _, Ξ» m h, by apply fork.is_limit.hom_ext i; tidy⟩ variables (f g) /-- A preadditive category has an equalizer for `f` and `g` if it has a kernel for `f - g`. -/ lemma has_equalizer_of_has_kernel [has_kernel (f - g)] : has_equalizer f g := has_limit.mk { cone := fork_of_kernel_fork _, is_limit := is_limit_fork_of_kernel_fork (equalizer_is_equalizer (f - g) 0) } /-- A preadditive category has a kernel for `f - g` if it has an equalizer for `f` and `g`. -/ lemma has_kernel_of_has_equalizer [has_equalizer f g] : has_kernel (f - g) := has_limit.mk { cone := kernel_fork_of_fork (equalizer.fork f g), is_limit := is_limit_kernel_fork_of_fork (limit.is_limit (parallel_pair f g)) } variables {f g} /-- Map a cokernel cocone on the difference of two morphisms to the coequalizer cofork. -/ @[simps X] def cofork_of_cokernel_cofork (c : cokernel_cofork (f - g)) : cofork f g := cofork.of_Ο€ c.Ο€ $ by rw [← sub_eq_zero, ← sub_comp, c.condition] @[simp] lemma cofork_of_cokernel_cofork_Ο€ (c : cokernel_cofork (f - g)) : (cofork_of_cokernel_cofork c).Ο€ = c.Ο€ := rfl /-- Map any coequalizer cofork to a cocone on the difference of the two morphisms. -/ def cokernel_cofork_of_cofork (c : cofork f g) : cokernel_cofork (f - g) := cofork.of_Ο€ c.Ο€ $ by rw [sub_comp, zero_comp, sub_eq_zero, c.condition] @[simp] lemma cokernel_cofork_of_cofork_Ο€ (c : cofork f g) : (cokernel_cofork_of_cofork c).Ο€ = c.Ο€ := rfl @[simp] lemma cokernel_cofork_of_cofork_of_Ο€ {P : C} (Ο€ : Y ⟢ P) (w : f ≫ Ο€ = g ≫ Ο€) : (cokernel_cofork_of_cofork (cofork.of_Ο€ Ο€ w)) = cokernel_cofork.of_Ο€ Ο€ (by simp [w]) := rfl /-- A cokernel of `f - g` is a coequalizer of `f` and `g`. -/ def is_colimit_cofork_of_cokernel_cofork {c : cokernel_cofork (f - g)} (i : is_colimit c) : is_colimit (cofork_of_cokernel_cofork c) := cofork.is_colimit.mk' _ $ Ξ» s, ⟨i.desc (cokernel_cofork_of_cofork s), i.fac _ _, Ξ» m h, by apply cofork.is_colimit.hom_ext i; tidy⟩ @[simp] lemma is_colimit_cofork_of_cokernel_cofork_desc {c : cokernel_cofork (f - g)} (i : is_colimit c) (s : cofork f g) : (is_colimit_cofork_of_cokernel_cofork i).desc s = i.desc (cokernel_cofork_of_cofork s) := rfl /-- A coequalizer of `f` and `g` is a cokernel of `f - g`. -/ def is_colimit_cokernel_cofork_of_cofork {c : cofork f g} (i : is_colimit c) : is_colimit (cokernel_cofork_of_cofork c) := cofork.is_colimit.mk' _ $ Ξ» s, ⟨i.desc (cofork_of_cokernel_cofork s), i.fac _ _, Ξ» m h, by apply cofork.is_colimit.hom_ext i; tidy⟩ variables (f g) /-- A preadditive category has a coequalizer for `f` and `g` if it has a cokernel for `f - g`. -/ lemma has_coequalizer_of_has_cokernel [has_cokernel (f - g)] : has_coequalizer f g := has_colimit.mk { cocone := cofork_of_cokernel_cofork _, is_colimit := is_colimit_cofork_of_cokernel_cofork (coequalizer_is_coequalizer (f - g) 0) } /-- A preadditive category has a cokernel for `f - g` if it has a coequalizer for `f` and `g`. -/ lemma has_cokernel_of_has_coequalizer [has_coequalizer f g] : has_cokernel (f - g) := has_colimit.mk { cocone := cokernel_cofork_of_cofork (coequalizer.cofork f g), is_colimit := is_colimit_cokernel_cofork_of_cofork (colimit.is_colimit (parallel_pair f g)) } end /-- If a preadditive category has all kernels, then it also has all equalizers. -/ lemma has_equalizers_of_has_kernels [has_kernels C] : has_equalizers C := @has_equalizers_of_has_limit_parallel_pair _ _ (Ξ» _ _ f g, has_equalizer_of_has_kernel f g) /-- If a preadditive category has all cokernels, then it also has all coequalizers. -/ lemma has_coequalizers_of_has_cokernels [has_cokernels C] : has_coequalizers C := @has_coequalizers_of_has_colimit_parallel_pair _ _ (Ξ» _ _ f g, has_coequalizer_of_has_cokernel f g) end equalizers end preadditive end category_theory
8776e9b2611bd5093323a50d737c871623e3f5bc
9dc8cecdf3c4634764a18254e94d43da07142918
/src/data/nat/choose/central.lean
d5e9bebe5f13c67b71501fb5431bf5d55a65b6fa
[ "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
5,191
lean
/- Copyright (c) 2021 Patrick Stevens. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Stevens, Thomas Browning -/ import data.nat.choose.basic import data.nat.choose.sum /-! # Central binomial coefficients This file proves properties of the central binomial coefficients (that is, `nat.choose (2 * n) n`). ## Main definition and results * `nat.central_binom`: the central binomial coefficient, `(2 * n).choose n`. * `nat.succ_mul_central_binom_succ`: the inductive relationship between successive central binomial coefficients. * `nat.four_pow_lt_mul_central_binom`: an exponential lower bound on the central binomial coefficient. * `succ_dvd_central_binom`: The result that `n+1 ∣ n.central_binom`, ensuring that the explicit definition of the Catalan numbers is integer-valued. -/ namespace nat /-- The central binomial coefficient, `nat.choose (2 * n) n`. -/ def central_binom (n : β„•) := (2 * n).choose n lemma central_binom_eq_two_mul_choose (n : β„•) : central_binom n = (2 * n).choose n := rfl lemma central_binom_pos (n : β„•) : 0 < central_binom n := choose_pos (nat.le_mul_of_pos_left zero_lt_two) lemma central_binom_ne_zero (n : β„•) : central_binom n β‰  0 := (central_binom_pos n).ne' @[simp] lemma central_binom_zero : central_binom 0 = 1 := choose_zero_right _ /-- The central binomial coefficient is the largest binomial coefficient. -/ lemma choose_le_central_binom (r n : β„•) : choose (2 * n) r ≀ central_binom n := calc (2 * n).choose r ≀ (2 * n).choose (2 * n / 2) : choose_le_middle r (2 * n) ... = (2 * n).choose n : by rw nat.mul_div_cancel_left n zero_lt_two lemma two_le_central_binom (n : β„•) (n_pos : 0 < n) : 2 ≀ central_binom n := calc 2 ≀ 2 * n : le_mul_of_pos_right n_pos ... = (2 * n).choose 1 : (choose_one_right (2 * n)).symm ... ≀ central_binom n : choose_le_central_binom 1 n /-- An inductive property of the central binomial coefficient. -/ lemma succ_mul_central_binom_succ (n : β„•) : (n + 1) * central_binom (n + 1) = 2 * (2 * n + 1) * central_binom n := calc (n + 1) * (2 * (n + 1)).choose (n + 1) = (2 * n + 2).choose (n + 1) * (n + 1) : mul_comm _ _ ... = (2 * n + 1).choose n * (2 * n + 2) : by rw [choose_succ_right_eq, choose_mul_succ_eq] ... = 2 * ((2 * n + 1).choose n * (n + 1)) : by ring ... = 2 * ((2 * n + 1).choose n * ((2 * n + 1) - n)) : by rw [two_mul n, add_assoc, nat.add_sub_cancel_left] ... = 2 * ((2 * n).choose n * (2 * n + 1)) : by rw choose_mul_succ_eq ... = (2 * (2 * n + 1)) * (2 * n).choose n : by rw [mul_assoc, mul_comm (2 * n + 1)] /-- An exponential lower bound on the central binomial coefficient. This bound is of interest because it appears in [Tochiori's refinement of ErdΕ‘s's proof of Bertrand's postulate](tochiori_bertrand). -/ lemma four_pow_lt_mul_central_binom (n : β„•) (n_big : 4 ≀ n) : 4 ^ n < n * central_binom n := begin induction n using nat.strong_induction_on with n IH, rcases lt_trichotomy n 4 with (hn|rfl|hn), { clear IH, dec_trivial! }, { norm_num [central_binom, choose] }, obtain ⟨n, rfl⟩ : βˆƒ m, n = m + 1 := nat.exists_eq_succ_of_ne_zero (zero_lt_four.trans hn).ne', calc 4 ^ (n + 1) < 4 * (n * central_binom n) : (mul_lt_mul_left zero_lt_four).mpr (IH n n.lt_succ_self (nat.le_of_lt_succ hn)) ... ≀ 2 * (2 * n + 1) * central_binom n : by { rw ← mul_assoc, linarith } ... = (n + 1) * central_binom (n + 1) : (succ_mul_central_binom_succ n).symm, end /-- An exponential lower bound on the central binomial coefficient. This bound is weaker than `nat.four_pow_lt_mul_central_binom`, but it is of historical interest because it appears in ErdΕ‘s's proof of Bertrand's postulate. -/ lemma four_pow_le_two_mul_self_mul_central_binom : βˆ€ (n : β„•) (n_pos : 0 < n), 4 ^ n ≀ (2 * n) * central_binom n | 0 pr := (nat.not_lt_zero _ pr).elim | 1 pr := by norm_num [central_binom, choose] | 2 pr := by norm_num [central_binom, choose] | 3 pr := by norm_num [central_binom, choose] | n@(m + 4) _ := calc 4 ^ n ≀ n * central_binom n : (four_pow_lt_mul_central_binom _ le_add_self).le ... ≀ 2 * n * central_binom n : by { rw [mul_assoc], refine le_mul_of_pos_left zero_lt_two } lemma two_dvd_central_binom_succ (n : β„•) : 2 ∣ central_binom (n + 1) := begin use (n+1+n).choose n, rw [central_binom_eq_two_mul_choose, two_mul, ← add_assoc, choose_succ_succ, choose_symm_add, ← two_mul], end lemma two_dvd_central_binom_of_one_le {n : β„•} (h : 0 < n) : 2 ∣ central_binom n := begin rw ← nat.succ_pred_eq_of_pos h, exact two_dvd_central_binom_succ n.pred, end /-- A crucial lemma to ensure that Catalan numbers can be defined via their explicit formula `catalan n = n.central_binom / (n + 1)`. -/ lemma succ_dvd_central_binom (n : β„•) : (n + 1) ∣ n.central_binom := begin have h_s : (n+1).coprime (2*n+1), { rw [two_mul,add_assoc, coprime_add_self_right, coprime_self_add_left], exact coprime_one_left n }, apply h_s.dvd_of_dvd_mul_left, apply dvd_of_mul_dvd_mul_left zero_lt_two, rw [← mul_assoc, ← succ_mul_central_binom_succ, mul_comm], exact mul_dvd_mul_left _ (two_dvd_central_binom_succ n), end end nat
1fdaf70d5b14a4e902426bdadea0869d42399e61
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/tactic/simps.lean
b66df7fc71e1cd4fd2f426835578bdae62461b3b
[ "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
47,635
lean
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import tactic.protected import tactic.to_additive /-! # simps attribute This file defines the `@[simps]` attribute, to automatically generate `simp` lemmas reducing a definition when projections are applied to it. ## Implementation Notes There are three attributes being defined here * `@[simps]` is the attribute for objects of a structure or instances of a class. It will automatically generate simplification lemmas for each projection of the object/instance that contains data. See the doc strings for `simps_attr` and `simps_cfg` for more details and configuration options. * `@[_simps_str]` is automatically added to structures that have been used in `@[simps]` at least once. This attribute contains the data of the projections used for this structure by all following invocations of `@[simps]`. * `@[notation_class]` should be added to all classes that define notation, like `has_mul` and `has_zero`. This specifies that the projections that `@[simps]` used are the projections from these notation classes instead of the projections of the superclasses. Example: if `has_mul` is tagged with `@[notation_class]` then the projection used for `semigroup` will be `Ξ» Ξ± hΞ±, @has_mul.mul Ξ± (@semigroup.to_has_mul Ξ± hΞ±)` instead of `@semigroup.mul`. ## Tags structures, projections, simp, simplifier, generates declarations -/ open tactic expr option sum setup_tactic_parser declare_trace simps.verbose declare_trace simps.debug /-- Projection data for a single projection of a structure, consisting of the following fields: - the name used in the generated `simp` lemmas - an expression used by simps for the projection. It must be definitionally equal to an original projection (or a composition of multiple projections). These expressions can contain the universe parameters specified in the first argument of `simps_str_attr`. - a list of natural numbers, which is the projection number(s) that have to be applied to the expression. For example the list `[0, 1]` corresponds to applying the first projection of the structure, and then the second projection of the resulting structure (this assumes that the target of the first projection is a structure with at least two projections). The composition of these projections is required to be definitionally equal to the provided expression. - A boolean specifying whether `simp` lemmas are generated for this projection by default. - A boolean specifying whether this projection is written as prefix. -/ @[protect_proj, derive [has_reflect, inhabited]] meta structure projection_data := (name : name) (expr : expr) (proj_nrs : list β„•) (is_default : bool) (is_prefix : bool) /-- Temporary projection data parsed from `initialize_simps_projections` before the expression matching this projection has been found. Only used internally in `simps_get_raw_projections`. -/ meta structure parsed_projection_data := (orig_name : name) -- name for this projection used in the structure definition (new_name : name) -- name for this projection used in the generated `simp` lemmas (is_default : bool) (is_prefix : bool) section open format meta instance : has_to_tactic_format projection_data := ⟨λ ⟨a, b, c, d, e⟩, (Ξ» x, group $ nest 1 $ to_fmt "⟨" ++ to_fmt a ++ to_fmt "," ++ line ++ x ++ to_fmt "," ++ line ++ to_fmt c ++ to_fmt "," ++ line ++ to_fmt d ++ to_fmt "," ++ line ++ to_fmt e ++ to_fmt "⟩") <$> pp b⟩ meta instance : has_to_format parsed_projection_data := ⟨λ ⟨a, b, c, d⟩, group $ nest 1 $ to_fmt "⟨" ++ to_fmt a ++ to_fmt "," ++ line ++ to_fmt b ++ to_fmt "," ++ line ++ to_fmt c ++ to_fmt "," ++ line ++ to_fmt d ++ to_fmt "⟩"⟩ end /-- The type of rules that specify how metadata for projections in changes. See `initialize_simps_projection`. -/ abbreviation projection_rule := (name Γ— name βŠ• name) Γ— bool /-- The `@[_simps_str]` attribute specifies the preferred projections of the given structure, used by the `@[simps]` attribute. - This will usually be tagged by the `@[simps]` tactic. - You can also generate this with the command `initialize_simps_projections`. - To change the default value, see Note [custom simps projection]. - You are strongly discouraged to add this attribute manually. - The first argument is the list of names of the universe variables used in the structure - The second argument is a list that consists of the projection data for each projection. -/ @[user_attribute] meta def simps_str_attr : user_attribute unit (list name Γ— list projection_data) := { name := `_simps_str, descr := "An attribute specifying the projection of the given structure.", parser := failed } /-- The `@[notation_class]` attribute specifies that this is a notation class, and this notation should be used instead of projections by @[simps]. * The first argument `tt` for notation classes and `ff` for classes applied to the structure, like `has_coe_to_sort` and `has_coe_to_fun` * The second argument is the name of the projection (by default it is the first projection of the structure) -/ @[user_attribute] meta def notation_class_attr : user_attribute unit (bool Γ— option name) := { name := `notation_class, descr := "An attribute specifying that this is a notation class. Used by @[simps].", parser := prod.mk <$> (option.is_none <$> (tk "*")?) <*> ident? } attribute [notation_class] has_zero has_one has_add has_mul has_inv has_neg has_sub has_div has_dvd has_mod has_le has_lt has_append has_andthen has_union has_inter has_sdiff has_equiv has_subset has_ssubset has_emptyc has_insert has_singleton has_sep has_mem has_pow attribute [notation_class* coe_sort] has_coe_to_sort attribute [notation_class* coe_fn] has_coe_to_fun /-- Returns the projection information of a structure. -/ meta def projections_info (l : list projection_data) (pref : string) (str : name) : tactic format := do ⟨defaults, nondefaults⟩ ← return $ l.partition_map $ Ξ» s, if s.is_default then inl s else inr s, to_print ← defaults.mmap $ Ξ» s, to_string <$> let prefix_str := if s.is_prefix then "(prefix) " else "" in pformat!"Projection {prefix_str}{s.name}: {s.expr}", let print2 := string.join $ (nondefaults.map (Ξ» nm : projection_data, to_string nm.1)).intersperse ", ", let to_print := to_print ++ if nondefaults.length = 0 then [] else ["No lemmas are generated for the projections: " ++ print2 ++ "."], let to_print := string.join $ to_print.intersperse "\n > ", return format!"[simps] > {pref} {str}:\n > {to_print}" /-- Auxiliary function of `get_composite_of_projections`. -/ meta def get_composite_of_projections_aux : Ξ  (str : name) (proj : string) (x : expr) (pos : list β„•) (args : list expr), tactic (expr Γ— list β„•) | str proj x pos args := do e ← get_env, projs ← e.structure_fields str, let proj_info := projs.map_with_index $ Ξ» n p, (Ξ» x, (x, n, p)) <$> proj.get_rest ("_" ++ p.last), when (proj_info.filter_map id = []) $ fail!"Failed to find constructor {proj.popn 1} in structure {str}.", (proj_rest, index, proj_nm) ← return (proj_info.filter_map id).ilast, str_d ← e.get str, let proj_e : expr := const (str ++ proj_nm) str_d.univ_levels, proj_d ← e.get (str ++ proj_nm), type ← infer_type x, let params := get_app_args type, let univs := proj_d.univ_params.zip type.get_app_fn.univ_levels, let new_x := (proj_e.instantiate_univ_params univs).mk_app $ params ++ [x], let new_pos := pos ++ [index], if proj_rest.is_empty then return (new_x.lambdas args, new_pos) else do type ← infer_type new_x, (type_args, tgt) ← open_pis_whnf type, let new_str := tgt.get_app_fn.const_name, get_composite_of_projections_aux new_str proj_rest (new_x.mk_app type_args) new_pos (args ++ type_args) /-- Given a structure `str` and a projection `proj`, that could be multiple nested projections (separated by `_`), returns an expression that is the composition of these projections and a list of natural numbers, that are the projection numbers of the applied projections. -/ meta def get_composite_of_projections (str : name) (proj : string) : tactic (expr Γ— list β„•) := do e ← get_env, str_d ← e.get str, let str_e : expr := const str str_d.univ_levels, type ← infer_type str_e, (type_args, tgt) ← open_pis_whnf type, let str_ap := str_e.mk_app type_args, x ← mk_local' `x binder_info.default str_ap, get_composite_of_projections_aux str ("_" ++ proj) x [] $ type_args ++ [x] /-- Get the projections used by `simps` associated to a given structure `str`. The returned information is also stored in a parameter of the attribute `@[_simps_str]`, which is given to `str`. If `str` already has this attribute, the information is read from this attribute instead. See the documentation for this attribute for the data this tactic returns. The returned universe levels are the universe levels of the structure. For the projections there are three cases * If the declaration `{structure_name}.simps.{projection_name}` has been declared, then the value of this declaration is used (after checking that it is definitionally equal to the actual projection. If you rename the projection name, the declaration should have the *new* projection name. * You can also declare a custom projection that is a composite of multiple projections. * Otherwise, for every class with the `notation_class` attribute, and the structure has an instance of that notation class, then the projection of that notation class is used for the projection that is definitionally equal to it (if there is such a projection). This means in practice that coercions to function types and sorts will be used instead of a projection, if this coercion is definitionally equal to a projection. Furthermore, for notation classes like `has_mul` and `has_zero` those projections are used instead of the corresponding projection. Projections for coercions and notation classes are not automatically generated if they are composites of multiple projections (for example when you use `extend` without the `old_structure_cmd`). * Otherwise, the projection of the structure is chosen. For example: ``simps_get_raw_projections env `prod`` gives the default projections ``` ([u, v], [prod.fst.{u v}, prod.snd.{u v}]) ``` while ``simps_get_raw_projections env `equiv`` gives ``` ([u_1, u_2], [Ξ» Ξ± Ξ², coe_fn, Ξ» {Ξ± Ξ²} (e : Ξ± ≃ Ξ²), ⇑(e.symm), left_inv, right_inv]) ``` after declaring the coercion from `equiv` to function and adding the declaration ``` def equiv.simps.inv_fun {Ξ± Ξ²} (e : Ξ± ≃ Ξ²) : Ξ² β†’ Ξ± := e.symm ``` Optionally, this command accepts three optional arguments: * If `trace_if_exists` the command will always generate a trace message when the structure already has the attribute `@[_simps_str]`. * The `rules` argument accepts a list of pairs `sum.inl (old_name, new_name)`. This is used to change the projection name `old_name` to the custom projection name `new_name`. Example: for the structure `equiv` the projection `to_fun` could be renamed `apply`. This name will be used for parsing and generating projection names. This argument is ignored if the structure already has an existing attribute. If an element of `rules` is of the form `sum.inr name`, this means that the projection `name` will not be applied by default. * if `trc` is true, this tactic will trace information. -/ -- if performance becomes a problem, possible heuristic: use the names of the projections to -- skip all classes that don't have the corresponding field. meta def simps_get_raw_projections (e : environment) (str : name) (trace_if_exists : bool := ff) (rules : list projection_rule := []) (trc := ff) : tactic (list name Γ— list projection_data) := do let trc := trc || is_trace_enabled_for `simps.verbose, has_attr ← has_attribute' `_simps_str str, if has_attr then do data ← simps_str_attr.get_param str, -- We always print the projections when they already exists and are called by -- `initialize_simps_projections`. when (trace_if_exists || is_trace_enabled_for `simps.verbose) $ projections_info data.2 "Already found projection information for structure" str >>= trace, return data else do when trc trace!"[simps] > generating projection information for structure {str}.", when_tracing `simps.debug trace!"[simps] > Applying the rules {rules}.", d_str ← e.get str, let raw_univs := d_str.univ_params, let raw_levels := level.param <$> raw_univs, /- Figure out projections, including renamings. The information for a projection is (before we figure out the `expr` of the projection: `(original name, given name, is default, is prefix)`. The first projections are always the actual projections of the structure, but `rules` could specify custom projections that are compositions of multiple projections. -/ projs ← e.structure_fields str, let projs : list parsed_projection_data := projs.map $ Ξ» nm, ⟨nm, nm, tt, ff⟩, let projs : list parsed_projection_data := rules.foldl (Ξ» projs rule, match rule with | (inl (old_nm, new_nm), is_prefix) := if old_nm ∈ projs.map (Ξ» x, x.new_name) then projs.map $ Ξ» proj, if proj.new_name = old_nm then { new_name := new_nm, is_prefix := is_prefix, ..proj } else proj else projs ++ [⟨old_nm, new_nm, tt, is_prefix⟩] | (inr nm, is_prefix) := if nm ∈ projs.map (Ξ» x, x.new_name) then projs.map $ Ξ» proj, if proj.new_name = nm then { is_default := ff, is_prefix := is_prefix, ..proj } else proj else projs ++ [⟨nm, nm, ff, is_prefix⟩] end) projs, when_tracing `simps.debug trace!"[simps] > Projection info after applying the rules: {projs}.", when Β¬ (projs.map $ Ξ» x, x.new_name : list name).nodup $ fail $ "Invalid projection names. Two projections have the same name. This is likely because a custom composition of projections was given the same name as an " ++ "existing projection. Solution: rename the existing projection (before renaming the custom " ++ "projection).", /- Define the raw expressions for the projections, by default as the projections (as an expression), but this can be overriden by the user. -/ raw_exprs_and_nrs ← projs.mmap $ Ξ» ⟨orig_nm, new_nm, _, _⟩, do { (raw_expr, nrs) ← get_composite_of_projections str orig_nm.last, custom_proj ← do { decl ← e.get (str ++ `simps ++ new_nm.last), let custom_proj := decl.value.instantiate_univ_params $ decl.univ_params.zip raw_levels, when trc trace! "[simps] > found custom projection for {new_nm}:\n > {custom_proj}", return custom_proj } <|> return raw_expr, is_def_eq custom_proj raw_expr <|> -- if the type of the expression is different, we show a different error message, because -- that is more likely going to be helpful. do { custom_proj_type ← infer_type custom_proj, raw_expr_type ← infer_type raw_expr, b ← succeeds (is_def_eq custom_proj_type raw_expr_type), if b then fail!"Invalid custom projection:\n {custom_proj} Expression is not definitionally equal to\n {raw_expr}" else fail!"Invalid custom projection:\n {custom_proj} Expression has different type than {str ++ orig_nm}. Given type:\n {custom_proj_type} Expected type:\n {raw_expr_type}" }, return (custom_proj, nrs) }, let raw_exprs := raw_exprs_and_nrs.map prod.fst, /- Check for other coercions and type-class arguments to use as projections instead. -/ (args, _) ← open_pis d_str.type, let e_str := (expr.const str raw_levels).mk_app args, automatic_projs ← attribute.get_instances `notation_class, raw_exprs ← automatic_projs.mfoldl (Ξ» (raw_exprs : list expr) class_nm, do { (is_class, proj_nm) ← notation_class_attr.get_param class_nm, proj_nm ← proj_nm <|> (e.structure_fields_full class_nm).map list.head, /- For this class, find the projection. `raw_expr` is the projection found applied to `args`, and `lambda_raw_expr` has the arguments `args` abstracted. -/ (raw_expr, lambda_raw_expr) ← if is_class then (do guard $ args.length = 1, let e_inst_type := (const class_nm raw_levels).mk_app args, (hyp, e_inst) ← try_for 1000 (mk_conditional_instance e_str e_inst_type), raw_expr ← mk_mapp proj_nm [args.head, e_inst], clear hyp, -- Note: `expr.bind_lambda` doesn't give the correct type raw_expr_lambda ← lambdas [hyp] raw_expr, return (raw_expr, raw_expr_lambda.lambdas args)) else (do e_inst_type ← to_expr (((const class_nm []).app (pexpr.of_expr e_str)).app ``(_)), e_inst ← try_for 1000 (mk_instance e_inst_type), raw_expr ← mk_mapp proj_nm [e_str, none, e_inst], return (raw_expr, raw_expr.lambdas args)), raw_expr_whnf ← whnf raw_expr, let relevant_proj := raw_expr_whnf.binding_body.get_app_fn.const_name, /- Use this as projection, if the function reduces to a projection, and this projection has not been overrriden by the user. -/ guard $ projs.any $ Ξ» x, x.1 = relevant_proj.last ∧ Β¬ e.contains (str ++ `simps ++ x.new_name.last), let pos := projs.find_index (Ξ» x, x.1 = relevant_proj.last), when trc trace! " > using {proj_nm} instead of the default projection {relevant_proj.last}.", when_tracing `simps.debug trace!"[simps] > The raw projection is:\n {lambda_raw_expr}", return $ raw_exprs.update_nth pos lambda_raw_expr } <|> return raw_exprs) raw_exprs, let positions := raw_exprs_and_nrs.map prod.snd, let proj_names := projs.map (Ξ» x, x.new_name), let defaults := projs.map (Ξ» x, x.is_default), let prefixes := projs.map (Ξ» x, x.is_prefix), let projs := proj_names.zip_with5 projection_data.mk raw_exprs positions defaults prefixes, /- make all proof non-default. -/ projs ← projs.mmap $ Ξ» proj, is_proof proj.expr >>= Ξ» b, return $ if b then { is_default := ff, .. proj } else proj, when trc $ projections_info projs "generated projections for" str >>= trace, simps_str_attr.set str (raw_univs, projs) tt, when_tracing `simps.debug trace! "[simps] > Generated raw projection data: \n{(raw_univs, projs)}", return (raw_univs, projs) /-- Parse a rule for `initialize_simps_projections`. It is either `<name>β†’<name>` or `-<name>`, possibly following by `as_prefix`.-/ meta def simps_parse_rule : parser projection_rule := prod.mk <$> ((Ξ» x y, inl (x, y)) <$> ident <*> (tk "->" >> ident) <|> inr <$> (tk "-" >> ident)) <*> is_some <$> (tk "as_prefix")? /-- You can specify custom projections for the `@[simps]` attribute. To do this for the projection `my_structure.original_projection` by adding a declaration `my_structure.simps.my_projection` that is definitionally equal to `my_structure.original_projection` but has the projection in the desired (simp-normal) form. Then you can call ``` initialize_simps_projections (original_projection β†’ my_projection, ...) ``` to register this projection. See `initialize_simps_projections_cmd` for more information. You can also specify custom projections that are definitionally equal to a composite of multiple projections. This is often desirable when extending structures (without `old_structure_cmd`). `has_coe_to_fun` and notation class (like `has_mul`) instances will be automatically used, if they are definitionally equal to a projection of the structure (but not when they are equal to the composite of multiple projections). -/ library_note "custom simps projection" /-- This command specifies custom names and custom projections for the simp attribute `simps_attr`. * You can specify custom names by writing e.g. `initialize_simps_projections equiv (to_fun β†’ apply, inv_fun β†’ symm_apply)`. * See Note [custom simps projection] and the examples below for information how to declare custom projections. * If no custom projection is specified, the projection will be `coe_fn`/`⇑` if a `has_coe_to_fun` instance has been declared, or the notation of a notation class (like `has_mul`) if such an instance is available. If none of these cases apply, the projection itself will be used. * You can disable a projection by default by running `initialize_simps_projections equiv (-inv_fun)` This will ensure that no simp lemmas are generated for this projection, unless this projection is explicitly specified by the user. * If you want the projection name added as a prefix in the generated lemma name, you can add the `as_prefix` modifier: `initialize_simps_projections equiv (to_fun β†’ coe as_prefix)` Note that this does not influence the parsing of projection names: if you have a declaration `foo` and you want to apply the projections `snd`, `coe` (which is a prefix) and `fst`, in that order you can run `@[simps snd_coe_fst] def foo ...` and this will generate a lemma with the name `coe_foo_snd_fst`. * Run `initialize_simps_projections?` (or `set_option trace.simps.verbose true`) to see the generated projections. * You can declare a new name for a projection that is the composite of multiple projections, e.g. ``` structure A := (proj : β„•) structure B extends A initialize_simps_projections? B (to_A_proj β†’ proj, -to_A) ``` You can also make your custom projection that is definitionally equal to a composite of projections. In this case, coercions and notation classes are not automatically recognized, and should be manually given by giving a custom projection. This is especially useful when extending a structure (without `old_structure_cmd`). In the above example, it is desirable to add `-to_A`, so that `@[simps]` doesn't automatically apply the `B.to_A` projection and then recursively the `A.proj` projection in the lemmas it generates. If you want to get both the `foo_proj` and `foo_to_A` simp lemmas, you can use `@[simps, simps to_A]`. * Running `initialize_simps_projections my_struc` without arguments is not necessary, it has the same effect if you just add `@[simps]` to a declaration. * If you do anything to change the default projections, make sure to call either `@[simps]` or `initialize_simps_projections` in the same file as the structure declaration. Otherwise, you might have a file that imports the structure, but not your custom projections. Some common uses: * If you define a new homomorphism-like structure (like `mul_hom`) you can just run `initialize_simps_projections` after defining the `has_coe_to_fun` instance ``` instance {mM : has_mul M} {mN : has_mul N} : has_coe_to_fun (M β†’β‚™* N) := ... initialize_simps_projections mul_hom (to_fun β†’ apply) ``` This will generate `foo_apply` lemmas for each declaration `foo`. * If you prefer `coe_foo` lemmas that state equalities between functions, use `initialize_simps_projections mul_hom (to_fun β†’ coe as_prefix)` In this case you have to use `@[simps {fully_applied := ff}]` or equivalently `@[simps as_fn]` whenever you call `@[simps]`. * You can also initialize to use both, in which case you have to choose which one to use by default, by using either of the following ``` initialize_simps_projections mul_hom (to_fun β†’ apply, to_fun β†’ coe, -coe as_prefix) initialize_simps_projections mul_hom (to_fun β†’ apply, to_fun β†’ coe as_prefix, -apply) ``` In the first case, you can get both lemmas using `@[simps, simps coe as_fn]` and in the second case you can get both lemmas using `@[simps as_fn, simps apply]`. * If your new homomorphism-like structure extends another structure (without `old_structure_cmd`) (like `rel_embedding`), then you have to specify explicitly that you want to use a coercion as a custom projection. For example ``` def rel_embedding.simps.apply (h : r β†ͺr s) : Ξ± β†’ Ξ² := h initialize_simps_projections rel_embedding (to_embedding_to_fun β†’ apply, -to_embedding) ``` * If you have an isomorphism-like structure (like `equiv`) you often want to define a custom projection for the inverse: ``` def equiv.simps.symm_apply (e : Ξ± ≃ Ξ²) : Ξ² β†’ Ξ± := e.symm initialize_simps_projections equiv (to_fun β†’ apply, inv_fun β†’ symm_apply) ``` -/ @[user_command] meta def initialize_simps_projections_cmd (_ : parse $ tk "initialize_simps_projections") : parser unit := do env ← get_env, trc ← is_some <$> (tk "?")?, ns ← (prod.mk <$> ident <*> (tk "(" >> sep_by (tk ",") simps_parse_rule <* tk ")")?)*, ns.mmap' $ Ξ» data, do nm ← resolve_constant data.1, simps_get_raw_projections env nm tt (data.2.get_or_else []) trc add_tactic_doc { name := "initialize_simps_projections", category := doc_category.cmd, decl_names := [`initialize_simps_projections_cmd], tags := ["simplification"] } /-- Configuration options for the `@[simps]` attribute. * `attrs` specifies the list of attributes given to the generated lemmas. Default: ``[`simp]``. The attributes can be either basic attributes, or user attributes without parameters. There are two attributes which `simps` might add itself: * If ``[`simp]`` is in the list, then ``[`_refl_lemma]`` is added automatically if appropriate. * If the definition is marked with `@[to_additive ...]` then all generated lemmas are marked with `@[to_additive]`. This is governed by the `add_additive` configuration option. * if `simp_rhs` is `tt` then the right-hand-side of the generated lemmas will be put in simp-normal form. More precisely: `dsimp, simp` will be called on all these expressions. See note [dsimp, simp]. * `type_md` specifies how aggressively definitions are unfolded in the type of expressions for the purposes of finding out whether the type is a function type. Default: `instances`. This will unfold coercion instances (so that a coercion to a function type is recognized as a function type), but not declarations like `set`. * `rhs_md` specifies how aggressively definition in the declaration are unfolded for the purposes of finding out whether it is a constructor. Default: `none` Exception: `@[simps]` will automatically add the options `{rhs_md := semireducible, simp_rhs := tt}` if the given definition is not a constructor with the given reducibility setting for `rhs_md`. * If `fully_applied` is `ff` then the generated `simp` lemmas will be between non-fully applied terms, i.e. equalities between functions. This does not restrict the recursive behavior of `@[simps]`, so only the "final" projection will be non-fully applied. However, it can be used in combination with explicit field names, to get a partially applied intermediate projection. * The option `not_recursive` contains the list of names of types for which `@[simps]` doesn't recursively apply projections. For example, given an equivalence `Ξ± Γ— Ξ² ≃ Ξ² Γ— Ξ±` one usually wants to only apply the projections for `equiv`, and not also those for `Γ—`. This option is only relevant if no explicit projection names are given as argument to `@[simps]`. * The option `trace` is set to `tt` when you write `@[simps?]`. In this case, the attribute will print all generated lemmas. It is almost the same as setting the option `trace.simps.verbose`, except that it doesn't print information about the found projections. * if `add_additive` is `some nm` then `@[to_additive]` is added to the generated lemma. This option is automatically set to `tt` when the original declaration was tagged with `@[to_additive, simps]` (in that order), where `nm` is the additive name of the original declaration. -/ @[derive [has_reflect, inhabited]] structure simps_cfg := (attrs := [`simp]) (simp_rhs := ff) (type_md := transparency.instances) (rhs_md := transparency.none) (fully_applied := tt) (not_recursive := [`prod, `pprod]) (trace := ff) (add_additive := @none name) /-- A common configuration for `@[simps]`: generate equalities between functions instead equalities between fully applied expressions. -/ def as_fn : simps_cfg := {fully_applied := ff} /-- A common configuration for `@[simps]`: don't tag the generated lemmas with `@[simp]`. -/ def lemmas_only : simps_cfg := {attrs := []} /-- Get the projections of a structure used by `@[simps]` applied to the appropriate arguments. Returns a list of tuples ``` (corresponding right-hand-side, given projection name, projection expression, projection numbers, used by default, is prefix) ``` (where all fields except the first are packed in a `projection_data` structure) one for each projection. The given projection name is the name for the projection used by the user used to generate (and parse) projection names. For example, in the structure Example 1: ``simps_get_projection_exprs env `(Ξ± Γ— Ξ²) `(⟨x, y⟩)`` will give the output ``` [(`(x), `fst, `(@prod.fst.{u v} Ξ± Ξ²), [0], tt, ff), (`(y), `snd, `(@prod.snd.{u v} Ξ± Ξ²), [1], tt, ff)] ``` Example 2: ``simps_get_projection_exprs env `(Ξ± ≃ Ξ±) `(⟨id, id, Ξ» _, rfl, Ξ» _, rfl⟩)`` will give the output ``` [(`(id), `apply, `(coe), [0], tt, ff), (`(id), `symm_apply, `(Ξ» f, ⇑f.symm), [1], tt, ff), ..., ...] ``` -/ meta def simps_get_projection_exprs (e : environment) (tgt : expr) (rhs : expr) (cfg : simps_cfg) : tactic $ list $ expr Γ— projection_data := do let params := get_app_args tgt, -- the parameters of the structure (params.zip $ (get_app_args rhs).take params.length).mmap' (Ξ» ⟨a, b⟩, is_def_eq a b) <|> fail "unreachable code (1)", let str := tgt.get_app_fn.const_name, let rhs_args := (get_app_args rhs).drop params.length, -- the fields of the object (raw_univs, proj_data) ← simps_get_raw_projections e str ff [] cfg.trace, let univs := raw_univs.zip tgt.get_app_fn.univ_levels, let new_proj_data : list $ expr Γ— projection_data := proj_data.map $ Ξ» proj, (rhs_args.inth proj.proj_nrs.head, { expr := (proj.expr.instantiate_univ_params univs).instantiate_lambdas_or_apps params, proj_nrs := proj.proj_nrs.tail, .. proj }), return new_proj_data /-- Add a lemma with `nm` stating that `lhs = rhs`. `type` is the type of both `lhs` and `rhs`, `args` is the list of local constants occurring, and `univs` is the list of universe variables. -/ meta def simps_add_projection (nm : name) (type lhs rhs : expr) (args : list expr) (univs : list name) (cfg : simps_cfg) : tactic (list name) := do when_tracing `simps.debug trace! "[simps] > Planning to add the equality\n > {lhs} = ({rhs} : {type})", lvl ← get_univ_level type, -- simplify `rhs` if `cfg.simp_rhs` is true (rhs, prf) ← do { guard cfg.simp_rhs, rhs' ← rhs.dsimp {fail_if_unchanged := ff}, when_tracing `simps.debug $ when (rhs β‰  rhs') trace! "[simps] > `dsimp` simplified rhs to\n > {rhs'}", (rhsprf1, rhsprf2, ns) ← rhs'.simp {fail_if_unchanged := ff}, when_tracing `simps.debug $ when (rhs' β‰  rhsprf1) trace! "[simps] > `simp` simplified rhs to\n > {rhsprf1}", return (prod.mk rhsprf1 rhsprf2) } <|> return (rhs, const `eq.refl [lvl] type lhs), let eq_ap := const `eq [lvl] type lhs rhs, decl_name ← get_unused_decl_name nm, let decl_type := eq_ap.pis args, let decl_value := prf.lambdas args, let decl := declaration.thm decl_name univs decl_type (pure decl_value), when cfg.trace trace! "[simps] > adding projection {decl_name}:\n > {decl_type}", decorate_error ("Failed to add projection lemma " ++ decl_name.to_string ++ ". Nested error:") $ add_decl decl, b ← succeeds $ is_def_eq lhs rhs, when (b ∧ `simp ∈ cfg.attrs) (set_basic_attribute `_refl_lemma decl_name tt), cfg.attrs.mmap' $ Ξ» nm, set_attribute nm decl_name tt, when cfg.add_additive.is_some $ to_additive.attr.set decl_name ⟨ff, cfg.trace, cfg.add_additive.iget, none, tt⟩ tt, pure [decl_name] /-- Derive lemmas specifying the projections of the declaration. If `todo` is non-empty, it will generate exactly the names in `todo`. `to_apply` is non-empty after a custom projection that is a composition of multiple projections was just used. In that case we need to apply these projections before we continue changing lhs. -/ meta def simps_add_projections : Ξ  (e : environment) (nm : name) (type lhs rhs : expr) (args : list expr) (univs : list name) (must_be_str : bool) (cfg : simps_cfg) (todo : list string) (to_apply : list β„•), tactic (list name) | e nm type lhs rhs args univs must_be_str cfg todo to_apply := do -- we don't want to unfold non-reducible definitions (like `set`) to apply more arguments when_tracing `simps.debug trace! "[simps] > Type of the expression before normalizing: {type}", (type_args, tgt) ← open_pis_whnf type cfg.type_md, when_tracing `simps.debug trace!"[simps] > Type after removing pi's: {tgt}", tgt ← whnf tgt, when_tracing `simps.debug trace!"[simps] > Type after reduction: {tgt}", let new_args := args ++ type_args, let lhs_ap := lhs.instantiate_lambdas_or_apps type_args, let rhs_ap := rhs.instantiate_lambdas_or_apps type_args, let str := tgt.get_app_fn.const_name, /- We want to generate the current projection if it is in `todo` -/ let todo_next := todo.filter (β‰  ""), /- Don't recursively continue if `str` is not a structure or if the structure is in `not_recursive`. -/ if e.is_structure str ∧ Β¬(todo = [] ∧ str ∈ cfg.not_recursive ∧ Β¬must_be_str) then do [intro] ← return $ e.constructors_of str | fail "unreachable code (3)", rhs_whnf ← whnf rhs_ap cfg.rhs_md, -- `todo_now` means that we still have to generate the current simp lemma (rhs_ap, todo_now, added_lems_requested) ← if Β¬ is_constant_of rhs_ap.get_app_fn intro ∧ is_constant_of rhs_whnf.get_app_fn intro then do /- If this was a desired projection, we want to apply it before taking the whnf. However, if the current field is an eta-expansion (see below), we first want to eta-reduce it and only then construct the projection. This makes the flow of this function messy. -/ added_lems_requested ← cond ("" ∈ todo ∧ to_apply = []) (if cfg.fully_applied then simps_add_projection nm tgt lhs_ap rhs_ap new_args univs cfg else simps_add_projection nm type lhs rhs args univs cfg) (pure []), return (rhs_whnf, ff, added_lems_requested) else return (rhs_ap, "" ∈ todo ∧ to_apply = [], []), if is_constant_of (get_app_fn rhs_ap) intro then do -- if the value is a constructor application proj_info ← simps_get_projection_exprs e tgt rhs_ap cfg, when_tracing `simps.debug trace!"[simps] > Raw projection information:\n {proj_info}", eta ← rhs_ap.is_eta_expansion, -- check whether `rhs_ap` is an eta-expansion let rhs_ap := eta.lhoare rhs_ap, -- eta-reduce `rhs_ap` /- As a special case, we want to automatically generate the current projection if `rhs_ap` was an eta-expansion. Also, when this was a desired projection, we need to generate the current projection if we haven't done it above. -/ added_lems_eta ← cond (todo_now ∨ (todo = [] ∧ eta.is_some ∧ to_apply = [])) (if cfg.fully_applied then simps_add_projection nm tgt lhs_ap rhs_ap new_args univs cfg else simps_add_projection nm type lhs rhs args univs cfg) (return []), /- If we are in the middle of a composite projection. -/ added_lems_custom_proj ← cond (to_apply β‰  []) (do { ⟨new_rhs, proj, proj_expr, proj_nrs, is_default, is_prefix⟩ ← return $ proj_info.inth to_apply.head, new_type ← infer_type new_rhs, when_tracing `simps.debug trace!"[simps] > Applying a custom composite projection. Current lhs: > {lhs_ap}", simps_add_projections e nm new_type lhs_ap new_rhs new_args univs ff cfg todo to_apply.tail }) (pure []), let all_added_lems := added_lems_requested ++ added_lems_eta ++ added_lems_custom_proj, /- We stop if no further projection is specified or if we just reduced an eta-expansion and we automatically choose projections -/ cond (Β¬(to_apply β‰  [] ∨ todo = [""] ∨ (eta.is_some ∧ todo = []))) (do let projs : list name := proj_info.map $ Ξ» x, x.snd.name, let todo := if to_apply = [] then todo_next else todo, -- check whether all elements in `todo` have a projection as prefix guard (todo.all $ Ξ» x, projs.any $ Ξ» proj, ("_" ++ proj.last).is_prefix_of x) <|> let x := (todo.find $ Ξ» x, projs.all $ Ξ» proj, Β¬ ("_" ++ proj.last).is_prefix_of x).iget, simp_lemma := nm.append_suffix x, needed_proj := (x.split_on '_').tail.head in fail! "Invalid simp lemma {simp_lemma}. Structure {str} does not have projection {needed_proj}. The known projections are: {projs} You can also see this information by running `initialize_simps_projections? {str}`. Note: these projection names might not correspond to the projection names of the structure.", added_lems_list ← proj_info.mmap_with_index (Ξ» proj_nr ⟨new_rhs, proj, proj_expr, proj_nrs, is_default, is_prefix⟩, do new_type ← infer_type new_rhs, let new_todo := todo.filter_map $ Ξ» x, x.get_rest ("_" ++ proj.last), -- we only continue with this field if it is non-propositional or mentioned in todo cond ((is_default ∧ todo = []) ∨ new_todo β‰  []) (do let new_lhs := proj_expr.instantiate_lambdas_or_apps [lhs_ap], let new_nm := nm.append_to_last proj.last is_prefix, let new_cfg := { add_additive := cfg.add_additive.map $ Ξ» nm, nm.append_to_last (to_additive.guess_name proj.last) is_prefix, ..cfg }, when_tracing `simps.debug trace!"[simps] > Recursively add projections for: > {new_lhs}", simps_add_projections e new_nm new_type new_lhs new_rhs new_args univs ff new_cfg new_todo proj_nrs) (pure [])), pure $ all_added_lems ++ added_lems_list.join) (pure all_added_lems) -- if I'm about to run into an error, try to set the transparency for `rhs_md` higher. else if cfg.rhs_md = transparency.none ∧ (must_be_str ∨ todo_next β‰  [] ∨ to_apply β‰  []) then do when cfg.trace trace! "[simps] > The given definition is not a constructor application: > {rhs_ap} > Retrying with the options {{ rhs_md := semireducible, simp_rhs := tt}.", added_lems_recursive ← simps_add_projections e nm type lhs rhs args univs must_be_str { rhs_md := semireducible, simp_rhs := tt, ..cfg} todo to_apply, pure $ added_lems_requested ++ added_lems_recursive else do when (to_apply β‰  []) $ fail!"Invalid simp lemma {nm}. The given definition is not a constructor application:\n {rhs_ap}", when must_be_str $ fail!"Invalid `simps` attribute. The body is not a constructor application:\n {rhs_ap}", when (todo_next β‰  []) $ fail!"Invalid simp lemma {nm.append_suffix todo_next.head}. The given definition is not a constructor application:\n {rhs_ap}", added_lems_no_constructor ← if cfg.fully_applied then simps_add_projection nm tgt lhs_ap rhs_ap new_args univs cfg else simps_add_projection nm type lhs rhs args univs cfg, pure $ added_lems_requested ++ added_lems_no_constructor else do when must_be_str $ fail!"Invalid `simps` attribute. Target {str} is not a structure", when (todo_next β‰  [] ∧ str βˆ‰ cfg.not_recursive) $ let first_todo := todo_next.head in fail!"Invalid simp lemma {nm.append_suffix first_todo}. Projection {(first_todo.split_on '_').tail.head} doesn't exist, because target is not a structure.", if cfg.fully_applied then simps_add_projection nm tgt lhs_ap rhs_ap new_args univs cfg else simps_add_projection nm type lhs rhs args univs cfg /-- The `@[_simps_aux]` attribute specifies which lemmas are added by `simps`. This should not be used manually and it only exists for mathport -/ @[user_attribute] meta def simps_aux : user_attribute unit (list name) := { name := `_simps_aux, descr := "An attribute specifying the added simps lemmas.", parser := failed } /-- `simps_tac` derives `simp` lemmas for all (nested) non-Prop projections of the declaration. If `todo` is non-empty, it will generate exactly the names in `todo`. If `short_nm` is true, the generated names will only use the last projection name. If `trc` is true, trace as if `trace.simps.verbose` is true. -/ meta def simps_tac (nm : name) (cfg : simps_cfg := {}) (todo : list string := []) (trc := ff) : tactic unit := do e ← get_env, d ← e.get nm, let lhs : expr := const d.to_name d.univ_levels, let todo := todo.dedup.map $ Ξ» proj, "_" ++ proj, let cfg := { trace := cfg.trace || is_trace_enabled_for `simps.verbose || trc, ..cfg }, b ← has_attribute' `to_additive nm, cfg ← if b then do { dict ← to_additive.aux_attr.get_cache, when cfg.trace trace!"[simps] > @[to_additive] will be added to all generated lemmas.", return { add_additive := dict.find nm, ..cfg } } else return cfg, added_names ← simps_add_projections e nm d.type lhs d.value [] d.univ_params tt cfg todo [], simps_aux.set nm added_names true /-- The parser for the `@[simps]` attribute. -/ meta def simps_parser : parser (bool Γ— list string Γ— simps_cfg) := do /- note: we don't check whether the user has written a nonsense namespace in an argument. -/ prod.mk <$> is_some <$> (tk "?")? <*> (prod.mk <$> many (name.last <$> ident) <*> (do some e ← parser.pexpr? | return {}, eval_pexpr simps_cfg e)) /-- The `@[simps]` attribute automatically derives lemmas specifying the projections of this declaration. Example: ```lean @[simps] def foo : β„• Γ— β„€ := (1, 2) ``` derives two `simp` lemmas: ```lean @[simp] lemma foo_fst : foo.fst = 1 @[simp] lemma foo_snd : foo.snd = 2 ``` * It does not derive `simp` lemmas for the prop-valued projections. * It will automatically reduce newly created beta-redexes, but will not unfold any definitions. * If the structure has a coercion to either sorts or functions, and this is defined to be one of the projections, then this coercion will be used instead of the projection. * If the structure is a class that has an instance to a notation class, like `has_mul`, then this notation is used instead of the corresponding projection. * You can specify custom projections, by giving a declaration with name `{structure_name}.simps.{projection_name}`. See Note [custom simps projection]. Example: ```lean def equiv.simps.inv_fun (e : Ξ± ≃ Ξ²) : Ξ² β†’ Ξ± := e.symm @[simps] def equiv.trans (e₁ : Ξ± ≃ Ξ²) (eβ‚‚ : Ξ² ≃ Ξ³) : Ξ± ≃ Ξ³ := ⟨eβ‚‚ ∘ e₁, e₁.symm ∘ eβ‚‚.symm⟩ ``` generates ``` @[simp] lemma equiv.trans_to_fun : βˆ€ {Ξ± Ξ² Ξ³} (e₁ eβ‚‚) (a : Ξ±), ⇑(e₁.trans eβ‚‚) a = (⇑eβ‚‚ ∘ ⇑e₁) a @[simp] lemma equiv.trans_inv_fun : βˆ€ {Ξ± Ξ² Ξ³} (e₁ eβ‚‚) (a : Ξ³), ⇑((e₁.trans eβ‚‚).symm) a = (⇑(e₁.symm) ∘ ⇑(eβ‚‚.symm)) a ``` * You can specify custom projection names, by specifying the new projection names using `initialize_simps_projections`. Example: `initialize_simps_projections equiv (to_fun β†’ apply, inv_fun β†’ symm_apply)`. See `initialize_simps_projections_cmd` for more information. * If one of the fields itself is a structure, this command will recursively create `simp` lemmas for all fields in that structure. * Exception: by default it will not recursively create `simp` lemmas for fields in the structures `prod` and `pprod`. You can give explicit projection names or change the value of `simps_cfg.not_recursive` to override this behavior. Example: ```lean structure my_prod (Ξ± Ξ² : Type*) := (fst : Ξ±) (snd : Ξ²) @[simps] def foo : prod β„• β„• Γ— my_prod β„• β„• := ⟨⟨1, 2⟩, 3, 4⟩ ``` generates ```lean @[simp] lemma foo_fst : foo.fst = (1, 2) @[simp] lemma foo_snd_fst : foo.snd.fst = 3 @[simp] lemma foo_snd_snd : foo.snd.snd = 4 ``` * You can use `@[simps proj1 proj2 ...]` to only generate the projection lemmas for the specified projections. * Recursive projection names can be specified using `proj1_proj2_proj3`. This will create a lemma of the form `foo.proj1.proj2.proj3 = ...`. Example: ```lean structure my_prod (Ξ± Ξ² : Type*) := (fst : Ξ±) (snd : Ξ²) @[simps fst fst_fst snd] def foo : prod β„• β„• Γ— my_prod β„• β„• := ⟨⟨1, 2⟩, 3, 4⟩ ``` generates ```lean @[simp] lemma foo_fst : foo.fst = (1, 2) @[simp] lemma foo_fst_fst : foo.fst.fst = 1 @[simp] lemma foo_snd : foo.snd = {fst := 3, snd := 4} ``` * If one of the values is an eta-expanded structure, we will eta-reduce this structure. Example: ```lean structure equiv_plus_data (Ξ± Ξ²) extends Ξ± ≃ Ξ² := (data : bool) @[simps] def bar {Ξ±} : equiv_plus_data Ξ± Ξ± := { data := tt, ..equiv.refl Ξ± } ``` generates the following: ```lean @[simp] lemma bar_to_equiv : βˆ€ {Ξ± : Sort*}, bar.to_equiv = equiv.refl Ξ± @[simp] lemma bar_data : βˆ€ {Ξ± : Sort*}, bar.data = tt ``` This is true, even though Lean inserts an eta-expanded version of `equiv.refl Ξ±` in the definition of `bar`. * For configuration options, see the doc string of `simps_cfg`. * The precise syntax is `('simps' ident* e)`, where `e` is an expression of type `simps_cfg`. * `@[simps]` reduces let-expressions where necessary. * When option `trace.simps.verbose` is true, `simps` will print the projections it finds and the lemmas it generates. The same can be achieved by using `@[simps?]`, except that in this case it will not print projection information. * Use `@[to_additive, simps]` to apply both `to_additive` and `simps` to a definition, making sure that `simps` comes after `to_additive`. This will also generate the additive versions of all `simp` lemmas. -/ /- If one of the fields is a partially applied constructor, we will eta-expand it (this likely never happens, so is not included in the official doc). -/ @[user_attribute] meta def simps_attr : user_attribute unit (bool Γ— list string Γ— simps_cfg) := { name := `simps, descr := "Automatically derive lemmas specifying the projections of this declaration.", parser := simps_parser, after_set := some $ Ξ» n _ persistent, do guard persistent <|> fail "`simps` currently cannot be used as a local attribute", (trc, todo, cfg) ← simps_attr.get_param n, simps_tac n cfg todo trc } add_tactic_doc { name := "simps", category := doc_category.attr, decl_names := [`simps_attr], tags := ["simplification"] }
bb9db4acf4d5ddd69ea9e4f80307dccc373c676e
205f0fc16279a69ea36e9fd158e3a97b06834ce2
/src/09_Disjunction/00_intro.lean
575c26468c8a1af077fd52ad22c501070c2fe56e
[]
no_license
kevinsullivan/cs-dm-lean
b21d3ca1a9b2a0751ba13fcb4e7b258010a5d124
a06a94e98be77170ca1df486c8189338b16cf6c6
refs/heads/master
1,585,948,743,595
1,544,339,346,000
1,544,339,346,000
155,570,767
1
3
null
1,541,540,372,000
1,540,995,993,000
Lean
UTF-8
Lean
false
false
15,183
lean
/- If P and Q are propositions, then P ∨ Q is also a proposition. It is read as "P or Q" and is called a disjunction. P and Q are called the disjuncts of the disjunction P ∨ Q. In constructive logic, one can prove P ∨ Q from either a proof of P or a proof of Q. This unit presents and discusses the basic introduction and elimination rules for or. -/ /- We start by making some assumptions that we use in the rest of this unit. -/ variables P Q R X Y Z: Prop variable pfP : P variable pfQ : Q variable pfR : R /- ************************** *** INTRODUCTION RULES *** ************************** -/ /- In constructive logic, P ∨ Q is true if either a proof of P or a proof of Q can be given. Having a proof of both of course allows one to give either proof to prove P ∨ Q. Here are the introduction rules written as inference rules. { P } Q : Prop, pfP: P ---------------------- (or.intro_left) P ∨ Q Notice in the preceding rule that while P can be inferred from pfP, Q has to be given explicitly, because otherwise there is no way to know what it is. P { Q } : Prop, pfQ: Q ----------------------- (or.intro_right) P ∨ Q Now P has to be given explicitly, while Q can be inferred. -/ /- The or.intro_left rule takes propositions P and Q (P implicitly) constructs a proof of P ∨ Q. No proof of Q is needed. P need not be given explicitly because it can be inferred from the proof of P; however, because no proof of Q is given, from which Q could be inferred, Q must be given explicitly. The or.intro_right rule takes a proof of Q explicitly along with a proposition P, from which P is inferred, and constructs a proof of P ∨ Q. No proof of P is required, but the proposition P has to be given explicitly, as there's no proof to infer it from. -/ /- To prove a disjunction, such as 0 = 0 ∨ 0 = 1, we have to pick which side of the disjunction we will give a proof for in order to apply or.intro. Here's an example. We pick the side to prove that actually has a proof. There is no proof of the right side. -/ theorem goodSide : 0 = 0 ∨ 0 = 1 := or.intro_left (0=1) (eq.refl 0) ---------------- Q ---pfP /- Recall that we can use "example" in Lean to state a theorem without giving its proof a name. Here we use example to state and prove that for any proposition, P, P or false is equivalent to P. (Remember that we assumed above that P is defined to be a Prop, and pfP is defined to be a proof of P.) -/ example : P ∨ false := or.intro_left false pfP example : false ∨ Q := or.intro_right false pfQ /- EXERCISE: Prove 0 = 1 ∨ 0 = 0. -/ example : 0 = 1 ∨ 0 = 0 := or.intro_right (0 = 1) rfl /- Note: inl and inr are shorthands for intro_left and intro_right, and the are defined so that the Prop parameter is implicit. -/ example : 0 = 1 ∨ 0 = 0 := or.inr rfl /- Here's a proof that P or true is always true. The key idea is that we can always choose to give a proof for the true side, which is trivial. -/ theorem zero_right_or : βˆ€ P : Prop, P ∨ true := Ξ» P, or.intro_right P true.intro /- EXERCISE: Prove that true ∨ Q is always true as well, but use one of the shorthands to write your proof. -/ example : βˆ€ Q : Prop, true ∨ Q := Ξ» Q, or.inl true.intro /- ************************** **** Elimination RULE **** ************************** -/ /- The or.elim rule gives us an indirect way to prove a proposition, R, (the goal) by showing first that at least one of two conditions holds (P ∨ Q), and in either case W must be true, because both (P β†’ R) and (Q β†’ R). If P ∨ Q, then if both P β†’ R and Q β†’ R, then R. Here's the inference rule in plain text. pfPQ: P ∨ Q, pfPR: P β†’ R, pfQR: Q β†’ R -------------------------------------- or.elim R -/ /- As an example, suppose that (1) when it is raining (R) the grass is wet (R β†’ W); (2) when the sprinkler (S) is on, the grass is also wet (S β†’ W); and it is raining *or* the sprinkler is on (R ∨ S). Then the grass must be wet (W). Going in the other direction, if our aim is to prove W, we can do it using or.elim by showing that for some propositions, R and S, that R ∨ S is true, and that *in either case*, W must also be true. The reasoning is by considering each case, each possible way to have proven R ∨ S, separately. R ∨ S means that at least one of R and S is true, and for whichever one is true, there must be a proof. We first consider a case where R is true. Then we consider the case where S is true. In the case where R is true, we show that W follows from R β†’ W. In case where S is true, we show that W follows from S β†’ W. W holds in either case and so W holds. -/ /- Now let's see it working in Lean. We make a few basic assumptions and then show how to combine them using the or elimination rule. We assume ... 1. a proof of P ∨ Q 2. a proof of P β†’ R 3. a proof of Q β†’ R -/ variable porq : P ∨ Q variable p2r : P β†’ R variable q2r : Q β†’ R /- Now we derive and check a proof of R by applying or.elim to these terms.. -/ #check or.elim porq p2r q2r /- Here's the same example using more suggestive names for propositions. -/ -- Raining, Sprinkling, Wet are Props variables Raining Sprinkling Wet : Prop -- rors proves it's Raining ∨ Sprinkling. variable rors: Raining ∨ Sprinkling -- r2w proves if Raining then Wet variable r2w: Raining β†’ Wet -- s2w proves if Sprinkling then Wet variable s2w: Sprinkling β†’ Wet -- Put it all together to show Wet theorem wet : Wet := or.elim rors r2w s2w /- The following program make the arguments to and the result of or.elim clear, and it gives an example of the use of or.elim. -/ theorem orElim : βˆ€ R S W: Prop, (R ∨ S) β†’ (R β†’ W) β†’ (S β†’ W) β†’ W := begin assume R S W rors r2w s2w, show W, from or.elim rors r2w s2w end /- This example constructs the same proof but illustrates how we can apply inference rules, leaving out some arguments, to be filled in, in the style of backward reasoning. -/ theorem orElim' : βˆ€ R S W: Prop, (R ∨ S) β†’ (R β†’ W) β†’ (S β†’ W) β†’ W := begin assume R S W rors r2w s2w, -- apply or.elim apply or.elim, -- reduce goal to two subgoals -- one for each required implication exact rors, assumption, exact s2w, end /- Notice the subtle difference between using or.elim and cases. The or.elim rule takes the disjunction and the two implications as arguments. The cases tactic, on the other hand, sets you up to apply one or the other implication depending on the case being considered. -/ theorem wet''' : βˆ€ R S W: Prop, (R ∨ S) β†’ (R β†’ W) β†’ (S β†’ W) β†’ W := begin assume R S W r_or_s r2w s2w, /- We want to show that if W follows from R and if W follows from S, then W follows R ∨ S. -/ show W, from begin /- What we need to show is that W follows from R ∨ S, whether because R is true and W follows from R or because S is true and W follows from S. We consider each case in turn. -/ cases r_or_s with r s, -- W follows from (r : R) and r2w show W, from r2w r, -- W follows from (r : R) and s2w show W, from s2w s, -- Thus W follows. end -- QED end /- We recommend approaching proofs from disjunctions, as here, using the cases tactic. It clearly shows that what is happening is a case analysis. That if the disjunction is true, then one way or another we can reach the desired conclusion. -/ /- Here's a proof that false is a right identity for disjunction. That's a fancy way of saying that P ∨ false is true if and only if P is true. They're equivalent propositions. -/ theorem id_right_or : βˆ€ P : Prop, P ∨ false ↔ P := Ξ» P, begin -- consider each direction separately apply iff.intro, -- note: missing args become subgoals -- Forward direction: P ∨ false β†’ P -- assume a proof of P ∨ false assume pfPorfalse, -- show P by case analysis on this disjunction cases pfPorfalse with pfP pfFalse, -- case where we have a proof of P assumption, -- case with proof of false exact false.elim pfFalse, -- Reverse direction, easy assume p, exact or.inl p, end /- Another example. The proof of another standard rule of reasoning in natural deduction. -/ theorem disjunctiveSyllogism : βˆ€ P Q : Prop, P ∨ Q β†’ Β¬Q β†’ P := begin assume P Q porq, assume nq, cases porq with p q, -- first case assumption, -- second case exact (false.elim (nq q)), end /- Exercise: Prove that false is also a *left* identity for disjunction. That is: false ∨ P ↔ P (false is on the left). -/ /- We now turn to the question, how do and, or, not, and implies interact? We prove both of DeMorgan's laws, and we also show that P β†’ Q ↔ Β¬ P ∨ Q. One of DeMorgan's law and this identity about β†’ are both classical, and not valid/provable without the axiom of the excluded middle (em). -/ /- De Morgan had two important laws. They explain how negations distribute over disjunctions and conjunctions. 1) Β¬P ∧ Β¬Q ↔ Β¬(P ∨ Q) 2) Β¬P ∨ Β¬Q ↔ Β¬(P ∧ Q) Consider what the first of DeMorgan's laws is saying. Start on the right. If P ∨ Q is not true, then both P and Q must be false, and if P and Q are both false, then so is P ∨ Q. Now the second law. If P and Q is false, then at least one of P, Q must be false, so Β¬ P ∨ Β¬ Q must be true. And if that is true, then certainly P ∧ Q is false. Proving that the first law is valid even in constructive logic is homework 4. We can only prove the second law using the axiom of the excluded middle, which we now proceed to do. -/ /- We could declare our own version of the axiom of the excluded middle, as we have seen. -/ axiom excluded_middle: βˆ€ (P: Prop), P ∨ Β¬P /- Or, better, is simply to open the classical namespace in Lean, which gives us access to the definition, em, of this axiom. We do this now and then show that the two propositions are the same. From now on, prefer to use em. -/ open classical -- "em" is excl. middle. axiom theorem emIse_m: em = excluded_middle := rfl /- And now for DeMorgan's second law. -/ theorem DemorganLaw2 : βˆ€ P Q: Prop, Β¬P ∨ Β¬ Q ↔ Β¬(P ∧ Q) := begin show βˆ€ P Q: Prop, Β¬P ∨ Β¬ Q ↔ Β¬(P ∧ Q), from begin -- introduce assumptions of P and Q assume P Q, -- prove implication in each direction apply iff.intro, -- first, implication in forward direction show Β¬P ∨ Β¬Q β†’ Β¬(P ∧ Q), from begin -- goal is an implication -- so assume premise, and ... assume pf_np_or_nq, -- ... show conclusion show Β¬(P ∧ Q), from begin -- remember Β¬ is an implication in Lean -- so, assume premise, and ... assume pf_p_and_q, -- show conclusion show false, from begin -- by case analysis on Β¬P ∨ Β¬Q cases pf_np_or_nq with pf_np pf_nq, -- consider case where Β¬P is true have pf_p := pf_p_and_q.left, exact pf_np pf_p, -- case where Β¬Q is true have pf_q := pf_p_and_q.right, exact pf_nq pf_q, end end, end, -- now implication in reverse direction show Β¬(P ∧ Q) β†’ Β¬P ∨ Β¬Q, from begin -- assume premise assume pf_n_p_and_q, show Β¬P ∨ Β¬Q, from begin -- consider cases for P using em cases (em P) with pf_p pf_np, -- consider cases for Q using em cases em Q with pf_q pf_nq, -- P true, Q true have pf_p_and_q := and.intro pf_p pf_q, have pf_false := pf_n_p_and_q pf_p_and_q, exact false.elim pf_false, -- P true, Q false exact or.intro_right (Β¬P) pf_nq, -- P false exact or.intro_left (Β¬Q) pf_np, end, end, end, end /- Assuming the axiom of the excluded middle, we can also show that P β†’ Q is equivalent to Β¬P ∨ Q. Think about what P β†’ Q means: whenever P is true, Q is true. So either P is false, in which case P β†’ Q is true, or Q is true (along with P). Here we use the axiom of the excluded middle to limit the possibilities for P to these cases. In this proof we take a more spartan approach to using show/from. It's really a matter of purpose and style to use a lot of show/from or not. It does make proofs more self-explanatory, but it can also make them unnecessarily verbose in cases where they should be clear enough in any case to one who knows how to read this kind of code. Still, in the first half of this code, we include English language comments. In the second half, we just leave them out. For now we recommend that you at least include English language comments. In many cases, you could then edit them end end up with a good English language proof, forgetting the formalism! So you are on your way now to understanding how to write informal proofs. -/ theorem altImplication: βˆ€ P Q: Prop, (P β†’ Q) ↔ (Β¬P ∨ Q) := begin -- to show βˆ€ P Q: Prop, (P β†’ Q) ↔ (Β¬P ∨ Q) -- we first introduce assumptions of P and Q assume P Q, -- next we prove implication in each direction apply iff.intro, -- first we prove forward direction -- we start by assuming the premise assume pf_p_imp_q, -- note that without em, we're stuck -- key is case analysis on P given em cases (em P) with pf_p pf_np, -- case where P is true -- construct a proof of Q have pf_q := (pf_p_imp_q pf_p), -- then prove goal by or intro --exact or.intro_right (Β¬P) pf_q, exact or.inr pf_q, -- shorhand! -- case where Β¬ P is true is easy exact or.inl pf_np, -- shorthand -- prove implication reverse direction assume pf_np_or_q, assume pf_p, cases pf_np_or_q with pf_np pf_q, have pf_false := (pf_np pf_p), exact false.elim pf_false, assumption, end theorem altEquivalence : βˆ€ { P Q : Prop }, (P ↔ Q) ↔ ((P ∧ Q) ∨ (Β¬P ∧ Β¬Q)) := begin assume P Q, apply iff.intro, intros, have pq := iff.elim_left a, have qp := iff.elim_right a, cases (em P) with p np, cases (em Q) with q nq, exact or.inl (and.intro p q), exact false.elim (nq (pq p)), cases (em Q) with q nq, exact false.elim (np (qp q)), exact or.inr (and.intro np nq), intros, cases a, apply iff.intro, intro, exact a.2, intro, exact a.1, apply iff.intro, intro, exact (false.elim (a.1 a_1)), intro, exact (false.elim (a.2 a_1)), end /- Recall, that once we've prove a theorem, we can then henceforth use it in larger proofs. Here's an example showing how we could use iffExplained, just proved, to transform a goal, P ↔ Q, into the form of a corresponding disjunction. -/ example : βˆ€ P Q : Prop, P ↔ Q := begin -- Assume P and Q are propositions intros, -- Apply backwards implication -- Goal matches right side of implication -- reducing goal to left side with substs apply altEquivalence.elim_right, -- abandon, never meant to complete proof end
9f23b8067c6a79a25f45d3126dd316770419dd5a
952248371e69ccae722eb20bfe6815d8641554a8
/src/multiplicative.lean
0f4dd8d69198af7343a25e2e99bffe68293e69a6
[]
no_license
robertylewis/lean_polya
5fd079031bf7114449d58d68ccd8c3bed9bcbc97
1da14d60a55ad6cd8af8017b1b64990fccb66ab7
refs/heads/master
1,647,212,226,179
1,558,108,354,000
1,558,108,354,000
89,933,264
1
2
null
1,560,964,118,000
1,493,650,551,000
Lean
UTF-8
Lean
false
false
49,550
lean
import .datatypes .blackboard .proof_reconstruction .reconstruction_theorems .radicals .proof_trace -- TODO: maybe more of this can move to datatypes namespace polya meta def approx_prec := 100 private meta def round_rat_to_prec_over (q : β„š) (prec : β„•) : β„š := let z' := ((q.num.nat_abs*prec)/q.denom) + 1 in rat.mk_nat (if q.num > 0 then z' else -z') prec -- if pf is an inequality, returns a new, implied inequality where the denominator of coeff is at most prec meta def prod_form_comp_data.round (pfcd : prod_form_comp_data) (prec : β„•) : prod_form_comp_data := if (pfcd.pfc.pf.coeff.denom ≀ prec) || (pfcd.pfc.c = spec_comp.eq) then pfcd else let ncoeff := round_rat_to_prec_over pfcd.pfc.pf.coeff prec in ⟨{pfcd.pfc with pf := {pfcd.pfc.pf with coeff := ncoeff}}, prod_form_proof.adhoc _ pfcd.prf.sketch (tactic.fail "pfcd.round not implemented yet"), pfcd.elim_list ⟩ private meta def Οƒ := hash_map expr sign_data Γ— hash_map expr (Ξ» e, ineq_info e rat_one) meta def mul_state := state Οƒ meta instance mul_state.monad : monad mul_state := state_t.monad meta instance mul_state.monad_state : monad_state Οƒ mul_state := state_t.monad_state private meta def inh_sd (e : expr) : inhabited (sign_data e) := ⟨⟨gen_comp.ne, sign_proof.adhoc _ _ (tactic.failed) (tactic.failed)⟩⟩ local attribute [instance] inh_sd open hash_map private meta def si (e : expr) : mul_state (sign_data e) := (Ξ» hm : Οƒ, hm.1.ifind e) <$> get private meta def si' (e : expr) : mul_state (option (sign_data e)) := (Ξ» hm : Οƒ, hm.1.find e) <$> get private meta def oi (e : expr) : mul_state (ineq_info e rat_one) := (Ξ» hm : Οƒ, hm.2.ifind e) <$> get -- returns true if the mul_state implies coeff*e c 1 private meta def implies_one_comp (coeff : β„š) (e : expr) (c : comp) : mul_state bool := do ii ← oi e, return $ ii.implies_ineq $ ineq.of_comp_and_slope c (slope.some coeff) private meta def find_comp {lhs rhs} (ii : ineq_info lhs rhs) (m : β„š) : option gen_comp := if ii.implies_eq m then some (gen_comp.eq) else if ii.implies_ineq (ineq.of_comp_and_slope comp.ge (slope.some m)) then some (if ii.implies_ineq $ ineq.of_comp_and_slope comp.gt (slope.some m) then gen_comp.gt else gen_comp.ge) else if ii.implies_ineq (ineq.of_comp_and_slope comp.le (slope.some m)) then some (if ii.implies_ineq $ ineq.of_comp_and_slope comp.lt (slope.some m) then gen_comp.lt else gen_comp.le) else none -- returns the known comparisons of e with 1 and -1 meta def oc (e : expr) : mul_state (option gen_comp Γ— option gen_comp) := do ii ← oi e, return (find_comp ii 1, find_comp ii (-1)) meta def is_ge_one (e : expr) : mul_state bool := do (c, _) ← oc e, match c with | some c' := return c'.is_greater_or_eq | none := return ff end meta def is_le_one (e : expr) : mul_state bool := do (c, _) ← oc e, match c with | some c' := return c'.is_less_or_eq | none := return ff end meta def is_le_neg_one (e : expr) : mul_state bool := do (_, c) ← oc e, match c with | some c' := return c'.is_less_or_eq | none := return ff end meta def is_ge_neg_one (e : expr) : mul_state bool := do (_, c) ← oc e, match c with | some c' := return c'.is_greater_or_eq | none := return ff end meta def is_pos_le_one (e : expr) : mul_state bool := do ⟨c, _⟩ ← si e, match c with | gen_comp.gt := is_le_one e --bnot <$> is_ge_one e | _ := return ff end meta def is_neg_ge_neg_one (e : expr) : mul_state bool := do ⟨c, _⟩ ← si e, match c with | gen_comp.lt := is_ge_neg_one e-- bnot <$> is_le_neg_one e | _ := return ff end private meta def all_signs : mul_state (hash_map expr sign_data) := prod.fst <$> get section sign_inference meta def sign_of_term (pf : prod_form) (e : expr) : mul_state (option gen_comp) := match pf.exps.find e with | some z := do opt ← si' e, match opt with | some ⟨gen_comp.lt, _⟩ := return $ some $ if z % 2 = 0 then gen_comp.gt else gen_comp.lt | some ⟨gen_comp.le, _⟩ := return $ some $ if z % 2 = 0 then gen_comp.ge else gen_comp.le | some ⟨gen_comp.eq, _⟩ := return $ if z > 0 then some gen_comp.eq else none | some ⟨c, _⟩ := return $ some c -- gt, ge, ne | _ := return none end | none := return none end meta def sign_of_prod (l : list gen_comp) : option gen_comp := l.mfoldl gen_comp.prod gen_comp.gt -- get_remaining_sign g s returns the unique g' such that gen_comp.prod g g' = s meta def get_remaining_sign_aux : gen_comp β†’ spec_comp β†’ option gen_comp | gen_comp.gt s := s.to_gen_comp | gen_comp.ge spec_comp.lt := none | gen_comp.ge s := s.to_gen_comp | gen_comp.eq _ := none | gen_comp.le spec_comp.lt := none | gen_comp.le s := s.to_gen_comp.reverse | gen_comp.lt s := s.to_gen_comp.reverse | gen_comp.ne s := none meta def get_remaining_sign : gen_comp β†’ gen_comp β†’ option gen_comp | a gen_comp.gt := gen_comp.reverse <$> (get_remaining_sign_aux a spec_comp.lt) | a gen_comp.ge := gen_comp.reverse <$> (get_remaining_sign_aux a spec_comp.le) | gen_comp.gt gen_comp.ne := gen_comp.ne | gen_comp.lt gen_comp.ne := gen_comp.ne | gen_comp.ne gen_comp.ne := gen_comp.ne | _ gen_comp.ne := none | a b := get_remaining_sign_aux a b.to_spec_comp /-meta def get_unknown_sign_data : prod_form_comp_data β†’ mul_state (option (Ξ£ e, sign_data e)) | ⟨⟨prod_f, c⟩, prf, _⟩ := do sds ← prod_f.exps.keys.mmap (sign_of_term prod_f), let known_signs := (sds.bfilter option.is_some), if known_signs.length = 1 then match sign_of_prod (known_signs.map option.iget) with | some ks := match get_remaining_sign ks c with | some c' := let i := sds.index_of none, e := prod_f.exps.keys.inth i, pfe := sign_proof.adhoc e c' (tactic.fail "unfinished adhoc") in return $ some ⟨e, ⟨_, pfe⟩⟩ -- e has sign ks | none := return none end | none := return none end else return none-/ private meta def reduce_sig_opt_list {Ξ±} {Ξ² : Ξ± β†’ Type} : list (Ξ£ a : Ξ±, option (Ξ² a)) β†’ list (Ξ£ a : Ξ±, (Ξ² a)) | [] := [] | (⟨a, none⟩::t) := reduce_sig_opt_list t | (⟨a, some b⟩::t) := ⟨a, b⟩::reduce_sig_opt_list t private lemma aux_sign_infer_tac_lemma (P : Prop) : P := sorry -- TODO private meta def aux_sign_infer_tac (e : expr) (pf : prod_form) (sds : hash_map expr sign_data) (c : gen_comp) : tactic expr := let sds' : list ((Ξ£ e, (sign_data e))) := reduce_sig_opt_list $ pf.exps.keys.map (Ξ» e, sigma.mk e (sds.find e)) in do --sds ← pf.exps.keys.mmap $ Ξ» e, sigma.mk e <$> (si e), sds'.mmap (Ξ» a, a.snd.prf.reconstruct), tp ← c.to_function e `(0 : β„š), tactic.mk_app ``aux_sign_infer_tac_lemma [tp] -- TODO : used when only one sign in the middle is unknown -- proves e C 0 when pf is the prod form of whole private meta def aux_sign_infer_tac_2 (e whole : expr) (sd : sign_data whole) (pf : prod_form) (sds : hash_map expr sign_data) (c : gen_comp) : tactic expr := let sds' : list ((Ξ£ e, (sign_data e))) := reduce_sig_opt_list $ pf.exps.keys.map (Ξ» e, sigma.mk e (sds.find e)) in do --sds ← pf.exps.keys.mmap $ Ξ» e, sigma.mk e <$> (si e), sds'.mmap (Ξ» a, a.snd.prf.reconstruct), sd.prf.reconstruct, tp ← c.to_function e `(0 : β„š), tactic.mk_app ``aux_sign_infer_tac_lemma [tp] /-- Assumes known_signs.length = pf.length -/ meta def infer_expr_sign_data_aux (e : expr) (pf : prod_form) (known_signs : list gen_comp) : mul_state (option Ξ£ e', sign_data e') := let prod_sign := (if pf.coeff < 0 then gen_comp.reverse else id) <$> sign_of_prod known_signs in match prod_sign with | some ks := do sis ← all_signs, let pfe := sign_proof.adhoc e ks (do s ← format_sign e ks, return ⟨s, "inferred from other sign data", []⟩) (aux_sign_infer_tac e pf sis ks) in --(do s ← tactic.pp e, sf ← tactic.pp ks, tactic.fail $ "unfinished adhoc -- infer-expr-sign-data-aux: 0 " ++ sf.to_string ++ s.to_string) return $ some ⟨e, ⟨_, pfe⟩⟩ | none := return none end /-- Infers the sign of an expression when the sign of subexpressions is known. -/ meta def infer_expr_sign_data (e : expr) (pf : prod_form) : mul_state (option Ξ£ e', sign_data e') := do sds ← pf.exps.keys.mmap (sign_of_term pf), let known_signs := sds.reduce_option, if pf.exps.keys.length = known_signs.length then infer_expr_sign_data_aux e pf known_signs else return none private meta def recheck_known_signs_aux (ks : list gen_comp) (es : gen_comp) (flip_coeff : bool) (i : β„•): option gen_comp := if i β‰₯ ks.length then none else let ks' := ks.remove_nth i, prod_sign := (if flip_coeff then gen_comp.reverse else id) <$> sign_of_prod ks' in match prod_sign with | some sn := get_remaining_sign sn es | none := none end /-- if we know the sign of e and all of its components, recalculate the sign of each component to check. -/ meta def recheck_known_signs (e : expr) (sd : option (sign_data e)) (pf : prod_form) (ks : list gen_comp) (flip_coeff : bool) : mul_state (list Ξ£ e', sign_data e') := match sd with | none := return [] | some ⟨es, p⟩ := list.reduce_option <$> ((list.range ks.length).mmap $ Ξ» i, match recheck_known_signs_aux ks es flip_coeff i with | some c := do sis ← all_signs, let e' := pf.exps.keys.inth i, let pfe := sign_proof.adhoc e' c (do s ← format_sign e' c, return ⟨s, "inferred from other sign data", []⟩) (aux_sign_infer_tac_2 e' e ⟨es, p⟩ pf sis c), return $ some ⟨e', ⟨_, pfe⟩⟩ | none := return none end) end /-- Tries to infer sign data of variables in expression when the sign of the whole expression is known. -/ meta def get_unknown_sign_data (e : expr) (sd : option (sign_data e)) (pf : prod_form) : mul_state (list Ξ£ e', sign_data e') := do sds ← pf.exps.keys.mmap (sign_of_term pf), let known_signs := sds.reduce_option, let num_vars := pf.exps.keys.length, if (known_signs.length = num_vars - 1) && sd.is_some then let prod_sign := (if pf.coeff < 0 then gen_comp.reverse else id) <$> sign_of_prod known_signs in match prod_sign with | some ks := match get_remaining_sign ks sd.iget.c with | some c' := do sis ← all_signs, let i := sds.index_of none, let e' := pf.exps.keys.inth i, let sd' := sd.iget, let pfe := sign_proof.adhoc e' c' (do s ← format_sign e' c', return ⟨s, "inferred from other sign data", []⟩) (aux_sign_infer_tac_2 e' e sd' pf sis c'), -- (tactic.fail "unfinished adhoc -- get-unknown-sign-data"), return $ [⟨e', ⟨_, pfe⟩⟩] -- e has sign ks | none := return [] end | none := return [] end else if known_signs.length = num_vars then /-let prod_sign := (if pf.coeff < 0 then gen_comp.reverse else id) <$> sign_of_prod (known_signs.map option.iget) in match prod_sign with | some ks := if sd.c.implies ks then return none else let pfe := sign_proof.adhoc e ks (tactic.fail "unfinished adhoc") in return $ some ⟨e, ⟨_, pfe⟩⟩ | none := return none end-/ do k1 ← infer_expr_sign_data_aux e pf known_signs, k2 ← recheck_known_signs e sd pf known_signs (pf.coeff < 0), match k1 with | some k1' := return $ k1'::k2 | none := return k2 end else return [] end sign_inference section sfcd_to_ineq /- -- assumes lhs < rhs as exprs. cl*lhs + cr*rhs R 0 ==> ineq_data private meta def mk_ineq_data_of_lhs_rhs (lhs rhs : expr) (cl cr : β„š) (c : comp) {s} (pf : sum_form_proof s) : Ξ£ l r, ineq_data l r := let c' := if cl > 0 then c else c.reverse, iq := ineq.of_comp_and_slope (c') (slope.some (-cr/cl)) in ⟨lhs, rhs, ⟨iq, ineq_proof.of_sum_form_proof lhs rhs iq pf⟩⟩ --_ _ _ (iq.to_expr lhs rhs pf)⟩⟩ -- TODO --⟨lhs, rhs, ⟨iq, ineq_proof.hyp _ _ _ ```(0)⟩⟩ -- TODO -/ -- assuming 1 r coeff*lhs^el*rhs^er, finds r' such that 1 r coeff*|lhs|^el*|rhs|^er /-private meta def get_abs_val_comp (lhs rhs : expr) (el er : β„€) (coeff : β„š) : spec_comp β†’ mul_state comp | spec_comp.lt := _ | spec_comp.le := _ | spec_comp.eq := _ -/ -- is_junk_comp c lhss rhss checks to see if lhs c rhs is of the form pos > neg, neg < pos, etc -- we can assume the gen_comps are strict. private meta def is_junk_comp : comp β†’ gen_comp β†’ gen_comp β†’ bool | comp.gt gen_comp.gt gen_comp.lt := tt | comp.ge gen_comp.gt gen_comp.lt := tt | comp.le gen_comp.lt gen_comp.gt := tt | comp.lt gen_comp.lt gen_comp.gt := tt | _ _ _ := ff -- none if can never lower. some tt if can always lower. some ff if can only lower by even number private meta def can_lower (e : expr) (ei : β„€) : mul_state (option bool) := do iplo ← is_pos_le_one e, if iplo then return $ some tt else do ingno ← is_neg_ge_neg_one e, if ingno && (ei % 2 = 0) then return $ some ff else do ilno ← is_le_neg_one e, if ilno && (ei % 2 = 1) then return $ some ff else return none private meta def can_raise (e : expr) (ei : β„€) : mul_state (option bool) := do igo ← is_ge_one e, if igo then return $ some tt else do ilno ← is_le_neg_one e, if ilno && (ei % 2 = 0) then return $ some ff else do ingno ← is_neg_ge_neg_one e, if ingno && (ei % 2 = 1) then return $ some ff else return none private meta def can_change_aux (diff_even : bool) : option bool β†’ bool | (some tt) := tt | (some ff) := diff_even | none := ff private meta def can_change (ob : option bool) (el er : β„€) : bool := can_change_aux ((el - er) % 2 = 0) ob -- assuming cmpl and cmpr are the signs of lhs and rhs, tries to find el', er' such that lhs^el*rhs^er ≀ lhs^el'*rhs^er' private meta def balance_coeffs : expr β†’ expr β†’ β„€ β†’ β„€ β†’ mul_state (list (β„€ Γ— β„€)) | lhs rhs el er:= if el = (/-trace_val-/ ("el, -er", lhs, rhs, el, -er)).2.2.2.2 then return $ [(el, er)] else if (/-trace_val-/ ("el.nat_abs", el.nat_abs)).2 ≀ er.nat_abs then do cll ← /-trace_val <$> -/can_lower lhs el, crl ← /-trace_val <$>-/ can_raise lhs el, clr ← /-trace_val <$> -/can_lower rhs er, crr ← /-trace_val <$>-/ can_raise rhs er, return $ if (el < 0) && (er > 0) then (guard (can_change clr el er) >> return (el, -el)) <|> (guard (can_change cll el er) >> return (-er, er)) else if (el > 0) && (er < 0) then (guard (can_change crr el er) >> return (el, -el)) <|> (guard (can_change crl el er) >> return (-er, er)) else if (el > 0) && (er > 0) then (guard (can_change clr el er) >> return (el, -el)) <|> (guard (can_change cll el er) >> return (-er, er)) else if (el < 0) && (er < 0) then (guard (can_change crr el er) >> return (el, -el)) <|> (guard (can_change crl el er) >> return (-er, er)) else [] else do pro ← balance_coeffs rhs lhs er el, return $ pro.map (Ξ» p, (p.2, p.1)) /-return $ match clr, crl with | some br, some bl := if br then el else if (er - el) % 2 = 0 then el else if bl then er else none | some br, none := if br || ((er - el)%2 = 0) then some el else none | none, some bl := if bl || ((er - el)%2 = 0) then some er else none | none, none := none end else do cll ← can_lower lhs el, crr ← can_raise rhs er, return $ match cll, crr with | some bl, some br := if bl then er else if (el - er) % 2 = 0 then er else if br then el else none | some bl, none := if bl || ((el - er) % 2 = 0) then some er else none | none, some br := if br || ((el - er) % 2 = 0) then some el else none | none, none := none end-/ -- assumes lhs > rhs as exprs, and el = -er. 1 R coeff*lhs^el*rhs^er ==> ineq private meta def mk_ineq_of_balanced_lhs_rhs (coeff : β„š) (lhs rhs : expr) (el er : β„€) (c : spec_comp) : mul_state ineq := if (el % 2 = 0) && (coeff < 0) then -- todo: this is a contradiction do ⟨cmpl, _⟩ ← si lhs, return $ (/-trace_val-/ ("GOT A CONTRADICTION HERE", ineq.of_comp_and_slope cmpl.to_comp.reverse (slope.some 0))).2 else -- know: 1 c | (root coeff |el|)*lhs^(sign el)*rhs^(sign er) | do ⟨cmpl, _⟩ ← si lhs, ⟨cmpr, _⟩ ← si rhs, let coeff_comp := if coeff < 0 then comp.lt else comp.gt, let prod_sign := (cmpl.to_comp.prod cmpr.to_comp).prod coeff_comp, let exp_val := el.nat_abs, --if prod_sign.is_greater then -- know: 1 c (root coeff exp_val)*lhs^(sign el)*rhs^(sign er) if cmpl.is_greater then -- lhs > 0 let c' := c.to_comp, m := (if prod_sign.is_greater then (1 : β„š) else -1) * nth_root_approx approx_dir.over coeff exp_val approx_prec in return $ /-trace_val $-/ if el < 0 then ineq.of_comp_and_slope c' (slope.some m) else ineq.of_comp_and_slope c'.reverse (slope.some (1/m)) else -- x < 0 let c' := c.to_comp.reverse, m := (if prod_sign.is_greater then (1 : β„š) else -1) * nth_root_approx approx_dir.under coeff exp_val approx_prec in return $ if el < 0 then ineq.of_comp_and_slope c' (slope.some m) else ineq.of_comp_and_slope c'.reverse (slope.some (1/m)) /-else -- know: 1 c -(root coeff exp_val)*lhs^(sign el)*rhs^(sign er) if cmpl.is_greater then -- lhs > 0 let c' := c.to_comp, m := nth_root_approx approx_dir.over coeff exp_val approx_prec in if el < 0 then return $ ineq.of_comp_and_slope c' (slope.some (-m)) else return $ ineq.of_comp_and_slope c'.reverse (slope.some (-1/m)) else let c' := c.to_comp.reverse, m := nth_root_approx approx_dir.under coeff exp_val approx_prec-/ /-if el < 0 then let c' := if cmpl.is_less then c.to_comp.reverse else c.to_comp, el' := -el in -- lhs^el' c' coeff * rhs^er -/ /-if (coeff < 0) && (exp % 2 = 0) then -- 1 ≀ neg. impossible. todo: create contr return none else if coeff < 0 then return none else if exp > 0 then let nexp := exp.nat_abs, coeff_root_approx := nth_root_approx'' approx_dir.over coeff nexp approx_prec in return none else return none-/ -- assumes lhs > rhs as exprs. 1 R coeff* lhs^el * rhs^er ==> ineq_data private meta def mk_ineq_of_lhs_rhs (coeff : β„š) (lhs rhs : expr) (el er : β„€) (c : spec_comp) : mul_state (list ineq) := do ⟨cmpl, _⟩ ← si lhs, ⟨cmpr, _⟩ ← si rhs, let cmpl' := cmpl.pow el, let cmpr' := cmpr.pow er, if is_junk_comp (if cmpl' = gen_comp.gt then c.to_comp else c.to_comp.reverse) cmpl' (if coeff > 0 then cmpr' else cmpr'.reverse) then return [] else do ncs ← balance_coeffs lhs rhs el er, ncs.mmap $ Ξ» p, do t ← mk_ineq_of_balanced_lhs_rhs coeff lhs rhs p.1 p.2 c, return (/-trace_val-/ ("got from mk_ineq", ncs.length, lhs, rhs, el, er, p.1, p.2, t)).2.2.2.2.2.2.2.2 /-match ncs with | none := return none | some (el', er') := some <$> mk_ineq_of_balanced_lhs_rhs coeff lhs rhs (trace_val ("calling mk_ineq", lhs, rhs, el, er, el')).2.2.2.2.2 er' c end-/ -- assumes lhs > rhs as exprs. 1 R coeff* lhs^el * rhs^er ==> ineq_data /-private meta def mk_ineq_of_lhs_rhs (coeff : β„š) (lhs rhs : expr) (el er : β„€) (c : spec_comp) : mul_state (option ineq) := do ⟨cmpl, _⟩ ← si lhs, ⟨cmpr, _⟩ ← si rhs, let cmpl' := cmpl.pow el, let cmpr' := cmpr.pow er, if is_junk_comp (if cmpl' = gen_comp.gt then c.to_comp else c.to_comp.reverse) cmpl' (if coeff > 0 then cmpr' else cmpr'.reverse) then return none else if cmpl = gen_comp.gt then -- lhs^(-el) c coeff*rhs^(er) if (el = -1) && (er = 1) then return $ some $ ineq.of_comp_and_slope c.to_comp (slope.some coeff) else if (el = 1) && (er = -1) then return $ some $ ineq.of_comp_and_slope c.to_comp.reverse (slope.some (1/coeff)) else if (el = -1) && (er > 0) then -- lhs c coeff*rhs^er else return none else if cmpl = gen_comp.lt then -- lhs^(-el) -c coeff*rhs^(er) if (el = -1) && (er = 1) then return $ some $ ineq.of_comp_and_slope c.to_comp.reverse (slope.some coeff) else if (el = 1) && (er = -1) then return $ some $ ineq.of_comp_and_slope c.to_comp (slope.some (1/coeff)) else if el = -1 then return none else return none else return none-/ -- assumes lhs > rhs as exprs. 1 = coeff* lhs^el * rhs^er ==> eq_data (coeff) -- TODO private meta def mk_eq_of_lhs_rhs (coeff : β„š) (lhs rhs : expr) (el er : β„€) : mul_state (option β„š) := do ⟨cmpl, _⟩ ← si lhs, ⟨cmpr, _⟩ ← si rhs, -- if cmpl = gen_comp.gt then -- lhs^(-el) c coeff*rhs^(er) if (el = -1) && (er = 1) then return $ some coeff else if (el = 1) && (er = -1) then return $ some (1/coeff) else return none -- else -- lhs^(-el) -- return none -- TODO section private lemma mk_ineq_proof_of_lhs_rhs_aux (P : Prop) {sp old : Prop} (p' : sp) (p : old) : P := sorry #check @mk_ineq_proof_of_lhs_rhs_aux open tactic --#check @op_of_one_op_pos meta def mk_ineq_proof_of_lhs_rhs /-(coeff : β„š)-/ (lhs rhs : expr) (el er : β„€) /-(c : spec_comp)-/ {s} (pf : prod_form_proof s) (iq : ineq) : mul_state (tactic expr) := do sdl ← si lhs, match sdl with | ⟨gen_comp.gt, pf'⟩ := do oil ← oi lhs, oir ← oi rhs, return $ do --tactic.trace "in mk_ineq_proof_of_lhs_rhs 1", pfr ← pf.reconstruct, trace "1", pfr' ← pf'.reconstruct, --trace "reconstructed::", infer_type pfr >>= trace, infer_type pfr' >>= trace, trace pf, tpr ← tactic.mk_mapp ``op_of_one_op_pos [none, none, none, none, none, some pfr', none, none, some pfr], if (el = 1) && (er = -1) then tactic.mk_app ``op_of_inv_op_inv_pow [tpr] else if (el = -1) && (er = 1) then tactic.mk_app ``op_of_op_pow [tpr] else do trace "know", infer_type pfr >>= trace, infer_type pfr' >>= trace, trace "wts", trace (lhs, rhs, iq), tp ← iq.to_type lhs rhs, mk_mapp ``mk_ineq_proof_of_lhs_rhs_aux [tp, none, none, pfr', pfr] -- fail $ "can't handle non-one exponents yet" ++ to_string el ++ " " ++ to_string er | ⟨gen_comp.lt, pf'⟩ := return $ do --tactic.trace "in mk_ineq_proof_of_lhs_rhs 2", pfr ← pf.reconstruct,-- trace "reconstructed::", infer_type pfr >>= trace, pfr' ← pf'.reconstruct, tactic.mk_mapp ``op_of_one_op_neg [none, none, none, none, none, some pfr', none, none, some pfr] | _ := return $ tactic.fail "mk_ineq_proof_of_lhs_rhs failed, no sign info for lhs" end end meta def find_deps_of_pfp : Ξ  {pfc}, prod_form_proof pfc β†’ tactic (list proof_sketch) | _ (prod_form_proof.of_ineq_proof id _ _) := do id' ← id.sketch, return [id'] | _ (prod_form_proof.of_eq_proof id _) := do id' ← id.sketch, return [id'] | _ (prod_form_proof.of_expr_def e pf) := do s ← to_string <$> (pf.to_expr >>= tactic.pp), return [⟨"1 = " ++ s, "by definition", []⟩] | _ (prod_form_proof.of_pow _ pfp) := find_deps_of_pfp pfp | _ (prod_form_proof.of_mul pfp1 pfp2 _) := do ds1 ← find_deps_of_pfp pfp1, ds2 ← find_deps_of_pfp pfp2, return (ds1 ++ ds2) | _ (prod_form_proof.adhoc _ t _) := do t' ← t, return [t'] | _ (prod_form_proof.fake _) := return [] meta def make_proof_sketch_for_ineq {s} (lhs rhs : expr) (iq : ineq) (pf : prod_form_proof s) : tactic proof_sketch := do s' ← format_ineq lhs rhs iq, deps ← find_deps_of_pfp pf, return ⟨s', "by multiplicative arithmetic", deps⟩ -- assumes lhs > rhs as exprs. 1 R coeff* lhs^el * rhs^er ==> ineq_data private meta def mk_ineq_data_of_lhs_rhs (coeff : β„š) (lhs rhs : expr) (el er : β„€) (c : spec_comp) {s} (pf : prod_form_proof s) : mul_state (list Ξ£ l r, ineq_data l r) := do iq ← mk_ineq_of_lhs_rhs coeff lhs rhs el er c, iq.mmap $ Ξ» id, do tac ← mk_ineq_proof_of_lhs_rhs lhs rhs el er pf id, return $ ⟨lhs, rhs, ⟨id, ineq_proof.adhoc _ _ id (make_proof_sketch_for_ineq lhs rhs id pf) tac⟩⟩ /- match iq with | none := return none | some id := do tac ← mk_ineq_proof_of_lhs_rhs lhs rhs el er pf id, return $ some ⟨lhs, rhs, ⟨id, ineq_proof.adhoc _ _ id $ tac -- do t ← id.to_type lhs rhs, tactic.trace "sorrying", tactic.trace t, tactic.to_expr ``(sorry : %%t) --tactic.fail "mk_ineq_data not implemented" ⟩⟩ end-/ -- assumes lhs > rhs as exprs. 1 = coeff* lhs^el * rhs^er ==> eq_data -- TODO private meta def mk_eq_data_of_lhs_rhs (coeff : β„š) (lhs rhs : expr) (el er : β„€) {s} (pf : prod_form_proof s) : mul_state (option Ξ£ l r, eq_data l r) := do eqc ← mk_eq_of_lhs_rhs coeff lhs rhs el er, match eqc with | none := return none | some c := do /-tac ← mk_ineq_proof_of_lhs_rhs lhs el er pf,-/ return none -- return $ some ⟨lhs, rhs, ⟨id, ineq_proof.adhoc _ _ id $ -- tac -- do t ← id.to_type lhs rhs, tactic.trace "sorrying", tactic.trace t, tactic.to_expr ``(sorry : %%t) --tactic.fail "mk_ineq_data not implemented" -- ⟩⟩ -- todo end -- pf proves 1 c coeff*e^(-1) -- returns a proof of 1 c' (1/coeff) * e -- 1 c coeff * e^exp private meta def mk_ineq_data_of_single_cmp (coeff : β„š) (e : expr) (exp : β„€) (c : spec_comp) {s} (pf : prod_form_proof s) : mul_state (option Ξ£ lhs rhs, ineq_data lhs rhs) := if exp = 1 then let inq := ineq.of_comp_and_slope c.to_comp (slope.some coeff), id : ineq_data `(1 : β„š) e := ⟨inq, ineq_proof.adhoc _ _ _ (make_proof_sketch_for_ineq `(1 : β„š) e inq pf) (do pf' ← pf.reconstruct, tactic.mk_mapp ``one_op_of_op [none, none, none, none, pf'])⟩ in--(tactic.fail "mk_ineq_data_of_single_cmp not implemented")⟩ in return $ some ⟨_, _, id⟩ else if exp = -1 then let inq := ineq.of_comp_and_slope c.to_comp.reverse (slope.some coeff).invert, id : ineq_data `(1 : β„š) e := ⟨inq, ineq_proof.adhoc _ _ _ (make_proof_sketch_for_ineq `(1 : β„š) e inq pf) (do pf' ← pf.reconstruct, tactic.mk_mapp ``one_op_of_op_inv [none, none, none, none, pf'])⟩ in return $ some ⟨_, _, id⟩ else -- TODO if exp > 0 then if (coeff < 0) && (exp % 2 = 0) then return none -- todo: this is a contradiction else do ⟨es, _⟩ ← si e, if es.is_greater then let m := nth_root_approx approx_dir.over coeff exp.nat_abs approx_prec, inq := ineq.of_comp_and_slope c.to_comp (slope.some m) in return $ some $ ⟨_, _, ⟨inq, ineq_proof.adhoc rat_one e _ (make_proof_sketch_for_ineq rat_one e inq pf) (tactic.fail "mk_ineq_data_of_single_cmp not implemented")⟩⟩ else --todo return none else return none private meta def mk_eq_data_of_single_cmp (coeff : β„š) (e : expr) (exp : β„€) {s} (pf : prod_form_proof s) : mul_state (option Ξ£ lhs rhs, eq_data lhs rhs) := if exp = 1 then let id : eq_data `(1 : β„š) e := ⟨coeff, eq_proof.adhoc _ _ _ (tactic.fail "mk_eq_data_of_single_cmp not implemented") (tactic.fail "mk_eq_data_of_single_cmp not implemented")⟩ in return $ some ⟨_, _, id⟩ else -- TODO return none -- we need a proof constructor for ineq and eq meta def prod_form_comp_data.to_ineq_data : prod_form_comp_data β†’ mul_state (list (Ξ£ lhs rhs, ineq_data lhs rhs)) | ⟨⟨_, spec_comp.eq⟩, _, _⟩ := return [] | ⟨⟨⟨coeff, exps⟩, c⟩, prf, _⟩ := match exps.to_list with | [(rhs, cr), (lhs, cl)] := if rhs.lt lhs then mk_ineq_data_of_lhs_rhs coeff lhs rhs cl cr c prf else mk_ineq_data_of_lhs_rhs coeff rhs lhs cr cl c prf | [(rhs, cr)] := do t ← mk_ineq_data_of_single_cmp coeff rhs cr c prf, return $ /-trace_val-/ ("in pfcd.toid:", t), match t with | some t' := return [t'] | none := return [] end | [] := if coeff β‰₯ 1 then return [] else return [⟨rat_one, rat_one, ⟨ineq.of_comp_and_slope c.to_comp (slope.some coeff), ineq_proof.adhoc _ _ _ (tactic.fail "prod_form_comp_data.to_ineq_data not implemented") (tactic.fail "oops")⟩⟩] | _ := return [] end meta def prod_form_comp_data.to_eq_data : prod_form_comp_data β†’ mul_state (option (Ξ£ lhs rhs, eq_data lhs rhs)) | ⟨⟨⟨coeff, exps⟩, spec_comp.eq⟩, prf, _⟩ := match exps.to_list with | [(rhs, cr), (lhs, cl)] := if rhs.lt lhs then mk_eq_data_of_lhs_rhs coeff lhs rhs cl cr prf else mk_eq_data_of_lhs_rhs coeff rhs lhs cr cl prf | [(rhs, cr)] := mk_eq_data_of_single_cmp coeff rhs cr prf | _ := return none end | _ := return none end sfcd_to_ineq --meta structure sign_storage := --(signs : hash_map expr sign_info) --private meta def inh_sp (e : expr) : inhabited (sign_proof e gen_comp.ne) := ⟨sign_proof.adhoc _ _ (tactic.failed)⟩ meta def ne_pf_of_si {e : expr} (sd : sign_data e) : sign_proof e gen_comp.ne := sign_proof.diseq_of_strict_ineq sd.prf meta def find_cancelled (pf1 pf2 : prod_form) : list expr := pf1.exps.fold [] (Ξ» t exp l, if exp + pf2.get_exp t = 0 then t::l else l) meta def ne_proofs_of_cancelled (pf1 pf2 : prod_form) : mul_state (list Ξ£ e : expr, sign_proof e gen_comp.ne) := (find_cancelled pf1 pf2).mmap (Ξ» e, do sd ← si e, return ⟨e, ne_pf_of_si sd⟩) meta def prod_form_proof.pfc {pfc} : prod_form_proof pfc β†’ prod_form_comp := Ξ» _, pfc open native -- assumes the exponent of pvt in both is nonzero. Does not enforce elim_list preservation meta def prod_form_comp_data.elim_expr_aux : prod_form_comp_data β†’ prod_form_comp_data β†’ expr β†’ mul_state (option prod_form_comp_data) | ⟨⟨pf1, comp1⟩, prf1, elim_list1⟩ ⟨⟨pf2, comp2⟩, prf2, elim_list2⟩ pvt := let exp1 := pf1.get_exp pvt, exp2 := pf2.get_exp pvt in if exp1 * exp2 < 0 then let npow : int := nat.lcm exp1.nat_abs exp2.nat_abs, pf1p := prod_form_proof.of_pow (npow/(abs exp1)) prf1, pf2p := prod_form_proof.of_pow (npow/(abs exp2)) prf2 in do neprfs ← ne_proofs_of_cancelled pf1p.pfc.pf pf2p.pfc.pf, let nprf := prod_form_proof.of_mul pf1p pf2p neprfs in return $ some $ prod_form_comp_data.round ⟨_, nprf, (rb_set.union elim_list1 elim_list2).insert pvt⟩ approx_prec else if comp1 = spec_comp.eq then let pf1p := prod_form_proof.of_pow (-1) prf1 in prod_form_comp_data.elim_expr_aux ⟨_, pf1p, elim_list1⟩ ⟨_, prf2, elim_list2⟩ pvt else if comp2 = spec_comp.eq then let pf2p := prod_form_proof.of_pow (-1) prf2 in prod_form_comp_data.elim_expr_aux ⟨_, prf1, elim_list1⟩ ⟨_, pf2p, elim_list2⟩ pvt else return none meta def prod_form_comp_data.elim_expr (pfcd1 pfcd2 : prod_form_comp_data) (pvt : expr) : mul_state (option prod_form_comp_data) := if pfcd1.pfc.pf.get_exp pvt = 0 then return $ some ⟨pfcd1.pfc, pfcd1.prf, pfcd1.elim_list.insert pvt⟩ else if pfcd2.pfc.pf.get_exp pvt = 0 then return none else prod_form_comp_data.elim_expr_aux pfcd1 pfcd2 pvt private meta def compare_coeffs (sf1 sf2 : prod_form) (h : expr) : ordering := let c1 := sf1.get_exp h, c2 := sf2.get_exp h in if c1 < c2 then ordering.lt else if c2 < c1 then ordering.gt else ordering.eq private meta def compare_coeff_lists (sf1 sf2 : prod_form) : list expr β†’ list expr β†’ ordering | [] [] := ordering.eq | [] _ := ordering.lt | _ [] := ordering.gt | (h1::t1) (h2::t2) := if h1 = h2 then let ccomp := compare_coeffs sf1 sf2 h1 in if ccomp = ordering.eq then compare_coeff_lists t1 t2 else ccomp else cmp h1 h2 meta def prod_form.order (sf1 sf2 : prod_form) : ordering := compare_coeff_lists sf1 sf2 sf1.exps.keys sf2.exps.keys meta def prod_form_comp.order : prod_form_comp β†’ prod_form_comp β†’ ordering | ⟨_, spec_comp.lt⟩ ⟨_, spec_comp.le⟩ := ordering.lt | ⟨_, spec_comp.lt⟩ ⟨_, spec_comp.eq⟩ := ordering.lt | ⟨_, spec_comp.le⟩ ⟨_, spec_comp.eq⟩ := ordering.lt | ⟨sf1, _⟩ ⟨sf2, _⟩ := prod_form.order sf1 sf2 -- need to normalize! meta def prod_form_comp_data.order : prod_form_comp_data β†’ prod_form_comp_data β†’ ordering | ⟨sfc1, _, ev1⟩ ⟨sfc2, _, ev2⟩ := match sfc1.order sfc2 with | ordering.eq := cmp ev1.keys ev2.keys | a := a end meta instance prod_form_comp_data.has_lt : has_lt prod_form_comp_data := ⟨λ x y, prod_form_comp_data.order x y = ordering.lt⟩ meta instance prod_form_comp_data.decidable_lt : decidable_rel (@has_lt.lt prod_form_comp_data _) := Ξ» _ _, by apply_instance meta def prod_form_comp_data.elim_into (sfcd1 sfcd2 : prod_form_comp_data) (pvt : expr) (rv : rb_set prod_form_comp_data) : mul_state (rb_set prod_form_comp_data) := do elimd ← /-trace_val <$>-/ sfcd1.elim_expr sfcd2 pvt, match elimd with | none := return rv | some sfcd := return $ rv.insert sfcd end private meta def check_elim_lists_aux (sfcd1 sfcd2 : prod_form_comp_data) : bool := sfcd1.vars.all (Ξ» e, bnot (sfcd2.elim_list.contains e)) private meta def check_elim_lists (sfcd1 sfcd2 : prod_form_comp_data) : bool := check_elim_lists_aux sfcd1 sfcd2 && check_elim_lists_aux sfcd2 sfcd1 meta def prod_form_comp_data.needs_elim_against (sfcd1 sfcd2 : prod_form_comp_data) (e : expr) : bool := (check_elim_lists sfcd1 sfcd2) && (((sfcd1.vars.append sfcd2.vars).filter (Ξ» e' : expr, e'.lt e)).length ≀ 2) namespace prod_form /-- Uses sfcd to eliminate the e from all comparisons in cmps, and adds the new comparisons to rv -/ meta def elim_expr_from_comp_data_filtered (sfcd : prod_form_comp_data) (cmps : rb_set prod_form_comp_data) (e : expr) (rv : rb_set prod_form_comp_data) : mul_state (rb_set prod_form_comp_data) := cmps.mfold rv (Ξ» c rv', if (/-trace_val-/ (sfcd.needs_elim_against (/-trace_val-/ c) (/-trace_val-/ e) : bool)) = tt then sfcd.elim_into c e rv' else return rv') /-- Performs all possible eliminations with sfcd on cmps. Returns a set of all new comps, NOT including the old ones. -/ meta def new_exprs_from_comp_data_set (sfcd : prod_form_comp_data) (cmps : rb_set prod_form_comp_data) : mul_state (rb_set prod_form_comp_data) := sfcd.vars.mfoldr (Ξ» e rv, elim_expr_from_comp_data_filtered sfcd cmps (/-trace_val-/ ("nefcds: ", e)).2 rv) mk_rb_set meta def elim_list_into_set : rb_set prod_form_comp_data β†’ list prod_form_comp_data β†’ mul_state (rb_set prod_form_comp_data) | cmps [] := return (/-trace_val-/ "elim_list_into_set []") >> return cmps | cmps (sfcd::new_cmps) := return (/-trace_val-/ ("elim_list_into_set cons", cmps, sfcd)) >> if cmps.contains sfcd then elim_list_into_set cmps new_cmps else do new_gen ← new_exprs_from_comp_data_set sfcd cmps,--.keys let new_gen := new_gen.keys in elim_list_into_set (cmps.insert sfcd) (new_cmps.append new_gen) meta def elim_list_set (cmps : list prod_form_comp_data) (start : rb_set prod_form_comp_data := mk_rb_set) : mul_state (rb_set prod_form_comp_data) := do s ← elim_list_into_set (/-trace_val-/ ("start:",start)).2 (/-trace_val-/ ("cmps:",cmps)).2, return (/-trace_val-/ ("elim_list_set finished:", s)).2 meta def elim_list (cmps : list prod_form_comp_data) : mul_state (list prod_form_comp_data) := rb_set.to_list <$> elim_list_into_set mk_rb_set (/-trace_val-/ ("cmps:", cmps)).2 end prod_form open prod_form section bb_process meta def mk_eqs_of_expr_prod_form_pair : expr Γ— prod_form β†’ prod_form_comp_data | (e, sf) := let sf' := sf * (prod_form.of_expr e).pow (-1) in ⟨⟨sf', spec_comp.eq⟩, prod_form_proof.of_expr_def e sf', mk_rb_set⟩ meta def pfcd_of_ineq_data {lhs rhs} (id : ineq_data lhs rhs) : polya_state (option prod_form_comp_data) := do sdl ← get_sign_info lhs, sdr ← get_sign_info rhs, match sdl, sdr with | some sil, some sir := if sil.c.is_strict && sir.c.is_strict then return $ some $ prod_form_comp_data.of_ineq_data id sil.prf sir.prf else return none | _, _ := return (/-trace_val-/ ("no sign_info", lhs, rhs)) >> return none end -- TODO meta def pfcd_of_eq_data {lhs rhs} (ed : eq_data lhs rhs) : polya_state (option prod_form_comp_data) := do sdl ← get_sign_info lhs, sdr ← get_sign_info rhs, match sdl, sdr with | some sil, some sir := if sil.c.is_strict && sir.c.is_strict then return $ some $ prod_form_comp_data.of_eq_data ed sil.prf.diseq_of_strict_ineq else return none | _, _ := return none end section open tactic private meta def remove_one_from_pfcd_proof (old : prod_form_comp) (new : prod_form) (prf : prod_form_proof old) : tactic expr := do `(1*%%old_e) ← { old.pf with coeff := 1}.to_expr, `(1*%%new_e) ← { new with coeff := 1}.to_expr, prf' ← prf.reconstruct, (_, onp) ← tactic.solve_aux `((%%old_e : β„š) = %%new_e) `[simp only [rat.one_pow, mul_one, one_mul]], --tactic.infer_type onp >>= tactic.trace, --tactic.infer_type prf' >>= tactic.trace, --(l, r) ← infer_type onp >>= match_eq, --trace l, -- `((<) %%l' %%r') ← infer_type prf', -- trace r', -- trace $ (l = r' : bool), (ntp, prf'', _) ← infer_type prf' >>= tactic.rewrite onp, -- trace ntp, --infer_type prf'' >>= trace, --return prf'' mk_app ``eq.mp [prf'', prf'] end private meta def remove_one_from_pfcd (pfcd : prod_form_comp_data) : prod_form_comp_data := match pfcd with | ⟨⟨⟨coeff, exps⟩, c⟩, prf, el⟩ := if exps.contains rat_one then let pf' : prod_form := ⟨coeff, exps.erase rat_one⟩ in ⟨⟨pf', c⟩, (prod_form_proof.adhoc _ --prf.sketch (do s ← to_string <$> (pf'.to_expr >>= tactic.pp), deps ← find_deps_of_pfp prf, return ⟨"1 " ++ (to_string $ to_fmt c) ++ s, "rearranging", deps⟩) (remove_one_from_pfcd_proof pfcd.pfc pf' pfcd.prf)), el⟩ else pfcd end private meta def mk_pfcd_list : polya_state (list prod_form_comp_data) := do il ← /-trace_val <$>-/ get_ineq_list, el ← /-trace_val <$>-/ get_eq_list, dfs ← /-trace_val <$> -/ get_mul_defs, il' ← /-trace_val <$>-/ list.reduce_option <$> il.mmap (Ξ» ⟨_, _, id⟩, pfcd_of_ineq_data id), el' ← /-trace_val <$>-/ list.reduce_option <$> el.mmap (Ξ» ⟨_, _, ed⟩, pfcd_of_eq_data ed), let dfs' := /-trace_val $-/ dfs.map mk_eqs_of_expr_prod_form_pair in -- TODO: does this filter ones without sign info? return $ list.map remove_one_from_pfcd $ ((il'.append el').append dfs').qsort (Ξ» a b, if cmp a b = ordering.lt then tt else ff) private meta def mk_signed_pfcd_list : polya_state (list (prod_form Γ— Ξ£ e, option (sign_data e))) := do mds ← get_mul_defs, mds' : list (prod_form Γ— Ξ£ e, sign_info e) ← mds.mmap (Ξ» e_pf, do sd ← get_sign_info e_pf.1, return (e_pf.2, sigma.mk e_pf.1 sd)), return mds' /- return $ reduce_option_list $ mds'.map (Ξ» pf_sig, match pf_sig.2 with | ⟨e, some sd⟩ := some ⟨pf_sig.1, ⟨e, sd⟩⟩ | ⟨_, none⟩ := none end)-/ private meta def mk_sign_data_list : list expr β†’ polya_state (list (Ξ£ e, sign_data e)) | [] := return [] | (h::t) := do si ← get_sign_info h, match si with | some sd := list.cons ⟨h, sd⟩ <$> mk_sign_data_list t | none := mk_sign_data_list t end --set_option pp.all true private meta def mk_one_ineq_info_list : list expr β†’ polya_state (list (Ξ£ e, ineq_info e rat_one)) | [] := return [] | (h::t) := do si ← get_comps_with_one h, t' ← mk_one_ineq_info_list t, return $ list.cons ⟨h, si⟩ t' meta def mk_mul_state : polya_state (hash_map expr (Ξ» e, sign_data e) Γ— hash_map expr (Ξ» e, ineq_info e rat_one)) := do l ← get_expr_list, sds ← mk_sign_data_list l, iis ← mk_one_ineq_info_list $ sds.map sigma.fst, return (hash_map.of_list sds expr.hash, hash_map.of_list iis expr.hash) private meta def gather_new_sign_info_pass_one : polya_state (list Ξ£ e, sign_data e) := do dfs ← mk_signed_pfcd_list, ms ← mk_mul_state, let vv : mul_state (list Ξ£ e, sign_data e) := dfs.mfoldl (Ξ» l (pf_sig : prod_form Γ— Ξ£ e, option (sign_data e)), l.append <$> (get_unknown_sign_data pf_sig.2.1 pf_sig.2.2 pf_sig.1)) [], return $ (vv.run ms).1 -- return $ reduce_option_list $ (dfs.mfoldl (Ξ» (pf_sig : prod_form Γ— Ξ£ e, option (sign_data e)) (l : , l.append (get_unknown_sign_data pf_sig.2.1 pf_sig.2.2 pf_sig.1)) ms).1 /- the second pass was originally to handle transitivity, but we can assume this is handled in the additive module private meta def find_sign_proof_by_trans_eq {unsigned signed : expr} (ed : eq_data unsigned signed) (sd : sign_data signed) : option (Ξ£ e', sign_data e') := none -- assumes sd is not an eq or diseq private meta def find_sign_proof_by_trans_ineq {unsigned signed : expr} (id : ineq_data unsigned signed) (sd : sign_data signed) : option (Ξ£ e', sign_data e') := let su := id.inq.to_comp, ss := sd.c.to_comp in if su.dir = ss.dir && (su.is_strict || ss.is_strict) --: ineq_data unsigned signed β†’ sign_data signed β†’ option (Ξ£ e', sign_data e') --| ⟨inq, prf⟩ ⟨c, prfs⟩ := none --(id : ineq_data unsigned signed) (sd : sign_data signed) : option (Ξ£ e', sign_data e') := --none meta def find_sign_proof_by_trans (e : expr) : list expr β†’ polya_state (option (Ξ£ e', sign_data e')) | [] := return none | (h::t) := do s ← get_sign_info h, ii ← get_ineqs e h, match ii, s with | _, none := return none | ineq_info.no_comps, _ := return none | ineq_info.equal ed, some sd := match find_sign_proof_by_trans_eq ed sd with | some p := return $ some p | none := find_sign_proof_by_trans t end | ineq_info.one_comp id, some sd := match find_sign_proof_by_trans_ineq id sd with | some p := return $ some p | none := find_sign_proof_by_trans t end | ineq_info.two_comps id1 id2, some sd := let o := find_sign_proof_by_trans_ineq id1 sd <|> find_sign_proof_by_trans_ineq id2 sd in match o with | some p := return $ some p | none := find_sign_proof_by_trans t end end meta def infer_sign_from_transitivity (e : expr) : polya_state (option (Ξ£ e', sign_data e')) := do exs ← get_weak_signed_exprs, find_sign_proof_by_trans e exs private meta def gather_new_sign_info_pass_two : polya_state (list Ξ£ e, sign_data e) := do use ← get_unsigned_exprs, ose ← use.mmap infer_sign_from_transitivity, return $ reduce_option_list ose -/ lemma rat_pow_pos_of_pos {q : β„š} (h : q > 0) (z : β„€) : rat.pow q z > 0 := sorry lemma rat_pow_pos_of_neg_even {q : β„š} (h : q < 0) {z : β„€} (hz1 : z > 0) (hz2 : z % 2 = 0) : rat.pow q z > 0 := sorry lemma rat_pow_neg_of_neg_odd {q : β„š} (h : q < 0) {z : β„€} (hz1 : z > 0) (hz2 : z % 2 = 1) : rat.pow q z < 0 := sorry lemma rat_pow_nonneg_of_nonneg {q : β„š} (h : q β‰₯ 0) (z : β„€) : rat.pow q z β‰₯ 0 := sorry lemma rat_pow_nonneg_of_nonpos_even {q : β„š} (h : q ≀ 0) {z : β„€} (hz1 : z > 0) (hz2 : z % 2 = 0) : rat.pow q z β‰₯ 0 := sorry lemma rat_pow_nonpos_of_nonpos_odd {q : β„š} (h : q ≀ 0) {z : β„€} (hz1 : z > 0) (hz2 : z % 2 = 1) : rat.pow q z ≀ 0 := sorry lemma rat_pow_zero_of_zero {q : β„š} (h : q = 0) (z : β„€) : rat.pow q z = 0 := sorry lemma rat_pow_zero (q : β„š) : rat.pow q 0 = 0 := sorry lemma rat_pow_pos_of_ne_even {q : β„š} (h : q β‰  0) {z : β„€} (hz1 : z > 0) (hz2 : z % 2 = 0) : rat.pow q z > 0 := sorry lemma rat_pow_ne_of_ne_odd {q : β„š} (h : q β‰  0) {z : β„€} (hz1 : z > 0) (hz2 : z % 2 = 1) : rat.pow q z β‰  0 := sorry lemma rat_pow_nonneg_of_pos_even (q : β„š) {z : β„€} (hz1 : z > 0) (hz2 : z % 2 = 0) : rat.pow q z β‰₯ 0 := sorry -- given a proof that e > 0, proves that rat.pow e z > 0. private meta def pos_pow_tac (pf : expr) (z : β„€) : tactic expr := tactic.mk_app ``rat_pow_pos_of_pos [pf, `(z)] private meta def nonneg_pow_tac (pf : expr) (z : β„€) : tactic expr := tactic.mk_app ``rat_pow_nonneg_of_nonneg [pf, `(z)] -- given a proof that e < 0, proves that rat.pow e z has the right sign private meta def neg_pow_tac (e pf : expr) (z : β„€) : tactic expr := if z > 0 then do zpp ← mk_int_sign_pf z, zmp ← mk_int_mod_pf z,--tactic.to_expr ``(by gen_comp_val : %%(reflect z) > 0), tactic.mk_mapp (if z % 2 = 0 then ``rat_pow_pos_of_neg_even else ``rat_pow_neg_of_neg_odd) [pf, none, zpp, zmp] else if z = 0 then tactic.mk_app ``rat_pow_zero [e] else tactic.fail "neg_pow_tac failed, neg expr to neg power" -- given a proof that e ≀ 0, proves that rat.pow e z has the right sign private meta def nonpos_pow_tac (e pf : expr) (z : β„€) : tactic expr := if z > 0 then do zpp ← mk_int_sign_pf z, zmp ← mk_int_mod_pf z,--tactic.to_expr ``(by gen_comp_val : %%(reflect z) > 0), tactic.mk_mapp (if z % 2 = 0 then ``rat_pow_nonneg_of_nonpos_even else ``rat_pow_nonpos_of_nonpos_odd) [pf, none, zpp, zmp] else if z = 0 then tactic.mk_app ``rat_pow_zero [e] else tactic.fail "neg_pow_tac failed, neg expr to neg power" private meta def ne_pow_tac (e pf : expr) (z : β„€) : tactic expr := if z > 0 then do zpp ← mk_int_sign_pf z, zmp ← mk_int_mod_pf z,--tactic.to_expr ``(by gen_comp_val : %%(reflect z) > 0), tactic.mk_mapp (if z % 2 = 0 then ``rat_pow_pos_of_ne_even else ``rat_pow_ne_of_ne_odd) [pf, none, zpp, zmp] else if z = 0 then tactic.mk_app ``rat_pow_zero [e] else tactic.fail "neg_pow_tac failed, neg expr to neg power" private meta def even_pow_tac (e : expr) (z : β„€) : tactic expr := if z > 0 then do --tactic.trace "in ept", tactic.trace e, zpp ← mk_int_sign_pf z, zmp ← mk_int_mod_pf z, tactic.mk_mapp ``rat_pow_nonneg_of_pos_even [e, none, zpp, zmp] else if z = 0 then tactic.mk_app ``rat_pow_zero [e] else tactic.fail "even_pow_tac failed, cannot handle neg power" -- assumes pf is the prod form of e and has only one component private meta def gather_new_sign_info_pass_two_aux (e : expr) (pf : prod_form) : polya_state $ option (Ξ£ e', sign_data e') := match pf.exps.to_list with | [(e', pow)] := do si ← get_sign_info (/-trace_val-/ ("e'", e')).2, match si with | some ⟨gen_comp.gt, pf⟩ := return $ some ⟨e, ⟨gen_comp.gt, sign_proof.adhoc _ _ (do s ← format_sign e' gen_comp.gt, return ⟨s, "inferred from other sign data", []⟩) (do pf' ← pf.reconstruct, pos_pow_tac pf' pow)⟩⟩ | some ⟨gen_comp.ge, pf⟩ := return $ some ⟨e, ⟨gen_comp.ge, sign_proof.adhoc _ _ (do s ← format_sign e' gen_comp.ge, return ⟨s, "inferred from other sign data", []⟩) (do pf' ← pf.reconstruct, nonneg_pow_tac pf' pow)⟩⟩ | some ⟨gen_comp.lt, pf⟩ := if pow β‰₯ 0 then let tac : tactic expr := (do pf' ← pf.reconstruct, neg_pow_tac e' pf' pow), c := (if pow = 0 then gen_comp.eq else if pow % 2 = 0 then gen_comp.gt else gen_comp.lt) in return $ some ⟨e, ⟨c, sign_proof.adhoc _ _ (do s ← format_sign e c, return ⟨s, "inferred from other sign data", []⟩) tac⟩⟩ else return none | some ⟨gen_comp.le, pf⟩ := if pow β‰₯ 0 then let tac : tactic expr := (do pf' ← pf.reconstruct, nonpos_pow_tac e' pf' pow), c := (if pow = 0 then gen_comp.eq else if pow % 2 = 0 then gen_comp.gt else gen_comp.lt) in return $ some ⟨e, ⟨c, sign_proof.adhoc _ _ (do s ← format_sign e c, return ⟨s, "inferred from other sign data", []⟩) tac⟩⟩ else return none | some ⟨gen_comp.eq, pf⟩ := return $ some ⟨e, ⟨gen_comp.eq, sign_proof.adhoc _ _ (do s ← format_sign e gen_comp.eq, return ⟨s, "inferred from other sign data", []⟩) (do pf' ← pf.reconstruct, tactic.mk_app ``rat_pow_zero [pf', `(pow)])⟩⟩ | some ⟨gen_comp.ne, pf⟩ := if pow β‰₯ 0 then let tac : tactic expr := (do pf' ← pf.reconstruct, ne_pow_tac e' pf' pow), c := (if pow = 0 then gen_comp.eq else if pow % 2 = 0 then gen_comp.gt else gen_comp.ne) in return $ some ⟨e, ⟨c, sign_proof.adhoc _ _ (do s ← format_sign e c, return ⟨s, "inferred from other sign data", []⟩) tac⟩⟩ else return none | none := if (pow β‰₯ 0) && (pow % 2 = 0) then let c := if pow = 0 then gen_comp.eq else gen_comp.ge in return $ some ⟨e, ⟨c, sign_proof.adhoc _ _ (do s ← format_sign e c, return ⟨s, "inferred from other sign data", []⟩) (even_pow_tac e' pow)⟩⟩ else return none end | _ := return none end -- get sign info for power exprs private meta def gather_new_sign_info_pass_two : polya_state (list Ξ£ e, sign_data e) := do exs ← get_mul_defs, let exs := (/-trace_val-/ ("of length one:", exs.filter (Ξ» e, e.2.exps.size = 1))).2, list.reduce_option <$> exs.mmap (Ξ» p, gather_new_sign_info_pass_two_aux p.1 p.2) private meta def gather_new_sign_info : polya_state (list Ξ£ e, sign_data e) := do l1 ← gather_new_sign_info_pass_one, l2 ← gather_new_sign_info_pass_two, return $ l1.append ((/-trace_val-/ ("THIS IS L2", l2)).2) private meta def mk_ineq_list (cmps : list prod_form_comp_data) : mul_state (list Ξ£ lhs rhs, ineq_data lhs rhs) := do il ← cmps.mmap (Ξ» pfcd, pfcd.to_ineq_data), return $ (/-trace_val-/ ("made ineq list: ", il.join)).2 private meta def mk_eq_list (cmps : list prod_form_comp_data) : mul_state (list Ξ£ lhs rhs, eq_data lhs rhs) := do il ← cmps.mmap (Ξ» pfcd, pfcd.to_eq_data), return $ list.reduce_option il private meta def mk_ineq_list_of_unelimed (cmps : list prod_form_comp_data) (start : rb_set prod_form_comp_data := mk_rb_set) : mul_state (rb_set prod_form_comp_data Γ— list Ξ£ lhs rhs, ineq_data lhs rhs) := do s ← prod_form.elim_list_set cmps start, l ← mk_ineq_list s.to_list, return (s, l) meta def prod_form.add_new_ineqs (start : rb_set prod_form_comp_data := mk_rb_set) : polya_state (rb_set prod_form_comp_data) := do --new_sign_info ← gather_new_sign_info, --new_sign_info.mmap (Ξ» sig, add_sign sig.2), is_contr ← contr_found, if is_contr then return start else do gather_new_sign_info >>= list.mmap (Ξ» sig, add_sign $ /-trace_val-/ sig.2), sfcds ← /-trace_val <$>-/ mk_pfcd_list, ms ← mk_mul_state, let ((pfcs, ineqs), _) := (mk_ineq_list_of_unelimed sfcds start).run ms, monad.mapm' (Ξ» s : Ξ£ lhs rhs, ineq_data lhs rhs, add_ineq s.2.2) ineqs, return pfcs -- TODO: FIX RETURN end bb_process end polya
0bc9f0b8fe2a507303bf74edcb66413b0176c0db
4727251e0cd73359b15b664c3170e5d754078599
/src/measure_theory/integral/set_to_l1.lean
e98d1aac0ef20592aedb110da446872ead32d892
[ "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
84,687
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_group E] [normed_space ℝ E] [normed_group F] [normed_space ℝ F] [normed_group F'] [normed_space ℝ F'] [normed_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, forall_false_left, 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 {Ξ²} [semi_normed_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*} [semi_normed_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_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_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_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βˆ₯ : begin refine finset.sum_le_sum (Ξ» b hb, _), by_cases hb : βˆ₯bβˆ₯ = 0, { rw hb, simp, }, rw _root_.mul_le_mul_right _, { exact hT_norm _ (simple_func.measurable_set_fiber _ _), }, { exact lt_of_le_of_ne (norm_nonneg _) (ne.symm hb), }, end ... ≀ 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, _), by_cases hb : βˆ₯bβˆ₯ = 0, { rw hb, simp, }, rw _root_.mul_le_mul_right _, { refine hT_norm _ (simple_func.measurable_set_fiber _ _) (simple_func.measure_preimage_lt_top_of_integrable _ hf _), rwa norm_eq_zero at hb, }, { exact lt_of_le_of_ne (norm_nonneg _) (ne.symm hb), }, 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 by_cases hs_empty : s = βˆ…, { simp only [hs_empty, hT_empty, continuous_linear_map.zero_apply, piecewise_empty, const_zero, set_to_simple_func_zero_apply], }, by_cases hs_univ : s = univ, { casesI hΞ± : is_empty_or_nonempty Ξ±, { refine absurd _ hs_empty, haveI : subsingleton (set Ξ±), by { unfold set, apply_instance, }, exact subsingleton.elim s βˆ…, }, simp [hs_univ, set_to_simple_func], }, simp_rw set_to_simple_func, rw [← ne.def, set.ne_empty_iff_nonempty] at hs_empty, 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 Ξ±) = βˆ…, { haveI : unique (set Ξ±) := unique_empty, exact subsingleton.elim (univ : set Ξ±) (βˆ… : set Ξ±), }, 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_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 (π•œ) [nondiscrete_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 [nondiscrete_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 _, } /-- 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_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_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
95fc5f6b30d9b0c8264d30d6edb6da86803a378a
e0f9ba56b7fedc16ef8697f6caeef5898b435143
/src/measure_theory/borel_space.lean
c5f3260060fe2f3ad76fccdad43ef26b4358aa44
[ "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
29,530
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, Yury Kudryashov -/ import measure_theory.measurable_space import topology.instances.ennreal import analysis.normed_space.basic /-! # Borel (measurable) space ## Main definitions * `borel Ξ±` : the least `Οƒ`-algebra that contains all open sets; * `class borel_space` : a space with `topological_space` and `measurable_space` structures such that `β€Ήmeasurable_space Ξ±β€Ί = borel Ξ±`; * `class opens_measurable_space` : a space with `topological_space` and `measurable_space` structures such that all open sets are measurable; equivalently, `borel Ξ± ≀ β€Ήmeasurable_space Ξ±β€Ί`. * `borel_space` instances on `empty`, `unit`, `bool`, `nat`, `int`, `rat`; * `measurable` and `borel_space` instances on `ℝ`, `ℝβ‰₯0`, `ennreal`. ## Main statements * `is_open.is_measurable`, `is_closed.is_measurable`: open and closed sets are measurable; * `continuous.measurable` : a continuous function is measurable; * `continuous.measurable2` : if `f : Ξ± β†’ Ξ²` and `g : Ξ± β†’ Ξ³` are measurable and `op : Ξ² Γ— Ξ³ β†’ Ξ΄` is continuous, then `Ξ» x, op (f x, g y)` is measurable; * `measurable.add` etc : dot notation for arithmetic operations on `measurable` predicates, and similarly for `dist` and `edist`; * `measurable.ennreal*` : special cases for arithmetic operations on `ennreal`s. -/ noncomputable theory open classical set open_locale classical universes u v w x y variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} {Ξ΄ : Type x} {ΞΉ : Sort y} {s t u : set Ξ±} open measurable_space topological_space /-- `measurable_space` structure generated by `topological_space`. -/ def borel (Ξ± : Type u) [topological_space Ξ±] : measurable_space Ξ± := generate_from {s : set Ξ± | is_open s} lemma borel_eq_top_of_discrete [topological_space Ξ±] [discrete_topology Ξ±] : borel Ξ± = ⊀ := top_le_iff.1 $ Ξ» s hs, generate_measurable.basic s (is_open_discrete s) lemma borel_eq_top_of_encodable [topological_space Ξ±] [t1_space Ξ±] [encodable Ξ±] : borel Ξ± = ⊀ := begin refine (top_le_iff.1 $ Ξ» s hs, bUnion_of_singleton s β–Έ _), apply is_measurable.bUnion s.countable_encodable, intros x hx, apply is_measurable.of_compl, apply generate_measurable.basic, exact is_closed_singleton end lemma borel_eq_generate_from_of_subbasis {s : set (set Ξ±)} [t : topological_space Ξ±] [second_countable_topology Ξ±] (hs : t = generate_from s) : borel Ξ± = generate_from s := le_antisymm (generate_from_le $ assume u (hu : t.is_open u), begin rw [hs] at hu, induction hu, case generate_open.basic : u hu { exact generate_measurable.basic u hu }, case generate_open.univ { exact @is_measurable.univ Ξ± (generate_from s) }, case generate_open.inter : s₁ sβ‚‚ _ _ hs₁ hsβ‚‚ { exact @is_measurable.inter Ξ± (generate_from s) _ _ hs₁ hsβ‚‚ }, case generate_open.sUnion : f hf ih { rcases is_open_sUnion_countable f (by rwa hs) with ⟨v, hv, vf, vu⟩, rw ← vu, exact @is_measurable.sUnion Ξ± (generate_from s) _ hv (Ξ» x xv, ih _ (vf xv)) } end) (generate_from_le $ assume u hu, generate_measurable.basic _ $ show t.is_open u, by rw [hs]; exact generate_open.basic _ hu) lemma borel_eq_generate_Iio (Ξ±) [topological_space Ξ±] [second_countable_topology Ξ±] [linear_order Ξ±] [order_topology Ξ±] : borel Ξ± = generate_from (range Iio) := begin refine le_antisymm _ (generate_from_le _), { rw borel_eq_generate_from_of_subbasis (@order_topology.topology_eq_generate_intervals Ξ± _ _ _), have H : βˆ€ a:Ξ±, is_measurable (measurable_space.generate_from (range Iio)) (Iio a) := Ξ» a, generate_measurable.basic _ ⟨_, rfl⟩, refine generate_from_le _, rintro _ ⟨a, rfl | rfl⟩; [skip, apply H], by_cases h : βˆƒ a', βˆ€ b, a < b ↔ a' ≀ b, { rcases h with ⟨a', ha'⟩, rw (_ : Ioi a = -Iio a'), {exact (H _).compl _}, simp [set.ext_iff, ha'] }, { rcases is_open_Union_countable (Ξ» a' : {a' : Ξ± // a < a'}, {b | a'.1 < b}) (Ξ» a', is_open_lt' _) with ⟨v, ⟨hv⟩, vu⟩, simp [set.ext_iff] at vu, have : Ioi a = ⋃ x : v, -Iio x.1.1, { simp [set.ext_iff], refine Ξ» x, ⟨λ ax, _, Ξ» ⟨a', ⟨h, av⟩, ax⟩, lt_of_lt_of_le h ax⟩, rcases (vu x).2 _ with ⟨a', h₁, hβ‚‚βŸ©, { exact ⟨a', h₁, le_of_lt hβ‚‚βŸ© }, refine not_imp_comm.1 (Ξ» h, _) h, exact ⟨x, Ξ» b, ⟨λ ab, le_of_not_lt (Ξ» h', h ⟨b, ab, h'⟩), lt_of_lt_of_le ax⟩⟩ }, rw this, resetI, apply is_measurable.Union, exact Ξ» _, (H _).compl _ } }, { simp, rintro _ a rfl, exact generate_measurable.basic _ is_open_Iio } end lemma borel_eq_generate_Ioi (Ξ±) [topological_space Ξ±] [second_countable_topology Ξ±] [linear_order Ξ±] [order_topology Ξ±] : borel Ξ± = generate_from (range Ioi) := begin refine le_antisymm _ (generate_from_le _), { rw borel_eq_generate_from_of_subbasis (@order_topology.topology_eq_generate_intervals Ξ± _ _ _), have H : βˆ€ a:Ξ±, is_measurable (measurable_space.generate_from (range (Ξ» a, {x | a < x}))) {x | a < x} := Ξ» a, generate_measurable.basic _ ⟨_, rfl⟩, refine generate_from_le _, rintro _ ⟨a, rfl | rfl⟩, {apply H}, by_cases h : βˆƒ a', βˆ€ b, b < a ↔ b ≀ a', { rcases h with ⟨a', ha'⟩, rw (_ : Iio a = -Ioi a'), {exact (H _).compl _}, simp [set.ext_iff, ha'] }, { rcases is_open_Union_countable (Ξ» a' : {a' : Ξ± // a' < a}, {b | b < a'.1}) (Ξ» a', is_open_gt' _) with ⟨v, ⟨hv⟩, vu⟩, simp [set.ext_iff] at vu, have : Iio a = ⋃ x : v, -Ioi x.1.1, { simp [set.ext_iff], refine Ξ» x, ⟨λ ax, _, Ξ» ⟨a', ⟨h, av⟩, ax⟩, lt_of_le_of_lt ax h⟩, rcases (vu x).2 _ with ⟨a', h₁, hβ‚‚βŸ©, { exact ⟨a', h₁, le_of_lt hβ‚‚βŸ© }, refine not_imp_comm.1 (Ξ» h, _) h, exact ⟨x, Ξ» b, ⟨λ ab, le_of_not_lt (Ξ» h', h ⟨b, ab, h'⟩), Ξ» h, lt_of_le_of_lt h ax⟩⟩ }, rw this, resetI, apply is_measurable.Union, exact Ξ» _, (H _).compl _ } }, { simp, rintro _ a rfl, exact generate_measurable.basic _ (is_open_lt' _) } end lemma borel_comap {f : Ξ± β†’ Ξ²} {t : topological_space Ξ²} : @borel Ξ± (t.induced f) = (@borel Ξ² t).comap f := comap_generate_from.symm lemma continuous.borel_measurable [topological_space Ξ±] [topological_space Ξ²] {f : Ξ± β†’ Ξ²} (hf : continuous f) : @measurable Ξ± Ξ² (borel Ξ±) (borel Ξ²) f := generate_from_le $ Ξ» s hs, generate_measurable.basic (f ⁻¹' s) (hf s hs) /-- A space with `measurable_space` and `topological_space` structures such that all open sets are measurable. -/ class opens_measurable_space (Ξ± : Type*) [topological_space Ξ±] [h : measurable_space Ξ±] : Prop := (borel_le : borel Ξ± ≀ h) /-- A space with `measurable_space` and `topological_space` structures such that the `Οƒ`-algebra of measurable sets is exactly the `Οƒ`-algebra generated by open sets. -/ class borel_space (Ξ± : Type*) [topological_space Ξ±] [measurable_space Ξ±] : Prop := (measurable_eq : β€Ήmeasurable_space Ξ±β€Ί = borel Ξ±) /-- In a `borel_space` all open sets are measurable. -/ @[priority 100] instance borel_space.opens_measurable {Ξ± : Type*} [topological_space Ξ±] [measurable_space Ξ±] [borel_space Ξ±] : opens_measurable_space Ξ± := ⟨ge_of_eq $ borel_space.measurable_eq⟩ instance subtype.borel_space {Ξ± : Type*} [topological_space Ξ±] [measurable_space Ξ±] [hΞ± : borel_space Ξ±] (s : set Ξ±) : borel_space s := ⟨by { rw [hΞ±.1, subtype.measurable_space, ← borel_comap], refl }⟩ instance subtype.opens_measurable_space {Ξ± : Type*} [topological_space Ξ±] [measurable_space Ξ±] [h : opens_measurable_space Ξ±] (s : set Ξ±) : opens_measurable_space s := ⟨by { rw [borel_comap], exact comap_mono h.1 }⟩ section variables [topological_space Ξ±] [measurable_space Ξ±] [opens_measurable_space Ξ±] [topological_space Ξ²] [measurable_space Ξ²] [opens_measurable_space Ξ²] [topological_space Ξ³] [measurable_space Ξ³] [borel_space Ξ³] [measurable_space Ξ΄] lemma is_open.is_measurable (h : is_open s) : is_measurable s := opens_measurable_space.borel_le _ $ generate_measurable.basic _ h lemma is_measurable_interior : is_measurable (interior s) := is_open_interior.is_measurable lemma is_closed.is_measurable (h : is_closed s) : is_measurable s := is_measurable.compl_iff.1 $ h.is_measurable lemma is_measurable_singleton [t1_space Ξ±] {x : Ξ±} : is_measurable ({x} : set Ξ±) := is_closed_singleton.is_measurable -- TODO (Lean 3.8): this will become `= is_measurable_singleton` lemma is_measurable_eq [t1_space Ξ±] {a : Ξ±} : is_measurable {x | x = a} := by { convert is_measurable_singleton; try { apply_instance }, ext x, exact mem_singleton_iff.symm } lemma is_measurable_closure : is_measurable (closure s) := is_closed_closure.is_measurable section order_closed_topology variables [preorder Ξ±] [order_closed_topology Ξ±] {a b : Ξ±} lemma is_measurable_Ici : is_measurable (Ici a) := is_closed_Ici.is_measurable lemma is_measurable_Iic : is_measurable (Iic a) := is_closed_Iic.is_measurable lemma is_measurable_Icc : is_measurable (Icc a b) := is_closed_Icc.is_measurable end order_closed_topology section order_closed_topology variables [linear_order Ξ±] [order_closed_topology Ξ±] {a b : Ξ±} lemma is_measurable_Iio : is_measurable (Iio a) := is_open_Iio.is_measurable lemma is_measurable_Ioi : is_measurable (Ioi a) := is_open_Ioi.is_measurable lemma is_measurable_Ioo : is_measurable (Ioo a b) := is_open_Ioo.is_measurable lemma is_measurable_Ioc : is_measurable (Ioc a b) := is_measurable_Ioi.inter is_measurable_Iic lemma is_measurable_Ico : is_measurable (Ico a b) := is_measurable_Ici.inter is_measurable_Iio end order_closed_topology lemma is_measurable_interval [decidable_linear_order Ξ±] [order_closed_topology Ξ±] {a b : Ξ±} : is_measurable (interval a b) := is_measurable_Icc instance prod.opens_measurable_space [second_countable_topology Ξ±] [second_countable_topology Ξ²] : opens_measurable_space (Ξ± Γ— Ξ²) := begin refine ⟨_⟩, rcases is_open_generated_countable_inter Ξ± with ⟨a, ha₁, haβ‚‚, ha₃, haβ‚„, haβ‚…βŸ©, rcases is_open_generated_countable_inter Ξ² with ⟨b, hb₁, hbβ‚‚, hb₃, hbβ‚„, hbβ‚…βŸ©, have : prod.topological_space = generate_from {g | βˆƒu∈a, βˆƒv∈b, g = set.prod u v}, { rw [haβ‚…, hbβ‚…], exact prod_generate_from_generate_from_eq haβ‚„ hbβ‚„ }, rw [borel_eq_generate_from_of_subbasis this], apply generate_from_le, rintros _ ⟨u, hu, v, hv, rfl⟩, have hu : is_open u, by { rw [haβ‚…], exact generate_open.basic _ hu }, have hv : is_open v, by { rw [hbβ‚…], exact generate_open.basic _ hv }, exact hu.is_measurable.prod hv.is_measurable end /-- A continuous function from an `opens_measurable_space` to a `borel_space` is measurable. -/ lemma continuous.measurable {f : Ξ± β†’ Ξ³} (hf : continuous f) : measurable f := hf.borel_measurable.mono opens_measurable_space.borel_le (le_of_eq $ borel_space.measurable_eq) /-- A homeomorphism between two Borel spaces is a measurable equivalence.-/ def homeomorph.to_measurable_equiv {Ξ± : Type*} {Ξ² : Type*} [topological_space Ξ±] [measurable_space Ξ±] [borel_space Ξ±] [topological_space Ξ²] [measurable_space Ξ²] [borel_space Ξ²] (h : Ξ± β‰ƒβ‚œ Ξ²) : measurable_equiv Ξ± Ξ² := { measurable_to_fun := h.continuous_to_fun.measurable, measurable_inv_fun := h.continuous_inv_fun.measurable, .. h } lemma measurable_of_continuous_on_compl_singleton [t1_space Ξ±] {f : Ξ± β†’ Ξ³} (a : Ξ±) (hf : continuous_on f {x | x β‰  a}) : measurable f := measurable_of_measurable_on_compl_singleton a is_measurable_singleton (continuous_on_iff_continuous_restrict.1 hf).measurable lemma continuous.measurable2 [second_countable_topology Ξ±] [second_countable_topology Ξ²] {f : Ξ΄ β†’ Ξ±} {g : Ξ΄ β†’ Ξ²} {c : Ξ± β†’ Ξ² β†’ Ξ³} (h : continuous (Ξ»p:Ξ±Γ—Ξ², c p.1 p.2)) (hf : measurable f) (hg : measurable g) : measurable (Ξ»a, c (f a) (g a)) := h.measurable.comp (hf.prod_mk hg) lemma measurable.smul [semiring Ξ±] [second_countable_topology Ξ±] [add_comm_monoid Ξ³] [second_countable_topology Ξ³] [semimodule Ξ± Ξ³] [topological_semimodule Ξ± Ξ³] {f : Ξ΄ β†’ Ξ±} {g : Ξ΄ β†’ Ξ³} (hf : measurable f) (hg : measurable g) : measurable (Ξ» c, f c β€’ g c) := continuous_smul.measurable2 hf hg lemma measurable.const_smul {Ξ± : Type*} [topological_space Ξ±] [semiring Ξ±] [add_comm_monoid Ξ³] [semimodule Ξ± Ξ³] [topological_semimodule Ξ± Ξ³] {f : Ξ΄ β†’ Ξ³} (hf : measurable f) (c : Ξ±) : measurable (Ξ» x, c β€’ f x) := (continuous_const.smul continuous_id).measurable.comp hf lemma measurable_const_smul_iff {Ξ± : Type*} [topological_space Ξ±] [division_ring Ξ±] [add_comm_monoid Ξ³] [semimodule Ξ± Ξ³] [topological_semimodule Ξ± Ξ³] {f : Ξ΄ β†’ Ξ³} {c : Ξ±} (hc : c β‰  0) : measurable (Ξ» x, c β€’ f x) ↔ measurable f := ⟨λ h, by simpa only [smul_smul, inv_mul_cancel hc, one_smul] using h.const_smul c⁻¹, Ξ» h, h.const_smul c⟩ lemma is_measurable_le' [partial_order Ξ±] [order_closed_topology Ξ±] [second_countable_topology Ξ±] : is_measurable {p : Ξ± Γ— Ξ± | p.1 ≀ p.2} := order_closed_topology.is_closed_le'.is_measurable lemma is_measurable_le [partial_order Ξ±] [order_closed_topology Ξ±] [second_countable_topology Ξ±] {f g : Ξ΄ β†’ Ξ±} (hf : measurable f) (hg : measurable g) : is_measurable {a | f a ≀ g a} := (hf.prod_mk hg).preimage is_measurable_le' lemma measurable.max [decidable_linear_order Ξ±] [order_closed_topology Ξ±] [second_countable_topology Ξ±] {f g : Ξ΄ β†’ Ξ±} (hf : measurable f) (hg : measurable g) : measurable (Ξ»a, max (f a) (g a)) := measurable.if (is_measurable_le hf hg) hg hf lemma measurable.min [decidable_linear_order Ξ±] [order_closed_topology Ξ±] [second_countable_topology Ξ±] {f g : Ξ΄ β†’ Ξ±} (hf : measurable f) (hg : measurable g) : measurable (Ξ»a, min (f a) (g a)) := measurable.if (is_measurable_le hf hg) hf hg end section borel_space variables [topological_space Ξ±] [measurable_space Ξ±] [borel_space Ξ±] [topological_space Ξ²] [measurable_space Ξ²] [borel_space Ξ²] [topological_space Ξ³] [measurable_space Ξ³] [borel_space Ξ³] [measurable_space Ξ΄] lemma prod_le_borel_prod : prod.measurable_space ≀ borel (Ξ± Γ— Ξ²) := begin rw [β€Ήborel_space Ξ±β€Ί.measurable_eq, β€Ήborel_space Ξ²β€Ί.measurable_eq], refine sup_le _ _, { exact comap_le_iff_le_map.mpr continuous_fst.borel_measurable }, { exact comap_le_iff_le_map.mpr continuous_snd.borel_measurable } end instance prod.borel_space [second_countable_topology Ξ±] [second_countable_topology Ξ²] : borel_space (Ξ± Γ— Ξ²) := ⟨le_antisymm prod_le_borel_prod opens_measurable_space.borel_le⟩ @[to_additive] lemma measurable_mul [monoid Ξ±] [topological_monoid Ξ±] [second_countable_topology Ξ±] : measurable (Ξ» p : Ξ± Γ— Ξ±, p.1 * p.2) := continuous_mul.measurable @[to_additive] lemma measurable.mul [monoid Ξ±] [topological_monoid Ξ±] [second_countable_topology Ξ±] {f : Ξ΄ β†’ Ξ±} {g : Ξ΄ β†’ Ξ±} : measurable f β†’ measurable g β†’ measurable (Ξ»a, f a * g a) := continuous_mul.measurable2 @[to_additive] lemma finset.measurable_prod {ΞΉ : Type*} [comm_monoid Ξ±] [topological_monoid Ξ±] [second_countable_topology Ξ±] {f : ΞΉ β†’ Ξ΄ β†’ Ξ±} (s : finset ΞΉ) (hf : βˆ€i, measurable (f i)) : measurable (Ξ»a, s.prod (Ξ»i, f i a)) := finset.induction_on s (by simp only [finset.prod_empty, measurable_const]) (assume i s his ih, by simpa [his] using (hf i).mul ih) @[to_additive] lemma measurable_inv [group Ξ±] [topological_group Ξ±] : measurable (has_inv.inv : Ξ± β†’ Ξ±) := continuous_inv.measurable @[to_additive] lemma measurable.inv [group Ξ±] [topological_group Ξ±] {f : Ξ΄ β†’ Ξ±} (hf : measurable f) : measurable (Ξ»a, (f a)⁻¹) := measurable_inv.comp hf lemma measurable_inv' {Ξ± : Type*} [normed_field Ξ±] [measurable_space Ξ±] [borel_space Ξ±] : measurable (has_inv.inv : Ξ± β†’ Ξ±) := measurable_of_continuous_on_compl_singleton 0 normed_field.continuous_on_inv lemma measurable.inv' {Ξ± : Type*} [normed_field Ξ±] [measurable_space Ξ±] [borel_space Ξ±] {f : Ξ΄ β†’ Ξ±} (hf : measurable f) : measurable (Ξ»a, (f a)⁻¹) := measurable_inv'.comp hf @[to_additive] lemma measurable.of_inv [group Ξ±] [topological_group Ξ±] {f : Ξ΄ β†’ Ξ±} (hf : measurable (Ξ» a, (f a)⁻¹)) : measurable f := by simpa only [inv_inv] using hf.inv @[to_additive] lemma measurable_inv_iff [group Ξ±] [topological_group Ξ±] {f : Ξ΄ β†’ Ξ±} : measurable (Ξ» a, (f a)⁻¹) ↔ measurable f := ⟨measurable.of_inv, measurable.inv⟩ lemma measurable.sub [add_group Ξ±] [topological_add_group Ξ±] [second_countable_topology Ξ±] {f g : Ξ΄ β†’ Ξ±} (hf : measurable f) (hg : measurable g) : measurable (Ξ» x, f x - g x) := hf.add hg.neg lemma measurable.is_lub [linear_order Ξ±] [order_topology Ξ±] [second_countable_topology Ξ±] {ΞΉ} [encodable ΞΉ] {f : ΞΉ β†’ Ξ΄ β†’ Ξ±} {g : Ξ΄ β†’ Ξ±} (hf : βˆ€ i, measurable (f i)) (hg : βˆ€ b, is_lub {a | βˆƒ i, f i b = a} (g b)) : measurable g := begin change βˆ€ b, is_lub (range $ Ξ» i, f i b) (g b) at hg, rw [β€Ήborel_space Ξ±β€Ί.measurable_eq, borel_eq_generate_Ioi Ξ±], apply measurable_generate_from, rintro _ ⟨a, rfl⟩, simp only [set.preimage, mem_Ioi, lt_is_lub_iff (hg _), exists_range_iff, set_of_exists], exact is_measurable.Union (Ξ» i, hf i _ (is_open_lt' _).is_measurable) end lemma measurable.is_glb [linear_order Ξ±] [order_topology Ξ±] [second_countable_topology Ξ±] {ΞΉ} [encodable ΞΉ] {f : ΞΉ β†’ Ξ΄ β†’ Ξ±} {g : Ξ΄ β†’ Ξ±} (hf : βˆ€ i, measurable (f i)) (hg : βˆ€ b, is_glb {a | βˆƒ i, f i b = a} (g b)) : measurable g := begin change βˆ€ b, is_glb (range $ Ξ» i, f i b) (g b) at hg, rw [β€Ήborel_space Ξ±β€Ί.measurable_eq, borel_eq_generate_Iio Ξ±], apply measurable_generate_from, rintro _ ⟨a, rfl⟩, simp only [set.preimage, mem_Iio, is_glb_lt_iff (hg _), exists_range_iff, set_of_exists], exact is_measurable.Union (Ξ» i, hf i _ (is_open_gt' _).is_measurable) end lemma measurable_supr [complete_linear_order Ξ±] [order_topology Ξ±] [second_countable_topology Ξ±] {ΞΉ} [encodable ΞΉ] {f : ΞΉ β†’ Ξ΄ β†’ Ξ±} (hf : βˆ€ i, measurable (f i)) : measurable (Ξ» b, ⨆ i, f i b) := measurable.is_lub hf $ Ξ» b, is_lub_supr lemma measurable_infi [complete_linear_order Ξ±] [order_topology Ξ±] [second_countable_topology Ξ±] {ΞΉ} [encodable ΞΉ] {f : ΞΉ β†’ Ξ΄ β†’ Ξ±} (hf : βˆ€ i, measurable (f i)) : measurable (Ξ» b, β¨… i, f i b) := measurable.is_glb hf $ Ξ» b, is_glb_infi lemma measurable.supr_Prop {Ξ±} [measurable_space Ξ±] [complete_lattice Ξ±] (p : Prop) {f : Ξ΄ β†’ Ξ±} (hf : measurable f) : measurable (Ξ» b, ⨆ h : p, f b) := classical.by_cases (assume h : p, begin convert hf, funext, exact supr_pos h end) (assume h : Β¬p, begin convert measurable_const, funext, exact supr_neg h end) lemma measurable.infi_Prop {Ξ±} [measurable_space Ξ±] [complete_lattice Ξ±] (p : Prop) {f : Ξ΄ β†’ Ξ±} (hf : measurable f) : measurable (Ξ» b, β¨… h : p, f b) := classical.by_cases (assume h : p, begin convert hf, funext, exact infi_pos h end ) (assume h : Β¬p, begin convert measurable_const, funext, exact infi_neg h end) lemma measurable_bsupr [complete_linear_order Ξ±] [order_topology Ξ±] [second_countable_topology Ξ±] {ΞΉ} [encodable ΞΉ] (p : ΞΉ β†’ Prop) {f : ΞΉ β†’ Ξ΄ β†’ Ξ±} (hf : βˆ€ i, measurable (f i)) : measurable (Ξ» b, ⨆ i (hi : p i), f i b) := measurable_supr $ Ξ» i, (hf i).supr_Prop (p i) lemma measurable_binfi [complete_linear_order Ξ±] [order_topology Ξ±] [second_countable_topology Ξ±] {ΞΉ} [encodable ΞΉ] (p : ΞΉ β†’ Prop) {f : ΞΉ β†’ Ξ΄ β†’ Ξ±} (hf : βˆ€ i, measurable (f i)) : measurable (Ξ» b, β¨… i (hi : p i), f i b) := measurable_infi $ Ξ» i, (hf i).infi_Prop (p i) /-- Convert a `homeomorph` to a `measurable_equiv`. -/ def homemorph.to_measurable_equiv (h : Ξ± β‰ƒβ‚œ Ξ²) : measurable_equiv Ξ± Ξ² := { to_equiv := h.to_equiv, measurable_to_fun := h.continuous_to_fun.measurable, measurable_inv_fun := h.continuous_inv_fun.measurable } end borel_space instance empty.borel_space : borel_space empty := ⟨borel_eq_top_of_discrete.symm⟩ instance unit.borel_space : borel_space unit := ⟨borel_eq_top_of_discrete.symm⟩ instance bool.borel_space : borel_space bool := ⟨borel_eq_top_of_discrete.symm⟩ instance nat.borel_space : borel_space β„• := ⟨borel_eq_top_of_discrete.symm⟩ instance int.borel_space : borel_space β„€ := ⟨borel_eq_top_of_discrete.symm⟩ instance rat.borel_space : borel_space β„š := ⟨borel_eq_top_of_encodable.symm⟩ instance real.measurable_space : measurable_space ℝ := borel ℝ instance real.borel_space : borel_space ℝ := ⟨rfl⟩ instance nnreal.measurable_space : measurable_space nnreal := borel nnreal instance nnreal.borel_space : borel_space nnreal := ⟨rfl⟩ instance ennreal.measurable_space : measurable_space ennreal := borel ennreal instance ennreal.borel_space : borel_space ennreal := ⟨rfl⟩ section metric_space variables [metric_space Ξ±] [measurable_space Ξ±] [opens_measurable_space Ξ±] {x : Ξ±} {Ξ΅ : ℝ} lemma is_measurable_ball : is_measurable (metric.ball x Ξ΅) := metric.is_open_ball.is_measurable lemma is_measurable_closed_ball : is_measurable (metric.closed_ball x Ξ΅) := metric.is_closed_ball.is_measurable lemma measurable_dist [second_countable_topology Ξ±] : measurable (Ξ»p:Ξ±Γ—Ξ±, dist p.1 p.2) := continuous_dist.measurable lemma measurable.dist [second_countable_topology Ξ±] [measurable_space Ξ²] {f g : Ξ² β†’ Ξ±} (hf : measurable f) (hg : measurable g) : measurable (Ξ» b, dist (f b) (g b)) := continuous_dist.measurable2 hf hg lemma measurable_nndist [second_countable_topology Ξ±] : measurable (Ξ»p:Ξ±Γ—Ξ±, nndist p.1 p.2) := continuous_nndist.measurable lemma measurable.nndist [second_countable_topology Ξ±] [measurable_space Ξ²] {f g : Ξ² β†’ Ξ±} : measurable f β†’ measurable g β†’ measurable (Ξ» b, nndist (f b) (g b)) := continuous_nndist.measurable2 end metric_space section emetric_space variables [emetric_space Ξ±] [measurable_space Ξ±] [opens_measurable_space Ξ±] {x : Ξ±} {Ξ΅ : ennreal} lemma is_measurable_eball : is_measurable (emetric.ball x Ξ΅) := emetric.is_open_ball.is_measurable lemma measurable_edist [second_countable_topology Ξ±] : measurable (Ξ»p:Ξ±Γ—Ξ±, edist p.1 p.2) := continuous_edist.measurable lemma measurable.edist [second_countable_topology Ξ±] [measurable_space Ξ²] {f g : Ξ² β†’ Ξ±} : measurable f β†’ measurable g β†’ measurable (Ξ» b, edist (f b) (g b)) := continuous_edist.measurable2 end emetric_space namespace real open measurable_space lemma borel_eq_generate_from_Ioo_rat : borel ℝ = generate_from (⋃(a b : β„š) (h : a < b), {Ioo a b}) := borel_eq_generate_from_of_subbasis is_topological_basis_Ioo_rat.2.2 lemma borel_eq_generate_from_Iio_rat : borel ℝ = generate_from (⋃a:β„š, {Iio a}) := begin let g, swap, apply le_antisymm (_ : _ ≀ g) (measurable_space.generate_from_le (Ξ» t, _)), { rw borel_eq_generate_from_Ioo_rat, refine generate_from_le (Ξ» t, _), simp only [mem_Union], rintro ⟨a, b, h, rfl|⟨⟨⟩⟩⟩, rw (set.ext (Ξ» x, _) : Ioo (a:ℝ) b = (⋃c>a, - Iio c) ∩ Iio b), { have hg : βˆ€q:β„š, g.is_measurable (Iio q) := Ξ» q, generate_measurable.basic _ (by simp; exact ⟨_, rfl⟩), refine @is_measurable.inter _ g _ _ _ (hg _), refine @is_measurable.bUnion _ _ g _ _ (countable_encodable _) (Ξ» c h, _), exact @is_measurable.compl _ _ g (hg _) }, { simp [Ioo, Iio], refine and_congr _ iff.rfl, exact ⟨λ h, let ⟨c, ac, cx⟩ := exists_rat_btwn h in ⟨c, rat.cast_lt.1 ac, le_of_lt cx⟩, Ξ» ⟨c, ac, cx⟩, lt_of_lt_of_le (rat.cast_lt.2 ac) cx⟩ } }, { simp, rintro r rfl, exact is_open_Iio.is_measurable } end end real lemma measurable.sub_nnreal [measurable_space Ξ±] {f g : Ξ± β†’ nnreal} : measurable f β†’ measurable g β†’ measurable (Ξ» a, f a - g a) := nnreal.continuous_sub.measurable2 lemma measurable.nnreal_of_real [measurable_space Ξ±] {f : Ξ± β†’ ℝ} (hf : measurable f) : measurable (Ξ» x, nnreal.of_real (f x)) := nnreal.continuous_of_real.measurable.comp hf lemma measurable.nnreal_coe [measurable_space Ξ±] {f : Ξ± β†’ nnreal} (hf : measurable f) : measurable (Ξ» x, (f x : ℝ)) := nnreal.continuous_coe.measurable.comp hf lemma measurable.ennreal_coe [measurable_space Ξ±] {f : Ξ± β†’ nnreal} (hf : measurable f) : measurable (Ξ» x, (f x : ennreal)) := (ennreal.continuous_coe.2 continuous_id).measurable.comp hf lemma measurable.ennreal_of_real [measurable_space Ξ±] {f : Ξ± β†’ ℝ} (hf : measurable f) : measurable (Ξ» x, ennreal.of_real (f x)) := ennreal.continuous_of_real.measurable.comp hf /-- The set of finite `ennreal` numbers is `measurable_equiv` to `nnreal`. -/ def measurable_equiv.ennreal_equiv_nnreal : measurable_equiv {r : ennreal | r β‰  ⊀} nnreal := ennreal.ne_top_homeomorph_nnreal.to_measurable_equiv namespace ennreal open filter lemma measurable_coe : measurable (coe : nnreal β†’ ennreal) := measurable_id.ennreal_coe lemma measurable_of_measurable_nnreal [measurable_space Ξ±] {f : ennreal β†’ Ξ±} (h : measurable (Ξ»p:nnreal, f p)) : measurable f := measurable_of_measurable_on_compl_singleton ⊀ is_measurable_singleton (measurable_equiv.ennreal_equiv_nnreal.symm.measurable_coe_iff.1 h) /-- `ennreal` is `measurable_equiv` to `nnreal βŠ• unit`. -/ def ennreal_equiv_sum : measurable_equiv ennreal (nnreal βŠ• unit) := { measurable_to_fun := measurable_of_measurable_nnreal measurable_inl, measurable_inv_fun := measurable_sum measurable_coe (@measurable_const ennreal unit _ _ ⊀), .. equiv.option_equiv_sum_punit nnreal } lemma measurable_of_measurable_nnreal_nnreal [measurable_space Ξ±] [measurable_space Ξ²] (f : ennreal β†’ ennreal β†’ Ξ²) {g : Ξ± β†’ ennreal} {h : Ξ± β†’ ennreal} (h₁ : measurable (Ξ»p:nnreal Γ— nnreal, f p.1 p.2)) (hβ‚‚ : measurable (Ξ»r:nnreal, f ⊀ r)) (h₃ : measurable (Ξ»r:nnreal, f r ⊀)) (hg : measurable g) (hh : measurable h) : measurable (Ξ»a, f (g a) (h a)) := let e : measurable_equiv (ennreal Γ— ennreal) (((nnreal Γ— nnreal) βŠ• (nnreal Γ— unit)) βŠ• ((unit Γ— nnreal) βŠ• (unit Γ— unit))) := (measurable_equiv.prod_congr ennreal_equiv_sum ennreal_equiv_sum).trans (measurable_equiv.sum_prod_sum _ _ _ _) in have measurable (Ξ»p:ennrealΓ—ennreal, f p.1 p.2), begin refine e.symm.measurable_coe_iff.1 (measurable_sum (measurable_sum _ _) (measurable_sum _ _)), { show measurable (Ξ»p:nnreal Γ— nnreal, f p.1 p.2), exact h₁ }, { show measurable (Ξ»p:nnreal Γ— unit, f p.1 ⊀), exact h₃.comp (measurable.fst measurable_id) }, { show measurable ((Ξ»p:nnreal, f ⊀ p) ∘ (Ξ»p:unit Γ— nnreal, p.2)), exact hβ‚‚.comp (measurable.snd measurable_id) }, { show measurable (Ξ»p:unit Γ— unit, f ⊀ ⊀), exact measurable_const } end, this.comp (measurable.prod_mk hg hh) lemma measurable_of_real : measurable ennreal.of_real := ennreal.continuous_of_real.measurable end ennreal lemma measurable.ennreal_mul {Ξ± : Type*} [measurable_space Ξ±] {f g : Ξ± β†’ ennreal} : measurable f β†’ measurable g β†’ measurable (Ξ»a, f a * g a) := begin refine ennreal.measurable_of_measurable_nnreal_nnreal (*) _ _ _, { simp only [ennreal.coe_mul.symm], exact ennreal.measurable_coe.comp measurable_mul }, { simp [ennreal.top_mul], exact measurable.if (is_closed_eq continuous_id continuous_const).is_measurable measurable_const measurable_const }, { simp [ennreal.mul_top], exact measurable.if (is_closed_eq continuous_id continuous_const).is_measurable measurable_const measurable_const } end lemma measurable.ennreal_add {Ξ± : Type*} [measurable_space Ξ±] {f g : Ξ± β†’ ennreal} : measurable f β†’ measurable g β†’ measurable (Ξ»a, f a + g a) := begin refine ennreal.measurable_of_measurable_nnreal_nnreal (+) _ _ _, { simp only [ennreal.coe_add.symm], exact ennreal.measurable_coe.comp measurable_add }, { simp [measurable_const] }, { simp [measurable_const] } end lemma measurable.ennreal_sub {Ξ± : Type*} [measurable_space Ξ±] {f g : Ξ± β†’ ennreal} : measurable f β†’ measurable g β†’ measurable (Ξ»a, f a - g a) := begin refine ennreal.measurable_of_measurable_nnreal_nnreal (has_sub.sub) _ _ _, { simp only [ennreal.coe_sub.symm], exact ennreal.measurable_coe.comp nnreal.continuous_sub.measurable }, { simp [measurable_const] }, { simp [measurable_const] } end section normed_group variables [measurable_space Ξ±] [normed_group Ξ±] [opens_measurable_space Ξ±] [measurable_space Ξ²] lemma measurable_norm : measurable (norm : Ξ± β†’ ℝ) := continuous_norm.measurable lemma measurable.norm {f : Ξ² β†’ Ξ±} (hf : measurable f) : measurable (Ξ»a, norm (f a)) := measurable_norm.comp hf lemma measurable_nnnorm : measurable (nnnorm : Ξ± β†’ nnreal) := continuous_nnnorm.measurable lemma measurable.nnnorm {f : Ξ² β†’ Ξ±} (hf : measurable f) : measurable (Ξ»a, nnnorm (f a)) := measurable_nnnorm.comp hf lemma measurable.ennnorm {f : Ξ² β†’ Ξ±} (hf : measurable f) : measurable (Ξ»a, (nnnorm (f a) : ennreal)) := hf.nnnorm.ennreal_coe end normed_group
b7f0ba2b3a74347bee96edb807b52875f585b042
8cb37a089cdb4af3af9d8bf1002b417e407a8e9e
/library/init/data/int/order.lean
6595c0639ee00ee6d81036d35872dbf3ca76bbc9
[ "Apache-2.0" ]
permissive
kbuzzard/lean
ae3c3db4bb462d750dbf7419b28bafb3ec983ef7
ed1788fd674bb8991acffc8fca585ec746711928
refs/heads/master
1,620,983,366,617
1,618,937,600,000
1,618,937,600,000
359,886,396
1
0
Apache-2.0
1,618,936,987,000
1,618,936,987,000
null
UTF-8
Lean
false
false
36,984
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad The order relation on the integers. -/ prelude import init.data.int.basic init.data.ordering.basic namespace int def nonneg (a : β„€) : Prop := int.cases_on a (assume n, true) (assume n, false) protected def le (a b : β„€) : Prop := nonneg (b - a) instance : has_le int := ⟨int.le⟩ protected def lt (a b : β„€) : Prop := (a + 1) ≀ b instance : has_lt int := ⟨int.lt⟩ def decidable_nonneg (a : β„€) : decidable (nonneg a) := int.cases_on a (assume a, decidable.true) (assume a, decidable.false) instance decidable_le (a b : β„€) : decidable (a ≀ b) := decidable_nonneg _ instance decidable_lt (a b : β„€) : decidable (a < b) := decidable_nonneg _ lemma lt_iff_add_one_le (a b : β„€) : a < b ↔ a + 1 ≀ b := iff.refl _ lemma nonneg.elim {a : β„€} : nonneg a β†’ βˆƒ n : β„•, a = n := int.cases_on a (assume n H, exists.intro n rfl) (assume n', false.elim) lemma nonneg_or_nonneg_neg (a : β„€) : nonneg a ∨ nonneg (-a) := int.cases_on a (assume n, or.inl trivial) (assume n, or.inr trivial) lemma le.intro_sub {a b : β„€} {n : β„•} (h : b - a = n) : a ≀ b := show nonneg (b - a), by rw h; trivial local attribute [simp] int.sub_eq_add_neg int.add_assoc int.add_right_neg int.add_left_neg int.zero_add int.add_zero int.neg_add int.neg_neg int.neg_zero lemma le.intro {a b : β„€} {n : β„•} (h : a + n = b) : a ≀ b := le.intro_sub (by rw [← h, int.add_comm]; simp) lemma le.dest_sub {a b : β„€} (h : a ≀ b) : βˆƒ n : β„•, b - a = n := nonneg.elim h lemma le.dest {a b : β„€} (h : a ≀ b) : βˆƒ n : β„•, a + n = b := match (le.dest_sub h) with | ⟨n, hβ‚βŸ© := exists.intro n begin rw [← h₁, int.add_comm], simp end end lemma le.elim {a b : β„€} (h : a ≀ b) {P : Prop} (h' : βˆ€ n : β„•, a + ↑n = b β†’ P) : P := exists.elim (le.dest h) h' protected lemma le_total (a b : β„€) : a ≀ b ∨ b ≀ a := or.imp_right (assume H : nonneg (-(b - a)), have -(b - a) = a - b, by simp [int.add_comm], show nonneg (a - b), from this β–Έ H) (nonneg_or_nonneg_neg (b - a)) lemma coe_nat_le_coe_nat_of_le {m n : β„•} (h : m ≀ n) : (↑m : β„€) ≀ ↑n := match nat.le.dest h with | ⟨k, (hk : m + k = n)⟩ := le.intro (begin rw [← hk], reflexivity end) end lemma le_of_coe_nat_le_coe_nat {m n : β„•} (h : (↑m : β„€) ≀ ↑n) : m ≀ n := le.elim h (assume k, assume hk : ↑m + ↑k = ↑n, have m + k = n, from int.coe_nat_inj ((int.coe_nat_add m k).trans hk), nat.le.intro this) lemma coe_nat_le_coe_nat_iff (m n : β„•) : (↑m : β„€) ≀ ↑n ↔ m ≀ n := iff.intro le_of_coe_nat_le_coe_nat coe_nat_le_coe_nat_of_le lemma coe_zero_le (n : β„•) : 0 ≀ (↑n : β„€) := coe_nat_le_coe_nat_of_le n.zero_le lemma eq_coe_of_zero_le {a : β„€} (h : 0 ≀ a) : βˆƒ n : β„•, a = n := by { have t := le.dest_sub h, simp at t, exact t } lemma eq_succ_of_zero_lt {a : β„€} (h : 0 < a) : βˆƒ n : β„•, a = n.succ := let ⟨n, (h : ↑(1+n) = a)⟩ := le.dest h in ⟨n, by rw nat.add_comm at h; exact h.symm⟩ lemma lt_add_succ (a : β„€) (n : β„•) : a < a + ↑(nat.succ n) := le.intro (show a + 1 + n = a + nat.succ n, by { simp [int.coe_nat_eq, int.add_comm, int.add_left_comm], reflexivity }) lemma lt.intro {a b : β„€} {n : β„•} (h : a + nat.succ n = b) : a < b := h β–Έ lt_add_succ a n lemma lt.dest {a b : β„€} (h : a < b) : βˆƒ n : β„•, a + ↑(nat.succ n) = b := le.elim h (assume n, assume hn : a + 1 + n = b, exists.intro n begin rw [← hn, int.add_assoc, int.add_comm 1], reflexivity end) lemma lt.elim {a b : β„€} (h : a < b) {P : Prop} (h' : βˆ€ n : β„•, a + ↑(nat.succ n) = b β†’ P) : P := exists.elim (lt.dest h) h' lemma coe_nat_lt_coe_nat_iff (n m : β„•) : (↑n : β„€) < ↑m ↔ n < m := begin rw [lt_iff_add_one_le, ← int.coe_nat_succ, coe_nat_le_coe_nat_iff], reflexivity end lemma lt_of_coe_nat_lt_coe_nat {m n : β„•} (h : (↑m : β„€) < ↑n) : m < n := (coe_nat_lt_coe_nat_iff _ _).mp h lemma coe_nat_lt_coe_nat_of_lt {m n : β„•} (h : m < n) : (↑m : β„€) < ↑n := (coe_nat_lt_coe_nat_iff _ _).mpr h /- show that the integers form an ordered additive group -/ protected lemma le_refl (a : β„€) : a ≀ a := le.intro (int.add_zero a) protected lemma le_trans {a b c : β„€} (h₁ : a ≀ b) (hβ‚‚ : b ≀ c) : a ≀ c := le.elim h₁ (assume n, assume hn : a + n = b, le.elim hβ‚‚ (assume m, assume hm : b + m = c, begin apply le.intro, rw [← hm, ← hn, int.add_assoc], reflexivity end)) protected lemma le_antisymm {a b : β„€} (h₁ : a ≀ b) (hβ‚‚ : b ≀ a) : a = b := le.elim h₁ (assume n, assume hn : a + n = b, le.elim hβ‚‚ (assume m, assume hm : b + m = a, have a + ↑(n + m) = a + 0, by rw [int.coe_nat_add, ← int.add_assoc, hn, hm, int.add_zero a], have (↑(n + m) : β„€) = 0, from int.add_left_cancel this, have n + m = 0, from int.coe_nat_inj this, have n = 0, from nat.eq_zero_of_add_eq_zero_right this, show a = b, begin rw [← hn, this, int.coe_nat_zero, int.add_zero a] end)) protected lemma lt_irrefl (a : β„€) : Β¬ a < a := assume : a < a, lt.elim this (assume n, assume hn : a + nat.succ n = a, have a + nat.succ n = a + 0, by rw [hn, int.add_zero], have nat.succ n = 0, from int.coe_nat_inj (int.add_left_cancel this), show false, from nat.succ_ne_zero _ this) protected lemma ne_of_lt {a b : β„€} (h : a < b) : a β‰  b := (assume : a = b, absurd (begin rewrite this at h, exact h end) (int.lt_irrefl b)) lemma le_of_lt {a b : β„€} (h : a < b) : a ≀ b := lt.elim h (assume n, assume hn : a + nat.succ n = b, le.intro hn) protected lemma lt_iff_le_and_ne (a b : β„€) : a < b ↔ (a ≀ b ∧ a β‰  b) := iff.intro (assume h, ⟨le_of_lt h, int.ne_of_lt h⟩) (assume ⟨aleb, aneb⟩, le.elim aleb (assume n, assume hn : a + n = b, have n β‰  0, from (assume : n = 0, aneb begin rw [← hn, this, int.coe_nat_zero, int.add_zero] end), have n = nat.succ (nat.pred n), from eq.symm (nat.succ_pred_eq_of_pos (nat.pos_of_ne_zero this)), lt.intro (begin rewrite this at hn, exact hn end))) lemma lt_succ (a : β„€) : a < a + 1 := int.le_refl (a + 1) protected lemma add_le_add_left {a b : β„€} (h : a ≀ b) (c : β„€) : c + a ≀ c + b := le.elim h (assume n, assume hn : a + n = b, le.intro (show c + a + n = c + b, begin rw [int.add_assoc, hn] end)) protected lemma add_lt_add_left {a b : β„€} (h : a < b) (c : β„€) : c + a < c + b := iff.mpr (int.lt_iff_le_and_ne _ _) (and.intro (int.add_le_add_left (le_of_lt h) _) (assume heq, int.lt_irrefl b begin rw int.add_left_cancel heq at h, exact h end)) protected lemma mul_nonneg {a b : β„€} (ha : 0 ≀ a) (hb : 0 ≀ b) : 0 ≀ a * b := le.elim ha (assume n, assume hn, le.elim hb (assume m, assume hm, le.intro (show 0 + ↑n * ↑m = a * b, begin rw [← hn, ← hm], simp [int.zero_add] end))) protected lemma mul_pos {a b : β„€} (ha : 0 < a) (hb : 0 < b) : 0 < a * b := lt.elim ha (assume n, assume hn, lt.elim hb (assume m, assume hm, lt.intro (show 0 + ↑(nat.succ (nat.succ n * m + n)) = a * b, begin rw [← hn, ← hm], simp [int.coe_nat_zero], rw [← int.coe_nat_mul], simp [nat.mul_succ, nat.succ_add] end))) protected lemma zero_lt_one : (0 : β„€) < 1 := trivial protected lemma lt_iff_le_not_le {a b : β„€} : a < b ↔ (a ≀ b ∧ Β¬ b ≀ a) := begin simp [int.lt_iff_le_and_ne], split; intro h, { cases h with hab hn, split, { assumption }, { intro hba, simp [int.le_antisymm hab hba] at *, contradiction } }, { cases h with hab hn, split, { assumption }, { intro h, simp [*] at * } } end instance : linear_order int := { le := int.le, le_refl := int.le_refl, le_trans := @int.le_trans, le_antisymm := @int.le_antisymm, lt := int.lt, lt_iff_le_not_le := @int.lt_iff_le_not_le, le_total := int.le_total, decidable_eq := int.decidable_eq, decidable_le := int.decidable_le, decidable_lt := int.decidable_lt } lemma eq_nat_abs_of_zero_le {a : β„€} (h : 0 ≀ a) : a = nat_abs a := let ⟨n, e⟩ := eq_coe_of_zero_le h in by rw e; refl lemma le_nat_abs {a : β„€} : a ≀ nat_abs a := or.elim (le_total 0 a) (Ξ»h, by rw eq_nat_abs_of_zero_le h; refl) (Ξ»h, le_trans h (coe_zero_le _)) lemma neg_succ_lt_zero (n : β„•) : -[1+ n] < 0 := lt_of_not_ge $ Ξ» h, let ⟨m, h⟩ := eq_coe_of_zero_le h in by contradiction lemma eq_neg_succ_of_lt_zero : βˆ€ {a : β„€}, a < 0 β†’ βˆƒ n : β„•, a = -[1+ n] | (n : β„•) h := absurd h (not_lt_of_ge (coe_zero_le _)) | -[1+ n] h := ⟨n, rfl⟩ /- int is an ordered add comm group -/ protected lemma eq_neg_of_eq_neg {a b : β„€} (h : a = -b) : b = -a := by rw [h, int.neg_neg] protected lemma neg_add_cancel_left (a b : β„€) : -a + (a + b) = b := by rw [← int.add_assoc, int.add_left_neg, int.zero_add] protected lemma add_neg_cancel_left (a b : β„€) : a + (-a + b) = b := by rw [← int.add_assoc, int.add_right_neg, int.zero_add] protected lemma add_neg_cancel_right (a b : β„€) : a + b + -b = a := by rw [int.add_assoc, int.add_right_neg, int.add_zero] protected lemma neg_add_cancel_right (a b : β„€) : a + -b + b = a := by rw [int.add_assoc, int.add_left_neg, int.add_zero] protected lemma sub_self (a : β„€) : a - a = 0 := by rw [int.sub_eq_add_neg, int.add_right_neg] protected lemma sub_eq_zero_of_eq {a b : β„€} (h : a = b) : a - b = 0 := by rw [h, int.sub_self] protected lemma eq_of_sub_eq_zero {a b : β„€} (h : a - b = 0) : a = b := have 0 + b = b, by rw int.zero_add, have (a - b) + b = b, by rwa h, by rwa [int.sub_eq_add_neg, int.neg_add_cancel_right] at this protected lemma sub_eq_zero_iff_eq {a b : β„€} : a - b = 0 ↔ a = b := ⟨int.eq_of_sub_eq_zero, int.sub_eq_zero_of_eq⟩ @[simp] protected lemma neg_eq_of_add_eq_zero {a b : β„€} (h : a + b = 0) : -a = b := by rw [← int.add_zero (-a), ←h, ←int.add_assoc, int.add_left_neg, int.zero_add] protected lemma neg_mul_eq_neg_mul (a b : β„€) : -(a * b) = -a * b := int.neg_eq_of_add_eq_zero begin rw [← int.distrib_right, int.add_right_neg, int.zero_mul] end protected lemma neg_mul_eq_mul_neg (a b : β„€) : -(a * b) = a * -b := int.neg_eq_of_add_eq_zero begin rw [← int.distrib_left, int.add_right_neg, int.mul_zero] end lemma neg_mul_eq_neg_mul_symm (a b : β„€) : - a * b = - (a * b) := eq.symm (int.neg_mul_eq_neg_mul a b) lemma mul_neg_eq_neg_mul_symm (a b : β„€) : a * - b = - (a * b) := eq.symm (int.neg_mul_eq_mul_neg a b) local attribute [simp] neg_mul_eq_neg_mul_symm mul_neg_eq_neg_mul_symm protected lemma neg_mul_neg (a b : β„€) : -a * -b = a * b := by simp protected lemma neg_mul_comm (a b : β„€) : -a * b = a * -b := by simp protected lemma mul_sub (a b c : β„€) : a * (b - c) = a * b - a * c := calc a * (b - c) = a * b + a * -c : int.distrib_left a b (-c) ... = a * b - a * c : by simp protected lemma sub_mul (a b c : β„€) : (a - b) * c = a * c - b * c := calc (a - b) * c = a * c + -b * c : int.distrib_right a (-b) c ... = a * c - b * c : by simp section protected lemma le_of_add_le_add_left {a b c : β„€} (h : a + b ≀ a + c) : b ≀ c := have -a + (a + b) ≀ -a + (a + c), from int.add_le_add_left h _, begin simp [int.neg_add_cancel_left] at this, assumption end protected lemma lt_of_add_lt_add_left {a b c : β„€} (h : a + b < a + c) : b < c := have -a + (a + b) < -a + (a + c), from int.add_lt_add_left h _, begin simp [int.neg_add_cancel_left] at this, assumption end protected lemma add_le_add_right {a b : β„€} (h : a ≀ b) (c : β„€) : a + c ≀ b + c := int.add_comm c a β–Έ int.add_comm c b β–Έ int.add_le_add_left h c protected theorem add_lt_add_right {a b : β„€} (h : a < b) (c : β„€) : a + c < b + c := begin rw [int.add_comm a c, int.add_comm b c], exact (int.add_lt_add_left h c) end protected lemma add_le_add {a b c d : β„€} (h₁ : a ≀ b) (hβ‚‚ : c ≀ d) : a + c ≀ b + d := le_trans (int.add_le_add_right h₁ c) (int.add_le_add_left hβ‚‚ b) protected lemma le_add_of_nonneg_right {a b : β„€} (h : 0 ≀ b) : a ≀ a + b := have a + b β‰₯ a + 0, from int.add_le_add_left h a, by rwa int.add_zero at this protected lemma le_add_of_nonneg_left {a b : β„€} (h : 0 ≀ b) : a ≀ b + a := have 0 + a ≀ b + a, from int.add_le_add_right h a, by rwa int.zero_add at this protected lemma add_lt_add {a b c d : β„€} (h₁ : a < b) (hβ‚‚ : c < d) : a + c < b + d := lt_trans (int.add_lt_add_right h₁ c) (int.add_lt_add_left hβ‚‚ b) protected lemma add_lt_add_of_le_of_lt {a b c d : β„€} (h₁ : a ≀ b) (hβ‚‚ : c < d) : a + c < b + d := lt_of_le_of_lt (int.add_le_add_right h₁ c) (int.add_lt_add_left hβ‚‚ b) protected lemma add_lt_add_of_lt_of_le {a b c d : β„€} (h₁ : a < b) (hβ‚‚ : c ≀ d) : a + c < b + d := lt_of_lt_of_le (int.add_lt_add_right h₁ c) (int.add_le_add_left hβ‚‚ b) protected lemma lt_add_of_pos_right (a : β„€) {b : β„€} (h : 0 < b) : a < a + b := have a + 0 < a + b, from int.add_lt_add_left h a, by rwa [int.add_zero] at this protected lemma lt_add_of_pos_left (a : β„€) {b : β„€} (h : 0 < b) : a < b + a := have 0 + a < b + a, from int.add_lt_add_right h a, by rwa [int.zero_add] at this protected lemma le_of_add_le_add_right {a b c : β„€} (h : a + b ≀ c + b) : a ≀ c := int.le_of_add_le_add_left (show b + a ≀ b + c, begin rw [int.add_comm b a, int.add_comm b c], assumption end) protected lemma lt_of_add_lt_add_right {a b c : β„€} (h : a + b < c + b) : a < c := int.lt_of_add_lt_add_left (show b + a < b + c, begin rw [int.add_comm b a, int.add_comm b c], assumption end) -- here we start using properties of zero. protected lemma add_nonneg {a b : β„€} (ha : 0 ≀ a) (hb : 0 ≀ b) : 0 ≀ a + b := int.zero_add (0:β„€) β–Έ (int.add_le_add ha hb) protected lemma add_pos {a b : β„€} (ha : 0 < a) (hb : 0 < b) : 0 < a + b := int.zero_add (0:β„€) β–Έ (int.add_lt_add ha hb) protected lemma add_pos_of_pos_of_nonneg {a b : β„€} (ha : 0 < a) (hb : 0 ≀ b) : 0 < a + b := int.zero_add (0:β„€) β–Έ (int.add_lt_add_of_lt_of_le ha hb) protected lemma add_pos_of_nonneg_of_pos {a b : β„€} (ha : 0 ≀ a) (hb : 0 < b) : 0 < a + b := int.zero_add (0:β„€) β–Έ (int.add_lt_add_of_le_of_lt ha hb) protected lemma add_nonpos {a b : β„€} (ha : a ≀ 0) (hb : b ≀ 0) : a + b ≀ 0 := int.zero_add (0:β„€) β–Έ (int.add_le_add ha hb) protected lemma add_neg {a b : β„€} (ha : a < 0) (hb : b < 0) : a + b < 0 := int.zero_add (0:β„€) β–Έ (int.add_lt_add ha hb) protected lemma add_neg_of_neg_of_nonpos {a b : β„€} (ha : a < 0) (hb : b ≀ 0) : a + b < 0 := int.zero_add (0:β„€) β–Έ (int.add_lt_add_of_lt_of_le ha hb) protected lemma add_neg_of_nonpos_of_neg {a b : β„€} (ha : a ≀ 0) (hb : b < 0) : a + b < 0 := int.zero_add (0:β„€) β–Έ (int.add_lt_add_of_le_of_lt ha hb) protected lemma lt_add_of_le_of_pos {a b c : β„€} (hbc : b ≀ c) (ha : 0 < a) : b < c + a := int.add_zero b β–Έ int.add_lt_add_of_le_of_lt hbc ha protected lemma sub_add_cancel (a b : β„€) : a - b + b = a := int.neg_add_cancel_right a b protected lemma add_sub_cancel (a b : β„€) : a + b - b = a := int.add_neg_cancel_right a b protected lemma add_sub_assoc (a b c : β„€) : a + b - c = a + (b - c) := by rw [int.sub_eq_add_neg, int.add_assoc, ←int.sub_eq_add_neg] protected lemma neg_le_neg {a b : β„€} (h : a ≀ b) : -b ≀ -a := have 0 ≀ -a + b, from int.add_left_neg a β–Έ int.add_le_add_left h (-a), have 0 + -b ≀ -a + b + -b, from int.add_le_add_right this (-b), by rwa [int.add_neg_cancel_right, int.zero_add] at this protected lemma le_of_neg_le_neg {a b : β„€} (h : -b ≀ -a) : a ≀ b := suffices -(-a) ≀ -(-b), from begin simp [int.neg_neg] at this, assumption end, int.neg_le_neg h protected lemma nonneg_of_neg_nonpos {a : β„€} (h : -a ≀ 0) : 0 ≀ a := have -a ≀ -0, by rwa int.neg_zero, int.le_of_neg_le_neg this protected lemma neg_nonpos_of_nonneg {a : β„€} (h : 0 ≀ a) : -a ≀ 0 := have -a ≀ -0, from int.neg_le_neg h, by rwa int.neg_zero at this protected lemma nonpos_of_neg_nonneg {a : β„€} (h : 0 ≀ -a) : a ≀ 0 := have -0 ≀ -a, by rwa int.neg_zero, int.le_of_neg_le_neg this protected lemma neg_nonneg_of_nonpos {a : β„€} (h : a ≀ 0) : 0 ≀ -a := have -0 ≀ -a, from int.neg_le_neg h, by rwa int.neg_zero at this protected lemma neg_lt_neg {a b : β„€} (h : a < b) : -b < -a := have 0 < -a + b, from int.add_left_neg a β–Έ int.add_lt_add_left h (-a), have 0 + -b < -a + b + -b, from int.add_lt_add_right this (-b), by rwa [int.add_neg_cancel_right, int.zero_add] at this protected lemma lt_of_neg_lt_neg {a b : β„€} (h : -b < -a) : a < b := int.neg_neg a β–Έ int.neg_neg b β–Έ int.neg_lt_neg h protected lemma pos_of_neg_neg {a : β„€} (h : -a < 0) : 0 < a := have -a < -0, by rwa int.neg_zero, int.lt_of_neg_lt_neg this protected lemma neg_neg_of_pos {a : β„€} (h : 0 < a) : -a < 0 := have -a < -0, from int.neg_lt_neg h, by rwa int.neg_zero at this protected lemma neg_of_neg_pos {a : β„€} (h : 0 < -a) : a < 0 := have -0 < -a, by rwa int.neg_zero, int.lt_of_neg_lt_neg this protected lemma neg_pos_of_neg {a : β„€} (h : a < 0) : 0 < -a := have -0 < -a, from int.neg_lt_neg h, by rwa int.neg_zero at this protected lemma le_neg_of_le_neg {a b : β„€} (h : a ≀ -b) : b ≀ -a := begin have h := int.neg_le_neg h, rwa int.neg_neg at h end protected lemma neg_le_of_neg_le {a b : β„€} (h : -a ≀ b) : -b ≀ a := begin have h := int.neg_le_neg h, rwa int.neg_neg at h end protected lemma lt_neg_of_lt_neg {a b : β„€} (h : a < -b) : b < -a := begin have h := int.neg_lt_neg h, rwa int.neg_neg at h end protected lemma neg_lt_of_neg_lt {a b : β„€} (h : -a < b) : -b < a := begin have h := int.neg_lt_neg h, rwa int.neg_neg at h end protected lemma sub_nonneg_of_le {a b : β„€} (h : b ≀ a) : 0 ≀ a - b := begin have h := int.add_le_add_right h (-b), rwa int.add_right_neg at h end protected lemma le_of_sub_nonneg {a b : β„€} (h : 0 ≀ a - b) : b ≀ a := begin have h := int.add_le_add_right h b, rwa [int.sub_add_cancel, int.zero_add] at h end protected lemma sub_nonpos_of_le {a b : β„€} (h : a ≀ b) : a - b ≀ 0 := begin have h := int.add_le_add_right h (-b), rwa int.add_right_neg at h end protected lemma le_of_sub_nonpos {a b : β„€} (h : a - b ≀ 0) : a ≀ b := begin have h := int.add_le_add_right h b, rwa [int.sub_add_cancel, int.zero_add] at h end protected lemma sub_pos_of_lt {a b : β„€} (h : b < a) : 0 < a - b := begin have h := int.add_lt_add_right h (-b), rwa int.add_right_neg at h end protected lemma lt_of_sub_pos {a b : β„€} (h : 0 < a - b) : b < a := begin have h := int.add_lt_add_right h b, rwa [int.sub_add_cancel, int.zero_add] at h end protected lemma sub_neg_of_lt {a b : β„€} (h : a < b) : a - b < 0 := begin have h := int.add_lt_add_right h (-b), rwa int.add_right_neg at h end protected lemma lt_of_sub_neg {a b : β„€} (h : a - b < 0) : a < b := begin have h := int.add_lt_add_right h b, rwa [int.sub_add_cancel, int.zero_add] at h end protected lemma add_le_of_le_neg_add {a b c : β„€} (h : b ≀ -a + c) : a + b ≀ c := begin have h := int.add_le_add_left h a, rwa int.add_neg_cancel_left at h end protected lemma le_neg_add_of_add_le {a b c : β„€} (h : a + b ≀ c) : b ≀ -a + c := begin have h := int.add_le_add_left h (-a), rwa int.neg_add_cancel_left at h end protected lemma add_le_of_le_sub_left {a b c : β„€} (h : b ≀ c - a) : a + b ≀ c := begin have h := int.add_le_add_left h a, rwa [← int.add_sub_assoc, int.add_comm a c, int.add_sub_cancel] at h end protected lemma le_sub_left_of_add_le {a b c : β„€} (h : a + b ≀ c) : b ≀ c - a := begin have h := int.add_le_add_right h (-a), rwa [int.add_comm a b, int.add_neg_cancel_right] at h end protected lemma add_le_of_le_sub_right {a b c : β„€} (h : a ≀ c - b) : a + b ≀ c := begin have h := int.add_le_add_right h b, rwa int.sub_add_cancel at h end protected lemma le_sub_right_of_add_le {a b c : β„€} (h : a + b ≀ c) : a ≀ c - b := begin have h := int.add_le_add_right h (-b), rwa int.add_neg_cancel_right at h end protected lemma le_add_of_neg_add_le {a b c : β„€} (h : -b + a ≀ c) : a ≀ b + c := begin have h := int.add_le_add_left h b, rwa int.add_neg_cancel_left at h end protected lemma neg_add_le_of_le_add {a b c : β„€} (h : a ≀ b + c) : -b + a ≀ c := begin have h := int.add_le_add_left h (-b), rwa int.neg_add_cancel_left at h end protected lemma le_add_of_sub_left_le {a b c : β„€} (h : a - b ≀ c) : a ≀ b + c := begin have h := int.add_le_add_right h b, rwa [int.sub_add_cancel, int.add_comm] at h end protected lemma sub_left_le_of_le_add {a b c : β„€} (h : a ≀ b + c) : a - b ≀ c := begin have h := int.add_le_add_right h (-b), rwa [int.add_comm b c, int.add_neg_cancel_right] at h end protected lemma le_add_of_sub_right_le {a b c : β„€} (h : a - c ≀ b) : a ≀ b + c := begin have h := int.add_le_add_right h c, rwa int.sub_add_cancel at h end protected lemma sub_right_le_of_le_add {a b c : β„€} (h : a ≀ b + c) : a - c ≀ b := begin have h := int.add_le_add_right h (-c), rwa int.add_neg_cancel_right at h end protected lemma le_add_of_neg_add_le_left {a b c : β„€} (h : -b + a ≀ c) : a ≀ b + c := begin rw int.add_comm at h, exact int.le_add_of_sub_left_le h end protected lemma neg_add_le_left_of_le_add {a b c : β„€} (h : a ≀ b + c) : -b + a ≀ c := begin rw int.add_comm, exact int.sub_left_le_of_le_add h end protected lemma le_add_of_neg_add_le_right {a b c : β„€} (h : -c + a ≀ b) : a ≀ b + c := begin rw int.add_comm at h, exact int.le_add_of_sub_right_le h end protected lemma neg_add_le_right_of_le_add {a b c : β„€} (h : a ≀ b + c) : -c + a ≀ b := begin rw int.add_comm at h, exact int.neg_add_le_left_of_le_add h end protected lemma le_add_of_neg_le_sub_left {a b c : β„€} (h : -a ≀ b - c) : c ≀ a + b := int.le_add_of_neg_add_le_left (int.add_le_of_le_sub_right h) protected lemma neg_le_sub_left_of_le_add {a b c : β„€} (h : c ≀ a + b) : -a ≀ b - c := begin have h := int.le_neg_add_of_add_le (int.sub_left_le_of_le_add h), rwa int.add_comm at h end protected lemma le_add_of_neg_le_sub_right {a b c : β„€} (h : -b ≀ a - c) : c ≀ a + b := int.le_add_of_sub_right_le (int.add_le_of_le_sub_left h) protected lemma neg_le_sub_right_of_le_add {a b c : β„€} (h : c ≀ a + b) : -b ≀ a - c := int.le_sub_left_of_add_le (int.sub_right_le_of_le_add h) protected lemma sub_le_of_sub_le {a b c : β„€} (h : a - b ≀ c) : a - c ≀ b := int.sub_left_le_of_le_add (int.le_add_of_sub_right_le h) protected lemma sub_le_sub_left {a b : β„€} (h : a ≀ b) (c : β„€) : c - b ≀ c - a := int.add_le_add_left (int.neg_le_neg h) c protected lemma sub_le_sub_right {a b : β„€} (h : a ≀ b) (c : β„€) : a - c ≀ b - c := int.add_le_add_right h (-c) protected lemma sub_le_sub {a b c d : β„€} (hab : a ≀ b) (hcd : c ≀ d) : a - d ≀ b - c := int.add_le_add hab (int.neg_le_neg hcd) protected lemma add_lt_of_lt_neg_add {a b c : β„€} (h : b < -a + c) : a + b < c := begin have h := int.add_lt_add_left h a, rwa int.add_neg_cancel_left at h end protected lemma lt_neg_add_of_add_lt {a b c : β„€} (h : a + b < c) : b < -a + c := begin have h := int.add_lt_add_left h (-a), rwa int.neg_add_cancel_left at h end protected lemma add_lt_of_lt_sub_left {a b c : β„€} (h : b < c - a) : a + b < c := begin have h := int.add_lt_add_left h a, rwa [← int.add_sub_assoc, int.add_comm a c, int.add_sub_cancel] at h end protected lemma lt_sub_left_of_add_lt {a b c : β„€} (h : a + b < c) : b < c - a := begin have h := int.add_lt_add_right h (-a), rwa [int.add_comm a b, int.add_neg_cancel_right] at h end protected lemma add_lt_of_lt_sub_right {a b c : β„€} (h : a < c - b) : a + b < c := begin have h := int.add_lt_add_right h b, rwa int.sub_add_cancel at h end protected lemma lt_sub_right_of_add_lt {a b c : β„€} (h : a + b < c) : a < c - b := begin have h := int.add_lt_add_right h (-b), rwa int.add_neg_cancel_right at h end protected lemma lt_add_of_neg_add_lt {a b c : β„€} (h : -b + a < c) : a < b + c := begin have h := int.add_lt_add_left h b, rwa int.add_neg_cancel_left at h end protected lemma neg_add_lt_of_lt_add {a b c : β„€} (h : a < b + c) : -b + a < c := begin have h := int.add_lt_add_left h (-b), rwa int.neg_add_cancel_left at h end protected lemma lt_add_of_sub_left_lt {a b c : β„€} (h : a - b < c) : a < b + c := begin have h := int.add_lt_add_right h b, rwa [int.sub_add_cancel, int.add_comm] at h end protected lemma sub_left_lt_of_lt_add {a b c : β„€} (h : a < b + c) : a - b < c := begin have h := int.add_lt_add_right h (-b), rwa [int.add_comm b c, int.add_neg_cancel_right] at h end protected lemma lt_add_of_sub_right_lt {a b c : β„€} (h : a - c < b) : a < b + c := begin have h := int.add_lt_add_right h c, rwa int.sub_add_cancel at h end protected lemma sub_right_lt_of_lt_add {a b c : β„€} (h : a < b + c) : a - c < b := begin have h := int.add_lt_add_right h (-c), rwa int.add_neg_cancel_right at h end protected lemma lt_add_of_neg_add_lt_left {a b c : β„€} (h : -b + a < c) : a < b + c := begin rw int.add_comm at h, exact int.lt_add_of_sub_left_lt h end protected lemma neg_add_lt_left_of_lt_add {a b c : β„€} (h : a < b + c) : -b + a < c := begin rw int.add_comm, exact int.sub_left_lt_of_lt_add h end protected lemma lt_add_of_neg_add_lt_right {a b c : β„€} (h : -c + a < b) : a < b + c := begin rw int.add_comm at h, exact int.lt_add_of_sub_right_lt h end protected lemma neg_add_lt_right_of_lt_add {a b c : β„€} (h : a < b + c) : -c + a < b := begin rw int.add_comm at h, exact int.neg_add_lt_left_of_lt_add h end protected lemma lt_add_of_neg_lt_sub_left {a b c : β„€} (h : -a < b - c) : c < a + b := int.lt_add_of_neg_add_lt_left (int.add_lt_of_lt_sub_right h) protected lemma neg_lt_sub_left_of_lt_add {a b c : β„€} (h : c < a + b) : -a < b - c := begin have h := int.lt_neg_add_of_add_lt (int.sub_left_lt_of_lt_add h), rwa int.add_comm at h end protected lemma lt_add_of_neg_lt_sub_right {a b c : β„€} (h : -b < a - c) : c < a + b := int.lt_add_of_sub_right_lt (int.add_lt_of_lt_sub_left h) protected lemma neg_lt_sub_right_of_lt_add {a b c : β„€} (h : c < a + b) : -b < a - c := int.lt_sub_left_of_add_lt (int.sub_right_lt_of_lt_add h) protected lemma sub_lt_of_sub_lt {a b c : β„€} (h : a - b < c) : a - c < b := int.sub_left_lt_of_lt_add (int.lt_add_of_sub_right_lt h) protected lemma sub_lt_sub_left {a b : β„€} (h : a < b) (c : β„€) : c - b < c - a := int.add_lt_add_left (int.neg_lt_neg h) c protected lemma sub_lt_sub_right {a b : β„€} (h : a < b) (c : β„€) : a - c < b - c := int.add_lt_add_right h (-c) protected lemma sub_lt_sub {a b c d : β„€} (hab : a < b) (hcd : c < d) : a - d < b - c := int.add_lt_add hab (int.neg_lt_neg hcd) protected lemma sub_lt_sub_of_le_of_lt {a b c d : β„€} (hab : a ≀ b) (hcd : c < d) : a - d < b - c := int.add_lt_add_of_le_of_lt hab (int.neg_lt_neg hcd) protected lemma sub_lt_sub_of_lt_of_le {a b c d : β„€} (hab : a < b) (hcd : c ≀ d) : a - d < b - c := int.add_lt_add_of_lt_of_le hab (int.neg_le_neg hcd) protected lemma sub_le_self (a : β„€) {b : β„€} (h : 0 ≀ b) : a - b ≀ a := calc a - b = a + -b : rfl ... ≀ a + 0 : int.add_le_add_left (int.neg_nonpos_of_nonneg h) _ ... = a : by rw int.add_zero protected lemma sub_lt_self (a : β„€) {b : β„€} (h : 0 < b) : a - b < a := calc a - b = a + -b : rfl ... < a + 0 : int.add_lt_add_left (int.neg_neg_of_pos h) _ ... = a : by rw int.add_zero protected 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 int.add_le_add, apply int.add_le_add, assumption', apply le_refl end end /- missing facts -/ protected lemma mul_lt_mul_of_pos_left {a b c : β„€} (h₁ : a < b) (hβ‚‚ : 0 < c) : c * a < c * b := have 0 < b - a, from int.sub_pos_of_lt h₁, have 0 < c * (b - a), from int.mul_pos hβ‚‚ this, begin rw int.mul_sub at this, exact int.lt_of_sub_pos this end protected lemma mul_lt_mul_of_pos_right {a b c : β„€} (h₁ : a < b) (hβ‚‚ : 0 < c) : a * c < b * c := have 0 < b - a, from int.sub_pos_of_lt h₁, have 0 < (b - a) * c, from int.mul_pos this hβ‚‚, begin rw int.sub_mul at this, exact int.lt_of_sub_pos this end protected lemma mul_le_mul_of_nonneg_left {a b c : β„€} (h₁ : a ≀ b) (hβ‚‚ : 0 ≀ c) : c * a ≀ c * b := begin by_cases hba : b ≀ a, { simp [le_antisymm hba h₁] }, by_cases hc0 : c ≀ 0, { simp [le_antisymm hc0 hβ‚‚, int.zero_mul] }, exact (le_not_le_of_lt (int.mul_lt_mul_of_pos_left (lt_of_le_not_le h₁ hba) (lt_of_le_not_le hβ‚‚ hc0))).left, end protected lemma mul_le_mul_of_nonneg_right {a b c : β„€} (h₁ : a ≀ b) (hβ‚‚ : 0 ≀ c) : a * c ≀ b * c := begin by_cases hba : b ≀ a, { simp [le_antisymm hba h₁] }, by_cases hc0 : c ≀ 0, { simp [le_antisymm hc0 hβ‚‚, int.mul_zero] }, exact (le_not_le_of_lt (int.mul_lt_mul_of_pos_right (lt_of_le_not_le h₁ hba) (lt_of_le_not_le hβ‚‚ hc0))).left, end -- TODO: there are four variations, depending on which variables we assume to be nonneg protected lemma mul_le_mul {a b c d : β„€} (hac : a ≀ c) (hbd : b ≀ d) (nn_b : 0 ≀ b) (nn_c : 0 ≀ c) : a * b ≀ c * d := calc a * b ≀ c * b : int.mul_le_mul_of_nonneg_right hac nn_b ... ≀ c * d : int.mul_le_mul_of_nonneg_left hbd nn_c protected lemma mul_nonpos_of_nonneg_of_nonpos {a b : β„€} (ha : 0 ≀ a) (hb : b ≀ 0) : a * b ≀ 0 := have h : a * b ≀ a * 0, from int.mul_le_mul_of_nonneg_left hb ha, by rwa int.mul_zero at h protected lemma mul_nonpos_of_nonpos_of_nonneg {a b : β„€} (ha : a ≀ 0) (hb : 0 ≀ b) : a * b ≀ 0 := have h : a * b ≀ 0 * b, from int.mul_le_mul_of_nonneg_right ha hb, by rwa int.zero_mul at h protected lemma mul_lt_mul {a b c d : β„€} (hac : a < c) (hbd : b ≀ d) (pos_b : 0 < b) (nn_c : 0 ≀ c) : a * b < c * d := calc a * b < c * b : int.mul_lt_mul_of_pos_right hac pos_b ... ≀ c * d : int.mul_le_mul_of_nonneg_left hbd nn_c protected lemma mul_lt_mul' {a b c d : β„€} (h1 : a ≀ c) (h2 : b < d) (h3 : 0 ≀ b) (h4 : 0 < c) : a * b < c * d := calc a * b ≀ c * b : int.mul_le_mul_of_nonneg_right h1 h3 ... < c * d : int.mul_lt_mul_of_pos_left h2 h4 protected lemma mul_neg_of_pos_of_neg {a b : β„€} (ha : 0 < a) (hb : b < 0) : a * b < 0 := have h : a * b < a * 0, from int.mul_lt_mul_of_pos_left hb ha, by rwa int.mul_zero at h protected lemma mul_neg_of_neg_of_pos {a b : β„€} (ha : a < 0) (hb : 0 < b) : a * b < 0 := have h : a * b < 0 * b, from int.mul_lt_mul_of_pos_right ha hb, by rwa int.zero_mul at h protected lemma mul_le_mul_of_nonpos_right {a b c : β„€} (h : b ≀ a) (hc : c ≀ 0) : a * c ≀ b * c := have -c β‰₯ 0, from int.neg_nonneg_of_nonpos hc, have b * -c ≀ a * -c, from int.mul_le_mul_of_nonneg_right h this, have -(b * c) ≀ -(a * c), by rwa [← int.neg_mul_eq_mul_neg, ← int.neg_mul_eq_mul_neg] at this, int.le_of_neg_le_neg this protected lemma mul_nonneg_of_nonpos_of_nonpos {a b : β„€} (ha : a ≀ 0) (hb : b ≀ 0) : 0 ≀ a * b := have 0 * b ≀ a * b, from int.mul_le_mul_of_nonpos_right ha hb, by rwa int.zero_mul at this protected lemma mul_lt_mul_of_neg_left {a b c : β„€} (h : b < a) (hc : c < 0) : c * a < c * b := have -c > 0, from int.neg_pos_of_neg hc, have -c * b < -c * a, from int.mul_lt_mul_of_pos_left h this, have -(c * b) < -(c * a), by rwa [← int.neg_mul_eq_neg_mul, ← int.neg_mul_eq_neg_mul] at this, int.lt_of_neg_lt_neg this protected lemma mul_lt_mul_of_neg_right {a b c : β„€} (h : b < a) (hc : c < 0) : a * c < b * c := have -c > 0, from int.neg_pos_of_neg hc, have b * -c < a * -c, from int.mul_lt_mul_of_pos_right h this, have -(b * c) < -(a * c), by rwa [← int.neg_mul_eq_mul_neg, ← int.neg_mul_eq_mul_neg] at this, int.lt_of_neg_lt_neg this protected lemma mul_pos_of_neg_of_neg {a b : β„€} (ha : a < 0) (hb : b < 0) : 0 < a * b := have 0 * b < a * b, from int.mul_lt_mul_of_neg_right ha hb, by rwa int.zero_mul at this protected lemma mul_self_le_mul_self {a b : β„€} (h1 : 0 ≀ a) (h2 : a ≀ b) : a * a ≀ b * b := int.mul_le_mul h2 h2 h1 (le_trans h1 h2) protected lemma mul_self_lt_mul_self {a b : β„€} (h1 : 0 ≀ a) (h2 : a < b) : a * a < b * b := int.mul_lt_mul' (le_of_lt h2) h2 h1 (lt_of_le_of_lt h1 h2) /- more facts specific to int -/ theorem of_nat_nonneg (n : β„•) : 0 ≀ of_nat n := trivial theorem coe_succ_pos (n : nat) : 0 < (nat.succ n : β„€) := coe_nat_lt_coe_nat_of_lt (nat.succ_pos _) theorem exists_eq_neg_of_nat {a : β„€} (H : a ≀ 0) : βˆƒn : β„•, a = -n := let ⟨n, h⟩ := eq_coe_of_zero_le (int.neg_nonneg_of_nonpos H) in ⟨n, int.eq_neg_of_eq_neg h.symm⟩ theorem nat_abs_of_nonneg {a : β„€} (H : 0 ≀ a) : (nat_abs a : β„€) = a := match a, eq_coe_of_zero_le H with ._, ⟨n, rfl⟩ := rfl end theorem of_nat_nat_abs_of_nonpos {a : β„€} (H : a ≀ 0) : (nat_abs a : β„€) = -a := by rw [← nat_abs_neg, nat_abs_of_nonneg (int.neg_nonneg_of_nonpos H)] theorem lt_of_add_one_le {a b : β„€} (H : a + 1 ≀ b) : a < b := H theorem add_one_le_of_lt {a b : β„€} (H : a < b) : a + 1 ≀ b := H theorem lt_add_one_of_le {a b : β„€} (H : a ≀ b) : a < b + 1 := int.add_le_add_right H 1 theorem le_of_lt_add_one {a b : β„€} (H : a < b + 1) : a ≀ b := int.le_of_add_le_add_right H theorem sub_one_le_of_lt {a b : β„€} (H : a ≀ b) : a - 1 < b := int.sub_right_lt_of_lt_add $ lt_add_one_of_le H theorem lt_of_sub_one_le {a b : β„€} (H : a - 1 < b) : a ≀ b := le_of_lt_add_one $ int.lt_add_of_sub_right_lt H theorem le_sub_one_of_lt {a b : β„€} (H : a < b) : a ≀ b - 1 := int.le_sub_right_of_add_le H theorem lt_of_le_sub_one {a b : β„€} (H : a ≀ b - 1) : a < b := int.add_le_of_le_sub_right H theorem sign_of_succ (n : nat) : sign (nat.succ n) = 1 := rfl theorem sign_eq_one_of_pos {a : β„€} (h : 0 < a) : sign a = 1 := match a, eq_succ_of_zero_lt h with ._, ⟨n, rfl⟩ := rfl end theorem sign_eq_neg_one_of_neg {a : β„€} (h : a < 0) : sign a = -1 := match a, eq_neg_succ_of_lt_zero h with ._, ⟨n, rfl⟩ := rfl end lemma eq_zero_of_sign_eq_zero : Ξ  {a : β„€}, sign a = 0 β†’ a = 0 | 0 _ := rfl theorem pos_of_sign_eq_one : βˆ€ {a : β„€}, sign a = 1 β†’ 0 < a | (n+1:β„•) _ := coe_nat_lt_coe_nat_of_lt (nat.succ_pos _) theorem neg_of_sign_eq_neg_one : βˆ€ {a : β„€}, sign a = -1 β†’ a < 0 | (n+1:β„•) h := match h with end | 0 h := match h with end | -[1+ n] _ := neg_succ_lt_zero _ theorem sign_eq_one_iff_pos (a : β„€) : sign a = 1 ↔ 0 < a := ⟨pos_of_sign_eq_one, sign_eq_one_of_pos⟩ theorem sign_eq_neg_one_iff_neg (a : β„€) : sign a = -1 ↔ a < 0 := ⟨neg_of_sign_eq_neg_one, sign_eq_neg_one_of_neg⟩ theorem sign_eq_zero_iff_zero (a : β„€) : sign a = 0 ↔ a = 0 := ⟨eq_zero_of_sign_eq_zero, Ξ» h, by rw [h, sign_zero]⟩ protected lemma eq_zero_or_eq_zero_of_mul_eq_zero {a b : β„€} (h : a * b = 0) : a = 0 ∨ b = 0 := match lt_trichotomy 0 a with | or.inl hlt₁ := match lt_trichotomy 0 b with | or.inl hltβ‚‚ := have 0 < a * b, from int.mul_pos hlt₁ hltβ‚‚, begin rw h at this, exact absurd this (lt_irrefl _) end | or.inr (or.inl heqβ‚‚) := or.inr heqβ‚‚.symm | or.inr (or.inr hgtβ‚‚) := have 0 > a * b, from int.mul_neg_of_pos_of_neg hlt₁ hgtβ‚‚, begin rw h at this, exact absurd this (lt_irrefl _) end end | or.inr (or.inl heq₁) := or.inl heq₁.symm | or.inr (or.inr hgt₁) := match lt_trichotomy 0 b with | or.inl hltβ‚‚ := have 0 > a * b, from int.mul_neg_of_neg_of_pos hgt₁ hltβ‚‚, begin rw h at this, exact absurd this (lt_irrefl _) end | or.inr (or.inl heqβ‚‚) := or.inr heqβ‚‚.symm | or.inr (or.inr hgtβ‚‚) := have 0 < a * b, from int.mul_pos_of_neg_of_neg hgt₁ hgtβ‚‚, begin rw h at this, exact absurd this (lt_irrefl _) end end end protected lemma eq_of_mul_eq_mul_right {a b c : β„€} (ha : a β‰  0) (h : b * a = c * a) : b = c := have b * a - c * a = 0, from int.sub_eq_zero_of_eq h, have (b - c) * a = 0, by rw [int.sub_mul, this], have b - c = 0, from (int.eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_right ha, int.eq_of_sub_eq_zero this protected lemma eq_of_mul_eq_mul_left {a b c : β„€} (ha : a β‰  0) (h : a * b = a * c) : b = c := have a * b - a * c = 0, from int.sub_eq_zero_of_eq h, have a * (b - c) = 0, by rw [int.mul_sub, this], have b - c = 0, from (int.eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_left ha, int.eq_of_sub_eq_zero this theorem eq_one_of_mul_eq_self_left {a b : β„€} (Hpos : a β‰  0) (H : b * a = a) : b = 1 := int.eq_of_mul_eq_mul_right Hpos (by rw [int.one_mul, H]) theorem eq_one_of_mul_eq_self_right {a b : β„€} (Hpos : b β‰  0) (H : b * a = b) : a = 1 := int.eq_of_mul_eq_mul_left Hpos (by rw [int.mul_one, H]) end int
88b6d1ca930619b9962f697337cc05793bcd3028
6065973b1fa7bbacba932011c9e2f32bf7bdd6c1
/src/analysis/special_functions/trigonometric.lean
6a01cee8c2256fa1eec49350677a71e637eb28ba
[ "Apache-2.0" ]
permissive
khmacdonald/mathlib
90a0fa2222369fa69ed2fbfb841b74d2bdfd66cb
3669cb35c578441812ad30fd967d21a94b6f387e
refs/heads/master
1,675,863,801,090
1,609,761,876,000
1,609,761,876,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
104,063
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 /-- Inverse of the `sin` function, returns values in the range `-Ο€ / 2 ≀ arcsin x` and `arcsin x ≀ Ο€ / 2`. If the argument is not between `-1` and `1` it defaults to `0` -/ noncomputable def arcsin (x : ℝ) : ℝ := if hx : -1 ≀ x ∧ x ≀ 1 then classical.some (surj_on_sin hx) else 0 lemma arcsin_le_pi_div_two (x : ℝ) : arcsin x ≀ Ο€ / 2 := if hx : -1 ≀ x ∧ x ≀ 1 then by rw [arcsin, dif_pos hx]; exact (classical.some_spec (surj_on_sin hx)).1.2 else by rw [arcsin, dif_neg hx]; exact le_of_lt pi_div_two_pos lemma neg_pi_div_two_le_arcsin (x : ℝ) : -(Ο€ / 2) ≀ arcsin x := if hx : -1 ≀ x ∧ x ≀ 1 then by rw [arcsin, dif_pos hx]; exact (classical.some_spec (surj_on_sin hx)).1.1 else by rw [arcsin, dif_neg hx]; exact neg_nonpos.2 (le_of_lt pi_div_two_pos) lemma sin_arcsin {x : ℝ} (hx₁ : -1 ≀ x) (hxβ‚‚ : x ≀ 1) : sin (arcsin x) = x := by rw [arcsin, dif_pos (and.intro hx₁ hxβ‚‚)]; exact (classical.some_spec (surj_on_sin ⟨hx₁, hxβ‚‚βŸ©)).2 lemma arcsin_sin {x : ℝ} (hx₁ : -(Ο€ / 2) ≀ x) (hxβ‚‚ : x ≀ Ο€ / 2) : arcsin (sin x) = x := inj_on_sin ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩ ⟨hx₁, hxβ‚‚βŸ© (by rw sin_arcsin (neg_one_le_sin _) (sin_le_one _)) lemma arcsin_inj {x y : ℝ} (hx₁ : -1 ≀ x) (hxβ‚‚ : x ≀ 1) (hy₁ : -1 ≀ y) (hyβ‚‚ : y ≀ 1) (hxy : arcsin x = arcsin y) : x = y := by rw [← sin_arcsin hx₁ hxβ‚‚, ← sin_arcsin hy₁ hyβ‚‚, hxy] @[simp] lemma arcsin_zero : arcsin 0 = 0 := inj_on_sin ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩ ⟨neg_nonpos.2 (le_of_lt pi_div_two_pos), le_of_lt pi_div_two_pos⟩ (by rw [sin_arcsin, sin_zero]; norm_num) @[simp] lemma arcsin_one : arcsin 1 = Ο€ / 2 := inj_on_sin ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩ ⟨by linarith [pi_pos], le_refl _⟩ (by rw [sin_arcsin, sin_pi_div_two]; norm_num) @[simp] lemma arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x := if h : -1 ≀ x ∧ x ≀ 1 then have -1 ≀ -x ∧ -x ≀ 1, by rwa [neg_le_neg_iff, neg_le, and.comm], inj_on_sin ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩ ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.1 (neg_pi_div_two_le_arcsin _)⟩ (by rw [sin_arcsin this.1 this.2, sin_neg, sin_arcsin h.1 h.2]) else have Β¬(-1 ≀ -x ∧ -x ≀ 1) := by rwa [neg_le_neg_iff, neg_le, and.comm], by rw [arcsin, arcsin, dif_neg h, dif_neg this, neg_zero] @[simp] lemma arcsin_neg_one : arcsin (-1) = -(Ο€ / 2) := by simp lemma arcsin_nonneg {x : ℝ} (hx : 0 ≀ x) : 0 ≀ arcsin x := if hx₁ : x ≀ 1 then not_lt.1 (Ξ» h, not_lt.2 hx begin have := sin_lt_sin_of_lt_of_le_pi_div_two (neg_pi_div_two_le_arcsin _) (le_of_lt pi_div_two_pos) h, rw [real.sin_arcsin, sin_zero] at this; linarith end) else by rw [arcsin, dif_neg]; simp [hx₁] lemma arcsin_eq_zero_iff {x : ℝ} (hx₁ : -1 ≀ x) (hxβ‚‚ : x ≀ 1) : arcsin x = 0 ↔ x = 0 := ⟨λ h, have sin (arcsin x) = 0, by simp [h], by rwa [sin_arcsin hx₁ hxβ‚‚] at this, Ξ» h, by simp [h]⟩ lemma arcsin_pos {x : ℝ} (hx₁ : 0 < x) (hxβ‚‚ : x ≀ 1) : 0 < arcsin x := lt_of_le_of_ne (arcsin_nonneg (le_of_lt hx₁)) (ne.symm (mt (arcsin_eq_zero_iff (by linarith) hxβ‚‚).1 (ne_of_lt hx₁).symm)) lemma arcsin_nonpos {x : ℝ} (hx : x ≀ 0) : arcsin x ≀ 0 := neg_nonneg.1 (arcsin_neg x β–Έ arcsin_nonneg (neg_nonneg.2 hx)) /-- 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` -/ 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 [sub_eq_add_neg, 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 arccos_inj {x y : ℝ} (hx₁ : -1 ≀ x) (hxβ‚‚ : x ≀ 1) (hy₁ : -1 ≀ y) (hyβ‚‚ : y ≀ 1) (hxy : arccos x = arccos y) : x = y := arcsin_inj hx₁ hxβ‚‚ hy₁ hyβ‚‚ $ by simp [arccos, *] at * @[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] lemma arccos_neg (x : ℝ) : arccos (-x) = Ο€ - arccos x := by rw [← add_halves Ο€, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self]; simp 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 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 abs_div_sqrt_one_add_lt (x : ℝ) : abs (x / sqrt (1 + x ^ 2)) < 1 := have h₁ : 0 < 1 + x ^ 2, from add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg _), have hβ‚‚ : 0 < sqrt (1 + x ^ 2), from sqrt_pos.2 h₁, by rw [abs_div, div_lt_iff (abs_pos_of_pos hβ‚‚), one_mul, mul_self_lt_mul_self_iff (abs_nonneg x) (abs_nonneg _), ← abs_mul, ← abs_mul, mul_self_sqrt (add_nonneg zero_le_one (pow_two_nonneg _)), abs_of_nonneg (mul_self_nonneg x), abs_of_nonneg (le_of_lt h₁), pow_two, add_comm]; exact lt_add_one _ lemma div_sqrt_one_add_lt_one (x : ℝ) : x / sqrt (1 + x ^ 2) < 1 := (abs_lt.1 (abs_div_sqrt_one_add_lt _)).2 lemma neg_one_lt_div_sqrt_one_add (x : ℝ) : -1 < x / sqrt (1 + x ^ 2) := (abs_lt.1 (abs_div_sqrt_one_add_lt _)).1 @[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 [pi_pos])) 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 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 := match lt_trichotomy x y with | or.inl h := absurd (tan_lt_tan_of_lt_of_lt_pi_div_two hx₁ hyβ‚‚ h) (by rw hxy; exact lt_irrefl _) | or.inr (or.inl h) := h | or.inr (or.inr h) := absurd (tan_lt_tan_of_lt_of_lt_pi_div_two hy₁ hxβ‚‚ h) (by rw hxy; exact lt_irrefl _) end /-- Inverse of the `tan` function, returns values in the range `-Ο€ / 2 < arctan x` and `arctan x < Ο€ / 2` -/ noncomputable def arctan (x : ℝ) : ℝ := arcsin (x / sqrt (1 + x ^ 2)) lemma sin_arctan (x : ℝ) : sin (arctan x) = x / sqrt (1 + x ^ 2) := sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _)) lemma cos_arctan (x : ℝ) : cos (arctan x) = 1 / sqrt (1 + x ^ 2) := have h₁ : (0 : ℝ) < 1 + x ^ 2, from add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg _), have hβ‚‚ : (x / sqrt (1 + x ^ 2)) ^ 2 < 1, by rw [pow_two, ← abs_mul_self, _root_.abs_mul]; exact mul_lt_one_of_nonneg_of_lt_one_left (abs_nonneg _) (abs_div_sqrt_one_add_lt _) (le_of_lt (abs_div_sqrt_one_add_lt _)), by rw [arctan, cos_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _)), one_div, ← sqrt_inv, sqrt_inj (sub_nonneg.2 (le_of_lt hβ‚‚)) (inv_nonneg.2 (le_of_lt h₁)), div_pow, pow_two (sqrt _), mul_self_sqrt (le_of_lt h₁), ← mul_right_inj' (ne.symm (ne_of_lt h₁)), mul_sub, mul_div_cancel' _ (ne.symm (ne_of_lt h₁)), mul_inv_cancel (ne.symm (ne_of_lt h₁))]; simp lemma tan_arctan (x : ℝ) : tan (arctan x) = x := by rw [tan_eq_sin_div_cos, sin_arctan, cos_arctan, div_div_div_div_eq, mul_one, mul_div_assoc, div_self (mt sqrt_eq_zero'.1 (not_le_of_gt (add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg x)))), mul_one] lemma arctan_lt_pi_div_two (x : ℝ) : arctan x < Ο€ / 2 := lt_of_le_of_ne (arcsin_le_pi_div_two _) (Ξ» h, ne_of_lt (div_sqrt_one_add_lt_one x) $ by rw [← sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _)), ← arctan, h, sin_pi_div_two]) lemma neg_pi_div_two_lt_arctan (x : ℝ) : -(Ο€ / 2) < arctan x := lt_of_le_of_ne (neg_pi_div_two_le_arcsin _) (Ξ» h, ne_of_lt (neg_one_lt_div_sqrt_one_add x) $ by rw [← sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _)), ← arctan, ← h, sin_neg, sin_pi_div_two]) lemma arctan_mem_Ioo (x : ℝ) : arctan x ∈ Ioo (-(Ο€ / 2)) (Ο€ / 2) := ⟨neg_pi_div_two_lt_arctan x, arctan_lt_pi_div_two x⟩ lemma tan_surjective : function.surjective tan := function.right_inverse.surjective tan_arctan lemma arctan_tan {x : ℝ} (hx₁ : -(Ο€ / 2) < x) (hxβ‚‚ : x < Ο€ / 2) : arctan (tan x) = x := tan_inj_of_lt_of_lt_pi_div_two (neg_pi_div_two_lt_arctan _) (arctan_lt_pi_div_two _) hx₁ hxβ‚‚ (by rw tan_arctan) @[simp] lemma arctan_zero : arctan 0 = 0 := by simp [arctan] @[simp] lemma arctan_one : arctan 1 = Ο€ / 4 := begin refine tan_inj_of_lt_of_lt_pi_div_two (neg_pi_div_two_lt_arctan 1) (arctan_lt_pi_div_two 1) _ _ _; linarith [pi_pos, tan_arctan 1, tan_pi_div_four], end @[simp] lemma arctan_neg (x : ℝ) : arctan (-x) = - arctan x := by simp [arctan, neg_div] 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β‚‚]; exact le_sub_iff_add_le.1 (by rw sub_self; exact real.arcsin_nonpos (by rw [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β‚‚]; exact sub_lt_iff_lt_add.1 (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β‚‚]; exact lt_sub_iff_add_lt.2 (by rw neg_add_self; exact real.arcsin_pos (by rw [neg_im]; exact div_pos (neg_pos.2 (lt_of_not_ge hxβ‚‚)) (abs_pos.2 hx)) (by rw [← abs_neg x]; exact (abs_le.1 (abs_im_div_abs_le_one _)).2)) 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 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 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 open filter open_locale topological_space 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 /-! ### Continuity and differentiability of arctan The continuity of `arctan` is difficult to prove due to `arctan` being (indirectly) defined naively via `classical.some`. The proof therefore uses the general theorem that monotone functions are homeomorphisms: `homeomorph_of_strict_mono_continuous_Ioo`. We first prove that `tan` (restricted) is a homeomorphism whose inverse is definitionally equal to `arctan`. The fact that `arctan` is continuous is then derived from the fact that it is equal to a homeomorphism, and its differentiability is in turn derived from its continuity using `has_deriv_at.of_local_left_inverse`. -/ /-- The function `tan`, restricted to the open interval (-Ο€/2, Ο€/2), is a homeomorphism. The inverse function of that homeomorphism is definitionally equal to `arctan` via `homeomorph.change_inv`. -/ def tan_homeomorph : (Ioo (-(Ο€/2)) (Ο€/2)) β‰ƒβ‚œ ℝ := (homeomorph_of_strict_mono_continuous_Ioo tan (by linarith [pi_div_two_pos]) (Ξ» x y, tan_lt_tan_of_lt_of_lt_pi_div_two) continuous_on_tan_Ioo tendsto_tan_pi_div_two tendsto_tan_neg_pi_div_two).change_inv (Ξ» x, ⟨arctan x, arctan_mem_Ioo x⟩) tan_arctan lemma tan_homeomorph_inv_fun_eq_arctan : coe ∘ tan_homeomorph.inv_fun = arctan := rfl lemma continuous_arctan : continuous arctan := continuous_subtype_coe.comp tan_homeomorph.continuous_inv_fun lemma has_deriv_at_arctan (x : ℝ) : has_deriv_at arctan (1 / (1 + x^2)) x := begin have h1 : 0 < 1 + x^2 := by nlinarith, have h2 : cos (arctan x) β‰  0 := by { rw cos_arctan, exact ne_of_gt (one_div_pos.mpr (sqrt_pos.mpr h1)) }, simpa [(cos_arctan x), sqr_sqrt (le_of_lt h1)] using has_deriv_at.of_local_left_inverse continuous_arctan.continuous_at (has_deriv_at_tan h2) (one_div_ne_zero (pow_ne_zero 2 h2)) (by {apply eventually_of_forall, exact tan_arctan} ), end lemma differentiable_at_arctan (x : ℝ) : differentiable_at ℝ arctan x := (has_deriv_at_arctan x).differentiable_at @[simp] lemma deriv_arctan : deriv arctan = (Ξ» x, 1 / (1 + x^2)) := funext $ Ξ» x, (has_deriv_at_arctan x).deriv end real section /-! Register lemmas for the derivatives of the composition of `real.arctan` with a differentiable function, for standalone use and use with `simp`. -/ variables {f : ℝ β†’ ℝ} {f' x : ℝ} {s : set ℝ} lemma has_deriv_at.arctan (hf : has_deriv_at f f' x) : has_deriv_at (Ξ» x, real.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, real.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 differentiable_within_at.arctan (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (Ξ» x, real.arctan (f x)) s x := hf.has_deriv_within_at.arctan.differentiable_within_at @[simp] lemma differentiable_at.arctan (hc : differentiable_at ℝ f x) : differentiable_at ℝ (Ξ» x, real.arctan (f x)) x := hc.has_deriv_at.arctan.differentiable_at lemma differentiable_on.arctan (hc : differentiable_on ℝ f s) : differentiable_on ℝ (Ξ» x, real.arctan (f x)) s := Ξ» x h, (hc x h).arctan @[simp] lemma differentiable.arctan (hc : differentiable ℝ f) : differentiable ℝ (Ξ» x, real.arctan (f x)) := Ξ» x, (hc x).arctan lemma deriv_within_arctan (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (Ξ» x, real.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, real.arctan (f x)) x = (1 / (1 + (f x)^2)) * (deriv f x) := hc.has_deriv_at.arctan.deriv end
ddcd90f5b5fa274dbc5bef79336f9c2e07ec0a1e
9338c56dfd6ceacc3e5e63e32a7918cfec5d5c69
/src/spectrum_of_a_ring/structure_presheaf_stalks.lean
59963cc663aeaaac49b3c877a28f960b44bf971a
[]
no_license
Project-Reykjavik/lean-scheme
7322eefce504898ba33737970be89dc751108e2b
6d3ec18fecfd174b79d0ce5c85a783f326dd50f6
refs/heads/master
1,669,426,172,632
1,578,284,588,000
1,578,284,588,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
4,701
lean
/- The stalks of the structure presheaf on the basis are local rings. -/ import ring_theory.ideals import ring_theory.localization import to_mathlib.localization.local_rings import to_mathlib.localization.localization_alt import sheaves.stalk_of_rings_on_standard_basis import spectrum_of_a_ring.structure_presheaf import spectrum_of_a_ring.structure_presheaf_localization import spectrum_of_a_ring.structure_presheaf_res universe u variables {R : Type u} [comm_ring R] variables (P : Spec R) open localization localization_alt stalk_of_rings_on_standard_basis open classical def Bstd := D_fs_standard_basis R namespace strucutre_presheaf_stalks def F := structure_presheaf_on_basis R def FP := stalk_of_rings_on_standard_basis Bstd F P -- This is essentially the map from x to x/1. def Ο† : R β†’ FP P := Ξ» x, ⟦{ U := opens.univ, BU := (D_fs_standard_basis R).1, Hx := set.mem_univ P, s := (of : R β†’ localization R (S (opens.univ))) x, }⟧ instance FP.is_comm_ring : comm_ring (FP P) := by simp [FP]; by apply_instance instance prime.is_submonoid : is_submonoid (-P.1 : set R) := { one_mem := P.1.ne_top_iff_one.1 P.2.1, mul_mem := Ξ» x y hnx hny hxy, or.cases_on (P.2.2 hxy) hnx hny } instance Ο†P.is_ring_hom : is_ring_hom (Ο† P) := { map_one := rfl, map_mul := Ξ» x y, begin apply quotient.sound, use [opens.univ, (D_fs_standard_basis R).1, set.mem_univ P], use [set.subset.refl _, (Ξ» x Hx, ⟨Hx, Hx⟩)], rw (F.res_is_ring_hom _ _ _).map_mul, rw ←presheaf_on_basis.Hcomp', rw ←presheaf_on_basis.Hcomp', rw of.is_ring_hom.map_mul, rw (F.res_is_ring_hom _ _ _).map_mul, end, map_add := Ξ» x y, begin apply quotient.sound, use [opens.univ, (D_fs_standard_basis R).1, set.mem_univ P], use [set.subset.refl _, (Ξ» x Hx, ⟨Hx, Hx⟩)], rw (F.res_is_ring_hom _ _ _).map_add, rw ←presheaf_on_basis.Hcomp', rw ←presheaf_on_basis.Hcomp', rw of.is_ring_hom.map_add, rw (F.res_is_ring_hom _ _ _).map_add, end, } lemma stalk_local.inverts_data : inverts_data (-P.1 : set R) (Ο† P) := begin rintros ⟨s, Hs⟩, change s βˆ‰ P.val at Hs, let BDs := D_fs.mem R s, have HsS : s ∈ S (Spec.DO R s) := S.f_mem s, let sinv : FP P := ⟦{ U := Spec.DO R s, BU := BDs, Hx := Hs, s := ⟦⟨1, ⟨s, HsS⟩⟩⟧, }⟧, use sinv, apply quotient.sound, use [Spec.DO R s, BDs, Hs, (Ξ» x Hx, ⟨trivial, Hx⟩), set.subset_univ _], simp, erw (F.res_is_ring_hom _ _ _).map_mul, erw (F.res_is_ring_hom _ _ _).map_one, iterate 2 { rw ←presheaf_on_basis.Hcomp', }, erw presheaf_on_basis.Hid', erw structure_presheaf_on_basis.res_eq, erw ←structure_presheaf_on_basis.res_comp_of', apply quotient.sound, use [1, is_submonoid.one_mem _], simp, end lemma stalk_local.has_denom : has_denom (-P.1 : set R) (Ο† P) := begin intros x, apply quotient.induction_on x, rintros ⟨U, BU, HPU, s⟩, -- s ∈ R[1/S(U)]. apply quotient.induction_on s, rintros ⟨p, ⟨q, Hq⟩⟩, change U βŠ† Spec.DO R q at Hq, -- Since P ∈ D(q). have HqnP : q βˆ‰ P.val := Hq HPU, use [⟨⟨q, HqnP⟩, p⟩], apply quotient.sound, use [U, BU, HPU, (Ξ» x Hx, ⟨trivial, Hx⟩), set.subset_univ _], simp, erw (F.res_is_ring_hom _ _ _).map_mul, iterate 2 { rw ←presheaf_on_basis.Hcomp', }, erw presheaf_on_basis.Hid', erw structure_presheaf_on_basis.res_eq, iterate 2 { erw ←structure_presheaf_on_basis.res_comp_of', }, apply quotient.sound, use [1, is_submonoid.one_mem _], simp, end noncomputable def stalk_local.has_denom_data : has_denom_data (-P.1 : set R) (Ο† P) := has_denom_some (-P.1 : set R) (Ο† P) (stalk_local.has_denom P) lemma stalk_local.ker_le : ker (Ο† P) ≀ submonoid_ann (-P.1 : set R) := begin intros x Hx, change Ο† P x = 0 at Hx, erw quotient.eq at Hx, rcases Hx with ⟨W, BW, HPW, HWuniv1, HWuniv2, Hres⟩, dsimp at Hres, erw is_ring_hom.map_zero (F.res (D_fs_standard_basis R).1 BW HWuniv2) at Hres, erw structure_presheaf_on_basis.res_eq at Hres, erw ←structure_presheaf_on_basis.res_comp_of' at Hres, erw quotient.eq at Hres, rcases Hres with ⟨t, HtSW, Ht⟩, simp at Ht, have HtnP : t βˆ‰ P.val := HtSW HPW, use ⟨⟨x, ⟨t, HtnP⟩⟩, Ht⟩, end noncomputable def stalk_local.localization : is_localization_data (-P.1 : set R) (Ο† P) := { inverts := stalk_local.inverts_data P, has_denom := stalk_local.has_denom_data P, ker_le := stalk_local.ker_le P, } lemma stalk_local : is_local_ring (FP P) := local_ring.of_is_localization_data_at_prime P.2 (stalk_local.localization P) end strucutre_presheaf_stalks
bb849a1d9b8c2bf550f8156549cb5ff31750e793
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/linear_algebra/matrix/special_linear_group.lean
1fcb0587bf39847c60bed42bfce5faf45dcf8bde
[ "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
12,015
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 linear_algebra.general_linear_group import linear_algebra.matrix.adjugate import linear_algebra.matrix.to_lin /-! # The Special Linear group $SL(n, R)$ > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines the elements of the Special Linear group `special_linear_group n R`, consisting of all square `R`-matrices with determinant `1` on the fintype `n` by `n`. In addition, we define the group structure on `special_linear_group n R` and the embedding into the general linear group `general_linear_group R (n β†’ R)`. ## Main definitions * `matrix.special_linear_group` is the type of matrices with determinant 1 * `matrix.special_linear_group.group` gives the group structure (under multiplication) * `matrix.special_linear_group.to_GL` is the embedding `SLβ‚™(R) β†’ GLβ‚™(R)` ## Notation For `m : β„•`, we introduce the notation `SL(m,R)` for the special linear group on the fintype `n = fin m`, in the locale `matrix_groups`. ## Implementation notes The inverse operation in the `special_linear_group` is defined to be the adjugate matrix, so that `special_linear_group n R` has a group structure for all `comm_ring R`. We define the elements of `special_linear_group` to be matrices, since we need to compute their determinant. This is in contrast with `general_linear_group R M`, which consists of invertible `R`-linear maps on `M`. We provide `matrix.special_linear_group.has_coe_to_fun` for convenience, but do not state any lemmas about it, and use `matrix.special_linear_group.coe_fn_eq_coe` to eliminate it `⇑` in favor of a regular `↑` coercion. ## References * https://en.wikipedia.org/wiki/Special_linear_group ## Tags matrix group, group, matrix inverse -/ namespace matrix universes u v open_locale matrix open linear_map section variables (n : Type u) [decidable_eq n] [fintype n] (R : Type v) [comm_ring R] /-- `special_linear_group n R` is the group of `n` by `n` `R`-matrices with determinant equal to 1. -/ def special_linear_group := { A : matrix n n R // A.det = 1 } end localized "notation (name := special_linear_group.fin) `SL(`n`, `R`)`:= matrix.special_linear_group (fin n) R" in matrix_groups namespace special_linear_group variables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [comm_ring R] instance has_coe_to_matrix : has_coe (special_linear_group n R) (matrix n n R) := ⟨λ A, A.val⟩ /- In this file, Lean often has a hard time working out the values of `n` and `R` for an expression like `det ↑A`. Rather than writing `(A : matrix n n R)` everywhere in this file which is annoyingly verbose, or `A.val` which is not the simp-normal form for subtypes, we create a local notation `β†‘β‚˜A`. This notation references the local `n` and `R` variables, so is not valid as a global notation. -/ local prefix `β†‘β‚˜`:1024 := @coe _ (matrix n n R) _ lemma ext_iff (A B : special_linear_group n R) : A = B ↔ (βˆ€ i j, β†‘β‚˜A i j = β†‘β‚˜B i j) := subtype.ext_iff.trans matrix.ext_iff.symm @[ext] lemma ext (A B : special_linear_group n R) : (βˆ€ i j, β†‘β‚˜A i j = β†‘β‚˜B i j) β†’ A = B := (special_linear_group.ext_iff A B).mpr instance has_inv : has_inv (special_linear_group n R) := ⟨λ A, ⟨adjugate A, by rw [det_adjugate, A.prop, one_pow]⟩⟩ instance has_mul : has_mul (special_linear_group n R) := ⟨λ A B, ⟨A.1 ⬝ B.1, by erw [det_mul, A.2, B.2, one_mul]⟩⟩ instance has_one : has_one (special_linear_group n R) := ⟨⟨1, det_one⟩⟩ instance : has_pow (special_linear_group n R) β„• := { pow := Ξ» x n, ⟨x ^ n, (det_pow _ _).trans $ x.prop.symm β–Έ one_pow _⟩} instance : inhabited (special_linear_group n R) := ⟨1⟩ section coe_lemmas variables (A B : special_linear_group n R) @[simp] lemma coe_mk (A : matrix n n R) (h : det A = 1) : ↑(⟨A, h⟩ : special_linear_group n R) = A := rfl @[simp] lemma coe_inv : β†‘β‚˜(A⁻¹) = adjugate A := rfl @[simp] lemma coe_mul : β†‘β‚˜(A * B) = β†‘β‚˜A ⬝ β†‘β‚˜B := rfl @[simp] lemma coe_one : β†‘β‚˜(1 : special_linear_group n R) = (1 : matrix n n R) := rfl @[simp] lemma det_coe : det β†‘β‚˜A = 1 := A.2 @[simp] lemma coe_pow (m : β„•) : β†‘β‚˜(A ^ m) = β†‘β‚˜A ^ m := rfl lemma det_ne_zero [nontrivial R] (g : special_linear_group n R) : det β†‘β‚˜g β‰  0 := by { rw g.det_coe, norm_num } lemma row_ne_zero [nontrivial R] (g : special_linear_group n R) (i : n): β†‘β‚˜g i β‰  0 := Ξ» h, g.det_ne_zero $ det_eq_zero_of_row_eq_zero i $ by simp [h] end coe_lemmas instance : monoid (special_linear_group n R) := function.injective.monoid coe subtype.coe_injective coe_one coe_mul coe_pow instance : group (special_linear_group n R) := { mul_left_inv := Ξ» A, by { ext1, simp [adjugate_mul] }, ..special_linear_group.monoid, ..special_linear_group.has_inv } /-- A version of `matrix.to_lin' A` that produces linear equivalences. -/ def to_lin' : special_linear_group n R β†’* (n β†’ R) ≃ₗ[R] (n β†’ R) := { to_fun := Ξ» A, linear_equiv.of_linear (matrix.to_lin' β†‘β‚˜A) (matrix.to_lin' β†‘β‚˜(A⁻¹)) (by rw [←to_lin'_mul, ←coe_mul, mul_right_inv, coe_one, to_lin'_one]) (by rw [←to_lin'_mul, ←coe_mul, mul_left_inv, coe_one, to_lin'_one]), map_one' := linear_equiv.to_linear_map_injective matrix.to_lin'_one, map_mul' := Ξ» A B, linear_equiv.to_linear_map_injective $ matrix.to_lin'_mul A B } lemma to_lin'_apply (A : special_linear_group n R) (v : n β†’ R) : special_linear_group.to_lin' A v = matrix.to_lin' β†‘β‚˜A v := rfl lemma to_lin'_to_linear_map (A : special_linear_group n R) : ↑(special_linear_group.to_lin' A) = matrix.to_lin' β†‘β‚˜A := rfl lemma to_lin'_symm_apply (A : special_linear_group n R) (v : n β†’ R) : A.to_lin'.symm v = matrix.to_lin' β†‘β‚˜(A⁻¹) v := rfl lemma to_lin'_symm_to_linear_map (A : special_linear_group n R) : ↑(A.to_lin'.symm) = matrix.to_lin' β†‘β‚˜(A⁻¹) := rfl lemma to_lin'_injective : function.injective ⇑(to_lin' : special_linear_group n R β†’* (n β†’ R) ≃ₗ[R] (n β†’ R)) := Ξ» A B h, subtype.coe_injective $ matrix.to_lin'.injective $ linear_equiv.to_linear_map_injective.eq_iff.mpr h /-- `to_GL` is the map from the special linear group to the general linear group -/ def to_GL : special_linear_group n R β†’* general_linear_group R (n β†’ R) := (general_linear_group.general_linear_equiv _ _).symm.to_monoid_hom.comp to_lin' lemma coe_to_GL (A : special_linear_group n R) : ↑A.to_GL = A.to_lin'.to_linear_map := rfl variables {S : Type*} [comm_ring S] /-- A ring homomorphism from `R` to `S` induces a group homomorphism from `special_linear_group n R` to `special_linear_group n S`. -/ @[simps] def map (f : R β†’+* S) : special_linear_group n R β†’* special_linear_group n S := { to_fun := Ξ» g, ⟨f.map_matrix ↑g, by { rw ← f.map_det, simp [g.2] }⟩, map_one' := subtype.ext $ f.map_matrix.map_one, map_mul' := Ξ» x y, subtype.ext $ f.map_matrix.map_mul x y } section cast /-- Coercion of SL `n` `β„€` to SL `n` `R` for a commutative ring `R`. -/ instance : has_coe (special_linear_group n β„€) (special_linear_group n R) := ⟨λ x, map (int.cast_ring_hom R) x⟩ @[simp] lemma coe_matrix_coe (g : special_linear_group n β„€) : ↑(g : special_linear_group n R) = (↑g : matrix n n β„€).map (int.cast_ring_hom R) := map_apply_coe (int.cast_ring_hom R) g end cast section has_neg variables [fact (even (fintype.card n))] /-- Formal operation of negation on special linear group on even cardinality `n` given by negating each element. -/ instance : has_neg (special_linear_group n R) := ⟨λ g, ⟨- g, by simpa [(fact.out $ even $ fintype.card n).neg_one_pow, g.det_coe] using det_smul β†‘β‚˜g (-1)⟩⟩ @[simp] lemma coe_neg (g : special_linear_group n R) : ↑(- g) = - (g : matrix n n R) := rfl instance : has_distrib_neg (special_linear_group n R) := function.injective.has_distrib_neg _ subtype.coe_injective coe_neg coe_mul @[simp] lemma coe_int_neg (g : special_linear_group n β„€) : ↑(-g) = (-↑g : special_linear_group n R) := subtype.ext $ (@ring_hom.map_matrix n _ _ _ _ _ _ (int.cast_ring_hom R)).map_neg ↑g end has_neg section special_cases lemma SL2_inv_expl_det (A : SL(2,R)) : det ![![A.1 1 1, -A.1 0 1], ![-A.1 1 0 , A.1 0 0]] = 1 := begin rw [matrix.det_fin_two, mul_comm], simp only [subtype.val_eq_coe, cons_val_zero, cons_val_one, head_cons, mul_neg, neg_mul, neg_neg], have := A.2, rw matrix.det_fin_two at this, convert this, end lemma SL2_inv_expl (A : SL(2, R)) : A⁻¹ = ⟨![![A.1 1 1, -A.1 0 1], ![-A.1 1 0 , A.1 0 0]], SL2_inv_expl_det A⟩ := begin ext, have := matrix.adjugate_fin_two A.1, simp only [subtype.val_eq_coe] at this, rw [coe_inv, this], refl, end lemma fin_two_induction (P : SL(2, R) β†’ Prop) (h : βˆ€ (a b c d : R) (hdet : a * d - b * c = 1), P ⟨!![a, b; c, d], by rwa [det_fin_two_of]⟩) (g : SL(2, R)) : P g := begin obtain ⟨m, hm⟩ := g, convert h (m 0 0) (m 0 1) (m 1 0) (m 1 1) (by rwa det_fin_two at hm), ext i j, fin_cases i; fin_cases j; refl, end lemma fin_two_exists_eq_mk_of_apply_zero_one_eq_zero {R : Type*} [field R] (g : SL(2, R)) (hg : (g : matrix (fin 2) (fin 2) R) 1 0 = 0) : βˆƒ (a b : R) (h : a β‰  0), g = (⟨!![a, b; 0, a⁻¹], by simp [h]⟩ : SL(2, R)) := begin induction g using matrix.special_linear_group.fin_two_induction with a b c d h_det, replace hg : c = 0 := by simpa using hg, have had : a * d = 1 := by rwa [hg, mul_zero, sub_zero] at h_det, refine ⟨a, b, left_ne_zero_of_mul_eq_one had, _⟩, simp_rw [eq_inv_of_mul_eq_one_right had, hg], end end special_cases -- this section should be last to ensure we do not use it in lemmas section coe_fn_instance /-- This instance is here for convenience, but is not the simp-normal form. -/ instance : has_coe_to_fun (special_linear_group n R) (Ξ» _, n β†’ n β†’ R) := { coe := Ξ» A, A.val } @[simp] lemma coe_fn_eq_coe (s : special_linear_group n R) : ⇑s = β†‘β‚˜s := rfl end coe_fn_instance end special_linear_group end matrix namespace modular_group open_locale matrix_groups open matrix matrix.special_linear_group local prefix `β†‘β‚˜`:1024 := @coe _ (matrix (fin 2) (fin 2) β„€) _ /-- The matrix `S = [[0, -1], [1, 0]]` as an element of `SL(2, β„€)`. This element acts naturally on the Euclidean plane as a rotation about the origin by `Ο€ / 2`. This element also acts naturally on the hyperbolic plane as rotation about `i` by `Ο€`. It represents the MobiΓΌs transformation `z ↦ -1/z` and is an involutive elliptic isometry. -/ def S : SL(2, β„€) := ⟨!![0, -1; 1, 0], by norm_num [matrix.det_fin_two_of]⟩ /-- The matrix `T = [[1, 1], [0, 1]]` as an element of `SL(2, β„€)` -/ def T : SL(2, β„€) := ⟨!![1, 1; 0, 1], by norm_num [matrix.det_fin_two_of]⟩ lemma coe_S : β†‘β‚˜S = !![0, -1; 1, 0] := rfl lemma coe_T : β†‘β‚˜T = !![1, 1; 0, 1] := rfl lemma coe_T_inv : β†‘β‚˜(T⁻¹) = !![1, -1; 0, 1] := by simp [coe_inv, coe_T, adjugate_fin_two] lemma coe_T_zpow (n : β„€) : β†‘β‚˜(T ^ n) = !![1, n; 0, 1] := begin induction n using int.induction_on with n h n h, { rw [zpow_zero, coe_one, matrix.one_fin_two] }, { simp_rw [zpow_add, zpow_one, coe_mul, h, coe_T, matrix.mul_fin_two], congrm !![_, _; _, _], rw [mul_one, mul_one, add_comm] }, { simp_rw [zpow_sub, zpow_one, coe_mul, h, coe_T_inv, matrix.mul_fin_two], congrm !![_, _; _, _]; ring }, end @[simp] lemma T_pow_mul_apply_one (n : β„€) (g : SL(2, β„€)) : β†‘β‚˜(T ^ n * g) 1 = β†‘β‚˜g 1 := by simp [coe_T_zpow, matrix.mul, matrix.dot_product, fin.sum_univ_succ] @[simp] lemma T_mul_apply_one (g : SL(2, β„€)) : β†‘β‚˜(T * g) 1 = β†‘β‚˜g 1 := by simpa using T_pow_mul_apply_one 1 g @[simp] lemma T_inv_mul_apply_one (g : SL(2, β„€)) : β†‘β‚˜(T⁻¹ * g) 1 = β†‘β‚˜g 1 := by simpa using T_pow_mul_apply_one (-1) g end modular_group
7c09d700b3f19d2e980be647d29f218c81bb5d46
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/tactic/omega/nat/form.lean
ec0fce316a43e73177cee2f7513dee7b482dbe71
[ "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
4,406
lean
/- Copyright (c) 2019 Seul Baek. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Seul Baek Linear natural number arithmetic formulas in pre-normalized form. -/ import tactic.omega.nat.preterm namespace omega namespace nat @[derive has_reflect] inductive form | eq : preterm β†’ preterm β†’ form | le : preterm β†’ preterm β†’ form | not : form β†’ form | or : form β†’ form β†’ form | and : form β†’ form β†’ form local notation x ` =* ` y := form.eq x y local notation x ` ≀* ` y := form.le x y local notation `Β¬* ` p := form.not p local notation p ` ∨* ` q := form.or p q local notation p ` ∧* ` q := form.and p q namespace form @[simp] def holds (v : nat β†’ nat) : form β†’ Prop | (t =* s) := t.val v = s.val v | (t ≀* s) := t.val v ≀ s.val v | (Β¬* p) := Β¬ p.holds | (p ∨* q) := p.holds ∨ q.holds | (p ∧* q) := p.holds ∧ q.holds end form @[simp] def univ_close (p : form) : (nat β†’ nat) β†’ nat β†’ Prop | v 0 := p.holds v | v (k+1) := βˆ€ i : nat, univ_close (update_zero i v) k namespace form def neg_free : form β†’ Prop | (t =* s) := true | (t ≀* s) := true | (p ∨* q) := neg_free p ∧ neg_free q | (p ∧* q) := neg_free p ∧ neg_free q | _ := false def sub_free : form β†’ Prop | (t =* s) := t.sub_free ∧ s.sub_free | (t ≀* s) := t.sub_free ∧ s.sub_free | (Β¬* p) := p.sub_free | (p ∨* q) := p.sub_free ∧ q.sub_free | (p ∧* q) := p.sub_free ∧ q.sub_free def fresh_index : form β†’ nat | (t =* s) := max t.fresh_index s.fresh_index | (t ≀* s) := max t.fresh_index s.fresh_index | (Β¬* p) := p.fresh_index | (p ∨* q) := max p.fresh_index q.fresh_index | (p ∧* q) := max p.fresh_index q.fresh_index def holds_constant {v w : nat β†’ nat} : βˆ€ p : form, ( (βˆ€ x < p.fresh_index, v x = w x) β†’ (p.holds v ↔ p.holds w) ) | (t =* s) h1 := begin simp only [holds], apply pred_mono_2; apply preterm.val_constant; intros x h2; apply h1 _ (lt_of_lt_of_le h2 _), apply le_max_left, apply le_max_right end | (t ≀* s) h1 := begin simp only [holds], apply pred_mono_2; apply preterm.val_constant; intros x h2; apply h1 _ (lt_of_lt_of_le h2 _), apply le_max_left, apply le_max_right end | (Β¬* p) h1 := begin apply not_iff_not_of_iff, apply holds_constant p h1 end | (p ∨* q) h1 := begin simp only [holds], apply pred_mono_2'; apply holds_constant; intros x h2; apply h1 _ (lt_of_lt_of_le h2 _), apply le_max_left, apply le_max_right end | (p ∧* q) h1 := begin simp only [holds], apply pred_mono_2'; apply holds_constant; intros x h2; apply h1 _ (lt_of_lt_of_le h2 _), apply le_max_left, apply le_max_right end def valid (p : form) : Prop := βˆ€ v, holds v p def sat (p : form) : Prop := βˆƒ v, holds v p def implies (p q : form) : Prop := βˆ€ v, (holds v p β†’ holds v q) def equiv (p q : form) : Prop := βˆ€ v, (holds v p ↔ holds v q) lemma sat_of_implies_of_sat {p q : form} : implies p q β†’ sat p β†’ sat q := begin intros h1 h2, apply exists_imp_exists h1 h2 end lemma sat_or {p q : form} : sat (p ∨* q) ↔ sat p ∨ sat q := begin constructor; intro h1, { cases h1 with v h1, cases h1 with h1 h1; [left,right]; refine ⟨v,_⟩; assumption }, { cases h1 with h1 h1; cases h1 with v h1; refine ⟨v,_⟩; [left,right]; assumption } end def unsat (p : form) : Prop := Β¬ sat p def repr : form β†’ string | (t =* s) := "(" ++ t.repr ++ " = " ++ s.repr ++ ")" | (t ≀* s) := "(" ++ t.repr ++ " ≀ " ++ s.repr ++ ")" | (Β¬* p) := "Β¬" ++ p.repr | (p ∨* q) := "(" ++ p.repr ++ " ∨ " ++ q.repr ++ ")" | (p ∧* q) := "(" ++ p.repr ++ " ∧ " ++ q.repr ++ ")" instance has_repr : has_repr form := ⟨repr⟩ meta instance has_to_format : has_to_format form := ⟨λ x, x.repr⟩ end form lemma univ_close_of_valid {p : form} : βˆ€ {m : nat} {v : nat β†’ nat}, p.valid β†’ univ_close p v m | 0 v h1 := h1 _ | (m+1) v h1 := Ξ» i, univ_close_of_valid h1 lemma valid_of_unsat_not {p : form} : (Β¬*p).unsat β†’ p.valid := begin simp only [form.sat, form.unsat, form.valid, form.holds], rw classical.not_exists_not, intro h, assumption end meta def form.induce (t : tactic unit := tactic.skip) : tactic unit := `[ intro p, induction p with t s t s p ih p q ihp ihq p q ihp ihq; t ] end nat end omega
97ad998c27dd3a025f904f32d2ec6816e113aeea
5d166a16ae129621cb54ca9dde86c275d7d2b483
/tests/lean/run/apply4.lean
a9e8e461d7721d6ce3f0b953d2b8b2537bf4d2f2
[ "Apache-2.0" ]
permissive
jcarlson23/lean
b00098763291397e0ac76b37a2dd96bc013bd247
8de88701247f54d325edd46c0eed57aeacb64baf
refs/heads/master
1,611,571,813,719
1,497,020,963,000
1,497,021,515,000
93,882,536
1
0
null
1,497,029,896,000
1,497,029,896,000
null
UTF-8
Lean
false
false
1,057
lean
open tactic bool universe variables u constant foo {A : Type u} [inhabited A] (a b : A) : a = default A β†’ a = b example (a b : nat) : a = 0 β†’ a = b := by do intro `H, apply (expr.const `foo [level.of_nat 0]), trace_state, assumption definition ex : inhabited (nat Γ— nat Γ— bool) := by apply_instance set_option pp.all true #print ex set_option pp.all false example (a b : nat) : a = 0 β†’ a = b := by do intro `H, apply_core (expr.const `foo [level.of_nat 0]) {approx := ff, all := tt, use_instances := ff }, trace_state, a ← get_local `a, trace_state, mk_app `inhabited.mk [a] >>= exact, trace "--------", trace_state, reflexivity #print "----------------" set_option pp.all true example (a b : nat) : a = 0 β†’ a = b := by do intro `H, foo ← mk_const `foo, trace foo, apply foo, trace_state, assumption example (a b : nat) : a = 0 β†’ a = b := by do `[intro], apply_core (expr.const `foo [level.of_nat 0]) {approx := ff, all := tt, use_instances := ff}, `[exact inhabited.mk a], reflexivity
3fc5a3b2de8eacf33eac5b67e6e0c07e4ac9ff93
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/analysis/complex/re_im_topology.lean
e86d1e2b077d3367fb3e0b0057b3e52d714f3cd4
[ "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
7,840
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.complex.basic import topology.fiber_bundle.is_homeomorphic_trivial_bundle /-! # Closure, interior, and frontier of preimages under `re` and `im` > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. In this fact we use the fact that `β„‚` is naturally homeomorphic to `ℝ Γ— ℝ` to deduce some topological properties of `complex.re` and `complex.im`. ## Main statements Each statement about `complex.re` listed below has a counterpart about `complex.im`. * `complex.is_homeomorphic_trivial_fiber_bundle_re`: `complex.re` turns `β„‚` into a trivial topological fiber bundle over `ℝ`; * `complex.is_open_map_re`, `complex.quotient_map_re`: in particular, `complex.re` is an open map and is a quotient map; * `complex.interior_preimage_re`, `complex.closure_preimage_re`, `complex.frontier_preimage_re`: formulas for `interior (complex.re ⁻¹' s)` etc; * `complex.interior_set_of_re_le` etc: particular cases of the above formulas in the cases when `s` is one of the infinite intervals `set.Ioi a`, `set.Ici a`, `set.Iio a`, and `set.Iic a`, formulated as `interior {z : β„‚ | z.re ≀ a} = {z | z.re < a}` etc. ## Tags complex, real part, imaginary part, closure, interior, frontier -/ open set noncomputable theory namespace complex /-- `complex.re` turns `β„‚` into a trivial topological fiber bundle over `ℝ`. -/ lemma is_homeomorphic_trivial_fiber_bundle_re : is_homeomorphic_trivial_fiber_bundle ℝ re := ⟨equiv_real_prod_clm.to_homeomorph, Ξ» z, rfl⟩ /-- `complex.im` turns `β„‚` into a trivial topological fiber bundle over `ℝ`. -/ lemma is_homeomorphic_trivial_fiber_bundle_im : is_homeomorphic_trivial_fiber_bundle ℝ im := ⟨equiv_real_prod_clm.to_homeomorph.trans (homeomorph.prod_comm ℝ ℝ), Ξ» z, rfl⟩ lemma is_open_map_re : is_open_map re := is_homeomorphic_trivial_fiber_bundle_re.is_open_map_proj lemma is_open_map_im : is_open_map im := is_homeomorphic_trivial_fiber_bundle_im.is_open_map_proj lemma quotient_map_re : quotient_map re := is_homeomorphic_trivial_fiber_bundle_re.quotient_map_proj lemma quotient_map_im : quotient_map im := is_homeomorphic_trivial_fiber_bundle_im.quotient_map_proj lemma interior_preimage_re (s : set ℝ) : interior (re ⁻¹' s) = re ⁻¹' (interior s) := (is_open_map_re.preimage_interior_eq_interior_preimage continuous_re _).symm lemma interior_preimage_im (s : set ℝ) : interior (im ⁻¹' s) = im ⁻¹' (interior s) := (is_open_map_im.preimage_interior_eq_interior_preimage continuous_im _).symm lemma closure_preimage_re (s : set ℝ) : closure (re ⁻¹' s) = re ⁻¹' (closure s) := (is_open_map_re.preimage_closure_eq_closure_preimage continuous_re _).symm lemma closure_preimage_im (s : set ℝ) : closure (im ⁻¹' s) = im ⁻¹' (closure s) := (is_open_map_im.preimage_closure_eq_closure_preimage continuous_im _).symm lemma frontier_preimage_re (s : set ℝ) : frontier (re ⁻¹' s) = re ⁻¹' (frontier s) := (is_open_map_re.preimage_frontier_eq_frontier_preimage continuous_re _).symm lemma frontier_preimage_im (s : set ℝ) : frontier (im ⁻¹' s) = im ⁻¹' (frontier s) := (is_open_map_im.preimage_frontier_eq_frontier_preimage continuous_im _).symm @[simp] lemma interior_set_of_re_le (a : ℝ) : interior {z : β„‚ | z.re ≀ a} = {z | z.re < a} := by simpa only [interior_Iic] using interior_preimage_re (Iic a) @[simp] lemma interior_set_of_im_le (a : ℝ) : interior {z : β„‚ | z.im ≀ a} = {z | z.im < a} := by simpa only [interior_Iic] using interior_preimage_im (Iic a) @[simp] lemma interior_set_of_le_re (a : ℝ) : interior {z : β„‚ | a ≀ z.re} = {z | a < z.re} := by simpa only [interior_Ici] using interior_preimage_re (Ici a) @[simp] lemma interior_set_of_le_im (a : ℝ) : interior {z : β„‚ | a ≀ z.im} = {z | a < z.im} := by simpa only [interior_Ici] using interior_preimage_im (Ici a) @[simp] lemma closure_set_of_re_lt (a : ℝ) : closure {z : β„‚ | z.re < a} = {z | z.re ≀ a} := by simpa only [closure_Iio] using closure_preimage_re (Iio a) @[simp] lemma closure_set_of_im_lt (a : ℝ) : closure {z : β„‚ | z.im < a} = {z | z.im ≀ a} := by simpa only [closure_Iio] using closure_preimage_im (Iio a) @[simp] lemma closure_set_of_lt_re (a : ℝ) : closure {z : β„‚ | a < z.re} = {z | a ≀ z.re} := by simpa only [closure_Ioi] using closure_preimage_re (Ioi a) @[simp] lemma closure_set_of_lt_im (a : ℝ) : closure {z : β„‚ | a < z.im} = {z | a ≀ z.im} := by simpa only [closure_Ioi] using closure_preimage_im (Ioi a) @[simp] lemma frontier_set_of_re_le (a : ℝ) : frontier {z : β„‚ | z.re ≀ a} = {z | z.re = a} := by simpa only [frontier_Iic] using frontier_preimage_re (Iic a) @[simp] lemma frontier_set_of_im_le (a : ℝ) : frontier {z : β„‚ | z.im ≀ a} = {z | z.im = a} := by simpa only [frontier_Iic] using frontier_preimage_im (Iic a) @[simp] lemma frontier_set_of_le_re (a : ℝ) : frontier {z : β„‚ | a ≀ z.re} = {z | z.re = a} := by simpa only [frontier_Ici] using frontier_preimage_re (Ici a) @[simp] lemma frontier_set_of_le_im (a : ℝ) : frontier {z : β„‚ | a ≀ z.im} = {z | z.im = a} := by simpa only [frontier_Ici] using frontier_preimage_im (Ici a) @[simp] lemma frontier_set_of_re_lt (a : ℝ) : frontier {z : β„‚ | z.re < a} = {z | z.re = a} := by simpa only [frontier_Iio] using frontier_preimage_re (Iio a) @[simp] lemma frontier_set_of_im_lt (a : ℝ) : frontier {z : β„‚ | z.im < a} = {z | z.im = a} := by simpa only [frontier_Iio] using frontier_preimage_im (Iio a) @[simp] lemma frontier_set_of_lt_re (a : ℝ) : frontier {z : β„‚ | a < z.re} = {z | z.re = a} := by simpa only [frontier_Ioi] using frontier_preimage_re (Ioi a) @[simp] lemma frontier_set_of_lt_im (a : ℝ) : frontier {z : β„‚ | a < z.im} = {z | z.im = a} := by simpa only [frontier_Ioi] using frontier_preimage_im (Ioi a) lemma closure_re_prod_im (s t : set ℝ) : closure (s Γ—β„‚ t) = closure s Γ—β„‚ closure t := by simpa only [← preimage_eq_preimage equiv_real_prod_clm.symm.to_homeomorph.surjective, equiv_real_prod_clm.symm.to_homeomorph.preimage_closure] using @closure_prod_eq _ _ _ _ s t lemma interior_re_prod_im (s t : set ℝ) : interior (s Γ—β„‚ t) = interior s Γ—β„‚ interior t := by rw [re_prod_im, re_prod_im, interior_inter, interior_preimage_re, interior_preimage_im] lemma frontier_re_prod_im (s t : set ℝ) : frontier (s Γ—β„‚ t) = (closure s Γ—β„‚ frontier t) βˆͺ (frontier s Γ—β„‚ closure t) := by simpa only [← preimage_eq_preimage equiv_real_prod_clm.symm.to_homeomorph.surjective, equiv_real_prod_clm.symm.to_homeomorph.preimage_frontier] using frontier_prod_eq s t lemma frontier_set_of_le_re_and_le_im (a b : ℝ) : frontier {z | a ≀ re z ∧ b ≀ im z} = {z | a ≀ re z ∧ im z = b ∨ re z = a ∧ b ≀ im z} := by simpa only [closure_Ici, frontier_Ici] using frontier_re_prod_im (Ici a) (Ici b) lemma frontier_set_of_le_re_and_im_le (a b : ℝ) : frontier {z | a ≀ re z ∧ im z ≀ b} = {z | a ≀ re z ∧ im z = b ∨ re z = a ∧ im z ≀ b} := by simpa only [closure_Ici, closure_Iic, frontier_Ici, frontier_Iic] using frontier_re_prod_im (Ici a) (Iic b) end complex open complex metric variables {s t : set ℝ} lemma is_open.re_prod_im (hs : is_open s) (ht : is_open t) : is_open (s Γ—β„‚ t) := (hs.preimage continuous_re).inter (ht.preimage continuous_im) lemma is_closed.re_prod_im (hs : is_closed s) (ht : is_closed t) : is_closed (s Γ—β„‚ t) := (hs.preimage continuous_re).inter (ht.preimage continuous_im) lemma metric.bounded.re_prod_im (hs : bounded s) (ht : bounded t) : bounded (s Γ—β„‚ t) := antilipschitz_equiv_real_prod.bounded_preimage (hs.prod ht)
e6da694fd11c2754b5a2ea9f1a196bb6d8157e7d
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
/src/category_theory/yoneda.lean
05e00ed453feb32a7fd128270c9328364d8bc498
[ "Apache-2.0" ]
permissive
lacker/mathlib
f2439c743c4f8eb413ec589430c82d0f73b2d539
ddf7563ac69d42cfa4a1bfe41db1fed521bd795f
refs/heads/master
1,671,948,326,773
1,601,479,268,000
1,601,479,268,000
298,686,743
0
0
Apache-2.0
1,601,070,794,000
1,601,070,794,000
null
UTF-8
Lean
false
false
7,506
lean
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import category_theory.hom_functor /-! # The Yoneda embedding The Yoneda embedding as a functor `yoneda : C β₯€ (Cα΅’α΅– β₯€ Type v₁)`, along with an instance that it is `fully_faithful`. Also the Yoneda lemma, `yoneda_lemma : (yoneda_pairing C) β‰… (yoneda_evaluation C)`. ## References * [Stacks: Opposite Categories and the Yoneda Lemma](https://stacks.math.columbia.edu/tag/001L) -/ namespace category_theory open opposite universes v₁ u₁ uβ‚‚ -- declare the `v`'s first; see `category_theory.category` for an explanation variables {C : Type u₁} [category.{v₁} C] /-- The Yoneda embedding, as a functor from `C` into presheaves on `C`. See https://stacks.math.columbia.edu/tag/001O. -/ @[simps] def yoneda : C β₯€ (Cα΅’α΅– β₯€ Type v₁) := { obj := Ξ» X, { obj := Ξ» Y, unop Y ⟢ X, map := Ξ» Y Y' f g, f.unop ≫ g, map_comp' := Ξ» _ _ _ f g, begin ext, dsimp, erw [category.assoc] end, map_id' := Ξ» Y, begin ext, dsimp, erw [category.id_comp] end }, map := Ξ» X X' f, { app := Ξ» Y g, g ≫ f } } /-- The co-Yoneda embedding, as a functor from `Cα΅’α΅–` into co-presheaves on `C`. -/ @[simps] def coyoneda : Cα΅’α΅– β₯€ (C β₯€ Type v₁) := { obj := Ξ» X, { obj := Ξ» Y, unop X ⟢ Y, map := Ξ» Y Y' f g, g ≫ f, map_comp' := Ξ» _ _ _ f g, begin ext1, dsimp, erw [category.assoc] end, map_id' := Ξ» Y, begin ext1, dsimp, erw [category.comp_id] end }, map := Ξ» X X' f, { app := Ξ» Y g, f.unop ≫ g }, map_comp' := Ξ» _ _ _ f g, begin ext, dsimp, erw [category.assoc] end, map_id' := Ξ» X, begin ext, dsimp, erw [category.id_comp] end } namespace yoneda lemma obj_map_id {X Y : C} (f : op X ⟢ op Y) : ((@yoneda C _).obj X).map f (πŸ™ X) = ((@yoneda C _).map f.unop).app (op Y) (πŸ™ Y) := by obviously @[simp] lemma naturality {X Y : C} (Ξ± : yoneda.obj X ⟢ yoneda.obj Y) {Z Z' : C} (f : Z ⟢ Z') (h : Z' ⟢ X) : f ≫ Ξ±.app (op Z') h = Ξ±.app (op Z) (f ≫ h) := (functor_to_types.naturality _ _ Ξ± f.op h).symm /-- The Yoneda embedding is full. See https://stacks.math.columbia.edu/tag/001P. -/ instance yoneda_full : full (@yoneda C _) := { preimage := Ξ» X Y f, (f.app (op X)) (πŸ™ X) } /-- The Yoneda embedding is faithful. See https://stacks.math.columbia.edu/tag/001P. -/ instance yoneda_faithful : faithful (@yoneda C _) := { map_injective' := Ξ» X Y f g p, begin injection p with h, convert (congr_fun (congr_fun h (op X)) (πŸ™ X)); dsimp; simp, end } /-- Extensionality via Yoneda. The typical usage would be ``` -- Goal is `X β‰… Y` apply yoneda.ext, -- Goals are now functions `(Z ⟢ X) β†’ (Z ⟢ Y)`, `(Z ⟢ Y) β†’ (Z ⟢ X)`, and the fact that these functions are inverses and natural in `Z`. ``` -/ def ext (X Y : C) (p : Ξ  {Z : C}, (Z ⟢ X) β†’ (Z ⟢ Y)) (q : Ξ  {Z : C}, (Z ⟢ Y) β†’ (Z ⟢ X)) (h₁ : Ξ  {Z : C} (f : Z ⟢ X), q (p f) = f) (hβ‚‚ : Ξ  {Z : C} (f : Z ⟢ Y), p (q f) = f) (n : Ξ  {Z Z' : C} (f : Z' ⟢ Z) (g : Z ⟢ X), p (f ≫ g) = f ≫ p g) : X β‰… Y := @preimage_iso _ _ _ _ yoneda _ _ _ _ (nat_iso.of_components (Ξ» Z, { hom := p, inv := q, }) (by tidy)) def is_iso {X Y : C} (f : X ⟢ Y) [is_iso (yoneda.map f)] : is_iso f := is_iso_of_fully_faithful yoneda f end yoneda namespace coyoneda @[simp] lemma naturality {X Y : Cα΅’α΅–} (Ξ± : coyoneda.obj X ⟢ coyoneda.obj Y) {Z Z' : C} (f : Z' ⟢ Z) (h : unop X ⟢ Z') : (Ξ±.app Z' h) ≫ f = Ξ±.app Z (h ≫ f) := begin erw [functor_to_types.naturality], refl end instance coyoneda_full : full (@coyoneda C _) := { preimage := Ξ» X Y f, ((f.app (unop X)) (πŸ™ _)).op } instance coyoneda_faithful : faithful (@coyoneda C _) := { map_injective' := Ξ» X Y f g p, begin injection p with h, have t := (congr_fun (congr_fun h (unop X)) (πŸ™ _)), simpa using congr_arg has_hom.hom.op t, end } def is_iso {X Y : Cα΅’α΅–} (f : X ⟢ Y) [is_iso (coyoneda.map f)] : is_iso f := is_iso_of_fully_faithful coyoneda f end coyoneda /-- A presheaf `F` is representable if there is object `X` so `F β‰… yoneda.obj X`. See https://stacks.math.columbia.edu/tag/001Q. -/ -- TODO should we make this a Prop, merely asserting existence of such an object? class representable (F : Cα΅’α΅– β₯€ Type v₁) := (X : C) (w : yoneda.obj X β‰… F) end category_theory namespace category_theory -- For the rest of the file, we are using product categories, -- so need to restrict to the case morphisms are in 'Type', not 'Sort'. universes v₁ u₁ uβ‚‚ -- declare the `v`'s first; see `category_theory.category` for an explanation open opposite variables (C : Type u₁) [category.{v₁} C] -- We need to help typeclass inference with some awkward universe levels here. instance prod_category_instance_1 : category ((Cα΅’α΅– β₯€ Type v₁) Γ— Cα΅’α΅–) := category_theory.prod.{(max u₁ v₁) v₁} (Cα΅’α΅– β₯€ Type v₁) Cα΅’α΅– instance prod_category_instance_2 : category (Cα΅’α΅– Γ— (Cα΅’α΅– β₯€ Type v₁)) := category_theory.prod.{v₁ (max u₁ v₁)} Cα΅’α΅– (Cα΅’α΅– β₯€ Type v₁) open yoneda def yoneda_evaluation : Cα΅’α΅– Γ— (Cα΅’α΅– β₯€ Type v₁) β₯€ Type (max u₁ v₁) := evaluation_uncurried Cα΅’α΅– (Type v₁) β‹™ ulift_functor.{u₁} @[simp] lemma yoneda_evaluation_map_down (P Q : Cα΅’α΅– Γ— (Cα΅’α΅– β₯€ Type v₁)) (Ξ± : P ⟢ Q) (x : (yoneda_evaluation C).obj P) : ((yoneda_evaluation C).map Ξ± x).down = Ξ±.2.app Q.1 (P.2.map Ξ±.1 x.down) := rfl def yoneda_pairing : Cα΅’α΅– Γ— (Cα΅’α΅– β₯€ Type v₁) β₯€ Type (max u₁ v₁) := functor.prod yoneda.op (𝟭 (Cα΅’α΅– β₯€ Type v₁)) β‹™ functor.hom (Cα΅’α΅– β₯€ Type v₁) @[simp] lemma yoneda_pairing_map (P Q : Cα΅’α΅– Γ— (Cα΅’α΅– β₯€ Type v₁)) (Ξ± : P ⟢ Q) (Ξ² : (yoneda_pairing C).obj P) : (yoneda_pairing C).map Ξ± Ξ² = yoneda.map Ξ±.1.unop ≫ Ξ² ≫ Ξ±.2 := rfl /-- The Yoneda lemma asserts that that the Yoneda pairing `(X : Cα΅’α΅–, F : Cα΅’α΅– β₯€ Type) ↦ (yoneda.obj (unop X) ⟢ F)` is naturally isomorphic to the evaluation `(X, F) ↦ F.obj X`. See https://stacks.math.columbia.edu/tag/001P. -/ def yoneda_lemma : yoneda_pairing C β‰… yoneda_evaluation C := { hom := { app := Ξ» F x, ulift.up ((x.app F.1) (πŸ™ (unop F.1))), naturality' := begin intros X Y f, ext, dsimp, erw [category.id_comp, ←functor_to_types.naturality], simp only [category.comp_id, yoneda_obj_map], end }, inv := { app := Ξ» F x, { app := Ξ» X a, (F.2.map a.op) x.down, naturality' := begin intros X Y f, ext, dsimp, rw [functor_to_types.map_comp_apply] end }, naturality' := begin intros X Y f, ext, dsimp, rw [←functor_to_types.naturality, functor_to_types.map_comp_apply] end }, hom_inv_id' := begin ext, dsimp, erw [←functor_to_types.naturality, obj_map_id], simp only [yoneda_map_app, has_hom.hom.unop_op], erw [category.id_comp], end, inv_hom_id' := begin ext, dsimp, rw [functor_to_types.map_id_apply] end }. variables {C} @[simp] def yoneda_sections (X : C) (F : Cα΅’α΅– β₯€ Type v₁) : (yoneda.obj X ⟢ F) β‰… ulift.{u₁} (F.obj (op X)) := (yoneda_lemma C).app (op X, F) @[simp] def yoneda_sections_small {C : Type u₁} [small_category C] (X : C) (F : Cα΅’α΅– β₯€ Type u₁) : (yoneda.obj X ⟢ F) β‰… F.obj (op X) := yoneda_sections X F β‰ͺ≫ ulift_trivial _ end category_theory
5d7fe56edc2dc2d15ae131a15effd63e2bd8d1b6
94e33a31faa76775069b071adea97e86e218a8ee
/src/data/nat/factorization/prime_pow.lean
106daf224ff01403c3b1aa0dc57c757faae69b7b
[ "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
5,480
lean
/- Copyright (c) 2022 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import algebra.is_prime_pow import data.nat.factorization.basic /-! # Prime powers and factorizations This file deals with factorizations of prime powers. -/ variables {R : Type*} [comm_monoid_with_zero R] (n p : R) (k : β„•) lemma is_prime_pow.min_fac_pow_factorization_eq {n : β„•} (hn : is_prime_pow n) : n.min_fac ^ n.factorization n.min_fac = n := begin obtain ⟨p, k, hp, hk, rfl⟩ := hn, rw ←nat.prime_iff at hp, rw [hp.pow_min_fac hk.ne', hp.factorization_pow, finsupp.single_eq_same], end lemma is_prime_pow_of_min_fac_pow_factorization_eq {n : β„•} (h : n.min_fac ^ n.factorization n.min_fac = n) (hn : n β‰  1) : is_prime_pow n := begin rcases eq_or_ne n 0 with rfl | hn', { simpa using h }, refine ⟨_, _, nat.prime_iff.1 (nat.min_fac_prime hn), _, h⟩, rw [pos_iff_ne_zero, ←finsupp.mem_support_iff, nat.factor_iff_mem_factorization, nat.mem_factors_iff_dvd hn' (nat.min_fac_prime hn)], apply nat.min_fac_dvd end lemma is_prime_pow_iff_min_fac_pow_factorization_eq {n : β„•} (hn : n β‰  1) : is_prime_pow n ↔ n.min_fac ^ n.factorization n.min_fac = n := ⟨λ h, h.min_fac_pow_factorization_eq, Ξ» h, is_prime_pow_of_min_fac_pow_factorization_eq h hn⟩ lemma is_prime_pow_iff_factorization_eq_single {n : β„•} : is_prime_pow n ↔ βˆƒ p k : β„•, 0 < k ∧ n.factorization = finsupp.single p k := begin rw is_prime_pow_nat_iff, refine existsβ‚‚_congr (Ξ» p k, _), split, { rintros ⟨hp, hk, hn⟩, exact ⟨hk, by rw [←hn, nat.prime.factorization_pow hp]⟩ }, { rintros ⟨hk, hn⟩, have hn0 : n β‰  0, { rintro rfl, simpa only [finsupp.single_eq_zero, eq_comm, nat.factorization_zero, hk.ne'] using hn }, rw nat.eq_pow_of_factorization_eq_single hn0 hn, exact ⟨nat.prime_of_mem_factorization (by simp [hn, hk.ne'] : p ∈ n.factorization.support), hk, rfl⟩ } end lemma is_prime_pow_iff_card_support_factorization_eq_one {n : β„•} : is_prime_pow n ↔ n.factorization.support.card = 1 := by simp_rw [is_prime_pow_iff_factorization_eq_single, finsupp.card_support_eq_one', exists_prop, pos_iff_ne_zero] /-- An equivalent definition for prime powers: `n` is a prime power iff there is a unique prime dividing it. -/ lemma is_prime_pow_iff_unique_prime_dvd {n : β„•} : is_prime_pow n ↔ βˆƒ! p : β„•, p.prime ∧ p ∣ n := begin rw is_prime_pow_nat_iff, split, { rintro ⟨p, k, hp, hk, rfl⟩, refine ⟨p, ⟨hp, dvd_pow_self _ hk.ne'⟩, _⟩, rintro q ⟨hq, hq'⟩, exact (nat.prime_dvd_prime_iff_eq hq hp).1 (hq.dvd_of_dvd_pow hq') }, rintro ⟨p, ⟨hp, hn⟩, hq⟩, -- Take care of the n = 0 case rcases eq_or_ne n 0 with rfl | hnβ‚€, { obtain ⟨q, hq', hq''⟩ := nat.exists_infinite_primes (p + 1), cases hq q ⟨hq'', by simp⟩, simpa using hq' }, -- So assume 0 < n refine ⟨p, n.factorization p, hp, hp.factorization_pos_of_dvd hnβ‚€ hn, _⟩, simp only [and_imp] at hq, apply nat.dvd_antisymm (nat.pow_factorization_dvd _ _), -- We need to show n ∣ p ^ n.factorization p apply nat.dvd_of_factors_subperm hnβ‚€, rw [hp.factors_pow, list.subperm_ext_iff], intros q hq', rw nat.mem_factors hnβ‚€ at hq', cases hq _ hq'.1 hq'.2, simp, end lemma is_prime_pow_pow_iff {n k : β„•} (hk : k β‰  0) : is_prime_pow (n ^ k) ↔ is_prime_pow n := begin simp only [is_prime_pow_iff_unique_prime_dvd], apply exists_unique_congr, simp only [and.congr_right_iff], intros p hp, exact ⟨hp.dvd_of_dvd_pow, Ξ» t, t.trans (dvd_pow_self _ hk)⟩, end lemma nat.coprime.is_prime_pow_dvd_mul {n a b : β„•} (hab : nat.coprime a b) (hn : is_prime_pow n) : n ∣ a * b ↔ n ∣ a ∨ n ∣ b := begin rcases eq_or_ne a 0 with rfl | ha, { simp only [nat.coprime_zero_left] at hab, simp [hab, finset.filter_singleton, not_is_prime_pow_one] }, rcases eq_or_ne b 0 with rfl | hb, { simp only [nat.coprime_zero_right] at hab, simp [hab, finset.filter_singleton, not_is_prime_pow_one] }, refine ⟨_, Ξ» h, or.elim h (Ξ» i, i.trans (dvd_mul_right _ _)) (Ξ» i, i.trans (dvd_mul_left _ _))⟩, obtain ⟨p, k, hp, hk, rfl⟩ := (is_prime_pow_nat_iff _).1 hn, simp only [hp.pow_dvd_iff_le_factorization (mul_ne_zero ha hb), nat.factorization_mul ha hb, hp.pow_dvd_iff_le_factorization ha, hp.pow_dvd_iff_le_factorization hb, pi.add_apply, finsupp.coe_add], have : a.factorization p = 0 ∨ b.factorization p = 0, { rw [←finsupp.not_mem_support_iff, ←finsupp.not_mem_support_iff, ←not_and_distrib, ←finset.mem_inter], exact Ξ» t, nat.factorization_disjoint_of_coprime hab t }, cases this; simp [this, imp_or_distrib], end lemma nat.mul_divisors_filter_prime_pow {a b : β„•} (hab : a.coprime b) : (a * b).divisors.filter is_prime_pow = (a.divisors βˆͺ b.divisors).filter is_prime_pow := begin rcases eq_or_ne a 0 with rfl | ha, { simp only [nat.coprime_zero_left] at hab, simp [hab, finset.filter_singleton, not_is_prime_pow_one] }, rcases eq_or_ne b 0 with rfl | hb, { simp only [nat.coprime_zero_right] at hab, simp [hab, finset.filter_singleton, not_is_prime_pow_one] }, ext n, simp only [ha, hb, finset.mem_union, finset.mem_filter, nat.mul_eq_zero, and_true, ne.def, and.congr_left_iff, not_false_iff, nat.mem_divisors, or_self], apply hab.is_prime_pow_dvd_mul, end
572041e21651f12f03b3447f144f80c668580a59
5d166a16ae129621cb54ca9dde86c275d7d2b483
/tests/lean/run/doc_string4.lean
e46d5057b92e7598d74e3dfd1afeee88cde11d0a
[ "Apache-2.0" ]
permissive
jcarlson23/lean
b00098763291397e0ac76b37a2dd96bc013bd247
8de88701247f54d325edd46c0eed57aeacb64baf
refs/heads/master
1,611,571,813,719
1,497,020,963,000
1,497,021,515,000
93,882,536
1
0
null
1,497,029,896,000
1,497,029,896,000
null
UTF-8
Lean
false
false
3,719
lean
/-! # Arithmetic expressions for a simple imperative language. -/ namespace imp open tactic /-- Variable names -/ @[reducible] def uname := string /-- #brief Arithmetic expressions abstract syntax tree. We encode x + 1 as ``` #check aexp.plus (aexp.var "x") (aexp.val 1) ``` -/ inductive aexp | val : nat β†’ aexp | var : uname β†’ aexp | plus : aexp β†’ aexp β†’ aexp /-- #brief Arithmetic expressions have decidable equality. -/ instance : decidable_eq aexp := by mk_dec_eq_instance /-- #brief Value assigned to variables. -/ @[reducible] def value := nat /-- #brief The state is a mapping from variable names to their values. -/ def state := uname β†’ value open aexp /-- #brief Given an arithmetic expression and a state, this function returns the value for the expression. ``` example : aval (plus (val 3) (var "x")) (Ξ» x, 0) = 3 := rfl ``` See [`aexp`](#imp.aexp) -/ def aval : aexp β†’ state β†’ value | (val n) s := n | (var x) s := s x | (plus a₁ aβ‚‚) s := aval a₁ s + aval aβ‚‚ s /-- #brief Update the state with then entry `x -> v`. We say we are assigning `v` to `x`. -/ def updt (s : state) (x : uname) (v : value) : state := Ξ» y, if x = y then v else s y /-- #brief Very basic constant folding simplification procedure. For example, it reduces subexpressions such as (3 + 2) to 5. -/ def asimp_const : aexp β†’ aexp | (val n) := val n | (var x) := var x | (plus a₁ aβ‚‚) := match asimp_const a₁, asimp_const aβ‚‚ with | val n₁, val nβ‚‚ := val (n₁ + nβ‚‚) | b₁, bβ‚‚ := plus b₁ bβ‚‚ end /-! _Remark_: we can prove by reflexivity the fact that the constant folder simplifies `(2+3)+x` into `5+x`. ``` example : asimp_const (plus (plus (val 2) (val 3)) (var "x")) = plus (val 5) (var "x") := rfl ``` -/ /-- #brief Prove that constant folding preserves the value of an artihmetic expressions. -/ lemma aval_asimp_const (a : aexp) (s : state) : aval (asimp_const a) s = aval a s := begin induction a with n x a₁ aβ‚‚ ih₁ ihβ‚‚, repeat {reflexivity}, {unfold asimp_const aval, rewrite [-ih₁, -ihβ‚‚], cases (asimp_const a₁), repeat {cases (asimp_const aβ‚‚), repeat {reflexivity}}} end /-- #brief Alternative proof without tactics that constant folding preserves the value of an arithmetic expression. This alternative proof is more verbose because we are essentially writing the proof term. -/ lemma aval_asimp_constβ‚‚ : βˆ€ (a : aexp) (s : state), aval (asimp_const a) s = aval a s | (val n) s := rfl | (var x) s := rfl | (plus a₁ aβ‚‚) s := show aval (asimp_const (plus a₁ aβ‚‚)) s = aval a₁ s + aval aβ‚‚ s, from suffices aval (asimp_const._match_1 (asimp_const a₁) (asimp_const aβ‚‚)) s = aval (asimp_const a₁) s + aval (asimp_const aβ‚‚) s, from aval_asimp_constβ‚‚ a₁ s β–Έ aval_asimp_constβ‚‚ aβ‚‚ s β–Έ this, match asimp_const a₁, asimp_const aβ‚‚ with | val _, val _ := rfl | val _, var _ := rfl | val _, plus _ _ := rfl | var _, val _ := rfl | var _, var _ := rfl | var _, plus _ _ := rfl | plus _ _, val _ := rfl | plus _ _, var _ := rfl | plus _ _, plus _ _ := rfl end /-- #brief Alternative proof that mixes proof terms and tactics. See [`asimp_const`](#imp.asimp_const) -/ lemma aval_asimp_const₃ : βˆ€ (a : aexp) (s : state), aval (asimp_const a) s = aval a s | (val n) s := rfl | (var x) s := rfl | (plus a₁ aβ‚‚) s := begin note h₁ := aval_asimp_const₃ a₁ s, note hβ‚‚ := aval_asimp_const₃ aβ‚‚ s, unfold asimp_const aval, rewrite [-h₁, -hβ‚‚], cases (asimp_const a₁); cases (asimp_const aβ‚‚); repeat {reflexivity} end end imp
7f3736ba32271e2b8f0c18b6a48953907b072cf9
076f5040b63237c6dd928c6401329ed5adcb0e44
/instructor-notes/2019.10.14.prop_logic/bool_sat.lean
e7d8ea8ad81a158738479d533e71990b3fc3f0b4
[]
no_license
kevinsullivan/uva-cs-dm-f19
0f123689cf6cb078f263950b18382a7086bf30be
09a950752884bd7ade4be33e9e89a2c4b1927167
refs/heads/master
1,594,771,841,541
1,575,853,850,000
1,575,853,850,000
205,433,890
4
9
null
1,571,592,121,000
1,567,188,539,000
Lean
UTF-8
Lean
false
false
4,437
lean
import .prop_logic open prop_logic open prop_logic.var open prop_logic.unOp open prop_logic.binOp open prop_logic.pExp /- *** SATISFIABILITY solver *** This module implements a model finder. It works by generating the 2^n possible interpretations of a given propositional logic formula, where n is the number of distinct variables in the formula, and by then evaluating the formula under each of the interpretations to produce a list of Boolean truth values. True entries correspond to models of the given formula. The insight on which the design of the model finder is based is that in a truth table for an expression based on a set of n variables, with are 2^n rows (each corresponding to an interpretation), and the truth table entry for the k'th variable in the m'th row is given by the k'th bit in the binary representation of the number, m. -/ /- Given (m n : nat), return m'th bit from the right in binary representation of n. Formerly called mrbn. However, the mrbn function returned a bool. This function just returns 0 or 1 of type nat. We then provide the following function to turn such a nat into a bool in the usual way, with 0 mapping to ff and 1 (or any other nat) mapping to tt. -/ def mth_bit_from_right_in_n: β„• β†’ β„• β†’ β„• | 0 n := n % 2 | (nat.succ m') n := mth_bit_from_right_in_n m' (n/2) /- Convert bit value 0 or 1 (of type nat) to corresponding Boolean value. -/ def bit_to_bool : β„• β†’ bool | 0 := ff | _ := tt /- Given (m n : β„•) return the m'th interpretation in an enumeration of the 2^n interpretations given n variables. Recall that in our formalization of the semantics of propositional logic, an interpretation is given as a function from var to bool, and there is an infinite number of values of type var. This function just assigns the "default" value ff to each variable of the form (mkVar k) where k >= n, and returns the "all false" intepretation function when m >= 2^n. Otherwise it returns an interpretation where the first n truth values are given by the n bits in the binary expansion of m. -/ def mth_interp_n_vars (m n: β„•) : var β†’ bool := if (m >= 2^n) then Ξ» v, ff else Ξ» v : var, match v with | (mkVar i) := if i >= n then ff else bit_to_bool (mth_bit_from_right_in_n i m) end /- This is a helper function for the primary function that follows. The primary function which is non-recursive and takes an argument, n, calls this recursive function with m=2^n and n to build a list of 2^n interpretations for n variables. Given arguments (m : nat) being the number of interps to generate and (n : nat), the number of variables, return a list of m interpretations. In practice this function is only called by the primary function and is called with m = 2^n. Using recursion it then "loops" m=2^n times to build a list of the required 2^n interpretations for a case in which there are n relevant variables. -/ def interps_helper : nat β†’ nat β†’ list (var β†’ bool) | 0 n := list.cons (mth_interp_n_vars 0 n) list.nil | (nat.succ m') n := list.cons (mth_interp_n_vars (nat.succ m') n) (interps_helper m' n) /- Primary function: return list of all possible interpretations for n variables -/ def interps_for_n_vars : β„• β†’ list (var β†’ bool) | nat.zero := [] | n := interps_helper (2^n-1) n /- Return list of Boolean results of evaluating a given propositional logic expression, p, under each of its possible interpretations. That is, return a list of the truth table "result" for the given expression under each of its possible The second argument, n, indicates the highest "index" of any variable in the expression, p. Precondition: if the variable expressions in p are (varExp (mkvar 0)), varExp (mkVar 1), and varExp (mkvar 3), for example, then the value of the second argument, n, should be set to 4. The resulting truth table will then contain 16 rows/interpretations, in which (mkvar 2) will also be given values. These values won't affect how p is evaluated, because that variable does not appear in p, but the variable nevertheless has to appear in the truth table for this code to work. If you "number" you var objects from 0 to n-1, using (mkVar 0), ..., (mkVar n-1), then use n as the value of the second argument. -/ def truth_table_results (p : pExp) (n : β„•) := list.map (Ξ» (i : var β†’ bool), pEval p i) (interps_for_n_vars n)
e685ce10f2431637751aa56ed4021090dbf840fa
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/test/back_chaining.lean
ded29a68c6a5997de6e803f959147e6548dcb8c2
[ "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
979
lean
open tactic variables {Ξ± : Type*} instance : has_subset (set Ξ±) := ⟨λ s t, βˆ€ ⦃x⦄, x ∈ s β†’ x ∈ t⟩ instance : has_union (set Ξ±) := ⟨λ s t, {a | a ∈ s ∨ a ∈ t}⟩ instance : has_inter (set Ξ±) := ⟨λ s t, {a | a ∈ s ∧ a ∈ t}⟩ -- TODO: write a tactic to unfold specific instances of generic notation? theorem subset_def {s t : set Ξ±} : (s βŠ† t) = βˆ€ x, x ∈ s β†’ x ∈ t := rfl theorem union_def {s₁ sβ‚‚ : set Ξ±} : s₁ βˆͺ sβ‚‚ = {a | a ∈ s₁ ∨ a ∈ sβ‚‚} := rfl theorem inter_def {s₁ sβ‚‚ : set Ξ±} : s₁ ∩ sβ‚‚ = {a | a ∈ s₁ ∧ a ∈ sβ‚‚} := rfl theorem union_subset {s t r : set Ξ±} (sr : s βŠ† r) (tr : t βŠ† r) : s βˆͺ t βŠ† r := begin dsimp [subset_def, union_def] at *, intros x h, cases h; back_chaining_using_hs end theorem subset_inter {s t r : set Ξ±} (rs : r βŠ† s) (rt : r βŠ† t) : r βŠ† s ∩ t := begin dsimp [subset_def, inter_def] at *, intros x h, split; back_chaining_using_hs end
e210b724ddaa74d6ea7596b63ff9f493957d6c80
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/archive/imo/imo1962_q1.lean
7bd2c6f015d7c730e983ac977ef0af89a3807e4d
[ "Apache-2.0" ]
permissive
jjgarzella/mathlib
96a345378c4e0bf26cf604aed84f90329e4896a2
395d8716c3ad03747059d482090e2bb97db612c8
refs/heads/master
1,686,480,124,379
1,625,163,323,000
1,625,163,323,000
281,190,421
2
0
Apache-2.0
1,595,268,170,000
1,595,268,169,000
null
UTF-8
Lean
false
false
5,425
lean
/- Copyright (c) 2020 Kevin Lacker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Lacker -/ import data.nat.digits /-! # IMO 1962 Q1 Find the smallest natural number $n$ which has the following properties: (a) Its decimal representation has 6 as the last digit. (b) If the last digit 6 is erased and placed in front of the remaining digits, the resulting number is four times as large as the original number $n$. Since Lean does not explicitly express problems of the form "find the smallest number satisfying X", we define the problem as a predicate, and then prove a particular number is the smallest member of a set satisfying it. -/ open nat def problem_predicate (n : β„•) : Prop := (digits 10 n).head = 6 ∧ of_digits 10 ((digits 10 n).tail.concat 6) = 4 * n /-! First, it's inconvenient to work with digits, so let's simplify them out of the problem. -/ abbreviation problem_predicate' (c n : β„•) : Prop := n = 10 * c + 6 ∧ 6 * 10 ^ (digits 10 c).length + c = 4 * n lemma without_digits {n : β„•} (h1 : problem_predicate n) : βˆƒ c : β„•, problem_predicate' c n := begin use n / 10, cases n, { have h2 : Β¬ problem_predicate 0, by norm_num [problem_predicate], contradiction }, { rw [problem_predicate, digits_def' (dec_trivial : 2 ≀ 10) n.succ_pos, list.head, list.tail_cons, list.concat_eq_append] at h1, split, { rw [← h1.left, div_add_mod (n+1) 10], }, { rw [← h1.right, of_digits_append, of_digits_digits, of_digits_singleton, add_comm, mul_comm], }, }, end /-! Now we can eliminate possibilities for `(digits 10 c).length` until we get to the one that works. -/ lemma case_0_digit {c n : β„•} (h1 : (digits 10 c).length = 0) : Β¬ problem_predicate' c n := begin intro h2, have h3 : 6 * 10 ^ 0 + c = 6 * 10 ^ (digits 10 c).length + c, by rw h1, have h4 : 6 * 10 ^ 0 + c = 4 * (10 * c + 6), by rw [h3, h2.right, h2.left], linarith, end lemma case_1_digit {c n : β„•} (h1 : (digits 10 c).length = 1) : Β¬ problem_predicate' c n := begin intro h2, have h3 : 6 * 10 ^ 1 + c = 6 * 10 ^ (digits 10 c).length + c, by rw h1, have h4 : 6 * 10 ^ 1 + c = 4 * (10 * c + 6), by rw [h3, h2.right, h2.left], have h6 : c > 0, by linarith, linarith, end lemma case_2_digit {c n : β„•} (h1 : (digits 10 c).length = 2) : Β¬ problem_predicate' c n := begin intro h2, have h3 : 6 * 10 ^ 2 + c = 6 * 10 ^ (digits 10 c).length + c, by rw h1, have h4 : 6 * 10 ^ 2 + c = 4 * (10 * c + 6), by rw [h3, h2.right, h2.left], have h5 : c > 14, by linarith, linarith end lemma case_3_digit {c n : β„•} (h1 : (digits 10 c).length = 3) : Β¬ problem_predicate' c n := begin intro h2, have h3 : 6 * 10 ^ 3 + c = 6 * 10 ^ (digits 10 c).length + c, by rw h1, have h4 : 6 * 10 ^ 3 + c = 4 * (10 * c + 6), by rw [h3, h2.right, h2.left], have h5 : c > 153, by linarith, linarith end lemma case_4_digit {c n : β„•} (h1 : (digits 10 c).length = 4) : Β¬ problem_predicate' c n := begin intro h2, have h3 : 6 * 10 ^ 4 + c = 6 * 10 ^ (digits 10 c).length + c, by rw h1, have h4 : 6 * 10 ^ 4 + c = 4 * (10 * c + 6), by rw [h3, h2.right, h2.left], have h5 : c > 1537, by linarith, linarith end /-- Putting this inline causes a deep recursion error, so we separate it out. -/ lemma helper_5_digit {c : β„€} (h : 6 * 10 ^ 5 + c = 4 * (10 * c + 6)) : c = 15384 := by linarith lemma case_5_digit {c n : β„•} (h1 : (digits 10 c).length = 5) (h2 : problem_predicate' c n) : c = 15384 := begin have h3 : 6 * 10 ^ 5 + c = 6 * 10 ^ (digits 10 c).length + c, by rw h1, have h4 : 6 * 10 ^ 5 + c = 4 * (10 * c + 6), by rw [h3, h2.right, h2.left], zify at *, exact helper_5_digit h4 end /-- `linarith` fails on numbers this large, so this lemma spells out some of the arithmetic that normally would be automated. -/ lemma case_more_digits {c n : β„•} (h1 : (digits 10 c).length β‰₯ 6) (h2 : problem_predicate' c n) : n β‰₯ 153846 := begin have h3 : c β‰  0, { intro h4, have h5 : (digits 10 c).length = 0, by simp [h4], exact case_0_digit h5 h2 }, have h6 : 2 ≀ 10, from dec_trivial, calc n β‰₯ 10 * c : le.intro h2.left.symm ... β‰₯ 10 ^ (digits 10 c).length : base_pow_length_digits_le 10 c h6 h3 ... β‰₯ 10 ^ 6 : (pow_le_iff_le_right h6).mpr h1 ... β‰₯ 153846 : by norm_num, end /-! Now we combine these cases to show that 153846 is the smallest solution. -/ lemma satisfied_by_153846 : problem_predicate 153846 := by norm_num [problem_predicate, digits_def', of_digits] lemma no_smaller_solutions (n : β„•) (h1 : problem_predicate n) : n β‰₯ 153846 := begin cases without_digits h1 with c h2, have h3 : (digits 10 c).length < 6 ∨ (digits 10 c).length β‰₯ 6, by apply lt_or_ge, cases h3, case or.inr { exact case_more_digits h3 h2, }, case or.inl { interval_cases (digits 10 c).length with h, { exfalso, exact case_0_digit h h2 }, { exfalso, exact case_1_digit h h2 }, { exfalso, exact case_2_digit h h2 }, { exfalso, exact case_3_digit h h2 }, { exfalso, exact case_4_digit h h2 }, { have h4 : c = 15384, from case_5_digit h h2, have h5 : n = 10 * 15384 + 6, from h4 β–Έ h2.left, norm_num at h5, exact h5.ge, }, }, end theorem imo1962_q1 : is_least {n | problem_predicate n} 153846 := ⟨satisfied_by_153846, no_smaller_solutions⟩
ee269a988946ee441055d739b8ecab9addf7d98c
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/set_theory/ordinal_notation.lean
632c9bc11f41b829e393d73b5de3649f8f7319b6
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
20,168
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.set_theory.ordinal_arithmetic import Mathlib.PostPort universes l u_1 namespace Mathlib /-! # Ordinal notations constructive ordinal arithmetic for ordinals `< Ξ΅β‚€`. -/ /-- Recursive definition of an ordinal notation. `zero` denotes the ordinal 0, and `oadd e n a` is intended to refer to `Ο‰^e * n + a`. For this to be valid Cantor normal form, we must have the exponents decrease to the right, but we can't state this condition until we've defined `repr`, so it is a separate definition `NF`. -/ inductive onote where | zero : onote | oadd : onote β†’ β„•+ β†’ onote β†’ onote namespace onote /-- Notation for 0 -/ protected instance has_zero : HasZero onote := { zero := zero } @[simp] theorem zero_def : zero = 0 := rfl protected instance inhabited : Inhabited onote := { default := 0 } /-- Notation for 1 -/ protected instance has_one : HasOne onote := { one := oadd 0 1 0 } /-- Notation for Ο‰ -/ def omega : onote := oadd 1 1 0 /-- The ordinal denoted by a notation -/ @[simp] def repr : onote β†’ ordinal := sorry /-- Auxiliary definition to print an ordinal notation -/ def to_string_aux1 (e : onote) (n : β„•) (s : string) : string := ite (e = 0) (to_string n) (ite (e = 1) (string.str string.empty (char.of_nat (bit1 (bit0 (bit0 (bit1 (bit0 (bit0 (bit1 (bit1 (bit1 1))))))))))) (string.str (string.str (string.str string.empty (char.of_nat (bit1 (bit0 (bit0 (bit1 (bit0 (bit0 (bit1 (bit1 (bit1 1))))))))))) (char.of_nat (bit0 (bit1 (bit1 (bit1 (bit1 (bit0 1)))))))) (char.of_nat (bit0 (bit0 (bit0 (bit1 (bit0 1)))))) ++ s ++ string.str string.empty (char.of_nat (bit1 (bit0 (bit0 (bit1 (bit0 1))))))) ++ ite (n = 1) string.empty (string.str string.empty (char.of_nat (bit0 (bit1 (bit0 (bit1 (bit0 1)))))) ++ to_string n)) /-- Print an ordinal notation -/ def to_string : onote β†’ string := sorry /-- Print an ordinal notation -/ def repr' : onote β†’ string := sorry protected instance has_to_string : has_to_string onote := has_to_string.mk to_string protected instance has_repr : has_repr onote := has_repr.mk repr' protected instance preorder : preorder onote := preorder.mk (fun (x y : onote) => repr x ≀ repr y) (fun (x y : onote) => repr x < repr y) sorry sorry theorem lt_def {x : onote} {y : onote} : x < y ↔ repr x < repr y := iff.rfl theorem le_def {x : onote} {y : onote} : x ≀ y ↔ repr x ≀ repr y := iff.rfl /-- Convert a `nat` into an ordinal -/ @[simp] def of_nat : β„• β†’ onote := sorry @[simp] theorem of_nat_one : of_nat 1 = 1 := rfl @[simp] theorem repr_of_nat (n : β„•) : repr (of_nat n) = ↑n := sorry @[simp] theorem repr_one : repr 1 = 1 := sorry theorem omega_le_oadd (e : onote) (n : β„•+) (a : onote) : ordinal.omega ^ repr e ≀ repr (oadd e n a) := sorry theorem oadd_pos (e : onote) (n : β„•+) (a : onote) : 0 < oadd e n a := lt_of_lt_of_le (ordinal.power_pos (repr e) ordinal.omega_pos) (omega_le_oadd e n a) /-- Compare ordinal notations -/ def cmp : onote β†’ onote β†’ ordering := sorry theorem eq_of_cmp_eq {o₁ : onote} {oβ‚‚ : onote} : cmp o₁ oβ‚‚ = ordering.eq β†’ o₁ = oβ‚‚ := sorry theorem zero_lt_one : 0 < 1 := eq.mpr (id (Eq._oldrec (Eq.refl (0 < 1)) (propext lt_def))) (eq.mpr (id (Eq._oldrec (Eq.refl (repr 0 < repr 1)) repr.equations._eqn_1)) (eq.mpr (id (Eq._oldrec (Eq.refl (0 < repr 1)) repr_one)) ordinal.zero_lt_one)) /-- `NF_below o b` says that `o` is a normal form ordinal notation satisfying `repr o < Ο‰ ^ b`. -/ inductive NF_below : onote β†’ ordinal β†’ Prop where | zero : βˆ€ {b : ordinal}, NF_below 0 b | oadd' : βˆ€ {e : onote} {n : β„•+} {a : onote} {eb b : ordinal}, NF_below e eb β†’ NF_below a (repr e) β†’ repr e < b β†’ NF_below (oadd e n a) b /-- A normal form ordinal notation has the form Ο‰ ^ a₁ * n₁ + Ο‰ ^ aβ‚‚ * nβ‚‚ + ... Ο‰ ^ aβ‚– * nβ‚– where `a₁ > aβ‚‚ > ... > aβ‚–` and all the `aα΅’` are also in normal form. We will essentially only be interested in normal form ordinal notations, but to avoid complicating the algorithms we define everything over general ordinal notations and only prove correctness with normal form as an invariant. -/ def NF (o : onote) := Exists (NF_below o) protected instance NF.zero : NF 0 := Exists.intro 0 NF_below.zero theorem NF_below.oadd {e : onote} {n : β„•+} {a : onote} {b : ordinal} : NF e β†’ NF_below a (repr e) β†’ repr e < b β†’ NF_below (oadd e n a) b := sorry theorem NF_below.fst {e : onote} {n : β„•+} {a : onote} {b : ordinal} (h : NF_below (oadd e n a) b) : NF e := sorry theorem NF.fst {e : onote} {n : β„•+} {a : onote} : NF (oadd e n a) β†’ NF e := fun (αΎ° : NF (oadd e n a)) => Exists.dcases_on αΎ° fun (αΎ°_w : ordinal) (αΎ°_h : NF_below (oadd e n a) αΎ°_w) => idRhs (NF e) (NF_below.fst αΎ°_h) theorem NF_below.snd {e : onote} {n : β„•+} {a : onote} {b : ordinal} (h : NF_below (oadd e n a) b) : NF_below a (repr e) := sorry theorem NF.snd' {e : onote} {n : β„•+} {a : onote} : NF (oadd e n a) β†’ NF_below a (repr e) := fun (αΎ° : NF (oadd e n a)) => Exists.dcases_on αΎ° fun (αΎ°_w : ordinal) (αΎ°_h : NF_below (oadd e n a) αΎ°_w) => idRhs (NF_below a (repr e)) (NF_below.snd αΎ°_h) theorem NF.snd {e : onote} {n : β„•+} {a : onote} (h : NF (oadd e n a)) : NF a := Exists.intro (repr e) (NF.snd' h) theorem NF.oadd {e : onote} {a : onote} (h₁ : NF e) (n : β„•+) (hβ‚‚ : NF_below a (repr e)) : NF (oadd e n a) := Exists.intro (ordinal.succ (repr e)) (NF_below.oadd h₁ hβ‚‚ (ordinal.lt_succ_self (repr e))) protected instance NF.oadd_zero (e : onote) (n : β„•+) [h : NF e] : NF (oadd e n 0) := NF.oadd h n NF_below.zero theorem NF_below.lt {e : onote} {n : β„•+} {a : onote} {b : ordinal} (h : NF_below (oadd e n a) b) : repr e < b := sorry theorem NF_below_zero {o : onote} : NF_below o 0 ↔ o = 0 := sorry theorem NF.zero_of_zero {e : onote} {n : β„•+} {a : onote} (h : NF (oadd e n a)) (e0 : e = 0) : a = 0 := sorry theorem NF_below.repr_lt {o : onote} {b : ordinal} (h : NF_below o b) : repr o < ordinal.omega ^ b := sorry theorem NF_below.mono {o : onote} {b₁ : ordinal} {bβ‚‚ : ordinal} (bb : b₁ ≀ bβ‚‚) (h : NF_below o b₁) : NF_below o bβ‚‚ := sorry theorem NF.below_of_lt {e : onote} {n : β„•+} {a : onote} {b : ordinal} (H : repr e < b) : NF (oadd e n a) β†’ NF_below (oadd e n a) b := sorry theorem NF.below_of_lt' {o : onote} {b : ordinal} : repr o < ordinal.omega ^ b β†’ NF o β†’ NF_below o b := sorry theorem NF_below_of_nat (n : β„•) : NF_below (of_nat n) 1 := nat.cases_on n (idRhs (NF_below 0 1) NF_below.zero) fun (n : β„•) => idRhs (NF_below (oadd 0 (nat.succ_pnat n) 0) 1) (NF_below.oadd NF.zero NF_below.zero ordinal.zero_lt_one) protected instance NF_of_nat (n : β„•) : NF (of_nat n) := Exists.intro 1 (NF_below_of_nat n) protected instance NF_one : NF 1 := eq.mpr (id (Eq._oldrec (Eq.refl (NF 1)) (Eq.symm of_nat_one))) (onote.NF_of_nat 1) theorem oadd_lt_oadd_1 {e₁ : onote} {n₁ : β„•+} {o₁ : onote} {eβ‚‚ : onote} {nβ‚‚ : β„•+} {oβ‚‚ : onote} (h₁ : NF (oadd e₁ n₁ o₁)) (h : e₁ < eβ‚‚) : oadd e₁ n₁ o₁ < oadd eβ‚‚ nβ‚‚ oβ‚‚ := lt_of_lt_of_le (NF_below.repr_lt (NF.below_of_lt h h₁)) (omega_le_oadd eβ‚‚ nβ‚‚ oβ‚‚) theorem oadd_lt_oadd_2 {e : onote} {o₁ : onote} {oβ‚‚ : onote} {n₁ : β„•+} {nβ‚‚ : β„•+} (h₁ : NF (oadd e n₁ o₁)) (h : ↑n₁ < ↑nβ‚‚) : oadd e n₁ o₁ < oadd e nβ‚‚ oβ‚‚ := sorry theorem oadd_lt_oadd_3 {e : onote} {n : β„•+} {a₁ : onote} {aβ‚‚ : onote} (h : a₁ < aβ‚‚) : oadd e n a₁ < oadd e n aβ‚‚ := sorry theorem cmp_compares (a : onote) (b : onote) [NF a] [NF b] : ordering.compares (cmp a b) a b := sorry theorem repr_inj {a : onote} {b : onote} [NF a] [NF b] : repr a = repr b ↔ a = b := sorry theorem NF.of_dvd_omega_power {b : ordinal} {e : onote} {n : β„•+} {a : onote} (h : NF (oadd e n a)) (d : ordinal.omega ^ b ∣ repr (oadd e n a)) : b ≀ repr e ∧ ordinal.omega ^ b ∣ repr a := sorry theorem NF.of_dvd_omega {e : onote} {n : β„•+} {a : onote} (h : NF (oadd e n a)) : ordinal.omega ∣ repr (oadd e n a) β†’ repr e β‰  0 ∧ ordinal.omega ∣ repr a := sorry /-- `top_below b o` asserts that the largest exponent in `o`, if it exists, is less than `b`. This is an auxiliary definition for decidability of `NF`. -/ def top_below (b : onote) : onote β†’ Prop := sorry protected instance decidable_top_below : DecidableRel top_below := id fun (b o : onote) => onote.cases_on o (id decidable.true) fun (o_αΎ° : onote) (o_αΎ°_1 : β„•+) (o_αΎ°_2 : onote) => id (ordering.decidable_eq (cmp o_αΎ° b) ordering.lt) theorem NF_below_iff_top_below {b : onote} [NF b] {o : onote} : NF_below o (repr b) ↔ NF o ∧ top_below b o := sorry protected instance decidable_NF : decidable_pred NF := sorry /-- Addition of ordinal notations (correct only for normal input) -/ def add : onote β†’ onote β†’ onote := sorry protected instance has_add : Add onote := { add := add } @[simp] theorem zero_add (o : onote) : 0 + o = o := rfl theorem oadd_add (e : onote) (n : β„•+) (a : onote) (o : onote) : oadd e n a + o = add._match_1 e n (a + o) := rfl /-- Subtraction of ordinal notations (correct only for normal input) -/ def sub : onote β†’ onote β†’ onote := sorry protected instance has_sub : Sub onote := { sub := sub } theorem add_NF_below {b : ordinal} {o₁ : onote} {oβ‚‚ : onote} : NF_below o₁ b β†’ NF_below oβ‚‚ b β†’ NF_below (o₁ + oβ‚‚) b := sorry protected instance add_NF (o₁ : onote) (oβ‚‚ : onote) [NF o₁] [NF oβ‚‚] : NF (o₁ + oβ‚‚) := sorry @[simp] theorem repr_add (o₁ : onote) (oβ‚‚ : onote) [NF o₁] [NF oβ‚‚] : repr (o₁ + oβ‚‚) = repr o₁ + repr oβ‚‚ := sorry theorem sub_NF_below {o₁ : onote} {oβ‚‚ : onote} {b : ordinal} : NF_below o₁ b β†’ NF oβ‚‚ β†’ NF_below (o₁ - oβ‚‚) b := sorry protected instance sub_NF (o₁ : onote) (oβ‚‚ : onote) [NF o₁] [NF oβ‚‚] : NF (o₁ - oβ‚‚) := sorry @[simp] theorem repr_sub (o₁ : onote) (oβ‚‚ : onote) [NF o₁] [NF oβ‚‚] : repr (o₁ - oβ‚‚) = repr o₁ - repr oβ‚‚ := sorry /-- Multiplication of ordinal notations (correct only for normal input) -/ def mul : onote β†’ onote β†’ onote := sorry protected instance has_mul : Mul onote := { mul := mul } @[simp] theorem zero_mul (o : onote) : 0 * o = 0 := onote.cases_on o (Eq.refl (0 * zero)) fun (o_αΎ° : onote) (o_αΎ°_1 : β„•+) (o_αΎ°_2 : onote) => Eq.refl (0 * oadd o_αΎ° o_αΎ°_1 o_αΎ°_2) @[simp] theorem mul_zero (o : onote) : o * 0 = 0 := onote.cases_on o (Eq.refl (zero * 0)) fun (o_αΎ° : onote) (o_αΎ°_1 : β„•+) (o_αΎ°_2 : onote) => Eq.refl (oadd o_αΎ° o_αΎ°_1 o_αΎ°_2 * 0) theorem oadd_mul (e₁ : onote) (n₁ : β„•+) (a₁ : onote) (eβ‚‚ : onote) (nβ‚‚ : β„•+) (aβ‚‚ : onote) : oadd e₁ n₁ a₁ * oadd eβ‚‚ nβ‚‚ aβ‚‚ = ite (eβ‚‚ = 0) (oadd e₁ (n₁ * nβ‚‚) a₁) (oadd (e₁ + eβ‚‚) nβ‚‚ (oadd e₁ n₁ a₁ * aβ‚‚)) := rfl theorem oadd_mul_NF_below {e₁ : onote} {n₁ : β„•+} {a₁ : onote} {b₁ : ordinal} (h₁ : NF_below (oadd e₁ n₁ a₁) b₁) {oβ‚‚ : onote} {bβ‚‚ : ordinal} : NF_below oβ‚‚ bβ‚‚ β†’ NF_below (oadd e₁ n₁ a₁ * oβ‚‚) (repr e₁ + bβ‚‚) := sorry protected instance mul_NF (o₁ : onote) (oβ‚‚ : onote) [NF o₁] [NF oβ‚‚] : NF (o₁ * oβ‚‚) := sorry @[simp] theorem repr_mul (o₁ : onote) (oβ‚‚ : onote) [NF o₁] [NF oβ‚‚] : repr (o₁ * oβ‚‚) = repr o₁ * repr oβ‚‚ := sorry /-- Calculate division and remainder of `o` mod Ο‰. `split' o = (a, n)` means `o = Ο‰ * a + n`. -/ def split' : onote β†’ onote Γ— β„• := sorry /-- Calculate division and remainder of `o` mod Ο‰. `split o = (a, n)` means `o = a + n`, where `Ο‰ ∣ a`. -/ def split : onote β†’ onote Γ— β„• := sorry /-- `scale x o` is the ordinal notation for `Ο‰ ^ x * o`. -/ def scale (x : onote) : onote β†’ onote := sorry /-- `mul_nat o n` is the ordinal notation for `o * n`. -/ def mul_nat : onote β†’ β„• β†’ onote := sorry /-- Auxiliary definition to compute the ordinal notation for the ordinal exponentiation in `power` -/ def power_aux (e : onote) (a0 : onote) (a : onote) : β„• β†’ β„• β†’ onote := sorry /-- `power o₁ oβ‚‚` calculates the ordinal notation for the ordinal exponential `o₁ ^ oβ‚‚`. -/ def power (o₁ : onote) (oβ‚‚ : onote) : onote := sorry protected instance has_pow : has_pow onote onote := has_pow.mk power theorem power_def (o₁ : onote) (oβ‚‚ : onote) : o₁ ^ oβ‚‚ = power._match_1 oβ‚‚ (split o₁) := rfl theorem split_eq_scale_split' {o : onote} {o' : onote} {m : β„•} [NF o] : split' o = (o', m) β†’ split o = (scale 1 o', m) := sorry theorem NF_repr_split' {o : onote} {o' : onote} {m : β„•} [NF o] : split' o = (o', m) β†’ NF o' ∧ repr o = ordinal.omega * repr o' + ↑m := sorry theorem scale_eq_mul (x : onote) [NF x] (o : onote) [NF o] : scale x o = oadd x 1 0 * o := sorry protected instance NF_scale (x : onote) [NF x] (o : onote) [NF o] : NF (scale x o) := eq.mpr (id (Eq._oldrec (Eq.refl (NF (scale x o))) (scale_eq_mul x o))) (onote.mul_NF (oadd x 1 0) o) @[simp] theorem repr_scale (x : onote) [NF x] (o : onote) [NF o] : repr (scale x o) = ordinal.omega ^ repr x * repr o := sorry theorem NF_repr_split {o : onote} {o' : onote} {m : β„•} [NF o] (h : split o = (o', m)) : NF o' ∧ repr o = repr o' + ↑m := sorry theorem split_dvd {o : onote} {o' : onote} {m : β„•} [NF o] (h : split o = (o', m)) : ordinal.omega ∣ repr o' := sorry theorem split_add_lt {o : onote} {e : onote} {n : β„•+} {a : onote} {m : β„•} [NF o] (h : split o = (oadd e n a, m)) : repr a + ↑m < ordinal.omega ^ repr e := sorry @[simp] theorem mul_nat_eq_mul (n : β„•) (o : onote) : mul_nat o n = o * of_nat n := sorry protected instance NF_mul_nat (o : onote) [NF o] (n : β„•) : NF (mul_nat o n) := eq.mpr (id ((fun (o o_1 : onote) (e_1 : o = o_1) => congr_arg NF e_1) (mul_nat o n) (o * of_nat n) (mul_nat_eq_mul n o))) (onote.mul_NF o (of_nat n)) protected instance NF_power_aux (e : onote) (a0 : onote) (a : onote) [NF e] [NF a0] [NF a] (k : β„•) (m : β„•) : NF (power_aux e a0 a k m) := sorry protected instance NF_power (o₁ : onote) (oβ‚‚ : onote) [NF o₁] [NF oβ‚‚] : NF (o₁ ^ oβ‚‚) := sorry theorem scale_power_aux (e : onote) (a0 : onote) (a : onote) [NF e] [NF a0] [NF a] (k : β„•) (m : β„•) : repr (power_aux e a0 a k m) = ordinal.omega ^ repr e * repr (power_aux 0 a0 a k m) := sorry theorem repr_power_aux₁ {e : onote} {a : onote} [Ne : NF e] [Na : NF a] {a' : ordinal} (e0 : repr e β‰  0) (h : a' < ordinal.omega ^ repr e) (aa : repr a = a') (n : β„•+) : (ordinal.omega ^ repr e * ↑↑n + a') ^ ordinal.omega = (ordinal.omega ^ repr e) ^ ordinal.omega := sorry theorem repr_power_auxβ‚‚ {a0 : onote} {a' : onote} [N0 : NF a0] [Na' : NF a'] (m : β„•) (d : ordinal.omega ∣ repr a') (e0 : repr a0 β‰  0) (h : repr a' + ↑m < ordinal.omega ^ repr a0) (n : β„•+) (k : β„•) : let R : ordinal := repr (power_aux 0 a0 (oadd a0 n a' * of_nat m) k m); (k β‰  0 β†’ R < (ordinal.omega ^ repr a0) ^ ordinal.succ ↑k) ∧ (ordinal.omega ^ repr a0) ^ ↑k * (ordinal.omega ^ repr a0 * ↑↑n + repr a') + R = (ordinal.omega ^ repr a0 * ↑↑n + repr a' + ↑m) ^ ordinal.succ ↑k := sorry theorem repr_power (o₁ : onote) (oβ‚‚ : onote) [NF o₁] [NF oβ‚‚] : repr (o₁ ^ oβ‚‚) = repr o₁ ^ repr oβ‚‚ := sorry end onote /-- The type of normal ordinal notations. (It would have been nicer to define this right in the inductive type, but `NF o` requires `repr` which requires `onote`, so all these things would have to be defined at once, which messes up the VM representation.) -/ def nonote := Subtype fun (o : onote) => onote.NF o protected instance nonote.decidable_eq : DecidableEq nonote := eq.mpr sorry fun (a b : Subtype fun (o : onote) => onote.NF o) => subtype.decidable_eq a b namespace nonote protected instance NF (o : nonote) : onote.NF (subtype.val o) := subtype.property o /-- Construct a `nonote` from an ordinal notation (and infer normality) -/ def mk (o : onote) [h : onote.NF o] : nonote := { val := o, property := h } /-- The ordinal represented by an ordinal notation. (This function is noncomputable because ordinal arithmetic is noncomputable. In computational applications `nonote` can be used exclusively without reference to `ordinal`, but this function allows for correctness results to be stated.) -/ def repr (o : nonote) : ordinal := onote.repr (subtype.val o) protected instance has_to_string : has_to_string nonote := has_to_string.mk fun (x : nonote) => onote.to_string (subtype.val x) protected instance has_repr : has_repr nonote := has_repr.mk fun (x : nonote) => onote.repr' (subtype.val x) protected instance preorder : preorder nonote := preorder.mk (fun (x y : nonote) => repr x ≀ repr y) (fun (x y : nonote) => repr x < repr y) sorry sorry protected instance has_zero : HasZero nonote := { zero := { val := 0, property := onote.NF.zero } } protected instance inhabited : Inhabited nonote := { default := 0 } /-- Convert a natural number to an ordinal notation -/ def of_nat (n : β„•) : nonote := { val := onote.of_nat n, property := sorry } /-- Compare ordinal notations -/ def cmp (a : nonote) (b : nonote) : ordering := onote.cmp (subtype.val a) (subtype.val b) theorem cmp_compares (a : nonote) (b : nonote) : ordering.compares (cmp a b) a b := sorry protected instance linear_order : linear_order nonote := linear_order_of_compares cmp cmp_compares /-- Asserts that `repr a < Ο‰ ^ repr b`. Used in `nonote.rec_on` -/ def old_below (a : nonote) (b : nonote) := onote.NF_below (subtype.val a) (repr b) /-- The `oadd` pseudo-constructor for `nonote` -/ def oadd (e : nonote) (n : β„•+) (a : nonote) (h : old_below a e) : nonote := { val := onote.oadd (subtype.val e) n (subtype.val a), property := sorry } /-- This is a recursor-like theorem for `nonote` suggesting an inductive definition, which can't actually be defined this way due to conflicting dependencies. -/ def rec_on {C : nonote β†’ Sort u_1} (o : nonote) (H0 : C 0) (H1 : (e : nonote) β†’ (n : β„•+) β†’ (a : nonote) β†’ (h : old_below a e) β†’ C e β†’ C a β†’ C (oadd e n a h)) : C o := subtype.cases_on o fun (o : onote) (h : onote.NF o) => onote.rec (fun (h : onote.NF onote.zero) => H0) (fun (e : onote) (n : β„•+) (a : onote) (IHe : (h : onote.NF e) β†’ C { val := e, property := h }) (IHa : (h : onote.NF a) β†’ C { val := a, property := h }) (h : onote.NF (onote.oadd e n a)) => H1 { val := e, property := onote.NF.fst h } n { val := a, property := onote.NF.snd h } (onote.NF.snd' h) (IHe (onote.NF.fst h)) (IHa (onote.NF.snd h))) o h /-- Addition of ordinal notations -/ protected instance has_add : Add nonote := { add := fun (x y : nonote) => mk (subtype.val x + subtype.val y) } theorem repr_add (a : nonote) (b : nonote) : repr (a + b) = repr a + repr b := onote.repr_add (subtype.val a) (subtype.val b) /-- Subtraction of ordinal notations -/ protected instance has_sub : Sub nonote := { sub := fun (x y : nonote) => mk (subtype.val x - subtype.val y) } theorem repr_sub (a : nonote) (b : nonote) : repr (a - b) = repr a - repr b := onote.repr_sub (subtype.val a) (subtype.val b) /-- Multiplication of ordinal notations -/ protected instance has_mul : Mul nonote := { mul := fun (x y : nonote) => mk (subtype.val x * subtype.val y) } theorem repr_mul (a : nonote) (b : nonote) : repr (a * b) = repr a * repr b := onote.repr_mul (subtype.val a) (subtype.val b) /-- Exponentiation of ordinal notations -/ def power (x : nonote) (y : nonote) : nonote := mk (onote.power (subtype.val x) (subtype.val y)) theorem repr_power (a : nonote) (b : nonote) : repr (power a b) = ordinal.power (repr a) (repr b) := onote.repr_power (subtype.val a) (subtype.val b)
49e88671afeed0041a7523ffa007b7d032ee6ce4
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/stage0/src/Lean/Meta/ExprDefEq.lean
bf52ed170a166556a1a03c4e8f74ba2af9d57d86
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
EdAyers/lean4
57ac632d6b0789cb91fab2170e8c9e40441221bd
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
refs/heads/master
1,676,463,245,298
1,660,619,433,000
1,660,619,433,000
183,433,437
1
0
Apache-2.0
1,657,612,672,000
1,556,196,574,000
Lean
UTF-8
Lean
false
false
77,804
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.ProjFns import Lean.Structure import Lean.Meta.WHNF import Lean.Meta.InferType import Lean.Meta.FunInfo import Lean.Meta.Check import Lean.Meta.Offset import Lean.Meta.ForEachExpr import Lean.Meta.UnificationHint namespace Lean.Meta /-- Return true if `b` is of the form `mk a.1 ... a.n`, and `a` is not a constructor application. If `a` and `b` are constructor applications, the method returns `false` to force `isDefEq` to use `isDefEqArgs`. For example, suppose we are trying to solve the constraint ``` Fin.mk ?n ?h =?= Fin.mk n h ``` If this method is applied, the constraints are reduced to ``` n =?= (Fin.mk ?n ?h).1 h =?= (Fin.mk ?n ?h).2 ``` The first constraint produces the assignment `?n := n`. Then, the second constraint is solved using proof irrelevance without assigning `?h`. TODO: investigate better solutions for the proof irrelevance issue. The problem above can happen is other scenarios. That is, proof irrelevance may prevent us from performing desired mvar assignments. -/ private def isDefEqEtaStruct (a b : Expr) : MetaM Bool := do matchConstCtor b.getAppFn (fun _ => return false) fun ctorVal us => do if (← useEtaStruct ctorVal.induct) then matchConstCtor a.getAppFn (fun _ => go ctorVal us) fun _ _ => return false else return false where go ctorVal us := do if ctorVal.numParams + ctorVal.numFields != b.getAppNumArgs then trace[Meta.isDefEq.eta.struct] "failed, insufficient number of arguments at{indentExpr b}" return false else if !isStructureLike (← getEnv) ctorVal.induct then trace[Meta.isDefEq.eta.struct] "failed, type is not a structure{indentExpr b}" return false else if (← isDefEq (← inferType a) (← inferType b)) then checkpointDefEq do let args := b.getAppArgs let params := args[:ctorVal.numParams].toArray for i in [ctorVal.numParams : args.size] do let j := i - ctorVal.numParams let proj ← mkProjFn ctorVal us params j a trace[Meta.isDefEq.eta.struct] "{a} =?= {b} @ [{j}], {proj} =?= {args[i]!}" unless (← isDefEq proj args[i]!) do trace[Meta.isDefEq.eta.struct] "failed, unexpect arg #{i}, projection{indentExpr proj}\nis not defeq to{indentExpr args[i]!}" return false return true else return false /-- Try to solve `a := (fun x => t) =?= b` by eta-expanding `b`. Remark: eta-reduction is not a good alternative even in a system without universe cumulativity like Lean. Example: ``` (fun x : A => f ?m) =?= f ``` The left-hand side of the constraint above it not eta-reduced because `?m` is a metavariable. -/ private def isDefEqEta (a b : Expr) : MetaM Bool := do if a.isLambda && !b.isLambda then let bType ← inferType b let bType ← whnfD bType match bType with | Expr.forallE n d _ c => let b' := mkLambda n c d (mkApp b (mkBVar 0)) checkpointDefEq <| Meta.isExprDefEqAux a b' | _ => pure false else return false /-- Support for `Lean.reduceBool` and `Lean.reduceNat` -/ def isDefEqNative (s t : Expr) : MetaM LBool := do let isDefEq (s t) : MetaM LBool := toLBoolM <| Meta.isExprDefEqAux s t let s? ← reduceNative? s let t? ← reduceNative? t match s?, t? with | some s, some t => isDefEq s t | some s, none => isDefEq s t | none, some t => isDefEq s t | none, none => pure LBool.undef /-- Support for reducing Nat basic operations. -/ def isDefEqNat (s t : Expr) : MetaM LBool := do let isDefEq (s t) : MetaM LBool := toLBoolM <| Meta.isExprDefEqAux s t if s.hasFVar || s.hasMVar || t.hasFVar || t.hasMVar then pure LBool.undef else let s? ← reduceNat? s let t? ← reduceNat? t match s?, t? with | some s, some t => isDefEq s t | some s, none => isDefEq s t | none, some t => isDefEq s t | none, none => pure LBool.undef /-- Support for constraints of the form `("..." =?= String.mk cs)` -/ def isDefEqStringLit (s t : Expr) : MetaM LBool := do let isDefEq (s t) : MetaM LBool := toLBoolM <| Meta.isExprDefEqAux s t if s.isStringLit && t.isAppOf ``String.mk then isDefEq s.toCtorIfLit t else if s.isAppOf `String.mk && t.isStringLit then isDefEq s t.toCtorIfLit else pure LBool.undef /-- Return `true` if `e` is of the form `fun (x_1 ... x_n) => ?m x_1 ... x_n)`, and `?m` is unassigned. Remark: `n` may be 0. -/ def isEtaUnassignedMVar (e : Expr) : MetaM Bool := do match e.etaExpanded? with | some (Expr.mvar mvarId) => if (← mvarId.isReadOnlyOrSyntheticOpaque) then pure false else if (← mvarId.isAssigned) then pure false else pure true | _ => pure false private def trySynthPending (e : Expr) : MetaM Bool := do let mvarId? ← getStuckMVar? e match mvarId? with | some mvarId => Meta.synthPending mvarId | none => pure false /-- Result type for `isDefEqArgsFirstPass`. -/ inductive DefEqArgsFirstPassResult where | /-- Failed to establish that explicit arguments are def-eq. Remark: higher output parameters, and parameters that depend on them are postponed. -/ failed | /-- Succeeded. The array `postponedImplicit` contains the position of the implicit arguments for which def-eq has been postponed. `postponedHO` contains the higher order output parameters, and parameters that depend on them. They should be processed after the implict ones. `postponedHO` is used to handle applications involving functions that contain higher order output parameters. Example: ```lean getElem : {cont : Type u_1} β†’ {idx : Type u_2} β†’ {elem : Type u_3} β†’ {dom : cont β†’ idx β†’ Prop} β†’ [self : GetElem cont idx elem dom] β†’ (xs : cont) β†’ (i : idx) β†’ (h : dom xs i) β†’ elem ``` The argumengs `dom` and `h` must be processed after all implicit arguments otherwise higher-order unification problems are generated. See issue #1299, when trying to solve ``` getElem ?a ?i ?h =?= getElem a i (Fin.val_lt_of_le i ...) ``` we have to solve the constraint ``` ?dom a i.val =?= LT.lt i.val (Array.size a) ``` by solving after the instance has been synthesized, we reduce this constraint to a simple check. -/ ok (postponedImplicit : Array Nat) (postponedHO : Array Nat) /-- First pass for `isDefEqArgs`. We unify explicit arguments, *and* easy cases Here, we say a case is easy if it is of the form ?m =?= t or t =?= ?m where `?m` is unassigned. These easy cases are not just an optimization. When `?m` is a function, by assigning it to t, we make sure a unification constraint (in the explicit part) ``` ?m t =?= f s ``` is not higher-order. We also handle the eta-expanded cases: ``` fun x₁ ... xβ‚™ => ?m x₁ ... xβ‚™ =?= t t =?= fun x₁ ... xβ‚™ => ?m x₁ ... xβ‚™ ``` This is important because type inference often produces eta-expanded terms, and without this extra case, we could introduce counter intuitive behavior. Pre: `paramInfo.size <= args₁.size = argsβ‚‚.size` See `DefEqArgsFirstPassResult` for additional information. -/ private def isDefEqArgsFirstPass (paramInfo : Array ParamInfo) (args₁ argsβ‚‚ : Array Expr) : MetaM DefEqArgsFirstPassResult := do let mut postponedImplicit := #[] let mut postponedHO := #[] for i in [:paramInfo.size] do let info := paramInfo[i]! let a₁ := args₁[i]! let aβ‚‚ := argsβ‚‚[i]! if info.dependsOnHigherOrderOutParam || info.higherOrderOutParam then trace[Meta.isDefEq] "found messy {a₁} =?= {aβ‚‚}" postponedHO := postponedHO.push i else if info.isExplicit then unless (← Meta.isExprDefEqAux a₁ aβ‚‚) do return .failed else if (← isEtaUnassignedMVar a₁ <||> isEtaUnassignedMVar aβ‚‚) then unless (← Meta.isExprDefEqAux a₁ aβ‚‚) do return .failed else postponedImplicit := postponedImplicit.push i return .ok postponedImplicit postponedHO private partial def isDefEqArgs (f : Expr) (args₁ argsβ‚‚ : Array Expr) : MetaM Bool := do unless args₁.size == argsβ‚‚.size do return false let finfo ← getFunInfoNArgs f args₁.size let .ok postponedImplicit postponedHO ← isDefEqArgsFirstPass finfo.paramInfo args₁ argsβ‚‚ | pure false -- finfo.paramInfo.size may be smaller than args₁.size for i in [finfo.paramInfo.size:args₁.size] do unless (← Meta.isExprDefEqAux args₁[i]! argsβ‚‚[i]!) do return false for i in postponedImplicit do /- Second pass: unify implicit arguments. In the second pass, we make sure we are unfolding at least non reducible definitions (default setting). -/ let a₁ := args₁[i]! let aβ‚‚ := argsβ‚‚[i]! let info := finfo.paramInfo[i]! if info.isInstImplicit then discard <| trySynthPending a₁ discard <| trySynthPending aβ‚‚ unless (← withAtLeastTransparency TransparencyMode.default <| Meta.isExprDefEqAux a₁ aβ‚‚) do return false for i in postponedHO do let a₁ := args₁[i]! let aβ‚‚ := argsβ‚‚[i]! let info := finfo.paramInfo[i]! if info.isInstImplicit then unless (← withAtLeastTransparency TransparencyMode.default <| Meta.isExprDefEqAux a₁ aβ‚‚) do return false else unless (← Meta.isExprDefEqAux a₁ aβ‚‚) do return false return true /-- Check whether the types of the free variables at `fvars` are definitionally equal to the types at `dsβ‚‚`. Pre: `fvars.size == dsβ‚‚.size` This method also updates the set of local instances, and invokes the continuation `k` with the updated set. We can't use `withNewLocalInstances` because the `isDeq fvarType dβ‚‚` may use local instances. -/ @[specialize] partial def isDefEqBindingDomain (fvars : Array Expr) (dsβ‚‚ : Array Expr) (k : MetaM Bool) : MetaM Bool := let rec loop (i : Nat) := do if h : i < fvars.size then do let fvar := fvars.get ⟨i, h⟩ let fvarDecl ← getFVarLocalDecl fvar let fvarType := fvarDecl.type let dβ‚‚ := dsβ‚‚[i]! if (← Meta.isExprDefEqAux fvarType dβ‚‚) then match (← isClass? fvarType) with | some className => withNewLocalInstance className fvar <| loop (i+1) | none => loop (i+1) else pure false else k loop 0 /-- Auxiliary function for `isDefEqBinding` for handling binders `forall/fun`. It accumulates the new free variables in `fvars`, and declare them at `lctx`. We use the domain types of `e₁` to create the new free variables. We store the domain types of `eβ‚‚` at `dsβ‚‚`. -/ private partial def isDefEqBindingAux (lctx : LocalContext) (fvars : Array Expr) (e₁ eβ‚‚ : Expr) (dsβ‚‚ : Array Expr) : MetaM Bool := let process (n : Name) (d₁ dβ‚‚ b₁ bβ‚‚ : Expr) : MetaM Bool := do let d₁ := d₁.instantiateRev fvars let dβ‚‚ := dβ‚‚.instantiateRev fvars let fvarId ← mkFreshFVarId let lctx := lctx.mkLocalDecl fvarId n d₁ let fvars := fvars.push (mkFVar fvarId) isDefEqBindingAux lctx fvars b₁ bβ‚‚ (dsβ‚‚.push dβ‚‚) match e₁, eβ‚‚ with | Expr.forallE n d₁ b₁ _, Expr.forallE _ dβ‚‚ bβ‚‚ _ => process n d₁ dβ‚‚ b₁ bβ‚‚ | Expr.lam n d₁ b₁ _, Expr.lam _ dβ‚‚ bβ‚‚ _ => process n d₁ dβ‚‚ b₁ bβ‚‚ | _, _ => withReader (fun ctx => { ctx with lctx := lctx }) do isDefEqBindingDomain fvars dsβ‚‚ do Meta.isExprDefEqAux (e₁.instantiateRev fvars) (eβ‚‚.instantiateRev fvars) @[inline] private def isDefEqBinding (a b : Expr) : MetaM Bool := do let lctx ← getLCtx isDefEqBindingAux lctx #[] a b #[] private def checkTypesAndAssign (mvar : Expr) (v : Expr) : MetaM Bool := traceCtx `Meta.isDefEq.assign.checkTypes do if !mvar.isMVar then trace[Meta.isDefEq.assign.final] "metavariable expected at {mvar} := {v}" return false else -- must check whether types are definitionally equal or not, before assigning and returning true let mvarType ← inferType mvar let vType ← inferType v if (← withTransparency TransparencyMode.default <| Meta.isExprDefEqAux mvarType vType) then trace[Meta.isDefEq.assign.final] "{mvar} := {v}" mvar.mvarId!.assign v pure true else trace[Meta.isDefEq.assign.typeMismatch] "{mvar} : {mvarType} := {v} : {vType}" pure false /-- Auxiliary method for solving constraints of the form `?m xs := v`. It creates a lambda using `mkLambdaFVars ys v`, where `ys` is a superset of `xs`. `ys` is often equal to `xs`. It is a bigger when there are let-declaration dependencies in `xs`. For example, suppose we have `xs` of the form `#[a, c]` where ``` a : Nat b : Nat := f a c : b = a ``` In this scenario, the type of `?m` is `(x1 : Nat) -> (x2 : f x1 = x1) -> C[x1, x2]`, and type of `v` is `C[a, c]`. Note that, `?m a c` is type correct since `f a = a` is definitionally equal to the type of `c : b = a`, and the type of `?m a c` is equal to the type of `v`. Note that `fun xs => v` is the term `fun (x1 : Nat) (x2 : b = x1) => v` which has type `(x1 : Nat) -> (x2 : b = x1) -> C[x1, x2]` which is not definitionally equal to the type of `?m`, and may not even be type correct. The issue here is that we are not capturing the `let`-declarations. This method collects let-declarations `y` occurring between `xs[0]` and `xs.back` s.t. some `x` in `xs` depends on `y`. `ys` is the `xs` with these extra let-declarations included. In the example above, `ys` is `#[a, b, c]`, and `mkLambdaFVars ys v` produces `fun a => let b := f a; fun (c : b = a) => v` which has a type definitionally equal to the type of `?m`. Recall that the method `checkAssignment` ensures `v` does not contain offending `let`-declarations. This method assumes that for any `xs[i]` and `xs[j]` where `i < j`, we have that `index of xs[i]` < `index of xs[j]`. where the index is the position in the local context. -/ private partial def mkLambdaFVarsWithLetDeps (xs : Array Expr) (v : Expr) : MetaM (Option Expr) := do if not (← hasLetDeclsInBetween) then mkLambdaFVars xs v else let ys ← addLetDeps mkLambdaFVars ys v where /-- Return true if there are let-declarions between `xs[0]` and `xs[xs.size-1]`. We use it a quick-check to avoid the more expensive collection procedure. -/ hasLetDeclsInBetween : MetaM Bool := do let check (lctx : LocalContext) : Bool := Id.run do let start := lctx.getFVar! xs[0]! |>.index let stop := lctx.getFVar! xs.back |>.index for i in [start+1:stop] do match lctx.getAt? i with | some localDecl => if localDecl.isLet then return true | _ => pure () return false if xs.size <= 1 then return false else return check (← getLCtx) /-- Traverse `e` and stores in the state `NameHashSet` any let-declaration with index greater than `(← read)`. The context `Nat` is the position of `xs[0]` in the local context. -/ collectLetDeclsFrom (e : Expr) : ReaderT Nat (StateRefT FVarIdHashSet MetaM) Unit := do let rec visit (e : Expr) : MonadCacheT Expr Unit (ReaderT Nat (StateRefT FVarIdHashSet MetaM)) Unit := checkCache e fun _ => do match e with | Expr.forallE _ d b _ => visit d; visit b | Expr.lam _ d b _ => visit d; visit b | Expr.letE _ t v b _ => visit t; visit v; visit b | Expr.app f a => visit f; visit a | Expr.mdata _ b => visit b | Expr.proj _ _ b => visit b | Expr.fvar fvarId => let localDecl ← fvarId.getDecl if localDecl.isLet && localDecl.index > (← read) then modify fun s => s.insert localDecl.fvarId | _ => pure () visit (← instantiateMVars e) |>.run /-- Auxiliary definition for traversing all declarations between `xs[0]` ... `xs.back` backwards. The `Nat` argument is the current position in the local context being visited, and it is less than or equal to the position of `xs.back` in the local context. The `Nat` context `(← read)` is the position of `xs[0]` in the local context. -/ collectLetDepsAux : Nat β†’ ReaderT Nat (StateRefT FVarIdHashSet MetaM) Unit | 0 => return () | i+1 => do if i+1 == (← read) then return () else match (← getLCtx).getAt? (i+1) with | none => collectLetDepsAux i | some localDecl => if (← get).contains localDecl.fvarId then collectLetDeclsFrom localDecl.type match localDecl.value? with | some val => collectLetDeclsFrom val | _ => pure () collectLetDepsAux i /-- Computes the set `ys`. It is a set of `FVarId`s, -/ collectLetDeps : MetaM FVarIdHashSet := do let lctx ← getLCtx let start := lctx.getFVar! xs[0]! |>.index let stop := lctx.getFVar! xs.back |>.index let s := xs.foldl (init := {}) fun s x => s.insert x.fvarId! let (_, s) ← collectLetDepsAux stop |>.run start |>.run s return s /-- Computes the array `ys` containing let-decls between `xs[0]` and `xs.back` that some `x` in `xs` depends on. -/ addLetDeps : MetaM (Array Expr) := do let lctx ← getLCtx let s ← collectLetDeps /- Convert `s` into the array `ys` -/ let start := lctx.getFVar! xs[0]! |>.index let stop := lctx.getFVar! xs.back |>.index let mut ys := #[] for i in [start:stop+1] do match lctx.getAt? i with | none => pure () | some localDecl => if s.contains localDecl.fvarId then ys := ys.push localDecl.toExpr return ys /-! Each metavariable is declared in a particular local context. We use the notation `C |- ?m : t` to denote a metavariable `?m` that was declared at the local context `C` with type `t` (see `MetavarDecl`). We also use `?m@C` as a shorthand for `C |- ?m : t` where `t` is the type of `?m`. The following method process the unification constraint ?m@C a₁ ... aβ‚™ =?= t We say the unification constraint is a pattern IFF 1) `a₁ ... aβ‚™` are pairwise distinct free variables that are ​*not*​ let-variables. 2) `a₁ ... aβ‚™` are not in `C` 3) `t` only contains free variables in `C` and/or `{a₁, ..., aβ‚™}` 4) For every metavariable `?m'@C'` occurring in `t`, `C'` is a subprefix of `C` 5) `?m` does not occur in `t` Claim: we don't have to check free variable declarations. That is, if `t` contains a reference to `x : A := v`, we don't need to check `v`. Reason: The reference to `x` is a free variable, and it must be in `C` (by 1 and 3). If `x` is in `C`, then any metavariable occurring in `v` must have been defined in a strict subprefix of `C`. So, condition 4 and 5 are satisfied. If the conditions above have been satisfied, then the solution for the unification constrain is ?m := fun a₁ ... aβ‚™ => t Now, we consider some workarounds/approximations. A1) Suppose `t` contains a reference to `x : A := v` and `x` is not in `C` (failed condition 3) (precise) solution: unfold `x` in `t`. A2) Suppose some `aα΅’` is in `C` (failed condition 2) (approximated) solution (when `config.quasiPatternApprox` is set to true) : ignore condition and also use ?m := fun a₁ ... aβ‚™ => t Here is an example where this approximation fails: Given `C` containing `a : nat`, consider the following two constraints ?m@C a =?= a ?m@C b =?= a If we use the approximation in the first constraint, we get ?m := fun x => x when we apply this solution to the second one we get a failure. IMPORTANT: When applying this approximation we need to make sure the abstracted term `fun a₁ ... aβ‚™ => t` is type correct. The check can only be skipped in the pattern case described above. Consider the following example. Given the local context (Ξ± : Type) (a : Ξ±) we try to solve ?m Ξ± =?= @id Ξ± a If we use the approximation above we obtain: ?m := (fun Ξ±' => @id Ξ±' a) which is a type incorrect term. `a` has type `Ξ±` but it is expected to have type `Ξ±'`. The problem occurs because the right hand side contains a free variable `a` that depends on the free variable `Ξ±` being abstracted. Note that this dependency cannot occur in patterns. We can address this by type checking the term after abstraction. This is not a significant performance bottleneck because this case doesn't happen very often in practice (262 times when compiling stdlib on Jan 2018). The second example is trickier, but it also occurs less frequently (8 times when compiling stdlib on Jan 2018, and all occurrences were at Init/Control when we define monads and auxiliary combinators for them). We considered three options for the addressing the issue on the second example: A3) `a₁ ... aβ‚™` are not pairwise distinct (failed condition 1). In Lean3, we would try to approximate this case using an approach similar to A2. However, this approximation complicates the code, and is never used in the Lean3 stdlib and mathlib. A4) `t` contains a metavariable `?m'@C'` where `C'` is not a subprefix of `C`. If `?m'` is assigned, we substitute. If not, we create an auxiliary metavariable with a smaller scope. Actually, we let `elimMVarDeps` at `MetavarContext.lean` to perform this step. A5) If some `aα΅’` is not a free variable, then we use first-order unification (if `config.foApprox` is set to true) ?m a_1 ... a_i a_{i+1} ... a_{i+k} =?= f b_1 ... b_k reduces to ?M a_1 ... a_i =?= f a_{i+1} =?= b_1 ... a_{i+k} =?= b_k A6) If (m =?= v) is of the form ?m a_1 ... a_n =?= ?m b_1 ... b_k then we use first-order unification (if `config.foApprox` is set to true) A7) When `foApprox`, we may use another approximation (`constApprox`) for solving constraints of the form ``` ?m s₁ ... sβ‚™ =?= t ``` where `s₁ ... sβ‚™` are arbitrary terms. We solve them by assigning the constant function to `?m`. ``` ?m := fun _ ... _ => t ``` In general, this approximation may produce bad solutions, and may prevent coercions from being tried. For example, consider the term `pure (x > 0)` with inferred type `?m Prop` and expected type `IO Bool`. In this situation, the elaborator generates the unification constraint ``` ?m Prop =?= IO Bool ``` It is not a higher-order pattern, nor first-order approximation is applicable. However, constant approximation produces the bogus solution `?m := fun _ => IO Bool`, and prevents the system from using the coercion from the decidable proposition `x > 0` to `Bool`. On the other hand, the constant approximation is desirable for elaborating the term ``` let f (x : _) := pure "hello"; f () ``` with expected type `IO String`. In this example, the following unification contraint is generated. ``` ?m () String =?= IO String ``` It is not a higher-order pattern, first-order approximation reduces it to ``` ?m () =?= IO ``` which fails to be solved. However, constant approximation solves it by assigning ``` ?m := fun _ => IO ``` Note that `f`s type is `(x : ?Ξ±) -> ?m x String`. The metavariable `?m` may depend on `x`. If `constApprox` is set to true, we use constant approximation. Otherwise, we use a heuristic to decide whether we should apply it or not. The heuristic is based on observing where the constraints above come from. In the first example, the constraint `?m Prop =?= IO Bool` come from polymorphic method where `?m` is expected to be a **function** of type `Type -> Type`. In the second example, the first argument of `?m` is used to model a **potential** dependency on `x`. By using constant approximation here, we are just saying the type of `f` does **not** depend on `x`. We claim this is a reasonable approximation in practice. Moreover, it is expected by any functional programmer used to non-dependently type languages (e.g., Haskell). We distinguish the two cases above by using the field `numScopeArgs` at `MetavarDecl`. This fiels tracks how many metavariable arguments are representing dependencies. -/ def mkAuxMVar (lctx : LocalContext) (localInsts : LocalInstances) (type : Expr) (numScopeArgs : Nat := 0) : MetaM Expr := do mkFreshExprMVarAt lctx localInsts type MetavarKind.natural Name.anonymous numScopeArgs namespace CheckAssignment builtin_initialize checkAssignmentExceptionId : InternalExceptionId ← registerInternalExceptionId `checkAssignment builtin_initialize outOfScopeExceptionId : InternalExceptionId ← registerInternalExceptionId `outOfScope structure State where cache : ExprStructMap Expr := {} structure Context where mvarId : MVarId mvarDecl : MetavarDecl fvars : Array Expr hasCtxLocals : Bool rhs : Expr abbrev CheckAssignmentM := ReaderT Context $ StateRefT State MetaM def throwCheckAssignmentFailure : CheckAssignmentM Ξ± := throw <| Exception.internal checkAssignmentExceptionId def throwOutOfScopeFVar : CheckAssignmentM Ξ± := throw <| Exception.internal outOfScopeExceptionId private def findCached? (e : Expr) : CheckAssignmentM (Option Expr) := do return (← get).cache.find? e private def cache (e r : Expr) : CheckAssignmentM Unit := do modify fun s => { s with cache := s.cache.insert e r } instance : MonadCache Expr Expr CheckAssignmentM where findCached? := findCached? cache := cache @[inline] private def visit (f : Expr β†’ CheckAssignmentM Expr) (e : Expr) : CheckAssignmentM Expr := if !e.hasExprMVar && !e.hasFVar then pure e else checkCache e (fun _ => f e) private def addAssignmentInfo (msg : MessageData) : CheckAssignmentM MessageData := do let ctx ← read return m!"{msg} @ {mkMVar ctx.mvarId} {ctx.fvars} := {ctx.rhs}" @[inline] def run (x : CheckAssignmentM Expr) (mvarId : MVarId) (fvars : Array Expr) (hasCtxLocals : Bool) (v : Expr) : MetaM (Option Expr) := do let mvarDecl ← mvarId.getDecl let ctx := { mvarId := mvarId, mvarDecl := mvarDecl, fvars := fvars, hasCtxLocals := hasCtxLocals, rhs := v : Context } let x : CheckAssignmentM (Option Expr) := catchInternalIds [outOfScopeExceptionId, checkAssignmentExceptionId] (do let e ← x; return some e) (fun _ => pure none) x.run ctx |>.run' {} mutual partial def checkFVar (fvar : Expr) : CheckAssignmentM Expr := do let ctxMeta ← readThe Meta.Context let ctx ← read if ctx.mvarDecl.lctx.containsFVar fvar then pure fvar else let lctx := ctxMeta.lctx match lctx.findFVar? fvar with | some (.ldecl (value := v) ..) => visit check v | _ => if ctx.fvars.contains fvar then pure fvar else traceM `Meta.isDefEq.assign.outOfScopeFVar do addAssignmentInfo fvar throwOutOfScopeFVar partial def checkMVar (mvar : Expr) : CheckAssignmentM Expr := do let mvarId := mvar.mvarId! let ctx ← read if mvarId == ctx.mvarId then traceM `Meta.isDefEq.assign.occursCheck <| addAssignmentInfo "occurs check failed" throwCheckAssignmentFailure else match (← getExprMVarAssignment? mvarId) with | some v => check v | none => match (← mvarId.findDecl?) with | none => throwUnknownMVar mvarId | some mvarDecl => if ctx.hasCtxLocals then throwCheckAssignmentFailure -- It is not a pattern, then we fail and fall back to FO unification else if mvarDecl.lctx.isSubPrefixOf ctx.mvarDecl.lctx ctx.fvars then /- The local context of `mvar` - free variables being abstracted is a subprefix of the metavariable being assigned. We "substract" variables being abstracted because we use `elimMVarDeps` -/ pure mvar else if mvarDecl.depth != (← getMCtx).depth || mvarDecl.kind.isSyntheticOpaque then traceM `Meta.isDefEq.assign.readOnlyMVarWithBiggerLCtx <| addAssignmentInfo (mkMVar mvarId) throwCheckAssignmentFailure else let ctxMeta ← readThe Meta.Context if ctxMeta.config.ctxApprox && ctx.mvarDecl.lctx.isSubPrefixOf mvarDecl.lctx then /- Create an auxiliary metavariable with a smaller context and "checked" type. Note that `mvarType` may be different from `mvarDecl.type`. Example: `mvarType` contains a metavariable that we also need to reduce the context. We remove from `ctx.mvarDecl.lctx` any variable that is not in `mvarDecl.lctx` or in `ctx.fvars`. We don't need to remove the ones in `ctx.fvars` because `elimMVarDeps` will take care of them. First, we collect `toErase` the variables that need to be erased. Notat that if a variable is `ctx.fvars`, but it depends on variable at `toErase`, we must also erase it. -/ let toErase ← mvarDecl.lctx.foldlM (init := #[]) fun toErase localDecl => do if ctx.mvarDecl.lctx.contains localDecl.fvarId then return toErase else if ctx.fvars.any fun fvar => fvar.fvarId! == localDecl.fvarId then if (← findLocalDeclDependsOn localDecl fun fvarId => toErase.contains fvarId) then -- localDecl depends on a variable that will be erased. So, we must add it to `toErase` too return toErase.push localDecl.fvarId else return toErase else return toErase.push localDecl.fvarId let lctx := toErase.foldl (init := mvarDecl.lctx) fun lctx toEraseFVar => lctx.erase toEraseFVar /- Compute new set of local instances. -/ let localInsts := mvarDecl.localInstances.filter fun localInst => toErase.contains localInst.fvar.fvarId! let mvarType ← check mvarDecl.type let newMVar ← mkAuxMVar lctx localInsts mvarType mvarDecl.numScopeArgs mvarId.assign newMVar pure newMVar else traceM `Meta.isDefEq.assign.readOnlyMVarWithBiggerLCtx <| addAssignmentInfo (mkMVar mvarId) throwCheckAssignmentFailure /-- Auxiliary function used to "fix" subterms of the form `?m x_1 ... x_n` where `x_i`s are free variables, and one of them is out-of-scope. See `Expr.app` case at `check`. If `ctxApprox` is true, then we solve this case by creating a fresh metavariable ?n with the correct scope, an assigning `?m := fun _ ... _ => ?n` -/ partial def assignToConstFun (mvar : Expr) (numArgs : Nat) (newMVar : Expr) : MetaM Bool := do let mvarType ← inferType mvar forallBoundedTelescope mvarType numArgs fun xs _ => do if xs.size != numArgs then pure false else let some v ← mkLambdaFVarsWithLetDeps xs newMVar | return false match (← checkAssignmentAux mvar.mvarId! #[] false v) with | some v => checkTypesAndAssign mvar v | none => return false -- See checkAssignment partial def checkAssignmentAux (mvarId : MVarId) (fvars : Array Expr) (hasCtxLocals : Bool) (v : Expr) : MetaM (Option Expr) := do run (check v) mvarId fvars hasCtxLocals v partial def checkApp (e : Expr) : CheckAssignmentM Expr := e.withApp fun f args => do let ctxMeta ← readThe Meta.Context if f.isMVar && ctxMeta.config.ctxApprox && args.all Expr.isFVar then let f ← visit checkMVar f catchInternalId outOfScopeExceptionId (do let args ← args.mapM (visit check) return mkAppN f args) (fun ex => do if !f.isMVar then throw ex else if (← f.mvarId!.isDelayedAssigned) then throw ex else let eType ← inferType e let mvarType ← check eType /- Create an auxiliary metavariable with a smaller context and "checked" type, assign `?f := fun _ => ?newMVar` Note that `mvarType` may be different from `eType`. -/ let ctx ← read let newMVar ← mkAuxMVar ctx.mvarDecl.lctx ctx.mvarDecl.localInstances mvarType if (← assignToConstFun f args.size newMVar) then pure newMVar else throw ex) else let f ← visit check f let args ← args.mapM (visit check) return mkAppN f args partial def check (e : Expr) : CheckAssignmentM Expr := do match e with | Expr.mdata _ b => return e.updateMData! (← visit check b) | Expr.proj _ _ s => return e.updateProj! (← visit check s) | Expr.lam _ d b _ => return e.updateLambdaE! (← visit check d) (← visit check b) | Expr.forallE _ d b _ => return e.updateForallE! (← visit check d) (← visit check b) | Expr.letE _ t v b _ => return e.updateLet! (← visit check t) (← visit check v) (← visit check b) | Expr.bvar .. => return e | Expr.sort .. => return e | Expr.const .. => return e | Expr.lit .. => return e | Expr.fvar .. => visit checkFVar e | Expr.mvar .. => visit checkMVar e | Expr.app .. => checkApp e -- TODO: investigate whether the following feature is too expensive or not /- catchInternalIds [checkAssignmentExceptionId, outOfScopeExceptionId] (checkApp e) fun ex => do let e' ← whnfR e if e != e' then check e' else throw ex -/ end end CheckAssignment namespace CheckAssignmentQuick partial def check (hasCtxLocals : Bool) (mctx : MetavarContext) (lctx : LocalContext) (mvarDecl : MetavarDecl) (mvarId : MVarId) (fvars : Array Expr) (e : Expr) : Bool := let rec visit (e : Expr) : Bool := if !e.hasExprMVar && !e.hasFVar then true else match e with | Expr.mdata _ b => visit b | Expr.proj _ _ s => visit s | Expr.app f a => visit f && visit a | Expr.lam _ d b _ => visit d && visit b | Expr.forallE _ d b _ => visit d && visit b | Expr.letE _ t v b _ => visit t && visit v && visit b | Expr.bvar .. => true | Expr.sort .. => true | Expr.const .. => true | Expr.lit .. => true | Expr.fvar fvarId .. => if mvarDecl.lctx.contains fvarId then true else match lctx.find? fvarId with | some (LocalDecl.ldecl ..) => false -- need expensive CheckAssignment.check | _ => if fvars.any fun x => x.fvarId! == fvarId then true else false -- We could throw an exception here, but we would have to use ExceptM. So, we let CheckAssignment.check do it | Expr.mvar mvarId' => match mctx.getExprAssignmentCore? mvarId' with | some _ => false -- use CheckAssignment.check to instantiate | none => if mvarId' == mvarId then false -- occurs check failed, use CheckAssignment.check to throw exception else match mctx.findDecl? mvarId' with | none => false | some mvarDecl' => if hasCtxLocals then false -- use CheckAssignment.check else if mvarDecl'.lctx.isSubPrefixOf mvarDecl.lctx fvars then true else false -- use CheckAssignment.check visit e end CheckAssignmentQuick /-- Auxiliary function for handling constraints of the form `?m a₁ ... aβ‚™ =?= v`. It will check whether we can perform the assignment ``` ?m := fun fvars => v ``` The result is `none` if the assignment can't be performed. The result is `some newV` where `newV` is a possibly updated `v`. This method may need to unfold let-declarations. -/ def checkAssignment (mvarId : MVarId) (fvars : Array Expr) (v : Expr) : MetaM (Option Expr) := do /- Check whether `mvarId` occurs in the type of `fvars` or not. If it does, return `none` to prevent us from creating the cyclic assignment `?m := fun fvars => v` -/ for fvar in fvars do unless (← occursCheck mvarId (← inferType fvar)) do return none if !v.hasExprMVar && !v.hasFVar then pure (some v) else let mvarDecl ← mvarId.getDecl let hasCtxLocals := fvars.any fun fvar => mvarDecl.lctx.containsFVar fvar let ctx ← read let mctx ← getMCtx if CheckAssignmentQuick.check hasCtxLocals mctx ctx.lctx mvarDecl mvarId fvars v then pure (some v) else let v ← instantiateMVars v CheckAssignment.checkAssignmentAux mvarId fvars hasCtxLocals v private def processAssignmentFOApproxAux (mvar : Expr) (args : Array Expr) (v : Expr) : MetaM Bool := match v with | .mdata _ e => processAssignmentFOApproxAux mvar args e | Expr.app f a => if args.isEmpty then pure false else Meta.isExprDefEqAux args.back a <&&> Meta.isExprDefEqAux (mkAppRange mvar 0 (args.size - 1) args) f | _ => pure false /-- Auxiliary method for applying first-order unification. It is an approximation. Remark: this method is trying to solve the unification constraint: ?m a₁ ... aβ‚™ =?= v It is uses processAssignmentFOApproxAux, if it fails, it tries to unfold `v`. We have added support for unfolding here because we want to be able to solve unification problems such as ?m Unit =?= ITactic where `ITactic` is defined as def ITactic := Tactic Unit -/ private partial def processAssignmentFOApprox (mvar : Expr) (args : Array Expr) (v : Expr) : MetaM Bool := let rec loop (v : Expr) := do let cfg ← getConfig if !cfg.foApprox then pure false else trace[Meta.isDefEq.foApprox] "{mvar} {args} := {v}" let v := v.headBeta if (← checkpointDefEq <| processAssignmentFOApproxAux mvar args v) then pure true else match (← unfoldDefinition? v) with | none => pure false | some v => loop v loop v private partial def simpAssignmentArgAux (e : Expr) : MetaM Expr := do match e with | .mdata _ e => simpAssignmentArgAux e | .fvar fvarId => let some value ← fvarId.getValue? | return e simpAssignmentArgAux value | _ => return e /-- Auxiliary procedure for processing `?m a₁ ... aβ‚™ =?= v`. We apply it to each `aα΅’`. It instantiates assigned metavariables if `aα΅’` is of the form `f[?n] b₁ ... bβ‚˜`, and then removes metadata, and zeta-expand let-decls. -/ private def simpAssignmentArg (arg : Expr) : MetaM Expr := do let arg ← if arg.getAppFn.hasExprMVar then instantiateMVars arg else pure arg simpAssignmentArgAux arg /-- Assign `mvar := fun a_1 ... a_{numArgs} => v`. We use it at `processConstApprox` and `isDefEqMVarSelf` -/ private def assignConst (mvar : Expr) (numArgs : Nat) (v : Expr) : MetaM Bool := do let mvarDecl ← mvar.mvarId!.getDecl forallBoundedTelescope mvarDecl.type numArgs fun xs _ => do if xs.size != numArgs then pure false else let some v ← mkLambdaFVarsWithLetDeps xs v | pure false match (← checkAssignment mvar.mvarId! #[] v) with | none => pure false | some v => trace[Meta.isDefEq.constApprox] "{mvar} := {v}" checkTypesAndAssign mvar v /-- Auxiliary procedure for solving `?m args =?= v` when `args[:patternVarPrefix]` contains only pairwise distinct free variables. Let `args[:patternVarPrefix] = #[a₁, ..., aβ‚™]`, and `args[patternVarPrefix:] = #[b₁, ..., bα΅’]`, this procedure first reduces the constraint to ``` ?m a₁ ... aβ‚™ =?= fun x₁ ... xα΅’ => v ``` where the left-hand-side is a constant function. Then, it tries to find the longest prefix `#[a₁, ..., aβ±Ό]` of `#[a₁, ..., aβ‚™]` such that the following assignment is valid. ``` ?m := fun y₁ ... yβ€Œβ±Ό => (fun y_{j+1} ... yβ‚™ x₁ ... xα΅’ => v)[a₁/y₁, .., aβ±Ό/yβ±Ό] ``` That is, after the longest prefix is found, we solve the contraint as the lhs was a pattern. See the definition of "pattern" above. -/ private partial def processConstApprox (mvar : Expr) (args : Array Expr) (patternVarPrefix : Nat) (v : Expr) : MetaM Bool := do trace[Meta.isDefEq.constApprox] "{mvar} {args} := {v}" let rec defaultCase : MetaM Bool := assignConst mvar args.size v let cfg ← getConfig let mvarId := mvar.mvarId! let mvarDecl ← mvarId.getDecl let numArgs := args.size if mvarDecl.numScopeArgs != numArgs && !cfg.constApprox then return false else if patternVarPrefix == 0 then defaultCase else let argsPrefix : Array Expr := args[:patternVarPrefix] let type ← instantiateForall mvarDecl.type argsPrefix let suffixSize := numArgs - argsPrefix.size forallBoundedTelescope type suffixSize fun xs _ => do if xs.size != suffixSize then defaultCase else let some v ← mkLambdaFVarsWithLetDeps xs v | defaultCase let rec go (argsPrefix : Array Expr) (v : Expr) : MetaM Bool := do trace[Meta.isDefEq] "processConstApprox.go {mvar} {argsPrefix} := {v}" let rec cont : MetaM Bool := do if argsPrefix.isEmpty then defaultCase else let some v ← mkLambdaFVarsWithLetDeps #[argsPrefix.back] v | defaultCase go argsPrefix.pop v match (← checkAssignment mvarId argsPrefix v) with | none => cont | some vNew => let some vNew ← mkLambdaFVarsWithLetDeps argsPrefix vNew | cont if argsPrefix.any (fun arg => mvarDecl.lctx.containsFVar arg) then /- We need to type check `vNew` because abstraction using `mkLambdaFVars` may have produced a type incorrect term. See discussion at A2 -/ (isTypeCorrect vNew <&&> checkTypesAndAssign mvar vNew) <||> cont else checkTypesAndAssign mvar vNew <||> cont go argsPrefix v /-- Tries to solve `?m a₁ ... aβ‚™ =?= v` by assigning `?m`. It assumes `?m` is unassigned. -/ private partial def processAssignment (mvarApp : Expr) (v : Expr) : MetaM Bool := traceCtx `Meta.isDefEq.assign do trace[Meta.isDefEq.assign] "{mvarApp} := {v}" let mvar := mvarApp.getAppFn let mvarDecl ← mvar.mvarId!.getDecl let rec process (i : Nat) (args : Array Expr) (v : Expr) := do let cfg ← getConfig let useFOApprox (args : Array Expr) : MetaM Bool := processAssignmentFOApprox mvar args v <||> processConstApprox mvar args i v if h : i < args.size then let arg := args.get ⟨i, h⟩ let arg ← simpAssignmentArg arg let args := args.set ⟨i, h⟩ arg match arg with | Expr.fvar fvarId => if args[0:i].any fun prevArg => prevArg == arg then useFOApprox args else if mvarDecl.lctx.contains fvarId && !cfg.quasiPatternApprox then useFOApprox args else process (i+1) args v | _ => useFOApprox args else let v ← instantiateMVars v -- enforce A4 if v.getAppFn == mvar then -- using A6 useFOApprox args else let mvarId := mvar.mvarId! match (← checkAssignment mvarId args v) with | none => useFOApprox args | some v => do trace[Meta.isDefEq.assign.beforeMkLambda] "{mvar} {args} := {v}" let some v ← mkLambdaFVarsWithLetDeps args v | return false if args.any (fun arg => mvarDecl.lctx.containsFVar arg) then /- We need to type check `v` because abstraction using `mkLambdaFVars` may have produced a type incorrect term. See discussion at A2 -/ if (← isTypeCorrect v) then checkTypesAndAssign mvar v else trace[Meta.isDefEq.assign.typeError] "{mvar} := {v}" useFOApprox args else checkTypesAndAssign mvar v process 0 mvarApp.getAppArgs v /-- Similar to processAssignment, but if it fails, compute v's whnf and try again. This helps to solve constraints such as `?m =?= { Ξ± := ?m, ... }.Ξ±` Note this is not perfect solution since we still fail occurs check for constraints such as ```lean ?m =?= List { Ξ± := ?m, Ξ² := Nat }.Ξ² ``` -/ private def processAssignment' (mvarApp : Expr) (v : Expr) : MetaM Bool := do if (← processAssignment mvarApp v) then return true else let vNew ← whnf v if vNew != v then if mvarApp == vNew then return true else processAssignment mvarApp vNew else return false private def isDeltaCandidate? (t : Expr) : MetaM (Option ConstantInfo) := do match t.getAppFn with | Expr.const c _ => match (← getConst? c) with | r@(some info) => if info.hasValue then return r else return none | _ => return none | _ => pure none /-- Auxiliary method for isDefEqDelta -/ private def isListLevelDefEq (us vs : List Level) : MetaM LBool := toLBoolM <| isListLevelDefEqAux us vs /-- Auxiliary method for isDefEqDelta -/ private def isDefEqLeft (fn : Name) (t s : Expr) : MetaM LBool := do trace[Meta.isDefEq.delta.unfoldLeft] fn toLBoolM <| Meta.isExprDefEqAux t s /-- Auxiliary method for isDefEqDelta -/ private def isDefEqRight (fn : Name) (t s : Expr) : MetaM LBool := do trace[Meta.isDefEq.delta.unfoldRight] fn toLBoolM <| Meta.isExprDefEqAux t s /-- Auxiliary method for isDefEqDelta -/ private def isDefEqLeftRight (fn : Name) (t s : Expr) : MetaM LBool := do trace[Meta.isDefEq.delta.unfoldLeftRight] fn toLBoolM <| Meta.isExprDefEqAux t s /-- Try to solve `f a₁ ... aβ‚™ =?= f b₁ ... bβ‚™` by solving `a₁ =?= b₁, ..., aβ‚™ =?= bβ‚™`. Auxiliary method for isDefEqDelta -/ private def tryHeuristic (t s : Expr) : MetaM Bool := do let mut t := t let mut s := s let tFn := t.getAppFn let sFn := s.getAppFn let info ← getConstInfo tFn.constName! /- We only use the heuristic when `f` is a regular definition or an auxiliary `match` application. That is, it is not marked an abbreviation (e.g., a user-facing projection) or as opaque (e.g., proof). We check whether terms contain metavariables to make sure we can solve constraints such as `S.proj ?x =?= S.proj t` without performing delta-reduction. That is, we are assuming the heuristic implemented by this method is seldom effective when `t` and `s` do not have metavariables, are not structurally equal, and `f` is an abbreviation. On the other hand, by unfolding `f`, we often produce smaller terms. Recall that auxiliary `match` definitions are marked as abbreviations, but we must use the heuristic on them since they will not be unfolded when smartUnfolding is turned on. The abbreviation annotation in this case is used to help the kernel type checker. -/ unless info.hints.isRegular || isMatcherCore (← getEnv) tFn.constName! do unless t.hasExprMVar || s.hasExprMVar do return false traceCtx `Meta.isDefEq.delta do /- We process arguments before universe levels to reduce a source of brittleness in the TC procedure. In the TC procedure, we can solve problems containing metavariables. If the TC procedure tries to assign one of these metavariables, it interrupts the search using a "stuck" exception. The elaborator catches it, and "interprets" it as "we should try again later". Now suppose we have a TC problem, and there are two "local" candidate instances we can try: "bad" and "good". The "bad" candidate is stuck because of a universe metavariable in the TC problem. If we try "bad" first, the TC procedure is interrupted. Moreover, if we have ignored the exception, "bad" would fail anyway trying to assign two different free variables `Ξ± =?= Ξ²`. Example: `Preorder.{?u} Ξ± =?= Preorder.{?v} Ξ²`, where `?u` and `?v` are universe metavariables that were not created by the TC procedure. The key issue here is that we have an `isDefEq t s` invocation that is interrupted by the "stuck" exception, but it would have failed anyway if we had continued processing it. By solving the arguments first, we make the example above fail without throwing the "stuck" exception. TODO: instead of throwing an exception as soon as we get stuck, we should just set a flag. Then the entry-point for `isDefEq` checks the flag before returning `true`. -/ checkpointDefEq do let b ← isDefEqArgs tFn t.getAppArgs s.getAppArgs <&&> isListLevelDefEqAux tFn.constLevels! sFn.constLevels! unless b do trace[Meta.isDefEq.delta] "heuristic failed {t} =?= {s}" pure b /-- Auxiliary method for isDefEqDelta -/ private abbrev unfold (e : Expr) (failK : MetaM Ξ±) (successK : Expr β†’ MetaM Ξ±) : MetaM Ξ± := do match (← unfoldDefinition? e) with | some e => successK e | none => failK /-- Auxiliary method for isDefEqDelta -/ private def unfoldBothDefEq (fn : Name) (t s : Expr) : MetaM LBool := do match t, s with | Expr.const _ ls₁, Expr.const _ lsβ‚‚ => isListLevelDefEq ls₁ lsβ‚‚ | Expr.app _ _, Expr.app _ _ => if (← tryHeuristic t s) then pure LBool.true else unfold t (unfold s (pure LBool.undef) (fun s => isDefEqRight fn t s)) (fun t => unfold s (isDefEqLeft fn t s) (fun s => isDefEqLeftRight fn t s)) | _, _ => pure LBool.false private def sameHeadSymbol (t s : Expr) : Bool := match t.getAppFn, s.getAppFn with | Expr.const c₁ _, Expr.const cβ‚‚ _ => c₁ == cβ‚‚ | _, _ => false /-- - If headSymbol (unfold t) == headSymbol s, then unfold t - If headSymbol (unfold s) == headSymbol t, then unfold s - Otherwise unfold t and s if possible. Auxiliary method for isDefEqDelta -/ private def unfoldComparingHeadsDefEq (tInfo sInfo : ConstantInfo) (t s : Expr) : MetaM LBool := unfold t (unfold s (pure LBool.undef) -- `t` and `s` failed to be unfolded (fun s => isDefEqRight sInfo.name t s)) (fun tNew => if sameHeadSymbol tNew s then isDefEqLeft tInfo.name tNew s else unfold s (isDefEqLeft tInfo.name tNew s) (fun sNew => if sameHeadSymbol t sNew then isDefEqRight sInfo.name t sNew else isDefEqLeftRight tInfo.name tNew sNew)) /-- If `t` and `s` do not contain metavariables, then use kernel definitional equality heuristics. Otherwise, use `unfoldComparingHeadsDefEq`. Auxiliary method for isDefEqDelta -/ private def unfoldDefEq (tInfo sInfo : ConstantInfo) (t s : Expr) : MetaM LBool := if !t.hasExprMVar && !s.hasExprMVar then /- If `t` and `s` do not contain metavariables, we simulate strategy used in the kernel. -/ if tInfo.hints.lt sInfo.hints then unfold t (unfoldComparingHeadsDefEq tInfo sInfo t s) fun t => isDefEqLeft tInfo.name t s else if sInfo.hints.lt tInfo.hints then unfold s (unfoldComparingHeadsDefEq tInfo sInfo t s) fun s => isDefEqRight sInfo.name t s else unfoldComparingHeadsDefEq tInfo sInfo t s else unfoldComparingHeadsDefEq tInfo sInfo t s /-- When `TransparencyMode` is set to `default` or `all`. If `t` is reducible and `s` is not ==> `isDefEqLeft (unfold t) s` If `s` is reducible and `t` is not ==> `isDefEqRight t (unfold s)` Otherwise, use `unfoldDefEq` Auxiliary method for isDefEqDelta -/ private def unfoldReducibeDefEq (tInfo sInfo : ConstantInfo) (t s : Expr) : MetaM LBool := do if (← shouldReduceReducibleOnly) then unfoldDefEq tInfo sInfo t s else let tReducible ← isReducible tInfo.name let sReducible ← isReducible sInfo.name if tReducible && !sReducible then unfold t (unfoldDefEq tInfo sInfo t s) fun t => isDefEqLeft tInfo.name t s else if !tReducible && sReducible then unfold s (unfoldDefEq tInfo sInfo t s) fun s => isDefEqRight sInfo.name t s else unfoldDefEq tInfo sInfo t s /-- This is an auxiliary method for isDefEqDelta. If `t` is a (non-class) projection function application and `s` is not ==> `isDefEqRight t (unfold s)` If `s` is a (non-class) projection function application and `t` is not ==> `isDefEqRight (unfold t) s` Otherwise, use `unfoldReducibeDefEq` One motivation for the heuristic above is unification problems such as ``` id (?m.1) =?= (a, b).1 ``` We want to reduce the lhs instead of the rhs, and eventually assign `?m := (a, b)`. Another motivation for the heuristic above is unification problems such as ``` List.length (a :: as) =?= HAdd.hAdd (List.length as) 1 ``` However, for class projections, we also unpack them and check whether the result function is the one on the other side. This is relevant for unification problems such as ``` Foo.pow x 256 =?= Pow.pow x 256 ``` where the the `Pow` instance is wrapping `Foo.pow` See issue #1419 for the complete example. -/ private partial def unfoldNonProjFnDefEq (tInfo sInfo : ConstantInfo) (t s : Expr) : MetaM LBool := do let tProjInfo? ← getProjectionFnInfo? tInfo.name let sProjInfo? ← getProjectionFnInfo? sInfo.name if let some tNew ← packedInstanceOf? tProjInfo? t sInfo.name then isDefEqLeft tInfo.name tNew s else if let some sNew ← packedInstanceOf? sProjInfo? s tInfo.name then isDefEqRight sInfo.name t sNew else match tProjInfo?, sProjInfo? with | some _, none => unfold s (unfoldDefEq tInfo sInfo t s) fun s => isDefEqRight sInfo.name t s | none, some _ => unfold t (unfoldDefEq tInfo sInfo t s) fun t => isDefEqLeft tInfo.name t s | _, _ => unfoldReducibeDefEq tInfo sInfo t s where packedInstanceOf? (projInfo? : Option ProjectionFunctionInfo) (e : Expr) (declName : Name) : MetaM (Option Expr) := do let some { fromClass := true, .. } := projInfo? | return none -- It is not a class projection let some e ← unfoldDefinition? e | return none let e ← whnfCore e if e.isAppOf declName then return some e let .const name _ := e.getAppFn | return none -- Keep going if new `e` is also a class projection packedInstanceOf? (← getProjectionFnInfo? name) e declName /-- isDefEq by lazy delta reduction. This method implements many different heuristics: 1- If only `t` can be unfolded => then unfold `t` and continue 2- If only `s` can be unfolded => then unfold `s` and continue 3- If `t` and `s` can be unfolded and they have the same head symbol, then a) First try to solve unification by unifying arguments. b) If it fails, unfold both and continue. Implemented by `unfoldBothDefEq` 4- If `t` is a projection function application and `s` is not => then unfold `s` and continue. 5- If `s` is a projection function application and `t` is not => then unfold `t` and continue. Remark: 4&5 are implemented by `unfoldNonProjFnDefEq` 6- If `t` is reducible and `s` is not => then unfold `t` and continue. 7- If `s` is reducible and `t` is not => then unfold `s` and continue Remark: 6&7 are implemented by `unfoldReducibeDefEq` 8- If `t` and `s` do not contain metavariables, then use heuristic used in the Kernel. Implemented by `unfoldDefEq` 9- If `headSymbol (unfold t) == headSymbol s`, then unfold t and continue. 10- If `headSymbol (unfold s) == headSymbol t`, then unfold s 11- Otherwise, unfold `t` and `s` and continue. Remark: 9&10&11 are implemented by `unfoldComparingHeadsDefEq` -/ private def isDefEqDelta (t s : Expr) : MetaM LBool := do let tInfo? ← isDeltaCandidate? t let sInfo? ← isDeltaCandidate? s match tInfo?, sInfo? with | none, none => pure LBool.undef | some tInfo, none => unfold t (pure LBool.undef) fun t => isDefEqLeft tInfo.name t s | none, some sInfo => unfold s (pure LBool.undef) fun s => isDefEqRight sInfo.name t s | some tInfo, some sInfo => if tInfo.name == sInfo.name then unfoldBothDefEq tInfo.name t s else unfoldNonProjFnDefEq tInfo sInfo t s private def isAssigned : Expr β†’ MetaM Bool | Expr.mvar mvarId => mvarId.isAssigned | _ => pure false private def expandDelayedAssigned? (t : Expr) : MetaM (Option Expr) := do let tFn := t.getAppFn if !tFn.isMVar then return none let some { fvars, mvarIdPending } ← getDelayedMVarAssignment? tFn.mvarId! | return none let tNew ← instantiateMVars t if tNew != t then return some tNew /- If `assignSyntheticOpaque` is true, we must follow the delayed assignment. Recall a delayed assignment `mvarId [xs] := mvarIdPending` is morally an assingment `mvarId := fun xs => mvarIdPending` where `xs` are free variables in the scope of `mvarIdPending`, but not in the scope of `mvarId`. We can only perform the abstraction when `mvarIdPending` has been fully synthesized. That is, `instantiateMVars (mkMVar mvarIdPending)` does not contain any expression metavariables. Here we just consume `fvar.size` arguments. That is, if `t` is of the form `mvarId as bs` where `as.size == fvars.size`, we return `mvarIdPending bs`. TODO: improve this transformation. Here is a possible improvement. Assume `t` is of the form `?m as` where `as` represent the arguments, and we are trying to solve `?m as =?= s[as]` where `s[as]` represents a term containing occurrences of `as`. We could try to compute the solution as usual `?m := fun ys => s[as/ys]` We also have the delayed assignment `?m [xs] := ?n`, where `xs` are variables in the scope of `?n`, and this delayed assignment is morally `?m := fun xs => ?n`. Thus, we can reduce `?m as =?= s[as]` to `?n =?= s[as/xs]`, and solve it using `?n`'s local context. This is more precise than simplying droping the arguments `as`. -/ unless (← getConfig).assignSyntheticOpaque do return none let tArgs := t.getAppArgs if tArgs.size < fvars.size then return none return some (mkAppRange (mkMVar mvarIdPending) fvars.size tArgs.size tArgs) private def isAssignable : Expr β†’ MetaM Bool | Expr.mvar mvarId => do let b ← mvarId.isReadOnlyOrSyntheticOpaque; pure (!b) | _ => pure false private def etaEq (t s : Expr) : Bool := match t.etaExpanded? with | some t => t == s | none => false /-- Helper method for implementing `isDefEqProofIrrel`. Execute `k` with a transparency setting that is at least as strong as `.default`. This is important for modules that use the `.reducible` setting (e.g., `simp`, `rw`, etc). We added this feature to address issue #1302. ```lean @[simp] theorem get_cons_zero {as : List Ξ±} : (a :: as).get ⟨0, Nat.zero_lt_succ _⟩ = a := rfl example (a b c : Ξ±) : [a, b, c].get ⟨0, by simp⟩ = a := by simp ``` In the example above `simp` fails to use `get_cons_zero` because it fails to establish that the proof objects are definitionally equal using proof irrelevance. In this example, the propositions are ```lean 0 < Nat.succ (List.length [b, c]) =?= 0 < Nat.succ (Nat.succ (Nat.succ 0)) ``` So, unless we can unfold `List.length`, it fails. Remark: if this becomes a performance bottleneck, we should add a flag to control when it is used. Then, we can enable the flag only when applying `simp` and `rw` theorems. -/ private def withProofIrrelTransparency (k : MetaM Ξ±) : MetaM Ξ± := withAtLeastTransparency .default k private def isDefEqProofIrrel (t s : Expr) : MetaM LBool := do if (← getConfig).proofIrrelevance then match (← isProofQuick t) with | LBool.false => pure LBool.undef | LBool.true => let tType ← inferType t let sType ← inferType s toLBoolM <| withProofIrrelTransparency <| Meta.isExprDefEqAux tType sType | LBool.undef => let tType ← inferType t if (← isProp tType) then let sType ← inferType s toLBoolM <| withProofIrrelTransparency <| Meta.isExprDefEqAux tType sType else pure LBool.undef else pure LBool.undef /-- Try to solve constraint of the form `?m args₁ =?= ?m argsβ‚‚`. - First try to unify `args₁` and `argsβ‚‚`, and return true if successful - Otherwise, try to assign `?m` to a constant function of the form `fun x_1 ... x_n => ?n` where `?n` is a fresh metavariable. See `assignConst`. -/ private def isDefEqMVarSelf (mvar : Expr) (args₁ argsβ‚‚ : Array Expr) : MetaM Bool := do if args₁.size != argsβ‚‚.size then pure false else if (← isDefEqArgs mvar args₁ argsβ‚‚) then pure true else if !(← isAssignable mvar) then pure false else let cfg ← getConfig let mvarId := mvar.mvarId! let mvarDecl ← mvarId.getDecl if mvarDecl.numScopeArgs == args₁.size || cfg.constApprox then let type ← inferType (mkAppN mvar args₁) let auxMVar ← mkAuxMVar mvarDecl.lctx mvarDecl.localInstances type assignConst mvar args₁.size auxMVar else pure false /-- Remove unnecessary let-decls -/ private def consumeLet : Expr β†’ Expr | e@(Expr.letE _ _ _ b _) => if b.hasLooseBVars then e else consumeLet b | e => e mutual private partial def isDefEqQuick (t s : Expr) : MetaM LBool := let t := consumeLet t let s := consumeLet s match t, s with | .lit l₁, .lit lβ‚‚ => return (l₁ == lβ‚‚).toLBool | .sort u, .sort v => toLBoolM <| isLevelDefEqAux u v | .lam .., .lam .. => if t == s then pure LBool.true else toLBoolM <| isDefEqBinding t s | .forallE .., .forallE .. => if t == s then pure LBool.true else toLBoolM <| isDefEqBinding t s -- | Expr.mdata _ t _, s => isDefEqQuick t s -- | t, Expr.mdata _ s _ => isDefEqQuick t s | .fvar fvarId₁, .fvar fvarIdβ‚‚ => do if (← fvarId₁.isLetVar <||> fvarIdβ‚‚.isLetVar) then return LBool.undef else if fvarId₁ == fvarIdβ‚‚ then return LBool.true else isDefEqProofIrrel t s | t, s => isDefEqQuickOther t s private partial def isDefEqQuickOther (t s : Expr) : MetaM LBool := do /- We used to eagerly consume all metadata (see commented lines at `isDefEqQuick`), but it was unnecessarily removing helpful annotations for the pretty-printer. For example, consider the following example. ``` constant p : Nat β†’ Prop constant q : Nat β†’ Prop theorem p_of_q : q x β†’ p x := sorry theorem pletfun : p (let_fun x := 0; x + 1) := by -- ⊒ p (let_fun x := 0; x + 1) apply p_of_q -- If we eagerly consume all metadata, the let_fun annotation is lost during `isDefEq` -- ⊒ q ((fun x => x + 1) 0) sorry ``` However, pattern annotations (`inaccessible?` and `patternWithRef?`) must be consumed. The frontend relies on the fact that is must not be propagated by `isDefEq`. Thus, we consume it here. This is a bit hackish since it is very adhoc. We might other annotations in the future that we should not preserve. Perhaps, we should mark the annotation we do want to preserve ones (e.g., hints for the pretty printer), and consume all other -/ if let some t := patternAnnotation? t then isDefEqQuick t s else if let some s := patternAnnotation? s then isDefEqQuick t s else if t == s then return LBool.true else if etaEq t s || etaEq s t then return LBool.true -- t =?= (fun xs => t xs) else let tFn := t.getAppFn let sFn := s.getAppFn if !tFn.isMVar && !sFn.isMVar then return LBool.undef else if (← isAssigned tFn) then let t ← instantiateMVars t isDefEqQuick t s else if (← isAssigned sFn) then let s ← instantiateMVars s isDefEqQuick t s else if let some t ← expandDelayedAssigned? t then isDefEqQuick t s else if let some s ← expandDelayedAssigned? s then isDefEqQuick t s /- Remark: we do not eagerly synthesize synthetic metavariables when the constraint is not stuck. Reason: we may fail to solve a constraint of the form `?x =?= A` when the synthesized instance is not definitionally equal to `A`. We left the code here as a remainder of this issue. -/ -- else if (← isSynthetic tFn <&&> trySynthPending tFn) then -- let t ← instantiateMVars t -- isDefEqQuick t s -- else if (← isSynthetic sFn <&&> trySynthPending sFn) then -- let s ← instantiateMVars s -- isDefEqQuick t s else if tFn.isMVar && sFn.isMVar && tFn == sFn then Bool.toLBool <$> isDefEqMVarSelf tFn t.getAppArgs s.getAppArgs else let tAssign? ← isAssignable tFn let sAssign? ← isAssignable sFn let assignableMsg (b : Bool) := if b then "[assignable]" else "[nonassignable]" trace[Meta.isDefEq] "{t} {assignableMsg tAssign?} =?= {s} {assignableMsg sAssign?}" if tAssign? && !sAssign? then toLBoolM <| processAssignment' t s else if !tAssign? && sAssign? then toLBoolM <| processAssignment' s t else if !tAssign? && !sAssign? then /- Trying to unify `?m ... =?= ?n ...` where both `?m` and `?n` cannot be assigned. This can happen when both of them are `syntheticOpaque` (e.g., metavars associated with tactics), or a metavariables from previous levels. If their types are propositions and are defeq, we can solve the constraint by proof irrelevance. This test is important for fixing a performance problem exposed by test `isDefEqPerfIssue.lean`. Without the proof irrelevance check, this example timeouts. Recall that: 1- The elaborator has a pending list of things to do: Tactics, TC, etc. 2- The elaborator only tries tactics after it tried to solve pending TC problems, delayed elaboratio, etc. The motivation: avoid unassigned metavariables in goals. 3- Each pending tactic goal is represented as a metavariable. It is marked as `synthethicOpaque` to make it clear that it should not be assigned by unification. 4- When we abstract a term containing metavariables, we often create new metavariables. Example: when abstracting `x` at `f ?m`, we obtain `fun x => f (?m' x)`. If `x` is in the scope of `?m`. If `?m` is `syntheticOpaque`, so is `?m'`, and we also have the delayed assignment `?m' x := ?m` 5- When checking a metavariable assignment, `?m := v` we check whether the type of `?m` is defeq to type of `v` with default reducibility setting. Now consider the following fragment ``` let a' := g 100 a ⟨i, h⟩ ⟨i - Nat.zero.succ, by exact Nat.lt_of_le_of_lt (Nat.pred_le i) h⟩ have : a'.size - i >= 0 := sorry f (i+1) a' ``` The elaborator tries to synthesize the instance `OfNat Nat 1` before we generate the tactic proof for `by exact ...` (remark 2). The solution `instOfNatNat 1` is synthesized. Let `m? a i h a' this` be the "hole" associated with the pending instance. Then, `isDefEq` tries to assign `m? a i h a' this := instOfNatNat 1` which is reduced to `m? := mkLambdaFVars #[a, i, h, a', this] (instOfNatNat 1)`. Note that, this is an abstraction step (remark 4), and the type contains the `syntheticOpaque` metavariable for the pending tactic proof (remark 3). Thus, a new `syntheticOpaque` opaque is created (remark 4). Then, `isDefEq` must check whether the type of `?m` is defeq to `mkLambdaFVars #[a, i, h, a', this] (instOfNatNat 1)` (remark 5). The two types are almost identical, but they contain different `syntheticOpaque` in the subterm corresponding to the `by exact ...` tactic proof. Without the following proof irrelevance test, the check will fail, and `isDefEq` timeouts unfolding `g` and its dependencies. Note that this test does not prevent a similar performance problem in a usecase where the tactic is used to synthesize a term that is not a proof. TODO: add better support for checking the delayed assignments. This is not high priority because tactics are usually only used for synthesizing proofs. -/ match (← isDefEqProofIrrel t s) with | LBool.true => return LBool.true | LBool.false => return LBool.false | _ => if tFn.isMVar || sFn.isMVar then let ctx ← read if ctx.config.isDefEqStuckEx then do trace[Meta.isDefEq.stuck] "{t} =?= {s}" Meta.throwIsDefEqStuck else return LBool.false else return LBool.undef else isDefEqQuickMVarMVar t s /-- Both `t` and `s` are terms of the form `?m ...` -/ private partial def isDefEqQuickMVarMVar (t s : Expr) : MetaM LBool := do if s.isMVar && !t.isMVar then /- Solve `?m t =?= ?n` by trying first `?n := ?m t`. Reason: this assignment is precise. -/ if (← checkpointDefEq (processAssignment s t)) then return LBool.true else toLBoolM <| processAssignment t s else if (← checkpointDefEq (processAssignment t s)) then return LBool.true else toLBoolM <| processAssignment s t end @[inline] def whenUndefDo (x : MetaM LBool) (k : MetaM Bool) : MetaM Bool := do let status ← x match status with | LBool.true => pure true | LBool.false => pure false | LBool.undef => k @[specialize] private def unstuckMVar (e : Expr) (successK : Expr β†’ MetaM Bool) (failK : MetaM Bool): MetaM Bool := do match (← getStuckMVar? e) with | some mvarId => trace[Meta.isDefEq.stuckMVar] "found stuck MVar {mkMVar mvarId} : {← inferType (mkMVar mvarId)}" if (← Meta.synthPending mvarId) then let e ← instantiateMVars e successK e else failK | none => failK private def isDefEqOnFailure (t s : Expr) : MetaM Bool := do trace[Meta.isDefEq.onFailure] "{t} =?= {s}" unstuckMVar t (fun t => Meta.isExprDefEqAux t s) <| unstuckMVar s (fun s => Meta.isExprDefEqAux t s) <| tryUnificationHints t s <||> tryUnificationHints s t private def isDefEqProj : Expr β†’ Expr β†’ MetaM Bool | Expr.proj _ i t, Expr.proj _ j s => pure (i == j) <&&> Meta.isExprDefEqAux t s | Expr.proj structName 0 s, v => isDefEqSingleton structName s v | v, Expr.proj structName 0 s => isDefEqSingleton structName s v | _, _ => pure false where /-- If `structName` is a structure with a single field and `(?m ...).1 =?= v`, then solve contraint as `?m ... =?= ⟨v⟩` -/ isDefEqSingleton (structName : Name) (s : Expr) (v : Expr) : MetaM Bool := do let ctorVal := getStructureCtor (← getEnv) structName if ctorVal.numFields != 1 then return false -- It is not a structure with a single field. let sType ← whnf (← inferType s) let sTypeFn := sType.getAppFn if !sTypeFn.isConstOf structName then return false let s ← whnf s let sFn := s.getAppFn if !sFn.isMVar then return false if (← isAssignable sFn) then let ctorApp := mkApp (mkAppN (mkConst ctorVal.name sTypeFn.constLevels!) sType.getAppArgs) v processAssignment' s ctorApp else return false /-- Given applications `t` and `s` that are in WHNF (modulo the current transparency setting), check whether they are definitionally equal or not. -/ private def isDefEqApp (t s : Expr) : MetaM Bool := do let tFn := t.getAppFn let sFn := s.getAppFn if tFn.isConst && sFn.isConst && tFn.constName! == sFn.constName! then /- See comment at `tryHeuristic` explaining why we processe arguments before universe levels. -/ if (← checkpointDefEq (isDefEqArgs tFn t.getAppArgs s.getAppArgs <&&> isListLevelDefEqAux tFn.constLevels! sFn.constLevels!)) then return true else isDefEqOnFailure t s else if (← checkpointDefEq (Meta.isExprDefEqAux tFn s.getAppFn <&&> isDefEqArgs tFn t.getAppArgs s.getAppArgs)) then return true else isDefEqOnFailure t s /-- Return `true` if the types of the given expressions is an inductive datatype with an inductive datatype with a single constructor with no fields. -/ private def isDefEqUnitLike (t : Expr) (s : Expr) : MetaM Bool := do let tType ← whnf (← inferType t) matchConstStruct tType.getAppFn (fun _ => return false) fun _ _ ctorVal => do if ctorVal.numFields != 0 then return false else if (← useEtaStruct ctorVal.induct) then Meta.isExprDefEqAux tType (← inferType s) else return false /-- The `whnf` procedure has support for unfolding class projections when the transparency mode is set to `.instances`. This method ensures the behavior of `whnf` and `isDefEq` is consistent in this transparency mode. -/ private def isDefEqProjInst (t : Expr) (s : Expr) : MetaM LBool := do if (← getTransparency) != .instances then return .undef let t? ← unfoldProjInstWhenIntances? t let s? ← unfoldProjInstWhenIntances? s if t?.isSome || s?.isSome then toLBoolM <| Meta.isExprDefEqAux (t?.getD t) (s?.getD s) else return .undef private def isExprDefEqExpensive (t : Expr) (s : Expr) : MetaM Bool := do if (← (isDefEqEta t s <||> isDefEqEta s t)) then return true -- TODO: investigate whether this is the place for putting this check if (← (isDefEqEtaStruct t s <||> isDefEqEtaStruct s t)) then return true if (← isDefEqProj t s) then return true let t' ← whnfCore t let s' ← whnfCore s if t != t' || s != s' then Meta.isExprDefEqAux t' s' else whenUndefDo (isDefEqNative t s) do whenUndefDo (isDefEqNat t s) do whenUndefDo (isDefEqOffset t s) do whenUndefDo (isDefEqDelta t s) do if t.isConst && s.isConst then if t.constName! == s.constName! then isListLevelDefEqAux t.constLevels! s.constLevels! else return false else if (← pure t.isApp <&&> pure s.isApp <&&> isDefEqApp t s) then return true else whenUndefDo (isDefEqProjInst t s) do whenUndefDo (isDefEqStringLit t s) do if (← isDefEqUnitLike t s) then return true else isDefEqOnFailure t s private def mkCacheKey (t : Expr) (s : Expr) : Expr Γ— Expr := if Expr.quickLt t s then (t, s) else (s, t) private def getCachedResult (key : Expr Γ— Expr) : MetaM LBool := do match (← get).cache.defEq.find? key with | some val => return val.toLBool | none => return .undef private def cacheResult (key : Expr Γ— Expr) (result : Bool) : MetaM Unit := do modifyDefEqCache fun c => c.insert key result @[export lean_is_expr_def_eq] partial def isExprDefEqAuxImpl (t : Expr) (s : Expr) : MetaM Bool := withIncRecDepth do trace[Meta.isDefEq.step] "{t} =?= {s}" checkMaxHeartbeats "isDefEq" withNestedTraces do whenUndefDo (isDefEqQuick t s) do whenUndefDo (isDefEqProofIrrel t s) do -- We perform `whnfCore` again with `deltaAtProj := true` at `isExprDefEqExpensive` after `isDefEqProj` let t' ← whnfCore t (deltaAtProj := false) let s' ← whnfCore s (deltaAtProj := false) if t != t' || s != s' then isExprDefEqAuxImpl t' s' else /- TODO: check whether the following `instantiateMVar`s are expensive or not in practice. Lean 3 does not use them, and may miss caching opportunities since it is not safe to cache when `t` and `s` may contain mvars. The unit test `tryHeuristicPerfIssue2.lean` cannot be solved without these two `instantiateMVar`s. If it becomes a problem, we may use store a flag in the context indicating whether we have already used `instantiateMVar` in outer invocations or not. It is not perfect (we may assign mvars in nested calls), but it should work well enough in practice, and prevent repeated traversals in nested calls. -/ let t ← instantiateMVars t let s ← instantiateMVars s let numPostponed ← getNumPostponed let k := mkCacheKey t s match (← getCachedResult k) with | .true => trace[Meta.isDefEq.cache] "cache hit 'true' for {t} =?= {s}" return true | .false => trace[Meta.isDefEq.cache] "cache hit 'false' for {t} =?= {s}" return false | .undef => let result ← isExprDefEqExpensive t s if numPostponed == (← getNumPostponed) then trace[Meta.isDefEq.cache] "cache {result} for {t} =?= {s}" cacheResult k result return result builtin_initialize registerTraceClass `Meta.isDefEq registerTraceClass `Meta.isDefEq.foApprox registerTraceClass `Meta.isDefEq.constApprox registerTraceClass `Meta.isDefEq.delta registerTraceClass `Meta.isDefEq.step registerTraceClass `Meta.isDefEq.assign registerTraceClass `Meta.isDefEq.eta.struct end Lean.Meta
fba493e56a8e761a6b9d4a1e402bcf3a92fd0aff
d9d511f37a523cd7659d6f573f990e2a0af93c6f
/src/order/complete_lattice.lean
1899c7a628e396bb273f3463893d975bc8366911
[ "Apache-2.0" ]
permissive
hikari0108/mathlib
b7ea2b7350497ab1a0b87a09d093ecc025a50dfa
a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901
refs/heads/master
1,690,483,608,260
1,631,541,580,000
1,631,541,580,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
53,222
lean
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import order.bounds import data.set.bool /-! # Theory of complete lattices ## Main definitions * `Sup` and `Inf` are the supremum and the infimum of a set; * `supr (f : ΞΉ β†’ Ξ±)` and `infi (f : ΞΉ β†’ Ξ±)` are indexed supremum and infimum of a function, defined as `Sup` and `Inf` of the range of this function; * `class complete_lattice`: a bounded lattice such that `Sup s` is always the least upper boundary of `s` and `Inf s` is always the greatest lower boundary of `s`; * `class complete_linear_order`: a linear ordered complete lattice. ## Naming conventions We use `Sup`/`Inf`/`supr`/`infi` for the corresponding functions in the statement. Sometimes we also use `bsupr`/`binfi` for "bounded" supremum or infimum, i.e. one of `⨆ i ∈ s, f i`, `⨆ i (hi : p i), f i`, or more generally `⨆ i (hi : p i), f i hi`. ## Notation * `⨆ i, f i` : `supr f`, the supremum of the range of `f`; * `β¨… i, f i` : `infi f`, the infimum of the range of `f`. -/ set_option old_structure_cmd true open set variables {Ξ± Ξ² Ξ²β‚‚ : Type*} {ΞΉ ΞΉβ‚‚ : Sort*} /-- class for the `Sup` operator -/ class has_Sup (Ξ± : Type*) := (Sup : set Ξ± β†’ Ξ±) /-- class for the `Inf` operator -/ class has_Inf (Ξ± : Type*) := (Inf : set Ξ± β†’ Ξ±) export has_Sup (Sup) has_Inf (Inf) /-- Supremum of a set -/ add_decl_doc has_Sup.Sup /-- Infimum of a set -/ add_decl_doc has_Inf.Inf /-- Indexed supremum -/ def supr [has_Sup Ξ±] {ΞΉ} (s : ΞΉ β†’ Ξ±) : Ξ± := Sup (range s) /-- Indexed infimum -/ def infi [has_Inf Ξ±] {ΞΉ} (s : ΞΉ β†’ Ξ±) : Ξ± := Inf (range s) @[priority 50] instance has_Inf_to_nonempty (Ξ±) [has_Inf Ξ±] : nonempty Ξ± := ⟨Inf βˆ…βŸ© @[priority 50] instance has_Sup_to_nonempty (Ξ±) [has_Sup Ξ±] : nonempty Ξ± := ⟨Sup βˆ…βŸ© notation `⨆` binders `, ` r:(scoped f, supr f) := r notation `β¨…` binders `, ` r:(scoped f, infi f) := r instance (Ξ±) [has_Inf Ξ±] : has_Sup (order_dual Ξ±) := ⟨(Inf : set Ξ± β†’ Ξ±)⟩ instance (Ξ±) [has_Sup Ξ±] : has_Inf (order_dual Ξ±) := ⟨(Sup : set Ξ± β†’ Ξ±)⟩ /-- Note that we rarely use `complete_semilattice_Sup` (in fact, any such object is always a `complete_lattice`, so it's usually best to start there). Nevertheless it is sometimes a useful intermediate step in constructions. -/ class complete_semilattice_Sup (Ξ± : Type*) extends partial_order Ξ±, has_Sup Ξ± := (le_Sup : βˆ€s, βˆ€a∈s, a ≀ Sup s) (Sup_le : βˆ€s a, (βˆ€b∈s, b ≀ a) β†’ Sup s ≀ a) section variables [complete_semilattice_Sup Ξ±] {s t : set Ξ±} {a b : Ξ±} @[ematch] theorem le_Sup : a ∈ s β†’ a ≀ Sup s := complete_semilattice_Sup.le_Sup s a theorem Sup_le : (βˆ€b∈s, b ≀ a) β†’ Sup s ≀ a := complete_semilattice_Sup.Sup_le s a lemma is_lub_Sup (s : set Ξ±) : is_lub s (Sup s) := ⟨assume x, le_Sup, assume x, Sup_le⟩ lemma is_lub.Sup_eq (h : is_lub s a) : Sup s = a := (is_lub_Sup s).unique h theorem le_Sup_of_le (hb : b ∈ s) (h : a ≀ b) : a ≀ Sup s := le_trans h (le_Sup hb) theorem Sup_le_Sup (h : s βŠ† t) : Sup s ≀ Sup t := (is_lub_Sup s).mono (is_lub_Sup t) h @[simp] theorem Sup_le_iff : Sup s ≀ a ↔ (βˆ€b ∈ s, b ≀ a) := is_lub_le_iff (is_lub_Sup s) lemma le_Sup_iff : a ≀ Sup s ↔ (βˆ€ b, (βˆ€ x ∈ s, x ≀ b) β†’ a ≀ b) := ⟨λ h b hb, le_trans h (Sup_le hb), Ξ» hb, hb _ (Ξ» x, le_Sup)⟩ theorem Sup_le_Sup_of_forall_exists_le (h : βˆ€ x ∈ s, βˆƒ y ∈ t, x ≀ y) : Sup s ≀ Sup t := le_of_forall_le' begin simp only [Sup_le_iff], introv hβ‚€ h₁, rcases h _ h₁ with ⟨y,hy,hy'⟩, solve_by_elim [le_trans hy'] end -- We will generalize this to conditionally complete lattices in `cSup_singleton`. theorem Sup_singleton {a : Ξ±} : Sup {a} = a := is_lub_singleton.Sup_eq end /-- Note that we rarely use `complete_semilattice_Inf` (in fact, any such object is always a `complete_lattice`, so it's usually best to start there). Nevertheless it is sometimes a useful intermediate step in constructions. -/ class complete_semilattice_Inf (Ξ± : Type*) extends partial_order Ξ±, has_Inf Ξ± := (Inf_le : βˆ€s, βˆ€a∈s, Inf s ≀ a) (le_Inf : βˆ€s a, (βˆ€b∈s, a ≀ b) β†’ a ≀ Inf s) section variables [complete_semilattice_Inf Ξ±] {s t : set Ξ±} {a b : Ξ±} @[ematch] theorem Inf_le : a ∈ s β†’ Inf s ≀ a := complete_semilattice_Inf.Inf_le s a theorem le_Inf : (βˆ€b∈s, a ≀ b) β†’ a ≀ Inf s := complete_semilattice_Inf.le_Inf s a lemma is_glb_Inf (s : set Ξ±) : is_glb s (Inf s) := ⟨assume a, Inf_le, assume a, le_Inf⟩ lemma is_glb.Inf_eq (h : is_glb s a) : Inf s = a := (is_glb_Inf s).unique h theorem Inf_le_of_le (hb : b ∈ s) (h : b ≀ a) : Inf s ≀ a := le_trans (Inf_le hb) h theorem Inf_le_Inf (h : s βŠ† t) : Inf t ≀ Inf s := (is_glb_Inf s).mono (is_glb_Inf t) h @[simp] theorem le_Inf_iff : a ≀ Inf s ↔ (βˆ€b ∈ s, a ≀ b) := le_is_glb_iff (is_glb_Inf s) lemma Inf_le_iff : Inf s ≀ a ↔ (βˆ€ b, (βˆ€ x ∈ s, b ≀ x) β†’ b ≀ a) := ⟨λ h b hb, le_trans (le_Inf hb) h, Ξ» hb, hb _ (Ξ» x, Inf_le)⟩ theorem Inf_le_Inf_of_forall_exists_le (h : βˆ€ x ∈ s, βˆƒ y ∈ t, y ≀ x) : Inf t ≀ Inf s := le_of_forall_le begin simp only [le_Inf_iff], introv hβ‚€ h₁, rcases h _ h₁ with ⟨y,hy,hy'⟩, solve_by_elim [le_trans _ hy'] end -- We will generalize this to conditionally complete lattices in `cInf_singleton`. theorem Inf_singleton {a : Ξ±} : Inf {a} = a := is_glb_singleton.Inf_eq end /-- A complete lattice is a bounded lattice which has suprema and infima for every subset. -/ @[protect_proj] class complete_lattice (Ξ± : Type*) extends bounded_lattice Ξ±, complete_semilattice_Sup Ξ±, complete_semilattice_Inf Ξ±. /-- Create a `complete_lattice` from a `partial_order` and `Inf` function that returns the greatest lower bound of a set. Usually this constructor provides poor definitional equalities. If other fields are known explicitly, they should be provided; for example, if `inf` is known explicitly, construct the `complete_lattice` instance as ``` instance : complete_lattice my_T := { inf := better_inf, le_inf := ..., inf_le_right := ..., inf_le_left := ... -- don't care to fix sup, Sup, bot, top ..complete_lattice_of_Inf my_T _ } ``` -/ def complete_lattice_of_Inf (Ξ± : Type*) [H1 : partial_order Ξ±] [H2 : has_Inf Ξ±] (is_glb_Inf : βˆ€ s : set Ξ±, is_glb s (Inf s)) : complete_lattice Ξ± := { bot := Inf univ, bot_le := Ξ» x, (is_glb_Inf univ).1 trivial, top := Inf βˆ…, le_top := Ξ» a, (is_glb_Inf βˆ…).2 $ by simp, sup := Ξ» a b, Inf {x | a ≀ x ∧ b ≀ x}, inf := Ξ» a b, Inf {a, b}, le_inf := Ξ» a b c hab hac, by { apply (is_glb_Inf _).2, simp [*] }, inf_le_right := Ξ» a b, (is_glb_Inf _).1 $ mem_insert_of_mem _ $ mem_singleton _, inf_le_left := Ξ» a b, (is_glb_Inf _).1 $ mem_insert _ _, sup_le := Ξ» a b c hac hbc, (is_glb_Inf _).1 $ by simp [*], le_sup_left := Ξ» a b, (is_glb_Inf _).2 $ Ξ» x, and.left, le_sup_right := Ξ» a b, (is_glb_Inf _).2 $ Ξ» x, and.right, le_Inf := Ξ» s a ha, (is_glb_Inf s).2 ha, Inf_le := Ξ» s a ha, (is_glb_Inf s).1 ha, Sup := Ξ» s, Inf (upper_bounds s), le_Sup := Ξ» s a ha, (is_glb_Inf (upper_bounds s)).2 $ Ξ» b hb, hb ha, Sup_le := Ξ» s a ha, (is_glb_Inf (upper_bounds s)).1 ha, .. H1, .. H2 } /-- Any `complete_semilattice_Inf` is in fact a `complete_lattice`. Note that this construction has bad definitional properties: see the doc-string on `complete_lattice_of_Inf`. -/ def complete_lattice_of_complete_semilattice_Inf (Ξ± : Type*) [complete_semilattice_Inf Ξ±] : complete_lattice Ξ± := complete_lattice_of_Inf Ξ± (Ξ» s, is_glb_Inf s) /-- Create a `complete_lattice` from a `partial_order` and `Sup` function that returns the least upper bound of a set. Usually this constructor provides poor definitional equalities. If other fields are known explicitly, they should be provided; for example, if `inf` is known explicitly, construct the `complete_lattice` instance as ``` instance : complete_lattice my_T := { inf := better_inf, le_inf := ..., inf_le_right := ..., inf_le_left := ... -- don't care to fix sup, Inf, bot, top ..complete_lattice_of_Sup my_T _ } ``` -/ def complete_lattice_of_Sup (Ξ± : Type*) [H1 : partial_order Ξ±] [H2 : has_Sup Ξ±] (is_lub_Sup : βˆ€ s : set Ξ±, is_lub s (Sup s)) : complete_lattice Ξ± := { top := Sup univ, le_top := Ξ» x, (is_lub_Sup univ).1 trivial, bot := Sup βˆ…, bot_le := Ξ» x, (is_lub_Sup βˆ…).2 $ by simp, sup := Ξ» a b, Sup {a, b}, sup_le := Ξ» a b c hac hbc, (is_lub_Sup _).2 (by simp [*]), le_sup_left := Ξ» a b, (is_lub_Sup _).1 $ mem_insert _ _, le_sup_right := Ξ» a b, (is_lub_Sup _).1 $ mem_insert_of_mem _ $ mem_singleton _, inf := Ξ» a b, Sup {x | x ≀ a ∧ x ≀ b}, le_inf := Ξ» a b c hab hac, (is_lub_Sup _).1 $ by simp [*], inf_le_left := Ξ» a b, (is_lub_Sup _).2 (Ξ» x, and.left), inf_le_right := Ξ» a b, (is_lub_Sup _).2 (Ξ» x, and.right), Inf := Ξ» s, Sup (lower_bounds s), Sup_le := Ξ» s a ha, (is_lub_Sup s).2 ha, le_Sup := Ξ» s a ha, (is_lub_Sup s).1 ha, Inf_le := Ξ» s a ha, (is_lub_Sup (lower_bounds s)).2 (Ξ» b hb, hb ha), le_Inf := Ξ» s a ha, (is_lub_Sup (lower_bounds s)).1 ha, .. H1, .. H2 } /-- Any `complete_semilattice_Sup` is in fact a `complete_lattice`. Note that this construction has bad definitional properties: see the doc-string on `complete_lattice_of_Sup`. -/ def complete_lattice_of_complete_semilattice_Sup (Ξ± : Type*) [complete_semilattice_Sup Ξ±] : complete_lattice Ξ± := complete_lattice_of_Sup Ξ± (Ξ» s, is_lub_Sup s) /-- A complete linear order is a linear order whose lattice structure is complete. -/ class complete_linear_order (Ξ± : Type*) extends complete_lattice Ξ±, linear_order Ξ± namespace order_dual variable (Ξ±) instance [complete_lattice Ξ±] : complete_lattice (order_dual Ξ±) := { le_Sup := @complete_lattice.Inf_le Ξ± _, Sup_le := @complete_lattice.le_Inf Ξ± _, Inf_le := @complete_lattice.le_Sup Ξ± _, le_Inf := @complete_lattice.Sup_le Ξ± _, .. order_dual.bounded_lattice Ξ±, ..order_dual.has_Sup Ξ±, ..order_dual.has_Inf Ξ± } instance [complete_linear_order Ξ±] : complete_linear_order (order_dual Ξ±) := { .. order_dual.complete_lattice Ξ±, .. order_dual.linear_order Ξ± } end order_dual section variables [complete_lattice Ξ±] {s t : set Ξ±} {a b : Ξ±} theorem Inf_le_Sup (hs : s.nonempty) : Inf s ≀ Sup s := is_glb_le_is_lub (is_glb_Inf s) (is_lub_Sup s) hs theorem Sup_union {s t : set Ξ±} : Sup (s βˆͺ t) = Sup s βŠ” Sup t := ((is_lub_Sup s).union (is_lub_Sup t)).Sup_eq theorem Sup_inter_le {s t : set Ξ±} : Sup (s ∩ t) ≀ Sup s βŠ“ Sup t := by finish /- Sup_le (assume a ⟨a_s, a_t⟩, le_inf (le_Sup a_s) (le_Sup a_t)) -/ theorem Inf_union {s t : set Ξ±} : Inf (s βˆͺ t) = Inf s βŠ“ Inf t := ((is_glb_Inf s).union (is_glb_Inf t)).Inf_eq theorem le_Inf_inter {s t : set Ξ±} : Inf s βŠ” Inf t ≀ Inf (s ∩ t) := @Sup_inter_le (order_dual Ξ±) _ _ _ @[simp] theorem Sup_empty : Sup βˆ… = (βŠ₯ : Ξ±) := (@is_lub_empty Ξ± _).Sup_eq @[simp] theorem Inf_empty : Inf βˆ… = (⊀ : Ξ±) := (@is_glb_empty Ξ± _).Inf_eq @[simp] theorem Sup_univ : Sup univ = (⊀ : Ξ±) := (@is_lub_univ Ξ± _).Sup_eq @[simp] theorem Inf_univ : Inf univ = (βŠ₯ : Ξ±) := (@is_glb_univ Ξ± _).Inf_eq -- TODO(Jeremy): get this automatically @[simp] theorem Sup_insert {a : Ξ±} {s : set Ξ±} : Sup (insert a s) = a βŠ” Sup s := ((is_lub_Sup s).insert a).Sup_eq @[simp] theorem Inf_insert {a : Ξ±} {s : set Ξ±} : Inf (insert a s) = a βŠ“ Inf s := ((is_glb_Inf s).insert a).Inf_eq theorem Sup_le_Sup_of_subset_insert_bot (h : s βŠ† insert βŠ₯ t) : Sup s ≀ Sup t := le_trans (Sup_le_Sup h) (le_of_eq (trans Sup_insert bot_sup_eq)) theorem Inf_le_Inf_of_subset_insert_top (h : s βŠ† insert ⊀ t) : Inf t ≀ Inf s := le_trans (le_of_eq (trans top_inf_eq.symm Inf_insert.symm)) (Inf_le_Inf h) theorem Sup_pair {a b : Ξ±} : Sup {a, b} = a βŠ” b := (@is_lub_pair Ξ± _ a b).Sup_eq theorem Inf_pair {a b : Ξ±} : Inf {a, b} = a βŠ“ b := (@is_glb_pair Ξ± _ a b).Inf_eq @[simp] theorem Inf_eq_top : Inf s = ⊀ ↔ (βˆ€a∈s, a = ⊀) := iff.intro (assume h a ha, top_unique $ h β–Έ Inf_le ha) (assume h, top_unique $ le_Inf $ assume a ha, top_le_iff.2 $ h a ha) lemma eq_singleton_top_of_Inf_eq_top_of_nonempty {s : set Ξ±} (h_inf : Inf s = ⊀) (hne : s.nonempty) : s = {⊀} := by { rw set.eq_singleton_iff_nonempty_unique_mem, rw Inf_eq_top at h_inf, exact ⟨hne, h_inf⟩, } @[simp] theorem Sup_eq_bot : Sup s = βŠ₯ ↔ (βˆ€a∈s, a = βŠ₯) := @Inf_eq_top (order_dual Ξ±) _ _ lemma eq_singleton_bot_of_Sup_eq_bot_of_nonempty {s : set Ξ±} (h_sup : Sup s = βŠ₯) (hne : s.nonempty) : s = {βŠ₯} := by { rw set.eq_singleton_iff_nonempty_unique_mem, rw Sup_eq_bot at h_sup, exact ⟨hne, h_sup⟩, } /--Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that `b` is larger than all elements of `s`, and that this is not the case of any `w<b`. See `cSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in conditionally complete lattices. -/ theorem Sup_eq_of_forall_le_of_forall_lt_exists_gt (_ : βˆ€a∈s, a ≀ b) (H : βˆ€w, w < b β†’ (βˆƒa∈s, w < a)) : Sup s = b := have bdd_above s := ⟨b, by assumption⟩, have (Sup s < b) ∨ (Sup s = b) := lt_or_eq_of_le (Sup_le β€Ήβˆ€a∈s, a ≀ bβ€Ί), have Β¬(Sup s < b) := assume: Sup s < b, let ⟨a, _, _⟩ := (H (Sup s) β€ΉSup s < bβ€Ί) in /- a ∈ s, Sup s < a-/ have Sup s < Sup s := lt_of_lt_of_le β€ΉSup s < aβ€Ί (le_Sup β€Ήa ∈ sβ€Ί), show false, by finish [lt_irrefl (Sup s)], show Sup s = b, by finish /--Introduction rule to prove that `b` is the infimum of `s`: it suffices to check that `b` is smaller than all elements of `s`, and that this is not the case of any `w>b`. See `cInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in conditionally complete lattices. -/ theorem Inf_eq_of_forall_ge_of_forall_gt_exists_lt (_ : βˆ€a∈s, b ≀ a) (H : βˆ€w, b < w β†’ (βˆƒa∈s, a < w)) : Inf s = b := @Sup_eq_of_forall_le_of_forall_lt_exists_gt (order_dual Ξ±) _ _ β€Ή_β€Ί β€Ή_β€Ί β€Ή_β€Ί end section complete_linear_order variables [complete_linear_order Ξ±] {s t : set Ξ±} {a b : Ξ±} lemma Inf_lt_iff : Inf s < b ↔ (βˆƒa∈s, a < b) := is_glb_lt_iff (is_glb_Inf s) lemma lt_Sup_iff : b < Sup s ↔ (βˆƒa∈s, b < a) := lt_is_lub_iff (is_lub_Sup s) lemma Sup_eq_top : Sup s = ⊀ ↔ (βˆ€b<⊀, βˆƒa∈s, b < a) := iff.intro (assume (h : Sup s = ⊀) b hb, by rwa [←h, lt_Sup_iff] at hb) (assume h, top_unique $ le_of_not_gt $ assume h', let ⟨a, ha, h⟩ := h _ h' in lt_irrefl a $ lt_of_le_of_lt (le_Sup ha) h) lemma Inf_eq_bot : Inf s = βŠ₯ ↔ (βˆ€b>βŠ₯, βˆƒa∈s, a < b) := @Sup_eq_top (order_dual Ξ±) _ _ lemma lt_supr_iff {f : ΞΉ β†’ Ξ±} : a < supr f ↔ (βˆƒi, a < f i) := lt_Sup_iff.trans exists_range_iff lemma infi_lt_iff {f : ΞΉ β†’ Ξ±} : infi f < a ↔ (βˆƒi, f i < a) := Inf_lt_iff.trans exists_range_iff end complete_linear_order /- ### supr & infi -/ section variables [complete_lattice Ξ±] {s t : ΞΉ β†’ Ξ±} {a b : Ξ±} -- TODO: this declaration gives error when starting smt state --@[ematch] theorem le_supr (s : ΞΉ β†’ Ξ±) (i : ΞΉ) : s i ≀ supr s := le_Sup ⟨i, rfl⟩ @[ematch] theorem le_supr' (s : ΞΉ β†’ Ξ±) (i : ΞΉ) : (: s i ≀ supr s :) := le_Sup ⟨i, rfl⟩ /- TODO: this version would be more powerful, but, alas, the pattern matcher doesn't accept it. @[ematch] theorem le_supr' (s : ΞΉ β†’ Ξ±) (i : ΞΉ) : (: s i :) ≀ (: supr s :) := le_Sup ⟨i, rfl⟩ -/ lemma is_lub_supr : is_lub (range s) (⨆j, s j) := is_lub_Sup _ lemma is_lub.supr_eq (h : is_lub (range s) a) : (⨆j, s j) = a := h.Sup_eq lemma is_glb_infi : is_glb (range s) (β¨…j, s j) := is_glb_Inf _ lemma is_glb.infi_eq (h : is_glb (range s) a) : (β¨…j, s j) = a := h.Inf_eq theorem le_supr_of_le (i : ΞΉ) (h : a ≀ s i) : a ≀ supr s := le_trans h (le_supr _ i) theorem le_bsupr {p : ΞΉ β†’ Prop} {f : Ξ  i (h : p i), Ξ±} (i : ΞΉ) (hi : p i) : f i hi ≀ ⨆ i hi, f i hi := le_supr_of_le i $ le_supr (f i) hi theorem le_bsupr_of_le {p : ΞΉ β†’ Prop} {f : Ξ  i (h : p i), Ξ±} (i : ΞΉ) (hi : p i) (h : a ≀ f i hi) : a ≀ ⨆ i hi, f i hi := le_trans h (le_bsupr i hi) theorem supr_le (h : βˆ€i, s i ≀ a) : supr s ≀ a := Sup_le $ assume b ⟨i, eq⟩, eq β–Έ h i theorem bsupr_le {p : ΞΉ β†’ Prop} {f : Ξ  i (h : p i), Ξ±} (h : βˆ€ i hi, f i hi ≀ a) : (⨆ i (hi : p i), f i hi) ≀ a := supr_le $ Ξ» i, supr_le $ h i theorem bsupr_le_supr (p : ΞΉ β†’ Prop) (f : ΞΉ β†’ Ξ±) : (⨆ i (H : p i), f i) ≀ ⨆ i, f i := bsupr_le (Ξ» i hi, le_supr f i) theorem supr_le_supr (h : βˆ€i, s i ≀ t i) : supr s ≀ supr t := supr_le $ assume i, le_supr_of_le i (h i) theorem supr_le_supr2 {t : ΞΉβ‚‚ β†’ Ξ±} (h : βˆ€i, βˆƒj, s i ≀ t j) : supr s ≀ supr t := supr_le $ assume j, exists.elim (h j) le_supr_of_le theorem bsupr_le_bsupr {p : ΞΉ β†’ Prop} {f g : Ξ  i (hi : p i), Ξ±} (h : βˆ€ i hi, f i hi ≀ g i hi) : (⨆ i hi, f i hi) ≀ ⨆ i hi, g i hi := bsupr_le $ Ξ» i hi, le_trans (h i hi) (le_bsupr i hi) theorem supr_le_supr_const (h : ΞΉ β†’ ΞΉβ‚‚) : (⨆ i:ΞΉ, a) ≀ (⨆ j:ΞΉβ‚‚, a) := supr_le $ le_supr _ ∘ h theorem bsupr_le_bsupr' {p q : ΞΉ β†’ Prop} (hpq : βˆ€ i, p i β†’ q i) {f : ΞΉ β†’ Ξ±} : (⨆ i (hpi : p i), f i) ≀ ⨆ i (hqi : q i), f i := supr_le_supr $ Ξ» i, supr_le_supr_const (hpq i) @[simp] theorem supr_le_iff : supr s ≀ a ↔ (βˆ€i, s i ≀ a) := (is_lub_le_iff is_lub_supr).trans forall_range_iff theorem supr_lt_iff : supr s < a ↔ βˆƒ b < a, βˆ€ i, s i ≀ b := ⟨λ h, ⟨supr s, h, Ξ» i, le_supr s i⟩, Ξ» ⟨b, hba, hsb⟩, (supr_le hsb).trans_lt hba⟩ theorem Sup_eq_supr {s : set Ξ±} : Sup s = (⨆a ∈ s, a) := le_antisymm (Sup_le $ assume b h, le_supr_of_le b $ le_supr _ h) (supr_le $ assume b, supr_le $ assume h, le_Sup h) lemma Sup_eq_supr' {Ξ±} [has_Sup Ξ±] (s : set Ξ±) : Sup s = ⨆ x : s, (x : Ξ±) := by rw [supr, subtype.range_coe] lemma Sup_sUnion {s : set (set Ξ±)} : Sup (⋃₀ s) = ⨆ (t ∈ s), Sup t := begin apply le_antisymm, { apply Sup_le (Ξ» b hb, _), rcases hb with ⟨t, ts, bt⟩, apply le_trans _ (le_supr _ t), exact le_trans (le_Sup bt) (le_supr _ ts), }, { apply supr_le (Ξ» t, _), exact supr_le (Ξ» ts, Sup_le_Sup (Ξ» x xt, ⟨t, ts, xt⟩)) } end lemma le_supr_iff : (a ≀ supr s) ↔ (βˆ€ b, (βˆ€ i, s i ≀ b) β†’ a ≀ b) := ⟨λ h b hb, le_trans h (supr_le hb), Ξ» h, h _ $ Ξ» i, le_supr s i⟩ lemma monotone.le_map_supr [complete_lattice Ξ²] {f : Ξ± β†’ Ξ²} (hf : monotone f) : (⨆ i, f (s i)) ≀ f (supr s) := supr_le $ Ξ» i, hf $ le_supr _ _ lemma monotone.le_map_supr2 [complete_lattice Ξ²] {f : Ξ± β†’ Ξ²} (hf : monotone f) {ΞΉ' : ΞΉ β†’ Sort*} (s : Ξ  i, ΞΉ' i β†’ Ξ±) : (⨆ i (h : ΞΉ' i), f (s i h)) ≀ f (⨆ i (h : ΞΉ' i), s i h) := calc (⨆ i h, f (s i h)) ≀ (⨆ i, f (⨆ h, s i h)) : supr_le_supr $ Ξ» i, hf.le_map_supr ... ≀ f (⨆ i (h : ΞΉ' i), s i h) : hf.le_map_supr lemma monotone.le_map_Sup [complete_lattice Ξ²] {s : set Ξ±} {f : Ξ± β†’ Ξ²} (hf : monotone f) : (⨆a∈s, f a) ≀ f (Sup s) := by rw [Sup_eq_supr]; exact hf.le_map_supr2 _ lemma supr_comp_le {ΞΉ' : Sort*} (f : ΞΉ' β†’ Ξ±) (g : ΞΉ β†’ ΞΉ') : (⨆ x, f (g x)) ≀ ⨆ y, f y := supr_le_supr2 $ Ξ» x, ⟨_, le_refl _⟩ lemma monotone.supr_comp_eq [preorder Ξ²] {f : Ξ² β†’ Ξ±} (hf : monotone f) {s : ΞΉ β†’ Ξ²} (hs : βˆ€ x, βˆƒ i, x ≀ s i) : (⨆ x, f (s x)) = ⨆ y, f y := le_antisymm (supr_comp_le _ _) (supr_le_supr2 $ Ξ» x, (hs x).imp $ Ξ» i hi, hf hi) lemma function.surjective.supr_comp {Ξ± : Type*} [has_Sup Ξ±] {f : ΞΉ β†’ ΞΉβ‚‚} (hf : function.surjective f) (g : ΞΉβ‚‚ β†’ Ξ±) : (⨆ x, g (f x)) = ⨆ y, g y := by simp only [supr, hf.range_comp] lemma supr_congr {Ξ± : Type*} [has_Sup Ξ±] {f : ΞΉ β†’ Ξ±} {g : ΞΉβ‚‚ β†’ Ξ±} (h : ΞΉ β†’ ΞΉβ‚‚) (h1 : function.surjective h) (h2 : βˆ€ x, g (h x) = f x) : (⨆ x, f x) = ⨆ y, g y := by { convert h1.supr_comp g, exact (funext h2).symm } -- TODO: finish doesn't do well here. @[congr] theorem supr_congr_Prop {Ξ± : Type*} [has_Sup Ξ±] {p q : Prop} {f₁ : p β†’ Ξ±} {fβ‚‚ : q β†’ Ξ±} (pq : p ↔ q) (f : βˆ€x, f₁ (pq.mpr x) = fβ‚‚ x) : supr f₁ = supr fβ‚‚ := begin have := propext pq, subst this, congr' with x, apply f end theorem infi_le (s : ΞΉ β†’ Ξ±) (i : ΞΉ) : infi s ≀ s i := Inf_le ⟨i, rfl⟩ @[ematch] theorem infi_le' (s : ΞΉ β†’ Ξ±) (i : ΞΉ) : (: infi s ≀ s i :) := Inf_le ⟨i, rfl⟩ theorem infi_le_of_le (i : ΞΉ) (h : s i ≀ a) : infi s ≀ a := le_trans (infi_le _ i) h theorem binfi_le {p : ΞΉ β†’ Prop} {f : Ξ  i (hi : p i), Ξ±} (i : ΞΉ) (hi : p i) : (β¨… i hi, f i hi) ≀ f i hi := infi_le_of_le i $ infi_le (f i) hi theorem binfi_le_of_le {p : ΞΉ β†’ Prop} {f : Ξ  i (hi : p i), Ξ±} (i : ΞΉ) (hi : p i) (h : f i hi ≀ a) : (β¨… i hi, f i hi) ≀ a := le_trans (binfi_le i hi) h theorem le_infi (h : βˆ€i, a ≀ s i) : a ≀ infi s := le_Inf $ assume b ⟨i, eq⟩, eq β–Έ h i theorem le_binfi {p : ΞΉ β†’ Prop} {f : Ξ  i (h : p i), Ξ±} (h : βˆ€ i hi, a ≀ f i hi) : a ≀ β¨… i hi, f i hi := le_infi $ Ξ» i, le_infi $ h i theorem infi_le_binfi (p : ΞΉ β†’ Prop) (f : ΞΉ β†’ Ξ±) : (β¨… i, f i) ≀ β¨… i (H : p i), f i := le_binfi (Ξ» i hi, infi_le f i) theorem infi_le_infi (h : βˆ€i, s i ≀ t i) : infi s ≀ infi t := le_infi $ assume i, infi_le_of_le i (h i) theorem infi_le_infi2 {t : ΞΉβ‚‚ β†’ Ξ±} (h : βˆ€j, βˆƒi, s i ≀ t j) : infi s ≀ infi t := le_infi $ assume j, exists.elim (h j) infi_le_of_le theorem binfi_le_binfi {p : ΞΉ β†’ Prop} {f g : Ξ  i (h : p i), Ξ±} (h : βˆ€ i hi, f i hi ≀ g i hi) : (β¨… i hi, f i hi) ≀ β¨… i hi, g i hi := le_binfi $ Ξ» i hi, le_trans (binfi_le i hi) (h i hi) theorem infi_le_infi_const (h : ΞΉβ‚‚ β†’ ΞΉ) : (β¨… i:ΞΉ, a) ≀ (β¨… j:ΞΉβ‚‚, a) := le_infi $ infi_le _ ∘ h @[simp] theorem le_infi_iff : a ≀ infi s ↔ (βˆ€i, a ≀ s i) := ⟨assume : a ≀ infi s, assume i, le_trans this (infi_le _ _), le_infi⟩ theorem Inf_eq_infi {s : set Ξ±} : Inf s = (β¨…a ∈ s, a) := @Sup_eq_supr (order_dual Ξ±) _ _ theorem Inf_eq_infi' {Ξ±} [has_Inf Ξ±] (s : set Ξ±) : Inf s = β¨… a : s, a := @Sup_eq_supr' (order_dual Ξ±) _ _ lemma monotone.map_infi_le [complete_lattice Ξ²] {f : Ξ± β†’ Ξ²} (hf : monotone f) : f (infi s) ≀ (β¨… i, f (s i)) := le_infi $ Ξ» i, hf $ infi_le _ _ lemma monotone.map_infi2_le [complete_lattice Ξ²] {f : Ξ± β†’ Ξ²} (hf : monotone f) {ΞΉ' : ΞΉ β†’ Sort*} (s : Ξ  i, ΞΉ' i β†’ Ξ±) : f (β¨… i (h : ΞΉ' i), s i h) ≀ (β¨… i (h : ΞΉ' i), f (s i h)) := @monotone.le_map_supr2 (order_dual Ξ±) (order_dual Ξ²) _ _ _ f hf.order_dual _ _ lemma monotone.map_Inf_le [complete_lattice Ξ²] {s : set Ξ±} {f : Ξ± β†’ Ξ²} (hf : monotone f) : f (Inf s) ≀ β¨… a∈s, f a := by rw [Inf_eq_infi]; exact hf.map_infi2_le _ lemma le_infi_comp {ΞΉ' : Sort*} (f : ΞΉ' β†’ Ξ±) (g : ΞΉ β†’ ΞΉ') : (β¨… y, f y) ≀ β¨… x, f (g x) := infi_le_infi2 $ Ξ» x, ⟨_, le_refl _⟩ lemma monotone.infi_comp_eq [preorder Ξ²] {f : Ξ² β†’ Ξ±} (hf : monotone f) {s : ΞΉ β†’ Ξ²} (hs : βˆ€ x, βˆƒ i, s i ≀ x) : (β¨… x, f (s x)) = β¨… y, f y := le_antisymm (infi_le_infi2 $ Ξ» x, (hs x).imp $ Ξ» i hi, hf hi) (le_infi_comp _ _) lemma function.surjective.infi_comp {Ξ± : Type*} [has_Inf Ξ±] {f : ΞΉ β†’ ΞΉβ‚‚} (hf : function.surjective f) (g : ΞΉβ‚‚ β†’ Ξ±) : (β¨… x, g (f x)) = β¨… y, g y := @function.surjective.supr_comp _ _ (order_dual Ξ±) _ f hf g lemma infi_congr {Ξ± : Type*} [has_Inf Ξ±] {f : ΞΉ β†’ Ξ±} {g : ΞΉβ‚‚ β†’ Ξ±} (h : ΞΉ β†’ ΞΉβ‚‚) (h1 : function.surjective h) (h2 : βˆ€ x, g (h x) = f x) : (β¨… x, f x) = β¨… y, g y := @supr_congr _ _ (order_dual Ξ±) _ _ _ h h1 h2 @[congr] theorem infi_congr_Prop {Ξ± : Type*} [has_Inf Ξ±] {p q : Prop} {f₁ : p β†’ Ξ±} {fβ‚‚ : q β†’ Ξ±} (pq : p ↔ q) (f : βˆ€x, f₁ (pq.mpr x) = fβ‚‚ x) : infi f₁ = infi fβ‚‚ := @supr_congr_Prop (order_dual Ξ±) _ p q f₁ fβ‚‚ pq f lemma supr_const_le {x : Ξ±} : (⨆ (h : ΞΉ), x) ≀ x := supr_le (Ξ» _, le_rfl) lemma le_infi_const {x : Ξ±} : x ≀ (β¨… (h : ΞΉ), x) := le_infi (Ξ» _, le_rfl) -- We will generalize this to conditionally complete lattices in `cinfi_const`. theorem infi_const [nonempty ΞΉ] {a : Ξ±} : (β¨… b:ΞΉ, a) = a := by rw [infi, range_const, Inf_singleton] -- We will generalize this to conditionally complete lattices in `csupr_const`. theorem supr_const [nonempty ΞΉ] {a : Ξ±} : (⨆ b:ΞΉ, a) = a := @infi_const (order_dual Ξ±) _ _ _ _ @[simp] lemma infi_top : (β¨…i:ΞΉ, ⊀ : Ξ±) = ⊀ := top_unique $ le_infi $ assume i, le_refl _ @[simp] lemma supr_bot : (⨆i:ΞΉ, βŠ₯ : Ξ±) = βŠ₯ := @infi_top (order_dual Ξ±) _ _ @[simp] lemma infi_eq_top : infi s = ⊀ ↔ (βˆ€i, s i = ⊀) := Inf_eq_top.trans forall_range_iff @[simp] lemma supr_eq_bot : supr s = βŠ₯ ↔ (βˆ€i, s i = βŠ₯) := Sup_eq_bot.trans forall_range_iff @[simp] lemma infi_pos {p : Prop} {f : p β†’ Ξ±} (hp : p) : (β¨… h : p, f h) = f hp := le_antisymm (infi_le _ _) (le_infi $ assume h, le_refl _) @[simp] lemma infi_neg {p : Prop} {f : p β†’ Ξ±} (hp : Β¬ p) : (β¨… h : p, f h) = ⊀ := le_antisymm le_top $ le_infi $ assume h, (hp h).elim @[simp] lemma supr_pos {p : Prop} {f : p β†’ Ξ±} (hp : p) : (⨆ h : p, f h) = f hp := le_antisymm (supr_le $ assume h, le_refl _) (le_supr _ _) @[simp] lemma supr_neg {p : Prop} {f : p β†’ Ξ±} (hp : Β¬ p) : (⨆ h : p, f h) = βŠ₯ := le_antisymm (supr_le $ assume h, (hp h).elim) bot_le /--Introduction rule to prove that `b` is the supremum of `f`: it suffices to check that `b` is larger than `f i` for all `i`, and that this is not the case of any `w<b`. See `csupr_eq_of_forall_le_of_forall_lt_exists_gt` for a version in conditionally complete lattices. -/ theorem supr_eq_of_forall_le_of_forall_lt_exists_gt {f : ΞΉ β†’ Ξ±} (h₁ : βˆ€ i, f i ≀ b) (hβ‚‚ : βˆ€ w, w < b β†’ (βˆƒ i, w < f i)) : (⨆ (i : ΞΉ), f i) = b := Sup_eq_of_forall_le_of_forall_lt_exists_gt (forall_range_iff.mpr h₁) (Ξ» w hw, exists_range_iff.mpr $ hβ‚‚ w hw) /--Introduction rule to prove that `b` is the infimum of `f`: it suffices to check that `b` is smaller than `f i` for all `i`, and that this is not the case of any `w>b`. See `cinfi_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in conditionally complete lattices. -/ theorem infi_eq_of_forall_ge_of_forall_gt_exists_lt {f : ΞΉ β†’ Ξ±} (h₁ : βˆ€ i, b ≀ f i) (hβ‚‚ : βˆ€ w, b < w β†’ (βˆƒ i, f i < w)) : (β¨… (i : ΞΉ), f i) = b := @supr_eq_of_forall_le_of_forall_lt_exists_gt (order_dual Ξ±) _ _ _ β€Ή_β€Ί β€Ή_β€Ί β€Ή_β€Ί lemma supr_eq_dif {p : Prop} [decidable p] (a : p β†’ Ξ±) : (⨆h:p, a h) = (if h : p then a h else βŠ₯) := by by_cases p; simp [h] lemma supr_eq_if {p : Prop} [decidable p] (a : Ξ±) : (⨆h:p, a) = (if p then a else βŠ₯) := supr_eq_dif (Ξ» _, a) lemma infi_eq_dif {p : Prop} [decidable p] (a : p β†’ Ξ±) : (β¨…h:p, a h) = (if h : p then a h else ⊀) := @supr_eq_dif (order_dual Ξ±) _ _ _ _ lemma infi_eq_if {p : Prop} [decidable p] (a : Ξ±) : (β¨…h:p, a) = (if p then a else ⊀) := infi_eq_dif (Ξ» _, a) -- TODO: should this be @[simp]? theorem infi_comm {f : ΞΉ β†’ ΞΉβ‚‚ β†’ Ξ±} : (β¨…i, β¨…j, f i j) = (β¨…j, β¨…i, f i j) := le_antisymm (le_infi $ assume i, le_infi $ assume j, infi_le_of_le j $ infi_le _ i) (le_infi $ assume j, le_infi $ assume i, infi_le_of_le i $ infi_le _ j) /- TODO: this is strange. In the proof below, we get exactly the desired among the equalities, but close does not get it. begin apply @le_antisymm, simp, intros, begin [smt] ematch, ematch, ematch, trace_state, have := le_refl (f i_1 i), trace_state, close end end -/ -- TODO: should this be @[simp]? theorem supr_comm {f : ΞΉ β†’ ΞΉβ‚‚ β†’ Ξ±} : (⨆i, ⨆j, f i j) = (⨆j, ⨆i, f i j) := @infi_comm (order_dual Ξ±) _ _ _ _ @[simp] theorem infi_infi_eq_left {b : Ξ²} {f : Ξ x:Ξ², x = b β†’ Ξ±} : (β¨…x, β¨…h:x = b, f x h) = f b rfl := le_antisymm (infi_le_of_le b $ infi_le _ rfl) (le_infi $ assume b', le_infi $ assume eq, match b', eq with ._, rfl := le_refl _ end) @[simp] theorem infi_infi_eq_right {b : Ξ²} {f : Ξ x:Ξ², b = x β†’ Ξ±} : (β¨…x, β¨…h:b = x, f x h) = f b rfl := le_antisymm (infi_le_of_le b $ infi_le _ rfl) (le_infi $ assume b', le_infi $ assume eq, match b', eq with ._, rfl := le_refl _ end) @[simp] theorem supr_supr_eq_left {b : Ξ²} {f : Ξ x:Ξ², x = b β†’ Ξ±} : (⨆x, ⨆h : x = b, f x h) = f b rfl := @infi_infi_eq_left (order_dual Ξ±) _ _ _ _ @[simp] theorem supr_supr_eq_right {b : Ξ²} {f : Ξ x:Ξ², b = x β†’ Ξ±} : (⨆x, ⨆h : b = x, f x h) = f b rfl := @infi_infi_eq_right (order_dual Ξ±) _ _ _ _ attribute [ematch] le_refl theorem infi_subtype {p : ΞΉ β†’ Prop} {f : subtype p β†’ Ξ±} : (β¨… x, f x) = (β¨… i (h:p i), f ⟨i, h⟩) := le_antisymm (le_infi $ assume i, le_infi $ assume : p i, infi_le _ _) (le_infi $ assume ⟨i, h⟩, infi_le_of_le i $ infi_le _ _) lemma infi_subtype' {p : ΞΉ β†’ Prop} {f : βˆ€ i, p i β†’ Ξ±} : (β¨… i (h : p i), f i h) = (β¨… x : subtype p, f x x.property) := (@infi_subtype _ _ _ p (Ξ» x, f x.val x.property)).symm lemma infi_subtype'' {ΞΉ} (s : set ΞΉ) (f : ΞΉ β†’ Ξ±) : (β¨… i : s, f i) = β¨… (t : ΞΉ) (H : t ∈ s), f t := infi_subtype theorem infi_inf_eq {f g : ΞΉ β†’ Ξ±} : (β¨… x, f x βŠ“ g x) = (β¨… x, f x) βŠ“ (β¨… x, g x) := le_antisymm (le_inf (le_infi $ assume i, infi_le_of_le i inf_le_left) (le_infi $ assume i, infi_le_of_le i inf_le_right)) (le_infi $ assume i, le_inf (inf_le_of_left_le $ infi_le _ _) (inf_le_of_right_le $ infi_le _ _)) /- TODO: here is another example where more flexible pattern matching might help. begin apply @le_antisymm, safe, pose h := f a βŠ“ g a, begin [smt] ematch, ematch end end -/ lemma infi_inf [h : nonempty ΞΉ] {f : ΞΉ β†’ Ξ±} {a : Ξ±} : (β¨…x, f x) βŠ“ a = (β¨… x, f x βŠ“ a) := by rw [infi_inf_eq, infi_const] lemma inf_infi [nonempty ΞΉ] {f : ΞΉ β†’ Ξ±} {a : Ξ±} : a βŠ“ (β¨…x, f x) = (β¨… x, a βŠ“ f x) := by rw [inf_comm, infi_inf]; simp [inf_comm] lemma binfi_inf {p : ΞΉ β†’ Prop} {f : Ξ  i (hi : p i), Ξ±} {a : Ξ±} (h : βˆƒ i, p i) : (β¨…i (h : p i), f i h) βŠ“ a = (β¨… i (h : p i), f i h βŠ“ a) := by haveI : nonempty {i // p i} := (let ⟨i, hi⟩ := h in ⟨⟨i, hi⟩⟩); rw [infi_subtype', infi_subtype', infi_inf] lemma inf_binfi {p : ΞΉ β†’ Prop} {f : Ξ  i (hi : p i), Ξ±} {a : Ξ±} (h : βˆƒ i, p i) : a βŠ“ (β¨…i (h : p i), f i h) = (β¨… i (h : p i), a βŠ“ f i h) := by simpa only [inf_comm] using binfi_inf h theorem supr_sup_eq {f g : ΞΉ β†’ Ξ±} : (⨆ x, f x βŠ” g x) = (⨆ x, f x) βŠ” (⨆ x, g x) := @infi_inf_eq (order_dual Ξ±) ΞΉ _ _ _ lemma supr_sup [h : nonempty ΞΉ] {f : ΞΉ β†’ Ξ±} {a : Ξ±} : (⨆ x, f x) βŠ” a = (⨆ x, f x βŠ” a) := @infi_inf (order_dual Ξ±) _ _ _ _ _ lemma sup_supr [nonempty ΞΉ] {f : ΞΉ β†’ Ξ±} {a : Ξ±} : a βŠ” (⨆ x, f x) = (⨆ x, a βŠ” f x) := @inf_infi (order_dual Ξ±) _ _ _ _ _ /-! ### `supr` and `infi` under `Prop` -/ @[simp] theorem infi_false {s : false β†’ Ξ±} : infi s = ⊀ := le_antisymm le_top (le_infi $ assume i, false.elim i) @[simp] theorem supr_false {s : false β†’ Ξ±} : supr s = βŠ₯ := le_antisymm (supr_le $ assume i, false.elim i) bot_le theorem infi_true {s : true β†’ Ξ±} : infi s = s trivial := infi_pos trivial theorem supr_true {s : true β†’ Ξ±} : supr s = s trivial := supr_pos trivial @[simp] theorem infi_exists {p : ΞΉ β†’ Prop} {f : Exists p β†’ Ξ±} : (β¨… x, f x) = (β¨… i, β¨… h:p i, f ⟨i, h⟩) := le_antisymm (le_infi $ assume i, le_infi $ assume : p i, infi_le _ _) (le_infi $ assume ⟨i, h⟩, infi_le_of_le i $ infi_le _ _) @[simp] theorem supr_exists {p : ΞΉ β†’ Prop} {f : Exists p β†’ Ξ±} : (⨆ x, f x) = (⨆ i, ⨆ h:p i, f ⟨i, h⟩) := @infi_exists (order_dual Ξ±) _ _ _ _ theorem infi_and {p q : Prop} {s : p ∧ q β†’ Ξ±} : infi s = (β¨… h₁ hβ‚‚, s ⟨h₁, hβ‚‚βŸ©) := le_antisymm (le_infi $ assume i, le_infi $ assume j, infi_le _ _) (le_infi $ assume ⟨i, h⟩, infi_le_of_le i $ infi_le _ _) /-- The symmetric case of `infi_and`, useful for rewriting into a infimum over a conjunction -/ lemma infi_and' {p q : Prop} {s : p β†’ q β†’ Ξ±} : (β¨… (h₁ : p) (hβ‚‚ : q), s h₁ hβ‚‚) = β¨… (h : p ∧ q), s h.1 h.2 := by { symmetry, exact infi_and } theorem supr_and {p q : Prop} {s : p ∧ q β†’ Ξ±} : supr s = (⨆ h₁ hβ‚‚, s ⟨h₁, hβ‚‚βŸ©) := @infi_and (order_dual Ξ±) _ _ _ _ /-- The symmetric case of `supr_and`, useful for rewriting into a supremum over a conjunction -/ lemma supr_and' {p q : Prop} {s : p β†’ q β†’ Ξ±} : (⨆ (h₁ : p) (hβ‚‚ : q), s h₁ hβ‚‚) = ⨆ (h : p ∧ q), s h.1 h.2 := by { symmetry, exact supr_and } theorem infi_or {p q : Prop} {s : p ∨ q β†’ Ξ±} : infi s = (β¨… h : p, s (or.inl h)) βŠ“ (β¨… h : q, s (or.inr h)) := le_antisymm (le_inf (infi_le_infi2 $ assume j, ⟨_, le_refl _⟩) (infi_le_infi2 $ assume j, ⟨_, le_refl _⟩)) (le_infi $ assume i, match i with | or.inl i := inf_le_of_left_le $ infi_le _ _ | or.inr j := inf_le_of_right_le $ infi_le _ _ end) theorem supr_or {p q : Prop} {s : p ∨ q β†’ Ξ±} : (⨆ x, s x) = (⨆ i, s (or.inl i)) βŠ” (⨆ j, s (or.inr j)) := @infi_or (order_dual Ξ±) _ _ _ _ section variables (p : ΞΉ β†’ Prop) [decidable_pred p] lemma supr_dite (f : Ξ  i, p i β†’ Ξ±) (g : Ξ  i, Β¬p i β†’ Ξ±) : (⨆ i, if h : p i then f i h else g i h) = (⨆ i (h : p i), f i h) βŠ” (⨆ i (h : Β¬ p i), g i h) := begin rw ←supr_sup_eq, congr' 1 with i, split_ifs with h; simp [h], end lemma supr_ite (f g : ΞΉ β†’ Ξ±) : (⨆ i, if p i then f i else g i) = (⨆ i (h : p i), f i) βŠ” (⨆ i (h : Β¬ p i), g i) := supr_dite _ _ _ lemma infi_dite (f : Ξ  i, p i β†’ Ξ±) (g : Ξ  i, Β¬p i β†’ Ξ±) : (β¨… i, if h : p i then f i h else g i h) = (β¨… i (h : p i), f i h) βŠ“ (β¨… i (h : Β¬ p i), g i h) := supr_dite p (show Ξ  i, p i β†’ order_dual Ξ±, from f) g lemma infi_ite (f g : ΞΉ β†’ Ξ±) : (β¨… i, if p i then f i else g i) = (β¨… i (h : p i), f i) βŠ“ (β¨… i (h : Β¬ p i), g i) := infi_dite _ _ _ end lemma Sup_range {Ξ± : Type*} [has_Sup Ξ±] {f : ΞΉ β†’ Ξ±} : Sup (range f) = supr f := rfl lemma Inf_range {Ξ± : Type*} [has_Inf Ξ±] {f : ΞΉ β†’ Ξ±} : Inf (range f) = infi f := rfl lemma supr_range' {Ξ±} [has_Sup Ξ±] (g : Ξ² β†’ Ξ±) (f : ΞΉ β†’ Ξ²) : (⨆ b : range f, g b) = ⨆ i, g (f i) := by rw [supr, supr, ← image_eq_range, ← range_comp] lemma infi_range' {Ξ±} [has_Inf Ξ±] (g : Ξ² β†’ Ξ±) (f : ΞΉ β†’ Ξ²) : (β¨… b : range f, g b) = β¨… i, g (f i) := @supr_range' _ _ (order_dual Ξ±) _ _ _ lemma infi_range {g : Ξ² β†’ Ξ±} {f : ΞΉ β†’ Ξ²} : (β¨…b∈range f, g b) = (β¨…i, g (f i)) := by rw [← infi_subtype'', infi_range'] lemma supr_range {g : Ξ² β†’ Ξ±} {f : ΞΉ β†’ Ξ²} : (⨆b∈range f, g b) = (⨆i, g (f i)) := @infi_range (order_dual Ξ±) _ _ _ _ _ theorem Inf_image' {Ξ±} [has_Inf Ξ±] {s : set Ξ²} {f : Ξ² β†’ Ξ±} : Inf (f '' s) = (β¨… a : s, f a) := by rw [infi, image_eq_range] theorem Sup_image' {Ξ±} [has_Sup Ξ±] {s : set Ξ²} {f : Ξ² β†’ Ξ±} : Sup (f '' s) = (⨆ a : s, f a) := @Inf_image' _ (order_dual Ξ±) _ _ _ theorem Inf_image {s : set Ξ²} {f : Ξ² β†’ Ξ±} : Inf (f '' s) = (β¨… a ∈ s, f a) := by rw [← infi_subtype'', Inf_image'] theorem Sup_image {s : set Ξ²} {f : Ξ² β†’ Ξ±} : Sup (f '' s) = (⨆ a ∈ s, f a) := @Inf_image (order_dual Ξ±) _ _ _ _ /- ### supr and infi under set constructions -/ theorem infi_emptyset {f : Ξ² β†’ Ξ±} : (β¨… x ∈ (βˆ… : set Ξ²), f x) = ⊀ := by simp theorem supr_emptyset {f : Ξ² β†’ Ξ±} : (⨆ x ∈ (βˆ… : set Ξ²), f x) = βŠ₯ := by simp theorem infi_univ {f : Ξ² β†’ Ξ±} : (β¨… x ∈ (univ : set Ξ²), f x) = (β¨… x, f x) := by simp theorem supr_univ {f : Ξ² β†’ Ξ±} : (⨆ x ∈ (univ : set Ξ²), f x) = (⨆ x, f x) := by simp theorem infi_union {f : Ξ² β†’ Ξ±} {s t : set Ξ²} : (β¨… x ∈ s βˆͺ t, f x) = (β¨…x∈s, f x) βŠ“ (β¨…x∈t, f x) := by simp only [← infi_inf_eq, infi_or] lemma infi_split (f : Ξ² β†’ Ξ±) (p : Ξ² β†’ Prop) : (β¨… i, f i) = (β¨… i (h : p i), f i) βŠ“ (β¨… i (h : Β¬ p i), f i) := by simpa [classical.em] using @infi_union _ _ _ f {i | p i} {i | Β¬ p i} lemma infi_split_single (f : Ξ² β†’ Ξ±) (iβ‚€ : Ξ²) : (β¨… i, f i) = f iβ‚€ βŠ“ (β¨… i (h : i β‰  iβ‚€), f i) := by convert infi_split _ _; simp theorem infi_le_infi_of_subset {f : Ξ² β†’ Ξ±} {s t : set Ξ²} (h : s βŠ† t) : (β¨… x ∈ t, f x) ≀ (β¨… x ∈ s, f x) := by rw [(union_eq_self_of_subset_left h).symm, infi_union]; exact inf_le_left theorem supr_union {f : Ξ² β†’ Ξ±} {s t : set Ξ²} : (⨆ x ∈ s βˆͺ t, f x) = (⨆x∈s, f x) βŠ” (⨆x∈t, f x) := @infi_union (order_dual Ξ±) _ _ _ _ _ lemma supr_split (f : Ξ² β†’ Ξ±) (p : Ξ² β†’ Prop) : (⨆ i, f i) = (⨆ i (h : p i), f i) βŠ” (⨆ i (h : Β¬ p i), f i) := @infi_split (order_dual Ξ±) _ _ _ _ lemma supr_split_single (f : Ξ² β†’ Ξ±) (iβ‚€ : Ξ²) : (⨆ i, f i) = f iβ‚€ βŠ” (⨆ i (h : i β‰  iβ‚€), f i) := @infi_split_single (order_dual Ξ±) _ _ _ _ theorem supr_le_supr_of_subset {f : Ξ² β†’ Ξ±} {s t : set Ξ²} (h : s βŠ† t) : (⨆ x ∈ s, f x) ≀ (⨆ x ∈ t, f x) := @infi_le_infi_of_subset (order_dual Ξ±) _ _ _ _ _ h theorem infi_insert {f : Ξ² β†’ Ξ±} {s : set Ξ²} {b : Ξ²} : (β¨… x ∈ insert b s, f x) = f b βŠ“ (β¨…x∈s, f x) := eq.trans infi_union $ congr_arg (Ξ»x:Ξ±, x βŠ“ (β¨…x∈s, f x)) infi_infi_eq_left theorem supr_insert {f : Ξ² β†’ Ξ±} {s : set Ξ²} {b : Ξ²} : (⨆ x ∈ insert b s, f x) = f b βŠ” (⨆x∈s, f x) := eq.trans supr_union $ congr_arg (Ξ»x:Ξ±, x βŠ” (⨆x∈s, f x)) supr_supr_eq_left theorem infi_singleton {f : Ξ² β†’ Ξ±} {b : Ξ²} : (β¨… x ∈ (singleton b : set Ξ²), f x) = f b := by simp theorem infi_pair {f : Ξ² β†’ Ξ±} {a b : Ξ²} : (β¨… x ∈ ({a, b} : set Ξ²), f x) = f a βŠ“ f b := by rw [infi_insert, infi_singleton] theorem supr_singleton {f : Ξ² β†’ Ξ±} {b : Ξ²} : (⨆ x ∈ (singleton b : set Ξ²), f x) = f b := @infi_singleton (order_dual Ξ±) _ _ _ _ theorem supr_pair {f : Ξ² β†’ Ξ±} {a b : Ξ²} : (⨆ x ∈ ({a, b} : set Ξ²), f x) = f a βŠ” f b := by rw [supr_insert, supr_singleton] lemma infi_image {Ξ³} {f : Ξ² β†’ Ξ³} {g : Ξ³ β†’ Ξ±} {t : set Ξ²} : (β¨… c ∈ f '' t, g c) = (β¨… b ∈ t, g (f b)) := by rw [← Inf_image, ← Inf_image, ← image_comp] lemma supr_image {Ξ³} {f : Ξ² β†’ Ξ³} {g : Ξ³ β†’ Ξ±} {t : set Ξ²} : (⨆ c ∈ f '' t, g c) = (⨆ b ∈ t, g (f b)) := @infi_image (order_dual Ξ±) _ _ _ _ _ _ /-! ### `supr` and `infi` under `Type` -/ theorem supr_of_empty' {Ξ± ΞΉ} [has_Sup Ξ±] [is_empty ΞΉ] (f : ΞΉ β†’ Ξ±) : supr f = Sup (βˆ… : set Ξ±) := congr_arg Sup (range_eq_empty f) theorem supr_of_empty [is_empty ΞΉ] (f : ΞΉ β†’ Ξ±) : supr f = βŠ₯ := (supr_of_empty' f).trans Sup_empty theorem infi_of_empty' {Ξ± ΞΉ} [has_Inf Ξ±] [is_empty ΞΉ] (f : ΞΉ β†’ Ξ±) : infi f = Inf (βˆ… : set Ξ±) := congr_arg Inf (range_eq_empty f) theorem infi_of_empty [is_empty ΞΉ] (f : ΞΉ β†’ Ξ±) : infi f = ⊀ := @supr_of_empty (order_dual Ξ±) _ _ _ f lemma supr_bool_eq {f : bool β†’ Ξ±} : (⨆b:bool, f b) = f tt βŠ” f ff := by rw [supr, bool.range_eq, Sup_pair, sup_comm] lemma infi_bool_eq {f : bool β†’ Ξ±} : (β¨…b:bool, f b) = f tt βŠ“ f ff := @supr_bool_eq (order_dual Ξ±) _ _ lemma sup_eq_supr (x y : Ξ±) : x βŠ” y = ⨆ b : bool, cond b x y := by rw [supr_bool_eq, bool.cond_tt, bool.cond_ff] lemma inf_eq_infi (x y : Ξ±) : x βŠ“ y = β¨… b : bool, cond b x y := @sup_eq_supr (order_dual Ξ±) _ _ _ lemma is_glb_binfi {s : set Ξ²} {f : Ξ² β†’ Ξ±} : is_glb (f '' s) (β¨… x ∈ s, f x) := by simpa only [range_comp, subtype.range_coe, infi_subtype'] using @is_glb_infi Ξ± s _ (f ∘ coe) theorem supr_subtype {p : ΞΉ β†’ Prop} {f : subtype p β†’ Ξ±} : (⨆ x, f x) = (⨆ i (h:p i), f ⟨i, h⟩) := @infi_subtype (order_dual Ξ±) _ _ _ _ lemma supr_subtype' {p : ΞΉ β†’ Prop} {f : βˆ€ i, p i β†’ Ξ±} : (⨆ i (h : p i), f i h) = (⨆ x : subtype p, f x x.property) := (@supr_subtype _ _ _ p (Ξ» x, f x.val x.property)).symm lemma supr_subtype'' {ΞΉ} (s : set ΞΉ) (f : ΞΉ β†’ Ξ±) : (⨆ i : s, f i) = ⨆ (t : ΞΉ) (H : t ∈ s), f t := supr_subtype lemma is_lub_bsupr {s : set Ξ²} {f : Ξ² β†’ Ξ±} : is_lub (f '' s) (⨆ x ∈ s, f x) := by simpa only [range_comp, subtype.range_coe, supr_subtype'] using @is_lub_supr Ξ± s _ (f ∘ coe) theorem infi_sigma {p : Ξ² β†’ Type*} {f : sigma p β†’ Ξ±} : (β¨… x, f x) = (β¨… i (h:p i), f ⟨i, h⟩) := eq_of_forall_le_iff $ Ξ» c, by simp only [le_infi_iff, sigma.forall] theorem supr_sigma {p : Ξ² β†’ Type*} {f : sigma p β†’ Ξ±} : (⨆ x, f x) = (⨆ i (h:p i), f ⟨i, h⟩) := @infi_sigma (order_dual Ξ±) _ _ _ _ theorem infi_prod {Ξ³ : Type*} {f : Ξ² Γ— Ξ³ β†’ Ξ±} : (β¨… x, f x) = (β¨… i j, f (i, j)) := eq_of_forall_le_iff $ Ξ» c, by simp only [le_infi_iff, prod.forall] theorem supr_prod {Ξ³ : Type*} {f : Ξ² Γ— Ξ³ β†’ Ξ±} : (⨆ x, f x) = (⨆ i j, f (i, j)) := @infi_prod (order_dual Ξ±) _ _ _ _ theorem infi_sum {Ξ³ : Type*} {f : Ξ² βŠ• Ξ³ β†’ Ξ±} : (β¨… x, f x) = (β¨… i, f (sum.inl i)) βŠ“ (β¨… j, f (sum.inr j)) := eq_of_forall_le_iff $ Ξ» c, by simp only [le_inf_iff, le_infi_iff, sum.forall] theorem supr_sum {Ξ³ : Type*} {f : Ξ² βŠ• Ξ³ β†’ Ξ±} : (⨆ x, f x) = (⨆ i, f (sum.inl i)) βŠ” (⨆ j, f (sum.inr j)) := @infi_sum (order_dual Ξ±) _ _ _ _ theorem supr_option (f : option Ξ² β†’ Ξ±) : (⨆ o, f o) = f none βŠ” ⨆ b, f (option.some b) := eq_of_forall_ge_iff $ Ξ» c, by simp only [supr_le_iff, sup_le_iff, option.forall] theorem infi_option (f : option Ξ² β†’ Ξ±) : (β¨… o, f o) = f none βŠ“ β¨… b, f (option.some b) := @supr_option (order_dual Ξ±) _ _ _ /-! ### `supr` and `infi` under `β„•` -/ lemma supr_ge_eq_supr_nat_add {u : β„• β†’ Ξ±} (n : β„•) : (⨆ i β‰₯ n, u i) = ⨆ i, u (i + n) := begin apply le_antisymm; simp only [supr_le_iff], { exact Ξ» i hi, le_Sup ⟨i - n, by { dsimp only, rw nat.sub_add_cancel hi }⟩ }, { exact Ξ» i, le_Sup ⟨i + n, supr_pos (nat.le_add_left _ _)⟩ } end lemma infi_ge_eq_infi_nat_add {u : β„• β†’ Ξ±} (n : β„•) : (β¨… i β‰₯ n, u i) = β¨… i, u (i + n) := @supr_ge_eq_supr_nat_add (order_dual Ξ±) _ _ _ lemma monotone.supr_nat_add {f : β„• β†’ Ξ±} (hf : monotone f) (k : β„•) : (⨆ n, f (n + k)) = ⨆ n, f n := le_antisymm (supr_le (Ξ» i, (le_refl _).trans (le_supr _ (i + k)))) (supr_le_supr (Ξ» i, hf (nat.le_add_right i k))) @[simp] lemma supr_infi_ge_nat_add (f : β„• β†’ Ξ±) (k : β„•) : (⨆ n, β¨… i β‰₯ n, f (i + k)) = ⨆ n, β¨… i β‰₯ n, f i := begin have hf : monotone (Ξ» n, β¨… i β‰₯ n, f i), from Ξ» n m hnm, le_infi (Ξ» i, (infi_le _ i).trans (le_infi (Ξ» h, infi_le _ (hnm.trans h)))), rw ←monotone.supr_nat_add hf k, { simp_rw [infi_ge_eq_infi_nat_add, ←nat.add_assoc], }, end lemma sup_supr_nat_succ (u : β„• β†’ Ξ±) : u 0 βŠ” (⨆ i, u (i + 1)) = ⨆ i, u i := begin refine eq_of_forall_ge_iff (Ξ» c, _), simp only [sup_le_iff, supr_le_iff], refine ⟨λ h, _, Ξ» h, ⟨h _, Ξ» i, h _⟩⟩, rintro (_|i), exacts [h.1, h.2 i] end lemma inf_infi_nat_succ (u : β„• β†’ Ξ±) : u 0 βŠ“ (β¨… i, u (i + 1)) = β¨… i, u i := @sup_supr_nat_succ (order_dual Ξ±) _ u end section complete_linear_order variables [complete_linear_order Ξ±] lemma supr_eq_top (f : ΞΉ β†’ Ξ±) : supr f = ⊀ ↔ (βˆ€b<⊀, βˆƒi, b < f i) := by simp only [← Sup_range, Sup_eq_top, set.exists_range_iff] lemma infi_eq_bot (f : ΞΉ β†’ Ξ±) : infi f = βŠ₯ ↔ (βˆ€b>βŠ₯, βˆƒi, f i < b) := by simp only [← Inf_range, Inf_eq_bot, set.exists_range_iff] end complete_linear_order /-! ### Instances -/ instance Prop.complete_lattice : complete_lattice Prop := { Sup := Ξ»s, βˆƒa∈s, a, le_Sup := assume s a h p, ⟨a, h, p⟩, Sup_le := assume s a h ⟨b, h', p⟩, h b h' p, Inf := Ξ»s, βˆ€a:Prop, a∈s β†’ a, Inf_le := assume s a h p, p a h, le_Inf := assume s a h p b hb, h b hb p, .. Prop.bounded_distrib_lattice } @[simp] lemma Inf_Prop_eq {s : set Prop} : Inf s = (βˆ€p ∈ s, p) := rfl @[simp] lemma Sup_Prop_eq {s : set Prop} : Sup s = (βˆƒp ∈ s, p) := rfl @[simp] lemma infi_Prop_eq {ΞΉ : Sort*} {p : ΞΉ β†’ Prop} : (β¨…i, p i) = (βˆ€i, p i) := le_antisymm (assume h i, h _ ⟨i, rfl⟩ ) (assume h p ⟨i, eq⟩, eq β–Έ h i) @[simp] lemma supr_Prop_eq {ΞΉ : Sort*} {p : ΞΉ β†’ Prop} : (⨆i, p i) = (βˆƒi, p i) := le_antisymm (Ξ» ⟨q, ⟨i, (eq : p i = q)⟩, hq⟩, ⟨i, eq.symm β–Έ hq⟩) (Ξ» ⟨i, hi⟩, ⟨p i, ⟨i, rfl⟩, hi⟩) instance pi.has_Sup {Ξ± : Type*} {Ξ² : Ξ± β†’ Type*} [Ξ  i, has_Sup (Ξ² i)] : has_Sup (Ξ  i, Ξ² i) := ⟨λ s i, ⨆ f : s, (f : Ξ  i, Ξ² i) i⟩ instance pi.has_Inf {Ξ± : Type*} {Ξ² : Ξ± β†’ Type*} [Ξ  i, has_Inf (Ξ² i)] : has_Inf (Ξ  i, Ξ² i) := ⟨λ s i, β¨… f : s, (f : Ξ  i, Ξ² i) i⟩ instance pi.complete_lattice {Ξ± : Type*} {Ξ² : Ξ± β†’ Type*} [βˆ€ i, complete_lattice (Ξ² i)] : complete_lattice (Ξ  i, Ξ² i) := { Sup := Sup, Inf := Inf, le_Sup := Ξ» s f hf i, le_supr (Ξ» f : s, (f : Ξ  i, Ξ² i) i) ⟨f, hf⟩, Inf_le := Ξ» s f hf i, infi_le (Ξ» f : s, (f : Ξ  i, Ξ² i) i) ⟨f, hf⟩, Sup_le := Ξ» s f hf i, supr_le $ Ξ» g, hf g g.2 i, le_Inf := Ξ» s f hf i, le_infi $ Ξ» g, hf g g.2 i, .. pi.bounded_lattice } lemma Inf_apply {Ξ± : Type*} {Ξ² : Ξ± β†’ Type*} [Ξ  i, has_Inf (Ξ² i)] {s : set (Ξ a, Ξ² a)} {a : Ξ±} : (Inf s) a = (β¨… f : s, (f : Ξ a, Ξ² a) a) := rfl @[simp] lemma infi_apply {Ξ± : Type*} {Ξ² : Ξ± β†’ Type*} {ΞΉ : Sort*} [Ξ  i, has_Inf (Ξ² i)] {f : ΞΉ β†’ Ξ a, Ξ² a} {a : Ξ±} : (β¨…i, f i) a = (β¨…i, f i a) := by rw [infi, Inf_apply, infi, infi, ← image_eq_range (Ξ» f : Ξ  i, Ξ² i, f a) (range f), ← range_comp] lemma Sup_apply {Ξ± : Type*} {Ξ² : Ξ± β†’ Type*} [Ξ  i, has_Sup (Ξ² i)] {s : set (Ξ a, Ξ² a)} {a : Ξ±} : (Sup s) a = (⨆f:s, (f : Ξ a, Ξ² a) a) := rfl lemma unary_relation_Sup_iff {Ξ± : Type*} (s : set (Ξ± β†’ Prop)) {a : Ξ±} : Sup s a ↔ βˆƒ (r : Ξ± β†’ Prop), r ∈ s ∧ r a := by { change (βˆƒ _, _) ↔ _, simp [-eq_iff_iff] } lemma binary_relation_Sup_iff {Ξ± Ξ² : Type*} (s : set (Ξ± β†’ Ξ² β†’ Prop)) {a : Ξ±} {b : Ξ²} : Sup s a b ↔ βˆƒ (r : Ξ± β†’ Ξ² β†’ Prop), r ∈ s ∧ r a b := by { change (βˆƒ _, _) ↔ _, simp [-eq_iff_iff] } @[simp] lemma supr_apply {Ξ± : Type*} {Ξ² : Ξ± β†’ Type*} {ΞΉ : Sort*} [Ξ  i, has_Sup (Ξ² i)] {f : ΞΉ β†’ Ξ a, Ξ² a} {a : Ξ±} : (⨆i, f i) a = (⨆i, f i a) := @infi_apply Ξ± (Ξ» i, order_dual (Ξ² i)) _ _ f a section complete_lattice variables [preorder Ξ±] [complete_lattice Ξ²] theorem monotone_Sup_of_monotone {s : set (Ξ± β†’ Ξ²)} (m_s : βˆ€f∈s, monotone f) : monotone (Sup s) := assume x y h, supr_le $ Ξ» f, le_supr_of_le f $ m_s f f.2 h theorem monotone_Inf_of_monotone {s : set (Ξ± β†’ Ξ²)} (m_s : βˆ€f∈s, monotone f) : monotone (Inf s) := assume x y h, le_infi $ Ξ» f, infi_le_of_le f $ m_s f f.2 h end complete_lattice namespace prod variables (Ξ± Ξ²) instance [has_Inf Ξ±] [has_Inf Ξ²] : has_Inf (Ξ± Γ— Ξ²) := ⟨λs, (Inf (prod.fst '' s), Inf (prod.snd '' s))⟩ instance [has_Sup Ξ±] [has_Sup Ξ²] : has_Sup (Ξ± Γ— Ξ²) := ⟨λs, (Sup (prod.fst '' s), Sup (prod.snd '' s))⟩ instance [complete_lattice Ξ±] [complete_lattice Ξ²] : complete_lattice (Ξ± Γ— Ξ²) := { le_Sup := assume s p hab, ⟨le_Sup $ mem_image_of_mem _ hab, le_Sup $ mem_image_of_mem _ hab⟩, Sup_le := assume s p h, ⟨ Sup_le $ ball_image_of_ball $ assume p hp, (h p hp).1, Sup_le $ ball_image_of_ball $ assume p hp, (h p hp).2⟩, Inf_le := assume s p hab, ⟨Inf_le $ mem_image_of_mem _ hab, Inf_le $ mem_image_of_mem _ hab⟩, le_Inf := assume s p h, ⟨ le_Inf $ ball_image_of_ball $ assume p hp, (h p hp).1, le_Inf $ ball_image_of_ball $ assume p hp, (h p hp).2⟩, .. prod.bounded_lattice Ξ± Ξ², .. prod.has_Sup Ξ± Ξ², .. prod.has_Inf Ξ± Ξ² } end prod section complete_lattice variables [complete_lattice Ξ±] {a : Ξ±} {s : set Ξ±} /-- This is a weaker version of `sup_Inf_eq` -/ lemma sup_Inf_le_infi_sup : a βŠ” Inf s ≀ (β¨… b ∈ s, a βŠ” b) := le_infi $ assume i, le_infi $ assume h, sup_le_sup_left (Inf_le h) _ /-- This is a weaker version of `Inf_sup_eq` -/ lemma Inf_sup_le_infi_sup : Inf s βŠ” a ≀ (β¨… b ∈ s, b βŠ” a) := le_infi $ assume i, le_infi $ assume h, sup_le_sup_right (Inf_le h) _ /-- This is a weaker version of `inf_Sup_eq` -/ lemma supr_inf_le_inf_Sup : (⨆ b ∈ s, a βŠ“ b) ≀ a βŠ“ Sup s := supr_le $ assume i, supr_le $ assume h, inf_le_inf_left _ (le_Sup h) /-- This is a weaker version of `Sup_inf_eq` -/ lemma supr_inf_le_Sup_inf : (⨆ b ∈ s, b βŠ“ a) ≀ Sup s βŠ“ a := supr_le $ assume i, supr_le $ assume h, inf_le_inf_right _ (le_Sup h) lemma disjoint_Sup_left {a : set Ξ±} {b : Ξ±} (d : disjoint (Sup a) b) {i} (hi : i ∈ a) : disjoint i b := (supr_le_iff.mp (supr_le_iff.mp (supr_inf_le_Sup_inf.trans (d : _)) i : _) hi : _) lemma disjoint_Sup_right {a : set Ξ±} {b : Ξ±} (d : disjoint b (Sup a)) {i} (hi : i ∈ a) : disjoint b i := (supr_le_iff.mp (supr_le_iff.mp (supr_inf_le_inf_Sup.trans (d : _)) i : _) hi : _) end complete_lattice namespace complete_lattice variables [complete_lattice Ξ±] /-- An independent set of elements in a complete lattice is one in which every element is disjoint from the `Sup` of the rest. -/ def set_independent (s : set Ξ±) : Prop := βˆ€ ⦃a⦄, a ∈ s β†’ disjoint a (Sup (s \ {a})) variables {s : set Ξ±} (hs : set_independent s) @[simp] lemma set_independent_empty : set_independent (βˆ… : set Ξ±) := Ξ» x hx, (set.not_mem_empty x hx).elim theorem set_independent.mono {t : set Ξ±} (hst : t βŠ† s) : set_independent t := Ξ» a ha, (hs (hst ha)).mono_right (Sup_le_Sup (diff_subset_diff_left hst)) /-- If the elements of a set are independent, then any pair within that set is disjoint. -/ lemma set_independent.disjoint {x y : Ξ±} (hx : x ∈ s) (hy : y ∈ s) (h : x β‰  y) : disjoint x y := disjoint_Sup_right (hs hx) ((mem_diff y).mpr ⟨hy, by simp [h.symm]⟩) include hs /-- If the elements of a set are independent, then any element is disjoint from the `Sup` of some subset of the rest. -/ lemma set_independent.disjoint_Sup {x : Ξ±} {y : set Ξ±} (hx : x ∈ s) (hy : y βŠ† s) (hxy : x βˆ‰ y) : disjoint x (Sup y) := begin have := (hs.mono $ insert_subset.mpr ⟨hx, hy⟩) (mem_insert x _), rw [insert_diff_of_mem _ (mem_singleton _), diff_singleton_eq_self hxy] at this, exact this, end omit hs /-- An independent indexed family of elements in a complete lattice is one in which every element is disjoint from the `supr` of the rest. Example: an indexed family of non-zero elements in a vector space is linearly independent iff the indexed family of subspaces they generate is independent in this sense. Example: an indexed family of submodules of a module is independent in this sense if and only the natural map from the direct sum of the submodules to the module is injective. -/ def independent {ΞΉ : Sort*} {Ξ± : Type*} [complete_lattice Ξ±] (t : ΞΉ β†’ Ξ±) : Prop := βˆ€ i : ΞΉ, disjoint (t i) (⨆ (j β‰  i), t j) lemma set_independent_iff {Ξ± : Type*} [complete_lattice Ξ±] (s : set Ξ±) : set_independent s ↔ independent (coe : s β†’ Ξ±) := begin simp_rw [independent, set_independent, set_coe.forall, Sup_eq_supr], apply forall_congr, intro a, apply forall_congr, intro ha, congr' 2, convert supr_subtype.symm, simp [supr_and], end variables {t : ΞΉ β†’ Ξ±} (ht : independent t) theorem independent_def : independent t ↔ βˆ€ i : ΞΉ, disjoint (t i) (⨆ (j β‰  i), t j) := iff.rfl theorem independent_def' {ΞΉ : Type*} {t : ΞΉ β†’ Ξ±} : independent t ↔ βˆ€ i, disjoint (t i) (Sup (t '' {j | j β‰  i})) := by {simp_rw Sup_image, refl} theorem independent_def'' {ΞΉ : Type*} {t : ΞΉ β†’ Ξ±} : independent t ↔ βˆ€ i, disjoint (t i) (Sup {a | βˆƒ j β‰  i, t j = a}) := by {rw independent_def', tidy} @[simp] lemma independent_empty (t : empty β†’ Ξ±) : independent t. @[simp] lemma independent_pempty (t : pempty β†’ Ξ±) : independent t. /-- If the elements of a set are independent, then any pair within that set is disjoint. -/ lemma independent.disjoint {x y : ΞΉ} (h : x β‰  y) : disjoint (t x) (t y) := disjoint_Sup_right (ht x) ⟨y, by simp [h.symm]⟩ lemma independent.mono {ΞΉ : Type*} {Ξ± : Type*} [complete_lattice Ξ±] {s t : ΞΉ β†’ Ξ±} (hs : independent s) (hst : t ≀ s) : independent t := Ξ» i, (hs i).mono (hst i) (supr_le_supr $ Ξ» j, supr_le_supr $ Ξ» _, hst j) /-- Composing an indepedent indexed family with an injective function on the index results in another indepedendent indexed family. -/ lemma independent.comp {ΞΉ ΞΉ' : Sort*} {Ξ± : Type*} [complete_lattice Ξ±] {s : ΞΉ β†’ Ξ±} (hs : independent s) (f : ΞΉ' β†’ ΞΉ) (hf : function.injective f) : independent (s ∘ f) := Ξ» i, (hs (f i)).mono_right begin refine (supr_le_supr $ Ξ» i, _).trans (supr_comp_le _ f), exact supr_le_supr_const hf.ne, end /-- If the elements of a set are independent, then any element is disjoint from the `supr` of some subset of the rest. -/ lemma independent.disjoint_bsupr {ΞΉ : Type*} {Ξ± : Type*} [complete_lattice Ξ±] {t : ΞΉ β†’ Ξ±} (ht : independent t) {x : ΞΉ} {y : set ΞΉ} (hx : x βˆ‰ y) : disjoint (t x) (⨆ i ∈ y, t i) := disjoint.mono_right (bsupr_le_bsupr' $ Ξ» i hi, (ne_of_mem_of_not_mem hi hx : _)) (ht x) end complete_lattice
2094d25e06c43dca0d814c0e728ba8940862880b
9b9a16fa2cb737daee6b2785474678b6fa91d6d4
/test/solve_by_elim.lean
b1774fd66018fd8247820e45690aac967197f743
[ "Apache-2.0" ]
permissive
johoelzl/mathlib
253f46daa30b644d011e8e119025b01ad69735c4
592e3c7a2dfbd5826919b4605559d35d4d75938f
refs/heads/master
1,625,657,216,488
1,551,374,946,000
1,551,374,946,000
98,915,829
0
0
Apache-2.0
1,522,917,267,000
1,501,524,499,000
Lean
UTF-8
Lean
false
false
2,348
lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Scott Morrison -/ import tactic data.set.lattice data.prod data.vector tactic.rewrite data.stream.basic example {a b : Prop} (hβ‚€ : a β†’ b) (h₁ : a) : b := begin apply_assumption, apply_assumption, end example {a b : Prop} (hβ‚€ : a β†’ b) (h₁ : a) : b := by solve_by_elim example {Ξ± : Type} {a b : Ξ± β†’ Prop} (hβ‚€ : βˆ€ x : Ξ±, b x = a x) (y : Ξ±) : a y = b y := by solve_by_elim example {Ξ± : Type} {a b : Ξ± β†’ Prop} (hβ‚€ : b = a) (y : Ξ±) : a y = b y := by solve_by_elim example {Ξ± : Type} {a b : Ξ± β†’ Prop} (hβ‚€ : b = a) (y : Ξ±) : a y = b y := begin success_if_fail { solve_by_elim only [] }, success_if_fail { solve_by_elim only [hβ‚€] }, solve_by_elim only [hβ‚€, congr_fun] end example {Ξ± : Type} {a b : Ξ± β†’ Prop} (hβ‚€ : b = a) (y : Ξ±) : a y = b y := by solve_by_elim [hβ‚€] example {Ξ± : Type} {a b : Ξ± β†’ Prop} (hβ‚€ : b = a) (y : Ξ±) : a y = b y := begin success_if_fail { solve_by_elim [*, -hβ‚€] }, solve_by_elim [*] end example {Ξ± Ξ² : Type} (a b : Ξ±) (f : Ξ± β†’ Ξ²) (i : function.injective f) (h : f a = f b) : a = b := begin success_if_fail { solve_by_elim only [i] }, success_if_fail { solve_by_elim only [h] }, solve_by_elim only [i,h] end @[user_attribute] meta def ex : user_attribute := { name := `ex, descr := "An example attribute for testing solve_by_elim." } @[ex] def f : β„• := 0 example : β„• := by solve_by_elim [f] example : β„• := begin success_if_fail { solve_by_elim }, success_if_fail { solve_by_elim [-f] with ex }, solve_by_elim with ex, end example {Ξ± : Type} {p : Ξ± β†’ Prop} (hβ‚€ : βˆ€ x, p x) (y : Ξ±) : p y := begin apply_assumption, end open tactic example : true := begin (do gs ← get_goals, set_goals [], success_if_fail `[solve_by_elim], set_goals gs), trivial end example {Ξ± : Type} (r : Ξ± β†’ Ξ± β†’ Prop) (f : Ξ± β†’ Ξ± β†’ Ξ±) (l : βˆ€ a b c : Ξ±, r a b β†’ r a (f b c) β†’ r a c) (a b c : Ξ±) (h₁ : r a b) (hβ‚‚ : r a (f b c)) : r a c := begin solve_by_elim, end -- Verifying that solve_by_elim behaves as expected in the presence of multiple goals. example (n : β„•) : β„• Γ— β„• := begin split, solve_by_elim, solve_by_elim end
a4593162dec51108b19ed0780ffac7624a82efcf
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/stage0/src/Lean/Server/Rpc/Deriving.lean
4c7c0d0abc8fd19207d51309dc3ddff04bddc161
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
EdAyers/lean4
57ac632d6b0789cb91fab2170e8c9e40441221bd
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
refs/heads/master
1,676,463,245,298
1,660,619,433,000
1,660,619,433,000
183,433,437
1
0
Apache-2.0
1,657,612,672,000
1,556,196,574,000
Lean
UTF-8
Lean
false
false
5,710
lean
/- Copyright (c) 2021 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Wojciech Nawrocki -/ import Lean.Elab.Command import Lean.Elab.Term import Lean.Elab.Deriving.Basic import Lean.Elab.Deriving.Util import Lean.Server.Rpc.Basic namespace Lean.Server.RpcEncodable open Meta Elab Command Term def isOptField (n : Name) : Bool := n.toString.endsWith "?" open Parser.Term private def deriveStructureInstance (indVal : InductiveVal) (params : Array Expr) (encInstBinders : Array (TSyntax ``bracketedBinder)) : TermElabM Command := do let fields := getStructureFieldsFlattened (← getEnv) indVal.name (includeSubobjectFields := false) trace[Elab.Deriving.RpcEncodable] "for structure {indVal.name} with params {params}" let mut fieldIds := #[] let mut fieldTys := #[] let mut encInits := #[] let mut decInits := #[] for fieldName in fields do let fid := mkIdent fieldName fieldIds := fieldIds.push fid if isOptField fieldName then fieldTys := fieldTys.push (← `(Option Json)) encInits := encInits.push (← `(structInstField| $fid:ident := ← (a.$fid).mapM rpcEncode)) decInits := decInits.push (← `(structInstField| $fid:ident := ← (a.$fid).mapM rpcDecode)) else fieldTys := fieldTys.push (← `(Json)) encInits := encInits.push (← `(structInstField| $fid:ident := ← rpcEncode a.$fid)) decInits := decInits.push (← `(structInstField| $fid:ident := ← rpcDecode a.$fid)) let paramIds ← params.mapM fun p => return mkIdent (← getFVarLocalDecl p).userName `(structure RpcEncodablePacket where $[($fieldIds : $fieldTys)]* deriving FromJson, ToJson variable $encInstBinders* in instance : RpcEncodable (@$(mkCIdent indVal.name) $paramIds*) := { rpcEncode := enc, rpcDecode := dec } where -- prevent inlining enc a := return toJson { $[$encInits],* : RpcEncodablePacket } dec j := do let a : RpcEncodablePacket ← fromJson? j return { $[$decInits],* } ) private def matchAltTerm := Lean.Parser.Term.matchAlt (rhsParser := Lean.Parser.termParser) instance : Coe (TSyntax ``matchAltTerm) (TSyntax ``Parser.Term.matchAlt) where coe s := ⟨s⟩ private def deriveInductiveInstance (indVal : InductiveVal) (params : Array Expr) (encInstBinders : Array (TSyntax ``bracketedBinder)) : TermElabM Command := do trace[Elab.Deriving.RpcEncodable] "for inductive {indVal.name} with params {params}" let st ← indVal.ctors.toArray.mapM fun ctorName => do let ctorTy ← instantiateForall (← getConstInfoCtor ctorName).type params forallTelescopeReducing ctorTy fun argVars _ => do let .str _ ctor := ctorName | throwError m!"constructor name not a string: {ctorName}" let ctorId := mkIdent ctor -- create the constructor let fieldStxs ← argVars.mapM fun arg => do let name := (← getFVarLocalDecl arg).userName `(bracketedBinder| ($(mkIdent name) : Json)) let pktCtor ← `(Parser.Command.ctor| | $ctorId:ident $[$fieldStxs]* : RpcEncodablePacket) -- create encoder and decoder match arms let nms ← argVars.mapM fun _ => mkIdent <$> mkFreshBinderName let encArgs ← nms.mapM fun nm => `(← rpcEncode $nm) let encArm ← `(matchAltTerm| | .$ctorId $nms* => return toJson (.$ctorId $encArgs* : RpcEncodablePacket)) let decArgs ← nms.mapM fun nm => `(← rpcDecode $nm) let decArm ← `(matchAltTerm| | .$ctorId $nms* => return (.$ctorId $decArgs*)) return (pktCtor, encArm, decArm) let (ctors, st) := st.unzip let (encodes, decodes) := st.unzip -- helpers for type name syntax let paramIds ← params.mapM fun p => return mkIdent (← getFVarLocalDecl p).userName let typeId ← `(@$(mkIdent indVal.name) $paramIds*) `(inductive RpcEncodablePacket where $[$ctors:ctor]* deriving FromJson, ToJson variable $encInstBinders* in partial instance : RpcEncodable $typeId := { rpcEncode := enc, rpcDecode := dec } where enc x := have inst : RpcEncodable $typeId := { rpcEncode := enc, rpcDecode := dec } match x with $[$encodes:matchAlt]* dec j := do have inst : RpcEncodable $typeId := { rpcEncode := enc, rpcDecode := dec } let pkt : RpcEncodablePacket ← fromJson? j id <| match pkt with $[$decodes:matchAlt]* ) /-- Creates an `RpcEncodablePacket` for `typeName`. For structures, the packet is a structure with the same field names. For inductives, it mirrors the inductive structure with every field of every ctor replaced by `Json`. Then `RpcEncodable typeName` is instantiated using the `RpcEncodablePacket`. -/ private def deriveInstance (declNames : Array Name) : CommandElabM Bool := do let #[typeName] := declNames | return false let indVal ← getConstInfoInduct typeName if indVal.all.length β‰  1 then throwError "mutually inductive types are not supported" if indVal.numIndices β‰  0 then throwError "indexed inductive families are not supported" elabCommand <| ← liftTermElabM do forallTelescopeReducing indVal.type fun params _ => do let encInstBinders ← (← params.filterM (isType Β·)).mapM fun p => do `(bracketedBinder| [RpcEncodable $(mkIdent (← getFVarLocalDecl p).userName):ident]) if isStructure (← getEnv) typeName then deriveStructureInstance indVal params encInstBinders else deriveInductiveInstance indVal params encInstBinders return true initialize registerDerivingHandler ``RpcEncodable deriveInstance registerTraceClass `Elab.Deriving.RpcEncodable end Lean.Server.RpcEncodable
57a920e8d27c07f96b6ae528c54eda774166993f
2a70b774d16dbdf5a533432ee0ebab6838df0948
/_target/deps/mathlib/src/data/real/cardinality.lean
eca413c7e62fbca70fe4e4bf601d8ae5983604a8
[ "Apache-2.0" ]
permissive
hjvromen/lewis
40b035973df7c77ebf927afab7878c76d05ff758
105b675f73630f028ad5d890897a51b3c1146fb0
refs/heads/master
1,677,944,636,343
1,676,555,301,000
1,676,555,301,000
327,553,599
0
0
null
null
null
null
UTF-8
Lean
false
false
9,412
lean
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import set_theory.cardinal_ordinal import analysis.specific_limits import data.rat.denumerable import data.set.intervals.image_preimage /-! # The cardinality of the reals This file shows that the real numbers have cardinality continuum, i.e. `#ℝ = 2^Ο‰`. We shows that `#ℝ ≀ 2^Ο‰` by noting that every real number is determined by a Cauchy-sequence of the form `β„• β†’ β„š`, which has cardinality `2^Ο‰`. To show that `#ℝ β‰₯ 2^Ο‰` we define an injection from `{0, 1} ^ β„•` to `ℝ` with `f ↦ Ξ£ n, f n * (1 / 3) ^ n`. We conclude that all intervals with distinct endpoints have cardinality continuum. ## Main definitions * `cardinal.cantor_function` is the function that sends `f` in `{0, 1} ^ β„•` to `ℝ` by `f ↦ Ξ£' n, f n * (1 / 3) ^ n` ## Main statements * `cardinal.mk_real : #ℝ = 2 ^ omega`: the reals have cardinality continuum. * `cardinal.not_countable_real`: the universal set of real numbers is not countable. We can use this same proof to show that all the other sets in this file are not countable. * 8 lemmas of the form `mk_Ixy_real` for `x,y ∈ {i,o,c}` state that intervals on the reals have cardinality continuum. ## Tags continuum, cardinality, reals, cardinality of the reals -/ open nat set open_locale cardinal noncomputable theory namespace cardinal variables {c : ℝ} {f g : β„• β†’ bool} {n : β„•} /-- The body of the sum in `cantor_function`. `cantor_function_aux c f n = c ^ n` if `f n = tt`; `cantor_function_aux c f n = 0` if `f n = ff`. -/ def cantor_function_aux (c : ℝ) (f : β„• β†’ bool) (n : β„•) : ℝ := cond (f n) (c ^ n) 0 @[simp] lemma cantor_function_aux_tt (h : f n = tt) : cantor_function_aux c f n = c ^ n := by simp [cantor_function_aux, h] @[simp] lemma cantor_function_aux_ff (h : f n = ff) : cantor_function_aux c f n = 0 := by simp [cantor_function_aux, h] lemma cantor_function_aux_nonneg (h : 0 ≀ c) : 0 ≀ cantor_function_aux c f n := by { cases h' : f n; simp [h'], apply pow_nonneg h } lemma cantor_function_aux_eq (h : f n = g n) : cantor_function_aux c f n = cantor_function_aux c g n := by simp [cantor_function_aux, h] lemma cantor_function_aux_succ (f : β„• β†’ bool) : (Ξ» n, cantor_function_aux c f (n + 1)) = Ξ» n, c * cantor_function_aux c (Ξ» n, f (n + 1)) n := by { ext n, cases h : f (n + 1); simp [h, pow_succ] } lemma summable_cantor_function (f : β„• β†’ bool) (h1 : 0 ≀ c) (h2 : c < 1) : summable (cantor_function_aux c f) := begin apply (summable_geometric_of_lt_1 h1 h2).summable_of_eq_zero_or_self, intro n, cases h : f n; simp [h] end /-- `cantor_function c (f : β„• β†’ bool)` is `Ξ£ n, f n * c ^ n`, where `tt` is interpreted as `1` and `ff` is interpreted as `0`. It is implemented using `cantor_function_aux`. -/ def cantor_function (c : ℝ) (f : β„• β†’ bool) : ℝ := βˆ‘' n, cantor_function_aux c f n lemma cantor_function_le (h1 : 0 ≀ c) (h2 : c < 1) (h3 : βˆ€ n, f n β†’ g n) : cantor_function c f ≀ cantor_function c g := begin apply tsum_le_tsum _ (summable_cantor_function f h1 h2) (summable_cantor_function g h1 h2), intro n, cases h : f n, simp [h, cantor_function_aux_nonneg h1], replace h3 : g n = tt := h3 n h, simp [h, h3] end lemma cantor_function_succ (f : β„• β†’ bool) (h1 : 0 ≀ c) (h2 : c < 1) : cantor_function c f = cond (f 0) 1 0 + c * cantor_function c (Ξ» n, f (n+1)) := begin rw [cantor_function, tsum_eq_zero_add (summable_cantor_function f h1 h2)], rw [cantor_function_aux_succ, tsum_mul_left], refl end /-- `cantor_function c` is strictly increasing with if `0 < c < 1/2`, if we endow `β„• β†’ bool` with a lexicographic order. The lexicographic order doesn't exist for these infinitary products, so we explicitly write out what it means. -/ lemma increasing_cantor_function (h1 : 0 < c) (h2 : c < 1 / 2) {n : β„•} {f g : β„• β†’ bool} (hn : βˆ€(k < n), f k = g k) (fn : f n = ff) (gn : g n = tt) : cantor_function c f < cantor_function c g := begin have h3 : c < 1, { apply h2.trans, norm_num }, induction n with n ih generalizing f g, { let f_max : β„• β†’ bool := Ξ» n, nat.rec ff (Ξ» _ _, tt) n, have hf_max : βˆ€n, f n β†’ f_max n, { intros n hn, cases n, rw [fn] at hn, contradiction, apply rfl }, let g_min : β„• β†’ bool := Ξ» n, nat.rec tt (Ξ» _ _, ff) n, have hg_min : βˆ€n, g_min n β†’ g n, { intros n hn, cases n, rw [gn], apply rfl, contradiction }, apply (cantor_function_le (le_of_lt h1) h3 hf_max).trans_lt, refine lt_of_lt_of_le _ (cantor_function_le (le_of_lt h1) h3 hg_min), have : c / (1 - c) < 1, { rw [div_lt_one, lt_sub_iff_add_lt], { convert add_lt_add h2 h2, norm_num }, rwa sub_pos }, convert this, { rw [cantor_function_succ _ (le_of_lt h1) h3, div_eq_mul_inv, ←tsum_geometric_of_lt_1 (le_of_lt h1) h3], apply zero_add }, { apply tsum_eq_single 0, intros n hn, cases n, contradiction, refl, apply_instance }}, rw [cantor_function_succ f (le_of_lt h1) h3, cantor_function_succ g (le_of_lt h1) h3], rw [hn 0 $ zero_lt_succ n], apply add_lt_add_left, rw mul_lt_mul_left h1, exact ih (Ξ» k hk, hn _ $ succ_lt_succ hk) fn gn end /-- `cantor_function c` is injective if `0 < c < 1/2`. -/ lemma cantor_function_injective (h1 : 0 < c) (h2 : c < 1 / 2) : function.injective (cantor_function c) := begin intros f g hfg, classical, by_contra h, revert hfg, have : βˆƒn, f n β‰  g n, { rw [←not_forall], intro h', apply h, ext, apply h' }, let n := nat.find this, have hn : βˆ€ (k : β„•), k < n β†’ f k = g k, { intros k hk, apply of_not_not, exact nat.find_min this hk }, cases fn : f n, { apply ne_of_lt, refine increasing_cantor_function h1 h2 hn fn _, apply eq_tt_of_not_eq_ff, rw [←fn], apply ne.symm, exact nat.find_spec this }, { apply ne_of_gt, refine increasing_cantor_function h1 h2 (Ξ» k hk, (hn k hk).symm) _ fn, apply eq_ff_of_not_eq_tt, rw [←fn], apply ne.symm, exact nat.find_spec this } end /-- The cardinality of the reals, as a type. -/ lemma mk_real : #ℝ = 2 ^ omega.{0} := begin apply le_antisymm, { dsimp [real], apply le_trans mk_quotient_le, apply le_trans (mk_subtype_le _), rw [←power_def, mk_nat, mk_rat, power_self_eq (le_refl _)] }, { convert mk_le_of_injective (cantor_function_injective _ _), rw [←power_def, mk_bool, mk_nat], exact 1 / 3, norm_num, norm_num } end /-- The cardinality of the reals, as a set. -/ lemma mk_univ_real : #(set.univ : set ℝ) = 2 ^ omega.{0} := by rw [mk_univ, mk_real] /-- The reals are not countable. -/ lemma not_countable_real : Β¬ countable (set.univ : set ℝ) := by { rw [countable_iff, not_le, mk_univ_real], apply cantor } /-- The cardinality of the interval (a, ∞). -/ lemma mk_Ioi_real (a : ℝ) : #(Ioi a) = 2 ^ omega.{0} := begin refine le_antisymm (mk_real β–Έ mk_set_le _) _, rw [← not_lt], intro h, refine ne_of_lt _ mk_univ_real, have hu : Iio a βˆͺ {a} βˆͺ Ioi a = set.univ, { convert Iic_union_Ioi, exact Iio_union_right }, rw ← hu, refine lt_of_le_of_lt (mk_union_le _ _) _, refine lt_of_le_of_lt (add_le_add_right (mk_union_le _ _) _) _, have h2 : (Ξ» x, a + a - x) '' Ioi a = Iio a, { convert image_const_sub_Ioi _ _, simp }, rw ← h2, refine add_lt_of_lt (cantor _).le _ h, refine add_lt_of_lt (cantor _).le (mk_image_le.trans_lt h) _, rw mk_singleton, exact one_lt_omega.trans (cantor _) end /-- The cardinality of the interval [a, ∞). -/ lemma mk_Ici_real (a : ℝ) : #(Ici a) = 2 ^ omega.{0} := le_antisymm (mk_real β–Έ mk_set_le _) (mk_Ioi_real a β–Έ mk_le_mk_of_subset Ioi_subset_Ici_self) /-- The cardinality of the interval (-∞, a). -/ lemma mk_Iio_real (a : ℝ) : #(Iio a) = 2 ^ omega.{0} := begin refine le_antisymm (mk_real β–Έ mk_set_le _) _, have h2 : (Ξ» x, a + a - x) '' Iio a = Ioi a, { convert image_const_sub_Iio _ _, simp }, exact mk_Ioi_real a β–Έ h2 β–Έ mk_image_le end /-- The cardinality of the interval (-∞, a]. -/ lemma mk_Iic_real (a : ℝ) : #(Iic a) = 2 ^ omega.{0} := le_antisymm (mk_real β–Έ mk_set_le _) (mk_Iio_real a β–Έ mk_le_mk_of_subset Iio_subset_Iic_self) /-- The cardinality of the interval (a, b). -/ lemma mk_Ioo_real {a b : ℝ} (h : a < b) : #(Ioo a b) = 2 ^ omega.{0} := begin refine le_antisymm (mk_real β–Έ mk_set_le _) _, have h1 : #((Ξ» x, x - a) '' Ioo a b) ≀ #(Ioo a b) := mk_image_le, refine le_trans _ h1, rw [image_sub_const_Ioo, sub_self], replace h := sub_pos_of_lt h, have h2 : #(has_inv.inv '' Ioo 0 (b - a)) ≀ #(Ioo 0 (b - a)) := mk_image_le, refine le_trans _ h2, rw [image_inv_Ioo_0_left h, mk_Ioi_real] end /-- The cardinality of the interval [a, b). -/ lemma mk_Ico_real {a b : ℝ} (h : a < b) : #(Ico a b) = 2 ^ omega.{0} := le_antisymm (mk_real β–Έ mk_set_le _) (mk_Ioo_real h β–Έ mk_le_mk_of_subset Ioo_subset_Ico_self) /-- The cardinality of the interval [a, b]. -/ lemma mk_Icc_real {a b : ℝ} (h : a < b) : #(Icc a b) = 2 ^ omega.{0} := le_antisymm (mk_real β–Έ mk_set_le _) (mk_Ioo_real h β–Έ mk_le_mk_of_subset Ioo_subset_Icc_self) /-- The cardinality of the interval (a, b]. -/ lemma mk_Ioc_real {a b : ℝ} (h : a < b) : #(Ioc a b) = 2 ^ omega.{0} := le_antisymm (mk_real β–Έ mk_set_le _) (mk_Ioo_real h β–Έ mk_le_mk_of_subset Ioo_subset_Ioc_self) end cardinal
94a962ad07387400fbf3cd086a653daa926c5b05
ba4794a0deca1d2aaa68914cd285d77880907b5c
/src/my_solutions/world3_le.lean
db648322421583afcf563826448f4eb9600b3e18
[ "Apache-2.0" ]
permissive
ChrisHughes24/natural_number_game
c7c00aa1f6a95004286fd456ed13cf6e113159ce
9d09925424da9f6275e6cfe427c8bcf12bb0944f
refs/heads/master
1,600,715,773,528
1,573,910,462,000
1,573,910,462,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
4,764
lean
import solutions.world2_multiplication import mynat.le /- Here's what you get from the import: 1) The following data: * a binary relation called mynat.le, and notation a ≀ b for this relation. The definition is: a ≀ b ↔ βˆƒ c : mynat, b = a + c 2) The following axiom: * `le_def (a b : mynat) : a ≀ b ↔ βˆƒ (c : mynat), b = a + c` You can rewrite `le_def`. If a goal is of the form `βˆƒ c, ...` then to make progress you can use the `use` tactic. For example `use 7` will replace all c's in the goal with 7's. -/ namespace mynat #exit -- example theorem le_refl (a : mynat) : a ≀ a := begin [less_leaky] rw le_def, use 0, rw add_zero, refl, end example : one ≀ one := le_refl one -- ignore this; it's making the "refl" tactic work with goals of the form a ≀ a attribute [_refl_lemma] le_refl theorem le_succ {a b : mynat} (h : a ≀ b) : a ≀ (succ b) := begin [less_leaky] rw le_def at h, cases h with c hc, use succ(c), rw hc, rw add_succ, refl, end lemma zero_le (a : mynat) : 0 ≀ a := begin [less_leaky] rw le_def, use a, rw zero_add, refl, end -- advanced lemma le_zero {a : mynat} (h : a ≀ 0) : a = 0 := begin [less_leaky] cases h with c hc, -- this is in world 2 advanced, I don't know how to do it without -- using zero_ne_succ sorry, end theorem le_trans ⦃a b c : mynat⦄ (hab : a ≀ b) (hbc : b ≀ c) : a ≀ c := begin cases hab with d hd, cases hbc with e he, use d + e, rw he, rw hd, exact add_assoc a d e, end instance : preorder mynat := by structure_helper -- need a = a + x -> x = 0 which is proved using functions theorem le_antisymm {{a b : mynat}} (hab : a ≀ b) (hba : b ≀ a) : a = b := begin cases hab with d hd, cases hba with e he, rw hd at he, sorry, end instance : partial_order mynat := by structure_helper -- ignore this, it's the definition. theorem lt_iff_le_not_le {a b : mynat} : a < b ↔ a ≀ b ∧ Β¬ b ≀ a := iff.rfl -- functions everywhere theorem lt_iff_le_and_ne ⦃a b : mynat⦄ : a < b ↔ a ≀ b ∧ a β‰  b := begin sorry end -- beginner lemma succ_le_succ {a b : mynat} (h : a ≀ b) : succ a ≀ succ b := begin [less_leaky] cases h with c hc, use c, rw hc, rw succ_add, refl, end -- haven't introduced left/right tactic theorem le_total (a b : mynat) : a ≀ b ∨ b ≀ a := begin revert a, induction b with d hd, intro a, right, exact zero_le a, intro a, sorry, end instance : linear_order mynat := by structure_helper -- beginner theorem add_le_add_right (a b : mynat) (hab : a ≀ b) (t : mynat) : (a + t) ≀ (b + t) := begin cases hab with c hc, use c, rw hc, simp, end -- odd use of exact theorem le_succ_self (a : mynat) : a ≀ succ a := begin use 1, exact succ_eq_add_one a, end -- advanced theorem le_of_succ_le_succ {a b : mynat} : succ a ≀ succ b β†’ a ≀ b := begin intro h, cases h with d hd, use d, rw succ_add at hd, exact succ_inj(hd), end -- advanced theorem not_succ_le_self {{d : mynat}} (h : succ d ≀ d) : false := begin sorry end -- beginner theorem add_le_add_left (a b : mynat) (hab : a ≀ b) (c : mynat) : c + a ≀ c + b := begin cases hab with d hd, use d, rw hd, simp, end -- split def succ_le_succ_iff (a b : mynat) : succ a ≀ succ b ↔ a ≀ b := begin sorry end -- split and < def succ_lt_succ_iff (a b : mynat) : succ a < succ b ↔ a < b := begin sorry end theorem lt_of_add_lt_add_left : βˆ€ {{a b c : mynat}}, a + b < a + c β†’ b < c := begin sorry end theorem le_iff_exists_add : βˆ€ (a b : mynat), a ≀ b ↔ βˆƒ (c : mynat), b = a + c := begin sorry end theorem zero_ne_one : (0 : mynat) β‰  1 := begin sorry end instance : ordered_comm_monoid mynat := by structure_helper -- beginner -- just theorem le_of_add_le_add_left ⦃a b c : mynat⦄ (h : a + b ≀ a + c) : b ≀ c := begin cases h with d hd, use d, rw add_assoc at hd, exact add_left_cancel hd, -- add_left_cancel is 2-10 and needs succ_inj end instance : ordered_cancel_comm_monoid mynat := by structure_helper theorem mul_le_mul_of_nonneg_left ⦃a b c : mynat⦄ : a ≀ b β†’ 0 ≀ c β†’ c * a ≀ c * b := begin sorry end theorem mul_le_mul_of_nonneg_right ⦃a b c : mynat⦄ : a ≀ b β†’ 0 ≀ c β†’ a * c ≀ b * c := begin sorry end theorem ne_zero_of_pos ⦃a : mynat⦄ : 0 < a β†’ a β‰  0 := begin sorry end theorem mul_lt_mul_of_pos_left ⦃a b c : mynat⦄ : a < b β†’ 0 < c β†’ c * a < c * b := begin sorry end theorem mul_lt_mul_of_pos_right ⦃a b c : mynat⦄ : a < b β†’ 0 < c β†’ a * c < b * c := begin sorry end instance : ordered_semiring mynat := by structure_helper lemma lt_irrefl (a : mynat) : Β¬ (a < a) := begin sorry end end mynat
d4d47a5200f13bd316444842e8c15db54ebb3deb
d9d511f37a523cd7659d6f573f990e2a0af93c6f
/src/ring_theory/norm.lean
b5b7292473bcc74ccb30b4ed965a57b96c956e0a
[ "Apache-2.0" ]
permissive
hikari0108/mathlib
b7ea2b7350497ab1a0b87a09d093ecc025a50dfa
a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901
refs/heads/master
1,690,483,608,260
1,631,541,580,000
1,631,541,580,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
6,018
lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import linear_algebra.char_poly.coeff import linear_algebra.determinant import ring_theory.power_basis /-! # Norm for (finite) ring extensions Suppose we have an `R`-algebra `S` with a finite basis. For each `s : S`, the determinant of the linear map given by multiplying by `s` gives information about the roots of the minimal polynomial of `s` over `R`. ## Implementation notes Typically, the norm is defined specifically for finite field extensions. The current definition is as general as possible and the assumption that we have fields or that the extension is finite is added to the lemmas as needed. We only define the norm for left multiplication (`algebra.left_mul_matrix`, i.e. `algebra.lmul_left`). For now, the definitions assume `S` is commutative, so the choice doesn't matter anyway. See also `algebra.trace`, which is defined similarly as the trace of `algebra.left_mul_matrix`. ## References * https://en.wikipedia.org/wiki/Field_norm -/ universes u v w variables {R S T : Type*} [integral_domain R] [integral_domain S] [integral_domain T] variables [algebra R S] [algebra R T] variables {K L F : Type*} [field K] [field L] [field F] variables [algebra K L] [algebra L F] [algebra K F] variables {ΞΉ : Type w} [fintype ΞΉ] open finite_dimensional open linear_map open matrix open_locale big_operators open_locale matrix namespace algebra variables (R) /-- The norm of an element `s` of an `R`-algebra is the determinant of `(*) s`. -/ noncomputable def norm : S β†’* R := linear_map.det.comp (lmul R S).to_ring_hom.to_monoid_hom lemma norm_apply (x : S) : norm R x = linear_map.det (lmul R S x) := rfl lemma norm_eq_one_of_not_exists_basis (h : Β¬ βˆƒ (s : finset S), nonempty (basis s R S)) (x : S) : norm R x = 1 := by { rw [norm_apply, linear_map.det], split_ifs with h, refl } variables {R} -- Can't be a `simp` lemma because it depends on a choice of basis lemma norm_eq_matrix_det [decidable_eq ΞΉ] (b : basis ΞΉ R S) (s : S) : norm R s = matrix.det (algebra.left_mul_matrix b s) := by rw [norm_apply, ← linear_map.det_to_matrix b, to_matrix_lmul_eq] /-- If `x` is in the base field `K`, then the norm is `x ^ [L : K]`. -/ lemma norm_algebra_map_of_basis (b : basis ΞΉ R S) (x : R) : norm R (algebra_map R S x) = x ^ fintype.card ΞΉ := begin haveI := classical.dec_eq ΞΉ, rw [norm_apply, ← det_to_matrix b, lmul_algebra_map], convert @det_diagonal _ _ _ _ _ (Ξ» (i : ΞΉ), x), { ext i j, rw [to_matrix_lsmul, matrix.diagonal] }, { rw [finset.prod_const, finset.card_univ] } end /-- If `x` is in the base field `K`, then the norm is `x ^ [L : K]`. (If `L` is not finite-dimensional over `K`, then `norm = 1 = x ^ 0 = x ^ (finrank L K)`.) -/ @[simp] lemma norm_algebra_map (x : K) : norm K (algebra_map K L x) = x ^ finrank K L := begin by_cases H : βˆƒ (s : finset L), nonempty (basis s K L), { rw [norm_algebra_map_of_basis H.some_spec.some, finrank_eq_card_basis H.some_spec.some] }, { rw [norm_eq_one_of_not_exists_basis K H, finrank_eq_zero_of_not_exists_basis, pow_zero], rintros ⟨s, ⟨b⟩⟩, exact H ⟨s, ⟨b⟩⟩ }, end section eq_prod_roots lemma norm_gen_eq_prod_roots [algebra K S] (pb : power_basis K S) (hf : (minpoly K pb.gen).splits (algebra_map K F)) : algebra_map K F (norm K pb.gen) = ((minpoly K pb.gen).map (algebra_map K F)).roots.prod := begin -- Write the LHS as the 0'th coefficient of `minpoly K pb.gen` rw [norm_eq_matrix_det pb.basis, det_eq_sign_char_poly_coeff, char_poly_left_mul_matrix, ring_hom.map_mul, ring_hom.map_pow, ring_hom.map_neg, ring_hom.map_one, ← polynomial.coeff_map, fintype.card_fin], -- Rewrite `minpoly K pb.gen` as a product over the roots. conv_lhs { rw polynomial.eq_prod_roots_of_splits hf }, rw [polynomial.coeff_C_mul, polynomial.coeff_zero_multiset_prod, multiset.map_map, (minpoly.monic pb.is_integral_gen).leading_coeff, ring_hom.map_one, one_mul], -- Incorporate the `-1` from the `char_poly` back into the product. rw [← multiset.prod_repeat (-1 : F), ← pb.nat_degree_minpoly, polynomial.nat_degree_eq_card_roots hf, ← multiset.map_const, ← multiset.prod_map_mul], -- And conclude that both sides are the same. congr, convert multiset.map_id _, ext f, simp end end eq_prod_roots section eq_zero_iff lemma norm_eq_zero_iff_of_basis (b : basis ΞΉ R S) {x : S} : algebra.norm R x = 0 ↔ x = 0 := begin have hΞΉ : nonempty ΞΉ := b.index_nonempty, letI := classical.dec_eq ΞΉ, rw algebra.norm_eq_matrix_det b, split, { rw ← matrix.exists_mul_vec_eq_zero_iff, rintros ⟨v, v_ne, hv⟩, rw [← b.equiv_fun.apply_symm_apply v, b.equiv_fun_symm_apply, b.equiv_fun_apply, algebra.left_mul_matrix_mul_vec_repr] at hv, refine (mul_eq_zero.mp (b.ext_elem $ Ξ» i, _)).resolve_right (show βˆ‘ i, v i β€’ b i β‰  0, from _), { simpa only [linear_equiv.map_zero, pi.zero_apply] using congr_fun hv i }, { contrapose! v_ne with sum_eq, apply b.equiv_fun.symm.injective, rw [b.equiv_fun_symm_apply, sum_eq, linear_equiv.map_zero] } }, { rintro rfl, rw [alg_hom.map_zero, matrix.det_zero hΞΉ] }, end lemma norm_ne_zero_iff_of_basis (b : basis ΞΉ R S) {x : S} : algebra.norm R x β‰  0 ↔ x β‰  0 := not_iff_not.mpr (algebra.norm_eq_zero_iff_of_basis b) /-- See also `algebra.norm_eq_zero_iff'` if you already have rewritten with `algebra.norm_apply`. -/ @[simp] lemma norm_eq_zero_iff [finite_dimensional K L] {x : L} : algebra.norm K x = 0 ↔ x = 0 := algebra.norm_eq_zero_iff_of_basis (basis.of_vector_space K L) /-- This is `algebra.norm_eq_zero_iff` composed with `algebra.norm_apply`. -/ @[simp] lemma norm_eq_zero_iff' [finite_dimensional K L] {x : L} : linear_map.det (algebra.lmul K L x) = 0 ↔ x = 0 := algebra.norm_eq_zero_iff_of_basis (basis.of_vector_space K L) end eq_zero_iff end algebra
5c830dc81fe4e198f187f643960fe9374a6873af
f3a5af2927397cf346ec0e24312bfff077f00425
/src/game/world2/level3.lean
b1c37d4ae95d31b91a3fda59c90dd6f0951d674d
[ "Apache-2.0" ]
permissive
ImperialCollegeLondon/natural_number_game
05c39e1586408cfb563d1a12e1085a90726ab655
f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd
refs/heads/master
1,688,570,964,990
1,636,908,242,000
1,636,908,242,000
195,403,790
277
84
Apache-2.0
1,694,547,955,000
1,562,328,792,000
Lean
UTF-8
Lean
false
false
1,390
lean
import mynat.definition -- hide import mynat.add -- hide import game.world2.level2 -- hide namespace mynat -- hide /- # Addition World ## Level 3: `succ_add` Oh no! On the way to `add_comm`, a wild `succ_add` appears. `succ_add` is the proof that `succ(a) + b = succ(a + b)` for `a` and `b` in your natural number type. We need to prove this now, because we will need to use this result in our proof that `a + b = b + a` in the next level. NB: think about why computer scientists called this result `succ_add` . There is a logic to all the names. Note that if you want to be more precise about exactly where you want to rewrite something like `add_succ` (the proof you already have), you can do things like `rw add_succ (succ a)` or `rw add_succ (succ a) d`, telling Lean explicitly what to use for the input variables for the function `add_succ`. Indeed, `add_succ` is a function -- it takes as input two variables `a` and `b` and outputs a proof that `a + succ(b) = succ(a + b)`. The tactic `rw add_succ` just says to Lean "guess what the variables are". -/ /- Lemma For all natural numbers $a, b$, we have $$ \operatorname{succ}(a) + b = \operatorname{succ}(a + b). $$ -/ lemma succ_add (a b : mynat) : succ a + b = succ (a + b) := begin [nat_num_game] induction b with d hd, { refl }, { rw add_succ, rw hd, rw add_succ, refl } end end mynat -- hide
aa4e2672f3d82f08993cbc9c0495d4b491221808
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
/src/topology/list.lean
04ceebda3bf08793c85f2c32371a4fbee70fb106
[ "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
8,395
lean
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl Topology on lists and vectors. -/ import topology.constructions open topological_space set filter open_locale topological_space variables {Ξ± : Type*} {Ξ² : Type*} instance [topological_space Ξ±] : topological_space (list Ξ±) := topological_space.mk_of_nhds (traverse nhds) lemma nhds_list [topological_space Ξ±] (as : list Ξ±) : 𝓝 as = traverse 𝓝 as := begin refine nhds_mk_of_nhds _ _ _ _, { assume l, induction l, case list.nil { exact le_refl _ }, case list.cons : a l ih { suffices : list.cons <$> pure a <*> pure l ≀ list.cons <$> 𝓝 a <*> traverse 𝓝 l, { simpa only [] with functor_norm using this }, exact filter.seq_mono (filter.map_mono $ pure_le_nhds a) ih } }, { assume l s hs, rcases (mem_traverse_sets_iff _ _).1 hs with ⟨u, hu, hus⟩, clear as hs, have : βˆƒv:list (set Ξ±), l.forallβ‚‚ (Ξ»a s, is_open s ∧ a ∈ s) v ∧ sequence v βŠ† s, { induction hu generalizing s, case list.forallβ‚‚.nil : hs this { existsi [], simpa only [list.forallβ‚‚_nil_left_iff, exists_eq_left] }, case list.forallβ‚‚.cons : a s as ss ht h ih t hts { rcases mem_nhds_sets_iff.1 ht with ⟨u, hut, hu⟩, rcases ih (subset.refl _) with ⟨v, hv, hvss⟩, exact ⟨u::v, list.forallβ‚‚.cons hu hv, subset.trans (set.seq_mono (set.image_subset _ hut) hvss) hts⟩ } }, rcases this with ⟨v, hv, hvs⟩, refine ⟨sequence v, mem_traverse_sets _ _ _, hvs, _⟩, { exact hv.imp (assume a s ⟨hs, ha⟩, mem_nhds_sets hs ha) }, { assume u hu, have hu := (list.mem_traverse _ _).1 hu, have : list.forallβ‚‚ (Ξ»a s, is_open s ∧ a ∈ s) u v, { refine list.forallβ‚‚.flip _, replace hv := hv.flip, simp only [list.forallβ‚‚_and_left, flip] at ⊒ hv, exact ⟨hv.1, hu.flip⟩ }, refine mem_sets_of_superset _ hvs, exact mem_traverse_sets _ _ (this.imp $ assume a s ⟨hs, ha⟩, mem_nhds_sets hs ha) } } end lemma nhds_nil [topological_space Ξ±] : 𝓝 ([] : list Ξ±) = pure [] := by rw [nhds_list, list.traverse_nil _]; apply_instance lemma nhds_cons [topological_space Ξ±] (a : Ξ±) (l : list Ξ±) : 𝓝 (a :: l) = list.cons <$> 𝓝 a <*> 𝓝 l := by rw [nhds_list, list.traverse_cons _, ← nhds_list]; apply_instance namespace list variables [topological_space Ξ±] [topological_space Ξ²] lemma tendsto_cons' {a : Ξ±} {l : list Ξ±} : tendsto (Ξ»p:Ξ±Γ—list Ξ±, list.cons p.1 p.2) ((𝓝 a).prod (𝓝 l)) (𝓝 (a :: l)) := by rw [nhds_cons, tendsto, map_prod]; exact le_refl _ lemma tendsto_cons {Ξ± : Type*} {f : Ξ± β†’ Ξ²} {g : Ξ± β†’ list Ξ²} {a : _root_.filter Ξ±} {b : Ξ²} {l : list Ξ²} (hf : tendsto f a (𝓝 b)) (hg : tendsto g a (𝓝 l)) : tendsto (Ξ»a, list.cons (f a) (g a)) a (𝓝 (b :: l)) := tendsto_cons'.comp (tendsto.prod_mk hf hg) lemma tendsto_cons_iff {Ξ² : Type*} {f : list Ξ± β†’ Ξ²} {b : _root_.filter Ξ²} {a : Ξ±} {l : list Ξ±} : tendsto f (𝓝 (a :: l)) b ↔ tendsto (Ξ»p:Ξ±Γ—list Ξ±, f (p.1 :: p.2)) ((𝓝 a).prod (𝓝 l)) b := have 𝓝 (a :: l) = ((𝓝 a).prod (𝓝 l)).map (Ξ»p:Ξ±Γ—list Ξ±, (p.1 :: p.2)), begin simp only [nhds_cons, filter.prod_eq, (filter.map_def _ _).symm, (filter.seq_eq_filter_seq _ _).symm], simp [-filter.seq_eq_filter_seq, -filter.map_def, (∘)] with functor_norm, end, by rw [this, filter.tendsto_map'_iff] lemma tendsto_nhds {Ξ² : Type*} {f : list Ξ± β†’ Ξ²} {r : list Ξ± β†’ _root_.filter Ξ²} (h_nil : tendsto f (pure []) (r [])) (h_cons : βˆ€l a, tendsto f (𝓝 l) (r l) β†’ tendsto (Ξ»p:Ξ±Γ—list Ξ±, f (p.1 :: p.2)) ((𝓝 a).prod (𝓝 l)) (r (a::l))) : βˆ€l, tendsto f (𝓝 l) (r l) | [] := by rwa [nhds_nil] | (a::l) := by rw [tendsto_cons_iff]; exact h_cons l a (tendsto_nhds l) lemma continuous_at_length : βˆ€(l : list Ξ±), continuous_at list.length l := begin simp only [continuous_at, nhds_discrete], refine tendsto_nhds _ _, { exact tendsto_pure_pure _ _ }, { assume l a ih, dsimp only [list.length], refine tendsto.comp (tendsto_pure_pure (Ξ»x, x + 1) _) _, refine tendsto.comp ih tendsto_snd } end lemma tendsto_insert_nth' {a : Ξ±} : βˆ€{n : β„•} {l : list Ξ±}, tendsto (Ξ»p:Ξ±Γ—list Ξ±, insert_nth n p.1 p.2) ((𝓝 a).prod (𝓝 l)) (𝓝 (insert_nth n a l)) | 0 l := tendsto_cons' | (n+1) [] := suffices tendsto (Ξ»a, []) (𝓝 a) (𝓝 ([] : list Ξ±)), by simpa [nhds_nil, tendsto, map_prod, (∘), insert_nth], tendsto_const_nhds | (n+1) (a'::l) := have (𝓝 a).prod (𝓝 (a' :: l)) = ((𝓝 a).prod ((𝓝 a').prod (𝓝 l))).map (Ξ»p:Ξ±Γ—Ξ±Γ—list Ξ±, (p.1, p.2.1 :: p.2.2)), begin simp only [nhds_cons, filter.prod_eq, (filter.map_def _ _).symm, (filter.seq_eq_filter_seq _ _).symm], simp [-filter.seq_eq_filter_seq, -filter.map_def, (∘)] with functor_norm end, begin rw [this, tendsto_map'_iff], exact tendsto_cons (tendsto_fst.comp tendsto_snd) ((@tendsto_insert_nth' n l).comp (tendsto.prod_mk tendsto_fst (tendsto_snd.comp tendsto_snd))) end lemma tendsto_insert_nth {Ξ² : Type*} {n : β„•} {a : Ξ±} {l : list Ξ±} {f : Ξ² β†’ Ξ±} {g : Ξ² β†’ list Ξ±} {b : _root_.filter Ξ²} (hf : tendsto f b (𝓝 a)) (hg : tendsto g b (𝓝 l)) : tendsto (Ξ»b:Ξ², insert_nth n (f b) (g b)) b (𝓝 (insert_nth n a l)) := tendsto_insert_nth'.comp (tendsto.prod_mk hf hg) lemma continuous_insert_nth {n : β„•} : continuous (Ξ»p:Ξ±Γ—list Ξ±, insert_nth n p.1 p.2) := continuous_iff_continuous_at.mpr $ assume ⟨a, l⟩, by rw [continuous_at, nhds_prod_eq]; exact tendsto_insert_nth' lemma tendsto_remove_nth : βˆ€{n : β„•} {l : list Ξ±}, tendsto (Ξ»l, remove_nth l n) (𝓝 l) (𝓝 (remove_nth l n)) | _ [] := by rw [nhds_nil]; exact tendsto_pure_nhds _ _ | 0 (a::l) := by rw [tendsto_cons_iff]; exact tendsto_snd | (n+1) (a::l) := begin rw [tendsto_cons_iff], dsimp [remove_nth], exact tendsto_cons tendsto_fst ((@tendsto_remove_nth n l).comp tendsto_snd) end lemma continuous_remove_nth {n : β„•} : continuous (Ξ»l : list Ξ±, remove_nth l n) := continuous_iff_continuous_at.mpr $ assume a, tendsto_remove_nth end list namespace vector open list instance (n : β„•) [topological_space Ξ±] : topological_space (vector Ξ± n) := by unfold vector; apply_instance lemma tendsto_cons [topological_space Ξ±] {n : β„•} {a : Ξ±} {l : vector Ξ± n}: tendsto (Ξ»p:Ξ±Γ—vector Ξ± n, vector.cons p.1 p.2) ((𝓝 a).prod (𝓝 l)) (𝓝 (a :: l)) := by { simp [tendsto_subtype_rng, ←subtype.val_eq_coe, cons_val], exact tendsto_cons tendsto_fst (tendsto.comp continuous_at_subtype_coe tendsto_snd) } lemma tendsto_insert_nth [topological_space Ξ±] {n : β„•} {i : fin (n+1)} {a:Ξ±} : βˆ€{l:vector Ξ± n}, tendsto (Ξ»p:Ξ±Γ—vector Ξ± n, insert_nth p.1 i p.2) ((𝓝 a).prod (𝓝 l)) (𝓝 (insert_nth a i l)) | ⟨l, hl⟩ := begin rw [insert_nth, tendsto_subtype_rng], simp [insert_nth_val], exact list.tendsto_insert_nth tendsto_fst (tendsto.comp continuous_at_subtype_coe tendsto_snd : _) end lemma continuous_insert_nth' [topological_space Ξ±] {n : β„•} {i : fin (n+1)} : continuous (Ξ»p:Ξ±Γ—vector Ξ± n, insert_nth p.1 i p.2) := continuous_iff_continuous_at.mpr $ assume ⟨a, l⟩, by rw [continuous_at, nhds_prod_eq]; exact tendsto_insert_nth lemma continuous_insert_nth [topological_space Ξ±] [topological_space Ξ²] {n : β„•} {i : fin (n+1)} {f : Ξ² β†’ Ξ±} {g : Ξ² β†’ vector Ξ± n} (hf : continuous f) (hg : continuous g) : continuous (Ξ»b, insert_nth (f b) i (g b)) := continuous_insert_nth'.comp (continuous.prod_mk hf hg) lemma continuous_at_remove_nth [topological_space Ξ±] {n : β„•} {i : fin (n+1)} : βˆ€{l:vector Ξ± (n+1)}, continuous_at (remove_nth i) l | ⟨l, hl⟩ := -- βˆ€{l:vector Ξ± (n+1)}, tendsto (remove_nth i) (𝓝 l) (𝓝 (remove_nth i l)) --| ⟨l, hl⟩ := begin rw [continuous_at, remove_nth, tendsto_subtype_rng], simp [remove_nth_val, ← subtype.val_eq_coe], exact tendsto.comp list.tendsto_remove_nth continuous_at_subtype_coe end lemma continuous_remove_nth [topological_space Ξ±] {n : β„•} {i : fin (n+1)} : continuous (remove_nth i : vector Ξ± (n+1) β†’ vector Ξ± n) := continuous_iff_continuous_at.mpr $ assume ⟨a, l⟩, continuous_at_remove_nth end vector
0840021aed179cfdfec792073bcba9c9904ce494
367134ba5a65885e863bdc4507601606690974c1
/src/analysis/analytic/inverse.lean
6a7e2813b33efb3323724d3f2c29f13dec3c2914
[ "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
27,075
lean
/- Copyright (c) 2021 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel -/ import analysis.analytic.composition /-! # Inverse of analytic functions We construct the left and right inverse of a formal multilinear series with invertible linear term, we prove that they coincide and study their properties (notably convergence). ## Main statements * `p.left_inv i`: the formal left inverse of the formal multilinear series `p`, for `i : E ≃L[π•œ] F` which coincides with `p₁`. * `p.right_inv i`: the formal right inverse of the formal multilinear series `p`, for `i : E ≃L[π•œ] F` which coincides with `p₁`. * `p.left_inv_comp` says that `p.left_inv i` is indeed a left inverse to `p` when `p₁ = i`. * `p.right_inv_comp` says that `p.right_inv i` is indeed a right inverse to `p` when `p₁ = i`. * `p.left_inv_eq_right_inv`: the two inverses coincide. * `p.radius_right_inv_pos_of_radius_pos`: if a power series has a positive radius of convergence, then so does its inverse. -/ open_locale big_operators classical topological_space open finset filter namespace formal_multilinear_series variables {π•œ : Type*} [nondiscrete_normed_field π•œ] {E : Type*} [normed_group E] [normed_space π•œ E] {F : Type*} [normed_group F] [normed_space π•œ F] /-! ### The left inverse of a formal multilinear series -/ /-- The left inverse of a formal multilinear series, where the `n`-th term is defined inductively in terms of the previous ones to make sure that `(left_inv p i) ∘ p = id`. For this, the linear term `p₁` in `p` should be invertible. In the definition, `i` is a linear isomorphism that should coincide with `p₁`, so that one can use its inverse in the construction. The definition does not use that `i = p₁`, but proofs that the definition is well-behaved do. The `n`-th term in `q ∘ p` is `βˆ‘ qβ‚– (p_{j₁}, ..., p_{jβ‚–})` over `j₁ + ... + jβ‚– = n`. In this expression, `qβ‚™` appears only once, in `qβ‚™ (p₁, ..., p₁)`. We adjust the definition so that this term compensates the rest of the sum, using `i⁻¹` as an inverse to `p₁`. These formulas only make sense when the constant term `pβ‚€` vanishes. The definition we give is general, but it ignores the value of `pβ‚€`. -/ noncomputable def left_inv (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) : formal_multilinear_series π•œ F E | 0 := 0 | 1 := (continuous_multilinear_curry_fin1 π•œ F E).symm i.symm | (n+2) := - βˆ‘ c : {c : composition (n+2) // c.length < n + 2}, have (c : composition (n+2)).length < n+2 := c.2, (left_inv (c : composition (n+2)).length).comp_along_composition (p.comp_continuous_linear_map i.symm) c @[simp] lemma left_inv_coeff_zero (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) : p.left_inv i 0 = 0 := rfl @[simp] lemma left_inv_coeff_one (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) : p.left_inv i 1 = (continuous_multilinear_curry_fin1 π•œ F E).symm i.symm := rfl /-- The left inverse does not depend on the zeroth coefficient of a formal multilinear series. -/ lemma left_inv_remove_zero (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) : p.remove_zero.left_inv i = p.left_inv i := begin ext1 n, induction n using nat.strong_rec' with n IH, cases n, { simp }, -- if one replaces `simp` with `refl`, the proof times out in the kernel. cases n, { simp }, -- TODO: why? simp only [left_inv, neg_inj], refine finset.sum_congr rfl (Ξ» c cuniv, _), rcases c with ⟨c, hc⟩, ext v, dsimp, simp [IH _ hc], end /-- The left inverse to a formal multilinear series is indeed a left inverse, provided its linear term is invertible. -/ lemma left_inv_comp (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) (h : p 1 = (continuous_multilinear_curry_fin1 π•œ E F).symm i) : (left_inv p i).comp p = id π•œ E := begin ext n v, cases n, { simp only [left_inv, continuous_multilinear_map.zero_apply, id_apply_ne_one, ne.def, not_false_iff, zero_ne_one, comp_coeff_zero']}, cases n, { simp only [left_inv, comp_coeff_one, h, id_apply_one, continuous_linear_equiv.coe_apply, continuous_linear_equiv.symm_apply_apply, continuous_multilinear_curry_fin1_symm_apply] }, have A : (finset.univ : finset (composition (n+2))) = {c | composition.length c < n + 2}.to_finset βˆͺ {composition.ones (n+2)}, { refine subset.antisymm (Ξ» c hc, _) (subset_univ _), by_cases h : c.length < n + 2, { simp [h] }, { simp [composition.eq_ones_iff_le_length.2 (not_lt.1 h)] } }, have B : disjoint ({c | composition.length c < n + 2} : set (composition (n + 2))).to_finset {composition.ones (n+2)}, by simp, have C : (p.left_inv i (composition.ones (n + 2)).length) (Ξ» (j : fin (composition.ones n.succ.succ).length), p 1 (Ξ» k, v ((fin.cast_le (composition.length_le _)) j))) = p.left_inv i (n+2) (Ξ» (j : fin (n+2)), p 1 (Ξ» k, v j)), { apply formal_multilinear_series.congr _ (composition.ones_length _) (Ξ» j hj1 hj2, _), exact formal_multilinear_series.congr _ rfl (Ξ» k hk1 hk2, by congr) }, have D : p.left_inv i (n+2) (Ξ» (j : fin (n+2)), p 1 (Ξ» k, v j)) = - βˆ‘ (c : composition (n + 2)) in {c : composition (n + 2) | c.length < n + 2}.to_finset, (p.left_inv i c.length) (p.apply_composition c v), { simp only [left_inv, continuous_multilinear_map.neg_apply, neg_inj, continuous_multilinear_map.sum_apply], convert (sum_to_finset_eq_subtype (Ξ» (c : composition (n+2)), c.length < n+2) (Ξ» (c : composition (n+2)), (continuous_multilinear_map.comp_along_composition (p.comp_continuous_linear_map ↑(i.symm)) c (p.left_inv i c.length)) (Ξ» (j : fin (n + 2)), p 1 (Ξ» (k : fin 1), v j)))).symm.trans _, simp only [comp_continuous_linear_map_apply_composition, continuous_multilinear_map.comp_along_composition_apply], congr, ext c, congr, ext k, simp [h] }, simp [formal_multilinear_series.comp, show n + 2 β‰  1, by dec_trivial, A, finset.sum_union B, apply_composition_ones, C, D], end /-! ### The right inverse of a formal multilinear series -/ /-- The right inverse of a formal multilinear series, where the `n`-th term is defined inductively in terms of the previous ones to make sure that `p ∘ (right_inv p i) = id`. For this, the linear term `p₁` in `p` should be invertible. In the definition, `i` is a linear isomorphism that should coincide with `p₁`, so that one can use its inverse in the construction. The definition does not use that `i = p₁`, but proofs that the definition is well-behaved do. The `n`-th term in `p ∘ q` is `βˆ‘ pβ‚– (q_{j₁}, ..., q_{jβ‚–})` over `j₁ + ... + jβ‚– = n`. In this expression, `qβ‚™` appears only once, in `p₁ (qβ‚™)`. We adjust the definition of `qβ‚™` so that this term compensates the rest of the sum, using `i⁻¹` as an inverse to `p₁`. These formulas only make sense when the constant term `pβ‚€` vanishes. The definition we give is general, but it ignores the value of `pβ‚€`. -/ noncomputable def right_inv (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) : formal_multilinear_series π•œ F E | 0 := 0 | 1 := (continuous_multilinear_curry_fin1 π•œ F E).symm i.symm | (n+2) := let q : formal_multilinear_series π•œ F E := Ξ» k, if h : k < n + 2 then right_inv k else 0 in - (i.symm : F β†’L[π•œ] E).comp_continuous_multilinear_map ((p.comp q) (n+2)) @[simp] lemma right_inv_coeff_zero (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) : p.right_inv i 0 = 0 := rfl @[simp] lemma right_inv_coeff_one (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) : p.right_inv i 1 = (continuous_multilinear_curry_fin1 π•œ F E).symm i.symm := rfl /-- The right inverse does not depend on the zeroth coefficient of a formal multilinear series. -/ lemma right_inv_remove_zero (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) : p.remove_zero.right_inv i = p.right_inv i := begin ext1 n, induction n using nat.strong_rec' with n IH, cases n, { simp }, cases n, { simp }, simp only [right_inv, neg_inj], unfold_coes, congr' 1, rw remove_zero_comp_of_pos _ _ (show 0 < n+2, by dec_trivial), congr' 1, ext k, by_cases hk : k < n+2; simp [hk, IH] end lemma comp_right_inv_aux1 {n : β„•} (hn : 0 < n) (p : formal_multilinear_series π•œ E F) (q : formal_multilinear_series π•œ F E) (v : fin n β†’ F) : p.comp q n v = (βˆ‘ (c : composition n) in {c : composition n | 1 < c.length}.to_finset, p c.length (q.apply_composition c v)) + p 1 (Ξ» i, q n v) := begin have A : (finset.univ : finset (composition n)) = {c | 1 < composition.length c}.to_finset βˆͺ {composition.single n hn}, { refine subset.antisymm (Ξ» c hc, _) (subset_univ _), by_cases h : 1 < c.length, { simp [h] }, { have : c.length = 1, by { refine (eq_iff_le_not_lt.2 ⟨ _, h⟩).symm, exact c.length_pos_of_pos hn }, rw ← composition.eq_single_iff_length hn at this, simp [this] } }, have B : disjoint ({c | 1 < composition.length c} : set (composition n)).to_finset {composition.single n hn}, by simp, have C : p (composition.single n hn).length (q.apply_composition (composition.single n hn) v) = p 1 (Ξ» (i : fin 1), q n v), { apply p.congr (composition.single_length hn) (Ξ» j hj1 hj2, _), simp [apply_composition_single] }, simp [formal_multilinear_series.comp, A, finset.sum_union B, C], end lemma comp_right_inv_aux2 (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) (n : β„•) (v : fin (n + 2) β†’ F) : βˆ‘ (c : composition (n + 2)) in {c : composition (n + 2) | 1 < c.length}.to_finset, p c.length (apply_composition (Ξ» (k : β„•), ite (k < n + 2) (p.right_inv i k) 0) c v) = βˆ‘ (c : composition (n + 2)) in {c : composition (n + 2) | 1 < c.length}.to_finset, p c.length ((p.right_inv i).apply_composition c v) := begin have N : 0 < n + 2, by dec_trivial, refine sum_congr rfl (Ξ» c hc, p.congr rfl (Ξ» j hj1 hj2, _)), have : βˆ€ k, c.blocks_fun k < n + 2, { simp only [set.mem_to_finset, set.mem_set_of_eq] at hc, simp [← composition.ne_single_iff N, composition.eq_single_iff_length, ne_of_gt hc] }, simp [apply_composition, this], end /-- The right inverse to a formal multilinear series is indeed a right inverse, provided its linear term is invertible and its constant term vanishes. -/ lemma comp_right_inv (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) (h : p 1 = (continuous_multilinear_curry_fin1 π•œ E F).symm i) (h0 : p 0 = 0) : p.comp (right_inv p i) = id π•œ F := begin ext n v, cases n, { simp only [h0, continuous_multilinear_map.zero_apply, id_apply_ne_one, ne.def, not_false_iff, zero_ne_one, comp_coeff_zero']}, cases n, { simp only [comp_coeff_one, h, right_inv, continuous_linear_equiv.apply_symm_apply, id_apply_one, continuous_linear_equiv.coe_apply, continuous_multilinear_curry_fin1_symm_apply] }, have N : 0 < n+2, by dec_trivial, simp [comp_right_inv_aux1 N, h, right_inv, lt_irrefl n, show n + 2 β‰  1, by dec_trivial, ← sub_eq_add_neg, sub_eq_zero, comp_right_inv_aux2], end lemma right_inv_coeff (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) (n : β„•) (hn : 2 ≀ n) : p.right_inv i n = - (i.symm : F β†’L[π•œ] E).comp_continuous_multilinear_map (βˆ‘ c in ({c | 1 < composition.length c}.to_finset : finset (composition n)), p.comp_along_composition (p.right_inv i) c) := begin cases n, { exact false.elim (zero_lt_two.not_le hn) }, cases n, { exact false.elim (one_lt_two.not_le hn) }, simp only [right_inv, neg_inj], congr' 1, ext v, have N : 0 < n + 2, by dec_trivial, have : (p 1) (Ξ» (i : fin 1), 0) = 0 := continuous_multilinear_map.map_zero _, simp [comp_right_inv_aux1 N, lt_irrefl n, this, comp_right_inv_aux2] end /-! ### Coincidence of the left and the right inverse -/ private lemma left_inv_eq_right_inv_aux (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) (h : p 1 = (continuous_multilinear_curry_fin1 π•œ E F).symm i) (h0 : p 0 = 0) : left_inv p i = right_inv p i := calc left_inv p i = (left_inv p i).comp (id π•œ F) : by simp ... = (left_inv p i).comp (p.comp (right_inv p i)) : by rw comp_right_inv p i h h0 ... = ((left_inv p i).comp p).comp (right_inv p i) : by rw comp_assoc ... = (id π•œ E).comp (right_inv p i) : by rw left_inv_comp p i h ... = right_inv p i : by simp /-- The left inverse and the right inverse of a formal multilinear series coincide. This is not at all obvious from their definition, but it follows from uniqueness of inverses (which comes from the fact that composition is associative on formal multilinear series). -/ theorem left_inv_eq_right_inv (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) (h : p 1 = (continuous_multilinear_curry_fin1 π•œ E F).symm i) : left_inv p i = right_inv p i := calc left_inv p i = left_inv p.remove_zero i : by rw left_inv_remove_zero ... = right_inv p.remove_zero i : by { apply left_inv_eq_right_inv_aux; simp [h] } ... = right_inv p i : by rw right_inv_remove_zero /-! ### Convergence of the inverse of a power series Assume that `p` is a convergent multilinear series, and let `q` be its (left or right) inverse. Using the left-inverse formula gives $$ q_n = - (p_1)^{-n} \sum_{k=0}^{n-1} \sum_{i_1 + \dotsc + i_k = n} q_k (p_{i_1}, \dotsc, p_{i_k}). $$ Assume for simplicity that we are in dimension `1` and `p₁ = 1`. In the formula for `qβ‚™`, the term `q_{n-1}` appears with a multiplicity of `n-1` (choosing the index `i_j` for which `i_j = 2` while all the other indices are equal to `1`), which indicates that `qβ‚™` might grow like `n!`. This is bad for summability properties. It turns out that the right-inverse formula is better behaved, and should instead be used for this kind of estimate. It reads $$ q_n = - (p_1)^{-1} \sum_{k=2}^n \sum_{i_1 + \dotsc + i_k = n} p_k (q_{i_1}, \dotsc, q_{i_k}). $$ Here, `q_{n-1}` can only appear in the term with `k = 2`, and it only appears twice, so there is hope this formula can lead to an at most geometric behavior. Let `Qβ‚™ = βˆ₯qβ‚™βˆ₯`. Bounding `βˆ₯pβ‚–βˆ₯` with `C r^k` gives an inequality $$ Q_n ≀ C' \sum_{k=2}^n r^k \sum_{i_1 + \dotsc + i_k = n} Q_{i_1} \dotsm Q_{i_k}. $$ This formula is not enough to prove by naive induction on `n` a bound of the form `Qβ‚™ ≀ D R^n`. However, assuming that the inequality above were an equality, one could get a formula for the generating series of the `Qβ‚™`: $$ \begin{align} Q(z) & := \sum Q_n z^n = Q_1 z + C' \sum_{2 \leq k \leq n} \sum_{i_1 + \dotsc + i_k = n} (r z^{i_1} Q_{i_1}) \dotsm (r z^{i_k} Q_{i_k}) \\ & = Q_1 z + C' \sum_{k = 2}^\infty (\sum_{i_1 \geq 1} r z^{i_1} Q_{i_1}) \dotsm (\sum_{i_k \geq 1} r z^{i_k} Q_{i_k}) \\ & = Q_1 z + C' \sum_{k = 2}^\infty (r Q(z))^k = Q_1 z + C' (r Q(z))^2 / (1 - r Q(z)). \end{align} $$ One can solve this formula explicitly. The solution is analytic in a neighborhood of `0` in `β„‚`, hence its coefficients grow at most geometrically (by a contour integral argument), and therefore the original `Qβ‚™`, which are bounded by these ones, are also at most geometric. This classical argument is not really satisfactory, as it requires an a priori bound on a complex analytic function. Another option would be to compute explicitly its terms (with binomial coefficients) to obtain an explicit geometric bound, but this would be very painful. Instead, we will use the above intuition, but in a slightly different form, with finite sums and an induction. I learnt this trick in [pΓΆschel2017siegelsternberg]. Let $S_n = \sum_{k=1}^n Q_k a^k$ (where `a` is a positive real parameter to be chosen suitably small). The above computation but with finite sums shows that $$ S_n \leq Q_1 a + C' \sum_{k=2}^n (r S_{n-1})^k. $$ In particular, $S_n \leq Q_1 a + C' (r S_{n-1})^2 / (1- r S_{n-1})$. Assume that $S_{n-1} \leq K a$, where `K > Q₁` is fixed and `a` is small enough so that `r K a ≀ 1/2` (to control the denominator). Then this equation gives a bound $S_n \leq Q_1 a + 2 C' r^2 K^2 a^2$. If `a` is small enough, this is bounded by `K a` as the second term is quadratic in `a`, and therefore negligible. By induction, we deduce `Sβ‚™ ≀ K a` for all `n`, which gives in particular the fact that `aⁿ Qβ‚™` remains bounded. -/ /-- First technical lemma to control the growth of coefficients of the inverse. Bound the explicit expression for `βˆ‘_{k<n+1} aᡏ Qβ‚–` in terms of a sum of powers of the same sum one step before, in a general abstract setup. -/ lemma radius_right_inv_pos_of_radius_pos_aux1 (n : β„•) (p : β„• β†’ ℝ) (hp : βˆ€ k, 0 ≀ p k) {r a : ℝ} (hr : 0 ≀ r) (ha : 0 ≀ a) : βˆ‘ k in Ico 2 (n + 1), a ^ k * (βˆ‘ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)), r ^ c.length * ∏ j, p (c.blocks_fun j)) ≀ βˆ‘ j in Ico 2 (n + 1), r ^ j * (βˆ‘ k in Ico 1 n, a ^ k * p k) ^ j := calc βˆ‘ k in Ico 2 (n + 1), a ^ k * (βˆ‘ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)), r ^ c.length * ∏ j, p (c.blocks_fun j)) = βˆ‘ k in Ico 2 (n + 1), (βˆ‘ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)), ∏ j, r * (a ^ (c.blocks_fun j) * p (c.blocks_fun j))) : begin simp_rw [mul_sum], apply sum_congr rfl (Ξ» k hk, _), apply sum_congr rfl (Ξ» c hc, _), rw [prod_mul_distrib, prod_mul_distrib, prod_pow_eq_pow_sum, composition.sum_blocks_fun, prod_const, card_fin], ring, end ... ≀ βˆ‘ d in comp_partial_sum_target 2 (n + 1) n, ∏ (j : fin d.2.length), r * (a ^ d.2.blocks_fun j * p (d.2.blocks_fun j)) : begin rw sum_sigma', refine sum_le_sum_of_subset_of_nonneg _ (Ξ» x hx1 hx2, prod_nonneg (Ξ» j hj, mul_nonneg hr (mul_nonneg (pow_nonneg ha _) (hp _)))), rintros ⟨k, c⟩ hd, simp only [set.mem_to_finset, Ico.mem, mem_sigma, set.mem_set_of_eq] at hd, simp only [mem_comp_partial_sum_target_iff], refine ⟨hd.2, c.length_le.trans_lt hd.1.2, Ξ» j, _⟩, have : c β‰  composition.single k (zero_lt_two.trans_le hd.1.1), by simp [composition.eq_single_iff_length, ne_of_gt hd.2], rw composition.ne_single_iff at this, exact (this j).trans_le (nat.lt_succ_iff.mp hd.1.2) end ... = βˆ‘ e in comp_partial_sum_source 2 (n+1) n, ∏ (j : fin e.1), r * (a ^ e.2 j * p (e.2 j)) : begin symmetry, apply comp_change_of_variables_sum, rintros ⟨k, blocks_fun⟩ H, have K : (comp_change_of_variables 2 (n + 1) n ⟨k, blocks_fun⟩ H).snd.length = k, by simp, congr' 2; try { rw K }, rw fin.heq_fun_iff K.symm, assume j, rw comp_change_of_variables_blocks_fun, end ... = βˆ‘ j in Ico 2 (n+1), r ^ j * (βˆ‘ k in Ico 1 n, a ^ k * p k) ^ j : begin rw [comp_partial_sum_source, ← sum_sigma' (Ico 2 (n + 1)) (Ξ» (k : β„•), (fintype.pi_finset (Ξ» (i : fin k), Ico 1 n) : finset (fin k β†’ β„•))) (Ξ» n e, ∏ (j : fin n), r * (a ^ e j * p (e j)))], apply sum_congr rfl (Ξ» j hj, _), simp only [← @multilinear_map.mk_pi_algebra_apply ℝ (fin j) _ _ ℝ], simp only [← multilinear_map.map_sum_finset (multilinear_map.mk_pi_algebra ℝ (fin j) ℝ) (Ξ» k (m : β„•), r * (a ^ m * p m))], simp only [multilinear_map.mk_pi_algebra_apply], dsimp, simp [prod_const, ← mul_sum, mul_pow], end /-- Second technical lemma to control the growth of coefficients of the inverse. Bound the explicit expression for `βˆ‘_{k<n+1} aᡏ Qβ‚–` in terms of a sum of powers of the same sum one step before, in the specific setup we are interesting in, by reducing to the general bound in `radius_right_inv_pos_of_radius_pos_aux1`. -/ lemma radius_right_inv_pos_of_radius_pos_aux2 {n : β„•} (hn : 2 ≀ n + 1) (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) {r a C : ℝ} (hr : 0 ≀ r) (ha : 0 ≀ a) (hC : 0 ≀ C) (hp : βˆ€ n, βˆ₯p nβˆ₯ ≀ C * r ^ n) : (βˆ‘ k in Ico 1 (n + 1), a ^ k * βˆ₯p.right_inv i kβˆ₯) ≀ βˆ₯(i.symm : F β†’L[π•œ] E)βˆ₯ * a + βˆ₯(i.symm : F β†’L[π•œ] E)βˆ₯ * C * βˆ‘ k in Ico 2 (n + 1), (r * ((βˆ‘ j in Ico 1 n, a ^ j * βˆ₯p.right_inv i jβˆ₯))) ^ k := let I := βˆ₯(i.symm : F β†’L[π•œ] E)βˆ₯ in calc βˆ‘ k in Ico 1 (n + 1), a ^ k * βˆ₯p.right_inv i kβˆ₯ = a * I + βˆ‘ k in Ico 2 (n + 1), a ^ k * βˆ₯p.right_inv i kβˆ₯ : by simp only [linear_isometry_equiv.norm_map, pow_one, right_inv_coeff_one, Ico.succ_singleton, sum_singleton, ← sum_Ico_consecutive _ one_le_two hn] ... = a * I + βˆ‘ k in Ico 2 (n + 1), a ^ k * βˆ₯(i.symm : F β†’L[π•œ] E).comp_continuous_multilinear_map (βˆ‘ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)), p.comp_along_composition (p.right_inv i) c)βˆ₯ : begin congr' 1, apply sum_congr rfl (Ξ» j hj, _), rw [right_inv_coeff _ _ _ (Ico.mem.1 hj).1, norm_neg], end ... ≀ a * βˆ₯(i.symm : F β†’L[π•œ] E)βˆ₯ + βˆ‘ k in Ico 2 (n + 1), a ^ k * (I * (βˆ‘ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)), C * r ^ c.length * ∏ j, βˆ₯p.right_inv i (c.blocks_fun j)βˆ₯)) : begin apply_rules [add_le_add, le_refl, sum_le_sum (Ξ» j hj, _), mul_le_mul_of_nonneg_left, pow_nonneg, ha], apply (continuous_linear_map.norm_comp_continuous_multilinear_map_le _ _).trans, apply mul_le_mul_of_nonneg_left _ (norm_nonneg _), apply (norm_sum_le _ _).trans, apply sum_le_sum (Ξ» c hc, _), apply (comp_along_composition_norm _ _ _).trans, apply mul_le_mul_of_nonneg_right (hp _), exact prod_nonneg (Ξ» j hj, norm_nonneg _), end ... = I * a + I * C * βˆ‘ k in Ico 2 (n + 1), a ^ k * (βˆ‘ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)), r ^ c.length * ∏ j, βˆ₯p.right_inv i (c.blocks_fun j)βˆ₯) : begin simp_rw [mul_assoc C, ← mul_sum, ← mul_assoc, mul_comm _ (βˆ₯↑i.symmβˆ₯), mul_assoc, ← mul_sum, ← mul_assoc, mul_comm _ C, mul_assoc, ← mul_sum], ring, end ... ≀ I * a + I * C * βˆ‘ k in Ico 2 (n+1), (r * ((βˆ‘ j in Ico 1 n, a ^ j * βˆ₯p.right_inv i jβˆ₯))) ^ k : begin apply_rules [add_le_add, le_refl, mul_le_mul_of_nonneg_left, norm_nonneg, hC, mul_nonneg], simp_rw [mul_pow], apply radius_right_inv_pos_of_radius_pos_aux1 n (Ξ» k, βˆ₯p.right_inv i kβˆ₯) (Ξ» k, norm_nonneg _) hr ha, end /-- If a a formal multilinear series has a positive radius of convergence, then its right inverse also has a positive radius of convergence. -/ theorem radius_right_inv_pos_of_radius_pos (p : formal_multilinear_series π•œ E F) (i : E ≃L[π•œ] F) (hp : 0 < p.radius) : 0 < (p.right_inv i).radius := begin obtain ⟨C, r, Cpos, rpos, ple⟩ : βˆƒ C r (hC : 0 < C) (hr : 0 < r), βˆ€ (n : β„•), βˆ₯p nβˆ₯ ≀ C * r ^ n := le_mul_pow_of_radius_pos p hp, let I := βˆ₯(i.symm : F β†’L[π•œ] E)βˆ₯, -- choose `a` small enough to make sure that `βˆ‘_{k ≀ n} aᡏ Qβ‚–` will be controllable by -- induction obtain ⟨a, apos, ha1, ha2⟩ : βˆƒ a (apos : 0 < a), (2 * I * C * r^2 * (I + 1) ^ 2 * a ≀ 1) ∧ (r * (I + 1) * a ≀ 1/2), { have : tendsto (Ξ» a, 2 * I * C * r^2 * (I + 1) ^ 2 * a) (𝓝 0) (𝓝 (2 * I * C * r^2 * (I + 1) ^ 2 * 0)) := tendsto_const_nhds.mul tendsto_id, have A : βˆ€αΆ  a in 𝓝 0, 2 * I * C * r^2 * (I + 1) ^ 2 * a < 1, by { apply (tendsto_order.1 this).2, simp [zero_lt_one] }, have : tendsto (Ξ» a, r * (I + 1) * a) (𝓝 0) (𝓝 (r * (I + 1) * 0)) := tendsto_const_nhds.mul tendsto_id, have B : βˆ€αΆ  a in 𝓝 0, r * (I + 1) * a < 1/2, by { apply (tendsto_order.1 this).2, simp [zero_lt_one] }, have C : βˆ€αΆ  a in 𝓝[set.Ioi (0 : ℝ)] (0 : ℝ), (0 : ℝ) < a, by { filter_upwards [self_mem_nhds_within], exact Ξ» a ha, ha }, rcases (C.and ((A.and B).filter_mono inf_le_left)).exists with ⟨a, ha⟩, exact ⟨a, ha.1, ha.2.1.le, ha.2.2.le⟩ }, -- check by induction that the partial sums are suitably bounded, using the choice of `a` and the -- inductive control from Lemma `radius_right_inv_pos_of_radius_pos_aux2`. let S := Ξ» n, βˆ‘ k in Ico 1 n, a ^ k * βˆ₯p.right_inv i kβˆ₯, have IRec : βˆ€ n, 1 ≀ n β†’ S n ≀ (I + 1) * a, { apply nat.le_induction, { simp only [S], rw [Ico.eq_empty_of_le (le_refl 1), sum_empty], exact mul_nonneg (add_nonneg (norm_nonneg _) zero_le_one) apos.le }, { assume n one_le_n hn, have In : 2 ≀ n + 1, by linarith, have Snonneg : 0 ≀ S n := sum_nonneg (Ξ» x hx, mul_nonneg (pow_nonneg apos.le _) (norm_nonneg _)), have rSn : r * S n ≀ 1/2 := calc r * S n ≀ r * ((I+1) * a) : mul_le_mul_of_nonneg_left hn rpos.le ... ≀ 1/2 : by rwa [← mul_assoc], calc S (n + 1) ≀ I * a + I * C * βˆ‘ k in Ico 2 (n + 1), (r * S n)^k : radius_right_inv_pos_of_radius_pos_aux2 In p i rpos.le apos.le Cpos.le ple ... = I * a + I * C * (((r * S n) ^ 2 - (r * S n) ^ (n + 1)) / (1 - r * S n)) : by { rw geom_sum_Ico' _ In, exact ne_of_lt (rSn.trans_lt (by norm_num)) } ... ≀ I * a + I * C * ((r * S n) ^ 2 / (1/2)) : begin apply_rules [add_le_add, le_refl, mul_le_mul_of_nonneg_left, mul_nonneg, norm_nonneg, Cpos.le], refine div_le_div (pow_two_nonneg _) _ (by norm_num) (by linarith), simp only [sub_le_self_iff], apply pow_nonneg (mul_nonneg rpos.le Snonneg), end ... = I * a + 2 * I * C * (r * S n) ^ 2 : by ring ... ≀ I * a + 2 * I * C * (r * ((I + 1) * a)) ^ 2 : by apply_rules [add_le_add, le_refl, mul_le_mul_of_nonneg_left, mul_nonneg, norm_nonneg, Cpos.le, zero_le_two, pow_le_pow_of_le_left, rpos.le] ... = (I + 2 * I * C * r^2 * (I + 1) ^ 2 * a) * a : by ring ... ≀ (I + 1) * a : by apply_rules [mul_le_mul_of_nonneg_right, apos.le, add_le_add, le_refl] } }, -- conclude that all coefficients satisfy `aⁿ Qβ‚™ ≀ (I + 1) a`. let a' : nnreal := ⟨a, apos.le⟩, suffices H : (a' : ennreal) ≀ (p.right_inv i).radius, by { apply lt_of_lt_of_le _ H, exact_mod_cast apos }, apply le_radius_of_bound _ ((I + 1) * a) (Ξ» n, _), by_cases hn : n = 0, { have : βˆ₯p.right_inv i nβˆ₯ = βˆ₯p.right_inv i 0βˆ₯, by congr; try { rw hn }, simp only [this, norm_zero, zero_mul, right_inv_coeff_zero], apply_rules [mul_nonneg, add_nonneg, norm_nonneg, zero_le_one, apos.le] }, { have one_le_n : 1 ≀ n := bot_lt_iff_ne_bot.2 hn, calc βˆ₯p.right_inv i nβˆ₯ * ↑a' ^ n = a ^ n * βˆ₯p.right_inv i nβˆ₯ : mul_comm _ _ ... ≀ βˆ‘ k in Ico 1 (n + 1), a ^ k * βˆ₯p.right_inv i kβˆ₯ : begin have : βˆ€ k ∈ Ico 1 (n + 1), 0 ≀ a ^ k * βˆ₯p.right_inv i kβˆ₯ := Ξ» k hk, mul_nonneg (pow_nonneg apos.le _) (norm_nonneg _), exact single_le_sum this (by simp [one_le_n]), end ... ≀ (I + 1) * a : IRec (n + 1) (by dec_trivial) } end end formal_multilinear_series
e6f8f9219d6e48553afceb66c8a2f96a0d5dbe3c
aa5a655c05e5359a70646b7154e7cac59f0b4132
/stage0/src/Init/Data/Array/InsertionSort.lean
67023dc6f92d2920ebb9563ddbced82e1f7dc291
[ "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
922
lean
/- Copyright (c) 2018 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.Array.Basic @[inline] def Array.insertionSort (a : Array Ξ±) (lt : Ξ± β†’ Ξ± β†’ Bool) : Array Ξ± := traverse a 0 a.size where @[specialize] traverse (a : Array Ξ±) (i : Nat) (fuel : Nat) : Array Ξ± := match fuel with | 0 => a | fuel+1 => if h : i < a.size then traverse (swapLoop a i h) (i+1) fuel else a @[specialize] swapLoop (a : Array Ξ±) (j : Nat) (h : j < a.size) : Array Ξ± := match he:j with | 0 => a | j'+1 => have h' : j' < a.size by subst j; exact Nat.ltTrans (Nat.ltSuccSelf _) h if lt (a.get ⟨j, h⟩) (a.get ⟨j', h'⟩) then swapLoop (a.swap ⟨j, h⟩ ⟨j', h'⟩) j' (by rw sizeSwapEq; assumption done) else a
27bcb18f8eff8178da741340fa29d772c773f9bb
26ac254ecb57ffcb886ff709cf018390161a9225
/src/field_theory/separable.lean
59af39fd106d2dca06c811abc7279ecc9c03cb06
[ "Apache-2.0" ]
permissive
eric-wieser/mathlib
42842584f584359bbe1fc8b88b3ff937c8acd72d
d0df6b81cd0920ad569158c06a3fd5abb9e63301
refs/heads/master
1,669,546,404,255
1,595,254,668,000
1,595,254,668,000
281,173,504
0
0
Apache-2.0
1,595,263,582,000
1,595,263,581,000
null
UTF-8
Lean
false
false
14,421
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 ring_theory.polynomial import data.polynomial.derivative /-! # Separable polynomials We define a polynomial to be separable if it is coprime with its derivative. We prove basic properties about separable polynomials here. ## Main definitions * `polynomial.separable f`: a polynomial `f` is separable iff it is coprime with its derivative. * `polynomial.expand R p f`: expand the polynomial `f` with coefficients in a commutative semiring `R` by a factor of p, so `expand R p (βˆ‘ aβ‚™ xⁿ)` is `βˆ‘ aβ‚™ xⁿᡖ`. * `polynomial.contract p f`: the opposite of `expand`, so it sends `βˆ‘ aβ‚™ xⁿᡖ` to `βˆ‘ aβ‚™ xⁿ`. -/ universes u v w open_locale classical namespace polynomial section comm_semiring variables {R : Type u} [comm_semiring R] {S : Type v} [comm_semiring S] /-- A polynomial is separable iff it is coprime with its derivative. -/ def separable (f : polynomial R) : Prop := is_coprime f f.derivative lemma separable_def (f : polynomial R) : f.separable ↔ is_coprime f f.derivative := iff.rfl lemma separable_def' (f : polynomial R) : f.separable ↔ βˆƒ a b : polynomial R, a * f + b * f.derivative = 1 := iff.rfl lemma separable_one : (1 : polynomial R).separable := is_coprime_one_left lemma separable_X_add_C (a : R) : (X + C a).separable := by { rw [separable_def, derivative_add, derivative_X, derivative_C, add_zero], exact is_coprime_one_right } lemma separable_X : (X : polynomial R).separable := by { rw [separable_def, derivative_X], exact is_coprime_one_right } lemma separable_C (r : R) : (C r).separable ↔ is_unit r := by rw [separable_def, derivative_C, is_coprime_zero_right, is_unit_C] lemma separable.of_mul_left {f g : polynomial R} (h : (f * g).separable) : f.separable := begin have := h.of_mul_left_left, rw derivative_mul at this, exact is_coprime.of_mul_right_left (is_coprime.of_add_mul_left_right this) end lemma separable.of_mul_right {f g : polynomial R} (h : (f * g).separable) : g.separable := by { rw mul_comm at h, exact h.of_mul_left } lemma separable.is_coprime {f g : polynomial R} (h : (f * g).separable) : is_coprime f g := begin have := h.of_mul_left_left, rw derivative_mul at this, exact is_coprime.of_mul_right_right (is_coprime.of_add_mul_left_right this) end theorem separable.of_pow' {f : polynomial R} : βˆ€ {n : β„•} (h : (f ^ n).separable), is_unit f ∨ (f.separable ∧ n = 1) ∨ n = 0 | 0 := Ξ» h, or.inr $ or.inr rfl | 1 := Ξ» h, or.inr $ or.inl ⟨pow_one f β–Έ h, rfl⟩ | (n+2) := Ξ» h, or.inl $ is_coprime_self.1 h.is_coprime.of_mul_right_left theorem separable.of_pow {f : polynomial R} (hf : Β¬is_unit f) {n : β„•} (hn : n β‰  0) (hfs : (f ^ n).separable) : f.separable ∧ n = 1 := (hfs.of_pow'.resolve_left hf).resolve_right hn theorem separable.map {p : polynomial R} (h : p.separable) {f : R β†’+* S} : (p.map f).separable := let ⟨a, b, H⟩ := h in ⟨a.map f, b.map f, by rw [derivative_map, ← map_mul, ← map_mul, ← map_add, H, map_one]⟩ variables (R) (p q : β„•) /-- Expand the polynomial by a factor of p, so `βˆ‘ aβ‚™ xⁿ` becomes `βˆ‘ aβ‚™ xⁿᡖ`. -/ noncomputable def expand : polynomial R →ₐ[R] polynomial R := { commutes' := Ξ» r, evalβ‚‚_C _ _, .. (evalβ‚‚_ring_hom C (X ^ p) : polynomial R β†’+* polynomial R) } lemma coe_expand : (expand R p : polynomial R β†’ polynomial R) = evalβ‚‚ C (X ^ p) := rfl variables {R} @[simp] lemma expand_C (r : R) : expand R p (C r) = C r := evalβ‚‚_C _ _ @[simp] lemma expand_X : expand R p X = X ^ p := evalβ‚‚_X _ _ @[simp] lemma expand_monomial (r : R) : expand R p (monomial q r) = monomial (q * p) r := by simp_rw [monomial_eq_smul_X, alg_hom.map_smul, alg_hom.map_pow, expand_X, mul_comm, pow_mul] theorem expand_expand (f : polynomial R) : expand R p (expand R q f) = expand R (p * q) f := polynomial.induction_on f (Ξ» r, by simp_rw expand_C) (Ξ» f g ihf ihg, by simp_rw [alg_hom.map_add, ihf, ihg]) (Ξ» n r ih, by simp_rw [alg_hom.map_mul, expand_C, alg_hom.map_pow, expand_X, alg_hom.map_pow, expand_X, pow_mul]) theorem expand_mul (f : polynomial R) : expand R (p * q) f = expand R p (expand R q f) := (expand_expand p q f).symm @[simp] theorem expand_one (f : polynomial R) : expand R 1 f = f := polynomial.induction_on f (Ξ» r, by rw expand_C) (Ξ» f g ihf ihg, by rw [alg_hom.map_add, ihf, ihg]) (Ξ» n r ih, by rw [alg_hom.map_mul, expand_C, alg_hom.map_pow, expand_X, pow_one]) theorem expand_pow (f : polynomial R) : expand R (p ^ q) f = (expand R p ^[q] f) := nat.rec_on q (by rw [nat.pow_zero, expand_one, function.iterate_zero, id]) $ Ξ» n ih, by rw [function.iterate_succ_apply', nat.pow_succ, mul_comm, expand_mul, ih] theorem derivative_expand (f : polynomial R) : (expand R p f).derivative = expand R p f.derivative * (p * X ^ (p - 1)) := by rw [coe_expand, derivative_evalβ‚‚_C, derivative_pow, derivative_X, mul_one] theorem coeff_expand {p : β„•} (hp : 0 < p) (f : polynomial R) (n : β„•) : (expand R p f).coeff n = if p ∣ n then f.coeff (n / p) else 0 := begin change (show β„• β†’β‚€ R, from (f.sum (Ξ» e a, C a * (X ^ p) ^ e) : polynomial R)) n = _, simp_rw [finsupp.sum_apply, finsupp.sum, ← pow_mul, C_mul', ← monomial_eq_smul_X, monomial, finsupp.single_apply], split_ifs with h, { rw [finset.sum_eq_single (n/p), nat.mul_div_cancel' h, if_pos rfl], refl, { intros b hb1 hb2, rw if_neg, intro hb3, apply hb2, rw [← hb3, nat.mul_div_cancel_left b hp] }, { intro hn, rw finsupp.not_mem_support_iff.1 hn, split_ifs; refl } }, { rw finset.sum_eq_zero, intros k hk, rw if_neg, exact Ξ» hkn, h ⟨k, hkn.symm⟩, }, end @[simp] theorem coeff_expand_mul {p : β„•} (hp : 0 < p) (f : polynomial R) (n : β„•) : (expand R p f).coeff (n * p) = f.coeff n := by rw [coeff_expand hp, if_pos (dvd_mul_left _ _), nat.mul_div_cancel _ hp] @[simp] theorem coeff_expand_mul' {p : β„•} (hp : 0 < p) (f : polynomial R) (n : β„•) : (expand R p f).coeff (p * n) = f.coeff n := by rw [mul_comm, coeff_expand_mul hp] theorem expand_eq_map_domain (p : β„•) (f : polynomial R) : expand R p f = f.map_domain (*p) := finsupp.induction f rfl $ Ξ» n r f hf hr ih, by rw [finsupp.map_domain_add, finsupp.map_domain_single, alg_hom.map_add, ← monomial, expand_monomial, ← monomial, ih] theorem expand_inj {p : β„•} (hp : 0 < p) {f g : polynomial R} : expand R p f = expand R p g ↔ f = g := ⟨λ H, ext $ Ξ» n, by rw [← coeff_expand_mul hp, H, coeff_expand_mul hp], congr_arg _⟩ theorem expand_eq_zero {p : β„•} (hp : 0 < p) {f : polynomial R} : expand R p f = 0 ↔ f = 0 := by rw [← (expand R p).map_zero, expand_inj hp, alg_hom.map_zero] theorem expand_eq_C {p : β„•} (hp : 0 < p) {f : polynomial R} {r : R} : expand R p f = C r ↔ f = C r := by rw [← expand_C, expand_inj hp, expand_C] theorem nat_degree_expand (p : β„•) (f : polynomial R) : (expand R p f).nat_degree = f.nat_degree * p := begin cases p.eq_zero_or_pos with hp hp, { rw [hp, coe_expand, pow_zero, mul_zero, ← C_1, evalβ‚‚_hom, nat_degree_C] }, by_cases hf : f = 0, { rw [hf, alg_hom.map_zero, nat_degree_zero, zero_mul] }, have hf1 : expand R p f β‰  0 := mt (expand_eq_zero hp).1 hf, rw [← with_bot.coe_eq_coe, ← degree_eq_nat_degree hf1], refine le_antisymm ((degree_le_iff_coeff_zero _ _).2 $ Ξ» n hn, _) _, { rw coeff_expand hp, split_ifs with hpn, { rw coeff_eq_zero_of_nat_degree_lt, contrapose! hn, rw [with_bot.coe_le_coe, ← nat.div_mul_cancel hpn], exact nat.mul_le_mul_right p hn }, { refl } }, { refine le_degree_of_ne_zero _, rw [coeff_expand_mul hp, ← leading_coeff], exact mt leading_coeff_eq_zero.1 hf } end end comm_semiring section comm_ring variables {R : Type u} [comm_ring R] lemma separable.mul {f g : polynomial R} (hf : f.separable) (hg : g.separable) (h : is_coprime f g) : (f * g).separable := by { rw [separable_def, derivative_mul], exact ((hf.mul_right h).add_mul_left_right _).mul_left ((h.symm.mul_right hg).mul_add_right_right _) } end comm_ring section integral_domain variables (R : Type u) [integral_domain R] theorem is_local_ring_hom_expand {p : β„•} (hp : 0 < p) : is_local_ring_hom (↑(expand R p) : polynomial R β†’+* polynomial R) := begin refine ⟨λ f hf1, _⟩, rw ← coe_fn_coe_base at hf1, have hf2 := eq_C_of_degree_eq_zero (degree_eq_zero_of_is_unit hf1), rw [coeff_expand hp, if_pos (dvd_zero _), p.zero_div] at hf2, rw [hf2, is_unit_C] at hf1, rw expand_eq_C hp at hf2, rwa [hf2, is_unit_C] end end integral_domain section field variables {F : Type u} [field F] theorem separable_iff_derivative_ne_zero {f : polynomial F} (hf : irreducible f) : f.separable ↔ f.derivative β‰  0 := ⟨λ h1 h2, hf.1 $ is_coprime_zero_right.1 $ h2 β–Έ h1, Ξ» h, is_coprime_of_dvd (mt and.right h) $ Ξ» g hg1 hg2 ⟨p, hg3⟩ hg4, let ⟨u, hu⟩ := (hf.2 _ _ hg3).resolve_left hg1 in have f ∣ f.derivative, by { conv_lhs { rw [hg3, ← hu] }, rwa mul_unit_dvd_iff }, not_lt_of_le (nat_degree_le_of_dvd this h) $ nat_degree_derivative_lt h⟩ section char_p variables (p : β„•) [hp : fact p.prime] include hp /-- The opposite of `expand`: sends `βˆ‘ aβ‚™ xⁿᡖ` to `βˆ‘ aβ‚™ xⁿ`. -/ noncomputable def contract (f : polynomial F) : polynomial F := ⟨@finset.preimage β„• β„• (*p) f.support $ Ξ» _ _ _ _, (nat.mul_left_inj hp.pos).1, Ξ» n, f.coeff (n * p), Ξ» n, by { rw [finset.mem_preimage, finsupp.mem_support_iff], refl }⟩ theorem coeff_contract (f : polynomial F) (n : β„•) : (contract p f).coeff n = f.coeff (n * p) := rfl theorem of_irreducible_expand {f : polynomial F} (hf : irreducible (expand F p f)) : irreducible f := @@of_irreducible_map _ _ _ (is_local_ring_hom_expand F hp.pos) hf theorem of_irreducible_expand_pow {f : polynomial F} {n : β„•} : irreducible (expand F (p ^ n) f) β†’ irreducible f := nat.rec_on n (Ξ» hf, by rwa [nat.pow_zero, expand_one] at hf) $ Ξ» n ih hf, ih $ of_irreducible_expand p $ by rwa [expand_expand, mul_comm] variables [HF : char_p F p] include HF theorem expand_contract {f : polynomial F} (hf : f.derivative = 0) : expand F p (contract p f) = f := begin ext n, rw [coeff_expand hp.pos, coeff_contract], split_ifs with h, { rw nat.div_mul_cancel h }, { cases n, { exact absurd (dvd_zero p) h }, have := coeff_derivative f n, rw [hf, coeff_zero, zero_eq_mul] at this, cases this, { rw this }, rw [← nat.cast_succ, char_p.cast_eq_zero_iff F p] at this, exact absurd this h } end theorem separable_or {f : polynomial F} (hf : irreducible f) : f.separable ∨ Β¬f.separable ∧ βˆƒ g : polynomial F, irreducible g ∧ expand F p g = f := if H : f.derivative = 0 then or.inr ⟨by rw [separable_iff_derivative_ne_zero hf, not_not, H], contract p f, by haveI := is_local_ring_hom_expand F hp.pos; exact of_irreducible_map ↑(expand F p) (by rwa ← expand_contract p H at hf), expand_contract p H⟩ else or.inl $ (separable_iff_derivative_ne_zero hf).2 H theorem exists_separable_of_irreducible {f : polynomial F} (hf : irreducible f) (hf0 : f β‰  0) : βˆƒ (n : β„•) (g : polynomial F), g.separable ∧ expand F (p ^ n) g = f := begin generalize hn : f.nat_degree = N, unfreezingI { revert f }, apply nat.strong_induction_on N, intros N ih f hf hf0 hn, rcases separable_or p hf with h | ⟨h1, g, hg, hgf⟩, { refine ⟨0, f, h, _⟩, rw [nat.pow_zero, expand_one] }, { cases N with N, { rw [nat_degree_eq_zero_iff_degree_le_zero, degree_le_zero_iff] at hn, rw [hn, separable_C, is_unit_iff_ne_zero, not_not] at h1, rw [h1, C_0] at hn, exact absurd hn hf0 }, have hg1 : g.nat_degree * p = N.succ, { rwa [← nat_degree_expand, hgf] }, have hg2 : g.nat_degree β‰  0, { intro this, rw [this, zero_mul] at hg1, cases hg1 }, have hg3 : g.nat_degree < N.succ, { rw [← mul_one g.nat_degree, ← hg1], exact nat.mul_lt_mul_of_pos_left hp.one_lt (nat.pos_of_ne_zero hg2) }, have hg4 : g β‰  0, { rintro rfl, exact hg2 nat_degree_zero }, rcases ih _ hg3 hg hg4 rfl with ⟨n, g, hg5, rfl⟩, refine ⟨n+1, g, hg5, _⟩, rw [← hgf, expand_expand, nat.pow_succ, mul_comm] } end theorem is_unit_or_eq_zero_of_separable_expand {f : polynomial F} (n : β„•) (hf : (expand F (p ^ n) f).separable) : is_unit f ∨ n = 0 := begin rw classical.or_iff_not_imp_right, intro hn, have hf2 : (expand F (p ^ n) f).derivative = 0, { by rw [derivative_expand, nat.cast_pow, char_p.cast_eq_zero, zero_pow (nat.pos_of_ne_zero hn), zero_mul, mul_zero] }, rw [separable_def, hf2, is_coprime_zero_right, is_unit_iff] at hf, rcases hf with ⟨r, hr, hrf⟩, rw [eq_comm, expand_eq_C (nat.pow_pos hp.pos _)] at hrf, rwa [hrf, is_unit_C] end theorem unique_separable_of_irreducible {f : polynomial F} (hf : irreducible f) (hf0 : f β‰  0) (n₁ : β„•) (g₁ : polynomial F) (hg₁ : g₁.separable) (hgf₁ : expand F (p ^ n₁) g₁ = f) (nβ‚‚ : β„•) (gβ‚‚ : polynomial F) (hgβ‚‚ : gβ‚‚.separable) (hgfβ‚‚ : expand F (p ^ nβ‚‚) gβ‚‚ = f) : n₁ = nβ‚‚ ∧ g₁ = gβ‚‚ := begin revert g₁ gβ‚‚, wlog hn : n₁ ≀ nβ‚‚ := le_total n₁ nβ‚‚ using [n₁ nβ‚‚, nβ‚‚ n₁] tactic.skip, unfreezingI { intros, rw le_iff_exists_add at hn, rcases hn with ⟨k, rfl⟩, rw [← hgf₁, nat.pow_add, expand_mul, expand_inj (nat.pow_pos hp.pos n₁)] at hgfβ‚‚, subst hgfβ‚‚, subst hgf₁, rcases is_unit_or_eq_zero_of_separable_expand p k hg₁ with h | rfl, { rw is_unit_iff at h, rcases h with ⟨r, hr, rfl⟩, simp_rw expand_C at hf, exact absurd (is_unit_C.2 hr) hf.1 }, { rw [add_zero, nat.pow_zero, expand_one], split; refl } }, exact Ξ» g₁ gβ‚‚ hg₁ hgf₁ hgβ‚‚ hgfβ‚‚, let ⟨hn, hg⟩ := this gβ‚‚ g₁ hgβ‚‚ hgfβ‚‚ hg₁ hgf₁ in ⟨hn.symm, hg.symm⟩ end end char_p end field end polynomial open polynomial theorem irreducible.separable {F : Type u} [field F] [char_zero F] {f : polynomial F} (hf : irreducible f) (hf0 : f β‰  0) : f.separable := begin rw [separable_iff_derivative_ne_zero hf, ne, ← degree_eq_bot, degree_derivative_eq], rintro ⟨⟩, rw [nat.pos_iff_ne_zero, ne, nat_degree_eq_zero_iff_degree_le_zero, degree_le_zero_iff], refine Ξ» hf1, hf.1 _, rw [hf1, is_unit_C, is_unit_iff_ne_zero], intro hf2, rw [hf2, C_0] at hf1, exact absurd hf1 hf0 end
da4ecd51927a6c337a4b4b49cf29a205e9416e49
07c6143268cfb72beccd1cc35735d424ebcb187b
/src/analysis/calculus/extend_deriv.lean
e37a8e4c9b9e90224cbc8870ed94b9e38e31d827
[ "Apache-2.0" ]
permissive
khoek/mathlib
bc49a842910af13a3c372748310e86467d1dc766
aa55f8b50354b3e11ba64792dcb06cccb2d8ee28
refs/heads/master
1,588,232,063,837
1,587,304,803,000
1,587,304,803,000
176,688,517
0
0
Apache-2.0
1,553,070,585,000
1,553,070,585,000
null
UTF-8
Lean
false
false
11,264
lean
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel -/ import analysis.calculus.mean_value import tactic.monotonicity /-! # Extending differentiability to the boundary We investigate how differentiable functions inside a set extend to differentiable functions on the boundary. For this, it suffices that the function and its derivative admit limits there. A general version of this statement is given in `has_fderiv_at_boundary_of_tendsto_fderiv`. One-dimensional versions, in which one wants to obtain differentiability at the left endpoint or the right endpoint of an interval, are given in `has_deriv_at_interval_left_endpoint_of_tendsto_deriv` and `has_deriv_at_interval_right_endpoint_of_tendsto_deriv`. These versions are formulated in terms of the one-dimensional derivative `deriv ℝ f`. -/ set_option class.instance_max_depth 40 variables {E : Type*} [normed_group E] [normed_space ℝ E] {F : Type*} [normed_group F] [normed_space ℝ F] open filter set metric continuous_linear_map open_locale topological_space local attribute [mono] prod_mono /-- If a function `f` is differentiable in a convex open set and continuous on its closure, and its derivative converges to `0` at a point on the boundary, then `f` is differentiable there with derivative `0`. This is an auxiliary statement to prove the same result for any value of the derivative, in `has_fderiv_at_boundary_of_tendsto_fderiv`. -/ theorem has_fderiv_at_boundary_of_tendsto_fderiv_aux {f : E β†’ F} {s : set E} {x : E} (f_diff : differentiable_on ℝ f s) (s_conv : convex s) (s_open : is_open s) (f_cont : βˆ€y ∈ closure s, continuous_within_at f s y) (h : tendsto (Ξ»y, fderiv ℝ f y) (nhds_within x s) (𝓝 0)) : has_fderiv_within_at f (0 : E β†’L[ℝ] F) (closure s) x := begin classical, -- one can assume without loss of generality that `x` belongs to the closure of `s`, as the -- statement is empty otherwise by_cases hx : x βˆ‰ closure s, { rw ← closure_closure at hx, exact has_fderiv_within_at_of_not_mem_closure hx }, push_neg at hx, rw [has_fderiv_within_at, has_fderiv_at_filter, asymptotics.is_o_iff], /- One needs to show that `βˆ₯f y - f xβˆ₯ ≀ Ξ΅ βˆ₯y - xβˆ₯` for `y` close to `x` in `closure s`, where `Ξ΅` is an arbitrary positive constant. By continuity of the functions, it suffices to prove this for nearby points inside `s`. In a neighborhood of `x`, the derivative of `f` is arbitrarily small by assumption. The mean value inequality ensures that `f` is `Ξ΅`-Lipschitz there, concluding the proof. -/ assume Ξ΅ Ξ΅_pos, obtain ⟨δ, Ξ΄_pos, hδ⟩ : βˆƒ Ξ΄ > 0, βˆ€ y ∈ s, dist y x < Ξ΄ β†’ βˆ₯fderiv ℝ f yβˆ₯ < Ξ΅, by simpa [dist_zero_right] using tendsto_nhds_within_nhds.1 h Ξ΅ Ξ΅_pos, set B := ball x Ξ΄, suffices : βˆ€ y ∈ B ∩ (closure s), βˆ₯f y - f xβˆ₯ ≀ Ξ΅ * βˆ₯y - xβˆ₯, from mem_nhds_within_iff.2 ⟨δ, Ξ΄_pos, Ξ»y hy, by simpa using this y hy⟩, suffices : βˆ€ p : E Γ— E, p ∈ closure ((B ∩ s).prod (B ∩ s)) β†’ βˆ₯f p.2 - f p.1βˆ₯ ≀ Ξ΅ * βˆ₯p.2 - p.1βˆ₯, { rw closure_prod_eq at this, intros y y_in, apply this ⟨x, y⟩, have : B ∩ closure s βŠ† closure (B ∩ s), from closure_inter_open is_open_ball, exact ⟨this ⟨mem_ball_self Ξ΄_pos, hx⟩, this y_in⟩ }, have key : βˆ€ p : E Γ— E, p ∈ (B ∩ s).prod (B ∩ s) β†’ βˆ₯f p.2 - f p.1βˆ₯ ≀ Ξ΅ * βˆ₯p.2 - p.1βˆ₯, { rintros ⟨u, v⟩ ⟨u_in, v_in⟩, have conv : convex (B ∩ s) := (convex_ball _ _).inter s_conv, have diff : differentiable_on ℝ f (B ∩ s) := f_diff.mono (inter_subset_right _ _), refine conv.norm_image_sub_le_of_norm_deriv_le diff (Ξ»z z_in, _) u_in v_in, convert le_of_lt (hΞ΄ _ z_in.2 z_in.1), have op : is_open (B ∩ s) := is_open_inter is_open_ball s_open, rw differentiable_at.fderiv_within _ (op.unique_diff_on z z_in), exact (diff z z_in).differentiable_at (mem_nhds_sets op z_in) }, rintros ⟨u, v⟩ uv_in, refine continuous_within_at.closure_le uv_in _ _ key, all_goals { -- common start for both continuity proofs have : (B ∩ s).prod (B ∩ s) βŠ† s.prod s, by mono ; exact inter_subset_right _ _, obtain ⟨u_in, v_in⟩ : u ∈ closure s ∧ v ∈ closure s, by simpa [closure_prod_eq] using closure_mono this uv_in, apply continuous_within_at.mono _ this, simp only [continuous_within_at, nhds_prod_eq] }, { rw nhds_within_prod_eq, exact tendsto.comp continuous_norm.continuous_at ((tendsto.comp (f_cont v v_in) tendsto_snd).sub $ tendsto.comp (f_cont u u_in) tendsto_fst) }, { apply tendsto_nhds_within_of_tendsto_nhds, rw nhds_prod_eq, exact tendsto_const_nhds.mul (tendsto.comp continuous_norm.continuous_at $ tendsto_snd.sub tendsto_fst) }, end /-- If a function `f` is differentiable in a convex open set and continuous on its closure, and its derivative converges to a limit `f'` at a point on the boundary, then `f` is differentiable there with derivative `f'`. -/ theorem has_fderiv_at_boundary_of_tendsto_fderiv {f : E β†’ F} {s : set E} {x : E} {f' : E β†’L[ℝ] F} (f_diff : differentiable_on ℝ f s) (s_conv : convex s) (s_open : is_open s) (f_cont : βˆ€y ∈ closure s, continuous_within_at f s y) (h : tendsto (Ξ»y, fderiv ℝ f y) (nhds_within x s) (𝓝 f')) : has_fderiv_within_at f f' (closure s) x := begin /- We subtract `f'` to define a new function `g` for which `g' = 0`, for which differentiability is proved `has_fderiv_at_boundary_of_differentiable_aux`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g := Ξ»y, f y - f' y, have diff_g : differentiable_on ℝ g s := f_diff.sub (f'.differentiable.comp differentiable_id).differentiable_on, have cont_g : βˆ€y ∈ closure s, continuous_within_at g s y := Ξ»y hy, tendsto.sub (f_cont y hy) (f'.continuous.comp continuous_id).continuous_within_at, have A : βˆ€y ∈ s, fderiv ℝ f y - f' = fderiv ℝ g y, { assume y hy, have : has_fderiv_at f (fderiv ℝ f y) y := (differentiable_within_at.differentiable_at (f_diff y hy) (mem_nhds_sets s_open hy)).has_fderiv_at, have : has_fderiv_at g (fderiv ℝ f y - f') y := this.sub (f'.has_fderiv_at.comp y (has_fderiv_at_id y)), exact this.fderiv.symm }, have B : tendsto (Ξ»y, fderiv ℝ f y - f') (nhds_within x s) (𝓝 (f' - f')) := h.sub tendsto_const_nhds, have : tendsto (Ξ»y, fderiv ℝ g y) (nhds_within x s) (𝓝 0), { have : f' - f' = 0, by simp, rw this at B, apply tendsto.congr' _ B, filter_upwards [self_mem_nhds_within] A }, have : has_fderiv_within_at g (0 : E β†’L[ℝ] F) (closure s) x := has_fderiv_at_boundary_of_tendsto_fderiv_aux diff_g s_conv s_open cont_g this, convert this.add f'.has_fderiv_within_at, { ext y, simp [g] }, { simp } end /-- If a function is differentiable on the right of a point `a : ℝ`, continuous at `a`, and its derivative also converges at `a`, then `f` is differentiable on the right at `a`. -/ lemma has_deriv_at_interval_left_endpoint_of_tendsto_deriv {s : set ℝ} {e : E} {a : ℝ} {f : ℝ β†’ E} (f_diff : differentiable_on ℝ f s) (f_lim : continuous_within_at f s a) (hs : s ∈ nhds_within a (Ioi a)) (f_lim' : tendsto (Ξ»x, deriv f x) (nhds_within a (Ioi a)) (𝓝 e)) : has_deriv_within_at f e (Ici a) a := begin /- This is a specialization of `has_fderiv_at_boundary_of_tendsto_fderiv`. To be in the setting of this theorem, we need to work on an open interval with closure contained in `s βˆͺ {a}`, that we call `t = (a, b)`. Then, we check all the assumptions of this theorem and we apply it. -/ obtain ⟨b, ab, sab⟩ : βˆƒ b ∈ Ioi a, Ioc a b βŠ† s := mem_nhds_within_Ioi_iff_exists_Ioc_subset.1 hs, let t := Ioo a b, have ts : t βŠ† s := subset.trans Ioo_subset_Ioc_self sab, have t_diff : differentiable_on ℝ f t := f_diff.mono ts, have t_conv : convex t := convex_Ioo a b, have t_open : is_open t := is_open_Ioo, have t_closure : closure t = Icc a b := closure_Ioo ab, have t_cont : βˆ€y ∈ closure t, continuous_within_at f t y, { rw t_closure, assume y hy, by_cases h : y = a, { rw h, exact f_lim.mono ts }, { have : y ∈ s := sab ⟨lt_of_le_of_ne hy.1 (ne.symm h), hy.2⟩, exact (f_diff.continuous_on y this).mono ts } }, have t_diff' : tendsto (Ξ»x, fderiv ℝ f x) (nhds_within a t) (𝓝 (smul_right 1 e)), { simp [deriv_fderiv.symm], refine tendsto.comp is_bounded_bilinear_map_smul_right.continuous_right.continuous_at _, exact tendsto_le_left (nhds_within_mono _ Ioo_subset_Ioi_self) f_lim' }, -- now we can apply `has_fderiv_at_boundary_of_differentiable` have : has_deriv_within_at f e (Icc a b) a, { rw [has_deriv_within_at_iff_has_fderiv_within_at, ← t_closure], exact has_fderiv_at_boundary_of_tendsto_fderiv t_diff t_conv t_open t_cont t_diff' }, exact this.nhds_within (mem_nhds_within_Ici_iff_exists_Icc_subset.2 ⟨b, ab, subset.refl _⟩) end /-- If a function is differentiable on the left of a point `a : ℝ`, continuous at `a`, and its derivative also converges at `a`, then `f` is differentiable on the left at `a`. -/ lemma has_fderiv_at_interval_right_endpoint_of_tendsto_deriv {s : set ℝ} {e : E} {a : ℝ} {f : ℝ β†’ E} (f_diff : differentiable_on ℝ f s) (f_lim : continuous_within_at f s a) (hs : s ∈ nhds_within a (Iio a)) (f_lim' : tendsto (Ξ»x, deriv f x) (nhds_within a (Iio a)) (𝓝 e)) : has_deriv_within_at f e (Iic a) a := begin /- This is a specialization of `has_fderiv_at_boundary_of_differentiable`. To be in the setting of this theorem, we need to work on an open interval with closure contained in `s βˆͺ {a}`, that we call `t = (b, a)`. Then, we check all the assumptions of this theorem and we apply it. -/ obtain ⟨b, ba, sab⟩ : βˆƒ b ∈ Iio a, Ico b a βŠ† s := mem_nhds_within_Iio_iff_exists_Ico_subset.1 hs, let t := Ioo b a, have ts : t βŠ† s := subset.trans Ioo_subset_Ico_self sab, have t_diff : differentiable_on ℝ f t := f_diff.mono ts, have t_conv : convex t := convex_Ioo b a, have t_open : is_open t := is_open_Ioo, have t_closure : closure t = Icc b a := closure_Ioo ba, have t_cont : βˆ€y ∈ closure t, continuous_within_at f t y, { rw t_closure, assume y hy, by_cases h : y = a, { rw h, exact f_lim.mono ts }, { have : y ∈ s := sab ⟨hy.1, lt_of_le_of_ne hy.2 h⟩, exact (f_diff.continuous_on y this).mono ts } }, have t_diff' : tendsto (Ξ»x, fderiv ℝ f x) (nhds_within a t) (𝓝 (smul_right 1 e)), { simp [deriv_fderiv.symm], refine tendsto.comp is_bounded_bilinear_map_smul_right.continuous_right.continuous_at _, exact tendsto_le_left (nhds_within_mono _ Ioo_subset_Iio_self) f_lim' }, -- now we can apply `has_fderiv_at_boundary_of_differentiable` have : has_deriv_within_at f e (Icc b a) a, { rw [has_deriv_within_at_iff_has_fderiv_within_at, ← t_closure], exact has_fderiv_at_boundary_of_tendsto_fderiv t_diff t_conv t_open t_cont t_diff' }, exact this.nhds_within (mem_nhds_within_Iic_iff_exists_Icc_subset.2 ⟨b, ba, subset.refl _⟩) end
c44f30a494c479018b441e1bdbfc4cb29ca34f6e
618003631150032a5676f229d13a079ac875ff77
/src/category_theory/punit.lean
d94c3120d1ea117b505f8c1513cee4cc99779f51
[ "Apache-2.0" ]
permissive
awainverse/mathlib
939b68c8486df66cfda64d327ad3d9165248c777
ea76bd8f3ca0a8bf0a166a06a475b10663dec44a
refs/heads/master
1,659,592,962,036
1,590,987,592,000
1,590,987,592,000
268,436,019
1
0
Apache-2.0
1,590,990,500,000
1,590,990,500,000
null
UTF-8
Lean
false
false
737
lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import category_theory.const universes v w u -- declare the `v`'s first; see `category_theory.category` for an explanation namespace category_theory instance punit_category : small_category punit := { hom := Ξ» X Y, punit, id := Ξ» _, punit.star, comp := Ξ» _ _ _ _ _, punit.star } namespace functor variables {C : Type u} [category.{v} C] def star : C β₯€ punit.{w+1} := (const C).obj punit.star @[simp] lemma star_obj (X : C) : star.obj X = punit.star := rfl @[simp] lemma star_map {X Y : C} (f : X ⟢ Y) : star.map f = πŸ™ _ := rfl end functor end category_theory
5d7b6b90f55307baaca2220b409e06e63d223588
4727251e0cd73359b15b664c3170e5d754078599
/src/algebra/category/Module/projective.lean
b7f632b8df1c94f4db8534f4301264ff2144dbc9
[ "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
2,164
lean
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Scott Morrison -/ import algebra.category.Module.epi_mono import algebra.module.projective import category_theory.preadditive.projective import linear_algebra.finsupp_vector_space /-! # The category of `R`-modules has enough projectives. -/ universes v u open category_theory open category_theory.limits open linear_map open_locale Module /-- The categorical notion of projective object agrees with the explicit module-theoretic notion. -/ theorem is_projective.iff_projective {R : Type u} [ring R] {P : Type (max u v)} [add_comm_group P] [module R P] : module.projective R P ↔ projective (Module.of R P) := begin refine ⟨λ h, _, Ξ» h, _⟩, { letI : module.projective R β†₯(Module.of R P) := h, exact ⟨λ E X f e epi, module.projective_lifting_property _ _ ((Module.epi_iff_surjective _).mp epi)⟩ }, { refine module.projective_of_lifting_property _, introsI E X mE mX sE sX f g s, haveI : epi β†Ÿf := (Module.epi_iff_surjective β†Ÿf).mpr s, letI : projective (Module.of R P) := h, exact ⟨projective.factor_thru β†Ÿg β†Ÿf, projective.factor_thru_comp β†Ÿg β†Ÿf⟩ } end namespace Module variables {R : Type u} [ring R] {M : Module.{(max u v)} R} /-- Modules that have a basis are projective. -/ -- We transport the corresponding result from `module.projective`. lemma projective_of_free {ΞΉ : Type*} (b : basis ΞΉ R M) : projective M := projective.of_iso (Module.of_self_iso _) ((is_projective.iff_projective).mp (module.projective_of_basis b)) /-- The category of modules has enough projectives, since every module is a quotient of a free module. -/ instance Module_enough_projectives : enough_projectives (Module.{max u v} R) := { presentation := Ξ» M, ⟨{ P := Module.of R (M β†’β‚€ R), projective := projective_of_free finsupp.basis_single_one, f := finsupp.basis_single_one.constr β„• id, epi := (epi_iff_range_eq_top _).mpr (range_eq_top.2 (Ξ» m, ⟨finsupp.single m (1 : R), by simp [basis.constr]⟩)) }⟩, } end Module
e690968925ff86510be674d36ff950c17b1e3ac2
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/geometry/manifold/charted_space.lean
f34b98310e7c7131a0696e2456c136bce7a6d53b
[]
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
37,880
lean
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.topology.local_homeomorph import Mathlib.PostPort universes u l u_5 u_1 u_6 u_2 u_3 u_4 namespace Mathlib /-! # Charted spaces A smooth manifold is a topological space `M` locally modelled on a euclidean space (or a euclidean half-space for manifolds with boundaries, or an infinite dimensional vector space for more general notions of manifolds), i.e., the manifold is covered by open subsets on which there are local homeomorphisms (the charts) going to a model space `H`, and the changes of charts should be smooth maps. In this file, we introduce a general framework describing these notions, where the model space is an arbitrary topological space. We avoid the word *manifold*, which should be reserved for the situation where the model space is a (subset of a) vector space, and use the terminology *charted space* instead. If the changes of charts satisfy some additional property (for instance if they are smooth), then `M` inherits additional structure (it makes sense to talk about smooth manifolds). There are therefore two different ingredients in a charted space: * the set of charts, which is data * the fact that changes of charts belong to some group (in fact groupoid), which is additional Prop. We separate these two parts in the definition: the charted space structure is just the set of charts, and then the different smoothness requirements (smooth manifold, orientable manifold, contact manifold, and so on) are additional properties of these charts. These properties are formalized through the notion of structure groupoid, i.e., a set of local homeomorphisms stable under composition and inverse, to which the change of coordinates should belong. ## Main definitions * `structure_groupoid H` : a subset of local homeomorphisms of `H` stable under composition, inverse and restriction (ex: local diffeos). * `continuous_groupoid H` : the groupoid of all local homeomorphisms of `H` * `charted_space H M` : charted space structure on `M` modelled on `H`, given by an atlas of local homeomorphisms from `M` to `H` whose sources cover `M`. This is a type class. * `has_groupoid M G` : when `G` is a structure groupoid on `H` and `M` is a charted space modelled on `H`, require that all coordinate changes belong to `G`. This is a type class. * `atlas H M` : when `M` is a charted space modelled on `H`, the atlas of this charted space structure, i.e., the set of charts. * `G.maximal_atlas M` : when `M` is a charted space modelled on `H` and admitting `G` as a structure groupoid, one can consider all the local homeomorphisms from `M` to `H` such that changing coordinate from any chart to them belongs to `G`. This is a larger atlas, called the maximal atlas (for the groupoid `G`). * `structomorph G M M'` : the type of diffeomorphisms between the charted spaces `M` and `M'` for the groupoid `G`. We avoid the word diffeomorphism, keeping it for the smooth category. As a basic example, we give the instance `instance charted_space_model_space (H : Type*) [topological_space H] : charted_space H H` saying that a topological space is a charted space over itself, with the identity as unique chart. This charted space structure is compatible with any groupoid. Additional useful definitions: * `pregroupoid H` : a subset of local mas of `H` stable under composition and restriction, but not inverse (ex: smooth maps) * `groupoid_of_pregroupoid` : construct a groupoid from a pregroupoid, by requiring that a map and its inverse both belong to the pregroupoid (ex: construct diffeos from smooth maps) * `chart_at H x` is a preferred chart at `x : M` when `M` has a charted space structure modelled on `H`. * `G.compatible he he'` states that, for any two charts `e` and `e'` in the atlas, the composition of `e.symm` and `e'` belongs to the groupoid `G` when `M` admits `G` as a structure groupoid. * `G.compatible_of_mem_maximal_atlas he he'` states that, for any two charts `e` and `e'` in the maximal atlas associated to the groupoid `G`, the composition of `e.symm` and `e'` belongs to the `G` if `M` admits `G` as a structure groupoid. * `charted_space_core.to_charted_space`: consider a space without a topology, but endowed with a set of charts (which are local equivs) for which the change of coordinates are local homeos. Then one can construct a topology on the space for which the charts become local homeos, defining a genuine charted space structure. ## Implementation notes The atlas in a charted space is *not* a maximal atlas in general: the notion of maximality depends on the groupoid one considers, and changing groupoids changes the maximal atlas. With the current formalization, it makes sense first to choose the atlas, and then to ask whether this precise atlas defines a smooth manifold, an orientable manifold, and so on. A consequence is that structomorphisms between `M` and `M'` do *not* induce a bijection between the atlases of `M` and `M'`: the definition is only that, read in charts, the structomorphism locally belongs to the groupoid under consideration. (This is equivalent to inducing a bijection between elements of the maximal atlas). A consequence is that the invariance under structomorphisms of properties defined in terms of the atlas is not obvious in general, and could require some work in theory (amounting to the fact that these properties only depend on the maximal atlas, for instance). In practice, this does not create any real difficulty. We use the letter `H` for the model space thinking of the case of manifolds with boundary, where the model space is a half space. Manifolds are sometimes defined as topological spaces with an atlas of local diffeomorphisms, and sometimes as spaces with an atlas from which a topology is deduced. We use the former approach: otherwise, there would be an instance from manifolds to topological spaces, which means that any instance search for topological spaces would try to find manifold structures involving a yet unknown model space, leading to problems. However, we also introduce the latter approach, through a structure `charted_space_core` making it possible to construct a topology out of a set of local equivs with compatibility conditions (but we do not register it as an instance). In the definition of a charted space, the model space is written as an explicit parameter as there can be several model spaces for a given topological space. For instance, a complex manifold (modelled over `β„‚^n`) will also be seen sometimes as a real manifold modelled over `ℝ^(2n)`. ## Notations In the locale `manifold`, we denote the composition of local homeomorphisms with `≫ₕ`, and the composition of local equivs with `≫`. -/ /- Notational shortcut for the composition of local homeomorphisms and local equivs, i.e., `local_homeomorph.trans` and `local_equiv.trans`. Note that, as is usual for equivs, the composition is from left to right, hence the direction of the arrow. -/ /- `simp` looks for subsingleton instances at every call. This turns out to be very inefficient, especially in `simp`-heavy parts of the library such as the manifold code. Disable two such instances to speed up things. NB: this is just a hack. TODO: fix `simp` properly. -/ /-! ### Structure groupoids-/ /-! One could add to the definition of a structure groupoid the fact that the restriction of an element of the groupoid to any open set still belongs to the groupoid. (This is in Kobayashi-Nomizu.) I am not sure I want this, for instance on `H Γ— E` where `E` is a vector space, and the groupoid is made of functions respecting the fibers and linear in the fibers (so that a charted space over this groupoid is naturally a vector bundle) I prefer that the members of the groupoid are always defined on sets of the form `s Γ— E`. There is a typeclass `closed_under_restriction` for groupoids which have the restriction property. The only nontrivial requirement is locality: if a local homeomorphism belongs to the groupoid around each point in its domain of definition, then it belongs to the groupoid. Without this requirement, the composition of structomorphisms does not have to be a structomorphism. Note that this implies that a local homeomorphism with empty source belongs to any structure groupoid, as it trivially satisfies this condition. There is also a technical point, related to the fact that a local homeomorphism is by definition a global map which is a homeomorphism when restricted to its source subset (and its values outside of the source are not relevant). Therefore, we also require that being a member of the groupoid only depends on the values on the source. We use primes in the structure names as we will reformulate them below (without primes) using a `has_mem` instance, writing `e ∈ G` instead of `e ∈ G.members`. -/ /-- A structure groupoid is a set of local homeomorphisms of a topological space stable under composition and inverse. They appear in the definition of the smoothness class of a manifold. -/ structure structure_groupoid (H : Type u) [topological_space H] where members : set (local_homeomorph H H) trans' : βˆ€ (e e' : local_homeomorph H H), e ∈ members β†’ e' ∈ members β†’ local_homeomorph.trans e e' ∈ members symm' : βˆ€ (e : local_homeomorph H H), e ∈ members β†’ local_homeomorph.symm e ∈ members id_mem' : local_homeomorph.refl H ∈ members locality' : βˆ€ (e : local_homeomorph H H), (βˆ€ (x : H), x ∈ local_equiv.source (local_homeomorph.to_local_equiv e) β†’ βˆƒ (s : set H), is_open s ∧ x ∈ s ∧ local_homeomorph.restr e s ∈ members) β†’ e ∈ members eq_on_source' : βˆ€ (e e' : local_homeomorph H H), e ∈ members β†’ e' β‰ˆ e β†’ e' ∈ members protected instance structure_groupoid.has_mem {H : Type u} [topological_space H] : has_mem (local_homeomorph H H) (structure_groupoid H) := has_mem.mk fun (e : local_homeomorph H H) (G : structure_groupoid H) => e ∈ structure_groupoid.members G theorem structure_groupoid.trans {H : Type u} [topological_space H] (G : structure_groupoid H) {e : local_homeomorph H H} {e' : local_homeomorph H H} (he : e ∈ G) (he' : e' ∈ G) : local_homeomorph.trans e e' ∈ G := structure_groupoid.trans' G e e' he he' theorem structure_groupoid.symm {H : Type u} [topological_space H] (G : structure_groupoid H) {e : local_homeomorph H H} (he : e ∈ G) : local_homeomorph.symm e ∈ G := structure_groupoid.symm' G e he theorem structure_groupoid.id_mem {H : Type u} [topological_space H] (G : structure_groupoid H) : local_homeomorph.refl H ∈ G := structure_groupoid.id_mem' G theorem structure_groupoid.locality {H : Type u} [topological_space H] (G : structure_groupoid H) {e : local_homeomorph H H} (h : βˆ€ (x : H), x ∈ local_equiv.source (local_homeomorph.to_local_equiv e) β†’ βˆƒ (s : set H), is_open s ∧ x ∈ s ∧ local_homeomorph.restr e s ∈ G) : e ∈ G := structure_groupoid.locality' G e h theorem structure_groupoid.eq_on_source {H : Type u} [topological_space H] (G : structure_groupoid H) {e : local_homeomorph H H} {e' : local_homeomorph H H} (he : e ∈ G) (h : e' β‰ˆ e) : e' ∈ G := structure_groupoid.eq_on_source' G e e' he h /-- Partial order on the set of groupoids, given by inclusion of the members of the groupoid -/ protected instance structure_groupoid.partial_order {H : Type u} [topological_space H] : partial_order (structure_groupoid H) := partial_order.lift structure_groupoid.members sorry theorem structure_groupoid.le_iff {H : Type u} [topological_space H] {G₁ : structure_groupoid H} {Gβ‚‚ : structure_groupoid H} : G₁ ≀ Gβ‚‚ ↔ βˆ€ (e : local_homeomorph H H), e ∈ G₁ β†’ e ∈ Gβ‚‚ := iff.rfl /-- The trivial groupoid, containing only the identity (and maps with empty source, as this is necessary from the definition) -/ def id_groupoid (H : Type u) [topological_space H] : structure_groupoid H := structure_groupoid.mk (singleton (local_homeomorph.refl H) βˆͺ set_of fun (e : local_homeomorph H H) => local_equiv.source (local_homeomorph.to_local_equiv e) = βˆ…) sorry sorry sorry sorry sorry /-- Every structure groupoid contains the identity groupoid -/ protected instance structure_groupoid.order_bot {H : Type u} [topological_space H] : order_bot (structure_groupoid H) := order_bot.mk (id_groupoid H) partial_order.le partial_order.lt sorry sorry sorry sorry protected instance structure_groupoid.inhabited (H : Type u) [topological_space H] : Inhabited (structure_groupoid H) := { default := id_groupoid H } /-- To construct a groupoid, one may consider classes of local homeos such that both the function and its inverse have some property. If this property is stable under composition, one gets a groupoid. `pregroupoid` bundles the properties needed for this construction, with the groupoid of smooth functions with smooth inverses as an application. -/ structure pregroupoid (H : Type u_5) [topological_space H] where property : (H β†’ H) β†’ set H β†’ Prop comp : βˆ€ {f g : H β†’ H} {u v : set H}, property f u β†’ property g v β†’ is_open u β†’ is_open v β†’ is_open (u ∩ f ⁻¹' v) β†’ property (g ∘ f) (u ∩ f ⁻¹' v) id_mem : property id set.univ locality : βˆ€ {f : H β†’ H} {u : set H}, is_open u β†’ (βˆ€ (x : H), x ∈ u β†’ βˆƒ (v : set H), is_open v ∧ x ∈ v ∧ property f (u ∩ v)) β†’ property f u congr : βˆ€ {f g : H β†’ H} {u : set H}, is_open u β†’ (βˆ€ (x : H), x ∈ u β†’ g x = f x) β†’ property f u β†’ property g u /-- Construct a groupoid of local homeos for which the map and its inverse have some property, from a pregroupoid asserting that this property is stable under composition. -/ def pregroupoid.groupoid {H : Type u} [topological_space H] (PG : pregroupoid H) : structure_groupoid H := structure_groupoid.mk (set_of fun (e : local_homeomorph H H) => pregroupoid.property PG (⇑e) (local_equiv.source (local_homeomorph.to_local_equiv e)) ∧ pregroupoid.property PG (⇑(local_homeomorph.symm e)) (local_equiv.target (local_homeomorph.to_local_equiv e))) sorry sorry sorry sorry sorry theorem mem_groupoid_of_pregroupoid {H : Type u} [topological_space H] {PG : pregroupoid H} {e : local_homeomorph H H} : e ∈ pregroupoid.groupoid PG ↔ pregroupoid.property PG (⇑e) (local_equiv.source (local_homeomorph.to_local_equiv e)) ∧ pregroupoid.property PG (⇑(local_homeomorph.symm e)) (local_equiv.target (local_homeomorph.to_local_equiv e)) := iff.rfl theorem groupoid_of_pregroupoid_le {H : Type u} [topological_space H] (PG₁ : pregroupoid H) (PGβ‚‚ : pregroupoid H) (h : βˆ€ (f : H β†’ H) (s : set H), pregroupoid.property PG₁ f s β†’ pregroupoid.property PGβ‚‚ f s) : pregroupoid.groupoid PG₁ ≀ pregroupoid.groupoid PGβ‚‚ := sorry theorem mem_pregroupoid_of_eq_on_source {H : Type u} [topological_space H] (PG : pregroupoid H) {e : local_homeomorph H H} {e' : local_homeomorph H H} (he' : e β‰ˆ e') (he : pregroupoid.property PG (⇑e) (local_equiv.source (local_homeomorph.to_local_equiv e))) : pregroupoid.property PG (⇑e') (local_equiv.source (local_homeomorph.to_local_equiv e')) := sorry /-- The pregroupoid of all local maps on a topological space `H` -/ def continuous_pregroupoid (H : Type u_1) [topological_space H] : pregroupoid H := pregroupoid.mk (fun (f : H β†’ H) (s : set H) => True) sorry trivial sorry sorry protected instance pregroupoid.inhabited (H : Type u_1) [topological_space H] : Inhabited (pregroupoid H) := { default := continuous_pregroupoid H } /-- The groupoid of all local homeomorphisms on a topological space `H` -/ def continuous_groupoid (H : Type u_1) [topological_space H] : structure_groupoid H := pregroupoid.groupoid (continuous_pregroupoid H) /-- Every structure groupoid is contained in the groupoid of all local homeomorphisms -/ protected instance structure_groupoid.order_top {H : Type u} [topological_space H] : order_top (structure_groupoid H) := order_top.mk (continuous_groupoid H) partial_order.le partial_order.lt sorry sorry sorry sorry /-- A groupoid is closed under restriction if it contains all restrictions of its element local homeomorphisms to open subsets of the source. -/ class closed_under_restriction {H : Type u} [topological_space H] (G : structure_groupoid H) where closed_under_restriction : βˆ€ {e : local_homeomorph H H}, e ∈ G β†’ βˆ€ (s : set H), is_open s β†’ local_homeomorph.restr e s ∈ G theorem closed_under_restriction' {H : Type u} [topological_space H] {G : structure_groupoid H} [closed_under_restriction G] {e : local_homeomorph H H} (he : e ∈ G) {s : set H} (hs : is_open s) : local_homeomorph.restr e s ∈ G := closed_under_restriction.closed_under_restriction he s hs /-- The trivial restriction-closed groupoid, containing only local homeomorphisms equivalent to the restriction of the identity to the various open subsets. -/ def id_restr_groupoid {H : Type u} [topological_space H] : structure_groupoid H := structure_groupoid.mk (set_of fun (e : local_homeomorph H H) => Exists fun {s : set H} => βˆƒ (h : is_open s), e β‰ˆ local_homeomorph.of_set s h) sorry sorry sorry sorry sorry theorem id_restr_groupoid_mem {H : Type u} [topological_space H] {s : set H} (hs : is_open s) : local_homeomorph.of_set s hs ∈ id_restr_groupoid := Exists.intro s (Exists.intro hs (setoid.refl (local_homeomorph.of_set s hs))) /-- The trivial restriction-closed groupoid is indeed `closed_under_restriction`. -/ protected instance closed_under_restriction_id_restr_groupoid {H : Type u} [topological_space H] : closed_under_restriction id_restr_groupoid := sorry /-- A groupoid is closed under restriction if and only if it contains the trivial restriction-closed groupoid. -/ theorem closed_under_restriction_iff_id_le {H : Type u} [topological_space H] (G : structure_groupoid H) : closed_under_restriction G ↔ id_restr_groupoid ≀ G := sorry /-- The groupoid of all local homeomorphisms on a topological space `H` is closed under restriction. -/ protected instance continuous_groupoid.closed_under_restriction {H : Type u} [topological_space H] : closed_under_restriction (continuous_groupoid H) := iff.mpr (closed_under_restriction_iff_id_le (continuous_groupoid H)) (eq.mpr ((fun (αΎ° αΎ°_1 : structure_groupoid H) (e_2 : αΎ° = αΎ°_1) (αΎ°_2 αΎ°_3 : structure_groupoid H) (e_3 : αΎ°_2 = αΎ°_3) => congr (congr_arg LessEq e_2) e_3) id_restr_groupoid id_restr_groupoid (Eq.refl id_restr_groupoid) (continuous_groupoid H) ⊀ (Eq.refl (continuous_groupoid H))) le_top) /-! ### Charted spaces -/ /-- A charted space is a topological space endowed with an atlas, i.e., a set of local homeomorphisms taking value in a model space `H`, called charts, such that the domains of the charts cover the whole space. We express the covering property by chosing for each `x` a member `chart_at H x` of the atlas containing `x` in its source: in the smooth case, this is convenient to construct the tangent bundle in an efficient way. The model space is written as an explicit parameter as there can be several model spaces for a given topological space. For instance, a complex manifold (modelled over `β„‚^n`) will also be seen sometimes as a real manifold over `ℝ^(2n)`. -/ class charted_space (H : Type u_5) [topological_space H] (M : Type u_6) [topological_space M] where atlas : set (local_homeomorph M H) chart_at : M β†’ local_homeomorph M H mem_chart_source : βˆ€ (x : M), x ∈ local_equiv.source (local_homeomorph.to_local_equiv (chart_at x)) chart_mem_atlas : βˆ€ (x : M), chart_at x ∈ atlas /-- Any space is a charted_space modelled over itself, by just using the identity chart -/ protected instance charted_space_self (H : Type u_1) [topological_space H] : charted_space H H := charted_space.mk (singleton (local_homeomorph.refl H)) (fun (x : H) => local_homeomorph.refl H) sorry sorry /-- In the trivial charted_space structure of a space modelled over itself through the identity, the atlas members are just the identity -/ @[simp] theorem charted_space_self_atlas {H : Type u_1} [topological_space H] {e : local_homeomorph H H} : e ∈ charted_space.atlas H H ↔ e = local_homeomorph.refl H := sorry /-- In the model space, chart_at is always the identity -/ @[simp] theorem chart_at_self_eq {H : Type u_1} [topological_space H] {x : H} : charted_space.chart_at H x = local_homeomorph.refl H := eq.mpr (id (Eq.refl (charted_space.chart_at H x = local_homeomorph.refl H))) (eq.mp (propext charted_space_self_atlas) (charted_space.chart_mem_atlas H x)) /-- Same thing as `H Γ— H'`. We introduce it for technical reasons: a charted space `M` with model `H` is a set of local charts from `M` to `H` covering the space. Every space is registered as a charted space over itself, using the only chart `id`, in `manifold_model_space`. You can also define a product of charted space `M` and `M'` (with model space `H Γ— H'`) by taking the products of the charts. Now, on `H Γ— H'`, there are two charted space structures with model space `H Γ— H'` itself, the one coming from `manifold_model_space`, and the one coming from the product of the two `manifold_model_space` on each component. They are equal, but not defeq (because the product of `id` and `id` is not defeq to `id`), which is bad as we know. This expedient of renaming `H Γ— H'` solves this problem. -/ def model_prod (H : Type u_1) (H' : Type u_2) := H Γ— H' protected instance model_prod_inhabited {Ξ± : Type u_1} {Ξ² : Type u_2} [Inhabited Ξ±] [Inhabited Ξ²] : Inhabited (model_prod Ξ± Ξ²) := { default := (Inhabited.default, Inhabited.default) } protected instance model_prod.topological_space (H : Type u_1) [topological_space H] (H' : Type u_2) [topological_space H'] : topological_space (model_prod H H') := prod.topological_space /- Next lemma shows up often when dealing with derivatives, register it as simp. -/ @[simp] theorem model_prod_range_prod_id {H : Type u_1} {H' : Type u_2} {Ξ± : Type u_3} (f : H β†’ Ξ±) : (set.range fun (p : model_prod H H') => (f (prod.fst p), prod.snd p)) = set.prod (set.range f) set.univ := sorry /-- The product of two charted spaces is naturally a charted space, with the canonical construction of the atlas of product maps. -/ protected instance prod_charted_space (H : Type u_1) [topological_space H] (M : Type u_2) [topological_space M] [charted_space H M] (H' : Type u_3) [topological_space H'] (M' : Type u_4) [topological_space M'] [charted_space H' M'] : charted_space (model_prod H H') (M Γ— M') := charted_space.mk (set_of fun (f : local_homeomorph (M Γ— M') (model_prod H H')) => βˆƒ (g : local_homeomorph M H), βˆƒ (H_1 : g ∈ charted_space.atlas H M), βˆƒ (h : local_homeomorph M' H'), βˆƒ (H_2 : h ∈ charted_space.atlas H' M'), f = local_homeomorph.prod g h) (fun (x : M Γ— M') => local_homeomorph.prod (charted_space.chart_at H (prod.fst x)) (charted_space.chart_at H' (prod.snd x))) sorry sorry @[simp] theorem prod_charted_space_chart_at {H : Type u} {H' : Type u_1} {M : Type u_2} {M' : Type u_3} [topological_space H] [topological_space M] [charted_space H M] [topological_space H'] [topological_space M'] [charted_space H' M'] {x : M Γ— M'} : charted_space.chart_at (model_prod H H') x = local_homeomorph.prod (charted_space.chart_at H (prod.fst x)) (charted_space.chart_at H' (prod.snd x)) := rfl /-! ### Constructing a topology from an atlas -/ /-- Sometimes, one may want to construct a charted space structure on a space which does not yet have a topological structure, where the topology would come from the charts. For this, one needs charts that are only local equivs, and continuity properties for their composition. This is formalised in `charted_space_core`. -/ structure charted_space_core (H : Type u_5) [topological_space H] (M : Type u_6) where atlas : set (local_equiv M H) chart_at : M β†’ local_equiv M H mem_chart_source : βˆ€ (x : M), x ∈ local_equiv.source (chart_at x) chart_mem_atlas : βˆ€ (x : M), chart_at x ∈ atlas open_source : βˆ€ (e e' : local_equiv M H), e ∈ atlas β†’ e' ∈ atlas β†’ is_open (local_equiv.source (local_equiv.trans (local_equiv.symm e) e')) continuous_to_fun : βˆ€ (e e' : local_equiv M H), e ∈ atlas β†’ e' ∈ atlas β†’ continuous_on (⇑(local_equiv.trans (local_equiv.symm e) e')) (local_equiv.source (local_equiv.trans (local_equiv.symm e) e')) namespace charted_space_core /-- Topology generated by a set of charts on a Type. -/ protected def to_topological_space {H : Type u} {M : Type u_2} [topological_space H] (c : charted_space_core H M) : topological_space M := topological_space.generate_from (set.Union fun (e : local_equiv M H) => set.Union fun (he : e ∈ atlas c) => set.Union fun (s : set H) => set.Union fun (s_open : is_open s) => singleton (⇑e ⁻¹' s ∩ local_equiv.source e)) theorem open_source' {H : Type u} {M : Type u_2} [topological_space H] (c : charted_space_core H M) {e : local_equiv M H} (he : e ∈ atlas c) : is_open (local_equiv.source e) := sorry theorem open_target {H : Type u} {M : Type u_2} [topological_space H] (c : charted_space_core H M) {e : local_equiv M H} (he : e ∈ atlas c) : is_open (local_equiv.target e) := sorry /-- An element of the atlas in a charted space without topology becomes a local homeomorphism for the topology constructed from this atlas. The `local_homeomorph` version is given in this definition. -/ def local_homeomorph {H : Type u} {M : Type u_2} [topological_space H] (c : charted_space_core H M) (e : local_equiv M H) (he : e ∈ atlas c) : local_homeomorph M H := local_homeomorph.mk (local_equiv.mk (local_equiv.to_fun e) (local_equiv.inv_fun e) (local_equiv.source e) (local_equiv.target e) (local_equiv.map_source' e) (local_equiv.map_target' e) (local_equiv.left_inv' e) (local_equiv.right_inv' e)) sorry sorry sorry sorry /-- Given a charted space without topology, endow it with a genuine charted space structure with respect to the topology constructed from the atlas. -/ def to_charted_space {H : Type u} {M : Type u_2} [topological_space H] (c : charted_space_core H M) : charted_space H M := charted_space.mk (set.Union fun (e : local_equiv M H) => set.Union fun (he : e ∈ atlas c) => singleton (local_homeomorph c e he)) (fun (x : M) => local_homeomorph c (chart_at c x) (chart_mem_atlas c x)) sorry sorry end charted_space_core /-! ### Charted space with a given structure groupoid -/ /-- A charted space has an atlas in a groupoid `G` if the change of coordinates belong to the groupoid -/ class has_groupoid {H : Type u_5} [topological_space H] (M : Type u_6) [topological_space M] [charted_space H M] (G : structure_groupoid H) where compatible : βˆ€ {e e' : local_homeomorph M H}, e ∈ charted_space.atlas H M β†’ e' ∈ charted_space.atlas H M β†’ local_homeomorph.trans (local_homeomorph.symm e) e' ∈ G /-- Reformulate in the `structure_groupoid` namespace the compatibility condition of charts in a charted space admitting a structure groupoid, to make it more easily accessible with dot notation. -/ theorem structure_groupoid.compatible {H : Type u_1} [topological_space H] (G : structure_groupoid H) {M : Type u_2} [topological_space M] [charted_space H M] [has_groupoid M G] {e : local_homeomorph M H} {e' : local_homeomorph M H} (he : e ∈ charted_space.atlas H M) (he' : e' ∈ charted_space.atlas H M) : local_homeomorph.trans (local_homeomorph.symm e) e' ∈ G := has_groupoid.compatible G he he' theorem has_groupoid_of_le {H : Type u} {M : Type u_2} [topological_space H] [topological_space M] [charted_space H M] {G₁ : structure_groupoid H} {Gβ‚‚ : structure_groupoid H} (h : has_groupoid M G₁) (hle : G₁ ≀ Gβ‚‚) : has_groupoid M Gβ‚‚ := has_groupoid.mk fun (e e' : local_homeomorph M H) (he : e ∈ charted_space.atlas H M) (he' : e' ∈ charted_space.atlas H M) => hle (has_groupoid.compatible G₁ he he') theorem has_groupoid_of_pregroupoid {H : Type u} {M : Type u_2} [topological_space H] [topological_space M] [charted_space H M] (PG : pregroupoid H) (h : βˆ€ {e e' : local_homeomorph M H}, e ∈ charted_space.atlas H M β†’ e' ∈ charted_space.atlas H M β†’ pregroupoid.property PG (⇑(local_homeomorph.trans (local_homeomorph.symm e) e')) (local_equiv.source (local_homeomorph.to_local_equiv (local_homeomorph.trans (local_homeomorph.symm e) e')))) : has_groupoid M (pregroupoid.groupoid PG) := has_groupoid.mk fun (e e' : local_homeomorph M H) (he : e ∈ charted_space.atlas H M) (he' : e' ∈ charted_space.atlas H M) => iff.mpr mem_groupoid_of_pregroupoid { left := h he he', right := h he' he } /-- The trivial charted space structure on the model space is compatible with any groupoid -/ protected instance has_groupoid_model_space (H : Type u_1) [topological_space H] (G : structure_groupoid H) : has_groupoid H G := sorry /-- Any charted space structure is compatible with the groupoid of all local homeomorphisms -/ protected instance has_groupoid_continuous_groupoid {H : Type u} {M : Type u_2} [topological_space H] [topological_space M] [charted_space H M] : has_groupoid M (continuous_groupoid H) := has_groupoid.mk fun (e e' : local_homeomorph M H) (he : e ∈ charted_space.atlas H M) (he' : e' ∈ charted_space.atlas H M) => eq.mpr (id (Eq._oldrec (Eq.refl (local_homeomorph.trans (local_homeomorph.symm e) e' ∈ continuous_groupoid H)) (continuous_groupoid.equations._eqn_1 H))) (eq.mpr (id (Eq._oldrec (Eq.refl (local_homeomorph.trans (local_homeomorph.symm e) e' ∈ pregroupoid.groupoid (continuous_pregroupoid H))) (propext mem_groupoid_of_pregroupoid))) (eq.mpr (id (propext (and_self True))) trivial)) /-- Given a charted space admitting a structure groupoid, the maximal atlas associated to this structure groupoid is the set of all local charts that are compatible with the atlas, i.e., such that changing coordinates with an atlas member gives an element of the groupoid. -/ def structure_groupoid.maximal_atlas {H : Type u} (M : Type u_2) [topological_space H] [topological_space M] [charted_space H M] (G : structure_groupoid H) : set (local_homeomorph M H) := set_of fun (e : local_homeomorph M H) => βˆ€ (e' : local_homeomorph M H), e' ∈ charted_space.atlas H M β†’ local_homeomorph.trans (local_homeomorph.symm e) e' ∈ G ∧ local_homeomorph.trans (local_homeomorph.symm e') e ∈ G /-- The elements of the atlas belong to the maximal atlas for any structure groupoid -/ theorem structure_groupoid.mem_maximal_atlas_of_mem_atlas {H : Type u} {M : Type u_2} [topological_space H] [topological_space M] [charted_space H M] (G : structure_groupoid H) [has_groupoid M G] {e : local_homeomorph M H} (he : e ∈ charted_space.atlas H M) : e ∈ structure_groupoid.maximal_atlas M G := fun (e' : local_homeomorph M H) (he' : e' ∈ charted_space.atlas H M) => { left := structure_groupoid.compatible G he he', right := structure_groupoid.compatible G he' he } theorem structure_groupoid.chart_mem_maximal_atlas {H : Type u} {M : Type u_2} [topological_space H] [topological_space M] [charted_space H M] (G : structure_groupoid H) [has_groupoid M G] (x : M) : charted_space.chart_at H x ∈ structure_groupoid.maximal_atlas M G := structure_groupoid.mem_maximal_atlas_of_mem_atlas G (charted_space.chart_mem_atlas H x) theorem mem_maximal_atlas_iff {H : Type u} {M : Type u_2} [topological_space H] [topological_space M] [charted_space H M] {G : structure_groupoid H} {e : local_homeomorph M H} : e ∈ structure_groupoid.maximal_atlas M G ↔ βˆ€ (e' : local_homeomorph M H), e' ∈ charted_space.atlas H M β†’ local_homeomorph.trans (local_homeomorph.symm e) e' ∈ G ∧ local_homeomorph.trans (local_homeomorph.symm e') e ∈ G := iff.rfl /-- Changing coordinates between two elements of the maximal atlas gives rise to an element of the structure groupoid. -/ theorem structure_groupoid.compatible_of_mem_maximal_atlas {H : Type u} {M : Type u_2} [topological_space H] [topological_space M] [charted_space H M] {G : structure_groupoid H} {e : local_homeomorph M H} {e' : local_homeomorph M H} (he : e ∈ structure_groupoid.maximal_atlas M G) (he' : e' ∈ structure_groupoid.maximal_atlas M G) : local_homeomorph.trans (local_homeomorph.symm e) e' ∈ G := sorry /-- In the model space, the identity is in any maximal atlas. -/ theorem structure_groupoid.id_mem_maximal_atlas {H : Type u} [topological_space H] (G : structure_groupoid H) : local_homeomorph.refl H ∈ structure_groupoid.maximal_atlas H G := structure_groupoid.mem_maximal_atlas_of_mem_atlas G (eq.mpr (id (Eq.trans (propext charted_space_self_atlas) (propext (eq_self_iff_true (local_homeomorph.refl H))))) trivial) /-- If a single local homeomorphism `e` from a space `Ξ±` into `H` has source covering the whole space `Ξ±`, then that local homeomorphism induces an `H`-charted space structure on `Ξ±`. (This condition is equivalent to `e` being an open embedding of `Ξ±` into `H`; see `local_homeomorph.to_open_embedding` and `open_embedding.to_local_homeomorph`.) -/ def singleton_charted_space {H : Type u} [topological_space H] {Ξ± : Type u_5} [topological_space Ξ±] (e : local_homeomorph Ξ± H) (h : local_equiv.source (local_homeomorph.to_local_equiv e) = set.univ) : charted_space H Ξ± := charted_space.mk (singleton e) (fun (_x : Ξ±) => e) sorry sorry theorem singleton_charted_space_one_chart {H : Type u} [topological_space H] {Ξ± : Type u_5} [topological_space Ξ±] (e : local_homeomorph Ξ± H) (h : local_equiv.source (local_homeomorph.to_local_equiv e) = set.univ) (e' : local_homeomorph Ξ± H) (h' : e' ∈ charted_space.atlas H Ξ±) : e' = e := h' /-- Given a local homeomorphism `e` from a space `Ξ±` into `H`, if its source covers the whole space `Ξ±`, then the induced charted space structure on `Ξ±` is `has_groupoid G` for any structure groupoid `G` which is closed under restrictions. -/ theorem singleton_has_groupoid {H : Type u} [topological_space H] {Ξ± : Type u_5} [topological_space Ξ±] (e : local_homeomorph Ξ± H) (h : local_equiv.source (local_homeomorph.to_local_equiv e) = set.univ) (G : structure_groupoid H) [closed_under_restriction G] : has_groupoid Ξ± G := sorry namespace topological_space.opens /-- An open subset of a charted space is naturally a charted space. -/ protected instance charted_space {H : Type u} {M : Type u_2} [topological_space H] [topological_space M] [charted_space H M] (s : opens M) : charted_space H β†₯s := charted_space.mk (set.Union fun (x : β†₯s) => singleton (local_homeomorph.subtype_restr (charted_space.chart_at H (subtype.val x)) s)) (fun (x : β†₯s) => local_homeomorph.subtype_restr (charted_space.chart_at H (subtype.val x)) s) sorry sorry /-- If a groupoid `G` is `closed_under_restriction`, then an open subset of a space which is `has_groupoid G` is naturally `has_groupoid G`. -/ protected instance has_groupoid {H : Type u} {M : Type u_2} [topological_space H] [topological_space M] [charted_space H M] (G : structure_groupoid H) [has_groupoid M G] (s : opens M) [closed_under_restriction G] : has_groupoid (β†₯s) G := sorry end topological_space.opens /-! ### Structomorphisms -/ /-- A `G`-diffeomorphism between two charted spaces is a homeomorphism which, when read in the charts, belongs to `G`. We avoid the word diffeomorph as it is too related to the smooth category, and use structomorph instead. -/ structure structomorph {H : Type u} [topological_space H] (G : structure_groupoid H) (M : Type u_5) (M' : Type u_6) [topological_space M] [topological_space M'] [charted_space H M] [charted_space H M'] extends M β‰ƒβ‚œ M' where mem_groupoid : βˆ€ (c : local_homeomorph M H) (c' : local_homeomorph M' H), c ∈ charted_space.atlas H M β†’ c' ∈ charted_space.atlas H M' β†’ local_homeomorph.trans (local_homeomorph.symm c) (local_homeomorph.trans (homeomorph.to_local_homeomorph _to_homeomorph) c') ∈ G /-- The identity is a diffeomorphism of any charted space, for any groupoid. -/ def structomorph.refl {H : Type u} [topological_space H] {G : structure_groupoid H} (M : Type u_1) [topological_space M] [charted_space H M] [has_groupoid M G] : structomorph G M M := structomorph.mk (homeomorph.mk (homeomorph.to_equiv (homeomorph.refl M))) sorry /-- The inverse of a structomorphism is a structomorphism -/ def structomorph.symm {H : Type u} {M : Type u_2} {M' : Type u_3} [topological_space H] [topological_space M] [charted_space H M] [topological_space M'] {G : structure_groupoid H} [charted_space H M'] (e : structomorph G M M') : structomorph G M' M := structomorph.mk (homeomorph.mk (homeomorph.to_equiv (homeomorph.symm (structomorph.to_homeomorph e)))) sorry /-- The composition of structomorphisms is a structomorphism -/ def structomorph.trans {H : Type u} {M : Type u_2} {M' : Type u_3} {M'' : Type u_4} [topological_space H] [topological_space M] [charted_space H M] [topological_space M'] [topological_space M''] {G : structure_groupoid H} [charted_space H M'] [charted_space H M''] (e : structomorph G M M') (e' : structomorph G M' M'') : structomorph G M M'' := structomorph.mk (homeomorph.mk (homeomorph.to_equiv (homeomorph.trans (structomorph.to_homeomorph e) (structomorph.to_homeomorph e')))) sorry
f60330e5a4c2df9a7af326e6622ca1ac66a34256
4efff1f47634ff19e2f786deadd394270a59ecd2
/src/data/indicator_function.lean
a95e0dac14eccdff2adfafd212f2d86777abe5c0
[ "Apache-2.0" ]
permissive
agjftucker/mathlib
d634cd0d5256b6325e3c55bb7fb2403548371707
87fe50de17b00af533f72a102d0adefe4a2285e8
refs/heads/master
1,625,378,131,941
1,599,166,526,000
1,599,166,526,000
160,748,509
0
0
Apache-2.0
1,544,141,789,000
1,544,141,789,000
null
UTF-8
Lean
false
false
12,707
lean
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou -/ import algebra.group.pi import group_theory.group_action import data.support import data.finset.lattice /-! # Indicator function `indicator (s : set Ξ±) (f : Ξ± β†’ Ξ²) (a : Ξ±)` is `f a` if `a ∈ s` and is `0` otherwise. ## Implementation note In mathematics, an indicator function or a characteristic function is a function used to indicate membership of an element in a set `s`, having the value `1` for all elements of `s` and the value `0` otherwise. But since it is usually used to restrict a function to a certain set `s`, we let the indicator function take the value `f x` for some function `f`, instead of `1`. If the usual indicator function is needed, just set `f` to be the constant function `Ξ»x, 1`. ## Tags indicator, characteristic -/ noncomputable theory open_locale classical big_operators open function variables {Ξ± Ξ² Ξ³ : Type*} namespace set section has_zero variables [has_zero Ξ²] {s t : set Ξ±} {f g : Ξ± β†’ Ξ²} {a : Ξ±} /-- `indicator s f a` is `f a` if `a ∈ s`, `0` otherwise. -/ @[reducible] def indicator (s : set Ξ±) (f : Ξ± β†’ Ξ²) : Ξ± β†’ Ξ² := Ξ» x, if x ∈ s then f x else 0 @[simp] lemma piecewise_eq_indicator {s : set Ξ±} : s.piecewise f 0 = s.indicator f := rfl lemma indicator_apply (s : set Ξ±) (f : Ξ± β†’ Ξ²) (a : Ξ±) : indicator s f a = if a ∈ s then f a else 0 := rfl @[simp] lemma indicator_of_mem (h : a ∈ s) (f : Ξ± β†’ Ξ²) : indicator s f a = f a := if_pos h @[simp] lemma indicator_of_not_mem (h : a βˆ‰ s) (f : Ξ± β†’ Ξ²) : indicator s f a = 0 := if_neg h /-- If an indicator function is nonzero at a point, that point is in the set. -/ lemma mem_of_indicator_ne_zero (h : indicator s f a β‰  0) : a ∈ s := not_imp_comm.1 (Ξ» hn, indicator_of_not_mem hn f) h lemma eq_on_indicator : eq_on (indicator s f) f s := Ξ» x hx, indicator_of_mem hx f lemma support_indicator : function.support (s.indicator f) βŠ† s := Ξ» x hx, hx.imp_symm (Ξ» h, indicator_of_not_mem h f) @[simp] lemma indicator_range_comp {ΞΉ : Sort*} (f : ΞΉ β†’ Ξ±) (g : Ξ± β†’ Ξ²) : indicator (range f) g ∘ f = g ∘ f := piecewise_range_comp _ _ _ lemma indicator_congr (h : βˆ€ a ∈ s, f a = g a) : indicator s f = indicator s g := funext $ Ξ»x, by { simp only [indicator], split_ifs, { exact h _ h_1 }, refl } @[simp] lemma indicator_univ (f : Ξ± β†’ Ξ²) : indicator (univ : set Ξ±) f = f := funext $ Ξ»x, indicator_of_mem (mem_univ _) f @[simp] lemma indicator_empty (f : Ξ± β†’ Ξ²) : indicator (βˆ… : set Ξ±) f = Ξ»a, 0 := funext $ Ξ»x, indicator_of_not_mem (not_mem_empty _) f variable (Ξ²) @[simp] lemma indicator_zero (s : set Ξ±) : indicator s (Ξ»x, (0:Ξ²)) = Ξ»x, (0:Ξ²) := funext $ Ξ»x, by { simp only [indicator], split_ifs, refl, refl } @[simp] lemma indicator_zero' {s : set Ξ±} : s.indicator (0 : Ξ± β†’ Ξ²) = 0 := indicator_zero Ξ² s variable {Ξ²} lemma indicator_indicator (s t : set Ξ±) (f : Ξ± β†’ Ξ²) : indicator s (indicator t f) = indicator (s ∩ t) f := funext $ Ξ»x, by { simp only [indicator], split_ifs, repeat {simp * at * {contextual := tt}} } lemma comp_indicator (h : Ξ² β†’ Ξ³) (f : Ξ± β†’ Ξ²) {s : set Ξ±} {x : Ξ±} : h (s.indicator f x) = s.piecewise (h ∘ f) (const Ξ± (h 0)) x := s.comp_piecewise h lemma indicator_comp_of_zero [has_zero Ξ³] {g : Ξ² β†’ Ξ³} (hg : g 0 = 0) : indicator s (g ∘ f) = g ∘ (indicator s f) := begin funext, simp only [indicator], split_ifs; simp [*] end lemma indicator_preimage (s : set Ξ±) (f : Ξ± β†’ Ξ²) (B : set Ξ²) : (indicator s f)⁻¹' B = s ∩ f ⁻¹' B βˆͺ sᢜ ∩ (Ξ»a:Ξ±, (0:Ξ²)) ⁻¹' B := piecewise_preimage s f 0 B lemma indicator_preimage_of_not_mem (s : set Ξ±) (f : Ξ± β†’ Ξ²) {t : set Ξ²} (ht : (0:Ξ²) βˆ‰ t) : (indicator s f)⁻¹' t = s ∩ f ⁻¹' t := by simp [indicator_preimage, set.preimage_const_of_not_mem ht] lemma mem_range_indicator {r : Ξ²} {s : set Ξ±} {f : Ξ± β†’ Ξ²} : r ∈ range (indicator s f) ↔ (r = 0 ∧ s β‰  univ) ∨ (r ∈ f '' s) := by simp [indicator, ite_eq_iff, exists_or_distrib, eq_univ_iff_forall, and_comm, or_comm, @eq_comm _ r 0] lemma indicator_rel_indicator {r : Ξ² β†’ Ξ² β†’ Prop} (h0 : r 0 0) (ha : a ∈ s β†’ r (f a) (g a)) : r (indicator s f a) (indicator s g a) := by { simp only [indicator], split_ifs with has has, exacts [ha has, h0] } /-- Consider a sum of `g i (f i)` over a `finset`. Suppose `g` is a function such as multiplication, which maps a second argument of 0 to 0. (A typical use case would be a weighted sum of `f i * h i` or `f i β€’ h i`, where `f` gives the weights that are multiplied by some other function `h`.) Then if `f` is replaced by the corresponding indicator function, the `finset` may be replaced by a possibly larger `finset` without changing the value of the sum. -/ lemma sum_indicator_subset_of_eq_zero {Ξ³ : Type*} [add_comm_monoid Ξ³] (f : Ξ± β†’ Ξ²) (g : Ξ± β†’ Ξ² β†’ Ξ³) {s₁ sβ‚‚ : finset Ξ±} (h : s₁ βŠ† sβ‚‚) (hg : βˆ€ a, g a 0 = 0) : βˆ‘ i in s₁, g i (f i) = βˆ‘ i in sβ‚‚, g i (indicator ↑s₁ f i) := begin rw ←finset.sum_subset h _, { apply finset.sum_congr rfl, intros i hi, congr, symmetry, exact indicator_of_mem hi _ }, { refine Ξ» i hi hn, _, convert hg i, exact indicator_of_not_mem hn _ } end /-- Summing an indicator function over a possibly larger `finset` is the same as summing the original function over the original `finset`. -/ lemma sum_indicator_subset {Ξ³ : Type*} [add_comm_monoid Ξ³] (f : Ξ± β†’ Ξ³) {s₁ sβ‚‚ : finset Ξ±} (h : s₁ βŠ† sβ‚‚) : βˆ‘ i in s₁, f i = βˆ‘ i in sβ‚‚, indicator ↑s₁ f i := sum_indicator_subset_of_eq_zero _ (Ξ» a b, b) h (Ξ» _, rfl) end has_zero section add_monoid variables [add_monoid Ξ²] {s t : set Ξ±} {f g : Ξ± β†’ Ξ²} {a : Ξ±} lemma indicator_union_of_not_mem_inter (h : a βˆ‰ s ∩ t) (f : Ξ± β†’ Ξ²) : indicator (s βˆͺ t) f a = indicator s f a + indicator t f a := by { simp only [indicator], split_ifs, repeat {simp * at * {contextual := tt}} } lemma indicator_union_of_disjoint (h : disjoint s t) (f : Ξ± β†’ Ξ²) : indicator (s βˆͺ t) f = Ξ»a, indicator s f a + indicator t f a := funext $ Ξ»a, indicator_union_of_not_mem_inter (by { convert not_mem_empty a, have := disjoint.eq_bot h, assumption }) _ lemma indicator_add (s : set Ξ±) (f g : Ξ± β†’ Ξ²) : indicator s (Ξ»a, f a + g a) = Ξ»a, indicator s f a + indicator s g a := by { funext, simp only [indicator], split_ifs, { refl }, rw add_zero } @[simp] lemma indicator_compl_add_self_apply (s : set Ξ±) (f : Ξ± β†’ Ξ²) (a : Ξ±) : indicator sᢜ f a + indicator s f a = f a := classical.by_cases (Ξ» ha : a ∈ s, by simp [ha]) (Ξ» ha, by simp [ha]) @[simp] lemma indicator_compl_add_self (s : set Ξ±) (f : Ξ± β†’ Ξ²) : indicator sᢜ f + indicator s f = f := funext $ indicator_compl_add_self_apply s f @[simp] lemma indicator_self_add_compl_apply (s : set Ξ±) (f : Ξ± β†’ Ξ²) (a : Ξ±) : indicator s f a + indicator sᢜ f a = f a := classical.by_cases (Ξ» ha : a ∈ s, by simp [ha]) (Ξ» ha, by simp [ha]) @[simp] lemma indicator_self_add_compl (s : set Ξ±) (f : Ξ± β†’ Ξ²) : indicator s f + indicator sᢜ f = f := funext $ indicator_self_add_compl_apply s f variables (Ξ²) instance is_add_monoid_hom.indicator (s : set Ξ±) : is_add_monoid_hom (Ξ»f:Ξ± β†’ Ξ², indicator s f) := { map_add := Ξ» _ _, indicator_add _ _ _, map_zero := indicator_zero _ _ } variables {Ξ²} {π•œ : Type*} [monoid π•œ] [distrib_mul_action π•œ Ξ²] lemma indicator_smul (s : set Ξ±) (r : π•œ) (f : Ξ± β†’ Ξ²) : indicator s (Ξ» (x : Ξ±), r β€’ f x) = Ξ» (x : Ξ±), r β€’ indicator s f x := by { simp only [indicator], funext, split_ifs, refl, exact (smul_zero r).symm } lemma indicator_add_eq_left {f g : Ξ± β†’ Ξ²} (h : univ βŠ† f ⁻¹' {0} βˆͺ g ⁻¹' {0}) : (f ⁻¹' {0})ᢜ.indicator (f + g) = f := begin ext x, by_cases hx : x ∈ (f ⁻¹' {0})ᢜ, { have : g x = 0, { simp at hx, specialize h (mem_univ x), simpa [hx] using h }, simp [hx, this] }, { simp * at * } end lemma indicator_add_eq_right {f g : Ξ± β†’ Ξ²} (h : univ βŠ† f ⁻¹' {0} βˆͺ g ⁻¹' {0}) : (g ⁻¹' {0})ᢜ.indicator (f + g) = g := begin ext x, by_cases hx : x ∈ (g ⁻¹' {0})ᢜ, { have : f x = 0, { simp at hx, specialize h (mem_univ x), simpa [hx] using h }, simp [hx, this] }, { simp * at * } end end add_monoid section add_group variables [add_group Ξ²] {s t : set Ξ±} {f g : Ξ± β†’ Ξ²} {a : Ξ±} variables (Ξ²) instance is_add_group_hom.indicator (s : set Ξ±) : is_add_group_hom (Ξ»f:Ξ± β†’ Ξ², indicator s f) := { .. is_add_monoid_hom.indicator Ξ² s } variables {Ξ²} lemma indicator_neg (s : set Ξ±) (f : Ξ± β†’ Ξ²) : indicator s (Ξ»a, - f a) = Ξ»a, - indicator s f a := show indicator s (- f) = - indicator s f, from is_add_group_hom.map_neg _ _ lemma indicator_sub (s : set Ξ±) (f g : Ξ± β†’ Ξ²) : indicator s (Ξ»a, f a - g a) = Ξ»a, indicator s f a - indicator s g a := show indicator s (f - g) = indicator s f - indicator s g, from is_add_group_hom.map_sub _ _ _ lemma indicator_compl (s : set Ξ±) (f : Ξ± β†’ Ξ²) : indicator sᢜ f = f - indicator s f := eq_sub_of_add_eq $ s.indicator_compl_add_self f lemma indicator_finset_sum {Ξ²} [add_comm_monoid Ξ²] {ΞΉ : Type*} (I : finset ΞΉ) (s : set Ξ±) (f : ΞΉ β†’ Ξ± β†’ Ξ²) : indicator s (βˆ‘ i in I, f i) = βˆ‘ i in I, indicator s (f i) := begin convert (finset.sum_hom _ _).symm, split, exact indicator_zero _ _ end lemma indicator_finset_bUnion {Ξ²} [add_comm_monoid Ξ²] {ΞΉ} (I : finset ΞΉ) (s : ΞΉ β†’ set Ξ±) {f : Ξ± β†’ Ξ²} : (βˆ€ (i ∈ I) (j ∈ I), i β‰  j β†’ s i ∩ s j = βˆ…) β†’ indicator (⋃ i ∈ I, s i) f = Ξ» a, βˆ‘ i in I, indicator (s i) f a := begin refine finset.induction_on I _ _, assume h, { funext, simp }, assume a I haI ih hI, funext, simp only [haI, finset.sum_insert, not_false_iff], rw [finset.bUnion_insert, indicator_union_of_not_mem_inter, ih _], { assume i hi j hj hij, exact hI i (finset.mem_insert_of_mem hi) j (finset.mem_insert_of_mem hj) hij }, simp only [not_exists, exists_prop, mem_Union, mem_inter_eq, not_and], assume hx a' ha', have := hI a (finset.mem_insert_self _ _) a' (finset.mem_insert_of_mem ha') _, { assume h, have h := mem_inter hx h, rw this at h, exact not_mem_empty _ h }, { assume h, rw h at haI, contradiction } end end add_group section mul_zero_class variables [mul_zero_class Ξ²] {s t : set Ξ±} {f g : Ξ± β†’ Ξ²} {a : Ξ±} lemma indicator_mul (s : set Ξ±) (f g : Ξ± β†’ Ξ²) : indicator s (Ξ»a, f a * g a) = Ξ»a, indicator s f a * indicator s g a := by { funext, simp only [indicator], split_ifs, { refl }, rw mul_zero } end mul_zero_class section order variables [has_zero Ξ²] [preorder Ξ²] {s t : set Ξ±} {f g : Ξ± β†’ Ξ²} {a : Ξ±} lemma indicator_nonneg' (h : a ∈ s β†’ 0 ≀ f a) : 0 ≀ indicator s f a := by { rw indicator_apply, split_ifs with as, { exact h as }, refl } lemma indicator_nonneg (h : βˆ€ a ∈ s, 0 ≀ f a) : βˆ€ a, 0 ≀ indicator s f a := Ξ» a, indicator_nonneg' (h a) lemma indicator_nonpos' (h : a ∈ s β†’ f a ≀ 0) : indicator s f a ≀ 0 := by { rw indicator_apply, split_ifs with as, { exact h as }, refl } lemma indicator_nonpos (h : βˆ€ a ∈ s, f a ≀ 0) : βˆ€ a, indicator s f a ≀ 0 := Ξ» a, indicator_nonpos' (h a) lemma indicator_le' (hfg : βˆ€ a ∈ s, f a ≀ g a) (hg : βˆ€ a βˆ‰ s, 0 ≀ g a) : indicator s f ≀ g := Ξ» a, if ha : a ∈ s then by simpa [ha] using hfg a ha else by simpa [ha] using hg a ha @[mono] lemma indicator_le_indicator (h : f a ≀ g a) : indicator s f a ≀ indicator s g a := indicator_rel_indicator (le_refl _) (Ξ» _, h) lemma indicator_le_indicator_of_subset (h : s βŠ† t) (hf : βˆ€a, 0 ≀ f a) (a : Ξ±) : indicator s f a ≀ indicator t f a := begin simp only [indicator], split_ifs with h₁, { refl }, { have := h h₁, contradiction }, { exact hf a }, { refl } end lemma indicator_le_self' (hf : βˆ€ x βˆ‰ s, 0 ≀ f x) : indicator s f ≀ f := indicator_le' (Ξ» _ _, le_refl _) hf lemma indicator_le_self {Ξ²} [canonically_ordered_add_monoid Ξ²] (s : set Ξ±) (f : Ξ± β†’ Ξ²) : indicator s f ≀ f := indicator_le_self' $ Ξ» _ _, zero_le _ lemma indicator_le {Ξ²} [canonically_ordered_add_monoid Ξ²] {s : set Ξ±} {f g : Ξ± β†’ Ξ²} (hfg : βˆ€ a ∈ s, f a ≀ g a) : indicator s f ≀ g := indicator_le' hfg $ Ξ» _ _, zero_le _ end order end set lemma add_monoid_hom.map_indicator {M N : Type*} [add_monoid M] [add_monoid N] (f : M β†’+ N) (s : set Ξ±) (g : Ξ± β†’ M) (x : Ξ±) : f (s.indicator g x) = s.indicator (f ∘ g) x := congr_fun (set.indicator_comp_of_zero f.map_zero).symm x
41ba8cefb1adadcc0b4a99e72afa3db10723e0ea
957a80ea22c5abb4f4670b250d55534d9db99108
/tests/lean/run/cody2.lean
ff2e456e21e39e2e7741379e0352a64fd04aef19
[ "Apache-2.0" ]
permissive
GaloisInc/lean
aa1e64d604051e602fcf4610061314b9a37ab8cd
f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0
refs/heads/master
1,592,202,909,807
1,504,624,387,000
1,504,624,387,000
75,319,626
2
1
Apache-2.0
1,539,290,164,000
1,480,616,104,000
C++
UTF-8
Lean
false
false
444
lean
open eq definition subsets (P : Type) := P β†’ Prop. section parameter A : Type. parameter r : A β†’ subsets A. parameter i : subsets A β†’ A. parameter retract {P : subsets A} {a : A} : r (i P) a = P a. definition delta (a:A) : Prop := Β¬ (r a a). local notation `Ξ΄` := delta. theorem delta_aux : Β¬ (Ξ΄ (i delta)) := assume H : Ξ΄ (i delta), H (subst (symm (@retract delta (i delta))) H) #check delta_aux. end
62f174e099ef25b0c5a0d63c701bd2b56dd74afc
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/tactic/omega/int/dnf.lean
6042952439f8af08fc920e43c4c4e289c7538e50
[ "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
6,073
lean
/- Copyright (c) 2019 Seul Baek. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Seul Baek DNF transformation. -/ import tactic.omega.clause import tactic.omega.int.form namespace omega namespace int local notation x ` =* ` y := form.eq x y local notation x ` ≀* ` y := form.le x y local notation `Β¬* ` p := form.not p local notation p ` ∨* ` q := form.or p q local notation p ` ∧* ` q := form.and p q @[simp] def push_neg : form β†’ form | (p ∨* q) := (push_neg p) ∧* (push_neg q) | (p ∧* q) := (push_neg p) ∨* (push_neg q) | (Β¬*p) := p | p := Β¬* p lemma push_neg_equiv : βˆ€ {p : form}, form.equiv (push_neg p) (Β¬* p) := begin form.induce `[intros v; try {refl}], { simp only [classical.not_not, push_neg, form.holds] }, { simp only [form.holds, push_neg, not_or_distrib, ihp v, ihq v] }, { simp only [form.holds, push_neg, classical.not_and_distrib, ihp v, ihq v] } end def nnf : form β†’ form | (Β¬* p) := push_neg (nnf p) | (p ∨* q) := (nnf p) ∨* (nnf q) | (p ∧* q) := (nnf p) ∧* (nnf q) | a := a def is_nnf : form β†’ Prop | (t =* s) := true | (t ≀* s) := true | Β¬*(t =* s) := true | Β¬*(t ≀* s) := true | (p ∨* q) := is_nnf p ∧ is_nnf q | (p ∧* q) := is_nnf p ∧ is_nnf q | _ := false lemma is_nnf_push_neg : βˆ€ p : form, is_nnf p β†’ is_nnf (push_neg p) := begin form.induce `[intro h1; try {trivial}], { cases p; try {cases h1}; trivial }, { cases h1, constructor; [{apply ihp}, {apply ihq}]; assumption }, { cases h1, constructor; [{apply ihp}, {apply ihq}]; assumption } end def neg_free : form β†’ Prop | (t =* s) := true | (t ≀* s) := true | (p ∨* q) := neg_free p ∧ neg_free q | (p ∧* q) := neg_free p ∧ neg_free q | _ := false lemma is_nnf_nnf : βˆ€ p : form, is_nnf (nnf p) := begin form.induce `[try {trivial}], { apply is_nnf_push_neg _ ih }, { constructor; assumption }, { constructor; assumption } end lemma nnf_equiv : βˆ€ {p : form}, form.equiv (nnf p) p := begin form.induce `[intros v; try {refl}; simp only [nnf]], { rw push_neg_equiv, apply not_iff_not_of_iff, apply ih }, { apply pred_mono_2' (ihp v) (ihq v) }, { apply pred_mono_2' (ihp v) (ihq v) } end @[simp] def neg_elim : form β†’ form | (Β¬* (t =* s)) := (t.add_one ≀* s) ∨* (s.add_one ≀* t) | (Β¬* (t ≀* s)) := s.add_one ≀* t | (p ∨* q) := (neg_elim p) ∨* (neg_elim q) | (p ∧* q) := (neg_elim p) ∧* (neg_elim q) | p := p lemma neg_free_neg_elim : βˆ€ p : form, is_nnf p β†’ neg_free (neg_elim p) := begin form.induce `[intro h1, try {simp only [neg_free, neg_elim]}, try {trivial}], { cases p; try {cases h1}; try {trivial}, constructor; trivial }, { cases h1, constructor; [{apply ihp}, {apply ihq}]; assumption }, { cases h1, constructor; [{apply ihp}, {apply ihq}]; assumption } end lemma le_and_le_iff_eq {Ξ± : Type} [partial_order Ξ±] {a b : Ξ±} : (a ≀ b ∧ b ≀ a) ↔ a = b := begin constructor; intro h1, { cases h1, apply le_antisymm; assumption }, { constructor; apply le_of_eq; rw h1 } end lemma implies_neg_elim : βˆ€ {p : form}, form.implies p (neg_elim p) := begin form.induce `[intros v h, try {apply h}], { cases p with t s t s; try {apply h}, { simp only [le_and_le_iff_eq.symm, classical.not_and_distrib, not_le, preterm.val, form.holds] at h, simp only [int.add_one_le_iff, preterm.add_one, preterm.val, form.holds, neg_elim], rw or_comm, assumption }, { simp only [not_le, int.add_one_le_iff, preterm.add_one, not_le, preterm.val, form.holds, neg_elim] at *, assumption} }, { simp only [neg_elim], cases h; [{left, apply ihp}, {right, apply ihq}]; assumption }, { apply and.imp (ihp _) (ihq _) h } end @[simp] def dnf_core : form β†’ list clause | (p ∨* q) := (dnf_core p) ++ (dnf_core q) | (p ∧* q) := (list.product (dnf_core p) (dnf_core q)).map (Ξ» pq, clause.append pq.fst pq.snd) | (t =* s) := [([term.sub (canonize s) (canonize t)],[])] | (t ≀* s) := [([],[term.sub (canonize s) (canonize t)])] | (Β¬* _) := [] def dnf (p : form) : list clause := dnf_core $ neg_elim $ nnf p lemma exists_clause_holds {v : nat β†’ int} : βˆ€ {p : form}, neg_free p β†’ p.holds v β†’ βˆƒ c ∈ (dnf_core p), clause.holds v c := begin form.induce `[intros h1 h2], { apply list.exists_mem_cons_of, constructor, { simp only [preterm.val, form.holds] at h2, rw [list.forall_mem_singleton], simp only [h2, omega.int.val_canonize, omega.term.val_sub, sub_self] }, { apply list.forall_mem_nil } }, { apply list.exists_mem_cons_of, constructor, { apply list.forall_mem_nil }, { simp only [preterm.val, form.holds] at h2 , rw [list.forall_mem_singleton], simp only [val_canonize, preterm.val, term.val_sub], rw [le_sub, sub_zero], assumption } }, { cases h1 }, { cases h2 with h2 h2; [ {cases (ihp h1.left h2) with c h3}, {cases (ihq h1.right h2) with c h3}]; cases h3 with h3 h4; refine ⟨c, list.mem_append.elim_right _, h4⟩; [left,right]; assumption }, { rcases (ihp h1.left h2.left) with ⟨cp, hp1, hp2⟩, rcases (ihq h1.right h2.right) with ⟨cq, hq1, hq2⟩, refine ⟨clause.append cp cq, ⟨_, clause.holds_append hp2 hq2⟩⟩, simp only [dnf_core, list.mem_map], refine ⟨(cp,cq),⟨_,rfl⟩⟩, rw list.mem_product, constructor; assumption } end lemma clauses_sat_dnf_core {p : form} : neg_free p β†’ p.sat β†’ clauses.sat (dnf_core p) := begin intros h1 h2, cases h2 with v h2, rcases (exists_clause_holds h1 h2) with ⟨c,h3,h4⟩, refine ⟨c,h3,v,h4⟩ end lemma unsat_of_clauses_unsat {p : form} : clauses.unsat (dnf p) β†’ p.unsat := begin intros h1 h2, apply h1, apply clauses_sat_dnf_core, apply neg_free_neg_elim _ (is_nnf_nnf _), apply form.sat_of_implies_of_sat implies_neg_elim, have hrw := exists_congr (@nnf_equiv p), apply hrw.elim_right h2 end end int end omega
e818efbe019ba8e1593ca3a78bd190f349226504
2a70b774d16dbdf5a533432ee0ebab6838df0948
/_target/deps/mathlib/src/measure_theory/lebesgue_measure.lean
78474f1f12bd544cf13e2990cf3d3e0a848298bb
[ "Apache-2.0" ]
permissive
hjvromen/lewis
40b035973df7c77ebf927afab7878c76d05ff758
105b675f73630f028ad5d890897a51b3c1146fb0
refs/heads/master
1,677,944,636,343
1,676,555,301,000
1,676,555,301,000
327,553,599
0
0
null
null
null
null
UTF-8
Lean
false
false
14,064
lean
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import measure_theory.measure_space import measure_theory.borel_space /-! # Lebesgue measure on the real line -/ noncomputable theory open classical set filter open ennreal (of_real) open_locale big_operators namespace measure_theory /-- Length of an interval. This is the largest monotonic function which correctly measures all intervals. -/ def lebesgue_length (s : set ℝ) : ennreal := β¨…a b (h : s βŠ† Ico a b), of_real (b - a) @[simp] lemma lebesgue_length_empty : lebesgue_length βˆ… = 0 := nonpos_iff_eq_zero.1 $ infi_le_of_le 0 $ infi_le_of_le 0 $ by simp @[simp] lemma lebesgue_length_Ico (a b : ℝ) : lebesgue_length (Ico a b) = of_real (b - a) := begin refine le_antisymm (infi_le_of_le a $ binfi_le b (subset.refl _)) (le_infi $ Ξ» a', le_infi $ Ξ» b', le_infi $ Ξ» h, ennreal.coe_le_coe.2 _), cases le_or_lt b a with ab ab, { rw nnreal.of_real_of_nonpos (sub_nonpos.2 ab), apply zero_le }, cases (Ico_subset_Ico_iff ab).1 h with h₁ hβ‚‚, exact nnreal.of_real_le_of_real (sub_le_sub hβ‚‚ h₁) end lemma lebesgue_length_mono {s₁ sβ‚‚ : set ℝ} (h : s₁ βŠ† sβ‚‚) : lebesgue_length s₁ ≀ lebesgue_length sβ‚‚ := infi_le_infi $ Ξ» a, infi_le_infi $ Ξ» b, infi_le_infi2 $ Ξ» h', ⟨subset.trans h h', le_refl _⟩ lemma lebesgue_length_eq_infi_Ioo (s) : lebesgue_length s = β¨…a b (h : s βŠ† Ioo a b), of_real (b - a) := begin refine le_antisymm (infi_le_infi $ Ξ» a, infi_le_infi $ Ξ» b, infi_le_infi2 $ Ξ» h, ⟨subset.trans h Ioo_subset_Ico_self, le_refl _⟩) _, refine le_infi (Ξ» a, le_infi $ Ξ» b, le_infi $ Ξ» h, _), refine ennreal.le_of_forall_epsilon_le (Ξ» Ξ΅ Ξ΅0 _, _), refine infi_le_of_le (a - Ξ΅) (infi_le_of_le b $ infi_le_of_le (subset.trans h $ Ico_subset_Ioo_left $ (sub_lt_self_iff _).2 Ξ΅0) _), rw ← sub_add, refine le_trans ennreal.of_real_add_le (add_le_add_left _ _), simp only [ennreal.of_real_coe_nnreal, le_refl] end @[simp] lemma lebesgue_length_Ioo (a b : ℝ) : lebesgue_length (Ioo a b) = of_real (b - a) := begin rw ← lebesgue_length_Ico, refine le_antisymm (lebesgue_length_mono Ioo_subset_Ico_self) _, rw lebesgue_length_eq_infi_Ioo (Ioo a b), refine (le_infi $ Ξ» a', le_infi $ Ξ» b', le_infi $ Ξ» h, _), cases le_or_lt b a with ab ab, {simp [ab]}, cases (Ioo_subset_Ioo_iff ab).1 h with h₁ hβ‚‚, rw [lebesgue_length_Ico], exact ennreal.of_real_le_of_real (sub_le_sub hβ‚‚ h₁) end lemma lebesgue_length_eq_infi_Icc (s) : lebesgue_length s = β¨…a b (h : s βŠ† Icc a b), of_real (b - a) := begin refine le_antisymm _ (infi_le_infi $ Ξ» a, infi_le_infi $ Ξ» b, infi_le_infi2 $ Ξ» h, ⟨subset.trans h Ico_subset_Icc_self, le_refl _⟩), refine le_infi (Ξ» a, le_infi $ Ξ» b, le_infi $ Ξ» h, _), refine ennreal.le_of_forall_epsilon_le (Ξ» Ξ΅ Ξ΅0 _, _), refine infi_le_of_le a (infi_le_of_le (b + Ξ΅) $ infi_le_of_le (subset.trans h $ Icc_subset_Ico_right $ (lt_add_iff_pos_right _).2 Ξ΅0) _), rw [← sub_add_eq_add_sub], refine le_trans ennreal.of_real_add_le (add_le_add_left _ _), simp only [ennreal.of_real_coe_nnreal, le_refl] end @[simp] lemma lebesgue_length_Icc (a b : ℝ) : lebesgue_length (Icc a b) = of_real (b - a) := begin rw ← lebesgue_length_Ico, refine le_antisymm _ (lebesgue_length_mono Ico_subset_Icc_self), rw lebesgue_length_eq_infi_Icc (Icc a b), exact infi_le_of_le a (infi_le_of_le b $ infi_le_of_le (by refl) (by simp [le_refl])) end /-- The Lebesgue outer measure, as an outer measure of ℝ. -/ def lebesgue_outer : outer_measure ℝ := outer_measure.of_function lebesgue_length lebesgue_length_empty lemma lebesgue_outer_le_length (s : set ℝ) : lebesgue_outer s ≀ lebesgue_length s := outer_measure.of_function_le _ lemma lebesgue_length_subadditive {a b : ℝ} {c d : β„• β†’ ℝ} (ss : Icc a b βŠ† ⋃i, Ioo (c i) (d i)) : (of_real (b - a) : ennreal) ≀ βˆ‘' i, of_real (d i - c i) := begin suffices : βˆ€ (s:finset β„•) b (cv : Icc a b βŠ† ⋃ i ∈ (↑s:set β„•), Ioo (c i) (d i)), (of_real (b - a) : ennreal) ≀ βˆ‘ i in s, of_real (d i - c i), { rcases compact_Icc.elim_finite_subcover_image (Ξ» (i : β„•) (_ : i ∈ univ), @is_open_Ioo _ _ _ _ (c i) (d i)) (by simpa using ss) with ⟨s, su, hf, hs⟩, have e : (⋃ i ∈ (↑hf.to_finset:set β„•), Ioo (c i) (d i)) = (⋃ i ∈ s, Ioo (c i) (d i)), {simp [set.ext_iff]}, rw ennreal.tsum_eq_supr_sum, refine le_trans _ (le_supr _ hf.to_finset), exact this hf.to_finset _ (by simpa [e]) }, clear ss b, refine Ξ» s, finset.strong_induction_on s (Ξ» s IH b cv, _), cases le_total b a with ab ab, { rw ennreal.of_real_eq_zero.2 (sub_nonpos.2 ab), exact zero_le _ }, have := cv ⟨ab, le_refl _⟩, simp at this, rcases this with ⟨i, is, cb, bd⟩, rw [← finset.insert_erase is] at cv ⊒, rw [finset.coe_insert, bUnion_insert] at cv, rw [finset.sum_insert (finset.not_mem_erase _ _)], refine le_trans _ (add_le_add_left (IH _ (finset.erase_ssubset is) (c i) _) _), { refine le_trans (ennreal.of_real_le_of_real _) ennreal.of_real_add_le, rw sub_add_sub_cancel, exact sub_le_sub_right (le_of_lt bd) _ }, { rintro x ⟨h₁, hβ‚‚βŸ©, refine (cv ⟨h₁, le_trans hβ‚‚ (le_of_lt cb)⟩).resolve_left (mt and.left (not_lt_of_le hβ‚‚)) } end @[simp] lemma lebesgue_outer_Icc (a b : ℝ) : lebesgue_outer (Icc a b) = of_real (b - a) := begin refine le_antisymm (by rw ← lebesgue_length_Icc; apply lebesgue_outer_le_length) (le_binfi $ Ξ» f hf, ennreal.le_of_forall_epsilon_le $ Ξ» Ξ΅ Ξ΅0 h, _), rcases ennreal.exists_pos_sum_of_encodable (ennreal.zero_lt_coe_iff.2 Ξ΅0) β„• with ⟨Ρ', Ξ΅'0, hΡ⟩, refine le_trans _ (add_le_add_left (le_of_lt hΞ΅) _), rw ← ennreal.tsum_add, choose g hg using show βˆ€ i, βˆƒ p:ℝ×ℝ, f i βŠ† Ioo p.1 p.2 ∧ (of_real (p.2 - p.1) : ennreal) < lebesgue_length (f i) + Ξ΅' i, { intro i, have := (ennreal.lt_add_right (lt_of_le_of_lt (ennreal.le_tsum i) h) (ennreal.zero_lt_coe_iff.2 (Ξ΅'0 i))), conv at this {to_lhs, rw lebesgue_length_eq_infi_Ioo}, simpa [infi_lt_iff] }, refine le_trans _ (ennreal.tsum_le_tsum $ Ξ» i, le_of_lt (hg i).2), exact lebesgue_length_subadditive (subset.trans hf $ Union_subset_Union $ Ξ» i, (hg i).1) end @[simp] lemma lebesgue_outer_singleton (a : ℝ) : lebesgue_outer {a} = 0 := by simpa using lebesgue_outer_Icc a a @[simp] lemma lebesgue_outer_Ico (a b : ℝ) : lebesgue_outer (Ico a b) = of_real (b - a) := by rw [← Icc_diff_right, lebesgue_outer.diff_null _ (lebesgue_outer_singleton _), lebesgue_outer_Icc] @[simp] lemma lebesgue_outer_Ioo (a b : ℝ) : lebesgue_outer (Ioo a b) = of_real (b - a) := by rw [← Ico_diff_left, lebesgue_outer.diff_null _ (lebesgue_outer_singleton _), lebesgue_outer_Ico] @[simp] lemma lebesgue_outer_Ioc (a b : ℝ) : lebesgue_outer (Ioc a b) = of_real (b - a) := by rw [← Icc_diff_left, lebesgue_outer.diff_null _ (lebesgue_outer_singleton _), lebesgue_outer_Icc] lemma is_lebesgue_measurable_Iio {c : ℝ} : lebesgue_outer.caratheodory.is_measurable' (Iio c) := outer_measure.of_function_caratheodory $ Ξ» t, le_infi $ Ξ» a, le_infi $ Ξ» b, le_infi $ Ξ» h, begin refine le_trans (add_le_add (lebesgue_length_mono $ inter_subset_inter_left _ h) (lebesgue_length_mono $ diff_subset_diff_left h)) _, cases le_total a c with hac hca; cases le_total b c with hbc hcb; simp [*, -sub_eq_add_neg, sub_add_sub_cancel', le_refl], { simp [*, ← ennreal.of_real_add, -sub_eq_add_neg, sub_add_sub_cancel', le_refl] }, { simp only [ennreal.of_real_eq_zero.2 (sub_nonpos.2 (le_trans hbc hca)), zero_add, le_refl] } end theorem lebesgue_outer_trim : lebesgue_outer.trim = lebesgue_outer := begin refine le_antisymm (Ξ» s, _) (outer_measure.le_trim _), rw outer_measure.trim_eq_infi, refine le_infi (Ξ» f, le_infi $ Ξ» hf, ennreal.le_of_forall_epsilon_le $ Ξ» Ξ΅ Ξ΅0 h, _), rcases ennreal.exists_pos_sum_of_encodable (ennreal.zero_lt_coe_iff.2 Ξ΅0) β„• with ⟨Ρ', Ξ΅'0, hΡ⟩, refine le_trans _ (add_le_add_left (le_of_lt hΞ΅) _), rw ← ennreal.tsum_add, choose g hg using show βˆ€ i, βˆƒ s, f i βŠ† s ∧ is_measurable s ∧ lebesgue_outer s ≀ lebesgue_length (f i) + of_real (Ξ΅' i), { intro i, have := (ennreal.lt_add_right (lt_of_le_of_lt (ennreal.le_tsum i) h) (ennreal.zero_lt_coe_iff.2 (Ξ΅'0 i))), conv at this {to_lhs, rw lebesgue_length}, simp only [infi_lt_iff] at this, rcases this with ⟨a, b, h₁, hβ‚‚βŸ©, rw ← lebesgue_outer_Ico at hβ‚‚, exact ⟨_, h₁, is_measurable_Ico, le_of_lt $ by simpa using hβ‚‚βŸ© }, simp at hg, apply infi_le_of_le (Union g) _, apply infi_le_of_le (subset.trans hf $ Union_subset_Union (Ξ» i, (hg i).1)) _, apply infi_le_of_le (is_measurable.Union (Ξ» i, (hg i).2.1)) _, exact le_trans (lebesgue_outer.Union _) (ennreal.tsum_le_tsum $ Ξ» i, (hg i).2.2) end lemma borel_le_lebesgue_measurable : borel ℝ ≀ lebesgue_outer.caratheodory := begin rw real.borel_eq_generate_from_Iio_rat, refine measurable_space.generate_from_le _, simp [is_lebesgue_measurable_Iio] { contextual := tt } end /-- Lebesgue measure on the Borel sets The outer Lebesgue measure is the completion of this measure. (TODO: proof this) -/ instance real.measure_space : measure_space ℝ := ⟨{to_outer_measure := lebesgue_outer, m_Union := Ξ» f hf, lebesgue_outer.Union_eq_of_caratheodory $ Ξ» i, borel_le_lebesgue_measurable _ (hf i), trimmed := lebesgue_outer_trim }⟩ @[simp] theorem lebesgue_to_outer_measure : (volume : measure ℝ).to_outer_measure = lebesgue_outer := rfl end measure_theory open measure_theory namespace real open_locale topological_space theorem volume_val (s) : volume s = lebesgue_outer s := rfl instance has_no_atoms_volume : has_no_atoms (volume : measure ℝ) := ⟨lebesgue_outer_singleton⟩ @[simp] lemma volume_Ico {a b : ℝ} : volume (Ico a b) = of_real (b - a) := lebesgue_outer_Ico a b @[simp] lemma volume_Icc {a b : ℝ} : volume (Icc a b) = of_real (b - a) := lebesgue_outer_Icc a b @[simp] lemma volume_Ioo {a b : ℝ} : volume (Ioo a b) = of_real (b - a) := lebesgue_outer_Ioo a b @[simp] lemma volume_Ioc {a b : ℝ} : volume (Ioc a b) = of_real (b - a) := lebesgue_outer_Ioc a b @[simp] lemma volume_singleton {a : ℝ} : volume ({a} : set ℝ) = 0 := lebesgue_outer_singleton a @[simp] lemma volume_interval {a b : ℝ} : volume (interval a b) = of_real (abs (b - a)) := by rw [interval, volume_Icc, max_sub_min_eq_abs] instance locally_finite_volume : locally_finite_measure (volume : measure ℝ) := ⟨λ x, ⟨Ioo (x - 1) (x + 1), mem_nhds_sets is_open_Ioo ⟨sub_lt_self _ zero_lt_one, lt_add_of_pos_right _ zero_lt_one⟩, by simp only [real.volume_Ioo, ennreal.of_real_lt_top]⟩⟩ lemma map_volume_add_left (a : ℝ) : measure.map ((+) a) volume = volume := eq.symm $ real.measure_ext_Ioo_rat $ Ξ» p q, by simp [measure.map_apply (measurable_add_left a) is_measurable_Ioo, sub_sub_sub_cancel_right] lemma map_volume_add_right (a : ℝ) : measure.map (+ a) volume = volume := by simpa only [add_comm] using real.map_volume_add_left a lemma smul_map_volume_mul_left {a : ℝ} (h : a β‰  0) : ennreal.of_real (abs a) β€’ measure.map ((*) a) volume = volume := begin refine (real.measure_ext_Ioo_rat $ Ξ» p q, _).symm, cases lt_or_gt_of_ne h with h h, { simp only [real.volume_Ioo, measure.smul_apply, ← ennreal.of_real_mul (le_of_lt $ neg_pos.2 h), measure.map_apply (measurable_mul_left a) is_measurable_Ioo, neg_sub_neg, ← neg_mul_eq_neg_mul, preimage_const_mul_Ioo_of_neg _ _ h, abs_of_neg h, mul_sub, mul_div_cancel' _ (ne_of_lt h)] }, { simp only [real.volume_Ioo, measure.smul_apply, ← ennreal.of_real_mul (le_of_lt h), measure.map_apply (measurable_mul_left a) is_measurable_Ioo, preimage_const_mul_Ioo _ _ h, abs_of_pos h, mul_sub, mul_div_cancel' _ (ne_of_gt h)] } end lemma map_volume_mul_left {a : ℝ} (h : a β‰  0) : measure.map ((*) a) volume = ennreal.of_real (abs a⁻¹) β€’ volume := by conv_rhs { rw [← real.smul_map_volume_mul_left h, smul_smul, ← ennreal.of_real_mul (abs_nonneg _), ← abs_mul, inv_mul_cancel h, abs_one, ennreal.of_real_one, one_smul] } lemma smul_map_volume_mul_right {a : ℝ} (h : a β‰  0) : ennreal.of_real (abs a) β€’ measure.map (* a) volume = volume := by simpa only [mul_comm] using real.smul_map_volume_mul_left h lemma map_volume_mul_right {a : ℝ} (h : a β‰  0) : measure.map (* a) volume = ennreal.of_real (abs a⁻¹) β€’ volume := by simpa only [mul_comm] using real.map_volume_mul_left h @[simp] lemma map_volume_neg : measure.map has_neg.neg (volume : measure ℝ) = volume := eq.symm $ real.measure_ext_Ioo_rat $ Ξ» p q, by simp [measure.map_apply measurable_neg is_measurable_Ioo] end real open_locale topological_space lemma filter.eventually.volume_pos_of_nhds_real {p : ℝ β†’ Prop} {a : ℝ} (h : βˆ€αΆ  x in 𝓝 a, p x) : (0 : ennreal) < volume {x | p x} := begin rcases h.exists_Ioo_subset with ⟨l, u, hx, hs⟩, refine lt_of_lt_of_le _ (measure_mono hs), simpa [-mem_Ioo] using hx.1.trans hx.2 end /- section vitali def vitali_aux_h (x : ℝ) (h : x ∈ Icc (0:ℝ) 1) : βˆƒ y ∈ Icc (0:ℝ) 1, βˆƒ q:β„š, ↑q = x - y := ⟨x, h, 0, by simp⟩ def vitali_aux (x : ℝ) (h : x ∈ Icc (0:ℝ) 1) : ℝ := classical.some (vitali_aux_h x h) theorem vitali_aux_mem (x : ℝ) (h : x ∈ Icc (0:ℝ) 1) : vitali_aux x h ∈ Icc (0:ℝ) 1 := Exists.fst (classical.some_spec (vitali_aux_h x h):_) theorem vitali_aux_rel (x : ℝ) (h : x ∈ Icc (0:ℝ) 1) : βˆƒ q:β„š, ↑q = x - vitali_aux x h := Exists.snd (classical.some_spec (vitali_aux_h x h):_) def vitali : set ℝ := {x | βˆƒ h, x = vitali_aux x h} theorem vitali_nonmeasurable : Β¬ is_null_measurable measure_space.ΞΌ vitali := sorry end vitali -/
6934bdbd9b99a2db63f16e3fb7572d55a7662844
c777c32c8e484e195053731103c5e52af26a25d1
/src/ring_theory/polynomial/eisenstein/is_integral.lean
8c44b9246e35d1ff28bfb72229691695920115cd
[ "Apache-2.0" ]
permissive
kbuzzard/mathlib
2ff9e85dfe2a46f4b291927f983afec17e946eb8
58537299e922f9c77df76cb613910914a479c1f7
refs/heads/master
1,685,313,702,744
1,683,974,212,000
1,683,974,212,000
128,185,277
1
0
null
1,522,920,600,000
1,522,920,600,000
null
UTF-8
Lean
false
false
20,271
lean
/- Copyright (c) 2022 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import data.nat.choose.dvd import ring_theory.integrally_closed import ring_theory.norm import ring_theory.polynomial.cyclotomic.basic /-! # Eisenstein polynomials In this file we gather more miscellaneous results about Eisenstein polynomials ## Main results * `mem_adjoin_of_smul_prime_pow_smul_of_minpoly_is_eiseinstein_at`: let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of `B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `p ^ n β€’ z ∈ adjoin R {B.gen}`, then `z ∈ adjoin R {B.gen}`. Together with `algebra.discr_mul_is_integral_mem_adjoin` this result often allows to compute the ring of integers of `L`. -/ universes u v w z variables {R : Type u} open ideal algebra finset open_locale big_operators polynomial section cyclotomic variables (p : β„•) local notation `π“Ÿ` := submodule.span β„€ {p} open polynomial lemma cyclotomic_comp_X_add_one_is_eisenstein_at [hp : fact p.prime] : ((cyclotomic p β„€).comp (X + 1)).is_eisenstein_at π“Ÿ := begin refine monic.is_eisenstein_at_of_mem_of_not_mem _ (ideal.is_prime.ne_top $(ideal.span_singleton_prime (by exact_mod_cast hp.out.ne_zero)).2 $ nat.prime_iff_prime_int.1 hp.out) (Ξ» i hi, _) _, { rw [show (X + 1 : β„€[X]) = X + C 1, by simp], refine ((cyclotomic.monic p β„€).comp (monic_X_add_C 1) (Ξ» h, _)), rw [nat_degree_X_add_C] at h, exact zero_ne_one h.symm }, { rw [cyclotomic_prime, geom_sum_X_comp_X_add_one_eq_sum, ← lcoeff_apply, linear_map.map_sum], conv { congr, congr, skip, funext, rw [lcoeff_apply, ← C_eq_nat_cast, C_mul_X_pow_eq_monomial, coeff_monomial] }, rw [nat_degree_comp, show (X + 1 : β„€[X]) = X + C 1, by simp, nat_degree_X_add_C, mul_one, nat_degree_cyclotomic, nat.totient_prime hp.out] at hi, simp only [hi.trans_le (nat.sub_le _ _), sum_ite_eq', mem_range, if_true, ideal.submodule_span_eq, ideal.mem_span_singleton, int.coe_nat_dvd], exact hp.out.dvd_choose_self i.succ_ne_zero (lt_tsub_iff_right.1 hi) }, { rw [coeff_zero_eq_eval_zero, eval_comp, cyclotomic_prime, eval_add, eval_X, eval_one, zero_add, eval_geom_sum, one_geom_sum, ideal.submodule_span_eq, ideal.span_singleton_pow, ideal.mem_span_singleton], intro h, obtain ⟨k, hk⟩ := int.coe_nat_dvd.1 h, rw [← mul_assoc, mul_one, mul_assoc] at hk, nth_rewrite 0 [← nat.mul_one p] at hk, rw [mul_right_inj' hp.out.ne_zero] at hk, exact nat.prime.not_dvd_one hp.out (dvd.intro k (hk.symm)) } end lemma cyclotomic_prime_pow_comp_X_add_one_is_eisenstein_at [hp : fact p.prime] (n : β„•) : ((cyclotomic (p ^ (n + 1)) β„€).comp (X + 1)).is_eisenstein_at π“Ÿ := begin refine monic.is_eisenstein_at_of_mem_of_not_mem _ (ideal.is_prime.ne_top $(ideal.span_singleton_prime (by exact_mod_cast hp.out.ne_zero)).2 $ nat.prime_iff_prime_int.1 hp.out) _ _, { rw [show (X + 1 : β„€[X]) = X + C 1, by simp], refine ((cyclotomic.monic _ β„€).comp (monic_X_add_C 1) (Ξ» h, _)), rw [nat_degree_X_add_C] at h, exact zero_ne_one h.symm }, { induction n with n hn, { intros i hi, rw [zero_add, pow_one] at hi ⊒, exact (cyclotomic_comp_X_add_one_is_eisenstein_at p).mem hi }, { intros i hi, rw [ideal.submodule_span_eq, ideal.mem_span_singleton, ← zmod.int_coe_zmod_eq_zero_iff_dvd, ← int.coe_cast_ring_hom, ← coeff_map, map_comp, map_cyclotomic, polynomial.map_add, map_X, polynomial.map_one, pow_add, pow_one, cyclotomic_mul_prime_dvd_eq_pow, pow_comp, ← zmod.expand_card, coeff_expand hp.out.pos], { simp only [ite_eq_right_iff], rintro ⟨k, hk⟩, rw [nat_degree_comp, show (X + 1 : β„€[X]) = X + C 1, by simp, nat_degree_X_add_C, mul_one, nat_degree_cyclotomic, nat.totient_prime_pow hp.out (nat.succ_pos _), nat.succ_sub_one] at hn hi, rw [hk, pow_succ, mul_assoc] at hi, rw [hk, mul_comm, nat.mul_div_cancel _ hp.out.pos], replace hn := hn (lt_of_mul_lt_mul_left' hi), rw [ideal.submodule_span_eq, ideal.mem_span_singleton, ← zmod.int_coe_zmod_eq_zero_iff_dvd, ← int.coe_cast_ring_hom, ← coeff_map] at hn, simpa [map_comp] using hn }, { exact ⟨p ^ n, by rw [pow_succ]⟩ } } }, { rw [coeff_zero_eq_eval_zero, eval_comp, cyclotomic_prime_pow_eq_geom_sum hp.out, eval_add, eval_X, eval_one, zero_add, eval_finset_sum], simp only [eval_pow, eval_X, one_pow, sum_const, card_range, nat.smul_one_eq_coe, submodule_span_eq, ideal.submodule_span_eq, ideal.span_singleton_pow, ideal.mem_span_singleton], intro h, obtain ⟨k, hk⟩ := int.coe_nat_dvd.1 h, rw [← mul_assoc, mul_one, mul_assoc] at hk, nth_rewrite 0 [← nat.mul_one p] at hk, rw [mul_right_inj' hp.out.ne_zero] at hk, exact nat.prime.not_dvd_one hp.out (dvd.intro k (hk.symm)) } end end cyclotomic section is_integral variables {K : Type v} {L : Type z} {p : R} [comm_ring R] [field K] [field L] variables [algebra K L] [algebra R L] [algebra R K] [is_scalar_tower R K L] [is_separable K L] variables [is_domain R] [is_fraction_ring R K] [is_integrally_closed R] local notation `π“Ÿ` := submodule.span R {p} open is_integrally_closed power_basis nat polynomial is_scalar_tower /-- Let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of `B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `Q : R[X]` is such that `aeval B.gen Q = p β€’ z`, then `p ∣ Q.coeff 0`. -/ lemma dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_is_eiseinstein_at {B : power_basis K L} (hp : prime p) (hBint : is_integral R B.gen) {z : L} {Q : R[X]} (hQ : aeval B.gen Q = p β€’ z) (hzint : is_integral R z) (hei : (minpoly R B.gen).is_eisenstein_at π“Ÿ) : p ∣ Q.coeff 0 := begin -- First define some abbreviations. letI := B.finite_dimensional, let P := minpoly R B.gen, obtain ⟨n , hn⟩ := nat.exists_eq_succ_of_ne_zero B.dim_pos.ne', have finrank_K_L : finite_dimensional.finrank K L = B.dim := B.finrank, have deg_K_P : (minpoly K B.gen).nat_degree = B.dim := B.nat_degree_minpoly, have deg_R_P : P.nat_degree = B.dim, { rw [← deg_K_P, minpoly.is_integrally_closed_eq_field_fractions' K hBint, (minpoly.monic hBint).nat_degree_map (algebra_map R K)] }, choose! f hf using hei.is_weakly_eisenstein_at.exists_mem_adjoin_mul_eq_pow_nat_degree_le (minpoly.aeval R B.gen) (minpoly.monic hBint), simp only [(minpoly.monic hBint).nat_degree_map, deg_R_P] at hf, -- The Eisenstein condition shows that `p` divides `Q.coeff 0` -- if `p^n.succ` divides the following multiple of `Q.coeff 0^n.succ`: suffices : p ^ n.succ ∣ (Q.coeff 0 ^ n.succ * ((-1) ^ (n.succ * n) * (minpoly R B.gen).coeff 0 ^ n)), { have hndiv : Β¬ p ^ 2 ∣ ((minpoly R B.gen)).coeff 0 := Ξ» h, hei.not_mem ((span_singleton_pow p 2).symm β–Έ (ideal.mem_span_singleton.2 h)), refine prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd hp ((_ : _ ^ n.succ ∣ _)) hndiv, convert (is_unit.dvd_mul_right ⟨(-1) ^ (n.succ * n), rfl⟩).mpr this using 1, push_cast, ring_nf, simp [pow_right_comm _ _ 2] }, -- We claim the quotient of `Q^n * _` by `p^n` is the following `r`: have aux : βˆ€ i ∈ (range (Q.nat_degree + 1)).erase 0, B.dim ≀ i + n, { intros i hi, simp only [mem_range, mem_erase] at hi, rw [hn], exact le_add_pred_of_pos _ hi.1 }, have hintsum : is_integral R (z * B.gen ^ n - βˆ‘ (x : β„•) in (range (Q.nat_degree + 1)).erase 0, Q.coeff x β€’ f (x + n)), { refine is_integral_sub (is_integral_mul hzint (is_integral.pow hBint _)) (is_integral.sum _ (Ξ» i hi, (is_integral_smul _ _))), exact adjoin_le_integral_closure hBint (hf _ (aux i hi)).1 }, obtain ⟨r, hr⟩ := is_integral_iff.1 (is_integral_norm K hintsum), use r, -- Do the computation in `K` so we can work in terms of `z` instead of `r`. apply is_fraction_ring.injective R K, simp only [_root_.map_mul, _root_.map_pow, _root_.map_neg, _root_.map_one], -- Both sides are actually norms: calc _ = norm K (Q.coeff 0 β€’ B.gen ^ n) : _ ... = norm K (p β€’ (z * B.gen ^ n) - βˆ‘ (x : β„•) in (range (Q.nat_degree + 1)).erase 0, p β€’ Q.coeff x β€’ f (x + n)) : congr_arg (norm K) (eq_sub_of_add_eq _) ... = _ : _, { simp only [algebra.smul_def, algebra_map_apply R K L, algebra.norm_algebra_map, _root_.map_mul, _root_.map_pow, finrank_K_L, power_basis.norm_gen_eq_coeff_zero_minpoly, minpoly.is_integrally_closed_eq_field_fractions' K hBint, coeff_map, ← hn], ring_exp }, swap, { simp_rw [← smul_sum, ← smul_sub, algebra.smul_def p, algebra_map_apply R K L, _root_.map_mul, algebra.norm_algebra_map, finrank_K_L, hr, ← hn] }, calc _ = (Q.coeff 0 β€’ 1 + βˆ‘ (x : β„•) in (range (Q.nat_degree + 1)).erase 0, Q.coeff x β€’ B.gen ^ x) * B.gen ^ n : _ ... = (Q.coeff 0 β€’ B.gen ^ 0 + βˆ‘ (x : β„•) in (range (Q.nat_degree + 1)).erase 0, Q.coeff x β€’ B.gen ^ x) * B.gen ^ n : by rw pow_zero ... = (aeval B.gen Q) * B.gen ^ n : _ ... = _ : by rw [hQ, algebra.smul_mul_assoc], { have : βˆ€ i ∈ (range (Q.nat_degree + 1)).erase 0, Q.coeff i β€’ (B.gen ^ i * B.gen ^ n) = p β€’ Q.coeff i β€’ f (i + n), { intros i hi, rw [←pow_add, ←(hf _ (aux i hi)).2, ←algebra.smul_def, smul_smul, mul_comm _ p, smul_smul] }, simp only [add_mul, smul_mul_assoc, one_mul, sum_mul, sum_congr rfl this] }, { rw [aeval_eq_sum_range, finset.add_sum_erase (range (Q.nat_degree + 1)) (Ξ» i, Q.coeff i β€’ B.gen ^ i)], simp }, end lemma mem_adjoin_of_dvd_coeff_of_dvd_aeval {A B : Type*} [comm_semiring A] [comm_ring B] [algebra A B] [no_zero_smul_divisors A B] {Q : A[X]} {p : A} {x z : B} (hp : p β‰  0) (hQ : βˆ€ i ∈ range (Q.nat_degree + 1), p ∣ Q.coeff i) (hz : aeval x Q = p β€’ z) : z ∈ adjoin A ({x} : set B) := begin choose! f hf using hQ, rw [aeval_eq_sum_range, sum_range] at hz, conv_lhs at hz { congr, skip, funext, rw [hf i (mem_range.2 (fin.is_lt i)), ← smul_smul] }, rw [← smul_sum] at hz, rw [← smul_right_injective _ hp hz], exact subalgebra.sum_mem _ (Ξ» _ _, subalgebra.smul_mem _ (subalgebra.pow_mem _ (subset_adjoin (set.mem_singleton _)) _) _) end /-- Let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of `B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `p β€’ z ∈ adjoin R {B.gen}`, then `z ∈ adjoin R {B.gen}`. -/ lemma mem_adjoin_of_smul_prime_smul_of_minpoly_is_eiseinstein_at {B : power_basis K L} (hp : prime p) (hBint : is_integral R B.gen) {z : L} (hzint : is_integral R z) (hz : p β€’ z ∈ adjoin R ({B.gen} : set L)) (hei : (minpoly R B.gen).is_eisenstein_at π“Ÿ) : z ∈ adjoin R ({B.gen} : set L) := begin -- First define some abbreviations. have hndiv : Β¬ p ^ 2 ∣ ((minpoly R B.gen)).coeff 0 := Ξ» h, hei.not_mem ((span_singleton_pow p 2).symm β–Έ (ideal.mem_span_singleton.2 h)), letI := finite_dimensional B, set P := minpoly R B.gen with hP, obtain ⟨n , hn⟩ := nat.exists_eq_succ_of_ne_zero B.dim_pos.ne', haveI : no_zero_smul_divisors R L := no_zero_smul_divisors.trans R K L, let P₁ := P.map (algebra_map R L), -- There is a polynomial `Q` such that `p β€’ z = aeval B.gen Q`. We can assume that -- `Q.degree < P.degree` and `Q β‰  0`. rw [adjoin_singleton_eq_range_aeval] at hz, obtain ⟨Q₁, hQ⟩ := hz, set Q := Q₁ %β‚˜ P with hQ₁, replace hQ : aeval B.gen Q = p β€’ z, { rw [← mod_by_monic_add_div Q₁ (minpoly.monic hBint)] at hQ, simpa using hQ }, by_cases hQzero : Q = 0, { simp only [hQzero, algebra.smul_def, zero_eq_mul, aeval_zero] at hQ, cases hQ with H H₁, { have : function.injective (algebra_map R L), { rw [algebra_map_eq R K L], exact (algebra_map K L).injective.comp (is_fraction_ring.injective R K) }, exfalso, exact hp.ne_zero ((injective_iff_map_eq_zero _).1 this _ H) }, { rw [H₁], exact subalgebra.zero_mem _ } }, -- It is enough to prove that all coefficients of `Q` are divisible by `p`, by induction. -- The base case is `dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_is_eiseinstein_at`. refine mem_adjoin_of_dvd_coeff_of_dvd_aeval hp.ne_zero (Ξ» i, _) hQ, refine nat.case_strong_induction_on i _ (Ξ» j hind, _), { intro H, exact dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_is_eiseinstein_at hp hBint hQ hzint hei }, { intro hj, refine hp.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd _ hndiv, exact n, -- Two technical results we will need about `P.nat_degree` and `Q.nat_degree`. have H := degree_mod_by_monic_lt Q₁ (minpoly.monic hBint), rw [← hQ₁, ← hP] at H, replace H:= nat.lt_iff_add_one_le.1 (lt_of_lt_of_le (lt_of_le_of_lt (nat.lt_iff_add_one_le.1 (nat.lt_of_succ_lt_succ (mem_range.1 hj))) (lt_succ_self _)) (nat.lt_iff_add_one_le.1 (((nat_degree_lt_nat_degree_iff hQzero).2 H)))), rw [add_assoc] at H, have Hj : Q.nat_degree + 1 = j + 1 + (Q.nat_degree - j), { rw [← add_comm 1, ← add_comm 1, add_assoc, add_right_inj, ← nat.add_sub_assoc (nat.lt_of_succ_lt_succ (mem_range.1 hj)).le, add_comm, nat.add_sub_cancel] }, -- By induction hypothesis we can find `g : β„• β†’ R` such that -- `k ∈ range (j + 1) β†’ Q.coeff k β€’ B.gen ^ k = (algebra_map R L) p * g k β€’ B.gen ^ k`- choose! g hg using hind, replace hg : βˆ€ k ∈ range (j + 1), Q.coeff k β€’ B.gen ^ k = (algebra_map R L p) * (g k β€’ B.gen ^ k), { intros k hk, rw [hg k (mem_range_succ_iff.1 hk) (mem_range_succ_iff.2 (le_trans (mem_range_succ_iff.1 hk) (succ_le_iff.1 (mem_range_succ_iff.1 hj)).le)), algebra.smul_def, algebra.smul_def, ring_hom.map_mul, mul_assoc] }, -- Since `minpoly R B.gen` is Eiseinstein, we can find `f : β„• β†’ L` such that -- `(map (algebra_map R L) (minpoly R B.gen)).nat_degree ≀ i` implies `f i ∈ adjoin R {B.gen}` -- and `(algebra_map R L) p * f i = B.gen ^ i`. We will also need `hf₁`, a reformulation of this -- property. choose! f hf using (is_weakly_eisenstein_at.exists_mem_adjoin_mul_eq_pow_nat_degree_le (minpoly.aeval R B.gen) (minpoly.monic hBint) hei.is_weakly_eisenstein_at), have hf₁ : βˆ€ k ∈ (range (Q.nat_degree - j)).erase 0, Q.coeff (j + 1 + k) β€’ B.gen ^ (j + 1 + k) * B.gen ^ (P.nat_degree - (j + 2)) = (algebra_map R L) p * Q.coeff (j + 1 + k) β€’ f (k + P.nat_degree - 1), { intros k hk, rw [smul_mul_assoc, ← pow_add, ← nat.add_sub_assoc H, ← add_assoc j 1 1, add_comm (j + 1) 1, add_assoc (j + 1), add_comm _ (k + P.nat_degree), nat.add_sub_add_right, ← (hf (k + P.nat_degree - 1) _).2, mul_smul_comm], rw [(minpoly.monic hBint).nat_degree_map, add_comm, nat.add_sub_assoc, le_add_iff_nonneg_right], { exact nat.zero_le _ }, { refine one_le_iff_ne_zero.2 (Ξ» h, _), rw [h] at hk, simpa using hk }, { apply_instance } }, -- The Eisenstein condition shows that `p` divides `Q.coeff j` -- if `p^n.succ` divides the following multiple of `Q.coeff (succ j)^n.succ`: suffices : p ^ n.succ ∣ Q.coeff (succ j) ^ n.succ * (minpoly R B.gen).coeff 0 ^ (succ j + (P.nat_degree - (j + 2))), { convert this, rw [nat.succ_eq_add_one, add_assoc, ← nat.add_sub_assoc H, ← add_assoc, add_comm (j + 1), nat.add_sub_add_left, ← nat.add_sub_assoc, nat.add_sub_add_left, hP, ← (minpoly.monic hBint).nat_degree_map (algebra_map R K), ← minpoly.is_integrally_closed_eq_field_fractions' K hBint, nat_degree_minpoly, hn, nat.sub_one, nat.pred_succ], linarith }, -- Using `hQ : aeval B.gen Q = p β€’ z`, we write `p β€’ z` as a sum of terms of degree less than -- `j+1`, that are multiples of `p` by induction, and terms of degree at least `j+1`. rw [aeval_eq_sum_range, Hj, range_add, sum_union (disjoint_range_add_left_embedding _ _), sum_congr rfl hg, add_comm] at hQ, -- We multiply this equality by `B.gen ^ (P.nat_degree-(j+2))`, so we can use `hf₁` on the terms -- we didn't know were multiples of `p`, and we take the norm on both sides. replace hQ := congr_arg (Ξ» x, x * B.gen ^ (P.nat_degree - (j + 2))) hQ, simp_rw [sum_map, add_left_embedding_apply, add_mul, sum_mul, mul_assoc] at hQ, rw [← insert_erase (mem_range.2 (tsub_pos_iff_lt.2 $ nat.lt_of_succ_lt_succ $ mem_range.1 hj)), sum_insert (not_mem_erase 0 _), add_zero, sum_congr rfl hf₁, ← mul_sum, ← mul_sum, add_assoc, ← mul_add, smul_mul_assoc, ← pow_add, algebra.smul_def] at hQ, replace hQ := congr_arg (norm K) (eq_sub_of_add_eq hQ), -- We obtain an equality of elements of `K`, but everything is integral, so we can move to `R` -- and simplify `hQ`. have hintsum : is_integral R (z * B.gen ^ (P.nat_degree - (j + 2)) - (βˆ‘ (x : β„•) in (range (Q.nat_degree - j)).erase 0, Q.coeff (j + 1 + x) β€’ f (x + P.nat_degree - 1) + βˆ‘ (x : β„•) in range (j + 1), g x β€’ B.gen ^ x * B.gen ^ (P.nat_degree - (j + 2)))), { refine is_integral_sub (is_integral_mul hzint (is_integral.pow hBint _)) (is_integral_add (is_integral.sum _ (Ξ» k hk, is_integral_smul _ _)) (is_integral.sum _ (Ξ» k hk, is_integral_mul (is_integral_smul _ (is_integral.pow hBint _)) ((is_integral.pow hBint _))))), refine adjoin_le_integral_closure hBint (hf _ _).1, rw [(minpoly.monic hBint).nat_degree_map (algebra_map R L)], rw [add_comm, nat.add_sub_assoc, le_add_iff_nonneg_right], { exact zero_le _ }, { refine one_le_iff_ne_zero.2 (Ξ» h, _), rw [h] at hk, simpa using hk } }, obtain ⟨r, hr⟩ := is_integral_iff.1 (is_integral_norm K hintsum), rw [algebra.smul_def, mul_assoc, ← mul_sub, _root_.map_mul, algebra_map_apply R K L, map_pow, algebra.norm_algebra_map, _root_.map_mul, algebra_map_apply R K L, algebra.norm_algebra_map, finrank B, ← hr, power_basis.norm_gen_eq_coeff_zero_minpoly, minpoly.is_integrally_closed_eq_field_fractions' K hBint, coeff_map, show (-1 : K) = algebra_map R K (-1), by simp, ← map_pow, ← map_pow, ← _root_.map_mul, ← map_pow, ← _root_.map_mul, ← map_pow, ← _root_.map_mul] at hQ, -- We can now finish the proof. have hppdiv : p ^ B.dim ∣ p ^ B.dim * r := dvd_mul_of_dvd_left dvd_rfl _, rwa [← is_fraction_ring.injective R K hQ, mul_comm, ← units.coe_neg_one, mul_pow, ← units.coe_pow, ← units.coe_pow, mul_assoc, is_unit.dvd_mul_left _ _ _ ⟨_, rfl⟩, mul_comm, ← nat.succ_eq_add_one, hn] at hppdiv } end /-- Let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of `B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `p ^ n β€’ z ∈ adjoin R {B.gen}`, then `z ∈ adjoin R {B.gen}`. Together with `algebra.discr_mul_is_integral_mem_adjoin` this result often allows to compute the ring of integers of `L`. -/ lemma mem_adjoin_of_smul_prime_pow_smul_of_minpoly_is_eiseinstein_at {B : power_basis K L} (hp : prime p) (hBint : is_integral R B.gen) {n : β„•} {z : L} (hzint : is_integral R z) (hz : p ^ n β€’ z ∈ adjoin R ({B.gen} : set L)) (hei : (minpoly R B.gen).is_eisenstein_at π“Ÿ) : z ∈ adjoin R ({B.gen} : set L) := begin induction n with n hn, { simpa using hz }, { rw [pow_succ, mul_smul] at hz, exact hn (mem_adjoin_of_smul_prime_smul_of_minpoly_is_eiseinstein_at hp hBint (is_integral_smul _ hzint) hz hei) } end end is_integral
92978b051a7d3db53af12d07b0f1964e38fdcc8a
77c5b91fae1b966ddd1db969ba37b6f0e4901e88
/src/number_theory/padics/padic_norm.lean
72993046a604d091b3f8936455915d1dffa57902
[ "Apache-2.0" ]
permissive
dexmagic/mathlib
ff48eefc56e2412429b31d4fddd41a976eb287ce
7a5d15a955a92a90e1d398b2281916b9c41270b2
refs/heads/master
1,693,481,322,046
1,633,360,193,000
1,633,360,193,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
27,963
lean
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis -/ import algebra.order.absolute_value import algebra.field_power import ring_theory.int.basic import tactic.basic import tactic.ring_exp /-! # p-adic norm This file defines the p-adic valuation and the p-adic norm on β„š. The p-adic valuation on β„š is the difference of the multiplicities of `p` in the numerator and denominator of `q`. This function obeys the standard properties of a valuation, with the appropriate assumptions on p. The valuation induces a norm on β„š. This norm is a nonarchimedean absolute value. It takes values in {0} βˆͺ {1/p^k | k ∈ β„€}. ## Notations This file uses the local notation `/.` for `rat.mk`. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking `[fact (prime p)]` as a type class argument. ## References * [F. Q. GouΓͺva, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, norm, valuation -/ universe u open nat open_locale rat open multiplicity /-- For `p β‰  1`, the p-adic valuation of an integer `z β‰  0` is the largest natural number `n` such that p^n divides z. `padic_val_rat` defines the valuation of a rational `q` to be the valuation of `q.num` minus the valuation of `q.denom`. If `q = 0` or `p = 1`, then `padic_val_rat p q` defaults to 0. -/ def padic_val_rat (p : β„•) (q : β„š) : β„€ := if h : q β‰  0 ∧ p β‰  1 then (multiplicity (p : β„€) q.num).get (multiplicity.finite_int_iff.2 ⟨h.2, rat.num_ne_zero_of_ne_zero h.1⟩) - (multiplicity (p : β„€) q.denom).get (multiplicity.finite_int_iff.2 ⟨h.2, by exact_mod_cast rat.denom_ne_zero _⟩) else 0 /-- A simplification of the definition of `padic_val_rat p q` when `q β‰  0` and `p` is prime. -/ lemma padic_val_rat_def (p : β„•) [hp : fact p.prime] {q : β„š} (hq : q β‰  0) : padic_val_rat p q = (multiplicity (p : β„€) q.num).get (finite_int_iff.2 ⟨hp.1.ne_one, rat.num_ne_zero_of_ne_zero hq⟩) - (multiplicity (p : β„€) q.denom).get (finite_int_iff.2 ⟨hp.1.ne_one, by exact_mod_cast rat.denom_ne_zero _⟩) := dif_pos ⟨hq, hp.1.ne_one⟩ namespace padic_val_rat open multiplicity variables {p : β„•} /-- `padic_val_rat p q` is symmetric in `q`. -/ @[simp] protected lemma neg (q : β„š) : padic_val_rat p (-q) = padic_val_rat p q := begin unfold padic_val_rat, split_ifs, { simp [-add_comm]; refl }, { exfalso, simp * at * }, { exfalso, simp * at * }, { refl } end /-- `padic_val_rat p 1` is 0 for any `p`. -/ @[simp] protected lemma one : padic_val_rat p 1 = 0 := by unfold padic_val_rat; split_ifs; simp * /-- For `p β‰  0, p β‰  1, `padic_val_rat p p` is 1. -/ @[simp] lemma padic_val_rat_self (hp : 1 < p) : padic_val_rat p p = 1 := by unfold padic_val_rat; split_ifs; simp [*, nat.one_lt_iff_ne_zero_and_ne_one] at * /-- The p-adic value of an integer `z β‰  0` is the multiplicity of `p` in `z`. -/ lemma padic_val_rat_of_int (z : β„€) (hp : p β‰  1) (hz : z β‰  0) : padic_val_rat p (z : β„š) = (multiplicity (p : β„€) z).get (finite_int_iff.2 ⟨hp, hz⟩) := by rw [padic_val_rat, dif_pos]; simp *; refl end padic_val_rat /-- A convenience function for the case of `padic_val_rat` when both inputs are natural numbers. -/ def padic_val_nat (p : β„•) (n : β„•) : β„• := int.to_nat (padic_val_rat p n) section padic_val_nat /-- `padic_val_nat` is defined as an `int.to_nat` cast; this lemma ensures that the cast is well-behaved. -/ lemma zero_le_padic_val_rat_of_nat (p n : β„•) : 0 ≀ padic_val_rat p n := begin unfold padic_val_rat, split_ifs, { simp, }, { trivial, }, end /-- `padic_val_rat` coincides with `padic_val_nat`. -/ @[simp, norm_cast] lemma padic_val_rat_of_nat (p n : β„•) : ↑(padic_val_nat p n) = padic_val_rat p n := begin unfold padic_val_nat, rw int.to_nat_of_nonneg (zero_le_padic_val_rat_of_nat p n), end /-- A simplification of `padic_val_nat` when one input is prime, by analogy with `padic_val_rat_def`. -/ lemma padic_val_nat_def {p : β„•} [hp : fact p.prime] {n : β„•} (hn : n β‰  0) : padic_val_nat p n = (multiplicity p n).get (multiplicity.finite_nat_iff.2 ⟨nat.prime.ne_one hp.1, bot_lt_iff_ne_bot.mpr hn⟩) := begin have n_nonzero : (n : β„š) β‰  0, by simpa only [cast_eq_zero, ne.def], -- Infinite loop with @simp padic_val_rat_of_nat unless we restrict the available lemmas here, -- hence the very long list simpa only [ int.coe_nat_multiplicity p n, rat.coe_nat_denom n, (padic_val_rat_of_nat p n).symm, int.coe_nat_zero, int.coe_nat_inj', sub_zero, get_one_right, int.coe_nat_succ, zero_add, rat.coe_nat_num ] using padic_val_rat_def p n_nonzero, end lemma one_le_padic_val_nat_of_dvd {n p : nat} [prime : fact p.prime] (nonzero : n β‰  0) (div : p ∣ n) : 1 ≀ padic_val_nat p n := begin rw @padic_val_nat_def _ prime _ nonzero, let one_le_mul : _ ≀ multiplicity p n := @multiplicity.le_multiplicity_of_pow_dvd _ _ _ p n 1 (begin norm_num, exact div end), simp only [nat.cast_one] at one_le_mul, rcases one_le_mul with ⟨_, q⟩, dsimp at q, solve_by_elim, end @[simp] lemma padic_val_nat_zero (m : nat) : padic_val_nat m 0 = 0 := by simpa @[simp] lemma padic_val_nat_one (m : nat) : padic_val_nat m 1 = 0 := by simp [padic_val_nat] end padic_val_nat namespace padic_val_rat open multiplicity variables (p : β„•) [p_prime : fact p.prime] include p_prime /-- The multiplicity of `p : β„•` in `a : β„€` is finite exactly when `a β‰  0`. -/ lemma finite_int_prime_iff {p : β„•} [p_prime : fact p.prime] {a : β„€} : finite (p : β„€) a ↔ a β‰  0 := by simp [finite_int_iff, ne.symm (ne_of_lt (p_prime.1.one_lt))] /-- A rewrite lemma for `padic_val_rat p q` when `q` is expressed in terms of `rat.mk`. -/ protected lemma defn {q : β„š} {n d : β„€} (hqz : q β‰  0) (qdf : q = n /. d) : padic_val_rat p q = (multiplicity (p : β„€) n).get (finite_int_iff.2 ⟨ne.symm $ ne_of_lt p_prime.1.one_lt, Ξ» hn, by simp * at *⟩) - (multiplicity (p : β„€) d).get (finite_int_iff.2 ⟨ne.symm $ ne_of_lt p_prime.1.one_lt, Ξ» hd, by simp * at *⟩) := have hn : n β‰  0, from rat.mk_num_ne_zero_of_ne_zero hqz qdf, have hd : d β‰  0, from rat.mk_denom_ne_zero_of_ne_zero hqz qdf, let ⟨c, hc1, hc2⟩ := rat.num_denom_mk hn hd qdf in by rw [padic_val_rat, dif_pos]; simp [hc1, hc2, multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1), (ne.symm (ne_of_lt p_prime.1.one_lt)), hqz] /-- A rewrite lemma for `padic_val_rat p (q * r)` with conditions `q β‰  0`, `r β‰  0`. -/ protected lemma mul {q r : β„š} (hq : q β‰  0) (hr : r β‰  0) : padic_val_rat p (q * r) = padic_val_rat p q + padic_val_rat p r := have q*r = (q.num * r.num) /. (↑q.denom * ↑r.denom), by rw_mod_cast rat.mul_num_denom, have hq' : q.num /. q.denom β‰  0, by rw rat.num_denom; exact hq, have hr' : r.num /. r.denom β‰  0, by rw rat.num_denom; exact hr, have hp' : _root_.prime (p : β„€), from nat.prime_iff_prime_int.1 p_prime.1, begin rw [padic_val_rat.defn p (mul_ne_zero hq hr) this], conv_rhs { rw [←(@rat.num_denom q), padic_val_rat.defn p hq', ←(@rat.num_denom r), padic_val_rat.defn p hr'] }, rw [multiplicity.mul' hp', multiplicity.mul' hp']; simp [add_comm, add_left_comm, sub_eq_add_neg] end /-- A rewrite lemma for `padic_val_rat p (q^k) with condition `q β‰  0`. -/ protected lemma pow {q : β„š} (hq : q β‰  0) {k : β„•} : padic_val_rat p (q ^ k) = k * padic_val_rat p q := by induction k; simp [*, padic_val_rat.mul _ hq (pow_ne_zero _ hq), pow_succ, add_mul, add_comm] /-- A rewrite lemma for `padic_val_rat p (q⁻¹)` with condition `q β‰  0`. -/ protected lemma inv {q : β„š} (hq : q β‰  0) : padic_val_rat p (q⁻¹) = -padic_val_rat p q := by rw [eq_neg_iff_add_eq_zero, ← padic_val_rat.mul p (inv_ne_zero hq) hq, inv_mul_cancel hq, padic_val_rat.one] /-- A rewrite lemma for `padic_val_rat p (q / r)` with conditions `q β‰  0`, `r β‰  0`. -/ protected lemma div {q r : β„š} (hq : q β‰  0) (hr : r β‰  0) : padic_val_rat p (q / r) = padic_val_rat p q - padic_val_rat p r := by rw [div_eq_mul_inv, padic_val_rat.mul p hq (inv_ne_zero hr), padic_val_rat.inv p hr, sub_eq_add_neg] /-- A condition for `padic_val_rat p (n₁ / d₁) ≀ padic_val_rat p (nβ‚‚ / dβ‚‚), in terms of divisibility by `p^n`. -/ lemma padic_val_rat_le_padic_val_rat_iff {n₁ nβ‚‚ d₁ dβ‚‚ : β„€} (hn₁ : n₁ β‰  0) (hnβ‚‚ : nβ‚‚ β‰  0) (hd₁ : d₁ β‰  0) (hdβ‚‚ : dβ‚‚ β‰  0) : padic_val_rat p (n₁ /. d₁) ≀ padic_val_rat p (nβ‚‚ /. dβ‚‚) ↔ βˆ€ (n : β„•), ↑p ^ n ∣ n₁ * dβ‚‚ β†’ ↑p ^ n ∣ nβ‚‚ * d₁ := have hf1 : finite (p : β„€) (n₁ * dβ‚‚), from finite_int_prime_iff.2 (mul_ne_zero hn₁ hdβ‚‚), have hf2 : finite (p : β„€) (nβ‚‚ * d₁), from finite_int_prime_iff.2 (mul_ne_zero hnβ‚‚ hd₁), by conv { to_lhs, rw [padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hn₁ hd₁) rfl, padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hnβ‚‚ hdβ‚‚) rfl, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le], norm_cast, rw [← multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1) hf1, add_comm, ← multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1) hf2, enat.get_le_get, multiplicity_le_multiplicity_iff] } /-- Sufficient conditions to show that the p-adic valuation of `q` is less than or equal to the p-adic vlauation of `q + r`. -/ theorem le_padic_val_rat_add_of_le {q r : β„š} (hq : q β‰  0) (hr : r β‰  0) (hqr : q + r β‰  0) (h : padic_val_rat p q ≀ padic_val_rat p r) : padic_val_rat p q ≀ padic_val_rat p (q + r) := have hqn : q.num β‰  0, from rat.num_ne_zero_of_ne_zero hq, have hqd : (q.denom : β„€) β‰  0, by exact_mod_cast rat.denom_ne_zero _, have hrn : r.num β‰  0, from rat.num_ne_zero_of_ne_zero hr, have hrd : (r.denom : β„€) β‰  0, by exact_mod_cast rat.denom_ne_zero _, have hqreq : q + r = (((q.num * r.denom + q.denom * r.num : β„€)) /. (↑q.denom * ↑r.denom : β„€)), from rat.add_num_denom _ _, have hqrd : q.num * ↑(r.denom) + ↑(q.denom) * r.num β‰  0, from rat.mk_num_ne_zero_of_ne_zero hqr hqreq, begin conv_lhs { rw ←(@rat.num_denom q) }, rw [hqreq, padic_val_rat_le_padic_val_rat_iff p hqn hqrd hqd (mul_ne_zero hqd hrd), ← multiplicity_le_multiplicity_iff, mul_left_comm, multiplicity.mul (nat.prime_iff_prime_int.1 p_prime.1), add_mul], rw [←(@rat.num_denom q), ←(@rat.num_denom r), padic_val_rat_le_padic_val_rat_iff p hqn hrn hqd hrd, ← multiplicity_le_multiplicity_iff] at h, calc _ ≀ min (multiplicity ↑p (q.num * ↑(r.denom) * ↑(q.denom))) (multiplicity ↑p (↑(q.denom) * r.num * ↑(q.denom))) : (le_min (by rw [@multiplicity.mul _ _ _ _ (_ * _) _ (nat.prime_iff_prime_int.1 p_prime.1), add_comm]) (by rw [mul_assoc, @multiplicity.mul _ _ _ _ (q.denom : β„€) (_ * _) (nat.prime_iff_prime_int.1 p_prime.1)]; exact add_le_add_left h _)) ... ≀ _ : min_le_multiplicity_add end /-- The minimum of the valuations of `q` and `r` is less than or equal to the valuation of `q + r`. -/ theorem min_le_padic_val_rat_add {q r : β„š} (hq : q β‰  0) (hr : r β‰  0) (hqr : q + r β‰  0) : min (padic_val_rat p q) (padic_val_rat p r) ≀ padic_val_rat p (q + r) := (le_total (padic_val_rat p q) (padic_val_rat p r)).elim (Ξ» h, by rw [min_eq_left h]; exact le_padic_val_rat_add_of_le _ hq hr hqr h) (Ξ» h, by rw [min_eq_right h, add_comm]; exact le_padic_val_rat_add_of_le _ hr hq (by rwa add_comm) h) open_locale big_operators /-- A finite sum of rationals with positive p-adic valuation has positive p-adic valuation (if the sum is non-zero). -/ theorem sum_pos_of_pos {n : β„•} {F : β„• β†’ β„š} (hF : βˆ€ i, i < n β†’ 0 < padic_val_rat p (F i)) (hn0 : βˆ‘ i in finset.range n, F i β‰  0) : 0 < padic_val_rat p (βˆ‘ i in finset.range n, F i) := begin induction n with d hd, { exact false.elim (hn0 rfl) }, { rw finset.sum_range_succ at hn0 ⊒, by_cases h : βˆ‘ (x : β„•) in finset.range d, F x = 0, { rw [h, zero_add], exact hF d (lt_add_one _) }, { refine lt_of_lt_of_le _ (min_le_padic_val_rat_add p h (Ξ» h1, _) hn0), { refine lt_min (hd (Ξ» i hi, _) h) (hF d (lt_add_one _)), exact hF _ (lt_trans hi (lt_add_one _)) }, { have h2 := hF d (lt_add_one _), rw h1 at h2, exact lt_irrefl _ h2 } } } end end padic_val_rat namespace padic_val_nat /-- A rewrite lemma for `padic_val_nat p (q * r)` with conditions `q β‰  0`, `r β‰  0`. -/ protected lemma mul (p : β„•) [p_prime : fact p.prime] {q r : β„•} (hq : q β‰  0) (hr : r β‰  0) : padic_val_nat p (q * r) = padic_val_nat p q + padic_val_nat p r := begin apply int.coe_nat_inj, simp only [padic_val_rat_of_nat, nat.cast_mul], rw padic_val_rat.mul, norm_cast, exact cast_ne_zero.mpr hq, exact cast_ne_zero.mpr hr, end /-- Dividing out by a prime factor reduces the padic_val_nat by 1. -/ protected lemma div {p : β„•} [p_prime : fact p.prime] {b : β„•} (dvd : p ∣ b) : (padic_val_nat p (b / p)) = (padic_val_nat p b) - 1 := begin by_cases b_split : (b = 0), { simp [b_split], }, { have split_frac : padic_val_rat p (b / p) = padic_val_rat p b - padic_val_rat p p := padic_val_rat.div p (nat.cast_ne_zero.mpr b_split) (nat.cast_ne_zero.mpr (nat.prime.ne_zero p_prime.1)), rw padic_val_rat.padic_val_rat_self (nat.prime.one_lt p_prime.1) at split_frac, have r : 1 ≀ padic_val_nat p b := one_le_padic_val_nat_of_dvd b_split dvd, exact_mod_cast split_frac, } end /-- A version of `padic_val_rat.pow` for `padic_val_nat` -/ protected lemma pow (p q n : β„•) [fact p.prime] (hq : q β‰  0) : padic_val_nat p (q ^ n) = n * padic_val_nat p q := begin apply @nat.cast_injective β„€, push_cast, exact padic_val_rat.pow _ (cast_ne_zero.mpr hq), end end padic_val_nat section padic_val_nat /-- If a prime doesn't appear in `n`, `padic_val_nat p n` is `0`. -/ lemma padic_val_nat_of_not_dvd {p : β„•} [fact p.prime] {n : β„•} (not_dvd : Β¬(p ∣ n)) : padic_val_nat p n = 0 := begin by_cases hn : n = 0, { subst hn, simp at not_dvd, trivial, }, { rw padic_val_nat_def hn, exact (@multiplicity.unique' _ _ _ p n 0 (by simp) (by simpa using not_dvd)).symm, assumption, }, end lemma dvd_of_one_le_padic_val_nat {n p : nat} [prime : fact p.prime] (hp : 1 ≀ padic_val_nat p n) : p ∣ n := begin by_contra h, rw padic_val_nat_of_not_dvd h at hp, exact lt_irrefl 0 (lt_of_lt_of_le zero_lt_one hp), end lemma pow_padic_val_nat_dvd {p n : β„•} [fact (nat.prime p)] : p ^ (padic_val_nat p n) ∣ n := begin cases nat.eq_zero_or_pos n with hn hn, { rw hn, exact dvd_zero (p ^ padic_val_nat p 0) }, { rw multiplicity.pow_dvd_iff_le_multiplicity, apply le_of_eq, rw padic_val_nat_def (ne_of_gt hn), { apply enat.coe_get }, { apply_instance } } end lemma pow_succ_padic_val_nat_not_dvd {p n : β„•} [hp : fact (nat.prime p)] (hn : 0 < n) : Β¬ p ^ (padic_val_nat p n + 1) ∣ n := begin { rw multiplicity.pow_dvd_iff_le_multiplicity, rw padic_val_nat_def (ne_of_gt hn), { rw [nat.cast_add, enat.coe_get], simp only [nat.cast_one, not_le], apply enat.lt_add_one (ne_top_iff_finite.2 (finite_nat_iff.2 ⟨hp.elim.ne_one, hn⟩)) }, { apply_instance } } end lemma padic_val_nat_primes {p q : β„•} [p_prime : fact p.prime] [q_prime : fact q.prime] (neq : p β‰  q) : padic_val_nat p q = 0 := @padic_val_nat_of_not_dvd p p_prime q $ (not_congr (iff.symm (prime_dvd_prime_iff_eq p_prime.1 q_prime.1))).mp neq protected lemma padic_val_nat.div' {p : β„•} [p_prime : fact p.prime] : βˆ€ {m : β„•} (cpm : coprime p m) {b : β„•} (dvd : m ∣ b), padic_val_nat p (b / m) = padic_val_nat p b | 0 := Ξ» cpm b dvd, by { rw zero_dvd_iff at dvd, rw [dvd, nat.zero_div], } | (n + 1) := Ξ» cpm b dvd, begin rcases dvd with ⟨c, rfl⟩, rw [mul_div_right c (nat.succ_pos _)],by_cases hc : c = 0, { rw [hc, mul_zero] }, { rw padic_val_nat.mul, { suffices : Β¬ p ∣ (n+1), { rw [padic_val_nat_of_not_dvd this, zero_add] }, contrapose! cpm, exact p_prime.1.dvd_iff_not_coprime.mp cpm }, { exact nat.succ_ne_zero _ }, { exact hc } }, end lemma padic_val_nat_eq_factors_count (p : β„•) [hp : fact p.prime] : βˆ€ (n : β„•), padic_val_nat p n = (factors n).count p | 0 := by simp | 1 := by simp | (m + 2) := let n := m + 2 in let q := min_fac n in have hq : fact q.prime := ⟨min_fac_prime (show m + 2 β‰  1, by linarith)⟩, have wf : n / q < n := nat.div_lt_self (nat.succ_pos _) hq.1.one_lt, begin rw factors_add_two, show padic_val_nat p n = list.count p (q :: (factors (n / q))), rw [list.count_cons', ← padic_val_nat_eq_factors_count], split_ifs with h, have p_dvd_n : p ∣ n, { have: q ∣ n := nat.min_fac_dvd n, cc }, { rw [←h, padic_val_nat.div], { have: 1 ≀ padic_val_nat p n := one_le_padic_val_nat_of_dvd (by linarith) p_dvd_n, exact (nat.sub_eq_iff_eq_add this).mp rfl, }, { exact p_dvd_n, }, }, { suffices : p.coprime q, { rw [padic_val_nat.div' this (min_fac_dvd n), add_zero], }, rwa nat.coprime_primes hp.1 hq.1, }, end @[simp] lemma padic_val_nat_self (p : β„•) [fact p.prime] : padic_val_nat p p = 1 := by simp [padic_val_nat_def (fact.out p.prime).ne_zero] @[simp] lemma padic_val_nat_prime_pow (p n : β„•) [fact p.prime] : padic_val_nat p (p ^ n) = n := by rw [padic_val_nat.pow p _ _ (fact.out p.prime).ne_zero, padic_val_nat_self p, mul_one] open_locale big_operators lemma prod_pow_prime_padic_val_nat (n : nat) (hn : n β‰  0) (m : nat) (pr : n < m) : ∏ p in finset.filter nat.prime (finset.range m), p ^ (padic_val_nat p n) = n := begin rw ← pos_iff_ne_zero at hn, have H : (factors n : multiset β„•).prod = n, { rw [multiset.coe_prod, prod_factors hn], }, rw finset.prod_multiset_count at H, conv_rhs { rw ← H, }, refine finset.prod_bij_ne_one (Ξ» p hp hp', p) _ _ _ _, { rintro p hp hpn, rw [finset.mem_filter, finset.mem_range] at hp, rw [multiset.mem_to_finset, multiset.mem_coe, mem_factors_iff_dvd hn hp.2], contrapose! hpn, haveI Hp : fact p.prime := ⟨hp.2⟩, rw [padic_val_nat_of_not_dvd hpn, pow_zero], }, { intros, assumption }, { intros p hp hpn, rw [multiset.mem_to_finset, multiset.mem_coe] at hp, haveI Hp : fact p.prime := ⟨prime_of_mem_factors hp⟩, simp only [exists_prop, ne.def, finset.mem_filter, finset.mem_range], refine ⟨p, ⟨_, Hp.1⟩, ⟨_, rfl⟩⟩, { rw mem_factors_iff_dvd hn Hp.1 at hp, exact lt_of_le_of_lt (le_of_dvd hn hp) pr }, { rw padic_val_nat_eq_factors_count, simpa [ne.def, multiset.coe_count] using hpn } }, { intros p hp hpn, rw [finset.mem_filter, finset.mem_range] at hp, haveI Hp : fact p.prime := ⟨hp.2⟩, rw [padic_val_nat_eq_factors_count, multiset.coe_count] } end end padic_val_nat /-- If `q β‰  0`, the p-adic norm of a rational `q` is `p ^ (-(padic_val_rat p q))`. If `q = 0`, the p-adic norm of `q` is 0. -/ def padic_norm (p : β„•) (q : β„š) : β„š := if q = 0 then 0 else (↑p : β„š) ^ (-(padic_val_rat p q)) namespace padic_norm section padic_norm open padic_val_rat variables (p : β„•) /-- Unfolds the definition of the p-adic norm of `q` when `q β‰  0`. -/ @[simp] protected lemma eq_fpow_of_nonzero {q : β„š} (hq : q β‰  0) : padic_norm p q = p ^ (-(padic_val_rat p q)) := by simp [hq, padic_norm] /-- The p-adic norm is nonnegative. -/ protected lemma nonneg (q : β„š) : 0 ≀ padic_norm p q := if hq : q = 0 then by simp [hq, padic_norm] else begin unfold padic_norm; split_ifs, apply fpow_nonneg, exact_mod_cast nat.zero_le _ end /-- The p-adic norm of 0 is 0. -/ @[simp] protected lemma zero : padic_norm p 0 = 0 := by simp [padic_norm] /-- The p-adic norm of 1 is 1. -/ @[simp] protected lemma one : padic_norm p 1 = 1 := by simp [padic_norm] /-- The p-adic norm of `p` is `1/p` if `p > 1`. See also `padic_norm.padic_norm_p_of_prime` for a version that assumes `p` is prime. -/ lemma padic_norm_p {p : β„•} (hp : 1 < p) : padic_norm p p = 1 / p := by simp [padic_norm, (show p β‰  0, by linarith), padic_val_rat.padic_val_rat_self hp] /-- The p-adic norm of `p` is `1/p` if `p` is prime. See also `padic_norm.padic_norm_p` for a version that assumes `1 < p`. -/ @[simp] lemma padic_norm_p_of_prime (p : β„•) [fact p.prime] : padic_norm p p = 1 / p := padic_norm_p $ nat.prime.one_lt (fact.out _) /-- The p-adic norm of `q` is `1` if `q` is prime and not equal to `p`. -/ lemma padic_norm_of_prime_of_ne {p q : β„•} [p_prime : fact p.prime] [q_prime : fact q.prime] (neq : p β‰  q) : padic_norm p q = 1 := begin have p : padic_val_rat p q = 0, { exact_mod_cast @padic_val_nat_primes p q p_prime q_prime neq }, simp [padic_norm, p, q_prime.1.1, q_prime.1.ne_zero], end /-- The p-adic norm of `p` is less than 1 if `1 < p`. See also `padic_norm.padic_norm_p_lt_one_of_prime` for a version assuming `prime p`. -/ lemma padic_norm_p_lt_one {p : β„•} (hp : 1 < p) : padic_norm p p < 1 := begin rw [padic_norm_p hp, div_lt_iff, one_mul], { exact_mod_cast hp }, { exact_mod_cast zero_lt_one.trans hp }, end /-- The p-adic norm of `p` is less than 1 if `p` is prime. See also `padic_norm.padic_norm_p_lt_one` for a version assuming `1 < p`. -/ lemma padic_norm_p_lt_one_of_prime (p : β„•) [fact p.prime] : padic_norm p p < 1 := padic_norm_p_lt_one $ nat.prime.one_lt (fact.out _) /-- `padic_norm p q` takes discrete values `p ^ -z` for `z : β„€`. -/ protected theorem values_discrete {q : β„š} (hq : q β‰  0) : βˆƒ z : β„€, padic_norm p q = p ^ (-z) := ⟨ (padic_val_rat p q), by simp [padic_norm, hq] ⟩ /-- `padic_norm p` is symmetric. -/ @[simp] protected lemma neg (q : β„š) : padic_norm p (-q) = padic_norm p q := if hq : q = 0 then by simp [hq] else by simp [padic_norm, hq] variable [hp : fact p.prime] include hp /-- If `q β‰  0`, then `padic_norm p q β‰  0`. -/ protected lemma nonzero {q : β„š} (hq : q β‰  0) : padic_norm p q β‰  0 := begin rw padic_norm.eq_fpow_of_nonzero p hq, apply fpow_ne_zero_of_ne_zero, exact_mod_cast ne_of_gt hp.1.pos end /-- If the p-adic norm of `q` is 0, then `q` is 0. -/ lemma zero_of_padic_norm_eq_zero {q : β„š} (h : padic_norm p q = 0) : q = 0 := begin apply by_contradiction, intro hq, unfold padic_norm at h, rw if_neg hq at h, apply absurd h, apply fpow_ne_zero_of_ne_zero, exact_mod_cast hp.1.ne_zero end /-- The p-adic norm is multiplicative. -/ @[simp] protected theorem mul (q r : β„š) : padic_norm p (q*r) = padic_norm p q * padic_norm p r := if hq : q = 0 then by simp [hq] else if hr : r = 0 then by simp [hr] else have q*r β‰  0, from mul_ne_zero hq hr, have (↑p : β„š) β‰  0, by simp [hp.1.ne_zero], by simp [padic_norm, *, padic_val_rat.mul, fpow_add this, mul_comm] /-- The p-adic norm respects division. -/ @[simp] protected theorem div (q r : β„š) : padic_norm p (q / r) = padic_norm p q / padic_norm p r := if hr : r = 0 then by simp [hr] else eq_div_of_mul_eq (padic_norm.nonzero _ hr) (by rw [←padic_norm.mul, div_mul_cancel _ hr]) /-- The p-adic norm of an integer is at most 1. -/ protected theorem of_int (z : β„€) : padic_norm p ↑z ≀ 1 := if hz : z = 0 then by simp [hz, zero_le_one] else begin unfold padic_norm, rw [if_neg _], { refine fpow_le_one_of_nonpos _ _, { exact_mod_cast le_of_lt hp.1.one_lt, }, { rw [padic_val_rat_of_int _ hp.1.ne_one hz, neg_nonpos], norm_cast, simp }}, exact_mod_cast hz end private lemma nonarchimedean_aux {q r : β„š} (h : padic_val_rat p q ≀ padic_val_rat p r) : padic_norm p (q + r) ≀ max (padic_norm p q) (padic_norm p r) := have hnqp : padic_norm p q β‰₯ 0, from padic_norm.nonneg _ _, have hnrp : padic_norm p r β‰₯ 0, from padic_norm.nonneg _ _, if hq : q = 0 then by simp [hq, max_eq_right hnrp, le_max_right] else if hr : r = 0 then by simp [hr, max_eq_left hnqp, le_max_left] else if hqr : q + r = 0 then le_trans (by simpa [hqr] using hnqp) (le_max_left _ _) else begin unfold padic_norm, split_ifs, apply le_max_iff.2, left, apply fpow_le_of_le, { exact_mod_cast le_of_lt hp.1.one_lt }, { apply neg_le_neg, have : padic_val_rat p q = min (padic_val_rat p q) (padic_val_rat p r), from (min_eq_left h).symm, rw this, apply min_le_padic_val_rat_add; assumption } end /-- The p-adic norm is nonarchimedean: the norm of `p + q` is at most the max of the norm of `p` and the norm of `q`. -/ protected theorem nonarchimedean {q r : β„š} : padic_norm p (q + r) ≀ max (padic_norm p q) (padic_norm p r) := begin wlog hle := le_total (padic_val_rat p q) (padic_val_rat p r) using [q r], exact nonarchimedean_aux p hle end /-- The p-adic norm respects the triangle inequality: the norm of `p + q` is at most the norm of `p` plus the norm of `q`. -/ theorem triangle_ineq (q r : β„š) : padic_norm p (q + r) ≀ padic_norm p q + padic_norm p r := calc padic_norm p (q + r) ≀ max (padic_norm p q) (padic_norm p r) : padic_norm.nonarchimedean p ... ≀ padic_norm p q + padic_norm p r : max_le_add_of_nonneg (padic_norm.nonneg p _) (padic_norm.nonneg p _) /-- The p-adic norm of a difference is at most the max of each component. Restates the archimedean property of the p-adic norm. -/ protected theorem sub {q r : β„š} : padic_norm p (q - r) ≀ max (padic_norm p q) (padic_norm p r) := by rw [sub_eq_add_neg, ←padic_norm.neg p r]; apply padic_norm.nonarchimedean /-- If the p-adic norms of `q` and `r` are different, then the norm of `q + r` is equal to the max of the norms of `q` and `r`. -/ lemma add_eq_max_of_ne {q r : β„š} (hne : padic_norm p q β‰  padic_norm p r) : padic_norm p (q + r) = max (padic_norm p q) (padic_norm p r) := begin wlog hle := le_total (padic_norm p r) (padic_norm p q) using [q r], have hlt : padic_norm p r < padic_norm p q, from lt_of_le_of_ne hle hne.symm, have : padic_norm p q ≀ max (padic_norm p (q + r)) (padic_norm p r), from calc padic_norm p q = padic_norm p (q + r - r) : by congr; ring ... ≀ max (padic_norm p (q + r)) (padic_norm p (-r)) : padic_norm.nonarchimedean p ... = max (padic_norm p (q + r)) (padic_norm p r) : by simp, have hnge : padic_norm p r ≀ padic_norm p (q + r), { apply le_of_not_gt, intro hgt, rw max_eq_right_of_lt hgt at this, apply not_lt_of_ge this, assumption }, have : padic_norm p q ≀ padic_norm p (q + r), by rwa [max_eq_left hnge] at this, apply _root_.le_antisymm, { apply padic_norm.nonarchimedean p }, { rw max_eq_left_of_lt hlt, assumption } end /-- The p-adic norm is an absolute value: positive-definite and multiplicative, satisfying the triangle inequality. -/ instance : is_absolute_value (padic_norm p) := { abv_nonneg := padic_norm.nonneg p, abv_eq_zero := begin intros, constructor; intro, { apply zero_of_padic_norm_eq_zero p, assumption }, { simp [*] } end, abv_add := padic_norm.triangle_ineq p, abv_mul := padic_norm.mul p } variable {p} lemma dvd_iff_norm_le {n : β„•} {z : β„€} : ↑(p^n) ∣ z ↔ padic_norm p z ≀ ↑p ^ (-n : β„€) := begin unfold padic_norm, split_ifs with hz, { norm_cast at hz, have : 0 ≀ (p^n : β„š), {apply pow_nonneg, exact_mod_cast le_of_lt hp.1.pos }, simp [hz, this] }, { rw [fpow_le_iff_le, neg_le_neg_iff, padic_val_rat_of_int _ hp.1.ne_one _], { norm_cast, rw [← enat.coe_le_coe, enat.coe_get, ← multiplicity.pow_dvd_iff_le_multiplicity], simp }, { exact_mod_cast hz }, { exact_mod_cast hp.1.one_lt } } end end padic_norm end padic_norm
f794179dac7ea759404c8fe3a1f7bccefbbfb11d
1abd1ed12aa68b375cdef28959f39531c6e95b84
/src/analysis/inner_product_space/calculus.lean
4b3481ee4420bbe4fbb9d03dc606bd3bd35cd51d
[ "Apache-2.0" ]
permissive
jumpy4/mathlib
d3829e75173012833e9f15ac16e481e17596de0f
af36f1a35f279f0e5b3c2a77647c6bf2cfd51a13
refs/heads/master
1,693,508,842,818
1,636,203,271,000
1,636,203,271,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
11,392
lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import analysis.inner_product_space.basic import analysis.special_functions.sqrt /-! # Derivative of the inner product In this file we prove that the inner product and square of the norm in an inner space are infinitely `ℝ`-smooth. In order to state these results, we need a `normed_space ℝ E` instance. Though we can deduce this structure from `inner_product_space π•œ E`, this instance may be not definitionally equal to some other β€œnatural” instance. So, we assume `[normed_space ℝ E]` and `[is_scalar_tower ℝ π•œ E]`. In both interesting cases `π•œ = ℝ` and `π•œ = β„‚` we have these instances. -/ noncomputable theory open is_R_or_C real filter open_locale big_operators classical topological_space variables {π•œ E F : Type*} [is_R_or_C π•œ] variables [inner_product_space π•œ E] [inner_product_space ℝ F] local notation `βŸͺ`x`, `y`⟫` := @inner π•œ _ _ x y variables [normed_space ℝ E] [is_scalar_tower ℝ π•œ E] /-- Derivative of the inner product. -/ def fderiv_inner_clm (p : E Γ— E) : E Γ— E β†’L[ℝ] π•œ := is_bounded_bilinear_map_inner.deriv p @[simp] lemma fderiv_inner_clm_apply (p x : E Γ— E) : fderiv_inner_clm p x = βŸͺp.1, x.2⟫ + βŸͺx.1, p.2⟫ := rfl lemma times_cont_diff_inner {n} : times_cont_diff ℝ n (Ξ» p : E Γ— E, βŸͺp.1, p.2⟫) := is_bounded_bilinear_map_inner.times_cont_diff lemma times_cont_diff_at_inner {p : E Γ— E} {n} : times_cont_diff_at ℝ n (Ξ» p : E Γ— E, βŸͺp.1, p.2⟫) p := times_cont_diff_inner.times_cont_diff_at lemma differentiable_inner : differentiable ℝ (Ξ» p : E Γ— E, βŸͺp.1, p.2⟫) := is_bounded_bilinear_map_inner.differentiable_at variables {G : Type*} [normed_group G] [normed_space ℝ G] {f g : G β†’ E} {f' g' : G β†’L[ℝ] E} {s : set G} {x : G} {n : with_top β„•} include π•œ lemma times_cont_diff_within_at.inner (hf : times_cont_diff_within_at ℝ n f s x) (hg : times_cont_diff_within_at ℝ n g s x) : times_cont_diff_within_at ℝ n (Ξ» x, βŸͺf x, g x⟫) s x := times_cont_diff_at_inner.comp_times_cont_diff_within_at x (hf.prod hg) lemma times_cont_diff_at.inner (hf : times_cont_diff_at ℝ n f x) (hg : times_cont_diff_at ℝ n g x) : times_cont_diff_at ℝ n (Ξ» x, βŸͺf x, g x⟫) x := hf.inner hg lemma times_cont_diff_on.inner (hf : times_cont_diff_on ℝ n f s) (hg : times_cont_diff_on ℝ n g s) : times_cont_diff_on ℝ n (Ξ» x, βŸͺf x, g x⟫) s := Ξ» x hx, (hf x hx).inner (hg x hx) lemma times_cont_diff.inner (hf : times_cont_diff ℝ n f) (hg : times_cont_diff ℝ n g) : times_cont_diff ℝ n (Ξ» x, βŸͺf x, g x⟫) := times_cont_diff_inner.comp (hf.prod hg) lemma has_fderiv_within_at.inner (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) : has_fderiv_within_at (Ξ» t, βŸͺf t, g t⟫) ((fderiv_inner_clm (f x, g x)).comp $ f'.prod g') s x := (is_bounded_bilinear_map_inner.has_fderiv_at (f x, g x)).comp_has_fderiv_within_at x (hf.prod hg) lemma has_strict_fderiv_at.inner (hf : has_strict_fderiv_at f f' x) (hg : has_strict_fderiv_at g g' x) : has_strict_fderiv_at (Ξ» t, βŸͺf t, g t⟫) ((fderiv_inner_clm (f x, g x)).comp $ f'.prod g') x := (is_bounded_bilinear_map_inner.has_strict_fderiv_at (f x, g x)).comp x (hf.prod hg) lemma has_fderiv_at.inner (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) : has_fderiv_at (Ξ» t, βŸͺf t, g t⟫) ((fderiv_inner_clm (f x, g x)).comp $ f'.prod g') x := (is_bounded_bilinear_map_inner.has_fderiv_at (f x, g x)).comp x (hf.prod hg) lemma has_deriv_within_at.inner {f g : ℝ β†’ E} {f' g' : E} {s : set ℝ} {x : ℝ} (hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) : has_deriv_within_at (Ξ» t, βŸͺf t, g t⟫) (βŸͺf x, g'⟫ + βŸͺf', g x⟫) s x := by simpa using (hf.has_fderiv_within_at.inner hg.has_fderiv_within_at).has_deriv_within_at lemma has_deriv_at.inner {f g : ℝ β†’ E} {f' g' : E} {x : ℝ} : has_deriv_at f f' x β†’ has_deriv_at g g' x β†’ has_deriv_at (Ξ» t, βŸͺf t, g t⟫) (βŸͺf x, g'⟫ + βŸͺf', g x⟫) x := by simpa only [← has_deriv_within_at_univ] using has_deriv_within_at.inner lemma differentiable_within_at.inner (hf : differentiable_within_at ℝ f s x) (hg : differentiable_within_at ℝ g s x) : differentiable_within_at ℝ (Ξ» x, βŸͺf x, g x⟫) s x := ((differentiable_inner _).has_fderiv_at.comp_has_fderiv_within_at x (hf.prod hg).has_fderiv_within_at).differentiable_within_at lemma differentiable_at.inner (hf : differentiable_at ℝ f x) (hg : differentiable_at ℝ g x) : differentiable_at ℝ (Ξ» x, βŸͺf x, g x⟫) x := (differentiable_inner _).comp x (hf.prod hg) lemma differentiable_on.inner (hf : differentiable_on ℝ f s) (hg : differentiable_on ℝ g s) : differentiable_on ℝ (Ξ» x, βŸͺf x, g x⟫) s := Ξ» x hx, (hf x hx).inner (hg x hx) lemma differentiable.inner (hf : differentiable ℝ f) (hg : differentiable ℝ g) : differentiable ℝ (Ξ» x, βŸͺf x, g x⟫) := Ξ» x, (hf x).inner (hg x) lemma fderiv_inner_apply (hf : differentiable_at ℝ f x) (hg : differentiable_at ℝ g x) (y : G) : fderiv ℝ (Ξ» t, βŸͺf t, g t⟫) x y = βŸͺf x, fderiv ℝ g x y⟫ + βŸͺfderiv ℝ f x y, g x⟫ := by { rw [(hf.has_fderiv_at.inner hg.has_fderiv_at).fderiv], refl } lemma deriv_inner_apply {f g : ℝ β†’ E} {x : ℝ} (hf : differentiable_at ℝ f x) (hg : differentiable_at ℝ g x) : deriv (Ξ» t, βŸͺf t, g t⟫) x = βŸͺf x, deriv g x⟫ + βŸͺderiv f x, g x⟫ := (hf.has_deriv_at.inner hg.has_deriv_at).deriv lemma times_cont_diff_norm_sq : times_cont_diff ℝ n (Ξ» x : E, βˆ₯xβˆ₯ ^ 2) := begin simp only [sq, ← inner_self_eq_norm_sq], exact (re_clm : π•œ β†’L[ℝ] ℝ).times_cont_diff.comp (times_cont_diff_id.inner times_cont_diff_id) end lemma times_cont_diff.norm_sq (hf : times_cont_diff ℝ n f) : times_cont_diff ℝ n (Ξ» x, βˆ₯f xβˆ₯ ^ 2) := times_cont_diff_norm_sq.comp hf lemma times_cont_diff_within_at.norm_sq (hf : times_cont_diff_within_at ℝ n f s x) : times_cont_diff_within_at ℝ n (Ξ» y, βˆ₯f yβˆ₯ ^ 2) s x := times_cont_diff_norm_sq.times_cont_diff_at.comp_times_cont_diff_within_at x hf lemma times_cont_diff_at.norm_sq (hf : times_cont_diff_at ℝ n f x) : times_cont_diff_at ℝ n (Ξ» y, βˆ₯f yβˆ₯ ^ 2) x := hf.norm_sq lemma times_cont_diff_at_norm {x : E} (hx : x β‰  0) : times_cont_diff_at ℝ n norm x := have βˆ₯id xβˆ₯ ^ 2 β‰  0, from pow_ne_zero _ (norm_pos_iff.2 hx).ne', by simpa only [id, sqrt_sq, norm_nonneg] using times_cont_diff_at_id.norm_sq.sqrt this lemma times_cont_diff_at.norm (hf : times_cont_diff_at ℝ n f x) (h0 : f x β‰  0) : times_cont_diff_at ℝ n (Ξ» y, βˆ₯f yβˆ₯) x := (times_cont_diff_at_norm h0).comp x hf lemma times_cont_diff_at.dist (hf : times_cont_diff_at ℝ n f x) (hg : times_cont_diff_at ℝ n g x) (hne : f x β‰  g x) : times_cont_diff_at ℝ n (Ξ» y, dist (f y) (g y)) x := by { simp only [dist_eq_norm], exact (hf.sub hg).norm (sub_ne_zero.2 hne) } lemma times_cont_diff_within_at.norm (hf : times_cont_diff_within_at ℝ n f s x) (h0 : f x β‰  0) : times_cont_diff_within_at ℝ n (Ξ» y, βˆ₯f yβˆ₯) s x := (times_cont_diff_at_norm h0).comp_times_cont_diff_within_at x hf lemma times_cont_diff_within_at.dist (hf : times_cont_diff_within_at ℝ n f s x) (hg : times_cont_diff_within_at ℝ n g s x) (hne : f x β‰  g x) : times_cont_diff_within_at ℝ n (Ξ» y, dist (f y) (g y)) s x := by { simp only [dist_eq_norm], exact (hf.sub hg).norm (sub_ne_zero.2 hne) } lemma times_cont_diff_on.norm_sq (hf : times_cont_diff_on ℝ n f s) : times_cont_diff_on ℝ n (Ξ» y, βˆ₯f yβˆ₯ ^ 2) s := (Ξ» x hx, (hf x hx).norm_sq) lemma times_cont_diff_on.norm (hf : times_cont_diff_on ℝ n f s) (h0 : βˆ€ x ∈ s, f x β‰  0) : times_cont_diff_on ℝ n (Ξ» y, βˆ₯f yβˆ₯) s := Ξ» x hx, (hf x hx).norm (h0 x hx) lemma times_cont_diff_on.dist (hf : times_cont_diff_on ℝ n f s) (hg : times_cont_diff_on ℝ n g s) (hne : βˆ€ x ∈ s, f x β‰  g x) : times_cont_diff_on ℝ n (Ξ» y, dist (f y) (g y)) s := Ξ» x hx, (hf x hx).dist (hg x hx) (hne x hx) lemma times_cont_diff.norm (hf : times_cont_diff ℝ n f) (h0 : βˆ€ x, f x β‰  0) : times_cont_diff ℝ n (Ξ» y, βˆ₯f yβˆ₯) := times_cont_diff_iff_times_cont_diff_at.2 $ Ξ» x, hf.times_cont_diff_at.norm (h0 x) lemma times_cont_diff.dist (hf : times_cont_diff ℝ n f) (hg : times_cont_diff ℝ n g) (hne : βˆ€ x, f x β‰  g x) : times_cont_diff ℝ n (Ξ» y, dist (f y) (g y)) := times_cont_diff_iff_times_cont_diff_at.2 $ Ξ» x, hf.times_cont_diff_at.dist hg.times_cont_diff_at (hne x) omit π•œ lemma has_strict_fderiv_at_norm_sq (x : F) : has_strict_fderiv_at (Ξ» x, βˆ₯xβˆ₯ ^ 2) (bit0 (inner_right x)) x := begin simp only [sq, ← inner_self_eq_norm_sq], convert (has_strict_fderiv_at_id x).inner (has_strict_fderiv_at_id x), ext y, simp [bit0, real_inner_comm], end include π•œ lemma differentiable_at.norm_sq (hf : differentiable_at ℝ f x) : differentiable_at ℝ (Ξ» y, βˆ₯f yβˆ₯ ^ 2) x := (times_cont_diff_at_id.norm_sq.differentiable_at le_rfl).comp x hf lemma differentiable_at.norm (hf : differentiable_at ℝ f x) (h0 : f x β‰  0) : differentiable_at ℝ (Ξ» y, βˆ₯f yβˆ₯) x := ((times_cont_diff_at_norm h0).differentiable_at le_rfl).comp x hf lemma differentiable_at.dist (hf : differentiable_at ℝ f x) (hg : differentiable_at ℝ g x) (hne : f x β‰  g x) : differentiable_at ℝ (Ξ» y, dist (f y) (g y)) x := by { simp only [dist_eq_norm], exact (hf.sub hg).norm (sub_ne_zero.2 hne) } lemma differentiable.norm_sq (hf : differentiable ℝ f) : differentiable ℝ (Ξ» y, βˆ₯f yβˆ₯ ^ 2) := Ξ» x, (hf x).norm_sq lemma differentiable.norm (hf : differentiable ℝ f) (h0 : βˆ€ x, f x β‰  0) : differentiable ℝ (Ξ» y, βˆ₯f yβˆ₯) := Ξ» x, (hf x).norm (h0 x) lemma differentiable.dist (hf : differentiable ℝ f) (hg : differentiable ℝ g) (hne : βˆ€ x, f x β‰  g x) : differentiable ℝ (Ξ» y, dist (f y) (g y)) := Ξ» x, (hf x).dist (hg x) (hne x) lemma differentiable_within_at.norm_sq (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (Ξ» y, βˆ₯f yβˆ₯ ^ 2) s x := (times_cont_diff_at_id.norm_sq.differentiable_at le_rfl).comp_differentiable_within_at x hf lemma differentiable_within_at.norm (hf : differentiable_within_at ℝ f s x) (h0 : f x β‰  0) : differentiable_within_at ℝ (Ξ» y, βˆ₯f yβˆ₯) s x := ((times_cont_diff_at_id.norm h0).differentiable_at le_rfl).comp_differentiable_within_at x hf lemma differentiable_within_at.dist (hf : differentiable_within_at ℝ f s x) (hg : differentiable_within_at ℝ g s x) (hne : f x β‰  g x) : differentiable_within_at ℝ (Ξ» y, dist (f y) (g y)) s x := by { simp only [dist_eq_norm], exact (hf.sub hg).norm (sub_ne_zero.2 hne) } lemma differentiable_on.norm_sq (hf : differentiable_on ℝ f s) : differentiable_on ℝ (Ξ» y, βˆ₯f yβˆ₯ ^ 2) s := Ξ» x hx, (hf x hx).norm_sq lemma differentiable_on.norm (hf : differentiable_on ℝ f s) (h0 : βˆ€ x ∈ s, f x β‰  0) : differentiable_on ℝ (Ξ» y, βˆ₯f yβˆ₯) s := Ξ» x hx, (hf x hx).norm (h0 x hx) lemma differentiable_on.dist (hf : differentiable_on ℝ f s) (hg : differentiable_on ℝ g s) (hne : βˆ€ x ∈ s, f x β‰  g x) : differentiable_on ℝ (Ξ» y, dist (f y) (g y)) s := Ξ» x hx, (hf x hx).dist (hg x hx) (hne x hx)
cad9b8032d6fdb1cbd0670b92787820c4488f012
8b9f17008684d796c8022dab552e42f0cb6fb347
/tests/lean/run/local_eqns.lean
b2e205a627aad28fca86699053e76621d3ee5427
[ "Apache-2.0" ]
permissive
chubbymaggie/lean
0d06ae25f9dd396306fb02190e89422ea94afd7b
d2c7b5c31928c98f545b16420d37842c43b4ae9a
refs/heads/master
1,611,313,622,901
1,430,266,839,000
1,430,267,083,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,519
lean
import data.nat logic open bool nat check show nat β†’ bool | 0 := tt | (n+1) := ff definition mult : nat β†’ nat β†’ nat := have plus : nat β†’ nat β†’ nat | 0 b := b | (succ a) b := succ (plus a b), have mult : nat β†’ nat β†’ nat | 0 b := 0 | (succ a) b := plus (mult a b) b, mult print definition mult example : mult 3 7 = 21 := rfl example : mult 8 7 = 56 := rfl theorem add_eq_addl : βˆ€ x y, x + y = x βŠ• y | 0 0 := rfl | (succ x) 0 := begin have addl_z : βˆ€ a : nat, a βŠ• 0 = a | 0 := rfl | (succ a) := calc (succ a) βŠ• 0 = succ (a βŠ• 0) : rfl ... = succ a : addl_z, rewrite addl_z end | 0 (succ y) := begin have z_add : βˆ€ a : nat, 0 + a = a | 0 := rfl | (succ a) := begin rewrite β–Έ succ(0 + a) = _, rewrite z_add end, rewrite z_add end | (succ x) (succ y) := begin change (succ x + succ y = succ (x βŠ• succ y)), have s_add : βˆ€ a b : nat, succ a + b = succ (a + b) | 0 0 := rfl | (succ a) 0 := rfl | 0 (succ b) := begin change (succ (succ 0 + b) = succ (succ (0 + b))), rewrite -(s_add 0 b) end | (succ a) (succ b) := begin change (succ (succ (succ a) + b) = succ (succ (succ a + b))), apply (congr_arg succ), rewrite (s_add (succ a) b), end, rewrite [s_add, add_eq_addl] end print definition add_eq_addl
e1c13b6f595150062ad61b808a51d404cb644552
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/combinatorics/simple_graph/coloring.lean
aa904b1be943fbc8278c115348c0f0331b8ed7f9
[ "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
15,488
lean
/- Copyright (c) 2021 Arthur Paulino. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Arthur Paulino, Kyle Miller -/ import combinatorics.simple_graph.clique import data.nat.lattice import data.setoid.partition import order.antichain /-! # Graph Coloring This module defines colorings of simple graphs (also known as proper colorings in the literature). A graph coloring is the attribution of "colors" to all of its vertices such that adjacent vertices have different colors. A coloring can be represented as a homomorphism into a complete graph, whose vertices represent the colors. ## Main definitions * `G.coloring Ξ±` is the type of `Ξ±`-colorings of a simple graph `G`, with `Ξ±` being the set of available colors. The type is defined to be homomorphisms from `G` into the complete graph on `Ξ±`, and colorings have a coercion to `V β†’ Ξ±`. * `G.colorable n` is the proposition that `G` is `n`-colorable, which is whether there exists a coloring with at most *n* colors. * `G.chromatic_number` is the minimal `n` such that `G` is `n`-colorable, or `0` if it cannot be colored with finitely many colors. * `C.color_class c` is the set of vertices colored by `c : Ξ±` in the coloring `C : G.coloring Ξ±`. * `C.color_classes` is the set containing all color classes. ## Todo: * Gather material from: * https://github.com/leanprover-community/mathlib/blob/simple_graph_matching/src/combinatorics/simple_graph/coloring.lean * https://github.com/kmill/lean-graphcoloring/blob/master/src/graph.lean * Trees * Planar graphs * Chromatic polynomials * develop API for partial colorings, likely as colorings of subgraphs (`H.coe.coloring Ξ±`) -/ universes u v namespace simple_graph variables {V : Type u} (G : simple_graph V) /-- An `Ξ±`-coloring of a simple graph `G` is a homomorphism of `G` into the complete graph on `Ξ±`. This is also known as a proper coloring. -/ abbreviation coloring (Ξ± : Type v) := G β†’g (⊀ : simple_graph Ξ±) variables {G} {Ξ± : Type v} (C : G.coloring Ξ±) lemma coloring.valid {v w : V} (h : G.adj v w) : C v β‰  C w := C.map_rel h /-- Construct a term of `simple_graph.coloring` using a function that assigns vertices to colors and a proof that it is as proper coloring. (Note: this is a definitionally the constructor for `simple_graph.hom`, but with a syntactically better proper coloring hypothesis.) -/ @[pattern] def coloring.mk (color : V β†’ Ξ±) (valid : βˆ€ {v w : V}, G.adj v w β†’ color v β‰  color w) : G.coloring Ξ± := ⟨color, @valid⟩ /-- The color class of a given color. -/ def coloring.color_class (c : Ξ±) : set V := {v : V | C v = c} /-- The set containing all color classes. -/ def coloring.color_classes : set (set V) := (setoid.ker C).classes lemma coloring.mem_color_class (v : V) : v ∈ C.color_class (C v) := by exact rfl lemma coloring.color_classes_is_partition : setoid.is_partition C.color_classes := setoid.is_partition_classes (setoid.ker C) lemma coloring.mem_color_classes {v : V} : C.color_class (C v) ∈ C.color_classes := ⟨v, rfl⟩ lemma coloring.color_classes_finite [finite Ξ±] : C.color_classes.finite := setoid.finite_classes_ker _ lemma coloring.card_color_classes_le [fintype Ξ±] [fintype C.color_classes] : fintype.card C.color_classes ≀ fintype.card Ξ± := setoid.card_classes_ker_le C lemma coloring.not_adj_of_mem_color_class {c : Ξ±} {v w : V} (hv : v ∈ C.color_class c) (hw : w ∈ C.color_class c) : Β¬G.adj v w := Ξ» h, C.valid h (eq.trans hv (eq.symm hw)) lemma coloring.color_classes_independent (c : Ξ±) : is_antichain G.adj (C.color_class c) := Ξ» v hv w hw h, C.not_adj_of_mem_color_class hv hw -- TODO make this computable noncomputable instance [fintype V] [fintype Ξ±] : fintype (coloring G Ξ±) := begin classical, change fintype (rel_hom G.adj (⊀ : simple_graph Ξ±).adj), apply fintype.of_injective _ rel_hom.coe_fn_injective, apply_instance, end variables (G) /-- Whether a graph can be colored by at most `n` colors. -/ def colorable (n : β„•) : Prop := nonempty (G.coloring (fin n)) /-- The coloring of an empty graph. -/ def coloring_of_is_empty [is_empty V] : G.coloring Ξ± := coloring.mk is_empty_elim (Ξ» v, is_empty_elim) lemma colorable_of_is_empty [is_empty V] (n : β„•) : G.colorable n := ⟨G.coloring_of_is_empty⟩ lemma is_empty_of_colorable_zero (h : G.colorable 0) : is_empty V := begin split, intro v, obtain ⟨i, hi⟩ := h.some v, exact nat.not_lt_zero _ hi, end /-- The "tautological" coloring of a graph, using the vertices of the graph as colors. -/ def self_coloring : G.coloring V := coloring.mk id (Ξ» v w, G.ne_of_adj) /-- The chromatic number of a graph is the minimal number of colors needed to color it. If `G` isn't colorable with finitely many colors, this will be 0. -/ noncomputable def chromatic_number : β„• := Inf { n : β„• | G.colorable n } /-- Given an embedding, there is an induced embedding of colorings. -/ def recolor_of_embedding {Ξ± Ξ² : Type*} (f : Ξ± β†ͺ Ξ²) : G.coloring Ξ± β†ͺ G.coloring Ξ² := { to_fun := Ξ» C, (embedding.complete_graph f).to_hom.comp C, inj' := begin -- this was strangely painful; seems like missing lemmas about embeddings intros C C' h, dsimp only at h, ext v, apply (embedding.complete_graph f).inj', change ((embedding.complete_graph f).to_hom.comp C) v = _, rw h, refl, end } /-- Given an equivalence, there is an induced equivalence between colorings. -/ def recolor_of_equiv {Ξ± Ξ² : Type*} (f : Ξ± ≃ Ξ²) : G.coloring Ξ± ≃ G.coloring Ξ² := { to_fun := G.recolor_of_embedding f.to_embedding, inv_fun := G.recolor_of_embedding f.symm.to_embedding, left_inv := Ξ» C, by { ext v, apply equiv.symm_apply_apply }, right_inv := Ξ» C, by { ext v, apply equiv.apply_symm_apply } } /-- There is a noncomputable embedding of `Ξ±`-colorings to `Ξ²`-colorings if `Ξ²` has at least as large a cardinality as `Ξ±`. -/ noncomputable def recolor_of_card_le {Ξ± Ξ² : Type*} [fintype Ξ±] [fintype Ξ²] (hn : fintype.card Ξ± ≀ fintype.card Ξ²) : G.coloring Ξ± β†ͺ G.coloring Ξ² := G.recolor_of_embedding $ (function.embedding.nonempty_of_card_le hn).some variables {G} lemma colorable.mono {n m : β„•} (h : n ≀ m) (hc : G.colorable n) : G.colorable m := ⟨G.recolor_of_card_le (by simp [h]) hc.some⟩ lemma coloring.to_colorable [fintype Ξ±] (C : G.coloring Ξ±) : G.colorable (fintype.card Ξ±) := ⟨G.recolor_of_card_le (by simp) C⟩ lemma colorable_of_fintype (G : simple_graph V) [fintype V] : G.colorable (fintype.card V) := G.self_coloring.to_colorable /-- Noncomputably get a coloring from colorability. -/ noncomputable def colorable.to_coloring [fintype Ξ±] {n : β„•} (hc : G.colorable n) (hn : n ≀ fintype.card Ξ±) : G.coloring Ξ± := begin rw ←fintype.card_fin n at hn, exact G.recolor_of_card_le hn hc.some, end lemma colorable.of_embedding {V' : Type*} {G' : simple_graph V'} (f : G β†ͺg G') {n : β„•} (h : G'.colorable n) : G.colorable n := ⟨(h.to_coloring (by simp)).comp f⟩ lemma colorable_iff_exists_bdd_nat_coloring (n : β„•) : G.colorable n ↔ βˆƒ (C : G.coloring β„•), βˆ€ v, C v < n := begin split, { rintro hc, have C : G.coloring (fin n) := hc.to_coloring (by simp), let f := embedding.complete_graph fin.coe_embedding, use f.to_hom.comp C, intro v, cases C with color valid, exact fin.is_lt (color v), }, { rintro ⟨C, Cf⟩, refine ⟨coloring.mk _ _⟩, { exact Ξ» v, ⟨C v, Cf v⟩, }, { rintro v w hvw, simp only [fin.mk_eq_mk, ne.def], exact C.valid hvw, } } end lemma colorable_set_nonempty_of_colorable {n : β„•} (hc : G.colorable n) : {n : β„• | G.colorable n}.nonempty := ⟨n, hc⟩ lemma chromatic_number_bdd_below : bdd_below {n : β„• | G.colorable n} := ⟨0, Ξ» _ _, zero_le _⟩ lemma chromatic_number_le_of_colorable {n : β„•} (hc : G.colorable n) : G.chromatic_number ≀ n := begin rw chromatic_number, apply cInf_le chromatic_number_bdd_below, fsplit, exact classical.choice hc, end lemma chromatic_number_le_card [fintype Ξ±] (C : G.coloring Ξ±) : G.chromatic_number ≀ fintype.card Ξ± := cInf_le chromatic_number_bdd_below C.to_colorable lemma colorable_chromatic_number {m : β„•} (hc : G.colorable m) : G.colorable G.chromatic_number := begin dsimp only [chromatic_number], rw nat.Inf_def, apply nat.find_spec, exact colorable_set_nonempty_of_colorable hc, end lemma colorable_chromatic_number_of_fintype (G : simple_graph V) [finite V] : G.colorable G.chromatic_number := by { casesI nonempty_fintype V, exact colorable_chromatic_number G.colorable_of_fintype } lemma chromatic_number_le_one_of_subsingleton (G : simple_graph V) [subsingleton V] : G.chromatic_number ≀ 1 := begin rw chromatic_number, apply cInf_le chromatic_number_bdd_below, fsplit, refine coloring.mk (Ξ» _, 0) _, intros v w, rw subsingleton.elim v w, simp, end lemma chromatic_number_eq_zero_of_isempty (G : simple_graph V) [is_empty V] : G.chromatic_number = 0 := begin rw ←nonpos_iff_eq_zero, apply cInf_le chromatic_number_bdd_below, apply colorable_of_is_empty, end lemma is_empty_of_chromatic_number_eq_zero (G : simple_graph V) [finite V] (h : G.chromatic_number = 0) : is_empty V := begin have h' := G.colorable_chromatic_number_of_fintype, rw h at h', exact G.is_empty_of_colorable_zero h', end lemma chromatic_number_pos [nonempty V] {n : β„•} (hc : G.colorable n) : 0 < G.chromatic_number := begin apply le_cInf (colorable_set_nonempty_of_colorable hc), intros m hm, by_contra h', simp only [not_le, nat.lt_one_iff] at h', subst h', obtain ⟨i, hi⟩ := hm.some (classical.arbitrary V), exact nat.not_lt_zero _ hi, end lemma colorable_of_chromatic_number_pos (h : 0 < G.chromatic_number) : G.colorable G.chromatic_number := begin obtain ⟨h, hn⟩ := nat.nonempty_of_pos_Inf h, exact colorable_chromatic_number hn, end lemma colorable.mono_left {G' : simple_graph V} (h : G ≀ G') {n : β„•} (hc : G'.colorable n) : G.colorable n := ⟨hc.some.comp (hom.map_spanning_subgraphs h)⟩ lemma colorable.chromatic_number_le_of_forall_imp {V' : Type*} {G' : simple_graph V'} {m : β„•} (hc : G'.colorable m) (h : βˆ€ n, G'.colorable n β†’ G.colorable n) : G.chromatic_number ≀ G'.chromatic_number := begin apply cInf_le chromatic_number_bdd_below, apply h, apply colorable_chromatic_number hc, end lemma colorable.chromatic_number_mono (G' : simple_graph V) {m : β„•} (hc : G'.colorable m) (h : G ≀ G') : G.chromatic_number ≀ G'.chromatic_number := hc.chromatic_number_le_of_forall_imp (Ξ» n, colorable.mono_left h) lemma colorable.chromatic_number_mono_of_embedding {V' : Type*} {G' : simple_graph V'} {n : β„•} (h : G'.colorable n) (f : G β†ͺg G') : G.chromatic_number ≀ G'.chromatic_number := h.chromatic_number_le_of_forall_imp (Ξ» _, colorable.of_embedding f) lemma chromatic_number_eq_card_of_forall_surj [fintype Ξ±] (C : G.coloring Ξ±) (h : βˆ€ (C' : G.coloring Ξ±), function.surjective C') : G.chromatic_number = fintype.card Ξ± := begin apply le_antisymm, { apply chromatic_number_le_card C, }, { by_contra hc, rw not_le at hc, obtain ⟨n, cn, hc⟩ := exists_lt_of_cInf_lt (colorable_set_nonempty_of_colorable C.to_colorable) hc, rw ←fintype.card_fin n at hc, have f := (function.embedding.nonempty_of_card_le (le_of_lt hc)).some, have C' := cn.some, specialize h (G.recolor_of_embedding f C'), change function.surjective (f ∘ C') at h, have h1 : function.surjective f := function.surjective.of_comp h, have h2 := fintype.card_le_of_surjective _ h1, exact nat.lt_le_antisymm hc h2, }, end lemma chromatic_number_bot [nonempty V] : (βŠ₯ : simple_graph V).chromatic_number = 1 := begin let C : (βŠ₯ : simple_graph V).coloring (fin 1) := coloring.mk (Ξ» _, 0) (Ξ» v w h, false.elim h), apply le_antisymm, { exact chromatic_number_le_card C, }, { exact chromatic_number_pos C.to_colorable, }, end @[simp] lemma chromatic_number_top [fintype V] : (⊀ : simple_graph V).chromatic_number = fintype.card V := begin apply chromatic_number_eq_card_of_forall_surj (self_coloring _), intro C, rw ←finite.injective_iff_surjective, intros v w, contrapose, intro h, exact C.valid h, end lemma chromatic_number_top_eq_zero_of_infinite (V : Type*) [infinite V] : (⊀ : simple_graph V).chromatic_number = 0 := begin let n := (⊀ : simple_graph V).chromatic_number, by_contra hc, replace hc := pos_iff_ne_zero.mpr hc, apply nat.not_succ_le_self n, convert_to (⊀ : simple_graph {m | m < n + 1}).chromatic_number ≀ _, { simp, }, refine (colorable_of_chromatic_number_pos hc).chromatic_number_mono_of_embedding _, apply embedding.complete_graph, exact (function.embedding.subtype _).trans (infinite.nat_embedding V), end /-- The bicoloring of a complete bipartite graph using whether a vertex is on the left or on the right. -/ def complete_bipartite_graph.bicoloring (V W : Type*) : (complete_bipartite_graph V W).coloring bool := coloring.mk (Ξ» v, v.is_right) begin intros v w, cases v; cases w; simp, end lemma complete_bipartite_graph.chromatic_number {V W : Type*} [nonempty V] [nonempty W] : (complete_bipartite_graph V W).chromatic_number = 2 := begin apply chromatic_number_eq_card_of_forall_surj (complete_bipartite_graph.bicoloring V W), intros C b, have v := classical.arbitrary V, have w := classical.arbitrary W, have h : (complete_bipartite_graph V W).adj (sum.inl v) (sum.inr w) := by simp, have hn := C.valid h, by_cases he : C (sum.inl v) = b, { exact ⟨_, he⟩ }, { by_cases he' : C (sum.inr w) = b, { exact ⟨_, he'⟩ }, { exfalso, cases b; simp only [eq_tt_eq_not_eq_ff, eq_ff_eq_not_eq_tt] at he he'; rw [he, he'] at hn; contradiction }, }, end /-! ### Cliques -/ lemma is_clique.card_le_of_coloring {s : finset V} (h : G.is_clique s) [fintype Ξ±] (C : G.coloring Ξ±) : s.card ≀ fintype.card Ξ± := begin rw is_clique_iff_induce_eq at h, have f : G.induce ↑s β†ͺg G := embedding.induce ↑s, rw h at f, convert fintype.card_le_of_injective _ (C.comp f.to_hom).injective_of_top_hom using 1, simp, end lemma is_clique.card_le_of_colorable {s : finset V} (h : G.is_clique s) {n : β„•} (hc : G.colorable n) : s.card ≀ n := begin convert h.card_le_of_coloring hc.some, simp, end -- TODO eliminate `finite V` constraint once chromatic numbers are refactored. -- This is just to ensure the chromatic number exists. lemma is_clique.card_le_chromatic_number [finite V] {s : finset V} (h : G.is_clique s) : s.card ≀ G.chromatic_number := by { casesI nonempty_fintype V, exact h.card_le_of_colorable G.colorable_chromatic_number_of_fintype } protected lemma colorable.clique_free {n m : β„•} (hc : G.colorable n) (hm : n < m) : G.clique_free m := begin by_contra h, simp only [clique_free, is_n_clique_iff, not_forall, not_not] at h, obtain ⟨s, h, rfl⟩ := h, exact nat.lt_le_antisymm hm (h.card_le_of_colorable hc), end -- TODO eliminate `finite V` constraint once chromatic numbers are refactored. -- This is just to ensure the chromatic number exists. lemma clique_free_of_chromatic_number_lt [finite V] {n : β„•} (hc : G.chromatic_number < n) : G.clique_free n := G.colorable_chromatic_number_of_fintype.clique_free hc end simple_graph
ee24ac07286e2fbec9dcf42703f23b4f21812148
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/data/list/bag_inter.lean
04308b5eed0b92f42590dbe4cfb7dd2bed815382
[ "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,824
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Scott Morrison -/ import data.list.basic /-! # List intersection This file provides basic results about `list.bag_inter` (definition in `data.list.defs`). `bag_inter l₁ lβ‚‚` is the list of elements that are in both `l₁` and `lβ‚‚`, counted with multiplicity and in the order they appear in `l₁`. For example, `bag_inter [0, 1, 2, 3, 2, 1, 0] [1, 0, 1, 4, 3] = [0, 1, 3, 1]` -/ open nat namespace list variables {Ξ± : Type*} [decidable_eq Ξ±] @[simp] theorem nil_bag_inter (l : list Ξ±) : [].bag_inter l = [] := by cases l; refl @[simp] theorem bag_inter_nil (l : list Ξ±) : l.bag_inter [] = [] := by cases l; refl @[simp] theorem cons_bag_inter_of_pos {a} (l₁ : list Ξ±) {lβ‚‚} (h : a ∈ lβ‚‚) : (a :: l₁).bag_inter lβ‚‚ = a :: l₁.bag_inter (lβ‚‚.erase a) := by cases lβ‚‚; exact if_pos h @[simp] theorem cons_bag_inter_of_neg {a} (l₁ : list Ξ±) {lβ‚‚} (h : a βˆ‰ lβ‚‚) : (a :: l₁).bag_inter lβ‚‚ = l₁.bag_inter lβ‚‚ := begin cases lβ‚‚, {simp only [bag_inter_nil]}, simp only [erase_of_not_mem h, list.bag_inter, if_neg h] end @[simp] theorem mem_bag_inter {a : Ξ±} : βˆ€ {l₁ lβ‚‚ : list Ξ±}, a ∈ l₁.bag_inter lβ‚‚ ↔ a ∈ l₁ ∧ a ∈ lβ‚‚ | [] lβ‚‚ := by simp only [nil_bag_inter, not_mem_nil, false_and] | (b :: l₁) lβ‚‚ := begin by_cases b ∈ lβ‚‚, { rw [cons_bag_inter_of_pos _ h, mem_cons_iff, mem_cons_iff, mem_bag_inter], by_cases ba : a = b, { simp only [ba, h, eq_self_iff_true, true_or, true_and] }, { simp only [mem_erase_of_ne ba, ba, false_or] } }, { rw [cons_bag_inter_of_neg _ h, mem_bag_inter, mem_cons_iff, or_and_distrib_right], symmetry, apply or_iff_right_of_imp, rintro ⟨rfl, h'⟩, exact h.elim h' } end @[simp] theorem count_bag_inter {a : Ξ±} : βˆ€ {l₁ lβ‚‚ : list Ξ±}, count a (l₁.bag_inter lβ‚‚) = min (count a l₁) (count a lβ‚‚) | [] lβ‚‚ := by simp | l₁ [] := by simp | (h₁ :: l₁) (hβ‚‚ :: lβ‚‚) := begin simp only [list.bag_inter, list.mem_cons_iff], by_cases p₁ : hβ‚‚ = h₁; by_cases pβ‚‚ : h₁ = a, { simp only [p₁, pβ‚‚, count_bag_inter, min_succ_succ, erase_cons_head, if_true, mem_cons_iff, count_cons_self, true_or, eq_self_iff_true] }, { simp only [p₁, ne.symm pβ‚‚, count_bag_inter, count_cons, erase_cons_head, if_true, mem_cons_iff, true_or, eq_self_iff_true, if_false] }, { rw pβ‚‚ at p₁, by_cases p₃ : a ∈ lβ‚‚, { simp only [p₁, ne.symm p₁, pβ‚‚, p₃, erase_cons, count_bag_inter, eq.symm (min_succ_succ _ _), succ_pred_eq_of_pos (count_pos.2 p₃), if_true, mem_cons_iff, false_or, count_cons_self, eq_self_iff_true, if_false, ne.def, not_false_iff, count_erase_self, list.count_cons_of_ne] }, { simp [ne.symm p₁, pβ‚‚, p₃] } }, { by_cases pβ‚„ : h₁ ∈ lβ‚‚; simp only [ne.symm p₁, ne.symm pβ‚‚, pβ‚„, count_bag_inter, if_true, if_false, mem_cons_iff, false_or, eq_self_iff_true, ne.def, not_false_iff,count_erase_of_ne, count_cons_of_ne] } end theorem bag_inter_sublist_left : βˆ€ l₁ lβ‚‚ : list Ξ±, l₁.bag_inter lβ‚‚ <+ l₁ | [] lβ‚‚ := by simp [nil_sublist] | (b :: l₁) lβ‚‚ := begin by_cases b ∈ lβ‚‚; simp [h], { apply cons_sublist_cons, apply bag_inter_sublist_left }, { apply sublist_cons_of_sublist, apply bag_inter_sublist_left } end theorem bag_inter_nil_iff_inter_nil : βˆ€ l₁ lβ‚‚ : list Ξ±, l₁.bag_inter lβ‚‚ = [] ↔ l₁ ∩ lβ‚‚ = [] | [] lβ‚‚ := by simp | (b :: l₁) lβ‚‚ := begin by_cases h : b ∈ lβ‚‚; simp [h], exact bag_inter_nil_iff_inter_nil l₁ lβ‚‚ end end list
762e30c01200c132fb9483f15997286133a7deb5
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/data/list/permutation.lean
d42d45bd24b58873156fb536a15cf88efcdf2f7f
[ "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
10,899
lean
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import data.list.join /-! # Permutations of a list > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. In this file we prove properties about `list.permutations`, a list of all permutations of a list. It is defined in `data.list.defs`. ## Order of the permutations Designed for performance, the order in which the permutations appear in `list.permutations` is rather intricate and not very amenable to induction. That's why we also provide `list.permutations'` as a less efficient but more straightforward way of listing permutations. ### `list.permutations` TODO. In the meantime, you can try decrypting the docstrings. ### `list.permutations'` The list of partitions is built by recursion. The permutations of `[]` are `[[]]`. Then, the permutations of `a :: l` are obtained by taking all permutations of `l` in order and adding `a` in all positions. Hence, to build `[0, 1, 2, 3].permutations'`, it does * `[[]]` * `[[3]]` * `[[2, 3], [3, 2]]]` * `[[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]]` * `[[0, 1, 2, 3], [1, 0, 2, 3], [1, 2, 0, 3], [1, 2, 3, 0],` `[0, 2, 1, 3], [2, 0, 1, 3], [2, 1, 0, 3], [2, 1, 3, 0],` `[0, 2, 3, 1], [2, 0, 3, 1], [2, 3, 0, 1], [2, 3, 1, 0],` `[0, 1, 3, 2], [1, 0, 3, 2], [1, 3, 0, 2], [1, 3, 2, 0],` `[0, 3, 1, 2], [3, 0, 1, 2], [3, 1, 0, 2], [3, 1, 2, 0],` `[0, 3, 2, 1], [3, 0, 2, 1], [3, 2, 0, 1], [3, 2, 1, 0]]` ## TODO Show that `l.nodup β†’ l.permutations.nodup`. See `data.fintype.list`. -/ open nat variables {Ξ± Ξ² : Type*} namespace list lemma permutations_aux2_fst (t : Ξ±) (ts : list Ξ±) (r : list Ξ²) : βˆ€ (ys : list Ξ±) (f : list Ξ± β†’ Ξ²), (permutations_aux2 t ts r ys f).1 = ys ++ ts | [] f := rfl | (y::ys) f := match _, permutations_aux2_fst ys _ : βˆ€ o : list Ξ± Γ— list Ξ², o.1 = ys ++ ts β†’ (permutations_aux2._match_1 t y f o).1 = y :: ys ++ ts with | ⟨_, zs⟩, rfl := rfl end @[simp] lemma permutations_aux2_snd_nil (t : Ξ±) (ts : list Ξ±) (r : list Ξ²) (f : list Ξ± β†’ Ξ²) : (permutations_aux2 t ts r [] f).2 = r := rfl @[simp] lemma permutations_aux2_snd_cons (t : Ξ±) (ts : list Ξ±) (r : list Ξ²) (y : Ξ±) (ys : list Ξ±) (f : list Ξ± β†’ Ξ²) : (permutations_aux2 t ts r (y::ys) f).2 = f (t :: y :: ys ++ ts) :: (permutations_aux2 t ts r ys (Ξ»x : list Ξ±, f (y::x))).2 := match _, permutations_aux2_fst t ts r _ _ : βˆ€ o : list Ξ± Γ— list Ξ², o.1 = ys ++ ts β†’ (permutations_aux2._match_1 t y f o).2 = f (t :: y :: ys ++ ts) :: o.2 with | ⟨_, zs⟩, rfl := rfl end /-- The `r` argument to `permutations_aux2` is the same as appending. -/ lemma permutations_aux2_append (t : Ξ±) (ts : list Ξ±) (r : list Ξ²) (ys : list Ξ±) (f : list Ξ± β†’ Ξ²) : (permutations_aux2 t ts nil ys f).2 ++ r = (permutations_aux2 t ts r ys f).2 := by induction ys generalizing f; simp * /-- The `ts` argument to `permutations_aux2` can be folded into the `f` argument. -/ lemma permutations_aux2_comp_append {t : Ξ±} {ts ys : list Ξ±} {r : list Ξ²} (f : list Ξ± β†’ Ξ²) : (permutations_aux2 t [] r ys $ Ξ» x, f (x ++ ts)).2 = (permutations_aux2 t ts r ys f).2 := begin induction ys generalizing f, { simp }, { simp [ys_ih (Ξ» xs, f (ys_hd :: xs))] }, end lemma map_permutations_aux2' {Ξ± Ξ² Ξ±' Ξ²'} (g : Ξ± β†’ Ξ±') (g' : Ξ² β†’ Ξ²') (t : Ξ±) (ts ys : list Ξ±) (r : list Ξ²) (f : list Ξ± β†’ Ξ²) (f' : list Ξ±' β†’ Ξ²') (H : βˆ€ a, g' (f a) = f' (map g a)) : map g' (permutations_aux2 t ts r ys f).2 = (permutations_aux2 (g t) (map g ts) (map g' r) (map g ys) f').2 := begin induction ys generalizing f f'; simp *, apply ys_ih, simp [H], end /-- The `f` argument to `permutations_aux2` when `r = []` can be eliminated. -/ lemma map_permutations_aux2 (t : Ξ±) (ts : list Ξ±) (ys : list Ξ±) (f : list Ξ± β†’ Ξ²) : (permutations_aux2 t ts [] ys id).2.map f = (permutations_aux2 t ts [] ys f).2 := begin rw [map_permutations_aux2' id, map_id, map_id], refl, simp end /-- An expository lemma to show how all of `ts`, `r`, and `f` can be eliminated from `permutations_aux2`. `(permutations_aux2 t [] [] ys id).2`, which appears on the RHS, is a list whose elements are produced by inserting `t` into every non-terminal position of `ys` in order. As an example: ```lean #eval permutations_aux2 1 [] [] [2, 3, 4] id -- [[1, 2, 3, 4], [2, 1, 3, 4], [2, 3, 1, 4]] ``` -/ lemma permutations_aux2_snd_eq (t : Ξ±) (ts : list Ξ±) (r : list Ξ²) (ys : list Ξ±) (f : list Ξ± β†’ Ξ²) : (permutations_aux2 t ts r ys f).2 = (permutations_aux2 t [] [] ys id).2.map (Ξ» x, f (x ++ ts)) ++ r := by rw [← permutations_aux2_append, map_permutations_aux2, permutations_aux2_comp_append] lemma map_map_permutations_aux2 {Ξ± Ξ±'} (g : Ξ± β†’ Ξ±') (t : Ξ±) (ts ys : list Ξ±) : map (map g) (permutations_aux2 t ts [] ys id).2 = (permutations_aux2 (g t) (map g ts) [] (map g ys) id).2 := map_permutations_aux2' _ _ _ _ _ _ _ _ (Ξ» _, rfl) lemma map_map_permutations'_aux (f : Ξ± β†’ Ξ²) (t : Ξ±) (ts : list Ξ±) : map (map f) (permutations'_aux t ts) = permutations'_aux (f t) (map f ts) := by induction ts with a ts ih; [refl, {simp [← ih], refl}] lemma permutations'_aux_eq_permutations_aux2 (t : Ξ±) (ts : list Ξ±) : permutations'_aux t ts = (permutations_aux2 t [] [ts ++ [t]] ts id).2 := begin induction ts with a ts ih, {refl}, simp [permutations'_aux, permutations_aux2_snd_cons, ih], simp only [← permutations_aux2_append] {single_pass := tt}, simp [map_permutations_aux2], end lemma mem_permutations_aux2 {t : Ξ±} {ts : list Ξ±} {ys : list Ξ±} {l l' : list Ξ±} : l' ∈ (permutations_aux2 t ts [] ys (append l)).2 ↔ βˆƒ l₁ lβ‚‚, lβ‚‚ β‰  [] ∧ ys = l₁ ++ lβ‚‚ ∧ l' = l ++ l₁ ++ t :: lβ‚‚ ++ ts := begin induction ys with y ys ih generalizing l, { simp {contextual := tt} }, rw [permutations_aux2_snd_cons, show (Ξ» (x : list Ξ±), l ++ y :: x) = append (l ++ [y]), by funext; simp, mem_cons_iff, ih], split, { rintro (rfl | ⟨l₁, lβ‚‚, l0, rfl, rfl⟩), { exact ⟨[], y::ys, by simp⟩ }, { exact ⟨y::l₁, lβ‚‚, l0, by simp⟩ } }, { rintro ⟨_ | ⟨y', lβ‚βŸ©, lβ‚‚, l0, ye, rfl⟩, { simp [ye] }, { simp only [cons_append] at ye, rcases ye with ⟨rfl, rfl⟩, exact or.inr ⟨l₁, lβ‚‚, l0, by simp⟩ } } end lemma mem_permutations_aux2' {t : Ξ±} {ts : list Ξ±} {ys : list Ξ±} {l : list Ξ±} : l ∈ (permutations_aux2 t ts [] ys id).2 ↔ βˆƒ l₁ lβ‚‚, lβ‚‚ β‰  [] ∧ ys = l₁ ++ lβ‚‚ ∧ l = l₁ ++ t :: lβ‚‚ ++ ts := by rw [show @id (list Ξ±) = append nil, by funext; refl]; apply mem_permutations_aux2 lemma length_permutations_aux2 (t : Ξ±) (ts : list Ξ±) (ys : list Ξ±) (f : list Ξ± β†’ Ξ²) : length (permutations_aux2 t ts [] ys f).2 = length ys := by induction ys generalizing f; simp * lemma foldr_permutations_aux2 (t : Ξ±) (ts : list Ξ±) (r L : list (list Ξ±)) : foldr (Ξ»y r, (permutations_aux2 t ts r y id).2) r L = L.bind (Ξ» y, (permutations_aux2 t ts [] y id).2) ++ r := by induction L with l L ih; [refl, {simp [ih], rw ← permutations_aux2_append}] lemma mem_foldr_permutations_aux2 {t : Ξ±} {ts : list Ξ±} {r L : list (list Ξ±)} {l' : list Ξ±} : l' ∈ foldr (Ξ»y r, (permutations_aux2 t ts r y id).2) r L ↔ l' ∈ r ∨ βˆƒ l₁ lβ‚‚, l₁ ++ lβ‚‚ ∈ L ∧ lβ‚‚ β‰  [] ∧ l' = l₁ ++ t :: lβ‚‚ ++ ts := have (βˆƒ (a : list Ξ±), a ∈ L ∧ βˆƒ (l₁ lβ‚‚ : list Ξ±), Β¬lβ‚‚ = nil ∧ a = l₁ ++ lβ‚‚ ∧ l' = l₁ ++ t :: (lβ‚‚ ++ ts)) ↔ βˆƒ (l₁ lβ‚‚ : list Ξ±), Β¬lβ‚‚ = nil ∧ l₁ ++ lβ‚‚ ∈ L ∧ l' = l₁ ++ t :: (lβ‚‚ ++ ts), from ⟨λ ⟨a, aL, l₁, lβ‚‚, l0, e, h⟩, ⟨l₁, lβ‚‚, l0, e β–Έ aL, h⟩, Ξ» ⟨l₁, lβ‚‚, l0, aL, h⟩, ⟨_, aL, l₁, lβ‚‚, l0, rfl, h⟩⟩, by rw foldr_permutations_aux2; simp [mem_permutations_aux2', this, or.comm, or.left_comm, or.assoc, and.comm, and.left_comm, and.assoc] lemma length_foldr_permutations_aux2 (t : Ξ±) (ts : list Ξ±) (r L : list (list Ξ±)) : length (foldr (Ξ»y r, (permutations_aux2 t ts r y id).2) r L) = sum (map length L) + length r := by simp [foldr_permutations_aux2, (∘), length_permutations_aux2] lemma length_foldr_permutations_aux2' (t : Ξ±) (ts : list Ξ±) (r L : list (list Ξ±)) (n) (H : βˆ€ l ∈ L, length l = n) : length (foldr (Ξ»y r, (permutations_aux2 t ts r y id).2) r L) = n * length L + length r := begin rw [length_foldr_permutations_aux2, (_ : sum (map length L) = n * length L)], induction L with l L ih, {simp}, have sum_map : sum (map length L) = n * length L := ih (Ξ» l m, H l (mem_cons_of_mem _ m)), have length_l : length l = n := H _ (mem_cons_self _ _), simp [sum_map, length_l, mul_add, add_comm] end @[simp] lemma permutations_aux_nil (is : list Ξ±) : permutations_aux [] is = [] := by rw [permutations_aux, permutations_aux.rec] @[simp] lemma permutations_aux_cons (t : Ξ±) (ts is : list Ξ±) : permutations_aux (t :: ts) is = foldr (Ξ»y r, (permutations_aux2 t ts r y id).2) (permutations_aux ts (t::is)) (permutations is) := by rw [permutations_aux, permutations_aux.rec]; refl @[simp] lemma permutations_nil : permutations ([] : list Ξ±) = [[]] := by rw [permutations, permutations_aux_nil] lemma map_permutations_aux (f : Ξ± β†’ Ξ²) : βˆ€ (ts is : list Ξ±), map (map f) (permutations_aux ts is) = permutations_aux (map f ts) (map f is) := begin refine permutations_aux.rec (by simp) _, introv IH1 IH2, rw map at IH2, simp only [foldr_permutations_aux2, map_append, map, map_map_permutations_aux2, permutations, bind_map, IH1, append_assoc, permutations_aux_cons, cons_bind, ← IH2, map_bind], end lemma map_permutations (f : Ξ± β†’ Ξ²) (ts : list Ξ±) : map (map f) (permutations ts) = permutations (map f ts) := by rw [permutations, permutations, map, map_permutations_aux, map] lemma map_permutations' (f : Ξ± β†’ Ξ²) (ts : list Ξ±) : map (map f) (permutations' ts) = permutations' (map f ts) := by induction ts with t ts ih; [refl, simp [← ih, map_bind, ← map_map_permutations'_aux, bind_map]] lemma permutations_aux_append (is is' ts : list Ξ±) : permutations_aux (is ++ ts) is' = (permutations_aux is is').map (++ ts) ++ permutations_aux ts (is.reverse ++ is') := begin induction is with t is ih generalizing is', {simp}, simp [foldr_permutations_aux2, ih, bind_map], congr' 2, funext ys, rw [map_permutations_aux2], simp only [← permutations_aux2_comp_append] {single_pass := tt}, simp only [id, append_assoc], end lemma permutations_append (is ts : list Ξ±) : permutations (is ++ ts) = (permutations is).map (++ ts) ++ permutations_aux ts is.reverse := by simp [permutations, permutations_aux_append] end list
fa491fe37882b841556af2bb31cc297130b0a17e
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/empty.lean
ac2d5db5c12495b35ad8bece3c6590eb2d295753
[ "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
182
lean
-- open inhabited nonempty classical noncomputable lemma v1 : Prop := epsilon (Ξ» x : Prop, true) inductive Empty : Type noncomputable definition v2 : Empty := epsilon (Ξ» x, true)
76701f23e0a723f010fb6e646b25a085b16f0d96
3434f05df84d8335b6bc46ffd22c8e9c90ba093c
/blog/code/2022-04-16-euclidean-algorithm-in-lean/gcd.lean
e8d345e2110cc30d918f11a4cbc3fae893aafcc0
[]
no_license
kunigami/kunigami.github.io
d3058f132ed305e10d47c36587d428bb3718f127
6970151977b428635b16501f74652e5c764428f2
refs/heads/master
1,691,638,246,509
1,691,263,235,000
1,691,263,235,000
18,582,971
13
13
null
1,664,211,056,000
1,397,011,712,000
CSS
UTF-8
Lean
false
false
2,800
lean
import tactic namespace sb inductive Nat | zero : Nat | succ (n : Nat) : Nat open Nat instance : has_zero Nat := ⟨zero⟩ axiom zero_is_nat : zero = 0 instance : has_one Nat := ⟨succ zero⟩ axiom one_is_nat : succ zero = 1 -- addition def add : Nat β†’ Nat β†’ Nat | m 0 := m | m (succ n) := succ (add m n) instance : has_add Nat := ⟨add⟩ axiom add_zero (m: Nat) : m + 0 = m axiom add_succ (m n: Nat) : m + succ n = succ (m + n) -- subtraction def sub : Nat β†’ Nat β†’ Nat | (succ a) (succ b) := sub a b | a b := a instance : has_sub Nat := ⟨sub⟩ axiom sub_zero (a: Nat) : a - 0 = a axiom sub_eq (a: Nat) : a - a = 0 axiom sub_assoc (a b c: Nat): a - b + c = a - (b - c) -- multiplication def mul : Nat β†’ Nat β†’ Nat | m 0 := 0 | m (succ n) := m + (mul m n) instance : has_mul Nat := ⟨mul⟩ axiom mul_zero (n: Nat) : n * 0 = 0 axiom mul_succ (n m: Nat): m * (succ n) = m + (m * n) axiom one_mul (n: Nat) : 1 * n = n axiom mul_dist_add (a b c: Nat) : a * ( b + c) = a * b + a * c axiom mul_dist_sub (a b c: Nat) : a * ( b - c) = a * b - a * c axiom mul_assoc (a b c: Nat) : a * ( b * c) = a * b * c axiom mul_comm (a b: Nat) : a * b = b * a -- divisibility def dvd (a b : Nat) : Prop := βˆƒ (c : Nat), b = a * c instance : has_dvd Nat := ⟨dvd⟩ lemma one_dvd_n (n : Nat) : 1 ∣ n := begin use n, rw one_mul, end def is_gcd (a b g: Nat) : Prop := (g ∣ a) ∧ (g ∣ b) ∧ (βˆ€ x: Nat, (x ∣ a) ∧ (x ∣ b) -> (x ∣ g)) lemma is_gcd_for_euclid (a b q g: Nat): is_gcd b (a - q * b) g -> is_gcd a b g := begin -- (1) replace by definition repeat {rw is_gcd}, -- (2) add to hypothesis intro H, cases H with H1 hrest, cases hrest with H2 H3, -- (3) break goal into 3 repeat {apply and.intro}, -- Goal 1: d | a cases H2 with k1 eq1, cases H1 with k2 eq2, use k1 + k2 * q, rw mul_dist_add, rw← eq1, rw mul_assoc, rw← eq2, rw mul_comm, rw sub_assoc, rw sub_eq, rw sub_zero, -- Goal 2: d | b exact H1, -- Goal 3: βˆ€ (x : Nat), (x ∣ a) ∧ (x ∣ b) β†’ (x ∣ d) intro x1, -- (4) assume (x1 ∣ a) ∧ (x1 ∣ b) intro G3H, cases G3H with G3H1 G3H2, -- (5) use x1 in -- βˆ€ (x : Nat), x ∣ b ∧ x ∣ a - q * b β†’ x ∣ g, specialize H3 x1, -- (6) turn (x1 ∣ g) into (x1 ∣ b) ∧ (x1 ∣ a - q * b) apply H3, repeat {apply and.intro}, -- Goal 3.1: (x1 ∣ b) exact G3H2, -- Goal 3.2: (x1 ∣ a - q * b) cases G3H1 with k3 eq3, cases G3H2 with k4 eq4, use k3 - q * k4, rw mul_dist_sub, rw← eq3, rw mul_comm q k4, rw mul_assoc, rw← eq4, rw mul_comm, end end sb open nat def gcd : nat β†’ nat β†’ nat | 0 a := a | (succ b) a := have a % succ b < succ b, from mod_lt a (succ_pos b), gcd (a % succ b) (succ b)
7ead9116d7704752a90bd8bb39e3c5f2ab320ee1
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/ring_theory/bezout.lean
07bbc8d8352c3af27e65f9922b71997269a1a838
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
4,862
lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import ring_theory.principal_ideal_domain import algebra.gcd_monoid.integrally_closed /-! # BΓ©zout rings > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. A BΓ©zout ring (Bezout ring) is a ring whose finitely generated ideals are principal. Notible examples include principal ideal rings, valuation rings, and the ring of algebraic integers. ## Main results - `is_bezout.iff_span_pair_is_principal`: It suffices to verify every `span {x, y}` is principal. - `is_bezout.to_gcd_monoid`: Every BΓ©zout domain is a GCD domain. This is not an instance. - `is_bezout.tfae`: For a BΓ©zout domain, noetherian ↔ PID ↔ UFD ↔ ACCP -/ universes u v variables (R : Type u) [comm_ring R] /-- A BΓ©zout ring is a ring whose finitely generated ideals are principal. -/ class is_bezout : Prop := (is_principal_of_fg : βˆ€ I : ideal R, I.fg β†’ I.is_principal) namespace is_bezout variables {R} instance span_pair_is_principal [is_bezout R] (x y : R) : (ideal.span {x, y} : ideal R).is_principal := by { classical, exact is_principal_of_fg (ideal.span {x, y}) ⟨{x, y}, by simp⟩ } lemma iff_span_pair_is_principal : is_bezout R ↔ (βˆ€ x y : R, (ideal.span {x, y} : ideal R).is_principal) := begin classical, split, { introsI H x y, apply_instance }, { intro H, constructor, apply submodule.fg_induction, { exact Ξ» _, ⟨⟨_, rfl⟩⟩ }, { rintro _ _ ⟨⟨x, rfl⟩⟩ ⟨⟨y, rfl⟩⟩, rw ← submodule.span_insert, exact H _ _ } }, end section gcd variable [is_bezout R] /-- The gcd of two elements in a bezout domain. -/ noncomputable def gcd (x y : R) : R := submodule.is_principal.generator (ideal.span {x, y}) lemma span_gcd (x y : R) : (ideal.span {gcd x y} : ideal R) = ideal.span {x, y} := ideal.span_singleton_generator _ lemma gcd_dvd_left (x y : R) : gcd x y ∣ x := (submodule.is_principal.mem_iff_generator_dvd _).mp (ideal.subset_span (by simp)) lemma gcd_dvd_right (x y : R) : gcd x y ∣ y := (submodule.is_principal.mem_iff_generator_dvd _).mp (ideal.subset_span (by simp)) lemma dvd_gcd {x y z : R} (hx : z ∣ x) (hy : z ∣ y) : z ∣ gcd x y := begin rw [← ideal.span_singleton_le_span_singleton] at hx hy ⊒, rw [span_gcd, ideal.span_insert, sup_le_iff], exact ⟨hx, hy⟩ end lemma gcd_eq_sum (x y : R) : βˆƒ a b : R, a * x + b * y = gcd x y := ideal.mem_span_pair.mp (by { rw ← span_gcd, apply ideal.subset_span, simp }) variable (R) /-- Any bezout domain is a GCD domain. This is not an instance since `gcd_monoid` contains data, and this might not be how we would like to construct it. -/ noncomputable def to_gcd_domain [is_domain R] [decidable_eq R] : gcd_monoid R := gcd_monoid_of_gcd gcd gcd_dvd_left gcd_dvd_right (Ξ» _ _ _, dvd_gcd) end gcd local attribute [instance] to_gcd_domain -- Note that the proof, despite being `infer_instance`, depends on the `local attribute [instance]` -- lemma above, and is thus necessary to be restated. @[priority 100] instance [is_domain R] [is_bezout R] : is_integrally_closed R := by classical; exact gcd_monoid.to_is_integrally_closed lemma _root_.function.surjective.is_bezout {S : Type v} [comm_ring S] (f : R β†’+* S) (hf : function.surjective f) [is_bezout R] : is_bezout S := begin rw iff_span_pair_is_principal, intros x y, obtain ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ := ⟨hf x, hf y⟩, use f (gcd x y), transitivity ideal.map f (ideal.span {gcd x y}), { rw [span_gcd, ideal.map_span, set.image_insert_eq, set.image_singleton] }, { rw [ideal.map_span, set.image_singleton], refl } end @[priority 100] instance of_is_principal_ideal_ring [is_principal_ideal_ring R] : is_bezout R := ⟨λ I _, is_principal_ideal_ring.principal I⟩ lemma tfae [is_bezout R] [is_domain R] : tfae [is_noetherian_ring R, is_principal_ideal_ring R, unique_factorization_monoid R, wf_dvd_monoid R] := begin classical, tfae_have : 1 β†’ 2, { introI H, exact ⟨λ I, is_principal_of_fg _ (is_noetherian.noetherian _)⟩ }, tfae_have : 2 β†’ 3, { introI _, apply_instance }, tfae_have : 3 β†’ 4, { introI _, apply_instance }, tfae_have : 4 β†’ 1, { rintro ⟨h⟩, rw [is_noetherian_ring_iff, is_noetherian_iff_fg_well_founded], apply rel_embedding.well_founded _ h, have : βˆ€ I : { J : ideal R // J.fg }, βˆƒ x : R, (I : ideal R) = ideal.span {x} := Ξ» ⟨I, hI⟩, (is_bezout.is_principal_of_fg I hI).1, choose f hf, exact { to_fun := f, inj' := Ξ» x y e, by { ext1, rw [hf, hf, e] }, map_rel_iff' := Ξ» x y, by { dsimp, rw [← ideal.span_singleton_lt_span_singleton, ← hf, ← hf], refl } } }, tfae_finish end end is_bezout
4da6ce434e6b7e284bc2ffce533256f9b723c0a3
367134ba5a65885e863bdc4507601606690974c1
/src/topology/constructions.lean
4ffd3e30812f4b51180301ee3d7ca8ac43f82aa3
[ "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
38,887
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.maps /-! # Constructions of new topological spaces from old ones This file constructs products, sums, subtypes and quotients of topological spaces and sets up their basic theory, such as criteria for maps into or out of these constructions to be continuous; descriptions of the open sets, neighborhood filters, and generators of these constructions; and their behavior with respect to embeddings and other specific classes of maps. ## Implementation note The constructed topologies are defined using induced and coinduced topologies along with the complete lattice structure on topologies. Their universal properties (for example, a map `X β†’ Y Γ— Z` is continuous if and only if both projections `X β†’ Y`, `X β†’ Z` are) follow easily using order-theoretic descriptions of continuity. With more work we can also extract descriptions of the open sets, neighborhood filters and so on. ## Tags product, sum, disjoint union, subspace, quotient space -/ noncomputable theory open topological_space set filter open_locale classical topological_space filter universes u v w x variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} {Ξ΄ : Type x} section constructions instance {p : Ξ± β†’ Prop} [t : topological_space Ξ±] : topological_space (subtype p) := induced coe t instance {r : Ξ± β†’ Ξ± β†’ Prop} [t : topological_space Ξ±] : topological_space (quot r) := coinduced (quot.mk r) t instance {s : setoid Ξ±} [t : topological_space Ξ±] : topological_space (quotient s) := coinduced quotient.mk t instance [t₁ : topological_space Ξ±] [tβ‚‚ : topological_space Ξ²] : topological_space (Ξ± Γ— Ξ²) := induced prod.fst t₁ βŠ“ induced prod.snd tβ‚‚ instance [t₁ : topological_space Ξ±] [tβ‚‚ : topological_space Ξ²] : topological_space (Ξ± βŠ• Ξ²) := coinduced sum.inl t₁ βŠ” coinduced sum.inr tβ‚‚ instance {Ξ² : Ξ± β†’ Type v} [tβ‚‚ : Ξ a, topological_space (Ξ² a)] : topological_space (sigma Ξ²) := ⨆a, coinduced (sigma.mk a) (tβ‚‚ a) instance Pi.topological_space {Ξ² : Ξ± β†’ Type v} [tβ‚‚ : Ξ a, topological_space (Ξ² a)] : topological_space (Ξ a, Ξ² a) := β¨…a, induced (Ξ»f, f a) (tβ‚‚ a) instance ulift.topological_space [t : topological_space Ξ±] : topological_space (ulift.{v u} Ξ±) := t.induced ulift.down /-- The image of a dense set under `quotient.mk` is a dense set. -/ lemma dense.quotient [setoid Ξ±] [topological_space Ξ±] {s : set Ξ±} (H : dense s) : dense (quotient.mk '' s) := (surjective_quotient_mk Ξ±).dense_range.dense_image continuous_coinduced_rng H /-- The composition of `quotient.mk` and a function with dense range has dense range. -/ lemma dense_range.quotient [setoid Ξ±] [topological_space Ξ±] {f : Ξ² β†’ Ξ±} (hf : dense_range f) : dense_range (quotient.mk ∘ f) := (surjective_quotient_mk Ξ±).dense_range.comp hf continuous_coinduced_rng instance {p : Ξ± β†’ Prop} [topological_space Ξ±] [discrete_topology Ξ±] : discrete_topology (subtype p) := ⟨bot_unique $ assume s hs, ⟨coe '' s, is_open_discrete _, (set.preimage_image_eq _ subtype.coe_injective)⟩⟩ instance sum.discrete_topology [topological_space Ξ±] [topological_space Ξ²] [hΞ± : discrete_topology Ξ±] [hΞ² : discrete_topology Ξ²] : discrete_topology (Ξ± βŠ• Ξ²) := ⟨by unfold sum.topological_space; simp [hΞ±.eq_bot, hΞ².eq_bot]⟩ instance sigma.discrete_topology {Ξ² : Ξ± β†’ Type v} [Ξ a, topological_space (Ξ² a)] [h : Ξ a, discrete_topology (Ξ² a)] : discrete_topology (sigma Ξ²) := ⟨by { unfold sigma.topological_space, simp [Ξ» a, (h a).eq_bot] }⟩ section topΞ± variable [topological_space Ξ±] /- The 𝓝 filter and the subspace topology. -/ theorem mem_nhds_subtype (s : set Ξ±) (a : {x // x ∈ s}) (t : set {x // x ∈ s}) : t ∈ 𝓝 a ↔ βˆƒ u ∈ 𝓝 (a : Ξ±), coe ⁻¹' u βŠ† t := mem_nhds_induced coe a t theorem nhds_subtype (s : set Ξ±) (a : {x // x ∈ s}) : 𝓝 a = comap coe (𝓝 (a : Ξ±)) := nhds_induced coe a end topΞ± end constructions section prod variables [topological_space Ξ±] [topological_space Ξ²] [topological_space Ξ³] [topological_space Ξ΄] @[continuity] lemma continuous_fst : continuous (@prod.fst Ξ± Ξ²) := continuous_inf_dom_left continuous_induced_dom lemma continuous_at_fst {p : Ξ± Γ— Ξ²} : continuous_at prod.fst p := continuous_fst.continuous_at @[continuity] lemma continuous_snd : continuous (@prod.snd Ξ± Ξ²) := continuous_inf_dom_right continuous_induced_dom lemma continuous_at_snd {p : Ξ± Γ— Ξ²} : continuous_at prod.snd p := continuous_snd.continuous_at @[continuity] lemma continuous.prod_mk {f : Ξ³ β†’ Ξ±} {g : Ξ³ β†’ Ξ²} (hf : continuous f) (hg : continuous g) : continuous (Ξ»x, (f x, g x)) := continuous_inf_rng (continuous_induced_rng hf) (continuous_induced_rng hg) lemma continuous.prod_map {f : Ξ³ β†’ Ξ±} {g : Ξ΄ β†’ Ξ²} (hf : continuous f) (hg : continuous g) : continuous (Ξ» x : Ξ³ Γ— Ξ΄, (f x.1, g x.2)) := (hf.comp continuous_fst).prod_mk (hg.comp continuous_snd) lemma filter.eventually.prod_inl_nhds {p : Ξ± β†’ Prop} {a : Ξ±} (h : βˆ€αΆ  x in 𝓝 a, p x) (b : Ξ²) : βˆ€αΆ  x in 𝓝 (a, b), p (x : Ξ± Γ— Ξ²).1 := continuous_at_fst h lemma filter.eventually.prod_inr_nhds {p : Ξ² β†’ Prop} {b : Ξ²} (h : βˆ€αΆ  x in 𝓝 b, p x) (a : Ξ±) : βˆ€αΆ  x in 𝓝 (a, b), p (x : Ξ± Γ— Ξ²).2 := continuous_at_snd h lemma filter.eventually.prod_mk_nhds {pa : Ξ± β†’ Prop} {a} (ha : βˆ€αΆ  x in 𝓝 a, pa x) {pb : Ξ² β†’ Prop} {b} (hb : βˆ€αΆ  y in 𝓝 b, pb y) : βˆ€αΆ  p in 𝓝 (a, b), pa (p : Ξ± Γ— Ξ²).1 ∧ pb p.2 := (ha.prod_inl_nhds b).and (hb.prod_inr_nhds a) lemma continuous_swap : continuous (prod.swap : Ξ± Γ— Ξ² β†’ Ξ² Γ— Ξ±) := continuous.prod_mk continuous_snd continuous_fst lemma continuous_uncurry_left {f : Ξ± β†’ Ξ² β†’ Ξ³} (a : Ξ±) (h : continuous (function.uncurry f)) : continuous (f a) := show continuous (function.uncurry f ∘ (Ξ» b, (a, b))), from h.comp (by continuity) lemma continuous_uncurry_right {f : Ξ± β†’ Ξ² β†’ Ξ³} (b : Ξ²) (h : continuous (function.uncurry f)) : continuous (Ξ» a, f a b) := show continuous (function.uncurry f ∘ (Ξ» a, (a, b))), from h.comp (by continuity) lemma continuous_curry {g : Ξ± Γ— Ξ² β†’ Ξ³} (a : Ξ±) (h : continuous g) : continuous (function.curry g a) := show continuous (g ∘ (Ξ» b, (a, b))), from h.comp (by continuity) lemma is_open.prod {s : set Ξ±} {t : set Ξ²} (hs : is_open s) (ht : is_open t) : is_open (set.prod s t) := is_open_inter (hs.preimage continuous_fst) (ht.preimage continuous_snd) lemma nhds_prod_eq {a : Ξ±} {b : Ξ²} : 𝓝 (a, b) = 𝓝 a Γ—αΆ  𝓝 b := by rw [filter.prod, prod.topological_space, nhds_inf, nhds_induced, nhds_induced] lemma mem_nhds_prod_iff {a : Ξ±} {b : Ξ²} {s : set (Ξ± Γ— Ξ²)} : s ∈ 𝓝 (a, b) ↔ βˆƒ (u ∈ 𝓝 a) (v ∈ 𝓝 b), set.prod u v βŠ† s := by rw [nhds_prod_eq, mem_prod_iff] lemma filter.has_basis.prod_nhds {ΞΉa ΞΉb : Type*} {pa : ΞΉa β†’ Prop} {pb : ΞΉb β†’ Prop} {sa : ΞΉa β†’ set Ξ±} {sb : ΞΉb β†’ set Ξ²} {a : Ξ±} {b : Ξ²} (ha : (𝓝 a).has_basis pa sa) (hb : (𝓝 b).has_basis pb sb) : (𝓝 (a, b)).has_basis (Ξ» i : ΞΉa Γ— ΞΉb, pa i.1 ∧ pb i.2) (Ξ» i, (sa i.1).prod (sb i.2)) := by { rw nhds_prod_eq, exact ha.prod hb } lemma filter.has_basis.prod_nhds' {ΞΉa ΞΉb : Type*} {pa : ΞΉa β†’ Prop} {pb : ΞΉb β†’ Prop} {sa : ΞΉa β†’ set Ξ±} {sb : ΞΉb β†’ set Ξ²} {ab : Ξ± Γ— Ξ²} (ha : (𝓝 ab.1).has_basis pa sa) (hb : (𝓝 ab.2).has_basis pb sb) : (𝓝 ab).has_basis (Ξ» i : ΞΉa Γ— ΞΉb, pa i.1 ∧ pb i.2) (Ξ» i, (sa i.1).prod (sb i.2)) := by { cases ab, exact ha.prod_nhds hb } instance [discrete_topology Ξ±] [discrete_topology Ξ²] : discrete_topology (Ξ± Γ— Ξ²) := ⟨eq_of_nhds_eq_nhds $ assume ⟨a, b⟩, by rw [nhds_prod_eq, nhds_discrete Ξ±, nhds_discrete Ξ², nhds_bot, filter.prod_pure_pure]⟩ lemma prod_mem_nhds_iff {s : set Ξ±} {t : set Ξ²} {a : Ξ±} {b : Ξ²} : s.prod t ∈ 𝓝 (a, b) ↔ s ∈ 𝓝 a ∧ t ∈ 𝓝 b := by rw [nhds_prod_eq, prod_mem_prod_iff] lemma prod_mem_nhds_sets {s : set Ξ±} {t : set Ξ²} {a : Ξ±} {b : Ξ²} (ha : s ∈ 𝓝 a) (hb : t ∈ 𝓝 b) : set.prod s t ∈ 𝓝 (a, b) := prod_mem_nhds_iff.2 ⟨ha, hb⟩ lemma nhds_swap (a : Ξ±) (b : Ξ²) : 𝓝 (a, b) = (𝓝 (b, a)).map prod.swap := by rw [nhds_prod_eq, filter.prod_comm, nhds_prod_eq]; refl lemma filter.tendsto.prod_mk_nhds {Ξ³} {a : Ξ±} {b : Ξ²} {f : filter Ξ³} {ma : Ξ³ β†’ Ξ±} {mb : Ξ³ β†’ Ξ²} (ha : tendsto ma f (𝓝 a)) (hb : tendsto mb f (𝓝 b)) : tendsto (Ξ»c, (ma c, mb c)) f (𝓝 (a, b)) := by rw [nhds_prod_eq]; exact filter.tendsto.prod_mk ha hb lemma filter.eventually.curry_nhds {p : Ξ± Γ— Ξ² β†’ Prop} {x : Ξ±} {y : Ξ²} (h : βˆ€αΆ  x in 𝓝 (x, y), p x) : βˆ€αΆ  x' in 𝓝 x, βˆ€αΆ  y' in 𝓝 y, p (x', y') := by { rw [nhds_prod_eq] at h, exact h.curry } lemma continuous_at.prod {f : Ξ± β†’ Ξ²} {g : Ξ± β†’ Ξ³} {x : Ξ±} (hf : continuous_at f x) (hg : continuous_at g x) : continuous_at (Ξ»x, (f x, g x)) x := hf.prod_mk_nhds hg lemma continuous_at.prod_map {f : Ξ± β†’ Ξ³} {g : Ξ² β†’ Ξ΄} {p : Ξ± Γ— Ξ²} (hf : continuous_at f p.fst) (hg : continuous_at g p.snd) : continuous_at (Ξ» p : Ξ± Γ— Ξ², (f p.1, g p.2)) p := (hf.comp continuous_at_fst).prod (hg.comp continuous_at_snd) lemma continuous_at.prod_map' {f : Ξ± β†’ Ξ³} {g : Ξ² β†’ Ξ΄} {x : Ξ±} {y : Ξ²} (hf : continuous_at f x) (hg : continuous_at g y) : continuous_at (Ξ» p : Ξ± Γ— Ξ², (f p.1, g p.2)) (x, y) := have hf : continuous_at f (x, y).fst, from hf, have hg : continuous_at g (x, y).snd, from hg, hf.prod_map hg lemma prod_generate_from_generate_from_eq {Ξ± Ξ² : Type*} {s : set (set Ξ±)} {t : set (set Ξ²)} (hs : ⋃₀ s = univ) (ht : ⋃₀ t = univ) : @prod.topological_space Ξ± Ξ² (generate_from s) (generate_from t) = generate_from {g | βˆƒu∈s, βˆƒv∈t, g = set.prod u v} := let G := generate_from {g | βˆƒu∈s, βˆƒv∈t, g = set.prod u v} in le_antisymm (le_generate_from $ assume g ⟨u, hu, v, hv, g_eq⟩, g_eq.symm β–Έ @is_open.prod _ _ (generate_from s) (generate_from t) _ _ (generate_open.basic _ hu) (generate_open.basic _ hv)) (le_inf (coinduced_le_iff_le_induced.mp $ le_generate_from $ assume u hu, have (⋃v∈t, set.prod u v) = prod.fst ⁻¹' u, from calc (⋃v∈t, set.prod u v) = set.prod u univ : set.ext $ assume ⟨a, b⟩, by rw ← ht; simp [and.left_comm] {contextual:=tt} ... = prod.fst ⁻¹' u : by simp [set.prod, preimage], show G.is_open (prod.fst ⁻¹' u), from this β–Έ @is_open_Union _ _ G _ $ assume v, @is_open_Union _ _ G _ $ assume hv, generate_open.basic _ ⟨_, hu, _, hv, rfl⟩) (coinduced_le_iff_le_induced.mp $ le_generate_from $ assume v hv, have (⋃u∈s, set.prod u v) = prod.snd ⁻¹' v, from calc (⋃u∈s, set.prod u v) = set.prod univ v: set.ext $ assume ⟨a, b⟩, by rw [←hs]; by_cases b ∈ v; simp [h] {contextual:=tt} ... = prod.snd ⁻¹' v : by simp [set.prod, preimage], show G.is_open (prod.snd ⁻¹' v), from this β–Έ @is_open_Union _ _ G _ $ assume u, @is_open_Union _ _ G _ $ assume hu, generate_open.basic _ ⟨_, hu, _, hv, rfl⟩)) lemma prod_eq_generate_from : prod.topological_space = generate_from {g | βˆƒ(s:set Ξ±) (t:set Ξ²), is_open s ∧ is_open t ∧ g = set.prod s t} := le_antisymm (le_generate_from $ assume g ⟨s, t, hs, ht, g_eq⟩, g_eq.symm β–Έ hs.prod ht) (le_inf (ball_image_of_ball $ Ξ»t ht, generate_open.basic _ ⟨t, univ, by simpa [set.prod_eq] using ht⟩) (ball_image_of_ball $ Ξ»t ht, generate_open.basic _ ⟨univ, t, by simpa [set.prod_eq] using ht⟩)) lemma is_open_prod_iff {s : set (Ξ±Γ—Ξ²)} : is_open s ↔ (βˆ€a b, (a, b) ∈ s β†’ βˆƒu v, is_open u ∧ is_open v ∧ a ∈ u ∧ b ∈ v ∧ set.prod u v βŠ† s) := begin rw [is_open_iff_nhds], simp_rw [le_principal_iff, prod.forall, ((nhds_basis_opens _).prod_nhds (nhds_basis_opens _)).mem_iff, prod.exists, exists_prop], simp only [and_assoc, and.left_comm] end lemma continuous_uncurry_of_discrete_topology_left [discrete_topology Ξ±] {f : Ξ± β†’ Ξ² β†’ Ξ³} (h : βˆ€ a, continuous (f a)) : continuous (function.uncurry f) := continuous_iff_continuous_at.2 $ Ξ» ⟨a, b⟩, by simp only [continuous_at, nhds_prod_eq, nhds_discrete Ξ±, pure_prod, tendsto_map'_iff, (∘), function.uncurry, (h a).tendsto] /-- Given a neighborhood `s` of `(x, x)`, then `(x, x)` has a square open neighborhood that is a subset of `s`. -/ lemma exists_nhds_square {s : set (Ξ± Γ— Ξ±)} {x : Ξ±} (hx : s ∈ 𝓝 (x, x)) : βˆƒU, is_open U ∧ x ∈ U ∧ set.prod U U βŠ† s := by simpa [nhds_prod_eq, (nhds_basis_opens x).prod_self.mem_iff, and.assoc, and.left_comm] using hx /-- `prod.fst` maps neighborhood of `x : Ξ± Γ— Ξ²` within the section `prod.snd ⁻¹' {x.2}` to `𝓝 x.1`. -/ lemma map_fst_nhds_within (x : Ξ± Γ— Ξ²) : map prod.fst (𝓝[prod.snd ⁻¹' {x.2}] x) = 𝓝 x.1 := begin refine le_antisymm (continuous_at_fst.mono_left inf_le_left) (Ξ» s hs, _), rcases x with ⟨x, y⟩, rw [mem_map, nhds_within, mem_inf_principal, mem_nhds_prod_iff] at hs, rcases hs with ⟨u, hu, v, hv, H⟩, simp only [prod_subset_iff, mem_singleton_iff, mem_set_of_eq, mem_preimage] at H, exact mem_sets_of_superset hu (Ξ» z hz, H _ hz _ (mem_of_nhds hv) rfl) end @[simp] lemma map_fst_nhds (x : Ξ± Γ— Ξ²) : map prod.fst (𝓝 x) = 𝓝 x.1 := le_antisymm continuous_at_fst $ (map_fst_nhds_within x).symm.trans_le (map_mono inf_le_left) /-- The first projection in a product of topological spaces sends open sets to open sets. -/ lemma is_open_map_fst : is_open_map (@prod.fst Ξ± Ξ²) := is_open_map_iff_nhds_le.2 $ Ξ» x, (map_fst_nhds x).ge /-- `prod.snd` maps neighborhood of `x : Ξ± Γ— Ξ²` within the section `prod.fst ⁻¹' {x.1}` to `𝓝 x.2`. -/ lemma map_snd_nhds_within (x : Ξ± Γ— Ξ²) : map prod.snd (𝓝[prod.fst ⁻¹' {x.1}] x) = 𝓝 x.2 := begin refine le_antisymm (continuous_at_snd.mono_left inf_le_left) (Ξ» s hs, _), rcases x with ⟨x, y⟩, rw [mem_map, nhds_within, mem_inf_principal, mem_nhds_prod_iff] at hs, rcases hs with ⟨u, hu, v, hv, H⟩, simp only [prod_subset_iff, mem_singleton_iff, mem_set_of_eq, mem_preimage] at H, exact mem_sets_of_superset hv (Ξ» z hz, H _ (mem_of_nhds hu) _ hz rfl) end @[simp] lemma map_snd_nhds (x : Ξ± Γ— Ξ²) : map prod.snd (𝓝 x) = 𝓝 x.2 := le_antisymm continuous_at_snd $ (map_snd_nhds_within x).symm.trans_le (map_mono inf_le_left) /-- The second projection in a product of topological spaces sends open sets to open sets. -/ lemma is_open_map_snd : is_open_map (@prod.snd Ξ± Ξ²) := is_open_map_iff_nhds_le.2 $ Ξ» x, (map_snd_nhds x).ge /-- A product set is open in a product space if and only if each factor is open, or one of them is empty -/ lemma is_open_prod_iff' {s : set Ξ±} {t : set Ξ²} : is_open (set.prod s t) ↔ (is_open s ∧ is_open t) ∨ (s = βˆ…) ∨ (t = βˆ…) := begin cases (set.prod s t).eq_empty_or_nonempty with h h, { simp [h, prod_eq_empty_iff.1 h] }, { have st : s.nonempty ∧ t.nonempty, from prod_nonempty_iff.1 h, split, { assume H : is_open (set.prod s t), refine or.inl ⟨_, _⟩, show is_open s, { rw ← fst_image_prod s st.2, exact is_open_map_fst _ H }, show is_open t, { rw ← snd_image_prod st.1 t, exact is_open_map_snd _ H } }, { assume H, simp only [st.1.ne_empty, st.2.ne_empty, not_false_iff, or_false] at H, exact H.1.prod H.2 } } end lemma closure_prod_eq {s : set Ξ±} {t : set Ξ²} : closure (set.prod s t) = set.prod (closure s) (closure t) := set.ext $ assume ⟨a, b⟩, have (𝓝 a Γ—αΆ  𝓝 b) βŠ“ π“Ÿ (set.prod s t) = (𝓝 a βŠ“ π“Ÿ s) Γ—αΆ  (𝓝 b βŠ“ π“Ÿ t), by rw [←prod_inf_prod, prod_principal_principal], by simp [closure_eq_cluster_pts, cluster_pt, nhds_prod_eq, this]; exact prod_ne_bot lemma interior_prod_eq (s : set Ξ±) (t : set Ξ²) : interior (s.prod t) = (interior s).prod (interior t) := set.ext $ Ξ» ⟨a, b⟩, by simp only [mem_interior_iff_mem_nhds, mem_prod, prod_mem_nhds_iff] lemma frontier_prod_eq (s : set Ξ±) (t : set Ξ²) : frontier (s.prod t) = (closure s).prod (frontier t) βˆͺ (frontier s).prod (closure t) := by simp only [frontier, closure_prod_eq, interior_prod_eq, prod_diff_prod] @[simp] lemma frontier_prod_univ_eq (s : set Ξ±) : frontier (s.prod (univ : set Ξ²)) = (frontier s).prod univ := by simp [frontier_prod_eq] @[simp] lemma frontier_univ_prod_eq (s : set Ξ²) : frontier ((univ : set Ξ±).prod s) = (univ : set Ξ±).prod (frontier s) := by simp [frontier_prod_eq] lemma map_mem_closure2 {s : set Ξ±} {t : set Ξ²} {u : set Ξ³} {f : Ξ± β†’ Ξ² β†’ Ξ³} {a : Ξ±} {b : Ξ²} (hf : continuous (Ξ»p:Ξ±Γ—Ξ², f p.1 p.2)) (ha : a ∈ closure s) (hb : b ∈ closure t) (hu : βˆ€a b, a ∈ s β†’ b ∈ t β†’ f a b ∈ u) : f a b ∈ closure u := have (a, b) ∈ closure (set.prod s t), by rw [closure_prod_eq]; from ⟨ha, hb⟩, show (Ξ»p:Ξ±Γ—Ξ², f p.1 p.2) (a, b) ∈ closure u, from map_mem_closure hf this $ assume ⟨a, b⟩ ⟨ha, hb⟩, hu a b ha hb lemma is_closed.prod {s₁ : set Ξ±} {sβ‚‚ : set Ξ²} (h₁ : is_closed s₁) (hβ‚‚ : is_closed sβ‚‚) : is_closed (set.prod s₁ sβ‚‚) := closure_eq_iff_is_closed.mp $ by simp only [h₁.closure_eq, hβ‚‚.closure_eq, closure_prod_eq] /-- The product of two dense sets is a dense set. -/ lemma dense.prod {s : set Ξ±} {t : set Ξ²} (hs : dense s) (ht : dense t) : dense (s.prod t) := Ξ» x, by { rw closure_prod_eq, exact ⟨hs x.1, ht x.2⟩ } /-- If `f` and `g` are maps with dense range, then `prod.map f g` has dense range. -/ lemma dense_range.prod_map {ΞΉ : Type*} {ΞΊ : Type*} {f : ΞΉ β†’ Ξ²} {g : ΞΊ β†’ Ξ³} (hf : dense_range f) (hg : dense_range g) : dense_range (prod.map f g) := by simpa only [dense_range, prod_range_range_eq] using hf.prod hg lemma inducing.prod_mk {f : Ξ± β†’ Ξ²} {g : Ξ³ β†’ Ξ΄} (hf : inducing f) (hg : inducing g) : inducing (Ξ»x:Ξ±Γ—Ξ³, (f x.1, g x.2)) := ⟨by rw [prod.topological_space, prod.topological_space, hf.induced, hg.induced, induced_compose, induced_compose, induced_inf, induced_compose, induced_compose]⟩ lemma embedding.prod_mk {f : Ξ± β†’ Ξ²} {g : Ξ³ β†’ Ξ΄} (hf : embedding f) (hg : embedding g) : embedding (Ξ»x:Ξ±Γ—Ξ³, (f x.1, g x.2)) := { inj := assume ⟨x₁, xβ‚‚βŸ© ⟨y₁, yβ‚‚βŸ©, by simp; exact assume h₁ hβ‚‚, ⟨hf.inj h₁, hg.inj hβ‚‚βŸ©, ..hf.to_inducing.prod_mk hg.to_inducing } protected lemma is_open_map.prod {f : Ξ± β†’ Ξ²} {g : Ξ³ β†’ Ξ΄} (hf : is_open_map f) (hg : is_open_map g) : is_open_map (Ξ» p : Ξ± Γ— Ξ³, (f p.1, g p.2)) := begin rw [is_open_map_iff_nhds_le], rintros ⟨a, b⟩, rw [nhds_prod_eq, nhds_prod_eq, ← filter.prod_map_map_eq], exact filter.prod_mono (is_open_map_iff_nhds_le.1 hf a) (is_open_map_iff_nhds_le.1 hg b) end protected lemma open_embedding.prod {f : Ξ± β†’ Ξ²} {g : Ξ³ β†’ Ξ΄} (hf : open_embedding f) (hg : open_embedding g) : open_embedding (Ξ»x:Ξ±Γ—Ξ³, (f x.1, g x.2)) := open_embedding_of_embedding_open (hf.1.prod_mk hg.1) (hf.is_open_map.prod hg.is_open_map) lemma embedding_graph {f : Ξ± β†’ Ξ²} (hf : continuous f) : embedding (Ξ»x, (x, f x)) := embedding_of_embedding_compose (continuous_id.prod_mk hf) continuous_fst embedding_id end prod section sum open sum variables [topological_space Ξ±] [topological_space Ξ²] [topological_space Ξ³] @[continuity] lemma continuous_inl : continuous (@inl Ξ± Ξ²) := continuous_sup_rng_left continuous_coinduced_rng @[continuity] lemma continuous_inr : continuous (@inr Ξ± Ξ²) := continuous_sup_rng_right continuous_coinduced_rng @[continuity] lemma continuous_sum_rec {f : Ξ± β†’ Ξ³} {g : Ξ² β†’ Ξ³} (hf : continuous f) (hg : continuous g) : @continuous (Ξ± βŠ• Ξ²) Ξ³ _ _ (@sum.rec Ξ± Ξ² (Ξ»_, Ξ³) f g) := begin apply continuous_sup_dom; rw continuous_def at hf hg ⊒; assumption end lemma is_open_sum_iff {s : set (Ξ± βŠ• Ξ²)} : is_open s ↔ is_open (inl ⁻¹' s) ∧ is_open (inr ⁻¹' s) := iff.rfl lemma is_open_map_sum {f : Ξ± βŠ• Ξ² β†’ Ξ³} (h₁ : is_open_map (Ξ» a, f (inl a))) (hβ‚‚ : is_open_map (Ξ» b, f (inr b))) : is_open_map f := begin intros u hu, rw is_open_sum_iff at hu, cases hu with hu₁ huβ‚‚, have : u = inl '' (inl ⁻¹' u) βˆͺ inr '' (inr ⁻¹' u), { ext (_|_); simp }, rw [this, set.image_union, set.image_image, set.image_image], exact is_open_union (h₁ _ hu₁) (hβ‚‚ _ huβ‚‚) end lemma embedding_inl : embedding (@inl Ξ± Ξ²) := { induced := begin unfold sum.topological_space, apply le_antisymm, { rw ← coinduced_le_iff_le_induced, exact le_sup_left }, { intros u hu, existsi (inl '' u), change (is_open (inl ⁻¹' (@inl Ξ± Ξ² '' u)) ∧ is_open (inr ⁻¹' (@inl Ξ± Ξ² '' u))) ∧ inl ⁻¹' (inl '' u) = u, have : inl ⁻¹' (@inl Ξ± Ξ² '' u) = u := preimage_image_eq u (Ξ» _ _, inl.inj_iff.mp), rw this, have : inr ⁻¹' (@inl Ξ± Ξ² '' u) = βˆ… := eq_empty_iff_forall_not_mem.mpr (assume a ⟨b, _, h⟩, inl_ne_inr h), rw this, exact ⟨⟨hu, is_open_empty⟩, rfl⟩ } end, inj := Ξ» _ _, inl.inj_iff.mp } lemma embedding_inr : embedding (@inr Ξ± Ξ²) := { induced := begin unfold sum.topological_space, apply le_antisymm, { rw ← coinduced_le_iff_le_induced, exact le_sup_right }, { intros u hu, existsi (inr '' u), change (is_open (inl ⁻¹' (@inr Ξ± Ξ² '' u)) ∧ is_open (inr ⁻¹' (@inr Ξ± Ξ² '' u))) ∧ inr ⁻¹' (inr '' u) = u, have : inl ⁻¹' (@inr Ξ± Ξ² '' u) = βˆ… := eq_empty_iff_forall_not_mem.mpr (assume b ⟨a, _, h⟩, inr_ne_inl h), rw this, have : inr ⁻¹' (@inr Ξ± Ξ² '' u) = u := preimage_image_eq u (Ξ» _ _, inr.inj_iff.mp), rw this, exact ⟨⟨is_open_empty, hu⟩, rfl⟩ } end, inj := Ξ» _ _, inr.inj_iff.mp } lemma is_open_range_inl : is_open (range (inl : Ξ± β†’ Ξ± βŠ• Ξ²)) := is_open_sum_iff.2 $ by simp lemma is_open_range_inr : is_open (range (inr : Ξ² β†’ Ξ± βŠ• Ξ²)) := is_open_sum_iff.2 $ by simp lemma open_embedding_inl : open_embedding (inl : Ξ± β†’ Ξ± βŠ• Ξ²) := { open_range := is_open_range_inl, .. embedding_inl } lemma open_embedding_inr : open_embedding (inr : Ξ² β†’ Ξ± βŠ• Ξ²) := { open_range := is_open_range_inr, .. embedding_inr } end sum section subtype variables [topological_space Ξ±] [topological_space Ξ²] [topological_space Ξ³] {p : Ξ± β†’ Prop} lemma embedding_subtype_coe : embedding (coe : subtype p β†’ Ξ±) := ⟨⟨rfl⟩, subtype.coe_injective⟩ lemma closed_embedding_subtype_coe (h : is_closed {a | p a}) : closed_embedding (coe : subtype p β†’ Ξ±) := ⟨embedding_subtype_coe, by rwa [subtype.range_coe_subtype]⟩ @[continuity] lemma continuous_subtype_val : continuous (@subtype.val Ξ± p) := continuous_induced_dom lemma continuous_subtype_coe : continuous (coe : subtype p β†’ Ξ±) := continuous_subtype_val lemma is_open.open_embedding_subtype_coe {s : set Ξ±} (hs : is_open s) : open_embedding (coe : s β†’ Ξ±) := { induced := rfl, inj := subtype.coe_injective, open_range := (subtype.range_coe : range coe = s).symm β–Έ hs } lemma is_open.is_open_map_subtype_coe {s : set Ξ±} (hs : is_open s) : is_open_map (coe : s β†’ Ξ±) := hs.open_embedding_subtype_coe.is_open_map lemma is_open_map.restrict {f : Ξ± β†’ Ξ²} (hf : is_open_map f) {s : set Ξ±} (hs : is_open s) : is_open_map (s.restrict f) := hf.comp hs.is_open_map_subtype_coe lemma is_closed.closed_embedding_subtype_coe {s : set Ξ±} (hs : is_closed s) : closed_embedding (coe : {x // x ∈ s} β†’ Ξ±) := { induced := rfl, inj := subtype.coe_injective, closed_range := (subtype.range_coe : range coe = s).symm β–Έ hs } @[continuity] lemma continuous_subtype_mk {f : Ξ² β†’ Ξ±} (hp : βˆ€x, p (f x)) (h : continuous f) : continuous (Ξ»x, (⟨f x, hp x⟩ : subtype p)) := continuous_induced_rng h lemma continuous_inclusion {s t : set Ξ±} (h : s βŠ† t) : continuous (inclusion h) := continuous_subtype_mk _ continuous_subtype_coe lemma continuous_at_subtype_coe {p : Ξ± β†’ Prop} {a : subtype p} : continuous_at (coe : subtype p β†’ Ξ±) a := continuous_iff_continuous_at.mp continuous_subtype_coe _ lemma map_nhds_subtype_coe_eq {a : Ξ±} (ha : p a) (h : {a | p a} ∈ 𝓝 a) : map (coe : subtype p β†’ Ξ±) (𝓝 ⟨a, ha⟩) = 𝓝 a := map_nhds_induced_of_mem $ by simpa only [subtype.coe_mk, subtype.range_coe] using h lemma nhds_subtype_eq_comap {a : Ξ±} {h : p a} : 𝓝 (⟨a, h⟩ : subtype p) = comap coe (𝓝 a) := nhds_induced _ _ lemma tendsto_subtype_rng {Ξ² : Type*} {p : Ξ± β†’ Prop} {b : filter Ξ²} {f : Ξ² β†’ subtype p} : βˆ€{a:subtype p}, tendsto f b (𝓝 a) ↔ tendsto (Ξ»x, (f x : Ξ±)) b (𝓝 (a : Ξ±)) | ⟨a, ha⟩ := by rw [nhds_subtype_eq_comap, tendsto_comap_iff, subtype.coe_mk] lemma continuous_subtype_nhds_cover {ΞΉ : Sort*} {f : Ξ± β†’ Ξ²} {c : ΞΉ β†’ Ξ± β†’ Prop} (c_cover : βˆ€x:Ξ±, βˆƒi, {x | c i x} ∈ 𝓝 x) (f_cont : βˆ€i, continuous (Ξ»(x : subtype (c i)), f x)) : continuous f := continuous_iff_continuous_at.mpr $ assume x, let ⟨i, (c_sets : {x | c i x} ∈ 𝓝 x)⟩ := c_cover x in let x' : subtype (c i) := ⟨x, mem_of_nhds c_sets⟩ in calc map f (𝓝 x) = map f (map coe (𝓝 x')) : congr_arg (map f) (map_nhds_subtype_coe_eq _ $ c_sets).symm ... = map (Ξ»x:subtype (c i), f x) (𝓝 x') : rfl ... ≀ 𝓝 (f x) : continuous_iff_continuous_at.mp (f_cont i) x' lemma continuous_subtype_is_closed_cover {ΞΉ : Sort*} {f : Ξ± β†’ Ξ²} (c : ΞΉ β†’ Ξ± β†’ Prop) (h_lf : locally_finite (Ξ»i, {x | c i x})) (h_is_closed : βˆ€i, is_closed {x | c i x}) (h_cover : βˆ€x, βˆƒi, c i x) (f_cont : βˆ€i, continuous (Ξ»(x : subtype (c i)), f x)) : continuous f := continuous_iff_is_closed.mpr $ assume s hs, have βˆ€i, is_closed ((coe : {x | c i x} β†’ Ξ±) '' (f ∘ coe ⁻¹' s)), from assume i, (closed_embedding_subtype_coe (h_is_closed _)).is_closed_map _ (hs.preimage (f_cont i)), have is_closed (⋃i, (coe : {x | c i x} β†’ Ξ±) '' (f ∘ coe ⁻¹' s)), from locally_finite.is_closed_Union (h_lf.subset $ assume i x ⟨⟨x', hx'⟩, _, heq⟩, heq β–Έ hx') this, have f ⁻¹' s = (⋃i, (coe : {x | c i x} β†’ Ξ±) '' (f ∘ coe ⁻¹' s)), begin apply set.ext, have : βˆ€ (x : Ξ±), f x ∈ s ↔ βˆƒ (i : ΞΉ), c i x ∧ f x ∈ s := Ξ» x, ⟨λ hx, let ⟨i, hi⟩ := h_cover x in ⟨i, hi, hx⟩, Ξ» ⟨i, hi, hx⟩, hx⟩, simpa [and.comm, @and.left_comm (c _ _), ← exists_and_distrib_right], end, by rwa [this] lemma closure_subtype {x : {a // p a}} {s : set {a // p a}}: x ∈ closure s ↔ (x : Ξ±) ∈ closure ((coe : _ β†’ Ξ±) '' s) := closure_induced end subtype section quotient variables [topological_space Ξ±] [topological_space Ξ²] [topological_space Ξ³] variables {r : Ξ± β†’ Ξ± β†’ Prop} {s : setoid Ξ±} lemma quotient_map_quot_mk : quotient_map (@quot.mk Ξ± r) := ⟨quot.exists_rep, rfl⟩ @[continuity] lemma continuous_quot_mk : continuous (@quot.mk Ξ± r) := continuous_coinduced_rng @[continuity] lemma continuous_quot_lift {f : Ξ± β†’ Ξ²} (hr : βˆ€ a b, r a b β†’ f a = f b) (h : continuous f) : continuous (quot.lift f hr : quot r β†’ Ξ²) := continuous_coinduced_dom h lemma quotient_map_quotient_mk : quotient_map (@quotient.mk Ξ± s) := quotient_map_quot_mk lemma continuous_quotient_mk : continuous (@quotient.mk Ξ± s) := continuous_coinduced_rng lemma continuous_quotient_lift {f : Ξ± β†’ Ξ²} (hs : βˆ€ a b, a β‰ˆ b β†’ f a = f b) (h : continuous f) : continuous (quotient.lift f hs : quotient s β†’ Ξ²) := continuous_coinduced_dom h end quotient section pi variables {ΞΉ : Type*} {Ο€ : ΞΉ β†’ Type*} @[continuity] lemma continuous_pi [topological_space Ξ±] [βˆ€i, topological_space (Ο€ i)] {f : Ξ± β†’ Ξ i:ΞΉ, Ο€ i} (h : βˆ€i, continuous (Ξ»a, f a i)) : continuous f := continuous_infi_rng $ assume i, continuous_induced_rng $ h i @[continuity] lemma continuous_apply [βˆ€i, topological_space (Ο€ i)] (i : ΞΉ) : continuous (Ξ»p:Ξ i, Ο€ i, p i) := continuous_infi_dom continuous_induced_dom /-- Embedding a factor into a product space (by fixing arbitrarily all the other coordinates) is continuous. -/ @[continuity] lemma continuous_update [decidable_eq ΞΉ] [βˆ€i, topological_space (Ο€ i)] {i : ΞΉ} {f : Ξ i:ΞΉ, Ο€ i} : continuous (Ξ» x : Ο€ i, function.update f i x) := begin refine continuous_pi (Ξ»j, _), by_cases h : j = i, { rw h, simpa using continuous_id }, { simpa [h] using continuous_const } end lemma nhds_pi [t : βˆ€i, topological_space (Ο€ i)] {a : Ξ i, Ο€ i} : 𝓝 a = (β¨…i, comap (Ξ»x, x i) (𝓝 (a i))) := calc 𝓝 a = (β¨…i, @nhds _ (@topological_space.induced _ _ (Ξ»x:Ξ i, Ο€ i, x i) (t i)) a) : nhds_infi ... = (β¨…i, comap (Ξ»x, x i) (𝓝 (a i))) : by simp [nhds_induced] lemma tendsto_pi [t : βˆ€i, topological_space (Ο€ i)] {f : Ξ± β†’ Ξ i, Ο€ i} {g : Ξ i, Ο€ i} {u : filter Ξ±} : tendsto f u (𝓝 g) ↔ βˆ€ x, tendsto (Ξ» i, f i x) u (𝓝 (g x)) := by simp [nhds_pi, filter.tendsto_comap_iff] lemma continuous_at_pi [βˆ€ i, topological_space (Ο€ i)] [topological_space Ξ±] {f : Ξ± β†’ Ξ  i, Ο€ i} {x : Ξ±} : continuous_at f x ↔ βˆ€ i, continuous_at (Ξ» y, f y i) x := tendsto_pi lemma is_open_set_pi [βˆ€a, topological_space (Ο€ a)] {i : set ΞΉ} {s : Ξ a, set (Ο€ a)} (hi : finite i) (hs : βˆ€a∈i, is_open (s a)) : is_open (pi i s) := by rw [pi_def]; exact (is_open_bInter hi $ assume a ha, (hs _ ha).preimage (continuous_apply _)) lemma is_closed_set_pi [βˆ€a, topological_space (Ο€ a)] {i : set ΞΉ} {s : Ξ a, set (Ο€ a)} (hs : βˆ€a∈i, is_closed (s a)) : is_closed (pi i s) := by rw [pi_def]; exact (is_closed_Inter $ Ξ» a, is_closed_Inter $ Ξ» ha, (hs _ ha).preimage (continuous_apply _)) lemma set_pi_mem_nhds [Ξ  a, topological_space (Ο€ a)] {i : set ΞΉ} {s : Ξ  a, set (Ο€ a)} {x : Ξ  a, Ο€ a} (hi : finite i) (hs : βˆ€ a ∈ i, s a ∈ 𝓝 (x a)) : pi i s ∈ 𝓝 x := by { rw [pi_def, bInter_mem_sets hi], exact Ξ» a ha, (continuous_apply a).continuous_at (hs a ha) } lemma pi_eq_generate_from [βˆ€a, topological_space (Ο€ a)] : Pi.topological_space = generate_from {g | βˆƒ(s:Ξ a, set (Ο€ a)) (i : finset ΞΉ), (βˆ€a∈i, is_open (s a)) ∧ g = pi ↑i s} := le_antisymm (le_generate_from $ assume g ⟨s, i, hi, eq⟩, eq.symm β–Έ is_open_set_pi (finset.finite_to_set _) hi) (le_infi $ assume a s ⟨t, ht, s_eq⟩, generate_open.basic _ $ ⟨function.update (Ξ»a, univ) a t, {a}, by simpa using ht, by ext f; simp [s_eq.symm, pi]⟩) lemma pi_generate_from_eq {g : Ξ a, set (set (Ο€ a))} : @Pi.topological_space ΞΉ Ο€ (Ξ»a, generate_from (g a)) = generate_from {t | βˆƒ(s:Ξ a, set (Ο€ a)) (i : finset ΞΉ), (βˆ€a∈i, s a ∈ g a) ∧ t = pi ↑i s} := let G := {t | βˆƒ(s:Ξ a, set (Ο€ a)) (i : finset ΞΉ), (βˆ€a∈i, s a ∈ g a) ∧ t = pi ↑i s} in begin rw [pi_eq_generate_from], refine le_antisymm (generate_from_mono _) (le_generate_from _), exact assume s ⟨t, i, ht, eq⟩, ⟨t, i, assume a ha, generate_open.basic _ (ht a ha), eq⟩, { rintros s ⟨t, i, hi, rfl⟩, rw [pi_def], apply is_open_bInter (finset.finite_to_set _), assume a ha, show ((generate_from G).coinduced (Ξ»f:Ξ a, Ο€ a, f a)).is_open (t a), refine le_generate_from _ _ (hi a ha), exact assume s hs, generate_open.basic _ ⟨function.update (Ξ»a, univ) a s, {a}, by simp [hs]⟩ } end lemma pi_generate_from_eq_fintype {g : Ξ a, set (set (Ο€ a))} [fintype ΞΉ] (hg : βˆ€a, ⋃₀ g a = univ) : @Pi.topological_space ΞΉ Ο€ (Ξ»a, generate_from (g a)) = generate_from {t | βˆƒ(s:Ξ a, set (Ο€ a)), (βˆ€a, s a ∈ g a) ∧ t = pi univ s} := begin rw [pi_generate_from_eq], refine le_antisymm (generate_from_mono _) (le_generate_from _), exact assume s ⟨t, ht, eq⟩, ⟨t, finset.univ, by simp [ht, eq]⟩, { rintros s ⟨t, i, ht, rfl⟩, apply is_open_iff_forall_mem_open.2 _, assume f hf, choose c hc using show βˆ€a, βˆƒs, s ∈ g a ∧ f a ∈ s, { assume a, have : f a ∈ ⋃₀ g a, { rw [hg], apply mem_univ }, simpa }, refine ⟨pi univ (Ξ»a, if a ∈ i then t a else (c : Ξ a, set (Ο€ a)) a), _, _, _⟩, { simp [pi_if] }, { refine generate_open.basic _ ⟨_, assume a, _, rfl⟩, by_cases a ∈ i; simp [*, pi] at * }, { have : f ∈ pi {a | a βˆ‰ i} c, { simp [*, pi] at * }, simpa [pi_if, hf] } } end variables [fintype ΞΉ] [βˆ€ i, topological_space (Ο€ i)] [βˆ€ i, discrete_topology (Ο€ i)] /-- A finite product of discrete spaces is discrete. -/ instance Pi.discrete_topology : discrete_topology (Ξ  i, Ο€ i) := singletons_open_iff_discrete.mp (Ξ» x, begin rw show {x} = β‹‚ i, {y : Ξ  i, Ο€ i | y i = x i}, { ext, simp only [function.funext_iff, set.mem_singleton_iff, set.mem_Inter, set.mem_set_of_eq] }, exact is_open_Inter (Ξ» i, (continuous_apply i).is_open_preimage {x i} (is_open_discrete {x i})) end) end pi section sigma variables {ΞΉ : Type*} {Οƒ : ΞΉ β†’ Type*} [Ξ  i, topological_space (Οƒ i)] @[continuity] lemma continuous_sigma_mk {i : ΞΉ} : continuous (@sigma.mk ΞΉ Οƒ i) := continuous_supr_rng continuous_coinduced_rng lemma is_open_sigma_iff {s : set (sigma Οƒ)} : is_open s ↔ βˆ€ i, is_open (sigma.mk i ⁻¹' s) := by simp only [is_open_supr_iff, is_open_coinduced] lemma is_closed_sigma_iff {s : set (sigma Οƒ)} : is_closed s ↔ βˆ€ i, is_closed (sigma.mk i ⁻¹' s) := by simp [← is_open_compl_iff, is_open_sigma_iff] lemma is_open_map_sigma_mk {i : ΞΉ} : is_open_map (@sigma.mk ΞΉ Οƒ i) := begin intros s hs, rw is_open_sigma_iff, intro j, classical, by_cases h : i = j, { subst j, convert hs, exact set.preimage_image_eq _ sigma_mk_injective }, { convert is_open_empty, apply set.eq_empty_of_subset_empty, rintro x ⟨y, _, hy⟩, have : i = j, by cc, contradiction } end lemma is_open_range_sigma_mk {i : ΞΉ} : is_open (set.range (@sigma.mk ΞΉ Οƒ i)) := by { rw ←set.image_univ, exact is_open_map_sigma_mk _ is_open_univ } lemma is_closed_map_sigma_mk {i : ΞΉ} : is_closed_map (@sigma.mk ΞΉ Οƒ i) := begin intros s hs, rw is_closed_sigma_iff, intro j, classical, by_cases h : i = j, { subst j, convert hs, exact set.preimage_image_eq _ sigma_mk_injective }, { convert is_closed_empty, apply set.eq_empty_of_subset_empty, rintro x ⟨y, _, hy⟩, have : i = j, by cc, contradiction } end lemma is_closed_sigma_mk {i : ΞΉ} : is_closed (set.range (@sigma.mk ΞΉ Οƒ i)) := by { rw ←set.image_univ, exact is_closed_map_sigma_mk _ is_closed_univ } lemma open_embedding_sigma_mk {i : ΞΉ} : open_embedding (@sigma.mk ΞΉ Οƒ i) := open_embedding_of_continuous_injective_open continuous_sigma_mk sigma_mk_injective is_open_map_sigma_mk lemma closed_embedding_sigma_mk {i : ΞΉ} : closed_embedding (@sigma.mk ΞΉ Οƒ i) := closed_embedding_of_continuous_injective_closed continuous_sigma_mk sigma_mk_injective is_closed_map_sigma_mk lemma embedding_sigma_mk {i : ΞΉ} : embedding (@sigma.mk ΞΉ Οƒ i) := closed_embedding_sigma_mk.1 /-- A map out of a sum type is continuous if its restriction to each summand is. -/ @[continuity] lemma continuous_sigma [topological_space Ξ²] {f : sigma Οƒ β†’ Ξ²} (h : βˆ€ i, continuous (Ξ» a, f ⟨i, a⟩)) : continuous f := continuous_supr_dom (Ξ» i, continuous_coinduced_dom (h i)) @[continuity] lemma continuous_sigma_map {ΞΊ : Type*} {Ο„ : ΞΊ β†’ Type*} [Ξ  k, topological_space (Ο„ k)] {f₁ : ΞΉ β†’ ΞΊ} {fβ‚‚ : Ξ  i, Οƒ i β†’ Ο„ (f₁ i)} (hf : βˆ€ i, continuous (fβ‚‚ i)) : continuous (sigma.map f₁ fβ‚‚) := continuous_sigma $ Ξ» i, show continuous (Ξ» a, sigma.mk (f₁ i) (fβ‚‚ i a)), from continuous_sigma_mk.comp (hf i) lemma is_open_map_sigma [topological_space Ξ²] {f : sigma Οƒ β†’ Ξ²} (h : βˆ€ i, is_open_map (Ξ» a, f ⟨i, a⟩)) : is_open_map f := begin intros s hs, rw is_open_sigma_iff at hs, have : s = ⋃ i, sigma.mk i '' (sigma.mk i ⁻¹' s), { rw Union_image_preimage_sigma_mk_eq_self }, rw this, rw [image_Union], apply is_open_Union, intro i, rw [image_image], exact h i _ (hs i) end /-- The sum of embeddings is an embedding. -/ lemma embedding_sigma_map {Ο„ : ΞΉ β†’ Type*} [Ξ  i, topological_space (Ο„ i)] {f : Ξ  i, Οƒ i β†’ Ο„ i} (hf : βˆ€ i, embedding (f i)) : embedding (sigma.map id f) := begin refine ⟨⟨_⟩, function.injective_id.sigma_map (Ξ» i, (hf i).inj)⟩, refine le_antisymm (continuous_iff_le_induced.mp (continuous_sigma_map (Ξ» i, (hf i).continuous))) _, intros s hs, replace hs := is_open_sigma_iff.mp hs, have : βˆ€ i, βˆƒ t, is_open t ∧ f i ⁻¹' t = sigma.mk i ⁻¹' s, { intro i, apply is_open_induced_iff.mp, convert hs i, exact (hf i).induced.symm }, choose t ht using this, apply is_open_induced_iff.mpr, refine βŸ¨β‹ƒ i, sigma.mk i '' t i, is_open_Union (Ξ» i, is_open_map_sigma_mk _ (ht i).1), _⟩, ext ⟨i, x⟩, change (sigma.mk i (f i x) ∈ ⋃ (i : ΞΉ), sigma.mk i '' t i) ↔ x ∈ sigma.mk i ⁻¹' s, rw [←(ht i).2, mem_Union], split, { rintro ⟨j, hj⟩, rw mem_image at hj, rcases hj with ⟨y, hy₁, hyβ‚‚βŸ©, rcases sigma.mk.inj_iff.mp hyβ‚‚ with ⟨rfl, hy⟩, replace hy := eq_of_heq hy, subst y, exact hy₁ }, { intro hx, use i, rw mem_image, exact ⟨f i x, hx, rfl⟩ } end end sigma section ulift @[continuity] lemma continuous_ulift_down [topological_space Ξ±] : continuous (ulift.down : ulift.{v u} Ξ± β†’ Ξ±) := continuous_induced_dom @[continuity] lemma continuous_ulift_up [topological_space Ξ±] : continuous (ulift.up : Ξ± β†’ ulift.{v u} Ξ±) := continuous_induced_rng continuous_id end ulift lemma mem_closure_of_continuous [topological_space Ξ±] [topological_space Ξ²] {f : Ξ± β†’ Ξ²} {a : Ξ±} {s : set Ξ±} {t : set Ξ²} (hf : continuous f) (ha : a ∈ closure s) (h : maps_to f s (closure t)) : f a ∈ closure t := calc f a ∈ f '' closure s : mem_image_of_mem _ ha ... βŠ† closure (f '' s) : image_closure_subset_closure_image hf ... βŠ† closure t : closure_minimal h.image_subset is_closed_closure lemma mem_closure_of_continuous2 [topological_space Ξ±] [topological_space Ξ²] [topological_space Ξ³] {f : Ξ± β†’ Ξ² β†’ Ξ³} {a : Ξ±} {b : Ξ²} {s : set Ξ±} {t : set Ξ²} {u : set Ξ³} (hf : continuous (Ξ»p:Ξ±Γ—Ξ², f p.1 p.2)) (ha : a ∈ closure s) (hb : b ∈ closure t) (h : βˆ€a∈s, βˆ€b∈t, f a b ∈ closure u) : f a b ∈ closure u := have (a,b) ∈ closure (set.prod s t), by simp [closure_prod_eq, ha, hb], show f (a, b).1 (a, b).2 ∈ closure u, from @mem_closure_of_continuous (Ξ±Γ—Ξ²) _ _ _ (Ξ»p:Ξ±Γ—Ξ², f p.1 p.2) (a,b) _ u hf this $ assume ⟨p₁, pβ‚‚βŸ© ⟨h₁, hβ‚‚βŸ©, h p₁ h₁ pβ‚‚ hβ‚‚
7b2628614a1647b766515ce1e4a91ef6192dea94
4727251e0cd73359b15b664c3170e5d754078599
/src/algebra/group/ext.lean
4371ab068a610f73e0cbf170f26067eda04cbc9e
[ "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,984
lean
/- Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bryan Gin-ge Chen, Yury Kudryashov -/ import algebra.hom.group /-! # Extensionality lemmas for monoid and group structures In this file we prove extensionality lemmas for `monoid` and higher algebraic structures with one binary operation. Extensionality lemmas for structures that are lower in the hierarchy can be found in `algebra.group.defs`. ## Implementation details To get equality of `npow` etc, we define a monoid homomorphism between two monoid structures on the same type, then apply lemmas like `monoid_hom.map_div`, `monoid_hom.map_pow` etc. ## Tags monoid, group, extensionality -/ universe u @[ext, to_additive] lemma monoid.ext {M : Type u} ⦃m₁ mβ‚‚ : monoid M⦄ (h_mul : m₁.mul = mβ‚‚.mul) : m₁ = mβ‚‚ := begin have h₁ : (@monoid.to_mul_one_class _ m₁).one = (@monoid.to_mul_one_class _ mβ‚‚).one, from congr_arg (@mul_one_class.one M) (mul_one_class.ext h_mul), set f : @monoid_hom M M (@monoid.to_mul_one_class _ m₁) (@monoid.to_mul_one_class _ mβ‚‚) := { to_fun := id, map_one' := h₁, map_mul' := Ξ» x y, congr_fun (congr_fun h_mul x) y }, have hpow : m₁.npow = mβ‚‚.npow, by { ext n x, exact @monoid_hom.map_pow M M m₁ mβ‚‚ f x n }, unfreezingI { cases m₁, cases mβ‚‚ }, congr; assumption end @[to_additive] lemma comm_monoid.to_monoid_injective {M : Type u} : function.injective (@comm_monoid.to_monoid M) := begin rintros ⟨⟩ ⟨⟩ h, congr'; injection h, end @[ext, to_additive] lemma comm_monoid.ext {M : Type*} ⦃m₁ mβ‚‚ : comm_monoid M⦄ (h_mul : m₁.mul = mβ‚‚.mul) : m₁ = mβ‚‚ := comm_monoid.to_monoid_injective $ monoid.ext h_mul @[to_additive] lemma left_cancel_monoid.to_monoid_injective {M : Type u} : function.injective (@left_cancel_monoid.to_monoid M) := begin rintros ⟨⟩ ⟨⟩ h, congr'; injection h, end @[ext, to_additive] lemma left_cancel_monoid.ext {M : Type u} ⦃m₁ mβ‚‚ : left_cancel_monoid M⦄ (h_mul : m₁.mul = mβ‚‚.mul) : m₁ = mβ‚‚ := left_cancel_monoid.to_monoid_injective $ monoid.ext h_mul @[to_additive] lemma right_cancel_monoid.to_monoid_injective {M : Type u} : function.injective (@right_cancel_monoid.to_monoid M) := begin rintros ⟨⟩ ⟨⟩ h, congr'; injection h, end @[ext, to_additive] lemma right_cancel_monoid.ext {M : Type u} ⦃m₁ mβ‚‚ : right_cancel_monoid M⦄ (h_mul : m₁.mul = mβ‚‚.mul) : m₁ = mβ‚‚ := right_cancel_monoid.to_monoid_injective $ monoid.ext h_mul @[to_additive] lemma cancel_monoid.to_left_cancel_monoid_injective {M : Type u} : function.injective (@cancel_monoid.to_left_cancel_monoid M) := begin rintros ⟨⟩ ⟨⟩ h, congr'; injection h, end @[ext, to_additive] lemma cancel_monoid.ext {M : Type*} ⦃m₁ mβ‚‚ : cancel_monoid M⦄ (h_mul : m₁.mul = mβ‚‚.mul) : m₁ = mβ‚‚ := cancel_monoid.to_left_cancel_monoid_injective $ left_cancel_monoid.ext h_mul @[to_additive] lemma cancel_comm_monoid.to_comm_monoid_injective {M : Type u} : function.injective (@cancel_comm_monoid.to_comm_monoid M) := begin rintros ⟨⟩ ⟨⟩ h, congr'; injection h, end @[ext, to_additive] lemma cancel_comm_monoid.ext {M : Type*} ⦃m₁ mβ‚‚ : cancel_comm_monoid M⦄ (h_mul : m₁.mul = mβ‚‚.mul) : m₁ = mβ‚‚ := cancel_comm_monoid.to_comm_monoid_injective $ comm_monoid.ext h_mul @[ext, to_additive] lemma div_inv_monoid.ext {M : Type*} ⦃m₁ mβ‚‚ : div_inv_monoid M⦄ (h_mul : m₁.mul = mβ‚‚.mul) (h_inv : m₁.inv = mβ‚‚.inv) : m₁ = mβ‚‚ := begin have h₁ : (@div_inv_monoid.to_monoid _ m₁).one = (@div_inv_monoid.to_monoid _ mβ‚‚).one, from congr_arg (@monoid.one M) (monoid.ext h_mul), set f : @monoid_hom M M (by letI := m₁; apply_instance) (by letI := mβ‚‚; apply_instance) := { to_fun := id, map_one' := h₁, map_mul' := Ξ» x y, congr_fun (congr_fun h_mul x) y }, have hpow : (@div_inv_monoid.to_monoid _ m₁).npow = (@div_inv_monoid.to_monoid _ mβ‚‚).npow := congr_arg (@monoid.npow M) (monoid.ext h_mul), have hzpow : m₁.zpow = mβ‚‚.zpow, { ext m x, exact @monoid_hom.map_zpow' M M m₁ mβ‚‚ f (congr_fun h_inv) x m }, have hdiv : m₁.div = mβ‚‚.div, { ext a b, exact @map_div' M M _ m₁ mβ‚‚ _ f (congr_fun h_inv) a b }, unfreezingI { cases m₁, cases mβ‚‚ }, congr, exacts [h_mul, h₁, hpow, h_inv, hdiv, hzpow] end @[ext, to_additive] lemma group.ext {G : Type*} ⦃g₁ gβ‚‚ : group G⦄ (h_mul : g₁.mul = gβ‚‚.mul) : g₁ = gβ‚‚ := begin set f := @monoid_hom.mk' G G (by letI := g₁; apply_instance) gβ‚‚ id (Ξ» a b, congr_fun (congr_fun h_mul a) b), exact group.to_div_inv_monoid_injective (div_inv_monoid.ext h_mul (funext $ @monoid_hom.map_inv G G g₁ gβ‚‚ f)) end @[ext, to_additive] lemma comm_group.ext {G : Type*} ⦃g₁ gβ‚‚ : comm_group G⦄ (h_mul : g₁.mul = gβ‚‚.mul) : g₁ = gβ‚‚ := comm_group.to_group_injective $ group.ext h_mul
b7edbd7d02fd365919d98f7b067d134936acb407
22e97a5d648fc451e25a06c668dc03ac7ed7bc25
/src/data/equiv/mul_add.lean
b0897fce5df3f25e8d458cac84b39ff26cb9439b
[ "Apache-2.0" ]
permissive
keeferrowan/mathlib
f2818da875dbc7780830d09bd4c526b0764a4e50
aad2dfc40e8e6a7e258287a7c1580318e865817e
refs/heads/master
1,661,736,426,952
1,590,438,032,000
1,590,438,032,000
266,892,663
0
0
Apache-2.0
1,590,445,835,000
1,590,445,835,000
null
UTF-8
Lean
false
false
11,071
lean
/- Copyright (c) 2018 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Callum Sutton, Yury Kudryashov -/ import data.equiv.basic import deprecated.group /-! # Multiplicative and additive equivs In this file we define two extensions of `equiv` called `add_equiv` and `mul_equiv`, which are datatypes representing isomorphisms of `add_monoid`s/`add_group`s and `monoid`s/`group`s. We also introduce the corresponding groups of automorphisms `add_aut` and `mul_aut`. ## Notations The extended equivs all have coercions to functions, and the coercions are the canonical notation when treating the isomorphisms as maps. ## Implementation notes The fields for `mul_equiv`, `add_equiv` now avoid the unbundled `is_mul_hom` and `is_add_hom`, as these are deprecated. Definition of multiplication in the groups of automorphisms agrees with function composition, multiplication in `equiv.perm`, and multiplication in `category_theory.End`, not with `category_theory.comp`. ## Tags equiv, mul_equiv, add_equiv, mul_aut, add_aut -/ variables {A : Type*} {B : Type*} {M : Type*} {N : Type*} {P : Type*} {G : Type*} {H : Type*} set_option old_structure_cmd true /-- add_equiv Ξ± Ξ² is the type of an equiv Ξ± ≃ Ξ² which preserves addition. -/ structure add_equiv (A B : Type*) [has_add A] [has_add B] extends A ≃ B := (map_add' : βˆ€ x y : A, to_fun (x + y) = to_fun x + to_fun y) /-- `mul_equiv Ξ± Ξ²` is the type of an equiv `Ξ± ≃ Ξ²` which preserves multiplication. -/ @[to_additive] structure mul_equiv (M N : Type*) [has_mul M] [has_mul N] extends M ≃ N := (map_mul' : βˆ€ x y : M, to_fun (x * y) = to_fun x * to_fun y) infix ` ≃* `:25 := mul_equiv infix ` ≃+ `:25 := add_equiv namespace mul_equiv @[to_additive] instance [has_mul M] [has_mul N] : has_coe_to_fun (M ≃* N) := ⟨_, mul_equiv.to_fun⟩ variables [has_mul M] [has_mul N] [has_mul P] /-- A multiplicative isomorphism preserves multiplication (canonical form). -/ @[to_additive] lemma map_mul (f : M ≃* N) : βˆ€ x y, f (x * y) = f x * f y := f.map_mul' /-- A multiplicative isomorphism preserves multiplication (deprecated). -/ @[to_additive] instance (h : M ≃* N) : is_mul_hom h := ⟨h.map_mul⟩ /-- Makes a multiplicative isomorphism from a bijection which preserves multiplication. -/ @[to_additive] def mk' (f : M ≃ N) (h : βˆ€ x y, f (x * y) = f x * f y) : M ≃* N := ⟨f.1, f.2, f.3, f.4, h⟩ /-- The identity map is a multiplicative isomorphism. -/ @[refl, to_additive] def refl (M : Type*) [has_mul M] : M ≃* M := { map_mul' := Ξ» _ _, rfl, ..equiv.refl _} /-- The inverse of an isomorphism is an isomorphism. -/ @[symm, to_additive] def symm (h : M ≃* N) : N ≃* M := { map_mul' := Ξ» n₁ nβ‚‚, h.left_inv.injective begin show h.to_equiv (h.to_equiv.symm (n₁ * nβ‚‚)) = h ((h.to_equiv.symm n₁) * (h.to_equiv.symm nβ‚‚)), rw h.map_mul, show _ = h.to_equiv (_) * h.to_equiv (_), rw [h.to_equiv.apply_symm_apply, h.to_equiv.apply_symm_apply, h.to_equiv.apply_symm_apply], end, ..h.to_equiv.symm} @[simp, to_additive] theorem to_equiv_symm (f : M ≃* N) : f.symm.to_equiv = f.to_equiv.symm := rfl @[simp, to_additive] theorem coe_mk (f : M β†’ N) (g h₁ hβ‚‚ h₃) : ⇑(mul_equiv.mk f g h₁ hβ‚‚ h₃) = f := rfl @[simp, to_additive] theorem coe_symm_mk (f : M β†’ N) (g h₁ hβ‚‚ h₃) : ⇑(mul_equiv.mk f g h₁ hβ‚‚ h₃).symm = g := rfl /-- Transitivity of multiplication-preserving isomorphisms -/ @[trans, to_additive] def trans (h1 : M ≃* N) (h2 : N ≃* P) : (M ≃* P) := { map_mul' := Ξ» x y, show h2 (h1 (x * y)) = h2 (h1 x) * h2 (h1 y), by rw [h1.map_mul, h2.map_mul], ..h1.to_equiv.trans h2.to_equiv } /-- e.right_inv in canonical form -/ @[simp, to_additive] lemma apply_symm_apply (e : M ≃* N) : βˆ€ y, e (e.symm y) = y := e.to_equiv.apply_symm_apply /-- e.left_inv in canonical form -/ @[simp, to_additive] lemma symm_apply_apply (e : M ≃* N) : βˆ€ x, e.symm (e x) = x := e.to_equiv.symm_apply_apply /-- a multiplicative equiv of monoids sends 1 to 1 (and is hence a monoid isomorphism) -/ @[simp, to_additive] lemma map_one {M N} [monoid M] [monoid N] (h : M ≃* N) : h 1 = 1 := by rw [←mul_one (h 1), ←h.apply_symm_apply 1, ←h.map_mul, one_mul] @[simp, to_additive] lemma map_eq_one_iff {M N} [monoid M] [monoid N] (h : M ≃* N) {x : M} : h x = 1 ↔ x = 1 := h.map_one β–Έ h.to_equiv.apply_eq_iff_eq x 1 @[to_additive] lemma map_ne_one_iff {M N} [monoid M] [monoid N] (h : M ≃* N) {x : M} : h x β‰  1 ↔ x β‰  1 := ⟨mt h.map_eq_one_iff.2, mt h.map_eq_one_iff.1⟩ /-- Extract the forward direction of a multiplicative equivalence as a multiplication preserving function. -/ @[to_additive to_add_monoid_hom] def to_monoid_hom {M N} [monoid M] [monoid N] (h : M ≃* N) : (M β†’* N) := { map_one' := h.map_one, .. h } @[simp, to_additive] lemma to_monoid_hom_apply {M N} [monoid M] [monoid N] (e : M ≃* N) (x : M) : e.to_monoid_hom x = e x := rfl /-- A multiplicative equivalence of groups preserves inversion. -/ @[to_additive] lemma map_inv [group G] [group H] (h : G ≃* H) (x : G) : h x⁻¹ = (h x)⁻¹ := h.to_monoid_hom.map_inv x /-- A multiplicative bijection between two monoids is a monoid hom (deprecated -- use to_monoid_hom). -/ @[to_additive is_add_monoid_hom] instance is_monoid_hom {M N} [monoid M] [monoid N] (h : M ≃* N) : is_monoid_hom h := ⟨h.map_one⟩ /-- A multiplicative bijection between two groups is a group hom (deprecated -- use to_monoid_hom). -/ @[to_additive is_add_group_hom] instance is_group_hom {G H} [group G] [group H] (h : G ≃* H) : is_group_hom h := { map_mul := h.map_mul } /-- Two multiplicative isomorphisms agree if they are defined by the same underlying function. -/ @[ext, to_additive "Two additive isomorphisms agree if they are defined by the same underlying function."] lemma ext {f g : mul_equiv M N} (h : βˆ€ x, f x = g x) : f = g := begin have h₁ : f.to_equiv = g.to_equiv := equiv.ext h, cases f, cases g, congr, { exact (funext h) }, { exact congr_arg equiv.inv_fun h₁ } end attribute [ext] add_equiv.ext end mul_equiv /-- An additive equivalence of additive groups preserves subtraction. -/ lemma add_equiv.map_sub [add_group A] [add_group B] (h : A ≃+ B) (x y : A) : h (x - y) = h x - h y := h.to_add_monoid_hom.map_sub x y /-- The group of multiplicative automorphisms. -/ @[to_additive "The group of additive automorphisms."] def mul_aut (M : Type*) [has_mul M] := M ≃* M namespace mul_aut variables (M) [has_mul M] /-- The group operation on multiplicative automorphisms is defined by `Ξ» g h, mul_equiv.trans h g`. This means that multiplication agrees with composition, `(g*h)(x) = g (h x)`. -/ instance : group (mul_aut M) := by refine_struct { mul := Ξ» g h, mul_equiv.trans h g, one := mul_equiv.refl M, inv := mul_equiv.symm }; intros; ext; try { refl }; apply equiv.left_inv instance : inhabited (mul_aut M) := ⟨1⟩ /-- Monoid hom from the group of multiplicative automorphisms to the group of permutations. -/ def to_perm : mul_aut M β†’* equiv.perm M := by refine_struct { to_fun := mul_equiv.to_equiv }; intros; refl end mul_aut namespace add_aut variables (A) [has_add A] /-- The group operation on additive automorphisms is defined by `Ξ» g h, mul_equiv.trans h g`. This means that multiplication agrees with composition, `(g*h)(x) = g (h x)`. -/ instance group : group (add_aut A) := by refine_struct { mul := Ξ» g h, add_equiv.trans h g, one := add_equiv.refl A, inv := add_equiv.symm }; intros; ext; try { refl }; apply equiv.left_inv instance : inhabited (add_aut A) := ⟨1⟩ /-- Monoid hom from the group of multiplicative automorphisms to the group of permutations. -/ def to_perm : add_aut A β†’* equiv.perm A := by refine_struct { to_fun := add_equiv.to_equiv }; intros; refl end add_aut /-- A group is isomorphic to its group of units. -/ def to_units (G) [group G] : G ≃* units G := { to_fun := Ξ» x, ⟨x, x⁻¹, mul_inv_self _, inv_mul_self _⟩, inv_fun := coe, left_inv := Ξ» x, rfl, right_inv := Ξ» u, units.ext rfl, map_mul' := Ξ» x y, units.ext rfl } namespace units variables [monoid M] [monoid N] [monoid P] /-- A multiplicative equivalence of monoids defines a multiplicative equivalence of their groups of units. -/ def map_equiv (h : M ≃* N) : units M ≃* units N := { inv_fun := map h.symm.to_monoid_hom, left_inv := Ξ» u, ext $ h.left_inv u, right_inv := Ξ» u, ext $ h.right_inv u, .. map h.to_monoid_hom } end units namespace equiv section group variables [group G] @[to_additive] protected def mul_left (a : G) : perm G := { to_fun := Ξ»x, a * x, inv_fun := Ξ»x, a⁻¹ * x, left_inv := assume x, show a⁻¹ * (a * x) = x, from inv_mul_cancel_left a x, right_inv := assume x, show a * (a⁻¹ * x) = x, from mul_inv_cancel_left a x } @[to_additive] protected def mul_right (a : G) : perm G := { to_fun := Ξ»x, x * a, inv_fun := Ξ»x, x * a⁻¹, left_inv := assume x, show (x * a) * a⁻¹ = x, from mul_inv_cancel_right x a, right_inv := assume x, show (x * a⁻¹) * a = x, from inv_mul_cancel_right x a } variable (G) @[to_additive] protected def inv : perm G := { to_fun := Ξ»a, a⁻¹, inv_fun := Ξ»a, a⁻¹, left_inv := assume a, inv_inv a, right_inv := assume a, inv_inv a } end group section point_reflection variables [add_comm_group A] (x y : A) /-- Point reflection in `x` as a permutation. -/ def point_reflection (x : A) : perm A := (equiv.neg A).trans (equiv.add_left (x + x)) lemma point_reflection_apply : point_reflection x y = x + x - y := rfl @[simp] lemma point_reflection_self : point_reflection x x = x := add_sub_cancel _ _ lemma point_reflection_involutive : function.involutive (point_reflection x : A β†’ A) := Ξ» y, by simp only [point_reflection_apply, sub_sub_cancel] @[simp] lemma point_reflection_symm : (point_reflection x).symm = point_reflection x := by { ext y, rw [symm_apply_eq, point_reflection_involutive x y] } /-- `x` is the only fixed point of `point_reflection x`. This lemma requires `x + x = y + y ↔ x = y`. There is no typeclass to use here, so we add it as an explicit argument. -/ lemma point_reflection_fixed_iff_of_bit0_inj {x y : A} (h : function.injective (bit0 : A β†’ A)) : point_reflection x y = y ↔ y = x := sub_eq_iff_eq_add.trans $ h.eq_iff.trans eq_comm end point_reflection end equiv section type_tags /-- Reinterpret `f : G ≃+ H` as `multiplicative G ≃* multiplicative H`. -/ def add_equiv.to_multiplicative [add_monoid G] [add_monoid H] (f : G ≃+ H) : multiplicative G ≃* multiplicative H := ⟨f.to_add_monoid_hom.to_multiplicative, f.symm.to_add_monoid_hom.to_multiplicative, f.3, f.4, f.5⟩ /-- Reinterpret `f : G ≃* H` as `additive G ≃+ additive H`. -/ def mul_equiv.to_additive [monoid G] [monoid H] (f : G ≃* H) : additive G ≃+ additive H := ⟨f.to_monoid_hom.to_additive, f.symm.to_monoid_hom.to_additive, f.3, f.4, f.5⟩ end type_tags
e10719245a9d1c5d0d025b1e26e39479cd287496
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/algebra/lie/nilpotent.lean
acf0c6fba770bc50797290602966a81b0755068d
[ "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
27,739
lean
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import algebra.lie.solvable import algebra.lie.quotient import algebra.lie.centralizer import linear_algebra.eigenspace import ring_theory.nilpotent /-! # Nilpotent Lie algebras Like groups, Lie algebras admit a natural concept of nilpotency. More generally, any Lie module carries a natural concept of nilpotency. We define these here via the lower central series. ## Main definitions * `lie_module.lower_central_series` * `lie_module.is_nilpotent` ## Tags lie algebra, lower central series, nilpotent -/ universes u v w w₁ wβ‚‚ section nilpotent_modules variables {R : Type u} {L : Type v} {M : Type w} variables [comm_ring R] [lie_ring L] [lie_algebra R L] [add_comm_group M] [module R M] variables [lie_ring_module L M] [lie_module R L M] variables (k : β„•) (N : lie_submodule R L M) namespace lie_submodule /-- A generalisation of the lower central series. The zeroth term is a specified Lie submodule of a Lie module. In the case when we specify the top ideal `⊀` of the Lie algebra, regarded as a Lie module over itself, we get the usual lower central series of a Lie algebra. It can be more convenient to work with this generalisation when considering the lower central series of a Lie submodule, regarded as a Lie module in its own right, since it provides a type-theoretic expression of the fact that the terms of the Lie submodule's lower central series are also Lie submodules of the enclosing Lie module. See also `lie_module.lower_central_series_eq_lcs_comap` and `lie_module.lower_central_series_map_eq_lcs` below, as well as `lie_submodule.ucs`. -/ def lcs : lie_submodule R L M β†’ lie_submodule R L M := (Ξ» N, ⁅(⊀ : lie_ideal R L), N⁆)^[k] @[simp] lemma lcs_zero (N : lie_submodule R L M) : N.lcs 0 = N := rfl @[simp] lemma lcs_succ : N.lcs (k + 1) = ⁅(⊀ : lie_ideal R L), N.lcs k⁆ := function.iterate_succ_apply' (Ξ» N', β…βŠ€, N'⁆) k N end lie_submodule namespace lie_module variables (R L M) /-- The lower central series of Lie submodules of a Lie module. -/ def lower_central_series : lie_submodule R L M := (⊀ : lie_submodule R L M).lcs k @[simp] lemma lower_central_series_zero : lower_central_series R L M 0 = ⊀ := rfl @[simp] lemma lower_central_series_succ : lower_central_series R L M (k + 1) = ⁅(⊀ : lie_ideal R L), lower_central_series R L M k⁆ := (⊀ : lie_submodule R L M).lcs_succ k end lie_module namespace lie_submodule open lie_module variables {R L M} lemma lcs_le_self : N.lcs k ≀ N := begin induction k with k ih, { simp, }, { simp only [lcs_succ], exact (lie_submodule.mono_lie_right _ _ ⊀ ih).trans (N.lie_le_right ⊀), }, end lemma lower_central_series_eq_lcs_comap : lower_central_series R L N k = (N.lcs k).comap N.incl := begin induction k with k ih, { simp, }, { simp only [lcs_succ, lower_central_series_succ] at ⊒ ih, have : N.lcs k ≀ N.incl.range, { rw N.range_incl, apply lcs_le_self, }, rw [ih, lie_submodule.comap_bracket_eq _ _ N.incl N.ker_incl this], }, end lemma lower_central_series_map_eq_lcs : (lower_central_series R L N k).map N.incl = N.lcs k := begin rw [lower_central_series_eq_lcs_comap, lie_submodule.map_comap_incl, inf_eq_right], apply lcs_le_self, end end lie_submodule namespace lie_module variables (R L M) lemma antitone_lower_central_series : antitone $ lower_central_series R L M := begin intros l k, induction k with k ih generalizing l; intros h, { exact (le_zero_iff.mp h).symm β–Έ le_rfl, }, { rcases nat.of_le_succ h with hk | hk, { rw lower_central_series_succ, exact (lie_submodule.mono_lie_right _ _ ⊀ (ih hk)).trans (lie_submodule.lie_le_right _ _), }, { exact hk.symm β–Έ le_rfl, }, }, end lemma trivial_iff_lower_central_eq_bot : is_trivial L M ↔ lower_central_series R L M 1 = βŠ₯ := begin split; intros h, { erw [eq_bot_iff, lie_submodule.lie_span_le], rintros m ⟨x, n, hn⟩, rw [← hn, h.trivial], simp,}, { rw lie_submodule.eq_bot_iff at h, apply is_trivial.mk, intros x m, apply h, apply lie_submodule.subset_lie_span, use [x, m], refl, }, end lemma iterate_to_endomorphism_mem_lower_central_series (x : L) (m : M) (k : β„•) : (to_endomorphism R L M x)^[k] m ∈ lower_central_series R L M k := begin induction k with k ih, { simp only [function.iterate_zero], }, { simp only [lower_central_series_succ, function.comp_app, function.iterate_succ', to_endomorphism_apply_apply], exact lie_submodule.lie_mem_lie _ _ (lie_submodule.mem_top x) ih, }, end variables {R L M} lemma map_lower_central_series_le {Mβ‚‚ : Type w₁} [add_comm_group Mβ‚‚] [module R Mβ‚‚] [lie_ring_module L Mβ‚‚] [lie_module R L Mβ‚‚] (k : β„•) (f : M →ₗ⁅R,L⁆ Mβ‚‚) : lie_submodule.map f (lower_central_series R L M k) ≀ lower_central_series R L Mβ‚‚ k := begin induction k with k ih, { simp only [lie_module.lower_central_series_zero, le_top], }, { simp only [lie_module.lower_central_series_succ, lie_submodule.map_bracket_eq], exact lie_submodule.mono_lie_right _ _ ⊀ ih, }, end variables (R L M) open lie_algebra lemma derived_series_le_lower_central_series (k : β„•) : derived_series R L k ≀ lower_central_series R L L k := begin induction k with k h, { rw [derived_series_def, derived_series_of_ideal_zero, lower_central_series_zero], exact le_rfl, }, { have h' : derived_series R L k ≀ ⊀, { simp only [le_top], }, rw [derived_series_def, derived_series_of_ideal_succ, lower_central_series_succ], exact lie_submodule.mono_lie _ _ _ _ h' h, }, end /-- A Lie module is nilpotent if its lower central series reaches 0 (in a finite number of steps). -/ class is_nilpotent : Prop := (nilpotent : βˆƒ k, lower_central_series R L M k = βŠ₯) /-- See also `lie_module.is_nilpotent_iff_exists_ucs_eq_top`. -/ lemma is_nilpotent_iff : is_nilpotent R L M ↔ βˆƒ k, lower_central_series R L M k = βŠ₯ := ⟨λ h, h.nilpotent, Ξ» h, ⟨h⟩⟩ variables {R L M} lemma _root_.lie_submodule.is_nilpotent_iff_exists_lcs_eq_bot (N : lie_submodule R L M) : lie_module.is_nilpotent R L N ↔ βˆƒ k, N.lcs k = βŠ₯ := begin rw is_nilpotent_iff, refine exists_congr (Ξ» k, _), rw [N.lower_central_series_eq_lcs_comap k, lie_submodule.comap_incl_eq_bot, inf_eq_right.mpr (N.lcs_le_self k)], end variables (R L M) @[priority 100] instance trivial_is_nilpotent [is_trivial L M] : is_nilpotent R L M := ⟨by { use 1, change β…βŠ€, βŠ€β† = βŠ₯, simp, }⟩ lemma nilpotent_endo_of_nilpotent_module [hM : is_nilpotent R L M] : βˆƒ (k : β„•), βˆ€ (x : L), (to_endomorphism R L M x)^k = 0 := begin unfreezingI { obtain ⟨k, hM⟩ := hM, }, use k, intros x, ext m, rw [linear_map.pow_apply, linear_map.zero_apply, ← @lie_submodule.mem_bot R L M, ← hM], exact iterate_to_endomorphism_mem_lower_central_series R L M x m k, end /-- For a nilpotent Lie module, the weight space of the 0 weight is the whole module. This result will be used downstream to show that weight spaces are Lie submodules, at which time it will be possible to state it in the language of weight spaces. -/ lemma infi_max_gen_zero_eigenspace_eq_top_of_nilpotent [is_nilpotent R L M] : (β¨… (x : L), (to_endomorphism R L M x).maximal_generalized_eigenspace 0) = ⊀ := begin ext m, simp only [module.End.mem_maximal_generalized_eigenspace, submodule.mem_top, sub_zero, iff_true, zero_smul, submodule.mem_infi], intros x, obtain ⟨k, hk⟩ := nilpotent_endo_of_nilpotent_module R L M, use k, rw hk, exact linear_map.zero_apply m, end /-- If the quotient of a Lie module `M` by a Lie submodule on which the Lie algebra acts trivially is nilpotent then `M` is nilpotent. This is essentially the Lie module equivalent of the fact that a central extension of nilpotent Lie algebras is nilpotent. See `lie_algebra.nilpotent_of_nilpotent_quotient` below for the corresponding result for Lie algebras. -/ lemma nilpotent_of_nilpotent_quotient {N : lie_submodule R L M} (h₁ : N ≀ max_triv_submodule R L M) (hβ‚‚ : is_nilpotent R L (M β§Έ N)) : is_nilpotent R L M := begin unfreezingI { obtain ⟨k, hk⟩ := hβ‚‚, }, use k+1, simp only [lower_central_series_succ], suffices : lower_central_series R L M k ≀ N, { replace this := lie_submodule.mono_lie_right _ _ ⊀ (le_trans this h₁), rwa [ideal_oper_max_triv_submodule_eq_bot, le_bot_iff] at this, }, rw [← lie_submodule.quotient.map_mk'_eq_bot_le, ← le_bot_iff, ← hk], exact map_lower_central_series_le k (lie_submodule.quotient.mk' N), end /-- Given a nilpotent Lie module `M` with lower central series `M = Cβ‚€ β‰₯ C₁ β‰₯ β‹― β‰₯ Cβ‚– = βŠ₯`, this is the natural number `k` (the number of inclusions). For a non-nilpotent module, we use the junk value 0. -/ noncomputable def nilpotency_length : β„• := Inf { k | lower_central_series R L M k = βŠ₯ } lemma nilpotency_length_eq_zero_iff [is_nilpotent R L M] : nilpotency_length R L M = 0 ↔ subsingleton M := begin let s := { k | lower_central_series R L M k = βŠ₯ }, have hs : s.nonempty, { unfreezingI { obtain ⟨k, hk⟩ := (by apply_instance : is_nilpotent R L M), }, exact ⟨k, hk⟩, }, change Inf s = 0 ↔ _, rw [← lie_submodule.subsingleton_iff R L M, ← subsingleton_iff_bot_eq_top, ← lower_central_series_zero, @eq_comm (lie_submodule R L M)], refine ⟨λ h, h β–Έ nat.Inf_mem hs, Ξ» h, _⟩, rw nat.Inf_eq_zero, exact or.inl h, end lemma nilpotency_length_eq_succ_iff (k : β„•) : nilpotency_length R L M = k + 1 ↔ lower_central_series R L M (k + 1) = βŠ₯ ∧ lower_central_series R L M k β‰  βŠ₯ := begin let s := { k | lower_central_series R L M k = βŠ₯ }, change Inf s = k + 1 ↔ k + 1 ∈ s ∧ k βˆ‰ s, have hs : βˆ€ k₁ kβ‚‚, k₁ ≀ kβ‚‚ β†’ k₁ ∈ s β†’ kβ‚‚ ∈ s, { rintros k₁ kβ‚‚ h₁₂ (h₁ : lower_central_series R L M k₁ = βŠ₯), exact eq_bot_iff.mpr (h₁ β–Έ antitone_lower_central_series R L M h₁₂), }, exact nat.Inf_upward_closed_eq_succ_iff hs k, end /-- Given a non-trivial nilpotent Lie module `M` with lower central series `M = Cβ‚€ β‰₯ C₁ β‰₯ β‹― β‰₯ Cβ‚– = βŠ₯`, this is the `k-1`th term in the lower central series (the last non-trivial term). For a trivial or non-nilpotent module, this is the bottom submodule, `βŠ₯`. -/ noncomputable def lower_central_series_last : lie_submodule R L M := match nilpotency_length R L M with | 0 := βŠ₯ | k + 1 := lower_central_series R L M k end lemma lower_central_series_last_le_max_triv : lower_central_series_last R L M ≀ max_triv_submodule R L M := begin rw lower_central_series_last, cases h : nilpotency_length R L M with k, { exact bot_le, }, { rw le_max_triv_iff_bracket_eq_bot, rw [nilpotency_length_eq_succ_iff, lower_central_series_succ] at h, exact h.1, }, end lemma nontrivial_lower_central_series_last [nontrivial M] [is_nilpotent R L M] : nontrivial (lower_central_series_last R L M) := begin rw [lie_submodule.nontrivial_iff_ne_bot, lower_central_series_last], cases h : nilpotency_length R L M, { rw [nilpotency_length_eq_zero_iff, ← not_nontrivial_iff_subsingleton] at h, contradiction, }, { rw nilpotency_length_eq_succ_iff at h, exact h.2, }, end lemma nontrivial_max_triv_of_is_nilpotent [nontrivial M] [is_nilpotent R L M] : nontrivial (max_triv_submodule R L M) := set.nontrivial_mono (lower_central_series_last_le_max_triv R L M) (nontrivial_lower_central_series_last R L M) @[simp] lemma coe_lcs_range_to_endomorphism_eq (k : β„•) : (lower_central_series R (to_endomorphism R L M).range M k : submodule R M) = lower_central_series R L M k := begin induction k with k ih, { simp, }, { simp only [lower_central_series_succ, lie_submodule.lie_ideal_oper_eq_linear_span', ← (lower_central_series R (to_endomorphism R L M).range M k).mem_coe_submodule, ih], congr, ext m, split, { rintros ⟨⟨-, ⟨y, rfl⟩⟩, -, n, hn, rfl⟩, exact ⟨y, lie_submodule.mem_top _, n, hn, rfl⟩, }, { rintros ⟨x, hx, n, hn, rfl⟩, exact ⟨⟨to_endomorphism R L M x, lie_hom.mem_range_self _ x⟩, lie_submodule.mem_top _, n, hn, rfl⟩, }, }, end @[simp] lemma is_nilpotent_range_to_endomorphism_iff : is_nilpotent R (to_endomorphism R L M).range M ↔ is_nilpotent R L M := begin split; rintros ⟨k, hk⟩; use k; rw ← lie_submodule.coe_to_submodule_eq_iff at ⊒ hk; simpa using hk, end end lie_module namespace lie_submodule variables {N₁ Nβ‚‚ : lie_submodule R L M} /-- The upper (aka ascending) central series. See also `lie_submodule.lcs`. -/ def ucs (k : β„•) : lie_submodule R L M β†’ lie_submodule R L M := centralizer^[k] @[simp] lemma ucs_zero : N.ucs 0 = N := rfl @[simp] lemma ucs_succ (k : β„•) : N.ucs (k + 1) = (N.ucs k).centralizer := function.iterate_succ_apply' centralizer k N lemma ucs_add (k l : β„•) : N.ucs (k + l) = (N.ucs l).ucs k := function.iterate_add_apply centralizer k l N @[mono] lemma ucs_mono (k : β„•) (h : N₁ ≀ Nβ‚‚) : N₁.ucs k ≀ Nβ‚‚.ucs k := begin induction k with k ih, { simpa, }, simp only [ucs_succ], mono, end lemma ucs_eq_self_of_centralizer_eq_self (h : N₁.centralizer = N₁) (k : β„•) : N₁.ucs k = N₁ := by { induction k with k ih, { simp, }, { rwa [ucs_succ, ih], }, } /-- If a Lie module `M` contains a self-centralizing Lie submodule `N`, then all terms of the upper central series of `M` are contained in `N`. An important instance of this situation arises from a Cartan subalgebra `H βŠ† L` with the roles of `L`, `M`, `N` played by `H`, `L`, `H`, respectively. -/ lemma ucs_le_of_centralizer_eq_self (h : N₁.centralizer = N₁) (k : β„•) : (βŠ₯ : lie_submodule R L M).ucs k ≀ N₁ := by { rw ← ucs_eq_self_of_centralizer_eq_self h k, mono, simp, } lemma lcs_add_le_iff (l k : β„•) : N₁.lcs (l + k) ≀ Nβ‚‚ ↔ N₁.lcs l ≀ Nβ‚‚.ucs k := begin revert l, induction k with k ih, { simp, }, intros l, rw [(by abel : l + (k + 1) = l + 1 + k), ih, ucs_succ, lcs_succ, top_lie_le_iff_le_centralizer], end lemma lcs_le_iff (k : β„•) : N₁.lcs k ≀ Nβ‚‚ ↔ N₁ ≀ Nβ‚‚.ucs k := by { convert lcs_add_le_iff 0 k, rw zero_add, } lemma gc_lcs_ucs (k : β„•): galois_connection (Ξ» (N : lie_submodule R L M), N.lcs k) (Ξ» (N : lie_submodule R L M), N.ucs k) := Ξ» N₁ Nβ‚‚, lcs_le_iff k lemma ucs_eq_top_iff (k : β„•) : N.ucs k = ⊀ ↔ lie_module.lower_central_series R L M k ≀ N := by { rw [eq_top_iff, ← lcs_le_iff], refl, } lemma _root_.lie_module.is_nilpotent_iff_exists_ucs_eq_top : lie_module.is_nilpotent R L M ↔ βˆƒ k, (βŠ₯ : lie_submodule R L M).ucs k = ⊀ := by { rw lie_module.is_nilpotent_iff, exact exists_congr (Ξ» k, by simp [ucs_eq_top_iff]), } lemma ucs_comap_incl (k : β„•) : ((βŠ₯ : lie_submodule R L M).ucs k).comap N.incl = (βŠ₯ : lie_submodule R L N).ucs k := by { induction k with k ih, { exact N.ker_incl, }, { simp [← ih], }, } lemma is_nilpotent_iff_exists_self_le_ucs : lie_module.is_nilpotent R L N ↔ βˆƒ k, N ≀ (βŠ₯ : lie_submodule R L M).ucs k := by simp_rw [lie_module.is_nilpotent_iff_exists_ucs_eq_top, ← ucs_comap_incl, comap_incl_eq_top] end lie_submodule section morphisms open lie_module function variables {Lβ‚‚ Mβ‚‚ : Type*} [lie_ring Lβ‚‚] [lie_algebra R Lβ‚‚] variables [add_comm_group Mβ‚‚] [module R Mβ‚‚] [lie_ring_module Lβ‚‚ Mβ‚‚] [lie_module R Lβ‚‚ Mβ‚‚] variables {f : L →ₗ⁅R⁆ Lβ‚‚} {g : M β†’β‚—[R] Mβ‚‚} variables (hf : surjective f) (hg : surjective g) (hfg : βˆ€ x m, ⁅f x, g m⁆ = g ⁅x, m⁆) include hf hg hfg lemma function.surjective.lie_module_lcs_map_eq (k : β„•) : (lower_central_series R L M k : submodule R M).map g = lower_central_series R Lβ‚‚ Mβ‚‚ k := begin induction k with k ih, { simp [linear_map.range_eq_top, hg], }, { suffices : g '' {m | βˆƒ (x : L) n, n ∈ lower_central_series R L M k ∧ ⁅x, n⁆ = m} = {m | βˆƒ (x : Lβ‚‚) n, n ∈ lower_central_series R L M k ∧ ⁅x, g n⁆ = m}, { simp only [← lie_submodule.mem_coe_submodule] at this, simp [← lie_submodule.mem_coe_submodule, ← ih, lie_submodule.lie_ideal_oper_eq_linear_span', submodule.map_span, -submodule.span_image, this], }, ext mβ‚‚, split, { rintros ⟨m, ⟨x, n, hn, rfl⟩, rfl⟩, exact ⟨f x, n, hn, hfg x n⟩, }, { rintros ⟨x, n, hn, rfl⟩, obtain ⟨y, rfl⟩ := hf x, exact βŸ¨β…y, n⁆, ⟨y, n, hn, rfl⟩, (hfg y n).symm⟩, }, }, end lemma function.surjective.lie_module_is_nilpotent [is_nilpotent R L M] : is_nilpotent R Lβ‚‚ Mβ‚‚ := begin obtain ⟨k, hk⟩ := id (by apply_instance : is_nilpotent R L M), use k, rw ← lie_submodule.coe_to_submodule_eq_iff at ⊒ hk, simp [← hf.lie_module_lcs_map_eq hg hfg k, hk], end omit hf hg hfg lemma equiv.lie_module_is_nilpotent_iff (f : L ≃ₗ⁅R⁆ Lβ‚‚) (g : M ≃ₗ[R] Mβ‚‚) (hfg : βˆ€ x m, ⁅f x, g m⁆ = g ⁅x, m⁆) : is_nilpotent R L M ↔ is_nilpotent R Lβ‚‚ Mβ‚‚ := begin split; introsI h, { have hg : surjective (g : M β†’β‚—[R] Mβ‚‚) := g.surjective, exact f.surjective.lie_module_is_nilpotent hg hfg, }, { have hg : surjective (g.symm : Mβ‚‚ β†’β‚—[R] M) := g.symm.surjective, refine f.symm.surjective.lie_module_is_nilpotent hg (Ξ» x m, _), rw [linear_equiv.coe_coe, lie_equiv.coe_to_lie_hom, ← g.symm_apply_apply ⁅f.symm x, g.symm m⁆, ← hfg, f.apply_symm_apply, g.apply_symm_apply], }, end @[simp] lemma lie_module.is_nilpotent_of_top_iff : is_nilpotent R (⊀ : lie_subalgebra R L) M ↔ is_nilpotent R L M := equiv.lie_module_is_nilpotent_iff lie_subalgebra.top_equiv (1 : M ≃ₗ[R] M) (Ξ» x m, rfl) end morphisms end nilpotent_modules @[priority 100] instance lie_algebra.is_solvable_of_is_nilpotent (R : Type u) (L : Type v) [comm_ring R] [lie_ring L] [lie_algebra R L] [hL : lie_module.is_nilpotent R L L] : lie_algebra.is_solvable R L := begin obtain ⟨k, h⟩ : βˆƒ k, lie_module.lower_central_series R L L k = βŠ₯ := hL.nilpotent, use k, rw ← le_bot_iff at h ⊒, exact le_trans (lie_module.derived_series_le_lower_central_series R L k) h, end section nilpotent_algebras variables (R : Type u) (L : Type v) (L' : Type w) variables [comm_ring R] [lie_ring L] [lie_algebra R L] [lie_ring L'] [lie_algebra R L'] /-- We say a Lie algebra is nilpotent when it is nilpotent as a Lie module over itself via the adjoint representation. -/ abbreviation lie_algebra.is_nilpotent (R : Type u) (L : Type v) [comm_ring R] [lie_ring L] [lie_algebra R L] : Prop := lie_module.is_nilpotent R L L open lie_algebra lemma lie_algebra.nilpotent_ad_of_nilpotent_algebra [is_nilpotent R L] : βˆƒ (k : β„•), βˆ€ (x : L), (ad R L x)^k = 0 := lie_module.nilpotent_endo_of_nilpotent_module R L L /-- See also `lie_algebra.zero_root_space_eq_top_of_nilpotent`. -/ lemma lie_algebra.infi_max_gen_zero_eigenspace_eq_top_of_nilpotent [is_nilpotent R L] : (β¨… (x : L), (ad R L x).maximal_generalized_eigenspace 0) = ⊀ := lie_module.infi_max_gen_zero_eigenspace_eq_top_of_nilpotent R L L -- TODO Generalise the below to Lie modules if / when we define morphisms, equivs of Lie modules -- covering a Lie algebra morphism of (possibly different) Lie algebras. variables {R L L'} open lie_module (lower_central_series) /-- Given an ideal `I` of a Lie algebra `L`, the lower central series of `L β§Έ I` is the same whether we regard `L β§Έ I` as an `L` module or an `L β§Έ I` module. TODO: This result obviously generalises but the generalisation requires the missing definition of morphisms between Lie modules over different Lie algebras. -/ lemma coe_lower_central_series_ideal_quot_eq {I : lie_ideal R L} (k : β„•) : (lower_central_series R L (L β§Έ I) k : submodule R (L β§Έ I)) = lower_central_series R (L β§Έ I) (L β§Έ I) k := begin induction k with k ih, { simp only [lie_submodule.top_coe_submodule, lie_module.lower_central_series_zero], }, { simp only [lie_module.lower_central_series_succ, lie_submodule.lie_ideal_oper_eq_linear_span], congr, ext x, split, { rintros ⟨⟨y, -⟩, ⟨z, hz⟩, rfl : ⁅y, z⁆ = x⟩, erw [← lie_submodule.mem_coe_submodule, ih, lie_submodule.mem_coe_submodule] at hz, exact ⟨⟨lie_submodule.quotient.mk y, lie_submodule.mem_top _⟩, ⟨z, hz⟩, rfl⟩, }, { rintros ⟨⟨⟨y⟩, -⟩, ⟨z, hz⟩, rfl : ⁅y, z⁆ = x⟩, erw [← lie_submodule.mem_coe_submodule, ← ih, lie_submodule.mem_coe_submodule] at hz, exact ⟨⟨y, lie_submodule.mem_top _⟩, ⟨z, hz⟩, rfl⟩, }, }, end /-- Note that the below inequality can be strict. For example the ideal of strictly-upper-triangular 2x2 matrices inside the Lie algebra of upper-triangular 2x2 matrices with `k = 1`. -/ lemma lie_module.coe_lower_central_series_ideal_le {I : lie_ideal R L} (k : β„•) : (lower_central_series R I I k : submodule R I) ≀ lower_central_series R L I k := begin induction k with k ih, { simp, }, { simp only [lie_module.lower_central_series_succ, lie_submodule.lie_ideal_oper_eq_linear_span], apply submodule.span_mono, rintros x ⟨⟨y, -⟩, ⟨z, hz⟩, rfl : ⁅y, z⁆ = x⟩, exact ⟨⟨y.val, lie_submodule.mem_top _⟩, ⟨z, ih hz⟩, rfl⟩, }, end /-- A central extension of nilpotent Lie algebras is nilpotent. -/ lemma lie_algebra.nilpotent_of_nilpotent_quotient {I : lie_ideal R L} (h₁ : I ≀ center R L) (hβ‚‚ : is_nilpotent R (L β§Έ I)) : is_nilpotent R L := begin suffices : lie_module.is_nilpotent R L (L β§Έ I), { exact lie_module.nilpotent_of_nilpotent_quotient R L L h₁ this, }, unfreezingI { obtain ⟨k, hk⟩ := hβ‚‚, }, use k, simp [← lie_submodule.coe_to_submodule_eq_iff, coe_lower_central_series_ideal_quot_eq, hk], end lemma lie_algebra.non_trivial_center_of_is_nilpotent [nontrivial L] [is_nilpotent R L] : nontrivial $ center R L := lie_module.nontrivial_max_triv_of_is_nilpotent R L L lemma lie_ideal.map_lower_central_series_le (k : β„•) {f : L →ₗ⁅R⁆ L'} : lie_ideal.map f (lower_central_series R L L k) ≀ lower_central_series R L' L' k := begin induction k with k ih, { simp only [lie_module.lower_central_series_zero, le_top], }, { simp only [lie_module.lower_central_series_succ], exact le_trans (lie_ideal.map_bracket_le f) (lie_submodule.mono_lie _ _ _ _ le_top ih), }, end lemma lie_ideal.lower_central_series_map_eq (k : β„•) {f : L →ₗ⁅R⁆ L'} (h : function.surjective f) : lie_ideal.map f (lower_central_series R L L k) = lower_central_series R L' L' k := begin have h' : (⊀ : lie_ideal R L).map f = ⊀, { rw ←f.ideal_range_eq_map, exact f.ideal_range_eq_top_of_surjective h, }, induction k with k ih, { simp only [lie_module.lower_central_series_zero], exact h', }, { simp only [lie_module.lower_central_series_succ, lie_ideal.map_bracket_eq f h, ih, h'], }, end lemma function.injective.lie_algebra_is_nilpotent [h₁ : is_nilpotent R L'] {f : L →ₗ⁅R⁆ L'} (hβ‚‚ : function.injective f) : is_nilpotent R L := { nilpotent := begin obtain ⟨k, hk⟩ := id h₁, use k, apply lie_ideal.bot_of_map_eq_bot hβ‚‚, rw [eq_bot_iff, ← hk], apply lie_ideal.map_lower_central_series_le, end, } lemma function.surjective.lie_algebra_is_nilpotent [h₁ : is_nilpotent R L] {f : L →ₗ⁅R⁆ L'} (hβ‚‚ : function.surjective f) : is_nilpotent R L' := { nilpotent := begin obtain ⟨k, hk⟩ := id h₁, use k, rw [← lie_ideal.lower_central_series_map_eq k hβ‚‚, hk], simp only [lie_ideal.map_eq_bot_iff, bot_le], end, } lemma lie_equiv.nilpotent_iff_equiv_nilpotent (e : L ≃ₗ⁅R⁆ L') : is_nilpotent R L ↔ is_nilpotent R L' := begin split; introsI h, { exact e.symm.injective.lie_algebra_is_nilpotent, }, { exact e.injective.lie_algebra_is_nilpotent, }, end lemma lie_hom.is_nilpotent_range [is_nilpotent R L] (f : L →ₗ⁅R⁆ L') : is_nilpotent R f.range := f.surjective_range_restrict.lie_algebra_is_nilpotent /-- Note that this result is not quite a special case of `lie_module.is_nilpotent_range_to_endomorphism_iff` which concerns nilpotency of the `(ad R L).range`-module `L`, whereas this result concerns nilpotency of the `(ad R L).range`-module `(ad R L).range`. -/ @[simp] lemma lie_algebra.is_nilpotent_range_ad_iff : is_nilpotent R (ad R L).range ↔ is_nilpotent R L := begin refine ⟨λ h, _, _⟩, { have : (ad R L).ker = center R L, { simp, }, exact lie_algebra.nilpotent_of_nilpotent_quotient (le_of_eq this) ((ad R L).quot_ker_equiv_range.nilpotent_iff_equiv_nilpotent.mpr h), }, { introsI h, exact (ad R L).is_nilpotent_range, }, end instance [h : lie_algebra.is_nilpotent R L] : lie_algebra.is_nilpotent R (⊀ : lie_subalgebra R L) := lie_subalgebra.top_equiv.nilpotent_iff_equiv_nilpotent.mpr h end nilpotent_algebras namespace lie_ideal open lie_module variables {R L : Type*} [comm_ring R] [lie_ring L] [lie_algebra R L] (I : lie_ideal R L) variables (M : Type*) [add_comm_group M] [module R M] [lie_ring_module L M] [lie_module R L M] variables (k : β„•) /-- Given a Lie module `M` over a Lie algebra `L` together with an ideal `I` of `L`, this is the lower central series of `M` as an `I`-module. The advantage of using this definition instead of `lie_module.lower_central_series R I M` is that its terms are Lie submodules of `M` as an `L`-module, rather than just as an `I`-module. See also `lie_ideal.coe_lcs_eq`. -/ def lcs : lie_submodule R L M := (Ξ» N, ⁅I, N⁆)^[k] ⊀ @[simp] lemma lcs_zero : I.lcs M 0 = ⊀ := rfl @[simp] lemma lcs_succ : I.lcs M (k + 1) = ⁅I, I.lcs M k⁆ := function.iterate_succ_apply' (Ξ» N, ⁅I, N⁆) k ⊀ lemma lcs_top : (⊀ : lie_ideal R L).lcs M k = lower_central_series R L M k := rfl lemma coe_lcs_eq : (I.lcs M k : submodule R M) = lower_central_series R I M k := begin induction k with k ih, { simp, }, { simp_rw [lower_central_series_succ, lcs_succ, lie_submodule.lie_ideal_oper_eq_linear_span', ← (I.lcs M k).mem_coe_submodule, ih, lie_submodule.mem_coe_submodule, lie_submodule.mem_top, exists_true_left, (I : lie_subalgebra R L).coe_bracket_of_module], congr, ext m, split, { rintros ⟨x, hx, m, hm, rfl⟩, exact ⟨⟨x, hx⟩, m, hm, rfl⟩, }, { rintros ⟨⟨x, hx⟩, m, hm, rfl⟩, exact ⟨x, hx, m, hm, rfl⟩, }, }, end end lie_ideal section of_associative variables (R : Type u) {A : Type v} [comm_ring R] [ring A] [algebra R A] lemma lie_algebra.ad_nilpotent_of_nilpotent {a : A} (h : is_nilpotent a) : is_nilpotent (lie_algebra.ad R A a) := begin rw lie_algebra.ad_eq_lmul_left_sub_lmul_right, have hl : is_nilpotent (linear_map.mul_left R a), { rwa linear_map.is_nilpotent_mul_left_iff, }, have hr : is_nilpotent (linear_map.mul_right R a), { rwa linear_map.is_nilpotent_mul_right_iff, }, have := @linear_map.commute_mul_left_right R A _ _ _ _ _ a a, exact this.is_nilpotent_sub hl hr, end variables {R} lemma lie_subalgebra.is_nilpotent_ad_of_is_nilpotent_ad {L : Type v} [lie_ring L] [lie_algebra R L] (K : lie_subalgebra R L) {x : K} (h : is_nilpotent (lie_algebra.ad R L ↑x)) : is_nilpotent (lie_algebra.ad R K x) := begin obtain ⟨n, hn⟩ := h, use n, exact linear_map.submodule_pow_eq_zero_of_pow_eq_zero (K.ad_comp_incl_eq x) hn, end lemma lie_algebra.is_nilpotent_ad_of_is_nilpotent {L : lie_subalgebra R A} {x : L} (h : is_nilpotent (x : A)) : is_nilpotent (lie_algebra.ad R L x) := L.is_nilpotent_ad_of_is_nilpotent_ad $ lie_algebra.ad_nilpotent_of_nilpotent R h end of_associative
02414fbc852050c6d7fb0efe887f484972a03e11
957a80ea22c5abb4f4670b250d55534d9db99108
/library/init/coe.lean
7af1db8ac2875935d816aaa810b11dbda63bb417
[ "Apache-2.0" ]
permissive
GaloisInc/lean
aa1e64d604051e602fcf4610061314b9a37ab8cd
f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0
refs/heads/master
1,592,202,909,807
1,504,624,387,000
1,504,624,387,000
75,319,626
2
1
Apache-2.0
1,539,290,164,000
1,480,616,104,000
C++
UTF-8
Lean
false
false
6,684
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ /- The elaborator tries to insert coercions automatically. Only instances of has_coe type class are considered in the process. Lean also provides a "lifting" operator: ↑a. It uses all instances of has_lift type class. Every has_coe instance is also a has_lift instance. We recommend users only use has_coe for coercions that do not produce a lot of ambiguity. All coercions and lifts can be identified with the constant coe. We use the has_coe_to_fun type class for encoding coercions from a type to a function space. We use the has_coe_to_sort type class for encoding coercions from a type to a sort. -/ prelude import init.data.list.basic init.data.subtype.basic init.data.prod universes u v class has_lift (a : Sort u) (b : Sort v) := (lift : a β†’ b) /-- Auxiliary class that contains the transitive closure of has_lift. -/ class has_lift_t (a : Sort u) (b : Sort v) := (lift : a β†’ b) class has_coe (a : Sort u) (b : Sort v) := (coe : a β†’ b) /-- Auxiliary class that contains the transitive closure of has_coe. -/ class has_coe_t (a : Sort u) (b : Sort v) := (coe : a β†’ b) class has_coe_to_fun (a : Sort u) : Sort (max u (v+1)) := (F : a β†’ Sort v) (coe : Ξ  x, F x) class has_coe_to_sort (a : Sort u) : Type (max u (v+1)) := (S : Sort v) (coe : a β†’ S) def lift {a : Sort u} {b : Sort v} [has_lift a b] : a β†’ b := @has_lift.lift a b _ def lift_t {a : Sort u} {b : Sort v} [has_lift_t a b] : a β†’ b := @has_lift_t.lift a b _ def coe_b {a : Sort u} {b : Sort v} [has_coe a b] : a β†’ b := @has_coe.coe a b _ def coe_t {a : Sort u} {b : Sort v} [has_coe_t a b] : a β†’ b := @has_coe_t.coe a b _ def coe_fn_b {a : Sort u} [has_coe_to_fun.{u v} a] : Ξ  x : a, has_coe_to_fun.F.{u v} x := has_coe_to_fun.coe /- User level coercion operators -/ @[reducible] def coe {a : Sort u} {b : Sort v} [has_lift_t a b] : a β†’ b := lift_t @[reducible] def coe_fn {a : Sort u} [has_coe_to_fun.{u v} a] : Ξ  x : a, has_coe_to_fun.F.{u v} x := has_coe_to_fun.coe @[reducible] def coe_sort {a : Sort u} [has_coe_to_sort.{u v} a] : a β†’ has_coe_to_sort.S.{u v} a := has_coe_to_sort.coe /- Notation -/ notation `↑`:max x:max := coe x notation `⇑`:max x:max := coe_fn x notation `β†₯`:max x:max := coe_sort x universes u₁ uβ‚‚ u₃ /- Transitive closure for has_lift, has_coe, has_coe_to_fun -/ instance lift_trans {a : Sort u₁} {b : Sort uβ‚‚} {c : Sort u₃} [has_lift a b] [has_lift_t b c] : has_lift_t a c := ⟨λ x, lift_t (lift x : b)⟩ instance lift_base {a : Sort u} {b : Sort v} [has_lift a b] : has_lift_t a b := ⟨lift⟩ instance coe_trans {a : Sort u₁} {b : Sort uβ‚‚} {c : Sort u₃} [has_coe a b] [has_coe_t b c] : has_coe_t a c := ⟨λ x, coe_t (coe_b x : b)⟩ instance coe_base {a : Sort u} {b : Sort v} [has_coe a b] : has_coe_t a b := ⟨coe_b⟩ /- We add this instance directly into has_coe_t to avoid non-termination. Suppose coe_option had type (has_coe a (option a)). Then, we can loop when searching a coercion from Ξ± to Ξ² (has_coe_t Ξ± Ξ²) 1- coe_trans at (has_coe_t Ξ± Ξ²) (has_coe Ξ± ?b₁) and (has_coe_t ?b₁ c) 2- coe_option at (has_coe Ξ± ?b₁) ?b₁ := option Ξ± 3- coe_trans at (has_coe_t (option Ξ±) Ξ²) (has_coe (option Ξ±) ?bβ‚‚) and (has_coe_t ?bβ‚‚ Ξ²) 4- coe_option at (has_coe (option Ξ±) ?bβ‚‚) ?bβ‚‚ := option (option Ξ±)) ... -/ instance coe_option {a : Type u} : has_coe_t a (option a) := ⟨λ x, some x⟩ /- Auxiliary transitive closure for has_coe which does not contain instances such as coe_option. They would produce non-termination when combined with coe_fn_trans and coe_sort_trans. -/ class has_coe_t_aux (a : Sort u) (b : Sort v) := (coe : a β†’ b) instance coe_trans_aux {a : Sort u₁} {b : Sort uβ‚‚} {c : Sort u₃} [has_coe a b] [has_coe_t_aux b c] : has_coe_t_aux a c := ⟨λ x : a, @has_coe_t_aux.coe b c _ (coe_b x)⟩ instance coe_base_aux {a : Sort u} {b : Sort v} [has_coe a b] : has_coe_t_aux a b := ⟨coe_b⟩ instance coe_fn_trans {a : Sort u₁} {b : Sort uβ‚‚} [has_coe_t_aux a b] [has_coe_to_fun.{uβ‚‚ u₃} b] : has_coe_to_fun.{u₁ u₃} a := { F := Ξ» x, @has_coe_to_fun.F.{uβ‚‚ u₃} b _ (@has_coe_t_aux.coe a b _ x), coe := Ξ» x, coe_fn (@has_coe_t_aux.coe a b _ x) } instance coe_sort_trans {a : Sort u₁} {b : Sort uβ‚‚} [has_coe_t_aux a b] [has_coe_to_sort.{uβ‚‚ u₃} b] : has_coe_to_sort.{u₁ u₃} a := { S := has_coe_to_sort.S.{uβ‚‚ u₃} b, coe := Ξ» x, coe_sort (@has_coe_t_aux.coe a b _ x) } /- Every coercion is also a lift -/ instance coe_to_lift {a : Sort u} {b : Sort v} [has_coe_t a b] : has_lift_t a b := ⟨coe_t⟩ /- basic coercions -/ instance coe_bool_to_Prop : has_coe bool Prop := ⟨λ y, y = tt⟩ instance coe_sort_bool : has_coe_to_sort bool := ⟨Prop, Ξ» y, y = tt⟩ instance coe_decidable_eq (x : bool) : decidable (coe x) := show decidable (x = tt), from bool.decidable_eq x tt instance coe_subtype {a : Type u} {p : a β†’ Prop} : has_coe {x // p x} a := ⟨subtype.val⟩ /- basic lifts -/ universes ua ua₁ uaβ‚‚ ub ub₁ ubβ‚‚ /- Remark: we can't use [has_lift_t aβ‚‚ a₁] since it will produce non-termination whenever a type class resolution problem does not have a solution. -/ instance lift_fn {a₁ : Sort ua₁} {aβ‚‚ : Sort uaβ‚‚} {b₁ : Sort ub₁} {bβ‚‚ : Sort ubβ‚‚} [has_lift aβ‚‚ a₁] [has_lift_t b₁ bβ‚‚] : has_lift (a₁ β†’ b₁) (aβ‚‚ β†’ bβ‚‚) := ⟨λ f x, ↑(f ↑x)⟩ instance lift_fn_range {a : Sort ua} {b₁ : Sort ub₁} {bβ‚‚ : Sort ubβ‚‚} [has_lift_t b₁ bβ‚‚] : has_lift (a β†’ b₁) (a β†’ bβ‚‚) := ⟨λ f x, ↑(f x)⟩ instance lift_fn_dom {a₁ : Sort ua₁} {aβ‚‚ : Sort uaβ‚‚} {b : Sort ub} [has_lift aβ‚‚ a₁] : has_lift (a₁ β†’ b) (aβ‚‚ β†’ b) := ⟨λ f x, f ↑x⟩ instance lift_pair {a₁ : Type ua₁} {aβ‚‚ : Type ubβ‚‚} {b₁ : Type ub₁} {bβ‚‚ : Type ubβ‚‚} [has_lift_t a₁ aβ‚‚] [has_lift_t b₁ bβ‚‚] : has_lift (a₁ Γ— b₁) (aβ‚‚ Γ— bβ‚‚) := ⟨λ p, prod.cases_on p (Ξ» x y, (↑x, ↑y))⟩ instance lift_pair₁ {a₁ : Type ua₁} {aβ‚‚ : Type uaβ‚‚} {b : Type ub} [has_lift_t a₁ aβ‚‚] : has_lift (a₁ Γ— b) (aβ‚‚ Γ— b) := ⟨λ p, prod.cases_on p (Ξ» x y, (↑x, y))⟩ instance lift_pairβ‚‚ {a : Type ua} {b₁ : Type ub₁} {bβ‚‚ : Type ubβ‚‚} [has_lift_t b₁ bβ‚‚] : has_lift (a Γ— b₁) (a Γ— bβ‚‚) := ⟨λ p, prod.cases_on p (Ξ» x y, (x, ↑y))⟩ instance lift_list {a : Type u} {b : Type v} [has_lift_t a b] : has_lift (list a) (list b) := ⟨λ l, list.map (@coe a b _) l⟩
88d39e88b1d2f036b832af768f028e1563bb5760
d1a52c3f208fa42c41df8278c3d280f075eb020c
/tests/lean/rewrite.lean
d49f2b4bec34910bd2925d9398a8687176bd3a6e
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
cipher1024/lean4
6e1f98bb58e7a92b28f5364eb38a14c8d0aae393
69114d3b50806264ef35b57394391c3e738a9822
refs/heads/master
1,642,227,983,603
1,642,011,696,000
1,642,011,696,000
228,607,691
0
0
Apache-2.0
1,576,584,269,000
1,576,584,268,000
null
UTF-8
Lean
false
false
1,548
lean
axiom appendNil {Ξ±} (as : List Ξ±) : as ++ [] = as axiom appendAssoc {Ξ±} (as bs cs : List Ξ±) : (as ++ bs) ++ cs = as ++ (bs ++ cs) axiom reverseEq {Ξ±} (as : List Ξ±) : as.reverse.reverse = as theorem ex1 {Ξ±} (as bs : List Ξ±) : as.reverse.reverse ++ [] ++ [] ++ bs ++ bs = as ++ (bs ++ bs) := by rw [appendNil, appendNil, reverseEq]; trace_state; rw [←appendAssoc]; theorem ex2 {Ξ±} (as bs : List Ξ±) : as.reverse.reverse ++ [] ++ [] ++ bs ++ bs = as ++ (bs ++ bs) := by rewrite [reverseEq, reverseEq]; -- Error on second reverseEq done axiom zeroAdd (x : Nat) : 0 + x = x theorem ex2 (x y z) (h₁ : 0 + x = y) (hβ‚‚ : 0 + y = z) : x = z := by rewrite [zeroAdd] at h₁ hβ‚‚; trace_state; subst x; subst y; exact rfl theorem ex3 (x y z) (h₁ : 0 + x = y) (hβ‚‚ : 0 + y = z) : x = z := by rewrite [zeroAdd] at *; subst x; subst y; exact rfl theorem ex4 (x y z) (h₁ : 0 + x = y) (hβ‚‚ : 0 + y = z) : x = z := by rewrite [appendAssoc] at *; -- Error done theorem ex5 (m n k : Nat) (h : 0 + n = m) (h : k = m) : k = n := by rw [zeroAdd] at *; trace_state; -- `h` is still a name for `h : k = m` refine Eq.trans h ?hole; apply Eq.symm; assumption theorem ex6 (p q r : Prop) (h₁ : q β†’ r) (hβ‚‚ : p ↔ q) (h₃ : p) : r := by rw [←hβ‚‚] at h₁; exact h₁ h₃ theorem ex7 (p q r : Prop) (h₁ : q β†’ r) (hβ‚‚ : p ↔ q) (h₃ : p) : r := by rw [hβ‚‚] at h₃; exact h₁ h₃ example (Ξ± : Type) (p : Prop) (a b c : Ξ±) (h : p β†’ a = b) : a = c := by rw [h _] -- should manifest goal `⊒ p`, like `rw [h]` would
9dc8c18fd82aa9c3ed9c91058ab573d7a404ceec
ac89c256db07448984849346288e0eeffe8b20d0
/stage0/src/Lean/Expr.lean
53062012ac04aeb2594acc8548d4d84e539fbc81
[ "Apache-2.0" ]
permissive
chepinzhang/lean4
002cc667f35417a418f0ebc9cb4a44559bb0ccac
24fe2875c68549b5481f07c57eab4ad4a0ae5305
refs/heads/master
1,688,942,838,326
1,628,801,942,000
1,628,801,995,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
37,418
lean
/- Copyright (c) 2018 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Data.KVMap import Lean.Level namespace Lean inductive Literal where | natVal (val : Nat) | strVal (val : String) deriving Inhabited, BEq, Repr protected def Literal.hash : Literal β†’ UInt64 | Literal.natVal v => hash v | Literal.strVal v => hash v instance : Hashable Literal := ⟨Literal.hash⟩ def Literal.lt : Literal β†’ Literal β†’ Bool | Literal.natVal _, Literal.strVal _ => true | Literal.natVal v₁, Literal.natVal vβ‚‚ => v₁ < vβ‚‚ | Literal.strVal v₁, Literal.strVal vβ‚‚ => v₁ < vβ‚‚ | _, _ => false instance : LT Literal := ⟨fun a b => a.lt b⟩ instance (a b : Literal) : Decidable (a < b) := inferInstanceAs (Decidable (a.lt b)) inductive BinderInfo where | default | implicit | strictImplicit | instImplicit | auxDecl deriving Inhabited, BEq, Repr def BinderInfo.hash : BinderInfo β†’ UInt64 | BinderInfo.default => 947 | BinderInfo.implicit => 1019 | BinderInfo.strictImplicit => 1087 | BinderInfo.instImplicit => 1153 | BinderInfo.auxDecl => 1229 def BinderInfo.isExplicit : BinderInfo β†’ Bool | BinderInfo.implicit => false | BinderInfo.strictImplicit => false | BinderInfo.instImplicit => false | _ => true instance : Hashable BinderInfo := ⟨BinderInfo.hash⟩ def BinderInfo.isInstImplicit : BinderInfo β†’ Bool | BinderInfo.instImplicit => true | _ => false def BinderInfo.isImplicit : BinderInfo β†’ Bool | BinderInfo.implicit => true | _ => false def BinderInfo.isStrictImplicit : BinderInfo β†’ Bool | BinderInfo.strictImplicit => true | _ => false def BinderInfo.isAuxDecl : BinderInfo β†’ Bool | BinderInfo.auxDecl => true | _ => false abbrev MData := KVMap abbrev MData.empty : MData := {} /-- Cached hash code, cached results, and other data for `Expr`. hash : 32-bits hasFVar : 1-bit hasExprMVar : 1-bit hasLevelMVar : 1-bit hasLevelParam : 1-bit nonDepLet : 1-bit binderInfo : 3-bits looseBVarRange : 24-bits -/ def Expr.Data := UInt64 instance: Inhabited Expr.Data := inferInstanceAs (Inhabited UInt64) def Expr.Data.hash (c : Expr.Data) : UInt64 := c.toUInt32.toUInt64 instance : BEq Expr.Data where beq (a b : UInt64) := a == b def Expr.Data.looseBVarRange (c : Expr.Data) : UInt32 := (c.shiftRight 40).toUInt32 def Expr.Data.hasFVar (c : Expr.Data) : Bool := ((c.shiftRight 32).land 1) == 1 def Expr.Data.hasExprMVar (c : Expr.Data) : Bool := ((c.shiftRight 33).land 1) == 1 def Expr.Data.hasLevelMVar (c : Expr.Data) : Bool := ((c.shiftRight 34).land 1) == 1 def Expr.Data.hasLevelParam (c : Expr.Data) : Bool := ((c.shiftRight 35).land 1) == 1 def Expr.Data.nonDepLet (c : Expr.Data) : Bool := ((c.shiftRight 36).land 1) == 1 @[extern c inline "(uint8_t)((#1 << 24) >> 61)"] def Expr.Data.binderInfo (c : Expr.Data) : BinderInfo := let bi := (c.shiftLeft 24).shiftRight 61 if bi == 0 then BinderInfo.default else if bi == 1 then BinderInfo.implicit else if bi == 2 then BinderInfo.strictImplicit else if bi == 3 then BinderInfo.instImplicit else BinderInfo.auxDecl @[extern c inline "(uint64_t)#1"] def BinderInfo.toUInt64 : BinderInfo β†’ UInt64 | BinderInfo.default => 0 | BinderInfo.implicit => 1 | BinderInfo.strictImplicit => 2 | BinderInfo.instImplicit => 3 | BinderInfo.auxDecl => 4 @[inline] private def Expr.mkDataCore (h : UInt64) (looseBVarRange : Nat) (hasFVar hasExprMVar hasLevelMVar hasLevelParam nonDepLet : Bool) (bi : BinderInfo) : Expr.Data := if looseBVarRange > Nat.pow 2 24 - 1 then panic! "bound variable index is too big" else let r : UInt64 := h.toUInt32.toUInt64 + hasFVar.toUInt64.shiftLeft 32 + hasExprMVar.toUInt64.shiftLeft 33 + hasLevelMVar.toUInt64.shiftLeft 34 + hasLevelParam.toUInt64.shiftLeft 35 + nonDepLet.toUInt64.shiftLeft 36 + bi.toUInt64.shiftLeft 37 + looseBVarRange.toUInt64.shiftLeft 40 r def Expr.mkData (h : UInt64) (looseBVarRange : Nat := 0) (hasFVar hasExprMVar hasLevelMVar hasLevelParam : Bool := false) : Expr.Data := Expr.mkDataCore h looseBVarRange hasFVar hasExprMVar hasLevelMVar hasLevelParam false BinderInfo.default def Expr.mkDataForBinder (h : UInt64) (looseBVarRange : Nat) (hasFVar hasExprMVar hasLevelMVar hasLevelParam : Bool) (bi : BinderInfo) : Expr.Data := Expr.mkDataCore h looseBVarRange hasFVar hasExprMVar hasLevelMVar hasLevelParam false bi def Expr.mkDataForLet (h : UInt64) (looseBVarRange : Nat) (hasFVar hasExprMVar hasLevelMVar hasLevelParam nonDepLet : Bool) : Expr.Data := Expr.mkDataCore h looseBVarRange hasFVar hasExprMVar hasLevelMVar hasLevelParam nonDepLet BinderInfo.default open Expr abbrev MVarId := Name abbrev FVarId := Name /- We use the `E` suffix (short for `Expr`) to avoid collision with keywords. We considered using Β«...Β», but it is too inconvenient to use. -/ inductive Expr where | bvar : Nat β†’ Data β†’ Expr -- bound variables | fvar : FVarId β†’ Data β†’ Expr -- free variables | mvar : MVarId β†’ Data β†’ Expr -- meta variables | sort : Level β†’ Data β†’ Expr -- Sort | const : Name β†’ List Level β†’ Data β†’ Expr -- constants | app : Expr β†’ Expr β†’ Data β†’ Expr -- application | lam : Name β†’ Expr β†’ Expr β†’ Data β†’ Expr -- lambda abstraction | forallE : Name β†’ Expr β†’ Expr β†’ Data β†’ Expr -- (dependent) arrow | letE : Name β†’ Expr β†’ Expr β†’ Expr β†’ Data β†’ Expr -- let expressions | lit : Literal β†’ Data β†’ Expr -- literals | mdata : MData β†’ Expr β†’ Data β†’ Expr -- metadata | proj : Name β†’ Nat β†’ Expr β†’ Data β†’ Expr -- projection deriving Inhabited namespace Expr @[inline] def data : Expr β†’ Data | bvar _ d => d | fvar _ d => d | mvar _ d => d | sort _ d => d | const _ _ d => d | app _ _ d => d | lam _ _ _ d => d | forallE _ _ _ d => d | letE _ _ _ _ d => d | lit _ d => d | mdata _ _ d => d | proj _ _ _ d => d def ctorName : Expr β†’ String | bvar _ _ => "bvar" | fvar _ _ => "fvar" | mvar _ _ => "mvar" | sort _ _ => "sort" | const _ _ _ => "const" | app _ _ _ => "app" | lam _ _ _ _ => "lam" | forallE _ _ _ _ => "forallE" | letE _ _ _ _ _ => "letE" | lit _ _ => "lit" | mdata _ _ _ => "mdata" | proj _ _ _ _ => "proj" protected def hash (e : Expr) : UInt64 := e.data.hash instance : Hashable Expr := ⟨Expr.hash⟩ def hasFVar (e : Expr) : Bool := e.data.hasFVar def hasExprMVar (e : Expr) : Bool := e.data.hasExprMVar def hasLevelMVar (e : Expr) : Bool := e.data.hasLevelMVar def hasMVar (e : Expr) : Bool := let d := e.data d.hasExprMVar || d.hasLevelMVar def hasLevelParam (e : Expr) : Bool := e.data.hasLevelParam def looseBVarRange (e : Expr) : Nat := e.data.looseBVarRange.toNat def binderInfo (e : Expr) : BinderInfo := e.data.binderInfo @[export lean_expr_hash] def hashEx : Expr β†’ UInt64 := hash @[export lean_expr_has_fvar] def hasFVarEx : Expr β†’ Bool := hasFVar @[export lean_expr_has_expr_mvar] def hasExprMVarEx : Expr β†’ Bool := hasExprMVar @[export lean_expr_has_level_mvar] def hasLevelMVarEx : Expr β†’ Bool := hasLevelMVar @[export lean_expr_has_mvar] def hasMVarEx : Expr β†’ Bool := hasMVar @[export lean_expr_has_level_param] def hasLevelParamEx : Expr β†’ Bool := hasLevelParam @[export lean_expr_loose_bvar_range] def looseBVarRangeEx (e : Expr) : UInt32 := e.data.looseBVarRange @[export lean_expr_binder_info] def binderInfoEx : Expr β†’ BinderInfo := binderInfo end Expr def mkConst (n : Name) (lvls : List Level := []) : Expr := Expr.const n lvls $ mkData (mixHash 5 $ mixHash (hash n) (hash lvls)) 0 false false (lvls.any Level.hasMVar) (lvls.any Level.hasParam) def Literal.type : Literal β†’ Expr | Literal.natVal _ => mkConst `Nat | Literal.strVal _ => mkConst `String @[export lean_lit_type] def Literal.typeEx : Literal β†’ Expr := Literal.type def mkBVar (idx : Nat) : Expr := Expr.bvar idx $ mkData (mixHash 7 $ hash idx) (idx+1) def mkSort (lvl : Level) : Expr := Expr.sort lvl $ mkData (mixHash 11 $ hash lvl) 0 false false lvl.hasMVar lvl.hasParam def mkFVar (fvarId : FVarId) : Expr := Expr.fvar fvarId $ mkData (mixHash 13 $ hash fvarId) 0 true def mkMVar (fvarId : MVarId) : Expr := Expr.mvar fvarId $ mkData (mixHash 17 $ hash fvarId) 0 false true def mkMData (d : MData) (e : Expr) : Expr := Expr.mdata d e $ mkData (mixHash 19 $ hash e) e.looseBVarRange e.hasFVar e.hasExprMVar e.hasLevelMVar e.hasLevelParam def mkProj (s : Name) (i : Nat) (e : Expr) : Expr := Expr.proj s i e $ mkData (mixHash 23 $ mixHash (hash s) $ mixHash (hash i) (hash e)) e.looseBVarRange e.hasFVar e.hasExprMVar e.hasLevelMVar e.hasLevelParam def mkApp (f a : Expr) : Expr := Expr.app f a $ mkData (mixHash 29 $ mixHash (hash f) (hash a)) (Nat.max f.looseBVarRange a.looseBVarRange) (f.hasFVar || a.hasFVar) (f.hasExprMVar || a.hasExprMVar) (f.hasLevelMVar || a.hasLevelMVar) (f.hasLevelParam || a.hasLevelParam) def mkLambda (x : Name) (bi : BinderInfo) (t : Expr) (b : Expr) : Expr := -- let x := x.eraseMacroScopes Expr.lam x t b $ mkDataForBinder (mixHash 31 $ mixHash (hash t) (hash b)) (Nat.max t.looseBVarRange (b.looseBVarRange - 1)) (t.hasFVar || b.hasFVar) (t.hasExprMVar || b.hasExprMVar) (t.hasLevelMVar || b.hasLevelMVar) (t.hasLevelParam || b.hasLevelParam) bi def mkForall (x : Name) (bi : BinderInfo) (t : Expr) (b : Expr) : Expr := -- let x := x.eraseMacroScopes Expr.forallE x t b $ mkDataForBinder (mixHash 37 $ mixHash (hash t) (hash b)) (Nat.max t.looseBVarRange (b.looseBVarRange - 1)) (t.hasFVar || b.hasFVar) (t.hasExprMVar || b.hasExprMVar) (t.hasLevelMVar || b.hasLevelMVar) (t.hasLevelParam || b.hasLevelParam) bi /- Return `Unit -> type`. Do not confuse with `Thunk type` -/ def mkSimpleThunkType (type : Expr) : Expr := mkForall Name.anonymous BinderInfo.default (Lean.mkConst `Unit) type /- Return `fun (_ : Unit), e` -/ def mkSimpleThunk (type : Expr) : Expr := mkLambda `_ BinderInfo.default (Lean.mkConst `Unit) type def mkLet (x : Name) (t : Expr) (v : Expr) (b : Expr) (nonDep : Bool := false) : Expr := -- let x := x.eraseMacroScopes Expr.letE x t v b $ mkDataForLet (mixHash 41 $ mixHash (hash t) $ mixHash (hash v) (hash b)) (Nat.max (Nat.max t.looseBVarRange v.looseBVarRange) (b.looseBVarRange - 1)) (t.hasFVar || v.hasFVar || b.hasFVar) (t.hasExprMVar || v.hasExprMVar || b.hasExprMVar) (t.hasLevelMVar || v.hasLevelMVar || b.hasLevelMVar) (t.hasLevelParam || v.hasLevelParam || b.hasLevelParam) nonDep def mkAppB (f a b : Expr) := mkApp (mkApp f a) b def mkApp2 (f a b : Expr) := mkAppB f a b def mkApp3 (f a b c : Expr) := mkApp (mkAppB f a b) c def mkApp4 (f a b c d : Expr) := mkAppB (mkAppB f a b) c d def mkApp5 (f a b c d e : Expr) := mkApp (mkApp4 f a b c d) e def mkApp6 (f a b c d e₁ eβ‚‚ : Expr) := mkAppB (mkApp4 f a b c d) e₁ eβ‚‚ def mkApp7 (f a b c d e₁ eβ‚‚ e₃ : Expr) := mkApp3 (mkApp4 f a b c d) e₁ eβ‚‚ e₃ def mkApp8 (f a b c d e₁ eβ‚‚ e₃ eβ‚„ : Expr) := mkApp4 (mkApp4 f a b c d) e₁ eβ‚‚ e₃ eβ‚„ def mkApp9 (f a b c d e₁ eβ‚‚ e₃ eβ‚„ eβ‚… : Expr) := mkApp5 (mkApp4 f a b c d) e₁ eβ‚‚ e₃ eβ‚„ eβ‚… def mkApp10 (f a b c d e₁ eβ‚‚ e₃ eβ‚„ eβ‚… e₆ : Expr) := mkApp6 (mkApp4 f a b c d) e₁ eβ‚‚ e₃ eβ‚„ eβ‚… e₆ def mkLit (l : Literal) : Expr := Expr.lit l $ mkData (mixHash 3 (hash l)) def mkRawNatLit (n : Nat) : Expr := mkLit (Literal.natVal n) def mkNatLit (n : Nat) : Expr := let r := mkRawNatLit n mkApp3 (mkConst ``OfNat.ofNat [levelZero]) (mkConst ``Nat) r (mkApp (mkConst ``instOfNatNat) r) def mkStrLit (s : String) : Expr := mkLit (Literal.strVal s) @[export lean_expr_mk_bvar] def mkBVarEx : Nat β†’ Expr := mkBVar @[export lean_expr_mk_fvar] def mkFVarEx : FVarId β†’ Expr := mkFVar @[export lean_expr_mk_mvar] def mkMVarEx : MVarId β†’ Expr := mkMVar @[export lean_expr_mk_sort] def mkSortEx : Level β†’ Expr := mkSort @[export lean_expr_mk_const] def mkConstEx (c : Name) (lvls : List Level) : Expr := mkConst c lvls @[export lean_expr_mk_app] def mkAppEx : Expr β†’ Expr β†’ Expr := mkApp @[export lean_expr_mk_lambda] def mkLambdaEx (n : Name) (d b : Expr) (bi : BinderInfo) : Expr := mkLambda n bi d b @[export lean_expr_mk_forall] def mkForallEx (n : Name) (d b : Expr) (bi : BinderInfo) : Expr := mkForall n bi d b @[export lean_expr_mk_let] def mkLetEx (n : Name) (t v b : Expr) : Expr := mkLet n t v b @[export lean_expr_mk_lit] def mkLitEx : Literal β†’ Expr := mkLit @[export lean_expr_mk_mdata] def mkMDataEx : MData β†’ Expr β†’ Expr := mkMData @[export lean_expr_mk_proj] def mkProjEx : Name β†’ Nat β†’ Expr β†’ Expr := mkProj def mkAppN (f : Expr) (args : Array Expr) : Expr := args.foldl mkApp f private partial def mkAppRangeAux (n : Nat) (args : Array Expr) (i : Nat) (e : Expr) : Expr := if i < n then mkAppRangeAux n args (i+1) (mkApp e (args.get! i)) else e /-- `mkAppRange f i j #[a_1, ..., a_i, ..., a_j, ... ]` ==> the expression `f a_i ... a_{j-1}` -/ def mkAppRange (f : Expr) (i j : Nat) (args : Array Expr) : Expr := mkAppRangeAux j args i f def mkAppRev (fn : Expr) (revArgs : Array Expr) : Expr := revArgs.foldr (fun a r => mkApp r a) fn namespace Expr -- TODO: implement it in Lean @[extern "lean_expr_dbg_to_string"] constant dbgToString (e : @& Expr) : String @[extern "lean_expr_quick_lt"] constant quickLt (a : @& Expr) (b : @& Expr) : Bool @[extern "lean_expr_lt"] constant lt (a : @& Expr) (b : @& Expr) : Bool /- Return true iff `a` and `b` are alpha equivalent. Binder annotations are ignored. -/ @[extern "lean_expr_eqv"] constant eqv (a : @& Expr) (b : @& Expr) : Bool instance : BEq Expr where beq := Expr.eqv /- Return true iff `a` and `b` are equal. Binder names and annotations are taking into account. -/ @[extern "lean_expr_equal"] constant equal (a : @& Expr) (b : @& Expr) : Bool def isSort : Expr β†’ Bool | sort _ _ => true | _ => false def isProp : Expr β†’ Bool | sort (Level.zero ..) _ => true | _ => false def isBVar : Expr β†’ Bool | bvar _ _ => true | _ => false def isMVar : Expr β†’ Bool | mvar _ _ => true | _ => false def isFVar : Expr β†’ Bool | fvar _ _ => true | _ => false def isApp : Expr β†’ Bool | app .. => true | _ => false def isProj : Expr β†’ Bool | proj .. => true | _ => false def isConst : Expr β†’ Bool | const .. => true | _ => false def isConstOf : Expr β†’ Name β†’ Bool | const n _ _, m => n == m | _, _ => false def isForall : Expr β†’ Bool | forallE .. => true | _ => false def isLambda : Expr β†’ Bool | lam .. => true | _ => false def isBinding : Expr β†’ Bool | lam .. => true | forallE .. => true | _ => false def isLet : Expr β†’ Bool | letE .. => true | _ => false def isMData : Expr β†’ Bool | mdata .. => true | _ => false def isLit : Expr β†’ Bool | lit .. => true | _ => false def getForallBody : Expr β†’ Expr | forallE _ _ b .. => getForallBody b | e => e def getAppFn : Expr β†’ Expr | app f a _ => getAppFn f | e => e def getAppNumArgsAux : Expr β†’ Nat β†’ Nat | app f a _, n => getAppNumArgsAux f (n+1) | e, n => n def getAppNumArgs (e : Expr) : Nat := getAppNumArgsAux e 0 private def getAppArgsAux : Expr β†’ Array Expr β†’ Nat β†’ Array Expr | app f a _, as, i => getAppArgsAux f (as.set! i a) (i-1) | _, as, _ => as @[inline] def getAppArgs (e : Expr) : Array Expr := let dummy := mkSort levelZero let nargs := e.getAppNumArgs getAppArgsAux e (mkArray nargs dummy) (nargs-1) private def getAppRevArgsAux : Expr β†’ Array Expr β†’ Array Expr | app f a _, as => getAppRevArgsAux f (as.push a) | _, as => as @[inline] def getAppRevArgs (e : Expr) : Array Expr := getAppRevArgsAux e (Array.mkEmpty e.getAppNumArgs) @[specialize] def withAppAux (k : Expr β†’ Array Expr β†’ Ξ±) : Expr β†’ Array Expr β†’ Nat β†’ Ξ± | app f a _, as, i => withAppAux k f (as.set! i a) (i-1) | f, as, i => k f as @[inline] def withApp (e : Expr) (k : Expr β†’ Array Expr β†’ Ξ±) : Ξ± := let dummy := mkSort levelZero let nargs := e.getAppNumArgs withAppAux k e (mkArray nargs dummy) (nargs-1) @[specialize] private def withAppRevAux (k : Expr β†’ Array Expr β†’ Ξ±) : Expr β†’ Array Expr β†’ Ξ± | app f a _, as => withAppRevAux k f (as.push a) | f, as => k f as @[inline] def withAppRev (e : Expr) (k : Expr β†’ Array Expr β†’ Ξ±) : Ξ± := withAppRevAux k e (Array.mkEmpty e.getAppNumArgs) def getRevArgD : Expr β†’ Nat β†’ Expr β†’ Expr | app f a _, 0, _ => a | app f _ _, i+1, v => getRevArgD f i v | _, _, v => v def getRevArg! : Expr β†’ Nat β†’ Expr | app f a _, 0 => a | app f _ _, i+1 => getRevArg! f i | _, _ => panic! "invalid index" @[inline] def getArg! (e : Expr) (i : Nat) (n := e.getAppNumArgs) : Expr := getRevArg! e (n - i - 1) @[inline] def getArgD (e : Expr) (i : Nat) (vβ‚€ : Expr) (n := e.getAppNumArgs) : Expr := getRevArgD e (n - i - 1) vβ‚€ def isAppOf (e : Expr) (n : Name) : Bool := match e.getAppFn with | const c _ _ => c == n | _ => false def isAppOfArity : Expr β†’ Name β†’ Nat β†’ Bool | const c _ _, n, 0 => c == n | app f _ _, n, a+1 => isAppOfArity f n a | _, _, _ => false def appFn! : Expr β†’ Expr | app f _ _ => f | _ => panic! "application expected" def appArg! : Expr β†’ Expr | app _ a _ => a | _ => panic! "application expected" def isNatLit : Expr β†’ Bool | lit (Literal.natVal _) _ => true | _ => false def natLit? : Expr β†’ Option Nat | lit (Literal.natVal v) _ => v | _ => none def isStringLit : Expr β†’ Bool | lit (Literal.strVal _) _ => true | _ => false def isCharLit (e : Expr) : Bool := e.isAppOfArity `Char.ofNat 1 && e.appArg!.isNatLit def constName! : Expr β†’ Name | const n _ _ => n | _ => panic! "constant expected" def constName? : Expr β†’ Option Name | const n _ _ => some n | _ => none def constLevels! : Expr β†’ List Level | const _ ls _ => ls | _ => panic! "constant expected" def bvarIdx! : Expr β†’ Nat | bvar idx _ => idx | _ => panic! "bvar expected" def fvarId! : Expr β†’ FVarId | fvar n _ => n | _ => panic! "fvar expected" def mvarId! : Expr β†’ MVarId | mvar n _ => n | _ => panic! "mvar expected" def bindingName! : Expr β†’ Name | forallE n _ _ _ => n | lam n _ _ _ => n | _ => panic! "binding expected" def bindingDomain! : Expr β†’ Expr | forallE _ d _ _ => d | lam _ d _ _ => d | _ => panic! "binding expected" def bindingBody! : Expr β†’ Expr | forallE _ _ b _ => b | lam _ _ b _ => b | _ => panic! "binding expected" def bindingInfo! : Expr β†’ BinderInfo | forallE _ _ _ c => c.binderInfo | lam _ _ _ c => c.binderInfo | _ => panic! "binding expected" def letName! : Expr β†’ Name | letE n _ _ _ _ => n | _ => panic! "let expression expected" def consumeMData : Expr β†’ Expr | mdata _ e _ => consumeMData e | e => e def hasLooseBVars (e : Expr) : Bool := e.looseBVarRange > 0 /- Remark: the following function assumes `e` does not have loose bound variables. -/ def isArrow (e : Expr) : Bool := match e with | forallE _ _ b _ => !b.hasLooseBVars | _ => false @[extern "lean_expr_has_loose_bvar"] constant hasLooseBVar (e : @& Expr) (bvarIdx : @& Nat) : Bool /-- Return true if `e` contains the loose bound variable `bvarIdx` in an explicit parameter, or in the range if `tryRange == true`. -/ def hasLooseBVarInExplicitDomain : Expr β†’ Nat β†’ Bool β†’ Bool | Expr.forallE _ d b c, bvarIdx, tryRange => (c.binderInfo.isExplicit && hasLooseBVar d bvarIdx) || hasLooseBVarInExplicitDomain b (bvarIdx+1) tryRange | e, bvarIdx, tryRange => tryRange && hasLooseBVar e bvarIdx /-- Lower the loose bound variables `>= s` in `e` by `d`. That is, a loose bound variable `bvar i`. `i >= s` is mapped into `bvar (i-d)`. Remark: if `s < d`, then result is `e` -/ @[extern "lean_expr_lower_loose_bvars"] constant lowerLooseBVars (e : @& Expr) (s d : @& Nat) : Expr /-- Lift loose bound variables `>= s` in `e` by `d`. -/ @[extern "lean_expr_lift_loose_bvars"] constant liftLooseBVars (e : @& Expr) (s d : @& Nat) : Expr /-- `inferImplicit e numParams considerRange` updates the first `numParams` parameter binder annotations of the `e` forall type. It marks any parameter with an explicit binder annotation if there is another explicit arguments that depends on it or the resulting type if `considerRange == true`. Remark: we use this function to infer the bind annotations of inductive datatype constructors, and structure projections. When the `{}` annotation is used in these commands, we set `considerRange == false`. -/ def inferImplicit : Expr β†’ Nat β†’ Bool β†’ Expr | Expr.forallE n d b c, i+1, considerRange => let b := inferImplicit b i considerRange let newInfo := if c.binderInfo.isExplicit && hasLooseBVarInExplicitDomain b 0 considerRange then BinderInfo.implicit else c.binderInfo mkForall n newInfo d b | e, 0, _ => e | e, _, _ => e /-- Instantiate the loose bound variables in `e` using `subst`. That is, a loose `Expr.bvar i` is replaced with `subst[i]`. -/ @[extern "lean_expr_instantiate"] constant instantiate (e : @& Expr) (subst : @& Array Expr) : Expr @[extern "lean_expr_instantiate1"] constant instantiate1 (e : @& Expr) (subst : @& Expr) : Expr /-- Similar to instantiate, but `Expr.bvar i` is replaced with `subst[subst.size - i - 1]` -/ @[extern "lean_expr_instantiate_rev"] constant instantiateRev (e : @& Expr) (subst : @& Array Expr) : Expr /-- Similar to `instantiate`, but consider only the variables `xs` in the range `[beginIdx, endIdx)`. Function panics if `beginIdx <= endIdx <= xs.size` does not hold. -/ @[extern "lean_expr_instantiate_range"] constant instantiateRange (e : @& Expr) (beginIdx endIdx : @& Nat) (xs : @& Array Expr) : Expr /-- Similar to `instantiateRev`, but consider only the variables `xs` in the range `[beginIdx, endIdx)`. Function panics if `beginIdx <= endIdx <= xs.size` does not hold. -/ @[extern "lean_expr_instantiate_rev_range"] constant instantiateRevRange (e : @& Expr) (beginIdx endIdx : @& Nat) (xs : @& Array Expr) : Expr /-- Replace free variables `xs` with loose bound variables. -/ @[extern "lean_expr_abstract"] constant abstract (e : @& Expr) (xs : @& Array Expr) : Expr /-- Similar to `abstract`, but consider only the first `min n xs.size` entries in `xs`. -/ @[extern "lean_expr_abstract_range"] constant abstractRange (e : @& Expr) (n : @& Nat) (xs : @& Array Expr) : Expr /-- Replace occurrences of the free variable `fvar` in `e` with `v` -/ def replaceFVar (e : Expr) (fvar : Expr) (v : Expr) : Expr := (e.abstract #[fvar]).instantiate1 v /-- Replace occurrences of the free variable `fvarId` in `e` with `v` -/ def replaceFVarId (e : Expr) (fvarId : FVarId) (v : Expr) : Expr := replaceFVar e (mkFVar fvarId) v /-- Replace occurrences of the free variables `fvars` in `e` with `vs` -/ def replaceFVars (e : Expr) (fvars : Array Expr) (vs : Array Expr) : Expr := (e.abstract fvars).instantiateRev vs instance : ToString Expr where toString := Expr.dbgToString def isAtomic : Expr β†’ Bool | Expr.const _ _ _ => true | Expr.sort _ _ => true | Expr.bvar _ _ => true | Expr.lit _ _ => true | Expr.mvar _ _ => true | Expr.fvar _ _ => true | _ => false end Expr def mkDecIsTrue (pred proof : Expr) := mkAppB (mkConst `Decidable.isTrue) pred proof def mkDecIsFalse (pred proof : Expr) := mkAppB (mkConst `Decidable.isFalse) pred proof open Std (HashMap HashSet PHashMap PHashSet) abbrev ExprMap (Ξ± : Type) := HashMap Expr Ξ± abbrev PersistentExprMap (Ξ± : Type) := PHashMap Expr Ξ± abbrev ExprSet := HashSet Expr abbrev PersistentExprSet := PHashSet Expr abbrev PExprSet := PersistentExprSet /- Auxiliary type for forcing `==` to be structural equality for `Expr` -/ structure ExprStructEq where val : Expr deriving Inhabited instance : Coe Expr ExprStructEq := ⟨ExprStructEq.mk⟩ namespace ExprStructEq protected def beq : ExprStructEq β†’ ExprStructEq β†’ Bool | ⟨eβ‚βŸ©, ⟨eβ‚‚βŸ© => Expr.equal e₁ eβ‚‚ protected def hash : ExprStructEq β†’ UInt64 | ⟨e⟩ => e.hash instance : BEq ExprStructEq := ⟨ExprStructEq.beq⟩ instance : Hashable ExprStructEq := ⟨ExprStructEq.hash⟩ instance : ToString ExprStructEq := ⟨fun e => toString e.val⟩ end ExprStructEq abbrev ExprStructMap (Ξ± : Type) := HashMap ExprStructEq Ξ± abbrev PersistentExprStructMap (Ξ± : Type) := PHashMap ExprStructEq Ξ± namespace Expr private partial def mkAppRevRangeAux (revArgs : Array Expr) (start : Nat) (b : Expr) (i : Nat) : Expr := if i == start then b else let i := i - 1 mkAppRevRangeAux revArgs start (mkApp b (revArgs.get! i)) i /-- `mkAppRevRange f b e args == mkAppRev f (revArgs.extract b e)` -/ def mkAppRevRange (f : Expr) (beginIdx endIdx : Nat) (revArgs : Array Expr) : Expr := mkAppRevRangeAux revArgs beginIdx f endIdx private def betaRevAux (revArgs : Array Expr) (sz : Nat) : Expr β†’ Nat β†’ Expr | Expr.lam _ _ b _, i => if i + 1 < sz then betaRevAux revArgs sz b (i+1) else let n := sz - (i + 1) mkAppRevRange (b.instantiateRange n sz revArgs) 0 n revArgs | Expr.mdata _ b _, i => betaRevAux revArgs sz b i | b, i => let n := sz - i mkAppRevRange (b.instantiateRange n sz revArgs) 0 n revArgs /-- If `f` is a lambda expression, than "beta-reduce" it using `revArgs`. This function is often used with `getAppRev` or `withAppRev`. Examples: - `betaRev (fun x y => t x y) #[]` ==> `fun x y => t x y` - `betaRev (fun x y => t x y) #[a]` ==> `fun y => t a y` - `betaRev (fun x y => t x y) #[a, b]` ==> t b a` - `betaRev (fun x y => t x y) #[a, b, c, d]` ==> t d c b a` Suppose `t` is `(fun x y => t x y) a b c d`, then `args := t.getAppRev` is `#[d, c, b, a]`, and `betaRev (fun x y => t x y) #[d, c, b, a]` is `t a b c d`. -/ def betaRev (f : Expr) (revArgs : Array Expr) : Expr := if revArgs.size == 0 then f else betaRevAux revArgs revArgs.size f 0 def isHeadBetaTargetFn : Expr β†’ Bool | Expr.lam _ _ _ _ => true | Expr.mdata _ b _ => isHeadBetaTargetFn b | _ => false def headBeta (e : Expr) : Expr := let f := e.getAppFn if f.isHeadBetaTargetFn then betaRev f e.getAppRevArgs else e def isHeadBetaTarget (e : Expr) : Bool := e.getAppFn.isHeadBetaTargetFn private def etaExpandedBody : Expr β†’ Nat β†’ Nat β†’ Option Expr | app f (bvar j _) _, n+1, i => if j == i then etaExpandedBody f n (i+1) else none | _, n+1, _ => none | f, 0, _ => if f.hasLooseBVars then none else some f private def etaExpandedAux : Expr β†’ Nat β†’ Option Expr | lam _ _ b _, n => etaExpandedAux b (n+1) | e, n => etaExpandedBody e n 0 /-- If `e` is of the form `(fun x₁ ... xβ‚™ => f x₁ ... xβ‚™)` and `f` does not contain `x₁`, ..., `xβ‚™`, then return `some f`. Otherwise, return `none`. It assumes `e` does not have loose bound variables. Remark: `β‚™` may be 0 -/ def etaExpanded? (e : Expr) : Option Expr := etaExpandedAux e 0 /-- Similar to `etaExpanded?`, but only succeeds if `β‚™ β‰₯ 1`. -/ def etaExpandedStrict? : Expr β†’ Option Expr | lam _ _ b _ => etaExpandedAux b 1 | _ => none def getOptParamDefault? (e : Expr) : Option Expr := if e.isAppOfArity `optParam 2 then some e.appArg! else none def getAutoParamTactic? (e : Expr) : Option Expr := if e.isAppOfArity `autoParam 2 then some e.appArg! else none def isOptParam (e : Expr) : Bool := e.isAppOfArity `optParam 2 def isAutoParam (e : Expr) : Bool := e.isAppOfArity `autoParam 2 /-- Return true iff `e` contains a free variable which statisfies `p`. -/ @[inline] def hasAnyFVar (e : Expr) (p : FVarId β†’ Bool) : Bool := let rec @[specialize] visit (e : Expr) := if !e.hasFVar then false else match e with | Expr.forallE _ d b _ => visit d || visit b | Expr.lam _ d b _ => visit d || visit b | Expr.mdata _ e _ => visit e | Expr.letE _ t v b _ => visit t || visit v || visit b | Expr.app f a _ => visit f || visit a | Expr.proj _ _ e _ => visit e | e@(Expr.fvar fvarId _) => p fvarId | e => false visit e def containsFVar (e : Expr) (fvarId : FVarId) : Bool := e.hasAnyFVar (Β· == fvarId) /- The update functions here are defined using C code. They will try to avoid allocating new values using pointer equality. The hypotheses `(h : e.is...)` are used to ensure Lean will not crash at runtime. The `update*!` functions are inlined and provide a convenient way of using the update proofs without providing proofs. Note that if they are used under a match-expression, the compiler will eliminate the double-match. -/ @[extern "lean_expr_update_app"] def updateApp (e : Expr) (newFn : Expr) (newArg : Expr) (h : e.isApp) : Expr := mkApp newFn newArg @[inline] def updateApp! (e : Expr) (newFn : Expr) (newArg : Expr) : Expr := match e with | app fn arg c => updateApp (app fn arg c) newFn newArg rfl | _ => panic! "application expected" @[extern "lean_expr_update_const"] def updateConst (e : Expr) (newLevels : List Level) (h : e.isConst) : Expr := mkConst e.constName! newLevels @[inline] def updateConst! (e : Expr) (newLevels : List Level) : Expr := match e with | const n ls c => updateConst (const n ls c) newLevels rfl | _ => panic! "constant expected" @[extern "lean_expr_update_sort"] def updateSort (e : Expr) (newLevel : Level) (h : e.isSort) : Expr := mkSort newLevel @[inline] def updateSort! (e : Expr) (newLevel : Level) : Expr := match e with | sort l c => updateSort (sort l c) newLevel rfl | _ => panic! "level expected" @[extern "lean_expr_update_proj"] def updateProj (e : Expr) (newExpr : Expr) (h : e.isProj) : Expr := match e with | proj s i _ _ => mkProj s i newExpr | _ => e -- unreachable because of `h` @[extern "lean_expr_update_mdata"] def updateMData (e : Expr) (newExpr : Expr) (h : e.isMData) : Expr := match e with | mdata d _ _ => mkMData d newExpr | _ => e -- unreachable because of `h` @[inline] def updateMData! (e : Expr) (newExpr : Expr) : Expr := match e with | mdata d e c => updateMData (mdata d e c) newExpr rfl | _ => panic! "mdata expected" @[inline] def updateProj! (e : Expr) (newExpr : Expr) : Expr := match e with | proj s i e c => updateProj (proj s i e c) newExpr rfl | _ => panic! "proj expected" @[extern "lean_expr_update_forall"] def updateForall (e : Expr) (newBinfo : BinderInfo) (newDomain : Expr) (newBody : Expr) (h : e.isForall) : Expr := mkForall e.bindingName! newBinfo newDomain newBody @[inline] def updateForall! (e : Expr) (newBinfo : BinderInfo) (newDomain : Expr) (newBody : Expr) : Expr := match e with | forallE n d b c => updateForall (forallE n d b c) newBinfo newDomain newBody rfl | _ => panic! "forall expected" @[inline] def updateForallE! (e : Expr) (newDomain : Expr) (newBody : Expr) : Expr := match e with | forallE n d b c => updateForall (forallE n d b c) c.binderInfo newDomain newBody rfl | _ => panic! "forall expected" @[extern "lean_expr_update_lambda"] def updateLambda (e : Expr) (newBinfo : BinderInfo) (newDomain : Expr) (newBody : Expr) (h : e.isLambda) : Expr := mkLambda e.bindingName! newBinfo newDomain newBody @[inline] def updateLambda! (e : Expr) (newBinfo : BinderInfo) (newDomain : Expr) (newBody : Expr) : Expr := match e with | lam n d b c => updateLambda (lam n d b c) newBinfo newDomain newBody rfl | _ => panic! "lambda expected" @[inline] def updateLambdaE! (e : Expr) (newDomain : Expr) (newBody : Expr) : Expr := match e with | lam n d b c => updateLambda (lam n d b c) c.binderInfo newDomain newBody rfl | _ => panic! "lambda expected" @[extern "lean_expr_update_let"] def updateLet (e : Expr) (newType : Expr) (newVal : Expr) (newBody : Expr) (h : e.isLet) : Expr := mkLet e.letName! newType newVal newBody @[inline] def updateLet! (e : Expr) (newType : Expr) (newVal : Expr) (newBody : Expr) : Expr := match e with | letE n t v b c => updateLet (letE n t v b c) newType newVal newBody rfl | _ => panic! "let expression expected" def updateFn : Expr β†’ Expr β†’ Expr | e@(app f a _), g => e.updateApp! (updateFn f g) a | _, g => g partial def eta (e : Expr) : Expr := match e with | Expr.lam _ d b _ => let b' := b.eta match b' with | Expr.app f (Expr.bvar 0 _) _ => if !f.hasLooseBVar 0 then f.lowerLooseBVars 1 1 else e.updateLambdaE! d b' | _ => e.updateLambdaE! d b' | _ => e /- Instantiate level parameters -/ @[inline] def instantiateLevelParamsCore (s : Name β†’ Option Level) (e : Expr) : Expr := let rec @[specialize] visit (e : Expr) : Expr := if !e.hasLevelParam then e else match e with | lam n d b _ => e.updateLambdaE! (visit d) (visit b) | forallE n d b _ => e.updateForallE! (visit d) (visit b) | letE n t v b _ => e.updateLet! (visit t) (visit v) (visit b) | app f a _ => e.updateApp! (visit f) (visit a) | proj _ _ s _ => e.updateProj! (visit s) | mdata _ b _ => e.updateMData! (visit b) | const _ us _ => e.updateConst! (us.map (fun u => u.instantiateParams s)) | sort u _ => e.updateSort! (u.instantiateParams s) | e => e visit e private def getParamSubst : List Name β†’ List Level β†’ Name β†’ Option Level | p::ps, u::us, p' => if p == p' then some u else getParamSubst ps us p' | _, _, _ => none def instantiateLevelParams (e : Expr) (paramNames : List Name) (lvls : List Level) : Expr := instantiateLevelParamsCore (getParamSubst paramNames lvls) e private partial def getParamSubstArray (ps : Array Name) (us : Array Level) (p' : Name) (i : Nat) : Option Level := if h : i < ps.size then let p := ps.get ⟨i, h⟩ if h : i < us.size then let u := us.get ⟨i, h⟩ if p == p' then some u else getParamSubstArray ps us p' (i+1) else none else none def instantiateLevelParamsArray (e : Expr) (paramNames : Array Name) (lvls : Array Level) : Expr := instantiateLevelParamsCore (fun p => getParamSubstArray paramNames lvls p 0) e /- Annotate `e` with the given option. -/ def setOption (e : Expr) (optionName : Name) [KVMap.Value Ξ±] (val : Ξ±) : Expr := mkMData (MData.empty.set optionName val) e /- Annotate `e` with `pp.explicit := true` The delaborator uses `pp` options. -/ def setPPExplicit (e : Expr) (flag : Bool) := e.setOption `pp.explicit flag def setPPUniverses (e : Expr) (flag : Bool) := e.setOption `pp.universes flag /- If `e` is an application `f a_1 ... a_n` annotate `f`, `a_1` ... `a_n` with `pp.explicit := false`, and annotate `e` with `pp.explicit := true`. -/ def setAppPPExplicit (e : Expr) : Expr := match e with | app .. => let f := e.getAppFn.setPPExplicit false let args := e.getAppArgs.map (Β·.setPPExplicit false) mkAppN f args |>.setPPExplicit true | _ => e /- Similar for `setAppPPExplicit`, but only annotate children with `pp.explicit := false` if `e` does not contain metavariables. -/ def setAppPPExplicitForExposingMVars (e : Expr) : Expr := match e with | app .. => let f := e.getAppFn.setPPExplicit false let args := e.getAppArgs.map fun arg => if arg.hasMVar then arg else arg.setPPExplicit false mkAppN f args |>.setPPExplicit true | _ => e end Expr def mkAnnotation (kind : Name) (e : Expr) : Expr := mkMData (KVMap.empty.insert kind (DataValue.ofBool true)) e def annotation? (kind : Name) (e : Expr) : Option Expr := match e with | Expr.mdata d b _ => if d.size == 1 && d.getBool kind false then some b else none | _ => none def mkFreshFVarId {m : Type β†’ Type} [Monad m] [MonadNameGenerator m] : m FVarId := mkFreshId def mkFreshMVarId {m : Type β†’ Type} [Monad m] [MonadNameGenerator m] : m FVarId := mkFreshId end Lean
57be7f77716ef7521b88ecba03886618488bbe90
a047a4718edfa935d17231e9e6ecec8c7b701e05
/src/ring_theory/adjoin_root.lean
7f0d36bfe09787331303f6b4d75c80b178f77b8d
[ "Apache-2.0" ]
permissive
utensil-contrib/mathlib
bae0c9fafe5e2bdb516efc89d6f8c1502ecc9767
b91909e77e219098a2f8cc031f89d595fe274bd2
refs/heads/master
1,668,048,976,965
1,592,442,701,000
1,592,442,701,000
273,197,855
0
0
null
1,592,472,812,000
1,592,472,811,000
null
UTF-8
Lean
false
false
4,180
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 Adjoining roots of polynomials -/ import data.polynomial import ring_theory.principal_ideal_domain /-! # Adjoining roots of polynomials This file defines the commutative ring `adjoin_root f`, the ring R[X]/(f) obtained from a commutative ring `R` and a polynomial `f : R[X]`. If furthermore `R` is a field and `f` is irreducible, the field structure on `adjoin_root f` is constructed. ## Main definitions and results The main definitions are in the `adjoin_root` namespace. * `mk f : polynomial R β†’+* adjoin_root f`, the natural ring homomorphism. * `of f : R β†’+* adjoin_root f`, the natural ring homomorphism. * `root f : adjoin_root f`, the image of X in R[X]/(f). * `lift (i : R β†’+* S) (x : S) (h : f.evalβ‚‚ i x = 0) : (adjoin_root f) β†’+* S`, the ring homomorphism from R[X]/(f) to S extending `i : R β†’+* S` and sending `X` to `x`. -/ noncomputable theory open_locale big_operators universes u v w variables {R : Type u} {S : Type v} {K : Type w} open polynomial ideal /-- Adjoin a root of a polynomial `f` to a commutative ring `R`. We define the new ring as the quotient of `R` by the principal ideal of `f`. -/ def adjoin_root [comm_ring R] (f : polynomial R) : Type u := ideal.quotient (span {f} : ideal (polynomial R)) namespace adjoin_root section comm_ring variables [comm_ring R] (f : polynomial R) instance : comm_ring (adjoin_root f) := ideal.quotient.comm_ring _ instance : inhabited (adjoin_root f) := ⟨0⟩ instance : decidable_eq (adjoin_root f) := classical.dec_eq _ /-- Ring homomorphism from `R[x]` to `adjoin_root f` sending `X` to the `root`. -/ def mk : polynomial R β†’+* adjoin_root f := ideal.quotient.mk_hom _ /-- Embedding of the original ring `R` into `adjoin_root f`. -/ def of : R β†’+* adjoin_root f := (mk f).comp (ring_hom.of C) /-- The adjoined root. -/ def root : adjoin_root f := mk f X variables {f} instance adjoin_root.has_coe_t : has_coe_t R (adjoin_root f) := ⟨of f⟩ @[simp] lemma mk_self : mk f f = 0 := quotient.sound' (mem_span_singleton.2 $ by simp) @[simp] lemma mk_C (x : R) : mk f (C x) = x := rfl @[simp] lemma evalβ‚‚_root (f : polynomial R) : f.evalβ‚‚ (of f) (root f) = 0 := quotient.induction_on' (root f) (Ξ» (g : polynomial R) (hg : mk f g = mk f X), show finsupp.sum f (Ξ» (e : β„•) (a : R), mk f (C a) * mk f g ^ e) = 0, by simp only [hg, ((mk f).map_pow _ _).symm, ((mk f).map_mul _ _).symm]; rw [finsupp.sum, ← (mk f).map_sum, show βˆ‘ i in _, _ = _, from sum_C_mul_X_eq _, mk_self]) (show (root f) = mk f X, from rfl) lemma is_root_root (f : polynomial R) : is_root (f.map (of f)) (root f) := by rw [is_root, eval_map, evalβ‚‚_root] variables [comm_ring S] /-- Lift a ring homomorphism `i : R β†’+* S` to `adjoin_root f β†’+* S`. -/ def lift (i : R β†’+* S) (x : S) (h : f.evalβ‚‚ i x = 0) : (adjoin_root f) β†’+* S := begin apply ideal.quotient.lift _ (evalβ‚‚_ring_hom i x), intros g H, rcases mem_span_singleton.1 H with ⟨y, hy⟩, rw [hy, ring_hom.map_mul, coe_evalβ‚‚_ring_hom, h, zero_mul] end variables {i : R β†’+* S} {a : S} {h : f.evalβ‚‚ i a = 0} @[simp] lemma lift_mk {g : polynomial R} : lift i a h (mk f g) = g.evalβ‚‚ i a := ideal.quotient.lift_mk _ _ _ @[simp] lemma lift_root : lift i a h (root f) = a := by simp [root, h] @[simp] lemma lift_of {x : R} : lift i a h x = i x := by rw [← mk_C x, lift_mk, evalβ‚‚_C] end comm_ring variables [field K] {f : polynomial K} [irreducible f] instance is_maximal_span : is_maximal (span {f} : ideal (polynomial K)) := principal_ideal_domain.is_maximal_of_irreducible β€Ήirreducible fβ€Ί noncomputable instance field : field (adjoin_root f) := ideal.quotient.field (span {f} : ideal (polynomial K)) lemma coe_injective : function.injective (coe : K β†’ adjoin_root f) := (of f).injective variable (f) lemma mul_div_root_cancel : ((X - C (root f)) * (f.map (of f) / (X - C (root f))) : polynomial (adjoin_root f)) = f.map (of f) := mul_div_eq_iff_is_root.2 $ is_root_root _ end adjoin_root
ca80d1ee6deb1cd0e97b9e80302173ec3b35deb3
6b45072eb2b3db3ecaace2a7a0241ce81f815787
/algebra/lattice/default.lean
83174a57a0d3b4b503436e3512343fac04a2462e
[]
no_license
avigad/library_dev
27b47257382667b5eb7e6476c4f5b0d685dd3ddc
9d8ac7c7798ca550874e90fed585caad030bbfac
refs/heads/master
1,610,452,468,791
1,500,712,839,000
1,500,713,478,000
69,311,142
1
0
null
1,474,942,903,000
1,474,942,902,000
null
UTF-8
Lean
false
false
67
lean
import .basic .bounded_lattice .boolean_algebra .complete_lattice
2d8937f2c68ba5d698d40f56f5cd8e02f4539403
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/category_theory/monad/limits_auto.lean
a72f7e52fd05e4e27b2d50f300e711114417313c
[]
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
15,218
lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.category_theory.monad.adjunction import Mathlib.category_theory.adjunction.limits import Mathlib.category_theory.limits.preserves.shapes.terminal import Mathlib.PostPort universes u₁ v₁ uβ‚‚ namespace Mathlib namespace category_theory namespace monad namespace forget_creates_limits /-- (Impl) The natural transformation used to define the new cone -/ @[simp] theorem Ξ³_app {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] (D : J β₯€ algebra T) (j : J) : nat_trans.app (Ξ³ D) j = algebra.a (functor.obj D j) := Eq.refl (nat_trans.app (Ξ³ D) j) /-- (Impl) This new cone is used to construct the algebra structure -/ @[simp] theorem new_cone_X {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] (D : J β₯€ algebra T) (c : limits.cone (D β‹™ forget T)) : limits.cone.X (new_cone D c) = functor.obj T (limits.cone.X c) := Eq.refl (limits.cone.X (new_cone D c)) /-- The algebra structure which will be the apex of the new limit cone for `D`. -/ @[simp] theorem cone_point_A {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] (D : J β₯€ algebra T) (c : limits.cone (D β‹™ forget T)) (t : limits.is_limit c) : algebra.A (cone_point D c t) = limits.cone.X c := Eq.refl (algebra.A (cone_point D c t)) /-- (Impl) Construct the lifted cone in `algebra T` which will be limiting. -/ @[simp] theorem lifted_cone_X {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] (D : J β₯€ algebra T) (c : limits.cone (D β‹™ forget T)) (t : limits.is_limit c) : limits.cone.X (lifted_cone D c t) = cone_point D c t := Eq.refl (limits.cone.X (lifted_cone D c t)) /-- (Impl) Prove that the lifted cone is limiting. -/ def lifted_cone_is_limit {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] (D : J β₯€ algebra T) (c : limits.cone (D β‹™ forget T)) (t : limits.is_limit c) : limits.is_limit (lifted_cone D c t) := limits.is_limit.mk fun (s : limits.cone D) => algebra.hom.mk (limits.is_limit.lift t (functor.map_cone (forget T) s)) end forget_creates_limits -- Theorem 5.6.5 from [Riehl][riehl2017] /-- The forgetful functor from the Eilenberg-Moore category creates limits. -/ protected instance forget_creates_limits {C : Type u₁} [category C] {T : C β₯€ C} [monad T] : creates_limits (forget T) := creates_limits.mk fun (J : Type v₁) (π’₯ : small_category J) => creates_limits_of_shape.mk fun (D : J β₯€ algebra T) => creates_limit_of_reflects_iso fun (c : limits.cone (D β‹™ forget T)) (t : limits.is_limit c) => lifts_to_limit.mk (liftable_cone.mk sorry (limits.cones.ext (iso.refl (limits.cone.X (functor.map_cone (forget T) sorry))) sorry)) sorry /-- `D β‹™ forget T` has a limit, then `D` has a limit. -/ theorem has_limit_of_comp_forget_has_limit {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] (D : J β₯€ algebra T) [limits.has_limit (D β‹™ forget T)] : limits.has_limit D := has_limit_of_created D (forget T) namespace forget_creates_colimits -- Let's hide the implementation details in a namespace -- We have a diagram D of shape J in the category of algebras, and we assume that we are given a -- colimit for its image D β‹™ forget T under the forgetful functor, say its apex is L. -- We'll construct a colimiting coalgebra for D, whose carrier will also be L. -- To do this, we must find a map TL ⟢ L. Since T preserves colimits, TL is also a colimit. -- In particular, it is a colimit for the diagram `(D β‹™ forget T) β‹™ T` -- so to construct a map TL ⟢ L it suffices to show that L is the apex of a cocone for this diagram. -- In other words, we need a natural transformation from const L to `(D β‹™ forget T) β‹™ T`. -- But we already know that L is the apex of a cocone for the diagram `D β‹™ forget T`, so it -- suffices to give a natural transformation `((D β‹™ forget T) β‹™ T) ⟢ (D β‹™ forget T)`: /-- (Impl) The natural transformation given by the algebra structure maps, used to construct a cocone `c` with apex `colimit (D β‹™ forget T)`. -/ @[simp] theorem Ξ³_app {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] {D : J β₯€ algebra T} (j : J) : nat_trans.app Ξ³ j = algebra.a (functor.obj D j) := Eq.refl (nat_trans.app Ξ³ j) /-- (Impl) A cocone for the diagram `(D β‹™ forget T) β‹™ T` found by composing the natural transformation `Ξ³` with the colimiting cocone for `D β‹™ forget T`. -/ @[simp] theorem new_cocone_X {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] {D : J β₯€ algebra T} (c : limits.cocone (D β‹™ forget T)) : limits.cocone.X (new_cocone c) = limits.cocone.X c := Eq.refl (limits.cocone.X (new_cocone c)) /-- (Impl) Define the map `Ξ» : TL ⟢ L`, which will serve as the structure of the coalgebra on `L`, and we will show is the colimiting object. We use the cocone constructed by `c` and the fact that `T` preserves colimits to produce this morphism. -/ def lambda {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] {D : J β₯€ algebra T} (c : limits.cocone (D β‹™ forget T)) (t : limits.is_colimit c) [limits.preserves_colimit (D β‹™ forget T) T] : limits.cocone.X (functor.map_cocone T c) ⟢ limits.cocone.X c := limits.is_colimit.desc (limits.preserves_colimit.preserves t) (new_cocone c) /-- (Impl) The key property defining the map `Ξ» : TL ⟢ L`. -/ theorem commuting {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] {D : J β₯€ algebra T} (c : limits.cocone (D β‹™ forget T)) (t : limits.is_colimit c) [limits.preserves_colimit (D β‹™ forget T) T] (j : J) : functor.map T (nat_trans.app (limits.cocone.ΞΉ c) j) ≫ lambda c t = algebra.a (functor.obj D j) ≫ nat_trans.app (limits.cocone.ΞΉ c) j := limits.is_colimit.fac (limits.preserves_colimit.preserves t) (new_cocone c) j /-- (Impl) Construct the colimiting algebra from the map `Ξ» : TL ⟢ L` given by `lambda`. We are required to show it satisfies the two algebra laws, which follow from the algebra laws for the image of `D` and our `commuting` lemma. -/ @[simp] theorem cocone_point_A {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] {D : J β₯€ algebra T} (c : limits.cocone (D β‹™ forget T)) (t : limits.is_colimit c) [limits.preserves_colimit (D β‹™ forget T) T] [limits.preserves_colimit ((D β‹™ forget T) β‹™ T) T] : algebra.A (cocone_point c t) = limits.cocone.X c := Eq.refl (algebra.A (cocone_point c t)) /-- (Impl) Construct the lifted cocone in `algebra T` which will be colimiting. -/ @[simp] theorem lifted_cocone_X {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] {D : J β₯€ algebra T} (c : limits.cocone (D β‹™ forget T)) (t : limits.is_colimit c) [limits.preserves_colimit (D β‹™ forget T) T] [limits.preserves_colimit ((D β‹™ forget T) β‹™ T) T] : limits.cocone.X (lifted_cocone c t) = cocone_point c t := Eq.refl (limits.cocone.X (lifted_cocone c t)) /-- (Impl) Prove that the lifted cocone is colimiting. -/ @[simp] theorem lifted_cocone_is_colimit_desc_f {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] {D : J β₯€ algebra T} (c : limits.cocone (D β‹™ forget T)) (t : limits.is_colimit c) [limits.preserves_colimit (D β‹™ forget T) T] [limits.preserves_colimit ((D β‹™ forget T) β‹™ T) T] (s : limits.cocone D) : algebra.hom.f (limits.is_colimit.desc (lifted_cocone_is_colimit c t) s) = limits.is_colimit.desc t (functor.map_cocone (forget T) s) := Eq.refl (algebra.hom.f (limits.is_colimit.desc (lifted_cocone_is_colimit c t) s)) end forget_creates_colimits -- TODO: the converse of this is true as well /-- The forgetful functor from the Eilenberg-Moore category for a monad creates any colimit which the monad itself preserves. -/ protected instance forget_creates_colimit {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] (D : J β₯€ algebra T) [limits.preserves_colimit (D β‹™ forget T) T] [limits.preserves_colimit ((D β‹™ forget T) β‹™ T) T] : creates_colimit D (forget T) := creates_colimit_of_reflects_iso fun (c : limits.cocone (D β‹™ forget T)) (t : limits.is_colimit c) => lifts_to_colimit.mk (liftable_cocone.mk (limits.cocone.mk (forget_creates_colimits.cocone_point c t) (nat_trans.mk fun (j : J) => algebra.hom.mk (nat_trans.app (limits.cocone.ΞΉ c) j))) (limits.cocones.ext (iso.refl (limits.cocone.X (functor.map_cocone (forget T) (limits.cocone.mk (forget_creates_colimits.cocone_point c t) (nat_trans.mk fun (j : J) => algebra.hom.mk (nat_trans.app (limits.cocone.ΞΉ c) j)))))) sorry)) (forget_creates_colimits.lifted_cocone_is_colimit c t) protected instance forget_creates_colimits_of_shape {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] [limits.preserves_colimits_of_shape J T] : creates_colimits_of_shape J (forget T) := creates_colimits_of_shape.mk fun (K : J β₯€ algebra T) => monad.forget_creates_colimit K protected instance forget_creates_colimits {C : Type u₁} [category C] {T : C β₯€ C} [monad T] [limits.preserves_colimits T] : creates_colimits (forget T) := creates_colimits.mk fun (J : Type v₁) (π’₯₁ : small_category J) => monad.forget_creates_colimits_of_shape /-- For `D : J β₯€ algebra T`, `D β‹™ forget T` has a colimit, then `D` has a colimit provided colimits of shape `J` are preserved by `T`. -/ theorem forget_creates_colimits_of_monad_preserves {C : Type u₁} [category C] {T : C β₯€ C} [monad T] {J : Type v₁} [small_category J] [limits.preserves_colimits_of_shape J T] (D : J β₯€ algebra T) [limits.has_colimit (D β‹™ forget T)] : limits.has_colimit D := has_colimit_of_created D (forget T) end monad protected instance comp_comparison_forget_has_limit {C : Type u₁} [category C] {D : Type uβ‚‚} [category D] {J : Type v₁} [small_category J] (F : J β₯€ D) (R : D β₯€ C) [monadic_right_adjoint R] [limits.has_limit (F β‹™ R)] : limits.has_limit ((F β‹™ monad.comparison R) β‹™ monad.forget (left_adjoint R β‹™ R)) := limits.has_limit_of_iso (iso_whisker_left F (iso.symm (monad.comparison_forget R))) protected instance comp_comparison_has_limit {C : Type u₁} [category C] {D : Type uβ‚‚} [category D] {J : Type v₁} [small_category J] (F : J β₯€ D) (R : D β₯€ C) [monadic_right_adjoint R] [limits.has_limit (F β‹™ R)] : limits.has_limit (F β‹™ monad.comparison R) := monad.has_limit_of_comp_forget_has_limit (F β‹™ monad.comparison R) /-- Any monadic functor creates limits. -/ def monadic_creates_limits {C : Type u₁} [category C] {D : Type uβ‚‚} [category D] (R : D β₯€ C) [monadic_right_adjoint R] : creates_limits R := creates_limits_of_nat_iso (monad.comparison_forget R) /-- The forgetful functor from the Eilenberg-Moore category for a monad creates any colimit which the monad itself preserves. -/ def monadic_creates_colimit_of_preserves_colimit {C : Type u₁} [category C] {D : Type uβ‚‚} [category D] {J : Type v₁} [small_category J] (R : D β₯€ C) (K : J β₯€ D) [monadic_right_adjoint R] [limits.preserves_colimit (K β‹™ R) (left_adjoint R β‹™ R)] [limits.preserves_colimit ((K β‹™ R) β‹™ left_adjoint R β‹™ R) (left_adjoint R β‹™ R)] : creates_colimit K R := creates_colimit_of_nat_iso (monad.comparison_forget R) /-- A monadic functor creates any colimits of shapes it preserves. -/ def monadic_creates_colimits_of_shape_of_preserves_colimits_of_shape {C : Type u₁} [category C] {D : Type uβ‚‚} [category D] {J : Type v₁} [small_category J] (R : D β₯€ C) [monadic_right_adjoint R] [limits.preserves_colimits_of_shape J R] : creates_colimits_of_shape J R := creates_colimits_of_shape_of_nat_iso (monad.comparison_forget R) /-- A monadic functor creates colimits if it preserves colimits. -/ def monadic_creates_colimits_of_preserves_colimits {C : Type u₁} [category C] {D : Type uβ‚‚} [category D] (R : D β₯€ C) [monadic_right_adjoint R] [limits.preserves_colimits R] : creates_colimits R := creates_colimits.mk fun (J : Type v₁) (π’₯₁ : small_category J) => monadic_creates_colimits_of_shape_of_preserves_colimits_of_shape R theorem has_limit_of_reflective {C : Type u₁} [category C] {D : Type uβ‚‚} [category D] {J : Type v₁} [small_category J] (F : J β₯€ D) (R : D β₯€ C) [limits.has_limit (F β‹™ R)] [reflective R] : limits.has_limit F := has_limit_of_created F R /-- If `C` has limits of shape `J` then any reflective subcategory has limits of shape `J`. -/ theorem has_limits_of_shape_of_reflective {C : Type u₁} [category C] {D : Type uβ‚‚} [category D] {J : Type v₁} [small_category J] [limits.has_limits_of_shape J C] (R : D β₯€ C) [reflective R] : limits.has_limits_of_shape J D := limits.has_limits_of_shape.mk fun (F : J β₯€ D) => has_limit_of_reflective F R /-- If `C` has limits then any reflective subcategory has limits. -/ theorem has_limits_of_reflective {C : Type u₁} [category C] {D : Type uβ‚‚} [category D] (R : D β₯€ C) [limits.has_limits C] [reflective R] : limits.has_limits D := limits.has_limits.mk fun (J : Type v₁) (π’₯₁ : small_category J) => has_limits_of_shape_of_reflective R /-- The reflector always preserves terminal objects. Note this in general doesn't apply to any other limit. -/ def left_adjoint_preserves_terminal_of_reflective {C : Type u₁} [category C] {D : Type uβ‚‚} [category D] (R : D β₯€ C) [reflective R] [limits.has_terminal C] : limits.preserves_limits_of_shape (discrete pempty) (left_adjoint R) := limits.preserves_limits_of_shape.mk fun (K : discrete pempty β₯€ C) => let _inst : limits.has_terminal D := sorry; let _inst_3 : creates_limits R := monadic_creates_limits R; let _inst_6 : limits.preserves_limit (functor.empty D) R := category_theory.preserves_limit_of_creates_limit_and_has_limit (functor.empty D) R; let _inst_7 : limits.preserves_limit (functor.empty C) (left_adjoint R) := limits.preserves_terminal_of_iso (left_adjoint R) (functor.map_iso (left_adjoint R) (iso.symm (limits.preserves_terminal.iso R)) β‰ͺ≫ as_iso (nat_trans.app (adjunction.counit (adjunction.of_right_adjoint R)) (⊀_D))); limits.preserves_limit_of_iso_diagram (left_adjoint R) (iso.symm (functor.unique_from_empty K)) end Mathlib
8d5b3c90773368b26ed91c10356554e8172861d6
b2e508d02500f1512e1618150413e6be69d9db10
/src/algebra/module.lean
772c6157603bb68d3f3f87caa94ba8147023500f
[ "Apache-2.0" ]
permissive
callum-sutton/mathlib
c3788f90216e9cd43eeffcb9f8c9f959b3b01771
afd623825a3ac6bfbcc675a9b023edad3f069e89
refs/heads/master
1,591,371,888,053
1,560,990,690,000
1,560,990,690,000
192,476,045
0
0
Apache-2.0
1,568,941,843,000
1,560,837,965,000
Lean
UTF-8
Lean
false
false
14,661
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 Modules over a ring. -/ import algebra.ring algebra.big_operators group_theory.subgroup group_theory.group_action open function universes u v w x variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} {Ξ΄ : Type x} -- /-- Typeclass for types with a scalar multiplication operation, denoted `β€’` (`\bu`) -/ -- class has_scalar (Ξ± : Type u) (Ξ³ : Type v) := (smul : Ξ± β†’ Ξ³ β†’ Ξ³) -- infixr ` β€’ `:73 := has_scalar.smul /-- A semimodule is a generalization of vector spaces to a scalar semiring. It consists of a scalar semiring `Ξ±` and an additive monoid of "vectors" `Ξ²`, connected by a "scalar multiplication" operation `r β€’ x : Ξ²` (where `r : Ξ±` and `x : Ξ²`) with some natural associativity and distributivity axioms similar to those on a ring. -/ class semimodule (Ξ± : Type u) (Ξ² : Type v) [semiring Ξ±] [add_comm_monoid Ξ²] extends distrib_mul_action Ξ± Ξ² := (add_smul : βˆ€(r s : Ξ±) (x : Ξ²), (r + s) β€’ x = r β€’ x + s β€’ x) (zero_smul : βˆ€x : Ξ², (0 : Ξ±) β€’ x = 0) section semimodule variables [R:semiring Ξ±] [add_comm_monoid Ξ²] [semimodule Ξ± Ξ²] (r s : Ξ±) (x y : Ξ²) include R theorem add_smul : (r + s) β€’ x = r β€’ x + s β€’ x := semimodule.add_smul r s x variables (Ξ±) @[simp] theorem zero_smul : (0 : Ξ±) β€’ x = 0 := semimodule.zero_smul Ξ± x lemma smul_smul : r β€’ s β€’ x = (r * s) β€’ x := (mul_smul _ _ _).symm instance smul.is_add_monoid_hom {r : Ξ±} : is_add_monoid_hom (Ξ» x : Ξ², r β€’ x) := { map_add := smul_add _, map_zero := smul_zero _ } end semimodule /-- A module is a generalization of vector spaces to a scalar ring. It consists of a scalar ring `Ξ±` and an additive group of "vectors" `Ξ²`, connected by a "scalar multiplication" operation `r β€’ x : Ξ²` (where `r : Ξ±` and `x : Ξ²`) with some natural associativity and distributivity axioms similar to those on a ring. -/ class module (Ξ± : Type u) (Ξ² : Type v) [ring Ξ±] [add_comm_group Ξ²] extends semimodule Ξ± Ξ² structure module.core (Ξ± Ξ²) [ring Ξ±] [add_comm_group Ξ²] extends has_scalar Ξ± Ξ² := (smul_add : βˆ€(r : Ξ±) (x y : Ξ²), r β€’ (x + y) = r β€’ x + r β€’ y) (add_smul : βˆ€(r s : Ξ±) (x : Ξ²), (r + s) β€’ x = r β€’ x + s β€’ x) (mul_smul : βˆ€(r s : Ξ±) (x : Ξ²), (r * s) β€’ x = r β€’ s β€’ x) (one_smul : βˆ€x : Ξ², (1 : Ξ±) β€’ x = x) def module.of_core {Ξ± Ξ²} [ring Ξ±] [add_comm_group Ξ²] (M : module.core Ξ± Ξ²) : module Ξ± Ξ² := by letI := M.to_has_scalar; exact { zero_smul := Ξ» x, have (0 : Ξ±) β€’ x + (0 : Ξ±) β€’ x = (0 : Ξ±) β€’ x + 0, by rw ← M.add_smul; simp, add_left_cancel this, smul_zero := Ξ» r, have r β€’ (0:Ξ²) + r β€’ 0 = r β€’ 0 + 0, by rw ← M.smul_add; simp, add_left_cancel this, ..M } section module variables [ring Ξ±] [add_comm_group Ξ²] [module Ξ± Ξ²] (r s : Ξ±) (x y : Ξ²) @[simp] theorem neg_smul : -r β€’ x = - (r β€’ x) := eq_neg_of_add_eq_zero (by rw [← add_smul, add_left_neg, zero_smul]) variables (Ξ±) theorem neg_one_smul (x : Ξ²) : (-1 : Ξ±) β€’ x = -x := by simp variables {Ξ±} @[simp] theorem smul_neg : r β€’ (-x) = -(r β€’ x) := by rw [← neg_one_smul Ξ±, ← mul_smul, mul_neg_one, neg_smul] theorem smul_sub (r : Ξ±) (x y : Ξ²) : r β€’ (x - y) = r β€’ x - r β€’ y := by simp [smul_add]; rw smul_neg theorem sub_smul (r s : Ξ±) (y : Ξ²) : (r - s) β€’ y = r β€’ y - s β€’ y := by simp [add_smul] end module instance semiring.to_semimodule [r : semiring Ξ±] : semimodule Ξ± Ξ± := { 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, ..r } @[simp] lemma smul_eq_mul [semiring Ξ±] {a a' : Ξ±} : a β€’ a' = a * a' := rfl instance ring.to_module [r : ring Ξ±] : module Ξ± Ξ± := { ..semiring.to_semimodule } def is_ring_hom.to_module [ring Ξ±] [ring Ξ²] (f : Ξ± β†’ Ξ²) [h : is_ring_hom f] : module Ξ± Ξ² := module.of_core { 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 [h.map_add, add_mul], mul_smul := Ξ» r s x, by unfold has_scalar.smul; rw [h.map_mul, mul_assoc], one_smul := Ξ» x, show f 1 * x = _, by rw [h.map_one, one_mul] } class is_linear_map (Ξ± : Type u) {Ξ² : Type v} {Ξ³ : Type w} [ring Ξ±] [add_comm_group Ξ²] [add_comm_group Ξ³] [module Ξ± Ξ²] [module Ξ± Ξ³] (f : Ξ² β†’ Ξ³) : Prop := (add : βˆ€x y, f (x + y) = f x + f y) (smul : βˆ€(c : Ξ±) x, f (c β€’ x) = c β€’ f x) structure linear_map (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : Type w) [ring Ξ±] [add_comm_group Ξ²] [add_comm_group Ξ³] [module Ξ± Ξ²] [module Ξ± Ξ³] := (to_fun : Ξ² β†’ Ξ³) (add : βˆ€x y, to_fun (x + y) = to_fun x + to_fun y) (smul : βˆ€(c : Ξ±) x, to_fun (c β€’ x) = c β€’ to_fun x) infixr ` β†’β‚— `:25 := linear_map _ notation Ξ² ` β†’β‚—[`:25 Ξ± `] ` Ξ³ := linear_map Ξ± Ξ² Ξ³ namespace linear_map variables [ring Ξ±] [add_comm_group Ξ²] [add_comm_group Ξ³] [add_comm_group Ξ΄] variables [module Ξ± Ξ²] [module Ξ± Ξ³] [module Ξ± Ξ΄] variables (f g : Ξ² β†’β‚—[Ξ±] Ξ³) include Ξ± instance : has_coe_to_fun (Ξ² β†’β‚—[Ξ±] Ξ³) := ⟨_, to_fun⟩ theorem is_linear : is_linear_map Ξ± f := {..f} @[extensionality] theorem ext {f g : Ξ² β†’β‚—[Ξ±] Ξ³} (H : βˆ€ x, f x = g x) : f = g := by cases f; cases g; congr'; exact funext H theorem ext_iff {f g : Ξ² β†’β‚—[Ξ±] Ξ³} : f = g ↔ βˆ€ x, f x = g x := ⟨by rintro rfl; simp, ext⟩ @[simp] lemma map_add (x y : Ξ²) : f (x + y) = f x + f y := f.add x y @[simp] lemma map_smul (c : Ξ±) (x : Ξ²) : f (c β€’ x) = c β€’ f x := f.smul c x @[simp] lemma map_zero : f 0 = 0 := by rw [← zero_smul Ξ±, map_smul f 0 0, zero_smul] instance : is_add_group_hom f := ⟨map_add f⟩ @[simp] lemma map_neg (x : Ξ²) : f (- x) = - f x := by rw [← neg_one_smul Ξ±, map_smul, neg_one_smul] @[simp] lemma map_sub (x y : Ξ²) : f (x - y) = f x - f y := by simp [map_neg, map_add] @[simp] lemma map_sum {ΞΉ} {t : finset ΞΉ} {g : ΞΉ β†’ Ξ²} : f (t.sum g) = t.sum (Ξ»i, f (g i)) := (finset.sum_hom f).symm def comp (f : Ξ³ β†’β‚—[Ξ±] Ξ΄) (g : Ξ² β†’β‚—[Ξ±] Ξ³) : Ξ² β†’β‚—[Ξ±] Ξ΄ := ⟨f ∘ g, by simp, by simp⟩ @[simp] lemma comp_apply (f : Ξ³ β†’β‚—[Ξ±] Ξ΄) (g : Ξ² β†’β‚—[Ξ±] Ξ³) (x : Ξ²) : f.comp g x = f (g x) := rfl def id : Ξ² β†’β‚—[Ξ±] Ξ² := ⟨id, by simp, by simp⟩ @[simp] lemma id_apply (x : Ξ²) : @id Ξ± Ξ² _ _ _ x = x := rfl end linear_map namespace is_linear_map variables [ring Ξ±] [add_comm_group Ξ²] [add_comm_group Ξ³] variables [module Ξ± Ξ²] [module Ξ± Ξ³] include Ξ± def mk' (f : Ξ² β†’ Ξ³) (H : is_linear_map Ξ± f) : Ξ² β†’β‚— Ξ³ := {to_fun := f, ..H} @[simp] theorem mk'_apply {f : Ξ² β†’ Ξ³} (H : is_linear_map Ξ± f) (x : Ξ²) : mk' f H x = f x := rfl lemma is_linear_map_neg : is_linear_map Ξ± (Ξ» (z : Ξ²), -z) := is_linear_map.mk neg_add (Ξ» x y, (smul_neg x y).symm) lemma is_linear_map_smul {Ξ± R : Type*} [add_comm_group Ξ±] [comm_ring R] [module R Ξ±] (c : R): is_linear_map R (Ξ» (z : Ξ±), c β€’ z) := begin refine is_linear_map.mk (smul_add c) _, intros _ _, simp [smul_smul], ac_refl end --TODO: move lemma is_linear_map_smul' {Ξ± R : Type*} [add_comm_group Ξ±] [comm_ring R] [module R Ξ±] (a : Ξ±): is_linear_map R (Ξ» (c : R), c β€’ a) := begin refine is_linear_map.mk (Ξ» x y, add_smul x y a) _, intros _ _, simp [smul_smul] end variables {f : Ξ² β†’ Ξ³} (lin : is_linear_map Ξ± f) include Ξ² Ξ³ lin @[simp] lemma map_zero : f (0 : Ξ²) = (0 : Ξ³) := by rw [← zero_smul Ξ± (0 : Ξ²), lin.smul, zero_smul] @[simp] lemma map_add (x y : Ξ²) : f (x + y) = f x + f y := by rw [lin.add] @[simp] lemma map_neg (x : Ξ²) : f (- x) = - f x := by rw [← neg_one_smul Ξ±, lin.smul, neg_one_smul] @[simp] lemma map_sub (x y : Ξ²) : f (x - y) = f x - f y := by simp [lin.map_neg, lin.map_add] end is_linear_map /-- 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 (Ξ± : Type u) (Ξ² : Type v) [ring Ξ±] [add_comm_group Ξ²] [module Ξ± Ξ²] : Type v := (carrier : set Ξ²) (zero : (0:Ξ²) ∈ carrier) (add : βˆ€ {x y}, x ∈ carrier β†’ y ∈ carrier β†’ x + y ∈ carrier) (smul : βˆ€ (c:Ξ±) {x}, x ∈ carrier β†’ c β€’ x ∈ carrier) namespace submodule variables [ring Ξ±] [add_comm_group Ξ²] [add_comm_group Ξ³] variables [module Ξ± Ξ²] [module Ξ± Ξ³] variables (p p' : submodule Ξ± Ξ²) variables {r : Ξ±} {x y : Ξ²} instance : has_coe (submodule Ξ± Ξ²) (set Ξ²) := ⟨submodule.carrier⟩ instance : has_mem Ξ² (submodule Ξ± Ξ²) := ⟨λ x p, x ∈ (p : set Ξ²)⟩ @[simp] theorem mem_coe : x ∈ (p : set Ξ²) ↔ x ∈ p := iff.rfl theorem ext' {s t : submodule Ξ± Ξ²} (h : (s : set Ξ²) = t) : s = t := by cases s; cases t; congr' protected theorem ext'_iff {s t : submodule Ξ± Ξ²} : (s : set Ξ²) = t ↔ s = t := ⟨ext', Ξ» h, h β–Έ rfl⟩ @[extensionality] theorem ext {s t : submodule Ξ± Ξ²} (h : βˆ€ x, x ∈ s ↔ x ∈ t) : s = t := ext' $ set.ext h @[simp] lemma zero_mem : (0 : Ξ²) ∈ p := p.zero lemma add_mem (h₁ : x ∈ p) (hβ‚‚ : y ∈ p) : x + y ∈ p := p.add h₁ hβ‚‚ lemma smul_mem (r : Ξ±) (h : x ∈ p) : r β€’ x ∈ p := p.smul r h lemma neg_mem (hx : x ∈ p) : -x ∈ p := by rw ← neg_one_smul Ξ±; 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 {ΞΉ : Type w} [decidable_eq ΞΉ] {t : finset ΞΉ} {f : ΞΉ β†’ Ξ²} : (βˆ€c∈t, f c ∈ p) β†’ t.sum f ∈ p := finset.induction_on t (by simp [p.zero_mem]) (by simp [p.add_mem] {contextual := tt}) instance : has_add p := ⟨λx y, ⟨x.1 + y.1, add_mem _ x.2 y.2⟩⟩ instance : has_zero p := ⟨⟨0, zero_mem _⟩⟩ instance : has_neg p := ⟨λx, ⟨-x.1, neg_mem _ x.2⟩⟩ instance : has_scalar Ξ± p := ⟨λ c x, ⟨c β€’ x.1, smul_mem _ c x.2⟩⟩ @[simp] lemma coe_add (x y : p) : (↑(x + y) : Ξ²) = ↑x + ↑y := rfl @[simp] lemma coe_zero : ((0 : p) : Ξ²) = 0 := rfl @[simp] lemma coe_neg (x : p) : ((-x : p) : Ξ²) = -x := rfl @[simp] lemma coe_smul (r : Ξ±) (x : p) : ((r β€’ x : p) : Ξ²) = r β€’ ↑x := rfl instance : add_comm_group p := by refine {add := (+), zero := 0, neg := has_neg.neg, ..}; { intros, apply set_coe.ext, simp } instance submodule_is_add_subgroup : is_add_subgroup (p : set Ξ²) := { zero_mem := p.zero, add_mem := p.add, neg_mem := Ξ» _, p.neg_mem } lemma coe_sub (x y : p) : (↑(x - y) : Ξ²) = ↑x - ↑y := by simp instance : module Ξ± p := by refine {smul := (β€’), ..}; { intros, apply set_coe.ext, simp [smul_add, add_smul, mul_smul] } protected def subtype : p β†’β‚—[Ξ±] Ξ² := by refine {to_fun := coe, ..}; simp [coe_smul] @[simp] theorem subtype_apply (x : p) : p.subtype x = x := rfl end submodule @[reducible] def ideal (Ξ± : Type u) [comm_ring Ξ±] := submodule Ξ± Ξ± namespace ideal variables [comm_ring Ξ±] (I : ideal Ξ±) {a b : Ξ±} protected lemma zero_mem : (0 : Ξ±) ∈ 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 /-- 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. -/ class vector_space (Ξ± : Type u) (Ξ² : Type v) [discrete_field Ξ±] [add_comm_group Ξ²] extends module Ξ± Ξ² instance discrete_field.to_vector_space {Ξ± : Type*} [discrete_field Ξ±] : vector_space Ξ± Ξ± := { .. ring.to_module } /-- Subspace of a vector space. Defined to equal `submodule`. -/ @[reducible] def subspace (Ξ± : Type u) (Ξ² : Type v) [discrete_field Ξ±] [add_comm_group Ξ²] [vector_space Ξ± Ξ²] : Type v := submodule Ξ± Ξ² instance subspace.vector_space {Ξ± Ξ²} {f : discrete_field Ξ±} [add_comm_group Ξ²] [vector_space Ξ± Ξ²] (p : subspace Ξ± Ξ²) : vector_space Ξ± p := {..submodule.module p} namespace submodule variables {R:discrete_field Ξ±} [add_comm_group Ξ²] [add_comm_group Ξ³] variables [vector_space Ξ± Ξ²] [vector_space Ξ± Ξ³] variables (p p' : submodule Ξ± Ξ²) variables {r : Ξ±} {x y : Ξ²} include R set_option class.instance_max_depth 36 theorem smul_mem_iff (r0 : r β‰  0) : r β€’ x ∈ p ↔ x ∈ p := ⟨λ h, by simpa [smul_smul, inv_mul_cancel r0] using p.smul_mem (r⁻¹) h, p.smul_mem r⟩ end submodule namespace add_comm_monoid open add_monoid variables {M : Type*} [add_comm_monoid M] instance : 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 {M : Type*} [add_comm_group M] instance : 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 } end add_comm_group def is_add_group_hom.to_linear_map [add_comm_group Ξ±] [add_comm_group Ξ²] (f : Ξ± β†’ Ξ²) [is_add_group_hom f] : Ξ± β†’β‚—[β„€] Ξ² := { to_fun := f, add := is_add_group_hom.map_add f, smul := Ξ» i x, int.induction_on i (by rw [zero_smul, zero_smul, is_add_group_hom.map_zero f]) (Ξ» i ih, by rw [add_smul, add_smul, is_add_group_hom.map_add f, ih, one_smul, one_smul]) (Ξ» i ih, by rw [sub_smul, sub_smul, is_add_group_hom.map_sub f, ih, one_smul, one_smul]) }
417756babf10e53d75739ebba5ca8293f9fbedc0
6cc23d886ccf271bfd0c9ca5d29cafb9c0be7bf5
/src/LeanPlay/Cli.lean
55980b11b08d4dd47a3437749c272e56477d42fd
[]
no_license
Anderssorby/LeanPlay
d39b15dbc3441c2be5a4ea5adf8fe70c4648737b
8fd63d98d02490060323f4c5117b9a7e8da50813
refs/heads/main
1,692,004,930,931
1,633,974,729,000
1,633,974,729,000
368,654,414
0
0
null
null
null
null
UTF-8
Lean
false
false
8,342
lean
import LeanPlay.Help import LeanPlay.LeanVersion import Blake3 namespace LeanPlay open System -------------------------------------------------------------------------------- -- # CLI Transformer Definition -------------------------------------------------------------------------------- -- Involves trickery patterned after `MacroM` -- to allow `BuildMethods` to refer to `BuildM` constant CliMethodsRefPointed : PointedType.{0} def CliMethodsRef (m : Type β†’ Type v) : Type := CliMethodsRefPointed.type abbrev CliT (m : Type β†’ Type v) := ReaderT (CliMethodsRef m) <| StateT (List String) m instance [Pure m] [Inhabited Ξ±] : Inhabited (CliT m Ξ±) := ⟨fun _ _ => pure (Inhabited.default, Inhabited.default)⟩ structure CliMethods (m : Type β†’ Type v) where longOption : String β†’ CliT m PUnit longShortOption : String β†’ CliT m PUnit shortOption : Char β†’ CliT m PUnit instance [Pure m] : Inhabited (CliMethods m) := ⟨Inhabited.default, Inhabited.default, Inhabited.default⟩ namespace CliMethodsRef unsafe def mkImp (methods : CliMethods m) : CliMethodsRef m := unsafeCast methods @[implementedBy mkImp] constant mk (methods : CliMethods m) : CliMethodsRef m := CliMethodsRefPointed.val instance : Coe (CliMethods m) (CliMethodsRef m) := ⟨mk⟩ instance [Pure m] : Inhabited (CliMethodsRef m) := ⟨mk Inhabited.default⟩ unsafe def getImp [Pure m] (self : CliMethodsRef m) : CliMethods m := unsafeCast self @[implementedBy getImp] constant get [Pure m] (self : CliMethodsRef m) : CliMethods m end CliMethodsRef -------------------------------------------------------------------------------- -- # CLI Utilities -------------------------------------------------------------------------------- namespace CliT variable [Monad m] /-- Run the CLI on the given argument list using the given methods. -/ def run (self : CliT m Ξ±) (args : List String) (methods : CliMethods m) : m Ξ± := ReaderT.run self methods |>.run' args /-- Get the remaining argument list. -/ def getArgs : CliT m (List String) := get /-- Replace the argument list. -/ def setArgs (args : List String) : CliT m PUnit := set args /-- Take the head of the remaining argument list (or none if empty). -/ def takeArg? : CliT m (Option String) := modifyGet fun | [] => (none, []) | arg :: args => (some arg, args) /-- Take the remaining argument list, leaving only an empty list. -/ def takeArgs : CliT m (List String) := modifyGet fun args => (args, []) /-- Add a string to the head of the remaining argument list. -/ def consArg (arg : String) : CliT m PUnit := modify fun args => arg :: args /-- Get the methods of this CLI. -/ def getMethods : CliT m (CliMethods m) := read >>= (Β·.get) /-- Change the methods of this CLI. -/ def adaptMethods (f : CliMethods m β†’ CliMethods m) (x : CliT m Ξ±) : CliT m Ξ± := ReaderT.adapt (fun ref => CliMethodsRef.mk <| f ref.get) x /-- Process a short option (ex. `-x` or `--`). -/ def shortOption (opt : Char) : CliT m PUnit := getMethods >>= (Β·.shortOption opt) /-- Process a short option of the form `-x=arg`. -/ def shortOptionEq (opt : String) : CliT m PUnit := do consArg (opt.drop 3); shortOption opt[1] /-- Process a short option of the form `-xarg`. -/ def shortOptionArg (opt : String) : CliT m PUnit := do consArg (opt.drop 2); shortOption opt[1] /-- Process a short option of the form `"-x arg"`. -/ def shortOptionSpace (opt : String) : CliT m PUnit := do consArg <| opt.drop 2 |>.trimLeft; shortOption opt[1] /-- Process a multiple short options grouped together (ex. `-xyz` as `x`, `y`, `z`). -/ def multiShortOption (opt : String) : CliT m PUnit := do for i in [1:opt.length] do shortOption opt[i] /-- Process a long option (ex. `--long` or `"--long a1 a2"`). -/ def longOption (opt : String) : CliT m PUnit := do getMethods >>= (Β·.longOption opt) /-- Process a long short option (ex. `-long`, `-xarg`, `-xyz`). -/ def longShortOption (opt : String) : CliT m PUnit := do getMethods >>= (Β·.longShortOption opt) /-- Process an option, short or long. An option is an argument of length > 1 starting with a dash (`-`). An option may consume additional elements of the argument list. -/ def option (opt : String) : CliT m PUnit := if opt[1] == '-' then -- `--(.*)` longOption opt else if opt.length == 2 then -- `-x` shortOption opt[1] else -- `-c(.+)` match opt[2] with | '=' => -- `-x=arg` shortOptionEq opt | ' ' => -- `"-x arg"` shortOptionSpace opt | _ => -- `-long` longShortOption opt /-- Process the leading options of the remaining argument list. -/ partial def processLeadingOptions : CliT m PUnit := do match (← getArgs) with | [] => pure () | arg :: args => let len := arg.length if len > 1 && arg[0] == '-' then -- `-(.+)` setArgs args option arg processLeadingOptions else if len == 0 then -- skip empty leading args setArgs args processLeadingOptions /-- Process every option and collect the remaining arguments into the given `Array`. -/ partial def collectArgsInto (arr : Array String) : CliT m (Array String) := do processLeadingOptions match (← takeArg?) with | some arg => collectArgsInto (arr.push arg) | none => arr /-- Process every option and collect the remaining arguments into an `Array`. -/ def collectArgs : CliT m (Array String) := collectArgsInto #[] /-- Process every option in the argument list. -/ def processOptions : CliT m PUnit := do setArgs (← collectArgs).toList end CliT structure CliOptions where wantsHelp : Bool := false dir : FilePath := "." file : FilePath := "play.lean" subArgs : List String := [] abbrev CliM := CliT (StateT CliOptions IO) namespace CliM open CliT def getDir : CliM FilePath := getThe CliOptions >>= (Β·.dir) def setDir (dir : FilePath) : CliM PUnit := modifyThe CliOptions fun st => {st with dir := dir} def getFile : CliM FilePath := getThe CliOptions >>= (Β·.file) def setFile (file : FilePath) : CliM PUnit := modifyThe CliOptions fun st => {st with file := file} def getSubArgs : CliM (List String) := getThe CliOptions >>= (Β·.subArgs) def setSubArgs (args : List String) : CliM PUnit := modifyThe CliOptions fun st => {st with subArgs := args} def getWantsHelp : CliM Bool := getThe CliOptions >>= (Β·.wantsHelp) def setWantsHelp : CliM PUnit := modifyThe CliOptions fun st => {st with wantsHelp := true} -- def getPkg (args : List String) : CliM Package := do -- Package.fromDir (← getDir) args (← getFile) def takeArg : CliM String := do match (← takeArg?) with | none => throw <| IO.userError "missing argument" | some arg => arg def takeFileArg : CliM FilePath := do match (← takeArg?) with | none => throw <| IO.userError "missing file argument" | some arg => arg def unknownShortOption (opt : Char) : CliM PUnit := throw <| IO.userError s!"unknown short option '-{opt}'" def shortOption : (opt : Char) β†’ CliM PUnit | 'h' => setWantsHelp | 'd' => do setDir (← takeFileArg) | 'f' => do setFile (← takeFileArg) | opt => unknownShortOption opt def unknownLongOption (opt : String) : CliM PUnit := throw <| IO.userError s!"unknown long option '{opt}'" def longOption : (opt : String) β†’ CliM PUnit | "--help" => setWantsHelp | "--dir" => do setDir (← takeFileArg) | "--file" => do setFile (← takeFileArg) | "--" => do setSubArgs (← takeArgs) | opt => unknownLongOption opt def command : (cmd : String) β†’ CliM PUnit | "help" => do IO.println <| help (← CliT.takeArg?) | cmd => throw <| IO.userError s!"unknown command '{cmd}'" def processArgs : CliM PUnit := do match (← getArgs) with | [] => IO.println usage | ["--version"] => IO.println version | _ => -- normal CLI processOptions match (← takeArg?) with | none => if (← getWantsHelp) then IO.println usage else throw <| IO.userError "expected command" | some cmd => if (← getWantsHelp) then IO.println (help cmd) else command cmd def run (self : CliM PUnit) (args : List String) : IO PUnit := CliT.run self args {shortOption, longOption, longShortOption := unknownLongOption} |>.run' {} end CliM def cli (args : List String) : IO PUnit := CliM.processArgs.run args
86f17ad2fe9e869835f57663b2021b3701292000
69d4931b605e11ca61881fc4f66db50a0a875e39
/src/data/dfinsupp.lean
4e30af3272b30c8a62d8aea64581ac94f5d5e769
[ "Apache-2.0" ]
permissive
abentkamp/mathlib
d9a75d291ec09f4637b0f30cc3880ffb07549ee5
5360e476391508e092b5a1e5210bd0ed22dc0755
refs/heads/master
1,682,382,954,948
1,622,106,077,000
1,622,106,077,000
149,285,665
0
0
null
null
null
null
UTF-8
Lean
false
false
49,808
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Kenny Lau -/ import algebra.module.pi import algebra.big_operators.basic import data.set.finite import group_theory.submonoid.basic /-! # Dependent functions with finite support For a non-dependent version see `data/finsupp.lean`. -/ universes u u₁ uβ‚‚ v v₁ vβ‚‚ v₃ w x y l open_locale big_operators variables (ΞΉ : Type u) (Ξ² : ΞΉ β†’ Type v) {β₁ : ΞΉ β†’ Type v₁} {Ξ²β‚‚ : ΞΉ β†’ Type vβ‚‚} namespace dfinsupp variable [Ξ  i, has_zero (Ξ² i)] structure pre : Type (max u v) := (to_fun : Ξ  i, Ξ² i) (pre_support : multiset ΞΉ) (zero : βˆ€ i, i ∈ pre_support ∨ to_fun i = 0) instance inhabited_pre : inhabited (pre ΞΉ Ξ²) := ⟨⟨λ i, 0, βˆ…, Ξ» i, or.inr rfl⟩⟩ instance : setoid (pre ΞΉ Ξ²) := { r := Ξ» x y, βˆ€ i, x.to_fun i = y.to_fun i, iseqv := ⟨λ f i, rfl, Ξ» f g H i, (H i).symm, Ξ» f g h H1 H2 i, (H1 i).trans (H2 i)⟩ } end dfinsupp variable {ΞΉ} /-- A dependent function `Ξ  i, Ξ² i` with finite support. -/ @[reducible] def dfinsupp [Ξ  i, has_zero (Ξ² i)] : Type* := quotient (dfinsupp.pre.setoid ΞΉ Ξ²) variable {Ξ²} notation `Ξ β‚€` binders `, ` r:(scoped f, dfinsupp f) := r infix ` β†’β‚š `:25 := dfinsupp namespace dfinsupp section basic variables [Ξ  i, has_zero (Ξ² i)] [Ξ  i, has_zero (β₁ i)] [Ξ  i, has_zero (Ξ²β‚‚ i)] instance : has_coe_to_fun (Ξ β‚€ i, Ξ² i) := ⟨λ _, Ξ  i, Ξ² i, Ξ» f, quotient.lift_on f pre.to_fun $ Ξ» _ _, funext⟩ instance : has_zero (Ξ β‚€ i, Ξ² i) := ⟨⟦⟨0, βˆ…, Ξ» i, or.inr rfl⟩⟧⟩ instance : inhabited (Ξ β‚€ i, Ξ² i) := ⟨0⟩ @[simp] lemma coe_zero : ⇑(0 : Ξ β‚€ i, Ξ² i) = 0 := rfl lemma zero_apply (i : ΞΉ) : (0 : Ξ β‚€ i, Ξ² i) i = 0 := rfl lemma coe_fn_injective : @function.injective (Ξ β‚€ i, Ξ² i) (Ξ  i, Ξ² i) coe_fn := Ξ» f g H, quotient.induction_onβ‚‚ f g (Ξ» _ _ H, quotient.sound H) (congr_fun H) @[ext] lemma ext {f g : Ξ β‚€ i, Ξ² i} (H : βˆ€ i, f i = g i) : f = g := coe_fn_injective (funext H) /-- The composition of `f : β₁ β†’ Ξ²β‚‚` and `g : Ξ β‚€ i, β₁ i` is `map_range f hf g : Ξ β‚€ i, Ξ²β‚‚ i`, well defined when `f 0 = 0`. This preserves the structure on `f`, and exists in various bundled forms for when `f` is itself bundled: * `dfinsupp.map_range.add_monoid_hom` * `dfinsupp.map_range.add_equiv` * `dfinsupp.map_range.linear_map` * `dfinsupp.map_range.linear_equiv` -/ def map_range (f : Ξ  i, β₁ i β†’ Ξ²β‚‚ i) (hf : βˆ€ i, f i 0 = 0) (g : Ξ β‚€ i, β₁ i) : Ξ β‚€ i, Ξ²β‚‚ i := quotient.lift_on g (Ξ» x, ⟦(⟨λ i, f i (x.1 i), x.2, Ξ» i, or.cases_on (x.3 i) or.inl $ Ξ» H, or.inr $ by rw [H, hf]⟩ : pre ΞΉ Ξ²β‚‚)⟧) $ Ξ» x y H, quotient.sound $ Ξ» i, by simp only [H i] @[simp] lemma map_range_apply (f : Ξ  i, β₁ i β†’ Ξ²β‚‚ i) (hf : βˆ€ i, f i 0 = 0) (g : Ξ β‚€ i, β₁ i) (i : ΞΉ) : map_range f hf g i = f i (g i) := quotient.induction_on g $ Ξ» x, rfl @[simp] lemma map_range_id (h : βˆ€ i, id (0 : β₁ i) = 0 := Ξ» i, rfl) (g : Ξ β‚€ (i : ΞΉ), β₁ i) : map_range (Ξ» i, (id : β₁ i β†’ β₁ i)) h g = g := by { ext, simp only [map_range_apply, id.def] } lemma map_range_comp (f : Ξ  i, β₁ i β†’ Ξ²β‚‚ i) (fβ‚‚ : Ξ  i, Ξ² i β†’ β₁ i) (hf : βˆ€ i, f i 0 = 0) (hfβ‚‚ : βˆ€ i, fβ‚‚ i 0 = 0) (h : βˆ€ i, (f i ∘ fβ‚‚ i) 0 = 0) (g : Ξ β‚€ (i : ΞΉ), Ξ² i) : map_range (Ξ» i, f i ∘ fβ‚‚ i) h g = map_range f hf (map_range fβ‚‚ hfβ‚‚ g) := by { ext, simp only [map_range_apply] } @[simp] lemma map_range_zero (f : Ξ  i, β₁ i β†’ Ξ²β‚‚ i) (hf : βˆ€ i, f i 0 = 0) : map_range f hf (0 : Ξ β‚€ i, β₁ i) = 0 := by { ext, simp only [map_range_apply, coe_zero, pi.zero_apply, hf] } /-- Let `f i` be a binary operation `β₁ i β†’ Ξ²β‚‚ i β†’ Ξ² i` such that `f i 0 0 = 0`. Then `zip_with f hf` is a binary operation `Ξ β‚€ i, β₁ i β†’ Ξ β‚€ i, Ξ²β‚‚ i β†’ Ξ β‚€ i, Ξ² i`. -/ def zip_with (f : Ξ  i, β₁ i β†’ Ξ²β‚‚ i β†’ Ξ² i) (hf : βˆ€ i, f i 0 0 = 0) (g₁ : Ξ β‚€ i, β₁ i) (gβ‚‚ : Ξ β‚€ i, Ξ²β‚‚ i) : (Ξ β‚€ i, Ξ² i) := begin refine quotient.lift_onβ‚‚ g₁ gβ‚‚ (Ξ» x y, ⟦(⟨λ i, f i (x.1 i) (y.1 i), x.2 + y.2, Ξ» i, _⟩ : pre ΞΉ Ξ²)⟧) _, { cases x.3 i with h1 h1, { left, rw multiset.mem_add, left, exact h1 }, cases y.3 i with h2 h2, { left, rw multiset.mem_add, right, exact h2 }, right, rw [h1, h2, hf] }, exact Ξ» x₁ xβ‚‚ y₁ yβ‚‚ H1 H2, quotient.sound $ Ξ» i, by simp only [H1 i, H2 i] end @[simp] lemma zip_with_apply (f : Ξ  i, β₁ i β†’ Ξ²β‚‚ i β†’ Ξ² i) (hf : βˆ€ i, f i 0 0 = 0) (g₁ : Ξ β‚€ i, β₁ i) (gβ‚‚ : Ξ β‚€ i, Ξ²β‚‚ i) (i : ΞΉ) : zip_with f hf g₁ gβ‚‚ i = f i (g₁ i) (gβ‚‚ i) := quotient.induction_onβ‚‚ g₁ gβ‚‚ $ Ξ» _ _, rfl end basic section algebra instance [Ξ  i, add_zero_class (Ξ² i)] : has_add (Ξ β‚€ i, Ξ² i) := ⟨zip_with (Ξ» _, (+)) (Ξ» _, add_zero 0)⟩ lemma add_apply [Ξ  i, add_zero_class (Ξ² i)] (g₁ gβ‚‚ : Ξ β‚€ i, Ξ² i) (i : ΞΉ) : (g₁ + gβ‚‚) i = g₁ i + gβ‚‚ i := zip_with_apply _ _ g₁ gβ‚‚ i @[simp] lemma coe_add [Ξ  i, add_zero_class (Ξ² i)] (g₁ gβ‚‚ : Ξ β‚€ i, Ξ² i) : ⇑(g₁ + gβ‚‚) = g₁ + gβ‚‚ := funext $ add_apply g₁ gβ‚‚ instance [Ξ  i, add_zero_class (Ξ² i)] : add_zero_class (Ξ β‚€ i, Ξ² i) := { zero := 0, add := (+), zero_add := Ξ» f, ext $ Ξ» i, by simp only [add_apply, zero_apply, zero_add], add_zero := Ξ» f, ext $ Ξ» i, by simp only [add_apply, zero_apply, add_zero] } instance [Ξ  i, add_monoid (Ξ² i)] : add_monoid (Ξ β‚€ i, Ξ² i) := { add_monoid . zero := 0, add := (+), add_assoc := Ξ» f g h, ext $ Ξ» i, by simp only [add_apply, add_assoc], .. dfinsupp.add_zero_class } /-- Coercion from a `dfinsupp` to a pi type is an `add_monoid_hom`. -/ def coe_fn_add_monoid_hom [Ξ  i, add_zero_class (Ξ² i)] : (Ξ β‚€ i, Ξ² i) β†’+ (Ξ  i, Ξ² i) := { to_fun := coe_fn, map_zero' := coe_zero, map_add' := coe_add } /-- Evaluation at a point is an `add_monoid_hom`. This is the finitely-supported version of `pi.eval_add_monoid_hom`. -/ def eval_add_monoid_hom [Ξ  i, add_zero_class (Ξ² i)] (i : ΞΉ) : (Ξ β‚€ i, Ξ² i) β†’+ Ξ² i := (pi.eval_add_monoid_hom Ξ² i).comp coe_fn_add_monoid_hom instance is_add_monoid_hom [Ξ  i, add_zero_class (Ξ² i)] {i : ΞΉ} : is_add_monoid_hom (Ξ» g : Ξ β‚€ i : ΞΉ, Ξ² i, g i) := (eval_add_monoid_hom i).is_add_monoid_hom instance [Ξ  i, add_group (Ξ² i)] : has_neg (Ξ β‚€ i, Ξ² i) := ⟨λ f, f.map_range (Ξ» _, has_neg.neg) (Ξ» _, neg_zero)⟩ instance [Ξ  i, add_comm_monoid (Ξ² i)] : add_comm_monoid (Ξ β‚€ i, Ξ² i) := { add_comm := Ξ» f g, ext $ Ξ» i, by simp only [add_apply, add_comm], .. dfinsupp.add_monoid } @[simp] lemma coe_finset_sum {Ξ±} [Ξ  i, add_comm_monoid (Ξ² i)] (s : finset Ξ±) (g : Ξ± β†’ Ξ β‚€ i, Ξ² i) : ⇑(βˆ‘ a in s, g a) = βˆ‘ a in s, g a := (coe_fn_add_monoid_hom : _ β†’+ (Ξ  i, Ξ² i)).map_sum g s @[simp] lemma finset_sum_apply {Ξ±} [Ξ  i, add_comm_monoid (Ξ² i)] (s : finset Ξ±) (g : Ξ± β†’ Ξ β‚€ i, Ξ² i) (i : ΞΉ) : (βˆ‘ a in s, g a) i = βˆ‘ a in s, g a i := (eval_add_monoid_hom i : _ β†’+ Ξ² i).map_sum g s lemma neg_apply [Ξ  i, add_group (Ξ² i)] (g : Ξ β‚€ i, Ξ² i) (i : ΞΉ) : (- g) i = - g i := map_range_apply _ _ g i @[simp] lemma coe_neg [Ξ  i, add_group (Ξ² i)] (g : Ξ β‚€ i, Ξ² i) : ⇑(- g) = - g := funext $ neg_apply g instance [Ξ  i, add_group (Ξ² i)] : add_group (Ξ β‚€ i, Ξ² i) := { add_left_neg := Ξ» f, ext $ Ξ» i, by simp only [add_apply, neg_apply, zero_apply, add_left_neg], .. dfinsupp.add_monoid, .. (infer_instance : has_neg (Ξ β‚€ i, Ξ² i)) } lemma sub_apply [Ξ  i, add_group (Ξ² i)] (g₁ gβ‚‚ : Ξ β‚€ i, Ξ² i) (i : ΞΉ) : (g₁ - gβ‚‚) i = g₁ i - gβ‚‚ i := by rw [sub_eq_add_neg]; simp [sub_eq_add_neg] @[simp] lemma coe_sub [Ξ  i, add_group (Ξ² i)] (g₁ gβ‚‚ : Ξ β‚€ i, Ξ² i) : ⇑(g₁ - gβ‚‚) = g₁ - gβ‚‚ := funext $ sub_apply g₁ gβ‚‚ instance [Ξ  i, add_comm_group (Ξ² i)] : add_comm_group (Ξ β‚€ i, Ξ² i) := { add_comm := Ξ» f g, ext $ Ξ» i, by simp only [add_apply, add_comm], ..dfinsupp.add_group } /-- Dependent functions with finite support inherit a semiring action from an action on each coordinate. -/ instance {Ξ³ : Type w} [monoid Ξ³] [Ξ  i, add_monoid (Ξ² i)] [Ξ  i, distrib_mul_action Ξ³ (Ξ² i)] : has_scalar Ξ³ (Ξ β‚€ i, Ξ² i) := ⟨λc v, v.map_range (Ξ» _, (β€’) c) (Ξ» _, smul_zero _)⟩ lemma smul_apply {Ξ³ : Type w} [monoid Ξ³] [Ξ  i, add_monoid (Ξ² i)] [Ξ  i, distrib_mul_action Ξ³ (Ξ² i)] (b : Ξ³) (v : Ξ β‚€ i, Ξ² i) (i : ΞΉ) : (b β€’ v) i = b β€’ (v i) := map_range_apply _ _ v i @[simp] lemma coe_smul {Ξ³ : Type w} [monoid Ξ³] [Ξ  i, add_monoid (Ξ² i)] [Ξ  i, distrib_mul_action Ξ³ (Ξ² i)] (b : Ξ³) (v : Ξ β‚€ i, Ξ² i) : ⇑(b β€’ v) = b β€’ v := funext $ smul_apply b v instance {Ξ³ : Type w} {Ξ΄ : Type*} [monoid Ξ³] [monoid Ξ΄] [Ξ  i, add_monoid (Ξ² i)] [Ξ  i, distrib_mul_action Ξ³ (Ξ² i)] [Ξ  i, distrib_mul_action Ξ΄ (Ξ² i)] [Ξ  i, smul_comm_class Ξ³ Ξ΄ (Ξ² i)] : smul_comm_class Ξ³ Ξ΄ (Ξ β‚€ i, Ξ² i) := { smul_comm := Ξ» r s m, ext $ Ξ» i, by simp only [smul_apply, smul_comm r s (m i)] } instance {Ξ³ : Type w} {Ξ΄ : Type*} [monoid Ξ³] [monoid Ξ΄] [Ξ  i, add_monoid (Ξ² i)] [Ξ  i, distrib_mul_action Ξ³ (Ξ² i)] [Ξ  i, distrib_mul_action Ξ΄ (Ξ² i)] [has_scalar Ξ³ Ξ΄] [Ξ  i, is_scalar_tower Ξ³ Ξ΄ (Ξ² i)] : is_scalar_tower Ξ³ Ξ΄ (Ξ β‚€ i, Ξ² i) := { smul_assoc := Ξ» r s m, ext $ Ξ» i, by simp only [smul_apply, smul_assoc r s (m i)] } /-- Dependent functions with finite support inherit a `distrib_mul_action` structure from such a structure on each coordinate. -/ instance {Ξ³ : Type w} [monoid Ξ³] [Ξ  i, add_monoid (Ξ² i)] [Ξ  i, distrib_mul_action Ξ³ (Ξ² i)] : distrib_mul_action Ξ³ (Ξ β‚€ i, Ξ² i) := { smul_zero := Ξ» c, ext $ Ξ» i, by simp only [smul_apply, smul_zero, zero_apply], smul_add := Ξ» c x y, ext $ Ξ» i, by simp only [add_apply, smul_apply, smul_add], one_smul := Ξ» x, ext $ Ξ» i, by simp only [smul_apply, one_smul], mul_smul := Ξ» r s x, ext $ Ξ» i, by simp only [smul_apply, smul_smul], ..dfinsupp.has_scalar } /-- Dependent functions with finite support inherit a module structure from such a structure on each coordinate. -/ instance {Ξ³ : Type w} [semiring Ξ³] [Ξ  i, add_comm_monoid (Ξ² i)] [Ξ  i, module Ξ³ (Ξ² i)] : module Ξ³ (Ξ β‚€ i, Ξ² i) := { zero_smul := Ξ» c, ext $ Ξ» i, by simp only [smul_apply, zero_smul, zero_apply], add_smul := Ξ» c x y, ext $ Ξ» i, by simp only [add_apply, smul_apply, add_smul], ..dfinsupp.distrib_mul_action } end algebra section filter_and_subtype_domain /-- `filter p f` is the function which is `f i` if `p i` is true and 0 otherwise. -/ def filter [Ξ  i, has_zero (Ξ² i)] (p : ΞΉ β†’ Prop) [decidable_pred p] (f : Ξ β‚€ i, Ξ² i) : Ξ β‚€ i, Ξ² i := quotient.lift_on f (Ξ» x, ⟦(⟨λ i, if p i then x.1 i else 0, x.2, Ξ» i, or.cases_on (x.3 i) or.inl $ Ξ» H, or.inr $ by rw [H, if_t_t]⟩ : pre ΞΉ Ξ²)⟧) $ Ξ» x y H, quotient.sound $ Ξ» i, by simp only [H i] @[simp] lemma filter_apply [Ξ  i, has_zero (Ξ² i)] (p : ΞΉ β†’ Prop) [decidable_pred p] (i : ΞΉ) (f : Ξ β‚€ i, Ξ² i) : f.filter p i = if p i then f i else 0 := quotient.induction_on f $ Ξ» x, rfl lemma filter_apply_pos [Ξ  i, has_zero (Ξ² i)] {p : ΞΉ β†’ Prop} [decidable_pred p] (f : Ξ β‚€ i, Ξ² i) {i : ΞΉ} (h : p i) : f.filter p i = f i := by simp only [filter_apply, if_pos h] lemma filter_apply_neg [Ξ  i, has_zero (Ξ² i)] {p : ΞΉ β†’ Prop} [decidable_pred p] (f : Ξ β‚€ i, Ξ² i) {i : ΞΉ} (h : Β¬ p i) : f.filter p i = 0 := by simp only [filter_apply, if_neg h] lemma filter_pos_add_filter_neg [Ξ  i, add_zero_class (Ξ² i)] (f : Ξ β‚€ i, Ξ² i) (p : ΞΉ β†’ Prop) [decidable_pred p] : f.filter p + f.filter (Ξ»i, Β¬ p i) = f := ext $ Ξ» i, by simp only [add_apply, filter_apply]; split_ifs; simp only [add_zero, zero_add] /-- `subtype_domain p f` is the restriction of the finitely supported function `f` to the subtype `p`. -/ def subtype_domain [Ξ  i, has_zero (Ξ² i)] (p : ΞΉ β†’ Prop) [decidable_pred p] (f : Ξ β‚€ i, Ξ² i) : Ξ β‚€ i : subtype p, Ξ² i := begin fapply quotient.lift_on f, { intro x, refine ⟦⟨λ i, x.1 (i : ΞΉ), (x.2.filter p).attach.map $ Ξ» j, ⟨j, (multiset.mem_filter.1 j.2).2⟩, _⟩⟧, refine Ξ» i, or.cases_on (x.3 i) (Ξ» H, _) or.inr, left, rw multiset.mem_map, refine ⟨⟨i, multiset.mem_filter.2 ⟨H, i.2⟩⟩, _, subtype.eta _ _⟩, apply multiset.mem_attach }, intros x y H, exact quotient.sound (Ξ» i, H i) end @[simp] lemma subtype_domain_zero [Ξ  i, has_zero (Ξ² i)] {p : ΞΉ β†’ Prop} [decidable_pred p] : subtype_domain p (0 : Ξ β‚€ i, Ξ² i) = 0 := rfl @[simp] lemma subtype_domain_apply [Ξ  i, has_zero (Ξ² i)] {p : ΞΉ β†’ Prop} [decidable_pred p] {i : subtype p} {v : Ξ β‚€ i, Ξ² i} : (subtype_domain p v) i = v i := quotient.induction_on v $ Ξ» x, rfl @[simp] lemma subtype_domain_add [Ξ  i, add_zero_class (Ξ² i)] {p : ΞΉ β†’ Prop} [decidable_pred p] {v v' : Ξ β‚€ i, Ξ² i} : (v + v').subtype_domain p = v.subtype_domain p + v'.subtype_domain p := ext $ Ξ» i, by simp only [add_apply, subtype_domain_apply] instance subtype_domain.is_add_monoid_hom [Ξ  i, add_zero_class (Ξ² i)] {p : ΞΉ β†’ Prop} [decidable_pred p] : is_add_monoid_hom (subtype_domain p : (Ξ β‚€ i : ΞΉ, Ξ² i) β†’ Ξ β‚€ i : subtype p, Ξ² i) := { map_add := Ξ» _ _, subtype_domain_add, map_zero := subtype_domain_zero } @[simp] lemma subtype_domain_neg [Ξ  i, add_group (Ξ² i)] {p : ΞΉ β†’ Prop} [decidable_pred p] {v : Ξ β‚€ i, Ξ² i} : (- v).subtype_domain p = - v.subtype_domain p := ext $ Ξ» i, by simp only [neg_apply, subtype_domain_apply] @[simp] lemma subtype_domain_sub [Ξ  i, add_group (Ξ² i)] {p : ΞΉ β†’ Prop} [decidable_pred p] {v v' : Ξ β‚€ i, Ξ² i} : (v - v').subtype_domain p = v.subtype_domain p - v'.subtype_domain p := ext $ Ξ» i, by simp only [sub_apply, subtype_domain_apply] end filter_and_subtype_domain variable [dec : decidable_eq ΞΉ] include dec section basic variable [Ξ  i, has_zero (Ξ² i)] omit dec lemma finite_support (f : Ξ β‚€ i, Ξ² i) : set.finite {i | f i β‰  0} := begin classical, exact quotient.induction_on f (Ξ» x, x.2.to_finset.finite_to_set.subset (Ξ» i H, multiset.mem_to_finset.2 ((x.3 i).resolve_right H))) end include dec /-- Create an element of `Ξ β‚€ i, Ξ² i` from a finset `s` and a function `x` defined on this `finset`. -/ def mk (s : finset ΞΉ) (x : Ξ  i : (↑s : set ΞΉ), Ξ² (i : ΞΉ)) : Ξ β‚€ i, Ξ² i := ⟦⟨λ i, if H : i ∈ s then x ⟨i, H⟩ else 0, s.1, Ξ» i, if H : i ∈ s then or.inl H else or.inr $ dif_neg H⟩⟧ @[simp] lemma mk_apply {s : finset ΞΉ} {x : Ξ  i : (↑s : set ΞΉ), Ξ² i} {i : ΞΉ} : (mk s x : Ξ  i, Ξ² i) i = if H : i ∈ s then x ⟨i, H⟩ else 0 := rfl theorem mk_injective (s : finset ΞΉ) : function.injective (@mk ΞΉ Ξ² _ _ s) := begin intros x y H, ext i, have h1 : (mk s x : Ξ  i, Ξ² i) i = (mk s y : Ξ  i, Ξ² i) i, {rw H}, cases i with i hi, change i ∈ s at hi, dsimp only [mk_apply, subtype.coe_mk] at h1, simpa only [dif_pos hi] using h1 end /-- The function `single i b : Ξ β‚€ i, Ξ² i` sends `i` to `b` and all other points to `0`. -/ def single (i : ΞΉ) (b : Ξ² i) : Ξ β‚€ i, Ξ² i := mk {i} $ Ξ» j, eq.rec_on (finset.mem_singleton.1 j.prop).symm b @[simp] lemma single_apply {i i' b} : (single i b : Ξ β‚€ i, Ξ² i) i' = (if h : i = i' then eq.rec_on h b else 0) := begin dsimp only [single], by_cases h : i = i', { have h1 : i' ∈ ({i} : finset ΞΉ) := finset.mem_singleton.2 h.symm, simp only [mk_apply, dif_pos h, dif_pos h1], refl }, { have h1 : i' βˆ‰ ({i} : finset ΞΉ) := finset.not_mem_singleton.2 (ne.symm h), simp only [mk_apply, dif_neg h, dif_neg h1] } end @[simp] lemma single_zero {i} : (single i 0 : Ξ β‚€ i, Ξ² i) = 0 := quotient.sound $ Ξ» j, if H : j ∈ ({i} : finset _) then by dsimp only; rw [dif_pos H]; cases finset.mem_singleton.1 H; refl else dif_neg H @[simp] lemma single_eq_same {i b} : (single i b : Ξ β‚€ i, Ξ² i) i = b := by simp only [single_apply, dif_pos rfl] lemma single_eq_of_ne {i i' b} (h : i β‰  i') : (single i b : Ξ β‚€ i, Ξ² i) i' = 0 := by simp only [single_apply, dif_neg h] lemma single_injective {i} : function.injective (single i : Ξ² i β†’ Ξ β‚€ i, Ξ² i) := Ξ» x y H, congr_fun (mk_injective _ H) ⟨i, by simp⟩ /-- Like `finsupp.single_eq_single_iff`, but with a `heq` due to dependent types -/ lemma single_eq_single_iff (i j : ΞΉ) (xi : Ξ² i) (xj : Ξ² j) : dfinsupp.single i xi = dfinsupp.single j xj ↔ i = j ∧ xi == xj ∨ xi = 0 ∧ xj = 0 := begin split, { intro h, by_cases hij : i = j, { subst hij, exact or.inl ⟨rfl, heq_of_eq (dfinsupp.single_injective h)⟩, }, { have h_coe : ⇑(dfinsupp.single i xi) = dfinsupp.single j xj := congr_arg coe_fn h, have hci := congr_fun h_coe i, have hcj := congr_fun h_coe j, rw dfinsupp.single_eq_same at hci hcj, rw dfinsupp.single_eq_of_ne (ne.symm hij) at hci, rw dfinsupp.single_eq_of_ne (hij) at hcj, exact or.inr ⟨hci, hcj.symm⟩, }, }, { rintros (⟨hi, hxi⟩ | ⟨hi, hj⟩), { subst hi, rw eq_of_heq hxi, }, { rw [hi, hj, dfinsupp.single_zero, dfinsupp.single_zero], }, }, end /-- Equality of sigma types is sufficient (but not necessary) to show equality of `dfinsupp`s. -/ lemma single_eq_of_sigma_eq {i j} {xi : Ξ² i} {xj : Ξ² j} (h : (⟨i, xi⟩ : sigma Ξ²) = ⟨j, xj⟩) : dfinsupp.single i xi = dfinsupp.single j xj := by { cases h, refl } /-- Redefine `f i` to be `0`. -/ def erase (i : ΞΉ) (f : Ξ β‚€ i, Ξ² i) : Ξ β‚€ i, Ξ² i := quotient.lift_on f (Ξ» x, ⟦(⟨λ j, if j = i then 0 else x.1 j, x.2, Ξ» j, or.cases_on (x.3 j) or.inl $ Ξ» H, or.inr $ by simp only [H, if_t_t]⟩ : pre ΞΉ Ξ²)⟧) $ Ξ» x y H, quotient.sound $ Ξ» j, if h : j = i then by simp only [if_pos h] else by simp only [if_neg h, H j] @[simp] lemma erase_apply {i j : ΞΉ} {f : Ξ β‚€ i, Ξ² i} : (f.erase i) j = if j = i then 0 else f j := quotient.induction_on f $ Ξ» x, rfl @[simp] lemma erase_same {i : ΞΉ} {f : Ξ β‚€ i, Ξ² i} : (f.erase i) i = 0 := by simp lemma erase_ne {i i' : ΞΉ} {f : Ξ β‚€ i, Ξ² i} (h : i' β‰  i) : (f.erase i) i' = f i' := by simp [h] end basic section add_monoid variable [Ξ  i, add_zero_class (Ξ² i)] @[simp] lemma single_add {i : ΞΉ} {b₁ bβ‚‚ : Ξ² i} : single i (b₁ + bβ‚‚) = single i b₁ + single i bβ‚‚ := ext $ assume i', begin by_cases h : i = i', { subst h, simp only [add_apply, single_eq_same] }, { simp only [add_apply, single_eq_of_ne h, zero_add] } end variables (Ξ²) /-- `dfinsupp.single` as an `add_monoid_hom`. -/ @[simps] def single_add_hom (i : ΞΉ) : Ξ² i β†’+ Ξ β‚€ i, Ξ² i := { to_fun := single i, map_zero' := single_zero, map_add' := Ξ» _ _, single_add } variables {Ξ²} lemma single_add_erase {i : ΞΉ} {f : Ξ β‚€ i, Ξ² i} : single i (f i) + f.erase i = f := ext $ Ξ» i', if h : i = i' then by subst h; simp only [add_apply, single_apply, erase_apply, dif_pos rfl, if_pos, add_zero] else by simp only [add_apply, single_apply, erase_apply, dif_neg h, if_neg (ne.symm h), zero_add] lemma erase_add_single {i : ΞΉ} {f : Ξ β‚€ i, Ξ² i} : f.erase i + single i (f i) = f := ext $ Ξ» i', if h : i = i' then by subst h; simp only [add_apply, single_apply, erase_apply, dif_pos rfl, if_pos, zero_add] else by simp only [add_apply, single_apply, erase_apply, dif_neg h, if_neg (ne.symm h), add_zero] protected theorem induction {p : (Ξ β‚€ i, Ξ² i) β†’ Prop} (f : Ξ β‚€ i, Ξ² i) (h0 : p 0) (ha : βˆ€i b (f : Ξ β‚€ i, Ξ² i), f i = 0 β†’ b β‰  0 β†’ p f β†’ p (single i b + f)) : p f := begin refine quotient.induction_on f (Ξ» x, _), cases x with f s H, revert f H, apply multiset.induction_on s, { intros f H, convert h0, ext i, exact (H i).resolve_left id }, intros i s ih f H, by_cases H1 : i ∈ s, { have H2 : βˆ€ j, j ∈ s ∨ f j = 0, { intro j, cases H j with H2 H2, { cases multiset.mem_cons.1 H2 with H3 H3, { left, rw H3, exact H1 }, { left, exact H3 } }, right, exact H2 }, have H3 : (⟦{to_fun := f, pre_support := i ::β‚˜ s, zero := H}⟧ : Ξ β‚€ i, Ξ² i) = ⟦{to_fun := f, pre_support := s, zero := H2}⟧, { exact quotient.sound (Ξ» i, rfl) }, rw H3, apply ih }, have H2 : p (erase i ⟦{to_fun := f, pre_support := i ::β‚˜ s, zero := H}⟧), { dsimp only [erase, quotient.lift_on_mk], have H2 : βˆ€ j, j ∈ s ∨ ite (j = i) 0 (f j) = 0, { intro j, cases H j with H2 H2, { cases multiset.mem_cons.1 H2 with H3 H3, { right, exact if_pos H3 }, { left, exact H3 } }, right, split_ifs; [refl, exact H2] }, have H3 : (⟦{to_fun := Ξ» (j : ΞΉ), ite (j = i) 0 (f j), pre_support := i ::β‚˜ s, zero := _}⟧ : Ξ β‚€ i, Ξ² i) = ⟦{to_fun := Ξ» (j : ΞΉ), ite (j = i) 0 (f j), pre_support := s, zero := H2}⟧ := quotient.sound (Ξ» i, rfl), rw H3, apply ih }, have H3 : single i _ + _ = (⟦{to_fun := f, pre_support := i ::β‚˜ s, zero := H}⟧ : Ξ β‚€ i, Ξ² i) := single_add_erase, rw ← H3, change p (single i (f i) + _), cases classical.em (f i = 0) with h h, { rw [h, single_zero, zero_add], exact H2 }, refine ha _ _ _ _ h H2, rw erase_same end lemma inductionβ‚‚ {p : (Ξ β‚€ i, Ξ² i) β†’ Prop} (f : Ξ β‚€ i, Ξ² i) (h0 : p 0) (ha : βˆ€i b (f : Ξ β‚€ i, Ξ² i), f i = 0 β†’ b β‰  0 β†’ p f β†’ p (f + single i b)) : p f := dfinsupp.induction f h0 $ Ξ» i b f h1 h2 h3, have h4 : f + single i b = single i b + f, { ext j, by_cases H : i = j, { subst H, simp [h1] }, { simp [H] } }, eq.rec_on h4 $ ha i b f h1 h2 h3 @[simp] lemma add_closure_Union_range_single : add_submonoid.closure (⋃ i : ΞΉ, set.range (single i : Ξ² i β†’ (Ξ β‚€ i, Ξ² i))) = ⊀ := top_unique $ Ξ» x hx, (begin apply dfinsupp.induction x, exact add_submonoid.zero_mem _, exact Ξ» a b f ha hb hf, add_submonoid.add_mem _ (add_submonoid.subset_closure $ set.mem_Union.2 ⟨a, set.mem_range_self _⟩) hf end) /-- If two additive homomorphisms from `Ξ β‚€ i, Ξ² i` are equal on each `single a b`, then they are equal. -/ lemma add_hom_ext {Ξ³ : Type w} [add_zero_class Ξ³] ⦃f g : (Ξ β‚€ i, Ξ² i) β†’+ γ⦄ (H : βˆ€ (i : ΞΉ) (y : Ξ² i), f (single i y) = g (single i y)) : f = g := begin refine add_monoid_hom.eq_of_eq_on_mdense add_closure_Union_range_single (Ξ» f hf, _), simp only [set.mem_Union, set.mem_range] at hf, rcases hf with ⟨x, y, rfl⟩, apply H end /-- If two additive homomorphisms from `Ξ β‚€ i, Ξ² i` are equal on each `single a b`, then they are equal. See note [partially-applied ext lemmas]. -/ @[ext] lemma add_hom_ext' {Ξ³ : Type w} [add_zero_class Ξ³] ⦃f g : (Ξ β‚€ i, Ξ² i) β†’+ γ⦄ (H : βˆ€ x, f.comp (single_add_hom Ξ² x) = g.comp (single_add_hom Ξ² x)) : f = g := add_hom_ext $ Ξ» x, add_monoid_hom.congr_fun (H x) end add_monoid @[simp] lemma mk_add [Ξ  i, add_zero_class (Ξ² i)] {s : finset ΞΉ} {x y : Ξ  i : (↑s : set ΞΉ), Ξ² i} : mk s (x + y) = mk s x + mk s y := ext $ Ξ» i, by simp only [add_apply, mk_apply]; split_ifs; [refl, rw zero_add] @[simp] lemma mk_zero [Ξ  i, has_zero (Ξ² i)] {s : finset ΞΉ} : mk s (0 : Ξ  i : (↑s : set ΞΉ), Ξ² i.1) = 0 := ext $ Ξ» i, by simp only [mk_apply]; split_ifs; refl @[simp] lemma mk_neg [Ξ  i, add_group (Ξ² i)] {s : finset ΞΉ} {x : Ξ  i : (↑s : set ΞΉ), Ξ² i.1} : mk s (-x) = -mk s x := ext $ Ξ» i, by simp only [neg_apply, mk_apply]; split_ifs; [refl, rw neg_zero] @[simp] lemma mk_sub [Ξ  i, add_group (Ξ² i)] {s : finset ΞΉ} {x y : Ξ  i : (↑s : set ΞΉ), Ξ² i.1} : mk s (x - y) = mk s x - mk s y := ext $ Ξ» i, by simp only [sub_apply, mk_apply]; split_ifs; [refl, rw sub_zero] instance [Ξ  i, add_group (Ξ² i)] {s : finset ΞΉ} : is_add_group_hom (@mk ΞΉ Ξ² _ _ s) := { map_add := Ξ» _ _, mk_add } section variables (Ξ³ : Type w) [semiring Ξ³] [Ξ  i, add_comm_monoid (Ξ² i)] [Ξ  i, module Ξ³ (Ξ² i)] include Ξ³ @[simp] lemma mk_smul {s : finset ΞΉ} {c : Ξ³} (x : Ξ  i : (↑s : set ΞΉ), Ξ² i.1) : mk s (c β€’ x) = c β€’ mk s x := ext $ Ξ» i, by simp only [smul_apply, mk_apply]; split_ifs; [refl, rw smul_zero] @[simp] lemma single_smul {i : ΞΉ} {c : Ξ³} {x : Ξ² i} : single i (c β€’ x) = c β€’ single i x := ext $ Ξ» i, by simp only [smul_apply, single_apply]; split_ifs; [cases h, rw smul_zero]; refl end section support_basic variables [Ξ  i, has_zero (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] /-- Set `{i | f x β‰  0}` as a `finset`. -/ def support (f : Ξ β‚€ i, Ξ² i) : finset ΞΉ := quotient.lift_on f (Ξ» x, x.2.to_finset.filter $ Ξ» i, x.1 i β‰  0) $ begin intros x y Hxy, ext i, split, { intro H, rcases finset.mem_filter.1 H with ⟨h1, h2⟩, rw Hxy i at h2, exact finset.mem_filter.2 ⟨multiset.mem_to_finset.2 $ (y.3 i).resolve_right h2, h2⟩ }, { intro H, rcases finset.mem_filter.1 H with ⟨h1, h2⟩, rw ← Hxy i at h2, exact finset.mem_filter.2 ⟨multiset.mem_to_finset.2 $ (x.3 i).resolve_right h2, h2⟩ }, end @[simp] theorem support_mk_subset {s : finset ΞΉ} {x : Ξ  i : (↑s : set ΞΉ), Ξ² i.1} : (mk s x).support βŠ† s := Ξ» i H, multiset.mem_to_finset.1 (finset.mem_filter.1 H).1 @[simp] theorem mem_support_to_fun (f : Ξ β‚€ i, Ξ² i) (i) : i ∈ f.support ↔ f i β‰  0 := begin refine quotient.induction_on f (Ξ» x, _), dsimp only [support, quotient.lift_on_mk], rw [finset.mem_filter, multiset.mem_to_finset], exact and_iff_right_of_imp (x.3 i).resolve_right end theorem eq_mk_support (f : Ξ β‚€ i, Ξ² i) : f = mk f.support (Ξ» i, f i) := begin change f = mk f.support (Ξ» i, f i.1), ext i, by_cases h : f i β‰  0; [skip, rw [not_not] at h]; simp [h] end @[simp] lemma support_zero : (0 : Ξ β‚€ i, Ξ² i).support = βˆ… := rfl lemma mem_support_iff (f : Ξ β‚€ i, Ξ² i) : βˆ€i:ΞΉ, i ∈ f.support ↔ f i β‰  0 := f.mem_support_to_fun @[simp] lemma support_eq_empty {f : Ξ β‚€ i, Ξ² i} : f.support = βˆ… ↔ f = 0 := ⟨λ H, ext $ by simpa [finset.ext_iff] using H, by simp {contextual:=tt}⟩ instance decidable_zero : decidable_pred (eq (0 : Ξ β‚€ i, Ξ² i)) := Ξ» f, decidable_of_iff _ $ support_eq_empty.trans eq_comm lemma support_subset_iff {s : set ΞΉ} {f : Ξ β‚€ i, Ξ² i} : ↑f.support βŠ† s ↔ (βˆ€iβˆ‰s, f i = 0) := by simp [set.subset_def]; exact forall_congr (assume i, not_imp_comm) lemma support_single_ne_zero {i : ΞΉ} {b : Ξ² i} (hb : b β‰  0) : (single i b).support = {i} := begin ext j, by_cases h : i = j, { subst h, simp [hb] }, simp [ne.symm h, h] end lemma support_single_subset {i : ΞΉ} {b : Ξ² i} : (single i b).support βŠ† {i} := support_mk_subset section map_range_and_zip_with variables [Ξ  i, has_zero (β₁ i)] [Ξ  i, has_zero (Ξ²β‚‚ i)] lemma map_range_def [Ξ  i (x : β₁ i), decidable (x β‰  0)] {f : Ξ  i, β₁ i β†’ Ξ²β‚‚ i} {hf : βˆ€ i, f i 0 = 0} {g : Ξ β‚€ i, β₁ i} : map_range f hf g = mk g.support (Ξ» i, f i.1 (g i.1)) := begin ext i, by_cases h : g i β‰  0; simp at h; simp [h, hf] end @[simp] lemma map_range_single {f : Ξ  i, β₁ i β†’ Ξ²β‚‚ i} {hf : βˆ€ i, f i 0 = 0} {i : ΞΉ} {b : β₁ i} : map_range f hf (single i b) = single i (f i b) := dfinsupp.ext $ Ξ» i', by by_cases i = i'; [{subst i', simp}, simp [h, hf]] variables [Ξ  i (x : β₁ i), decidable (x β‰  0)] [Ξ  i (x : Ξ²β‚‚ i), decidable (x β‰  0)] lemma support_map_range {f : Ξ  i, β₁ i β†’ Ξ²β‚‚ i} {hf : βˆ€ i, f i 0 = 0} {g : Ξ β‚€ i, β₁ i} : (map_range f hf g).support βŠ† g.support := by simp [map_range_def] lemma zip_with_def {f : Ξ  i, β₁ i β†’ Ξ²β‚‚ i β†’ Ξ² i} {hf : βˆ€ i, f i 0 0 = 0} {g₁ : Ξ β‚€ i, β₁ i} {gβ‚‚ : Ξ β‚€ i, Ξ²β‚‚ i} : zip_with f hf g₁ gβ‚‚ = mk (g₁.support βˆͺ gβ‚‚.support) (Ξ» i, f i.1 (g₁ i.1) (gβ‚‚ i.1)) := begin ext i, by_cases h1 : g₁ i β‰  0; by_cases h2 : gβ‚‚ i β‰  0; simp only [not_not, ne.def] at h1 h2; simp [h1, h2, hf] end lemma support_zip_with {f : Ξ  i, β₁ i β†’ Ξ²β‚‚ i β†’ Ξ² i} {hf : βˆ€ i, f i 0 0 = 0} {g₁ : Ξ β‚€ i, β₁ i} {gβ‚‚ : Ξ β‚€ i, Ξ²β‚‚ i} : (zip_with f hf g₁ gβ‚‚).support βŠ† g₁.support βˆͺ gβ‚‚.support := by simp [zip_with_def] end map_range_and_zip_with lemma erase_def (i : ΞΉ) (f : Ξ β‚€ i, Ξ² i) : f.erase i = mk (f.support.erase i) (Ξ» j, f j.1) := by { ext j, by_cases h1 : j = i; by_cases h2 : f j β‰  0; simp at h2; simp [h1, h2] } @[simp] lemma support_erase (i : ΞΉ) (f : Ξ β‚€ i, Ξ² i) : (f.erase i).support = f.support.erase i := by { ext j, by_cases h1 : j = i; by_cases h2 : f j β‰  0; simp at h2; simp [h1, h2] } section filter_and_subtype_domain variables {p : ΞΉ β†’ Prop} [decidable_pred p] lemma filter_def (f : Ξ β‚€ i, Ξ² i) : f.filter p = mk (f.support.filter p) (Ξ» i, f i.1) := by ext i; by_cases h1 : p i; by_cases h2 : f i β‰  0; simp at h2; simp [h1, h2] @[simp] lemma support_filter (f : Ξ β‚€ i, Ξ² i) : (f.filter p).support = f.support.filter p := by ext i; by_cases h : p i; simp [h] lemma subtype_domain_def (f : Ξ β‚€ i, Ξ² i) : f.subtype_domain p = mk (f.support.subtype p) (Ξ» i, f i) := by ext i; by_cases h1 : p i; by_cases h2 : f i β‰  0; try {simp at h2}; dsimp; simp [h1, h2, ← subtype.val_eq_coe] @[simp] lemma support_subtype_domain {f : Ξ β‚€ i, Ξ² i} : (subtype_domain p f).support = f.support.subtype p := by ext i; by_cases h1 : p i; by_cases h2 : f i β‰  0; try {simp at h2}; dsimp; simp [h1, h2] end filter_and_subtype_domain end support_basic lemma support_add [Ξ  i, add_zero_class (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] {g₁ gβ‚‚ : Ξ β‚€ i, Ξ² i} : (g₁ + gβ‚‚).support βŠ† g₁.support βˆͺ gβ‚‚.support := support_zip_with @[simp] lemma support_neg [Ξ  i, add_group (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] {f : Ξ β‚€ i, Ξ² i} : support (-f) = support f := by ext i; simp lemma support_smul {Ξ³ : Type w} [semiring Ξ³] [Ξ  i, add_comm_monoid (Ξ² i)] [Ξ  i, module Ξ³ (Ξ² i)] [Ξ  ( i : ΞΉ) (x : Ξ² i), decidable (x β‰  0)] (b : Ξ³) (v : Ξ β‚€ i, Ξ² i) : (b β€’ v).support βŠ† v.support := support_map_range instance [Ξ  i, has_zero (Ξ² i)] [Ξ  i, decidable_eq (Ξ² i)] : decidable_eq (Ξ β‚€ i, Ξ² i) := assume f g, decidable_of_iff (f.support = g.support ∧ (βˆ€i∈f.support, f i = g i)) ⟨assume ⟨h₁, hβ‚‚βŸ©, ext $ assume i, if h : i ∈ f.support then hβ‚‚ i h else have hf : f i = 0, by rwa [f.mem_support_iff, not_not] at h, have hg : g i = 0, by rwa [h₁, g.mem_support_iff, not_not] at h, by rw [hf, hg], by intro h; subst h; simp⟩ section prod_and_sum variables {Ξ³ : Type w} -- [to_additive sum] for dfinsupp.prod doesn't work, the equation lemmas are not generated /-- `sum f g` is the sum of `g i (f i)` over the support of `f`. -/ def sum [Ξ  i, has_zero (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [add_comm_monoid Ξ³] (f : Ξ β‚€ i, Ξ² i) (g : Ξ  i, Ξ² i β†’ Ξ³) : Ξ³ := βˆ‘ i in f.support, g i (f i) /-- `prod f g` is the product of `g i (f i)` over the support of `f`. -/ @[to_additive] def prod [Ξ  i, has_zero (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [comm_monoid Ξ³] (f : Ξ β‚€ i, Ξ² i) (g : Ξ  i, Ξ² i β†’ Ξ³) : Ξ³ := ∏ i in f.support, g i (f i) @[to_additive] lemma prod_map_range_index {β₁ : ΞΉ β†’ Type v₁} {Ξ²β‚‚ : ΞΉ β†’ Type vβ‚‚} [Ξ  i, has_zero (β₁ i)] [Ξ  i, has_zero (Ξ²β‚‚ i)] [Ξ  i (x : β₁ i), decidable (x β‰  0)] [Ξ  i (x : Ξ²β‚‚ i), decidable (x β‰  0)] [comm_monoid Ξ³] {f : Ξ  i, β₁ i β†’ Ξ²β‚‚ i} {hf : βˆ€ i, f i 0 = 0} {g : Ξ β‚€ i, β₁ i} {h : Ξ  i, Ξ²β‚‚ i β†’ Ξ³} (h0 : βˆ€i, h i 0 = 1) : (map_range f hf g).prod h = g.prod (Ξ»i b, h i (f i b)) := begin rw [map_range_def], refine (finset.prod_subset support_mk_subset _).trans _, { intros i h1 h2, dsimp, simp [h1] at h2, dsimp at h2, simp [h1, h2, h0] }, { refine finset.prod_congr rfl _, intros i h1, simp [h1] } end @[to_additive] lemma prod_zero_index [Ξ  i, add_comm_monoid (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [comm_monoid Ξ³] {h : Ξ  i, Ξ² i β†’ Ξ³} : (0 : Ξ β‚€ i, Ξ² i).prod h = 1 := rfl @[to_additive] lemma prod_single_index [Ξ  i, has_zero (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [comm_monoid Ξ³] {i : ΞΉ} {b : Ξ² i} {h : Ξ  i, Ξ² i β†’ Ξ³} (h_zero : h i 0 = 1) : (single i b).prod h = h i b := begin by_cases h : b β‰  0, { simp [dfinsupp.prod, support_single_ne_zero h] }, { rw [not_not] at h, simp [h, prod_zero_index, h_zero], refl } end @[to_additive] lemma prod_neg_index [Ξ  i, add_group (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [comm_monoid Ξ³] {g : Ξ β‚€ i, Ξ² i} {h : Ξ  i, Ξ² i β†’ Ξ³} (h0 : βˆ€i, h i 0 = 1) : (-g).prod h = g.prod (Ξ»i b, h i (- b)) := prod_map_range_index h0 omit dec @[to_additive] lemma prod_comm {ι₁ ΞΉβ‚‚ : Sort*} {β₁ : ι₁ β†’ Type*} {Ξ²β‚‚ : ΞΉβ‚‚ β†’ Type*} [decidable_eq ι₁] [decidable_eq ΞΉβ‚‚] [Ξ  i, has_zero (β₁ i)] [Ξ  i, has_zero (Ξ²β‚‚ i)] [Ξ  i (x : β₁ i), decidable (x β‰  0)] [Ξ  i (x : Ξ²β‚‚ i), decidable (x β‰  0)] [comm_monoid Ξ³] (f₁ : Ξ β‚€ i, β₁ i) (fβ‚‚ : Ξ β‚€ i, Ξ²β‚‚ i) (h : Ξ  i, β₁ i β†’ Ξ  i, Ξ²β‚‚ i β†’ Ξ³) : f₁.prod (Ξ» i₁ x₁, fβ‚‚.prod $ Ξ» iβ‚‚ xβ‚‚, h i₁ x₁ iβ‚‚ xβ‚‚) = fβ‚‚.prod (Ξ» iβ‚‚ xβ‚‚, f₁.prod $ Ξ» i₁ x₁, h i₁ x₁ iβ‚‚ xβ‚‚) := finset.prod_comm @[simp] lemma sum_apply {ι₁ : Type u₁} [decidable_eq ι₁] {β₁ : ι₁ β†’ Type v₁} [Ξ  i₁, has_zero (β₁ i₁)] [Ξ  i (x : β₁ i), decidable (x β‰  0)] [Ξ  i, add_comm_monoid (Ξ² i)] {f : Ξ β‚€ i₁, β₁ i₁} {g : Ξ  i₁, β₁ i₁ β†’ Ξ β‚€ i, Ξ² i} {iβ‚‚ : ΞΉ} : (f.sum g) iβ‚‚ = f.sum (Ξ»i₁ b, g i₁ b iβ‚‚) := (f.support.sum_hom (Ξ»f : Ξ β‚€ i, Ξ² i, f iβ‚‚)).symm include dec lemma support_sum {ι₁ : Type u₁} [decidable_eq ι₁] {β₁ : ι₁ β†’ Type v₁} [Ξ  i₁, has_zero (β₁ i₁)] [Ξ  i (x : β₁ i), decidable (x β‰  0)] [Ξ  i, add_comm_monoid (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] {f : Ξ β‚€ i₁, β₁ i₁} {g : Ξ  i₁, β₁ i₁ β†’ Ξ β‚€ i, Ξ² i} : (f.sum g).support βŠ† f.support.bUnion (Ξ»i, (g i (f i)).support) := have βˆ€i₁ : ΞΉ, f.sum (Ξ» (i : ι₁) (b : β₁ i), (g i b) i₁) β‰  0 β†’ (βˆƒ (i : ι₁), f i β‰  0 ∧ Β¬ (g i (f i)) i₁ = 0), from assume i₁ h, let ⟨i, hi, ne⟩ := finset.exists_ne_zero_of_sum_ne_zero h in ⟨i, (f.mem_support_iff i).mp hi, ne⟩, by simpa [finset.subset_iff, mem_support_iff, finset.mem_bUnion, sum_apply] using this @[simp, to_additive] lemma prod_one [Ξ  i, add_comm_monoid (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [comm_monoid Ξ³] {f : Ξ β‚€ i, Ξ² i} : f.prod (Ξ»i b, (1 : Ξ³)) = 1 := finset.prod_const_one @[simp, to_additive] lemma prod_mul [Ξ  i, add_comm_monoid (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [comm_monoid Ξ³] {f : Ξ β‚€ i, Ξ² i} {h₁ hβ‚‚ : Ξ  i, Ξ² i β†’ Ξ³} : f.prod (Ξ»i b, h₁ i b * hβ‚‚ i b) = f.prod h₁ * f.prod hβ‚‚ := finset.prod_mul_distrib @[simp, to_additive] lemma prod_inv [Ξ  i, add_comm_monoid (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [comm_group Ξ³] {f : Ξ β‚€ i, Ξ² i} {h : Ξ  i, Ξ² i β†’ Ξ³} : f.prod (Ξ»i b, (h i b)⁻¹) = (f.prod h)⁻¹ := f.support.prod_hom (@has_inv.inv Ξ³ _) @[to_additive] lemma prod_add_index [Ξ  i, add_comm_monoid (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [comm_monoid Ξ³] {f g : Ξ β‚€ i, Ξ² i} {h : Ξ  i, Ξ² i β†’ Ξ³} (h_zero : βˆ€i, h i 0 = 1) (h_add : βˆ€i b₁ bβ‚‚, h i (b₁ + bβ‚‚) = h i b₁ * h i bβ‚‚) : (f + g).prod h = f.prod h * g.prod h := have f_eq : ∏ i in f.support βˆͺ g.support, h i (f i) = f.prod h, from (finset.prod_subset (finset.subset_union_left _ _) $ by simp [mem_support_iff, h_zero] {contextual := tt}).symm, have g_eq : ∏ i in f.support βˆͺ g.support, h i (g i) = g.prod h, from (finset.prod_subset (finset.subset_union_right _ _) $ by simp [mem_support_iff, h_zero] {contextual := tt}).symm, calc ∏ i in (f + g).support, h i ((f + g) i) = ∏ i in f.support βˆͺ g.support, h i ((f + g) i) : finset.prod_subset support_add $ by simp [mem_support_iff, h_zero] {contextual := tt} ... = (∏ i in f.support βˆͺ g.support, h i (f i)) * (∏ i in f.support βˆͺ g.support, h i (g i)) : by simp [h_add, finset.prod_mul_distrib] ... = _ : by rw [f_eq, g_eq] /-- When summing over an `add_monoid_hom`, the decidability assumption is not needed, and the result is also an `add_monoid_hom`. -/ def sum_add_hom [Ξ  i, add_zero_class (Ξ² i)] [add_comm_monoid Ξ³] (Ο† : Ξ  i, Ξ² i β†’+ Ξ³) : (Ξ β‚€ i, Ξ² i) β†’+ Ξ³ := { to_fun := (Ξ» f, quotient.lift_on f (Ξ» x, βˆ‘ i in x.2.to_finset, Ο† i (x.1 i)) $ Ξ» x y H, begin have H1 : x.2.to_finset ∩ y.2.to_finset βŠ† x.2.to_finset, from finset.inter_subset_left _ _, have H2 : x.2.to_finset ∩ y.2.to_finset βŠ† y.2.to_finset, from finset.inter_subset_right _ _, refine (finset.sum_subset H1 _).symm.trans ((finset.sum_congr rfl _).trans (finset.sum_subset H2 _)), { intros i H1 H2, rw finset.mem_inter at H2, rw H i, simp only [multiset.mem_to_finset] at H1 H2, rw [(y.3 i).resolve_left (mt (and.intro H1) H2), add_monoid_hom.map_zero] }, { intros i H1, rw H i }, { intros i H1 H2, rw finset.mem_inter at H2, rw ← H i, simp only [multiset.mem_to_finset] at H1 H2, rw [(x.3 i).resolve_left (mt (Ξ» H3, and.intro H3 H1) H2), add_monoid_hom.map_zero] } end), map_add' := assume f g, begin refine quotient.induction_on f (Ξ» x, _), refine quotient.induction_on g (Ξ» y, _), change βˆ‘ i in _, _ = (βˆ‘ i in _, _) + (βˆ‘ i in _, _), simp only, conv { to_lhs, congr, skip, funext, rw add_monoid_hom.map_add }, simp only [finset.sum_add_distrib], congr' 1, { refine (finset.sum_subset _ _).symm, { intro i, simp only [multiset.mem_to_finset, multiset.mem_add], exact or.inl }, { intros i H1 H2, simp only [multiset.mem_to_finset, multiset.mem_add] at H2, rw [(x.3 i).resolve_left H2, add_monoid_hom.map_zero] } }, { refine (finset.sum_subset _ _).symm, { intro i, simp only [multiset.mem_to_finset, multiset.mem_add], exact or.inr }, { intros i H1 H2, simp only [multiset.mem_to_finset, multiset.mem_add] at H2, rw [(y.3 i).resolve_left H2, add_monoid_hom.map_zero] } } end, map_zero' := rfl } @[simp] lemma sum_add_hom_single [Ξ  i, add_zero_class (Ξ² i)] [add_comm_monoid Ξ³] (Ο† : Ξ  i, Ξ² i β†’+ Ξ³) (i) (x : Ξ² i) : sum_add_hom Ο† (single i x) = Ο† i x := (add_zero _).trans $ congr_arg (Ο† i) $ show (if H : i ∈ ({i} : finset _) then x else 0) = x, from dif_pos $ finset.mem_singleton_self i @[simp] lemma sum_add_hom_comp_single [Ξ  i, add_zero_class (Ξ² i)] [add_comm_monoid Ξ³] (f : Ξ  i, Ξ² i β†’+ Ξ³) (i : ΞΉ) : (sum_add_hom f).comp (single_add_hom Ξ² i) = f i := add_monoid_hom.ext $ Ξ» x, sum_add_hom_single f i x /-- While we didn't need decidable instances to define it, we do to reduce it to a sum -/ lemma sum_add_hom_apply [Ξ  i, add_zero_class (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [add_comm_monoid Ξ³] (Ο† : Ξ  i, Ξ² i β†’+ Ξ³) (f : Ξ β‚€ i, Ξ² i) : sum_add_hom Ο† f = f.sum (Ξ» x, Ο† x) := begin refine quotient.induction_on f (Ξ» x, _), change βˆ‘ i in _, _ = (βˆ‘ i in finset.filter _ _, _), rw [finset.sum_filter, finset.sum_congr rfl], intros i _, dsimp only, split_ifs, refl, rw [(not_not.mp h), add_monoid_hom.map_zero], end omit dec lemma sum_add_hom_comm {ι₁ ΞΉβ‚‚ : Sort*} {β₁ : ι₁ β†’ Type*} {Ξ²β‚‚ : ΞΉβ‚‚ β†’ Type*} {Ξ³ : Type*} [decidable_eq ι₁] [decidable_eq ΞΉβ‚‚] [Ξ  i, add_zero_class (β₁ i)] [Ξ  i, add_zero_class (Ξ²β‚‚ i)] [add_comm_monoid Ξ³] (f₁ : Ξ β‚€ i, β₁ i) (fβ‚‚ : Ξ β‚€ i, Ξ²β‚‚ i) (h : Ξ  i j, β₁ i β†’+ Ξ²β‚‚ j β†’+ Ξ³) : sum_add_hom (Ξ» iβ‚‚, sum_add_hom (Ξ» i₁, h i₁ iβ‚‚) f₁) fβ‚‚ = sum_add_hom (Ξ» i₁, sum_add_hom (Ξ» iβ‚‚, (h i₁ iβ‚‚).flip) fβ‚‚) f₁ := begin refine quotient.induction_onβ‚‚ f₁ fβ‚‚ (Ξ» x₁ xβ‚‚, _), simp only [sum_add_hom, add_monoid_hom.finset_sum_apply, quotient.lift_on_mk, add_monoid_hom.coe_mk, add_monoid_hom.flip_apply], exact finset.sum_comm, end include dec /-- The `dfinsupp` version of `finsupp.lift_add_hom`,-/ @[simps apply symm_apply] def lift_add_hom [Ξ  i, add_zero_class (Ξ² i)] [add_comm_monoid Ξ³] : (Ξ  i, Ξ² i β†’+ Ξ³) ≃+ ((Ξ β‚€ i, Ξ² i) β†’+ Ξ³) := { to_fun := sum_add_hom, inv_fun := Ξ» F i, F.comp (single_add_hom Ξ² i), left_inv := Ξ» x, by { ext, simp }, right_inv := Ξ» ψ, by { ext, simp }, map_add' := Ξ» F G, by { ext, simp } } /-- The `dfinsupp` version of `finsupp.lift_add_hom_single_add_hom`,-/ @[simp] lemma lift_add_hom_single_add_hom [Ξ  i, add_comm_monoid (Ξ² i)] : lift_add_hom (single_add_hom Ξ²) = add_monoid_hom.id (Ξ β‚€ i, Ξ² i) := lift_add_hom.to_equiv.apply_eq_iff_eq_symm_apply.2 rfl /-- The `dfinsupp` version of `finsupp.lift_add_hom_apply_single`,-/ lemma lift_add_hom_apply_single [Ξ  i, add_zero_class (Ξ² i)] [add_comm_monoid Ξ³] (f : Ξ  i, Ξ² i β†’+ Ξ³) (i : ΞΉ) (x : Ξ² i) : lift_add_hom f (single i x) = f i x := by simp /-- The `dfinsupp` version of `finsupp.lift_add_hom_comp_single`,-/ lemma lift_add_hom_comp_single [Ξ  i, add_zero_class (Ξ² i)] [add_comm_monoid Ξ³] (f : Ξ  i, Ξ² i β†’+ Ξ³) (i : ΞΉ) : (lift_add_hom f).comp (single_add_hom Ξ² i) = f i := by simp /-- The `dfinsupp` version of `finsupp.comp_lift_add_hom`,-/ lemma comp_lift_add_hom {Ξ΄ : Type*} [Ξ  i, add_zero_class (Ξ² i)] [add_comm_monoid Ξ³] [add_comm_monoid Ξ΄] (g : Ξ³ β†’+ Ξ΄) (f : Ξ  i, Ξ² i β†’+ Ξ³) : g.comp (lift_add_hom f) = lift_add_hom (Ξ» a, g.comp (f a)) := lift_add_hom.symm_apply_eq.1 $ funext $ Ξ» a, by rw [lift_add_hom_symm_apply, add_monoid_hom.comp_assoc, lift_add_hom_comp_single] @[simp] lemma sum_add_hom_zero [Ξ  i, add_zero_class (Ξ² i)] [add_comm_monoid Ξ³] : sum_add_hom (Ξ» i, (0 : Ξ² i β†’+ Ξ³)) = 0 := (lift_add_hom : (Ξ  i, Ξ² i β†’+ Ξ³) ≃+ _).map_zero @[simp] lemma sum_add_hom_add [Ξ  i, add_zero_class (Ξ² i)] [add_comm_monoid Ξ³] (g : Ξ  i, Ξ² i β†’+ Ξ³) (h : Ξ  i, Ξ² i β†’+ Ξ³) : sum_add_hom (Ξ» i, g i + h i) = sum_add_hom g + sum_add_hom h := lift_add_hom.map_add _ _ @[simp] lemma sum_add_hom_single_add_hom [Ξ  i, add_comm_monoid (Ξ² i)] : sum_add_hom (single_add_hom Ξ²) = add_monoid_hom.id _ := lift_add_hom_single_add_hom lemma comp_sum_add_hom {Ξ΄ : Type*} [Ξ  i, add_zero_class (Ξ² i)] [add_comm_monoid Ξ³] [add_comm_monoid Ξ΄] (g : Ξ³ β†’+ Ξ΄) (f : Ξ  i, Ξ² i β†’+ Ξ³) : g.comp (sum_add_hom f) = sum_add_hom (Ξ» a, g.comp (f a)) := comp_lift_add_hom _ _ lemma sum_sub_index [Ξ  i, add_group (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [add_comm_group Ξ³] {f g : Ξ β‚€ i, Ξ² i} {h : Ξ  i, Ξ² i β†’ Ξ³} (h_sub : βˆ€i b₁ bβ‚‚, h i (b₁ - bβ‚‚) = h i b₁ - h i bβ‚‚) : (f - g).sum h = f.sum h - g.sum h := begin have := (lift_add_hom (Ξ» a, add_monoid_hom.of_map_sub (h a) (h_sub a))).map_sub f g, rw [lift_add_hom_apply, sum_add_hom_apply, sum_add_hom_apply, sum_add_hom_apply] at this, exact this, end @[to_additive] lemma prod_finset_sum_index {Ξ³ : Type w} {Ξ± : Type x} [Ξ  i, add_comm_monoid (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [comm_monoid Ξ³] {s : finset Ξ±} {g : Ξ± β†’ Ξ β‚€ i, Ξ² i} {h : Ξ  i, Ξ² i β†’ Ξ³} (h_zero : βˆ€i, h i 0 = 1) (h_add : βˆ€i b₁ bβ‚‚, h i (b₁ + bβ‚‚) = h i b₁ * h i bβ‚‚) : ∏ i in s, (g i).prod h = (βˆ‘ i in s, g i).prod h := begin classical, exact finset.induction_on s (by simp [prod_zero_index]) (by simp [prod_add_index, h_zero, h_add] {contextual := tt}) end @[to_additive] lemma prod_sum_index {ι₁ : Type u₁} [decidable_eq ι₁] {β₁ : ι₁ β†’ Type v₁} [Ξ  i₁, has_zero (β₁ i₁)] [Ξ  i (x : β₁ i), decidable (x β‰  0)] [Ξ  i, add_comm_monoid (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [comm_monoid Ξ³] {f : Ξ β‚€ i₁, β₁ i₁} {g : Ξ  i₁, β₁ i₁ β†’ Ξ β‚€ i, Ξ² i} {h : Ξ  i, Ξ² i β†’ Ξ³} (h_zero : βˆ€i, h i 0 = 1) (h_add : βˆ€i b₁ bβ‚‚, h i (b₁ + bβ‚‚) = h i b₁ * h i bβ‚‚) : (f.sum g).prod h = f.prod (Ξ»i b, (g i b).prod h) := (prod_finset_sum_index h_zero h_add).symm @[simp] lemma sum_single [Ξ  i, add_comm_monoid (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] {f : Ξ β‚€ i, Ξ² i} : f.sum single = f := begin have := add_monoid_hom.congr_fun lift_add_hom_single_add_hom f, rw [lift_add_hom_apply, sum_add_hom_apply] at this, exact this, end @[to_additive] lemma prod_subtype_domain_index [Ξ  i, has_zero (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] [comm_monoid Ξ³] {v : Ξ β‚€ i, Ξ² i} {p : ΞΉ β†’ Prop} [decidable_pred p] {h : Ξ  i, Ξ² i β†’ Ξ³} (hp : βˆ€ x ∈ v.support, p x) : (v.subtype_domain p).prod (Ξ»i b, h i b) = v.prod h := finset.prod_bij (Ξ»p _, p) (by simp) (by simp) (assume ⟨aβ‚€, haβ‚€βŸ© ⟨a₁, haβ‚βŸ©, by simp) (Ξ» i hi, ⟨⟨i, hp i hi⟩, by simpa using hi, rfl⟩) omit dec lemma subtype_domain_sum [Ξ  i, add_comm_monoid (Ξ² i)] {s : finset Ξ³} {h : Ξ³ β†’ Ξ β‚€ i, Ξ² i} {p : ΞΉ β†’ Prop} [decidable_pred p] : (βˆ‘ c in s, h c).subtype_domain p = βˆ‘ c in s, (h c).subtype_domain p := eq.symm (s.sum_hom _) lemma subtype_domain_finsupp_sum {Ξ΄ : Ξ³ β†’ Type x} [decidable_eq Ξ³] [Ξ  c, has_zero (Ξ΄ c)] [Ξ  c (x : Ξ΄ c), decidable (x β‰  0)] [Ξ  i, add_comm_monoid (Ξ² i)] {p : ΞΉ β†’ Prop} [decidable_pred p] {s : Ξ β‚€ c, Ξ΄ c} {h : Ξ  c, Ξ΄ c β†’ Ξ β‚€ i, Ξ² i} : (s.sum h).subtype_domain p = s.sum (Ξ»c d, (h c d).subtype_domain p) := subtype_domain_sum end prod_and_sum /-! ### Bundled versions of `dfinsupp.map_range` The names should match the equivalent bundled `finsupp.map_range` definitions. -/ section map_range omit dec variables [Ξ  i, add_zero_class (Ξ² i)] [Ξ  i, add_zero_class (β₁ i)] [Ξ  i, add_zero_class (Ξ²β‚‚ i)] lemma map_range_add (f : Ξ  i, β₁ i β†’ Ξ²β‚‚ i) (hf : βˆ€ i, f i 0 = 0) (hf' : βˆ€ i x y, f i (x + y) = f i x + f i y) (g₁ gβ‚‚ : Ξ β‚€ i, β₁ i): map_range f hf (g₁ + gβ‚‚) = map_range f hf g₁ + map_range f hf gβ‚‚ := begin ext, simp only [map_range_apply f, coe_add, pi.add_apply, hf'] end /-- `dfinsupp.map_range` as an `add_monoid_hom`. -/ @[simps apply] def map_range.add_monoid_hom (f : Ξ  i, β₁ i β†’+ Ξ²β‚‚ i) : (Ξ β‚€ i, β₁ i) β†’+ (Ξ β‚€ i, Ξ²β‚‚ i) := { to_fun := map_range (Ξ» i x, f i x) (Ξ» i, (f i).map_zero), map_zero' := map_range_zero _ _, map_add' := map_range_add _ _ (Ξ» i, (f i).map_add) } @[simp] lemma map_range.add_monoid_hom_id : map_range.add_monoid_hom (Ξ» i, add_monoid_hom.id (Ξ²β‚‚ i)) = add_monoid_hom.id _ := add_monoid_hom.ext map_range_id lemma map_range.add_monoid_hom_comp (f : Ξ  i, β₁ i β†’+ Ξ²β‚‚ i) (fβ‚‚ : Ξ  i, Ξ² i β†’+ β₁ i): map_range.add_monoid_hom (Ξ» i, (f i).comp (fβ‚‚ i)) = (map_range.add_monoid_hom f).comp (map_range.add_monoid_hom fβ‚‚) := add_monoid_hom.ext $ map_range_comp (Ξ» i x, f i x) (Ξ» i x, fβ‚‚ i x) _ _ _ /-- `dfinsupp.map_range.add_monoid_hom` as an `add_equiv`. -/ @[simps apply] def map_range.add_equiv (e : Ξ  i, β₁ i ≃+ Ξ²β‚‚ i) : (Ξ β‚€ i, β₁ i) ≃+ (Ξ β‚€ i, Ξ²β‚‚ i) := { to_fun := map_range (Ξ» i x, e i x) (Ξ» i, (e i).map_zero), inv_fun := map_range (Ξ» i x, (e i).symm x) (Ξ» i, (e i).symm.map_zero), left_inv := Ξ» x, by rw ←map_range_comp; { simp_rw add_equiv.symm_comp_self, simp }, right_inv := Ξ» x, by rw ←map_range_comp; { simp_rw add_equiv.self_comp_symm, simp }, .. map_range.add_monoid_hom (Ξ» i, (e i).to_add_monoid_hom) } @[simp] lemma map_range.add_equiv_refl : (map_range.add_equiv $ Ξ» i, add_equiv.refl (β₁ i)) = add_equiv.refl _ := add_equiv.ext map_range_id lemma map_range.add_equiv_trans (f : Ξ  i, Ξ² i ≃+ β₁ i) (fβ‚‚ : Ξ  i, β₁ i ≃+ Ξ²β‚‚ i): map_range.add_equiv (Ξ» i, (f i).trans (fβ‚‚ i)) = (map_range.add_equiv f).trans (map_range.add_equiv fβ‚‚) := add_equiv.ext $ map_range_comp (Ξ» i x, fβ‚‚ i x) (Ξ» i x, f i x) _ _ _ @[simp] lemma map_range.add_equiv_symm (e : Ξ  i, β₁ i ≃+ Ξ²β‚‚ i) : (map_range.add_equiv e).symm = map_range.add_equiv (Ξ» i, (e i).symm) := rfl end map_range end dfinsupp /-! ### Product and sum lemmas for bundled morphisms -/ section variables [decidable_eq ΞΉ] namespace monoid_hom variables {R S : Type*} variables [Ξ  i, has_zero (Ξ² i)] [Ξ  i (x : Ξ² i), decidable (x β‰  0)] @[simp, to_additive] lemma map_dfinsupp_prod [comm_monoid R] [comm_monoid S] (h : R β†’* S) (f : Ξ β‚€ i, Ξ² i) (g : Ξ  i, Ξ² i β†’ R) : h (f.prod g) = f.prod (Ξ» a b, h (g a b)) := h.map_prod _ _ @[to_additive] lemma coe_dfinsupp_prod [monoid R] [comm_monoid S] (f : Ξ β‚€ i, Ξ² i) (g : Ξ  i, Ξ² i β†’ R β†’* S) : ⇑(f.prod g) = f.prod (Ξ» a b, (g a b)) := coe_prod _ _ @[simp, to_additive] lemma dfinsupp_prod_apply [monoid R] [comm_monoid S] (f : Ξ β‚€ i, Ξ² i) (g : Ξ  i, Ξ² i β†’ R β†’* S) (r : R) : (f.prod g) r = f.prod (Ξ» a b, (g a b) r) := finset_prod_apply _ _ _ end monoid_hom namespace add_monoid_hom variables {R S : Type*} open dfinsupp /-! The above lemmas, repeated for `dfinsupp.sum_add_hom`. -/ @[simp] lemma map_dfinsupp_sum_add_hom [add_comm_monoid R] [add_comm_monoid S] [Ξ  i, add_comm_monoid (Ξ² i)] (h : R β†’+ S) (f : Ξ β‚€ i, Ξ² i) (g : Ξ  i, Ξ² i β†’+ R) : h (sum_add_hom g f) = sum_add_hom (Ξ» i, h.comp (g i)) f := congr_fun (comp_lift_add_hom h g) f @[simp] lemma dfinsupp_sum_add_hom_apply [add_zero_class R] [add_comm_monoid S] [Ξ  i, add_comm_monoid (Ξ² i)] (f : Ξ β‚€ i, Ξ² i) (g : Ξ  i, Ξ² i β†’+ R β†’+ S) (r : R) : (sum_add_hom g f) r = sum_add_hom (Ξ» i, (eval r).comp (g i)) f := map_dfinsupp_sum_add_hom (eval r) f g lemma coe_dfinsupp_sum_add_hom [add_zero_class R] [add_comm_monoid S] [Ξ  i, add_comm_monoid (Ξ² i)] (f : Ξ β‚€ i, Ξ² i) (g : Ξ  i, Ξ² i β†’+ R β†’+ S) : ⇑(sum_add_hom g f) = sum_add_hom (Ξ» i, (coe_fn R S).comp (g i)) f := map_dfinsupp_sum_add_hom (coe_fn R S) f g end add_monoid_hom end
9251e24eb58a75c4df351043fe96aaebe6d43b58
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/param_binder_update2.lean
cb415a56235792922368136f5951d164c7084776
[ "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
378
lean
section parameters {A : Type*} {B : Type*} definition foo1 (a : A) (b : B) := a parameters (B) {A} -- Should not change the order of the parameters definition foo2 (a : A) (b : B) := a parameters {B} (A) definition foo3 (a : A) (b : B) := a parameters (A) (B) definition foo4 (a : A) (b : B) := a end #check @foo1 #check @foo2 #check @foo3 #check @foo4
4cc7476b1d1e09980c82d8a629557fb5f2019e62
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
/tests/lean/refute1.lean
7b7cdaf33a855f3d8923a49fb715ba81f205ecb8
[ "Apache-2.0" ]
permissive
codyroux/lean0.1
1ce92751d664aacff0529e139083304a7bbc8a71
0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef
refs/heads/master
1,610,830,535,062
1,402,150,480,000
1,402,150,480,000
19,588,851
2
0
null
null
null
null
UTF-8
Lean
false
false
104
lean
variables a b : Bool axiom H : a /\ b theorem T : a := by_contradiction (fun R, absurd (and_eliml H) R)
f6c3c438474fd4732a2b6c2d1e1158f8bb386077
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/ring_theory/fintype.lean
00047fc067b6b8516a5c044f6dd1bc4e739bfbd3
[ "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
474
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 data.fintype.units /-! # Some facts about finite rings -/ open_locale classical lemma card_units_lt (Mβ‚€ : Type*) [monoid_with_zero Mβ‚€] [nontrivial Mβ‚€] [fintype Mβ‚€] : fintype.card Mβ‚€Λ£ < fintype.card Mβ‚€ := fintype.card_lt_of_injective_of_not_mem (coe : Mβ‚€Λ£ β†’ Mβ‚€) units.ext not_is_unit_zero
676591df25b348ac8350824c3fb299e464b38c2e
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/tests/lean/1298.lean
26c885dc496a6804ff5d7c9919701547c355607b
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
EdAyers/lean4
57ac632d6b0789cb91fab2170e8c9e40441221bd
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
refs/heads/master
1,676,463,245,298
1,660,619,433,000
1,660,619,433,000
183,433,437
1
0
Apache-2.0
1,657,612,672,000
1,556,196,574,000
Lean
UTF-8
Lean
false
false
421
lean
class Semiring (R : Type u) extends Add R, HPow R Nat R, Mul R where zero : R instance [Semiring R] : OfNat R n where ofNat := Semiring.zero def Nat.cast [Semiring R] (n : Nat) : R := let _ := n = n; Semiring.zero @[defaultInstance high] instance [Semiring R] : HPow R Nat R := inferInstance instance [Semiring R] : CoeTail Nat R where coe n := n.cast variable (R) [Semiring R] #check (8 + 2 ^ 2 * 3 : R) = 20
e4ab442f5bf98b0fffbd52e16850c3674ecf9fdb
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/nat/parity_auto.lean
a31035b6dd170d8029ac89fa1e9d36d7d17f0925
[]
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,770
lean
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad The `even` and `odd` predicates on the natural numbers. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.nat.modeq import Mathlib.PostPort universes u_1 namespace Mathlib namespace nat @[simp] theorem mod_two_ne_one {n : β„•} : Β¬n % bit0 1 = 1 ↔ n % bit0 1 = 0 := sorry @[simp] theorem mod_two_ne_zero {n : β„•} : Β¬n % bit0 1 = 0 ↔ n % bit0 1 = 1 := sorry theorem even_iff {n : β„•} : even n ↔ n % bit0 1 = 0 := sorry theorem odd_iff {n : β„•} : odd n ↔ n % bit0 1 = 1 := sorry theorem not_even_iff {n : β„•} : Β¬even n ↔ n % bit0 1 = 1 := eq.mpr (id (Eq._oldrec (Eq.refl (Β¬even n ↔ n % bit0 1 = 1)) (propext even_iff))) (eq.mpr (id (Eq._oldrec (Eq.refl (Β¬n % bit0 1 = 0 ↔ n % bit0 1 = 1)) (propext mod_two_ne_zero))) (iff.refl (n % bit0 1 = 1))) theorem not_odd_iff {n : β„•} : Β¬odd n ↔ n % bit0 1 = 0 := eq.mpr (id (Eq._oldrec (Eq.refl (Β¬odd n ↔ n % bit0 1 = 0)) (propext odd_iff))) (eq.mpr (id (Eq._oldrec (Eq.refl (Β¬n % bit0 1 = 1 ↔ n % bit0 1 = 0)) (propext mod_two_ne_one))) (iff.refl (n % bit0 1 = 0))) theorem even_iff_not_odd {n : β„•} : even n ↔ Β¬odd n := eq.mpr (id (Eq._oldrec (Eq.refl (even n ↔ Β¬odd n)) (propext not_odd_iff))) (eq.mpr (id (Eq._oldrec (Eq.refl (even n ↔ n % bit0 1 = 0)) (propext even_iff))) (iff.refl (n % bit0 1 = 0))) @[simp] theorem odd_iff_not_even {n : β„•} : odd n ↔ Β¬even n := eq.mpr (id (Eq._oldrec (Eq.refl (odd n ↔ Β¬even n)) (propext not_even_iff))) (eq.mpr (id (Eq._oldrec (Eq.refl (odd n ↔ n % bit0 1 = 1)) (propext odd_iff))) (iff.refl (n % bit0 1 = 1))) theorem even_or_odd (n : β„•) : even n ∨ odd n := or.imp_right (iff.mpr odd_iff_not_even) (em (even n)) theorem even_or_odd' (n : β„•) : βˆƒ (k : β„•), n = bit0 1 * k ∨ n = bit0 1 * k + 1 := sorry theorem even_xor_odd (n : β„•) : xor (even n) (odd n) := or.dcases_on (even_or_odd n) (fun (h : even n) => Or.inl { left := h, right := iff.mp even_iff_not_odd h }) fun (h : odd n) => Or.inr { left := h, right := iff.mp odd_iff_not_even h } theorem even_xor_odd' (n : β„•) : βˆƒ (k : β„•), xor (n = bit0 1 * k) (n = bit0 1 * k + 1) := sorry theorem odd_gt_zero {n : β„•} (h : odd n) : 0 < n := Exists.dcases_on h fun (k : β„•) (hk : n = bit0 1 * k + 1) => eq.mpr (id (Eq._oldrec (Eq.refl (0 < n)) hk)) succ_pos' protected instance even.decidable_pred : decidable_pred even := fun (n : β„•) => decidable_of_decidable_of_iff (nat.decidable_eq (n % bit0 1) 0) sorry protected instance decidable_pred_odd : decidable_pred odd := fun (n : β„•) => decidable_of_decidable_of_iff not.decidable sorry @[simp] theorem even_zero : even 0 := Exists.intro 0 (of_as_true trivial) @[simp] theorem not_even_one : Β¬even 1 := eq.mpr (id (Eq._oldrec (Eq.refl (Β¬even 1)) (propext even_iff))) one_ne_zero @[simp] theorem even_bit0 (n : β„•) : even (bit0 n) := Exists.intro n (eq.mpr (id (Eq._oldrec (Eq.refl (bit0 n = bit0 1 * n)) (bit0.equations._eqn_1 n))) (eq.mpr (id (Eq._oldrec (Eq.refl (n + n = bit0 1 * n)) (two_mul n))) (Eq.refl (n + n)))) theorem even_add {m : β„•} {n : β„•} : even (m + n) ↔ (even m ↔ even n) := sorry theorem even.add {m : β„•} {n : β„•} (hm : even m) (hn : even n) : even (m + n) := sorry @[simp] theorem not_even_bit1 (n : β„•) : Β¬even (bit1 n) := sorry theorem two_not_dvd_two_mul_add_one (a : β„•) : Β¬bit0 1 ∣ bit0 1 * a + 1 := sorry theorem two_not_dvd_two_mul_sub_one {a : β„•} (w : 0 < a) : Β¬bit0 1 ∣ bit0 1 * a - 1 := sorry theorem even_sub {m : β„•} {n : β„•} (h : n ≀ m) : even (m - n) ↔ (even m ↔ even n) := sorry theorem even.sub {m : β„•} {n : β„•} (hm : even m) (hn : even n) : even (m - n) := sorry theorem even_succ {n : β„•} : even (Nat.succ n) ↔ Β¬even n := sorry theorem even_mul {m : β„•} {n : β„•} : even (m * n) ↔ even m ∨ even n := sorry /-- If `m` and `n` are natural numbers, then the natural number `m^n` is even if and only if `m` is even and `n` is positive. -/ theorem even_pow {m : β„•} {n : β„•} : even (m ^ n) ↔ even m ∧ n β‰  0 := sorry theorem even_div {a : β„•} {b : β„•} : even (a / b) ↔ a % (bit0 1 * b) / b = 0 := sorry theorem neg_one_pow_eq_one_iff_even {Ξ± : Type u_1} [ring Ξ±] {n : β„•} (h1 : -1 β‰  1) : (-1) ^ n = 1 ↔ even n := sorry @[simp] theorem neg_one_pow_two {Ξ± : Type u_1} [ring Ξ±] : (-1) ^ bit0 1 = 1 := sorry theorem neg_one_pow_of_even {Ξ± : Type u_1} [ring Ξ±] {n : β„•} : even n β†’ (-1) ^ n = 1 := sorry theorem neg_one_pow_of_odd {Ξ± : Type u_1} [ring Ξ±] {n : β„•} : odd n β†’ (-1) ^ n = -1 := sorry end Mathlib
437b080091e8a26b221013b65c166a49fb53df17
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/test/conv/apply_congr.lean
053f9837ef1bb86aa7d9c07425acc865c671f0de
[ "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,138
lean
/- Copyright (c) 2019 Lucas Allen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Lucas Allen, Scott Morrison -/ import algebra.big_operators.finsupp import tactic.converter.apply_congr import tactic.interactive example (f g : β„€ β†’ β„€) (S : finset β„€) (h : βˆ€ m ∈ S, f m = g m) : finset.sum S f = finset.sum S g := begin conv_lhs { -- If we just call `congr` here, in the second goal we're helpless, -- because we are only given the opportunity to rewrite `f`. -- However `apply_congr` uses the appropriate `@[congr]` lemma, -- so we get to rewrite `f x`, in the presence of the crucial `H : x ∈ S` hypothesis. apply_congr, skip, simp [h, H], } end -- Again, with some `guard` statements. example (f g : β„€ β†’ β„€) (S : finset β„€) (h : βˆ€ m ∈ S, f m = g m) : finset.sum S f = finset.sum S g := begin conv_lhs { apply_congr finset.sum_congr, -- (See the note about get_goals/set_goals inside apply_congr) (do ng ← tactic.num_goals, guard $ ng = 2), guard_target S, skip, guard_target f x, simp [h, H] } end -- Verify we can `rw` as well as `simp`. example (f g : β„€ β†’ β„€) (S : finset β„€) (h : βˆ€ m ∈ S, f m = g m) : finset.sum S f = finset.sum S g := by conv_lhs { apply_congr, skip, rw h x H, } -- Check that the appropriate `@[congr]` lemma is automatically selected. example (f g : β„€ β†’ β„€) (S : finset β„€) (h : βˆ€ m ∈ S, f m = g m) : finset.prod S f = finset.prod S g := by conv_lhs { apply_congr, skip, simp [h, H], } example (f g : β„€ β†’ β„€) (S : finset β„€) (h : βˆ€ m ∈ S, f m = g m) : finset.fold (+) 0 f S = finset.fold (+) 0 g S := begin -- This time, the automatically selected congruence lemma is "too good"! -- `finset.sum_congr` matches, and so the `conv` block actually -- rewrites the left hand side into a `finset.sum`. conv_lhs { apply_congr, skip, simp [h, H], }, -- So we need a `refl` to identify that we're done. refl, end -- This can be avoided by selecting the congruence lemma by hand. example (f g : β„€ β†’ β„€) (S : finset β„€) (h : βˆ€ m ∈ S, f m = g m) : finset.fold (+) 0 f S = finset.fold (+) 0 g S := begin conv_lhs { apply_congr finset.fold_congr, simp [h, H], }, end example (f : β„€ β†’ β„€) (S : finset β„€) (h : βˆ€ m ∈ S, f m = 0) : finset.sum S f = 0 := begin conv_lhs { apply_congr, skip, simp [h, H], }, simp, end -- An example using `finsupp.sum` open_locale classical example {k G : Type} [semiring k] [group G] (g : G β†’β‚€ k) (a₁ x : G) (b₁ : k) (t : βˆ€ (aβ‚‚ : G), a₁ * aβ‚‚ = x ↔ a₁⁻¹ * x = aβ‚‚) : g.sum (Ξ» (aβ‚‚ : G) (bβ‚‚ : k), ite (a₁ * aβ‚‚ = x) (b₁ * bβ‚‚) 0) = b₁ * g (a₁⁻¹ * x) := begin -- In fact, `congr` works fine here, because our rewrite works globally. conv_lhs { apply_congr, skip, dsimp, rw t, }, rw finset.sum_ite_eq g.support, -- it's a pity we can't just use `simp` here. split_ifs, { refl, }, { simp [finsupp.not_mem_support_iff.1 h], }, end example : true := begin success_if_fail { conv { apply_congr, }, }, trivial end
4d969b2ce7c550c4d411a1960fde7af3d46413dc
432d948a4d3d242fdfb44b81c9e1b1baacd58617
/src/data/equiv/mul_add.lean
1ebce2970f668fb3e7884ab8b1ce76309aff8f96
[ "Apache-2.0" ]
permissive
JLimperg/aesop3
306cc6570c556568897ed2e508c8869667252e8a
a4a116f650cc7403428e72bd2e2c4cda300fe03f
refs/heads/master
1,682,884,916,368
1,620,320,033,000
1,620,320,033,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
21,159
lean
/- Copyright (c) 2018 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Callum Sutton, Yury Kudryashov -/ import algebra.group.hom import algebra.group.type_tags import algebra.group.units_hom import algebra.group_with_zero /-! # Multiplicative and additive equivs In this file we define two extensions of `equiv` called `add_equiv` and `mul_equiv`, which are datatypes representing isomorphisms of `add_monoid`s/`add_group`s and `monoid`s/`group`s. ## Notations * ``infix ` ≃* `:25 := mul_equiv`` * ``infix ` ≃+ `:25 := add_equiv`` The extended equivs all have coercions to functions, and the coercions are the canonical notation when treating the isomorphisms as maps. ## Implementation notes The fields for `mul_equiv`, `add_equiv` now avoid the unbundled `is_mul_hom` and `is_add_hom`, as these are deprecated. ## Tags equiv, mul_equiv, add_equiv -/ variables {A : Type*} {B : Type*} {M : Type*} {N : Type*} {P : Type*} {Q : Type*} {G : Type*} {H : Type*} /-- Makes a multiplicative inverse from a bijection which preserves multiplication. -/ @[to_additive "Makes an additive inverse from a bijection which preserves addition."] def mul_hom.inverse [has_mul M] [has_mul N] (f : mul_hom M N) (g : N β†’ M) (h₁ : function.left_inverse g f) (hβ‚‚ : function.right_inverse g f) : mul_hom N M := { to_fun := g, map_mul' := Ξ» x y, calc g (x * y) = g (f (g x) * f (g y)) : by rw [hβ‚‚ x, hβ‚‚ y] ... = g (f (g x * g y)) : by rw f.map_mul ... = g x * g y : h₁ _, } set_option old_structure_cmd true /-- add_equiv Ξ± Ξ² is the type of an equiv Ξ± ≃ Ξ² which preserves addition. -/ @[ancestor equiv add_hom] structure add_equiv (A B : Type*) [has_add A] [has_add B] extends A ≃ B, add_hom A B /-- The `equiv` underlying an `add_equiv`. -/ add_decl_doc add_equiv.to_equiv /-- The `add_hom` underlying a `add_equiv`. -/ add_decl_doc add_equiv.to_add_hom /-- `mul_equiv Ξ± Ξ²` is the type of an equiv `Ξ± ≃ Ξ²` which preserves multiplication. -/ @[ancestor equiv mul_hom, to_additive] structure mul_equiv (M N : Type*) [has_mul M] [has_mul N] extends M ≃ N, mul_hom M N /-- The `equiv` underlying a `mul_equiv`. -/ add_decl_doc mul_equiv.to_equiv /-- The `mul_hom` underlying a `mul_equiv`. -/ add_decl_doc mul_equiv.to_mul_hom infix ` ≃* `:25 := mul_equiv infix ` ≃+ `:25 := add_equiv namespace mul_equiv @[to_additive] instance [has_mul M] [has_mul N] : has_coe_to_fun (M ≃* N) := ⟨_, mul_equiv.to_fun⟩ variables [has_mul M] [has_mul N] [has_mul P] [has_mul Q] @[simp, to_additive] lemma to_fun_eq_coe {f : M ≃* N} : f.to_fun = f := rfl @[simp, to_additive] lemma coe_to_equiv {f : M ≃* N} : ⇑f.to_equiv = f := rfl @[simp, to_additive] lemma coe_to_mul_hom {f : M ≃* N} : ⇑f.to_mul_hom = f := rfl /-- A multiplicative isomorphism preserves multiplication (canonical form). -/ @[simp, to_additive] lemma map_mul (f : M ≃* N) : βˆ€ x y, f (x * y) = f x * f y := f.map_mul' /-- Makes a multiplicative isomorphism from a bijection which preserves multiplication. -/ @[to_additive "Makes an additive isomorphism from a bijection which preserves addition."] def mk' (f : M ≃ N) (h : βˆ€ x y, f (x * y) = f x * f y) : M ≃* N := ⟨f.1, f.2, f.3, f.4, h⟩ @[to_additive] protected lemma bijective (e : M ≃* N) : function.bijective e := e.to_equiv.bijective @[to_additive] protected lemma injective (e : M ≃* N) : function.injective e := e.to_equiv.injective @[to_additive] protected lemma surjective (e : M ≃* N) : function.surjective e := e.to_equiv.surjective /-- The identity map is a multiplicative isomorphism. -/ @[refl, to_additive "The identity map is an additive isomorphism."] def refl (M : Type*) [has_mul M] : M ≃* M := { map_mul' := Ξ» _ _, rfl, ..equiv.refl _} @[to_additive] instance : inhabited (M ≃* M) := ⟨refl M⟩ /-- The inverse of an isomorphism is an isomorphism. -/ @[symm, to_additive "The inverse of an isomorphism is an isomorphism."] def symm (h : M ≃* N) : N ≃* M := { map_mul' := (h.to_mul_hom.inverse h.to_equiv.symm h.left_inv h.right_inv).map_mul, .. h.to_equiv.symm} /-- See Note [custom simps projection] -/ -- we don't hyperlink the note in the additive version, since that breaks syntax highlighting -- in the whole file. @[to_additive "See Note custom simps projection"] def simps.symm_apply (e : M ≃* N) : N β†’ M := e.symm initialize_simps_projections add_equiv (to_fun β†’ apply, inv_fun β†’ symm_apply) initialize_simps_projections mul_equiv (to_fun β†’ apply, inv_fun β†’ symm_apply) @[simp, to_additive] theorem to_equiv_symm (f : M ≃* N) : f.symm.to_equiv = f.to_equiv.symm := rfl @[simp, to_additive] theorem coe_mk (f : M β†’ N) (g h₁ hβ‚‚ h₃) : ⇑(mul_equiv.mk f g h₁ hβ‚‚ h₃) = f := rfl @[simp, to_additive] lemma symm_symm : βˆ€ (f : M ≃* N), f.symm.symm = f | ⟨f, g, h₁, hβ‚‚, hβ‚ƒβŸ© := rfl @[to_additive] lemma symm_bijective : function.bijective (symm : (M ≃* N) β†’ (N ≃* M)) := equiv.bijective ⟨symm, symm, symm_symm, symm_symm⟩ @[simp, to_additive] theorem symm_mk (f : M β†’ N) (g h₁ hβ‚‚ h₃) : (mul_equiv.mk f g h₁ hβ‚‚ h₃).symm = { to_fun := g, inv_fun := f, ..(mul_equiv.mk f g h₁ hβ‚‚ h₃).symm} := rfl /-- Transitivity of multiplication-preserving isomorphisms -/ @[trans, to_additive "Transitivity of addition-preserving isomorphisms"] def trans (h1 : M ≃* N) (h2 : N ≃* P) : (M ≃* P) := { map_mul' := Ξ» x y, show h2 (h1 (x * y)) = h2 (h1 x) * h2 (h1 y), by rw [h1.map_mul, h2.map_mul], ..h1.to_equiv.trans h2.to_equiv } /-- e.right_inv in canonical form -/ @[simp, to_additive] lemma apply_symm_apply (e : M ≃* N) : βˆ€ y, e (e.symm y) = y := e.to_equiv.apply_symm_apply /-- e.left_inv in canonical form -/ @[simp, to_additive] lemma symm_apply_apply (e : M ≃* N) : βˆ€ x, e.symm (e x) = x := e.to_equiv.symm_apply_apply @[simp, to_additive] theorem symm_comp_self (e : M ≃* N) : e.symm ∘ e = id := funext e.symm_apply_apply @[simp, to_additive] theorem self_comp_symm (e : M ≃* N) : e ∘ e.symm = id := funext e.apply_symm_apply @[simp, to_additive] theorem coe_refl : ⇑(refl M) = id := rfl @[to_additive] theorem refl_apply (m : M) : refl M m = m := rfl @[simp, to_additive] theorem coe_trans (e₁ : M ≃* N) (eβ‚‚ : N ≃* P) : ⇑(e₁.trans eβ‚‚) = eβ‚‚ ∘ e₁ := rfl @[to_additive] theorem trans_apply (e₁ : M ≃* N) (eβ‚‚ : N ≃* P) (m : M) : e₁.trans eβ‚‚ m = eβ‚‚ (e₁ m) := rfl @[simp, to_additive] theorem apply_eq_iff_eq (e : M ≃* N) {x y : M} : e x = e y ↔ x = y := e.injective.eq_iff @[to_additive] lemma apply_eq_iff_symm_apply (e : M ≃* N) {x : M} {y : N} : e x = y ↔ x = e.symm y := e.to_equiv.apply_eq_iff_eq_symm_apply @[to_additive] lemma symm_apply_eq (e : M ≃* N) {x y} : e.symm x = y ↔ x = e y := e.to_equiv.symm_apply_eq @[to_additive] lemma eq_symm_apply (e : M ≃* N) {x y} : y = e.symm x ↔ e y = x := e.to_equiv.eq_symm_apply /-- Two multiplicative isomorphisms agree if they are defined by the same underlying function. -/ @[ext, to_additive "Two additive isomorphisms agree if they are defined by the same underlying function."] lemma ext {f g : mul_equiv M N} (h : βˆ€ x, f x = g x) : f = g := begin have h₁ : f.to_equiv = g.to_equiv := equiv.ext h, cases f, cases g, congr, { exact (funext h) }, { exact congr_arg equiv.inv_fun h₁ } end attribute [ext] add_equiv.ext @[to_additive] lemma ext_iff {f g : mul_equiv M N} : f = g ↔ βˆ€ x, f x = g x := ⟨λ h x, h β–Έ rfl, ext⟩ @[simp, to_additive] lemma mk_coe (e : M ≃* N) (e' h₁ hβ‚‚ h₃) : (⟨e, e', h₁, hβ‚‚, hβ‚ƒβŸ© : M ≃* N) = e := ext $ Ξ» _, rfl @[simp, to_additive] lemma mk_coe' (e : M ≃* N) (f h₁ hβ‚‚ h₃) : (mul_equiv.mk f ⇑e h₁ hβ‚‚ h₃ : N ≃* M) = e.symm := symm_bijective.injective $ ext $ Ξ» x, rfl @[to_additive] protected lemma congr_arg {f : mul_equiv M N} : Ξ  {x x' : M}, x = x' β†’ f x = f x' | _ _ rfl := rfl @[to_additive] protected lemma congr_fun {f g : mul_equiv M N} (h : f = g) (x : M) : f x = g x := h β–Έ rfl /-- The `mul_equiv` between two monoids with a unique element. -/ @[to_additive "The `add_equiv` between two add_monoids with a unique element."] def mul_equiv_of_unique_of_unique {M N} [unique M] [unique N] [has_mul M] [has_mul N] : M ≃* N := { map_mul' := Ξ» _ _, subsingleton.elim _ _, ..equiv_of_unique_of_unique } /-- There is a unique monoid homomorphism between two monoids with a unique element. -/ @[to_additive] instance {M N} [unique M] [unique N] [has_mul M] [has_mul N] : unique (M ≃* N) := { default := mul_equiv_of_unique_of_unique , uniq := Ξ» _, ext $ Ξ» x, subsingleton.elim _ _} /-! ## Monoids -/ /-- A multiplicative equiv of monoids sends 1 to 1 (and is hence a monoid isomorphism). -/ @[simp, to_additive] lemma map_one {M N} [mul_one_class M] [mul_one_class N] (h : M ≃* N) : h 1 = 1 := by rw [←mul_one (h 1), ←h.apply_symm_apply 1, ←h.map_mul, one_mul] @[simp, to_additive] lemma map_eq_one_iff {M N} [mul_one_class M] [mul_one_class N] (h : M ≃* N) {x : M} : h x = 1 ↔ x = 1 := h.map_one β–Έ h.to_equiv.apply_eq_iff_eq @[to_additive] lemma map_ne_one_iff {M N} [mul_one_class M] [mul_one_class N] (h : M ≃* N) {x : M} : h x β‰  1 ↔ x β‰  1 := ⟨mt h.map_eq_one_iff.2, mt h.map_eq_one_iff.1⟩ /-- A bijective `monoid` homomorphism is an isomorphism -/ @[to_additive "A bijective `add_monoid` homomorphism is an isomorphism"] noncomputable def of_bijective {M N} [mul_one_class M] [mul_one_class N] (f : M β†’* N) (hf : function.bijective f) : M ≃* N := { map_mul' := f.map_mul', ..equiv.of_bijective f hf } /-- Extract the forward direction of a multiplicative equivalence as a multiplication-preserving function. -/ @[to_additive "Extract the forward direction of an additive equivalence as an addition-preserving function."] def to_monoid_hom {M N} [mul_one_class M] [mul_one_class N] (h : M ≃* N) : (M β†’* N) := { map_one' := h.map_one, .. h } @[simp, to_additive] lemma coe_to_monoid_hom {M N} [mul_one_class M] [mul_one_class N] (e : M ≃* N) : ⇑e.to_monoid_hom = e := rfl @[to_additive] lemma to_monoid_hom_injective {M N} [mul_one_class M] [mul_one_class N] : function.injective (to_monoid_hom : (M ≃* N) β†’ M β†’* N) := Ξ» f g h, mul_equiv.ext (monoid_hom.ext_iff.1 h) /-- A multiplicative analogue of `equiv.arrow_congr`, where the equivalence between the targets is multiplicative. -/ @[to_additive "An additive analogue of `equiv.arrow_congr`, where the equivalence between the targets is additive.", simps apply] def arrow_congr {M N P Q : Type*} [mul_one_class P] [mul_one_class Q] (f : M ≃ N) (g : P ≃* Q) : (M β†’ P) ≃* (N β†’ Q) := { to_fun := Ξ» h n, g (h (f.symm n)), inv_fun := Ξ» k m, g.symm (k (f m)), left_inv := Ξ» h, by { ext, simp, }, right_inv := Ξ» k, by { ext, simp, }, map_mul' := Ξ» h k, by { ext, simp, }, } /-- A multiplicative analogue of `equiv.arrow_congr`, for multiplicative maps from a monoid to a commutative monoid. -/ @[to_additive "An additive analogue of `equiv.arrow_congr`, for additive maps from an additive monoid to a commutative additive monoid.", simps apply] def monoid_hom_congr {M N P Q} [mul_one_class M] [mul_one_class N] [comm_monoid P] [comm_monoid Q] (f : M ≃* N) (g : P ≃* Q) : (M β†’* P) ≃* (N β†’* Q) := { to_fun := Ξ» h, g.to_monoid_hom.comp (h.comp f.symm.to_monoid_hom), inv_fun := Ξ» k, g.symm.to_monoid_hom.comp (k.comp f.to_monoid_hom), left_inv := Ξ» h, by { ext, simp, }, right_inv := Ξ» k, by { ext, simp, }, map_mul' := Ξ» h k, by { ext, simp, }, } /-! # Groups -/ /-- A multiplicative equivalence of groups preserves inversion. -/ @[simp, to_additive] lemma map_inv [group G] [group H] (h : G ≃* H) (x : G) : h x⁻¹ = (h x)⁻¹ := h.to_monoid_hom.map_inv x end mul_equiv -- We don't use `to_additive` to generate definition because it fails to tell Lean about -- equational lemmas /-- Given a pair of additive monoid homomorphisms `f`, `g` such that `g.comp f = id` and `f.comp g = id`, returns an additive equivalence with `to_fun = f` and `inv_fun = g`. This constructor is useful if the underlying type(s) have specialized `ext` lemmas for additive monoid homomorphisms. -/ def add_monoid_hom.to_add_equiv [add_zero_class M] [add_zero_class N] (f : M β†’+ N) (g : N β†’+ M) (h₁ : g.comp f = add_monoid_hom.id _) (hβ‚‚ : f.comp g = add_monoid_hom.id _) : M ≃+ N := { to_fun := f, inv_fun := g, left_inv := add_monoid_hom.congr_fun h₁, right_inv := add_monoid_hom.congr_fun hβ‚‚, map_add' := f.map_add } /-- Given a pair of monoid homomorphisms `f`, `g` such that `g.comp f = id` and `f.comp g = id`, returns an multiplicative equivalence with `to_fun = f` and `inv_fun = g`. This constructor is useful if the underlying type(s) have specialized `ext` lemmas for monoid homomorphisms. -/ @[to_additive, simps {fully_applied := ff}] def monoid_hom.to_mul_equiv [mul_one_class M] [mul_one_class N] (f : M β†’* N) (g : N β†’* M) (h₁ : g.comp f = monoid_hom.id _) (hβ‚‚ : f.comp g = monoid_hom.id _) : M ≃* N := { to_fun := f, inv_fun := g, left_inv := monoid_hom.congr_fun h₁, right_inv := monoid_hom.congr_fun hβ‚‚, map_mul' := f.map_mul } /-- An additive equivalence of additive groups preserves subtraction. -/ lemma add_equiv.map_sub [add_group A] [add_group B] (h : A ≃+ B) (x y : A) : h (x - y) = h x - h y := h.to_add_monoid_hom.map_sub x y /-- A group is isomorphic to its group of units. -/ @[to_additive to_add_units "An additive group is isomorphic to its group of additive units"] def to_units {G} [group G] : G ≃* units G := { to_fun := Ξ» x, ⟨x, x⁻¹, mul_inv_self _, inv_mul_self _⟩, inv_fun := coe, left_inv := Ξ» x, rfl, right_inv := Ξ» u, units.ext rfl, map_mul' := Ξ» x y, units.ext rfl } protected lemma group.is_unit {G} [group G] (x : G) : is_unit x := (to_units x).is_unit namespace units variables [monoid M] [monoid N] [monoid P] /-- A multiplicative equivalence of monoids defines a multiplicative equivalence of their groups of units. -/ def map_equiv (h : M ≃* N) : units M ≃* units N := { inv_fun := map h.symm.to_monoid_hom, left_inv := Ξ» u, ext $ h.left_inv u, right_inv := Ξ» u, ext $ h.right_inv u, .. map h.to_monoid_hom } /-- Left multiplication by a unit of a monoid is a permutation of the underlying type. -/ @[to_additive "Left addition of an additive unit is a permutation of the underlying type.", simps apply {fully_applied := ff}] def mul_left (u : units M) : equiv.perm M := { to_fun := Ξ»x, u * x, inv_fun := Ξ»x, ↑u⁻¹ * x, left_inv := u.inv_mul_cancel_left, right_inv := u.mul_inv_cancel_left } @[simp, to_additive] lemma mul_left_symm (u : units M) : u.mul_left.symm = u⁻¹.mul_left := equiv.ext $ Ξ» x, rfl /-- Right multiplication by a unit of a monoid is a permutation of the underlying type. -/ @[to_additive "Right addition of an additive unit is a permutation of the underlying type.", simps apply {fully_applied := ff}] def mul_right (u : units M) : equiv.perm M := { to_fun := Ξ»x, x * u, inv_fun := Ξ»x, x * ↑u⁻¹, left_inv := Ξ» x, mul_inv_cancel_right x u, right_inv := Ξ» x, inv_mul_cancel_right x u } @[simp, to_additive] lemma mul_right_symm (u : units M) : u.mul_right.symm = u⁻¹.mul_right := equiv.ext $ Ξ» x, rfl end units namespace equiv section group variables [group G] /-- Left multiplication in a `group` is a permutation of the underlying type. -/ @[to_additive "Left addition in an `add_group` is a permutation of the underlying type."] protected def mul_left (a : G) : perm G := (to_units a).mul_left @[simp, to_additive] lemma coe_mul_left (a : G) : ⇑(equiv.mul_left a) = (*) a := rfl /-- extra simp lemma that `dsimp` can use. `simp` will never use this. -/ @[simp, nolint simp_nf, to_additive] lemma mul_left_symm_apply (a : G) : ((equiv.mul_left a).symm : G β†’ G) = (*) a⁻¹ := rfl @[simp, to_additive] lemma mul_left_symm (a : G) : (equiv.mul_left a).symm = equiv.mul_left a⁻¹ := ext $ Ξ» x, rfl /-- Right multiplication in a `group` is a permutation of the underlying type. -/ @[to_additive "Right addition in an `add_group` is a permutation of the underlying type."] protected def mul_right (a : G) : perm G := (to_units a).mul_right @[simp, to_additive] lemma coe_mul_right (a : G) : ⇑(equiv.mul_right a) = Ξ» x, x * a := rfl @[simp, to_additive] lemma mul_right_symm (a : G) : (equiv.mul_right a).symm = equiv.mul_right a⁻¹ := ext $ Ξ» x, rfl /-- extra simp lemma that `dsimp` can use. `simp` will never use this. -/ @[simp, nolint simp_nf, to_additive] lemma mul_right_symm_apply (a : G) : ((equiv.mul_right a).symm : G β†’ G) = Ξ» x, x * a⁻¹ := rfl attribute [nolint simp_nf] add_left_symm_apply add_right_symm_apply variable (G) /-- Inversion on a `group` is a permutation of the underlying type. -/ @[to_additive "Negation on an `add_group` is a permutation of the underlying type.", simps apply {fully_applied := ff}] protected def inv : perm G := { to_fun := Ξ»a, a⁻¹, inv_fun := Ξ»a, a⁻¹, left_inv := assume a, inv_inv a, right_inv := assume a, inv_inv a } variable {G} @[simp, to_additive] lemma inv_symm : (equiv.inv G).symm = equiv.inv G := rfl end group section group_with_zero variables [group_with_zero G] /-- Left multiplication by a nonzero element in a `group_with_zero` is a permutation of the underlying type. -/ @[simps {fully_applied := ff}] protected def mul_left' (a : G) (ha : a β‰  0) : perm G := { to_fun := Ξ» x, a * x, inv_fun := Ξ» x, a⁻¹ * x, left_inv := Ξ» x, by { dsimp, rw [← mul_assoc, inv_mul_cancel ha, one_mul] }, right_inv := Ξ» x, by { dsimp, rw [← mul_assoc, mul_inv_cancel ha, one_mul] } } /-- Right multiplication by a nonzero element in a `group_with_zero` is a permutation of the underlying type. -/ @[simps {fully_applied := ff}] protected def mul_right' (a : G) (ha : a β‰  0) : perm G := { to_fun := Ξ» x, x * a, inv_fun := Ξ» x, x * a⁻¹, left_inv := Ξ» x, by { dsimp, rw [mul_assoc, mul_inv_cancel ha, mul_one] }, right_inv := Ξ» x, by { dsimp, rw [mul_assoc, inv_mul_cancel ha, mul_one] } } end group_with_zero end equiv /-- When the group is commutative, `equiv.inv` is a `mul_equiv`. There is a variant of this `mul_equiv.inv' G : G ≃* Gα΅’α΅–` for the non-commutative case. -/ @[to_additive "When the `add_group` is commutative, `equiv.neg` is an `add_equiv`."] def mul_equiv.inv (G : Type*) [comm_group G] : G ≃* G := { to_fun := has_inv.inv, inv_fun := has_inv.inv, map_mul' := mul_inv, ..equiv.inv G} section type_tags /-- Reinterpret `G ≃+ H` as `multiplicative G ≃* multiplicative H`. -/ def add_equiv.to_multiplicative [add_zero_class G] [add_zero_class H] : (G ≃+ H) ≃ (multiplicative G ≃* multiplicative H) := { to_fun := Ξ» f, ⟨f.to_add_monoid_hom.to_multiplicative, f.symm.to_add_monoid_hom.to_multiplicative, f.3, f.4, f.5⟩, inv_fun := Ξ» f, ⟨f.to_monoid_hom, f.symm.to_monoid_hom, f.3, f.4, f.5⟩, left_inv := Ξ» x, by { ext, refl, }, right_inv := Ξ» x, by { ext, refl, }, } /-- Reinterpret `G ≃* H` as `additive G ≃+ additive H`. -/ def mul_equiv.to_additive [mul_one_class G] [mul_one_class H] : (G ≃* H) ≃ (additive G ≃+ additive H) := { to_fun := Ξ» f, ⟨f.to_monoid_hom.to_additive, f.symm.to_monoid_hom.to_additive, f.3, f.4, f.5⟩, inv_fun := Ξ» f, ⟨f.to_add_monoid_hom, f.symm.to_add_monoid_hom, f.3, f.4, f.5⟩, left_inv := Ξ» x, by { ext, refl, }, right_inv := Ξ» x, by { ext, refl, }, } /-- Reinterpret `additive G ≃+ H` as `G ≃* multiplicative H`. -/ def add_equiv.to_multiplicative' [mul_one_class G] [add_zero_class H] : (additive G ≃+ H) ≃ (G ≃* multiplicative H) := { to_fun := Ξ» f, ⟨f.to_add_monoid_hom.to_multiplicative', f.symm.to_add_monoid_hom.to_multiplicative'', f.3, f.4, f.5⟩, inv_fun := Ξ» f, ⟨f.to_monoid_hom, f.symm.to_monoid_hom, f.3, f.4, f.5⟩, left_inv := Ξ» x, by { ext, refl, }, right_inv := Ξ» x, by { ext, refl, }, } /-- Reinterpret `G ≃* multiplicative H` as `additive G ≃+ H` as. -/ def mul_equiv.to_additive' [mul_one_class G] [add_zero_class H] : (G ≃* multiplicative H) ≃ (additive G ≃+ H) := add_equiv.to_multiplicative'.symm /-- Reinterpret `G ≃+ additive H` as `multiplicative G ≃* H`. -/ def add_equiv.to_multiplicative'' [add_zero_class G] [mul_one_class H] : (G ≃+ additive H) ≃ (multiplicative G ≃* H) := { to_fun := Ξ» f, ⟨f.to_add_monoid_hom.to_multiplicative'', f.symm.to_add_monoid_hom.to_multiplicative', f.3, f.4, f.5⟩, inv_fun := Ξ» f, ⟨f.to_monoid_hom, f.symm.to_monoid_hom, f.3, f.4, f.5⟩, left_inv := Ξ» x, by { ext, refl, }, right_inv := Ξ» x, by { ext, refl, }, } /-- Reinterpret `multiplicative G ≃* H` as `G ≃+ additive H` as. -/ def mul_equiv.to_additive'' [add_zero_class G] [mul_one_class H] : (multiplicative G ≃* H) ≃ (G ≃+ additive H) := add_equiv.to_multiplicative''.symm end type_tags
1b406b1eba7367e18cde91fec91eafc49f2cd0f3
94e33a31faa76775069b071adea97e86e218a8ee
/src/data/fintype/fin.lean
ba0a641d266d1d47c295c013f6c96c1a7ced0dc5
[ "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
1,207
lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import data.fin.interval /-! # The structure of `fintype (fin n)` This file contains some basic results about the `fintype` instance for `fin`, especially properties of `finset.univ : finset (fin n)`. -/ open finset open fintype namespace fin @[simp] lemma Ioi_zero_eq_map {n : β„•} : Ioi (0 : fin n.succ) = univ.map (fin.succ_embedding _).to_embedding := begin ext i, simp only [mem_Ioi, mem_map, mem_univ, function.embedding.coe_fn_mk, exists_true_left], split, { refine cases _ _ i, { rintro ⟨⟨⟩⟩ }, { intros j _, exact ⟨j, rfl⟩ } }, { rintro ⟨i, _, rfl⟩, exact succ_pos _ }, end @[simp] lemma Ioi_succ {n : β„•} (i : fin n) : Ioi i.succ = (Ioi i).map (fin.succ_embedding _).to_embedding := begin ext i, simp only [mem_filter, mem_Ioi, mem_map, mem_univ, true_and, function.embedding.coe_fn_mk, exists_true_left], split, { refine cases _ _ i, { rintro ⟨⟨⟩⟩ }, { intros i hi, refine ⟨i, succ_lt_succ_iff.mp hi, rfl⟩ } }, { rintro ⟨i, hi, rfl⟩, simpa }, end end fin
927adc813037f16a364086579898f0e02c4157f2
92b50235facfbc08dfe7f334827d47281471333b
/tests/lean/interactive/class_bug.lean
98d6edc9181854ff257db01514268076c6a9164f
[ "Apache-2.0" ]
permissive
htzh/lean
24f6ed7510ab637379ec31af406d12584d31792c
d70c79f4e30aafecdfc4a60b5d3512199200ab6e
refs/heads/master
1,607,677,731,270
1,437,089,952,000
1,437,089,952,000
37,078,816
0
0
null
1,433,780,956,000
1,433,780,955,000
null
UTF-8
Lean
false
false
176
lean
import logic.axioms.hilbert data.nat.basic open nonempty inhabited nat theorem int_inhabited [instance] : inhabited nat := inhabited.mk zero check epsilon (Ξ» x : nat, true)
fd83d3ecd6d11627541c43987347ef20531dd106
853df553b1d6ca524e3f0a79aedd32dde5d27ec3
/src/analysis/normed_space/hahn_banach.lean
d8bd90feeedb48d77c12f7d81919305aad82dc4c
[ "Apache-2.0" ]
permissive
DanielFabian/mathlib
efc3a50b5dde303c59eeb6353ef4c35a345d7112
f520d07eba0c852e96fe26da71d85bf6d40fcc2a
refs/heads/master
1,668,739,922,971
1,595,201,756,000
1,595,201,756,000
279,469,476
0
0
null
1,594,696,604,000
1,594,696,604,000
null
UTF-8
Lean
false
false
3,471
lean
/- Copyright (c) 2020 Yury Kudryashov All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Heather Macbeth -/ import analysis.normed_space.operator_norm import analysis.convex.cone /-! # Hahn-Banach theorem In this file we prove a version of Hahn-Banach theorem for continuous linear functions on normed spaces. We also prove a standard corollary, needed for the isometric inclusion in the double dual. ## TODO Prove more corollaries -/ section basic variables {E : Type*} [normed_group E] [normed_space ℝ E] /-- Hahn-Banach theorem for continuous linear functions. -/ theorem exists_extension_norm_eq (p : subspace ℝ E) (f : p β†’L[ℝ] ℝ) : βˆƒ g : E β†’L[ℝ] ℝ, (βˆ€ x : p, g x = f x) ∧ βˆ₯gβˆ₯ = βˆ₯fβˆ₯ := begin rcases exists_extension_of_le_sublinear ⟨p, f⟩ (Ξ» x, βˆ₯fβˆ₯ * βˆ₯xβˆ₯) (Ξ» c hc x, by simp only [norm_smul c x, real.norm_eq_abs, abs_of_pos hc, mul_left_comm]) (Ξ» x y, _) (Ξ» x, le_trans (le_abs_self _) (f.le_op_norm _)) with ⟨g, g_eq, g_le⟩, set g' := g.mk_continuous (βˆ₯fβˆ₯) (Ξ» x, abs_le.2 ⟨neg_le.1 $ g.map_neg x β–Έ norm_neg x β–Έ g_le (-x), g_le x⟩), { refine ⟨g', g_eq, _⟩, { apply le_antisymm (g.mk_continuous_norm_le (norm_nonneg f) _), refine f.op_norm_le_bound (norm_nonneg _) (Ξ» x, _), dsimp at g_eq, rw ← g_eq, apply g'.le_op_norm } }, { simp only [← mul_add], exact mul_le_mul_of_nonneg_left (norm_add_le x y) (norm_nonneg f) } end end basic section dual_vector variables {E : Type*} [normed_group E] [normed_space ℝ E] open continuous_linear_equiv open_locale classical lemma coord_self' (x : E) (h : x β‰  0) : (βˆ₯xβˆ₯ β€’ (coord ℝ x h)) ⟨x, submodule.mem_span_singleton_self x⟩ = βˆ₯xβˆ₯ := calc (βˆ₯xβˆ₯ β€’ (coord ℝ x h)) ⟨x, submodule.mem_span_singleton_self x⟩ = βˆ₯xβˆ₯ β€’ (linear_equiv.coord ℝ E x h) ⟨x, submodule.mem_span_singleton_self x⟩ : rfl ... = βˆ₯xβˆ₯ β€’ 1 : by rw linear_equiv.coord_self ℝ E x h ... = βˆ₯xβˆ₯ : mul_one _ lemma coord_norm' (x : E) (h : x β‰  0) : βˆ₯βˆ₯xβˆ₯ β€’ coord ℝ x hβˆ₯ = 1 := by rw [norm_smul, norm_norm, coord_norm, mul_inv_cancel (mt norm_eq_zero.mp h)] /-- Corollary of Hahn-Banach. Given a nonzero element `x` of a normed space, there exists an element of the dual space, of norm 1, whose value on `x` is `βˆ₯xβˆ₯`. -/ theorem exists_dual_vector (x : E) (h : x β‰  0) : βˆƒ g : E β†’L[ℝ] ℝ, βˆ₯gβˆ₯ = 1 ∧ g x = βˆ₯xβˆ₯ := begin cases exists_extension_norm_eq (submodule.span ℝ {x}) (βˆ₯xβˆ₯ β€’ coord ℝ x h) with g hg, use g, split, { rw [hg.2, coord_norm'] }, { calc g x = g (⟨x, submodule.mem_span_singleton_self x⟩ : submodule.span ℝ {x}) : by simp ... = (βˆ₯xβˆ₯ β€’ coord ℝ x h) (⟨x, submodule.mem_span_singleton_self x⟩ : submodule.span ℝ {x}) : by rw ← hg.1 ... = βˆ₯xβˆ₯ : by rw coord_self' } end /-- Variant of the above theorem, eliminating the hypothesis that `x` be nonzero, and choosing the dual element arbitrarily when `x = 0`. -/ theorem exists_dual_vector' [nontrivial E] (x : E) : βˆƒ g : E β†’L[ℝ] ℝ, βˆ₯gβˆ₯ = 1 ∧ g x = βˆ₯xβˆ₯ := begin by_cases hx : x = 0, { rcases exists_ne (0 : E) with ⟨y, hy⟩, cases exists_dual_vector y hy with g hg, use g, refine ⟨hg.left, _⟩, simp [hx] }, { exact exists_dual_vector x hx } end -- TODO: These corollaries are also true over β„‚. end dual_vector
308ce68da04d56d2db873e5c47068b130105196f
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/tests/lean/change2.lean
fd228caa9512ffacddbcdd2fefade5b86463980a
[ "Apache-2.0" ]
permissive
soonhokong/lean-osx
4a954262c780e404c1369d6c06516161d07fcb40
3670278342d2f4faa49d95b46d86642d7875b47c
refs/heads/master
1,611,410,334,552
1,474,425,686,000
1,474,425,686,000
12,043,103
5
1
null
null
null
null
UTF-8
Lean
false
false
473
lean
open tactic nat expr option attribute [defeq] definition succ_eq_add (n : nat) : succ n = n + 0 + 1 := rfl example (a b : nat) : a = b β†’ succ (succ a) = succ (b + 1) := by do intro `Heq, get_local `a >>= subst, trace_state, dsimp, trace "---- after dsimp ----", trace_state, t ← target, match (is_eq t) with | (some (lhs, rhs)) := do pr ← mk_app `eq.refl [lhs], exact pr | none := failed end
b65214d695e1fb8c7bd86583c03544e19a71dfd6
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/algebra/char_zero_auto.lean
8c988234eadfbf175570bfd95998be067c8b7626
[]
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,574
lean
/- Copyright (c) 2014 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro Natural homomorphism from the natural numbers into a monoid with one. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.nat.cast import Mathlib.data.fintype.basic import Mathlib.tactic.wlog import Mathlib.PostPort universes u_1 l namespace Mathlib /-- Typeclass for monoids with characteristic zero. (This is usually stated on fields but it makes sense for any additive monoid with 1.) -/ class char_zero (R : Type u_1) [add_monoid R] [HasOne R] where cast_injective : function.injective coe theorem char_zero_of_inj_zero {R : Type u_1} [add_left_cancel_monoid R] [HasOne R] (H : βˆ€ (n : β„•), ↑n = 0 β†’ n = 0) : char_zero R := sorry protected instance linear_ordered_semiring.to_char_zero {R : Type u_1} [linear_ordered_semiring R] : char_zero R := char_zero.mk (strict_mono.injective nat.strict_mono_cast) namespace nat theorem cast_injective {R : Type u_1} [add_monoid R] [HasOne R] [char_zero R] : function.injective coe := char_zero.cast_injective @[simp] theorem cast_inj {R : Type u_1} [add_monoid R] [HasOne R] [char_zero R] {m : β„•} {n : β„•} : ↑m = ↑n ↔ m = n := function.injective.eq_iff cast_injective @[simp] theorem cast_eq_zero {R : Type u_1} [add_monoid R] [HasOne R] [char_zero R] {n : β„•} : ↑n = 0 ↔ n = 0 := eq.mpr (id (Eq._oldrec (Eq.refl (↑n = 0 ↔ n = 0)) (Eq.symm cast_zero))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑n = ↑0 ↔ n = 0)) (propext cast_inj))) (iff.refl (n = 0))) theorem cast_ne_zero {R : Type u_1} [add_monoid R] [HasOne R] [char_zero R] {n : β„•} : ↑n β‰  0 ↔ n β‰  0 := not_congr cast_eq_zero theorem cast_add_one_ne_zero {R : Type u_1} [add_monoid R] [HasOne R] [char_zero R] (n : β„•) : ↑n + 1 β‰  0 := sorry @[simp] theorem cast_dvd_char_zero {k : Type u_1} [field k] [char_zero k] {m : β„•} {n : β„•} (n_dvd : n ∣ m) : ↑(m / n) = ↑m / ↑n := sorry end nat protected instance char_zero.infinite (M : Type u_1) [add_monoid M] [HasOne M] [char_zero M] : infinite M := infinite.of_injective coe nat.cast_injective theorem two_ne_zero' {M : Type u_1} [add_monoid M] [HasOne M] [char_zero M] : bit0 1 β‰  0 := (fun (this : ↑(bit0 1) β‰  0) => eq.mp (Eq._oldrec (Eq.refl (↑(bit0 1) β‰  0)) nat.cast_two) this) (iff.mpr nat.cast_ne_zero (of_as_true trivial)) theorem add_self_eq_zero {R : Type u_1} [semiring R] [no_zero_divisors R] [char_zero R] {a : R} : a + a = 0 ↔ a = 0 := sorry theorem bit0_eq_zero {R : Type u_1} [semiring R] [no_zero_divisors R] [char_zero R] {a : R} : bit0 a = 0 ↔ a = 0 := add_self_eq_zero @[simp] theorem half_add_self {R : Type u_1} [division_ring R] [char_zero R] (a : R) : (a + a) / bit0 1 = a := eq.mpr (id (Eq._oldrec (Eq.refl ((a + a) / bit0 1 = a)) (Eq.symm (mul_two a)))) (eq.mpr (id (Eq._oldrec (Eq.refl (a * bit0 1 / bit0 1 = a)) (mul_div_cancel a two_ne_zero'))) (Eq.refl a)) @[simp] theorem add_halves' {R : Type u_1} [division_ring R] [char_zero R] (a : R) : a / bit0 1 + a / bit0 1 = a := eq.mpr (id (Eq._oldrec (Eq.refl (a / bit0 1 + a / bit0 1 = a)) (Eq.symm (add_div a a (bit0 1))))) (eq.mpr (id (Eq._oldrec (Eq.refl ((a + a) / bit0 1 = a)) (half_add_self a))) (Eq.refl a)) theorem sub_half {R : Type u_1} [division_ring R] [char_zero R] (a : R) : a - a / bit0 1 = a / bit0 1 := eq.mpr (id (Eq._oldrec (Eq.refl (a - a / bit0 1 = a / bit0 1)) (propext sub_eq_iff_eq_add))) (eq.mpr (id (Eq._oldrec (Eq.refl (a = a / bit0 1 + a / bit0 1)) (add_halves' a))) (Eq.refl a)) theorem half_sub {R : Type u_1} [division_ring R] [char_zero R] (a : R) : a / bit0 1 - a = -(a / bit0 1) := eq.mpr (id (Eq._oldrec (Eq.refl (a / bit0 1 - a = -(a / bit0 1))) (Eq.symm (neg_sub a (a / bit0 1))))) (eq.mpr (id (Eq._oldrec (Eq.refl (-(a - a / bit0 1) = -(a / bit0 1))) (sub_half a))) (Eq.refl (-(a / bit0 1)))) namespace with_top protected instance char_zero {R : Type u_1} [add_monoid R] [HasOne R] [char_zero R] : char_zero (with_top R) := char_zero.mk fun (m n : β„•) (h : ↑m = ↑n) => eq.mp (Eq._oldrec (Eq.refl (↑m = ↑n)) (propext nat.cast_inj)) (eq.mp (Eq._oldrec (Eq.refl (↑↑m = ↑↑n)) (propext coe_eq_coe)) (eq.mp (Eq._oldrec (Eq.refl (↑↑m = ↑n)) (Eq.symm (coe_nat n))) (eq.mp (Eq._oldrec (Eq.refl (↑m = ↑n)) (Eq.symm (coe_nat m))) h))) end Mathlib
9cccc25a79eac5f4880e6e34a17691650f776b16
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/dynamics/flow_auto.lean
a01d0c5beb19166feddf53e3d0958b9bf6bdfb82
[]
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
7,694
lean
/- Copyright (c) 2020 Jean Lo. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jean Lo -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.topology.algebra.group import Mathlib.logic.function.iterate import Mathlib.PostPort universes u_1 u_2 l u_3 namespace Mathlib /-! # Flows and invariant sets This file defines a flow on a topological space `Ξ±` by a topological monoid `Ο„` as a continuous monoid-act of `Ο„` on `Ξ±`. Anticipating the cases where `Ο„` is one of `β„•`, `β„€`, `ℝ⁺`, or `ℝ`, we use additive notation for the monoids, though the definition does not require commutativity. A subset `s` of `Ξ±` is invariant under a family of maps `Ο•β‚œ : Ξ± β†’ Ξ±` if `Ο•β‚œ s βŠ† s` for all `t`. In many cases `Ο•` will be a flow on `Ξ±`. For the cases where `Ο•` is a flow by an ordered (additive, commutative) monoid, we additionally define forward invariance, where `t` ranges over those elements which are nonnegative. Additionally, we define such constructions as the restriction of a flow onto an invariant subset, and the time-reveral of a flow by a group. -/ /-! ### Invariant sets -/ /-- A set `s βŠ† Ξ±` is invariant under `Ο• : Ο„ β†’ Ξ± β†’ Ξ±` if `Ο• t s βŠ† s` for all `t` in `Ο„`. -/ def is_invariant {Ο„ : Type u_1} {Ξ± : Type u_2} (Ο• : Ο„ β†’ Ξ± β†’ Ξ±) (s : set Ξ±) := βˆ€ (t : Ο„), set.maps_to (Ο• t) s s theorem is_invariant_iff_image {Ο„ : Type u_1} {Ξ± : Type u_2} (Ο• : Ο„ β†’ Ξ± β†’ Ξ±) (s : set Ξ±) : is_invariant Ο• s ↔ βˆ€ (t : Ο„), Ο• t '' s βŠ† s := sorry /-- A set `s βŠ† Ξ±` is forward-invariant under `Ο• : Ο„ β†’ Ξ± β†’ Ξ±` if `Ο• t s βŠ† s` for all `t β‰₯ 0`. -/ def is_fw_invariant {Ο„ : Type u_1} {Ξ± : Type u_2} [preorder Ο„] [HasZero Ο„] (Ο• : Ο„ β†’ Ξ± β†’ Ξ±) (s : set Ξ±) := βˆ€ {t : Ο„}, 0 ≀ t β†’ set.maps_to (Ο• t) s s theorem is_invariant.is_fw_invariant {Ο„ : Type u_1} {Ξ± : Type u_2} [preorder Ο„] [HasZero Ο„] {Ο• : Ο„ β†’ Ξ± β†’ Ξ±} {s : set Ξ±} (h : is_invariant Ο• s) : is_fw_invariant Ο• s := fun (t : Ο„) (ht : 0 ≀ t) => h t /-- If `Ο„` is a `canonically_ordered_add_monoid` (e.g., `β„•` or `ℝβ‰₯0`), then the notions `is_fw_invariant` and `is_invariant` are equivalent. -/ theorem is_fw_invariant.is_invariant {Ο„ : Type u_1} {Ξ± : Type u_2} [canonically_ordered_add_monoid Ο„] {Ο• : Ο„ β†’ Ξ± β†’ Ξ±} {s : set Ξ±} (h : is_fw_invariant Ο• s) : is_invariant Ο• s := fun (t : Ο„) => h (zero_le t) /-- If `Ο„` is a `canonically_ordered_add_monoid` (e.g., `β„•` or `ℝβ‰₯0`), then the notions `is_fw_invariant` and `is_invariant` are equivalent. -/ theorem is_fw_invariant_iff_is_invariant {Ο„ : Type u_1} {Ξ± : Type u_2} [canonically_ordered_add_monoid Ο„] {Ο• : Ο„ β†’ Ξ± β†’ Ξ±} {s : set Ξ±} : is_fw_invariant Ο• s ↔ is_invariant Ο• s := { mp := is_fw_invariant.is_invariant, mpr := is_invariant.is_fw_invariant } /-! ### Flows -/ /-- A flow on a topological space `Ξ±` by an a additive topological monoid `Ο„` is a continuous monoid action of `Ο„` on `Ξ±`.-/ structure flow (Ο„ : Type u_1) [topological_space Ο„] [add_monoid Ο„] [has_continuous_add Ο„] (Ξ± : Type u_2) [topological_space Ξ±] where to_fun : Ο„ β†’ Ξ± β†’ Ξ± cont' : continuous (function.uncurry to_fun) map_add' : βˆ€ (t₁ tβ‚‚ : Ο„) (x : Ξ±), to_fun (t₁ + tβ‚‚) x = to_fun t₁ (to_fun tβ‚‚ x) map_zero' : βˆ€ (x : Ξ±), to_fun 0 x = x namespace flow protected instance inhabited {Ο„ : Type u_1} [add_monoid Ο„] [topological_space Ο„] [has_continuous_add Ο„] {Ξ± : Type u_2} [topological_space Ξ±] : Inhabited (flow Ο„ Ξ±) := { default := mk (fun (_x : Ο„) (x : Ξ±) => x) continuous_snd sorry sorry } protected instance has_coe_to_fun {Ο„ : Type u_1} [add_monoid Ο„] [topological_space Ο„] [has_continuous_add Ο„] {Ξ± : Type u_2} [topological_space Ξ±] : has_coe_to_fun (flow Ο„ Ξ±) := has_coe_to_fun.mk (fun (x : flow Ο„ Ξ±) => Ο„ β†’ Ξ± β†’ Ξ±) to_fun theorem ext {Ο„ : Type u_1} [add_monoid Ο„] [topological_space Ο„] [has_continuous_add Ο„] {Ξ± : Type u_2} [topological_space Ξ±] {ϕ₁ : flow Ο„ Ξ±} {Ο•β‚‚ : flow Ο„ Ξ±} : (βˆ€ (t : Ο„) (x : Ξ±), coe_fn ϕ₁ t x = coe_fn Ο•β‚‚ t x) β†’ ϕ₁ = Ο•β‚‚ := sorry protected theorem continuous {Ο„ : Type u_1} [add_monoid Ο„] [topological_space Ο„] [has_continuous_add Ο„] {Ξ± : Type u_2} [topological_space Ξ±] (Ο• : flow Ο„ Ξ±) {Ξ² : Type u_3} [topological_space Ξ²] {t : Ξ² β†’ Ο„} (ht : continuous t) {f : Ξ² β†’ Ξ±} (hf : continuous f) : continuous fun (x : Ξ²) => coe_fn Ο• (t x) (f x) := continuous.comp (cont' Ο•) (continuous.prod_mk ht hf) theorem Mathlib.continuous.flow {Ο„ : Type u_1} [add_monoid Ο„] [topological_space Ο„] [has_continuous_add Ο„] {Ξ± : Type u_2} [topological_space Ξ±] (Ο• : flow Ο„ Ξ±) {Ξ² : Type u_3} [topological_space Ξ²] {t : Ξ² β†’ Ο„} (ht : continuous t) {f : Ξ² β†’ Ξ±} (hf : continuous f) : continuous fun (x : Ξ²) => coe_fn Ο• (t x) (f x) := flow.continuous theorem map_add {Ο„ : Type u_1} [add_monoid Ο„] [topological_space Ο„] [has_continuous_add Ο„] {Ξ± : Type u_2} [topological_space Ξ±] (Ο• : flow Ο„ Ξ±) (t₁ : Ο„) (tβ‚‚ : Ο„) (x : Ξ±) : coe_fn Ο• (t₁ + tβ‚‚) x = coe_fn Ο• t₁ (coe_fn Ο• tβ‚‚ x) := map_add' Ο• t₁ tβ‚‚ x @[simp] theorem map_zero {Ο„ : Type u_1} [add_monoid Ο„] [topological_space Ο„] [has_continuous_add Ο„] {Ξ± : Type u_2} [topological_space Ξ±] (Ο• : flow Ο„ Ξ±) : coe_fn Ο• 0 = id := funext (map_zero' Ο•) theorem map_zero_apply {Ο„ : Type u_1} [add_monoid Ο„] [topological_space Ο„] [has_continuous_add Ο„] {Ξ± : Type u_2} [topological_space Ξ±] (Ο• : flow Ο„ Ξ±) (x : Ξ±) : coe_fn Ο• 0 x = x := map_zero' Ο• x /-- Iterations of a continuous function from a topological space `Ξ±` to itself defines a semiflow by `β„•` on `Ξ±`. -/ def from_iter {Ξ± : Type u_2} [topological_space Ξ±] {g : Ξ± β†’ Ξ±} (h : continuous g) : flow β„• Ξ± := mk (fun (n : β„•) (x : Ξ±) => nat.iterate g n x) sorry (function.iterate_add_apply g) sorry /-- Restriction of a flow onto an invariant set. -/ def restrict {Ο„ : Type u_1} [add_monoid Ο„] [topological_space Ο„] [has_continuous_add Ο„] {Ξ± : Type u_2} [topological_space Ξ±] (Ο• : flow Ο„ Ξ±) {s : set Ξ±} (h : is_invariant (⇑ϕ) s) : flow Ο„ β†₯s := mk (fun (t : Ο„) => set.maps_to.restrict (coe_fn Ο• t) s s (h t)) sorry sorry sorry end flow namespace flow theorem is_invariant_iff_image_eq {Ο„ : Type u_1} [add_comm_group Ο„] [topological_space Ο„] [topological_add_group Ο„] {Ξ± : Type u_2} [topological_space Ξ±] (Ο• : flow Ο„ Ξ±) (s : set Ξ±) : is_invariant (⇑ϕ) s ↔ βˆ€ (t : Ο„), coe_fn Ο• t '' s = s := sorry /-- The time-reversal of a flow `Ο•` by a (commutative, additive) group is defined `Ο•.reverse t x = Ο• (-t) x`. -/ def reverse {Ο„ : Type u_1} [add_comm_group Ο„] [topological_space Ο„] [topological_add_group Ο„] {Ξ± : Type u_2} [topological_space Ξ±] (Ο• : flow Ο„ Ξ±) : flow Ο„ Ξ± := mk (fun (t : Ο„) => coe_fn Ο• (-t)) sorry sorry sorry /-- The map `Ο• t` as a homeomorphism. -/ def to_homeomorph {Ο„ : Type u_1} [add_comm_group Ο„] [topological_space Ο„] [topological_add_group Ο„] {Ξ± : Type u_2} [topological_space Ξ±] (Ο• : flow Ο„ Ξ±) (t : Ο„) : Ξ± β‰ƒβ‚œ Ξ± := homeomorph.mk (equiv.mk (coe_fn Ο• t) (coe_fn Ο• (-t)) sorry sorry) theorem image_eq_preimage {Ο„ : Type u_1} [add_comm_group Ο„] [topological_space Ο„] [topological_add_group Ο„] {Ξ± : Type u_2} [topological_space Ξ±] (Ο• : flow Ο„ Ξ±) (t : Ο„) (s : set Ξ±) : coe_fn Ο• t '' s = coe_fn Ο• (-t) ⁻¹' s := equiv.image_eq_preimage (homeomorph.to_equiv (to_homeomorph Ο• t)) s end Mathlib
9bbfae13f0f38d5a9e4d1306cf920c5083ab092b
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/simpperf/pre1500.lean
ced75134ac012c58761fbc8e13532742b541e3d3
[ "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
129,030
lean
axiom f (x : Prop) : Prop axiom g0 (x : Prop) : Prop axiom g1 (x : Prop) : Prop axiom g2 (x : Prop) : Prop axiom g3 (x : Prop) : Prop axiom g4 (x : Prop) : Prop axiom g5 (x : Prop) : Prop axiom g6 (x : Prop) : Prop axiom g7 (x : Prop) : Prop axiom g8 (x : Prop) : Prop axiom g9 (x : Prop) : Prop axiom g10 (x : Prop) : Prop axiom g11 (x : Prop) : Prop axiom g12 (x : Prop) : Prop axiom g13 (x : Prop) : Prop axiom g14 (x : Prop) : Prop axiom g15 (x : Prop) : Prop axiom g16 (x : Prop) : Prop axiom g17 (x : Prop) : Prop axiom g18 (x : Prop) : Prop axiom g19 (x : Prop) : Prop axiom g20 (x : Prop) : Prop axiom g21 (x : Prop) : Prop axiom g22 (x : Prop) : Prop axiom g23 (x : Prop) : Prop axiom g24 (x : Prop) : Prop axiom g25 (x : Prop) : Prop axiom g26 (x : Prop) : Prop axiom g27 (x : Prop) : Prop axiom g28 (x : Prop) : Prop axiom g29 (x : Prop) : Prop axiom g30 (x : Prop) : Prop axiom g31 (x : Prop) : Prop axiom g32 (x : Prop) : Prop axiom g33 (x : Prop) : Prop axiom g34 (x : Prop) : Prop axiom g35 (x : Prop) : Prop axiom g36 (x : Prop) : Prop axiom g37 (x : Prop) : Prop axiom g38 (x : Prop) : Prop axiom g39 (x : Prop) : Prop axiom g40 (x : Prop) : Prop axiom g41 (x : Prop) : Prop axiom g42 (x : Prop) : Prop axiom g43 (x : Prop) : Prop axiom g44 (x : Prop) : Prop axiom g45 (x : Prop) : Prop axiom g46 (x : Prop) : Prop axiom g47 (x : Prop) : Prop axiom g48 (x : Prop) : Prop axiom g49 (x : Prop) : Prop axiom g50 (x : Prop) : Prop axiom g51 (x : Prop) : Prop axiom g52 (x : Prop) : Prop axiom g53 (x : Prop) : Prop axiom g54 (x : Prop) : Prop axiom g55 (x : Prop) : Prop axiom g56 (x : Prop) : Prop axiom g57 (x : Prop) : Prop axiom g58 (x : Prop) : Prop axiom g59 (x : Prop) : Prop axiom g60 (x : Prop) : Prop axiom g61 (x : Prop) : Prop axiom g62 (x : Prop) : Prop axiom g63 (x : Prop) : Prop axiom g64 (x : Prop) : Prop axiom g65 (x : Prop) : Prop axiom g66 (x : Prop) : Prop axiom g67 (x : Prop) : Prop axiom g68 (x : Prop) : Prop axiom g69 (x : Prop) : Prop axiom g70 (x : Prop) : Prop axiom g71 (x : Prop) : Prop axiom g72 (x : Prop) : Prop axiom g73 (x : Prop) : Prop axiom g74 (x : Prop) : Prop axiom g75 (x : Prop) : Prop axiom g76 (x : Prop) : Prop axiom g77 (x : Prop) : Prop axiom g78 (x : Prop) : Prop axiom g79 (x : Prop) : Prop axiom g80 (x : Prop) : Prop axiom g81 (x : Prop) : Prop axiom g82 (x : Prop) : Prop axiom g83 (x : Prop) : Prop axiom g84 (x : Prop) : Prop axiom g85 (x : Prop) : Prop axiom g86 (x : Prop) : Prop axiom g87 (x : Prop) : Prop axiom g88 (x : Prop) : Prop axiom g89 (x : Prop) : Prop axiom g90 (x : Prop) : Prop axiom g91 (x : Prop) : Prop axiom g92 (x : Prop) : Prop axiom g93 (x : Prop) : Prop axiom g94 (x : Prop) : Prop axiom g95 (x : Prop) : Prop axiom g96 (x : Prop) : Prop axiom g97 (x : Prop) : Prop axiom g98 (x : Prop) : Prop axiom g99 (x : Prop) : Prop axiom g100 (x : Prop) : Prop axiom g101 (x : Prop) : Prop axiom g102 (x : Prop) : Prop axiom g103 (x : Prop) : Prop axiom g104 (x : Prop) : Prop axiom g105 (x : Prop) : Prop axiom g106 (x : Prop) : Prop axiom g107 (x : Prop) : Prop axiom g108 (x : Prop) : Prop axiom g109 (x : Prop) : Prop axiom g110 (x : Prop) : Prop axiom g111 (x : Prop) : Prop axiom g112 (x : Prop) : Prop axiom g113 (x : Prop) : Prop axiom g114 (x : Prop) : Prop axiom g115 (x : Prop) : Prop axiom g116 (x : Prop) : Prop axiom g117 (x : Prop) : Prop axiom g118 (x : Prop) : Prop axiom g119 (x : Prop) : Prop axiom g120 (x : Prop) : Prop axiom g121 (x : Prop) : Prop axiom g122 (x : Prop) : Prop axiom g123 (x : Prop) : Prop axiom g124 (x : Prop) : Prop axiom g125 (x : Prop) : Prop axiom g126 (x : Prop) : Prop axiom g127 (x : Prop) : Prop axiom g128 (x : Prop) : Prop axiom g129 (x : Prop) : Prop axiom g130 (x : Prop) : Prop axiom g131 (x : Prop) : Prop axiom g132 (x : Prop) : Prop axiom g133 (x : Prop) : Prop axiom g134 (x : Prop) : Prop axiom g135 (x : Prop) : Prop axiom g136 (x : Prop) : Prop axiom g137 (x : Prop) : Prop axiom g138 (x : Prop) : Prop axiom g139 (x : Prop) : Prop axiom g140 (x : Prop) : Prop axiom g141 (x : Prop) : Prop axiom g142 (x : Prop) : Prop axiom g143 (x : Prop) : Prop axiom g144 (x : Prop) : Prop axiom g145 (x : Prop) : Prop axiom g146 (x : Prop) : Prop axiom g147 (x : Prop) : Prop axiom g148 (x : Prop) : Prop axiom g149 (x : Prop) : Prop axiom g150 (x : Prop) : Prop axiom g151 (x : Prop) : Prop axiom g152 (x : Prop) : Prop axiom g153 (x : Prop) : Prop axiom g154 (x : Prop) : Prop axiom g155 (x : Prop) : Prop axiom g156 (x : Prop) : Prop axiom g157 (x : Prop) : Prop axiom g158 (x : Prop) : Prop axiom g159 (x : Prop) : Prop axiom g160 (x : Prop) : Prop axiom g161 (x : Prop) : Prop axiom g162 (x : Prop) : Prop axiom g163 (x : Prop) : Prop axiom g164 (x : Prop) : Prop axiom g165 (x : Prop) : Prop axiom g166 (x : Prop) : Prop axiom g167 (x : Prop) : Prop axiom g168 (x : Prop) : Prop axiom g169 (x : Prop) : Prop axiom g170 (x : Prop) : Prop axiom g171 (x : Prop) : Prop axiom g172 (x : Prop) : Prop axiom g173 (x : Prop) : Prop axiom g174 (x : Prop) : Prop axiom g175 (x : Prop) : Prop axiom g176 (x : Prop) : Prop axiom g177 (x : Prop) : Prop axiom g178 (x : Prop) : Prop axiom g179 (x : Prop) : Prop axiom g180 (x : Prop) : Prop axiom g181 (x : Prop) : Prop axiom g182 (x : Prop) : Prop axiom g183 (x : Prop) : Prop axiom g184 (x : Prop) : Prop axiom g185 (x : Prop) : Prop axiom g186 (x : Prop) : Prop axiom g187 (x : Prop) : Prop axiom g188 (x : Prop) : Prop axiom g189 (x : Prop) : Prop axiom g190 (x : Prop) : Prop axiom g191 (x : Prop) : Prop axiom g192 (x : Prop) : Prop axiom g193 (x : Prop) : Prop axiom g194 (x : Prop) : Prop axiom g195 (x : Prop) : Prop axiom g196 (x : Prop) : Prop axiom g197 (x : Prop) : Prop axiom g198 (x : Prop) : Prop axiom g199 (x : Prop) : Prop axiom g200 (x : Prop) : Prop axiom g201 (x : Prop) : Prop axiom g202 (x : Prop) : Prop axiom g203 (x : Prop) : Prop axiom g204 (x : Prop) : Prop axiom g205 (x : Prop) : Prop axiom g206 (x : Prop) : Prop axiom g207 (x : Prop) : Prop axiom g208 (x : Prop) : Prop axiom g209 (x : Prop) : Prop axiom g210 (x : Prop) : Prop axiom g211 (x : Prop) : Prop axiom g212 (x : Prop) : Prop axiom g213 (x : Prop) : Prop axiom g214 (x : Prop) : Prop axiom g215 (x : Prop) : Prop axiom g216 (x : Prop) : Prop axiom g217 (x : Prop) : Prop axiom g218 (x : Prop) : Prop axiom g219 (x : Prop) : Prop axiom g220 (x : Prop) : Prop axiom g221 (x : Prop) : Prop axiom g222 (x : Prop) : Prop axiom g223 (x : Prop) : Prop axiom g224 (x : Prop) : Prop axiom g225 (x : Prop) : Prop axiom g226 (x : Prop) : Prop axiom g227 (x : Prop) : Prop axiom g228 (x : Prop) : Prop axiom g229 (x : Prop) : Prop axiom g230 (x : Prop) : Prop axiom g231 (x : Prop) : Prop axiom g232 (x : Prop) : Prop axiom g233 (x : Prop) : Prop axiom g234 (x : Prop) : Prop axiom g235 (x : Prop) : Prop axiom g236 (x : Prop) : Prop axiom g237 (x : Prop) : Prop axiom g238 (x : Prop) : Prop axiom g239 (x : Prop) : Prop axiom g240 (x : Prop) : Prop axiom g241 (x : Prop) : Prop axiom g242 (x : Prop) : Prop axiom g243 (x : Prop) : Prop axiom g244 (x : Prop) : Prop axiom g245 (x : Prop) : Prop axiom g246 (x : Prop) : Prop axiom g247 (x : Prop) : Prop axiom g248 (x : Prop) : Prop axiom g249 (x : Prop) : Prop axiom g250 (x : Prop) : Prop axiom g251 (x : Prop) : Prop axiom g252 (x : Prop) : Prop axiom g253 (x : Prop) : Prop axiom g254 (x : Prop) : Prop axiom g255 (x : Prop) : Prop axiom g256 (x : Prop) : Prop axiom g257 (x : Prop) : Prop axiom g258 (x : Prop) : Prop axiom g259 (x : Prop) : Prop axiom g260 (x : Prop) : Prop axiom g261 (x : Prop) : Prop axiom g262 (x : Prop) : Prop axiom g263 (x : Prop) : Prop axiom g264 (x : Prop) : Prop axiom g265 (x : Prop) : Prop axiom g266 (x : Prop) : Prop axiom g267 (x : Prop) : Prop axiom g268 (x : Prop) : Prop axiom g269 (x : Prop) : Prop axiom g270 (x : Prop) : Prop axiom g271 (x : Prop) : Prop axiom g272 (x : Prop) : Prop axiom g273 (x : Prop) : Prop axiom g274 (x : Prop) : Prop axiom g275 (x : Prop) : Prop axiom g276 (x : Prop) : Prop axiom g277 (x : Prop) : Prop axiom g278 (x : Prop) : Prop axiom g279 (x : Prop) : Prop axiom g280 (x : Prop) : Prop axiom g281 (x : Prop) : Prop axiom g282 (x : Prop) : Prop axiom g283 (x : Prop) : Prop axiom g284 (x : Prop) : Prop axiom g285 (x : Prop) : Prop axiom g286 (x : Prop) : Prop axiom g287 (x : Prop) : Prop axiom g288 (x : Prop) : Prop axiom g289 (x : Prop) : Prop axiom g290 (x : Prop) : Prop axiom g291 (x : Prop) : Prop axiom g292 (x : Prop) : Prop axiom g293 (x : Prop) : Prop axiom g294 (x : Prop) : Prop axiom g295 (x : Prop) : Prop axiom g296 (x : Prop) : Prop axiom g297 (x : Prop) : Prop axiom g298 (x : Prop) : Prop axiom g299 (x : Prop) : Prop axiom g300 (x : Prop) : Prop axiom g301 (x : Prop) : Prop axiom g302 (x : Prop) : Prop axiom g303 (x : Prop) : Prop axiom g304 (x : Prop) : Prop axiom g305 (x : Prop) : Prop axiom g306 (x : Prop) : Prop axiom g307 (x : Prop) : Prop axiom g308 (x : Prop) : Prop axiom g309 (x : Prop) : Prop axiom g310 (x : Prop) : Prop axiom g311 (x : Prop) : Prop axiom g312 (x : Prop) : Prop axiom g313 (x : Prop) : Prop axiom g314 (x : Prop) : Prop axiom g315 (x : Prop) : Prop axiom g316 (x : Prop) : Prop axiom g317 (x : Prop) : Prop axiom g318 (x : Prop) : Prop axiom g319 (x : Prop) : Prop axiom g320 (x : Prop) : Prop axiom g321 (x : Prop) : Prop axiom g322 (x : Prop) : Prop axiom g323 (x : Prop) : Prop axiom g324 (x : Prop) : Prop axiom g325 (x : Prop) : Prop axiom g326 (x : Prop) : Prop axiom g327 (x : Prop) : Prop axiom g328 (x : Prop) : Prop axiom g329 (x : Prop) : Prop axiom g330 (x : Prop) : Prop axiom g331 (x : Prop) : Prop axiom g332 (x : Prop) : Prop axiom g333 (x : Prop) : Prop axiom g334 (x : Prop) : Prop axiom g335 (x : Prop) : Prop axiom g336 (x : Prop) : Prop axiom g337 (x : Prop) : Prop axiom g338 (x : Prop) : Prop axiom g339 (x : Prop) : Prop axiom g340 (x : Prop) : Prop axiom g341 (x : Prop) : Prop axiom g342 (x : Prop) : Prop axiom g343 (x : Prop) : Prop axiom g344 (x : Prop) : Prop axiom g345 (x : Prop) : Prop axiom g346 (x : Prop) : Prop axiom g347 (x : Prop) : Prop axiom g348 (x : Prop) : Prop axiom g349 (x : Prop) : Prop axiom g350 (x : Prop) : Prop axiom g351 (x : Prop) : Prop axiom g352 (x : Prop) : Prop axiom g353 (x : Prop) : Prop axiom g354 (x : Prop) : Prop axiom g355 (x : Prop) : Prop axiom g356 (x : Prop) : Prop axiom g357 (x : Prop) : Prop axiom g358 (x : Prop) : Prop axiom g359 (x : Prop) : Prop axiom g360 (x : Prop) : Prop axiom g361 (x : Prop) : Prop axiom g362 (x : Prop) : Prop axiom g363 (x : Prop) : Prop axiom g364 (x : Prop) : Prop axiom g365 (x : Prop) : Prop axiom g366 (x : Prop) : Prop axiom g367 (x : Prop) : Prop axiom g368 (x : Prop) : Prop axiom g369 (x : Prop) : Prop axiom g370 (x : Prop) : Prop axiom g371 (x : Prop) : Prop axiom g372 (x : Prop) : Prop axiom g373 (x : Prop) : Prop axiom g374 (x : Prop) : Prop axiom g375 (x : Prop) : Prop axiom g376 (x : Prop) : Prop axiom g377 (x : Prop) : Prop axiom g378 (x : Prop) : Prop axiom g379 (x : Prop) : Prop axiom g380 (x : Prop) : Prop axiom g381 (x : Prop) : Prop axiom g382 (x : Prop) : Prop axiom g383 (x : Prop) : Prop axiom g384 (x : Prop) : Prop axiom g385 (x : Prop) : Prop axiom g386 (x : Prop) : Prop axiom g387 (x : Prop) : Prop axiom g388 (x : Prop) : Prop axiom g389 (x : Prop) : Prop axiom g390 (x : Prop) : Prop axiom g391 (x : Prop) : Prop axiom g392 (x : Prop) : Prop axiom g393 (x : Prop) : Prop axiom g394 (x : Prop) : Prop axiom g395 (x : Prop) : Prop axiom g396 (x : Prop) : Prop axiom g397 (x : Prop) : Prop axiom g398 (x : Prop) : Prop axiom g399 (x : Prop) : Prop axiom g400 (x : Prop) : Prop axiom g401 (x : Prop) : Prop axiom g402 (x : Prop) : Prop axiom g403 (x : Prop) : Prop axiom g404 (x : Prop) : Prop axiom g405 (x : Prop) : Prop axiom g406 (x : Prop) : Prop axiom g407 (x : Prop) : Prop axiom g408 (x : Prop) : Prop axiom g409 (x : Prop) : Prop axiom g410 (x : Prop) : Prop axiom g411 (x : Prop) : Prop axiom g412 (x : Prop) : Prop axiom g413 (x : Prop) : Prop axiom g414 (x : Prop) : Prop axiom g415 (x : Prop) : Prop axiom g416 (x : Prop) : Prop axiom g417 (x : Prop) : Prop axiom g418 (x : Prop) : Prop axiom g419 (x : Prop) : Prop axiom g420 (x : Prop) : Prop axiom g421 (x : Prop) : Prop axiom g422 (x : Prop) : Prop axiom g423 (x : Prop) : Prop axiom g424 (x : Prop) : Prop axiom g425 (x : Prop) : Prop axiom g426 (x : Prop) : Prop axiom g427 (x : Prop) : Prop axiom g428 (x : Prop) : Prop axiom g429 (x : Prop) : Prop axiom g430 (x : Prop) : Prop axiom g431 (x : Prop) : Prop axiom g432 (x : Prop) : Prop axiom g433 (x : Prop) : Prop axiom g434 (x : Prop) : Prop axiom g435 (x : Prop) : Prop axiom g436 (x : Prop) : Prop axiom g437 (x : Prop) : Prop axiom g438 (x : Prop) : Prop axiom g439 (x : Prop) : Prop axiom g440 (x : Prop) : Prop axiom g441 (x : Prop) : Prop axiom g442 (x : Prop) : Prop axiom g443 (x : Prop) : Prop axiom g444 (x : Prop) : Prop axiom g445 (x : Prop) : Prop axiom g446 (x : Prop) : Prop axiom g447 (x : Prop) : Prop axiom g448 (x : Prop) : Prop axiom g449 (x : Prop) : Prop axiom g450 (x : Prop) : Prop axiom g451 (x : Prop) : Prop axiom g452 (x : Prop) : Prop axiom g453 (x : Prop) : Prop axiom g454 (x : Prop) : Prop axiom g455 (x : Prop) : Prop axiom g456 (x : Prop) : Prop axiom g457 (x : Prop) : Prop axiom g458 (x : Prop) : Prop axiom g459 (x : Prop) : Prop axiom g460 (x : Prop) : Prop axiom g461 (x : Prop) : Prop axiom g462 (x : Prop) : Prop axiom g463 (x : Prop) : Prop axiom g464 (x : Prop) : Prop axiom g465 (x : Prop) : Prop axiom g466 (x : Prop) : Prop axiom g467 (x : Prop) : Prop axiom g468 (x : Prop) : Prop axiom g469 (x : Prop) : Prop axiom g470 (x : Prop) : Prop axiom g471 (x : Prop) : Prop axiom g472 (x : Prop) : Prop axiom g473 (x : Prop) : Prop axiom g474 (x : Prop) : Prop axiom g475 (x : Prop) : Prop axiom g476 (x : Prop) : Prop axiom g477 (x : Prop) : Prop axiom g478 (x : Prop) : Prop axiom g479 (x : Prop) : Prop axiom g480 (x : Prop) : Prop axiom g481 (x : Prop) : Prop axiom g482 (x : Prop) : Prop axiom g483 (x : Prop) : Prop axiom g484 (x : Prop) : Prop axiom g485 (x : Prop) : Prop axiom g486 (x : Prop) : Prop axiom g487 (x : Prop) : Prop axiom g488 (x : Prop) : Prop axiom g489 (x : Prop) : Prop axiom g490 (x : Prop) : Prop axiom g491 (x : Prop) : Prop axiom g492 (x : Prop) : Prop axiom g493 (x : Prop) : Prop axiom g494 (x : Prop) : Prop axiom g495 (x : Prop) : Prop axiom g496 (x : Prop) : Prop axiom g497 (x : Prop) : Prop axiom g498 (x : Prop) : Prop axiom g499 (x : Prop) : Prop axiom g500 (x : Prop) : Prop axiom g501 (x : Prop) : Prop axiom g502 (x : Prop) : Prop axiom g503 (x : Prop) : Prop axiom g504 (x : Prop) : Prop axiom g505 (x : Prop) : Prop axiom g506 (x : Prop) : Prop axiom g507 (x : Prop) : Prop axiom g508 (x : Prop) : Prop axiom g509 (x : Prop) : Prop axiom g510 (x : Prop) : Prop axiom g511 (x : Prop) : Prop axiom g512 (x : Prop) : Prop axiom g513 (x : Prop) : Prop axiom g514 (x : Prop) : Prop axiom g515 (x : Prop) : Prop axiom g516 (x : Prop) : Prop axiom g517 (x : Prop) : Prop axiom g518 (x : Prop) : Prop axiom g519 (x : Prop) : Prop axiom g520 (x : Prop) : Prop axiom g521 (x : Prop) : Prop axiom g522 (x : Prop) : Prop axiom g523 (x : Prop) : Prop axiom g524 (x : Prop) : Prop axiom g525 (x : Prop) : Prop axiom g526 (x : Prop) : Prop axiom g527 (x : Prop) : Prop axiom g528 (x : Prop) : Prop axiom g529 (x : Prop) : Prop axiom g530 (x : Prop) : Prop axiom g531 (x : Prop) : Prop axiom g532 (x : Prop) : Prop axiom g533 (x : Prop) : Prop axiom g534 (x : Prop) : Prop axiom g535 (x : Prop) : Prop axiom g536 (x : Prop) : Prop axiom g537 (x : Prop) : Prop axiom g538 (x : Prop) : Prop axiom g539 (x : Prop) : Prop axiom g540 (x : Prop) : Prop axiom g541 (x : Prop) : Prop axiom g542 (x : Prop) : Prop axiom g543 (x : Prop) : Prop axiom g544 (x : Prop) : Prop axiom g545 (x : Prop) : Prop axiom g546 (x : Prop) : Prop axiom g547 (x : Prop) : Prop axiom g548 (x : Prop) : Prop axiom g549 (x : Prop) : Prop axiom g550 (x : Prop) : Prop axiom g551 (x : Prop) : Prop axiom g552 (x : Prop) : Prop axiom g553 (x : Prop) : Prop axiom g554 (x : Prop) : Prop axiom g555 (x : Prop) : Prop axiom g556 (x : Prop) : Prop axiom g557 (x : Prop) : Prop axiom g558 (x : Prop) : Prop axiom g559 (x : Prop) : Prop axiom g560 (x : Prop) : Prop axiom g561 (x : Prop) : Prop axiom g562 (x : Prop) : Prop axiom g563 (x : Prop) : Prop axiom g564 (x : Prop) : Prop axiom g565 (x : Prop) : Prop axiom g566 (x : Prop) : Prop axiom g567 (x : Prop) : Prop axiom g568 (x : Prop) : Prop axiom g569 (x : Prop) : Prop axiom g570 (x : Prop) : Prop axiom g571 (x : Prop) : Prop axiom g572 (x : Prop) : Prop axiom g573 (x : Prop) : Prop axiom g574 (x : Prop) : Prop axiom g575 (x : Prop) : Prop axiom g576 (x : Prop) : Prop axiom g577 (x : Prop) : Prop axiom g578 (x : Prop) : Prop axiom g579 (x : Prop) : Prop axiom g580 (x : Prop) : Prop axiom g581 (x : Prop) : Prop axiom g582 (x : Prop) : Prop axiom g583 (x : Prop) : Prop axiom g584 (x : Prop) : Prop axiom g585 (x : Prop) : Prop axiom g586 (x : Prop) : Prop axiom g587 (x : Prop) : Prop axiom g588 (x : Prop) : Prop axiom g589 (x : Prop) : Prop axiom g590 (x : Prop) : Prop axiom g591 (x : Prop) : Prop axiom g592 (x : Prop) : Prop axiom g593 (x : Prop) : Prop axiom g594 (x : Prop) : Prop axiom g595 (x : Prop) : Prop axiom g596 (x : Prop) : Prop axiom g597 (x : Prop) : Prop axiom g598 (x : Prop) : Prop axiom g599 (x : Prop) : Prop axiom g600 (x : Prop) : Prop axiom g601 (x : Prop) : Prop axiom g602 (x : Prop) : Prop axiom g603 (x : Prop) : Prop axiom g604 (x : Prop) : Prop axiom g605 (x : Prop) : Prop axiom g606 (x : Prop) : Prop axiom g607 (x : Prop) : Prop axiom g608 (x : Prop) : Prop axiom g609 (x : Prop) : Prop axiom g610 (x : Prop) : Prop axiom g611 (x : Prop) : Prop axiom g612 (x : Prop) : Prop axiom g613 (x : Prop) : Prop axiom g614 (x : Prop) : Prop axiom g615 (x : Prop) : Prop axiom g616 (x : Prop) : Prop axiom g617 (x : Prop) : Prop axiom g618 (x : Prop) : Prop axiom g619 (x : Prop) : Prop axiom g620 (x : Prop) : Prop axiom g621 (x : Prop) : Prop axiom g622 (x : Prop) : Prop axiom g623 (x : Prop) : Prop axiom g624 (x : Prop) : Prop axiom g625 (x : Prop) : Prop axiom g626 (x : Prop) : Prop axiom g627 (x : Prop) : Prop axiom g628 (x : Prop) : Prop axiom g629 (x : Prop) : Prop axiom g630 (x : Prop) : Prop axiom g631 (x : Prop) : Prop axiom g632 (x : Prop) : Prop axiom g633 (x : Prop) : Prop axiom g634 (x : Prop) : Prop axiom g635 (x : Prop) : Prop axiom g636 (x : Prop) : Prop axiom g637 (x : Prop) : Prop axiom g638 (x : Prop) : Prop axiom g639 (x : Prop) : Prop axiom g640 (x : Prop) : Prop axiom g641 (x : Prop) : Prop axiom g642 (x : Prop) : Prop axiom g643 (x : Prop) : Prop axiom g644 (x : Prop) : Prop axiom g645 (x : Prop) : Prop axiom g646 (x : Prop) : Prop axiom g647 (x : Prop) : Prop axiom g648 (x : Prop) : Prop axiom g649 (x : Prop) : Prop axiom g650 (x : Prop) : Prop axiom g651 (x : Prop) : Prop axiom g652 (x : Prop) : Prop axiom g653 (x : Prop) : Prop axiom g654 (x : Prop) : Prop axiom g655 (x : Prop) : Prop axiom g656 (x : Prop) : Prop axiom g657 (x : Prop) : Prop axiom g658 (x : Prop) : Prop axiom g659 (x : Prop) : Prop axiom g660 (x : Prop) : Prop axiom g661 (x : Prop) : Prop axiom g662 (x : Prop) : Prop axiom g663 (x : Prop) : Prop axiom g664 (x : Prop) : Prop axiom g665 (x : Prop) : Prop axiom g666 (x : Prop) : Prop axiom g667 (x : Prop) : Prop axiom g668 (x : Prop) : Prop axiom g669 (x : Prop) : Prop axiom g670 (x : Prop) : Prop axiom g671 (x : Prop) : Prop axiom g672 (x : Prop) : Prop axiom g673 (x : Prop) : Prop axiom g674 (x : Prop) : Prop axiom g675 (x : Prop) : Prop axiom g676 (x : Prop) : Prop axiom g677 (x : Prop) : Prop axiom g678 (x : Prop) : Prop axiom g679 (x : Prop) : Prop axiom g680 (x : Prop) : Prop axiom g681 (x : Prop) : Prop axiom g682 (x : Prop) : Prop axiom g683 (x : Prop) : Prop axiom g684 (x : Prop) : Prop axiom g685 (x : Prop) : Prop axiom g686 (x : Prop) : Prop axiom g687 (x : Prop) : Prop axiom g688 (x : Prop) : Prop axiom g689 (x : Prop) : Prop axiom g690 (x : Prop) : Prop axiom g691 (x : Prop) : Prop axiom g692 (x : Prop) : Prop axiom g693 (x : Prop) : Prop axiom g694 (x : Prop) : Prop axiom g695 (x : Prop) : Prop axiom g696 (x : Prop) : Prop axiom g697 (x : Prop) : Prop axiom g698 (x : Prop) : Prop axiom g699 (x : Prop) : Prop axiom g700 (x : Prop) : Prop axiom g701 (x : Prop) : Prop axiom g702 (x : Prop) : Prop axiom g703 (x : Prop) : Prop axiom g704 (x : Prop) : Prop axiom g705 (x : Prop) : Prop axiom g706 (x : Prop) : Prop axiom g707 (x : Prop) : Prop axiom g708 (x : Prop) : Prop axiom g709 (x : Prop) : Prop axiom g710 (x : Prop) : Prop axiom g711 (x : Prop) : Prop axiom g712 (x : Prop) : Prop axiom g713 (x : Prop) : Prop axiom g714 (x : Prop) : Prop axiom g715 (x : Prop) : Prop axiom g716 (x : Prop) : Prop axiom g717 (x : Prop) : Prop axiom g718 (x : Prop) : Prop axiom g719 (x : Prop) : Prop axiom g720 (x : Prop) : Prop axiom g721 (x : Prop) : Prop axiom g722 (x : Prop) : Prop axiom g723 (x : Prop) : Prop axiom g724 (x : Prop) : Prop axiom g725 (x : Prop) : Prop axiom g726 (x : Prop) : Prop axiom g727 (x : Prop) : Prop axiom g728 (x : Prop) : Prop axiom g729 (x : Prop) : Prop axiom g730 (x : Prop) : Prop axiom g731 (x : Prop) : Prop axiom g732 (x : Prop) : Prop axiom g733 (x : Prop) : Prop axiom g734 (x : Prop) : Prop axiom g735 (x : Prop) : Prop axiom g736 (x : Prop) : Prop axiom g737 (x : Prop) : Prop axiom g738 (x : Prop) : Prop axiom g739 (x : Prop) : Prop axiom g740 (x : Prop) : Prop axiom g741 (x : Prop) : Prop axiom g742 (x : Prop) : Prop axiom g743 (x : Prop) : Prop axiom g744 (x : Prop) : Prop axiom g745 (x : Prop) : Prop axiom g746 (x : Prop) : Prop axiom g747 (x : Prop) : Prop axiom g748 (x : Prop) : Prop axiom g749 (x : Prop) : Prop axiom g750 (x : Prop) : Prop axiom g751 (x : Prop) : Prop axiom g752 (x : Prop) : Prop axiom g753 (x : Prop) : Prop axiom g754 (x : Prop) : Prop axiom g755 (x : Prop) : Prop axiom g756 (x : Prop) : Prop axiom g757 (x : Prop) : Prop axiom g758 (x : Prop) : Prop axiom g759 (x : Prop) : Prop axiom g760 (x : Prop) : Prop axiom g761 (x : Prop) : Prop axiom g762 (x : Prop) : Prop axiom g763 (x : Prop) : Prop axiom g764 (x : Prop) : Prop axiom g765 (x : Prop) : Prop axiom g766 (x : Prop) : Prop axiom g767 (x : Prop) : Prop axiom g768 (x : Prop) : Prop axiom g769 (x : Prop) : Prop axiom g770 (x : Prop) : Prop axiom g771 (x : Prop) : Prop axiom g772 (x : Prop) : Prop axiom g773 (x : Prop) : Prop axiom g774 (x : Prop) : Prop axiom g775 (x : Prop) : Prop axiom g776 (x : Prop) : Prop axiom g777 (x : Prop) : Prop axiom g778 (x : Prop) : Prop axiom g779 (x : Prop) : Prop axiom g780 (x : Prop) : Prop axiom g781 (x : Prop) : Prop axiom g782 (x : Prop) : Prop axiom g783 (x : Prop) : Prop axiom g784 (x : Prop) : Prop axiom g785 (x : Prop) : Prop axiom g786 (x : Prop) : Prop axiom g787 (x : Prop) : Prop axiom g788 (x : Prop) : Prop axiom g789 (x : Prop) : Prop axiom g790 (x : Prop) : Prop axiom g791 (x : Prop) : Prop axiom g792 (x : Prop) : Prop axiom g793 (x : Prop) : Prop axiom g794 (x : Prop) : Prop axiom g795 (x : Prop) : Prop axiom g796 (x : Prop) : Prop axiom g797 (x : Prop) : Prop axiom g798 (x : Prop) : Prop axiom g799 (x : Prop) : Prop axiom g800 (x : Prop) : Prop axiom g801 (x : Prop) : Prop axiom g802 (x : Prop) : Prop axiom g803 (x : Prop) : Prop axiom g804 (x : Prop) : Prop axiom g805 (x : Prop) : Prop axiom g806 (x : Prop) : Prop axiom g807 (x : Prop) : Prop axiom g808 (x : Prop) : Prop axiom g809 (x : Prop) : Prop axiom g810 (x : Prop) : Prop axiom g811 (x : Prop) : Prop axiom g812 (x : Prop) : Prop axiom g813 (x : Prop) : Prop axiom g814 (x : Prop) : Prop axiom g815 (x : Prop) : Prop axiom g816 (x : Prop) : Prop axiom g817 (x : Prop) : Prop axiom g818 (x : Prop) : Prop axiom g819 (x : Prop) : Prop axiom g820 (x : Prop) : Prop axiom g821 (x : Prop) : Prop axiom g822 (x : Prop) : Prop axiom g823 (x : Prop) : Prop axiom g824 (x : Prop) : Prop axiom g825 (x : Prop) : Prop axiom g826 (x : Prop) : Prop axiom g827 (x : Prop) : Prop axiom g828 (x : Prop) : Prop axiom g829 (x : Prop) : Prop axiom g830 (x : Prop) : Prop axiom g831 (x : Prop) : Prop axiom g832 (x : Prop) : Prop axiom g833 (x : Prop) : Prop axiom g834 (x : Prop) : Prop axiom g835 (x : Prop) : Prop axiom g836 (x : Prop) : Prop axiom g837 (x : Prop) : Prop axiom g838 (x : Prop) : Prop axiom g839 (x : Prop) : Prop axiom g840 (x : Prop) : Prop axiom g841 (x : Prop) : Prop axiom g842 (x : Prop) : Prop axiom g843 (x : Prop) : Prop axiom g844 (x : Prop) : Prop axiom g845 (x : Prop) : Prop axiom g846 (x : Prop) : Prop axiom g847 (x : Prop) : Prop axiom g848 (x : Prop) : Prop axiom g849 (x : Prop) : Prop axiom g850 (x : Prop) : Prop axiom g851 (x : Prop) : Prop axiom g852 (x : Prop) : Prop axiom g853 (x : Prop) : Prop axiom g854 (x : Prop) : Prop axiom g855 (x : Prop) : Prop axiom g856 (x : Prop) : Prop axiom g857 (x : Prop) : Prop axiom g858 (x : Prop) : Prop axiom g859 (x : Prop) : Prop axiom g860 (x : Prop) : Prop axiom g861 (x : Prop) : Prop axiom g862 (x : Prop) : Prop axiom g863 (x : Prop) : Prop axiom g864 (x : Prop) : Prop axiom g865 (x : Prop) : Prop axiom g866 (x : Prop) : Prop axiom g867 (x : Prop) : Prop axiom g868 (x : Prop) : Prop axiom g869 (x : Prop) : Prop axiom g870 (x : Prop) : Prop axiom g871 (x : Prop) : Prop axiom g872 (x : Prop) : Prop axiom g873 (x : Prop) : Prop axiom g874 (x : Prop) : Prop axiom g875 (x : Prop) : Prop axiom g876 (x : Prop) : Prop axiom g877 (x : Prop) : Prop axiom g878 (x : Prop) : Prop axiom g879 (x : Prop) : Prop axiom g880 (x : Prop) : Prop axiom g881 (x : Prop) : Prop axiom g882 (x : Prop) : Prop axiom g883 (x : Prop) : Prop axiom g884 (x : Prop) : Prop axiom g885 (x : Prop) : Prop axiom g886 (x : Prop) : Prop axiom g887 (x : Prop) : Prop axiom g888 (x : Prop) : Prop axiom g889 (x : Prop) : Prop axiom g890 (x : Prop) : Prop axiom g891 (x : Prop) : Prop axiom g892 (x : Prop) : Prop axiom g893 (x : Prop) : Prop axiom g894 (x : Prop) : Prop axiom g895 (x : Prop) : Prop axiom g896 (x : Prop) : Prop axiom g897 (x : Prop) : Prop axiom g898 (x : Prop) : Prop axiom g899 (x : Prop) : Prop axiom g900 (x : Prop) : Prop axiom g901 (x : Prop) : Prop axiom g902 (x : Prop) : Prop axiom g903 (x : Prop) : Prop axiom g904 (x : Prop) : Prop axiom g905 (x : Prop) : Prop axiom g906 (x : Prop) : Prop axiom g907 (x : Prop) : Prop axiom g908 (x : Prop) : Prop axiom g909 (x : Prop) : Prop axiom g910 (x : Prop) : Prop axiom g911 (x : Prop) : Prop axiom g912 (x : Prop) : Prop axiom g913 (x : Prop) : Prop axiom g914 (x : Prop) : Prop axiom g915 (x : Prop) : Prop axiom g916 (x : Prop) : Prop axiom g917 (x : Prop) : Prop axiom g918 (x : Prop) : Prop axiom g919 (x : Prop) : Prop axiom g920 (x : Prop) : Prop axiom g921 (x : Prop) : Prop axiom g922 (x : Prop) : Prop axiom g923 (x : Prop) : Prop axiom g924 (x : Prop) : Prop axiom g925 (x : Prop) : Prop axiom g926 (x : Prop) : Prop axiom g927 (x : Prop) : Prop axiom g928 (x : Prop) : Prop axiom g929 (x : Prop) : Prop axiom g930 (x : Prop) : Prop axiom g931 (x : Prop) : Prop axiom g932 (x : Prop) : Prop axiom g933 (x : Prop) : Prop axiom g934 (x : Prop) : Prop axiom g935 (x : Prop) : Prop axiom g936 (x : Prop) : Prop axiom g937 (x : Prop) : Prop axiom g938 (x : Prop) : Prop axiom g939 (x : Prop) : Prop axiom g940 (x : Prop) : Prop axiom g941 (x : Prop) : Prop axiom g942 (x : Prop) : Prop axiom g943 (x : Prop) : Prop axiom g944 (x : Prop) : Prop axiom g945 (x : Prop) : Prop axiom g946 (x : Prop) : Prop axiom g947 (x : Prop) : Prop axiom g948 (x : Prop) : Prop axiom g949 (x : Prop) : Prop axiom g950 (x : Prop) : Prop axiom g951 (x : Prop) : Prop axiom g952 (x : Prop) : Prop axiom g953 (x : Prop) : Prop axiom g954 (x : Prop) : Prop axiom g955 (x : Prop) : Prop axiom g956 (x : Prop) : Prop axiom g957 (x : Prop) : Prop axiom g958 (x : Prop) : Prop axiom g959 (x : Prop) : Prop axiom g960 (x : Prop) : Prop axiom g961 (x : Prop) : Prop axiom g962 (x : Prop) : Prop axiom g963 (x : Prop) : Prop axiom g964 (x : Prop) : Prop axiom g965 (x : Prop) : Prop axiom g966 (x : Prop) : Prop axiom g967 (x : Prop) : Prop axiom g968 (x : Prop) : Prop axiom g969 (x : Prop) : Prop axiom g970 (x : Prop) : Prop axiom g971 (x : Prop) : Prop axiom g972 (x : Prop) : Prop axiom g973 (x : Prop) : Prop axiom g974 (x : Prop) : Prop axiom g975 (x : Prop) : Prop axiom g976 (x : Prop) : Prop axiom g977 (x : Prop) : Prop axiom g978 (x : Prop) : Prop axiom g979 (x : Prop) : Prop axiom g980 (x : Prop) : Prop axiom g981 (x : Prop) : Prop axiom g982 (x : Prop) : Prop axiom g983 (x : Prop) : Prop axiom g984 (x : Prop) : Prop axiom g985 (x : Prop) : Prop axiom g986 (x : Prop) : Prop axiom g987 (x : Prop) : Prop axiom g988 (x : Prop) : Prop axiom g989 (x : Prop) : Prop axiom g990 (x : Prop) : Prop axiom g991 (x : Prop) : Prop axiom g992 (x : Prop) : Prop axiom g993 (x : Prop) : Prop axiom g994 (x : Prop) : Prop axiom g995 (x : Prop) : Prop axiom g996 (x : Prop) : Prop axiom g997 (x : Prop) : Prop axiom g998 (x : Prop) : Prop axiom g999 (x : Prop) : Prop axiom g1000 (x : Prop) : Prop axiom g1001 (x : Prop) : Prop axiom g1002 (x : Prop) : Prop axiom g1003 (x : Prop) : Prop axiom g1004 (x : Prop) : Prop axiom g1005 (x : Prop) : Prop axiom g1006 (x : Prop) : Prop axiom g1007 (x : Prop) : Prop axiom g1008 (x : Prop) : Prop axiom g1009 (x : Prop) : Prop axiom g1010 (x : Prop) : Prop axiom g1011 (x : Prop) : Prop axiom g1012 (x : Prop) : Prop axiom g1013 (x : Prop) : Prop axiom g1014 (x : Prop) : Prop axiom g1015 (x : Prop) : Prop axiom g1016 (x : Prop) : Prop axiom g1017 (x : Prop) : Prop axiom g1018 (x : Prop) : Prop axiom g1019 (x : Prop) : Prop axiom g1020 (x : Prop) : Prop axiom g1021 (x : Prop) : Prop axiom g1022 (x : Prop) : Prop axiom g1023 (x : Prop) : Prop axiom g1024 (x : Prop) : Prop axiom g1025 (x : Prop) : Prop axiom g1026 (x : Prop) : Prop axiom g1027 (x : Prop) : Prop axiom g1028 (x : Prop) : Prop axiom g1029 (x : Prop) : Prop axiom g1030 (x : Prop) : Prop axiom g1031 (x : Prop) : Prop axiom g1032 (x : Prop) : Prop axiom g1033 (x : Prop) : Prop axiom g1034 (x : Prop) : Prop axiom g1035 (x : Prop) : Prop axiom g1036 (x : Prop) : Prop axiom g1037 (x : Prop) : Prop axiom g1038 (x : Prop) : Prop axiom g1039 (x : Prop) : Prop axiom g1040 (x : Prop) : Prop axiom g1041 (x : Prop) : Prop axiom g1042 (x : Prop) : Prop axiom g1043 (x : Prop) : Prop axiom g1044 (x : Prop) : Prop axiom g1045 (x : Prop) : Prop axiom g1046 (x : Prop) : Prop axiom g1047 (x : Prop) : Prop axiom g1048 (x : Prop) : Prop axiom g1049 (x : Prop) : Prop axiom g1050 (x : Prop) : Prop axiom g1051 (x : Prop) : Prop axiom g1052 (x : Prop) : Prop axiom g1053 (x : Prop) : Prop axiom g1054 (x : Prop) : Prop axiom g1055 (x : Prop) : Prop axiom g1056 (x : Prop) : Prop axiom g1057 (x : Prop) : Prop axiom g1058 (x : Prop) : Prop axiom g1059 (x : Prop) : Prop axiom g1060 (x : Prop) : Prop axiom g1061 (x : Prop) : Prop axiom g1062 (x : Prop) : Prop axiom g1063 (x : Prop) : Prop axiom g1064 (x : Prop) : Prop axiom g1065 (x : Prop) : Prop axiom g1066 (x : Prop) : Prop axiom g1067 (x : Prop) : Prop axiom g1068 (x : Prop) : Prop axiom g1069 (x : Prop) : Prop axiom g1070 (x : Prop) : Prop axiom g1071 (x : Prop) : Prop axiom g1072 (x : Prop) : Prop axiom g1073 (x : Prop) : Prop axiom g1074 (x : Prop) : Prop axiom g1075 (x : Prop) : Prop axiom g1076 (x : Prop) : Prop axiom g1077 (x : Prop) : Prop axiom g1078 (x : Prop) : Prop axiom g1079 (x : Prop) : Prop axiom g1080 (x : Prop) : Prop axiom g1081 (x : Prop) : Prop axiom g1082 (x : Prop) : Prop axiom g1083 (x : Prop) : Prop axiom g1084 (x : Prop) : Prop axiom g1085 (x : Prop) : Prop axiom g1086 (x : Prop) : Prop axiom g1087 (x : Prop) : Prop axiom g1088 (x : Prop) : Prop axiom g1089 (x : Prop) : Prop axiom g1090 (x : Prop) : Prop axiom g1091 (x : Prop) : Prop axiom g1092 (x : Prop) : Prop axiom g1093 (x : Prop) : Prop axiom g1094 (x : Prop) : Prop axiom g1095 (x : Prop) : Prop axiom g1096 (x : Prop) : Prop axiom g1097 (x : Prop) : Prop axiom g1098 (x : Prop) : Prop axiom g1099 (x : Prop) : Prop axiom g1100 (x : Prop) : Prop axiom g1101 (x : Prop) : Prop axiom g1102 (x : Prop) : Prop axiom g1103 (x : Prop) : Prop axiom g1104 (x : Prop) : Prop axiom g1105 (x : Prop) : Prop axiom g1106 (x : Prop) : Prop axiom g1107 (x : Prop) : Prop axiom g1108 (x : Prop) : Prop axiom g1109 (x : Prop) : Prop axiom g1110 (x : Prop) : Prop axiom g1111 (x : Prop) : Prop axiom g1112 (x : Prop) : Prop axiom g1113 (x : Prop) : Prop axiom g1114 (x : Prop) : Prop axiom g1115 (x : Prop) : Prop axiom g1116 (x : Prop) : Prop axiom g1117 (x : Prop) : Prop axiom g1118 (x : Prop) : Prop axiom g1119 (x : Prop) : Prop axiom g1120 (x : Prop) : Prop axiom g1121 (x : Prop) : Prop axiom g1122 (x : Prop) : Prop axiom g1123 (x : Prop) : Prop axiom g1124 (x : Prop) : Prop axiom g1125 (x : Prop) : Prop axiom g1126 (x : Prop) : Prop axiom g1127 (x : Prop) : Prop axiom g1128 (x : Prop) : Prop axiom g1129 (x : Prop) : Prop axiom g1130 (x : Prop) : Prop axiom g1131 (x : Prop) : Prop axiom g1132 (x : Prop) : Prop axiom g1133 (x : Prop) : Prop axiom g1134 (x : Prop) : Prop axiom g1135 (x : Prop) : Prop axiom g1136 (x : Prop) : Prop axiom g1137 (x : Prop) : Prop axiom g1138 (x : Prop) : Prop axiom g1139 (x : Prop) : Prop axiom g1140 (x : Prop) : Prop axiom g1141 (x : Prop) : Prop axiom g1142 (x : Prop) : Prop axiom g1143 (x : Prop) : Prop axiom g1144 (x : Prop) : Prop axiom g1145 (x : Prop) : Prop axiom g1146 (x : Prop) : Prop axiom g1147 (x : Prop) : Prop axiom g1148 (x : Prop) : Prop axiom g1149 (x : Prop) : Prop axiom g1150 (x : Prop) : Prop axiom g1151 (x : Prop) : Prop axiom g1152 (x : Prop) : Prop axiom g1153 (x : Prop) : Prop axiom g1154 (x : Prop) : Prop axiom g1155 (x : Prop) : Prop axiom g1156 (x : Prop) : Prop axiom g1157 (x : Prop) : Prop axiom g1158 (x : Prop) : Prop axiom g1159 (x : Prop) : Prop axiom g1160 (x : Prop) : Prop axiom g1161 (x : Prop) : Prop axiom g1162 (x : Prop) : Prop axiom g1163 (x : Prop) : Prop axiom g1164 (x : Prop) : Prop axiom g1165 (x : Prop) : Prop axiom g1166 (x : Prop) : Prop axiom g1167 (x : Prop) : Prop axiom g1168 (x : Prop) : Prop axiom g1169 (x : Prop) : Prop axiom g1170 (x : Prop) : Prop axiom g1171 (x : Prop) : Prop axiom g1172 (x : Prop) : Prop axiom g1173 (x : Prop) : Prop axiom g1174 (x : Prop) : Prop axiom g1175 (x : Prop) : Prop axiom g1176 (x : Prop) : Prop axiom g1177 (x : Prop) : Prop axiom g1178 (x : Prop) : Prop axiom g1179 (x : Prop) : Prop axiom g1180 (x : Prop) : Prop axiom g1181 (x : Prop) : Prop axiom g1182 (x : Prop) : Prop axiom g1183 (x : Prop) : Prop axiom g1184 (x : Prop) : Prop axiom g1185 (x : Prop) : Prop axiom g1186 (x : Prop) : Prop axiom g1187 (x : Prop) : Prop axiom g1188 (x : Prop) : Prop axiom g1189 (x : Prop) : Prop axiom g1190 (x : Prop) : Prop axiom g1191 (x : Prop) : Prop axiom g1192 (x : Prop) : Prop axiom g1193 (x : Prop) : Prop axiom g1194 (x : Prop) : Prop axiom g1195 (x : Prop) : Prop axiom g1196 (x : Prop) : Prop axiom g1197 (x : Prop) : Prop axiom g1198 (x : Prop) : Prop axiom g1199 (x : Prop) : Prop axiom g1200 (x : Prop) : Prop axiom g1201 (x : Prop) : Prop axiom g1202 (x : Prop) : Prop axiom g1203 (x : Prop) : Prop axiom g1204 (x : Prop) : Prop axiom g1205 (x : Prop) : Prop axiom g1206 (x : Prop) : Prop axiom g1207 (x : Prop) : Prop axiom g1208 (x : Prop) : Prop axiom g1209 (x : Prop) : Prop axiom g1210 (x : Prop) : Prop axiom g1211 (x : Prop) : Prop axiom g1212 (x : Prop) : Prop axiom g1213 (x : Prop) : Prop axiom g1214 (x : Prop) : Prop axiom g1215 (x : Prop) : Prop axiom g1216 (x : Prop) : Prop axiom g1217 (x : Prop) : Prop axiom g1218 (x : Prop) : Prop axiom g1219 (x : Prop) : Prop axiom g1220 (x : Prop) : Prop axiom g1221 (x : Prop) : Prop axiom g1222 (x : Prop) : Prop axiom g1223 (x : Prop) : Prop axiom g1224 (x : Prop) : Prop axiom g1225 (x : Prop) : Prop axiom g1226 (x : Prop) : Prop axiom g1227 (x : Prop) : Prop axiom g1228 (x : Prop) : Prop axiom g1229 (x : Prop) : Prop axiom g1230 (x : Prop) : Prop axiom g1231 (x : Prop) : Prop axiom g1232 (x : Prop) : Prop axiom g1233 (x : Prop) : Prop axiom g1234 (x : Prop) : Prop axiom g1235 (x : Prop) : Prop axiom g1236 (x : Prop) : Prop axiom g1237 (x : Prop) : Prop axiom g1238 (x : Prop) : Prop axiom g1239 (x : Prop) : Prop axiom g1240 (x : Prop) : Prop axiom g1241 (x : Prop) : Prop axiom g1242 (x : Prop) : Prop axiom g1243 (x : Prop) : Prop axiom g1244 (x : Prop) : Prop axiom g1245 (x : Prop) : Prop axiom g1246 (x : Prop) : Prop axiom g1247 (x : Prop) : Prop axiom g1248 (x : Prop) : Prop axiom g1249 (x : Prop) : Prop axiom g1250 (x : Prop) : Prop axiom g1251 (x : Prop) : Prop axiom g1252 (x : Prop) : Prop axiom g1253 (x : Prop) : Prop axiom g1254 (x : Prop) : Prop axiom g1255 (x : Prop) : Prop axiom g1256 (x : Prop) : Prop axiom g1257 (x : Prop) : Prop axiom g1258 (x : Prop) : Prop axiom g1259 (x : Prop) : Prop axiom g1260 (x : Prop) : Prop axiom g1261 (x : Prop) : Prop axiom g1262 (x : Prop) : Prop axiom g1263 (x : Prop) : Prop axiom g1264 (x : Prop) : Prop axiom g1265 (x : Prop) : Prop axiom g1266 (x : Prop) : Prop axiom g1267 (x : Prop) : Prop axiom g1268 (x : Prop) : Prop axiom g1269 (x : Prop) : Prop axiom g1270 (x : Prop) : Prop axiom g1271 (x : Prop) : Prop axiom g1272 (x : Prop) : Prop axiom g1273 (x : Prop) : Prop axiom g1274 (x : Prop) : Prop axiom g1275 (x : Prop) : Prop axiom g1276 (x : Prop) : Prop axiom g1277 (x : Prop) : Prop axiom g1278 (x : Prop) : Prop axiom g1279 (x : Prop) : Prop axiom g1280 (x : Prop) : Prop axiom g1281 (x : Prop) : Prop axiom g1282 (x : Prop) : Prop axiom g1283 (x : Prop) : Prop axiom g1284 (x : Prop) : Prop axiom g1285 (x : Prop) : Prop axiom g1286 (x : Prop) : Prop axiom g1287 (x : Prop) : Prop axiom g1288 (x : Prop) : Prop axiom g1289 (x : Prop) : Prop axiom g1290 (x : Prop) : Prop axiom g1291 (x : Prop) : Prop axiom g1292 (x : Prop) : Prop axiom g1293 (x : Prop) : Prop axiom g1294 (x : Prop) : Prop axiom g1295 (x : Prop) : Prop axiom g1296 (x : Prop) : Prop axiom g1297 (x : Prop) : Prop axiom g1298 (x : Prop) : Prop axiom g1299 (x : Prop) : Prop axiom g1300 (x : Prop) : Prop axiom g1301 (x : Prop) : Prop axiom g1302 (x : Prop) : Prop axiom g1303 (x : Prop) : Prop axiom g1304 (x : Prop) : Prop axiom g1305 (x : Prop) : Prop axiom g1306 (x : Prop) : Prop axiom g1307 (x : Prop) : Prop axiom g1308 (x : Prop) : Prop axiom g1309 (x : Prop) : Prop axiom g1310 (x : Prop) : Prop axiom g1311 (x : Prop) : Prop axiom g1312 (x : Prop) : Prop axiom g1313 (x : Prop) : Prop axiom g1314 (x : Prop) : Prop axiom g1315 (x : Prop) : Prop axiom g1316 (x : Prop) : Prop axiom g1317 (x : Prop) : Prop axiom g1318 (x : Prop) : Prop axiom g1319 (x : Prop) : Prop axiom g1320 (x : Prop) : Prop axiom g1321 (x : Prop) : Prop axiom g1322 (x : Prop) : Prop axiom g1323 (x : Prop) : Prop axiom g1324 (x : Prop) : Prop axiom g1325 (x : Prop) : Prop axiom g1326 (x : Prop) : Prop axiom g1327 (x : Prop) : Prop axiom g1328 (x : Prop) : Prop axiom g1329 (x : Prop) : Prop axiom g1330 (x : Prop) : Prop axiom g1331 (x : Prop) : Prop axiom g1332 (x : Prop) : Prop axiom g1333 (x : Prop) : Prop axiom g1334 (x : Prop) : Prop axiom g1335 (x : Prop) : Prop axiom g1336 (x : Prop) : Prop axiom g1337 (x : Prop) : Prop axiom g1338 (x : Prop) : Prop axiom g1339 (x : Prop) : Prop axiom g1340 (x : Prop) : Prop axiom g1341 (x : Prop) : Prop axiom g1342 (x : Prop) : Prop axiom g1343 (x : Prop) : Prop axiom g1344 (x : Prop) : Prop axiom g1345 (x : Prop) : Prop axiom g1346 (x : Prop) : Prop axiom g1347 (x : Prop) : Prop axiom g1348 (x : Prop) : Prop axiom g1349 (x : Prop) : Prop axiom g1350 (x : Prop) : Prop axiom g1351 (x : Prop) : Prop axiom g1352 (x : Prop) : Prop axiom g1353 (x : Prop) : Prop axiom g1354 (x : Prop) : Prop axiom g1355 (x : Prop) : Prop axiom g1356 (x : Prop) : Prop axiom g1357 (x : Prop) : Prop axiom g1358 (x : Prop) : Prop axiom g1359 (x : Prop) : Prop axiom g1360 (x : Prop) : Prop axiom g1361 (x : Prop) : Prop axiom g1362 (x : Prop) : Prop axiom g1363 (x : Prop) : Prop axiom g1364 (x : Prop) : Prop axiom g1365 (x : Prop) : Prop axiom g1366 (x : Prop) : Prop axiom g1367 (x : Prop) : Prop axiom g1368 (x : Prop) : Prop axiom g1369 (x : Prop) : Prop axiom g1370 (x : Prop) : Prop axiom g1371 (x : Prop) : Prop axiom g1372 (x : Prop) : Prop axiom g1373 (x : Prop) : Prop axiom g1374 (x : Prop) : Prop axiom g1375 (x : Prop) : Prop axiom g1376 (x : Prop) : Prop axiom g1377 (x : Prop) : Prop axiom g1378 (x : Prop) : Prop axiom g1379 (x : Prop) : Prop axiom g1380 (x : Prop) : Prop axiom g1381 (x : Prop) : Prop axiom g1382 (x : Prop) : Prop axiom g1383 (x : Prop) : Prop axiom g1384 (x : Prop) : Prop axiom g1385 (x : Prop) : Prop axiom g1386 (x : Prop) : Prop axiom g1387 (x : Prop) : Prop axiom g1388 (x : Prop) : Prop axiom g1389 (x : Prop) : Prop axiom g1390 (x : Prop) : Prop axiom g1391 (x : Prop) : Prop axiom g1392 (x : Prop) : Prop axiom g1393 (x : Prop) : Prop axiom g1394 (x : Prop) : Prop axiom g1395 (x : Prop) : Prop axiom g1396 (x : Prop) : Prop axiom g1397 (x : Prop) : Prop axiom g1398 (x : Prop) : Prop axiom g1399 (x : Prop) : Prop axiom g1400 (x : Prop) : Prop axiom g1401 (x : Prop) : Prop axiom g1402 (x : Prop) : Prop axiom g1403 (x : Prop) : Prop axiom g1404 (x : Prop) : Prop axiom g1405 (x : Prop) : Prop axiom g1406 (x : Prop) : Prop axiom g1407 (x : Prop) : Prop axiom g1408 (x : Prop) : Prop axiom g1409 (x : Prop) : Prop axiom g1410 (x : Prop) : Prop axiom g1411 (x : Prop) : Prop axiom g1412 (x : Prop) : Prop axiom g1413 (x : Prop) : Prop axiom g1414 (x : Prop) : Prop axiom g1415 (x : Prop) : Prop axiom g1416 (x : Prop) : Prop axiom g1417 (x : Prop) : Prop axiom g1418 (x : Prop) : Prop axiom g1419 (x : Prop) : Prop axiom g1420 (x : Prop) : Prop axiom g1421 (x : Prop) : Prop axiom g1422 (x : Prop) : Prop axiom g1423 (x : Prop) : Prop axiom g1424 (x : Prop) : Prop axiom g1425 (x : Prop) : Prop axiom g1426 (x : Prop) : Prop axiom g1427 (x : Prop) : Prop axiom g1428 (x : Prop) : Prop axiom g1429 (x : Prop) : Prop axiom g1430 (x : Prop) : Prop axiom g1431 (x : Prop) : Prop axiom g1432 (x : Prop) : Prop axiom g1433 (x : Prop) : Prop axiom g1434 (x : Prop) : Prop axiom g1435 (x : Prop) : Prop axiom g1436 (x : Prop) : Prop axiom g1437 (x : Prop) : Prop axiom g1438 (x : Prop) : Prop axiom g1439 (x : Prop) : Prop axiom g1440 (x : Prop) : Prop axiom g1441 (x : Prop) : Prop axiom g1442 (x : Prop) : Prop axiom g1443 (x : Prop) : Prop axiom g1444 (x : Prop) : Prop axiom g1445 (x : Prop) : Prop axiom g1446 (x : Prop) : Prop axiom g1447 (x : Prop) : Prop axiom g1448 (x : Prop) : Prop axiom g1449 (x : Prop) : Prop axiom g1450 (x : Prop) : Prop axiom g1451 (x : Prop) : Prop axiom g1452 (x : Prop) : Prop axiom g1453 (x : Prop) : Prop axiom g1454 (x : Prop) : Prop axiom g1455 (x : Prop) : Prop axiom g1456 (x : Prop) : Prop axiom g1457 (x : Prop) : Prop axiom g1458 (x : Prop) : Prop axiom g1459 (x : Prop) : Prop axiom g1460 (x : Prop) : Prop axiom g1461 (x : Prop) : Prop axiom g1462 (x : Prop) : Prop axiom g1463 (x : Prop) : Prop axiom g1464 (x : Prop) : Prop axiom g1465 (x : Prop) : Prop axiom g1466 (x : Prop) : Prop axiom g1467 (x : Prop) : Prop axiom g1468 (x : Prop) : Prop axiom g1469 (x : Prop) : Prop axiom g1470 (x : Prop) : Prop axiom g1471 (x : Prop) : Prop axiom g1472 (x : Prop) : Prop axiom g1473 (x : Prop) : Prop axiom g1474 (x : Prop) : Prop axiom g1475 (x : Prop) : Prop axiom g1476 (x : Prop) : Prop axiom g1477 (x : Prop) : Prop axiom g1478 (x : Prop) : Prop axiom g1479 (x : Prop) : Prop axiom g1480 (x : Prop) : Prop axiom g1481 (x : Prop) : Prop axiom g1482 (x : Prop) : Prop axiom g1483 (x : Prop) : Prop axiom g1484 (x : Prop) : Prop axiom g1485 (x : Prop) : Prop axiom g1486 (x : Prop) : Prop axiom g1487 (x : Prop) : Prop axiom g1488 (x : Prop) : Prop axiom g1489 (x : Prop) : Prop axiom g1490 (x : Prop) : Prop axiom g1491 (x : Prop) : Prop axiom g1492 (x : Prop) : Prop axiom g1493 (x : Prop) : Prop axiom g1494 (x : Prop) : Prop axiom g1495 (x : Prop) : Prop axiom g1496 (x : Prop) : Prop axiom g1497 (x : Prop) : Prop axiom g1498 (x : Prop) : Prop axiom g1499 (x : Prop) : Prop @[simp] axiom s0 (x : Prop) : f (g1 x) = f (g0 x) @[simp] axiom s1 (x : Prop) : f (g2 x) = f (g1 x) @[simp] axiom s2 (x : Prop) : f (g3 x) = f (g2 x) @[simp] axiom s3 (x : Prop) : f (g4 x) = f (g3 x) @[simp] axiom s4 (x : Prop) : f (g5 x) = f (g4 x) @[simp] axiom s5 (x : Prop) : f (g6 x) = f (g5 x) @[simp] axiom s6 (x : Prop) : f (g7 x) = f (g6 x) @[simp] axiom s7 (x : Prop) : f (g8 x) = f (g7 x) @[simp] axiom s8 (x : Prop) : f (g9 x) = f (g8 x) @[simp] axiom s9 (x : Prop) : f (g10 x) = f (g9 x) @[simp] axiom s10 (x : Prop) : f (g11 x) = f (g10 x) @[simp] axiom s11 (x : Prop) : f (g12 x) = f (g11 x) @[simp] axiom s12 (x : Prop) : f (g13 x) = f (g12 x) @[simp] axiom s13 (x : Prop) : f (g14 x) = f (g13 x) @[simp] axiom s14 (x : Prop) : f (g15 x) = f (g14 x) @[simp] axiom s15 (x : Prop) : f (g16 x) = f (g15 x) @[simp] axiom s16 (x : Prop) : f (g17 x) = f (g16 x) @[simp] axiom s17 (x : Prop) : f (g18 x) = f (g17 x) @[simp] axiom s18 (x : Prop) : f (g19 x) = f (g18 x) @[simp] axiom s19 (x : Prop) : f (g20 x) = f (g19 x) @[simp] axiom s20 (x : Prop) : f (g21 x) = f (g20 x) @[simp] axiom s21 (x : Prop) : f (g22 x) = f (g21 x) @[simp] axiom s22 (x : Prop) : f (g23 x) = f (g22 x) @[simp] axiom s23 (x : Prop) : f (g24 x) = f (g23 x) @[simp] axiom s24 (x : Prop) : f (g25 x) = f (g24 x) @[simp] axiom s25 (x : Prop) : f (g26 x) = f (g25 x) @[simp] axiom s26 (x : Prop) : f (g27 x) = f (g26 x) @[simp] axiom s27 (x : Prop) : f (g28 x) = f (g27 x) @[simp] axiom s28 (x : Prop) : f (g29 x) = f (g28 x) @[simp] axiom s29 (x : Prop) : f (g30 x) = f (g29 x) @[simp] axiom s30 (x : Prop) : f (g31 x) = f (g30 x) @[simp] axiom s31 (x : Prop) : f (g32 x) = f (g31 x) @[simp] axiom s32 (x : Prop) : f (g33 x) = f (g32 x) @[simp] axiom s33 (x : Prop) : f (g34 x) = f (g33 x) @[simp] axiom s34 (x : Prop) : f (g35 x) = f (g34 x) @[simp] axiom s35 (x : Prop) : f (g36 x) = f (g35 x) @[simp] axiom s36 (x : Prop) : f (g37 x) = f (g36 x) @[simp] axiom s37 (x : Prop) : f (g38 x) = f (g37 x) @[simp] axiom s38 (x : Prop) : f (g39 x) = f (g38 x) @[simp] axiom s39 (x : Prop) : f (g40 x) = f (g39 x) @[simp] axiom s40 (x : Prop) : f (g41 x) = f (g40 x) @[simp] axiom s41 (x : Prop) : f (g42 x) = f (g41 x) @[simp] axiom s42 (x : Prop) : f (g43 x) = f (g42 x) @[simp] axiom s43 (x : Prop) : f (g44 x) = f (g43 x) @[simp] axiom s44 (x : Prop) : f (g45 x) = f (g44 x) @[simp] axiom s45 (x : Prop) : f (g46 x) = f (g45 x) @[simp] axiom s46 (x : Prop) : f (g47 x) = f (g46 x) @[simp] axiom s47 (x : Prop) : f (g48 x) = f (g47 x) @[simp] axiom s48 (x : Prop) : f (g49 x) = f (g48 x) @[simp] axiom s49 (x : Prop) : f (g50 x) = f (g49 x) @[simp] axiom s50 (x : Prop) : f (g51 x) = f (g50 x) @[simp] axiom s51 (x : Prop) : f (g52 x) = f (g51 x) @[simp] axiom s52 (x : Prop) : f (g53 x) = f (g52 x) @[simp] axiom s53 (x : Prop) : f (g54 x) = f (g53 x) @[simp] axiom s54 (x : Prop) : f (g55 x) = f (g54 x) @[simp] axiom s55 (x : Prop) : f (g56 x) = f (g55 x) @[simp] axiom s56 (x : Prop) : f (g57 x) = f (g56 x) @[simp] axiom s57 (x : Prop) : f (g58 x) = f (g57 x) @[simp] axiom s58 (x : Prop) : f (g59 x) = f (g58 x) @[simp] axiom s59 (x : Prop) : f (g60 x) = f (g59 x) @[simp] axiom s60 (x : Prop) : f (g61 x) = f (g60 x) @[simp] axiom s61 (x : Prop) : f (g62 x) = f (g61 x) @[simp] axiom s62 (x : Prop) : f (g63 x) = f (g62 x) @[simp] axiom s63 (x : Prop) : f (g64 x) = f (g63 x) @[simp] axiom s64 (x : Prop) : f (g65 x) = f (g64 x) @[simp] axiom s65 (x : Prop) : f (g66 x) = f (g65 x) @[simp] axiom s66 (x : Prop) : f (g67 x) = f (g66 x) @[simp] axiom s67 (x : Prop) : f (g68 x) = f (g67 x) @[simp] axiom s68 (x : Prop) : f (g69 x) = f (g68 x) @[simp] axiom s69 (x : Prop) : f (g70 x) = f (g69 x) @[simp] axiom s70 (x : Prop) : f (g71 x) = f (g70 x) @[simp] axiom s71 (x : Prop) : f (g72 x) = f (g71 x) @[simp] axiom s72 (x : Prop) : f (g73 x) = f (g72 x) @[simp] axiom s73 (x : Prop) : f (g74 x) = f (g73 x) @[simp] axiom s74 (x : Prop) : f (g75 x) = f (g74 x) @[simp] axiom s75 (x : Prop) : f (g76 x) = f (g75 x) @[simp] axiom s76 (x : Prop) : f (g77 x) = f (g76 x) @[simp] axiom s77 (x : Prop) : f (g78 x) = f (g77 x) @[simp] axiom s78 (x : Prop) : f (g79 x) = f (g78 x) @[simp] axiom s79 (x : Prop) : f (g80 x) = f (g79 x) @[simp] axiom s80 (x : Prop) : f (g81 x) = f (g80 x) @[simp] axiom s81 (x : Prop) : f (g82 x) = f (g81 x) @[simp] axiom s82 (x : Prop) : f (g83 x) = f (g82 x) @[simp] axiom s83 (x : Prop) : f (g84 x) = f (g83 x) @[simp] axiom s84 (x : Prop) : f (g85 x) = f (g84 x) @[simp] axiom s85 (x : Prop) : f (g86 x) = f (g85 x) @[simp] axiom s86 (x : Prop) : f (g87 x) = f (g86 x) @[simp] axiom s87 (x : Prop) : f (g88 x) = f (g87 x) @[simp] axiom s88 (x : Prop) : f (g89 x) = f (g88 x) @[simp] axiom s89 (x : Prop) : f (g90 x) = f (g89 x) @[simp] axiom s90 (x : Prop) : f (g91 x) = f (g90 x) @[simp] axiom s91 (x : Prop) : f (g92 x) = f (g91 x) @[simp] axiom s92 (x : Prop) : f (g93 x) = f (g92 x) @[simp] axiom s93 (x : Prop) : f (g94 x) = f (g93 x) @[simp] axiom s94 (x : Prop) : f (g95 x) = f (g94 x) @[simp] axiom s95 (x : Prop) : f (g96 x) = f (g95 x) @[simp] axiom s96 (x : Prop) : f (g97 x) = f (g96 x) @[simp] axiom s97 (x : Prop) : f (g98 x) = f (g97 x) @[simp] axiom s98 (x : Prop) : f (g99 x) = f (g98 x) @[simp] axiom s99 (x : Prop) : f (g100 x) = f (g99 x) @[simp] axiom s100 (x : Prop) : f (g101 x) = f (g100 x) @[simp] axiom s101 (x : Prop) : f (g102 x) = f (g101 x) @[simp] axiom s102 (x : Prop) : f (g103 x) = f (g102 x) @[simp] axiom s103 (x : Prop) : f (g104 x) = f (g103 x) @[simp] axiom s104 (x : Prop) : f (g105 x) = f (g104 x) @[simp] axiom s105 (x : Prop) : f (g106 x) = f (g105 x) @[simp] axiom s106 (x : Prop) : f (g107 x) = f (g106 x) @[simp] axiom s107 (x : Prop) : f (g108 x) = f (g107 x) @[simp] axiom s108 (x : Prop) : f (g109 x) = f (g108 x) @[simp] axiom s109 (x : Prop) : f (g110 x) = f (g109 x) @[simp] axiom s110 (x : Prop) : f (g111 x) = f (g110 x) @[simp] axiom s111 (x : Prop) : f (g112 x) = f (g111 x) @[simp] axiom s112 (x : Prop) : f (g113 x) = f (g112 x) @[simp] axiom s113 (x : Prop) : f (g114 x) = f (g113 x) @[simp] axiom s114 (x : Prop) : f (g115 x) = f (g114 x) @[simp] axiom s115 (x : Prop) : f (g116 x) = f (g115 x) @[simp] axiom s116 (x : Prop) : f (g117 x) = f (g116 x) @[simp] axiom s117 (x : Prop) : f (g118 x) = f (g117 x) @[simp] axiom s118 (x : Prop) : f (g119 x) = f (g118 x) @[simp] axiom s119 (x : Prop) : f (g120 x) = f (g119 x) @[simp] axiom s120 (x : Prop) : f (g121 x) = f (g120 x) @[simp] axiom s121 (x : Prop) : f (g122 x) = f (g121 x) @[simp] axiom s122 (x : Prop) : f (g123 x) = f (g122 x) @[simp] axiom s123 (x : Prop) : f (g124 x) = f (g123 x) @[simp] axiom s124 (x : Prop) : f (g125 x) = f (g124 x) @[simp] axiom s125 (x : Prop) : f (g126 x) = f (g125 x) @[simp] axiom s126 (x : Prop) : f (g127 x) = f (g126 x) @[simp] axiom s127 (x : Prop) : f (g128 x) = f (g127 x) @[simp] axiom s128 (x : Prop) : f (g129 x) = f (g128 x) @[simp] axiom s129 (x : Prop) : f (g130 x) = f (g129 x) @[simp] axiom s130 (x : Prop) : f (g131 x) = f (g130 x) @[simp] axiom s131 (x : Prop) : f (g132 x) = f (g131 x) @[simp] axiom s132 (x : Prop) : f (g133 x) = f (g132 x) @[simp] axiom s133 (x : Prop) : f (g134 x) = f (g133 x) @[simp] axiom s134 (x : Prop) : f (g135 x) = f (g134 x) @[simp] axiom s135 (x : Prop) : f (g136 x) = f (g135 x) @[simp] axiom s136 (x : Prop) : f (g137 x) = f (g136 x) @[simp] axiom s137 (x : Prop) : f (g138 x) = f (g137 x) @[simp] axiom s138 (x : Prop) : f (g139 x) = f (g138 x) @[simp] axiom s139 (x : Prop) : f (g140 x) = f (g139 x) @[simp] axiom s140 (x : Prop) : f (g141 x) = f (g140 x) @[simp] axiom s141 (x : Prop) : f (g142 x) = f (g141 x) @[simp] axiom s142 (x : Prop) : f (g143 x) = f (g142 x) @[simp] axiom s143 (x : Prop) : f (g144 x) = f (g143 x) @[simp] axiom s144 (x : Prop) : f (g145 x) = f (g144 x) @[simp] axiom s145 (x : Prop) : f (g146 x) = f (g145 x) @[simp] axiom s146 (x : Prop) : f (g147 x) = f (g146 x) @[simp] axiom s147 (x : Prop) : f (g148 x) = f (g147 x) @[simp] axiom s148 (x : Prop) : f (g149 x) = f (g148 x) @[simp] axiom s149 (x : Prop) : f (g150 x) = f (g149 x) @[simp] axiom s150 (x : Prop) : f (g151 x) = f (g150 x) @[simp] axiom s151 (x : Prop) : f (g152 x) = f (g151 x) @[simp] axiom s152 (x : Prop) : f (g153 x) = f (g152 x) @[simp] axiom s153 (x : Prop) : f (g154 x) = f (g153 x) @[simp] axiom s154 (x : Prop) : f (g155 x) = f (g154 x) @[simp] axiom s155 (x : Prop) : f (g156 x) = f (g155 x) @[simp] axiom s156 (x : Prop) : f (g157 x) = f (g156 x) @[simp] axiom s157 (x : Prop) : f (g158 x) = f (g157 x) @[simp] axiom s158 (x : Prop) : f (g159 x) = f (g158 x) @[simp] axiom s159 (x : Prop) : f (g160 x) = f (g159 x) @[simp] axiom s160 (x : Prop) : f (g161 x) = f (g160 x) @[simp] axiom s161 (x : Prop) : f (g162 x) = f (g161 x) @[simp] axiom s162 (x : Prop) : f (g163 x) = f (g162 x) @[simp] axiom s163 (x : Prop) : f (g164 x) = f (g163 x) @[simp] axiom s164 (x : Prop) : f (g165 x) = f (g164 x) @[simp] axiom s165 (x : Prop) : f (g166 x) = f (g165 x) @[simp] axiom s166 (x : Prop) : f (g167 x) = f (g166 x) @[simp] axiom s167 (x : Prop) : f (g168 x) = f (g167 x) @[simp] axiom s168 (x : Prop) : f (g169 x) = f (g168 x) @[simp] axiom s169 (x : Prop) : f (g170 x) = f (g169 x) @[simp] axiom s170 (x : Prop) : f (g171 x) = f (g170 x) @[simp] axiom s171 (x : Prop) : f (g172 x) = f (g171 x) @[simp] axiom s172 (x : Prop) : f (g173 x) = f (g172 x) @[simp] axiom s173 (x : Prop) : f (g174 x) = f (g173 x) @[simp] axiom s174 (x : Prop) : f (g175 x) = f (g174 x) @[simp] axiom s175 (x : Prop) : f (g176 x) = f (g175 x) @[simp] axiom s176 (x : Prop) : f (g177 x) = f (g176 x) @[simp] axiom s177 (x : Prop) : f (g178 x) = f (g177 x) @[simp] axiom s178 (x : Prop) : f (g179 x) = f (g178 x) @[simp] axiom s179 (x : Prop) : f (g180 x) = f (g179 x) @[simp] axiom s180 (x : Prop) : f (g181 x) = f (g180 x) @[simp] axiom s181 (x : Prop) : f (g182 x) = f (g181 x) @[simp] axiom s182 (x : Prop) : f (g183 x) = f (g182 x) @[simp] axiom s183 (x : Prop) : f (g184 x) = f (g183 x) @[simp] axiom s184 (x : Prop) : f (g185 x) = f (g184 x) @[simp] axiom s185 (x : Prop) : f (g186 x) = f (g185 x) @[simp] axiom s186 (x : Prop) : f (g187 x) = f (g186 x) @[simp] axiom s187 (x : Prop) : f (g188 x) = f (g187 x) @[simp] axiom s188 (x : Prop) : f (g189 x) = f (g188 x) @[simp] axiom s189 (x : Prop) : f (g190 x) = f (g189 x) @[simp] axiom s190 (x : Prop) : f (g191 x) = f (g190 x) @[simp] axiom s191 (x : Prop) : f (g192 x) = f (g191 x) @[simp] axiom s192 (x : Prop) : f (g193 x) = f (g192 x) @[simp] axiom s193 (x : Prop) : f (g194 x) = f (g193 x) @[simp] axiom s194 (x : Prop) : f (g195 x) = f (g194 x) @[simp] axiom s195 (x : Prop) : f (g196 x) = f (g195 x) @[simp] axiom s196 (x : Prop) : f (g197 x) = f (g196 x) @[simp] axiom s197 (x : Prop) : f (g198 x) = f (g197 x) @[simp] axiom s198 (x : Prop) : f (g199 x) = f (g198 x) @[simp] axiom s199 (x : Prop) : f (g200 x) = f (g199 x) @[simp] axiom s200 (x : Prop) : f (g201 x) = f (g200 x) @[simp] axiom s201 (x : Prop) : f (g202 x) = f (g201 x) @[simp] axiom s202 (x : Prop) : f (g203 x) = f (g202 x) @[simp] axiom s203 (x : Prop) : f (g204 x) = f (g203 x) @[simp] axiom s204 (x : Prop) : f (g205 x) = f (g204 x) @[simp] axiom s205 (x : Prop) : f (g206 x) = f (g205 x) @[simp] axiom s206 (x : Prop) : f (g207 x) = f (g206 x) @[simp] axiom s207 (x : Prop) : f (g208 x) = f (g207 x) @[simp] axiom s208 (x : Prop) : f (g209 x) = f (g208 x) @[simp] axiom s209 (x : Prop) : f (g210 x) = f (g209 x) @[simp] axiom s210 (x : Prop) : f (g211 x) = f (g210 x) @[simp] axiom s211 (x : Prop) : f (g212 x) = f (g211 x) @[simp] axiom s212 (x : Prop) : f (g213 x) = f (g212 x) @[simp] axiom s213 (x : Prop) : f (g214 x) = f (g213 x) @[simp] axiom s214 (x : Prop) : f (g215 x) = f (g214 x) @[simp] axiom s215 (x : Prop) : f (g216 x) = f (g215 x) @[simp] axiom s216 (x : Prop) : f (g217 x) = f (g216 x) @[simp] axiom s217 (x : Prop) : f (g218 x) = f (g217 x) @[simp] axiom s218 (x : Prop) : f (g219 x) = f (g218 x) @[simp] axiom s219 (x : Prop) : f (g220 x) = f (g219 x) @[simp] axiom s220 (x : Prop) : f (g221 x) = f (g220 x) @[simp] axiom s221 (x : Prop) : f (g222 x) = f (g221 x) @[simp] axiom s222 (x : Prop) : f (g223 x) = f (g222 x) @[simp] axiom s223 (x : Prop) : f (g224 x) = f (g223 x) @[simp] axiom s224 (x : Prop) : f (g225 x) = f (g224 x) @[simp] axiom s225 (x : Prop) : f (g226 x) = f (g225 x) @[simp] axiom s226 (x : Prop) : f (g227 x) = f (g226 x) @[simp] axiom s227 (x : Prop) : f (g228 x) = f (g227 x) @[simp] axiom s228 (x : Prop) : f (g229 x) = f (g228 x) @[simp] axiom s229 (x : Prop) : f (g230 x) = f (g229 x) @[simp] axiom s230 (x : Prop) : f (g231 x) = f (g230 x) @[simp] axiom s231 (x : Prop) : f (g232 x) = f (g231 x) @[simp] axiom s232 (x : Prop) : f (g233 x) = f (g232 x) @[simp] axiom s233 (x : Prop) : f (g234 x) = f (g233 x) @[simp] axiom s234 (x : Prop) : f (g235 x) = f (g234 x) @[simp] axiom s235 (x : Prop) : f (g236 x) = f (g235 x) @[simp] axiom s236 (x : Prop) : f (g237 x) = f (g236 x) @[simp] axiom s237 (x : Prop) : f (g238 x) = f (g237 x) @[simp] axiom s238 (x : Prop) : f (g239 x) = f (g238 x) @[simp] axiom s239 (x : Prop) : f (g240 x) = f (g239 x) @[simp] axiom s240 (x : Prop) : f (g241 x) = f (g240 x) @[simp] axiom s241 (x : Prop) : f (g242 x) = f (g241 x) @[simp] axiom s242 (x : Prop) : f (g243 x) = f (g242 x) @[simp] axiom s243 (x : Prop) : f (g244 x) = f (g243 x) @[simp] axiom s244 (x : Prop) : f (g245 x) = f (g244 x) @[simp] axiom s245 (x : Prop) : f (g246 x) = f (g245 x) @[simp] axiom s246 (x : Prop) : f (g247 x) = f (g246 x) @[simp] axiom s247 (x : Prop) : f (g248 x) = f (g247 x) @[simp] axiom s248 (x : Prop) : f (g249 x) = f (g248 x) @[simp] axiom s249 (x : Prop) : f (g250 x) = f (g249 x) @[simp] axiom s250 (x : Prop) : f (g251 x) = f (g250 x) @[simp] axiom s251 (x : Prop) : f (g252 x) = f (g251 x) @[simp] axiom s252 (x : Prop) : f (g253 x) = f (g252 x) @[simp] axiom s253 (x : Prop) : f (g254 x) = f (g253 x) @[simp] axiom s254 (x : Prop) : f (g255 x) = f (g254 x) @[simp] axiom s255 (x : Prop) : f (g256 x) = f (g255 x) @[simp] axiom s256 (x : Prop) : f (g257 x) = f (g256 x) @[simp] axiom s257 (x : Prop) : f (g258 x) = f (g257 x) @[simp] axiom s258 (x : Prop) : f (g259 x) = f (g258 x) @[simp] axiom s259 (x : Prop) : f (g260 x) = f (g259 x) @[simp] axiom s260 (x : Prop) : f (g261 x) = f (g260 x) @[simp] axiom s261 (x : Prop) : f (g262 x) = f (g261 x) @[simp] axiom s262 (x : Prop) : f (g263 x) = f (g262 x) @[simp] axiom s263 (x : Prop) : f (g264 x) = f (g263 x) @[simp] axiom s264 (x : Prop) : f (g265 x) = f (g264 x) @[simp] axiom s265 (x : Prop) : f (g266 x) = f (g265 x) @[simp] axiom s266 (x : Prop) : f (g267 x) = f (g266 x) @[simp] axiom s267 (x : Prop) : f (g268 x) = f (g267 x) @[simp] axiom s268 (x : Prop) : f (g269 x) = f (g268 x) @[simp] axiom s269 (x : Prop) : f (g270 x) = f (g269 x) @[simp] axiom s270 (x : Prop) : f (g271 x) = f (g270 x) @[simp] axiom s271 (x : Prop) : f (g272 x) = f (g271 x) @[simp] axiom s272 (x : Prop) : f (g273 x) = f (g272 x) @[simp] axiom s273 (x : Prop) : f (g274 x) = f (g273 x) @[simp] axiom s274 (x : Prop) : f (g275 x) = f (g274 x) @[simp] axiom s275 (x : Prop) : f (g276 x) = f (g275 x) @[simp] axiom s276 (x : Prop) : f (g277 x) = f (g276 x) @[simp] axiom s277 (x : Prop) : f (g278 x) = f (g277 x) @[simp] axiom s278 (x : Prop) : f (g279 x) = f (g278 x) @[simp] axiom s279 (x : Prop) : f (g280 x) = f (g279 x) @[simp] axiom s280 (x : Prop) : f (g281 x) = f (g280 x) @[simp] axiom s281 (x : Prop) : f (g282 x) = f (g281 x) @[simp] axiom s282 (x : Prop) : f (g283 x) = f (g282 x) @[simp] axiom s283 (x : Prop) : f (g284 x) = f (g283 x) @[simp] axiom s284 (x : Prop) : f (g285 x) = f (g284 x) @[simp] axiom s285 (x : Prop) : f (g286 x) = f (g285 x) @[simp] axiom s286 (x : Prop) : f (g287 x) = f (g286 x) @[simp] axiom s287 (x : Prop) : f (g288 x) = f (g287 x) @[simp] axiom s288 (x : Prop) : f (g289 x) = f (g288 x) @[simp] axiom s289 (x : Prop) : f (g290 x) = f (g289 x) @[simp] axiom s290 (x : Prop) : f (g291 x) = f (g290 x) @[simp] axiom s291 (x : Prop) : f (g292 x) = f (g291 x) @[simp] axiom s292 (x : Prop) : f (g293 x) = f (g292 x) @[simp] axiom s293 (x : Prop) : f (g294 x) = f (g293 x) @[simp] axiom s294 (x : Prop) : f (g295 x) = f (g294 x) @[simp] axiom s295 (x : Prop) : f (g296 x) = f (g295 x) @[simp] axiom s296 (x : Prop) : f (g297 x) = f (g296 x) @[simp] axiom s297 (x : Prop) : f (g298 x) = f (g297 x) @[simp] axiom s298 (x : Prop) : f (g299 x) = f (g298 x) @[simp] axiom s299 (x : Prop) : f (g300 x) = f (g299 x) @[simp] axiom s300 (x : Prop) : f (g301 x) = f (g300 x) @[simp] axiom s301 (x : Prop) : f (g302 x) = f (g301 x) @[simp] axiom s302 (x : Prop) : f (g303 x) = f (g302 x) @[simp] axiom s303 (x : Prop) : f (g304 x) = f (g303 x) @[simp] axiom s304 (x : Prop) : f (g305 x) = f (g304 x) @[simp] axiom s305 (x : Prop) : f (g306 x) = f (g305 x) @[simp] axiom s306 (x : Prop) : f (g307 x) = f (g306 x) @[simp] axiom s307 (x : Prop) : f (g308 x) = f (g307 x) @[simp] axiom s308 (x : Prop) : f (g309 x) = f (g308 x) @[simp] axiom s309 (x : Prop) : f (g310 x) = f (g309 x) @[simp] axiom s310 (x : Prop) : f (g311 x) = f (g310 x) @[simp] axiom s311 (x : Prop) : f (g312 x) = f (g311 x) @[simp] axiom s312 (x : Prop) : f (g313 x) = f (g312 x) @[simp] axiom s313 (x : Prop) : f (g314 x) = f (g313 x) @[simp] axiom s314 (x : Prop) : f (g315 x) = f (g314 x) @[simp] axiom s315 (x : Prop) : f (g316 x) = f (g315 x) @[simp] axiom s316 (x : Prop) : f (g317 x) = f (g316 x) @[simp] axiom s317 (x : Prop) : f (g318 x) = f (g317 x) @[simp] axiom s318 (x : Prop) : f (g319 x) = f (g318 x) @[simp] axiom s319 (x : Prop) : f (g320 x) = f (g319 x) @[simp] axiom s320 (x : Prop) : f (g321 x) = f (g320 x) @[simp] axiom s321 (x : Prop) : f (g322 x) = f (g321 x) @[simp] axiom s322 (x : Prop) : f (g323 x) = f (g322 x) @[simp] axiom s323 (x : Prop) : f (g324 x) = f (g323 x) @[simp] axiom s324 (x : Prop) : f (g325 x) = f (g324 x) @[simp] axiom s325 (x : Prop) : f (g326 x) = f (g325 x) @[simp] axiom s326 (x : Prop) : f (g327 x) = f (g326 x) @[simp] axiom s327 (x : Prop) : f (g328 x) = f (g327 x) @[simp] axiom s328 (x : Prop) : f (g329 x) = f (g328 x) @[simp] axiom s329 (x : Prop) : f (g330 x) = f (g329 x) @[simp] axiom s330 (x : Prop) : f (g331 x) = f (g330 x) @[simp] axiom s331 (x : Prop) : f (g332 x) = f (g331 x) @[simp] axiom s332 (x : Prop) : f (g333 x) = f (g332 x) @[simp] axiom s333 (x : Prop) : f (g334 x) = f (g333 x) @[simp] axiom s334 (x : Prop) : f (g335 x) = f (g334 x) @[simp] axiom s335 (x : Prop) : f (g336 x) = f (g335 x) @[simp] axiom s336 (x : Prop) : f (g337 x) = f (g336 x) @[simp] axiom s337 (x : Prop) : f (g338 x) = f (g337 x) @[simp] axiom s338 (x : Prop) : f (g339 x) = f (g338 x) @[simp] axiom s339 (x : Prop) : f (g340 x) = f (g339 x) @[simp] axiom s340 (x : Prop) : f (g341 x) = f (g340 x) @[simp] axiom s341 (x : Prop) : f (g342 x) = f (g341 x) @[simp] axiom s342 (x : Prop) : f (g343 x) = f (g342 x) @[simp] axiom s343 (x : Prop) : f (g344 x) = f (g343 x) @[simp] axiom s344 (x : Prop) : f (g345 x) = f (g344 x) @[simp] axiom s345 (x : Prop) : f (g346 x) = f (g345 x) @[simp] axiom s346 (x : Prop) : f (g347 x) = f (g346 x) @[simp] axiom s347 (x : Prop) : f (g348 x) = f (g347 x) @[simp] axiom s348 (x : Prop) : f (g349 x) = f (g348 x) @[simp] axiom s349 (x : Prop) : f (g350 x) = f (g349 x) @[simp] axiom s350 (x : Prop) : f (g351 x) = f (g350 x) @[simp] axiom s351 (x : Prop) : f (g352 x) = f (g351 x) @[simp] axiom s352 (x : Prop) : f (g353 x) = f (g352 x) @[simp] axiom s353 (x : Prop) : f (g354 x) = f (g353 x) @[simp] axiom s354 (x : Prop) : f (g355 x) = f (g354 x) @[simp] axiom s355 (x : Prop) : f (g356 x) = f (g355 x) @[simp] axiom s356 (x : Prop) : f (g357 x) = f (g356 x) @[simp] axiom s357 (x : Prop) : f (g358 x) = f (g357 x) @[simp] axiom s358 (x : Prop) : f (g359 x) = f (g358 x) @[simp] axiom s359 (x : Prop) : f (g360 x) = f (g359 x) @[simp] axiom s360 (x : Prop) : f (g361 x) = f (g360 x) @[simp] axiom s361 (x : Prop) : f (g362 x) = f (g361 x) @[simp] axiom s362 (x : Prop) : f (g363 x) = f (g362 x) @[simp] axiom s363 (x : Prop) : f (g364 x) = f (g363 x) @[simp] axiom s364 (x : Prop) : f (g365 x) = f (g364 x) @[simp] axiom s365 (x : Prop) : f (g366 x) = f (g365 x) @[simp] axiom s366 (x : Prop) : f (g367 x) = f (g366 x) @[simp] axiom s367 (x : Prop) : f (g368 x) = f (g367 x) @[simp] axiom s368 (x : Prop) : f (g369 x) = f (g368 x) @[simp] axiom s369 (x : Prop) : f (g370 x) = f (g369 x) @[simp] axiom s370 (x : Prop) : f (g371 x) = f (g370 x) @[simp] axiom s371 (x : Prop) : f (g372 x) = f (g371 x) @[simp] axiom s372 (x : Prop) : f (g373 x) = f (g372 x) @[simp] axiom s373 (x : Prop) : f (g374 x) = f (g373 x) @[simp] axiom s374 (x : Prop) : f (g375 x) = f (g374 x) @[simp] axiom s375 (x : Prop) : f (g376 x) = f (g375 x) @[simp] axiom s376 (x : Prop) : f (g377 x) = f (g376 x) @[simp] axiom s377 (x : Prop) : f (g378 x) = f (g377 x) @[simp] axiom s378 (x : Prop) : f (g379 x) = f (g378 x) @[simp] axiom s379 (x : Prop) : f (g380 x) = f (g379 x) @[simp] axiom s380 (x : Prop) : f (g381 x) = f (g380 x) @[simp] axiom s381 (x : Prop) : f (g382 x) = f (g381 x) @[simp] axiom s382 (x : Prop) : f (g383 x) = f (g382 x) @[simp] axiom s383 (x : Prop) : f (g384 x) = f (g383 x) @[simp] axiom s384 (x : Prop) : f (g385 x) = f (g384 x) @[simp] axiom s385 (x : Prop) : f (g386 x) = f (g385 x) @[simp] axiom s386 (x : Prop) : f (g387 x) = f (g386 x) @[simp] axiom s387 (x : Prop) : f (g388 x) = f (g387 x) @[simp] axiom s388 (x : Prop) : f (g389 x) = f (g388 x) @[simp] axiom s389 (x : Prop) : f (g390 x) = f (g389 x) @[simp] axiom s390 (x : Prop) : f (g391 x) = f (g390 x) @[simp] axiom s391 (x : Prop) : f (g392 x) = f (g391 x) @[simp] axiom s392 (x : Prop) : f (g393 x) = f (g392 x) @[simp] axiom s393 (x : Prop) : f (g394 x) = f (g393 x) @[simp] axiom s394 (x : Prop) : f (g395 x) = f (g394 x) @[simp] axiom s395 (x : Prop) : f (g396 x) = f (g395 x) @[simp] axiom s396 (x : Prop) : f (g397 x) = f (g396 x) @[simp] axiom s397 (x : Prop) : f (g398 x) = f (g397 x) @[simp] axiom s398 (x : Prop) : f (g399 x) = f (g398 x) @[simp] axiom s399 (x : Prop) : f (g400 x) = f (g399 x) @[simp] axiom s400 (x : Prop) : f (g401 x) = f (g400 x) @[simp] axiom s401 (x : Prop) : f (g402 x) = f (g401 x) @[simp] axiom s402 (x : Prop) : f (g403 x) = f (g402 x) @[simp] axiom s403 (x : Prop) : f (g404 x) = f (g403 x) @[simp] axiom s404 (x : Prop) : f (g405 x) = f (g404 x) @[simp] axiom s405 (x : Prop) : f (g406 x) = f (g405 x) @[simp] axiom s406 (x : Prop) : f (g407 x) = f (g406 x) @[simp] axiom s407 (x : Prop) : f (g408 x) = f (g407 x) @[simp] axiom s408 (x : Prop) : f (g409 x) = f (g408 x) @[simp] axiom s409 (x : Prop) : f (g410 x) = f (g409 x) @[simp] axiom s410 (x : Prop) : f (g411 x) = f (g410 x) @[simp] axiom s411 (x : Prop) : f (g412 x) = f (g411 x) @[simp] axiom s412 (x : Prop) : f (g413 x) = f (g412 x) @[simp] axiom s413 (x : Prop) : f (g414 x) = f (g413 x) @[simp] axiom s414 (x : Prop) : f (g415 x) = f (g414 x) @[simp] axiom s415 (x : Prop) : f (g416 x) = f (g415 x) @[simp] axiom s416 (x : Prop) : f (g417 x) = f (g416 x) @[simp] axiom s417 (x : Prop) : f (g418 x) = f (g417 x) @[simp] axiom s418 (x : Prop) : f (g419 x) = f (g418 x) @[simp] axiom s419 (x : Prop) : f (g420 x) = f (g419 x) @[simp] axiom s420 (x : Prop) : f (g421 x) = f (g420 x) @[simp] axiom s421 (x : Prop) : f (g422 x) = f (g421 x) @[simp] axiom s422 (x : Prop) : f (g423 x) = f (g422 x) @[simp] axiom s423 (x : Prop) : f (g424 x) = f (g423 x) @[simp] axiom s424 (x : Prop) : f (g425 x) = f (g424 x) @[simp] axiom s425 (x : Prop) : f (g426 x) = f (g425 x) @[simp] axiom s426 (x : Prop) : f (g427 x) = f (g426 x) @[simp] axiom s427 (x : Prop) : f (g428 x) = f (g427 x) @[simp] axiom s428 (x : Prop) : f (g429 x) = f (g428 x) @[simp] axiom s429 (x : Prop) : f (g430 x) = f (g429 x) @[simp] axiom s430 (x : Prop) : f (g431 x) = f (g430 x) @[simp] axiom s431 (x : Prop) : f (g432 x) = f (g431 x) @[simp] axiom s432 (x : Prop) : f (g433 x) = f (g432 x) @[simp] axiom s433 (x : Prop) : f (g434 x) = f (g433 x) @[simp] axiom s434 (x : Prop) : f (g435 x) = f (g434 x) @[simp] axiom s435 (x : Prop) : f (g436 x) = f (g435 x) @[simp] axiom s436 (x : Prop) : f (g437 x) = f (g436 x) @[simp] axiom s437 (x : Prop) : f (g438 x) = f (g437 x) @[simp] axiom s438 (x : Prop) : f (g439 x) = f (g438 x) @[simp] axiom s439 (x : Prop) : f (g440 x) = f (g439 x) @[simp] axiom s440 (x : Prop) : f (g441 x) = f (g440 x) @[simp] axiom s441 (x : Prop) : f (g442 x) = f (g441 x) @[simp] axiom s442 (x : Prop) : f (g443 x) = f (g442 x) @[simp] axiom s443 (x : Prop) : f (g444 x) = f (g443 x) @[simp] axiom s444 (x : Prop) : f (g445 x) = f (g444 x) @[simp] axiom s445 (x : Prop) : f (g446 x) = f (g445 x) @[simp] axiom s446 (x : Prop) : f (g447 x) = f (g446 x) @[simp] axiom s447 (x : Prop) : f (g448 x) = f (g447 x) @[simp] axiom s448 (x : Prop) : f (g449 x) = f (g448 x) @[simp] axiom s449 (x : Prop) : f (g450 x) = f (g449 x) @[simp] axiom s450 (x : Prop) : f (g451 x) = f (g450 x) @[simp] axiom s451 (x : Prop) : f (g452 x) = f (g451 x) @[simp] axiom s452 (x : Prop) : f (g453 x) = f (g452 x) @[simp] axiom s453 (x : Prop) : f (g454 x) = f (g453 x) @[simp] axiom s454 (x : Prop) : f (g455 x) = f (g454 x) @[simp] axiom s455 (x : Prop) : f (g456 x) = f (g455 x) @[simp] axiom s456 (x : Prop) : f (g457 x) = f (g456 x) @[simp] axiom s457 (x : Prop) : f (g458 x) = f (g457 x) @[simp] axiom s458 (x : Prop) : f (g459 x) = f (g458 x) @[simp] axiom s459 (x : Prop) : f (g460 x) = f (g459 x) @[simp] axiom s460 (x : Prop) : f (g461 x) = f (g460 x) @[simp] axiom s461 (x : Prop) : f (g462 x) = f (g461 x) @[simp] axiom s462 (x : Prop) : f (g463 x) = f (g462 x) @[simp] axiom s463 (x : Prop) : f (g464 x) = f (g463 x) @[simp] axiom s464 (x : Prop) : f (g465 x) = f (g464 x) @[simp] axiom s465 (x : Prop) : f (g466 x) = f (g465 x) @[simp] axiom s466 (x : Prop) : f (g467 x) = f (g466 x) @[simp] axiom s467 (x : Prop) : f (g468 x) = f (g467 x) @[simp] axiom s468 (x : Prop) : f (g469 x) = f (g468 x) @[simp] axiom s469 (x : Prop) : f (g470 x) = f (g469 x) @[simp] axiom s470 (x : Prop) : f (g471 x) = f (g470 x) @[simp] axiom s471 (x : Prop) : f (g472 x) = f (g471 x) @[simp] axiom s472 (x : Prop) : f (g473 x) = f (g472 x) @[simp] axiom s473 (x : Prop) : f (g474 x) = f (g473 x) @[simp] axiom s474 (x : Prop) : f (g475 x) = f (g474 x) @[simp] axiom s475 (x : Prop) : f (g476 x) = f (g475 x) @[simp] axiom s476 (x : Prop) : f (g477 x) = f (g476 x) @[simp] axiom s477 (x : Prop) : f (g478 x) = f (g477 x) @[simp] axiom s478 (x : Prop) : f (g479 x) = f (g478 x) @[simp] axiom s479 (x : Prop) : f (g480 x) = f (g479 x) @[simp] axiom s480 (x : Prop) : f (g481 x) = f (g480 x) @[simp] axiom s481 (x : Prop) : f (g482 x) = f (g481 x) @[simp] axiom s482 (x : Prop) : f (g483 x) = f (g482 x) @[simp] axiom s483 (x : Prop) : f (g484 x) = f (g483 x) @[simp] axiom s484 (x : Prop) : f (g485 x) = f (g484 x) @[simp] axiom s485 (x : Prop) : f (g486 x) = f (g485 x) @[simp] axiom s486 (x : Prop) : f (g487 x) = f (g486 x) @[simp] axiom s487 (x : Prop) : f (g488 x) = f (g487 x) @[simp] axiom s488 (x : Prop) : f (g489 x) = f (g488 x) @[simp] axiom s489 (x : Prop) : f (g490 x) = f (g489 x) @[simp] axiom s490 (x : Prop) : f (g491 x) = f (g490 x) @[simp] axiom s491 (x : Prop) : f (g492 x) = f (g491 x) @[simp] axiom s492 (x : Prop) : f (g493 x) = f (g492 x) @[simp] axiom s493 (x : Prop) : f (g494 x) = f (g493 x) @[simp] axiom s494 (x : Prop) : f (g495 x) = f (g494 x) @[simp] axiom s495 (x : Prop) : f (g496 x) = f (g495 x) @[simp] axiom s496 (x : Prop) : f (g497 x) = f (g496 x) @[simp] axiom s497 (x : Prop) : f (g498 x) = f (g497 x) @[simp] axiom s498 (x : Prop) : f (g499 x) = f (g498 x) @[simp] axiom s499 (x : Prop) : f (g500 x) = f (g499 x) @[simp] axiom s500 (x : Prop) : f (g501 x) = f (g500 x) @[simp] axiom s501 (x : Prop) : f (g502 x) = f (g501 x) @[simp] axiom s502 (x : Prop) : f (g503 x) = f (g502 x) @[simp] axiom s503 (x : Prop) : f (g504 x) = f (g503 x) @[simp] axiom s504 (x : Prop) : f (g505 x) = f (g504 x) @[simp] axiom s505 (x : Prop) : f (g506 x) = f (g505 x) @[simp] axiom s506 (x : Prop) : f (g507 x) = f (g506 x) @[simp] axiom s507 (x : Prop) : f (g508 x) = f (g507 x) @[simp] axiom s508 (x : Prop) : f (g509 x) = f (g508 x) @[simp] axiom s509 (x : Prop) : f (g510 x) = f (g509 x) @[simp] axiom s510 (x : Prop) : f (g511 x) = f (g510 x) @[simp] axiom s511 (x : Prop) : f (g512 x) = f (g511 x) @[simp] axiom s512 (x : Prop) : f (g513 x) = f (g512 x) @[simp] axiom s513 (x : Prop) : f (g514 x) = f (g513 x) @[simp] axiom s514 (x : Prop) : f (g515 x) = f (g514 x) @[simp] axiom s515 (x : Prop) : f (g516 x) = f (g515 x) @[simp] axiom s516 (x : Prop) : f (g517 x) = f (g516 x) @[simp] axiom s517 (x : Prop) : f (g518 x) = f (g517 x) @[simp] axiom s518 (x : Prop) : f (g519 x) = f (g518 x) @[simp] axiom s519 (x : Prop) : f (g520 x) = f (g519 x) @[simp] axiom s520 (x : Prop) : f (g521 x) = f (g520 x) @[simp] axiom s521 (x : Prop) : f (g522 x) = f (g521 x) @[simp] axiom s522 (x : Prop) : f (g523 x) = f (g522 x) @[simp] axiom s523 (x : Prop) : f (g524 x) = f (g523 x) @[simp] axiom s524 (x : Prop) : f (g525 x) = f (g524 x) @[simp] axiom s525 (x : Prop) : f (g526 x) = f (g525 x) @[simp] axiom s526 (x : Prop) : f (g527 x) = f (g526 x) @[simp] axiom s527 (x : Prop) : f (g528 x) = f (g527 x) @[simp] axiom s528 (x : Prop) : f (g529 x) = f (g528 x) @[simp] axiom s529 (x : Prop) : f (g530 x) = f (g529 x) @[simp] axiom s530 (x : Prop) : f (g531 x) = f (g530 x) @[simp] axiom s531 (x : Prop) : f (g532 x) = f (g531 x) @[simp] axiom s532 (x : Prop) : f (g533 x) = f (g532 x) @[simp] axiom s533 (x : Prop) : f (g534 x) = f (g533 x) @[simp] axiom s534 (x : Prop) : f (g535 x) = f (g534 x) @[simp] axiom s535 (x : Prop) : f (g536 x) = f (g535 x) @[simp] axiom s536 (x : Prop) : f (g537 x) = f (g536 x) @[simp] axiom s537 (x : Prop) : f (g538 x) = f (g537 x) @[simp] axiom s538 (x : Prop) : f (g539 x) = f (g538 x) @[simp] axiom s539 (x : Prop) : f (g540 x) = f (g539 x) @[simp] axiom s540 (x : Prop) : f (g541 x) = f (g540 x) @[simp] axiom s541 (x : Prop) : f (g542 x) = f (g541 x) @[simp] axiom s542 (x : Prop) : f (g543 x) = f (g542 x) @[simp] axiom s543 (x : Prop) : f (g544 x) = f (g543 x) @[simp] axiom s544 (x : Prop) : f (g545 x) = f (g544 x) @[simp] axiom s545 (x : Prop) : f (g546 x) = f (g545 x) @[simp] axiom s546 (x : Prop) : f (g547 x) = f (g546 x) @[simp] axiom s547 (x : Prop) : f (g548 x) = f (g547 x) @[simp] axiom s548 (x : Prop) : f (g549 x) = f (g548 x) @[simp] axiom s549 (x : Prop) : f (g550 x) = f (g549 x) @[simp] axiom s550 (x : Prop) : f (g551 x) = f (g550 x) @[simp] axiom s551 (x : Prop) : f (g552 x) = f (g551 x) @[simp] axiom s552 (x : Prop) : f (g553 x) = f (g552 x) @[simp] axiom s553 (x : Prop) : f (g554 x) = f (g553 x) @[simp] axiom s554 (x : Prop) : f (g555 x) = f (g554 x) @[simp] axiom s555 (x : Prop) : f (g556 x) = f (g555 x) @[simp] axiom s556 (x : Prop) : f (g557 x) = f (g556 x) @[simp] axiom s557 (x : Prop) : f (g558 x) = f (g557 x) @[simp] axiom s558 (x : Prop) : f (g559 x) = f (g558 x) @[simp] axiom s559 (x : Prop) : f (g560 x) = f (g559 x) @[simp] axiom s560 (x : Prop) : f (g561 x) = f (g560 x) @[simp] axiom s561 (x : Prop) : f (g562 x) = f (g561 x) @[simp] axiom s562 (x : Prop) : f (g563 x) = f (g562 x) @[simp] axiom s563 (x : Prop) : f (g564 x) = f (g563 x) @[simp] axiom s564 (x : Prop) : f (g565 x) = f (g564 x) @[simp] axiom s565 (x : Prop) : f (g566 x) = f (g565 x) @[simp] axiom s566 (x : Prop) : f (g567 x) = f (g566 x) @[simp] axiom s567 (x : Prop) : f (g568 x) = f (g567 x) @[simp] axiom s568 (x : Prop) : f (g569 x) = f (g568 x) @[simp] axiom s569 (x : Prop) : f (g570 x) = f (g569 x) @[simp] axiom s570 (x : Prop) : f (g571 x) = f (g570 x) @[simp] axiom s571 (x : Prop) : f (g572 x) = f (g571 x) @[simp] axiom s572 (x : Prop) : f (g573 x) = f (g572 x) @[simp] axiom s573 (x : Prop) : f (g574 x) = f (g573 x) @[simp] axiom s574 (x : Prop) : f (g575 x) = f (g574 x) @[simp] axiom s575 (x : Prop) : f (g576 x) = f (g575 x) @[simp] axiom s576 (x : Prop) : f (g577 x) = f (g576 x) @[simp] axiom s577 (x : Prop) : f (g578 x) = f (g577 x) @[simp] axiom s578 (x : Prop) : f (g579 x) = f (g578 x) @[simp] axiom s579 (x : Prop) : f (g580 x) = f (g579 x) @[simp] axiom s580 (x : Prop) : f (g581 x) = f (g580 x) @[simp] axiom s581 (x : Prop) : f (g582 x) = f (g581 x) @[simp] axiom s582 (x : Prop) : f (g583 x) = f (g582 x) @[simp] axiom s583 (x : Prop) : f (g584 x) = f (g583 x) @[simp] axiom s584 (x : Prop) : f (g585 x) = f (g584 x) @[simp] axiom s585 (x : Prop) : f (g586 x) = f (g585 x) @[simp] axiom s586 (x : Prop) : f (g587 x) = f (g586 x) @[simp] axiom s587 (x : Prop) : f (g588 x) = f (g587 x) @[simp] axiom s588 (x : Prop) : f (g589 x) = f (g588 x) @[simp] axiom s589 (x : Prop) : f (g590 x) = f (g589 x) @[simp] axiom s590 (x : Prop) : f (g591 x) = f (g590 x) @[simp] axiom s591 (x : Prop) : f (g592 x) = f (g591 x) @[simp] axiom s592 (x : Prop) : f (g593 x) = f (g592 x) @[simp] axiom s593 (x : Prop) : f (g594 x) = f (g593 x) @[simp] axiom s594 (x : Prop) : f (g595 x) = f (g594 x) @[simp] axiom s595 (x : Prop) : f (g596 x) = f (g595 x) @[simp] axiom s596 (x : Prop) : f (g597 x) = f (g596 x) @[simp] axiom s597 (x : Prop) : f (g598 x) = f (g597 x) @[simp] axiom s598 (x : Prop) : f (g599 x) = f (g598 x) @[simp] axiom s599 (x : Prop) : f (g600 x) = f (g599 x) @[simp] axiom s600 (x : Prop) : f (g601 x) = f (g600 x) @[simp] axiom s601 (x : Prop) : f (g602 x) = f (g601 x) @[simp] axiom s602 (x : Prop) : f (g603 x) = f (g602 x) @[simp] axiom s603 (x : Prop) : f (g604 x) = f (g603 x) @[simp] axiom s604 (x : Prop) : f (g605 x) = f (g604 x) @[simp] axiom s605 (x : Prop) : f (g606 x) = f (g605 x) @[simp] axiom s606 (x : Prop) : f (g607 x) = f (g606 x) @[simp] axiom s607 (x : Prop) : f (g608 x) = f (g607 x) @[simp] axiom s608 (x : Prop) : f (g609 x) = f (g608 x) @[simp] axiom s609 (x : Prop) : f (g610 x) = f (g609 x) @[simp] axiom s610 (x : Prop) : f (g611 x) = f (g610 x) @[simp] axiom s611 (x : Prop) : f (g612 x) = f (g611 x) @[simp] axiom s612 (x : Prop) : f (g613 x) = f (g612 x) @[simp] axiom s613 (x : Prop) : f (g614 x) = f (g613 x) @[simp] axiom s614 (x : Prop) : f (g615 x) = f (g614 x) @[simp] axiom s615 (x : Prop) : f (g616 x) = f (g615 x) @[simp] axiom s616 (x : Prop) : f (g617 x) = f (g616 x) @[simp] axiom s617 (x : Prop) : f (g618 x) = f (g617 x) @[simp] axiom s618 (x : Prop) : f (g619 x) = f (g618 x) @[simp] axiom s619 (x : Prop) : f (g620 x) = f (g619 x) @[simp] axiom s620 (x : Prop) : f (g621 x) = f (g620 x) @[simp] axiom s621 (x : Prop) : f (g622 x) = f (g621 x) @[simp] axiom s622 (x : Prop) : f (g623 x) = f (g622 x) @[simp] axiom s623 (x : Prop) : f (g624 x) = f (g623 x) @[simp] axiom s624 (x : Prop) : f (g625 x) = f (g624 x) @[simp] axiom s625 (x : Prop) : f (g626 x) = f (g625 x) @[simp] axiom s626 (x : Prop) : f (g627 x) = f (g626 x) @[simp] axiom s627 (x : Prop) : f (g628 x) = f (g627 x) @[simp] axiom s628 (x : Prop) : f (g629 x) = f (g628 x) @[simp] axiom s629 (x : Prop) : f (g630 x) = f (g629 x) @[simp] axiom s630 (x : Prop) : f (g631 x) = f (g630 x) @[simp] axiom s631 (x : Prop) : f (g632 x) = f (g631 x) @[simp] axiom s632 (x : Prop) : f (g633 x) = f (g632 x) @[simp] axiom s633 (x : Prop) : f (g634 x) = f (g633 x) @[simp] axiom s634 (x : Prop) : f (g635 x) = f (g634 x) @[simp] axiom s635 (x : Prop) : f (g636 x) = f (g635 x) @[simp] axiom s636 (x : Prop) : f (g637 x) = f (g636 x) @[simp] axiom s637 (x : Prop) : f (g638 x) = f (g637 x) @[simp] axiom s638 (x : Prop) : f (g639 x) = f (g638 x) @[simp] axiom s639 (x : Prop) : f (g640 x) = f (g639 x) @[simp] axiom s640 (x : Prop) : f (g641 x) = f (g640 x) @[simp] axiom s641 (x : Prop) : f (g642 x) = f (g641 x) @[simp] axiom s642 (x : Prop) : f (g643 x) = f (g642 x) @[simp] axiom s643 (x : Prop) : f (g644 x) = f (g643 x) @[simp] axiom s644 (x : Prop) : f (g645 x) = f (g644 x) @[simp] axiom s645 (x : Prop) : f (g646 x) = f (g645 x) @[simp] axiom s646 (x : Prop) : f (g647 x) = f (g646 x) @[simp] axiom s647 (x : Prop) : f (g648 x) = f (g647 x) @[simp] axiom s648 (x : Prop) : f (g649 x) = f (g648 x) @[simp] axiom s649 (x : Prop) : f (g650 x) = f (g649 x) @[simp] axiom s650 (x : Prop) : f (g651 x) = f (g650 x) @[simp] axiom s651 (x : Prop) : f (g652 x) = f (g651 x) @[simp] axiom s652 (x : Prop) : f (g653 x) = f (g652 x) @[simp] axiom s653 (x : Prop) : f (g654 x) = f (g653 x) @[simp] axiom s654 (x : Prop) : f (g655 x) = f (g654 x) @[simp] axiom s655 (x : Prop) : f (g656 x) = f (g655 x) @[simp] axiom s656 (x : Prop) : f (g657 x) = f (g656 x) @[simp] axiom s657 (x : Prop) : f (g658 x) = f (g657 x) @[simp] axiom s658 (x : Prop) : f (g659 x) = f (g658 x) @[simp] axiom s659 (x : Prop) : f (g660 x) = f (g659 x) @[simp] axiom s660 (x : Prop) : f (g661 x) = f (g660 x) @[simp] axiom s661 (x : Prop) : f (g662 x) = f (g661 x) @[simp] axiom s662 (x : Prop) : f (g663 x) = f (g662 x) @[simp] axiom s663 (x : Prop) : f (g664 x) = f (g663 x) @[simp] axiom s664 (x : Prop) : f (g665 x) = f (g664 x) @[simp] axiom s665 (x : Prop) : f (g666 x) = f (g665 x) @[simp] axiom s666 (x : Prop) : f (g667 x) = f (g666 x) @[simp] axiom s667 (x : Prop) : f (g668 x) = f (g667 x) @[simp] axiom s668 (x : Prop) : f (g669 x) = f (g668 x) @[simp] axiom s669 (x : Prop) : f (g670 x) = f (g669 x) @[simp] axiom s670 (x : Prop) : f (g671 x) = f (g670 x) @[simp] axiom s671 (x : Prop) : f (g672 x) = f (g671 x) @[simp] axiom s672 (x : Prop) : f (g673 x) = f (g672 x) @[simp] axiom s673 (x : Prop) : f (g674 x) = f (g673 x) @[simp] axiom s674 (x : Prop) : f (g675 x) = f (g674 x) @[simp] axiom s675 (x : Prop) : f (g676 x) = f (g675 x) @[simp] axiom s676 (x : Prop) : f (g677 x) = f (g676 x) @[simp] axiom s677 (x : Prop) : f (g678 x) = f (g677 x) @[simp] axiom s678 (x : Prop) : f (g679 x) = f (g678 x) @[simp] axiom s679 (x : Prop) : f (g680 x) = f (g679 x) @[simp] axiom s680 (x : Prop) : f (g681 x) = f (g680 x) @[simp] axiom s681 (x : Prop) : f (g682 x) = f (g681 x) @[simp] axiom s682 (x : Prop) : f (g683 x) = f (g682 x) @[simp] axiom s683 (x : Prop) : f (g684 x) = f (g683 x) @[simp] axiom s684 (x : Prop) : f (g685 x) = f (g684 x) @[simp] axiom s685 (x : Prop) : f (g686 x) = f (g685 x) @[simp] axiom s686 (x : Prop) : f (g687 x) = f (g686 x) @[simp] axiom s687 (x : Prop) : f (g688 x) = f (g687 x) @[simp] axiom s688 (x : Prop) : f (g689 x) = f (g688 x) @[simp] axiom s689 (x : Prop) : f (g690 x) = f (g689 x) @[simp] axiom s690 (x : Prop) : f (g691 x) = f (g690 x) @[simp] axiom s691 (x : Prop) : f (g692 x) = f (g691 x) @[simp] axiom s692 (x : Prop) : f (g693 x) = f (g692 x) @[simp] axiom s693 (x : Prop) : f (g694 x) = f (g693 x) @[simp] axiom s694 (x : Prop) : f (g695 x) = f (g694 x) @[simp] axiom s695 (x : Prop) : f (g696 x) = f (g695 x) @[simp] axiom s696 (x : Prop) : f (g697 x) = f (g696 x) @[simp] axiom s697 (x : Prop) : f (g698 x) = f (g697 x) @[simp] axiom s698 (x : Prop) : f (g699 x) = f (g698 x) @[simp] axiom s699 (x : Prop) : f (g700 x) = f (g699 x) @[simp] axiom s700 (x : Prop) : f (g701 x) = f (g700 x) @[simp] axiom s701 (x : Prop) : f (g702 x) = f (g701 x) @[simp] axiom s702 (x : Prop) : f (g703 x) = f (g702 x) @[simp] axiom s703 (x : Prop) : f (g704 x) = f (g703 x) @[simp] axiom s704 (x : Prop) : f (g705 x) = f (g704 x) @[simp] axiom s705 (x : Prop) : f (g706 x) = f (g705 x) @[simp] axiom s706 (x : Prop) : f (g707 x) = f (g706 x) @[simp] axiom s707 (x : Prop) : f (g708 x) = f (g707 x) @[simp] axiom s708 (x : Prop) : f (g709 x) = f (g708 x) @[simp] axiom s709 (x : Prop) : f (g710 x) = f (g709 x) @[simp] axiom s710 (x : Prop) : f (g711 x) = f (g710 x) @[simp] axiom s711 (x : Prop) : f (g712 x) = f (g711 x) @[simp] axiom s712 (x : Prop) : f (g713 x) = f (g712 x) @[simp] axiom s713 (x : Prop) : f (g714 x) = f (g713 x) @[simp] axiom s714 (x : Prop) : f (g715 x) = f (g714 x) @[simp] axiom s715 (x : Prop) : f (g716 x) = f (g715 x) @[simp] axiom s716 (x : Prop) : f (g717 x) = f (g716 x) @[simp] axiom s717 (x : Prop) : f (g718 x) = f (g717 x) @[simp] axiom s718 (x : Prop) : f (g719 x) = f (g718 x) @[simp] axiom s719 (x : Prop) : f (g720 x) = f (g719 x) @[simp] axiom s720 (x : Prop) : f (g721 x) = f (g720 x) @[simp] axiom s721 (x : Prop) : f (g722 x) = f (g721 x) @[simp] axiom s722 (x : Prop) : f (g723 x) = f (g722 x) @[simp] axiom s723 (x : Prop) : f (g724 x) = f (g723 x) @[simp] axiom s724 (x : Prop) : f (g725 x) = f (g724 x) @[simp] axiom s725 (x : Prop) : f (g726 x) = f (g725 x) @[simp] axiom s726 (x : Prop) : f (g727 x) = f (g726 x) @[simp] axiom s727 (x : Prop) : f (g728 x) = f (g727 x) @[simp] axiom s728 (x : Prop) : f (g729 x) = f (g728 x) @[simp] axiom s729 (x : Prop) : f (g730 x) = f (g729 x) @[simp] axiom s730 (x : Prop) : f (g731 x) = f (g730 x) @[simp] axiom s731 (x : Prop) : f (g732 x) = f (g731 x) @[simp] axiom s732 (x : Prop) : f (g733 x) = f (g732 x) @[simp] axiom s733 (x : Prop) : f (g734 x) = f (g733 x) @[simp] axiom s734 (x : Prop) : f (g735 x) = f (g734 x) @[simp] axiom s735 (x : Prop) : f (g736 x) = f (g735 x) @[simp] axiom s736 (x : Prop) : f (g737 x) = f (g736 x) @[simp] axiom s737 (x : Prop) : f (g738 x) = f (g737 x) @[simp] axiom s738 (x : Prop) : f (g739 x) = f (g738 x) @[simp] axiom s739 (x : Prop) : f (g740 x) = f (g739 x) @[simp] axiom s740 (x : Prop) : f (g741 x) = f (g740 x) @[simp] axiom s741 (x : Prop) : f (g742 x) = f (g741 x) @[simp] axiom s742 (x : Prop) : f (g743 x) = f (g742 x) @[simp] axiom s743 (x : Prop) : f (g744 x) = f (g743 x) @[simp] axiom s744 (x : Prop) : f (g745 x) = f (g744 x) @[simp] axiom s745 (x : Prop) : f (g746 x) = f (g745 x) @[simp] axiom s746 (x : Prop) : f (g747 x) = f (g746 x) @[simp] axiom s747 (x : Prop) : f (g748 x) = f (g747 x) @[simp] axiom s748 (x : Prop) : f (g749 x) = f (g748 x) @[simp] axiom s749 (x : Prop) : f (g750 x) = f (g749 x) @[simp] axiom s750 (x : Prop) : f (g751 x) = f (g750 x) @[simp] axiom s751 (x : Prop) : f (g752 x) = f (g751 x) @[simp] axiom s752 (x : Prop) : f (g753 x) = f (g752 x) @[simp] axiom s753 (x : Prop) : f (g754 x) = f (g753 x) @[simp] axiom s754 (x : Prop) : f (g755 x) = f (g754 x) @[simp] axiom s755 (x : Prop) : f (g756 x) = f (g755 x) @[simp] axiom s756 (x : Prop) : f (g757 x) = f (g756 x) @[simp] axiom s757 (x : Prop) : f (g758 x) = f (g757 x) @[simp] axiom s758 (x : Prop) : f (g759 x) = f (g758 x) @[simp] axiom s759 (x : Prop) : f (g760 x) = f (g759 x) @[simp] axiom s760 (x : Prop) : f (g761 x) = f (g760 x) @[simp] axiom s761 (x : Prop) : f (g762 x) = f (g761 x) @[simp] axiom s762 (x : Prop) : f (g763 x) = f (g762 x) @[simp] axiom s763 (x : Prop) : f (g764 x) = f (g763 x) @[simp] axiom s764 (x : Prop) : f (g765 x) = f (g764 x) @[simp] axiom s765 (x : Prop) : f (g766 x) = f (g765 x) @[simp] axiom s766 (x : Prop) : f (g767 x) = f (g766 x) @[simp] axiom s767 (x : Prop) : f (g768 x) = f (g767 x) @[simp] axiom s768 (x : Prop) : f (g769 x) = f (g768 x) @[simp] axiom s769 (x : Prop) : f (g770 x) = f (g769 x) @[simp] axiom s770 (x : Prop) : f (g771 x) = f (g770 x) @[simp] axiom s771 (x : Prop) : f (g772 x) = f (g771 x) @[simp] axiom s772 (x : Prop) : f (g773 x) = f (g772 x) @[simp] axiom s773 (x : Prop) : f (g774 x) = f (g773 x) @[simp] axiom s774 (x : Prop) : f (g775 x) = f (g774 x) @[simp] axiom s775 (x : Prop) : f (g776 x) = f (g775 x) @[simp] axiom s776 (x : Prop) : f (g777 x) = f (g776 x) @[simp] axiom s777 (x : Prop) : f (g778 x) = f (g777 x) @[simp] axiom s778 (x : Prop) : f (g779 x) = f (g778 x) @[simp] axiom s779 (x : Prop) : f (g780 x) = f (g779 x) @[simp] axiom s780 (x : Prop) : f (g781 x) = f (g780 x) @[simp] axiom s781 (x : Prop) : f (g782 x) = f (g781 x) @[simp] axiom s782 (x : Prop) : f (g783 x) = f (g782 x) @[simp] axiom s783 (x : Prop) : f (g784 x) = f (g783 x) @[simp] axiom s784 (x : Prop) : f (g785 x) = f (g784 x) @[simp] axiom s785 (x : Prop) : f (g786 x) = f (g785 x) @[simp] axiom s786 (x : Prop) : f (g787 x) = f (g786 x) @[simp] axiom s787 (x : Prop) : f (g788 x) = f (g787 x) @[simp] axiom s788 (x : Prop) : f (g789 x) = f (g788 x) @[simp] axiom s789 (x : Prop) : f (g790 x) = f (g789 x) @[simp] axiom s790 (x : Prop) : f (g791 x) = f (g790 x) @[simp] axiom s791 (x : Prop) : f (g792 x) = f (g791 x) @[simp] axiom s792 (x : Prop) : f (g793 x) = f (g792 x) @[simp] axiom s793 (x : Prop) : f (g794 x) = f (g793 x) @[simp] axiom s794 (x : Prop) : f (g795 x) = f (g794 x) @[simp] axiom s795 (x : Prop) : f (g796 x) = f (g795 x) @[simp] axiom s796 (x : Prop) : f (g797 x) = f (g796 x) @[simp] axiom s797 (x : Prop) : f (g798 x) = f (g797 x) @[simp] axiom s798 (x : Prop) : f (g799 x) = f (g798 x) @[simp] axiom s799 (x : Prop) : f (g800 x) = f (g799 x) @[simp] axiom s800 (x : Prop) : f (g801 x) = f (g800 x) @[simp] axiom s801 (x : Prop) : f (g802 x) = f (g801 x) @[simp] axiom s802 (x : Prop) : f (g803 x) = f (g802 x) @[simp] axiom s803 (x : Prop) : f (g804 x) = f (g803 x) @[simp] axiom s804 (x : Prop) : f (g805 x) = f (g804 x) @[simp] axiom s805 (x : Prop) : f (g806 x) = f (g805 x) @[simp] axiom s806 (x : Prop) : f (g807 x) = f (g806 x) @[simp] axiom s807 (x : Prop) : f (g808 x) = f (g807 x) @[simp] axiom s808 (x : Prop) : f (g809 x) = f (g808 x) @[simp] axiom s809 (x : Prop) : f (g810 x) = f (g809 x) @[simp] axiom s810 (x : Prop) : f (g811 x) = f (g810 x) @[simp] axiom s811 (x : Prop) : f (g812 x) = f (g811 x) @[simp] axiom s812 (x : Prop) : f (g813 x) = f (g812 x) @[simp] axiom s813 (x : Prop) : f (g814 x) = f (g813 x) @[simp] axiom s814 (x : Prop) : f (g815 x) = f (g814 x) @[simp] axiom s815 (x : Prop) : f (g816 x) = f (g815 x) @[simp] axiom s816 (x : Prop) : f (g817 x) = f (g816 x) @[simp] axiom s817 (x : Prop) : f (g818 x) = f (g817 x) @[simp] axiom s818 (x : Prop) : f (g819 x) = f (g818 x) @[simp] axiom s819 (x : Prop) : f (g820 x) = f (g819 x) @[simp] axiom s820 (x : Prop) : f (g821 x) = f (g820 x) @[simp] axiom s821 (x : Prop) : f (g822 x) = f (g821 x) @[simp] axiom s822 (x : Prop) : f (g823 x) = f (g822 x) @[simp] axiom s823 (x : Prop) : f (g824 x) = f (g823 x) @[simp] axiom s824 (x : Prop) : f (g825 x) = f (g824 x) @[simp] axiom s825 (x : Prop) : f (g826 x) = f (g825 x) @[simp] axiom s826 (x : Prop) : f (g827 x) = f (g826 x) @[simp] axiom s827 (x : Prop) : f (g828 x) = f (g827 x) @[simp] axiom s828 (x : Prop) : f (g829 x) = f (g828 x) @[simp] axiom s829 (x : Prop) : f (g830 x) = f (g829 x) @[simp] axiom s830 (x : Prop) : f (g831 x) = f (g830 x) @[simp] axiom s831 (x : Prop) : f (g832 x) = f (g831 x) @[simp] axiom s832 (x : Prop) : f (g833 x) = f (g832 x) @[simp] axiom s833 (x : Prop) : f (g834 x) = f (g833 x) @[simp] axiom s834 (x : Prop) : f (g835 x) = f (g834 x) @[simp] axiom s835 (x : Prop) : f (g836 x) = f (g835 x) @[simp] axiom s836 (x : Prop) : f (g837 x) = f (g836 x) @[simp] axiom s837 (x : Prop) : f (g838 x) = f (g837 x) @[simp] axiom s838 (x : Prop) : f (g839 x) = f (g838 x) @[simp] axiom s839 (x : Prop) : f (g840 x) = f (g839 x) @[simp] axiom s840 (x : Prop) : f (g841 x) = f (g840 x) @[simp] axiom s841 (x : Prop) : f (g842 x) = f (g841 x) @[simp] axiom s842 (x : Prop) : f (g843 x) = f (g842 x) @[simp] axiom s843 (x : Prop) : f (g844 x) = f (g843 x) @[simp] axiom s844 (x : Prop) : f (g845 x) = f (g844 x) @[simp] axiom s845 (x : Prop) : f (g846 x) = f (g845 x) @[simp] axiom s846 (x : Prop) : f (g847 x) = f (g846 x) @[simp] axiom s847 (x : Prop) : f (g848 x) = f (g847 x) @[simp] axiom s848 (x : Prop) : f (g849 x) = f (g848 x) @[simp] axiom s849 (x : Prop) : f (g850 x) = f (g849 x) @[simp] axiom s850 (x : Prop) : f (g851 x) = f (g850 x) @[simp] axiom s851 (x : Prop) : f (g852 x) = f (g851 x) @[simp] axiom s852 (x : Prop) : f (g853 x) = f (g852 x) @[simp] axiom s853 (x : Prop) : f (g854 x) = f (g853 x) @[simp] axiom s854 (x : Prop) : f (g855 x) = f (g854 x) @[simp] axiom s855 (x : Prop) : f (g856 x) = f (g855 x) @[simp] axiom s856 (x : Prop) : f (g857 x) = f (g856 x) @[simp] axiom s857 (x : Prop) : f (g858 x) = f (g857 x) @[simp] axiom s858 (x : Prop) : f (g859 x) = f (g858 x) @[simp] axiom s859 (x : Prop) : f (g860 x) = f (g859 x) @[simp] axiom s860 (x : Prop) : f (g861 x) = f (g860 x) @[simp] axiom s861 (x : Prop) : f (g862 x) = f (g861 x) @[simp] axiom s862 (x : Prop) : f (g863 x) = f (g862 x) @[simp] axiom s863 (x : Prop) : f (g864 x) = f (g863 x) @[simp] axiom s864 (x : Prop) : f (g865 x) = f (g864 x) @[simp] axiom s865 (x : Prop) : f (g866 x) = f (g865 x) @[simp] axiom s866 (x : Prop) : f (g867 x) = f (g866 x) @[simp] axiom s867 (x : Prop) : f (g868 x) = f (g867 x) @[simp] axiom s868 (x : Prop) : f (g869 x) = f (g868 x) @[simp] axiom s869 (x : Prop) : f (g870 x) = f (g869 x) @[simp] axiom s870 (x : Prop) : f (g871 x) = f (g870 x) @[simp] axiom s871 (x : Prop) : f (g872 x) = f (g871 x) @[simp] axiom s872 (x : Prop) : f (g873 x) = f (g872 x) @[simp] axiom s873 (x : Prop) : f (g874 x) = f (g873 x) @[simp] axiom s874 (x : Prop) : f (g875 x) = f (g874 x) @[simp] axiom s875 (x : Prop) : f (g876 x) = f (g875 x) @[simp] axiom s876 (x : Prop) : f (g877 x) = f (g876 x) @[simp] axiom s877 (x : Prop) : f (g878 x) = f (g877 x) @[simp] axiom s878 (x : Prop) : f (g879 x) = f (g878 x) @[simp] axiom s879 (x : Prop) : f (g880 x) = f (g879 x) @[simp] axiom s880 (x : Prop) : f (g881 x) = f (g880 x) @[simp] axiom s881 (x : Prop) : f (g882 x) = f (g881 x) @[simp] axiom s882 (x : Prop) : f (g883 x) = f (g882 x) @[simp] axiom s883 (x : Prop) : f (g884 x) = f (g883 x) @[simp] axiom s884 (x : Prop) : f (g885 x) = f (g884 x) @[simp] axiom s885 (x : Prop) : f (g886 x) = f (g885 x) @[simp] axiom s886 (x : Prop) : f (g887 x) = f (g886 x) @[simp] axiom s887 (x : Prop) : f (g888 x) = f (g887 x) @[simp] axiom s888 (x : Prop) : f (g889 x) = f (g888 x) @[simp] axiom s889 (x : Prop) : f (g890 x) = f (g889 x) @[simp] axiom s890 (x : Prop) : f (g891 x) = f (g890 x) @[simp] axiom s891 (x : Prop) : f (g892 x) = f (g891 x) @[simp] axiom s892 (x : Prop) : f (g893 x) = f (g892 x) @[simp] axiom s893 (x : Prop) : f (g894 x) = f (g893 x) @[simp] axiom s894 (x : Prop) : f (g895 x) = f (g894 x) @[simp] axiom s895 (x : Prop) : f (g896 x) = f (g895 x) @[simp] axiom s896 (x : Prop) : f (g897 x) = f (g896 x) @[simp] axiom s897 (x : Prop) : f (g898 x) = f (g897 x) @[simp] axiom s898 (x : Prop) : f (g899 x) = f (g898 x) @[simp] axiom s899 (x : Prop) : f (g900 x) = f (g899 x) @[simp] axiom s900 (x : Prop) : f (g901 x) = f (g900 x) @[simp] axiom s901 (x : Prop) : f (g902 x) = f (g901 x) @[simp] axiom s902 (x : Prop) : f (g903 x) = f (g902 x) @[simp] axiom s903 (x : Prop) : f (g904 x) = f (g903 x) @[simp] axiom s904 (x : Prop) : f (g905 x) = f (g904 x) @[simp] axiom s905 (x : Prop) : f (g906 x) = f (g905 x) @[simp] axiom s906 (x : Prop) : f (g907 x) = f (g906 x) @[simp] axiom s907 (x : Prop) : f (g908 x) = f (g907 x) @[simp] axiom s908 (x : Prop) : f (g909 x) = f (g908 x) @[simp] axiom s909 (x : Prop) : f (g910 x) = f (g909 x) @[simp] axiom s910 (x : Prop) : f (g911 x) = f (g910 x) @[simp] axiom s911 (x : Prop) : f (g912 x) = f (g911 x) @[simp] axiom s912 (x : Prop) : f (g913 x) = f (g912 x) @[simp] axiom s913 (x : Prop) : f (g914 x) = f (g913 x) @[simp] axiom s914 (x : Prop) : f (g915 x) = f (g914 x) @[simp] axiom s915 (x : Prop) : f (g916 x) = f (g915 x) @[simp] axiom s916 (x : Prop) : f (g917 x) = f (g916 x) @[simp] axiom s917 (x : Prop) : f (g918 x) = f (g917 x) @[simp] axiom s918 (x : Prop) : f (g919 x) = f (g918 x) @[simp] axiom s919 (x : Prop) : f (g920 x) = f (g919 x) @[simp] axiom s920 (x : Prop) : f (g921 x) = f (g920 x) @[simp] axiom s921 (x : Prop) : f (g922 x) = f (g921 x) @[simp] axiom s922 (x : Prop) : f (g923 x) = f (g922 x) @[simp] axiom s923 (x : Prop) : f (g924 x) = f (g923 x) @[simp] axiom s924 (x : Prop) : f (g925 x) = f (g924 x) @[simp] axiom s925 (x : Prop) : f (g926 x) = f (g925 x) @[simp] axiom s926 (x : Prop) : f (g927 x) = f (g926 x) @[simp] axiom s927 (x : Prop) : f (g928 x) = f (g927 x) @[simp] axiom s928 (x : Prop) : f (g929 x) = f (g928 x) @[simp] axiom s929 (x : Prop) : f (g930 x) = f (g929 x) @[simp] axiom s930 (x : Prop) : f (g931 x) = f (g930 x) @[simp] axiom s931 (x : Prop) : f (g932 x) = f (g931 x) @[simp] axiom s932 (x : Prop) : f (g933 x) = f (g932 x) @[simp] axiom s933 (x : Prop) : f (g934 x) = f (g933 x) @[simp] axiom s934 (x : Prop) : f (g935 x) = f (g934 x) @[simp] axiom s935 (x : Prop) : f (g936 x) = f (g935 x) @[simp] axiom s936 (x : Prop) : f (g937 x) = f (g936 x) @[simp] axiom s937 (x : Prop) : f (g938 x) = f (g937 x) @[simp] axiom s938 (x : Prop) : f (g939 x) = f (g938 x) @[simp] axiom s939 (x : Prop) : f (g940 x) = f (g939 x) @[simp] axiom s940 (x : Prop) : f (g941 x) = f (g940 x) @[simp] axiom s941 (x : Prop) : f (g942 x) = f (g941 x) @[simp] axiom s942 (x : Prop) : f (g943 x) = f (g942 x) @[simp] axiom s943 (x : Prop) : f (g944 x) = f (g943 x) @[simp] axiom s944 (x : Prop) : f (g945 x) = f (g944 x) @[simp] axiom s945 (x : Prop) : f (g946 x) = f (g945 x) @[simp] axiom s946 (x : Prop) : f (g947 x) = f (g946 x) @[simp] axiom s947 (x : Prop) : f (g948 x) = f (g947 x) @[simp] axiom s948 (x : Prop) : f (g949 x) = f (g948 x) @[simp] axiom s949 (x : Prop) : f (g950 x) = f (g949 x) @[simp] axiom s950 (x : Prop) : f (g951 x) = f (g950 x) @[simp] axiom s951 (x : Prop) : f (g952 x) = f (g951 x) @[simp] axiom s952 (x : Prop) : f (g953 x) = f (g952 x) @[simp] axiom s953 (x : Prop) : f (g954 x) = f (g953 x) @[simp] axiom s954 (x : Prop) : f (g955 x) = f (g954 x) @[simp] axiom s955 (x : Prop) : f (g956 x) = f (g955 x) @[simp] axiom s956 (x : Prop) : f (g957 x) = f (g956 x) @[simp] axiom s957 (x : Prop) : f (g958 x) = f (g957 x) @[simp] axiom s958 (x : Prop) : f (g959 x) = f (g958 x) @[simp] axiom s959 (x : Prop) : f (g960 x) = f (g959 x) @[simp] axiom s960 (x : Prop) : f (g961 x) = f (g960 x) @[simp] axiom s961 (x : Prop) : f (g962 x) = f (g961 x) @[simp] axiom s962 (x : Prop) : f (g963 x) = f (g962 x) @[simp] axiom s963 (x : Prop) : f (g964 x) = f (g963 x) @[simp] axiom s964 (x : Prop) : f (g965 x) = f (g964 x) @[simp] axiom s965 (x : Prop) : f (g966 x) = f (g965 x) @[simp] axiom s966 (x : Prop) : f (g967 x) = f (g966 x) @[simp] axiom s967 (x : Prop) : f (g968 x) = f (g967 x) @[simp] axiom s968 (x : Prop) : f (g969 x) = f (g968 x) @[simp] axiom s969 (x : Prop) : f (g970 x) = f (g969 x) @[simp] axiom s970 (x : Prop) : f (g971 x) = f (g970 x) @[simp] axiom s971 (x : Prop) : f (g972 x) = f (g971 x) @[simp] axiom s972 (x : Prop) : f (g973 x) = f (g972 x) @[simp] axiom s973 (x : Prop) : f (g974 x) = f (g973 x) @[simp] axiom s974 (x : Prop) : f (g975 x) = f (g974 x) @[simp] axiom s975 (x : Prop) : f (g976 x) = f (g975 x) @[simp] axiom s976 (x : Prop) : f (g977 x) = f (g976 x) @[simp] axiom s977 (x : Prop) : f (g978 x) = f (g977 x) @[simp] axiom s978 (x : Prop) : f (g979 x) = f (g978 x) @[simp] axiom s979 (x : Prop) : f (g980 x) = f (g979 x) @[simp] axiom s980 (x : Prop) : f (g981 x) = f (g980 x) @[simp] axiom s981 (x : Prop) : f (g982 x) = f (g981 x) @[simp] axiom s982 (x : Prop) : f (g983 x) = f (g982 x) @[simp] axiom s983 (x : Prop) : f (g984 x) = f (g983 x) @[simp] axiom s984 (x : Prop) : f (g985 x) = f (g984 x) @[simp] axiom s985 (x : Prop) : f (g986 x) = f (g985 x) @[simp] axiom s986 (x : Prop) : f (g987 x) = f (g986 x) @[simp] axiom s987 (x : Prop) : f (g988 x) = f (g987 x) @[simp] axiom s988 (x : Prop) : f (g989 x) = f (g988 x) @[simp] axiom s989 (x : Prop) : f (g990 x) = f (g989 x) @[simp] axiom s990 (x : Prop) : f (g991 x) = f (g990 x) @[simp] axiom s991 (x : Prop) : f (g992 x) = f (g991 x) @[simp] axiom s992 (x : Prop) : f (g993 x) = f (g992 x) @[simp] axiom s993 (x : Prop) : f (g994 x) = f (g993 x) @[simp] axiom s994 (x : Prop) : f (g995 x) = f (g994 x) @[simp] axiom s995 (x : Prop) : f (g996 x) = f (g995 x) @[simp] axiom s996 (x : Prop) : f (g997 x) = f (g996 x) @[simp] axiom s997 (x : Prop) : f (g998 x) = f (g997 x) @[simp] axiom s998 (x : Prop) : f (g999 x) = f (g998 x) @[simp] axiom s999 (x : Prop) : f (g1000 x) = f (g999 x) @[simp] axiom s1000 (x : Prop) : f (g1001 x) = f (g1000 x) @[simp] axiom s1001 (x : Prop) : f (g1002 x) = f (g1001 x) @[simp] axiom s1002 (x : Prop) : f (g1003 x) = f (g1002 x) @[simp] axiom s1003 (x : Prop) : f (g1004 x) = f (g1003 x) @[simp] axiom s1004 (x : Prop) : f (g1005 x) = f (g1004 x) @[simp] axiom s1005 (x : Prop) : f (g1006 x) = f (g1005 x) @[simp] axiom s1006 (x : Prop) : f (g1007 x) = f (g1006 x) @[simp] axiom s1007 (x : Prop) : f (g1008 x) = f (g1007 x) @[simp] axiom s1008 (x : Prop) : f (g1009 x) = f (g1008 x) @[simp] axiom s1009 (x : Prop) : f (g1010 x) = f (g1009 x) @[simp] axiom s1010 (x : Prop) : f (g1011 x) = f (g1010 x) @[simp] axiom s1011 (x : Prop) : f (g1012 x) = f (g1011 x) @[simp] axiom s1012 (x : Prop) : f (g1013 x) = f (g1012 x) @[simp] axiom s1013 (x : Prop) : f (g1014 x) = f (g1013 x) @[simp] axiom s1014 (x : Prop) : f (g1015 x) = f (g1014 x) @[simp] axiom s1015 (x : Prop) : f (g1016 x) = f (g1015 x) @[simp] axiom s1016 (x : Prop) : f (g1017 x) = f (g1016 x) @[simp] axiom s1017 (x : Prop) : f (g1018 x) = f (g1017 x) @[simp] axiom s1018 (x : Prop) : f (g1019 x) = f (g1018 x) @[simp] axiom s1019 (x : Prop) : f (g1020 x) = f (g1019 x) @[simp] axiom s1020 (x : Prop) : f (g1021 x) = f (g1020 x) @[simp] axiom s1021 (x : Prop) : f (g1022 x) = f (g1021 x) @[simp] axiom s1022 (x : Prop) : f (g1023 x) = f (g1022 x) @[simp] axiom s1023 (x : Prop) : f (g1024 x) = f (g1023 x) @[simp] axiom s1024 (x : Prop) : f (g1025 x) = f (g1024 x) @[simp] axiom s1025 (x : Prop) : f (g1026 x) = f (g1025 x) @[simp] axiom s1026 (x : Prop) : f (g1027 x) = f (g1026 x) @[simp] axiom s1027 (x : Prop) : f (g1028 x) = f (g1027 x) @[simp] axiom s1028 (x : Prop) : f (g1029 x) = f (g1028 x) @[simp] axiom s1029 (x : Prop) : f (g1030 x) = f (g1029 x) @[simp] axiom s1030 (x : Prop) : f (g1031 x) = f (g1030 x) @[simp] axiom s1031 (x : Prop) : f (g1032 x) = f (g1031 x) @[simp] axiom s1032 (x : Prop) : f (g1033 x) = f (g1032 x) @[simp] axiom s1033 (x : Prop) : f (g1034 x) = f (g1033 x) @[simp] axiom s1034 (x : Prop) : f (g1035 x) = f (g1034 x) @[simp] axiom s1035 (x : Prop) : f (g1036 x) = f (g1035 x) @[simp] axiom s1036 (x : Prop) : f (g1037 x) = f (g1036 x) @[simp] axiom s1037 (x : Prop) : f (g1038 x) = f (g1037 x) @[simp] axiom s1038 (x : Prop) : f (g1039 x) = f (g1038 x) @[simp] axiom s1039 (x : Prop) : f (g1040 x) = f (g1039 x) @[simp] axiom s1040 (x : Prop) : f (g1041 x) = f (g1040 x) @[simp] axiom s1041 (x : Prop) : f (g1042 x) = f (g1041 x) @[simp] axiom s1042 (x : Prop) : f (g1043 x) = f (g1042 x) @[simp] axiom s1043 (x : Prop) : f (g1044 x) = f (g1043 x) @[simp] axiom s1044 (x : Prop) : f (g1045 x) = f (g1044 x) @[simp] axiom s1045 (x : Prop) : f (g1046 x) = f (g1045 x) @[simp] axiom s1046 (x : Prop) : f (g1047 x) = f (g1046 x) @[simp] axiom s1047 (x : Prop) : f (g1048 x) = f (g1047 x) @[simp] axiom s1048 (x : Prop) : f (g1049 x) = f (g1048 x) @[simp] axiom s1049 (x : Prop) : f (g1050 x) = f (g1049 x) @[simp] axiom s1050 (x : Prop) : f (g1051 x) = f (g1050 x) @[simp] axiom s1051 (x : Prop) : f (g1052 x) = f (g1051 x) @[simp] axiom s1052 (x : Prop) : f (g1053 x) = f (g1052 x) @[simp] axiom s1053 (x : Prop) : f (g1054 x) = f (g1053 x) @[simp] axiom s1054 (x : Prop) : f (g1055 x) = f (g1054 x) @[simp] axiom s1055 (x : Prop) : f (g1056 x) = f (g1055 x) @[simp] axiom s1056 (x : Prop) : f (g1057 x) = f (g1056 x) @[simp] axiom s1057 (x : Prop) : f (g1058 x) = f (g1057 x) @[simp] axiom s1058 (x : Prop) : f (g1059 x) = f (g1058 x) @[simp] axiom s1059 (x : Prop) : f (g1060 x) = f (g1059 x) @[simp] axiom s1060 (x : Prop) : f (g1061 x) = f (g1060 x) @[simp] axiom s1061 (x : Prop) : f (g1062 x) = f (g1061 x) @[simp] axiom s1062 (x : Prop) : f (g1063 x) = f (g1062 x) @[simp] axiom s1063 (x : Prop) : f (g1064 x) = f (g1063 x) @[simp] axiom s1064 (x : Prop) : f (g1065 x) = f (g1064 x) @[simp] axiom s1065 (x : Prop) : f (g1066 x) = f (g1065 x) @[simp] axiom s1066 (x : Prop) : f (g1067 x) = f (g1066 x) @[simp] axiom s1067 (x : Prop) : f (g1068 x) = f (g1067 x) @[simp] axiom s1068 (x : Prop) : f (g1069 x) = f (g1068 x) @[simp] axiom s1069 (x : Prop) : f (g1070 x) = f (g1069 x) @[simp] axiom s1070 (x : Prop) : f (g1071 x) = f (g1070 x) @[simp] axiom s1071 (x : Prop) : f (g1072 x) = f (g1071 x) @[simp] axiom s1072 (x : Prop) : f (g1073 x) = f (g1072 x) @[simp] axiom s1073 (x : Prop) : f (g1074 x) = f (g1073 x) @[simp] axiom s1074 (x : Prop) : f (g1075 x) = f (g1074 x) @[simp] axiom s1075 (x : Prop) : f (g1076 x) = f (g1075 x) @[simp] axiom s1076 (x : Prop) : f (g1077 x) = f (g1076 x) @[simp] axiom s1077 (x : Prop) : f (g1078 x) = f (g1077 x) @[simp] axiom s1078 (x : Prop) : f (g1079 x) = f (g1078 x) @[simp] axiom s1079 (x : Prop) : f (g1080 x) = f (g1079 x) @[simp] axiom s1080 (x : Prop) : f (g1081 x) = f (g1080 x) @[simp] axiom s1081 (x : Prop) : f (g1082 x) = f (g1081 x) @[simp] axiom s1082 (x : Prop) : f (g1083 x) = f (g1082 x) @[simp] axiom s1083 (x : Prop) : f (g1084 x) = f (g1083 x) @[simp] axiom s1084 (x : Prop) : f (g1085 x) = f (g1084 x) @[simp] axiom s1085 (x : Prop) : f (g1086 x) = f (g1085 x) @[simp] axiom s1086 (x : Prop) : f (g1087 x) = f (g1086 x) @[simp] axiom s1087 (x : Prop) : f (g1088 x) = f (g1087 x) @[simp] axiom s1088 (x : Prop) : f (g1089 x) = f (g1088 x) @[simp] axiom s1089 (x : Prop) : f (g1090 x) = f (g1089 x) @[simp] axiom s1090 (x : Prop) : f (g1091 x) = f (g1090 x) @[simp] axiom s1091 (x : Prop) : f (g1092 x) = f (g1091 x) @[simp] axiom s1092 (x : Prop) : f (g1093 x) = f (g1092 x) @[simp] axiom s1093 (x : Prop) : f (g1094 x) = f (g1093 x) @[simp] axiom s1094 (x : Prop) : f (g1095 x) = f (g1094 x) @[simp] axiom s1095 (x : Prop) : f (g1096 x) = f (g1095 x) @[simp] axiom s1096 (x : Prop) : f (g1097 x) = f (g1096 x) @[simp] axiom s1097 (x : Prop) : f (g1098 x) = f (g1097 x) @[simp] axiom s1098 (x : Prop) : f (g1099 x) = f (g1098 x) @[simp] axiom s1099 (x : Prop) : f (g1100 x) = f (g1099 x) @[simp] axiom s1100 (x : Prop) : f (g1101 x) = f (g1100 x) @[simp] axiom s1101 (x : Prop) : f (g1102 x) = f (g1101 x) @[simp] axiom s1102 (x : Prop) : f (g1103 x) = f (g1102 x) @[simp] axiom s1103 (x : Prop) : f (g1104 x) = f (g1103 x) @[simp] axiom s1104 (x : Prop) : f (g1105 x) = f (g1104 x) @[simp] axiom s1105 (x : Prop) : f (g1106 x) = f (g1105 x) @[simp] axiom s1106 (x : Prop) : f (g1107 x) = f (g1106 x) @[simp] axiom s1107 (x : Prop) : f (g1108 x) = f (g1107 x) @[simp] axiom s1108 (x : Prop) : f (g1109 x) = f (g1108 x) @[simp] axiom s1109 (x : Prop) : f (g1110 x) = f (g1109 x) @[simp] axiom s1110 (x : Prop) : f (g1111 x) = f (g1110 x) @[simp] axiom s1111 (x : Prop) : f (g1112 x) = f (g1111 x) @[simp] axiom s1112 (x : Prop) : f (g1113 x) = f (g1112 x) @[simp] axiom s1113 (x : Prop) : f (g1114 x) = f (g1113 x) @[simp] axiom s1114 (x : Prop) : f (g1115 x) = f (g1114 x) @[simp] axiom s1115 (x : Prop) : f (g1116 x) = f (g1115 x) @[simp] axiom s1116 (x : Prop) : f (g1117 x) = f (g1116 x) @[simp] axiom s1117 (x : Prop) : f (g1118 x) = f (g1117 x) @[simp] axiom s1118 (x : Prop) : f (g1119 x) = f (g1118 x) @[simp] axiom s1119 (x : Prop) : f (g1120 x) = f (g1119 x) @[simp] axiom s1120 (x : Prop) : f (g1121 x) = f (g1120 x) @[simp] axiom s1121 (x : Prop) : f (g1122 x) = f (g1121 x) @[simp] axiom s1122 (x : Prop) : f (g1123 x) = f (g1122 x) @[simp] axiom s1123 (x : Prop) : f (g1124 x) = f (g1123 x) @[simp] axiom s1124 (x : Prop) : f (g1125 x) = f (g1124 x) @[simp] axiom s1125 (x : Prop) : f (g1126 x) = f (g1125 x) @[simp] axiom s1126 (x : Prop) : f (g1127 x) = f (g1126 x) @[simp] axiom s1127 (x : Prop) : f (g1128 x) = f (g1127 x) @[simp] axiom s1128 (x : Prop) : f (g1129 x) = f (g1128 x) @[simp] axiom s1129 (x : Prop) : f (g1130 x) = f (g1129 x) @[simp] axiom s1130 (x : Prop) : f (g1131 x) = f (g1130 x) @[simp] axiom s1131 (x : Prop) : f (g1132 x) = f (g1131 x) @[simp] axiom s1132 (x : Prop) : f (g1133 x) = f (g1132 x) @[simp] axiom s1133 (x : Prop) : f (g1134 x) = f (g1133 x) @[simp] axiom s1134 (x : Prop) : f (g1135 x) = f (g1134 x) @[simp] axiom s1135 (x : Prop) : f (g1136 x) = f (g1135 x) @[simp] axiom s1136 (x : Prop) : f (g1137 x) = f (g1136 x) @[simp] axiom s1137 (x : Prop) : f (g1138 x) = f (g1137 x) @[simp] axiom s1138 (x : Prop) : f (g1139 x) = f (g1138 x) @[simp] axiom s1139 (x : Prop) : f (g1140 x) = f (g1139 x) @[simp] axiom s1140 (x : Prop) : f (g1141 x) = f (g1140 x) @[simp] axiom s1141 (x : Prop) : f (g1142 x) = f (g1141 x) @[simp] axiom s1142 (x : Prop) : f (g1143 x) = f (g1142 x) @[simp] axiom s1143 (x : Prop) : f (g1144 x) = f (g1143 x) @[simp] axiom s1144 (x : Prop) : f (g1145 x) = f (g1144 x) @[simp] axiom s1145 (x : Prop) : f (g1146 x) = f (g1145 x) @[simp] axiom s1146 (x : Prop) : f (g1147 x) = f (g1146 x) @[simp] axiom s1147 (x : Prop) : f (g1148 x) = f (g1147 x) @[simp] axiom s1148 (x : Prop) : f (g1149 x) = f (g1148 x) @[simp] axiom s1149 (x : Prop) : f (g1150 x) = f (g1149 x) @[simp] axiom s1150 (x : Prop) : f (g1151 x) = f (g1150 x) @[simp] axiom s1151 (x : Prop) : f (g1152 x) = f (g1151 x) @[simp] axiom s1152 (x : Prop) : f (g1153 x) = f (g1152 x) @[simp] axiom s1153 (x : Prop) : f (g1154 x) = f (g1153 x) @[simp] axiom s1154 (x : Prop) : f (g1155 x) = f (g1154 x) @[simp] axiom s1155 (x : Prop) : f (g1156 x) = f (g1155 x) @[simp] axiom s1156 (x : Prop) : f (g1157 x) = f (g1156 x) @[simp] axiom s1157 (x : Prop) : f (g1158 x) = f (g1157 x) @[simp] axiom s1158 (x : Prop) : f (g1159 x) = f (g1158 x) @[simp] axiom s1159 (x : Prop) : f (g1160 x) = f (g1159 x) @[simp] axiom s1160 (x : Prop) : f (g1161 x) = f (g1160 x) @[simp] axiom s1161 (x : Prop) : f (g1162 x) = f (g1161 x) @[simp] axiom s1162 (x : Prop) : f (g1163 x) = f (g1162 x) @[simp] axiom s1163 (x : Prop) : f (g1164 x) = f (g1163 x) @[simp] axiom s1164 (x : Prop) : f (g1165 x) = f (g1164 x) @[simp] axiom s1165 (x : Prop) : f (g1166 x) = f (g1165 x) @[simp] axiom s1166 (x : Prop) : f (g1167 x) = f (g1166 x) @[simp] axiom s1167 (x : Prop) : f (g1168 x) = f (g1167 x) @[simp] axiom s1168 (x : Prop) : f (g1169 x) = f (g1168 x) @[simp] axiom s1169 (x : Prop) : f (g1170 x) = f (g1169 x) @[simp] axiom s1170 (x : Prop) : f (g1171 x) = f (g1170 x) @[simp] axiom s1171 (x : Prop) : f (g1172 x) = f (g1171 x) @[simp] axiom s1172 (x : Prop) : f (g1173 x) = f (g1172 x) @[simp] axiom s1173 (x : Prop) : f (g1174 x) = f (g1173 x) @[simp] axiom s1174 (x : Prop) : f (g1175 x) = f (g1174 x) @[simp] axiom s1175 (x : Prop) : f (g1176 x) = f (g1175 x) @[simp] axiom s1176 (x : Prop) : f (g1177 x) = f (g1176 x) @[simp] axiom s1177 (x : Prop) : f (g1178 x) = f (g1177 x) @[simp] axiom s1178 (x : Prop) : f (g1179 x) = f (g1178 x) @[simp] axiom s1179 (x : Prop) : f (g1180 x) = f (g1179 x) @[simp] axiom s1180 (x : Prop) : f (g1181 x) = f (g1180 x) @[simp] axiom s1181 (x : Prop) : f (g1182 x) = f (g1181 x) @[simp] axiom s1182 (x : Prop) : f (g1183 x) = f (g1182 x) @[simp] axiom s1183 (x : Prop) : f (g1184 x) = f (g1183 x) @[simp] axiom s1184 (x : Prop) : f (g1185 x) = f (g1184 x) @[simp] axiom s1185 (x : Prop) : f (g1186 x) = f (g1185 x) @[simp] axiom s1186 (x : Prop) : f (g1187 x) = f (g1186 x) @[simp] axiom s1187 (x : Prop) : f (g1188 x) = f (g1187 x) @[simp] axiom s1188 (x : Prop) : f (g1189 x) = f (g1188 x) @[simp] axiom s1189 (x : Prop) : f (g1190 x) = f (g1189 x) @[simp] axiom s1190 (x : Prop) : f (g1191 x) = f (g1190 x) @[simp] axiom s1191 (x : Prop) : f (g1192 x) = f (g1191 x) @[simp] axiom s1192 (x : Prop) : f (g1193 x) = f (g1192 x) @[simp] axiom s1193 (x : Prop) : f (g1194 x) = f (g1193 x) @[simp] axiom s1194 (x : Prop) : f (g1195 x) = f (g1194 x) @[simp] axiom s1195 (x : Prop) : f (g1196 x) = f (g1195 x) @[simp] axiom s1196 (x : Prop) : f (g1197 x) = f (g1196 x) @[simp] axiom s1197 (x : Prop) : f (g1198 x) = f (g1197 x) @[simp] axiom s1198 (x : Prop) : f (g1199 x) = f (g1198 x) @[simp] axiom s1199 (x : Prop) : f (g1200 x) = f (g1199 x) @[simp] axiom s1200 (x : Prop) : f (g1201 x) = f (g1200 x) @[simp] axiom s1201 (x : Prop) : f (g1202 x) = f (g1201 x) @[simp] axiom s1202 (x : Prop) : f (g1203 x) = f (g1202 x) @[simp] axiom s1203 (x : Prop) : f (g1204 x) = f (g1203 x) @[simp] axiom s1204 (x : Prop) : f (g1205 x) = f (g1204 x) @[simp] axiom s1205 (x : Prop) : f (g1206 x) = f (g1205 x) @[simp] axiom s1206 (x : Prop) : f (g1207 x) = f (g1206 x) @[simp] axiom s1207 (x : Prop) : f (g1208 x) = f (g1207 x) @[simp] axiom s1208 (x : Prop) : f (g1209 x) = f (g1208 x) @[simp] axiom s1209 (x : Prop) : f (g1210 x) = f (g1209 x) @[simp] axiom s1210 (x : Prop) : f (g1211 x) = f (g1210 x) @[simp] axiom s1211 (x : Prop) : f (g1212 x) = f (g1211 x) @[simp] axiom s1212 (x : Prop) : f (g1213 x) = f (g1212 x) @[simp] axiom s1213 (x : Prop) : f (g1214 x) = f (g1213 x) @[simp] axiom s1214 (x : Prop) : f (g1215 x) = f (g1214 x) @[simp] axiom s1215 (x : Prop) : f (g1216 x) = f (g1215 x) @[simp] axiom s1216 (x : Prop) : f (g1217 x) = f (g1216 x) @[simp] axiom s1217 (x : Prop) : f (g1218 x) = f (g1217 x) @[simp] axiom s1218 (x : Prop) : f (g1219 x) = f (g1218 x) @[simp] axiom s1219 (x : Prop) : f (g1220 x) = f (g1219 x) @[simp] axiom s1220 (x : Prop) : f (g1221 x) = f (g1220 x) @[simp] axiom s1221 (x : Prop) : f (g1222 x) = f (g1221 x) @[simp] axiom s1222 (x : Prop) : f (g1223 x) = f (g1222 x) @[simp] axiom s1223 (x : Prop) : f (g1224 x) = f (g1223 x) @[simp] axiom s1224 (x : Prop) : f (g1225 x) = f (g1224 x) @[simp] axiom s1225 (x : Prop) : f (g1226 x) = f (g1225 x) @[simp] axiom s1226 (x : Prop) : f (g1227 x) = f (g1226 x) @[simp] axiom s1227 (x : Prop) : f (g1228 x) = f (g1227 x) @[simp] axiom s1228 (x : Prop) : f (g1229 x) = f (g1228 x) @[simp] axiom s1229 (x : Prop) : f (g1230 x) = f (g1229 x) @[simp] axiom s1230 (x : Prop) : f (g1231 x) = f (g1230 x) @[simp] axiom s1231 (x : Prop) : f (g1232 x) = f (g1231 x) @[simp] axiom s1232 (x : Prop) : f (g1233 x) = f (g1232 x) @[simp] axiom s1233 (x : Prop) : f (g1234 x) = f (g1233 x) @[simp] axiom s1234 (x : Prop) : f (g1235 x) = f (g1234 x) @[simp] axiom s1235 (x : Prop) : f (g1236 x) = f (g1235 x) @[simp] axiom s1236 (x : Prop) : f (g1237 x) = f (g1236 x) @[simp] axiom s1237 (x : Prop) : f (g1238 x) = f (g1237 x) @[simp] axiom s1238 (x : Prop) : f (g1239 x) = f (g1238 x) @[simp] axiom s1239 (x : Prop) : f (g1240 x) = f (g1239 x) @[simp] axiom s1240 (x : Prop) : f (g1241 x) = f (g1240 x) @[simp] axiom s1241 (x : Prop) : f (g1242 x) = f (g1241 x) @[simp] axiom s1242 (x : Prop) : f (g1243 x) = f (g1242 x) @[simp] axiom s1243 (x : Prop) : f (g1244 x) = f (g1243 x) @[simp] axiom s1244 (x : Prop) : f (g1245 x) = f (g1244 x) @[simp] axiom s1245 (x : Prop) : f (g1246 x) = f (g1245 x) @[simp] axiom s1246 (x : Prop) : f (g1247 x) = f (g1246 x) @[simp] axiom s1247 (x : Prop) : f (g1248 x) = f (g1247 x) @[simp] axiom s1248 (x : Prop) : f (g1249 x) = f (g1248 x) @[simp] axiom s1249 (x : Prop) : f (g1250 x) = f (g1249 x) @[simp] axiom s1250 (x : Prop) : f (g1251 x) = f (g1250 x) @[simp] axiom s1251 (x : Prop) : f (g1252 x) = f (g1251 x) @[simp] axiom s1252 (x : Prop) : f (g1253 x) = f (g1252 x) @[simp] axiom s1253 (x : Prop) : f (g1254 x) = f (g1253 x) @[simp] axiom s1254 (x : Prop) : f (g1255 x) = f (g1254 x) @[simp] axiom s1255 (x : Prop) : f (g1256 x) = f (g1255 x) @[simp] axiom s1256 (x : Prop) : f (g1257 x) = f (g1256 x) @[simp] axiom s1257 (x : Prop) : f (g1258 x) = f (g1257 x) @[simp] axiom s1258 (x : Prop) : f (g1259 x) = f (g1258 x) @[simp] axiom s1259 (x : Prop) : f (g1260 x) = f (g1259 x) @[simp] axiom s1260 (x : Prop) : f (g1261 x) = f (g1260 x) @[simp] axiom s1261 (x : Prop) : f (g1262 x) = f (g1261 x) @[simp] axiom s1262 (x : Prop) : f (g1263 x) = f (g1262 x) @[simp] axiom s1263 (x : Prop) : f (g1264 x) = f (g1263 x) @[simp] axiom s1264 (x : Prop) : f (g1265 x) = f (g1264 x) @[simp] axiom s1265 (x : Prop) : f (g1266 x) = f (g1265 x) @[simp] axiom s1266 (x : Prop) : f (g1267 x) = f (g1266 x) @[simp] axiom s1267 (x : Prop) : f (g1268 x) = f (g1267 x) @[simp] axiom s1268 (x : Prop) : f (g1269 x) = f (g1268 x) @[simp] axiom s1269 (x : Prop) : f (g1270 x) = f (g1269 x) @[simp] axiom s1270 (x : Prop) : f (g1271 x) = f (g1270 x) @[simp] axiom s1271 (x : Prop) : f (g1272 x) = f (g1271 x) @[simp] axiom s1272 (x : Prop) : f (g1273 x) = f (g1272 x) @[simp] axiom s1273 (x : Prop) : f (g1274 x) = f (g1273 x) @[simp] axiom s1274 (x : Prop) : f (g1275 x) = f (g1274 x) @[simp] axiom s1275 (x : Prop) : f (g1276 x) = f (g1275 x) @[simp] axiom s1276 (x : Prop) : f (g1277 x) = f (g1276 x) @[simp] axiom s1277 (x : Prop) : f (g1278 x) = f (g1277 x) @[simp] axiom s1278 (x : Prop) : f (g1279 x) = f (g1278 x) @[simp] axiom s1279 (x : Prop) : f (g1280 x) = f (g1279 x) @[simp] axiom s1280 (x : Prop) : f (g1281 x) = f (g1280 x) @[simp] axiom s1281 (x : Prop) : f (g1282 x) = f (g1281 x) @[simp] axiom s1282 (x : Prop) : f (g1283 x) = f (g1282 x) @[simp] axiom s1283 (x : Prop) : f (g1284 x) = f (g1283 x) @[simp] axiom s1284 (x : Prop) : f (g1285 x) = f (g1284 x) @[simp] axiom s1285 (x : Prop) : f (g1286 x) = f (g1285 x) @[simp] axiom s1286 (x : Prop) : f (g1287 x) = f (g1286 x) @[simp] axiom s1287 (x : Prop) : f (g1288 x) = f (g1287 x) @[simp] axiom s1288 (x : Prop) : f (g1289 x) = f (g1288 x) @[simp] axiom s1289 (x : Prop) : f (g1290 x) = f (g1289 x) @[simp] axiom s1290 (x : Prop) : f (g1291 x) = f (g1290 x) @[simp] axiom s1291 (x : Prop) : f (g1292 x) = f (g1291 x) @[simp] axiom s1292 (x : Prop) : f (g1293 x) = f (g1292 x) @[simp] axiom s1293 (x : Prop) : f (g1294 x) = f (g1293 x) @[simp] axiom s1294 (x : Prop) : f (g1295 x) = f (g1294 x) @[simp] axiom s1295 (x : Prop) : f (g1296 x) = f (g1295 x) @[simp] axiom s1296 (x : Prop) : f (g1297 x) = f (g1296 x) @[simp] axiom s1297 (x : Prop) : f (g1298 x) = f (g1297 x) @[simp] axiom s1298 (x : Prop) : f (g1299 x) = f (g1298 x) @[simp] axiom s1299 (x : Prop) : f (g1300 x) = f (g1299 x) @[simp] axiom s1300 (x : Prop) : f (g1301 x) = f (g1300 x) @[simp] axiom s1301 (x : Prop) : f (g1302 x) = f (g1301 x) @[simp] axiom s1302 (x : Prop) : f (g1303 x) = f (g1302 x) @[simp] axiom s1303 (x : Prop) : f (g1304 x) = f (g1303 x) @[simp] axiom s1304 (x : Prop) : f (g1305 x) = f (g1304 x) @[simp] axiom s1305 (x : Prop) : f (g1306 x) = f (g1305 x) @[simp] axiom s1306 (x : Prop) : f (g1307 x) = f (g1306 x) @[simp] axiom s1307 (x : Prop) : f (g1308 x) = f (g1307 x) @[simp] axiom s1308 (x : Prop) : f (g1309 x) = f (g1308 x) @[simp] axiom s1309 (x : Prop) : f (g1310 x) = f (g1309 x) @[simp] axiom s1310 (x : Prop) : f (g1311 x) = f (g1310 x) @[simp] axiom s1311 (x : Prop) : f (g1312 x) = f (g1311 x) @[simp] axiom s1312 (x : Prop) : f (g1313 x) = f (g1312 x) @[simp] axiom s1313 (x : Prop) : f (g1314 x) = f (g1313 x) @[simp] axiom s1314 (x : Prop) : f (g1315 x) = f (g1314 x) @[simp] axiom s1315 (x : Prop) : f (g1316 x) = f (g1315 x) @[simp] axiom s1316 (x : Prop) : f (g1317 x) = f (g1316 x) @[simp] axiom s1317 (x : Prop) : f (g1318 x) = f (g1317 x) @[simp] axiom s1318 (x : Prop) : f (g1319 x) = f (g1318 x) @[simp] axiom s1319 (x : Prop) : f (g1320 x) = f (g1319 x) @[simp] axiom s1320 (x : Prop) : f (g1321 x) = f (g1320 x) @[simp] axiom s1321 (x : Prop) : f (g1322 x) = f (g1321 x) @[simp] axiom s1322 (x : Prop) : f (g1323 x) = f (g1322 x) @[simp] axiom s1323 (x : Prop) : f (g1324 x) = f (g1323 x) @[simp] axiom s1324 (x : Prop) : f (g1325 x) = f (g1324 x) @[simp] axiom s1325 (x : Prop) : f (g1326 x) = f (g1325 x) @[simp] axiom s1326 (x : Prop) : f (g1327 x) = f (g1326 x) @[simp] axiom s1327 (x : Prop) : f (g1328 x) = f (g1327 x) @[simp] axiom s1328 (x : Prop) : f (g1329 x) = f (g1328 x) @[simp] axiom s1329 (x : Prop) : f (g1330 x) = f (g1329 x) @[simp] axiom s1330 (x : Prop) : f (g1331 x) = f (g1330 x) @[simp] axiom s1331 (x : Prop) : f (g1332 x) = f (g1331 x) @[simp] axiom s1332 (x : Prop) : f (g1333 x) = f (g1332 x) @[simp] axiom s1333 (x : Prop) : f (g1334 x) = f (g1333 x) @[simp] axiom s1334 (x : Prop) : f (g1335 x) = f (g1334 x) @[simp] axiom s1335 (x : Prop) : f (g1336 x) = f (g1335 x) @[simp] axiom s1336 (x : Prop) : f (g1337 x) = f (g1336 x) @[simp] axiom s1337 (x : Prop) : f (g1338 x) = f (g1337 x) @[simp] axiom s1338 (x : Prop) : f (g1339 x) = f (g1338 x) @[simp] axiom s1339 (x : Prop) : f (g1340 x) = f (g1339 x) @[simp] axiom s1340 (x : Prop) : f (g1341 x) = f (g1340 x) @[simp] axiom s1341 (x : Prop) : f (g1342 x) = f (g1341 x) @[simp] axiom s1342 (x : Prop) : f (g1343 x) = f (g1342 x) @[simp] axiom s1343 (x : Prop) : f (g1344 x) = f (g1343 x) @[simp] axiom s1344 (x : Prop) : f (g1345 x) = f (g1344 x) @[simp] axiom s1345 (x : Prop) : f (g1346 x) = f (g1345 x) @[simp] axiom s1346 (x : Prop) : f (g1347 x) = f (g1346 x) @[simp] axiom s1347 (x : Prop) : f (g1348 x) = f (g1347 x) @[simp] axiom s1348 (x : Prop) : f (g1349 x) = f (g1348 x) @[simp] axiom s1349 (x : Prop) : f (g1350 x) = f (g1349 x) @[simp] axiom s1350 (x : Prop) : f (g1351 x) = f (g1350 x) @[simp] axiom s1351 (x : Prop) : f (g1352 x) = f (g1351 x) @[simp] axiom s1352 (x : Prop) : f (g1353 x) = f (g1352 x) @[simp] axiom s1353 (x : Prop) : f (g1354 x) = f (g1353 x) @[simp] axiom s1354 (x : Prop) : f (g1355 x) = f (g1354 x) @[simp] axiom s1355 (x : Prop) : f (g1356 x) = f (g1355 x) @[simp] axiom s1356 (x : Prop) : f (g1357 x) = f (g1356 x) @[simp] axiom s1357 (x : Prop) : f (g1358 x) = f (g1357 x) @[simp] axiom s1358 (x : Prop) : f (g1359 x) = f (g1358 x) @[simp] axiom s1359 (x : Prop) : f (g1360 x) = f (g1359 x) @[simp] axiom s1360 (x : Prop) : f (g1361 x) = f (g1360 x) @[simp] axiom s1361 (x : Prop) : f (g1362 x) = f (g1361 x) @[simp] axiom s1362 (x : Prop) : f (g1363 x) = f (g1362 x) @[simp] axiom s1363 (x : Prop) : f (g1364 x) = f (g1363 x) @[simp] axiom s1364 (x : Prop) : f (g1365 x) = f (g1364 x) @[simp] axiom s1365 (x : Prop) : f (g1366 x) = f (g1365 x) @[simp] axiom s1366 (x : Prop) : f (g1367 x) = f (g1366 x) @[simp] axiom s1367 (x : Prop) : f (g1368 x) = f (g1367 x) @[simp] axiom s1368 (x : Prop) : f (g1369 x) = f (g1368 x) @[simp] axiom s1369 (x : Prop) : f (g1370 x) = f (g1369 x) @[simp] axiom s1370 (x : Prop) : f (g1371 x) = f (g1370 x) @[simp] axiom s1371 (x : Prop) : f (g1372 x) = f (g1371 x) @[simp] axiom s1372 (x : Prop) : f (g1373 x) = f (g1372 x) @[simp] axiom s1373 (x : Prop) : f (g1374 x) = f (g1373 x) @[simp] axiom s1374 (x : Prop) : f (g1375 x) = f (g1374 x) @[simp] axiom s1375 (x : Prop) : f (g1376 x) = f (g1375 x) @[simp] axiom s1376 (x : Prop) : f (g1377 x) = f (g1376 x) @[simp] axiom s1377 (x : Prop) : f (g1378 x) = f (g1377 x) @[simp] axiom s1378 (x : Prop) : f (g1379 x) = f (g1378 x) @[simp] axiom s1379 (x : Prop) : f (g1380 x) = f (g1379 x) @[simp] axiom s1380 (x : Prop) : f (g1381 x) = f (g1380 x) @[simp] axiom s1381 (x : Prop) : f (g1382 x) = f (g1381 x) @[simp] axiom s1382 (x : Prop) : f (g1383 x) = f (g1382 x) @[simp] axiom s1383 (x : Prop) : f (g1384 x) = f (g1383 x) @[simp] axiom s1384 (x : Prop) : f (g1385 x) = f (g1384 x) @[simp] axiom s1385 (x : Prop) : f (g1386 x) = f (g1385 x) @[simp] axiom s1386 (x : Prop) : f (g1387 x) = f (g1386 x) @[simp] axiom s1387 (x : Prop) : f (g1388 x) = f (g1387 x) @[simp] axiom s1388 (x : Prop) : f (g1389 x) = f (g1388 x) @[simp] axiom s1389 (x : Prop) : f (g1390 x) = f (g1389 x) @[simp] axiom s1390 (x : Prop) : f (g1391 x) = f (g1390 x) @[simp] axiom s1391 (x : Prop) : f (g1392 x) = f (g1391 x) @[simp] axiom s1392 (x : Prop) : f (g1393 x) = f (g1392 x) @[simp] axiom s1393 (x : Prop) : f (g1394 x) = f (g1393 x) @[simp] axiom s1394 (x : Prop) : f (g1395 x) = f (g1394 x) @[simp] axiom s1395 (x : Prop) : f (g1396 x) = f (g1395 x) @[simp] axiom s1396 (x : Prop) : f (g1397 x) = f (g1396 x) @[simp] axiom s1397 (x : Prop) : f (g1398 x) = f (g1397 x) @[simp] axiom s1398 (x : Prop) : f (g1399 x) = f (g1398 x) @[simp] axiom s1399 (x : Prop) : f (g1400 x) = f (g1399 x) @[simp] axiom s1400 (x : Prop) : f (g1401 x) = f (g1400 x) @[simp] axiom s1401 (x : Prop) : f (g1402 x) = f (g1401 x) @[simp] axiom s1402 (x : Prop) : f (g1403 x) = f (g1402 x) @[simp] axiom s1403 (x : Prop) : f (g1404 x) = f (g1403 x) @[simp] axiom s1404 (x : Prop) : f (g1405 x) = f (g1404 x) @[simp] axiom s1405 (x : Prop) : f (g1406 x) = f (g1405 x) @[simp] axiom s1406 (x : Prop) : f (g1407 x) = f (g1406 x) @[simp] axiom s1407 (x : Prop) : f (g1408 x) = f (g1407 x) @[simp] axiom s1408 (x : Prop) : f (g1409 x) = f (g1408 x) @[simp] axiom s1409 (x : Prop) : f (g1410 x) = f (g1409 x) @[simp] axiom s1410 (x : Prop) : f (g1411 x) = f (g1410 x) @[simp] axiom s1411 (x : Prop) : f (g1412 x) = f (g1411 x) @[simp] axiom s1412 (x : Prop) : f (g1413 x) = f (g1412 x) @[simp] axiom s1413 (x : Prop) : f (g1414 x) = f (g1413 x) @[simp] axiom s1414 (x : Prop) : f (g1415 x) = f (g1414 x) @[simp] axiom s1415 (x : Prop) : f (g1416 x) = f (g1415 x) @[simp] axiom s1416 (x : Prop) : f (g1417 x) = f (g1416 x) @[simp] axiom s1417 (x : Prop) : f (g1418 x) = f (g1417 x) @[simp] axiom s1418 (x : Prop) : f (g1419 x) = f (g1418 x) @[simp] axiom s1419 (x : Prop) : f (g1420 x) = f (g1419 x) @[simp] axiom s1420 (x : Prop) : f (g1421 x) = f (g1420 x) @[simp] axiom s1421 (x : Prop) : f (g1422 x) = f (g1421 x) @[simp] axiom s1422 (x : Prop) : f (g1423 x) = f (g1422 x) @[simp] axiom s1423 (x : Prop) : f (g1424 x) = f (g1423 x) @[simp] axiom s1424 (x : Prop) : f (g1425 x) = f (g1424 x) @[simp] axiom s1425 (x : Prop) : f (g1426 x) = f (g1425 x) @[simp] axiom s1426 (x : Prop) : f (g1427 x) = f (g1426 x) @[simp] axiom s1427 (x : Prop) : f (g1428 x) = f (g1427 x) @[simp] axiom s1428 (x : Prop) : f (g1429 x) = f (g1428 x) @[simp] axiom s1429 (x : Prop) : f (g1430 x) = f (g1429 x) @[simp] axiom s1430 (x : Prop) : f (g1431 x) = f (g1430 x) @[simp] axiom s1431 (x : Prop) : f (g1432 x) = f (g1431 x) @[simp] axiom s1432 (x : Prop) : f (g1433 x) = f (g1432 x) @[simp] axiom s1433 (x : Prop) : f (g1434 x) = f (g1433 x) @[simp] axiom s1434 (x : Prop) : f (g1435 x) = f (g1434 x) @[simp] axiom s1435 (x : Prop) : f (g1436 x) = f (g1435 x) @[simp] axiom s1436 (x : Prop) : f (g1437 x) = f (g1436 x) @[simp] axiom s1437 (x : Prop) : f (g1438 x) = f (g1437 x) @[simp] axiom s1438 (x : Prop) : f (g1439 x) = f (g1438 x) @[simp] axiom s1439 (x : Prop) : f (g1440 x) = f (g1439 x) @[simp] axiom s1440 (x : Prop) : f (g1441 x) = f (g1440 x) @[simp] axiom s1441 (x : Prop) : f (g1442 x) = f (g1441 x) @[simp] axiom s1442 (x : Prop) : f (g1443 x) = f (g1442 x) @[simp] axiom s1443 (x : Prop) : f (g1444 x) = f (g1443 x) @[simp] axiom s1444 (x : Prop) : f (g1445 x) = f (g1444 x) @[simp] axiom s1445 (x : Prop) : f (g1446 x) = f (g1445 x) @[simp] axiom s1446 (x : Prop) : f (g1447 x) = f (g1446 x) @[simp] axiom s1447 (x : Prop) : f (g1448 x) = f (g1447 x) @[simp] axiom s1448 (x : Prop) : f (g1449 x) = f (g1448 x) @[simp] axiom s1449 (x : Prop) : f (g1450 x) = f (g1449 x) @[simp] axiom s1450 (x : Prop) : f (g1451 x) = f (g1450 x) @[simp] axiom s1451 (x : Prop) : f (g1452 x) = f (g1451 x) @[simp] axiom s1452 (x : Prop) : f (g1453 x) = f (g1452 x) @[simp] axiom s1453 (x : Prop) : f (g1454 x) = f (g1453 x) @[simp] axiom s1454 (x : Prop) : f (g1455 x) = f (g1454 x) @[simp] axiom s1455 (x : Prop) : f (g1456 x) = f (g1455 x) @[simp] axiom s1456 (x : Prop) : f (g1457 x) = f (g1456 x) @[simp] axiom s1457 (x : Prop) : f (g1458 x) = f (g1457 x) @[simp] axiom s1458 (x : Prop) : f (g1459 x) = f (g1458 x) @[simp] axiom s1459 (x : Prop) : f (g1460 x) = f (g1459 x) @[simp] axiom s1460 (x : Prop) : f (g1461 x) = f (g1460 x) @[simp] axiom s1461 (x : Prop) : f (g1462 x) = f (g1461 x) @[simp] axiom s1462 (x : Prop) : f (g1463 x) = f (g1462 x) @[simp] axiom s1463 (x : Prop) : f (g1464 x) = f (g1463 x) @[simp] axiom s1464 (x : Prop) : f (g1465 x) = f (g1464 x) @[simp] axiom s1465 (x : Prop) : f (g1466 x) = f (g1465 x) @[simp] axiom s1466 (x : Prop) : f (g1467 x) = f (g1466 x) @[simp] axiom s1467 (x : Prop) : f (g1468 x) = f (g1467 x) @[simp] axiom s1468 (x : Prop) : f (g1469 x) = f (g1468 x) @[simp] axiom s1469 (x : Prop) : f (g1470 x) = f (g1469 x) @[simp] axiom s1470 (x : Prop) : f (g1471 x) = f (g1470 x) @[simp] axiom s1471 (x : Prop) : f (g1472 x) = f (g1471 x) @[simp] axiom s1472 (x : Prop) : f (g1473 x) = f (g1472 x) @[simp] axiom s1473 (x : Prop) : f (g1474 x) = f (g1473 x) @[simp] axiom s1474 (x : Prop) : f (g1475 x) = f (g1474 x) @[simp] axiom s1475 (x : Prop) : f (g1476 x) = f (g1475 x) @[simp] axiom s1476 (x : Prop) : f (g1477 x) = f (g1476 x) @[simp] axiom s1477 (x : Prop) : f (g1478 x) = f (g1477 x) @[simp] axiom s1478 (x : Prop) : f (g1479 x) = f (g1478 x) @[simp] axiom s1479 (x : Prop) : f (g1480 x) = f (g1479 x) @[simp] axiom s1480 (x : Prop) : f (g1481 x) = f (g1480 x) @[simp] axiom s1481 (x : Prop) : f (g1482 x) = f (g1481 x) @[simp] axiom s1482 (x : Prop) : f (g1483 x) = f (g1482 x) @[simp] axiom s1483 (x : Prop) : f (g1484 x) = f (g1483 x) @[simp] axiom s1484 (x : Prop) : f (g1485 x) = f (g1484 x) @[simp] axiom s1485 (x : Prop) : f (g1486 x) = f (g1485 x) @[simp] axiom s1486 (x : Prop) : f (g1487 x) = f (g1486 x) @[simp] axiom s1487 (x : Prop) : f (g1488 x) = f (g1487 x) @[simp] axiom s1488 (x : Prop) : f (g1489 x) = f (g1488 x) @[simp] axiom s1489 (x : Prop) : f (g1490 x) = f (g1489 x) @[simp] axiom s1490 (x : Prop) : f (g1491 x) = f (g1490 x) @[simp] axiom s1491 (x : Prop) : f (g1492 x) = f (g1491 x) @[simp] axiom s1492 (x : Prop) : f (g1493 x) = f (g1492 x) @[simp] axiom s1493 (x : Prop) : f (g1494 x) = f (g1493 x) @[simp] axiom s1494 (x : Prop) : f (g1495 x) = f (g1494 x) @[simp] axiom s1495 (x : Prop) : f (g1496 x) = f (g1495 x) @[simp] axiom s1496 (x : Prop) : f (g1497 x) = f (g1496 x) @[simp] axiom s1497 (x : Prop) : f (g1498 x) = f (g1497 x) @[simp] axiom s1498 (x : Prop) : f (g1499 x) = f (g1498 x)
341dbe4a1c90b2f8ccd0f2af6d80c35cc4369220
26ac254ecb57ffcb886ff709cf018390161a9225
/src/topology/algebra/infinite_sum.lean
dec76f4dc38e9b3bfe0683d4e0e7090747189576
[ "Apache-2.0" ]
permissive
eric-wieser/mathlib
42842584f584359bbe1fc8b88b3ff937c8acd72d
d0df6b81cd0920ad569158c06a3fd5abb9e63301
refs/heads/master
1,669,546,404,255
1,595,254,668,000
1,595,254,668,000
281,173,504
0
0
Apache-2.0
1,595,263,582,000
1,595,263,581,000
null
UTF-8
Lean
false
false
38,041
lean
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl -/ import topology.instances.real import data.indicator_function import data.equiv.encodable.lattice import order.filter.at_top_bot /-! # Infinite sum over a topological monoid This sum is known as unconditionally convergent, as it sums to the same value under all possible permutations. For Euclidean spaces (finite dimensional Banach spaces) this is equivalent to absolute convergence. Note: There are summable sequences which are not unconditionally convergent! The other way holds generally, see `has_sum.tendsto_sum_nat`. ## References * Bourbaki: General Topology (1995), Chapter 3 Β§5 (Infinite sums in commutative groups) -/ noncomputable theory open finset filter function classical open_locale topological_space classical big_operators variables {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} {Ξ΄ : Type*} section has_sum variables [add_comm_monoid Ξ±] [topological_space Ξ±] /-- Infinite sum on a topological monoid The `at_top` filter on `finset Ξ±` is the limit of all finite sets towards the entire type. So we sum up bigger and bigger sets. This sum operation is still invariant under reordering, and a absolute sum operator. This is based on Mario Carneiro's infinite sum in Metamath. For the definition or many statements, Ξ± does not need to be a topological monoid. We only add this assumption later, for the lemmas where it is relevant. -/ def has_sum (f : Ξ² β†’ Ξ±) (a : Ξ±) : Prop := tendsto (Ξ»s:finset Ξ², βˆ‘ b in s, f b) at_top (𝓝 a) /-- `summable f` means that `f` has some (infinite) sum. Use `tsum` to get the value. -/ def summable (f : Ξ² β†’ Ξ±) : Prop := βˆƒa, has_sum f a /-- `βˆ‘' i, f i` is the sum of `f` it exists, or 0 otherwise -/ def tsum (f : Ξ² β†’ Ξ±) := if h : summable f then classical.some h else 0 notation `βˆ‘'` binders `, ` r:(scoped f, tsum f) := r variables {f g : Ξ² β†’ Ξ±} {a b : Ξ±} {s : finset Ξ²} lemma summable.has_sum (ha : summable f) : has_sum f (βˆ‘'b, f b) := by simp [ha, tsum]; exact some_spec ha lemma has_sum.summable (h : has_sum f a) : summable f := ⟨a, h⟩ /-- Constant zero function has sum `0` -/ lemma has_sum_zero : has_sum (Ξ»b, 0 : Ξ² β†’ Ξ±) 0 := by simp [has_sum, tendsto_const_nhds] lemma summable_zero : summable (Ξ»b, 0 : Ξ² β†’ Ξ±) := has_sum_zero.summable lemma tsum_eq_zero_of_not_summable (h : Β¬ summable f) : (βˆ‘'b, f b) = 0 := by simp [tsum, h] lemma has_sum.has_sum_of_sum_eq {g : Ξ³ β†’ Ξ±} (h_eq : βˆ€u:finset Ξ³, βˆƒv:finset Ξ², βˆ€v', v βŠ† v' β†’ βˆƒu', u βŠ† u' ∧ βˆ‘ x in u', g x = βˆ‘ b in v', f b) (hf : has_sum g a) : has_sum f a := le_trans (map_at_top_finset_sum_le_of_sum_eq h_eq) hf lemma has_sum_iff_has_sum {g : Ξ³ β†’ Ξ±} (h₁ : βˆ€u:finset Ξ³, βˆƒv:finset Ξ², βˆ€v', v βŠ† v' β†’ βˆƒu', u βŠ† u' ∧ βˆ‘ x in u', g x = βˆ‘ b in v', f b) (hβ‚‚ : βˆ€v:finset Ξ², βˆƒu:finset Ξ³, βˆ€u', u βŠ† u' β†’ βˆƒv', v βŠ† v' ∧ βˆ‘ b in v', f b = βˆ‘ x in u', g x) : has_sum f a ↔ has_sum g a := ⟨has_sum.has_sum_of_sum_eq hβ‚‚, has_sum.has_sum_of_sum_eq hβ‚βŸ© lemma function.injective.has_sum_iff {g : Ξ³ β†’ Ξ²} (hg : injective g) (hf : βˆ€ x βˆ‰ set.range g, f x = 0) : has_sum (f ∘ g) a ↔ has_sum f a := by simp only [has_sum, tendsto, hg.map_at_top_finset_sum_eq hf] lemma function.injective.summable_iff {g : Ξ³ β†’ Ξ²} (hg : injective g) (hf : βˆ€ x βˆ‰ set.range g, f x = 0) : summable (f ∘ g) ↔ summable f := exists_congr $ Ξ» _, hg.has_sum_iff hf lemma has_sum_subtype_iff_of_support_subset {s : set Ξ²} (hf : support f βŠ† s) : has_sum (f ∘ coe : s β†’ Ξ±) a ↔ has_sum f a := subtype.coe_injective.has_sum_iff $ by simpa using support_subset_iff'.1 hf lemma has_sum_subtype_iff_indicator {s : set Ξ²} : has_sum (f ∘ coe : s β†’ Ξ±) a ↔ has_sum (s.indicator f) a := by rw [← set.indicator_range_comp, subtype.range_coe, has_sum_subtype_iff_of_support_subset set.support_indicator] @[simp] lemma has_sum_subtype_support : has_sum (f ∘ coe : support f β†’ Ξ±) a ↔ has_sum f a := has_sum_subtype_iff_of_support_subset $ set.subset.refl _ lemma has_sum_fintype [fintype Ξ²] (f : Ξ² β†’ Ξ±) : has_sum f (βˆ‘ b, f b) := order_top.tendsto_at_top _ protected lemma finset.has_sum (s : finset Ξ²) (f : Ξ² β†’ Ξ±) : has_sum (f ∘ coe : (↑s : set Ξ²) β†’ Ξ±) (βˆ‘ b in s, f b) := by { rw ← sum_attach, exact has_sum_fintype _ } protected lemma finset.summable (s : finset Ξ²) (f : Ξ² β†’ Ξ±) : summable (f ∘ coe : (↑s : set Ξ²) β†’ Ξ±) := (s.has_sum f).summable protected lemma set.finite.summable {s : set Ξ²} (hs : s.finite) (f : Ξ² β†’ Ξ±) : summable (f ∘ coe : s β†’ Ξ±) := by convert hs.to_finset.summable f; simp only [hs.coe_to_finset] /-- If a function `f` vanishes outside of a finite set `s`, then it `has_sum` `βˆ‘ b in s, f b`. -/ lemma has_sum_sum_of_ne_finset_zero (hf : βˆ€bβˆ‰s, f b = 0) : has_sum f (βˆ‘ b in s, f b) := (has_sum_subtype_iff_of_support_subset $ support_subset_iff'.2 hf).1 $ s.has_sum f lemma summable_of_ne_finset_zero (hf : βˆ€bβˆ‰s, f b = 0) : summable f := (has_sum_sum_of_ne_finset_zero hf).summable lemma has_sum_single {f : Ξ² β†’ Ξ±} (b : Ξ²) (hf : βˆ€b' β‰  b, f b' = 0) : has_sum f (f b) := suffices has_sum f (βˆ‘ b' in {b}, f b'), by simpa using this, has_sum_sum_of_ne_finset_zero $ by simpa [hf] lemma has_sum_ite_eq (b : Ξ²) (a : Ξ±) : has_sum (Ξ»b', if b' = b then a else 0) a := begin convert has_sum_single b _, { exact (if_pos rfl).symm }, assume b' hb', exact if_neg hb' end lemma equiv.has_sum_iff (e : Ξ³ ≃ Ξ²) : has_sum (f ∘ e) a ↔ has_sum f a := e.injective.has_sum_iff $ by simp lemma equiv.summable_iff (e : Ξ³ ≃ Ξ²) : summable (f ∘ e) ↔ summable f := exists_congr $ Ξ» a, e.has_sum_iff lemma summable.prod_symm {f : Ξ² Γ— Ξ³ β†’ Ξ±} (hf : summable f) : summable (Ξ» p : Ξ³ Γ— Ξ², f p.swap) := (equiv.prod_comm Ξ³ Ξ²).summable_iff.2 hf lemma equiv.has_sum_iff_of_support {g : Ξ³ β†’ Ξ±} (e : support f ≃ support g) (he : βˆ€ x : support f, g (e x) = f x) : has_sum f a ↔ has_sum g a := have (g ∘ coe) ∘ e = f ∘ coe, from funext he, by rw [← has_sum_subtype_support, ← this, e.has_sum_iff, has_sum_subtype_support] lemma has_sum_iff_has_sum_of_ne_zero_bij {g : Ξ³ β†’ Ξ±} (i : support g β†’ Ξ²) (hi : βˆ€ ⦃x y⦄, i x = i y β†’ (x : Ξ³) = y) (hf : support f βŠ† set.range i) (hfg : βˆ€ x, f (i x) = g x) : has_sum f a ↔ has_sum g a := iff.symm $ equiv.has_sum_iff_of_support (equiv.of_bijective (Ξ» x, ⟨i x, Ξ» hx, x.coe_prop $ hfg x β–Έ hx⟩) ⟨λ x y h, subtype.ext $ hi $ subtype.ext_iff.1 h, Ξ» y, (hf y.coe_prop).imp $ Ξ» x hx, subtype.ext hx⟩) hfg lemma equiv.summable_iff_of_support {g : Ξ³ β†’ Ξ±} (e : support f ≃ support g) (he : βˆ€ x : support f, g (e x) = f x) : summable f ↔ summable g := exists_congr $ Ξ» _, e.has_sum_iff_of_support he protected lemma has_sum.map [add_comm_monoid Ξ³] [topological_space Ξ³] (hf : has_sum f a) (g : Ξ± β†’+ Ξ³) (h₃ : continuous g) : has_sum (g ∘ f) (g a) := have g ∘ (Ξ»s:finset Ξ², βˆ‘ b in s, f b) = (Ξ»s:finset Ξ², βˆ‘ b in s, g (f b)), from funext $ g.map_sum _, show tendsto (Ξ»s:finset Ξ², βˆ‘ b in s, g (f b)) at_top (𝓝 (g a)), from this β–Έ (h₃.tendsto a).comp hf /-- If `f : β„• β†’ Ξ±` has sum `a`, then the partial sums `βˆ‘_{i=0}^{n-1} f i` converge to `a`. -/ lemma has_sum.tendsto_sum_nat {f : β„• β†’ Ξ±} (h : has_sum f a) : tendsto (Ξ»n:β„•, βˆ‘ i in range n, f i) at_top (𝓝 a) := h.comp tendsto_finset_range lemma has_sum.unique {a₁ aβ‚‚ : Ξ±} [t2_space Ξ±] : has_sum f a₁ β†’ has_sum f aβ‚‚ β†’ a₁ = aβ‚‚ := tendsto_nhds_unique lemma summable.has_sum_iff_tendsto_nat [t2_space Ξ±] {f : β„• β†’ Ξ±} {a : Ξ±} (hf : summable f) : has_sum f a ↔ tendsto (Ξ»n:β„•, βˆ‘ i in range n, f i) at_top (𝓝 a) := begin refine ⟨λ h, h.tendsto_sum_nat, Ξ» h, _⟩, rw tendsto_nhds_unique h hf.has_sum.tendsto_sum_nat, exact hf.has_sum end lemma equiv.summable_iff_of_has_sum_iff {Ξ±' : Type*} [add_comm_monoid Ξ±'] [topological_space Ξ±'] (e : Ξ±' ≃ Ξ±) {f : Ξ² β†’ Ξ±} {g : Ξ³ β†’ Ξ±'} (he : βˆ€ {a}, has_sum f (e a) ↔ has_sum g a) : summable f ↔ summable g := ⟨λ ⟨a, ha⟩, ⟨e.symm a, he.1 $ by rwa [e.apply_symm_apply]⟩, Ξ» ⟨a, ha⟩, ⟨e a, he.2 ha⟩⟩ variable [topological_add_monoid Ξ±] lemma has_sum.add (hf : has_sum f a) (hg : has_sum g b) : has_sum (Ξ»b, f b + g b) (a + b) := by simp only [has_sum, sum_add_distrib]; exact hf.add hg lemma summable.add (hf : summable f) (hg : summable g) : summable (Ξ»b, f b + g b) := (hf.has_sum.add hg.has_sum).summable lemma has_sum_sum {f : Ξ³ β†’ Ξ² β†’ Ξ±} {a : Ξ³ β†’ Ξ±} {s : finset Ξ³} : (βˆ€i∈s, has_sum (f i) (a i)) β†’ has_sum (Ξ»b, βˆ‘ i in s, f i b) (βˆ‘ i in s, a i) := finset.induction_on s (by simp [has_sum_zero]) (by simp [has_sum.add] {contextual := tt}) lemma summable_sum {f : Ξ³ β†’ Ξ² β†’ Ξ±} {s : finset Ξ³} (hf : βˆ€i∈s, summable (f i)) : summable (Ξ»b, βˆ‘ i in s, f i b) := (has_sum_sum $ assume i hi, (hf i hi).has_sum).summable lemma has_sum.add_compl {s : set Ξ²} (ha : has_sum (f ∘ coe : s β†’ Ξ±) a) (hb : has_sum (f ∘ coe : sᢜ β†’ Ξ±) b) : has_sum f (a + b) := by simpa using (has_sum_subtype_iff_indicator.1 ha).add (has_sum_subtype_iff_indicator.1 hb) lemma summable.add_compl {s : set Ξ²} (hs : summable (f ∘ coe : s β†’ Ξ±)) (hsc : summable (f ∘ coe : sᢜ β†’ Ξ±)) : summable f := (hs.has_sum.add_compl hsc.has_sum).summable lemma has_sum.compl_add {s : set Ξ²} (ha : has_sum (f ∘ coe : sᢜ β†’ Ξ±) a) (hb : has_sum (f ∘ coe : s β†’ Ξ±) b) : has_sum f (a + b) := by simpa using (has_sum_subtype_iff_indicator.1 ha).add (has_sum_subtype_iff_indicator.1 hb) lemma summable.compl_add {s : set Ξ²} (hs : summable (f ∘ coe : sᢜ β†’ Ξ±)) (hsc : summable (f ∘ coe : s β†’ Ξ±)) : summable f := (hs.has_sum.compl_add hsc.has_sum).summable lemma has_sum.sigma [regular_space Ξ±] {Ξ³ : Ξ² β†’ Type*} {f : (Ξ£ b:Ξ², Ξ³ b) β†’ Ξ±} {g : Ξ² β†’ Ξ±} {a : Ξ±} (ha : has_sum f a) (hf : βˆ€b, has_sum (Ξ»c, f ⟨b, c⟩) (g b)) : has_sum g a := assume s' hs', let ⟨s, hs, hss', hsc⟩ := nhds_is_closed hs', ⟨u, hu⟩ := mem_at_top_sets.mp $ ha hs, fsts := u.image sigma.fst, snds := Ξ»b, u.bind (Ξ»p, (if h : p.1 = b then {cast (congr_arg Ξ³ h) p.2} else βˆ… : finset (Ξ³ b))) in have u_subset : u βŠ† fsts.sigma snds, from subset_iff.mpr $ assume ⟨b, c⟩ hu, have hb : b ∈ fsts, from finset.mem_image.mpr ⟨_, hu, rfl⟩, have hc : c ∈ snds b, from mem_bind.mpr ⟨_, hu, by simp; refl⟩, by simp [mem_sigma, hb, hc] , mem_at_top_sets.mpr $ exists.intro fsts $ assume bs (hbs : fsts βŠ† bs), have h : βˆ€cs : Ξ  b ∈ bs, finset (Ξ³ b), ((β‹‚b (hb : b ∈ bs), (Ξ»p:Ξ b, finset (Ξ³ b), p b) ⁻¹' {cs' | cs b hb βŠ† cs' }) ∩ (Ξ»p, βˆ‘ b in bs, βˆ‘ c in p b, f ⟨b, c⟩) ⁻¹' s).nonempty, from assume cs, let cs' := Ξ»b, (if h : b ∈ bs then cs b h else βˆ…) βˆͺ snds b in have sum_eq : βˆ‘ b in bs, βˆ‘ c in cs' b, f ⟨b, c⟩ = βˆ‘ x in bs.sigma cs', f x, from sum_sigma.symm, have βˆ‘ x in bs.sigma cs', f x ∈ s, from hu _ $ finset.subset.trans u_subset $ sigma_mono hbs $ assume b, @finset.subset_union_right (Ξ³ b) _ _ _, exists.intro cs' $ by simp [sum_eq, this]; { intros b hb, simp [cs', hb, finset.subset_union_left] }, have tendsto (Ξ»p:(Ξ b:Ξ², finset (Ξ³ b)), βˆ‘ b in bs, βˆ‘ c in p b, f ⟨b, c⟩) (β¨…b (h : b ∈ bs), at_top.comap (Ξ»p, p b)) (𝓝 (βˆ‘ b in bs, g b)), from tendsto_finset_sum bs $ assume c hc, tendsto_infi' c $ tendsto_infi' hc $ by apply tendsto.comp (hf c) tendsto_comap, have βˆ‘ b in bs, g b ∈ s, from @mem_of_closed_of_tendsto' _ _ _ _ _ _ _ this hsc $ forall_sets_nonempty_iff_ne_bot.mp $ begin simp only [mem_inf_sets, exists_imp_distrib, forall_and_distrib, and_imp, filter.mem_infi_sets_finset, mem_comap_sets, mem_at_top_sets, and_comm, mem_principal_sets, set.preimage_subset_iff, exists_prop, skolem], intros s₁ sβ‚‚ s₃ hs₁ hs₃ p hsβ‚‚ p' hp cs hp', have : (β‹‚b (h : b ∈ bs), (Ξ»p:(Ξ b, finset (Ξ³ b)), p b) ⁻¹' {cs' | cs b h βŠ† cs' }) ≀ (β¨…b∈bs, p b), from (infi_le_infi $ assume b, infi_le_infi $ assume hb, le_trans (set.preimage_mono $ hp' b hb) (hp b hb)), exact (h _).mono (set.subset.trans (set.inter_subset_inter (le_trans this hsβ‚‚) hs₃) hs₁) end, hss' this /-- If a series `f` on `Ξ² Γ— Ξ³` has sum `a` and for each `b` the restriction of `f` to `{b} Γ— Ξ³` has sum `g b`, then the series `g` has sum `a`. -/ lemma has_sum.prod_fiberwise [regular_space Ξ±] {f : Ξ² Γ— Ξ³ β†’ Ξ±} {g : Ξ² β†’ Ξ±} {a : Ξ±} (ha : has_sum f a) (hf : βˆ€b, has_sum (Ξ»c, f (b, c)) (g b)) : has_sum g a := has_sum.sigma ((equiv.sigma_equiv_prod Ξ² Ξ³).has_sum_iff.2 ha) hf lemma summable.sigma' [regular_space Ξ±] {Ξ³ : Ξ² β†’ Type*} {f : (Ξ£b:Ξ², Ξ³ b) β†’ Ξ±} (ha : summable f) (hf : βˆ€b, summable (Ξ»c, f ⟨b, c⟩)) : summable (Ξ»b, βˆ‘'c, f ⟨b, c⟩) := (ha.has_sum.sigma (assume b, (hf b).has_sum)).summable lemma has_sum.sigma_of_has_sum [regular_space Ξ±] {Ξ³ : Ξ² β†’ Type*} {f : (Ξ£ b:Ξ², Ξ³ b) β†’ Ξ±} {g : Ξ² β†’ Ξ±} {a : Ξ±} (ha : has_sum g a) (hf : βˆ€b, has_sum (Ξ»c, f ⟨b, c⟩) (g b)) (hf' : summable f) : has_sum f a := by simpa [(hf'.has_sum.sigma hf).unique ha] using hf'.has_sum end has_sum section tsum variables [add_comm_monoid Ξ±] [topological_space Ξ±] [t2_space Ξ±] variables {f g : Ξ² β†’ Ξ±} {a a₁ aβ‚‚ : Ξ±} lemma has_sum.tsum_eq (ha : has_sum f a) : (βˆ‘'b, f b) = a := (summable.has_sum ⟨a, ha⟩).unique ha lemma summable.has_sum_iff (h : summable f) : has_sum f a ↔ (βˆ‘'b, f b) = a := iff.intro has_sum.tsum_eq (assume eq, eq β–Έ h.has_sum) @[simp] lemma tsum_zero : (βˆ‘'b:Ξ², 0:Ξ±) = 0 := has_sum_zero.tsum_eq lemma tsum_eq_sum {f : Ξ² β†’ Ξ±} {s : finset Ξ²} (hf : βˆ€bβˆ‰s, f b = 0) : (βˆ‘'b, f b) = βˆ‘ b in s, f b := (has_sum_sum_of_ne_finset_zero hf).tsum_eq lemma tsum_fintype [fintype Ξ²] (f : Ξ² β†’ Ξ±) : (βˆ‘'b, f b) = βˆ‘ b, f b := (has_sum_fintype f).tsum_eq @[simp] lemma finset.tsum_subtype (s : finset Ξ²) (f : Ξ² β†’ Ξ±) : (βˆ‘'x : {x // x ∈ s}, f x) = βˆ‘ x in s, f x := (s.has_sum f).tsum_eq lemma tsum_eq_single {f : Ξ² β†’ Ξ±} (b : Ξ²) (hf : βˆ€b' β‰  b, f b' = 0) : (βˆ‘'b, f b) = f b := (has_sum_single b hf).tsum_eq @[simp] lemma tsum_ite_eq (b : Ξ²) (a : Ξ±) : (βˆ‘'b', if b' = b then a else 0) = a := (has_sum_ite_eq b a).tsum_eq lemma equiv.tsum_eq_tsum_of_has_sum_iff_has_sum {Ξ±' : Type*} [add_comm_monoid Ξ±'] [topological_space Ξ±'] (e : Ξ±' ≃ Ξ±) (h0 : e 0 = 0) {f : Ξ² β†’ Ξ±} {g : Ξ³ β†’ Ξ±'} (h : βˆ€ {a}, has_sum f (e a) ↔ has_sum g a) : (βˆ‘' b, f b) = e (βˆ‘' c, g c) := by_cases (assume : summable g, (h.mpr this.has_sum).tsum_eq) (assume hg : Β¬ summable g, have hf : Β¬ summable f, from mt (e.summable_iff_of_has_sum_iff @h).1 hg, by simp [tsum, hf, hg, h0]) lemma tsum_eq_tsum_of_has_sum_iff_has_sum {f : Ξ² β†’ Ξ±} {g : Ξ³ β†’ Ξ±} (h : βˆ€{a}, has_sum f a ↔ has_sum g a) : (βˆ‘'b, f b) = (βˆ‘'c, g c) := (equiv.refl Ξ±).tsum_eq_tsum_of_has_sum_iff_has_sum rfl @h lemma equiv.tsum_eq (j : Ξ³ ≃ Ξ²) (f : Ξ² β†’ Ξ±) : (βˆ‘'c, f (j c)) = (βˆ‘'b, f b) := tsum_eq_tsum_of_has_sum_iff_has_sum $ Ξ» a, j.has_sum_iff lemma equiv.tsum_eq_tsum_of_support {f : Ξ² β†’ Ξ±} {g : Ξ³ β†’ Ξ±} (e : support f ≃ support g) (he : βˆ€ x, g (e x) = f x) : (βˆ‘' x, f x) = βˆ‘' y, g y := tsum_eq_tsum_of_has_sum_iff_has_sum $ Ξ» _, e.has_sum_iff_of_support he lemma tsum_eq_tsum_of_ne_zero_bij {g : Ξ³ β†’ Ξ±} (i : support g β†’ Ξ²) (hi : βˆ€ ⦃x y⦄, i x = i y β†’ (x : Ξ³) = y) (hf : support f βŠ† set.range i) (hfg : βˆ€ x, f (i x) = g x) : (βˆ‘' x, f x) = βˆ‘' y, g y := tsum_eq_tsum_of_has_sum_iff_has_sum $ Ξ» _, has_sum_iff_has_sum_of_ne_zero_bij i hi hf hfg lemma tsum_subtype (s : set Ξ²) (f : Ξ² β†’ Ξ±) : (βˆ‘' x : s, f x) = βˆ‘' x, s.indicator f x := tsum_eq_tsum_of_has_sum_iff_has_sum $ Ξ» _, has_sum_subtype_iff_indicator section topological_add_monoid variable [topological_add_monoid Ξ±] lemma tsum_add (hf : summable f) (hg : summable g) : (βˆ‘'b, f b + g b) = (βˆ‘'b, f b) + (βˆ‘'b, g b) := (hf.has_sum.add hg.has_sum).tsum_eq lemma tsum_sum {f : Ξ³ β†’ Ξ² β†’ Ξ±} {s : finset Ξ³} (hf : βˆ€i∈s, summable (f i)) : (βˆ‘'b, βˆ‘ i in s, f i b) = βˆ‘ i in s, βˆ‘'b, f i b := (has_sum_sum $ assume i hi, (hf i hi).has_sum).tsum_eq lemma tsum_sigma' [regular_space Ξ±] {Ξ³ : Ξ² β†’ Type*} {f : (Ξ£b:Ξ², Ξ³ b) β†’ Ξ±} (h₁ : βˆ€b, summable (Ξ»c, f ⟨b, c⟩)) (hβ‚‚ : summable f) : (βˆ‘'p, f p) = (βˆ‘'b c, f ⟨b, c⟩) := (hβ‚‚.has_sum.sigma (assume b, (h₁ b).has_sum)).tsum_eq.symm lemma tsum_prod' [regular_space Ξ±] {f : Ξ² Γ— Ξ³ β†’ Ξ±} (h : summable f) (h₁ : βˆ€b, summable (Ξ»c, f (b, c))) : (βˆ‘'p, f p) = (βˆ‘'b c, f (b, c)) := (h.has_sum.prod_fiberwise (assume b, (h₁ b).has_sum)).tsum_eq.symm lemma tsum_comm' [regular_space Ξ±] {f : Ξ² β†’ Ξ³ β†’ Ξ±} (h : summable (function.uncurry f)) (h₁ : βˆ€b, summable (f b)) (hβ‚‚ : βˆ€ c, summable (Ξ» b, f b c)) : (βˆ‘' c b, f b c) = (βˆ‘' b c, f b c) := begin erw [← tsum_prod' h h₁, ← tsum_prod' h.prod_symm hβ‚‚, ← (equiv.prod_comm Ξ² Ξ³).tsum_eq], refl, assumption end end topological_add_monoid section encodable open encodable variable [encodable Ξ³] /-- You can compute a sum over an encodably type by summing over the natural numbers and taking a supremum. This is useful for outer measures. -/ theorem tsum_supr_decode2 [complete_lattice Ξ²] (m : Ξ² β†’ Ξ±) (m0 : m βŠ₯ = 0) (s : Ξ³ β†’ Ξ²) : (βˆ‘' i : β„•, m (⨆ b ∈ decode2 Ξ³ i, s b)) = (βˆ‘' b : Ξ³, m (s b)) := begin have H : βˆ€ n, m (⨆ b ∈ decode2 Ξ³ n, s b) β‰  0 β†’ (decode2 Ξ³ n).is_some, { intros n h, cases decode2 Ξ³ n with b, { refine (h $ by simp [m0]).elim }, { exact rfl } }, symmetry, refine tsum_eq_tsum_of_ne_zero_bij (Ξ» a, option.get (H a.1 a.2)) _ _ _, { rintros ⟨m, hm⟩ ⟨n, hn⟩ e, have := mem_decode2.1 (option.get_mem (H n hn)), rwa [← e, mem_decode2.1 (option.get_mem (H m hm))] at this }, { intros b h, refine ⟨⟨encode b, _⟩, _⟩, { simp only [mem_support, encodek2] at h ⊒, convert h, simp [set.ext_iff, encodek2] }, { exact option.get_of_mem _ (encodek2 _) } }, { rintros ⟨n, h⟩, dsimp only [subtype.coe_mk], transitivity, swap, rw [show decode2 Ξ³ n = _, from option.get_mem (H n h)], congr, simp [ext_iff, -option.some_get] } end /-- `tsum_supr_decode2` specialized to the complete lattice of sets. -/ theorem tsum_Union_decode2 (m : set Ξ² β†’ Ξ±) (m0 : m βˆ… = 0) (s : Ξ³ β†’ set Ξ²) : (βˆ‘' i, m (⋃ b ∈ decode2 Ξ³ i, s b)) = (βˆ‘' b, m (s b)) := tsum_supr_decode2 m m0 s /-! Some properties about measure-like functions. These could also be functions defined on complete sublattices of sets, with the property that they are countably sub-additive. `R` will probably be instantiated with `(≀)` in all applications. -/ /-- If a function is countably sub-additive then it is sub-additive on encodable types -/ theorem rel_supr_tsum [complete_lattice Ξ²] (m : Ξ² β†’ Ξ±) (m0 : m βŠ₯ = 0) (R : Ξ± β†’ Ξ± β†’ Prop) (m_supr : βˆ€(s : β„• β†’ Ξ²), R (m (⨆ i, s i)) (βˆ‘' i, m (s i))) (s : Ξ³ β†’ Ξ²) : R (m (⨆ b : Ξ³, s b)) (βˆ‘' b : Ξ³, m (s b)) := by { rw [← supr_decode2, ← tsum_supr_decode2 _ m0 s], exact m_supr _ } /-- If a function is countably sub-additive then it is sub-additive on finite sets -/ theorem rel_supr_sum [complete_lattice Ξ²] (m : Ξ² β†’ Ξ±) (m0 : m βŠ₯ = 0) (R : Ξ± β†’ Ξ± β†’ Prop) (m_supr : βˆ€(s : β„• β†’ Ξ²), R (m (⨆ i, s i)) (βˆ‘' i, m (s i))) (s : Ξ΄ β†’ Ξ²) (t : finset Ξ΄) : R (m (⨆ d ∈ t, s d)) (βˆ‘ d in t, m (s d)) := by { cases t.nonempty_encodable, rw [supr_subtype'], convert rel_supr_tsum m m0 R m_supr _, rw [← finset.tsum_subtype], assumption } /-- If a function is countably sub-additive then it is binary sub-additive -/ theorem rel_sup_add [complete_lattice Ξ²] (m : Ξ² β†’ Ξ±) (m0 : m βŠ₯ = 0) (R : Ξ± β†’ Ξ± β†’ Prop) (m_supr : βˆ€(s : β„• β†’ Ξ²), R (m (⨆ i, s i)) (βˆ‘' i, m (s i))) (s₁ sβ‚‚ : Ξ²) : R (m (s₁ βŠ” sβ‚‚)) (m s₁ + m sβ‚‚) := begin convert rel_supr_tsum m m0 R m_supr (Ξ» b, cond b s₁ sβ‚‚), { simp only [supr_bool_eq, cond] }, { rw tsum_fintype, simp only [finset.sum_insert, not_false_iff, fintype.univ_bool, finset.mem_singleton, cond, finset.sum_singleton] } end end encodable end tsum section topological_group variables [add_comm_group Ξ±] [topological_space Ξ±] [topological_add_group Ξ±] variables {f g : Ξ² β†’ Ξ±} {a a₁ aβ‚‚ : Ξ±} -- `by simpa using` speeds up elaboration. Why? lemma has_sum.neg (h : has_sum f a) : has_sum (Ξ»b, - f b) (- a) := by simpa only using h.map (-add_monoid_hom.id Ξ±) continuous_neg lemma summable.neg (hf : summable f) : summable (Ξ»b, - f b) := hf.has_sum.neg.summable lemma has_sum.sub (hf : has_sum f a₁) (hg : has_sum g aβ‚‚) : has_sum (Ξ»b, f b - g b) (a₁ - aβ‚‚) := by { simp [sub_eq_add_neg], exact hf.add hg.neg } lemma summable.sub (hf : summable f) (hg : summable g) : summable (Ξ»b, f b - g b) := (hf.has_sum.sub hg.has_sum).summable lemma has_sum.has_sum_compl_iff {s : set Ξ²} (hf : has_sum (f ∘ coe : s β†’ Ξ±) a₁) : has_sum (f ∘ coe : sᢜ β†’ Ξ±) aβ‚‚ ↔ has_sum f (a₁ + aβ‚‚) := begin refine ⟨λ h, hf.add_compl h, Ξ» h, _⟩, rw [has_sum_subtype_iff_indicator] at hf ⊒, rw [set.indicator_compl], simpa only [add_sub_cancel'] using h.sub hf end lemma has_sum.has_sum_iff_compl {s : set Ξ²} (hf : has_sum (f ∘ coe : s β†’ Ξ±) a₁) : has_sum f aβ‚‚ ↔ has_sum (f ∘ coe : sᢜ β†’ Ξ±) (aβ‚‚ - a₁) := iff.symm $ hf.has_sum_compl_iff.trans $ by rw [add_sub_cancel'_right] lemma summable.summable_compl_iff {s : set Ξ²} (hf : summable (f ∘ coe : s β†’ Ξ±)) : summable (f ∘ coe : sᢜ β†’ Ξ±) ↔ summable f := ⟨λ ⟨a, ha⟩, (hf.has_sum.has_sum_compl_iff.1 ha).summable, Ξ» ⟨a, ha⟩, (hf.has_sum.has_sum_iff_compl.1 ha).summable⟩ protected lemma finset.has_sum_compl_iff (s : finset Ξ²) : has_sum (Ξ» x : {x // x βˆ‰ s}, f x) a ↔ has_sum f (a + βˆ‘ i in s, f i) := (s.has_sum f).has_sum_compl_iff.trans $ by rw [add_comm] protected lemma finset.has_sum_iff_compl (s : finset Ξ²) : has_sum f a ↔ has_sum (Ξ» x : {x // x βˆ‰ s}, f x) (a - βˆ‘ i in s, f i) := (s.has_sum f).has_sum_iff_compl protected lemma finset.summable_compl_iff (s : finset Ξ²) : summable (Ξ» x : {x // x βˆ‰ s}, f x) ↔ summable f := (s.summable f).summable_compl_iff lemma set.finite.summable_compl_iff {s : set Ξ²} (hs : s.finite) : summable (f ∘ coe : sᢜ β†’ Ξ±) ↔ summable f := (hs.summable f).summable_compl_iff section tsum variables [t2_space Ξ±] lemma tsum_neg (hf : summable f) : (βˆ‘'b, - f b) = - (βˆ‘'b, f b) := hf.has_sum.neg.tsum_eq lemma tsum_sub (hf : summable f) (hg : summable g) : (βˆ‘'b, f b - g b) = (βˆ‘'b, f b) - (βˆ‘'b, g b) := (hf.has_sum.sub hg.has_sum).tsum_eq lemma tsum_add_tsum_compl {s : set Ξ²} (hs : summable (f ∘ coe : s β†’ Ξ±)) (hsc : summable (f ∘ coe : sᢜ β†’ Ξ±)) : (βˆ‘' x : s, f x) + (βˆ‘' x : sᢜ, f x) = βˆ‘' x, f x := (hs.has_sum.add_compl hsc.has_sum).tsum_eq.symm lemma sum_add_tsum_compl {s : finset Ξ²} (hf : summable f) : (βˆ‘ x in s, f x) + (βˆ‘' x : (↑s : set Ξ²)ᢜ, f x) = βˆ‘' x, f x := ((s.has_sum f).add_compl (s.summable_compl_iff.2 hf).has_sum).tsum_eq.symm end tsum /-! ### Sums on subtypes If `s` is a finset of `Ξ±`, we show that the summability of `f` in the whole space and on the subtype `univ - s` are equivalent, and relate their sums. For a function defined on `β„•`, we deduce the formula `(βˆ‘ i in range k, f i) + (βˆ‘' i, f (i + k)) = (βˆ‘' i, f i)`, in `sum_add_tsum_nat_add`. -/ section subtype variables {s : finset Ξ²} lemma has_sum_nat_add_iff {f : β„• β†’ Ξ±} (k : β„•) {a : Ξ±} : has_sum (Ξ» n, f (n + k)) a ↔ has_sum f (a + βˆ‘ i in range k, f i) := begin refine iff.trans _ ((range k).has_sum_compl_iff), rw [← (not_mem_range_equiv k).symm.has_sum_iff], refl end lemma summable_nat_add_iff {f : β„• β†’ Ξ±} (k : β„•) : summable (Ξ» n, f (n + k)) ↔ summable f := iff.symm $ (equiv.add_right (βˆ‘ i in range k, f i)).summable_iff_of_has_sum_iff $ Ξ» a, (has_sum_nat_add_iff k).symm lemma has_sum_nat_add_iff' {f : β„• β†’ Ξ±} (k : β„•) {a : Ξ±} : has_sum (Ξ» n, f (n + k)) (a - βˆ‘ i in range k, f i) ↔ has_sum f a := by simp [has_sum_nat_add_iff] lemma sum_add_tsum_nat_add [t2_space Ξ±] {f : β„• β†’ Ξ±} (k : β„•) (h : summable f) : (βˆ‘ i in range k, f i) + (βˆ‘' i, f (i + k)) = (βˆ‘' i, f i) := by simpa [add_comm] using ((has_sum_nat_add_iff k).1 ((summable_nat_add_iff k).2 h).has_sum).unique h.has_sum lemma tsum_eq_zero_add [t2_space Ξ±] {f : β„• β†’ Ξ±} (hf : summable f) : (βˆ‘'b, f b) = f 0 + (βˆ‘'b, f (b + 1)) := by simpa only [range_one, sum_singleton] using (sum_add_tsum_nat_add 1 hf).symm end subtype end topological_group section topological_semiring variables [semiring Ξ±] [topological_space Ξ±] [topological_semiring Ξ±] variables {f g : Ξ² β†’ Ξ±} {a a₁ aβ‚‚ : Ξ±} lemma has_sum.mul_left (aβ‚‚) (h : has_sum f a₁) : has_sum (Ξ»b, aβ‚‚ * f b) (aβ‚‚ * a₁) := by simpa only using h.map (add_monoid_hom.mul_left aβ‚‚) (continuous_const.mul continuous_id) lemma has_sum.mul_right (aβ‚‚) (hf : has_sum f a₁) : has_sum (Ξ»b, f b * aβ‚‚) (a₁ * aβ‚‚) := by simpa only using hf.map (add_monoid_hom.mul_right aβ‚‚) (continuous_id.mul continuous_const) lemma summable.mul_left (a) (hf : summable f) : summable (Ξ»b, a * f b) := (hf.has_sum.mul_left _).summable lemma summable.mul_right (a) (hf : summable f) : summable (Ξ»b, f b * a) := (hf.has_sum.mul_right _).summable section tsum variables [t2_space Ξ±] lemma tsum_mul_left (a) (hf : summable f) : (βˆ‘'b, a * f b) = a * (βˆ‘'b, f b) := (hf.has_sum.mul_left _).tsum_eq lemma tsum_mul_right (a) (hf : summable f) : (βˆ‘'b, f b * a) = (βˆ‘'b, f b) * a := (hf.has_sum.mul_right _).tsum_eq end tsum end topological_semiring section division_ring variables [division_ring Ξ±] [topological_space Ξ±] [topological_semiring Ξ±] {f g : Ξ² β†’ Ξ±} {a a₁ aβ‚‚ : Ξ±} lemma has_sum_mul_left_iff (h : aβ‚‚ β‰  0) : has_sum f a₁ ↔ has_sum (Ξ»b, aβ‚‚ * f b) (aβ‚‚ * a₁) := ⟨has_sum.mul_left _, Ξ» H, by simpa only [inv_mul_cancel_left' h] using H.mul_left aβ‚‚β»ΒΉβŸ© lemma has_sum_mul_right_iff (h : aβ‚‚ β‰  0) : has_sum f a₁ ↔ has_sum (Ξ»b, f b * aβ‚‚) (a₁ * aβ‚‚) := ⟨has_sum.mul_right _, Ξ» H, by simpa only [mul_inv_cancel_right' h] using H.mul_right aβ‚‚β»ΒΉβŸ© lemma summable_mul_left_iff (h : a β‰  0) : summable f ↔ summable (Ξ»b, a * f b) := ⟨λ H, H.mul_left _, Ξ» H, by simpa only [inv_mul_cancel_left' h] using H.mul_left a⁻¹⟩ lemma summable_mul_right_iff (h : a β‰  0) : summable f ↔ summable (Ξ»b, f b * a) := ⟨λ H, H.mul_right _, Ξ» H, by simpa only [mul_inv_cancel_right' h] using H.mul_right a⁻¹⟩ end division_ring section order_topology variables [ordered_add_comm_monoid Ξ±] [topological_space Ξ±] [order_closed_topology Ξ±] variables {f g : Ξ² β†’ Ξ±} {a a₁ aβ‚‚ : Ξ±} lemma has_sum_le (h : βˆ€b, f b ≀ g b) (hf : has_sum f a₁) (hg : has_sum g aβ‚‚) : a₁ ≀ aβ‚‚ := le_of_tendsto_of_tendsto' hf hg $ assume s, sum_le_sum $ assume b _, h b lemma has_sum_le_inj {g : Ξ³ β†’ Ξ±} (i : Ξ² β†’ Ξ³) (hi : injective i) (hs : βˆ€cβˆ‰set.range i, 0 ≀ g c) (h : βˆ€b, f b ≀ g (i b)) (hf : has_sum f a₁) (hg : has_sum g aβ‚‚) : a₁ ≀ aβ‚‚ := have has_sum (Ξ»c, (partial_inv i c).cases_on' 0 f) a₁, begin refine (has_sum_iff_has_sum_of_ne_zero_bij (i ∘ coe) _ _ _).2 hf, { exact assume c₁ cβ‚‚ eq, hi eq }, { intros c hc, rw [mem_support] at hc, cases eq : partial_inv i c with b; rw eq at hc, { contradiction }, { rw [partial_inv_of_injective hi] at eq, exact ⟨⟨b, hc⟩, eq⟩ } }, { assume c, simp [partial_inv_left hi, option.cases_on'] } end, begin refine has_sum_le (assume c, _) this hg, by_cases c ∈ set.range i, { rcases h with ⟨b, rfl⟩, rw [partial_inv_left hi, option.cases_on'], exact h _ }, { have : partial_inv i c = none := dif_neg h, rw [this, option.cases_on'], exact hs _ h } end lemma tsum_le_tsum_of_inj {g : Ξ³ β†’ Ξ±} (i : Ξ² β†’ Ξ³) (hi : injective i) (hs : βˆ€cβˆ‰set.range i, 0 ≀ g c) (h : βˆ€b, f b ≀ g (i b)) (hf : summable f) (hg : summable g) : tsum f ≀ tsum g := has_sum_le_inj i hi hs h hf.has_sum hg.has_sum lemma sum_le_has_sum {f : Ξ² β†’ Ξ±} (s : finset Ξ²) (hs : βˆ€ bβˆ‰s, 0 ≀ f b) (hf : has_sum f a) : βˆ‘ b in s, f b ≀ a := ge_of_tendsto hf (eventually_at_top.2 ⟨s, Ξ» t hst, sum_le_sum_of_subset_of_nonneg hst $ Ξ» b hbt hbs, hs b hbs⟩) lemma sum_le_tsum {f : Ξ² β†’ Ξ±} (s : finset Ξ²) (hs : βˆ€ bβˆ‰s, 0 ≀ f b) (hf : summable f) : βˆ‘ b in s, f b ≀ tsum f := sum_le_has_sum s hs hf.has_sum lemma tsum_le_tsum (h : βˆ€b, f b ≀ g b) (hf : summable f) (hg : summable g) : (βˆ‘'b, f b) ≀ (βˆ‘'b, g b) := has_sum_le h hf.has_sum hg.has_sum lemma tsum_nonneg (h : βˆ€ b, 0 ≀ g b) : 0 ≀ (βˆ‘'b, g b) := begin by_cases hg : summable g, { simpa using tsum_le_tsum h summable_zero hg }, { simp [tsum_eq_zero_of_not_summable hg] } end lemma tsum_nonpos (h : βˆ€ b, f b ≀ 0) : (βˆ‘'b, f b) ≀ 0 := begin by_cases hf : summable f, { simpa using tsum_le_tsum h hf summable_zero}, { simp [tsum_eq_zero_of_not_summable hf] } end end order_topology section uniform_group variables [add_comm_group Ξ±] [uniform_space Ξ±] variables {f g : Ξ² β†’ Ξ±} {a a₁ aβ‚‚ : Ξ±} lemma summable_iff_cauchy_seq_finset [complete_space Ξ±] : summable f ↔ cauchy_seq (Ξ» (s : finset Ξ²), βˆ‘ b in s, f b) := cauchy_map_iff_exists_tendsto.symm variable [uniform_add_group Ξ±] lemma cauchy_seq_finset_iff_vanishing : cauchy_seq (Ξ» (s : finset Ξ²), βˆ‘ b in s, f b) ↔ βˆ€ e ∈ 𝓝 (0:Ξ±), (βˆƒs:finset Ξ², βˆ€t, disjoint t s β†’ βˆ‘ b in t, f b ∈ e) := begin simp only [cauchy_seq, cauchy_map_iff, and_iff_right at_top_ne_bot, prod_at_top_at_top_eq, uniformity_eq_comap_nhds_zero Ξ±, tendsto_comap_iff, (∘)], rw [tendsto_at_top' (_ : finset Ξ² Γ— finset Ξ² β†’ Ξ±)], split, { assume h e he, rcases h e he with ⟨⟨s₁, sβ‚‚βŸ©, h⟩, use [s₁ βˆͺ sβ‚‚], assume t ht, specialize h (s₁ βˆͺ sβ‚‚, (s₁ βˆͺ sβ‚‚) βˆͺ t) ⟨le_sup_left, le_sup_left_of_le le_sup_right⟩, simpa only [finset.sum_union ht.symm, add_sub_cancel'] using h }, { assume h e he, rcases exists_nhds_half_neg he with ⟨d, hd, hde⟩, rcases h d hd with ⟨s, h⟩, use [(s, s)], rintros ⟨t₁, tβ‚‚βŸ© ⟨ht₁, htβ‚‚βŸ©, have : βˆ‘ b in tβ‚‚, f b - βˆ‘ b in t₁, f b = βˆ‘ b in tβ‚‚ \ s, f b - βˆ‘ b in t₁ \ s, f b, { simp only [(finset.sum_sdiff ht₁).symm, (finset.sum_sdiff htβ‚‚).symm, add_sub_add_right_eq_sub] }, simp only [this], exact hde _ _ (h _ finset.sdiff_disjoint) (h _ finset.sdiff_disjoint) } end variable [complete_space Ξ±] lemma summable_iff_vanishing : summable f ↔ βˆ€ e ∈ 𝓝 (0:Ξ±), (βˆƒs:finset Ξ², βˆ€t, disjoint t s β†’ βˆ‘ b in t, f b ∈ e) := by rw [summable_iff_cauchy_seq_finset, cauchy_seq_finset_iff_vanishing] /- TODO: generalize to monoid with a uniform continuous subtraction operator: `(a + b) - b = a` -/ lemma summable.summable_of_eq_zero_or_self (hf : summable f) (h : βˆ€b, g b = 0 ∨ g b = f b) : summable g := summable_iff_vanishing.2 $ assume e he, let ⟨s, hs⟩ := summable_iff_vanishing.1 hf e he in ⟨s, assume t ht, have eq : βˆ‘ b in t.filter (Ξ»b, g b = f b), f b = βˆ‘ b in t, g b := calc βˆ‘ b in t.filter (Ξ»b, g b = f b), f b = βˆ‘ b in t.filter (Ξ»b, g b = f b), g b : finset.sum_congr rfl (assume b hb, (finset.mem_filter.1 hb).2.symm) ... = βˆ‘ b in t, g b : begin refine finset.sum_subset (finset.filter_subset _) _, assume b hbt hb, simp only [(βˆ‰), finset.mem_filter, and_iff_right hbt] at hb, exact (h b).resolve_right hb end, eq β–Έ hs _ $ finset.disjoint_of_subset_left (finset.filter_subset _) ht⟩ protected lemma summable.indicator (hf : summable f) (s : set Ξ²) : summable (s.indicator f) := hf.summable_of_eq_zero_or_self $ Ξ» b, if hb : b ∈ s then or.inr (set.indicator_of_mem hb _) else or.inl (set.indicator_of_not_mem hb _) lemma summable.comp_injective {i : Ξ³ β†’ Ξ²} (hf : summable f) (hi : injective i) : summable (f ∘ i) := begin simpa only [set.indicator_range_comp] using (hi.summable_iff _).2 (hf.indicator (set.range i)), exact Ξ» x hx, set.indicator_of_not_mem hx _ end lemma summable.subtype (hf : summable f) (s : set Ξ²) : summable (f ∘ coe : s β†’ Ξ±) := hf.comp_injective subtype.coe_injective lemma summable.sigma_factor {Ξ³ : Ξ² β†’ Type*} {f : (Ξ£b:Ξ², Ξ³ b) β†’ Ξ±} (ha : summable f) (b : Ξ²) : summable (Ξ»c, f ⟨b, c⟩) := ha.comp_injective sigma_mk_injective lemma summable.sigma [regular_space Ξ±] {Ξ³ : Ξ² β†’ Type*} {f : (Ξ£b:Ξ², Ξ³ b) β†’ Ξ±} (ha : summable f) : summable (Ξ»b, βˆ‘'c, f ⟨b, c⟩) := ha.sigma' (Ξ» b, ha.sigma_factor b) lemma summable.prod_factor {f : Ξ² Γ— Ξ³ β†’ Ξ±} (h : summable f) (b : Ξ²) : summable (Ξ» c, f (b, c)) := h.comp_injective $ Ξ» c₁ cβ‚‚ h, (prod.ext_iff.1 h).2 lemma tsum_sigma [regular_space Ξ±] {Ξ³ : Ξ² β†’ Type*} {f : (Ξ£b:Ξ², Ξ³ b) β†’ Ξ±} (ha : summable f) : (βˆ‘'p, f p) = (βˆ‘'b c, f ⟨b, c⟩) := tsum_sigma' (Ξ» b, ha.sigma_factor b) ha lemma tsum_prod [regular_space Ξ±] {f : Ξ² Γ— Ξ³ β†’ Ξ±} (h : summable f) : (βˆ‘'p, f p) = (βˆ‘'b c, f ⟨b, c⟩) := tsum_prod' h h.prod_factor lemma tsum_comm [regular_space Ξ±] {f : Ξ² β†’ Ξ³ β†’ Ξ±} (h : summable (function.uncurry f)) : (βˆ‘' c b, f b c) = (βˆ‘' b c, f b c) := tsum_comm' h h.prod_factor h.prod_symm.prod_factor end uniform_group section cauchy_seq open finset.Ico filter /-- If the extended distance between consequent points of a sequence is estimated by a summable series of `nnreal`s, then the original sequence is a Cauchy sequence. -/ lemma cauchy_seq_of_edist_le_of_summable [emetric_space Ξ±] {f : β„• β†’ Ξ±} (d : β„• β†’ nnreal) (hf : βˆ€ n, edist (f n) (f n.succ) ≀ d n) (hd : summable d) : cauchy_seq f := begin refine emetric.cauchy_seq_iff_nnreal.2 (Ξ» Ξ΅ Ξ΅pos, _), -- Actually we need partial sums of `d` to be a Cauchy sequence replace hd : cauchy_seq (Ξ» (n : β„•), βˆ‘ x in range n, d x) := let ⟨_, H⟩ := hd in cauchy_seq_of_tendsto_nhds _ H.tendsto_sum_nat, -- Now we take the same `N` as in one of the definitions of a Cauchy sequence refine (metric.cauchy_seq_iff'.1 hd Ξ΅ (nnreal.coe_pos.2 Ξ΅pos)).imp (Ξ» N hN n hn, _), have hsum := hN n hn, -- We simplify the known inequality rw [dist_nndist, nnreal.nndist_eq, ← sum_range_add_sum_Ico _ hn, nnreal.add_sub_cancel'] at hsum, norm_cast at hsum, replace hsum := lt_of_le_of_lt (le_max_left _ _) hsum, rw edist_comm, -- Then use `hf` to simplify the goal to the same form apply lt_of_le_of_lt (edist_le_Ico_sum_of_edist_le hn (Ξ» k _ _, hf k)), assumption_mod_cast end /-- If the distance between consequent points of a sequence is estimated by a summable series, then the original sequence is a Cauchy sequence. -/ lemma cauchy_seq_of_dist_le_of_summable [metric_space Ξ±] {f : β„• β†’ Ξ±} (d : β„• β†’ ℝ) (hf : βˆ€ n, dist (f n) (f n.succ) ≀ d n) (hd : summable d) : cauchy_seq f := begin refine metric.cauchy_seq_iff'.2 (λΡ Ξ΅pos, _), replace hd : cauchy_seq (Ξ» (n : β„•), βˆ‘ x in range n, d x) := let ⟨_, H⟩ := hd in cauchy_seq_of_tendsto_nhds _ H.tendsto_sum_nat, refine (metric.cauchy_seq_iff'.1 hd Ξ΅ Ξ΅pos).imp (Ξ» N hN n hn, _), have hsum := hN n hn, rw [real.dist_eq, ← sum_Ico_eq_sub _ hn] at hsum, calc dist (f n) (f N) = dist (f N) (f n) : dist_comm _ _ ... ≀ βˆ‘ x in Ico N n, d x : dist_le_Ico_sum_of_dist_le hn (Ξ» k _ _, hf k) ... ≀ abs (βˆ‘ x in Ico N n, d x) : le_abs_self _ ... < Ξ΅ : hsum end lemma cauchy_seq_of_summable_dist [metric_space Ξ±] {f : β„• β†’ Ξ±} (h : summable (Ξ»n, dist (f n) (f n.succ))) : cauchy_seq f := cauchy_seq_of_dist_le_of_summable _ (Ξ» _, le_refl _) h lemma dist_le_tsum_of_dist_le_of_tendsto [metric_space Ξ±] {f : β„• β†’ Ξ±} (d : β„• β†’ ℝ) (hf : βˆ€ n, dist (f n) (f n.succ) ≀ d n) (hd : summable d) {a : Ξ±} (ha : tendsto f at_top (𝓝 a)) (n : β„•) : dist (f n) a ≀ βˆ‘' m, d (n + m) := begin refine le_of_tendsto (tendsto_const_nhds.dist ha) (eventually_at_top.2 ⟨n, Ξ» m hnm, _⟩), refine le_trans (dist_le_Ico_sum_of_dist_le hnm (Ξ» k _ _, hf k)) _, rw [sum_Ico_eq_sum_range], refine sum_le_tsum (range _) (Ξ» _ _, le_trans dist_nonneg (hf _)) _, exact hd.comp_injective (add_right_injective n) end lemma dist_le_tsum_of_dist_le_of_tendstoβ‚€ [metric_space Ξ±] {f : β„• β†’ Ξ±} (d : β„• β†’ ℝ) (hf : βˆ€ n, dist (f n) (f n.succ) ≀ d n) (hd : summable d) {a : Ξ±} (ha : tendsto f at_top (𝓝 a)) : dist (f 0) a ≀ tsum d := by simpa only [zero_add] using dist_le_tsum_of_dist_le_of_tendsto d hf hd ha 0 lemma dist_le_tsum_dist_of_tendsto [metric_space Ξ±] {f : β„• β†’ Ξ±} (h : summable (Ξ»n, dist (f n) (f n.succ))) {a : Ξ±} (ha : tendsto f at_top (𝓝 a)) (n) : dist (f n) a ≀ βˆ‘' m, dist (f (n+m)) (f (n+m).succ) := show dist (f n) a ≀ βˆ‘' m, (Ξ»x, dist (f x) (f x.succ)) (n + m), from dist_le_tsum_of_dist_le_of_tendsto (Ξ» n, dist (f n) (f n.succ)) (Ξ» _, le_refl _) h ha n lemma dist_le_tsum_dist_of_tendstoβ‚€ [metric_space Ξ±] {f : β„• β†’ Ξ±} (h : summable (Ξ»n, dist (f n) (f n.succ))) {a : Ξ±} (ha : tendsto f at_top (𝓝 a)) : dist (f 0) a ≀ βˆ‘' n, dist (f n) (f n.succ) := by simpa only [zero_add] using dist_le_tsum_dist_of_tendsto h ha 0 end cauchy_seq
b45bcd5e6b317442e999eb85d6bddf762cb96bf4
022547453607c6244552158ff25ab3bf17361760
/src/linear_algebra/matrix/determinant.lean
3aab1c2c4f3aec4e4e3fafab0d7a91fbc6d245a1
[ "Apache-2.0" ]
permissive
1293045656/mathlib
5f81741a7c1ff1873440ec680b3680bfb6b7b048
4709e61525a60189733e72a50e564c58d534bed8
refs/heads/master
1,687,010,200,553
1,626,245,646,000
1,626,245,646,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
28,555
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Tim Baanen -/ import data.matrix.pequiv import data.matrix.block import data.fintype.card import group_theory.perm.fin import group_theory.perm.sign import algebra.algebra.basic import tactic.ring import linear_algebra.alternating import linear_algebra.pi /-! # Determinant of a matrix This file defines the determinant of a matrix, `matrix.det`, and its essential properties. ## Main definitions - `matrix.det`: the determinant of a square matrix, as a sum over permutations - `matrix.det_row_multilinear`: the determinant, as an `alternating_map` in the rows of the matrix ## Main results - `det_mul`: the determinant of `A ⬝ B` is the product of determinants - `det_zero_of_row_eq`: the determinant is zero if there is a repeated row - `det_block_diagonal`: the determinant of a block diagonal matrix is a product of the blocks' determinants ## Implementation notes It is possible to configure `simp` to compute determinants. See the file `test/matrix.lean` for some examples. -/ universes u v w z open equiv equiv.perm finset function namespace matrix open_locale matrix big_operators variables {m n : Type*} [decidable_eq n] [fintype n] [decidable_eq m] [fintype m] variables {R : Type v} [comm_ring R] local notation `Ξ΅` Οƒ:max := ((sign Οƒ : β„€ ) : R) /-- `det` is an `alternating_map` in the rows of the matrix. -/ def det_row_multilinear : alternating_map R (n β†’ R) R n := ((multilinear_map.mk_pi_algebra R n R).comp_linear_map (linear_map.proj)).alternatization /-- The determinant of a matrix given by the Leibniz formula. -/ abbreviation det (M : matrix n n R) : R := det_row_multilinear M lemma det_apply (M : matrix n n R) : M.det = βˆ‘ Οƒ : perm n, Οƒ.sign β€’ ∏ i, M (Οƒ i) i := multilinear_map.alternatization_apply _ M -- This is what the old definition was. We use it to avoid having to change the old proofs below lemma det_apply' (M : matrix n n R) : M.det = βˆ‘ Οƒ : perm n, Ξ΅ Οƒ * ∏ i, M (Οƒ i) i := by simp [det_apply, units.smul_def] @[simp] lemma det_diagonal {d : n β†’ R} : det (diagonal d) = ∏ i, d i := begin rw det_apply', refine (finset.sum_eq_single 1 _ _).trans _, { intros Οƒ h1 h2, cases not_forall.1 (mt equiv.ext h2) with x h3, convert mul_zero _, apply finset.prod_eq_zero, { change x ∈ _, simp }, exact if_neg h3 }, { simp }, { simp } end @[simp] lemma det_zero (h : nonempty n) : det (0 : matrix n n R) = 0 := (det_row_multilinear : alternating_map R (n β†’ R) R n).map_zero @[simp] lemma det_one : det (1 : matrix n n R) = 1 := by rw [← diagonal_one]; simp [-diagonal_one] lemma det_eq_one_of_card_eq_zero {A : matrix n n R} (h : fintype.card n = 0) : det A = 1 := begin have perm_eq : (univ : finset (perm n)) = {1} := univ_eq_singleton_of_card_one (1 : perm n) (by simp [card_univ, fintype.card_perm, h]), simp [det_apply, card_eq_zero.mp h, perm_eq], end /-- Specialize `det_eq_one_of_card_eq_zero` to `fin 0`. This is especially useful in combination with the `det_succ_` lemmas, for computing the determinant of a matrix given in the `![...]` notation. -/ @[simp] lemma det_fin_zero {A : matrix (fin 0) (fin 0) R}: det A = 1 := det_eq_one_of_card_eq_zero (fintype.card_fin _) /-- If `n` has only one element, the determinant of an `n` by `n` matrix is just that element. Although `unique` implies `decidable_eq` and `fintype`, the instances might not be syntactically equal. Thus, we need to fill in the args explicitly. -/ @[simp] lemma det_unique {n : Type*} [unique n] [decidable_eq n] [fintype n] (A : matrix n n R) : det A = A (default n) (default n) := by simp [det_apply, univ_unique] lemma det_eq_elem_of_card_eq_one {A : matrix n n R} (h : fintype.card n = 1) (k : n) : det A = A k k := begin have h1 : (univ : finset (perm n)) = {1}, { apply univ_eq_singleton_of_card_one (1 : perm n), simp [card_univ, fintype.card_perm, h] }, have h2 := univ_eq_singleton_of_card_one k h, simp [det_apply, h1, h2], end lemma det_mul_aux {M N : matrix n n R} {p : n β†’ n} (H : Β¬bijective p) : βˆ‘ Οƒ : perm n, (Ξ΅ Οƒ) * ∏ x, (M (Οƒ x) (p x) * N (p x) x) = 0 := begin obtain ⟨i, j, hpij, hij⟩ : βˆƒ i j, p i = p j ∧ i β‰  j, { rw [← fintype.injective_iff_bijective, injective] at H, push_neg at H, exact H }, exact sum_involution (Ξ» Οƒ _, Οƒ * swap i j) (Ξ» Οƒ _, have ∏ x, M (Οƒ x) (p x) = ∏ x, M ((Οƒ * swap i j) x) (p x), from fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij]), by simp [this, sign_swap hij, prod_mul_distrib]) (Ξ» Οƒ _ _, (not_congr mul_swap_eq_iff).mpr hij) (Ξ» _ _, mem_univ _) (Ξ» Οƒ _, mul_swap_involutive i j Οƒ) end @[simp] lemma det_mul (M N : matrix n n R) : det (M ⬝ N) = det M * det N := calc det (M ⬝ N) = βˆ‘ p : n β†’ n, βˆ‘ Οƒ : perm n, Ξ΅ Οƒ * ∏ i, (M (Οƒ i) (p i) * N (p i) i) : by simp only [det_apply', mul_apply, prod_univ_sum, mul_sum, fintype.pi_finset_univ]; rw [finset.sum_comm] ... = βˆ‘ p in (@univ (n β†’ n) _).filter bijective, βˆ‘ Οƒ : perm n, Ξ΅ Οƒ * ∏ i, (M (Οƒ i) (p i) * N (p i) i) : eq.symm $ sum_subset (filter_subset _ _) (Ξ» f _ hbij, det_mul_aux $ by simpa only [true_and, mem_filter, mem_univ] using hbij) ... = βˆ‘ Ο„ : perm n, βˆ‘ Οƒ : perm n, Ξ΅ Οƒ * ∏ i, (M (Οƒ i) (Ο„ i) * N (Ο„ i) i) : sum_bij (Ξ» p h, equiv.of_bijective p (mem_filter.1 h).2) (Ξ» _ _, mem_univ _) (Ξ» _ _, rfl) (Ξ» _ _ _ _ h, by injection h) (Ξ» b _, ⟨b, mem_filter.2 ⟨mem_univ _, b.bijective⟩, coe_fn_injective rfl⟩) ... = βˆ‘ Οƒ : perm n, βˆ‘ Ο„ : perm n, (∏ i, N (Οƒ i) i) * Ξ΅ Ο„ * (∏ j, M (Ο„ j) (Οƒ j)) : by simp only [mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc] ... = βˆ‘ Οƒ : perm n, βˆ‘ Ο„ : perm n, (((∏ i, N (Οƒ i) i) * (Ξ΅ Οƒ * Ξ΅ Ο„)) * ∏ i, M (Ο„ i) i) : sum_congr rfl (Ξ» Οƒ _, fintype.sum_equiv (equiv.mul_right σ⁻¹) _ _ (Ξ» Ο„, have ∏ j, M (Ο„ j) (Οƒ j) = ∏ j, M ((Ο„ * σ⁻¹) j) j, by { rw ← σ⁻¹.prod_comp, simp only [equiv.perm.coe_mul, apply_inv_self] }, have h : Ξ΅ Οƒ * Ξ΅ (Ο„ * σ⁻¹) = Ξ΅ Ο„ := calc Ξ΅ Οƒ * Ξ΅ (Ο„ * σ⁻¹) = Ξ΅ ((Ο„ * σ⁻¹) * Οƒ) : by { rw [mul_comm, sign_mul (Ο„ * σ⁻¹)], simp only [int.cast_mul, units.coe_mul] } ... = Ξ΅ Ο„ : by simp only [inv_mul_cancel_right], by { simp_rw [equiv.coe_mul_right, h], simp only [this] })) ... = det M * det N : by simp only [det_apply', finset.mul_sum, mul_comm, mul_left_comm] instance : is_monoid_hom (det : matrix n n R β†’ R) := { map_one := det_one, map_mul := det_mul } /-- On square matrices, `mul_comm` applies under `det`. -/ lemma det_mul_comm (M N : matrix m m R) : det (M ⬝ N) = det (N ⬝ M) := by rw [det_mul, det_mul, mul_comm] /-- On square matrices, `mul_left_comm` applies under `det`. -/ lemma det_mul_left_comm (M N P : matrix m m R) : det (M ⬝ (N ⬝ P)) = det (N ⬝ (M ⬝ P)) := by rw [←matrix.mul_assoc, ←matrix.mul_assoc, det_mul, det_mul_comm M N, ←det_mul] /-- On square matrices, `mul_right_comm` applies under `det`. -/ lemma det_mul_right_comm (M N P : matrix m m R) : det (M ⬝ N ⬝ P) = det (M ⬝ P ⬝ N) := by rw [matrix.mul_assoc, matrix.mul_assoc, det_mul, det_mul_comm N P, ←det_mul] lemma det_units_conj (M : units (matrix m m R)) (N : matrix m m R) : det (↑M ⬝ N ⬝ ↑M⁻¹ : matrix m m R) = det N := by rw [det_mul_right_comm, ←mul_eq_mul, ←mul_eq_mul, units.mul_inv, one_mul] lemma det_units_conj' (M : units (matrix m m R)) (N : matrix m m R) : det (↑M⁻¹ ⬝ N ⬝ ↑M : matrix m m R) = det N := det_units_conj M⁻¹ N /-- Transposing a matrix preserves the determinant. -/ @[simp] lemma det_transpose (M : matrix n n R) : Mα΅€.det = M.det := begin rw [det_apply', det_apply'], refine fintype.sum_bijective _ inv_involutive.bijective _ _ _, intros Οƒ, rw sign_inv, congr' 1, apply fintype.prod_equiv Οƒ, intros, simp end /-- Permuting the columns changes the sign of the determinant. -/ lemma det_permute (Οƒ : perm n) (M : matrix n n R) : matrix.det (Ξ» i, M (Οƒ i)) = Οƒ.sign * M.det := ((det_row_multilinear : alternating_map R (n β†’ R) R n).map_perm M Οƒ).trans (by simp [units.smul_def]) /-- Permuting rows and columns with the same equivalence has no effect. -/ @[simp] lemma det_minor_equiv_self (e : n ≃ m) (A : matrix m m R) : det (A.minor e e) = det A := begin rw [det_apply', det_apply'], apply fintype.sum_equiv (equiv.perm_congr e), intro Οƒ, rw equiv.perm.sign_perm_congr e Οƒ, congr' 1, apply fintype.prod_equiv e, intro i, rw [equiv.perm_congr_apply, equiv.symm_apply_apply, minor_apply], end /-- Reindexing both indices along the same equivalence preserves the determinant. For the `simp` version of this lemma, see `det_minor_equiv_self`; this one is unsuitable because `matrix.reindex_apply` unfolds `reindex` first. -/ lemma det_reindex_self (e : m ≃ n) (A : matrix m m R) : det (reindex e e A) = det A := det_minor_equiv_self e.symm A /-- The determinant of a permutation matrix equals its sign. -/ @[simp] lemma det_permutation (Οƒ : perm n) : matrix.det (Οƒ.to_pequiv.to_matrix : matrix n n R) = Οƒ.sign := by rw [←matrix.mul_one (Οƒ.to_pequiv.to_matrix : matrix n n R), pequiv.to_pequiv_mul_matrix, det_permute, det_one, mul_one] @[simp] lemma det_smul {A : matrix n n R} {c : R} : det (c β€’ A) = c ^ fintype.card n * det A := calc det (c β€’ A) = det (matrix.mul (diagonal (Ξ» _, c)) A) : by rw [smul_eq_diagonal_mul] ... = det (diagonal (Ξ» _, c)) * det A : det_mul _ _ ... = c ^ fintype.card n * det A : by simp [card_univ] /-- Multiplying each row by a fixed `v i` multiplies the determinant by the product of the `v`s. -/ lemma det_mul_row (v : n β†’ R) (A : matrix n n R) : det (Ξ» i j, v j * A i j) = (∏ i, v i) * det A := calc det (Ξ» i j, v j * A i j) = det (A ⬝ diagonal v) : congr_arg det $ by { ext, simp [mul_comm] } ... = (∏ i, v i) * det A : by rw [det_mul, det_diagonal, mul_comm] /-- Multiplying each column by a fixed `v j` multiplies the determinant by the product of the `v`s. -/ lemma det_mul_column (v : n β†’ R) (A : matrix n n R) : det (Ξ» i j, v i * A i j) = (∏ i, v i) * det A := multilinear_map.map_smul_univ _ v A section hom_map variables {S : Type w} [comm_ring S] lemma ring_hom.map_det {M : matrix n n R} {f : R β†’+* S} : f M.det = matrix.det (f.map_matrix M) := by simp [matrix.det_apply', f.map_sum, f.map_prod] lemma alg_hom.map_det [algebra R S] {T : Type z} [comm_ring T] [algebra R T] {M : matrix n n S} {f : S →ₐ[R] T} : f M.det = matrix.det ((f : S β†’+* T).map_matrix M) := by rw [← alg_hom.coe_to_ring_hom, ring_hom.map_det] end hom_map section det_zero /-! ### `det_zero` section Prove that a matrix with a repeated column has determinant equal to zero. -/ lemma det_eq_zero_of_row_eq_zero {A : matrix n n R} (i : n) (h : βˆ€ j, A i j = 0) : det A = 0 := (det_row_multilinear : alternating_map R (n β†’ R) R n).map_coord_zero i (funext h) lemma det_eq_zero_of_column_eq_zero {A : matrix n n R} (j : n) (h : βˆ€ i, A i j = 0) : det A = 0 := by { rw ← det_transpose, exact det_eq_zero_of_row_eq_zero j h, } variables {M : matrix n n R} {i j : n} /-- If a matrix has a repeated row, the determinant will be zero. -/ theorem det_zero_of_row_eq (i_ne_j : i β‰  j) (hij : M i = M j) : M.det = 0 := (det_row_multilinear : alternating_map R (n β†’ R) R n).map_eq_zero_of_eq M hij i_ne_j /-- If a matrix has a repeated column, the determinant will be zero. -/ theorem det_zero_of_column_eq (i_ne_j : i β‰  j) (hij : βˆ€ k, M k i = M k j) : M.det = 0 := by { rw [← det_transpose, det_zero_of_row_eq i_ne_j], exact funext hij } end det_zero lemma det_update_row_add (M : matrix n n R) (j : n) (u v : n β†’ R) : det (update_row M j $ u + v) = det (update_row M j u) + det (update_row M j v) := (det_row_multilinear : alternating_map R (n β†’ R) R n).map_add M j u v lemma det_update_column_add (M : matrix n n R) (j : n) (u v : n β†’ R) : det (update_column M j $ u + v) = det (update_column M j u) + det (update_column M j v) := begin rw [← det_transpose, ← update_row_transpose, det_update_row_add], simp [update_row_transpose, det_transpose] end lemma det_update_row_smul (M : matrix n n R) (j : n) (s : R) (u : n β†’ R) : det (update_row M j $ s β€’ u) = s * det (update_row M j u) := (det_row_multilinear : alternating_map R (n β†’ R) R n).map_smul M j s u lemma det_update_column_smul (M : matrix n n R) (j : n) (s : R) (u : n β†’ R) : det (update_column M j $ s β€’ u) = s * det (update_column M j u) := begin rw [← det_transpose, ← update_row_transpose, det_update_row_smul], simp [update_row_transpose, det_transpose] end section det_eq /-! ### `det_eq` section Lemmas showing the determinant is invariant under a variety of operations. -/ lemma det_eq_of_eq_mul_det_one {A B : matrix n n R} (C : matrix n n R) (hC : det C = 1) (hA : A = B ⬝ C) : det A = det B := calc det A = det (B ⬝ C) : congr_arg _ hA ... = det B * det C : det_mul _ _ ... = det B : by rw [hC, mul_one] lemma det_eq_of_eq_det_one_mul {A B : matrix n n R} (C : matrix n n R) (hC : det C = 1) (hA : A = C ⬝ B) : det A = det B := calc det A = det (C ⬝ B) : congr_arg _ hA ... = det C * det B : det_mul _ _ ... = det B : by rw [hC, one_mul] lemma det_update_row_add_self (A : matrix n n R) {i j : n} (hij : i β‰  j) : det (update_row A i (A i + A j)) = det A := by simp [det_update_row_add, det_zero_of_row_eq hij ((update_row_self).trans (update_row_ne hij.symm).symm)] lemma det_update_column_add_self (A : matrix n n R) {i j : n} (hij : i β‰  j) : det (update_column A i (Ξ» k, A k i + A k j)) = det A := by { rw [← det_transpose, ← update_row_transpose, ← det_transpose A], exact det_update_row_add_self Aα΅€ hij } lemma det_update_row_add_smul_self (A : matrix n n R) {i j : n} (hij : i β‰  j) (c : R) : det (update_row A i (A i + c β€’ A j)) = det A := by simp [det_update_row_add, det_update_row_smul, det_zero_of_row_eq hij ((update_row_self).trans (update_row_ne hij.symm).symm)] lemma det_update_column_add_smul_self (A : matrix n n R) {i j : n} (hij : i β‰  j) (c : R) : det (update_column A i (Ξ» k, A k i + c β€’ A k j)) = det A := by { rw [← det_transpose, ← update_row_transpose, ← det_transpose A], exact det_update_row_add_smul_self Aα΅€ hij c } lemma det_eq_of_forall_row_eq_smul_add_const_aux {A B : matrix n n R} {s : finset n} : βˆ€ (c : n β†’ R) (hs : βˆ€ i, i βˆ‰ s β†’ c i = 0) (k : n) (hk : k βˆ‰ s) (A_eq : βˆ€ i j, A i j = B i j + c i * B k j), det A = det B := begin revert B, refine s.induction_on _ _, { intros A c hs k hk A_eq, have : βˆ€ i, c i = 0, { intros i, specialize hs i, contrapose! hs, simp [hs] }, congr, ext i j, rw [A_eq, this, zero_mul, add_zero], }, { intros i s hi ih B c hs k hk A_eq, have hAi : A i = B i + c i β€’ B k := funext (A_eq i), rw [@ih (update_row B i (A i)) (function.update c i 0), hAi, det_update_row_add_smul_self], { exact mt (Ξ» h, show k ∈ insert i s, from h β–Έ finset.mem_insert_self _ _) hk }, { intros i' hi', rw function.update_apply, split_ifs with hi'i, { refl }, { exact hs i' (Ξ» h, hi' ((finset.mem_insert.mp h).resolve_left hi'i)) } }, { exact Ξ» h, hk (finset.mem_insert_of_mem h) }, { intros i' j', rw [update_row_apply, function.update_apply], split_ifs with hi'i, { simp [hi'i] }, rw [A_eq, update_row_ne (Ξ» (h : k = i), hk $ h β–Έ finset.mem_insert_self k s)] } } end /-- If you add multiples of row `B k` to other rows, the determinant doesn't change. -/ lemma det_eq_of_forall_row_eq_smul_add_const {A B : matrix n n R} (c : n β†’ R) (k : n) (hk : c k = 0) (A_eq : βˆ€ i j, A i j = B i j + c i * B k j) : det A = det B := det_eq_of_forall_row_eq_smul_add_const_aux c (Ξ» i, not_imp_comm.mp $ Ξ» hi, finset.mem_erase.mpr ⟨mt (Ξ» (h : i = k), show c i = 0, from h.symm β–Έ hk) hi, finset.mem_univ i⟩) k (finset.not_mem_erase k finset.univ) A_eq lemma det_eq_of_forall_row_eq_smul_add_pred_aux {n : β„•} (k : fin (n + 1)) : βˆ€ (c : fin n β†’ R) (hc : βˆ€ (i : fin n), k < i.succ β†’ c i = 0) {M N : matrix (fin n.succ) (fin n.succ) R} (h0 : βˆ€ j, M 0 j = N 0 j) (hsucc : βˆ€ (i : fin n) j, M i.succ j = N i.succ j + c i * M i.cast_succ j), det M = det N := begin refine fin.induction _ (Ξ» k ih, _) k; intros c hc M N h0 hsucc, { congr, ext i j, refine fin.cases (h0 j) (Ξ» i, _) i, rw [hsucc, hc i (fin.succ_pos _), zero_mul, add_zero] }, set M' := update_row M k.succ (N k.succ) with hM', have hM : M = update_row M' k.succ (M' k.succ + c k β€’ M k.cast_succ), { ext i j, by_cases hi : i = k.succ, { simp [hi, hM', hsucc, update_row_self] }, rw [update_row_ne hi, hM', update_row_ne hi] }, have k_ne_succ : k.cast_succ β‰  k.succ := (fin.cast_succ_lt_succ k).ne, have M_k : M k.cast_succ = M' k.cast_succ := (update_row_ne k_ne_succ).symm, rw [hM, M_k, det_update_row_add_smul_self M' k_ne_succ.symm, ih (function.update c k 0)], { intros i hi, rw [fin.lt_iff_coe_lt_coe, fin.coe_cast_succ, fin.coe_succ, nat.lt_succ_iff] at hi, rw function.update_apply, split_ifs with hik, { refl }, exact hc _ (fin.succ_lt_succ_iff.mpr (lt_of_le_of_ne hi (ne.symm hik))) }, { rwa [hM', update_row_ne (fin.succ_ne_zero _).symm] }, intros i j, rw function.update_apply, split_ifs with hik, { rw [zero_mul, add_zero, hM', hik, update_row_self] }, rw [hM', update_row_ne ((fin.succ_injective _).ne hik), hsucc], by_cases hik2 : k < i, { simp [hc i (fin.succ_lt_succ_iff.mpr hik2)] }, rw update_row_ne, apply ne_of_lt, rwa [fin.lt_iff_coe_lt_coe, fin.coe_cast_succ, fin.coe_succ, nat.lt_succ_iff, ← not_lt] end /-- If you add multiples of previous rows to the next row, the determinant doesn't change. -/ lemma det_eq_of_forall_row_eq_smul_add_pred {n : β„•} {A B : matrix (fin (n + 1)) (fin (n + 1)) R} (c : fin n β†’ R) (A_zero : βˆ€ j, A 0 j = B 0 j) (A_succ : βˆ€ (i : fin n) j, A i.succ j = B i.succ j + c i * A i.cast_succ j) : det A = det B := det_eq_of_forall_row_eq_smul_add_pred_aux (fin.last _) c (Ξ» i hi, absurd hi (not_lt_of_ge (fin.le_last _))) A_zero A_succ /-- If you add multiples of previous columns to the next columns, the determinant doesn't change. -/ lemma det_eq_of_forall_col_eq_smul_add_pred {n : β„•} {A B : matrix (fin (n + 1)) (fin (n + 1)) R} (c : fin n β†’ R) (A_zero : βˆ€ i, A i 0 = B i 0) (A_succ : βˆ€ i (j : fin n), A i j.succ = B i j.succ + c j * A i j.cast_succ) : det A = det B := by { rw [← det_transpose A, ← det_transpose B], exact det_eq_of_forall_row_eq_smul_add_pred c A_zero (Ξ» i j, A_succ j i) } end det_eq @[simp] lemma det_block_diagonal {o : Type*} [fintype o] [decidable_eq o] (M : o β†’ matrix n n R) : (block_diagonal M).det = ∏ k, (M k).det := begin -- Rewrite the determinants as a sum over permutations. simp_rw [det_apply'], -- The right hand side is a product of sums, rewrite it as a sum of products. rw finset.prod_sum, simp_rw [finset.mem_univ, finset.prod_attach_univ, finset.univ_pi_univ], -- We claim that the only permutations contributing to the sum are those that -- preserve their second component. let preserving_snd : finset (equiv.perm (n Γ— o)) := finset.univ.filter (Ξ» Οƒ, βˆ€ x, (Οƒ x).snd = x.snd), have mem_preserving_snd : βˆ€ {Οƒ : equiv.perm (n Γ— o)}, Οƒ ∈ preserving_snd ↔ βˆ€ x, (Οƒ x).snd = x.snd := Ξ» Οƒ, finset.mem_filter.trans ⟨λ h, h.2, Ξ» h, ⟨finset.mem_univ _, h⟩⟩, rw ← finset.sum_subset (finset.subset_univ preserving_snd) _, -- And that these are in bijection with `o β†’ equiv.perm m`. rw (finset.sum_bij (Ξ» (Οƒ : βˆ€ (k : o), k ∈ finset.univ β†’ equiv.perm n) _, prod_congr_left (Ξ» k, Οƒ k (finset.mem_univ k))) _ _ _ _).symm, { intros Οƒ _, rw mem_preserving_snd, rintros ⟨k, x⟩, simp only [prod_congr_left_apply] }, { intros Οƒ _, rw [finset.prod_mul_distrib, ←finset.univ_product_univ, finset.prod_product, finset.prod_comm], simp only [sign_prod_congr_left, units.coe_prod, int.coe_prod, block_diagonal_apply_eq, prod_congr_left_apply] }, { intros Οƒ Οƒ' _ _ eq, ext x hx k, simp only at eq, have : βˆ€ k x, prod_congr_left (Ξ» k, Οƒ k (finset.mem_univ _)) (k, x) = prod_congr_left (Ξ» k, Οƒ' k (finset.mem_univ _)) (k, x) := Ξ» k x, by rw eq, simp only [prod_congr_left_apply, prod.mk.inj_iff] at this, exact (this k x).1 }, { intros Οƒ hΟƒ, rw mem_preserving_snd at hΟƒ, have hΟƒ' : βˆ€ x, (σ⁻¹ x).snd = x.snd, { intro x, conv_rhs { rw [← perm.apply_inv_self Οƒ x, hΟƒ] } }, have mk_apply_eq : βˆ€ k x, ((Οƒ (x, k)).fst, k) = Οƒ (x, k), { intros k x, ext, { simp only}, { simp only [hΟƒ] } }, have mk_inv_apply_eq : βˆ€ k x, ((σ⁻¹ (x, k)).fst, k) = σ⁻¹ (x, k), { intros k x, conv_lhs { rw ← perm.apply_inv_self Οƒ (x, k) }, ext, { simp only [apply_inv_self] }, { simp only [hΟƒ'] } }, refine ⟨λ k _, ⟨λ x, (Οƒ (x, k)).fst, Ξ» x, (σ⁻¹ (x, k)).fst, _, _⟩, _, _⟩, { intro x, simp only [mk_apply_eq, inv_apply_self] }, { intro x, simp only [mk_inv_apply_eq, apply_inv_self] }, { apply finset.mem_univ }, { ext ⟨k, x⟩, { simp only [coe_fn_mk, prod_congr_left_apply] }, { simp only [prod_congr_left_apply, hΟƒ] } } }, { intros Οƒ _ hΟƒ, rw mem_preserving_snd at hΟƒ, obtain ⟨⟨k, x⟩, hkx⟩ := not_forall.mp hΟƒ, rw [finset.prod_eq_zero (finset.mem_univ (k, x)), mul_zero], rw [← @prod.mk.eta _ _ (Οƒ (k, x)), block_diagonal_apply_ne], exact hkx } end /-- The determinant of a 2x2 block matrix with the lower-left block equal to zero is the product of the determinants of the diagonal blocks. For the generalization to any number of blocks, see `matrix.upper_block_triangular_det`. -/ lemma upper_two_block_triangular_det (A : matrix m m R) (B : matrix m n R) (D : matrix n n R) : (matrix.from_blocks A B 0 D).det = A.det * D.det := begin classical, simp_rw det_apply', convert (sum_subset (subset_univ ((sum_congr_hom m n).range : set (perm (m βŠ• n))).to_finset) _).symm, rw sum_mul_sum, simp_rw univ_product_univ, rw (sum_bij (Ξ» (Οƒ : perm m Γ— perm n) _, equiv.sum_congr Οƒ.fst Οƒ.snd) _ _ _ _).symm, { intros σ₁₂ h, simp only [], erw [set.mem_to_finset, monoid_hom.mem_range], use σ₁₂, simp only [sum_congr_hom_apply] }, { simp only [forall_prop_of_true, prod.forall, mem_univ], intros σ₁ Οƒβ‚‚, rw fintype.prod_sum_type, simp_rw [equiv.sum_congr_apply, sum.map_inr, sum.map_inl, from_blocks_apply₁₁, from_blocks_applyβ‚‚β‚‚], have hr : βˆ€ (a b c d : R), (a * b) * (c * d) = a * c * (b * d), { intros, ac_refl }, rw hr, congr, rw [sign_sum_congr, units.coe_mul, int.cast_mul] }, { intros σ₁ Οƒβ‚‚ h₁ hβ‚‚, dsimp only [], intro h, have h2 : βˆ€ x, perm.sum_congr σ₁.fst σ₁.snd x = perm.sum_congr Οƒβ‚‚.fst Οƒβ‚‚.snd x, { intro x, exact congr_fun (congr_arg to_fun h) x }, simp only [sum.map_inr, sum.map_inl, perm.sum_congr_apply, sum.forall] at h2, ext, { exact h2.left x }, { exact h2.right x }}, { intros Οƒ hΟƒ, erw [set.mem_to_finset, monoid_hom.mem_range] at hΟƒ, obtain βŸ¨Οƒβ‚β‚‚, hΟƒβ‚β‚‚βŸ© := hΟƒ, use σ₁₂, rw ←hσ₁₂, simp }, { intros Οƒ hΟƒ hΟƒn, have h1 : Β¬ (βˆ€ x, βˆƒ y, sum.inl y = Οƒ (sum.inl x)), { by_contradiction, rw set.mem_to_finset at hΟƒn, apply absurd (mem_sum_congr_hom_range_of_perm_maps_to_inl _) hΟƒn, rintros x ⟨a, ha⟩, rw [←ha], exact h a }, obtain ⟨a, ha⟩ := not_forall.mp h1, cases hx : Οƒ (sum.inl a) with a2 b, { have hn := (not_exists.mp ha) a2, exact absurd hx.symm hn }, { rw [finset.prod_eq_zero (finset.mem_univ (sum.inl a)), mul_zero], rw [hx, from_blocks_apply₂₁], refl }} end /-- Laplacian expansion of the determinant of an `n+1 Γ— n+1` matrix along column 0. -/ lemma det_succ_column_zero {n : β„•} (A : matrix (fin n.succ) (fin n.succ) R) : det A = βˆ‘ i : fin n.succ, (-1) ^ (i : β„•) * A i 0 * det (A.minor i.succ_above fin.succ) := begin rw [matrix.det_apply, finset.univ_perm_fin_succ, ← finset.univ_product_univ], simp only [finset.sum_map, equiv.to_embedding_apply, finset.sum_product, matrix.minor], refine finset.sum_congr rfl (Ξ» i _, fin.cases _ (Ξ» i, _) i), { simp only [fin.prod_univ_succ, matrix.det_apply, finset.mul_sum, equiv.perm.decompose_fin_symm_apply_zero, fin.coe_zero, one_mul, equiv.perm.decompose_fin.symm_sign, equiv.swap_self, if_true, id.def, eq_self_iff_true, equiv.perm.decompose_fin_symm_apply_succ, fin.succ_above_zero, equiv.coe_refl, pow_zero, mul_smul_comm] }, -- `univ_perm_fin_succ` gives a different embedding of `perm (fin n)` into -- `perm (fin n.succ)` than the determinant of the submatrix we want, -- permute `A` so that we get the correct one. have : (-1 : R) ^ (i : β„•) = i.cycle_range.sign, { simp [fin.sign_cycle_range] }, rw [fin.coe_succ, pow_succ, this, mul_assoc, mul_assoc, mul_left_comm ↑(equiv.perm.sign _), ← det_permute, matrix.det_apply, finset.mul_sum, finset.mul_sum], -- now we just need to move the corresponding parts to the same place refine finset.sum_congr rfl (Ξ» Οƒ _, _), rw [equiv.perm.decompose_fin.symm_sign, if_neg (fin.succ_ne_zero i)], calc ((-1) * Οƒ.sign : β„€) β€’ ∏ i', A (equiv.perm.decompose_fin.symm (fin.succ i, Οƒ) i') i' = ((-1) * Οƒ.sign : β„€) β€’ (A (fin.succ i) 0 * ∏ i', A (((fin.succ i).succ_above) (fin.cycle_range i (Οƒ i'))) i'.succ) : by simp only [fin.prod_univ_succ, fin.succ_above_cycle_range, equiv.perm.decompose_fin_symm_apply_zero, equiv.perm.decompose_fin_symm_apply_succ] ... = (-1) * (A (fin.succ i) 0 * (Οƒ.sign : β„€) β€’ ∏ i', A (((fin.succ i).succ_above) (fin.cycle_range i (Οƒ i'))) i'.succ) : by simp only [mul_assoc, mul_comm, neg_mul_eq_neg_mul_symm, one_mul, gsmul_eq_mul, neg_inj, neg_smul, fin.succ_above_cycle_range], end /-- Laplacian expansion of the determinant of an `n+1 Γ— n+1` matrix along row 0. -/ lemma det_succ_row_zero {n : β„•} (A : matrix (fin n.succ) (fin n.succ) R) : det A = βˆ‘ j : fin n.succ, (-1) ^ (j : β„•) * A 0 j * det (A.minor fin.succ j.succ_above) := by { rw [← det_transpose A, det_succ_column_zero], refine finset.sum_congr rfl (Ξ» i _, _), rw [← det_transpose], simp only [transpose_apply, transpose_minor, transpose_transpose] } /-- Laplacian expansion of the determinant of an `n+1 Γ— n+1` matrix along row `i`. -/ lemma det_succ_row {n : β„•} (A : matrix (fin n.succ) (fin n.succ) R) (i : fin n.succ) : det A = βˆ‘ j : fin n.succ, (-1) ^ (i + j : β„•) * A i j * det (A.minor i.succ_above j.succ_above) := begin simp_rw [pow_add, mul_assoc, ← mul_sum], have : det A = (-1 : R) ^ (i : β„•) * (i.cycle_range⁻¹).sign * det A, { calc det A = ↑((-1 : units β„€) ^ (i : β„•) * (-1 : units β„€) ^ (i : β„•) : units β„€) * det A : by simp ... = (-1 : R) ^ (i : β„•) * (i.cycle_range⁻¹).sign * det A : by simp [-int.units_mul_self] }, rw [this, mul_assoc], congr, rw [← det_permute, det_succ_row_zero], refine finset.sum_congr rfl (Ξ» j _, _), rw [mul_assoc, matrix.minor, matrix.minor], congr, { rw [equiv.perm.inv_def, fin.cycle_range_symm_zero] }, { ext i' j', rw [equiv.perm.inv_def, fin.cycle_range_symm_succ] }, end /-- Laplacian expansion of the determinant of an `n+1 Γ— n+1` matrix along column `j`. -/ lemma det_succ_column {n : β„•} (A : matrix (fin n.succ) (fin n.succ) R) (j : fin n.succ) : det A = βˆ‘ i : fin n.succ, (-1) ^ (i + j : β„•) * A i j * det (A.minor i.succ_above j.succ_above) := by { rw [← det_transpose, det_succ_row _ j], refine finset.sum_congr rfl (Ξ» i _, _), rw [add_comm, ← det_transpose, transpose_apply, transpose_minor, transpose_transpose] } end matrix
0615e50bae91818b48d175cdb4d8f6bfc2412925
d1a52c3f208fa42c41df8278c3d280f075eb020c
/stage0/src/Lean/Elab/PreDefinition/Structural/Main.lean
02c64db0379ab35835df25c840f2be83fc67bfac
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
cipher1024/lean4
6e1f98bb58e7a92b28f5364eb38a14c8d0aae393
69114d3b50806264ef35b57394391c3e738a9822
refs/heads/master
1,642,227,983,603
1,642,011,696,000
1,642,011,696,000
228,607,691
0
0
Apache-2.0
1,576,584,269,000
1,576,584,268,000
null
UTF-8
Lean
false
false
4,282
lean
/- Copyright (c) 2021 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Elab.PreDefinition.Structural.Basic import Lean.Elab.PreDefinition.Structural.FindRecArg import Lean.Elab.PreDefinition.Structural.Preprocess import Lean.Elab.PreDefinition.Structural.BRecOn import Lean.Elab.PreDefinition.Structural.IndPred import Lean.Elab.PreDefinition.Structural.Eqns import Lean.Elab.PreDefinition.Structural.SmartUnfolding namespace Lean.Elab namespace Structural open Meta private def getFixedPrefix (declName : Name) (xs : Array Expr) (value : Expr) : MetaM Nat := do let numFixedRef ← IO.mkRef xs.size forEachExpr' value fun e => do if e.isAppOf declName then let args := e.getAppArgs numFixedRef.modify fun numFixed => if args.size < numFixed then args.size else numFixed for arg in args, x in xs do /- We should not use structural equality here. For example, given the definition ``` def V.map {Ξ± Ξ²} f x x_1 := @V.map.match_1.{1} Ξ± (fun x x_2 => V Ξ² x) x x_1 (fun x x_2 => @V.mk₁ Ξ² x (f Bool.true x_2)) (fun e => @V.mkβ‚‚ Ξ² (V.map (fun b => Ξ± b) (fun b => Ξ² b) f Bool.false e)) ``` The first three arguments at `V.map (fun b => Ξ± b) (fun b => Ξ² b) f Bool.false e` are "fixed" modulo definitional equality. We disable to proof irrelevance to be able to use structural recursion on inductive predicates. For example, consider the example ``` inductive PList (Ξ± : Type) : Prop | nil | cons : Ξ± β†’ PList Ξ± β†’ PList Ξ± infixr:67 " ::: " => PList.cons set_option trace.Elab.definition.structural true in def pmap {Ξ± Ξ²} (f : Ξ± β†’ Ξ²) : PList Ξ± β†’ PList Ξ² | PList.nil => PList.nil | a:::as => f a ::: pmap f as ``` The "Fixed" prefix would be 4 since all elements of type `PList Ξ±` are definitionally equal. -/ if !(← withoutProofIrrelevance <| withReducible <| isDefEq arg x) then -- We continue searching if e's arguments are not a prefix of `xs` return true return false else return true numFixedRef.get private def elimRecursion (preDef : PreDefinition) : M (Nat Γ— PreDefinition) := do trace[Elab.definition.structural] "{preDef.declName} := {preDef.value}" withoutModifyingEnv do lambdaTelescope preDef.value fun xs value => do addAsAxiom preDef let value ← preprocess value preDef.declName trace[Elab.definition.structural] "{preDef.declName} {xs} :=\n{value}" let numFixed ← getFixedPrefix preDef.declName xs value trace[Elab.definition.structural] "numFixed: {numFixed}" findRecArg numFixed xs fun recArgInfo => do -- when (recArgInfo.indName == `Nat) throwStructuralFailed -- HACK to skip Nat argument let valueNew ← if recArgInfo.indPred then mkIndPredBRecOn preDef.declName recArgInfo value else mkBRecOn preDef.declName recArgInfo value let valueNew ← mkLambdaFVars xs valueNew trace[Elab.definition.structural] "result: {valueNew}" -- Recursive applications may still occur in expressions that were not visited by replaceRecApps (e.g., in types) let valueNew ← ensureNoRecFn preDef.declName valueNew let recArgPos := recArgInfo.fixedParams.size + recArgInfo.pos return (recArgPos, { preDef with value := valueNew }) def structuralRecursion (preDefs : Array PreDefinition) : TermElabM Unit := if preDefs.size != 1 then throwError "structural recursion does not handle mutually recursive functions" else do let ((recArgPos, preDefNonRec), state) ← run <| elimRecursion preDefs[0] state.addMatchers.forM liftM mapError (addNonRec preDefNonRec) (fun msg => m!"structural recursion failed, produced type incorrect term{indentD msg}") addAndCompilePartialRec preDefs addSmartUnfoldingDef preDefs[0] recArgPos registerEqnsInfo preDefs[0] recArgPos builtin_initialize registerTraceClass `Elab.definition.structural end Structural export Structural (structuralRecursion) end Lean.Elab
44b58fd3989ce3e28c5100a82c035bdc4852c03f
22e97a5d648fc451e25a06c668dc03ac7ed7bc25
/src/data/num/lemmas.lean
be2f1868cf5c5641226be3ae70c581492576d0b9
[ "Apache-2.0" ]
permissive
keeferrowan/mathlib
f2818da875dbc7780830d09bd4c526b0764a4e50
aad2dfc40e8e6a7e258287a7c1580318e865817e
refs/heads/master
1,661,736,426,952
1,590,438,032,000
1,590,438,032,000
266,892,663
0
0
Apache-2.0
1,590,445,835,000
1,590,445,835,000
null
UTF-8
Lean
false
false
50,219
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro Properties of the binary representation of integers. -/ import data.num.bitwise import data.int.basic import data.nat.gcd local attribute [simp] add_assoc namespace pos_num variables {Ξ± : Type*} @[simp, norm_cast] theorem cast_one [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] : ((1 : pos_num) : Ξ±) = 1 := rfl @[simp] theorem cast_one' [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] : (pos_num.one : Ξ±) = 1 := rfl @[simp, norm_cast] theorem cast_bit0 [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] (n : pos_num) : (n.bit0 : Ξ±) = _root_.bit0 n := rfl @[simp, norm_cast] theorem cast_bit1 [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] (n : pos_num) : (n.bit1 : Ξ±) = _root_.bit1 n := rfl @[simp, norm_cast] theorem cast_to_nat [add_monoid Ξ±] [has_one Ξ±] : βˆ€ n : pos_num, ((n : β„•) : Ξ±) = n | 1 := nat.cast_one | (bit0 p) := (nat.cast_bit0 _).trans $ congr_arg _root_.bit0 p.cast_to_nat | (bit1 p) := (nat.cast_bit1 _).trans $ congr_arg _root_.bit1 p.cast_to_nat @[simp, norm_cast] theorem to_nat_to_int (n : pos_num) : ((n : β„•) : β„€) = n := by rw [← int.nat_cast_eq_coe_nat, cast_to_nat] @[simp, norm_cast] theorem cast_to_int [add_group Ξ±] [has_one Ξ±] (n : pos_num) : ((n : β„€) : Ξ±) = n := by rw [← to_nat_to_int, int.cast_coe_nat, cast_to_nat] theorem succ_to_nat : βˆ€ n, (succ n : β„•) = n + 1 | 1 := rfl | (bit0 p) := rfl | (bit1 p) := (congr_arg _root_.bit0 (succ_to_nat p)).trans $ show ↑p + 1 + ↑p + 1 = ↑p + ↑p + 1 + 1, by simp [add_left_comm] theorem one_add (n : pos_num) : 1 + n = succ n := by cases n; refl theorem add_one (n : pos_num) : n + 1 = succ n := by cases n; refl @[norm_cast] theorem add_to_nat : βˆ€ m n, ((m + n : pos_num) : β„•) = m + n | 1 b := by rw [one_add b, succ_to_nat, add_comm]; refl | a 1 := by rw [add_one a, succ_to_nat]; refl | (bit0 a) (bit0 b) := (congr_arg _root_.bit0 (add_to_nat a b)).trans $ show ((a + b) + (a + b) : β„•) = (a + a) + (b + b), by simp [add_left_comm] | (bit0 a) (bit1 b) := (congr_arg _root_.bit1 (add_to_nat a b)).trans $ show ((a + b) + (a + b) + 1 : β„•) = (a + a) + (b + b + 1), by simp [add_left_comm] | (bit1 a) (bit0 b) := (congr_arg _root_.bit1 (add_to_nat a b)).trans $ show ((a + b) + (a + b) + 1 : β„•) = (a + a + 1) + (b + b), by simp [add_comm, add_left_comm] | (bit1 a) (bit1 b) := show (succ (a + b) + succ (a + b) : β„•) = (a + a + 1) + (b + b + 1), by rw [succ_to_nat, add_to_nat]; simp [add_left_comm] theorem add_succ : βˆ€ (m n : pos_num), m + succ n = succ (m + n) | 1 b := by simp [one_add] | (bit0 a) 1 := congr_arg bit0 (add_one a) | (bit1 a) 1 := congr_arg bit1 (add_one a) | (bit0 a) (bit0 b) := rfl | (bit0 a) (bit1 b) := congr_arg bit0 (add_succ a b) | (bit1 a) (bit0 b) := rfl | (bit1 a) (bit1 b) := congr_arg bit1 (add_succ a b) theorem bit0_of_bit0 : Ξ  n, _root_.bit0 n = bit0 n | 1 := rfl | (bit0 p) := congr_arg bit0 (bit0_of_bit0 p) | (bit1 p) := show bit0 (succ (_root_.bit0 p)) = _, by rw bit0_of_bit0; refl theorem bit1_of_bit1 (n : pos_num) : _root_.bit1 n = bit1 n := show _root_.bit0 n + 1 = bit1 n, by rw [add_one, bit0_of_bit0]; refl @[norm_cast] theorem mul_to_nat (m) : βˆ€ n, ((m * n : pos_num) : β„•) = m * n | 1 := (mul_one _).symm | (bit0 p) := show (↑(m * p) + ↑(m * p) : β„•) = ↑m * (p + p), by rw [mul_to_nat, left_distrib] | (bit1 p) := (add_to_nat (bit0 (m * p)) m).trans $ show (↑(m * p) + ↑(m * p) + ↑m : β„•) = ↑m * (p + p) + m, by rw [mul_to_nat, left_distrib] theorem to_nat_pos : βˆ€ n : pos_num, 0 < (n : β„•) | 1 := zero_lt_one | (bit0 p) := let h := to_nat_pos p in add_pos h h | (bit1 p) := nat.succ_pos _ theorem cmp_to_nat_lemma {m n : pos_num} : (m:β„•) < n β†’ (bit1 m : β„•) < bit0 n := show (m:β„•) < n β†’ (m + m + 1 + 1 : β„•) ≀ n + n, by intro h; rw [nat.add_right_comm m m 1, add_assoc]; exact add_le_add h h theorem cmp_swap (m) : βˆ€n, (cmp m n).swap = cmp n m := by induction m with m IH m IH; intro n; cases n with n n; try {unfold cmp}; try {refl}; rw ←IH; cases cmp m n; refl theorem cmp_to_nat : βˆ€ (m n), (ordering.cases_on (cmp m n) ((m:β„•) < n) (m = n) ((m:β„•) > n) : Prop) | 1 1 := rfl | (bit0 a) 1 := let h : (1:β„•) ≀ a := to_nat_pos a in add_le_add h h | (bit1 a) 1 := nat.succ_lt_succ $ to_nat_pos $ bit0 a | 1 (bit0 b) := let h : (1:β„•) ≀ b := to_nat_pos b in add_le_add h h | 1 (bit1 b) := nat.succ_lt_succ $ to_nat_pos $ bit0 b | (bit0 a) (bit0 b) := begin have := cmp_to_nat a b, revert this, cases cmp a b; dsimp; intro, { exact add_lt_add this this }, { rw this }, { exact add_lt_add this this } end | (bit0 a) (bit1 b) := begin dsimp [cmp], have := cmp_to_nat a b, revert this, cases cmp a b; dsimp; intro, { exact nat.le_succ_of_le (add_lt_add this this) }, { rw this, apply nat.lt_succ_self }, { exact cmp_to_nat_lemma this } end | (bit1 a) (bit0 b) := begin dsimp [cmp], have := cmp_to_nat a b, revert this, cases cmp a b; dsimp; intro, { exact cmp_to_nat_lemma this }, { rw this, apply nat.lt_succ_self }, { exact nat.le_succ_of_le (add_lt_add this this) }, end | (bit1 a) (bit1 b) := begin have := cmp_to_nat a b, revert this, cases cmp a b; dsimp; intro, { exact nat.succ_lt_succ (add_lt_add this this) }, { rw this }, { exact nat.succ_lt_succ (add_lt_add this this) } end @[norm_cast] theorem lt_to_nat {m n : pos_num} : (m:β„•) < n ↔ m < n := show (m:β„•) < n ↔ cmp m n = ordering.lt, from match cmp m n, cmp_to_nat m n with | ordering.lt, h := by simp at h; simp [h] | ordering.eq, h := by simp at h; simp [h, lt_irrefl]; exact dec_trivial | ordering.gt, h := by simp [not_lt_of_gt h]; exact dec_trivial end @[norm_cast] theorem le_to_nat {m n : pos_num} : (m:β„•) ≀ n ↔ m ≀ n := by rw ← not_lt; exact not_congr lt_to_nat end pos_num namespace num variables {Ξ± : Type*} open pos_num theorem add_zero (n : num) : n + 0 = n := by cases n; refl theorem zero_add (n : num) : 0 + n = n := by cases n; refl theorem add_one : βˆ€ n : num, n + 1 = succ n | 0 := rfl | (pos p) := by cases p; refl theorem add_succ : βˆ€ (m n : num), m + succ n = succ (m + n) | 0 n := by simp [zero_add] | (pos p) 0 := show pos (p + 1) = succ (pos p + 0), by rw [pos_num.add_one, add_zero]; refl | (pos p) (pos q) := congr_arg pos (pos_num.add_succ _ _) @[simp, norm_cast] theorem add_of_nat (m) : βˆ€ n, ((m + n : β„•) : num) = m + n | 0 := (add_zero _).symm | (n+1) := show ((m + n : β„•) + 1 : num) = m + (↑ n + 1), by rw [add_one, add_one, add_succ, add_of_nat] theorem bit0_of_bit0 : βˆ€ n : num, bit0 n = n.bit0 | 0 := rfl | (pos p) := congr_arg pos p.bit0_of_bit0 theorem bit1_of_bit1 : βˆ€ n : num, bit1 n = n.bit1 | 0 := rfl | (pos p) := congr_arg pos p.bit1_of_bit1 @[simp, norm_cast] theorem cast_zero [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] : ((0 : num) : Ξ±) = 0 := rfl @[simp] theorem cast_zero' [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] : (num.zero : Ξ±) = 0 := rfl @[simp, norm_cast] theorem cast_one [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] : ((1 : num) : Ξ±) = 1 := rfl @[simp] theorem cast_pos [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] (n : pos_num) : (num.pos n : Ξ±) = n := rfl theorem succ'_to_nat : βˆ€ n, (succ' n : β„•) = n + 1 | 0 := (_root_.zero_add _).symm | (pos p) := pos_num.succ_to_nat _ theorem succ_to_nat (n) : (succ n : β„•) = n + 1 := succ'_to_nat n @[simp, norm_cast] theorem cast_to_nat [add_monoid Ξ±] [has_one Ξ±] : βˆ€ n : num, ((n : β„•) : Ξ±) = n | 0 := nat.cast_zero | (pos p) := p.cast_to_nat @[simp, norm_cast] theorem to_nat_to_int (n : num) : ((n : β„•) : β„€) = n := by rw [← int.nat_cast_eq_coe_nat, cast_to_nat] @[simp, norm_cast] theorem cast_to_int [add_group Ξ±] [has_one Ξ±] (n : num) : ((n : β„€) : Ξ±) = n := by rw [← to_nat_to_int, int.cast_coe_nat, cast_to_nat] @[norm_cast] theorem to_of_nat : Ξ  (n : β„•), ((n : num) : β„•) = n | 0 := rfl | (n+1) := by rw [nat.cast_add_one, add_one, succ_to_nat, to_of_nat] @[simp, norm_cast] theorem of_nat_cast [add_monoid Ξ±] [has_one Ξ±] (n : β„•) : ((n : num) : Ξ±) = n := by rw [← cast_to_nat, to_of_nat] @[norm_cast] theorem of_nat_inj {m n : β„•} : (m : num) = n ↔ m = n := ⟨λ h, function.left_inverse.injective to_of_nat h, congr_arg _⟩ @[norm_cast] theorem add_to_nat : βˆ€ m n, ((m + n : num) : β„•) = m + n | 0 0 := rfl | 0 (pos q) := (_root_.zero_add _).symm | (pos p) 0 := rfl | (pos p) (pos q) := pos_num.add_to_nat _ _ @[norm_cast] theorem mul_to_nat : βˆ€ m n, ((m * n : num) : β„•) = m * n | 0 0 := rfl | 0 (pos q) := (zero_mul _).symm | (pos p) 0 := rfl | (pos p) (pos q) := pos_num.mul_to_nat _ _ theorem cmp_to_nat : βˆ€ (m n), (ordering.cases_on (cmp m n) ((m:β„•) < n) (m = n) ((m:β„•) > n) : Prop) | 0 0 := rfl | 0 (pos b) := to_nat_pos _ | (pos a) 0 := to_nat_pos _ | (pos a) (pos b) := by { have := pos_num.cmp_to_nat a b; revert this; dsimp [cmp]; cases pos_num.cmp a b, exacts [id, congr_arg pos, id] } @[norm_cast] theorem lt_to_nat {m n : num} : (m:β„•) < n ↔ m < n := show (m:β„•) < n ↔ cmp m n = ordering.lt, from match cmp m n, cmp_to_nat m n with | ordering.lt, h := by simp at h; simp [h] | ordering.eq, h := by simp at h; simp [h, lt_irrefl]; exact dec_trivial | ordering.gt, h := by simp [not_lt_of_gt h]; exact dec_trivial end @[norm_cast] theorem le_to_nat {m n : num} : (m:β„•) ≀ n ↔ m ≀ n := by rw ← not_lt; exact not_congr lt_to_nat end num namespace pos_num @[simp] theorem of_to_nat : Ξ  (n : pos_num), ((n : β„•) : num) = num.pos n | 1 := rfl | (bit0 p) := show ↑(p + p : β„•) = num.pos p.bit0, by rw [num.add_of_nat, of_to_nat]; exact congr_arg num.pos p.bit0_of_bit0 | (bit1 p) := show ((p + p : β„•) : num) + 1 = num.pos p.bit1, by rw [num.add_of_nat, of_to_nat]; exact congr_arg num.pos p.bit1_of_bit1 end pos_num namespace num @[simp, norm_cast] theorem of_to_nat : Ξ  (n : num), ((n : β„•) : num) = n | 0 := rfl | (pos p) := p.of_to_nat @[norm_cast] theorem to_nat_inj {m n : num} : (m : β„•) = n ↔ m = n := ⟨λ h, function.left_inverse.injective of_to_nat h, congr_arg _⟩ meta def transfer_rw : tactic unit := `[repeat {rw ← to_nat_inj <|> rw ← lt_to_nat <|> rw ← le_to_nat}, repeat {rw add_to_nat <|> rw mul_to_nat <|> rw cast_one <|> rw cast_zero}] meta def transfer : tactic unit := `[intros, transfer_rw, try {simp}] instance : comm_semiring num := by refine { add := (+), zero := 0, zero_add := zero_add, add_zero := add_zero, mul := (*), one := 1, .. }; try {transfer}; simp [mul_add, mul_left_comm, mul_comm, add_comm] instance : ordered_cancel_add_comm_monoid num := { add_left_cancel := by {intros a b c, transfer_rw, apply add_left_cancel}, add_right_cancel := by {intros a b c, transfer_rw, apply add_right_cancel}, lt := (<), lt_iff_le_not_le := by {intros a b, transfer_rw, apply lt_iff_le_not_le}, le := (≀), le_refl := by transfer, le_trans := by {intros a b c, transfer_rw, apply le_trans}, le_antisymm := by {intros a b, transfer_rw, apply le_antisymm}, add_le_add_left := by {intros a b h c, revert h, transfer_rw, exact Ξ» h, add_le_add_left h c}, le_of_add_le_add_left := by {intros a b c, transfer_rw, apply le_of_add_le_add_left}, ..num.comm_semiring } instance : decidable_linear_ordered_semiring num := { le_total := by {intros a b, transfer_rw, apply le_total}, zero_lt_one := dec_trivial, mul_lt_mul_of_pos_left := by {intros a b c, transfer_rw, apply mul_lt_mul_of_pos_left}, mul_lt_mul_of_pos_right := by {intros a b c, transfer_rw, apply mul_lt_mul_of_pos_right}, decidable_lt := num.decidable_lt, decidable_le := num.decidable_le, decidable_eq := num.decidable_eq, ..num.comm_semiring, ..num.ordered_cancel_add_comm_monoid } @[norm_cast] theorem dvd_to_nat (m n : num) : (m : β„•) ∣ n ↔ m ∣ n := ⟨λ ⟨k, e⟩, ⟨k, by rw [← of_to_nat n, e]; simp⟩, Ξ» ⟨k, e⟩, ⟨k, by simp [e, mul_to_nat]⟩⟩ end num namespace pos_num variables {Ξ± : Type*} open num @[norm_cast] theorem to_nat_inj {m n : pos_num} : (m : β„•) = n ↔ m = n := ⟨λ h, num.pos.inj $ by rw [← pos_num.of_to_nat, ← pos_num.of_to_nat, h], congr_arg _⟩ theorem pred'_to_nat : βˆ€ n, (pred' n : β„•) = nat.pred n | 1 := rfl | (bit0 n) := have nat.succ ↑(pred' n) = ↑n, by rw [pred'_to_nat n, nat.succ_pred_eq_of_pos (to_nat_pos n)], match pred' n, this : βˆ€ k : num, nat.succ ↑k = ↑n β†’ ↑(num.cases_on k 1 bit1 : pos_num) = nat.pred (_root_.bit0 n) with | 0, (h : ((1:num):β„•) = n) := by rw ← to_nat_inj.1 h; refl | num.pos p, (h : nat.succ ↑p = n) := by rw ← h; exact (nat.succ_add p p).symm end | (bit1 n) := rfl @[simp] theorem pred'_succ' (n) : pred' (succ' n) = n := num.to_nat_inj.1 $ by rw [pred'_to_nat, succ'_to_nat, nat.add_one, nat.pred_succ] @[simp] theorem succ'_pred' (n) : succ' (pred' n) = n := to_nat_inj.1 $ by rw [succ'_to_nat, pred'_to_nat, nat.add_one, nat.succ_pred_eq_of_pos (to_nat_pos _)] theorem size_to_nat : βˆ€ n, (size n : β„•) = nat.size n | 1 := nat.size_one.symm | (bit0 n) := by rw [size, succ_to_nat, size_to_nat, cast_bit0, nat.size_bit0 $ ne_of_gt $ to_nat_pos n] | (bit1 n) := by rw [size, succ_to_nat, size_to_nat, cast_bit1, nat.size_bit1] theorem size_eq_nat_size : βˆ€ n, (size n : β„•) = nat_size n | 1 := rfl | (bit0 n) := by rw [size, succ_to_nat, nat_size, size_eq_nat_size] | (bit1 n) := by rw [size, succ_to_nat, nat_size, size_eq_nat_size] theorem nat_size_to_nat (n) : nat_size n = nat.size n := by rw [← size_eq_nat_size, size_to_nat] theorem nat_size_pos (n) : 0 < nat_size n := by cases n; apply nat.succ_pos meta def transfer_rw : tactic unit := `[repeat {rw ← to_nat_inj <|> rw ← lt_to_nat <|> rw ← le_to_nat}, repeat {rw add_to_nat <|> rw mul_to_nat <|> rw cast_one <|> rw cast_zero}] meta def transfer : tactic unit := `[intros, transfer_rw, try {simp [add_comm, add_left_comm, mul_comm, mul_left_comm]}] instance : add_comm_semigroup pos_num := by refine {add := (+), ..}; transfer instance : comm_monoid pos_num := by refine {mul := (*), one := 1, ..}; transfer instance : distrib pos_num := by refine {add := (+), mul := (*), ..}; {transfer, simp [mul_add, mul_comm]} instance : decidable_linear_order pos_num := { lt := (<), lt_iff_le_not_le := by {intros a b, transfer_rw, apply lt_iff_le_not_le}, le := (≀), le_refl := by transfer, le_trans := by {intros a b c, transfer_rw, apply le_trans}, le_antisymm := by {intros a b, transfer_rw, apply le_antisymm}, le_total := by {intros a b, transfer_rw, apply le_total}, decidable_lt := by apply_instance, decidable_le := by apply_instance, decidable_eq := by apply_instance } @[simp] theorem cast_to_num (n : pos_num) : ↑n = num.pos n := by rw [← cast_to_nat, ← of_to_nat n] @[simp, norm_cast] theorem bit_to_nat (b n) : (bit b n : β„•) = nat.bit b n := by cases b; refl @[simp, norm_cast] theorem cast_add [add_monoid Ξ±] [has_one Ξ±] (m n) : ((m + n : pos_num) : Ξ±) = m + n := by rw [← cast_to_nat, add_to_nat, nat.cast_add, cast_to_nat, cast_to_nat] @[simp, norm_cast, priority 500] theorem cast_succ [add_monoid Ξ±] [has_one Ξ±] (n : pos_num) : (succ n : Ξ±) = n + 1 := by rw [← add_one, cast_add, cast_one] @[simp, norm_cast] theorem cast_inj [add_monoid Ξ±] [has_one Ξ±] [char_zero Ξ±] {m n : pos_num} : (m:Ξ±) = n ↔ m = n := by rw [← cast_to_nat m, ← cast_to_nat n, nat.cast_inj, to_nat_inj] @[simp] theorem one_le_cast [linear_ordered_semiring Ξ±] (n : pos_num) : (1 : Ξ±) ≀ n := by rw [← cast_to_nat, ← nat.cast_one, nat.cast_le]; apply to_nat_pos @[simp] theorem cast_pos [linear_ordered_semiring Ξ±] (n : pos_num) : 0 < (n : Ξ±) := lt_of_lt_of_le zero_lt_one (one_le_cast n) @[simp, norm_cast] theorem cast_mul [semiring Ξ±] (m n) : ((m * n : pos_num) : Ξ±) = m * n := by rw [← cast_to_nat, mul_to_nat, nat.cast_mul, cast_to_nat, cast_to_nat] @[simp] theorem cmp_eq (m n) : cmp m n = ordering.eq ↔ m = n := begin have := cmp_to_nat m n, cases cmp m n; simp at this ⊒; try {exact this}; { simp [show m β‰  n, from Ξ» e, by rw e at this; exact lt_irrefl _ this] } end @[simp, norm_cast] theorem cast_lt [linear_ordered_semiring Ξ±] {m n : pos_num} : (m:Ξ±) < n ↔ m < n := by rw [← cast_to_nat m, ← cast_to_nat n, nat.cast_lt, lt_to_nat] @[simp, norm_cast] theorem cast_le [linear_ordered_semiring Ξ±] {m n : pos_num} : (m:Ξ±) ≀ n ↔ m ≀ n := by rw ← not_lt; exact not_congr cast_lt end pos_num namespace num variables {Ξ± : Type*} open pos_num theorem bit_to_nat (b n) : (bit b n : β„•) = nat.bit b n := by cases b; cases n; refl theorem cast_succ' [add_monoid Ξ±] [has_one Ξ±] (n) : (succ' n : Ξ±) = n + 1 := by rw [← pos_num.cast_to_nat, succ'_to_nat, nat.cast_add_one, cast_to_nat] theorem cast_succ [add_monoid Ξ±] [has_one Ξ±] (n) : (succ n : Ξ±) = n + 1 := cast_succ' n @[simp, norm_cast] theorem cast_add [semiring Ξ±] (m n) : ((m + n : num) : Ξ±) = m + n := by rw [← cast_to_nat, add_to_nat, nat.cast_add, cast_to_nat, cast_to_nat] @[simp, norm_cast] theorem cast_bit0 [semiring Ξ±] (n : num) : (n.bit0 : Ξ±) = _root_.bit0 n := by rw [← bit0_of_bit0, _root_.bit0, cast_add]; refl @[simp, norm_cast] theorem cast_bit1 [semiring Ξ±] (n : num) : (n.bit1 : Ξ±) = _root_.bit1 n := by rw [← bit1_of_bit1, _root_.bit1, bit0_of_bit0, cast_add, cast_bit0]; refl @[simp, norm_cast] theorem cast_mul [semiring Ξ±] : βˆ€ m n, ((m * n : num) : Ξ±) = m * n | 0 0 := (zero_mul _).symm | 0 (pos q) := (zero_mul _).symm | (pos p) 0 := (mul_zero _).symm | (pos p) (pos q) := pos_num.cast_mul _ _ theorem size_to_nat : βˆ€ n, (size n : β„•) = nat.size n | 0 := nat.size_zero.symm | (pos p) := p.size_to_nat theorem size_eq_nat_size : βˆ€ n, (size n : β„•) = nat_size n | 0 := rfl | (pos p) := p.size_eq_nat_size theorem nat_size_to_nat (n) : nat_size n = nat.size n := by rw [← size_eq_nat_size, size_to_nat] @[simp] theorem of_nat'_eq : βˆ€ n, num.of_nat' n = n := nat.binary_rec rfl $ Ξ» b n IH, begin rw of_nat' at IH ⊒, rw [nat.binary_rec_eq, IH], { cases b; simp [nat.bit, bit0_of_bit0, bit1_of_bit1] }, { refl } end theorem zneg_to_znum (n : num) : -n.to_znum = n.to_znum_neg := by cases n; refl theorem zneg_to_znum_neg (n : num) : -n.to_znum_neg = n.to_znum := by cases n; refl theorem to_znum_inj {m n : num} : m.to_znum = n.to_znum ↔ m = n := ⟨λ h, by cases m; cases n; cases h; refl, congr_arg _⟩ @[simp, norm_cast squash] theorem cast_to_znum [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] [has_neg Ξ±] : βˆ€ n : num, (n.to_znum : Ξ±) = n | 0 := rfl | (num.pos p) := rfl @[simp] theorem cast_to_znum_neg [add_group Ξ±] [has_one Ξ±] : βˆ€ n : num, (n.to_znum_neg : Ξ±) = -n | 0 := neg_zero.symm | (num.pos p) := rfl @[simp] theorem add_to_znum (m n : num) : num.to_znum (m + n) = m.to_znum + n.to_znum := by cases m; cases n; refl end num namespace pos_num open num theorem pred_to_nat {n : pos_num} (h : n > 1) : (pred n : β„•) = nat.pred n := begin unfold pred, have := pred'_to_nat n, cases e : pred' n, { have : (1:β„•) ≀ nat.pred n := nat.pred_le_pred ((@cast_lt β„• _ _ _).2 h), rw [← pred'_to_nat, e] at this, exact absurd this dec_trivial }, { rw [← pred'_to_nat, e], refl } end theorem sub'_one (a : pos_num) : sub' a 1 = (pred' a).to_znum := by cases a; refl theorem one_sub' (a : pos_num) : sub' 1 a = (pred' a).to_znum_neg := by cases a; refl theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = ordering.lt := iff.rfl theorem le_iff_cmp {m n} : m ≀ n ↔ cmp m n β‰  ordering.gt := not_congr $ lt_iff_cmp.trans $ by rw ← cmp_swap; cases cmp m n; exact dec_trivial end pos_num namespace num variables {Ξ± : Type*} open pos_num theorem pred_to_nat : βˆ€ (n : num), (pred n : β„•) = nat.pred n | 0 := rfl | (pos p) := by rw [pred, pos_num.pred'_to_nat]; refl theorem ppred_to_nat : βˆ€ (n : num), coe <$> ppred n = nat.ppred n | 0 := rfl | (pos p) := by rw [ppred, option.map_some, nat.ppred_eq_some.2]; rw [pos_num.pred'_to_nat, nat.succ_pred_eq_of_pos (pos_num.to_nat_pos _)]; refl theorem cmp_swap (m n) : (cmp m n).swap = cmp n m := by cases m; cases n; try {unfold cmp}; try {refl}; apply pos_num.cmp_swap theorem cmp_eq (m n) : cmp m n = ordering.eq ↔ m = n := begin have := cmp_to_nat m n, cases cmp m n; simp at this ⊒; try {exact this}; { simp [show m β‰  n, from Ξ» e, by rw e at this; exact lt_irrefl _ this] } end @[simp, norm_cast] theorem cast_lt [linear_ordered_semiring Ξ±] {m n : num} : (m:Ξ±) < n ↔ m < n := by rw [← cast_to_nat m, ← cast_to_nat n, nat.cast_lt, lt_to_nat] @[simp, norm_cast] theorem cast_le [linear_ordered_semiring Ξ±] {m n : num} : (m:Ξ±) ≀ n ↔ m ≀ n := by rw ← not_lt; exact not_congr cast_lt @[simp, norm_cast] theorem cast_inj [linear_ordered_semiring Ξ±] {m n : num} : (m:Ξ±) = n ↔ m = n := by rw [← cast_to_nat m, ← cast_to_nat n, nat.cast_inj, to_nat_inj] theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = ordering.lt := iff.rfl theorem le_iff_cmp {m n} : m ≀ n ↔ cmp m n β‰  ordering.gt := not_congr $ lt_iff_cmp.trans $ by rw ← cmp_swap; cases cmp m n; exact dec_trivial theorem bitwise_to_nat {f : num β†’ num β†’ num} {g : bool β†’ bool β†’ bool} (p : pos_num β†’ pos_num β†’ num) (gff : g ff ff = ff) (f00 : f 0 0 = 0) (f0n : βˆ€ n, f 0 (pos n) = cond (g ff tt) (pos n) 0) (fn0 : βˆ€ n, f (pos n) 0 = cond (g tt ff) (pos n) 0) (fnn : βˆ€ m n, f (pos m) (pos n) = p m n) (p11 : p 1 1 = cond (g tt tt) 1 0) (p1b : βˆ€ b n, p 1 (pos_num.bit b n) = bit (g tt b) (cond (g ff tt) (pos n) 0)) (pb1 : βˆ€ a m, p (pos_num.bit a m) 1 = bit (g a tt) (cond (g tt ff) (pos m) 0)) (pbb : βˆ€ a b m n, p (pos_num.bit a m) (pos_num.bit b n) = bit (g a b) (p m n)) : βˆ€ m n : num, (f m n : β„•) = nat.bitwise g m n := begin intros, cases m with m; cases n with n; try { change zero with 0 }; try { change ((0:num):β„•) with 0 }, { rw [f00, nat.bitwise_zero]; refl }, { unfold nat.bitwise, rw [f0n, nat.binary_rec_zero], cases g ff tt; refl }, { unfold nat.bitwise, generalize h : (pos m : β„•) = m', revert h, apply nat.bit_cases_on m' _, intros b m' h, rw [fn0, nat.binary_rec_eq, nat.binary_rec_zero, ←h], cases g tt ff; refl, apply nat.bitwise_bit_aux gff }, { rw fnn, have : βˆ€b (n : pos_num), (cond b ↑n 0 : β„•) = ↑(cond b (pos n) 0 : num) := by intros; cases b; refl, induction m with m IH m IH generalizing n; cases n with n n, any_goals { change one with 1 }, any_goals { change pos 1 with 1 }, any_goals { change pos_num.bit0 with pos_num.bit ff }, any_goals { change pos_num.bit1 with pos_num.bit tt }, any_goals { change ((1:num):β„•) with nat.bit tt 0 }, all_goals { repeat { rw show βˆ€ b n, (pos (pos_num.bit b n) : β„•) = nat.bit b ↑n, by intros; cases b; refl }, rw nat.bitwise_bit }, any_goals { assumption }, any_goals { rw [nat.bitwise_zero, p11], cases g tt tt; refl }, any_goals { rw [nat.bitwise_zero_left, this, ← bit_to_nat, p1b] }, any_goals { rw [nat.bitwise_zero_right _ gff, this, ← bit_to_nat, pb1] }, all_goals { rw [← show βˆ€ n, ↑(p m n) = nat.bitwise g ↑m ↑n, from IH], rw [← bit_to_nat, pbb] } } end @[simp, norm_cast] theorem lor_to_nat : βˆ€ m n, (lor m n : β„•) = nat.lor m n := by apply bitwise_to_nat (Ξ»x y, pos (pos_num.lor x y)); intros; try {cases a}; try {cases b}; refl @[simp, norm_cast] theorem land_to_nat : βˆ€ m n, (land m n : β„•) = nat.land m n := by apply bitwise_to_nat pos_num.land; intros; try {cases a}; try {cases b}; refl @[simp, norm_cast] theorem ldiff_to_nat : βˆ€ m n, (ldiff m n : β„•) = nat.ldiff m n := by apply bitwise_to_nat pos_num.ldiff; intros; try {cases a}; try {cases b}; refl @[simp, norm_cast] theorem lxor_to_nat : βˆ€ m n, (lxor m n : β„•) = nat.lxor m n := by apply bitwise_to_nat pos_num.lxor; intros; try {cases a}; try {cases b}; refl @[simp, norm_cast] theorem shiftl_to_nat (m n) : (shiftl m n : β„•) = nat.shiftl m n := begin cases m; dunfold shiftl, {symmetry, apply nat.zero_shiftl}, simp, induction n with n IH, {refl}, simp [pos_num.shiftl, nat.shiftl_succ], rw ←IH end @[simp, norm_cast] theorem shiftr_to_nat (m n) : (shiftr m n : β„•) = nat.shiftr m n := begin cases m with m; dunfold shiftr, {symmetry, apply nat.zero_shiftr}, induction n with n IH generalizing m, {cases m; refl}, cases m with m m; dunfold pos_num.shiftr, { rw [nat.shiftr_eq_div_pow], symmetry, apply nat.div_eq_of_lt, exact @nat.pow_lt_pow_of_lt_right 2 dec_trivial 0 (n+1) (nat.succ_pos _) }, { transitivity, apply IH, change nat.shiftr m n = nat.shiftr (bit1 m) (n+1), rw [add_comm n 1, nat.shiftr_add], apply congr_arg (Ξ»x, nat.shiftr x n), unfold nat.shiftr, change (bit1 ↑m : β„•) with nat.bit tt m, rw nat.div2_bit }, { transitivity, apply IH, change nat.shiftr m n = nat.shiftr (bit0 m) (n + 1), rw [add_comm n 1, nat.shiftr_add], apply congr_arg (Ξ»x, nat.shiftr x n), unfold nat.shiftr, change (bit0 ↑m : β„•) with nat.bit ff m, rw nat.div2_bit } end @[simp] theorem test_bit_to_nat (m n) : test_bit m n = nat.test_bit m n := begin cases m with m; unfold test_bit nat.test_bit, { change (zero : nat) with 0, rw nat.zero_shiftr, refl }, induction n with n IH generalizing m; cases m; dunfold pos_num.test_bit, {refl}, { exact (nat.bodd_bit _ _).symm }, { exact (nat.bodd_bit _ _).symm }, { change ff = nat.bodd (nat.shiftr 1 (n + 1)), rw [add_comm, nat.shiftr_add], change nat.shiftr 1 1 with 0, rw nat.zero_shiftr; refl }, { change pos_num.test_bit m n = nat.bodd (nat.shiftr (nat.bit tt m) (n + 1)), rw [add_comm, nat.shiftr_add], unfold nat.shiftr, rw nat.div2_bit, apply IH }, { change pos_num.test_bit m n = nat.bodd (nat.shiftr (nat.bit ff m) (n + 1)), rw [add_comm, nat.shiftr_add], unfold nat.shiftr, rw nat.div2_bit, apply IH }, end end num namespace znum variables {Ξ± : Type*} open pos_num @[simp, norm_cast] theorem cast_zero [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] [has_neg Ξ±] : ((0 : znum) : Ξ±) = 0 := rfl @[simp] theorem cast_zero' [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] [has_neg Ξ±] : (znum.zero : Ξ±) = 0 := rfl @[simp, norm_cast] theorem cast_one [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] [has_neg Ξ±] : ((1 : znum) : Ξ±) = 1 := rfl @[simp] theorem cast_pos [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] [has_neg Ξ±] (n : pos_num) : (pos n : Ξ±) = n := rfl @[simp] theorem cast_neg [has_zero Ξ±] [has_one Ξ±] [has_add Ξ±] [has_neg Ξ±] (n : pos_num) : (neg n : Ξ±) = -n := rfl @[simp, norm_cast] theorem cast_zneg [add_group Ξ±] [has_one Ξ±] : βˆ€ n, ((-n : znum) : Ξ±) = -n | 0 := neg_zero.symm | (pos p) := rfl | (neg p) := (neg_neg _).symm theorem neg_zero : (-0 : znum) = 0 := rfl theorem zneg_pos (n : pos_num) : -pos n = neg n := rfl theorem zneg_neg (n : pos_num) : -neg n = pos n := rfl theorem zneg_zneg (n : znum) : - -n = n := by cases n; refl theorem zneg_bit1 (n : znum) : -n.bit1 = (-n).bitm1 := by cases n; refl theorem zneg_bitm1 (n : znum) : -n.bitm1 = (-n).bit1 := by cases n; refl theorem zneg_succ (n : znum) : -n.succ = (-n).pred := by cases n; try {refl}; rw [succ, num.zneg_to_znum_neg]; refl theorem zneg_pred (n : znum) : -n.pred = (-n).succ := by rw [← zneg_zneg (succ (-n)), zneg_succ, zneg_zneg] @[simp, norm_cast] theorem neg_of_int : βˆ€ n, ((-n : β„€) : znum) = -n | (n+1:β„•) := rfl | 0 := rfl | -[1+n] := (zneg_zneg _).symm @[simp] theorem abs_to_nat : βˆ€ n, (abs n : β„•) = int.nat_abs n | 0 := rfl | (pos p) := congr_arg int.nat_abs p.to_nat_to_int | (neg p) := show int.nat_abs ((p:β„•):β„€) = int.nat_abs (- p), by rw [p.to_nat_to_int, int.nat_abs_neg] @[simp] theorem abs_to_znum : βˆ€ n : num, abs n.to_znum = n | 0 := rfl | (num.pos p) := rfl @[simp, norm_cast] theorem cast_to_int [add_group Ξ±] [has_one Ξ±] : βˆ€ n : znum, ((n : β„€) : Ξ±) = n | 0 := rfl | (pos p) := by rw [cast_pos, cast_pos, pos_num.cast_to_int] | (neg p) := by rw [cast_neg, cast_neg, int.cast_neg, pos_num.cast_to_int] theorem bit0_of_bit0 : βˆ€ n : znum, _root_.bit0 n = n.bit0 | 0 := rfl | (pos a) := congr_arg pos a.bit0_of_bit0 | (neg a) := congr_arg neg a.bit0_of_bit0 theorem bit1_of_bit1 : βˆ€ n : znum, _root_.bit1 n = n.bit1 | 0 := rfl | (pos a) := congr_arg pos a.bit1_of_bit1 | (neg a) := show pos_num.sub' 1 (_root_.bit0 a) = _, by rw [pos_num.one_sub', a.bit0_of_bit0]; refl @[simp, norm_cast] theorem cast_bit0 [add_group Ξ±] [has_one Ξ±] : βˆ€ n : znum, (n.bit0 : Ξ±) = bit0 n | 0 := (add_zero _).symm | (pos p) := by rw [znum.bit0, cast_pos, cast_pos]; refl | (neg p) := by rw [znum.bit0, cast_neg, cast_neg, pos_num.cast_bit0, _root_.bit0, _root_.bit0, neg_add_rev] @[simp, norm_cast] theorem cast_bit1 [add_group Ξ±] [has_one Ξ±] : βˆ€ n : znum, (n.bit1 : Ξ±) = bit1 n | 0 := by simp [znum.bit1, _root_.bit1, _root_.bit0] | (pos p) := by rw [znum.bit1, cast_pos, cast_pos]; refl | (neg p) := begin rw [znum.bit1, cast_neg, cast_neg], cases e : pred' p; have : p = _ := (succ'_pred' p).symm.trans (congr_arg num.succ' e), { change p=1 at this, subst p, simp [_root_.bit1, _root_.bit0] }, { rw [num.succ'] at this, subst p, have : (↑(-↑a:β„€) : Ξ±) = -1 + ↑(-↑a + 1 : β„€), {simp [add_comm]}, simpa [_root_.bit1, _root_.bit0, -add_comm] }, end @[simp] theorem cast_bitm1 [add_group Ξ±] [has_one Ξ±] (n : znum) : (n.bitm1 : Ξ±) = bit0 n - 1 := begin conv { to_lhs, rw ← zneg_zneg n }, rw [← zneg_bit1, cast_zneg, cast_bit1], have : ((-1 + n + n : β„€) : Ξ±) = (n + n + -1 : β„€), {simp [add_comm, add_left_comm]}, simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg] end theorem add_zero (n : znum) : n + 0 = n := by cases n; refl theorem zero_add (n : znum) : 0 + n = n := by cases n; refl theorem add_one : βˆ€ n : znum, n + 1 = succ n | 0 := rfl | (pos p) := congr_arg pos p.add_one | (neg p) := by cases p; refl end znum namespace pos_num variables {Ξ± : Type*} theorem cast_to_znum : βˆ€ n : pos_num, (n : znum) = znum.pos n | 1 := rfl | (bit0 p) := (znum.bit0_of_bit0 p).trans $ congr_arg _ (cast_to_znum p) | (bit1 p) := (znum.bit1_of_bit1 p).trans $ congr_arg _ (cast_to_znum p) theorem cast_sub' [add_group Ξ±] [has_one Ξ±] : βˆ€ m n : pos_num, (sub' m n : Ξ±) = m - n | a 1 := by rw [sub'_one, num.cast_to_znum, ← num.cast_to_nat, pred'_to_nat, ← nat.sub_one]; simp [pos_num.cast_pos] | 1 b := by rw [one_sub', num.cast_to_znum_neg, ← neg_sub, neg_inj', ← num.cast_to_nat, pred'_to_nat, ← nat.sub_one]; simp [pos_num.cast_pos] | (bit0 a) (bit0 b) := begin rw [sub', znum.cast_bit0, cast_sub'], have : ((a + -b + (a + -b) : β„€) : Ξ±) = a + a + (-b + -b), {simp [add_left_comm]}, simpa [_root_.bit0, sub_eq_add_neg] end | (bit0 a) (bit1 b) := begin rw [sub', znum.cast_bitm1, cast_sub'], have : ((-b + (a + (-b + -1)) : β„€) : Ξ±) = (a + -1 + (-b + -b):β„€), { simp [add_comm, add_left_comm] }, simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg] end | (bit1 a) (bit0 b) := begin rw [sub', znum.cast_bit1, cast_sub'], have : ((-b + (a + (-b + 1)) : β„€) : Ξ±) = (a + 1 + (-b + -b):β„€), { simp [add_comm, add_left_comm] }, simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg] end | (bit1 a) (bit1 b) := begin rw [sub', znum.cast_bit0, cast_sub'], have : ((-b + (a + -b) : β„€) : Ξ±) = a + (-b + -b), {simp [add_left_comm]}, simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg] end theorem to_nat_eq_succ_pred (n : pos_num) : (n:β„•) = n.pred' + 1 := by rw [← num.succ'_to_nat, n.succ'_pred'] theorem to_int_eq_succ_pred (n : pos_num) : (n:β„€) = (n.pred' : β„•) + 1 := by rw [← n.to_nat_to_int, to_nat_eq_succ_pred]; refl end pos_num namespace num variables {Ξ± : Type*} @[simp] theorem cast_sub' [add_group Ξ±] [has_one Ξ±] : βˆ€ m n : num, (sub' m n : Ξ±) = m - n | 0 0 := (sub_zero _).symm | (pos a) 0 := (sub_zero _).symm | 0 (pos b) := (zero_sub _).symm | (pos a) (pos b) := pos_num.cast_sub' _ _ @[simp] theorem of_nat_to_znum : βˆ€ n : β„•, to_znum n = n | 0 := rfl | (n+1) := by rw [nat.cast_add_one, nat.cast_add_one, znum.add_one, add_one, ← of_nat_to_znum]; cases (n:num); refl @[simp] theorem of_nat_to_znum_neg (n : β„•) : to_znum_neg n = -n := by rw [← of_nat_to_znum, zneg_to_znum] theorem mem_of_znum' : βˆ€ {m : num} {n : znum}, m ∈ of_znum' n ↔ n = to_znum m | 0 0 := ⟨λ _, rfl, Ξ» _, rfl⟩ | (pos m) 0 := ⟨λ h, by cases h, Ξ» h, by cases h⟩ | m (znum.pos p) := option.some_inj.trans $ by cases m; split; intro h; try {cases h}; refl | m (znum.neg p) := ⟨λ h, by cases h, Ξ» h, by cases m; cases h⟩ theorem of_znum'_to_nat : βˆ€ (n : znum), coe <$> of_znum' n = int.to_nat' n | 0 := rfl | (znum.pos p) := show _ = int.to_nat' p, by rw [← pos_num.to_nat_to_int p]; refl | (znum.neg p) := congr_arg (Ξ» x, int.to_nat' (-x)) $ show ((p.pred' + 1 : β„•) : β„€) = p, by rw ← succ'_to_nat; simp @[simp] theorem of_znum_to_nat : βˆ€ (n : znum), (of_znum n : β„•) = int.to_nat n | 0 := rfl | (znum.pos p) := show _ = int.to_nat p, by rw [← pos_num.to_nat_to_int p]; refl | (znum.neg p) := congr_arg (Ξ» x, int.to_nat (-x)) $ show ((p.pred' + 1 : β„•) : β„€) = p, by rw ← succ'_to_nat; simp @[simp] theorem cast_of_znum [add_group Ξ±] [has_one Ξ±] (n : znum) : (of_znum n : Ξ±) = int.to_nat n := by rw [← cast_to_nat, of_znum_to_nat] @[simp, norm_cast] theorem sub_to_nat (m n) : ((m - n : num) : β„•) = m - n := show (of_znum _ : β„•) = _, by rw [of_znum_to_nat, cast_sub', ← to_nat_to_int, ← to_nat_to_int, int.to_nat_sub] end num namespace znum variables {Ξ± : Type*} @[simp, norm_cast] theorem cast_add [add_group Ξ±] [has_one Ξ±] : βˆ€ m n, ((m + n : znum) : Ξ±) = m + n | 0 a := by cases a; exact (_root_.zero_add _).symm | b 0 := by cases b; exact (_root_.add_zero _).symm | (pos a) (pos b) := pos_num.cast_add _ _ | (pos a) (neg b) := pos_num.cast_sub' _ _ | (neg a) (pos b) := (pos_num.cast_sub' _ _).trans $ show ↑b + -↑a = -↑a + ↑b, by rw [← pos_num.cast_to_int a, ← pos_num.cast_to_int b, ← int.cast_neg, ← int.cast_add (-a)]; simp [add_comm] | (neg a) (neg b) := show -(↑(a + b) : Ξ±) = -a + -b, by rw [ pos_num.cast_add, neg_eq_iff_neg_eq, neg_add_rev, neg_neg, neg_neg, ← pos_num.cast_to_int a, ← pos_num.cast_to_int b, ← int.cast_add]; simp [add_comm] @[simp] theorem cast_succ [add_group Ξ±] [has_one Ξ±] (n) : ((succ n : znum) : Ξ±) = n + 1 := by rw [← add_one, cast_add, cast_one] @[simp, norm_cast] theorem mul_to_int : βˆ€ m n, ((m * n : znum) : β„€) = m * n | 0 a := by cases a; exact (_root_.zero_mul _).symm | b 0 := by cases b; exact (_root_.mul_zero _).symm | (pos a) (pos b) := pos_num.cast_mul a b | (pos a) (neg b) := show -↑(a * b) = ↑a * -↑b, by rw [pos_num.cast_mul, neg_mul_eq_mul_neg] | (neg a) (pos b) := show -↑(a * b) = -↑a * ↑b, by rw [pos_num.cast_mul, neg_mul_eq_neg_mul] | (neg a) (neg b) := show ↑(a * b) = -↑a * -↑b, by rw [pos_num.cast_mul, neg_mul_neg] theorem cast_mul [ring Ξ±] (m n) : ((m * n : znum) : Ξ±) = m * n := by rw [← cast_to_int, mul_to_int, int.cast_mul, cast_to_int, cast_to_int] @[simp, norm_cast] theorem of_to_int : Ξ  (n : znum), ((n : β„€) : znum) = n | 0 := rfl | (pos a) := by rw [cast_pos, ← pos_num.cast_to_nat, int.cast_coe_nat', ← num.of_nat_to_znum, pos_num.of_to_nat]; refl | (neg a) := by rw [cast_neg, neg_of_int, ← pos_num.cast_to_nat, int.cast_coe_nat', ← num.of_nat_to_znum_neg, pos_num.of_to_nat]; refl @[norm_cast] theorem to_of_int : Ξ  (n : β„€), ((n : znum) : β„€) = n | (n : β„•) := by rw [int.cast_coe_nat, ← num.of_nat_to_znum, num.cast_to_znum, ← num.cast_to_nat, int.nat_cast_eq_coe_nat, num.to_of_nat] | -[1+ n] := by rw [int.cast_neg_succ_of_nat, cast_zneg, add_one, cast_succ, int.neg_succ_of_nat_eq, ← num.of_nat_to_znum, num.cast_to_znum, ← num.cast_to_nat, int.nat_cast_eq_coe_nat, num.to_of_nat] theorem to_int_inj {m n : znum} : (m : β„€) = n ↔ m = n := ⟨λ h, function.left_inverse.injective of_to_int h, congr_arg _⟩ @[simp, norm_cast] theorem of_int_cast [add_group Ξ±] [has_one Ξ±] (n : β„€) : ((n : znum) : Ξ±) = n := by rw [← cast_to_int, to_of_int] @[simp, norm_cast] theorem of_nat_cast [add_group Ξ±] [has_one Ξ±] (n : β„•) : ((n : znum) : Ξ±) = n := of_int_cast n @[simp] theorem of_int'_eq : βˆ€ n, znum.of_int' n = n | (n : β„•) := to_int_inj.1 $ by simp [znum.of_int'] | -[1+ n] := to_int_inj.1 $ by simp [znum.of_int'] theorem cmp_to_int : βˆ€ (m n), (ordering.cases_on (cmp m n) ((m:β„€) < n) (m = n) ((m:β„€) > n) : Prop) | 0 0 := rfl | (pos a) (pos b) := begin have := pos_num.cmp_to_nat a b; revert this; dsimp [cmp]; cases pos_num.cmp a b; dsimp; [simp, exact congr_arg pos, simp [gt]] end | (neg a) (neg b) := begin have := pos_num.cmp_to_nat b a; revert this; dsimp [cmp]; cases pos_num.cmp b a; dsimp; [simp, simp {contextual := tt}, simp [gt]] end | (pos a) 0 := pos_num.cast_pos _ | (pos a) (neg b) := lt_trans (neg_lt_zero.2 $ pos_num.cast_pos _) (pos_num.cast_pos _) | 0 (neg b) := neg_lt_zero.2 $ pos_num.cast_pos _ | (neg a) 0 := neg_lt_zero.2 $ pos_num.cast_pos _ | (neg a) (pos b) := lt_trans (neg_lt_zero.2 $ pos_num.cast_pos _) (pos_num.cast_pos _) | 0 (pos b) := pos_num.cast_pos _ @[norm_cast] theorem lt_to_int {m n : znum} : (m:β„€) < n ↔ m < n := show (m:β„€) < n ↔ cmp m n = ordering.lt, from match cmp m n, cmp_to_int m n with | ordering.lt, h := by simp at h; simp [h] | ordering.eq, h := by simp at h; simp [h, lt_irrefl]; exact dec_trivial | ordering.gt, h := by simp [not_lt_of_gt h]; exact dec_trivial end theorem le_to_int {m n : znum} : (m:β„€) ≀ n ↔ m ≀ n := by rw ← not_lt; exact not_congr lt_to_int @[simp, norm_cast] theorem cast_lt [linear_ordered_ring Ξ±] {m n : znum} : (m:Ξ±) < n ↔ m < n := by rw [← cast_to_int m, ← cast_to_int n, int.cast_lt, lt_to_int] @[simp, norm_cast] theorem cast_le [linear_ordered_ring Ξ±] {m n : znum} : (m:Ξ±) ≀ n ↔ m ≀ n := by rw ← not_lt; exact not_congr cast_lt @[simp, norm_cast] theorem cast_inj [linear_ordered_ring Ξ±] {m n : znum} : (m:Ξ±) = n ↔ m = n := by rw [← cast_to_int m, ← cast_to_int n, int.cast_inj, to_int_inj] meta def transfer_rw : tactic unit := `[repeat {rw ← to_int_inj <|> rw ← lt_to_int <|> rw ← le_to_int}, repeat {rw cast_add <|> rw mul_to_int <|> rw cast_one <|> rw cast_zero}] meta def transfer : tactic unit := `[intros, transfer_rw, try {simp [add_comm, add_left_comm, mul_comm, mul_left_comm]}] instance : decidable_linear_order znum := { lt := (<), lt_iff_le_not_le := by {intros a b, transfer_rw, apply lt_iff_le_not_le}, le := (≀), le_refl := by transfer, le_trans := by {intros a b c, transfer_rw, apply le_trans}, le_antisymm := by {intros a b, transfer_rw, apply le_antisymm}, le_total := by {intros a b, transfer_rw, apply le_total}, decidable_eq := znum.decidable_eq, decidable_le := znum.decidable_le, decidable_lt := znum.decidable_lt } instance : add_comm_group znum := { add := (+), add_assoc := by transfer, zero := 0, zero_add := zero_add, add_zero := add_zero, add_comm := by transfer, neg := has_neg.neg, add_left_neg := by transfer } instance : decidable_linear_ordered_comm_ring znum := { mul := (*), mul_assoc := by transfer, one := 1, one_mul := by transfer, mul_one := by transfer, left_distrib := by {transfer, simp [mul_add]}, right_distrib := by {transfer, simp [mul_add, mul_comm]}, mul_comm := by transfer, zero_ne_one := dec_trivial, add_le_add_left := by {intros a b h c, revert h, transfer_rw, exact Ξ» h, add_le_add_left h c}, mul_pos := Ξ» a b, show 0 < a β†’ 0 < b β†’ 0 < a * b, by {transfer_rw, apply mul_pos}, zero_lt_one := dec_trivial, ..znum.decidable_linear_order, ..znum.add_comm_group } @[simp, norm_cast] theorem dvd_to_int (m n : znum) : (m : β„€) ∣ n ↔ m ∣ n := ⟨λ ⟨k, e⟩, ⟨k, by rw [← of_to_int n, e]; simp⟩, Ξ» ⟨k, e⟩, ⟨k, by simp [e]⟩⟩ end znum namespace pos_num theorem divmod_to_nat_aux {n d : pos_num} {q r : num} (h₁ : (r:β„•) + d * _root_.bit0 q = n) (hβ‚‚ : (r:β„•) < 2 * d) : ((divmod_aux d q r).2 + d * (divmod_aux d q r).1 : β„•) = ↑n ∧ ((divmod_aux d q r).2 : β„•) < d := begin unfold divmod_aux, have : βˆ€ {rβ‚‚}, num.of_znum' (num.sub' r (num.pos d)) = some rβ‚‚ ↔ (r : β„•) = rβ‚‚ + d, { intro rβ‚‚, apply num.mem_of_znum'.trans, rw [← znum.to_int_inj, num.cast_to_znum, num.cast_sub', sub_eq_iff_eq_add, ← int.coe_nat_inj'], simp }, cases e : num.of_znum' (num.sub' r (num.pos d)) with rβ‚‚; simp [divmod_aux], { refine ⟨h₁, lt_of_not_ge (Ξ» h, _)⟩, cases nat.le.dest h with rβ‚‚ e', rw [← num.to_of_nat rβ‚‚, add_comm] at e', cases e.symm.trans (this.2 e'.symm) }, { have := this.1 e, split, { rwa [_root_.bit1, add_comm _ 1, mul_add, mul_one, ← add_assoc, ← this] }, { rwa [this, two_mul, add_lt_add_iff_right] at hβ‚‚ } } end theorem divmod_to_nat (d n : pos_num) : (n / d : β„•) = (divmod d n).1 ∧ (n % d : β„•) = (divmod d n).2 := begin rw nat.div_mod_unique (pos_num.cast_pos _), induction n with n IH n IH, { exact divmod_to_nat_aux (by simp; refl) (nat.mul_le_mul_left 2 (pos_num.cast_pos d : (0 : β„•) < d)) }, { unfold divmod, cases divmod d n with q r, simp only [divmod] at IH ⊒, apply divmod_to_nat_aux; simp, { rw [_root_.bit1, _root_.bit1, add_right_comm, bit0_eq_two_mul ↑n, ← IH.1, mul_add, ← bit0_eq_two_mul, mul_left_comm, ← bit0_eq_two_mul] }, { rw ← bit0_eq_two_mul, exact nat.bit1_lt_bit0 IH.2 } }, { unfold divmod, cases divmod d n with q r, simp only [divmod] at IH ⊒, apply divmod_to_nat_aux; simp, { rw [bit0_eq_two_mul ↑n, ← IH.1, mul_add, ← bit0_eq_two_mul, mul_left_comm, ← bit0_eq_two_mul] }, { rw ← bit0_eq_two_mul, exact nat.bit0_lt IH.2 } } end @[simp] theorem div'_to_nat (n d) : (div' n d : β„•) = n / d := (divmod_to_nat _ _).1.symm @[simp] theorem mod'_to_nat (n d) : (mod' n d : β„•) = n % d := (divmod_to_nat _ _).2.symm end pos_num namespace num @[simp, norm_cast] theorem div_to_nat : βˆ€ n d, ((n / d : num) : β„•) = n / d | 0 0 := rfl | 0 (pos d) := (nat.zero_div _).symm | (pos n) 0 := (nat.div_zero _).symm | (pos n) (pos d) := pos_num.div'_to_nat _ _ @[simp, norm_cast] theorem mod_to_nat : βˆ€ n d, ((n % d : num) : β„•) = n % d | 0 0 := rfl | 0 (pos d) := (nat.zero_mod _).symm | (pos n) 0 := (nat.mod_zero _).symm | (pos n) (pos d) := pos_num.mod'_to_nat _ _ theorem gcd_to_nat_aux : βˆ€ {n} {a b : num}, a ≀ b β†’ (a * b).nat_size ≀ n β†’ (gcd_aux n a b : β„•) = nat.gcd a b | 0 0 b ab h := (nat.gcd_zero_left _).symm | 0 (pos a) 0 ab h := (not_lt_of_ge ab).elim rfl | 0 (pos a) (pos b) ab h := (not_lt_of_le h).elim $ pos_num.nat_size_pos _ | (nat.succ n) 0 b ab h := (nat.gcd_zero_left _).symm | (nat.succ n) (pos a) b ab h := begin simp [gcd_aux], rw [nat.gcd_rec, gcd_to_nat_aux, mod_to_nat], {refl}, { rw [← le_to_nat, mod_to_nat], exact le_of_lt (nat.mod_lt _ (pos_num.cast_pos _)) }, rw [nat_size_to_nat, mul_to_nat, nat.size_le] at h ⊒, rw [mod_to_nat, mul_comm], rw [nat.pow_succ, ← nat.mod_add_div b (pos a)] at h, refine lt_of_mul_lt_mul_right (lt_of_le_of_lt _ h) (nat.zero_le 2), rw [mul_two, mul_add], refine add_le_add_left (nat.mul_le_mul_left _ (le_trans (le_of_lt (nat.mod_lt _ (pos_num.cast_pos _))) _)) _, suffices : 1 ≀ _, simpa using nat.mul_le_mul_left (pos a) this, rw [nat.le_div_iff_mul_le _ _ a.cast_pos, one_mul], exact le_to_nat.2 ab end @[simp] theorem gcd_to_nat : βˆ€ a b, (gcd a b : β„•) = nat.gcd a b := have βˆ€ a b : num, (a * b).nat_size ≀ a.nat_size + b.nat_size, begin intros, simp [nat_size_to_nat], rw [nat.size_le, nat.pow_add], exact mul_lt_mul'' (nat.lt_size_self _) (nat.lt_size_self _) (nat.zero_le _) (nat.zero_le _) end, begin intros, unfold gcd, split_ifs, { exact gcd_to_nat_aux h (this _ _) }, { rw nat.gcd_comm, exact gcd_to_nat_aux (le_of_not_le h) (this _ _) } end theorem dvd_iff_mod_eq_zero {m n : num} : m ∣ n ↔ n % m = 0 := by rw [← dvd_to_nat, nat.dvd_iff_mod_eq_zero, ← to_nat_inj, mod_to_nat]; refl instance : decidable_rel ((∣) : num β†’ num β†’ Prop) | a b := decidable_of_iff' _ dvd_iff_mod_eq_zero end num namespace znum @[simp, norm_cast] theorem div_to_int : βˆ€ n d, ((n / d : znum) : β„€) = n / d | 0 0 := rfl | 0 (pos d) := (int.zero_div _).symm | 0 (neg d) := (int.zero_div _).symm | (pos n) 0 := (int.div_zero _).symm | (neg n) 0 := (int.div_zero _).symm | (pos n) (pos d) := (num.cast_to_znum _).trans $ by rw ← num.to_nat_to_int; simp | (pos n) (neg d) := (num.cast_to_znum_neg _).trans $ by rw ← num.to_nat_to_int; simp | (neg n) (pos d) := show - _ = (-_/↑d), begin rw [n.to_int_eq_succ_pred, d.to_int_eq_succ_pred, ← pos_num.to_nat_to_int, num.succ'_to_nat, num.div_to_nat], change -[1+ n.pred' / ↑d] = -[1+ n.pred' / (d.pred' + 1)], rw d.to_nat_eq_succ_pred end | (neg n) (neg d) := show ↑(pos_num.pred' n / num.pos d).succ' = (-_ / -↑d), begin rw [n.to_int_eq_succ_pred, d.to_int_eq_succ_pred, ← pos_num.to_nat_to_int, num.succ'_to_nat, num.div_to_nat], change (nat.succ (_/d) : β„€) = nat.succ (n.pred'/(d.pred' + 1)), rw d.to_nat_eq_succ_pred end @[simp, norm_cast] theorem mod_to_int : βˆ€ n d, ((n % d : znum) : β„€) = n % d | 0 d := (int.zero_mod _).symm | (pos n) d := (num.cast_to_znum _).trans $ by rw [← num.to_nat_to_int, cast_pos, num.mod_to_nat, ← pos_num.to_nat_to_int, abs_to_nat]; refl | (neg n) d := (num.cast_sub' _ _).trans $ by rw [← num.to_nat_to_int, cast_neg, ← num.to_nat_to_int, num.succ_to_nat, num.mod_to_nat, abs_to_nat, ← int.sub_nat_nat_eq_coe, n.to_int_eq_succ_pred]; refl @[simp] theorem gcd_to_nat (a b) : (gcd a b : β„•) = int.gcd a b := (num.gcd_to_nat _ _).trans $ by simpa theorem dvd_iff_mod_eq_zero {m n : znum} : m ∣ n ↔ n % m = 0 := by rw [← dvd_to_int, int.dvd_iff_mod_eq_zero, ← to_int_inj, mod_to_int]; refl instance : decidable_rel ((∣) : znum β†’ znum β†’ Prop) | a b := decidable_of_iff' _ dvd_iff_mod_eq_zero end znum namespace int def of_snum : snum β†’ β„€ := snum.rec' (Ξ» a, cond a (-1) 0) (Ξ»a p IH, cond a (bit1 IH) (bit0 IH)) instance snum_coe : has_coe snum β„€ := ⟨of_snum⟩ end int instance : has_lt snum := ⟨λa b, (a : β„€) < b⟩ instance : has_le snum := ⟨λa b, (a : β„€) ≀ b⟩
3f3c522d73e21548993ea52405865f6468867008
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/io_process_env.lean
16144e8871228d9b0309b40bd5c385762daf4337
[ "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
177
lean
import system.io #eval do res ← io.cmd {cmd := "printenv", args := ["foo"], env := [("foo", "bar")]}, when (res β‰  "bar\n") $ io.fail $ "unexpected value for foo: " ++ res
f8c109f8e71212d88d88fd84a02867e94d6e186c
e07b1aca72e83a272dd59d24c6e0fa246034d774
/src/tutorials/03_forall_or.lean
d5307939206619ff1f0582f98bb335b66c00a1f6
[ "Apache-2.0", "LicenseRef-scancode-unknown-license-reference" ]
permissive
pedrominicz/learn
637a343bd4f8669d76819ac660a2d2d3e0958710
b79b802a9846c86c21d4b6f3e17af36e7382f0ef
refs/heads/master
1,671,746,990,402
1,670,778,113,000
1,670,778,113,000
265,735,177
1
0
null
null
null
null
UTF-8
Lean
false
false
10,391
lean
import data.real.basic import algebra.pi_instances set_option pp.beta true /- In this file, we'll learn about the βˆ€ quantifier, and the disjunction operator ∨ (logical OR). Let P be a predicate on a type X. This means for every mathematical object x with type X, we get a mathematical statement P x. In Lean, P x has type Prop. Lean sees a proof h of `βˆ€ x, P x` as a function sending any `x : X` to a proof `h x` of `P x`. This already explains the main way to use an assumption or lemma which starts with a βˆ€. In order to prove `βˆ€ x, P x`, we use `intros x` to fix an arbitrary object with type X, and call it x. Note also we don't need to give the type of x in the expression `βˆ€ x, P x` as long as the type of P is clear to Lean, which can then infer the type of x. Let's define two predicates to play with βˆ€. -/ def even_fun (f : ℝ β†’ ℝ) := βˆ€ x, f (-x) = f x #check even_fun def odd_fun (f : ℝ β†’ ℝ) := βˆ€ x, f (-x) = -f x #check odd_fun /- In the next proof, we also take the opportunity to introduce the `unfold` tactic, which simply unfolds definitions. Here this is purely for didactic reason, Lean doesn't need those `unfold` invocations. We will also use `rfl` which is a term proving equalities that are true by definition (in a very strong sense to be discussed later). -/ example (f g : ℝ β†’ ℝ) : even_fun f β†’ even_fun g β†’ even_fun (f + g) := begin unfold even_fun, intros hf hg x, calc (f + g) (-x) = f (-x) + g (-x) : rfl ... = f x + g x : by rw [hf x, hg x], end example (f g : ℝ β†’ ℝ) : even_fun f β†’ even_fun g β†’ even_fun (f + g) := begin -- Assume f is even intros hf, -- which means βˆ€ x, f (-x) = f x unfold even_fun at hf, -- and the same for g intros hg, unfold even_fun at hg, -- We need to prove βˆ€ x, (f+g)(-x) = (f+g)(x) unfold even_fun, -- Let x be any real number intros x, -- and let's compute calc (f + g) (-x) = f (-x) + g (-x) : rfl ... = f x + g (-x) : by rw hf x ... = f x + g x : by rw hg x ... = (f + g) x : rfl end /- In the preceding proof, all `unfold` lines are purely for psychological comfort. Sometimes unfolding is necessary because we want to apply a tactic that operates purely on the syntactical level. The main such tactic is `rw`. The same property of `rw` explain why the first computation line is necessary, although its proof is simply `rfl`. Before that line, `rw hf x` won't find anything like `f (-x)` hence will give up. The last line is not necessary however, since it only proves something that is true by definition, and is not followed by a `rw`. Also, Lean doesn't need to be told that hf should be specialized to x before rewriting, exactly as in the first file 01_equality_rewriting. We can also gather several rewrites using a list of expressions. Hence we can compress the above proof to: -/ example (f g : ℝ β†’ ℝ) : even_fun f β†’ even_fun g β†’ even_fun (f + g) := begin intros hf hg x, calc (f + g) (-x) = f (-x) + g (-x) : rfl ... = f x + g x : by rw [hf, hg] end /- Note that the tactic state displays changes when we move the cursor inside the list of expressions given to `rw`. Now let's practice. -/ -- 0023 example (f g : ℝ β†’ ℝ) : even_fun f β†’ even_fun (g ∘ f) := begin intros hf x, calc (g ∘ f) (-x) = g (f (-x)) : rfl ... = g (f x) : by rw hf, end -- 0024 example (f g : ℝ β†’ ℝ) : odd_fun f β†’ odd_fun g β†’ odd_fun (g ∘ f) := begin intros hf hg x, calc (g ∘ f) (-x) = g (f (-x)) : rfl ... = -(g (f x)) : by rw [hf, hg], end /- Let's have more quantifiers, and play with forward and backward reasoning. In the next definitions, note how `βˆ€ x₁, βˆ€ xβ‚‚` is abreviated to `βˆ€ x₁ xβ‚‚`. -/ def non_decreasing (f : ℝ β†’ ℝ) := βˆ€ x₁ xβ‚‚, x₁ ≀ xβ‚‚ β†’ f x₁ ≀ f xβ‚‚ def non_increasing (f : ℝ β†’ ℝ) := βˆ€ x₁ xβ‚‚, x₁ ≀ xβ‚‚ β†’ f x₁ β‰₯ f xβ‚‚ example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) := assume x₁ xβ‚‚ h, have f x₁ ≀ f xβ‚‚, from hf _ _ h, show g (f x₁) ≀ g (f xβ‚‚), from hg _ _ this /- Let's be very explicit and use forward reasonning first. -/ example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) := begin -- Let x₁ and xβ‚‚ be real numbers such that x₁ ≀ xβ‚‚ intros x₁ xβ‚‚ h, -- Since f is non-decreasing, f x₁ ≀ f xβ‚‚. have step₁ : f x₁ ≀ f xβ‚‚, exact hf x₁ xβ‚‚ h, -- Since g is non-decreasing, we then get g (f x₁) ≀ g (f xβ‚‚). exact hg (f x₁) (f xβ‚‚) step₁, end /- In the above proof, note how inconvenient it is to specify x₁ and xβ‚‚ in `hf x₁ xβ‚‚ h` since they could be inferred from the type of h. We could have written `hf _ _ h` and Lean would have filled the holes denoted by _. Even better we could have written the definition of `non_decreasing` as: βˆ€ {x₁ xβ‚‚}, x₁ ≀ xβ‚‚ β†’ f x₁ ≀ f xβ‚‚, with curly braces to denote implicit arguments. But let's leave that aside for now. One possible variation on the above proof is to use the `specialize` tactic to replace hf by its specialization to the relevant value. -/ example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) := begin intros x₁ xβ‚‚ h, specialize hf _ _ h, exact hg _ _ hf, end example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) := begin intros x₁ xβ‚‚ h, specialize hf x₁ xβ‚‚ h, exact hg (f x₁) (f xβ‚‚) hf, end /- This `specialize` tactic is mostly useful for exploration, or in preparation for rewriting in the assumption. One can very often replace its use by using more complicated expressions directly involving the original assumption, as in the next variation: -/ example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) := begin intros x₁ xβ‚‚ h, exact hg (f x₁) (f xβ‚‚) (hf x₁ xβ‚‚ h), end /- Since the above proof uses only `intros` and `exact`, we could very easily replace it by the raw proof term: -/ example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) := Ξ» _ _ h, hg (f _) (f _) (hf _ _ h) /- Of course the above proof is difficult to decipher. The principle in mathlib is to use such a proof when the result is obvious and you don't want to read the proof anyway. Instead of pursuing this style, let's see how backward reasoning would look like here. As usual with this style, we use `apply` and enjoy Lean specializing assumptions for us using unification. -/ example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) := begin intros _ _ _, apply hg, apply hf, assumption end example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) := begin -- Let x₁ and xβ‚‚ be real numbers such that x₁ ≀ xβ‚‚ intros x₁ xβ‚‚ h, -- We need to prove (g ∘ f) x₁ ≀ (g ∘ f) xβ‚‚. -- Since g is non-decreasing, it suffices to prove f x₁ ≀ f xβ‚‚ apply hg, -- which follows from our assumption on f apply hf, -- and on x₁ and xβ‚‚ exact h end -- 0025 example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_increasing g) : non_increasing (g ∘ f) := begin intros x₁ xβ‚‚ h, apply hg, apply hf, assumption, end example (f g : ℝ β†’ ℝ) (hf : non_decreasing f) (hg : non_increasing g) : non_increasing (g ∘ f) := begin intros x₁ xβ‚‚ h, exact hg (f x₁) (f xβ‚‚) (hf x₁ xβ‚‚ h) end /- Let's switch to disjunctions now. Lean denotes by ∨ the logical OR operator. In order to make use of an assumption hyp : P ∨ Q we use the cases tactic: cases hyp with hP hQ which creates two proof branches: one branch assuming hP : P, and one branch assuming hQ : Q. In order to directly prove a goal P ∨ Q, we use either the `left` tactic and prove P or the `right` tactic and prove Q. In the next proof we use `ring` and `linarith` to get rid of easy computations or inequalities, as well as one lemma: mul_eq_zero : a*b = 0 ↔ a = 0 ∨ b = 0 -/ example (a b : ℝ) : a = a*b β†’ a = 0 ∨ b = 1 := begin intro h, have : a*(1 - b) = 0, by calc a*(1 - b) = a - a*b : by ring ... = 0 : by linarith, rw mul_eq_zero at this, cases this with ha hb, { left, assumption }, { right, linarith }, end example (a b : ℝ) : a = a*b β†’ a = 0 ∨ b = 1 := begin intro hyp, have H : a*(1 - b) = 0, { calc a*(1 - b) = a - a*b : by ring ... = 0 : by linarith, }, rw mul_eq_zero at H, cases H with Ha Hb, { left, exact Ha, }, { right, linarith, }, end -- 0026 example (x y : ℝ) : x^2 = y^2 β†’ x = y ∨ x = -y := begin intro h, have : (x - y) * (x + y) = 0, by calc (x - y) * (x + y) = x^2 - y^2 : by ring ... = y^2 - y^2 : by rw h ... = 0 : by ring, rw mul_eq_zero at this, cases this, { left, linarith }, { right, linarith } end /- In the next exercise, we can use: eq_or_lt_of_le : x ≀ y β†’ x = y ∨ x < y -/ -- 0027 example (f : ℝ β†’ ℝ) : non_decreasing f ↔ βˆ€ x y, x < y β†’ f x ≀ f y := begin split, { intros h₁ x y hβ‚‚, apply h₁, linarith }, { intros h₁ x y hβ‚‚, cases eq_or_lt_of_le hβ‚‚, { rw h }, { apply h₁, exact h } }, end /- In the next exercise, we can use: le_total x y : x ≀ y ∨ y ≀ x -/ -- 0028 example (f : ℝ β†’ ℝ) (h : non_decreasing f) (h' : βˆ€ x, f (f x) = x) : βˆ€ x, f x = x := begin intro x, have : f (f x) = x, by rw h', have : f x ≀ x ∨ x ≀ f x, from le_total _ _, cases this with hx hx; { specialize h _ _ hx, rw h' at h, linarith }, end -- 0028 example (f : ℝ β†’ ℝ) (h : non_decreasing f) (h' : βˆ€ x, f (f x) = x) : βˆ€ x, f x = x := begin -- sorry intro x, have : f (f x) = x, { rw h' }, have : (f x ≀ x) ∨ (x ≀ f x), { exact le_total (f x) x }, cases this with hx hx, { have f1: f (f x) ≀ f x, { exact h (f x) x hx, }, rw h' at f1, linarith, }, { have f1: f x ≀ f (f x), { exact h x (f x) hx, }, rw h' x at f1, linarith, }, -- sorry end
a3893bd5060e543e80d1ea8ac0c8920eeb005260
1abd1ed12aa68b375cdef28959f39531c6e95b84
/src/data/list/zip.lean
a59f35c18c33865dfd1bd9018c501833c080fd31
[ "Apache-2.0" ]
permissive
jumpy4/mathlib
d3829e75173012833e9f15ac16e481e17596de0f
af36f1a35f279f0e5b3c2a77647c6bf2cfd51a13
refs/heads/master
1,693,508,842,818
1,636,203,271,000
1,636,203,271,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
15,537
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kenny Lau -/ import data.list.basic /-! # zip & unzip This file provides results about `list.zip_with`, `list.zip` and `list.unzip` (definitions are in core Lean). `zip_with f l₁ lβ‚‚` applies `f : Ξ± β†’ Ξ² β†’ Ξ³` pointwise to a list `l₁ : list Ξ±` and `lβ‚‚ : list Ξ²`. It applies, until one of the lists is exhausted. For example, `zip_with f [0, 1, 2] [6.28, 31] = [f 0 6.28, f 1 31]`. `zip` is `zip_with` applied to `prod.mk`. For example, `zip [a₁, aβ‚‚] [b₁, bβ‚‚, b₃] = [(a₁, b₁), (aβ‚‚, bβ‚‚)]`. `unzip` undoes `zip`. For example, `unzip [(a₁, b₁), (aβ‚‚, bβ‚‚)] = ([a₁, aβ‚‚], [b₁, bβ‚‚])`. -/ universe u open nat namespace list variables {Ξ± : Type u} {Ξ² Ξ³ Ξ΄ : Type*} @[simp] theorem zip_with_cons_cons (f : Ξ± β†’ Ξ² β†’ Ξ³) (a : Ξ±) (b : Ξ²) (l₁ : list Ξ±) (lβ‚‚ : list Ξ²) : zip_with f (a :: l₁) (b :: lβ‚‚) = f a b :: zip_with f l₁ lβ‚‚ := rfl @[simp] theorem zip_cons_cons (a : Ξ±) (b : Ξ²) (l₁ : list Ξ±) (lβ‚‚ : list Ξ²) : zip (a :: l₁) (b :: lβ‚‚) = (a, b) :: zip l₁ lβ‚‚ := rfl @[simp] theorem zip_with_nil_left (f : Ξ± β†’ Ξ² β†’ Ξ³) (l) : zip_with f [] l = [] := rfl @[simp] theorem zip_with_nil_right (f : Ξ± β†’ Ξ² β†’ Ξ³) (l) : zip_with f l [] = [] := by cases l; refl @[simp] lemma zip_with_eq_nil_iff {f : Ξ± β†’ Ξ² β†’ Ξ³} {l l'} : zip_with f l l' = [] ↔ l = [] ∨ l' = [] := by { cases l; cases l'; simp } @[simp] theorem zip_nil_left (l : list Ξ±) : zip ([] : list Ξ²) l = [] := rfl @[simp] theorem zip_nil_right (l : list Ξ±) : zip l ([] : list Ξ²) = [] := zip_with_nil_right _ l @[simp] theorem zip_swap : βˆ€ (l₁ : list Ξ±) (lβ‚‚ : list Ξ²), (zip l₁ lβ‚‚).map prod.swap = zip lβ‚‚ l₁ | [] lβ‚‚ := (zip_nil_right _).symm | l₁ [] := by rw zip_nil_right; refl | (a::l₁) (b::lβ‚‚) := by simp only [zip_cons_cons, map_cons, zip_swap l₁ lβ‚‚, prod.swap_prod_mk]; split; refl @[simp] theorem length_zip_with (f : Ξ± β†’ Ξ² β†’ Ξ³) : βˆ€ (l₁ : list Ξ±) (lβ‚‚ : list Ξ²), length (zip_with f l₁ lβ‚‚) = min (length l₁) (length lβ‚‚) | [] lβ‚‚ := rfl | l₁ [] := by simp only [length, min_zero, zip_with_nil_right] | (a::l₁) (b::lβ‚‚) := by simp [length, zip_cons_cons, length_zip_with l₁ lβ‚‚, min_add_add_right] @[simp] theorem length_zip : βˆ€ (l₁ : list Ξ±) (lβ‚‚ : list Ξ²), length (zip l₁ lβ‚‚) = min (length l₁) (length lβ‚‚) := length_zip_with _ lemma lt_length_left_of_zip_with {f : Ξ± β†’ Ξ² β†’ Ξ³} {i : β„•} {l : list Ξ±} {l' : list Ξ²} (h : i < (zip_with f l l').length) : i < l.length := by { rw [length_zip_with, lt_min_iff] at h, exact h.left } lemma lt_length_right_of_zip_with {f : Ξ± β†’ Ξ² β†’ Ξ³} {i : β„•} {l : list Ξ±} {l' : list Ξ²} (h : i < (zip_with f l l').length) : i < l'.length := by { rw [length_zip_with, lt_min_iff] at h, exact h.right } lemma lt_length_left_of_zip {i : β„•} {l : list Ξ±} {l' : list Ξ²} (h : i < (zip l l').length) : i < l.length := lt_length_left_of_zip_with h lemma lt_length_right_of_zip {i : β„•} {l : list Ξ±} {l' : list Ξ²} (h : i < (zip l l').length) : i < l'.length := lt_length_right_of_zip_with h theorem zip_append : βˆ€ {l₁ r₁ : list Ξ±} {lβ‚‚ rβ‚‚ : list Ξ²} (h : length l₁ = length lβ‚‚), zip (l₁ ++ r₁) (lβ‚‚ ++ rβ‚‚) = zip l₁ lβ‚‚ ++ zip r₁ rβ‚‚ | [] r₁ lβ‚‚ rβ‚‚ h := by simp only [eq_nil_of_length_eq_zero h.symm]; refl | l₁ r₁ [] rβ‚‚ h := by simp only [eq_nil_of_length_eq_zero h]; refl | (a::l₁) r₁ (b::lβ‚‚) rβ‚‚ h := by simp only [cons_append, zip_cons_cons, zip_append (succ.inj h)]; split; refl theorem zip_map (f : Ξ± β†’ Ξ³) (g : Ξ² β†’ Ξ΄) : βˆ€ (l₁ : list Ξ±) (lβ‚‚ : list Ξ²), zip (l₁.map f) (lβ‚‚.map g) = (zip l₁ lβ‚‚).map (prod.map f g) | [] lβ‚‚ := rfl | l₁ [] := by simp only [map, zip_nil_right] | (a::l₁) (b::lβ‚‚) := by simp only [map, zip_cons_cons, zip_map l₁ lβ‚‚, prod.map]; split; refl theorem zip_map_left (f : Ξ± β†’ Ξ³) (l₁ : list Ξ±) (lβ‚‚ : list Ξ²) : zip (l₁.map f) lβ‚‚ = (zip l₁ lβ‚‚).map (prod.map f id) := by rw [← zip_map, map_id] theorem zip_map_right (f : Ξ² β†’ Ξ³) (l₁ : list Ξ±) (lβ‚‚ : list Ξ²) : zip l₁ (lβ‚‚.map f) = (zip l₁ lβ‚‚).map (prod.map id f) := by rw [← zip_map, map_id] @[simp] lemma zip_with_map {ΞΌ} (f : Ξ³ β†’ Ξ΄ β†’ ΞΌ) (g : Ξ± β†’ Ξ³) (h : Ξ² β†’ Ξ΄) (as : list Ξ±) (bs : list Ξ²) : zip_with f (as.map g) (bs.map h) = zip_with (Ξ» a b, f (g a) (h b)) as bs := begin induction as generalizing bs, { simp }, { cases bs; simp * } end lemma zip_with_map_left (f : Ξ± β†’ Ξ² β†’ Ξ³) (g : Ξ΄ β†’ Ξ±) (l : list Ξ΄) (l' : list Ξ²) : zip_with f (l.map g) l' = zip_with (f ∘ g) l l' := by { convert (zip_with_map f g id l l'), exact eq.symm (list.map_id _) } lemma zip_with_map_right (f : Ξ± β†’ Ξ² β†’ Ξ³) (l : list Ξ±) (g : Ξ΄ β†’ Ξ²) (l' : list Ξ΄) : zip_with f l (l'.map g) = zip_with (Ξ» x, f x ∘ g) l l' := by { convert (list.zip_with_map f id g l l'), exact eq.symm (list.map_id _) } theorem zip_map' (f : Ξ± β†’ Ξ²) (g : Ξ± β†’ Ξ³) : βˆ€ (l : list Ξ±), zip (l.map f) (l.map g) = l.map (Ξ» a, (f a, g a)) | [] := rfl | (a::l) := by simp only [map, zip_cons_cons, zip_map' l]; split; refl lemma map_zip_with {Ξ΄ : Type*} (f : Ξ± β†’ Ξ²) (g : Ξ³ β†’ Ξ΄ β†’ Ξ±) (l : list Ξ³) (l' : list Ξ΄) : map f (zip_with g l l') = zip_with (Ξ» x y, f (g x y)) l l' := begin induction l with hd tl hl generalizing l', { simp }, { cases l', { simp }, { simp [hl] } } end theorem mem_zip {a b} : βˆ€ {l₁ : list Ξ±} {lβ‚‚ : list Ξ²}, (a, b) ∈ zip l₁ lβ‚‚ β†’ a ∈ l₁ ∧ b ∈ lβ‚‚ | (_::l₁) (_::lβ‚‚) (or.inl rfl) := ⟨or.inl rfl, or.inl rfl⟩ | (a'::l₁) (b'::lβ‚‚) (or.inr h) := by split; simp only [mem_cons_iff, or_true, mem_zip h] theorem map_fst_zip : βˆ€ (l₁ : list Ξ±) (lβ‚‚ : list Ξ²), l₁.length ≀ lβ‚‚.length β†’ map prod.fst (zip l₁ lβ‚‚) = l₁ | [] bs _ := rfl | (a :: as) (b :: bs) h := by { simp at h, simp! * } | (a :: as) [] h := by { simp at h, contradiction } theorem map_snd_zip : βˆ€ (l₁ : list Ξ±) (lβ‚‚ : list Ξ²), lβ‚‚.length ≀ l₁.length β†’ map prod.snd (zip l₁ lβ‚‚) = lβ‚‚ | _ [] _ := by { rw zip_nil_right, refl } | [] (b :: bs) h := by { simp at h, contradiction } | (a :: as) (b :: bs) h := by { simp at h, simp! * } @[simp] theorem unzip_nil : unzip (@nil (Ξ± Γ— Ξ²)) = ([], []) := rfl @[simp] theorem unzip_cons (a : Ξ±) (b : Ξ²) (l : list (Ξ± Γ— Ξ²)) : unzip ((a, b) :: l) = (a :: (unzip l).1, b :: (unzip l).2) := by rw unzip; cases unzip l; refl theorem unzip_eq_map : βˆ€ (l : list (Ξ± Γ— Ξ²)), unzip l = (l.map prod.fst, l.map prod.snd) | [] := rfl | ((a, b) :: l) := by simp only [unzip_cons, map_cons, unzip_eq_map l] theorem unzip_left (l : list (Ξ± Γ— Ξ²)) : (unzip l).1 = l.map prod.fst := by simp only [unzip_eq_map] theorem unzip_right (l : list (Ξ± Γ— Ξ²)) : (unzip l).2 = l.map prod.snd := by simp only [unzip_eq_map] theorem unzip_swap (l : list (Ξ± Γ— Ξ²)) : unzip (l.map prod.swap) = (unzip l).swap := by simp only [unzip_eq_map, map_map]; split; refl theorem zip_unzip : βˆ€ (l : list (Ξ± Γ— Ξ²)), zip (unzip l).1 (unzip l).2 = l | [] := rfl | ((a, b) :: l) := by simp only [unzip_cons, zip_cons_cons, zip_unzip l]; split; refl theorem unzip_zip_left : βˆ€ {l₁ : list Ξ±} {lβ‚‚ : list Ξ²}, length l₁ ≀ length lβ‚‚ β†’ (unzip (zip l₁ lβ‚‚)).1 = l₁ | [] lβ‚‚ h := rfl | l₁ [] h := by rw eq_nil_of_length_eq_zero (nat.eq_zero_of_le_zero h); refl | (a::l₁) (b::lβ‚‚) h := by simp only [zip_cons_cons, unzip_cons, unzip_zip_left (le_of_succ_le_succ h)]; split; refl theorem unzip_zip_right {l₁ : list Ξ±} {lβ‚‚ : list Ξ²} (h : length lβ‚‚ ≀ length l₁) : (unzip (zip l₁ lβ‚‚)).2 = lβ‚‚ := by rw [← zip_swap, unzip_swap]; exact unzip_zip_left h theorem unzip_zip {l₁ : list Ξ±} {lβ‚‚ : list Ξ²} (h : length l₁ = length lβ‚‚) : unzip (zip l₁ lβ‚‚) = (l₁, lβ‚‚) := by rw [← @prod.mk.eta _ _ (unzip (zip l₁ lβ‚‚)), unzip_zip_left (le_of_eq h), unzip_zip_right (ge_of_eq h)] lemma zip_of_prod {l : list Ξ±} {l' : list Ξ²} {lp : list (Ξ± Γ— Ξ²)} (hl : lp.map prod.fst = l) (hr : lp.map prod.snd = l') : lp = l.zip l' := by rw [←hl, ←hr, ←zip_unzip lp, ←unzip_left, ←unzip_right, zip_unzip, zip_unzip] lemma map_prod_left_eq_zip {l : list Ξ±} (f : Ξ± β†’ Ξ²) : l.map (Ξ» x, (x, f x)) = l.zip (l.map f) := by { rw ←zip_map', congr, exact map_id _ } lemma map_prod_right_eq_zip {l : list Ξ±} (f : Ξ± β†’ Ξ²) : l.map (Ξ» x, (f x, x)) = (l.map f).zip l := by { rw ←zip_map', congr, exact map_id _ } lemma zip_with_comm (f : Ξ± β†’ Ξ± β†’ Ξ²) (comm : βˆ€ (x y : Ξ±), f x y = f y x) (l l' : list Ξ±) : zip_with f l l' = zip_with f l' l := begin induction l with hd tl hl generalizing l', { simp }, { cases l', { simp }, { simp [comm, hl] } } end instance (f : Ξ± β†’ Ξ± β†’ Ξ²) [is_symm_op Ξ± Ξ² f] : is_symm_op (list Ξ±) (list Ξ²) (zip_with f) := ⟨zip_with_comm f is_symm_op.symm_op⟩ @[simp] theorem length_revzip (l : list Ξ±) : length (revzip l) = length l := by simp only [revzip, length_zip, length_reverse, min_self] @[simp] theorem unzip_revzip (l : list Ξ±) : (revzip l).unzip = (l, l.reverse) := unzip_zip (length_reverse l).symm @[simp] theorem revzip_map_fst (l : list Ξ±) : (revzip l).map prod.fst = l := by rw [← unzip_left, unzip_revzip] @[simp] theorem revzip_map_snd (l : list Ξ±) : (revzip l).map prod.snd = l.reverse := by rw [← unzip_right, unzip_revzip] theorem reverse_revzip (l : list Ξ±) : reverse l.revzip = revzip l.reverse := by rw [← zip_unzip.{u u} (revzip l).reverse, unzip_eq_map]; simp; simp [revzip] theorem revzip_swap (l : list Ξ±) : (revzip l).map prod.swap = revzip l.reverse := by simp [revzip] lemma nth_zip_with (f : Ξ± β†’ Ξ² β†’ Ξ³) (l₁ : list Ξ±) (lβ‚‚ : list Ξ²) (i : β„•) : (zip_with f l₁ lβ‚‚).nth i = ((l₁.nth i).map f).bind (Ξ» g, (lβ‚‚.nth i).map g) := begin induction l₁ generalizing lβ‚‚ i, { simp [zip_with, (<*>)] }, { cases lβ‚‚; simp only [zip_with, has_seq.seq, functor.map, nth, option.map_none'], { cases ((l₁_hd :: l₁_tl).nth i); refl }, { cases i; simp only [option.map_some', nth, option.some_bind', *] } } end lemma nth_zip_with_eq_some {Ξ± Ξ² Ξ³} (f : Ξ± β†’ Ξ² β†’ Ξ³) (l₁ : list Ξ±) (lβ‚‚ : list Ξ²) (z : Ξ³) (i : β„•) : (zip_with f l₁ lβ‚‚).nth i = some z ↔ βˆƒ x y, l₁.nth i = some x ∧ lβ‚‚.nth i = some y ∧ f x y = z := begin induction l₁ generalizing lβ‚‚ i, { simp [zip_with] }, { cases lβ‚‚; simp only [zip_with, nth, exists_false, and_false, false_and], cases i; simp *, }, end lemma nth_zip_eq_some (l₁ : list Ξ±) (lβ‚‚ : list Ξ²) (z : Ξ± Γ— Ξ²) (i : β„•) : (zip l₁ lβ‚‚).nth i = some z ↔ l₁.nth i = some z.1 ∧ lβ‚‚.nth i = some z.2 := begin cases z, rw [zip, nth_zip_with_eq_some], split, { rintro ⟨x, y, hβ‚€, h₁, hβ‚‚βŸ©, cc }, { rintro ⟨hβ‚€, hβ‚βŸ©, exact ⟨_,_,hβ‚€,h₁,rfl⟩ } end @[simp] lemma nth_le_zip_with {f : Ξ± β†’ Ξ² β†’ Ξ³} {l : list Ξ±} {l' : list Ξ²} {i : β„•} {h : i < (zip_with f l l').length} : (zip_with f l l').nth_le i h = f (l.nth_le i (lt_length_left_of_zip_with h)) (l'.nth_le i (lt_length_right_of_zip_with h)) := begin rw [←option.some_inj, ←nth_le_nth, nth_zip_with_eq_some], refine ⟨l.nth_le i (lt_length_left_of_zip_with h), l'.nth_le i (lt_length_right_of_zip_with h), nth_le_nth _, _⟩, simp only [←nth_le_nth, eq_self_iff_true, and_self] end @[simp] lemma nth_le_zip {l : list Ξ±} {l' : list Ξ²} {i : β„•} {h : i < (zip l l').length} : (zip l l').nth_le i h = (l.nth_le i (lt_length_left_of_zip h), l'.nth_le i (lt_length_right_of_zip h)) := nth_le_zip_with lemma mem_zip_inits_tails {l : list Ξ±} {init tail : list Ξ±} : (init, tail) ∈ zip l.inits l.tails ↔ init ++ tail = l := begin induction l generalizing init tail; simp_rw [tails, inits, zip_cons_cons], { simp }, { split; rw [mem_cons_iff, zip_map_left, mem_map, prod.exists], { rintros (⟨rfl, rfl⟩ | ⟨_, _, h, rfl, rfl⟩), { simp }, { simp [l_ih.mp h], }, }, { cases init, { simp }, { intro h, right, use [init_tl, tail], simp * at *, }, }, }, end lemma map_uncurry_zip_eq_zip_with (f : Ξ± β†’ Ξ² β†’ Ξ³) (l : list Ξ±) (l' : list Ξ²) : map (function.uncurry f) (l.zip l') = zip_with f l l' := begin induction l with hd tl hl generalizing l', { simp }, { cases l' with hd' tl', { simp }, { simp [hl] } } end @[simp] lemma sum_zip_with_distrib_left {Ξ³ : Type*} [semiring Ξ³] (f : Ξ± β†’ Ξ² β†’ Ξ³) (n : Ξ³) (l : list Ξ±) (l' : list Ξ²) : (l.zip_with (Ξ» x y, n * f x y) l').sum = n * (l.zip_with f l').sum := begin induction l with hd tl hl generalizing f n l', { simp }, { cases l' with hd' tl', { simp, }, { simp [hl, mul_add] } } end section distrib /-! ### Operations that can be applied before or after a `zip_with` -/ variables (f : Ξ± β†’ Ξ² β†’ Ξ³) (l : list Ξ±) (l' : list Ξ²) (n : β„•) lemma zip_with_distrib_take : (zip_with f l l').take n = zip_with f (l.take n) (l'.take n) := begin induction l with hd tl hl generalizing l' n, { simp }, { cases l', { simp }, { cases n, { simp }, { simp [hl] } } } end lemma zip_with_distrib_drop : (zip_with f l l').drop n = zip_with f (l.drop n) (l'.drop n) := begin induction l with hd tl hl generalizing l' n, { simp }, { cases l', { simp }, { cases n, { simp }, { simp [hl] } } } end lemma zip_with_distrib_tail : (zip_with f l l').tail = zip_with f l.tail l'.tail := by simp_rw [←drop_one, zip_with_distrib_drop] lemma zip_with_append (f : Ξ± β†’ Ξ² β†’ Ξ³) (l la : list Ξ±) (l' lb : list Ξ²) (h : l.length = l'.length) : zip_with f (l ++ la) (l' ++ lb) = zip_with f l l' ++ zip_with f la lb := begin induction l with hd tl hl generalizing l', { have : l' = [] := eq_nil_of_length_eq_zero (by simpa using h.symm), simp [this], }, { cases l', { simpa using h }, { simp only [add_left_inj, length] at h, simp [hl _ h] } } end lemma zip_with_distrib_reverse (h : l.length = l'.length) : (zip_with f l l').reverse = zip_with f l.reverse l'.reverse := begin induction l with hd tl hl generalizing l', { simp }, { cases l' with hd' tl', { simp }, { simp only [add_left_inj, length] at h, have : tl.reverse.length = tl'.reverse.length := by simp [h], simp [hl _ h, zip_with_append _ _ _ _ _ this] } } end end distrib section comm_monoid variables [comm_monoid Ξ±] @[to_additive] lemma prod_mul_prod_eq_prod_zip_with_mul_prod_drop : βˆ€ (L L' : list Ξ±), L.prod * L'.prod = (zip_with (*) L L').prod * (L.drop L'.length).prod * (L'.drop L.length).prod | [] ys := by simp | xs [] := by simp | (x :: xs) (y :: ys) := begin simp only [drop, length, zip_with_cons_cons, prod_cons], rw [mul_assoc x, mul_comm xs.prod, mul_assoc y, mul_comm ys.prod, prod_mul_prod_eq_prod_zip_with_mul_prod_drop xs ys, mul_assoc, mul_assoc, mul_assoc, mul_assoc] end @[to_additive] lemma prod_mul_prod_eq_prod_zip_with_of_length_eq (L L' : list Ξ±) (h : L.length = L'.length) : L.prod * L'.prod = (zip_with (*) L L').prod := (prod_mul_prod_eq_prod_zip_with_mul_prod_drop L L').trans (by simp [h]) end comm_monoid end list
aaa1e987cbef840b4a601dc34703494b93d92242
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/data/seq/wseq.lean
4182c7fe937a7f702fe35a7dddcc48735062b54e
[ "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
55,376
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import data.list.basic import data.seq.seq open function universes u v w /- coinductive wseq (Ξ± : Type u) : Type u | nil : wseq Ξ± | cons : Ξ± β†’ wseq Ξ± β†’ wseq Ξ± | think : wseq Ξ± β†’ wseq Ξ± -/ /-- Weak sequences. While the `seq` structure allows for lists which may not be finite, a weak sequence also allows the computation of each element to involve an indeterminate amount of computation, including possibly an infinite loop. This is represented as a regular `seq` interspersed with `none` elements to indicate that computation is ongoing. This model is appropriate for Haskell style lazy lists, and is closed under most interesting computation patterns on infinite lists, but conversely it is difficult to extract elements from it. -/ def wseq (Ξ±) := seq (option Ξ±) namespace wseq variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} /-- Turn a sequence into a weak sequence -/ def of_seq : seq Ξ± β†’ wseq Ξ± := (<$>) some /-- Turn a list into a weak sequence -/ def of_list (l : list Ξ±) : wseq Ξ± := of_seq l /-- Turn a stream into a weak sequence -/ def of_stream (l : stream Ξ±) : wseq Ξ± := of_seq l instance coe_seq : has_coe (seq Ξ±) (wseq Ξ±) := ⟨of_seq⟩ instance coe_list : has_coe (list Ξ±) (wseq Ξ±) := ⟨of_list⟩ instance coe_stream : has_coe (stream Ξ±) (wseq Ξ±) := ⟨of_stream⟩ /-- The empty weak sequence -/ def nil : wseq Ξ± := seq.nil instance : inhabited (wseq Ξ±) := ⟨nil⟩ /-- Prepend an element to a weak sequence -/ def cons (a : Ξ±) : wseq Ξ± β†’ wseq Ξ± := seq.cons (some a) /-- Compute for one tick, without producing any elements -/ def think : wseq Ξ± β†’ wseq Ξ± := seq.cons none /-- Destruct a weak sequence, to (eventually possibly) produce either `none` for `nil` or `some (a, s)` if an element is produced. -/ def destruct : wseq Ξ± β†’ computation (option (Ξ± Γ— wseq Ξ±)) := computation.corec (Ξ» s, match seq.destruct s with | none := sum.inl none | some (none, s') := sum.inr s' | some (some a, s') := sum.inl (some (a, s')) end) /-- Recursion principle for weak sequences, compare with `list.rec_on`. -/ def rec_on {C : wseq Ξ± β†’ Sort v} (s : wseq Ξ±) (h1 : C nil) (h2 : βˆ€ x s, C (cons x s)) (h3 : βˆ€ s, C (think s)) : C s := seq.rec_on s h1 (Ξ» o, option.rec_on o h3 h2) protected def mem (a : Ξ±) (s : wseq Ξ±) := seq.mem (some a) s instance : has_mem Ξ± (wseq Ξ±) := ⟨wseq.mem⟩ theorem not_mem_nil (a : Ξ±) : a βˆ‰ @nil Ξ± := seq.not_mem_nil a /-- Get the head of a weak sequence. This involves a possibly infinite computation. -/ def head (s : wseq Ξ±) : computation (option Ξ±) := computation.map ((<$>) prod.fst) (destruct s) /-- Encode a computation yielding a weak sequence into additional `think` constructors in a weak sequence -/ def flatten : computation (wseq Ξ±) β†’ wseq Ξ± := seq.corec (Ξ» c, match computation.destruct c with | sum.inl s := seq.omap return (seq.destruct s) | sum.inr c' := some (none, c') end) /-- Get the tail of a weak sequence. This doesn't need a `computation` wrapper, unlike `head`, because `flatten` allows us to hide this in the construction of the weak sequence itself. -/ def tail (s : wseq Ξ±) : wseq Ξ± := flatten $ (Ξ» o, option.rec_on o nil prod.snd) <$> destruct s /-- drop the first `n` elements from `s`. -/ def drop (s : wseq Ξ±) : β„• β†’ wseq Ξ± | 0 := s | (n+1) := tail (drop n) attribute [simp] drop /-- Get the nth element of `s`. -/ def nth (s : wseq Ξ±) (n : β„•) : computation (option Ξ±) := head (drop s n) /-- Convert `s` to a list (if it is finite and completes in finite time). -/ def to_list (s : wseq Ξ±) : computation (list Ξ±) := @computation.corec (list Ξ±) (list Ξ± Γ— wseq Ξ±) (Ξ» ⟨l, s⟩, match seq.destruct s with | none := sum.inl l.reverse | some (none, s') := sum.inr (l, s') | some (some a, s') := sum.inr (a::l, s') end) ([], s) /-- Get the length of `s` (if it is finite and completes in finite time). -/ def length (s : wseq Ξ±) : computation β„• := @computation.corec β„• (β„• Γ— wseq Ξ±) (Ξ» ⟨n, s⟩, match seq.destruct s with | none := sum.inl n | some (none, s') := sum.inr (n, s') | some (some a, s') := sum.inr (n+1, s') end) (0, s) /-- A weak sequence is finite if `to_list s` terminates. Equivalently, it is a finite number of `think` and `cons` applied to `nil`. -/ class is_finite (s : wseq Ξ±) : Prop := (out : (to_list s).terminates) instance to_list_terminates (s : wseq Ξ±) [h : is_finite s] : (to_list s).terminates := h.out /-- Get the list corresponding to a finite weak sequence. -/ def get (s : wseq Ξ±) [is_finite s] : list Ξ± := (to_list s).get /-- A weak sequence is *productive* if it never stalls forever - there are always a finite number of `think`s between `cons` constructors. The sequence itself is allowed to be infinite though. -/ class productive (s : wseq Ξ±) : Prop := (nth_terminates : βˆ€ n, (nth s n).terminates) theorem productive_iff (s : wseq Ξ±) : productive s ↔ βˆ€ n, (nth s n).terminates := ⟨λ h, h.1, Ξ» h, ⟨h⟩⟩ instance nth_terminates (s : wseq Ξ±) [h : productive s] : βˆ€ n, (nth s n).terminates := h.nth_terminates instance head_terminates (s : wseq Ξ±) [productive s] : (head s).terminates := s.nth_terminates 0 /-- Replace the `n`th element of `s` with `a`. -/ def update_nth (s : wseq Ξ±) (n : β„•) (a : Ξ±) : wseq Ξ± := @seq.corec (option Ξ±) (β„• Γ— wseq Ξ±) (Ξ» ⟨n, s⟩, match seq.destruct s, n with | none, n := none | some (none, s'), n := some (none, n, s') | some (some a', s'), 0 := some (some a', 0, s') | some (some a', s'), 1 := some (some a, 0, s') | some (some a', s'), (n+2) := some (some a', n+1, s') end) (n+1, s) /-- Remove the `n`th element of `s`. -/ def remove_nth (s : wseq Ξ±) (n : β„•) : wseq Ξ± := @seq.corec (option Ξ±) (β„• Γ— wseq Ξ±) (Ξ» ⟨n, s⟩, match seq.destruct s, n with | none, n := none | some (none, s'), n := some (none, n, s') | some (some a', s'), 0 := some (some a', 0, s') | some (some a', s'), 1 := some (none, 0, s') | some (some a', s'), (n+2) := some (some a', n+1, s') end) (n+1, s) /-- Map the elements of `s` over `f`, removing any values that yield `none`. -/ def filter_map (f : Ξ± β†’ option Ξ²) : wseq Ξ± β†’ wseq Ξ² := seq.corec (Ξ» s, match seq.destruct s with | none := none | some (none, s') := some (none, s') | some (some a, s') := some (f a, s') end) /-- Select the elements of `s` that satisfy `p`. -/ def filter (p : Ξ± β†’ Prop) [decidable_pred p] : wseq Ξ± β†’ wseq Ξ± := filter_map (Ξ» a, if p a then some a else none) -- example of infinite list manipulations /-- Get the first element of `s` satisfying `p`. -/ def find (p : Ξ± β†’ Prop) [decidable_pred p] (s : wseq Ξ±) : computation (option Ξ±) := head $ filter p s /-- Zip a function over two weak sequences -/ def zip_with (f : Ξ± β†’ Ξ² β†’ Ξ³) (s1 : wseq Ξ±) (s2 : wseq Ξ²) : wseq Ξ³ := @seq.corec (option Ξ³) (wseq Ξ± Γ— wseq Ξ²) (Ξ» ⟨s1, s2⟩, match seq.destruct s1, seq.destruct s2 with | some (none, s1'), some (none, s2') := some (none, s1', s2') | some (some a1, s1'), some (none, s2') := some (none, s1, s2') | some (none, s1'), some (some a2, s2') := some (none, s1', s2) | some (some a1, s1'), some (some a2, s2') := some (some (f a1 a2), s1', s2') | _, _ := none end) (s1, s2) /-- Zip two weak sequences into a single sequence of pairs -/ def zip : wseq Ξ± β†’ wseq Ξ² β†’ wseq (Ξ± Γ— Ξ²) := zip_with prod.mk /-- Get the list of indexes of elements of `s` satisfying `p` -/ def find_indexes (p : Ξ± β†’ Prop) [decidable_pred p] (s : wseq Ξ±) : wseq β„• := (zip s (stream.nats : wseq β„•)).filter_map (Ξ» ⟨a, n⟩, if p a then some n else none) /-- Get the index of the first element of `s` satisfying `p` -/ def find_index (p : Ξ± β†’ Prop) [decidable_pred p] (s : wseq Ξ±) : computation β„• := (Ξ» o, option.get_or_else o 0) <$> head (find_indexes p s) /-- Get the index of the first occurrence of `a` in `s` -/ def index_of [decidable_eq Ξ±] (a : Ξ±) : wseq Ξ± β†’ computation β„• := find_index (eq a) /-- Get the indexes of occurrences of `a` in `s` -/ def indexes_of [decidable_eq Ξ±] (a : Ξ±) : wseq Ξ± β†’ wseq β„• := find_indexes (eq a) /-- `union s1 s2` is a weak sequence which interleaves `s1` and `s2` in some order (nondeterministically). -/ def union (s1 s2 : wseq Ξ±) : wseq Ξ± := @seq.corec (option Ξ±) (wseq Ξ± Γ— wseq Ξ±) (Ξ» ⟨s1, s2⟩, match seq.destruct s1, seq.destruct s2 with | none, none := none | some (a1, s1'), none := some (a1, s1', nil) | none, some (a2, s2') := some (a2, nil, s2') | some (none, s1'), some (none, s2') := some (none, s1', s2') | some (some a1, s1'), some (none, s2') := some (some a1, s1', s2') | some (none, s1'), some (some a2, s2') := some (some a2, s1', s2') | some (some a1, s1'), some (some a2, s2') := some (some a1, cons a2 s1', s2') end) (s1, s2) /-- Returns `tt` if `s` is `nil` and `ff` if `s` has an element -/ def is_empty (s : wseq Ξ±) : computation bool := computation.map option.is_none $ head s /-- Calculate one step of computation -/ def compute (s : wseq Ξ±) : wseq Ξ± := match seq.destruct s with | some (none, s') := s' | _ := s end /-- Get the first `n` elements of a weak sequence -/ def take (s : wseq Ξ±) (n : β„•) : wseq Ξ± := @seq.corec (option Ξ±) (β„• Γ— wseq Ξ±) (Ξ» ⟨n, s⟩, match n, seq.destruct s with | 0, _ := none | m+1, none := none | m+1, some (none, s') := some (none, m+1, s') | m+1, some (some a, s') := some (some a, m, s') end) (n, s) /-- Split the sequence at position `n` into a finite initial segment and the weak sequence tail -/ def split_at (s : wseq Ξ±) (n : β„•) : computation (list Ξ± Γ— wseq Ξ±) := @computation.corec (list Ξ± Γ— wseq Ξ±) (β„• Γ— list Ξ± Γ— wseq Ξ±) (Ξ» ⟨n, l, s⟩, match n, seq.destruct s with | 0, _ := sum.inl (l.reverse, s) | m+1, none := sum.inl (l.reverse, s) | m+1, some (none, s') := sum.inr (n, l, s') | m+1, some (some a, s') := sum.inr (m, a::l, s') end) (n, [], s) /-- Returns `tt` if any element of `s` satisfies `p` -/ def any (s : wseq Ξ±) (p : Ξ± β†’ bool) : computation bool := computation.corec (Ξ» s : wseq Ξ±, match seq.destruct s with | none := sum.inl ff | some (none, s') := sum.inr s' | some (some a, s') := if p a then sum.inl tt else sum.inr s' end) s /-- Returns `tt` if every element of `s` satisfies `p` -/ def all (s : wseq Ξ±) (p : Ξ± β†’ bool) : computation bool := computation.corec (Ξ» s : wseq Ξ±, match seq.destruct s with | none := sum.inl tt | some (none, s') := sum.inr s' | some (some a, s') := if p a then sum.inr s' else sum.inl ff end) s /-- Apply a function to the elements of the sequence to produce a sequence of partial results. (There is no `scanr` because this would require working from the end of the sequence, which may not exist.) -/ def scanl (f : Ξ± β†’ Ξ² β†’ Ξ±) (a : Ξ±) (s : wseq Ξ²) : wseq Ξ± := cons a $ @seq.corec (option Ξ±) (Ξ± Γ— wseq Ξ²) (Ξ» ⟨a, s⟩, match seq.destruct s with | none := none | some (none, s') := some (none, a, s') | some (some b, s') := let a' := f a b in some (some a', a', s') end) (a, s) /-- Get the weak sequence of initial segments of the input sequence -/ def inits (s : wseq Ξ±) : wseq (list Ξ±) := cons [] $ @seq.corec (option (list Ξ±)) (dlist Ξ± Γ— wseq Ξ±) (Ξ» ⟨l, s⟩, match seq.destruct s with | none := none | some (none, s') := some (none, l, s') | some (some a, s') := let l' := l.concat a in some (some l'.to_list, l', s') end) (dlist.empty, s) /-- Like take, but does not wait for a result. Calculates `n` steps of computation and returns the sequence computed so far -/ def collect (s : wseq Ξ±) (n : β„•) : list Ξ± := (seq.take n s).filter_map id /-- Append two weak sequences. As with `seq.append`, this may not use the second sequence if the first one takes forever to compute -/ def append : wseq Ξ± β†’ wseq Ξ± β†’ wseq Ξ± := seq.append /-- Map a function over a weak sequence -/ def map (f : Ξ± β†’ Ξ²) : wseq Ξ± β†’ wseq Ξ² := seq.map (option.map f) /-- Flatten a sequence of weak sequences. (Note that this allows empty sequences, unlike `seq.join`.) -/ def join (S : wseq (wseq Ξ±)) : wseq Ξ± := seq.join ((Ξ» o : option (wseq Ξ±), match o with | none := seq1.ret none | some s := (none, s) end) <$> S) /-- Monadic bind operator for weak sequences -/ def bind (s : wseq Ξ±) (f : Ξ± β†’ wseq Ξ²) : wseq Ξ² := join (map f s) @[simp] def lift_rel_o (R : Ξ± β†’ Ξ² β†’ Prop) (C : wseq Ξ± β†’ wseq Ξ² β†’ Prop) : option (Ξ± Γ— wseq Ξ±) β†’ option (Ξ² Γ— wseq Ξ²) β†’ Prop | none none := true | (some (a, s)) (some (b, t)) := R a b ∧ C s t | _ _ := false theorem lift_rel_o.imp {R S : Ξ± β†’ Ξ² β†’ Prop} {C D : wseq Ξ± β†’ wseq Ξ² β†’ Prop} (H1 : βˆ€ a b, R a b β†’ S a b) (H2 : βˆ€ s t, C s t β†’ D s t) : βˆ€ {o p}, lift_rel_o R C o p β†’ lift_rel_o S D o p | none none h := trivial | (some (a, s)) (some (b, t)) h := and.imp (H1 _ _) (H2 _ _) h | none (some _) h := false.elim h | (some (_, _)) none h := false.elim h theorem lift_rel_o.imp_right (R : Ξ± β†’ Ξ² β†’ Prop) {C D : wseq Ξ± β†’ wseq Ξ² β†’ Prop} (H : βˆ€ s t, C s t β†’ D s t) {o p} : lift_rel_o R C o p β†’ lift_rel_o R D o p := lift_rel_o.imp (Ξ» _ _, id) H @[simp] def bisim_o (R : wseq Ξ± β†’ wseq Ξ± β†’ Prop) : option (Ξ± Γ— wseq Ξ±) β†’ option (Ξ± Γ— wseq Ξ±) β†’ Prop := lift_rel_o (=) R theorem bisim_o.imp {R S : wseq Ξ± β†’ wseq Ξ± β†’ Prop} (H : βˆ€ s t, R s t β†’ S s t) {o p} : bisim_o R o p β†’ bisim_o S o p := lift_rel_o.imp_right _ H /-- Two weak sequences are `lift_rel R` related if they are either both empty, or they are both nonempty and the heads are `R` related and the tails are `lift_rel R` related. (This is a coinductive definition.) -/ def lift_rel (R : Ξ± β†’ Ξ² β†’ Prop) (s : wseq Ξ±) (t : wseq Ξ²) : Prop := βˆƒ C : wseq Ξ± β†’ wseq Ξ² β†’ Prop, C s t ∧ βˆ€ {s t}, C s t β†’ computation.lift_rel (lift_rel_o R C) (destruct s) (destruct t) /-- If two sequences are equivalent, then they have the same values and the same computational behavior (i.e. if one loops forever then so does the other), although they may differ in the number of `think`s needed to arrive at the answer. -/ def equiv : wseq Ξ± β†’ wseq Ξ± β†’ Prop := lift_rel (=) theorem lift_rel_destruct {R : Ξ± β†’ Ξ² β†’ Prop} {s : wseq Ξ±} {t : wseq Ξ²} : lift_rel R s t β†’ computation.lift_rel (lift_rel_o R (lift_rel R)) (destruct s) (destruct t) | ⟨R, h1, h2⟩ := by refine computation.lift_rel.imp _ _ _ (h2 h1); apply lift_rel_o.imp_right; exact Ξ» s' t' h', ⟨R, h', @h2⟩ theorem lift_rel_destruct_iff {R : Ξ± β†’ Ξ² β†’ Prop} {s : wseq Ξ±} {t : wseq Ξ²} : lift_rel R s t ↔ computation.lift_rel (lift_rel_o R (lift_rel R)) (destruct s) (destruct t) := ⟨lift_rel_destruct, Ξ» h, ⟨λ s t, lift_rel R s t ∨ computation.lift_rel (lift_rel_o R (lift_rel R)) (destruct s) (destruct t), or.inr h, Ξ» s t h, begin have h : computation.lift_rel (lift_rel_o R (lift_rel R)) (destruct s) (destruct t), { cases h with h h, exact lift_rel_destruct h, assumption }, apply computation.lift_rel.imp _ _ _ h, intros a b, apply lift_rel_o.imp_right, intros s t, apply or.inl end⟩⟩ infix (name := equiv) ` ~ `:50 := equiv theorem destruct_congr {s t : wseq Ξ±} : s ~ t β†’ computation.lift_rel (bisim_o (~)) (destruct s) (destruct t) := lift_rel_destruct theorem destruct_congr_iff {s t : wseq Ξ±} : s ~ t ↔ computation.lift_rel (bisim_o (~)) (destruct s) (destruct t) := lift_rel_destruct_iff theorem lift_rel.refl (R : Ξ± β†’ Ξ± β†’ Prop) (H : reflexive R) : reflexive (lift_rel R) := Ξ» s, begin refine ⟨(=), rfl, Ξ» s t (h : s = t), _⟩, rw ←h, apply computation.lift_rel.refl, intro a, cases a with a, simp, cases a; simp, apply H end theorem lift_rel_o.swap (R : Ξ± β†’ Ξ² β†’ Prop) (C) : swap (lift_rel_o R C) = lift_rel_o (swap R) (swap C) := by funext x y; cases x with x; [skip, cases x]; { cases y with y; [skip, cases y]; refl } theorem lift_rel.swap_lem {R : Ξ± β†’ Ξ² β†’ Prop} {s1 s2} (h : lift_rel R s1 s2) : lift_rel (swap R) s2 s1 := begin refine ⟨swap (lift_rel R), h, Ξ» s t (h : lift_rel R t s), _⟩, rw [←lift_rel_o.swap, computation.lift_rel.swap], apply lift_rel_destruct h end theorem lift_rel.swap (R : Ξ± β†’ Ξ² β†’ Prop) : swap (lift_rel R) = lift_rel (swap R) := funext $ Ξ» x, funext $ Ξ» y, propext ⟨lift_rel.swap_lem, lift_rel.swap_lem⟩ theorem lift_rel.symm (R : Ξ± β†’ Ξ± β†’ Prop) (H : symmetric R) : symmetric (lift_rel R) := Ξ» s1 s2 (h : swap (lift_rel R) s2 s1), by rwa [lift_rel.swap, show swap R = R, from funext $ Ξ» a, funext $ Ξ» b, propext $ by constructor; apply H] at h theorem lift_rel.trans (R : Ξ± β†’ Ξ± β†’ Prop) (H : transitive R) : transitive (lift_rel R) := Ξ» s t u h1 h2, begin refine ⟨λ s u, βˆƒ t, lift_rel R s t ∧ lift_rel R t u, ⟨t, h1, h2⟩, Ξ» s u h, _⟩, rcases h with ⟨t, h1, h2⟩, have h1 := lift_rel_destruct h1, have h2 := lift_rel_destruct h2, refine computation.lift_rel_def.2 ⟨(computation.terminates_of_lift_rel h1).trans (computation.terminates_of_lift_rel h2), Ξ» a c ha hc, _⟩, rcases h1.left ha with ⟨b, hb, t1⟩, have t2 := computation.rel_of_lift_rel h2 hb hc, cases a with a; cases c with c, { trivial }, { cases b, {cases t2}, {cases t1} }, { cases a, cases b with b, {cases t1}, {cases b, cases t2} }, { cases a with a s, cases b with b, {cases t1}, cases b with b t, cases c with c u, cases t1 with ab st, cases t2 with bc tu, exact ⟨H ab bc, t, st, tu⟩ } end theorem lift_rel.equiv (R : Ξ± β†’ Ξ± β†’ Prop) : equivalence R β†’ equivalence (lift_rel R) | ⟨refl, symm, trans⟩ := ⟨lift_rel.refl R refl, lift_rel.symm R symm, lift_rel.trans R trans⟩ @[refl] theorem equiv.refl : βˆ€ (s : wseq Ξ±), s ~ s := lift_rel.refl (=) eq.refl @[symm] theorem equiv.symm : βˆ€ {s t : wseq Ξ±}, s ~ t β†’ t ~ s := lift_rel.symm (=) (@eq.symm _) @[trans] theorem equiv.trans : βˆ€ {s t u : wseq Ξ±}, s ~ t β†’ t ~ u β†’ s ~ u := lift_rel.trans (=) (@eq.trans _) theorem equiv.equivalence : equivalence (@equiv Ξ±) := ⟨@equiv.refl _, @equiv.symm _, @equiv.trans _⟩ open computation local notation `return` := computation.return @[simp] theorem destruct_nil : destruct (nil : wseq Ξ±) = return none := computation.destruct_eq_ret rfl @[simp] theorem destruct_cons (a : Ξ±) (s) : destruct (cons a s) = return (some (a, s)) := computation.destruct_eq_ret $ by simp [destruct, cons, computation.rmap] @[simp] theorem destruct_think (s : wseq Ξ±) : destruct (think s) = (destruct s).think := computation.destruct_eq_think $ by simp [destruct, think, computation.rmap] @[simp] theorem seq_destruct_nil : seq.destruct (nil : wseq Ξ±) = none := seq.destruct_nil @[simp] theorem seq_destruct_cons (a : Ξ±) (s) : seq.destruct (cons a s) = some (some a, s) := seq.destruct_cons _ _ @[simp] theorem seq_destruct_think (s : wseq Ξ±) : seq.destruct (think s) = some (none, s) := seq.destruct_cons _ _ @[simp] theorem head_nil : head (nil : wseq Ξ±) = return none := by simp [head]; refl @[simp] theorem head_cons (a : Ξ±) (s) : head (cons a s) = return (some a) := by simp [head]; refl @[simp] theorem head_think (s : wseq Ξ±) : head (think s) = (head s).think := by simp [head]; refl @[simp] theorem flatten_ret (s : wseq Ξ±) : flatten (return s) = s := begin refine seq.eq_of_bisim (Ξ» s1 s2, flatten (return s2) = s1) _ rfl, intros s' s h, rw ←h, simp [flatten], cases seq.destruct s, { simp }, { cases val with o s', simp } end @[simp] theorem flatten_think (c : computation (wseq Ξ±)) : flatten c.think = think (flatten c) := seq.destruct_eq_cons $ by simp [flatten, think] @[simp] theorem destruct_flatten (c : computation (wseq Ξ±)) : destruct (flatten c) = c >>= destruct := begin refine computation.eq_of_bisim (Ξ» c1 c2, c1 = c2 ∨ βˆƒ c, c1 = destruct (flatten c) ∧ c2 = computation.bind c destruct) _ (or.inr ⟨c, rfl, rfl⟩), intros c1 c2 h, exact match c1, c2, h with | _, _, (or.inl $ eq.refl c) := by cases c.destruct; simp | _, _, (or.inr ⟨c, rfl, rfl⟩) := begin apply c.rec_on (Ξ» a, _) (Ξ» c', _); repeat {simp}, { cases (destruct a).destruct; simp }, { exact or.inr ⟨c', rfl, rfl⟩ } end end end theorem head_terminates_iff (s : wseq Ξ±) : terminates (head s) ↔ terminates (destruct s) := terminates_map_iff _ (destruct s) @[simp] theorem tail_nil : tail (nil : wseq Ξ±) = nil := by simp [tail] @[simp] theorem tail_cons (a : Ξ±) (s) : tail (cons a s) = s := by simp [tail] @[simp] theorem tail_think (s : wseq Ξ±) : tail (think s) = (tail s).think := by simp [tail] @[simp] theorem dropn_nil (n) : drop (nil : wseq Ξ±) n = nil := by induction n; simp [*, drop] @[simp] theorem dropn_cons (a : Ξ±) (s) (n) : drop (cons a s) (n+1) = drop s n := by induction n; simp [*, drop] @[simp] theorem dropn_think (s : wseq Ξ±) (n) : drop (think s) n = (drop s n).think := by induction n; simp [*, drop] theorem dropn_add (s : wseq Ξ±) (m) : βˆ€ n, drop s (m + n) = drop (drop s m) n | 0 := rfl | (n+1) := congr_arg tail (dropn_add n) theorem dropn_tail (s : wseq Ξ±) (n) : drop (tail s) n = drop s (n + 1) := by rw add_comm; symmetry; apply dropn_add theorem nth_add (s : wseq Ξ±) (m n) : nth s (m + n) = nth (drop s m) n := congr_arg head (dropn_add _ _ _) theorem nth_tail (s : wseq Ξ±) (n) : nth (tail s) n = nth s (n + 1) := congr_arg head (dropn_tail _ _) @[simp] theorem join_nil : join nil = (nil : wseq Ξ±) := seq.join_nil @[simp] theorem join_think (S : wseq (wseq Ξ±)) : join (think S) = think (join S) := by { simp [think, join], unfold functor.map, simp [join, seq1.ret] } @[simp] theorem join_cons (s : wseq Ξ±) (S) : join (cons s S) = think (append s (join S)) := by { simp [think, join], unfold functor.map, simp [join, cons, append] } @[simp] theorem nil_append (s : wseq Ξ±) : append nil s = s := seq.nil_append _ @[simp] theorem cons_append (a : Ξ±) (s t) : append (cons a s) t = cons a (append s t) := seq.cons_append _ _ _ @[simp] theorem think_append (s t : wseq Ξ±) : append (think s) t = think (append s t) := seq.cons_append _ _ _ @[simp] theorem append_nil (s : wseq Ξ±) : append s nil = s := seq.append_nil _ @[simp] theorem append_assoc (s t u : wseq Ξ±) : append (append s t) u = append s (append t u) := seq.append_assoc _ _ _ @[simp] def tail.aux : option (Ξ± Γ— wseq Ξ±) β†’ computation (option (Ξ± Γ— wseq Ξ±)) | none := return none | (some (a, s)) := destruct s theorem destruct_tail (s : wseq Ξ±) : destruct (tail s) = destruct s >>= tail.aux := begin simp [tail], rw [← bind_pure_comp_eq_map, is_lawful_monad.bind_assoc], apply congr_arg, ext1 (_|⟨a, s⟩); apply (@pure_bind computation _ _ _ _ _ _).trans _; simp end @[simp] def drop.aux : β„• β†’ option (Ξ± Γ— wseq Ξ±) β†’ computation (option (Ξ± Γ— wseq Ξ±)) | 0 := return | (n+1) := Ξ» a, tail.aux a >>= drop.aux n theorem drop.aux_none : βˆ€ n, @drop.aux Ξ± n none = return none | 0 := rfl | (n+1) := show computation.bind (return none) (drop.aux n) = return none, by rw [ret_bind, drop.aux_none] theorem destruct_dropn : βˆ€ (s : wseq Ξ±) n, destruct (drop s n) = destruct s >>= drop.aux n | s 0 := (bind_ret' _).symm | s (n+1) := by rw [← dropn_tail, destruct_dropn _ n, destruct_tail, is_lawful_monad.bind_assoc]; refl theorem head_terminates_of_head_tail_terminates (s : wseq Ξ±) [T : terminates (head (tail s))] : terminates (head s) := (head_terminates_iff _).2 $ begin rcases (head_terminates_iff _).1 T with ⟨⟨a, h⟩⟩, simp [tail] at h, rcases exists_of_mem_bind h with ⟨s', h1, h2⟩, unfold functor.map at h1, exact let ⟨t, h3, h4⟩ := exists_of_mem_map h1 in terminates_of_mem h3 end theorem destruct_some_of_destruct_tail_some {s : wseq Ξ±} {a} (h : some a ∈ destruct (tail s)) : βˆƒ a', some a' ∈ destruct s := begin unfold tail functor.map at h, simp at h, rcases exists_of_mem_bind h with ⟨t, tm, td⟩, clear h, rcases exists_of_mem_map tm with ⟨t', ht', ht2⟩, clear tm, cases t' with t'; rw ←ht2 at td; simp at td, { have := mem_unique td (ret_mem _), contradiction }, { exact ⟨_, ht'⟩ } end theorem head_some_of_head_tail_some {s : wseq Ξ±} {a} (h : some a ∈ head (tail s)) : βˆƒ a', some a' ∈ head s := begin unfold head at h, rcases exists_of_mem_map h with ⟨o, md, e⟩, clear h, cases o with o; injection e with h', clear e h', cases destruct_some_of_destruct_tail_some md with a am, exact ⟨_, mem_map ((<$>) (@prod.fst Ξ± (wseq Ξ±))) am⟩ end theorem head_some_of_nth_some {s : wseq Ξ±} {a n} (h : some a ∈ nth s n) : βˆƒ a', some a' ∈ head s := begin revert a, induction n with n IH; intros, exacts [⟨_, h⟩, let ⟨a', h'⟩ := head_some_of_head_tail_some h in IH h'] end instance productive_tail (s : wseq Ξ±) [productive s] : productive (tail s) := ⟨λ n, by rw [nth_tail]; apply_instance⟩ instance productive_dropn (s : wseq Ξ±) [productive s] (n) : productive (drop s n) := ⟨λ m, by rw [←nth_add]; apply_instance⟩ /-- Given a productive weak sequence, we can collapse all the `think`s to produce a sequence. -/ def to_seq (s : wseq Ξ±) [productive s] : seq Ξ± := ⟨λ n, (nth s n).get, Ξ» n h, begin cases e : computation.get (nth s (n + 1)), {assumption}, have := mem_of_get_eq _ e, simp [nth] at this h, cases head_some_of_head_tail_some this with a' h', have := mem_unique h' (@mem_of_get_eq _ _ _ _ h), contradiction end⟩ theorem nth_terminates_le {s : wseq Ξ±} {m n} (h : m ≀ n) : terminates (nth s n) β†’ terminates (nth s m) := by induction h with m' h IH; [exact id, exact Ξ» T, IH (@head_terminates_of_head_tail_terminates _ _ T)] theorem head_terminates_of_nth_terminates {s : wseq Ξ±} {n} : terminates (nth s n) β†’ terminates (head s) := nth_terminates_le (nat.zero_le n) theorem destruct_terminates_of_nth_terminates {s : wseq Ξ±} {n} (T : terminates (nth s n)) : terminates (destruct s) := (head_terminates_iff _).1 $ head_terminates_of_nth_terminates T theorem mem_rec_on {C : wseq Ξ± β†’ Prop} {a s} (M : a ∈ s) (h1 : βˆ€ b s', (a = b ∨ C s') β†’ C (cons b s')) (h2 : βˆ€ s, C s β†’ C (think s)) : C s := begin apply seq.mem_rec_on M, intros o s' h, cases o with b, { apply h2, cases h, {contradiction}, {assumption} }, { apply h1, apply or.imp_left _ h, intro h, injection h } end @[simp] theorem mem_think (s : wseq Ξ±) (a) : a ∈ think s ↔ a ∈ s := begin cases s with f al, change some (some a) ∈ some none :: f ↔ some (some a) ∈ f, constructor; intro h, { apply (stream.eq_or_mem_of_mem_cons h).resolve_left, intro, injections }, { apply stream.mem_cons_of_mem _ h } end theorem eq_or_mem_iff_mem {s : wseq Ξ±} {a a' s'} : some (a', s') ∈ destruct s β†’ (a ∈ s ↔ a = a' ∨ a ∈ s') := begin generalize e : destruct s = c, intro h, revert s, apply computation.mem_rec_on h _ (Ξ» c IH, _); intro s; apply s.rec_on _ (Ξ» x s, _) (Ξ» s, _); intros m; have := congr_arg computation.destruct m; simp at this; cases this with i1 i2, { rw [i1, i2], cases s' with f al, unfold cons has_mem.mem wseq.mem seq.mem seq.cons, simp, have h_a_eq_a' : a = a' ↔ some (some a) = some (some a'), {simp}, rw [h_a_eq_a'], refine ⟨stream.eq_or_mem_of_mem_cons, Ξ» o, _⟩, { cases o with e m, { rw e, apply stream.mem_cons }, { exact stream.mem_cons_of_mem _ m } } }, { simp, exact IH this } end @[simp] theorem mem_cons_iff (s : wseq Ξ±) (b) {a} : a ∈ cons b s ↔ a = b ∨ a ∈ s := eq_or_mem_iff_mem $ by simp [ret_mem] theorem mem_cons_of_mem {s : wseq Ξ±} (b) {a} (h : a ∈ s) : a ∈ cons b s := (mem_cons_iff _ _).2 (or.inr h) theorem mem_cons (s : wseq Ξ±) (a) : a ∈ cons a s := (mem_cons_iff _ _).2 (or.inl rfl) theorem mem_of_mem_tail {s : wseq Ξ±} {a} : a ∈ tail s β†’ a ∈ s := begin intro h, have := h, cases h with n e, revert s, simp [stream.nth], induction n with n IH; intro s; apply s.rec_on _ (Ξ» x s, _) (Ξ» s, _); repeat{simp}; intros m e; injections, { exact or.inr m }, { exact or.inr m }, { apply IH m, rw e, cases tail s, refl } end theorem mem_of_mem_dropn {s : wseq Ξ±} {a} : βˆ€ {n}, a ∈ drop s n β†’ a ∈ s | 0 h := h | (n+1) h := @mem_of_mem_dropn n (mem_of_mem_tail h) theorem nth_mem {s : wseq Ξ±} {a n} : some a ∈ nth s n β†’ a ∈ s := begin revert s, induction n with n IH; intros s h, { rcases exists_of_mem_map h with ⟨o, h1, h2⟩, cases o with o; injection h2 with h', cases o with a' s', exact (eq_or_mem_iff_mem h1).2 (or.inl h'.symm) }, { have := @IH (tail s), rw nth_tail at this, exact mem_of_mem_tail (this h) } end theorem exists_nth_of_mem {s : wseq Ξ±} {a} (h : a ∈ s) : βˆƒ n, some a ∈ nth s n := begin apply mem_rec_on h, { intros a' s' h, cases h with h h, { existsi 0, simp [nth], rw h, apply ret_mem }, { cases h with n h, existsi n+1, simp [nth], exact h } }, { intros s' h, cases h with n h, existsi n, simp [nth], apply think_mem h } end theorem exists_dropn_of_mem {s : wseq Ξ±} {a} (h : a ∈ s) : βˆƒ n s', some (a, s') ∈ destruct (drop s n) := let ⟨n, h⟩ := exists_nth_of_mem h in ⟨n, begin rcases (head_terminates_iff _).1 ⟨⟨_, h⟩⟩ with ⟨⟨o, om⟩⟩, have := mem_unique (mem_map _ om) h, cases o with o; injection this with i, cases o with a' s', dsimp at i, rw i at om, exact ⟨_, om⟩ end⟩ theorem lift_rel_dropn_destruct {R : Ξ± β†’ Ξ² β†’ Prop} {s t} (H : lift_rel R s t) : βˆ€ n, computation.lift_rel (lift_rel_o R (lift_rel R)) (destruct (drop s n)) (destruct (drop t n)) | 0 := lift_rel_destruct H | (n+1) := begin simp [destruct_tail], apply lift_rel_bind, apply lift_rel_dropn_destruct n, exact Ξ» a b o, match a, b, o with | none, none, _ := by simp | some (a, s), some (b, t), ⟨h1, h2⟩ := by simp [tail.aux]; apply lift_rel_destruct h2 end end theorem exists_of_lift_rel_left {R : Ξ± β†’ Ξ² β†’ Prop} {s t} (H : lift_rel R s t) {a} (h : a ∈ s) : βˆƒ {b}, b ∈ t ∧ R a b := let ⟨n, h⟩ := exists_nth_of_mem h, ⟨some (._, s'), sd, rfl⟩ := exists_of_mem_map h, ⟨some (b, t'), td, ⟨ab, _⟩⟩ := (lift_rel_dropn_destruct H n).left sd in ⟨b, nth_mem (mem_map ((<$>) prod.fst.{v v}) td), ab⟩ theorem exists_of_lift_rel_right {R : Ξ± β†’ Ξ² β†’ Prop} {s t} (H : lift_rel R s t) {b} (h : b ∈ t) : βˆƒ {a}, a ∈ s ∧ R a b := by rw ←lift_rel.swap at H; exact exists_of_lift_rel_left H h theorem head_terminates_of_mem {s : wseq Ξ±} {a} (h : a ∈ s) : terminates (head s) := let ⟨n, h⟩ := exists_nth_of_mem h in head_terminates_of_nth_terminates ⟨⟨_, h⟩⟩ theorem of_mem_append {s₁ sβ‚‚ : wseq Ξ±} {a : Ξ±} : a ∈ append s₁ sβ‚‚ β†’ a ∈ s₁ ∨ a ∈ sβ‚‚ := seq.of_mem_append theorem mem_append_left {s₁ sβ‚‚ : wseq Ξ±} {a : Ξ±} : a ∈ s₁ β†’ a ∈ append s₁ sβ‚‚ := seq.mem_append_left theorem exists_of_mem_map {f} {b : Ξ²} : βˆ€ {s : wseq Ξ±}, b ∈ map f s β†’ βˆƒ a, a ∈ s ∧ f a = b | ⟨g, al⟩ h := let ⟨o, om, oe⟩ := seq.exists_of_mem_map h in by cases o with a; injection oe with h'; exact ⟨a, om, h'⟩ @[simp] theorem lift_rel_nil (R : Ξ± β†’ Ξ² β†’ Prop) : lift_rel R nil nil := by rw [lift_rel_destruct_iff]; simp @[simp] theorem lift_rel_cons (R : Ξ± β†’ Ξ² β†’ Prop) (a b s t) : lift_rel R (cons a s) (cons b t) ↔ R a b ∧ lift_rel R s t := by rw [lift_rel_destruct_iff]; simp @[simp] theorem lift_rel_think_left (R : Ξ± β†’ Ξ² β†’ Prop) (s t) : lift_rel R (think s) t ↔ lift_rel R s t := by rw [lift_rel_destruct_iff, lift_rel_destruct_iff]; simp @[simp] theorem lift_rel_think_right (R : Ξ± β†’ Ξ² β†’ Prop) (s t) : lift_rel R s (think t) ↔ lift_rel R s t := by rw [lift_rel_destruct_iff, lift_rel_destruct_iff]; simp theorem cons_congr {s t : wseq Ξ±} (a : Ξ±) (h : s ~ t) : cons a s ~ cons a t := by unfold equiv; simp; exact h theorem think_equiv (s : wseq Ξ±) : think s ~ s := by unfold equiv; simp; apply equiv.refl theorem think_congr {s t : wseq Ξ±} (a : Ξ±) (h : s ~ t) : think s ~ think t := by unfold equiv; simp; exact h theorem head_congr : βˆ€ {s t : wseq Ξ±}, s ~ t β†’ head s ~ head t := suffices βˆ€ {s t : wseq Ξ±}, s ~ t β†’ βˆ€ {o}, o ∈ head s β†’ o ∈ head t, from Ξ» s t h o, ⟨this h, this h.symm⟩, begin intros s t h o ho, rcases @computation.exists_of_mem_map _ _ _ _ (destruct s) ho with ⟨ds, dsm, dse⟩, rw ←dse, cases destruct_congr h with l r, rcases l dsm with ⟨dt, dtm, dst⟩, cases ds with a; cases dt with b, { apply mem_map _ dtm }, { cases b, cases dst }, { cases a, cases dst }, { cases a with a s', cases b with b t', rw dst.left, exact @mem_map _ _ (@functor.map _ _ (Ξ± Γ— wseq Ξ±) _ prod.fst) _ (destruct t) dtm } end theorem flatten_equiv {c : computation (wseq Ξ±)} {s} (h : s ∈ c) : flatten c ~ s := begin apply computation.mem_rec_on h, { simp }, { intro s', apply equiv.trans, simp [think_equiv] } end theorem lift_rel_flatten {R : Ξ± β†’ Ξ² β†’ Prop} {c1 : computation (wseq Ξ±)} {c2 : computation (wseq Ξ²)} (h : c1.lift_rel (lift_rel R) c2) : lift_rel R (flatten c1) (flatten c2) := let S := Ξ» s t, βˆƒ c1 c2, s = flatten c1 ∧ t = flatten c2 ∧ computation.lift_rel (lift_rel R) c1 c2 in ⟨S, ⟨c1, c2, rfl, rfl, h⟩, Ξ» s t h, match s, t, h with ._, ._, ⟨c1, c2, rfl, rfl, h⟩ := begin simp, apply lift_rel_bind _ _ h, intros a b ab, apply computation.lift_rel.imp _ _ _ (lift_rel_destruct ab), intros a b, apply lift_rel_o.imp_right, intros s t h, refine ⟨return s, return t, _, _, _⟩; simp [h] end end⟩ theorem flatten_congr {c1 c2 : computation (wseq Ξ±)} : computation.lift_rel equiv c1 c2 β†’ flatten c1 ~ flatten c2 := lift_rel_flatten theorem tail_congr {s t : wseq Ξ±} (h : s ~ t) : tail s ~ tail t := begin apply flatten_congr, unfold functor.map, rw [←bind_ret, ←bind_ret], apply lift_rel_bind _ _ (destruct_congr h), intros a b h, simp, cases a with a; cases b with b, { trivial }, { cases h }, { cases a, cases h }, { cases a with a s', cases b with b t', exact h.right } end theorem dropn_congr {s t : wseq Ξ±} (h : s ~ t) (n) : drop s n ~ drop t n := by induction n; simp [*, tail_congr] theorem nth_congr {s t : wseq Ξ±} (h : s ~ t) (n) : nth s n ~ nth t n := head_congr (dropn_congr h _) theorem mem_congr {s t : wseq Ξ±} (h : s ~ t) (a) : a ∈ s ↔ a ∈ t := suffices βˆ€ {s t : wseq Ξ±}, s ~ t β†’ a ∈ s β†’ a ∈ t, from ⟨this h, this h.symm⟩, Ξ» s t h as, let ⟨n, hn⟩ := exists_nth_of_mem as in nth_mem ((nth_congr h _ _).1 hn) theorem productive_congr {s t : wseq Ξ±} (h : s ~ t) : productive s ↔ productive t := by simp only [productive_iff]; exact forall_congr (Ξ» n, terminates_congr $ nth_congr h _) theorem equiv.ext {s t : wseq Ξ±} (h : βˆ€ n, nth s n ~ nth t n) : s ~ t := ⟨λ s t, βˆ€ n, nth s n ~ nth t n, h, Ξ» s t h, begin refine lift_rel_def.2 ⟨_, _⟩, { rw [←head_terminates_iff, ←head_terminates_iff], exact terminates_congr (h 0) }, { intros a b ma mb, cases a with a; cases b with b, { trivial }, { injection mem_unique (mem_map _ ma) ((h 0 _).2 (mem_map _ mb)) }, { injection mem_unique (mem_map _ ma) ((h 0 _).2 (mem_map _ mb)) }, { cases a with a s', cases b with b t', injection mem_unique (mem_map _ ma) ((h 0 _).2 (mem_map _ mb)) with ab, refine ⟨ab, Ξ» n, _⟩, refine (nth_congr (flatten_equiv (mem_map _ ma)) n).symm.trans ((_ : nth (tail s) n ~ nth (tail t) n).trans (nth_congr (flatten_equiv (mem_map _ mb)) n)), rw [nth_tail, nth_tail], apply h } } end⟩ theorem length_eq_map (s : wseq Ξ±) : length s = computation.map list.length (to_list s) := begin refine eq_of_bisim (Ξ» c1 c2, βˆƒ (l : list Ξ±) (s : wseq Ξ±), c1 = corec length._match_2 (l.length, s) ∧ c2 = computation.map list.length (corec to_list._match_2 (l, s))) _ ⟨[], s, rfl, rfl⟩, intros s1 s2 h, rcases h with ⟨l, s, h⟩, rw [h.left, h.right], apply s.rec_on _ (Ξ» a s, _) (Ξ» s, _); repeat {simp [to_list, nil, cons, think, length]}, { refine ⟨a::l, s, _, _⟩; simp }, { refine ⟨l, s, _, _⟩; simp } end @[simp] theorem of_list_nil : of_list [] = (nil : wseq Ξ±) := rfl @[simp] theorem of_list_cons (a : Ξ±) (l) : of_list (a :: l) = cons a (of_list l) := show seq.map some (seq.of_list (a :: l)) = seq.cons (some a) (seq.map some (seq.of_list l)), by simp @[simp] theorem to_list'_nil (l : list Ξ±) : corec to_list._match_2 (l, nil) = return l.reverse := destruct_eq_ret rfl @[simp] theorem to_list'_cons (l : list Ξ±) (s : wseq Ξ±) (a : Ξ±) : corec to_list._match_2 (l, cons a s) = (corec to_list._match_2 (a::l, s)).think := destruct_eq_think $ by simp [to_list, cons] @[simp] theorem to_list'_think (l : list Ξ±) (s : wseq Ξ±) : corec to_list._match_2 (l, think s) = (corec to_list._match_2 (l, s)).think := destruct_eq_think $ by simp [to_list, think] theorem to_list'_map (l : list Ξ±) (s : wseq Ξ±) : corec to_list._match_2 (l, s) = ((++) l.reverse) <$> to_list s := begin refine eq_of_bisim (Ξ» c1 c2, βˆƒ (l' : list Ξ±) (s : wseq Ξ±), c1 = corec to_list._match_2 (l' ++ l, s) ∧ c2 = computation.map ((++) l.reverse) (corec to_list._match_2 (l', s))) _ ⟨[], s, rfl, rfl⟩, intros s1 s2 h, rcases h with ⟨l', s, h⟩, rw [h.left, h.right], apply s.rec_on _ (Ξ» a s, _) (Ξ» s, _); repeat {simp [to_list, nil, cons, think, length]}, { refine ⟨a::l', s, _, _⟩; simp }, { refine ⟨l', s, _, _⟩; simp } end @[simp] theorem to_list_cons (a : Ξ±) (s) : to_list (cons a s) = (list.cons a <$> to_list s).think := destruct_eq_think $ by unfold to_list; simp; rw to_list'_map; simp; refl @[simp] theorem to_list_nil : to_list (nil : wseq Ξ±) = return [] := destruct_eq_ret rfl theorem to_list_of_list (l : list Ξ±) : l ∈ to_list (of_list l) := by induction l with a l IH; simp [ret_mem]; exact think_mem (mem_map _ IH) @[simp] theorem destruct_of_seq (s : seq Ξ±) : destruct (of_seq s) = return (s.head.map $ Ξ» a, (a, of_seq s.tail)) := destruct_eq_ret $ begin simp [of_seq, head, destruct, seq.destruct, seq.head], rw [show seq.nth (some <$> s) 0 = some <$> seq.nth s 0, by apply seq.map_nth], cases seq.nth s 0 with a, { refl }, unfold functor.map, simp [destruct] end @[simp] theorem head_of_seq (s : seq Ξ±) : head (of_seq s) = return s.head := by simp [head]; cases seq.head s; refl @[simp] theorem tail_of_seq (s : seq Ξ±) : tail (of_seq s) = of_seq s.tail := begin simp [tail], apply s.rec_on _ (Ξ» x s, _); simp [of_seq], {refl}, rw [seq.head_cons, seq.tail_cons], refl end @[simp] theorem dropn_of_seq (s : seq Ξ±) : βˆ€ n, drop (of_seq s) n = of_seq (s.drop n) | 0 := rfl | (n+1) := by dsimp [drop]; rw [dropn_of_seq, tail_of_seq] theorem nth_of_seq (s : seq Ξ±) (n) : nth (of_seq s) n = return (seq.nth s n) := by dsimp [nth]; rw [dropn_of_seq, head_of_seq, seq.head_dropn] instance productive_of_seq (s : seq Ξ±) : productive (of_seq s) := ⟨λ n, by rw nth_of_seq; apply_instance⟩ theorem to_seq_of_seq (s : seq Ξ±) : to_seq (of_seq s) = s := begin apply subtype.eq, funext n, dsimp [to_seq], apply get_eq_of_mem, rw nth_of_seq, apply ret_mem end /-- The monadic `return a` is a singleton list containing `a`. -/ def ret (a : Ξ±) : wseq Ξ± := of_list [a] @[simp] theorem map_nil (f : Ξ± β†’ Ξ²) : map f nil = nil := rfl @[simp] theorem map_cons (f : Ξ± β†’ Ξ²) (a s) : map f (cons a s) = cons (f a) (map f s) := seq.map_cons _ _ _ @[simp] theorem map_think (f : Ξ± β†’ Ξ²) (s) : map f (think s) = think (map f s) := seq.map_cons _ _ _ @[simp] theorem map_id (s : wseq Ξ±) : map id s = s := by simp [map] @[simp] theorem map_ret (f : Ξ± β†’ Ξ²) (a) : map f (ret a) = ret (f a) := by simp [ret] @[simp] theorem map_append (f : Ξ± β†’ Ξ²) (s t) : map f (append s t) = append (map f s) (map f t) := seq.map_append _ _ _ theorem map_comp (f : Ξ± β†’ Ξ²) (g : Ξ² β†’ Ξ³) (s : wseq Ξ±) : map (g ∘ f) s = map g (map f s) := begin dsimp [map], rw ←seq.map_comp, apply congr_fun, apply congr_arg, ext ⟨⟩; refl end theorem mem_map (f : Ξ± β†’ Ξ²) {a : Ξ±} {s : wseq Ξ±} : a ∈ s β†’ f a ∈ map f s := seq.mem_map (option.map f) -- The converse is not true without additional assumptions theorem exists_of_mem_join {a : Ξ±} : βˆ€ {S : wseq (wseq Ξ±)}, a ∈ join S β†’ βˆƒ s, s ∈ S ∧ a ∈ s := suffices βˆ€ ss : wseq Ξ±, a ∈ ss β†’ βˆ€ s S, append s (join S) = ss β†’ a ∈ append s (join S) β†’ a ∈ s ∨ βˆƒ s, s ∈ S ∧ a ∈ s, from Ξ» S h, (this _ h nil S (by simp) (by simp [h])).resolve_left (not_mem_nil _), begin intros ss h, apply mem_rec_on h (Ξ» b ss o, _) (Ξ» ss IH, _); intros s S, { refine s.rec_on (S.rec_on _ (Ξ» s S, _) (Ξ» S, _)) (Ξ» b' s, _) (Ξ» s, _); intros ej m; simp at ej; have := congr_arg seq.destruct ej; simp at this; try {cases this}; try {contradiction}, substs b' ss, simp at m ⊒, cases o with e IH, { simp [e] }, cases m with e m, { simp [e] }, exact or.imp_left or.inr (IH _ _ rfl m) }, { refine s.rec_on (S.rec_on _ (Ξ» s S, _) (Ξ» S, _)) (Ξ» b' s, _) (Ξ» s, _); intros ej m; simp at ej; have := congr_arg seq.destruct ej; simp at this; try { try {have := this.1}, contradiction }; subst ss, { apply or.inr, simp at m ⊒, cases IH s S rfl m with as ex, { exact ⟨s, or.inl rfl, as⟩ }, { rcases ex with ⟨s', sS, as⟩, exact ⟨s', or.inr sS, as⟩ } }, { apply or.inr, simp at m, rcases (IH nil S (by simp) (by simp [m])).resolve_left (not_mem_nil _) with ⟨s, sS, as⟩, exact ⟨s, by simp [sS], as⟩ }, { simp at m IH ⊒, apply IH _ _ rfl m } } end theorem exists_of_mem_bind {s : wseq Ξ±} {f : Ξ± β†’ wseq Ξ²} {b} (h : b ∈ bind s f) : βˆƒ a ∈ s, b ∈ f a := let ⟨t, tm, bt⟩ := exists_of_mem_join h, ⟨a, as, e⟩ := exists_of_mem_map tm in ⟨a, as, by rwa e⟩ theorem destruct_map (f : Ξ± β†’ Ξ²) (s : wseq Ξ±) : destruct (map f s) = computation.map (option.map (prod.map f (map f))) (destruct s) := begin apply eq_of_bisim (Ξ» c1 c2, βˆƒ s, c1 = destruct (map f s) ∧ c2 = computation.map (option.map (prod.map f (map f))) (destruct s)), { intros c1 c2 h, cases h with s h, rw [h.left, h.right], apply s.rec_on _ (Ξ» a s, _) (Ξ» s, _); simp, exact ⟨s, rfl, rfl⟩ }, { exact ⟨s, rfl, rfl⟩ } end theorem lift_rel_map {Ξ΄} (R : Ξ± β†’ Ξ² β†’ Prop) (S : Ξ³ β†’ Ξ΄ β†’ Prop) {s1 : wseq Ξ±} {s2 : wseq Ξ²} {f1 : Ξ± β†’ Ξ³} {f2 : Ξ² β†’ Ξ΄} (h1 : lift_rel R s1 s2) (h2 : βˆ€ {a b}, R a b β†’ S (f1 a) (f2 b)) : lift_rel S (map f1 s1) (map f2 s2) := ⟨λ s1 s2, βˆƒ s t, s1 = map f1 s ∧ s2 = map f2 t ∧ lift_rel R s t, ⟨s1, s2, rfl, rfl, h1⟩, Ξ» s1 s2 h, match s1, s2, h with ._, ._, ⟨s, t, rfl, rfl, h⟩ := begin simp [destruct_map], apply computation.lift_rel_map _ _ (lift_rel_destruct h), intros o p h, cases o with a; cases p with b; simp, { cases b; cases h }, { cases a; cases h }, { cases a with a s; cases b with b t, cases h with r h, exact ⟨h2 r, s, rfl, t, rfl, h⟩ } end end⟩ theorem map_congr (f : Ξ± β†’ Ξ²) {s t : wseq Ξ±} (h : s ~ t) : map f s ~ map f t := lift_rel_map _ _ h (Ξ» _ _, congr_arg _) @[simp] def destruct_append.aux (t : wseq Ξ±) : option (Ξ± Γ— wseq Ξ±) β†’ computation (option (Ξ± Γ— wseq Ξ±)) | none := destruct t | (some (a, s)) := return (some (a, append s t)) theorem destruct_append (s t : wseq Ξ±) : destruct (append s t) = (destruct s).bind (destruct_append.aux t) := begin apply eq_of_bisim (Ξ» c1 c2, βˆƒ s t, c1 = destruct (append s t) ∧ c2 = (destruct s).bind (destruct_append.aux t)) _ ⟨s, t, rfl, rfl⟩, intros c1 c2 h, rcases h with ⟨s, t, h⟩, rw [h.left, h.right], apply s.rec_on _ (Ξ» a s, _) (Ξ» s, _); simp, { apply t.rec_on _ (Ξ» b t, _) (Ξ» t, _); simp, { refine ⟨nil, t, _, _⟩; simp } }, { exact ⟨s, t, rfl, rfl⟩ } end @[simp] def destruct_join.aux : option (wseq Ξ± Γ— wseq (wseq Ξ±)) β†’ computation (option (Ξ± Γ— wseq Ξ±)) | none := return none | (some (s, S)) := (destruct (append s (join S))).think theorem destruct_join (S : wseq (wseq Ξ±)) : destruct (join S) = (destruct S).bind destruct_join.aux := begin apply eq_of_bisim (Ξ» c1 c2, c1 = c2 ∨ βˆƒ S, c1 = destruct (join S) ∧ c2 = (destruct S).bind destruct_join.aux) _ (or.inr ⟨S, rfl, rfl⟩), intros c1 c2 h, exact match c1, c2, h with | _, _, (or.inl $ eq.refl c) := by cases c.destruct; simp | _, _, or.inr ⟨S, rfl, rfl⟩ := begin apply S.rec_on _ (Ξ» s S, _) (Ξ» S, _); simp, { refine or.inr ⟨S, rfl, rfl⟩ } end end end theorem lift_rel_append (R : Ξ± β†’ Ξ² β†’ Prop) {s1 s2 : wseq Ξ±} {t1 t2 : wseq Ξ²} (h1 : lift_rel R s1 t1) (h2 : lift_rel R s2 t2) : lift_rel R (append s1 s2) (append t1 t2) := ⟨λ s t, lift_rel R s t ∨ βˆƒ s1 t1, s = append s1 s2 ∧ t = append t1 t2 ∧ lift_rel R s1 t1, or.inr ⟨s1, t1, rfl, rfl, h1⟩, Ξ» s t h, match s, t, h with | s, t, or.inl h := begin apply computation.lift_rel.imp _ _ _ (lift_rel_destruct h), intros a b, apply lift_rel_o.imp_right, intros s t, apply or.inl end | ._, ._, or.inr ⟨s1, t1, rfl, rfl, h⟩ := begin simp [destruct_append], apply computation.lift_rel_bind _ _ (lift_rel_destruct h), intros o p h, cases o with a; cases p with b, { simp, apply computation.lift_rel.imp _ _ _ (lift_rel_destruct h2), intros a b, apply lift_rel_o.imp_right, intros s t, apply or.inl }, { cases b; cases h }, { cases a; cases h }, { cases a with a s; cases b with b t, cases h with r h, simp, exact ⟨r, or.inr ⟨s, rfl, t, rfl, h⟩⟩ } end end⟩ theorem lift_rel_join.lem (R : Ξ± β†’ Ξ² β†’ Prop) {S T} {U : wseq Ξ± β†’ wseq Ξ² β†’ Prop} (ST : lift_rel (lift_rel R) S T) (HU : βˆ€ s1 s2, (βˆƒ s t S T, s1 = append s (join S) ∧ s2 = append t (join T) ∧ lift_rel R s t ∧ lift_rel (lift_rel R) S T) β†’ U s1 s2) {a} (ma : a ∈ destruct (join S)) : βˆƒ {b}, b ∈ destruct (join T) ∧ lift_rel_o R U a b := begin cases exists_results_of_mem ma with n h, clear ma, revert a S T, apply nat.strong_induction_on n _, intros n IH a S T ST ra, simp [destruct_join] at ra, exact let ⟨o, m, k, rs1, rs2, en⟩ := of_results_bind ra, ⟨p, mT, rop⟩ := computation.exists_of_lift_rel_left (lift_rel_destruct ST) rs1.mem in by exact match o, p, rop, rs1, rs2, mT with | none, none, _, rs1, rs2, mT := by simp only [destruct_join]; exact ⟨none, mem_bind mT (ret_mem _), by rw eq_of_ret_mem rs2.mem; trivial⟩ | some (s, S'), some (t, T'), ⟨st, ST'⟩, rs1, rs2, mT := by simp [destruct_append] at rs2; exact let ⟨k1, rs3, ek⟩ := of_results_think rs2, ⟨o', m1, n1, rs4, rs5, ek1⟩ := of_results_bind rs3, ⟨p', mt, rop'⟩ := computation.exists_of_lift_rel_left (lift_rel_destruct st) rs4.mem in by exact match o', p', rop', rs4, rs5, mt with | none, none, _, rs4, rs5', mt := have n1 < n, begin rw [en, ek, ek1], apply lt_of_lt_of_le _ (nat.le_add_right _ _), apply nat.lt_succ_of_le (nat.le_add_right _ _) end, let ⟨ob, mb, rob⟩ := IH _ this ST' rs5' in by refine ⟨ob, _, rob⟩; { simp [destruct_join], apply mem_bind mT, simp [destruct_append], apply think_mem, apply mem_bind mt, exact mb } | some (a, s'), some (b, t'), ⟨ab, st'⟩, rs4, rs5, mt := begin simp at rs5, refine ⟨some (b, append t' (join T')), _, _⟩, { simp [destruct_join], apply mem_bind mT, simp [destruct_append], apply think_mem, apply mem_bind mt, apply ret_mem }, rw eq_of_ret_mem rs5.mem, exact ⟨ab, HU _ _ ⟨s', t', S', T', rfl, rfl, st', ST'⟩⟩ end end end end theorem lift_rel_join (R : Ξ± β†’ Ξ² β†’ Prop) {S : wseq (wseq Ξ±)} {T : wseq (wseq Ξ²)} (h : lift_rel (lift_rel R) S T) : lift_rel R (join S) (join T) := ⟨λ s1 s2, βˆƒ s t S T, s1 = append s (join S) ∧ s2 = append t (join T) ∧ lift_rel R s t ∧ lift_rel (lift_rel R) S T, ⟨nil, nil, S, T, by simp, by simp, by simp, h⟩, Ξ» s1 s2 ⟨s, t, S, T, h1, h2, st, ST⟩, begin clear _fun_match _x, rw [h1, h2], rw [destruct_append, destruct_append], apply computation.lift_rel_bind _ _ (lift_rel_destruct st), exact Ξ» o p h, match o, p, h with | some (a, s), some (b, t), ⟨h1, h2⟩ := by simp; exact ⟨h1, s, t, S, rfl, T, rfl, h2, ST⟩ | none, none, _ := begin dsimp [destruct_append.aux, computation.lift_rel], constructor, { intro, apply lift_rel_join.lem _ ST (Ξ» _ _, id) }, { intros b mb, rw [←lift_rel_o.swap], apply lift_rel_join.lem (swap R), { rw [←lift_rel.swap R, ←lift_rel.swap], apply ST }, { rw [←lift_rel.swap R, ←lift_rel.swap (lift_rel R)], exact Ξ» s1 s2 ⟨s, t, S, T, h1, h2, st, ST⟩, ⟨t, s, T, S, h2, h1, st, ST⟩ }, { exact mb } } end end end⟩ theorem join_congr {S T : wseq (wseq Ξ±)} (h : lift_rel equiv S T) : join S ~ join T := lift_rel_join _ h theorem lift_rel_bind {Ξ΄} (R : Ξ± β†’ Ξ² β†’ Prop) (S : Ξ³ β†’ Ξ΄ β†’ Prop) {s1 : wseq Ξ±} {s2 : wseq Ξ²} {f1 : Ξ± β†’ wseq Ξ³} {f2 : Ξ² β†’ wseq Ξ΄} (h1 : lift_rel R s1 s2) (h2 : βˆ€ {a b}, R a b β†’ lift_rel S (f1 a) (f2 b)) : lift_rel S (bind s1 f1) (bind s2 f2) := lift_rel_join _ (lift_rel_map _ _ h1 @h2) theorem bind_congr {s1 s2 : wseq Ξ±} {f1 f2 : Ξ± β†’ wseq Ξ²} (h1 : s1 ~ s2) (h2 : βˆ€ a, f1 a ~ f2 a) : bind s1 f1 ~ bind s2 f2 := lift_rel_bind _ _ h1 (Ξ» a b h, by rw h; apply h2) @[simp] theorem join_ret (s : wseq Ξ±) : join (ret s) ~ s := by simp [ret]; apply think_equiv @[simp] theorem join_map_ret (s : wseq Ξ±) : join (map ret s) ~ s := begin refine ⟨λ s1 s2, join (map ret s2) = s1, rfl, _⟩, intros s' s h, rw ←h, apply lift_rel_rec (Ξ» c1 c2, βˆƒ s, c1 = destruct (join (map ret s)) ∧ c2 = destruct s), { exact Ξ» c1 c2 h, match c1, c2, h with | ._, ._, ⟨s, rfl, rfl⟩ := begin clear h _match, have : βˆ€ s, βˆƒ s' : wseq Ξ±, (map ret s).join.destruct = (map ret s').join.destruct ∧ destruct s = s'.destruct, from Ξ» s, ⟨s, rfl, rfl⟩, apply s.rec_on _ (Ξ» a s, _) (Ξ» s, _); simp [ret, ret_mem, this, option.exists] end end }, { exact ⟨s, rfl, rfl⟩ } end @[simp] theorem join_append (S T : wseq (wseq Ξ±)) : join (append S T) ~ append (join S) (join T) := begin refine ⟨λ s1 s2, βˆƒ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)), ⟨nil, S, T, by simp, by simp⟩, _⟩, intros s1 s2 h, apply lift_rel_rec (Ξ» c1 c2, βˆƒ (s : wseq Ξ±) S T, c1 = destruct (append s (join (append S T))) ∧ c2 = destruct (append s (append (join S) (join T)))) _ _ _ (let ⟨s, S, T, h1, h2⟩ := h in ⟨s, S, T, congr_arg destruct h1, congr_arg destruct h2⟩), intros c1 c2 h, exact match c1, c2, h with ._, ._, ⟨s, S, T, rfl, rfl⟩ := begin clear _match h h, apply wseq.rec_on s _ (Ξ» a s, _) (Ξ» s, _); simp, { apply wseq.rec_on S _ (Ξ» s S, _) (Ξ» S, _); simp, { apply wseq.rec_on T _ (Ξ» s T, _) (Ξ» T, _); simp, { refine ⟨s, nil, T, _, _⟩; simp }, { refine ⟨nil, nil, T, _, _⟩; simp } }, { exact ⟨s, S, T, rfl, rfl⟩ }, { refine ⟨nil, S, T, _, _⟩; simp } }, { exact ⟨s, S, T, rfl, rfl⟩ }, { exact ⟨s, S, T, rfl, rfl⟩ } end end end @[simp] theorem bind_ret (f : Ξ± β†’ Ξ²) (s) : bind s (ret ∘ f) ~ map f s := begin dsimp [bind], change (Ξ» x, ret (f x)) with (ret ∘ f), rw [map_comp], apply join_map_ret end @[simp] theorem ret_bind (a : Ξ±) (f : Ξ± β†’ wseq Ξ²) : bind (ret a) f ~ f a := by simp [bind] @[simp] theorem map_join (f : Ξ± β†’ Ξ²) (S) : map f (join S) = join (map (map f) S) := begin apply seq.eq_of_bisim (Ξ» s1 s2, βˆƒ s S, s1 = append s (map f (join S)) ∧ s2 = append s (join (map (map f) S))), { intros s1 s2 h, exact match s1, s2, h with ._, ._, ⟨s, S, rfl, rfl⟩ := begin apply wseq.rec_on s _ (Ξ» a s, _) (Ξ» s, _); simp, { apply wseq.rec_on S _ (Ξ» s S, _) (Ξ» S, _); simp, { exact ⟨map f s, S, rfl, rfl⟩ }, { refine ⟨nil, S, _, _⟩; simp } }, { exact ⟨_, _, rfl, rfl⟩ }, { exact ⟨_, _, rfl, rfl⟩ } end end }, { refine ⟨nil, S, _, _⟩; simp } end @[simp] theorem join_join (SS : wseq (wseq (wseq Ξ±))) : join (join SS) ~ join (map join SS) := begin refine ⟨λ s1 s2, βˆƒ s S SS, s1 = append s (join (append S (join SS))) ∧ s2 = append s (append (join S) (join (map join SS))), ⟨nil, nil, SS, by simp, by simp⟩, _⟩, intros s1 s2 h, apply lift_rel_rec (Ξ» c1 c2, βˆƒ s S SS, c1 = destruct (append s (join (append S (join SS)))) ∧ c2 = destruct (append s (append (join S) (join (map join SS))))) _ (destruct s1) (destruct s2) (let ⟨s, S, SS, h1, h2⟩ := h in ⟨s, S, SS, by simp [h1], by simp [h2]⟩), intros c1 c2 h, exact match c1, c2, h with ._, ._, ⟨s, S, SS, rfl, rfl⟩ := begin clear _match h h, apply wseq.rec_on s _ (Ξ» a s, _) (Ξ» s, _); simp, { apply wseq.rec_on S _ (Ξ» s S, _) (Ξ» S, _); simp, { apply wseq.rec_on SS _ (Ξ» S SS, _) (Ξ» SS, _); simp, { refine ⟨nil, S, SS, _, _⟩; simp }, { refine ⟨nil, nil, SS, _, _⟩; simp } }, { exact ⟨s, S, SS, rfl, rfl⟩ }, { refine ⟨nil, S, SS, _, _⟩; simp } }, { exact ⟨s, S, SS, rfl, rfl⟩ }, { exact ⟨s, S, SS, rfl, rfl⟩ } end end end @[simp] theorem bind_assoc (s : wseq Ξ±) (f : Ξ± β†’ wseq Ξ²) (g : Ξ² β†’ wseq Ξ³) : bind (bind s f) g ~ bind s (Ξ» (x : Ξ±), bind (f x) g) := begin simp [bind], rw [← map_comp f (map g), map_comp (map g ∘ f) join], apply join_join end instance : monad wseq := { map := @map, pure := @ret, bind := @bind } /- Unfortunately, wseq is not a lawful monad, because it does not satisfy the monad laws exactly, only up to sequence equivalence. Furthermore, even quotienting by the equivalence is not sufficient, because the join operation involves lists of quotient elements, with a lifted equivalence relation, and pure quotients cannot handle this type of construction. instance : is_lawful_monad wseq := { id_map := @map_id, bind_pure_comp_eq_map := @bind_ret, pure_bind := @ret_bind, bind_assoc := @bind_assoc } -/ end wseq
3b5fc1504dd7d9f97913069ca36c9e9967e85754
a5271082abc327bbe26fc4acdaa885da9582cefa
/src/parser.lean
7de9a6264234141be3e4a7700f24238222bed39f
[ "Apache-2.0" ]
permissive
avigad/embed
9ee7d104609eeded173ca1e6e7a1925897b1652a
0e3612028d4039d29d06239ef03bc50576ca0f8b
refs/heads/master
1,584,548,951,613
1,527,883,346,000
1,527,883,346,000
134,967,973
0
0
null
null
null
null
UTF-8
Lean
false
false
3,874
lean
import .prop data.buffer.parser open parser namespace prop namespace parser class has_vars (Ξ± : Type) := (var : string β†’ Ξ±) instance : has_vars symb := ⟨symb.atom⟩ variables {Ξ± : Type} [is_symb Ξ±] [has_vars Ξ±] -- whitespace def Ws : parser unit := many' $ one_of' " \t\x0d\n".to_list -- token def tok (s : string) := str s >> Ws /- -- a variable: a, ..., z, A, ..., Z def Var : parser nat := do c ← sat (Ξ» x, _root_.true), Ws, let n := c.to_nat in if 65 ≀ n ∧ n ≀ 122 then return n else parser.fail "not a letter" -/ def is_letter (c : char) := let n := c.to_nat in 65 ≀ n ∧ n ≀ 122 instance : decidable_pred is_letter := by { delta is_letter, apply_instance } -- a variable: a, ..., z, A, ..., Z def Var : parser (exp Ξ±) := do c ← sat is_letter, Ws, return (@exp.cst _ $ has_vars.var _ c.to_string) -- an atom def Atom : parser (exp Ξ±) := (tok "⊀" >> Ws >> return prop.true) <|> (tok "βŠ₯" >> Ws >> return prop.false) <|> Var --(do n ← Var, pure (exp.fvr Ξ± n)) section formula parameters {Ξ² : Type} [is_symb Ξ²] [has_vars Ξ²] (Form : parser (exp Ξ²)) def ParenForm : parser (exp Ξ²) := tok "(" *> Form <* tok ")" <* Ws def Form0 : parser (exp Ξ²) := (fix $ Ξ» F, Atom <|> ParenForm <|> (do tok "Β¬", f ← F, pure (prop.not f))) <* Ws def Form1 : parser (exp Ξ²) := fix $ Ξ» F, do l ← Form0, (do tok "∧", r ← F, pure (prop.and l r)) <|> pure l def Form2 : parser (exp Ξ²) := fix $ Ξ» F, do l ← Form1, (do tok "∨", r ← F, pure (prop.or l r)) <|> pure l def Form3 : parser (exp Ξ²) := fix $ Ξ» F, do l ← Form2, (do tok "β†’", r ← F, pure (prop.imp l r)) <|> pure l end formula def Form : parser (exp Ξ±) := do fix $ Ξ» F, Form3 F def Sequent : parser (seq Ξ±) := do l ← sep_by (tok ",") Form, tok "⊒", r ← sep_by (tok ",") Form, return (l, r) /- def parse_prop_to_str (s : string) : string := match parser.run (Form : parser (exp symb)) s.to_char_buffer with | (sum.inl error) := error | (sum.inr result) := fml2str result end def ex := parser.run (Form : parser (exp symb)) "(p ∧ Β¬ q) β†’ r ∨ s".to_char_buffer #eval ex def ex' := parse_prop_to_str "(p ∧ Β¬ q) β†’ r ∨ s" #eval ex' -/ section open lean open lean.parser open interactive /- meta def mk_thm (s: string) : tactic unit := let S := (Sequent : parser (seq symb) in match parser.run S s.to_char_buffer with | (sum.inl error) := do exact `(_root_.false) | (sum.inr sq) := do exact `(thm sq) end def thm_type (s : string) := Prop meta def mk_thm' : tactic unit := do `(thm_type %%s) ← target | failed, ss ← eval_expr string s, mk_thm ss notation `!seq` s := (by mk_thm' : thm_type s) -/ -- I don't know whether this is any better than the other method. reserve prefix `!seq `:100 @[user_notation] meta def sequent_macro (_ : parse $ tk "!seq") (s : string) : lean.parser pexpr := let S := (Sequent : _root_.parser (seq symb)) in match parser.run S s.to_char_buffer with | (sum.inl error) := do pure ``(_root_.false) | (sum.inr sq) := do let sq' := `(sq) in pure ``(thm %%sq') end end /- example : !seq "p, q ⊒ p" := begin apply thm.id end example : !seq "⊒ (p β†’ q β†’ r) β†’ (p β†’ q) β†’ p β†’ r" := begin showgoal, apply thm.impr, apply thm.impr, apply thm.impr, apply thm.rl 2, apply thm.impl, apply thm.rl 1, apply thm.id, apply thm.impl, apply thm.impl, apply thm.id, apply thm.id, apply thm.id, showgoal end example : !seq "p ∧ (q β†’ Β¬ p) ⊒ Β¬ q" := begin apply thm.andl, showgoal sorry end theorem foo : !seq "p ∧ q ⊒ q ∧ p" := begin apply thm.andl, apply thm.andr, apply thm.rl 1, apply thm.id, apply thm.id, showgoal end -/ end parser def pp_thm {l r : list (exp symb)} (p : thm (l, r)) : string := sqt2str fml2str l r end prop
53d193d16ec75651678320c5abb5ee0f5fab56b0
853df553b1d6ca524e3f0a79aedd32dde5d27ec3
/src/data/equiv/denumerable.lean
00124abc80d771e34a20c5288b9169c723f99ea5
[ "Apache-2.0" ]
permissive
DanielFabian/mathlib
efc3a50b5dde303c59eeb6353ef4c35a345d7112
f520d07eba0c852e96fe26da71d85bf6d40fcc2a
refs/heads/master
1,668,739,922,971
1,595,201,756,000
1,595,201,756,000
279,469,476
0
0
null
1,594,696,604,000
1,594,696,604,000
null
UTF-8
Lean
false
false
9,151
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro Denumerable (countably infinite) types, as a typeclass extending encodable. This is used to provide explicit encode/decode functions from nat, where the functions are known inverses of each other. -/ import data.equiv.encodable import data.sigma import data.fintype.basic import data.list.min_max open nat section prio set_option default_priority 100 -- see Note [default priority] /-- A denumerable type is one which is (constructively) bijective with β„•. Although we already have a name for this property, namely `Ξ± ≃ β„•`, we are here interested in using it as a typeclass. -/ class denumerable (Ξ± : Type*) extends encodable Ξ± := (decode_inv : βˆ€ n, βˆƒ a ∈ decode n, encode a = n) end prio namespace denumerable section variables {Ξ± : Type*} {Ξ² : Type*} [denumerable Ξ±] [denumerable Ξ²] open encodable theorem decode_is_some (Ξ±) [denumerable Ξ±] (n : β„•) : (decode Ξ± n).is_some := option.is_some_iff_exists.2 $ (decode_inv n).imp $ Ξ» a, Exists.fst def of_nat (Ξ±) [f : denumerable Ξ±] (n : β„•) : Ξ± := option.get (decode_is_some Ξ± n) @[simp, priority 900] theorem decode_eq_of_nat (Ξ±) [denumerable Ξ±] (n : β„•) : decode Ξ± n = some (of_nat Ξ± n) := option.eq_some_of_is_some _ @[simp] theorem of_nat_of_decode {n b} (h : decode Ξ± n = some b) : of_nat Ξ± n = b := option.some.inj $ (decode_eq_of_nat _ _).symm.trans h @[simp] theorem encode_of_nat (n) : encode (of_nat Ξ± n) = n := let ⟨a, h, e⟩ := decode_inv n in by rwa [of_nat_of_decode h] @[simp] theorem of_nat_encode (a) : of_nat Ξ± (encode a) = a := of_nat_of_decode (encodek _) def eqv (Ξ±) [denumerable Ξ±] : Ξ± ≃ β„• := ⟨encode, of_nat Ξ±, of_nat_encode, encode_of_nat⟩ def mk' {Ξ±} (e : Ξ± ≃ β„•) : denumerable Ξ± := { encode := e, decode := some ∘ e.symm, encodek := Ξ» a, congr_arg some (e.symm_apply_apply _), decode_inv := Ξ» n, ⟨_, rfl, e.apply_symm_apply _⟩ } def of_equiv (Ξ±) {Ξ²} [denumerable Ξ±] (e : Ξ² ≃ Ξ±) : denumerable Ξ² := { decode_inv := Ξ» n, by simp, ..encodable.of_equiv _ e } @[simp] theorem of_equiv_of_nat (Ξ±) {Ξ²} [denumerable Ξ±] (e : Ξ² ≃ Ξ±) (n) : @of_nat Ξ² (of_equiv _ e) n = e.symm (of_nat Ξ± n) := by apply of_nat_of_decode; show option.map _ _ = _; simp def equivβ‚‚ (Ξ± Ξ²) [denumerable Ξ±] [denumerable Ξ²] : Ξ± ≃ Ξ² := (eqv Ξ±).trans (eqv Ξ²).symm instance nat : denumerable nat := ⟨λ n, ⟨_, rfl, rfl⟩⟩ @[simp] theorem of_nat_nat (n) : of_nat β„• n = n := rfl instance option : denumerable (option Ξ±) := ⟨λ n, by cases n; simp⟩ instance sum : denumerable (Ξ± βŠ• Ξ²) := ⟨λ n, begin suffices : βˆƒ a ∈ @decode_sum Ξ± Ξ² _ _ n, encode_sum a = bit (bodd n) (div2 n), {simpa [bit_decomp]}, simp [decode_sum]; cases bodd n; simp [decode_sum, bit, encode_sum] end⟩ section sigma variables {Ξ³ : Ξ± β†’ Type*} [βˆ€ a, denumerable (Ξ³ a)] instance sigma : denumerable (sigma Ξ³) := ⟨λ n, by simp [decode_sigma]; exact ⟨_, _, ⟨rfl, heq.rfl⟩, by simp⟩⟩ @[simp] theorem sigma_of_nat_val (n : β„•) : of_nat (sigma Ξ³) n = ⟨of_nat Ξ± (unpair n).1, of_nat (Ξ³ _) (unpair n).2⟩ := option.some.inj $ by rw [← decode_eq_of_nat, decode_sigma_val]; simp; refl end sigma instance prod : denumerable (Ξ± Γ— Ξ²) := of_equiv _ (equiv.sigma_equiv_prod Ξ± Ξ²).symm @[simp] theorem prod_of_nat_val (n : β„•) : of_nat (Ξ± Γ— Ξ²) n = (of_nat Ξ± (unpair n).1, of_nat Ξ² (unpair n).2) := by simp; refl @[simp] theorem prod_nat_of_nat : of_nat (β„• Γ— β„•) = unpair := by funext; simp instance int : denumerable β„€ := denumerable.mk' equiv.int_equiv_nat instance pnat : denumerable β„•+ := denumerable.mk' equiv.pnat_equiv_nat instance ulift : denumerable (ulift Ξ±) := of_equiv _ equiv.ulift instance plift : denumerable (plift Ξ±) := of_equiv _ equiv.plift def pair : Ξ± Γ— Ξ± ≃ Ξ± := equivβ‚‚ _ _ end end denumerable namespace nat.subtype open function encodable variables {s : set β„•} [infinite s] section classical open_locale classical lemma exists_succ (x : s) : βˆƒ n, x.1 + n + 1 ∈ s := classical.by_contradiction $ Ξ» h, have βˆ€ (a : β„•) (ha : a ∈ s), a < x.val.succ, from Ξ» a ha, lt_of_not_ge (Ξ» hax, h ⟨a - (x.1 + 1), by rwa [add_right_comm, nat.add_sub_cancel' hax]⟩), infinite.not_fintype ⟨(((multiset.range x.1.succ).filter (∈ s)).pmap (Ξ» (y : β„•) (hy : y ∈ s), subtype.mk y hy) (by simp [-multiset.range_succ])).to_finset, by simpa [subtype.ext_iff_val, multiset.mem_filter, -multiset.range_succ]⟩ end classical variable [decidable_pred s] def succ (x : s) : s := have h : βˆƒ m, x.1 + m + 1 ∈ s, from exists_succ x, ⟨x.1 + nat.find h + 1, nat.find_spec h⟩ lemma succ_le_of_lt {x y : s} (h : y < x) : succ y ≀ x := have hx : βˆƒ m, y.1 + m + 1 ∈ s, from exists_succ _, let ⟨k, hk⟩ := nat.exists_eq_add_of_lt h in have nat.find hx ≀ k, from nat.find_min' _ (hk β–Έ x.2), show y.1 + nat.find hx + 1 ≀ x.1, by rw hk; exact add_le_add_right (add_le_add_left this _) _ lemma le_succ_of_forall_lt_le {x y : s} (h : βˆ€ z < x, z ≀ y) : x ≀ succ y := have hx : βˆƒ m, y.1 + m + 1 ∈ s, from exists_succ _, show x.1 ≀ y.1 + nat.find hx + 1, from le_of_not_gt $ Ξ» hxy, have y.1 + nat.find hx + 1 ≀ y.1 := h ⟨_, nat.find_spec hx⟩ hxy, not_lt_of_le this $ calc y.1 ≀ y.1 + nat.find hx : le_add_of_nonneg_right (nat.zero_le _) ... < y.1 + nat.find hx + 1 : nat.lt_succ_self _ lemma lt_succ_self (x : s) : x < succ x := calc x.1 ≀ x.1 + _ : le_add_right (le_refl _) ... < succ x : nat.lt_succ_self (x.1 + _) lemma lt_succ_iff_le {x y : s} : x < succ y ↔ x ≀ y := ⟨λ h, le_of_not_gt (Ξ» h', not_le_of_gt h (succ_le_of_lt h')), Ξ» h, lt_of_le_of_lt h (lt_succ_self _)⟩ def of_nat (s : set β„•) [decidable_pred s] [infinite s] : β„• β†’ s | 0 := βŠ₯ | (n+1) := succ (of_nat n) lemma of_nat_surjective_aux : βˆ€ {x : β„•} (hx : x ∈ s), βˆƒ n, of_nat s n = ⟨x, hx⟩ | x := Ξ» hx, let t : list s := ((list.range x).filter (Ξ» y, y ∈ s)).pmap (Ξ» (y : β„•) (hy : y ∈ s), ⟨y, hy⟩) (by simp) in have hmt : βˆ€ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩, by simp [list.mem_filter, subtype.ext_iff_val, t]; intros; refl, have wf : βˆ€ m : s, list.maximum t = m β†’ m.1 < x, from Ξ» m hmax, by simpa [hmt] using list.maximum_mem hmax, begin cases hmax : list.maximum t with m, { exact ⟨0, le_antisymm (@bot_le s _ _) (le_of_not_gt (Ξ» h, list.not_mem_nil (βŠ₯ : s) $ by rw [← list.maximum_eq_none.1 hmax, hmt]; exact h))⟩ }, { cases of_nat_surjective_aux m.2 with a ha, exact ⟨a + 1, le_antisymm (by rw of_nat; exact succ_le_of_lt (by rw ha; exact wf _ hmax)) $ by rw of_nat; exact le_succ_of_forall_lt_le (Ξ» z hz, by rw ha; cases m; exact list.le_maximum_of_mem (hmt.2 hz) hmax)⟩ } end using_well_founded {dec_tac := `[tauto]} lemma of_nat_surjective : surjective (of_nat s) := Ξ» ⟨x, hx⟩, of_nat_surjective_aux hx private def to_fun_aux (x : s) : β„• := (list.range x).countp s private lemma to_fun_aux_eq (x : s) : to_fun_aux x = ((finset.range x).filter s).card := by rw [to_fun_aux, list.countp_eq_length_filter]; refl open finset private lemma right_inverse_aux : βˆ€ n, to_fun_aux (of_nat s n) = n | 0 := begin rw [to_fun_aux_eq, card_eq_zero, eq_empty_iff_forall_not_mem], assume n, rw [mem_filter, of_nat, mem_range], assume h, exact not_lt_of_le bot_le (show (⟨n, h.2⟩ : s) < βŠ₯, from h.1) end | (n+1) := have ih : to_fun_aux (of_nat s n) = n, from right_inverse_aux n, have h₁ : (of_nat s n : β„•) βˆ‰ (range (of_nat s n)).filter s, by simp, have hβ‚‚ : (range (succ (of_nat s n))).filter s = insert (of_nat s n) ((range (of_nat s n)).filter s), begin simp only [finset.ext_iff, mem_insert, mem_range, mem_filter], assume m, exact ⟨λ h, by simp only [h.2, and_true]; exact or.symm (lt_or_eq_of_le ((@lt_succ_iff_le _ _ _ ⟨m, h.2⟩ _).1 h.1)), Ξ» h, h.elim (Ξ» h, h.symm β–Έ ⟨lt_succ_self _, subtype.property _⟩) (Ξ» h, ⟨lt_of_le_of_lt (le_of_lt h.1) (lt_succ_self _), h.2⟩)⟩ end, begin clear_aux_decl, simp only [to_fun_aux_eq, of_nat, range_succ] at *, conv {to_rhs, rw [← ih, ← card_insert_of_not_mem h₁, ← hβ‚‚] }, end def denumerable (s : set β„•) [decidable_pred s] [infinite s] : denumerable s := denumerable.of_equiv β„• { to_fun := to_fun_aux, inv_fun := of_nat s, left_inv := left_inverse_of_surjective_of_right_inverse of_nat_surjective right_inverse_aux, right_inv := right_inverse_aux } end nat.subtype namespace denumerable open encodable def of_encodable_of_infinite (Ξ± : Type*) [encodable Ξ±] [infinite Ξ±] : denumerable Ξ± := begin letI := @decidable_range_encode Ξ± _; letI : infinite (set.range (@encode Ξ± _)) := infinite.of_injective _ (equiv.set.range _ encode_injective).injective, letI := nat.subtype.denumerable (set.range (@encode Ξ± _)), exact denumerable.of_equiv (set.range (@encode Ξ± _)) (equiv_range_encode Ξ±) end end denumerable
3144916ce11f31c25e1b02a38d67460431b9e036
88892181780ff536a81e794003fe058062f06758
/src/algorithms/insertion_sort.lean
1fe135f8c1c5a4e2dfe6ab756fe7a7d9e93143f0
[]
no_license
AtnNn/lean-sandbox
fe2c44280444e8bb8146ab8ac391c82b480c0a2e
8c68afbdc09213173aef1be195da7a9a86060a97
refs/heads/master
1,623,004,395,876
1,579,969,507,000
1,579,969,507,000
146,666,368
0
0
null
null
null
null
UTF-8
Lean
false
false
61
lean
import algorithms.data.array insertion_sort (A : vector) :
17cb659bd10497d2535f8e8e305f7079698322a2
ae9f8bf05de0928a4374adc7d6b36af3411d3400
/src/formal_ml/radon_nikodym.lean
4002cf64bfff4ed6cb4593fe8d3bb6c000afa401
[ "Apache-2.0" ]
permissive
NeoTim/formal-ml
bc42cf6beba9cd2ed56c1cd054ab4eb5402ed445
c9cbad2837104160a9832a29245471468748bb8d
refs/heads/master
1,671,549,160,900
1,601,362,989,000
1,601,362,989,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
83,534
lean
/- Copyright 2020 Google LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -/ import measure_theory.measurable_space import measure_theory.measure_space import measure_theory.outer_measure import measure_theory.lebesgue_measure import measure_theory.integration import measure_theory.set_integral import measure_theory.borel_space import data.set.countable import formal_ml.nnreal import formal_ml.sum import formal_ml.core import formal_ml.measurable_space import formal_ml.semiring import formal_ml.real_measurable_space import formal_ml.set import formal_ml.filter_util import topology.instances.ennreal import formal_ml.int import formal_ml.with_density_compose_eq_multiply import formal_ml.hahn /- The Lebesgue-Radon-Nikodym theorem, while it delves deeply into the nuances of measure theory, provides the foundation for statistics and probability. Specifically, continuous random variables can be represented by a density function. The Lebesgue-Radon-Nikodym theorem (and the Radon-Nikodym theorem) exactly characterize what probability measures have this simple representation: specifically, those that are absolutely continuous with respect to the Lebesgue measure. This theorem, like the fundamental theorem of calculus, provides a deep insight that can be easily used even by those who do not understand the nuances of the proof. -/ lemma ennreal.ne_zero_iff_zero_lt {x:ennreal}:x β‰  0 ↔ 0 < x := begin split;intros A1, { apply lt_of_not_ge, intro B1, apply A1, simp at B1, apply B1, }, { intros C1, subst x, simp at A1, apply A1, }, end lemma real.sub_le_sub_of_le_of_le_of_le {a b c d:real}: a ≀ b β†’ c ≀ d β†’ a ≀ b - c + d := begin intros A1 A2, apply le_trans A1, have B1:b - c + c ≀ b - c + d, { apply add_le_add, apply le_refl _, apply A2, }, simp at B1, apply B1 end lemma nnreal.sub_le_sub_of_le_of_le_of_le {a b c d:nnreal}: a ≀ b β†’ c ≀ d β†’ d ≀ a β†’ a ≀ b - c + d := begin intros A1 A2 A3, rw ← nnreal.coe_le_coe, rw nnreal.coe_add, rw nnreal.coe_sub, apply real.sub_le_sub_of_le_of_le_of_le, { rw nnreal.coe_le_coe, apply A1, }, { rw nnreal.coe_le_coe, apply A2, }, apply le_trans A2, apply le_trans A3, apply le_trans A1, apply le_refl _, end lemma ennreal.sub_le_sub_of_le_of_le_of_le {a b c d:ennreal}: a ≀ b β†’ c ≀ d β†’ d ≀ a β†’ a - d ≀ b - c := begin cases a;cases b;cases c;cases d;try {simp}, intros A1 A2 A3, have B1:(a:ennreal) ≀ (b:ennreal) - (c:ennreal) + (d:ennreal), { rw ← ennreal.coe_sub, rw ← ennreal.coe_add, rw ennreal.coe_le_coe, apply nnreal.sub_le_sub_of_le_of_le_of_le A1 A2 A3, }, apply B1, end lemma nnreal.mul_lt_mul_of_pos_of_lt {a b c:nnreal}:(0 < a) β†’ (b < c) β†’ (a * b < a * c) := begin intros A1 A2, apply mul_lt_mul', apply le_refl _, apply A2, simp, apply A1, end /- It is hard to generalize this. -/ lemma nnreal.mul_pos_iff_pos_pos {a b:nnreal}:(0 < a * b) ↔ (0 < a)∧ (0 < b) := begin split;intros A1, { rw zero_lt_iff_ne_zero at A1, repeat {rw zero_lt_iff_ne_zero}, split;intro B1;apply A1, { rw B1, rw zero_mul, }, { rw B1, rw mul_zero, }, }, { have C1:0 ≀ a * 0, { simp, }, apply lt_of_le_of_lt C1, apply nnreal.mul_lt_mul_of_pos_of_lt, apply A1.left, apply A1.right, }, end lemma nnreal.inv_mul_eq_inv_mul_inv {a b:nnreal}:(a * b)⁻¹=a⁻¹ * b⁻¹ := begin rw nnreal.mul_inv, rw mul_comm, end lemma nnreal.le_zero_iff {a:nnreal}:a ≀ 0 ↔ a=0 := begin simp end lemma nnreal.pos_iff {a:nnreal}:0 < a ↔ a β‰  0 := begin split;intros B1, { intros C1, subst a, simp at B1, apply B1, }, { apply by_contradiction, intros D1, apply B1, rw ← @nnreal.le_zero_iff a, apply le_of_not_lt D1, }, end lemma ennreal.inv_mul_eq_inv_mul_inv {a b:ennreal}:(aβ‰  0) β†’ (bβ‰  0) β†’ (a * b)⁻¹=a⁻¹ * b⁻¹ := begin cases a;simp;cases b;simp, intros A1 A2, rw ← ennreal.coe_mul, repeat {rw ← ennreal.coe_inv}, rw ← ennreal.coe_mul, rw ennreal.coe_eq_coe, apply @nnreal.inv_mul_eq_inv_mul_inv a b, apply A2, apply A1, rw ← @nnreal.pos_iff (a * b), rw nnreal.mul_pos_iff_pos_pos, repeat {rw zero_lt_iff_ne_zero}, apply and.intro A1 A2, end lemma ennreal.div_dist {a b c:ennreal}:(bβ‰  0) β†’ (cβ‰  0) β†’ a/(b * c)=(a/b)/c := begin intros A1 A2, rw ennreal.div_def, rw ennreal.inv_mul_eq_inv_mul_inv, rw ← mul_assoc, rw ennreal.div_def, rw ennreal.div_def, apply A1, apply A2, end lemma ennreal.div_eq_zero_iff {a b:ennreal}:a/b=0 ↔ (a = 0) ∨ (b = ⊀) := begin cases a;cases b;split;simp;intros A1;simp;simp at A1, end /- Helper function to lift nnreal.exists_unit_frac_lt_pos to ennreal. -/ lemma ennreal.exists_unit_frac_lt_pos' {Ξ΅:nnreal}:0 < Ξ΅ β†’ (βˆƒ n:β„•, (1/((n:ennreal) + 1)) < (Ξ΅:ennreal)) := begin intros A1, -- simp at A1, have C1:= nnreal.exists_unit_frac_lt_pos A1, cases C1 with n A1, apply exists.intro n, have D1:((1:nnreal):ennreal) = 1 := rfl, rw ← D1, have D2:((n:nnreal):ennreal) = (n:ennreal), { simp, }, rw ← D2, rw ← ennreal.coe_add, rw ← ennreal.coe_div, rw ennreal.coe_lt_coe, apply A1, simp, end lemma ennreal.exists_unit_frac_lt_pos {Ξ΅:ennreal}:0 < Ξ΅ β†’ (βˆƒ n:β„•, (1/((n:ennreal) + 1)) < Ξ΅) := begin cases Ξ΅, { intros A1, have B1:(0:nnreal) < (1:nnreal), { apply zero_lt_one, }, have B1:=ennreal.exists_unit_frac_lt_pos' B1, cases B1 with n B1, apply exists.intro n, apply lt_of_lt_of_le B1, simp, }, { intros A1, simp at A1, have C1:= ennreal.exists_unit_frac_lt_pos' A1, apply C1, }, end lemma ennreal.zero_of_le_all_unit_frac {x:ennreal}: (βˆ€ (n:β„•), (x ≀ 1/((n:ennreal) + 1))) β†’ (x = 0) := begin intros A1, rw ← not_exists_not at A1, apply by_contradiction, intros B1, apply A1, have B2:0 < x, { rw zero_lt_iff_ne_zero, apply B1, }, have B3:= ennreal.exists_unit_frac_lt_pos B2, cases B3 with n B3, apply exists.intro n, apply not_le_of_lt, apply B3, end lemma ennreal.unit_frac_pos {n:β„•}:(1/((n:ennreal) + 1))>0 := begin simp, intros B1, rw ennreal.add_eq_top at B1, simp at B1, apply B1, end lemma ennreal.div_eq_top_iff {a b:ennreal}:a/b=⊀ ↔ ((a = ⊀)∧(bβ‰  ⊀) )∨ ((aβ‰  0)∧(b=0)):= begin rw ennreal.div_def, cases a;cases b;simp, end lemma ennreal.unit_frac_ne_top {n:β„•}:(1/((n:ennreal) + 1))β‰  ⊀ := begin intro A1, rw ennreal.div_eq_top_iff at A1, simp at A1, apply A1, end lemma nnreal.mul_le_mul_left' (a b:nnreal) (H:a≀ b) (c:nnreal): c * a ≀ c * b := begin cases (classical.em (c = 0)) with B1 B1, { subst c, simp, }, { have C1:0 < c, { rw zero_lt_iff, intro C1A, apply B1, apply C1A, }, rw mul_le_mul_left, apply H, apply C1, }, end lemma ennreal.mul_le_mul_left' (a b:ennreal) (H:a≀ b) (c:ennreal): c * a ≀ c * b := begin revert H, cases c;cases a;cases b;try {simp}, { intros A1, rw ennreal.top_mul, rw ennreal.top_mul, cases (classical.em (a = 0)) with B1 B1, { subst a, simp, }, { have B2:0 < a, { rw zero_lt_iff_ne_zero, intro B2A, rw B2A at B1, simp at B1, apply B1, }, have B3:0 < b, { apply lt_of_lt_of_le B2 A1, }, have B4:(b:ennreal) β‰  0, { rw zero_lt_iff_ne_zero at B3, intros B4A, apply B3, simp at B4A, apply B4A, }, rw if_neg B4, simp, }, }, { apply le_refl _, }, { rw ennreal.mul_top, cases (classical.em (c = 0)) with D1 D1, { subst c, simp, }, { have E1:Β¬((c:ennreal) = 0), { intro E1A, apply D1, simp at E1A, apply E1A, }, rw if_neg E1, simp, }, }, rw ← ennreal.coe_mul, rw ← ennreal.coe_mul, rw ennreal.coe_le_coe, intro F1, apply nnreal.mul_le_mul_left', apply F1, end lemma lt_eq_le_compl {Ξ΄ Ξ±:Type*} [linear_order Ξ±] {f g : Ξ΄ β†’ Ξ±}:{a | f a < g a} ={a | g a ≀ f a}ᢜ := begin apply set.ext, intros Ο‰;split;intros A3A;simp;simp at A3A;apply A3A, end lemma ennreal.lt_add_self {a b:ennreal}:a < ⊀ β†’ 0 < b β†’ a < a + b := begin cases a;cases b;simp, intros A1, rw ← ennreal.coe_add, rw ennreal.coe_lt_coe, simp, apply A1, end ---------------------------End theorems to move---------------------------------- lemma simple_restrict_eq_indicator_const {Ξ©:Type*} {M:measurable_space Ξ©} (S:set Ξ©) (x:ennreal):(is_measurable S) β†’ ⇑((measure_theory.simple_func.const Ξ© x).restrict S) = (set.indicator S (Ξ» Ο‰:Ξ©, x)) := begin intro A1, rw measure_theory.simple_func.coe_restrict, rw measure_theory.simple_func.coe_const, apply A1, end lemma with_density_const_apply {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) {k:ennreal} {S:set Ξ©}:is_measurable S β†’ ΞΌ.with_density (Ξ» Ο‰:Ξ©, k) S = k * ΞΌ S := begin intros B1, rw measure_theory.with_density_apply2', rw ← simple_restrict_eq_indicator_const, rw measure_theory.simple_func.lintegral_eq_lintegral, rw measure_theory.simple_func.restrict_const_lintegral, repeat {apply B1}, end lemma measure_theory.measure.le_zero_iff {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ:measure_theory.measure Ξ©):ΞΌ ≀ 0 ↔ ΞΌ = 0 := begin split;intros A1, { apply le_antisymm A1, apply measure_theory.measure.zero_le, }, { rw A1, apply le_refl _, }, end lemma measure_theory.measure.sub_eq_zero_if_le {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©):ΞΌ ≀ Ξ½ β†’ ΞΌ - Ξ½ = 0 := begin intros A1, rw ← measure_theory.measure.le_zero_iff, rw measure_theory.measure.sub_def, apply @Inf_le (measure_theory.measure Ξ©) _ _, simp [A1], end lemma measure_sub_add {Ξ±:Type*} [M:measurable_space Ξ±] {ΞΌ Ξ½:measure_theory.measure Ξ±} (H:Ξ½ ≀ ΞΌ) [H2:measure_theory.finite_measure Ξ½]:ΞΌ = Ξ½ + (measure_sub H) := begin apply measure_theory.measure.ext, intros s A3, simp, rw measure_sub_apply, rw add_comm, rw ennreal.sub_add_cancel_of_le, apply H, repeat {apply A3}, end lemma measure_sub_eq {Ξ±:Type*} [M:measurable_space Ξ±] (ΞΌ Ξ½:measure_theory.measure Ξ±) (H:Ξ½ ≀ ΞΌ) (H2:measure_theory.finite_measure Ξ½):(ΞΌ - Ξ½) = (measure_sub H) := begin rw measure_theory.measure.sub_def, have A1B:ΞΌ = Ξ½ + measure_sub H := measure_sub_add H, apply le_antisymm, { have A1:ΞΌ ≀ (measure_sub H) + Ξ½, { rw add_comm, rw ← A1B, apply le_refl ΞΌ, }, have A2:(measure_sub H) ∈ {d|ΞΌ ≀ d + Ξ½} := A1, apply Inf_le A2, }, { apply @le_Inf (measure_theory.measure Ξ±) _, intros b B1, simp at B1, rw A1B at B1, rw add_comm at B1, apply measure_theory.measure.le_of_add_le_add_right B1, }, end lemma le_of_le_measure_sub {Ξ±:Type*} [M:measurable_space Ξ±] {ΞΌ ν₁ Ξ½β‚‚:measure_theory.measure Ξ±} [H2:measure_theory.finite_measure ΞΌ] [H3:measure_theory.finite_measure ν₁] (H:ν₁ ≀ ΞΌ): Ξ½β‚‚ ≀ (measure_sub H) β†’ ν₁ + Ξ½β‚‚ ≀ ΞΌ := begin intro A1, have B1:ΞΌ = ν₁ + (measure_sub H), { apply measure_sub_add, }, rw B1, apply measure_theory.measure.add_le_add_left, apply A1, end lemma measure_theory.measure.sub_apply {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) {S:set Ξ©} [A2:measure_theory.finite_measure Ξ½]: is_measurable S β†’ Ξ½ ≀ ΞΌ β†’ (ΞΌ - Ξ½) S = ΞΌ S - Ξ½ S := begin intros A1 A3, rw measure_sub_eq ΞΌ Ξ½ A3 A2, apply measure_sub_apply, apply A1, end lemma measure_theory.measure.restrict_apply_subset {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ:measure_theory.measure Ξ©) {S T:set Ξ©}:is_measurable S β†’ S βŠ† T β†’ (ΞΌ.restrict T) S = ΞΌ S := begin intros A1 A3, rw measure_theory.measure.restrict_apply A1, simp [set.inter_eq_self_of_subset_left,A3], end lemma measure_theory.measure.restrict_apply_self {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ:measure_theory.measure Ξ©) {S:set Ξ©} (H:is_measurable S): (ΞΌ.restrict S) S = ΞΌ S := begin rw measure_theory.measure.restrict_apply H, simp, end lemma restrict_le_restrict_of_le_on_subsets {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) {S:set Ξ©}: le_on_subsets ΞΌ Ξ½ S β†’ (ΞΌ.restrict S) ≀ Ξ½.restrict S := begin intros A1, rw le_on_subsets_def at A1, rw measure_theory.measure.le_iff, intros T B1, rw measure_theory.measure.restrict_apply, rw measure_theory.measure.restrict_apply, apply A1.right, simp, apply is_measurable.inter, apply B1, apply A1.left, repeat {apply B1}, end /- Not required, but completes the connection between le_on_subsets and restrict. -/ lemma le_on_subsets_of_is_measurable_of_restrict_le_restrict {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) {S:set Ξ©}:is_measurable S β†’ (ΞΌ.restrict S) ≀ Ξ½.restrict S β†’ le_on_subsets ΞΌ Ξ½ S := begin intros A1 A2, rw measure_theory.measure.le_iff at A2, rw le_on_subsets_def, apply and.intro A1, intros X B1 B2, have B3 := A2 X B2, rw measure_theory.measure.restrict_apply_subset ΞΌ B2 B1 at B3, rw measure_theory.measure.restrict_apply_subset Ξ½ B2 B1 at B3, apply B3, end lemma measure_theory.outer_measure.Inf_gen_nonempty3 {Ξ±:Type*} (m : set (measure_theory.outer_measure Ξ±)) (t:set Ξ±) :m.nonempty β†’ measure_theory.outer_measure.Inf_gen m t = (β¨… (ΞΌ : measure_theory.outer_measure Ξ±) (H:μ∈ m), ΞΌ t) := begin intro A1, have B1:βˆƒ ΞΌ:measure_theory.outer_measure Ξ±, ΞΌ ∈ m, { rw set.nonempty_def at A1, apply A1, }, cases B1 with ΞΌ B1, rw measure_theory.outer_measure.Inf_gen_nonempty2 _ ΞΌ B1, end lemma measure_theory.outer_measure.of_function_def2 {Ξ± : Type*} (m : set Ξ± β†’ ennreal) (m_empty : m βˆ… = 0) (s:set Ξ±): (measure_theory.outer_measure.of_function m m_empty) s = β¨…{f : β„• β†’ set Ξ±} (h : s βŠ† ⋃i, f i), βˆ‘'i, m (f i) := rfl lemma set.Union_inter_eq_inter_Union {Ξ± Ξ²:Type*} {f:Ξ± β†’ set Ξ²} {T:set Ξ²}: (⋃ (a:Ξ±), f a ∩ T) = T ∩ (⋃ (a:Ξ±), f a) := begin apply set.ext, intro b,split;intros B1;simp;simp at B1; apply and.intro B1.right B1.left, end lemma set.Union_union_eq_union_Union {Ξ± Ξ²:Type*} [NE:nonempty Ξ±] {f:Ξ± β†’ set Ξ²} {T:set Ξ²}: (⋃ (a:Ξ±), f a βˆͺ T) = T βˆͺ (⋃ (a:Ξ±), f a) := begin apply set.ext, intro b,split;intros B1;simp;simp at B1, { cases B1 with a B2, cases B2 with B3 B4, { right, apply exists.intro a B3, }, { left, apply B4, }, }, { cases B1 with C1 C2, { apply nonempty.elim NE, intro a, apply exists.intro a, right, apply C1, }, { cases C2 with a C3, apply exists.intro a, left, apply C3, }, }, end lemma set.subset_union_compl_of_inter_subset {Ξ±:Type*} {A B C:set Ξ±}:A ∩ B βŠ† C β†’ A βŠ† C βˆͺ Bᢜ := begin intro D1, rw set.subset_def, intros x D2, rw set.subset_def at D1, simp, cases (classical.em (x∈ B)) with D3 D3, { left, apply D1, simp [D2,D3], }, { right, apply D3, }, end lemma infi_le_trans {Ξ± Ξ²:Type*} [complete_lattice Ξ²] (a:Ξ±) (f:Ξ± β†’ Ξ²) (b:Ξ²):(f a ≀ b) β†’ (β¨… (c:Ξ±), (f c)) ≀ b := begin intros A1, apply le_trans _ A1, apply @infi_le _ _ _, end /- I saw this pattern a bunch below. It could be more widely used. -/ lemma infi_set_le_trans {Ξ± Ξ²:Type*} [complete_lattice Ξ²] (a:Ξ±) (P:Ξ± β†’ Prop) (f:Ξ± β†’ Ξ²) (b:Ξ²):(P a) β†’ (f a ≀ b) β†’ (β¨… (c:Ξ±) (H:P c), f c) ≀ b := begin intros A1 A2, apply infi_le_trans a, rw infi_prop_def A1, apply A2, end lemma infi_set_image {Ξ± Ξ² Ξ³:Type*} [complete_lattice Ξ³] (S:set Ξ±) (f:Ξ± β†’ Ξ²) (g:Ξ² β†’ Ξ³):(β¨… (c∈ (f '' S)), g c) = β¨… (a∈ S), (g ∘ f) a := begin apply le_antisymm;simp, { intros a B1, apply infi_le_trans (f a), apply infi_le_trans a, rw infi_prop_def, apply and.intro B1, refl, }, { intros b a2 C1 C2, apply infi_le_trans a2, rw infi_prop_def C1, rw C2, }, end --Note that this does not hold true for empty S. --If S2.nonempty, but S2 ∩ T = βˆ…, then ⊀ (S2 ∩ T) = 0, but ⊀ (S2) = ⊀. lemma measure_theory.outer_measure.Inf_restrict {Ξ©:Type*} [measurable_space Ξ©] (S:set (measure_theory.outer_measure Ξ©)) {T:set Ξ©}: is_measurable T β†’ (S.nonempty) β†’ measure_theory.outer_measure.restrict T (Inf S) = Inf ((measure_theory.outer_measure.restrict T) '' S) := begin intros A1 B1, apply measure_theory.outer_measure.ext, intros S2, rw measure_theory.outer_measure.restrict_apply, rw measure_theory.outer_measure.Inf_eq_of_function_Inf_gen, rw measure_theory.outer_measure.Inf_eq_of_function_Inf_gen, rw measure_theory.outer_measure.of_function_def2, rw measure_theory.outer_measure.of_function_def2, have E1:((measure_theory.outer_measure.restrict T) '' S).nonempty, { apply set.nonempty_image_iff.mpr B1, }, apply le_antisymm, { simp, intros f C1, let g := Ξ» n, (f n) ∩ T, begin have C2:g = (Ξ» n, (f n) ∩ T) := rfl, have C3: (βˆ‘' (i:β„•), measure_theory.outer_measure.Inf_gen S (g i)) ≀ βˆ‘' (i : β„•), measure_theory.outer_measure.Inf_gen (⇑(measure_theory.outer_measure.restrict T) '' S) (f i), { apply ennreal.tsum_le_tsum, intro n, rw measure_theory.outer_measure.Inf_gen_nonempty3 _ _ B1, rw measure_theory.outer_measure.Inf_gen_nonempty3 _ _ E1, simp, intros ΞΌ' ΞΌ C3A C3B, subst ΞΌ', rw measure_theory.outer_measure.restrict_apply, rw C2, simp, have C3C:(β¨… (H : ΞΌ ∈ S), ΞΌ (f n ∩ T)) ≀ ΞΌ (f n ∩ T), { rw infi_prop_def, apply le_refl _, apply C3A, }, apply le_trans _ C3C, apply @infi_le ennreal _ _, }, apply le_trans _ C3, have C4:(β¨… (h : S2 ∩ T βŠ† ⋃ (i : β„•), g i), (βˆ‘' (i:β„•), measure_theory.outer_measure.Inf_gen S (g i))) ≀ (βˆ‘' (i:β„•), measure_theory.outer_measure.Inf_gen S (g i)), { rw infi_prop_def, apply le_refl _, rw C2, simp, rw set.Union_inter_eq_inter_Union, simp, apply set.subset.trans _ C1, apply set.inter_subset_left, }, apply le_trans _ C4, apply @infi_le ennreal _ _, end }, { simp, intros h D1, let g := Ξ» n, (h n) βˆͺ Tᢜ, begin have D2:g = Ξ» n, (h n) βˆͺ Tᢜ := rfl, apply @infi_set_le_trans (β„• β†’ set Ξ©) ennreal _ g, { rw D2, simp, rw set.Union_union_eq_union_Union, rw set.union_comm, apply set.subset_union_compl_of_inter_subset, apply D1, }, { apply ennreal.tsum_le_tsum, intro n, rw measure_theory.outer_measure.Inf_gen_nonempty3 _ _ B1, rw measure_theory.outer_measure.Inf_gen_nonempty3 _ _ E1, rw infi_set_image, simp, intros ΞΌ D3, apply @infi_set_le_trans (measure_theory.outer_measure Ξ©) ennreal _ ΞΌ, apply D3, { rw D2, simp, rw set.inter_distrib_right, simp, apply ΞΌ.mono, simp, }, }, end }, end lemma measure_theory.measure.lift_linear_def {Ξ± Ξ²:Type*} [measurable_space Ξ±] [MΞ²:measurable_space Ξ²] (f : measure_theory.outer_measure Ξ± β†’β‚—[ennreal] measure_theory.outer_measure Ξ²) (H:βˆ€ (ΞΌ : measure_theory.measure Ξ±), MΞ² ≀ (f ΞΌ.to_outer_measure).caratheodory) {ΞΌ:measure_theory.measure Ξ±}: (measure_theory.measure.lift_linear f H ΞΌ) = (f (ΞΌ.to_outer_measure)).to_measure (H ΞΌ) := begin apply measure_theory.measure.ext, intros S B1, unfold measure_theory.measure.lift_linear, simp, end lemma measure_theory.outer_measure.to_measure_to_outer_measure_eq_trim {Ξ©:Type*} [M:measurable_space Ξ©] {ΞΌ:measure_theory.outer_measure Ξ©} (H:M ≀ (ΞΌ).caratheodory): (ΞΌ.to_measure H).to_outer_measure = ΞΌ.trim := begin apply measure_theory.outer_measure.ext, intros S, unfold measure_theory.outer_measure.to_measure measure_theory.measure.to_outer_measure measure_theory.outer_measure.trim measure_theory.measure.of_measurable, simp, refl, end lemma infi_prop_false2 {Ξ±:Type*} [complete_lattice Ξ±] {P:Prop} {v:Pβ†’ Ξ±} (H:Β¬P):(β¨… (H2:P), v H2) = ⊀ := begin apply le_antisymm, { simp, }, { apply @le_infi Ξ± _ _, intro H2, exfalso, apply H, apply H2, }, end lemma measure_theory.extend_top {Ξ± : Type*} {P : Ξ± β†’ Prop} {m : Ξ  (s : Ξ±), P s β†’ ennreal} {s : Ξ±}: ( Β¬P s)β†’ measure_theory.extend m s = ⊀ := begin intros A1, unfold measure_theory.extend, rw infi_prop_false2, apply A1, end --Unused. lemma measure_theory.le_extend2 {Ξ±:Type*} [measurable_space Ξ±] {x:ennreal} {h:Ξ  (s:set Ξ±), (is_measurable s) β†’ ennreal} (s:set Ξ±): (Ξ  (H:is_measurable s), (x ≀ h s H)) β†’ (x ≀ measure_theory.extend h s) := begin intros A1, cases (classical.em (is_measurable s)) with B1 B1, { apply le_trans (A1 B1), apply measure_theory.le_extend, }, { rw measure_theory.extend_top B1, simp, }, end /- This is a result that must be proven directly for restrict, but has larger implications. I am curious whether this follows from lift_linear constraint on the catheodary measurable space of the output outer measure of restrict. That would be a more general result, implying that this would hold for all places where lift_linear was used. -/ lemma measure_theory.outer_measure.restrict_trimmed_of_trimmed {Ξ©:Type*} [M:measurable_space Ξ©] {ΞΌ:measure_theory.outer_measure Ξ©} {S:set Ξ©}:is_measurable S β†’ ΞΌ.trim = ΞΌ β†’ (measure_theory.outer_measure.restrict S ΞΌ).trim = (measure_theory.outer_measure.restrict S ΞΌ) := begin intros A2 A1, apply measure_theory.outer_measure.ext, unfold measure_theory.outer_measure.trim, unfold measure_theory.induced_outer_measure, intros T, simp, rw measure_theory.outer_measure.of_function_def2, apply le_antisymm, { have B1:ΞΌ (T ∩ S) = ΞΌ.trim (T ∩ S), { rw A1, }, rw B1, unfold measure_theory.outer_measure.trim, unfold measure_theory.induced_outer_measure, rw measure_theory.outer_measure.of_function_def2, simp, intros h B2, let g := Ξ» (n:β„•), (h n) βˆͺ Sᢜ, begin have B3:g = Ξ» (n:β„•), (h n) βˆͺ Sᢜ := rfl, have B4:(βˆ‘' (i : β„•), measure_theory.extend (Ξ» (s : set Ξ©) (_x : is_measurable s), ΞΌ (s ∩ S)) (g i)) ≀ βˆ‘' (i : β„•), measure_theory.extend (Ξ» (s : set Ξ©) (_x : is_measurable s), ΞΌ s) (h i), { apply ennreal.tsum_le_tsum, intros n, apply measure_theory.le_extend2, intro B4A, rw measure_theory.extend_eq, rw B3, simp, rw set.inter_distrib_right, simp, apply measure_theory.outer_measure.mono', simp, rw B3, simp, apply is_measurable.union B4A (is_measurable.compl A2), }, apply le_trans _ B4, clear B4, have B5:(β¨… (h : T βŠ† ⋃ (i : β„•), g i), βˆ‘' (i : β„•), measure_theory.extend (Ξ» (s : set Ξ©) (_x : is_measurable s), ΞΌ (s ∩ S)) (g i)) ≀ βˆ‘' (i : β„•), measure_theory.extend (Ξ» (s : set Ξ©) (_x : is_measurable s), ΞΌ (s ∩ S)) (g i), { rw infi_prop_def, apply le_refl _, rw B3, simp, rw set.Union_union_eq_union_Union, rw set.union_comm, apply set.subset_union_compl_of_inter_subset B2, }, apply le_trans _ B5, apply @infi_le ennreal _ _, end }, { simp, intros h C1, let g := Ξ» n:β„•, h n ∩ S, begin have C2:g = Ξ» n:β„•, h n ∩ S := rfl, have C3:ΞΌ (T ∩ S) ≀ ΞΌ(set.Union g), { apply measure_theory.outer_measure.mono', rw C2, rw set.Union_inter_eq_inter_Union, rw set.inter_comm S, simp, apply set.subset.trans _ C1, simp, }, apply le_trans C3, have C4:ΞΌ(set.Union g) ≀ βˆ‘' (i:β„•), ΞΌ (g i), { apply measure_theory.outer_measure.Union, }, apply le_trans C4, apply ennreal.tsum_le_tsum, intro n, cases (classical.em (is_measurable (h n))) with C5 C5, { apply le_trans _ (measure_theory.le_extend _ C5), rw C2, apply le_refl _, }, { rw measure_theory.extend_top C5, simp, }, end }, end lemma measure_theory.measure.to_outer_measure.restrict' {Ξ©:Type*} [measurable_space Ξ©] {ΞΌ:measure_theory.measure Ξ©} {S:set Ξ©}:is_measurable S β†’ (ΞΌ.restrict S).to_outer_measure = measure_theory.outer_measure.restrict S (ΞΌ.to_outer_measure) := begin intros A1, apply measure_theory.outer_measure.ext, intro T, rw measure_theory.outer_measure.restrict_apply, simp, unfold measure_theory.measure.restrict, unfold measure_theory.measure.restrictβ‚—, rw measure_theory.measure.lift_linear_def, rw measure.apply, rw measure_theory.to_measure_to_outer_measure, --rw measure_theory.outer_measure.to_measure_to_outer_measure_eq_trim, rw measure_theory.outer_measure.restrict_trimmed_of_trimmed A1, simp, apply measure_theory.measure.trimmed, end lemma compose_image {Ξ± Ξ² Ξ³:Type*} {f:Ξ± β†’ Ξ²} {g:Ξ² β†’ Ξ³} {S:set Ξ±}: g '' (f '' S) = (g ∘ f) '' S := begin ext c, split; intros B1;simp;simp at B1;apply B1, end lemma measure_theory.measure.Inf_restrict {Ξ©:Type*} [measurable_space Ξ©] (S:set (measure_theory.measure Ξ©)) {T:set Ξ©}:S.nonempty β†’ is_measurable T β†’ (Inf S).restrict T = Inf ((Ξ» ΞΌ:measure_theory.measure Ξ©,ΞΌ.restrict T) '' S) := begin intros AX A1, apply measure_theory.measure.ext, intros S2 B1, rw measure_theory.measure.Inf_apply B1, rw measure_theory.measure.restrict_apply B1, rw measure_theory.measure.Inf_apply (is_measurable.inter B1 A1), have B3:(measure_theory.measure.to_outer_measure '' ((Ξ» (ΞΌ : measure_theory.measure Ξ©), ΞΌ.restrict T) '' S)) = (measure_theory.outer_measure.restrict T) ''( measure_theory.measure.to_outer_measure '' S), { rw compose_image, rw compose_image, have B3A:(measure_theory.measure.to_outer_measure ∘ Ξ» (ΞΌ : measure_theory.measure Ξ©), ΞΌ.restrict T) = (measure_theory.outer_measure.restrict T) ∘ (measure_theory.measure.to_outer_measure), { apply funext, intro ΞΌ, simp, apply measure_theory.measure.to_outer_measure.restrict', apply A1, }, rw B3A, }, rw B3, rw ← measure_theory.outer_measure.Inf_restrict _ A1, rw measure_theory.outer_measure.restrict_apply, apply set.nonempty_image_iff.mpr, apply AX, end lemma measure_theory.measure.restrict_le_restrict_of_le {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) {S:set Ξ©}: ΞΌ ≀ Ξ½ β†’ ΞΌ.restrict S ≀ Ξ½.restrict S := begin intros A1, apply measure_theory.measure.restrict_mono, apply set.subset.refl, apply A1, end lemma measure_theory.measure_partition_apply {Ξ©:Type*} [M:measurable_space Ξ©] (ΞΌ:measure_theory.measure Ξ©) (S T:set Ξ©):is_measurable S β†’ is_measurable T β†’ ΞΌ T = ΞΌ (S ∩ T) + ΞΌ (Sᢜ ∩ T) := begin intros A1 A2, rw set.inter_comm, rw set.inter_comm Sᢜ, have B1:T = (T∩ S) βˆͺ (T∩ Sᢜ), { rw set.inter_union_compl, }, --have B2:ΞΌ T = rw ← @measure_theory.measure_union Ξ© M ΞΌ (T∩ S) _, rw ← B1, apply set.disjoint_inter_compl, apply is_measurable.inter, apply A2, apply A1, apply is_measurable.inter, apply A2, apply is_measurable.compl, apply A1, end lemma measure_theory.measure.le_of_partition {Ξ©:Type*} [M:measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) {S T:set Ξ©}:is_measurable S β†’ is_measurable T β†’ ΞΌ (S ∩ T) ≀ Ξ½ (S ∩ T) β†’ ΞΌ (Sᢜ ∩ T) ≀ Ξ½ (Sᢜ ∩ T) β†’ ΞΌ T ≀ Ξ½ T := begin intros A1 A2 A3 A4, rw measure_theory.measure_partition_apply ΞΌ S T, rw measure_theory.measure_partition_apply Ξ½ S T, have B1:ΞΌ (S ∩ T) + ΞΌ (Sᢜ ∩ T) ≀ Ξ½ (S ∩ T) + ΞΌ (Sᢜ ∩ T), { apply add_le_add_right A3, }, apply le_trans B1, apply add_le_add_left A4, repeat {assumption}, end lemma Inf_le_Inf' {Ξ±:Type*} [complete_lattice Ξ±] {S T:set Ξ±}:(βˆ€ t∈ T, βˆƒ s∈ S, s ≀ t) β†’ Inf S ≀ Inf T := begin intros A1, apply @le_Inf, intros t B1, have B2 := A1 t B1, cases B2 with s B2, cases B2 with B2 B3, apply le_trans _ B3, apply @Inf_le, apply B2 end lemma measure_theory.outer_measure.le_top_caratheodory {Ξ©:Type*} [M:measurable_space Ξ©]: M ≀ (⊀:measure_theory.outer_measure Ξ©).caratheodory := begin rw measure_theory.outer_measure.top_caratheodory, simp end lemma measure_theory.measure.of_measurable_apply' {Ξ±:Type*} [M:measurable_space Ξ±] (m : Ξ  (s : set Ξ±), is_measurable s β†’ ennreal) (m0 : m βˆ… is_measurable.empty = 0) (mU : βˆ€ {{f : β„• β†’ set Ξ±}} (h : βˆ€i, is_measurable (f i)), pairwise (disjoint on f) β†’ m (⋃i, f i) (is_measurable.Union h) = (βˆ‘'i, m (f i) (h i))) (S:set Ξ±): measure_theory.measure.of_measurable m m0 mU S = measure_theory.induced_outer_measure m _ m0 S := begin unfold measure_theory.measure.of_measurable, simp, rw measure.apply, end lemma measure_theory.outer_measure.top_eq {Ξ©:Type*} [M:measurable_space Ξ©]: ⇑(⊀:measure_theory.outer_measure Ξ©) = (Ξ» (s:set Ξ©), (@ite (s=βˆ…) (classical.prop_decidable (s=βˆ…)) ennreal 0 ⊀)) := begin apply funext, intro S, cases (classical.em (S = βˆ…)) with B1 B1, { rw if_pos, subst S, apply measure_theory.outer_measure.empty', apply B1, }, { rw if_neg, apply measure_theory.outer_measure.top_apply, rw ← set.ne_empty_iff_nonempty, apply B1, apply B1, }, end lemma measure_theory.outer_measure.extend_top {Ξ©:Type*} [M:measurable_space Ξ©]: (measure_theory.extend (Ξ» (s : set Ξ©) (_x : is_measurable s), (⊀:measure_theory.outer_measure Ξ©) s))=(Ξ» (s:set Ξ©), (@ite (s=βˆ…) (classical.prop_decidable (s=βˆ…)) ennreal 0 ⊀)) := begin apply funext, intro S, rw measure_theory.outer_measure.top_eq, cases (classical.em (is_measurable S)) with B1 B1, { unfold measure_theory.extend, rw infi_prop_def, apply B1, }, { unfold measure_theory.extend, rw infi_prop_false, rw if_neg, intros B2, apply B1, subst S, simp, apply B1, }, end lemma measure_theory.outer_measure.extend_top' {Ξ©:Type*} [M:measurable_space Ξ©]: (measure_theory.extend (Ξ» (s : set Ξ©) (_x : is_measurable s), (⊀:measure_theory.outer_measure Ξ©) s))=(⊀:measure_theory.outer_measure Ξ©) := begin rw measure_theory.outer_measure.extend_top, rw measure_theory.outer_measure.top_eq, end lemma subst_apply_empty_zero {Ξ©:Type*} {f g:set Ξ© β†’ ennreal}:(f = g) β†’ (f βˆ… = 0) β†’ (g βˆ… = 0) := begin intros A1 A2, subst f, apply A2, end lemma measure_theory.outer_measure.of_function_subst {Ξ©:Type*} [M:measurable_space Ξ©] {f g:set Ξ© β†’ ennreal} {P:f βˆ… = 0} (H:f = g): measure_theory.outer_measure.of_function f P = measure_theory.outer_measure.of_function g (subst_apply_empty_zero H P) := begin subst g, end lemma measure_theory.outer_measure.of_function_eq' {Ξ©:Type*} [M:measurable_space Ξ©] {ΞΌ:measure_theory.outer_measure Ξ©} (H:ΞΌ βˆ… = 0): measure_theory.outer_measure.of_function (⇑μ) H = ΞΌ := begin apply measure_theory.outer_measure.ext, intro S, apply measure_theory.outer_measure.of_function_eq, { intros T B1, apply measure_theory.outer_measure.mono', apply B1, }, { intros f, apply measure_theory.outer_measure.Union_nat, }, end lemma measure_theory.outer_measure.top_eq_trim {Ξ©:Type*} [M:measurable_space Ξ©]: (⊀:measure_theory.outer_measure Ξ©).trim = ⊀ := begin unfold measure_theory.outer_measure.trim, unfold measure_theory.induced_outer_measure, have B1:= @measure_theory.outer_measure.extend_top' Ξ© M, rw measure_theory.outer_measure.of_function_subst B1, rw measure_theory.outer_measure.of_function_eq', end lemma measure_theory.outer_measure.top_to_measure_to_outer_measure_eq_top {Ξ©:Type*} [M:measurable_space Ξ©]: ((⊀:measure_theory.outer_measure Ξ©).to_measure measure_theory.outer_measure.le_top_caratheodory).to_outer_measure = ⊀ := begin apply measure_theory.outer_measure.ext, intro S, unfold measure_theory.outer_measure.to_measure, simp, rw measure_theory.measure.of_measurable_apply', unfold measure_theory.induced_outer_measure, have B1:= @measure_theory.outer_measure.extend_top' Ξ© M, rw measure_theory.outer_measure.of_function_subst B1, rw measure_theory.outer_measure.of_function_eq', end /- One could extract many monotone relationships from this: induced_outer_measure, extend, of_function, et cetera. However, I wouldn't be surprised to find them in the library. -/ lemma measure_theory.outer_measure.trim_monotone {Ξ©:Type*} [M:measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.outer_measure Ξ©):ΞΌ ≀ Ξ½ β†’ ΞΌ.trim ≀ Ξ½.trim := begin intros A1, rw outer_measure_measure_of_le, unfold measure_theory.outer_measure.trim, unfold measure_theory.induced_outer_measure, unfold measure_theory.outer_measure.of_function, intros S, simp, intros f B1, have B2:(βˆ‘' (i : β„•), measure_theory.extend (Ξ» (s : set Ξ©) (_x : is_measurable s), ΞΌ s) (f i)) ≀ βˆ‘' (i : β„•), measure_theory.extend (Ξ» (s : set Ξ©) (_x : is_measurable s), Ξ½ s) (f i), { apply ennreal.tsum_le_tsum, unfold measure_theory.extend, intros n, simp, intros B2A, rw infi_prop_def, apply A1, apply B2A, }, apply le_trans _ B2, have B3:(β¨… (h : S βŠ† ⋃ (i : β„•), f i),(βˆ‘' (i : β„•), measure_theory.extend (Ξ» (s : set Ξ©) (_x : is_measurable s), ΞΌ s) (f i))) = βˆ‘' (i : β„•), measure_theory.extend (Ξ» (s : set Ξ©) (_x : is_measurable s), ΞΌ s) (f i), { rw infi_prop_def, apply B1, }, rw ← B3, apply @infi_le ennreal _ _, end lemma measure_theory.measure.to_outer_measure_eq_top {Ξ©:Type*} [M:measurable_space Ξ©]: (⊀:measure_theory.measure Ξ©).to_outer_measure = ⊀ := begin rw ← measure_theory.measure.trimmed, rw ← @top_le_iff (measure_theory.outer_measure Ξ©) _, have B1:((⊀:measure_theory.outer_measure Ξ©).to_measure measure_theory.outer_measure.le_top_caratheodory).to_outer_measure.trim ≀ (⊀:measure_theory.measure Ξ©).to_outer_measure.trim, { apply measure_theory.outer_measure.trim_monotone, apply measure_theory.measure.to_outer_measure_le.mpr, simp }, rw measure_theory.outer_measure.top_to_measure_to_outer_measure_eq_top at B1, rw measure_theory.outer_measure.top_eq_trim at B1, apply B1, end lemma measure_theory.measure.top_apply {Ξ©:Type*} [M:measurable_space Ξ©] {S:set Ξ©}:S.nonempty β†’ (⊀:measure_theory.measure Ξ©)(S) = (⊀:ennreal) := begin intro A1, rw measure.apply, rw measure_theory.measure.to_outer_measure_eq_top, simp, rw measure_theory.outer_measure.top_apply A1, end lemma measure_theory.measure.le_add {Ξ©:Type*} [M:measurable_space Ξ©] {ΞΌ Ξ½:measure_theory.measure Ξ©}:ΞΌ ≀ ΞΌ + Ξ½ := begin rw measure_theory.measure.le_iff, intros S B1, simp, apply le_add_nonnegative _ _, end lemma measure_theory.measure.sub_restrict_comm {Ξ©:Type*} [M:measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) {S:set Ξ©}:is_measurable S β†’ (ΞΌ - Ξ½).restrict S = (ΞΌ.restrict S) - (Ξ½.restrict S) := begin intro A1, rw measure_theory.measure.sub_def, rw measure_theory.measure.sub_def, have G1:{d : measure_theory.measure Ξ© | ΞΌ ≀ d + Ξ½}.nonempty, { apply @set.nonempty_of_mem _ _ ΞΌ, simp, apply measure_theory.measure.le_add, }, rw measure_theory.measure.Inf_restrict _ G1 A1, apply le_antisymm, { apply @Inf_le_Inf' (measure_theory.measure Ξ©) _, intros t B1, simp at B1, apply exists.intro (t.restrict S), split, { simp, apply exists.intro (t + (⊀:measure_theory.measure Ξ©).restrict Sᢜ), split, { rw add_assoc, rw add_comm _ Ξ½, rw ← add_assoc, rw measure_theory.measure.le_iff, intros T E1, have E2:is_measurable (S ∩ T) := is_measurable.inter A1 E1, --rw measure_theory.measure.add_apply, apply measure_theory.measure.le_of_partition _ _ A1 E1; rw measure_theory.measure.add_apply, { rw measure_theory.measure.restrict_apply E2, rw set.inter_assoc, rw set.inter_comm _ Sᢜ, rw ← set.inter_assoc, rw set.inter_compl_self, simp, rw measure_theory.measure.le_iff at B1, have B2 := B1 (S ∩ T) E2, rw measure_theory.measure.add_apply at B2, rw measure_theory.measure.restrict_apply E2 at B2, rw measure_theory.measure.restrict_apply E2 at B2, have E3:S ∩ T ∩ S = S ∩ T, { rw set.inter_eq_self_of_subset_left, apply set.inter_subset_left S T, }, rw E3 at B2, apply B2, }, cases (@set.eq_empty_or_nonempty _ (Sᢜ ∩ T)) with E4 E4, { rw E4, simp, }, { rw measure_theory.measure.restrict_apply, have E5:Sᢜ ∩ T ∩ Sᢜ = Sᢜ ∩ T, { rw set.inter_eq_self_of_subset_left, apply set.inter_subset_left Sᢜ T, }, rw E5, have E6:(⊀:measure_theory.measure Ξ©)(Sᢜ ∩ T) = (⊀:ennreal), { apply measure_theory.measure.top_apply, apply E4, }, rw E6, simp, apply is_measurable.inter (is_measurable.compl A1) E1, }, }, { apply measure_theory.measure.ext, intros T D1, rw measure_theory.measure.restrict_apply D1, rw measure_theory.measure.restrict_apply D1, rw measure_theory.measure.add_apply, rw measure_theory.measure.restrict_apply (is_measurable.inter D1 A1), have D2:T ∩ S ∩ Sᢜ = βˆ…, { rw set.inter_assoc, simp, }, rw D2, simp, }, }, { apply measure_theory.measure.restrict_le_self, }, }, { apply @Inf_le_Inf' (measure_theory.measure Ξ©) _, intros s C1, simp at C1, cases C1 with t C1, cases C1 with C1 C2, subst s, apply exists.intro (t.restrict S), split, { simp, rw ← measure_theory.measure.restrict_add, apply measure_theory.measure.restrict_le_restrict_of_le, apply C1, }, { apply le_refl _, }, }, end lemma jordan_decomposition_junior_zero {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) (S:set Ξ©) -- [measure_theory.finite_measure Ξ½] :le_on_subsets ΞΌ Ξ½ S β†’ (ΞΌ - Ξ½) S = 0 := begin intro A1, have B1 := le_on_subsets_is_measurable A1, rw ← measure_theory.measure.restrict_apply_self _ B1, rw measure_theory.measure.sub_restrict_comm, rw measure_theory.measure.sub_eq_zero_if_le, simp, apply restrict_le_restrict_of_le_on_subsets _ _ A1, apply B1, end --This works with EITHER Ξ½ or ΞΌ being finite, or even Ξ½ S < ⊀. lemma jordan_decomposition_junior_apply {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) (S:set Ξ©) [AX:measure_theory.finite_measure Ξ½]: le_on_subsets Ξ½ ΞΌ S β†’ (ΞΌ - Ξ½) S = ΞΌ S - Ξ½ S := begin intros A1, have B1 := le_on_subsets_is_measurable A1, rw ← measure_theory.measure.restrict_apply_self _ B1, rw measure_theory.measure.sub_restrict_comm, have B2:measure_theory.finite_measure (Ξ½.restrict S), { apply measure_theory.finite_measure_restrict, }, rw @measure_theory.measure.sub_apply Ξ© _ _ _ S B2, rw measure_theory.measure.restrict_apply_self, rw measure_theory.measure.restrict_apply_self, apply B1, apply B1, apply B1, { --rw le_on_subsets_def at A1, apply restrict_le_restrict_of_le_on_subsets, apply A1, }, apply B1, end /- A jordan decomposition of subtraction. -/ lemma jordan_decomposition_nonneg_sub {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) (S T:set Ξ©) [A1:measure_theory.finite_measure ΞΌ]: is_measurable T β†’ (le_on_subsets ΞΌ Ξ½ S) β†’ (le_on_subsets Ξ½ ΞΌ Sᢜ) β†’ (Ξ½ - ΞΌ) T = Ξ½ (S ∩ T) - ΞΌ (S ∩ T) := begin intros A3 A4 A5, have A2:is_measurable S, { apply le_on_subsets_is_measurable A4, }, have B1:(Ξ½ - ΞΌ) T = (Ξ½ - ΞΌ) (S∩ T) + (Ξ½ - ΞΌ) (Sᢜ ∩ T), { rw measure_theory.measure_partition_apply, apply A2, apply A3, }, have B2:(Ξ½ - ΞΌ) (S∩ T) = Ξ½ (S ∩ T) - ΞΌ (S ∩ T), { apply jordan_decomposition_junior_apply, apply le_on_subsets_subset _ _ _ _ A4, simp, apply is_measurable.inter A2 A3, }, have B3:(Ξ½ - ΞΌ) (Sᢜ ∩ T) = 0, { apply jordan_decomposition_junior_zero, apply le_on_subsets_subset _ _ _ _ A5, simp, apply is_measurable.inter (is_measurable.compl A2) A3, }, rw B1, rw B2, rw B3, rw add_zero, end lemma jordan_decomposition_nonneg_sub' {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) (S:set Ξ©) (T:set Ξ©) [A1:measure_theory.finite_measure ΞΌ]: (le_on_subsets ΞΌ Ξ½ S) β†’ (le_on_subsets Ξ½ ΞΌ Sᢜ) β†’ (is_measurable T) β†’ (Ξ½ - ΞΌ) T = (Ξ½.restrict S) T - (ΞΌ.restrict S) T := begin intros A2 A3 B1, rw jordan_decomposition_nonneg_sub ΞΌ Ξ½ S T B1 A2 A3, rw measure_theory.measure.restrict_apply B1, rw measure_theory.measure.restrict_apply B1, rw set.inter_comm T, end lemma measure_theory.measure.add_compl_inter {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ:measure_theory.measure Ξ©) (S T:set Ξ©):(is_measurable S) β†’ (is_measurable T) β†’ (ΞΌ T = ΞΌ (S ∩ T) + ΞΌ (Sᢜ ∩ T)) := begin intros A1 A2, have A3:T = (S∩ T) βˆͺ (Sᢜ ∩ T), { rw ← set.inter_distrib_right, rw set.union_compl_self, simp, }, have A4:ΞΌ T = ΞΌ ( (S∩ T) βˆͺ (Sᢜ ∩ T)), { rw ← A3, }, rw A4, rw measure_theory.measure_union, rw set.inter_comm, rw set.inter_comm _ T, apply set.disjoint_inter_compl, apply is_measurable.inter A1 A2, apply is_measurable.inter (is_measurable.compl A1) A2, end lemma le_on_subsets_inter {Ξ©:Type*} [measurable_space Ξ©] {ΞΌ Ξ½:measure_theory.measure Ξ©} {T U:set Ξ©}:is_measurable U β†’ le_on_subsets ΞΌ Ξ½ T β†’ ΞΌ (T ∩ U) ≀ Ξ½ (T ∩ U) := begin intros A1 A2, rw le_on_subsets_def at A2, apply A2.right, simp, apply is_measurable.inter A2.left A1, end --This may be gotten by easier methods. lemma measure_theory.measure.sub_le_sub {Ξ©:Type*} [measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) (T:set Ξ©) [A1:measure_theory.finite_measure ΞΌ]: is_measurable T β†’ (Ξ½ T - ΞΌ T) ≀ (Ξ½ - ΞΌ) T := begin intros A2, have B1 := hahn_unsigned_inequality_decomp Ξ½ ΞΌ, cases B1 with U B1, have C1 := le_on_subsets_is_measurable B1.left, rw jordan_decomposition_nonneg_sub ΞΌ Ξ½ Uᢜ, { have C2:Ξ½ T = Ξ½ (U ∩ T) + Ξ½ (Uᢜ ∩ T), { apply measure_theory.measure.add_compl_inter _ _ _ C1 A2, }, rw C2, have C3:ΞΌ T = ΞΌ (U ∩ T) + ΞΌ (Uᢜ ∩ T), { apply measure_theory.measure.add_compl_inter _ _ _ C1 A2, }, rw C3, simp, rw add_comm (ΞΌ (U ∩ T)) (ΞΌ (Uᢜ ∩ T)), rw ← add_assoc, have C4:Ξ½ (Uᢜ ∩ T) ≀ Ξ½ (Uᢜ ∩ T) - ΞΌ (Uᢜ ∩ T) + ΞΌ (Uᢜ ∩ T), { apply ennreal.le_sub_add_self, }, have C5 := add_le_add_right C4 (ΞΌ (U ∩ T)), apply le_trans _ C5, rw add_comm, apply add_le_add_left _ _, apply le_on_subsets_inter A2 B1.left, }, --apply A1,---??? apply A2, apply B1.right, simp, apply B1.left, end lemma measure_theory.measure.is_support_def {Ξ±:Type*} [measurable_space Ξ±] (ΞΌ:measure_theory.measure Ξ±) (S:set Ξ±): ΞΌ.is_support S = (is_measurable S ∧ ΞΌ (Sᢜ) = 0) := rfl def measure_theory.measure.perpendicular {Ξ±:Type*} [measurable_space Ξ±] (ΞΌ Ξ½:measure_theory.measure Ξ±):Prop := (βˆƒ S T:set Ξ±, ΞΌ.is_support S ∧ Ξ½.is_support T ∧ disjoint S T) lemma measure_theory.measure.perpendicular_def {Ξ±:Type*} [measurable_space Ξ±] (ΞΌ Ξ½:measure_theory.measure Ξ±):ΞΌ.perpendicular Ξ½ = (βˆƒ S T:set Ξ±, ΞΌ.is_support S ∧ Ξ½.is_support T ∧ disjoint S T) := rfl lemma measure_theory.measure.perpendicular_def2 {Ξ±:Type*} [measurable_space Ξ±] (ΞΌ Ξ½:measure_theory.measure Ξ±):ΞΌ.perpendicular Ξ½ ↔ (βˆƒ S:set Ξ±, is_measurable S ∧ ΞΌ S = 0 ∧ Ξ½ (Sᢜ) = 0) := begin rw measure_theory.measure.perpendicular_def, split;intros B1, { cases B1 with S B1, cases B1 with T B1, cases B1 with B1 B2, cases B2 with B2 B3, rw measure_theory.measure.is_support_def at B1, rw measure_theory.measure.is_support_def at B2, apply exists.intro T, split, { apply B2.left, }, split, { cases B1 with C1 C2, rw ← ennreal.le_zero_iff, rw ← ennreal.le_zero_iff at C2, apply le_trans _ C2, apply measure_theory.measure_mono, rw set.disjoint_iff_inter_eq_empty at B3, rw set.inter_comm at B3, rw ← set.subset_compl_iff_disjoint at B3, apply B3, }, { apply B2.right, }, }, { cases B1 with S B1, apply exists.intro Sᢜ, apply exists.intro S, split, { rw measure_theory.measure.is_support_def, apply and.intro (is_measurable.compl (B1.left)), simp, apply B1.right.left, }, split, { rw measure_theory.measure.is_support_def, apply and.intro (B1.left) (B1.right.right), }, { rw set.disjoint_iff_inter_eq_empty, rw ← set.subset_compl_iff_disjoint, apply set.subset.refl Sᢜ, }, }, end lemma measure_theory.measure.perpendicular_intro {Ξ±:Type*} [measurable_space Ξ±] (ΞΌ Ξ½:measure_theory.measure Ξ±) {S:set Ξ±}:is_measurable S β†’ ΞΌ S = 0 β†’ Ξ½ (Sᢜ) = 0 β†’ ΞΌ.perpendicular Ξ½ := begin intros A1 A2 A3, rw measure_theory.measure.perpendicular_def2, apply exists.intro S (and.intro A1 (and.intro A2 A3)), end lemma measure_theory.measure.not_perpendicular {Ξ±:Type*} [measurable_space Ξ±] (ΞΌ Ξ½:measure_theory.measure Ξ±) {S:set Ξ±}:(Β¬(ΞΌ.perpendicular Ξ½)) β†’ is_measurable S β†’ ΞΌ S = 0 β†’ 0 < Ξ½ (Sᢜ) := begin intros A1 A2 A3, rw zero_lt_iff_ne_zero, intros A4, apply A1, apply measure_theory.measure.perpendicular_intro ΞΌ Ξ½ A2 A3 A4, end lemma measure_theory.measure.perpendicular_symmetric' {Ξ±:Type*} [measurable_space Ξ±] (ΞΌ Ξ½:measure_theory.measure Ξ±):(ΞΌ.perpendicular Ξ½) β†’ (Ξ½.perpendicular ΞΌ) := begin intro A1, rw measure_theory.measure.perpendicular_def2, rw measure_theory.measure.perpendicular_def2 at A1, cases A1 with S A1, apply exists.intro Sᢜ, apply and.intro (is_measurable.compl A1.left), apply and.intro A1.right.right, simp, apply A1.right.left, end lemma measure_theory.measure.perpendicular_symmetric {Ξ±:Type*} [measurable_space Ξ±] (ΞΌ Ξ½:measure_theory.measure Ξ±):(ΞΌ.perpendicular Ξ½) ↔ (Ξ½.perpendicular ΞΌ) := begin split;apply measure_theory.measure.perpendicular_symmetric', end lemma measure_theory.measure.perpendicular_of_le {Ξ±:Type*} [measurable_space Ξ±] {ΞΌ Ξ½ Ξ½':measure_theory.measure Ξ±}:ΞΌ.perpendicular Ξ½ β†’ Ξ½' ≀ Ξ½ β†’ ΞΌ.perpendicular Ξ½' := begin intros A1 A2, rw measure_theory.measure.perpendicular_def2, rw measure_theory.measure.perpendicular_def2 at A1, cases A1 with S A1, apply exists.intro S, apply and.intro A1.left, apply and.intro (A1.right.left), rw ← ennreal.le_zero_iff, rw ← A1.right.right, apply A2, apply is_measurable.compl (A1.left), end lemma measure_theory.measure.sub_le {Ξ±:Type*} [measurable_space Ξ±] {ΞΌ Ξ½:measure_theory.measure Ξ±}:ΞΌ - Ξ½ ≀ ΞΌ := begin rw measure_theory.measure.sub_def, apply @Inf_le (measure_theory.measure Ξ±) _ _, simp, apply measure_theory.measure.le_add, end lemma measure_theory.measure.perpendicular_of_sub {Ξ±:Type*} [measurable_space Ξ±] {ΞΌ Ξ½ Ξ½':measure_theory.measure Ξ±}:ΞΌ.perpendicular Ξ½ β†’ (ΞΌ.perpendicular (Ξ½ - Ξ½')) := begin intros A1, apply measure_theory.measure.perpendicular_of_le A1, apply measure_theory.measure.sub_le, end lemma measure_theory.measure.smul_finite {Ξ±:Type*} [measurable_space Ξ±] {ΞΌ:measure_theory.measure Ξ±} {Ξ΅:ennreal} [measure_theory.finite_measure ΞΌ]: Ξ΅ β‰  ⊀ β†’ (measure_theory.finite_measure (Ξ΅β€’ ΞΌ)) := begin intros A1, apply measure_theory.finite_measure_of_lt_top, rw ennreal_smul_measure_apply, apply ennreal.mul_lt_top, rw lt_top_iff_ne_top, apply A1, apply measure_theory.measure_lt_top, --apply A2, simp, end lemma set.compl_Union_eq_Inter_compl {Ξ± Ξ²:Type*} {f:Ξ± β†’ set Ξ²}:(⋃ n, f n)ᢜ = (β‹‚ n, (f n)ᢜ) := begin ext b, split;intros A1;simp;simp at A1;apply A1, end lemma le_on_subsets_of_zero {Ξ±:Type*} [measurable_space Ξ±] {ΞΌ:measure_theory.measure Ξ±} (Ξ½:measure_theory.measure Ξ±) {S:set Ξ±}:is_measurable S β†’ ΞΌ S = 0 β†’ le_on_subsets ΞΌ Ξ½ S := begin intros A1 A2, rw le_on_subsets_def, apply and.intro A1, intros X B1 B2, have B3:ΞΌ X ≀ ΞΌ S, { apply measure_theory.measure_mono, apply B1, }, apply le_trans B3, rw A2, simp, end lemma measure_theory.measure.sub_zero_eq_self {Ξ±:Type*} [measurable_space Ξ±] {ΞΌ Ξ½:measure_theory.measure Ξ±} {S:set Ξ±} [A2:measure_theory.finite_measure ΞΌ]:is_measurable S β†’ ΞΌ S = 0 β†’ (Ξ½ - ΞΌ) S = Ξ½ S := begin intros A1 A4, have B1 := le_on_subsets_of_zero Ξ½ A1 A4, rw jordan_decomposition_junior_apply, rw A4, simp, --apply A2, apply B1, end lemma measure_theory.measure.perpendicular_of {Ξ±:Type*} [M:measurable_space Ξ±] {ΞΌ Ξ½:measure_theory.measure Ξ±} [A2:measure_theory.finite_measure ΞΌ] [A3:measure_theory.finite_measure Ξ½]: (βˆ€ Ξ΅:ennreal, Ξ΅ > 0 β†’ ΞΌ.perpendicular (Ξ½ - (Ξ΅ β€’ ΞΌ)) ) β†’ ΞΌ.perpendicular Ξ½ := begin intros A1, have B1:βˆ€ n:β„•,(βˆƒ S:set Ξ±, is_measurable S ∧ ΞΌ S = 0 ∧ (Ξ½ - ((1/((n:ennreal) + 1))β€’ ΞΌ)) (Sᢜ) = 0), { intros n, have B1A:(1/((n:ennreal) + 1))>0, { apply ennreal.unit_frac_pos, }, have B1B := A1 _ B1A, rw measure_theory.measure.perpendicular_def2 at B1B, apply B1B, }, have B2 := classical.some_func B1, cases B2 with f B2, let T := ⋃ n, f n, begin have C1:T = ⋃ n, f n := rfl, have C2:Tᢜ = β‹‚ n, (f n)ᢜ, { rw C1, rw set.compl_Union_eq_Inter_compl, }, have C3:is_measurable T, { rw C1, apply is_measurable.Union, intro n, apply (B2 n).left, }, have C4:is_measurable Tᢜ, { apply is_measurable.compl C3, }, have I1:βˆ€ (n:β„•), Tᢜ βŠ† (f n)ᢜ, { intro n, rw C2, apply @set.Inter_subset Ξ± β„• (Ξ» n, (f n)ᢜ), }, have I2:βˆ€ (n:β„•), ΞΌ Tᢜ ≀ ΞΌ (f n)ᢜ, { intro n, apply @measure_theory.measure_mono Ξ± M ΞΌ _ _ (I1 n), }, apply @measure_theory.measure.perpendicular_intro Ξ± _ ΞΌ Ξ½ T, { apply is_measurable.Union, intro n, apply (B2 n).left, }, { rw C1, rw ← ennreal.le_zero_iff, have D1:=@measure_theory.measure.Union_nat Ξ± _ ΞΌ f, apply le_trans D1, rw ennreal.le_zero_iff, have E1:(Ξ» n, ΞΌ (f n)) = (Ξ» (n:β„•), (0:ennreal)), { apply funext, intro n, apply (B2 n).right.left, }, rw E1, simp, }, { --rw C2, have H1:Ξ½ (Tᢜ)/(ΞΌ (Tᢜ)) = 0, { apply ennreal.zero_of_le_all_unit_frac, intro n, apply ennreal.div_le_of_le_mul, have H1X:measure_theory.finite_measure ((1 / ((n:ennreal) + 1)) β€’ ΞΌ), { apply measure_theory.measure.smul_finite, { apply ennreal.unit_frac_ne_top, }, }, --have H1B := H1A n, have H1B:(Ξ½) Tᢜ - ((1 / ((n:ennreal) + 1)) β€’ ΞΌ) Tᢜ ≀ (Ξ½ - (1 / ((n:ennreal) + 1)) β€’ ΞΌ) Tᢜ, { apply @measure_theory.measure.sub_le_sub Ξ± M ((1 / ((n:ennreal) + 1)) β€’ ΞΌ) Ξ½ Tᢜ H1X C4, }, have H1C:(Ξ½) Tᢜ - ((1 / ((n:ennreal) + 1)) β€’ ΞΌ) Tᢜ = 0, --have H1B:(Ξ½ - (1 / ((n:ennreal) + 1)) β€’ ΞΌ) Tᢜ = 0, { rw ← ennreal.le_zero_iff, apply le_trans H1B, rw ← (B2 n).right.right, apply measure_theory.measure_mono (I1 n), }, rw ennreal_smul_measure_apply at H1C, apply ennreal.le_of_sub_eq_zero, apply H1C, apply C4, }, rw ennreal.div_eq_zero_iff at H1, cases H1 with H1 H1, { apply H1, }, { exfalso, apply measure_theory.measure_ne_top ΞΌ Tᢜ H1, }, }, end end lemma measure_theory.measure.exists_of_not_perpendicular {Ξ±:Type*} [measurable_space Ξ±] (ΞΌ:measure_theory.measure Ξ±) {Ξ½:measure_theory.measure Ξ±} [A1:measure_theory.finite_measure ΞΌ] [A2:measure_theory.finite_measure Ξ½]: (Β¬ (ΞΌ.perpendicular Ξ½)) β†’ (βˆƒ Ξ΅:ennreal, Ξ΅ > 0 ∧ ¬μ.perpendicular (Ξ½ - (Ξ΅ β€’ ΞΌ)) ) := begin intros A3, apply classical.exists_of_not_forall_not, intros B1, apply A3, apply measure_theory.measure.perpendicular_of, intros Ξ΅ C1, have C2 := B1 Ξ΅, simp at C2, apply C2, apply C1, end lemma measure_theory.measure.sub_add_cancel_of_le {Ξ±:Type*} [measurable_space Ξ±] {ΞΌ Ξ½:measure_theory.measure Ξ±} [measure_theory.finite_measure ΞΌ]: ΞΌ ≀ Ξ½ β†’ Ξ½ - ΞΌ + ΞΌ = Ξ½ := begin intros A1, apply measure_theory.measure.ext, intros S B1, rw measure_theory.measure.add_apply, rw jordan_decomposition_junior_apply, rw ennreal.sub_add_cancel_of_le, apply A1, apply B1, --apply A2, rw le_on_subsets_def, apply and.intro B1, intros X' C1 C2, apply A1, apply C2, end /- This is taken from a step in Tao's proof of the Lebesgue-Radon-Nikodym Theorem. By the Hahn Decomposition Theorem, we can find a set where ΞΌ ≀ Ξ½ and ΞΌ S > 0. -/ lemma measure_theory.measure.perpendicular_sub_elim {Ξ±:Type*} [measurable_space Ξ±] (ΞΌ:measure_theory.measure Ξ±) {Ξ½:measure_theory.measure Ξ±} [A2:measure_theory.finite_measure Ξ½]: Β¬(ΞΌ.perpendicular (Ξ½ - ΞΌ)) β†’ βˆƒ (S:set Ξ±), is_measurable S ∧ le_on_subsets ΞΌ Ξ½ S ∧ 0 < ΞΌ S := begin intros A3, have B1:=hahn_unsigned_inequality_decomp ΞΌ Ξ½, cases B1 with X B1, have B2 := jordan_decomposition_junior_zero Ξ½ ΞΌ Xᢜ B1.right, have B3 := le_on_subsets_is_measurable B1.right, have B4:Β¬((Ξ½ - ΞΌ).perpendicular ΞΌ), { intro B4A, apply A3, apply measure_theory.measure.perpendicular_symmetric', apply B4A, }, have B5 := measure_theory.measure.not_perpendicular (Ξ½ - ΞΌ) ΞΌ B4 B3 B2, simp at B5, apply exists.intro X, apply and.intro (le_on_subsets_is_measurable B1.left) (and.intro B1.left B5), end lemma ennreal_smul_smul_measure_assoc {Ξ©:Type*} [N:measurable_space Ξ©] (ΞΌ:measure_theory.measure Ξ©) {a b:ennreal}:(a * b) β€’ ΞΌ = a β€’ (b β€’ ΞΌ) := begin apply measure_theory.measure.ext, intros S B1, repeat {rw ennreal_smul_measure_apply _ _ S B1}, rw mul_assoc, end lemma measure_theory.measure.perpendicular_zero {Ξ©:Type*} [N:measurable_space Ξ©] (ΞΌ:measure_theory.measure Ξ©): (ΞΌ.perpendicular 0) := begin rw measure_theory.measure.perpendicular_def2, apply exists.intro (βˆ…:set Ξ©), split, apply is_measurable.empty, split, apply measure_theory.measure_empty, simp, end lemma measure_theory.measure.perpendicular_smul' {Ξ©:Type*} [N:measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) {k:ennreal}: (ΞΌ.perpendicular Ξ½) β†’ (k β€’ ΞΌ).perpendicular Ξ½ := begin intros A2, rw measure_theory.measure.perpendicular_def2, rw measure_theory.measure.perpendicular_def2 at A2, cases A2 with S A2, apply exists.intro S, apply and.intro (A2.left), apply and.intro _ A2.right.right, rw ennreal_smul_measure_apply, rw A2.right.left, simp, apply A2.left, end lemma measure_theory.measure.perpendicular_smul {Ξ©:Type*} [N:measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) {k:ennreal}: 0 < k β†’ (k β€’ ΞΌ).perpendicular Ξ½ β†’ ΞΌ.perpendicular Ξ½ := begin intros A1 A2, rw measure_theory.measure.perpendicular_def2, rw measure_theory.measure.perpendicular_def2 at A2, cases A2 with S A2, apply exists.intro S, apply and.intro A2.left, apply and.intro _ A2.right.right, have B1 := A2.right.left, rw ennreal_smul_measure_apply _ _ _ A2.left at B1, simp at B1, cases B1 with B1 B1, { exfalso, rw zero_lt_iff_ne_zero at A1, apply A1, apply B1, }, { apply B1, }, end lemma measure_theory.measure.restrict_integral_eq_integral_indicator' {Ξ©:Type*} [M:measurable_space Ξ©] (ΞΌ:measure_theory.measure Ξ©) {S:set Ξ©} {f:Ξ© β†’ ennreal}: (is_measurable S) β†’ ∫⁻ (a : Ξ©), f a βˆ‚ (ΞΌ.restrict S) = ∫⁻ (a : Ξ©), (S.indicator f) a βˆ‚ ΞΌ := begin intros A1, rw measure_theory.lintegral_indicator, apply A1, end lemma with_density_indicator_eq_restrict {Ξ©:Type*} [M:measurable_space Ξ©] (ΞΌ:measure_theory.measure Ξ©) {S:set Ξ©} {f:Ξ© β†’ ennreal}: (is_measurable S) β†’ ΞΌ.with_density (set.indicator S f) = (ΞΌ.restrict S).with_density f := begin intros A1, apply measure_theory.measure.ext, intros T B1, rw measure_theory.with_density_apply2', rw measure_theory.with_density_apply2', rw ← measure_theory.lintegral_indicator, rw set.indicator_indicator, rw set.indicator_indicator, rw set.inter_comm, repeat {assumption}, end lemma scalar_as_with_density {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) {k:ennreal}: (kβ€’ΞΌ) = ΞΌ.with_density (Ξ» Ο‰:Ξ©, k) := begin apply measure_theory.measure.ext, intros S B1, rw with_density_const_apply, rw ennreal_smul_measure_apply, apply B1, apply B1, end lemma with_density_indicator_eq_restrict_smul {Ξ©:Type*} [M:measurable_space Ξ©] (ΞΌ:measure_theory.measure Ξ©) {S:set Ξ©} {k:ennreal}:(is_measurable S) β†’ ΞΌ.with_density (set.indicator S (Ξ» Ο‰:Ξ©, k)) = k β€’ ΞΌ.restrict S := begin intro A1, rw with_density_indicator_eq_restrict, rw scalar_as_with_density, apply A1, end lemma smul_restrict_comm {Ξ©:Type*} [M:measurable_space Ξ©] (ΞΌ:measure_theory.measure Ξ©) {S:set Ξ©} {k:ennreal}:(is_measurable S) β†’ (k β€’ ΞΌ).restrict S = k β€’ ΞΌ.restrict S := begin intros A1, apply measure_theory.measure.ext, intros T B1, rw ennreal_smul_measure_apply _ _ _ B1, rw measure_theory.measure.restrict_apply B1, rw measure_theory.measure.restrict_apply B1, rw ennreal_smul_measure_apply _ _ _ (is_measurable.inter B1 A1), end /- In the full version of Lebesgue-Radon-Nikodym theorem, ΞΌ is an unsigned Οƒ-finite measure, and Ξ½ is a signed Οƒ-finite measure. The first stage of the proof focuses on finite, unsigned measures (see lebesgue_radon_nikodym_unsigned_finite). In that proof, there is a need to prove that if two measures are not perpendicular, then there exists some nontrivial f where ΞΌ.with_density f set.univ > 0 and ΞΌ.with_density f ≀ Ξ½. In Tao's An Epsilon of Room, this is to show that taking the f which maximizes ΞΌ.with_density f set.univ subject to ΞΌ.with_density f ≀ Ξ½, when subtracted from Ξ½, leaves a measure perpendicular to ΞΌ. -/ lemma lebesgue_radon_nikodym_junior {Ξ©:Type*} [N:measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) [A1:measure_theory.finite_measure ΞΌ] [A2:measure_theory.finite_measure Ξ½]: Β¬(ΞΌ.perpendicular Ξ½) β†’ βˆƒ f:Ξ© β†’ ennreal, measurable f ∧ ΞΌ.with_density f ≀ Ξ½ ∧ 0 < ΞΌ.with_density f (set.univ) := begin intros A3, have B1 := measure_theory.measure.exists_of_not_perpendicular ΞΌ A3, cases B1 with Ξ΅ B1, have B2:Β¬((Ξ΅ β€’ ΞΌ).perpendicular (Ξ½ - Ξ΅ β€’ ΞΌ)), { intro B2A, apply B1.right, apply measure_theory.measure.perpendicular_smul _ _ B1.left, apply B2A, }, have B3 := measure_theory.measure.perpendicular_sub_elim _ B2, cases B3 with S B3, let f := (set.indicator S (Ξ» Ο‰:Ξ©, Ξ΅)), begin have C1:f = (set.indicator S (Ξ» Ο‰:Ξ©, Ξ΅)) := rfl, apply exists.intro f, split, { apply measurable.indicator, apply measurable_const, apply B3.left, }, split, { rw C1, rw with_density_indicator_eq_restrict_smul _ B3.left, rw ← smul_restrict_comm _ B3.left, apply le_trans _ (@measure_theory.measure.restrict_le_self _ _ _ S), apply restrict_le_restrict_of_le_on_subsets, apply B3.right.left, }, { have C2:0 < ΞΌ S, { have C2A := B3.right.right, rw ennreal_smul_measure_apply _ _ _ B3.left at C2A, simp at C2A, apply C2A.right, }, rw C1, rw with_density_indicator_eq_restrict_smul _ B3.left, rw ennreal_smul_measure_apply _ _ _ (is_measurable.univ), rw measure_theory.measure.restrict_apply is_measurable.univ, simp, apply and.intro (B1.left) C2, }, end end lemma set.indicator_sup {Ξ©:Type*} {x y:Ξ© β†’ ennreal} {S:set Ξ©}: (βˆ€ Ο‰βˆˆ S, x Ο‰ ≀ y Ο‰) β†’ set.indicator S (x βŠ” y) = set.indicator S y := begin intros A1, apply funext, intro Ο‰, cases (classical.em (Ο‰ ∈ S)) with B1 B1, { repeat {rw set.indicator_of_mem B1}, simp, rw max_eq_right, apply A1, apply B1, }, { repeat {rw set.indicator_of_not_mem B1}, }, end lemma sup_indicator_partition {Ξ±:Type*} {x y:Ξ± β†’ ennreal}: (x βŠ” y) = set.indicator {Ο‰|y Ο‰ < x Ο‰} x + set.indicator {Ο‰|x Ο‰ ≀ y Ο‰} y := begin apply funext, intro a, simp, cases (classical.em (x a ≀ y a)) with B1 B1, { rw max_eq_right B1, rw set.indicator_of_not_mem, rw set.indicator_of_mem, simp, apply B1, simp, apply B1, }, { have B2:=lt_of_not_ge B1, have B3:=le_of_lt B2, rw max_eq_left B3, rw set.indicator_of_mem, rw set.indicator_of_not_mem, simp, apply B1, apply B2, }, end lemma with_density_le_sup_apply {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) {x y:Ξ© β†’ ennreal} {S:set Ξ©}: (is_measurable S) β†’ (βˆ€ Ο‰βˆˆ S, x Ο‰ ≀ y Ο‰) β†’ ΞΌ.with_density (x βŠ” y) S = ΞΌ.with_density y S := begin intros A3 A4, rw measure_theory.with_density_apply2', rw measure_theory.with_density_apply2', rw set.indicator_sup A4, repeat {apply A3}, end lemma le_on_subsets_with_density_of_le {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) {x y:Ξ© β†’ ennreal} {S:set Ξ©}: (is_measurable S) β†’ (βˆ€ Ο‰βˆˆ S, x Ο‰ ≀ y Ο‰) β†’ le_on_subsets (ΞΌ.with_density x) (ΞΌ.with_density y) S := begin intros A3 A4, rw le_on_subsets_def, apply and.intro A3, intros X' B1 B2, apply with_density_le_with_density B2, intros Ο‰ C1, apply A4 Ο‰, apply B1, apply C1, end lemma measure_theory.measure.sup_def {Ξ©:Type*} [measurable_space Ξ©] {ΞΌ Ξ½:measure_theory.measure Ξ©}:ΞΌ βŠ” Ξ½ = Inf {d|ΞΌ ≀ d ∧ Ξ½ ≀ d} := rfl lemma measure_theory.measure.le_sup {Ξ©:Type*} [measurable_space Ξ©] {ΞΌ Ξ½ d:measure_theory.measure Ξ©}:(βˆ€ c, ΞΌ ≀ c β†’ Ξ½ ≀ c β†’ d ≀ c) β†’ d ≀ ΞΌ βŠ” Ξ½ := begin rw measure_theory.measure.sup_def, intro A1, apply @le_Inf (measure_theory.measure Ξ©) _, intros c B1, apply A1;simp at B1, apply B1.left, apply B1.right, end lemma measure_theory.measure.le_restrict_add_restrict {Ξ©:Type*} [measurable_space Ξ©] {ΞΌ Ξ½:measure_theory.measure Ξ©} {S:set Ξ©}:le_on_subsets ΞΌ Ξ½ S β†’ le_on_subsets Ξ½ ΞΌ Sᢜ β†’ ΞΌ ≀ ΞΌ.restrict Sᢜ + Ξ½.restrict S := begin intros A1 A2, have B1:is_measurable S := le_on_subsets_is_measurable A1, rw measure_theory.measure.le_iff, intros T C1, rw measure_theory.measure_partition_apply ΞΌ S T B1 C1, rw measure_theory.measure.add_apply, rw add_comm, apply @add_le_add ennreal _, { rw measure_theory.measure.restrict_apply C1, rw set.inter_comm, apply le_refl _, }, { rw measure_theory.measure.restrict_apply C1, rw set.inter_comm, rw le_on_subsets_def at A1, apply A1.right, apply set.inter_subset_right, apply is_measurable.inter C1 B1, }, end lemma measure_theory.measure.sup_eq {Ξ©:Type*} [measurable_space Ξ©] {ΞΌ Ξ½:measure_theory.measure Ξ©} (S:set Ξ©):le_on_subsets ΞΌ Ξ½ S β†’ le_on_subsets Ξ½ ΞΌ Sᢜ β†’ (ΞΌ βŠ” Ξ½) = ΞΌ.restrict Sᢜ + Ξ½.restrict S := begin intros A1 A2, have D1:is_measurable S := le_on_subsets_is_measurable A1, apply le_antisymm, { apply @sup_le (measure_theory.measure Ξ©) _, { apply measure_theory.measure.le_restrict_add_restrict A1 A2, }, { rw add_comm, have B1:Ξ½.restrict Sᢜᢜ = Ξ½.restrict S, { simp, }, rw ← B1, apply measure_theory.measure.le_restrict_add_restrict, apply A2, simp, apply A1, }, }, { apply measure_theory.measure.le_sup, intros c C1 C2, rw measure_theory.measure.le_iff, intros T C3, simp, rw measure_theory.measure.restrict_apply C3, rw measure_theory.measure.restrict_apply C3, rw measure_theory.measure_partition_apply c S, rw add_comm, apply @add_le_add ennreal _, rw set.inter_comm, apply C2, apply is_measurable.inter D1 C3, rw set.inter_comm, apply C1, apply is_measurable.inter (is_measurable.compl D1) C3, apply D1, apply C3, }, end lemma set.indicator_add_comm {Ξ± Ξ²:Type*} [ordered_add_comm_monoid Ξ²] {f g:Ξ± β†’ Ξ²} {S:set Ξ±}: S.indicator (f + g) = S.indicator f + S.indicator g := begin apply funext, intros a, simp, cases (classical.em (a∈ S)) with B1 B1, { repeat {rw set.indicator_of_mem B1}, simp, }, { repeat {rw set.indicator_of_not_mem B1}, simp, }, end lemma measure_theory.measure.with_density_restrict_comm {Ξ©:Type*} [M:measurable_space Ξ©] (ΞΌ:measure_theory.measure Ξ©) {x:Ξ© β†’ ennreal} {S:set Ξ©}:is_measurable S β†’ (ΞΌ.with_density x).restrict S = (ΞΌ.restrict S).with_density x := begin intros A1, apply measure_theory.measure.ext, intros T B1, rw measure_theory.with_density_apply2', rw measure_theory.lintegral_indicator, rw measure_theory.measure.restrict_apply, rw measure_theory.measure.restrict_restrict, --rw measure_theory.measure.restrict_apply, --rw measure_theory.measure.restrict_apply, rw ← measure_theory.lintegral_indicator, --rw measure_theory.measure.restrict_integral_eq_integral_indicator', --rw measure_theory.measure.restrict_apply, -- rw set.indicator_indicator, rw set.inter_comm, rw measure_theory.with_density_apply2', repeat {assumption <|> apply is_measurable.inter}, end lemma measure_theory.measure.with_density_restrict_comm' {Ξ©:Type*} [M:measurable_space Ξ©] (ΞΌ:measure_theory.measure Ξ©) {x:Ξ© β†’ ennreal} {S:set Ξ©}:is_measurable S β†’ (ΞΌ.with_density x).restrict S = (ΞΌ.restrict S).with_density x := begin intros A1, apply measure_theory.measure.ext, intros T B1, rw measure_theory.with_density_apply2', /-rw measure_theory.lintegral_indicator, rw measure_theory.measure.restrict_apply, rw measure_theory.measure.restrict_apply,-/ rw measure_theory.measure.restrict_integral_eq_integral_indicator', rw measure_theory.measure.restrict_apply, rw set.indicator_indicator, rw set.inter_comm, rw measure_theory.with_density_apply2', repeat {assumption <|> apply is_measurable.inter}, end lemma measure_theory.measure.with_density_add {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) {x y:Ξ© β†’ ennreal}:measurable x β†’ measurable y β†’ ΞΌ.with_density (x + y) = ΞΌ.with_density x + ΞΌ.with_density y := begin intros A1 A2, apply measure_theory.measure.ext, intros S B1, rw measure_theory.measure.add_apply, rw measure_theory.with_density_apply2' , rw measure_theory.with_density_apply2' , rw measure_theory.with_density_apply2' , rw set.indicator_add_comm, simp, rw @measure_theory.lintegral_add Ξ© M ΞΌ (S.indicator x) (S.indicator y), repeat{assumption <|> apply measurable.indicator}, end lemma with_density_sup' {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) {x y:Ξ© β†’ ennreal}:measurable x β†’ measurable y β†’ ΞΌ.with_density (x βŠ” y) = (ΞΌ.with_density x).restrict {Ο‰:Ξ©|y Ο‰ < x Ο‰} + (ΞΌ.with_density y).restrict {Ο‰:Ξ©|x Ο‰ ≀ y Ο‰} := begin intros A1 A2, rw sup_indicator_partition, rw measure_theory.measure.with_density_add, rw with_density_indicator_eq_restrict, rw with_density_indicator_eq_restrict, rw measure_theory.measure.with_density_restrict_comm, rw measure_theory.measure.with_density_restrict_comm, repeat {assumption <|> apply is_measurable_le <|> apply is_measurable_lt <|> apply measurable.indicator}, end lemma with_density_sup {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) {x y:Ξ© β†’ ennreal}:measurable x β†’ measurable y β†’ ΞΌ.with_density (x βŠ” y) = measure_theory.measure.with_density ΞΌ x βŠ” measure_theory.measure.with_density ΞΌ y := begin intros A1 A2, rw with_density_sup' ΞΌ A1 A2, rw measure_theory.measure.sup_eq {Ο‰:Ξ©|x Ο‰ ≀ y Ο‰}, rw lt_eq_le_compl, { apply le_on_subsets_with_density_of_le, apply is_measurable_le A1 A2, simp, }, { apply le_on_subsets_with_density_of_le, apply is_measurable.compl (is_measurable_le A1 A2), simp, intros Ο‰ B3, apply le_of_lt B3, }, end def measure_theory.finite_measure_sub {Ξ©:Type*} [M:measurable_space Ξ©] (ΞΌ Ξ½:measure_theory.measure Ξ©) [measure_theory.finite_measure Ξ½]: measure_theory.finite_measure (Ξ½ - ΞΌ) := begin apply measure_theory.finite_measure_of_le (Ξ½ - ΞΌ) Ξ½, apply measure_theory.measure.sub_le, end lemma lebesgue_radon_nikodym_finite_unsigned {Ξ©:Type*} {N:measurable_space Ξ©} (ΞΌ Ξ½:measure_theory.measure Ξ©) [A1:measure_theory.finite_measure ΞΌ] [A2:measure_theory.finite_measure Ξ½]: βˆƒ f:Ξ© β†’ ennreal, βˆƒ ΞΌβ‚‚:measure_theory.measure Ξ©, measurable f ∧ Ξ½ = ΞΌ.with_density f + ΞΌβ‚‚ ∧ ΞΌ.perpendicular ΞΌβ‚‚ := begin let S := {f:Ξ© β†’ ennreal|measurable f ∧ (ΞΌ.with_density f ≀ Ξ½)}, let M := Sup ((Ξ» f, ΞΌ.with_density f set.univ) '' S), begin have A4:S = {f:Ξ© β†’ ennreal|measurable f ∧ (ΞΌ.with_density f ≀ Ξ½)} := rfl, have B2:M = Sup ((Ξ» f, ΞΌ.with_density f set.univ) '' S) := rfl, have B3:M < ⊀, { -- Because ΞΌ is finite. -- Or, because Ξ½ is finite, and ΞΌ... is less than Ξ½. have B3A:M ≀ Ξ½ set.univ, { rw B2, apply @Sup_le ennreal _, intros b B3A1, simp at B3A1, cases B3A1 with f B3A1, cases B3A1 with B3A1 B3A2, subst b, apply B3A1.right, apply is_measurable.univ, }, apply lt_of_le_of_lt B3A, apply measure_theory.measure_lt_top, }, have B1:βˆƒ h:β„• β†’ Ξ© β†’ ennreal, (βˆ€ n, h n ∈ S) ∧ (monotone h) ∧ (ΞΌ.with_density (supr h) set.univ) = M, { -- have B1A:= apply @Sup_apply_eq_supr_apply_of_closed' (Ξ© β†’ ennreal) _ S (Ξ» f:Ξ© β†’ ennreal, ΞΌ.with_density f set.univ) _ _, --cases B1A with h B1A, { -- ⊒ S.nonempty apply @set.nonempty_of_mem (Ξ© β†’ ennreal) S 0, rw A4, simp, split, apply @measurable_const ennreal Ξ© _ N 0, rw with_density.zero, apply measure_theory.measure.zero_le, }, { -- ⊒ βˆ€ a ∈ S, βˆ€ b ∈ S, a βŠ” b ∈ S intros a B1B1 b B1B2, cases B1B1 with B1B1 B1B3, cases B1B2 with B1B2 B1B4, simp, split, { apply measurable_sup B1B1 B1B2, }, { rw (with_density_sup ΞΌ B1B1 B1B2), simp, apply and.intro B1B3 B1B4, }, }, { -- ⊒ βˆ€ a ∈ S,βˆ€ b ∈ S,a ≀ b β†’ -- (ΞΌ.with_density a set.univ ≀ ΞΌ.with_density b set.univ), intros a B1C b B1D B1E, simp, rw A4 at B1C, rw A4 at B1D, apply with_density_le_with_density, simp, intros Ο‰ B1F, apply B1E, }, { -- ⊒ βˆ€ (f : β„• β†’ Ξ© β†’ ennreal), -- set.range f βŠ† S β†’ -- monotone f β†’ -- supr ((Ξ» (f : Ξ© β†’ ennreal), ⇑(ΞΌ.with_density f) set.univ) ∘ f) = -- (Ξ» (f : Ξ© β†’ ennreal), ⇑(ΞΌ.with_density f) set.univ) (supr f) intros f B1G B1H, simp, rw supr_with_density_apply_eq_with_density_supr_apply _ _ B1H, simp, intros n, rw A4 at B1G, unfold set.range at B1G, rw set.subset_def at B1G, simp at B1G, apply (B1G n).left, }, }, cases B1 with h B1, have B4:βˆ€ n, measurable (h n), { intros n, have B4A := (B1.left n), rw A4 at B4A, apply B4A.left, }, let g := supr h, begin apply exists.intro g, have A5:g = supr h := rfl, have A6:ΞΌ.with_density g set.univ = M, { rw A5, rw ← B1.right.right, }, have A7:ΞΌ.with_density g ≀ Ξ½, { rw measure_theory.measure.le_iff, intros S A7A, rw ← supr_with_density_apply_eq_with_density_supr_apply, apply @supr_le ennreal _ _, intros i, have A7B := (B1.left i), simp at A7B, apply A7B.right, apply A7A, apply A7A, apply B4, apply B1.right.left, }, apply exists.intro (Ξ½ - ΞΌ.with_density g), have C4:Ξ½ = ΞΌ.with_density g + (Ξ½ - ΞΌ.with_density g), { rw add_comm, have C4A:measure_theory.finite_measure (ΞΌ.with_density g), { apply measure_theory.finite_measure_of_lt_top, rw A6, apply B3, }, rw @measure_theory.measure.sub_add_cancel_of_le Ξ© N (ΞΌ.with_density g) Ξ½ C4A, apply A7, }, have C5:measurable g, { rw A5, apply @measurable_supr_of_measurable, apply B4, }, apply and.intro C5, apply and.intro C4, { apply by_contradiction, intros C1, have C2X:=measure_theory.finite_measure_sub (ΞΌ.with_density g) Ξ½, have C2 := @lebesgue_radon_nikodym_junior Ξ© N ΞΌ (Ξ½ - ΞΌ.with_density g) A1 C2X C1, cases C2 with f C2, have D1:M < ΞΌ.with_density (f + g) set.univ, { rw measure_theory.measure.with_density_add, rw measure_theory.measure.add_apply, rw A6, rw add_comm, apply ennreal.lt_add_self, apply B3, apply C2.right.right, apply C2.left, apply C5, }, apply not_le_of_lt D1, rw B2, apply @le_Sup ennreal _, simp, apply exists.intro (f + g), split, split, { apply measurable.add, apply C2.left, apply C5, }, { rw C4, rw measure_theory.measure.with_density_add, rw add_comm, apply measure_theory.measure.add_le_add, apply le_refl _, apply C2.right.left, apply C2.left, apply C5, --apply @add_le_add (measure_theory.measure Ξ©) _, }, refl, }, end end end --Note that the Radon-Nikodym derivative is not necessarily unique. def is_radon_nikodym_deriv {Ξ©:Type*} {M:measurable_space Ξ©} (Ξ½ ΞΌ:measure_theory.measure Ξ©) (f:Ξ© β†’ ennreal):Prop := (measurable f) ∧ ΞΌ.with_density f = Ξ½ --TODO:working here --∫⁻ (a : Ξ©), lemma is_radon_nikodym_deriv_elim' {Ξ©:Type*} {M:measurable_space Ξ©} (Ξ½ ΞΌ:measure_theory.measure Ξ©) (f:Ξ© β†’ ennreal) (S:set Ξ©): (is_radon_nikodym_deriv Ξ½ ΞΌ f) β†’ (is_measurable S) β†’ (∫⁻ (a : Ξ©), (set.indicator S f) a βˆ‚ ΞΌ = Ξ½ S) := begin intros A1 A2, unfold is_radon_nikodym_deriv at A1, cases A1 with A3 A1, subst Ξ½, rw measure_theory.with_density_apply2', apply A2, end lemma measurable_of_is_radon_nikodym_deriv {Ξ©:Type*} {M:measurable_space Ξ©} (Ξ½ ΞΌ:measure_theory.measure Ξ©) (f:Ξ© β†’ ennreal) (S:set Ξ©): (is_radon_nikodym_deriv Ξ½ ΞΌ f) β†’ (measurable f) := begin intro A1, cases A1 with A1 A2, apply A1, end lemma is_radon_nikodym_deriv_intro {Ξ©:Type*} {M:measurable_space Ξ©} (Ξ½ ΞΌ:measure_theory.measure Ξ©) (f:Ξ© β†’ ennreal): (measurable f) β†’ (βˆ€ S:set Ξ©, (is_measurable S) β†’ (∫⁻ (a : Ξ©), (set.indicator S f) a βˆ‚ ΞΌ = Ξ½ S)) β†’ (is_radon_nikodym_deriv Ξ½ ΞΌ f) := begin intros A1 A2, unfold is_radon_nikodym_deriv, split, apply A1, apply measure_theory.measure.ext, intros S A3, rw measure_theory.with_density_apply2', apply A2, repeat {apply A3}, end /- As we move on to the later theorems, we need to be able to say that two functions are "almost everywhere equal". Specifically, given two radon-nikodym derivatives of a measure, they are equal almost everywhere according to the base measure. -/ -- There used to be a definition close to this, measure_theory,measure.a_e, and -- This used to be βˆ€αΆ  a in ΞΌ.a_e, P a -- For now, we use a local definition. def measure_theory.measure.all_ae {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) (P:Ξ© β†’ Prop):Prop := (ΞΌ ({Ο‰:Ξ©|(P Ο‰)}ᢜ)) = 0 lemma measure_theory.measure.all_ae_def2 {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) (P:Ξ© β†’ Prop): ΞΌ.all_ae P = ( (ΞΌ ({Ο‰:Ξ©|(P Ο‰)}ᢜ)) = 0) := begin unfold measure_theory.measure.all_ae, end lemma measure_theory.measure.all_ae_and {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) (P Q:Ξ© β†’ Prop): (ΞΌ.all_ae P) β†’ (ΞΌ.all_ae Q) β†’ (ΞΌ.all_ae (Ξ» a, P a ∧ Q a)) := begin intros A1 A2, rw measure_theory.measure.all_ae_def2, have A3:{Ο‰:Ξ©| P Ο‰ ∧ Q Ο‰}ᢜ = ({Ο‰:Ξ©|P Ο‰}ᢜ) βˆͺ ({Ο‰:Ξ©|Q Ο‰}ᢜ), { ext Ο‰, split;intros A3A;simp;simp at A3A, { have A3B:P Ο‰ ∨ Β¬(P Ο‰) := classical.em (P Ο‰), cases A3B, { apply or.inr (A3A A3B), }, { apply or.inl A3B, }, }, { cases A3A, { intro A3B, exfalso, apply A3A, apply A3B, }, { intro A3B, apply A3A, }, }, }, rw A3, have A4:(βŠ₯:ennreal)=(0:ennreal) := rfl, rw ← A4, rw ← le_bot_iff, apply le_trans (measure_theory.measure_union_le ({Ο‰:Ξ©|P Ο‰}ᢜ) ({Ο‰:Ξ©|Q Ο‰}ᢜ)), rw measure_theory.measure.all_ae_def2 at A1, rw measure_theory.measure.all_ae_def2 at A2, rw A1, rw A2, simp, end lemma measure_theory.all_ae_imp {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) (P Q:Ξ© β†’ Prop): (ΞΌ.all_ae (Ξ» a, P a β†’ Q a)) β†’ (ΞΌ.all_ae P) β†’ (ΞΌ.all_ae Q) := begin intros A1 A2, rw measure_theory.measure.all_ae_def2 at A1, rw measure_theory.measure.all_ae_def2 at A2, rw measure_theory.measure.all_ae_def2, have A3:{Ο‰:Ξ©|Q Ο‰}ᢜ βŠ† ({Ο‰:Ξ©|P Ο‰ β†’ Q Ο‰}ᢜ) βˆͺ ({Ο‰:Ξ©|P Ο‰}ᢜ), { rw set.subset_def, intro Ο‰, simp, intro A3A, cases (classical.em (P Ο‰)) with A3B A3B, { apply or.inl (and.intro A3B A3A), }, { apply or.inr A3B, }, }, have A4:(βŠ₯:ennreal)=(0:ennreal) := rfl, rw ← A4, rw ← le_bot_iff, apply le_trans (measure_theory.measure_mono A3), apply le_trans (measure_theory.measure_union_le ({Ο‰:Ξ©|P Ο‰ β†’ Q Ο‰}ᢜ) ({Ο‰:Ξ©|P Ο‰}ᢜ)), rw A1, rw A2, simp, end lemma measure_theory.all_ae2_of_all {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) (P:Ξ© β†’ Prop): (βˆ€ a, P a) β†’ (ΞΌ.all_ae P) := begin intro A1, rw measure_theory.measure.all_ae_def2, have A2:{Ο‰:Ξ©|P Ο‰}ᢜ = βˆ…, { ext Ο‰,split;intros A2A, exfalso, simp at A2A, apply A2A, apply A1, exfalso, apply A2A, }, rw A2, simp, end lemma measure_theory.not_ae {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) (P:Ξ© β†’ Prop): (βˆƒ S:set Ξ©, (ΞΌ S > 0) ∧ (βˆ€ Ο‰βˆˆ S, Β¬ (P Ο‰)) )β†’ (Β¬(ΞΌ.all_ae P)) := begin intros A1 A2, cases A1 with S A3, cases A3 with A3 A4, rw measure_theory.measure.all_ae_def2 at A2, have A5:SβŠ† {Ο‰:Ξ©|P Ο‰}ᢜ, { rw set.subset_def, intro Ο‰, intro A5A, apply A4 _ A5A, }, have A6 := measure_theory.outer_measure.mono (ΞΌ.to_outer_measure) A5, have A7 := lt_of_lt_of_le A3 A6, rw measure.apply at A2, rw A2 at A7, apply lt_irrefl (0:ennreal) A7, end /- Notice that it is not necessarily the case that a measurable set exists. For example, consider where Ξ© = {a,b}. The measurable sets are {} and {a,b}, where ΞΌ βˆ… = 0 and ΞΌ {a,b} = 1. Define (P a) and (Β¬P b). Thus S={a}, which is not measurable. -/ lemma measure_theory.not_ae_elim {Ξ©:Type*} {M:measurable_space Ξ©} (ΞΌ:measure_theory.measure Ξ©) (P:Ξ© β†’ Prop): (Β¬(ΞΌ.all_ae P)) β†’ (βˆƒ S:set Ξ©, (ΞΌ S > 0) ∧ (βˆ€ Ο‰βˆˆ S, Β¬ (P Ο‰)) ) := begin intro A1, rw measure_theory.measure.all_ae_def2 at A1, have A2 := ennreal.eq_zero_or_zero_lt A1, apply exists.intro ({Ο‰ : Ξ© | P Ο‰}ᢜ), split, apply A2, intros Ο‰ A3, simp at A3, apply A3, end
515a68d5a0c1c7deb296e95dc545d685460ba45c
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/Lean3Lib/init/data/repr.lean
39d94eb0054255db8b59674db64c424b009c10f0
[]
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
5,743
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.data.string.basic import Mathlib.Lean3Lib.init.data.bool.basic import Mathlib.Lean3Lib.init.data.subtype.basic import Mathlib.Lean3Lib.init.data.unsigned.basic import Mathlib.Lean3Lib.init.data.prod import Mathlib.Lean3Lib.init.data.sum.basic import Mathlib.Lean3Lib.init.data.nat.div universes u l v namespace Mathlib /-- Implement `has_repr` if the output string is valid lean code that evaluates back to the original object. If you just want to view the object as a string for a trace message, use `has_to_string`. ### Example: ``` #eval to_string "hello world" -- [Lean] "hello world" -- [Lean] "hello world" #eval repr "hello world" -- [Lean] "\"hello world\"" -- [Lean] "\"hello world\"" ``` Reference: https://github.com/leanprover/lean/issues/1664 -/ class has_repr (Ξ± : Type u) where repr : Ξ± β†’ string /-- `repr` is similar to `to_string` except that we should have the property `eval (repr x) = x` for most sensible datatypes. Hence, `repr "hello"` has the value `"\"hello\""` not `"hello"`. -/ def repr {Ξ± : Type u} [has_repr Ξ±] : Ξ± β†’ string := has_repr.repr protected instance bool.has_repr : has_repr Bool := has_repr.mk fun (b : Bool) => cond b (string.str (string.str string.empty (char.of_nat (bit0 (bit0 (bit1 (bit0 (bit1 (bit1 1)))))))) (char.of_nat (bit0 (bit0 (bit1 (bit0 (bit1 (bit1 1)))))))) (string.str (string.str string.empty (char.of_nat (bit0 (bit1 (bit1 (bit0 (bit0 (bit1 1)))))))) (char.of_nat (bit0 (bit1 (bit1 (bit0 (bit0 (bit1 1)))))))) -- Remark: type class inference will not consider local instance `b` in the new elaborator protected instance decidable.has_repr {p : Prop} : has_repr (Decidable p) := has_repr.mk fun (b : Decidable p) => ite p (string.str (string.str string.empty (char.of_nat (bit0 (bit0 (bit1 (bit0 (bit1 (bit1 1)))))))) (char.of_nat (bit0 (bit0 (bit1 (bit0 (bit1 (bit1 1)))))))) (string.str (string.str string.empty (char.of_nat (bit0 (bit1 (bit1 (bit0 (bit0 (bit1 1)))))))) (char.of_nat (bit0 (bit1 (bit1 (bit0 (bit0 (bit1 1)))))))) protected def list.repr_aux {Ξ± : Type u} [has_repr Ξ±] : Bool β†’ List Ξ± β†’ string := sorry protected def list.repr {Ξ± : Type u} [has_repr Ξ±] : List Ξ± β†’ string := sorry protected instance list.has_repr {Ξ± : Type u} [has_repr Ξ±] : has_repr (List Ξ±) := has_repr.mk list.repr protected instance unit.has_repr : has_repr Unit := has_repr.mk fun (u : Unit) => string.str (string.str (string.str (string.str string.empty (char.of_nat (bit1 (bit1 (bit0 (bit0 (bit1 (bit1 1)))))))) (char.of_nat (bit0 (bit0 (bit1 (bit0 (bit1 (bit1 1)))))))) (char.of_nat (bit1 (bit0 (bit0 (bit0 (bit0 (bit1 1)))))))) (char.of_nat (bit0 (bit1 (bit0 (bit0 (bit1 (bit1 1))))))) protected instance option.has_repr {Ξ± : Type u} [has_repr Ξ±] : has_repr (Option Ξ±) := has_repr.mk fun (o : Option Ξ±) => sorry protected instance sum.has_repr {Ξ± : Type u} {Ξ² : Type v} [has_repr Ξ±] [has_repr Ξ²] : has_repr (Ξ± βŠ• Ξ²) := has_repr.mk fun (s : Ξ± βŠ• Ξ²) => sorry protected instance prod.has_repr {Ξ± : Type u} {Ξ² : Type v} [has_repr Ξ±] [has_repr Ξ²] : has_repr (Ξ± Γ— Ξ²) := has_repr.mk fun (_x : Ξ± Γ— Ξ²) => sorry protected instance sigma.has_repr {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [has_repr Ξ±] [s : (x : Ξ±) β†’ has_repr (Ξ² x)] : has_repr (sigma Ξ²) := has_repr.mk fun (_x : sigma Ξ²) => sorry protected instance subtype.has_repr {Ξ± : Type u} {p : Ξ± β†’ Prop} [has_repr Ξ±] : has_repr (Subtype p) := has_repr.mk fun (s : Subtype p) => repr (subtype.val s) namespace nat def digit_char (n : β„•) : char := sorry def digit_succ (base : β„•) : List β„• β†’ List β„• := sorry def to_digits (base : β„•) : β„• β†’ List β„• := sorry protected def repr (n : β„•) : string := list.as_string (list.reverse (list.map digit_char (to_digits (bit0 (bit1 (bit0 1))) n))) end nat protected instance nat.has_repr : has_repr β„• := has_repr.mk nat.repr def hex_digit_repr (n : β„•) : string := string.singleton (nat.digit_char n) def char_to_hex (c : char) : string := let n : β„• := char.to_nat c; let d2 : β„• := n / bit0 (bit0 (bit0 (bit0 1))); let d1 : β„• := n % bit0 (bit0 (bit0 (bit0 1))); hex_digit_repr d2 ++ hex_digit_repr d1 def char.quote_core (c : char) : string := sorry protected instance char.has_repr : has_repr char := has_repr.mk fun (c : char) => string.str string.empty (char.of_nat (bit1 (bit1 (bit1 (bit0 (bit0 1)))))) ++ char.quote_core c ++ string.str string.empty (char.of_nat (bit1 (bit1 (bit1 (bit0 (bit0 1)))))) def string.quote_aux : List char β†’ string := sorry def string.quote (s : string) : string := ite (string.is_empty s = tt) (string.str (string.str string.empty (char.of_nat (bit0 (bit1 (bit0 (bit0 (bit0 1))))))) (char.of_nat (bit0 (bit1 (bit0 (bit0 (bit0 1))))))) (string.str string.empty (char.of_nat (bit0 (bit1 (bit0 (bit0 (bit0 1)))))) ++ string.quote_aux (string.to_list s) ++ string.str string.empty (char.of_nat (bit0 (bit1 (bit0 (bit0 (bit0 1))))))) protected instance string.has_repr : has_repr string := has_repr.mk string.quote protected instance fin.has_repr (n : β„•) : has_repr (fin n) := has_repr.mk fun (f : fin n) => repr (subtype.val f) protected instance unsigned.has_repr : has_repr unsigned := has_repr.mk fun (n : unsigned) => repr (subtype.val n) def char.repr (c : char) : string := repr c
1f839b6a3a56745ddd61dda88ab1421af3fefaff
856e2e1615a12f95b551ed48fa5b03b245abba44
/src/field_theory/mv_polynomial.lean
ad10dbd283e000e06d5457341683b946b7e25e92
[ "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
9,574
lean
/- Copyright (c) 2019 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Johannes HΓΆlzl Multivariate functions of the form `Ξ±^n β†’ Ξ±` are isomorphic to multivariate polynomials in `n` variables. -/ import linear_algebra.finsupp_vector_space import field_theory.finite noncomputable theory open_locale classical open set linear_map submodule open_locale big_operators namespace mv_polynomial universes u v variables {Οƒ : Type u} {Ξ± : Type v} section variables (Οƒ Ξ±) [field Ξ±] (m : β„•) def restrict_total_degree : submodule Ξ± (mv_polynomial Οƒ Ξ±) := finsupp.supported _ _ {n | n.sum (Ξ»n e, e) ≀ m } lemma mem_restrict_total_degree (p : mv_polynomial Οƒ Ξ±) : p ∈ restrict_total_degree Οƒ Ξ± m ↔ p.total_degree ≀ m := begin rw [total_degree, finset.sup_le_iff], refl end end section variables (Οƒ Ξ±) def restrict_degree (m : β„•) [field Ξ±] : submodule Ξ± (mv_polynomial Οƒ Ξ±) := finsupp.supported _ _ {n | βˆ€i, n i ≀ m } end lemma mem_restrict_degree [field Ξ±] (p : mv_polynomial Οƒ Ξ±) (n : β„•) : p ∈ restrict_degree Οƒ Ξ± n ↔ (βˆ€s ∈ p.support, βˆ€i, (s : Οƒ β†’β‚€ β„•) i ≀ n) := begin rw [restrict_degree, finsupp.mem_supported], refl end lemma mem_restrict_degree_iff_sup [field Ξ±] (p : mv_polynomial Οƒ Ξ±) (n : β„•) : p ∈ restrict_degree Οƒ Ξ± n ↔ βˆ€i, p.degrees.count i ≀ n := begin simp only [mem_restrict_degree, degrees, multiset.count_sup, finsupp.count_to_multiset, finset.sup_le_iff], exact ⟨assume h n s hs, h s hs n, assume h s hs n, h n s hs⟩ end lemma map_range_eq_map {Ξ² : Type*} [comm_ring Ξ±] [comm_ring Ξ²] (p : mv_polynomial Οƒ Ξ±) (f : Ξ± β†’ Ξ²) [is_semiring_hom f]: finsupp.map_range f (is_semiring_hom.map_zero f) p = p.map f := begin rw [← finsupp.sum_single p, finsupp.sum], -- It's not great that we need to use an `erw` here, -- but hopefully it will become smoother when we move entirely away from `is_semiring_hom`. erw [finsupp.map_range_finset_sum (add_monoid_hom.of f)], rw [← p.support.sum_hom (map f)], { refine finset.sum_congr rfl (assume n _, _), rw [finsupp.map_range_single, ← monomial, ← monomial, map_monomial, add_monoid_hom.coe_of], }, apply_instance end section variables (Οƒ Ξ±) lemma is_basis_monomials [field Ξ±] : is_basis Ξ± ((Ξ»s, (monomial s 1 : mv_polynomial Οƒ Ξ±))) := suffices is_basis Ξ± (Ξ» (sa : Ξ£ _, unit), (monomial sa.1 1 : mv_polynomial Οƒ Ξ±)), begin apply is_basis.comp this (Ξ» (s : Οƒ β†’β‚€ β„•), ⟨s, punit.star⟩), split, { intros x y hxy, simpa using hxy }, { intros x, rcases x with ⟨x₁, xβ‚‚βŸ©, use x₁, rw punit_eq punit.star xβ‚‚ } end, begin apply finsupp.is_basis_single (Ξ» _ _, (1 : Ξ±)), intro _, apply is_basis_singleton_one, end end end mv_polynomial namespace mv_polynomial universe u variables (Οƒ : Type u) (Ξ± : Type u) [field Ξ±] open_locale classical lemma dim_mv_polynomial : vector_space.dim Ξ± (mv_polynomial Οƒ Ξ±) = cardinal.mk (Οƒ β†’β‚€ β„•) := by rw [← cardinal.lift_inj, ← (is_basis_monomials Οƒ Ξ±).mk_eq_dim] end mv_polynomial namespace mv_polynomial variables {Ξ± : Type*} {Οƒ : Type*} variables [field Ξ±] [fintype Ξ±] [fintype Οƒ] def indicator (a : Οƒ β†’ Ξ±) : mv_polynomial Οƒ Ξ± := ∏ n, (1 - (X n - C (a n))^(fintype.card Ξ± - 1)) lemma eval_indicator_apply_eq_one (a : Οƒ β†’ Ξ±) : eval a (indicator a) = 1 := have 0 < fintype.card Ξ± - 1, begin rw [← finite_field.card_units, fintype.card_pos_iff], exact ⟨1⟩ end, by simp only [indicator, (finset.univ.prod_hom (eval a)).symm, eval_sub, is_ring_hom.map_one (eval a), is_semiring_hom.map_pow (eval a), eval_X, eval_C, sub_self, zero_pow this, sub_zero, finset.prod_const_one] lemma eval_indicator_apply_eq_zero (a b : Οƒ β†’ Ξ±) (h : a β‰  b) : eval a (indicator b) = 0 := have βˆƒi, a i β‰  b i, by rwa [(β‰ ), function.funext_iff, not_forall] at h, begin rcases this with ⟨i, hi⟩, simp only [indicator, (finset.univ.prod_hom (eval a)).symm, eval_sub, is_ring_hom.map_one (eval a), is_semiring_hom.map_pow (eval a), eval_X, eval_C, sub_self, finset.prod_eq_zero_iff], refine ⟨i, finset.mem_univ _, _⟩, rw [finite_field.pow_card_sub_one_eq_one, sub_self], rwa [(β‰ ), sub_eq_zero], end lemma degrees_indicator (c : Οƒ β†’ Ξ±) : degrees (indicator c) ≀ βˆ‘ s : Οƒ, (fintype.card Ξ± - 1) β€’β„• {s} := begin rw [indicator], refine le_trans (degrees_prod _ _) (finset.sum_le_sum $ assume s hs, _), refine le_trans (degrees_sub _ _) _, rw [degrees_one, ← bot_eq_zero, bot_sup_eq], refine le_trans (degrees_pow _ _) (nsmul_le_nsmul_of_le_right _ _), refine le_trans (degrees_sub _ _) _, rw [degrees_C, ← bot_eq_zero, sup_bot_eq], exact degrees_X _ end lemma indicator_mem_restrict_degree (c : Οƒ β†’ Ξ±) : indicator c ∈ restrict_degree Οƒ Ξ± (fintype.card Ξ± - 1) := begin rw [mem_restrict_degree_iff_sup, indicator], assume n, refine le_trans (multiset.count_le_of_le _ $ degrees_indicator _) (le_of_eq _), rw [← finset.univ.sum_hom (multiset.count n)], simp only [is_add_monoid_hom.map_nsmul (multiset.count n), multiset.singleton_eq_singleton, nsmul_eq_mul, nat.cast_id], transitivity, refine finset.sum_eq_single n _ _, { assume b hb ne, rw [multiset.count_cons_of_ne ne.symm, multiset.count_zero, mul_zero] }, { assume h, exact (h $ finset.mem_univ _).elim }, { rw [multiset.count_cons_self, multiset.count_zero, mul_one] } end section variables (Ξ± Οƒ) def evalβ‚— : mv_polynomial Οƒ Ξ± β†’β‚—[Ξ±] (Οƒ β†’ Ξ±) β†’ Ξ± := ⟨ Ξ»p e, p.eval e, assume p q, funext $ assume e, eval_add, assume a p, funext $ assume e, by rw [smul_eq_C_mul, eval_mul, eval_C]; refl ⟩ end section lemma evalβ‚—_apply (p : mv_polynomial Οƒ Ξ±) (e : Οƒ β†’ Ξ±) : evalβ‚— Ξ± Οƒ p e = p.eval e := rfl end lemma map_restrict_dom_evalβ‚— : (restrict_degree Οƒ Ξ± (fintype.card Ξ± - 1)).map (evalβ‚— Ξ± Οƒ) = ⊀ := begin refine top_unique (submodule.le_def'.2 $ assume e _, mem_map.2 _), refine βŸ¨βˆ‘ n : Οƒ β†’ Ξ±, e n β€’ indicator n, _, _⟩, { exact sum_mem _ (assume c _, smul_mem _ _ (indicator_mem_restrict_degree _)) }, { ext n, simp only [linear_map.map_sum, @pi.finset_sum_apply (Οƒ β†’ Ξ±) (Ξ»_, Ξ±) _ _ _ _ _, pi.smul_apply, linear_map.map_smul], simp only [evalβ‚—_apply], transitivity, refine finset.sum_eq_single n _ _, { assume b _ h, rw [eval_indicator_apply_eq_zero _ _ h.symm, smul_zero] }, { assume h, exact (h $ finset.mem_univ n).elim }, { rw [eval_indicator_apply_eq_one, smul_eq_mul, mul_one] } } end end mv_polynomial namespace mv_polynomial universe u variables (Οƒ : Type u) (Ξ± : Type u) [fintype Οƒ] [field Ξ±] [fintype Ξ±] @[derive [add_comm_group, vector_space Ξ±, inhabited]] def R : Type u := restrict_degree Οƒ Ξ± (fintype.card Ξ± - 1) noncomputable instance decidable_restrict_degree (m : β„•) : decidable_pred (Ξ»n, n ∈ {n : Οƒ β†’β‚€ β„• | βˆ€i, n i ≀ m }) := by simp only [set.mem_set_of_eq]; apply_instance lemma dim_R : vector_space.dim Ξ± (R Οƒ Ξ±) = fintype.card (Οƒ β†’ Ξ±) := calc vector_space.dim Ξ± (R Οƒ Ξ±) = vector_space.dim Ξ± (β†₯{s : Οƒ β†’β‚€ β„• | βˆ€ (n : Οƒ), s n ≀ fintype.card Ξ± - 1} β†’β‚€ Ξ±) : linear_equiv.dim_eq (finsupp.supported_equiv_finsupp {s : Οƒ β†’β‚€ β„• | βˆ€n:Οƒ, s n ≀ fintype.card Ξ± - 1 }) ... = cardinal.mk {s : Οƒ β†’β‚€ β„• | βˆ€ (n : Οƒ), s n ≀ fintype.card Ξ± - 1} : by rw [finsupp.dim_eq, dim_of_field, mul_one] ... = cardinal.mk {s : Οƒ β†’ β„• | βˆ€ (n : Οƒ), s n < fintype.card Ξ± } : begin refine quotient.sound ⟨equiv.subtype_congr finsupp.equiv_fun_on_fintype $ assume f, _⟩, refine forall_congr (assume n, nat.le_sub_right_iff_add_le _), exact fintype.card_pos_iff.2 ⟨0⟩ end ... = cardinal.mk (Οƒ β†’ {n // n < fintype.card Ξ±}) : quotient.sound ⟨@equiv.subtype_pi_equiv_pi Οƒ (Ξ»_, β„•) (Ξ»s n, n < fintype.card Ξ±)⟩ ... = cardinal.mk (Οƒ β†’ fin (fintype.card Ξ±)) : quotient.sound ⟨equiv.arrow_congr (equiv.refl Οƒ) (equiv.fin_equiv_subtype _).symm⟩ ... = cardinal.mk (Οƒ β†’ Ξ±) : begin refine (trunc.induction_on (fintype.equiv_fin Ξ±) $ assume (e : Ξ± ≃ fin (fintype.card Ξ±)), _), refine quotient.sound ⟨equiv.arrow_congr (equiv.refl Οƒ) e.symm⟩ end ... = fintype.card (Οƒ β†’ Ξ±) : cardinal.fintype_card _ def evalα΅’ : R Οƒ Ξ± β†’β‚—[Ξ±] (Οƒ β†’ Ξ±) β†’ Ξ± := ((evalβ‚— Ξ± Οƒ).comp (restrict_degree Οƒ Ξ± (fintype.card Ξ± - 1)).subtype) lemma range_evalα΅’ : (evalα΅’ Οƒ Ξ±).range = ⊀ := begin rw [evalα΅’, linear_map.range_comp, range_subtype], exact map_restrict_dom_evalβ‚— end lemma ker_evalβ‚— : (evalα΅’ Οƒ Ξ±).ker = βŠ₯ := begin refine injective_of_surjective _ _ _ (range_evalα΅’ _ _), { rw [dim_R], exact cardinal.nat_lt_omega _ }, { rw [dim_R, dim_fun, dim_of_field, mul_one] } end lemma eq_zero_of_eval_eq_zero (p : mv_polynomial Οƒ Ξ±) (h : βˆ€v:Οƒ β†’ Ξ±, p.eval v = 0) (hp : p ∈ restrict_degree Οƒ Ξ± (fintype.card Ξ± - 1)) : p = 0 := let p' : R Οƒ Ξ± := ⟨p, hp⟩ in have p' ∈ (evalα΅’ Οƒ Ξ±).ker := by rw [mem_ker]; ext v; exact h v, show p'.1 = (0 : R Οƒ Ξ±).1, begin rw [ker_evalβ‚—, mem_bot] at this, rw [this] end end mv_polynomial namespace mv_polynomial variables (Οƒ : Type*) (R : Type*) [comm_ring R] (p : β„•) instance [char_p R p] : char_p (mv_polynomial Οƒ R) p := { cast_eq_zero_iff := Ξ» n, by rw [← C_eq_coe_nat, ← C_0, C_inj, char_p.cast_eq_zero_iff R p] } end mv_polynomial
662a12cb33731989e4b7a2c72f21747cd742c275
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/geometry/manifold/smooth_manifold_with_corners.lean
9eade2cf3a81a52c4e0916305925030a1a65b7b7
[ "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
54,951
lean
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel -/ import analysis.calculus.cont_diff import geometry.manifold.charted_space /-! # Smooth manifolds (possibly with boundary or corners) > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. A smooth manifold is a manifold modelled on a normed vector space, or a subset like a half-space (to get manifolds with boundaries) for which the changes of coordinates are smooth maps. We define a model with corners as a map `I : H β†’ E` embedding nicely the topological space `H` in the vector space `E` (or more precisely as a structure containing all the relevant properties). Given such a model with corners `I` on `(E, H)`, we define the groupoid of local homeomorphisms of `H` which are smooth when read in `E` (for any regularity `n : β„•βˆž`). With this groupoid at hand and the general machinery of charted spaces, we thus get the notion of `C^n` manifold with respect to any model with corners `I` on `(E, H)`. We also introduce a specific type class for `C^∞` manifolds as these are the most commonly used. ## Main definitions * `model_with_corners π•œ E H` : a structure containing informations on the way a space `H` embeds in a model vector space E over the field `π•œ`. This is all that is needed to define a smooth manifold with model space `H`, and model vector space `E`. * `model_with_corners_self π•œ E` : trivial model with corners structure on the space `E` embedded in itself by the identity. * `cont_diff_groupoid n I` : when `I` is a model with corners on `(π•œ, E, H)`, this is the groupoid of local homeos of `H` which are of class `C^n` over the normed field `π•œ`, when read in `E`. * `smooth_manifold_with_corners I M` : a type class saying that the charted space `M`, modelled on the space `H`, has `C^∞` changes of coordinates with respect to the model with corners `I` on `(π•œ, E, H)`. This type class is just a shortcut for `has_groupoid M (cont_diff_groupoid ∞ I)`. * `ext_chart_at I x`: in a smooth manifold with corners with the model `I` on `(E, H)`, the charts take values in `H`, but often we may want to use their `E`-valued version, obtained by composing the charts with `I`. Since the target is in general not open, we can not register them as local homeomorphisms, but we register them as local equivs. `ext_chart_at I x` is the canonical such local equiv around `x`. As specific examples of models with corners, we define (in the file `real_instances.lean`) * `model_with_corners_self ℝ (euclidean_space (fin n))` for the model space used to define `n`-dimensional real manifolds without boundary (with notation `𝓑 n` in the locale `manifold`) * `model_with_corners ℝ (euclidean_space (fin n)) (euclidean_half_space n)` for the model space used to define `n`-dimensional real manifolds with boundary (with notation `π“‘βˆ‚ n` in the locale `manifold`) * `model_with_corners ℝ (euclidean_space (fin n)) (euclidean_quadrant n)` for the model space used to define `n`-dimensional real manifolds with corners With these definitions at hand, to invoke an `n`-dimensional real manifold without boundary, one could use `variables {n : β„•} {M : Type*} [topological_space M] [charted_space (euclidean_space (fin n)) M] [smooth_manifold_with_corners (𝓑 n) M]`. However, this is not the recommended way: a theorem proved using this assumption would not apply for instance to the tangent space of such a manifold, which is modelled on `(euclidean_space (fin n)) Γ— (euclidean_space (fin n))` and not on `euclidean_space (fin (2 * n))`! In the same way, it would not apply to product manifolds, modelled on `(euclidean_space (fin n)) Γ— (euclidean_space (fin m))`. The right invocation does not focus on one specific construction, but on all constructions sharing the right properties, like `variables {E : Type*} [normed_add_comm_group E] [normed_space ℝ E] [finite_dimensional ℝ E] {I : model_with_corners ℝ E E} [I.boundaryless] {M : Type*} [topological_space M] [charted_space E M] [smooth_manifold_with_corners I M]` Here, `I.boundaryless` is a typeclass property ensuring that there is no boundary (this is for instance the case for `model_with_corners_self`, or products of these). Note that one could consider as a natural assumption to only use the trivial model with corners `model_with_corners_self ℝ E`, but again in product manifolds the natural model with corners will not be this one but the product one (and they are not defeq as `(Ξ»p : E Γ— F, (p.1, p.2))` is not defeq to the identity). So, it is important to use the above incantation to maximize the applicability of theorems. ## Implementation notes We want to talk about manifolds modelled on a vector space, but also on manifolds with boundary, modelled on a half space (or even manifolds with corners). For the latter examples, we still want to define smooth functions, tangent bundles, and so on. As smooth functions are well defined on vector spaces or subsets of these, one could take for model space a subtype of a vector space. With the drawback that the whole vector space itself (which is the most basic example) is not directly a subtype of itself: the inclusion of `univ : set E` in `set E` would show up in the definition, instead of `id`. A good abstraction covering both cases it to have a vector space `E` (with basic example the Euclidean space), a model space `H` (with basic example the upper half space), and an embedding of `H` into `E` (which can be the identity for `H = E`, or `subtype.val` for manifolds with corners). We say that the pair `(E, H)` with their embedding is a model with corners, and we encompass all the relevant properties (in particular the fact that the image of `H` in `E` should have unique differentials) in the definition of `model_with_corners`. We concentrate on `C^∞` manifolds: all the definitions work equally well for `C^n` manifolds, but later on it is a pain to carry all over the smoothness parameter, especially when one wants to deal with `C^k` functions as there would be additional conditions `k ≀ n` everywhere. Since one deals almost all the time with `C^∞` (or analytic) manifolds, this seems to be a reasonable choice that one could revisit later if needed. `C^k` manifolds are still available, but they should be called using `has_groupoid M (cont_diff_groupoid k I)` where `I` is the model with corners. I have considered using the model with corners `I` as a typeclass argument, possibly `out_param`, to get lighter notations later on, but it did not turn out right, as on `E Γ— F` there are two natural model with corners, the trivial (identity) one, and the product one, and they are not defeq and one needs to indicate to Lean which one we want to use. This means that when talking on objects on manifolds one will most often need to specify the model with corners one is using. For instance, the tangent bundle will be `tangent_bundle I M` and the derivative will be `mfderiv I I' f`, instead of the more natural notations `tangent_bundle π•œ M` and `mfderiv π•œ f` (the field has to be explicit anyway, as some manifolds could be considered both as real and complex manifolds). -/ noncomputable theory universes u v w u' v' w' open set filter function open_locale manifold filter topology localized "notation (name := with_top.nat.top) `∞` := (⊀ : β„•βˆž)" in manifold /-! ### Models with corners. -/ /-- A structure containing informations on the way a space `H` embeds in a model vector space `E` over the field `π•œ`. This is all what is needed to define a smooth manifold with model space `H`, and model vector space `E`. -/ @[ext, nolint has_nonempty_instance] structure model_with_corners (π•œ : Type*) [nontrivially_normed_field π•œ] (E : Type*) [normed_add_comm_group E] [normed_space π•œ E] (H : Type*) [topological_space H] extends local_equiv H E := (source_eq : source = univ) (unique_diff' : unique_diff_on π•œ to_local_equiv.target) (continuous_to_fun : continuous to_fun . tactic.interactive.continuity') (continuous_inv_fun : continuous inv_fun . tactic.interactive.continuity') attribute [simp, mfld_simps] model_with_corners.source_eq /-- A vector space is a model with corners. -/ def model_with_corners_self (π•œ : Type*) [nontrivially_normed_field π•œ] (E : Type*) [normed_add_comm_group E] [normed_space π•œ E] : model_with_corners π•œ E E := { to_local_equiv := local_equiv.refl E, source_eq := rfl, unique_diff' := unique_diff_on_univ, continuous_to_fun := continuous_id, continuous_inv_fun := continuous_id } localized "notation (name := model_with_corners_self) `π“˜(` π•œ `, ` E `)` := model_with_corners_self π•œ E" in manifold localized "notation (name := model_with_corners_self.self) `π“˜(` π•œ `)` := model_with_corners_self π•œ π•œ" in manifold section variables {π•œ : Type*} [nontrivially_normed_field π•œ] {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {H : Type*} [topological_space H] (I : model_with_corners π•œ E H) namespace model_with_corners instance : has_coe_to_fun (model_with_corners π•œ E H) (Ξ» _, H β†’ E) := ⟨λ e, e.to_fun⟩ /-- The inverse to a model with corners, only registered as a local equiv. -/ protected def symm : local_equiv E H := I.to_local_equiv.symm /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def simps.apply (π•œ : Type*) [nontrivially_normed_field π•œ] (E : Type*) [normed_add_comm_group E] [normed_space π•œ E] (H : Type*) [topological_space H] (I : model_with_corners π•œ E H) : H β†’ E := I /-- See Note [custom simps projection] -/ def simps.symm_apply (π•œ : Type*) [nontrivially_normed_field π•œ] (E : Type*) [normed_add_comm_group E] [normed_space π•œ E] (H : Type*) [topological_space H] (I : model_with_corners π•œ E H) : E β†’ H := I.symm initialize_simps_projections model_with_corners (to_local_equiv_to_fun β†’ apply, to_local_equiv_inv_fun β†’ symm_apply, to_local_equiv_source β†’ source, to_local_equiv_target β†’ target, -to_local_equiv) /- Register a few lemmas to make sure that `simp` puts expressions in normal form -/ @[simp, mfld_simps] lemma to_local_equiv_coe : (I.to_local_equiv : H β†’ E) = I := rfl @[simp, mfld_simps] lemma mk_coe (e : local_equiv H E) (a b c d) : ((model_with_corners.mk e a b c d : model_with_corners π•œ E H) : H β†’ E) = (e : H β†’ E) := rfl @[simp, mfld_simps] lemma to_local_equiv_coe_symm : (I.to_local_equiv.symm : E β†’ H) = I.symm := rfl @[simp, mfld_simps] lemma mk_symm (e : local_equiv H E) (a b c d) : (model_with_corners.mk e a b c d : model_with_corners π•œ E H).symm = e.symm := rfl @[continuity] protected lemma continuous : continuous I := I.continuous_to_fun protected lemma continuous_at {x} : continuous_at I x := I.continuous.continuous_at protected lemma continuous_within_at {s x} : continuous_within_at I s x := I.continuous_at.continuous_within_at @[continuity] lemma continuous_symm : continuous I.symm := I.continuous_inv_fun lemma continuous_at_symm {x} : continuous_at I.symm x := I.continuous_symm.continuous_at lemma continuous_within_at_symm {s x} : continuous_within_at I.symm s x := I.continuous_symm.continuous_within_at lemma continuous_on_symm {s} : continuous_on I.symm s := I.continuous_symm.continuous_on @[simp, mfld_simps] lemma target_eq : I.target = range (I : H β†’ E) := by { rw [← image_univ, ← I.source_eq], exact (I.to_local_equiv.image_source_eq_target).symm } protected lemma unique_diff : unique_diff_on π•œ (range I) := I.target_eq β–Έ I.unique_diff' @[simp, mfld_simps] protected lemma left_inv (x : H) : I.symm (I x) = x := by { refine I.left_inv' _, simp } protected lemma left_inverse : left_inverse I.symm I := I.left_inv lemma injective : injective I := I.left_inverse.injective @[simp, mfld_simps] lemma symm_comp_self : I.symm ∘ I = id := I.left_inverse.comp_eq_id protected lemma right_inv_on : right_inv_on I.symm I (range I) := I.left_inverse.right_inv_on_range @[simp, mfld_simps] protected lemma right_inv {x : E} (hx : x ∈ range I) : I (I.symm x) = x := I.right_inv_on hx lemma preimage_image (s : set H) : I ⁻¹' (I '' s) = s := I.injective.preimage_image s protected lemma image_eq (s : set H) : I '' s = I.symm ⁻¹' s ∩ range I := begin refine (I.to_local_equiv.image_eq_target_inter_inv_preimage _).trans _, { rw I.source_eq, exact subset_univ _ }, { rw [inter_comm, I.target_eq, I.to_local_equiv_coe_symm] } end protected lemma closed_embedding : closed_embedding I := I.left_inverse.closed_embedding I.continuous_symm I.continuous lemma closed_range : is_closed (range I) := I.closed_embedding.closed_range lemma map_nhds_eq (x : H) : map I (𝓝 x) = 𝓝[range I] (I x) := I.closed_embedding.to_embedding.map_nhds_eq x lemma map_nhds_within_eq (s : set H) (x : H) : map I (𝓝[s] x) = 𝓝[I '' s] (I x) := I.closed_embedding.to_embedding.map_nhds_within_eq s x lemma image_mem_nhds_within {x : H} {s : set H} (hs : s ∈ 𝓝 x) : I '' s ∈ 𝓝[range I] (I x) := I.map_nhds_eq x β–Έ image_mem_map hs lemma symm_map_nhds_within_image {x : H} {s : set H} : map I.symm (𝓝[I '' s] (I x)) = 𝓝[s] x := by rw [← I.map_nhds_within_eq, map_map, I.symm_comp_self, map_id] lemma symm_map_nhds_within_range (x : H) : map I.symm (𝓝[range I] (I x)) = 𝓝 x := by rw [← I.map_nhds_eq, map_map, I.symm_comp_self, map_id] lemma unique_diff_preimage {s : set H} (hs : is_open s) : unique_diff_on π•œ (I.symm ⁻¹' s ∩ range I) := by { rw inter_comm, exact I.unique_diff.inter (hs.preimage I.continuous_inv_fun) } lemma unique_diff_preimage_source {Ξ² : Type*} [topological_space Ξ²] {e : local_homeomorph H Ξ²} : unique_diff_on π•œ (I.symm ⁻¹' (e.source) ∩ range I) := I.unique_diff_preimage e.open_source lemma unique_diff_at_image {x : H} : unique_diff_within_at π•œ (range I) (I x) := I.unique_diff _ (mem_range_self _) lemma symm_continuous_within_at_comp_right_iff {X} [topological_space X] {f : H β†’ X} {s : set H} {x : H} : continuous_within_at (f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I x) ↔ continuous_within_at f s x := begin refine ⟨λ h, _, Ξ» h, _⟩, { have := h.comp I.continuous_within_at (maps_to_preimage _ _), simp_rw [preimage_inter, preimage_preimage, I.left_inv, preimage_id', preimage_range, inter_univ] at this, rwa [function.comp.assoc, I.symm_comp_self] at this }, { rw [← I.left_inv x] at h, exact h.comp I.continuous_within_at_symm (inter_subset_left _ _) } end protected lemma locally_compact [locally_compact_space E] (I : model_with_corners π•œ E H) : locally_compact_space H := begin have : βˆ€ (x : H), (𝓝 x).has_basis (Ξ» s, s ∈ 𝓝 (I x) ∧ is_compact s) (Ξ» s, I.symm '' (s ∩ range ⇑I)), { intro x, rw ← I.symm_map_nhds_within_range, exact ((compact_basis_nhds (I x)).inf_principal _).map _ }, refine locally_compact_space_of_has_basis this _, rintro x s ⟨-, hsc⟩, exact (hsc.inter_right I.closed_range).image I.continuous_symm end open topological_space protected lemma second_countable_topology [second_countable_topology E] (I : model_with_corners π•œ E H) : second_countable_topology H := I.closed_embedding.to_embedding.second_countable_topology end model_with_corners section variables (π•œ E) /-- In the trivial model with corners, the associated local equiv is the identity. -/ @[simp, mfld_simps] lemma model_with_corners_self_local_equiv : (π“˜(π•œ, E)).to_local_equiv = local_equiv.refl E := rfl @[simp, mfld_simps] lemma model_with_corners_self_coe : (π“˜(π•œ, E) : E β†’ E) = id := rfl @[simp, mfld_simps] lemma model_with_corners_self_coe_symm : (π“˜(π•œ, E).symm : E β†’ E) = id := rfl end end section model_with_corners_prod /-- Given two model_with_corners `I` on `(E, H)` and `I'` on `(E', H')`, we define the model with corners `I.prod I'` on `(E Γ— E', model_prod H H')`. This appears in particular for the manifold structure on the tangent bundle to a manifold modelled on `(E, H)`: it will be modelled on `(E Γ— E, H Γ— E)`. See note [Manifold type tags] for explanation about `model_prod H H'` vs `H Γ— H'`. -/ @[simps (lemmas_only)] def model_with_corners.prod {π•œ : Type u} [nontrivially_normed_field π•œ] {E : Type v} [normed_add_comm_group E] [normed_space π•œ E] {H : Type w} [topological_space H] (I : model_with_corners π•œ E H) {E' : Type v'} [normed_add_comm_group E'] [normed_space π•œ E'] {H' : Type w'} [topological_space H'] (I' : model_with_corners π•œ E' H') : model_with_corners π•œ (E Γ— E') (model_prod H H') := { to_fun := Ξ» x, (I x.1, I' x.2), inv_fun := Ξ» x, (I.symm x.1, I'.symm x.2), source := {x | x.1 ∈ I.source ∧ x.2 ∈ I'.source}, source_eq := by simp only [set_of_true] with mfld_simps, unique_diff' := I.unique_diff'.prod I'.unique_diff', continuous_to_fun := I.continuous_to_fun.prod_map I'.continuous_to_fun, continuous_inv_fun := I.continuous_inv_fun.prod_map I'.continuous_inv_fun, .. I.to_local_equiv.prod I'.to_local_equiv } /-- Given a finite family of `model_with_corners` `I i` on `(E i, H i)`, we define the model with corners `pi I` on `(Ξ  i, E i, model_pi H)`. See note [Manifold type tags] for explanation about `model_pi H`. -/ def model_with_corners.pi {π•œ : Type u} [nontrivially_normed_field π•œ] {ΞΉ : Type v} [fintype ΞΉ] {E : ΞΉ β†’ Type w} [Ξ  i, normed_add_comm_group (E i)] [Ξ  i, normed_space π•œ (E i)] {H : ΞΉ β†’ Type u'} [Ξ  i, topological_space (H i)] (I : Ξ  i, model_with_corners π•œ (E i) (H i)) : model_with_corners π•œ (Ξ  i, E i) (model_pi H) := { to_local_equiv := local_equiv.pi (Ξ» i, (I i).to_local_equiv), source_eq := by simp only [set.pi_univ] with mfld_simps, unique_diff' := unique_diff_on.pi ΞΉ E _ _ (Ξ» i _, (I i).unique_diff'), continuous_to_fun := continuous_pi $ Ξ» i, (I i).continuous.comp (continuous_apply i), continuous_inv_fun := continuous_pi $ Ξ» i, (I i).continuous_symm.comp (continuous_apply i) } /-- Special case of product model with corners, which is trivial on the second factor. This shows up as the model to tangent bundles. -/ @[reducible] def model_with_corners.tangent {π•œ : Type u} [nontrivially_normed_field π•œ] {E : Type v} [normed_add_comm_group E] [normed_space π•œ E] {H : Type w} [topological_space H] (I : model_with_corners π•œ E H) : model_with_corners π•œ (E Γ— E) (model_prod H E) := I.prod (π“˜(π•œ, E)) variables {π•œ : Type*} [nontrivially_normed_field π•œ] {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {E' : Type*} [normed_add_comm_group E'] [normed_space π•œ E'] {F : Type*} [normed_add_comm_group F] [normed_space π•œ F] {F' : Type*} [normed_add_comm_group F'] [normed_space π•œ F'] {H : Type*} [topological_space H] {H' : Type*} [topological_space H'] {G : Type*} [topological_space G] {G' : Type*} [topological_space G'] {I : model_with_corners π•œ E H} {J : model_with_corners π•œ F G} @[simp, mfld_simps] lemma model_with_corners_prod_to_local_equiv : (I.prod J).to_local_equiv = I.to_local_equiv.prod (J.to_local_equiv) := rfl @[simp, mfld_simps] lemma model_with_corners_prod_coe (I : model_with_corners π•œ E H) (I' : model_with_corners π•œ E' H') : (I.prod I' : _ Γ— _ β†’ _ Γ— _) = prod.map I I' := rfl @[simp, mfld_simps] lemma model_with_corners_prod_coe_symm (I : model_with_corners π•œ E H) (I' : model_with_corners π•œ E' H') : ((I.prod I').symm : _ Γ— _ β†’ _ Γ— _) = prod.map I.symm I'.symm := rfl lemma model_with_corners_self_prod : π“˜(π•œ, E Γ— F) = π“˜(π•œ, E).prod π“˜(π•œ, F) := by { ext1, simp } lemma model_with_corners.range_prod : range (I.prod J) = range I Γ—Λ’ range J := by { simp_rw [← model_with_corners.target_eq], refl } end model_with_corners_prod section boundaryless /-- Property ensuring that the model with corners `I` defines manifolds without boundary. -/ class model_with_corners.boundaryless {π•œ : Type*} [nontrivially_normed_field π•œ] {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {H : Type*} [topological_space H] (I : model_with_corners π•œ E H) : Prop := (range_eq_univ : range I = univ) /-- The trivial model with corners has no boundary -/ instance model_with_corners_self_boundaryless (π•œ : Type*) [nontrivially_normed_field π•œ] (E : Type*) [normed_add_comm_group E] [normed_space π•œ E] : (model_with_corners_self π•œ E).boundaryless := ⟨by simp⟩ /-- If two model with corners are boundaryless, their product also is -/ instance model_with_corners.range_eq_univ_prod {π•œ : Type u} [nontrivially_normed_field π•œ] {E : Type v} [normed_add_comm_group E] [normed_space π•œ E] {H : Type w} [topological_space H] (I : model_with_corners π•œ E H) [I.boundaryless] {E' : Type v'} [normed_add_comm_group E'] [normed_space π•œ E'] {H' : Type w'} [topological_space H'] (I' : model_with_corners π•œ E' H') [I'.boundaryless] : (I.prod I').boundaryless := begin split, dsimp [model_with_corners.prod, model_prod], rw [← prod_range_range_eq, model_with_corners.boundaryless.range_eq_univ, model_with_corners.boundaryless.range_eq_univ, univ_prod_univ] end end boundaryless section cont_diff_groupoid /-! ### Smooth functions on models with corners -/ variables {m n : β„•βˆž} {π•œ : Type*} [nontrivially_normed_field π•œ] {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {H : Type*} [topological_space H] (I : model_with_corners π•œ E H) {M : Type*} [topological_space M] variable (n) /-- Given a model with corners `(E, H)`, we define the groupoid of `C^n` transformations of `H` as the maps that are `C^n` when read in `E` through `I`. -/ def cont_diff_groupoid : structure_groupoid H := pregroupoid.groupoid { property := Ξ»f s, cont_diff_on π•œ n (I ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I), comp := Ξ»f g u v hf hg hu hv huv, begin have : I ∘ (g ∘ f) ∘ I.symm = (I ∘ g ∘ I.symm) ∘ (I ∘ f ∘ I.symm), by { ext x, simp }, rw this, apply cont_diff_on.comp hg _, { rintros x ⟨hx1, hx2⟩, simp only with mfld_simps at ⊒ hx1, exact hx1.2 }, { refine hf.mono _, rintros x ⟨hx1, hx2⟩, exact ⟨hx1.1, hx2⟩ } end, id_mem := begin apply cont_diff_on.congr (cont_diff_id.cont_diff_on), rintros x ⟨hx1, hx2⟩, rcases mem_range.1 hx2 with ⟨y, hy⟩, rw ← hy, simp only with mfld_simps, end, locality := Ξ»f u hu H, begin apply cont_diff_on_of_locally_cont_diff_on, rintros y ⟨hy1, hy2⟩, rcases mem_range.1 hy2 with ⟨x, hx⟩, rw ← hx at ⊒ hy1, simp only with mfld_simps at ⊒ hy1, rcases H x hy1 with ⟨v, v_open, xv, hv⟩, have : ((I.symm ⁻¹' (u ∩ v)) ∩ (range I)) = ((I.symm ⁻¹' u) ∩ (range I) ∩ I.symm ⁻¹' v), { rw [preimage_inter, inter_assoc, inter_assoc], congr' 1, rw inter_comm }, rw this at hv, exact ⟨I.symm ⁻¹' v, v_open.preimage I.continuous_symm, by simpa, hv⟩ end, congr := Ξ»f g u hu fg hf, begin apply hf.congr, rintros y ⟨hy1, hy2⟩, rcases mem_range.1 hy2 with ⟨x, hx⟩, rw ← hx at ⊒ hy1, simp only with mfld_simps at ⊒ hy1, rw fg _ hy1 end } variable {n} /-- Inclusion of the groupoid of `C^n` local diffeos in the groupoid of `C^m` local diffeos when `m ≀ n` -/ lemma cont_diff_groupoid_le (h : m ≀ n) : cont_diff_groupoid n I ≀ cont_diff_groupoid m I := begin rw [cont_diff_groupoid, cont_diff_groupoid], apply groupoid_of_pregroupoid_le, assume f s hfs, exact cont_diff_on.of_le hfs h end /-- The groupoid of `0`-times continuously differentiable maps is just the groupoid of all local homeomorphisms -/ lemma cont_diff_groupoid_zero_eq : cont_diff_groupoid 0 I = continuous_groupoid H := begin apply le_antisymm le_top, assume u hu, -- we have to check that every local homeomorphism belongs to `cont_diff_groupoid 0 I`, -- by unfolding its definition change u ∈ cont_diff_groupoid 0 I, rw [cont_diff_groupoid, mem_groupoid_of_pregroupoid], simp only [cont_diff_on_zero], split, { refine I.continuous.comp_continuous_on (u.continuous_on.comp I.continuous_on_symm _), exact (maps_to_preimage _ _).mono_left (inter_subset_left _ _) }, { refine I.continuous.comp_continuous_on (u.symm.continuous_on.comp I.continuous_on_symm _), exact (maps_to_preimage _ _).mono_left (inter_subset_left _ _) }, end variable (n) /-- An identity local homeomorphism belongs to the `C^n` groupoid. -/ lemma of_set_mem_cont_diff_groupoid {s : set H} (hs : is_open s) : local_homeomorph.of_set s hs ∈ cont_diff_groupoid n I := begin rw [cont_diff_groupoid, mem_groupoid_of_pregroupoid], suffices h : cont_diff_on π•œ n (I ∘ I.symm) (I.symm ⁻¹' s ∩ range I), by simp [h], have : cont_diff_on π•œ n id (univ : set E) := cont_diff_id.cont_diff_on, exact this.congr_mono (Ξ» x hx, by simp [hx.2]) (subset_univ _) end /-- The composition of a local homeomorphism from `H` to `M` and its inverse belongs to the `C^n` groupoid. -/ lemma symm_trans_mem_cont_diff_groupoid (e : local_homeomorph M H) : e.symm.trans e ∈ cont_diff_groupoid n I := begin have : e.symm.trans e β‰ˆ local_homeomorph.of_set e.target e.open_target := local_homeomorph.trans_symm_self _, exact structure_groupoid.eq_on_source _ (of_set_mem_cont_diff_groupoid n I e.open_target) this end variables {E' H' : Type*} [normed_add_comm_group E'] [normed_space π•œ E'] [topological_space H'] /-- The product of two smooth local homeomorphisms is smooth. -/ lemma cont_diff_groupoid_prod {I : model_with_corners π•œ E H} {I' : model_with_corners π•œ E' H'} {e : local_homeomorph H H} {e' : local_homeomorph H' H'} (he : e ∈ cont_diff_groupoid ⊀ I) (he' : e' ∈ cont_diff_groupoid ⊀ I') : e.prod e' ∈ cont_diff_groupoid ⊀ (I.prod I') := begin cases he with he he_symm, cases he' with he' he'_symm, simp only at he he_symm he' he'_symm, split; simp only [local_equiv.prod_source, local_homeomorph.prod_to_local_equiv], { have h3 := cont_diff_on.prod_map he he', rw [← I.image_eq, ← I'.image_eq, set.prod_image_image_eq] at h3, rw ← (I.prod I').image_eq, exact h3, }, { have h3 := cont_diff_on.prod_map he_symm he'_symm, rw [← I.image_eq, ← I'.image_eq, set.prod_image_image_eq] at h3, rw ← (I.prod I').image_eq, exact h3, } end /-- The `C^n` groupoid is closed under restriction. -/ instance : closed_under_restriction (cont_diff_groupoid n I) := (closed_under_restriction_iff_id_le _).mpr begin apply structure_groupoid.le_iff.mpr, rintros e ⟨s, hs, hes⟩, apply (cont_diff_groupoid n I).eq_on_source' _ _ _ hes, exact of_set_mem_cont_diff_groupoid n I hs, end end cont_diff_groupoid section smooth_manifold_with_corners /-! ### Smooth manifolds with corners -/ /-- Typeclass defining smooth manifolds with corners with respect to a model with corners, over a field `π•œ` and with infinite smoothness to simplify typeclass search and statements later on. -/ @[ancestor has_groupoid] class smooth_manifold_with_corners {π•œ : Type*} [nontrivially_normed_field π•œ] {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {H : Type*} [topological_space H] (I : model_with_corners π•œ E H) (M : Type*) [topological_space M] [charted_space H M] extends has_groupoid M (cont_diff_groupoid ∞ I) : Prop lemma smooth_manifold_with_corners.mk' {π•œ : Type*} [nontrivially_normed_field π•œ] {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {H : Type*} [topological_space H] (I : model_with_corners π•œ E H) (M : Type*) [topological_space M] [charted_space H M] [gr : has_groupoid M (cont_diff_groupoid ∞ I)] : smooth_manifold_with_corners I M := { ..gr } lemma smooth_manifold_with_corners_of_cont_diff_on {π•œ : Type*} [nontrivially_normed_field π•œ] {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {H : Type*} [topological_space H] (I : model_with_corners π•œ E H) (M : Type*) [topological_space M] [charted_space H M] (h : βˆ€ (e e' : local_homeomorph M H), e ∈ atlas H M β†’ e' ∈ atlas H M β†’ cont_diff_on π•œ ⊀ (I ∘ (e.symm ≫ₕ e') ∘ I.symm) (I.symm ⁻¹' (e.symm ≫ₕ e').source ∩ range I)) : smooth_manifold_with_corners I M := { compatible := begin haveI : has_groupoid M (cont_diff_groupoid ∞ I) := has_groupoid_of_pregroupoid _ h, apply structure_groupoid.compatible, end } /-- For any model with corners, the model space is a smooth manifold -/ instance model_space_smooth {π•œ : Type*} [nontrivially_normed_field π•œ] {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {H : Type*} [topological_space H] {I : model_with_corners π•œ E H} : smooth_manifold_with_corners I H := { .. has_groupoid_model_space _ _ } end smooth_manifold_with_corners namespace smooth_manifold_with_corners /- We restate in the namespace `smooth_manifolds_with_corners` some lemmas that hold for general charted space with a structure groupoid, avoiding the need to specify the groupoid `cont_diff_groupoid ∞ I` explicitly. -/ variables {π•œ : Type*} [nontrivially_normed_field π•œ] {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {H : Type*} [topological_space H] (I : model_with_corners π•œ E H) (M : Type*) [topological_space M] [charted_space H M] /-- The maximal atlas of `M` for the smooth manifold with corners structure corresponding to the model with corners `I`. -/ def maximal_atlas := (cont_diff_groupoid ∞ I).maximal_atlas M variable {M} lemma subset_maximal_atlas [smooth_manifold_with_corners I M] : atlas H M βŠ† maximal_atlas I M := structure_groupoid.subset_maximal_atlas _ lemma chart_mem_maximal_atlas [smooth_manifold_with_corners I M] (x : M) : chart_at H x ∈ maximal_atlas I M := structure_groupoid.chart_mem_maximal_atlas _ x variable {I} lemma compatible_of_mem_maximal_atlas {e e' : local_homeomorph M H} (he : e ∈ maximal_atlas I M) (he' : e' ∈ maximal_atlas I M) : e.symm.trans e' ∈ cont_diff_groupoid ∞ I := structure_groupoid.compatible_of_mem_maximal_atlas he he' /-- The product of two smooth manifolds with corners is naturally a smooth manifold with corners. -/ instance prod {π•œ : Type*} [nontrivially_normed_field π•œ] {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {E' : Type*} [normed_add_comm_group E'] [normed_space π•œ E'] {H : Type*} [topological_space H] {I : model_with_corners π•œ E H} {H' : Type*} [topological_space H'] {I' : model_with_corners π•œ E' H'} (M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (M' : Type*) [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] : smooth_manifold_with_corners (I.prod I') (MΓ—M') := { compatible := begin rintros f g ⟨f1, f2, hf1, hf2, rfl⟩ ⟨g1, g2, hg1, hg2, rfl⟩, rw [local_homeomorph.prod_symm, local_homeomorph.prod_trans], have h1 := has_groupoid.compatible (cont_diff_groupoid ⊀ I) hf1 hg1, have h2 := has_groupoid.compatible (cont_diff_groupoid ⊀ I') hf2 hg2, exact cont_diff_groupoid_prod h1 h2, end } end smooth_manifold_with_corners lemma local_homeomorph.singleton_smooth_manifold_with_corners {π•œ : Type*} [nontrivially_normed_field π•œ] {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {H : Type*} [topological_space H] (I : model_with_corners π•œ E H) {M : Type*} [topological_space M] (e : local_homeomorph M H) (h : e.source = set.univ) : @smooth_manifold_with_corners π•œ _ E _ _ H _ I M _ (e.singleton_charted_space h) := @smooth_manifold_with_corners.mk' _ _ _ _ _ _ _ _ _ _ (id _) $ e.singleton_has_groupoid h (cont_diff_groupoid ∞ I) lemma open_embedding.singleton_smooth_manifold_with_corners {π•œ : Type*} [nontrivially_normed_field π•œ] {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {H : Type*} [topological_space H] (I : model_with_corners π•œ E H) {M : Type*} [topological_space M] [nonempty M] {f : M β†’ H} (h : open_embedding f) : @smooth_manifold_with_corners π•œ _ E _ _ H _ I M _ h.singleton_charted_space := (h.to_local_homeomorph f).singleton_smooth_manifold_with_corners I (by simp) namespace topological_space.opens open topological_space variables {π•œ : Type*} [nontrivially_normed_field π•œ] {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {H : Type*} [topological_space H] (I : model_with_corners π•œ E H) {M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (s : opens M) instance : smooth_manifold_with_corners I s := { ..s.has_groupoid (cont_diff_groupoid ∞ I) } end topological_space.opens section extended_charts open_locale topology variables {π•œ E M H E' M' H' : Type*} [nontrivially_normed_field π•œ] [normed_add_comm_group E] [normed_space π•œ E] [topological_space H] [topological_space M] (f f' : local_homeomorph M H) (I : model_with_corners π•œ E H) [normed_add_comm_group E'] [normed_space π•œ E'] [topological_space H'] [topological_space M'] (I' : model_with_corners π•œ E' H') (x : M) {s t : set M} /-! ### Extended charts In a smooth manifold with corners, the model space is the space `H`. However, we will also need to use extended charts taking values in the model vector space `E`. These extended charts are not `local_homeomorph` as the target is not open in `E` in general, but we can still register them as `local_equiv`. -/ namespace local_homeomorph /-- Given a chart `f` on a manifold with corners, `f.extend I` is the extended chart to the model vector space. -/ @[simp, mfld_simps] def extend : local_equiv M E := f.to_local_equiv ≫ I.to_local_equiv lemma extend_coe : ⇑(f.extend I) = I ∘ f := rfl lemma extend_coe_symm : ⇑(f.extend I).symm = f.symm ∘ I.symm := rfl lemma extend_source : (f.extend I).source = f.source := by rw [extend, local_equiv.trans_source, I.source_eq, preimage_univ, inter_univ] lemma is_open_extend_source : is_open (f.extend I).source := by { rw extend_source, exact f.open_source } lemma extend_target : (f.extend I).target = I.symm ⁻¹' f.target ∩ range I := by simp_rw [extend, local_equiv.trans_target, I.target_eq, I.to_local_equiv_coe_symm, inter_comm] lemma maps_to_extend (hs : s βŠ† f.source) : maps_to (f.extend I) s ((f.extend I).symm ⁻¹' s ∩ range I) := begin rw [maps_to', extend_coe, extend_coe_symm, preimage_comp, ← I.image_eq, image_comp, f.image_eq_target_inter_inv_preimage hs], exact image_subset _ (inter_subset_right _ _) end lemma extend_left_inv {x : M} (hxf : x ∈ f.source) : (f.extend I).symm (f.extend I x) = x := (f.extend I).left_inv $ by rwa f.extend_source lemma extend_source_mem_nhds {x : M} (h : x ∈ f.source) : (f.extend I).source ∈ 𝓝 x := (is_open_extend_source f I).mem_nhds $ by rwa f.extend_source I lemma extend_source_mem_nhds_within {x : M} (h : x ∈ f.source) : (f.extend I).source ∈ 𝓝[s] x := mem_nhds_within_of_mem_nhds $ extend_source_mem_nhds f I h lemma continuous_on_extend : continuous_on (f.extend I) (f.extend I).source := begin refine I.continuous.comp_continuous_on _, rw extend_source, exact f.continuous_on end lemma continuous_at_extend {x : M} (h : x ∈ f.source) : continuous_at (f.extend I) x := (continuous_on_extend f I).continuous_at $ extend_source_mem_nhds f I h lemma map_extend_nhds {x : M} (hy : x ∈ f.source) : map (f.extend I) (𝓝 x) = 𝓝[range I] (f.extend I x) := by rwa [extend_coe, (∘), ← I.map_nhds_eq, ← f.map_nhds_eq, map_map] lemma extend_target_mem_nhds_within {y : M} (hy : y ∈ f.source) : (f.extend I).target ∈ 𝓝[range I] (f.extend I y) := begin rw [← local_equiv.image_source_eq_target, ← map_extend_nhds f I hy], exact image_mem_map (extend_source_mem_nhds _ _ hy) end lemma extend_target_subset_range : (f.extend I).target βŠ† range I := by simp only with mfld_simps lemma nhds_within_extend_target_eq {y : M} (hy : y ∈ f.source) : 𝓝[(f.extend I).target] (f.extend I y) = 𝓝[range I] (f.extend I y) := (nhds_within_mono _ (extend_target_subset_range _ _)).antisymm $ nhds_within_le_of_mem (extend_target_mem_nhds_within _ _ hy) lemma continuous_at_extend_symm' {x : E} (h : x ∈ (f.extend I).target) : continuous_at (f.extend I).symm x := continuous_at.comp (f.continuous_at_symm h.2) (I.continuous_symm.continuous_at) lemma continuous_at_extend_symm {x : M} (h : x ∈ f.source) : continuous_at (f.extend I).symm (f.extend I x) := continuous_at_extend_symm' f I $ (f.extend I).map_source $ by rwa f.extend_source lemma continuous_on_extend_symm : continuous_on (f.extend I).symm (f.extend I).target := Ξ» y hy, (continuous_at_extend_symm' _ _ hy).continuous_within_at lemma extend_symm_continuous_within_at_comp_right_iff {X} [topological_space X] {g : M β†’ X} {s : set M} {x : M} : continuous_within_at (g ∘ (f.extend I).symm) ((f.extend I).symm ⁻¹' s ∩ range I) (f.extend I x) ↔ continuous_within_at (g ∘ f.symm) (f.symm ⁻¹' s) (f x) := by convert I.symm_continuous_within_at_comp_right_iff; refl lemma is_open_extend_preimage' {s : set E} (hs : is_open s) : is_open ((f.extend I).source ∩ f.extend I ⁻¹' s) := (continuous_on_extend f I).preimage_open_of_open (is_open_extend_source _ _) hs lemma is_open_extend_preimage {s : set E} (hs : is_open s) : is_open (f.source ∩ f.extend I ⁻¹' s) := by { rw ← extend_source f I, exact is_open_extend_preimage' f I hs } lemma map_extend_nhds_within_eq_image {y : M} (hy : y ∈ f.source) : map (f.extend I) (𝓝[s] y) = 𝓝[f.extend I '' ((f.extend I).source ∩ s)] (f.extend I y) := by set e := f.extend I; calc map e (𝓝[s] y) = map e (𝓝[e.source ∩ s] y) : congr_arg (map e) (nhds_within_inter_of_mem (extend_source_mem_nhds_within f I hy)).symm ... = 𝓝[e '' (e.source ∩ s)] (e y) : ((f.extend I).left_inv_on.mono $ inter_subset_left _ _).map_nhds_within_eq ((f.extend I).left_inv $ by rwa f.extend_source) (continuous_at_extend_symm f I hy).continuous_within_at (continuous_at_extend f I hy).continuous_within_at lemma map_extend_nhds_within {y : M} (hy : y ∈ f.source) : map (f.extend I) (𝓝[s] y) = 𝓝[(f.extend I).symm ⁻¹' s ∩ range I] (f.extend I y) := by rw [map_extend_nhds_within_eq_image f I hy, nhds_within_inter, ← nhds_within_extend_target_eq _ _ hy, ← nhds_within_inter, (f.extend I).image_source_inter_eq', inter_comm] lemma map_extend_symm_nhds_within {y : M} (hy : y ∈ f.source) : map (f.extend I).symm (𝓝[(f.extend I).symm ⁻¹' s ∩ range I] (f.extend I y)) = 𝓝[s] y := begin rw [← map_extend_nhds_within f I hy, map_map, map_congr, map_id], exact (f.extend I).left_inv_on.eq_on.eventually_eq_of_mem (extend_source_mem_nhds_within _ _ hy) end lemma map_extend_symm_nhds_within_range {y : M} (hy : y ∈ f.source) : map (f.extend I).symm (𝓝[range I] (f.extend I y)) = 𝓝 y := by rw [← nhds_within_univ, ← map_extend_symm_nhds_within f I hy, preimage_univ, univ_inter] /-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of a point in the source is a neighborhood of the preimage, within a set. -/ lemma extend_preimage_mem_nhds_within {x : M} (h : x ∈ f.source) (ht : t ∈ 𝓝[s] x) : (f.extend I).symm ⁻¹' t ∈ 𝓝[(f.extend I).symm ⁻¹' s ∩ range I] (f.extend I x) := by rwa [← map_extend_symm_nhds_within f I h, mem_map] at ht lemma extend_preimage_mem_nhds {x : M} (h : x ∈ f.source) (ht : t ∈ 𝓝 x) : (f.extend I).symm ⁻¹' t ∈ 𝓝 (f.extend I x) := begin apply (continuous_at_extend_symm f I h).preimage_mem_nhds, rwa (f.extend I).left_inv, rwa f.extend_source end /-- Technical lemma to rewrite suitably the preimage of an intersection under an extended chart, to bring it into a convenient form to apply derivative lemmas. -/ lemma extend_preimage_inter_eq : ((f.extend I).symm ⁻¹' (s ∩ t) ∩ range I) = ((f.extend I).symm ⁻¹' s ∩ range I) ∩ ((f.extend I).symm ⁻¹' t) := by mfld_set_tac lemma extend_symm_preimage_inter_range_eventually_eq_aux {s : set M} {x : M} (hx : x ∈ f.source) : ((f.extend I).symm ⁻¹' s ∩ range I : set _) =αΆ [𝓝 (f.extend I x)] ((f.extend I).target ∩ (f.extend I).symm ⁻¹' s : set _) := begin rw [f.extend_target, inter_assoc, inter_comm (range I)], conv { congr, skip, rw [← @univ_inter _ (_ ∩ _)] }, refine (eventually_eq_univ.mpr _).symm.inter eventually_eq.rfl, refine I.continuous_at_symm.preimage_mem_nhds (f.open_target.mem_nhds _), simp_rw [f.extend_coe, function.comp_apply, I.left_inv, f.maps_to hx] end lemma extend_symm_preimage_inter_range_eventually_eq {s : set M} {x : M} (hs : s βŠ† f.source) (hx : x ∈ f.source) : ((f.extend I).symm ⁻¹' s ∩ range I : set _) =αΆ [𝓝 (f.extend I x)] f.extend I '' s := begin rw [← f.extend_source I] at hs, rw [(f.extend I).image_eq_target_inter_inv_preimage hs], exact f.extend_symm_preimage_inter_range_eventually_eq_aux I hx end /-! We use the name `extend_coord_change` for `(f'.extend I).symm ≫ f.extend I`. -/ lemma extend_coord_change_source : ((f.extend I).symm ≫ f'.extend I).source = I '' (f.symm ≫ₕ f').source := by { simp_rw [local_equiv.trans_source, I.image_eq, extend_source, local_equiv.symm_source, extend_target, inter_right_comm _ (range I)], refl } lemma extend_image_source_inter : f.extend I '' (f.source ∩ f'.source) = ((f.extend I).symm ≫ f'.extend I).source := by simp_rw [f.extend_coord_change_source, f.extend_coe, image_comp I f, trans_source'', symm_symm, symm_target] lemma extend_coord_change_source_mem_nhds_within {x : E} (hx : x ∈ ((f.extend I).symm ≫ f'.extend I).source) : ((f.extend I).symm ≫ f'.extend I).source ∈ 𝓝[range I] x := begin rw [f.extend_coord_change_source] at hx ⊒, obtain ⟨x, hx, rfl⟩ := hx, refine I.image_mem_nhds_within _, refine (local_homeomorph.open_source _).mem_nhds hx end lemma extend_coord_change_source_mem_nhds_within' {x : M} (hxf : x ∈ f.source) (hxf' : x ∈ f'.source) : ((f.extend I).symm ≫ f'.extend I).source ∈ 𝓝[range I] f.extend I x := begin apply extend_coord_change_source_mem_nhds_within, rw [← extend_image_source_inter], exact mem_image_of_mem _ ⟨hxf, hxf'⟩, end variables {f f'} open smooth_manifold_with_corners lemma cont_diff_on_extend_coord_change [charted_space H M] (hf : f ∈ maximal_atlas I M) (hf' : f' ∈ maximal_atlas I M) : cont_diff_on π•œ ⊀ (f.extend I ∘ (f'.extend I).symm) ((f'.extend I).symm ≫ f.extend I).source := begin rw [extend_coord_change_source, I.image_eq], exact (structure_groupoid.compatible_of_mem_maximal_atlas hf' hf).1 end lemma cont_diff_within_at_extend_coord_change [charted_space H M] (hf : f ∈ maximal_atlas I M) (hf' : f' ∈ maximal_atlas I M) {x : E} (hx : x ∈ ((f'.extend I).symm ≫ f.extend I).source) : cont_diff_within_at π•œ ⊀ (f.extend I ∘ (f'.extend I).symm) (range I) x := begin apply (cont_diff_on_extend_coord_change I hf hf' x hx).mono_of_mem, rw [extend_coord_change_source] at hx ⊒, obtain ⟨z, hz, rfl⟩ := hx, exact I.image_mem_nhds_within ((local_homeomorph.open_source _).mem_nhds hz) end lemma cont_diff_within_at_extend_coord_change' [charted_space H M] (hf : f ∈ maximal_atlas I M) (hf' : f' ∈ maximal_atlas I M) {x : M} (hxf : x ∈ f.source) (hxf' : x ∈ f'.source) : cont_diff_within_at π•œ ⊀ (f.extend I ∘ (f'.extend I).symm) (range I) (f'.extend I x) := begin refine cont_diff_within_at_extend_coord_change I hf hf' _, rw [← extend_image_source_inter], exact mem_image_of_mem _ ⟨hxf', hxf⟩ end end local_homeomorph open local_homeomorph variables [charted_space H M] [charted_space H' M'] /-- The preferred extended chart on a manifold with corners around a point `x`, from a neighborhood of `x` to the model vector space. -/ @[simp, mfld_simps] def ext_chart_at (x : M) : local_equiv M E := (chart_at H x).extend I lemma ext_chart_at_coe : ⇑(ext_chart_at I x) = I ∘ chart_at H x := rfl lemma ext_chart_at_coe_symm : ⇑(ext_chart_at I x).symm = (chart_at H x).symm ∘ I.symm := rfl lemma ext_chart_at_source : (ext_chart_at I x).source = (chart_at H x).source := extend_source _ _ lemma is_open_ext_chart_at_source : is_open (ext_chart_at I x).source := is_open_extend_source _ _ lemma mem_ext_chart_source : x ∈ (ext_chart_at I x).source := by simp only [ext_chart_at_source, mem_chart_source] lemma ext_chart_at_target (x : M) : (ext_chart_at I x).target = I.symm ⁻¹' (chart_at H x).target ∩ range I := extend_target _ _ lemma ext_chart_at_to_inv : (ext_chart_at I x).symm ((ext_chart_at I x) x) = x := (ext_chart_at I x).left_inv (mem_ext_chart_source I x) lemma maps_to_ext_chart_at (hs : s βŠ† (chart_at H x).source) : maps_to (ext_chart_at I x) s ((ext_chart_at I x).symm ⁻¹' s ∩ range I) := maps_to_extend _ _ hs lemma ext_chart_at_source_mem_nhds' {x' : M} (h : x' ∈ (ext_chart_at I x).source) : (ext_chart_at I x).source ∈ 𝓝 x' := extend_source_mem_nhds _ _ $ by rwa ← ext_chart_at_source I lemma ext_chart_at_source_mem_nhds : (ext_chart_at I x).source ∈ 𝓝 x := ext_chart_at_source_mem_nhds' I x (mem_ext_chart_source I x) lemma ext_chart_at_source_mem_nhds_within' {x' : M} (h : x' ∈ (ext_chart_at I x).source) : (ext_chart_at I x).source ∈ 𝓝[s] x' := mem_nhds_within_of_mem_nhds (ext_chart_at_source_mem_nhds' I x h) lemma ext_chart_at_source_mem_nhds_within : (ext_chart_at I x).source ∈ 𝓝[s] x := mem_nhds_within_of_mem_nhds (ext_chart_at_source_mem_nhds I x) lemma continuous_on_ext_chart_at : continuous_on (ext_chart_at I x) (ext_chart_at I x).source := continuous_on_extend _ _ lemma continuous_at_ext_chart_at' {x' : M} (h : x' ∈ (ext_chart_at I x).source) : continuous_at (ext_chart_at I x) x' := continuous_at_extend _ _ $ by rwa ← ext_chart_at_source I lemma continuous_at_ext_chart_at : continuous_at (ext_chart_at I x) x := continuous_at_ext_chart_at' _ _ (mem_ext_chart_source I x) lemma map_ext_chart_at_nhds' {x y : M} (hy : y ∈ (ext_chart_at I x).source) : map (ext_chart_at I x) (𝓝 y) = 𝓝[range I] (ext_chart_at I x y) := map_extend_nhds _ _ $ by rwa ← ext_chart_at_source I lemma map_ext_chart_at_nhds : map (ext_chart_at I x) (𝓝 x) = 𝓝[range I] (ext_chart_at I x x) := map_ext_chart_at_nhds' I $ mem_ext_chart_source I x lemma ext_chart_at_target_mem_nhds_within' {y : M} (hy : y ∈ (ext_chart_at I x).source) : (ext_chart_at I x).target ∈ 𝓝[range I] (ext_chart_at I x y) := extend_target_mem_nhds_within _ _ $ by rwa ← ext_chart_at_source I lemma ext_chart_at_target_mem_nhds_within : (ext_chart_at I x).target ∈ 𝓝[range I] (ext_chart_at I x x) := ext_chart_at_target_mem_nhds_within' I x (mem_ext_chart_source I x) lemma ext_chart_at_target_subset_range : (ext_chart_at I x).target βŠ† range I := by simp only with mfld_simps lemma nhds_within_ext_chart_at_target_eq' {y : M} (hy : y ∈ (ext_chart_at I x).source) : 𝓝[(ext_chart_at I x).target] (ext_chart_at I x y) = 𝓝[range I] (ext_chart_at I x y) := nhds_within_extend_target_eq _ _ $ by rwa ← ext_chart_at_source I lemma nhds_within_ext_chart_at_target_eq : 𝓝[(ext_chart_at I x).target] ((ext_chart_at I x) x) = 𝓝[range I] ((ext_chart_at I x) x) := nhds_within_ext_chart_at_target_eq' I x (mem_ext_chart_source I x) lemma continuous_at_ext_chart_at_symm'' {y : E} (h : y ∈ (ext_chart_at I x).target) : continuous_at (ext_chart_at I x).symm y := continuous_at_extend_symm' _ _ h lemma continuous_at_ext_chart_at_symm' {x' : M} (h : x' ∈ (ext_chart_at I x).source) : continuous_at (ext_chart_at I x).symm (ext_chart_at I x x') := continuous_at_ext_chart_at_symm'' I _ $ (ext_chart_at I x).map_source h lemma continuous_at_ext_chart_at_symm : continuous_at (ext_chart_at I x).symm ((ext_chart_at I x) x) := continuous_at_ext_chart_at_symm' I x (mem_ext_chart_source I x) lemma continuous_on_ext_chart_at_symm : continuous_on (ext_chart_at I x).symm (ext_chart_at I x).target := Ξ» y hy, (continuous_at_ext_chart_at_symm'' _ _ hy).continuous_within_at lemma is_open_ext_chart_at_preimage' {s : set E} (hs : is_open s) : is_open ((ext_chart_at I x).source ∩ ext_chart_at I x ⁻¹' s) := is_open_extend_preimage' _ _ hs lemma is_open_ext_chart_at_preimage {s : set E} (hs : is_open s) : is_open ((chart_at H x).source ∩ ext_chart_at I x ⁻¹' s) := by { rw ← ext_chart_at_source I, exact is_open_ext_chart_at_preimage' I x hs } lemma map_ext_chart_at_nhds_within_eq_image' {y : M} (hy : y ∈ (ext_chart_at I x).source) : map (ext_chart_at I x) (𝓝[s] y) = 𝓝[ext_chart_at I x '' ((ext_chart_at I x).source ∩ s)] (ext_chart_at I x y) := map_extend_nhds_within_eq_image _ _ $ by rwa ← ext_chart_at_source I lemma map_ext_chart_at_nhds_within_eq_image : map (ext_chart_at I x) (𝓝[s] x) = 𝓝[ext_chart_at I x '' ((ext_chart_at I x).source ∩ s)] (ext_chart_at I x x) := map_ext_chart_at_nhds_within_eq_image' I x (mem_ext_chart_source I x) lemma map_ext_chart_at_nhds_within' {y : M} (hy : y ∈ (ext_chart_at I x).source) : map (ext_chart_at I x) (𝓝[s] y) = 𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x y) := map_extend_nhds_within _ _ $ by rwa ← ext_chart_at_source I lemma map_ext_chart_at_nhds_within : map (ext_chart_at I x) (𝓝[s] x) = 𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x x) := map_ext_chart_at_nhds_within' I x (mem_ext_chart_source I x) lemma map_ext_chart_at_symm_nhds_within' {y : M} (hy : y ∈ (ext_chart_at I x).source) : map (ext_chart_at I x).symm (𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x y)) = 𝓝[s] y := map_extend_symm_nhds_within _ _ $ by rwa ← ext_chart_at_source I lemma map_ext_chart_at_symm_nhds_within_range' {y : M} (hy : y ∈ (ext_chart_at I x).source) : map (ext_chart_at I x).symm (𝓝[range I] (ext_chart_at I x y)) = 𝓝 y := map_extend_symm_nhds_within_range _ _ $ by rwa ← ext_chart_at_source I lemma map_ext_chart_at_symm_nhds_within : map (ext_chart_at I x).symm (𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x x)) = 𝓝[s] x := map_ext_chart_at_symm_nhds_within' I x (mem_ext_chart_source I x) lemma map_ext_chart_at_symm_nhds_within_range : map (ext_chart_at I x).symm (𝓝[range I] (ext_chart_at I x x)) = 𝓝 x := map_ext_chart_at_symm_nhds_within_range' I x (mem_ext_chart_source I x) /-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of a point in the source is a neighborhood of the preimage, within a set. -/ lemma ext_chart_at_preimage_mem_nhds_within' {x' : M} (h : x' ∈ (ext_chart_at I x).source) (ht : t ∈ 𝓝[s] x') : (ext_chart_at I x).symm ⁻¹' t ∈ 𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] ((ext_chart_at I x) x') := by rwa [← map_ext_chart_at_symm_nhds_within' I x h, mem_map] at ht /-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of the base point is a neighborhood of the preimage, within a set. -/ lemma ext_chart_at_preimage_mem_nhds_within (ht : t ∈ 𝓝[s] x) : (ext_chart_at I x).symm ⁻¹' t ∈ 𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] ((ext_chart_at I x) x) := ext_chart_at_preimage_mem_nhds_within' I x (mem_ext_chart_source I x) ht lemma ext_chart_at_preimage_mem_nhds' {x' : M} (h : x' ∈ (ext_chart_at I x).source) (ht : t ∈ 𝓝 x') : (ext_chart_at I x).symm ⁻¹' t ∈ 𝓝 (ext_chart_at I x x') := extend_preimage_mem_nhds _ _ (by rwa ← ext_chart_at_source I) ht /-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of a point is a neighborhood of the preimage. -/ lemma ext_chart_at_preimage_mem_nhds (ht : t ∈ 𝓝 x) : (ext_chart_at I x).symm ⁻¹' t ∈ 𝓝 ((ext_chart_at I x) x) := begin apply (continuous_at_ext_chart_at_symm I x).preimage_mem_nhds, rwa (ext_chart_at I x).left_inv (mem_ext_chart_source _ _) end /-- Technical lemma to rewrite suitably the preimage of an intersection under an extended chart, to bring it into a convenient form to apply derivative lemmas. -/ lemma ext_chart_at_preimage_inter_eq : ((ext_chart_at I x).symm ⁻¹' (s ∩ t) ∩ range I) = ((ext_chart_at I x).symm ⁻¹' s ∩ range I) ∩ ((ext_chart_at I x).symm ⁻¹' t) := by mfld_set_tac /-! We use the name `ext_coord_change` for `(ext_chart_at I x').symm ≫ ext_chart_at I x`. -/ lemma ext_coord_change_source (x x' : M) : ((ext_chart_at I x').symm ≫ ext_chart_at I x).source = I '' ((chart_at H x').symm ≫ₕ (chart_at H x)).source := extend_coord_change_source _ _ _ open smooth_manifold_with_corners lemma cont_diff_on_ext_coord_change [smooth_manifold_with_corners I M] (x x' : M) : cont_diff_on π•œ ⊀ (ext_chart_at I x ∘ (ext_chart_at I x').symm) ((ext_chart_at I x').symm ≫ ext_chart_at I x).source := cont_diff_on_extend_coord_change I (chart_mem_maximal_atlas I x) (chart_mem_maximal_atlas I x') lemma cont_diff_within_at_ext_coord_change [smooth_manifold_with_corners I M] (x x' : M) {y : E} (hy : y ∈ ((ext_chart_at I x').symm ≫ ext_chart_at I x).source) : cont_diff_within_at π•œ ⊀ (ext_chart_at I x ∘ (ext_chart_at I x').symm) (range I) y := cont_diff_within_at_extend_coord_change I (chart_mem_maximal_atlas I x) (chart_mem_maximal_atlas I x') hy /-- Conjugating a function to write it in the preferred charts around `x`. The manifold derivative of `f` will just be the derivative of this conjugated function. -/ @[simp, mfld_simps] def written_in_ext_chart_at (x : M) (f : M β†’ M') : E β†’ E' := ext_chart_at I' (f x) ∘ f ∘ (ext_chart_at I x).symm variable (π•œ) lemma ext_chart_at_self_eq {x : H} : ⇑(ext_chart_at I x) = I := rfl lemma ext_chart_at_self_apply {x y : H} : ext_chart_at I x y = I y := rfl /-- In the case of the manifold structure on a vector space, the extended charts are just the identity.-/ lemma ext_chart_at_model_space_eq_id (x : E) : ext_chart_at π“˜(π•œ, E) x = local_equiv.refl E := by simp only with mfld_simps lemma ext_chart_model_space_apply {x y : E} : ext_chart_at π“˜(π•œ, E) x y = y := rfl variable {π•œ} lemma ext_chart_at_prod (x : M Γ— M') : ext_chart_at (I.prod I') x = (ext_chart_at I x.1).prod (ext_chart_at I' x.2) := by simp only with mfld_simps end extended_charts
2007cf52d52ba7b13f70ae5388385d9c6b51e00f
ddf69e0b8ad10bfd251aa1fb492bd92f064768ec
/src/analysis/calculus/times_cont_diff.lean
376664b6d58706d37892d213cbdadbc9fe1a378a
[ "Apache-2.0" ]
permissive
MaboroshiChan/mathlib
db1c1982df384a2604b19a5e1f5c6464c7c76de1
7f74e6b35f6bac86b9218250e83441ac3e17264c
refs/heads/master
1,671,993,587,476
1,601,911,102,000
1,601,911,102,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
122,121
lean
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel -/ import analysis.calculus.mean_value /-! # Higher differentiability A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous. By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or, equivalently, if it is `C^1` and its derivative is `C^{n-1}`. Finally, it is `C^∞` if it is `C^n` for all n. We formalize these notions by defining iteratively the `n+1`-th derivative of a function as the derivative of the `n`-th derivative. It is called `iterated_fderiv π•œ n f x` where `π•œ` is the field, `n` is the number of iterations, `f` is the function and `x` is the point, and it is given as an `n`-multilinear map. We also define a version `iterated_fderiv_within` relative to a domain, as well as predicates `times_cont_diff_within_at`, `times_cont_diff_at`, `times_cont_diff_on` and `times_cont_diff` saying that the function is `C^n` within a set at a point, at a point, on a set and on the whole space respectively. To avoid the issue of choice when choosing a derivative in sets where the derivative is not necessarily unique, `times_cont_diff_on` is not defined directly in terms of the regularity of the specific choice `iterated_fderiv_within π•œ n f s` inside `s`, but in terms of the existence of a nice sequence of derivatives, expressed with a predicate `has_ftaylor_series_up_to_on`. We prove basic properties of these notions. ## Main definitions and results Let `f : E β†’ F` be a map between normed vector spaces over a nondiscrete normed field `π•œ`. * `formal_multilinear_series π•œ E F`: a family of `n`-multilinear maps for all `n`, designed to model the sequence of derivatives of a function. * `has_ftaylor_series_up_to n f p`: expresses that the formal multilinear series `p` is a sequence of iterated derivatives of `f`, up to the `n`-th term (where `n` is a natural number or `∞`). * `has_ftaylor_series_up_to_on n f p s`: same thing, but inside a set `s`. The notion of derivative is now taken inside `s`. In particular, derivatives don't have to be unique. * `times_cont_diff π•œ n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to rank `n`. * `times_cont_diff_on π•œ n f s`: expresses that `f` is `C^n` in `s`. * `times_cont_diff_at π•œ n f x`: expresses that `f` is `C^n` around `x`. * `times_cont_diff_within_at π•œ n f s x`: expresses that `f` is `C^n` around `x` within the set `s`. * `iterated_fderiv_within π•œ n f s x` is an `n`-th derivative of `f` over the field `π•œ` on the set `s` at the point `x`. It is a continuous multilinear map from `E^n` to `F`, defined as a derivative within `s` of `iterated_fderiv_within π•œ (n-1) f s` if one exists, and `0` otherwise. * `iterated_fderiv π•œ n f x` is the `n`-th derivative of `f` over the field `π•œ` at the point `x`. It is a continuous multilinear map from `E^n` to `F`, defined as a derivative of `iterated_fderiv π•œ (n-1) f` if one exists, and `0` otherwise. In sets of unique differentiability, `times_cont_diff_on π•œ n f s` can be expressed in terms of the properties of `iterated_fderiv_within π•œ m f s` for `m ≀ n`. In the whole space, `times_cont_diff π•œ n f` can be expressed in terms of the properties of `iterated_fderiv π•œ m f` for `m ≀ n`. We also prove that the usual operations (addition, multiplication, difference, composition, and so on) preserve `C^n` functions. ## Implementation notes The definitions in this file are designed to work on any field `π•œ`. They are sometimes slightly more complicated than the naive definitions one would guess from the intuition over the real or complex numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity in general. In the usual situations, they coincide with the usual definitions. ### Definition of `C^n` functions in domains One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this is what we do with `iterated_fderiv_within`) and requiring that all these derivatives up to `n` are continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n` functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`. This definition still has the problem that a function which is locally `C^n` would not need to be `C^n`, as different choices of sequences of derivatives around different points might possibly not be glued together to give a globally defined sequence of derivatives. (Note that this issue can not happen over reals, thanks to partition of unity, but the behavior over a general field is not so clear, and we want a definition for general fields). Also, there are locality problems for the order parameter: one could image a function which, for each `n`, has a nice sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore not be glued to give rise to an infinite sequence of derivatives. This would give a function which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions in space and order in our definition of `times_cont_diff_within_at` and `times_cont_diff_on`. The resulting definition is slightly more complicated to work with (in fact not so much), but it gives rise to completely satisfactory theorems. For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)` for each natural `m` is by definition `C^∞` at `0`. There is another issue with the definition of `times_cont_diff_within_at π•œ n f s x`. We can require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x` within `s`. However, this does not imply continuity or differentiability within `s` of the function at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on a neighborhood of `x` within `s βˆͺ {x}` (which appears as `insert x s` in this file). ### Side of the composition, and universe issues With a naΓ―ve direct definition, the `n`-th derivative of a function belongs to the space `E β†’L[π•œ] (E β†’L[π•œ] (E ... F)...)))` where there are n iterations of `E β†’L[π•œ]`. This space may also be seen as the space of continuous multilinear functions on `n` copies of `E` with values in `F`, by uncurrying. This is the point of view that is usually adopted in textbooks, and that we also use. This means that the definition and the first proofs are slightly involved, as one has to keep track of the uncurrying operation. The uncurrying can be done from the left or from the right, amounting to defining the `n+1`-th derivative either as the derivative of the `n`-th derivative, or as the `n`-th derivative of the derivative. For proofs, it would be more convenient to use the latter approach (from the right), as it means to prove things at the `n+1`-th step we only need to understand well enough the derivative in `E β†’L[π•œ] F` (contrary to the approach from the left, where one would need to know enough on the `n`-th derivative to deduce things on the `n+1`-th derivative). However, the definition from the right leads to a universe polymorphism problem: if we define `iterated_fderiv π•œ (n + 1) f x = iterated_fderiv π•œ n (fderiv π•œ f) x` by induction, we need to generalize over all spaces (as `f` and `fderiv π•œ f` don't take values in the same space). It is only possible to generalize over all spaces in some fixed universe in an inductive definition. For `f : E β†’ F`, then `fderiv π•œ f` is a map `E β†’ (E β†’L[π•œ] F)`. Therefore, the definition will only work if `F` and `E β†’L[π•œ] F` are in the same universe. This issue does not appear with the definition from the left, where one does not need to generalize over all spaces. Therefore, we use the definition from the left. This means some proofs later on become a little bit more complicated: to prove that a function is `C^n`, the most efficient approach is to exhibit a formula for its `n`-th derivative and prove it is continuous (contrary to the inductive approach where one would prove smoothness statements without giving a formula for the derivative). In the end, this approach is still satisfactory as it is good to have formulas for the iterated derivatives in various constructions. One point where we depart from this explicit approach is in the proof of smoothness of a composition: there is a formula for the `n`-th derivative of a composition (FaΓ  di Bruno's formula), but it is very complicated and barely usable, while the inductive proof is very simple. Thus, we give the inductive proof. As explained above, it works by generalizing over the target space, hence it only works well if all spaces belong to the same universe. To get the general version, we lift things to a common universe using a trick. ### Variables management The textbook definitions and proofs use various identifications and abuse of notations, for instance when saying that the natural space in which the derivative lives, i.e., `E β†’L[π•œ] (E β†’L[π•œ] ( ... β†’L[π•œ] F))`, is the same as a space of multilinear maps. When doing things formally, we need to provide explicit maps for these identifications, and chase some diagrams to see everything is compatible with the identifications. In particular, one needs to check that taking the derivative and then doing the identification, or first doing the identification and then taking the derivative, gives the same result. The key point for this is that taking the derivative commutes with continuous linear equivalences. Therefore, we need to implement all our identifications with continuous linear equivs. ## Notations We use the notation `E [Γ—n]β†’L[π•œ] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `⊀ : with_top β„•` with `∞`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable theory open_locale classical big_operators local notation `∞` := (⊀ : with_top β„•) universes u v w local attribute [instance, priority 1001] normed_group.to_add_comm_group normed_space.to_semimodule add_comm_group.to_add_comm_monoid open set fin open_locale topological_space variables {π•œ : Type*} [nondiscrete_normed_field π•œ] {E : Type*} [normed_group E] [normed_space π•œ E] {F : Type*} [normed_group F] [normed_space π•œ F] {G : Type*} [normed_group G] [normed_space π•œ G] {s s₁ t u : set E} {f f₁ : E β†’ F} {g : F β†’ G} {x : E} {c : F} {b : E Γ— F β†’ G} /-- A formal multilinear series over a field `π•œ`, from `E` to `F`, is given by a family of multilinear maps from `E^n` to `F` for all `n`. -/ @[derive add_comm_group] def formal_multilinear_series (π•œ : Type*) [nondiscrete_normed_field π•œ] (E : Type*) [normed_group E] [normed_space π•œ E] (F : Type*) [normed_group F] [normed_space π•œ F] := Ξ  (n : β„•), (E [Γ—n]β†’L[π•œ] F) instance : inhabited (formal_multilinear_series π•œ E F) := ⟨0⟩ section module /- `derive` is not able to find the module structure, probably because Lean is confused by the dependent types. We register it explicitly. -/ local attribute [reducible] formal_multilinear_series instance : module π•œ (formal_multilinear_series π•œ E F) := begin letI : βˆ€ n, module π•œ (continuous_multilinear_map π•œ (Ξ» (i : fin n), E) F) := Ξ» n, by apply_instance, apply_instance end end module namespace formal_multilinear_series variables (p : formal_multilinear_series π•œ E F) /-- Forgetting the zeroth term in a formal multilinear series, and interpreting the following terms as multilinear maps into `E β†’L[π•œ] F`. If `p` corresponds to the Taylor series of a function, then `p.shift` is the Taylor series of the derivative of the function. -/ def shift : formal_multilinear_series π•œ E (E β†’L[π•œ] F) := Ξ»n, (p n.succ).curry_right /-- Adding a zeroth term to a formal multilinear series taking values in `E β†’L[π•œ] F`. This corresponds to starting from a Taylor series for the derivative of a function, and building a Taylor series for the function itself. -/ def unshift (q : formal_multilinear_series π•œ E (E β†’L[π•œ] F)) (z : F) : formal_multilinear_series π•œ E F | 0 := (continuous_multilinear_curry_fin0 π•œ E F).symm z | (n + 1) := (continuous_multilinear_curry_right_equiv π•œ (Ξ» (i : fin (n + 1)), E) F) (q n) /-- Convenience congruence lemma stating in a dependent setting that, if the arguments to a formal multilinear series are equal, then the values are also equal. -/ lemma congr (p : formal_multilinear_series π•œ E F) {m n : β„•} {v : fin m β†’ E} {w : fin n β†’ E} (h1 : m = n) (h2 : βˆ€ (i : β„•) (him : i < m) (hin : i < n), v ⟨i, him⟩ = w ⟨i, hin⟩) : p m v = p n w := by { cases h1, congr' with ⟨i, hi⟩, exact h2 i hi hi } end formal_multilinear_series /-! ### Functions with a Taylor series on a domain -/ variable {p : E β†’ formal_multilinear_series π•œ E F} /-- `has_ftaylor_series_up_to_on n f p s` registers the fact that `p 0 = f` and `p (m+1)` is a derivative of `p m` for `m < n`, and is continuous for `m ≀ n`. This is a predicate analogous to `has_fderiv_within_at` but for higher order derivatives. -/ structure has_ftaylor_series_up_to_on (n : with_top β„•) (f : E β†’ F) (p : E β†’ formal_multilinear_series π•œ E F) (s : set E) : Prop := (zero_eq : βˆ€ x ∈ s, (p x 0).uncurry0 = f x) (fderiv_within : βˆ€ (m : β„•) (hm : (m : with_top β„•) < n), βˆ€ x ∈ s, has_fderiv_within_at (Ξ» y, p y m) (p x m.succ).curry_left s x) (cont : βˆ€ (m : β„•) (hm : (m : with_top β„•) ≀ n), continuous_on (Ξ» x, p x m) s) lemma has_ftaylor_series_up_to_on.zero_eq' {n : with_top β„•} (h : has_ftaylor_series_up_to_on n f p s) {x : E} (hx : x ∈ s) : p x 0 = (continuous_multilinear_curry_fin0 π•œ E F).symm (f x) := by { rw ← h.zero_eq x hx, symmetry, exact continuous_multilinear_map.uncurry0_curry0 _ } /-- If two functions coincide on a set `s`, then a Taylor series for the first one is as well a Taylor series for the second one. -/ lemma has_ftaylor_series_up_to_on.congr {n : with_top β„•} (h : has_ftaylor_series_up_to_on n f p s) (h₁ : βˆ€ x ∈ s, f₁ x = f x) : has_ftaylor_series_up_to_on n f₁ p s := begin refine ⟨λ x hx, _, h.fderiv_within, h.cont⟩, rw h₁ x hx, exact h.zero_eq x hx end lemma has_ftaylor_series_up_to_on.mono {n : with_top β„•} (h : has_ftaylor_series_up_to_on n f p s) {t : set E} (hst : t βŠ† s) : has_ftaylor_series_up_to_on n f p t := ⟨λ x hx, h.zero_eq x (hst hx), Ξ» m hm x hx, (h.fderiv_within m hm x (hst hx)).mono hst, Ξ» m hm, (h.cont m hm).mono hst⟩ lemma has_ftaylor_series_up_to_on.of_le {m n : with_top β„•} (h : has_ftaylor_series_up_to_on n f p s) (hmn : m ≀ n) : has_ftaylor_series_up_to_on m f p s := ⟨h.zero_eq, Ξ» k hk x hx, h.fderiv_within k (lt_of_lt_of_le hk hmn) x hx, Ξ» k hk, h.cont k (le_trans hk hmn)⟩ lemma has_ftaylor_series_up_to_on.continuous_on {n : with_top β„•} (h : has_ftaylor_series_up_to_on n f p s) : continuous_on f s := begin have := (h.cont 0 bot_le).congr (Ξ» x hx, (h.zero_eq' hx).symm), rwa continuous_linear_equiv.comp_continuous_on_iff at this end lemma has_ftaylor_series_up_to_on_zero_iff : has_ftaylor_series_up_to_on 0 f p s ↔ continuous_on f s ∧ (βˆ€ x ∈ s, (p x 0).uncurry0 = f x) := begin refine ⟨λ H, ⟨H.continuous_on, H.zero_eq⟩, Ξ» H, ⟨H.2, Ξ» m hm, false.elim (not_le.2 hm bot_le), _⟩⟩, assume m hm, have : (m : with_top β„•) = ((0 : β„•) : with_bot β„•) := le_antisymm hm bot_le, rw with_top.coe_eq_coe at this, rw this, have : βˆ€ x ∈ s, p x 0 = (continuous_multilinear_curry_fin0 π•œ E F).symm (f x), by { assume x hx, rw ← H.2 x hx, symmetry, exact continuous_multilinear_map.uncurry0_curry0 _ }, rw [continuous_on_congr this, continuous_linear_equiv.comp_continuous_on_iff], exact H.1 end lemma has_ftaylor_series_up_to_on_top_iff : (has_ftaylor_series_up_to_on ∞ f p s) ↔ (βˆ€ (n : β„•), has_ftaylor_series_up_to_on n f p s) := begin split, { assume H n, exact H.of_le le_top }, { assume H, split, { exact (H 0).zero_eq }, { assume m hm, apply (H m.succ).fderiv_within m (with_top.coe_lt_coe.2 (lt_add_one m)) }, { assume m hm, apply (H m).cont m (le_refl _) } } end /-- If a function has a Taylor series at order at least `1`, then the term of order `1` of this series is a derivative of `f`. -/ lemma has_ftaylor_series_up_to_on.has_fderiv_within_at {n : with_top β„•} (h : has_ftaylor_series_up_to_on n f p s) (hn : 1 ≀ n) (hx : x ∈ s) : has_fderiv_within_at f (continuous_multilinear_curry_fin1 π•œ E F (p x 1)) s x := begin have A : βˆ€ y ∈ s, f y = (continuous_multilinear_curry_fin0 π•œ E F) (p y 0), { assume y hy, rw ← h.zero_eq y hy, refl }, suffices H : has_fderiv_within_at (Ξ» y, continuous_multilinear_curry_fin0 π•œ E F (p y 0)) (continuous_multilinear_curry_fin1 π•œ E F (p x 1)) s x, by exact H.congr A (A x hx), rw continuous_linear_equiv.comp_has_fderiv_within_at_iff', have : ((0 : β„•) : with_top β„•) < n := lt_of_lt_of_le (with_top.coe_lt_coe.2 nat.zero_lt_one) hn, convert h.fderiv_within _ this x hx, ext y v, change (p x 1) (snoc 0 y) = (p x 1) (cons y v), unfold_coes, congr' with i, have : i = 0 := subsingleton.elim i 0, rw this, refl end lemma has_ftaylor_series_up_to_on.differentiable_on {n : with_top β„•} (h : has_ftaylor_series_up_to_on n f p s) (hn : 1 ≀ n) : differentiable_on π•œ f s := Ξ» x hx, (h.has_fderiv_within_at hn hx).differentiable_within_at /-- `p` is a Taylor series of `f` up to `n+1` if and only if `p` is a Taylor series up to `n`, and `p (n + 1)` is a derivative of `p n`. -/ theorem has_ftaylor_series_up_to_on_succ_iff_left {n : β„•} : has_ftaylor_series_up_to_on (n + 1) f p s ↔ has_ftaylor_series_up_to_on n f p s ∧ (βˆ€ x ∈ s, has_fderiv_within_at (Ξ» y, p y n) (p x n.succ).curry_left s x) ∧ continuous_on (Ξ» x, p x (n + 1)) s := begin split, { assume h, exact ⟨h.of_le (with_top.coe_le_coe.2 (nat.le_succ n)), h.fderiv_within _ (with_top.coe_lt_coe.2 (lt_add_one n)), h.cont (n + 1) (le_refl _)⟩ }, { assume h, split, { exact h.1.zero_eq }, { assume m hm, by_cases h' : m < n, { exact h.1.fderiv_within m (with_top.coe_lt_coe.2 h') }, { have : m = n := nat.eq_of_lt_succ_of_not_lt (with_top.coe_lt_coe.1 hm) h', rw this, exact h.2.1 } }, { assume m hm, by_cases h' : m ≀ n, { apply h.1.cont m (with_top.coe_le_coe.2 h') }, { have : m = (n + 1) := le_antisymm (with_top.coe_le_coe.1 hm) (not_le.1 h'), rw this, exact h.2.2 } } } end /-- `p` is a Taylor series of `f` up to `n+1` if and only if `p.shift` is a Taylor series up to `n` for `p 1`, which is a derivative of `f`. -/ theorem has_ftaylor_series_up_to_on_succ_iff_right {n : β„•} : has_ftaylor_series_up_to_on ((n + 1) : β„•) f p s ↔ (βˆ€ x ∈ s, (p x 0).uncurry0 = f x) ∧ (βˆ€ x ∈ s, has_fderiv_within_at (Ξ» y, p y 0) (p x 1).curry_left s x) ∧ has_ftaylor_series_up_to_on n (Ξ» x, continuous_multilinear_curry_fin1 π•œ E F (p x 1)) (Ξ» x, (p x).shift) s := begin split, { assume H, refine ⟨H.zero_eq, H.fderiv_within 0 (with_top.coe_lt_coe.2 (nat.succ_pos n)), _⟩, split, { assume x hx, refl }, { assume m (hm : (m : with_top β„•) < n) x (hx : x ∈ s), have A : (m.succ : with_top β„•) < n.succ, by { rw with_top.coe_lt_coe at ⊒ hm, exact nat.lt_succ_iff.mpr hm }, change has_fderiv_within_at ((continuous_multilinear_curry_right_equiv π•œ (Ξ» i : fin m.succ, E) F).symm ∘ (Ξ» (y : E), p y m.succ)) (p x m.succ.succ).curry_right.curry_left s x, rw continuous_linear_equiv.comp_has_fderiv_within_at_iff', convert H.fderiv_within _ A x hx, ext y v, change (p x m.succ.succ) (snoc (cons y (init v)) (v (last _))) = (p x (nat.succ (nat.succ m))) (cons y v), rw [← cons_snoc_eq_snoc_cons, snoc_init_self] }, { assume m (hm : (m : with_top β„•) ≀ n), have A : (m.succ : with_top β„•) ≀ n.succ, by { rw with_top.coe_le_coe at ⊒ hm, exact nat.pred_le_iff.mp hm }, change continuous_on ((continuous_multilinear_curry_right_equiv π•œ (Ξ» i : fin m.succ, E) F).symm ∘ (Ξ» (y : E), p y m.succ)) s, rw continuous_linear_equiv.comp_continuous_on_iff, exact H.cont _ A } }, { rintros ⟨Hzero_eq, Hfderiv_zero, Htaylor⟩, split, { exact Hzero_eq }, { assume m (hm : (m : with_top β„•) < n.succ) x (hx : x ∈ s), cases m, { exact Hfderiv_zero x hx }, { have A : (m : with_top β„•) < n, by { rw with_top.coe_lt_coe at hm ⊒, exact nat.lt_of_succ_lt_succ hm }, have : has_fderiv_within_at ((continuous_multilinear_curry_right_equiv π•œ (Ξ» i : fin m.succ, E) F).symm ∘ (Ξ» (y : E), p y m.succ)) ((p x).shift m.succ).curry_left s x := Htaylor.fderiv_within _ A x hx, rw continuous_linear_equiv.comp_has_fderiv_within_at_iff' at this, convert this, ext y v, change (p x (nat.succ (nat.succ m))) (cons y v) = (p x m.succ.succ) (snoc (cons y (init v)) (v (last _))), rw [← cons_snoc_eq_snoc_cons, snoc_init_self] } }, { assume m (hm : (m : with_top β„•) ≀ n.succ), cases m, { have : differentiable_on π•œ (Ξ» x, p x 0) s := Ξ» x hx, (Hfderiv_zero x hx).differentiable_within_at, exact this.continuous_on }, { have A : (m : with_top β„•) ≀ n, by { rw with_top.coe_le_coe at hm ⊒, exact nat.lt_succ_iff.mp hm }, have : continuous_on ((continuous_multilinear_curry_right_equiv π•œ (Ξ» i : fin m.succ, E) F).symm ∘ (Ξ» (y : E), p y m.succ)) s := Htaylor.cont _ A, rwa continuous_linear_equiv.comp_continuous_on_iff at this } } } end /-! ### Smooth functions within a set around a point -/ variable (π•œ) /-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s βˆͺ {x}`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not better, is `C^∞` at `0` within `univ`. -/ def times_cont_diff_within_at (n : with_top β„•) (f : E β†’ F) (s : set E) (x : E) := βˆ€ (m : β„•), (m : with_top β„•) ≀ n β†’ βˆƒ u ∈ 𝓝[insert x s] x, βˆƒ p : E β†’ formal_multilinear_series π•œ E F, has_ftaylor_series_up_to_on m f p u variable {π•œ} lemma times_cont_diff_within_at_nat {n : β„•} : times_cont_diff_within_at π•œ n f s x ↔ βˆƒ u ∈ 𝓝[insert x s] x, βˆƒ p : E β†’ formal_multilinear_series π•œ E F, has_ftaylor_series_up_to_on n f p u := ⟨λ H, H n (le_refl _), Ξ» ⟨u, hu, p, hp⟩ m hm, ⟨u, hu, p, hp.of_le hm⟩⟩ lemma times_cont_diff_within_at_top : times_cont_diff_within_at π•œ ∞ f s x ↔ βˆ€ (n : β„•), times_cont_diff_within_at π•œ n f s x := begin split, { assume H n m hm, rcases H m le_top with ⟨u, hu, p, hp⟩, exact ⟨u, hu, p, hp⟩ }, { assume H m hm, rcases H m m (le_refl _) with ⟨u, hu, p, hp⟩, exact ⟨u, hu, p, hp⟩ } end lemma times_cont_diff_within_at.continuous_within_at' {n : with_top β„•} (h : times_cont_diff_within_at π•œ n f s x) : continuous_within_at f (insert x s) x := begin rcases h 0 bot_le with ⟨u, hu, p, H⟩, rcases mem_nhds_within.1 hu with ⟨t, t_open, xt, tu⟩, have A : x ∈ t ∩ insert x s, by simp [xt], have := (H.mono tu).continuous_on.continuous_within_at A, rw inter_comm at this, exact (continuous_within_at_inter (mem_nhds_sets t_open xt)).1 this end lemma times_cont_diff_within_at.continuous_within_at {n : with_top β„•} (h : times_cont_diff_within_at π•œ n f s x) : continuous_within_at f s x := (h.continuous_within_at').mono (subset_insert x s) lemma times_cont_diff_within_at.congr_of_eventually_eq {n : with_top β„•} (h : times_cont_diff_within_at π•œ n f s x) (h₁ : f₁ =αΆ [𝓝[s] x] f) (hx : f₁ x = f x) : times_cont_diff_within_at π•œ n f₁ s x := begin assume m hm, rcases h m hm with ⟨u, hu, p, H⟩, rcases h₁.exists_mem with ⟨v, v_neighb, hv⟩, refine ⟨u ∩ ((insert x v) ∩ (insert x s)), _, p, _⟩, { exact filter.inter_mem_sets hu (filter.inter_mem_sets (mem_nhds_within_insert v_neighb) self_mem_nhds_within) }, { apply (H.mono (inter_subset_left u _)).congr (Ξ» y hy, _), simp at hy, rcases hy.2.1 with rfl|hy', { exact hx }, { exact hv hy' } } end lemma times_cont_diff_within_at.congr_of_eventually_eq' {n : with_top β„•} (h : times_cont_diff_within_at π•œ n f s x) (h₁ : f₁ =αΆ [𝓝[s] x] f) (hx : x ∈ s) : times_cont_diff_within_at π•œ n f₁ s x := begin apply h.congr_of_eventually_eq h₁, rcases h₁.exists_mem with ⟨t, ht, t_eq⟩, exact t_eq (mem_of_mem_nhds_within hx ht) end lemma filter.eventually_eq.times_cont_diff_within_at_iff {n : with_top β„•} (h₁ : f₁ =αΆ [𝓝[s] x] f) (hx : f₁ x = f x) : times_cont_diff_within_at π•œ n f₁ s x ↔ times_cont_diff_within_at π•œ n f s x := ⟨λ H, times_cont_diff_within_at.congr_of_eventually_eq H h₁.symm hx.symm, Ξ» H, H.congr_of_eventually_eq h₁ hx⟩ lemma times_cont_diff_within_at.congr {n : with_top β„•} (h : times_cont_diff_within_at π•œ n f s x) (h₁ : βˆ€ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : times_cont_diff_within_at π•œ n f₁ s x := h.congr_of_eventually_eq (filter.eventually_eq_of_mem self_mem_nhds_within h₁) hx lemma times_cont_diff_within_at.mono {n : with_top β„•} (h : times_cont_diff_within_at π•œ n f s x) {t : set E} (hst : t βŠ† s) : times_cont_diff_within_at π•œ n f t x := begin assume m hm, rcases h m hm with ⟨u, hu, p, H⟩, exact ⟨u, nhds_within_mono _ (insert_subset_insert hst) hu, p, H⟩, end lemma times_cont_diff_within_at.of_le {m n : with_top β„•} (h : times_cont_diff_within_at π•œ n f s x) (hmn : m ≀ n) : times_cont_diff_within_at π•œ m f s x := Ξ» k hk, h k (le_trans hk hmn) lemma times_cont_diff_within_at_inter' {n : with_top β„•} (h : t ∈ 𝓝[s] x) : times_cont_diff_within_at π•œ n f (s ∩ t) x ↔ times_cont_diff_within_at π•œ n f s x := begin refine ⟨λ H m hm, _, Ξ» H, H.mono (inter_subset_left _ _)⟩, rcases H m hm with ⟨u, u_nhbd, p, hu⟩, refine ⟨(insert x s ∩ insert x t) ∩ u, _, p, hu.mono (inter_subset_right _ _)⟩, rw nhds_within_restrict'' (insert x s) (mem_nhds_within_insert h), rw insert_inter at u_nhbd, exact filter.inter_mem_sets self_mem_nhds_within u_nhbd end lemma times_cont_diff_within_at_inter {n : with_top β„•} (h : t ∈ 𝓝 x) : times_cont_diff_within_at π•œ n f (s ∩ t) x ↔ times_cont_diff_within_at π•œ n f s x := times_cont_diff_within_at_inter' (mem_nhds_within_of_mem_nhds h) /-- If a function is `C^n` within a set at a point, with `n β‰₯ 1`, then it is differentiable within this set at this point. -/ lemma times_cont_diff_within_at.differentiable_within_at' {n : with_top β„•} (h : times_cont_diff_within_at π•œ n f s x) (hn : 1 ≀ n) : differentiable_within_at π•œ f (insert x s) x := begin rcases h 1 hn with ⟨u, hu, p, H⟩, rcases mem_nhds_within.1 hu with ⟨t, t_open, xt, tu⟩, rw inter_comm at tu, have := ((H.mono tu).differentiable_on (le_refl _)) x ⟨mem_insert x s, xt⟩, exact (differentiable_within_at_inter (mem_nhds_sets t_open xt)).1 this, end lemma times_cont_diff_within_at.differentiable_within_at {n : with_top β„•} (h : times_cont_diff_within_at π•œ n f s x) (hn : 1 ≀ n) : differentiable_within_at π•œ f s x := (h.differentiable_within_at' hn).mono (subset_insert x s) /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/ theorem times_cont_diff_within_at_succ_iff_has_fderiv_within_at {n : β„•} : times_cont_diff_within_at π•œ ((n + 1) : β„•) f s x ↔ βˆƒ u ∈ 𝓝[insert x s] x, βˆƒ f' : E β†’ (E β†’L[π•œ] F), (βˆ€ x ∈ u, has_fderiv_within_at f (f' x) u x) ∧ (times_cont_diff_within_at π•œ n f' u x) := begin split, { assume h, rcases h n.succ (le_refl _) with ⟨u, hu, p, Hp⟩, refine ⟨u, hu, Ξ» y, (continuous_multilinear_curry_fin1 π•œ E F) (p y 1), Ξ» y hy, Hp.has_fderiv_within_at (with_top.coe_le_coe.2 (nat.le_add_left 1 n)) hy, _⟩, assume m hm, refine ⟨u, _, Ξ» (y : E), (p y).shift, _⟩, { convert self_mem_nhds_within, have : x ∈ insert x s, by simp, exact (insert_eq_of_mem (mem_of_mem_nhds_within this hu)) }, { rw has_ftaylor_series_up_to_on_succ_iff_right at Hp, exact Hp.2.2.of_le hm } }, { rintros ⟨u, hu, f', f'_eq_deriv, Hf'⟩, rw times_cont_diff_within_at_nat, rcases Hf' n (le_refl _) with ⟨v, hv, p', Hp'⟩, refine ⟨v ∩ u, _, Ξ» x, (p' x).unshift (f x), _⟩, { apply filter.inter_mem_sets _ hu, apply nhds_within_le_of_mem hu, exact nhds_within_mono _ (subset_insert x u) hv }, { rw has_ftaylor_series_up_to_on_succ_iff_right, refine ⟨λ y hy, rfl, Ξ» y hy, _, _⟩, { change has_fderiv_within_at (Ξ» (z : E), (continuous_multilinear_curry_fin0 π•œ E F).symm (f z)) ((formal_multilinear_series.unshift (p' y) (f y) 1).curry_left) (v ∩ u) y, rw continuous_linear_equiv.comp_has_fderiv_within_at_iff', convert (f'_eq_deriv y hy.2).mono (inter_subset_right v u), rw ← Hp'.zero_eq y hy.1, ext z, change ((p' y 0) (init (@cons 0 (Ξ» i, E) z 0))) (@cons 0 (Ξ» i, E) z 0 (last 0)) = ((p' y 0) 0) z, unfold_coes, congr }, { convert (Hp'.mono (inter_subset_left v u)).congr (Ξ» x hx, Hp'.zero_eq x hx.1), { ext x y, change p' x 0 (init (@snoc 0 (Ξ» i : fin 1, E) 0 y)) y = p' x 0 0 y, rw init_snoc }, { ext x k v y, change p' x k (init (@snoc k (Ξ» i : fin k.succ, E) v y)) (@snoc k (Ξ» i : fin k.succ, E) v y (last k)) = p' x k v y, rw [snoc_last, init_snoc] } } } } end /-! ### Smooth functions within a set -/ variable (π•œ) /-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). -/ definition times_cont_diff_on (n : with_top β„•) (f : E β†’ F) (s : set E) := βˆ€ x ∈ s, times_cont_diff_within_at π•œ n f s x variable {π•œ} lemma times_cont_diff_on.times_cont_diff_within_at {n : with_top β„•} (h : times_cont_diff_on π•œ n f s) (hx : x ∈ s) : times_cont_diff_within_at π•œ n f s x := h x hx lemma times_cont_diff_within_at.times_cont_diff_on {n : with_top β„•} {m : β„•} (hm : (m : with_top β„•) ≀ n) (h : times_cont_diff_within_at π•œ n f s x) : βˆƒ u ∈ 𝓝[insert x s] x, u βŠ† insert x s ∧ times_cont_diff_on π•œ m f u := begin rcases h m hm with ⟨u, u_nhd, p, hp⟩, refine ⟨u ∩ insert x s, filter.inter_mem_sets u_nhd self_mem_nhds_within, inter_subset_right _ _, _⟩, assume y hy m' hm', refine ⟨u ∩ insert x s, _, p, (hp.mono (inter_subset_left _ _)).of_le hm'⟩, convert self_mem_nhds_within, exact insert_eq_of_mem hy end lemma times_cont_diff_on_top : times_cont_diff_on π•œ ∞ f s ↔ βˆ€ (n : β„•), times_cont_diff_on π•œ n f s := by { simp [times_cont_diff_on, times_cont_diff_within_at_top], tauto } lemma times_cont_diff_on.continuous_on {n : with_top β„•} (h : times_cont_diff_on π•œ n f s) : continuous_on f s := Ξ» x hx, (h x hx).continuous_within_at lemma times_cont_diff_on.congr {n : with_top β„•} (h : times_cont_diff_on π•œ n f s) (h₁ : βˆ€ x ∈ s, f₁ x = f x) : times_cont_diff_on π•œ n f₁ s := Ξ» x hx, (h x hx).congr h₁ (h₁ x hx) lemma times_cont_diff_on_congr {n : with_top β„•} (h₁ : βˆ€ x ∈ s, f₁ x = f x) : times_cont_diff_on π•œ n f₁ s ↔ times_cont_diff_on π•œ n f s := ⟨λ H, H.congr (Ξ» x hx, (h₁ x hx).symm), Ξ» H, H.congr hβ‚βŸ© lemma times_cont_diff_on.mono {n : with_top β„•} (h : times_cont_diff_on π•œ n f s) {t : set E} (hst : t βŠ† s) : times_cont_diff_on π•œ n f t := Ξ» x hx, (h x (hst hx)).mono hst lemma times_cont_diff_on.congr_mono {n : with_top β„•} (hf : times_cont_diff_on π•œ n f s) (h₁ : βˆ€ x ∈ s₁, f₁ x = f x) (hs : s₁ βŠ† s) : times_cont_diff_on π•œ n f₁ s₁ := (hf.mono hs).congr h₁ lemma times_cont_diff_on.of_le {m n : with_top β„•} (h : times_cont_diff_on π•œ n f s) (hmn : m ≀ n) : times_cont_diff_on π•œ m f s := Ξ» x hx, (h x hx).of_le hmn /-- If a function is `C^n` on a set with `n β‰₯ 1`, then it is differentiable there. -/ lemma times_cont_diff_on.differentiable_on {n : with_top β„•} (h : times_cont_diff_on π•œ n f s) (hn : 1 ≀ n) : differentiable_on π•œ f s := Ξ» x hx, (h x hx).differentiable_within_at hn /-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/ lemma times_cont_diff_on_of_locally_times_cont_diff_on {n : with_top β„•} (h : βˆ€ x ∈ s, βˆƒu, is_open u ∧ x ∈ u ∧ times_cont_diff_on π•œ n f (s ∩ u)) : times_cont_diff_on π•œ n f s := begin assume x xs, rcases h x xs with ⟨u, u_open, xu, hu⟩, apply (times_cont_diff_within_at_inter _).1 (hu x ⟨xs, xu⟩), exact mem_nhds_sets u_open xu end /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/ theorem times_cont_diff_on_succ_iff_has_fderiv_within_at {n : β„•} : times_cont_diff_on π•œ ((n + 1) : β„•) f s ↔ βˆ€ x ∈ s, βˆƒ u ∈ 𝓝[insert x s] x, βˆƒ f' : E β†’ (E β†’L[π•œ] F), (βˆ€ x ∈ u, has_fderiv_within_at f (f' x) u x) ∧ (times_cont_diff_on π•œ n f' u) := begin split, { assume h x hx, rcases (h x hx) n.succ (le_refl _) with ⟨u, hu, p, Hp⟩, refine ⟨u, hu, Ξ» y, (continuous_multilinear_curry_fin1 π•œ E F) (p y 1), Ξ» y hy, Hp.has_fderiv_within_at (with_top.coe_le_coe.2 (nat.le_add_left 1 n)) hy, _⟩, rw has_ftaylor_series_up_to_on_succ_iff_right at Hp, assume z hz m hm, refine ⟨u, _, Ξ» (x : E), (p x).shift, Hp.2.2.of_le hm⟩, convert self_mem_nhds_within, exact insert_eq_of_mem hz, }, { assume h x hx, rw times_cont_diff_within_at_succ_iff_has_fderiv_within_at, rcases h x hx with ⟨u, u_nhbd, f', hu, hf'⟩, have : x ∈ u := mem_of_mem_nhds_within (mem_insert _ _) u_nhbd, exact ⟨u, u_nhbd, f', hu, hf' x this⟩ } end /-! ### Iterated derivative within a set -/ variable (π•œ) /-- The `n`-th derivative of a function along a set, defined inductively by saying that the `n+1`-th derivative of `f` is the derivative of the `n`-th derivative of `f` along this set, together with an uncurrying step to see it as a multilinear map in `n+1` variables.. -/ noncomputable def iterated_fderiv_within (n : β„•) (f : E β†’ F) (s : set E) : E β†’ (E [Γ—n]β†’L[π•œ] F) := nat.rec_on n (Ξ» x, continuous_multilinear_map.curry0 π•œ E (f x)) (Ξ» n rec x, continuous_linear_map.uncurry_left (fderiv_within π•œ rec s x)) /-- Formal Taylor series associated to a function within a set. -/ def ftaylor_series_within (f : E β†’ F) (s : set E) (x : E) : formal_multilinear_series π•œ E F := Ξ» n, iterated_fderiv_within π•œ n f s x variable {π•œ} @[simp] lemma iterated_fderiv_within_zero_apply (m : (fin 0) β†’ E) : (iterated_fderiv_within π•œ 0 f s x : ((fin 0) β†’ E) β†’ F) m = f x := rfl lemma iterated_fderiv_within_zero_eq_comp : iterated_fderiv_within π•œ 0 f s = (continuous_multilinear_curry_fin0 π•œ E F).symm ∘ f := rfl lemma iterated_fderiv_within_succ_apply_left {n : β„•} (m : fin (n + 1) β†’ E): (iterated_fderiv_within π•œ (n + 1) f s x : (fin (n + 1) β†’ E) β†’ F) m = (fderiv_within π•œ (iterated_fderiv_within π•œ n f s) s x : E β†’ (E [Γ—n]β†’L[π•œ] F)) (m 0) (tail m) := rfl /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the derivative of the `n`-th derivative. -/ lemma iterated_fderiv_within_succ_eq_comp_left {n : β„•} : iterated_fderiv_within π•œ (n + 1) f s = (continuous_multilinear_curry_left_equiv π•œ (Ξ»(i : fin (n + 1)), E) F) ∘ (fderiv_within π•œ (iterated_fderiv_within π•œ n f s) s) := rfl theorem iterated_fderiv_within_succ_apply_right {n : β„•} (hs : unique_diff_on π•œ s) (hx : x ∈ s) (m : fin (n + 1) β†’ E) : (iterated_fderiv_within π•œ (n + 1) f s x : (fin (n + 1) β†’ E) β†’ F) m = iterated_fderiv_within π•œ n (Ξ»y, fderiv_within π•œ f s y) s x (init m) (m (last n)) := begin induction n with n IH generalizing x, { rw [iterated_fderiv_within_succ_eq_comp_left, iterated_fderiv_within_zero_eq_comp, iterated_fderiv_within_zero_apply, function.comp_apply, continuous_linear_equiv.comp_fderiv_within _ (hs x hx)], refl }, { let I := (continuous_multilinear_curry_right_equiv π•œ (Ξ» (i : fin (n + 1)), E) F), have A : βˆ€ y ∈ s, iterated_fderiv_within π•œ n.succ f s y = (I ∘ (iterated_fderiv_within π•œ n (Ξ»y, fderiv_within π•œ f s y) s)) y, by { assume y hy, ext m, rw @IH m y hy, refl }, calc (iterated_fderiv_within π•œ (n+2) f s x : (fin (n+2) β†’ E) β†’ F) m = (fderiv_within π•œ (iterated_fderiv_within π•œ n.succ f s) s x : E β†’ (E [Γ—(n + 1)]β†’L[π•œ] F)) (m 0) (tail m) : rfl ... = (fderiv_within π•œ (I ∘ (iterated_fderiv_within π•œ n (fderiv_within π•œ f s) s)) s x : E β†’ (E [Γ—(n + 1)]β†’L[π•œ] F)) (m 0) (tail m) : by rw fderiv_within_congr (hs x hx) A (A x hx) ... = (I ∘ fderiv_within π•œ ((iterated_fderiv_within π•œ n (fderiv_within π•œ f s) s)) s x : E β†’ (E [Γ—(n + 1)]β†’L[π•œ] F)) (m 0) (tail m) : by { rw continuous_linear_equiv.comp_fderiv_within _ (hs x hx), refl } ... = (fderiv_within π•œ ((iterated_fderiv_within π•œ n (Ξ» y, fderiv_within π•œ f s y) s)) s x : E β†’ (E [Γ—n]β†’L[π•œ] (E β†’L[π•œ] F))) (m 0) (init (tail m)) ((tail m) (last n)) : rfl ... = iterated_fderiv_within π•œ (nat.succ n) (Ξ» y, fderiv_within π•œ f s y) s x (init m) (m (last (n + 1))) : by { rw [iterated_fderiv_within_succ_apply_left, tail_init_eq_init_tail], refl } } end /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the `n`-th derivative of the derivative. -/ lemma iterated_fderiv_within_succ_eq_comp_right {n : β„•} (hs : unique_diff_on π•œ s) (hx : x ∈ s) : iterated_fderiv_within π•œ (n + 1) f s x = ((continuous_multilinear_curry_right_equiv π•œ (Ξ»(i : fin (n + 1)), E) F) ∘ (iterated_fderiv_within π•œ n (Ξ»y, fderiv_within π•œ f s y) s)) x := by { ext m, rw iterated_fderiv_within_succ_apply_right hs hx, refl } @[simp] lemma iterated_fderiv_within_one_apply (hs : unique_diff_on π•œ s) (hx : x ∈ s) (m : (fin 1) β†’ E) : (iterated_fderiv_within π•œ 1 f s x : ((fin 1) β†’ E) β†’ F) m = (fderiv_within π•œ f s x : E β†’ F) (m 0) := by { rw [iterated_fderiv_within_succ_apply_right hs hx, iterated_fderiv_within_zero_apply], refl } /-- If two functions coincide on a set `s` of unique differentiability, then their iterated differentials within this set coincide. -/ lemma iterated_fderiv_within_congr {n : β„•} (hs : unique_diff_on π•œ s) (hL : βˆ€y∈s, f₁ y = f y) (hx : x ∈ s) : iterated_fderiv_within π•œ n f₁ s x = iterated_fderiv_within π•œ n f s x := begin induction n with n IH generalizing x, { ext m, simp [hL x hx] }, { have : fderiv_within π•œ (Ξ» y, iterated_fderiv_within π•œ n f₁ s y) s x = fderiv_within π•œ (Ξ» y, iterated_fderiv_within π•œ n f s y) s x := fderiv_within_congr (hs x hx) (Ξ» y hy, IH hy) (IH hx), ext m, rw [iterated_fderiv_within_succ_apply_left, iterated_fderiv_within_succ_apply_left, this] } end /-- The iterated differential within a set `s` at a point `x` is not modified if one intersects `s` with an open set containing `x`. -/ lemma iterated_fderiv_within_inter_open {n : β„•} (hu : is_open u) (hs : unique_diff_on π•œ (s ∩ u)) (hx : x ∈ s ∩ u) : iterated_fderiv_within π•œ n f (s ∩ u) x = iterated_fderiv_within π•œ n f s x := begin induction n with n IH generalizing x, { ext m, simp }, { have A : fderiv_within π•œ (Ξ» y, iterated_fderiv_within π•œ n f (s ∩ u) y) (s ∩ u) x = fderiv_within π•œ (Ξ» y, iterated_fderiv_within π•œ n f s y) (s ∩ u) x := fderiv_within_congr (hs x hx) (Ξ» y hy, IH hy) (IH hx), have B : fderiv_within π•œ (Ξ» y, iterated_fderiv_within π•œ n f s y) (s ∩ u) x = fderiv_within π•œ (Ξ» y, iterated_fderiv_within π•œ n f s y) s x := fderiv_within_inter (mem_nhds_sets hu hx.2) ((unique_diff_within_at_inter (mem_nhds_sets hu hx.2)).1 (hs x hx)), ext m, rw [iterated_fderiv_within_succ_apply_left, iterated_fderiv_within_succ_apply_left, A, B] } end /-- The iterated differential within a set `s` at a point `x` is not modified if one intersects `s` with a neighborhood of `x` within `s`. -/ lemma iterated_fderiv_within_inter' {n : β„•} (hu : u ∈ 𝓝[s] x) (hs : unique_diff_on π•œ s) (xs : x ∈ s) : iterated_fderiv_within π•œ n f (s ∩ u) x = iterated_fderiv_within π•œ n f s x := begin obtain ⟨v, v_open, xv, vu⟩ : βˆƒ v, is_open v ∧ x ∈ v ∧ v ∩ s βŠ† u := mem_nhds_within.1 hu, have A : (s ∩ u) ∩ v = s ∩ v, { apply subset.antisymm (inter_subset_inter (inter_subset_left _ _) (subset.refl _)), exact Ξ» y ⟨ys, yv⟩, ⟨⟨ys, vu ⟨yv, ys⟩⟩, yv⟩ }, have : iterated_fderiv_within π•œ n f (s ∩ v) x = iterated_fderiv_within π•œ n f s x := iterated_fderiv_within_inter_open v_open (hs.inter v_open) ⟨xs, xv⟩, rw ← this, have : iterated_fderiv_within π•œ n f ((s ∩ u) ∩ v) x = iterated_fderiv_within π•œ n f (s ∩ u) x, { refine iterated_fderiv_within_inter_open v_open _ ⟨⟨xs, vu ⟨xv, xs⟩⟩, xv⟩, rw A, exact hs.inter v_open }, rw A at this, rw ← this end /-- The iterated differential within a set `s` at a point `x` is not modified if one intersects `s` with a neighborhood of `x`. -/ lemma iterated_fderiv_within_inter {n : β„•} (hu : u ∈ 𝓝 x) (hs : unique_diff_on π•œ s) (xs : x ∈ s) : iterated_fderiv_within π•œ n f (s ∩ u) x = iterated_fderiv_within π•œ n f s x := iterated_fderiv_within_inter' (mem_nhds_within_of_mem_nhds hu) hs xs @[simp] lemma times_cont_diff_on_zero : times_cont_diff_on π•œ 0 f s ↔ continuous_on f s := begin refine ⟨λ H, H.continuous_on, Ξ» H, _⟩, assume x hx m hm, have : (m : with_top β„•) = 0 := le_antisymm hm bot_le, rw this, refine ⟨insert x s, self_mem_nhds_within, ftaylor_series_within π•œ f s, _⟩, rw has_ftaylor_series_up_to_on_zero_iff, exact ⟨by rwa insert_eq_of_mem hx, Ξ» x hx, by simp [ftaylor_series_within]⟩ end /-- On a set with unique differentiability, any choice of iterated differential has to coincide with the one we have chosen in `iterated_fderiv_within π•œ m f s`. -/ theorem has_ftaylor_series_up_to_on.eq_ftaylor_series_of_unique_diff_on {n : with_top β„•} (h : has_ftaylor_series_up_to_on n f p s) {m : β„•} (hmn : (m : with_top β„•) ≀ n) (hs : unique_diff_on π•œ s) (hx : x ∈ s) : p x m = iterated_fderiv_within π•œ m f s x := begin induction m with m IH generalizing x, { rw [h.zero_eq' hx, iterated_fderiv_within_zero_eq_comp] }, { have A : (m : with_top β„•) < n := lt_of_lt_of_le (with_top.coe_lt_coe.2 (lt_add_one m)) hmn, have : has_fderiv_within_at (Ξ» (y : E), iterated_fderiv_within π•œ m f s y) (continuous_multilinear_map.curry_left (p x (nat.succ m))) s x := (h.fderiv_within m A x hx).congr (Ξ» y hy, (IH (le_of_lt A) hy).symm) (IH (le_of_lt A) hx).symm, rw [iterated_fderiv_within_succ_eq_comp_left, function.comp_apply, this.fderiv_within (hs x hx)], exact (continuous_multilinear_map.uncurry_curry_left _).symm } end /-- When a function is `C^n` in a set `s` of unique differentiability, it admits `ftaylor_series_within π•œ f s` as a Taylor series up to order `n` in `s`. -/ theorem times_cont_diff_on.ftaylor_series_within {n : with_top β„•} (h : times_cont_diff_on π•œ n f s) (hs : unique_diff_on π•œ s) : has_ftaylor_series_up_to_on n f (ftaylor_series_within π•œ f s) s := begin split, { assume x hx, simp only [ftaylor_series_within, continuous_multilinear_map.uncurry0_apply, iterated_fderiv_within_zero_apply] }, { assume m hm x hx, rcases (h x hx) m.succ (with_top.add_one_le_of_lt hm) with ⟨u, hu, p, Hp⟩, rw insert_eq_of_mem hx at hu, rcases mem_nhds_within.1 hu with ⟨o, o_open, xo, ho⟩, rw inter_comm at ho, have : p x m.succ = ftaylor_series_within π•œ f s x m.succ, { change p x m.succ = iterated_fderiv_within π•œ m.succ f s x, rw ← iterated_fderiv_within_inter (mem_nhds_sets o_open xo) hs hx, exact (Hp.mono ho).eq_ftaylor_series_of_unique_diff_on (le_refl _) (hs.inter o_open) ⟨hx, xo⟩ }, rw [← this, ← has_fderiv_within_at_inter (mem_nhds_sets o_open xo)], have A : βˆ€ y ∈ s ∩ o, p y m = ftaylor_series_within π•œ f s y m, { rintros y ⟨hy, yo⟩, change p y m = iterated_fderiv_within π•œ m f s y, rw ← iterated_fderiv_within_inter (mem_nhds_sets o_open yo) hs hy, exact (Hp.mono ho).eq_ftaylor_series_of_unique_diff_on (with_top.coe_le_coe.2 (nat.le_succ m)) (hs.inter o_open) ⟨hy, yo⟩ }, exact ((Hp.mono ho).fderiv_within m (with_top.coe_lt_coe.2 (lt_add_one m)) x ⟨hx, xo⟩).congr (Ξ» y hy, (A y hy).symm) (A x ⟨hx, xo⟩).symm }, { assume m hm, apply continuous_on_of_locally_continuous_on, assume x hx, rcases h x hx m hm with ⟨u, hu, p, Hp⟩, rcases mem_nhds_within.1 hu with ⟨o, o_open, xo, ho⟩, rw insert_eq_of_mem hx at ho, rw inter_comm at ho, refine ⟨o, o_open, xo, _⟩, have A : βˆ€ y ∈ s ∩ o, p y m = ftaylor_series_within π•œ f s y m, { rintros y ⟨hy, yo⟩, change p y m = iterated_fderiv_within π•œ m f s y, rw ← iterated_fderiv_within_inter (mem_nhds_sets o_open yo) hs hy, exact (Hp.mono ho).eq_ftaylor_series_of_unique_diff_on (le_refl _) (hs.inter o_open) ⟨hy, yo⟩ }, exact ((Hp.mono ho).cont m (le_refl _)).congr (Ξ» y hy, (A y hy).symm) } end lemma times_cont_diff_on_of_continuous_on_differentiable_on {n : with_top β„•} (Hcont : βˆ€ (m : β„•), (m : with_top β„•) ≀ n β†’ continuous_on (Ξ» x, iterated_fderiv_within π•œ m f s x) s) (Hdiff : βˆ€ (m : β„•), (m : with_top β„•) < n β†’ differentiable_on π•œ (Ξ» x, iterated_fderiv_within π•œ m f s x) s) : times_cont_diff_on π•œ n f s := begin assume x hx m hm, rw insert_eq_of_mem hx, refine ⟨s, self_mem_nhds_within, ftaylor_series_within π•œ f s, _⟩, split, { assume y hy, simp only [ftaylor_series_within, continuous_multilinear_map.uncurry0_apply, iterated_fderiv_within_zero_apply] }, { assume k hk y hy, convert (Hdiff k (lt_of_lt_of_le hk hm) y hy).has_fderiv_within_at, simp only [ftaylor_series_within, iterated_fderiv_within_succ_eq_comp_left, continuous_linear_equiv.coe_apply, function.comp_app, coe_fn_coe_base], exact continuous_linear_map.curry_uncurry_left _ }, { assume k hk, exact Hcont k (le_trans hk hm) } end lemma times_cont_diff_on_of_differentiable_on {n : with_top β„•} (h : βˆ€(m : β„•), (m : with_top β„•) ≀ n β†’ differentiable_on π•œ (iterated_fderiv_within π•œ m f s) s) : times_cont_diff_on π•œ n f s := times_cont_diff_on_of_continuous_on_differentiable_on (Ξ» m hm, (h m hm).continuous_on) (Ξ» m hm, (h m (le_of_lt hm))) lemma times_cont_diff_on.continuous_on_iterated_fderiv_within {n : with_top β„•} {m : β„•} (h : times_cont_diff_on π•œ n f s) (hmn : (m : with_top β„•) ≀ n) (hs : unique_diff_on π•œ s) : continuous_on (iterated_fderiv_within π•œ m f s) s := (h.ftaylor_series_within hs).cont m hmn lemma times_cont_diff_on.differentiable_on_iterated_fderiv_within {n : with_top β„•} {m : β„•} (h : times_cont_diff_on π•œ n f s) (hmn : (m : with_top β„•) < n) (hs : unique_diff_on π•œ s) : differentiable_on π•œ (iterated_fderiv_within π•œ m f s) s := Ξ» x hx, ((h.ftaylor_series_within hs).fderiv_within m hmn x hx).differentiable_within_at lemma times_cont_diff_on_iff_continuous_on_differentiable_on {n : with_top β„•} (hs : unique_diff_on π•œ s) : times_cont_diff_on π•œ n f s ↔ (βˆ€ (m : β„•), (m : with_top β„•) ≀ n β†’ continuous_on (Ξ» x, iterated_fderiv_within π•œ m f s x) s) ∧ (βˆ€ (m : β„•), (m : with_top β„•) < n β†’ differentiable_on π•œ (Ξ» x, iterated_fderiv_within π•œ m f s x) s) := begin split, { assume h, split, { assume m hm, exact h.continuous_on_iterated_fderiv_within hm hs }, { assume m hm, exact h.differentiable_on_iterated_fderiv_within hm hs } }, { assume h, exact times_cont_diff_on_of_continuous_on_differentiable_on h.1 h.2 } end /-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (expressed with `fderiv_within`) is `C^n`. -/ theorem times_cont_diff_on_succ_iff_fderiv_within {n : β„•} (hs : unique_diff_on π•œ s) : times_cont_diff_on π•œ ((n + 1) : β„•) f s ↔ differentiable_on π•œ f s ∧ times_cont_diff_on π•œ n (Ξ» y, fderiv_within π•œ f s y) s := begin split, { assume H, refine ⟨H.differentiable_on (with_top.coe_le_coe.2 (nat.le_add_left 1 n)), Ξ» x hx, _⟩, rcases times_cont_diff_within_at_succ_iff_has_fderiv_within_at.1 (H x hx) with ⟨u, hu, f', hff', hf'⟩, rcases mem_nhds_within.1 hu with ⟨o, o_open, xo, ho⟩, rw [inter_comm, insert_eq_of_mem hx] at ho, have := hf'.mono ho, rw times_cont_diff_within_at_inter' (mem_nhds_within_of_mem_nhds (mem_nhds_sets o_open xo)) at this, apply this.congr_of_eventually_eq' _ hx, have : o ∩ s ∈ 𝓝[s] x := mem_nhds_within.2 ⟨o, o_open, xo, subset.refl _⟩, rw inter_comm at this, apply filter.eventually_eq_of_mem this (Ξ» y hy, _), have A : fderiv_within π•œ f (s ∩ o) y = f' y := ((hff' y (ho hy)).mono ho).fderiv_within (hs.inter o_open y hy), rwa fderiv_within_inter (mem_nhds_sets o_open hy.2) (hs y hy.1) at A, }, { rintros ⟨hdiff, h⟩ x hx, rw [times_cont_diff_within_at_succ_iff_has_fderiv_within_at, insert_eq_of_mem hx], exact ⟨s, self_mem_nhds_within, fderiv_within π•œ f s, Ξ» y hy, (hdiff y hy).has_fderiv_within_at, h x hx⟩ } end /-- A function is `C^(n + 1)` on an open domain if and only if it is differentiable there, and its derivative (expressed with `fderiv`) is `C^n`. -/ theorem times_cont_diff_on_succ_iff_fderiv_of_open {n : β„•} (hs : is_open s) : times_cont_diff_on π•œ ((n + 1) : β„•) f s ↔ differentiable_on π•œ f s ∧ times_cont_diff_on π•œ n (Ξ» y, fderiv π•œ f y) s := begin rw times_cont_diff_on_succ_iff_fderiv_within hs.unique_diff_on, congr' 2, rw ← iff_iff_eq, apply times_cont_diff_on_congr, assume x hx, exact fderiv_within_of_open hs hx end /-- A function is `C^∞` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (expressed with `fderiv_within`) is `C^∞`. -/ theorem times_cont_diff_on_top_iff_fderiv_within (hs : unique_diff_on π•œ s) : times_cont_diff_on π•œ ∞ f s ↔ differentiable_on π•œ f s ∧ times_cont_diff_on π•œ ∞ (Ξ» y, fderiv_within π•œ f s y) s := begin split, { assume h, refine ⟨h.differentiable_on le_top, _⟩, apply times_cont_diff_on_top.2 (Ξ» n, ((times_cont_diff_on_succ_iff_fderiv_within hs).1 _).2), exact h.of_le le_top }, { assume h, refine times_cont_diff_on_top.2 (Ξ» n, _), have A : (n : with_top β„•) ≀ ∞ := le_top, apply ((times_cont_diff_on_succ_iff_fderiv_within hs).2 ⟨h.1, h.2.of_le A⟩).of_le, exact with_top.coe_le_coe.2 (nat.le_succ n) } end /-- A function is `C^∞` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (expressed with `fderiv`) is `C^∞`. -/ theorem times_cont_diff_on_top_iff_fderiv_of_open (hs : is_open s) : times_cont_diff_on π•œ ∞ f s ↔ differentiable_on π•œ f s ∧ times_cont_diff_on π•œ ∞ (Ξ» y, fderiv π•œ f y) s := begin rw times_cont_diff_on_top_iff_fderiv_within hs.unique_diff_on, congr' 2, rw ← iff_iff_eq, apply times_cont_diff_on_congr, assume x hx, exact fderiv_within_of_open hs hx end lemma times_cont_diff_on.fderiv_within {m n : with_top β„•} (hf : times_cont_diff_on π•œ n f s) (hs : unique_diff_on π•œ s) (hmn : m + 1 ≀ n) : times_cont_diff_on π•œ m (Ξ» y, fderiv_within π•œ f s y) s := begin cases m, { change ∞ + 1 ≀ n at hmn, have : n = ∞, by simpa using hmn, rw this at hf, exact ((times_cont_diff_on_top_iff_fderiv_within hs).1 hf).2 }, { change (m.succ : with_top β„•) ≀ n at hmn, exact ((times_cont_diff_on_succ_iff_fderiv_within hs).1 (hf.of_le hmn)).2 } end lemma times_cont_diff_on.fderiv_of_open {m n : with_top β„•} (hf : times_cont_diff_on π•œ n f s) (hs : is_open s) (hmn : m + 1 ≀ n) : times_cont_diff_on π•œ m (Ξ» y, fderiv π•œ f y) s := (hf.fderiv_within hs.unique_diff_on hmn).congr (Ξ» x hx, (fderiv_within_of_open hs hx).symm) lemma times_cont_diff_on.continuous_on_fderiv_within {n : with_top β„•} (h : times_cont_diff_on π•œ n f s) (hs : unique_diff_on π•œ s) (hn : 1 ≀ n) : continuous_on (Ξ» x, fderiv_within π•œ f s x) s := ((times_cont_diff_on_succ_iff_fderiv_within hs).1 (h.of_le hn)).2.continuous_on lemma times_cont_diff_on.continuous_on_fderiv_of_open {n : with_top β„•} (h : times_cont_diff_on π•œ n f s) (hs : is_open s) (hn : 1 ≀ n) : continuous_on (Ξ» x, fderiv π•œ f x) s := ((times_cont_diff_on_succ_iff_fderiv_of_open hs).1 (h.of_le hn)).2.continuous_on /-- If a function is at least `C^1`, its bundled derivative (mapping `(x, v)` to `Df(x) v`) is continuous. -/ lemma times_cont_diff_on.continuous_on_fderiv_within_apply {n : with_top β„•} (h : times_cont_diff_on π•œ n f s) (hs : unique_diff_on π•œ s) (hn : 1 ≀ n) : continuous_on (Ξ»p : E Γ— E, (fderiv_within π•œ f s p.1 : E β†’ F) p.2) (set.prod s univ) := begin have A : continuous (Ξ»q : (E β†’L[π•œ] F) Γ— E, q.1 q.2) := is_bounded_bilinear_map_apply.continuous, have B : continuous_on (Ξ»p : E Γ— E, (fderiv_within π•œ f s p.1, p.2)) (set.prod s univ), { apply continuous_on.prod _ continuous_snd.continuous_on, exact continuous_on.comp (h.continuous_on_fderiv_within hs hn) continuous_fst.continuous_on (prod_subset_preimage_fst _ _) }, exact A.comp_continuous_on B end /-! ### Functions with a Taylor series on the whole space -/ /-- `has_ftaylor_series_up_to n f p` registers the fact that `p 0 = f` and `p (m+1)` is a derivative of `p m` for `m < n`, and is continuous for `m ≀ n`. This is a predicate analogous to `has_fderiv_at` but for higher order derivatives. -/ structure has_ftaylor_series_up_to (n : with_top β„•) (f : E β†’ F) (p : E β†’ formal_multilinear_series π•œ E F) : Prop := (zero_eq : βˆ€ x, (p x 0).uncurry0 = f x) (fderiv : βˆ€ (m : β„•) (hm : (m : with_top β„•) < n), βˆ€ x, has_fderiv_at (Ξ» y, p y m) (p x m.succ).curry_left x) (cont : βˆ€ (m : β„•) (hm : (m : with_top β„•) ≀ n), continuous (Ξ» x, p x m)) lemma has_ftaylor_series_up_to.zero_eq' {n : with_top β„•} (h : has_ftaylor_series_up_to n f p) (x : E) : p x 0 = (continuous_multilinear_curry_fin0 π•œ E F).symm (f x) := by { rw ← h.zero_eq x, symmetry, exact continuous_multilinear_map.uncurry0_curry0 _ } lemma has_ftaylor_series_up_to_on_univ_iff {n : with_top β„•} : has_ftaylor_series_up_to_on n f p univ ↔ has_ftaylor_series_up_to n f p := begin split, { assume H, split, { exact Ξ» x, H.zero_eq x (mem_univ x) }, { assume m hm x, rw ← has_fderiv_within_at_univ, exact H.fderiv_within m hm x (mem_univ x) }, { assume m hm, rw continuous_iff_continuous_on_univ, exact H.cont m hm } }, { assume H, split, { exact Ξ» x hx, H.zero_eq x }, { assume m hm x hx, rw has_fderiv_within_at_univ, exact H.fderiv m hm x }, { assume m hm, rw ← continuous_iff_continuous_on_univ, exact H.cont m hm } } end lemma has_ftaylor_series_up_to.has_ftaylor_series_up_to_on {n : with_top β„•} (h : has_ftaylor_series_up_to n f p) (s : set E) : has_ftaylor_series_up_to_on n f p s := (has_ftaylor_series_up_to_on_univ_iff.2 h).mono (subset_univ _) lemma has_ftaylor_series_up_to.of_le {m n : with_top β„•} (h : has_ftaylor_series_up_to n f p) (hmn : m ≀ n) : has_ftaylor_series_up_to m f p := by { rw ← has_ftaylor_series_up_to_on_univ_iff at h ⊒, exact h.of_le hmn } lemma has_ftaylor_series_up_to.continuous {n : with_top β„•} (h : has_ftaylor_series_up_to n f p) : continuous f := begin rw ← has_ftaylor_series_up_to_on_univ_iff at h, rw continuous_iff_continuous_on_univ, exact h.continuous_on end lemma has_ftaylor_series_up_to_zero_iff : has_ftaylor_series_up_to 0 f p ↔ continuous f ∧ (βˆ€ x, (p x 0).uncurry0 = f x) := by simp [has_ftaylor_series_up_to_on_univ_iff.symm, continuous_iff_continuous_on_univ, has_ftaylor_series_up_to_on_zero_iff] /-- If a function has a Taylor series at order at least `1`, then the term of order `1` of this series is a derivative of `f`. -/ lemma has_ftaylor_series_up_to.has_fderiv_at {n : with_top β„•} (h : has_ftaylor_series_up_to n f p) (hn : 1 ≀ n) (x : E) : has_fderiv_at f (continuous_multilinear_curry_fin1 π•œ E F (p x 1)) x := begin rw [← has_fderiv_within_at_univ], exact (has_ftaylor_series_up_to_on_univ_iff.2 h).has_fderiv_within_at hn (mem_univ _) end lemma has_ftaylor_series_up_to.differentiable {n : with_top β„•} (h : has_ftaylor_series_up_to n f p) (hn : 1 ≀ n) : differentiable π•œ f := Ξ» x, (h.has_fderiv_at hn x).differentiable_at /-- `p` is a Taylor series of `f` up to `n+1` if and only if `p.shift` is a Taylor series up to `n` for `p 1`, which is a derivative of `f`. -/ theorem has_ftaylor_series_up_to_succ_iff_right {n : β„•} : has_ftaylor_series_up_to ((n + 1) : β„•) f p ↔ (βˆ€ x, (p x 0).uncurry0 = f x) ∧ (βˆ€ x, has_fderiv_at (Ξ» y, p y 0) (p x 1).curry_left x) ∧ has_ftaylor_series_up_to n (Ξ» x, continuous_multilinear_curry_fin1 π•œ E F (p x 1)) (Ξ» x, (p x).shift) := by simp [has_ftaylor_series_up_to_on_succ_iff_right, has_ftaylor_series_up_to_on_univ_iff.symm, -add_comm, -with_zero.coe_add] /-! ### Smooth functions at a point -/ variable (π•œ) /-- A function is continuously differentiable up to `n` at a point `x` if, for any integer `k ≀ n`, there is a neighborhood of `x` where `f` admits derivatives up to order `n`, which are continuous. -/ def times_cont_diff_at (n : with_top β„•) (f : E β†’ F) (x : E) := times_cont_diff_within_at π•œ n f univ x variable {π•œ} theorem times_cont_diff_within_at_univ {n : with_top β„•} : times_cont_diff_within_at π•œ n f univ x ↔ times_cont_diff_at π•œ n f x := iff.rfl lemma times_cont_diff_at_top : times_cont_diff_at π•œ ∞ f x ↔ βˆ€ (n : β„•), times_cont_diff_at π•œ n f x := by simp [← times_cont_diff_within_at_univ, times_cont_diff_within_at_top] lemma times_cont_diff_at.times_cont_diff_within_at {n : with_top β„•} (h : times_cont_diff_at π•œ n f x) : times_cont_diff_within_at π•œ n f s x := h.mono (subset_univ _) lemma times_cont_diff_within_at.times_cont_diff_at {n : with_top β„•} (h : times_cont_diff_within_at π•œ n f s x) (hx : s ∈ 𝓝 x) : times_cont_diff_at π•œ n f x := by rwa [times_cont_diff_at, ← times_cont_diff_within_at_inter hx, univ_inter] lemma times_cont_diff_at.of_le {m n : with_top β„•} (h : times_cont_diff_at π•œ n f x) (hmn : m ≀ n) : times_cont_diff_at π•œ m f x := h.of_le hmn lemma times_cont_diff_at.continuous_at {n : with_top β„•} (h : times_cont_diff_at π•œ n f x) : continuous_at f x := by simpa [continuous_within_at_univ] using h.continuous_within_at /-- If a function is `C^n` with `n β‰₯ 1` at a point, then it is differentiable there. -/ lemma times_cont_diff_at.differentiable {n : with_top β„•} (h : times_cont_diff_at π•œ n f x) (hn : 1 ≀ n) : differentiable_at π•œ f x := by simpa [hn, differentiable_within_at_univ] using h.differentiable_within_at /-- A function is `C^(n + 1)` at a point iff locally, it has a derivative which is `C^n`. -/ theorem times_cont_diff_at_succ_iff_has_fderiv_at {n : β„•} : times_cont_diff_at π•œ ((n + 1) : β„•) f x ↔ (βˆƒ f' : E β†’ (E β†’L[π•œ] F), (βˆƒ u ∈ 𝓝 x, (βˆ€ x ∈ u, has_fderiv_at f (f' x) x)) ∧ (times_cont_diff_at π•œ n f' x)) := begin rw [← times_cont_diff_within_at_univ, times_cont_diff_within_at_succ_iff_has_fderiv_within_at], simp only [nhds_within_univ, exists_prop, mem_univ, insert_eq_of_mem], split, { rintros ⟨u, H, f', h_fderiv, h_times_cont_diff⟩, rcases mem_nhds_sets_iff.mp H with ⟨t, htu, ht, hxt⟩, refine ⟨f', ⟨t, _⟩, h_times_cont_diff.times_cont_diff_at H⟩, refine ⟨mem_nhds_sets_iff.mpr ⟨t, subset.rfl, ht, hxt⟩, _⟩, intros y hyt, refine (h_fderiv y (htu hyt)).has_fderiv_at _, exact mem_nhds_sets_iff.mpr ⟨t, htu, ht, hyt⟩ }, { rintros ⟨f', ⟨u, H, h_fderiv⟩, h_times_cont_diff⟩, refine ⟨u, H, f', _, h_times_cont_diff.times_cont_diff_within_at⟩, intros x hxu, exact (h_fderiv x hxu).has_fderiv_within_at } end /-! ### Smooth functions -/ variable (π•œ) /-- A function is continuously differentiable up to `n` if it admits derivatives up to order `n`, which are continuous. Contrary to the case of definitions in domains (where derivatives might not be unique) we do not need to localize the definition in space or time. -/ definition times_cont_diff (n : with_top β„•) (f : E β†’ F) := βˆƒ p : E β†’ formal_multilinear_series π•œ E F, has_ftaylor_series_up_to n f p variable {π•œ} theorem times_cont_diff_on_univ {n : with_top β„•} : times_cont_diff_on π•œ n f univ ↔ times_cont_diff π•œ n f := begin split, { assume H, use ftaylor_series_within π•œ f univ, rw ← has_ftaylor_series_up_to_on_univ_iff, exact H.ftaylor_series_within unique_diff_on_univ }, { rintros ⟨p, hp⟩ x hx m hm, exact ⟨univ, filter.univ_sets _, p, (hp.has_ftaylor_series_up_to_on univ).of_le hm⟩ } end lemma times_cont_diff_iff_times_cont_diff_at {n : with_top β„•} : times_cont_diff π•œ n f ↔ βˆ€ x, times_cont_diff_at π•œ n f x := by simp [← times_cont_diff_on_univ, times_cont_diff_on, times_cont_diff_at] lemma times_cont_diff.times_cont_diff_at {n : with_top β„•} (h : times_cont_diff π•œ n f) : times_cont_diff_at π•œ n f x := times_cont_diff_iff_times_cont_diff_at.1 h x lemma times_cont_diff.times_cont_diff_within_at {n : with_top β„•} (h : times_cont_diff π•œ n f) : times_cont_diff_within_at π•œ n f s x := h.times_cont_diff_at.times_cont_diff_within_at lemma times_cont_diff_top : times_cont_diff π•œ ∞ f ↔ βˆ€ (n : β„•), times_cont_diff π•œ n f := by simp [times_cont_diff_on_univ.symm, times_cont_diff_on_top] lemma times_cont_diff.times_cont_diff_on {n : with_top β„•} (h : times_cont_diff π•œ n f) : times_cont_diff_on π•œ n f s := (times_cont_diff_on_univ.2 h).mono (subset_univ _) @[simp] lemma times_cont_diff_zero : times_cont_diff π•œ 0 f ↔ continuous f := begin rw [← times_cont_diff_on_univ, continuous_iff_continuous_on_univ], exact times_cont_diff_on_zero end lemma times_cont_diff.of_le {m n : with_top β„•} (h : times_cont_diff π•œ n f) (hmn : m ≀ n) : times_cont_diff π•œ m f := times_cont_diff_on_univ.1 $ (times_cont_diff_on_univ.2 h).of_le hmn lemma times_cont_diff.continuous {n : with_top β„•} (h : times_cont_diff π•œ n f) : continuous f := times_cont_diff_zero.1 (h.of_le bot_le) /-- If a function is `C^n` with `n β‰₯ 1`, then it is differentiable. -/ lemma times_cont_diff.differentiable {n : with_top β„•} (h : times_cont_diff π•œ n f) (hn : 1 ≀ n) : differentiable π•œ f := differentiable_on_univ.1 $ (times_cont_diff_on_univ.2 h).differentiable_on hn /-! ### Iterated derivative -/ variable (π•œ) /-- The `n`-th derivative of a function, as a multilinear map, defined inductively. -/ noncomputable def iterated_fderiv (n : β„•) (f : E β†’ F) : E β†’ (E [Γ—n]β†’L[π•œ] F) := nat.rec_on n (Ξ» x, continuous_multilinear_map.curry0 π•œ E (f x)) (Ξ» n rec x, continuous_linear_map.uncurry_left (fderiv π•œ rec x)) /-- Formal Taylor series associated to a function within a set. -/ def ftaylor_series (f : E β†’ F) (x : E) : formal_multilinear_series π•œ E F := Ξ» n, iterated_fderiv π•œ n f x variable {π•œ} @[simp] lemma iterated_fderiv_zero_apply (m : (fin 0) β†’ E) : (iterated_fderiv π•œ 0 f x : ((fin 0) β†’ E) β†’ F) m = f x := rfl lemma iterated_fderiv_zero_eq_comp : iterated_fderiv π•œ 0 f = (continuous_multilinear_curry_fin0 π•œ E F).symm ∘ f := rfl lemma iterated_fderiv_succ_apply_left {n : β„•} (m : fin (n + 1) β†’ E): (iterated_fderiv π•œ (n + 1) f x : (fin (n + 1) β†’ E) β†’ F) m = (fderiv π•œ (iterated_fderiv π•œ n f) x : E β†’ (E [Γ—n]β†’L[π•œ] F)) (m 0) (tail m) := rfl /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the derivative of the `n`-th derivative. -/ lemma iterated_fderiv_succ_eq_comp_left {n : β„•} : iterated_fderiv π•œ (n + 1) f = (continuous_multilinear_curry_left_equiv π•œ (Ξ»(i : fin (n + 1)), E) F) ∘ (fderiv π•œ (iterated_fderiv π•œ n f)) := rfl lemma iterated_fderiv_within_univ {n : β„•} : iterated_fderiv_within π•œ n f univ = iterated_fderiv π•œ n f := begin induction n with n IH, { ext x, simp }, { ext x m, rw [iterated_fderiv_succ_apply_left, iterated_fderiv_within_succ_apply_left, IH, fderiv_within_univ] } end lemma ftaylor_series_within_univ : ftaylor_series_within π•œ f univ = ftaylor_series π•œ f := begin ext1 x, ext1 n, change iterated_fderiv_within π•œ n f univ x = iterated_fderiv π•œ n f x, rw iterated_fderiv_within_univ end theorem iterated_fderiv_succ_apply_right {n : β„•} (m : fin (n + 1) β†’ E) : (iterated_fderiv π•œ (n + 1) f x : (fin (n + 1) β†’ E) β†’ F) m = iterated_fderiv π•œ n (Ξ»y, fderiv π•œ f y) x (init m) (m (last n)) := begin rw [← iterated_fderiv_within_univ, ← iterated_fderiv_within_univ, ← fderiv_within_univ], exact iterated_fderiv_within_succ_apply_right unique_diff_on_univ (mem_univ _) _ end /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the `n`-th derivative of the derivative. -/ lemma iterated_fderiv_succ_eq_comp_right {n : β„•} : iterated_fderiv π•œ (n + 1) f x = ((continuous_multilinear_curry_right_equiv π•œ (Ξ»(i : fin (n + 1)), E) F) ∘ (iterated_fderiv π•œ n (Ξ»y, fderiv π•œ f y))) x := by { ext m, rw iterated_fderiv_succ_apply_right, refl } @[simp] lemma iterated_fderiv_one_apply (m : (fin 1) β†’ E) : (iterated_fderiv π•œ 1 f x : ((fin 1) β†’ E) β†’ F) m = (fderiv π•œ f x : E β†’ F) (m 0) := by { rw [iterated_fderiv_succ_apply_right, iterated_fderiv_zero_apply], refl } /-- When a function is `C^n` in a set `s` of unique differentiability, it admits `ftaylor_series_within π•œ f s` as a Taylor series up to order `n` in `s`. -/ theorem times_cont_diff_on_iff_ftaylor_series {n : with_top β„•} : times_cont_diff π•œ n f ↔ has_ftaylor_series_up_to n f (ftaylor_series π•œ f) := begin split, { rw [← times_cont_diff_on_univ, ← has_ftaylor_series_up_to_on_univ_iff, ← ftaylor_series_within_univ], exact Ξ» h, times_cont_diff_on.ftaylor_series_within h unique_diff_on_univ }, { assume h, exact ⟨ftaylor_series π•œ f, h⟩ } end lemma times_cont_diff_iff_continuous_differentiable {n : with_top β„•} : times_cont_diff π•œ n f ↔ (βˆ€ (m : β„•), (m : with_top β„•) ≀ n β†’ continuous (Ξ» x, iterated_fderiv π•œ m f x)) ∧ (βˆ€ (m : β„•), (m : with_top β„•) < n β†’ differentiable π•œ (Ξ» x, iterated_fderiv π•œ m f x)) := by simp [times_cont_diff_on_univ.symm, continuous_iff_continuous_on_univ, differentiable_on_univ.symm, iterated_fderiv_within_univ, times_cont_diff_on_iff_continuous_on_differentiable_on unique_diff_on_univ] lemma times_cont_diff_of_differentiable_iterated_fderiv {n : with_top β„•} (h : βˆ€(m : β„•), (m : with_top β„•) ≀ n β†’ differentiable π•œ (iterated_fderiv π•œ m f)) : times_cont_diff π•œ n f := times_cont_diff_iff_continuous_differentiable.2 ⟨λ m hm, (h m hm).continuous, Ξ» m hm, (h m (le_of_lt hm))⟩ /-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is differentiable there, and its derivative is `C^n`. -/ theorem times_cont_diff_succ_iff_fderiv {n : β„•} : times_cont_diff π•œ ((n + 1) : β„•) f ↔ differentiable π•œ f ∧ times_cont_diff π•œ n (Ξ» y, fderiv π•œ f y) := by simp [times_cont_diff_on_univ.symm, differentiable_on_univ.symm, fderiv_within_univ.symm, - fderiv_within_univ, times_cont_diff_on_succ_iff_fderiv_within unique_diff_on_univ, -with_zero.coe_add, -add_comm] /-- A function is `C^∞` on a domain with unique derivatives if and only if it is differentiable there, and its derivative is `C^∞`. -/ theorem times_cont_diff_top_iff_fderiv : times_cont_diff π•œ ∞ f ↔ differentiable π•œ f ∧ times_cont_diff π•œ ∞ (Ξ» y, fderiv π•œ f y) := begin simp [times_cont_diff_on_univ.symm, differentiable_on_univ.symm, fderiv_within_univ.symm, - fderiv_within_univ], rw times_cont_diff_on_top_iff_fderiv_within unique_diff_on_univ, end lemma times_cont_diff.continuous_fderiv {n : with_top β„•} (h : times_cont_diff π•œ n f) (hn : 1 ≀ n) : continuous (Ξ» x, fderiv π•œ f x) := ((times_cont_diff_succ_iff_fderiv).1 (h.of_le hn)).2.continuous /-- If a function is at least `C^1`, its bundled derivative (mapping `(x, v)` to `Df(x) v`) is continuous. -/ lemma times_cont_diff.continuous_fderiv_apply {n : with_top β„•} (h : times_cont_diff π•œ n f) (hn : 1 ≀ n) : continuous (Ξ»p : E Γ— E, (fderiv π•œ f p.1 : E β†’ F) p.2) := begin have A : continuous (Ξ»q : (E β†’L[π•œ] F) Γ— E, q.1 q.2) := is_bounded_bilinear_map_apply.continuous, have B : continuous (Ξ»p : E Γ— E, (fderiv π•œ f p.1, p.2)), { apply continuous.prod_mk _ continuous_snd, exact continuous.comp (h.continuous_fderiv hn) continuous_fst }, exact A.comp B end /-! ### Constants -/ lemma iterated_fderiv_within_zero_fun {n : β„•} : iterated_fderiv π•œ n (Ξ» x : E, (0 : F)) = 0 := begin induction n with n IH, { ext m, simp }, { ext x m, rw [iterated_fderiv_succ_apply_left, IH], change (fderiv π•œ (Ξ» (x : E), (0 : (E [Γ—n]β†’L[π•œ] F))) x : E β†’ (E [Γ—n]β†’L[π•œ] F)) (m 0) (tail m) = _, rw fderiv_const, refl } end lemma times_cont_diff_zero_fun {n : with_top β„•} : times_cont_diff π•œ n (Ξ» x : E, (0 : F)) := begin apply times_cont_diff_of_differentiable_iterated_fderiv (Ξ»m hm, _), rw iterated_fderiv_within_zero_fun, apply differentiable_const (0 : (E [Γ—m]β†’L[π•œ] F)) end /-- Constants are `C^∞`. -/ lemma times_cont_diff_const {n : with_top β„•} {c : F} : times_cont_diff π•œ n (Ξ»x : E, c) := begin suffices h : times_cont_diff π•œ ∞ (Ξ»x : E, c), by exact h.of_le le_top, rw times_cont_diff_top_iff_fderiv, refine ⟨differentiable_const c, _⟩, rw fderiv_const, exact times_cont_diff_zero_fun end lemma times_cont_diff_on_const {n : with_top β„•} {c : F} {s : set E} : times_cont_diff_on π•œ n (Ξ»x : E, c) s := times_cont_diff_const.times_cont_diff_on lemma times_cont_diff_at_const {n : with_top β„•} {c : F} : times_cont_diff_at π•œ n (Ξ»x : E, c) x := times_cont_diff_const.times_cont_diff_at lemma times_cont_diff_within_at_const {n : with_top β„•} {c : F} : times_cont_diff_within_at π•œ n (Ξ»x : E, c) s x := times_cont_diff_at_const.times_cont_diff_within_at /-! ### Linear functions -/ /-- Unbundled bounded linear functions are `C^∞`. -/ lemma is_bounded_linear_map.times_cont_diff {n : with_top β„•} (hf : is_bounded_linear_map π•œ f) : times_cont_diff π•œ n f := begin suffices h : times_cont_diff π•œ ∞ f, by exact h.of_le le_top, rw times_cont_diff_top_iff_fderiv, refine ⟨hf.differentiable, _⟩, simp [hf.fderiv], exact times_cont_diff_const end lemma continuous_linear_map.times_cont_diff {n : with_top β„•} (f : E β†’L[π•œ] F) : times_cont_diff π•œ n f := f.is_bounded_linear_map.times_cont_diff /-- The first projection in a product is `C^∞`. -/ lemma times_cont_diff_fst {n : with_top β„•} : times_cont_diff π•œ n (prod.fst : E Γ— F β†’ E) := is_bounded_linear_map.times_cont_diff is_bounded_linear_map.fst /-- The first projection on a domain in a product is `C^∞`. -/ lemma times_cont_diff_on_fst {s : set (EΓ—F)} {n : with_top β„•} : times_cont_diff_on π•œ n (prod.fst : E Γ— F β†’ E) s := times_cont_diff.times_cont_diff_on times_cont_diff_fst /-- The first projection at a point in a product is `C^∞`. -/ lemma times_cont_diff_at_fst {p : E Γ— F} {n : with_top β„•} : times_cont_diff_at π•œ n (prod.fst : E Γ— F β†’ E) p := times_cont_diff_fst.times_cont_diff_at /-- The first projection within a domain at a point in a product is `C^∞`. -/ lemma times_cont_diff_within_at_fst {s : set (E Γ— F)} {p : E Γ— F} {n : with_top β„•} : times_cont_diff_within_at π•œ n (prod.fst : E Γ— F β†’ E) s p := times_cont_diff_fst.times_cont_diff_within_at /-- The second projection in a product is `C^∞`. -/ lemma times_cont_diff_snd {n : with_top β„•} : times_cont_diff π•œ n (prod.snd : E Γ— F β†’ F) := is_bounded_linear_map.times_cont_diff is_bounded_linear_map.snd /-- The second projection on a domain in a product is `C^∞`. -/ lemma times_cont_diff_on_snd {s : set (EΓ—F)} {n : with_top β„•} : times_cont_diff_on π•œ n (prod.snd : E Γ— F β†’ F) s := times_cont_diff.times_cont_diff_on times_cont_diff_snd /-- The second projection at a point in a product is `C^∞`. -/ lemma times_cont_diff_at_snd {p : E Γ— F} {n : with_top β„•} : times_cont_diff_at π•œ n (prod.snd : E Γ— F β†’ F) p := times_cont_diff_snd.times_cont_diff_at /-- The second projection within a domain at a point in a product is `C^∞`. -/ lemma times_cont_diff_within_at_snd {s : set (E Γ— F)} {p : E Γ— F} {n : with_top β„•} : times_cont_diff_within_at π•œ n (prod.snd : E Γ— F β†’ F) s p := times_cont_diff_snd.times_cont_diff_within_at /-- The identity is `C^∞`. -/ lemma times_cont_diff_id {n : with_top β„•} : times_cont_diff π•œ n (id : E β†’ E) := is_bounded_linear_map.id.times_cont_diff /-- Bilinear functions are `C^∞`. -/ lemma is_bounded_bilinear_map.times_cont_diff {n : with_top β„•} (hb : is_bounded_bilinear_map π•œ b) : times_cont_diff π•œ n b := begin suffices h : times_cont_diff π•œ ∞ b, by exact h.of_le le_top, rw times_cont_diff_top_iff_fderiv, refine ⟨hb.differentiable, _⟩, simp [hb.fderiv], exact hb.is_bounded_linear_map_deriv.times_cont_diff end /-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `g ∘ f` admits a Taylor series whose `k`-th term is given by `g ∘ (p k)`. -/ lemma has_ftaylor_series_up_to_on.continuous_linear_map_comp {n : with_top β„•} (g : F β†’L[π•œ] G) (hf : has_ftaylor_series_up_to_on n f p s) : has_ftaylor_series_up_to_on n (g ∘ f) (Ξ» x k, g.comp_continuous_multilinear_map (p x k)) s := begin split, { assume x hx, simp [(hf.zero_eq x hx).symm] }, { assume m hm x hx, let A : (E [Γ—m]β†’L[π•œ] F) β†’ (E [Γ—m]β†’L[π•œ] G) := Ξ» f, g.comp_continuous_multilinear_map f, have hA : is_bounded_linear_map π•œ A := is_bounded_bilinear_map_comp_multilinear.is_bounded_linear_map_right _, have := hf.fderiv_within m hm x hx, convert has_fderiv_at.comp_has_fderiv_within_at x (hA.has_fderiv_at) this }, { assume m hm, let A : (E [Γ—m]β†’L[π•œ] F) β†’ (E [Γ—m]β†’L[π•œ] G) := Ξ» f, g.comp_continuous_multilinear_map f, have hA : is_bounded_linear_map π•œ A := is_bounded_bilinear_map_comp_multilinear.is_bounded_linear_map_right _, exact hA.continuous.comp_continuous_on (hf.cont m hm) } end /-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain at a point. -/ lemma times_cont_diff_within_at.continuous_linear_map_comp {n : with_top β„•} (g : F β†’L[π•œ] G) (hf : times_cont_diff_within_at π•œ n f s x) : times_cont_diff_within_at π•œ n (g ∘ f) s x := begin assume m hm, rcases hf m hm with ⟨u, hu, p, hp⟩, exact ⟨u, hu, _, hp.continuous_linear_map_comp g⟩, end /-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain at a point. -/ lemma times_cont_diff_at.continuous_linear_map_comp {n : with_top β„•} (g : F β†’L[π•œ] G) (hf : times_cont_diff_at π•œ n f x) : times_cont_diff_at π•œ n (g ∘ f) x := times_cont_diff_within_at.continuous_linear_map_comp g hf /-- Composition by continuous linear maps on the left preserves `C^n` functions on domains. -/ lemma times_cont_diff_on.continuous_linear_map_comp {n : with_top β„•} (g : F β†’L[π•œ] G) (hf : times_cont_diff_on π•œ n f s) : times_cont_diff_on π•œ n (g ∘ f) s := Ξ» x hx, (hf x hx).continuous_linear_map_comp g /-- Composition by continuous linear maps on the left preserves `C^n` functions. -/ lemma times_cont_diff.continuous_linear_map_comp {n : with_top β„•} {f : E β†’ F} (g : F β†’L[π•œ] G) (hf : times_cont_diff π•œ n f) : times_cont_diff π•œ n (Ξ»x, g (f x)) := times_cont_diff_on_univ.1 $ times_cont_diff_on.continuous_linear_map_comp _ (times_cont_diff_on_univ.2 hf) /-- Composition by continuous linear equivs on the left respects higher differentiability on domains. -/ lemma continuous_linear_equiv.comp_times_cont_diff_within_at_iff {n : with_top β„•} (e : F ≃L[π•œ] G) : times_cont_diff_within_at π•œ n (e ∘ f) s x ↔ times_cont_diff_within_at π•œ n f s x := begin split, { assume H, have : f = e.symm ∘ (e ∘ f), by { ext y, simp only [function.comp_app], rw e.symm_apply_apply (f y) }, rw this, exact H.continuous_linear_map_comp _ }, { assume H, exact H.continuous_linear_map_comp _ } end /-- Composition by continuous linear equivs on the left respects higher differentiability on domains. -/ lemma continuous_linear_equiv.comp_times_cont_diff_on_iff {n : with_top β„•} (e : F ≃L[π•œ] G) : times_cont_diff_on π•œ n (e ∘ f) s ↔ times_cont_diff_on π•œ n f s := by simp [times_cont_diff_on, e.comp_times_cont_diff_within_at_iff] /-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `f ∘ g` admits a Taylor series in `g ⁻¹' s`, whose `k`-th term is given by `p k (g v₁, ..., g vβ‚–)` . -/ lemma has_ftaylor_series_up_to_on.comp_continuous_linear_map {n : with_top β„•} (hf : has_ftaylor_series_up_to_on n f p s) (g : G β†’L[π•œ] E) : has_ftaylor_series_up_to_on n (f ∘ g) (Ξ» x k, (p (g x) k).comp_continuous_linear_map π•œ E g) (g ⁻¹' s) := begin split, { assume x hx, simp only [(hf.zero_eq (g x) hx).symm, function.comp_app], change p (g x) 0 (Ξ» (i : fin 0), g 0) = p (g x) 0 0, rw continuous_linear_map.map_zero, refl }, { assume m hm x hx, let A : (E [Γ—m]β†’L[π•œ] F) β†’ (G [Γ—m]β†’L[π•œ] F) := Ξ» h, h.comp_continuous_linear_map π•œ E g, have hA : is_bounded_linear_map π•œ A := is_bounded_linear_map_continuous_multilinear_map_comp_linear g, convert (hA.has_fderiv_at).comp_has_fderiv_within_at x ((hf.fderiv_within m hm (g x) hx).comp x (g.has_fderiv_within_at) (subset.refl _)), ext y v, change p (g x) (nat.succ m) (g ∘ (cons y v)) = p (g x) m.succ (cons (g y) (g ∘ v)), rw comp_cons }, { assume m hm, let A : (E [Γ—m]β†’L[π•œ] F) β†’ (G [Γ—m]β†’L[π•œ] F) := Ξ» h, h.comp_continuous_linear_map π•œ E g, have hA : is_bounded_linear_map π•œ A := is_bounded_linear_map_continuous_multilinear_map_comp_linear g, exact hA.continuous.comp_continuous_on ((hf.cont m hm).comp g.continuous.continuous_on (subset.refl _)) } end /-- Composition by continuous linear maps on the right preserves `C^n` functions at a point on a domain. -/ lemma times_cont_diff_within_at.comp_continuous_linear_map {n : with_top β„•} {x : G} (g : G β†’L[π•œ] E) (hf : times_cont_diff_within_at π•œ n f s (g x)) : times_cont_diff_within_at π•œ n (f ∘ g) (g ⁻¹' s) x := begin assume m hm, rcases hf m hm with ⟨u, hu, p, hp⟩, refine ⟨g ⁻¹' u, _, _, hp.comp_continuous_linear_map g⟩, apply continuous_within_at.preimage_mem_nhds_within', { exact g.continuous.continuous_within_at }, { apply nhds_within_mono (g x) _ hu, rw image_insert_eq, exact insert_subset_insert (image_preimage_subset g s) } end /-- Composition by continuous linear maps on the right preserves `C^n` functions on domains. -/ lemma times_cont_diff_on.comp_continuous_linear_map {n : with_top β„•} (hf : times_cont_diff_on π•œ n f s) (g : G β†’L[π•œ] E) : times_cont_diff_on π•œ n (f ∘ g) (g ⁻¹' s) := Ξ» x hx, (hf (g x) hx).comp_continuous_linear_map g /-- Composition by continuous linear maps on the right preserves `C^n` functions. -/ lemma times_cont_diff.comp_continuous_linear_map {n : with_top β„•} {f : E β†’ F} {g : G β†’L[π•œ] E} (hf : times_cont_diff π•œ n f) : times_cont_diff π•œ n (f ∘ g) := times_cont_diff_on_univ.1 $ times_cont_diff_on.comp_continuous_linear_map (times_cont_diff_on_univ.2 hf) _ /-- Composition by continuous linear equivs on the right respects higher differentiability at a point in a domain. -/ lemma continuous_linear_equiv.times_cont_diff_within_at_comp_iff {n : with_top β„•} (e : G ≃L[π•œ] E) : times_cont_diff_within_at π•œ n (f ∘ e) (e ⁻¹' s) (e.symm x) ↔ times_cont_diff_within_at π•œ n f s x := begin split, { assume H, have A : f = (f ∘ e) ∘ e.symm, by { ext y, simp only [function.comp_app], rw e.apply_symm_apply y }, have B : e.symm ⁻¹' (e ⁻¹' s) = s, by { rw [← preimage_comp, e.self_comp_symm], refl }, rw [A, ← B], exact H.comp_continuous_linear_map _}, { assume H, have : x = e (e.symm x), by simp, rw this at H, exact H.comp_continuous_linear_map _ }, end /-- Composition by continuous linear equivs on the right respects higher differentiability on domains. -/ lemma continuous_linear_equiv.times_cont_diff_on_comp_iff {n : with_top β„•} (e : G ≃L[π•œ] E) : times_cont_diff_on π•œ n (f ∘ e) (e ⁻¹' s) ↔ times_cont_diff_on π•œ n f s := begin refine ⟨λ H, _, Ξ» H, H.comp_continuous_linear_map _⟩, have A : f = (f ∘ e) ∘ e.symm, by { ext y, simp only [function.comp_app], rw e.apply_symm_apply y }, have B : e.symm ⁻¹' (e ⁻¹' s) = s, by { rw [← preimage_comp, e.self_comp_symm], refl }, rw [A, ← B], exact H.comp_continuous_linear_map _ end /-- If two functions `f` and `g` admit Taylor series `p` and `q` in a set `s`, then the cartesian product of `f` and `g` admits the cartesian product of `p` and `q` as a Taylor series. -/ lemma has_ftaylor_series_up_to_on.prod {n : with_top β„•} (hf : has_ftaylor_series_up_to_on n f p s) {g : E β†’ G} {q : E β†’ formal_multilinear_series π•œ E G} (hg : has_ftaylor_series_up_to_on n g q s) : has_ftaylor_series_up_to_on n (Ξ» y, (f y, g y)) (Ξ» y k, (p y k).prod (q y k)) s := begin split, { assume x hx, rw [← hf.zero_eq x hx, ← hg.zero_eq x hx], refl }, { assume m hm x hx, let A : (E [Γ—m]β†’L[π•œ] F) Γ— (E [Γ—m]β†’L[π•œ] G) β†’ (E [Γ—m]β†’L[π•œ] (F Γ— G)) := Ξ» p, p.1.prod p.2, have hA : is_bounded_linear_map π•œ A := is_bounded_linear_map_prod_multilinear, convert hA.has_fderiv_at.comp_has_fderiv_within_at x ((hf.fderiv_within m hm x hx).prod (hg.fderiv_within m hm x hx)) }, { assume m hm, let A : (E [Γ—m]β†’L[π•œ] F) Γ— (E [Γ—m]β†’L[π•œ] G) β†’ (E [Γ—m]β†’L[π•œ] (F Γ— G)) := Ξ» p, p.1.prod p.2, have hA : is_bounded_linear_map π•œ A := is_bounded_linear_map_prod_multilinear, exact hA.continuous.comp_continuous_on ((hf.cont m hm).prod (hg.cont m hm)) } end /-- The cartesian product of `C^n` functions at a point in a domain is `C^n`. -/ lemma times_cont_diff_within_at.prod {n : with_top β„•} {s : set E} {f : E β†’ F} {g : E β†’ G} (hf : times_cont_diff_within_at π•œ n f s x) (hg : times_cont_diff_within_at π•œ n g s x) : times_cont_diff_within_at π•œ n (Ξ»x:E, (f x, g x)) s x := begin assume m hm, rcases hf m hm with ⟨u, hu, p, hp⟩, rcases hg m hm with ⟨v, hv, q, hq⟩, exact ⟨u ∩ v, filter.inter_mem_sets hu hv, _, (hp.mono (inter_subset_left u v)).prod (hq.mono (inter_subset_right u v))⟩ end /-- The cartesian product of `C^n` functions on domains is `C^n`. -/ lemma times_cont_diff_on.prod {n : with_top β„•} {s : set E} {f : E β†’ F} {g : E β†’ G} (hf : times_cont_diff_on π•œ n f s) (hg : times_cont_diff_on π•œ n g s) : times_cont_diff_on π•œ n (Ξ»x:E, (f x, g x)) s := Ξ» x hx, (hf x hx).prod (hg x hx) /-- The cartesian product of `C^n` functions at a point is `C^n`. -/ lemma times_cont_diff_at.prod {n : with_top β„•} {f : E β†’ F} {g : E β†’ G} (hf : times_cont_diff_at π•œ n f x) (hg : times_cont_diff_at π•œ n g x) : times_cont_diff_at π•œ n (Ξ»x:E, (f x, g x)) x := times_cont_diff_within_at_univ.1 $ times_cont_diff_within_at.prod (times_cont_diff_within_at_univ.2 hf) (times_cont_diff_within_at_univ.2 hg) /-- The cartesian product of `C^n` functions is `C^n`. -/ lemma times_cont_diff.prod {n : with_top β„•} {f : E β†’ F} {g : E β†’ G} (hf : times_cont_diff π•œ n f) (hg : times_cont_diff π•œ n g) : times_cont_diff π•œ n (Ξ»x:E, (f x, g x)) := times_cont_diff_on_univ.1 $ times_cont_diff_on.prod (times_cont_diff_on_univ.2 hf) (times_cont_diff_on_univ.2 hg) /-! ### Composition of `C^n` functions We show that the composition of `C^n` functions is `C^n`. One way to prove it would be to write the `n`-th derivative of the composition (this is FaΓ  di Bruno's formula) and check its continuity, but this is very painful. Instead, we go for a simple inductive proof. Assume it is done for `n`. Then, to check it for `n+1`, one needs to check that the derivative of `g ∘ f` is `C^n`, i.e., that `Dg(f x) ⬝ Df(x)` is `C^n`. The term `Dg (f x)` is the composition of two `C^n` functions, so it is `C^n` by the inductive assumption. The term `Df(x)` is also `C^n`. Then, the matrix multiplication is the application of a bilinear map (which is `C^∞`, and therefore `C^n`) to `x ↦ (Dg(f x), Df x)`. As the composition of two `C^n` maps, it is again `C^n`, and we are done. There is a subtlety in this argument: we apply the inductive assumption to functions on other Banach spaces. In maths, one would say: prove by induction over `n` that, for all `C^n` maps between all pairs of Banach spaces, their composition is `C^n`. In Lean, this is fine as long as the spaces stay in the same universe. This is not the case in the above argument: if `E` lives in universe `u` and `F` lives in universe `v`, then linear maps from `E` to `F` (to which the derivative of `f` belongs) is in universe `max u v`. If one could quantify over finitely many universes, the above proof would work fine, but this is not the case. One could still write the proof considering spaces in any universe in `u, v, w, max u v, max v w, max u v w`, but it would be extremely tedious and lead to a lot of duplication. Instead, we formulate the above proof when all spaces live in the same universe (where everything is fine), and then we deduce the general result by lifting all our spaces to a common universe. We use the trick that any space `H` is isomorphic through a continuous linear equiv to `continuous_multilinear_map (Ξ» (i : fin 0), E Γ— F Γ— G) H` to change the universe level, and then argue that composing with such a linear equiv does not change the fact of being `C^n`, which we have already proved previously. -/ /-- Auxiliary lemma proving that the composition of `C^n` functions on domains is `C^n` when all spaces live in the same universe. Use instead `times_cont_diff_on.comp` which removes the universe assumption (but is deduced from this one). -/ private lemma times_cont_diff_on.comp_same_univ {Eu : Type u} [normed_group Eu] [normed_space π•œ Eu] {Fu : Type u} [normed_group Fu] [normed_space π•œ Fu] {Gu : Type u} [normed_group Gu] [normed_space π•œ Gu] {n : with_top β„•} {s : set Eu} {t : set Fu} {g : Fu β†’ Gu} {f : Eu β†’ Fu} (hg : times_cont_diff_on π•œ n g t) (hf : times_cont_diff_on π•œ n f s) (st : s βŠ† f ⁻¹' t) : times_cont_diff_on π•œ n (g ∘ f) s := begin unfreezingI { induction n using with_top.nat_induction with n IH Itop generalizing Eu Fu Gu }, { rw times_cont_diff_on_zero at hf hg ⊒, exact continuous_on.comp hg hf st }, { rw times_cont_diff_on_succ_iff_has_fderiv_within_at at hg ⊒, assume x hx, rcases (times_cont_diff_on_succ_iff_has_fderiv_within_at.1 hf) x hx with ⟨u, hu, f', hf', f'_diff⟩, rcases hg (f x) (st hx) with ⟨v, hv, g', hg', g'_diff⟩, rw insert_eq_of_mem hx at hu ⊒, have xu : x ∈ u := mem_of_mem_nhds_within hx hu, let w := s ∩ (u ∩ f⁻¹' v), have wv : w βŠ† f ⁻¹' v := Ξ» y hy, hy.2.2, have wu : w βŠ† u := Ξ» y hy, hy.2.1, have ws : w βŠ† s := Ξ» y hy, hy.1, refine ⟨w, _, Ξ» y, (g' (f y)).comp (f' y), _, _⟩, show w ∈ 𝓝[s] x, { apply filter.inter_mem_sets self_mem_nhds_within, apply filter.inter_mem_sets hu, apply continuous_within_at.preimage_mem_nhds_within', { rw ← continuous_within_at_inter' hu, exact (hf' x xu).differentiable_within_at.continuous_within_at.mono (inter_subset_right _ _) }, { apply nhds_within_mono _ _ hv, exact subset.trans (image_subset_iff.mpr st) (subset_insert (f x) t) } }, show βˆ€ y ∈ w, has_fderiv_within_at (g ∘ f) ((g' (f y)).comp (f' y)) w y, { rintros y ⟨ys, yu, yv⟩, exact (hg' (f y) yv).comp y ((hf' y yu).mono wu) wv }, show times_cont_diff_on π•œ n (Ξ» y, (g' (f y)).comp (f' y)) w, { have A : times_cont_diff_on π•œ n (Ξ» y, g' (f y)) w := IH g'_diff ((hf.of_le (with_top.coe_le_coe.2 (nat.le_succ n))).mono ws) wv, have B : times_cont_diff_on π•œ n f' w := f'_diff.mono wu, have C : times_cont_diff_on π•œ n (Ξ» y, (f' y, g' (f y))) w := times_cont_diff_on.prod B A, have D : times_cont_diff_on π•œ n (Ξ»(p : (Eu β†’L[π•œ] Fu) Γ— (Fu β†’L[π•œ] Gu)), p.2.comp p.1) univ := is_bounded_bilinear_map_comp.times_cont_diff.times_cont_diff_on, exact IH D C (subset_univ _) } }, { rw times_cont_diff_on_top at hf hg ⊒, assume n, apply Itop n (hg n) (hf n) st } end /-- The composition of `C^n` functions on domains is `C^n`. -/ lemma times_cont_diff_on.comp {n : with_top β„•} {s : set E} {t : set F} {g : F β†’ G} {f : E β†’ F} (hg : times_cont_diff_on π•œ n g t) (hf : times_cont_diff_on π•œ n f s) (st : s βŠ† f ⁻¹' t) : times_cont_diff_on π•œ n (g ∘ f) s := begin /- we lift all the spaces to a common universe, as we have already proved the result in this situation. For the lift, we use the trick that `H` is isomorphic through a continuous linear equiv to `continuous_multilinear_map π•œ (Ξ» (i : fin 0), (E Γ— F Γ— G)) H`, and continuous linear equivs respect smoothness classes. -/ let Eu := continuous_multilinear_map π•œ (Ξ» (i : fin 0), (E Γ— F Γ— G)) E, letI : normed_group Eu := by apply_instance, letI : normed_space π•œ Eu := by apply_instance, let Fu := continuous_multilinear_map π•œ (Ξ» (i : fin 0), (E Γ— F Γ— G)) F, letI : normed_group Fu := by apply_instance, letI : normed_space π•œ Fu := by apply_instance, let Gu := continuous_multilinear_map π•œ (Ξ» (i : fin 0), (E Γ— F Γ— G)) G, letI : normed_group Gu := by apply_instance, letI : normed_space π•œ Gu := by apply_instance, -- declare the isomorphisms let isoE : Eu ≃L[π•œ] E := continuous_multilinear_curry_fin0 π•œ (E Γ— F Γ— G) E, let isoF : Fu ≃L[π•œ] F := continuous_multilinear_curry_fin0 π•œ (E Γ— F Γ— G) F, let isoG : Gu ≃L[π•œ] G := continuous_multilinear_curry_fin0 π•œ (E Γ— F Γ— G) G, -- lift the functions to the new spaces, check smoothness there, and then go back. let fu : Eu β†’ Fu := (isoF.symm ∘ f) ∘ isoE, have fu_diff : times_cont_diff_on π•œ n fu (isoE ⁻¹' s), by rwa [isoE.times_cont_diff_on_comp_iff, isoF.symm.comp_times_cont_diff_on_iff], let gu : Fu β†’ Gu := (isoG.symm ∘ g) ∘ isoF, have gu_diff : times_cont_diff_on π•œ n gu (isoF ⁻¹' t), by rwa [isoF.times_cont_diff_on_comp_iff, isoG.symm.comp_times_cont_diff_on_iff], have main : times_cont_diff_on π•œ n (gu ∘ fu) (isoE ⁻¹' s), { apply times_cont_diff_on.comp_same_univ gu_diff fu_diff, assume y hy, simp only [fu, continuous_linear_equiv.coe_apply, function.comp_app, mem_preimage], rw isoF.apply_symm_apply (f (isoE y)), exact st hy }, have : gu ∘ fu = (isoG.symm ∘ (g ∘ f)) ∘ isoE, { ext y, simp only [function.comp_apply, gu, fu], rw isoF.apply_symm_apply (f (isoE y)) }, rwa [this, isoE.times_cont_diff_on_comp_iff, isoG.symm.comp_times_cont_diff_on_iff] at main end /-- The composition of `C^n` functions on domains is `C^n`. -/ lemma times_cont_diff_on.comp' {n : with_top β„•} {s : set E} {t : set F} {g : F β†’ G} {f : E β†’ F} (hg : times_cont_diff_on π•œ n g t) (hf : times_cont_diff_on π•œ n f s) : times_cont_diff_on π•œ n (g ∘ f) (s ∩ f⁻¹' t) := hg.comp (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _) /-- The composition of a `C^n` function on a domain with a `C^n` function is `C^n`. -/ lemma times_cont_diff.comp_times_cont_diff_on {n : with_top β„•} {s : set E} {g : F β†’ G} {f : E β†’ F} (hg : times_cont_diff π•œ n g) (hf : times_cont_diff_on π•œ n f s) : times_cont_diff_on π•œ n (g ∘ f) s := (times_cont_diff_on_univ.2 hg).comp hf subset_preimage_univ /-- The composition of `C^n` functions is `C^n`. -/ lemma times_cont_diff.comp {n : with_top β„•} {g : F β†’ G} {f : E β†’ F} (hg : times_cont_diff π•œ n g) (hf : times_cont_diff π•œ n f) : times_cont_diff π•œ n (g ∘ f) := times_cont_diff_on_univ.1 $ times_cont_diff_on.comp (times_cont_diff_on_univ.2 hg) (times_cont_diff_on_univ.2 hf) (subset_univ _) /-- The composition of `C^n` functions at points in domains is `C^n`. -/ lemma times_cont_diff_within_at.comp {n : with_top β„•} {s : set E} {t : set F} {g : F β†’ G} {f : E β†’ F} (x : E) (hg : times_cont_diff_within_at π•œ n g t (f x)) (hf : times_cont_diff_within_at π•œ n f s x) (st : s βŠ† f ⁻¹' t) : times_cont_diff_within_at π•œ n (g ∘ f) s x := begin assume m hm, rcases hg.times_cont_diff_on hm with ⟨u, u_nhd, ut, hu⟩, rcases hf.times_cont_diff_on hm with ⟨v, v_nhd, vs, hv⟩, have xmem : x ∈ f ⁻¹' u ∩ v := ⟨(mem_of_mem_nhds_within (mem_insert (f x) _) u_nhd : _), mem_of_mem_nhds_within (mem_insert x s) v_nhd⟩, have : f ⁻¹' u ∈ 𝓝[insert x s] x, { apply hf.continuous_within_at'.preimage_mem_nhds_within', apply nhds_within_mono _ _ u_nhd, rw image_insert_eq, exact insert_subset_insert (image_subset_iff.mpr st) }, have Z := ((hu.comp (hv.mono (inter_subset_right (f ⁻¹' u) v)) (inter_subset_left _ _)) .times_cont_diff_within_at) xmem m (le_refl _), have : 𝓝[f ⁻¹' u ∩ v] x = 𝓝[insert x s] x, { have A : f ⁻¹' u ∩ v = (insert x s) ∩ (f ⁻¹' u ∩ v), { apply subset.antisymm _ (inter_subset_right _ _), rintros y ⟨hy1, hy2⟩, simp [hy1, hy2, vs hy2] }, rw [A, ← nhds_within_restrict''], exact filter.inter_mem_sets this v_nhd }, rwa [insert_eq_of_mem xmem, this] at Z, end /-- The composition of `C^n` functions at points in domains is `C^n`. -/ lemma times_cont_diff_within_at.comp' {n : with_top β„•} {s : set E} {t : set F} {g : F β†’ G} {f : E β†’ F} (x : E) (hg : times_cont_diff_within_at π•œ n g t (f x)) (hf : times_cont_diff_within_at π•œ n f s x) : times_cont_diff_within_at π•œ n (g ∘ f) (s ∩ f⁻¹' t) x := hg.comp x (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _) /-- The composition of `C^n` functions at points is `C^n`. -/ lemma times_cont_diff_at.comp {n : with_top β„•} {g : F β†’ G} {f : E β†’ F} (x : E) (hg : times_cont_diff_at π•œ n g (f x)) (hf : times_cont_diff_at π•œ n f x) : times_cont_diff_at π•œ n (g ∘ f) x := hg.comp x hf subset_preimage_univ lemma times_cont_diff.comp_times_cont_diff_within_at {n : with_top β„•} {g : F β†’ G} {f : E β†’ F} (h : times_cont_diff π•œ n g) (hf : times_cont_diff_within_at π•œ n f t x) : times_cont_diff_within_at π•œ n (g ∘ f) t x := begin have : times_cont_diff_within_at π•œ n g univ (f x) := h.times_cont_diff_at.times_cont_diff_within_at, exact this.comp x hf (subset_univ _), end lemma times_cont_diff.comp_times_cont_diff_at {n : with_top β„•} {g : F β†’ G} {f : E β†’ F} (x : E) (hg : times_cont_diff π•œ n g) (hf : times_cont_diff_at π•œ n f x) : times_cont_diff_at π•œ n (g ∘ f) x := hg.comp_times_cont_diff_within_at hf /-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/ lemma times_cont_diff_on_fderiv_within_apply {m n : with_top β„•} {s : set E} {f : E β†’ F} (hf : times_cont_diff_on π•œ n f s) (hs : unique_diff_on π•œ s) (hmn : m + 1 ≀ n) : times_cont_diff_on π•œ m (Ξ»p : E Γ— E, (fderiv_within π•œ f s p.1 : E β†’L[π•œ] F) p.2) (set.prod s (univ : set E)) := begin have A : times_cont_diff π•œ m (Ξ»p : (E β†’L[π•œ] F) Γ— E, p.1 p.2), { apply is_bounded_bilinear_map.times_cont_diff, exact is_bounded_bilinear_map_apply }, have B : times_cont_diff_on π•œ m (Ξ» (p : E Γ— E), ((fderiv_within π•œ f s p.fst), p.snd)) (set.prod s univ), { apply times_cont_diff_on.prod _ _, { have I : times_cont_diff_on π•œ m (Ξ» (x : E), fderiv_within π•œ f s x) s := hf.fderiv_within hs hmn, have J : times_cont_diff_on π•œ m (Ξ» (x : E Γ— E), x.1) (set.prod s univ) := times_cont_diff_fst.times_cont_diff_on, exact times_cont_diff_on.comp I J (prod_subset_preimage_fst _ _) }, { apply times_cont_diff.times_cont_diff_on _ , apply is_bounded_linear_map.snd.times_cont_diff } }, exact A.comp_times_cont_diff_on B end /-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/ lemma times_cont_diff.times_cont_diff_fderiv_apply {n m : with_top β„•} {f : E β†’ F} (hf : times_cont_diff π•œ n f) (hmn : m + 1 ≀ n) : times_cont_diff π•œ m (Ξ»p : E Γ— E, (fderiv π•œ f p.1 : E β†’L[π•œ] F) p.2) := begin rw ← times_cont_diff_on_univ at ⊒ hf, rw [← fderiv_within_univ, ← univ_prod_univ], exact times_cont_diff_on_fderiv_within_apply hf unique_diff_on_univ hmn end /-! ### Sum of two functions -/ /- The sum is smooth. -/ lemma times_cont_diff_add {n : with_top β„•} : times_cont_diff π•œ n (Ξ»p : F Γ— F, p.1 + p.2) := (is_bounded_linear_map.fst.add is_bounded_linear_map.snd).times_cont_diff /-- The sum of two `C^n` functions within a set at a point is `C^n` within this set at this point. -/ lemma times_cont_diff_within_at.add {n : with_top β„•} {s : set E} {f g : E β†’ F} (hf : times_cont_diff_within_at π•œ n f s x) (hg : times_cont_diff_within_at π•œ n g s x) : times_cont_diff_within_at π•œ n (Ξ»x, f x + g x) s x := times_cont_diff_add.times_cont_diff_within_at.comp x (hf.prod hg) subset_preimage_univ /-- The sum of two `C^n` functions at a point is `C^n` at this point. -/ lemma times_cont_diff_at.add {n : with_top β„•} {f g : E β†’ F} (hf : times_cont_diff_at π•œ n f x) (hg : times_cont_diff_at π•œ n g x) : times_cont_diff_at π•œ n (Ξ»x, f x + g x) x := by rw [← times_cont_diff_within_at_univ] at *; exact hf.add hg /-- The sum of two `C^n`functions is `C^n`. -/ lemma times_cont_diff.add {n : with_top β„•} {f g : E β†’ F} (hf : times_cont_diff π•œ n f) (hg : times_cont_diff π•œ n g) : times_cont_diff π•œ n (Ξ»x, f x + g x) := times_cont_diff_add.comp (hf.prod hg) /-- The sum of two `C^n` functions on a domain is `C^n`. -/ lemma times_cont_diff_on.add {n : with_top β„•} {s : set E} {f g : E β†’ F} (hf : times_cont_diff_on π•œ n f s) (hg : times_cont_diff_on π•œ n g s) : times_cont_diff_on π•œ n (Ξ»x, f x + g x) s := Ξ» x hx, (hf x hx).add (hg x hx) /-! ### Negative -/ /- The negative is smooth. -/ lemma times_cont_diff_neg {n : with_top β„•} : times_cont_diff π•œ n (Ξ»p : F, -p) := is_bounded_linear_map.id.neg.times_cont_diff /-- The negative of a `C^n` function within a domain at a point is `C^n` within this domain at this point. -/ lemma times_cont_diff_within_at.neg {n : with_top β„•} {s : set E} {f : E β†’ F} (hf : times_cont_diff_within_at π•œ n f s x) : times_cont_diff_within_at π•œ n (Ξ»x, -f x) s x := times_cont_diff_neg.times_cont_diff_within_at.comp x hf subset_preimage_univ /-- The negative of a `C^n` function at a point is `C^n` at this point. -/ lemma times_cont_diff_at.neg {n : with_top β„•} {f : E β†’ F} (hf : times_cont_diff_at π•œ n f x) : times_cont_diff_at π•œ n (Ξ»x, -f x) x := by rw ← times_cont_diff_within_at_univ at *; exact hf.neg /-- The negative of a `C^n`function is `C^n`. -/ lemma times_cont_diff.neg {n : with_top β„•} {f : E β†’ F} (hf : times_cont_diff π•œ n f) : times_cont_diff π•œ n (Ξ»x, -f x) := times_cont_diff_neg.comp hf /-- The negative of a `C^n` function on a domain is `C^n`. -/ lemma times_cont_diff_on.neg {n : with_top β„•} {s : set E} {f : E β†’ F} (hf : times_cont_diff_on π•œ n f s) : times_cont_diff_on π•œ n (Ξ»x, -f x) s := Ξ» x hx, (hf x hx).neg /-! ### Subtraction -/ /-- The difference of two `C^n` functions within a set at a point is `C^n` within this set at this point. -/ lemma times_cont_diff_within_at.sub {n : with_top β„•} {s : set E} {f g : E β†’ F} (hf : times_cont_diff_within_at π•œ n f s x) (hg : times_cont_diff_within_at π•œ n g s x) : times_cont_diff_within_at π•œ n (Ξ»x, f x - g x) s x := hf.add hg.neg /-- The difference of two `C^n` functions at a point is `C^n` at this point. -/ lemma times_cont_diff_at.sub {n : with_top β„•} {f g : E β†’ F} (hf : times_cont_diff_at π•œ n f x) (hg : times_cont_diff_at π•œ n g x) : times_cont_diff_at π•œ n (Ξ»x, f x - g x) x := hf.add hg.neg /-- The difference of two `C^n` functions on a domain is `C^n`. -/ lemma times_cont_diff_on.sub {n : with_top β„•} {s : set E} {f g : E β†’ F} (hf : times_cont_diff_on π•œ n f s) (hg : times_cont_diff_on π•œ n g s) : times_cont_diff_on π•œ n (Ξ»x, f x - g x) s := hf.add hg.neg /-- The difference of two `C^n` functions is `C^n`. -/ lemma times_cont_diff.sub {n : with_top β„•} {f g : E β†’ F} (hf : times_cont_diff π•œ n f) (hg : times_cont_diff π•œ n g) : times_cont_diff π•œ n (Ξ»x, f x - g x) := hf.add hg.neg /-! ### Sum of finitely many functions -/ lemma times_cont_diff_within_at.sum {ΞΉ : Type*} {f : ΞΉ β†’ E β†’ F} {s : finset ΞΉ} {n : with_top β„•} {t : set E} {x : E} (h : βˆ€ i ∈ s, times_cont_diff_within_at π•œ n (Ξ» x, f i x) t x) : times_cont_diff_within_at π•œ n (Ξ» x, (βˆ‘ i in s, f i x)) t x := begin classical, induction s using finset.induction_on with i s is IH, { simp [times_cont_diff_within_at_const] }, { simp only [is, finset.sum_insert, not_false_iff], exact (h _ (finset.mem_insert_self i s)).add (IH (Ξ» j hj, h _ (finset.mem_insert_of_mem hj))) } end lemma times_cont_diff_at.sum {ΞΉ : Type*} {f : ΞΉ β†’ E β†’ F} {s : finset ΞΉ} {n : with_top β„•} {x : E} (h : βˆ€ i ∈ s, times_cont_diff_at π•œ n (Ξ» x, f i x) x) : times_cont_diff_at π•œ n (Ξ» x, (βˆ‘ i in s, f i x)) x := by rw [← times_cont_diff_within_at_univ] at *; exact times_cont_diff_within_at.sum h lemma times_cont_diff_on.sum {ΞΉ : Type*} {f : ΞΉ β†’ E β†’ F} {s : finset ΞΉ} {n : with_top β„•} {t : set E} (h : βˆ€ i ∈ s, times_cont_diff_on π•œ n (Ξ» x, f i x) t) : times_cont_diff_on π•œ n (Ξ» x, (βˆ‘ i in s, f i x)) t := Ξ» x hx, times_cont_diff_within_at.sum (Ξ» i hi, h i hi x hx) lemma times_cont_diff.sum {ΞΉ : Type*} {f : ΞΉ β†’ E β†’ F} {s : finset ΞΉ} {n : with_top β„•} (h : βˆ€ i ∈ s, times_cont_diff π•œ n (Ξ» x, f i x)) : times_cont_diff π•œ n (Ξ» x, (βˆ‘ i in s, f i x)) := by simp [← times_cont_diff_on_univ] at *; exact times_cont_diff_on.sum h /-! ### Product of two functions -/ /- The product is smooth. -/ lemma times_cont_diff_mul {n : with_top β„•} : times_cont_diff π•œ n (Ξ» p : π•œ Γ— π•œ, p.1 * p.2) := is_bounded_bilinear_map_mul.times_cont_diff /-- The product of two `C^n` functions within a set at a point is `C^n` within this set at this point. -/ lemma times_cont_diff_within_at.mul {n : with_top β„•} {s : set E} {f g : E β†’ π•œ} (hf : times_cont_diff_within_at π•œ n f s x) (hg : times_cont_diff_within_at π•œ n g s x) : times_cont_diff_within_at π•œ n (Ξ» x, f x * g x) s x := times_cont_diff_mul.times_cont_diff_within_at.comp x (hf.prod hg) subset_preimage_univ /-- The product of two `C^n` functions at a point is `C^n` at this point. -/ lemma times_cont_diff_at.mul {n : with_top β„•} {f g : E β†’ π•œ} (hf : times_cont_diff_at π•œ n f x) (hg : times_cont_diff_at π•œ n g x) : times_cont_diff_at π•œ n (Ξ» x, f x * g x) x := by rw [← times_cont_diff_within_at_univ] at *; exact hf.mul hg /-- The product of two `C^n`functions is `C^n`. -/ lemma times_cont_diff.mul {n : with_top β„•} {f g : E β†’ π•œ} (hf : times_cont_diff π•œ n f) (hg : times_cont_diff π•œ n g) : times_cont_diff π•œ n (Ξ» x, f x * g x) := times_cont_diff_mul.comp (hf.prod hg) /-- The product of two `C^n` functions on a domain is `C^n`. -/ lemma times_cont_diff_on.mul {n : with_top β„•} {s : set E} {f g : E β†’ π•œ} (hf : times_cont_diff_on π•œ n f s) (hg : times_cont_diff_on π•œ n g s) : times_cont_diff_on π•œ n (Ξ» x, f x * g x) s := Ξ» x hx, (hf x hx).mul (hg x hx) /-! ### Scalar multiplication -/ /- The scalar multiplication is smooth. -/ lemma times_cont_diff_smul {n : with_top β„•} : times_cont_diff π•œ n (Ξ» p : π•œ Γ— F, p.1 β€’ p.2) := is_bounded_bilinear_map_smul.times_cont_diff /-- The scalar multiplication of two `C^n` functions within a set at a point is `C^n` within this set at this point. -/ lemma times_cont_diff_within_at.smul {n : with_top β„•} {s : set E} {f : E β†’ π•œ} {g : E β†’ F} (hf : times_cont_diff_within_at π•œ n f s x) (hg : times_cont_diff_within_at π•œ n g s x) : times_cont_diff_within_at π•œ n (Ξ» x, f x β€’ g x) s x := times_cont_diff_smul.times_cont_diff_within_at.comp x (hf.prod hg) subset_preimage_univ /-- The scalar multiplication of two `C^n` functions at a point is `C^n` at this point. -/ lemma times_cont_diff_at.smul {n : with_top β„•} {f : E β†’ π•œ} {g : E β†’ F} (hf : times_cont_diff_at π•œ n f x) (hg : times_cont_diff_at π•œ n g x) : times_cont_diff_at π•œ n (Ξ» x, f x β€’ g x) x := by rw [← times_cont_diff_within_at_univ] at *; exact hf.smul hg /-- The scalar multiplication of two `C^n` functions is `C^n`. -/ lemma times_cont_diff.smul {n : with_top β„•} {f : E β†’ π•œ} {g : E β†’ F} (hf : times_cont_diff π•œ n f) (hg : times_cont_diff π•œ n g) : times_cont_diff π•œ n (Ξ» x, f x β€’ g x) := times_cont_diff_smul.comp (hf.prod hg) /-- The scalar multiplication of two `C^n` functions on a domain is `C^n`. -/ lemma times_cont_diff_on.smul {n : with_top β„•} {s : set E} {f : E β†’ π•œ} {g : E β†’ F} (hf : times_cont_diff_on π•œ n f s) (hg : times_cont_diff_on π•œ n g s) : times_cont_diff_on π•œ n (Ξ» x, f x β€’ g x) s := Ξ» x hx, (hf x hx).smul (hg x hx) /-! ### Cartesian product of two functions-/ section prod_map variables {E' : Type*} [normed_group E'] [normed_space π•œ E'] {F' : Type*} [normed_group F'] [normed_space π•œ F'] {n : with_top β„•} /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ lemma times_cont_diff_within_at.prod_map' {s : set E} {t : set E'} {f : E β†’ F} {g : E' β†’ F'} {p : E Γ— E'} (hf : times_cont_diff_within_at π•œ n f s p.1) (hg : times_cont_diff_within_at π•œ n g t p.2) : times_cont_diff_within_at π•œ n (prod.map f g) (set.prod s t) p := (hf.comp p times_cont_diff_within_at_fst (prod_subset_preimage_fst _ _)).prod (hg.comp p times_cont_diff_within_at_snd (prod_subset_preimage_snd _ _)) lemma times_cont_diff_within_at.prod_map {s : set E} {t : set E'} {f : E β†’ F} {g : E' β†’ F'} {x : E} {y : E'} (hf : times_cont_diff_within_at π•œ n f s x) (hg : times_cont_diff_within_at π•œ n g t y) : times_cont_diff_within_at π•œ n (prod.map f g) (set.prod s t) (x, y) := times_cont_diff_within_at.prod_map' hf hg /-- The product map of two `C^n` functions on a set is `C^n` on the product set. -/ lemma times_cont_diff_on.prod_map {E' : Type*} [normed_group E'] [normed_space π•œ E'] {F' : Type*} [normed_group F'] [normed_space π•œ F'] {s : set E} {t : set E'} {n : with_top β„•} {f : E β†’ F} {g : E' β†’ F'} (hf : times_cont_diff_on π•œ n f s) (hg : times_cont_diff_on π•œ n g t) : times_cont_diff_on π•œ n (prod.map f g) (set.prod s t) := (hf.comp times_cont_diff_on_fst (prod_subset_preimage_fst _ _)).prod (hg.comp (times_cont_diff_on_snd) (prod_subset_preimage_snd _ _)) /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ lemma times_cont_diff_at.prod_map {f : E β†’ F} {g : E' β†’ F'} {x : E} {y : E'} (hf : times_cont_diff_at π•œ n f x) (hg : times_cont_diff_at π•œ n g y) : times_cont_diff_at π•œ n (prod.map f g) (x, y) := begin rw times_cont_diff_at at *, convert hf.prod_map hg, simp only [univ_prod_univ] end /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ lemma times_cont_diff_at.prod_map' {f : E β†’ F} {g : E' β†’ F'} {p : E Γ— E'} (hf : times_cont_diff_at π•œ n f p.1) (hg : times_cont_diff_at π•œ n g p.2) : times_cont_diff_at π•œ n (prod.map f g) p := begin rcases p, exact times_cont_diff_at.prod_map hf hg end /-- The product map of two `C^n` functions is `C^n`. -/ lemma times_cont_diff.prod_map {f : E β†’ F} {g : E' β†’ F'} (hf : times_cont_diff π•œ n f) (hg : times_cont_diff π•œ n g) : times_cont_diff π•œ n (prod.map f g) := begin rw times_cont_diff_iff_times_cont_diff_at at *, exact Ξ» ⟨x, y⟩, (hf x).prod_map (hg y) end end prod_map /-! ### Inversion in a complete normed algebra -/ section algebra_inverse variables (π•œ) (R : Type*) [normed_ring R] [normed_algebra π•œ R] open normed_ring continuous_linear_map ring /-- In a complete normed algebra, the operation of inversion is `C^n`, for all `n`, at each invertible element. The proof is by induction, bootstrapping using an identity expressing the derivative of inversion as a bilinear map of inversion itself. -/ lemma times_cont_diff_at_ring_inverse [complete_space R] {n : with_top β„•} (x : units R) : times_cont_diff_at π•œ n ring.inverse (x : R) := begin induction n using with_top.nat_induction with n IH Itop, { intros m hm, refine ⟨{y : R | is_unit y}, _, _⟩, { simp [nhds_within_univ], exact x.nhds }, { use (ftaylor_series_within π•œ inverse univ), rw [le_antisymm hm bot_le, has_ftaylor_series_up_to_on_zero_iff], split, { rintros _ ⟨x', hx'⟩, rw ← hx', exact (inverse_continuous_at x').continuous_within_at }, { simp [ftaylor_series_within] } } }, { apply times_cont_diff_at_succ_iff_has_fderiv_at.mpr, refine ⟨λ (x : R), - lmul_left_right π•œ R (inverse x, inverse x), _, _⟩, { refine ⟨{y : R | is_unit y}, x.nhds, _⟩, intros y hy, cases mem_set_of_eq.mp hy with y' hy', rw [← hy', inverse_unit], exact @has_fderiv_at_ring_inverse π•œ _ _ _ _ _ y' }, { exact (lmul_left_right_is_bounded_bilinear π•œ R).times_cont_diff.neg.comp_times_cont_diff_at (x : R) (IH.prod IH) } }, { exact times_cont_diff_at_top.mpr Itop } end end algebra_inverse /-! ### Inversion of continuous linear maps between Banach spaces -/ section map_inverse open continuous_linear_map /-- At a continuous linear equivalence `e : E ≃L[π•œ] F` between Banach spaces, the operation of inversion is `C^n`, for all `n`. -/ lemma times_cont_diff_at_map_inverse [complete_space E] {n : with_top β„•} (e : E ≃L[π•œ] F) : times_cont_diff_at π•œ n inverse (e : E β†’L[π•œ] F) := begin -- first, we use the lemma `to_ring_inverse` to rewrite in terms of `ring.inverse` in the ring -- `E β†’L[π•œ] E` let O₁ : (E β†’L[π•œ] E) β†’ (F β†’L[π•œ] E) := Ξ» f, f.comp (e.symm : (F β†’L[π•œ] E)), let Oβ‚‚ : (E β†’L[π•œ] F) β†’ (E β†’L[π•œ] E) := Ξ» f, (e.symm : (F β†’L[π•œ] E)).comp f, have : continuous_linear_map.inverse = O₁ ∘ ring.inverse ∘ Oβ‚‚, { funext f, rw to_ring_inverse e}, rw this, -- `O₁` and `Oβ‚‚` are `times_cont_diff`, so we reduce to proving that `ring.inverse` is `times_cont_diff` have h₁ : times_cont_diff π•œ n O₁, { exact is_bounded_bilinear_map_comp.times_cont_diff.comp (times_cont_diff_const.prod times_cont_diff_id) }, have hβ‚‚ : times_cont_diff π•œ n Oβ‚‚, { exact is_bounded_bilinear_map_comp.times_cont_diff.comp (times_cont_diff_id.prod times_cont_diff_const) }, refine h₁.times_cont_diff_at.comp _ (times_cont_diff_at.comp _ _ hβ‚‚.times_cont_diff_at), -- this works differently depending on whether or not `E` is `nontrivial` (the condition for -- `E β†’L[π•œ] E` to be a `normed_algebra`) cases subsingleton_or_nontrivial E with _i _i; resetI, { convert @times_cont_diff_at_const _ _ _ _ _ _ _ _ _ _ (0 : E β†’L[π•œ] E), ext, simp }, { convert times_cont_diff_at_ring_inverse π•œ (E β†’L[π•œ] E) 1, simp [Oβ‚‚], refl }, end end map_inverse section real /-! ### Results over `ℝ` The results in this section rely on the Mean Value Theorem, and therefore hold only over `ℝ` (and its extension fields such as `β„‚`). -/ variables {E' : Type*} [normed_group E'] [normed_space ℝ E'] {F' : Type*} [normed_group F'] [normed_space ℝ F'] /-- If a function has a Taylor series at order at least 1, then at points in the interior of the domain of definition, the term of order 1 of this series is a strict derivative of `f`. -/ lemma has_ftaylor_series_up_to_on.has_strict_fderiv_at {s : set E'} {f : E' β†’ F'} {x : E'} {p : E' β†’ formal_multilinear_series ℝ E' F'} {n : with_top β„•} (hf : has_ftaylor_series_up_to_on n f p s) (hn : 1 ≀ n) (hs : s ∈ 𝓝 x) : has_strict_fderiv_at f ((continuous_multilinear_curry_fin1 ℝ E' F') (p x 1)) x := begin let f' := Ξ» x, (continuous_multilinear_curry_fin1 ℝ E' F') (p x 1), have hf' : βˆ€ x, x ∈ s β†’ has_fderiv_within_at f (f' x) s x := Ξ» x, has_ftaylor_series_up_to_on.has_fderiv_within_at hf hn, have hcont : continuous_on f' s := (continuous_multilinear_curry_fin1 ℝ E' F').continuous.comp_continuous_on (hf.cont 1 hn), exact strict_fderiv_of_cont_diff hf' hcont hs, end /-- If a function is `C^n` with `1 ≀ n` around a point, then the derivative of `f` at this point is also a strict derivative. -/ lemma times_cont_diff_at.has_strict_fderiv_at {f : E' β†’ F'} {x : E'} {n : with_top β„•} (hf : times_cont_diff_at ℝ n f x) (hn : 1 ≀ n) : has_strict_fderiv_at f (fderiv ℝ f x) x := begin rcases hf 1 hn with ⟨u, H, p, hp⟩, simp only [nhds_within_univ, mem_univ, insert_eq_of_mem] at H, have := hp.has_strict_fderiv_at (by norm_num) H, convert this, exact this.has_fderiv_at.fderiv end /-- If a function is `C^n` with `1 ≀ n`, then the derivative of `f` is also a strict derivative. -/ lemma times_cont_diff.has_strict_fderiv_at {f : E' β†’ F'} {x : E'} {n : with_top β„•} (hf : times_cont_diff ℝ n f) (hn : 1 ≀ n) : has_strict_fderiv_at f (fderiv ℝ f x) x := hf.times_cont_diff_at.has_strict_fderiv_at hn end real section deriv /-! ### One dimension All results up to now have been expressed in terms of the general FrΓ©chet derivative `fderiv`. For maps defined on the field, the one-dimensional derivative `deriv` is often easier to use. In this paragraph, we reformulate some higher smoothness results in terms of `deriv`. -/ variables {fβ‚‚ : π•œ β†’ F} {sβ‚‚ : set π•œ} open continuous_linear_map (smul_right) /-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (formulated with `deriv_within`) is `C^n`. -/ theorem times_cont_diff_on_succ_iff_deriv_within {n : β„•} (hs : unique_diff_on π•œ sβ‚‚) : times_cont_diff_on π•œ ((n + 1) : β„•) fβ‚‚ sβ‚‚ ↔ differentiable_on π•œ fβ‚‚ sβ‚‚ ∧ times_cont_diff_on π•œ n (deriv_within fβ‚‚ sβ‚‚) sβ‚‚ := begin rw times_cont_diff_on_succ_iff_fderiv_within hs, congr' 2, rw ← iff_iff_eq, split, { assume h, have : deriv_within fβ‚‚ sβ‚‚ = (Ξ» u : π•œ β†’L[π•œ] F, u 1) ∘ (fderiv_within π•œ fβ‚‚ sβ‚‚), by { ext x, refl }, simp only [this], apply times_cont_diff.comp_times_cont_diff_on _ h, exact (is_bounded_bilinear_map_apply.is_bounded_linear_map_left _).times_cont_diff }, { assume h, have : fderiv_within π•œ fβ‚‚ sβ‚‚ = (Ξ» u, smul_right 1 u) ∘ (Ξ» x, deriv_within fβ‚‚ sβ‚‚ x), by { ext x, simp [deriv_within] }, simp only [this], apply times_cont_diff.comp_times_cont_diff_on _ h, exact (is_bounded_bilinear_map_smul_right.is_bounded_linear_map_right _).times_cont_diff } end /-- A function is `C^(n + 1)` on an open domain if and only if it is differentiable there, and its derivative (formulated with `deriv`) is `C^n`. -/ theorem times_cont_diff_on_succ_iff_deriv_of_open {n : β„•} (hs : is_open sβ‚‚) : times_cont_diff_on π•œ ((n + 1) : β„•) fβ‚‚ sβ‚‚ ↔ differentiable_on π•œ fβ‚‚ sβ‚‚ ∧ times_cont_diff_on π•œ n (deriv fβ‚‚) sβ‚‚ := begin rw times_cont_diff_on_succ_iff_deriv_within hs.unique_diff_on, congr' 2, rw ← iff_iff_eq, apply times_cont_diff_on_congr, assume x hx, exact deriv_within_of_open hs hx end /-- A function is `C^∞` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (formulated with `deriv_within`) is `C^∞`. -/ theorem times_cont_diff_on_top_iff_deriv_within (hs : unique_diff_on π•œ sβ‚‚) : times_cont_diff_on π•œ ∞ fβ‚‚ sβ‚‚ ↔ differentiable_on π•œ fβ‚‚ sβ‚‚ ∧ times_cont_diff_on π•œ ∞ (deriv_within fβ‚‚ sβ‚‚) sβ‚‚ := begin split, { assume h, refine ⟨h.differentiable_on le_top, _⟩, apply times_cont_diff_on_top.2 (Ξ» n, ((times_cont_diff_on_succ_iff_deriv_within hs).1 _).2), exact h.of_le le_top }, { assume h, refine times_cont_diff_on_top.2 (Ξ» n, _), have A : (n : with_top β„•) ≀ ∞ := le_top, apply ((times_cont_diff_on_succ_iff_deriv_within hs).2 ⟨h.1, h.2.of_le A⟩).of_le, exact with_top.coe_le_coe.2 (nat.le_succ n) } end /-- A function is `C^∞` on an open domain if and only if it is differentiable there, and its derivative (formulated with `deriv`) is `C^∞`. -/ theorem times_cont_diff_on_top_iff_deriv_of_open (hs : is_open sβ‚‚) : times_cont_diff_on π•œ ∞ fβ‚‚ sβ‚‚ ↔ differentiable_on π•œ fβ‚‚ sβ‚‚ ∧ times_cont_diff_on π•œ ∞ (deriv fβ‚‚) sβ‚‚ := begin rw times_cont_diff_on_top_iff_deriv_within hs.unique_diff_on, congr' 2, rw ← iff_iff_eq, apply times_cont_diff_on_congr, assume x hx, exact deriv_within_of_open hs hx end lemma times_cont_diff_on.deriv_within {m n : with_top β„•} (hf : times_cont_diff_on π•œ n fβ‚‚ sβ‚‚) (hs : unique_diff_on π•œ sβ‚‚) (hmn : m + 1 ≀ n) : times_cont_diff_on π•œ m (deriv_within fβ‚‚ sβ‚‚) sβ‚‚ := begin cases m, { change ∞ + 1 ≀ n at hmn, have : n = ∞, by simpa using hmn, rw this at hf, exact ((times_cont_diff_on_top_iff_deriv_within hs).1 hf).2 }, { change (m.succ : with_top β„•) ≀ n at hmn, exact ((times_cont_diff_on_succ_iff_deriv_within hs).1 (hf.of_le hmn)).2 } end lemma times_cont_diff_on.deriv_of_open {m n : with_top β„•} (hf : times_cont_diff_on π•œ n fβ‚‚ sβ‚‚) (hs : is_open sβ‚‚) (hmn : m + 1 ≀ n) : times_cont_diff_on π•œ m (deriv fβ‚‚) sβ‚‚ := (hf.deriv_within hs.unique_diff_on hmn).congr (Ξ» x hx, (deriv_within_of_open hs hx).symm) lemma times_cont_diff_on.continuous_on_deriv_within {n : with_top β„•} (h : times_cont_diff_on π•œ n fβ‚‚ sβ‚‚) (hs : unique_diff_on π•œ sβ‚‚) (hn : 1 ≀ n) : continuous_on (deriv_within fβ‚‚ sβ‚‚) sβ‚‚ := ((times_cont_diff_on_succ_iff_deriv_within hs).1 (h.of_le hn)).2.continuous_on lemma times_cont_diff_on.continuous_on_deriv_of_open {n : with_top β„•} (h : times_cont_diff_on π•œ n fβ‚‚ sβ‚‚) (hs : is_open sβ‚‚) (hn : 1 ≀ n) : continuous_on (deriv fβ‚‚) sβ‚‚ := ((times_cont_diff_on_succ_iff_deriv_of_open hs).1 (h.of_le hn)).2.continuous_on end deriv